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 34 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 56 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().

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

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

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

Referenced by AlignmentProducerBase::writeDB().

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