/[PAMELA software]/quicklook/tracker/flight/macros/FTrkQLook_BASIC.cxx
ViewVC logotype

Contents of /quicklook/tracker/flight/macros/FTrkQLook_BASIC.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (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.7: +11 -23 lines
new release tagged v1r04

1 /**
2 * FTrkQLook_BASIC.cxx
3 *
4 * autor: D.Fedele
5 * version v1r04
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 <TFile.h>
21 #include <TTree.h>
22 #include <TArrow.h>
23 //
24 #include <physics/tracker/TrackerEvent.h>
25 #include <PscuHeader.h>
26 #include <EventHeader.h>
27 #include <RunHeaderEvent.h>
28 #include <EventCounter.h>
29 #include <PacketType.h>
30 //
31 #define MAXSTORAGE 50000
32
33 void FTrkQLook_BASIC(TString file,Int_t fromevent,Int_t toevent, TString outdir,TString outfile)
34 {
35 //
36 // obtain information about the data file and select the output dir
37 const string filepath=file.Data();
38 Int_t dwpos = file.Last('/');
39 Int_t dwpos1 = file.Last('.');
40 TString base,ffile ;
41 ffile=file(dwpos+1,dwpos1-(dwpos+1));
42 if(dwpos>0) base=file(0,dwpos);
43
44 TString out;
45 if(outdir.Length()==0){
46 out = base;
47 }else{
48 out = outdir;
49 }
50 if(out.Last('/')+1<out.Length()) out+="/";
51
52 //
53 // inizialise the variables and open the file
54 pamela::tracker::TrackerEvent *te=0;
55 pamela::EventHeader *eh=0,*eH=0,*ceh=0;
56 pamela::RunHeaderEvent *reh=0;
57 pamela::PscuHeader *ph=0,*pH=0;
58 pamela::EventCounter *cod=0;
59
60 pamela::PacketType *pctp=0;
61
62 TFile *datafile = new TFile(file);
63 TTree *otr = (TTree*)datafile->Get("RunHeader");
64 otr->SetBranchAddress("Header",&eH);
65 otr->SetBranchAddress("RunHeader",&reh);
66 TTree *tr = (TTree*)datafile->Get("Physics");
67 tr->SetBranchAddress("Tracker",&te);
68 tr->SetBranchAddress("Header",&eh);
69 TTree *ctr = (TTree*)datafile->Get("CalibTrk1");
70 ctr->SetBranchAddress("Header",&ceh);
71
72 Long64_t neventC = ctr->GetEntries();
73 Long64_t nevent = tr->GetEntries();
74 Long64_t neventH = otr->GetEntries();
75 Int_t minevent=0;
76 Int_t maxevent=0;
77
78 printf("Number of total events: %lld\nNumber of total header events: %lld\n",nevent,neventH);
79 printf("Number of calibration events: %lld\n",neventC);
80
81 if (nevent<=0){
82 datafile->Close();
83 return;
84 }
85 if ( fromevent > toevent && toevent>0 ){
86 printf("It must be fromevent < toevent \n");
87 return;
88 }
89 if ( fromevent > nevent || fromevent < 0 ) {
90 printf("You can choose fromevent between 0 (all) and %lld \n",nevent);
91 return;
92 }
93 if ( toevent > nevent || toevent < 0 ) {
94 printf("You can choose toevent between 0 (all) and %lld \n",nevent);
95 return;
96 }
97 if ( fromevent == 0 ) {
98 minevent = 0;
99 maxevent = nevent;
100 } else {
101 minevent = fromevent;
102 if ( toevent > 0 ){
103 maxevent = toevent+1;
104 } else if (toevent > nevent) {
105 maxevent = nevent;
106 } else {
107 maxevent = toevent+1;
108 }
109 nevent=maxevent-minevent ;
110 }
111
112 //
113 // other variables definitions
114 stringstream oss,fromfile,isfile;
115 //
116 // information about the RunHeader
117 Int_t HOBT[neventH];
118 Int_t trk_cal_us[neventH];
119 for (Int_t vi=0; vi<neventH;vi++){
120 HOBT[vi]=0;
121 trk_cal_us[vi]=0;
122 }
123
124 //
125 // information about RunHeader
126 Int_t countnboot=1;
127 for (Int_t ev=0; ev<neventH; ev++){
128 otr->GetEntry(ev);
129 pH = eH->GetPscuHeader();
130 HOBT[ev]= pH->GetOrbitalTime();
131 trk_cal_us[ev]=reh->TRK_CALIB_USED;
132 if((HOBT[ev]<HOBT[ev-1]) && ev>0)
133 countnboot+=1;
134 }
135 countnboot+=2*(Int_t)nevent/MAXSTORAGE;
136 // printf("\ncountnboot=%d\n",countnboot);
137
138 //
139 // information about calibration OBT
140 Int_t COBT[neventC];
141 for (Int_t vi=0; vi<neventC;vi++){
142 COBT[vi]=0;
143 }
144 for (Int_t ev=0; ev<neventC; ev++){
145 ctr->GetEntry(ev);
146 pH = ceh->GetPscuHeader();
147 COBT[ev]= pH->GetOrbitalTime();
148 }
149
150 //
151 // Style options
152 gStyle->SetLabelSize(0.06,"x");
153 gStyle->SetLabelSize(0.06,"y");
154 gStyle->SetStatFontSize(0.075);
155 gStyle->SetOptStat(10);
156 gStyle->SetFillColor(10);
157 gStyle->SetTitleFontSize(0.1);
158 gStyle->SetTitleFillColor(10);
159 gStyle->SetTitleOffset(0.8,"y");
160 gStyle->SetTitleOffset(0.9,"x");
161 gStyle->SetTitleSize(0.06,"y");
162 gStyle->SetTitleSize(0.055,"x");
163
164 //***************************************************************************************
165 // LOOP on each event
166 //***************************************************************************************
167
168 if (fromevent!=0)
169 printf("\n Scan of events from %i to %i ... \n",minevent,maxevent-1);
170 else
171 printf("\n Scan of events from %i to %i ... \n",minevent+1,maxevent);
172
173
174 Int_t minev=minevent,maxev=maxevent,hin=0,hfin=0,cin=0,cfin=0;
175 TPad *pad[12][countnboot];
176 TGraph *dataletime[12][countnboot],*dataletime1[12][countnboot];
177 TCanvas *DataTimeCanv[countnboot];
178 for(Int_t ii=0; ii<countnboot;ii++){
179 fromfile<<"FTrkQLook_BASIC File: "<<ffile;
180 isfile<<"DATALENGTH vs. OBT pag"<<ii+1;
181 DataTimeCanv[ii]=new TCanvas(isfile.str().c_str(),isfile.str().c_str(),900,1200);
182 DataTimeCanv[ii]->SetFillColor(10);
183 DataTimeCanv[ii]->Range(0,0,100,100);
184
185 TLatex *t=new TLatex();
186 t->SetTextFont(32);
187 t->SetTextColor(1);
188 t->SetTextAlign(12);
189 t->SetTextSize(0.02);
190 t->DrawLatex(2.,98.7,fromfile.str().c_str());
191 TLatex *t1=new TLatex();
192 t1->SetTextFont(32);
193 t1->SetTextColor(1);
194 t1->SetTextAlign(12);
195 t1->SetTextSize(0.02);
196 t1->DrawLatex(70.,98.7,isfile.str().c_str());
197 fromfile.str("");
198 isfile.str("");
199
200 fromfile<<"D = Default Calibration";
201 isfile<<"O = OnLine Calibration";
202 t->SetTextColor(6);
203 t->SetTextSize(0.018);
204 t->DrawLatex(70.,97.,fromfile.str().c_str());
205 t->SetTextColor(3);
206 t->DrawLatex(70.,96.,isfile.str().c_str());
207 fromfile.str("");
208 isfile.str("");
209
210 fromfile<<"The green arrow (if present) points out the time of the online calibration";
211 t->DrawLatex(7.,96.,fromfile.str().c_str());
212 fromfile.str("");
213
214 //*************************************************************************************
215 //book pads and histos
216 //***************************************************************************************
217
218
219 Float_t posy = 0.95; // up y-coord - top pads
220 Float_t hpad = 0; // pad height
221 Float_t posx1=0; // left x-coord - pad column
222 Float_t posx0=0; // x-coord - column division
223 Float_t wrel = 0; // relative x size of first sub-column
224 Float_t marg = 0.004; // margin among pads
225
226 hpad = (posy-marg*11)/6;
227 wrel = (1-marg*4)/2;
228 stringstream title;
229 stringstream hid;
230
231 for(Int_t n = 0; n<12; n++) {
232 if ( (n+1)%2==1 ) {
233 if(n>1) posy = posy-(marg*2+hpad);
234 posx1 = marg;
235 posx0 = posx1 + wrel;
236 }
237 else {
238 posx1 = posx0 + 2*marg;
239 posx0 = posx1 + wrel;
240 }
241
242 /* -----------> pad for histograms */
243 oss<<"pad"<<n*100+ii;
244 pad[n][ii]=new TPad(oss.str().c_str()," ",posx1,posy-hpad,posx0,posy,18,0,0);
245 oss.str("");
246 };
247
248 TLine li;
249 li.SetLineColor(1);
250 li.SetLineStyle(1);
251 li.SetLineWidth(1);
252
253 TArrow ar;
254 ar.SetLineColor(3);
255 stringstream calus;
256
257 TLatex *t2=new TLatex();
258 t2->SetTextFont(32);
259 t2->SetTextColor(1);
260 t2->SetTextAlign(13);
261 t2->SetTextSize(0.08);
262
263 Int_t i=0;
264 Float_t x[MAXSTORAGE], xb[MAXSTORAGE];
265 Float_t yyd[MAXSTORAGE][12],yyb[MAXSTORAGE][12];
266 Int_t countbad[12];
267 Float_t perc=0,xMIN=0.,xMAX=0.;
268 for (Int_t n=0; n<12 ; n++)
269 countbad[n]=0;
270
271 //
272 // obtain values of the datalenght
273 for (Int_t ev=minev; ev<maxevent; ev++){
274 tr->GetEntry(ev);
275 ph = eh->GetPscuHeader();
276 cod = eh->GetCounter();
277
278 if(ev==minev){
279 if(cod->Get(pctp->CalibTrk1)>0) cin=cod->Get(pctp->CalibTrk1)-1;
280 else cin=cod->Get(pctp->CalibTrk1);
281 if(cin==cfin-1) cin+=1;
282
283 if(cod->Get(pctp->RunHeader)>0) hin=cod->Get(pctp->RunHeader)-1;
284 else hin=cod->Get(pctp->RunHeader);
285 if(hin==hfin-1) hin+=1;
286 }
287
288 if(ev==maxevent-1) maxev=maxevent-1;
289
290 if((ph->GetOrbitalTime()<x[ev-minev-1] && ev-minev!=0) || ev-minev==MAXSTORAGE){
291 maxev=ev;
292 break;
293 }
294 else{
295 cfin=cod->Get(pctp->CalibTrk1);
296 hfin=cod->Get(pctp->RunHeader);
297 x[(ev-minev)]= ph->GetOrbitalTime();
298 i=0;
299
300 for (Int_t n=0; n<12 ; n++){
301 yyb[countbad[n]][i]=0;
302 xb[countbad[n]]= 0;
303
304 i=te->DSPnumber[n]-1;
305
306 yyd[(ev-minev)][i]=te->DATAlength[n];
307 if(i==6){
308 if(yyd[(ev-minev)][i]>1500){
309 if(yyd[(ev-minev)][i]<3075){
310 yyb[countbad[i]][i]= yyd[(ev-minev)][i];
311 xb[countbad[i]]= x[(ev-minev)];
312 countbad[i]+=1;
313 }
314 }
315 }
316 else{
317 if(yyd[(ev-minev)][i]>750){
318 if(yyd[(ev-minev)][i]<3075){
319 yyb[countbad[i]][i]= yyd[(ev-minev)][i];
320 xb[countbad[i]]= x[(ev-minev)];
321 countbad[i]+=1;
322 }
323 }
324 }
325 }
326 }
327 }
328
329 //
330 // define limit for the Xaxis of the graphs
331
332 xMAX=x[maxev-minev-1]+(x[maxev-minev-1]-x[0])/10;
333 if(xMAX>1000000) xMIN=x[0]-(x[maxev-minev-1]-x[0])/10;
334 if(xMAX<1000000 || xMIN<0) xMIN=0.;
335
336
337 //
338 // Draw Histos
339 for (Int_t i=0; i<12 ; i++){
340
341 Float_t y[maxev-minev],yb[maxev-minev];
342 for(Int_t v=0;v<maxev-minev;v++){
343 y[v]=yyd[v][i];
344 yb[v]=yyb[v][i];
345 }
346
347 if(xMAX<1000000){
348 x[maxev-minev-1]=0.;
349 y[maxev-minev-1]=0.;
350 }
351
352 if((maxev-minev)>1000){
353 perc=(countbad[i]*100)/(maxev-minev);
354 if(perc>10) pad[i][ii]->SetFillColor(2);
355 else pad[i][ii]->SetFillColor(10);
356 }
357 else{
358 if(countbad[i]>=100) pad[i][ii]->SetFillColor(2);
359 else pad[i][ii]->SetFillColor(10);
360 }
361
362 oss<<"DSP "<<i+1;
363 DataTimeCanv[ii]->cd();
364 pad[i][ii]->SetFrameFillColor(10);
365 pad[i][ii]->Draw();
366 pad[i][ii]->cd();
367 dataletime[i][ii]= new TGraph((maxev-minev),x,y);
368 dataletime[i][ii]->SetTitle(oss.str().c_str());
369 dataletime[i][ii]->GetXaxis()->SetTitle("OBT (ms)");
370 dataletime[i][ii]->GetXaxis()->CenterTitle();
371 dataletime[i][ii]->GetXaxis()->SetRangeUser(xMIN,xMAX);
372 dataletime[i][ii]->GetYaxis()->SetTitle("datalength (Word 13 bit)");
373 dataletime[i][ii]->GetYaxis()->CenterTitle();
374 if(i==6) dataletime[i][ii]->GetYaxis()->SetRangeUser(0,4500);
375 else dataletime[i][ii]->GetYaxis()->SetRangeUser(0,4000);
376 dataletime[i][ii]->SetMarkerStyle(21);
377 if((maxev-minev)<50) dataletime[i][ii]->SetMarkerSize(0.5);
378 else dataletime[i][ii]->SetMarkerSize(0.1);
379 dataletime[i][ii]->SetMarkerColor(4);
380 dataletime[i][ii]->Draw("ap");
381
382
383 if((maxev-minev)>1000 && perc>10){
384 dataletime1[i][ii]= new TGraph(countbad[i],xb,yb);
385 dataletime1[i][ii]->SetMarkerStyle(21);
386 if((maxev-minev)<50) dataletime1[i][ii]->SetMarkerSize(0.5);
387 else dataletime1[i][ii]->SetMarkerSize(0.1);
388 dataletime1[i][ii]->SetMarkerColor(2);
389 dataletime1[i][ii]->Draw("psame");
390 }
391 else if((maxev-minev)<1000 && countbad[i]>=100){
392 dataletime1[i][ii]= new TGraph(countbad[i],xb,yb);
393 dataletime1[i][ii]->SetMarkerStyle(21);
394 if((maxev-minev)<50) dataletime1[i][ii]->SetMarkerSize(0.5);
395 else dataletime1[i][ii]->SetMarkerSize(0.1);
396 dataletime1[i][ii]->SetMarkerColor(2);
397 dataletime1[i][ii]->Draw("psame");
398 }
399 li.SetLineColor(1);
400 li.SetLineStyle(1);
401 li.SetLineWidth(1);
402 if(i!=6) li.DrawLine(xMIN,750,xMAX,750);
403 else li.DrawLine(xMIN,1500,xMAX,1500);
404 li.DrawLine(xMIN,3075,xMAX,3075);
405
406 li.SetLineColor(12);
407 li.SetLineStyle(4);
408 li.SetLineWidth(1);
409 for(Int_t j=hin;j<hfin;j++){
410 if(i==6) li.DrawLine(HOBT[j],0.,HOBT[j],4500.);
411 else li.DrawLine(HOBT[j],0.,HOBT[j],4000.);
412 if(trk_cal_us[j]==104){
413 calus<<"D";
414 t2->SetTextColor(6);
415 if(i==6) t2->DrawLatex(HOBT[j],4350.,calus.str().c_str());
416 else t2->DrawLatex(HOBT[j],3850.,calus.str().c_str());
417 calus.str("");
418 }
419 else{
420 calus<<"O";
421 t2->SetTextColor(3);
422 if(i==6) t2->DrawLatex(HOBT[j],4350.,calus.str().c_str());
423 else t2->DrawLatex(HOBT[j],3850.,calus.str().c_str());
424 calus.str("");
425 }
426 }
427 for(Int_t j=cin;j<cfin;j++){
428 if(i==6) ar.DrawArrow(COBT[j],1700.,COBT[j],2700.,0.01,"<");
429 else ar.DrawArrow(COBT[j],1000.,COBT[j],2000.,0.01,"<");
430 }
431
432 oss.str("");
433 DataTimeCanv[ii]->Update();
434 }
435
436 minev=maxev;
437 if(maxev==maxevent-1) {
438 countnboot=ii+1;
439 break;
440 }
441 }
442 printf("... end of packets. \n");
443
444 //*************************************************************************
445 // Save output Files
446 //*************************************************************************
447 stringstream nom1,nom2,nom3;
448
449 for(Int_t fl=0;fl<countnboot;fl++){
450 if(countnboot==1){
451 nom1<<ffile<<"_FTrkQLook_BASIC."<<outfile.Data();
452 DataTimeCanv[fl]->Print(out+nom1.str().c_str());
453 nom1.str("");
454 }
455
456 if(countnboot>=2){
457 if(!strcmp(outfile.Data(),"ps") || !strcmp(outfile.Data(),"pdf")){
458 nom1.str("");
459 nom2.str("");
460 nom3.str("");
461 nom1<<ffile<<"_FTrkQLook_BASIC.ps(";
462 nom2<<ffile<<"_FTrkQLook_BASIC.ps";
463 nom3<<ffile<<"_FTrkQLook_BASIC.ps)";
464 if(fl==0) DataTimeCanv[fl]->Print(out+nom1.str().c_str(),"portrait");
465 else if(fl==countnboot-1) DataTimeCanv[fl]->Print(out+nom3.str().c_str(),"portrait");
466 else DataTimeCanv[fl]->Print(out+nom2.str().c_str(),"portrait");
467
468 }
469 else{
470 nom1.str("");
471 nom1<<ffile<<"_FTrkQLook_BASIC-pag"<<fl+1<<"."<<outfile.Data();
472 DataTimeCanv[fl]->Print(out+nom1.str().c_str());
473 }
474 }
475 }
476
477 //
478 // Convert ps to pdf if required
479 if(!strcmp(outfile.Data(),"pdf") && countnboot>=2){
480 stringstream com;
481 com<<"ps2pdf13 "<<out<<ffile<<"_FTrkQLook_BASIC.ps "<<out<<ffile<<"_FTrkQLook_BASIC.pdf";
482 system(com.str().c_str());
483 printf("\n---> ps file converted in pdf format!\n");
484 com.str("");
485 com<<"rm -f "<<out<<ffile<<"_FTrkQLook_BASIC.ps";
486 system(com.str().c_str());
487 printf("---> ps file removed!\n\n");
488 com.str("");
489 }
490
491 datafile->Close();
492 gROOT->Reset();
493 return;
494 }

  ViewVC Help
Powered by ViewVC 1.1.23