CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
AlignableDet.cc
Go to the documentation of this file.
4 #include "CLHEP/Vector/RotationInterfaces.h"
7 
9 
12 
13 //__________________________________________________________________________________________________
14 AlignableDet::AlignableDet(const GeomDet* geomDet, bool addComponents)
15  : AlignableComposite(geomDet), theAlignmentPositionError(nullptr) {
16  // ensure that the surface is not constrained to the average position of the
17  // components:
18  compConstraintType_ = Alignable::CompConstraintType::NONE;
19 
20  if (geomDet->alignmentPositionError()) {
21  // false: do not propagate APE to (anyway not yet existing) daughters
22  this->setAlignmentPositionError(*(geomDet->alignmentPositionError()), false);
23  }
24 
25  if (addComponents) {
26  if (geomDet->components().empty()) { // Is a DetUnit
27  throw cms::Exception("BadHierarchy") << "[AlignableDet] GeomDet with DetId " << geomDet->geographicalId().rawId()
28  << " has no components, use AlignableDetUnit.\n";
29  } else { // Push back all components
30  const std::vector<const GeomDet*>& geomDets = geomDet->components();
31  for (std::vector<const GeomDet*>::const_iterator idet = geomDets.begin(); idet != geomDets.end(); ++idet) {
32  const GeomDetUnit* unit = dynamic_cast<const GeomDetUnit*>(*idet);
33  if (!unit) {
34  throw cms::Exception("BadHierarchy")
35  << "[AlignableDet] component not GeomDetUnit, call with addComponents==false"
36  << " and build hierarchy yourself.\n"; // e.g. AlignableDTChamber
37  }
38  this->addComponent(new AlignableDetUnit(unit));
39  }
40  }
41  // Ensure that the surface is not screwed up by addComponent, it must stay the GeomDet's one:
42  theSurface = AlignableSurface(geomDet->surface());
43  } // end addComponents
44 }
45 
46 //__________________________________________________________________________________________________
48 
49 //______________________________________________________________________________
50 void AlignableDet::update(const GeomDet* geomDet, bool updateComponents) {
52 
53  if (geomDet->alignmentPositionError()) {
54  // false: do not propagate APE to daughters (done by their update functions)
55  this->setAlignmentPositionError(*(geomDet->alignmentPositionError()), false);
56  }
57 
58  if (updateComponents) {
59  if (geomDet->components().empty()) { // Is a DetUnit
60  throw cms::Exception("BadHierarchy") << "[AlignableDet] GeomDet with DetId " << geomDet->geographicalId().rawId()
61  << " has no components, use AlignableDetUnit.\n";
62  } else { // Push back all components
63  const auto& geomDets = geomDet->components();
64  for (const auto& idet : geomDets) {
65  auto unit = dynamic_cast<const GeomDetUnit*>(idet);
66  if (!unit) {
67  throw cms::Exception("BadHierarchy") << "[AlignableDet] component not GeomDetUnit, call with "
68  << "updateComponents==false and build hierarchy yourself.\n";
69  // -> e.g. AlignableDTChamber
70  }
71 
72  const auto components = this->components();
73  auto comp = std::find_if(components.begin(), components.end(), [&unit](const auto& c) {
74  return c->id() == unit->geographicalId().rawId();
75  });
76 
77  if (comp != components.end()) {
78  auto aliDetUnit = dynamic_cast<AlignableDetUnit*>(*comp);
79  if (aliDetUnit) {
80  aliDetUnit->update(unit);
81  } else {
82  throw cms::Exception("LogicError") << "[AlignableDet::update] cast to 'AlignableDetUnit*' failed "
83  << "while it should not\n";
84  }
85  } else {
86  throw cms::Exception("GeometryMismatch")
87  << "[AlignableDet::update] GeomDet with DetId " << unit->geographicalId().rawId()
88  << " not found in current geometry.\n";
89  }
90  }
91  }
92  // Ensure that the surface is not screwed up by update of components, it must stay the GeomDet's one:
93  theSurface = AlignableSurface(geomDet->surface());
94  } // end updateComponents
95 }
96 
97 //__________________________________________________________________________________________________
101  else
103 
104  this->AlignableComposite::setAlignmentPositionError(ape, propagateDown);
105 }
106 
107 //__________________________________________________________________________________________________
111  } else {
113  }
114 
115  this->AlignableComposite::addAlignmentPositionError(ape, propagateDown);
116 }
117 
118 //__________________________________________________________________________________________________
120  // average error calculated by movement of a local point at
121  // (xWidth/2,yLength/2,0) caused by the rotation rot
122  GlobalVector localPositionVector =
123  surface().toGlobal(LocalVector(.5 * surface().width(), .5 * surface().length(), 0.));
124 
125  const LocalVector::BasicVectorType& lpvgf = localPositionVector.basicVector();
126  GlobalVector gv(rot.multiplyInverse(lpvgf) - lpvgf);
127 
128  AlignmentPositionError ape(gv.x(), gv.y(), gv.z());
129  this->addAlignmentPositionError(ape, propagateDown);
130 
132 }
133 
134 //__________________________________________________________________________________________________
136  Alignments* m_alignments = new Alignments();
138 
139  // Get position, rotation, detId
140  CLHEP::Hep3Vector clhepVector(globalPosition().x(), globalPosition().y(), globalPosition().z());
141  CLHEP::HepRotation clhepRotation(
142  CLHEP::HepRep3x3(rot.xx(), rot.xy(), rot.xz(), rot.yx(), rot.yy(), rot.yz(), rot.zx(), rot.zy(), rot.zz()));
143  uint32_t detId = this->geomDetId().rawId();
144 
145  AlignTransform transform(clhepVector, clhepRotation, detId);
146 
147  // Add to alignments container
148  m_alignments->m_align.push_back(transform);
149 
150  // Add those from components
151  Alignments* compAlignments = this->AlignableComposite::alignments();
152  std::copy(compAlignments->m_align.begin(), compAlignments->m_align.end(), std::back_inserter(m_alignments->m_align));
153  delete compAlignments;
154 
155  return m_alignments;
156 }
157 
158 //__________________________________________________________________________________________________
160  AlignmentErrorsExtended* m_alignmentErrors = new AlignmentErrorsExtended();
161 
162  // Add associated alignment position error
163  uint32_t detId = this->geomDetId().rawId();
164  CLHEP::HepSymMatrix clhepSymMatrix(6, 0);
165  if (theAlignmentPositionError) // Might not be set
167  AlignTransformErrorExtended transformError(clhepSymMatrix, detId);
168  m_alignmentErrors->m_alignError.push_back(transformError);
169 
170  // Add those from components
172  std::copy(compAlignmentErrs->m_alignError.begin(),
173  compAlignmentErrs->m_alignError.end(),
174  std::back_inserter(m_alignmentErrors->m_alignError));
175  delete compAlignmentErrs;
176 
177  return m_alignmentErrors;
178 }
T xx() const
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:60
void addAlignmentPositionErrorFromRotation(const RotationType &rotation, bool propagateDown) override
const edm::EventSetup & c
Alignments * alignments() const override
Return vector of alignment data.
AlignmentPositionError * theAlignmentPositionError
Definition: AlignableDet.h:47
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
T yx() const
const Alignables & components() const override
Return vector of direct components.
const RotationType & globalRotation() const
Return the global orientation of the object.
Definition: Alignable.h:138
virtual std::vector< const GeomDet * > components() const
Returns direct components, if any.
Definition: GeomDet.h:73
align::LocalVector LocalVector
Definition: Alignable.h:33
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
std::vector< AlignTransform > m_align
Definition: Alignments.h:19
void setAlignmentPositionError(const AlignmentPositionError &ape, bool propagateDown) override
AlignmentErrorsExtended * alignmentErrors() const override
Return vector of alignment errors.
const GlobalErrorExtended & globalError() const
void update(const GeomDetUnit *geomDetUnit)
T zx() const
T xy() const
T zz() const
~AlignableDet() override
Destructor.
Definition: AlignableDet.cc:47
Alignments * alignments() const override
Return alignment data.
T zy() const
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:64
AlignmentErrorsExtended * alignmentErrors() const override
Return vector of alignment errors.
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:132
std::vector< AlignTransformErrorExtended > m_alignError
AlignableDet(const GeomDet *geomDet, bool addComponents=true)
Definition: AlignableDet.cc:14
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:50
const PositionType & globalPosition() const
Return the global position of the object.
Definition: Alignable.h:135
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.
Definition: AlignableDet.cc:98
void addAlignmentPositionError(const AlignmentPositionError &ape, bool propagateDown) override
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:53
AlignmentPositionError const * alignmentPositionError() const
Return pointer to alignment errors.
Definition: GeomDet.h:80
T yz() const
const DetId & geomDetId() const
Definition: Alignable.h:177
void addComponent(Alignable *component) final
AlignableSurface theSurface
Definition: Alignable.h:237
Basic3DVector unit() const
unsigned transform(const HcalDetId &id, unsigned transformCode)