Skip to content

Commit 03397f7

Browse files
Merge pull request #315 from AndrewEdmonds11/trkpid-rooutil
Add trkpid branch to RooUtil
2 parents b8b2b78 + 1ea6ca2 commit 03397f7

9 files changed

Lines changed: 76 additions & 3 deletions

File tree

doc/branches.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ If a Kalman fit fails or there are multiple downstream tracks to fit, the number
3535
| trkcalohit | Vector branch | the calorimeter cluster assigned to a track| [see TrkCaloHitInfo.hh](../inc/TrkCaloHitInfo.hh)
3636
| trkcalohitmc | Vector branch | MC-truth infromation for calorimeter clusters| [see CaloClusterInfoMC.hh](../inc/CaloClusterInfoMC.hh)
3737
| trkqual | Vector branch | the output of a multi-variate analysis (MVA)| [see MVAResultInfo.hh](../inc/MVAResultInfo.hh)
38+
| trkpid | Vector branch | the output of a multi-variate analysis (MVA)| [see MVAResultInfo.hh](../inc/MVAResultInfo.hh)
3839
## Track segments Branches
3940

4041
These branches contain 4 elements per event corresponding to different Kalman fit hypotheses (see Track branches).

helper/ntuplehelper.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
class nthelper:
44

55
single_object_branches = ['evtinfo', 'evtinfomc', 'hitcount', 'tcnt', 'crvsummary', 'crvsummarymc']
6-
vector_object_branches = ['trk', 'trkmc', 'trkcalohit', 'trkcalohitmc', 'caloclusters', 'calohits', 'calorecodigis', 'calodigis', 'crvcoincs', 'crvcoincsmc', 'crvcoincsmcplane', 'trkqual']
6+
vector_object_branches = ['trk', 'trkmc', 'trkcalohit', 'trkcalohitmc', 'caloclusters', 'calohits', 'calorecodigis', 'calodigis', 'crvcoincs', 'crvcoincsmc', 'crvcoincsmcplane', 'trkqual', 'trkpid']
77
vector_vector_object_branches = ['trksegs', 'trksegpars_lh', 'trksegpars_ch', 'trksegpars_kl', 'trkmcsim', 'trkhits', 'trkhitsmc', 'trkmats', 'trkhitcalibs', 'trkmcsci', 'trkmcssi', 'trksegsmc' ]
88

99
evt_branches = ['evtinfo','evtinfomc','hitcount','tcnt']
10-
trk_branches = ['trk', 'trkmc', 'trkcalohit', 'trkcalohitmc', 'trkqual']
10+
trk_branches = ['trk', 'trkmc', 'trkcalohit', 'trkcalohitmc', 'trkqual', 'trkpid']
1111
trksegs_branches = ['trksegs', 'trksegpars_lh', 'trksegpars_ch', 'trksegpars_kl', 'trksegsmc']
1212
straw_branches = ['trkhits', 'trkmats', 'trkhitsmc', 'trkhitcalibs']
1313
mc_branches = ['trkmcsim']
@@ -56,6 +56,7 @@ class nthelper:
5656
"crvcoincsmc" : "CrvHitInfoMC",
5757
"crvcoincsmcplane" : "CrvPlaneInfoMC",
5858
"trkqual" : "MVAResultInfo",
59+
"trkpid" : "MVAResultInfo",
5960
"helices" : "HelixInfo",
6061
"trksegsmc" : "SurfaceStepInfo"
6162
}

rooutil/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Because some vector-object branches in the EventNtuple should be paired and loop
5959
### The ```Track``` Class
6060
The ```Track``` class contains all information related to a single track
6161

62-
* single objects: ```trk```, ```trkmc```, ```trkcalohit```, ```trkqual```
62+
* single objects: ```trk```, ```trkmc```, ```trkcalohit```, ```trkqual```, ```trkpid```
6363
* vectors: ```trksegs```, ```trksegmcs```, ```trksegpars_{lh,ch,kl}```, ```trkmcsim```, ```trkhits```, ```trkhitsmc```, ```trkmats```, ```trkhitcalibs```
6464

