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
HGCalShowerShapeHelper::createCalc
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
Definition: HGCalShowerShapeHelper.h:143
HGCalShowerShapeHelper::ShowerShapeCalc::hitsAndFracs_
std::vector< std::pair< DetId, float > > hitsAndFracs_
Definition: HGCalShowerShapeHelper.h:110
HGCalShowerShapeHelper::HGCalShowerShapeHelper
HGCalShowerShapeHelper()
Definition: HGCalShowerShapeHelper.cc:295
HGCEEDetId.h
HGCalShowerShapeHelper::ShowerShapeCalc::minLayer_
int minLayer_
Definition: HGCalShowerShapeHelper.h:105
HGCalShowerShapeHelper::ShowerShapeCalc::recHitTools_
std::shared_ptr< const hgcal::RecHitTools > recHitTools_
Definition: HGCalShowerShapeHelper.h:98
HGCalShowerShapeHelper::ShowerShapeCalc::nLayer_
int nLayer_
Definition: HGCalShowerShapeHelper.h:107
HGCalShowerShapeHelper::recHitTools_
std::shared_ptr< hgcal::RecHitTools > recHitTools_
Definition: HGCalShowerShapeHelper.h:156
HGCalShowerShapeHelper::ShowerWidths::sigma2yy
double sigma2yy
Definition: HGCalShowerShapeHelper.h:49
reco::SuperCluster
Definition: SuperCluster.h:18
CaloGeometryRecord
Definition: CaloGeometryRecord.h:30
HGCalShowerShapeHelper::ShowerShapeCalc
Definition: HGCalShowerShapeHelper.h:72
HGCalShowerShapeHelper::ShowerShapeCalc::getRvar
double getRvar(double cylinderR, bool useFractions=true, bool useCellSize=true) const
Definition: HGCalShowerShapeHelper.cc:41
RecHitTools.h
HGCalShowerShapeHelper::ShowerWidths::sigma2uu
double sigma2uu
Definition: HGCalShowerShapeHelper.h:56
HGCalShowerShapeHelper::ShowerShapeCalc::subDet_
DetId::Detector subDet_
Definition: HGCalShowerShapeHelper.h:108
EDProducer.h
HGCalShowerShapeHelper::caloGeometryToken_
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeometryToken_
Definition: HGCalShowerShapeHelper.h:155
HGCalShowerShapeHelper::operator=
HGCalShowerShapeHelper & operator=(const HGCalShowerShapeHelper &rhs)=delete
edm::ConsumesCollector::esConsumes
auto esConsumes()
Definition: ConsumesCollector.h:97
HGCalShowerShapeHelper::setTokens
void setTokens(edm::ConsumesCollector consumesCollector)
Definition: HGCalShowerShapeHelper.h:128
PFRecHit.h
HGCalShowerShapeHelper::ShowerShapeCalc::hitEnergies_
std::vector< double > hitEnergies_
Definition: HGCalShowerShapeHelper.h:111
HGCalShowerShapeHelper::setPFRecHitPtrMap
void setPFRecHitPtrMap(const std::vector< reco::PFRecHit > &recHits)
Definition: HGCalShowerShapeHelper.cc:330
DetId
Definition: DetId.h:17
DetId::HGCalEE
Definition: DetId.h:32
MakerMacros.h
CaloGeometry
Definition: CaloGeometry.h:21
HGCRecHit.h
HGCalTopology.h
HGCalShowerShapeHelper::ShowerShapeCalc::setFilteredHitsAndFractions
void setFilteredHitsAndFractions(const std::vector< std::pair< DetId, float > > &hitsAndFracs)
Definition: HGCalShowerShapeHelper.cc:207
HGCalShowerShapeHelper::ShowerShapeCalc::minHitE_
double minHitE_
Definition: HGCalShowerShapeHelper.h:102
HGCalShowerShapeHelper::ShowerWidths::sigma2vv
double sigma2vv
Definition: HGCalShowerShapeHelper.h:57
HGCalShowerShapeHelper::ShowerShapeCalc::minHitET_
double minHitET_
Definition: HGCalShowerShapeHelper.h:103
HGCalShowerShapeHelper::ShowerWidths::ShowerWidths
ShowerWidths()
Definition: HGCalShowerShapeHelper.h:60
HGCalShowerShapeHelper::ShowerShapeCalc::pfRecHitPtrMap_
std::shared_ptr< const std::unordered_map< uint32_t, const reco::PFRecHit * > > pfRecHitPtrMap_
Definition: HGCalShowerShapeHelper.h:99
HGCalShowerShapeHelper::~HGCalShowerShapeHelper
~HGCalShowerShapeHelper()=default
HGCalShowerShapeHelper::ShowerWidths::sigma2zz
double sigma2zz
Definition: HGCalShowerShapeHelper.h:50
HGCalShowerShapeHelper::ShowerShapeCalc::getEnergyHighestHits
std::vector< double > getEnergyHighestHits(unsigned int nrHits, bool useFractions=true) const
Definition: HGCalShowerShapeHelper.cc:198
Transition.h
HGCalShowerShapeHelper::ShowerWidths
Definition: HGCalShowerShapeHelper.h:47
HGCalShowerShapeHelper::ShowerWidths::sigma2yz
double sigma2yz
Definition: HGCalShowerShapeHelper.h:53
HGCalShowerShapeHelper::pfRecHitPtrMap_
std::shared_ptr< std::unordered_map< uint32_t, const reco::PFRecHit * > > pfRecHitPtrMap_
Definition: HGCalShowerShapeHelper.h:157
HGCalShowerShapeHelper::ShowerShapeCalc::layerCentroids_
std::vector< ROOT::Math::XYZVector > layerCentroids_
Definition: HGCalShowerShapeHelper.h:116
FastTrackerRecHitMaskProducer_cfi.recHits
recHits
Definition: FastTrackerRecHitMaskProducer_cfi.py:8
HGCalShowerShapeHelper::createCalc
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
Event.h
reco::CaloCluster::hitsAndFractions
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
Definition: CaloCluster.h:210
HLT_FULL_cff.minLayer
minLayer
Definition: HLT_FULL_cff.py:53000
HGCalShowerShapeHelper::ShowerWidths::sigma2xy
double sigma2xy
Definition: HGCalShowerShapeHelper.h:52
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
IdealGeometryRecord.h
DetId::Detector
Detector
Definition: DetId.h:24
edm::EventSetup
Definition: EventSetup.h:58
HGCalShowerShapeHelper::ShowerShapeCalc::centroid_
ROOT::Math::XYZVector centroid_
Definition: HGCalShowerShapeHelper.h:114
HGCalShowerShapeHelper::ShowerShapeCalc::maxLayer_
int maxLayer_
Definition: HGCalShowerShapeHelper.h:106
edm::ESGetToken< CaloGeometry, CaloGeometryRecord >
HGCalShowerShapeHelper::ShowerWidths::sigma2ww
double sigma2ww
Definition: HGCalShowerShapeHelper.h:58
PFRecHitFraction.h
HGCalDetId.h
HGCalShowerShapeHelper::ShowerShapeCalc::ShowerShapeCalc
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)
Definition: HGCalShowerShapeHelper.cc:12
reco::SuperCluster::rawEnergy
double rawEnergy() const
raw uncorrected energy (sum of energies of component BasicClusters)
Definition: SuperCluster.h:58
SuperCluster.h
HGCalShowerShapeHelper::ShowerShapeCalc::rawEnergy_
double rawEnergy_
Definition: HGCalShowerShapeHelper.h:100
HGCalShowerShapeHelper::kHDWaferCellSize_
static const double kHDWaferCellSize_
Definition: HGCalShowerShapeHelper.h:45
ROOT::Math::XYZVector
Transform3DPJ::Vector XYZVector
Definition: Transform3DPJ.cc:34
HGCalShowerShapeHelper::ShowerShapeCalc::getCellSize
double getCellSize(DetId detId) const
Definition: HGCalShowerShapeHelper.cc:37
ConsumesCollector.h
ParameterSet.h
HGCalShowerShapeHelper::ShowerShapeCalc::layerEnergies_
std::vector< double > layerEnergies_
Definition: HGCalShowerShapeHelper.h:115
HGCalShowerShapeHelper::ShowerWidths::sigma2zx
double sigma2zx
Definition: HGCalShowerShapeHelper.h:54
HGCalShowerShapeHelper::ShowerWidths::sigma2xx
double sigma2xx
Definition: HGCalShowerShapeHelper.h:48
HGCalShowerShapeHelper::ShowerShapeCalc::minHitET2_
double minHitET2_
Definition: HGCalShowerShapeHelper.h:104
HGCalShowerShapeHelper::initPerEvent
void initPerEvent(const std::vector< reco::PFRecHit > &recHits)
Definition: HGCalShowerShapeHelper.cc:309
HGCalShowerShapeHelper::ShowerShapeCalc::setLayerWiseInfo
void setLayerWiseInfo()
Definition: HGCalShowerShapeHelper.cc:248
HGCalShowerShapeHelper::kLDWaferCellSize_
static const double kLDWaferCellSize_
Definition: HGCalShowerShapeHelper.h:44
HGCalShowerShapeHelper
Definition: HGCalShowerShapeHelper.h:31
StreamID.h
HGCalShowerShapeHelper::ShowerShapeCalc::getPCAWidths
ShowerWidths getPCAWidths(double cylinderR, bool useFractions=false) const
Definition: HGCalShowerShapeHelper.cc:92
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
HGCalShowerShapeHelper::ShowerShapeCalc::hitEnergiesWithFracs_
std::vector< double > hitEnergiesWithFracs_
Definition: HGCalShowerShapeHelper.h:112
HGCalShowerShapeHelper::initPerSetup
void initPerSetup(const edm::EventSetup &iSetup)
Definition: HGCalShowerShapeHelper.cc:305