forked from warwick-legend/warwick-legend
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathanalyseRootOutput.C
59 lines (51 loc) · 2 KB
/
analyseRootOutput.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
#include <TFile.h>
#include <TTreeReader.h>
#include <TTreeReaderValue.h>
#include <iostream>
#include <vector>
void summary(TString fname) {
if (fname.IsNull()) fname = "lg.root";
TFile *fin = new TFile(fname.Data(), "READ");
TTreeReader myreader("Score", fin);
TTreeReaderValue<std::vector<int>> hid(myreader, "HitID");
TTreeReaderValue<std::vector<int>> tn(myreader, "Trjentries");
TTreeReaderValue<std::vector<double>> edep(myreader, "Edep");
TTreeReaderValue<std::vector<double>> time(myreader, "Time");
TTreeReaderValue<std::vector<double>> we(myreader, "Weight");
TTreeReaderValue<std::vector<double>> xpos(myreader, "Hitxloc");
TTreeReaderValue<std::vector<double>> ypos(myreader, "Hityloc");
TTreeReaderValue<std::vector<double>> zpos(myreader, "Hitzloc");
// event loop
while (myreader.Next())
{
for (size_t i=0; i<hid->size();++i) {
std::cout << "<<< Hit Track ID " << hid->at(i) << std::endl;
std::cout << "deposited energy [MeV]: " << edep->at(i) << std::endl;
std::cout << "global time [ns]: " << time->at(i) << std::endl;
std::cout << "track weight: " << we->at(i) << std::endl;
std::cout << "pos x [m]: " << xpos->at(i) << std::endl;
std::cout << "pos y [m]: " << ypos->at(i) << std::endl;
std::cout << "pos z [m]: " << zpos->at(i) << std::endl;
}
}
}
// use output TTree for summary and TGraph2D
TGraph2D *graphics(TString fname) {
TFile *fin = new TFile(fname.Data(), "READ");
TTreeReader myreader("Score", fin);
TTreeReaderValue<std::vector<double>> xvtx(myreader, "TrjXVtx");
TTreeReaderValue<std::vector<double>> yvtx(myreader, "TrjYVtx");
TTreeReaderValue<std::vector<double>> zvtx(myreader, "TrjZVtx");
// event loop
TGraph2D *gr = new TGraph2D(myreader.GetEntries());
int npoint = 0;
while (myreader.Next()) // vertex location graph in 3D
{
for (size_t i=0; i<xvtx->size();++i) {
gr->SetPoint(npoint, xvtx->at(i), yvtx->at(i), zvtx->at(i));
npoint++;
}
}
gr->SetMarkerStyle(20);
return gr;
}