adding some drawing macros for balance functions
[u/mrichter/AliRoot.git] / PWGCF / EBYE / macros / drawBalanceFunctionPsiEventMixing.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
5 void drawBalanceFunctionPsiEventMixing(const char* lhcPeriod = "LHC11h",
6                                        Int_t gTrainID = 208,                          
7                                        Int_t gCentrality = 1,
8                                        Double_t psiMin = -0.5, 
9                                        Double_t psiMax = 3.5) {
10   // Macro that draws the fit results for the 
11   // correlation functions from the balance function analysis
12   // Author: m.weber@cern.ch
13
14   gROOT->LoadMacro("~/SetPlotStyle.C");
15   SetPlotStyle();
16   gStyle->SetPalette(1,0);
17
18   //Load the PWG2ebye library
19   gSystem->Load("libANALYSIS.so");
20   gSystem->Load("libANALYSISalice.so");
21   gSystem->Load("libEventMixing.so");
22   gSystem->Load("libCORRFW.so");
23   gSystem->Load("libPWGTools.so");
24   gSystem->Load("libPWGCFebye.so");
25
26   const Int_t kNPtBins = 3;
27   Double_t ptBins[kNPtBins+1] = {1.0,2.0,3.0,4.0};
28
29   TString type[3] = {"PN","NN","PP"}
30
31   TCanvas *cEM = new TCanvas("cEM","",1200,900);
32   cEM->Divide(3,3);
33
34   TFile *inFile  = NULL; 
35   TH2D *hTMPData = NULL;
36   TH2D *hTMPEM = NULL;
37   TH1D *hTMPData1D = NULL;
38   TH1D *hTMPEM1D = NULL;
39   TH1D *hTMPRatio1D = NULL;
40
41   // Loop over pt bins
42   Double_t ptTriggerMin = 0.0;
43   Double_t ptTriggerMax = 0.;
44   Double_t ptAssociatedMin = 0.0;
45   Double_t ptAssociatedMax = 0.0;
46   TString inFileName = "";
47   
48   for(Int_t i = 0; i < kNPtBins; i++){
49
50       cout<<" PROCESSING PT BIN "<<i<<" "<<endl;
51
52       ptTriggerMin = ptBins[i];
53       ptTriggerMax = ptBins[i+1];
54       ptAssociatedMin = ptBins[i];
55       ptAssociatedMax = ptBins[i+1];
56
57
58       //Latex
59       TString centralityLatex = "Centrality: ";
60       centralityLatex += centralityArray[gCentrality-1]; 
61       centralityLatex += "%";
62       
63       TString psiLatex;
64       if((psiMin == -0.5)&&(psiMax == 0.5))
65         psiLatex = " -7.5^{o} < #varphi - #Psi_{2} < 7.5^{o}"; 
66       else if((psiMin == 0.5)&&(psiMax == 1.5))
67         psiLatex = " 37.5^{o} < #varphi - #Psi_{2} < 52.5^{o}"; 
68       else if((psiMin == 1.5)&&(psiMax == 2.5))
69         psiLatex = " 82.5^{o} < #varphi - #Psi_{2} < 97.5^{o}"; 
70       else 
71         psiLatex = " 0^{o} < #varphi - #Psi_{2} < 180^{o}"; 
72       
73       TString pttLatex = Form("%.1f",ptTriggerMin);
74       pttLatex += " < p_{T,trig} < "; pttLatex += Form("%.1f",ptTriggerMax);
75       pttLatex += " GeV/c";
76       
77       TString ptaLatex = Form("%.1f",ptAssociatedMin);
78       ptaLatex += " < p_{T,assoc} < "; ptaLatex += Form("%.1f",ptAssociatedMax);
79       ptaLatex += " GeV/c";
80       
81       TLatex *latexInfo1 = new TLatex();
82       latexInfo1->SetNDC();
83       latexInfo1->SetTextSize(0.045);
84       latexInfo1->SetTextColor(1);
85       
86       // Open input file
87       inFileName = Form("PbPb/%s/Train%d/Centrality%d/correlationFunction",lhcPeriod,gTrainID,gCentrality);
88       inFileName += ".Centrality";  
89       inFileName += gCentrality; inFileName += ".Psi";
90       if((psiMin == -0.5)&&(psiMax == 0.5)) inFileName += "InPlane.Ptt";
91       else if((psiMin == 0.5)&&(psiMax == 1.5)) inFileName += "Intermediate.Ptt";
92       else if((psiMin == 1.5)&&(psiMax == 2.5)) inFileName += "OutOfPlane.Ptt";
93       else if((psiMin == 2.5)&&(psiMax == 3.5)) inFileName += "Rest.PttFrom";
94       else inFileName += "All.PttFrom";
95       inFileName += Form("%.1f",ptTriggerMin); inFileName += "To"; 
96       inFileName += Form("%.1f",ptTriggerMax); inFileName += "PtaFrom";
97       inFileName += Form("%.1f",ptAssociatedMin); inFileName += "To"; 
98       inFileName += Form("%.1f",ptAssociatedMax); 
99       inFileName += ".root";
100       inFile = TFile::Open(inFileName.Data(),"read");
101       inFile->ls();
102
103       for(Int_t j = 0; j < 3; j++){
104
105         hTMPData = (TH2D*)inFile->Get(Form("gHist%sRaw",type[j].Data()));
106         hTMPEM   = (TH2D*)inFile->Get(Form("gHist%sMixed",type[j].Data()));
107         
108         cEM->cd(3*j+i+1);
109         hTMPData1D = (TH1D*)hTMPData->ProjectionX(Form("hTMP%d%d",i,j),33,39);
110         hTMPEM1D = (TH1D*)hTMPEM->ProjectionX(Form("hTMPEM%d%d",i,j),33,39);
111         hTMPData1D->Fit("pol1","0","0",0,1.6);
112         hTMPEM1D->Fit("pol1","0","0",0,1.6);
113         hTMPRatio1D = (TH1D*)hTMPData1D->Clone(Form("hTMPRatio%d%d",i,j));
114         hTMPRatio1D->Divide(hTMPEM1D);
115         hTMPData1D->Divide(hTMPData1D->GetFunction("pol1"));
116         hTMPEM1D->Divide(hTMPEM1D->GetFunction("pol1"));
117         hTMPData1D->SetMinimum(0.8);
118         hTMPData1D->SetMaximum(1.2);
119         hTMPData1D->GetXaxis()->SetRangeUser(0,1.6);
120         hTMPData1D->Draw();
121         hTMPEM1D->SetMarkerColor(2);
122         hTMPEM1D->SetLineColor(2);
123         hTMPEM1D->Draw("same");
124         hTMPRatio1D->SetMarkerColor(4);
125         hTMPRatio1D->SetLineColor(4);
126         hTMPRatio1D->Draw("same");
127
128
129         TLegend *legend1 = new TLegend(0.24,0.17,0.5,0.4,"","brNDC");
130         setupLegend(legend1,0.065);
131         legend1->AddEntry(hTMPRatio1D,"Correlation Function","lp");
132         legend1->AddEntry(hTMPEM1D,"Event Mixing/Pol1(EM)","lp");
133         legend1->AddEntry(hTMPData1D,"Raw Data/Pol1(Raw)","lp");          
134         legend1->Draw();
135
136
137         latexInfo1->DrawLatex(0.24,0.82,centralityLatex.Data());
138         latexInfo1->DrawLatex(0.24,0.76,pttLatex.Data());
139         latexInfo1->DrawLatex(0.24,0.70,ptaLatex.Data());
140       }
141       
142   }
143
144   cEM->SaveAs(Form(Form("PbPb/%s/Train%d/figs/eventMixingDivided_Cent%d.eps",lhcPeriod,gTrainID,gCentrality)));
145
146 }
147
148 //____________________________________________________________//
149 void setupLegend(TLegend *currentLegend=0,float currentTextSize=0.07){
150   currentLegend->SetTextFont(42);
151   currentLegend->SetBorderSize(0);
152   currentLegend->SetFillStyle(0);
153   currentLegend->SetFillColor(0);
154   currentLegend->SetMargin(0.25);
155   currentLegend->SetTextSize(currentTextSize);
156   currentLegend->SetEntrySeparation(0.5);
157   return;
158 }