1 |
/** |
2 |
* Header_Scan |
3 |
* Author Nagni |
4 |
* version 1.0 |
5 |
* |
6 |
* Version 1.1 - 28 December 2004 |
7 |
* If outList does not exist the function exit to prompt |
8 |
* If nevents = 0 the function exit to promt |
9 |
* |
10 |
* Version 1.2 - 3 January 2005 |
11 |
* Two canvases are created to see the graphs better |
12 |
* |
13 |
* Version 1.25 - 13 January 2005 |
14 |
* Changed Int_t to Float because of variable range size |
15 |
* (UInt_t has been excluded beacuse of uncompatibility with TGraph) |
16 |
* |
17 |
* version 1.3 - 22 February 2005 - Nagni |
18 |
* For compatibility with batch mode excution: |
19 |
* 1) Added "include <iostream>" and "using namespace std" |
20 |
* 2) Removed gROOT->Reset() |
21 |
* |
22 |
* Version 1.4 |
23 |
* Date 08 March 2005 |
24 |
* Added "format" parameter for saving the produced image in various formats |
25 |
* (for a complete list of types refer to TPad::SaveAs method) |
26 |
* |
27 |
* Version 1.5 |
28 |
* Date 09 February 2006 - Marcelli |
29 |
* Update to work with new Yoda output |
30 |
* |
31 |
* Version 1.6 |
32 |
* Date 27 February 2006 - Marcelli |
33 |
* For compilation: |
34 |
* Added function "int main(int argc, char* argv[])" |
35 |
* |
36 |
* |
37 |
* Description: This script creates two canvases with five pads. The first pad shows packetID variable (for all packets) vs. OBT. |
38 |
* The second pad shows the number of physic packets vs. OBT. The third pad shows the lenght of Physic packets (byte) vs. OBT. |
39 |
* The fourth pad shows the packetcounter of physic packets vs. OBT. The fifth pad shows PacketCounter vs. File Offset. |
40 |
* |
41 |
* Parameters: |
42 |
* TSTring base - the path to the root directory for the specific Pamela unpack session |
43 |
* There is no default value, without this input the program will not run |
44 |
* TString outDir - the path where to save the output image (Default = ./) |
45 |
* TString format - the format which will be used fo rsave the produced images (Default = "jpg") |
46 |
* |
47 |
* |
48 |
* Version 1.7 |
49 |
* Date 16 June 2006 - Malvezzi |
50 |
* |
51 |
* Description of changes: |
52 |
* Implementation of the case: numebr of events <= 0. |
53 |
* Remove graph "grPcktId1"; see PacketScan for the same information. |
54 |
* Fixed bugs: for a large namber of events is not possible to have vectors, so I have subsituted graphs with histograms |
55 |
* or divided the graphs in more than one canvas. |
56 |
* |
57 |
* Version 1.8 |
58 |
* Date 8 August 2006 - Malvezzi |
59 |
* |
60 |
* Description: changed the scale in the second and third graph of the first canvas; added a pad of text in the second canvas |
61 |
* |
62 |
*/ |
63 |
|
64 |
|
65 |
#include <fstream> |
66 |
#include <math.h> |
67 |
#include "TLatex.h" |
68 |
#include "TF1.h" |
69 |
#include "TPaveText.h" |
70 |
#include "TMultiGraph.h" |
71 |
#include <sstream> |
72 |
#include <iostream> |
73 |
#include "TString.h" |
74 |
#include "TStyle.h" |
75 |
#include "TFile.h" |
76 |
#include "TList.h" |
77 |
#include "TTree.h" |
78 |
#include "TObjString.h" |
79 |
#include "TCanvas.h" |
80 |
#include "TGraph.h" |
81 |
#include "TH1F.h" |
82 |
#include "TGaxis.h" |
83 |
#include "EventHeader.h" |
84 |
#include "PscuHeader.h" |
85 |
|
86 |
using namespace std; |
87 |
|
88 |
void HeaderScan(TString base, TString outDir, TString format) |
89 |
{ |
90 |
|
91 |
//------------------- Variables initilization -------------------------// |
92 |
Long64_t nevents=0; |
93 |
ULong_t lastime, firstime, primotempo, ultimotempo, primoffset=500000000, ultimoffset=100000000; |
94 |
double obmin=0.; |
95 |
double obmax=0.; |
96 |
stringstream oss, oss1, oss2, oss3, noentries, stringa; |
97 |
//------- load root file -------------- |
98 |
TFile *file = new TFile(base.Data()); |
99 |
if (!file){ |
100 |
printf("No such file in the directory has been found"); |
101 |
return; |
102 |
} |
103 |
|
104 |
TTree *PhysicsTr = (TTree*)file->Get("Physics"); |
105 |
TBranch *headBr = PhysicsTr->GetBranch("Header"); |
106 |
|
107 |
pamela::EventHeader *eh = 0; |
108 |
pamela::PscuHeader *ph = 0; |
109 |
|
110 |
PhysicsTr->SetBranchAddress("Header", &eh); |
111 |
|
112 |
nevents = headBr->GetEntries(); |
113 |
|
114 |
TString filename = ((TObjString*)base.Tokenize('/')->Last())->GetString(); |
115 |
filename = ((TObjString*)filename.Tokenize('.')->First())->GetString(); |
116 |
|
117 |
//----------- If nevents < = 0 ---------------------------------/ |
118 |
if (nevents<=0) { |
119 |
printf("nevents = %i \n", nevents); |
120 |
printf(" \n"); |
121 |
|
122 |
TCanvas *canv = new TCanvas("No entries", "No entries ", 400, 200); |
123 |
canv->SetFillColor(10); |
124 |
canv->cd(); |
125 |
|
126 |
TLatex *l = new TLatex(); |
127 |
l->SetTextAlign(12); |
128 |
l->SetTextSize(0.15); |
129 |
l->SetTextColor(2); |
130 |
noentries.str(""); |
131 |
noentries<< "HeaderScan_QL:"; |
132 |
l->DrawLatex(0.05, 0.7, noentries.str().c_str()); |
133 |
noentries.str(""); |
134 |
noentries<< "No Physics entries for this files"; |
135 |
l->DrawLatex(0.05, 0.5, noentries.str().c_str()); |
136 |
|
137 |
if (outDir == "./") { |
138 |
oss.str(""); |
139 |
oss << filename.Data() << "_HeaderScan_QL." << format.Data(); |
140 |
} else { |
141 |
oss.str(""); |
142 |
oss << outDir.Data() << filename.Data() << "_HeaderScan_QL." << format.Data(); |
143 |
} |
144 |
|
145 |
canv->Update(); |
146 |
canv->SaveAs(oss.str().c_str()); |
147 |
|
148 |
return; |
149 |
} |
150 |
|
151 |
//-------------- to know the max and min OBT ----------------------------// |
152 |
headBr->GetEntry(0); |
153 |
ph = eh->GetPscuHeader(); |
154 |
firstime = ph->GetOrbitalTime(); |
155 |
|
156 |
for (Int_t i = 0; i < nevents; i++){ |
157 |
headBr->GetEntry(i); |
158 |
ph = eh->GetPscuHeader(); |
159 |
if((ph->GetOrbitalTime()) <= firstime) firstime=ph->GetOrbitalTime(); |
160 |
if((ph->GetOrbitalTime()) >= lastime) lastime=ph->GetOrbitalTime(); |
161 |
} |
162 |
|
163 |
//------------------------ First histogram -----------------------------------// |
164 |
|
165 |
obmin=firstime; |
166 |
obmax=lastime; |
167 |
|
168 |
oss1.str(""); |
169 |
oss1 << filename.Data() <<": Physics Packet per minute. Start time = " << obmin << ", End time = "<< obmax <<" ms"; |
170 |
Int_t nbin = (lastime-firstime)/60000; |
171 |
TH1F *h1 = new TH1F ("histo1", oss1.str().c_str(), nbin, obmin, obmax); |
172 |
|
173 |
oss2.str(""); |
174 |
oss2 << filename.Data() <<": Lenght of Physic packets"; |
175 |
Int_t nbin2 =(lastime-firstime); |
176 |
TH1F *packetLength = new TH1F ("packetLength", oss2.str().c_str(), nbin2, obmin, obmax); |
177 |
|
178 |
oss3.str(""); |
179 |
oss3 << filename.Data() <<": Physics Counter"; |
180 |
TH1F *packeCounter = new TH1F ("packeCounter", oss3.str().c_str(), nbin2, obmin, obmax); |
181 |
//---------------------------------------------------- |
182 |
TCanvas *finalCanv1 = new TCanvas("Header_1", base, 1280, 1150); |
183 |
finalCanv1->Divide(1,3); |
184 |
finalCanv1->SetFillColor(10); |
185 |
TPad *all2= new TPad ("","", 0, 0, 1, 1); |
186 |
all2->SetFillColor(10); |
187 |
TPad *all3= new TPad ("","", 0, 0, 1, 1); |
188 |
all3->SetFillColor(10); |
189 |
TPad *all4= new TPad ("","", 0, 0, 1, 1); |
190 |
all4->SetFillColor(10); |
191 |
//---------------------------------------------------- |
192 |
TCanvas *finalCanv2 = new TCanvas("Header_2", base, 1280, 1150); |
193 |
finalCanv2->Divide(1,2); |
194 |
finalCanv2->SetFillColor(10); |
195 |
|
196 |
TMultiGraph *mg1 = new TMultiGraph(); |
197 |
oss1.str(""); |
198 |
oss1 << filename.Data() <<": PscuCounter vs FileOffset."; |
199 |
mg1->SetTitle(oss1.str().c_str()); |
200 |
|
201 |
TMultiGraph *mg2 = new TMultiGraph(); |
202 |
|
203 |
TPad *all= new TPad ("","", 0, 0, 1, 1); |
204 |
all->SetFillColor(10); |
205 |
TPad *all1= new TPad ("","", 0, 0, 1, 1); |
206 |
all1->SetFillColor(10); |
207 |
TPad *pad = new TPad("pad","pad", .80,.50,.90,.80); |
208 |
pad->SetFillColor(10); |
209 |
//-------------------------------------------------------------------------- |
210 |
for (Int_t l = 0; l < nevents; l++){ |
211 |
headBr->GetEntry(l); |
212 |
ph = eh->GetPscuHeader(); |
213 |
h1->Fill(ph->GetOrbitalTime()); |
214 |
packetLength->Fill(ph->GetOrbitalTime(),ph->GetPacketLenght()); |
215 |
packeCounter->Fill(ph->GetOrbitalTime(),ph->GetCounter()); |
216 |
} |
217 |
|
218 |
//------------ First Canvas ---------------------// |
219 |
|
220 |
finalCanv1->cd(1); |
221 |
all2->Draw(); |
222 |
all2->cd(); |
223 |
h1->SetStats(kFALSE); |
224 |
h1->GetXaxis()->SetTitle("OBT (ms)"); |
225 |
h1->GetXaxis()->CenterTitle(); |
226 |
h1->GetXaxis()->SetLabelSize(0.04); |
227 |
h1->GetYaxis()->SetTitle("Number of events "); |
228 |
h1->GetYaxis()->CenterTitle(); |
229 |
h1->GetYaxis()->SetTitleSize(0.06); |
230 |
h1->GetYaxis()->SetTitleOffset(0.8); |
231 |
h1->Draw(); |
232 |
|
233 |
|
234 |
finalCanv1->cd(2); |
235 |
all3->Draw(); |
236 |
all3->cd(); |
237 |
packetLength->SetStats(kFALSE); |
238 |
packetLength->SetMarkerColor(2); |
239 |
packetLength->SetMarkerSize(.5); |
240 |
packetLength->SetMarkerStyle(21); |
241 |
packetLength->GetXaxis()->SetTitle("OBT (ms)"); |
242 |
packetLength->GetXaxis()->CenterTitle(); |
243 |
packetLength->GetXaxis()->SetLabelSize(0.04); |
244 |
packetLength->GetYaxis()->SetTitle("Lenght (byte)"); |
245 |
packetLength->GetYaxis()->CenterTitle(); |
246 |
packetLength->GetYaxis()->SetLabelSize(0.04); |
247 |
packetLength->GetYaxis()->SetTitleSize(0.06); |
248 |
packetLength->GetYaxis()->SetTitleOffset(0.8); |
249 |
packetLength->Draw("9p"); |
250 |
|
251 |
finalCanv1->cd(3); |
252 |
all4->Draw(); |
253 |
all4->cd(); |
254 |
packeCounter->SetStats(kFALSE); |
255 |
packeCounter->SetMarkerColor(4); |
256 |
packeCounter->SetMarkerSize(.5); |
257 |
packeCounter->SetMarkerStyle(21); |
258 |
packeCounter->GetXaxis()->SetTitle("OBT (ms)"); |
259 |
packeCounter->GetXaxis()->SetTitleSize(0.05); |
260 |
packeCounter->GetXaxis()->CenterTitle(); |
261 |
packeCounter->GetXaxis()->SetLabelSize(0.04); |
262 |
packeCounter->GetYaxis()->SetTitle("Counter"); |
263 |
packeCounter->GetYaxis()->SetTitleSize(0.05); |
264 |
packeCounter->GetYaxis()->CenterTitle(); |
265 |
packeCounter->GetYaxis()->SetLabelSize(0.04); |
266 |
packeCounter->GetYaxis()->SetTitleSize(0.06); |
267 |
packeCounter->GetYaxis()->SetTitleOffset(0.8); |
268 |
Double_t min = 500000000.; |
269 |
for (Int_t l = 0; l < nevents; l++){ |
270 |
if((packeCounter->GetBinContent(l))<= min && (packeCounter->GetBinContent(l))!= 0) min = packeCounter->GetBinContent(l); |
271 |
} |
272 |
packeCounter->SetMinimum(min); |
273 |
packeCounter->Draw("9p"); |
274 |
|
275 |
oss.str(""); |
276 |
oss << outDir.Data() << filename.Data(); |
277 |
oss << "_HeaderScan_1." << format.Data(); |
278 |
finalCanv1->SaveAs(oss.str().c_str()); |
279 |
|
280 |
//------------------------------------------------- |
281 |
TList *list = new TList; |
282 |
Int_t numkey; |
283 |
TObject *key = new TObject; |
284 |
const char *name; |
285 |
TTree* tr = new TTree; |
286 |
Long64_t nevntskey=0; |
287 |
list = file->GetListOfKeys(); |
288 |
numkey = file->GetNkeys(); |
289 |
|
290 |
const Int_t size1 = 10000; |
291 |
Int_t ev1=0; |
292 |
Double_t PscuCounter1[size1], FileOffset1[size1], tempo1[size1], salto[size1]; |
293 |
Int_t pag1=0; |
294 |
Int_t m1=0; |
295 |
Int_t ll=0; |
296 |
|
297 |
for (Int_t i=0; i<numkey; i++){ |
298 |
key = list->At(i); |
299 |
name=(char *)(key->GetName()); |
300 |
tr = (TTree*)file->Get(name); |
301 |
if (tr->IsZombie()) continue; |
302 |
tr->SetBranchAddress("Header", &eh); |
303 |
TBranch *Br = tr->GetBranch("Header"); |
304 |
nevntskey = tr->GetEntries(); |
305 |
m1=0; |
306 |
pag1= (nevntskey/10000)+1; |
307 |
/////ciclo sulle pagine//////////////////// |
308 |
for (Int_t interval1=0; interval1<pag1; interval1++){ |
309 |
|
310 |
for (Int_t l = 0; l < size1; l++){ //ciclo su un sottogruppo |
311 |
Br->GetEntry(ev1+l); |
312 |
ph = eh->GetPscuHeader(); |
313 |
PscuCounter1[l]= ph->GetCounter(); // = PcktCounter[l] |
314 |
FileOffset1[l]=ph->GetFileOffset(); |
315 |
tempo1[l]=ph->GetOrbitalTime(); |
316 |
if(ph->GetFileOffset()<= primoffset){ |
317 |
primoffset =ph->GetFileOffset(); |
318 |
primotempo=ph->GetOrbitalTime(); |
319 |
} |
320 |
if(ph->GetFileOffset()>= ultimoffset){ |
321 |
ultimoffset = ph->GetFileOffset(); |
322 |
ultimotempo = ph->GetOrbitalTime(); |
323 |
} |
324 |
if(l>0){ |
325 |
if(tempo1[l] < tempo1[l-1]){ |
326 |
salto[ll]= ph->GetOrbitalTime(); |
327 |
ll=ll+1; |
328 |
} |
329 |
} |
330 |
|
331 |
m1=l; |
332 |
} |
333 |
|
334 |
TGraph *graph3= new TGraph(m1, FileOffset1, PscuCounter1); |
335 |
graph3->SetMarkerColor(3); |
336 |
graph3->SetMarkerSize(.5); |
337 |
graph3->SetMarkerStyle(21); |
338 |
mg1->Add(graph3); |
339 |
|
340 |
TGraph *graph4= new TGraph(m1, FileOffset1, tempo1); |
341 |
graph4->SetMarkerColor(kBlue); |
342 |
graph4->SetMarkerSize(.5); |
343 |
graph4->SetMarkerStyle(21); |
344 |
mg2->Add(graph4); |
345 |
|
346 |
ev1=ev1+10000; |
347 |
} |
348 |
} |
349 |
|
350 |
|
351 |
TLatex *lat = new TLatex(); |
352 |
lat->SetTextAlign(12); |
353 |
lat->SetTextSize(0.15); |
354 |
lat->SetTextColor(kBlue); |
355 |
|
356 |
|
357 |
//------------ Second Canvas ---------------------// |
358 |
finalCanv2->cd(1); |
359 |
all1->Draw(); |
360 |
all1->cd(); |
361 |
mg1->Draw("AP"); |
362 |
mg1->GetXaxis()->SetTitle("File Offset"); |
363 |
mg1->GetXaxis()->CenterTitle(); |
364 |
mg1->GetXaxis()->SetTitleSize(0.05); |
365 |
mg1->GetXaxis()->SetLabelSize(0.04); |
366 |
mg1->GetYaxis()->SetTitle("Counter"); |
367 |
mg1->GetYaxis()->CenterTitle(); |
368 |
mg1->GetYaxis()->SetTitleSize(0.05); |
369 |
mg1->GetYaxis()->SetLabelSize(0.03); |
370 |
|
371 |
finalCanv2->cd(2); |
372 |
all->Draw(); |
373 |
all->cd(); |
374 |
|
375 |
oss3.str(""); |
376 |
oss3 << filename.Data() <<" OBT vs FileOffset. First packet = "<<primotempo <<" ms, Last packet = "<<ultimotempo<<" ms."; |
377 |
mg2->SetTitle(oss3.str().c_str()); |
378 |
mg2->Draw("AP"); |
379 |
mg2->GetXaxis()->SetTitle("File Offset"); |
380 |
mg2->GetXaxis()->CenterTitle(); |
381 |
mg2->GetXaxis()->SetTitleSize(0.05); |
382 |
mg2->GetXaxis()->SetLabelSize(0.04); |
383 |
mg2->GetYaxis()->SetTitle("OBT"); |
384 |
mg2->GetYaxis()->CenterTitle(); |
385 |
mg2->GetYaxis()->SetTitleSize(0.05); |
386 |
mg2->GetYaxis()->SetLabelSize(0.03); |
387 |
double min2 = 0.8; |
388 |
if(ll-1 > 0){ |
389 |
pad->Draw(); |
390 |
pad->cd(); |
391 |
stringa.str(""); |
392 |
stringa << "jump back at:"; |
393 |
lat->DrawLatex(0.08, min2, stringa.str().c_str()); |
394 |
for(Int_t kk=0; kk <(ll-1); kk++){ |
395 |
stringa.str(""); |
396 |
stringa << salto[kk]; |
397 |
min2=min2-0.1; |
398 |
lat->DrawLatex(0.08, min2,stringa.str().c_str()); |
399 |
//cout<<salto[kk]<<";\n"; |
400 |
} |
401 |
} |
402 |
|
403 |
finalCanv2->Update(); |
404 |
|
405 |
|
406 |
|
407 |
|
408 |
|
409 |
oss1.str(""); |
410 |
oss1 << outDir.Data() << filename.Data(); |
411 |
oss1 << "_HeaderScan_2"<<"." << format.Data(); |
412 |
|
413 |
finalCanv2->SaveAs(oss1.str().c_str()); |
414 |
|
415 |
file->Close(); |
416 |
|
417 |
} |
418 |
|
419 |
int main(int argc, char* argv[]){ |
420 |
TString path; |
421 |
TString outDir = "./"; |
422 |
TString format = "jpg"; |
423 |
if (argc < 2){ |
424 |
printf("You have to insert at least the file to analyze \n"); |
425 |
printf("Try '--help' for more information. \n"); |
426 |
exit(1); |
427 |
} |
428 |
if (!strcmp(argv[1], "--help")){ |
429 |
printf( "Usage: HeaderScan FILE [OPTION] \n"); |
430 |
printf( "\t --help Print this help and exit \n"); |
431 |
printf( "\t -outDir[path] Path where to put the output [default ./] \n"); |
432 |
printf( "\t -format[jpg|ps|gif] Format for output files [default 'jpg'] \n"); |
433 |
exit(1); |
434 |
} |
435 |
path=argv[1]; |
436 |
for (int i = 2; i < argc; i++){ |
437 |
if (!strcmp(argv[i], "-outDir")){ |
438 |
if (++i >= argc){ |
439 |
printf( "-outDir needs arguments. \n"); |
440 |
printf( "Try '--help' for more information. \n"); |
441 |
exit(1); |
442 |
} |
443 |
else{ |
444 |
outDir = argv[i]; |
445 |
continue; |
446 |
} |
447 |
} |
448 |
if (!strcmp(argv[i], "-format")){ |
449 |
if (++i >= argc){ |
450 |
printf( "-format needs arguments. \n"); |
451 |
printf( "Try '--help' for more information. \n"); |
452 |
exit(1); |
453 |
} |
454 |
else{ |
455 |
format = argv[i]; |
456 |
continue; |
457 |
} |
458 |
} |
459 |
} |
460 |
HeaderScan(argv[1], outDir, format); |
461 |
} |