/[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.6 - (hide annotations) (download)
Thu Jun 8 10:33:53 2006 UTC (18 years, 6 months ago) by pam-fi
Branch: MAIN
Changes since 1.5: +55 -55 lines
*** empty log message ***

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

  ViewVC Help
Powered by ViewVC 1.1.23