Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:07:37

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