-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalyzeTree.cpp
More file actions
123 lines (91 loc) · 2.74 KB
/
analyzeTree.cpp
File metadata and controls
123 lines (91 loc) · 2.74 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// #include "EventTree_V07_04_14_00.h"
#include "TreeEvent.h"
#include "TreeAnalysis.h"
#include <string>
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int main(int argc, char **argv)
{
char* outputFileName(0);
char* inputFileName(0);
char* fileList(0);
bool useInputList = false;
bool gotInput = false;
bool gotOutput = false;
char c;
while ((c = getopt (argc, argv, "i:o:l:")) != -1)
switch (c) {
case 'o':
gotOutput = true;
outputFileName = new char[strlen(optarg)+1];
strcpy(outputFileName, optarg);
break;
case 'i':
gotInput = true;
inputFileName = new char[strlen(optarg)+1];
strcpy(inputFileName, optarg);
break;
case 'l':
useInputList = true;
fileList = new char[strlen(optarg)+1];
strcpy(fileList, optarg);
break;
default:
cout << "usage: [-k|-g|-l] [-v] [-b <binWidth>] -i <input> -o <output> \n";
abort ();
}
// OUTPUT ROOT FILE
TFile* fout;
if (gotOutput) fout = new TFile(outputFileName, "RECREATE");
else fout = new TFile("output.root", "RECREATE");
// INPUT TREES
vector<TString> inputName;
TChain chain("TREE_IN_ROOTFILE");
if (useInputList) {
ifstream list(fileList);
TString name;
while (list>>name) inputName.push_back(name);
} else if (gotInput) inputName.push_back(inputFileName);
else {
cout << "Got no input ROOT file: quit \n";
return 1;
}
for (unsigned int input = 0; input < inputName.size(); input++) {
cout << "Adding: " << input << endl;
chain.Add(inputName[input]);
cout << "Added \n";
}
TTree* ev_tTree = (TTree*)& chain;
TreeEvent * the_event= new TreeEvent(ev_tTree);
Int_t events = ev_tTree->GetEntries();
cout << endl << "Total number of events: " << events << endl << endl;
/////////////////////////////////////////////////////////////////////
/// HERE IS THE PLACE WHERE YOU PUT YOUR STUFF
// Define your analyses here
vector<TreeAnalysis*> analyses;
for (unsigned int iana=0; iana<analyses.size(); iana++ )
{
analyses[iana]->Init();
}
// Event loop
for (Int_t k = 0; k < events; k++) {
if (! (k%100000) ) std::cout << "Processed " << k << " events \n";
// Read next event before we do anything with it
ev_tTree->GetEntry(k);
the_event->ReadEvent();
// Run all defined analyses
for (unsigned int iana=0; iana<analyses.size(); iana++ )
{
analyses[iana]->EventAnalysis(the_event);
}
}
for (unsigned int iana=0; iana<analyses.size(); iana++ )
{
analyses[iana]->End(fout);
}
// We need to write explicity all histograms to the output root
fout->cd();
fout->Close();
}