Skip to content

Commit e5ec8eb

Browse files
Add example for plotting VD steps with RooUtil
1 parent 24f6724 commit e5ec8eb

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

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/inc/common_cuts.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "Offline/MCDataProducts/inc/ProcessCode.hh"
1111
#include "Offline/MCDataProducts/inc/GenId.hh"
1212
#include "Offline/MCDataProducts/inc/MCRelationship.hh"
13+
#include "Offline/DataProducts/inc/VirtualDetectorId.hh"
1314

1415
#include "EventNtuple/rooutil/inc/Track.hh"
1516
#include "EventNtuple/rooutil/inc/TrackSegment.hh"

0 commit comments

Comments
 (0)