CMS 3D CMS Logo

List of all members | Public Member Functions
GeometryAligner Class Reference

Class to update a given geometry with a set of alignments. More...

#include <GeometryAligner.h>

Inheritance diagram for GeometryAligner:
DetPositioner

Public Member Functions

template<class C >
void applyAlignments (C *geometry, const Alignments *alignments, const AlignmentErrorsExtended *alignmentErrors, const AlignTransform &globalCoordinates)
 
template<class C >
void attachSurfaceDeformations (C *geometry, const AlignmentSurfaceDeformations *surfaceDeformations)
 
void removeGlobalTransform (const Alignments *alignments, const AlignmentErrorsExtended *alignmentErrors, const AlignTransform &globalCoordinates, Alignments *newAlignments, AlignmentErrorsExtended *newAlignmentErrorsExtended)
 
- Public Member Functions inherited from DetPositioner
virtual ~DetPositioner ()
 

Additional Inherited Members

- Protected Member Functions inherited from DetPositioner
void moveGeomDet (GeomDet &det, const GlobalVector &displacement)
 
void rotateGeomDet (GeomDet &det, const Surface::RotationType &rotation)
 
bool setAlignmentPositionError (GeomDet &det, const AlignmentPositionError &ape)
 
void setGeomDetPosition (GeomDet &det, const Surface::PositionType &position, const Surface::RotationType &rotation)
 
void setSurfaceDeformation (GeomDetUnit &detUnit, const SurfaceDeformation *deformation)
 

Detailed Description

Class to update a given geometry with a set of alignments.

Definition at line 33 of file GeometryAligner.h.

Member Function Documentation

template<class C >
void GeometryAligner::applyAlignments ( C *  geometry,
const Alignments alignments,
const AlignmentErrorsExtended alignmentErrors,
const AlignTransform globalCoordinates 
)

Definition at line 52 of file GeometryAligner.h.

References filterCSVwithJSON::copy, relativeConstraints::error, Alignments::m_align, AlignmentErrorsExtended::m_alignError, position, idealTransformation::rotation, AlignTransform::rotation(), DetPositioner::setAlignmentPositionError(), DetPositioner::setGeomDetPosition(), and AlignTransform::translation().

Referenced by CreateSurveyRcds::analyze(), TrackerSystematicMisalignments::analyze(), AlignmentMonitorAsAnalyzer::analyze(), TrackerGeometryIntoNtuples::analyze(), AlignmentProducerBase::applyAlignmentsToGeometry(), AlignmentProducerBase::applyDB(), TrackerGeometryCompare::createROOTGeometry(), MuonAlignmentInputDB::newAlignableMuon(), TrackerDigiGeometryESModule::produce(), MTDDigiGeometryESModule::produce(), MisalignedTrackerESProducer::produce(), GEMGeometryESModule::produce(), DTGeometryESModule::produce(), MisalignedMuonESProducer::produce(), CSCGeometryESModule::produce(), and DTGeometryESProducer::produce().

