CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 : 0),
23  AlgebraicSymMatrix(N_PARAM, 0))
24 {
25 
26 }
27 
28 //__________________________________________________________________________________________________
31  const AlgebraicSymMatrix& covMatrix) :
32  AlignmentParameters( alignable, parameters, covMatrix )
33 {
34  if (parameters.num_row() != N_PARAM) {
35  throw cms::Exception("BadParameters") << "in BeamSpotAlignmentParameters(): "
36  << parameters.num_row() << " instead of " << N_PARAM
37  << " parameters.";
38  }
39 }
40 
41 //__________________________________________________________________________________________________
44  const AlgebraicSymMatrix& covMatrix,
45  const std::vector<bool>& selection ) :
46  AlignmentParameters( alignable, parameters, covMatrix, selection )
47 {
48  if (parameters.num_row() != N_PARAM) {
49  throw cms::Exception("BadParameters") << "in BeamSpotAlignmentParameters(): "
50  << parameters.num_row() << " instead of " << N_PARAM
51  << " parameters.";
52  }
53 }
54 
55 //__________________________________________________________________________________________________
57 {
58 
59 }
60 
61 //__________________________________________________________________________________________________
64  const AlgebraicSymMatrix& covMatrix ) const
65 {
67  new BeamSpotAlignmentParameters( alignable(), parameters, covMatrix, selector());
68 
70  rbap->setValid(isValid());
71 
72  return rbap;
73 }
74 
75 //__________________________________________________________________________________________________
78  const AlgebraicSymMatrix& covMatrix ) const
79 {
82  expandSymMatrix(covMatrix, selector()), selector());
83 
85  rbap->setValid(isValid());
86 
87  return rbap;
88 }
89 
90 //__________________________________________________________________________________________________
93  const AlignableDetOrUnitPtr &alidet ) const
94 {
95  const Alignable *ali = this->alignable(); // Alignable of these parameters
96 
97  if (ali == alidet) { // same alignable => same frame
98  return BeamSpotAlignmentDerivatives()(tsos);
99  } else {
100  throw cms::Exception("MisMatch")
101  << "BeamSpotAlignmentParameters::derivatives: The hit alignable must match the "
102  << "aligned one, i.e. these parameters make only sense for AlignableBeamSpot.\n";
103  return AlgebraicMatrix(N_PARAM, 2); // please compiler
104  }
105 }
106 
107 //__________________________________________________________________________________________________
110  const AlignableDetOrUnitPtr &alignableDet ) const
111 {
112  const AlgebraicMatrix dev = this->derivatives( tsos, alignableDet );
113 
114  int ncols = dev.num_col();
115  int nrows = dev.num_row();
116  int nsel = numSelected();
117 
118  AlgebraicMatrix seldev( nsel, ncols );
119 
120  int ir2=0;
121  for ( int irow=0; irow<nrows; ++irow ) {
122  if (selector()[irow]) {
123  for ( int icol=0; icol<ncols; ++icol ) seldev[ir2][icol] = dev[irow][icol];
124  ++ir2;
125  }
126  }
127 
128  return seldev;
129 }
130 
131 //__________________________________________________________________________________________________
133 {
135  for ( int i=0;i<2;++i ) shift[i] = theData->parameters()[i];
136  shift[2] = 0.0;
137 
138  return shift;
139 }
140 
141 //__________________________________________________________________________________________________
143 {
144  AlgebraicVector rot(3);
145 
146  double dxdz = theData->parameters()[2];
147  double dydz = theData->parameters()[3];
148  double angleY = std::atan(dxdz);
149  double angleX = -std::atan(dydz);
150 
151  align::RotationType rotY( std::cos(angleY), 0., -std::sin(angleY),
152  0., 1., 0.,
153  std::sin(angleY), 0., std::cos(angleY) );
154 
155  align::RotationType rotX( 1., 0., 0.,
156  0., std::cos(angleX), std::sin(angleX),
157  0., -std::sin(angleX), std::cos(angleX) );
158 
159  align::EulerAngles angles = align::toAngles(rotY * rotX);
160 
161  rot[0] = angles(1);
162  rot[1] = angles(2);
163  rot[2] = angles(3);
164 
165  return rot;
166 }
167 
168 //__________________________________________________________________________________________________
170 {
171  Alignable *alignable = this->alignable();
172  if (!alignable) {
173  throw cms::Exception("BadParameters")
174  << "BeamSpotAlignmentParameters::apply: parameters without alignable";
175  }
176 
177  // Translation in local frame
178  AlgebraicVector shift = this->translation(); // fixme: should be LocalVector
179 
180  // Translation local->global
181  align::GlobalVector gv(shift[0], shift[1], shift[2]);
182  alignable->move( gv );
183 
184  // Rotation in local frame
185  align::EulerAngles angles = this->rotation();
186  // original code:
187  // alignable->rotateInLocalFrame( align::toMatrix(angles) );
188  // correct for rounding errors:
189  align::RotationType rot = alignable->surface().toGlobal( align::toMatrix(angles) );
190  align::rectify(rot);
191  alignable->rotateInGlobalFrame(rot);
192 }
193 
194 //__________________________________________________________________________________________________
196 {
198 }
199 
200 //__________________________________________________________________________________________________
202 {
203  AlgebraicVector m_GlobalParameters(N_PARAM, 0);
204 
205  const AlgebraicVector shift = translation(); // fixme: should return LocalVector
206 
207  const align::GlobalVector dg(shift[0], shift[1], 0);
208 
209  m_GlobalParameters[0] = dg.x();
210  m_GlobalParameters[1] = dg.y();
211 
212  align::LocalVector lv(0.0, 0.0, 1.0);
214 
215  double dxdz = gv.x()/gv.z();
216  double dydz = gv.x()/gv.z();
217 
218  m_GlobalParameters[2] = dxdz;
219  m_GlobalParameters[3] = dydz;
220 
221  return m_GlobalParameters;
222 }
223 
224 //__________________________________________________________________________________________________
226 {
227 
228  std::cout << "Contents of BeamSpotAlignmentParameters:"
229  << "\nParameters: " << theData->parameters()
230  << "\nCovariance: " << theData->covariance() << std::endl;
231 }
232 
233 //__________________________________________________________________________________________________
235 {
236  AlgebraicVector displacement(N_PARAM);
237 
238  if (ali) {
239  const align::RotationType& dR = ali->rotation();
240 
241  const align::LocalVector shifts( ali->globalRotation() *
242  ( dR.transposed() * ali->displacement().basicVector() ) );
243 
244  align::GlobalVector gv(0.0, 0.0, 1.0);
245  align::LocalVector lv(dR.transposed() * gv.basicVector());
246 
247  displacement[0] = shifts.x();
248  displacement[1] = shifts.y();
249  displacement[2] = lv.x()/lv.z();
250  displacement[3] = lv.y()/lv.z();
251  }
252 
253  return displacement;
254 }
int i
Definition: DBlmapReader.cc:9
virtual AlgebraicMatrix derivatives(const TrajectoryStateOnSurface &tsos, const AlignableDetOrUnitPtr &) const
Get all derivatives.
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:135
selection
main part
Definition: corrVsCorr.py:98
T y() const
Definition: PV3DBase.h:63
const RotationType & globalRotation() const
Return the global orientation of the object.
Definition: Alignable.h:132
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.
virtual AlgebraicMatrix selectedDerivatives(const TrajectoryStateOnSurface &tsos, const AlignableDetOrUnitPtr &) const
Get selected derivatives.
const std::vector< bool > & selector(void) const
Get alignment parameter selector vector.
BeamSpotAlignmentParameters(Alignable *alignable, bool calcMis)
virtual ~BeamSpotAlignmentParameters()
Destructor.
AlignmentUserVariables * userVariables(void) const
Get pointer to user variables.
virtual BeamSpotAlignmentParameters * cloneFromSelected(const AlgebraicVector &parameters, const AlgebraicSymMatrix &covMatrix) const
Clone selected parameters (for update of parameters)
const RotationType & rotation() const
Return change of orientation since the creation of the object.
Definition: Alignable.h:138
virtual void apply()
apply parameters to alignable
virtual BeamSpotAlignmentParameters * clone(const AlgebraicVector &parameters, const AlgebraicSymMatrix &covMatrix) const
Clone all parameters (for update of parameters)
CLHEP::HepMatrix AlgebraicMatrix
void rectify(RotationType &)
Correct a rotation matrix for rounding errors.
Definition: Utilities.cc:196
void setValid(bool v)
Set validity flag.
AlgebraicVector globalParameters(void) const
calculate and return parameters in global frame
T z() const
Definition: PV3DBase.h:64
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:7
Alignable * alignable(void) const
Get pointer to corresponding alignable.
AlgebraicVector rotation(void) const
Get rotation parameters.
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:126
virtual int type() const
tell type (AlignmentParametersFactory::ParametersType - but no circular dependency) ...
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
void print(void) const
print parameters to screen
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:40
CLHEP::HepSymMatrix AlgebraicSymMatrix
static unsigned int const shift
tuple cout
Definition: gather_cfg.py:145
T x() const
Definition: PV3DBase.h:62
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:56
AlgebraicVector translation(void) const
Get translation parameters.