/[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.4 - (show annotations) (download)
Mon Jun 5 08:38:42 2006 UTC (18 years, 6 months ago) by pam-fi
Branch: MAIN
Changes since 1.3: +4 -3 lines
*** empty log message ***

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

  ViewVC Help
Powered by ViewVC 1.1.23