Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:57:28

0001 // Framework
0002 #include "FWCore/Framework/interface/ESHandle.h"
0003 #include "FWCore/Framework/interface/ConsumesCollector.h"
0004 // Conditions database
0005 #include "FWCore/ServiceRegistry/interface/Service.h"
0006 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0007 
0008 // Geometry
0009 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0010 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0011 
0012 // Alignment
0013 #include "CondFormats/Alignment/interface/Alignments.h"
0014 #include "CondFormats/Alignment/interface/AlignmentErrorsExtended.h"
0015 
0016 #include "Alignment/TrackerAlignment/interface/TrackerAlignment.h"
0017 
0018 //__________________________________________________________________
0019 //
0020 TrackerAlignment::TrackerAlignment(const TrackerTopology* tTopo, const TrackerGeometry* tGeom)
0021     : theAlignRecordName("TrackerAlignmentRcd"), theErrorRecordName("TrackerAlignmentErrorExtendedRcd") {
0022   theAlignableTracker = new AlignableTracker(tGeom, tTopo);
0023 }
0024 
0025 //__________________________________________________________________
0026 //
0027 TrackerAlignment::~TrackerAlignment(void) { delete theAlignableTracker; }
0028 
0029 //__________________________________________________________________
0030 //
0031 void TrackerAlignment::moveAlignablePixelEndCaps(int rawid,
0032                                                  const align::Scalars& local_displacements,
0033                                                  const align::Scalars& local_rotations) {
0034   // Displace and rotate pixelEndCaps
0035   const align::Alignables& thePixelEndCapsAlignables = theAlignableTracker->pixelEndcapGeomDets();
0036   for (align::Alignables::const_iterator iter = thePixelEndCapsAlignables.begin();
0037        iter != thePixelEndCapsAlignables.end();
0038        ++iter) {
0039     // Get the raw ID of the associated GeomDet
0040     int id = (*iter)->geomDetId().rawId();
0041 
0042     // Select the given module
0043     if (id == rawid) {
0044       // Convert local to global diplacements
0045       align::LocalVector lvector(local_displacements.at(0), local_displacements.at(1), local_displacements.at(2));
0046       align::GlobalVector gvector = ((*iter)->surface()).toGlobal(lvector);
0047 
0048       // global displacement
0049       (*iter)->move(gvector);
0050 
0051       // local rotation
0052       (*iter)->rotateAroundLocalX(local_rotations.at(0));  // Local X axis rotation
0053       (*iter)->rotateAroundLocalY(local_rotations.at(1));  // Local Y axis rotation
0054       (*iter)->rotateAroundLocalZ(local_rotations.at(2));  // Local Z axis rotation
0055     }
0056   }
0057 }
0058 //__________________________________________________________________
0059 //
0060 void TrackerAlignment::moveAlignableEndCaps(int rawid,
0061                                             const align::Scalars& local_displacements,
0062                                             const align::Scalars& local_rotations) {
0063   // Displace and rotate EndCaps
0064   const align::Alignables& theEndCapsAlignables = theAlignableTracker->endcapGeomDets();
0065   for (align::Alignables::const_iterator iter = theEndCapsAlignables.begin(); iter != theEndCapsAlignables.end();
0066        ++iter) {
0067     // Get the raw ID of the associated GeomDet
0068     int id = (*iter)->geomDetId().rawId();
0069 
0070     // Select the given module
0071     if (id == rawid) {
0072       // Convert local to global diplacements
0073       align::LocalVector lvector(local_displacements.at(0), local_displacements.at(1), local_displacements.at(2));
0074       align::GlobalVector gvector = ((*iter)->surface()).toGlobal(lvector);
0075 
0076       // global displacement
0077       (*iter)->move(gvector);
0078 
0079       // local rotation
0080       (*iter)->rotateAroundLocalX(local_rotations.at(0));  // Local X axis rotation
0081       (*iter)->rotateAroundLocalY(local_rotations.at(1));  // Local Y axis rotation
0082       (*iter)->rotateAroundLocalZ(local_rotations.at(2));  // Local Z axis rotation
0083     }
0084   }
0085 }
0086 //__________________________________________________________________
0087 //
0088 void TrackerAlignment::moveAlignablePixelHalfBarrels(int rawid,
0089                                                      const align::Scalars& local_displacements,
0090                                                      const align::Scalars& local_rotations) {
0091   // Displace and rotate PixelHalfBarrels
0092   const align::Alignables& thePixelHalfBarrelsAlignables = theAlignableTracker->pixelHalfBarrelGeomDets();
0093   for (align::Alignables::const_iterator iter = thePixelHalfBarrelsAlignables.begin();
0094        iter != thePixelHalfBarrelsAlignables.end();
0095        ++iter) {
0096     // Get the raw ID of the associated GeomDet
0097     int id = (*iter)->geomDetId().rawId();
0098 
0099     // Select the given module
0100     if (id == rawid) {
0101       // Convert local to global diplacements
0102       align::LocalVector lvector(local_displacements.at(0), local_displacements.at(1), local_displacements.at(2));
0103       align::GlobalVector gvector = ((*iter)->surface()).toGlobal(lvector);
0104 
0105       // global displacement
0106       (*iter)->move(gvector);
0107 
0108       // local rotation
0109       (*iter)->rotateAroundLocalX(local_rotations.at(0));  // Local X axis rotation
0110       (*iter)->rotateAroundLocalY(local_rotations.at(1));  // Local Y axis rotation
0111       (*iter)->rotateAroundLocalZ(local_rotations.at(2));  // Local Z axis rotation
0112     }
0113   }
0114 }
0115 //__________________________________________________________________
0116 //
0117 void TrackerAlignment::moveAlignableOuterHalfBarrels(int rawid,
0118                                                      const align::Scalars& local_displacements,
0119                                                      const align::Scalars& local_rotations) {
0120   // Displace and rotate OuterHalfBarrels
0121   const align::Alignables& theOuterHalfBarrelsAlignables = theAlignableTracker->outerBarrelGeomDets();
0122   for (align::Alignables::const_iterator iter = theOuterHalfBarrelsAlignables.begin();
0123        iter != theOuterHalfBarrelsAlignables.end();
0124        ++iter) {
0125     // Get the raw ID of the associated GeomDet
0126     int id = (*iter)->geomDetId().rawId();
0127 
0128     // Select the given module
0129     if (id == rawid) {
0130       // Convert local to global diplacements
0131       align::LocalVector lvector(local_displacements.at(0), local_displacements.at(1), local_displacements.at(2));
0132       align::GlobalVector gvector = ((*iter)->surface()).toGlobal(lvector);
0133 
0134       // global displacement
0135       (*iter)->move(gvector);
0136 
0137       // local rotation
0138       (*iter)->rotateAroundLocalX(local_rotations.at(0));  // Local X axis rotation
0139       (*iter)->rotateAroundLocalY(local_rotations.at(1));  // Local Y axis rotation
0140       (*iter)->rotateAroundLocalZ(local_rotations.at(2));  // Local Z axis rotation
0141     }
0142   }
0143 }
0144 //__________________________________________________________________
0145 //
0146 void TrackerAlignment::moveAlignableInnerHalfBarrels(int rawid,
0147                                                      const align::Scalars& local_displacements,
0148                                                      const align::Scalars& local_rotations) {
0149   // Displace and rotate InnerHalfBarrels
0150   const align::Alignables& theInnerHalfBarrelsAlignables = theAlignableTracker->innerBarrelGeomDets();
0151   for (align::Alignables::const_iterator iter = theInnerHalfBarrelsAlignables.begin();
0152        iter != theInnerHalfBarrelsAlignables.end();
0153        ++iter) {
0154     // Get the raw ID of the associated GeomDet
0155     int id = (*iter)->geomDetId().rawId();
0156 
0157     // Select the given module
0158     if (id == rawid) {
0159       // Convert local to global diplacements
0160       align::LocalVector lvector(local_displacements.at(0), local_displacements.at(1), local_displacements.at(2));
0161       align::GlobalVector gvector = ((*iter)->surface()).toGlobal(lvector);
0162 
0163       // global displacement
0164       (*iter)->move(gvector);
0165 
0166       // local rotation
0167       (*iter)->rotateAroundLocalX(local_rotations.at(0));  // Local X axis rotation
0168       (*iter)->rotateAroundLocalY(local_rotations.at(1));  // Local Y axis rotation
0169       (*iter)->rotateAroundLocalZ(local_rotations.at(2));  // Local Z axis rotation
0170     }
0171   }
0172 }
0173 //__________________________________________________________________
0174 //
0175 void TrackerAlignment::moveAlignableTIDs(int rawid,
0176                                          const align::Scalars& local_displacements,
0177                                          const align::Scalars& local_rotations) {
0178   // Displace and rotate TIDs
0179   const align::Alignables& theTIDsAlignables = theAlignableTracker->TIDGeomDets();
0180   for (align::Alignables::const_iterator iter = theTIDsAlignables.begin(); iter != theTIDsAlignables.end(); ++iter) {
0181     // Get the raw ID of the associated GeomDet
0182     int id = (*iter)->geomDetId().rawId();
0183 
0184     // Select the given module
0185     if (id == rawid) {
0186       // Convert local to global diplacements
0187       align::LocalVector lvector(local_displacements.at(0), local_displacements.at(1), local_displacements.at(2));
0188       align::GlobalVector gvector = ((*iter)->surface()).toGlobal(lvector);
0189 
0190       // global displacement
0191       (*iter)->move(gvector);
0192 
0193       // local rotation
0194       (*iter)->rotateAroundLocalX(local_rotations.at(0));  // Local X axis rotation
0195       (*iter)->rotateAroundLocalY(local_rotations.at(1));  // Local Y axis rotation
0196       (*iter)->rotateAroundLocalZ(local_rotations.at(2));  // Local Z axis rotation
0197     }
0198   }
0199 }
0200 
0201 //__________________________________________________________________
0202 //
0203 void TrackerAlignment::moveAlignableTIBTIDs(int rawId,
0204                                             const align::Scalars& globalDisplacements,
0205                                             const align::RotationType& backwardRotation,
0206                                             const align::RotationType& forwardRotation,
0207                                             bool toAndFro) {
0208   // Displace and rotate TIB and TID
0209   const align::Alignables& theTIBTIDAlignables = theAlignableTracker->TIBTIDGeomDets();
0210   for (align::Alignables::const_iterator iter = theTIBTIDAlignables.begin(); iter != theTIBTIDAlignables.end();
0211        ++iter) {
0212     // Get the raw ID of the associated GeomDet
0213     int id = (*iter)->geomDetId().rawId();
0214 
0215     // Select the given module
0216     if (id == rawId) {
0217       // global displacement
0218       align::GlobalVector gvector(globalDisplacements.at(0), globalDisplacements.at(1), globalDisplacements.at(2));
0219       (*iter)->move(gvector);
0220 
0221       // global rotation
0222       if (toAndFro) {
0223         align::RotationType theResultRotation = backwardRotation * forwardRotation.transposed();
0224         (*iter)->rotateInGlobalFrame(theResultRotation);
0225       } else {
0226         (*iter)->rotateInGlobalFrame(backwardRotation);
0227       }
0228     }
0229   }
0230 }
0231 
0232 //__________________________________________________________________
0233 //
0234 void TrackerAlignment::saveToDB(void) {
0235   // Output POOL-ORA objects
0236   edm::Service<cond::service::PoolDBOutputService> poolDbService;
0237   if (!poolDbService.isAvailable())  // Die if not available
0238     throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
0239 
0240   // Retrieve and store
0241   Alignments alignments = *(theAlignableTracker->alignments());
0242   AlignmentErrorsExtended alignmentErrors = *(theAlignableTracker->alignmentErrors());
0243 
0244   //   if ( poolDbService->isNewTagRequest(theAlignRecordName) )
0245   //     poolDbService->createOneIOV<Alignments>( alignments, poolDbService->endOfTime(),
0246   //                                              theAlignRecordName );
0247   //   else
0248   //     poolDbService->appendOneIOV<Alignments>( alignments, poolDbService->currentTime(),
0249   //                                                 theAlignRecordName );
0250   // In the two calls below it is assumed that the delete of "theAlignableTracker" is also deleting the two concerned payloads...
0251   poolDbService->writeOneIOV<Alignments>(alignments, poolDbService->currentTime(), theAlignRecordName);
0252   //   if ( poolDbService->isNewTagRequest(theErrorRecordName) )
0253   //     poolDbService->createOneIOV<AlignmentErrorsExtended>( alignmentErrors,
0254   //                                                   poolDbService->endOfTime(),
0255   //                                                   theErrorRecordName );
0256   //   else
0257   //     poolDbService->appendOneIOV<AlignmentErrorsExtended>( alignmentErrors,
0258   //                                                      poolDbService->currentTime(),
0259   //                                                      theErrorRecordName );
0260   poolDbService->writeOneIOV<AlignmentErrorsExtended>(
0261       alignmentErrors, poolDbService->currentTime(), theErrorRecordName);
0262 }