/[PAMELA software]/quicklook/tracker/flight/src/TrkCalibQLook_BASIC.cpp
ViewVC logotype

Annotation of /quicklook/tracker/flight/src/TrkCalibQLook_BASIC.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Wed May 10 09:57:36 2006 UTC (18 years, 8 months ago) by pam-fi
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +0 -0 lines
FILE REMOVED
.cpp files removed

1 pam-fi 1.1 #include <utils/yodaUtility.h>
2     #include "TrkFunctions.cpp"
3     #include <iostream>
4     #include <fstream>
5     #include <TPaveText.h>
6     #include <TLatex.h>
7     #include <TCanvas.h>
8     #include <TGraph.h>
9     #include <TStyle.h>
10     #include <TObjString.h>
11     #include <PscuHeader.h>
12     #include <EventHeader.h>
13     #include <CalibTrk1Event.h>
14     #include <CalibTrk2Event.h>
15    
16     /**
17     * TrkCalibQLookBasic.cpp
18     *
19     * autor: D.Fedele
20     * version 1.0
21     * Parameters:
22     * base - the path to the root directory for the specific
23     * Pamela unpack session
24     * fromevent - first event to analyse
25     * toevent - last event to analyse
26     * outdir - total path of output file
27     * outfile - extension of output file (pdf,ps,gif,jpg)
28     *
29     */
30    
31     void TrkCalibQLook_BASIC(TString file,Int_t fromevent,Int_t toevent,TString outdir,TString outfile)
32     {
33     //
34     // obtain information about the data file and select the output dir
35     const string filepath=file.Data();
36     Int_t dwpos = filepath.find("DW_");
37     Int_t dwpos1 = filepath.find(".root");
38     TString fpath=(filepath.c_str());
39     TString base,ffile;
40     stringcopy(base,fpath,0,dwpos);
41     stringcopy(ffile,fpath,dwpos,dwpos1);
42    
43     TString out;
44     if(outdir.Length()==0){
45     out = base;
46     }else{
47     out = outdir;
48     };
49    
50     //
51     // inizialise the variables and open the file
52     struct caltrk_def ctrk;
53     Int_t nevents=0;
54     Int_t minevent = 0;
55     Int_t maxevent = 0;
56     ULong64_t OBT[2];
57    
58     OBT[0]=0;
59     OBT[1]=0;
60     ctrk.good0[0]=0;
61     ctrk.good0[1]=0;
62     for(Int_t i=0;i<12;i++){
63     ctrk.daqmode[i]=0;
64     ctrk.dspnum[i]=0;
65     ctrk.calibnum[i]=0;
66     ctrk.ncalev[i]=0;
67     ctrk.calfl[i]=0;
68     ctrk.ped1[i]=0;
69     ctrk.ped2[i]=0;
70     ctrk.ped3[i]=0;
71     ctrk.sig1[i]=0;
72     ctrk.sig2[i]=0;
73     ctrk.sig3[i]=0;
74     ctrk.nbad1[i]=0;
75     ctrk.nbad2[i]=0;
76     ctrk.nbad3[i]=0;
77     ctrk.crc_hc[i]=0;
78     ctrk.crc_c[i][0]=0;
79     ctrk.crc_c[i][1]=0;
80     ctrk.crc_c[i][2]=0;
81     for(Int_t iii=0;iii<3072;iii++){
82     ctrk.dspped[i][iii]=0;
83     ctrk.dspsig[i][iii]=0;
84     ctrk.dspbad[i][iii]=0;
85     }
86     }
87    
88     pamela::EventHeader *eh1=0,*eh2=0;
89     pamela::PscuHeader *ph1=0,*ph2=0;
90     pamela::CalibTrk1Event *trk1 = 0;
91     pamela::CalibTrk2Event *trk2 = 0;
92    
93     TFile *datafile = new TFile(file);
94     if ( !datafile ){
95     printf("No data file, exiting...\n");
96     return;
97     };
98     TTree *otr1,*otr2;
99    
100     otr1 = (TTree*)datafile->Get("CalibTrk1");
101     otr1->SetBranchAddress("CalibTrk1", &trk1);
102     otr1->SetBranchAddress("Header",&eh1);
103     otr2 = (TTree*)datafile->Get("CalibTrk2");
104     otr2->SetBranchAddress("CalibTrk2", &trk2);
105     otr2->SetBranchAddress("Header",&eh2);
106    
107    
108     if(otr1->GetEntries()==otr2->GetEntries())
109     nevents = otr1->GetEntries();
110     else{
111     printf("WARNING: CalibTrk1 entries is different from CalibTrk2 entries");
112     return;}
113    
114     if (nevents<=0) {
115     datafile->Close();
116     printf("No calibration packets found, exiting...\n");
117     return;
118     };
119     // printf("Number of calibration packets: %i\n",nevents);
120    
121     if ( fromevent > toevent && toevent ){
122     printf("It must be fromevent < toevent \n");
123     return;
124     };
125    
126     if ( fromevent > nevents || fromevent < 0 ) {
127     printf("You can choose fromevent between 0 (all) and %i \n",nevents);
128     return;
129     };
130    
131     if ( toevent > nevents || toevent < 0 ) {
132     printf("You can choose toevent between 0 (all) and %i \n",nevents);
133     return;
134     };
135     if ( fromevent == 0 ) {
136     minevent = 0;
137     maxevent = nevents;
138     } else {
139     minevent = fromevent - 1;
140     if ( toevent > 0 ){
141     maxevent = toevent;
142     } else if (toevent > nevents) {
143     maxevent = nevents;
144     } else {
145     maxevent = fromevent;
146     };
147     };
148    
149     //
150     // other variables definitions
151     stringstream fromfile,rep,tit;
152     fromfile<<"TrkCalibQLookBasic File: "<<ffile;
153    
154     gStyle->SetLabelSize(0.08,"x");
155     gStyle->SetLabelSize(0.08,"y");
156     gStyle->SetFillColor(0);
157     gStyle->SetTitleFillColor(0);
158     gStyle->SetTitleFontSize(0.1);
159     gStyle->SetTitleOffset(0.8,"y");
160     gStyle->SetTitleOffset(1.,"x");
161     gStyle->SetTitleSize(0.06,"y");
162     gStyle->SetTitleSize(0.06,"x");
163     gStyle->SetOptStat(0);
164    
165     TLatex *tzz=new TLatex();
166     tzz->SetTextFont(32);
167     tzz->SetTextColor(1);
168     tzz->SetTextAlign(12);
169     tzz->SetTextSize(0.02);
170    
171     Int_t canvasx=900;
172     Int_t canvasy=1200;
173    
174     Int_t ndsp =0,alarm=0;
175     Float_t pedav[12][12],pedavtemp[12][12],sigav[12][12],sigavtemp[12][12];
176     Int_t flpedav[12][12],flsigav[12][12];
177     Float_t siglimsup[12][12],sigliminf[12][12],pedlimsup[12][12],pedliminf[12][12];
178    
179     //
180     // inizialize the limits for simga and pedestall
181     for(Int_t i=0;i<12;i++){
182     for(Int_t ii=0;ii<12;ii++){
183     siglimsup[i][ii]=20.;
184     sigliminf[i][ii]=0.;
185     pedlimsup[i][ii]=3500.;
186     pedliminf[i][ii]=50.;
187     }
188     }
189    
190     //
191     // count of possible alarm to set the number of output pages
192     alarm+=(maxevent-minevent)/9 +1;
193     for (Int_t i = minevent; i < maxevent; i++){
194     otr1->GetEntry(i);
195     otr2->GetEntry(i);
196     for(Int_t m=0;m<6;m++){
197     for(Int_t mm=0;mm<3;mm++){
198     if(trk1->crc_cal[m][mm]!=0) alarm+=1;
199     if(trk2->crc_cal[m][mm]!=0 ) alarm+=1;
200     }
201     if(trk1->crc_hcal[m]!=0 ) alarm+=1;
202     if(trk1->cal_flag[m]!=0 ) alarm+=1;
203     if(trk2->crc_hcal[m]!=0) alarm+=1;
204     if(trk2->cal_flag[m]!=0) alarm+=1;
205     }
206     }
207     const Int_t cnum=alarm/30 + 10;
208     Int_t flcanvas=1;
209     Float_t spacep=1.5,space[cnum];
210     TCanvas *c[cnum];
211    
212     //
213     // create output canvas
214     for(Int_t i=0;i<cnum;i++){
215     space[i]=96.0;
216     rep.str("");
217     tit.str("");
218     tit<<"c"<<i;
219     rep<<"TrkCalibQLook_BASIC_pag"<<i+1;
220     c[i]=new TCanvas(tit.str().c_str(),rep.str().c_str(),canvasx,canvasy);
221     c[i]->Range(0,0,100,100);
222     tzz->DrawLatex(1,98.5,fromfile.str().c_str());
223     rep.str("");
224     rep<<"CALIBRATION REPORT pag"<<i+1;
225     tzz->DrawLatex(70,98.5,rep.str().c_str());
226     rep.str("");
227     }
228    
229    
230     //**********************************************************************
231     //
232     // LOOP OVER EVENTS
233     //
234     //**********************************************************************
235    
236     Int_t wc=0;
237     // printf("\n Scan of calibration packets from %i to %i ... \n",minevent+1,maxevent);
238     for (Int_t i = minevent; i < maxevent; i++){
239    
240     otr1->GetEntry(i);
241     otr2->GetEntry(i);
242    
243     ctrk.good0[0]=trk1->good0;
244     ctrk.good0[1]=trk2->good0;
245     for (Int_t m = 0; m < 6; m++){
246     ph1 = eh1->GetPscuHeader();
247     OBT[0]= ph1->GetOrbitalTime();
248     ctrk.daqmode[trk1->DSPnumber[m]-1]=trk1->DAQmode[m];
249     ctrk.dspnum[trk1->DSPnumber[m]-1]=trk1->DSPnumber[m];
250     ctrk.calibnum[trk1->DSPnumber[m]-1]=trk1->calibnumber[m];
251     ctrk.ncalev[trk1->DSPnumber[m]-1]=trk1->ncalib_event[m];
252     ctrk.ped1[trk1->DSPnumber[m]-1]=trk1->ped_l1[m];
253     ctrk.ped2[trk1->DSPnumber[m]-1]=trk1->ped_l2[m];
254     ctrk.ped3[trk1->DSPnumber[m]-1]=trk1->ped_l3[m];
255     ctrk.sig1[trk1->DSPnumber[m]-1]=trk1->sig_l1[m];
256     ctrk.sig2[trk1->DSPnumber[m]-1]=trk1->sig_l2[m];
257     ctrk.sig3[trk1->DSPnumber[m]-1]=trk1->sig_l3[m];
258     ctrk.nbad1[trk1->DSPnumber[m]-1]=trk1->nbad_l1[m];
259     ctrk.nbad2[trk1->DSPnumber[m]-1]=trk1->nbad_l2[m];
260     ctrk.nbad3[trk1->DSPnumber[m]-1]=trk1->nbad_l3[m];
261     ctrk.calfl[trk1->DSPnumber[m]-1]=trk1->cal_flag[m];
262     ctrk.crc_c[trk1->DSPnumber[m]-1][0]=trk1->crc_cal[m][0];
263     ctrk.crc_c[trk1->DSPnumber[m]-1][1]=trk1->crc_cal[m][1];
264     ctrk.crc_c[trk1->DSPnumber[m]-1][2]=trk1->crc_cal[m][2];
265     ctrk.crc_hc[trk1->DSPnumber[m]-1]=trk1->crc_hcal[m];
266     for (Int_t j = 0; j < 3072; j++){
267     ctrk.dspped[trk1->DSPnumber[m]-1][j]=trk1->DSPped_par[m][j];
268     ctrk.dspsig[trk1->DSPnumber[m]-1][j]=trk1->DSPsig_par[m][j];
269     ctrk.dspbad[trk1->DSPnumber[m]-1][j]=trk1->DSPbad_par[m][j];
270     }
271     ph2 = eh2->GetPscuHeader();
272     OBT[1]= ph2->GetOrbitalTime();
273     ctrk.daqmode[trk2->DSPnumber[m]-1]=trk2->DAQmode[m];
274     ctrk.dspnum[trk2->DSPnumber[m]-1]=trk2->DSPnumber[m];
275     ctrk.calibnum[trk2->DSPnumber[m]-1]=trk2->calibnumber[m];
276     ctrk.ncalev[trk2->DSPnumber[m]-1]=trk2->ncalib_event[m];
277     ctrk.ped1[trk2->DSPnumber[m]-1]=trk2->ped_l1[m];
278     ctrk.ped2[trk2->DSPnumber[m]-1]=trk2->ped_l2[m];
279     ctrk.ped3[trk2->DSPnumber[m]-1]=trk2->ped_l3[m];
280     ctrk.sig1[trk2->DSPnumber[m]-1]=trk2->sig_l1[m];
281     ctrk.sig2[trk2->DSPnumber[m]-1]=trk2->sig_l2[m];
282     ctrk.sig3[trk2->DSPnumber[m]-1]=trk2->sig_l3[m];
283     ctrk.nbad1[trk2->DSPnumber[m]-1]=trk2->nbad_l1[m];
284     ctrk.nbad2[trk2->DSPnumber[m]-1]=trk2->nbad_l2[m];
285     ctrk.nbad3[trk2->DSPnumber[m]-1]=trk2->nbad_l3[m];
286     ctrk.calfl[trk2->DSPnumber[m]-1]=trk2->cal_flag[m];
287     ctrk.crc_c[trk1->DSPnumber[m]-1][0]=trk2->crc_cal[m][0];
288     ctrk.crc_c[trk1->DSPnumber[m]-1][1]=trk2->crc_cal[m][1];
289     ctrk.crc_c[trk1->DSPnumber[m]-1][2]=trk2->crc_cal[m][2];
290     ctrk.crc_hc[trk1->DSPnumber[m]-1]=trk2->crc_hcal[m];
291     for (Int_t j = 0; j < 3072; j++){
292     ctrk.dspped[trk2->DSPnumber[m]-1][j]=trk2->DSPped_par[m][j];
293     ctrk.dspsig[trk2->DSPnumber[m]-1][j]=trk2->DSPsig_par[m][j];
294     ctrk.dspbad[trk2->DSPnumber[m]-1][j]=trk2->DSPbad_par[m][j];
295     }
296     }
297    
298     for(Int_t n = 0; n<12; n++){
299     for(Int_t nm = 0; nm<12; nm++){
300     pedav[n][nm]=0;
301     pedavtemp[n][nm]=0;
302     sigav[n][nm]=0;
303     sigavtemp[n][nm]=0;
304     flpedav[n][nm]=0;
305     flsigav[n][nm]=0;
306     }
307     }
308    
309     Int_t nn,ok=0;
310    
311     //
312     // write warning if it occur
313     for(Int_t n = 0; n<12; n++){
314    
315     ndsp = ctrk.dspnum[n];
316     nn = ndsp-1;
317    
318     for(Int_t iii=0;iii<3;iii++){
319     if(ctrk.crc_c[nn][iii]!=0){
320     ok=1;
321     if(space[wc]<=3){
322     wc+=1;
323     flcanvas+=1;
324     }
325     c[wc]->cd();
326     tzz->SetTextFont(40);
327     tzz->SetTextSize(0.02);
328     tzz->SetTextAlign(13);
329     tzz->SetTextColor(2);
330     rep<<"***************************************************************************************************************************";
331     tzz->DrawLatex(2,space[wc],rep.str().c_str());
332     rep.str("");
333     space[wc]-=spacep;
334     rep<<" ERROR >>> CALIBRATION pkt "<<i+1<<" -->CalibTrk"<<(nn+1)%2+1<<" at OBT: "<<OBT[(nn+1)%2]<<" --> crc_cal["<<nn+1<<"]["<<iii+1<<"]= "<<ctrk.crc_c[nn][iii];
335     tzz->DrawLatex(2,space[wc],rep.str().c_str());
336     rep.str("");
337     space[wc]-=spacep;
338     }
339     }
340    
341     if(ctrk.crc_hc[nn]!=0){
342     ok=1;
343     if(space[wc]<=3){
344     wc+=1;
345     flcanvas+=1;
346     }
347     c[wc]->cd();
348     tzz->SetTextFont(40);
349     tzz->SetTextSize(0.02);
350     tzz->SetTextAlign(13);
351     tzz->SetTextColor(2);
352     rep<<"***************************************************************************************************************************";
353     tzz->DrawLatex(2,space[wc],rep.str().c_str());
354     rep.str("");
355     space[wc]-=spacep;
356     rep<<" ERROR >>> CALIBRATION pkt "<<i+1<<" -->CalibTrk"<<(nn+1)%2+1<<" at OBT: "<<OBT[(nn+1)%2]<<" --> crc_hcal["<<nn+1<<"]= "<<ctrk.crc_hc[nn];
357     tzz->DrawLatex(2,space[wc],rep.str().c_str());
358     rep.str("");
359     space[wc]-=spacep;
360     }
361    
362     if(ctrk.calfl[nn]!=0){
363     ok=1;
364     if(space[wc]<=3){
365     wc+=1;
366     flcanvas+=1;
367     }
368     c[wc]->cd();
369     tzz->SetTextFont(40);
370     tzz->SetTextSize(0.02);
371     tzz->SetTextAlign(13);
372     tzz->SetTextColor(2);
373     rep<<"***************************************************************************************************************************";
374     tzz->DrawLatex(2,space[wc],rep.str().c_str());
375     rep.str("");
376     space[wc]-=spacep;
377     rep<<" ERROR >>> CALIBRATION pkt "<<i+1<<" -->CalibTrk"<<(nn+1)%2+1<<" at OBT: "<<OBT[(nn+1)%2]<<" --> cal_flag["<<nn+1<<"]= "<<ctrk.calfl[nn];
378     tzz->DrawLatex(2,space[wc],rep.str().c_str());
379     rep.str("");
380     space[wc]-=spacep;
381     }
382    
383     if(ctrk.good0[0]==1 && ctrk.good0[1]==1){
384     //
385     // evaluate the mean value of the sigma and pedestal
386     for(Int_t j = 0; j < 3072; j++){
387     sigavtemp[nn][j/256]+=ctrk.dspsig[nn][j];
388     pedavtemp[nn][j/256]+=ctrk.dspped[nn][j];
389     }
390    
391     for(Int_t ii=0;ii<12;ii++){
392     pedav[nn][ii]=pedavtemp[nn][ii]/256;
393     sigav[nn][ii]=sigavtemp[nn][ii]/256;
394    
395     if(pedav[nn][ii]>pedlimsup[nn][ii] || pedav[nn][ii]<pedliminf[nn][ii]) flpedav[nn][ii]=1;
396     if(sigav[nn][ii]>siglimsup[nn][ii] || sigav[nn][ii]<sigliminf[nn][ii]) flsigav[nn][ii]=1;
397    
398     if(flpedav[nn][ii]==1){
399     ok=1;
400     if(space[wc]<=3){
401     wc+=1;
402     flcanvas+=1;
403     }
404     c[wc]->cd();
405     tzz->SetTextFont(40);
406     tzz->SetTextSize(0.02);
407     tzz->SetTextAlign(13);
408     tzz->SetTextColor(50);
409     rep<<"********************************************************************************************************************************";
410     tzz->DrawLatex(2,space[wc],rep.str().c_str());
411     rep.str("");
412     space[wc]-=spacep;
413     rep<<"WARNING >>> CALIBRATION pkt "<<i+1<<" -->CalibTrk"<<(nn+1)%2+1<<" at OBT: "<<OBT[(nn+1)%2]<<"-->DSP "<<nn+1<<" -VA1 "<<2*ii+1<<"-"<<2*ii+2<<" --> <PED>= "<<pedav[nn][ii];
414     tzz->DrawLatex(2,space[wc],rep.str().c_str());
415     rep.str("");
416     space[wc]-=spacep;
417     }
418    
419     if(flsigav[nn][ii]==1){
420     ok=1;
421     if(space[wc]<=3){
422     wc+=1;
423     flcanvas+=1;
424     }
425     c[wc]->cd();
426     tzz->SetTextFont(40);
427     tzz->SetTextSize(0.02);
428     tzz->SetTextAlign(13);
429     tzz->SetTextColor(50);
430     rep<<"********************************************************************************************************************************";
431     tzz->DrawLatex(2,space[wc],rep.str().c_str());
432     rep.str("");
433     space[wc]-=spacep;
434     rep<<"WARNING >>> CALIBRATION pkt "<<i+1<<" -->CalibTrk"<<(nn+1)%2+1<<" at OBT: "<<OBT[(nn+1)%2]<<"-->DSP "<<nn+1<<" -VA1 "<<2*ii+1<<"-"<<2*ii+2<<" --> <SIG>= "<<sigav[nn][ii];
435     tzz->DrawLatex(2,space[wc],rep.str().c_str());
436     rep.str("");
437     space[wc]-=spacep;
438     }
439     }
440     }
441     }
442    
443     if(ok==0 && ctrk.good0[0]==1 && ctrk.good0[1]==1){
444     if(space[wc]<=10){
445     wc+=1;
446     flcanvas+=1;
447     }
448     c[wc]->cd();
449     tzz->SetTextFont(40);
450     tzz->SetTextSize(0.03);
451     tzz->SetTextAlign(13);
452     tzz->SetTextColor(1);
453     rep<<"*********************************** CALIBRATION pkt "<<i+1<<"********************************";
454     tzz->DrawLatex(2,space[wc],rep.str().c_str());
455     rep.str("");
456     space[wc]-=spacep+1;
457     rep<<">>>>>>> CalibTrk1 at OBT: "<<OBT[0]<<" ---------> OK ";
458     tzz->DrawLatex(2,space[wc],rep.str().c_str());
459     rep.str("");
460     space[wc]-=spacep+1;
461     rep<<">>>>>>> CalibTrk2 at OBT: "<<OBT[1]<<" ---------> OK ";
462     tzz->DrawLatex(2,space[wc],rep.str().c_str());
463     rep.str("");
464     space[wc]-=spacep+1;
465     rep<<"*******************************************************************************************";
466     tzz->DrawLatex(2,space[wc],rep.str().c_str());
467     rep.str("");
468     space[wc]-=spacep+1;
469     }
470     };//end loop on events
471     datafile->Close();
472    
473     //
474     // Save output Files
475     stringstream nom1,nom2,nom3;
476    
477     for(Int_t i=0;i<cnum;i++)
478     c[i]->Update();//draw pads in canvas
479    
480     for(Int_t fl=0;fl<flcanvas;fl++){
481     if(flcanvas==1){
482     nom1.str("");
483     nom1<<ffile<<"_TrkCalibQLook_BASIC."<<outfile.Data();
484     c[fl]->Print(out+nom1.str().c_str());
485     nom1.str("");
486     }
487    
488     if(flcanvas>=2){
489     if(!strcmp(outfile.Data(),"ps")||!strcmp(outfile.Data(),"pdf")){
490     nom1.str("");
491     nom2.str("");
492     nom3.str("");
493     nom1<<ffile<<"_TrkCalibQLook_BASIC.ps(";
494     nom2<<ffile<<"_TrkCalibQLook_BASIC.ps";
495     nom3<<ffile<<"_TrkCalibQLook_BASIC.ps)";
496     if(fl==0) c[fl]->Print(out+nom1.str().c_str(),"portrait");
497     else if(fl==flcanvas-1) c[fl]->Print(out+nom3.str().c_str(),"portrait");
498     else c[fl]->Print(out+nom2.str().c_str(),"portrait");
499    
500     }
501     else{
502     nom1.str("");
503     nom1<<ffile<<"_TrkCalibQLook_BASIC-pag"<<fl+1<<"."<<outfile.Data();
504     c[fl]->Print(out+nom1.str().c_str());
505     }
506     }
507     }
508    
509     if(!strcmp(outfile.Data(),"pdf")&&flcanvas>=2){
510     stringstream com;
511     com<<"ps2pdf13 "<<out<<ffile<<"_TrkCalibQLook_BASIC.ps "<<out<<ffile<<"_TrkCalibQLook_BASIC.pdf";
512     system(com.str().c_str());
513     com.str("");
514     com<<"rm -f "<<out<<ffile<<"_TrkCalibQLook_BASIC.ps";
515     system(com.str().c_str());
516     com.str("");
517     }
518    
519     for(Int_t i=0;i<cnum;i++)
520     delete c[i];
521    
522     gROOT->Reset();
523     // printf("... end of packets. \n");
524     return;
525    
526     }

  ViewVC Help
Powered by ViewVC 1.1.23