Skip to content

Commit 191fbeb

Browse files
Add mcsteps_virtualdetector branch to RooUtil
1 parent 2f2282b commit 191fbeb

5 files changed

Lines changed: 61 additions & 8 deletions

File tree

rooutil/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ Some branches are not contained in any of the above classes:
114114
* ```crvcoincsmcplane```
115115
* ```calohits```, ```calorecodigis```, ```calodigis```
116116
* ```trig_``` branches
117+
* ```mcsteps_virtualdetector```
117118

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

@@ -224,23 +225,22 @@ Beware: there are a lot of debug messages.
224225
If a new branch is added to the EventNtuple, then the following needs to be done to so that RooUtil can access the branch:
225226

226227
1. In [Event.hh](inc/Event.hh) add the pointers at the bottom of the file
227-
2. In [Event.hh](inc/Event.hh) constructor, set the branch address
228-
- make sure to test that the branch exists
229-
3. In [Event.hh](inc/Event.hh) add the #include to the underlying object
228+
2. In [Event.hh](inc/Event.hh) constructor, set the branch address using the ```CheckForBranch()``` function
229+
3. In [Event.hh](inc/Event.hh) add the #include to the underlying info struct
230230
4. In [RooUtil.hh](inc/RooUtil.hh) add it to the ```CreateOutputEventNtuple()``` function
231231
5. Add to validation places:
232232
- [PrintEvents.C](examples/PrintEvents.C): at least the first and last leaf in the struct
233233
- [create_val_file_rooutil.C](../../validation/create_val_file_rooutil.C)
234234
- copy contents of struct into place where histograms are defined
235235
- then copy and replace "type " with "TH1F* h_branchname_" (e.g. "float " with "TH1F* h_trkcalohit_")
236-
- then copy in " = new TH1F("h_branchname_", "", 100,0,100); //"
236+
- then copy in " = new TH1F("h_branchname_", "", 100,0,100); //" after the histogram name
237237
- delete line after "//"
238238
- add in leaf names to histname (and make separate x, y, z histograms for XYZVectorF leaves)
239239
- copy histogram lines into main loop
240-
- search and replace "TH1F* " with ""
241-
- search and replace " = new TH1F("h_" with "->Fill("
242-
- search and replace "", "", 100,0,100);" with ");"
243-
- search and replace "(branchname_" with "(branchname."
240+
- search and replace ```TH1F* ``` (note space) with nothing
241+
- search and replace ``` = new TH1F("h_``` with ```->Fill(```
242+
- search and replace ```", "", 100,0,100);``` with ```);```
243+
- search and replace ```(branchname_``` with ```(branchname.``` in the ```Fill()``` commands
244244
- update histogram ranges
245245
6. (Optional) If appropriate, add branches to other classes (e.g. Track.hh) and to ```Event::Update()```
246246
- be sure to test it with an example script

rooutil/examples/PrintEvents.C

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,5 +263,10 @@ void PrintEvents(std::string filename) {
263263
std::cout << pair.first << ": " << event.trigger.Fired(pair.second) << std::endl;
264264
}
265265

266+
// mcsteps_virtualdetector branch
267+
if (event.mcsteps_virtualdetector != nullptr) {
268+
for (const auto& vdstep : *(event.mcsteps_virtualdetector)) {
269+
std::cout << "vdstep: " << vdstep.vid << ", " << vdstep.time << ", " << vdstep.mom << ", " << vdstep.pos << ", " << vdstep.pdg << ", " << vdstep.startCode << ", " << vdstep.stopCode << std::endl;
270+
}
266271
}
267272
}

rooutil/inc/Event.hh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "EventNtuple/inc/MVAResultInfo.hh"
3838

3939
#include "EventNtuple/inc/TrigInfo.hh"
40+
#include "EventNtuple/inc/MCStepInfo.hh"
4041

4142
#include "EventNtuple/rooutil/inc/Track.hh"
4243
#include "EventNtuple/rooutil/inc/CrvCoinc.hh"
@@ -87,6 +88,7 @@ namespace rooutil {
8788
CheckForBranch(ntuple, "calorecodigis", &this->calorecodigis);
8889
CheckForBranch(ntuple, "calodigis", &this->calodigis);
8990

91+
CheckForBranch(ntuple, "mcsteps_virtualdetector", &this->mcsteps_virtualdetector);
9092
}
9193

9294
// Check if a branch exists in the TChain, and optionally set its address
@@ -342,6 +344,7 @@ namespace rooutil {
342344
std::vector<mu2e::CrvPlaneInfoMC>* crvcoincsmcplane = nullptr;
343345

344346
std::vector<std::vector<mu2e::SimInfo>>* trkmcsim = nullptr;
347+
std::vector<mu2e::MCStepInfo>* mcsteps_virtualdetector = nullptr; // TODO: EventNtuple could have other mcsteps_* branches but for the time being just hardcode for the virtualdetector ones
345348
};
346349
} // namespace rooutil
347350
#endif

rooutil/inc/RooUtil.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ namespace rooutil {
148148
output_ntuple->Branch(("trig_" + pair.first).c_str(), &event->triginfo._triggerArray[pair.second]);
149149
}
150150

151+
if (event->mcsteps_virtualdetector) { output_ntuple->Branch("mcsteps_virtualdetector", event->mcsteps_virtualdetector); }
152+
151153
// Write out histograms from input to output
152154
hVersion->Write();
153155
}

