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