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 )
00018 {
00019 edm::ESHandle< Alignments > alignments ;
00020 iRecord.getRecord< typename HcalGeometry::AlignmentRecord >().get( alignments ) ;
00021
00022 assert( alignments.isValid() &&
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 IVec dins ;
00037
00038 if( CaloGeometryDBWriter::writeFlag() )
00039 {
00040 edm::ESHandle<CaloSubdetectorGeometry> pG ;
00041 iRecord.get( HcalGeometry::producerTag() + std::string("_master"), pG ) ;
00042
00043 const CaloSubdetectorGeometry* pGptr ( pG.product() ) ;
00044
00045 pGptr->getSummary( tvec, ivec, dvec, dins ) ;
00046
00047 CaloGeometryDBWriter::writeIndexed( tvec, dvec, ivec, dins, HcalGeometry::dbString() ) ;
00048 }
00049 else
00050 {
00051 edm::ESHandle<PCaloGeometry> pG ;
00052 iRecord.getRecord<typename HcalGeometry::PGeometryRecord >().get( pG ) ;
00053
00054 tvec = pG->getTranslation() ;
00055 dvec = pG->getDimension() ;
00056 ivec = pG->getIndexes() ;
00057 dins = pG->getDenseIndices();
00058 }
00059
00060
00061 edm::ESHandle<HcalTopology> hcalTopology;
00062 iRecord.getRecord<IdealGeometryRecord>().get( hcalTopology );
00063
00064
00065
00066
00067
00068 assert( dvec.size() <= hcalTopology->getNumberOfShapes() * HcalGeometry::k_NumberOfParametersPerShape ) ;
00069 HcalGeometry* hcg=new HcalGeometry( *hcalTopology );
00070 PtrType ptr ( hcg );
00071
00072 const unsigned int nTrParm ( tvec.size()/hcalTopology->ncells() ) ;
00073
00074 ptr->fillDefaultNamedParameters() ;
00075
00076 ptr->allocateCorners( hcalTopology->ncells() ) ;
00077
00078 ptr->allocatePar( dvec.size() ,
00079 HcalGeometry::k_NumberOfParametersPerShape ) ;
00080
00081 for( unsigned int i ( 0 ) ; i < hcalTopology->ncells() ; ++i )
00082 {
00083 const unsigned int nPerShape ( HcalGeometry::k_NumberOfParametersPerShape ) ;
00084 DimVec dims ;
00085 dims.reserve( nPerShape ) ;
00086
00087 const unsigned int indx ( ivec.size()==1 ? 0 : i ) ;
00088
00089 DimVec::const_iterator dsrc ( dvec.begin() + ivec[indx]*nPerShape ) ;
00090
00091 for( unsigned int j ( 0 ) ; j != nPerShape ; ++j )
00092 {
00093 dims.push_back( *dsrc ) ;
00094 ++dsrc ;
00095 }
00096
00097 const CCGFloat* myParm ( CaloCellGeometry::getParmPtr( dims,
00098 ptr->parMgr(),
00099 ptr->parVecVec() ) ) ;
00100
00101
00102 const DetId id ( hcalTopology->denseId2detId(dins[i]) ) ;
00103
00104 const unsigned int iGlob ( 0 == globalPtr ? 0 :
00105 HcalGeometry::alignmentTransformIndexGlobal( id ) ) ;
00106
00107 assert( 0 == globalPtr || iGlob < globalPtr->m_align.size() ) ;
00108
00109 const AlignTransform* gt ( 0 == globalPtr ? 0 : &globalPtr->m_align[ iGlob ] ) ;
00110
00111 assert( 0 == gt || iGlob == HcalGeometry::alignmentTransformIndexGlobal( DetId( gt->rawId() ) ) ) ;
00112
00113 const unsigned int iLoc ( 0 == alignPtr ? 0 :
00114 HcalGeometry::alignmentTransformIndexLocal( id ) ) ;
00115
00116 assert( 0 == alignPtr || iLoc < alignPtr->m_align.size() ) ;
00117
00118 const AlignTransform* at ( 0 == alignPtr ? 0 :
00119 &alignPtr->m_align[ iLoc ] ) ;
00120
00121 assert( 0 == at || ( HcalGeometry::alignmentTransformIndexLocal( DetId( at->rawId() ) ) == iLoc ) ) ;
00122
00123 Pt3D lRef ;
00124 Pt3DVec lc ( 8, Pt3D(0,0,0) ) ;
00125 hcg->localCorners( lc, &dims.front(), dins[i], lRef ) ;
00126
00127 const Pt3D lBck ( 0.25*(lc[4]+lc[5]+lc[6]+lc[7] ) ) ;
00128 const Pt3D lCor ( lc[0] ) ;
00129
00130
00131 const unsigned int jj ( dins[i]*nTrParm ) ;
00132
00133 Tr3D tr ;
00134 const ROOT::Math::Translation3D tl ( tvec[jj], tvec[jj+1], tvec[jj+2] ) ;
00135 const ROOT::Math::EulerAngles ea (
00136 6==nTrParm ?
00137 ROOT::Math::EulerAngles( tvec[jj+3], tvec[jj+4], tvec[jj+5] ) :
00138 ROOT::Math::EulerAngles() ) ;
00139 const ROOT::Math::Transform3D rt ( ea, tl ) ;
00140 double xx,xy,xz,dx,yx,yy,yz,dy,zx,zy,zz,dz;
00141 rt.GetComponents(xx,xy,xz,dx,yx,yy,yz,dy,zx,zy,zz,dz) ;
00142 tr = Tr3D( CLHEP::HepRep3x3( xx, xy, xz,
00143 yx, yy, yz,
00144 zx, zy, zz ),
00145 CLHEP::Hep3Vector(dx,dy,dz) );
00146
00147
00148 const Tr3D atr ( 0 == at ? tr :
00149 ( 0 == gt ? at->transform()*tr :
00150 at->transform()*gt->transform()*tr ) ) ;
00151
00152
00153 const Pt3D gRef ( atr*lRef ) ;
00154 const GlobalPoint fCtr ( gRef.x(), gRef.y(), gRef.z() ) ;
00155 const Pt3D gBck ( atr*lBck ) ;
00156 const GlobalPoint fBck ( gBck.x(), gBck.y(), gBck.z() ) ;
00157 const Pt3D gCor ( atr*lCor ) ;
00158 const GlobalPoint fCor ( gCor.x(), gCor.y(), gCor.z() ) ;
00159
00160 assert( hcalTopology->detId2denseId(id) == dins[i] );
00161
00162 ptr->newCell( fCtr, fBck, fCor, myParm, id ) ;
00163 }
00164
00165 ptr->initializeParms() ;
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);