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