Skip to content

Commit b8b2b78

Browse files
Merge pull request #314 from AndrewEdmonds11/rooutil-trig
Updates to trigger branch for RooUtil
2 parents dbe1708 + f504c5c commit b8b2b78

14 files changed

Lines changed: 172 additions & 22 deletions

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Table of Contents
44
1. [Introduction](#Introduction)
55
2. [Structure](#Structure)
6-
3. [How to get the version of EventNtuple](#How-to-get-the-version-of-EventNtuple)
6+
3. [How to Check the EventNtuple](#How-to-Check-the-EventNtuple)
77
4. [How to Analyze an EventNtuple](#How-to-Analyze-an-EventNtuple)
88
5. [How to Create an EventNtuple](#How-to-Create-an-EventNtuple)
99
6. [Validation](#Validation)
@@ -24,13 +24,16 @@ A [list of branches is available](./doc/branches.md)
2424

2525
The help understand what all the branches and leaves mean, we have an [```ntuplehelper```](doc/ntuplehelper.md) tool
2626

27-
## How to get the version of EventNtuple that is in a file
28-
For versions of EventNtuple later than v6.3.0, we store the version number in the ROOT file. You can check the version number with the ```checkEventNtuple``` tool:
27+
## How to Check the EventNtuple
28+
You can get some basic information about the EventNtuple file useing ```checkEventNtuple``` like so:
2929

3030
```
3131
checkEventNtuple file1.root file2.root
3232
```
3333

34+
This will print the version number (for versions after v6.3.0) and the trigger branches in the file (for versions after v6.8.0)
35+
36+
3437
## How to Analyze an EventNtuple
3538
To help with analyzing the EventNtuple given its complex structure, we have two sets of utilities:
3639
* [```RooUtil```](rooutil/README.md) for ROOT-based analyses, and

bin/checkEventNtuple

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,35 @@ def main():
1515

1616
foldername = "EventNtuple"
1717
histname = "version"
18+
treename = "ntuple"
1819
for filename in args.filenames:
1920
try:
2021
f = ROOT.TFile(filename, "READ");
2122
if (f.GetListOfKeys().Contains(foldername)):
2223
folder = f.Get(foldername)
23-
if (folder.GetListOfKeys().Contains("version")):
24-
h = f.Get("EventNtuple/version")
24+
# Check version number
25+
if (folder.GetListOfKeys().Contains(histname)):
26+
h = f.Get(foldername+"/"+histname)
2527
print("{} contains EventNtuple v{:02.0f}_{:02.0f}_{:02.0f}".format(filename, h.GetBinContent(1), h.GetBinContent(2), h.GetBinContent(3)))
2628
else:
2729
print("{} histogram does not exist in {} (it is either v06_02_00 or older)".format(histname, filename))
30+
31+
# Print triggers
32+
if (folder.GetListOfKeys().Contains(treename)):
33+
t = f.Get(foldername+"/"+treename)
34+
print("\nIt contains the following trigger paths:")
35+
for br in t.GetListOfBranches():
36+
if "trig_" in br.GetName():
37+
print(f" - {br.GetName()}")
38+
print("For trigger definitions, please contact the Trigger group.")
39+
else:
40+
print("{} tree does not exist in {}...".format(treename, filename))
2841
else:
2942
print("{}/ folder does not exist in {}".format(foldername, filename))
3043
except OSError:
3144
print("{} threw an OSError (does it exist?)".format(filename))
3245

46+
print("\nFor any questions about EventNtuple, please contact the Analysis Tools group.")
47+
3348
if __name__ == "__main__":
3449
main()

doc/branches.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ The branch is empty if there are no CRV hit during the event.
9898
| crvcoincs | Vector branch | information about a cluster of CRV coincidence triplets| [see CrvHitInfoReco.hh](../inc/CrvHitInfoReco.hh)
9999
| crvcoincsmc | Vector branch | information about the MC track which most likely caused the CRV coincidence triplets| [see CrvHitInfoMC.hh](../inc/CrvHitInfoMC.hh)
100100
| crvcoincsmcplane | Vector branch | information about the point where the MC trajectory crosses the xz plane of CRV-T| [see CrvPlaneInfoMC.hh](../inc/CrvPlaneInfoMC.hh)
101+
## Trigger Branches
102+
103+
Each element in these branch corresponds to a different Kalman fit hypotheses to reconstruct the track:
104+
105+
Trigger branches are prefixed with ```trig_```. To find the names of the trigger branches run ```checkEventNtuple filename.root```
101106
## Deprecated Branches
102107

103108
These branches are remnants from trkana and are deprecated.

helper/ntuplehelper.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,15 @@ def list_all_branches(self, export_to_md=False):
230230
tokens=explanation.split(":")
231231
print("| " + tokens[0] + " | " + tokens[1] + " | " + tokens[2] + "| [see " + struct_file + "](../inc/"+struct_file+")")
232232

233+
if not export_to_md:
234+
print("\nTrigger Branches")
235+
print("================")
236+
print("Trigger branches are prefixed with \"trig_\". To find the names of the trigger branches run \"checkEventNtuple filename.root\"")
237+
else:
238+
print("## Trigger Branches\n")
239+
print("Each element in these branch corresponds to a different Kalman fit hypotheses to reconstruct the track:\n")
240+
print("Trigger branches are prefixed with ```trig_```. To find the names of the trigger branches run ```checkEventNtuple filename.root```")
241+
233242
if not export_to_md:
234243
print("\nDeprecated Branches")
235244
print("================")

inc/TrigInfo.hh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ namespace mu2e
99
{
1010
struct TrigInfo {
1111

12-
static const unsigned int ntrig_ = 30;
12+
static const unsigned int ntrig_ = 30;
13+
14+
bool _triggerArray[ntrig_];
1315

14-
UChar_t _triggerArray[ntrig_];
15-
1616
void reset() { *this = TrigInfo(); }
1717
};
1818
}

rooutil/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ Some branches are not contained in any of the above classes:
113113
* ```crvpulses``` and ```crvpulsesmc```
114114
* ```crvcoincsmcplane```
115115
* ```calohits```, ```calorecodigis```, ```calodigis```
116+
* ```trig_``` branches
116117

117-
Reach out to the developers on the #analysis-tools Slack channel if you have a need to have these added somewhere.
118+
Reach out to the developers on the #analysis-tools Slack channel if you need to have these added somewhere.
118119

119120
## Accessing User-Friendly Classes
120121
The ```Event``` class provides access to ```Tracks``` and ```CrvCoincs```:
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
11+
void PlotEntranceMomentumTriggeredEvents(std::string filename) {
12+
13+
// Create the histogram you want to fill
14+
TH1F* hRecoMomAll = new TH1F("hRecoMomAll", "Reconstructed Momentum at Tracker Entrance", 50,95,110);
15+
TH1F* hRecoMom_tprDe_highP_stopTarg = new TH1F("hRecoMom_tprDe_highP_stopTarg", "Reconstructed Momentum at Tracker Entrance", 50,95,110);
16+
TH1F* hRecoMom_tprDe_highP = new TH1F("hRecoMom_tprDe_highP", "Reconstructed Momentum at Tracker Entrance", 50,95,110);
17+
18+
// Set up RooUtil
19+
RooUtil util(filename);
20+
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+
// Get the track segments at the tracker entrance
33+
auto trk_ent_segments = track.GetSegments([](TrackSegment& segment){ return tracker_entrance(segment) && has_reco_step(segment); });
34+
35+
// Loop through the tracker entrance track segments
36+
for (auto& segment : trk_ent_segments) {
37+
38+
// Fill the histogram
39+
hRecoMomAll->Fill(segment.trkseg->mom.R());
40+
41+
if (passes_trigger(event, "tprDe_highP_stopTarg")) {
42+
hRecoMom_tprDe_highP_stopTarg->Fill(segment.trkseg->mom.R());
43+
}
44+
if (passes_trigger(event, "tprDe_highP_stopTarg")) {
45+
hRecoMom_tprDe_highP->Fill(segment.trkseg->mom.R());
46+
}
47+
}
48+
}
49+
}
50+
51+
// Draw the histogram
52+
hRecoMomAll->SetLineColor(kBlack);
53+
hRecoMomAll->SetLineWidth(2);
54+
hRecoMomAll->Draw("HIST E");
55+
56+
hRecoMom_tprDe_highP->SetLineColor(kBlue);
57+
hRecoMom_tprDe_highP->SetLineWidth(2);
58+
hRecoMom_tprDe_highP->Draw("HIST E SAME");
59+
60+
hRecoMom_tprDe_highP_stopTarg->SetLineColor(kRed);
61+
hRecoMom_tprDe_highP_stopTarg->SetLineWidth(2);
62+
hRecoMom_tprDe_highP_stopTarg->Draw("HIST E SAME");
63+
64+
}

rooutil/examples/PrintEvents.C

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,5 +249,11 @@ void PrintEvents(std::string filename) {
249249
std::cout << "calodigi: " << calodigi.SiPMID_ << ", " << calodigi.t0_ << ", " << calodigi.peakpos_ << ", " << calodigi.caloRecoDigiIdx_ << std::endl;
250250
}
251251
}
252+
253+
// trigger branches
254+
for (const auto pair : event.trigNameMap) {
255+
std::cout << pair.first << ": " << event.triginfo._triggerArray[pair.second] << std::endl;
256+
}
257+
252258
}
253259
}

rooutil/inc/Event.hh

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
#include "EventNtuple/inc/MVAResultInfo.hh"
3737

38+
#include "EventNtuple/inc/TrigInfo.hh"
39+
3840
#include "EventNtuple/rooutil/inc/Track.hh"
3941
#include "EventNtuple/rooutil/inc/CrvCoinc.hh"
4042
#include "EventNtuple/rooutil/inc/CaloCluster.hh"
@@ -43,7 +45,6 @@
4345

4446
struct Event {
4547
Event(TChain* ntuple) {
46-
4748
if (ntuple->GetBranch("evtinfo")) {
4849
ntuple->SetBranchAddress("evtinfo", &this->evtinfo);
4950
}
@@ -53,6 +54,16 @@ struct Event {
5354
if (ntuple->GetBranch("crvsummary")) {
5455
ntuple->SetBranchAddress("crvsummary", &this->crvsummary);
5556
}
57+
const auto& branches = ntuple->GetListOfBranches();
58+
int i_trig_branch = 0;
59+
for (const auto& branch : *branches) {
60+
std::string brname = branch->GetName();
61+
if (brname.substr(0, 5) == "trig_") {
62+
ntuple->SetBranchAddress(brname.c_str(), &this->triginfo._triggerArray[i_trig_branch]);
63+
trigNameMap.insert({brname, i_trig_branch});
64+
i_trig_branch++;
65+
}
66+
}
5667

5768
if (ntuple->GetBranch("trk")) {
5869
ntuple->SetBranchAddress("trk", &this->trk);
@@ -363,6 +374,7 @@ struct Event {
363374
mu2e::HitCount* hitcount = nullptr;
364375
mu2e::CrvSummaryReco* crvsummary = nullptr;
365376
mu2e::CrvSummaryMC* crvsummarymc = nullptr;
377+
mu2e::TrigInfo triginfo; // not a pointer because we give the address of array elements inside this
366378

367379
std::vector<mu2e::TrkInfo>* trk = nullptr;
368380
std::vector<mu2e::TrkInfoMC>* trkmc = nullptr;
@@ -393,6 +405,9 @@ struct Event {
393405
std::vector<mu2e::CrvPlaneInfoMC>* crvcoincsmcplane = nullptr;
394406

395407
std::vector<std::vector<mu2e::SimInfo>>* trkmcsim = nullptr;
408+
409+
// Need to keep track of trigger name to element in triginfo
410+
std::map<std::string, unsigned int> trigNameMap;
396411
};
397412

398413
#endif

rooutil/inc/RooUtil.hh

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,16 @@ public:
4747

4848
void SetVersionNumber(std::string filename) {
4949
TFile* file = new TFile(filename.c_str(), "READ");
50-
TH1I* hVersion = (TH1I*) file->Get("EventNtuple/version");
51-
if (!hVersion) {
50+
TH1I* version = (TH1I*) file->Get("EventNtuple/version");
51+
if (!version) {
5252
std::cout << "Warning: this EventNtuple file does not contain a version number. It is either v06_02_00 or older. This is just a warning..." << std::endl;
5353
}
5454
else {
55-
majorVer = hVersion->GetBinContent(1);
56-
minorVer = hVersion->GetBinContent(2);
57-
patchVer = hVersion->GetBinContent(3);
55+
hVersion = (TH1I*) version->Clone();
56+
hVersion->SetDirectory(0);
57+
int majorVer = hVersion->GetBinContent(1);
58+
int minorVer = hVersion->GetBinContent(2);
59+
int patchVer = hVersion->GetBinContent(3);
5860
std::cout << "EventNtuple v" << std::setw(2) << std::setfill('0') << majorVer << "_"
5961
<< std::setw(2) << std::setfill('0') << minorVer << "_"
6062
<< std::setw(2) << std::setfill('0') << patchVer << std::endl;
@@ -140,6 +142,12 @@ public:
140142

141143
if(event->trkmcsim) { output_ntuple->Branch("trkmcsim", event->trkmcsim); }
142144

145+
for (const auto pair : event->trigNameMap) {
146+
output_ntuple->Branch(pair.first.c_str(), &event->triginfo._triggerArray[pair.second]);
147+
}
148+
149+
// Write out histograms from input to output
150+
hVersion->Write();
143151
}
144152

145153
void FillOutputEventNtuple() {
@@ -151,9 +159,7 @@ private:
151159
Event* event; // holds all the variables for SetBranchAddress
152160
bool debug;
153161

154-
int majorVer;
155-
int minorVer;
156-
int patchVer;
162+
TH1I* hVersion;
157163

158164
TTree* output_ntuple; // for output
159165
};

0 commit comments

Comments
 (0)