CMS 3D CMS Logo

AlignableComposite.cc
Go to the documentation of this file.
1 // Framework
4 
9 
11 
12 
13 //__________________________________________________________________________________________________
15  Alignable( geomDet->geographicalId().rawId(), geomDet->surface() ),
16  theStructureType(align::AlignableDet)
17 {
19 }
20 
21 //__________________________________________________________________________________________________
24  const RotationType& rot):
25  Alignable(id, rot),
26  theStructureType(type)
27 {
29 }
30 
31 //__________________________________________________________________________________________________
33 {
34  for (unsigned int i = 0; i < theComponents.size(); ++i) delete theComponents[i];
35 }
36 
37 //__________________________________________________________________________________________________
38 void AlignableComposite::update(const GeomDet* geomDet)
39 {
40  if (!geomDet) {
41  throw cms::Exception("Alignment")
42  << "@SUB=AlignableComposite::update\n"
43  << "Trying to update with GeomDet* pointing to 'nullptr'.";
44  }
45 
46  Alignable::update(geomDet->geographicalId().rawId(), geomDet->surface());
47 }
48 
49 //__________________________________________________________________________________________________
52  const RotationType& rot)
53 {
54  if (theStructureType != type) {
55  throw cms::Exception("Alignment")
56  << "@SUB=AlignableComposite::update\n"
57  << "Current alignable type does not match type of the update.";
58  }
59  // composite's position is already updated by components, i.e. it needs to be kept
61 }
62 
63 //__________________________________________________________________________________________________
65 {
66  const Alignables& newComps = ali->deepComponents();
67 
68  theDeepComponents.insert( theDeepComponents.end(), newComps.begin(), newComps.end() );
69 
70  Scalar k = static_cast<Scalar>( newComps.size() ) / theDeepComponents.size();
71 
72  theSurface.move( ( ali->globalPosition() - globalPosition() ) * k );
73 
74  ali->setMother(this);
75  theComponents.push_back(ali);
76 }
77 
78 //__________________________________________________________________________________________________
80 {
81 
84  && components.size() <= 1) { // Non-glued AlignableDets (still) contain themselves
85  return; // (would be better to implement AlignableDet::recursiveComponents!)
86  }
87  for (Alignables::const_iterator iter = components.begin();
88  iter != components.end(); ++iter) {
89  result.push_back(*iter); // could use std::copy(..), but here we build a real hierarchy
90  (*iter)->recursiveComponents(result);
91  }
92 }
93 
94 //__________________________________________________________________________________________________
96 {
97 
98  // Move components
99  Alignables comp = this->components();
100  for ( Alignables::iterator i=comp.begin(); i!=comp.end(); ++i )
101  (**i).move( displacement);
102 
103  // Move surface
104  this->addDisplacement( displacement );
105  theSurface.move( displacement );
106 
107 }
108 
109 
110 //__________________________________________________________________________________________________
111 void AlignableComposite::moveComponentsLocal( const LocalVector& localDisplacement )
112 {
113 
114  this->move( this->surface().toGlobal(localDisplacement) );
115 
116 }
117 
118 //__________________________________________________________________________________________________
119 void AlignableComposite::moveComponentLocal( const int i, const LocalVector& localDisplacement )
120 {
121 
122  if (i >= size() )
123  throw cms::Exception("LogicError")
124  << "AlignableComposite index (" << i << ") out of range";
125 
126  Alignables comp = this->components();
127  comp[i]->move( this->surface().toGlobal( localDisplacement ) );
128 
129 }
130 
131 
132 //__________________________________________________________________________________________________
138 {
139 
140  Alignables comp = this->components();
141 
142  PositionType myPosition = this->globalPosition();
143 
144  for ( Alignables::iterator i=comp.begin(); i!=comp.end(); ++i )
145  {
146 
147  // It is much simpler to calculate the local position given in coordinates
148  // of the GLOBAL frame and then just apply the rotation matrix given in the
149  // GLOBAL frame as well. ONLY this is somewhat tricky... as Teddy's frames
150  // don't like this kind of mixing...
151 
152  // Rotations are defined for "Basic3DVector" types, without any FrameTAG,
153  // because Rotations usually switch between different frames. You get
154  // this by using the method .basicVector()
155 
156  // localPosition = globalPosition (Component) - globalPosition(Composite)
157  // moveVector = rotated localPosition - original localposition
158  // LocalVector localPositionVector = (**i).globalPosition()-myPosition;
159 
160 
161  // Local Position given in coordinates of the GLOBAL Frame
162  const GlobalVector localPositionVector = (**i).globalPosition() - myPosition;
163  const GlobalVector::BasicVectorType& lpvgf = localPositionVector.basicVector();
164 
165  // rotate with GLOBAL rotation matrix and subtract => moveVector in
166  // global Coordinates
167  // apparently... you have to use the inverse of the rotation here
168  // (rotate the VECTOR rather than the frame)
169  GlobalVector moveVector( rotation.multiplyInverse(lpvgf) - lpvgf );
170 
171 
172  (**i).move( moveVector );
173  (**i).rotateInGlobalFrame( rotation );
174 
175  }
176 
177  this->addRotation( rotation );
178 
179  theSurface.rotate( rotation );
180 
181 }
182 
183 
184 //__________________________________________________________________________________________________
186  bool propagateDown )
187 {
188 
189  // Since no geomDet is attached, alignable composites do not have an APE
190  // The APE is, therefore, just propagated down
191  if (!propagateDown) return;
192 
193  Alignables comp = this->components();
194  for (Alignables::const_iterator i = comp.begin(); i != comp.end(); ++i) {
195  (*i)->setAlignmentPositionError(ape, propagateDown);
196  }
197 }
198 
199 
200 //__________________________________________________________________________________________________
201 void
203  bool propagateDown )
204 {
205 
206  // Since no geomDet is attached, alignable composites do not have an APE
207  // The APE is, therefore, just propagated down
208  if (!propagateDown) return;
209 
210  Alignables comp = this->components();
211  for (Alignables::const_iterator i = comp.begin(); i != comp.end(); ++i) {
212  (*i)->addAlignmentPositionError(ape, propagateDown);
213  }
214 
215 }
216 
217 
218 //__________________________________________________________________________________________________
223  bool propagateDown )
224 {
225 
226  if (!propagateDown) return;
227 
228  Alignables comp = this->components();
229  PositionType myPosition=this->globalPosition();
230 
231  for ( Alignables::const_iterator i=comp.begin(); i!=comp.end(); ++i )
232  {
233 
234  // It is just similar to to the "movement" that results to the components
235  // when the composite is rotated.
236  // Local Position given in coordinates of the GLOBAL Frame
237  const GlobalVector localPositionVector = (**i).globalPosition()-myPosition;
238  const GlobalVector::BasicVectorType& lpvgf = localPositionVector.basicVector();
239 
240  // rotate with GLOBAL rotation matrix and subtract => moveVector in global coordinates
241  // apparently... you have to use the inverse of the rotation here
242  // (rotate the VECTOR rather than the frame)
243  GlobalVector moveVector( rotation.multiplyInverse(lpvgf) - lpvgf );
244 
245  AlignmentPositionError ape( moveVector.x(), moveVector.y(), moveVector.z() );
246  (*i)->addAlignmentPositionError( ape, propagateDown );
247  (*i)->addAlignmentPositionErrorFromRotation( rotation, propagateDown );
248 
249  }
250 
251 }
252 
253 
254 //__________________________________________________________________________________________________
259  bool propagateDown )
260 {
261  // if (!propagateDown) return; // No! Cannot yet jump out since
262  // addAlignmentPositionErrorFromRotation(..) below might be overwritten in derived
263  // classes to do something on 'this' (and in fact does so in AlignableDet).
264 
266  this->addAlignmentPositionErrorFromRotation(globalRot, propagateDown);
267 
268 }
269 
270 //__________________________________________________________________________________________________
272  bool propagateDown)
273 {
274  // Only DetUnits have surface deformations.
275  // The parameters are, therefore, just propagated down.
276  if (!propagateDown) return;
277 
278  Alignables comp(this->components());
279  for (Alignables::const_iterator i = comp.begin(); i != comp.end(); ++i) {
280  (*i)->setSurfaceDeformation(deformation, propagateDown);
281  }
282 }
283 
284 //__________________________________________________________________________________________________
286  bool propagateDown)
287 {
288  // Only DetUnits have surface deformations.
289  // The parameters are, therefore, just propagated down.
290  if (!propagateDown) return;
291 
292  Alignables comp(this->components());
293  for (Alignables::const_iterator i = comp.begin(); i != comp.end(); ++i) {
294  (*i)->addSurfaceDeformation(deformation, propagateDown);
295  }
296 }
297 
298 //__________________________________________________________________________________________________
299 void AlignableComposite::dump( void ) const
300 {
301 
302  // A simple printout method. Could be specialized in the implementation classes.
303 
304  Alignables comp = this->components();
305 
306  // Dump this
307  edm::LogInfo("AlignableDump")
308  << " Alignable of type " << this->alignableObjectId()
309  << " has " << comp.size() << " components" << std::endl
310  << " position = " << this->globalPosition() << ", orientation:" << std::endl
311  << this->globalRotation();
312 
313  // Dump components
314  for ( Alignables::iterator i=comp.begin(); i!=comp.end(); ++i )
315  (*i)->dump();
316 
317 }
318 
319 
320 
321 //__________________________________________________________________________________________________
323 {
324 
325  // Recursively call alignments, until we get to an AlignableDetUnit
326  Alignables comp = this->components();
327 
328  Alignments* m_alignments = new Alignments();
329 
330  // Add components recursively
331  for ( Alignables::iterator i=comp.begin(); i!=comp.end(); ++i )
332  {
333  Alignments* tmpAlignments = (*i)->alignments();
334  std::copy( tmpAlignments->m_align.begin(), tmpAlignments->m_align.end(),
335  std::back_inserter(m_alignments->m_align) );
336  delete tmpAlignments;
337  }
338 
339 
340  return m_alignments;
341 
342 }
343 
344 
345 //__________________________________________________________________________________________________
347 {
348 
349  // Recursively call alignmentsErrors, until we get to an AlignableDetUnit
350  Alignables comp = this->components();
351 
352  AlignmentErrorsExtended* m_alignmentErrors = new AlignmentErrorsExtended();
353 
354  // Add components recursively
355  for ( Alignables::iterator i=comp.begin(); i!=comp.end(); ++i )
356  {
357  AlignmentErrorsExtended* tmpAlignmentErrorsExtended = (*i)->alignmentErrors();
358  std::copy( tmpAlignmentErrorsExtended->m_alignError.begin(), tmpAlignmentErrorsExtended->m_alignError.end(),
359  std::back_inserter(m_alignmentErrors->m_alignError) );
360  delete tmpAlignmentErrorsExtended;
361  }
362 
363 
364  return m_alignmentErrors;
365 
366 }
367 
368 
369 //__________________________________________________________________________________________________
370 int AlignableComposite::surfaceDeformationIdPairs(std::vector<std::pair<int,SurfaceDeformation*> > & result) const
371 {
372 
373  Alignables comp = this->components();
374 
375  int count = 0;
376 
377  // Add components recursively
378  for ( Alignables::iterator i=comp.begin(); i!=comp.end(); ++i) {
379  count += (*i)->surfaceDeformationIdPairs(result);
380  }
381 
382  return count;
383 
384 }
type
Definition: HCALResponse.h:21
void addAlignmentPositionError(const AlignmentPositionError &ape, bool propagateDown) override
void addAlignmentPositionErrorFromRotation(const RotationType &rotation, bool propagateDown) override
void update(align::ID, const AlignableSurface &)
Definition: Alignable.cc:50
void setSurfaceDeformation(const SurfaceDeformation *deformation, bool propagateDown) override
Set the surface deformation parameters - if (!propagateDown) do not affect daughters.
void rotateInGlobalFrame(const RotationType &rotation) override
Rotation interpreted in global reference frame.
AlignableComposite()
default constructor hidden
int surfaceDeformationIdPairs(std::vector< std::pair< int, SurfaceDeformation * > > &) const override
Return surface deformations.
uint32_t ID
Definition: Definitions.h:26
const GlobalVector & displacement() const
Return change of the global position since the creation of the object.
Definition: Alignable.h:144
StructureType alignableObjectId() const override
Return the alignable type identifier.
void move(const GlobalVector &displacement)
const RotationType & globalRotation() const
Return the global orientation of the object.
Definition: Alignable.h:141
void move(const GlobalVector &displacement) override
Move with respect to the global reference frame.
void addAlignmentPositionErrorFromLocalRotation(const RotationType &rotation, bool propagateDown) override
void recursiveComponents(Alignables &result) const override
Provide all components, subcomponents etc. (cf. description in base class)
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
std::vector< AlignTransform > m_align
Definition: Alignments.h:19
void setAlignmentPositionError(const AlignmentPositionError &ape, bool propagateDown) override
void addComponent(Alignable *component) override
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
virtual void moveComponentsLocal(const LocalVector &localDisplacement)
Move with respect to the local reference frame.
const RotationType & rotation() const
Return change of orientation since the creation of the object.
Definition: Alignable.h:147
StructureType theStructureType
Alignments * alignments() const override
Return alignment data.
AlignmentErrorsExtended * alignmentErrors() const override
Return vector of alignment errors.
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:79
virtual void moveComponentLocal(const int i, const LocalVector &localDisplacement)
Move a single component with respect to the local reference frame.
Alignables components() const override
Return vector of direct components.
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:135
int k[5][pyjets_maxn]
void setMother(Alignable *mother)
Assign mother to alignable.
Definition: Alignable.h:97
void addSurfaceDeformation(const SurfaceDeformation *deformation, bool propagateDown) override
const Alignables & deepComponents() const
Definition: Alignable.h:75
std::vector< AlignTransformErrorExtended > m_alignError
void addRotation(const RotationType &rotation)
Definition: Alignable.cc:256
void addDisplacement(const GlobalVector &displacement)
Definition: Alignable.cc:248
~AlignableComposite() override
deleting its components
void rotate(const RotationType &rotation)
align::Scalar Scalar
Definition: Alignable.h:32
CompConstraintType compConstraintType_
Definition: Alignable.h:252
const PositionType & globalPosition() const
Return the global position of the object.
Definition: Alignable.h:138
void update(align::ID, StructureType aType, const RotationType &rot=RotationType())
Basic3DVector< T > multiplyInverse(const Basic3DVector< T > &v) const
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:56
align::Alignables Alignables
Definition: Alignable.h:37
AlignableSurface theSurface
Definition: Alignable.h:243
int size() const
Return number of direct components.
Definition: Alignable.h:71
Alignables theDeepComponents
Definition: Alignable.h:254
void dump() const override
Recursive printout of alignable structure.