CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/CondTools/Geometry/plugins/calowriters.cc

Go to the documentation of this file.
00001 #include "Geometry/CaloEventSetup/interface/CaloGeometryDBEP.h"
00002 #include "Geometry/CaloEventSetup/interface/CaloGeometryDBWriter.h"
00003 #include "Geometry/EcalAlgo/interface/EcalBarrelGeometry.h"
00004 #include "Geometry/EcalAlgo/interface/EcalEndcapGeometry.h"
00005 #include "Geometry/EcalAlgo/interface/EcalPreshowerGeometry.h"
00006 #include "Geometry/HcalTowerAlgo/interface/HcalGeometry.h"
00007 #include "Geometry/HcalTowerAlgo/interface/CaloTowerGeometry.h"
00008 #include "Geometry/ForwardGeometry/interface/ZdcGeometry.h"
00009 #include "Geometry/ForwardGeometry/interface/CastorGeometry.h"
00010 
00011 template<>
00012 CaloGeometryDBEP<HcalGeometry, CaloGeometryDBWriter>::PtrType
00013 CaloGeometryDBEP<HcalGeometry, CaloGeometryDBWriter>::produceAligned( const typename HcalGeometry::AlignedRecord& iRecord ) 
00014 {
00015     const Alignments* alignPtr  ( 0 ) ;
00016     const Alignments* globalPtr ( 0 ) ;
00017     if( m_applyAlignment ) // get ptr if necessary
00018     {
00019         edm::ESHandle< Alignments >                                      alignments ;
00020         iRecord.getRecord< typename HcalGeometry::AlignmentRecord >().get( alignments ) ;
00021 
00022         assert( alignments.isValid() && // require valid alignments and expected size
00023                 ( alignments->m_align.size() == HcalGeometry::numberOfAlignments() ) ) ;
00024         alignPtr = alignments.product() ;
00025 
00026         edm::ESHandle< Alignments >                          globals   ;
00027         iRecord.getRecord<GlobalPositionRcd>().get( globals ) ;
00028 
00029         assert( globals.isValid() ) ;
00030         globalPtr = globals.product() ;
00031     }
00032 
00033     TrVec  tvec ;
00034     DimVec dvec ;
00035     IVec   ivec ;
00036 
00037     // Get vector of dense indices either from transient or DB ES record
00038     std::vector<uint32_t> dins;
00039     
00040     if( CaloGeometryDBWriter::writeFlag() )
00041     {
00042         edm::ESHandle<CaloSubdetectorGeometry> pG ;
00043         iRecord.get( HcalGeometry::producerTag() + std::string("_master"), pG ) ; 
00044 
00045         const CaloSubdetectorGeometry* pGptr ( pG.product() ) ;
00046 
00047         pGptr->getSummary( tvec, ivec, dvec, dins ) ;
00048         
00049         CaloGeometryDBWriter::writeIndexed( tvec, dvec, ivec, dins, HcalGeometry::dbString() ) ;
00050     }
00051     else
00052     {
00053         edm::ESHandle<PCaloGeometry> pG ;
00054         iRecord.getRecord<typename HcalGeometry::PGeometryRecord >().get( pG ) ; 
00055 
00056         tvec = pG->getTranslation() ;
00057         dvec = pG->getDimension() ;
00058         ivec = pG->getIndexes() ;
00059         dins = pG->getDenseIndices();
00060     }    
00061     //*********************************************************************************************
00062 
00063     edm::ESHandle<HcalTopology> hcalTopology;
00064     iRecord.getRecord<IdealGeometryRecord>().get( hcalTopology );
00065 
00066     // We know that the numer of shapes chanes with changing depth
00067     // so, this check is temporary disabled. We need to implement
00068     // a way either to store or calculate the number of shapes or be able
00069     // to deal with only max numer of shapes.
00070     assert( dvec.size() <= hcalTopology->getNumberOfShapes() * HcalGeometry::k_NumberOfParametersPerShape ) ;
00071     HcalGeometry* hcg=new HcalGeometry( *hcalTopology );
00072     PtrType ptr ( hcg );
00073 
00074     const unsigned int nTrParm ( tvec.size()/hcalTopology->ncells() ) ;
00075     
00076     ptr->fillDefaultNamedParameters() ;
00077 
00078     ptr->allocateCorners( hcalTopology->ncells() ) ;
00079 
00080     ptr->allocatePar(    dvec.size() ,
00081                          HcalGeometry::k_NumberOfParametersPerShape ) ;
00082 
00083     for( unsigned int i ( 0 ) ; i < dins.size() ; ++i )
00084     {
00085         const unsigned int nPerShape ( HcalGeometry::k_NumberOfParametersPerShape ) ;
00086         DimVec dims ;
00087         dims.reserve( nPerShape ) ;
00088 
00089         const unsigned int indx ( ivec.size()==1 ? 0 : i ) ;
00090 
00091         DimVec::const_iterator dsrc ( dvec.begin() + ivec[indx]*nPerShape ) ;
00092 
00093         for( unsigned int j ( 0 ) ; j != nPerShape ; ++j )
00094         {
00095             dims.push_back( *dsrc ) ;
00096             ++dsrc ;
00097         }
00098 
00099         const CCGFloat* myParm ( CaloCellGeometry::getParmPtr( dims, 
00100                                                                ptr->parMgr(), 
00101                                                                ptr->parVecVec() ) ) ;
00102 
00103 
00104         const DetId id ( hcalTopology->denseId2detId(dins[i]) ) ;
00105     
00106         const unsigned int iGlob ( 0 == globalPtr ? 0 :
00107                                    HcalGeometry::alignmentTransformIndexGlobal( id ) ) ;
00108 
00109         assert( 0 == globalPtr || iGlob < globalPtr->m_align.size() ) ;
00110 
00111         const AlignTransform* gt ( 0 == globalPtr ? 0 : &globalPtr->m_align[ iGlob ] ) ;
00112 
00113         assert( 0 == gt || iGlob == HcalGeometry::alignmentTransformIndexGlobal( DetId( gt->rawId() ) ) ) ;
00114 
00115         const unsigned int iLoc ( 0 == alignPtr ? 0 :
00116                                   HcalGeometry::alignmentTransformIndexLocal( id ) ) ;
00117 
00118         assert( 0 == alignPtr || iLoc < alignPtr->m_align.size() ) ;
00119 
00120         const AlignTransform* at ( 0 == alignPtr ? 0 :
00121                                    &alignPtr->m_align[ iLoc ] ) ;
00122 
00123         assert( 0 == at || ( HcalGeometry::alignmentTransformIndexLocal( DetId( at->rawId() ) ) == iLoc ) ) ;
00124 
00125         Pt3D  lRef ;
00126         Pt3DVec lc ( 8, Pt3D(0,0,0) ) ;
00127         hcg->localCorners( lc, &dims.front(), dins[i], lRef ) ;
00128 
00129         const Pt3D lBck ( 0.25*(lc[4]+lc[5]+lc[6]+lc[7] ) ) ; // ctr rear  face in local
00130         const Pt3D lCor ( lc[0] ) ;
00131 
00132         //----------------------------------- create transform from 6 numbers ---
00133         const unsigned int jj ( dins[i]*nTrParm ) ;
00134         
00135         Tr3D tr ;
00136         const ROOT::Math::Translation3D tl ( tvec[jj], tvec[jj+1], tvec[jj+2] ) ;
00137         const ROOT::Math::EulerAngles ea (
00138             6==nTrParm ?
00139             ROOT::Math::EulerAngles( tvec[jj+3], tvec[jj+4], tvec[jj+5] ) :
00140             ROOT::Math::EulerAngles() ) ;
00141         const ROOT::Math::Transform3D rt ( ea, tl ) ;
00142         double xx,xy,xz,dx,yx,yy,yz,dy,zx,zy,zz,dz;
00143         rt.GetComponents(xx,xy,xz,dx,yx,yy,yz,dy,zx,zy,zz,dz) ;
00144         tr = Tr3D( CLHEP::HepRep3x3( xx, xy, xz,
00145                                      yx, yy, yz,
00146                                      zx, zy, zz ), 
00147                    CLHEP::Hep3Vector(dx,dy,dz)     );
00148 
00149         // now prepend alignment(s) for final transform
00150         const Tr3D atr ( 0 == at ? tr :
00151                          ( 0 == gt ? at->transform()*tr :
00152                            at->transform()*gt->transform()*tr ) ) ;
00153         //--------------------------------- done making transform  ---------------
00154 
00155         const Pt3D        gRef ( atr*lRef ) ;
00156         const GlobalPoint fCtr ( gRef.x(), gRef.y(), gRef.z() ) ;
00157         const Pt3D        gBck ( atr*lBck ) ;
00158         const GlobalPoint fBck ( gBck.x(), gBck.y(), gBck.z() ) ;
00159         const Pt3D        gCor ( atr*lCor ) ;
00160         const GlobalPoint fCor ( gCor.x(), gCor.y(), gCor.z() ) ;
00161 
00162         ptr->newCell(  fCtr, fBck, fCor, myParm, id ) ;
00163     }
00164     
00165     ptr->initializeParms() ; // initializations; must happen after cells filled
00166 
00167     return ptr ; 
00168 }
00169  
00170 template class CaloGeometryDBEP< EcalBarrelGeometry    , CaloGeometryDBWriter> ;
00171 template class CaloGeometryDBEP< EcalEndcapGeometry    , CaloGeometryDBWriter> ;
00172 template class CaloGeometryDBEP< EcalPreshowerGeometry , CaloGeometryDBWriter> ;
00173 
00174 template class CaloGeometryDBEP< HcalGeometry, CaloGeometryDBWriter> ;
00175 template class CaloGeometryDBEP< CaloTowerGeometry     , CaloGeometryDBWriter> ;
00176 template class CaloGeometryDBEP< ZdcGeometry           , CaloGeometryDBWriter> ;
00177 template class CaloGeometryDBEP< CastorGeometry        , CaloGeometryDBWriter> ;
00178 
00179 typedef CaloGeometryDBEP< EcalBarrelGeometry , CaloGeometryDBWriter> 
00180 EcalBarrelGeometryToDBEP ;
00181 
00182 DEFINE_FWK_EVENTSETUP_MODULE(EcalBarrelGeometryToDBEP);
00183 
00184 typedef CaloGeometryDBEP< EcalEndcapGeometry , CaloGeometryDBWriter> 
00185 EcalEndcapGeometryToDBEP ;
00186 
00187 DEFINE_FWK_EVENTSETUP_MODULE(EcalEndcapGeometryToDBEP);
00188 
00189 typedef CaloGeometryDBEP< EcalPreshowerGeometry , CaloGeometryDBWriter> 
00190 EcalPreshowerGeometryToDBEP ;
00191 
00192 DEFINE_FWK_EVENTSETUP_MODULE(EcalPreshowerGeometryToDBEP);
00193 
00194 typedef CaloGeometryDBEP< HcalGeometry , CaloGeometryDBWriter> 
00195 HcalGeometryToDBEP ;
00196 
00197 DEFINE_FWK_EVENTSETUP_MODULE(HcalGeometryToDBEP);
00198 
00199 typedef CaloGeometryDBEP< CaloTowerGeometry , CaloGeometryDBWriter> 
00200 CaloTowerGeometryToDBEP ;
00201 
00202 DEFINE_FWK_EVENTSETUP_MODULE(CaloTowerGeometryToDBEP);
00203 
00204 typedef CaloGeometryDBEP< ZdcGeometry , CaloGeometryDBWriter> 
00205 ZdcGeometryToDBEP ;
00206 
00207 DEFINE_FWK_EVENTSETUP_MODULE(ZdcGeometryToDBEP);
00208 
00209 typedef CaloGeometryDBEP< CastorGeometry , CaloGeometryDBWriter> 
00210 CastorGeometryToDBEP ;
00211 
00212 DEFINE_FWK_EVENTSETUP_MODULE(CastorGeometryToDBEP);