CMS 3D CMS Logo

Alignable.cc
Go to the documentation of this file.
1 
10 
12 
14 
17 
18 //__________________________________________________________________________________________________
20  : theDetId(id), // FIXME: inconsistent with other ctr., but needed for AlignableNavigator
21  theId(id), // (finally get rid of one of the IDs!)
22  theSurface(surf),
23  theCachedSurface(surf),
24  theAlignmentParameters(nullptr),
25  theMother(nullptr),
26  theSurvey(nullptr) {}
27 
28 //__________________________________________________________________________________________________
30  : theDetId(), // FIXME: inconsistent with other ctr., cf. above
31  theId(id),
32  theSurface(PositionType(), rot),
33  theCachedSurface(PositionType(), rot),
34  theAlignmentParameters(nullptr),
35  theMother(nullptr),
36  theSurvey(nullptr) {}
37 
38 //__________________________________________________________________________________________________
41  delete theSurvey;
42 }
43 
44 //__________________________________________________________________________________________________
46  if (theId != id) {
47  throw cms::Exception("Alignment") << "@SUB=Alignable::update\n"
48  << "Current alignable ID does not match ID of the update.";
49  }
50  const auto shift = surf.position() - theSurface.position();
51  theSurface = surf;
52 
53  // reset displacement and rotations after update
56 
57  // recalculate containing composite's position
59 }
60 
61 //__________________________________________________________________________________________________
63  bool isConsistent = true;
64  bool hasAliComp = false; // whether there are any (grand-) daughters with parameters
65  bool first = true;
66  const auto& comps = this->components();
67  for (const auto& iComp : comps) {
68  if (iComp->alignmentParameters()) { // component has parameters itself
69  paramComps.push_back(iComp);
70  if (!first && !hasAliComp)
71  isConsistent = false;
72  hasAliComp = true;
73  } else {
74  const unsigned int nCompBefore = paramComps.size();
75  if (!(iComp->firstCompsWithParams(paramComps))) {
76  isConsistent = false; // problem down in hierarchy
77  }
78  if (paramComps.size() != nCompBefore) {
79  if (!first && !hasAliComp)
80  isConsistent = false;
81  hasAliComp = true;
82  } else if (hasAliComp) { // no components with params, but previous component did have comps.
83  isConsistent = false;
84  }
85  }
86  first = false;
87  }
88 
89  return isConsistent;
90 }
91 
92 //__________________________________________________________________________________________________
93 bool Alignable::lastCompsWithParams(Alignables& paramComps) const {
94  bool isConsistent = true;
95  bool hasAliComp = false;
96  bool first = true;
97  const auto& comps = this->components();
98  for (const auto& iComp : comps) {
99  const auto nCompsBefore = paramComps.size();
100  isConsistent = iComp->lastCompsWithParams(paramComps);
101  if (paramComps.size() == nCompsBefore) {
102  if (iComp->alignmentParameters()) {
103  paramComps.push_back(iComp);
104  if (!first && !hasAliComp)
105  isConsistent = false;
106  hasAliComp = true;
107  }
108  } else {
109  if (hasAliComp) {
110  isConsistent = false;
111  }
112  if (!first && !hasAliComp)
113  isConsistent = false;
114  hasAliComp = true;
115  }
116  first = false;
117  }
118 
119  return isConsistent;
120 }
121 
122 //__________________________________________________________________________________________________
124  delete theAlignmentParameters;
126 }
127 
128 //__________________________________________________________________________________________________
130  // This is done by simply transforming the rotation from
131  // the local system O to the global one O^-1 * Rot * O
132  // and then applying the global rotation O * Rot
133 
134  rotateInGlobalFrame(surface().toGlobal(rotation));
135 }
136 
137 //__________________________________________________________________________________________________
139  rotateInGlobalFrame(RotationType(axis.basicVector(), radians));
140 }
141 
142 //__________________________________________________________________________________________________
144  rotateInLocalFrame(RotationType(axis.basicVector(), radians));
145 }
146 
147 //__________________________________________________________________________________________________
149  RotationType rot(1., 0., 0., 0., std::cos(radians), std::sin(radians), 0., -std::sin(radians), std::cos(radians));
150 
152 }
153 
154 //__________________________________________________________________________________________________
156  RotationType rot(1., 0., 0., 0., std::cos(radians), std::sin(radians), 0., -std::sin(radians), std::cos(radians));
157 
159 }
160 
161 //__________________________________________________________________________________________________
163  RotationType rot(std::cos(radians), 0., -std::sin(radians), 0., 1., 0., std::sin(radians), 0., std::cos(radians));
164 
166 }
167 
168 //__________________________________________________________________________________________________
170  RotationType rot(std::cos(radians), 0., -std::sin(radians), 0., 1., 0., std::sin(radians), 0., std::cos(radians));
171 
173 }
174 
175 //__________________________________________________________________________________________________
177  RotationType rot(std::cos(radians), std::sin(radians), 0., -std::sin(radians), std::cos(radians), 0., 0., 0., 1.);
178 
180 }
181 
182 //__________________________________________________________________________________________________
184  RotationType rot(std::cos(radians), std::sin(radians), 0., -std::sin(radians), std::cos(radians), 0., 0., 0., 1.);
185 
187 }
188 
189 //__________________________________________________________________________________________________
191 
192 //__________________________________________________________________________________________________
194 
195 //__________________________________________________________________________________________________
197  typedef std::pair<int, SurfaceDeformation*> IdSurfaceDeformationPtrPair;
198 
199  std::vector<IdSurfaceDeformationPtrPair> result;
201  std::sort(result.begin(), result.end(), [](auto& a, auto& b) { return a.first < b.first; });
202 
203  AlignmentSurfaceDeformations* allSurfaceDeformations = new AlignmentSurfaceDeformations();
204 
205  for (std::vector<IdSurfaceDeformationPtrPair>::const_iterator iPair = result.begin(); iPair != result.end();
206  ++iPair) {
207  // should we check for 'empty' parameters here (all zeros) and skip ?
208  // may be add 'empty' method to SurfaceDeformation
209  allSurfaceDeformations->add((*iPair).first, (*iPair).second->type(), (*iPair).second->parameters());
210  }
211 
212  return allSurfaceDeformations;
213 }
214 
216  // first treat itself
220 
221  // now treat components (a clean design would move that to AlignableComposite...)
222  for (const auto& it : this->components())
223  it->cacheTransformation();
224 }
225 
227  // first treat itself
231 
232  // now treat components (a clean design would move that to AlignableComposite...)
233  for (const auto& it : this->components())
234  it->cacheTransformation(run);
235 }
236 
238  // first treat itself
242 
243  // now treat components (a clean design would move that to AlignableComposite...)
244  for (const auto& it : this->components())
245  it->restoreCachedTransformation();
246 }
247 
249  if (surfacesCache_.find(run) == surfacesCache_.end()) {
250  throw cms::Exception("Alignment") << "@SUB=Alignable::restoreCachedTransformation\n"
251  << "Trying to restore cached transformation for a run (" << run
252  << ") that has not been cached.";
253  } else {
254  // first treat itself
258 
259  // now treat components (a clean design would move that to AlignableComposite...)
260  for (const auto& it : this->components())
261  it->restoreCachedTransformation();
262  }
263 }
264 
265 //__________________________________________________________________________________________________
266 void Alignable::setSurvey(const SurveyDet* survey) {
267  delete theSurvey;
268  theSurvey = survey;
269 }
270 
271 //______________________________________________________________________________
273  if (!theMother)
274  return;
275 
276  const auto thisComps = this->deepComponents().size();
277  const auto motherComps = theMother->deepComponents().size();
278  const auto motherShift = shift * static_cast<Scalar>(thisComps) / motherComps;
279 
280  switch (theMother->compConstraintType()) {
282  break;
284  theMother->theSurface.move(GlobalVector(0, 0, motherShift.z()));
285  theMother->updateMother(GlobalVector(0, 0, motherShift.z()));
286  break;
288  theMother->theSurface.move(motherShift);
289  theMother->updateMother(motherShift);
290  break;
291  }
292 }
293 
294 //______________________________________________________________________________
296  const auto& currentPosition = this->globalPosition();
297  theSurface.move(align::GlobalVector{-currentPosition.x(), -currentPosition.y(), -currentPosition.z()});
298 }
RotationType theCachedRotation
Definition: Alignable.h:244
AlignmentSurfaceDeformations * surfaceDeformations() const
Return surface deformations, sorted by DetId.
Definition: Alignable.cc:196
void update(align::ID, const AlignableSurface &)
Definition: Alignable.cc:45
virtual void rotateInLocalFrame(const RotationType &rotation)
Rotation intepreted in the local reference frame.
Definition: Alignable.cc:129
RotationType theRotation
Definition: Alignable.h:240
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:132
virtual void rotateAroundLocalZ(Scalar radians)
Rotation around local z-axis.
Definition: Alignable.cc:183
virtual void rotateAroundLocalAxis(const LocalVector &axis, Scalar radians)
Rotation around arbitratry local axis.
Definition: Alignable.cc:143
Alignable()
private default ctr. to enforce usage of the specialised ones
Definition: Alignable.h:257
uint32_t ID
Definition: Definitions.h:24
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Alignable * theMother
Definition: Alignable.h:261
void move(const GlobalVector &displacement)
Cache< GlobalVector > displacementsCache_
Definition: Alignable.h:252
Cache< AlignableSurface > surfacesCache_
Definition: Alignable.h:251
const Alignables & deepComponents() const
Definition: Alignable.h:72
Cache< RotationType > rotationsCache_
Definition: Alignable.h:253
virtual void rotateAroundGlobalAxis(const GlobalVector &axis, Scalar radians)
Rotation around arbitratry global axis.
Definition: Alignable.cc:138
GlobalVector theDisplacement
Definition: Alignable.h:239
virtual void rotateAroundGlobalZ(Scalar radians)
Rotation around global z-axis.
Definition: Alignable.cc:176
T x() const
Definition: PV3DBase.h:59
bool firstCompsWithParams(Alignables &paramComps) const
Definition: Alignable.cc:62
virtual void recenterSurface()
Recenter surface object without moving possible components.
Definition: Alignable.cc:295
const PositionType & globalPosition() const
Return the global position of the object.
Definition: Alignable.h:135
AlignmentParameters * theAlignmentParameters
Definition: Alignable.h:259
void setAlignmentParameters(AlignmentParameters *dap)
Set the AlignmentParameters.
Definition: Alignable.cc:123
const SurveyDet * survey() const
Return survey info.
Definition: Alignable.h:216
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
virtual void restoreCachedTransformation()
restore the previously cached transformation, also for possible components
Definition: Alignable.cc:237
virtual const Alignables & components() const =0
Return vector of all direct components.
virtual void updateMother(const GlobalVector &shift)
Definition: Alignable.cc:272
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:53
virtual CompConstraintType compConstraintType() const
Return the alignable type of contraints wrt. its components.
Definition: Alignable.h:183
AlignableSurface theCachedSurface
Definition: Alignable.h:242
const PositionType & position() const
virtual void rotateAroundGlobalX(Scalar radians)
Rotation around global x-axis.
Definition: Alignable.cc:148
virtual void rotateInGlobalFrame(const RotationType &rotation)=0
void setSurvey(const SurveyDet *)
Set survey info.
Definition: Alignable.cc:266
void addRotation(const RotationType &rotation)
Definition: Alignable.cc:193
double b
Definition: hdecay.h:120
align::RotationType RotationType
Definition: Alignable.h:31
bool lastCompsWithParams(Alignables &paramComps) const
Definition: Alignable.cc:93
const GlobalVector & displacement() const
Return change of the global position since the creation of the object.
Definition: Alignable.h:141
GlobalVector theCachedDisplacement
Definition: Alignable.h:243
virtual void rotateAroundLocalY(Scalar radians)
Rotation around local y-axis.
Definition: Alignable.cc:169
virtual void rotateAroundGlobalY(Scalar radians)
Rotation around global y-axis.
Definition: Alignable.cc:162
void addDisplacement(const GlobalVector &displacement)
Definition: Alignable.cc:190
virtual void cacheTransformation()
cache the current position, rotation and other parameters (e.g. surface deformations), also for possible components
Definition: Alignable.cc:215
double a
Definition: hdecay.h:121
virtual void rotateAroundLocalX(Scalar radians)
Rotation around local x-axis.
Definition: Alignable.cc:155
static unsigned int const shift
align::Scalar Scalar
Definition: Alignable.h:29
virtual int surfaceDeformationIdPairs(std::vector< std::pair< int, SurfaceDeformation *> > &) const =0
align::GlobalVector GlobalVector
Definition: Alignable.h:32
align::ID theId
Definition: Alignable.h:235
virtual ~Alignable()
Destructor.
Definition: Alignable.cc:39
const SurveyDet * theSurvey
Definition: Alignable.h:263
align::Alignables Alignables
Definition: Alignable.h:34
AlignableSurface theSurface
Definition: Alignable.h:237
cond::RealTimeType< cond::runnumber >::type RunNumber
Definition: Utilities.h:37
const RotationType & rotation() const
Return change of orientation since the creation of the object.
Definition: Alignable.h:144