CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/Geometry/HcalEventSetup/src/moduleDB.cc

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