CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
LowPtGsfElectronFeatures.cc
Go to the documentation of this file.
9 #include "TVector3.h"
10 #include <algorithm>
11 #include <iostream>
12 
13 namespace lowptgsfeleseed {
14 
16  //
17  std::vector<float> features(const reco::PreId& ecal,
18  const reco::PreId& hcal,
19  double rho,
20  const reco::BeamSpot& spot,
22  float trk_pt_ = -1.;
23  float trk_eta_ = -1.;
24  float trk_phi_ = -1.;
25  float trk_p_ = -1.;
26  float trk_nhits_ = -1.;
27  float trk_high_quality_ = -1.;
28  float trk_chi2red_ = -1.;
29  float rho_ = -1.;
30  float ktf_ecal_cluster_e_ = -1.;
31  float ktf_ecal_cluster_deta_ = -42.;
32  float ktf_ecal_cluster_dphi_ = -42.;
33  float ktf_ecal_cluster_e3x3_ = -1.;
34  float ktf_ecal_cluster_e5x5_ = -1.;
35  float ktf_ecal_cluster_covEtaEta_ = -42.;
36  float ktf_ecal_cluster_covEtaPhi_ = -42.;
37  float ktf_ecal_cluster_covPhiPhi_ = -42.;
38  float ktf_ecal_cluster_r9_ = -0.1;
39  float ktf_ecal_cluster_circularity_ = -0.1;
40  float ktf_hcal_cluster_e_ = -1.;
41  float ktf_hcal_cluster_deta_ = -42.;
42  float ktf_hcal_cluster_dphi_ = -42.;
43  float preid_gsf_dpt_ = -1.;
44  float preid_trk_gsf_chiratio_ = -1.;
45  float preid_gsf_chi2red_ = -1.;
46  float trk_dxy_sig_ = -1.; // must be last (not used by unbiased model)
47 
48  // Tracks
49  const auto& trk = ecal.trackRef(); // reco::TrackRef
50  if (trk.isNonnull()) {
51  trk_pt_ = trk->pt();
52  trk_eta_ = trk->eta();
53  trk_phi_ = trk->phi();
54  trk_p_ = trk->p();
55  trk_nhits_ = static_cast<float>(trk->found());
56  trk_high_quality_ = static_cast<float>(trk->quality(reco::TrackBase::qualityByName("highPurity")));
57  trk_chi2red_ = trk->normalizedChi2();
58  if (trk->dxy(spot) > 0.) {
59  trk_dxy_sig_ = trk->dxyError() / trk->dxy(spot); //@@ to be consistent with the training based on 94X MC
60  }
61  ktf_ecal_cluster_dphi_ *= trk->charge(); //@@ to be consistent with the training based on 94X MC
62  }
63 
64  // Rho
65  rho_ = static_cast<float>(rho);
66 
67  // ECAL clusters
68  const auto& ecal_clu = ecal.clusterRef(); // reco::PFClusterRef
69  if (ecal_clu.isNonnull()) {
70  ktf_ecal_cluster_e_ = ecal_clu->energy();
71  ktf_ecal_cluster_deta_ = ecal.geomMatching()[0];
72  ktf_ecal_cluster_dphi_ = ecal.geomMatching()[1];
73  ktf_ecal_cluster_e3x3_ = tools.e3x3(*ecal_clu);
74  ktf_ecal_cluster_e5x5_ = tools.e5x5(*ecal_clu);
75  const auto& covs = tools.localCovariances(*ecal_clu);
76  ktf_ecal_cluster_covEtaEta_ = covs[0];
77  ktf_ecal_cluster_covEtaPhi_ = covs[1];
78  ktf_ecal_cluster_covPhiPhi_ = covs[2];
79  if (ktf_ecal_cluster_e_ > 0.) {
80  ktf_ecal_cluster_r9_ = ktf_ecal_cluster_e3x3_ / ktf_ecal_cluster_e_;
81  }
82  if (ktf_ecal_cluster_e5x5_ > 0.) {
83  ktf_ecal_cluster_circularity_ = 1. - tools.e1x5(*ecal_clu) / ktf_ecal_cluster_e5x5_;
84  } else {
85  ktf_ecal_cluster_circularity_ = -0.1;
86  }
87  }
88 
89  // HCAL clusters
90  const auto& hcal_clu = hcal.clusterRef(); // reco::PFClusterRef
91  if (hcal_clu.isNonnull()) {
92  ktf_hcal_cluster_e_ = hcal_clu->energy();
93  ktf_hcal_cluster_deta_ = hcal.geomMatching()[0];
94  ktf_hcal_cluster_dphi_ = hcal.geomMatching()[1];
95  }
96 
97  // PreId
98  preid_gsf_dpt_ = ecal.dpt();
99  preid_trk_gsf_chiratio_ = ecal.chi2Ratio();
100  preid_gsf_chi2red_ = ecal.gsfChi2();
101 
102  // Set contents of vector
103  std::vector<float> output = {trk_pt_,
104  trk_eta_,
105  trk_phi_,
106  trk_p_,
107  trk_nhits_,
108  trk_high_quality_,
109  trk_chi2red_,
110  rho_,
111  ktf_ecal_cluster_e_,
112  ktf_ecal_cluster_deta_,
113  ktf_ecal_cluster_dphi_,
114  ktf_ecal_cluster_e3x3_,
115  ktf_ecal_cluster_e5x5_,
116  ktf_ecal_cluster_covEtaEta_,
117  ktf_ecal_cluster_covEtaPhi_,
118  ktf_ecal_cluster_covPhiPhi_,
119  ktf_ecal_cluster_r9_,
120  ktf_ecal_cluster_circularity_,
121  ktf_hcal_cluster_e_,
122  ktf_hcal_cluster_deta_,
123  ktf_hcal_cluster_dphi_,
124  preid_gsf_dpt_,
125  preid_trk_gsf_chiratio_,
126  preid_gsf_chi2red_,
127  trk_dxy_sig_};
128  return output;
129  };
130 
131 } // namespace lowptgsfeleseed
132 
133 namespace lowptgsfeleid {
134 
135  std::vector<float> features_V1(reco::GsfElectron const& ele, float rho, float unbiased, float field_z) {
136  float eid_rho = -999.;
137  float eid_sc_eta = -999.;
138  float eid_shape_full5x5_r9 = -999.;
139  float eid_sc_etaWidth = -999.;
140  float eid_sc_phiWidth = -999.;
141  float eid_shape_full5x5_HoverE = -999.;
142  float eid_trk_nhits = -999.;
143  float eid_trk_chi2red = -999.;
144  float eid_gsf_chi2red = -999.;
145  float eid_brem_frac = -999.;
146  float eid_gsf_nhits = -999.;
147  float eid_match_SC_EoverP = -999.;
148  float eid_match_eclu_EoverP = -999.;
149  float eid_match_SC_dEta = -999.;
150  float eid_match_SC_dPhi = -999.;
151  float eid_match_seed_dEta = -999.;
152  float eid_sc_E = -999.;
153  float eid_trk_p = -999.;
154  float gsf_mode_p = -999.;
155  float core_shFracHits = -999.;
156  float gsf_bdtout1 = -999.;
157  float gsf_dr = -999.;
158  float trk_dr = -999.;
159  float sc_Nclus = -999.;
160  float sc_clus1_nxtal = -999.;
161  float sc_clus1_dphi = -999.;
162  float sc_clus2_dphi = -999.;
163  float sc_clus1_deta = -999.;
164  float sc_clus2_deta = -999.;
165  float sc_clus1_E = -999.;
166  float sc_clus2_E = -999.;
167  float sc_clus1_E_ov_p = -999.;
168  float sc_clus2_E_ov_p = -999.;
169 
170  // KF tracks
171  if (ele.core().isNonnull()) {
173  if (trk.isNonnull()) {
174  eid_trk_p = (float)trk->p();
175  eid_trk_nhits = (float)trk->found();
176  eid_trk_chi2red = (float)trk->normalizedChi2();
177  TVector3 trkTV3(0, 0, 0);
178  trkTV3.SetPtEtaPhi(trk->pt(), trk->eta(), trk->phi());
179  TVector3 eleTV3(0, 0, 0);
180  eleTV3.SetPtEtaPhi(ele.pt(), ele.eta(), ele.phi());
181  trk_dr = eleTV3.DeltaR(trkTV3);
182  }
183  }
184 
185  // GSF tracks
186  if (ele.core().isNonnull()) {
188  if (gsf.isNonnull()) {
189  gsf_mode_p = gsf->pMode();
190  eid_gsf_nhits = (float)gsf->found();
191  eid_gsf_chi2red = gsf->normalizedChi2();
192  TVector3 gsfTV3(0, 0, 0);
193  gsfTV3.SetPtEtaPhi(gsf->ptMode(), gsf->etaMode(), gsf->phiMode());
194  TVector3 eleTV3(0, 0, 0);
195  eleTV3.SetPtEtaPhi(ele.pt(), ele.eta(), ele.phi());
196  gsf_dr = eleTV3.DeltaR(gsfTV3);
197  }
198  }
199 
200  // Super clusters
201  if (ele.core().isNonnull()) {
203  if (sc.isNonnull()) {
204  eid_sc_E = sc->energy();
205  eid_sc_eta = sc->eta();
206  eid_sc_etaWidth = sc->etaWidth();
207  eid_sc_phiWidth = sc->phiWidth();
208  sc_Nclus = sc->clustersSize();
209  }
210  }
211 
212  // Track-cluster matching
213  eid_match_seed_dEta = ele.deltaEtaSeedClusterTrackAtCalo();
214  eid_match_eclu_EoverP = (1. / ele.ecalEnergy()) - (1. / ele.p());
215  eid_match_SC_EoverP = ele.eSuperClusterOverP();
216  eid_match_SC_dEta = ele.deltaEtaSuperClusterTrackAtVtx();
217  eid_match_SC_dPhi = ele.deltaPhiSuperClusterTrackAtVtx();
218 
219  // Shower shape vars
220  eid_shape_full5x5_HoverE = ele.full5x5_hcalOverEcal();
221  eid_shape_full5x5_r9 = ele.full5x5_r9();
222 
223  // Misc
224  eid_rho = rho;
225 
226  eid_brem_frac = ele.fbrem();
227  core_shFracHits = ele.shFracInnerHits();
228 
229  // Unbiased BDT from ElectronSeed
230  gsf_bdtout1 = unbiased;
231 
232  // Clusters
233  if (ele.core().isNonnull()) {
235  if (gsf.isNonnull()) {
237  if (sc.isNonnull()) {
238  // Propagate electron track to ECAL surface
239  double mass2 = 0.000511 * 0.000511;
240  float p2 = pow(gsf->p(), 2);
241  float energy = sqrt(mass2 + p2);
242  XYZTLorentzVector mom = XYZTLorentzVector(gsf->px(), gsf->py(), gsf->pz(), energy);
243  XYZTLorentzVector pos = XYZTLorentzVector(gsf->vx(), gsf->vy(), gsf->vz(), 0.);
244  BaseParticlePropagator propagator(RawParticle(mom, pos, gsf->charge()), 0, 0, field_z);
245  propagator.propagateToEcalEntrance(true); // true only first half loop , false more than one loop
246  bool reach_ECAL = propagator.getSuccess(); // 0 does not reach ECAL, 1 yes barrel, 2 yes endcaps
247  // ECAL entry point for track
248  GlobalPoint ecal_pos(propagator.particle().x(), propagator.particle().y(), propagator.particle().z());
249 
250  // Track-cluster matching for most energetic clusters
251  sc_clus1_nxtal = -999;
252  sc_clus1_dphi = -999.;
253  sc_clus2_dphi = -999.;
254  sc_clus1_deta = -999.;
255  sc_clus2_deta = -999.;
256  sc_clus1_E = -999.;
257  sc_clus2_E = -999.;
258  sc_clus1_E_ov_p = -999.;
259  sc_clus2_E_ov_p = -999.;
261  *gsf,
262  reach_ECAL,
263  ecal_pos,
264  sc_clus1_nxtal,
265  sc_clus1_dphi,
266  sc_clus2_dphi,
267  sc_clus1_deta,
268  sc_clus2_deta,
269  sc_clus1_E,
270  sc_clus2_E,
271  sc_clus1_E_ov_p,
272  sc_clus2_E_ov_p);
273  sc_clus1_nxtal = (int)sc_clus1_nxtal;
274 
275  } // sc.isNonnull()
276  } // gsf.isNonnull()
277  } // clusters
278 
279  // Out-of-range
280  eid_rho = std::clamp(eid_rho, 0.f, 100.f);
281  eid_sc_eta = std::clamp(eid_sc_eta, -5.f, 5.f);
282  eid_shape_full5x5_r9 = std::clamp(eid_shape_full5x5_r9, 0.f, 2.f);
283  eid_sc_etaWidth = std::clamp(eid_sc_etaWidth, 0.f, 3.14f);
284  eid_sc_phiWidth = std::clamp(eid_sc_phiWidth, 0.f, 3.14f);
285  eid_shape_full5x5_HoverE = std::clamp(eid_shape_full5x5_HoverE, 0.f, 50.f);
286  eid_trk_nhits = std::clamp(eid_trk_nhits, -1.f, 50.f);
287  eid_trk_chi2red = std::clamp(eid_trk_chi2red, -1.f, 50.f);
288  eid_gsf_chi2red = std::clamp(eid_gsf_chi2red, -1.f, 100.f);
289  if (eid_brem_frac < 0.)
290  eid_brem_frac = -1.; //
291  if (eid_brem_frac > 1.)
292  eid_brem_frac = 1.; //
293  eid_gsf_nhits = std::clamp(eid_gsf_nhits, -1.f, 50.f);
294  eid_match_SC_EoverP = std::clamp(eid_match_SC_EoverP, 0.f, 100.f);
295  eid_match_eclu_EoverP = std::clamp(eid_match_eclu_EoverP, -1.f, 1.f);
296  eid_match_SC_dEta = std::clamp(eid_match_SC_dEta, -10.f, 10.f);
297  eid_match_SC_dPhi = std::clamp(eid_match_SC_dPhi, -3.14f, 3.14f);
298  eid_match_seed_dEta = std::clamp(eid_match_seed_dEta, -10.f, 10.f);
299  eid_sc_E = std::clamp(eid_sc_E, 0.f, 1000.f);
300  eid_trk_p = std::clamp(eid_trk_p, -1.f, 1000.f);
301  gsf_mode_p = std::clamp(gsf_mode_p, 0.f, 1000.f);
302  core_shFracHits = std::clamp(core_shFracHits, 0.f, 1.f);
303  gsf_bdtout1 = std::clamp(gsf_bdtout1, -20.f, 20.f);
304  if (gsf_dr < 0.)
305  gsf_dr = 5.; //
306  if (gsf_dr > 5.)
307  gsf_dr = 5.; //
308  if (trk_dr < 0.)
309  trk_dr = 5.; //
310  if (trk_dr > 5.)
311  trk_dr = 5.; //
312  sc_Nclus = std::clamp(sc_Nclus, 0.f, 20.f);
313  sc_clus1_nxtal = std::clamp(sc_clus1_nxtal, 0.f, 100.f);
314  sc_clus1_dphi = std::clamp(sc_clus1_dphi, -3.14f, 3.14f);
315  sc_clus2_dphi = std::clamp(sc_clus2_dphi, -3.14f, 3.14f);
316  sc_clus1_deta = std::clamp(sc_clus1_deta, -5.f, 5.f);
317  sc_clus2_deta = std::clamp(sc_clus2_deta, -5.f, 5.f);
318  sc_clus1_E = std::clamp(sc_clus1_E, 0.f, 1000.f);
319  sc_clus2_E = std::clamp(sc_clus2_E, 0.f, 1000.f);
320  if (sc_clus1_E_ov_p < 0.)
321  sc_clus1_E_ov_p = -1.; //
322  if (sc_clus2_E_ov_p < 0.)
323  sc_clus2_E_ov_p = -1.; //
324 
325  // Set contents of vector
326  std::vector<float> output = {eid_rho,
327  eid_sc_eta,
328  eid_shape_full5x5_r9,
329  eid_sc_etaWidth,
330  eid_sc_phiWidth,
331  eid_shape_full5x5_HoverE,
332  eid_trk_nhits,
333  eid_trk_chi2red,
334  eid_gsf_chi2red,
335  eid_brem_frac,
336  eid_gsf_nhits,
337  eid_match_SC_EoverP,
338  eid_match_eclu_EoverP,
339  eid_match_SC_dEta,
340  eid_match_SC_dPhi,
341  eid_match_seed_dEta,
342  eid_sc_E,
343  eid_trk_p,
344  gsf_mode_p,
345  core_shFracHits,
346  gsf_bdtout1,
347  gsf_dr,
348  trk_dr,
349  sc_Nclus,
350  sc_clus1_nxtal,
351  sc_clus1_dphi,
352  sc_clus2_dphi,
353  sc_clus1_deta,
354  sc_clus2_deta,
355  sc_clus1_E,
356  sc_clus2_E,
357  sc_clus1_E_ov_p,
358  sc_clus2_E_ov_p};
359  return output;
360  }
361 
363  // feature list for original models (2019Aug07 and earlier)
364  std::vector<float> features_V0(reco::GsfElectron const& ele, float rho, float unbiased) {
365  float eid_rho = -999.;
366  float eid_sc_eta = -999.;
367  float eid_shape_full5x5_r9 = -999.;
368  float eid_sc_etaWidth = -999.;
369  float eid_sc_phiWidth = -999.;
370  float eid_shape_full5x5_HoverE = -999.;
371  float eid_trk_nhits = -999.;
372  float eid_trk_chi2red = -999.;
373  float eid_gsf_chi2red = -999.;
374  float eid_brem_frac = -999.;
375  float eid_gsf_nhits = -999.;
376  float eid_match_SC_EoverP = -999.;
377  float eid_match_eclu_EoverP = -999.;
378  float eid_match_SC_dEta = -999.;
379  float eid_match_SC_dPhi = -999.;
380  float eid_match_seed_dEta = -999.;
381  float eid_sc_E = -999.;
382  float eid_trk_p = -999.;
383  float gsf_mode_p = -999.;
384  float core_shFracHits = -999.;
385  float gsf_bdtout1 = -999.;
386  float gsf_dr = -999.;
387  float trk_dr = -999.;
388  float sc_Nclus = -999.;
389  float sc_clus1_nxtal = -999.;
390  float sc_clus1_dphi = -999.;
391  float sc_clus2_dphi = -999.;
392  float sc_clus1_deta = -999.;
393  float sc_clus2_deta = -999.;
394  float sc_clus1_E = -999.;
395  float sc_clus2_E = -999.;
396  float sc_clus1_E_ov_p = -999.;
397  float sc_clus2_E_ov_p = -999.;
398 
399  // KF tracks
400  if (ele.core().isNonnull()) {
401  const auto& trk = ele.closestCtfTrackRef(); // reco::TrackRef
402  if (trk.isNonnull()) {
403  eid_trk_p = (float)trk->p();
404  eid_trk_nhits = (float)trk->found();
405  eid_trk_chi2red = (float)trk->normalizedChi2();
406  TVector3 trkTV3(0, 0, 0);
407  trkTV3.SetPtEtaPhi(trk->pt(), trk->eta(), trk->phi());
408  TVector3 eleTV3(0, 0, 0);
409  eleTV3.SetPtEtaPhi(ele.pt(), ele.eta(), ele.phi());
410  trk_dr = eleTV3.DeltaR(trkTV3);
411  }
412  }
413 
414  // GSF tracks
415  if (ele.core().isNonnull()) {
416  const auto& gsf = ele.core()->gsfTrack(); // reco::GsfTrackRef
417  if (gsf.isNonnull()) {
418  gsf_mode_p = gsf->pMode();
419  eid_gsf_nhits = (float)gsf->found();
420  eid_gsf_chi2red = gsf->normalizedChi2();
421  TVector3 gsfTV3(0, 0, 0);
422  gsfTV3.SetPtEtaPhi(gsf->ptMode(), gsf->etaMode(), gsf->phiMode());
423  TVector3 eleTV3(0, 0, 0);
424  eleTV3.SetPtEtaPhi(ele.pt(), ele.eta(), ele.phi());
425  gsf_dr = eleTV3.DeltaR(gsfTV3);
426  }
427  }
428 
429  // Super clusters
430  if (ele.core().isNonnull()) {
431  const auto& sc = ele.core()->superCluster(); // reco::SuperClusterRef
432  if (sc.isNonnull()) {
433  eid_sc_E = sc->energy();
434  eid_sc_eta = sc->eta();
435  eid_sc_etaWidth = sc->etaWidth();
436  eid_sc_phiWidth = sc->phiWidth();
437  sc_Nclus = (float)sc->clustersSize();
438  }
439  }
440 
441  // Track-cluster matching
442  eid_match_seed_dEta = ele.deltaEtaSeedClusterTrackAtCalo();
443  eid_match_eclu_EoverP = (1. / ele.ecalEnergy()) - (1. / ele.p());
444  eid_match_SC_EoverP = ele.eSuperClusterOverP();
445  eid_match_SC_dEta = ele.deltaEtaSuperClusterTrackAtVtx();
446  eid_match_SC_dPhi = ele.deltaPhiSuperClusterTrackAtVtx();
447 
448  // Shower shape vars
449  eid_shape_full5x5_HoverE = ele.full5x5_hcalOverEcal();
450  eid_shape_full5x5_r9 = ele.full5x5_r9();
451 
452  // Misc
453  eid_rho = rho;
454 
455  eid_brem_frac = ele.fbrem();
456  core_shFracHits = (float)ele.shFracInnerHits();
457 
458  // Unbiased BDT from ElectronSeed
459  gsf_bdtout1 = unbiased;
460 
461  // Clusters
462  if (ele.core().isNonnull()) {
463  const auto& gsf = ele.core()->gsfTrack(); // reco::GsfTrackRef
464  if (gsf.isNonnull()) {
465  const auto& sc = ele.core()->superCluster(); // reco::SuperClusterRef
466  if (sc.isNonnull()) {
467  // Propagate electron track to ECAL surface
468  double mass2 = 0.000511 * 0.000511;
469  float p2 = pow(gsf->p(), 2);
470  float energy = sqrt(mass2 + p2);
471  math::XYZTLorentzVector mom = math::XYZTLorentzVector(gsf->px(), gsf->py(), gsf->pz(), energy);
472  math::XYZTLorentzVector pos = math::XYZTLorentzVector(gsf->vx(), gsf->vy(), gsf->vz(), 0.);
473  float field_z = 3.8;
474  BaseParticlePropagator mypart(RawParticle(mom, pos, gsf->charge()), 0, 0, field_z);
475  mypart.propagateToEcalEntrance(true); // true only first half loop , false more than one loop
476  bool reach_ECAL = mypart.getSuccess(); // 0 does not reach ECAL, 1 yes barrel, 2 yes endcaps
477 
478  // ECAL entry point for track
479  GlobalPoint ecal_pos(
480  mypart.particle().vertex().x(), mypart.particle().vertex().y(), mypart.particle().vertex().z());
481 
482  // Track-cluster matching for most energetic clusters
483  sc_clus1_nxtal = -999.;
484  sc_clus1_dphi = -999.;
485  sc_clus2_dphi = -999.;
486  sc_clus1_deta = -999.;
487  sc_clus2_deta = -999.;
488  sc_clus1_E = -999.;
489  sc_clus2_E = -999.;
490  sc_clus1_E_ov_p = -999.;
491  sc_clus2_E_ov_p = -999.;
493  *gsf,
494  reach_ECAL,
495  ecal_pos,
496  sc_clus1_nxtal,
497  sc_clus1_dphi,
498  sc_clus2_dphi,
499  sc_clus1_deta,
500  sc_clus2_deta,
501  sc_clus1_E,
502  sc_clus2_E,
503  sc_clus1_E_ov_p,
504  sc_clus2_E_ov_p);
505 
506  } // sc.isNonnull()
507  } // gsf.isNonnull()
508  } // clusters
509 
510  // Out-of-range
511  eid_sc_eta = std::clamp(eid_sc_eta, -5.f, 5.f);
512  eid_shape_full5x5_r9 = std::clamp(eid_shape_full5x5_r9, 0.f, 2.f);
513  eid_sc_etaWidth = std::clamp(eid_sc_etaWidth, 0.f, 3.14f);
514  eid_sc_phiWidth = std::clamp(eid_sc_phiWidth, 0.f, 3.14f);
515  eid_shape_full5x5_HoverE = std::clamp(eid_shape_full5x5_HoverE, 0.f, 50.f);
516  eid_trk_nhits = std::clamp(eid_trk_nhits, -1.f, 50.f);
517  eid_trk_chi2red = std::clamp(eid_trk_chi2red, -1.f, 50.f);
518  eid_gsf_chi2red = std::clamp(eid_gsf_chi2red, -1.f, 100.f);
519  if (eid_brem_frac < 0.)
520  eid_brem_frac = -1.; //
521  if (eid_brem_frac > 1.)
522  eid_brem_frac = 1.; //
523  eid_gsf_nhits = std::clamp(eid_gsf_nhits, -1.f, 50.f);
524  eid_match_SC_EoverP = std::clamp(eid_match_SC_EoverP, 0.f, 100.f);
525  eid_match_eclu_EoverP = std::clamp(eid_match_eclu_EoverP, -1.f, 1.f);
526  eid_match_SC_dEta = std::clamp(eid_match_SC_dEta, -10.f, 10.f);
527  eid_match_SC_dPhi = std::clamp(eid_match_SC_dPhi, -3.14f, 3.14f);
528  eid_match_seed_dEta = std::clamp(eid_match_seed_dEta, -10.f, 10.f);
529  eid_sc_E = std::clamp(eid_sc_E, 0.f, 1000.f);
530  eid_trk_p = std::clamp(eid_trk_p, -1.f, 1000.f);
531  gsf_mode_p = std::clamp(gsf_mode_p, 0.f, 1000.f);
532  core_shFracHits = std::clamp(core_shFracHits, 0.f, 1.f);
533  gsf_bdtout1 = std::clamp(gsf_bdtout1, -20.f, 20.f);
534  if (gsf_dr < 0.)
535  gsf_dr = 5.; //
536  if (gsf_dr > 5.)
537  gsf_dr = 5.; //
538  if (trk_dr < 0.)
539  trk_dr = 5.; //
540  if (trk_dr > 5.)
541  trk_dr = 5.; //
542  sc_Nclus = std::clamp(sc_Nclus, 0.f, 20.f);
543  sc_clus1_nxtal = std::clamp(sc_clus1_nxtal, 0.f, 100.f);
544  if (sc_clus1_dphi < -3.14)
545  sc_clus1_dphi = -5.; //
546  if (sc_clus1_dphi > 3.14)
547  sc_clus1_dphi = 5.; //
548  if (sc_clus2_dphi < -3.14)
549  sc_clus2_dphi = -5.; //
550  if (sc_clus2_dphi > 3.14)
551  sc_clus2_dphi = 5.; //
552  sc_clus1_deta = std::clamp(sc_clus1_deta, -5.f, 5.f);
553  sc_clus2_deta = std::clamp(sc_clus2_deta, -5.f, 5.f);
554  sc_clus1_E = std::clamp(sc_clus1_E, 0.f, 1000.f);
555  sc_clus2_E = std::clamp(sc_clus2_E, 0.f, 1000.f);
556  if (sc_clus1_E_ov_p < 0.)
557  sc_clus1_E_ov_p = -1.; //
558  if (sc_clus2_E_ov_p < 0.)
559  sc_clus2_E_ov_p = -1.; //
560 
561  // Set contents of vector
562  std::vector<float> output = {eid_rho,
563  eid_sc_eta,
564  eid_shape_full5x5_r9,
565  eid_sc_etaWidth,
566  eid_sc_phiWidth,
567  eid_shape_full5x5_HoverE,
568  eid_trk_nhits,
569  eid_trk_chi2red,
570  eid_gsf_chi2red,
571  eid_brem_frac,
572  eid_gsf_nhits,
573  eid_match_SC_EoverP,
574  eid_match_eclu_EoverP,
575  eid_match_SC_dEta,
576  eid_match_SC_dPhi,
577  eid_match_seed_dEta,
578  eid_sc_E,
579  eid_trk_p,
580  gsf_mode_p,
581  core_shFracHits,
582  gsf_bdtout1,
583  gsf_dr,
584  trk_dr,
585  sc_Nclus,
586  sc_clus1_nxtal,
587  sc_clus1_dphi,
588  sc_clus2_dphi,
589  sc_clus1_deta,
590  sc_clus2_deta,
591  sc_clus1_E,
592  sc_clus2_E,
593  sc_clus1_E_ov_p,
594  sc_clus2_E_ov_p};
595  return output;
596  }
597 
599  // Find most energetic clusters
601  reco::SuperCluster const& sc, int& clusNum, float& maxEne1, float& maxEne2, int& i1, int& i2) {
602  if (sc.clustersSize() > 0 && sc.clustersBegin() != sc.clustersEnd()) {
603  for (auto const& cluster : sc.clusters()) {
604  if (cluster->energy() > maxEne1) {
605  maxEne1 = cluster->energy();
606  i1 = clusNum;
607  }
608  clusNum++;
609  }
610  if (sc.clustersSize() > 1) {
611  clusNum = 0;
612  for (auto const& cluster : sc.clusters()) {
613  if (clusNum != i1) {
614  if (cluster->energy() > maxEne2) {
615  maxEne2 = cluster->energy();
616  i2 = clusNum;
617  }
618  }
619  clusNum++;
620  }
621  }
622  } // loop over clusters
623  }
624 
626  // Track-cluster matching for most energetic clusters
628  reco::GsfTrack const& gsf,
629  bool const& reach_ECAL,
630  GlobalPoint const& ecal_pos,
631  float& sc_clus1_nxtal,
632  float& sc_clus1_dphi,
633  float& sc_clus2_dphi,
634  float& sc_clus1_deta,
635  float& sc_clus2_deta,
636  float& sc_clus1_E,
637  float& sc_clus2_E,
638  float& sc_clus1_E_ov_p,
639  float& sc_clus2_E_ov_p) {
640  // Iterate through ECAL clusters and sort in energy
641  int clusNum = 0;
642  float maxEne1 = -1;
643  float maxEne2 = -1;
644  int i1 = -1;
645  int i2 = -1;
646  findEnergeticClusters(sc, clusNum, maxEne1, maxEne2, i1, i2);
647 
648  // track-clusters match
649  clusNum = 0;
650  if (sc.clustersSize() > 0 && sc.clustersBegin() != sc.clustersEnd()) {
651  for (auto const& cluster : sc.clusters()) {
652  float deta = ecal_pos.eta() - cluster->eta();
653  float dphi = reco::deltaPhi(ecal_pos.phi(), cluster->phi());
654  if (clusNum == i1) {
655  sc_clus1_E = cluster->energy();
656  if (gsf.pMode() > 0)
657  sc_clus1_E_ov_p = cluster->energy() / gsf.pMode();
658  sc_clus1_nxtal = (float)cluster->size();
659  if (reach_ECAL > 0) {
660  sc_clus1_deta = deta;
661  sc_clus1_dphi = dphi;
662  }
663  } else if (clusNum == i2) {
664  sc_clus2_E = cluster->energy();
665  if (gsf.pMode() > 0)
666  sc_clus2_E_ov_p = cluster->energy() / gsf.pMode();
667  if (reach_ECAL > 0) {
668  sc_clus2_deta = deta;
669  sc_clus2_dphi = dphi;
670  }
671  }
672  clusNum++;
673  }
674  }
675  }
676 
677 } // namespace lowptgsfeleid
reco::GsfElectron::deltaEtaSeedClusterTrackAtCalo
float deltaEtaSeedClusterTrackAtCalo() const
Definition: GsfElectron.h:234
testProducerWithPsetDescEmpty_cfi.i2
i2
Definition: testProducerWithPsetDescEmpty_cfi.py:46
RawParticle
Definition: RawParticle.h:37
BaseParticlePropagator::propagateToEcalEntrance
bool propagateToEcalEntrance(bool first=true)
Definition: BaseParticlePropagator.cc:450
reco::GsfElectron::gsfTrack
GsfTrackRef gsfTrack() const override
reference to a GsfTrack
Definition: GsfElectron.h:164
reco::SuperCluster::clusters
const CaloClusterPtrVector & clusters() const
const access to the cluster list itself
Definition: SuperCluster.h:80
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
BaseParticlePropagator::particle
RawParticle const & particle() const
The particle being propagated.
Definition: BaseParticlePropagator.h:164
reco::GsfElectron::deltaPhiSuperClusterTrackAtVtx
float deltaPhiSuperClusterTrackAtVtx() const
Definition: GsfElectron.h:236
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
reco::SuperCluster::clustersSize
size_t clustersSize() const
number of BasicCluster constituents
Definition: SuperCluster.h:98
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
reco::SuperCluster
Definition: SuperCluster.h:18
lowptgsfeleid::features_V1
std::vector< float > features_V1(reco::GsfElectron const &ele, float rho, float unbiased, float field_z)
Definition: LowPtGsfElectronFeatures.cc:135
reco::deltaPhi
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
hcal
Definition: ConfigurationDatabase.cc:13
RawParticle::vertex
const XYZTLorentzVector & vertex() const
the vertex fourvector
Definition: RawParticle.h:320
lowptgsfeleid
Definition: LowPtGsfElectronFeatures.h:24
pos
Definition: PixelAliasList.h:18
testProducerWithPsetDescEmpty_cfi.i1
i1
Definition: testProducerWithPsetDescEmpty_cfi.py:45
BaseParticlePropagator.h
BaseParticlePropagator::getSuccess
int getSuccess() const
Has propagation been performed and was barrel or endcap reached ?
Definition: BaseParticlePropagator.h:296
lowptgsfeleid::findEnergeticClusters
void findEnergeticClusters(reco::SuperCluster const &, int &, float &, float &, int &, int &)
Definition: LowPtGsfElectronFeatures.cc:600
reco::LeafCandidate::pt
double pt() const final
transverse momentum
Definition: LeafCandidate.h:146
XYZTLorentzVector
math::XYZTLorentzVector XYZTLorentzVector
Definition: RawParticle.h:25
reco::PreId
Definition: PreId.h:13
ecal
Definition: ElectronicsMappingGPU.h:13
reco::GsfElectron::fbrem
float fbrem() const
Definition: GsfElectron.h:796
BaseParticlePropagator
Definition: BaseParticlePropagator.h:82
edm::Ref< TrackCollection >
reco::GsfElectron::full5x5_hcalOverEcal
float full5x5_hcalOverEcal(int depth=0) const
Definition: GsfElectron.h:485
reco::GsfElectron::core
virtual GsfElectronCoreRef core() const
Definition: GsfElectron.cc:8
reco::GsfTrack
Definition: GsfTrack.h:12
Track.h
TrackFwd.h
TrackCandidateProducer_cfi.propagator
propagator
Definition: TrackCandidateProducer_cfi.py:17
LowPtGsfElectronFeatures.h
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
reco::BeamSpot
Definition: BeamSpot.h:21
p2
double p2[4]
Definition: TauolaWrapper.h:90
PFCluster.h
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
reco::GsfElectron
Definition: GsfElectron.h:35
lowptgsfeleid::trackClusterMatching
void trackClusterMatching(reco::SuperCluster const &, reco::GsfTrack const &, bool const &, GlobalPoint const &, float &, float &, float &, float &, float &, float &, float &, float &, float &)
Definition: LowPtGsfElectronFeatures.cc:627
Point3DBase< float, GlobalTag >
lowptgsfeleseed::features
std::vector< float > features(const reco::PreId &ecal, const reco::PreId &hcal, double rho, const reco::BeamSpot &spot, noZS::EcalClusterLazyTools &ecalTools)
Definition: LowPtGsfElectronFeatures.cc:17
EcalClusterLazyToolsT
Definition: EcalClusterLazyTools.h:137
Geom::Phi::phi
T1 phi() const
Definition: Phi.h:78
reco::GsfElectron::full5x5_r9
float full5x5_r9() const
Definition: GsfElectron.h:484
reco::GsfElectron::deltaEtaSuperClusterTrackAtVtx
float deltaEtaSuperClusterTrackAtVtx() const
Definition: GsfElectron.h:233
reco::LeafCandidate::eta
double eta() const final
momentum pseudorapidity
Definition: LeafCandidate.h:152
edm::Ref::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
PV3DBase::eta
T eta() const
Definition: PV3DBase.h:73
lowptgsfeleid::features_V0
std::vector< float > features_V0(reco::GsfElectron const &ele, float rho, float unbiased)
Definition: LowPtGsfElectronFeatures.cc:364
createfilelist.int
int
Definition: createfilelist.py:10
PFClusterFwd.h
GsfTrack.h
reco::SuperCluster::clustersBegin
CaloCluster_iterator clustersBegin() const
fist iterator over BasicCluster constituents
Definition: SuperCluster.h:86
ntupleEnum.gsf
gsf
Definition: ntupleEnum.py:48
tools
Definition: tools.py:1
reco::GsfElectron::closestCtfTrackRef
virtual TrackRef closestCtfTrackRef() const
Definition: GsfElectron.h:188
lowPtElectrons_cff.unbiased
unbiased
Definition: lowPtElectrons_cff.py:35
reco::TrackBase::qualityByName
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:126
reco::LeafCandidate::phi
double phi() const final
momentum azimuthal angle
Definition: LeafCandidate.h:148
math::XYZTLorentzVector
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
reco::LeafCandidate::p
double p() const final
magnitude of momentum vector
Definition: LeafCandidate.h:123
reco::GsfElectron::eSuperClusterOverP
float eSuperClusterOverP() const
Definition: GsfElectron.h:229
reco::GsfElectron::superCluster
SuperClusterRef superCluster() const override
reference to a SuperCluster
Definition: GsfElectron.h:163
Electron.h
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
lowptgsfeleseed
Definition: LowPtGsfElectronFeatures.h:14
reco::SuperCluster::clustersEnd
CaloCluster_iterator clustersEnd() const
last iterator over BasicCluster constituents
Definition: SuperCluster.h:89
PV3DBase::phi
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
reco::GsfElectron::shFracInnerHits
float shFracInnerHits() const
Definition: GsfElectron.h:187
reco::GsfElectron::ecalEnergy
float ecalEnergy() const
Definition: GsfElectron.h:883