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