6565
Example: [PlotTrackNHits_RecoVsTrue.C](./examples/PlotTrackNHits_RecoVsTrue.C)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//
2+
// An example of how to plot the momentum of electrons at the tracker entrance
3+
// This uses cut functions defined in common_cuts.hh
4+
//
5+
6+
#include "EventNtuple/rooutil/inc/RooUtil.hh"
7+
#include "EventNtuple/rooutil/inc/common_cuts.hh"
8+
9+
#include "TH1F.h"
10+
#include "TCanvas.h"
11+
12+
void PlotEoverP_TrkPIDCut(std::string filename) {
13+
14+
// Create the histogram you want to fill
15+
TH1F* hEoverP_All = new TH1F("hEoverP_All", "E / p", 200,0, 1);
16+
TH1F* hEoverP_TrkPIDCut = new TH1F("hEoverP_TrkPIDCut", "E / p", 200,0, 1);
17+
18+
// Set up RooUtil
19+
RooUtil util(filename);
20+
// util.Debug(true);
21+
// Loop through the events
22+
for (int i_event = 0; i_event < util.GetNEvents(); ++i_event) {
23+
// Get the next event
24+
auto& event = util.GetEvent(i_event);
25+
26+
// Get the e_minus tracks from the event
27+
auto e_minus_tracks = event.GetTracks(is_e_minus);
28+
29+
// Loop through the e_minus tracks
30+
for (auto& track : e_minus_tracks) {
31+
32+
double EoverP = track.trkcalohit->edep / track.trkcalohit->mom.R();
33+
hEoverP_All->Fill(EoverP);
34+
35+
if (passes_trkpid(track, 0.8)) {
36+
hEoverP_TrkPIDCut->Fill(EoverP);
37+
}
38+
}
39+
}
40+
41+
// Draw the histogram
42+
TCanvas* c1 = new TCanvas();
43+
hEoverP_All->SetLineColor(kBlack);
44+
hEoverP_All->Draw("HIST E");
45+
46+
hEoverP_TrkPIDCut->SetLineColor(kRed);
47+
hEoverP_TrkPIDCut->Draw("HIST E SAME");
48+
}

rooutil/examples/PrintEvents.C

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ void PrintEvents(std::string filename) {
108108
}
109109
}
110110

