Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-11-16 03:43:44

0001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0002 #include "Geometry/CaloGeometry/interface/CaloGenericDetId.h"
0003 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
0004 #include "Geometry/ForwardGeometry/interface/ZdcGeometry.h"
0005 #include "Geometry/ForwardGeometry/interface/IdealZDCTrapezoid.h"
0006 #include "Geometry/ForwardGeometry/interface/ZdcHardcodeGeometryData.h"
0007 #include <algorithm>
0008 
0009 #include <Math/Transform3D.h>
0010 #include <Math/EulerAngles.h>
0011 
0012 #include <algorithm>
0013 
0014 typedef CaloCellGeometry::Pt3D Pt3D;
0015 typedef CaloCellGeometry::Pt3DVec Pt3DVec;
0016 typedef CaloCellGeometry::Tr3D Tr3D;
0017 
0018 typedef CaloSubdetectorGeometry::CCGFloat CCGFloat;
0019 
0020 //#define EDM_ML_DEBUG
0021 
0022 ZdcGeometry::ZdcGeometry()
0023     : theTopology(new ZdcTopology),
0024       lastReqDet_(DetId::Detector(0)),
0025       lastReqSubdet_(0),
0026       m_ownsTopology(true),
0027       m_cellVec(k_NumberOfCellsForCorners) {}
0028 
0029 ZdcGeometry::ZdcGeometry(const ZdcTopology* topology)
0030     : theTopology(topology),
0031       lastReqDet_(DetId::Detector(0)),
0032       lastReqSubdet_(0),
0033       m_ownsTopology(false),
0034       m_cellVec(k_NumberOfCellsForCorners) {}
0035 
0036 ZdcGeometry::~ZdcGeometry() {
0037   if (m_ownsTopology)
0038     delete theTopology;
0039 }
0040 /*
0041 DetId ZdcGeometry::getClosestCell(const GlobalPoint& r) const
0042 {
0043    DetId returnId ( 0 ) ;
0044    const std::vector<DetId>& detIds ( getValidDetIds() ) ;
0045    for( std::vector<DetId>::const_iterator it ( detIds.begin() ) ;
0046     it != detIds.end(); ++it )
0047    {
0048       auto cell = ( getGeometry( *it ) ) ;
0049       if( 0 != cell &&
0050       cell->inside( r ) )
0051       {
0052      returnId = *it ;
0053      break ;
0054       }
0055    }
0056    return returnId ;
0057 }
0058 */
0059 unsigned int ZdcGeometry::alignmentTransformIndexLocal(const DetId& id) {
0060   const CaloGenericDetId gid(id);
0061   assert(gid.isZDC());
0062 
0063   return (0 > HcalZDCDetId(id).zside() ? 0 : 1);
0064 }
0065 
0066 unsigned int ZdcGeometry::alignmentTransformIndexGlobal(const DetId& /*id*/) { return (unsigned int)DetId::Calo - 1; }
0067 
0068 void ZdcGeometry::localCorners(Pt3DVec& lc, const CCGFloat* pv, unsigned int /*i*/, Pt3D& ref) {
0069   IdealZDCTrapezoid::localCorners(lc, pv, ref);
0070 }
0071 
0072 void ZdcGeometry::newCell(const GlobalPoint& f1,
0073                           const GlobalPoint& /*f2*/,
0074                           const GlobalPoint& /*f3*/,
0075                           const CCGFloat* parm,
0076                           const DetId& detId) {
0077   const CaloGenericDetId cgid(detId);
0078 #ifdef EDM_ML_DEBUG
0079   edm::LogVerbatim("ZDCGeom") << "ZDCGeometry " << HcalZDCDetId(detId) << " Generic ID " << std::hex << cgid.rawId()
0080                               << std::dec << " ZDC? " << cgid.isZDC();
0081 #endif
0082   assert(cgid.isZDC());
0083 
0084   const unsigned int di(cgid.denseIndex());
0085 
0086   m_cellVec[di] = IdealZDCTrapezoid(f1, cornersMgr(), parm);
0087   addValidID(detId);
0088 }
0089 
0090 const CaloCellGeometry* ZdcGeometry::getGeometryRawPtr(uint32_t index) const {
0091   // Modify the RawPtr class
0092   if (m_cellVec.size() < index)
0093     return nullptr;
0094   const CaloCellGeometry* cell(&m_cellVec[index]);
0095   return (((cell == nullptr) || (nullptr == cell->param())) ? nullptr : cell);
0096 }
0097 
0098 void ZdcGeometry::getSummary(CaloSubdetectorGeometry::TrVec& tVec,
0099                              CaloSubdetectorGeometry::IVec& iVec,
0100                              CaloSubdetectorGeometry::DimVec& dVec,
0101                              CaloSubdetectorGeometry::IVec& /*dins*/) const {
0102   tVec.reserve(m_validIds.size() * numberOfTransformParms());
0103   iVec.reserve(numberOfShapes() == 1 ? 1 : m_validIds.size());
0104   dVec.reserve(numberOfShapes() * numberOfParametersPerShape());
0105 
0106   for (const auto& pv : parVecVec()) {
0107     for (float iv : pv) {
0108       dVec.emplace_back(iv);
0109     }
0110   }
0111 
0112   for (uint32_t i(0); i != m_validIds.size(); ++i) {
0113     Tr3D tr;
0114     std::shared_ptr<const CaloCellGeometry> ptr(cellGeomPtr(i));
0115 #ifdef EDM_ML_DEBUG
0116     edm::LogVerbatim("ZDCGeom") << "ZDCGeometry:Summary " << i << ":" << HcalZDCDetId::kSizeForDenseIndexingRun1
0117                                 << " Pointer " << ptr << ":" << (nullptr != ptr);
0118 #endif
0119     if (i < static_cast<int32_t>(HcalZDCDetId::kSizeForDenseIndexingRun1))
0120       assert(nullptr != ptr);
0121     if (ptr != nullptr) {
0122       ptr->getTransform(tr, (Pt3DVec*)nullptr);
0123 
0124       if (Tr3D() == tr) {  // for preshower there is no rotation
0125         const GlobalPoint& gp(ptr->getPosition());
0126         tr = HepGeom::Translate3D(gp.x(), gp.y(), gp.z());
0127       }
0128 
0129       const CLHEP::Hep3Vector tt(tr.getTranslation());
0130       tVec.emplace_back(tt.x());
0131       tVec.emplace_back(tt.y());
0132       tVec.emplace_back(tt.z());
0133       if (6 == numberOfTransformParms()) {
0134         const CLHEP::HepRotation rr(tr.getRotation());
0135         const ROOT::Math::Transform3D rtr(
0136             rr.xx(), rr.xy(), rr.xz(), tt.x(), rr.yx(), rr.yy(), rr.yz(), tt.y(), rr.zx(), rr.zy(), rr.zz(), tt.z());
0137         ROOT::Math::EulerAngles ea;
0138         rtr.GetRotation(ea);
0139         tVec.emplace_back(ea.Phi());
0140         tVec.emplace_back(ea.Theta());
0141         tVec.emplace_back(ea.Psi());
0142       }
0143 
0144       const CCGFloat* par(ptr->param());
0145 
0146       unsigned int ishape(9999);
0147       for (unsigned int ivv(0); ivv != parVecVec().size(); ++ivv) {
0148         bool ok(true);
0149         const CCGFloat* pv(&(*parVecVec()[ivv].begin()));
0150         for (unsigned int k(0); k != numberOfParametersPerShape(); ++k) {
0151           ok = ok && (fabs(par[k] - pv[k]) < 1.e-6);
0152         }
0153         if (ok) {
0154           ishape = ivv;
0155           break;
0156         }
0157       }
0158       assert(9999 != ishape);
0159 
0160       const unsigned int nn((numberOfShapes() == 1) ? (unsigned int)1 : m_validIds.size());
0161       if (iVec.size() < nn)
0162         iVec.emplace_back(ishape);
0163     }
0164   }
0165 }