adding some drawing macros for balance functions
[u/mrichter/AliRoot.git] / PWGCF / EBYE / macros / drawBalanceFunctionPsiSummary.C
1 const Int_t numberOfCentralityBins = 8;
2 TString centralityArray[numberOfCentralityBins] = {"0-10","10-20","20-30","30-40","40-50","50-60","60-70","70-80"};
3
4 void drawBalanceFunctionPsiSummarySummary(const char* lhcPeriod = "LHC11h",
5                                               Int_t gTrainID = 250,                           
6                                               Double_t psiMin = -0.5, 
7                                               Double_t psiMax = 3.5){
8   TFile        *fPar[3];
9   TGraphErrors *gPar[3][18];
10
11   Int_t iCentrality[3] = {1,1,5};
12   
13   for(Int_t iCent = 0 ; iCent < 3; iCent++){
14
15     // open file
16     fPar[iCent] = TFile::Open(Form("PbPb/%s/Train%d/figs/balanceFunctionFit_Cent%d_FitParameters.root",lhcPeriod,gTrainID,iCentrality[iCent]));
17     if(!fPar[iCent]){
18       cerr<<"FILE "<<Form("PbPb/%s/Train%d/figs/correlationFunctionFit_Cent%d_FitParameters.root",lhcPeriod,gTrainID,iCentrality[iCent])<<" not found!"<<endl;
19       return;
20     } 
21     
22     // open graph
23     for(Int_t iPar = 0 ; iPar < 18; iPar++){
24       gPar[iCent][iPar] = (TGraphErrors*)fPar[iCent]->Get(Form("gPar%d",iPar));
25       if(!gPar[iCent][iPar]){
26         cerr<<"Graph for parameter "<<iPar<<" not found!"<<endl;
27         return;
28       } 
29     }
30   }
31   
32
33   TCanvas *cSummary[18]; 
34   for(Int_t iPar = 0 ; iPar < 18; iPar++){
35     
36     cSummary[iPar]  = new TCanvas(Form("cSummary%d",iPar),Form("Summary %d",iPar));
37     
38     // compare centralities
39     cSummary[iPar]->cd();
40     gPar[0][iPar]->SetMarkerColor(1);
41     gPar[0][iPar]->SetLineColor(1);
42     gPar[0][iPar]->Draw("AP");
43     gPar[1][iPar]->SetMarkerColor(2);
44     gPar[1][iPar]->SetLineColor(2);
45     gPar[1][iPar]->Draw("P");
46     gPar[2][iPar]->SetMarkerColor(4);
47     gPar[2][iPar]->SetLineColor(4);
48     gPar[2][iPar]->Draw("P");
49     
50     
51     TLegend *legend2 = new TLegend(0.2,0.6,0.85,0.88,"","brNDC");
52     setupLegend(legend2,0.065);
53     for(Int_t iCent = 0 ; iCent < 3; iCent++){
54       legend2->AddEntry(gPar[iCent][iPar],Form("%s \%",centralityArray[iCentrality[iCent]-1].Data()),"lp");
55     }
56     legend2->Draw();
57
58     cSummary[iPar]->SaveAs(Form("PbPb/%s/Train%d/figs/balanceFunctionFit_FitParameter%d_Summary.eps",lhcPeriod,gTrainID,iPar));
59   }
60   
61   
62 }
63   
64
65 void drawBalanceFunctionPsiSummary(const char* lhcPeriod = "LHC11h",
66                                    Int_t gTrainID = 208,                              
67                                    Int_t gCentrality = 1,
68                                    Double_t psiMin = -0.5, 
69                                    Double_t psiMax = 3.5) {
70   // Macro that draws the fit results for the 
71   // correlation functions from the balance function analysis
72   // Author: m.weber@cern.ch
73
74   gROOT->LoadMacro("~/SetPlotStyle.C");
75   SetPlotStyle();
76   gStyle->SetPalette(1,0);
77
78   //Load the PWG2ebye library
79   gSystem->Load("libANALYSIS.so");
80   gSystem->Load("libANALYSISalice.so");
81   gSystem->Load("libEventMixing.so");
82   gSystem->Load("libCORRFW.so");
83   gSystem->Load("libPWGTools.so");
84   gSystem->Load("libPWGCFebye.so");
85
86   // pt bins
87   // this could also be retrieved directly from AliBalancePsi
88   //const Int_t kNPtBins = 16;
89   //Double_t ptBins[kNPtBins+1] = {0.2,0.6,1.0,1.5,2.0,2.5,3.0,3.5,4.0,5.0,6.0,7.0,8.0,10.,12.,15.,20.};
90   const Int_t kNPtBins = 5;
91   Double_t ptBins[kNPtBins+1] = {0.2,1.0,2.0,3.0,4.0,8.0};
92   //const Int_t kNPtBins = 4;
93   //Double_t ptBins[kNPtBins+1] = {1.0,2.0,3.0,4.0,8.0};
94   //const Int_t kNPtBins = 1;
95   //Double_t ptBins[kNPtBins+1] = {0.2,2.0};
96
97   Double_t pt[kNPtBins*kNPtBins];
98   Double_t ptE[kNPtBins*kNPtBins];
99   for(Int_t i = 0; i < kNPtBins; i++){
100     for(Int_t j = 0; j < kNPtBins; j++){
101       pt[i*kNPtBins+j] = 10*i + (ptBins[j]+ptBins[j+1])/2.;
102       ptE[i*kNPtBins+j] = 0.2;
103     }
104   }
105
106
107   // Canvases
108   TCanvas *cQA[kNPtBins][kNPtBins];
109   for(Int_t i = 0; i < kNPtBins; i++){
110     for(Int_t j = 0; j <= i; j++){
111       cQA[i][j] = new TCanvas(Form("cQA%d%d",i,j),Form("Fitting QA for bin %d %d",i,j),1200,900);
112       cQA[i][j]->Divide(3,3);
113     }
114   }
115
116
117   // Loop over pt bins
118   Double_t ptTriggerMin = 0.0;
119   Double_t ptTriggerMax = 0.;
120   Double_t ptAssociatedMin = 0.0;
121   Double_t ptAssociatedMax = 0.0;
122   TString inFileName = "";
123   
124   //Fit Parameters
125   Double_t p[18][kNPtBins*kNPtBins];
126   Double_t pE[18][kNPtBins*kNPtBins];
127
128   for(Int_t iPar = 0; iPar < 18; iPar++){
129     for(Int_t i = 0; i < kNPtBins; i++){
130       for(Int_t j = 0; j < kNPtBins; j++){
131         p[iPar][i*kNPtBins+j] = -1.;
132         pE[iPar][i*kNPtBins+j] = 0.;
133       }
134     }
135   }
136
137   TFile *inFile  = NULL; 
138   TH2D *hTMPData = NULL;
139   TH2D *hTMPRes  = NULL;
140   TH2D *hTMPFit  = NULL;
141   TF2 *fFit  = NULL;
142
143   
144   for(Int_t i = 0; i < kNPtBins; i++){
145     for(Int_t j = 0; j <= i; j++){
146
147       cout<<" PROCESSING PT BIN "<<i<<" "<<j<<endl;
148
149       ptTriggerMin = ptBins[i];
150       ptTriggerMax = ptBins[i+1];
151       ptAssociatedMin = ptBins[j];
152       ptAssociatedMax = ptBins[j+1];
153
154
155       //Latex
156       TString centralityLatex = "Centrality: ";
157       centralityLatex += centralityArray[gCentrality-1]; 
158       centralityLatex += "%";
159       
160       TString psiLatex;
161       if((psiMin == -0.5)&&(psiMax == 0.5))
162         psiLatex = " -7.5^{o} < #varphi - #Psi_{2} < 7.5^{o}"; 
163       else if((psiMin == 0.5)&&(psiMax == 1.5))
164         psiLatex = " 37.5^{o} < #varphi - #Psi_{2} < 52.5^{o}"; 
165       else if((psiMin == 1.5)&&(psiMax == 2.5))
166         psiLatex = " 82.5^{o} < #varphi - #Psi_{2} < 97.5^{o}"; 
167       else 
168         psiLatex = " 0^{o} < #varphi - #Psi_{2} < 180^{o}"; 
169       
170       TString pttLatex = Form("%.1f",ptTriggerMin);
171       pttLatex += " < p_{T,trig} < "; pttLatex += Form("%.1f",ptTriggerMax);
172       pttLatex += " GeV/c";
173       
174       TString ptaLatex = Form("%.1f",ptAssociatedMin);
175       ptaLatex += " < p_{T,assoc} < "; ptaLatex += Form("%.1f",ptAssociatedMax);
176       ptaLatex += " GeV/c";
177       
178       TLatex *latexInfo1 = new TLatex();
179       latexInfo1->SetNDC();
180       latexInfo1->SetTextSize(0.045);
181       latexInfo1->SetTextColor(1);
182       
183       // Open input file
184       inFileName = Form("PbPb/%s/Train%d/Fits/balanceFunctionFit",lhcPeriod,gTrainID);
185       inFileName += ".Centrality";  
186       inFileName += gCentrality; inFileName += ".Psi";
187       if((psiMin == -0.5)&&(psiMax == 0.5)) inFileName += "InPlane.Ptt";
188       else if((psiMin == 0.5)&&(psiMax == 1.5)) inFileName += "Intermediate.Ptt";
189       else if((psiMin == 1.5)&&(psiMax == 2.5)) inFileName += "OutOfPlane.Ptt";
190       else if((psiMin == 2.5)&&(psiMax == 3.5)) inFileName += "Rest.PttFrom";
191       else inFileName += "All.PttFrom";
192       inFileName += Form("%.1f",ptTriggerMin); inFileName += "To"; 
193       inFileName += Form("%.1f",ptTriggerMax); inFileName += "PtaFrom";
194       inFileName += Form("%.1f",ptAssociatedMin); inFileName += "To"; 
195       inFileName += Form("%.1f",ptAssociatedMax); 
196       inFileName += ".root";
197       inFile = TFile::Open(inFileName.Data(),"read");
198       inFile->ls();
199       hTMPData = (TH2D*)inFile->Get(Form("gHistBalanceFunctionSubtracted"));
200       hTMPRes  = (TH2D*)inFile->Get("gHistResidual");
201       hTMPFit  = (TH2D*)inFile->Get(Form("gHistBalanceFunctionSubtractedFit"));
202
203       cQA[i][j]->cd(1);
204       hTMPData->DrawCopy("surf1fb");
205       latexInfo1->DrawLatex(0.2,0.95,"Data");
206
207       latexInfo1->DrawLatex(0.44,0.88,centralityLatex.Data());
208       //latexInfo1->DrawLatex(0.44,0.82,psiLatex.Data());
209       latexInfo1->DrawLatex(0.44,0.82,pttLatex.Data());
210       latexInfo1->DrawLatex(0.44,0.76,ptaLatex.Data());
211
212       cQA[i][j]->cd(2);
213       hTMPFit->DrawCopy("surf1fb");
214       latexInfo1->DrawLatex(0.2,0.95,"Fit");
215
216       cQA[i][j]->cd(3);
217       hTMPRes->DrawCopy("surf1fb");
218       latexInfo1->DrawLatex(0.2,0.95,"Residual");
219
220       cQA[i][j]->cd(4);
221       hTMPData->ProjectionX()->DrawCopy("");
222       latexInfo1->DrawLatex(0.2,0.95,"Data");
223
224       cQA[i][j]->cd(5);
225       hTMPFit->ProjectionX()->DrawCopy("");
226       latexInfo1->DrawLatex(0.2,0.95,"Fit");
227
228       cQA[i][j]->cd(6);
229       hTMPRes->ProjectionX()->DrawCopy("");
230       latexInfo1->DrawLatex(0.2,0.95,"Residual");
231
232       cQA[i][j]->cd(7);
233       hTMPData->ProjectionY()->DrawCopy("");
234       latexInfo1->DrawLatex(0.2,0.95,"Data");
235
236       cQA[i][j]->cd(8);
237       hTMPFit->ProjectionY()->DrawCopy("");
238       latexInfo1->DrawLatex(0.2,0.95,"Fit");
239
240       cQA[i][j]->cd(9);
241       hTMPRes->ProjectionY()->DrawCopy("");
242       latexInfo1->DrawLatex(0.2,0.95,"Residual");
243
244
245       cQA[i][j]->SaveAs(Form(Form("PbPb/%s/Train%d/figs/balanceFunctionFit_PttFrom%.1fTo%.1fPtaFrom%.1fTo%.1f.eps",lhcPeriod,gTrainID,ptTriggerMin,ptTriggerMax,ptAssociatedMin,ptAssociatedMax)));
246       cQA[i][j]->SaveAs(Form(Form("PbPb/%s/Train%d/figs/balanceFunctionFit_PttFrom%.1fTo%.1fPtaFrom%.1fTo%.1f.pdf",lhcPeriod,gTrainID,ptTriggerMin,ptTriggerMax,ptAssociatedMin,ptAssociatedMax)));
247
248       // fit parameters
249       fFit = (TF2*)inFile->Get("gFitFunction");
250       for(Int_t iPar = 0; iPar < 18; iPar++){
251         p[iPar][i*kNPtBins+j] = fFit->GetParameter(iPar);
252         pE[iPar][i*kNPtBins+j] = fFit->GetParError(iPar);
253         cout<<iPar<<") Parameter "<<fFit->GetParName(iPar)<<" : "<<p[iPar][i*kNPtBins+j]<<" +- "<<pE[iPar][i*kNPtBins+j]<<endl;
254       }
255
256       inFile->Close();
257     }
258   }
259
260   TGraphErrors *gPar[18];
261   for(Int_t iPar = 0; iPar < 18; iPar++){
262     gPar[iPar]  = new TGraphErrors(kNPtBins*kNPtBins,pt,p[iPar],ptE,pE[iPar]);
263     gPar[iPar]->SetName(Form("gPar%d",iPar));
264     gPar[iPar]->SetTitle(fFit->GetParName(iPar));
265     gPar[iPar]->GetXaxis()->SetTitle("p_{T}");
266     gPar[iPar]->GetYaxis()->SetTitle(fFit->GetParName(iPar));
267     gPar[iPar]->SetMinimum(0.01);
268     gPar[iPar]->SetMaximum(2);
269     gPar[iPar]->SetMarkerStyle(20);
270     gPar[iPar]->SetMarkerColor(2);
271     gPar[iPar]->SetLineColor(2);
272   }
273
274   TLatex *latexInfo2 = new TLatex();
275   latexInfo2->SetNDC();
276   latexInfo2->SetTextSize(0.045);
277   latexInfo2->SetTextColor(1);
278
279   TCanvas *cPar = new TCanvas("cPar","parameters",1200,900);
280   cPar->Divide(3,3);
281
282   cPar->cd(1);
283   gPar[1]->Draw("AP");
284
285   cPar->cd(2);
286   gPar[2]->Draw("AP");
287
288   cPar->cd(3);
289   gPar[3]->Draw("AP");
290
291   cPar->cd(4);
292   gPar[8]->Draw("AP");
293
294   cPar->cd(5);
295   gPar[9]->Draw("AP");
296
297   cPar->cd(6);
298   gPar[17]->Draw("AP");
299
300   cPar->cd(7);
301   gPar[12]->Draw("AP");
302
303   cPar->cd(8);
304   gPar[14]->Draw("AP");
305
306   cPar->cd(9);
307   gPar[15]->Draw("AP");
308
309   cPar->SaveAs(Form("PbPb/%s/Train%d/figs/balanceFunctionFit_Cent%d_FitParameters.eps",lhcPeriod,gTrainID,gCentrality));
310   cPar->SaveAs(Form("PbPb/%s/Train%d/figs/balanceFunctionFit_Cent%d_FitParameters.pdf",lhcPeriod,gTrainID,gCentrality));
311
312   TFile *fOut = TFile::Open(Form("PbPb/%s/Train%d/figs/balanceFunctionFit_Cent%d_FitParameters.root",lhcPeriod,gTrainID,gCentrality),"RECREATE");
313   for(Int_t iPar = 0; iPar < 18; iPar++){
314     gPar[iPar]->Write();
315   }
316
317   // delete canvases
318   for(Int_t i = 0; i < kNPtBins; i++){
319     for(Int_t j = 0; j <= i; j++){
320       //delete cQA[i][j];
321     }
322   }
323
324 }
325
326
327
328 //____________________________________________________________//
329 void setupLegend(TLegend *currentLegend=0,float currentTextSize=0.07){
330   currentLegend->SetTextFont(42);
331   currentLegend->SetBorderSize(0);
332   currentLegend->SetFillStyle(0);
333   currentLegend->SetFillColor(0);
334   currentLegend->SetMargin(0.25);
335   currentLegend->SetTextSize(currentTextSize);
336   currentLegend->SetEntrySeparation(0.5);
337   return;
338 }