CMS 3D CMS Logo

Alignable.cc
Go to the documentation of this file.
1 
10 
12 
15 
17 
18 //__________________________________________________________________________________________________
20  theDetId(id), // FIXME: inconsistent with other ctr., but needed for AlignableNavigator
21  theId(id), // (finally get rid of one of the IDs!)
22  theSurface(surf),
23  theCachedSurface(surf),
24  theAlignmentParameters(0),
25  theMother(0),
26  theSurvey(0)
27 {
28 }
29 
30 //__________________________________________________________________________________________________
32  theDetId(), // FIXME: inconsistent with other ctr., cf. above
33  theId(id),
34  theSurface(PositionType(), rot),
37  theMother(0),
38  theSurvey(0)
39 {
40 }
41 
42 //__________________________________________________________________________________________________
44 {
46  delete theSurvey;
47 }
48 
49 //__________________________________________________________________________________________________
51 {
52  if (theId != id) {
53  throw cms::Exception("Alignment")
54  << "@SUB=Alignable::update\n"
55  << "Current alignable ID does not match ID of the update.";
56  }
57  const auto shift = surf.position() - theSurface.position();
58  theSurface = surf;
59 
60  // reset displacement and rotations after update
63 
64  // recalculate containing composite's position
66 }
67 
68 //__________________________________________________________________________________________________
70 {
71  bool isConsistent = true;
72  bool hasAliComp = false; // whether there are any (grand-) daughters with parameters
73  bool first = true;
74  const Alignables comps(this->components());
75  for (Alignables::const_iterator iComp = comps.begin(), iCompEnd = comps.end();
76  iComp != iCompEnd; ++iComp) {
77  if ((*iComp)->alignmentParameters()) { // component has parameters itself
78  paramComps.push_back(*iComp);
79  if (!first && !hasAliComp) isConsistent = false;
80  hasAliComp = true;
81  } else {
82  const unsigned int nCompBefore = paramComps.size();
83  if (!(*iComp)->firstCompsWithParams(paramComps)) {
84  isConsistent = false; // problem down in hierarchy
85  }
86  if (paramComps.size() != nCompBefore) {
87  if (!first && !hasAliComp) isConsistent = false;
88  hasAliComp = true;
89  } else if (hasAliComp) { // no components with params, but previous component did have comps.
90  isConsistent = false;
91  }
92  }
93  first = false;
94  }
95 
96  return isConsistent;
97 }
98 
99 //__________________________________________________________________________________________________
101 {
102  bool isConsistent = true;
103  bool hasAliComp = false;
104  bool first = true;
105  const Alignables comps(this->components());
106  for (const auto& iComp: comps) {
107  const auto nCompsBefore = paramComps.size();
108  isConsistent = iComp->lastCompsWithParams(paramComps);
109  if (paramComps.size() == nCompsBefore) {
110  if (iComp->alignmentParameters()) {
111  paramComps.push_back(iComp);
112  if (!first && !hasAliComp) isConsistent = false;
113  hasAliComp = true;
114  }
115  } else {
116  if (hasAliComp) {
117  isConsistent = false;
118  }
119  if (!first && !hasAliComp) isConsistent = false;
120  hasAliComp = true;
121  }
122  first = false;
123  }
124 
125  return isConsistent;
126 }
127 
128 //__________________________________________________________________________________________________
130 {
131 
132  delete theAlignmentParameters;
134 
135 }
136 
137 
138 //__________________________________________________________________________________________________
140 {
141 
142  // This is done by simply transforming the rotation from
143  // the local system O to the global one O^-1 * Rot * O
144  // and then applying the global rotation O * Rot
145 
146  rotateInGlobalFrame( surface().toGlobal(rotation) );
147 
148 }
149 
150 
151 //__________________________________________________________________________________________________
153 {
154 
155  rotateInGlobalFrame( RotationType(axis.basicVector(),radians) );
156 
157 }
158 
159 
160 //__________________________________________________________________________________________________
162 {
163 
164  rotateInLocalFrame(RotationType(axis.basicVector(), radians));
165 
166 }
167 
168 
169 //__________________________________________________________________________________________________
171 {
172 
173  RotationType rot( 1., 0., 0.,
174  0., std::cos(radians), std::sin(radians),
175  0., -std::sin(radians), std::cos(radians) );
176 
177  rotateInGlobalFrame(rot);
178 
179 }
180 
181 
182 //__________________________________________________________________________________________________
184 {
185 
186  RotationType rot( 1., 0., 0.,
187  0., std::cos(radians), std::sin(radians),
188  0., -std::sin(radians), std::cos(radians) );
189 
190  rotateInLocalFrame(rot);
191 
192 }
193 
194 
195 //__________________________________________________________________________________________________
197 {
198 
199  RotationType rot( std::cos(radians), 0., -std::sin(radians),
200  0., 1., 0.,
201  std::sin(radians), 0., std::cos(radians) );
202 
203  rotateInGlobalFrame(rot);
204 
205 }
206 
207 
208 //__________________________________________________________________________________________________
210 {
211 
212  RotationType rot( std::cos(radians), 0., -std::sin(radians),
213  0., 1., 0.,
214  std::sin(radians), 0., std::cos(radians) );
215 
216  rotateInLocalFrame(rot);
217 
218 }
219 
220 
221 //__________________________________________________________________________________________________
223 {
224 
225  RotationType rot( std::cos(radians), std::sin(radians), 0.,
226  -std::sin(radians), std::cos(radians), 0.,
227  0., 0., 1. );
228 
229  rotateInGlobalFrame(rot);
230 
231 }
232 
233 
234 //__________________________________________________________________________________________________
236 {
237 
238  RotationType rot( std::cos(radians), std::sin(radians), 0. ,
239  -std::sin(radians), std::cos(radians), 0. ,
240  0., 0., 1. );
241 
242  rotateInLocalFrame(rot);
243 
244 }
245 
246 
247 //__________________________________________________________________________________________________
249 {
250 
252 
253 }
254 
255 //__________________________________________________________________________________________________
257 {
258 
260 
261 }
262 
263 //__________________________________________________________________________________________________
265 {
266 
267  typedef std::pair<int,SurfaceDeformation*> IdSurfaceDeformationPtrPair;
268 
269  std::vector<IdSurfaceDeformationPtrPair> result;
271  std::sort( result.begin(),
272  result.end(),
274 
275  AlignmentSurfaceDeformations* allSurfaceDeformations = new AlignmentSurfaceDeformations();
276 
277  for ( std::vector<IdSurfaceDeformationPtrPair>::const_iterator iPair = result.begin();
278  iPair != result.end();
279  ++iPair) {
280 
281  // should we check for 'empty' parameters here (all zeros) and skip ?
282  // may be add 'empty' method to SurfaceDeformation
283  allSurfaceDeformations->add((*iPair).first,
284  (*iPair).second->type(),
285  (*iPair).second->parameters());
286  }
287 
288  return allSurfaceDeformations;
289 
290 }
291 
293 {
294  // first treat itself
298 
299  // now treat components (a clean design would move that to AlignableComposite...)
300  const Alignables comps(this->components());
301 
302  for (auto it = comps.begin(); it != comps.end(); ++it) {
303  (*it)->cacheTransformation();
304  }
305 
306 }
307 
309 {
310  // first treat itself
314 
315  // now treat components (a clean design would move that to AlignableComposite...)
316  const Alignables comps(this->components());
317  for (auto& it: comps) it->cacheTransformation(run);
318 }
319 
321 {
322  // first treat itself
326 
327  // now treat components (a clean design would move that to AlignableComposite...)
328  const auto comps = this->components();
329 
330  for (auto it = comps.begin(); it != comps.end(); ++it) {
331  (*it)->restoreCachedTransformation();
332  }
333 
334 }
335 
337 {
338  if (surfacesCache_.find(run) == surfacesCache_.end()) {
339  throw cms::Exception("Alignment")
340  << "@SUB=Alignable::restoreCachedTransformation\n"
341  << "Trying to restore cached transformation for a run (" << run
342  << ") that has not been cached.";
343  } else {
344  // first treat itself
348 
349  // now treat components (a clean design would move that to AlignableComposite...)
350  const auto comps = this->components();
351  for (auto it: comps) it->restoreCachedTransformation();
352  }
353 }
354 
355 //__________________________________________________________________________________________________
357 {
358 
359  delete theSurvey;
360  theSurvey = survey;
361 
362 }
363 
364 //______________________________________________________________________________
366 
367  if (!theMother) return;
368 
369  const auto thisComps = this->deepComponents().size();
370  const auto motherComps = theMother->deepComponents().size();
371  const auto motherShift = shift * static_cast<Scalar>(thisComps) / motherComps;
372 
373  switch(theMother->compConstraintType()) {
375  break;
377  theMother->theSurface.move(GlobalVector(0,0, motherShift.z()));
378  theMother->updateMother(GlobalVector(0,0, motherShift.z()));
379  break;
381  theMother->theSurface.move(motherShift);
382  theMother->updateMother(motherShift);
383  break;
384  }
385 }
RotationType theCachedRotation
Definition: Alignable.h:250
void update(align::ID, const AlignableSurface &)
Definition: Alignable.cc:50
virtual void rotateInLocalFrame(const RotationType &rotation)
Rotation intepreted in the local reference frame.
Definition: Alignable.cc:139
DetId theDetId
Definition: Alignable.h:238
virtual int surfaceDeformationIdPairs(std::vector< std::pair< int, SurfaceDeformation * > > &) const =0
RotationType theRotation
Definition: Alignable.h:246
virtual void rotateAroundLocalZ(Scalar radians)
Rotation around local z-axis.
Definition: Alignable.cc:235
virtual void rotateAroundLocalAxis(const LocalVector &axis, Scalar radians)
Rotation around arbitratry local axis.
Definition: Alignable.cc:161
Alignable()
private default ctr. to enforce usage of the specialised ones
Definition: Alignable.h:264
uint32_t ID
Definition: Definitions.h:26
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
const SurveyDet * survey() const
Return survey info.
Definition: Alignable.h:225
Alignable * theMother
Definition: Alignable.h:268
const GlobalVector & displacement() const
Return change of the global position since the creation of the object.
Definition: Alignable.h:144
void move(const GlobalVector &displacement)
Cache< GlobalVector > displacementsCache_
Definition: Alignable.h:258
Cache< AlignableSurface > surfacesCache_
Definition: Alignable.h:257
Cache< RotationType > rotationsCache_
Definition: Alignable.h:259
virtual void rotateAroundGlobalAxis(const GlobalVector &axis, Scalar radians)
Rotation around arbitratry global axis.
Definition: Alignable.cc:152
GlobalVector theDisplacement
Definition: Alignable.h:245
virtual void rotateAroundGlobalZ(Scalar radians)
Rotation around global z-axis.
Definition: Alignable.cc:222
const RotationType & rotation() const
Return change of orientation since the creation of the object.
Definition: Alignable.h:147
AlignmentParameters * theAlignmentParameters
Definition: Alignable.h:264
void setAlignmentParameters(AlignmentParameters *dap)
Set the AlignmentParameters.
Definition: Alignable.cc:129
virtual Alignables components() const =0
Return vector of all direct components.
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
bool firstCompsWithParams(Alignables &paramComps) const
Definition: Alignable.cc:69
AlignmentSurfaceDeformations * surfaceDeformations() const
Return surface deformations, sorted by DetId.
Definition: Alignable.cc:264
virtual void restoreCachedTransformation()
restore the previously cached transformation, also for possible components
Definition: Alignable.cc:320
virtual void updateMother(const GlobalVector &shift)
Definition: Alignable.cc:365
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:135
AlignableSurface theCachedSurface
Definition: Alignable.h:248
const Alignables & deepComponents() const
Definition: Alignable.h:75
virtual void rotateAroundGlobalX(Scalar radians)
Rotation around global x-axis.
Definition: Alignable.cc:170
bool add(align::ID rawId, int type, const std::vector< align::Scalar > &parameters)
Add a new item.
virtual void rotateInGlobalFrame(const RotationType &rotation)=0
void setSurvey(const SurveyDet *)
Set survey info.
Definition: Alignable.cc:356
void addRotation(const RotationType &rotation)
Definition: Alignable.cc:256
align::RotationType RotationType
Definition: Alignable.h:34
GlobalVector theCachedDisplacement
Definition: Alignable.h:249
virtual void rotateAroundLocalY(Scalar radians)
Rotation around local y-axis.
Definition: Alignable.cc:209
virtual void rotateAroundGlobalY(Scalar radians)
Rotation around global y-axis.
Definition: Alignable.cc:196
void addDisplacement(const GlobalVector &displacement)
Definition: Alignable.cc:248
virtual CompConstraintType compConstraintType() const
Return the alignable type of contraints wrt. its components.
Definition: Alignable.h:192
virtual void cacheTransformation()
cache the current position, rotation and other parameters (e.g. surface deformations), also for possible components
Definition: Alignable.cc:292
virtual void rotateAroundLocalX(Scalar radians)
Rotation around local x-axis.
Definition: Alignable.cc:183
static unsigned int const shift
align::Scalar Scalar
Definition: Alignable.h:32
align::GlobalVector GlobalVector
Definition: Alignable.h:35
align::ID theId
Definition: Alignable.h:241
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:56
const PositionType & position() const
virtual ~Alignable()
Destructor.
Definition: Alignable.cc:43
const SurveyDet * theSurvey
Definition: Alignable.h:270
align::Alignables Alignables
Definition: Alignable.h:37
AlignableSurface theSurface
Definition: Alignable.h:243
bool lastCompsWithParams(Alignables &paramComps) const
Definition: Alignable.cc:100
cond::RealTimeType< cond::runnumber >::type RunNumber
Definition: Utilities.h:37