Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:52:07

0001 #include "Geometry/CaloEventSetup/interface/CaloGeometryDBEP.h"
0002 #include "Geometry/CaloEventSetup/interface/CaloGeometryDBWriter.h"
0003 #include "Geometry/EcalAlgo/interface/EcalBarrelGeometry.h"
0004 #include "Geometry/EcalAlgo/interface/EcalEndcapGeometry.h"
0005 #include "Geometry/EcalAlgo/interface/EcalPreshowerGeometry.h"
0006 #include "Geometry/HcalTowerAlgo/interface/HcalGeometry.h"
0007 #include "Geometry/HcalTowerAlgo/interface/CaloTowerGeometry.h"
0008 #include "Geometry/HcalTowerAlgo/interface/CaloGeometryDBHcal.h"
0009 #include "Geometry/HcalTowerAlgo/interface/CaloGeometryDBCaloTower.h"
0010 #include "Geometry/ForwardGeometry/interface/ZdcGeometry.h"
0011 #include "Geometry/ForwardGeometry/interface/CastorGeometry.h"
0012 #include "Geometry/Records/interface/HcalRecNumberingRecord.h"
0013 #include "Geometry/HGCalGeometry/interface/HGCalGeometry.h"
0014 #include "Geometry/HGCalGeometry/interface/CaloGeometryDBHGCal.h"
0015 
0016 template <>
0017 CaloGeometryDBEP<HcalGeometry, CaloGeometryDBWriter>::PtrType
0018 CaloGeometryDBEP<HcalGeometry, CaloGeometryDBWriter>::produceAligned(
0019     const typename HcalGeometry::AlignedRecord& iRecord) {
0020   const auto [alignPtr, globalPtr] = getAlignGlobal(iRecord);
0021 
0022   TrVec tvec;
0023   DimVec dvec;
0024   IVec ivec;
0025   IVec dins;
0026 
0027   const auto& pG = iRecord.get(geometryToken_);
0028 
0029   pG.getSummary(tvec, ivec, dvec, dins);
0030 
0031   CaloGeometryDBWriter::writeIndexed(tvec, dvec, ivec, dins, HcalGeometry::dbString());
0032   //*********************************************************************************************
0033 
0034   const auto& hcalTopology = iRecord.get(additionalTokens_.topology);
0035 
0036   // We know that the numer of shapes chanes with changing depth
0037   // so, this check is temporary disabled. We need to implement
0038   // a way either to store or calculate the number of shapes or be able
0039   // to deal with only max numer of shapes.
0040   assert(dvec.size() <= hcalTopology.getNumberOfShapes() * HcalGeometry::k_NumberOfParametersPerShape);
0041   HcalGeometry* hcalGeometry = new HcalGeometry(hcalTopology);
0042   PtrType ptr(hcalGeometry);
0043 
0044   const unsigned int nTrParm(hcalGeometry->numberOfTransformParms());
0045 
0046   ptr->fillDefaultNamedParameters();
0047   ptr->allocateCorners(hcalTopology.ncells() + hcalTopology.getHFSize());
0048   ptr->allocatePar(hcalGeometry->numberOfShapes(), HcalGeometry::k_NumberOfParametersPerShape);
0049 
0050   for (unsigned int i(0); i < dins.size(); ++i) {
0051     const unsigned int nPerShape(HcalGeometry::k_NumberOfParametersPerShape);
0052     DimVec dims;
0053     dims.reserve(nPerShape);
0054 
0055     const unsigned int indx(ivec.size() == 1 ? 0 : i);
0056 
0057     DimVec::const_iterator dsrc(dvec.begin() + ivec[indx] * nPerShape);
0058 
0059     for (unsigned int j(0); j != nPerShape; ++j) {
0060       dims.push_back(*dsrc);
0061       ++dsrc;
0062     }
0063 
0064     const CCGFloat* myParm(CaloCellGeometry::getParmPtr(dims, ptr->parMgr(), ptr->parVecVec()));
0065 
0066     const DetId id(hcalTopology.denseId2detId(dins[i]));
0067 
0068     const unsigned int iGlob(nullptr == globalPtr ? 0 : HcalGeometry::alignmentTransformIndexGlobal(id));
0069 
0070     assert(nullptr == globalPtr || iGlob < globalPtr->m_align.size());
0071 
0072     const AlignTransform* gt(nullptr == globalPtr ? nullptr : &globalPtr->m_align[iGlob]);
0073 
0074     assert(nullptr == gt || iGlob == HcalGeometry::alignmentTransformIndexGlobal(DetId(gt->rawId())));
0075 
0076     const unsigned int iLoc(nullptr == alignPtr ? 0 : HcalGeometry::alignmentTransformIndexLocal(id));
0077 
0078     assert(nullptr == alignPtr || iLoc < alignPtr->m_align.size());
0079 
0080     const AlignTransform* at(nullptr == alignPtr ? nullptr : &alignPtr->m_align[iLoc]);
0081 
0082     assert(nullptr == at || (HcalGeometry::alignmentTransformIndexLocal(DetId(at->rawId())) == iLoc));
0083 
0084     Pt3D lRef;
0085     Pt3DVec lc(8, Pt3D(0, 0, 0));
0086     hcalGeometry->localCorners(lc, &dims.front(), dins[i], lRef);
0087 
0088     const Pt3D lBck(0.25 * (lc[4] + lc[5] + lc[6] + lc[7]));  // ctr rear  face in local
0089     const Pt3D lCor(lc[0]);
0090 
0091     //----------------------------------- create transform from 6 numbers ---
0092     const unsigned int jj(i * nTrParm);
0093 
0094     Tr3D tr;
0095     const ROOT::Math::Translation3D tl(tvec[jj], tvec[jj + 1], tvec[jj + 2]);
0096     const ROOT::Math::EulerAngles ea(6 == nTrParm ? ROOT::Math::EulerAngles(tvec[jj + 3], tvec[jj + 4], tvec[jj + 5])
0097                                                   : ROOT::Math::EulerAngles());
0098     const ROOT::Math::Transform3D rt(ea, tl);
0099     double xx, xy, xz, dx;
0100     double yx, yy, yz, dy;
0101     double zx, zy, zz, dz;
0102     rt.GetComponents(xx, xy, xz, dx, yx, yy, yz, dy, zx, zy, zz, dz);
0103     tr = Tr3D(CLHEP::HepRep3x3(xx, xy, xz, yx, yy, yz, zx, zy, zz), CLHEP::Hep3Vector(dx, dy, dz));
0104 
0105     // now prepend alignment(s) for final transform
0106     const Tr3D atr(nullptr == at ? tr
0107                                  : (nullptr == gt ? at->transform() * tr : at->transform() * gt->transform() * tr));
0108     //--------------------------------- done making transform  ---------------
0109 
0110     const Pt3D gRef(atr * lRef);
0111     const GlobalPoint fCtr(gRef.x(), gRef.y(), gRef.z());
0112     const Pt3D gBck(atr * lBck);
0113     const GlobalPoint fBck(gBck.x(), gBck.y(), gBck.z());
0114     const Pt3D gCor(atr * lCor);
0115     const GlobalPoint fCor(gCor.x(), gCor.y(), gCor.z());
0116 
0117     assert(hcalTopology.detId2denseId(id) == dins[i]);
0118     ptr->newCell(fCtr, fBck, fCor, myParm, id);
0119   }
0120 
0121   ptr->initializeParms();  // initializations; must happen after cells filled
0122 
0123   return ptr;
0124 }
0125 
0126 template <>
0127 CaloGeometryDBEP<CaloTowerGeometry, CaloGeometryDBWriter>::PtrType
0128 CaloGeometryDBEP<CaloTowerGeometry, CaloGeometryDBWriter>::produceAligned(
0129     const typename CaloTowerGeometry::AlignedRecord& iRecord) {
0130   const auto [alignPtr, globalPtr] = getAlignGlobal(iRecord);
0131 
0132   TrVec tvec;
0133   DimVec dvec;
0134   IVec ivec;
0135   IVec dins;
0136 
0137   const auto& pG = iRecord.get(geometryToken_);
0138 
0139   pG.getSummary(tvec, ivec, dvec, dins);
0140 
0141   CaloGeometryDBWriter::writeIndexed(tvec, dvec, ivec, dins, CaloTowerGeometry::dbString());
0142   //*********************************************************************************************
0143 
0144   const auto& caloTopology = iRecord.get(additionalTokens_.topology);
0145 
0146   CaloTowerGeometry* ctg = new CaloTowerGeometry(&caloTopology);
0147 
0148   const unsigned int nTrParm(tvec.size() / ctg->numberOfCellsForCorners());
0149 
0150   assert(dvec.size() == ctg->numberOfShapes() * CaloTowerGeometry::k_NumberOfParametersPerShape);
0151 
0152   PtrType ptr(ctg);
0153 
0154   ptr->fillDefaultNamedParameters();
0155 
0156   ptr->allocateCorners(ctg->numberOfCellsForCorners());
0157 
0158   ptr->allocatePar(dvec.size(), CaloTowerGeometry::k_NumberOfParametersPerShape);
0159 
0160   for (unsigned int i(0); i < dins.size(); ++i) {
0161     const unsigned int nPerShape(ctg->numberOfParametersPerShape());
0162     DimVec dims;
0163     dims.reserve(nPerShape);
0164 
0165     const unsigned int indx(ivec.size() == 1 ? 0 : i);
0166 
0167     DimVec::const_iterator dsrc(dvec.begin() + ivec[indx] * nPerShape);
0168 
0169     for (unsigned int j(0); j != nPerShape; ++j) {
0170       dims.push_back(*dsrc);
0171       ++dsrc;
0172     }
0173 
0174     const CCGFloat* myParm(CaloCellGeometry::getParmPtr(dims, ptr->parMgr(), ptr->parVecVec()));
0175 
0176     const DetId id(caloTopology.detIdFromDenseIndex(dins[i]));
0177 
0178     const unsigned int iGlob(nullptr == globalPtr ? 0 : ctg->alignmentTransformIndexGlobal(id));
0179 
0180     assert(nullptr == globalPtr || iGlob < globalPtr->m_align.size());
0181 
0182     const AlignTransform* gt(nullptr == globalPtr ? nullptr : &globalPtr->m_align[iGlob]);
0183 
0184     assert(nullptr == gt || iGlob == ctg->alignmentTransformIndexGlobal(DetId(gt->rawId())));
0185 
0186     const unsigned int iLoc(nullptr == alignPtr ? 0 : ctg->alignmentTransformIndexLocal(id));
0187 
0188     assert(nullptr == alignPtr || iLoc < alignPtr->m_align.size());
0189 
0190     const AlignTransform* at(nullptr == alignPtr ? nullptr : &alignPtr->m_align[iLoc]);
0191 
0192     assert(nullptr == at || (ctg->alignmentTransformIndexLocal(DetId(at->rawId())) == iLoc));
0193 
0194     const CaloGenericDetId gId(id);
0195 
0196     Pt3D lRef;
0197     Pt3DVec lc(8, Pt3D(0, 0, 0));
0198     ctg->localCorners(lc, &dims.front(), dins[i], lRef);
0199 
0200     const Pt3D lBck(0.25 * (lc[4] + lc[5] + lc[6] + lc[7]));  // ctr rear  face in local
0201     const Pt3D lCor(lc[0]);
0202 
0203     //----------------------------------- create transform from 6 numbers ---
0204     const unsigned int jj(i * nTrParm);
0205     Tr3D tr;
0206     const ROOT::Math::Translation3D tl(tvec[jj], tvec[jj + 1], tvec[jj + 2]);
0207     const ROOT::Math::EulerAngles ea(6 == nTrParm ? ROOT::Math::EulerAngles(tvec[jj + 3], tvec[jj + 4], tvec[jj + 5])
0208                                                   : ROOT::Math::EulerAngles());
0209     const ROOT::Math::Transform3D rt(ea, tl);
0210     double xx, xy, xz, dx, yx, yy, yz, dy, zx, zy, zz, dz;
0211     rt.GetComponents(xx, xy, xz, dx, yx, yy, yz, dy, zx, zy, zz, dz);
0212     tr = Tr3D(CLHEP::HepRep3x3(xx, xy, xz, yx, yy, yz, zx, zy, zz), CLHEP::Hep3Vector(dx, dy, dz));
0213 
0214     // now prepend alignment(s) for final transform
0215     const Tr3D atr(nullptr == at ? tr
0216                                  : (nullptr == gt ? at->transform() * tr : at->transform() * gt->transform() * tr));
0217     //--------------------------------- done making transform  ---------------
0218 
0219     const Pt3D gRef(atr * lRef);
0220     const GlobalPoint fCtr(gRef.x(), gRef.y(), gRef.z());
0221     const Pt3D gBck(atr * lBck);
0222     const GlobalPoint fBck(gBck.x(), gBck.y(), gBck.z());
0223     const Pt3D gCor(atr * lCor);
0224     const GlobalPoint fCor(gCor.x(), gCor.y(), gCor.z());
0225 
0226     assert(caloTopology.denseIndex(id) == dins[i]);
0227 
0228     ptr->newCell(fCtr, fBck, fCor, myParm, id);
0229   }
0230 
0231   ptr->initializeParms();  // initializations; must happen after cells filled
0232 
0233   return ptr;
0234 }
0235 
0236 template <>
0237 CaloGeometryDBEP<HGCalGeometry, CaloGeometryDBWriter>::PtrType
0238 CaloGeometryDBEP<HGCalGeometry, CaloGeometryDBWriter>::produceAligned(
0239     const typename HGCalGeometry::AlignedRecord& iRecord) {
0240   TrVec tvec;   // transformation
0241   DimVec dvec;  // parameters
0242   IVec ivec;    // layers
0243   IVec dins;    // valid geom ids
0244 
0245   const auto& geom = iRecord.get(geometryToken_);
0246 
0247   geom.getSummary(tvec, ivec, dvec, dins);
0248 
0249   CaloGeometryDBWriter::writeIndexed(tvec, dvec, ivec, dins, HGCalGeometry::dbString());
0250   //*********************************************************************************************
0251 
0252   const auto& topology = iRecord.get(additionalTokens_.topology);
0253 
0254   assert(dvec.size() <= topology.totalGeomModules() * HGCalGeometry::k_NumberOfParametersPerShape);
0255   HGCalGeometry* hcg = new HGCalGeometry(topology);
0256   PtrType ptr(hcg);
0257 
0258   ptr->allocateCorners(topology.ncells());
0259   ptr->allocatePar(HGCalGeometry::k_NumberOfShapes, HGCalGeometry::k_NumberOfParametersPerShape);
0260 
0261   const unsigned int nTrParm(ptr->numberOfTransformParms());
0262   const unsigned int nPerShape(HGCalGeometry::k_NumberOfParametersPerShape);
0263 
0264   for (auto it : dins) {
0265     DetId id = topology.encode(topology.geomDenseId2decId(it));
0266     // get layer
0267     int layer = ivec[it];
0268 
0269     // get transformation
0270     const unsigned int jj(it * nTrParm);
0271     Tr3D tr;
0272     const ROOT::Math::Translation3D tl(tvec[jj], tvec[jj + 1], tvec[jj + 2]);
0273     const ROOT::Math::EulerAngles ea(6 == nTrParm ? ROOT::Math::EulerAngles(tvec[jj + 3], tvec[jj + 4], tvec[jj + 5])
0274                                                   : ROOT::Math::EulerAngles());
0275     const ROOT::Math::Transform3D rt(ea, tl);
0276     double xx, xy, xz, dx, yx, yy, yz, dy, zx, zy, zz, dz;
0277     rt.GetComponents(xx, xy, xz, dx, yx, yy, yz, dy, zx, zy, zz, dz);
0278     tr = Tr3D(CLHEP::HepRep3x3(xx, xy, xz, yx, yy, yz, zx, zy, zz), CLHEP::Hep3Vector(dx, dy, dz));
0279 
0280     // get parameters
0281     DimVec dims;
0282     dims.reserve(nPerShape);
0283 
0284     DimVec::const_iterator dsrc(dvec.begin() + layer * nPerShape);
0285     for (unsigned int j(0); j != nPerShape; ++j) {
0286       dims.push_back(*dsrc);
0287       ++dsrc;
0288     }
0289 
0290     std::vector<GlobalPoint> corners(FlatHexagon::ncorner_);
0291 
0292     FlatHexagon::createCorners(dims, tr, corners);
0293 
0294     const CCGFloat* myParm(CaloCellGeometry::getParmPtr(dims, ptr->parMgr(), ptr->parVecVec()));
0295     GlobalPoint front(
0296         FlatHexagon::oneBySix_ *
0297             (corners[0].x() + corners[1].x() + corners[2].x() + corners[3].x() + corners[4].x() + corners[5].x()),
0298         FlatHexagon::oneBySix_ *
0299             (corners[0].y() + corners[1].y() + corners[2].y() + corners[3].y() + corners[4].y() + corners[5].y()),
0300         FlatHexagon::oneBySix_ *
0301             (corners[0].z() + corners[1].z() + corners[2].z() + corners[3].z() + corners[4].z() + corners[5].z()));
0302 
0303     GlobalPoint back(
0304         FlatHexagon::oneBySix_ *
0305             (corners[6].x() + corners[7].x() + corners[8].x() + corners[9].x() + corners[10].x() + corners[11].x()),
0306         FlatHexagon::oneBySix_ *
0307             (corners[6].y() + corners[7].y() + corners[8].y() + corners[9].y() + corners[10].y() + corners[11].y()),
0308         FlatHexagon::oneBySix_ *
0309             (corners[6].z() + corners[7].z() + corners[8].z() + corners[9].z() + corners[10].z() + corners[11].z()));
0310 
0311     if (front.mag2() > back.mag2()) {  // front should always point to the center, so swap front and back
0312       std::swap(front, back);
0313       std::swap_ranges(
0314           corners.begin(), corners.begin() + FlatHexagon::ncornerBy2_, corners.begin() + FlatHexagon::ncornerBy2_);
0315     }
0316 
0317     ptr->newCell(front, back, corners[0], myParm, id);
0318   }
0319 
0320   ptr->initializeParms();  // initializations; must happen after cells filled
0321 
0322   return ptr;
0323 }
0324 
0325 template class CaloGeometryDBEP<EcalBarrelGeometry, CaloGeometryDBWriter>;
0326 template class CaloGeometryDBEP<EcalEndcapGeometry, CaloGeometryDBWriter>;
0327 template class CaloGeometryDBEP<EcalPreshowerGeometry, CaloGeometryDBWriter>;
0328 
0329 template class CaloGeometryDBEP<HcalGeometry, CaloGeometryDBWriter>;
0330 template class CaloGeometryDBEP<CaloTowerGeometry, CaloGeometryDBWriter>;
0331 template class CaloGeometryDBEP<ZdcGeometry, CaloGeometryDBWriter>;
0332 template class CaloGeometryDBEP<CastorGeometry, CaloGeometryDBWriter>;
0333 
0334 typedef CaloGeometryDBEP<EcalBarrelGeometry, CaloGeometryDBWriter> EcalBarrelGeometryToDBEP;
0335 
0336 DEFINE_FWK_EVENTSETUP_MODULE(EcalBarrelGeometryToDBEP);
0337 
0338 typedef CaloGeometryDBEP<EcalEndcapGeometry, CaloGeometryDBWriter> EcalEndcapGeometryToDBEP;
0339 
0340 DEFINE_FWK_EVENTSETUP_MODULE(EcalEndcapGeometryToDBEP);
0341 
0342 typedef CaloGeometryDBEP<EcalPreshowerGeometry, CaloGeometryDBWriter> EcalPreshowerGeometryToDBEP;
0343 
0344 DEFINE_FWK_EVENTSETUP_MODULE(EcalPreshowerGeometryToDBEP);
0345 
0346 typedef CaloGeometryDBEP<HcalGeometry, CaloGeometryDBWriter> HcalGeometryToDBEP;
0347 
0348 DEFINE_FWK_EVENTSETUP_MODULE(HcalGeometryToDBEP);
0349 
0350 typedef CaloGeometryDBEP<CaloTowerGeometry, CaloGeometryDBWriter> CaloTowerGeometryToDBEP;
0351 
0352 DEFINE_FWK_EVENTSETUP_MODULE(CaloTowerGeometryToDBEP);
0353 
0354 typedef CaloGeometryDBEP<ZdcGeometry, CaloGeometryDBWriter> ZdcGeometryToDBEP;
0355 
0356 DEFINE_FWK_EVENTSETUP_MODULE(ZdcGeometryToDBEP);
0357 
0358 typedef CaloGeometryDBEP<CastorGeometry, CaloGeometryDBWriter> CastorGeometryToDBEP;
0359 
0360 DEFINE_FWK_EVENTSETUP_MODULE(CastorGeometryToDBEP);
0361 
0362 typedef CaloGeometryDBEP<HGCalGeometry, CaloGeometryDBWriter> HGCalGeometryToDBEP;
0363 
0364 DEFINE_FWK_EVENTSETUP_MODULE(HGCalGeometryToDBEP);