CMS 3D CMS Logo

SurveyAlignment.cc
Go to the documentation of this file.
4 
6 
7 using namespace align;
8 
9 SurveyAlignment::SurveyAlignment(const Alignables& sensors, const std::vector<StructureType>& levels)
10  : theSensors(sensors), theLevels(levels) {}
11 
13  unsigned int nSensor = theSensors.size();
14 
15  for (unsigned int i = 0; i < nSensor; ++i) {
16  Alignable* ali = theSensors[i];
17 
18  const AlignableSurface& surf = ali->surface();
19  const AlgebraicVector& pars = ali->alignmentParameters()->parameters();
20 
22 
23  angles(1) = pars[3];
24  angles(2) = pars[4];
25  angles(3) = pars[5];
26 
27  RotationType rot = surf.toGlobal(toMatrix(angles));
28 
29  rectify(rot); // correct for rounding errors
30 
31  ali->move(surf.toGlobal(align::LocalVector(pars[0], pars[1], pars[2])));
32  ali->rotateInGlobalFrame(rot);
33  }
34 }
35 
36 void SurveyAlignment::iterate(unsigned int nIteration, const std::string& fileName, bool bias) {
37  static const double tolerance = 1e-4; // convergence criteria
38 
39  SurveyOutput out(theSensors, fileName);
40 
41  out.write(0);
42 
43  for (unsigned int i = 1; i <= nIteration; ++i) {
44  std::cout << "***** Iteration " << i << " *****\n";
45  findAlignPars(bias);
46  shiftSensors();
47  out.write(i);
48 
49  // Check convergence
50 
51  double parChi2 = 0.;
52 
53  unsigned int nSensor = theSensors.size();
54 
55  for (unsigned int j = 0; j < nSensor; ++j) {
56  AlignmentParameters* alignPar = theSensors[j]->alignmentParameters();
57 
58  const AlgebraicVector& par = alignPar->parameters();
59  const AlgebraicSymMatrix& cov = alignPar->covariance();
60 
61  int dummy;
62 
63  parChi2 += cov.inverse(dummy).similarity(par);
64  }
65 
66  parChi2 /= static_cast<double>(nSensor);
67  std::cout << "chi2 = " << parChi2 << std::endl;
68  if (parChi2 < tolerance)
69  break; // converges, so exit loop
70  }
71 }
void iterate(unsigned int nIteration, const std::string &fileName, bool bias=false)
Run the iteration: find residuals, write to output, shift sensors.
const align::Alignables & theSensors
virtual void findAlignPars(bool bias=false)=0
Find the alignment parameters for all sensors.
const double tolerance
void write(unsigned int iter)
write out variables
Definition: SurveyOutput.cc:13
virtual void move(const GlobalVector &displacement)=0
Movement with respect to the global reference frame.
virtual void shiftSensors()
Apply the alignment parameters to all sensors.
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
Definition: Alignable.h:61
const AlgebraicVector & parameters(void) const
Get alignment parameters.
SurveyAlignment(const align::Alignables &sensors, const std::vector< align::StructureType > &levels)
Constructor to set the sensors and residual levels.
void rectify(RotationType &)
Correct a rotation matrix for rounding errors.
Definition: Utilities.cc:198
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:135
CLHEP::HepVector AlgebraicVector
AlgebraicVector EulerAngles
Definition: Definitions.h:36
virtual void rotateInGlobalFrame(const RotationType &rotation)=0
std::vector< Alignable * > Alignables
Definition: Utilities.h:32
align::GlobalPoints toGlobal(const align::LocalPoints &) const
Return in global coord given a set of local points.
RotationType toMatrix(const EulerAngles &)
Convert rotation angles about x-, y-, z-axes to matrix.
Definition: Utilities.cc:42
CLHEP::HepSymMatrix AlgebraicSymMatrix
const AlgebraicSymMatrix & covariance(void) const
Get parameter covariance matrix.