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