/[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.5 - (show annotations) (download)
Thu Jun 29 11:11:59 2006 UTC (18 years, 5 months ago) by pam-fi
Branch: MAIN
CVS Tags: v1r04
Changes since 1.4: +8 -19 lines
new release tagged v1r04

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

  ViewVC Help
Powered by ViewVC 1.1.23