EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
KaonPIDModule.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file KaonPIDModule.cc
1 #include "KaonPIDModule.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 
12  : Module(data)
13 {
14 
15 }
16 
18 {
19 
20 }
21 
22 
23 
24 bool KaonPIDModule::execute(std::map<std::string, std::any>* DataStore)
25 {
26  auto data = getData();
27 
28  // If event contains at least 1 jet
29  // std::vector<Jet*> all_jets;
30  // for (int ijet = 0; ijet < getJets()->GetEntries(); ijet++)
31  // {
32  // // Take first jet
33  // Jet *jet = (Jet*) getJets()->At(ijet);
34  // all_jets.push_back(jet);
35  // }
36 
37  // std::vector<Jet*> fiducial_jets = SelectorFcn<Jet>(all_jets, [](Jet* j){ return (TMath::Abs(j->Eta) < 3.0 && j->PT > 5.0); });
38  // std::vector<Jet*> charmJets = SelectorFcn<Jet>(fiducial_jets, [](Jet* j){ return (j->Flavor == 4); });
39 
40  std::vector<Track*> all_kaons;
41 
42 
43  if (DataStore->find("TracksForPID") != DataStore->end()) {
44  for (auto track : std::any_cast<std::vector<Track*>>((*DataStore)["TracksForPID"])) {
45  if (KaonPID(track, 0.90, 3.0))
46  all_kaons.push_back(track);
47  }
48 
49 
50  } else {
51  for (int itrk = 0; itrk < getEFlowTracks()->GetEntries(); itrk++)
52  {
53  Track* track = (Track*) getEFlowTracks()->At(itrk);
54  if (KaonPID(track, 0.90, 3.0))
55  all_kaons.push_back(track);
56  }
57 
58  std::vector<Track*> tracks_for_PID;
59  for (int itrk = 0; itrk < getEFlowTracks()->GetEntries(); itrk++)
60  {
61  Track* track = (Track*) getEFlowTracks()->At(itrk);
62  tracks_for_PID.push_back(track);
63  }
64  (*DataStore)["TracksForPID"] = tracks_for_PID;
65  }
66 
67  //auto reconstructed_kaons = all_kaons;
68  std::vector<Track*> reconstructed_kaons = SelectorFcn<Track>(all_kaons, [](Track* t){ return (t->PT >= 0.1); });
69 
70  std::vector<Track*> tracks_for_PID = std::any_cast<std::vector<Track*>>((*DataStore)["TracksForPID"]);
71  for (auto kaon : reconstructed_kaons) {
72  tracks_for_PID.erase(std::find(tracks_for_PID.begin(), tracks_for_PID.end(), kaon));
73  }
74  (*DataStore)["TracksForPID"] = tracks_for_PID;
75 
76 
77  (*DataStore)["Kaons"] = reconstructed_kaons;
78 
79 
80  return true;
81 }
82 
83 
84 bool KaonPIDModule::KaonPID(Track* track, float kIDprob, float separation)
85 {
86  bool TrackIsKaon = false;
87 
88 
89  // Apply a basic parameterized kaon PID to tracks. If the track is really a
90  // kaon from truth information, apply a flat ID probability. If it's a pion,
91  // use the separation (in Gaussian sigma) to determine if it's mis-identified.
92 
93  if (track->PT < 0.1)
94  return TrackIsKaon;
95 
96  int track_truth = track->PID;
97 
98  if (TMath::Abs(track_truth) == 321) {
99  // true charged kaon
100  if (gRandom->Uniform(0, 1) <= kIDprob) {
101  TrackIsKaon = true;
102  } else {
103  TrackIsKaon = false;
104  }
105 
106 
107 
108  } else if (TMath::Abs(track_truth) == 211) {
109  // true charged pion
110  if (gRandom->Uniform(0,1) <= ROOT::Math::gaussian_pdf(separation)) {
111  TrackIsKaon = true;
112  } else {
113  TrackIsKaon = false;
114  }
115 
116  } else {
117  // ignore ALL other species for now
118  TrackIsKaon = false;
119  }
120 
121 
122  return TrackIsKaon;
123 }
124 
125 
126 
127