6 #include "TGraphErrors.h"
11 #include "TLegendEntry.h"
12 #include "TMultiGraph.h"
13 #include "TPaveText.h"
15 void AddPoint(TGraphErrors* graph, Float_t x, Float_t y, Float_t xe, Float_t ye)
17 graph->SetPoint(graph->GetN(), x, y);
18 graph->SetPointError(graph->GetN() - 1, xe, ye);
21 void DrawLatex(Float_t x, Float_t y, Int_t color, const char* text, Float_t textSize = 0.06)
23 TLatex* latex = new TLatex(x, y, text);
25 latex->SetTextSize(textSize);
26 latex->SetTextColor(color);
30 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
31 // norm,dphi,deta,norm2,dphi2,deta2,chi2_1,chi2_2,moment2phi,moment2eta,moment3phi,moment3eta,moment4phi,moment4eta,kurtosisphi,kurtosiseta,
32 // 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
33 // second fit:norm,dphi,deta,norm2,dphi2,deta2,chi2_1,chi2_2,moment2phi,moment2eta,moment3phi,moment3eta,moment4phi,moment4eta,kurtosisphi,kurtosiseta,
34 const Int_t NGraphs = 32;
35 const Int_t NHists = 6;
36 TGraphErrors*** graphs = 0;
39 void CreateGraphStructure()
41 graphs = new TGraphErrors**[NGraphs];
42 for (Int_t i=0; i<NGraphs; i++)
44 graphs[i] = new TGraphErrors*[NHists];
45 for (Int_t j=0; j<NHists; j++)
46 graphs[i][j] = new TGraphErrors;
49 labelList = new TList;
54 TFile::Open("graphs.root", "RECREATE");
55 for (Int_t i=0; i<NGraphs; i++)
56 for (Int_t j=0; j<NHists; j++)
57 graphs[i][j]->Write(Form("graph_%d_%d", i, j));
59 labelList->Write("labelList", TObject::kSingleKey);
64 void ReadGraphs(const char* fileName = "graphs.root")
66 CreateGraphStructure();
67 TFile::Open(fileName);
68 for (Int_t i=0; i<NGraphs; i++)
69 for (Int_t j=0; j<NHists; j++)
70 graphs[i][j] = (TGraphErrors*) gFile->Get(Form("graph_%d_%d", i, j));
72 labelList = (TList*) gFile->Get("labelList");
76 // old one with 1 Gaussian
77 Double_t DeltaPhiWidth2DFitFunction(Double_t *x, Double_t *par)
79 // params: 0: gaussian amplitude, 1: phi width, 2: eta width
80 // 3..bins+2 constants as fct of phi
85 if (phi > TMath::Pi())
86 phi = TMath::TwoPi() - phi;
87 Int_t phiBin = (Int_t) (phi / TMath::Pi() * 36);
90 return par[3+phiBin]+par[0]*TMath::Exp(-0.5*((x[0]/par[1])*(x[0]/par[1])+(x[1]/par[2])*(x[1]/par[2])));
93 const Double_t k1OverSqrtTwoPi = 1.0 / TMath::Sqrt(TMath::TwoPi());
95 Double_t DeltaPhiWidth2DFitFunction(Double_t *x, Double_t *par)
97 // params: 0: gaussian amplitude, 1: phi width I, 2: eta width I
98 // 3: fraction for first Gaussian, 4: phi width II, 5: eta width II
99 // 6..bins+5 constants as fct of phi
104 if (phi > TMath::Pi())
105 phi = TMath::TwoPi() - phi;
106 Int_t phiBin = (Int_t) (phi / TMath::Pi() * 36);
109 return par[6+phiBin] + par[0]*(
110 par[3]/TMath::TwoPi()/par[1]/par[2] *
111 TMath::Exp(-0.5*((x[0]/par[1])*(x[0]/par[1])+(x[1]/par[2])*(x[1]/par[2])))
112 + (1-par[3])/TMath::TwoPi()/par[4]/par[5]
113 * TMath::Exp(-0.5*((x[0]/par[4])*(x[0]/par[4])+(x[1]/par[5])*(x[1]/par[5])))
117 void SubtractEtaGap(TH2* hist, Float_t etaLimit, Float_t outerLimit, Bool_t scale, Bool_t drawEtaGapDist = kFALSE)
119 TString histName(hist->GetName());
121 TH1D* etaGap = hist->ProjectionX(histName + "_1", TMath::Max(1, hist->GetYaxis()->FindBin(-outerLimit + 0.01)), hist->GetYaxis()->FindBin(-etaLimit - 0.01));
122 Int_t etaBins = hist->GetYaxis()->FindBin(-etaLimit - 0.01) - TMath::Max(1, hist->GetYaxis()->FindBin(-outerLimit + 0.01)) + 1;
124 TH1D* tracksTmp = hist->ProjectionX(histName + "_2", hist->GetYaxis()->FindBin(etaLimit + 0.01), TMath::Min(hist->GetYaxis()->GetNbins(), hist->GetYaxis()->FindBin(outerLimit - 0.01)));
125 etaBins += TMath::Min(hist->GetYaxis()->GetNbins(), hist->GetYaxis()->FindBin(outerLimit - 0.01)) - hist->GetYaxis()->FindBin(etaLimit + 0.01) + 1;
127 etaGap->Add(tracksTmp);
129 // get per bin result
130 etaGap->Scale(1.0 / etaBins);
134 TH1D* centralRegion = hist->ProjectionX(histName + "_3", hist->GetYaxis()->FindBin(-etaLimit + 0.01), hist->GetYaxis()->FindBin(etaLimit - 0.01));
136 centralRegion->Scale(1.0 / (hist->GetYaxis()->FindBin(etaLimit - 0.01) - hist->GetYaxis()->FindBin(-etaLimit + 0.01) + 1));
138 TCanvas* c = new TCanvas("SubtractEtaGap", "SubtractEtaGap", 800, 800);
139 centralRegion->SetStats(0);
140 centralRegion->Draw();
141 etaGap->DrawCopy("SAME")->SetLineColor(2);
142 c->SaveAs("etagap_proj.eps");
145 // new TCanvas; etaGap->DrawCopy();
147 TH2* histTmp2D = (TH2*) hist->Clone("histTmp2D");
150 for (Int_t xbin=1; xbin<=histTmp2D->GetNbinsX(); xbin++)
151 for (Int_t y=1; y<=histTmp2D->GetNbinsY(); y++)
152 histTmp2D->SetBinContent(xbin, y, etaGap->GetBinContent(xbin));
156 // mixed event does not reproduce away-side perfectly
157 // --> extract scaling factor on the away-side from ratios of eta gap and central region
158 TH1D* centralRegion = hist->ProjectionX(histName + "_3", hist->GetYaxis()->FindBin(-etaLimit + 0.01), hist->GetYaxis()->FindBin(etaLimit - 0.01));
159 etaBins = hist->GetYaxis()->FindBin(etaLimit - 0.01) - hist->GetYaxis()->FindBin(-etaLimit + 0.01) + 1;
160 centralRegion->Scale(1.0 / etaBins);
162 // new TCanvas; centralRegion->DrawCopy(); etaGap->SetLineColor(2); etaGap->DrawCopy("SAME");
163 centralRegion->Divide(etaGap);
164 // new TCanvas; centralRegion->Draw();
165 centralRegion->Fit("pol0", "0", "", TMath::Pi() - 1, TMath::Pi() + 1);
166 Float_t scalingFactor = centralRegion->GetFunction("pol0")->GetParameter(0);
167 Printf(" scalingFactor = %f", scalingFactor);
168 histTmp2D->Scale(scalingFactor);
171 // new TCanvas; hist->DrawCopy("SURF1");
173 hist->Add(histTmp2D, -1);
176 /*void FitDeltaPhiEtaGap2D(TH2* hist, Bool_t scale, TCanvas* canvas, Int_t canvasPos, TGraphErrors** width, Float_t x, Float_t yPosChi2, TGraphErrors* chi2_1, TGraphErrors* chi2_2)
178 Float_t etaLimit = 1.0;
179 Float_t outerLimit = 1.6;
181 SubtractEtaGap(hist, etaLimit, outerLimit, scale);
183 // new TCanvas; hist->DrawCopy("SURF1");
185 hist->GetYaxis()->SetRangeUser(-outerLimit+0.01, outerLimit-0.01);
186 hist->GetXaxis()->SetRangeUser(-TMath::Pi() / 2 + 0.01, TMath::Pi() * 0.5 - 0.01);
188 canvas->cd(canvasPos);
190 hist->DrawCopy("SURF1");
192 Float_t min = hist->GetMinimum();
193 Float_t max = hist->GetMaximum();
195 // ranges are to exclude eta gap region from fit
196 TF2* func = new TF2("func", "[0]+[1]*exp(-0.5*((x/[2])**2+(y/[3])**2))", -0.5 * TMath::Pi(), 0.5 * TMath::Pi(), -outerLimit, outerLimit);
197 func->SetParameters(0, 1, 0.3, 0.3);
198 func->SetParLimits(1, 0, 10);
199 func->SetParLimits(2, 0.05, 1);
200 func->SetParLimits(3, 0.05, 1);
201 func->FixParameter(0, 0);
203 // TF2* func = new TF2("func", DeltaPhiWidth2DFitFunction, -TMath::Pi() / 2, TMath::Pi() * 1.5, -1, 1, 4);
204 // func->SetParameters(1, 0.3, 0.3, 0);
205 // func->SetParLimits(0, 0, 10);
206 // func->SetParLimits(1, 0.1, 10);
207 // func->SetParLimits(2, 0.1, 10);
209 hist->Fit(func, "0R", "");
210 hist->Fit(func, "I0R", "");
212 // func->SetRange(-0.5 * TMath::Pi(), 0.5 * TMath::Pi(), -outerLimit, outerLimit);
214 canvas->cd(canvasPos + 1);
215 TH2* funcHist = (TH2*) hist->Clone("funcHist");
218 funcHist->SetMinimum(min);
219 funcHist->SetMaximum(max);
220 funcHist->Draw("SURF1");
222 canvas->cd(canvasPos + 2);
224 hist->SetMinimum(min);
225 hist->SetMaximum(max);
226 hist->DrawCopy("SURF1");
228 width[0]->SetPoint(width[0]->GetN(), x, TMath::Abs(func->GetParameter(2)));
229 width[0]->SetPointError(width[0]->GetN()-1, 0, func->GetParError(2));
231 width[1]->SetPoint(width[1]->GetN(), x, TMath::Abs(func->GetParameter(3)));
232 width[1]->SetPointError(width[1]->GetN()-1, 0, func->GetParError(3));
236 for (Int_t i=hist->GetXaxis()->FindBin(-0.8); i<=hist->GetXaxis()->FindBin(0.8); i++)
237 for (Int_t j=hist->GetYaxis()->FindBin(-0.8); j<=hist->GetYaxis()->FindBin(0.8); j++)
239 if (hist->GetBinError(i, j) > 0)
241 chi2 += TMath::Power(hist->GetBinContent(i, j) / hist->GetBinError(i, j), 2);
245 ndf -= func->GetNumberFreeParameters();
247 printf("#chi^{2}/ndf = %.1f/%d = %.1f ", func->GetChisquare(), func->GetNDF(), func->GetChisquare() / func->GetNDF());
248 Printf("#chi^{2}/ndf = %.1f/%d = %.1f", chi2, ndf, chi2 / ndf);
250 DrawLatex(0.5, yPosChi2, 1, Form("#chi^{2}/ndf = %.1f/%d = %.1f", func->GetChisquare(), func->GetNDF(), func->GetChisquare() / func->GetNDF()));
251 DrawLatex(0.5, yPosChi2 - 0.05, 1, Form("#chi^{2}/ndf = %.1f/%d = %.1f", chi2, ndf, chi2 / ndf));
253 chi2_1->SetPoint(chi2_1->GetN(), x, func->GetChisquare() / func->GetNDF());
254 chi2_2->SetPoint(chi2_2->GetN(), x, chi2 / ndf);
258 void CalculateMomentsKurtosis(Float_t momentCalcLimit, TH1* proj, Int_t graphIDStart, Int_t histId, Float_t x)
260 // momentCalcLimit = 0.6;
261 for (Int_t n=2; n <= 4; n++)
265 for (Int_t bin = proj->GetXaxis()->FindBin(-momentCalcLimit+0.01); bin <= proj->GetXaxis()->FindBin(momentCalcLimit-0.01); bin++)
267 moment += proj->GetBinContent(bin) * TMath::Power(proj->GetMean() - proj->GetXaxis()->GetBinCenter(bin), n);
268 sum += proj->GetBinContent(bin);
273 for (Int_t bin = proj->GetXaxis()->FindBin(-momentCalcLimit+0.01); bin <= proj->GetXaxis()->FindBin(momentCalcLimit-0.01); bin++)
275 error += proj->GetBinError(bin) * proj->GetBinError(bin) *
276 TMath::Power(TMath::Power(proj->GetMean() - proj->GetXaxis()->GetBinCenter(bin), n) / sum
280 AddPoint(graphs[graphIDStart+(n-2)*2][histId], x, moment, 0, TMath::Sqrt(error));
281 // Printf("%d %f +- %f <-> %f +- %f", n, moment, error, projx2->GetRMS() * projx2->GetRMS(), 2 * projx2->GetRMSError() * projx2->GetRMSError());
284 proj->GetXaxis()->SetRangeUser(-momentCalcLimit, momentCalcLimit);
285 AddPoint(graphs[graphIDStart+6][histId], x, proj->GetKurtosis(1), 0, proj->GetKurtosis(11));
288 void FitDeltaPhi2DOneFunction(TH2* hist, TCanvas* canvas, Int_t canvasPos, Float_t x, Float_t yPosChi2, Bool_t quick, Int_t histId, Int_t limits, Bool_t twoTrack)
290 Float_t etaLimit = 1.0;
291 Float_t outerLimit = 1.59;
292 Float_t sigmaFitLimit = 0.1 - limits * 0.05;
293 Float_t etaFitUpperLimit = 0.8;
294 Float_t initSigma = 0.6;
295 if (histId == 2) // pp
297 etaFitUpperLimit = 0.6;
301 hist->GetYaxis()->SetRangeUser(-outerLimit+0.01, outerLimit-0.01);
302 hist->GetXaxis()->SetRangeUser(-TMath::Pi() / 2 + 0.01, TMath::Pi() * 0.5 - 0.01);
304 Float_t mean = hist->Integral(hist->GetYaxis()->FindBin(-TMath::Pi() / 2), hist->GetYaxis()->FindBin(TMath::Pi() / 2), hist->GetYaxis()->FindBin(1.0), hist->GetYaxis()->FindBin(outerLimit)) / (hist->GetYaxis()->FindBin(TMath::Pi() / 2) - hist->GetYaxis()->FindBin(-TMath::Pi() / 2)) / (hist->GetYaxis()->FindBin(outerLimit) - hist->GetYaxis()->FindBin(1.0) + 1);
305 // Printf("%f", mean);
308 TGraphErrors* sumSummary = new TGraphErrors;
309 TGraphErrors* phiWidthSummary = new TGraphErrors;
310 TGraphErrors* etaWidthSummary = new TGraphErrors;
312 canvas->cd(canvasPos++);
314 hist->DrawCopy("SURF1");
315 sumSummary->SetPoint(sumSummary->GetN(), sumSummary->GetN(), hist->Integral());
317 Float_t min = hist->GetMinimum();
318 Float_t max = hist->GetMaximum();
320 Int_t bins = hist->GetNbinsX() / 2 / 2;
322 TF2* func = new TF2("func", DeltaPhiWidth2DFitFunction, -TMath::Pi() / 2, TMath::Pi() * 0.5, -outerLimit, outerLimit, bins+6);
323 func->SetParameters(1, 0.3, 0.3, 0.25, initSigma, initSigma);
324 for (Int_t i=6; i<bins+6; i++)
325 func->SetParameter(i, mean);
327 func->SetParLimits(0, 0, 10);
328 func->SetParLimits(1, sigmaFitLimit, 1);
329 func->SetParLimits(2, sigmaFitLimit, etaFitUpperLimit);
330 func->SetParLimits(3, 0.1, 0.9);
331 func->SetParLimits(4, sigmaFitLimit, 1);
332 func->SetParLimits(5, sigmaFitLimit, etaFitUpperLimit);
334 Int_t fitResult = hist->Fit(func, "0R", "");
335 Printf("Fit result: %d", fitResult);
337 // if both parameters are within 1%, refit with 1 Gaussian only
338 if (TMath::Abs(1.0 - func->GetParameter(1) / func->GetParameter(4)) < 0.01 && TMath::Abs(1.0 - func->GetParameter(2) / func->GetParameter(5)) < 0.01)
340 Printf("Parameters within 1%%. Refitting with 1 Gaussian...");
342 func->SetParLimits(3, 1, 1);
343 func->FixParameter(3, 1);
344 func->FixParameter(4, sigmaFitLimit);
345 func->FixParameter(5, sigmaFitLimit);
347 fitResult = hist->Fit(func, "0R", "");
348 Printf("Fit result: %d", fitResult);
353 if (func->GetParameter(1) < func->GetParameter(4))
359 AddPoint(graphs[1+16][histId], x, TMath::Abs(func->GetParameter(first)), 0, func->GetParError(first));
360 AddPoint(graphs[4+16][histId], x, TMath::Abs(func->GetParameter(second)), 0, func->GetParError(second));
363 AddPoint(graphs[2+16][histId], x, TMath::Abs(func->GetParameter(first+1)), 0, func->GetParError(first+1));
364 AddPoint(graphs[5+16][histId], x, TMath::Abs(func->GetParameter(second+1)), 0, func->GetParError(second+1));
367 AddPoint(graphs[0+16][histId], x, func->GetParameter(0), 0, func->GetParError(0));
369 AddPoint(graphs[3+16][histId], x, func->GetParameter(3), 0, func->GetParError(3));
371 AddPoint(graphs[3+16][histId], x, 1.0 - func->GetParameter(3), 0, func->GetParError(3));
373 // hist->Fit(func, "0RI", "");
375 // width[0]->SetPoint(width[0]->GetN(), x, TMath::Abs(func->GetParameter(1)));
376 // width[0]->SetPointError(width[0]->GetN()-1, 0, func->GetParError(1));
378 // width[1]->SetPoint(width[1]->GetN(), x, TMath::Abs(func->GetParameter(2)));
379 // width[1]->SetPointError(width[1]->GetN()-1, 0, func->GetParError(2));
381 AddPoint(phiWidthSummary, phiWidthSummary->GetN(), func->GetParameter(1), 0, func->GetParError(1));
382 AddPoint(phiWidthSummary, phiWidthSummary->GetN(), func->GetParameter(4), 0, func->GetParError(4));
384 AddPoint(etaWidthSummary, etaWidthSummary->GetN(), func->GetParameter(2), 0, func->GetParError(2));
385 AddPoint(etaWidthSummary, etaWidthSummary->GetN(), func->GetParameter(5), 0, func->GetParError(5));
387 canvas->cd(canvasPos++);
388 TH2* funcHist = (TH2*) hist->Clone("funcHist");
391 funcHist->SetMinimum(min);
392 funcHist->SetMaximum(max);
393 funcHist->Draw("SURF1");
394 sumSummary->SetPoint(sumSummary->GetN(), sumSummary->GetN(), funcHist->Integral());
396 canvas->cd(canvasPos++);
397 TH2* residuals = (TH2*) hist->Clone("residuals");
398 residuals->Add(func, -1);
399 residuals->SetMinimum(-(max - min) / 2);
400 residuals->SetMaximum((max - min) / 2);
401 residuals->Draw("SURF1");
405 for (Int_t i=hist->GetXaxis()->FindBin(-0.8); i<=hist->GetXaxis()->FindBin(0.8); i++)
406 for (Int_t j=hist->GetYaxis()->FindBin(-etaLimit); j<=hist->GetYaxis()->FindBin(etaLimit); j++)
408 if (residuals->GetBinError(i, j) > 0)
410 chi2 += TMath::Power(residuals->GetBinContent(i, j) / residuals->GetBinError(i, j), 2);
414 ndf -= func->GetNumberFreeParameters();
416 if (func->GetNDF() > 0)
418 printf("#chi^{2}/ndf = %.1f/%d = %.1f ", func->GetChisquare(), func->GetNDF(), func->GetChisquare() / func->GetNDF());
419 DrawLatex(0.2, yPosChi2, 1, Form("#chi^{2}/ndf = %.1f/%d = %.1f", func->GetChisquare(), func->GetNDF(), func->GetChisquare() / func->GetNDF()));
423 Printf("#chi^{2}/ndf = %.1f/%d = %.1f", chi2, ndf, chi2 / ndf);
424 DrawLatex(0.2, yPosChi2 - 0.05, 1, Form("#chi^{2}/ndf = %.1f/%d = %.1f", chi2, ndf, chi2 / ndf));
427 // draw gaussian only
428 TF2* funcClone = new TF2("funcClone", DeltaPhiWidth2DFitFunction, -TMath::Pi() / 2, TMath::Pi() * 0.5, -outerLimit, outerLimit, bins+6);
429 for (Int_t i=0; i<6; i++)
430 funcClone->SetParameter(i, func->GetParameter(i));
431 for (Int_t i=6; i<bins+6; i++)
432 funcClone->SetParameter(i, 0);
433 // funcClone->Print();
434 canvas->cd(canvasPos++);
435 funcHist = (TH2*) hist->Clone("funcHistb");
437 funcHist->Add(funcClone);
438 funcHist->SetMinimum(-(max - min) / 2);
439 funcHist->SetMaximum((max - min) / 2);
440 funcHist->Draw("SURF1");
442 // eta gap subtraction
443 canvas->cd(canvasPos++);
444 func->SetParameter(0, 0);
445 TH2* subtractFlow = (TH2*) hist->Clone("subtractFlow");
446 subtractFlow->Add(func, -1);
447 subtractFlow->SetMinimum(-(max - min) / 2);
448 subtractFlow->SetMaximum((max - min) / 2);
449 subtractFlow->DrawCopy("SURF1");
450 sumSummary->SetPoint(sumSummary->GetN(), sumSummary->GetN(), subtractFlow->Integral());
452 canvas->cd(canvasPos++);
453 SubtractEtaGap(hist, etaLimit, outerLimit, kFALSE);
454 hist->SetMinimum(-(max - min) / 2);
455 hist->SetMaximum((max - min) / 2);
456 hist->DrawCopy("SURF1");
457 sumSummary->SetPoint(sumSummary->GetN(), sumSummary->GetN(), hist->Integral());
461 canvas->cd(canvasPos++);
462 TH2* difference = (TH2*) hist->Clone("difference");
463 difference->Add(subtractFlow, -1);
464 difference->SetMinimum(-(max - min) / 2);
465 difference->SetMaximum((max - min) / 2);
466 difference->DrawCopy("SURF1");
468 canvas->cd(canvasPos++);
469 TF2* func2 = new TF2("func2", "[0]+[1]*exp(-0.5*((x/[2])**2+(y/[3])**2))", -0.5 * TMath::Pi(), 0.5 * TMath::Pi(), -outerLimit, outerLimit);
470 func2->SetParameters(0, 1, 0.3, 0.3);
471 func2->SetParLimits(1, 0, 10);
472 func2->SetParLimits(2, sigmaFitLimit, 1);
473 func2->SetParLimits(3, sigmaFitLimit, 1);
474 func2->FixParameter(0, 0);
476 hist->Fit(func2, "0R", "");
477 // hist->Fit(func2, "I0R", "");
479 AddPoint(phiWidthSummary, phiWidthSummary->GetN(), func2->GetParameter(2), 0, func2->GetParError(2));
480 AddPoint(etaWidthSummary, etaWidthSummary->GetN(), func2->GetParameter(3), 0, func2->GetParError(3));
482 TH2* funcHist2 = (TH2*) hist->Clone("funcHist2");
484 funcHist2->Add(func2);
485 funcHist2->SetMinimum(-(max - min) / 2);
486 funcHist2->SetMaximum((max - min) / 2);
487 funcHist2->Draw("SURF1");
488 sumSummary->SetPoint(sumSummary->GetN(), sumSummary->GetN(), funcHist2->Integral());
490 if (func2->GetNDF() > 0)
492 Printf("#chi^{2}/ndf = %.1f/%d = %.1f", func2->GetChisquare(), func2->GetNDF(), func2->GetChisquare() / func2->GetNDF());
493 DrawLatex(0.2, yPosChi2, 1, Form("#chi^{2}/ndf = %.1f/%d = %.1f", func2->GetChisquare(), func2->GetNDF(), func2->GetChisquare() / func2->GetNDF()));
496 canvas->cd(canvasPos++);
497 TH2* residuals2 = (TH2*) hist->Clone("residuals");
498 residuals2->Add(funcHist2, -1);
499 residuals2->SetMinimum(-(max - min) / 2);
500 residuals2->SetMaximum((max - min) / 2);
501 residuals2->Draw("SURF1");
504 Float_t momentFitLimit = 0.8;
505 TH1* projx2 = hist->ProjectionX(Form("%s_projx2", hist->GetName()), hist->GetYaxis()->FindBin(-momentFitLimit+0.01), hist->GetYaxis()->FindBin(momentFitLimit-0.01));
506 projx2->GetXaxis()->SetRangeUser(-1, 1);
508 TH1* projy2 = hist->ProjectionY(Form("%s_projy2", hist->GetName()), hist->GetXaxis()->FindBin(-momentFitLimit+0.01), hist->GetXaxis()->FindBin(momentFitLimit-0.01));
509 projy2->GetXaxis()->SetRangeUser(-1, 1);
511 CalculateMomentsKurtosis(momentFitLimit, projx2, 8, histId, x);
512 CalculateMomentsKurtosis(momentFitLimit, projy2, 9, histId, x);
516 TH1* projx1 = subtractFlow->ProjectionX(Form("%s_projx1", hist->GetName()), hist->GetYaxis()->FindBin(-0.8), hist->GetYaxis()->FindBin(0.8));
517 TH1* projy1 = subtractFlow->ProjectionY(Form("%s_projy1", hist->GetName()), hist->GetXaxis()->FindBin(-0.8), hist->GetXaxis()->FindBin(0.8));
519 CalculateMomentsKurtosis(momentFitLimit, projx1, 8+16, histId, x);
520 CalculateMomentsKurtosis(momentFitLimit, projy1, 9+16, histId, x);
522 // TF1* twoGauss = new TF1("twoGauss", "gaus(0)+gaus(3)", -2, 2);
523 // twoGauss->SetParameters(1, 0, 0.3, 1, 0, 0.6);
524 // twoGauss->FixParameter(1, 0);
525 // twoGauss->FixParameter(4, 0);
526 // twoGauss->SetLineColor(4);
527 // projx1->Fit("twoGauss", "I+", "SAME");
529 canvas->cd(canvasPos++);
531 projx1->Fit("gaus", "I");
533 projx2->SetLineColor(2);
534 projx2->Draw("SAME");
535 projx2->Fit("gaus", "I+", "SAME");
536 projx2->GetFunction("gaus")->SetLineColor(2);
538 canvas->cd(canvasPos++);
540 projy1->Fit("gaus", "I");
542 projy2->SetLineColor(2);
543 projy2->Draw("SAME");
544 projy2->Fit("gaus", "I+", "SAME");
545 projy2->GetFunction("gaus")->SetLineColor(2);
547 // 1d fit (lots of params)
548 AddPoint(phiWidthSummary, phiWidthSummary->GetN(), projx2->GetFunction("gaus")->GetParameter(2), 0, projx2->GetFunction("gaus")->GetParError(2));
550 // 1d fit (eta gap subtraction)
551 AddPoint(phiWidthSummary, phiWidthSummary->GetN(), projx1->GetFunction("gaus")->GetParameter(2), 0, projx1->GetFunction("gaus")->GetParError(2));
553 // 1d fit (lots of params)
554 AddPoint(etaWidthSummary, etaWidthSummary->GetN(), projy2->GetFunction("gaus")->GetParameter(2), 0, projy2->GetFunction("gaus")->GetParError(2));
556 // 1d fit (eta gap subtraction)
557 AddPoint(etaWidthSummary, etaWidthSummary->GetN(), projy1->GetFunction("gaus")->GetParameter(2), 0, projy1->GetFunction("gaus")->GetParError(2));
559 // set errors large for bins potentially affected by two-track effects
562 Printf("NOTE : Skipping bins at (0, 0)");
563 // for (Int_t binx = hist->GetXaxis()->FindBin(-0.25); binx <= hist->GetXaxis()->FindBin(0.25); binx++)
564 for (Int_t binx = hist->GetXaxis()->FindBin(-0.01); binx <= hist->GetXaxis()->FindBin(0.01); binx++)
565 for (Int_t biny = hist->GetYaxis()->FindBin(-0.01); biny <= hist->GetYaxis()->FindBin(0.01); biny++)
567 // hist->SetBinContent(binx, biny, 0);
568 hist->SetBinError(binx, biny, 1e5);
572 // 2d fit with two gaussians
573 canvas->cd(canvasPos++);
574 // TF2* func3 = new TF2("func3", "[0]+[1]*exp(-0.5*((x/[2])**2+(y/[3])**2))+[4]*exp(-0.5*((x/[5])**2+(y/[6])**2))", -0.5 * TMath::Pi(), 0.5 * TMath::Pi(), -outerLimit, outerLimit);
575 // func3->SetParameters(0, 1, 0.3, 0.3, 1, 0.6, 0.6);
576 // func3->SetParLimits(4, 0, 10);
577 Float_t etaFitLimit = outerLimit;
578 // Float_t etaFitLimit = 0.5;
579 TF2* func3 = new TF2("func3", "[0]+[1]*([4]/TMath::TwoPi()/[2]/[3]*exp(-0.5*((x/[2])**2+(y/[3])**2))+(1-[4])/TMath::TwoPi()/[5]/[6]*exp(-0.5*((x/[5])**2+(y/[6])**2)))", -0.5 * TMath::Pi(), 0.5 * TMath::Pi(), -etaFitLimit, etaFitLimit);
580 func3->SetParameters(0, 1, 0.3, 0.3, 0.25, initSigma, initSigma);
581 func3->SetParLimits(4, 0.1, 0.9);
583 func3->SetParLimits(1, 0, 10);
584 func3->SetParLimits(2, sigmaFitLimit, 1);
585 func3->SetParLimits(3, sigmaFitLimit, etaFitUpperLimit);
586 func3->SetParLimits(5, sigmaFitLimit, 1);
587 func3->SetParLimits(6, sigmaFitLimit, etaFitUpperLimit);
588 func3->FixParameter(0, 0);
590 if (0 && histId == 0)
592 // central --> go to 1 Gaussian only
593 func3->SetParLimits(4, 1, 1);
594 func3->FixParameter(4, 1);
595 func3->FixParameter(5, sigmaFitLimit);
596 func3->FixParameter(6, sigmaFitLimit);
599 // set errors 20% of the value for bins potentially affected by two-track effects
600 // hist->SetBinError(hist->GetXaxis()->FindBin(0.0001), hist->GetYaxis()->FindBin(0.0001), 0.1 * hist->GetBinContent(hist->GetXaxis()->FindBin(0.0001), hist->GetYaxis()->FindBin(0.0001)));
601 // hist->SetBinError(hist->GetXaxis()->FindBin(0.0001), hist->GetYaxis()->FindBin(-0.0001), 0.1 * hist->GetBinContent(hist->GetXaxis()->FindBin(0.0001), hist->GetYaxis()->FindBin(-0.0001)));
602 // hist->SetBinError(hist->GetXaxis()->FindBin(-0.0001), hist->GetYaxis()->FindBin(0.0001), 0.1 * hist->GetBinContent(hist->GetXaxis()->FindBin(-0.0001), hist->GetYaxis()->FindBin(0.0001)));
603 // hist->SetBinError(hist->GetXaxis()->FindBin(-0.0001), hist->GetYaxis()->FindBin(-0.0001), 0.1 * hist->GetBinContent(hist->GetXaxis()->FindBin(-0.0001), hist->GetYaxis()->FindBin(-0.0001)));
605 fitResult = hist->Fit(func3, "0R", "");
606 Printf("Fit result: %d", fitResult);
608 // if both parameters are within 1%, refit with 1 Gaussian only
609 if (TMath::Abs(1.0 - func3->GetParameter(2) / func3->GetParameter(5)) < 0.01 && TMath::Abs(1.0 - func3->GetParameter(3) / func3->GetParameter(6)) < 0.01)
611 Printf("Parameters within 1%%. Refitting with 1 Gaussian...");
613 func3->SetParLimits(4, 1, 1);
614 func3->FixParameter(4, 1);
615 func3->FixParameter(5, sigmaFitLimit);
616 func3->FixParameter(6, sigmaFitLimit);
618 fitResult = hist->Fit(func3, "0R", "");
619 Printf("Fit result: %d", fitResult);
622 // hist->Fit(func3, "I0R", "");
626 if (func3->GetParameter(2) < func3->GetParameter(5))
632 AddPoint(graphs[1][histId], x, TMath::Abs(func3->GetParameter(first)), 0, func3->GetParError(first));
633 AddPoint(graphs[4][histId], x, TMath::Abs(func3->GetParameter(second)), 0, func3->GetParError(second));
635 AddPoint(phiWidthSummary, phiWidthSummary->GetN(), TMath::Abs(func3->GetParameter(first)), 0, func3->GetParError(first));
636 AddPoint(phiWidthSummary, phiWidthSummary->GetN(), TMath::Abs(func3->GetParameter(second)), 0, func3->GetParError(second));
639 AddPoint(graphs[2][histId], x, TMath::Abs(func3->GetParameter(first+1)), 0, func3->GetParError(first+1));
640 AddPoint(graphs[5][histId], x, TMath::Abs(func3->GetParameter(second+1)), 0, func3->GetParError(second+1));
642 AddPoint(etaWidthSummary, etaWidthSummary->GetN(), TMath::Abs(func3->GetParameter(first+1)), 0, func3->GetParError(first+1));
643 AddPoint(etaWidthSummary, etaWidthSummary->GetN(), TMath::Abs(func3->GetParameter(second+1)), 0, func3->GetParError(second+1));
646 AddPoint(graphs[0][histId], x, func3->GetParameter(1), 0, func3->GetParError(1));
648 AddPoint(graphs[3][histId], x, func3->GetParameter(4), 0, func3->GetParError(4));
650 AddPoint(graphs[3][histId], x, 1.0 - func3->GetParameter(4), 0, func3->GetParError(4));
652 TH2* funcHist3 = (TH2*) hist->Clone("funcHist3");
654 funcHist3->Add(func3);
655 funcHist3->SetMinimum(-(max - min) / 2);
656 funcHist3->SetMaximum((max - min) / 2);
657 funcHist3->Draw("SURF1");
658 sumSummary->SetPoint(sumSummary->GetN(), sumSummary->GetN(), funcHist3->Integral());
660 canvas->cd(canvasPos++);
661 TH2* residuals3 = (TH2*) hist->Clone("residuals");
662 residuals3->Add(funcHist3, -1);
663 residuals3->SetMinimum(-(max - min) / 2);
664 residuals3->SetMaximum((max - min) / 2);
665 residuals3->Draw("SURF1");
669 for (Int_t i=hist->GetXaxis()->FindBin(-0.8); i<=hist->GetXaxis()->FindBin(0.8); i++)
670 for (Int_t j=hist->GetYaxis()->FindBin(-etaLimit); j<=hist->GetYaxis()->FindBin(etaLimit); j++)
672 if (residuals3->GetBinError(i, j) > 0)
674 chi2 += TMath::Power(residuals3->GetBinContent(i, j) / residuals3->GetBinError(i, j), 2);
678 ndf -= func3->GetNumberFreeParameters();
680 if (func3->GetNDF() > 0)
682 printf("#chi^{2}/ndf = %.1f/%d = %.1f ", func3->GetChisquare(), func3->GetNDF(), func3->GetChisquare() / func3->GetNDF());
683 DrawLatex(0.2, yPosChi2, 1, Form("#chi^{2}/ndf = %.1f/%d = %.1f", func3->GetChisquare(), func3->GetNDF(), func3->GetChisquare() / func3->GetNDF()));
684 AddPoint(graphs[6][histId], x, func3->GetChisquare() / func3->GetNDF(), 0, 0);
688 Printf("#chi^{2}/ndf = %.1f/%d = %.1f", chi2, ndf, chi2 / ndf);
689 DrawLatex(0.2, yPosChi2 - 0.05, 1, Form("#chi^{2}/ndf = %.1f/%d = %.1f", chi2, ndf, chi2 / ndf));
690 AddPoint(graphs[7][histId], x, chi2 / ndf, 0, 0);
693 canvas->cd(canvasPos++);
694 phiWidthSummary->SetMarkerStyle(20);
695 phiWidthSummary->Draw("AP");
698 etaWidthSummary->SetMarkerStyle(21);
699 etaWidthSummary->SetLineColor(2);
700 etaWidthSummary->SetMarkerColor(2);
701 etaWidthSummary->Draw("PSAME");
703 phiWidthSummary->GetYaxis()->SetRangeUser(0, 0.9);
705 canvas->cd(canvasPos++);
706 sumSummary->Draw("*A");
710 void AnalyzeDeltaPhiEtaGap2D(const char* fileName, Int_t method = 1)
712 gROOT->SetBatch(kTRUE);
713 if (!gROOT->IsBatch())
715 Printf("Not in batch mode. Exiting!");
719 CreateGraphStructure();
721 TFile::Open(fileName);
723 Int_t maxLeadingPt = 3;
724 Int_t maxAssocPt = 6;
726 for (Int_t histId = 0; histId < NHists; histId++)
728 for (Int_t i=0; i<maxLeadingPt; i++)
730 for (Int_t j=1; j<maxAssocPt; j++)
732 // if (i != 1 || j != 2)
735 TH2* hist1 = (TH2*) gFile->Get(Form("dphi_%d_%d_%d", i, j+1, histId));
739 if (hist1->GetEntries() < 1e4)
741 Printf("Only %f entries. Skipping...", hist1->GetEntries());
745 TCanvas* canvas = new TCanvas(Form("DeltaPhi_%d_%d_%d_%d", histId, i, j, method), Form("DeltaPhi_%d_%d_%d_%d", histId, i, j, method), 1400, 1100);
746 canvas->Divide(5, 3);
748 Printf("\n\n>>> %d %d %d", i, j, histId);
750 for (Int_t k=1; k<=3; k++)
752 canvas->cd(3 * j + k);
753 gPad->SetLeftMargin(0.15);
754 gPad->SetBottomMargin(0.2);
755 gPad->SetTopMargin(0.01);
756 gPad->SetRightMargin(0.01);
760 labelList->Add(new TObjString(hist1->GetTitle()));
762 // hist1->Rebin2D(2, 1);
764 Float_t xPos = j*8+i;
767 FitDeltaPhiEtaGap2D((TH2*) hist1, kFALSE, canvas, 1, width, xPos, 0.9, graphs[6][histId], graphs[7][histId]);
769 FitDeltaPhi2DOneFunction((TH2*) hist1, canvas, 1, xPos, 0.9, kTRUE, histId, (i > 0) ? 1 : 0, (j <= 2 && histId != 2));
771 // canvas->SaveAs(Form("%s.png", canvas->GetName()));
786 void AnalyzeDeltaPhiEtaGap2DExample(const char* fileName, Int_t i, Int_t j, Int_t histId, Bool_t drawDetails = kFALSE)
788 CreateGraphStructure();
790 TFile::Open(fileName);
792 TH2* hist1 = (TH2*) gFile->Get(Form("dphi_%d_%d_%d", i, j+1, histId));
796 Printf("Entries: %f %s", hist1->GetEntries(), hist1->GetTitle());
799 hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
800 hist1->GetXaxis()->SetTitleOffset(1.5);
801 hist1->GetYaxis()->SetTitleOffset(2);
802 hist1->SetStats(kFALSE);
804 if (hist1->GetEntries() < 1e4)
807 TCanvas* canvas = new TCanvas(Form("DeltaPhi_%d_%d_%d_%d", histId, i, j, 1), Form("DeltaPhi_%d_%d_%d_%d", histId, i, j, 1), 1400, 1100);
808 canvas->Divide(5, 3);
810 Float_t xPos = j*8+i;
812 FitDeltaPhi2DOneFunction((TH2*) hist1, canvas, 1, xPos, 0.9, kFALSE, histId, (i > 0) ? 1 : 0, (j <= 2 && histId != 2));
817 TVirtualPad* pad = canvas->cd(6);
818 TCanvas* c = new TCanvas("c", "c", 800, 800);
819 pad->SetPad(0.05, 0, 1, 1);
821 c->SaveAs("fit_subtracted.eps");
823 pad = canvas->cd(12);
824 c = new TCanvas("c2", "c2", 800, 800);
825 pad->SetPad(0.05, 0, 1, 1);
827 c->SaveAs("fit_fit1.eps");
829 pad = canvas->cd(13);
830 c = new TCanvas("c3", "c3", 800, 800);
831 gPad->SetLeftMargin(0.15);
832 pad->SetPad(0.05, 0, 1, 1);
834 c->SaveAs("fit_residual1.eps");
837 c = new TCanvas("c4", "c4", 800, 800);
838 pad->SetPad(0.05, 0, 1, 1);
840 c->SaveAs("fit_fit2.eps");
843 c = new TCanvas("c5", "c5", 800, 800);
844 pad->SetPad(0.05, 0, 1, 1);
846 c->SaveAs("fit_residual2.eps");
849 c = new TCanvas("c6", "c6", 800, 800);
850 pad->SetPad(0.05, 0, 1, 1);
852 c->SaveAs("fit_differences.eps");
855 void SqrtAll(Int_t nHists, TGraphErrors** graph)
857 for (Int_t histId = 0; histId < nHists; histId++)
859 for (Int_t i=0; i<graph[histId]->GetN(); i++)
861 if (graph[histId]->GetY()[i] > 0)
863 graph[histId]->GetEY()[i] *= 0.5 / TMath::Sqrt(graph[histId]->GetY()[i]);
864 graph[histId]->GetY()[i] = TMath::Sqrt(graph[histId]->GetY()[i]);
870 Int_t marker[6] = { 24, 25, 26, 30, 27, 28 };
871 Int_t marker2[6] = { 20, 21, 22, 29, 33, 34 };
872 const char* labels[6] = { "0-5%", "60-90%", "pp", "20-30%", "10-20%", "40-60%" };
874 void Draw(const char* canvasName, Int_t nHists, TGraphErrors** graph, TGraphErrors** graph2 = 0, Bool_t normalize = kFALSE, Float_t min = 0, Float_t max = 0)
876 Int_t colors[6] = { 1, 2, 4, 6, 7, 8 };
877 Bool_t found = kTRUE;
878 TCanvas* c1 = (TCanvas*) gROOT->GetListOfCanvases()->FindObject(canvasName);
881 c1 = new TCanvas(canvasName, canvasName, 800, 600);
887 if (normalize && graph2)
890 for (Int_t histId = 0; histId < nHists; histId++)
892 for (Int_t i=0; i<graph[histId]->GetN(); i++)
894 Float_t sum = graph[histId]->GetY()[i] + graph2[histId]->GetY()[i];
895 graph[histId]->GetY()[i] /= sum;
896 graph2[histId]->GetY()[i] /= sum;
897 graph[histId]->GetEY()[i] /= sum;
898 graph2[histId]->GetEY()[i] /= sum;
903 for (Int_t histId = 0; histId < nHists; histId++)
905 graph[histId]->SetMarkerStyle((found) ? marker2[histId] : marker[histId]);
906 graph[histId]->SetMarkerColor(colors[histId]);
907 graph[histId]->SetLineColor(colors[histId]);
909 graph[histId]->GetYaxis()->SetRangeUser(0, 1);
911 graph[histId]->GetYaxis()->SetRangeUser(min, max);
912 graph[histId]->GetXaxis()->SetRangeUser(7, 38);
913 graph[histId]->DrawClone((histId == 0 && !found) ? "AP" : "PSAME");
914 DrawLatex(0.7, 0.8 - 0.05 * histId, colors[histId], labels[histId]);
919 for (Int_t histId = 0; histId < nHists; histId++)
921 graph2[histId]->SetMarkerStyle(marker2[histId]);
922 graph2[histId]->SetMarkerColor(colors[histId]);
923 graph2[histId]->SetLineColor(colors[histId]);
924 graph2[histId]->DrawClone("PSAME");
930 c1->SaveAs(Form("%s.png", canvasName));
933 void CalculateRMS(Int_t nHists, TGraphErrors** graph, TGraphErrors** graph2, TGraphErrors** weight)
936 for (Int_t histId = 0; histId < nHists; histId++)
938 for (Int_t i=0; i<graph[histId]->GetN(); i++)
940 Float_t rms = graph[histId]->GetY()[i] * weight[histId]->GetY()[i] + graph2[histId]->GetY()[i] * (1.0 - weight[histId]->GetY()[i]);
941 graph[histId]->GetY()[i] = rms;
942 // error**2 = weight**2 * error_sigma**2 + (weight-1)**2 * error_sigma2**2 + (sigma1 + sigma2)**2 * error_weight**2
943 // TODO this neglects some correlations
944 graph[histId]->GetEY()[i] = TMath::Sqrt(TMath::Power(weight[histId]->GetY()[i] * graph[histId]->GetEY()[i], 2) +
945 TMath::Power((weight[histId]->GetY()[i] - 1) * graph2[histId]->GetEY()[i], 2) + TMath::Power((graph[histId]->GetY()[i] + graph2[histId]->GetY()[i]) * weight[histId]->GetEY()[i], 2));
950 void DrawRMS(const char* canvasName, Int_t nHists, TGraphErrors** graph, TGraphErrors** graph2, TGraphErrors** weight, Float_t min = 0, Float_t max = 0)
952 Int_t colors[6] = { 2, 2, 4, 6, 7, 8 };
953 Bool_t found = kTRUE;
954 TCanvas* c1 = (TCanvas*) gROOT->GetListOfCanvases()->FindObject(canvasName);
957 c1 = new TCanvas(canvasName, canvasName, 800, 600);
963 for (Int_t histId = 0; histId < nHists; histId++)
965 graph[histId]->SetMarkerStyle(marker[histId]);
966 graph[histId]->SetMarkerColor(colors[histId]);
967 graph[histId]->SetLineColor(colors[histId]);
969 graph[histId]->GetYaxis()->SetRangeUser(min, max);
970 graph[histId]->DrawClone((histId == 0 && !found) ? "AP" : "PSAME");
971 DrawLatex(0.7, 0.8 - 0.05 * histId, colors[histId], labels[histId]);
973 graph2[histId]->SetMarkerStyle(marker2[histId]);
974 graph2[histId]->SetMarkerColor(colors[histId]);
975 graph2[histId]->SetLineColor(colors[histId]);
976 graph2[histId]->DrawClone("PSAME");
979 CalculateRMS(nHists, graph, graph2, weight);
982 for (Int_t histId = 0; histId < nHists; histId++)
983 graph[histId]->DrawClone("*SAME");
987 c1->SaveAs(Form("%s.png", canvasName));
990 TGraphErrors* GetCentralityGraph(Int_t nHists, TGraphErrors** graph, Int_t point)
992 TGraphErrors* graphcentrality = new TGraphErrors;
994 Float_t centralityAxisMapping[] = { 5, 75, 100, 30, 15, 50 };
995 Float_t centralityAxisMappingE[] = { 5, 15, 0, 10, 5, 10 };
997 for (Int_t histId = 0; histId < nHists; histId++)
1000 while (j < graph[histId]->GetN() && TMath::Abs(graph[0]->GetX()[point] - graph[histId]->GetX()[j]) > 0.1)
1002 if (j == graph[histId]->GetN())
1005 // Printf("%d %d %f %f %f %f", point, histId, graph[0]->GetX()[point], graph[histId]->GetX()[j], graph[0]->GetY()[point], graph[histId]->GetY()[j]);
1006 if (TMath::Abs(graph[0]->GetX()[point] - graph[histId]->GetX()[j]) > 0.1)
1008 AddPoint(graphcentrality, centralityAxisMapping[histId], graph[histId]->GetY()[j], centralityAxisMappingE[histId], graph[histId]->GetEY()[j]);
1009 // Printf("%f %f", graph[histId]->GetY()[i], graph[histId]->GetEY()[i]);
1010 // graphcentrality->Print();
1013 graphcentrality->Sort();
1014 return graphcentrality;
1017 void PrepareGraphs(Int_t nHists, TGraphErrors** graph, TGraphErrors** systematic, TMultiGraph** multiGraph, TMultiGraph** multiGraphSyst)
1019 Int_t colors[] = { 1, 2, 3, 4, 6, 7, 8, 9 };
1020 Int_t markers[] = { 20, 21, 22, 23, 24, 26, 27, 28 };
1021 Int_t fillStyle[] = { 3001, 3002, 3003, 3004, 3005, 3006, 3007, 3008, 3009 };
1024 Int_t beginWith = 0;
1026 if (*multiGraph == 0)
1027 *multiGraph = new TMultiGraph;
1028 if (*multiGraphSyst == 0)
1029 *multiGraphSyst = new TMultiGraph;
1031 for (Int_t i=beginWith; i<graph[0]->GetN(); i++)
1033 Int_t xPos = (Int_t) graph[0]->GetX()[i];
1034 if (xPos == 24 || xPos == 33 || xPos == 34 || xPos == 41 || xPos == 26)
1036 Printf("%d %i", i, xPos);
1038 TGraphErrors* graphcentrality = GetCentralityGraph(nHists, graph, i);
1042 TGraphErrors* graphsystematics = GetCentralityGraph(nHists, systematic, i);
1044 if (graphcentrality->GetN() != graphsystematics->GetN())
1046 Printf("Different number of points %d %d", graphcentrality->GetN(), graphsystematics->GetN());
1050 for (Int_t j=0; j<=graphsystematics->GetN(); j++)
1052 graphsystematics->GetEY()[j] = TMath::Abs(graphcentrality->GetY()[j] - graphsystematics->GetY()[j]) / 2;
1053 graphsystematics->GetY()[j] = (graphcentrality->GetY()[j] + graphsystematics->GetY()[j]) / 2;
1054 graphsystematics->GetEX()[j] = 1;
1057 // graphsystematics->SetFillColor(kGray);
1058 graphsystematics->SetFillColor(colors[count]);
1059 // graphsystematics->SetFillStyle(1001);
1060 graphsystematics->SetFillStyle(fillStyle[count]);
1061 graphsystematics->SetMarkerStyle(0);
1062 graphsystematics->SetLineColor(0);
1063 (*multiGraphSyst)->Add(graphsystematics, "2");
1066 graphcentrality->SetMarkerStyle(markers[count]);
1067 graphcentrality->SetMarkerColor(colors[count]);
1068 graphcentrality->SetLineColor(colors[count]);
1070 (*multiGraph)->Add(graphcentrality);
1072 TString label = (labelList && i < labelList->GetEntries()) ? labelList->At(i)->GetName() : "";
1073 if (label.Length() > 0)
1075 TObjArray* tokens = label.Tokenize("-");
1076 label.Form("%s-%s", tokens->At(0)->GetName(),tokens->At(1)->GetName());
1077 label.ReplaceAll(".00", "");
1078 label.ReplaceAll(".0", "");
1080 graphcentrality->SetTitle(label);
1086 void DrawCentrality(const char* canvasName, Int_t nHists, TGraphErrors** graph, Float_t min = 0, Float_t max = 0, const char* yLabel = "", TGraphErrors** systematic = 0, TGraphErrors** graph2 = 0, TGraphErrors** systematic2 = 0)
1088 Bool_t found = kTRUE;
1089 TCanvas* c1 = (TCanvas*) gROOT->GetListOfCanvases()->FindObject(canvasName);
1092 c1 = new TCanvas(canvasName, canvasName, 800, 600);
1097 TMultiGraph* multiGraph = 0;
1098 TMultiGraph* multiGraphSyst = 0;
1100 PrepareGraphs(nHists, graph, systematic, &multiGraph, &multiGraphSyst);
1101 TLegend* legend = new TLegend(0.65, 0.65, 0.95, 0.95);
1102 legend->SetFillColor(0);
1103 for (Int_t i=0; i<multiGraph->GetListOfGraphs()->GetEntries(); i++)
1104 legend->AddEntry(multiGraph->GetListOfGraphs()->At(i), 0, "PL");
1108 TMultiGraph* multiGraph2 = 0;
1109 PrepareGraphs(nHists, graph2, systematic2, &multiGraph2, &multiGraphSyst);
1110 for (Int_t i=0; i<multiGraph2->GetListOfGraphs()->GetEntries(); i++)
1111 ((TGraph*)multiGraph2->GetListOfGraphs()->At(i))->SetLineWidth(2);
1113 while (multiGraph2->GetListOfGraphs()->GetEntries() > multiGraph->GetListOfGraphs()->GetEntries())
1114 multiGraph2->GetListOfGraphs()->RemoveAt(multiGraph->GetListOfGraphs()->GetEntries());
1117 multiGraphSyst->Add(multiGraph2, "LX");
1120 multiGraphSyst->Add(multiGraph, (found) ? "LX" : "P");
1122 TString drawString("A");
1123 multiGraphSyst->Draw(drawString);
1124 multiGraphSyst->GetXaxis()->SetTitle("Centrality");
1125 multiGraphSyst->GetYaxis()->SetTitle(yLabel);
1127 multiGraphSyst->GetYaxis()->SetRangeUser(min, max);
1133 c1->SaveAs(Form("results/%s.png", canvasName));
1134 // c1->SaveAs(Form("%s.eps", canvasName));
1137 void DrawResults(const char* fileName = "graphs.root")
1139 ReadGraphs(fileName);
1147 Draw("width_phi", nHists, graphs[1], graphs[4], kFALSE, 0, 0.8);
1148 Draw("width_eta", nHists, graphs[2], graphs[5], kFALSE, 0, 0.8);
1149 Draw("norm", nHists, graphs[0], graphs[3], kFALSE, 0, 1);
1150 Draw("chi2", nHists, graphs[6], graphs[7], kFALSE, 0.5, 2.5);
1151 DrawRMS("width_phi_rms", nHists, graphs[1], graphs[4], graphs[3], 0, 0.8);
1152 DrawRMS("width_eta_rms", nHists, graphs[2], graphs[5], graphs[3], 0, 0.8);
1155 Draw("moment2", nHists, graphs[8], graphs[9], kFALSE, 0, 0.3);
1156 Draw("moment3", nHists, graphs[10], graphs[11], kFALSE, -0.05, 0.05);
1157 Draw("moment4", nHists, graphs[12], graphs[13], kFALSE, -0.1, 0.2);
1158 Draw("kurtosis", nHists, graphs[14], graphs[15], kFALSE, -2, 2);
1159 Draw("kurtosisphi", nHists, graphs[14], 0, kFALSE, -2, 2);
1160 Draw("kurtosiseta", nHists, graphs[15], 0, kFALSE, -2, 2);
1163 void DrawResultsCentrality(const char* fileName = "graphs.root")
1165 ReadGraphs(fileName);
1171 DrawCentrality("norm", nHists, graphs[0], 0, 0.2, "N (a.u.)", graphs[0+16]);
1173 DrawCentrality("width_phi1_centrality", nHists, graphs[1], 0, 0.8, "#sigma_{#phi, 1} (rad.)", graphs[1+16]);
1175 DrawCentrality("width_phi2_centrality", nHists, graphs[4], 0, 0.8, "#sigma_{#phi, 2} (rad.)", graphs[4+16]);
1176 DrawCentrality("width_eta1_centrality", nHists, graphs[2], 0, 0.8, "#sigma_{#eta, 1} (rad.)", graphs[2+16]);
1177 DrawCentrality("width_eta2_centrality", nHists, graphs[5], 0, 0.8, "#sigma_{#eta, 2} (rad.)", graphs[5+16]);
1179 CalculateRMS(nHists, graphs[1], graphs[4], graphs[3]);
1180 CalculateRMS(nHists, graphs[2], graphs[5], graphs[3]);
1182 CalculateRMS(nHists, graphs[1+16], graphs[4+16], graphs[3+16]);
1183 CalculateRMS(nHists, graphs[2+16], graphs[5+16], graphs[3+16]);
1185 DrawCentrality("phi_rms_centrality", nHists, graphs[1], 0, 0.8, "#sigma_{#phi} (fit) (rad.)", graphs[1+16]);
1186 DrawCentrality("eta_rms_centrality", nHists, graphs[2], 0, 0.8, "#sigma_{#eta} (fit)", graphs[2+16]);
1188 DrawCentrality("chi2_1", nHists, graphs[6], 0.5, 2.5, "#chi^2/ndf (full region)");
1189 DrawCentrality("chi2_2", nHists, graphs[7], 0.5, 2.5, "#chi^2/ndf (peak region)");
1191 // sqrt(moment2) = sigma
1192 SqrtAll(nHists, graphs[8]);
1193 SqrtAll(nHists, graphs[9]);
1194 SqrtAll(nHists, graphs[8+16]);
1195 SqrtAll(nHists, graphs[9+16]);
1196 DrawCentrality("sigma_phi", nHists, graphs[8], 0, 0.8, "#sigma_{#phi} (rad.)", graphs[8+16]);
1197 DrawCentrality("sigma_eta", nHists, graphs[9], 0, 0.8, "#sigma_{#eta}", graphs[9+16]);
1200 DrawCentrality("kurtosisphi_centrality", nHists, graphs[14], -2, 4, "Kurtosis #phi", graphs[14+16]);
1201 DrawCentrality("kurtosiseta_centrality", nHists, graphs[15], -2, 4, "Kurtosis #eta", graphs[15+16]);
1204 void DrawRMSCentrality(const char* fileNameData, const char* fileNameHijing)
1208 ReadGraphs(fileNameHijing);
1212 while (n++ < graphs[0][0]->GetN())
1214 // Printf("%d %f", n, graphs[0][0]->GetX()[n]); continue;
1215 if (graphs[0][0]->GetX()[n] == 42)
1217 for (Int_t i=0; i<NGraphs; i++)
1218 graphs[i][0]->RemovePoint(n);
1225 CalculateRMS(nHists, graphs[1], graphs[4], graphs[3]);
1226 CalculateRMS(nHists, graphs[2], graphs[5], graphs[3]);
1228 CalculateRMS(nHists, graphs[1+16], graphs[4+16], graphs[3+16]);
1229 CalculateRMS(nHists, graphs[2+16], graphs[5+16], graphs[3+16]);
1231 // DrawCentrality("phi_rms_centrality", nHists, graphs[1], 0, 0.8, "#sigma_{#phi} (fit) (rad.)");
1234 TGraphErrors*** graphs1 = graphs;
1236 ReadGraphs(fileNameData);
1238 //Remove high trigger pT:18.26,34,42
1242 while (n++ < graphs[0][0]->GetN())
1244 // Printf("%d %f", n, graphs[0][0]->GetX()[n]); continue;
1245 if (graphs[0][0]->GetX()[n] == 18 || graphs[0][0]->GetX()[n] == 10) // || graphs[0][0]->GetX()[n] == 34 || graphs[0][0]->GetX()[n] == 42
1247 for (Int_t i=0; i<NGraphs; i++)
1249 graphs[i][0]->RemovePoint(n);
1256 CalculateRMS(nHists, graphs[1], graphs[4], graphs[3]);
1257 CalculateRMS(nHists, graphs[2], graphs[5], graphs[3]);
1259 CalculateRMS(nHists, graphs[1+16], graphs[4+16], graphs[3+16]);
1260 CalculateRMS(nHists, graphs[2+16], graphs[5+16], graphs[3+16]);
1262 DrawCentrality("phi_rms_centrality_mc", nHists, graphs[1], 0, 0.8, "#sigma_{#phi} (fit) (rad.)", graphs[1+16], graphs1[1]);
1263 DrawCentrality("eta_rms_centrality_mc", nHists, graphs[2], 0, 0.8, "#sigma_{#eta} (fit)", graphs[2+16], graphs1[2]);
1265 DrawCentrality("kurtosisphi_centrality_mc", nHists, graphs[14], -2, 4, "Kurtosis #phi", graphs[14+16], graphs1[14]);
1266 DrawCentrality("kurtosiseta_centrality_mc", nHists, graphs[15], -2, 4, "Kurtosis #eta", graphs[15+16], graphs1[15]);
1269 void CompareRMS(const char* graphFileName1, const char* graphFileName2)
1271 ReadGraphs(graphFileName1);
1275 DrawRMS("width_phi_rms1", nHists, graphs[1], graphs[4], graphs[3], 0, 0.8);
1276 DrawRMS("width_eta_rms1", nHists, graphs[2], graphs[5], graphs[3], 0, 0.8);
1278 Draw("width_phi_rms_compare", nHists, graphs[1], 0, kFALSE, 0, 0.8);
1279 Draw("width_eta_rms_compare", nHists, graphs[2], 0, kFALSE, 0, 0.8);
1281 ReadGraphs(graphFileName2);
1282 DrawRMS("width_phi_rms2", nHists, graphs[1], graphs[4], graphs[3], 0, 0.8);
1283 DrawRMS("width_eta_rms2", nHists, graphs[2], graphs[5], graphs[3], 0, 0.8);
1285 Draw("width_phi_rms_compare", nHists, graphs[1], 0, kFALSE, 0, 0.8);
1286 Draw("width_eta_rms_compare", nHists, graphs[2], 0, kFALSE, 0, 0.8);
1289 void CompareEtaPhi(const char* graphFileName1)
1291 ReadGraphs(graphFileName1);
1295 CalculateRMS(nHists, graphs[1], graphs[4], graphs[3]);
1296 CalculateRMS(nHists, graphs[2], graphs[5], graphs[3]);
1298 CalculateRMS(nHists, graphs[1+16], graphs[4+16], graphs[3+16]);
1299 CalculateRMS(nHists, graphs[2+16], graphs[5+16], graphs[3+16]);
1301 DrawCentrality("rms_centrality", nHists, graphs[1], 0, 0.8, "#sigma_{#phi} (fit) (rad.) / #sigma_{#eta}", graphs[1+16], graphs[2], graphs[2+16]);
1302 DrawCentrality("rms_centrality_nosyst", nHists, graphs[1], 0, 0.8, "#sigma_{#phi} (fit) (rad.) / #sigma_{#eta}", 0, graphs[2], 0);
1305 void DrawExamples(const char* histFileName, const char* graphFileName, Bool_t drawFunc = kTRUE)
1307 Float_t etaLimit = 1.0;
1308 Float_t outerLimit = 1.79;
1309 Float_t projectLimit = 0.8;
1311 ReadGraphs(graphFileName);
1313 TFile::Open(histFileName);
1317 Int_t exColors[] = { 1, 2, 4, 6 };
1319 for (Int_t i=0; i<6; i++)
1321 TCanvas* c = new TCanvas(Form("c_%d", i), Form("c_%d", i), 1000, 600);
1324 for (Int_t histId = 0; histId < nHists; histId++)
1326 TH2* hist = (TH2*) gFile->Get(Form("dphi_%d_%d_%d", i, j+1, histId));
1330 Float_t xPos = j*8+i;
1332 while ( n < graphs[0][histId]->GetN() && graphs[0][histId]->GetX()[n] != xPos)
1334 if (n == graphs[0][histId]->GetN())
1336 Printf("ERROR: Pos in graph not found: %d %d", i, histId);
1340 SubtractEtaGap(hist, etaLimit, outerLimit, kFALSE, kFALSE);
1343 TH1* proj = hist->ProjectionX(Form("%s_proj1", hist->GetName()), hist->GetYaxis()->FindBin(-projectLimit+0.01), hist->GetYaxis()->FindBin(projectLimit-0.01));
1344 proj->SetLineColor(exColors[histId]);
1345 proj->GetXaxis()->SetRangeUser(-1.49, 1.49);
1346 proj->GetYaxis()->SetRangeUser(proj->GetMinimum() * 1.2, proj->GetMaximum() * 1.5);
1347 proj->Draw((histId == 0) ? "" : "SAME");
1352 TF1* func = new TF1("func", "[0]+[1]*([4]/[2]/TMath::Sqrt(TMath::TwoPi())*exp(-0.5*(x/[2])**2)+(1-[4])/[5]/TMath::Sqrt(TMath::TwoPi())*exp(-0.5*(x/[5])**2))", -0.5 * TMath::Pi(), 0.5 * TMath::Pi());
1353 func->SetParameter(0, 0);
1354 for (Int_t k=0; k<6; k++)
1355 func->SetParameter(k+1, graphs[k][histId]->GetY()[n]);
1356 // scale by bin width (to compare with projection)
1357 func->SetParameter(1, func->GetParameter(1) / hist->GetYaxis()->GetBinWidth(1));
1358 func->SetLineColor(exColors[histId]);
1359 func->SetLineWidth(1);
1360 func->DrawCopy("SAME");
1362 // draw contributions
1363 Float_t scale = func->GetParameter(1);
1364 Float_t weighting = func->GetParameter(4);
1365 func->SetParameter(1, scale * weighting);
1366 func->SetParameter(4, 1);
1367 func->SetLineStyle(2);
1368 func->DrawCopy("SAME");
1370 func->SetParameter(1, scale * (1.0-weighting));
1371 func->SetParameter(4, 0);
1372 func->SetLineStyle(3);
1373 func->DrawCopy("SAME");
1376 DrawLatex(0.15, 0.8 - 0.05 * histId, exColors[histId], labels[histId]);
1379 proj = hist->ProjectionY(Form("%s_proj2b", hist->GetName()), hist->GetXaxis()->FindBin(-projectLimit+0.01), hist->GetXaxis()->FindBin(projectLimit-0.01));
1380 proj->SetLineColor(exColors[histId]);
1381 proj->GetXaxis()->SetRangeUser(-1.49, 1.49);
1382 proj->GetYaxis()->SetRangeUser(proj->GetMinimum() * 1.2, proj->GetMaximum() * 2);
1383 proj->Draw((histId == 0) ? "" : "SAME");
1387 proj = hist->ProjectionY(Form("%s_proj2", hist->GetName()), hist->GetXaxis()->FindBin(-0.5 * TMath::Pi()), hist->GetXaxis()->FindBin(0.5 * TMath::Pi()));
1388 proj->SetLineColor(exColors[histId]);
1389 proj->GetXaxis()->SetRangeUser(-1.2, 1.2);
1390 proj->GetYaxis()->SetRangeUser(proj->GetMinimum() * 1.2, proj->GetMaximum() * 2);
1391 proj->SetLineStyle(2);
1398 TF1* func = new TF1("func", "[0]+[1]*([4]/[3]/TMath::Sqrt(TMath::TwoPi())*exp(-0.5*(x/[3])**2)+(1-[4])/[6]/TMath::Sqrt(TMath::TwoPi())*exp(-0.5*(x/[6])**2))", -outerLimit, outerLimit);
1399 func->SetParameter(0, 0);
1400 for (Int_t k=0; k<6; k++)
1401 func->SetParameter(k+1, graphs[k][histId]->GetY()[n]);
1402 // scale by bin width (to compare with projection)
1403 func->SetParameter(1, func->GetParameter(1) / hist->GetXaxis()->GetBinWidth(1));
1404 func->SetLineColor(exColors[histId]);
1405 func->SetLineWidth(1);
1406 func->DrawCopy("SAME");
1408 // draw contributions
1409 Float_t scale = func->GetParameter(1);
1410 Float_t weighting = func->GetParameter(4);
1411 func->SetParameter(1, scale * weighting);
1412 func->SetParameter(4, 1);
1413 func->SetLineStyle(2);
1414 func->DrawCopy("SAME");
1416 func->SetParameter(1, scale * (1.0-weighting));
1417 func->SetParameter(4, 0);
1418 func->SetLineStyle(3);
1419 func->DrawCopy("SAME");
1422 DrawLatex(0.15, 0.8 - 0.05 * histId, exColors[histId], labels[histId]);
1427 void DrawExample(const char* histFileName, Int_t i, Int_t j, Int_t histId, TH1** projPhi, TH1** projEta)
1429 Float_t etaLimit = 1.0;
1430 Float_t outerLimit = 1.6;
1431 Float_t projectLimit = 0.8;
1433 TFile::Open(histFileName);
1435 TCanvas* c = new TCanvas(Form("ex_%d_%d_%d", i, j, histId), Form("ex_%d_%d_%d", i, j, histId), 1200, 400);
1438 TH2* hist = (TH2*) gFile->Get(Form("dphi_%d_%d_%d", i, j+1, histId));
1442 TString label(hist->GetTitle());
1443 label.ReplaceAll(".00", ".0");
1444 TObjArray* objArray = label.Tokenize("-");
1445 TPaveText* paveText = new TPaveText(0.52, 0.72, 0.95, 0.9, "BRNDC");
1446 paveText->SetTextSize(0.04);
1447 paveText->SetFillColor(0);
1448 paveText->SetShadowColor(0);
1449 paveText->AddText(objArray->At(0)->GetName());
1450 paveText->AddText(objArray->At(1)->GetName());
1451 if (objArray->GetEntries() == 4)
1452 paveText->AddText(Form("Pb-Pb %s-%s", objArray->At(2)->GetName(), objArray->At(3)->GetName()));
1454 paveText->AddText(objArray->At(2)->GetName());
1457 hist->GetXaxis()->SetRangeUser(-TMath::Pi() / 2, TMath::Pi() / 2);
1458 hist->GetYaxis()->SetRangeUser(-outerLimit, outerLimit);
1459 hist->GetXaxis()->SetTitleOffset(1.5);
1460 hist->GetYaxis()->SetTitleOffset(1.5);
1462 hist->SetTitle("a) Correlation");
1463 hist->DrawCopy("SURF1");
1466 SubtractEtaGap(hist, etaLimit, outerLimit, kFALSE, kFALSE);
1468 hist->SetTitle("b) #eta-gap subtracted");
1469 hist->DrawCopy("SURF1");
1472 TH1* proj = hist->ProjectionX(Form("%s_proj1", hist->GetName()), hist->GetYaxis()->FindBin(-projectLimit+0.01), hist->GetYaxis()->FindBin(projectLimit-0.01));
1473 TH1* proj2 = hist->ProjectionY(Form("%s_proj2b", hist->GetName()), hist->GetXaxis()->FindBin(-projectLimit+0.01), hist->GetXaxis()->FindBin(projectLimit-0.01));
1476 proj->SetTitle("c) Projections");
1477 proj->GetXaxis()->SetRangeUser(-1.49, 1.49);
1478 proj->GetXaxis()->SetTitleOffset(1);
1479 proj->GetYaxis()->SetRangeUser(proj->GetMinimum(), proj->GetMaximum() * 1.4);
1480 TH1* copy = proj->DrawCopy();
1481 copy->GetXaxis()->SetTitle(Form("%s / %s", proj->GetXaxis()->GetTitle(), proj2->GetXaxis()->GetTitle()));
1482 DrawLatex(0.3, 0.85, 1, Form("#Delta#phi projection in |#Delta#eta| < %.1f", projectLimit), 0.04);
1484 proj2->SetLineColor(2);
1486 proj2->GetXaxis()->SetTitleOffset(1);
1487 proj2->GetYaxis()->SetRangeUser(proj2->GetMinimum(), proj2->GetMaximum() * 1.6);
1488 proj2->DrawCopy("SAME");
1489 DrawLatex(0.3, 0.80, 2, Form("#Delta#eta projection in |#Delta#phi| < %.1f", projectLimit), 0.04);
1491 proj->SetTitle(label);
1492 proj2->SetTitle(label);
1497 c->SaveAs(Form("ex/%s.png", c->GetName()));
1498 c->SaveAs(Form("ex/%s.eps", c->GetName()));
1500 c = new TCanvas(Form("ex_%d_%d_%d_a", i, j, histId), Form("ex_%d_%d_%d_a", i, j, histId), 400, 400);
1502 hist->DrawCopy("SURF1");
1504 c->SaveAs(Form("ex/%s.png", c->GetName()));
1505 c->SaveAs(Form("ex/%s.eps", c->GetName()));
1508 void DrawExampleAll(const char* histFileName)
1510 Int_t colors[] = { 1, 2, 4 };
1512 Float_t exampleI[] = { 0, 1, 2 };
1513 Float_t exampleJ[] = { 1, 2, 3 };
1515 TH1* projectionsPhi[9];
1516 TH1* projectionsEta[9];
1519 for (Int_t i=0; i<3; i++)
1521 for (Int_t histId = 0; histId<3; histId++)
1523 DrawExample(histFileName, exampleI[i], exampleJ[i], histId, &projectionsPhi[count], &projectionsEta[count]);
1527 TCanvas* c = new TCanvas(Form("centralities_%d", i), Form("centralities_%d", i), 800, 400);
1530 TLegend* legend = new TLegend(0.62, 0.7, 0.88, 0.88);
1531 legend->SetFillColor(0);
1533 for (Int_t histId = 0; histId<3; histId++)
1536 TH1* clone = projectionsPhi[count-3+histId]->DrawCopy((histId > 0) ? "SAME" : "");
1537 clone->SetLineColor(colors[histId]);
1539 TString label(clone->GetTitle());
1540 TObjArray* objArray = label.Tokenize("-");
1541 clone->SetTitle(Form("%s-%s", objArray->At(0)->GetName(), objArray->At(1)->GetName()));
1543 legend->AddEntry(clone, (objArray->GetEntries() == 4) ? Form("%s-%s", objArray->At(2)->GetName(), objArray->At(3)->GetName()) : objArray->At(2)->GetName(), "L");
1546 clone = projectionsEta[count-3+histId]->DrawCopy((histId > 0) ? "SAME" : "");
1547 clone->SetTitle(Form("%s-%s", objArray->At(0)->GetName(), objArray->At(1)->GetName()));
1548 clone->SetLineColor(colors[histId]);
1553 c->SaveAs(Form("ex/%s.png", c->GetName()));
1554 c->SaveAs(Form("ex/%s.eps", c->GetName()));
1557 for (Int_t histId = 0; histId<3; histId++)
1559 TCanvas* c = new TCanvas(Form("pt_%d", histId), Form("pt_%d", histId), 800, 400);
1562 TLegend* legend = new TLegend(0.15, 0.7, 0.88, 0.88);
1563 legend->SetFillColor(0);
1565 for (Int_t i=2; i>=0; i--)
1568 TH1* clone = projectionsPhi[i*3+histId]->DrawCopy((i < 2) ? "SAME" : "");
1569 clone->SetLineColor(colors[i]);
1570 clone->GetYaxis()->SetRangeUser(clone->GetMinimum(), clone->GetMaximum() * 1.2);
1572 TString label(clone->GetTitle());
1573 TObjArray* objArray = label.Tokenize("-");
1574 clone->SetTitle((objArray->GetEntries() == 4) ? Form("%s-%s", objArray->At(2)->GetName(), objArray->At(3)->GetName()) : objArray->At(2)->GetName());
1576 legend->GetListOfPrimitives()->AddFirst(new TLegendEntry(clone, Form("%s-%s", objArray->At(0)->GetName(), objArray->At(1)->GetName()), "L"));
1579 clone = projectionsEta[i*3+histId]->DrawCopy((i < 2) ? "SAME" : "");
1580 clone->SetTitle((objArray->GetEntries() == 4) ? Form("%s-%s", objArray->At(2)->GetName(), objArray->At(3)->GetName()) : objArray->At(2)->GetName());
1581 clone->SetLineColor(colors[i]);
1582 // clone->GetYaxis()->SetRangeUser(clone->GetMinimum(), clone->GetMaximum() * 1.2);
1588 c->SaveAs(Form("ex/%s.png", c->GetName()));
1589 c->SaveAs(Form("ex/%s.eps", c->GetName()));
1593 void DrawFullCentralityDependence(const char* histFileName)
1595 Int_t colors[] = { 1, 2, 4, 3, 5, 6 };
1597 TH1* projectionsPhi[9];
1598 TH1* projectionsEta[9];
1601 for (Int_t histId = 0; histId<6; histId++)
1603 DrawExample(histFileName, 0, 1, histId, &projectionsPhi[count], &projectionsEta[count]);
1607 TCanvas* c = new TCanvas(Form("centralities_%d", 0), Form("centralities_%d", 0), 800, 400);
1610 TLegend* legend = new TLegend(0.62, 0.7, 0.88, 0.88);
1611 legend->SetFillColor(0);
1613 for (Int_t histId = 0; histId<6; histId++)
1616 TH1* clone = projectionsPhi[count-6+histId]->DrawCopy((histId > 0) ? "SAME" : "");
1617 clone->SetLineColor(colors[histId]);
1619 TString label(clone->GetTitle());
1620 TObjArray* objArray = label.Tokenize("-");
1621 clone->SetTitle(Form("%s-%s", objArray->At(0)->GetName(), objArray->At(1)->GetName()));
1623 legend->AddEntry(clone, (objArray->GetEntries() == 4) ? Form("%s-%s", objArray->At(2)->GetName(), objArray->At(3)->GetName()) : objArray->At(2)->GetName(), "L");
1626 clone = projectionsEta[count-6+histId]->DrawCopy((histId > 0) ? "SAME" : "");
1627 clone->SetTitle(Form("%s-%s", objArray->At(0)->GetName(), objArray->At(1)->GetName()));
1628 clone->SetLineColor(colors[histId]);
1633 c->SaveAs(Form("ex/%s.png", c->GetName()));
1634 c->SaveAs(Form("ex/%s.eps", c->GetName()));
1637 void CompareExamples(const char* histFileName1, const char* histFileName2, Int_t i, Int_t j, Int_t histId, Bool_t twoTrack = kFALSE)
1639 Float_t etaLimit = 1.0;
1640 Float_t outerLimit = 1.79;
1641 Float_t projectLimit = 0.8;
1643 Int_t exColors[] = { 1, 2, 4, 6 };
1645 TCanvas* c = new TCanvas(Form("c_%d", i), Form("c_%d", i), 1000, 600);
1648 for (Int_t k=0; k<2; k++)
1651 TFile::Open(histFileName1);
1653 TFile::Open(histFileName2);
1655 TH2* hist = (TH2*) gFile->Get(Form("dphi_%d_%d_%d", i, j+1, histId));
1660 // hist->Rebin2D(2, 2);
1662 // new TCanvas; hist->DrawCopy("COLZ"); return;
1664 SubtractEtaGap(hist, etaLimit, outerLimit, kFALSE);
1666 // new TCanvas; hist->DrawCopy("COLZ");
1668 // remove bins potentially affected by two-track effects
1671 Printf("NOTE : Skipping bins at (0, 0)");
1672 for (Int_t binx = hist->GetXaxis()->FindBin(-0.25); binx <= hist->GetXaxis()->FindBin(0.25); binx++)
1673 for (Int_t biny = hist->GetYaxis()->FindBin(-0.01); biny <= hist->GetYaxis()->FindBin(0.01); biny++)
1675 hist->SetBinContent(binx, biny, 0);
1676 hist->SetBinError(binx, biny, 0);
1681 TH1* proj = hist->ProjectionX(Form("%s_proj1%d", hist->GetName(), k), hist->GetYaxis()->FindBin(-projectLimit+0.01), hist->GetYaxis()->FindBin(projectLimit-0.01));
1682 proj->SetLineColor(exColors[k]);
1683 proj->GetXaxis()->SetRangeUser(-1.49, 1.49);
1684 proj->GetYaxis()->SetRangeUser(proj->GetMinimum() * 1.2, proj->GetMaximum() * 1.5);
1685 proj->Draw((k == 0) ? "" : "SAME");
1688 proj = hist->ProjectionY(Form("%s_proj2_%d", hist->GetName(), k), hist->GetXaxis()->FindBin(-projectLimit+0.01), hist->GetXaxis()->FindBin(projectLimit-0.01));
1689 proj->SetLineColor(exColors[k]);
1690 proj->GetXaxis()->SetRangeUser(-1.49, 1.49);
1691 proj->GetYaxis()->SetRangeUser(proj->GetMinimum() * 1.2, proj->GetMaximum() * 2);
1692 proj->Draw((k == 0) ? "" : "SAME");
1696 void TestMomentCode()
1698 Float_t momentLimit = 1;
1699 TH1* proj = new TH1F("hist", "", 100, -momentLimit, momentLimit);
1700 TF1* func = new TF1("func", "gaus(0)", -momentLimit, momentLimit);
1701 func->SetParameters(1, 0, 0.2);
1702 proj->FillRandom("func", 100);
1706 for (Int_t n=2; n <= 4; n++)
1710 for (Int_t bin = proj->GetXaxis()->FindBin(-momentLimit); bin <= proj->GetXaxis()->FindBin(momentLimit); bin++)
1712 moment += proj->GetBinContent(bin) * TMath::Power(proj->GetMean() - proj->GetXaxis()->GetBinCenter(bin), n);
1713 sum += proj->GetBinContent(bin);
1718 for (Int_t bin = proj->GetXaxis()->FindBin(-momentLimit); bin <= proj->GetXaxis()->FindBin(momentLimit); bin++)
1720 error += proj->GetBinError(bin) * proj->GetBinError(bin) *
1721 TMath::Power(TMath::Power(proj->GetMean() - proj->GetXaxis()->GetBinCenter(bin), n) / sum
1725 Printf("%d %f %f", n, moment, TMath::Sqrt(error));
1729 void DivideGraphs(TGraphErrors* graph1, TGraphErrors* graph2)
1734 for (Int_t bin1 = 0; bin1 < graph1->GetN(); bin1++)
1736 Float_t x = graph1->GetX()[bin1];
1739 for (bin2 = 0; bin2<graph2->GetN(); bin2++)
1740 if (graph2->GetX()[bin2] >= x)
1743 if (bin2 == graph2->GetN())
1747 if (TMath::Abs(graph2->GetX()[bin2-1] - x) < TMath::Abs(graph2->GetX()[bin2] - x))
1750 if (graph1->GetY()[bin1] == 0 || graph2->GetY()[bin2] == 0 || bin2 == graph2->GetN())
1752 Printf("%d %d removed", bin1, bin2);
1753 graph1->RemovePoint(bin1--);
1757 Float_t graph2Extrapolated = graph2->GetY()[bin2];
1758 if (TMath::Abs(x - graph2->GetX()[bin2]) > 0.0001)
1760 Printf("%f %f %d %d not found", x, graph2->GetX()[bin2], bin1, bin2);
1761 graph1->RemovePoint(bin1--);
1765 Float_t value = graph1->GetY()[bin1] / graph2Extrapolated;
1766 Float_t error = value * TMath::Sqrt(TMath::Power(graph1->GetEY()[bin1] / graph1->GetY()[bin1], 2) + TMath::Power(graph2->GetEY()[bin2] / graph2->GetY()[bin2], 2));
1768 graph1->GetY()[bin1] = value;
1769 graph1->GetEY()[bin1] = error;
1771 Printf("%d %d %f %f %f %f", bin1, bin2, x, graph2Extrapolated, value, error);
1775 void CompareGraph(const char* fileName1, const char* fileName2, Int_t graph, Int_t centrality)
1777 ReadGraphs(fileName1);
1778 TGraphErrors* graph1 = (TGraphErrors*) graphs[graph][centrality]->Clone("graph1");
1780 ReadGraphs(fileName2);
1781 TGraphErrors* graph2 = (TGraphErrors*) graphs[graph][centrality]->Clone("graph2");
1786 TCanvas* c = new TCanvas(Form("%s_%s", fileName1, fileName2), Form("%s_%s", fileName1, fileName2), 800, 800);
1792 graph1->SetMarkerStyle(24);
1793 graph1->GetXaxis()->SetRangeUser(7, 38);
1794 graph1->DrawClone("AP");
1795 graph2->SetLineColor(2);
1796 graph2->SetMarkerColor(2);
1797 graph2->SetMarkerStyle(25);
1798 graph2->DrawClone("PSAME");
1803 DivideGraphs(graph1, graph2);
1804 graph1->DrawClone("AP");
1807 void Compare2D(const char* fileName1, const char* fileName2, const char* histName)
1809 TFile::Open(fileName1);
1810 TH1* hist1 = (TH1*) gFile->Get(histName);
1812 TFile::Open(fileName2);
1813 TH1* hist2 = (TH1*) gFile->Get(histName);
1815 hist1->Divide(hist2);
1816 hist1->GetZaxis()->SetRangeUser(0.5, 1.5);
1817 hist1->Draw("COLZ");
1820 void TestTwoGaussian()
1822 // TF1* func = new TF1("func", "[0]/TMath::Sqrt(TMath::TwoPi())/[2]*exp(-0.5*((x-[1])/[2])**2) + [3]/TMath::Sqrt(TMath::TwoPi())/[5]*exp(-0.5*((x-[4])/[5])**2)", -2, 2);
1823 TF1* func = new TF1("func", "[0]*exp(-0.5*((x-[1])/[2])**2) + [3]*exp(-0.5*((x-[4])/[5])**2)", -2, 2);
1824 func->SetParameters(0.25, 0, 0.5, 0.75, 0, 0.2);
1826 TH1* hist = new TH1F("hist", "", 100, -2, 2);
1827 hist->FillRandom("func", 10000000);
1833 Float_t momentLimit = 1.99;
1834 for (Int_t n=2; n <= 4; n++)
1838 for (Int_t bin = proj->GetXaxis()->FindBin(-momentLimit); bin <= proj->GetXaxis()->FindBin(momentLimit); bin++)
1840 moment += proj->GetBinContent(bin) * TMath::Power(proj->GetMean() - proj->GetXaxis()->GetBinCenter(bin), n);
1841 sum += proj->GetBinContent(bin);
1846 for (Int_t bin = proj->GetXaxis()->FindBin(-momentLimit); bin <= proj->GetXaxis()->FindBin(momentLimit); bin++)
1848 error += proj->GetBinError(bin) * proj->GetBinError(bin) *
1849 TMath::Power(TMath::Power(proj->GetMean() - proj->GetXaxis()->GetBinCenter(bin), n) / sum
1853 Printf("%d %f %f", n, moment, TMath::Sqrt(error));
1857 void DrawEtaGapExample(const char* histFileName, Int_t i = 1, Int_t j = 2)
1859 Float_t etaLimit = 1.0;
1860 Float_t outerLimit = 1.79;
1861 Float_t projectLimit = 0.8;
1863 TFile::Open(histFileName);
1865 TH2* hist = (TH2*) gFile->Get(Form("dphi_%d_%d_%d", i, j, 0));
1869 TCanvas* c = new TCanvas("c", "c", 800, 800);
1870 gPad->SetLeftMargin(0.15);
1871 TH2* clone = (TH2*) hist->DrawCopy("SURF1");
1872 clone->SetTitle("");
1873 clone->GetYaxis()->SetRangeUser(-1.79, 1.79);
1874 clone->GetXaxis()->SetTitleOffset(1.5);
1875 clone->GetYaxis()->SetTitleOffset(2);
1876 clone->SetStats(kFALSE);
1877 c->SaveAs("etagap_raw.eps");
1879 SubtractEtaGap(hist, etaLimit, outerLimit, kFALSE, kTRUE);
1881 c = new TCanvas("c3", "c3", 800, 800);
1882 TH1* proj = hist->ProjectionX(Form("%s_proj1%d", hist->GetName(), 0), hist->GetYaxis()->FindBin(-projectLimit+0.01), hist->GetYaxis()->FindBin(projectLimit-0.01));
1883 proj->GetXaxis()->SetRangeUser(-1.49, 1.49);
1885 proj->GetXaxis()->SetTitle(Form("%s / %s", proj->GetXaxis()->GetTitle(), "#Delta#eta"));
1886 proj->GetYaxis()->SetRangeUser(proj->GetMinimum() * 1.2, proj->GetMaximum() * 1.5);
1889 proj = hist->ProjectionY(Form("%s_proj2_%d", hist->GetName(), 0), hist->GetXaxis()->FindBin(-projectLimit+0.01), hist->GetXaxis()->FindBin(projectLimit-0.01));
1890 proj->GetXaxis()->SetRangeUser(-1.49, 1.49);
1891 proj->GetYaxis()->SetRangeUser(proj->GetMinimum() * 1.2, proj->GetMaximum() * 2);
1892 proj->SetLineColor(2);
1894 c->SaveAs("etagap_subtracted_proj.eps");
1896 c = new TCanvas("c2", "c2", 800, 800);
1897 gPad->SetLeftMargin(0.15);
1899 hist->GetYaxis()->SetRangeUser(-1.79, 1.79);
1900 hist->GetXaxis()->SetTitleOffset(1.5);
1901 hist->GetYaxis()->SetTitleOffset(2);
1902 hist->SetStats(kFALSE);
1903 hist->Draw("SURF1");
1904 c->SaveAs("etagap_subtracted.eps");