Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 13:03:38

0001 #ifndef GeometryHGCalGeometryHGCalGeometry_h
0002 #define GeometryHGCalGeometryHGCalGeometry_h
0003 
0004 /*
0005  * Geometry for High Granularity Calorimeter
0006  * This geometry is essentially driven by topology, 
0007  * which is thus encapsulated in this class. 
0008  * This makes this geometry not suitable to be loaded
0009  * by regular CaloGeometryLoader<T>
0010  */
0011 
0012 #include "DataFormats/Common/interface/AtomicPtrCache.h"
0013 #include "DataFormats/ForwardDetId/interface/HFNoseDetId.h"
0014 #include "DataFormats/ForwardDetId/interface/HGCalDetId.h"
0015 #include "DataFormats/ForwardDetId/interface/HGCScintillatorDetId.h"
0016 #include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h"
0017 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
0018 #include "DataFormats/GeometryVector/interface/GlobalVector.h"
0019 #include "DetectorDescription/Core/interface/DDFilteredView.h"
0020 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
0021 #include "Geometry/CaloGeometry/interface/FlatHexagon.h"
0022 #include "Geometry/CaloGeometry/interface/FlatTrd.h"
0023 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0024 #include "Geometry/CaloTopology/interface/HGCalTopology.h"
0025 #include "Geometry/Records/interface/HGCalGeometryRecord.h"
0026 #include "MagneticField/Engine/interface/MagneticField.h"
0027 #include <vector>
0028 
0029 class HGCalGeometry final : public CaloSubdetectorGeometry {
0030 public:
0031   typedef std::vector<FlatHexagon> CellVec;
0032   typedef std::vector<FlatTrd> CellVec2;
0033   typedef CaloCellGeometry::CCGFloat CCGFloat;
0034   typedef CaloCellGeometry::Pt3D Pt3D;
0035   typedef CaloCellGeometry::Pt3DVec Pt3DVec;
0036 
0037   typedef std::set<DetId> DetIdSet;
0038   typedef std::vector<GlobalPoint> CornersVec;
0039 
0040   typedef HGCalGeometryRecord AlignedRecord;  // NOTE: not aligned yet
0041   typedef PHGCalRcd PGeometryRecord;
0042 
0043   static constexpr unsigned int k_NumberOfParametersPerTrd = 12;   // FlatTrd
0044   static constexpr unsigned int k_NumberOfParametersPerHex = 3;    // FlatHexagon
0045   static constexpr unsigned int k_NumberOfParametersPerShape = 3;  // FlatHexagon
0046   static constexpr unsigned int k_NumberOfShapes = 100;
0047   static constexpr unsigned int k_NumberOfShapesTrd = 1000;
0048 
0049   static std::string dbString() { return "PHGCalRcd"; }
0050 
0051   HGCalGeometry(const HGCalTopology& topology);
0052 
0053   ~HGCalGeometry() override = default;
0054 
0055   void localCorners(Pt3DVec& lc, const CCGFloat* pv, unsigned int i, Pt3D& ref);
0056 
0057   void newCell(const GlobalPoint& f1,
0058                const GlobalPoint& f2,
0059                const GlobalPoint& f3,
0060                const CCGFloat* parm,
0061                const DetId& detId) override;
0062 
0063   /// Get the cell geometry of a given detector id.  Should return false if not found.
0064   std::shared_ptr<const CaloCellGeometry> getGeometry(const DetId& id) const override;
0065 
0066   bool present(const DetId& id) const override;
0067 
0068   void getSummary(CaloSubdetectorGeometry::TrVec& trVector,
0069                   CaloSubdetectorGeometry::IVec& iVector,
0070                   CaloSubdetectorGeometry::DimVec& dimVector,
0071                   CaloSubdetectorGeometry::IVec& dinsVector) const override;
0072 
0073   GlobalPoint getPosition(const DetId& id, bool debug = false) const;
0074   GlobalPoint getWaferPosition(const DetId& id) const;
0075 
0076   /// Returns area of a cell
0077   double getArea(const DetId& detid) const;
0078 
0079   /// Returns the corner points of this cell's volume.
0080   CornersVec getCorners(const DetId& id) const;
0081   CornersVec get8Corners(const DetId& id) const;
0082   CornersVec getNewCorners(const DetId& id, bool debug = false) const;
0083 
0084   // Get neighbor in z along a direction
0085   DetId neighborZ(const DetId& idin, const GlobalVector& p) const;
0086   DetId neighborZ(const DetId& idin, const MagneticField* bField, int charge, const GlobalVector& momentum) const;
0087 
0088   // avoid sorting set in base class
0089   const std::vector<DetId>& getValidDetIds(DetId::Detector det = DetId::Detector(0), int subdet = 0) const override {
0090     return m_validIds;
0091   }
0092   const std::vector<DetId>& getValidGeomDetIds(void) const { return m_validGeomIds; }
0093 
0094   // Get closest cell, etc...
0095   DetId getClosestCell(const GlobalPoint& r) const override;
0096   DetId getClosestCellHex(const GlobalPoint& r, bool extend) const;
0097 
0098   /** \brief Get a list of all cells within a dR of the given cell
0099       
0100       The default implementation makes a loop over all cell geometries.
0101       Cleverer implementations are suggested to use rough conversions between
0102       eta/phi and ieta/iphi and test on the boundaries.
0103   */
0104   DetIdSet getCells(const GlobalPoint& r, double dR) const override;
0105 
0106   virtual void fillNamedParams(DDFilteredView fv);
0107   void initializeParms() override;
0108 
0109   static std::string producerTag() { return "HGCal"; }
0110   std::string cellElement() const;
0111 
0112   const HGCalTopology& topology() const { return m_topology; }
0113   void sortDetIds();
0114 
0115 protected:
0116   unsigned int indexFor(const DetId& id) const override;
0117   using CaloSubdetectorGeometry::sizeForDenseIndex;
0118   unsigned int sizeForDenseIndex() const;
0119 
0120   // Modify the RawPtr class
0121   const CaloCellGeometry* getGeometryRawPtr(uint32_t index) const override;
0122 
0123   std::shared_ptr<const CaloCellGeometry> cellGeomPtr(uint32_t index) const override;
0124 
0125   void addValidID(const DetId& id);
0126   unsigned int getClosestCellIndex(const GlobalPoint& r) const;
0127 
0128 private:
0129   template <class T>
0130   unsigned int getClosestCellIndex(const GlobalPoint& r, const std::vector<T>& vec) const;
0131   std::shared_ptr<const CaloCellGeometry> cellGeomPtr(uint32_t index, const GlobalPoint& p) const;
0132   DetId getGeometryDetId(DetId detId) const;
0133 
0134   static constexpr double k_half = 0.5;
0135   static constexpr double k_fac1 = 0.5;
0136   static constexpr double k_fac2 = 1.0 / 3.0;
0137 
0138   const HGCalTopology& m_topology;
0139   CellVec m_cellVec;
0140   CellVec2 m_cellVec2;
0141   std::vector<DetId> m_validGeomIds;
0142   DetId::Detector m_det;
0143   ForwardSubdetector m_subdet;
0144   const double twoBysqrt3_;
0145 };
0146 
0147 #endif