Skip to content

Commit a3c677e

Browse files
Merge pull request #330 from AndrewEdmonds11/add-vd-steps
Add branch for StepPointMCs
2 parents 63d0ca3 + b93fd85 commit a3c677e

18 files changed

Lines changed: 243 additions & 23 deletions

doc/developers.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ mu2e -c EventNtuple/fcl/from_mcs-mockdata.fcl -s test-art-file.art -n 10
6262

6363
8. Add to ```ntuplehelper```
6464
* instructions [here](./ntuplehelper.md#Adding-a-branch)
65-
9. Add to validation, RooUtil, and PyUtil
66-
* [instructions to be completed... for the time being contact Andy and Sophie for this]
65+
9. Add to validation, RooUtil, and pyutils
66+
* instructions for validation and RooUtil are [here](../rooutil/README.md#For-Developers). Contact Andy for more info if needed
67+
* contact Sophie for pyutils
6768
10. Run validation
6869
* both [test_fcls.sh](../validation/README.md#Validating-EventNtuple-Runs), and
6970
* and [valCompare](../validation/README.md#Validating-EventNtuple-Contents) steps

fcl/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ where ```tier``` is the data tier of the input dataset, ```type``` is the type o
2222
| from_mcs-mockdata_separateTrkBranches.fcl | mock datasets | example on how to separate the tracks into separate branches again|
2323
| from_mcs-mockdata_selectorExample.fcl | mock datasets | example on how to use a selector to select certain types of tracks before putting them into the EventNtuple |
2424
| from_mcs-mixed_trkQualCompare.fcl | reconstructed mixed (i.e. primary+background hits) datasets | shows how to output result of more than one TrkQual |
25+
| from_mcs-primary_addVDSteps.fcl | reconstructed primary (i.e. no background hits) datasets | shows how to add the branch for virtual detector steps |
2526
| from_mcs-DeMCalib.fcl | reconstructed primary or mixed datasets | only writes one track per event |
2627
| from_mcs-OffSpill.fcl | off spill datasets | only contains ```CentralHelix``` tracks (i.e. field-on cosmics) |
2728
| from_dig-mockdata.fcl | mock datasets (digis) | runs reconstruction and creates EventNtuple in one job |
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "EventNtuple/fcl/from_mcs-primary.fcl"
2+
3+
physics.analyzers.EventNtuple.StepPointMCTags : [ "compressRecoMCs:virtualdetector" ]

fcl/prolog.fcl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ EventNtupleMaker : {
319319
ExtraMCStepCollectionTags : []
320320
SurfaceStepCollectionTag : "compressRecoMCs"
321321
FitType : LoopHelix
322+
StepPointMCTags : [ ]
322323
}
323324
# instance for processing trigger (digitization) output from simulation
324325
EventNtupleMakerTTMC: {

helper/ntuplehelper.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
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', 'trkpid']
6+
vector_object_branches = ['trk', 'trkmc', 'trkcalohit', 'trkcalohitmc', 'caloclusters', 'calohits', 'calorecodigis', 'calodigis', 'crvcoincs', 'crvcoincsmc', 'crvcoincsmcplane', 'trkqual', 'trkpid', 'mcsteps']
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']
1010
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']
13-
mc_branches = ['trkmcsim']
13+
trk_mc_branches = [ 'trkmcsim' ]
14+
general_mc_branches = [ 'mcsteps' ]
1415
calo_branches = ['caloclusters', 'calohits', 'calorecodigis', 'calodigis']
1516
crv_branches = ['crvsummary','crvsummarymc','crvcoincs','crvcoincsmc','crvcoincsmcplane']
1617
deprecated_branches = ['trkmcsci','trkmcssi']
@@ -58,7 +59,8 @@ class nthelper:
5859
"trkqual" : "MVAResultInfo",
5960
"trkpid" : "MVAResultInfo",
6061
"helices" : "HelixInfo",
61-
"trksegsmc" : "SurfaceStepInfo"
62+
"trksegsmc" : "SurfaceStepInfo",
63+
"mcsteps" : "MCStepInfo"
6264
}
6365

6466
#
@@ -170,16 +172,34 @@ def list_all_branches(self, export_to_md=False):
170172
print("| " + tokens[0] + " | " + tokens[1] + " | " + tokens[2] + "| [see " + struct_file + "](../inc/"+struct_file+")")
171173

172174
if not export_to_md:
173-
print("\nMonte Carlo Branches")
175+
print("\nTrk Monte Carlo Branches")
174176
print("================")
175177
else:
176-
print("## Monte Carlo Branches\n")
178+
print("## Trk Monte Carlo Branches\n")
177179
print("These branches contain 4 elements per event corresponding to different Kalman fit hypotheses (see Track branches).\n")
178180
print("Within each Kalman fit element, there is a vector containing Monte Carlo truth information about the particle making the track and its parent particles.\n")
179181
print("The vector is sorted in reverse chronological order, such that the last element is the initial particle simulated in GEANT4, and each element before correspond to one of its daughter particles.\n")
180182
print("| branch | structure | explanation | leaf information |")
181183
print("|--------|-----------|-------------|------------------|")
182-
for branch in self.mc_branches:
184+
for branch in self.trk_mc_branches:
185+
explanation = self.get_branch_explanation(branch)
186+
struct = self.branch_struct_dict[branch]
187+
struct_file = struct + ".hh";
188+
if not export_to_md:
189+
print(explanation)
190+
else:
191+
tokens=explanation.split(":")
192+
print("| " + tokens[0] + " | " + tokens[1] + " | " + tokens[2] + "| [see " + struct_file + "](../inc/"+struct_file+")")
193+
194+
if not export_to_md:
195+
print("\nGeneral Monte Carlo Branches")
196+
print("================")
197+
else:
198+
print("## General Monte Carlo Branches\n")
199+
print("These branches contain MC information in the event and are not required to be related to tracks")
200+
print("| branch | structure | explanation | leaf information |")
201+
print("|--------|-----------|-------------|------------------|")
202+
for branch in self.general_mc_branches:
183203
explanation = self.get_branch_explanation(branch)
184204
struct = self.branch_struct_dict[branch]
185205
struct_file = struct + ".hh";

inc/InfoMCStructHelper.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ namespace mu2e {
7575
void fillExtraMCStepInfos(KalSeedMC const& kseedmc, StepPointMCCollection const& mcsteps,
7676
std::vector<MCStepInfos>& mcsics, std::vector<MCStepSummaryInfo>& mcssis);
7777
void fillSurfaceStepInfos(KalSeedMC const& kseedmc, SurfaceStepCollection const& surfsteps,std::vector<SurfaceStepInfo>& ssic);
78-
78+
void fillStepPointMCInfo(StepPointMCCollection const& mcsteps, MCStepInfos& mcstepinfos);
7979
};
8080
}
8181

inc/MCStepInfo.hh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@ namespace mu2e {
1414
float time = 0; // time of this step WRT MC primary proton (ns)
1515
float de = 0; // energy deposit through this step (MeV)
1616
float dp = 0; // momentum magnitude change throw this step (MeV/c)
17-
bool early = false;
18-
bool late = false; // flag if this is the earliest or latest step
17+
bool early = false; // flag if this is the earliest step
18+
bool late = false; // flag if this is the latest step
1919
XYZVectorF mom; // particle momentum at the start of this step
2020
XYZVectorF pos; // particle position at the start of this step
2121
void reset() {*this = MCStepInfo(); }
2222
bool valid() { return vid>=0; }
23+
int pdg = -1; // true PDG code
24+
int startCode = -1; // creation process code
25+
int stopCode = -1; // stop process code
26+
2327
};
2428

2529
using MCStepInfos = std::vector<MCStepInfo>;

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/PlotVDSteps.C

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//
2+
// An example of how to plot reco vs true
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 "TCanvas.h"
10+
#include "TH1F.h"
11+
#include "TH2F.h"
12+
13+
using namespace rooutil;
14+
void PlotVDSteps(std::string filename) {
15+
16+
// Create the histogram you want to fill
17+
TH2F* hVD13_XY = new TH2F("hVD13_XY", "XY position at VD13 (tracker entrance)", 100,-500,500, 100,-500,500);
18+
hVD13_XY->SetXTitle("X (det. coords) [mm]");
19+
hVD13_XY->SetYTitle("Y (det. coords) [mm]");
20+
21+
TH1F* hVD13_Mom = new TH1F("hVD13_Mom", "Momentum at VD13 (tracker entrance)", 120,0,120);
22+
hVD13_Mom->SetXTitle("Momentum [MeV/c]");
23+
24+
// Set up RooUtil
25+
RooUtil util(filename);
26+
27+
// Loop through the events
28+
for (int i_event = 0; i_event < util.GetNEvents(); ++i_event) {
29+
// Get the next event
30+
auto& event = util.GetEvent(i_event);
31+
32+
// Get the e_minus tracks from the event
33+
if (event.mcsteps_virtualdetector != nullptr) {
34+
for (const auto& vdstep : *(event.mcsteps_virtualdetector)) {
35+
if (vdstep.vid == mu2e::VirtualDetectorId::TT_FrontHollow) {
36+
// Fill the histogram
37+
hVD13_XY->Fill(vdstep.pos.x(), vdstep.pos.y());
38+
39+
hVD13_Mom->Fill(vdstep.mom.R());
40+
}
41+
}
42+
}
43+
}
44+
45+
// Draw the histogram
46+
TCanvas* c = new TCanvas();
47+
c->Divide(2);
48+
c->cd(1);
49+
hVD13_XY->Draw("COLZ");
50+
c->cd(2);
51+
hVD13_Mom->Draw("HIST E");
52+
}

rooutil/examples/PrintEvents.C

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,5 +263,11 @@ 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+
}
271+
}
266272
}
267273
}

0 commit comments

Comments
 (0)