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 }
Vector3DBase< Scalar, GlobalTag >
Alignable::theDisplacement
GlobalVector theDisplacement
Definition: Alignable.h:239
TkRotation< Scalar >
Alignable::firstCompsWithParams
bool firstCompsWithParams(Alignables &paramComps) const
Definition: Alignable.cc:62
Alignable::Alignables
align::Alignables Alignables
Definition: Alignable.h:34
Alignable::setAlignmentParameters
void setAlignmentParameters(AlignmentParameters *dap)
Set the AlignmentParameters.
Definition: Alignable.cc:123
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
Alignable::theCachedSurface
AlignableSurface theCachedSurface
Definition: Alignable.h:242
Alignable::rotateInGlobalFrame
virtual void rotateInGlobalFrame(const RotationType &rotation)=0
align::RunNumber
cond::RealTimeType< cond::runnumber >::type RunNumber
Definition: Utilities.h:37
Alignable::rotateAroundGlobalX
virtual void rotateAroundGlobalX(Scalar radians)
Rotation around global x-axis.
Definition: Alignable.cc:148
Alignable::surfaceDeformationIdPairs
virtual int surfaceDeformationIdPairs(std::vector< std::pair< int, SurfaceDeformation * > > &) const =0
Alignable::restoreCachedTransformation
virtual void restoreCachedTransformation()
restore the previously cached transformation, also for possible components
Definition: Alignable.cc:237
Alignable::rotateAroundLocalAxis
virtual void rotateAroundLocalAxis(const LocalVector &axis, Scalar radians)
Rotation around arbitratry local axis.
Definition: Alignable.cc:143
Alignable::CompConstraintType::POSITION_Z
Alignable::Alignable
Alignable()
private default ctr. to enforce usage of the specialised ones
Definition: Alignable.h:257
Alignable::GlobalVector
align::GlobalVector GlobalVector
Definition: Alignable.h:32
Alignable::rotateAroundGlobalZ
virtual void rotateAroundGlobalZ(Scalar radians)
Rotation around global z-axis.
Definition: Alignable.cc:176
AlignmentParameters
Definition: AlignmentParameters.h:35
Alignable::surfaceDeformations
AlignmentSurfaceDeformations * surfaceDeformations() const
Return surface deformations, sorted by DetId.
Definition: Alignable.cc:196
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Alignable::surfacesCache_
Cache< AlignableSurface > surfacesCache_
Definition: Alignable.h:251
AlignmentParameters.h
SurveyDet
Definition: SurveyDet.h:15
Alignable::setSurvey
void setSurvey(const SurveyDet *)
Set survey info.
Definition: Alignable.cc:266
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Alignable::update
void update(align::ID, const AlignableSurface &)
Definition: Alignable.cc:45
Alignable::~Alignable
virtual ~Alignable()
Destructor.
Definition: Alignable.cc:39
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
Point3DBase< Scalar, GlobalTag >
Alignable::lastCompsWithParams
bool lastCompsWithParams(Alignables &paramComps) const
Definition: Alignable.cc:93
Alignable::displacement
const GlobalVector & displacement() const
Return change of the global position since the creation of the object.
Definition: Alignable.h:141
b
double b
Definition: hdecay.h:118
Alignable::rotateAroundGlobalY
virtual void rotateAroundGlobalY(Scalar radians)
Rotation around global y-axis.
Definition: Alignable.cc:162
Alignable::Scalar
align::Scalar Scalar
Definition: Alignable.h:29
first
auto first
Definition: CAHitNtupletGeneratorKernelsImpl.h:125
Alignable::theSurvey
const SurveyDet * theSurvey
Definition: Alignable.h:263
Alignable::theAlignmentParameters
AlignmentParameters * theAlignmentParameters
Definition: Alignable.h:257
SurfaceDeformation.h
Alignable::displacementsCache_
Cache< GlobalVector > displacementsCache_
Definition: Alignable.h:252
Alignable::updateMother
virtual void updateMother(const GlobalVector &shift)
Definition: Alignable.cc:272
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
a
double a
Definition: hdecay.h:119
align::ID
uint32_t ID
Definition: Definitions.h:24
Alignable::rotateAroundGlobalAxis
virtual void rotateAroundGlobalAxis(const GlobalVector &axis, Scalar radians)
Rotation around arbitratry global axis.
Definition: Alignable.cc:138
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
Alignable::RotationType
align::RotationType RotationType
Definition: Alignable.h:31
Alignable::rotateAroundLocalZ
virtual void rotateAroundLocalZ(Scalar radians)
Rotation around local z-axis.
Definition: Alignable.cc:183
Alignable::rotateInLocalFrame
virtual void rotateInLocalFrame(const RotationType &rotation)
Rotation intepreted in the local reference frame.
Definition: Alignable.cc:129
Alignable::CompConstraintType::NONE
GloballyPositioned::move
void move(const GlobalVector &displacement)
Definition: GloballyPositioned.h:128
AlignmentSurfaceDeformations
Definition: AlignmentSurfaceDeformations.h:20
Alignable::theSurface
AlignableSurface theSurface
Definition: Alignable.h:237
Alignable::theCachedRotation
RotationType theCachedRotation
Definition: Alignable.h:244
Alignable::rotateAroundLocalX
virtual void rotateAroundLocalX(Scalar radians)
Rotation around local x-axis.
Definition: Alignable.cc:155
Alignable::theMother
Alignable * theMother
Definition: Alignable.h:261
PV3DBase::basicVector
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:53
GloballyPositioned::position
const PositionType & position() const
Definition: GloballyPositioned.h:36
writedatasetfile.run
run
Definition: writedatasetfile.py:27
edm::shift
static unsigned const int shift
Definition: LuminosityBlockID.cc:7
AlignableSurface
Definition: AlignableSurface.h:20
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
AlignmentSurfaceDeformations.h
Alignable::rotationsCache_
Cache< RotationType > rotationsCache_
Definition: Alignable.h:253
Alignable::deepComponents
const Alignables & deepComponents() const
Definition: Alignable.h:72
Alignable::rotateAroundLocalY
virtual void rotateAroundLocalY(Scalar radians)
Rotation around local y-axis.
Definition: Alignable.cc:169
Exception
Definition: hltDiff.cc:245
Alignable::theCachedDisplacement
GlobalVector theCachedDisplacement
Definition: Alignable.h:243
Alignable::addDisplacement
void addDisplacement(const GlobalVector &displacement)
Definition: Alignable.cc:190
makeMuonMisalignmentScenario.rot
rot
Definition: makeMuonMisalignmentScenario.py:322
Alignable.h
Alignable::theId
align::ID theId
Definition: Alignable.h:235
Alignable::theRotation
RotationType theRotation
Definition: Alignable.h:240
Exception.h
Alignable::cacheTransformation
virtual void cacheTransformation()
cache the current position, rotation and other parameters (e.g. surface deformations),...
Definition: Alignable.cc:215
mps_fire.result
result
Definition: mps_fire.py:311
SurveyDet.h
Alignable::globalPosition
const PositionType & globalPosition() const
Return the global position of the object.
Definition: Alignable.h:135
Alignable::components
virtual const Alignables & components() const =0
Return vector of all direct components.
Alignable::survey
const SurveyDet * survey() const
Return survey info.
Definition: Alignable.h:216
Alignable::recenterSurface
virtual void recenterSurface()
Recenter surface object without moving possible components.
Definition: Alignable.cc:295
Alignable::CompConstraintType::POSITION
Alignable::compConstraintType
virtual CompConstraintType compConstraintType() const
Return the alignable type of contraints wrt. its components.
Definition: Alignable.h:183