CMS 3D CMS Logo

AlignableDetUnit.cc
Go to the documentation of this file.
2 
4 
7 #include "CLHEP/Vector/RotationInterfaces.h"
10 
13 
14 //__________________________________________________________________________________________________
15 AlignableDetUnit::AlignableDetUnit(const GeomDetUnit *geomDetUnit) : // rely on non-NULL pointer!
16  Alignable(geomDetUnit->geographicalId().rawId(), geomDetUnit->surface()),
17  theAlignmentPositionError(nullptr),
18  theSurfaceDeformation(nullptr),
19  theCachedSurfaceDeformation(nullptr)
20 {
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 
35 //__________________________________________________________________________________________________
37 {
39  delete theSurfaceDeformation;
41  for (auto surface: surfaceDeformationsCache_) delete surface.second;
42 }
43 
44 //__________________________________________________________________________________________________
45 void AlignableDetUnit::update(const GeomDetUnit *geomDetUnit)
46 {
47  if (!geomDetUnit) {
48  throw cms::Exception("Alignment")
49  << "@SUB=AlignableDetUnit::update\n"
50  << "Trying to update with GeomDetUnit* pointing to 'nullptr'.";
51  }
52 
53  Alignable::update(geomDetUnit->geographicalId().rawId(), geomDetUnit->surface());
54 
55  if (geomDetUnit->alignmentPositionError()) { // take over APE from geometry
56  // 2nd argument w/o effect:
57  this->setAlignmentPositionError(*(geomDetUnit->alignmentPositionError()), false);
58  }
59 
60  if (geomDetUnit->surfaceDeformation()) { // take over surface modification
61  // 2nd argument w/o effect:
62  this->setSurfaceDeformation(geomDetUnit->surfaceDeformation(), false);
63  }
64 }
65 
66 //__________________________________________________________________________________________________
68 {
69  throw cms::Exception("LogicError")
70  << "AlignableDetUnit cannot have components, but try to add one!";
71 }
72 
73 //__________________________________________________________________________________________________
75 {
76 
77  theSurface.move( displacement );
78  this->addDisplacement( displacement );
79 
80 }
81 
82 
83 //__________________________________________________________________________________________________
85 {
86 
87  theSurface.rotate( rotation );
88  this->addRotation( rotation );
89 
90 }
91 
92 
93 //__________________________________________________________________________________________________
95  bool /*propagateDown*/)
96 {
97 
100  else
102 
103 }
104 
105 
106 //__________________________________________________________________________________________________
108  bool propagateDown )
109 {
110 
112  this->setAlignmentPositionError( ape, propagateDown ); // 2nd argument w/o effect
113  else
115 }
116 
117 
118 //__________________________________________________________________________________________________
120  bool propagateDown )
121 {
122 
123  // average error calculated by movement of a local point at
124  // (xWidth/2,yLength/2,0) caused by the rotation rot
125  GlobalVector localPositionVector = surface().toGlobal( LocalVector(.5 * surface().width(),
126  .5 * surface().length(),
127  0.) );
128 
129  const LocalVector::BasicVectorType& lpvgf = localPositionVector.basicVector();
130  GlobalVector gv( rot.multiplyInverse(lpvgf) - lpvgf );
131 
132  AlignmentPositionError ape( gv.x(),gv.y(),gv.z() );
133  this->addAlignmentPositionError( ape, propagateDown ); // 2nd argument w/o effect
134 
135 }
136 
137 
138 //__________________________________________________________________________________________________
140  bool propagateDown )
141 {
142 
144  this->addAlignmentPositionErrorFromRotation(globalRot, propagateDown); // 2nd argument w/o effect
145 
146 }
147 
148 //__________________________________________________________________________________________________
150  bool /* propagateDown */ )
151 {
152  delete theSurfaceDeformation; // OK for zero pointers
153  if (deformation) {
154  theSurfaceDeformation = deformation->clone();
155  } else {
156  theSurfaceDeformation = nullptr;
157  }
158 }
159 
160 //__________________________________________________________________________________________________
162  bool propagateDown)
163 {
164  if (!deformation) {
165  // nothing to do
166  } else if (!theSurfaceDeformation) {
167  this->setSurfaceDeformation(deformation, propagateDown); // fine since no components
168  } else if (!theSurfaceDeformation->add(*deformation)) {
169  edm::LogError("Alignment") << "@SUB=AlignableDetUnit::addSurfaceDeformation"
170  << "Cannot add deformation type " << deformation->type()
171  << " to type " << theSurfaceDeformation->type()
172  << ", so erase deformation information.";
173  delete theSurfaceDeformation;
174  theSurfaceDeformation = nullptr;
175  }
176 }
177 
178 //__________________________________________________________________________________________________
180 {
181  std::ostringstream parameters;
182  if (theSurfaceDeformation) {
183  parameters << " surface deformation parameters:";
184  for (const auto& param: theSurfaceDeformation->parameters()) {
185  parameters << " " << param;
186  }
187  } else {
188  parameters << " no surface deformation parameters";
189  }
190 
191  edm::LogInfo("AlignableDump")
192  << " AlignableDetUnit has position = " << this->globalPosition()
193  << ", orientation:" << std::endl << this->globalRotation() << std::endl
194  << " total displacement and rotation: " << this->displacement() << std::endl
195  << this->rotation() << "\n"
196  << parameters.str();
197 }
198 
199 
200 //__________________________________________________________________________________________________
202 {
203  Alignments* m_alignments = new Alignments();
204  RotationType rot( this->globalRotation() );
205 
206  // Get alignments (position, rotation, detId)
207  CLHEP::Hep3Vector clhepVector( globalPosition().x(), globalPosition().y(), globalPosition().z() );
208  CLHEP::HepRotation clhepRotation( CLHEP::HepRep3x3( rot.xx(), rot.xy(), rot.xz(),
209  rot.yx(), rot.yy(), rot.yz(),
210  rot.zx(), rot.zy(), rot.zz() ) );
211  uint32_t detId = this->geomDetId().rawId();
212 
213  AlignTransform transform( clhepVector, clhepRotation, detId );
214 
215  // Add to alignments container
216  m_alignments->m_align.push_back( transform );
217 
218  return m_alignments;
219 
220 }
221 
222 
223 //__________________________________________________________________________________________________
225 {
226 
227  AlignmentErrorsExtended* m_alignmentErrors = new AlignmentErrorsExtended();
228 
229  uint32_t detId = this->geomDetId().rawId();
230 
231  CLHEP::HepSymMatrix clhepSymMatrix(6,0);
232  if ( theAlignmentPositionError ) // Might not be set
234 
235  AlignTransformErrorExtended transformError( clhepSymMatrix, detId );
236 
237  m_alignmentErrors->m_alignError.push_back( transformError );
238 
239  return m_alignmentErrors;
240 
241 }
242 
243 
244 //__________________________________________________________________________________________________
245 int AlignableDetUnit::surfaceDeformationIdPairs(std::vector<std::pair<int,SurfaceDeformation*> > & result) const
246 {
247  if ( theSurfaceDeformation ) {
248  result.push_back( std::pair<int,SurfaceDeformation*>(this->geomDetId().rawId(),theSurfaceDeformation) );
249  return 1;
250  }
251 
252  return 0;
253 }
254 
255 //__________________________________________________________________________________________________
257 {
261 
264  theCachedSurfaceDeformation = nullptr;
265  }
266 
269 }
270 
271 //__________________________________________________________________________________________________
273 {
277 
278  auto existingCache = surfaceDeformationsCache_.find(run);
279  if (existingCache != surfaceDeformationsCache_.end()) {
280  delete existingCache->second;
281  existingCache->second = nullptr;
282  }
283 
284  if (theSurfaceDeformation) {
286  }
287 }
288 
289 //__________________________________________________________________________________________________
291 {
295 
296  if (theSurfaceDeformation) {
297  delete theSurfaceDeformation;
298  theSurfaceDeformation = nullptr;
299  }
300 
303  }
304 }
305 
306 //__________________________________________________________________________________________________
308 {
309  if (surfacesCache_.find(run) == surfacesCache_.end()) {
310  throw cms::Exception("Alignment")
311  << "@SUB=Alignable::restoreCachedTransformation\n"
312  << "Trying to restore cached transformation for a run (" << run
313  << ") that has not been cached.";
314  } else {
318 
319  if (theSurfaceDeformation) {
320  delete theSurfaceDeformation;
321  theSurfaceDeformation = nullptr;
322  }
323 
324  if (surfaceDeformationsCache_[run]) {
326  }
327  }
328 }
329 
330 //______________________________________________________________________________
T xx() const
RotationType theCachedRotation
Definition: Alignable.h:253
void dump() const override
Printout information about GeomDet.
CLHEP::HepMatrix asHepMatrix(const ROOT::Math::SMatrix< double, N1, N2, typename ROOT::Math::MatRepStd< double, N1, N2 > > &rm)
Definition: Migration.h:54
void update(align::ID, const AlignableSurface &)
Definition: Alignable.cc:49
int surfaceDeformationIdPairs(std::vector< std::pair< int, SurfaceDeformation * > > &) const override
Return surface deformations.
RotationType theRotation
Definition: Alignable.h:249
Cache< SurfaceDeformation * > surfaceDeformationsCache_
virtual std::vector< double > parameters() const =0
parameters - interpretation left to the concrete implementation
const GlobalVector & displacement() const
Return change of the global position since the creation of the object.
Definition: Alignable.h:144
#define nullptr
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
T yx() const
virtual int type() const =0
specific type, i.e. SurfaceDeformationFactory::Type
AlignmentErrorsExtended * alignmentErrors() const override
Return vector of alignment errors.
void move(const GlobalVector &displacement)
const RotationType & globalRotation() const
Return the global orientation of the object.
Definition: Alignable.h:141
Cache< GlobalVector > displacementsCache_
Definition: Alignable.h:261
void setSurfaceDeformation(const SurfaceDeformation *deformation, bool) final
Set surface deformation parameters (2nd argument without effect)
Cache< AlignableSurface > surfacesCache_
Definition: Alignable.h:260
Cache< RotationType > rotationsCache_
Definition: Alignable.h:262
align::LocalVector LocalVector
Definition: Alignable.h:36
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
std::vector< AlignTransform > m_align
Definition: Alignments.h:19
GlobalVector theDisplacement
Definition: Alignable.h:248
SurfaceDeformation * theCachedSurfaceDeformation
static const Alignables emptyComponents_
const GlobalErrorExtended & globalError() const
void update(const GeomDetUnit *geomDetUnit)
T zx() const
Alignments * alignments() const override
Return vector of alignment data.
T xy() const
T zz() const
const RotationType & rotation() const
Return change of orientation since the creation of the object.
Definition: Alignable.h:147
~AlignableDetUnit() override
Destructor.
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) ...
T zy() const
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:79
void addComponent(Alignable *) final
No components here => exception!
void setAlignmentPositionError(const AlignmentPositionError &ape, bool) final
Set the AlignmentPositionError (no components => second argument ignored)
T yy() const
void addAlignmentPositionError(const AlignmentPositionError &ape, bool) final
const AlgebraicSymMatrix66 & matrix() const
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:135
AlignableSurface theCachedSurface
Definition: Alignable.h:251
std::vector< AlignTransformErrorExtended > m_alignError
void addRotation(const RotationType &rotation)
Definition: Alignable.cc:254
GlobalVector theCachedDisplacement
Definition: Alignable.h:252
void addAlignmentPositionErrorFromRotation(const RotationType &rot, bool) final
void addDisplacement(const GlobalVector &displacement)
Definition: Alignable.cc:246
std::vector< Alignable * > Alignables
Definition: Utilities.h:32
void addAlignmentPositionErrorFromLocalRotation(const RotationType &rot, bool) final
virtual bool add(const SurfaceDeformation &other)=0
void rotate(const RotationType &rotation)
T xz() const
virtual const SurfaceDeformation * surfaceDeformation() const
Definition: GeomDet.h:114
align::GlobalPoints toGlobal(const align::LocalPoints &) const
Return in global coord given a set of local points.
AlignmentPositionError * theAlignmentPositionError
void addSurfaceDeformation(const SurfaceDeformation *deformation, bool) final
Add surface deformation parameters to the existing ones (2nd argument without effect) ...
const PositionType & globalPosition() const
Return the global position of the object.
Definition: Alignable.h:138
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.
Basic3DVector< T > multiplyInverse(const Basic3DVector< T > &v) const
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:56
SurfaceDeformation * theSurfaceDeformation
AlignmentPositionError const * alignmentPositionError() const
Return pointer to alignment errors.
Definition: GeomDet.h:95
T yz() const
const DetId & geomDetId() const
Definition: Alignable.h:186
AlignableSurface theSurface
Definition: Alignable.h:246
virtual SurfaceDeformation * clone() const =0
Alignables theDeepComponents
Definition: Alignable.h:257
cond::RealTimeType< cond::runnumber >::type RunNumber
Definition: Utilities.h:38
void restoreCachedTransformation() override
restore the previously cached transformation