1 |
mocchiut |
1.1 |
// |
2 |
|
|
// Shows calorimeter tracks - Emiliano Mocchiutti |
3 |
|
|
// |
4 |
|
|
// FCaloMATRA.cxx version 1.01 (2006-03-07) |
5 |
|
|
// |
6 |
|
|
// The only input needed is the path to the directory created by YODA for the data file you want to analyze. |
7 |
|
|
// |
8 |
|
|
// Changelog: |
9 |
|
|
// |
10 |
|
|
// 1.00 - 1.01 (2006-03-07): Flight version, read unique YODA file. |
11 |
|
|
// |
12 |
|
|
// 0.00 - 1.00 (2006-03-07): Clone of CaloMATARA v3r00. |
13 |
|
|
// |
14 |
|
|
#include <sys/types.h> |
15 |
|
|
#include <unistd.h> |
16 |
|
|
#include <stdio.h> |
17 |
|
|
#include <fstream> |
18 |
|
|
#include <sstream> |
19 |
|
|
#include <TTree.h> |
20 |
|
|
#include <TObjectTable.h> |
21 |
|
|
#include <TClassEdit.h> |
22 |
|
|
#include <TObject.h> |
23 |
|
|
#include <TList.h> |
24 |
|
|
#include <TSystem.h> |
25 |
|
|
#include <TSystemDirectory.h> |
26 |
|
|
#include <TString.h> |
27 |
|
|
#include <TFile.h> |
28 |
|
|
#include <TClass.h> |
29 |
|
|
#include <TCanvas.h> |
30 |
mocchiut |
1.2 |
#include <TROOT.h> |
31 |
mocchiut |
1.1 |
#include <TH1.h> |
32 |
|
|
#include <TH1F.h> |
33 |
|
|
#include <TH2D.h> |
34 |
|
|
#include <TLatex.h> |
35 |
|
|
#include <TPad.h> |
36 |
|
|
#include <TPaveLabel.h> |
37 |
|
|
#include <TChain.h> |
38 |
|
|
#include <TApplication.h> |
39 |
|
|
#include <TStyle.h> |
40 |
|
|
extern bool existfile(TString); |
41 |
|
|
extern void stringcopy(TString&, const TString&, Int_t, Int_t); |
42 |
|
|
extern void ColorMIP(Float_t, int&); |
43 |
|
|
extern Int_t WhatToDo(int&, int&, int&, Long64_t, Float_t, Float_t, const char*, TString, TString, TCanvas&); |
44 |
|
|
extern TString getFilename(const TString); |
45 |
|
|
extern void *processevents(void *); |
46 |
|
|
// |
47 |
|
|
#include <caloclassesfun.h> |
48 |
|
|
// |
49 |
|
|
using namespace std; |
50 |
|
|
|
51 |
|
|
|
52 |
|
|
void FCaloMATRA(TString filename, Int_t fromevent = 1, Int_t toevent = 0, TString tyhist="box", TString outDir = "", TString saveas = "gif"){ |
53 |
|
|
Int_t doflag = 1; |
54 |
|
|
TApplication *app; |
55 |
|
|
if ( !gROOT->GetListOfClasses()->FindObject("TRint") ){ |
56 |
|
|
// |
57 |
|
|
app = new TApplication("app",0,0); |
58 |
|
|
}; |
59 |
|
|
const char* startingdir = gSystem->WorkingDirectory(); |
60 |
|
|
if ( !strcmp(outDir.Data(),"") ) outDir = startingdir; |
61 |
|
|
if ( !existfile(filename) ){ |
62 |
|
|
printf(" %s :no such file or directory \n",filename.Data()); |
63 |
|
|
printf("\n ERROR: No calorimeter LEVEL1 file! \n\n Run FCaloLEVEL1 to generate level1 data. \n\n"); |
64 |
|
|
return; |
65 |
|
|
}; |
66 |
|
|
// |
67 |
|
|
TFile *File = new TFile(filename.Data()); |
68 |
|
|
TTree *otr = (TTree*)File->Get("CaloLevel1"); |
69 |
|
|
if ( !otr ){ |
70 |
|
|
printf(" %s are you sure? I need a LEVEL1 file! \n",filename.Data()); |
71 |
|
|
return; |
72 |
|
|
}; |
73 |
|
|
// |
74 |
|
|
CalorimeterLevel1 *calo = new CalorimeterLevel1(); |
75 |
|
|
otr->SetBranchAddress("Event", &calo); |
76 |
|
|
// |
77 |
|
|
Long64_t nevents = otr->GetEntries(); |
78 |
|
|
stringstream titolo; |
79 |
|
|
stringstream stringa; |
80 |
|
|
TString fififile = getFilename(filename); |
81 |
|
|
const char *file = fififile; |
82 |
|
|
// |
83 |
|
|
// |
84 |
|
|
// input limits |
85 |
|
|
// |
86 |
|
|
if ( tyhist != "box" && tyhist != "lego" ) { |
87 |
|
|
printf("You can choose tyhist as box (default) or lego \n"); |
88 |
|
|
return; |
89 |
|
|
}; |
90 |
|
|
|
91 |
|
|
if ( fromevent > toevent && toevent ){ |
92 |
|
|
printf("It must be fromevent < toevent \n"); |
93 |
|
|
return; |
94 |
|
|
}; |
95 |
|
|
|
96 |
|
|
|
97 |
|
|
if ( fromevent > nevents+1 || fromevent < 0 ) { |
98 |
|
|
printf("You can choose fromevent between 0 (all) and %i \n",(int)nevents+1); |
99 |
|
|
return; |
100 |
|
|
}; |
101 |
|
|
|
102 |
|
|
if ( toevent > nevents+1 || toevent < 0 ) { |
103 |
|
|
printf("You can choose toevent between 0 (all) and %i \n",(int)nevents+1); |
104 |
|
|
return; |
105 |
|
|
}; |
106 |
|
|
Int_t minevent = 0; |
107 |
|
|
Int_t maxevent = nevents; |
108 |
|
|
if ( fromevent == 0 ) { |
109 |
|
|
minevent = 0; |
110 |
|
|
maxevent = nevents; |
111 |
|
|
} else { |
112 |
|
|
minevent = fromevent - 1; |
113 |
|
|
if ( toevent > 0 ){ |
114 |
|
|
maxevent = toevent - 1; |
115 |
|
|
} else { |
116 |
|
|
maxevent = fromevent -1; |
117 |
|
|
}; |
118 |
|
|
}; |
119 |
|
|
|
120 |
|
|
// |
121 |
|
|
// run over all the events |
122 |
|
|
// |
123 |
|
|
TCanvas *figura2 = new TCanvas("Calorimeter_tracks", "Calorimeter_tracks", 750, 650); |
124 |
|
|
figura2->SetFillColor(10); |
125 |
|
|
figura2->Range(0,0,100,100); |
126 |
|
|
Int_t i = minevent; |
127 |
|
|
while ( i < maxevent+1 ){ |
128 |
|
|
figura2->Clear(); |
129 |
|
|
// |
130 |
|
|
// variables definition |
131 |
|
|
// |
132 |
|
|
Int_t badstrip = 0; |
133 |
|
|
// |
134 |
|
|
// Book the histograms: |
135 |
|
|
// |
136 |
|
|
// |
137 |
|
|
stringstream xview; |
138 |
|
|
xview.str(""); |
139 |
|
|
xview << "x-view event " << (i+1); |
140 |
|
|
stringstream yview; |
141 |
|
|
yview.str(""); |
142 |
|
|
yview << "y-view event " << (i+1); |
143 |
|
|
gDirectory->Delete(xview.str().c_str()); |
144 |
|
|
gDirectory->Delete(yview.str().c_str()); |
145 |
|
|
TH2F *Xview = new TH2F(xview.str().c_str(),"",96,-0.5,95.5,22,-0.5,21.5); |
146 |
|
|
TH2F *Yview = new TH2F(yview.str().c_str(),"",96,-0.5,95.5,22,-0.5,21.5); |
147 |
|
|
// |
148 |
|
|
// figures: |
149 |
|
|
// |
150 |
|
|
Int_t bgcolor = 10; |
151 |
|
|
TLatex *t=new TLatex(); |
152 |
|
|
t->SetTextFont(32); |
153 |
|
|
t->SetTextColor(1); |
154 |
|
|
t->SetTextSize(0.03); |
155 |
|
|
t->SetTextAlign(12); |
156 |
|
|
titolo.str(""); |
157 |
|
|
titolo << "Calorimeter tracks - file " << file; |
158 |
|
|
titolo << " - event number " << (i+1); |
159 |
|
|
t->DrawLatex(0.5,97.,titolo.str().c_str()); |
160 |
|
|
Float_t paddim = 0.88; |
161 |
|
|
if ( !strcmp(tyhist.Data(),"lego") ){ |
162 |
|
|
paddim = 0.98; |
163 |
|
|
} else { |
164 |
|
|
paddim = 0.88; |
165 |
|
|
}; |
166 |
|
|
TPad *pd1 = new TPad("pd1","This is pad1",0.02,0.05,paddim,0.49,bgcolor); |
167 |
|
|
TPad *pd2 = new TPad("pd2","This is pad2",0.02,0.51,paddim,0.95,bgcolor); |
168 |
|
|
TPad *palette = 0; |
169 |
|
|
figura2->cd(); |
170 |
|
|
pd1->Range(0,0,100,100); |
171 |
|
|
pd2->Range(0,0,100,100); |
172 |
|
|
pd1->SetTicks(); |
173 |
|
|
pd2->SetTicks(); |
174 |
|
|
pd1->Draw(); |
175 |
|
|
pd2->Draw(); |
176 |
|
|
if ( !strcmp(tyhist.Data(),"box") ){ |
177 |
|
|
palette = new TPad("palette","This is palette",0.90,0.05,0.98,0.9,bgcolor); |
178 |
|
|
figura2->cd(); |
179 |
|
|
t=new TLatex(); |
180 |
|
|
t->SetTextFont(32); |
181 |
|
|
t->SetTextColor(1); |
182 |
|
|
t->SetTextSize(0.03); |
183 |
|
|
t->SetTextAlign(12); |
184 |
|
|
t->DrawLatex(92.,92.5,"MIP"); |
185 |
|
|
palette->Range(0,0,100,100); |
186 |
|
|
palette->Draw(); |
187 |
|
|
palette->cd(); |
188 |
|
|
// palette |
189 |
|
|
TPaveLabel *box1 = new TPaveLabel(2,2,98,16.3,"0",""); |
190 |
|
|
box1->SetTextFont(32); |
191 |
|
|
box1->SetTextColor(1); |
192 |
|
|
box1->SetTextSize(0.25); |
193 |
|
|
box1->SetFillColor(10); |
194 |
|
|
box1->Draw(); |
195 |
|
|
TPaveLabel *box2 = new TPaveLabel(2,18.3,98,32.66,"0-2",""); |
196 |
|
|
box2->SetTextFont(32); |
197 |
|
|
box2->SetTextColor(1); |
198 |
|
|
box2->SetTextSize(0.25); |
199 |
|
|
box2->SetFillColor(38); |
200 |
|
|
box2->Draw(); |
201 |
|
|
TPaveLabel *box3 = new TPaveLabel(2,34.66,98,48.96,"2-10",""); |
202 |
|
|
box3->SetTextFont(32); |
203 |
|
|
box3->SetTextColor(1); |
204 |
|
|
box3->SetTextSize(0.25); |
205 |
|
|
box3->SetFillColor(4); |
206 |
|
|
box3->Draw(); |
207 |
|
|
TPaveLabel *box4 = new TPaveLabel(2,50.96,98,65.26,"10-100",""); |
208 |
|
|
box4->SetTextFont(32); |
209 |
|
|
box4->SetTextColor(1); |
210 |
|
|
box4->SetTextSize(0.25); |
211 |
|
|
box4->SetFillColor(3); |
212 |
|
|
box4->Draw(); |
213 |
|
|
TPaveLabel *box5 = new TPaveLabel(2,67.26,98,81.56,"100-500",""); |
214 |
|
|
box5->SetTextFont(32); |
215 |
|
|
box5->SetTextColor(1); |
216 |
|
|
box5->SetTextSize(0.2); |
217 |
|
|
box5->SetFillColor(2); |
218 |
|
|
box5->Draw(); |
219 |
|
|
TPaveLabel *box6 = new TPaveLabel(2,83.56,98,97.86,">500",""); |
220 |
|
|
box6->SetTextFont(32); |
221 |
|
|
box6->SetTextColor(1); |
222 |
|
|
box6->SetTextSize(0.25); |
223 |
|
|
box6->SetFillColor(6); |
224 |
|
|
box6->Draw(); |
225 |
|
|
}; |
226 |
|
|
figura2->cd(); |
227 |
|
|
gStyle->SetOptDate(1); |
228 |
|
|
if ( tyhist == "box" ) { |
229 |
|
|
pd1->cd(); |
230 |
|
|
gStyle->SetOptStat(0); |
231 |
|
|
Xview->SetXTitle("strip"); |
232 |
|
|
Xview->SetYTitle("X - plane"); |
233 |
|
|
Xview->GetYaxis()->SetTitleOffset(0.5); |
234 |
|
|
Xview->SetFillColor(bgcolor); |
235 |
|
|
Xview->Fill(1.,1.,1.); |
236 |
|
|
Xview->Draw(tyhist); |
237 |
|
|
pd1->Update(); |
238 |
|
|
pd2->cd(); |
239 |
|
|
gStyle->SetOptStat(0); |
240 |
|
|
Yview->SetXTitle("strip"); |
241 |
|
|
Yview->SetYTitle("Y - plane"); |
242 |
|
|
Yview->GetYaxis()->SetTitleOffset(0.5); |
243 |
|
|
Yview->SetFillColor(bgcolor); |
244 |
|
|
Yview->Fill(1.,1.,1.); |
245 |
|
|
Yview->Draw(tyhist); |
246 |
|
|
pd2->Update(); |
247 |
|
|
}; |
248 |
|
|
// |
249 |
|
|
// read from the header of the event the absolute time at which it was recorded |
250 |
|
|
// |
251 |
|
|
otr->GetEntry(i); |
252 |
|
|
// |
253 |
|
|
// run over views and planes |
254 |
|
|
// |
255 |
|
|
for (Int_t m = 0; m < 22; m++){ |
256 |
|
|
for (Int_t l = 0; l < 2; l++){ |
257 |
|
|
for (Int_t n = 0; n < 96; n++){ |
258 |
|
|
if ( calo->estrip[l][m][n] > 0.7 ) { |
259 |
|
|
// |
260 |
|
|
// OK, now in estrip we have the energy deposit in MIP of all the strips for this event (at the end of loops of course) |
261 |
|
|
// |
262 |
|
|
if ( tyhist == "box" ){ |
263 |
|
|
xview.str(""); |
264 |
|
|
xview << "x-view event " << n; |
265 |
|
|
xview << " " << m; |
266 |
|
|
xview << " " << l; |
267 |
|
|
yview.str(""); |
268 |
|
|
yview << "y-view event " << n; |
269 |
|
|
yview << " " << m; |
270 |
|
|
yview << " " << l; |
271 |
|
|
gDirectory->Delete(xview.str().c_str()); |
272 |
|
|
gDirectory->Delete(yview.str().c_str()); |
273 |
|
|
TH2F *Xview = new TH2F(xview.str().c_str(),"",96,-0.5,95.5,22,-0.5,21.5); |
274 |
|
|
TH2F *Yview = new TH2F(yview.str().c_str(),"",96,-0.5,95.5,22,-0.5,21.5); |
275 |
|
|
Int_t colo; |
276 |
|
|
ColorMIP(calo->estrip[l][m][n],colo); |
277 |
|
|
Xview->SetFillColor(colo); |
278 |
|
|
Yview->SetFillColor(colo); |
279 |
|
|
if ( l == 0 ) { |
280 |
|
|
Xview->Fill(n,m,1.); |
281 |
|
|
pd1->cd(); |
282 |
|
|
Xview->Draw("box same"); |
283 |
|
|
}; |
284 |
|
|
if ( l == 1 ) { |
285 |
|
|
Yview->Fill(n,m,1.); |
286 |
|
|
pd2->cd(); |
287 |
|
|
Yview->Draw("box same"); |
288 |
|
|
}; |
289 |
|
|
} else { |
290 |
|
|
if ( l == 0 ) Xview->Fill(n,m,calo->estrip[l][m][n]); |
291 |
|
|
if ( l == 1 ) Yview->Fill(n,m,calo->estrip[l][m][n]); |
292 |
|
|
}; |
293 |
|
|
if ( calo->good[l][m][n] != 0 ) badstrip++; |
294 |
|
|
}; |
295 |
|
|
}; |
296 |
|
|
}; |
297 |
|
|
}; |
298 |
|
|
// |
299 |
|
|
figura2->cd(); |
300 |
|
|
t=new TLatex(); |
301 |
|
|
t->SetTextFont(32); |
302 |
|
|
t->SetTextColor(8); |
303 |
|
|
t->SetTextAlign(12); |
304 |
|
|
t->SetTextSize(0.02); |
305 |
|
|
Int_t qtot = (int)calo->qtot; |
306 |
|
|
Int_t nstrip = (int)calo->nstrip; |
307 |
|
|
stringa.str(""); |
308 |
|
|
stringa << "QTOT = " << qtot; |
309 |
|
|
stringa << " NSTRIP = " << nstrip; |
310 |
|
|
stringa << " Bad strips = " << badstrip; |
311 |
|
|
stringa << " "; |
312 |
|
|
t->DrawLatex(30.,2.,stringa.str().c_str()); |
313 |
|
|
figura2->Update(); |
314 |
|
|
if ( tyhist == "lego" ){ |
315 |
|
|
pd1->cd(); |
316 |
|
|
gStyle->SetOptStat(0); |
317 |
|
|
Xview->SetXTitle("strip"); |
318 |
|
|
Xview->SetYTitle("X - plane"); |
319 |
|
|
Xview->GetXaxis()->SetTitleOffset(1.5); |
320 |
|
|
Xview->GetYaxis()->SetTitleOffset(1.5); |
321 |
|
|
Xview->SetZTitle("MIP"); |
322 |
|
|
Xview->Draw(tyhist); |
323 |
|
|
pd1->Update(); |
324 |
|
|
pd2->cd(); |
325 |
|
|
gStyle->SetOptStat(0); |
326 |
|
|
Yview->SetXTitle("strip"); |
327 |
|
|
Yview->SetYTitle("Y - plane"); |
328 |
|
|
Yview->GetXaxis()->SetTitleOffset(1.5); |
329 |
|
|
Yview->GetYaxis()->SetTitleOffset(1.5); |
330 |
|
|
Yview->SetZTitle("MIP"); |
331 |
|
|
Yview->Draw(tyhist); |
332 |
|
|
pd2->Update(); |
333 |
|
|
}; |
334 |
|
|
pd1->Update(); |
335 |
|
|
pd2->Update(); |
336 |
|
|
figura2->Update(); |
337 |
|
|
|
338 |
|
|
// |
339 |
|
|
// Interact with user: do you want to continue, exit or print the figure? |
340 |
|
|
// |
341 |
|
|
if ( i != maxevent ) { |
342 |
|
|
TString figty = "matra"; |
343 |
|
|
doflag = 1; |
344 |
|
|
Float_t lastevno = 0; |
345 |
|
|
Float_t firstevno = 0; |
346 |
|
|
Int_t jumpto = 0; |
347 |
|
|
Int_t ifout = WhatToDo(i,doflag, jumpto,nevents,lastevno,firstevno,file,outDir,figty,*figura2); |
348 |
|
|
if ( maxevent < i+1 ) { |
349 |
|
|
maxevent = nevents; |
350 |
|
|
printf("WARNING: you have chosen an event number out of the starting range.\n Range extended to %i\n\n",maxevent); |
351 |
|
|
}; |
352 |
|
|
if ( ifout ) return; |
353 |
|
|
} else { |
354 |
|
|
const string fil = (const char*)filename; |
355 |
|
|
Int_t posiz = fil.find("dw_"); |
356 |
|
|
if ( posiz == -1 ) posiz = fil.find("DW_"); |
357 |
|
|
Int_t posiz2 = posiz+13; |
358 |
|
|
TString file2; |
359 |
|
|
stringcopy(file2,filename,posiz,posiz2); |
360 |
|
|
// |
361 |
|
|
const char *figrec = file2; |
362 |
|
|
const char *outdir = outDir; |
363 |
|
|
stringstream figsave; |
364 |
|
|
const char *format = saveas; |
365 |
|
|
figsave.str(""); |
366 |
|
|
figsave << outdir << "/" ; |
367 |
|
|
figsave << figrec << "_matra_"; |
368 |
|
|
figsave << (i+1) << "."; |
369 |
|
|
figsave << format; |
370 |
|
|
// |
371 |
|
|
figura2->SaveAs(figsave.str().c_str()); |
372 |
|
|
}; |
373 |
|
|
if ( doflag == 2 && i == 0 ) { |
374 |
|
|
printf("\n WARNING: Cannot go backward! Going forward. \n"); |
375 |
|
|
doflag = 1; |
376 |
|
|
}; |
377 |
|
|
if ( doflag == 2 && i>0 ) i--; |
378 |
|
|
if ( doflag == 1 ) i++; |
379 |
|
|
}; |
380 |
|
|
// |
381 |
|
|
// last warning (if the case) |
382 |
|
|
// |
383 |
|
|
figura2->Update(); |
384 |
|
|
printf("\n"); |
385 |
|
|
gSystem->ChangeDirectory(startingdir); |
386 |
|
|
} |