File indexing completed on 2024-11-16 09:02:33
0001 #include "ElectronPIDModule.h"
0002
0003 #include "TClonesArray.h"
0004 #include "TRandom3.h"
0005 #include "Math/PdfFuncMathCore.h"
0006
0007 #include "AnalysisFunctions.cc"
0008
0009 #include <iostream>
0010 #include <algorithm>
0011
0012 ElectronPIDModule::ElectronPIDModule(ExRootTreeReader* data)
0013 : Module(data)
0014 {
0015
0016 }
0017
0018 ElectronPIDModule::~ElectronPIDModule()
0019 {
0020
0021 }
0022
0023
0024
0025 bool ElectronPIDModule::execute(std::map<std::string, std::any>* DataStore)
0026 {
0027 auto data = getData();
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041 std::vector<Track*> all_electrons;
0042
0043
0044
0045
0046
0047
0048 float e_efficiency = 0.90;
0049 float epi_separation = 2.4;
0050
0051
0052
0053 if (DataStore->find("TracksForPID") != DataStore->end()) {
0054 for (auto track : std::any_cast<std::vector<Track*>>((*DataStore)["TracksForPID"])) {
0055 if (ElectronPID(track, e_efficiency, epi_separation))
0056 all_electrons.push_back(track);
0057 }
0058
0059
0060 } else {
0061 for (int itrk = 0; itrk < getEFlowTracks()->GetEntries(); itrk++)
0062 {
0063 Track* track = (Track*) getEFlowTracks()->At(itrk);
0064 if (ElectronPID(track, e_efficiency, epi_separation))
0065 all_electrons.push_back(track);
0066 }
0067
0068 std::vector<Track*> tracks_for_PID;
0069 for (int itrk = 0; itrk < getEFlowTracks()->GetEntries(); itrk++)
0070 {
0071 Track* track = (Track*) getEFlowTracks()->At(itrk);
0072 tracks_for_PID.push_back(track);
0073 }
0074 (*DataStore)["TracksForPID"] = tracks_for_PID;
0075 }
0076
0077
0078 std::vector<Track*> reconstructed_electrons = SelectorFcn<Track>(all_electrons,
0079 [](Track* t){ return (t->PT >= 0.1); });
0080
0081 std::vector<Track*> tracks_for_PID = std::any_cast<std::vector<Track*>>((*DataStore)["TracksForPID"]);
0082 for (auto electron : reconstructed_electrons) {
0083 tracks_for_PID.erase(std::find(tracks_for_PID.begin(), tracks_for_PID.end(), electron));
0084 }
0085 (*DataStore)["TracksForPID"] = tracks_for_PID;
0086
0087
0088
0089 (*DataStore)["Electrons"] = reconstructed_electrons;
0090
0091
0092 return true;
0093 }
0094
0095
0096 bool ElectronPIDModule::ElectronPID(Track* track, float eIDprob, float separation)
0097 {
0098 bool TrackIsElectron = false;
0099
0100
0101
0102
0103
0104
0105 if (track->PT < 0.1)
0106 return TrackIsElectron;
0107
0108 int track_truth = track->PID;
0109
0110 if (TMath::Abs(track_truth) == 11) {
0111
0112 if (gRandom->Uniform(0, 1) <= eIDprob) {
0113 TrackIsElectron = true;
0114 } else {
0115 TrackIsElectron = false;
0116 }
0117
0118
0119
0120 } else if (TMath::Abs(track_truth) == 211) {
0121
0122 if (gRandom->Uniform(0,1) <= ROOT::Math::gaussian_pdf(separation)) {
0123 TrackIsElectron = true;
0124 } else {
0125 TrackIsElectron = false;
0126 }
0127
0128 } else {
0129
0130 TrackIsElectron = false;
0131 }
0132
0133
0134 return TrackIsElectron;
0135 }
0136
0137
0138
0139