Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:14:51

0001 #include "Geometry/CaloGeometry/interface/CaloGenericDetId.h"
0002 #include "Geometry/HcalTowerAlgo/interface/CaloTowerGeometry.h"
0003 
0004 #include <Math/Transform3D.h>
0005 #include <Math/EulerAngles.h>
0006 
0007 typedef CaloCellGeometry::CCGFloat CCGFloat;
0008 typedef CaloCellGeometry::Pt3D Pt3D;
0009 typedef CaloCellGeometry::Pt3DVec Pt3DVec;
0010 typedef CaloCellGeometry::Tr3D Tr3D;
0011 
0012 CaloTowerGeometry::CaloTowerGeometry(const CaloTowerTopology* cttopo)
0013     : m_cttopo(cttopo),
0014       k_NumberOfCellsForCorners(m_cttopo->sizeForDenseIndexing()),
0015       k_NumberOfShapes(m_cttopo->lastHFRing()),
0016       m_cellVec(k_NumberOfCellsForCorners) {}
0017 
0018 CaloTowerGeometry::~CaloTowerGeometry() {}
0019 
0020 unsigned int CaloTowerGeometry::alignmentTransformIndexLocal(const DetId& id) {
0021   const CaloGenericDetId gid(id);
0022   assert(gid.isCaloTower());
0023 
0024   const CaloTowerDetId cid(id);
0025   const int iea(cid.ietaAbs());
0026   const unsigned int ip((cid.iphi() - 1) / 4);
0027   const int izoff((cid.zside() + 1) / 2);
0028   const unsigned int offset(izoff * 3 * 18);
0029 
0030   return (offset + ip +
0031           (m_cttopo->firstHFQuadPhiRing() <= iea ? 36 : (m_cttopo->firstHEDoublePhiRing() <= iea ? 18 : 0)));
0032 }
0033 
0034 unsigned int CaloTowerGeometry::alignmentTransformIndexGlobal(const DetId& id) { return (unsigned int)DetId::Calo - 1; }
0035 
0036 void CaloTowerGeometry::localCorners(Pt3DVec& lc, const CCGFloat* pv, unsigned int i, Pt3D& ref) {
0037   IdealObliquePrism::localCorners(lc, pv, ref);
0038 }
0039 
0040 void CaloTowerGeometry::newCell(
0041     const GlobalPoint& f1, const GlobalPoint& f2, const GlobalPoint& f3, const CCGFloat* parm, const DetId& detId) {
0042   const CaloGenericDetId cgid(detId);
0043 
0044   assert(cgid.isCaloTower());
0045 
0046   const CaloTowerDetId cid(detId);
0047 
0048   const unsigned int di(m_cttopo->denseIndex(cid));
0049 
0050   m_cellVec[di] = IdealObliquePrism(f1, cornersMgr(), parm);
0051   addValidID(detId);
0052   m_dins.emplace_back(di);
0053 }
0054 
0055 const CaloCellGeometry* CaloTowerGeometry::getGeometryRawPtr(uint32_t index) const {
0056   // Modify the RawPtr class
0057   const CaloCellGeometry* cell(&m_cellVec[index]);
0058   return (m_cellVec.size() < index || nullptr == cell->param() ? nullptr : cell);
0059 }
0060 
0061 void CaloTowerGeometry::getSummary(CaloSubdetectorGeometry::TrVec& tVec,
0062                                    CaloSubdetectorGeometry::IVec& iVec,
0063                                    CaloSubdetectorGeometry::DimVec& dVec,
0064                                    CaloSubdetectorGeometry::IVec& dinsVec) const {
0065   tVec.reserve(numberOfCellsForCorners() * numberOfTransformParms());
0066   iVec.reserve(numberOfShapes() == 1 ? 1 : numberOfCellsForCorners());
0067   dVec.reserve(numberOfShapes() * numberOfParametersPerShape());
0068   dinsVec.reserve(numberOfCellsForCorners());
0069 
0070   for (const auto& pv : parVecVec()) {
0071     for (float iv : pv) {
0072       dVec.emplace_back(iv);
0073     }
0074   }
0075 
0076   for (unsigned int i(0); i < numberOfCellsForCorners(); ++i) {
0077     Tr3D tr;
0078     auto ptr(cellGeomPtr(i));
0079 
0080     if (nullptr != ptr) {
0081       dinsVec.emplace_back(i);
0082 
0083       ptr->getTransform(tr, (Pt3DVec*)nullptr);
0084 
0085       if (Tr3D() == tr) {  // for preshower there is no rotation
0086         const GlobalPoint& gp(ptr->getPosition());
0087         tr = HepGeom::Translate3D(gp.x(), gp.y(), gp.z());
0088       }
0089 
0090       const CLHEP::Hep3Vector tt(tr.getTranslation());
0091       tVec.emplace_back(tt.x());
0092       tVec.emplace_back(tt.y());
0093       tVec.emplace_back(tt.z());
0094       if (6 == numberOfTransformParms()) {
0095         const CLHEP::HepRotation rr(tr.getRotation());
0096         const ROOT::Math::Transform3D rtr(
0097             rr.xx(), rr.xy(), rr.xz(), tt.x(), rr.yx(), rr.yy(), rr.yz(), tt.y(), rr.zx(), rr.zy(), rr.zz(), tt.z());
0098         ROOT::Math::EulerAngles ea;
0099         rtr.GetRotation(ea);
0100         tVec.emplace_back(ea.Phi());
0101         tVec.emplace_back(ea.Theta());
0102         tVec.emplace_back(ea.Psi());
0103       }
0104 
0105       const CCGFloat* par(ptr->param());
0106 
0107       unsigned int ishape(9999);
0108       for (unsigned int ivv(0); ivv != parVecVec().size(); ++ivv) {
0109         bool ok(true);
0110         const CCGFloat* pv(&(*parVecVec()[ivv].begin()));
0111         for (unsigned int k(0); k != numberOfParametersPerShape(); ++k) {
0112           ok = ok && (fabs(par[k] - pv[k]) < 1.e-6);
0113         }
0114         if (ok) {
0115           ishape = ivv;
0116           break;
0117         }
0118       }
0119       assert(9999 != ishape);
0120 
0121       const unsigned int nn((numberOfShapes() == 1) ? (unsigned int)1 : m_dins.size());
0122       if (iVec.size() < nn)
0123         iVec.emplace_back(ishape);
0124     }
0125   }
0126 }