Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:48:36

0001 #include "Geometry/HGCalGeometry/interface/HGCalGeometry.h"
0002 #include "Geometry/HGCalGeometry/interface/CaloGeometryDBHGCal.h"
0003 #include "Geometry/CaloEventSetup/interface/CaloGeometryDBEP.h"
0004 #include "Geometry/CaloEventSetup/interface/CaloGeometryDBReader.h"
0005 
0006 template <>
0007 CaloGeometryDBEP<HGCalGeometry, CaloGeometryDBReader>::PtrType
0008 CaloGeometryDBEP<HGCalGeometry, CaloGeometryDBReader>::produceAligned(
0009     const typename HGCalGeometry::AlignedRecord& iRecord) {
0010   TrVec tvec;
0011   DimVec dvec;
0012   IVec ivec;
0013   IVec dins;
0014 
0015   std::cout << "Reading HGCalGeometry " << calogeometryDBEPimpl::nameHGCal << "\n";
0016   const auto& pG = iRecord.get(geometryToken_);
0017 
0018   tvec = pG.getTranslation();
0019   dvec = pG.getDimension();
0020   ivec = pG.getIndexes();
0021   dins = pG.getDenseIndices();
0022   //*********************************************************************************************
0023   const auto& topology = iRecord.get(additionalTokens_.topology);
0024 
0025   assert(dvec.size() <= topology.totalGeomModules() * HGCalGeometry::k_NumberOfParametersPerShape);
0026   HGCalGeometry* hcg = new HGCalGeometry(topology);
0027   PtrType ptr(hcg);
0028 
0029   ptr->allocateCorners(topology.ncells());
0030   ptr->allocatePar(HGCalGeometry::k_NumberOfShapes, HGCalGeometry::k_NumberOfParametersPerShape);
0031 
0032   const unsigned int nTrParm(ptr->numberOfTransformParms());
0033   const unsigned int nPerShape(HGCalGeometry::k_NumberOfParametersPerShape);
0034 
0035   for (auto it : dins) {
0036     DetId id = topology.encode(topology.geomDenseId2decId(it));
0037     // get layer
0038     int layer = ivec[it];
0039 
0040     // get transformation
0041     const unsigned int jj(it * nTrParm);
0042     Tr3D tr;
0043     const ROOT::Math::Translation3D tl(tvec[jj], tvec[jj + 1], tvec[jj + 2]);
0044     const ROOT::Math::EulerAngles ea(6 == nTrParm ? ROOT::Math::EulerAngles(tvec[jj + 3], tvec[jj + 4], tvec[jj + 5])
0045                                                   : ROOT::Math::EulerAngles());
0046     const ROOT::Math::Transform3D rt(ea, tl);
0047     double xx, xy, xz, dx, yx, yy, yz, dy, zx, zy, zz, dz;
0048     rt.GetComponents(xx, xy, xz, dx, yx, yy, yz, dy, zx, zy, zz, dz);
0049     tr = Tr3D(CLHEP::HepRep3x3(xx, xy, xz, yx, yy, yz, zx, zy, zz), CLHEP::Hep3Vector(dx, dy, dz));
0050 
0051     // get parameters
0052     DimVec dims;
0053     dims.reserve(nPerShape);
0054 
0055     DimVec::const_iterator dsrc(dvec.begin() + layer * nPerShape);
0056     for (unsigned int j(0); j != nPerShape; ++j) {
0057       dims.emplace_back(*dsrc);
0058       ++dsrc;
0059     }
0060 
0061     std::vector<GlobalPoint> corners(FlatHexagon::ncorner_);
0062 
0063     FlatHexagon::createCorners(dims, tr, corners);
0064 
0065     const CCGFloat* myParm(CaloCellGeometry::getParmPtr(dims, ptr->parMgr(), ptr->parVecVec()));
0066     GlobalPoint front(
0067         FlatHexagon::oneBySix_ *
0068             (corners[0].x() + corners[1].x() + corners[2].x() + corners[3].x() + corners[4].x() + corners[5].x()),
0069         FlatHexagon::oneBySix_ *
0070             (corners[0].y() + corners[1].y() + corners[2].y() + corners[3].y() + corners[4].y() + corners[5].y()),
0071         FlatHexagon::oneBySix_ *
0072             (corners[0].z() + corners[1].z() + corners[2].z() + corners[3].z() + corners[4].z() + corners[5].z()));
0073 
0074     GlobalPoint back(
0075         FlatHexagon::oneBySix_ *
0076             (corners[6].x() + corners[7].x() + corners[8].x() + corners[9].x() + corners[10].x() + corners[11].x()),
0077         FlatHexagon::oneBySix_ *
0078             (corners[6].y() + corners[7].y() + corners[8].y() + corners[9].y() + corners[10].y() + corners[11].y()),
0079         FlatHexagon::oneBySix_ *
0080             (corners[6].z() + corners[7].z() + corners[8].z() + corners[9].z() + corners[10].z() + corners[11].z()));
0081 
0082     if (front.mag2() > back.mag2()) {  // front should always point to the center, so swap front and back
0083       std::swap(front, back);
0084       std::swap_ranges(
0085           corners.begin(), corners.begin() + FlatHexagon::ncornerBy2_, corners.begin() + FlatHexagon::ncornerBy2_);
0086     }
0087 
0088     ptr->newCell(front, back, corners[0], myParm, id);
0089   }
0090 
0091   ptr->initializeParms();  // initializations; must happen after cells filled
0092 
0093   return ptr;
0094 }
0095 
0096 template class CaloGeometryDBEP<HGCalGeometry, CaloGeometryDBReader>;
0097 
0098 typedef CaloGeometryDBEP<HGCalGeometry, CaloGeometryDBReader> HGCalGeometryFromDBEP;
0099 
0100 DEFINE_FWK_EVENTSETUP_MODULE(HGCalGeometryFromDBEP);