validation/create_val_file_rooutil.C

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,25 @@ void create_val_file_rooutil(std::string filename, std::string outfilename) {
505505
TH1F* h_calodigis_caloRecoDigiIdx_ = new TH1F("h_calodigis_caloRecoDigiIdx_", "", 100,0,100);
506506

507507
TH1F* h_triginfo = new TH1F("h_triginfo", "", mu2e::TrigInfo::ntrig_,0,mu2e::TrigInfo::ntrig_);
508+
509+
TH1F* h_mcsteps_virtualdetector_vid = new TH1F("h_mcsteps_virtualdetector_vid", "", 150,0,150);
510+
TH1F* h_mcsteps_virtualdetector_sid = new TH1F("h_mcsteps_virtualdetector_sid", "", 100,0,100);
511+
TH1F* h_mcsteps_virtualdetector_iinter = new TH1F("h_mcsteps_virtualdetector_iinter", "", 100,0,100);
512+
TH1F* h_mcsteps_virtualdetector_time = new TH1F("h_mcsteps_virtualdetector_time", "", 100,0,2000);
513+
TH1F* h_mcsteps_virtualdetector_de = new TH1F("h_mcsteps_virtualdetector_de", "", 100,0,200);
514+
TH1F* h_mcsteps_virtualdetector_dp = new TH1F("h_mcsteps_virtualdetector_dp", "", 100,0,200);
515+
TH1F* h_mcsteps_virtualdetector_early = new TH1F("h_mcsteps_virtualdetector_early", "", 2,0,2);
516+
TH1F* h_mcsteps_virtualdetector_late = new TH1F("h_mcsteps_virtualdetector_late", "", 2,0,2);
517+
TH1F* h_mcsteps_virtualdetector_mom_x = new TH1F("h_mcsteps_virtualdetector_mom_x", "", 100,-200,200);
518+
TH1F* h_mcsteps_virtualdetector_mom_y = new TH1F("h_mcsteps_virtualdetector_mom_y", "", 100,-200,200);
519+
TH1F* h_mcsteps_virtualdetector_mom_z = new TH1F("h_mcsteps_virtualdetector_mom_z", "", 320,-200,200);
520+
TH1F* h_mcsteps_virtualdetector_pos_x = new TH1F("h_mcsteps_virtualdetector_pos_x", "", 100,-1000,1000);
521+
TH1F* h_mcsteps_virtualdetector_pos_y = new TH1F("h_mcsteps_virtualdetector_pos_y", "", 100,-1000,1000);
522+
TH1F* h_mcsteps_virtualdetector_pos_z = new TH1F("h_mcsteps_virtualdetector_pos_z", "", 320,-1600,1600);
523+
TH1F* h_mcsteps_virtualdetector_pdg = new TH1F("h_mcsteps_virtualdetector_pdg", "", 100,0,100);
524+
TH1F* h_mcsteps_virtualdetector_startCode = new TH1F("h_mcsteps_virtualdetector_startCode", "", 100,0,100);
525+
TH1F* h_mcsteps_virtualdetector_stopCode = new TH1F("h_mcsteps_virtualdetector_stopCode", "", 100,0,100);
526+
508527
// Grab the first event to name the bins
509528
const auto& evt = util.GetEvent(0);
510529
for (const auto pair : evt.trigger.NameToIndexMap()) {
@@ -1153,6 +1172,30 @@ void create_val_file_rooutil(std::string filename, std::string outfilename) {
11531172
h_triginfo->AddBinContent(i_trig+1, event.triginfo._triggerArray[i_trig]);
11541173
}
11551174

1175+
// Creating mcsteps_virtualdetector histogram
1176+
std::cout << "Creating mcsteps_virtualdetector histogram" << std::endl;
1177+
if (event.mcsteps_virtualdetector != nullptr) {
1178+
for (const auto& vdstep : *(event.mcsteps_virtualdetector)) {
1179+
h_mcsteps_virtualdetector_vid->Fill(mcsteps_virtualdetector.vid);
1180+
h_mcsteps_virtualdetector_sid->Fill(mcsteps_virtualdetector.sid);
1181+
h_mcsteps_virtualdetector_iinter->Fill(mcsteps_virtualdetector.iinter);
1182+
h_mcsteps_virtualdetector_time->Fill(mcsteps_virtualdetector.time);
1183+
h_mcsteps_virtualdetector_de->Fill(mcsteps_virtualdetector.de);
1184+
h_mcsteps_virtualdetector_dp->Fill(mcsteps_virtualdetector.dp);
1185+
h_mcsteps_virtualdetector_early->Fill(mcsteps_virtualdetector.early);
1186+
h_mcsteps_virtualdetector_late->Fill(mcsteps_virtualdetector.late);
1187+
h_mcsteps_virtualdetector_mom_x->Fill(mcsteps_virtualdetector.mom.x());
1188+
h_mcsteps_virtualdetector_mom_y->Fill(mcsteps_virtualdetector.mom.y());
1189+
h_mcsteps_virtualdetector_mom_z->Fill(mcsteps_virtualdetector.mom.z());
1190+
h_mcsteps_virtualdetector_pos_x->Fill(mcsteps_virtualdetector.pos.x());
1191+
h_mcsteps_virtualdetector_pos_y->Fill(mcsteps_virtualdetector.pos.y());
1192+
h_mcsteps_virtualdetector_pos_z->Fill(mcsteps_virtualdetector.pos.z());
1193+
h_mcsteps_virtualdetector_pdg->Fill(mcsteps_virtualdetector.pdg);
1194+
h_mcsteps_virtualdetector_startCode->Fill(mcsteps_virtualdetector.startCode);
1195+
h_mcsteps_virtualdetector_stopCode->Fill(mcsteps_virtualdetector.stopCode);
1196+
1197+
}
1198+
}
11561199
}
11571200

11581201
file->Write();

0 commit comments

Comments
 (0)