/[PAMELA software]/quicklook/QLflightTmtc_Header/HeaderScan.cpp
ViewVC logotype

Contents of /quicklook/QLflightTmtc_Header/HeaderScan.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (show annotations) (download)
Thu Aug 10 09:21:06 2006 UTC (18 years, 6 months ago) by pam-rm2
Branch: MAIN
CVS Tags: v2r03
Changes since 1.6: +5 -1 lines
*** empty log message ***

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;
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 ev1=0;
307 pag1=0;
308 pag1= (nevntskey/10000)+1;
309 /////ciclo sulle pagine////////////////////
310 for (Int_t interval1=0; interval1<pag1; interval1++){
311
312 for (Int_t l = 0; l < size1; l++){ //ciclo su un sottogruppo
313 Br->GetEntry(ev1+l);
314 ph = eh->GetPscuHeader();
315 PscuCounter1[l]= ph->GetCounter(); // = PcktCounter[l]
316 FileOffset1[l]=ph->GetFileOffset();
317 tempo1[l]=ph->GetOrbitalTime();
318 if(ph->GetFileOffset()<= primoffset){
319 primoffset =ph->GetFileOffset();
320 primotempo=ph->GetOrbitalTime();
321 }
322 if(ph->GetFileOffset()>= ultimoffset){
323 ultimoffset = ph->GetFileOffset();
324 ultimotempo = ph->GetOrbitalTime();
325 }
326 if(l>0){
327 if(tempo1[l] < tempo1[l-1]){
328 salto[ll]= ph->GetOrbitalTime();
329 ll=ll+1;
330 }
331 }
332
333 m1=l;
334 }
335
336 TGraph *graph3= new TGraph(m1, FileOffset1, PscuCounter1);
337 graph3->SetMarkerColor(3);
338 graph3->SetMarkerSize(.5);
339 graph3->SetMarkerStyle(21);
340 mg1->Add(graph3);
341
342 TGraph *graph4= new TGraph(m1, FileOffset1, tempo1);
343 graph4->SetMarkerColor(kBlue);
344 graph4->SetMarkerSize(.5);
345 graph4->SetMarkerStyle(21);
346 mg2->Add(graph4);
347
348 ev1=ev1+10000;
349 }
350
351 }
352
353
354 TLatex *lat = new TLatex();
355 lat->SetTextAlign(12);
356 lat->SetTextSize(0.15);
357 lat->SetTextColor(kBlue);
358
359
360 //------------ Second Canvas ---------------------//
361 finalCanv2->cd(1);
362 all1->Draw();
363 all1->cd();
364 mg1->Draw("AP");
365 mg1->GetXaxis()->SetTitle("File Offset");
366 mg1->GetXaxis()->CenterTitle();
367 mg1->GetXaxis()->SetTitleSize(0.05);
368 mg1->GetXaxis()->SetLabelSize(0.04);
369 mg1->GetYaxis()->SetTitle("Counter");
370 mg1->GetYaxis()->CenterTitle();
371 mg1->GetYaxis()->SetTitleSize(0.05);
372 mg1->GetYaxis()->SetLabelSize(0.03);
373
374 finalCanv2->cd(2);
375 all->Draw();
376 all->cd();
377
378 oss3.str("");
379 oss3 << filename.Data() <<" OBT vs FileOffset. First packet = "<<primotempo <<" ms, Last packet = "<<ultimotempo<<" ms.";
380 mg2->SetTitle(oss3.str().c_str());
381 mg2->Draw("AP");
382 mg2->GetXaxis()->SetTitle("File Offset");
383 mg2->GetXaxis()->CenterTitle();
384 mg2->GetXaxis()->SetTitleSize(0.05);
385 mg2->GetXaxis()->SetLabelSize(0.04);
386 mg2->GetYaxis()->SetTitle("OBT");
387 mg2->GetYaxis()->CenterTitle();
388 mg2->GetYaxis()->SetTitleSize(0.05);
389 mg2->GetYaxis()->SetLabelSize(0.03);
390 double min2 = 0.8;
391 if(ll-1 > 0){
392 pad->Draw();
393 pad->cd();
394 stringa.str("");
395 stringa << "jump back at:";
396 lat->DrawLatex(0.08, min2, stringa.str().c_str());
397 for(Int_t kk=0; kk <(ll-1); kk++){
398 stringa.str("");
399 stringa << salto[kk];
400 min2=min2-0.1;
401 lat->DrawLatex(0.08, min2,stringa.str().c_str());
402 //cout<<salto[kk]<<";\n";
403 }
404 }
405
406 finalCanv2->Update();
407
408
409
410
411
412 oss1.str("");
413 oss1 << outDir.Data() << filename.Data();
414 oss1 << "_HeaderScan_2"<<"." << format.Data();
415
416 finalCanv2->SaveAs(oss1.str().c_str());
417
418 file->Close();
419
420 }
421
422 int main(int argc, char* argv[]){
423 TString path;
424 TString outDir = "./";
425 TString format = "jpg";
426 if (argc < 2){
427 printf("You have to insert at least the file to analyze \n");
428 printf("Try '--help' for more information. \n");
429 exit(1);
430 }
431 if (!strcmp(argv[1], "--help")){
432 printf( "Usage: HeaderScan FILE [OPTION] \n");
433 printf( "\t --help Print this help and exit \n");
434 printf( "\t -outDir[path] Path where to put the output [default ./] \n");
435 printf( "\t -format[jpg|ps|gif] Format for output files [default 'jpg'] \n");
436 exit(1);
437 }
438 path=argv[1];
439 for (int i = 2; i < argc; i++){
440 if (!strcmp(argv[i], "-outDir")){
441 if (++i >= argc){
442 printf( "-outDir needs arguments. \n");
443 printf( "Try '--help' for more information. \n");
444 exit(1);
445 }
446 else{
447 outDir = argv[i];
448 continue;
449 }
450 }
451 if (!strcmp(argv[i], "-format")){
452 if (++i >= argc){
453 printf( "-format needs arguments. \n");
454 printf( "Try '--help' for more information. \n");
455 exit(1);
456 }
457 else{
458 format = argv[i];
459 continue;
460 }
461 }
462 }
463 HeaderScan(argv[1], outDir, format);
464 }
465

  ViewVC Help
Powered by ViewVC 1.1.23