CMS 3D CMS Logo

AlignableDet.cc
Go to the documentation of this file.
4 #include "CLHEP/Vector/RotationInterfaces.h"
7 
9 
12 
13 
14 //__________________________________________________________________________________________________
15 AlignableDet::AlignableDet( const GeomDet* geomDet, bool addComponents ) :
16  AlignableComposite( geomDet ),
17  theAlignmentPositionError(nullptr)
18 {
19  // ensure that the surface is not constrained to the average position of the
20  // components:
22 
23  if (geomDet->alignmentPositionError()) {
24  // false: do not propagate APE to (anyway not yet existing) daughters
25  this->setAlignmentPositionError(*(geomDet->alignmentPositionError()), false);
26  }
27 
28  if (addComponents) {
29  if ( geomDet->components().empty() ) { // Is a DetUnit
30  throw cms::Exception("BadHierarchy") << "[AlignableDet] GeomDet with DetId "
31  << geomDet->geographicalId().rawId()
32  << " has no components, use AlignableDetUnit.\n";
33  } else { // Push back all components
34  const std::vector<const GeomDet*>& geomDets = geomDet->components();
35  for (std::vector<const GeomDet*>::const_iterator idet = geomDets.begin();
36  idet != geomDets.end(); ++idet) {
37  const GeomDetUnit *unit = dynamic_cast<const GeomDetUnit*>(*idet);
38  if (!unit) {
39  throw cms::Exception("BadHierarchy")
40  << "[AlignableDet] component not GeomDetUnit, call with addComponents==false"
41  << " and build hierarchy yourself.\n"; // e.g. AlignableDTChamber
42  }
43  this->addComponent(new AlignableDetUnit(unit));
44  }
45  }
46  // Ensure that the surface is not screwed up by addComponent, it must stay the GeomDet's one:
47  theSurface = AlignableSurface(geomDet->surface());
48  } // end addComponents
49 }
50 
51 
52 //__________________________________________________________________________________________________
54 {
55 
57 
58 }
59 
60 
61 //______________________________________________________________________________
62 void AlignableDet::update(const GeomDet* geomDet, bool updateComponents)
63 {
65 
66  if (geomDet->alignmentPositionError()) {
67  // false: do not propagate APE to daughters (done by their update functions)
68  this->setAlignmentPositionError(*(geomDet->alignmentPositionError()), false);
69  }
70 
71  if (updateComponents) {
72  if (geomDet->components().empty() ) { // Is a DetUnit
73  throw cms::Exception("BadHierarchy")
74  << "[AlignableDet] GeomDet with DetId "
75  << geomDet->geographicalId().rawId()
76  << " has no components, use AlignableDetUnit.\n";
77  } else { // Push back all components
78  const auto& geomDets = geomDet->components();
79  for (const auto& idet: geomDets) {
80  auto unit = dynamic_cast<const GeomDetUnit*>(idet);
81  if (!unit) {
82  throw cms::Exception("BadHierarchy")
83  << "[AlignableDet] component not GeomDetUnit, call with "
84  << "updateComponents==false and build hierarchy yourself.\n";
85  // -> e.g. AlignableDTChamber
86  }
87 
88  const auto components = this->components();
89  auto comp =
90  std::find_if(components.begin(), components.end(),
91  [&unit](const auto& c) {
92  return c->id() == unit->geographicalId().rawId(); });
93 
94  if (comp != components.end()) {
95  auto aliDetUnit = dynamic_cast<AlignableDetUnit*>(*comp);
96  if (aliDetUnit) {
97  aliDetUnit->update(unit);
98  } else {
99  throw cms::Exception("LogicError")
100  << "[AlignableDet::update] cast to 'AlignableDetUnit*' failed "
101  << "while it should not\n";
102  }
103  } else {
104  throw cms::Exception("GeometryMismatch")
105  << "[AlignableDet::update] GeomDet with DetId "
106  << unit->geographicalId().rawId()
107  << " not found in current geometry.\n";
108  }
109  }
110  }
111  // Ensure that the surface is not screwed up by update of components, it must stay the GeomDet's one:
112  theSurface = AlignableSurface(geomDet->surface());
113  } // end updateComponents
114 }
115 
116 
117 //__________________________________________________________________________________________________
119 {
120 
123  else
125 
126  this->AlignableComposite::setAlignmentPositionError( ape, propagateDown );
127 
128 }
129 
130 
131 //__________________________________________________________________________________________________
133 {
134 
135  if ( !theAlignmentPositionError ) {
137  } else {
139  }
140 
141  this->AlignableComposite::addAlignmentPositionError( ape, propagateDown );
142 
143 }
144 
145 //__________________________________________________________________________________________________
147  bool propagateDown)
148 {
149 
150  // average error calculated by movement of a local point at
151  // (xWidth/2,yLength/2,0) caused by the rotation rot
152  GlobalVector localPositionVector = surface().toGlobal( LocalVector(.5 * surface().width(), .5 * surface().length(), 0.) );
153 
154  const LocalVector::BasicVectorType& lpvgf = localPositionVector.basicVector();
155  GlobalVector gv( rot.multiplyInverse(lpvgf) - lpvgf );
156 
157  AlignmentPositionError ape( gv.x(),gv.y(),gv.z() );
158  this->addAlignmentPositionError( ape, propagateDown );
159 
161 
162 }
163 
164 //__________________________________________________________________________________________________
166 {
167 
168  Alignments* m_alignments = new Alignments();
169  RotationType rot( this->globalRotation() );
170 
171  // Get position, rotation, detId
172  CLHEP::Hep3Vector clhepVector( globalPosition().x(), globalPosition().y(), globalPosition().z() );
173  CLHEP::HepRotation clhepRotation( CLHEP::HepRep3x3( rot.xx(), rot.xy(), rot.xz(),
174  rot.yx(), rot.yy(), rot.yz(),
175  rot.zx(), rot.zy(), rot.zz() ) );
176  uint32_t detId = this->geomDetId().rawId();
177 
178  AlignTransform transform( clhepVector, clhepRotation, detId );
179 
180  // Add to alignments container
181  m_alignments->m_align.push_back( transform );
182 
183  // Add those from components
184  Alignments *compAlignments = this->AlignableComposite::alignments();
185  std::copy(compAlignments->m_align.begin(), compAlignments->m_align.end(),
186  std::back_inserter(m_alignments->m_align));
187  delete compAlignments;
188 
189 
190  return m_alignments;
191 }
192 
193 //__________________________________________________________________________________________________
195 {
196 
197  AlignmentErrorsExtended* m_alignmentErrors = new AlignmentErrorsExtended();
198 
199  // Add associated alignment position error
200  uint32_t detId = this->geomDetId().rawId();
201  CLHEP::HepSymMatrix clhepSymMatrix(6,0);
202  if ( theAlignmentPositionError ) // Might not be set
204  AlignTransformErrorExtended transformError( clhepSymMatrix, detId );
205  m_alignmentErrors->m_alignError.push_back( transformError );
206 
207  // Add those from components
209  std::copy(compAlignmentErrs->m_alignError.begin(), compAlignmentErrs->m_alignError.end(),
210  std::back_inserter(m_alignmentErrors->m_alignError));
211  delete compAlignmentErrs;
212 
213 
214  return m_alignmentErrors;
215 }
T xx() const
const Alignables & components() const override
Return vector of direct components.
void addAlignmentPositionError(const AlignmentPositionError &ape, bool propagateDown) override
CLHEP::HepMatrix asHepMatrix(const ROOT::Math::SMatrix< double, N1, N2, typename ROOT::Math::MatRepStd< double, N1, N2 > > &rm)
Definition: Migration.h:54
void addAlignmentPositionErrorFromRotation(const RotationType &rotation, bool propagateDown) override
AlignmentPositionError * theAlignmentPositionError
Definition: AlignableDet.h:51
T yx() const
const RotationType & globalRotation() const
Return the global orientation of the object.
Definition: Alignable.h:141
#define nullptr
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
void setAlignmentPositionError(const AlignmentPositionError &ape, bool propagateDown) override
const GlobalErrorExtended & globalError() const
void update(const GeomDetUnit *geomDetUnit)
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
T zx() const
T xy() const
T zz() const
~AlignableDet() override
Destructor.
Definition: AlignableDet.cc:53
Alignments * alignments() const override
Return alignment data.
AlignmentErrorsExtended * alignmentErrors() const override
Return vector of alignment errors.
T zy() const
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:79
void addAlignmentPositionErrorFromRotation(const RotationType &rot, bool propagateDown) override
T yy() const
const AlgebraicSymMatrix66 & matrix() const
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:135
virtual std::vector< const GeomDet * > components() const
Returns direct components, if any.
Definition: GeomDet.h:88
std::vector< AlignTransformErrorExtended > m_alignError
Alignments * alignments() const override
Return vector of alignment data.
AlignableDet(const GeomDet *geomDet, bool addComponents=true)
Definition: AlignableDet.cc:15
T xz() const
align::GlobalPoints toGlobal(const align::LocalPoints &) const
Return in global coord given a set of local points.
void update(const GeomDet *geomDet, bool updateComponents=true)
Definition: AlignableDet.cc:62
CompConstraintType compConstraintType_
Definition: Alignable.h:255
AlignmentErrorsExtended * alignmentErrors() const override
Return vector of alignment errors.
const PositionType & globalPosition() const
Return the global position of the object.
Definition: Alignable.h:138
void update(align::ID, StructureType aType, const RotationType &rot=RotationType())
Basic3DVector< T > multiplyInverse(const Basic3DVector< T > &v) const
void setAlignmentPositionError(const AlignmentPositionError &ape, bool propagateDown) override
Set the AlignmentPositionError and, if (propagateDown), to all components.
void addAlignmentPositionError(const AlignmentPositionError &ape, bool propagateDown) override
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:56
AlignmentPositionError const * alignmentPositionError() const
Return pointer to alignment errors.
Definition: GeomDet.h:95
T yz() const
const DetId & geomDetId() const
Definition: Alignable.h:186
void addComponent(Alignable *component) final
AlignableSurface theSurface
Definition: Alignable.h:246