Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:31:35

0001 #ifndef TrackingTools_TrackAssociator_DetIdAssociator_h
0002 #define TrackingTools_TrackAssociator_DetIdAssociator_h 1
0003 
0004 // -*- C++ -*-
0005 //
0006 // Package:    TrackingTools/TrackAssociator
0007 // Class:      DetIdAssociator
0008 //
0009 /**\
0010 
0011  Description: Abstract base class for 3D point -> std::set<DetId>
0012 
0013  Implementation:
0014      A look up map of active detector elements in eta-phi space is 
0015      built to speed up access to the detector element geometry as well 
0016      as associated hits. The map is uniformly binned in eta and phi 
0017      dimensions, which can be viewed as a histogram with every bin
0018      containing DetId of elements crossed in a given eta-phi window.
0019      It is very likely that a single DetId can be found in a few bins
0020      if it's geometrical size is bigger than eta-phi bin size.
0021 
0022      The map is implemented as a double array. The first one has fixed
0023      size and points to the range of array elements in the second one.
0024 **/
0025 //
0026 // Original Author:  Dmytro Kovalskyi
0027 //         Created:  Fri Apr 21 10:59:41 PDT 2006
0028 //
0029 //
0030 
0031 #include "DataFormats/DetId/interface/DetId.h"
0032 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
0033 #include "DataFormats/GeometrySurface/interface/Cylinder.h"
0034 #include "DataFormats/GeometrySurface/interface/Plane.h"
0035 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
0036 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
0037 #include "FWCore/Utilities/interface/Exception.h"
0038 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0039 #include "TrackPropagation/SteppingHelixPropagator/interface/SteppingHelixStateInfo.h"
0040 #include "TrackingTools/TrackAssociator/interface/FiducialVolume.h"
0041 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0042 #include <set>
0043 #include <vector>
0044 
0045 class DetIdAssociator {
0046 public:
0047   enum PropagationTarget { Barrel, ForwardEndcap, BackwardEndcap };
0048   struct MapRange {
0049     float dThetaPlus;
0050     float dThetaMinus;
0051     float dPhiPlus;
0052     float dPhiMinus;
0053   };
0054   typedef std::vector<GlobalPoint>::const_iterator const_iterator;
0055 
0056   DetIdAssociator(const int nPhi, const int nEta, const double etaBinSize);
0057   virtual ~DetIdAssociator() {}
0058 
0059   /// Preselect DetIds close to a point on the inner surface of the detector.
0060   /// "iN" is a number of the adjacent bins of the map to retrieve
0061   virtual std::set<DetId> getDetIdsCloseToAPoint(const GlobalPoint&, const int iN = 0) const;
0062   virtual std::set<DetId> getDetIdsCloseToAPoint(const GlobalPoint& direction,
0063                                                  const unsigned int iNEtaPlus,
0064                                                  const unsigned int iNEtaMinus,
0065                                                  const unsigned int iNPhiPlus,
0066                                                  const unsigned int iNPhiMinus) const;
0067   virtual std::set<DetId> getDetIdsCloseToAPoint(const GlobalPoint& direction, const MapRange& mapRange) const;
0068   /// Preselect DetIds close to a point on the inner surface of the detector.
0069   /// "d" defines the allowed range in theta-phi space:
0070   /// - theta is in [point.theta()-d, point.theta()+d]
0071   /// - phi is in [point.phi()-d, point.phi()+d]
0072   virtual std::set<DetId> getDetIdsCloseToAPoint(const GlobalPoint& point, const double d = 0) const;
0073   /// - theta is in [point.theta()-dThetaMinus, point.theta()+dThetaPlus]
0074   /// - phi is in [point.phi()-dPhiMinus, point.phi()+dPhiPlus]
0075   virtual std::set<DetId> getDetIdsCloseToAPoint(const GlobalPoint& point,
0076                                                  const double dThetaPlus,
0077                                                  const double dThetaMinus,
0078                                                  const double dPhiPlus,
0079                                                  const double dPhiMinus) const;
0080 
0081   /// helper to see if getDetIdsInACone is useful
0082   virtual bool selectAllInACone(const double dR) const { return dR > 2 * M_PI && dR > maxEta_; }
0083 
0084   /// Find DetIds that satisfy given requirements
0085   /// - inside eta-phi cone of radius dR
0086   virtual std::set<DetId> getDetIdsInACone(const std::set<DetId>&,
0087                                            const std::vector<GlobalPoint>& trajectory,
0088                                            const double dR) const;
0089   /// - DetIds crossed by the track
0090   ///   tolerance is the radius of the trajectory used for matching
0091   ///   -1 is default and represent the case with no uncertainty
0092   ///   on the trajectory direction. It's the fastest option
0093   /// - DetIds crossed by the track, ordered according to the order
0094   ///   that they were crossed by the track flying outside the detector
0095   virtual std::vector<DetId> getCrossedDetIds(const std::set<DetId>&, const std::vector<GlobalPoint>& trajectory) const;
0096   virtual std::vector<DetId> getCrossedDetIds(const std::set<DetId>&,
0097                                               const std::vector<SteppingHelixStateInfo>& trajectory,
0098                                               const double toleranceInSigmas = -1) const;
0099   /// look-up map eta index
0100   virtual int iEta(const GlobalPoint&) const;
0101   /// look-up map phi index
0102   virtual int iPhi(const GlobalPoint&) const;
0103   /// number of bins of the look-up map in phi dimension
0104   int nPhiBins() const { return nPhi_; }
0105   /// number of bins of the look-up map in eta dimension
0106   int nEtaBins() const { return nEta_; }
0107   /// look-up map bin size in eta dimension
0108   double etaBinSize() const { return etaBinSize_; };
0109   /// make the look-up map
0110   virtual void buildMap();
0111   /// get active detector volume
0112   const FiducialVolume& volume() const;
0113 
0114   virtual const GeomDet* getGeomDet(const DetId&) const = 0;
0115 
0116   virtual const char* name() const = 0;
0117 
0118 protected:
0119   virtual void check_setup() const;
0120 
0121   virtual void dumpMapContent(int, int) const;
0122   virtual void dumpMapContent(int, int, int, int) const;
0123 
0124   virtual GlobalPoint getPosition(const DetId&) const = 0;
0125   virtual const unsigned int getNumberOfSubdetectors() const { return 1; }
0126   virtual void getValidDetIds(unsigned int subDetectorIndex, std::vector<DetId>&) const = 0;
0127   virtual std::pair<const_iterator, const_iterator> getDetIdPoints(const DetId&, std::vector<GlobalPoint>&) const = 0;
0128 
0129   virtual bool insideElement(const GlobalPoint&, const DetId&) const = 0;
0130   virtual bool crossedElement(const GlobalPoint&,
0131                               const GlobalPoint&,
0132                               const DetId&,
0133                               const double toleranceInSigmas = -1,
0134                               const SteppingHelixStateInfo* = nullptr) const {
0135     return false;
0136   }
0137   virtual bool nearElement(const GlobalPoint& point, const DetId& id, const double distance) const;
0138 
0139   unsigned int index(unsigned int iEta, unsigned int iPhi) const { return iEta * nPhi_ + iPhi; }
0140   void fillSet(std::set<DetId>& set, unsigned int iEta, unsigned int iPhi) const;
0141 
0142   // map parameters
0143   const int nPhi_;
0144   const int nEta_;
0145   // The first number in the pair points to the begging
0146   // of the DetId list for a given bin
0147   // The second number is the number of elements in a bin
0148   std::vector<std::pair<unsigned int, unsigned int> > lookupMap_;
0149   std::vector<DetId> container_;
0150   bool theMapIsValid_;
0151   const double etaBinSize_;
0152   double maxEta_;
0153   double minTheta_;
0154 
0155   // Detector fiducial volume
0156   // approximated as a closed cylinder with non-zero width.
0157   // Parameters are extracted from the active detector elements.
0158   FiducialVolume volume_;
0159 };
0160 #endif