1 |
/** |
2 |
* FTrkQLook_BASIC.cpp |
3 |
* |
4 |
* autor: D.Fedele |
5 |
* version 2.0 |
6 |
* Parameters: |
7 |
* file - the data file to analyze |
8 |
* fromevent - first event to analyze |
9 |
* toevent - last event to analyze |
10 |
* outdir - total path of output file |
11 |
* outfile - extension of output file (pdf,ps,gif,jpg) |
12 |
* |
13 |
*/ |
14 |
// |
15 |
#include <TPaveText.h> |
16 |
#include <TLatex.h> |
17 |
#include <TCanvas.h> |
18 |
#include <TGraph.h> |
19 |
#include <TStyle.h> |
20 |
#include <TTree.h> |
21 |
// |
22 |
#include <physics/tracker/TrackerEvent.h> |
23 |
#include <PscuHeader.h> |
24 |
#include <EventHeader.h> |
25 |
#include <RunHeaderEvent.h> |
26 |
// |
27 |
|
28 |
void stringcopy(TString& s1, const TString& s2, Int_t from=0, Int_t to=0){ |
29 |
if ( to == 0 ){ |
30 |
Int_t t2length = s2.Length(); |
31 |
s1 = ""; |
32 |
to = t2length; |
33 |
}; |
34 |
for (Int_t i = from; i<to; i++){ |
35 |
s1.Append(s2[i],1); |
36 |
}; |
37 |
}; |
38 |
|
39 |
|
40 |
void FTrkQLook_BASIC(TString file,Int_t fromevent,Int_t toevent, TString outdir,TString outfile) |
41 |
{ |
42 |
// |
43 |
// obtain information about the data file and select the output dir |
44 |
const string filepath=file.Data(); |
45 |
Int_t dwpos = filepath.rfind("DW_"); |
46 |
Int_t dwpos1 = filepath.find(".root"); |
47 |
TString fpath=(filepath.c_str()); |
48 |
TString base,ffile ; |
49 |
stringcopy(ffile,fpath,dwpos,dwpos1); |
50 |
stringcopy(base,fpath,0,dwpos); |
51 |
|
52 |
TString out; |
53 |
if(outdir.Length()==0){ |
54 |
out = base; |
55 |
}else{ |
56 |
out = outdir; |
57 |
} |
58 |
|
59 |
// |
60 |
// inizialise the variables and open the file |
61 |
pamela::tracker::TrackerEvent *te=0; |
62 |
pamela::EventHeader *eh=0,*eH=0; |
63 |
pamela::RunHeaderEvent *reh=0; |
64 |
pamela::PscuHeader *ph=0,*pH=0; |
65 |
|
66 |
TFile *datafile = new TFile(file); |
67 |
TTree *otr = (TTree*)datafile->Get("RunHeader"); |
68 |
otr->SetBranchAddress("Header",&eH); |
69 |
otr->SetBranchAddress("RunHeader",&reh); |
70 |
TTree *tr = (TTree*)datafile->Get("Physics"); |
71 |
tr->SetBranchAddress("Tracker",&te); |
72 |
tr->SetBranchAddress("Header",&eh); |
73 |
|
74 |
|
75 |
Long64_t nevent = tr->GetEntries(); |
76 |
Long64_t neventH = otr->GetEntries(); |
77 |
Int_t minevent=0; |
78 |
Int_t maxevent=0; |
79 |
|
80 |
printf("Number of total events: %lld\nNumber of total header events: %lld\n",nevent,neventH); |
81 |
|
82 |
if (nevent<=0){ |
83 |
datafile->Close(); |
84 |
return; |
85 |
} |
86 |
if ( fromevent > toevent && toevent>0 ){ |
87 |
printf("It must be fromevent < toevent \n"); |
88 |
return; |
89 |
} |
90 |
if ( fromevent > nevent || fromevent < 0 ) { |
91 |
printf("You can choose fromevent between 0 (all) and %lld \n",nevent); |
92 |
return; |
93 |
} |
94 |
if ( toevent > nevent || toevent < 0 ) { |
95 |
printf("You can choose toevent between 0 (all) and %lld \n",nevent); |
96 |
return; |
97 |
} |
98 |
if ( fromevent == 0 ) { |
99 |
minevent = 0; |
100 |
maxevent = nevent; |
101 |
} else { |
102 |
minevent = fromevent; |
103 |
if ( toevent > 0 ){ |
104 |
maxevent = toevent+1; |
105 |
} else if (toevent > nevent) { |
106 |
maxevent = nevent; |
107 |
} else { |
108 |
maxevent = toevent+1; |
109 |
} |
110 |
nevent=maxevent-minevent ; |
111 |
} |
112 |
|
113 |
// |
114 |
// other variables definitions |
115 |
stringstream oss,fromfile,isfile; |
116 |
const Int_t size=nevent; |
117 |
Int_t dsp=0,count=0,trk_cal_us[50]; |
118 |
Double_t perc; |
119 |
Double_t yd[size*12], x[size+1]; |
120 |
Double_t yyd[size+1],yyb[size], xb[size]; |
121 |
ULong64_t HOBT[50]; |
122 |
TGraph *dataletime,*dataletime1; |
123 |
|
124 |
for (Int_t i=0; i<50;i++){ |
125 |
HOBT[i]=0; |
126 |
trk_cal_us[i]=0; |
127 |
} |
128 |
|
129 |
//*************************************************************************************** |
130 |
// LOOP on each event |
131 |
//*************************************************************************************** |
132 |
|
133 |
// |
134 |
// information about trk_calib_used |
135 |
for (Int_t ev=0; ev<neventH; ev++){ |
136 |
otr->GetEntry(ev); |
137 |
pH = eH->GetPscuHeader(); |
138 |
HOBT[ev]= pH->GetOrbitalTime(); |
139 |
trk_cal_us[ev]=reh->TRK_CALIB_USED; |
140 |
} |
141 |
|
142 |
|
143 |
// |
144 |
// information about datalength |
145 |
x[0]=(Double_t)HOBT[0]; |
146 |
for (Int_t ev=minevent; ev<maxevent; ev++){ |
147 |
tr->GetEntry(ev); |
148 |
ph = eh->GetPscuHeader(); |
149 |
|
150 |
x[(ev-minevent)+1]= ph->GetOrbitalTime(); |
151 |
dsp=0; |
152 |
for(Int_t i=0; i<12; i++){ |
153 |
dsp=te->DSPnumber[i]-1; |
154 |
yd[(ev-minevent)*12+dsp]= te->DATAlength[i]; |
155 |
} |
156 |
}; |
157 |
datafile->Close(); |
158 |
|
159 |
|
160 |
//**************************************************************************************** |
161 |
//Output figure |
162 |
//**************************************************************************************** |
163 |
|
164 |
TCanvas *DataTimeCanv=new TCanvas("Tracker_Detector_Report_","",900,1200); |
165 |
DataTimeCanv->SetFillColor(10); |
166 |
DataTimeCanv->Range(0,0,100,100); |
167 |
fromfile<<"FTrkQLook_BASIC File: "<<ffile; |
168 |
isfile<<"DATALENGTH vs. ORBITALTIME "; |
169 |
|
170 |
TLatex *t=new TLatex(); |
171 |
t->SetTextFont(32); |
172 |
t->SetTextColor(1); |
173 |
t->SetTextAlign(12); |
174 |
t->SetTextSize(0.02); |
175 |
t->DrawLatex(2.,98.7,fromfile.str().c_str()); |
176 |
TLatex *t1=new TLatex(); |
177 |
t1->SetTextFont(32); |
178 |
t1->SetTextColor(1); |
179 |
t1->SetTextAlign(12); |
180 |
t1->SetTextSize(0.02); |
181 |
t1->DrawLatex(70.,98.7,isfile.str().c_str()); |
182 |
fromfile.str(""); |
183 |
isfile.str(""); |
184 |
|
185 |
|
186 |
//************************************************************************************* |
187 |
//book pads and histos |
188 |
//*************************************************************************************** |
189 |
gStyle->SetLabelSize(0.06,"x"); |
190 |
gStyle->SetLabelSize(0.06,"y"); |
191 |
gStyle->SetStatFontSize(0.075); |
192 |
gStyle->SetOptStat(1110); |
193 |
gStyle->SetFillColor(10); |
194 |
gStyle->SetTitleFontSize(0.1); |
195 |
gStyle->SetTitleOffset(0.8,"y"); |
196 |
gStyle->SetTitleOffset(0.9,"x"); |
197 |
gStyle->SetTitleSize(0.06,"y"); |
198 |
gStyle->SetTitleSize(0.055,"x"); |
199 |
|
200 |
TPad *pad[12]; //pad for histos |
201 |
Double_t posy = 0.95; // up y-coord - top pads |
202 |
Double_t hpad = 0; // pad height |
203 |
Double_t posx1=0; // left x-coord - pad column |
204 |
Double_t posx0=0; // x-coord - column division |
205 |
Double_t wrel = 0; // relative x size of first sub-column |
206 |
Double_t marg = 0.004; // margin among pads |
207 |
|
208 |
hpad = (posy-marg*11)/6; |
209 |
wrel = (1-marg*4)/2; |
210 |
stringstream title; |
211 |
stringstream hid; |
212 |
|
213 |
for(Int_t n = 0; n<12; n++) { |
214 |
if ( (n+1)%2==1 ) { |
215 |
if(n>1) posy = posy-(marg*2+hpad); |
216 |
posx1 = marg; |
217 |
posx0 = posx1 + wrel; |
218 |
} |
219 |
else { |
220 |
posx1 = posx0 + 2*marg; |
221 |
posx0 = posx1 + wrel; |
222 |
} |
223 |
|
224 |
/* -----------> pad for histograms */ |
225 |
pad[n] = new TPad("pad"," ",posx1,posy-hpad,posx0,posy,18,0,0); |
226 |
}; |
227 |
|
228 |
TLine li; |
229 |
li.SetLineColor(1); |
230 |
li.SetLineStyle(1); |
231 |
li.SetLineWidth(1); |
232 |
//********************************************************************************** |
233 |
// Fill Graphs and Histos |
234 |
//********************************************************************************** |
235 |
stringstream calus; |
236 |
TLatex *t2=new TLatex(); |
237 |
t2->SetTextFont(32); |
238 |
t2->SetTextColor(1); |
239 |
t2->SetTextAlign(13); |
240 |
t2->SetTextSize(0.08); |
241 |
|
242 |
for (Int_t i=0; i<12 ; i++){ |
243 |
perc=0; |
244 |
count=0; |
245 |
yyd[0]=-10000.; |
246 |
for (Int_t ev=minevent; ev<maxevent; ev++){ |
247 |
yyd[(ev-minevent)+1]=yd[12*(ev-minevent)+i]; |
248 |
if(i==6){ |
249 |
if(yyd[(ev-minevent)+1]>1500){ |
250 |
if(yyd[(ev-minevent)+1]<3075){ |
251 |
yyb[count]= yyd[(ev-minevent)+1]; |
252 |
xb[count]= x[(ev-minevent)+1]; |
253 |
count++; |
254 |
} |
255 |
} |
256 |
} |
257 |
else{ |
258 |
if(yyd[(ev-minevent)+1]>750){ |
259 |
if(yyd[(ev-minevent)+1]<3075){ |
260 |
yyb[count]= yyd[(ev-minevent)+1]; |
261 |
xb[count]= x[(ev-minevent)+1]; |
262 |
count++; |
263 |
} |
264 |
} |
265 |
} |
266 |
} |
267 |
|
268 |
if((maxevent-minevent)>100) perc=(count*100)/(maxevent-minevent); |
269 |
else perc=(count*10)/(maxevent-minevent); |
270 |
|
271 |
Double_t min,max; |
272 |
if((maxevent-minevent)<100){ |
273 |
min=x[0]; |
274 |
max=x[size]*1.0001; |
275 |
} |
276 |
else{ |
277 |
min=x[0]; |
278 |
max=x[size-1]*1.0005; |
279 |
} |
280 |
oss<<"DSP "<<i+1; |
281 |
DataTimeCanv->cd(); |
282 |
if(perc>1) pad[i]->SetFillColor(2); |
283 |
else pad[i]->SetFillColor(10); |
284 |
pad[i]->SetFrameFillColor(10); |
285 |
pad[i]->Draw(); |
286 |
pad[i]->cd(); |
287 |
dataletime= new TGraph((maxevent-minevent)+1,x,yyd); |
288 |
dataletime->SetTitle(oss.str().c_str()); |
289 |
dataletime->GetXaxis()->SetTitle("OBT (ms)"); |
290 |
dataletime->GetXaxis()->CenterTitle(); |
291 |
dataletime->GetXaxis()->SetRangeUser(min,max); |
292 |
dataletime->GetYaxis()->SetTitle("datalength (Word 13 bit)"); |
293 |
dataletime->GetYaxis()->CenterTitle(); |
294 |
dataletime->GetYaxis()->SetRangeUser(0,3500); |
295 |
dataletime->SetMarkerStyle(21); |
296 |
if((maxevent-minevent)<50) dataletime->SetMarkerSize(0.5); |
297 |
else dataletime->SetMarkerSize(0.3); |
298 |
dataletime->SetMarkerColor(1); |
299 |
dataletime->Draw("ap"); |
300 |
if(perc>1){ |
301 |
dataletime1= new TGraph(count,xb,yyb); |
302 |
dataletime1->SetMarkerStyle(21); |
303 |
if((maxevent-minevent)<50) dataletime1->SetMarkerSize(0.5); |
304 |
else dataletime1->SetMarkerSize(0.3); |
305 |
dataletime1->SetMarkerColor(2); |
306 |
dataletime1->Draw("psame"); |
307 |
} |
308 |
li.SetLineColor(1); |
309 |
li.SetLineStyle(1); |
310 |
li.SetLineWidth(1); |
311 |
if(i!=6) li.DrawLine(min,750,max,750); |
312 |
else li.DrawLine(min,1500,max,1500); |
313 |
li.DrawLine(min,3075,max,3075); |
314 |
for(Int_t j=0;j<neventH;j++){ |
315 |
li.SetLineColor(12); |
316 |
li.SetLineStyle(4); |
317 |
li.SetLineWidth(1); |
318 |
li.DrawLine(HOBT[j],0.,HOBT[j],3500.); |
319 |
if(trk_cal_us[j]==104){ |
320 |
calus<<"D"; |
321 |
t2->SetTextColor(6); |
322 |
t2->DrawLatex(HOBT[j],3350.,calus.str().c_str()); |
323 |
calus.str(""); |
324 |
} |
325 |
else{ |
326 |
calus<<trk_cal_us[j]; |
327 |
t2->SetTextColor(3); |
328 |
t2->DrawLatex(HOBT[j],3350.,calus.str().c_str()); |
329 |
calus.str(""); |
330 |
} |
331 |
} |
332 |
oss.str(""); |
333 |
}; |
334 |
|
335 |
DataTimeCanv->Update(); |
336 |
|
337 |
printf("... end of packets. \n"); |
338 |
//************************************************************************* |
339 |
// Save output Files |
340 |
//************************************************************************* |
341 |
stringstream out1; |
342 |
|
343 |
out1<<ffile<<"_FTrkQLook_BASIC."<<outfile.Data(); |
344 |
DataTimeCanv->Print(out+out1.str().c_str()); |
345 |
out1.str(""); |
346 |
|
347 |
gROOT->Reset(); |
348 |
return; |
349 |
} |