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