Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef HcalGeometry_h
0002 #define HcalGeometry_h
0003 
0004 #include "DataFormats/Common/interface/AtomicPtrCache.h"
0005 
0006 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
0007 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
0008 #include "Geometry/CaloGeometry/interface/IdealObliquePrism.h"
0009 #include "Geometry/CaloGeometry/interface/IdealZPrism.h"
0010 #include "Geometry/CaloTopology/interface/HcalTopology.h"
0011 #include "CondFormats/AlignmentRecord/interface/HcalAlignmentRcd.h"
0012 #include "Geometry/Records/interface/HcalGeometryRecord.h"
0013 
0014 class HcalFlexiHardcodeGeometryLoader;
0015 class HcalHardcodeGeometryLoader;
0016 
0017 class HcalGeometry : public CaloSubdetectorGeometry {
0018   friend class HcalGeometryPlan1Tester;
0019 
0020 public:
0021   friend class HcalFlexiHardcodeGeometryLoader;
0022   friend class HcalHardcodeGeometryLoader;
0023 
0024   typedef std::vector<IdealObliquePrism> HBCellVec;
0025   typedef std::vector<IdealObliquePrism> HECellVec;
0026   typedef std::vector<IdealObliquePrism> HOCellVec;
0027   typedef std::vector<IdealZPrism> HFCellVec;
0028 
0029   typedef CaloCellGeometry::CCGFloat CCGFloat;
0030   typedef CaloCellGeometry::Pt3D Pt3D;
0031   typedef CaloCellGeometry::Pt3DVec Pt3DVec;
0032 
0033   typedef HcalAlignmentRcd AlignmentRecord;
0034   typedef HcalGeometryRecord AlignedRecord;
0035   typedef PHcalRcd PGeometryRecord;
0036   typedef HcalDetId DetIdType;
0037 
0038   enum { k_NumberOfParametersPerShape = 5 };
0039 
0040   static std::string dbString() { return "PHcalRcd"; }
0041 
0042   unsigned int numberOfShapes() const override { return m_topology.getNumberOfShapes(); }
0043   unsigned int numberOfParametersPerShape() const override { return k_NumberOfParametersPerShape; }
0044 
0045   explicit HcalGeometry(const HcalTopology& topology);
0046 
0047   /// The HcalGeometry will delete all its cell geometries at destruction time
0048   ~HcalGeometry() override;
0049 
0050   const std::vector<DetId>& getValidDetIds(DetId::Detector det = DetId::Detector(0), int subdet = 0) const override;
0051 
0052   std::shared_ptr<const CaloCellGeometry> getGeometry(const DetId& id) const override;
0053 
0054   DetId getClosestCell(const GlobalPoint& r) const override;
0055   DetId getClosestCell(const GlobalPoint& r, bool ignoreCorrect) const;
0056 
0057   CaloSubdetectorGeometry::DetIdSet getCells(const GlobalPoint& r, double dR) const override;
0058 
0059   GlobalPoint getPosition(const DetId& id) const;
0060   GlobalPoint getPosition(uint32_t id, bool type) const;
0061   GlobalPoint getBackPosition(const DetId& id) const;
0062   GlobalPoint getBackPosition(uint32_t id, bool type) const;
0063   CaloCellGeometry::CornersVec getCorners(const DetId& id) const;
0064 
0065   static std::string producerTag() { return "HCAL"; }
0066 
0067   static unsigned int numberOfBarrelAlignments() { return 36; }
0068 
0069   static unsigned int numberOfEndcapAlignments() { return 36; }
0070 
0071   static unsigned int numberOfForwardAlignments() { return 36; }
0072 
0073   static unsigned int numberOfOuterAlignments() { return 60; }
0074 
0075   unsigned int getHxSize(const int type) const;
0076 
0077   static unsigned int numberOfAlignments() {
0078     return (numberOfBarrelAlignments() + numberOfEndcapAlignments() + numberOfOuterAlignments() +
0079             numberOfForwardAlignments());
0080   }
0081 
0082   static unsigned int alignmentBarrelIndexLocal(const DetId& id);
0083   static unsigned int alignmentEndcapIndexLocal(const DetId& id);
0084   static unsigned int alignmentForwardIndexLocal(const DetId& id);
0085   static unsigned int alignmentOuterIndexLocal(const DetId& id);
0086   static unsigned int alignmentTransformIndexLocal(const DetId& id);
0087 
0088   static unsigned int alignmentBarEndForIndexLocal(const DetId& id, unsigned int nD);
0089 
0090   static unsigned int alignmentTransformIndexGlobal(const DetId& id);
0091 
0092   static DetId detIdFromLocalAlignmentIndex(unsigned int i);
0093   static DetId detIdFromBarrelAlignmentIndex(unsigned int i);
0094   static DetId detIdFromEndcapAlignmentIndex(unsigned int i);
0095   static DetId detIdFromForwardAlignmentIndex(unsigned int i);
0096   static DetId detIdFromOuterAlignmentIndex(unsigned int i);
0097 
0098   void localCorners(Pt3DVec& lc, const CCGFloat* pv, unsigned int i, Pt3D& ref);
0099 
0100   void newCell(const GlobalPoint& f1,
0101                const GlobalPoint& f2,
0102                const GlobalPoint& f3,
0103                const CCGFloat* parm,
0104                const DetId& detId) override;
0105 
0106   void getSummary(CaloSubdetectorGeometry::TrVec& trVector,
0107                   CaloSubdetectorGeometry::IVec& iVector,
0108                   CaloSubdetectorGeometry::DimVec& dimVector,
0109                   CaloSubdetectorGeometry::IVec& dinsVector) const override;
0110 
0111   const HcalTopology& topology() const { return m_topology; }
0112 
0113 protected:
0114   unsigned int indexFor(const DetId& id) const override { return m_topology.detId2denseId(id); }
0115   unsigned int sizeForDenseIndex(const DetId& id) const override { return m_topology.ncells(); }
0116 
0117   // Modify the RawPtr class
0118   const CaloCellGeometry* getGeometryRawPtr(uint32_t index) const override;
0119 
0120 private:
0121   // Base clas for getting geometry
0122   std::shared_ptr<const CaloCellGeometry> getGeometryBase(const DetId& id) const {
0123     return cellGeomPtr(m_topology.detId2denseId(id));
0124   }
0125 
0126   //returns din
0127   unsigned int newCellImpl(
0128       const GlobalPoint& f1, const GlobalPoint& f2, const GlobalPoint& f3, const CCGFloat* parm, const DetId& detId);
0129 
0130   //can only be used by friend classes, to ensure sorting is done at the end
0131   void newCellFast(
0132       const GlobalPoint& f1, const GlobalPoint& f2, const GlobalPoint& f3, const CCGFloat* parm, const DetId& detId);
0133 
0134   void increaseReserve(unsigned int extra);
0135   void sortValidIds();
0136 
0137   void fillDetIds() const;
0138 
0139   void init();
0140 
0141   /// helper methods for getClosestCell
0142   int etaRing(HcalSubdetector bc, double abseta) const;
0143   int phiBin(HcalSubdetector bc, int etaring, double phi) const;
0144   DetId correctId(const DetId& id) const;
0145 
0146   const HcalTopology& m_topology;
0147   bool m_mergePosition;
0148 
0149   mutable edm::AtomicPtrCache<std::vector<DetId>> m_hbIds;
0150   mutable edm::AtomicPtrCache<std::vector<DetId>> m_heIds;
0151   mutable edm::AtomicPtrCache<std::vector<DetId>> m_hoIds;
0152   mutable edm::AtomicPtrCache<std::vector<DetId>> m_hfIds;
0153   mutable edm::AtomicPtrCache<std::vector<DetId>> m_emptyIds;
0154   CaloSubdetectorGeometry::IVec m_dins;
0155 
0156   HBCellVec m_hbCellVec;
0157   HECellVec m_heCellVec;
0158   HOCellVec m_hoCellVec;
0159   HFCellVec m_hfCellVec;
0160 };
0161 
0162 #endif