00001 #include "Alignment/CommonAlignment/interface/Alignable.h" 00002 #include "Alignment/CommonAlignment/interface/AlignmentParameters.h" 00003 #include "Alignment/SurveyAnalysis/interface/SurveyOutput.h" 00004 00005 #include "Alignment/SurveyAnalysis/interface/SurveyAlignment.h" 00006 00007 using namespace align; 00008 00009 SurveyAlignment::SurveyAlignment(const Alignables& sensors, 00010 const std::vector<StructureType>& levels): 00011 theSensors(sensors), 00012 theLevels(levels) 00013 { 00014 } 00015 00016 void SurveyAlignment::shiftSensors() 00017 { 00018 unsigned int nSensor = theSensors.size(); 00019 00020 for (unsigned int i = 0; i < nSensor; ++i) 00021 { 00022 Alignable* ali = theSensors[i]; 00023 00024 const AlignableSurface& surf = ali->surface(); 00025 const AlgebraicVector& pars = ali->alignmentParameters()->parameters(); 00026 00027 EulerAngles angles(3); 00028 00029 angles(1) = pars[3]; angles(2) = pars[4]; angles(3) = pars[5]; 00030 00031 RotationType rot = surf.toGlobal( toMatrix(angles) ); 00032 00033 rectify(rot); // correct for rounding errors 00034 00035 ali->move( surf.toGlobal( align::LocalVector(pars[0], pars[1], pars[2]) ) ); 00036 ali->rotateInGlobalFrame(rot); 00037 } 00038 } 00039 00040 void SurveyAlignment::iterate(unsigned int nIteration, 00041 const std::string& fileName, 00042 bool bias) 00043 { 00044 static const double tolerance = 1e-4; // convergence criteria 00045 00046 SurveyOutput out(theSensors, fileName); 00047 00048 out.write(0); 00049 00050 for (unsigned int i = 1; i <= nIteration; ++i) 00051 { 00052 std::cout << "***** Iteration " << i << " *****\n"; 00053 findAlignPars(bias); 00054 shiftSensors(); 00055 out.write(i); 00056 00057 // Check convergence 00058 00059 double parChi2 = 0.; 00060 00061 unsigned int nSensor = theSensors.size(); 00062 00063 for (unsigned int j = 0; j < nSensor; ++j) 00064 { 00065 AlignmentParameters* alignPar = theSensors[j]->alignmentParameters(); 00066 00067 const AlgebraicVector& par = alignPar->parameters(); 00068 const AlgebraicSymMatrix& cov = alignPar->covariance(); 00069 00070 int dummy; 00071 00072 parChi2 += cov.inverse(dummy).similarity(par); 00073 } 00074 00075 parChi2 /= static_cast<double>(nSensor); 00076 std::cout << "chi2 = " << parChi2 << std::endl; 00077 if (parChi2 < tolerance) break; // converges, so exit loop 00078 } 00079 }