CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/Alignment/TrackerAlignment/src/TrackerAlignment.cc

Go to the documentation of this file.
00001 // Framework
00002 #include "FWCore/Framework/interface/ESHandle.h"
00003 
00004 // Conditions database
00005 #include "FWCore/ServiceRegistry/interface/Service.h"
00006 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00007 
00008 // Geometry
00009 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00010 
00011 // Alignment
00012 #include "CondFormats/Alignment/interface/Alignments.h"
00013 #include "CondFormats/Alignment/interface/AlignmentErrors.h"
00014 
00015 #include "Alignment/TrackerAlignment/interface/TrackerAlignment.h"
00016 
00017 //__________________________________________________________________
00018 //
00019 TrackerAlignment::TrackerAlignment( const edm::EventSetup& setup ):
00020   theAlignRecordName( "TrackerAlignmentRcd" ),
00021   theErrorRecordName( "TrackerAlignmentErrorRcd" )
00022 {
00023 
00024   edm::ESHandle<TrackerGeometry> trackerGeometry;
00025   setup.get<TrackerDigiGeometryRecord>().get( trackerGeometry );
00026   theAlignableTracker = new AlignableTracker( &(*trackerGeometry) );
00027 
00028 }
00029 
00030 
00031 //__________________________________________________________________
00032 //
00033 TrackerAlignment::~TrackerAlignment( void )
00034 {
00035 
00036   delete theAlignableTracker;
00037 
00038 }
00039 
00040 
00041 //__________________________________________________________________
00042 //
00043 void TrackerAlignment::moveAlignablePixelEndCaps( int rawid , 
00044                                                   const align::Scalars& local_displacements,  
00045                                                   const align::Scalars& local_rotations  )
00046 {
00047         
00048   // Displace and rotate pixelEndCaps
00049   const align::Alignables& thePixelEndCapsAlignables = theAlignableTracker->pixelEndcapGeomDets();
00050   for ( align::Alignables::const_iterator iter = thePixelEndCapsAlignables.begin(); 
00051         iter != thePixelEndCapsAlignables.end(); ++iter )
00052     { 
00053         
00054       // Get the raw ID of the associated GeomDet
00055       int id = (*iter)->geomDetId().rawId();
00056                 
00057       // Select the given module
00058       if ( id == rawid ){
00059           
00060         // Convert local to global diplacements
00061         align::LocalVector lvector( local_displacements.at(0), local_displacements.at(1), local_displacements.at(2)); 
00062         align::GlobalVector gvector = ((*iter)->surface()).toGlobal( lvector );
00063           
00064         // global displacement 
00065         (*iter)->move( gvector );
00066           
00067         // local rotation 
00068         (*iter)->rotateAroundLocalX( local_rotations.at(0) ); // Local X axis rotation
00069         (*iter)->rotateAroundLocalY( local_rotations.at(1) ); // Local Y axis rotation
00070         (*iter)->rotateAroundLocalZ( local_rotations.at(2) ); // Local Z axis rotation
00071           
00072       }
00073     }
00074 }
00075 //__________________________________________________________________
00076 //
00077 void TrackerAlignment::moveAlignableEndCaps( int rawid , const align::Scalars& local_displacements,  const align::Scalars& local_rotations  ){
00078         
00079   // Displace and rotate EndCaps
00080   const align::Alignables& theEndCapsAlignables = theAlignableTracker->endcapGeomDets();
00081   for ( align::Alignables::const_iterator iter = theEndCapsAlignables.begin(); 
00082         iter != theEndCapsAlignables.end(); ++iter ){ 
00083                 
00084     // Get the raw ID of the associated GeomDet
00085     int id = (*iter)->geomDetId().rawId();
00086                 
00087     // Select the given module
00088     if ( id == rawid ){
00089                         
00090       // Convert local to global diplacements
00091       align::LocalVector lvector( local_displacements.at(0), local_displacements.at(1), local_displacements.at(2)); 
00092       align::GlobalVector gvector = ((*iter)->surface()).toGlobal( lvector );
00093                         
00094       // global displacement 
00095       (*iter)->move( gvector );
00096                         
00097       // local rotation 
00098       (*iter)->rotateAroundLocalX( local_rotations.at(0) ); // Local X axis rotation
00099       (*iter)->rotateAroundLocalY( local_rotations.at(1) ); // Local Y axis rotation
00100       (*iter)->rotateAroundLocalZ( local_rotations.at(2) ); // Local Z axis rotation
00101                         
00102     }
00103   }
00104 }
00105 //__________________________________________________________________
00106 //
00107 void TrackerAlignment::moveAlignablePixelHalfBarrels( int rawid , const align::Scalars& local_displacements,  const align::Scalars& local_rotations  ){
00108         
00109   // Displace and rotate PixelHalfBarrels
00110   const align::Alignables& thePixelHalfBarrelsAlignables = theAlignableTracker->pixelHalfBarrelGeomDets();
00111   for ( align::Alignables::const_iterator iter = thePixelHalfBarrelsAlignables.begin(); 
00112         iter != thePixelHalfBarrelsAlignables.end(); ++iter ){ 
00113                 
00114     // Get the raw ID of the associated GeomDet
00115     int id = (*iter)->geomDetId().rawId();
00116                 
00117     // Select the given module
00118     if ( id == rawid ){
00119                         
00120       // Convert local to global diplacements
00121       align::LocalVector lvector( local_displacements.at(0), local_displacements.at(1), local_displacements.at(2)); 
00122       align::GlobalVector gvector = ((*iter)->surface()).toGlobal( lvector );
00123                         
00124       // global displacement 
00125       (*iter)->move( gvector );
00126                         
00127       // local rotation 
00128       (*iter)->rotateAroundLocalX( local_rotations.at(0) ); // Local X axis rotation
00129       (*iter)->rotateAroundLocalY( local_rotations.at(1) ); // Local Y axis rotation
00130       (*iter)->rotateAroundLocalZ( local_rotations.at(2) ); // Local Z axis rotation
00131                         
00132     }
00133   }
00134 }
00135 //__________________________________________________________________
00136 //
00137 void TrackerAlignment::moveAlignableOuterHalfBarrels( int rawid , const align::Scalars& local_displacements,  const align::Scalars& local_rotations  ){
00138         
00139   // Displace and rotate OuterHalfBarrels
00140   const align::Alignables& theOuterHalfBarrelsAlignables = theAlignableTracker->outerBarrelGeomDets();
00141   for ( align::Alignables::const_iterator iter = theOuterHalfBarrelsAlignables.begin(); 
00142         iter != theOuterHalfBarrelsAlignables.end(); ++iter ){ 
00143                 
00144     // Get the raw ID of the associated GeomDet
00145     int id = (*iter)->geomDetId().rawId();
00146                 
00147     // Select the given module
00148     if ( id == rawid ){
00149                         
00150       // Convert local to global diplacements
00151       align::LocalVector lvector( local_displacements.at(0), local_displacements.at(1), local_displacements.at(2)); 
00152       align::GlobalVector gvector = ((*iter)->surface()).toGlobal( lvector );
00153                         
00154       // global displacement 
00155       (*iter)->move( gvector );
00156                         
00157       // local rotation 
00158       (*iter)->rotateAroundLocalX( local_rotations.at(0) ); // Local X axis rotation
00159       (*iter)->rotateAroundLocalY( local_rotations.at(1) ); // Local Y axis rotation
00160       (*iter)->rotateAroundLocalZ( local_rotations.at(2) ); // Local Z axis rotation
00161                         
00162     }
00163   }
00164 }
00165 //__________________________________________________________________
00166 //
00167 void TrackerAlignment::moveAlignableInnerHalfBarrels( int rawid , const align::Scalars& local_displacements,  const align::Scalars& local_rotations  ){
00168         
00169   // Displace and rotate InnerHalfBarrels
00170   const align::Alignables& theInnerHalfBarrelsAlignables = theAlignableTracker->innerBarrelGeomDets();
00171   for ( align::Alignables::const_iterator iter = theInnerHalfBarrelsAlignables.begin(); 
00172         iter != theInnerHalfBarrelsAlignables.end(); ++iter ){ 
00173                 
00174     // Get the raw ID of the associated GeomDet
00175     int id = (*iter)->geomDetId().rawId();
00176                 
00177     // Select the given module
00178     if ( id == rawid ){
00179                         
00180       // Convert local to global diplacements
00181       align::LocalVector lvector( local_displacements.at(0), local_displacements.at(1), local_displacements.at(2)); 
00182       align::GlobalVector gvector = ((*iter)->surface()).toGlobal( lvector );
00183                         
00184       // global displacement 
00185       (*iter)->move( gvector );
00186                         
00187       // local rotation 
00188       (*iter)->rotateAroundLocalX( local_rotations.at(0) ); // Local X axis rotation
00189       (*iter)->rotateAroundLocalY( local_rotations.at(1) ); // Local Y axis rotation
00190       (*iter)->rotateAroundLocalZ( local_rotations.at(2) ); // Local Z axis rotation
00191                         
00192     }
00193   }
00194 }
00195 //__________________________________________________________________
00196 //
00197 void TrackerAlignment::moveAlignableTIDs( int rawid , const align::Scalars& local_displacements,  const align::Scalars& local_rotations  ){
00198         
00199   // Displace and rotate TIDs
00200   const align::Alignables& theTIDsAlignables = theAlignableTracker->TIDGeomDets();
00201   for ( align::Alignables::const_iterator iter = theTIDsAlignables.begin(); 
00202         iter != theTIDsAlignables.end(); ++iter ){ 
00203                 
00204     // Get the raw ID of the associated GeomDet
00205     int id = (*iter)->geomDetId().rawId();
00206                 
00207     // Select the given module
00208     if ( id == rawid ){
00209                         
00210       // Convert local to global diplacements
00211       align::LocalVector lvector( local_displacements.at(0), local_displacements.at(1), local_displacements.at(2)); 
00212       align::GlobalVector gvector = ((*iter)->surface()).toGlobal( lvector );
00213                         
00214       // global displacement 
00215       (*iter)->move( gvector );
00216                         
00217       // local rotation 
00218       (*iter)->rotateAroundLocalX( local_rotations.at(0) ); // Local X axis rotation
00219       (*iter)->rotateAroundLocalY( local_rotations.at(1) ); // Local Y axis rotation
00220       (*iter)->rotateAroundLocalZ( local_rotations.at(2) ); // Local Z axis rotation
00221                         
00222     }
00223   }
00224 }
00225 
00226 //__________________________________________________________________
00227 //
00228 void TrackerAlignment::moveAlignableTIBTIDs( int rawId, const align::Scalars& globalDisplacements, const align::RotationType& backwardRotation, const align::RotationType& forwardRotation, bool toAndFro ){
00229 
00230   // Displace and rotate TIB and TID
00231   const align::Alignables& theTIBTIDAlignables = theAlignableTracker->TIBTIDGeomDets();
00232   for ( align::Alignables::const_iterator iter = theTIBTIDAlignables.begin(); 
00233         iter != theTIBTIDAlignables.end(); ++iter )
00234     { 
00235             
00236       // Get the raw ID of the associated GeomDet
00237       int id = (*iter)->geomDetId().rawId();
00238             
00239       // Select the given module
00240       if ( id == rawId ){
00241               
00242         // global displacement 
00243         align::GlobalVector gvector (globalDisplacements.at(0), globalDisplacements.at(1), globalDisplacements.at(2));
00244         (*iter)->move( gvector );
00245               
00246         // global rotation
00247         if (toAndFro) { 
00248           align::RotationType theResultRotation = backwardRotation*forwardRotation.transposed();
00249           (*iter)->rotateInGlobalFrame( theResultRotation ); 
00250         } else {
00251           (*iter)->rotateInGlobalFrame( backwardRotation );
00252         }
00253       }
00254     }
00255 }
00256 
00257 
00258 //__________________________________________________________________
00259 //
00260 void TrackerAlignment::saveToDB(void){
00261         
00262   // Output POOL-ORA objects
00263   edm::Service<cond::service::PoolDBOutputService> poolDbService;
00264   if( !poolDbService.isAvailable() ) // Die if not available
00265         throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
00266 
00267   // Retrieve and store
00268   Alignments* alignments = theAlignableTracker->alignments();
00269   AlignmentErrors* alignmentErrors = theAlignableTracker->alignmentErrors();
00270 
00271 //   if ( poolDbService->isNewTagRequest(theAlignRecordName) )
00272 //     poolDbService->createNewIOV<Alignments>( alignments, poolDbService->endOfTime(), 
00273 //                                              theAlignRecordName );
00274 //   else
00275 //     poolDbService->appendSinceTime<Alignments>( alignments, poolDbService->currentTime(), 
00276 //                                                 theAlignRecordName );
00277   poolDbService->writeOne<Alignments>(alignments, poolDbService->currentTime(),
00278                                       theAlignRecordName);
00279 //   if ( poolDbService->isNewTagRequest(theErrorRecordName) )
00280 //     poolDbService->createNewIOV<AlignmentErrors>( alignmentErrors,
00281 //                                                   poolDbService->endOfTime(), 
00282 //                                                   theErrorRecordName );
00283 //   else
00284 //     poolDbService->appendSinceTime<AlignmentErrors>( alignmentErrors,
00285 //                                                      poolDbService->currentTime(), 
00286 //                                                      theErrorRecordName );
00287   poolDbService->writeOne<AlignmentErrors>(alignmentErrors, poolDbService->currentTime(),
00288                                            theErrorRecordName);
00289 }
00290