/[PAMELA software]/quicklook/tracker/flight/macros/FTrkQLook_BASIC.cxx
ViewVC logotype

Annotation of /quicklook/tracker/flight/macros/FTrkQLook_BASIC.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.19 - (hide annotations) (download)
Fri Jan 17 15:10:40 2014 UTC (10 years, 10 months ago) by mocchiut
Branch: MAIN
CVS Tags: HEAD
Changes since 1.18: +4 -0 lines
Compilation warnings using GCC4.7 fixed

1 pam-fi 1.1 /**
2 pam-fi 1.8 * FTrkQLook_BASIC.cxx
3 pam-fi 1.1 *
4     * autor: D.Fedele
5 pam-fi 1.18 * version v1r12
6 pam-fi 1.1 * Parameters:
7     * file - the data file to analyze
8     * fromevent - first event to analyze
9     * toevent - last event to analyze
10     * outdir - total path of output file
11     * outfile - extension of output file (pdf,ps,gif,jpg)
12     *
13     */
14     //
15     #include <TPaveText.h>
16     #include <TLatex.h>
17     #include <TCanvas.h>
18     #include <TGraph.h>
19     #include <TStyle.h>
20 pam-fi 1.8 #include <TFile.h>
21 pam-fi 1.1 #include <TTree.h>
22 pam-fi 1.2 #include <TArrow.h>
23 mocchiut 1.19 #include <TAxis.h>
24     #include <TROOT.h>
25     #include <cstdlib>
26     #include <sys/stat.h>
27 pam-fi 1.1 //
28     #include <physics/tracker/TrackerEvent.h>
29     #include <PscuHeader.h>
30     #include <EventHeader.h>
31     #include <RunHeaderEvent.h>
32 pam-fi 1.6 #include <EventCounter.h>
33     #include <PacketType.h>
34 pam-fi 1.1 //
35 pam-fi 1.4 #define MAXSTORAGE 50000
36 pam-fi 1.1
37     void FTrkQLook_BASIC(TString file,Int_t fromevent,Int_t toevent, TString outdir,TString outfile)
38     {
39     //
40     // obtain information about the data file and select the output dir
41 pam-fi 1.8 Int_t dwpos = file.Last('/');
42     Int_t dwpos1 = file.Last('.');
43 pam-fi 1.1 TString base,ffile ;
44 pam-fi 1.8 ffile=file(dwpos+1,dwpos1-(dwpos+1));
45     if(dwpos>0) base=file(0,dwpos);
46 pam-fi 1.1
47     TString out;
48     if(outdir.Length()==0){
49     out = base;
50     }else{
51     out = outdir;
52     }
53 pam-fi 1.8 if(out.Last('/')+1<out.Length()) out+="/";
54 pam-fi 1.1
55     //
56     // inizialise the variables and open the file
57     pamela::tracker::TrackerEvent *te=0;
58 pam-fi 1.2 pamela::EventHeader *eh=0,*eH=0,*ceh=0;
59 pam-fi 1.1 pamela::RunHeaderEvent *reh=0;
60     pamela::PscuHeader *ph=0,*pH=0;
61 pam-fi 1.6 pamela::EventCounter *cod=0;
62    
63     pamela::PacketType *pctp=0;
64 pam-fi 1.1
65     TFile *datafile = new TFile(file);
66     TTree *otr = (TTree*)datafile->Get("RunHeader");
67     otr->SetBranchAddress("Header",&eH);
68     otr->SetBranchAddress("RunHeader",&reh);
69     TTree *tr = (TTree*)datafile->Get("Physics");
70     tr->SetBranchAddress("Tracker",&te);
71     tr->SetBranchAddress("Header",&eh);
72 pam-fi 1.2 TTree *ctr = (TTree*)datafile->Get("CalibTrk1");
73     ctr->SetBranchAddress("Header",&ceh);
74    
75     Long64_t neventC = ctr->GetEntries();
76 pam-fi 1.1 Long64_t nevent = tr->GetEntries();
77     Long64_t neventH = otr->GetEntries();
78     Int_t minevent=0;
79     Int_t maxevent=0;
80    
81     printf("Number of total events: %lld\nNumber of total header events: %lld\n",nevent,neventH);
82 pam-fi 1.2 printf("Number of calibration events: %lld\n",neventC);
83 pam-fi 1.1
84     if (nevent<=0){
85     datafile->Close();
86     return;
87     }
88     if ( fromevent > toevent && toevent>0 ){
89     printf("It must be fromevent < toevent \n");
90     return;
91     }
92     if ( fromevent > nevent || fromevent < 0 ) {
93     printf("You can choose fromevent between 0 (all) and %lld \n",nevent);
94     return;
95     }
96     if ( toevent > nevent || toevent < 0 ) {
97     printf("You can choose toevent between 0 (all) and %lld \n",nevent);
98     return;
99     }
100     if ( fromevent == 0 ) {
101     minevent = 0;
102     maxevent = nevent;
103     } else {
104     minevent = fromevent;
105     if ( toevent > 0 ){
106     maxevent = toevent+1;
107     } else if (toevent > nevent) {
108     maxevent = nevent;
109     } else {
110 pam-fi 1.13 maxevent = nevent;
111 pam-fi 1.1 }
112     nevent=maxevent-minevent ;
113     }
114    
115     //
116     // other variables definitions
117     stringstream oss,fromfile,isfile;
118 pam-fi 1.7 //
119     // information about the RunHeader
120 pam-fi 1.18 ULong_t HOBT[neventH];
121 pam-fi 1.7 Int_t trk_cal_us[neventH];
122     for (Int_t vi=0; vi<neventH;vi++){
123 pam-fi 1.2 HOBT[vi]=0;
124     trk_cal_us[vi]=0;
125     }
126 pam-fi 1.7
127 pam-fi 1.1 //
128 pam-fi 1.7 // information about RunHeader
129     Int_t countnboot=1;
130 pam-fi 1.1 for (Int_t ev=0; ev<neventH; ev++){
131     otr->GetEntry(ev);
132     pH = eH->GetPscuHeader();
133     HOBT[ev]= pH->GetOrbitalTime();
134     trk_cal_us[ev]=reh->TRK_CALIB_USED;
135 pam-fi 1.2 if((HOBT[ev]<HOBT[ev-1]) && ev>0)
136 pam-fi 1.7 countnboot+=1;
137 pam-fi 1.1 }
138 pam-fi 1.12 countnboot+=(Int_t)(2*nevent/MAXSTORAGE);
139 pam-fi 1.7 // printf("\ncountnboot=%d\n",countnboot);
140 pam-fi 1.5
141 pam-fi 1.1 //
142 pam-fi 1.2 // information about calibration OBT
143 pam-fi 1.18 ULong_t COBT[neventC];
144 pam-fi 1.7 for (Int_t vi=0; vi<neventC;vi++){
145     COBT[vi]=0;
146     }
147 pam-fi 1.2 for (Int_t ev=0; ev<neventC; ev++){
148     ctr->GetEntry(ev);
149     pH = ceh->GetPscuHeader();
150     COBT[ev]= pH->GetOrbitalTime();
151     }
152 pam-fi 1.1
153 pam-fi 1.7 //
154     // Style options
155 pam-fi 1.1 gStyle->SetLabelSize(0.06,"x");
156     gStyle->SetLabelSize(0.06,"y");
157     gStyle->SetStatFontSize(0.075);
158 pam-fi 1.2 gStyle->SetOptStat(10);
159 pam-fi 1.1 gStyle->SetFillColor(10);
160     gStyle->SetTitleFontSize(0.1);
161 pam-fi 1.2 gStyle->SetTitleFillColor(10);
162 pam-fi 1.1 gStyle->SetTitleOffset(0.8,"y");
163     gStyle->SetTitleOffset(0.9,"x");
164     gStyle->SetTitleSize(0.06,"y");
165     gStyle->SetTitleSize(0.055,"x");
166    
167 pam-fi 1.7 //***************************************************************************************
168     // LOOP on each event
169     //***************************************************************************************
170    
171     if (fromevent!=0)
172     printf("\n Scan of events from %i to %i ... \n",minevent,maxevent-1);
173     else
174     printf("\n Scan of events from %i to %i ... \n",minevent+1,maxevent);
175    
176 pam-fi 1.2
177 pam-fi 1.6 Int_t minev=minevent,maxev=maxevent,hin=0,hfin=0,cin=0,cfin=0;
178 pam-fi 1.7 TPad *pad[12][countnboot];
179     TGraph *dataletime[12][countnboot],*dataletime1[12][countnboot];
180     TCanvas *DataTimeCanv[countnboot];
181     for(Int_t ii=0; ii<countnboot;ii++){
182 pam-fi 1.2 fromfile<<"FTrkQLook_BASIC File: "<<ffile;
183     isfile<<"DATALENGTH vs. OBT pag"<<ii+1;
184     DataTimeCanv[ii]=new TCanvas(isfile.str().c_str(),isfile.str().c_str(),900,1200);
185     DataTimeCanv[ii]->SetFillColor(10);
186     DataTimeCanv[ii]->Range(0,0,100,100);
187    
188     TLatex *t=new TLatex();
189     t->SetTextFont(32);
190     t->SetTextColor(1);
191     t->SetTextAlign(12);
192     t->SetTextSize(0.02);
193     t->DrawLatex(2.,98.7,fromfile.str().c_str());
194     TLatex *t1=new TLatex();
195     t1->SetTextFont(32);
196     t1->SetTextColor(1);
197     t1->SetTextAlign(12);
198     t1->SetTextSize(0.02);
199     t1->DrawLatex(70.,98.7,isfile.str().c_str());
200     fromfile.str("");
201     isfile.str("");
202    
203     fromfile<<"D = Default Calibration";
204     isfile<<"O = OnLine Calibration";
205     t->SetTextColor(6);
206     t->SetTextSize(0.018);
207     t->DrawLatex(70.,97.,fromfile.str().c_str());
208     t->SetTextColor(3);
209     t->DrawLatex(70.,96.,isfile.str().c_str());
210     fromfile.str("");
211     isfile.str("");
212    
213 pam-fi 1.7 fromfile<<"The green arrow (if present) points out the time of the online calibration";
214 pam-fi 1.6 t->DrawLatex(7.,96.,fromfile.str().c_str());
215 pam-fi 1.2 fromfile.str("");
216    
217     //*************************************************************************************
218     //book pads and histos
219     //***************************************************************************************
220    
221    
222 pam-fi 1.3 Float_t posy = 0.95; // up y-coord - top pads
223     Float_t hpad = 0; // pad height
224     Float_t posx1=0; // left x-coord - pad column
225     Float_t posx0=0; // x-coord - column division
226     Float_t wrel = 0; // relative x size of first sub-column
227     Float_t marg = 0.004; // margin among pads
228 pam-fi 1.2
229     hpad = (posy-marg*11)/6;
230     wrel = (1-marg*4)/2;
231     stringstream title;
232     stringstream hid;
233    
234     for(Int_t n = 0; n<12; n++) {
235     if ( (n+1)%2==1 ) {
236     if(n>1) posy = posy-(marg*2+hpad);
237     posx1 = marg;
238     posx0 = posx1 + wrel;
239     }
240     else {
241     posx1 = posx0 + 2*marg;
242     posx0 = posx1 + wrel;
243     }
244    
245     /* -----------> pad for histograms */
246     oss<<"pad"<<n*100+ii;
247     pad[n][ii]=new TPad(oss.str().c_str()," ",posx1,posy-hpad,posx0,posy,18,0,0);
248     oss.str("");
249     };
250    
251     TLine li;
252     li.SetLineColor(1);
253     li.SetLineStyle(1);
254     li.SetLineWidth(1);
255 pam-fi 1.1
256 pam-fi 1.2 TArrow ar;
257     ar.SetLineColor(3);
258     stringstream calus;
259    
260     TLatex *t2=new TLatex();
261     t2->SetTextFont(32);
262     t2->SetTextColor(1);
263     t2->SetTextAlign(13);
264     t2->SetTextSize(0.08);
265    
266     Int_t i=0;
267 pam-fi 1.18 ULong_t x[MAXSTORAGE], xb[MAXSTORAGE];
268 pam-fi 1.4 Float_t yyd[MAXSTORAGE][12],yyb[MAXSTORAGE][12];
269 pam-fi 1.7 Int_t countbad[12];
270 pam-fi 1.17 Float_t perc=0;
271     Double_t xMIN=0.,xMAX=0.;
272 pam-fi 1.7 for (Int_t n=0; n<12 ; n++)
273     countbad[n]=0;
274    
275     //
276     // obtain values of the datalenght
277 pam-fi 1.2 for (Int_t ev=minev; ev<maxevent; ev++){
278     tr->GetEntry(ev);
279     ph = eh->GetPscuHeader();
280 pam-fi 1.6 cod = eh->GetCounter();
281    
282     if(ev==minev){
283 pam-fi 1.7 if(cod->Get(pctp->CalibTrk1)>0) cin=cod->Get(pctp->CalibTrk1)-1;
284     else cin=cod->Get(pctp->CalibTrk1);
285     if(cin==cfin-1) cin+=1;
286    
287     if(cod->Get(pctp->RunHeader)>0) hin=cod->Get(pctp->RunHeader)-1;
288     else hin=cod->Get(pctp->RunHeader);
289     if(hin==hfin-1) hin+=1;
290 pam-fi 1.6 }
291    
292 pam-fi 1.2 if(ev==maxevent-1) maxev=maxevent-1;
293 pam-fi 1.6
294 pam-fi 1.18 if(((ULong_t)ph->GetOrbitalTime()<x[ev-minev-1] && ev-minev!=0) || ev-minev==MAXSTORAGE){
295 pam-fi 1.2 maxev=ev;
296     break;
297 pam-fi 1.1 }
298     else{
299 pam-fi 1.6 cfin=cod->Get(pctp->CalibTrk1);
300     hfin=cod->Get(pctp->RunHeader);
301 pam-fi 1.2 x[(ev-minev)]= ph->GetOrbitalTime();
302     i=0;
303    
304 pam-fi 1.14 for (Int_t n=0; n<12 ; n++){
305     i=te->DSPnumber[n]-1;
306     if(i>=0){
307     if(i<12){
308     yyb[countbad[i]][i]=0;
309     xb[countbad[i]]= 0;
310    
311     yyd[(ev-minev)][i]=te->DATAlength[n];
312     if(i==6){
313     if(yyd[(ev-minev)][i]>1500){
314     if(yyd[(ev-minev)][i]<3075){
315     yyb[countbad[i]][i]= yyd[(ev-minev)][i];
316     xb[countbad[i]]= x[(ev-minev)];
317     countbad[i]+=1;
318     }
319     }
320 pam-fi 1.2 }
321 pam-fi 1.14 else{
322     if(yyd[(ev-minev)][i]>750){
323     if(yyd[(ev-minev)][i]<3075){
324     yyb[countbad[i]][i]= yyd[(ev-minev)][i];
325     xb[countbad[i]]= x[(ev-minev)];
326     countbad[i]+=1;
327     }
328     }
329 pam-fi 1.2 }
330     }
331 pam-fi 1.1 }
332 pam-fi 1.14 }
333 pam-fi 1.1 }
334     }
335 pam-fi 1.2
336 pam-fi 1.7 //
337     // define limit for the Xaxis of the graphs
338    
339 pam-fi 1.6 xMAX=x[maxev-minev-1]+(x[maxev-minev-1]-x[0])/10;
340 pam-fi 1.7 if(xMAX>1000000) xMIN=x[0]-(x[maxev-minev-1]-x[0])/10;
341 pam-fi 1.17 if(xMAX<1000000 || xMIN<0) xMIN=0.;
342     if(xMIN==xMAX) xMIN=x[0] * x[0]/xMAX;
343 pam-fi 1.6
344 pam-fi 1.2
345 pam-fi 1.7 //
346     // Draw Histos
347 pam-fi 1.14 for (Int_t n=0; n<12 ; n++){
348 pam-fi 1.2
349 pam-fi 1.11 Double_t yd[maxev-minev],ybd[maxev-minev];
350     Double_t xd[maxev-minev],xbd[maxev-minev];
351    
352 pam-fi 1.2 for(Int_t v=0;v<maxev-minev;v++){
353 pam-fi 1.14 yd[v]=(Double_t)yyd[v][n];
354     ybd[v]=(Double_t)yyb[v][n];
355 pam-fi 1.11 xd[v]=(Double_t)x[v];
356     xbd[v]=(Double_t)xb[v];
357 pam-fi 1.2 }
358    
359 pam-fi 1.7 if(xMAX<1000000){
360 pam-fi 1.11 xd[maxev-minev-1]=0;
361     yd[maxev-minev-1]=0.;
362 pam-fi 1.7 }
363    
364 pam-fi 1.2 if((maxev-minev)>1000){
365 pam-fi 1.14 perc=(countbad[n]*100)/(maxev-minev);
366     if(perc>10) pad[n][ii]->SetFillColor(2);
367     else pad[n][ii]->SetFillColor(10);
368    
369 pam-fi 1.2 }
370     else{
371 pam-fi 1.14 if(countbad[n]>=100) pad[n][ii]->SetFillColor(2);
372     else pad[n][ii]->SetFillColor(10);
373 pam-fi 1.2 }
374    
375 pam-fi 1.15 oss<<"DSP "<<n+1;
376 pam-fi 1.2 DataTimeCanv[ii]->cd();
377 pam-fi 1.14 pad[n][ii]->SetFrameFillColor(10);
378     pad[n][ii]->Draw();
379     pad[n][ii]->cd();
380     dataletime[n][ii]= new TGraph((maxev-minev),xd,yd);
381 pam-fi 1.16 if(maxev-minev==1) dataletime[n][ii]->GetXaxis()->SetNdivisions(-501);
382 pam-fi 1.14 dataletime[n][ii]->SetTitle(oss.str().c_str());
383     dataletime[n][ii]->GetXaxis()->SetTitle("OBT (ms)");
384     dataletime[n][ii]->GetXaxis()->CenterTitle();
385     dataletime[n][ii]->GetXaxis()->SetRangeUser(xMIN,xMAX);
386     dataletime[n][ii]->GetYaxis()->SetTitle("datalength (Word 13 bit)");
387     dataletime[n][ii]->GetYaxis()->CenterTitle();
388     if(i==6) dataletime[n][ii]->GetYaxis()->SetRangeUser(0,4500);
389     else dataletime[n][ii]->GetYaxis()->SetRangeUser(0,4000);
390     dataletime[n][ii]->SetMarkerStyle(21);
391     if((maxev-minev)<50) dataletime[n][ii]->SetMarkerSize(0.5);
392     else dataletime[n][ii]->SetMarkerSize(0.1);
393     dataletime[n][ii]->SetMarkerColor(4);
394     dataletime[n][ii]->Draw("ap");
395 pam-fi 1.2
396    
397     if((maxev-minev)>1000 && perc>10){
398 pam-fi 1.14 dataletime1[n][ii]= new TGraph(countbad[n],xbd,ybd);
399     dataletime1[n][ii]->SetMarkerStyle(21);
400     dataletime1[n][ii]->SetMarkerSize(0.1);
401     dataletime1[n][ii]->SetMarkerColor(2);
402     dataletime1[n][ii]->Draw("psame");
403     }
404     else if((maxev-minev)<1000 && countbad[n]>=100){
405     dataletime1[n][ii]= new TGraph(countbad[n],xbd,ybd);
406     dataletime1[n][ii]->SetMarkerStyle(21);
407     if((maxev-minev)<50) dataletime1[n][ii]->SetMarkerSize(0.5);
408     else dataletime1[n][ii]->SetMarkerSize(0.1);
409     dataletime1[n][ii]->SetMarkerColor(2);
410     dataletime1[n][ii]->Draw("psame");
411 pam-fi 1.2 }
412     li.SetLineColor(1);
413     li.SetLineStyle(1);
414     li.SetLineWidth(1);
415     if(i!=6) li.DrawLine(xMIN,750,xMAX,750);
416     else li.DrawLine(xMIN,1500,xMAX,1500);
417     li.DrawLine(xMIN,3075,xMAX,3075);
418    
419 pam-fi 1.1 li.SetLineColor(12);
420     li.SetLineStyle(4);
421     li.SetLineWidth(1);
422 pam-fi 1.6 for(Int_t j=hin;j<hfin;j++){
423     if(i==6) li.DrawLine(HOBT[j],0.,HOBT[j],4500.);
424 pam-fi 1.7 else li.DrawLine(HOBT[j],0.,HOBT[j],4000.);
425 pam-fi 1.6 if(trk_cal_us[j]==104){
426     calus<<"D";
427     t2->SetTextColor(6);
428     if(i==6) t2->DrawLatex(HOBT[j],4350.,calus.str().c_str());
429 pam-fi 1.7 else t2->DrawLatex(HOBT[j],3850.,calus.str().c_str());
430 pam-fi 1.6 calus.str("");
431     }
432 pam-fi 1.2 else{
433 pam-fi 1.6 calus<<"O";
434     t2->SetTextColor(3);
435     if(i==6) t2->DrawLatex(HOBT[j],4350.,calus.str().c_str());
436 pam-fi 1.7 else t2->DrawLatex(HOBT[j],3850.,calus.str().c_str());
437 pam-fi 1.6 calus.str("");
438 pam-fi 1.2 }
439     }
440 pam-fi 1.6 for(Int_t j=cin;j<cfin;j++){
441     if(i==6) ar.DrawArrow(COBT[j],1700.,COBT[j],2700.,0.01,"<");
442     else ar.DrawArrow(COBT[j],1000.,COBT[j],2000.,0.01,"<");
443 pam-fi 1.1 }
444 pam-fi 1.7
445 pam-fi 1.2 oss.str("");
446     DataTimeCanv[ii]->Update();
447 pam-fi 1.1 }
448 pam-fi 1.2
449     minev=maxev;
450     if(maxev==maxevent-1) {
451 pam-fi 1.7 countnboot=ii+1;
452 pam-fi 1.2 break;
453     }
454     }
455 pam-fi 1.1 printf("... end of packets. \n");
456 pam-fi 1.7
457 pam-fi 1.1 //*************************************************************************
458     // Save output Files
459     //*************************************************************************
460 pam-fi 1.2 stringstream nom1,nom2,nom3;
461    
462 pam-fi 1.7 for(Int_t fl=0;fl<countnboot;fl++){
463     if(countnboot==1){
464 pam-fi 1.2 nom1<<ffile<<"_FTrkQLook_BASIC."<<outfile.Data();
465     DataTimeCanv[fl]->Print(out+nom1.str().c_str());
466     nom1.str("");
467     }
468    
469 pam-fi 1.7 if(countnboot>=2){
470 pam-fi 1.2 if(!strcmp(outfile.Data(),"ps") || !strcmp(outfile.Data(),"pdf")){
471     nom1.str("");
472     nom2.str("");
473     nom3.str("");
474     nom1<<ffile<<"_FTrkQLook_BASIC.ps(";
475     nom2<<ffile<<"_FTrkQLook_BASIC.ps";
476     nom3<<ffile<<"_FTrkQLook_BASIC.ps)";
477     if(fl==0) DataTimeCanv[fl]->Print(out+nom1.str().c_str(),"portrait");
478 pam-fi 1.7 else if(fl==countnboot-1) DataTimeCanv[fl]->Print(out+nom3.str().c_str(),"portrait");
479 pam-fi 1.2 else DataTimeCanv[fl]->Print(out+nom2.str().c_str(),"portrait");
480    
481     }
482     else{
483     nom1.str("");
484     nom1<<ffile<<"_FTrkQLook_BASIC-pag"<<fl+1<<"."<<outfile.Data();
485     DataTimeCanv[fl]->Print(out+nom1.str().c_str());
486     }
487     }
488     }
489 pam-fi 1.1
490 pam-fi 1.7 //
491     // Convert ps to pdf if required
492     if(!strcmp(outfile.Data(),"pdf") && countnboot>=2){
493 pam-fi 1.2 stringstream com;
494     com<<"ps2pdf13 "<<out<<ffile<<"_FTrkQLook_BASIC.ps "<<out<<ffile<<"_FTrkQLook_BASIC.pdf";
495     system(com.str().c_str());
496     printf("\n---> ps file converted in pdf format!\n");
497     com.str("");
498     com<<"rm -f "<<out<<ffile<<"_FTrkQLook_BASIC.ps";
499     system(com.str().c_str());
500     printf("---> ps file removed!\n\n");
501     com.str("");
502     }
503 pam-fi 1.1
504 pam-fi 1.2 datafile->Close();
505 pam-fi 1.1 gROOT->Reset();
506     return;
507     }

  ViewVC Help
Powered by ViewVC 1.1.23