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