]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGHF/vertexingHF/charmFlow/DmesonsFlowAnalysis.C
Minor modifications to output of D meson v2 macro
[u/mrichter/AliRoot.git] / PWGHF / vertexingHF / charmFlow / DmesonsFlowAnalysis.C
CommitLineData
a8f6c03f 1#if !defined(__CINT__) || defined(__MAKECINT__)
2#include <Riostream.h>
3#include <TFile.h>
4#include <TString.h>
5#include <TH2F.h>
6#include <TH1F.h>
7#include <TF1.h>
8#include <TGraph.h>
9#include <TGraphErrors.h>
10#include <TMultiGraph.h>
11#include <TDirectoryFile.h>
12#include <TList.h>
13#include <TCanvas.h>
14#include <TLegend.h>
15#include <TLegendEntry.h>
16#include <TPaveText.h>
17#include <TStyle.h>
18#include <TASImage.h>
19#include <TPad.h>
20#include <TROOT.h>
21#include <TDatabasePDG.h>
22#include <TParameter.h>
23#include <TLatex.h>
4c73ef0b 24#include <TGraphAsymmErrors.h>
a8f6c03f 25
26#include <AliHFMassFitter.h>
27#include "AliRDHFCutsD0toKpi.h"
4c73ef0b 28#include "AliVertexingHFUtils.h"
a8f6c03f 29#include "AliRDHFCutsDplustoKpipi.h"
30#include "AliRDHFCutsDStartoKpipi.h"
4c73ef0b 31#include <AliVertexingHFUtils.h>
a8f6c03f 32
33#endif
34
b356f0ee 35/* $Id$ */
36
a8f6c03f 37//methods for the analysis of AliAnalysisTaskSEHFv2 output
38//Authors: Chiara Bianchin cbianchi@pd.infn.it
39// Giacomo Ortona ortona@to.infn.it
40// Francesco Prino prino@to.infn.it
41
b356f0ee 42//evPlane flag: -1=V0C,0=V0,1=V0A,2=TPC2subevs,3=TPC3subevs
a8f6c03f 43//global variables to be set
4c73ef0b 44Bool_t gnopng=kTRUE; //don't save in png format (only root and eps)
a8f6c03f 45const Int_t nptbinsnew=3;
4c73ef0b 46Float_t ptbinsnew[nptbinsnew+1]={3,5,8,12.};
a8f6c03f 47Int_t fittype=0;
a8f6c03f 48Int_t rebin[nptbinsnew]={4,4,4};
49Double_t nsigma=3;
4c73ef0b 50const Int_t nphibins=4;
51Float_t phibinslim[nphibins+1]={0,TMath::Pi()/4,TMath::Pi()/2,3*TMath::Pi()/4,TMath::Pi()};
52Int_t minPtBin[nptbinsnew]={-1,-1,-1};
53Int_t maxPtBin[nptbinsnew]={-1,-1,-1};
54Double_t mass;
b356f0ee 55
a8f6c03f 56//methods
5866c5ed 57TList *LoadMassHistos(TList *inputlist,Int_t minCent,Int_t maxCent,Bool_t inoutanis);
a8f6c03f 58Int_t FindPtBin(Int_t nbins, Float_t* array,Float_t value);
4c73ef0b 59void FillSignalGraph(TList *histlist,TGraphAsymmErrors **gSignal,TGraphAsymmErrors **gSignalfs,Bool_t inoutanis);
5866c5ed 60void DmesonsFlowAnalysis(Bool_t inoutanis=kTRUE,Int_t minC=30,Int_t maxC=50,TString partname="Dplus",Int_t evPlane=2);
61void DrawEventPlane(Int_t mincentr=0,Int_t maxcentr=0,TString filename="AnalysisResults.root",TString dirname="PWG3_D2H_HFv2",TString listname="coutputv2",Int_t evPlane=2);
a001b53c 62Double_t DrawEventPlane(Double_t &error, TList *list,Int_t mincentr=0,Int_t maxcentr=0,Int_t evPlane=2);
5866c5ed 63void DrawEventPlaneAllCentralities(TList *list,Int_t startCentr=20,Int_t endCentr=80,Int_t evPlane=2);
a8f6c03f 64
65//methods implementation
4c73ef0b 66//________________________________________________________________________________
67TList *LoadMassHistos(TList *inputlist,Int_t minCent,Int_t maxCent,Bool_t inoutanis){
68 // printf("Start load histos\n");
69 // const Int_t nptbins=cutobj->GetNPtBins();
70 TList *outlist = new TList();
71 outlist->SetName("azimuthalhistoslist");
5866c5ed 72
4c73ef0b 73 Int_t nphi=nphibins;
74 if(inoutanis)nphi=2;
75
76 //Create 2D histogram in final pt bins
77 for(Int_t iFinalPtBin=0; iFinalPtBin<nptbinsnew; iFinalPtBin++){
78 for(Int_t iphi=0;iphi<nphi;iphi++){
79 TH1F *hMass=0x0;//=new TH1F();
80 for(Int_t iPtBin=minPtBin[iFinalPtBin]; iPtBin<=maxPtBin[iFinalPtBin];iPtBin++){
81 for(Int_t iHisC=minCent; iHisC<=maxCent-5; iHisC+=5){
9615aedf 82 TString hisname=Form("hMdeltaphi_pt%dcentr%d_%d",iPtBin,iHisC,iHisC+5);
4c73ef0b 83 TH2F* htmp=(TH2F*)inputlist->FindObject(hisname.Data());
84 Int_t startX=htmp->FindBin(phibinslim[iphi]);
a001b53c 85 Int_t endX=htmp->FindBin(phibinslim[iphi+1]-0.0001); // -0.0001 to be sure that the upper limit of the bin is properly set
4c73ef0b 86 TH1F *h1tmp;
87 if(inoutanis){
88 if(iphi==0){
a001b53c 89 Int_t firstBin=htmp->FindBin(0);
90 Int_t lastBin=htmp->FindBin(TMath::Pi()/4.-0.0001); // -0.0001 to be sure that the upper limit of the bin is pi/4
91 h1tmp=(TH1F*)htmp->ProjectionY(Form("hMass%d_phi0",iPtBin),firstBin,lastBin);
92 printf("In-plane, Range: bins %d-%d -> phi %f - %f\n",firstBin,lastBin,htmp->GetXaxis()->GetBinLowEdge(firstBin),htmp->GetXaxis()->GetBinUpEdge(lastBin));
93 firstBin=htmp->FindBin(3.*TMath::Pi()/4.);
94 lastBin=htmp->FindBin(TMath::Pi()-0.0001); // -0.0001 to be sure that the upper limit of the bin is pi
95 h1tmp->Add((TH1F*)htmp->ProjectionY(Form("hMass%d",iPtBin),firstBin,lastBin));
96 printf("In-plane, Range: bins %d-%d -> phi %f - %f\n",firstBin,lastBin,htmp->GetXaxis()->GetBinLowEdge(firstBin),htmp->GetXaxis()->GetBinUpEdge(lastBin));
4c73ef0b 97 }else{
a001b53c 98 Int_t firstBin=htmp->FindBin(TMath::Pi()/4.);
99 Int_t lastBin=htmp->FindBin(3.*TMath::Pi()/4.-0.0001); // -0.0001 to be sure that the upper limit of the bin is pi/4
100 h1tmp=(TH1F*)htmp->ProjectionY(Form("hMass%d_phi1",iPtBin),firstBin,lastBin);
101 printf("Out-of-plane, Range: bins %d-%d -> phi %f - %f\n",firstBin,lastBin,htmp->GetXaxis()->GetBinLowEdge(firstBin),htmp->GetXaxis()->GetBinUpEdge(lastBin));
4c73ef0b 102 }
a001b53c 103 }else{
104 h1tmp=(TH1F*)htmp->ProjectionY(Form("hMass%d_phi%d",iPtBin,iphi),startX,endX);
105 }
4c73ef0b 106 if(hMass==0)hMass=(TH1F*)h1tmp->Clone();
107 else hMass->Add((TH1F*)h1tmp->Clone());
108 }
109 }
110 hMass->SetTitle(Form("hMass_pt%d_phi%d",iFinalPtBin,iphi));
111 hMass->SetName(Form("hMass_pt%d_phi%d",iFinalPtBin,iphi));
112 outlist->Add(hMass->Clone());
113 // hMass->DrawClone();
114 delete hMass;
115 hMass=0x0;
116 }
a8f6c03f 117 }
4c73ef0b 118 return outlist;
a8f6c03f 119}
4c73ef0b 120//______________________________________________________________
121Bool_t DefinePtBins(AliRDHFCuts *cutobj){
122 Int_t nPtBinsCuts=cutobj->GetNPtBins();
123 Float_t *ptlimsCuts=cutobj->GetPtBinLimits();
124 // for(Int_t iPt=0; iPt<nPtBinsCuts; iPt++) printf(" %d %f-%f\n",iPt,ptlimsCuts[iPt],ptlimsCuts[iPt+1]);
125 for(Int_t iPtCuts=0; iPtCuts<nPtBinsCuts; iPtCuts++){
126 for(Int_t iFinalPtBin=0; iFinalPtBin<nptbinsnew; iFinalPtBin++){
127 if(TMath::Abs(ptlimsCuts[iPtCuts]-ptbinsnew[iFinalPtBin])<0.0001){
128 minPtBin[iFinalPtBin]=iPtCuts;
129 if(iFinalPtBin>0) maxPtBin[iFinalPtBin-1]=iPtCuts-1;
130 }
a8f6c03f 131 }
4c73ef0b 132 if(TMath::Abs(ptlimsCuts[iPtCuts]-ptbinsnew[nptbinsnew])<0.0001) maxPtBin[nptbinsnew-1]=iPtCuts-1;
a8f6c03f 133 }
4c73ef0b 134 if(TMath::Abs(ptbinsnew[nptbinsnew]-ptlimsCuts[nPtBinsCuts])<0.0001) maxPtBin[nptbinsnew-1]=nPtBinsCuts-1;
135 for(Int_t iFinalPtBin=0; iFinalPtBin<nptbinsnew; iFinalPtBin++){
136 printf("Pt bins to be merged: %d %d\n",minPtBin[iFinalPtBin],maxPtBin[iFinalPtBin]);
137 if(minPtBin[iFinalPtBin]<0 || maxPtBin[iFinalPtBin]<0) return kFALSE;
a8f6c03f 138 }
139
4c73ef0b 140 return kTRUE;
a8f6c03f 141}
4c73ef0b 142//______________________________________________________________
143Int_t GetPadNumber(Int_t ix,Int_t iy){
144 return (iy)*nptbinsnew+ix+1;
a8f6c03f 145}
4c73ef0b 146//________________________________________________________________________________
147void FillSignalGraph(TList *histlist,TGraphAsymmErrors **gSignal,TGraphAsymmErrors **gSignalfs,Bool_t inoutanis){
a8f6c03f 148
4c73ef0b 149 Int_t nphi=nphibins;
150 if(inoutanis)nphi=2;
a8f6c03f 151
4c73ef0b 152 //Canvases for drawing histograms
153 TCanvas *cDeltaPhi = new TCanvas("cinvmassdeltaphi","Invariant mass distributions",1200,700);
154 TCanvas *cDeltaPhifs = new TCanvas("cinvmassdeltaphifs","Invariant mass distributions - fit with fixed sigma",1200,700);
155 TCanvas *cPhiInteg = new TCanvas("cinvmass","Invariant mass distributions - #phi integrated",1200,350);
156 cDeltaPhi->Divide(nptbinsnew,nphi);
157 cDeltaPhifs->Divide(nptbinsnew,nphi);
158 cPhiInteg->Divide(nptbinsnew,1);
159
160 for(Int_t ipt=0;ipt<nptbinsnew;ipt++){
161 TH1F *histtofitfullsigma=(TH1F*)histlist->FindObject(Form("hMass_pt%d_phi0",ipt))->Clone();
162 for(Int_t iphi=0;iphi<nphi;iphi++){
163 Int_t ipad=GetPadNumber(ipt,iphi);
164 Double_t signal=0,esignal=0;
165 TH1F *histtofit=(TH1F*)histlist->FindObject(Form("hMass_pt%d_phi%d",ipt,iphi))->Clone();
166 if(iphi>0)histtofitfullsigma->Add((TH1F*)histtofit->Clone());
167 if(!histtofit){
168 gSignal[ipt]->SetPoint(iphi,iphi,signal);
169 gSignal[ipt]->SetPointError(iphi,0,0,esignal,esignal);
170 return;
a8f6c03f 171 }
4c73ef0b 172 histtofit->SetTitle(Form("%.1f<p_{t}<%.1f, #phi%d",ptbinsnew[ipt],ptbinsnew[ipt+1],iphi));
173 AliHFMassFitter fitter(histtofit,histtofit->GetBinLowEdge(2),histtofit->GetBinLowEdge(histtofit->GetNbinsX()-2),rebin[ipt]);
174 fitter.SetInitialGaussianMean(mass);
175 // fitter.SetInitialGaussianSigma(0.012);
a8f6c03f 176 Bool_t ok=fitter.MassFitter(kFALSE);
4c73ef0b 177 if(ok){
178 fitter.DrawHere(cDeltaPhi->cd(ipad),3,1);
179 fitter.Signal(3,signal,esignal);
a8f6c03f 180 }
4c73ef0b 181 gSignal[ipt]->SetPoint(iphi,iphi,signal);
182 gSignal[ipt]->SetPointError(iphi,0,0,esignal,esignal);
a8f6c03f 183 }
4c73ef0b 184 //fit for fixed sigma
185 histtofitfullsigma->SetTitle(Form("%.1f<p_{t}<%.1f",ptbinsnew[ipt],ptbinsnew[ipt+1]));
186 AliHFMassFitter fitter(histtofitfullsigma,histtofitfullsigma->GetBinLowEdge(2),histtofitfullsigma->GetBinLowEdge(histtofitfullsigma->GetNbinsX()-2),rebin[ipt]);
187 fitter.SetInitialGaussianMean(mass);
188 // fitter.SetInitialGaussianSigma(0.012);
a8f6c03f 189 Bool_t ok=fitter.MassFitter(kFALSE);
190 if(ok){
4c73ef0b 191 fitter.DrawHere(cPhiInteg->cd(ipt+1),3,1);
a8f6c03f 192 }
4c73ef0b 193 Double_t sigma=fitter.GetSigma();
194 for(Int_t iphi=0;iphi<nphi;iphi++){
195 Int_t ipad=GetPadNumber(ipt,iphi);
196 TH1F *histtofit=(TH1F*)histlist->FindObject(Form("hMass_pt%d_phi%d",ipt,iphi))->Clone();
197 histtofit->SetTitle(Form("%.1f<p_{t}<%.1f, #phi%d",ptbinsnew[ipt],ptbinsnew[ipt+1],iphi));
198 AliHFMassFitter fitter2(histtofit,histtofit->GetBinLowEdge(2),histtofit->GetBinLowEdge(histtofit->GetNbinsX()-2),rebin[ipt]);
199 fitter2.SetInitialGaussianMean(mass);
200 fitter2.SetFixGaussianSigma(sigma);
201 Bool_t ok2=fitter2.MassFitter(kFALSE);
202 Double_t signal=0,esignal=0;
203 if(ok2){
204 fitter2.DrawHere(cDeltaPhifs->cd(ipad),3,1);
205 fitter2.Signal(3,signal,esignal);
206 }
207 gSignalfs[ipt]->SetPoint(iphi,iphi,signal);
208 gSignalfs[ipt]->SetPointError(iphi,0,0,esignal,esignal);
a8f6c03f 209
a8f6c03f 210 }
4c73ef0b 211 }//end loop on pt bin
a8f6c03f 212
4c73ef0b 213 cDeltaPhi->SaveAs("InvMassDeltaPhi.eps");
214 cDeltaPhifs->SaveAs("InvMassDeltaPhi_fs.eps");
4e001f7e 215 cDeltaPhifs->SaveAs("InvMassDeltaPhi_fs.root");
4c73ef0b 216 cPhiInteg->SaveAs("InvMassfullphi.eps");
a8f6c03f 217
4c73ef0b 218 if(!gnopng){
219 cDeltaPhi->SaveAs("InvMassDeltaPhi.png");
220 cDeltaPhifs->SaveAs("InvMassDeltaPhi_fs.png");
221 cPhiInteg->SaveAs("InvMassfullphi.png");
a8f6c03f 222 }
4c73ef0b 223 //cDeltaPhifs->DrawClone();
4e001f7e 224 //cDeltaPhifs->Close();
4c73ef0b 225
226}
227//______________________________________________________________
5866c5ed 228void DmesonsFlowAnalysis(Bool_t inoutanis,Int_t minC,Int_t maxC,TString partname,Int_t evPlane){
4c73ef0b 229 TString filename="AnalysisResults.root";
230 TString dirname="PWG3_D2H_HFv2";
231 TString listname="coutputv2";
a8f6c03f 232
b356f0ee 233 if(evPlane>3||evPlane<-1){
234 printf("Wrong EP flag %d \n",evPlane);
235 return;
236 }
237
4c73ef0b 238 AliRDHFCuts *cutsobj=0x0;
239 //Load input data from AliAnalysisTaskSEHFv2
240 TFile *f = TFile::Open(filename.Data());
241 if(!f){
242 printf("file %s not found, please check file name\n",filename.Data());return;
a8f6c03f 243 }
4c73ef0b 244 TDirectoryFile* dir=(TDirectoryFile*)f->Get(dirname.Data());
245 if(!dir){
246 printf("Directory %s not found, please check dir name\n",dirname.Data());return;
a8f6c03f 247 }
4c73ef0b 248 if(partname.Contains("D0")) {
249 cutsobj=((AliRDHFCutsD0toKpi*)dir->Get(dir->GetListOfKeys()->At(2)->GetName()));
250 mass=TDatabasePDG::Instance()->GetParticle(421)->Mass();
a8f6c03f 251 }
4c73ef0b 252 if(partname.Contains("Dplus")){
253 cutsobj=((AliRDHFCutsDplustoKpipi*)dir->Get(dir->GetListOfKeys()->At(2)->GetName()));
254 mass=TDatabasePDG::Instance()->GetParticle(411)->Mass();
a8f6c03f 255 }
4c73ef0b 256 if(partname.Contains("Dstar")) {
257 cutsobj=((AliRDHFCutsDStartoKpipi*)dir->Get(dir->GetListOfKeys()->At(2)->GetName()));
258 mass=(TDatabasePDG::Instance()->GetParticle(413)->Mass() - TDatabasePDG::Instance()->GetParticle(421)->Mass());
a8f6c03f 259 }
260
4c73ef0b 261 TList *list =(TList*)dir->Get(listname.Data());
262 if(!list){
263 printf("list %s not found in file, please check list name\n",listname.Data());return;
a8f6c03f 264 }
4c73ef0b 265 if(!cutsobj){
266 printf("cut object not found in file, please check keylist number\n");return;
267 }
268 //Define new pt bins
269 if(!DefinePtBins(cutsobj)){
270 printf("cut not define pt bins\n");return;
271 }
272 //Load mass histograms corresponding to the required centrality, pt range and phi binning
273 printf("Load mass histos \n");
274 TList *histlist=LoadMassHistos(list,minC,maxC,inoutanis);
5866c5ed 275 TString aniss="";
276 if(inoutanis)aniss+="anis";
277 histlist->SaveAs(Form("v2Histograms_%d_%d_%s.root",minC,maxC,aniss.Data()),"RECREATE");
4c73ef0b 278
279 Int_t nphi=nphibins;
280 if(inoutanis)nphi=2;
281
282 //EP resolution
283 TH1F* hevplresos=(TH1F*)list->FindObject(Form("hEvPlaneResocentr%d_%d",minC,minC+5));
5866c5ed 284 TH1F* hevplresos2=0;
285 TH1F* hevplresos3=0;
b356f0ee 286 if(evPlane!=2){
5866c5ed 287 hevplresos2=(TH1F*)list->FindObject(Form("hEvPlaneReso2centr%d_%d",minC,minC+5));
288 hevplresos3=(TH1F*)list->FindObject(Form("hEvPlaneReso3centr%d_%d",minC,minC+5));
289 }
290 Double_t resol=0;
291 for(Int_t icent=minC+5;icent<maxC;icent=icent+5){
292 hevplresos->Add((TH1F*)list->FindObject(Form("hEvPlaneResocentr%d_%d",icent,icent+5)));
b356f0ee 293 if(evPlane!=2){
5866c5ed 294 hevplresos2->Add((TH1F*)list->FindObject(Form("hEvPlaneReso2centr%d_%d",icent,icent+5)));
295 hevplresos3->Add((TH1F*)list->FindObject(Form("hEvPlaneReso3centr%d_%d",icent,icent+5)));
296 }
297 }
b356f0ee 298 if(evPlane==2){
5866c5ed 299 resol=AliVertexingHFUtils::GetFullEvResol(hevplresos);
300 }else{
301 Double_t resolSub[3]={hevplresos->GetMean(),hevplresos2->GetMean(),hevplresos3->GetMean()};
b356f0ee 302 if(evPlane<=0)resol=TMath::Sqrt(resolSub[1]*resolSub[2]/resolSub[0]);
303 else if(evPlane==1) resol=TMath::Sqrt(resolSub[0]*resolSub[2]/resolSub[1]);
304 else if(evPlane==3) resol=TMath::Sqrt(resolSub[0]*resolSub[1]/resolSub[2]);
5866c5ed 305 }
4c73ef0b 306
307 printf("average pt for pt bin \n");
308 //average pt for pt bin
309 AliVertexingHFUtils *utils=new AliVertexingHFUtils();
310 TH2F* hmasspt=(TH2F*)list->FindObject(Form("hMPtCandcentr%d_%d",minC,minC+5));
5866c5ed 311 for(Int_t icent=minC+5;icent<maxC;icent=icent+5)hmasspt->Add((TH2F*)list->FindObject(Form("hMPtCandcentr%d_%d",icent,icent+5)));
4c73ef0b 312 Float_t averagePt[nptbinsnew];
313 Float_t errorPt[nptbinsnew];
314 for(Int_t ipt=0;ipt<nptbinsnew;ipt++){
315 TH1F *histtofit = (TH1F*)hmasspt->ProjectionY("_py",hmasspt->FindBin(ptbinsnew[ipt]),hmasspt->FindBin(ptbinsnew[ipt+1]));
316 AliHFMassFitter fitter(histtofit,histtofit->GetBinLowEdge(2),histtofit->GetBinLowEdge(histtofit->GetNbinsX()-2),1);
317 fitter.MassFitter(kFALSE);
318 Float_t massFromFit=fitter.GetMean();
319 Float_t sigmaFromFit=fitter.GetSigma();
320 TF1* funcB2=fitter.GetBackgroundRecalcFunc();
321 utils->AveragePt(averagePt[ipt],errorPt[ipt],ptbinsnew[ipt],ptbinsnew[ipt+1],hmasspt,massFromFit,sigmaFromFit,funcB2);
322 }
5866c5ed 323
4c73ef0b 324 printf("Fill TGraphs for signal \n");
325 //Fill TGraphs for signal
326 TGraphAsymmErrors *gSignal[nptbinsnew];
327 TGraphAsymmErrors *gSignalfs[nptbinsnew];
328 for(Int_t i=0;i<nptbinsnew;i++){
329 gSignal[i]=new TGraphAsymmErrors(nphi);
330 gSignal[i]->SetName(Form("gasigpt%d",i));
331 gSignal[i]->SetTitle(Form("Signal %.1f<p_{t}<%.1f GeV/c;#Delta#phi bin;Counts",ptbinsnew[i],ptbinsnew[i+1]));
332 gSignal[i]->SetMarkerStyle(25);
333 gSignalfs[i]=new TGraphAsymmErrors(nphi);
334 gSignalfs[i]->SetName(Form("gasigfspt%d",i));
335 gSignalfs[i]->SetTitle(Form("Signal (fixed sigma) %.1f<p_{t}<%.1f GeV/c;#Delta#phi bin;Counts",ptbinsnew[i],ptbinsnew[i+1]));
336 gSignalfs[i]->SetMarkerStyle(21);
337 }
338 FillSignalGraph(histlist,gSignal,gSignalfs,inoutanis);
339
340 printf("Compute v2 \n");
341 //compute v2
342 TCanvas *cv2 =new TCanvas("v2","v2");
343 TCanvas *cv2fs =new TCanvas("v2_fs","v2 Fit with fixed sigma");
344 TGraphAsymmErrors *gv2=new TGraphAsymmErrors(nptbinsnew);
345 TGraphAsymmErrors *gv2fs=new TGraphAsymmErrors(nptbinsnew);
346 gv2->SetName("gav2");
347 gv2->SetTitle("v_{2}(p_{t})");
348 gv2fs->SetName("gav2fs");
349 gv2fs->SetTitle("v_{2}(p_{t}) (fit with fixed sigma)");
350
351 //Prepare output file
5866c5ed 352 TFile *fout=new TFile(Form("v2Output_%d_%d_%s.root",minC,maxC,aniss.Data()),"RECREATE");
4c73ef0b 353
354 for(Int_t ipt=0;ipt<nptbinsnew;ipt++){
355 fout->cd();
356 gSignal[ipt]->Write();
357 gSignalfs[ipt]->Write();
358
359 if(inoutanis){
360 //v2 from in-out anisotropy
361 Double_t *y,*yfs;
362 y=gSignal[ipt]->GetY();
363 yfs=gSignalfs[ipt]->GetY();
364 Double_t nIn=y[0];
365 Double_t nOut=y[1];
366 Double_t enIn=gSignal[ipt]->GetErrorY(0);
367 Double_t enOut=gSignal[ipt]->GetErrorY(1);
368 Double_t anis=(nIn-nOut)/(nIn+nOut);
425d0260 369 // Double_t eAnis=TMath::Sqrt(enIn*enIn+enOut*enOut)/(nIn+nOut);
370 Double_t eAnis=2./((nIn+nOut)*(nIn+nOut))*TMath::Sqrt(nIn*nIn*enOut*enOut+nOut*nOut*enIn*enIn);
4c73ef0b 371 Double_t v2=anis*TMath::Pi()/4./resol;
372 Double_t ev2=eAnis*TMath::Pi()/4./resol;
373 gv2->SetPoint(ipt,averagePt[ipt],v2);
374 gv2->SetPointError(ipt,averagePt[ipt]-ptbinsnew[ipt],ptbinsnew[ipt+1]-averagePt[ipt],ev2,ev2);
375
376 nIn=yfs[0];
377 nOut=yfs[1];
425d0260 378 enIn=gSignalfs[ipt]->GetErrorY(0);
379 enOut=gSignalfs[ipt]->GetErrorY(1);
4c73ef0b 380 anis=(nIn-nOut)/(nIn+nOut);
425d0260 381 // eAnis=TMath::Sqrt(enIn*enIn+enOut*enOut)/(nIn+nOut);
382 eAnis=2./((nIn+nOut)*(nIn+nOut))*TMath::Sqrt(nIn*nIn*enOut*enOut+nOut*nOut*enIn*enIn);
4c73ef0b 383 v2=anis*TMath::Pi()/4./resol;
384 ev2=eAnis*TMath::Pi()/4./resol;
385 gv2fs->SetPoint(ipt,averagePt[ipt],v2);
386 gv2fs->SetPointError(ipt,averagePt[ipt]-ptbinsnew[ipt],ptbinsnew[ipt+1]-averagePt[ipt],ev2,ev2);
4e001f7e 387 printf(" Bin %d <pt>=%.3f v2=%f+-%f\n",ipt,averagePt[ipt],v2,ev2);
4c73ef0b 388 }else{
389 TF1 *flowFunc = new TF1("flow","[0]*(1.+2.*[1]*TMath::Cos(2.*x))");
390 //v2 from fit to Deltaphi distribution
391 gSignal[ipt]->Fit(flowFunc);
392 Double_t v2 = flowFunc->GetParameter(1)/resol;
393 Double_t ev2=flowFunc->GetParError(1)/resol;
394 gv2->SetPoint(ipt,averagePt[ipt],v2);
395 gv2->SetPointError(ipt,averagePt[ipt]-ptbinsnew[ipt],ptbinsnew[ipt+1]-averagePt[ipt],ev2,ev2);
396
397 gSignalfs[ipt]->Fit(flowFunc);
398 v2 = flowFunc->GetParameter(1)/resol;
399 ev2=flowFunc->GetParError(1)/resol;
400 gv2fs->SetPoint(ipt,averagePt[ipt],v2);
401 gv2fs->SetPointError(ipt,averagePt[ipt]-ptbinsnew[ipt],ptbinsnew[ipt+1]-averagePt[ipt],ev2,ev2);
402 }
a8f6c03f 403 }
a8f6c03f 404 gv2->SetMarkerStyle(20);
4c73ef0b 405 gv2fs->SetMarkerStyle(20);
406 cv2->cd();
a8f6c03f 407 gv2->Draw("AP");
4c73ef0b 408 gv2->GetYaxis()->SetTitle("v_{2}");
409 gv2->GetXaxis()->SetTitle("p_{t} [GeV/c]");
410 cv2fs->cd();
411 gv2fs->Draw("AP");
412 gv2fs->GetYaxis()->SetTitle("v_{2}");
413 gv2fs->GetXaxis()->SetTitle("p_{t} [GeV/c]");
a8f6c03f 414
415 fout->cd();
a8f6c03f 416 gv2->Write();
4c73ef0b 417 gv2fs->Write();
418 printf("Event plane resolution %f\n",resol);
419 printf("Average pt\n");
420 for(Int_t ipt=0;ipt<nptbinsnew;ipt++) printf("%f +- %f\n",averagePt[ipt],errorPt[ipt]);
a8f6c03f 421}
4c73ef0b 422//_______________________________________________________________________________________________________________________________
423Int_t FindPtBin(Int_t nbins, Float_t* array,Float_t value){
424 for (Int_t i=0;i<nbins;i++){
425 if(value>=array[i] && value<array[i+1]){
426 return i;
a8f6c03f 427 }
a8f6c03f 428 }
4c73ef0b 429 cout<<value<< " out of range "<<array[0]<<", "<<array[nbins]<<endl;
430 return -1;
a8f6c03f 431}
432
4c73ef0b 433//_______________________________________________________________________________________________________________________________
5866c5ed 434void DrawEventPlane(Int_t mincentr,Int_t maxcentr,TString filename,TString dirname,TString listname,Int_t evPlane){
4c73ef0b 435 TFile *f = TFile::Open(filename.Data());
436 if(!f){
437 printf("file %s not found, please check file name\n",filename.Data());return;
a8f6c03f 438 }
4c73ef0b 439 TDirectoryFile* dir=(TDirectoryFile*)f->Get(dirname.Data());
440 if(!dir){
441 printf("Directory %s not found, please check dir name\n",dirname.Data());return;
a8f6c03f 442 }
4c73ef0b 443 TList *list =(TList*)dir->Get(listname.Data());
444 if(!list){
445 printf("list %s not found in file, please check list name\n",listname.Data());return;
446 }
a001b53c 447 Double_t err;
448 DrawEventPlane(err,list,mincentr,maxcentr,evPlane);
a8f6c03f 449}
4c73ef0b 450//_______________________________________________________________________________________________________________________________
a001b53c 451Double_t DrawEventPlane(Double_t &error, TList *list,Int_t mincentr,Int_t maxcentr,Int_t evPlane){
5866c5ed 452
453 //draw the histograms correlated to the event plane, returns event plane resolution
454
a8f6c03f 455 gStyle->SetCanvasColor(0);
456 gStyle->SetTitleFillColor(0);
457 gStyle->SetStatColor(0);
458 //gStyle->SetPalette(1);
459 gStyle->SetOptFit(1);
5866c5ed 460
461 Double_t resolFull=0;
462 Int_t nSubRes=1;
b356f0ee 463 if(evPlane!=2)nSubRes=3;//3 sub-events method for VZERO EP
5866c5ed 464 TString namereso[3]={"Reso","Reso2","Reso3"};
465 TString suffixcentr=Form("centr%d_%d",mincentr,maxcentr);
466 TH2F* hevpls=(TH2F*)list->FindObject(Form("hEvPlanecentr%d_%d",mincentr,mincentr+5));
467 hevpls->SetName(Form("hEvPlane%s",suffixcentr.Data()));
468 hevpls->SetTitle(Form("Event Plane angle %s",suffixcentr.Data()));
469 // TH1F* hevplresos=(TH1F*)list->FindObject(Form("hEvPlaneResocentr%d_%d",mincentr,mincentr+5));QUI!!!
470 TH1F* hevplresos[3];
471 for(Int_t ires=0;ires<nSubRes;ires++){
472 hevplresos[ires]=(TH1F*)list->FindObject(Form("hEvPlane%scentr%d_%d",namereso[ires].Data(),mincentr,mincentr+5));
473 hevplresos[ires]->SetName(Form("hEvPlane%s%s",namereso[ires].Data(),suffixcentr.Data()));
474 hevplresos[ires]->SetTitle(Form("Event Plane Resolution %s%s",namereso[ires].Data(),suffixcentr.Data()));
475 }
476
477 for(Int_t icentr=mincentr+5;icentr<maxcentr;icentr=icentr+5){
478 TH2F* h=(TH2F*)list->FindObject(Form("hEvPlanecentr%d_%d",icentr,icentr+5));
479 if(h)hevpls->Add(h);
480 else cout<<"skipping ev plane "<<icentr<<"_"<<icentr+5<<endl;
481 for(Int_t ires=0;ires<nSubRes;ires++){
482 TH1F *hr=(TH1F*)list->FindObject(Form("hEvPlane%scentr%d_%d",namereso[ires].Data(),icentr,icentr+5));
483 if(hr)hevplresos[ires]->Add(hr);
a8f6c03f 484 else cout<<"skipping ev pl reso "<<icentr<<"_"<<icentr+5<<endl;
485 }
a8f6c03f 486 }
5866c5ed 487
1c451ce0 488 TCanvas* cvtotevpl=new TCanvas(Form("cvtotevpl%s",suffixcentr.Data()),Form("Ev plane %s",suffixcentr.Data()),1200,400);
5866c5ed 489 cvtotevpl->Divide(3,1);
490 cvtotevpl->cd(1);
491 hevpls->Draw("COLZ");
492 TH1F* htpc = (TH1F*)hevpls->ProjectionX();
493 cvtotevpl->cd(2);
494 htpc->Draw();
495 htpc->Fit("pol0");
496 TH1F* hv0 = (TH1F*)hevpls->ProjectionY();
497 cvtotevpl->cd(3);
498 hv0->Draw();
499 hv0->Fit("pol0");
500
1c451ce0 501 TCanvas* cvtotevplreso=new TCanvas(Form("cvtotevplreso%s",suffixcentr.Data()),Form("Ev plane Resolution %s",suffixcentr.Data()));
5866c5ed 502 cvtotevplreso->cd();
503 hevplresos[0]->SetTitle("TPC cos2(#Psi_{A}-#Psi_{B})");
504 hevplresos[0]->Draw();
505 gStyle->SetOptStat(0);
506 if(nSubRes>1){
507 hevplresos[1]->SetLineColor(2);
508 hevplresos[2]->SetLineColor(3);
b356f0ee 509 hevplresos[0]->SetTitle("cos2(#Psi_{TPC}-#Psi_{V0A})");
510 hevplresos[1]->SetTitle("cos2(#Psi_{TPC}-#Psi_{V0C})");
511 hevplresos[2]->SetTitle("cos2(#Psi_{V0A}-#Psi_{V0C})");
5866c5ed 512 hevplresos[1]->Draw("SAME");
513 hevplresos[2]->Draw("SAME");
514 }
515 TLegend *leg = cvtotevplreso->BuildLegend();
516 leg->SetLineColor(0);
517 leg->SetFillColor(0);
518
b356f0ee 519 if(nSubRes<=1){
520 resolFull=AliVertexingHFUtils::GetFullEvResol(hevplresos[0]);
521 error = TMath::Abs(resolFull-AliVertexingHFUtils::GetSubEvResolLowLim(hevplresos[0]));
522 }
5866c5ed 523 else{
524 Double_t resolSub[3];
b356f0ee 525 Double_t errors[3];
526 for(Int_t ires=0;ires<nSubRes;ires++){
527 resolSub[ires]=hevplresos[ires]->GetMean();
528 errors[ires]=hevplresos[ires]->GetMeanError();
529 }
530 Double_t lowlim[3];for(Int_t ie=0;ie<3;ie++)lowlim[ie]=TMath::Abs(resolSub[ie]-errors[ie]);
531 if(evPlane<=0){
532 resolFull=TMath::Sqrt(resolSub[1]*resolSub[2]/resolSub[0]);
533 error=resolFull-TMath::Sqrt(lowlim[2]*lowlim[1]/lowlim[0]);
534 }
535 else if(evPlane==1){
536 resolFull=TMath::Sqrt(resolSub[0]*resolSub[2]/resolSub[1]);
537 error=resolFull-TMath::Sqrt(lowlim[2]*lowlim[0]/lowlim[1]);
538 }
539 else if(evPlane==3){
540 resolFull=TMath::Sqrt(resolSub[0]*resolSub[1]/resolSub[2]);
541 error=resolFull-TMath::Sqrt(lowlim[0]*lowlim[1]/lowlim[2]);
542 }
5866c5ed 543 }
544
545 TPaveText* pvreso=new TPaveText(0.1,0.1,0.6,0.2,"NDC");
546 pvreso->SetBorderSize(0);
547 pvreso->SetFillStyle(0);
548 pvreso->AddText(Form("Resolution on full event = %.4f\n",resolFull));
549 pvreso->Draw();
550
551 TFile* fout=new TFile(Form("EvPlanecentr%d-%d.root",mincentr,maxcentr),"recreate");
552 fout->cd();
553 hevpls->Write();
554 for(Int_t ires=0;ires<nSubRes;ires++)hevplresos[ires]->Write();
555
556 return resolFull;
557}
558
559//_______________________________________________________________________________________________________________________________
560void DrawEventPlaneAllCentralities(TList *list,Int_t startCentr,Int_t endCentr,Int_t evPlane){
b356f0ee 561 TGraphErrors* gresovscentr=new TGraphErrors(0);
5866c5ed 562 gresovscentr->SetName("gresovscentr");
563 gresovscentr->SetTitle(Form("Resolution vs Centrality;centrality (%s);Resolution","%"));
564
565 Int_t iPoint=0;
566 Int_t step=5;//5% centrality step
567 // Int_t nCC=(endCentr-startCentr)/step;
b356f0ee 568 Double_t errory=0;
5866c5ed 569 for(Int_t i=startCentr;i<endCentr;i=i+step){
a001b53c 570 Double_t resolFull=DrawEventPlane(errory,list,i,i+step,evPlane);
5866c5ed 571 gresovscentr->SetPoint(iPoint,i+(Float_t)step/2.,resolFull);
b356f0ee 572 gresovscentr->SetPointError(iPoint,5./2.,errory);
5866c5ed 573 iPoint++;
a8f6c03f 574 }
575
5866c5ed 576 TCanvas* cresovscentr=new TCanvas("cresovscentr", "Resolution vs Centrality");
577 cresovscentr->cd();
578 gresovscentr->SetMarkerStyle(20);
579 gresovscentr->Draw("AP");
580 if(!gnopng) gresovscentr->SaveAs(Form("%s.png",gresovscentr->GetName()));
581 gresovscentr->SaveAs(Form("%s.eps",gresovscentr->GetName()));
582 TFile* fout=new TFile(Form("%s.root",gresovscentr->GetName()),"recreate");
583 fout->cd();
584 gresovscentr->Write();
a8f6c03f 585}
5866c5ed 586//_______________________________________________________________________________________________________________________________
4c73ef0b 587void DrawPaveStat(TVirtualPad* c,Int_t nev,Int_t mincentr,Int_t maxcentr,TString string,TString string2){
588
589 TPaveText* txtoff=new TPaveText(0.2,0.3,0.6,0.5,"NDC");
590 txtoff->SetBorderSize(0);
591 txtoff->SetFillStyle(0);
592 //txtoff->AddText(Form("%.0f#times10^{6} events",nev/1e6));
593 txtoff->AddText("Pb-Pb, #sqrt{s_{NN}} = 2.76TeV");
594 printf("Centrality range %d%s, nev=%d, corrected=%f \n",maxcentr-mincentr,"%",nev,(Float_t)nev/(Float_t)(maxcentr-mincentr)/100.);
595 txtoff->AddText(Form("%.0f#times10^{6} evts in %d-%d%s centr cl",nev/1e6*(Float_t)(maxcentr-mincentr)/100.,mincentr,maxcentr,"%"));
596 txtoff->AddText(string.Data());
597 if(string2!="") {
598 txtoff->AddText(string2.Data());
599 txtoff->SetY1(0.3);
600 }
601 txtoff->SetTextColor(kAzure-5);
602 c->cd();
603 txtoff->Draw();
a8f6c03f 604}
5866c5ed 605//_______________________________________________________________________________________________________________________________
4c73ef0b 606void ALICEPerformance2(TVirtualPad *c,TString today,Double_t* where,TString type){
607
5866c5ed 608 //date must be in the form: 04/05/2010
4c73ef0b 609 if(today=="today"){
610 TDatime startt;
611 int date=startt.GetDate();
612 int y=date/10000;
613 int m=(date%10000)/100;
614 int d=date%100;
615
616
617 today="";
618 today+=d;
619 if(m<10)
620 today.Append("/0");
621 else today.Append("/");
622 today+=m;
623 today.Append("/");
624 today+=y;
625
a8f6c03f 626 }
4c73ef0b 627 cout<<"here"<<endl;
628 TPad *myPadLogo = new TPad("myPadLogo", "Pad for ALICE Logo",where[0],where[1],where[2],where[3]);
629 myPadLogo->SetFillColor(0);
630 myPadLogo->SetBorderMode(0);
631 myPadLogo->SetBorderSize(2);
632 myPadLogo->SetFrameBorderMode(0);
633 myPadLogo->SetLeftMargin(0.0);
634 myPadLogo->SetTopMargin(0.0);
635 myPadLogo->SetBottomMargin(0.0);
636 myPadLogo->SetRightMargin(0.0);
637 myPadLogo->Draw();
638 myPadLogo->cd();
639 TASImage *myAliceLogo = new TASImage("/home/cbianchi/macros/alice_logo.png");
640 myAliceLogo->Draw();
641 printf("Draw logo\n");
642 c->cd();
643 TPaveText* t1=new TPaveText(where[0]-0.03,where[1]-0.11,where[2]+0.01,where[1]-0.01,"NDC");
a8f6c03f 644
4c73ef0b 645 t1->SetFillStyle(0);
646 t1->SetBorderSize(0);
647 //t1->AddText(0.,0.,Form("%s%s",type.Data(),(type=="Performace") ? today.Data() : ""));
5866c5ed 648 t1->AddText(0.,0.,Form("%s",type.Data()));
4c73ef0b 649 t1->SetTextColor(kRed);
650 t1->SetTextFont(42);
651
652 if(type=="Preliminary") {
653 cout<<"Preliminary"<<endl;
654 //t1->Print();
655 t1->Draw();
656 }
657 else {
658 printf("performance\n");
659 t1->AddText(0.,0.,today.Data());
660 t1->SetY1NDC(where[1]-0.17);
661 t1->SetY2NDC(where[1]-0.05);
662 t1->Draw();
663 printf("Drawn date\n");
a8f6c03f 664 }
4c73ef0b 665
a8f6c03f 666}