CMS 3D CMS Logo

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