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(nullptr),
25  theMother(nullptr),
26  theSurvey(nullptr)
27 {
28 }
29 
30 //__________________________________________________________________________________________________
32  theDetId(), // FIXME: inconsistent with other ctr., cf. above
33  theId(id),
34  theSurface(PositionType(), rot),
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 auto& comps = this->components();
75  for (const auto& iComp: comps) {
76  if (iComp->alignmentParameters()) { // component has parameters itself
77  paramComps.push_back(iComp);
78  if (!first && !hasAliComp) isConsistent = false;
79  hasAliComp = true;
80  } else {
81  const unsigned int nCompBefore = paramComps.size();
82  if (!(iComp->firstCompsWithParams(paramComps))) {
83  isConsistent = false; // problem down in hierarchy
84  }
85  if (paramComps.size() != nCompBefore) {
86  if (!first && !hasAliComp) isConsistent = false;
87  hasAliComp = true;
88  } else if (hasAliComp) { // no components with params, but previous component did have comps.
89  isConsistent = false;
90  }
91  }
92  first = false;
93  }
94 
95  return isConsistent;
96 }
97 
98 //__________________________________________________________________________________________________
100 {
101  bool isConsistent = true;
102  bool hasAliComp = false;
103  bool first = true;
104  const auto& comps = this->components();
105  for (const auto& iComp: comps) {
106  const auto nCompsBefore = paramComps.size();
107  isConsistent = iComp->lastCompsWithParams(paramComps);
108  if (paramComps.size() == nCompsBefore) {
109  if (iComp->alignmentParameters()) {
110  paramComps.push_back(iComp);
111  if (!first && !hasAliComp) isConsistent = false;
112  hasAliComp = true;
113  }
114  } else {
115  if (hasAliComp) {
116  isConsistent = false;
117  }
118  if (!first && !hasAliComp) isConsistent = false;
119  hasAliComp = true;
120  }
121  first = false;
122  }
123 
124  return isConsistent;
125 }
126 
127 //__________________________________________________________________________________________________
129 {
130 
131  delete theAlignmentParameters;
133 
134 }
135 
136 
137 //__________________________________________________________________________________________________
139 {
140 
141  // This is done by simply transforming the rotation from
142  // the local system O to the global one O^-1 * Rot * O
143  // and then applying the global rotation O * Rot
144 
145  rotateInGlobalFrame( surface().toGlobal(rotation) );
146 
147 }
148 
149 
150 //__________________________________________________________________________________________________
152 {
153 
154  rotateInGlobalFrame( RotationType(axis.basicVector(),radians) );
155 
156 }
157 
158 
159 //__________________________________________________________________________________________________
161 {
162 
163  rotateInLocalFrame(RotationType(axis.basicVector(), radians));
164 
165 }
166 
167 
168 //__________________________________________________________________________________________________
170 {
171 
172  RotationType rot( 1., 0., 0.,
173  0., std::cos(radians), std::sin(radians),
174  0., -std::sin(radians), std::cos(radians) );
175 
176  rotateInGlobalFrame(rot);
177 
178 }
179 
180 
181 //__________________________________________________________________________________________________
183 {
184 
185  RotationType rot( 1., 0., 0.,
186  0., std::cos(radians), std::sin(radians),
187  0., -std::sin(radians), std::cos(radians) );
188 
189  rotateInLocalFrame(rot);
190 
191 }
192 
193 
194 //__________________________________________________________________________________________________
196 {
197 
198  RotationType rot( std::cos(radians), 0., -std::sin(radians),
199  0., 1., 0.,
200  std::sin(radians), 0., std::cos(radians) );
201 
202  rotateInGlobalFrame(rot);
203 
204 }
205 
206 
207 //__________________________________________________________________________________________________
209 {
210 
211  RotationType rot( std::cos(radians), 0., -std::sin(radians),
212  0., 1., 0.,
213  std::sin(radians), 0., std::cos(radians) );
214 
215  rotateInLocalFrame(rot);
216 
217 }
218 
219 
220 //__________________________________________________________________________________________________
222 {
223 
224  RotationType rot( std::cos(radians), std::sin(radians), 0.,
225  -std::sin(radians), std::cos(radians), 0.,
226  0., 0., 1. );
227 
228  rotateInGlobalFrame(rot);
229 
230 }
231 
232 
233 //__________________________________________________________________________________________________
235 {
236 
237  RotationType rot( std::cos(radians), std::sin(radians), 0. ,
238  -std::sin(radians), std::cos(radians), 0. ,
239  0., 0., 1. );
240 
241  rotateInLocalFrame(rot);
242 
243 }
244 
245 
246 //__________________________________________________________________________________________________
248 {
249 
251 
252 }
253 
254 //__________________________________________________________________________________________________
256 {
257 
259 
260 }
261 
262 //__________________________________________________________________________________________________
264 {
265 
266  typedef std::pair<int,SurfaceDeformation*> IdSurfaceDeformationPtrPair;
267 
268  std::vector<IdSurfaceDeformationPtrPair> result;
270  std::sort( result.begin(),
271  result.end(),
273 
274  AlignmentSurfaceDeformations* allSurfaceDeformations = new AlignmentSurfaceDeformations();
275 
276  for ( std::vector<IdSurfaceDeformationPtrPair>::const_iterator iPair = result.begin();
277  iPair != result.end();
278  ++iPair) {
279 
280  // should we check for 'empty' parameters here (all zeros) and skip ?
281  // may be add 'empty' method to SurfaceDeformation
282  allSurfaceDeformations->add((*iPair).first,
283  (*iPair).second->type(),
284  (*iPair).second->parameters());
285  }
286 
287  return allSurfaceDeformations;
288 
289 }
290 
292 {
293  // first treat itself
297 
298  // now treat components (a clean design would move that to AlignableComposite...)
299  for (const auto& it: this->components()) it->cacheTransformation();
300 }
301 
303 {
304  // first treat itself
308 
309  // now treat components (a clean design would move that to AlignableComposite...)
310  for (const auto& it: this->components()) it->cacheTransformation(run);
311 }
312 
314 {
315  // first treat itself
319 
320  // now treat components (a clean design would move that to AlignableComposite...)
321  for (const auto& it: this->components()) it->restoreCachedTransformation();
322 }
323 
325 {
326  if (surfacesCache_.find(run) == surfacesCache_.end()) {
327  throw cms::Exception("Alignment")
328  << "@SUB=Alignable::restoreCachedTransformation\n"
329  << "Trying to restore cached transformation for a run (" << run
330  << ") that has not been cached.";
331  } else {
332  // first treat itself
336 
337  // now treat components (a clean design would move that to AlignableComposite...)
338  for (const auto& it: this->components()) it->restoreCachedTransformation();
339  }
340 }
341 
342 //__________________________________________________________________________________________________
344 {
345 
346  delete theSurvey;
347  theSurvey = survey;
348 
349 }
350 
351 //______________________________________________________________________________
353 
354  if (!theMother) return;
355 
356  const auto thisComps = this->deepComponents().size();
357  const auto motherComps = theMother->deepComponents().size();
358  const auto motherShift = shift * static_cast<Scalar>(thisComps) / motherComps;
359 
360  switch(theMother->compConstraintType()) {
362  break;
364  theMother->theSurface.move(GlobalVector(0,0, motherShift.z()));
365  theMother->updateMother(GlobalVector(0,0, motherShift.z()));
366  break;
368  theMother->theSurface.move(motherShift);
369  theMother->updateMother(motherShift);
370  break;
371  }
372 }
373 
374 //______________________________________________________________________________
376 {
377  const auto& currentPosition = this->globalPosition();
378  theSurface.move(align::GlobalVector{-currentPosition.x(),
379  -currentPosition.y(),
380  -currentPosition.z()});
381 }
RotationType theCachedRotation
Definition: Alignable.h:253
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:138
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:234
virtual void rotateAroundLocalAxis(const LocalVector &axis, Scalar radians)
Rotation around arbitratry local axis.
Definition: Alignable.cc:160
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
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.
#define nullptr
Cache< RotationType > rotationsCache_
Definition: Alignable.h:262
virtual void rotateAroundGlobalAxis(const GlobalVector &axis, Scalar radians)
Rotation around arbitratry global axis.
Definition: Alignable.cc:151
GlobalVector theDisplacement
Definition: Alignable.h:248
virtual void rotateAroundGlobalZ(Scalar radians)
Rotation around global z-axis.
Definition: Alignable.cc:221
virtual void recenterSurface()
Recenter surface object without moving possible components.
Definition: Alignable.cc:375
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:128
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:263
virtual void restoreCachedTransformation()
restore the previously cached transformation, also for possible components
Definition: Alignable.cc:313
virtual void updateMother(const GlobalVector &shift)
Definition: Alignable.cc:352
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:169
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:343
void addRotation(const RotationType &rotation)
Definition: Alignable.cc:255
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:208
virtual void rotateAroundGlobalY(Scalar radians)
Rotation around global y-axis.
Definition: Alignable.cc:195
void addDisplacement(const GlobalVector &displacement)
Definition: Alignable.cc:247
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:291
virtual void rotateAroundLocalX(Scalar radians)
Rotation around local x-axis.
Definition: Alignable.cc:182
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:43
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:99
cond::RealTimeType< cond::runnumber >::type RunNumber
Definition: Utilities.h:38