/[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.3 - (hide annotations) (download)
Mon Jun 5 08:37:53 2006 UTC (18 years, 6 months ago) by pam-fi
Branch: MAIN
Changes since 1.2: +324 -284 lines
*** empty log message ***

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

  ViewVC Help
Powered by ViewVC 1.1.23