EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ElectronPIDModule.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ElectronPIDModule.cc
1 #include "ElectronPIDModule.h"
2 
3 #include "TClonesArray.h"
4 #include "TRandom3.h"
5 #include "Math/PdfFuncMathCore.h"
6 
7 #include "AnalysisFunctions.cc"
8 
9 #include <iostream>
10 #include <algorithm>
11 
13  : Module(data)
14 {
15 
16 }
17 
19 {
20 
21 }
22 
23 
24 
25 bool ElectronPIDModule::execute(std::map<std::string, std::any>* DataStore)
26 {
27  auto data = getData();
28 
29  // If event contains at least 1 jet
30  // std::vector<Jet*> all_jets;
31  // for (int ijet = 0; ijet < getJets()->GetEntries(); ijet++)
32  // {
33  // // Take first jet
34  // Jet *jet = (Jet*) getJets()->At(ijet);
35  // all_jets.push_back(jet);
36  // }
37 
38  // std::vector<Jet*> fiducial_jets = SelectorFcn<Jet>(all_jets, [](Jet* j){ return (TMath::Abs(j->Eta) < 3.0 && j->PT > 5.0); });
39  // std::vector<Jet*> charmJets = SelectorFcn<Jet>(fiducial_jets, [](Jet* j){ return (j->Flavor == 4); });
40 
41  std::vector<Track*> all_electrons;
42 
43  // If the DataStore contains already a list of tracks to be used for PID assignment,
44  // use that. If not, use the getEFlowTracks() method to get the general list of all tracks.
45  // TracksForPID is special - it contains tracks NOT already used by another PID algorithm,
46  // to avoid using the same track (pion) twice in two categories.
47 
48  float e_efficiency = 0.90;
49  float epi_separation = 2.4; //sigma
50  //float e_efficiency = 1.00;
51  //float epi_separation = 100.0; //sigma
52 
53  if (DataStore->find("TracksForPID") != DataStore->end()) {
54  for (auto track : std::any_cast<std::vector<Track*>>((*DataStore)["TracksForPID"])) {
55  if (ElectronPID(track, e_efficiency, epi_separation))
56  all_electrons.push_back(track);
57  }
58 
59 
60  } else {
61  for (int itrk = 0; itrk < getEFlowTracks()->GetEntries(); itrk++)
62  {
63  Track* track = (Track*) getEFlowTracks()->At(itrk);
64  if (ElectronPID(track, e_efficiency, epi_separation))
65  all_electrons.push_back(track);
66  }
67 
68  std::vector<Track*> tracks_for_PID;
69  for (int itrk = 0; itrk < getEFlowTracks()->GetEntries(); itrk++)
70  {
71  Track* track = (Track*) getEFlowTracks()->At(itrk);
72  tracks_for_PID.push_back(track);
73  }
74  (*DataStore)["TracksForPID"] = tracks_for_PID;
75  }
76 
77  //auto reconstructed_electrons = all_electrons;
78  std::vector<Track*> reconstructed_electrons = SelectorFcn<Track>(all_electrons,
79  [](Track* t){ return (t->PT >= 0.1); });
80 
81  std::vector<Track*> tracks_for_PID = std::any_cast<std::vector<Track*>>((*DataStore)["TracksForPID"]);
82  for (auto electron : reconstructed_electrons) {
83  tracks_for_PID.erase(std::find(tracks_for_PID.begin(), tracks_for_PID.end(), electron));
84  }
85  (*DataStore)["TracksForPID"] = tracks_for_PID;
86 
87 
88  // store the electrons
89  (*DataStore)["Electrons"] = reconstructed_electrons;
90 
91 
92  return true;
93 }
94 
95 
96 bool ElectronPIDModule::ElectronPID(Track* track, float eIDprob, float separation)
97 {
98  bool TrackIsElectron = false;
99 
100 
101  // Apply a basic parameterized electron PID to tracks. If the track is really a
102  // electron from truth information, apply a flat ID probability. If it's a pion,
103  // use the separation (in Gaussian sigma) to determine if it's mis-identified.
104 
105  if (track->PT < 0.1)
106  return TrackIsElectron;
107 
108  int track_truth = track->PID;
109 
110  if (TMath::Abs(track_truth) == 11) {
111  // true charged electron
112  if (gRandom->Uniform(0, 1) <= eIDprob) {
113  TrackIsElectron = true;
114  } else {
115  TrackIsElectron = false;
116  }
117 
118 
119 
120  } else if (TMath::Abs(track_truth) == 211) {
121  // true charged pion
122  if (gRandom->Uniform(0,1) <= ROOT::Math::gaussian_pdf(separation)) {
123  TrackIsElectron = true;
124  } else {
125  TrackIsElectron = false;
126  }
127 
128  } else {
129  // ignore ALL other species for now
130  TrackIsElectron = false;
131  }
132 
133 
134  return TrackIsElectron;
135 }
136 
137 
138 
139