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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.18 - (show annotations) (download)
Wed Dec 6 10:06:27 2006 UTC (18 years ago) by pam-fi
Branch: MAIN
CVS Tags: v1r20
Changes since 1.17: +22 -9 lines
*** empty log message ***

1 /**
2 * FTrkScanQlook_EXPERT.cxx
3 *
4 * autor: D.Fedele
5 * version v1r18
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 <TFile.h>
23 #include <TTree.h>
24 #include <TStyle.h>
25 #include <TString.h>
26 //
27 #include <physics/tracker/TrackerEvent.h>
28 #include <PscuHeader.h>
29 #include <EventHeader.h>
30 #include <RunHeaderEvent.h>
31 //
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 Int_t dwpos = file.Last('/');
127 Int_t dwpos1 = file.Last('.');
128 TString base,ffile ;
129 ffile=file(dwpos+1,dwpos1-(dwpos+1));
130 if(dwpos>0) base=file(0,dwpos);
131
132 TString out;
133 if(outdir.Length()==0){
134 out = base;
135 }else{
136 out = outdir;
137 }
138 if(out.Last('/')+1<out.Length()) out+="/";
139
140 pamela::tracker::TrackerEvent *trk=0;
141 pamela::EventHeader *eh=0,*eH=0;
142 pamela::PscuHeader *ph=0,*pH=0;
143 pamela::RunHeaderEvent *reh=0;
144 pamela::EventCounter *cod=0;
145
146 pamela::PacketType *pctp=0;
147 // open files
148 TFile *trackerFile = new TFile(file);
149 if ( !trackerFile ){
150 trackerFile->Close();
151 printf("No tracker file! \n");
152 return;
153 }
154
155 //Takes the tree and branches
156 TTree *tr = (TTree*)trackerFile->Get("Physics");
157 tr->SetBranchAddress("Tracker",&trk);
158 tr->SetBranchAddress("Header",&eh);
159
160 TTree *otr = (TTree*)trackerFile->Get("RunHeader");
161 otr->SetBranchAddress("Header",&eH);
162 otr->SetBranchAddress("RunHeader",&reh);
163
164 // Define variables
165 Int_t nevents = tr->GetEntries();
166 Int_t neventH = otr->GetEntries();
167 if ( nevents <= 0 ) {
168 trackerFile->Close();
169 printf("The file is empty, exiting...\n");
170 return;
171 }
172
173
174 printf("\n Number of Entries: %d\n",nevents);
175 printf(" Number of Header Entries: %d\n",neventH);
176
177 Long64_t obt=0;
178 Int_t ev[2],cin=0;
179 TString cal="";
180
181 ev[0]=3;
182 ev[1]=4;
183 for(Int_t i=0;i<neventH;i++){
184 otr->GetEntry(i);
185 pH = eH->GetPscuHeader();
186 if(reh->TRK_CALIB_USED!=104){
187 obt = pH->GetOrbitalTime();
188 cal="Event with online calibration";
189 break;
190 }
191 if(i==neventH-1){
192 cal="***** ONLINE CALIBRATION NOT FOUND IN THIS FILE *****";
193 ev[0]=2;
194 ev[1]=3;
195 }
196 }
197 if(ev[0]==3){
198 for(Int_t i=0;i<nevents;i++){
199 tr->GetEntry(i);
200 ph = eh->GetPscuHeader();
201 cod = eh->GetCounter();
202 if(i==0) cin=cod->Get(pctp->CalibTrk1);
203 if(reh->TRK_CALIB_USED==104) continue;
204 if(event<0 && cod->Get(pctp->CalibTrk1)==cin+1){
205 ev[0]=i+3;
206 ev[1]=i+4;
207 break;
208 }
209 else if(event>=0 && ph->GetOrbitalTime()>obt){
210 ev[0]=i+3;
211 ev[1]=i+4;
212 break;
213 }
214 }
215 }
216
217
218 TH1F *histomax[12][2]; //histos of max signals
219 TH1F *histocomp[12][2]; //histos of compressed data
220 TH1F *histofull[12][2]; //histos of full data
221 TCanvas *c1[2];
222
223 for(Int_t e=0;e<2;e++){
224 if(event<=0)
225 event=ev[e];
226 else {
227 event=event+e;
228 if(event>ev[e]-3 && ev[0]>2)
229 cal="Event with online calibration";
230 else
231 cal="***** ONLINE CALIBRATION NOT FOUND IN THIS FILE *****";
232 }
233 printf("Scan of Entry %d\n",event);
234
235 tr->GetEntry(event);
236 //============================================================================
237
238 gStyle->SetLabelSize(0.06,"x");
239 gStyle->SetLabelSize(0.06,"y");
240 gStyle->SetTitleFontSize(0.1);
241 gStyle->SetFillColor(10);
242 gStyle->SetTitleFillColor(10);
243 gStyle->SetTitleOffset(-1,"Y");
244 gStyle->SetOptStat(0);
245
246 // draw display area
247
248 Int_t canvasx=1200;
249 Int_t canvasy=900;
250 stringstream figsav;
251 figsav.str("");
252 figsav<<out<<ffile<<"_FTrkScanQLook_EXPERT_ev"<<event+1<<"."<<outfile.Data();
253 c1[e] = new TCanvas(figsav.str().c_str(),"FTrkQLookSCAN",canvasx,canvasy);
254 c1[e]->SetFillColor(10);
255 c1[e]->Range(0,0,1,1);
256 stringstream fromfile;
257 fromfile<<"FTrkScanQLook_EXPERT File: "<<ffile<<" ----> Entry "<<event;
258 TLatex *t=new TLatex();
259 t->SetTextFont(32);
260 t->SetTextColor(1);
261 t->SetTextAlign(12);
262 t->SetTextSize(0.02);
263 t->DrawLatex(0.02,0.98,fromfile.str().c_str());
264 t->DrawLatex(0.60,0.98,cal.Data());
265
266 // draw pads
267 TPad *trkpad[12]; //pad for histos
268 TPaveText *trkpadtext[12]; //pad for header
269 Double_t posy = 0.95; // up y-coord - top pads
270 Double_t hpad = 0.15; // pad height
271 Double_t posx1=0; // left x-coord - pad column
272 Double_t posx2=0; // right x-coord - pad olumn
273 Double_t posx0=0; // x-coord - column division
274 Double_t wrel = 0.6; // relative x size of first sub-column
275 Double_t marg = 0.004; // margin among pads
276
277
278 stringstream title;
279 stringstream hid;
280 for(Int_t n = 0; n<12; n++){
281 if ( (n+1)%2 ) {
282 if(n>1)posy = posy-(marg*2+hpad);
283 posx1 = marg;
284 posx2 = 0.5 - marg;
285 posx0 = 0.5*wrel;
286 } else {
287 posx1 = posx1 + 0.5;
288 posx2 = posx2 + 0.5;
289 posx0 = posx0 + 0.5;
290 };
291
292 /* -----------> pad for histograms */
293 trkpad[n] = new TPad("pad"," ",posx1,posy-hpad,posx0-marg,posy,18,0,0);
294 trkpad[n]->SetFillColor(19);
295 trkpad[n]->SetFrameFillColor(10);
296 /* -----------> pad for header dump */
297 trkpadtext[n] = new TPaveText((posx0+marg),(posy-hpad),posx2,posy);
298 /* -----------> HISTOGRAMS */
299
300 title<<"DSP "<<n+1;
301 hid<<"h"<<n+e*100;
302 histomax[n][e] = new TH1F(hid.str().c_str(),title.str().c_str(),3073,-0.5,3072.5);
303 hid<<"hh"<<n+e*100;
304 histocomp[n][e] = new TH1F(hid.str().c_str(),title.str().c_str(),3073,-0.5,3072.5);
305 hid<<"hhh"<<n+e*100;
306 histofull[n][e] = new TH1F(hid.str().c_str(),title.str().c_str(),3073,-0.5,3072.5);
307 title.str("");
308 hid.str("");
309 } //end loop on views
310
311 // = = = = = = = = = = = = = = = = = = = = = = = = =
312 // create header dump retrieving event info
313 // = = = = = = = = = = = = = = = = = = = = = = = = =
314 Int_t ndsp=0;
315 stringstream message;
316
317 Double_t whistomax[3072];
318 Double_t whisto[3072];
319 Double_t whistocomp[3072];
320 Double_t whistofull[3072];
321
322 //=============================================
323 // transmitted words
324 Int_t word = 0;
325 Int_t iword = 0;
326 Int_t TOTDATAlength_check = 0;
327 Int_t ii=0,ifull[12],icomp[12],imax[12],nn=0;
328 trkword thisword;
329
330 Int_t address,ladder;
331
332 for(Int_t n = 0; n<12; n++){
333
334 ndsp = trk->DSPnumber[n];
335 nn = ndsp-1;
336 ifull[nn]=0;
337 icomp[nn]=0;
338 imax[nn]=0;
339 if(ndsp>0){
340 if(ndsp<13){
341
342 /*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*
343 *
344 * Write event LEVEL0 report
345 *
346 *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*/
347
348 trkpadtext[nn]->SetTextFont(40);
349 trkpadtext[nn]->SetFillColor(33);
350 trkpadtext[nn]->SetTextSize(0.012);
351 trkpadtext[nn]->SetTextAlign(13);
352
353 trkpadtext[nn]->AddText(" ");
354 message<<"DAQ mode --------> "<<trk->DAQmode[n];
355 trkpadtext[nn]->AddText(message.str().c_str());
356 message.str("");
357 message<<"Event number --------> "<<trk->eventn[n];
358 trkpadtext[nn]->AddText(message.str().c_str());
359 message.str("");
360 message<<"13-bit words --------> "<<trk->DATAlength[n];
361 trkpadtext[nn]->AddText(message.str().c_str());
362 message.str("");
363 if (!(nn%2)&&trk->signcluster[n][0]!=0) message<<"L1 add: "<<trk->addrcluster[n][0]<<" - sign: "<<1024-(trk->signcluster[n][0]);
364 else message<<"L1 add: "<<trk->addrcluster[n][0]<<" - sign: "<<(trk->signcluster[n][0]);
365 trkpadtext[nn]->AddText(message.str().c_str());
366 message.str("");
367 if (!(nn%2)&&trk->signcluster[n][1]!=0) message<<"L2 add: "<<trk->addrcluster[n][1]<<" - sign: "<<1024-(trk->signcluster[n][1]);
368 else message<<"L2 add: "<<trk->addrcluster[n][1]<<" - sign: "<<trk->signcluster[n][1];
369 trkpadtext[nn]->AddText(message.str().c_str());
370 message.str("");
371 if (!(nn%2)&&trk->signcluster[n][2]!=0) message<<"L3 add: "<<trk->addrcluster[n][2]<<" - sign: "<<1024-(trk->signcluster[n][2]);
372 else message<<"L3 add: "<<trk->addrcluster[n][2]<<" - sign: "<<trk->signcluster[n][2];
373 trkpadtext[nn]->AddText(message.str().c_str());
374 message.str("");
375 message<<"NCLUST "<<trk->nclust[n]<<" CUTC "<<trk->cutc[n]<<" CUTCL "<<trk->cutcl[n];
376 trkpadtext[nn]->AddText(message.str().c_str());
377 message.str("");
378 message<<"Comp. time "<<trk->compressiontime[n]<<" x 0.051ms = "<<0.051*trk->compressiontime[n]<<" ms";
379 trkpadtext[nn]->AddText(message.str().c_str());
380 message.str("");
381 trkpadtext[nn]->AddText(" ");
382 message<<"CRC --> "<<trk->crc[n];
383 trkpadtext[nn]->AddText(message.str().c_str());
384 message.str("");
385 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];
386 trkpadtext[nn]->AddText(message.str().c_str());
387 message.str("");
388 trkpadtext[nn]->AddText(" ");
389 trkpadtext[nn]->AddLine(0,0,0,0);
390 message<<"PNum "<<trk->pnum[n]<<" - BId "<<trk->bid[n]<<" ALARM "<<trk->alarm[n];
391 trkpadtext[nn]->AddText(message.str().c_str());
392 message.str("");
393 message<<"Cmd "<<trk->cmdnum[n]<<" --- Answer length "<<trk->aswr[n]<<" byte";
394 trkpadtext[nn]->AddText(message.str().c_str());
395 message.str("");
396 trkpadtext[nn]->AddText(" ");
397
398 TOTDATAlength_check = TOTDATAlength_check + trk->DATAlength[n];
399
400 /*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*
401 *
402 * Plot event LEVEL0 histo
403 *
404 *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*/
405
406 //=============================================
407
408 for(Int_t i = 0; i< 3072; i++){
409 whistomax[i] = -200;
410 whistocomp[i] = -200;
411 whistofull[i] = -200;
412 whisto[i] = -200;
413 }
414
415 // ===============
416 // trasmitted data
417 // ===============
418
419 address = 0;
420 ladder = 1;
421 for(Int_t i = 0; i < trk->DATAlength[n] ; i++){
422 word = trk->TrackerData.At(iword);
423 thisword = datadecode(word);
424 iword++;
425 switch (thisword.type){
426
427 case 0: //ADC value
428 whisto[address] = thisword.decode;
429 address++;
430 // cout << " adr " << address << "\n";
431 break;
432
433 case 1: //address
434 address = 1024*(ladder-1) + thisword.decode;
435 // cout << " adr " << address << "\n";
436 break;
437
438 case 2: //end-of-ladder
439 ladder = thisword.decode;
440 // cout << "Ladder " << ladder << "\n";
441 if(ladder==3){
442 // end of compressed data - FILL HISTO
443 //cout << ">>> COMPRESSED data" << "\n";
444 for(ii = 0; ii < 3072; ii++){
445 whistocomp[ii]=whisto[ii];
446 whisto[ii] = -200;
447 }
448 address = 0;
449 ladder = 1;
450 }else if(ladder==6){
451 // end of full data - FILL HISTO
452 //cout << ">>> FULL data" << "\n";
453 for(ii = 0; ii < 3072; ii++){
454 whistofull[ii]=whisto[ii];
455 whisto[ii] = -200;
456 }
457 address = 0;
458 ladder = 1;
459 }else{
460 if(ladder>3) ladder=ladder-3;
461 address= ladder*1024;
462 ladder = ladder + 1;
463 }
464 }
465 }
466
467
468 // ===============
469 // maximum signals
470 // ===============
471 if(trk->signcluster[nn][0]!=0) whistomax[ 0+(int)trk->addrcluster[nn][0]] = whistocomp[ 0+(int)trk->addrcluster[nn][0]];
472 if(trk->signcluster[nn][1]!=0) whistomax[1024+(int)trk->addrcluster[nn][1]] = whistocomp[1024+(int)trk->addrcluster[nn][1]];
473 if(trk->signcluster[nn][2]!=0) whistomax[2048+(int)trk->addrcluster[nn][2]] = whistocomp[2048+(int)trk->addrcluster[nn][2]];
474
475 for(Int_t i = 0; i < 3072; i++){
476 if(whistomax[i]>-200) imax[nn]=1;
477 if(whistocomp[i]>-200) icomp[nn]=1;
478 if(whistofull[i]>-200) ifull[nn]=1;
479 histomax[nn][e]->Fill((Float_t)i,whistomax[i]);
480 histocomp[nn][e]->Fill((Float_t)i,whistocomp[i]);
481 histofull[nn][e]->Fill((Float_t)i,whistofull[i]);
482 }
483
484 TBox b;
485
486 c1[e]->cd();
487 trkpadtext[nn]->Draw();
488 trkpad[nn]->Draw();
489 trkpad[nn]->cd();
490 trkpad[nn]->SetFillColor(10);
491
492 histocomp[nn][e]->GetYaxis()->SetRangeUser(-500,4500);
493 histocomp[nn][e]->SetLineStyle(1);
494 histocomp[nn][e]->SetLineColor(38);
495 histocomp[nn][e]->SetFillColor(38);
496 histocomp[nn][e]->SetLineWidth(1);
497 histocomp[nn][e]->Draw("");
498
499 histofull[nn][e]->SetLineColor(40);
500 histofull[nn][e]->SetFillColor(40);
501 histofull[nn][e]->SetLineWidth(1);
502 histofull[nn][e]->SetLineStyle(2);
503
504 histomax[nn][e]->SetLineColor(2);
505 histomax[nn][e]->SetLineWidth(1);
506 histomax[nn][e]->SetLineStyle(3);
507
508 if(ifull[nn]==1) histofull[nn][e]->Draw("9bsame][");
509 if(icomp[nn]==1) histocomp[nn][e]->Draw("9bsame][");
510 if(imax[nn]==1) histomax[nn][e]->Draw("same][");
511 histocomp[nn][e]->Draw("axis same");
512 if(nn==0){
513 b.SetFillColor(107);
514 b.SetFillStyle(3945);
515 b.DrawBox(768.,-500.,2047.,4500.);
516 }
517 else if(nn==1){
518 b.SetFillColor(6);
519 b.SetFillStyle(3945);
520 b.DrawBox(2944.,-500.,3060.,4500.);
521
522 b.SetFillColor(107);
523 b.SetFillStyle(3954);
524 //b.DrawBox(384.,-500.,512.,4500.);
525 b.DrawBox(2816.,-500.,2944.,4500.);
526 b.DrawBox(2048.,-500.,2176.,4500.);
527 }
528 else if(nn==4){
529 b.SetFillColor(107);
530 b.SetFillStyle(3954);
531 b.DrawBox(384.,-500.,512.,4500.);
532 }
533 else if(nn==6){
534 b.SetFillColor(6);
535 b.SetFillStyle(3945);
536 b.DrawBox(2560.,-500.,2816.,4500.);
537 b.DrawBox(1024.,-500.,1535.,4500.);
538
539 b.SetFillColor(107);
540 b.SetFillStyle(3954);
541 b.DrawBox(512.,-500.,768.,4500.);
542 b.DrawBox(1536.,-500.,1792.,4500.);
543 }
544 else if(nn==7){
545 b.SetFillColor(107);
546 b.SetFillStyle(3954);
547 b.DrawBox(512.,-500.,768.,4500.);
548 }
549 else if(nn==8){
550 b.SetFillColor(107);
551 b.SetFillStyle(3954);
552 b.DrawBox(512.,-500.,768.,4500.);
553 }
554 else if(nn==9){
555 b.SetFillColor(107);
556 b.SetFillStyle(3954);
557 b.DrawBox(256.,-500.,384.,4500.);
558 //b.DrawBox(1280.,-500.,1408.,4500.);
559 //b.DrawBox(1792.,-500.,1920.,4500.);
560 }
561 else if(nn==10){
562 b.SetFillColor(107);
563 b.SetFillStyle(3954);
564 b.DrawBox(2048.,-500.,3070.,4500.);
565 }
566 else if(nn==11){
567 b.SetFillColor(6);
568 b.SetFillStyle(3945);
569 b.DrawBox(768.,-500.,1024.,4500.);
570
571 b.SetFillColor(107);
572 b.SetFillStyle(3954);
573 b.DrawBox(0.,-500.,512.,4500.);
574 b.DrawBox(1920.,-500.,2560.,4500.);
575 }
576 c1[e]->Update();
577 }
578 }
579
580 }//end loop on views
581
582 c1[e]->Print(figsav.str().c_str());
583 }
584 return;
585 }

  ViewVC Help
Powered by ViewVC 1.1.23