CMS 3D CMS Logo

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