/[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.14 - (hide annotations) (download)
Thu Oct 12 16:58:34 2006 UTC (18 years, 1 month ago) by pam-fi
Branch: MAIN
CVS Tags: v1r16, v1r15
Changes since 1.13: +2 -3 lines
*** empty log message ***

1 pam-fi 1.1 /**
2     * FTrkScanQlook_EXPERT.cxx
3     *
4     * autor: D.Fedele
5 pam-fi 1.14 * version v1r13
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.12 if(ndsp>0){
322     if(ndsp<13){
323 pam-fi 1.1
324 pam-fi 1.12 /*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*
325     *
326     * Write event LEVEL0 report
327     *
328     *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*/
329    
330     trkpadtext[nn]->SetTextFont(40);
331     trkpadtext[nn]->SetFillColor(33);
332     trkpadtext[nn]->SetTextSize(0.012);
333     trkpadtext[nn]->SetTextAlign(13);
334    
335     trkpadtext[nn]->AddText(" ");
336     message<<"DAQ mode --------> "<<trk->DAQmode[n];
337     trkpadtext[nn]->AddText(message.str().c_str());
338     message.str("");
339     message<<"Event number --------> "<<trk->eventn[n];
340     trkpadtext[nn]->AddText(message.str().c_str());
341     message.str("");
342     message<<"13-bit words --------> "<<trk->DATAlength[n];
343     trkpadtext[nn]->AddText(message.str().c_str());
344     message.str("");
345     if (!(nn%2)&&trk->signcluster[n][0]!=0) message<<"L1 add: "<<trk->addrcluster[n][0]<<" - sign: "<<1024-(trk->signcluster[n][0]);
346     else message<<"L1 add: "<<trk->addrcluster[n][0]<<" - sign: "<<(trk->signcluster[n][0]);
347     trkpadtext[nn]->AddText(message.str().c_str());
348     message.str("");
349     if (!(nn%2)&&trk->signcluster[n][1]!=0) message<<"L2 add: "<<trk->addrcluster[n][1]<<" - sign: "<<1024-(trk->signcluster[n][1]);
350     else message<<"L2 add: "<<trk->addrcluster[n][1]<<" - sign: "<<trk->signcluster[n][1];
351     trkpadtext[nn]->AddText(message.str().c_str());
352     message.str("");
353     if (!(nn%2)&&trk->signcluster[n][2]!=0) message<<"L3 add: "<<trk->addrcluster[n][2]<<" - sign: "<<1024-(trk->signcluster[n][2]);
354     else message<<"L3 add: "<<trk->addrcluster[n][2]<<" - sign: "<<trk->signcluster[n][2];
355     trkpadtext[nn]->AddText(message.str().c_str());
356     message.str("");
357     message<<"NCLUST "<<trk->nclust[n]<<" CUTC "<<trk->cutc[n]<<" CUTCL "<<trk->cutcl[n];
358     trkpadtext[nn]->AddText(message.str().c_str());
359     message.str("");
360     message<<"Comp. time "<<trk->compressiontime[n]<<" x 0.051ms = "<<0.051*trk->compressiontime[n]<<" ms";
361     trkpadtext[nn]->AddText(message.str().c_str());
362     message.str("");
363     trkpadtext[nn]->AddText(" ");
364     message<<"CRC --> "<<trk->crc[n];
365     trkpadtext[nn]->AddText(message.str().c_str());
366     message.str("");
367     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];
368     trkpadtext[nn]->AddText(message.str().c_str());
369     message.str("");
370     trkpadtext[nn]->AddText(" ");
371     trkpadtext[nn]->AddLine(0,0,0,0);
372     message<<"PNum "<<trk->pnum[n]<<" - BId "<<trk->bid[n]<<" ALARM "<<trk->alarm[n];
373     trkpadtext[nn]->AddText(message.str().c_str());
374     message.str("");
375     message<<"Cmd "<<trk->cmdnum[n]<<" --- Answer length "<<trk->aswr[n]<<" byte";
376     trkpadtext[nn]->AddText(message.str().c_str());
377     message.str("");
378     trkpadtext[nn]->AddText(" ");
379 pam-fi 1.1
380 pam-fi 1.12 TOTDATAlength_check = TOTDATAlength_check + trk->DATAlength[n];
381 pam-fi 1.1
382 pam-fi 1.12 /*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*
383     *
384     * Plot event LEVEL0 histo
385     *
386     *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*/
387    
388     //=============================================
389    
390     for(Int_t i = 0; i< 3072; i++){
391     whistomax[i] = -200;
392     whistocomp[i] = -200;
393     whistofull[i] = -200;
394     whisto[i] = -200;
395     }
396 pam-fi 1.1
397 pam-fi 1.12 // ===============
398     // trasmitted data
399     // ===============
400    
401     address = 0;
402     ladder = 1;
403     for(Int_t i = 0; i < trk->DATAlength[n] ; i++){
404     word = trk->TrackerData.At(iword);
405     thisword = datadecode(word);
406     iword++;
407     switch (thisword.type){
408 pam-fi 1.1
409 pam-fi 1.12 case 0: //ADC value
410     whisto[address] = thisword.decode;
411     address++;
412     // cout << " adr " << address << "\n";
413     break;
414    
415     case 1: //address
416     address = 1024*(ladder-1) + thisword.decode;
417     // cout << " adr " << address << "\n";
418     break;
419    
420     case 2: //end-of-ladder
421     ladder = thisword.decode;
422     // cout << "Ladder " << ladder << "\n";
423     if(ladder==3){
424     // end of compressed data - FILL HISTO
425     //cout << ">>> COMPRESSED data" << "\n";
426     for(ii = 0; ii < 3072; ii++){
427     whistocomp[ii]=whisto[ii];
428     whisto[ii] = -200;
429     }
430     address = 0;
431     ladder = 1;
432     }else if(ladder==6){
433     // end of full data - FILL HISTO
434     //cout << ">>> FULL data" << "\n";
435     for(ii = 0; ii < 3072; ii++){
436     whistofull[ii]=whisto[ii];
437     whisto[ii] = -200;
438     }
439     address = 0;
440     ladder = 1;
441     }else{
442     if(ladder>3) ladder=ladder-3;
443     address= ladder*1024;
444     ladder = ladder + 1;
445     }
446     }
447     }
448 pam-fi 1.1
449    
450 pam-fi 1.12 // ===============
451     // maximum signals
452     // ===============
453     if(trk->signcluster[nn][0]!=0) whistomax[ 0+(int)trk->addrcluster[nn][0]] = whistocomp[ 0+(int)trk->addrcluster[nn][0]];
454     if(trk->signcluster[nn][1]!=0) whistomax[1024+(int)trk->addrcluster[nn][1]] = whistocomp[1024+(int)trk->addrcluster[nn][1]];
455     if(trk->signcluster[nn][2]!=0) whistomax[2048+(int)trk->addrcluster[nn][2]] = whistocomp[2048+(int)trk->addrcluster[nn][2]];
456    
457     for(Int_t i = 0; i < 3072; i++){
458     if(whistomax[i]>-200) imax[nn]=1;
459     if(whistocomp[i]>-200) icomp[nn]=1;
460     if(whistofull[i]>-200) ifull[nn]=1;
461     histomax[nn][e]->Fill((Float_t)i,whistomax[i]);
462     histocomp[nn][e]->Fill((Float_t)i,whistocomp[i]);
463     histofull[nn][e]->Fill((Float_t)i,whistofull[i]);
464     }
465 pam-fi 1.2
466 pam-fi 1.12 TBox b;
467 pam-fi 1.3
468 pam-fi 1.12 c1[e]->cd();
469     trkpadtext[nn]->Draw();
470     trkpad[nn]->Draw();
471     trkpad[nn]->cd();
472     trkpad[nn]->SetFillColor(10);
473    
474     histocomp[nn][e]->GetYaxis()->SetRangeUser(-500,4500);
475     histocomp[nn][e]->SetLineStyle(1);
476     histocomp[nn][e]->SetLineColor(38);
477     histocomp[nn][e]->SetFillColor(38);
478     histocomp[nn][e]->SetLineWidth(1);
479     histocomp[nn][e]->Draw("");
480    
481     histofull[nn][e]->SetLineColor(40);
482     histofull[nn][e]->SetFillColor(40);
483     histofull[nn][e]->SetLineWidth(1);
484     histofull[nn][e]->SetLineStyle(2);
485    
486     histomax[nn][e]->SetLineColor(2);
487     histomax[nn][e]->SetLineWidth(1);
488     histomax[nn][e]->SetLineStyle(3);
489    
490     if(ifull[nn]==1) histofull[nn][e]->Draw("9bsame][");
491     if(icomp[nn]==1) histocomp[nn][e]->Draw("9bsame][");
492     if(imax[nn]==1) histomax[nn][e]->Draw("same][");
493     histocomp[nn][e]->Draw("axis same");
494     if(nn==1){
495     b.SetFillColor(6);
496     b.SetFillStyle(3945);
497     b.DrawBox(2944.,-500.,3060.,4500.);
498 pam-fi 1.8
499 pam-fi 1.12 b.SetFillColor(107);
500     b.SetFillStyle(3954);
501     b.DrawBox(2816.,-500.,2944.,4500.);
502     b.DrawBox(2048.,-500.,2176.,4500.);
503     }
504     else if(nn==4){
505     b.SetFillColor(107);
506     b.SetFillStyle(3954);
507     b.DrawBox(384.,-500.,512.,4500.);
508     }
509     else if(nn==6){
510     b.SetFillColor(6);
511     b.SetFillStyle(3945);
512     b.DrawBox(2560.,-500.,2816.,4500.);
513     b.DrawBox(1024.,-500.,1535.,4500.);
514 pam-fi 1.8
515 pam-fi 1.12 b.SetFillColor(107);
516     b.SetFillStyle(3954);
517     b.DrawBox(512.,-500.,768.,4500.);
518     b.DrawBox(1536.,-500.,1792.,4500.);
519     }
520     else if(nn==7){
521     b.SetFillColor(107);
522     b.SetFillStyle(3954);
523     b.DrawBox(512.,-500.,768.,4500.);
524     }
525 pam-fi 1.13 else if(nn==9){
526     b.SetFillColor(107);
527     b.SetFillStyle(3954);
528     b.DrawBox(256.,-500.,384.,4500);
529     }
530 pam-fi 1.12 else if(nn==11){
531     b.SetFillColor(6);
532     b.SetFillStyle(3945);
533     b.DrawBox(768.,-500.,1024.,4500.);
534 pam-fi 1.8
535 pam-fi 1.12 b.SetFillColor(107);
536     b.SetFillStyle(3954);
537     b.DrawBox(0.,-500.,512.,4500);
538 pam-fi 1.14 b.DrawBox(1920.,-500.,2560.,4500);
539 pam-fi 1.12 }
540     c1[e]->Update();
541     }
542 pam-fi 1.3 }
543 pam-fi 1.1
544 pam-fi 1.3 }//end loop on views
545 pam-fi 1.1
546 pam-fi 1.3 c1[e]->Print(figsav.str().c_str());
547     }
548 pam-fi 1.1 return;
549     }

  ViewVC Help
Powered by ViewVC 1.1.23