CMS 3D CMS Logo

AlignableDetUnit.cc
Go to the documentation of this file.
2 
4 
7 #include "CLHEP/Vector/RotationInterfaces.h"
10 
13 
14 //__________________________________________________________________________________________________
16  : // rely on non-NULL pointer!
17  Alignable(geomDetUnit->geographicalId().rawId(), geomDetUnit->surface()),
18  theAlignmentPositionError(nullptr),
19  theSurfaceDeformation(nullptr),
20  theCachedSurfaceDeformation(nullptr) {
21  if (geomDetUnit->alignmentPositionError()) { // take over APE from geometry
22  // 2nd argument w/o effect:
23  this->setAlignmentPositionError(*(geomDetUnit->alignmentPositionError()), false);
24  }
25 
26  if (geomDetUnit->surfaceDeformation()) { // take over surface modification
27  // 2nd argument w/o effect:
28  this->setSurfaceDeformation(geomDetUnit->surfaceDeformation(), false);
29  }
30 
31  theDeepComponents.push_back(this);
32 }
33 
34 //__________________________________________________________________________________________________
37  delete theSurfaceDeformation;
40  delete surface.second;
41 }
42 
43 //__________________________________________________________________________________________________
44 void AlignableDetUnit::update(const GeomDetUnit* geomDetUnit) {
45  if (!geomDetUnit) {
46  throw cms::Exception("Alignment") << "@SUB=AlignableDetUnit::update\n"
47  << "Trying to update with GeomDetUnit* pointing to 'nullptr'.";
48  }
49 
50  Alignable::update(geomDetUnit->geographicalId().rawId(), geomDetUnit->surface());
51 
52  if (geomDetUnit->alignmentPositionError()) { // take over APE from geometry
53  // 2nd argument w/o effect:
54  this->setAlignmentPositionError(*(geomDetUnit->alignmentPositionError()), false);
55  }
56 
57  if (geomDetUnit->surfaceDeformation()) { // take over surface modification
58  // 2nd argument w/o effect:
59  this->setSurfaceDeformation(geomDetUnit->surfaceDeformation(), false);
60  }
61 }
62 
63 //__________________________________________________________________________________________________
65  throw cms::Exception("LogicError") << "AlignableDetUnit cannot have components, but try to add one!";
66 }
67 
68 //__________________________________________________________________________________________________
69 void AlignableDetUnit::move(const GlobalVector& displacement) {
71  this->addDisplacement(displacement);
72 }
73 
74 //__________________________________________________________________________________________________
77  this->addRotation(rotation);
78 }
79 
80 //__________________________________________________________________________________________________
81 void AlignableDetUnit::setAlignmentPositionError(const AlignmentPositionError& ape, bool /*propagateDown*/) {
84  else
86 }
87 
88 //__________________________________________________________________________________________________
91  this->setAlignmentPositionError(ape, propagateDown); // 2nd argument w/o effect
92  else
94 }
95 
96 //__________________________________________________________________________________________________
98  // average error calculated by movement of a local point at
99  // (xWidth/2,yLength/2,0) caused by the rotation rot
100  GlobalVector localPositionVector =
101  surface().toGlobal(LocalVector(.5 * surface().width(), .5 * surface().length(), 0.));
102 
103  const LocalVector::BasicVectorType& lpvgf = localPositionVector.basicVector();
104  GlobalVector gv(rot.multiplyInverse(lpvgf) - lpvgf);
105 
106  AlignmentPositionError ape(gv.x(), gv.y(), gv.z());
107  this->addAlignmentPositionError(ape, propagateDown); // 2nd argument w/o effect
108 }
109 
110 //__________________________________________________________________________________________________
113  this->addAlignmentPositionErrorFromRotation(globalRot, propagateDown); // 2nd argument w/o effect
114 }
115 
116 //__________________________________________________________________________________________________
117 void AlignableDetUnit::setSurfaceDeformation(const SurfaceDeformation* deformation, bool /* propagateDown */) {
118  delete theSurfaceDeformation; // OK for zero pointers
119  if (deformation) {
120  theSurfaceDeformation = deformation->clone();
121  } else {
122  theSurfaceDeformation = nullptr;
123  }
124 }
125 
126 //__________________________________________________________________________________________________
127 void AlignableDetUnit::addSurfaceDeformation(const SurfaceDeformation* deformation, bool propagateDown) {
128  if (!deformation) {
129  // nothing to do
130  } else if (!theSurfaceDeformation) {
131  this->setSurfaceDeformation(deformation, propagateDown); // fine since no components
132  } else if (!theSurfaceDeformation->add(*deformation)) {
133  edm::LogError("Alignment") << "@SUB=AlignableDetUnit::addSurfaceDeformation"
134  << "Cannot add deformation type " << deformation->type() << " to type "
135  << theSurfaceDeformation->type() << ", so erase deformation information.";
136  delete theSurfaceDeformation;
137  theSurfaceDeformation = nullptr;
138  }
139 }
140 
141 //__________________________________________________________________________________________________
143  std::ostringstream parameters;
144  if (theSurfaceDeformation) {
145  parameters << " surface deformation parameters:";
146  for (const auto& param : theSurfaceDeformation->parameters()) {
147  parameters << " " << param;
148  }
149  } else {
150  parameters << " no surface deformation parameters";
151  }
152 
153  edm::LogInfo("AlignableDump") << " AlignableDetUnit has position = " << this->globalPosition()
154  << ", orientation:" << std::endl
155  << this->globalRotation() << std::endl
156  << " total displacement and rotation: " << this->displacement() << std::endl
157  << this->rotation() << "\n"
158  << parameters.str();
159 }
160 
161 //__________________________________________________________________________________________________
163  Alignments* m_alignments = new Alignments();
165 
166  // Get alignments (position, rotation, detId)
167  CLHEP::Hep3Vector clhepVector(globalPosition().x(), globalPosition().y(), globalPosition().z());
168  CLHEP::HepRotation clhepRotation(
169  CLHEP::HepRep3x3(rot.xx(), rot.xy(), rot.xz(), rot.yx(), rot.yy(), rot.yz(), rot.zx(), rot.zy(), rot.zz()));
170  uint32_t detId = this->geomDetId().rawId();
171 
172  AlignTransform transform(clhepVector, clhepRotation, detId);
173 
174  // Add to alignments container
175  m_alignments->m_align.push_back(transform);
176 
177  return m_alignments;
178 }
179 
180 //__________________________________________________________________________________________________
182  AlignmentErrorsExtended* m_alignmentErrors = new AlignmentErrorsExtended();
183 
184  uint32_t detId = this->geomDetId().rawId();
185 
186  CLHEP::HepSymMatrix clhepSymMatrix(6, 0);
187  if (theAlignmentPositionError) // Might not be set
189 
190  AlignTransformErrorExtended transformError(clhepSymMatrix, detId);
191 
192  m_alignmentErrors->m_alignError.push_back(transformError);
193 
194  return m_alignmentErrors;
195 }
196 
197 //__________________________________________________________________________________________________
198 int AlignableDetUnit::surfaceDeformationIdPairs(std::vector<std::pair<int, SurfaceDeformation*> >& result) const {
199  if (theSurfaceDeformation) {
200  result.push_back(std::pair<int, SurfaceDeformation*>(this->geomDetId().rawId(), theSurfaceDeformation));
201  return 1;
202  }
203 
204  return 0;
205 }
206 
207 //__________________________________________________________________________________________________
212 
215  theCachedSurfaceDeformation = nullptr;
216  }
217 
220 }
221 
222 //__________________________________________________________________________________________________
227 
228  auto existingCache = surfaceDeformationsCache_.find(run);
229  if (existingCache != surfaceDeformationsCache_.end()) {
230  delete existingCache->second;
231  existingCache->second = nullptr;
232  }
233 
234  if (theSurfaceDeformation) {
236  }
237 }
238 
239 //__________________________________________________________________________________________________
244 
245  if (theSurfaceDeformation) {
246  delete theSurfaceDeformation;
247  theSurfaceDeformation = nullptr;
248  }
249 
252  }
253 }
254 
255 //__________________________________________________________________________________________________
257  if (surfacesCache_.find(run) == surfacesCache_.end()) {
258  throw cms::Exception("Alignment") << "@SUB=Alignable::restoreCachedTransformation\n"
259  << "Trying to restore cached transformation for a run (" << run
260  << ") that has not been cached.";
261  } else {
265 
266  if (theSurfaceDeformation) {
267  delete theSurfaceDeformation;
268  theSurfaceDeformation = nullptr;
269  }
270 
273  }
274  }
275 }
276 
277 //______________________________________________________________________________
align::GlobalPoints toGlobal(const align::LocalPoints &) const
Return in global coord given a set of local points.
const AlgebraicSymMatrix66 & matrix() const
void dump() const override
Printout information about GeomDet.
RotationType theCachedRotation
Definition: Alignable.h:244
CLHEP::HepMatrix asHepMatrix(const ROOT::Math::SMatrix< double, N1, N2, typename ROOT::Math::MatRepStd< double, N1, N2 > > &rm)
Definition: Migration.h:60
void update(align::ID, const AlignableSurface &)
Definition: Alignable.cc:45
AlignmentErrorsExtended * alignmentErrors() const override
Return vector of alignment errors.
RotationType theRotation
Definition: Alignable.h:240
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:132
Cache< SurfaceDeformation * > surfaceDeformationsCache_
void move(const GlobalVector &displacement)
Cache< GlobalVector > displacementsCache_
Definition: Alignable.h:252
void setSurfaceDeformation(const SurfaceDeformation *deformation, bool) final
Set surface deformation parameters (2nd argument without effect)
Cache< AlignableSurface > surfacesCache_
Definition: Alignable.h:251
Log< level::Error, false > LogError
Cache< RotationType > rotationsCache_
Definition: Alignable.h:253
align::LocalVector LocalVector
Definition: Alignable.h:33
std::vector< AlignTransform > m_align
Definition: Alignments.h:19
GlobalVector theDisplacement
Definition: Alignable.h:239
SurfaceDeformation * theCachedSurfaceDeformation
static const Alignables emptyComponents_
void update(const GeomDetUnit *geomDetUnit)
const PositionType & globalPosition() const
Return the global position of the object.
Definition: Alignable.h:135
~AlignableDetUnit() override
Destructor.
int surfaceDeformationIdPairs(std::vector< std::pair< int, SurfaceDeformation *> > &) const override
Return surface deformations.
AlignableDetUnit(const GeomDetUnit *geomDetUnit)
Constructor from GeomDetUnit - must not be NULL pointer!
void cacheTransformation() override
cache the current position, rotation and other parameters (e.g. surface deformations) ...
AlignmentPositionError const * alignmentPositionError() const
Return pointer to alignment errors.
Definition: GeomDet.h:80
virtual std::vector< double > parameters() const =0
parameters - interpretation left to the concrete implementation
void addComponent(Alignable *) final
No components here => exception!
void setAlignmentPositionError(const AlignmentPositionError &ape, bool) final
Set the AlignmentPositionError (no components => second argument ignored)
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:64
void addAlignmentPositionError(const AlignmentPositionError &ape, bool) final
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:53
Log< level::Info, false > LogInfo
AlignableSurface theCachedSurface
Definition: Alignable.h:242
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
Basic3DVector< T > multiplyInverse(const Basic3DVector< T > &v) const
std::vector< AlignTransformErrorExtended > m_alignError
const DetId & geomDetId() const
Definition: Alignable.h:177
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
void addRotation(const RotationType &rotation)
Definition: Alignable.cc:193
virtual SurfaceDeformation * clone() const =0
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
const GlobalErrorExtended & globalError() const
void addAlignmentPositionErrorFromRotation(const RotationType &rot, bool) final
virtual int type() const =0
specific type, i.e. SurfaceDeformationFactory::Type
void addDisplacement(const GlobalVector &displacement)
Definition: Alignable.cc:190
std::vector< Alignable * > Alignables
Definition: Utilities.h:31
void addAlignmentPositionErrorFromLocalRotation(const RotationType &rot, bool) final
virtual bool add(const SurfaceDeformation &other)=0
void rotate(const RotationType &rotation)
AlignmentPositionError * theAlignmentPositionError
void addSurfaceDeformation(const SurfaceDeformation *deformation, bool) final
Add surface deformation parameters to the existing ones (2nd argument without effect) ...
const RotationType & globalRotation() const
Return the global orientation of the object.
Definition: Alignable.h:138
virtual const SurfaceDeformation * surfaceDeformation() const
Definition: GeomDet.h:96
void move(const GlobalVector &displacement) override
Move with respect to the global reference frame.
void rotateInGlobalFrame(const RotationType &rotation) override
Rotation with respect to the global reference frame.
Alignments * alignments() const override
Return vector of alignment data.
SurfaceDeformation * theSurfaceDeformation
AlignableSurface theSurface
Definition: Alignable.h:237
Alignables theDeepComponents
Definition: Alignable.h:248
cond::RealTimeType< cond::runnumber >::type RunNumber
Definition: Utilities.h:37
void restoreCachedTransformation() override
restore the previously cached transformation
const RotationType & rotation() const
Return change of orientation since the creation of the object.
Definition: Alignable.h:144
unsigned transform(const HcalDetId &id, unsigned transformCode)