1 |
// |
2 |
// Shows calorimeter tracks - Emiliano Mocchiutti |
3 |
// |
4 |
// CaloMATRA.c version 3.00 (2005-11-23) |
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 |
// 2.12 - 3.00 (2005-11-23): now it can be run as a compiled program with graphic output! |
11 |
// |
12 |
// 2.11 - 2.12 (2005-11-15): compiled! |
13 |
// |
14 |
// 2.10 - 2.11 (2005-08-16): 64 bit arch bugs fixed. |
15 |
// |
16 |
// 2.09 - 2.10 (2005-07-25): don't load anymore yodaUtility.c use instead clones of routines. |
17 |
// |
18 |
// 2.08 - 2.09 (2005-07-12): small changes for compilation |
19 |
// |
20 |
// 2.07 - 2.08 (2005-06-28): changed to be inserted in package CaloQLOOK. |
21 |
// |
22 |
// 2.06 - 2.07 (2005-06-07): check if file is older than 050515_007. |
23 |
// |
24 |
// 2.05 - 2.06 (2005-04-07): changed tree name of level1 data. |
25 |
// |
26 |
// 2.04 - 2.05 (2005-03-30): changed call to WhatToDo subroutine according to the changes in WhatToDo |
27 |
// |
28 |
// 2.03 - 2.04 (2005-03-09): saveas input parameter introduced (required by Maurizio). |
29 |
// |
30 |
// 2.02 - 2.03 (2005-02-24): Changed colour background (required by Marco Casolino). |
31 |
// |
32 |
// 2.01 - 2.02 (2005-02-24): Changed variable definition from C/C++ style to ROOT style (int->Int_t). |
33 |
// |
34 |
// 2.00 - 2.01 (2005-02-07): User interaction routine changed. Maxevent bug fixed. Change default name for printed files. |
35 |
// |
36 |
// 1.04 - 2.00 (2005-01-20): Now it will access directly LEVEL1 ntuple instead of calibrating everything everytime. |
37 |
// |
38 |
// 1.03 - 1.04 (2005-01-17): Upgrade in the user-interaction capability and cleanup of the code |
39 |
// |
40 |
// 1.02 - 1.03 (2004-12-20): canvas is created once and then cleared. |
41 |
// |
42 |
// 1.01 - 1.02 (2004-12-17): bugs fixed and include the possibility of using a old calibration file to see the data |
43 |
// |
44 |
// 1.00 - 1.01 (2004-12-15): Include also yodaUtility.c |
45 |
// |
46 |
#include <fstream> |
47 |
#include <sstream> |
48 |
#include <TTree.h> |
49 |
#include <TClassEdit.h> |
50 |
#include <TObject.h> |
51 |
#include <TList.h> |
52 |
#include <TSystem.h> |
53 |
#include <TSystemDirectory.h> |
54 |
#include <TString.h> |
55 |
#include <TFile.h> |
56 |
#include <TClass.h> |
57 |
#include <TCanvas.h> |
58 |
#include <TH1.h> |
59 |
#include <TH1F.h> |
60 |
#include <TH2D.h> |
61 |
#include <TLatex.h> |
62 |
#include <TPad.h> |
63 |
#include <TPaveLabel.h> |
64 |
#include <TChain.h> |
65 |
#include <TApplication.h> |
66 |
#if !defined (__CINT__) |
67 |
#include <event/PamelaRun.h> |
68 |
#include <event/physics/calorimeter/CalorimeterEvent.h> |
69 |
#include <event/physics/trigger/TriggerEvent.h> |
70 |
#include <event/CalibCalPedEvent.h> |
71 |
extern short int CaloLEVEL1(TString, TString, Int_t); |
72 |
#include <caloclasses.h> |
73 |
#endif |
74 |
#include <CaloFunctions.h> |
75 |
|
76 |
void CaloMATRA(TString filename, Int_t fromevent = 1, Int_t toevent = 0, TString tyhist="box", TString outDir = "", TString saveas = "gif"){ |
77 |
gROOT->GetListOfCanvases()->Delete("a"); |
78 |
gDirectory->GetList()->Delete(); |
79 |
const char* startingdir = gSystem->WorkingDirectory(); |
80 |
Int_t doflag = 1; |
81 |
#if !defined (__CINT__) |
82 |
TApplication app("app",0,0); |
83 |
#endif |
84 |
#if defined (__CINT__) |
85 |
emicheckLib(); |
86 |
stringstream llib; |
87 |
const char *pamlib = gSystem->ExpandPathName("$PAM_LIB"); |
88 |
llib << pamlib << "/caloclasses_h.so"; |
89 |
gSystem->Load(llib.str().c_str()); |
90 |
#endif |
91 |
if ( outDir == "" ) outDir = filename; |
92 |
// |
93 |
// Open LEVEL1 ntuple, if it doesn't exist call CaloLEVEL1. |
94 |
// |
95 |
TFile *headerFile = 0; |
96 |
TFile *caloFile = 0; |
97 |
headerFile = emigetFile(filename, "Physics", "Header"); |
98 |
if ( !headerFile ){ |
99 |
printf("No header file, exiting...\n"); |
100 |
return; |
101 |
}; |
102 |
caloFile = emigetFile(filename, "Physics.Level1", "Calorimeter"); |
103 |
if ( !caloFile ){ |
104 |
printf("\n WARNING: No calorimeter LEVEL1 file! \n\n I am going to call CaloLEVEL1, it could take some time to generate level1 data. \n\n"); |
105 |
headerFile->Close(); |
106 |
gSystem->Exec("sleep 3"); |
107 |
short int ERR = CaloLEVEL1(filename,"",0); |
108 |
if ( ERR ) { |
109 |
printf("\n I am not able to calibrate data, please call CaloLEVEL1 by hand \n\n Exiting... \n\n"); |
110 |
return; |
111 |
} else { |
112 |
printf(" OK, back to CaloMATRA! \n\n"); |
113 |
headerFile = emigetFile(filename, "Physics", "Header"); |
114 |
caloFile = emigetFile(filename, "Physics.Level1", "Calorimeter"); |
115 |
}; |
116 |
}; |
117 |
//Takes the tree of the header file |
118 |
TTree *otr = (TTree*)headerFile->Get("Pscu"); |
119 |
otr->AddFriend("CaloLevel1",caloFile); |
120 |
// |
121 |
CalorimeterLevel1 *calo = new CalorimeterLevel1(); |
122 |
otr->SetBranchAddress("Event", &calo); |
123 |
// |
124 |
Long64_t nevents = otr->GetEntries(); |
125 |
stringstream titolo; |
126 |
// char *titolo=" looong long line as workaround since root is not working other ways"; |
127 |
// char *stringa=" looong long line as workaround since root is not working other ways"; |
128 |
stringstream stringa; |
129 |
//TString *file[17]; |
130 |
//file = "dw_000000_000.dat"; |
131 |
//file = getFilename(filename); |
132 |
TString fififile = getFilename(filename); |
133 |
const char *file = fififile; |
134 |
// |
135 |
// |
136 |
// input limits |
137 |
// |
138 |
if ( tyhist != "box" && tyhist != "lego" ) { |
139 |
printf("You can choose tyhist as box (default) or lego \n"); |
140 |
return; |
141 |
}; |
142 |
|
143 |
if ( fromevent > toevent && toevent ){ |
144 |
printf("It must be fromevent < toevent \n"); |
145 |
return; |
146 |
}; |
147 |
|
148 |
|
149 |
if ( fromevent > nevents+1 || fromevent < 0 ) { |
150 |
printf("You can choose fromevent between 0 (all) and %i \n",(int)nevents+1); |
151 |
return; |
152 |
}; |
153 |
|
154 |
if ( toevent > nevents+1 || toevent < 0 ) { |
155 |
printf("You can choose toevent between 0 (all) and %i \n",(int)nevents+1); |
156 |
return; |
157 |
}; |
158 |
Int_t minevent = 0; |
159 |
Int_t maxevent = nevents; |
160 |
if ( fromevent == 0 ) { |
161 |
minevent = 0; |
162 |
maxevent = nevents; |
163 |
} else { |
164 |
minevent = fromevent - 1; |
165 |
if ( toevent > 0 ){ |
166 |
maxevent = toevent - 1; |
167 |
} else { |
168 |
maxevent = fromevent -1; |
169 |
}; |
170 |
}; |
171 |
|
172 |
// |
173 |
// run over all the events |
174 |
// |
175 |
TCanvas *figura2 = new TCanvas("Calorimeter_tracks", "Calorimeter_tracks", 750, 650); |
176 |
figura2->SetFillColor(10); |
177 |
figura2->Range(0,0,100,100); |
178 |
Int_t i = minevent; |
179 |
while ( i < maxevent+1 ){ |
180 |
figura2->Clear(); |
181 |
// |
182 |
// variables definition |
183 |
// |
184 |
Int_t badstrip = 0; |
185 |
// |
186 |
// Book the histograms: |
187 |
// |
188 |
// |
189 |
stringstream xview; |
190 |
xview.str(""); |
191 |
xview << "x-view event " << (i+1); |
192 |
stringstream yview; |
193 |
yview.str(""); |
194 |
yview << "y-view event " << (i+1); |
195 |
gDirectory->Delete(xview.str().c_str()); |
196 |
gDirectory->Delete(yview.str().c_str()); |
197 |
TH2F *Xview = new TH2F(xview.str().c_str(),"",96,-0.5,95.5,22,-0.5,21.5); |
198 |
TH2F *Yview = new TH2F(yview.str().c_str(),"",96,-0.5,95.5,22,-0.5,21.5); |
199 |
// |
200 |
// figures: |
201 |
// |
202 |
Int_t bgcolor = 10; |
203 |
TLatex *t=new TLatex(); |
204 |
t->SetTextFont(32); |
205 |
t->SetTextColor(1); |
206 |
t->SetTextSize(0.03); |
207 |
t->SetTextAlign(12); |
208 |
titolo.str(""); |
209 |
titolo << "Calorimeter tracks - file " << file; |
210 |
titolo << " - event number " << (i+1); |
211 |
// sprintf(titolo,"Calorimeter tracks - file %s - event number %i ",file,i+1); |
212 |
t->DrawLatex(0.5,97.,titolo.str().c_str()); |
213 |
TPad *pd1 = new TPad("pd1","This is pad1",0.02,0.05,0.88,0.49,bgcolor); |
214 |
TPad *pd2 = new TPad("pd2","This is pad2",0.02,0.51,0.88,0.95,bgcolor); |
215 |
TPad *palette = new TPad("palette","This is palette",0.90,0.05,0.98,0.9,bgcolor); |
216 |
figura2->cd(); |
217 |
t=new TLatex(); |
218 |
t->SetTextFont(32); |
219 |
t->SetTextColor(1); |
220 |
t->SetTextSize(0.03); |
221 |
t->SetTextAlign(12); |
222 |
t->DrawLatex(92.,92.5,"MIP"); |
223 |
pd1->Range(0,0,100,100); |
224 |
pd2->Range(0,0,100,100); |
225 |
palette->Range(0,0,100,100); |
226 |
pd1->SetTicks(); |
227 |
pd2->SetTicks(); |
228 |
pd1->Draw(); |
229 |
pd2->Draw(); |
230 |
palette->Draw(); |
231 |
palette->cd(); |
232 |
// palette |
233 |
TPaveLabel *box1 = new TPaveLabel(2,2,98,16.3,"0",""); |
234 |
box1->SetTextFont(32); |
235 |
box1->SetTextColor(1); |
236 |
box1->SetTextSize(0.25); |
237 |
box1->SetFillColor(10); |
238 |
box1->Draw(); |
239 |
TPaveLabel *box2 = new TPaveLabel(2,18.3,98,32.66,"0-2",""); |
240 |
box2->SetTextFont(32); |
241 |
box2->SetTextColor(1); |
242 |
box2->SetTextSize(0.25); |
243 |
box2->SetFillColor(38); |
244 |
box2->Draw(); |
245 |
TPaveLabel *box3 = new TPaveLabel(2,34.66,98,48.96,"2-10",""); |
246 |
box3->SetTextFont(32); |
247 |
box3->SetTextColor(1); |
248 |
box3->SetTextSize(0.25); |
249 |
box3->SetFillColor(4); |
250 |
box3->Draw(); |
251 |
TPaveLabel *box4 = new TPaveLabel(2,50.96,98,65.26,"10-100",""); |
252 |
box4->SetTextFont(32); |
253 |
box4->SetTextColor(1); |
254 |
box4->SetTextSize(0.25); |
255 |
box4->SetFillColor(3); |
256 |
box4->Draw(); |
257 |
TPaveLabel *box5 = new TPaveLabel(2,67.26,98,81.56,"100-500",""); |
258 |
box5->SetTextFont(32); |
259 |
box5->SetTextColor(1); |
260 |
box5->SetTextSize(0.2); |
261 |
box5->SetFillColor(2); |
262 |
box5->Draw(); |
263 |
TPaveLabel *box6 = new TPaveLabel(2,83.56,98,97.86,">500",""); |
264 |
box6->SetTextFont(32); |
265 |
box6->SetTextColor(1); |
266 |
box6->SetTextSize(0.25); |
267 |
box6->SetFillColor(6); |
268 |
box6->Draw(); |
269 |
figura2->cd(); |
270 |
gStyle->SetOptDate(1); |
271 |
if ( tyhist == "box" ) { |
272 |
pd1->cd(); |
273 |
gStyle->SetOptStat(0); |
274 |
Xview->SetXTitle("strip"); |
275 |
Xview->SetYTitle("X - plane"); |
276 |
Xview->GetYaxis()->SetTitleOffset(0.5); |
277 |
Xview->SetFillColor(bgcolor); |
278 |
Xview->Fill(1.,1.,1.); |
279 |
Xview->Draw(tyhist); |
280 |
pd1->Update(); |
281 |
pd2->cd(); |
282 |
gStyle->SetOptStat(0); |
283 |
Yview->SetXTitle("strip"); |
284 |
Yview->SetYTitle("Y - plane"); |
285 |
Yview->GetYaxis()->SetTitleOffset(0.5); |
286 |
Yview->SetFillColor(bgcolor); |
287 |
Yview->Fill(1.,1.,1.); |
288 |
Yview->Draw(tyhist); |
289 |
pd2->Update(); |
290 |
}; |
291 |
// |
292 |
// read from the header of the event the absolute time at which it was recorded |
293 |
// |
294 |
otr->GetEntry(i); |
295 |
// |
296 |
// run over views and planes |
297 |
// |
298 |
for (Int_t m = 0; m < 22; m++){ |
299 |
for (Int_t l = 0; l < 2; l++){ |
300 |
for (Int_t n = 0; n < 96; n++){ |
301 |
if ( calo->estrip[l][m][n] > 0.7 ) { |
302 |
// |
303 |
// 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) |
304 |
// |
305 |
if ( tyhist == "box" ){ |
306 |
xview.str(""); |
307 |
xview << "x-view event " << n; |
308 |
xview << " " << m; |
309 |
xview << " " << l; |
310 |
yview.str(""); |
311 |
yview << "y-view event " << n; |
312 |
yview << " " << m; |
313 |
yview << " " << l; |
314 |
gDirectory->Delete(xview.str().c_str()); |
315 |
gDirectory->Delete(yview.str().c_str()); |
316 |
TH2F *Xview = new TH2F(xview.str().c_str(),"",96,-0.5,95.5,22,-0.5,21.5); |
317 |
TH2F *Yview = new TH2F(yview.str().c_str(),"",96,-0.5,95.5,22,-0.5,21.5); |
318 |
Int_t colo; |
319 |
ColorMIP(calo->estrip[l][m][n],colo); |
320 |
Xview->SetFillColor(colo); |
321 |
Yview->SetFillColor(colo); |
322 |
if ( l == 0 ) { |
323 |
Xview->Fill(n,m,1.); |
324 |
pd1->cd(); |
325 |
Xview->Draw("box same"); |
326 |
}; |
327 |
if ( l == 1 ) { |
328 |
Yview->Fill(n,m,1.); |
329 |
pd2->cd(); |
330 |
Yview->Draw("box same"); |
331 |
}; |
332 |
} else { |
333 |
if ( l == 0 ) Xview->Fill(n,m,calo->estrip[l][m][n]); |
334 |
if ( l == 1 ) Yview->Fill(n,m,calo->estrip[l][m][n]); |
335 |
}; |
336 |
if ( calo->good[l][m][n] != 0 ) badstrip++; |
337 |
}; |
338 |
}; |
339 |
}; |
340 |
}; |
341 |
// |
342 |
figura2->cd(); |
343 |
t=new TLatex(); |
344 |
t->SetTextFont(32); |
345 |
t->SetTextColor(8); |
346 |
t->SetTextAlign(12); |
347 |
t->SetTextSize(0.02); |
348 |
Int_t qtot = (int)calo->qtot; |
349 |
Int_t nstrip = (int)calo->nstrip; |
350 |
stringa.str(""); |
351 |
stringa << "QTOT = " << qtot; |
352 |
stringa << " NSTRIP = " << nstrip; |
353 |
stringa << " Bad strips = " << badstrip; |
354 |
stringa << " "; |
355 |
//sprintf(stringa,"QTOT = %i NSTRIP = %i Bad strips = %i ",qtot,nstrip,badstrip); |
356 |
t->DrawLatex(30.,2.,stringa.str().c_str()); |
357 |
figura2->Update(); |
358 |
if ( tyhist == "lego" ){ |
359 |
pd1->cd(); |
360 |
gStyle->SetOptStat(0); |
361 |
Xview->SetXTitle("strip"); |
362 |
Xview->SetYTitle("X - plane"); |
363 |
Xview->GetXaxis()->SetTitleOffset(1.5); |
364 |
Xview->GetYaxis()->SetTitleOffset(1.5); |
365 |
Xview->SetZTitle("MIP"); |
366 |
Xview->Draw(tyhist); |
367 |
pd1->Update(); |
368 |
pd2->cd(); |
369 |
gStyle->SetOptStat(0); |
370 |
Yview->SetXTitle("strip"); |
371 |
Yview->SetYTitle("Y - plane"); |
372 |
Yview->GetXaxis()->SetTitleOffset(1.5); |
373 |
Yview->GetYaxis()->SetTitleOffset(1.5); |
374 |
Yview->SetZTitle("MIP"); |
375 |
Yview->Draw(tyhist); |
376 |
pd2->Update(); |
377 |
}; |
378 |
pd1->Update(); |
379 |
pd2->Update(); |
380 |
figura2->Update(); |
381 |
|
382 |
// |
383 |
// Interact with user: do you want to continue, exit or print the figure? |
384 |
// |
385 |
if ( i != maxevent ) { |
386 |
TString figty = "matra"; |
387 |
doflag = 1; |
388 |
Float_t lastevno = 0; |
389 |
Float_t firstevno = 0; |
390 |
Int_t jumpto = 0; |
391 |
Int_t ifout = WhatToDo(i,doflag, jumpto,nevents,lastevno,firstevno,file,outDir,figty,*figura2); |
392 |
if ( maxevent < i+1 ) { |
393 |
maxevent = nevents; |
394 |
printf("WARNING: you have chosen an event number out of the starting range.\n Range extended to %i\n\n",maxevent); |
395 |
}; |
396 |
if ( ifout ) return; |
397 |
} else { |
398 |
const string fil = (const char*)filename; |
399 |
Int_t posiz = fil.find("dw_"); |
400 |
if ( posiz == -1 ) posiz = fil.find("DW_"); |
401 |
Int_t posiz2 = posiz+13; |
402 |
TString file2; |
403 |
stringcopy(file2,filename,posiz,posiz2); |
404 |
// |
405 |
const char *figrec = file2; |
406 |
const char *outdir = outDir; |
407 |
stringstream figsave; |
408 |
const char *format = saveas; |
409 |
figsave.str(""); |
410 |
figsave << outdir << "/" ; |
411 |
figsave << figrec << "_matra_"; |
412 |
figsave << (i+1) << "."; |
413 |
figsave << format; |
414 |
// |
415 |
figura2->SaveAs(figsave.str().c_str()); |
416 |
|
417 |
// char *figrec = 0; |
418 |
//figrec = "dw_000000_000"; |
419 |
//memcpy(figrec, file, 13); |
420 |
//const char *outdir = outDir; |
421 |
// char *figsave = 0; |
422 |
//const char *format = saveas; |
423 |
//stringstream figsave; |
424 |
//figsave.str(""); |
425 |
//figsave << outdir << "/"; |
426 |
//figsave << figrec << "_matra_"; |
427 |
//figsave << (i+1) << "."; |
428 |
//figsave << format; |
429 |
// figsave = Form("%s/%s_matra_%i.%s",outdir,figrec,i+1,format); |
430 |
// figura2->SaveAs(figsave.str().c_str()); |
431 |
}; |
432 |
if ( doflag == 2 && i == 0 ) { |
433 |
printf("\n WARNING: Cannot go backward! Going forward. \n"); |
434 |
doflag = 1; |
435 |
}; |
436 |
if ( doflag == 2 && i>0 ) i--; |
437 |
if ( doflag == 1 ) i++; |
438 |
// app.Run(); |
439 |
}; |
440 |
// |
441 |
// last warning (if the case) |
442 |
// |
443 |
figura2->Update(); |
444 |
printf("\n"); |
445 |
caloFile->Close(); |
446 |
gSystem->ChangeDirectory(startingdir); |
447 |
} |