Updating macro to read QA output: saving canvases both for single run and for trending.
[u/mrichter/AliRoot.git] / TOF / macrosQA / MakeTrendingTOFQA.C
1 //fbellini@cern.ch, 11/11/2011
2 //-----------------------------------------------------------
3 Int_t MakeTrendingTOFQA(char * runlist, Int_t year=2011, char *period="LHC11d", char* pass="cpass1", Int_t trainId=0){
4         Int_t filesCounter=0;
5   
6         if (!runlist) {
7                 printf("Invalid list of runs given as input: nothing done\n");
8                 return 1;
9         }       
10         Int_t runNumber;
11         char infile[300]; 
12         char postFileName[20];
13   
14         char trendFileName[100]; 
15         //Define trending output
16         if (trainId==0){
17                 sprintf(trendFileName,"treeTOFQA_%s_%s.root",period,pass);  
18         }else{
19                 sprintf(trendFileName,"treeTOFQA_QA%i_%s_%s.root",trainId,period,pass);
20         }
21         TFile * trendFile=new TFile(trendFileName,"recreate");
22   
23         Double_t avTime=-9999., peakTime=-9999., spreadTime=-9999., peakTimeErr=-9999., spreadTimeErr=-9999., negTimeRatio=-9999.,
24                 avRawTime=-9999., peakRawTime=-9999., spreadRawTime=-9999., peakRawTimeErr=-9999., spreadRawTimeErr=-9999., 
25                 avTot=-9999., peakTot=-9999.,spreadTot=-9999.,  peakTotErr=-9999.,spreadTotErr=-9999.,
26                 orphansRatio=-9999., avL=-9999., negLratio=-9999.,
27                 effPt1=-9999., effPt2=-9999., matchEffLinFit1Gev=-9999.,matchEffLinFit1GevErr=-9999.;
28   
29         Double_t avPiDiffTime=-9999.,peakPiDiffTime=-9999., spreadPiDiffTime=-9999.,peakPiDiffTimeErr=-9999., spreadPiDiffTimeErr=-9999.;
30   
31         Double_t avT0A=-9999.,peakT0A=-9999., spreadT0A=-9999.,peakT0AErr=-9999., spreadT0AErr=-9999.;
32         Double_t avT0C=-9999.,peakT0C=-9999., spreadT0C=-9999.,peakT0CErr=-9999., spreadT0CErr=-9999.;
33         Double_t avT0AC=-9999.,peakT0AC=-9999., spreadT0AC=-9999.,peakT0ACErr=-9999., spreadT0ACErr=-9999.;
34         Double_t avT0res=-9999.,peakT0res=-9999., spreadT0res=-9999.,peakT0resErr=-9999., spreadT0resErr=-9999.;
35         Double_t avT0fillRes=-9999.;
36
37         Int_t avMulti=0;
38         Float_t fractionEventsWHits=-9999.;
39   
40         TTree * ttree=new TTree("trendTree","tree of trending variables");
41         ttree->Branch("run",&runNumber,"run/I");
42         ttree->Branch("avMulti",&avMulti,"avMulti/I");
43         ttree->Branch("fractionEventsWHits",&fractionEventsWHits,"fractionEventsWHits/F");
44         ttree->Branch("avTime",&avTime,"avTime/D"); //mean time
45         ttree->Branch("peakTime",&peakTime,"peakTime/D"); //main peak time after fit
46         ttree->Branch("spreadTime",&spreadTime,"spreadTime/D"); //spread of main peak of time after fit
47         ttree->Branch("peakTimeErr",&peakTimeErr,"peakTimeErr/D"); //main peak time after fit error
48         ttree->Branch("spreadTimeErr",&spreadTimeErr,"spreadTimeErr/D"); //spread of main peak of time after fit error
49         ttree->Branch("negTimeRatio",&negTimeRatio,"negTimeRatio/D"); //negative time ratio
50   
51         ttree->Branch("avRawTime",&avRawTime,"avRawTime/D"); //mean raw time
52         ttree->Branch("peakRawTime",&peakRawTime,"peakRawTime/D"); //mean peak of RAW TIME after fit
53         ttree->Branch("spreadRawTime",&spreadRawTime,"spreadRawTime/D"); //spread of main peak of raw time after fit
54         ttree->Branch("peakRawTimeErr",&peakRawTimeErr,"peakRawTimeErr/D"); //main peak raw  time after fit error
55         ttree->Branch("spreadRawTimeErr",&spreadRawTimeErr,"spreadRawTimeErr/D"); //spread of  raw main peak of time after fit error
56   
57         ttree->Branch("avTot",&avTot,"avTot/D"); //main peak tot
58         ttree->Branch("peakTot",&peakTot,"peakTot/D"); // main peak of tot after fit
59         ttree->Branch("spreadTot",&spreadTot,"spreadTot/D"); //spread of main peak of tot after fit
60         ttree->Branch("peakTotErr",&peakTotErr,"peakTotErr/D"); // main peak of tot after fit
61         ttree->Branch("spreadTotErr",&spreadTotErr,"spreadTotErr/D"); //spread of main peak of tot after fit
62   
63         ttree->Branch("orphansRatio",&orphansRatio,"orphansRatio/D"); //orphans ratio
64
65         ttree->Branch("avL",&avL,"avL/D"); //mean track length
66         ttree->Branch("negLratio",&negLratio,"negLratio/D");//ratio of tracks with track length <350 cm
67
68         ttree->Branch("effPt1",&effPt1,"effPt1/D");//matching eff at 1 GeV/c
69         ttree->Branch("effPt2",&effPt2,"effPt2/D"); //matching eff at 2 GeV/c
70         ttree->Branch("matchEffLinFit1Gev",&matchEffLinFit1Gev,"matchEffLinFit1Gev/D");//matching eff fit param 
71         ttree->Branch("matchEffLinFit1GevErr",&matchEffLinFit1GevErr,"matchEffLinFit1GevErr/D");////matching eff fit param error
72   
73         ttree->Branch("avPiDiffTime",&avPiDiffTime,"avPiDiffTime/D"); //mean t-texp
74         ttree->Branch("peakPiDiffTime",&peakPiDiffTime,"peakPiDiffTime/D"); //main peak t-texp after fit
75         ttree->Branch("spreadPiDiffTime",&spreadPiDiffTime,"spreadPiDiffTime/D"); //spread of main peak t-texp after fit
76         ttree->Branch("peakPiDiffTimeErr",&peakPiDiffTimeErr,"peakPiDiffTimeErr/D"); //main peak t-texp after fit error
77         ttree->Branch("spreadPiDiffTimeErr",&spreadPiDiffTimeErr,"spreadPiDiffTimeErr/D"); //spread of main peak of t-texp after fit error
78
79         ttree->Branch("avT0A",&avT0A,"avT0A/D"); //main peak t0A
80         ttree->Branch("peakT0A",&peakT0A,"peakT0A/D"); // main peak of t0A after fit
81         ttree->Branch("spreadT0A",&spreadT0A,"spreadTot/D"); //spread of main peak of t0A after fit
82         ttree->Branch("peakT0AErr",&peakT0AErr,"peakT0AErr/D"); // main peak of t0A after fit
83         ttree->Branch("spreadT0AErr",&spreadT0AErr,"spreadT0AErr/D"); //spread of main peak of t0A after fit
84
85         ttree->Branch("avT0C",&avT0C,"avT0C/D"); //main peak t0C
86         ttree->Branch("peakT0C",&peakT0C,"peakT0C/D"); // main peak of t0C after fit
87         ttree->Branch("spreadT0C",&spreadT0C,"spreadT0C/D"); //spread of main peak of t0C after fit
88         ttree->Branch("peakT0CErr",&peakT0CErr,"peakT0CErr/D"); // main peak of t0C after fit
89         ttree->Branch("spreadT0CErr",&spreadT0CErr,"spreadT0CErr/D"); //spread of main peak of t0C after fit
90  
91         ttree->Branch("avT0AC",&avT0AC,"avT0AC/D"); //main peak t0AC
92         ttree->Branch("peakT0AC",&peakT0AC,"peakT0AC/D"); // main peak of t0AC after fit
93         ttree->Branch("spreadT0AC",&spreadT0AC,"spreadT0AC/D"); //spread of main peak of t0AC after fit
94         ttree->Branch("peakT0ACErr",&peakT0ACErr,"peakT0ACErr/D"); // main peak of t0AC after fit
95         ttree->Branch("spreadT0ACErr",&spreadT0ACErr,"spreadT0ACErr/D"); //spread of main peak of t0AC after fit
96  
97         ttree->Branch("avT0res",&avT0res,"avT0res/D"); //main peak t0AC
98         ttree->Branch("peakT0res",&peakT0res,"peakT0res/D"); // main peak of t0AC after fit
99         ttree->Branch("spreadT0res",&spreadT0res,"spreadT0res/D"); //spread of main peak of t0AC after fit
100         ttree->Branch("peakT0resErr",&peakT0resErr,"peakT0resErr/D"); // main peak of t0AC after fit
101         ttree->Branch("spreadT0resErr",&spreadT0resErr,"spreadT0resErr/D"); //spread of main peak of t0AC after fit
102         ttree->Branch("avT0fillRes",&avT0fillRes,"avT0fillRes/D"); //t0 fill res
103   
104
105         FILE * files = fopen(runlist, "r") ; 
106         while (fscanf(files,"%d",&runNumber)==1 ){
107     
108                 //reset all variables
109                 avTime=-9999.; peakTime=-9999.; spreadTime=-9999.; peakTimeErr=-9999.; spreadTimeErr=-9999.;negTimeRatio=-9999.;
110                 avRawTime=-9999.; peakRawTime=-9999.; spreadRawTime=-9999.; peakRawTimeErr=-9999.; spreadRawTimeErr=-9999.; 
111                 avTot=-9999.; peakTot=-9999.;spreadTot=-9999.;  peakTotErr=-9999.;spreadTotErr=-9999.;
112                 orphansRatio=-9999.; avL=-9999.; negLratio=-9999.;
113                 effPt1=-9999.; effPt2=-9999.; matchEffLinFit1Gev=-9999.;matchEffLinFit1GevErr=-9999.;
114     
115                 avPiDiffTime=-9999.;peakPiDiffTime=-9999.; spreadPiDiffTime=-9999.;peakPiDiffTimeErr=-9999.; spreadPiDiffTimeErr=-9999.;
116     
117                 avT0A=-9999.;peakT0A=-9999.; spreadT0A=-9999.;peakT0AErr=-9999.; spreadT0AErr=-9999.;
118                 avT0C=-9999.;peakT0C=-9999.; spreadT0C=-9999.;peakT0CErr=-9999.; spreadT0CErr=-9999.;
119                 avT0AC=-9999.;peakT0AC=-9999.; spreadT0AC=-9999.;peakT0ACErr=-9999.; spreadT0ACErr=-9999.;
120                 avT0res=-9999.;peakT0res=-9999.; spreadT0res=-9999.;peakT0resErr=-9999.; spreadT0resErr=-9999.;
121                 avMulti=0; avT0fillRes=0.;
122                 fractionEventsWHits=-9999.;
123     
124                 //get QAtrain output
125                 //SetQAtrainOutputName(runNumber, year,period,pass,trainId);
126                 if (trainId==0){
127                         sprintf(infile,"alien:///alice/data/%i/%s/000%d/ESDs/%s/QAresults.root",year,period,runNumber,pass);
128                 } else{
129                         sprintf(infile,"alien:///alice/data/%i/%s/000%d/ESDs/%s/QA%i/QAresults.root",year,period,runNumber,pass,trainId);
130                 }
131                 printf("============== Opening QA file(s) for run %i =======================\n",runNumber);
132     
133     
134                 //run post-analysis
135                 if (RunESDQApostAnalysis(infile,runNumber,kTRUE)==0){
136                         filesCounter++;
137       
138                         //get post-analysis output
139                         sprintf(postFileName,"postQA_%i.root",runNumber);
140                         TFile *postfile=TFile::Open(postFileName);
141                         if (!postfile) {
142                                 printf("Post-analysis output not found - cannot perform trending analysis. Exiting.");
143                                 return 2;
144                         } else {
145                                 printf("==============  Retrieving post-analysis for run %i ===============\n",runNumber);
146                         }
147                         //postfile->ls();
148                         //save quantities for trending
149       
150                         //--------------------------------- Multiplicity ----------------------------------//
151                         TH1F*hMulti=(TH1F*)postfile->Get("hTOFmatchedPerEvt");
152                         if ((hMulti)&&(hMulti->GetEntries()>0)) {
153                                 avMulti=hMulti->GetMean();
154                         }
155       
156                         //--------------------------------- T0F signal ----------------------------------//
157       
158                         TH1F*hTime=(TH1F*)postfile->Get("hTOFmatchedESDtime");
159                         if ((hTime)&&(hTime->GetEntries()>0)) {
160                                 avTime=hTime->GetMean();
161                                 hTime->Fit("landau","","",0.,50.);
162                                 peakTime=(hTime->GetFunction("landau"))->GetParameter(1);
163                                 spreadTime=(hTime->GetFunction("landau"))->GetParameter(2);
164                                 peakTimeErr=(hTime->GetFunction("landau"))->GetParError(1);
165                                 spreadTimeErr=(hTime->GetFunction("landau"))->GetParError(2);
166         
167                                 negTimeRatio=((Double_t)hTime->Integral(1,3)*100.)/((Double_t)hTime->Integral());
168                                 printf("Main peak time (landau): mean = %f +- %f\n",peakTime,peakTimeErr );
169                                 printf("Main peak time (landau): spread = %f +- %f\n",spreadTime,spreadTimeErr );
170                                 printf("Ratio of tracks with time<12.5 ns / total = %f\n",negTimeRatio );
171         
172                                 //add integral of main peak over total
173                         }
174                         printf("---------------------------------------------------------------- \n");
175                         TH1F * hRawTime = (TH1F*)postfile->Get("hTOFmatchedESDrawTime");
176                         if ((hRawTime)&&(hRawTime->GetEntries()>0)){
177                                 avRawTime=hRawTime->GetMean();
178                                 hRawTime->Fit("landau","","",200.,250.);
179                                 peakRawTime=(hRawTime->GetFunction("landau"))->GetParameter(1);
180                                 spreadRawTime=(hRawTime->GetFunction("landau"))->GetParameter(2);
181                                 peakRawTimeErr=(hRawTime->GetFunction("landau"))->GetParError(1);
182                                 spreadRawTimeErr=(hRawTime->GetFunction("landau"))->GetParError(2);
183                                 printf("Main peak raw time (landau): mean = %f +- %f\n",peakTime,peakTimeErr );
184                                 printf("Main peak raw time (landau): spread = %f +- %f\n",spreadRawTime,spreadRawTimeErr );
185                         }
186       
187                         printf("---------------------------------------------------------------- \n");
188       
189                         TH1F * hTot = (TH1F*)postfile->Get("hTOFmatchedESDToT");
190                         if ((hTot)&&(hTot->GetEntries()>0)){
191                                 avTot=hTot->GetMean();
192                                 hTot->Fit("gaus","","",0.,50.);
193                                 peakTot=(hTot->GetFunction("gaus"))->GetParameter(1);
194                                 spreadTot=(hTot->GetFunction("gaus"))->GetParameter(2);
195                                 peakTotErr=(hTot->GetFunction("gaus"))->GetParError(1);
196                                 spreadTotErr=(hTot->GetFunction("gaus"))->GetParError(2);
197                                 printf("Main peak ToT (gaus): mean = %f +- %f\n",peakTot,peakTotErr );
198                                 printf("Main peak ToT (gaus): spread = %f +- %f\n",spreadTot,spreadTotErr );    
199                         }      
200                         printf("---------------------------------------------------------------- \n");
201                         TH1F * hOrphansRatio=(TH1F*)postfile->Get("hOrphansRatio");
202                         if (hOrphansRatio)
203                                 orphansRatio=hOrphansRatio->GetMean();
204       
205                         TH1F * hL=(TH1F*)postfile->Get("hTOFmatchedESDtrkLength");
206                         if (hL)
207                                 avL=hL->GetMean();
208       
209                         TH1F *hLnegRatio =(TH1F*)postfile->Get("hLnegRatio");
210                         if (hLnegRatio)
211                                 negLratio=hLnegRatio->GetMean();
212       
213                         //--------------------------------- matching eff ----------------------------------//
214      
215                         //Double_t linFitEff1Param[3]={0.,0.,0.};
216                         TH1F *hMatchingVsPt =(TH1F*)postfile->Get("hTOFmatchedESDPt");
217                         if (hMatchingVsPt) {
218                                 if (hMatchingVsPt->GetEntries()>0){
219                                         hMatchingVsPt->Fit("pol0","","",1.0,5.);
220                                         hMatchingVsPt->Draw();
221                                         if (hMatchingVsPt->GetFunction("pol0")){
222                                                 matchEffLinFit1Gev=(hMatchingVsPt->GetFunction("pol0"))->GetParameter(0);
223                                                 matchEffLinFit1GevErr=(hMatchingVsPt->GetFunction("pol0"))->GetParError(0);     
224                                                 printf("Matching efficiency fit param is %f +- %f\n",matchEffLinFit1Gev,matchEffLinFit1GevErr );
225                                         }
226                                 } else {
227                                         printf("WARNING: matching efficiency plot has 0 entries. Skipped!\n");
228                                 }
229                         } else {
230                                 printf("WARNING: cannot retrieve matching efficiency plot\n");
231                         }
232
233                         //--------------------------------- t-texp ----------------------------------//
234      
235                         TH1F*hPiDiffTime=(TH1F*)postfile->Get("hTOFmatchedExpTimePi");
236                         if ((hPiDiffTime)&&(hPiDiffTime->GetEntries()>0)) {
237                                 avPiDiffTime=hPiDiffTime->GetMean();
238                                 hPiDiffTime->Fit("gaus","","",-1000.,500.);
239                                 if (hPiDiffTime->GetFunction("gaus")){
240                                         peakPiDiffTime=(hPiDiffTime->GetFunction("gaus"))->GetParameter(1);
241                                         spreadPiDiffTime=(hPiDiffTime->GetFunction("gaus"))->GetParameter(2);
242                                         peakPiDiffTimeErr=(hPiDiffTime->GetFunction("gaus"))->GetParError(1);
243                                         spreadPiDiffTimeErr=(hPiDiffTime->GetFunction("gaus"))->GetParError(2);
244                                         printf("Main peak t-t_exp (gaus): mean = %f +- %f\n",peakPiDiffTime,peakPiDiffTimeErr );
245                                         printf("Main peak t-t_exp (gaus): spread = %f +- %f\n",spreadPiDiffTime,spreadPiDiffTimeErr );
246                                 }
247                         }
248                         //--------------------------------- T0 detector ----------------------------------//
249       
250                         TH1F*hT0A=(TH1F*)postfile->Get("hEventT0DetA");
251                         if ((hT0A)&&(hT0A->GetEntries()>0)) {
252                                 avhT0A=hT0A->GetMean();
253                                 hT0A->Fit("gaus");
254                                 peakT0A=(hT0A->GetFunction("gaus"))->GetParameter(1);
255                                 spreadT0A=(hT0A->GetFunction("gaus"))->GetParameter(2);
256                                 peakT0AErr=(hT0A->GetFunction("gaus"))->GetParError(1);
257                                 spreadT0AErr=(hT0A->GetFunction("gaus"))->GetParError(2);       
258                                 printf("Main peak T0A(gaus): mean = %f +- %f\n",peakT0A,peakT0AErr );
259                                 printf("Main peak T0A (gaus): spread = %f +- %f\n",spreadT0A,spreadT0AErr );     
260                                 //add integral of main peak over total
261                         }
262
263                         TH1F*hT0C=(TH1F*)postfile->Get("hEventT0DetC");
264                         if ((hT0C)&&(hT0C->GetEntries()>0)) {
265                                 avhT0C=hT0C->GetMean();
266                                 hT0C->Fit("gaus");
267                                 peakT0C=(hT0C->GetFunction("gaus"))->GetParameter(1);
268                                 spreadT0C=(hT0C->GetFunction("gaus"))->GetParameter(2);
269                                 peakT0CErr=(hT0C->GetFunction("gaus"))->GetParError(1);
270                                 spreadT0CErr=(hT0C->GetFunction("gaus"))->GetParError(2);       
271                                 printf("Main peak T0C(gaus): mean = %f +- %f\n",peakT0C,peakT0CErr );
272                                 printf("Main peak T0C (gaus): spread = %f +- %f\n",spreadT0C,spreadT0CErr );     
273                                 //add integral of main peak over total
274                         }
275
276                         TH1F*hT0AC=(TH1F*)postfile->Get("hEventT0DetAND");
277                         if ((hT0AC)&&(hT0AC->GetEntries()>0)) {
278                                 avhT0AC=hT0AC->GetMean();
279                                 hT0AC->Fit("gaus");
280                                 peakT0AC=(hT0AC->GetFunction("gaus"))->GetParameter(1);
281                                 spreadT0AC=(hT0AC->GetFunction("gaus"))->GetParameter(2);
282                                 peakT0ACErr=(hT0AC->GetFunction("gaus"))->GetParError(1);
283                                 spreadT0ACErr=(hT0AC->GetFunction("gaus"))->GetParError(2);     
284                                 printf("Main peak T0AC(gaus): mean = %f +- %f\n",peakT0AC,peakT0ACErr );
285                                 printf("Main peak T0AC (gaus): spread = %f +- %f\n",spreadT0AC,spreadT0ACErr );  
286                         }
287       
288                         TH1F*hT0res=(TH1F*)postfile->Get("hT0DetRes");
289                         if ((hT0res)&&(hT0res->GetEntries()>0)) {
290                                 avhT0res=hT0res->GetMean();
291                                 hT0res->Fit("gaus");
292                                 peakT0res=(hT0res->GetFunction("gaus"))->GetParameter(1);
293                                 spreadT0res=(hT0res->GetFunction("gaus"))->GetParameter(2);
294                                 peakT0resErr=(hT0res->GetFunction("gaus"))->GetParError(1);
295                                 spreadT0resErr=(hT0res->GetFunction("gaus"))->GetParError(2);   
296                                 printf("Main peak T0res(gaus): mean = %f +- %f\n",peakT0res,peakT0resErr );
297                                 printf("Main peak T0res (gaus): spread = %f +- %f\n",spreadT0res,spreadT0resErr );       
298                                 //add integral of main peak over total
299                         }
300
301                         TH1F*hT0fillRes=(TH1F*)postfile->Get("hT0fillRes");
302                         if ((hT0fillRes)&&(hT0fillRes->GetEntries()>0)) {
303                                 avT0fillRes=hT0fillRes->GetMean();
304                         }
305       
306                         ttree->Fill();
307                         printf("==============  Saving trending quantities for run %i ===============\n",runNumber);
308                         if (postfile->IsOpen()) {
309                                 printf("Trying to close\n");
310                                 postfile->Close();
311                         }  
312                 } else {
313                         printf("==============   QA for run %i not available - skipping ===============\n",runNumber);
314                 }
315     
316         } 
317         printf("Number of files processed = %i\n",filesCounter);
318   
319         trendFile->cd();
320         ttree->Write();
321         trendFile->Close();
322
323         return  MakeTrendingFromTreeWithErrors(trendFileName); 
324 }
325
326 //______________________________________________________________________________
327
328 Int_t MakeTrendingFromTreeWithErrors(char* trendFileName=NULL){
329
330         if (!trendFileName) 
331                 return 3;
332   
333         TFile *fin=TFile::Open(trendFileName);
334         if (!fin) 
335                 return 4;
336         Int_t runNumber;
337         Double_t avTime=0., peakTime=0., spreadTime=0., peakTimeErr=0., spreadTimeErr=0.,negTimeRatio=0.,
338                 avRawTime=0., peakRawTime=0., spreadRawTime=0., peakRawTimeErr=0., spreadRawTimeErr=0., 
339                 avTot=0., peakTot=0.,spreadTot=0.,  peakTotErr=0.,spreadTotErr=0.,
340                 orphansRatio=0., avL=0., negLratio=0.,
341                 effPt1=0., effPt2=0., matchEffLinFit1Gev=0.,matchEffLinFit1GevErr=0.;
342         Double_t avDiffTime=0.,peakDiffTime=0., spreadDiffTime=0.,peakDiffTimeErr=0., spreadDiffTimeErr=0.,avT0fillRes=0.;
343    
344         Double_t avT0A=0.,peakT0A=0., spreadT0A=0.,peakT0AErr=0., spreadT0AErr=0.;
345         Double_t avT0C=0.,peakT0C=0., spreadT0C=0.,peakT0CErr=0., spreadT0CErr=0.;
346         Double_t avT0AC=0.,peakT0AC=0., spreadT0AC=0.,peakT0ACErr=0., spreadT0ACErr=0.;
347         Double_t avT0res=0.,peakT0res=0., spreadT0res=0.,peakT0resErr=0., spreadT0resErr=0.;
348         Int_t avMulti=0;
349         Float_t fractionEventsWHits=0;
350    
351         TTree * ttree=(TTree*)fin->Get("trendTree");
352         ttree->SetBranchAddress("run",&runNumber);
353    
354         ttree->SetBranchAddress("avTime",&avTime); //mean time
355         ttree->SetBranchAddress("peakTime",&peakTime); //main peak time after fit
356         ttree->SetBranchAddress("spreadTime",&spreadTime); //spread of main peak of time after fit
357         ttree->SetBranchAddress("peakTimeErr",&peakTimeErr); //main peak time after fit error
358         ttree->SetBranchAddress("spreadTimeErr",&spreadTimeErr); //spread of main peak of time after fit error
359    
360         ttree->SetBranchAddress("negTimeRatio",&negTimeRatio); //negative time ratio
361    
362         ttree->SetBranchAddress("avRawTime",&avRawTime); //mean raw time
363         ttree->SetBranchAddress("peakRawTime",&peakRawTime); //mean peak of raw time after fit
364         ttree->SetBranchAddress("spreadRawTime",&spreadRawTime); //spread of main peak of raw time after fit
365         ttree->SetBranchAddress("peakRawTimeErr",&peakRawTimeErr); //main peak raw  time after fit error
366         ttree->SetBranchAddress("spreadRawTimeErr",&spreadRawTimeErr); //spread of  raw main peak of time after fit error
367   
368         ttree->SetBranchAddress("avTot",&avTot); //main peak tot
369         ttree->SetBranchAddress("peakTot",&peakTot); // main peak of tot after fit
370         ttree->SetBranchAddress("spreadTot",&spreadTot); //spread of main peak of tot after fit
371         ttree->SetBranchAddress("peakTotErr",&peakTotErr); // main peak of tot after fit
372         ttree->SetBranchAddress("spreadTotErr",&spreadTotErr); //spread of main peak of tot after fit
373    
374         ttree->SetBranchAddress("orphansRatio",&orphansRatio); //orphans ratio
375    
376         ttree->SetBranchAddress("avL",&avL); //mean track length
377         ttree->SetBranchAddress("negLratio",&negLratio);//ratio of tracks with track length <350 cm
378    
379         ttree->SetBranchAddress("effPt1",&effPt1);//matching eff at 1 GeV/c
380         ttree->SetBranchAddress("effPt2",&effPt2); //matching eff at 2 GeV/c
381         ttree->SetBranchAddress("matchEffLinFit1Gev",&matchEffLinFit1Gev);//matching eff fit param 
382         ttree->SetBranchAddress("matchEffLinFit1GevErr",&matchEffLinFit1GevErr);////matching eff fit param error
383    
384         ttree->SetBranchAddress("avPiDiffTime",&avDiffTime); //mean t-texp
385         ttree->SetBranchAddress("peakPiDiffTime",&peakDiffTime); //main peak t-texp after fit
386         ttree->SetBranchAddress("spreadPiDiffTime",&spreadDiffTime); //spread of main peak t-texp after fit
387         ttree->SetBranchAddress("peakPiDiffTimeErr",&peakDiffTimeErr); //main peak t-texp after fit error
388         ttree->SetBranchAddress("spreadPiDiffTimeErr",&spreadDiffTimeErr); //spread of main peak of t-texp after fit error
389    
390         ttree->SetBranchAddress("avT0A",&avT0A); //main peak t0A
391         ttree->SetBranchAddress("peakT0A",&peakT0A); // main peak of t0A after fit
392         ttree->SetBranchAddress("spreadT0A",&spreadT0A); //spread of main peak of t0A after fit
393         ttree->SetBranchAddress("peakT0AErr",&peakT0AErr); // main peak of t0A after fit
394         ttree->SetBranchAddress("spreadT0AErr",&spreadT0AErr); //spread of main peak of t0A after fit
395    
396         ttree->SetBranchAddress("avT0C",&avT0C); //main peak t0C
397         ttree->SetBranchAddress("peakT0C",&peakT0C); // main peak of t0C after fit
398         ttree->SetBranchAddress("spreadT0C",&spreadT0C); //spread of main peak of t0C after fit
399         ttree->SetBranchAddress("peakT0CErr",&peakT0CErr); // main peak of t0C after fit
400         ttree->SetBranchAddress("spreadT0CErr",&spreadT0CErr); //spread of main peak of t0C after fit
401    
402         ttree->SetBranchAddress("avT0AC",&avT0AC); //main peak t0AC
403         ttree->SetBranchAddress("peakT0AC",&peakT0AC); // main peak of t0AC after fit
404         ttree->SetBranchAddress("spreadT0AC",&spreadT0AC); //spread of main peak of t0AC after fit
405         ttree->SetBranchAddress("peakT0ACErr",&peakT0ACErr); // main peak of t0AC after fit
406         ttree->SetBranchAddress("spreadT0ACErr",&spreadT0ACErr); //spread of main peak of t0AC after fit
407    
408         ttree->SetBranchAddress("avT0res",&avT0res); //main peak t0AC
409         ttree->SetBranchAddress("peakT0res",&peakT0res); // main peak of t0AC after fit
410         ttree->SetBranchAddress("spreadT0res",&spreadT0res); //spread of main peak of t0AC after fit
411         ttree->SetBranchAddress("peakT0resErr",&peakT0resErr); // main peak of t0AC after fit
412         ttree->SetBranchAddress("spreadT0resErr",&spreadT0resErr); //spread of main peak of t0AC after fit
413         ttree->SetBranchAddress("avT0fillRes",&avT0fillRes); //t0 fill res
414
415         Int_t nRuns=ttree->GetEntries();
416         TList lista;
417    
418         TH1F * hAvDiffTimeVsRun=new TH1F("hAvDiffTimeVsRun","hAvDiffTimeVsRun;run;<t^{TOF}-t_{exp,#pi}> (ps)",nRuns,0., nRuns);//, 600, 0. , 600.);
419         hAvDiffTimeVsRun->SetDrawOption("E1");
420         hAvDiffTimeVsRun->SetMarkerStyle(20);
421         hAvDiffTimeVsRun->SetMarkerColor(kBlue);
422         //   hAvTimeVsRun->GetYaxis()->SetRangeUser(0.0, 50.0);
423
424         TH1F * hPeakDiffTimeVsRun=new TH1F("hPeakDiffTimeVsRun","hPeakDiffTimeVsRun (gaussian fit) ;run; <t^{TOF}-t_{exp,#pi}> (ps)",nRuns,0., nRuns);//,600, 0. , 600. );
425         hPeakDiffTimeVsRun->SetDrawOption("E1");
426         hPeakDiffTimeVsRun->SetMarkerStyle(20);
427         hPeakDiffTimeVsRun->SetMarkerColor(kBlue);
428    
429         TH1F * hSpreadDiffTimeVsRun=new TH1F("hSpreadDiffTimeVsRun","hSpreadDiffTimeVsRun (gaussian fit);run; #sigma(t^{TOF}-t_{exp,#pi}) (ns)",nRuns,0., nRuns);//, 100, 0. , 100.);
430         hSpreadDiffTimeVsRun->SetDrawOption("E1");
431         hSpreadDiffTimeVsRun->SetMarkerStyle(20);
432         hSpreadDiffTimeVsRun->SetMarkerColor(kBlue);
433
434         TH1F * hAvTimeVsRun=new TH1F("hAvTimeVsRun","hAvTimeVsRun;run;<t^{TOF}> (ns)",nRuns,0., nRuns);//, 600, 0. , 600.);
435         hAvTimeVsRun->SetDrawOption("E1");
436         hAvTimeVsRun->SetMarkerStyle(20);
437         hAvTimeVsRun->SetMarkerColor(kBlue);
438         //   hAvTimeVsRun->GetYaxis()->SetRangeUser(0.0, 50.0);
439
440         TH1F * hPeakTimeVsRun=new TH1F("hPeakTimeVsRun","hPeakTimeVsRun (gaussian fit);run;t_{peak}^{TOF} (ns)",nRuns,0., nRuns);//,600, 0. , 600. );
441         hPeakTimeVsRun->SetDrawOption("E1");
442         hPeakTimeVsRun->SetMarkerStyle(20);
443         hPeakTimeVsRun->SetMarkerColor(kBlue);
444    
445         TH1F * hSpreadTimeVsRun=new TH1F("hSpreadTimeVsRun","hSpreadTimeVsRun (gaussian fit);run; #sigma(t^{TOF}) (ns)",nRuns,0., nRuns);//, 100, 0. , 100.);
446         hSpreadTimeVsRun->SetDrawOption("E1");
447         hSpreadTimeVsRun->SetMarkerStyle(20);
448         hSpreadTimeVsRun->SetMarkerColor(kBlue);
449   
450   
451         TH1F * hAvRawTimeVsRun=new TH1F("hAvRawTimeVsRun","hAvRawTimeVsRun;run;<t_{raw}^{TOF}> (ns)",nRuns,0., nRuns);//, 600, 0. , 600.);
452         hAvRawTimeVsRun->SetDrawOption("E1");
453         hAvRawTimeVsRun->SetMarkerStyle(21);
454         hAvRawTimeVsRun->SetMarkerColor(kGreen);
455
456         TH1F * hPeakRawTimeVsRun=new TH1F("hPeakRawTimeVsRun","hPeakRawTimeVsRun (gaussian fit);run;t_{peak,raw}^{TOF} (ns)",nRuns,0., nRuns);//, 600, 0. , 600.);
457         hPeakRawTimeVsRun->SetDrawOption("E1");
458         hPeakRawTimeVsRun->SetMarkerStyle(21);
459         hPeakRawTimeVsRun->SetMarkerColor(kGreen);
460
461         TH1F * hSpreadRawTimeVsRun=new TH1F("hSpreadRawTimeVsRun","hSpreadRawTimeVsRun (gaussian fit);run;#sigma(t_{raw}^{TOF}) (ns)",nRuns,0., nRuns);//, 100, 0. , 100.);
462         hSpreadRawTimeVsRun->SetDrawOption("E1");
463         hSpreadRawTimeVsRun->SetMarkerStyle(21);
464         hSpreadRawTimeVsRun->SetMarkerColor(kGreen);
465    
466         TH1F * hAvTotVsRun=new TH1F("hAvTotVsRun","hAvTotVsRun;run;<ToT> (ns)",nRuns,0., nRuns);//, 50, 0. , 50.);
467         hAvTotVsRun->SetDrawOption("E1");
468         hAvTotVsRun->SetMarkerStyle(22);
469    
470         TH1F * hPeakTotVsRun=new TH1F("hPeakTotVsRun","hPeakTotVsRun (gaussian fit);run;ToT_{peak} (ns)",nRuns,0., nRuns);//, 50, 0. , 50.);
471         hPeakTotVsRun->SetDrawOption("E1");
472         hPeakTotVsRun->SetMarkerStyle(22);
473    
474         TH1F * hSpreadTotVsRun=new TH1F("hSpreadTotVsRun","hSpreadTotVsRun (gaussian fit);#sigma(ToT) (ns)",nRuns,0., nRuns);//, 50, 0. , 50.);
475         hSpreadTotVsRun->SetDrawOption("E1");
476         hSpreadTotVsRun->SetMarkerStyle(22);
477    
478         TH1F * hNegTimeRatioVsRun=new TH1F("hNegTimeRatioVsRun","hNegTimeRatioVsRun;run;ratio of tracks with t^{TOF}<12.5 ns (%)",nRuns, 0., nRuns);//, 100, 0. , 100.);
479         hNegTimeRatioVsRun->SetDrawOption("E");
480
481         TH1F * hOrphansRatioVsRun=new TH1F("hOrphansRatioVsRun","hOrphansRatioVsRun; run; ratio of orphans (%)",nRuns, 0., nRuns);//, 1000, 0. , 100.);
482         hOrphansRatioVsRun->SetDrawOption("E");
483
484         TH1F * hMeanLVsRun=new TH1F("hMeanLVsRun","hMeanLVsRun;run; <L> (cm)",nRuns, 0., nRuns);//, 350, 350. , 700.);
485         hMeanLVsRun->SetDrawOption("E");
486         TH1F * hNegLRatioVsRun=new TH1F("hNegLRatioVsRun","hNegLRatioVsRun;run; ratio of tracks with L<350 cm (%)",nRuns, 0., nRuns);//, 1000, 0. , 100.);
487         hNegLRatioVsRun->SetDrawOption("E");
488         TH1F * hMatchEffVsRun=new TH1F("hMatchEffVsRun","hMatchEffVsRun;run;matching efficiency (pT>1.5 GeV/c)",nRuns, 0., nRuns);//, 100, 0. , 1.);
489         hMatchEffVsRun->SetDrawOption("E");
490         TH1F * hMatchEffVsRun1=new TH1F("hMatchEffVsRun1","hMatchEffVsRun;run;matching efficiency (pT>1.0 GeV/c)",nRuns, 0., nRuns);
491         hMatchEffVsRun1->SetDrawOption("E");
492         TH1F * hPeakT0AVsRun=new TH1F("hPeakT0AVsRun","hPeakT0AVsRun (gaussian fit);run;t0A (ps)",nRuns,0., nRuns);
493         TH1F * hPeakT0CVsRun=new TH1F("hPeakT0CVsRun","hPeakT0CVsRun (gaussian fit);run;t0AC (ps)",nRuns,0., nRuns);
494         TH1F * hPeakT0ACVsRun=new TH1F("hPeakT0ACVsRun","hPeakT0ACVsRun (gaussian fit);run;t0AC (ps)",nRuns,0., nRuns);
495         TH1F * hT0fillResVsRun=new TH1F("hT0fillResVsRun","hT0fillResVsRun;run;t0_spread (ps)",nRuns,0., nRuns);
496   
497         lista.Add(hAvDiffTimeVsRun);
498         lista.Add(hPeakDiffTimeVsRun);
499         lista.Add(hSpreadDiffTimeVsRun);
500         lista.Add(hAvTimeVsRun);
501         lista.Add(hPeakTimeVsRun);
502         lista.Add(hSpreadTimeVsRun);
503         lista.Add(  hAvRawTimeVsRun);
504         lista.Add(  hPeakRawTimeVsRun);
505         lista.Add(  hSpreadRawTimeVsRun); 
506         lista.Add(  hAvTotVsRun);
507         lista.Add(  hPeakTotVsRun);
508         lista.Add(  hSpreadTotVsRun);
509         lista.Add(  hNegTimeRatioVsRun);
510         lista.Add(  hOrphansRatioVsRun);
511         lista.Add( hMeanLVsRun);
512         lista.Add(  hNegLRatioVsRun);
513         lista.Add(  hMatchEffVsRun);
514         lista.Add(hPeakT0AVsRun);
515         lista.Add(hPeakT0CVsRun);
516         lista.Add(hPeakT0ACVsRun);
517         lista.Add(hT0fillResVsRun);
518         char runlabel[6];
519    
520         for (Int_t irun=0;irun<nRuns;irun++){
521                 ttree->GetEntry(irun);
522     
523                 sprintf(runlabel,"%i",runNumber);
524     
525                 hAvDiffTimeVsRun->SetBinContent(irun+1, avDiffTime);
526                 hAvDiffTimeVsRun->GetXaxis()->SetBinLabel(irun+1,runlabel);
527
528                 hPeakDiffTimeVsRun->SetBinContent(irun+1,peakDiffTime);
529                 hPeakDiffTimeVsRun->SetBinError(irun+1,peakDiffTimeErr);
530                 hPeakDiffTimeVsRun->GetXaxis()->SetBinLabel(irun+1,runlabel);
531
532                 hSpreadDiffTimeVsRun->SetBinContent(irun+1,spreadDiffTime);
533                 hSpreadDiffTimeVsRun->SetBinError(irun+1,spreadDiffTimeErr);
534                 hSpreadDiffTimeVsRun->GetXaxis()->SetBinLabel(irun+1,runlabel);
535
536                 hAvTimeVsRun->SetBinContent(irun+1, avTime);
537                 hAvTimeVsRun->GetXaxis()->SetBinLabel(irun+1,runlabel);
538
539                 hPeakTimeVsRun->SetBinContent(irun+1,peakTime);
540                 hPeakTimeVsRun->SetBinError(irun+1,peakTimeErr);
541                 hPeakTimeVsRun->GetXaxis()->SetBinLabel(irun+1,runlabel);
542
543                 hSpreadTimeVsRun->SetBinContent(irun+1,spreadTime);
544                 hSpreadTimeVsRun->SetBinError(irun+1,spreadTimeErr);
545                 hSpreadTimeVsRun->GetXaxis()->SetBinLabel(irun+1,runlabel);
546
547                 hAvRawTimeVsRun->SetBinContent(irun+1, avRawTime);
548                 hAvRawTimeVsRun->GetXaxis()->SetBinLabel(irun+1,runlabel);
549     
550                 hPeakRawTimeVsRun->SetBinContent(irun+1,peakRawTime);
551                 hPeakRawTimeVsRun->SetBinError(irun+1,peakRawTimeErr);
552                 hPeakRawTimeVsRun->GetXaxis()->SetBinLabel(irun+1,runlabel);
553
554                 hSpreadRawTimeVsRun->SetBinContent(irun+1,spreadRawTime);
555                 hSpreadRawTimeVsRun->SetBinError(irun+1,spreadRawTimeErr);
556                 hSpreadRawTimeVsRun->GetXaxis()->SetBinLabel(irun+1,runlabel);
557
558                 hAvTotVsRun->SetBinContent(irun,avTot);
559                 hAvTotVsRun->GetXaxis()->SetBinLabel(irun+1,runlabel);
560
561                 hPeakTotVsRun->SetBinContent(irun,peakTot);
562                 hPeakTotVsRun->SetBinError(irun+1,peakTotErr);
563                 hPeakTotVsRun->GetXaxis()->SetBinLabel(irun+1,runlabel);
564
565                 hSpreadTotVsRun->SetBinContent(irun,spreadTot);
566                 hSpreadTotVsRun->SetBinError(irun+1,spreadTotErr);
567                 hSpreadTotVsRun->GetXaxis()->SetBinLabel(irun+1,runlabel);
568     
569                 hNegTimeRatioVsRun->SetBinContent(irun,negTimeRatio);
570                 hNegTimeRatioVsRun->GetXaxis()->SetBinLabel(irun+1,runlabel);
571     
572                 hOrphansRatioVsRun->SetBinContent(irun,orphansRatio);
573                 hOrphansRatioVsRun->GetXaxis()->SetBinLabel(irun+1,runlabel);
574     
575                 hMeanLVsRun->SetBinContent(irun,avL);
576                 hMeanLVsRun->GetXaxis()->SetBinLabel(irun+1,runlabel);
577     
578                 hNegLRatioVsRun->SetBinContent(irun,negLratio);
579                 hNegLRatioVsRun->GetXaxis()->SetBinLabel(irun+1,runlabel);
580
581                 hMatchEffVsRun->SetBinContent(irun,matchEffLinFit1Gev);
582                 hMatchEffVsRun->SetBinError(irun+1,matchEffLinFit1GevErr);
583                 hMatchEffVsRun->GetXaxis()->SetBinLabel(irun+1,runlabel);
584
585                 hPeakT0AVsRun->SetBinContent(irun+1,peakT0A);
586                 hPeakT0AVsRun->SetBinError(irun+1,spreadT0A);
587                 hPeakT0AVsRun->GetXaxis()->SetBinLabel(irun+1,runlabel);
588
589                 hPeakT0CVsRun->SetBinContent(irun+1,peakT0C);
590                 hPeakT0CVsRun->SetBinError(irun+1,spreadT0C);
591                 hPeakT0CVsRun->GetXaxis()->SetBinLabel(irun+1,runlabel);
592     
593                 hPeakT0ACVsRun->SetBinContent(irun+1,peakT0AC);
594                 hPeakT0ACVsRun->SetBinError(irun+1,spreadT0AC);
595                 hPeakT0ACVsRun->GetXaxis()->SetBinLabel(irun+1,runlabel);
596
597                 hT0fillResVsRun->SetBinContent(irun+1,avT0fillRes);
598                 hT0fillResVsRun->GetXaxis()->SetBinLabel(irun+1,runlabel);
599
600         }
601   
602         char  outfilename[200];
603         sprintf(outfilename, "trend_%s",trendFileName);
604         TFile * fout=new TFile(outfilename,"recreate");
605         fout->cd();
606         lista.Write();
607         fout->Close();
608
609         TString plotDir(Form("PlotsTrending"));
610         gSystem->Exec(Form("mkdir %s",plotDir.Data()));
611
612         TCanvas* cAvDiffTimeVsRun = new TCanvas("cAvDiffTimeVsRun","cAvDiffTimeVsRun",50,50,750,550);
613         gPad->SetGridx();
614         gPad->SetGridy();
615         hAvDiffTimeVsRun->Draw();
616         cAvDiffTimeVsRun->Print(Form("%s/cAvDiffTimeVsRun.png",plotDir.Data()));
617
618         TCanvas* cPeakDiffTimeVsRun = new TCanvas("cPeakDiffTimeVsRun","cPeakDiffTimeVsRun", 50,50,750,550);
619         hPeakDiffTimeVsRun->Draw();
620         cPeakDiffTimeVsRun->Print(Form("%s/cPeakDiffTimeVsRun",plotDir.Data()));
621
622         TCanvas* cSpreadDiffTimeVsRun = new TCanvas("cSpreadDiffTimeVsRun","cSpreadDiffTimeVsRun", 50,50,750,550);
623         hSpreadDiffTimeVsRun->Draw();
624         cSpreadDiffTimeVsRun->Print(Form("%s/cSpreadDiffTimeVsRun",plotDir.Data()));
625
626         TCanvas* cAvTimeVsRun = new TCanvas("cAvTimeVsRun","cAvTimeVsRun", 50,50,750,550);
627         hAvTimeVsRun->Draw();
628         cAvTimeVsRun->Print(Form("%s/cAvTimeVsRun",plotDir.Data()));
629
630         TCanvas* cPeakTimeVsRun = new TCanvas("cPeakTimeVsRun","cPeakTimeVsRun", 50,50,750,550);
631         hPeakTimeVsRun->Draw();
632         cPeakTimeVsRun->Print(Form("%s/cPeakTimeVsRun",plotDir.Data()));
633
634         TCanvas* cSpreadTimeVsRun = new TCanvas("cSpreadTimeVsRun","cSpreadTimeVsRun", 50,50,750,550);
635         hSpreadTimeVsRun->Draw();
636         cSpreadTimeVsRun->Print(Form("%s/cSpreadTimeVsRun",plotDir.Data()));
637
638         TCanvas* cAvRawTimeVsRun = new TCanvas("cAvRawTimeVsRun","cAvRawTimeVsRun", 50,50,750,550);
639         hAvRawTimeVsRun->Draw();
640         cAvRawTimeVsRun->Print(Form("%s/cAvRawTimeVsRun",plotDir.Data()));
641
642         TCanvas* cPeakRawTimeVsRun = new TCanvas("cPeakRawTimeVsRun","cPeakRawTimeVsRun", 50,50,750,550);
643         hPeakRawTimeVsRun->Draw();
644         cPeakRawTimeVsRun->Print(Form("%s/cPeakRawTimeVsRun",plotDir.Data()));
645
646         TCanvas* cSpreadRawTimeVsRun = new TCanvas("cSpreadRawTimeVsRun","cSpreadRawTimeVsRun", 50,50,750,550);
647         hSpreadRawTimeVsRun->Draw();
648         cSpreadRawTimeVsRun->Print(Form("%s/cSpreadRawTimeVsRun",plotDir.Data()));
649
650         TCanvas* cAvTotVsRun = new TCanvas("cAvTotVsRun","cAvTotVsRun", 50,50,750,550);
651         hAvTotVsRun->Draw();
652         cAvTotVsRun->Print(Form("%s/cAvTotVsRun",plotDir.Data()));
653
654         TCanvas* cPeakTotVsRun = new TCanvas("cPeakTotVsRun","cPeakTotVsRun", 50,50,750,550);
655         hPeakTotVsRun->Draw();
656         cPeakTotVsRun->Print(Form("%s/cPeakTotVsRun",plotDir.Data()));
657
658         TCanvas* cSpreadTotVsRun = new TCanvas("cSpreadTotVsRun","cSpreadTotVsRun", 50,50,750,550);
659         hSpreadTotVsRun->Draw();
660         cSpreadTotVsRun->Print(Form("%s/cSpreadTotVsRun",plotDir.Data()));
661
662         TCanvas* cNegTimeRatioVsRun = new TCanvas("cNegTimeRatioVsRun","cNegTimeRatioVsRun", 50,50,750,550);
663         hNegTimeRatioVsRun->Draw();
664         cNegTimeRatioVsRun->Print(Form("%s/cNegTimeRatioVsRun",plotDir.Data()));
665
666         TCanvas* cOrphansRatioVsRun = new TCanvas("cOrphansRatioVsRun","cOrphansRatioVsRun", 50,50,750,550);
667         hOrphansRatioVsRun->Draw();
668         cOrphansRatioVsRun->Print(Form("%s/cOrphansRatioVsRun",plotDir.Data()));
669
670         TCanvas* cMeanLVsRun = new TCanvas("cMeanLVsRun","cMeanLVsRun", 50,50,750,550);
671         hMeanLVsRun->Draw();
672         cMeanLVsRun->Print(Form("%s/cMeanLVsRun",plotDir.Data()));
673
674         TCanvas* cNegLRatioVsRun = new TCanvas("cNegLRatioVsRun","cNegLRatioVsRun", 50,50,750,550);
675         hNegLRatioVsRun->Draw();
676         cNegLRatioVsRun->Print(Form("%s/cNegLRatioVsRun",plotDir.Data()));
677
678         TCanvas* cMatchEffVsRun = new TCanvas("cMatchEffVsRun","cMatchEffVsRun", 50,50,750,550);
679         hMatchEffVsRun->Draw();
680         cMatchEffVsRun->Print(Form("%s/cMatchEffVsRun",plotDir.Data()));
681
682         TCanvas* cPeakT0AVsRun = new TCanvas("cPeakT0AVsRun","cPeakT0AVsRun", 50,50,750,550);
683         hPeakT0AVsRun->Draw();
684         cPeakT0AVsRun->Print(Form("%s/cPeakT0AVsRun.png",plotDir.Data()));
685
686         TCanvas* cPeakT0CVsRun = new TCanvas("cPeakT0CVsRun","cPeakT0CVsRun", 50,50,750,550);
687         hPeakT0CVsRun->Draw();
688         cPeakT0CVsRun->Print(Form("%s/cPeakT0CVsRun.png",plotDir.Data()));
689
690         TCanvas* cPeakT0ACVsRun = new TCanvas("cPeakT0ACVsRun","cPeakT0ACVsRun", 50,50,750,550);
691         hPeakT0ACVsRun->Draw();
692         cPeakT0ACVsRun->Print(Form("%s/cPeakT0ACVsRun.png",plotDir.Data()));
693
694         TCanvas* cT0fillResVsRun = new TCanvas("cT0fillResVsRun","cT0fillResVsRun", 50,50,750,550);
695         hT0fillResVsRun->Draw();
696         cT0fillResVsRun->Print(Form("%s/cT0fillResVsRun.png",plotDir.Data()));
697
698
699         return 0;
700 }
701
702 //------------------------------------------------------------------------------------
703
704 Int_t RunESDQApostAnalysis(char *qafilename=NULL, Int_t runNumber=-1, Bool_t IsOnGrid=kFALSE, Bool_t canvasE=kFALSE) {
705   
706         Bool_t debug=kFALSE;
707   
708         /*access qa PWG1 output files - saved locally or on grid as specified by the second argument */
709   
710         char defaultQAoutput[30]="QAresults.root";
711         if (IsOnGrid) TGrid::Connect("alien://");
712         TFile * fin= TFile::Open(qafilename,"r");
713         printf("Opening file %s\n",qafilename);
714         if (!fin) {
715                 printf("ERROR: QA output not found. Exiting with status -1\n");
716                 return -1;
717         } else {
718                 printf("INFO: QA output file %s open. \n",fin->GetName());
719         }
720   
721  
722         //access histograms lists
723         char tofQAdirName[15]="TOF_Performance";
724         char genListName[15]="cGeneralTOFqa";
725         char t0ListName[15]="cTimeZeroTOFqa";
726         char pidListName[15]="cPIDTOFqa"; 
727         char posListName[15]="cPositiveTOFqa";
728         char negListName[15]="cNegativeTOFqa";
729   
730         TDirectoryFile * tofQAdir=(TDirectoryFile*)fin->Get(tofQAdirName);
731         if(debug){
732                 printf("------------------------------------------------------------------\n");
733                 tofQAdir->ls();
734                 printf("------------------------------------------------------------------\n");
735         }
736   
737         TList * generalList=(TList*)tofQAdir->Get(genListName);
738         TList  *timeZeroList=(TList*)tofQAdir->Get(t0ListName);
739         TList  *pidList=(TList*)tofQAdir->Get(pidListName);
740         TList  *posList=(TList*)tofQAdir->Get(posListName);
741         TList  *negList=(TList*)tofQAdir->Get(negListName);
742
743         if (!generalList) printf("WARNING: general QA histograms absent or not accessible\n");
744         if (!timeZeroList) printf("WARNING: timeZero QA histograms absent or not accessible\n");
745         if (!pidList) printf("WARNING: PID QA histograms absent or not accessible\n");
746         if (!posList) printf("WARNING: general QA histograms for positive tracks absent or not accessible\n");
747         if (!negList) printf("WARNING: general QA histograms for negative tracks absent or not accessible\n");
748
749         if ( (!generalList) && (!timeZeroList) && (!pidList) ){
750                 printf("ERROR: no QA available \n");
751                 return 1;
752         }
753   
754         if (debug){
755                 generalList->ls();
756                 printf("------------------------------------------------------------------\n");
757                 timeZeroList->ls();
758                 printf("------------------------------------------------------------------\n");
759                 pidList->ls();
760                 printf("------------------------------------------------------------------\n");
761         }
762
763         /*set graphic style*/
764         gStyle->SetCanvasColor(kWhite);
765         gStyle->SetFrameFillColor(kWhite);
766         gStyle->SetFrameBorderMode(0);
767         gStyle->SetCanvasBorderMode(0);
768         gStyle->SetTitleFillColor(kWhite);
769         gStyle->SetTitleBorderSize(0)  ;
770         gStyle->SetTitleFont(42);
771         gStyle->SetTextFont(42);
772         //gStyle->SetPalette(1);
773         gStyle->SetStatColor(kWhite); 
774         gStyle->SetStatBorderSize(1);
775         gStyle->SetOptStat(0);
776   
777         //DEFINE OUTPUT FILE 
778         char outfilename[60];
779         sprintf(outfilename,"postQA_%i.root",runNumber);
780         TFile * fout=new TFile(outfilename,"recreate");
781
782         TH1I* hRunNumber=new TH1I("hRunNumber","hRunNumber;run",1,runNumber,runNumber+1);
783         hRunNumber->Fill(runNumber);
784
785         //-------------------------------------------------------------
786         /*GENERAL MONITOR - MULTIPLICITY*/
787         TH1F*hMulti= (TH1F*) generalList->At(0);
788
789         TH1F* hFractionEventsWhits=new TH1F("hFractionEventsWhits","hFractionEventsWhits;fraction of events with hits (%)",200,0.,100.);
790         Float_t fraction=0.0;
791         if (hMulti->GetEntries()>0.0) fraction=((Float_t) hMulti->GetBinContent(1))/((Float_t) hMulti->GetEntries());
792         else fraction=0.0;
793         hFractionEventsWhits->Fill(fraction*100.);
794
795         //-------------------------------------------------------------
796         /*GENERAL MONITOR - TIMING AND GEOMETRY*/
797         TH1F * hTime = (TH1F*) generalList->At(1);
798         hTime->SetMarkerStyle(8);
799         hTime->SetMarkerSize(0.7);
800         hTime->SetMarkerColor(kBlue);
801         hTime->SetLineColor(kBlue);
802         hTime->SetFillColor(kBlue);
803         hTime->SetFillStyle(3001);
804         hTime->Rebin(2);
805         hTime->GetYaxis()->SetTitle("matched tracks"); 
806         hTime->GetYaxis()->SetTitleOffset(1.35);
807   
808         TH1F * hRawTime = (TH1F*) generalList->At(2);
809         hRawTime->SetMarkerStyle(21);
810         hRawTime->SetMarkerSize(0.7);
811         hRawTime->SetMarkerColor(kGreen);
812         hRawTime->SetLineColor(kGreen);
813         hRawTime->SetFillColor(kGreen);
814         hRawTime->SetFillStyle(3001); 
815         hRawTime->Rebin(2);
816         hRawTime->GetYaxis()->SetTitle("matched tracks");
817         hRawTime->GetYaxis()->SetTitleOffset(1.35);
818   
819         TLegend *lTime = new TLegend(0.7125881,0.6052519,0.979435,0.7408306,NULL,"brNDC");
820         lTime->SetTextSize(0.04281433);
821         lTime->AddEntry(hRawTime, "raw","L");
822         lTime->AddEntry(hTime, "ESD","L"); 
823         lTime->SetFillColor(kWhite);
824         lTime->SetShadowColor(0);
825
826         TH1F * hTot = (TH1F*) generalList->At(3);
827         hTot->SetMarkerStyle(8);
828         hTot->SetMarkerSize(0.7);
829         hTot->SetMarkerColor(kViolet-3);
830         hTot->SetLineColor(kViolet-3);
831         hTot->SetFillColor(kViolet-3);
832         hTot->SetFillStyle(3001);
833         //hTime->SetDrawOption();
834         hTot->GetYaxis()->SetTitle("matched tracks");
835         hTot->GetYaxis()->SetTitleOffset(1.35);
836   
837   
838         char orphansTxt[200];
839         Float_t orphansRatio=0.0;
840         if (hTot->GetEntries()>1){
841                 orphansRatio=((Float_t) hTot->GetBinContent(1))/((Float_t) hTot->GetEntries()) ;
842         }
843         sprintf(orphansTxt,"orphans/matched tracks = %.4f ",orphansRatio);
844         TH1F * hOrphansRatio=new TH1F("hOrphansRatio","Percentage of signals with only leading edge; percentage (%)",1000,0.,100.);
845         hOrphansRatio->Fill(orphansRatio*100.);  
846
847
848         TPaveText *tOrphans = new TPaveText(0.38,0.63,0.88,0.7, "NDC");
849         //NDC sets coords relative to pad
850         tOrphans->SetBorderSize(0);
851         tOrphans->SetTextSize(0.045);
852         tOrphans->SetFillColor(0); //white background
853         tOrphans->SetTextAlign(12);
854         tOrphans->SetTextColor(kViolet-3);
855         tOrphans->AddText(orphansTxt);
856       
857         TH1F * hL = (TH1F*) generalList->At(4);
858         hL->SetMarkerStyle(8);
859         hL->SetMarkerSize(0.7);
860         hL->SetMarkerColor(kOrange-3);
861         hL->SetLineColor(kOrange-3);
862         hL->SetFillColor(kOrange-3);
863         hL->SetFillStyle(3001);
864         //hTime->SetDrawOption();
865         hL->GetYaxis()->SetTitle("matched tracks");
866         hL->GetYaxis()->SetTitleOffset(1.35);
867
868         char negLengthTxt[200];
869         Float_t negLengthRatio=0.0;
870         if (hL->GetEntries()>1){
871                 negLengthRatio=(hL->Integral(1,750))/((Float_t) hL->GetEntries()) ;
872         }
873         sprintf(negLengthTxt,"tracks with L<350cm /matched tracks = %.5f ",negLengthRatio);
874         TH1F * hLnegRatio=new TH1F("hLnegRatio","Ratio of TOF-matched tracks with L<350cm; ratio (%)",10000,0.,100.);
875         hLnegRatio->Fill(negLengthRatio*100);
876   
877
878
879         TPaveText *tLength = new TPaveText(0.15,0.83,0.65,0.87, "NDC");
880         //NDC sets coords relative to pad
881         tLength->SetBorderSize(0);
882         tLength->SetTextSize(0.04);
883         tLength->SetFillColor(0); //white background
884         tLength->SetTextAlign(11);
885         tLength->SetTextColor(kOrange-3);
886         tLength->AddText(negLengthTxt);
887  
888         if (canvasE){
889                 TCanvas *cTrackProperties= new TCanvas("cTrackProperties","summary of matched tracks properties",900,900);
890                 cTrackProperties->Divide(2,2);
891                 cTrackProperties->cd(1);
892                 gPad->SetLogy();
893                 gPad->SetGridx();
894                 gPad->SetGridy();
895                 hTime->Draw("BAR");
896                 hRawTime ->Draw("BARsame");
897                 lTime->Draw();  
898                 cTrackProperties->cd(2);
899                 gPad->SetGridx();
900                 gPad->SetGridy();
901                 gPad->SetLogy();
902                 hTot->Draw("BAR");
903                 tOrphans->Draw(); 
904                 cTrackProperties->cd(3);
905                 gPad->SetGridx();
906                 gPad->SetGridy();
907                 gPad->SetLogy();
908                 hL->Draw("BAR");
909                 tLength->Draw(); 
910         }
911         fout->cd();
912         hRunNumber->Write();
913         hMulti->Write();
914         hFractionEventsWhits->Write();
915         hTime->Write();
916         hRawTime->Write();
917         hTot->Write();
918         hOrphansRatio->Write();
919         hL->Write();
920         hLnegRatio->Write();
921   
922         TH2F* hDxPos4profile = (TH2F*) generalList->At(14);
923         TH2F* hDxNeg4profile = (TH2F*) generalList->At(13);
924     
925         char profilename[30];
926         const Int_t ybinMin = 0;
927         const Int_t ybinMax =hDxPos4profile->GetYaxis()->GetNbins() ;
928         sprintf(profilename,"profDxPos");
929         TProfile * profDxPos = (TProfile*)hDxPos4profile->ProfileX(profilename, ybinMin,ybinMax); 
930         sprintf(profilename,"profDxNeg");
931         profDxPos->SetLineWidth(2);
932         TProfile * profDxNeg = (TProfile*)hDxNeg4profile->ProfileX(profilename, ybinMin, ybinMax); 
933         profDxNeg->SetLineWidth(2);  
934  
935         TH1 *profRatioPosOverNegDx = (TH1*) profDxPos->Clone();
936         profRatioPosOverNegDx->SetName("profRatioPosOverNegDx");
937         profRatioPosOverNegDx->Divide((TH1*) profDxNeg);
938         profRatioPosOverNegDx->GetYaxis()->SetRangeUser(-5.,5.);
939         profRatioPosOverNegDx->GetXaxis()->SetRangeUser(0.,2.);
940         if (canvasE){
941                 TCanvas *residuals= new TCanvas("residuals","residuals",900,450);
942                 residuals->Divide(2,1);
943                 residuals->cd(1);
944                 gPad->SetGridx();
945                 gPad->SetGridy();
946                 hDxPos4profile->GetYaxis()->SetRangeUser(-5.,5.);
947                 hDxPos4profile->Draw("colz");
948                 profDxPos->SetLineColor(kRed);
949                 profDxPos ->Draw("same");
950                 residuals->cd(2);
951                 gPad->SetGridx();
952                 gPad->SetGridy();
953                 hDxNeg4profile->GetYaxis()->SetRangeUser(-5.,5.); 
954                 hDxNeg4profile->Draw("colz");
955                 profDxNeg->SetLineColor(kBlue);
956                 profDxNeg->Draw("same"); 
957         }
958
959         fout->cd();
960         hDxPos4profile->Write();
961         hDxNeg4profile->Write();
962         profDxPos->Write();
963         profDxNeg->Write();
964         profRatioPosOverNegDx->Write();
965         //-------------------------------------------------------------
966         /* T0 DETECTOR MONITOR*/
967
968         TH1F * hT0AC = (TH1F*) timeZeroList->At(0);
969         hT0AC->SetMarkerStyle(8);
970         hT0AC->SetMarkerSize(0.7);
971         hT0AC->SetMarkerColor(kRed);
972         hT0AC->SetLineColor(kRed);
973         hT0AC->SetFillColor(kRed);
974         hT0AC->SetFillStyle(1001);
975         hT0AC->Rebin(2);
976         hT0AC->GetYaxis()->SetTitle("events"); 
977         hT0AC->GetYaxis()->SetTitleOffset(1.35);
978         hT0AC->GetXaxis()->SetLabelSize(0.03);
979  
980         TH1F * hT0A = (TH1F*) timeZeroList->At(1);
981         hT0A->SetMarkerStyle(8);
982         hT0A->SetMarkerSize(0.7);
983         hT0A->SetMarkerColor(kBlue);
984         hT0A->SetLineColor(kBlue);
985         hT0A->SetFillColor(kBlue);
986         hT0A->SetFillStyle(1001);
987         hT0A->Rebin(2);
988         hT0A->GetYaxis()->SetTitle("events"); 
989         hT0A->GetYaxis()->SetTitleOffset(1.35);
990         hT0A->GetXaxis()->SetLabelSize(0.03);
991
992         TH1F * hT0C = (TH1F*) timeZeroList->At(2);
993         hT0C->SetMarkerStyle(8);
994         hT0C->SetMarkerSize(0.7);
995         hT0C->SetMarkerColor(kGreen);
996         hT0C->SetLineColor(kGreen);
997         hT0C->SetFillColor(kGreen);
998         hT0C->SetFillStyle(1001);
999         hT0C->Rebin(2);
1000         hT0C->GetYaxis()->SetTitle("events"); 
1001         hT0C->GetYaxis()->SetTitleOffset(1.35);
1002         hT0C->GetXaxis()->SetLabelSize(0.03);
1003  
1004         TLegend *lT0 = new TLegend(0.7125881,0.6052519,0.979435,0.7408306,NULL,"brNDC");
1005         lT0->SetTextSize(0.041);
1006         lT0->AddEntry(hT0AC, "T0 A&C","L");
1007         lT0->AddEntry(hT0A, "T0 A","L"); 
1008         lT0->AddEntry(hT0C, "T0 C","L");
1009         lT0->SetFillColor(kWhite);
1010         lT0->SetShadowColor(0);
1011   
1012         TH1F * hT0res = (TH1F*) timeZeroList->At(3);
1013         hT0res->GetXaxis()->SetLabelSize(0.03);
1014         if (canvasE){
1015                 TCanvas *cT0detector= new TCanvas("cT0detector","T0 detector",900,450);
1016                 cT0detector->Divide(2,1);
1017                 cT0detector->cd(1);
1018                 gPad->SetGridx();
1019                 gPad->SetGridy();
1020                 hT0AC->Draw("BAR");
1021                 hT0AC->SetTitle("timeZero measured by T0 detector");
1022                 hT0A ->Draw("BARsame");
1023                 hT0C ->Draw("BARsame");
1024                 lT0->Draw();  
1025                 cT0detector->cd(2);
1026                 gPad->SetGridx();
1027                 gPad->SetGridy();
1028                 // gPad->SetLogy();
1029                 hT0res->Draw();
1030                 // myText1->Draw(); 
1031                 // cTrackProperties->cd(3);
1032                 // gPad->SetLogy();
1033                 // hL->Draw("BAR");
1034                 // myText2->Draw(); 
1035         }
1036
1037         TH1F * hT0fillRes = (TH1F*) timeZeroList->At(8);
1038         hT0fillRes->GetXaxis()->SetLabelSize(0.03);
1039
1040         fout->cd();
1041         hT0AC->Write();
1042         hT0A->Write();
1043         hT0C->Write();
1044         hT0res->Write();
1045         hT0fillRes->Write();
1046         lT0->Write();
1047   
1048
1049         //-------------------------------------------------------------
1050         /*MATCHING EFFICIENCY  MONITOR*/
1051
1052         //TH1F * hMatchingVsP =new TH1F("hMatchingVsP","Matching probability vs. P; P(GeV/c); matching probability", 50, 0., 5. );
1053   
1054         TH1F * hMatchingVsPt =new TH1F("hMatchingVsPt","Matching probability vs. Pt; Pt(GeV/c); matching probability", 50, 0., 5. );
1055   
1056         TH1F * hMatchingVsEta =new TH1F("hMatchingVsEta","Matching probability vs. #\Eta; #\Eta; matching probability", 20, -1., 1.);
1057   
1058         TH1F * hMatchingVsPhi =new TH1F("hMatchingVsPhi","Matching probability vs. Phi; Phi(rad); matching probability", 628, 0., 6.28);
1059   
1060         /*/matching as function of p
1061           TH1F * hDenom=(TH1F*)generalList->At(9); 
1062           if (hDenom) {  
1063           hMatchingVsP=(TH1F*) generalList->At(5); 
1064           hMatchingVsP->Rebin(5);
1065           hDenom->Rebin(5);
1066           hMatchingVsP->Divide(hDenom);
1067           hMatchingVsP->GetYaxis()->SetTitle("matching efficiency");
1068           hMatchingVsP->SetTitle("TOF matching efficiency as function of momentum");
1069           }*/
1070   
1071         //matching as function of pT
1072   
1073         // hDenom->Clear();
1074         TH1F * hDenom=(TH1F*)generalList->At(10); 
1075         if (hDenom) {  
1076                 hMatchingVsPt=(TH1F*) generalList->At(6); 
1077                 hMatchingVsPt->Rebin(5);
1078                 hDenom->Rebin(5);
1079                 hMatchingVsPt->Divide(hDenom);
1080                 hMatchingVsPt->GetYaxis()->SetTitle("matching efficiency");
1081                 hMatchingVsPt->SetTitle("TOF matching efficiency as function of transverse momentum");
1082                 hMatchingVsPt->GetYaxis()->SetRangeUser(0,1.2); 
1083         }
1084   
1085         //matching as function of eta
1086         hDenom->Clear();
1087         hDenom=(TH1F*)generalList->At(11); 
1088         if (hDenom) {  
1089                 hMatchingVsEta=(TH1F*) generalList->At(7); 
1090                 hMatchingVsEta->Rebin(5);
1091                 hDenom->Rebin(5);
1092                 hMatchingVsEta->Divide(hDenom);
1093                 hMatchingVsEta->GetXaxis()->SetRangeUser(-1,1);
1094                 hMatchingVsEta->GetYaxis()->SetTitle("matching efficiency");
1095                 hMatchingVsEta->GetYaxis()->SetRangeUser(0,1.2);
1096                 hMatchingVsEta->SetTitle("TOF matching efficiency as function of pseudorapidity");
1097         }
1098         //matching as function of phi
1099         hDenom->Clear();
1100         hDenom=(TH1F*)generalList->At(12); 
1101         if (hDenom) {  
1102                 hMatchingVsPhi=(TH1F*) generalList->At(8); 
1103                 //hMatchingVsPhi->Rebin(5);
1104                 //hDenom->Rebin(5);
1105                 hMatchingVsPhi->Divide(hDenom);
1106                 hMatchingVsPhi->GetYaxis()->SetTitle("matching efficiency");
1107                 hMatchingVsPhi->SetTitle("TOF matching efficiency as function of phi");
1108                 hMatchingVsPhi->GetYaxis()->SetRangeUser(0,1.2);
1109         }
1110         if (  canvasE){
1111                 TCanvas *cMatchingPerformance= new TCanvas("cMatchingPerformance","summary of matching performance",700,400);
1112                 cMatchingPerformance->Divide(2,2);
1113                 cMatchingPerformance->cd(1);
1114                 gPad->SetGridx();
1115                 gPad->SetGridy();
1116                 hMatchingVsPt->Draw();
1117                 cMatchingPerformance->cd(2);
1118                 gPad->SetGridx();
1119                 gPad->SetGridy();
1120                 hMatchingVsEta->Draw();
1121                 cMatchingPerformance->cd(3);
1122                 gPad->SetGridx();
1123                 gPad->SetGridy();
1124                 hMatchingVsPhi->Draw();
1125         }
1126         fout->cd();
1127         hMatchingVsPt->Write();
1128         hMatchingVsEta->Write();
1129         hMatchingVsPhi->Write();
1130   
1131         //----------------------------------------------------
1132         /* PID PERFORMANCE MONITOR */
1133
1134         TH2F * hBetaP=(TH2F*)pidList->At(0);
1135         hBetaP->GetYaxis()->SetRangeUser(0.,1.2);
1136         TH1F * hMass=(TH1F*)pidList->At(1);
1137         //hMass->SetMarkerColor(kBlue);
1138         //hMass->SetLineColor(kBlue);
1139         hMass->SetFillColor(kAzure+10);
1140         hMass->SetFillStyle(1001);
1141         hMass->Rebin(2);
1142         hMass->GetYaxis()->SetTitle("tracks"); 
1143         hMass->GetYaxis()->SetTitleOffset(1.35);
1144         hMass->GetXaxis()->SetLabelSize(0.03);
1145
1146         TH1F * hPionDiff=(TH1F*)pidList->At(3); 
1147   
1148
1149         TH2F * hDiffTimePi=(TH2F*)pidList->At(4); 
1150         hDiffTimePi->GetYaxis()->SetRangeUser(-2000.,2000.);
1151         //hDiffTime->GetYaxis()->Rebin(2);//1 bin=10 ps
1152         sprintf(profilename,"profDiffTimePi");
1153  
1154         TProfile * profDiffTimePi = (TProfile*)hDiffTimePi->ProfileX(profilename, 490, 510); 
1155         profDiffTimePi->SetLineWidth(2);
1156         profDiffTimePi->SetLineColor(kRed+2); 
1157
1158         TH2F * hDiffTimePiTh=(TH2F*)pidList->At(6); 
1159         //hDiffTime->GetYaxis()->Rebin(2);//1 bin=10 ps
1160         sprintf(profilename,"profDiffTimePiTh");
1161         hDiffTimePiTh->GetYaxis()->SetRangeUser(-2000.,2000.); 
1162   
1163         TProfile * profDiffTimePiTh = (TProfile*)hDiffTimePiTh->ProfileX(profilename, 490, 510);
1164         profDiffTimePiTh->SetLineWidth(2);
1165         profDiffTimePiTh->SetLineColor(kRed+2);
1166
1167         TH2F * hDiffTimeKa=(TH2F*)pidList->At(9); 
1168         //hDiffTime->GetYaxis()->Rebin(2);//1 bin=10 ps
1169         sprintf(profilename,"profDiffTimeKa");
1170         hDiffTimeKa->GetYaxis()->SetRangeUser(-2000.,2000.);
1171   
1172         TProfile * profDiffTimeKa = (TProfile*)hDiffTimeKa->ProfileX(profilename, 490, 510); 
1173         profDiffTimeKa->SetLineWidth(2);
1174         profDiffTimeKa->SetLineColor(kBlue);  
1175
1176         TH2F * hDiffTimeKaTh=(TH2F*)pidList->At(11); 
1177         //hDiffTime->GetYaxis()->Rebin(2);//1 bin=10 ps
1178         sprintf(profilename,"profDiffTimeKaTh");
1179         hDiffTimeKaTh->GetYaxis()->SetRangeUser(-2000.,2000.);
1180         TProfile * profDiffTimeKaTh = (TProfile*)hDiffTimeKaTh->ProfileX(profilename, 490, 510); 
1181         profDiffTimeKaTh->SetLineWidth(2);
1182         profDiffTimeKaTh->SetLineColor(kBlue);
1183   
1184         TH2F * hDiffTimePro=(TH2F*)pidList->At(14); 
1185         //hDiffTime->GetYaxis()->Rebin(2);//1 bin=10 ps
1186         sprintf(profilename,"profDiffTimePro");
1187         hDiffTimePro->GetYaxis()->SetRangeUser(-2000.,2000.);
1188         TProfile * profDiffTimePro = (TProfile*)hDiffTimePro->ProfileX(profilename, 490, 510); 
1189         profDiffTimePro->SetLineWidth(2);
1190         profDiffTimePro->SetLineColor(kGreen+2);  
1191
1192         TH2F * hDiffTimeProTh=(TH2F*)pidList->At(16); 
1193         //hDiffTime->GetYaxis()->Rebin(2);//1 bin=10 ps
1194         sprintf(profilename,"profDiffTimeProTh");
1195         hDiffTimeProTh->GetYaxis()->SetRangeUser(-2000.,2000.);
1196         TProfile * profDiffTimeProTh = (TProfile*)hDiffTimeProTh->ProfileX(profilename, 490, 510);
1197         profDiffTimeProTh->SetLineWidth(2);
1198         profDiffTimeProTh->SetLineColor(kGreen+2);
1199
1200         if (canvasE){
1201                 TCanvas *cPidPerformance= new TCanvas("cPidPerformance","summary of pid performance",800,800);
1202                 cPidPerformance->Divide(2,1);
1203                 cPidPerformance->cd(1);
1204                 gPad->SetGridy();
1205                 gPad->SetGridx();
1206                 gPad->SetLogz();
1207                 hBetaP->Draw("colz"); 
1208   
1209                 cPidPerformance->cd(2);
1210                 gPad->SetGridx();
1211                 gPad->SetGridy();
1212                 gPad->SetLogy();
1213                 hMass->Draw("HIST BAR");
1214   
1215                 TLegend * lPid=new TLegend(0.75,0.75,0.95,0.95,"PID");
1216                 lPid->AddEntry(profDiffTimePi,"#pi^{#pm}","l");
1217                 lPid->AddEntry(profDiffTimeKa,"K^{#pm}","l");
1218                 lPid->AddEntry(profDiffTimePro,"p^{#pm}","l");
1219
1220                 gStyle->SetOptStat(10);
1221                 TCanvas *cPidPerformance2= new TCanvas("cPidPerformance2","summary of pid performance - tracking",700,700);
1222                 cPidPerformance2->Divide(2,2);
1223                 cPidPerformance2->cd(1);
1224                 gPad->SetLogz();
1225                 gPad->SetGridx();
1226                 gPad->SetGridy();
1227                 hDiffTimePi->Draw("colz");
1228                 // profDiffTimePi->Draw("same");
1229   
1230                 cPidPerformance2->cd(2);
1231                 gPad->SetLogz();
1232                 gPad->SetGridx();
1233                 gPad->SetGridy();
1234                 hDiffTimeKa->Draw("colz");
1235                 //profDiffTimeKa->Draw("same");
1236                 cPidPerformance2->cd(3);
1237                 gPad->SetLogz();
1238                 hDiffTimePro->Draw("colz");
1239                 //  profDiffTimePro->Draw("same");
1240  
1241                 // cPidPerformance2->cd(4);
1242                 //  profDiffTimePi->Draw();
1243                 //  profDiffTimeKa->Draw("same");
1244                 //  profDiffTimePro->Draw("same");
1245                 //  lPid->Draw("same");
1246   
1247                 TCanvas *cPidPerformanceTh= new TCanvas("cPidPerformanceTh","summary of pid performance - theoretical times",700,700);
1248                 cPidPerformanceTh->Divide(2,2);
1249                 cPidPerformanceTh->cd(1);
1250                 gPad->SetLogz();
1251                 gPad->SetGridx();
1252                 gPad->SetGridy();
1253                 hDiffTimePiTh->Draw("colz");
1254                 profDiffTimePiTh->Draw("same");
1255                 cPidPerformanceTh->cd(2);
1256                 gPad->SetLogz();
1257                 gPad->SetGridx();
1258                 gPad->SetGridy();
1259                 hDiffTimeKaTh->Draw("colz");
1260                 profDiffTimeKaTh->Draw("same");
1261                 cPidPerformanceTh->cd(3);
1262                 gPad->SetLogz();
1263                 gPad->SetGridx();
1264                 gPad->SetGridy();
1265                 hDiffTimeProTh->Draw("colz");
1266                 profDiffTimeProTh->Draw("same");
1267                 // cPidPerformanceTh->cd(4);
1268                 // profDiffTimePiTh->Draw();
1269                 // profDiffTimeKaTh->Draw("same");
1270                 // profDiffTimeProTh->Draw("same");
1271                 // lPid->Draw("same");
1272         }
1273   
1274         TH1F * hPionDiff=(TH1F*)pidList->FindObject("hTOFmatchedExpTimePi"); 
1275         TH1F * hKaonDiff=(TH1F*)pidList->FindObject("hTOFmatchedExpTimeKa"); 
1276         TH1F * hProtonDiff=(TH1F*)pidList->FindObject("hTOFmatchedExpTimePro"); 
1277  
1278
1279         fout->cd();
1280         hPionDiff->Write();
1281         hKaonDiff->Write();
1282         hProtonDiff->Write();
1283
1284         hBetaP->Write();
1285         hMass->Write();
1286         hDiffTimePi->Write();
1287         profDiffTimePi->Write();
1288         hDiffTimeKa->Write();
1289         profDiffTimeKa->Write();
1290         hDiffTimePro->Write();
1291         profDiffTimePro->Write();
1292         //lPid->Draw();
1293         hDiffTimePiTh->Write();
1294         profDiffTimePiTh->Write();
1295         hDiffTimeKaTh->Write();
1296         profDiffTimeKaTh->Write();
1297         hDiffTimeProTh->Write();
1298         profDiffTimeProTh->Write();
1299   
1300         //SIGMAS PID
1301         TH2F * hSigmaPi=(TH2F*)pidList->At(7); 
1302         sprintf(profilename,"profSigmaPi");
1303         hSigmaPi->GetYaxis()->SetRangeUser(-5.,5.);
1304         TProfile * profSigmaPi = (TProfile*)hSigmaPi->ProfileX(profilename); 
1305         profSigmaPi->SetLineWidth(2);
1306         profSigmaPi->SetLineColor(kRed+2); 
1307
1308         TH2F * hSigmaKa=(TH2F*)pidList->At(12); 
1309         sprintf(profilename,"profSigmaKa");
1310         hSigmaKa->GetYaxis()->SetRangeUser(-5.,5.);
1311         TProfile * profSigmaKa = (TProfile*)hSigmaKa->ProfileX(profilename); 
1312         profSigmaKa->SetLineWidth(2);
1313         profSigmaKa->SetLineColor(kBlue);  
1314
1315         TH2F * hSigmaPro=(TH2F*)pidList->At(17); 
1316         sprintf(profilename,"profSigmaPro");
1317         hSigmaPro->GetYaxis()->SetRangeUser(-5.,5.);
1318         TProfile * profSigmaPro = (TProfile*)hSigmaPro->ProfileX(profilename); 
1319         profSigmaPro->SetLineWidth(2);
1320         profSigmaPro->SetLineColor(kGreen+2);  
1321
1322
1323         if (canvasE){
1324           
1325                 TLegend * lSigmaPid=new TLegend(0.75,0.75,0.95,0.95,"#sigma_{PID}");
1326                 lSigmaPid->AddEntry(profSigmaPi,"#pi^{#pm}","l");
1327                 lSigmaPid->AddEntry(profSigmaKa,"K^{#pm}","l");
1328                 lSigmaPid->AddEntry(profSigmaPro,"p^{#pm}","l");
1329           
1330                 TCanvas *cPidPerformance3= new TCanvas("cPidPerformance3","summary of pid performance - sigmas",1200,400);
1331                 cPidPerformance3->Divide(3,1);
1332                 cPidPerformance3->cd(1);
1333                 gPad->SetLogz();
1334                 gPad->SetGridx();
1335                 gPad->SetGridy();
1336           
1337                 hSigmaPi->Draw("colz");
1338                 profSigmaPi->Draw("same");
1339           
1340                 cPidPerformance3->cd(2);
1341                 gPad->SetLogz();
1342                 gPad->SetGridx();
1343                 gPad->SetGridy();
1344                 hSigmaKa->Draw("colz");
1345                 profSigmaKa->Draw("same");
1346           
1347                 cPidPerformance3->cd(3);
1348                 gPad->SetGridx();
1349                 gPad->SetGridy();
1350                 gPad->SetLogz();
1351                 hSigmaPro->Draw("colz");
1352                 profSigmaPro->Draw("same");
1353         }
1354
1355         fout->cd();
1356         hSigmaPi->Write();
1357         profSigmaPi->Write();
1358         hSigmaKa->Write();
1359         profSigmaKa->Write();
1360         hSigmaPro->Write();
1361         profSigmaPro->Write();
1362
1363         if (canvasE){
1364                 TH2F* hTOFmatchedDzVsStrip = (TH2F*)generalList->FindObject("hTOFmatchedDzVsStrip");
1365                 TCanvas* cProfile = new TCanvas("cProfile","cProfile",50,50,750,550);
1366                 gStyle->SetOptStat(0);
1367                 hTOFmatchedDzVsStrip->Draw("colz");
1368                 Int_t binmin = hTOFmatchedDzVsStrip->GetYaxis()->FindBin(-3);
1369                 Int_t binmax = hTOFmatchedDzVsStrip->GetYaxis()->FindBin(3);
1370                 TProfile* hDzProfile = (TProfile*)hTOFmatchedDzVsStrip->ProfileX("hDzProfile",binmin, binmax);
1371                 hDzProfile->SetLineWidth(3);
1372                 hDzProfile->Draw("same");
1373                 cProfile->SetGridx();
1374                 cProfile->SetGridy();
1375                 TString plotDir(Form("Plots_run%d",runNumber));
1376                 gSystem->Exec(Form("mkdir %s",plotDir.Data()));
1377                 cPidPerformance3->Print(Form("%s/PID_sigmas.png",plotDir.Data()));
1378                 cPidPerformance->Print(Form("%s/PID.png",plotDir.Data()));
1379                 cPidPerformanceTh->Print(Form("%s/PID_thereticalTimes.png",plotDir.Data()));
1380                 cPidPerformance2->Print(Form("%s/PID_ExpTimes.png",plotDir.Data()));
1381                 cMatchingPerformance->Print(Form("%s/Matching.png",plotDir.Data()));
1382                 cT0detector->Print(Form("%s/T0Detector.png",plotDir.Data()));
1383                 cTrackProperties->Print(Form("%s/TrackProperties.png",plotDir.Data()));
1384                 residuals->Print(Form("%s/Residuals.png",plotDir.Data()));
1385                 cProfile->Print(Form("%s/ProfileDZvsStripNumber.png",plotDir.Data()));
1386         }
1387
1388         return 0;
1389 }
1390
1391 //----------------------------------------------------------
1392 char * SetQAtrainOutputName(Int_t run=0,Int_t year=2011,char *period="LHC11a", char* pass="cpass1",Int_t trainId=76){
1393   
1394         char infile[200];
1395         sprintf(infile,"alien:///alice/data/%i/%s/000%d/ESDs/%s/QA%i/QAresults.root",year,period,runNumber,pass,trainId);
1396         return infile;
1397   
1398 }
1399
1400
1401