55  {
56  edm::LogInfo("Alignment") << "@SUB=GeometryAligner::applyAlignments"
57  << "Starting to apply alignments.";
58 
59  // Preliminary checks (or we can't loop!)
60  if (alignments->m_align.size() != geometry->theMap.size())
61  throw cms::Exception("GeometryMismatch") << "Size mismatch between geometry (size=" << geometry->theMap.size()
62  << ") and alignments (size=" << alignments->m_align.size() << ")";
63  if (alignments->m_align.size() != alignmentErrors->m_alignError.size())
64  throw cms::Exception("GeometryMismatch")
65  << "Size mismatch between geometry (size=" << geometry->theMap.size()
66  << ") and alignment errors (size=" << alignmentErrors->m_alignError.size() << ")";
67 
68  const AlignTransform::Translation& globalShift = globalCoordinates.translation();
69  const AlignTransform::Rotation globalRotation = globalCoordinates.rotation(); // by value!
70  const AlignTransform::Rotation inverseGlobalRotation = globalRotation.inverse();
71 
72  // Parallel loop on alignments, alignment errors and geomdets
73  std::vector<AlignTransform>::const_iterator iAlign = alignments->m_align.begin();
74  std::vector<AlignTransformErrorExtended>::const_iterator iAlignError = alignmentErrors->m_alignError.begin();
75  //copy geometry->theMap to a real map to order it....
76  std::map<unsigned int, GeomDet const*> theMap;
77  std::copy(geometry->theMap.begin(), geometry->theMap.end(), std::inserter(theMap, theMap.begin()));
78  unsigned int nAPE = 0;
79  for (auto iPair = theMap.begin(); iPair != theMap.end(); ++iPair, ++iAlign, ++iAlignError) {
80  // Check DetIds
81  if ((*iPair).first != (*iAlign).rawId())
82  throw cms::Exception("GeometryMismatch") << "DetId mismatch between geometry (rawId=" << (*iPair).first
83  << ") and alignments (rawId=" << (*iAlign).rawId();
84 
85  if ((*iPair).first != (*iAlignError).rawId())
86  throw cms::Exception("GeometryMismatch") << "DetId mismatch between geometry (rawId=" << (*iPair).first
87  << ") and alignment errors (rawId=" << (*iAlignError).rawId();
88 
89  // Apply global correction
90  CLHEP::Hep3Vector positionHep = globalRotation * CLHEP::Hep3Vector((*iAlign).translation()) + globalShift;
91  CLHEP::HepRotation rotationHep = CLHEP::HepRotation((*iAlign).rotation()) * inverseGlobalRotation;
92 
93  // Define new position/rotation objects and apply
94  Surface::PositionType position(positionHep.x(), positionHep.y(), positionHep.z());
95  Surface::RotationType rotation(rotationHep.xx(),
96  rotationHep.xy(),
97  rotationHep.xz(),
98  rotationHep.yx(),
99  rotationHep.yy(),
100  rotationHep.yz(),
101  rotationHep.zx(),
102  rotationHep.zy(),
103  rotationHep.zz());
104  GeomDet* iGeomDet = const_cast<GeomDet*>((*iPair).second);
105  this->setGeomDetPosition(*iGeomDet, position, rotation);
106 
107  // Alignment Position Error only if non-zero to save memory
108  GlobalErrorExtended error(asSMatrix<6>((*iAlignError).matrix()));
109 
111  if (this->setAlignmentPositionError(*iGeomDet, ape))
112  ++nAPE;
113  }
114 
115  edm::LogInfo("Alignment") << "@SUB=GeometryAligner::applyAlignments"
116  << "Finished to apply " << theMap.size() << " alignments with " << nAPE << " non-zero APE.";
117 }
bool setAlignmentPositionError(GeomDet &det, const AlignmentPositionError &ape)
Definition: DetPositioner.h:37
CLHEP::Hep3Vector Translation
std::vector< AlignTransform > m_align
Definition: Alignments.h:19
const Translation & translation() const
void setGeomDetPosition(GeomDet &det, const Surface::PositionType &position, const Surface::RotationType &rotation)
Definition: DetPositioner.h:28
std::vector< AlignTransformErrorExtended > m_alignError
static int position[264][3]
Definition: ReadPGInfo.cc:289
Rotation rotation() const
CLHEP::HepRotation Rotation
template<class C >
void GeometryAligner::attachSurfaceDeformations ( C *  geometry,
const AlignmentSurfaceDeformations surfaceDeformations 
)

Definition at line 120 of file GeometryAligner.h.

References filterCSVwithJSON::copy, SurfaceDeformationFactory::create(), AlignmentSurfaceDeformations::items(), AlignmentSurfaceDeformations::parameters(), and DetPositioner::setSurfaceDeformation().