111+
// trkpid branch
112+
if (event.trkpid != nullptr) {
113+
for (const auto& trkpid : *(event.trkpid)) {
114+
std::cout << "trkpid: " << trkpid.valid << ", " << trkpid.result << std::endl;
115+
}
116+
}
117+
111118
// trksegpars_lh
112119
if (event.trksegpars_lh != nullptr) { // might not have this branch
113120
for (const auto& track : *(event.trksegpars_lh)) {

rooutil/inc/Event.hh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ struct Event {
8383
if (ntuple->GetBranch("crvcoincs")) {
8484
ntuple->SetBranchAddress("crvcoincs", &this->crvcoincs);
8585
}
86+
if (ntuple->GetBranch("trkpid")) {
87+
ntuple->SetBranchAddress("trkpid", &this->trkpid);
88+
}
8689

8790
// Check if the MC branches exist
8891
if (ntuple->GetBranch("evtinfomc")) {
@@ -211,6 +214,10 @@ struct Event {
211214
if (debug) { std::cout << "Event::Update(): Adding trkqual_alt to Track " << i_track << "... " << std::endl; }
212215
track.trkqual_alt = &(trkqual_alt->at(i_track));
213216
}
217+
if (trkpid != nullptr) {
218+
if (debug) { std::cout << "Event::Update(): Adding trkpid to Track " << i_track << "... " << std::endl; }
219+
track.trkpid = &(trkpid->at(i_track));
220+
}
214221

215222
if (debug) { std::cout << "Event::Update(): Updating Track " << i_track << "... " << std::endl; }
216223
track.Update(debug);
@@ -284,6 +291,7 @@ struct Event {
284291
if (trkcalohit) { trkcalohit->erase(trkcalohit->begin()+trks_to_remove[i_trk]); }
285292
if (trkqual) { trkqual->erase(trkqual->begin()+trks_to_remove[i_trk]); }
286293
if (trkqual_alt) { trkqual_alt->erase(trkqual_alt->begin()+trks_to_remove[i_trk]); }
294+
if (trkpid) { trkpid->erase(trkpid->begin()+trks_to_remove[i_trk]); }
287295
if (trksegpars_lh) { trksegpars_lh->erase(trksegpars_lh->begin()+trks_to_remove[i_trk]); }
288296
if (trksegpars_ch) { trksegpars_ch->erase(trksegpars_ch->begin()+trks_to_remove[i_trk]); }
289297
if (trksegpars_kl) { trksegpars_kl->erase(trksegpars_kl->begin()+trks_to_remove[i_trk]); }
@@ -382,6 +390,7 @@ struct Event {
382390
std::vector<mu2e::CaloClusterInfoMC>* trkcalohitmc = nullptr;
383391
std::vector<mu2e::MVAResultInfo>* trkqual = nullptr;
384392
std::vector<mu2e::MVAResultInfo>* trkqual_alt = nullptr; // an optional trkqual branch to also use
393+
std::vector<mu2e::MVAResultInfo>* trkpid = nullptr;
385394
std::vector<std::vector<mu2e::TrkSegInfo>>* trksegs = nullptr;
386395
std::vector<std::vector<mu2e::SurfaceStepInfo>>* trksegsmc = nullptr;
387396
std::vector<std::vector<mu2e::LoopHelixInfo>>* trksegpars_lh = nullptr;

rooutil/inc/RooUtil.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public:
118118
if(event->trkcalohitmc) { output_ntuple->Branch("trkcalohitmc", event->trkcalohitmc); }
119119
if(event->trkqual) { output_ntuple->Branch("trkqual", event->trkqual); }
120120
if(event->trkqual_alt) { output_ntuple->Branch("trkqual_alt", event->trkqual_alt); }
121+
if(event->trkpid) { output_ntuple->Branch("trkpid", event->trkpid); }
121122
if(event->trksegs) { output_ntuple->Branch("trksegs", event->trksegs); }
122123
if(event->trksegsmc) { output_ntuple->Branch("trksegsmc", event->trksegsmc); }
123124
if(event->trksegpars_lh) { output_ntuple->Branch("trksegpars_lh", event->trksegpars_lh); }

rooutil/inc/Track.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ struct Track {
177177
std::vector<mu2e::SimInfo>* trkmcsim = nullptr;
178178
mu2e::MVAResultInfo* trkqual = nullptr;
179179
mu2e::MVAResultInfo* trkqual_alt = nullptr; // TODO: is there a way to allow for more than two...
180+
mu2e::MVAResultInfo* trkpid = nullptr;
180181
};
181182

182183
typedef std::function<bool(Track&)> TrackCut;

rooutil/inc/common_cuts.hh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@ bool passes_trkqual(Track& track, double cut_val) { // true if trkqual > cut_val
184184
else { return false; }
185185
}
186186

187+
bool passes_trkpid(Track& track, double cut_val) { // true if trkpid > cut_val
188+
if (track.trkpid->result > cut_val) { return true; }
189+
else { return false; }
190+
}
191+
187192
//+ CrvCoinc Cuts
188193
bool three_of_four_coinc(CrvCoinc& crv_coinc) { // CRV coincidence has exactly three layers hit
189194
if (crv_coinc.reco->nLayers == 3) { return true; }

0 commit comments

Comments
 (0)