Updates of trending macro for QA outputs from AliAnalysisTaskTOFqa:
[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=kTRUE, Int_t trainId=0, Bool_t displayAll=kTRUE, Bool_t includeStartTime=kTRUE){                                             
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,displayAll,includeStartTime)==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, includeStartTime)==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, includeStartTime); 
66 }
67 //-----------------------------------------------------------
68 Int_t MakeTrendingHistoFromTreeList(char * fileList, TString treeName = "trendTree", Bool_t displayAll=kFALSE, Bool_t includeStartTime=kTRUE){    
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(treeName.Data());
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, includeStartTime); 
95 }
96
97 //______________________________________________________________________________
98 Int_t MakeTrendingFromTreeWithErrors(TChain * fin,char* trendFileName=NULL, Bool_t displayAll=kFALSE, Bool_t includeStartTime=kTRUE){
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", Bool_t includeStartTime=kTRUE){  
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           avT0A=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           avT0C=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           avT0AC=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           avT0res=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 displayAll=kFALSE, Bool_t includeStartTime=kTRUE) {
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 PIDqaListName[6]="PIDqa";
800         char genListName[15]="cGeneralTOFqa";
801         char t0ListName[15]="cTimeZeroTOFqa";
802         char pidListName[15]="cPIDTOFqa"; 
803         char posListName[15]="cPositiveTOFqa";
804         char negListName[15]="cNegativeTOFqa";
805  
806         TDirectoryFile * tofQAdir=(TDirectoryFile*)fin->Get(tofQAdirName);
807         TDirectoryFile * pidQAdir=(TDirectoryFile*)fin->Get(PIDqaListName);
808
809         if(debug){
810           printf("------------------------------------------------------------------\n");
811           tofQAdir->ls();
812           printf("------------------------------------------------------------------\n");
813           if(includeStartTime){
814             pidQAdir->ls();
815             printf("------------------------------------------------------------------\n");
816           }
817         }
818         
819         TList * generalList=(TList*)tofQAdir->Get(genListName);
820         TList  *timeZeroList=(TList*)tofQAdir->Get(t0ListName);
821         TList  *pidList=(TList*)tofQAdir->Get(pidListName);
822         TList  *posList=(TList*)tofQAdir->Get(posListName);
823         TList  *negList=(TList*)tofQAdir->Get(negListName);
824
825         if(!pidQAdir)
826           printf("WARNING: PIDqa histograms not available\n");
827         else{
828           TList  *pidListT0=(TList*)pidQAdir->Get(PIDqaListName);        
829           TList  *tofPidListT0=(TList*)pidListT0->FindObject("TOF");      
830         }
831         if (!generalList) printf("WARNING: general QA histograms absent or not accessible\n");
832         if (!timeZeroList) printf("WARNING: timeZero QA histograms absent or not accessible\n");
833         if (!pidList) printf("WARNING: PID QA histograms absent or not accessible\n");
834         if (!posList) printf("WARNING: general QA histograms for positive tracks absent or not accessible\n");
835         if (!negList) printf("WARNING: general QA histograms for negative tracks absent or not accessible\n");
836
837         if ( (!generalList) && (!timeZeroList) && (!pidList) ){
838                 printf("ERROR: no QA available \n");
839                 return 1;
840         }
841   
842         if (debug){
843                 generalList->ls();
844                 printf("------------------------------------------------------------------\n");
845                 timeZeroList->ls();
846                 printf("------------------------------------------------------------------\n");
847                 pidList->ls();
848                 printf("------------------------------------------------------------------\n");
849         }
850
851         /*set graphic style*/
852         gStyle->SetCanvasColor(kWhite);
853         gStyle->SetFrameFillColor(kWhite);
854         gStyle->SetFrameBorderMode(0);
855         gStyle->SetCanvasBorderMode(0);
856         gStyle->SetTitleFillColor(kWhite);
857         gStyle->SetTitleBorderSize(0)  ;
858         gStyle->SetTitleFont(42);
859         gStyle->SetTextFont(42);
860         //gStyle->SetPalette(1);
861         gStyle->SetStatColor(kWhite); 
862         gStyle->SetStatBorderSize(1);
863         gStyle->SetOptStat(0);
864   
865         //DEFINE OUTPUT FILE 
866         char outfilename[60];
867         sprintf(outfilename,"postQA_%i.root",runNumber);
868         TFile * fout=new TFile(outfilename,"recreate");
869
870         TH1I* hRunNumber=new TH1I("hRunNumber","hRunNumber;run",1,runNumber,runNumber+1);
871         hRunNumber->Fill(runNumber);
872
873         //-------------------------------------------------------------
874         /*GENERAL MONITOR - MULTIPLICITY*/
875         TH1F*hMulti= (TH1F*) generalList->At(0);
876
877         TH1F* hFractionEventsWhits=new TH1F("hFractionEventsWhits","hFractionEventsWhits;fraction of events with hits (%)",200,0.,100.);
878         if (hMulti->GetEntries()<1) return 2;
879         Float_t fraction=0.0;
880         if (hMulti->GetEntries()>0.0) fraction=((Float_t) hMulti->GetBinContent(1))/((Float_t) hMulti->GetEntries());
881         else fraction=0.0;
882         hFractionEventsWhits->Fill(fraction*100.);
883         //-------------------------------------------------------------
884         /*GENERAL MONITOR - TIMING AND GEOMETRY*/
885         TH1F * hTime = (TH1F*) generalList->At(1);
886         if (hTime->GetEntries()<1) return 2;
887         hTime->SetMarkerStyle(8);
888         hTime->SetMarkerSize(0.7);
889         hTime->SetMarkerColor(kBlue);
890         hTime->SetLineColor(kBlue);
891         hTime->SetFillColor(kBlue);
892         hTime->SetFillStyle(3001);
893         hTime->Rebin(2);
894         hTime->GetYaxis()->SetTitle("matched tracks"); 
895         hTime->GetYaxis()->SetTitleOffset(1.35);
896  
897         TH1F * hRawTime = (TH1F*) generalList->At(2);
898         hRawTime->SetMarkerStyle(21);
899         hRawTime->SetMarkerSize(0.7);
900         hRawTime->SetMarkerColor(kGreen);
901         hRawTime->SetLineColor(kGreen);
902         hRawTime->SetFillColor(kGreen);
903         hRawTime->SetFillStyle(3001); 
904         hRawTime->Rebin(2);
905         hRawTime->GetYaxis()->SetTitle("matched tracks");
906         hRawTime->GetYaxis()->SetTitleOffset(1.35);
907   
908         TLegend *lTime = new TLegend(0.7125881,0.6052519,0.979435,0.7408306,NULL,"brNDC");
909         lTime->SetTextSize(0.04281433);
910         lTime->AddEntry(hRawTime, "raw","L");
911         lTime->AddEntry(hTime, "ESD","L"); 
912         lTime->SetFillColor(kWhite);
913         lTime->SetShadowColor(0);
914
915         TH1F * hTot = (TH1F*) generalList->At(3);
916         hTot->SetMarkerStyle(8);
917         hTot->SetMarkerSize(0.7);
918         hTot->SetMarkerColor(kViolet-3);
919         hTot->SetLineColor(kViolet-3);
920         hTot->SetFillColor(kViolet-3);
921         hTot->SetFillStyle(3001);
922         //hTime->SetDrawOption();
923         hTot->GetYaxis()->SetTitle("matched tracks");
924         hTot->GetYaxis()->SetTitleOffset(1.35);
925   
926   
927         char orphansTxt[200];
928         Float_t orphansRatio=0.0;
929         if (hTot->GetEntries()>1){
930                 orphansRatio=((Float_t) hTot->GetBinContent(1))/((Float_t) hTot->GetEntries()) ;
931         }
932         sprintf(orphansTxt,"orphans/matched tracks = %.4f ",orphansRatio);
933         TH1F * hOrphansRatio=new TH1F("hOrphansRatio","Percentage of signals with only leading edge; percentage (%)",1000,0.,100.);
934         hOrphansRatio->Fill(orphansRatio*100.);  
935
936
937         TPaveText *tOrphans = new TPaveText(0.38,0.63,0.88,0.7, "NDC");
938         //NDC sets coords relative to pad
939         tOrphans->SetBorderSize(0);
940         tOrphans->SetTextSize(0.045);
941         tOrphans->SetFillColor(0); //white background
942         tOrphans->SetTextAlign(12);
943         tOrphans->SetTextColor(kViolet-3);
944         tOrphans->AddText(orphansTxt);
945       
946         TH1F * hL = (TH1F*) generalList->At(4);
947         hL->SetMarkerStyle(8);
948         hL->SetMarkerSize(0.7);
949         hL->SetMarkerColor(kOrange-3);
950         hL->SetLineColor(kOrange-3);
951         hL->SetFillColor(kOrange-3);
952         hL->SetFillStyle(3001);
953         //hTime->SetDrawOption();
954         hL->GetYaxis()->SetTitle("matched tracks");
955         hL->GetYaxis()->SetTitleOffset(1.35);
956
957         char negLengthTxt[200];
958         Float_t negLengthRatio=0.0;
959         if (hL->GetEntries()>1){
960                 negLengthRatio=(hL->Integral(1,750))/((Float_t) hL->GetEntries()) ;
961         }
962         sprintf(negLengthTxt,"tracks with L<350cm /matched tracks = %.5f ",negLengthRatio);
963         TH1F * hLnegRatio=new TH1F("hLnegRatio","Ratio of TOF-matched tracks with L<350cm; ratio (%)",10000,0.,100.);
964         hLnegRatio->Fill(negLengthRatio*100);
965   
966
967
968         TPaveText *tLength = new TPaveText(0.15,0.83,0.65,0.87, "NDC");
969         //NDC sets coords relative to pad
970         tLength->SetBorderSize(0);
971         tLength->SetTextSize(0.04);
972         tLength->SetFillColor(0); //white background
973         tLength->SetTextAlign(11);
974         tLength->SetTextColor(kOrange-3);
975         tLength->AddText(negLengthTxt);
976  
977         if (displayAll){
978                 TCanvas *cTrackProperties= new TCanvas("cTrackProperties","summary of matched tracks properties",900,900);
979                 cTrackProperties->Divide(2,2);
980                 cTrackProperties->cd(1);
981                 gPad->SetLogy();
982                 gPad->SetGridx();
983                 gPad->SetGridy();
984                 hTime->Draw("BAR");
985                 hRawTime ->Draw("BARsame");
986                 lTime->Draw();  
987                 cTrackProperties->cd(2);
988                 gPad->SetGridx();
989                 gPad->SetGridy();
990                 gPad->SetLogy();
991                 hTot->Draw("BAR");
992                 tOrphans->Draw(); 
993                 cTrackProperties->cd(3);
994                 gPad->SetGridx();
995                 gPad->SetGridy();
996                 gPad->SetLogy();
997                 hL->Draw("BAR");
998                 tLength->Draw(); 
999         }
1000         fout->cd();
1001         hRunNumber->Write();
1002         hMulti->Write();
1003         hFractionEventsWhits->Write();
1004         hTime->Write();
1005         hRawTime->Write();
1006         hTot->Write();
1007         hOrphansRatio->Write();
1008         hL->Write();
1009         hLnegRatio->Write();
1010   
1011         TH2F* hDxPos4profile = (TH2F*) generalList->At(14);
1012         TH2F* hDxNeg4profile = (TH2F*) generalList->At(13);
1013     
1014         char profilename[30];
1015         const Int_t ybinMin = 0;
1016         const Int_t ybinMax =hDxPos4profile->GetYaxis()->GetNbins() ;
1017         sprintf(profilename,"profDxPos");
1018         TProfile * profDxPos = (TProfile*)hDxPos4profile->ProfileX(profilename, ybinMin,ybinMax); 
1019         sprintf(profilename,"profDxNeg");
1020         profDxPos->SetLineWidth(2);
1021         TProfile * profDxNeg = (TProfile*)hDxNeg4profile->ProfileX(profilename, ybinMin, ybinMax); 
1022         profDxNeg->SetLineWidth(2);  
1023  
1024         TH1 *profRatioPosOverNegDx = (TH1*) profDxPos->Clone();
1025         profRatioPosOverNegDx->SetName("profRatioPosOverNegDx");
1026         profRatioPosOverNegDx->Divide((TH1*) profDxNeg);
1027         profRatioPosOverNegDx->GetYaxis()->SetRangeUser(-5.,5.);
1028         profRatioPosOverNegDx->GetXaxis()->SetRangeUser(0.,2.);
1029         if (displayAll){
1030                 TCanvas *residuals= new TCanvas("residuals","residuals",900,450);
1031                 residuals->Divide(2,1);
1032                 residuals->cd(1);
1033                 gPad->SetGridx();
1034                 gPad->SetGridy();
1035                 hDxPos4profile->GetYaxis()->SetRangeUser(-5.,5.);
1036                 hDxPos4profile->Draw("colz");
1037                 profDxPos->SetLineColor(kRed);
1038                 profDxPos ->Draw("same");
1039                 residuals->cd(2);
1040                 gPad->SetGridx();
1041                 gPad->SetGridy();
1042                 hDxNeg4profile->GetYaxis()->SetRangeUser(-5.,5.); 
1043                 hDxNeg4profile->Draw("colz");
1044                 profDxNeg->SetLineColor(kBlue);
1045                 profDxNeg->Draw("same"); 
1046         }
1047
1048         fout->cd();
1049         hDxPos4profile->Write();
1050         hDxNeg4profile->Write();
1051         profDxPos->Write();
1052         profDxNeg->Write();
1053         profRatioPosOverNegDx->Write();
1054         //-------------------------------------------------------------
1055         /* T0 DETECTOR MONITOR*/
1056
1057         TH1F * hT0AC = (TH1F*) timeZeroList->At(0);
1058         hT0AC->SetMarkerStyle(8);
1059         hT0AC->SetMarkerSize(0.7);
1060         hT0AC->SetMarkerColor(kRed);
1061         hT0AC->SetLineColor(kRed);
1062         hT0AC->SetFillColor(kRed);
1063         hT0AC->SetFillStyle(1001);
1064         hT0AC->Rebin(2);
1065         hT0AC->GetYaxis()->SetTitle("events"); 
1066         hT0AC->GetYaxis()->SetTitleOffset(1.35);
1067         hT0AC->GetXaxis()->SetLabelSize(0.03);
1068  
1069         TH1F * hT0A = (TH1F*) timeZeroList->At(1);
1070         hT0A->SetMarkerStyle(8);
1071         hT0A->SetMarkerSize(0.7);
1072         hT0A->SetMarkerColor(kBlue);
1073         hT0A->SetLineColor(kBlue);
1074         hT0A->SetFillColor(kBlue);
1075         hT0A->SetFillStyle(1001);
1076         hT0A->Rebin(2);
1077         hT0A->GetYaxis()->SetTitle("events"); 
1078         hT0A->GetYaxis()->SetTitleOffset(1.35);
1079         hT0A->GetXaxis()->SetLabelSize(0.03);
1080
1081         TH1F * hT0C = (TH1F*) timeZeroList->At(2);
1082         hT0C->SetMarkerStyle(8);
1083         hT0C->SetMarkerSize(0.7);
1084         hT0C->SetMarkerColor(kGreen);
1085         hT0C->SetLineColor(kGreen);
1086         hT0C->SetFillColor(kGreen);
1087         hT0C->SetFillStyle(1001);
1088         hT0C->Rebin(2);
1089         hT0C->GetYaxis()->SetTitle("events"); 
1090         hT0C->GetYaxis()->SetTitleOffset(1.35);
1091         hT0C->GetXaxis()->SetLabelSize(0.03);
1092  
1093         TLegend *lT0 = new TLegend(0.7125881,0.6052519,0.979435,0.7408306,NULL,"brNDC");
1094         lT0->SetTextSize(0.041);
1095         lT0->AddEntry(hT0AC, "T0 A&C","L");
1096         lT0->AddEntry(hT0A, "T0 A","L"); 
1097         lT0->AddEntry(hT0C, "T0 C","L");
1098         lT0->SetFillColor(kWhite);
1099         lT0->SetShadowColor(0);
1100   
1101         TH1F * hT0res = (TH1F*) timeZeroList->At(3);
1102         hT0res->GetXaxis()->SetLabelSize(0.03);
1103         if (displayAll){
1104                 TCanvas *cT0detector= new TCanvas("cT0detector","T0 detector",900,450);
1105                 cT0detector->Divide(2,1);
1106                 cT0detector->cd(1);
1107                 gPad->SetGridx();
1108                 gPad->SetGridy();
1109                 hT0AC->Draw("BAR");
1110                 hT0AC->SetTitle("timeZero measured by T0 detector");
1111                 hT0A ->Draw("BARsame");
1112                 hT0C ->Draw("BARsame");
1113                 lT0->Draw();  
1114                 cT0detector->cd(2);
1115                 gPad->SetGridx();
1116                 gPad->SetGridy();
1117                 // gPad->SetLogy();
1118                 hT0res->Draw();
1119                 // myText1->Draw(); 
1120                 // cTrackProperties->cd(3);
1121                 // gPad->SetLogy();
1122                 // hL->Draw("BAR");
1123                 // myText2->Draw(); 
1124         }
1125
1126         TH1F * hT0fillRes = (TH1F*) timeZeroList->At(8);
1127         hT0fillRes->GetXaxis()->SetLabelSize(0.03);
1128
1129         fout->cd();
1130         hT0AC->Write();
1131         hT0A->Write();
1132         hT0C->Write();
1133         hT0res->Write();
1134         hT0fillRes->Write();
1135         lT0->Write();
1136   
1137
1138         //-------------------------------------------------------------
1139         /*MATCHING EFFICIENCY  MONITOR*/
1140
1141         //TH1F * hMatchingVsP =new TH1F("hMatchingVsP","Matching probability vs. P; P(GeV/c); matching probability", 50, 0., 5. );
1142   
1143         TH1F * hMatchingVsPt =new TH1F("hMatchingVsPt","Matching probability vs. Pt; Pt(GeV/c); matching probability", 50, 0., 5. );
1144   
1145         TH1F * hMatchingVsEta =new TH1F("hMatchingVsEta","Matching probability vs. #\Eta; #\Eta; matching probability", 20, -1., 1.);
1146   
1147         TH1F * hMatchingVsPhi =new TH1F("hMatchingVsPhi","Matching probability vs. Phi; Phi(rad); matching probability", 628, 0., 6.28);
1148   
1149         /*/matching as function of p
1150           TH1F * hDenom=(TH1F*)generalList->At(9); 
1151           if (hDenom) {  
1152           hMatchingVsP=(TH1F*) generalList->At(5); 
1153           hMatchingVsP->Rebin(5);
1154           hDenom->Rebin(5);
1155           hMatchingVsP->Divide(hDenom);
1156           hMatchingVsP->GetYaxis()->SetTitle("matching efficiency");
1157           hMatchingVsP->SetTitle("TOF matching efficiency as function of momentum");
1158           }*/
1159   
1160         //matching as function of pT
1161   
1162         // hDenom->Clear();
1163         TH1F * hDenom=(TH1F*)generalList->At(10); 
1164         if (hDenom) {  
1165                 hMatchingVsPt=(TH1F*) generalList->At(6); 
1166                 hMatchingVsPt->Rebin(5);
1167                 hDenom->Rebin(5);
1168                 hMatchingVsPt->Divide(hDenom);
1169                 hMatchingVsPt->GetYaxis()->SetTitle("matching efficiency");
1170                 hMatchingVsPt->SetTitle("TOF matching efficiency as function of transverse momentum");
1171                 hMatchingVsPt->GetYaxis()->SetRangeUser(0,1.2); 
1172         }
1173   
1174         //matching as function of eta
1175         hDenom->Clear();
1176         hDenom=(TH1F*)generalList->At(11); 
1177         if (hDenom) {  
1178                 hMatchingVsEta=(TH1F*) generalList->At(7); 
1179                 hMatchingVsEta->Rebin(5);
1180                 hDenom->Rebin(5);
1181                 hMatchingVsEta->Divide(hDenom);
1182                 hMatchingVsEta->GetXaxis()->SetRangeUser(-1,1);
1183                 hMatchingVsEta->GetYaxis()->SetTitle("matching efficiency");
1184                 hMatchingVsEta->GetYaxis()->SetRangeUser(0,1.2);
1185                 hMatchingVsEta->SetTitle("TOF matching efficiency as function of pseudorapidity");
1186         }
1187         //matching as function of phi
1188         hDenom->Clear();
1189         hDenom=(TH1F*)generalList->At(12); 
1190         if (hDenom) {  
1191                 hMatchingVsPhi=(TH1F*) generalList->At(8); 
1192                 //hMatchingVsPhi->Rebin(5);
1193                 //hDenom->Rebin(5);
1194                 hMatchingVsPhi->Divide(hDenom);
1195                 hMatchingVsPhi->GetYaxis()->SetTitle("matching efficiency");
1196                 hMatchingVsPhi->SetTitle("TOF matching efficiency as function of phi");
1197                 hMatchingVsPhi->GetYaxis()->SetRangeUser(0,1.2);
1198         }
1199         if (  displayAll){
1200                 TCanvas *cMatchingPerformance= new TCanvas("cMatchingPerformance","summary of matching performance",700,400);
1201                 cMatchingPerformance->Divide(2,2);
1202                 cMatchingPerformance->cd(1);
1203                 gPad->SetGridx();
1204                 gPad->SetGridy();
1205                 hMatchingVsPt->Draw();
1206                 cMatchingPerformance->cd(2);
1207                 gPad->SetGridx();
1208                 gPad->SetGridy();
1209                 hMatchingVsEta->Draw();
1210                 cMatchingPerformance->cd(3);
1211                 gPad->SetGridx();
1212                 gPad->SetGridy();
1213                 hMatchingVsPhi->Draw();
1214         }
1215         fout->cd();
1216         hMatchingVsPt->Write();
1217         hMatchingVsEta->Write();
1218         hMatchingVsPhi->Write();
1219   
1220         //----------------------------------------------------
1221         /* PID PERFORMANCE MONITOR */
1222
1223         TH2F * hBetaP=(TH2F*)pidList->At(0);
1224         if (hBetaP) hBetaP->GetYaxis()->SetRangeUser(0.,1.2);
1225         else Printf("Plot hBetaP not available (old aliroot?)");
1226         TH1F * hMass=(TH1F*)pidList->At(1);
1227         if (hMass){
1228           //hMass->SetMarkerColor(kBlue);
1229           //hMass->SetLineColor(kBlue);
1230           hMass->SetFillColor(kAzure+10);
1231           hMass->SetFillStyle(1001);
1232           hMass->Rebin(2);
1233           hMass->GetYaxis()->SetTitle("tracks"); 
1234           hMass->GetYaxis()->SetTitleOffset(1.35);
1235           hMass->GetXaxis()->SetLabelSize(0.03);
1236         } else 
1237           Printf("Plot hMass not available (old aliroot?)");
1238         
1239         TH1F * hPionDiff=(TH1F*)pidList->At(3); 
1240
1241         TH2F * hDiffTimePi=(TH2F*)pidList->At(4); 
1242         if (!hDiffTimePi) {
1243           Printf("Plot hDiffTimePi not available (old aliroot?)");
1244         } else {
1245           hDiffTimePi->SetTitle("PIONS t-t_{exp,#pi} (from tracking) vs. P");
1246           hDiffTimePi->GetYaxis()->SetRangeUser(-2000.,2000.);
1247           //hDiffTimePi->GetYaxis()->Rebin(2);//1 bin=10 ps
1248         }
1249         
1250         TH2F * hDiffTimePiTh=(TH2F*)pidList->At(6); 
1251         if (!hDiffTimePiTh) {
1252           Printf("Plot hDiffTimePiTh not available (old aliroot?)");
1253         } else {
1254           hDiffTimePiTh->SetTitle("PIONS t-t_{exp,#pi} (theoretical) vs. P");
1255           hDiffTimePiTh->GetYaxis()->SetRangeUser(-2000.,2000.); 
1256           //hDiffTimePiTh->GetYaxis()->Rebin(2);//1 bin=10 ps
1257         }
1258
1259         TH2F * hDiffTimeKa=(TH2F*)pidList->At(9); 
1260         if (!hDiffTimeKa) {
1261           Printf("Plot hDiffTimeKa not available (old aliroot?)");
1262         } else {
1263           hDiffTimeKa->SetTitle("KAONS t-t_{exp,K} (from tracking) vs. P");
1264           hDiffTimeKa->GetYaxis()->SetRangeUser(-2000.,2000.);
1265           //hDiffTimeKa->GetYaxis()->Rebin(2);//1 bin=10 ps
1266         }
1267
1268         TH2F * hDiffTimeKaTh=(TH2F*)pidList->At(11); 
1269         if (!hDiffTimeKaTh) {
1270           Printf("Plot hDiffTimeKaTh not available (old aliroot?)");
1271         } else {
1272           hDiffTimeKaTh->SetTitle("KAONS t-t_{exp,K} (theoretical) vs. P");
1273           hDiffTimeKaTh->GetYaxis()->SetRangeUser(-2000.,2000.);
1274           //hDiffTimeKaTh->GetYaxis()->Rebin(2);//1 bin=10 ps
1275         }
1276
1277         TH2F * hDiffTimePro=(TH2F*)pidList->At(14); 
1278         if (!hDiffTimePro) {
1279           Printf("Plot hDiffTimePro not available (old aliroot?)");
1280         } else {
1281           hDiffTimePro->SetTitle("PROTONS t-t_{exp,p} (from tracking) vs. P");
1282           hDiffTimePro->GetYaxis()->SetRangeUser(-2000.,2000.);
1283           //hDiffTime->GetYaxis()->Rebin(2);//1 bin=10 ps
1284         }
1285         
1286         TH2F * hDiffTimeProTh=(TH2F*)pidList->At(16); 
1287         if (!hDiffTimeProTh) {
1288           Printf("Plot hDiffTimeProTh not available (old aliroot?)");
1289         } else {
1290           hDiffTimePro->SetTitle("PROTONS t-t_{exp,p} (theoretical) vs. P");
1291           hDiffTimeProTh->GetYaxis()->SetRangeUser(-2000.,2000.);
1292           //hDiffTime->GetYaxis()->Rebin(2);//1 bin=10 ps
1293         }
1294
1295         if (displayAll){
1296                 TCanvas *cPidPerformance= new TCanvas("cPidPerformance","summary of pid performance",800,800);
1297                 cPidPerformance->Divide(2,1);
1298                 cPidPerformance->cd(1);
1299                 gPad->SetGridy();
1300                 gPad->SetGridx();
1301                 gPad->SetLogz();
1302                 if (hBetaP) hBetaP->Draw("colz"); 
1303   
1304                 cPidPerformance->cd(2);
1305                 gPad->SetGridx();
1306                 gPad->SetGridy();
1307                 gPad->SetLogy();
1308                 if (hMass) hMass->Draw("HIST BAR");
1309   
1310                 gStyle->SetOptStat(10);
1311                 TCanvas *cPidPerformance2= new TCanvas("cPidPerformance2","summary of pid performance - tracking",700,700);
1312                 cPidPerformance2->Divide(2,2);
1313                 cPidPerformance2->cd(1);
1314                 gPad->SetLogz();
1315                 gPad->SetGridx();
1316                 gPad->SetGridy();
1317                 if (hDiffTimePi) hDiffTimePi->Draw("colz");
1318                 cPidPerformance2->cd(2);
1319                 gPad->SetLogz();
1320                 gPad->SetGridx();
1321                 gPad->SetGridy();
1322                 if (hDiffTimeKa) hDiffTimeKa->Draw("colz");
1323                 cPidPerformance2->cd(3);
1324                 gPad->SetLogz();
1325                 if (hDiffTimePro) hDiffTimePro->Draw("colz");
1326
1327                 TCanvas *cPidPerformanceTh= new TCanvas("cPidPerformanceTh","summary of pid performance - theoretical times",700,700);
1328                 cPidPerformanceTh->Divide(2,2);
1329                 cPidPerformanceTh->cd(1);
1330                 gPad->SetLogz();
1331                 gPad->SetGridx();
1332                 gPad->SetGridy();
1333                 if (hDiffTimePiTh) hDiffTimePiTh->Draw("colz");
1334                 cPidPerformanceTh->cd(2);
1335                 gPad->SetLogz();
1336                 gPad->SetGridx();
1337                 gPad->SetGridy();
1338                 if (hDiffTimeKaTh) hDiffTimeKaTh->Draw("colz");
1339                 cPidPerformanceTh->cd(3);
1340                 gPad->SetLogz();
1341                 gPad->SetGridx();
1342                 gPad->SetGridy();
1343                 if (hDiffTimeProTh) hDiffTimeProTh->Draw("colz");
1344         }
1345   
1346         TH1F * hPionDiff=(TH1F*)pidList->FindObject("hTOFmatchedExpTimePi"); 
1347         TH1F * hKaonDiff=(TH1F*)pidList->FindObject("hTOFmatchedExpTimeKa"); 
1348         TH1F * hProtonDiff=(TH1F*)pidList->FindObject("hTOFmatchedExpTimePro");
1349         TH2F * hDiffTimeT0TOFPion1GeV=(TH2F*)pidList->FindObject("hTOFmatchedTimePion1GeV"); 
1350
1351         fout->cd();
1352         if (hPionDiff) hPionDiff->Write();
1353         if (hKaonDiff) hKaonDiff->Write();
1354         if (hProtonDiff) hProtonDiff->Write();
1355         if (hBetaP) hBetaP->Write();
1356         if (hMass) hMass->Write();
1357         if (hDiffTimeT0TOFPion1GeV) hDiffTimeT0TOFPion1GeV->Write();
1358         if (hDiffTimePi) hDiffTimePi->Write();
1359         if (hDiffTimeKa) hDiffTimeKa->Write();
1360         if (hDiffTimePro) hDiffTimePro->Write();
1361         if (hDiffTimePiTh) hDiffTimePiTh->Write();
1362         if (hDiffTimeKaTh) hDiffTimeKaTh->Write();
1363         if (hDiffTimeProTh) hDiffTimeProTh->Write();
1364
1365         //SIGMAS PID
1366         TH2F * hSigmaPi=(TH2F*)pidList->At(7); 
1367         TProfile * profSigmaPi = 0x0;
1368         if (!hSigmaPi){
1369           Printf("Plot hSigmaPi not available (old aliroot?)");
1370         } else {
1371           sprintf(profilename,"profSigmaPi");
1372           hSigmaPi->GetYaxis()->SetRangeUser(-5.,5.);
1373           hSigmaPi->GetXaxis()->SetRangeUser(0.2,10.);  
1374           profSigmaPi = (TProfile*)hSigmaPi->ProfileX(profilename); 
1375           profSigmaPi->SetLineWidth(2);
1376           profSigmaPi->SetLineColor(kRed+2); 
1377         }
1378
1379         TH2F * hSigmaKa=(TH2F*)pidList->At(12); 
1380         TProfile * profSigmaKa = 0x0;
1381         if (!hSigmaKa){
1382           Printf("Plot hSigmaKa not available (old aliroot?)");
1383         } else {
1384           sprintf(profilename,"profSigmaKa");
1385           hSigmaKa->GetYaxis()->SetRangeUser(-5.,5.);
1386           hSigmaKa->GetXaxis()->SetRangeUser(0.2,10.);
1387           profSigmaKa = (TProfile*)hSigmaKa->ProfileX(profilename); 
1388           profSigmaKa->SetLineWidth(2);
1389           profSigmaKa->SetLineColor(kBlue);  
1390         }
1391  
1392         TH2F * hSigmaPro=(TH2F*)pidList->At(17); 
1393         TProfile * profSigmaPro = 0x0;
1394         if (!hSigmaPro){
1395           Printf("Plot hSigmaPro not available (old aliroot?)");
1396         } else {
1397           sprintf(profilename,"profSigmaPro");
1398           hSigmaPro->GetYaxis()->SetRangeUser(-5.,5.);
1399           hSigmaPro->GetXaxis()->SetRangeUser(0.2,10.);
1400           profSigmaPro = (TProfile*)hSigmaPro->ProfileX(profilename); 
1401           profSigmaPro->SetLineWidth(2);
1402           profSigmaPro->SetLineColor(kGreen+2);  
1403         }
1404
1405         if(includeStartTime){                                                                  
1406           if(pidQAdir){
1407           TH2F * hSigmaPiT0=(TH2F*)tofPidListT0->FindObject("hNsigmaP_TOF_pion"); 
1408           hSigmaPiT0->GetYaxis()->SetRangeUser(-5.,5.);
1409           hSigmaPiT0->GetXaxis()->SetRangeUser(0.2,10.);
1410           hSigmaPiT0->FitSlicesY();
1411           TH1D * hSigmaPiT0_1 = (TH1D*)gDirectory->Get("hNsigmaP_TOF_pion_1");
1412           TH1D * hSigmaPiT0_2 = (TH1D*)gDirectory->Get("hNsigmaP_TOF_pion_2");
1413           hSigmaPiT0_1->SetLineColor(1);
1414           hSigmaPiT0_1->SetLineWidth(2);
1415           hSigmaPiT0_2->SetLineColor(2);
1416           hSigmaPiT0_2->SetLineWidth(2);  
1417
1418           TH2F * hSigmaKaT0=(TH2F*)tofPidListT0->FindObject("hNsigmaP_TOF_kaon"); 
1419           hSigmaKaT0->GetYaxis()->SetRangeUser(-5.,5.);
1420           hSigmaKaT0->GetXaxis()->SetRangeUser(0.2,10.);
1421           hSigmaKaT0->FitSlicesY();
1422           TH1D * hSigmaKaT0_1 = (TH1D*)gDirectory->Get("hNsigmaP_TOF_kaon_1");
1423           TH1D * hSigmaKaT0_2 = (TH1D*)gDirectory->Get("hNsigmaP_TOF_kaon_2");
1424           hSigmaKaT0_1->SetLineColor(1);
1425           hSigmaKaT0_1->SetLineWidth(2);
1426           hSigmaKaT0_2->SetLineColor(2);
1427           hSigmaKaT0_2->SetLineWidth(2); 
1428  
1429           TH2F * hSigmaProT0=(TH2F*)tofPidListT0->FindObject("hNsigmaP_TOF_proton"); 
1430           hSigmaProT0->GetYaxis()->SetRangeUser(-5.,5.);
1431           hSigmaProT0->GetXaxis()->SetRangeUser(0.2,10.);
1432           hSigmaProT0->FitSlicesY();
1433           TH1D * hSigmaProT0_1 = (TH1D*)gDirectory->Get("hNsigmaP_TOF_proton_1");
1434           TH1D * hSigmaProT0_2 = (TH1D*)gDirectory->Get("hNsigmaP_TOF_proton_2");
1435           hSigmaProT0_1->SetLineColor(1);
1436           hSigmaProT0_1->SetLineWidth(2);
1437           hSigmaProT0_2->SetLineColor(2);
1438           hSigmaProT0_2->SetLineWidth(2);
1439           } 
1440         }
1441         if (displayAll){
1442           
1443                 TLegend * lSigmaPid=new TLegend(0.75,0.75,0.95,0.95,"#sigma_{PID}");
1444                 lSigmaPid->AddEntry(profSigmaPi,"#pi^{#pm}","l");
1445                 lSigmaPid->AddEntry(profSigmaKa,"K^{#pm}","l");
1446                 lSigmaPid->AddEntry(profSigmaPro,"p^{#pm}","l");
1447           
1448                 TCanvas *cPidPerformance3= new TCanvas("cPidPerformance3","summary of pid performance - sigmas",1200,400);
1449                 cPidPerformance3->Divide(3,1);
1450                 cPidPerformance3->cd(1);
1451                 gPad->SetLogz();
1452                 gPad->SetLogx();
1453                 gPad->SetGridx();
1454                 gPad->SetGridy();
1455                 if (hSigmaPi){
1456                   hSigmaPi->Draw("colz");
1457                   profSigmaPi->Draw("same");
1458                 }
1459                 cPidPerformance3->cd(2);
1460                 gPad->SetLogz();
1461                 gPad->SetLogx();
1462                 gPad->SetGridx();
1463                 gPad->SetGridy();
1464                 if (hSigmaKa){
1465                   hSigmaKa->Draw("colz");
1466                   profSigmaKa->Draw("same");
1467                 }
1468                 cPidPerformance3->cd(3);
1469                 gPad->SetGridx();
1470                 gPad->SetGridy();
1471                 gPad->SetLogz();
1472                 gPad->SetLogx();
1473                 if (hSigmaPro){
1474                   hSigmaPro->Draw("colz");
1475                   profSigmaPro->Draw("same");
1476                 }
1477
1478                 if(includeStartTime){  
1479                   if(pidQAdir){   
1480                     TLine *l1=new TLine(0.,0.,5.,0.);
1481                     TLine *l2=new TLine(0.,1.,5.,1.); 
1482                     TCanvas *cPidPerformance3T0 = new TCanvas("cPidPerformance3T0","summary of pid performance - sigmas - with StartTime",1200,500);  
1483                     cPidPerformance3T0->Divide(3,1);
1484                     cPidPerformance3T0->cd(1);        
1485                     gPad->SetLogz();
1486                     gPad->SetLogx();
1487                     gPad->SetGridx();
1488                     gPad->SetGridy();
1489                     hSigmaPiT0->Draw("colz");    
1490                     hSigmaPiT0_1->Draw("same");
1491                     hSigmaPiT0_2->Draw("same");
1492                     l1->Draw("same");
1493                     l2->Draw("same");
1494                     cPidPerformance3T0->cd(2);
1495                     gPad->SetLogz();
1496                     gPad->SetLogx();
1497                     gPad->SetGridx();
1498                     gPad->SetGridy();
1499                     hSigmaKaT0->Draw("colz");
1500                     hSigmaKaT0_1->Draw("same");
1501                     hSigmaKaT0_2->Draw("same");
1502                     l1->Draw("same");
1503                     l2->Draw("same");
1504                     cPidPerformance3T0->cd(3);  
1505                     gPad->SetLogz();
1506                     gPad->SetLogx();
1507                     gPad->SetGridx();
1508                     gPad->SetGridy();
1509                     hSigmaProT0->Draw("colz");
1510                     hSigmaProT0_1->Draw("same");
1511                     hSigmaProT0_2->Draw("same");
1512                     l1->Draw("same");
1513                     l2->Draw("same");                      
1514                 }
1515         }
1516         }
1517
1518         fout->cd();
1519         if (hSigmaPi){
1520           hSigmaPi->Write();
1521           profSigmaPi->Write();
1522         }
1523         if (hSigmaKa){ 
1524           hSigmaKa->Write();
1525           profSigmaKa->Write();
1526         }
1527         if (hSigmaPro){
1528           hSigmaPro->Write();
1529           profSigmaPro->Write();
1530         }
1531         if(includeStartTime)
1532           {
1533             if(pidQAdir){
1534               hSigmaPiT0->Write();
1535               hSigmaKaT0->Write();
1536               hSigmaProT0->Write();
1537       
1538               hSigmaPiT0_1->Write();
1539               hSigmaKaT0_1->Write();
1540               hSigmaProT0_1->Write();
1541
1542               hSigmaPiT0_2->Write();
1543               hSigmaKaT0_2->Write();
1544               hSigmaProT0_2->Write();
1545             }
1546           }
1547         TH2F* hTOFmatchedDzVsStrip = (TH2F*)generalList->FindObject("hTOFmatchedDzVsStrip");
1548         
1549         if (displayAll){
1550           TCanvas* cProfile = new TCanvas("cProfile","cProfile",50,50,750,550);
1551                 gStyle->SetOptStat(0);
1552                 hTOFmatchedDzVsStrip->Draw("colz");
1553                 Int_t binmin = hTOFmatchedDzVsStrip->GetYaxis()->FindBin(-3);
1554                 Int_t binmax = hTOFmatchedDzVsStrip->GetYaxis()->FindBin(3);
1555                 TProfile* hDzProfile = (TProfile*)hTOFmatchedDzVsStrip->ProfileX("hDzProfile",binmin, binmax);
1556                 hDzProfile->SetLineWidth(3);
1557                 hDzProfile->Draw("same");
1558                 cProfile->SetGridx();
1559                 cProfile->SetGridy();
1560                 TString plotDir(Form("Plots_run%d",runNumber));
1561                 gSystem->Exec(Form("mkdir %s",plotDir.Data()));
1562                 cPidPerformance3->Print(Form("%s/PID_sigmas.png",plotDir.Data()));
1563                 if(includeStartTime){
1564                   if(pidQAdir)
1565                     cPidPerformance3T0->Print(Form("%s/%i_PID_sigmaStartTime.png", plotDir.Data()));  
1566                 }
1567                 cPidPerformance->Print(Form("%s/PID.png",plotDir.Data()));
1568                 cPidPerformanceTh->Print(Form("%s/PID_theoreticalTimes.png",plotDir.Data()));
1569                 cPidPerformance2->Print(Form("%s/PID_ExpTimes.png",plotDir.Data()));
1570                 cMatchingPerformance->Print(Form("%s/Matching.png",plotDir.Data()));
1571                 cT0detector->Print(Form("%s/T0Detector.png",plotDir.Data()));
1572                 cTrackProperties->Print(Form("%s/TrackProperties.png",plotDir.Data()));
1573                 residuals->Print(Form("%s/Residuals.png",plotDir.Data()));
1574                 cProfile->Print(Form("%s/ProfileDZvsStripNumber.png",plotDir.Data()));
1575         }
1576         fout->cd();
1577         hTOFmatchedDzVsStrip->Write();
1578         fout->Close();
1579         fin->Close();
1580         return 0;
1581 }
1582
1583 //----------------------------------------------------------
1584 char * SetQAtrainOutputName(Int_t run=0,Int_t year=2011,char *period="LHC11a", char* pass="cpass1",Int_t trainId=76){
1585   
1586         char infile[200];
1587         sprintf(infile,"alien:///alice/data/%i/%s/000%d/ESDs/%s/QA%i/QAresults.root",year,period,runNumber,pass,trainId);
1588         return infile;
1589   
1590 }
1591
1592 //----------------------------------------------------------
1593 Double_t GetGoodTOFChannelsRatio(Int_t run, Bool_t saveMap = kFALSE)
1594 {
1595   /*
1596     It retrieves from OCDB the number of good (= efficient && not noisy && HW ok) TOF channels.
1597     Optionally is saves the channel map
1598   */
1599   if (run<=0) {
1600     printf("MakeTrendingTOFqa.C - ERROR in CheckCalibStatus(): invalid run number. Please set a run number.\n"); 
1601     return 0.0;
1602   }
1603   
1604   AliCDBManager *cdb = AliCDBManager::Instance();
1605   cdb->SetDefaultStorage("raw://");
1606   cdb->SetRun(run);
1607   
1608   AliCDBEntry *cdbe = cdb->Get("TOF/Calib/Status");
1609   if (!cdbe) {
1610     printf("MakeTrendingTOFqa.C - ERROR in CheckCalibStatus(): OCDB entry not available. Please, try again.\n");
1611     return 0.0;
1612   }  
1613
1614   AliTOFChannelOnlineStatusArray *array = (AliTOFChannelOnlineStatusArray *)cdbe->GetObject();
1615   TH2F *hOkMap = new TH2F("hOkMap", "Ok map (!noisy & !problematic & efficient);sector;strip", 72, 0., 18., 91, 0., 91.);
1616
1617   AliTOFcalibHisto calibHisto;
1618   calibHisto.LoadCalibHisto();
1619   AliTOFcalib calib;
1620   calib.Init();
1621
1622   Int_t sector, sectorStrip, padx, fea;
1623   Float_t hitmapx, hitmapy;
1624   for (Int_t i = 0; i <  array->GetSize(); i++) {
1625     sector = calibHisto.GetCalibMap(AliTOFcalibHisto::kSector, i);
1626     sectorStrip = calibHisto.GetCalibMap(AliTOFcalibHisto::kSectorStrip, i);
1627     padx = calibHisto.GetCalibMap(AliTOFcalibHisto::kPadX, i);
1628     fea = padx / 12;
1629     hitmapx = sector + ((Double_t)(3 - fea) + 0.5) / 4.;
1630     hitmapy = sectorStrip;
1631     if ( !(array->GetNoiseStatus(i) == AliTOFChannelOnlineStatusArray::kTOFNoiseBad)   &&
1632          (calib.IsChannelEnabled(i,kTRUE,kTRUE)))
1633       hOkMap->Fill(hitmapx,hitmapy);
1634   }
1635   Int_t nOk=(Int_t) hOkMap->GetEntries();
1636   Double_t ratioOk=nOk/152928.;
1637   if (saveMap) hOkMap->SaveAs(Form("run%i_OKChannelsMap.root",run));
1638   cout << "###    Run " << run << ": TOF channels ok = " << nOk << "/ total 152928 channels = " << ratioOk*100. << "% of whole TOF" << endl;
1639   return ratioOk;
1640 }
1641