/[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.1 - (hide annotations) (download)
Wed May 10 10:06:55 2006 UTC (18 years, 6 months ago) by pam-fi
Branch: MAIN
CVS Tags: R2v00
.cpp files of utilities removed, quicklook macros added

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

  ViewVC Help
Powered by ViewVC 1.1.23