Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-10-29 06:08:23

0001 #ifndef GEOMETRY_CALOGEOMETRY_CALOCELLGEOMETRY_H
0002 #define GEOMETRY_CALOGEOMETRY_CALOCELLGEOMETRY_H 1
0003 
0004 #include "Geometry/CaloGeometry/interface/EZArrayFL.h"
0005 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
0006 #include "DataFormats/GeometryVector/interface/GlobalVector.h"
0007 #include <CLHEP/Geometry/Point3D.h>
0008 #include <CLHEP/Geometry/Transform3D.h>
0009 #include "DataFormats/Math/interface/PtEtaPhiMass.h"
0010 
0011 #include <vector>
0012 #include <array>
0013 #include <string>
0014 #include <cassert>
0015 #include <atomic>
0016 
0017 /** \class CaloCellGeometry
0018 
0019 Abstract base class for an individual cell's geometry.
0020 
0021 The base class declares a pure virtual function and also writes a definition (body)
0022 to force conscious acceptance of default behaviour.
0023 
0024 If a derived class doesn't choose to override a normal virtual,
0025 it just inherits the base version's behaviour by default. If you want
0026 to provide a default behaviour but not let derived classes just inherit
0027 it "silently" like this, you can make it pure virtual but still provide
0028 a default that the derived class author has to call deliberately if he wants it:
0029 
0030 @code
0031    class B {
0032      public:
0033          virtual bool f() = 0;
0034      };
0035 
0036      bool B::f() {
0037          return true;  // this is a good default, but
0038      }                 // shouldn't be used blindly
0039 
0040      class D : public B {
0041      public:
0042          bool f() {
0043              return B::f(); // if D wants the default
0044          }                  // behaviour, it has to say so
0045     };
0046 @endcode
0047 
0048 \author J. Mans, P. Meridiani
0049 */
0050 
0051 class CaloCellGeometry {
0052 public:
0053   typedef float CCGFloat;
0054   typedef HepGeom::Transform3D Tr3D;
0055   typedef HepGeom::Point3D<CCGFloat> Pt3D;
0056   typedef std::vector<Pt3D> Pt3DVec;
0057 
0058   typedef EZArrayFL<GlobalPoint> CornersVec;
0059   typedef EZMgrFL<GlobalPoint> CornersMgr;
0060 
0061   typedef EZArrayFL<CCGFloat> ParVec;
0062   typedef std::vector<ParVec> ParVecVec;
0063   typedef EZMgrFL<CCGFloat> ParMgr;
0064 
0065   friend class CaloCellGeometryMayOwnPtr;
0066 
0067   static constexpr unsigned int k_cornerSize = 8;
0068 
0069   using RepCorners = std::array<RhoEtaPhi, k_cornerSize>;
0070 
0071   static const CCGFloat k_ScaleFromDDDtoGeant;
0072 
0073   virtual ~CaloCellGeometry();
0074 
0075   /// Returns the corner points of this cell's volume.
0076   CornersVec const& getCorners() const {
0077     assert(not m_corners.uninitialized());
0078     return m_corners;
0079   }
0080   RepCorners const& getCornersREP() const { return m_repCorners; }
0081 
0082   /// Returns the position of reference for this cell
0083   virtual const GlobalPoint& getPosition() const { return m_refPoint; }
0084   virtual GlobalPoint getPosition(CCGFloat) const { return m_refPoint; }
0085   virtual GlobalPoint getPosition(const Pt3D&) const { return m_refPoint; }
0086 
0087   GlobalPoint const& getBackPoint() const { return m_backPoint; }
0088 
0089   RhoEtaPhi const& repPos() const { return m_rep; }
0090   virtual float rhoPos() const { return m_rep.rho(); }
0091   virtual float etaPos() const { return m_rep.eta(); }
0092   virtual float phiPos() const { return m_rep.phi(); }
0093 
0094   virtual float etaSpan() const { return m_dEta; }
0095   virtual float phiSpan() const { return m_dPhi; }
0096 
0097   /// Returns true if the specified point is inside this cell
0098   bool inside(const GlobalPoint& point) const;
0099 
0100   bool emptyCorners() const { return m_corners.empty(); }
0101 
0102   const CCGFloat* param() const { return m_parms; }
0103 
0104   static const CCGFloat* checkParmPtr(const std::vector<CCGFloat>& vd, ParVecVec& pvv);
0105 
0106   static const CCGFloat* getParmPtr(const std::vector<CCGFloat>& vd, ParMgr* mgr, ParVecVec& pvv);
0107 
0108   ///----------- only needed by specific utility; overloaded when needed ----
0109   virtual void getTransform(Tr3D& tr, Pt3DVec* lptr) const;
0110   //------------------------------------------------------------------------
0111   void setBackPoint(const GlobalPoint& pos) { m_backPoint = pos; }
0112 
0113   virtual void vocalCorners(Pt3DVec& vec, const CCGFloat* pv, Pt3D& ref) const = 0;
0114 
0115 protected:
0116   CaloCellGeometry(CornersVec::const_reference gp, CornersMgr* mgr, const CCGFloat* par);
0117 
0118   CaloCellGeometry(const CornersVec& cv, const CCGFloat* par);
0119 
0120   CaloCellGeometry();
0121 
0122   CaloCellGeometry(CaloCellGeometry&&) = default;
0123   CaloCellGeometry(CaloCellGeometry const&) = default;
0124   CaloCellGeometry& operator=(CaloCellGeometry&&) = default;
0125   CaloCellGeometry& operator=(CaloCellGeometry const&) = default;
0126   // MUST be called by children constructors
0127   void initSpan() {
0128     initCorners(m_corners);
0129     m_dEta = std::abs(getCorners()[0].eta() - getCorners()[2].eta());
0130     m_dPhi = std::abs(getCorners()[0].phi() - getCorners()[2].phi());
0131     initBack();
0132     initReps();
0133   }
0134 
0135   virtual void initCorners(CornersVec&) = 0;
0136 
0137   void setRefPoint(const GlobalPoint& pos) { m_refPoint = pos; }
0138   void setCornerVec(const std::vector<GlobalPoint>& cor) {
0139     for (unsigned int k = 0; k < cor.size(); ++k)
0140       m_corners[k] = cor[k];
0141   }
0142 
0143 private:
0144   void initBack() {
0145     // from CaloTower code
0146     CornersVec const& cv = getCorners();
0147     m_backPoint = GlobalPoint(0.25 * (cv[4].x() + cv[5].x() + cv[6].x() + cv[7].x()),
0148                               0.25 * (cv[4].y() + cv[5].y() + cv[6].y() + cv[7].y()),
0149                               0.25 * (cv[4].z() + cv[5].z() + cv[6].z() + cv[7].z()));
0150   }
0151   void initReps() {
0152     for (auto i = 0U; i < k_cornerSize; ++i)
0153       m_repCorners[i] = {getCorners()[i].perp(), getCorners()[i].eta(), getCorners()[i].barePhi()};
0154   }
0155 
0156   //These methods are ONLY used by CaloCellGeometryMayOwnPtr
0157   void increment() const { ++m_ref.m_count; }
0158   bool decrement() const { return 0 == --m_ref.m_count; }
0159 
0160   GlobalPoint m_refPoint;
0161   GlobalPoint m_backPoint;
0162   CornersVec m_corners;
0163   const CCGFloat* m_parms;
0164   RhoEtaPhi m_rep;
0165   float m_dEta;
0166   float m_dPhi;
0167   std::array<RhoEtaPhi, k_cornerSize> m_repCorners;
0168   struct RefCount {
0169     RefCount() = default;
0170     RefCount(RefCount&&) {}
0171     RefCount(RefCount const&) {}
0172     RefCount& operator=(RefCount&&) { return *this; }
0173     RefCount& operator=(const RefCount&) { return *this; }
0174 
0175     mutable std::atomic<unsigned int> m_count = 0;
0176   } m_ref;
0177 };
0178 
0179 std::ostream& operator<<(std::ostream& s, const CaloCellGeometry& cell);
0180 
0181 #endif