CMS 3D CMS Logo

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) {
18 }
19 
20 //__________________________________________________________________________________________________
22  : Alignable(id, rot), theStructureType(type) {
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 
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);
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 
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 }
Vector3DBase< Scalar, GlobalTag >
AlignmentErrorsExtended.h
TkRotation< Scalar >
AlCaHLTBitMon_QueryRunRegistry.comp
string comp
Definition: AlCaHLTBitMon_QueryRunRegistry.py:249
AlignableComposite::alignments
Alignments * alignments() const override
Return alignment data.
Definition: AlignableComposite.cc:254
Alignable::theDeepComponents
Alignables theDeepComponents
Definition: Alignable.h:248
mps_fire.i
i
Definition: mps_fire.py:428
GloballyPositioned::rotate
void rotate(const RotationType &rotation)
Definition: GloballyPositioned.h:136
MessageLogger.h
Alignable::Alignables
align::Alignables Alignables
Definition: Alignable.h:34
align
Definition: AlignableIndexer.h:30
GeomDet
Definition: GeomDet.h:27
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
AlignableComposite::components
const Alignables & components() const override
Return vector of direct components.
Definition: AlignableComposite.h:45
AlignableComposite::recursiveComponents
void recursiveComponents(Alignables &result) const override
Provide all components, subcomponents etc. (cf. description in base class)
Definition: AlignableComposite.cc:67
Alignable
Definition: Alignable.h:27
AlignableComposite::setSurfaceDeformation
void setSurfaceDeformation(const SurfaceDeformation *deformation, bool propagateDown) override
Set the surface deformation parameters - if (!propagateDown) do not affect daughters.
Definition: AlignableComposite.cc:213
Alignments.h
AlignableComposite::addSurfaceDeformation
void addSurfaceDeformation(const SurfaceDeformation *deformation, bool propagateDown) override
Definition: AlignableComposite.cc:225
TkRotation::multiplyInverse
Basic3DVector< T > multiplyInverse(const Basic3DVector< T > &v) const
Definition: extTkRotation.h:178
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
AlignableComposite::addAlignmentPositionErrorFromRotation
void addAlignmentPositionErrorFromRotation(const RotationType &rotation, bool propagateDown) override
Definition: AlignableComposite.cc:175
SurfaceDeformation
Definition: SurfaceDeformation.h:18
AlignableDet
Definition: AlignableDet.h:8
GeomDet::surface
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
Alignable::compConstraintType_
CompConstraintType compConstraintType_
Definition: Alignable.h:246
AlignableComposite::dump
void dump() const override
Recursive printout of alignable structure.
Definition: AlignableComposite.cc:237
Alignable::update
void update(align::ID, const AlignableSurface &)
Definition: Alignable.cc:45
AlignableComposite::addAlignmentPositionErrorFromLocalRotation
void addAlignmentPositionErrorFromLocalRotation(const RotationType &rotation, bool propagateDown) override
Definition: AlignableComposite.cc:203
AlignableComposite::addComponent
void addComponent(Alignable *component) final
Definition: AlignableComposite.cc:53
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
AlignableComposite::update
void update(align::ID, StructureType aType, const RotationType &rot=RotationType())
Definition: AlignableComposite.cc:43
Alignable::addRotation
void addRotation(const RotationType &rotation)
Definition: Alignable.cc:193
Alignable::surface
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:132
dqmdumpme.k
k
Definition: dqmdumpme.py:60
Point3DBase< Scalar, GlobalTag >
Alignable::displacement
const GlobalVector & displacement() const
Return change of the global position since the creation of the object.
Definition: Alignable.h:141
Alignable::Scalar
align::Scalar Scalar
Definition: Alignable.h:29
align::StructureType
StructureType
Definition: StructureType.h:16
GeomDet::geographicalId
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:64
Alignable::rotation
const RotationType & rotation() const
Return change of orientation since the creation of the object.
Definition: Alignable.h:144
idealTransformation.rotation
dictionary rotation
Definition: idealTransformation.py:1
align::ID
uint32_t ID
Definition: Definitions.h:24
type
type
Definition: SiPixelVCal_PayloadInspector.cc:39
AlignableComposite::theStructureType
StructureType theStructureType
Definition: AlignableComposite.h:114
AlignableComposite.h
AlignableComposite::AlignableComposite
AlignableComposite()
default constructor hidden
Definition: AlignableComposite.h:118
AlignableComposite::alignableObjectId
StructureType alignableObjectId() const override
Return the alignable type identifier.
Definition: AlignableComposite.h:86
GloballyPositioned::move
void move(const GlobalVector &displacement)
Definition: GloballyPositioned.h:128
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
Alignable::theSurface
AlignableSurface theSurface
Definition: Alignable.h:237
AlignmentErrorsExtended
Definition: AlignmentErrorsExtended.h:10
PV3DBase::basicVector
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:53
AlignableComposite::moveComponentLocal
virtual void moveComponentLocal(const int i, const LocalVector &localDisplacement)
Move a single component with respect to the local reference frame.
Definition: AlignableComposite.cc:96
Alignable::setMother
void setMother(Alignable *mother)
Assign mother to alignable.
Definition: Alignable.h:94
AlignableComposite::rotateInGlobalFrame
void rotateInGlobalFrame(const RotationType &rotation) override
Rotation interpreted in global reference frame.
Definition: AlignableComposite.cc:109
AlignableComposite::move
void move(const GlobalVector &displacement) override
Move with respect to the global reference frame.
Definition: AlignableComposite.cc:80
align::AlignableDet
Definition: StructureType.h:20
AlignableComposite::surfaceDeformationIdPairs
int surfaceDeformationIdPairs(std::vector< std::pair< int, SurfaceDeformation * > > &) const override
Return surface deformations.
Definition: AlignableComposite.cc:286
GeomDet.h
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
AlignableSurface
Definition: AlignableSurface.h:20
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
Alignable::deepComponents
const Alignables & deepComponents() const
Definition: Alignable.h:72
AlignableComposite::theComponents
Alignables theComponents
Definition: AlignableComposite.h:118
Exception
Definition: hltDiff.cc:245
Alignable::addDisplacement
void addDisplacement(const GlobalVector &displacement)
Definition: Alignable.cc:190
AlignableComposite::moveComponentsLocal
virtual void moveComponentsLocal(const LocalVector &localDisplacement)
Move with respect to the local reference frame.
Definition: AlignableComposite.cc:91
AlignmentPositionError.h
makeMuonMisalignmentScenario.rot
rot
Definition: makeMuonMisalignmentScenario.py:322
AlignableComposite::addAlignmentPositionError
void addAlignmentPositionError(const AlignmentPositionError &ape, bool propagateDown) override
Definition: AlignableComposite.cc:160
Exception.h
Alignments::m_align
std::vector< AlignTransform > m_align
Definition: Alignments.h:19
AlignmentErrorsExtended::m_alignError
std::vector< AlignTransformErrorExtended > m_alignError
Definition: AlignmentErrorsExtended.h:19
mps_fire.result
result
Definition: mps_fire.py:311
AlignableComposite::~AlignableComposite
~AlignableComposite() override
deleting its components
Definition: AlignableComposite.cc:27
Alignable::globalPosition
const PositionType & globalPosition() const
Return the global position of the object.
Definition: Alignable.h:135
AlignmentPositionError
Definition: AlignmentPositionError.h:10
AlignableComposite::setAlignmentPositionError
void setAlignmentPositionError(const AlignmentPositionError &ape, bool propagateDown) override
Definition: AlignableComposite.cc:148
Alignments
Definition: Alignments.h:10
AlignableComposite::alignmentErrors
AlignmentErrorsExtended * alignmentErrors() const override
Return vector of alignment errors.
Definition: AlignableComposite.cc:269
Alignable::CompConstraintType::POSITION
Basic3DVector< Scalar >
Alignable::globalRotation
const RotationType & globalRotation() const
Return the global orientation of the object.
Definition: Alignable.h:138
Alignable::size
int size() const
Return number of direct components.
Definition: Alignable.h:68