-
Notifications
You must be signed in to change notification settings - Fork 2
/
readrootfile.C
106 lines (88 loc) · 2.53 KB
/
readrootfile.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
Raghav Kunnawalkam Elayavalli
Rutgers University
June 9th 2017
readrootfile.C
Test code that compiles and reads root file and makes histograms from trees
*/
#include <iostream>
#include "TFile.h"
#include "TH1.h"
#include "TTree.h"
#include "TCanvas.h"
#include "TLegend.h"
#include "TROOT.h"
#include "TStyle.h"
void readrootfile(){
gStyle->SetOptStat(0);
//! Load the input file
TFile * fInput1 = TFile::Open("testfile.root");
TFile * fInput2 = TFile::Open("events.root");
//! get histograms/trees from file
TH1F * hMeasurement = (TH1F*)fInput1->Get("mytestHisto");
TTree * tevt = (TTree*)fInput2->Get("events");
TH1F * hTrackX = new TH1F("hTrackX",
"", 100, -30, 30);
TH1F * hTrackY = new TH1F("hTrackY",
"", 100, -30, 30);
TH1F * hTrackZ = new TH1F("hTrackZ",
"", 100, -30, 30);
TH1F * hTrackT = new TH1F("hTrackT",
"", 100, 0, 100);
//! Draw histograms from the tree
tevt->Draw("tracks.fCoordinates.fX>>hTrackX"
, "", "goff");
tevt->Draw("tracks.fCoordinates.fY>>hTrackY"
, "", "goff");
tevt->Draw("tracks.fCoordinates.fZ>>hTrackZ"
, "", "goff");
tevt->Draw("tracks.fCoordinates.fT>>hTrackT"
, "", "goff");
//! Create canvas
TCanvas * cMeas = new TCanvas("cMeas", "",
900, 300);
cMeas->Divide(3, 1);
cMeas->cd(1);
gStyle->SetErrorX(0);
gStyle->SetOptStat(0);
gPad->SetTickx();
gPad->SetTicky();
hMeasurement->SetXTitle("Length [cm]");
hMeasurement->SetMarkerStyle(23);
hMeasurement->SetMarkerColor(kRed);
hMeasurement->Draw("p");
cMeas->cd(2);
gStyle->SetErrorX(0);
gStyle->SetOptStat(0);
gPad->SetTickx();
gPad->SetTicky();
hTrackX->SetXTitle("Track Position [cm]");
hTrackX->SetMarkerStyle(25);
hTrackX->SetMarkerColor(kRed);
hTrackX->Draw("p");
hTrackY->SetMarkerStyle(26);
hTrackY->SetMarkerColor(kBlue);
hTrackY->Draw("same p");
hTrackZ->SetMarkerStyle(27);
hTrackZ->SetMarkerColor(kGreen);
hTrackZ->Draw("same p");
TLegend * ltest = new TLegend(0.15, 0.4,
0.4, 0.8);
ltest->AddEntry(hTrackX, "X", "p");
ltest->AddEntry(hTrackY, "Y", "p");
ltest->AddEntry(hTrackZ, "Z", "p");
ltest->SetTextSize(0.04);
ltest->SetBorderSize(0);
ltest->SetFillStyle(0);
ltest->Draw();
cMeas->cd(3);
gStyle->SetErrorX(0);
gStyle->SetOptStat(0);
gPad->SetTickx();
gPad->SetTicky();
hTrackT->SetXTitle("Track Time [sec]");
hTrackT->SetMarkerStyle(25);
hTrackT->SetMarkerColor(kRed);
hTrackT->Draw("p");
cMeas->SaveAs("measurement.pdf", "RECREATE");
}//! end of main analysis