CMS 3D CMS Logo

ElectronDNNEstimator.cc
Go to the documentation of this file.
5 
6 #include <iostream>
7 #include <fstream>
8 #include <memory>
9 
10 using namespace std::placeholders;
11 
13  const std::map<std::string, float>& vars, float ptThr, float etaThr, float endcapBoundary, float extEtaBoundary) {
14  /*
15  Selection of the model to be applied on the electron based on pt/eta cuts or whatever selection
16  */
17  const auto pt = vars.at("pt");
18  const auto absEta = std::abs(vars.at("superCluster.eta"));
19  if (absEta <= endcapBoundary) {
20  if (pt < ptThr)
21  return 0;
22  else {
23  if (absEta <= etaThr) {
24  return 1;
25  } else {
26  return 2;
27  }
28  }
29  } else {
30  if (absEta < extEtaBoundary)
31  return 3;
32  else {
33  return 4;
34  }
35  }
36 }
37 
39  : dnnHelper_(cfg,
41  _1,
43  (useEBModelInGap) ? ElectronDNNEstimator::ecalBarrelMaxEtaWithGap
44  : ElectronDNNEstimator::ecalBarrelMaxEtaNoGap,
45  ElectronDNNEstimator::endcapBoundary,
46  ElectronDNNEstimator::extEtaBoundary),
47  ElectronDNNEstimator::dnnAvaibleInputs),
48  useEBModelInGap_(useEBModelInGap) {}
49 
50 std::vector<tensorflow::Session*> ElectronDNNEstimator::getSessions() const { return dnnHelper_.getSessions(); };
51 
52 const std::vector<std::string> ElectronDNNEstimator::dnnAvaibleInputs = {
53  {"pt",
54  "eta",
55  "fbrem",
56  "abs(deltaEtaSuperClusterTrackAtVtx)",
57  "abs(deltaPhiSuperClusterTrackAtVtx)",
58  "full5x5_sigmaIetaIeta",
59  "full5x5_hcalOverEcal",
60  "eSuperClusterOverP",
61  "full5x5_e1x5",
62  "eEleClusterOverPout",
63  "closestCtfTrackNormChi2",
64  "closestCtfTrackNLayers",
65  "gsfTrack.missing_inner_hits",
66  "dr03TkSumPt",
67  "dr03EcalRecHitSumEt",
68  "dr03HcalTowerSumEt",
69  "gsfTrack.normalizedChi2",
70  "superCluster.eta",
71  "ecalPFClusterIso",
72  "hcalPFClusterIso",
73  "numberOfBrems",
74  "abs(deltaEtaSeedClusterTrackAtCalo)",
75  "hadronicOverEm",
76  "full5x5_e2x5Max",
77  "full5x5_e5x5",
78  "full5x5_sigmaIphiIphi",
79  "1_minus_full5x5_e1x5_ratio_full5x5_e5x5",
80  "full5x5_e1x5_ratio_full5x5_e5x5",
81  "full5x5_r9",
82  "gsfTrack.trackerLayersWithMeasurement",
83  "gsfTrack.numberOfValidPixelBarrelHits",
84  "gsfTrack.numberOfValidPixelEndcapHits",
85  "superCluster.energy",
86  "superCluster.rawEnergy",
87  "superClusterFbrem",
88  "1_ratio_ecalEnergy_minus_1_ratio_trackMomentumAtVtx.R",
89  "superCluster.preshowerEnergy_ratio_superCluster.rawEnergy",
90  "convVtxFitProb",
91  "superCluster.clustersSize",
92  "ecalEnergyError_ratio_ecalEnergy",
93  "superClusterFbrem_plus_superCluster.energy",
94  "superClusterFbrem_plus_superCluster.rawEnergy",
95  "trackMomentumError",
96  "trackMomentumError_ratio_pt",
97  "full5x5_e5x5_ratio_superCluster.rawEnergy",
98  "full5x5_e5x5_ratio_superCluster.energy"}};
99 
100 std::map<std::string, float> ElectronDNNEstimator::getInputsVars(const reco::GsfElectron& ele) const {
101  // Prepare a map with all the defined variables
102  std::map<std::string, float> variables;
103  variables["pt"] = ele.pt();
104  variables["eta"] = ele.eta();
105  variables["fbrem"] = ele.fbrem();
106  variables["abs(deltaEtaSuperClusterTrackAtVtx)"] = std::abs(ele.deltaEtaSuperClusterTrackAtVtx());
107  variables["abs(deltaPhiSuperClusterTrackAtVtx)"] = std::abs(ele.deltaPhiSuperClusterTrackAtVtx());
108  variables["full5x5_sigmaIetaIeta"] = ele.full5x5_sigmaIetaIeta();
109  variables["full5x5_hcalOverEcal"] = ele.full5x5_hcalOverEcalValid() ? ele.full5x5_hcalOverEcal() : 0;
110  variables["eSuperClusterOverP"] = ele.eSuperClusterOverP();
111  variables["full5x5_e1x5"] = ele.full5x5_e1x5();
112  variables["eEleClusterOverPout"] = ele.eEleClusterOverPout();
113  variables["closestCtfTrackNormChi2"] = ele.closestCtfTrackNormChi2();
114  variables["closestCtfTrackNLayers"] = ele.closestCtfTrackNLayers();
115  variables["gsfTrack.missing_inner_hits"] =
116  ele.gsfTrack()->hitPattern().numberOfLostHits(reco::HitPattern::MISSING_INNER_HITS);
117  variables["dr03TkSumPt"] = ele.dr03TkSumPt();
118  variables["dr03EcalRecHitSumEt"] = ele.dr03EcalRecHitSumEt();
119  variables["dr03HcalTowerSumEt"] = ele.dr03HcalTowerSumEt();
120  variables["gsfTrack.normalizedChi2"] = ele.gsfTrack()->normalizedChi2();
121  variables["superCluster.eta"] = ele.superCluster()->eta();
122  variables["ecalPFClusterIso"] = ele.ecalPFClusterIso();
123  variables["hcalPFClusterIso"] = ele.hcalPFClusterIso();
124  variables["numberOfBrems"] = ele.numberOfBrems();
125  variables["abs(deltaEtaSeedClusterTrackAtCalo)"] = std::abs(ele.deltaEtaSeedClusterTrackAtCalo());
126  variables["hadronicOverEm"] = ele.hcalOverEcalValid() ? ele.hadronicOverEm() : 0;
127  variables["full5x5_e2x5Max"] = ele.full5x5_e2x5Max();
128  variables["full5x5_e5x5"] = ele.full5x5_e5x5();
129 
130  variables["full5x5_sigmaIphiIphi"] = ele.full5x5_sigmaIphiIphi();
131  variables["1_minus_full5x5_e1x5_ratio_full5x5_e5x5"] = 1 - ele.full5x5_e1x5() / ele.full5x5_e5x5();
132  variables["full5x5_e1x5_ratio_full5x5_e5x5"] = ele.full5x5_e1x5() / ele.full5x5_e5x5();
133  variables["full5x5_r9"] = ele.full5x5_r9();
134  variables["gsfTrack.trackerLayersWithMeasurement"] = ele.gsfTrack()->hitPattern().trackerLayersWithMeasurement();
135  variables["gsfTrack.numberOfValidPixelBarrelHits"] = ele.gsfTrack()->hitPattern().numberOfValidPixelBarrelHits();
136  variables["gsfTrack.numberOfValidPixelEndcapHits"] = ele.gsfTrack()->hitPattern().numberOfValidPixelEndcapHits();
137  variables["superCluster.energy"] = ele.superCluster()->energy();
138  variables["superCluster.rawEnergy"] = ele.superCluster()->rawEnergy();
139  variables["superClusterFbrem"] = ele.superClusterFbrem();
140  variables["1_ratio_ecalEnergy_minus_1_ratio_trackMomentumAtVtx.R"] =
141  1 / ele.ecalEnergy() - 1 / ele.trackMomentumAtVtx().R();
142  variables["superCluster.preshowerEnergy_ratio_superCluster.rawEnergy"] =
143  ele.superCluster()->preshowerEnergy() / ele.superCluster()->rawEnergy();
144  variables["convVtxFitProb"] = ele.convVtxFitProb();
145  variables["superCluster.clustersSize"] = ele.superCluster()->clustersSize();
146  variables["ecalEnergyError_ratio_ecalEnergy"] = ele.ecalEnergyError() / ele.ecalEnergy();
147  variables["superClusterFbrem_plus_superCluster.energy"] = ele.superClusterFbrem() + ele.superCluster()->energy();
148  variables["superClusterFbrem_plus_superCluster.rawEnergy"] =
149  ele.superClusterFbrem() + ele.superCluster()->rawEnergy();
150  variables["trackMomentumError"] = ele.trackMomentumError();
151  variables["trackMomentumError_ratio_pt"] = ele.trackMomentumError() / ele.pt();
152  variables["full5x5_e5x5_ratio_superCluster.rawEnergy"] = ele.full5x5_e5x5() / ele.superCluster()->rawEnergy();
153  variables["full5x5_e5x5_ratio_superCluster.energy"] = ele.full5x5_e5x5() / ele.superCluster()->energy();
154 
155  // Define more variables here and use them directly in the model config!
156  return variables;
157 }
158 
159 std::vector<std::pair<uint, std::vector<float>>> ElectronDNNEstimator::evaluate(
160  const reco::GsfElectronCollection& electrons, const std::vector<tensorflow::Session*>& sessions) const {
161  // Collect the map of variables for each candidate and call the dnnHelper
162  // Scaling, model selection and running is performed in the helper
163  std::vector<std::map<std::string, float>> inputs;
164  for (const auto& ele : electrons) {
165  inputs.push_back(getInputsVars(ele));
166  }
167  return dnnHelper_.evaluate(inputs, sessions);
168 }
bool full5x5_hcalOverEcalValid() const
Definition: GsfElectron.h:479
ElectronDNNEstimator(const egammaTools::DNNConfiguration &, const bool useEBModelInGap)
float full5x5_e2x5Max() const
Definition: GsfElectron.h:474
std::map< std::string, float > getInputsVars(const reco::GsfElectron &ele) const
std::vector< tensorflow::Session * > getSessions() const
double pt() const final
transverse momentum
std::vector< tensorflow::Session * > getSessions() const
float full5x5_e1x5() const
Definition: GsfElectron.h:473
vars
Definition: DeepTauIdBase.h:60
float trackMomentumError() const
Definition: GsfElectron.h:884
float full5x5_sigmaIphiIphi() const
Definition: GsfElectron.h:472
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
float eSuperClusterOverP() const
Definition: GsfElectron.h:221
float full5x5_e5x5() const
Definition: GsfElectron.h:475
float eEleClusterOverPout() const
Definition: GsfElectron.h:224
std::vector< std::pair< uint, std::vector< float > > > evaluate(const reco::GsfElectronCollection &ele, const std::vector< tensorflow::Session *> &sessions) const
float dr03TkSumPt() const
Definition: GsfElectron.h:557
GsfTrackRef gsfTrack() const override
reference to a GsfTrack
Definition: GsfElectron.h:156
static const std::vector< std::string > dnnAvaibleInputs
float ecalPFClusterIso() const
Definition: GsfElectron.h:731
float closestCtfTrackNormChi2() const
Definition: GsfElectron.h:165
int numberOfBrems() const
Definition: GsfElectron.h:808
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
math::XYZVectorF trackMomentumAtVtx() const
Definition: GsfElectron.h:268
float convVtxFitProb() const
Definition: GsfElectron.h:648
float deltaPhiSuperClusterTrackAtVtx() const
Definition: GsfElectron.h:228
float superClusterFbrem() const
Definition: GsfElectron.h:803
int closestCtfTrackNLayers() const
Definition: GsfElectron.h:168
float deltaEtaSuperClusterTrackAtVtx() const
Definition: GsfElectron.h:225
float ecalEnergy() const
Definition: GsfElectron.h:896
float ecalEnergyError() const
Definition: GsfElectron.h:897
float hcalPFClusterIso() const
Definition: GsfElectron.h:732
float fbrem() const
Definition: GsfElectron.h:809
float full5x5_hcalOverEcal(int depth=0) const
Definition: GsfElectron.h:477
float dr03EcalRecHitSumEt() const
Definition: GsfElectron.h:559
std::vector< std::pair< uint, std::vector< float > > > evaluate(const std::vector< std::map< std::string, float >> &candidates, const std::vector< tensorflow::Session *> &sessions) const
float full5x5_r9() const
Definition: GsfElectron.h:476
const egammaTools::EgammaDNNHelper dnnHelper_
float deltaEtaSeedClusterTrackAtCalo() const
Definition: GsfElectron.h:226
float full5x5_sigmaIetaIeta() const
Definition: GsfElectron.h:471
float dr03HcalTowerSumEt(int depth=0) const
Definition: GsfElectron.h:576
uint electronModelSelector(const std::map< std::string, float > &vars, float ptThr, float etaThr, float endcapBoundary, float extEtaBoundary)
float hadronicOverEm() const
Definition: GsfElectron.h:500
SuperClusterRef superCluster() const override
reference to a SuperCluster
Definition: GsfElectron.h:155
bool hcalOverEcalValid() const
Definition: GsfElectron.h:462
double eta() const final
momentum pseudorapidity