CMS 3D CMS Logo

HGCalShowerShapeHelper.h
Go to the documentation of this file.
1 #ifndef RecoEgamma_EgammaTools_HGCalShowerShapeHelper_h
2 #define RecoEgamma_EgammaTools_HGCalShowerShapeHelper_h
3 
4 // system include files
5 #include <map>
6 #include <memory>
7 #include <utility>
8 #include <vector>
9 
10 // external include files
11 #include <Math/Vector3Dfwd.h>
12 
13 // CMSSW include files
30 
32  // Good to filter/compute/store this stuff beforehand as they are common to the shower shape variables.
33  // No point in filtering, computing layer-wise centroids, etc. for each variable again and again.
34  // Once intitialized, one can the calculate different variables one after another for a given object.
35  // This is all handled by ShowerShapeCalc class which caches the layer-wise centroids and other
36  // heavy variables for an object + set of cuts
37  // It was changed to this approach so that we could use this in constant functions
38 
39  // In principle should consider the HGCalHSi and HGCalHSc hits (leakage) also.
40  // Can have subdetector dependent thresholds and layer selection.
41  // To be implemented.
42 
43 public:
44  static const double kLDWaferCellSize_;
45  static const double kHDWaferCellSize_;
46 
47  struct ShowerWidths {
48  double sigma2xx;
49  double sigma2yy;
50  double sigma2zz;
51 
52  double sigma2xy;
53  double sigma2yz;
54  double sigma2zx;
55 
56  double sigma2uu;
57  double sigma2vv;
58  double sigma2ww;
59 
61  : sigma2xx(0.0),
62  sigma2yy(0.0),
63  sigma2zz(0.0),
64  sigma2xy(0.0),
65  sigma2yz(0.0),
66  sigma2zx(0.0),
67  sigma2uu(0.0),
68  sigma2vv(0.0),
69  sigma2ww(0.0) {}
70  };
71 
73  public:
74  ShowerShapeCalc(std::shared_ptr<const hgcal::RecHitTools> recHitTools,
75  std::shared_ptr<const std::unordered_map<uint32_t, const reco::PFRecHit *> > pfRecHitPtrMap,
76  const std::vector<std::pair<DetId, float> > &hitsAndFracs,
77  const double rawEnergy,
78  const double minHitE = 0,
79  const double minHitET = 0,
80  const int minLayer = 1,
81  const int maxLayer = -1,
83 
84  double getCellSize(DetId detId) const;
85 
86  // Compute Rvar in a cylinder around the layer centroids
87  double getRvar(double cylinderR, bool useFractions = true, bool useCellSize = true) const;
88 
89  // Compute PCA widths around the layer centroids
90  ShowerWidths getPCAWidths(double cylinderR, bool useFractions = false) const;
91 
92  std::vector<double> getEnergyHighestHits(unsigned int nrHits, bool useFractions = true) const;
93 
94  private:
95  void setFilteredHitsAndFractions(const std::vector<std::pair<DetId, float> > &hitsAndFracs);
96  void setLayerWiseInfo();
97 
98  std::shared_ptr<const hgcal::RecHitTools> recHitTools_;
99  std::shared_ptr<const std::unordered_map<uint32_t, const reco::PFRecHit *> > pfRecHitPtrMap_;
100  double rawEnergy_;
101 
102  double minHitE_;
103  double minHitET_;
104  double minHitET2_;
107  int nLayer_;
109 
110  std::vector<std::pair<DetId, float> > hitsAndFracs_;
111  std::vector<double> hitEnergies_;
112  std::vector<double> hitEnergiesWithFracs_;
113 
115  std::vector<double> layerEnergies_;
116  std::vector<ROOT::Math::XYZVector> layerCentroids_;
117  };
118 
121  ~HGCalShowerShapeHelper() = default;
122  HGCalShowerShapeHelper(const HGCalShowerShapeHelper &rhs) = delete;
123  HGCalShowerShapeHelper(const HGCalShowerShapeHelper &&rhs) = delete;
126 
127  template <edm::Transition tr = edm::Transition::Event>
128  void setTokens(edm::ConsumesCollector consumesCollector) {
129  caloGeometryToken_ = consumesCollector.esConsumes<CaloGeometry, CaloGeometryRecord, tr>();
130  }
131 
132  void initPerSetup(const edm::EventSetup &iSetup);
133  void initPerEvent(const std::vector<reco::PFRecHit> &recHits);
134  void initPerEvent(const edm::EventSetup &iSetup, const std::vector<reco::PFRecHit> &recHits);
135 
136  HGCalShowerShapeHelper::ShowerShapeCalc createCalc(const std::vector<std::pair<DetId, float> > &hitsAndFracs,
137  double rawEnergy,
138  double minHitE = 0,
139  double minHitET = 0,
140  int minLayer = 1,
141  int maxLayer = -1,
142  DetId::Detector subDet = DetId::HGCalEE) const;
144  double minHitE = 0,
145  double minHitET = 0,
146  int minLayer = 1,
147  int maxLayer = -1,
148  DetId::Detector subDet = DetId::HGCalEE) const {
149  return createCalc(sc.hitsAndFractions(), sc.rawEnergy(), minHitE, minHitET, minLayer, maxLayer, subDet);
150  }
151 
152 private:
153  void setPFRecHitPtrMap(const std::vector<reco::PFRecHit> &recHits);
154 
156  std::shared_ptr<hgcal::RecHitTools> recHitTools_;
157  std::shared_ptr<std::unordered_map<uint32_t, const reco::PFRecHit *> > pfRecHitPtrMap_;
158 };
159 
160 #endif
std::shared_ptr< std::unordered_map< uint32_t, const reco::PFRecHit * > > pfRecHitPtrMap_
std::vector< std::pair< DetId, float > > hitsAndFracs_
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
Definition: CaloCluster.h:210
std::shared_ptr< const hgcal::RecHitTools > recHitTools_
double getRvar(double cylinderR, bool useFractions=true, bool useCellSize=true) const
double rawEnergy() const
raw uncorrected energy (sum of energies of component BasicClusters)
Definition: SuperCluster.h:60
static const double kHDWaferCellSize_
ShowerShapeCalc(std::shared_ptr< const hgcal::RecHitTools > recHitTools, std::shared_ptr< const std::unordered_map< uint32_t, const reco::PFRecHit *> > pfRecHitPtrMap, const std::vector< std::pair< DetId, float > > &hitsAndFracs, const double rawEnergy, const double minHitE=0, const double minHitET=0, const int minLayer=1, const int maxLayer=-1, DetId::Detector subDet=DetId::HGCalEE)
void initPerSetup(const edm::EventSetup &iSetup)
void setFilteredHitsAndFractions(const std::vector< std::pair< DetId, float > > &hitsAndFracs)
void initPerEvent(const std::vector< reco::PFRecHit > &recHits)
static const double kLDWaferCellSize_
std::shared_ptr< const std::unordered_map< uint32_t, const reco::PFRecHit * > > pfRecHitPtrMap_
std::vector< double > getEnergyHighestHits(unsigned int nrHits, bool useFractions=true) const
HGCalShowerShapeHelper::ShowerShapeCalc createCalc(const reco::SuperCluster &sc, double minHitE=0, double minHitET=0, int minLayer=1, int maxLayer=-1, DetId::Detector subDet=DetId::HGCalEE) const
std::vector< ROOT::Math::XYZVector > layerCentroids_
std::shared_ptr< hgcal::RecHitTools > recHitTools_
Definition: DetId.h:17
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeometryToken_
Transform3DPJ::Vector XYZVector
Detector
Definition: DetId.h:24
HGCalShowerShapeHelper & operator=(const HGCalShowerShapeHelper &rhs)=delete
void setTokens(edm::ConsumesCollector consumesCollector)
void setPFRecHitPtrMap(const std::vector< reco::PFRecHit > &recHits)
~HGCalShowerShapeHelper()=default
ShowerWidths getPCAWidths(double cylinderR, bool useFractions=false) const
HGCalShowerShapeHelper::ShowerShapeCalc createCalc(const std::vector< std::pair< DetId, float > > &hitsAndFracs, double rawEnergy, double minHitE=0, double minHitET=0, int minLayer=1, int maxLayer=-1, DetId::Detector subDet=DetId::HGCalEE) const