Referenced by TrackerGeometryIntoNtuples::analyze(), AlignmentProducerBase::applyAlignmentsToGeometry(), AlignmentProducerBase::applyDB(), TrackerDigiGeometryESModule::produce(), and MTDDigiGeometryESModule::produce().

120  {
121  edm::LogInfo("Alignment") << "@SUB=GeometryAligner::attachSurfaceDeformations"
122  << "Starting to attach surface deformations.";
123 
124  //copy geometry->theMapUnit to a real map to order it....
125  std::map<unsigned int, GeomDetUnit const*> theMap;
126  std::copy(geometry->theMapUnit.begin(), geometry->theMapUnit.end(), std::inserter(theMap, theMap.begin()));
127 
128  unsigned int nSurfDef = 0;
129  unsigned int itemIndex = 0;
130  auto iPair = theMap.begin();
131  for (std::vector<AlignmentSurfaceDeformations::Item>::const_iterator iItem = surfaceDeformations->items().begin();
132  iItem != surfaceDeformations->items().end();
133  ++iItem, ++iPair) {
134  // Check DetIds
135  // go forward in map of GeomDetUnits until DetId is found
136  while ((*iPair).first != (*iItem).m_rawId) {
137  // remove SurfaceDeformation from GeomDetUnit (i.e. set NULL pointer)
138  GeomDetUnit* geomDetUnit = const_cast<GeomDetUnit*>((*iPair).second);
139  this->setSurfaceDeformation(*geomDetUnit, nullptr);
140 
141  ++iPair;
142  if (iPair == theMap.end())
143  throw cms::Exception("GeometryMismatch")
144  << "GeomDetUnit with rawId=" << (*iItem).m_rawId << " not found in geometry";
145  }
146 
147  // get the parameters and put them into a vector
148  AlignmentSurfaceDeformations::ParametersConstIteratorPair iteratorPair = surfaceDeformations->parameters(itemIndex);
149  std::vector<double> parameters;
150  std::copy(iteratorPair.first, iteratorPair.second, std::back_inserter(parameters));
151 
152  // create SurfaceDeformation via factory
153  SurfaceDeformation* surfDef = SurfaceDeformationFactory::create((*iItem).m_parametrizationType, parameters);
154  GeomDetUnit* geomDetUnit = const_cast<GeomDetUnit*>((*iPair).second);
155  this->setSurfaceDeformation(*geomDetUnit, surfDef);
156  // delete is not needed since SurfaceDeformation is passed as a
157  // DeepCopyPointerByClone which takes over ownership. Needs to be
158  // cleaned up and checked once SurfaceDeformation are moved to
159  // proxy topology classes
160  //delete surfDef;
161 
162  ++nSurfDef;
163 
164  ++itemIndex;
165  }
166 
167  edm::LogInfo("Alignment") << "@SUB=GeometryAligner::attachSurfaceDeformations"
168  << "Finished to attach " << nSurfDef << " surface deformations.";
169 }
void setSurfaceDeformation(GeomDetUnit &detUnit, const SurfaceDeformation *deformation)
Definition: DetPositioner.h:44
ParametersConstIteratorPair parameters(size_t index) const
std::pair< ParametersConstIterator, ParametersConstIterator > ParametersConstIteratorPair
const ItemVector & items() const
Get vector of all items.
SurfaceDeformation * create(int type, const std::vector< double > &params)
void GeometryAligner::removeGlobalTransform ( const Alignments alignments,
const AlignmentErrorsExtended alignmentErrors,
const AlignTransform globalCoordinates,
Alignments newAlignments,
AlignmentErrorsExtended newAlignmentErrorsExtended 
)
inline

Definition at line 171 of file GeometryAligner.h.

References relativeConstraints::error, Alignments::m_align, AlignmentErrorsExtended::m_alignError, AlignTransform::rotation(), and AlignTransform::translation().

Referenced by AlignmentProducerBase::writeDB().

