/[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.16 - (show annotations) (download)
Mon Nov 20 11:33:24 2006 UTC (18 years ago) by pam-fi
Branch: MAIN
CVS Tags: v1r18
Changes since 1.15: +6 -1 lines
*** empty log message ***

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

  ViewVC Help
Powered by ViewVC 1.1.23