CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 // Muon geom
14 
15 // Alignment
21 
23 
28 
29 //____________________________________________________________________________________
30 //
32 {
33  theDTAlignRecordName = "DTAlignmentRcd";
34  theDTErrorRecordName = "DTAlignmentErrorExtendedRcd";
35  theCSCAlignRecordName = "CSCAlignmentRcd";
36  theCSCErrorRecordName = "CSCAlignmentErrorExtendedRcd";
37  theDTSurveyRecordName = "DTSurveyRcd";
38  theDTSurveyErrorRecordName = "DTSurveyErrorExtendedRcd";
39  theCSCSurveyRecordName = "CSCSurveyRcd";
40  theCSCSurveyErrorRecordName = "CSCSurveyErrorExtendedRcd";
43 }
44 
46 {
47  init();
48 
49  edm::ESHandle<DTGeometry> dtGeometry;
50  edm::ESHandle<CSCGeometry> cscGeometry;
51  iSetup.get<MuonGeometryRecord>().get( dtGeometry );
52  iSetup.get<MuonGeometryRecord>().get( cscGeometry );
53 
54  theAlignableMuon = new AlignableMuon( &(*dtGeometry) , &(*cscGeometry) );
56 }
57 
59 {
60  init();
61 
62  theAlignableMuon = input.newAlignableMuon( iSetup );
64 }
65 
66 //____________________________________________________________________________________
67 //
69 
70  // Displace and rotate DT an Alignable associated to a GeomDet or GeomDetUnit
71  Alignable* theAlignable = theAlignableNavigator->alignableFromDetId( detid );
72 
73  // Convert local to global diplacements
74  align::LocalVector lvector( displacements.at(0), displacements.at(1), displacements.at(2));
75  align::GlobalVector gvector = ( theAlignable->surface()).toGlobal( lvector );
76 
77  // global displacement of the chamber
78  theAlignable->move( gvector );
79 
80  // local rotation of the chamber
81  theAlignable->rotateAroundLocalX( rotations.at(0) ); // Local X axis rotation
82  theAlignable->rotateAroundLocalY( rotations.at(1) ); // Local Y axis rotation
83  theAlignable->rotateAroundLocalZ( rotations.at(2) ); // Local Z axis rotation
84 
85 }
86 
87 //____________________________________________________________________________________
88 //
90 
91  // Displace and rotate DT an Alignable associated to a GeomDet or GeomDetUnit
92  Alignable* theAlignable = theAlignableNavigator->alignableFromDetId( detid );
93 
94  // Convert std::vector to GlobalVector
95  align::GlobalVector gvector( displacements.at(0), displacements.at(1), displacements.at(2));
96 
97  // global displacement of the chamber
98  theAlignable->move( gvector );
99 
100  // local rotation of the chamber
101  theAlignable->rotateAroundGlobalX( rotations.at(0) ); // Global X axis rotation
102  theAlignable->rotateAroundGlobalY( rotations.at(1) ); // Global Y axis rotation
103  theAlignable->rotateAroundGlobalZ( rotations.at(2) ); // Global Z axis rotation
104 
105 }
106 
107 //____________________________________________________________________________________
108 //
110  for (align::Alignables::const_iterator alignable = alignables.begin(); alignable != alignables.end(); ++alignable) {
111  recursiveList((*alignable)->components(), theList);
112  theList.push_back(*alignable);
113  }
114 }
115 
116 //____________________________________________________________________________________
117 //
118 void MuonAlignment::recursiveMap(const align::Alignables& alignables, std::map<align::ID, Alignable*> &theMap) {
119  for (align::Alignables::const_iterator alignable = alignables.begin(); alignable != alignables.end(); ++alignable) {
120  unsigned int rawId = (*alignable)->geomDetId().rawId();
121  if (rawId != 0) {
122  theMap[rawId] = *alignable;
123  }
124  recursiveMap((*alignable)->components(), theMap);
125  }
126 }
127 
128 //____________________________________________________________________________________
129 //
130 void MuonAlignment::recursiveStructureMap(const align::Alignables& alignables, std::map<std::pair<align::StructureType, align::ID>, Alignable*> &theMap) {
131  for (align::Alignables::const_iterator alignable = alignables.begin(); alignable != alignables.end(); ++alignable) {
132  theMap[std::pair<align::StructureType, align::ID>((*alignable)->alignableObjectId(), (*alignable)->id())] = *alignable;
133  recursiveStructureMap((*alignable)->components(), theMap);
134  }
135 }
136 
137 //____________________________________________________________________________________
138 //
140  std::map<align::ID, Alignable*> alignableMap;
141  recursiveMap(theAlignableMuon->DTBarrel(), alignableMap);
142  recursiveMap(theAlignableMuon->CSCEndcaps(), alignableMap);
143 
144  // Set the survey error to the alignable error, expanding the matrix as needed
147  std::vector<AlignTransformErrorExtended> alignmentErrors;
148  std::copy(dtAlignmentErrorsExtended->m_alignError.begin(), dtAlignmentErrorsExtended->m_alignError.end(), std::back_inserter(alignmentErrors));
149  std::copy(cscAlignmentErrorsExtended->m_alignError.begin(), cscAlignmentErrorsExtended->m_alignError.end(), std::back_inserter(alignmentErrors));
150 
151  for (std::vector<AlignTransformErrorExtended>::const_iterator alignmentError = alignmentErrors.begin();
152  alignmentError != alignmentErrors.end();
153  ++alignmentError) {
154  align::ErrorMatrix matrix6x6 = ROOT::Math::SMatrixIdentity();
155  CLHEP::HepSymMatrix matrix6x6new = alignmentError->matrix();
156 
157  for (int i = 0; i < 6; i++) {
158  for (int j = 0; j < 6; j++) {
159  matrix6x6(i, j) = matrix6x6new(i, j);
160  }
161  }
162  //matrix6x6(3,3) = angleErr;
163  //matrix6x6(4,4) = angleErr;
164  //matrix6x6(5,5) = angleErr;
165 
166  Alignable *alignable = alignableMap[alignmentError->rawId()];
167  alignable->setSurvey(new SurveyDet(alignable->surface(), matrix6x6));
168  }
169 
170  fillGapsInSurvey(shiftErr, angleErr);
171 }
172 
173 //____________________________________________________________________________________
174 //
175 
177  // get all the ones we missed
178  std::map<std::pair<align::StructureType, align::ID>, Alignable*> alignableStructureMap;
179  recursiveStructureMap(theAlignableMuon->DTBarrel(), alignableStructureMap);
180  recursiveStructureMap(theAlignableMuon->CSCEndcaps(), alignableStructureMap);
181 
182  for (std::map<std::pair<align::StructureType, align::ID>, Alignable*>::const_iterator iter = alignableStructureMap.begin();
183  iter != alignableStructureMap.end();
184  ++iter) {
185  if (iter->second->survey() == NULL) {
186  align::ErrorMatrix matrix6x6 = ROOT::Math::SMatrixIdentity();
187  matrix6x6(0,0) = shiftErr;
188  matrix6x6(1,1) = shiftErr;
189  matrix6x6(2,2) = shiftErr;
190  matrix6x6(3,3) = angleErr;
191  matrix6x6(4,4) = angleErr;
192  matrix6x6(5,5) = angleErr;
193  iter->second->setSurvey(new SurveyDet(iter->second->surface(), matrix6x6));
194  }
195  }
196 }
197 
198 //____________________________________________________________________________________
199 //
201  if (alignable->survey() != NULL) {
202  const SurveyDet *survey = alignable->survey();
203 
204  align::PositionType pos = survey->position();
205  align::RotationType rot = survey->rotation();
206 
207  align::PositionType oldpos = alignable->globalPosition();
208  align::RotationType oldrot = alignable->globalRotation();
209  alignable->move(align::GlobalVector(-oldpos.x(), -oldpos.y(), -oldpos.z()));
210  alignable->rotateInGlobalFrame(oldrot.transposed());
211  alignable->rotateInGlobalFrame(rot);
212  alignable->move(align::GlobalVector(pos.x(), pos.y(), pos.z()));
213 
214  align::ErrorMatrix matrix6x6 = survey->errors(); // start from 0,0
215  AlgebraicSymMatrix66 matrix6x6new; // start from 0,0
216  for (int i = 0; i < 6; i++) {
217  for (int j = 0; j <= i; j++) {
218  matrix6x6new(i, j) = matrix6x6(i, j);
219  }
220  }
221 
222  // this sets APEs at this level and (since 2nd argument is true) all lower levels
224  }
225 
226  // do lower levels afterward to thwart the cumulative setting of APEs
227  align::Alignables components = alignable->components();
228  for (align::Alignables::const_iterator comp = components.begin(); comp != components.end(); ++comp) {
230  }
231 }
232 
235 }
236 
237 //____________________________________________________________________________________
238 // Code needed to store alignments to DB
239 
240 void MuonAlignment::writeXML(const edm::ParameterSet &iConfig, const edm::EventSetup &iSetup) {
242 }
243 
245  // Call service
247  if( !poolDbService.isAvailable() ) // Die if not available
248  throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
249 
250  // Get alignments and errors
251  Alignments *dtAlignments = new Alignments();
252  SurveyErrors *dtSurveyErrors = new SurveyErrors();
253 
254  align::Alignables alignableList;
255  recursiveList(theAlignableMuon->DTBarrel(), alignableList);
256 
257  for (align::Alignables::const_iterator alignable = alignableList.begin(); alignable != alignableList.end(); ++alignable) {
258  const align::PositionType &pos = (*alignable)->survey()->position();
259  const align::RotationType &rot = (*alignable)->survey()->rotation();
260 
261  AlignTransform value(CLHEP::Hep3Vector(pos.x(), pos.y(), pos.z()),
262  CLHEP::HepRotation(CLHEP::HepRep3x3(rot.xx(), rot.xy(), rot.xz(),
263  rot.yx(), rot.yy(), rot.yz(),
264  rot.zx(), rot.zy(), rot.zz())),
265  (*alignable)->id());
266  SurveyError error((*alignable)->alignableObjectId(), (*alignable)->id(), (*alignable)->survey()->errors());
267 
268  dtAlignments->m_align.push_back(value);
269  dtSurveyErrors->m_surveyErrors.push_back(error);
270  }
271 
272  // Store DT alignments and errors
273  poolDbService->writeOne<Alignments>( &(*dtAlignments), poolDbService->currentTime(), theDTSurveyRecordName);
274  poolDbService->writeOne<SurveyErrors>( &(*dtSurveyErrors), poolDbService->currentTime(), theDTSurveyErrorRecordName);
275 }
276 
278  // Call service
280  if( !poolDbService.isAvailable() ) // Die if not available
281  throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
282 
283  // Get alignments and errors
284  Alignments *cscAlignments = new Alignments();
285  SurveyErrors *cscSurveyErrors = new SurveyErrors();
286 
287  align::Alignables alignableList;
288  recursiveList(theAlignableMuon->CSCEndcaps(), alignableList);
289 
290  for (align::Alignables::const_iterator alignable = alignableList.begin(); alignable != alignableList.end(); ++alignable) {
291  const align::PositionType &pos = (*alignable)->survey()->position();
292  const align::RotationType &rot = (*alignable)->survey()->rotation();
293 
294  AlignTransform value(CLHEP::Hep3Vector(pos.x(), pos.y(), pos.z()),
295  CLHEP::HepRotation(CLHEP::HepRep3x3(rot.xx(), rot.xy(), rot.xz(),
296  rot.yx(), rot.yy(), rot.yz(),
297  rot.zx(), rot.zy(), rot.zz())),
298  (*alignable)->id());
299  SurveyError error((*alignable)->alignableObjectId(), (*alignable)->id(), (*alignable)->survey()->errors());
300 
301  cscAlignments->m_align.push_back(value);
302  cscSurveyErrors->m_surveyErrors.push_back(error);
303  }
304 
305  // Store CSC alignments and errors
306  poolDbService->writeOne<Alignments>( &(*cscAlignments), poolDbService->currentTime(), theCSCSurveyRecordName);
307  poolDbService->writeOne<SurveyErrors>( &(*cscSurveyErrors), poolDbService->currentTime(), theCSCSurveyErrorRecordName);
308 }
309 
313 }
314 
316  // Call service
318  if( !poolDbService.isAvailable() ) // Die if not available
319  throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
320 
321  // Get alignments and errors
322  Alignments* dt_Alignments = theAlignableMuon->dtAlignments() ;
323  AlignmentErrorsExtended* dt_AlignmentErrorsExtended = theAlignableMuon->dtAlignmentErrorsExtended();
324 
325  // Store DT alignments and errors
326  poolDbService->writeOne<Alignments>( &(*dt_Alignments), poolDbService->currentTime(), theDTAlignRecordName);
327  poolDbService->writeOne<AlignmentErrorsExtended>( &(*dt_AlignmentErrorsExtended), poolDbService->currentTime(), theDTErrorRecordName);
328 }
329 
331  // Call service
333  if( !poolDbService.isAvailable() ) // Die if not available
334  throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
335 
336  // Get alignments and errors
337  Alignments* csc_Alignments = theAlignableMuon->cscAlignments();
338  AlignmentErrorsExtended* csc_AlignmentErrorsExtended = theAlignableMuon->cscAlignmentErrorsExtended();
339 
340  // Store CSC alignments and errors
341  poolDbService->writeOne<Alignments>( &(*csc_Alignments), poolDbService->currentTime(), theCSCAlignRecordName);
342  poolDbService->writeOne<AlignmentErrorsExtended>( &(*csc_AlignmentErrorsExtended), poolDbService->currentTime(), theCSCErrorRecordName);
343 }
344 
346  saveDTtoDB();
347  saveCSCtoDB();
348 }
GlobalErrorBaseExtended< double, ErrorMatrixTag > GlobalErrorExtended
Definition: GlobalError.h:13
T xx() const
AlignableNavigator * theAlignableNavigator
Definition: MuonAlignment.h:72
int i
Definition: DBlmapReader.cc:9
std::string theCSCErrorRecordName
Definition: MuonAlignment.h:62
void write(AlignableMuon *alignableMuon, const edm::EventSetup &iSetup) const
virtual void rotateAroundLocalZ(Scalar radians)
Rotation around local z-axis.
Definition: Alignable.cc:216
void copyAlignmentToSurvey(double shiftErr, double angleErr)
align::Alignables DTBarrel()
const SurveyDet * survey() const
Return survey info.
Definition: Alignable.h:210
ROOT::Math::SMatrix< double, 6, 6, ROOT::Math::MatRepSym< double, 6 > > AlgebraicSymMatrix66
T y() const
Definition: PV3DBase.h:63
T yx() const
#define NULL
Definition: scimark2.h:8
const RotationType & globalRotation() const
Return the global orientation of the object.
Definition: Alignable.h:137
virtual void move(const GlobalVector &displacement)=0
Movement with respect to the global reference frame.
const align::ErrorMatrix & errors() const
Definition: SurveyDet.h:73
void copySurveyToAlignment()
virtual Alignables components() const =0
Return vector of all direct components.
std::vector< AlignTransform > m_align
Definition: Alignments.h:19
MuonAlignment(const edm::EventSetup &iSetup)
static std::string const input
Definition: EdmProvDump.cc:43
std::string theDTAlignRecordName
Definition: MuonAlignment.h:61
virtual void rotateAroundGlobalZ(Scalar radians)
Rotation around global z-axis.
Definition: Alignable.cc:203
const align::RotationType & rotation() const
Definition: SurveyDet.h:68
T zx() const
T xy() const
const align::PositionType & position() const
Definition: SurveyDet.h:63
void recursiveCopySurveyToAlignment(Alignable *alignable)
void saveSurveyToDB()
T zz() const
Alignments * dtAlignments()
align::Alignables CSCEndcaps()
std::string theDTSurveyRecordName
Definition: MuonAlignment.h:63
std::vector< Scalar > Scalars
Definition: Utilities.h:22
void saveDTSurveyToDB()
T z() const
Definition: PV3DBase.h:64
bool isAvailable() const
Definition: Service.h:46
T zy() const
int j
Definition: DBlmapReader.cc:9
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
T yy() const
std::string theCSCSurveyErrorRecordName
Definition: MuonAlignment.h:64
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:70
AlignmentErrorsExtended * cscAlignmentErrorsExtended()
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:131
std::string theCSCSurveyRecordName
Definition: MuonAlignment.h:64
std::string theDTSurveyErrorRecordName
Definition: MuonAlignment.h:63
Definition: DetId.h:18
void fillGapsInSurvey(double shiftErr, double angleErr)
virtual void rotateAroundGlobalX(Scalar radians)
Rotation around global x-axis.
Definition: Alignable.cc:151
void recursiveList(const align::Alignables &alignables, align::Alignables &theList)
virtual void rotateInGlobalFrame(const RotationType &rotation)=0
std::vector< AlignTransformErrorExtended > m_alignError
void setSurvey(const SurveyDet *)
Set survey info.
Definition: Alignable.cc:306
const T & get() const
Definition: EventSetup.h:56
virtual AlignableMuon * newAlignableMuon(const edm::EventSetup &iSetup) const
Alignments * cscAlignments()
virtual void rotateAroundLocalY(Scalar radians)
Rotation around local y-axis.
Definition: Alignable.cc:190
void moveAlignableLocalCoord(DetId &, align::Scalars &, align::Scalars &)
virtual void rotateAroundGlobalY(Scalar radians)
Rotation around global y-axis.
Definition: Alignable.cc:177
AlignmentErrorsExtended * dtAlignmentErrorsExtended()
std::vector< Alignable * > Alignables
Definition: Utilities.h:28
void moveAlignableGlobalCoord(DetId &, align::Scalars &, align::Scalars &)
std::string theCSCAlignRecordName
Definition: MuonAlignment.h:62
T xz() const
virtual void rotateAroundLocalX(Scalar radians)
Rotation around local x-axis.
Definition: Alignable.cc:164
TkRotation transposed() const
void recursiveMap(const align::Alignables &alignables, std::map< align::ID, Alignable * > &theMap)
std::string theDTErrorRecordName
Definition: MuonAlignment.h:61
void recursiveStructureMap(const align::Alignables &alignables, std::map< std::pair< align::StructureType, align::ID >, Alignable * > &theMap)
const PositionType & globalPosition() const
Return the global position of the object.
Definition: Alignable.h:134
void writeXML(const edm::ParameterSet &iConfig, const edm::EventSetup &iSetup)
math::Error< 6 >::type ErrorMatrix
Definition: Definitions.h:39
std::vector< SurveyError > m_surveyErrors
Definition: SurveyErrors.h:23
T x() const
Definition: PV3DBase.h:62
AlignableDetOrUnitPtr alignableFromDetId(const DetId &detid)
Returns AlignableDetOrUnitPtr corresponding to given DetId.
T yz() const
void saveCSCSurveyToDB()