CMS 3D CMS Logo

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