CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
BeamSpotAlignmentParameters.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 BeamSpotAlignmentParameters(): " << 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 BeamSpotAlignmentParameters(): " << parameters.num_row() << " instead of " << N_PARAM << " parameters.";
44  }
45 }
46 
47 //__________________________________________________________________________________________________
49 
50 //__________________________________________________________________________________________________
52  const AlgebraicSymMatrix &covMatrix) const {
53  BeamSpotAlignmentParameters *rbap = new BeamSpotAlignmentParameters(alignable(), parameters, covMatrix, selector());
54 
55  if (userVariables())
57  rbap->setValid(isValid());
58 
59  return rbap;
60 }
61 
62 //__________________________________________________________________________________________________
64  const AlgebraicSymMatrix &covMatrix) const {
66  alignable(), expandVector(parameters, selector()), expandSymMatrix(covMatrix, selector()), selector());
67 
68  if (userVariables())
70  rbap->setValid(isValid());
71 
72  return rbap;
73 }
74 
75 //__________________________________________________________________________________________________
77  const AlignableDetOrUnitPtr &alidet) const {
78  const Alignable *ali = this->alignable(); // Alignable of these parameters
79 
80  if (ali == alidet) { // same alignable => same frame
81  return BeamSpotAlignmentDerivatives()(tsos);
82  } else {
83  throw cms::Exception("MisMatch") << "BeamSpotAlignmentParameters::derivatives: The hit alignable must "
84  "match the "
85  << "aligned one, i.e. these parameters make only sense for "
86  "AlignableBeamSpot.\n";
87  return AlgebraicMatrix(N_PARAM, 2); // please compiler
88  }
89 }
90 
91 //__________________________________________________________________________________________________
93  const AlignableDetOrUnitPtr &alignableDet) const {
94  const AlgebraicMatrix dev = this->derivatives(tsos, alignableDet);
95 
96  int ncols = dev.num_col();
97  int nrows = dev.num_row();
98  int nsel = numSelected();
99 
100  AlgebraicMatrix seldev(nsel, ncols);
101 
102  int ir2 = 0;
103  for (int irow = 0; irow < nrows; ++irow) {
104  if (selector()[irow]) {
105  for (int icol = 0; icol < ncols; ++icol)
106  seldev[ir2][icol] = dev[irow][icol];
107  ++ir2;
108  }
109  }
110 
111  return seldev;
112 }
113 
114 //__________________________________________________________________________________________________
117  for (int i = 0; i < 2; ++i)
118  shift[i] = theData->parameters()[i];
119  shift[2] = 0.0;
120 
121  return shift;
122 }
123 
124 //__________________________________________________________________________________________________
126  AlgebraicVector rot(3);
127 
128  double dxdz = theData->parameters()[2];
129  double dydz = theData->parameters()[3];
130  double angleY = std::atan(dxdz);
131  double angleX = -std::atan(dydz);
132 
133  align::RotationType rotY(std::cos(angleY), 0., -std::sin(angleY), 0., 1., 0., std::sin(angleY), 0., std::cos(angleY));
134 
135  align::RotationType rotX(1., 0., 0., 0., std::cos(angleX), std::sin(angleX), 0., -std::sin(angleX), std::cos(angleX));
136 
137  align::EulerAngles angles = align::toAngles(rotY * rotX);
138 
139  rot[0] = angles(1);
140  rot[1] = angles(2);
141  rot[2] = angles(3);
142 
143  return rot;
144 }
145 
146 //__________________________________________________________________________________________________
148  Alignable *alignable = this->alignable();
149  if (!alignable) {
150  throw cms::Exception("BadParameters") << "BeamSpotAlignmentParameters::apply: parameters without alignable";
151  }
152 
153  // Translation in local frame
154  AlgebraicVector shift = this->translation(); // fixme: should be LocalVector
155 
156  // Translation local->global
157  align::GlobalVector gv(shift[0], shift[1], shift[2]);
158  alignable->move(gv);
159 
160  // Rotation in local frame
161  align::EulerAngles angles = this->rotation();
162  // original code:
163  // alignable->rotateInLocalFrame( align::toMatrix(angles) );
164  // correct for rounding errors:
165  align::RotationType rot = alignable->surface().toGlobal(align::toMatrix(angles));
166  align::rectify(rot);
167  alignable->rotateInGlobalFrame(rot);
168 }
169 
170 //__________________________________________________________________________________________________
172 
173 //__________________________________________________________________________________________________
175  AlgebraicVector m_GlobalParameters(N_PARAM, 0);
176 
177  const AlgebraicVector shift = translation(); // fixme: should return LocalVector
178 
179  const align::GlobalVector dg(shift[0], shift[1], 0);
180 
181  m_GlobalParameters[0] = dg.x();
182  m_GlobalParameters[1] = dg.y();
183 
184  align::LocalVector lv(0.0, 0.0, 1.0);
186 
187  double dxdz = gv.x() / gv.z();
188  double dydz = gv.x() / gv.z();
189 
190  m_GlobalParameters[2] = dxdz;
191  m_GlobalParameters[3] = dydz;
192 
193  return m_GlobalParameters;
194 }
195 
196 //__________________________________________________________________________________________________
198  std::cout << "Contents of BeamSpotAlignmentParameters:"
199  << "\nParameters: " << theData->parameters() << "\nCovariance: " << theData->covariance() << std::endl;
200 }
201 
202 //__________________________________________________________________________________________________
204  AlgebraicVector displacement(N_PARAM);
205 
206  if (ali) {
207  const align::RotationType &dR = ali->rotation();
208 
209  const align::LocalVector shifts(ali->globalRotation() * (dR.transposed() * ali->displacement().basicVector()));
210 
211  align::GlobalVector gv(0.0, 0.0, 1.0);
212  align::LocalVector lv(dR.transposed() * gv.basicVector());
213 
214  displacement[0] = shifts.x();
215  displacement[1] = shifts.y();
216  displacement[2] = lv.x() / lv.z();
217  displacement[3] = lv.y() / lv.z();
218  }
219 
220  return displacement;
221 }
static AlgebraicVector displacementFromAlignable(const Alignable *ali)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
const GlobalVector & displacement() const
Return change of the global position since the creation of the object.
Definition: Alignable.h:141
selection
main part
Definition: corrVsCorr.py:100
T y() const
Definition: PV3DBase.h:60
const RotationType & globalRotation() const
Return the global orientation of the object.
Definition: Alignable.h:138
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.
BeamSpotAlignmentParameters(Alignable *alignable, bool calcMis)
~BeamSpotAlignmentParameters() override
Destructor.
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:144
CLHEP::HepMatrix AlgebraicMatrix
void rectify(RotationType &)
Correct a rotation matrix for rounding errors.
Definition: Utilities.cc:185
void setValid(bool v)
Set validity flag.
AlgebraicVector globalParameters(void) const
calculate and return parameters in global frame
T z() const
Definition: PV3DBase.h:61
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
EulerAngles toAngles(const RotationType &)
Convert rotation matrix to angles about x-, y-, z-axes (frame rotation).
Definition: Utilities.cc:8
Alignable * alignable(void) const
Get pointer to corresponding alignable.
int type() const override
tell type (AlignmentParametersFactory::ParametersType - but no circular dependency) ...
AlgebraicVector rotation(void) const
Get rotation parameters.
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:132
AlgebraicMatrix derivatives(const TrajectoryStateOnSurface &tsos, const AlignableDetOrUnitPtr &) const override
Get all derivatives.
int numSelected(void) const
Get number of selected parameters.
CLHEP::HepVector AlgebraicVector
AlgebraicVector EulerAngles
Definition: Definitions.h:34
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
void print(void) const
print parameters to screen
BeamSpotAlignmentParameters * clone(const AlgebraicVector &parameters, const AlgebraicSymMatrix &covMatrix) const override
Clone all parameters (for update of 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.
RotationType toMatrix(const EulerAngles &)
Convert rotation angles about x-, y-, z-axes to matrix.
Definition: Utilities.cc:34
CLHEP::HepSymMatrix AlgebraicSymMatrix
static unsigned int const shift
AlgebraicMatrix selectedDerivatives(const TrajectoryStateOnSurface &tsos, const AlignableDetOrUnitPtr &) const override
Get selected derivatives.
tuple cout
Definition: gather_cfg.py:144
void apply() override
apply parameters to alignable
T x() const
Definition: PV3DBase.h:59
BeamSpotAlignmentParameters * cloneFromSelected(const AlgebraicVector &parameters, const AlgebraicSymMatrix &covMatrix) const override
Clone selected parameters (for update of parameters)
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:53
AlgebraicVector translation(void) const
Get translation parameters.