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 55 of file GeometryAligner.h.

References popcon2dropbox::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(), CSCGeometryESModule::produce(), DTGeometryESModule::produce(), MisalignedTrackerESProducer::produce(), and MisalignedMuonESProducer::produce().

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

Definition at line 128 of file GeometryAligner.h.

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

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

130 {
131  edm::LogInfo("Alignment") << "@SUB=GeometryAligner::attachSurfaceDeformations"
132  << "Starting to attach surface deformations.";
133 
134  //copy geometry->theMapUnit to a real map to order it....
135  std::map<unsigned int, GeomDetUnit const*> theMap;
136  std::copy(geometry->theMapUnit.begin(), geometry->theMapUnit.end(), std::inserter(theMap, theMap.begin()));
137 
138  unsigned int nSurfDef = 0;
139  unsigned int itemIndex = 0;
140  auto iPair = theMap.begin();
141  for ( std::vector<AlignmentSurfaceDeformations::Item>::const_iterator iItem = surfaceDeformations->items().begin();
142  iItem != surfaceDeformations->items().end();
143  ++iItem, ++iPair) {
144 
145  // Check DetIds
146  // go forward in map of GeomDetUnits until DetId is found
147  while ( (*iPair).first != (*iItem).m_rawId ) {
148 
149  // remove SurfaceDeformation from GeomDetUnit (i.e. set NULL pointer)
150  GeomDetUnit* geomDetUnit = const_cast<GeomDetUnit*>((*iPair).second);
151  this->setSurfaceDeformation( *geomDetUnit, 0 );
152 
153  ++iPair;
154  if ( iPair==theMap.end() )
155  throw cms::Exception("GeometryMismatch")
156  << "GeomDetUnit with rawId=" << (*iItem).m_rawId
157  << " not found in geometry";
158  }
159 
160  // get the parameters and put them into a vector
161  AlignmentSurfaceDeformations::ParametersConstIteratorPair iteratorPair = surfaceDeformations->parameters(itemIndex);
162  std::vector<double> parameters;
163  std::copy(iteratorPair.first, iteratorPair.second, std::back_inserter(parameters));
164 
165  // create SurfaceDeformation via factory
166  SurfaceDeformation * surfDef = SurfaceDeformationFactory::create( (*iItem).m_parametrizationType, parameters);
167  GeomDetUnit* geomDetUnit = const_cast<GeomDetUnit*>((*iPair).second);
168  this->setSurfaceDeformation( *geomDetUnit, surfDef );
169  // delete is not needed since SurfaceDeformation is passed as a
170  // DeepCopyPointerByClone which takes over ownership. Needs to be
171  // cleaned up and checked once SurfaceDeformation are moved to
172  // proxy topology classes
173  //delete surfDef;
174 
175  ++nSurfDef;
176 
177  ++itemIndex;
178  }
179 
180  edm::LogInfo("Alignment") << "@SUB=GeometryAligner::attachSurfaceDeformations"
181  << "Finished to attach " << nSurfDef << " surface deformations.";
182 }
std::pair< ParametersConstIterator, ParametersConstIterator > ParametersConstIteratorPair
void setSurfaceDeformation(GeomDetUnit &detUnit, const SurfaceDeformation *deformation)
Definition: DetPositioner.h:54
ParametersConstIteratorPair parameters(size_t index) const
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 184 of file GeometryAligner.h.

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

Referenced by AlignmentProducerBase::writeDB().

189 {
190  edm::LogInfo("Alignment") << "@SUB=GeometryAligner::removeGlobalTransform"
191  << "Starting to remove global position from alignments and errors";
192 
193  if ( alignments->m_align.size() != alignmentErrors->m_alignError.size() )
194  throw cms::Exception("GeometryMismatch")
195  << "Size mismatch between alignments (size=" << alignments->m_align.size()
196  << ") and alignment errors (size=" << alignmentErrors->m_alignError.size() << ")";
197 
198  const AlignTransform::Translation &globalShift = globalCoordinates.translation();
199  const AlignTransform::Rotation globalRotation = globalCoordinates.rotation(); // by value!
200  const AlignTransform::Rotation inverseGlobalRotation = globalRotation.inverse();
201 
202  AlignTransform::Translation newPosition;
203  AlignTransform::Rotation newRotation;
204 
205  std::vector<AlignTransform>::const_iterator iAlign = alignments->m_align.begin();
206  std::vector<AlignTransformErrorExtended>::const_iterator iAlignError = alignmentErrors->m_alignError.begin();
207  unsigned int nAPE = 0;
208  for ( iAlign = alignments->m_align.begin();
209  iAlign != alignments->m_align.end();
210  ++iAlign, ++iAlignError ) {
211 
212  // Remove global position transformation from alignment
213  newPosition = inverseGlobalRotation * ( (*iAlign).translation() - globalShift );
214  newRotation = (*iAlign).rotation() * globalRotation;
215 
216  newAlignments->m_align.push_back( AlignTransform(newPosition,
217  newRotation,
218  (*iAlign).rawId()) );
219 
220  // Don't remove global position transformation from APE
221  // as it wasn't applied. Just fill vector with original
222  // values
223  GlobalErrorExtended error( asSMatrix<6>((*iAlignError).matrix()) );
224  newAlignmentErrorsExtended->m_alignError.push_back( AlignTransformErrorExtended( (*iAlignError).matrix(),
225  (*iAlignError).rawId() ) );
226 
227  //if ( error.cxx() || error.cyy() || error.czz() ||
228 // error.cyx() || error.czx() || error.czy() ) {
229 // ++nAPE;
230 // }
231 
232  // Code that removes the global postion transformation
233  // from the APE.
234  //
235  //AlgebraicSymMatrix as(3,0);
236  //as[0][0] = error.cxx();
237  //as[1][0] = error.cyx(); as[1][1] = error.cyy();
238  //as[2][0] = error.czx(); as[2][1] = error.czy(); as[2][2] = error.czz();
239 
240  //AlgebraicMatrix am(3,3);
241  //am[0][0] = inverseGlobalRotation.xx(); am[0][1] = inverseGlobalRotation.xy(); am[0][2] = inverseGlobalRotation.xz();
242  //am[1][0] = inverseGlobalRotation.yx(); am[1][1] = inverseGlobalRotation.yy(); am[1][2] = inverseGlobalRotation.yz();
243  //am[2][0] = inverseGlobalRotation.zx(); am[2][1] = inverseGlobalRotation.zy(); am[2][2] = inverseGlobalRotation.zz();
244  //as = as.similarityT( am );
245 
246  //GlobalErrorExtended newError( as );
247  //newAlignmentErrorsExtended->m_alignError.push_back( AlignTransformErrorExtended( newError.matrix(),
248  // (*iAlignError).rawId() ) );
249  //++nAPE;
250  }
251 
252  edm::LogInfo("Alignment") << "@SUB=GeometryAligner::removeGlobalTransform"
253  << "Finished to remove global transformation from "
254  << alignments->m_align.size() << " alignments with "
255  << nAPE << " non-zero APE.";
256 }
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