/[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.7 - (hide annotations) (download)
Thu Jun 8 17:03:57 2006 UTC (18 years, 5 months ago) by pam-fi
Branch: MAIN
CVS Tags: R3v00
Changes since 1.6: +85 -76 lines
release R3v00

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

  ViewVC Help
Powered by ViewVC 1.1.23