CMS 3D CMS Logo

RigidBodyAlignmentParameters.cc
Go to the documentation of this file.
1 
9 
16 
17 // This class's header
19 
20 //__________________________________________________________________________________________________
22  : AlignmentParameters(ali, displacementFromAlignable(calcMis ? ali : nullptr), AlgebraicSymMatrix(N_PARAM, 0)) {}
23 
24 //__________________________________________________________________________________________________
27  const AlgebraicSymMatrix &covMatrix)
28  : AlignmentParameters(alignable, parameters, covMatrix) {
29  if (parameters.num_row() != N_PARAM) {
30  throw cms::Exception("BadParameters")
31  << "in RigidBodyAlignmentParameters(): " << parameters.num_row() << " instead of " << N_PARAM << " parameters.";
32  }
33 }
34 
35 //__________________________________________________________________________________________________
38  const AlgebraicSymMatrix &covMatrix,
39  const std::vector<bool> &selection)
40  : AlignmentParameters(alignable, parameters, covMatrix, selection) {
41  if (parameters.num_row() != N_PARAM) {
42  throw cms::Exception("BadParameters")
43  << "in RigidBodyAlignmentParameters(): " << parameters.num_row() << " instead of " << N_PARAM << " parameters.";
44  }
45 }
46 
47 //__________________________________________________________________________________________________
49  const AlgebraicSymMatrix &covMatrix) const {
50  RigidBodyAlignmentParameters *rbap = new RigidBodyAlignmentParameters(alignable(), parameters, covMatrix, selector());
51 
52  if (userVariables())
54  rbap->setValid(isValid());
55 
56  return rbap;
57 }
58 
59 //__________________________________________________________________________________________________
61  const AlgebraicVector &parameters, const AlgebraicSymMatrix &covMatrix) const {
63  alignable(), expandVector(parameters, selector()), expandSymMatrix(covMatrix, selector()), selector());
64 
65  if (userVariables())
67  rbap->setValid(isValid());
68 
69  return rbap;
70 }
71 
72 //__________________________________________________________________________________________________
74  const AlignableDetOrUnitPtr &alidet) const {
75  const Alignable *ali = this->alignable(); // Alignable of these parameters
76 
77  if (ali == alidet) { // same alignable => same frame
78  return KarimakiAlignmentDerivatives()(tsos);
79  } else { // different alignable => transform into correct frame
80  const AlgebraicMatrix deriv = KarimakiAlignmentDerivatives()(tsos);
82  return ftfd.frameToFrameDerivative(alidet, ali).T() * deriv;
83  }
84 }
85 
86 //__________________________________________________________________________________________________
88  const AlignableDetOrUnitPtr &alignableDet) const {
89  const AlgebraicMatrix dev = this->derivatives(tsos, alignableDet);
90 
91  int ncols = dev.num_col();
92  int nrows = dev.num_row();
93  int nsel = numSelected();
94 
95  AlgebraicMatrix seldev(nsel, ncols);
96 
97  int ir2 = 0;
98  for (int irow = 0; irow < nrows; ++irow) {
99  if (selector()[irow]) {
100  for (int icol = 0; icol < ncols; ++icol)
101  seldev[ir2][icol] = dev[irow][icol];
102  ++ir2;
103  }
104  }
105 
106  return seldev;
107 }
108 
109 //__________________________________________________________________________________________________
112  for (int i = 0; i < 3; ++i)
113  shift[i] = theData->parameters()[i];
114 
115  return shift;
116 }
117 
118 //__________________________________________________________________________________________________
120  AlgebraicVector rot(3);
121  for (int i = 0; i < 3; ++i)
122  rot[i] = theData->parameters()[i + 3];
123 
124  return rot;
125 }
126 
127 //__________________________________________________________________________________________________
129  Alignable *alignable = this->alignable();
130  if (!alignable) {
131  throw cms::Exception("BadParameters") << "RigidBodyAlignmentParameters::apply: parameters without alignable";
132  }
133 
134  // Translation in local frame
135  AlgebraicVector shift = this->translation(); // fixme: should be LocalVector
136 
137  // Translation local->global
138  align::LocalVector lv(shift[0], shift[1], shift[2]);
139  alignable->move(alignable->surface().toGlobal(lv));
140 
141  // Rotation in local frame
143  // original code:
144  // alignable->rotateInLocalFrame( align::toMatrix(angles) );
145  // correct for rounding errors:
146  align::RotationType rot = alignable->surface().toGlobal(align::toMatrix(angles));
147  align::rectify(rot);
148  alignable->rotateInGlobalFrame(rot);
149 }
150 
151 //__________________________________________________________________________________________________
153 
154 //__________________________________________________________________________________________________
156  AlgebraicVector m_GlobalParameters(N_PARAM, 0);
157 
158  const AlgebraicVector shift = translation(); // fixme: should return LocalVector
159 
160  const align::LocalVector lv(shift[0], shift[1], shift[2]);
162 
163  m_GlobalParameters[0] = dg.x();
164  m_GlobalParameters[1] = dg.y();
165  m_GlobalParameters[2] = dg.z();
166 
167  const align::EulerAngles eulerglob = theAlignable->surface().toGlobal(rotation());
168 
169  m_GlobalParameters[3] = eulerglob(1);
170  m_GlobalParameters[4] = eulerglob(2);
171  m_GlobalParameters[5] = eulerglob(3);
172 
173  return m_GlobalParameters;
174 }
175 
176 //__________________________________________________________________________________________________
178  std::cout << "Contents of RigidBodyAlignmentParameters:"
179  << "\nParameters: " << theData->parameters() << "\nCovariance: " << theData->covariance() << std::endl;
180 }
181 
182 //__________________________________________________________________________________________________
184  AlgebraicVector displacement(N_PARAM);
185 
186  if (ali) {
187  const align::RotationType &dR = ali->rotation();
188 
189  const align::LocalVector shifts(ali->globalRotation() * (dR.transposed() * ali->displacement().basicVector()));
190 
192 
193  displacement[0] = shifts.x();
194  displacement[1] = shifts.y();
195  displacement[2] = shifts.z();
196  displacement[3] = angles(1);
197  displacement[4] = angles(2);
198  displacement[5] = angles(3);
199  }
200 
201  return displacement;
202 }
int type() const override
tell type (AlignmentParametersFactory::ParametersType - but no circular dependency) ...
static AlgebraicVector displacementFromAlignable(const Alignable *ali)
const GlobalVector & displacement() const
Return change of the global position since the creation of the object.
Definition: Alignable.h:144
#define nullptr
selection
main part
Definition: corrVsCorr.py:100
AlgebraicMatrix derivatives(const TrajectoryStateOnSurface &tsos, const AlignableDetOrUnitPtr &) const override
Get all derivatives.
T y() const
Definition: PV3DBase.h:63
void apply() override
apply parameters to alignable
const RotationType & globalRotation() const
Return the global orientation of the object.
Definition: Alignable.h:141
AlgebraicSymMatrix expandSymMatrix(const AlgebraicSymMatrix &m, const std::vector< bool > &sel) const
virtual void move(const GlobalVector &displacement)=0
Movement with respect to the global reference frame.
const std::vector< bool > & selector(void) const
Get alignment parameter selector vector.
AlignmentUserVariables * userVariables(void) const
Get pointer to user variables.
const RotationType & rotation() const
Return change of orientation since the creation of the object.
Definition: Alignable.h:147
align::RotationType toLocal(const align::RotationType &) const
Return in local frame a rotation given in global frame.
CLHEP::HepMatrix AlgebraicMatrix
void rectify(RotationType &)
Correct a rotation matrix for rounding errors.
Definition: Utilities.cc:198
void setValid(bool v)
Set validity flag.
T z() const
Definition: PV3DBase.h:64
EulerAngles toAngles(const RotationType &)
Convert rotation matrix to angles about x-, y-, z-axes (frame rotation).
Definition: Utilities.cc:9
Alignable * alignable(void) const
Get pointer to corresponding alignable.
AlgebraicMatrix frameToFrameDerivative(const Alignable *object, const Alignable *composedObject) const
void print(void) const
print parameters to screen
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:135
RigidBodyAlignmentParameters * cloneFromSelected(const AlgebraicVector &parameters, const AlgebraicSymMatrix &covMatrix) const override
Clone selected parameters (for update of parameters)
int numSelected(void) const
Get number of selected parameters.
CLHEP::HepVector AlgebraicVector
AlgebraicVector EulerAngles
Definition: Definitions.h:36
AlgebraicVector expandVector(const AlgebraicVector &m, const std::vector< bool > &sel) const
void setUserVariables(AlignmentUserVariables *auv)
Set pointer to user variables.
virtual void rotateInGlobalFrame(const RotationType &rotation)=0
AlgebraicVector translation(void) const
Get translation parameters.
bool isValid(void) const
Get validity flag.
TkRotation transposed() const
align::GlobalPoints toGlobal(const align::LocalPoints &) const
Return in global coord given a set of local points.
AlgebraicMatrix selectedDerivatives(const TrajectoryStateOnSurface &tsos, const AlignableDetOrUnitPtr &) const override
Get selected derivatives.
RotationType toMatrix(const EulerAngles &)
Convert rotation angles about x-, y-, z-axes to matrix.
Definition: Utilities.cc:42
CLHEP::HepSymMatrix AlgebraicSymMatrix
static unsigned int const shift
AlgebraicVector rotation(void) const
Get rotation parameters.
AlgebraicVector globalParameters(void) const
calculate and return parameters in global frame
T x() const
Definition: PV3DBase.h:62
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:56
RigidBodyAlignmentParameters(Alignable *alignable, bool calcMis)
RigidBodyAlignmentParameters * clone(const AlgebraicVector &parameters, const AlgebraicSymMatrix &covMatrix) const override
Clone all parameters (for update of parameters)