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 (const C *geometry, const Alignments *alignments, const AlignmentErrorsExtended *alignmentErrors, const AlignTransform &globalCoordinates)
 
template<class C >
void attachSurfaceDeformations (const 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

◆ applyAlignments()

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

Definition at line 52 of file GeometryAligner.h.

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 }

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 TrackerSystematicMisalignments::analyze(), CreateSurveyRcds::analyze(), AlignmentMonitorAsAnalyzer::analyze(), TrackerGeometryIntoNtuples::analyze(), AlignmentProducerBase::applyAlignmentsToGeometry(), AlignmentProducerBase::applyDB(), TrackerGeometryCompare::createROOTGeometry(), MuonAlignmentInputDB::newAlignableMuon(), TrackerDigiGeometryESModule::produce(), MTDDigiGeometryESModule::produce(), MisalignedTrackerESProducer::produce(), GEMGeometryESModule::produce(), CSCGeometryESModule::produce(), DTGeometryESModule::produce(), and DTGeometryESProducer::produce().

◆ attachSurfaceDeformations()

template<class C >
void GeometryAligner::attachSurfaceDeformations ( const C *  geometry,
const AlignmentSurfaceDeformations surfaceDeformations 
)

Definition at line 120 of file GeometryAligner.h.

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

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

◆ removeGlobalTransform()

void GeometryAligner::removeGlobalTransform ( const Alignments alignments,
const AlignmentErrorsExtended alignmentErrors,
const AlignTransform globalCoordinates,
Alignments newAlignments,
AlignmentErrorsExtended newAlignmentErrorsExtended 
)
inline

Definition at line 172 of file GeometryAligner.h.

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

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

Referenced by AlignmentProducerBase::writeDB().

TkRotation< float >
BeamSpotPI::parameters
parameters
Definition: BeamSpotPayloadInspectorHelper.h:30
GeomDet
Definition: GeomDet.h:27
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
AlignTransform::Rotation
CLHEP::HepRotation Rotation
Definition: AlignTransform.h:19
geometry
Definition: geometry.py:1
AlignTransform::Translation
CLHEP::Hep3Vector Translation
Definition: AlignTransform.h:18
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
relativeConstraints.error
error
Definition: relativeConstraints.py:53
SurfaceDeformation
Definition: SurfaceDeformation.h:18
DetPositioner::setGeomDetPosition
void setGeomDetPosition(GeomDet &det, const Surface::PositionType &position, const Surface::RotationType &rotation)
Definition: DetPositioner.h:28
Point3DBase< float, GlobalTag >
AlignTransform
Definition: AlignTransform.h:15
idealTransformation.rotation
dictionary rotation
Definition: idealTransformation.py:1
DetPositioner::setAlignmentPositionError
bool setAlignmentPositionError(GeomDet &det, const AlignmentPositionError &ape)
Definition: DetPositioner.h:37
AlignTransform::rotation
Rotation rotation() const
Definition: AlignTransform.h:38
position
static int position[264][3]
Definition: ReadPGInfo.cc:289
AlignTransform::translation
const Translation & translation() const
Definition: AlignTransform.h:33
AlignTransformErrorExtended
Definition: AlignTransformErrorExtended.h:13
DetPositioner::setSurfaceDeformation
void setSurfaceDeformation(GeomDetUnit &detUnit, const SurfaceDeformation *deformation)
Definition: DetPositioner.h:44
AlignmentSurfaceDeformations::parameters
ParametersConstIteratorPair parameters(size_t index) const
Definition: AlignmentSurfaceDeformations.h:59
Alignments::m_align
std::vector< AlignTransform > m_align
Definition: Alignments.h:19
AlignmentErrorsExtended::m_alignError
std::vector< AlignTransformErrorExtended > m_alignError
Definition: AlignmentErrorsExtended.h:19
cms::Exception
Definition: Exception.h:70
GlobalErrorBaseExtended< double, ErrorMatrixTag >
AlignmentPositionError
Definition: AlignmentPositionError.h:10
AlignmentSurfaceDeformations::items
const ItemVector & items() const
Get vector of all items.
Definition: AlignmentSurfaceDeformations.h:55
AlignmentSurfaceDeformations::ParametersConstIteratorPair
std::pair< ParametersConstIterator, ParametersConstIterator > ParametersConstIteratorPair
Definition: AlignmentSurfaceDeformations.h:32
SurfaceDeformationFactory::create
SurfaceDeformation * create(int type, const std::vector< double > &params)
Definition: SurfaceDeformationFactory.cc:40