Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:14:23

0001 #ifndef Calibration_Tools_DetIdAssociator_h
0002 #define Calibration_Tools_DetIdAssociator_h
0003 
0004 //
0005 // Original Author:  Dmytro Kovalskyi
0006 // Modified for HCAL by Michal Szleper
0007 //
0008 
0009 #include "DataFormats/DetId/interface/DetId.h"
0010 #include "DataFormats/CaloTowers/interface/CaloTowerDetId.h"
0011 #include "DataFormats/CaloTowers/interface/CaloTower.h"
0012 #include "DataFormats/CaloTowers/interface/CaloTowerCollection.h"
0013 #include "DataFormats/HcalRecHit/interface/HBHERecHit.h"
0014 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
0015 #include "FWCore/Framework/interface/Event.h"
0016 #include "FWCore/Framework/interface/EventSetup.h"
0017 #include "FWCore/Framework/interface/MakerMacros.h"
0018 #include "DataFormats/Common/interface/Handle.h"
0019 #include "FWCore/Framework/interface/ESHandle.h"
0020 #include "DataFormats/Common/interface/OrphanHandle.h"
0021 //#include "DataFormats/GeometryVector/interface/GlobalPoint.h"
0022 #include "DataFormats/GeometrySurface/interface/Cylinder.h"
0023 #include "DataFormats/GeometrySurface/interface/Plane.h"
0024 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
0025 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
0026 #include "FWCore/Utilities/interface/Exception.h"
0027 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0028 
0029 #include <set>
0030 #include <vector>
0031 
0032 class HDetIdAssociator {
0033 public:
0034   HDetIdAssociator() : theMap_(nullptr), nPhi_(0), nEta_(0), etaBinSize_(0), ivProp_(nullptr){};
0035   HDetIdAssociator(const int nPhi, const int nEta, const double etaBinSize)
0036       : theMap_(nullptr), nPhi_(nPhi), nEta_(nEta), etaBinSize_(etaBinSize), ivProp_(nullptr){};
0037 
0038   virtual ~HDetIdAssociator(){};
0039   virtual std::vector<GlobalPoint> getTrajectory(const FreeTrajectoryState&, const std::vector<GlobalPoint>&);
0040   // find DetIds arround given direction
0041   // idR is a number of the adjacent bins to retrieve
0042   virtual std::set<DetId> getDetIdsCloseToAPoint(const GlobalPoint&, const int idR = 0);
0043   // dR is a cone radius in eta-phi
0044   virtual std::set<DetId> getDetIdsCloseToAPoint(const GlobalPoint& point, const double dR = 0) {
0045     int etaIdR = int(dR / etaBinSize_);
0046     int phiIdR = int(dR / (2 * 3.1416) * nPhi_);
0047     if (etaIdR > phiIdR)
0048       return getDetIdsCloseToAPoint(point, 1 + etaIdR);
0049     else
0050       return getDetIdsCloseToAPoint(point, 1 + phiIdR);
0051   }
0052 
0053   virtual std::set<DetId> getDetIdsInACone(const std::set<DetId>&,
0054                                            const std::vector<GlobalPoint>& trajectory,
0055                                            const double);
0056   virtual std::set<DetId> getCrossedDetIds(const std::set<DetId>&, const std::vector<GlobalPoint>& trajectory);
0057   virtual std::set<DetId> getMaxEDetId(const std::set<DetId>&, edm::Handle<CaloTowerCollection> caloTowers);
0058   virtual std::set<DetId> getMaxEDetId(const std::set<DetId>&, edm::Handle<HBHERecHitCollection> recHits);
0059 
0060   virtual int iEta(const GlobalPoint&);
0061   virtual int iPhi(const GlobalPoint&);
0062   virtual void setPropagator(Propagator* ptr) { ivProp_ = ptr; };
0063 
0064 protected:
0065   virtual void check_setup() {
0066     if (nEta_ == 0)
0067       throw cms::Exception("FatalError") << "Number of eta bins is not set.\n";
0068     if (nPhi_ == 0)
0069       throw cms::Exception("FatalError") << "Number of phi bins is not set.\n";
0070     if (ivProp_ == nullptr)
0071       throw cms::Exception("FatalError") << "Track propagator is not defined\n";
0072     if (etaBinSize_ == 0)
0073       throw cms::Exception("FatalError") << "Eta bin size is not set.\n";
0074   }
0075 
0076   virtual void buildMap();
0077   virtual GlobalPoint getPosition(const DetId&) = 0;
0078   virtual std::set<DetId> getASetOfValidDetIds() = 0;
0079   virtual std::vector<GlobalPoint> getDetIdPoints(const DetId&) = 0;
0080 
0081   virtual bool insideElement(const GlobalPoint&, const DetId&) = 0;
0082   virtual bool nearElement(const GlobalPoint& point, const DetId& id, const double distance) {
0083     GlobalPoint center = getPosition(id);
0084     return sqrt(pow(point.eta() - center.eta(), 2) + pow(point.phi() - center.phi(), 2)) < distance;
0085   };
0086 
0087   std::vector<std::vector<std::set<DetId> > >* theMap_;
0088   const int nPhi_;
0089   const int nEta_;
0090   const double etaBinSize_;
0091   Propagator* ivProp_;
0092 };
0093 
0094 #endif  // Calibration_Tools_DetIdAssociator_h