Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:46:13

0001 #include "Alignment/CommonAlignment/interface/Alignable.h"
0002 #include "Alignment/CommonAlignment/interface/AlignmentParameters.h"
0003 #include "Alignment/SurveyAnalysis/interface/SurveyOutput.h"
0004 
0005 #include "Alignment/SurveyAnalysis/interface/SurveyAlignment.h"
0006 
0007 using namespace align;
0008 
0009 SurveyAlignment::SurveyAlignment(const Alignables& sensors, const std::vector<StructureType>& levels)
0010     : theSensors(sensors), theLevels(levels) {}
0011 
0012 void SurveyAlignment::shiftSensors() {
0013   unsigned int nSensor = theSensors.size();
0014 
0015   for (unsigned int i = 0; i < nSensor; ++i) {
0016     Alignable* ali = theSensors[i];
0017 
0018     const AlignableSurface& surf = ali->surface();
0019     const AlgebraicVector& pars = ali->alignmentParameters()->parameters();
0020 
0021     EulerAngles angles(3);
0022 
0023     angles(1) = pars[3];
0024     angles(2) = pars[4];
0025     angles(3) = pars[5];
0026 
0027     RotationType rot = surf.toGlobal(toMatrix(angles));
0028 
0029     rectify(rot);  // correct for rounding errors
0030 
0031     ali->move(surf.toGlobal(align::LocalVector(pars[0], pars[1], pars[2])));
0032     ali->rotateInGlobalFrame(rot);
0033   }
0034 }
0035 
0036 void SurveyAlignment::iterate(unsigned int nIteration, const std::string& fileName, bool bias) {
0037   static const double tolerance = 1e-4;  // convergence criteria
0038 
0039   SurveyOutput out(theSensors, fileName);
0040 
0041   out.write(0);
0042 
0043   for (unsigned int i = 1; i <= nIteration; ++i) {
0044     std::cout << "***** Iteration " << i << " *****\n";
0045     findAlignPars(bias);
0046     shiftSensors();
0047     out.write(i);
0048 
0049     // Check convergence
0050 
0051     double parChi2 = 0.;
0052 
0053     unsigned int nSensor = theSensors.size();
0054 
0055     for (unsigned int j = 0; j < nSensor; ++j) {
0056       AlignmentParameters* alignPar = theSensors[j]->alignmentParameters();
0057 
0058       const AlgebraicVector& par = alignPar->parameters();
0059       const AlgebraicSymMatrix& cov = alignPar->covariance();
0060 
0061       int dummy;
0062 
0063       parChi2 += cov.inverse(dummy).similarity(par);
0064     }
0065 
0066     parChi2 /= static_cast<double>(nSensor);
0067     std::cout << "chi2 = " << parChi2 << std::endl;
0068     if (parChi2 < tolerance)
0069       break;  // converges, so exit loop
0070   }
0071 }