CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/Geometry/EcalAlgo/src/WriteESAlignments.cc

Go to the documentation of this file.
00001 #include "Geometry/EcalAlgo/interface/WriteESAlignments.h"
00002 
00003 #include "FWCore/Framework/interface/ESHandle.h"
00004 #include "FWCore/Framework/interface/EventSetup.h"
00005 #include "FWCore/ServiceRegistry/interface/Service.h"
00006 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00007 
00008 #include "Geometry/EcalAlgo/interface/EcalPreshowerGeometry.h"
00009 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00010 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00011 
00012 typedef WriteESAlignments WEA ;
00013 
00014 const unsigned int WEA::k_nA = EcalPreshowerGeometry::numberOfAlignments() ;
00015 
00016 WEA::~WriteESAlignments(){}
00017 
00018 WEA::WriteESAlignments( const edm::EventSetup& eventSetup ,
00019                         const WEA::DVec&       alphaVec   ,
00020                         const WEA::DVec&       betaVec    ,
00021                         const WEA::DVec&       gammaVec   ,
00022                         const WEA::DVec&       xtranslVec ,
00023                         const WEA::DVec&       ytranslVec ,
00024                         const WEA::DVec&       ztranslVec  ) 
00025 {
00026    assert( alphaVec.size()   == k_nA ) ;
00027    assert( betaVec.size()    == k_nA ) ;
00028    assert( gammaVec.size()   == k_nA ) ;
00029    assert( xtranslVec.size() == k_nA ) ;
00030    assert( ytranslVec.size() == k_nA ) ;
00031    assert( ztranslVec.size() == k_nA ) ;
00032 
00033    AliPtr  aliPtr ( new Alignments  ) ;// writeOne will take ownership!
00034    AliVec& vali   ( aliPtr->m_align ) ;
00035 
00036    convert( eventSetup , 
00037             alphaVec   ,
00038             betaVec    , 
00039             gammaVec   ,
00040             xtranslVec , 
00041             ytranslVec , 
00042             ztranslVec ,
00043             vali         ) ;
00044 
00045    write( aliPtr ) ;
00046 }
00047 
00048 void 
00049 WEA::write( WEA::AliPtr aliPtr ) 
00050 {
00051    std::cout << "Uploading ES alignments to the database" << std::endl ;
00052 
00053    edm::Service<cond::service::PoolDBOutputService> poolDbService ;
00054 
00055    if (!poolDbService.isAvailable()) throw cms::Exception("NotAvailable") 
00056       << "PoolDBOutputService not available";
00057 
00058    poolDbService->writeOne<Alignments>(&(*aliPtr), 
00059                                        poolDbService->currentTime(),
00060                                        "ESAlignmentRcd" ) ;
00061 }
00062 
00063 void 
00064 WEA::convert( const edm::EventSetup& eS ,
00065               const WEA::DVec&       a  ,
00066               const WEA::DVec&       b  ,
00067               const WEA::DVec&       g  ,
00068               const WEA::DVec&       x  ,
00069               const WEA::DVec&       y  ,
00070               const WEA::DVec&       z  ,
00071               WEA::AliVec&           va   ) 
00072 {
00073    edm::ESHandle<CaloGeometry>       pG   ;
00074    eS.get<CaloGeometryRecord>().get( pG ) ;
00075 
00076    const CaloSubdetectorGeometry* geom ( 
00077       pG->getSubdetectorGeometry( DetId::Ecal, EcalPreshower ) ) ;
00078 
00079    edm::ESHandle<Alignments>  pA ;
00080    eS.get<ESAlignmentRcd>().get( pA ) ;
00081    const AliVec& vaPrev ( pA->m_align ) ;
00082 
00083    va.reserve( k_nA ) ;
00084    for( unsigned int i ( 0 ) ; i != k_nA ; ++i )
00085    {
00086       // ordering of i is: left, right, left, right,...
00087       // starting at ES- rear, then ES- front, 
00088       // then ES+ front, then ES+ rear
00089 
00090       const ESDetId id ( EcalPreshowerGeometry::detIdFromLocalAlignmentIndex( i ) ) ;
00091 
00092       const double zPlanePrev ( geom->getGeometry( id )->getPosition().z() ) ;
00093       const double zAlignPrev ( vaPrev[i].translation().z() ) ;
00094       const Trl    q_I ( 0, 0, zPlanePrev - zAlignPrev ) ;
00095       const Trl&   s_p ( vaPrev[i].translation() ) ;
00096       const Trl    t_n ( x[i], y[i], z[i] ) ;
00097       const Rot    G_p ( vaPrev[i].rotation() ) ;
00098       const double gamma ( g[i] ) ;
00099       const double alpha ( a[i] ) ;
00100       const double beta  ( b[i] ) ;
00101 
00102       const Rot L_n ( // New rotation in local frame!
00103          Rot( Rot( Rot().rotateZ( -gamma ) ).rotateX( -alpha ) ).rotateY( -beta ) ) ;
00104 
00105       const Rot InvL_n ( L_n.inverse() ) ;
00106 
00107       const Rot G_n ( InvL_n * G_p ) ;
00108 
00109       const Trl s_n ( t_n + s_p + q_I - InvL_n*q_I ) ;
00110 
00111       std::cout<<"For i = "<<i<<", q_I="<<q_I<<std::endl ;
00112       std::cout<<"For i = "<<i<<", s_p="<<s_p<<std::endl ;
00113       std::cout<<"For i = "<<i<<", alpha = "<<1000.*alpha<<" mr"<<std::endl;
00114       std::cout<<"For i = "<<i<<", beta  = "<<1000.*beta <<" mr"<<std::endl;
00115       std::cout<<"For i = "<<i<<", gamma = "<<1000.*gamma<<" mr"<<std::endl;
00116       std::cout<<" For i = "<<i<<", L_n = "<< L_n
00117                <<"   Euler angles="<<InvL_n.eulerAngles()<<"\n"<<std::endl;
00118       std::cout<<"For i = "<<i<<", t_n="<<t_n<<std::endl ;
00119       std::cout<<"For i = "<<i<<", G_p="<<G_p
00120                <<"   Euler angles="<<G_p.eulerAngles()<<"\n"<<std::endl ;
00121       std::cout<<" For i = "<<i<<", InvL_n = "<< InvL_n
00122                <<"   Euler angles="<<InvL_n.eulerAngles()<<"\n"<<std::endl;
00123       std::cout<<" For i ="<<i<<", G_n = "<< G_n
00124                <<"    Euler angles="<<G_n.eulerAngles()<<"\n"<<std::endl;
00125       std::cout<<" For i ="<<i<<", s_n = "<< s_n<<std::endl;
00126       std::cout<<"++++++++++++++++++++++++++\n\n"<<std::endl;
00127 
00128       va.push_back( AlignTransform( s_n, G_n, id ) ) ;
00129    }
00130 }