175  {
176  edm::LogInfo("Alignment") << "@SUB=GeometryAligner::removeGlobalTransform"
177  << "Starting to remove global position from alignments and errors";
178 
179  if (alignments->m_align.size() != alignmentErrors->m_alignError.size())
180  throw cms::Exception("GeometryMismatch")
181  << "Size mismatch between alignments (size=" << alignments->m_align.size()
182  << ") and alignment errors (size=" << alignmentErrors->m_alignError.size() << ")";
183 
184  const AlignTransform::Translation& globalShift = globalCoordinates.translation();
185  const AlignTransform::Rotation globalRotation = globalCoordinates.rotation(); // by value!
186  const AlignTransform::Rotation inverseGlobalRotation = globalRotation.inverse();
187 
188  AlignTransform::Translation newPosition;
189  AlignTransform::Rotation newRotation;
190 
191  std::vector<AlignTransform>::const_iterator iAlign = alignments->m_align.begin();
192  std::vector<AlignTransformErrorExtended>::const_iterator iAlignError = alignmentErrors->m_alignError.begin();
193  unsigned int nAPE = 0;
194  for (iAlign = alignments->m_align.begin(); iAlign != alignments->m_align.end(); ++iAlign, ++iAlignError) {
195  // Remove global position transformation from alignment
196  newPosition = inverseGlobalRotation * ((*iAlign).translation() - globalShift);
197  newRotation = (*iAlign).rotation() * globalRotation;
198 
199  newAlignments->m_align.emplace_back(AlignTransform(newPosition, newRotation, (*iAlign).rawId()));
200 
201  // Don't remove global position transformation from APE
202  // as it wasn't applied. Just fill vector with original
203  // values
204  GlobalErrorExtended error(asSMatrix<6>((*iAlignError).matrix()));
205  newAlignmentErrorsExtended->m_alignError.emplace_back(
206  AlignTransformErrorExtended((*iAlignError).matrix(), (*iAlignError).rawId()));
207 
208  //if ( error.cxx() || error.cyy() || error.czz() ||
209  // error.cyx() || error.czx() || error.czy() ) {
210  // ++nAPE;
211  // }
212 
213  // Code that removes the global postion transformation
214  // from the APE.
215  //
216  //AlgebraicSymMatrix as(3,0);
217  //as[0][0] = error.cxx();
218  //as[1][0] = error.cyx(); as[1][1] = error.cyy();
219  //as[2][0] = error.czx(); as[2][1] = error.czy(); as[2][2] = error.czz();
220 
221  //AlgebraicMatrix am(3,3);
222  //am[0][0] = inverseGlobalRotation.xx(); am[0][1] = inverseGlobalRotation.xy(); am[0][2] = inverseGlobalRotation.xz();
223  //am[1][0] = inverseGlobalRotation.yx(); am[1][1] = inverseGlobalRotation.yy(); am[1][2] = inverseGlobalRotation.yz();
224  //am[2][0] = inverseGlobalRotation.zx(); am[2][1] = inverseGlobalRotation.zy(); am[2][2] = inverseGlobalRotation.zz();
225  //as = as.similarityT( am );
226 
227  //GlobalErrorExtended newError( as );
228  //newAlignmentErrorsExtended->m_alignError.emplace_back( AlignTransformErrorExtended( newError.matrix(),
229  // (*iAlignError).rawId() ) );
230  //++nAPE;
231  }
232 
233  edm::LogInfo("Alignment") << "@SUB=GeometryAligner::removeGlobalTransform"
234  << "Finished to remove global transformation from " << alignments->m_align.size()
235  << " alignments with " << nAPE << " non-zero APE.";
236 }
CLHEP::Hep3Vector Translation
std::vector< AlignTransform > m_align
Definition: Alignments.h:19
const Translation & translation() const
std::vector< AlignTransformErrorExtended > m_alignError
Rotation rotation() const
CLHEP::HepRotation Rotation