1 |
#include <fstream> |
2 |
#include <sstream> |
3 |
#include <string> |
4 |
#include <math.h> |
5 |
#include <iostream> |
6 |
#include <TTree.h> |
7 |
#include <TClassEdit.h> |
8 |
#include <TObject.h> |
9 |
#include <TList.h> |
10 |
#include <TSystem.h> |
11 |
#include <TSystemDirectory.h> |
12 |
#include <TString.h> |
13 |
#include <TFile.h> |
14 |
#include <TClass.h> |
15 |
#include <TCanvas.h> |
16 |
#include <TH1.h> |
17 |
#include <TH1F.h> |
18 |
#include <TH2D.h> |
19 |
#include <TLatex.h> |
20 |
#include <TPad.h> |
21 |
#include <TPaveLabel.h> |
22 |
#include <TChain.h> |
23 |
#include <TGraph.h> |
24 |
#include <TMultiGraph.h> |
25 |
#include <TLine.h> |
26 |
#include <TStyle.h> |
27 |
#include <TF1.h> |
28 |
#include <TH1F.h> |
29 |
#include <TTree.h> |
30 |
#include <TCanvas.h> |
31 |
#include <PamLevel2.h> |
32 |
|
33 |
#include <CaloBragg.h> // ADD HEADER FILE HERE |
34 |
|
35 |
using namespace std; |
36 |
|
37 |
|
38 |
//=================================== |
39 |
// global variables |
40 |
//=================================== |
41 |
Bool_t DEBUG; |
42 |
Bool_t SIMU; |
43 |
TString DIR; |
44 |
TString LIST; |
45 |
TString OPTIONS; |
46 |
ULong64_t MAXEV; |
47 |
TString OUTFILE; |
48 |
|
49 |
PamLevel2 *pam_event = NULL; |
50 |
TFile *outfv = NULL; |
51 |
|
52 |
bool fillTree = false; |
53 |
bool fillHistos = false; |
54 |
|
55 |
|
56 |
//========================================== |
57 |
//000000000000000000000000000000000000000000 |
58 |
//========================================== |
59 |
Int_t Loop(TString ddir,TString list, ULong64_t nmax, TString options, TString outfile){ |
60 |
|
61 |
|
62 |
TH1F *hzeta = new TH1F("hzeta","Zeta Distribution",100,0.,50.); |
63 |
|
64 |
if(options.Contains("fillTree"))fillTree=true; |
65 |
if(options.Contains("fillHisto"))fillHistos=true; |
66 |
|
67 |
// ------------------- |
68 |
// create output files |
69 |
// ------------------- |
70 |
TString outfile_t =""; |
71 |
// TString outfile_h =""; |
72 |
// TString outfile_v =""; |
73 |
if( outfile.IsNull() ){ |
74 |
if(!list.IsNull())outfile = list(0,list.Last('.')); |
75 |
else outfile = "output"; |
76 |
}else{ |
77 |
if(outfile.Contains(".root"))outfile = outfile(0,outfile.Last('.')); |
78 |
} |
79 |
// if(fillTree){ |
80 |
outfile_t = outfile; |
81 |
outfile_t.Append("-hzeta.root"); |
82 |
outfv = (TFile*)gROOT->FindObject(outfile_t); |
83 |
if (outfv) outfv->Close(); |
84 |
outfv = new TFile(outfile_t,"RECREATE"); |
85 |
if(outfv->IsZombie()){ |
86 |
cout << "Output file could not be created\n"; |
87 |
return 1; |
88 |
}; |
89 |
cout << "Created output file: "<<outfv->GetName()<<endl; |
90 |
// -------------------- |
91 |
// read input file/list |
92 |
// -------------------- |
93 |
pam_event = new PamLevel2(ddir,list,options); |
94 |
// |
95 |
CaloBragg *cn = new CaloBragg(pam_event); // CREATE CaloBragg OBJECT GIVING PamLevel2 POINTER |
96 |
|
97 |
// |
98 |
// loop over events |
99 |
// |
100 |
ULong64_t nevents = pam_event->GetEntries(); |
101 |
if(!nmax)nmax = numeric_limits<ULong64_t>::max(); |
102 |
if(nevents < nmax)nmax=nevents; |
103 |
cout << endl<<" Start loop over events: "<< nmax<<endl; |
104 |
// |
105 |
for(ULong64_t i=0; i<nmax; i++){ |
106 |
// |
107 |
if ( i%10000 == 0) cout<<i<<endl; |
108 |
// |
109 |
pam_event->Clear(); |
110 |
if( pam_event->GetEntry(i) ){ // get the entry |
111 |
// |
112 |
cn->Print(); // this will simply print on the terminal the determined CaloNuclei values |
113 |
// |
114 |
Float_t zeta = cn->Get_lpz(); // here how you can use the "old" dE/dx on the first plane |
115 |
printf(" Event number %llu zeta %f \n",i,zeta); |
116 |
hzeta->Fill(zeta); |
117 |
|
118 |
} |
119 |
}; |
120 |
pam_event->Clear(); |
121 |
// |
122 |
// save histo to file |
123 |
// |
124 |
gROOT->cd(); |
125 |
outfv->cd(); |
126 |
// |
127 |
hzeta->Write(); |
128 |
outfv->Close(); |
129 |
// |
130 |
printf(" end!\n"); |
131 |
return 0; |
132 |
|
133 |
} |
134 |
|
135 |
///////////////////////////////////////////////////////////////// |
136 |
|
137 |
void usage(){ |
138 |
|
139 |
cout << "------------------------------------------------------------"<<endl; |
140 |
cout << "Loop over events (on one or more Level2-files), applying some selection cuts (defined in My-Selection.cpp), \n"; |
141 |
cout << "creating output histograms (defined in My-Histos.cpp) and/or trees with selected events. \n \n "; |
142 |
cout << "USAGE:"<<endl; |
143 |
cout << "-processDir DIR - Level2 data directory \n"; |
144 |
cout << "-processList LIST - list of files (.txt) or single file (.root) to be analysed \n"; |
145 |
cout << "-outputFile PATH - name of the output file \n"; |
146 |
cout << "-NumEvents XXX - number of events to be analysed \n"; |
147 |
cout << "--debug, -g - debug mode \n"; |
148 |
cout << "--help, -h - print this help \n"; |
149 |
cout << "-options [ options ] - options: \n"; |
150 |
cout << " fillHistos --> create an output file with histograms \n"; |
151 |
cout << " fillTree --> create an output file with trees storing the selected events \n "; |
152 |
cout << " +(-)ALL --> inlcude(exclude) all trees and branches \n " ; |
153 |
cout << " +(-)TRK1 +(-)TRK2 +(-)CAL1 +(-)CAL2 +(-)TOF +(-)TRG +(-)ND +(-)S4 +(-)ORB --> inlcude(exclude) trees and branches \n" ; |
154 |
cout << "------------------------------------------------------------"<<endl; |
155 |
} |
156 |
// |
157 |
int HandleInputPar(int argc, char **argv){ |
158 |
|
159 |
if(argc>1){ |
160 |
|
161 |
if(!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help") ){ |
162 |
usage(); |
163 |
return(1); |
164 |
}; |
165 |
// ----------------------- |
166 |
// Read input parameters |
167 |
// ----------------------- |
168 |
DEBUG = false; |
169 |
SIMU = false; |
170 |
DIR = gSystem->WorkingDirectory(); |
171 |
LIST = ""; |
172 |
OUTFILE = ""; |
173 |
OPTIONS = "+AUTO fillTree"; |
174 |
MAXEV = 0; |
175 |
|
176 |
|
177 |
for (int i = 1; i < argc; i++){ |
178 |
// -----------------------------------------------------// |
179 |
if (!strcmp(argv[i], "-processDir")){ |
180 |
if (++i >= argc) throw -1; |
181 |
DIR = argv[i]; |
182 |
cout << "processDir "<<DIR<<endl; |
183 |
continue; |
184 |
} |
185 |
// -----------------------------------------------------// |
186 |
else if (!strcmp(argv[i], "-processList")){ |
187 |
if (++i >= argc) throw -1; |
188 |
LIST = argv[i]; |
189 |
cout << "processList "<<LIST<<endl; |
190 |
continue; |
191 |
} |
192 |
// -----------------------------------------------------// |
193 |
else if (!strcmp(argv[i], "-outputFile")){ |
194 |
if (++i >= argc) throw -1; |
195 |
OUTFILE = argv[i]; |
196 |
cout << "outputFile "<<OUTFILE<<endl; |
197 |
continue; |
198 |
} |
199 |
// -----------------------------------------------------// |
200 |
else if (!strcmp(argv[i], "-NumEvents")){ |
201 |
if (++i >= argc) throw -1; |
202 |
MAXEV = atoi(argv[i]); |
203 |
cout << "NumEvents "<<MAXEV<<endl; |
204 |
continue; |
205 |
} |
206 |
// -----------------------------------------------------// |
207 |
else if (!strcmp(argv[i], "-options")){ |
208 |
if (++i >= argc) throw -1; |
209 |
OPTIONS = argv[i]; |
210 |
if( OPTIONS.Contains("[") ){ |
211 |
do{ |
212 |
if (++i >= argc) throw -1; |
213 |
OPTIONS.Append(argv[i]); |
214 |
}while(!OPTIONS.Contains("]")); |
215 |
}else cout << "wrong option format --> ignoring " << endl; |
216 |
} |
217 |
// -----------------------------------------------------// |
218 |
else if (!strcmp(argv[i], "--debug") || !strcmp(argv[i], "-g")){ |
219 |
DEBUG = true; |
220 |
continue; |
221 |
} |
222 |
else if (!strcmp(argv[i], "--simu") || !strcmp(argv[i], "-s")){ |
223 |
SIMU = true; |
224 |
continue; |
225 |
} |
226 |
// -----------------------------------------------------// |
227 |
else{ |
228 |
cout << "Unidentified input parameter. Ignored."<< endl; |
229 |
}; |
230 |
}; |
231 |
}else{ |
232 |
usage(); |
233 |
return(1); |
234 |
}; |
235 |
// ----------------------- |
236 |
// Check input parameters |
237 |
// ----------------------- |
238 |
|
239 |
|
240 |
return(0); |
241 |
|
242 |
}; |
243 |
// |
244 |
|
245 |
int main(int argc, char **argv) |
246 |
{ |
247 |
|
248 |
if( HandleInputPar(argc,argv) )return(1); |
249 |
|
250 |
// Loop(DIR,LIST,MAXEV,"-ALL+TRK1+TRK2+CAL1+CAL2+TOF+AC",OUTFILE); |
251 |
cout << "OPTIONS "<<OPTIONS<<endl; |
252 |
Int_t tt = Loop(DIR,LIST,MAXEV,OPTIONS,OUTFILE); |
253 |
|
254 |
cout << "Back to main - end"<<endl; |
255 |
|
256 |
return tt; |
257 |
|
258 |
}; |
259 |
|