CMS 3D CMS Logo

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:
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 }
Vector3DBase< Scalar, GlobalTag >
AlignmentErrorsExtended.h
TkRotation< Scalar >
DDAxes::y
ApeEstimator_cff.width
width
Definition: ApeEstimator_cff.py:24
AlignableComposite::alignments
Alignments * alignments() const override
Return alignment data.
Definition: AlignableComposite.cc:254
MessageLogger.h
AlignableDetUnit.h
AlignableDet::addAlignmentPositionErrorFromRotation
void addAlignmentPositionErrorFromRotation(const RotationType &rot, bool propagateDown) override
Definition: AlignableDet.cc:119
GeomDet
Definition: GeomDet.h:27
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
AlignableComposite::components
const Alignables & components() const override
Return vector of direct components.
Definition: AlignableComposite.h:45
AlignableComposite
Definition: AlignableComposite.h:25
AlignableDet::theAlignmentPositionError
AlignmentPositionError * theAlignmentPositionError
Definition: AlignableDet.h:47
Alignments.h
AlignableDet::alignmentErrors
AlignmentErrorsExtended * alignmentErrors() const override
Return vector of alignment errors.
Definition: AlignableDet.cc:159
AlignableDet::setAlignmentPositionError
void setAlignmentPositionError(const AlignmentPositionError &ape, bool propagateDown) override
Set the AlignmentPositionError and, if (propagateDown), to all components.
Definition: AlignableDet.cc:98
AlignableDet.h
GeomDet::components
virtual std::vector< const GeomDet * > components() const
Returns direct components, if any.
Definition: GeomDet.h:73
DDAxes::x
AlignableComposite::addAlignmentPositionErrorFromRotation
void addAlignmentPositionErrorFromRotation(const RotationType &rotation, bool propagateDown) override
Definition: AlignableComposite.cc:175
AlCaHLTBitMon_QueryRunRegistry.comp
comp
Definition: AlCaHLTBitMon_QueryRunRegistry.py:249
GeomDet::surface
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
AlignmentPositionError::globalError
const GlobalErrorExtended & globalError() const
Definition: AlignmentPositionError.h:24
Alignable::compConstraintType_
CompConstraintType compConstraintType_
Definition: Alignable.h:246
DDAxes::z
AlignableComposite::addComponent
void addComponent(Alignable *component) final
Definition: AlignableComposite.cc:53
AlignableComposite::update
void update(align::ID, StructureType aType, const RotationType &rot=RotationType())
Definition: AlignableComposite.cc:43
HcalDetIdTransform::transform
unsigned transform(const HcalDetId &id, unsigned transformCode)
Definition: HcalDetIdTransform.cc:7
AlignableSurface::toGlobal
align::GlobalPoints toGlobal(const align::LocalPoints &) const
Return in global coord given a set of local points.
Definition: AlignableSurface.cc:15
Alignable::surface
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:132
AlignTransform
Definition: AlignTransform.h:15
AlignableDet::alignments
Alignments * alignments() const override
Return vector of alignment data.
Definition: AlignableDet.cc:135
AlignableDet::update
void update(const GeomDet *geomDet, bool updateComponents=true)
Definition: AlignableDet.cc:50
GeomDet::geographicalId
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:64
align::AlignableDetUnit
Definition: StructureType.h:19
AlignableDet::AlignableDet
AlignableDet(const GeomDet *geomDet, bool addComponents=true)
Definition: AlignableDet.cc:14
GeomDet::alignmentPositionError
AlignmentPositionError const * alignmentPositionError() const
Return pointer to alignment errors.
Definition: GeomDet.h:80
Alignable::CompConstraintType::NONE
Alignable::geomDetId
const DetId & geomDetId() const
Definition: Alignable.h:177
Alignable::theSurface
AlignableSurface theSurface
Definition: Alignable.h:237
AlignmentErrorsExtended
Definition: AlignmentErrorsExtended.h:10
PV3DBase::basicVector
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:53
unit
Basic3DVector unit() const
Definition: Basic3DVectorLD.h:162
AlignableDet::~AlignableDet
~AlignableDet() override
Destructor.
Definition: AlignableDet.cc:47
GeomDet.h
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
AlignableSurface
Definition: AlignableSurface.h:20
Exception
Definition: hltDiff.cc:245
AlignmentPositionError.h
makeMuonMisalignmentScenario.rot
rot
Definition: makeMuonMisalignmentScenario.py:322
AlignableComposite::addAlignmentPositionError
void addAlignmentPositionError(const AlignmentPositionError &ape, bool propagateDown) override
Definition: AlignableComposite.cc:160
AlignTransformErrorExtended
Definition: AlignTransformErrorExtended.h:13
Exception.h
GlobalErrorBaseExtended::matrix
const AlgebraicSymMatrix66 & matrix() const
Definition: GlobalErrorBaseExtended.h:153
Alignments::m_align
std::vector< AlignTransform > m_align
Definition: Alignments.h:19
AlignmentErrorsExtended::m_alignError
std::vector< AlignTransformErrorExtended > m_alignError
Definition: AlignmentErrorsExtended.h:19
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
Alignable::globalPosition
const PositionType & globalPosition() const
Return the global position of the object.
Definition: Alignable.h:135
AlignmentPositionError
Definition: AlignmentPositionError.h:10
AlignableComposite::setAlignmentPositionError
void setAlignmentPositionError(const AlignmentPositionError &ape, bool propagateDown) override
Definition: AlignableComposite.cc:148
asHepMatrix
CLHEP::HepMatrix asHepMatrix(const ROOT::Math::SMatrix< double, N1, N2, typename ROOT::Math::MatRepStd< double, N1, N2 > > &rm)
Definition: Migration.h:60
Alignments
Definition: Alignments.h:10
Alignable::LocalVector
align::LocalVector LocalVector
Definition: Alignable.h:33
AlignableDet::addAlignmentPositionError
void addAlignmentPositionError(const AlignmentPositionError &ape, bool propagateDown) override
Definition: AlignableDet.cc:108
AlignableComposite::alignmentErrors
AlignmentErrorsExtended * alignmentErrors() const override
Return vector of alignment errors.
Definition: AlignableComposite.cc:269
Basic3DVector
Definition: extBasic3DVector.h:30
Alignable::globalRotation
const RotationType & globalRotation() const
Return the global orientation of the object.
Definition: Alignable.h:138