CMS 3D CMS Logo

LowPtGsfElectronIDProducer.cc
Go to the documentation of this file.
15 
16 #include <string>
17 #include <vector>
18 
19 namespace {
20 
21  std::vector<float> getFeatures(reco::GsfElectronRef const& ele, float rho) {
22  // KF track
23  float trk_p = -1.;
24  float trk_nhits = -1.;
25  float trk_chi2red = -1.;
26  // GSF track
27  float gsf_nhits = -1.;
28  float gsf_chi2red = -1.;
29  // SC
30  float sc_E = -1.;
31  float sc_eta = -1.;
32  float sc_etaWidth = -1.;
33  float sc_phiWidth = -1.;
34  // Track-cluster matching
35  float match_seed_dEta = -1.;
36  float match_eclu_EoverP = -1.;
37  float match_SC_EoverP = -1.;
38  float match_SC_dEta = -1.;
39  float match_SC_dPhi = -1.;
40  // Shower shape vars
41  float shape_full5x5_sigmaIetaIeta = -1.;
42  float shape_full5x5_sigmaIphiIphi = -1.;
43  float shape_full5x5_HoverE = -1.;
44  float shape_full5x5_r9 = -1.;
45  float shape_full5x5_circularity = -1.;
46  // Misc
47  float brem_frac = -1.;
48  float ele_pt = -1.;
49 
50  // KF tracks
51  if (ele->core().isNonnull()) {
52  reco::TrackRef trk = ele->core()->ctfTrack(); //@@ is this what we want?!
53  if (trk.isNonnull()) {
54  trk_p = float(trk->p());
55  trk_nhits = float(trk->found());
56  trk_chi2red = float(trk->normalizedChi2());
57  }
58  }
59 
60  // GSF tracks
61  if (ele->core().isNonnull()) {
62  reco::GsfTrackRef gsf = ele->core()->gsfTrack();
63  if (gsf.isNonnull()) {
64  gsf_nhits = gsf->found();
65  gsf_chi2red = gsf->normalizedChi2();
66  }
67  }
68 
69  // Super clusters
70  if (ele->core().isNonnull()) {
71  reco::SuperClusterRef sc = ele->core()->superCluster();
72  if (sc.isNonnull()) {
73  sc_E = sc->energy();
74  sc_eta = sc->eta();
75  sc_etaWidth = sc->etaWidth();
76  sc_phiWidth = sc->phiWidth();
77  }
78  }
79 
80  // Track-cluster matching
81  if (ele.isNonnull()) {
82  match_seed_dEta = ele->deltaEtaSeedClusterTrackAtCalo();
83  match_eclu_EoverP = (1. / ele->ecalEnergy()) - (1. / ele->p());
84  match_SC_EoverP = ele->eSuperClusterOverP();
85  match_SC_dEta = ele->deltaEtaSuperClusterTrackAtVtx();
86  match_SC_dPhi = ele->deltaPhiSuperClusterTrackAtVtx();
87  }
88 
89  // Shower shape vars
90  if (ele.isNonnull()) {
91  shape_full5x5_sigmaIetaIeta = ele->full5x5_sigmaIetaIeta();
92  shape_full5x5_sigmaIphiIphi = ele->full5x5_sigmaIphiIphi();
93  shape_full5x5_HoverE = ele->full5x5_hcalOverEcal();
94  shape_full5x5_r9 = ele->full5x5_r9();
95  shape_full5x5_circularity = 1. - ele->full5x5_e1x5() / ele->full5x5_e5x5();
96  }
97 
98  // Misc
99  if (ele.isNonnull()) {
100  brem_frac = ele->fbrem();
101  ele_pt = ele->pt();
102  }
103 
104  return {
105  rho,
106  ele_pt,
107  sc_eta,
108  shape_full5x5_sigmaIetaIeta,
109  shape_full5x5_sigmaIphiIphi,
110  shape_full5x5_circularity,
111  shape_full5x5_r9,
112  sc_etaWidth,
113  sc_phiWidth,
114  shape_full5x5_HoverE,
115  trk_nhits,
116  trk_chi2red,
117  gsf_chi2red,
118  brem_frac,
119  gsf_nhits,
120  match_SC_EoverP,
121  match_eclu_EoverP,
122  match_SC_dEta,
123  match_SC_dPhi,
124  match_seed_dEta,
125  sc_E,
126  trk_p,
127  };
128  }
129 
130 } // namespace
131 
133 public:
135 
136  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
137 
139 
140 private:
141  double eval(const std::string& name, const reco::GsfElectronRef&, double rho) const;
142 
145  const std::vector<std::string> names_;
146  const bool passThrough_;
147  const double minPtThreshold_;
148  const double maxPtThreshold_;
149  std::vector<std::unique_ptr<const GBRForest> > models_;
150  const std::vector<double> thresholds_;
151 };
152 
154 //
156  : gsfElectrons_(consumes<reco::GsfElectronCollection>(conf.getParameter<edm::InputTag>("electrons"))),
157  rho_(consumes<double>(conf.getParameter<edm::InputTag>("rho"))),
158  names_(conf.getParameter<std::vector<std::string> >("ModelNames")),
159  passThrough_(conf.getParameter<bool>("PassThrough")),
160  minPtThreshold_(conf.getParameter<double>("MinPtThreshold")),
161  maxPtThreshold_(conf.getParameter<double>("MaxPtThreshold")),
162  thresholds_(conf.getParameter<std::vector<double> >("ModelThresholds")) {
163  for (auto& weights : conf.getParameter<std::vector<std::string> >("ModelWeights")) {
165  }
166  if (names_.size() != models_.size()) {
167  throw cms::Exception("Incorrect configuration")
168  << "'ModelNames' size (" << names_.size() << ") != 'ModelWeights' size (" << models_.size() << ").\n";
169  }
170  if (models_.size() != thresholds_.size()) {
171  throw cms::Exception("Incorrect configuration")
172  << "'ModelWeights' size (" << models_.size() << ") != 'ModelThresholds' size (" << thresholds_.size() << ").\n";
173  }
174  for (const auto& name : names_) {
175  produces<edm::ValueMap<float> >(name);
176  }
177 }
178 
180 //
182  // Pileup
184  event.getByToken(rho_, rho);
185  if (!rho.isValid()) {
186  edm::LogError("Problem with rho handle");
187  }
188 
189  // Retrieve GsfElectrons from Event
191  event.getByToken(gsfElectrons_, gsfElectrons);
192  if (!gsfElectrons.isValid()) {
193  edm::LogError("Problem with gsfElectrons handle");
194  }
195 
196  // Iterate through Electrons, evaluate BDT, and store result
197  std::vector<std::vector<float> > output;
198  for (unsigned int iname = 0; iname < names_.size(); ++iname) {
199  output.emplace_back(gsfElectrons->size(), -999.);
200  }
201  for (unsigned int iele = 0; iele < gsfElectrons->size(); iele++) {
203  //if ( !passThrough_ && ( ele->pt() < minPtThreshold_ ) ) { continue; }
204  for (unsigned int iname = 0; iname < names_.size(); ++iname) {
205  output[iname][iele] = eval(names_[iname], ele, *rho);
206  }
207  }
208 
209  // Create and put ValueMap in Event
210  for (unsigned int iname = 0; iname < names_.size(); ++iname) {
211  auto ptr = std::make_unique<edm::ValueMap<float> >(edm::ValueMap<float>());
213  filler.insert(gsfElectrons, output[iname].begin(), output[iname].end());
214  filler.fill();
216  event.put(std::move(ptr), names_[iname]);
217  }
218 }
219 
221  auto iter = std::find(names_.begin(), names_.end(), name);
222  if (iter != names_.end()) {
223  int index = std::distance(names_.begin(), iter);
224  std::vector<float> inputs = getFeatures(ele, rho);
225  return models_.at(index)->GetResponse(inputs.data());
226  } else {
227  throw cms::Exception("Unknown model name") << "'Name given: '" << name << "'. Check against configuration file.\n";
228  }
229  return 0.;
230 }
231 
233 //
236  desc.add<edm::InputTag>("electrons", edm::InputTag("lowPtGsfElectrons"));
237  desc.add<edm::InputTag>("rho", edm::InputTag("fixedGridRhoFastjetAllTmp"));
238  desc.add<std::vector<std::string> >("ModelNames", {""});
239  desc.add<std::vector<std::string> >(
240  "ModelWeights",
241  {"RecoEgamma/ElectronIdentification/data/LowPtElectrons/RunII_Autumn18_LowPtElectrons_mva_id.xml.gz"});
242  desc.add<std::vector<double> >("ModelThresholds", {-10.});
243  desc.add<bool>("PassThrough", false);
244  desc.add<double>("MinPtThreshold", 0.5);
245  desc.add<double>("MaxPtThreshold", 15.);
246  descriptions.add("lowPtGsfElectronID", desc);
247 }
248 
250 //
ConfigurationDescriptions.h
edm::StreamID
Definition: StreamID.h:30
LowPtGsfElectronIDProducer::LowPtGsfElectronIDProducer
LowPtGsfElectronIDProducer(const edm::ParameterSet &)
Definition: LowPtGsfElectronIDProducer.cc:155
Handle.h
HLT_2018_cff.weights
weights
Definition: HLT_2018_cff.py:87167
electrons_cff.bool
bool
Definition: electrons_cff.py:372
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
ESHandle.h
LowPtGsfElectronIDProducer::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition: LowPtGsfElectronIDProducer.cc:181
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:32
edm::EDGetTokenT< reco::GsfElectronCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
GBRForestTools.h
ZElectronSkim_cff.rho
rho
Definition: ZElectronSkim_cff.py:38
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
LowPtGsfElectronIDProducer::eval
double eval(const std::string &name, const reco::GsfElectronRef &, double rho) const
Definition: LowPtGsfElectronIDProducer.cc:220
HLT_2018_cff.distance
distance
Definition: HLT_2018_cff.py:6417
createGBRForest
std::unique_ptr< const GBRForest > createGBRForest(const std::string &weightsFile)
Definition: GBRForestTools.cc:244
reco::GsfElectronCollection
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
Definition: GsfElectronFwd.h:14
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
electronIsolatorFromEffectiveArea_cfi.gsfElectrons
gsfElectrons
Definition: electronIsolatorFromEffectiveArea_cfi.py:4
edm::Handle< double >
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
end
#define end
Definition: vmac.h:39
edm::Ref
Definition: AssociativeIterator.h:58
LowPtGsfElectronIDProducer::models_
std::vector< std::unique_ptr< const GBRForest > > models_
Definition: LowPtGsfElectronIDProducer.cc:149
edm::FileInPath
Definition: FileInPath.h:64
MakerMacros.h
LowPtGsfElectronIDProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &)
Definition: LowPtGsfElectronIDProducer.cc:234
Track.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
LowPtGsfElectronIDProducer::gsfElectrons_
const edm::EDGetTokenT< reco::GsfElectronCollection > gsfElectrons_
Definition: LowPtGsfElectronIDProducer.cc:143
LowPtGsfElectronIDProducer::thresholds_
const std::vector< double > thresholds_
Definition: LowPtGsfElectronIDProducer.cc:150
ParameterSetDescription.h
GsfElectron.h
edm::global::EDProducer
Definition: EDProducer.h:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
DDAxes::rho
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
edm::LogError
Definition: MessageLogger.h:183
Event.h
trigObjTnPSource_cfi.filler
filler
Definition: trigObjTnPSource_cfi.py:21
edm::Ref::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
LowPtGsfElectronIDProducer::maxPtThreshold_
const double maxPtThreshold_
Definition: LowPtGsfElectronIDProducer.cc:148
GsfTrack.h
PixelMapPlotter.inputs
inputs
Definition: PixelMapPlotter.py:490
ntupleEnum.gsf
gsf
Definition: ntupleEnum.py:48
edm::EventSetup
Definition: EventSetup.h:57
InputTag.h
ValueMap.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
edm::ValueMap< float >
SuperCluster.h
Exception
Definition: hltDiff.cc:246
LowPtGsfElectronIDProducer::rho_
const edm::EDGetTokenT< double > rho_
Definition: LowPtGsfElectronIDProducer.cc:144
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
LowPtGsfElectronIDProducer::minPtThreshold_
const double minPtThreshold_
Definition: LowPtGsfElectronIDProducer.cc:147
LowPtGsfElectronIDProducer::names_
const std::vector< std::string > names_
Definition: LowPtGsfElectronIDProducer.cc:145
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
LowPtGsfElectronIDProducer
Definition: LowPtGsfElectronIDProducer.cc:132
edm::helper::Filler
Definition: ValueMap.h:22
ParameterSet.h
EDProducer.h
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
LowPtGsfElectronIDProducer::passThrough_
const bool passThrough_
Definition: LowPtGsfElectronIDProducer.cc:146
edm::InputTag
Definition: InputTag.h:15
begin
#define begin
Definition: vmac.h:32