Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-10-25 23:57:04

0001 #ifndef GEOMETRY_CALOGEOMETRY_CALOSUBDETECTORGEOMETRY_H
0002 #define GEOMETRY_CALOGEOMETRY_CALOSUBDETECTORGEOMETRY_H 1
0003 
0004 #include <algorithm>
0005 #include <memory>
0006 #include <vector>
0007 #include <set>
0008 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
0009 #include <atomic>
0010 #endif
0011 #include "DataFormats/DetId/interface/DetId.h"
0012 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
0013 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
0014 #include "Geometry/CaloGeometry/interface/CaloCellGeometryPtr.h"
0015 #include "Geometry/CaloGeometry/interface/CaloCellGeometryMayOwnPtr.h"
0016 #include "DataFormats/Math/interface/deltaR.h"
0017 
0018 /** \class CaloSubdetectorGeometry
0019       
0020 Base class for a geometry container for a specific calorimetry subdetector.
0021 
0022 
0023 \author J. Mans - Minnesota
0024 */
0025 class CaloSubdetectorGeometry {
0026 public:
0027   typedef std::vector<std::shared_ptr<const CaloCellGeometry> > CellSet;
0028   typedef CaloCellGeometry::CCGFloat CCGFloat;
0029 
0030   typedef std::set<DetId> DetIdSet;
0031 
0032   typedef CaloCellGeometry::ParMgr ParMgr;
0033   typedef CaloCellGeometry::ParVec ParVec;
0034   typedef CaloCellGeometry::ParVecVec ParVecVec;
0035 
0036   typedef std::vector<CCGFloat> TrVec;
0037   typedef std::vector<unsigned int> IVec;
0038   typedef std::vector<CCGFloat> DimVec;
0039 
0040   using CellPtr = CaloCellGeometryPtr;
0041   using CellMayOwnPtr = CaloCellGeometryMayOwnPtr;
0042 
0043   CaloSubdetectorGeometry();
0044 
0045   /// The base class DOES assume that it owns the CaloCellGeometry objects
0046   virtual ~CaloSubdetectorGeometry();
0047 
0048   /// avoid copies
0049   CaloSubdetectorGeometry(const CaloSubdetectorGeometry&) = delete;
0050   CaloSubdetectorGeometry& operator=(const CaloSubdetectorGeometry&) = delete;
0051 
0052   virtual void newCell(const GlobalPoint& f1,
0053                        const GlobalPoint& f2,
0054                        const GlobalPoint& f3,
0055                        const CCGFloat* parm,
0056                        const DetId& detId) = 0;
0057 
0058   /// is this detid present in the geometry?
0059   virtual bool present(const DetId& id) const;
0060 
0061   /// Get the cell geometry of a given detector id.  Should return false if not found.
0062   virtual CellMayOwnPtr getGeometry(const DetId& id) const;
0063 
0064   /** \brief Get a list of valid detector ids (for the given subdetector)
0065       \note The implementation in this class is relevant for SubdetectorGeometries which handle only
0066       a single subdetector at a time.  It does not look at the det and subdet arguments.
0067   */
0068   virtual const std::vector<DetId>& getValidDetIds(DetId::Detector det = DetId::Detector(0), int subdet = 0) const;
0069 
0070   // Get closest cell, etc...
0071   virtual DetId getClosestCell(const GlobalPoint& r) const;
0072 
0073   /** \brief Get a list of all cells within a dR of the given cell
0074       
0075       The default implementation makes a loop over all cell geometries.
0076       Cleverer implementations are suggested to use rough conversions between
0077       eta/phi and ieta/iphi and test on the boundaries.
0078   */
0079   virtual DetIdSet getCells(const GlobalPoint& r, double dR) const;
0080   virtual CellSet getCellSet(const GlobalPoint& r, double dR) const;
0081 
0082   CCGFloat deltaPhi(const DetId& detId) const;
0083 
0084   CCGFloat deltaEta(const DetId& detId) const;
0085 
0086   void allocateCorners(CaloCellGeometry::CornersVec::size_type n);
0087 
0088   CaloCellGeometry::CornersMgr* cornersMgr() { return m_cmgr; }
0089 
0090   void allocatePar(ParVec::size_type n, unsigned int m);
0091 
0092   ParMgr* parMgr() { return m_parMgr; }
0093   const ParMgr* parMgrConst() const { return m_parMgr; }
0094 
0095   ParVecVec& parVecVec() { return m_parVecVec; }
0096   const ParVecVec& parVecVec() const { return m_parVecVec; }
0097 
0098   virtual unsigned int numberOfShapes() const { return 1; }
0099   virtual unsigned int numberOfParametersPerShape() const { return 1; }
0100   virtual unsigned int numberOfTransformParms() const { return 6; }
0101 
0102   virtual void fillDefaultNamedParameters() const { return; }
0103 
0104   virtual void getSummary(TrVec& trVector, IVec& iVector, DimVec& dimVector, IVec& dinsVector) const;
0105 
0106   virtual void initializeParms() { return; }
0107 
0108   virtual bool valid(const DetId& id) const {
0109     return (std::find(m_validIds.begin(), m_validIds.end(), id) != m_validIds.end());
0110   }
0111 
0112 protected:
0113   virtual unsigned int indexFor(const DetId& id) const;
0114   virtual unsigned int sizeForDenseIndex(const DetId& id) const;
0115 
0116   virtual CellPtr getGeometryRawPtr(uint32_t index) const = 0;
0117   virtual CellPtr cellGeomPtr(uint32_t index) const;
0118 
0119   ParVecVec m_parVecVec;
0120 
0121   static CCGFloat deltaR(const GlobalPoint& p1, const GlobalPoint& p2) { return reco::deltaR(p1, p2); }
0122 
0123   void addValidID(const DetId& id);
0124 
0125   std::vector<DetId> m_validIds;
0126 
0127 private:
0128   ParMgr* m_parMgr;
0129 
0130   CaloCellGeometry::CornersMgr* m_cmgr;
0131 
0132   bool m_sortedIds;
0133 
0134 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
0135   mutable std::atomic<std::vector<CCGFloat>*> m_deltaPhi;
0136   mutable std::atomic<std::vector<CCGFloat>*> m_deltaEta;
0137 #else
0138   mutable std::vector<CCGFloat>* m_deltaPhi;
0139   mutable std::vector<CCGFloat>* m_deltaEta;
0140 #endif
0141 };
0142 
0143 #endif