Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:08:12

0001 #include "Geometry/HcalTowerAlgo/interface/HcalGeometry.h"
0002 #include "Geometry/HcalTowerAlgo/interface/CaloTowerGeometry.h"
0003 #include "Geometry/HcalTowerAlgo/interface/CaloGeometryDBHcal.h"
0004 #include "Geometry/HcalTowerAlgo/interface/CaloGeometryDBCaloTower.h"
0005 
0006 #include "Geometry/CaloEventSetup/interface/CaloGeometryDBEP.h"
0007 #include "Geometry/CaloEventSetup/interface/CaloGeometryDBReader.h"
0008 #include "Geometry/Records/interface/HcalRecNumberingRecord.h"
0009 
0010 template <>
0011 CaloGeometryDBEP<HcalGeometry, CaloGeometryDBReader>::PtrType
0012 CaloGeometryDBEP<HcalGeometry, CaloGeometryDBReader>::produceAligned(
0013     const typename HcalGeometry::AlignedRecord& iRecord) {
0014   const auto [alignPtr, globalPtr] = getAlignGlobal(iRecord);
0015 
0016   TrVec tvec;
0017   DimVec dvec;
0018   IVec ivec;
0019   IVec dins;
0020 
0021   const auto& pG = iRecord.get(geometryToken_);
0022 
0023   tvec = pG.getTranslation();
0024   dvec = pG.getDimension();
0025   ivec = pG.getIndexes();
0026   dins = pG.getDenseIndices();
0027   //*********************************************************************************************
0028 
0029   const auto& hcalTopology = iRecord.get(additionalTokens_.topology);
0030 
0031   // We know that the numer of shapes chanes with changing depth
0032   // so, this check is temporary disabled. We need to implement
0033   // a way either to store or calculate the number of shapes or be able
0034   // to deal with only max numer of shapes.
0035   // assert( dvec.size() == hcalTopology.getNumberOfShapes() * HcalGeometry::k_NumberOfParametersPerShape ) ;
0036   assert(dvec.size() <= hcalTopology.getNumberOfShapes() * HcalGeometry::k_NumberOfParametersPerShape);
0037   HcalGeometry* hcg = new HcalGeometry(hcalTopology);
0038 
0039   PtrType ptr(hcg);
0040 
0041   const unsigned int nTrParm(hcg->numberOfTransformParms());
0042 
0043   ptr->fillDefaultNamedParameters();
0044   ptr->allocateCorners(hcalTopology.ncells() + hcalTopology.getHFSize());
0045   ptr->allocatePar(dvec.size(), HcalGeometry::k_NumberOfParametersPerShape);
0046 
0047   for (unsigned int i(0); i < dins.size(); ++i) {
0048     const unsigned int nPerShape(HcalGeometry::k_NumberOfParametersPerShape);
0049     DimVec dims;
0050     dims.reserve(nPerShape);
0051 
0052     const unsigned int indx(ivec.size() == 1 ? 0 : i);
0053 
0054     DimVec::const_iterator dsrc(dvec.begin() + ivec[indx] * nPerShape);
0055 
0056     for (unsigned int j(0); j != nPerShape; ++j) {
0057       dims.emplace_back(*dsrc);
0058       ++dsrc;
0059     }
0060 
0061     const CCGFloat* myParm(CaloCellGeometry::getParmPtr(dims, ptr->parMgr(), ptr->parVecVec()));
0062 
0063     const DetId id(hcalTopology.denseId2detId(dins[i]));
0064 
0065     const unsigned int iGlob(nullptr == globalPtr ? 0 : HcalGeometry::alignmentTransformIndexGlobal(id));
0066 
0067     assert(nullptr == globalPtr || iGlob < globalPtr->m_align.size());
0068 
0069     const AlignTransform* gt(nullptr == globalPtr ? nullptr : &globalPtr->m_align[iGlob]);
0070 
0071     assert(nullptr == gt || iGlob == HcalGeometry::alignmentTransformIndexGlobal(DetId(gt->rawId())));
0072 
0073     const unsigned int iLoc(nullptr == alignPtr ? 0 : HcalGeometry::alignmentTransformIndexLocal(id));
0074 
0075     assert(nullptr == alignPtr || iLoc < alignPtr->m_align.size());
0076 
0077     const AlignTransform* at(nullptr == alignPtr ? nullptr : &alignPtr->m_align[iLoc]);
0078 
0079     assert(nullptr == at || (HcalGeometry::alignmentTransformIndexLocal(DetId(at->rawId())) == iLoc));
0080 
0081     Pt3D lRef;
0082     Pt3DVec lc(8, Pt3D(0, 0, 0));
0083     hcg->localCorners(lc, &dims.front(), dins[i], lRef);
0084 
0085     const Pt3D lBck(0.25 * (lc[4] + lc[5] + lc[6] + lc[7]));  // ctr rear  face in local
0086     const Pt3D lCor(lc[0]);
0087 
0088     //----------------------------------- create transform from 6 numbers ---
0089     const unsigned int jj(i * nTrParm);  // Note: Dence indices are not sorted and
0090                                          // parameters stored according to order of a cell creation
0091     Tr3D tr;
0092     const ROOT::Math::Translation3D tl(tvec[jj], tvec[jj + 1], tvec[jj + 2]);
0093     const ROOT::Math::EulerAngles ea(6 == nTrParm ? ROOT::Math::EulerAngles(tvec[jj + 3], tvec[jj + 4], tvec[jj + 5])
0094                                                   : ROOT::Math::EulerAngles());
0095     const ROOT::Math::Transform3D rt(ea, tl);
0096     double xx, xy, xz, dx;
0097     double yx, yy, yz, dy;
0098     double zx, zy, zz, dz;
0099     rt.GetComponents(xx, xy, xz, dx, yx, yy, yz, dy, zx, zy, zz, dz);
0100     tr = Tr3D(CLHEP::HepRep3x3(xx, xy, xz, yx, yy, yz, zx, zy, zz), CLHEP::Hep3Vector(dx, dy, dz));
0101 
0102     // now prepend alignment(s) for final transform
0103     const Tr3D atr(nullptr == at ? tr
0104                                  : (nullptr == gt ? at->transform() * tr : at->transform() * gt->transform() * tr));
0105     //--------------------------------- done making transform  ---------------
0106 
0107     const Pt3D gRef(atr * lRef);
0108     const GlobalPoint fCtr(gRef.x(), gRef.y(), gRef.z());
0109     const Pt3D gBck(atr * lBck);
0110     const GlobalPoint fBck(gBck.x(), gBck.y(), gBck.z());
0111     const Pt3D gCor(atr * lCor);
0112     const GlobalPoint fCor(gCor.x(), gCor.y(), gCor.z());
0113 
0114     assert(hcalTopology.detId2denseId(id) == dins[i]);
0115 
0116     ptr->newCell(fCtr, fBck, fCor, myParm, id);
0117   }
0118 
0119   ptr->initializeParms();  // initializations; must happen after cells filled
0120 
0121   return ptr;
0122 }
0123 
0124 template <>
0125 CaloGeometryDBEP<CaloTowerGeometry, CaloGeometryDBReader>::PtrType
0126 CaloGeometryDBEP<CaloTowerGeometry, CaloGeometryDBReader>::produceAligned(
0127     const typename CaloTowerGeometry::AlignedRecord& iRecord) {
0128   const auto [alignPtr, globalPtr] = getAlignGlobal(iRecord);
0129 
0130   TrVec tvec;
0131   DimVec dvec;
0132   IVec ivec;
0133   IVec dins;
0134 
0135   const auto& pG = iRecord.get(geometryToken_);
0136 
0137   tvec = pG.getTranslation();
0138   dvec = pG.getDimension();
0139   ivec = pG.getIndexes();
0140   dins = pG.getDenseIndices();
0141   //*********************************************************************************************
0142 
0143   const auto& caloTopology = iRecord.get(additionalTokens_.topology);
0144 
0145   CaloTowerGeometry* ctg = new CaloTowerGeometry(&caloTopology);
0146 
0147   const unsigned int nTrParm(tvec.size() / ctg->numberOfCellsForCorners());
0148 
0149   assert(dvec.size() == ctg->numberOfShapes() * CaloTowerGeometry::k_NumberOfParametersPerShape);
0150 
0151   PtrType ptr(ctg);
0152 
0153   ptr->fillDefaultNamedParameters();
0154 
0155   ptr->allocateCorners(ctg->numberOfCellsForCorners());
0156 
0157   ptr->allocatePar(dvec.size(), CaloTowerGeometry::k_NumberOfParametersPerShape);
0158 
0159   for (unsigned int i(0); i < dins.size(); ++i) {
0160     const unsigned int nPerShape(ctg->numberOfParametersPerShape());
0161     DimVec dims;
0162     dims.reserve(nPerShape);
0163 
0164     const unsigned int indx(ivec.size() == 1 ? 0 : i);
0165 
0166     DimVec::const_iterator dsrc(dvec.begin() + ivec[indx] * nPerShape);
0167 
0168     for (unsigned int j(0); j != nPerShape; ++j) {
0169       dims.emplace_back(*dsrc);
0170       ++dsrc;
0171     }
0172 
0173     const CCGFloat* myParm(CaloCellGeometry::getParmPtr(dims, ptr->parMgr(), ptr->parVecVec()));
0174 
0175     const DetId id(caloTopology.detIdFromDenseIndex(dins[i]));
0176 
0177     const unsigned int iGlob(nullptr == globalPtr ? 0 : ctg->alignmentTransformIndexGlobal(id));
0178 
0179     assert(nullptr == globalPtr || iGlob < globalPtr->m_align.size());
0180 
0181     const AlignTransform* gt(nullptr == globalPtr ? nullptr : &globalPtr->m_align[iGlob]);
0182 
0183     assert(nullptr == gt || iGlob == ctg->alignmentTransformIndexGlobal(DetId(gt->rawId())));
0184 
0185     const unsigned int iLoc(nullptr == alignPtr ? 0 : ctg->alignmentTransformIndexLocal(id));
0186 
0187     assert(nullptr == alignPtr || iLoc < alignPtr->m_align.size());
0188 
0189     const AlignTransform* at(nullptr == alignPtr ? nullptr : &alignPtr->m_align[iLoc]);
0190 
0191     assert(nullptr == at || (ctg->alignmentTransformIndexLocal(DetId(at->rawId())) == iLoc));
0192 
0193     const CaloGenericDetId gId(id);
0194 
0195     Pt3D lRef;
0196     Pt3DVec lc(8, Pt3D(0, 0, 0));
0197     ctg->localCorners(lc, &dims.front(), dins[i], lRef);
0198 
0199     const Pt3D lBck(0.25 * (lc[4] + lc[5] + lc[6] + lc[7]));  // ctr rear  face in local
0200     const Pt3D lCor(lc[0]);
0201 
0202     //----------------------------------- create transform from 6 numbers ---
0203     const unsigned int jj(i * nTrParm);
0204     Tr3D tr;
0205     const ROOT::Math::Translation3D tl(tvec[jj], tvec[jj + 1], tvec[jj + 2]);
0206     const ROOT::Math::EulerAngles ea(6 == nTrParm ? ROOT::Math::EulerAngles(tvec[jj + 3], tvec[jj + 4], tvec[jj + 5])
0207                                                   : ROOT::Math::EulerAngles());
0208     const ROOT::Math::Transform3D rt(ea, tl);
0209     double xx, xy, xz, dx, yx, yy, yz, dy, zx, zy, zz, dz;
0210     rt.GetComponents(xx, xy, xz, dx, yx, yy, yz, dy, zx, zy, zz, dz);
0211     tr = Tr3D(CLHEP::HepRep3x3(xx, xy, xz, yx, yy, yz, zx, zy, zz), CLHEP::Hep3Vector(dx, dy, dz));
0212 
0213     // now prepend alignment(s) for final transform
0214     const Tr3D atr(nullptr == at ? tr
0215                                  : (nullptr == gt ? at->transform() * tr : at->transform() * gt->transform() * tr));
0216     //--------------------------------- done making transform  ---------------
0217 
0218     const Pt3D gRef(atr * lRef);
0219     const GlobalPoint fCtr(gRef.x(), gRef.y(), gRef.z());
0220     const Pt3D gBck(atr * lBck);
0221     const GlobalPoint fBck(gBck.x(), gBck.y(), gBck.z());
0222     const Pt3D gCor(atr * lCor);
0223     const GlobalPoint fCor(gCor.x(), gCor.y(), gCor.z());
0224 
0225     assert(caloTopology.denseIndex(id) == dins[i]);
0226 
0227     ptr->newCell(fCtr, fBck, fCor, myParm, id);
0228   }
0229 
0230   ptr->initializeParms();  // initializations; must happen after cells filled
0231 
0232   return ptr;
0233 }
0234 
0235 template class CaloGeometryDBEP<HcalGeometry, CaloGeometryDBReader>;
0236 
0237 typedef CaloGeometryDBEP<HcalGeometry, CaloGeometryDBReader> HcalGeometryFromDBEP;
0238 
0239 DEFINE_FWK_EVENTSETUP_MODULE(HcalGeometryFromDBEP);
0240 
0241 template class CaloGeometryDBEP<CaloTowerGeometry, CaloGeometryDBReader>;
0242 
0243 typedef CaloGeometryDBEP<CaloTowerGeometry, CaloGeometryDBReader> CaloTowerGeometryFromDBEP;
0244 
0245 DEFINE_FWK_EVENTSETUP_MODULE(CaloTowerGeometryFromDBEP);