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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (hide annotations) (download)
Tue Aug 22 15:47:49 2006 UTC (18 years, 3 months ago) by pam-fi
Branch: MAIN
CVS Tags: v1r11, v1r10
Changes since 1.8: +6 -1 lines
*** empty log message ***

1 pam-fi 1.1 /**
2     * FTrkScanQlook_EXPERT.cxx
3     *
4     * autor: D.Fedele
5 pam-fi 1.9 * version v1r10
6 pam-fi 1.1 * Parameters:
7     * file - the path to the root file to analyze
8     * outdir - total path of output file
9     * event - the number of the single event to analyze
10     * DSPprint - the number of a particular DSP to draw (0 don't draw)
11     * outfile - extension of output file (pdf,ps,gif,jpg)
12     *
13     */
14     //
15     #include <iostream>
16     #include <sstream>
17     //
18     #include <TPaveText.h>
19     #include <TLatex.h>
20     #include <TCanvas.h>
21     #include <TGraph.h>
22 pam-fi 1.5 #include <TFile.h>
23 pam-fi 1.1 #include <TTree.h>
24     #include <TStyle.h>
25     #include <TString.h>
26     //
27     #include <physics/tracker/TrackerEvent.h>
28 pam-fi 1.3 #include <PscuHeader.h>
29     #include <EventHeader.h>
30     #include <RunHeaderEvent.h>
31 pam-fi 1.1 //
32    
33     using namespace std;
34    
35     typedef struct trkword{
36     int type;
37     int decode;
38     };
39    
40     /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
41     *
42     | The function "datadecode" decodes the tracker words.
43     *
44     | Tracker words are of three types:
45     * - ADC data
46     | - strip address
47     * - end of ladder
48     |
49     * The function returns a struct variable (trkword)
50     | that contains two quantities, type and decode, which are assigned
51     * the following values:
52     |
53     * type decode
54     | ----------------------------------------------------
55     * -1 error 0
56     | 0 data 0-4095 ADC values
57     * 1 address 0-1023 strip address (relative to ladder)
58     | 2 end-of-ladder 1,2,3 ladder number (compressed acq mode)
59     * 4,5,6 ladder number + 3 (full acq mode)
60     |
61     *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
62     trkword datadecode(int word){
63     int type =0;
64     int data =0;
65     int nodata = word&0xf000;
66     int zero = 0;
67    
68     trkword thisword;
69    
70     switch (nodata>>12){
71    
72     case 0:
73    
74     thisword.decode = word;
75     thisword.type = 0;
76     // cout << thisword.decode << "\n";
77     return (thisword); //>>>>> ADC data (0)
78    
79     case 1:
80    
81     type = word&0xC00;
82     data = word&0x3ff;
83    
84     switch(type>>10){
85    
86     case 0:
87     thisword.decode = data;
88     thisword.type = 1; //>>> address (1)
89     return (thisword);
90    
91     case 2:
92     // if(data>=4)data = data-3;
93     if(data>6){
94     printf("Error on data \n");
95     thisword.decode = zero;
96     thisword.type = -1;
97     return (thisword); //>>>>> error (-1)
98     }
99     thisword.decode = data;
100     thisword.type = 2;
101     return (thisword); //>>> end-of-ladder
102    
103     default:
104     printf("Error on data \n");
105     thisword.decode = zero;
106     thisword.type = -1;
107     return (thisword); //>>>>> error (-1)
108    
109     }
110    
111     default:
112    
113     printf("Error on data \n");
114     thisword.decode = zero;
115     thisword.type = -1;
116     return (thisword); //>>>>> error (-1)
117     }
118     }
119    
120    
121     void FTrkScanQLook_EXPERT(TString file, TString outdir,Int_t event, Int_t DSPprint, TString outfile)
122     {
123    
124     //
125     // obtain information about the data file and select the output file
126 pam-fi 1.5 Int_t dwpos = file.Last('/');
127     Int_t dwpos1 = file.Last('.');
128 pam-fi 1.1 TString base,ffile ;
129 pam-fi 1.5 ffile=file(dwpos+1,dwpos1-(dwpos+1));
130     if(dwpos>0) base=file(0,dwpos);
131 pam-fi 1.1
132     TString out;
133     if(outdir.Length()==0){
134     out = base;
135     }else{
136     out = outdir;
137     }
138 pam-fi 1.5 if(out.Last('/')+1<out.Length()) out+="/";
139 pam-fi 1.1
140     pamela::tracker::TrackerEvent *trk=0;
141 pam-fi 1.3 pamela::EventHeader *eh=0,*eH=0;
142     pamela::PscuHeader *ph=0,*pH=0;
143     pamela::RunHeaderEvent *reh=0;
144 pam-fi 1.1
145     // open files
146     TFile *trackerFile = new TFile(file);
147     if ( !trackerFile ){
148     trackerFile->Close();
149     printf("No tracker file! \n");
150     return;
151     }
152    
153     //Takes the tree and branches
154 pam-fi 1.3 TTree *tr = (TTree*)trackerFile->Get("Physics");
155     tr->SetBranchAddress("Tracker",&trk);
156     tr->SetBranchAddress("Header",&eh);
157    
158     TTree *otr = (TTree*)trackerFile->Get("RunHeader");
159     otr->SetBranchAddress("Header",&eH);
160     otr->SetBranchAddress("RunHeader",&reh);
161 pam-fi 1.1
162     // Define variables
163 pam-fi 1.3 Int_t nevents = tr->GetEntries();
164     Int_t neventH = otr->GetEntries();
165 pam-fi 1.1 if ( nevents <= 0 ) {
166     trackerFile->Close();
167     printf("The file is empty, exiting...\n");
168     return;
169     }
170    
171    
172     printf("\n Number of Entries: %d\n",nevents);
173 pam-fi 1.3 printf(" Number of Header Entries: %d\n",neventH);
174 pam-fi 1.1
175 pam-fi 1.3 Long64_t obt=0;
176 pam-fi 1.7 Int_t ev[2];
177     TString cal="";
178    
179     ev[0]=0;
180     ev[1]=0;
181 pam-fi 1.3 for(Int_t i=0;i<neventH;i++){
182     otr->GetEntry(i);
183     pH = eH->GetPscuHeader();
184     if(reh->TRK_CALIB_USED!=104){
185     obt = pH->GetOrbitalTime();
186 pam-fi 1.7 cal="Event with online calibration";
187 pam-fi 1.3 break;
188     }
189     if(i==neventH-1){
190 pam-fi 1.7 cal="***** ONLINE CALIBRATION NOT FOUND IN THIS FILE *****";
191     ev[0]=2;
192     ev[1]=3;
193 pam-fi 1.3 }
194     }
195 pam-fi 1.7 if(ev[0]==0){
196     for(Int_t i=0;i<nevents;i++){
197     tr->GetEntry(i);
198     ph = eh->GetPscuHeader();
199     if(ph->GetOrbitalTime()>obt){
200     ev[0]=i+2;
201     ev[1]=i+3;
202     break;
203     }
204 pam-fi 1.3 }
205     }
206    
207    
208     TH1F *histomax[12][2]; //histos of max signals
209     TH1F *histocomp[12][2]; //histos of compressed data
210     TH1F *histofull[12][2]; //histos of full data
211     TCanvas *c1[2];
212    
213     for(Int_t e=0;e<2;e++){
214     event=ev[e];
215 pam-fi 1.7 printf("Scan of Entry %d\n",event);
216 pam-fi 1.1
217 pam-fi 1.7 tr->GetEntry(event);
218 pam-fi 1.3 //============================================================================
219    
220     gStyle->SetLabelSize(0.06,"x");
221     gStyle->SetLabelSize(0.06,"y");
222     gStyle->SetTitleFontSize(0.1);
223     gStyle->SetFillColor(10);
224     gStyle->SetTitleFillColor(10);
225     gStyle->SetTitleOffset(-1,"Y");
226     gStyle->SetOptStat(0);
227 pam-fi 1.1
228 pam-fi 1.3 // draw display area
229 pam-fi 1.1
230 pam-fi 1.3 Int_t canvasx=1200;
231     Int_t canvasy=900;
232     stringstream figsav;
233     figsav.str("");
234     figsav<<out<<ffile<<"_FTrkScanQLook_EXPERT_ev"<<event+1<<"."<<outfile.Data();
235     c1[e] = new TCanvas(figsav.str().c_str(),"FTrkQLookSCAN",canvasx,canvasy);
236     c1[e]->SetFillColor(10);
237     c1[e]->Range(0,0,1,1);
238     stringstream fromfile;
239 pam-fi 1.7 fromfile<<"FTrkScanQLook_EXPERT File: "<<ffile<<" ----> Entry "<<event;
240 pam-fi 1.3 TLatex *t=new TLatex();
241     t->SetTextFont(32);
242     t->SetTextColor(1);
243     t->SetTextAlign(12);
244     t->SetTextSize(0.02);
245     t->DrawLatex(0.02,0.98,fromfile.str().c_str());
246 pam-fi 1.7 t->DrawLatex(0.60,0.98,cal.Data());
247 pam-fi 1.3
248     // draw pads
249     TPad *trkpad[12]; //pad for histos
250     TPaveText *trkpadtext[12]; //pad for header
251     Double_t posy = 0.95; // up y-coord - top pads
252     Double_t hpad = 0.15; // pad height
253     Double_t posx1=0; // left x-coord - pad column
254     Double_t posx2=0; // right x-coord - pad olumn
255     Double_t posx0=0; // x-coord - column division
256     Double_t wrel = 0.6; // relative x size of first sub-column
257     Double_t marg = 0.004; // margin among pads
258    
259    
260     stringstream title;
261     stringstream hid;
262     for(Int_t n = 0; n<12; n++){
263     if ( (n+1)%2 ) {
264     if(n>1)posy = posy-(marg*2+hpad);
265     posx1 = marg;
266     posx2 = 0.5 - marg;
267     posx0 = 0.5*wrel;
268     } else {
269     posx1 = posx1 + 0.5;
270     posx2 = posx2 + 0.5;
271     posx0 = posx0 + 0.5;
272     };
273 pam-fi 1.1
274 pam-fi 1.3 /* -----------> pad for histograms */
275     trkpad[n] = new TPad("pad"," ",posx1,posy-hpad,posx0-marg,posy,18,0,0);
276     trkpad[n]->SetFillColor(19);
277     trkpad[n]->SetFrameFillColor(10);
278     /* -----------> pad for header dump */
279     trkpadtext[n] = new TPaveText((posx0+marg),(posy-hpad),posx2,posy);
280     /* -----------> HISTOGRAMS */
281    
282     title<<"DSP "<<n+1;
283     hid<<"h"<<n+e*100;
284     histomax[n][e] = new TH1F(hid.str().c_str(),title.str().c_str(),3073,-0.5,3072.5);
285     hid<<"hh"<<n+e*100;
286     histocomp[n][e] = new TH1F(hid.str().c_str(),title.str().c_str(),3073,-0.5,3072.5);
287     hid<<"hhh"<<n+e*100;
288     histofull[n][e] = new TH1F(hid.str().c_str(),title.str().c_str(),3073,-0.5,3072.5);
289     title.str("");
290     hid.str("");
291     } //end loop on views
292    
293     // = = = = = = = = = = = = = = = = = = = = = = = = =
294     // create header dump retrieving event info
295     // = = = = = = = = = = = = = = = = = = = = = = = = =
296     Int_t ndsp=0;
297     stringstream message;
298    
299     Double_t whistomax[3072];
300     Double_t whisto[3072];
301     Double_t whistocomp[3072];
302     Double_t whistofull[3072];
303    
304     //=============================================
305     // transmitted words
306     Int_t word = 0;
307     Int_t iword = 0;
308     Int_t TOTDATAlength_check = 0;
309     Int_t ii=0,ifull[12],icomp[12],imax[12],nn=0;
310     trkword thisword;
311 pam-fi 1.1
312 pam-fi 1.3 Int_t address,ladder;
313 pam-fi 1.1
314 pam-fi 1.3 for(Int_t n = 0; n<12; n++){
315 pam-fi 1.1
316 pam-fi 1.3 ndsp = trk->DSPnumber[n];
317     nn = ndsp-1;
318     ifull[nn]=0;
319     icomp[nn]=0;
320     imax[nn]=0;
321 pam-fi 1.1
322 pam-fi 1.3 /*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*
323     *
324     * Write event LEVEL0 report
325     *
326     *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*/
327    
328     trkpadtext[nn]->SetTextFont(40);
329     trkpadtext[nn]->SetFillColor(33);
330     trkpadtext[nn]->SetTextSize(0.012);
331     trkpadtext[nn]->SetTextAlign(13);
332    
333     trkpadtext[nn]->AddText(" ");
334     message<<"DAQ mode --------> "<<trk->DAQmode[n];
335     trkpadtext[nn]->AddText(message.str().c_str());
336     message.str("");
337     message<<"Event number --------> "<<trk->eventn[n];
338     trkpadtext[nn]->AddText(message.str().c_str());
339     message.str("");
340     message<<"13-bit words --------> "<<trk->DATAlength[n];
341     trkpadtext[nn]->AddText(message.str().c_str());
342     message.str("");
343     if (!(nn%2)&&trk->signcluster[n][0]!=0) message<<"L1 add: "<<trk->addrcluster[n][0]<<" - sign: "<<1024-(trk->signcluster[n][0]);
344     else message<<"L1 add: "<<trk->addrcluster[n][0]<<" - sign: "<<(trk->signcluster[n][0]);
345     trkpadtext[nn]->AddText(message.str().c_str());
346     message.str("");
347     if (!(nn%2)&&trk->signcluster[n][1]!=0) message<<"L2 add: "<<trk->addrcluster[n][1]<<" - sign: "<<1024-(trk->signcluster[n][1]);
348     else message<<"L2 add: "<<trk->addrcluster[n][1]<<" - sign: "<<trk->signcluster[n][1];
349     trkpadtext[nn]->AddText(message.str().c_str());
350     message.str("");
351     if (!(nn%2)&&trk->signcluster[n][2]!=0) message<<"L3 add: "<<trk->addrcluster[n][2]<<" - sign: "<<1024-(trk->signcluster[n][2]);
352     else message<<"L3 add: "<<trk->addrcluster[n][2]<<" - sign: "<<trk->signcluster[n][2];
353     trkpadtext[nn]->AddText(message.str().c_str());
354     message.str("");
355     message<<"NCLUST "<<trk->nclust[n]<<" CUTC "<<trk->cutc[n]<<" CUTCL "<<trk->cutcl[n];
356     trkpadtext[nn]->AddText(message.str().c_str());
357     message.str("");
358     message<<"Comp. time "<<trk->compressiontime[n]<<" x 0.051ms = "<<0.051*trk->compressiontime[n]<<" ms";
359     trkpadtext[nn]->AddText(message.str().c_str());
360     message.str("");
361     trkpadtext[nn]->AddText(" ");
362     message<<"CRC --> "<<trk->crc[n];
363     trkpadtext[nn]->AddText(message.str().c_str());
364     message.str("");
365     message<<"FL1-6 --> "<<trk->fl1[n]<<" "<<trk->fl2[n]<<" "<<trk->fl3[n]<<" "<<trk->fl4[n]<<" "<<trk->fl5[n]<<" "<<trk->fl6[n]<<" FC "<<trk->fc[n];
366     trkpadtext[nn]->AddText(message.str().c_str());
367     message.str("");
368     trkpadtext[nn]->AddText(" ");
369     trkpadtext[nn]->AddLine(0,0,0,0);
370     message<<"PNum "<<trk->pnum[n]<<" - BId "<<trk->bid[n]<<" ALARM "<<trk->alarm[n];
371     trkpadtext[nn]->AddText(message.str().c_str());
372     message.str("");
373     message<<"Cmd "<<trk->cmdnum[n]<<" --- Answer length "<<trk->aswr[n]<<" byte";
374     trkpadtext[nn]->AddText(message.str().c_str());
375     message.str("");
376     trkpadtext[nn]->AddText(" ");
377 pam-fi 1.1
378 pam-fi 1.3 TOTDATAlength_check = TOTDATAlength_check + trk->DATAlength[n];
379 pam-fi 1.1
380 pam-fi 1.3 /*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*
381     *
382     * Plot event LEVEL0 histo
383     *
384     *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*/
385    
386     //=============================================
387    
388     for(Int_t i = 0; i< 3072; i++){
389     whistomax[i] = -200;
390     whistocomp[i] = -200;
391     whistofull[i] = -200;
392     whisto[i] = -200;
393     }
394 pam-fi 1.1
395 pam-fi 1.3 // ===============
396     // trasmitted data
397     // ===============
398    
399     address = 0;
400     ladder = 1;
401     for(Int_t i = 0; i < trk->DATAlength[n] ; i++){
402     word = trk->TrackerData.At(iword);
403     thisword = datadecode(word);
404     iword++;
405     switch (thisword.type){
406 pam-fi 1.1
407 pam-fi 1.3 case 0: //ADC value
408     whisto[address] = thisword.decode;
409     address++;
410     // cout << " adr " << address << "\n";
411     break;
412    
413     case 1: //address
414     address = 1024*(ladder-1) + thisword.decode;
415     // cout << " adr " << address << "\n";
416     break;
417    
418     case 2: //end-of-ladder
419     ladder = thisword.decode;
420     // cout << "Ladder " << ladder << "\n";
421     if(ladder==3){
422     // end of compressed data - FILL HISTO
423     //cout << ">>> COMPRESSED data" << "\n";
424     for(ii = 0; ii < 3072; ii++){
425     whistocomp[ii]=whisto[ii];
426     whisto[ii] = -200;
427     }
428     address = 0;
429     ladder = 1;
430     }else if(ladder==6){
431     // end of full data - FILL HISTO
432     //cout << ">>> FULL data" << "\n";
433     for(ii = 0; ii < 3072; ii++){
434     whistofull[ii]=whisto[ii];
435     whisto[ii] = -200;
436     }
437     address = 0;
438     ladder = 1;
439     }else{
440     if(ladder>3) ladder=ladder-3;
441     address= ladder*1024;
442     ladder = ladder + 1;
443 pam-fi 1.1 }
444 pam-fi 1.3 }
445 pam-fi 1.1 }
446    
447    
448 pam-fi 1.3 // ===============
449     // maximum signals
450     // ===============
451     if(trk->signcluster[nn][0]!=0) whistomax[ 0+(int)trk->addrcluster[nn][0]] = whistocomp[ 0+(int)trk->addrcluster[nn][0]];
452     if(trk->signcluster[nn][1]!=0) whistomax[1024+(int)trk->addrcluster[nn][1]] = whistocomp[1024+(int)trk->addrcluster[nn][1]];
453     if(trk->signcluster[nn][2]!=0) whistomax[2048+(int)trk->addrcluster[nn][2]] = whistocomp[2048+(int)trk->addrcluster[nn][2]];
454    
455     for(Int_t i = 0; i < 3072; i++){
456     if(whistomax[i]>-200) imax[nn]=1;
457     if(whistocomp[i]>-200) icomp[nn]=1;
458     if(whistofull[i]>-200) ifull[nn]=1;
459     histomax[nn][e]->Fill((Float_t)i,whistomax[i]);
460     histocomp[nn][e]->Fill((Float_t)i,whistocomp[i]);
461     histofull[nn][e]->Fill((Float_t)i,whistofull[i]);
462     }
463 pam-fi 1.2
464 pam-fi 1.3 TBox b;
465    
466     c1[e]->cd();
467     trkpadtext[nn]->Draw();
468     trkpad[nn]->Draw();
469     trkpad[nn]->cd();
470     trkpad[nn]->SetFillColor(10);
471    
472     histocomp[nn][e]->GetYaxis()->SetRangeUser(-500,4500);
473     histocomp[nn][e]->SetLineStyle(1);
474     histocomp[nn][e]->SetLineColor(38);
475     histocomp[nn][e]->SetFillColor(38);
476     histocomp[nn][e]->SetLineWidth(1);
477     histocomp[nn][e]->Draw("");
478    
479     histofull[nn][e]->SetLineColor(40);
480     histofull[nn][e]->SetFillColor(40);
481     histofull[nn][e]->SetLineWidth(1);
482     histofull[nn][e]->SetLineStyle(2);
483    
484     histomax[nn][e]->SetLineColor(2);
485     histomax[nn][e]->SetLineWidth(1);
486     histomax[nn][e]->SetLineStyle(3);
487    
488     if(ifull[nn]==1) histofull[nn][e]->Draw("9bsame][");
489     if(icomp[nn]==1) histocomp[nn][e]->Draw("9bsame][");
490     if(imax[nn]==1) histomax[nn][e]->Draw("same][");
491     histocomp[nn][e]->Draw("axis same");
492     if(nn==1){
493 pam-fi 1.8 b.SetFillColor(6);
494     b.SetFillStyle(3945);
495     b.DrawBox(2944.,-500.,3060.,4500.);
496    
497     b.SetFillColor(107);
498     b.SetFillStyle(3954);
499     b.DrawBox(2816.,-500.,2944.,4500.);
500     b.DrawBox(2048.,-500.,2176.,4500.);
501 pam-fi 1.3 }
502 pam-fi 1.9 else if(nn==4){
503     b.SetFillColor(107);
504     b.SetFillStyle(3954);
505     b.DrawBox(384.,-500.,512.,4500.);
506     }
507 pam-fi 1.3 else if(nn==6){
508 pam-fi 1.8 b.SetFillColor(6);
509     b.SetFillStyle(3945);
510 pam-fi 1.3 b.DrawBox(2560.,-500.,2816.,4500.);
511 pam-fi 1.8 b.DrawBox(1024.,-500.,1792.,4500.);
512    
513     b.SetFillColor(107);
514     b.SetFillStyle(3954);
515     b.DrawBox(512.,-500.,768.,4500.);
516     }
517     else if(nn==7){
518     b.SetFillColor(107);
519     b.SetFillStyle(3954);
520 pam-fi 1.3 b.DrawBox(512.,-500.,768.,4500.);
521     }
522     else if(nn==11){
523 pam-fi 1.8 b.SetFillColor(6);
524     b.SetFillStyle(3945);
525 pam-fi 1.3 b.DrawBox(768.,-500.,1024.,4500.);
526 pam-fi 1.8
527     b.SetFillColor(107);
528     b.SetFillStyle(3954);
529     b.DrawBox(0.,-500.,512.,4500);
530     b.DrawBox(1920.,-500.,2048.,4500);
531 pam-fi 1.3 }
532     c1[e]->Update();
533 pam-fi 1.1
534 pam-fi 1.3 }//end loop on views
535 pam-fi 1.1
536 pam-fi 1.3 c1[e]->Print(figsav.str().c_str());
537     }
538 pam-fi 1.1 return;
539     }

  ViewVC Help
Powered by ViewVC 1.1.23