CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 AlignmentErrors *alignmentErrors, const AlignTransform &globalCoordinates)
 
template<class C >
void attachSurfaceDeformations (C *geometry, const AlignmentSurfaceDeformations *surfaceDeformations)
 
void removeGlobalTransform (const Alignments *alignments, const AlignmentErrors *alignmentErrors, const AlignTransform &globalCoordinates, Alignments *newAlignments, AlignmentErrors *newAlignmentErrors)
 
- 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 32 of file GeometryAligner.h.

Member Function Documentation

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

Definition at line 54 of file GeometryAligner.h.

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

Referenced by CreateSurveyRcds::analyze(), TrackerSystematicMisalignments::analyze(), AlignmentMonitorAsAnalyzer::analyze(), TrackerGeometryIntoNtuples::analyze(), AlignmentProducer::applyDB(), TrackerGeometryCompare::createROOTGeometry(), MuonAlignmentInputDB::newAlignableMuon(), TrackerDigiGeometryESModule::produce(), DTGeometryESModule::produce(), CSCGeometryESModule::produce(), MisalignedTrackerESProducer::produce(), MisalignedMuonESProducer::produce(), and AlignmentProducer::startingNewLoop().

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

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

Referenced by TrackerGeometryIntoNtuples::analyze(), AlignmentProducer::applyDB(), TrackerDigiGeometryESModule::produce(), and AlignmentProducer::startingNewLoop().

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

Definition at line 183 of file GeometryAligner.h.

References GlobalErrorBase< T, ErrorWeightType >::cxx(), GlobalErrorBase< T, ErrorWeightType >::cyx(), GlobalErrorBase< T, ErrorWeightType >::cyy(), GlobalErrorBase< T, ErrorWeightType >::czx(), GlobalErrorBase< T, ErrorWeightType >::czy(), GlobalErrorBase< T, ErrorWeightType >::czz(), relativeConstraints::error, Alignments::m_align, AlignmentErrors::m_alignError, AlignTransform::rotation(), and AlignTransform::translation().

Referenced by AlignmentProducer::writeDB().

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