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