CMS 3D CMS Logo

MuonAlignment.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 
4 // user include files
7 
8 // Conditions database
11 
12 // Alignment
18 
20 
25 
26 //____________________________________________________________________________________
27 //
29  theDTAlignRecordName = "DTAlignmentRcd";
30  theDTErrorRecordName = "DTAlignmentErrorExtendedRcd";
31  theCSCAlignRecordName = "CSCAlignmentRcd";
32  theCSCErrorRecordName = "CSCAlignmentErrorExtendedRcd";
33  theGEMAlignRecordName = "GEMAlignmentRcd";
34  theGEMErrorRecordName = "GEMAlignmentErrorExtendedRcd";
35  theDTSurveyRecordName = "DTSurveyRcd";
36  theDTSurveyErrorRecordName = "DTSurveyErrorExtendedRcd";
37  theCSCSurveyRecordName = "CSCSurveyRcd";
38  theCSCSurveyErrorRecordName = "CSCSurveyErrorExtendedRcd";
39  theAlignableMuon = nullptr;
40  theAlignableNavigator = nullptr;
41 }
42 
44  const CSCGeometry* cscGeometry,
45  const GEMGeometry* gemGeometry)
46  : dtGeometry_(dtGeometry), cscGeometry_(cscGeometry), gemGeometry_(gemGeometry) {
47  init();
48 
51 }
52 
54  init();
55 
56  theAlignableMuon = input.newAlignableMuon();
58 }
59 
60 //____________________________________________________________________________________
61 //
63  // Displace and rotate DT an Alignable associated to a GeomDet or GeomDetUnit
65 
66  // Convert local to global diplacements
67  align::LocalVector lvector(displacements.at(0), displacements.at(1), displacements.at(2));
68  align::GlobalVector gvector = (theAlignable->surface()).toGlobal(lvector);
69 
70  // global displacement of the chamber
71  theAlignable->move(gvector);
72 
73  // local rotation of the chamber
74  theAlignable->rotateAroundLocalX(rotations.at(0)); // Local X axis rotation
75  theAlignable->rotateAroundLocalY(rotations.at(1)); // Local Y axis rotation
76  theAlignable->rotateAroundLocalZ(rotations.at(2)); // Local Z axis rotation
77 }
78 
79 //____________________________________________________________________________________
80 //
82  // Displace and rotate DT an Alignable associated to a GeomDet or GeomDetUnit
84 
85  // Convert std::vector to GlobalVector
86  align::GlobalVector gvector(displacements.at(0), displacements.at(1), displacements.at(2));
87 
88  // global displacement of the chamber
89  theAlignable->move(gvector);
90 
91  // local rotation of the chamber
92  theAlignable->rotateAroundGlobalX(rotations.at(0)); // Global X axis rotation
93  theAlignable->rotateAroundGlobalY(rotations.at(1)); // Global Y axis rotation
94  theAlignable->rotateAroundGlobalZ(rotations.at(2)); // Global Z axis rotation
95 }
96 
97 //____________________________________________________________________________________
98 //
100  for (align::Alignables::const_iterator alignable = alignables.begin(); alignable != alignables.end(); ++alignable) {
101  recursiveList((*alignable)->components(), theList);
102  theList.push_back(*alignable);
103  }
104 }
105 
106 //____________________________________________________________________________________
107 //
108 void MuonAlignment::recursiveMap(const align::Alignables& alignables, std::map<align::ID, Alignable*>& theMap) {
109  for (align::Alignables::const_iterator alignable = alignables.begin(); alignable != alignables.end(); ++alignable) {
110  unsigned int rawId = (*alignable)->geomDetId().rawId();
111  if (rawId != 0) {
112  theMap[rawId] = *alignable;
113  }
114  recursiveMap((*alignable)->components(), theMap);
115  }
116 }
117 
118 //____________________________________________________________________________________
119 //
121  std::map<std::pair<align::StructureType, align::ID>, Alignable*>& theMap) {
122  for (align::Alignables::const_iterator alignable = alignables.begin(); alignable != alignables.end(); ++alignable) {
123  theMap[std::pair<align::StructureType, align::ID>((*alignable)->alignableObjectId(), (*alignable)->id())] =
124  *alignable;
125  recursiveStructureMap((*alignable)->components(), theMap);
126  }
127 }
128 
129 //____________________________________________________________________________________
130 //
132  std::map<align::ID, Alignable*> alignableMap;
133  recursiveMap(theAlignableMuon->DTBarrel(), alignableMap);
134  recursiveMap(theAlignableMuon->CSCEndcaps(), alignableMap);
135  recursiveMap(theAlignableMuon->GEMEndcaps(), alignableMap);
136 
137  // Set the survey error to the alignable error, expanding the matrix as needed
141  std::vector<AlignTransformErrorExtended> alignmentErrors;
142  std::copy(dtAlignmentErrorsExtended->m_alignError.begin(),
143  dtAlignmentErrorsExtended->m_alignError.end(),
144  std::back_inserter(alignmentErrors));
145  std::copy(cscAlignmentErrorsExtended->m_alignError.begin(),
146  cscAlignmentErrorsExtended->m_alignError.end(),
147  std::back_inserter(alignmentErrors));
148  std::copy(gemAlignmentErrorsExtended->m_alignError.begin(),
149  gemAlignmentErrorsExtended->m_alignError.end(),
150  std::back_inserter(alignmentErrors));
151 
152  for (std::vector<AlignTransformErrorExtended>::const_iterator alignmentError = alignmentErrors.begin();
153  alignmentError != alignmentErrors.end();
154  ++alignmentError) {
155  align::ErrorMatrix matrix6x6 = ROOT::Math::SMatrixIdentity(); // start from (0, 0)
156  CLHEP::HepSymMatrix matrix6x6new = alignmentError->matrix(); // start from (1, 1)
157 
158  for (int i = 0; i < 6; i++) {
159  for (int j = 0; j < 6; j++) {
160  matrix6x6(i, j) = matrix6x6new(i + 1, j + 1);
161  }
162  }
163  //matrix6x6(3,3) = angleErr;
164  //matrix6x6(4,4) = angleErr;
165  //matrix6x6(5,5) = angleErr;
166 
167  Alignable* alignable = alignableMap[alignmentError->rawId()];
168  alignable->setSurvey(new SurveyDet(alignable->surface(), matrix6x6));
169  }
170 
172 }
173 
174 //____________________________________________________________________________________
175 //
176 
178  // get all the ones we missed
179  std::map<std::pair<align::StructureType, align::ID>, Alignable*> alignableStructureMap;
180  recursiveStructureMap(theAlignableMuon->DTBarrel(), alignableStructureMap);
181  recursiveStructureMap(theAlignableMuon->CSCEndcaps(), alignableStructureMap);
182 
183  for (std::map<std::pair<align::StructureType, align::ID>, Alignable*>::const_iterator iter =
184  alignableStructureMap.begin();
185  iter != alignableStructureMap.end();
186  ++iter) {
187  if (iter->second->survey() == nullptr) {
188  align::ErrorMatrix matrix6x6 = ROOT::Math::SMatrixIdentity();
189  matrix6x6(0, 0) = shiftErr;
190  matrix6x6(1, 1) = shiftErr;
191  matrix6x6(2, 2) = shiftErr;
192  matrix6x6(3, 3) = angleErr;
193  matrix6x6(4, 4) = angleErr;
194  matrix6x6(5, 5) = angleErr;
195  iter->second->setSurvey(new SurveyDet(iter->second->surface(), matrix6x6));
196  }
197  }
198 }
199 
200 //____________________________________________________________________________________
201 //
203  if (alignable->survey() != nullptr) {
204  const SurveyDet* survey = alignable->survey();
205 
206  const align::PositionType& pos = survey->position();
207  align::RotationType rot = survey->rotation();
208 
209  align::PositionType oldpos = alignable->globalPosition();
210  align::RotationType oldrot = alignable->globalRotation();
211  alignable->move(align::GlobalVector(-oldpos.x(), -oldpos.y(), -oldpos.z()));
212  alignable->rotateInGlobalFrame(oldrot.transposed());
213  alignable->rotateInGlobalFrame(rot);
214  alignable->move(align::GlobalVector(pos.x(), pos.y(), pos.z()));
215 
216  align::ErrorMatrix matrix6x6 = survey->errors(); // start from 0,0
217  AlgebraicSymMatrix66 matrix6x6new; // start from 0,0
218  for (int i = 0; i < 6; i++) {
219  for (int j = 0; j <= i; j++) {
220  matrix6x6new(i, j) = matrix6x6(i, j);
221  }
222  }
223 
224  // this sets APEs at this level and (since 2nd argument is true) all lower levels
226  }
227 
228  // do lower levels afterward to thwart the cumulative setting of APEs
229  align::Alignables components = alignable->components();
230  for (align::Alignables::const_iterator comp = components.begin(); comp != components.end(); ++comp) {
232  }
233 }
234 
236 
237 //____________________________________________________________________________________
238 // Code needed to store alignments to DB
239 
241  const DTGeometry* dtGeometryXML,
242  const CSCGeometry* cscGeometryXML,
243  const GEMGeometry* gemGeometryXML) {
244  MuonAlignmentOutputXML(iConfig, dtGeometryXML, cscGeometryXML, gemGeometryXML).write(theAlignableMuon);
245 }
246 
248  // Call service
250  if (!poolDbService.isAvailable()) // Die if not available
251  throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
252 
253  // Get alignments and errors
254  Alignments dtAlignments{};
255  SurveyErrors dtSurveyErrors{};
256 
257  align::Alignables alignableList;
258  recursiveList(theAlignableMuon->DTBarrel(), alignableList);
259 
260  for (align::Alignables::const_iterator alignable = alignableList.begin(); alignable != alignableList.end();
261  ++alignable) {
262  const align::PositionType& pos = (*alignable)->survey()->position();
263  const align::RotationType& rot = (*alignable)->survey()->rotation();
264 
265  AlignTransform value(CLHEP::Hep3Vector(pos.x(), pos.y(), pos.z()),
266  CLHEP::HepRotation(CLHEP::HepRep3x3(
267  rot.xx(), rot.xy(), rot.xz(), rot.yx(), rot.yy(), rot.yz(), rot.zx(), rot.zy(), rot.zz())),
268  (*alignable)->id());
269  SurveyError error((*alignable)->alignableObjectId(), (*alignable)->id(), (*alignable)->survey()->errors());
270 
271  dtAlignments.m_align.push_back(value);
272  dtSurveyErrors.m_surveyErrors.push_back(error);
273  }
274 
275  // Store DT alignments and errors
276  poolDbService->writeOneIOV<Alignments>(dtAlignments, poolDbService->currentTime(), theDTSurveyRecordName);
277  poolDbService->writeOneIOV<SurveyErrors>(dtSurveyErrors, poolDbService->currentTime(), theDTSurveyErrorRecordName);
278 }
279 
281  // Call service
283  if (!poolDbService.isAvailable()) // Die if not available
284  throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
285 
286  // Get alignments and errors
287  Alignments cscAlignments{};
288  SurveyErrors cscSurveyErrors{};
289 
290  align::Alignables alignableList;
291  recursiveList(theAlignableMuon->CSCEndcaps(), alignableList);
292 
293  for (align::Alignables::const_iterator alignable = alignableList.begin(); alignable != alignableList.end();
294  ++alignable) {
295  const align::PositionType& pos = (*alignable)->survey()->position();
296  const align::RotationType& rot = (*alignable)->survey()->rotation();
297 
298  AlignTransform value(CLHEP::Hep3Vector(pos.x(), pos.y(), pos.z()),
299  CLHEP::HepRotation(CLHEP::HepRep3x3(
300  rot.xx(), rot.xy(), rot.xz(), rot.yx(), rot.yy(), rot.yz(), rot.zx(), rot.zy(), rot.zz())),
301  (*alignable)->id());
302  SurveyError error((*alignable)->alignableObjectId(), (*alignable)->id(), (*alignable)->survey()->errors());
303 
304  cscAlignments.m_align.push_back(value);
305  cscSurveyErrors.m_surveyErrors.push_back(error);
306  }
307 
308  // Store CSC alignments and errors
309  poolDbService->writeOneIOV<Alignments>(cscAlignments, poolDbService->currentTime(), theCSCSurveyRecordName);
310  poolDbService->writeOneIOV<SurveyErrors>(cscSurveyErrors, poolDbService->currentTime(), theCSCSurveyErrorRecordName);
311 }
312 
316 }
317 
319  // Call service
321  if (!poolDbService.isAvailable()) // Die if not available
322  throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
323 
324  // Get alignments and errors
325  Alignments dt_Alignments = *(theAlignableMuon->dtAlignments());
326  AlignmentErrorsExtended dt_AlignmentErrorsExtended = *(theAlignableMuon->dtAlignmentErrorsExtended());
327 
328  // Store DT alignments and errors
329  poolDbService->writeOneIOV<Alignments>(dt_Alignments, poolDbService->currentTime(), theDTAlignRecordName);
330  poolDbService->writeOneIOV<AlignmentErrorsExtended>(
331  dt_AlignmentErrorsExtended, poolDbService->currentTime(), theDTErrorRecordName);
332 }
333 
335  // Call service
337  if (!poolDbService.isAvailable()) // Die if not available
338  throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
339 
340  // Get alignments and errors
341  Alignments csc_Alignments = *(theAlignableMuon->cscAlignments());
342  AlignmentErrorsExtended csc_AlignmentErrorsExtended = *(theAlignableMuon->cscAlignmentErrorsExtended());
343 
344  // Store CSC alignments and errors
345  poolDbService->writeOneIOV<Alignments>(csc_Alignments, poolDbService->currentTime(), theCSCAlignRecordName);
346  poolDbService->writeOneIOV<AlignmentErrorsExtended>(
347  csc_AlignmentErrorsExtended, poolDbService->currentTime(), theCSCErrorRecordName);
348 }
349 
351  // Call service
353  if (!poolDbService.isAvailable()) // Die if not available
354  throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
355 
356  // Get alignments and errors
357  Alignments gem_Alignments = *(theAlignableMuon->gemAlignments());
358  AlignmentErrorsExtended gem_AlignmentErrorsExtended = *(theAlignableMuon->gemAlignmentErrorsExtended());
359 
360  // Store CSC alignments and errors
361  poolDbService->writeOneIOV<Alignments>(gem_Alignments, poolDbService->currentTime(), theGEMAlignRecordName);
362  poolDbService->writeOneIOV<AlignmentErrorsExtended>(
363  gem_AlignmentErrorsExtended, poolDbService->currentTime(), theGEMErrorRecordName);
364 }
365 
367  saveDTtoDB();
368  saveCSCtoDB();
369  saveGEMtoDB();
370 }
AlignableNavigator * theAlignableNavigator
Definition: MuonAlignment.h:82
std::string theCSCErrorRecordName
Definition: MuonAlignment.h:67
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:132
virtual void rotateAroundLocalZ(Scalar radians)
Rotation around local z-axis.
Definition: Alignable.cc:183
void copyAlignmentToSurvey(double shiftErr, double angleErr)
T z() const
Definition: PV3DBase.h:61
align::Alignables DTBarrel()
const align::ErrorMatrix & errors() const
Definition: SurveyDet.h:62
virtual void move(const GlobalVector &displacement)=0
Movement with respect to the global reference frame.
void copySurveyToAlignment()
std::string theGEMAlignRecordName
Definition: MuonAlignment.h:68
void write(AlignableMuon *alignableMuon) const
static std::string const input
Definition: EdmProvDump.cc:50
std::string theDTAlignRecordName
Definition: MuonAlignment.h:66
virtual void rotateAroundGlobalZ(Scalar radians)
Rotation around global z-axis.
Definition: Alignable.cc:176
void recursiveCopySurveyToAlignment(Alignable *alignable)
void saveSurveyToDB()
T x() const
Definition: PV3DBase.h:59
TkRotation transposed() const
T y() const
Definition: PV3DBase.h:60
std::string theGEMErrorRecordName
Definition: MuonAlignment.h:68
const PositionType & globalPosition() const
Return the global position of the object.
Definition: Alignable.h:135
Alignments * dtAlignments()
Get DT alignments sorted by DetId.
const align::RotationType & rotation() const
Definition: SurveyDet.h:60
align::Alignables CSCEndcaps()
std::string theDTSurveyRecordName
Definition: MuonAlignment.h:69
const SurveyDet * survey() const
Return survey info.
Definition: Alignable.h:216
void writeXML(const edm::ParameterSet &iConfig, const DTGeometry *dtGeometryXML, const CSCGeometry *cscGeometryXML, const GEMGeometry *gemGeometryXML)
std::vector< Scalar > Scalars
Definition: Utilities.h:26
void saveDTSurveyToDB()
const DTGeometry * dtGeometry_
Definition: MuonAlignment.h:72
Hash writeOneIOV(const T &payload, Time_t time, const std::string &recordName)
Definition: value.py:1
const align::PositionType & position() const
Definition: SurveyDet.h:58
virtual const Alignables & components() const =0
Return vector of all direct components.
std::string theCSCSurveyErrorRecordName
Definition: MuonAlignment.h:70
virtual void setAlignmentPositionError(const AlignmentPositionError &ape, bool propagateDown)=0
Set the alignment position error - if (!propagateDown) do not affect daughters.
AlignableMuon * theAlignableMuon
Definition: MuonAlignment.h:80
AlignmentErrorsExtended * cscAlignmentErrorsExtended()
Get CSC alignment errors sorted by DetId.
GlobalErrorBaseExtended< double, ErrorMatrixTag > GlobalErrorExtended
Definition: GlobalError.h:14
ROOT::Math::SMatrix< double, 6, 6, ROOT::Math::MatRepSym< double, 6 > > AlgebraicSymMatrix66
std::string theCSCSurveyRecordName
Definition: MuonAlignment.h:70
std::string theDTSurveyErrorRecordName
Definition: MuonAlignment.h:69
Definition: DetId.h:17
void fillGapsInSurvey(double shiftErr, double angleErr)
virtual void rotateAroundGlobalX(Scalar radians)
Rotation around global x-axis.
Definition: Alignable.cc:148
void recursiveList(const align::Alignables &alignables, align::Alignables &theList)
virtual void rotateInGlobalFrame(const RotationType &rotation)=0
std::vector< AlignTransformErrorExtended > m_alignError
void recursiveStructureMap(const align::Alignables &alignables, std::map< std::pair< align::StructureType, align::ID >, Alignable *> &theMap)
void setSurvey(const SurveyDet *)
Set survey info.
Definition: Alignable.cc:266
Alignments * cscAlignments()
Get CSC alignments sorted by DetId.
Alignments * gemAlignments()
virtual void rotateAroundLocalY(Scalar radians)
Rotation around local y-axis.
Definition: Alignable.cc:169
void moveAlignableLocalCoord(DetId &, align::Scalars &, align::Scalars &)
virtual void rotateAroundGlobalY(Scalar radians)
Rotation around global y-axis.
Definition: Alignable.cc:162
AlignmentErrorsExtended * dtAlignmentErrorsExtended()
Get DT alignment errors sorted by DetId.
AlignmentErrorsExtended * gemAlignmentErrorsExtended()
std::vector< Alignable * > Alignables
Definition: Utilities.h:31
align::Alignables GEMEndcaps()
align::Scalars rotations
Definition: MuonAlignment.h:78
void moveAlignableGlobalCoord(DetId &, align::Scalars &, align::Scalars &)
std::string theCSCAlignRecordName
Definition: MuonAlignment.h:67
const GEMGeometry * gemGeometry_
Definition: MuonAlignment.h:74
virtual void rotateAroundLocalX(Scalar radians)
Rotation around local x-axis.
Definition: Alignable.cc:155
std::string theDTErrorRecordName
Definition: MuonAlignment.h:66
const RotationType & globalRotation() const
Return the global orientation of the object.
Definition: Alignable.h:138
bool isAvailable() const
Definition: Service.h:40
math::Error< 6 >::type ErrorMatrix
Definition: Definitions.h:37
const CSCGeometry * cscGeometry_
Definition: MuonAlignment.h:73
align::Scalars displacements
Definition: MuonAlignment.h:76
AlignableDetOrUnitPtr alignableFromDetId(const DetId &detid)
Returns AlignableDetOrUnitPtr corresponding to given DetId.
void recursiveMap(const align::Alignables &alignables, std::map< align::ID, Alignable *> &theMap)
MuonAlignment(const DTGeometry *dtGeometry, const CSCGeometry *cscGeometry, const GEMGeometry *gemGeometry)
void saveCSCSurveyToDB()