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 <algorithm>
6 #include <cstdlib>
7 #include <iostream>
8 #include <map>
9 #include <memory>
10 #include <string>
11 #include <utility>
12 #include <vector>
13 
14 // external include files
15 #include <CLHEP/Vector/LorentzVector.h>
16 #include <Math/Point3D.h>
17 #include <Math/Point3Dfwd.h>
18 #include <TMatrixD.h>
19 #include <TVectorD.h>
20 
21 // CMSSW include files
46 
48  // Good to filter/compute/store this stuff beforehand as they are common to the shower shape variables.
49  // No point in filtering, computing layer-wise centroids, etc. for each variable again and again.
50  // Once intitialized, one can the calculate different variables one after another for a given object.
51  // This is all handled by ShowerShapeCalc class which caches the layer-wise centroids and other
52  // heavy variables for an object + set of cuts
53  // It was changed to this approach so that we could use this in constant functions
54 
55  // In principle should consider the HGCalHSi and HGCalHSc hits (leakage) also.
56  // Can have subdetector dependent thresholds and layer selection.
57  // To be implemented.
58 
59 public:
60  static const double kLDWaferCellSize_;
61  static const double kHDWaferCellSize_;
62 
63  struct ShowerWidths {
64  double sigma2xx;
65  double sigma2yy;
66  double sigma2zz;
67 
68  double sigma2xy;
69  double sigma2yz;
70  double sigma2zx;
71 
72  double sigma2uu;
73  double sigma2vv;
74  double sigma2ww;
75 
77  : sigma2xx(0.0),
78  sigma2yy(0.0),
79  sigma2zz(0.0),
80  sigma2xy(0.0),
81  sigma2yz(0.0),
82  sigma2zx(0.0),
83  sigma2uu(0.0),
84  sigma2vv(0.0),
85  sigma2ww(0.0) {}
86  };
87 
89  public:
90  ShowerShapeCalc(std::shared_ptr<const hgcal::RecHitTools> recHitTools,
91  std::shared_ptr<const std::unordered_map<uint32_t, const reco::PFRecHit *> > pfRecHitPtrMap,
92  const std::vector<std::pair<DetId, float> > &hitsAndFracs,
93  const double rawEnergy,
94  const double minHitE = 0,
95  const double minHitET = 0,
96  const int minLayer = 1,
97  const int maxLayer = -1,
99 
100  double getCellSize(DetId detId) const;
101 
102  // Compute Rvar in a cylinder around the layer centroids
103  double getRvar(double cylinderR, bool useFractions = true, bool useCellSize = true) const;
104 
105  // Compute PCA widths around the layer centroids
106  ShowerWidths getPCAWidths(double cylinderR, bool useFractions = false) const;
107 
108  std::vector<double> getEnergyHighestHits(unsigned int nrHits, bool useFractions = true) const;
109 
110  private:
111  void setFilteredHitsAndFractions(const std::vector<std::pair<DetId, float> > &hitsAndFracs);
112  void setLayerWiseInfo();
113 
114  std::shared_ptr<const hgcal::RecHitTools> recHitTools_;
115  std::shared_ptr<const std::unordered_map<uint32_t, const reco::PFRecHit *> > pfRecHitPtrMap_;
116  double rawEnergy_;
117 
118  double minHitE_;
119  double minHitET_;
120  double minHitET2_;
123  int nLayer_;
125 
126  std::vector<std::pair<DetId, float> > hitsAndFracs_;
127  std::vector<double> hitEnergies_;
128  std::vector<double> hitEnergiesWithFracs_;
129 
131  std::vector<double> layerEnergies_;
132  std::vector<ROOT::Math::XYZVector> layerCentroids_;
133  };
134 
137  ~HGCalShowerShapeHelper() = default;
138  HGCalShowerShapeHelper(const HGCalShowerShapeHelper &rhs) = delete;
139  HGCalShowerShapeHelper(const HGCalShowerShapeHelper &&rhs) = delete;
142 
143  template <edm::Transition tr = edm::Transition::Event>
144  void setTokens(edm::ConsumesCollector consumesCollector) {
145  caloGeometryToken_ = consumesCollector.esConsumes<CaloGeometry, CaloGeometryRecord, tr>();
146  }
147 
148  void initPerSetup(const edm::EventSetup &iSetup);
149  void initPerEvent(const std::vector<reco::PFRecHit> &recHits);
150  void initPerEvent(const edm::EventSetup &iSetup, const std::vector<reco::PFRecHit> &recHits);
151 
152  HGCalShowerShapeHelper::ShowerShapeCalc createCalc(const std::vector<std::pair<DetId, float> > &hitsAndFracs,
153  double rawEnergy,
154  double minHitE = 0,
155  double minHitET = 0,
156  int minLayer = 1,
157  int maxLayer = -1,
158  DetId::Detector subDet = DetId::HGCalEE) const;
160  double minHitE = 0,
161  double minHitET = 0,
162  int minLayer = 1,
163  int maxLayer = -1,
164  DetId::Detector subDet = DetId::HGCalEE) const {
165  return createCalc(sc.hitsAndFractions(), sc.rawEnergy(), minHitE, minHitET, minLayer, maxLayer, subDet);
166  }
167 
168 private:
169  void setPFRecHitPtrMap(const std::vector<reco::PFRecHit> &recHits);
170 
172  std::shared_ptr<hgcal::RecHitTools> recHitTools_;
173  std::shared_ptr<std::unordered_map<uint32_t, const reco::PFRecHit *> > pfRecHitPtrMap_;
174 };
175 
176 #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:159
HGCalShowerShapeHelper::ShowerShapeCalc::hitsAndFracs_
std::vector< std::pair< DetId, float > > hitsAndFracs_
Definition: HGCalShowerShapeHelper.h:126
HGCalShowerShapeHelper::HGCalShowerShapeHelper
HGCalShowerShapeHelper()
Definition: HGCalShowerShapeHelper.cc:289
HGCEEDetId.h
HGCalShowerShapeHelper::ShowerShapeCalc::minLayer_
int minLayer_
Definition: HGCalShowerShapeHelper.h:121
HGCalShowerShapeHelper::ShowerShapeCalc::recHitTools_
std::shared_ptr< const hgcal::RecHitTools > recHitTools_
Definition: HGCalShowerShapeHelper.h:114
HGCalShowerShapeHelper::ShowerShapeCalc::nLayer_
int nLayer_
Definition: HGCalShowerShapeHelper.h:123
HGCalShowerShapeHelper::recHitTools_
std::shared_ptr< hgcal::RecHitTools > recHitTools_
Definition: HGCalShowerShapeHelper.h:172
InitialClusteringStepBase.h
ESHandle.h
HGCalShowerShapeHelper::ShowerWidths::sigma2yy
double sigma2yy
Definition: HGCalShowerShapeHelper.h:65
reco::SuperCluster
Definition: SuperCluster.h:18
CaloGeometryRecord
Definition: CaloGeometryRecord.h:30
HGCalShowerShapeHelper::ShowerShapeCalc
Definition: HGCalShowerShapeHelper.h:88
HGCalShowerShapeHelper::ShowerShapeCalc::getRvar
double getRvar(double cylinderR, bool useFractions=true, bool useCellSize=true) const
Definition: HGCalShowerShapeHelper.cc:35
RecHitTools.h
HGCalShowerShapeHelper::ShowerWidths::sigma2uu
double sigma2uu
Definition: HGCalShowerShapeHelper.h:72
HGCalShowerShapeHelper::ShowerShapeCalc::subDet_
DetId::Detector subDet_
Definition: HGCalShowerShapeHelper.h:124
EDProducer.h
HGCalShowerShapeHelper::caloGeometryToken_
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeometryToken_
Definition: HGCalShowerShapeHelper.h:171
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:144
PFRecHit.h
HGCalShowerShapeHelper::ShowerShapeCalc::hitEnergies_
std::vector< double > hitEnergies_
Definition: HGCalShowerShapeHelper.h:127
HGCalShowerShapeHelper::setPFRecHitPtrMap
void setPFRecHitPtrMap(const std::vector< reco::PFRecHit > &recHits)
Definition: HGCalShowerShapeHelper.cc:324
DetId
Definition: DetId.h:17
DetId::HGCalEE
Definition: DetId.h:32
MakerMacros.h
CaloGeometry
Definition: CaloGeometry.h:21
Track.h
TrackFwd.h
HGCRecHit.h
HGCalTopology.h
HGCalShowerShapeHelper::ShowerShapeCalc::setFilteredHitsAndFractions
void setFilteredHitsAndFractions(const std::vector< std::pair< DetId, float > > &hitsAndFracs)
Definition: HGCalShowerShapeHelper.cc:201
HGCalShowerShapeHelper::ShowerShapeCalc::minHitE_
double minHitE_
Definition: HGCalShowerShapeHelper.h:118
HGCalShowerShapeHelper::ShowerWidths::sigma2vv
double sigma2vv
Definition: HGCalShowerShapeHelper.h:73
HGCalShowerShapeHelper::ShowerShapeCalc::minHitET_
double minHitET_
Definition: HGCalShowerShapeHelper.h:119
HGCalShowerShapeHelper::ShowerWidths::ShowerWidths
ShowerWidths()
Definition: HGCalShowerShapeHelper.h:76
HGCalShowerShapeHelper::ShowerShapeCalc::pfRecHitPtrMap_
std::shared_ptr< const std::unordered_map< uint32_t, const reco::PFRecHit * > > pfRecHitPtrMap_
Definition: HGCalShowerShapeHelper.h:115
HGCalShowerShapeHelper::~HGCalShowerShapeHelper
~HGCalShowerShapeHelper()=default
HGCalShowerShapeHelper::ShowerWidths::sigma2zz
double sigma2zz
Definition: HGCalShowerShapeHelper.h:66
HGCalShowerShapeHelper::ShowerShapeCalc::getEnergyHighestHits
std::vector< double > getEnergyHighestHits(unsigned int nrHits, bool useFractions=true) const
Definition: HGCalShowerShapeHelper.cc:192
Transition.h
HGCalShowerShapeHelper::ShowerWidths
Definition: HGCalShowerShapeHelper.h:63
GsfElectron.h
HGCalShowerShapeHelper::ShowerWidths::sigma2yz
double sigma2yz
Definition: HGCalShowerShapeHelper.h:69
HGCalShowerShapeHelper::pfRecHitPtrMap_
std::shared_ptr< std::unordered_map< uint32_t, const reco::PFRecHit * > > pfRecHitPtrMap_
Definition: HGCalShowerShapeHelper.h:173
HGCalShowerShapeHelper::ShowerShapeCalc::layerCentroids_
std::vector< ROOT::Math::XYZVector > layerCentroids_
Definition: HGCalShowerShapeHelper.h:132
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:52990
LorentzVector.h
HGCalShowerShapeHelper::ShowerWidths::sigma2xy
double sigma2xy
Definition: HGCalShowerShapeHelper.h:68
GsfTrack.h
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:130
HGCalShowerShapeHelper::ShowerShapeCalc::maxLayer_
int maxLayer_
Definition: HGCalShowerShapeHelper.h:122
edm::ESGetToken< CaloGeometry, CaloGeometryRecord >
HGCalShowerShapeHelper::ShowerWidths::sigma2ww
double sigma2ww
Definition: HGCalShowerShapeHelper.h:74
PFRecHitFraction.h
HGCalDetId.h
Frameworkfwd.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:6
reco::SuperCluster::rawEnergy
double rawEnergy() const
raw uncorrected energy (sum of energies of component BasicClusters)
Definition: SuperCluster.h:58
HGCalShowerShapeHelper::ShowerShapeCalc::rawEnergy_
double rawEnergy_
Definition: HGCalShowerShapeHelper.h:116
HGCalShowerShapeHelper::kHDWaferCellSize_
static const double kHDWaferCellSize_
Definition: HGCalShowerShapeHelper.h:61
ESHandle.h
ROOT::Math::XYZVector
Transform3DPJ::Vector XYZVector
Definition: Transform3DPJ.cc:34
HGCalShowerShapeHelper::ShowerShapeCalc::getCellSize
double getCellSize(DetId detId) const
Definition: HGCalShowerShapeHelper.cc:31
ParameterSet.h
HGCalShowerShapeHelper::ShowerShapeCalc::layerEnergies_
std::vector< double > layerEnergies_
Definition: HGCalShowerShapeHelper.h:131
HGCalShowerShapeHelper::ShowerWidths::sigma2zx
double sigma2zx
Definition: HGCalShowerShapeHelper.h:70
HGCalShowerShapeHelper::ShowerWidths::sigma2xx
double sigma2xx
Definition: HGCalShowerShapeHelper.h:64
HGCalShowerShapeHelper::ShowerShapeCalc::minHitET2_
double minHitET2_
Definition: HGCalShowerShapeHelper.h:120
HGCalShowerShapeHelper::initPerEvent
void initPerEvent(const std::vector< reco::PFRecHit > &recHits)
Definition: HGCalShowerShapeHelper.cc:303
HGCalShowerShapeHelper::ShowerShapeCalc::setLayerWiseInfo
void setLayerWiseInfo()
Definition: HGCalShowerShapeHelper.cc:242
HGCalShowerShapeHelper::kLDWaferCellSize_
static const double kLDWaferCellSize_
Definition: HGCalShowerShapeHelper.h:60
HGCalShowerShapeHelper
Definition: HGCalShowerShapeHelper.h:47
StreamID.h
HGCalShowerShapeHelper::ShowerShapeCalc::getPCAWidths
ShowerWidths getPCAWidths(double cylinderR, bool useFractions=false) const
Definition: HGCalShowerShapeHelper.cc:86
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
HGCalShowerShapeHelper::ShowerShapeCalc::hitEnergiesWithFracs_
std::vector< double > hitEnergiesWithFracs_
Definition: HGCalShowerShapeHelper.h:128
CaloCluster.h
HGCalShowerShapeHelper::initPerSetup
void initPerSetup(const edm::EventSetup &iSetup)
Definition: HGCalShowerShapeHelper.cc:299