CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
AlignableComposite.cc
Go to the documentation of this file.
1 #include <memory>
2 
3 // Framework
6 
11 
13 
14 //__________________________________________________________________________________________________
16  : Alignable(geomDet->geographicalId().rawId(), geomDet->surface()), theStructureType(align::AlignableDet) {
17  compConstraintType_ = Alignable::CompConstraintType::POSITION;
18 }
19 
20 //__________________________________________________________________________________________________
22  : Alignable(id, rot), theStructureType(type) {
23  compConstraintType_ = Alignable::CompConstraintType::POSITION;
24 }
25 
26 //__________________________________________________________________________________________________
28  for (unsigned int i = 0; i < theComponents.size(); ++i)
29  delete theComponents[i];
30 }
31 
32 //__________________________________________________________________________________________________
33 void AlignableComposite::update(const GeomDet* geomDet) {
34  if (!geomDet) {
35  throw cms::Exception("Alignment") << "@SUB=AlignableComposite::update\n"
36  << "Trying to update with GeomDet* pointing to 'nullptr'.";
37  }
38 
39  Alignable::update(geomDet->geographicalId().rawId(), geomDet->surface());
40 }
41 
42 //__________________________________________________________________________________________________
44  if (theStructureType != type) {
45  throw cms::Exception("Alignment") << "@SUB=AlignableComposite::update\n"
46  << "Current alignable type does not match type of the update.";
47  }
48  // composite's position is already updated by components, i.e. it needs to be kept
50 }
51 
52 //__________________________________________________________________________________________________
54  const auto& newComps = ali->deepComponents();
55 
56  theDeepComponents.insert(theDeepComponents.end(), newComps.begin(), newComps.end());
57 
58  Scalar k = static_cast<Scalar>(newComps.size()) / theDeepComponents.size();
59 
60  theSurface.move((ali->globalPosition() - globalPosition()) * k);
61 
62  ali->setMother(this);
63  theComponents.push_back(ali);
64 }
65 
66 //__________________________________________________________________________________________________
68  const auto& components = this->components();
69  if (this->alignableObjectId() == align::AlignableDet &&
70  components.size() <= 1) { // Non-glued AlignableDets (still) contain themselves
71  return; // (would be better to implement AlignableDet::recursiveComponents!)
72  }
73  for (const auto& iter : components) {
74  result.push_back(iter); // could use std::copy(..), but here we build a real hierarchy
75  iter->recursiveComponents(result);
76  }
77 }
78 
79 //__________________________________________________________________________________________________
80 void AlignableComposite::move(const GlobalVector& displacement) {
81  // Move components
82  for (const auto& i : this->components())
83  i->move(displacement);
84 
85  // Move surface
86  this->addDisplacement(displacement);
87  theSurface.move(displacement);
88 }
89 
90 //__________________________________________________________________________________________________
91 void AlignableComposite::moveComponentsLocal(const LocalVector& localDisplacement) {
92  this->move(this->surface().toGlobal(localDisplacement));
93 }
94 
95 //__________________________________________________________________________________________________
96 void AlignableComposite::moveComponentLocal(const int i, const LocalVector& localDisplacement) {
97  if (i >= size())
98  throw cms::Exception("LogicError") << "AlignableComposite index (" << i << ") out of range";
99 
100  const auto& comp = this->components();
101  comp[i]->move(this->surface().toGlobal(localDisplacement));
102 }
103 
104 //__________________________________________________________________________________________________
110  const auto& comp = this->components();
111 
112  PositionType myPosition = this->globalPosition();
113 
114  for (const auto& i : comp) {
115  // It is much simpler to calculate the local position given in coordinates
116  // of the GLOBAL frame and then just apply the rotation matrix given in the
117  // GLOBAL frame as well. ONLY this is somewhat tricky... as Teddy's frames
118  // don't like this kind of mixing...
119 
120  // Rotations are defined for "Basic3DVector" types, without any FrameTAG,
121  // because Rotations usually switch between different frames. You get
122  // this by using the method .basicVector()
123 
124  // localPosition = globalPosition (Component) - globalPosition(Composite)
125  // moveVector = rotated localPosition - original localposition
126  // LocalVector localPositionVector = (**i).globalPosition()-myPosition;
127 
128  // Local Position given in coordinates of the GLOBAL Frame
129  const GlobalVector localPositionVector = i->globalPosition() - myPosition;
130  const GlobalVector::BasicVectorType& lpvgf = localPositionVector.basicVector();
131 
132  // rotate with GLOBAL rotation matrix and subtract => moveVector in
133  // global Coordinates
134  // apparently... you have to use the inverse of the rotation here
135  // (rotate the VECTOR rather than the frame)
136  GlobalVector moveVector(rotation.multiplyInverse(lpvgf) - lpvgf);
137 
138  i->move(moveVector);
139  i->rotateInGlobalFrame(rotation);
140  }
141 
142  this->addRotation(rotation);
143 
144  theSurface.rotate(rotation);
145 }
146 
147 //__________________________________________________________________________________________________
149  // Since no geomDet is attached, alignable composites do not have an APE
150  // The APE is, therefore, just propagated down
151  if (!propagateDown)
152  return;
153 
154  for (const auto& i : this->components()) {
155  i->setAlignmentPositionError(ape, propagateDown);
156  }
157 }
158 
159 //__________________________________________________________________________________________________
161  // Since no geomDet is attached, alignable composites do not have an APE
162  // The APE is, therefore, just propagated down
163  if (!propagateDown)
164  return;
165 
166  for (const auto& i : this->components()) {
167  i->addAlignmentPositionError(ape, propagateDown);
168  }
169 }
170 
171 //__________________________________________________________________________________________________
176  if (!propagateDown)
177  return;
178 
179  PositionType myPosition = this->globalPosition();
180 
181  for (const auto& i : this->components()) {
182  // It is just similar to to the "movement" that results to the components
183  // when the composite is rotated.
184  // Local Position given in coordinates of the GLOBAL Frame
185  const GlobalVector localPositionVector = i->globalPosition() - myPosition;
186  const GlobalVector::BasicVectorType& lpvgf = localPositionVector.basicVector();
187 
188  // rotate with GLOBAL rotation matrix and subtract => moveVector in global coordinates
189  // apparently... you have to use the inverse of the rotation here
190  // (rotate the VECTOR rather than the frame)
191  GlobalVector moveVector(rotation.multiplyInverse(lpvgf) - lpvgf);
192 
193  AlignmentPositionError ape(moveVector.x(), moveVector.y(), moveVector.z());
194  i->addAlignmentPositionError(ape, propagateDown);
195  i->addAlignmentPositionErrorFromRotation(rotation, propagateDown);
196  }
197 }
198 
199 //__________________________________________________________________________________________________
204  // if (!propagateDown) return; // No! Cannot yet jump out since
205  // addAlignmentPositionErrorFromRotation(..) below might be overwritten in derived
206  // classes to do something on 'this' (and in fact does so in AlignableDet).
207 
209  this->addAlignmentPositionErrorFromRotation(globalRot, propagateDown);
210 }
211 
212 //__________________________________________________________________________________________________
213 void AlignableComposite::setSurfaceDeformation(const SurfaceDeformation* deformation, bool propagateDown) {
214  // Only DetUnits have surface deformations.
215  // The parameters are, therefore, just propagated down.
216  if (!propagateDown)
217  return;
218 
219  for (const auto& i : this->components()) {
220  i->setSurfaceDeformation(deformation, propagateDown);
221  }
222 }
223 
224 //__________________________________________________________________________________________________
225 void AlignableComposite::addSurfaceDeformation(const SurfaceDeformation* deformation, bool propagateDown) {
226  // Only DetUnits have surface deformations.
227  // The parameters are, therefore, just propagated down.
228  if (!propagateDown)
229  return;
230 
231  for (const auto& i : this->components()) {
232  i->addSurfaceDeformation(deformation, propagateDown);
233  }
234 }
235 
236 //__________________________________________________________________________________________________
237 void AlignableComposite::dump(void) const {
238  // A simple printout method. Could be specialized in the implementation classes.
239 
240  const auto& comp = this->components();
241 
242  // Dump this
243  edm::LogInfo("AlignableDump") << " Alignable of type " << this->alignableObjectId() << " has " << comp.size()
244  << " components" << std::endl
245  << " position = " << this->globalPosition() << ", orientation:" << std::endl
246  << this->globalRotation();
247 
248  // Dump components
249  for (const auto& i : comp)
250  i->dump();
251 }
252 
253 //__________________________________________________________________________________________________
255  // Recursively call alignments, until we get to an AlignableDetUnit
256 
257  Alignments* m_alignments = new Alignments();
258 
259  // Add components recursively
260  for (const auto& i : this->components()) {
261  std::unique_ptr<Alignments> tmpAlignments{i->alignments()};
262  std::copy(tmpAlignments->m_align.begin(), tmpAlignments->m_align.end(), std::back_inserter(m_alignments->m_align));
263  }
264 
265  return m_alignments;
266 }
267 
268 //__________________________________________________________________________________________________
270  // Recursively call alignmentsErrors, until we get to an AlignableDetUnit
271 
272  AlignmentErrorsExtended* m_alignmentErrors = new AlignmentErrorsExtended();
273 
274  // Add components recursively
275  for (const auto& i : this->components()) {
276  std::unique_ptr<AlignmentErrorsExtended> tmpAlignmentErrorsExtended{i->alignmentErrors()};
277  std::copy(tmpAlignmentErrorsExtended->m_alignError.begin(),
278  tmpAlignmentErrorsExtended->m_alignError.end(),
279  std::back_inserter(m_alignmentErrors->m_alignError));
280  }
281 
282  return m_alignmentErrors;
283 }
284 
285 //__________________________________________________________________________________________________
286 int AlignableComposite::surfaceDeformationIdPairs(std::vector<std::pair<int, SurfaceDeformation*> >& result) const {
287  int count = 0;
288 
289  // Add components recursively
290  for (const auto& i : this->components()) {
291  count += i->surfaceDeformationIdPairs(result);
292  }
293 
294  return count;
295 }
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:45
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.
StructureType alignableObjectId() const override
Return the alignable type identifier.
AlignableComposite()
default constructor hidden
uint32_t ID
Definition: Definitions.h:24
int surfaceDeformationIdPairs(std::vector< std::pair< int, SurfaceDeformation * > > &) const override
Return surface deformations.
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
const Alignables & components() const override
Return vector of direct components.
void move(const GlobalVector &displacement)
const RotationType & globalRotation() const
Return the global orientation of the object.
Definition: Alignable.h:138
void move(const GlobalVector &displacement) override
Move with respect to the global reference frame.
void addAlignmentPositionErrorFromLocalRotation(const RotationType &rotation, bool propagateDown) override
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
void recursiveComponents(Alignables &result) const override
Provide all components, subcomponents etc. (cf. description in base class)
std::vector< AlignTransform > m_align
Definition: Alignments.h:19
void setAlignmentPositionError(const AlignmentPositionError &ape, bool propagateDown) override
AlignmentErrorsExtended * alignmentErrors() const override
Return vector of alignment errors.
tuple result
Definition: mps_fire.py:311
virtual void moveComponentsLocal(const LocalVector &localDisplacement)
Move with respect to the local reference frame.
StructureType theStructureType
Alignments * alignments() const override
Return alignment data.
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:64
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:132
void dump() const override
Recursive printout of alignable structure.
Log< level::Info, false > LogInfo
void setMother(Alignable *mother)
Assign mother to alignable.
Definition: Alignable.h:94
void addSurfaceDeformation(const SurfaceDeformation *deformation, bool propagateDown) override
const Alignables & deepComponents() const
Definition: Alignable.h:72
std::vector< AlignTransformErrorExtended > m_alignError
void addRotation(const RotationType &rotation)
Definition: Alignable.cc:193
void addDisplacement(const GlobalVector &displacement)
Definition: Alignable.cc:190
~AlignableComposite() override
deleting its components
void rotate(const RotationType &rotation)
align::Scalar Scalar
Definition: Alignable.h:29
const PositionType & globalPosition() const
Return the global position of the object.
Definition: Alignable.h:135
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:53
align::Alignables Alignables
Definition: Alignable.h:34
void addComponent(Alignable *component) final
AlignableSurface theSurface
Definition: Alignable.h:237
int size() const
Return number of direct components.
Definition: Alignable.h:68
Alignables theDeepComponents
Definition: Alignable.h:248