]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG4/macros/dphicorrelations/correct.C
update to trigger correlation study
[u/mrichter/AliRoot.git] / PWG4 / macros / dphicorrelations / correct.C
1 Float_t gpTMin = 0.51;
2 Float_t gpTMax = 49.99;
3 Int_t gUEHist = 0;
4 Bool_t gCache = 0;
5 void* gFirst = 0;
6 void* gSecond = 0;
7 Float_t gForceRange = -1;
8 Int_t gEnergy = 900;
9 Int_t gRegion = 0;
10 const char* gText = "";
11
12 void SetRanges(TAxis* axis)
13 {
14   if (strcmp(axis->GetTitle(), "leading p_{T} (GeV/c)") == 0)
15     axis->SetRangeUser(0, (gEnergy == 900) ? 10 : 25);
16
17   if (strcmp(axis->GetTitle(), "multiplicity") == 0)
18     axis->SetRangeUser(0, 10);
19 }
20
21 void SetRanges(TH1* hist)
22 {
23   SetRanges(hist->GetXaxis());
24   SetRanges(hist->GetYaxis());
25   SetRanges(hist->GetZaxis());
26 }
27
28 void Prepare1DPlot(TH1* hist)
29 {
30   if (!hist)
31     return;
32
33   hist->SetLineWidth(2);
34   hist->SetStats(kFALSE);
35
36   hist->GetXaxis()->SetLabelOffset(0.02);
37   hist->GetXaxis()->SetTitleOffset(1.3);
38   hist->GetYaxis()->SetTitleOffset(1.3);
39
40   SetRanges(hist);
41 }
42
43 TH1* GetSystematicUncertainty(TH1* corr, TH1* trackHist)
44 {
45   if (!trackHist)
46   {
47     systError = (TH1*) corr->Clone("systError");
48     systError->Reset();
49   }
50   else  // for dphi evaluation
51     systError = new TH1F("systError", "", 100, 0, 50);
52   
53   Float_t constantUnc = 0;
54   
55   // particle composition
56   constantUnc += 0.8 ** 2;
57   
58   // tpc efficiency
59   if (gEnergy == 900 && gpTMin < 1.0)
60     constantUnc += 1.0 ** 2;
61   else if (gEnergy == 900 && gpTMin < 1.5)
62     constantUnc += 0.5 ** 2;
63   if (gEnergy == 7000 && gpTMin < 1.0)
64     constantUnc += 1.0 ** 2;
65   else if (gEnergy == 7000 && gpTMin < 1.5)
66     constantUnc += 0.6 ** 2;
67   
68   // track cuts
69   if (gEnergy == 900 && gpTMin < 1.0)
70     constantUnc += 2.5 ** 2;
71   else if (gEnergy == 900 && gpTMin < 1.5)
72     constantUnc += 2.0 ** 2;
73   if (gEnergy == 7000)
74     constantUnc += 3.0 ** 2;
75
76   // difference corrected with pythia and phojet
77   if (gEnergy == 900 && gpTMin < 1.0)
78     constantUnc += 0.6 ** 2;
79   else if (gEnergy == 900 && gpTMin < 1.5)
80     constantUnc += 0.8 ** 2;
81   
82   if (gEnergy == 7000 && gpTMin < 1.0)
83   {
84     if (gUEHist == 0)
85       constantUnc += 0.6 ** 2;
86     if (gUEHist == 1)
87       constantUnc += 0.8 ** 2;
88     if (gUEHist == 2)
89       constantUnc += 1.0 ** 2;
90   }
91   else if (gEnergy == 7000 && gpTMin < 1.5)
92     constantUnc += 1.0 ** 2;
93     
94   for (Int_t bin=1; bin<=systError->GetNbinsX(); bin++)
95     systError->SetBinContent(bin, constantUnc);
96
97   // mis id bias
98   if (gUEHist == 0 || gUEHist == 2)
99     systError->Fill(0.75, 4.0 ** 2);
100   if (gUEHist == 1)
101     systError->Fill(0.75, 5.0 ** 2);
102
103   if (gEnergy == 900)
104   {
105     if (gpTMin < 1.0)
106       systError->Fill(1.25, 1.0 ** 2);
107     else if (gpTMin < 1.5)
108       systError->Fill(1.25, 2.0 ** 2);
109   }
110   
111   // non-closure in MC
112   if (gEnergy == 900)
113     for (Int_t bin=1; bin<=systError->GetNbinsX(); bin++)
114       systError->Fill(systError->GetXaxis()->GetBinCenter(bin), 1.0 ** 2);
115       
116   if (gEnergy == 7000)
117   {
118     if (gUEHist == 0 && gUEHist == 1)
119       systError->Fill(0.75, 2.0 ** 2);
120     if (gUEHist == 2)
121       systError->Fill(0.75, 1.2 ** 2);
122   }
123   
124   // vertex efficiency
125   systError->Fill(0.75, 1.0 ** 2);
126
127   // strangeness
128   for (Int_t bin=1; bin<=systError->GetNbinsX(); bin++)
129   {
130     if (gEnergy == 900)
131       systError->Fill(systError->GetXaxis()->GetBinCenter(bin), 0.5 ** 2);
132     if (gEnergy == 7000 && systError->GetXaxis()->GetBinCenter(bin) < 1.5)
133       systError->Fill(systError->GetXaxis()->GetBinCenter(bin), 2.0 ** 2);
134     else if (gEnergy == 7000)
135       systError->Fill(systError->GetXaxis()->GetBinCenter(bin), 1.0 ** 2);
136   }  
137     
138   for (Int_t bin=1; bin<=systError->GetNbinsX(); bin++)
139     systError->SetBinContent(bin, TMath::Sqrt(systError->GetBinContent(bin)));
140   
141   if (trackHist)
142   {
143     //new TCanvas; trackHist->Draw();
144     //new TCanvas; systError->DrawCopy("");
145     
146     Float_t uncFlat = 0;
147     for (Int_t i=1; i<=trackHist->GetNbinsX(); i++)
148       uncFlat += trackHist->GetBinContent(i) * systError->GetBinContent(systError->FindBin(trackHist->GetBinCenter(i)));
149     if (trackHist->Integral() > 0)
150       uncFlat /= trackHist->Integral();
151     
152     systError = (TH1F*) corr->Clone("systError");
153     systError->Reset();
154   
155     for (Int_t i=1; i<=systError->GetNbinsX(); i++)
156       systError->SetBinContent(i, uncFlat);
157       
158     //new TCanvas; systError->DrawCopy("");
159   }
160   
161   systError->SetFillColor(kGray);
162   systError->SetFillStyle(1001);
163   systError->SetMarkerStyle(0);
164   systError->SetLineColor(0);
165   
166   return systError;
167 }
168
169 void DrawRatio(TH1* corr, TH1* mc, const char* name, TH1* syst = 0)
170 {
171   mc->SetLineColor(2);
172
173   TCanvas* canvas3 = new TCanvas(name, name, 600, 600);
174   canvas3->Range(0, 0, 1, 1);
175
176   TPad* pad1 = new TPad(Form("%s_1", name), "", 0, 0.5, 0.98, 0.98);
177   pad1->Draw();
178
179   TPad* pad2 = new TPad(Form("%s_2", name), "", 0, 0.02, 0.98, 0.5);
180   pad2->Draw();
181
182   pad1->SetRightMargin(0.01);
183   pad2->SetRightMargin(0.01);
184   pad1->SetTopMargin(0.05);
185   pad1->SetLeftMargin(0.13);
186   pad2->SetLeftMargin(0.13);
187   pad2->SetBottomMargin(0.22);
188   
189   // no border between them
190   pad1->SetBottomMargin(0);
191   pad2->SetTopMargin(0);
192
193   pad1->cd();
194   pad1->SetGridx();
195   pad1->SetGridy();
196
197   if (gUEHist != 2)
198     TLegend* legend = new TLegend(0.15, 0.65, 0.55, 0.90);
199   else
200     TLegend* legend = new TLegend(0.55, 0.65, 0.95, 0.90);
201
202   legend->SetFillColor(0);
203   legend->AddEntry(corr, "Corrected");
204   legend->AddEntry(mc, "MC prediction");
205   legend->SetTextSize(0.08);
206
207   Prepare1DPlot(corr);
208
209   TH2F* dummy = new TH2F("dummy", "", 100, corr->GetXaxis()->GetBinLowEdge(1), corr->GetXaxis()->GetBinUpEdge(corr->GetNbinsX()), 1000, 0, TMath::Max(corr->GetMaximum(), mc->GetMaximum()) * 1.1);
210   dummy->SetYTitle(corr->GetYaxis()->GetTitle());
211   
212   //dummy = new TH2F("dummy", "", 100, corr->GetXaxis()->GetBinLowEdge(1), corr->GetXaxis()->GetBinUpEdge(corr->GetNbinsX()), 1000, 13.5, 20.5);
213   //dummy->SetYTitle("1/N_{trig} dN/d#Delta#phi");
214   
215   dummy->SetStats(kFALSE);
216   dummy->SetXTitle(corr->GetXaxis()->GetTitle());
217   dummy->GetYaxis()->SetTitleOffset(1);
218   Prepare1DPlot(dummy);
219
220   dummy->GetXaxis()->SetLabelSize(0.08);
221   dummy->GetYaxis()->SetLabelSize(0.08);
222   dummy->GetXaxis()->SetTitleSize(0.08);
223   dummy->GetYaxis()->SetTitleSize(0.08);
224   dummy->GetYaxis()->SetTitleOffset(0.8);
225   
226   if (gForceRange > 0)
227     dummy->GetYaxis()->SetRangeUser(0, gForceRange);
228   
229   dummy->DrawCopy();
230   
231   if (0 && gUEHist != 2)
232   {
233     const char* regionStr[] = { "Toward Region", "Away Region", "Transverse Region" };
234     latex = new TLatex(0.65, 0.1, regionStr[gRegion]);
235     latex->SetTextSize(0.075);
236     latex->SetNDC();
237     latex->Draw();
238   }
239   
240   if (syst)
241   {
242     systError = (TH1*) syst->Clone("corrSystError");
243     for (Int_t bin=1; bin<=systError->GetNbinsX(); bin++)
244     {
245       systError->SetBinError(bin, corr->GetBinContent(bin) * syst->GetBinContent(bin) / 100);
246       systError->SetBinContent(bin, corr->GetBinContent(bin));
247     }
248     
249     systError->Draw("E2 ][ SAME");
250   }
251   
252   corr->Draw("SAME");
253   mc->Draw("SAME");
254   
255   if (strlen(gText) > 0)
256   {
257     latex = new TLatex(0.2, 0.2, gText);
258     latex->SetNDC();
259     latex->SetTextSize(0.06);
260     latex->Draw();
261   }
262
263   //legend->Draw();
264
265   pad2->cd();
266   //pad2->SetBottomMargin(0.15);
267   //pad2->SetGridx();
268   //pad2->SetGridy();
269
270   TH1* ratio = (TH1*) mc->Clone("ratio");
271   ratio->Divide(corr);
272
273   Float_t minR = TMath::Min(0.91, ratio->GetMinimum() * 0.95);
274   Float_t maxR = TMath::Max(1.09, ratio->GetMaximum() * 1.05);
275   
276   minR = 0.8;
277   maxR = 1.2;
278
279   TH1F dummy3("dummy3", ";;Ratio: MC / corr", 100, corr->GetXaxis()->GetBinLowEdge(1), corr->GetXaxis()->GetBinUpEdge(corr->GetNbinsX()));
280   dummy3.SetXTitle(corr->GetXaxis()->GetTitle());
281   Prepare1DPlot(&dummy3);
282   dummy3.SetStats(kFALSE);
283   for (Int_t i=1; i<=100; ++i)
284         dummy3.SetBinContent(i, 1);
285   dummy3.GetYaxis()->SetRangeUser(minR, maxR);
286   dummy3.SetLineWidth(2);
287   dummy3.GetXaxis()->SetLabelSize(0.08);
288   dummy3.GetYaxis()->SetLabelSize(0.08);
289   dummy3.GetXaxis()->SetTitleSize(0.08);
290   dummy3.GetYaxis()->SetTitleSize(0.08);
291   dummy3.GetYaxis()->SetTitleOffset(0.8);
292   dummy3.DrawCopy();
293   
294   if (syst)
295   {
296     // for the ratio add in quadrature
297     for (Int_t bin=1; bin<=syst->GetNbinsX(); bin++)
298     {
299       if (corr->GetBinError(bin) > 0)
300         syst->SetBinError(bin, TMath::Sqrt(TMath::Power(syst->GetBinContent(bin) / 100, 2) + TMath::Power(corr->GetBinError(bin) / corr->GetBinContent(bin), 2)));
301       else
302         syst->SetBinError(bin, 0);
303       syst->SetBinContent(bin, 1);
304     }
305     
306     syst->Draw("E2 ][ SAME");
307     dummy3.DrawCopy("SAME");
308   }
309
310   ratio->Draw("SAME");
311   
312   ratio->Fit("pol0", "N");
313
314   canvas3->Modified();
315   //canvas3->SaveAs(Form("%s.eps", canvas3->GetTitle()));
316 }
317
318 void loadlibs()
319 {
320   gSystem->Load("libANALYSIS");
321   gSystem->Load("libANALYSISalice");
322   gSystem->Load("libCORRFW");
323   gSystem->Load("libJETAN");
324   gSystem->Load("libPWG4JetTasks");
325 }
326
327 void* GetUEHistogram(const char* fileName, TList** listRef = 0, Bool_t mixed = kFALSE)
328 {
329   file = TFile::Open(fileName);
330   if (!file)
331     return 0;
332   
333   list = (TList*) gFile->Get("PWG4_LeadingTrackUE/histosLeadingTrackUE");
334   if (!list)
335     list = (TList*) gFile->Get("PWG4_PhiCorrelations/histosPhiCorrelations");
336     
337   if (!list)
338     return 0;
339     
340   if (listRef)
341     *listRef = list;
342     
343   if (mixed)
344     return list->FindObject("AliUEHistogramsMixed");
345   
346   if (list->FindObject("AliUEHistograms"))
347     return list->FindObject("AliUEHistograms");
348     
349   return list->FindObject("AliUEHistogramsSame");
350 }
351
352 void CompareBias(const char* mcFile = "PWG4_JetTasksOutput.root", Int_t region, Int_t ueHist)
353 {
354   loadlibs();
355
356   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(mcFile);
357   SetupRanges(h);
358   
359   const char* axis = "z";
360   Float_t ptLeadMin = 0;
361   Float_t ptLeadMax = -1;
362   
363   if (ueHist == 2)
364   {
365     ptLeadMin = 0.51 + 0;
366     ptLeadMax = 1.99 + 0;
367     axis = "y";
368   }
369   
370   biasFromData = (TH1*) h->GetUEHist(ueHist)->GetBias(AliUEHist::kCFStepBiasStudy, AliUEHist::kCFStepReconstructed, region, axis, ptLeadMin, ptLeadMax)->Clone("biasFromData");
371   biasFromData2 = (TH1*) h->GetUEHist(ueHist)->GetBias(AliUEHist::kCFStepBiasStudy2, AliUEHist::kCFStepReconstructed, region, axis, ptLeadMin, ptLeadMax)->Clone("biasFromData2");
372   //biasFromData = (TH1*) h->GetUEHist(ueHist)->GetBias(AliUEHist::kCFStepReconstructed, AliUEHist::kCFStepRealLeading, region, axis)->Clone("biasFromData");
373   biasFromMC   = (TH1*) h->GetUEHist(ueHist)->GetBias(AliUEHist::kCFStepReconstructed, AliUEHist::kCFStepTracked, region, axis, ptLeadMin, ptLeadMax)->Clone("biasFromMC");
374   //biasFromMC   = (TH1*) h->GetUEHist(ueHist)->GetBias(AliUEHist::kCFStepReconstructed, AliUEHist::kCFStepRealLeading, region, axis)->Clone("biasFromMC");
375   
376 /*  biasFromData->Draw();
377   biasFromMC->SetLineColor(2);
378   biasFromMC->Draw("SAME");
379   return;*/
380   
381   DrawRatio(biasFromData, biasFromMC, "bias: data vs MC");
382   DrawRatio(biasFromData, biasFromData2, "bias: data vs data two step");
383 }
384   
385 void CompareBiasWithData(const char* mcFile = "PWG4_JetTasksOutput.root", const char* dataFile = "esd.root", Int_t region = 2)
386 {
387   loadlibs();
388
389   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(mcFile);
390   SetupRanges(h);
391   
392   biasFromMC   = (TH1*) h->GetNumberDensitypT()->GetBias(AliUEHist::kCFStepReconstructed, AliUEHist::kCFStepTracked, region, "z")->Clone("biasFromMC");
393   
394   AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(dataFile);
395   SetupRanges(h2);
396   
397   biasFromData = (TH1*) h2->GetNumberDensitypT()->GetBias(AliUEHist::kCFStepBiasStudy, AliUEHist::kCFStepReconstructed, region, "z")->Clone("biasFromData");
398   biasFromData2 = (TH1*) h2->GetNumberDensitypT()->GetBias(AliUEHist::kCFStepBiasStudy2, AliUEHist::kCFStepReconstructed, region, "z")->Clone("biasFromData2");
399   
400   DrawRatio(biasFromData, biasFromMC, "bias: data vs MC");
401   DrawRatio(biasFromData, biasFromData2, "bias: data vs data two step");
402 }
403
404 Int_t count = 0;
405
406 void Compare(const char* fileName1, const char* fileName2, Int_t id, Int_t step1, Int_t step2, Int_t region, Float_t ptLeadMin = -1, Float_t ptLeadMax = -1, Int_t centralityBegin = 0, Int_t centralityEnd = -1)
407 {
408   loadlibs();
409   
410   if (!gCache || !gFirst)
411   {
412     AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName1);
413     AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(fileName2);
414   }
415   
416   if (gCache)
417   {
418     if (!gFirst)
419     {
420       gFirst = h;
421       gSecond = h2;
422     }
423     else
424     {
425       AliUEHistograms* h = (AliUEHistograms*) gFirst;
426       AliUEHistograms* h2 = (AliUEHistograms*) gSecond;
427     }
428   }
429   
430   SetupRanges(h);
431   SetupRanges(h2);
432   
433   TH1* hist1 = h->GetUEHist(id)->GetUEHist(step1, region, ptLeadMin, ptLeadMax, centralityBegin, centralityEnd);
434   //TH1* hist1 = h->GetUEHist(id)->GetUEHist(step1, region, ptLeadMin, ptLeadMax);
435   TH1* hist2 = h2->GetUEHist(id)->GetUEHist(step2, region, ptLeadMin, ptLeadMax, centralityBegin, centralityEnd);
436
437   //hist1->Scale(1.0 / hist1->Integral());
438   //hist2->Scale(1.0 / hist2->Integral());
439
440   TH1* trackHist = 0;
441   if (id == 2)
442   {
443     trackHist = h->GetUEHist(id)->GetTrackHist(region)->ShowProjection(2, 0);
444     // only keep bins under consideration
445     for (Int_t bin=1; bin<=trackHist->GetNbinsX(); bin++)
446       if (bin < trackHist->FindBin(ptLeadMin) || bin > trackHist->FindBin(ptLeadMax))
447         trackHist->SetBinContent(bin, 0);
448   }
449
450   // systematic uncertainty
451   TH1* syst = 0; //GetSystematicUncertainty(hist1, trackHist);
452   
453   DrawRatio(hist1, hist2, Form("%d_%s_%d_%d_%d_%.2f_%.2f", count++, TString(gSystem->BaseName(fileName1)).Tokenize(".")->First()->GetName(), id, step1, region, ptLeadMin, ptLeadMax), syst);
454 }  
455
456 void CompareEventHist(const char* fileName1, const char* fileName2, Int_t id, Int_t step, Int_t var)
457 {
458   loadlibs();
459
460   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName1);
461   SetupRanges(h);
462
463   AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(fileName2);
464   SetupRanges(h2);
465
466   TH1* hist1 = h->GetUEHist(id)->GetEventHist()->ShowProjection(var, step);
467   TH1* hist2 = h2->GetUEHist(id)->GetEventHist()->ShowProjection(var, step);
468  
469   DrawRatio(hist1, hist2, "compare");
470 }
471
472 void CompareEventHist(const char* fileName1, const char* fileName2, Int_t id, Int_t step1, Int_t step2, Int_t var)
473 {
474   loadlibs();
475
476   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName1);
477   SetupRanges(h);
478
479   AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(fileName2);
480   SetupRanges(h2);
481
482   TH1* hist1 = h->GetUEHist(id)->GetEventHist()->ShowProjection(var, step1);
483   TH1* hist2 = h2->GetUEHist(id)->GetEventHist()->ShowProjection(var, step2);
484  
485   DrawRatio(hist1, hist2, "compare");
486 }
487
488 void CompareStep(const char* fileName1, const char* fileName2, Int_t id, Int_t step, Int_t region, Float_t ptLeadMin = -1, Float_t ptLeadMax = -1)
489 {
490   // fileName1 is labelled Corrected in the plot
491
492   loadlibs();
493
494   gUEHist = id;
495   gRegion = region;
496   Compare(fileName1, fileName2, id, step, step, region, ptLeadMin, ptLeadMax);
497 }
498
499 void CompareStep(const char* fileName1, const char* fileName2, Int_t id, Int_t step1, Int_t step2, Int_t region, Float_t ptLeadMin = -1, Float_t ptLeadMax = -1, Int_t centralityBegin = 0, Int_t centralityEnd = -1)
500 {
501   // fileName1 is labelled Corrected in the plot
502
503   loadlibs();
504
505   gUEHist = id;
506   gRegion = region;
507   Compare(fileName1, fileName2, id, step1, step2, region, ptLeadMin, ptLeadMax, centralityBegin, centralityEnd);
508 }
509
510 TH1* DrawStep(const char* fileName, Int_t id, Int_t step, Int_t region, Float_t ptLeadMin = -1, Float_t ptLeadMax = -1, Int_t centralityBegin = 0, Int_t centralityEnd = -1, Int_t twoD = 0, Bool_t mixed = kFALSE)
511 {
512   loadlibs();
513
514   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName, 0, mixed);
515   SetupRanges(h);
516
517   new TCanvas;
518   return h->GetUEHist(id)->GetUEHist(step, region, ptLeadMin, ptLeadMax, centralityBegin, centralityEnd, twoD)->DrawCopy();
519 }
520
521 void DrawExample(const char* fileName)
522 {
523   gpTMin = 1.01;
524   gpTMax = 3.99;
525   
526   hist = DrawStep(fileName, 2, 6, 0, 4.01, 19.99, 1, 6, 0);
527   hist->SetStats(0);
528   hist->SetTitle("");
529   hist->SetYTitle("1/N_{trig} dN/d#Delta#phi"); 
530
531   hist = DrawStep(fileName, 2, 6, 0, 4.01, 19.99, 1, 6, 1);
532   hist->SetStats(0);
533   hist->SetTitle("");
534   hist->SetZTitle("1/N_{trig} d^{2}N/d#Delta#phid#Delta#eta"); 
535   hist->GetYaxis()->SetTitleOffset(1.5);
536   hist->GetZaxis()->SetTitleOffset(1.2);
537   hist->Draw("SURF1");
538
539   hist2 = DrawStep(fileName, 2, 6, 0, 4.01, 19.99, 1, 6, 1, kTRUE);
540   hist2->SetStats(0);
541   hist2->SetTitle("");
542   hist2->SetZTitle("1/N_{trig} d^{2}N/d#Delta#phid#Delta#eta"); 
543   hist2->GetYaxis()->SetTitleOffset(1.5);
544   hist2->GetZaxis()->SetTitleOffset(1.2);
545   hist2->Draw("SURF1");
546   
547   new TCanvas;
548   hist = (TH1*) hist->Clone();
549   hist->Divide(hist2);
550   hist->SetZTitle("C(dN/d#Delta#phi#Delta#eta)"); 
551   hist->Draw("SURF1");
552 }
553
554 void DrawValidation(const char* fileName1, const char* fileName2)
555 {
556   gpTMin = 1.01;
557   gpTMax = 3.99;
558   
559   CompareStep(fileName1, fileName2, 2, 6, 4, 0, 4.01, 19.99);
560   CompareStep(fileName1, fileName2, 2, 4, 4, 0, 4.01, 19.99);
561
562   CompareStep(fileName1, fileName2, 2, 4, 2, 0, 4.01, 19.99);
563   CompareStep(fileName1, fileName2, 2, 2, 2, 0, 4.01, 19.99);
564 }
565
566 void ProfileMultiplicity(const char* fileName = "PWG4_JetTasksOutput.root")
567 {
568   loadlibs();
569
570   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
571
572   new TCanvas;
573   h->GetCorrelationMultiplicity()->Draw("colz");
574   gPad->SetLogz();
575
576   new TCanvas;
577   h->GetCorrelationMultiplicity()->ProfileX()->DrawCopy()->Fit("pol1", "", "", 1, 10);
578 }
579
580 void SetupRanges(void* obj)
581 {
582   //((AliUEHistograms*) obj)->SetEtaRange(-0.79, 0.79);
583   ((AliUEHistograms*) obj)->SetPtRange(gpTMin, gpTMax);
584   ((AliUEHistograms*) obj)->SetCombineMinMax(kTRUE);
585 }
586
587 void DrawRatios(const char* name, void* correctedVoid, void* comparisonVoid, Int_t compareStep = -1, Int_t compareRegion = 2, Float_t ptLeadMin = -1, Float_t ptLeadMax = -1)
588 {
589   AliUEHist* corrected = (AliUEHist*) correctedVoid;
590   AliUEHist* comparison = (AliUEHist*) comparisonVoid;
591
592   Int_t beginStep = AliUEHist::kCFStepAll;
593   Int_t endStep = AliUEHist::kCFStepReconstructed;
594   
595   if (compareStep != -1)
596   {
597     beginStep = compareStep;
598     endStep = compareStep;
599   }
600   
601   Int_t beginRegion = 0;
602   Int_t endRegion = 2;
603   
604   if (compareRegion != -1)
605   {
606     beginRegion = compareRegion;
607     endRegion = compareRegion;
608   }
609
610   for (Int_t step=beginStep; step<=endStep; step++)
611   {
612     if (compareStep == -1 && (step == AliUEHist::kCFStepAnaTopology || step == AliUEHist::kCFStepTriggered))
613       continue;
614       
615     for (Int_t region=beginRegion; region <= endRegion; region++)
616     {
617       Printf("%f %f", ptLeadMin, ptLeadMax);
618       TH1* corrHist = corrected->GetUEHist(step, region, ptLeadMin, ptLeadMax);
619       TH1* mcHist   = comparison->GetUEHist(step, region, ptLeadMin, ptLeadMax);
620       
621       DrawRatio(corrHist, mcHist, TString(Form("%s: step %d %s %s", name, step, corrected->GetStepTitle(step), corrected->GetRegionTitle(region))));
622     }
623   }
624 }
625
626 void DrawRatios(void* correctedVoid, void* comparisonVoid, Int_t compareStep = -1, Int_t compareRegion = 2, Int_t compareUEHist = 0)
627 {
628   AliUEHistograms* corrected = (AliUEHistograms*) correctedVoid;
629   AliUEHistograms* comparison = (AliUEHistograms*) comparisonVoid;
630
631   if (1 && compareUEHist == 2)
632   {
633     for (Float_t ptMin = 2.01; ptMin < 8; ptMin += 2)
634     {
635       ((AliUEHistograms*) corrected)->SetPtRange(ptMin, ptMin + 1.98);
636       ((AliUEHistograms*) comparison)->SetPtRange(ptMin, ptMin + 1.98);
637       
638       DrawRatios(TString(Form("Dphi %d pT %f", compareUEHist, ptMin)), corrected->GetUEHist(compareUEHist), comparison->GetUEHist(compareUEHist), compareStep, compareRegion, 8.01, 19.99);      
639     }
640     return;
641   }
642
643   if (compareUEHist == -1)
644   {
645     for (Int_t i=0; i<2; i++)
646       DrawRatios(TString(Form("UE %d", i)), corrected->GetUEHist(i), comparison->GetUEHist(i), compareStep, compareRegion);
647   }
648   else
649     DrawRatios(TString(Form("UE %d", compareUEHist)), corrected->GetUEHist(compareUEHist), comparison->GetUEHist(compareUEHist), compareStep, compareRegion);
650 }
651
652 void CompareEventsTracks(void* corrVoid, void* mcVoid, Int_t compareStep, Int_t compareRegion, Int_t compareUEHist = 0)
653 {
654   AliUEHist* corr = ((AliUEHistograms*) corrVoid)->GetUEHist(compareUEHist);
655   AliUEHist* mc   = ((AliUEHistograms*) mcVoid)->GetUEHist(compareUEHist);
656
657   Float_t ptLeadMin = 0;
658   Float_t ptLeadMax = -1;
659   Int_t axis = 2;
660   
661   if (compareUEHist == 2)
662   {
663     ptLeadMin = 1.01;
664     ptLeadMax = 1.49;
665     axis = 4;
666   }
667
668   TH1* corrHist = corr->GetUEHist(compareStep, compareRegion, ptLeadMin, ptLeadMax);
669   TH1* mcHist   = mc  ->GetUEHist(compareStep, compareRegion, ptLeadMin, ptLeadMax);
670   
671   DrawRatio(corrHist, mcHist, Form("check"));
672   
673   corr->SetBinLimits(corr->GetTrackHist(compareRegion)->GetGrid(compareStep));
674   mc->SetBinLimits(corr->GetTrackHist(compareRegion)->GetGrid(compareStep));
675
676   corrHist =  corr->GetTrackHist(compareRegion)->GetGrid(compareStep)->Project(axis);
677   mcHist   =  mc  ->GetTrackHist(compareRegion)->GetGrid(compareStep)->Project(axis);
678   DrawRatio(corrHist, mcHist, Form("check2"));
679   
680   corrHist =  corr->GetEventHist()->GetGrid(compareStep)->Project(0);
681   mcHist   =  mc  ->GetEventHist()->GetGrid(compareStep)->Project(0);
682   DrawRatio(corrHist, mcHist, Form("check3"));
683 }
684
685 void correctMC(const char* fileNameCorrections, const char* fileNameESD = 0, Int_t compareStep = -1, Int_t compareRegion = 2, Int_t compareUEHist = 0)
686 {
687   // corrects the reconstructed step in fileNameESD with fileNameCorr
688   // if fileNameESD is 0 data from fileNameCorr is taken
689   // afterwards the corrected distributions are compared with the MC stored in fileNameESD
690   
691   loadlibs();
692   
693   AliUEHistograms* corr = (AliUEHistograms*) GetUEHistogram(fileNameCorrections);
694   SetupRanges(corr);
695   corr->ExtendTrackingEfficiency();
696   
697   AliUEHistograms* testSample = corr;
698   if (fileNameESD)
699     testSample = (AliUEHistograms*) GetUEHistogram(fileNameESD);
700       
701   // copy to esd object
702   AliUEHistograms* esd = (AliUEHistograms*) corr->Clone();
703   esd->Reset();
704   esd->CopyReconstructedData(testSample);
705   
706   SetupRanges(corr);
707   SetupRanges(testSample);
708   SetupRanges(esd);
709   
710   esd->Correct(corr);
711   
712   list = new TList;
713   list->Add(esd);
714   
715   file3 = TFile::Open("correctedMC.root", "RECREATE");
716   file3->mkdir("PWG4_PhiCorrelations");
717   file3->cd("PWG4_PhiCorrelations");
718   list->Write("histosPhiCorrelations", TObject::kSingleKey);
719   file3->Close();
720   
721   if (1)
722     DrawRatios(esd, testSample, compareStep, compareRegion, compareUEHist);
723   
724   if (1)
725   {
726     esd->SetPtRange(2.01, 3.99);
727     corrected = esd->GetUEHist(2)->GetUEHist(0, 0, 4.01, 7.99, 0, -1, 1);
728     testSample->SetPtRange(2.01, 3.99);
729     mc = testSample->GetUEHist(2)->GetUEHist(0, 0, 4.01, 7.99, 0, -1, 1);
730     new TCanvas; corrected->DrawCopy("SURF1");
731     new TCanvas; mc->DrawCopy("SURF1");
732     new TCanvas; mc->DrawCopy("SURF1")->Divide(corrected);
733   }
734   
735   //CompareEventsTracks(esd, testSample, compareStep, compareRegion, compareUEHist);
736 }
737
738 // function to compare only final step for all regions and distributions
739
740 void correctData(const char* fileNameCorrections, const char* fileNameESD, const char* contEnhancement = 0, Float_t contEncUpTo = 1.0, Int_t compareStep = 0, Int_t compareRegion = 0, Int_t compareUEHist = 2)
741 {
742   // corrects fileNameESD with fileNameCorrections and compares the two
743   
744   loadlibs();
745   
746   AliUEHistograms* corr = (AliUEHistograms*) GetUEHistogram(fileNameCorrections);
747   
748   TList* list = 0;
749   AliUEHistograms* esd = (AliUEHistograms*) GetUEHistogram(fileNameESD, &list);
750   
751   SetupRanges(corr);
752   SetupRanges(esd);
753   
754   corr->ExtendTrackingEfficiency();
755   
756   if (contEnhancement)
757   {
758     TFile::Open(contEnhancement);
759     contEncHist = (TH1*) gFile->Get("histo");
760     contEncHistFullRange = (TH1*) corr->GetUEHist(0)->GetTrackingEfficiency(1)->Clone("contEncHistFullRange");
761     
762     contEncHistFullRange->Reset();
763     for (Int_t i=1; i<=contEncHistFullRange->GetNbinsX(); i++)
764     {
765       contEncHistFullRange->SetBinContent(i, 1);
766       if (i <= contEncHist->GetNbinsX() && contEncHist->GetXaxis()->GetBinCenter(i) < contEncUpTo && contEncHist->GetBinContent(i) > 0)
767         contEncHistFullRange->SetBinContent(i, contEncHist->GetBinContent(i));
768     }
769     corr->SetContaminationEnhancement((TH1F*) contEncHistFullRange);
770   }
771   
772   esd->Correct(corr);
773   //esd->GetUEHist(2)->AdditionalDPhiCorrection(0);
774   
775   file3 = TFile::Open("corrected.root", "RECREATE");
776   file3->mkdir("PWG4_PhiCorrelations");
777   file3->cd("PWG4_PhiCorrelations");
778   list->Write(0, TObject::kSingleKey);
779   file3->Close();
780   
781   DrawRatios(esd, corr, compareStep, compareRegion, compareUEHist);
782 }
783
784 void ITSTPCEfficiency(const char* fileNameData, Int_t id, Int_t itsTPC = 0)
785 {
786   // its = 0; tpc = 1
787
788   // uncertainty from dN/dpT paper
789   Double_t pTBins[] =  {0.0, 0.1, 0.15,  0.2,  0.25,  0.3,   0.35,  0.4,   0.45,  0.5,   0.6,   0.7,   0.8,   0.9,   1.0,   1.5,   2.0,   2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 12.0, 14.0, 16.0, 18.0, 20.0, 25.0, 30.0, 35.0, 40.0, 45.0, 50.0, 100.0};
790   Float_t effITS[] =   {0.,  0.,  0.995, 0.98, 0.986, 0.996, 1,     1,     1,     1,     1,     1,     1,     1,     1,     1,     1,    };  // the last three are the same because i don't have entries
791   Float_t effTPC[] =   {0.,  0,   1.042, 1.026,1.021, 1.018, 1.015, 1.015, 1.012, 1.012, 1.007, 1.0075,1.006, 1.006, 1.004, 1.004, 1.009 }; // the last bins put as if they were the same
792
793   TH1F* effHist = new TH1F("effHist", "effHist", 39, pTBins);
794   for (Int_t i=0; i<39; i++)
795   {
796     Int_t bin = i;
797     if (i > 16)
798       bin = 16;
799     effHist->SetBinContent(i+1, (itsTPC == 0) ? effITS[bin] : effTPC[bin]);
800   }
801
802   new TCanvas; effHist->Draw();
803
804   EffectOfModifiedTrackingEfficiency(fileNameData, id, 2, effHist, 1, -1, (itsTPC == 0) ? "ITS" : "TPC");
805
806
807
808 void EffectOfModifiedTrackingEfficiency(const char* fileNameData, Int_t id, Int_t region, TH1* trackingEff, Int_t axis1, Int_t axis2 = -1, const char* name = "EffectOfModifiedTrackingEfficiency")
809 {
810   // trackingEff should contain the change in tracking efficiency, i.e. between before and after in the eta-pT plane
811
812   loadlibs();
813   
814   AliUEHistograms* corrected = (AliUEHistograms*) GetUEHistogram(fileNameData);
815   SetupRanges(corrected);
816   
817   AliUEHist* ueHist = corrected->GetUEHist(id);
818   
819   Float_t ptLeadMin = -1;
820   Float_t ptLeadMax = -1;
821   if (id == 2)
822   {
823     // the uncertainty is flat in delta phi, so use this trick to get directly the uncertainty as function of leading pT
824     //ptLeadMin = 1.01;
825     //ptLeadMax = 1.99;
826   }
827     
828   // histogram before
829   TH1* before = ueHist->GetUEHist(AliUEHist::kCFStepAll, region, ptLeadMin, ptLeadMax);
830
831   // copy histogram
832   // the CFStepTriggered step is overwritten here and cannot be used for comparison afterwards anymore
833   ueHist->CorrectTracks(AliUEHist::kCFStepAll, AliUEHist::kCFStepTriggered, (TH1*) 0, 0, -1);
834
835   // reapply tracking efficiency
836   ueHist->CorrectTracks(AliUEHist::kCFStepTriggered, AliUEHist::kCFStepAll, trackingEff, axis1, axis2);
837
838   // histogram after
839   TH1* after = ueHist->GetUEHist(AliUEHist::kCFStepAll, region, ptLeadMin, ptLeadMax);
840   
841   DrawRatio(before, after, name);
842   gPad->GetCanvas()->SaveAs(Form("%s.png", name));
843 }
844
845 void EffectOfTrackCuts(const char* fileNameData, Int_t id, const char* systFile)
846 {
847   loadlibs();
848
849   AliUEHistograms* corrected = (AliUEHistograms*) GetUEHistogram(fileNameData);
850   effHist = (TH2D*) corrected->GetUEHist(0)->GetTrackingEfficiency()->Clone("effHist");
851
852   file = TFile::Open(systFile);
853
854   Int_t maxSyst = 3;
855   const char* systNames[] = { "NClusTPC", "Chi2TPC", "SigmaDCA" };
856
857   for (Int_t i=0; i<maxSyst; i++)
858   {
859     for (Int_t j=0; j<2; j++)
860     {
861       TString histName;
862       histName.Form("%s_syst_%s", systNames[i], (j == 0) ? "up" : "down");
863       systEffect = (TH2*) file->Get(histName);
864
865       // rebin
866       effHist->Reset();
867       for (Int_t x=1; x <= effHist->GetNbinsX(); x++)
868         for (Int_t y=1; y <= effHist->GetNbinsY(); y++)
869           effHist->SetBinContent(x, y, 1);
870
871       for (Int_t x=1; x <= systEffect->GetNbinsX(); x++)
872         for (Int_t y=1; y <= systEffect->GetNbinsY(); y++)
873           if (systEffect->GetBinContent(x, y) != 0)
874             effHist->SetBinContent(effHist->GetXaxis()->FindBin(systEffect->GetYaxis()->GetBinCenter(y)), effHist->GetYaxis()->FindBin(systEffect->GetXaxis()->GetBinCenter(x)), systEffect->GetBinContent(x, y));
875            
876    
877       //new TCanvas; systEffect->Draw("COLZ"); new TCanvas; effHist->Draw("COLZ");
878  
879       EffectOfModifiedTrackingEfficiency(fileNameData, id, (id == 2) ? 0 : 2, effHist, 0, 1, histName);
880
881       //return;
882     }
883   } 
884 }
885
886 void ModifyComposition(const char* fileNameData, const char* fileNameCorrections, Int_t id, Bool_t verbose = kFALSE)
887 {
888   loadlibs();
889   
890   AliUEHistograms* corrected = (AliUEHistograms*) GetUEHistogram(fileNameData);
891   SetupRanges(corrected);
892   
893   AliUEHistograms* corrections = (AliUEHistograms*) GetUEHistogram(fileNameCorrections);
894   SetupRanges(corrections);
895   
896   ueHistData        = (AliUEHist*) corrected->GetUEHist(id);
897   ueHistCorrections = (AliUEHist*) corrections->GetUEHist(id);
898   
899   // copy histogram
900   // the CFStepTriggered step is overwritten here and cannot be used for comparison afterwards anymore
901   ueHistData->CorrectTracks(AliUEHist::kCFStepAll, AliUEHist::kCFStepTriggered, (TH1*) 0, 0);
902   
903   Int_t maxRegion = 3;
904   Float_t ptLeadMin = -1;
905   Float_t ptLeadMax = -1;
906   if (id == 2)
907   {
908     maxRegion = 1;
909     // the uncertainty is flat in delta phi, so use this trick to get directly the uncertainty as function of leading pT
910     //ptLeadMin = 1.01;
911     //ptLeadMax = 1.99;
912   }
913   
914   // histogram before
915   TH1* before[3];
916   for (Int_t region=0; region<maxRegion; region++)
917     before[region] = ueHistData->GetUEHist(AliUEHist::kCFStepAll, region, ptLeadMin, ptLeadMax);
918   
919   //defaultEff = ueHistCorrections->GetTrackingEfficiency();
920   defaultEff = ueHistCorrections->GetTrackingCorrection();
921   //defaultEffpT = ueHistCorrections->GetTrackingEfficiency(1);
922   defaultEffpT = ueHistCorrections->GetTrackingCorrection(1);
923   defaultContainer = ueHistCorrections->GetTrackHistEfficiency();
924   
925   c = new TCanvas;
926   defaultEffpT->Draw("");
927   
928   Float_t largestDeviation[3];
929   for (Int_t i=0; i<maxRegion; i++)
930     largestDeviation[i] = 0;  
931   
932   for (Int_t i=0; i<7; i++)
933   {
934     // case 0: // default
935     // case 1: // + 30% kaons
936     // case 2: // - 30% kaons
937     // case 3: // + 30% protons
938     // case 4: // - 30% protons
939     // case 5: // + 30% others
940     // case 6: // - 30% others
941     Int_t correctionIndex = (i+1) / 2 + 1; // bin 1 == protons, bin 2 == kaons, ...
942     Double_t scaleFactor = (i % 2 == 1) ? 1.3 : 0.7;
943     if (i == 0)
944       scaleFactor = 1;
945     
946     newContainer = (AliCFContainer*) defaultContainer->Clone();
947     
948     // modify, change all steps
949     for (Int_t j=0; j<newContainer->GetNStep(); j++)
950     {
951       THnSparse* grid = newContainer->GetGrid(j)->GetGrid();
952       
953       for (Int_t binIdx = 0; binIdx < grid->GetNbins(); binIdx++)
954       {
955         Int_t bins[5];
956         Double_t value = grid->GetBinContent(binIdx, bins);
957         Double_t error = grid->GetBinError(binIdx);
958         
959         if (bins[2] != correctionIndex)
960           continue;
961     
962         value *= scaleFactor;
963         error *= scaleFactor;
964     
965         grid->SetBinContent(bins, value);
966         grid->SetBinError(bins, error);      
967       }
968     }
969     
970     // put in corrections
971     ueHistCorrections->SetTrackHistEfficiency(newContainer);
972     
973     // ratio
974     //modifiedEff = ueHistCorrections->GetTrackingEfficiency();
975     modifiedEff = ueHistCorrections->GetTrackingCorrection();
976     modifiedEff->Divide(modifiedEff, defaultEff);
977     //modifiedEff->Draw("COLZ");
978     
979     c->cd();
980     //modifiedEffpT = ueHistCorrections->GetTrackingEfficiency(1);
981     modifiedEffpT = ueHistCorrections->GetTrackingCorrection(1);
982     modifiedEffpT->SetLineColor(i+1);
983     modifiedEffpT->Draw("SAME");
984     
985     // apply change in tracking efficiency
986     ueHistData->CorrectTracks(AliUEHist::kCFStepTriggered, AliUEHist::kCFStepAll, modifiedEff, 0, 1);
987   
988     for (Int_t region=0; region<maxRegion; region++)
989     {
990       // histogram after
991       TH1* after = ueHistData->GetUEHist(AliUEHist::kCFStepAll, region, ptLeadMin, ptLeadMax);
992       
993       if (verbose)
994         DrawRatio(before[region], (TH1*) after->Clone(), Form("Region %d Composition %d", region, i));
995       
996       // ratio is flat, extract deviation
997       after->Divide(before[region]);
998       after->Fit("pol0", "0");
999       Float_t deviation = 100.0 - 100.0 * after->GetFunction("pol0")->GetParameter(0);
1000       Printf("Deviation for region %d case %d is %.2f %%", region, i, deviation);
1001       
1002       if (TMath::Abs(deviation) > largestDeviation[region])
1003         largestDeviation[region] = TMath::Abs(deviation);
1004     }
1005     //return;
1006   }
1007   
1008   for (Int_t i=0; i<maxRegion; i++)
1009     Printf("Largest deviation in region %d is %f", i, largestDeviation[i]);
1010 }    
1011
1012 void MergeList()
1013 {
1014   loadlibs();
1015
1016   ifstream in;
1017   in.open("list");
1018
1019   TFileMerger m;
1020
1021   TString line;
1022   while (in.good())
1023   {
1024     in >> line;
1025
1026     if (line.Length() == 0)
1027       continue;
1028
1029     TString fileName;
1030     fileName.Form("%s/%s/PWG4_JetTasksOutput.root", "maps", line.Data());
1031     Printf("%s", fileName.Data());
1032     
1033     m.AddFile(fileName);
1034   }
1035   
1036   m.SetFastMethod();
1037   m.OutputFile("merged.root");
1038   m.Merge();
1039 }
1040
1041 void MergeList2(const char* listFile, const char* dir, Bool_t onlyPrintEvents = kFALSE, const char* targetDir = "PWG4_LeadingTrackUE")
1042 {
1043   loadlibs();
1044
1045   ifstream in;
1046   in.open(listFile);
1047   
1048   AliUEHistograms* final = 0;
1049   TList* finalList = 0;
1050
1051   TString line;
1052   while (in.good())
1053   {
1054     in >> line;
1055
1056     if (line.Length() == 0)
1057       continue;
1058
1059     TString fileName;
1060     fileName.Form("%s/%s/PWG4_JetTasksOutput.root", dir, line.Data());
1061     Printf("%s", fileName.Data());
1062     
1063     TList* list = 0;
1064     AliUEHistograms* obj = (AliUEHistograms*) GetUEHistogram(fileName, &list);
1065     if (!obj)
1066       continue;
1067     
1068     if (!final)
1069     {
1070       final = (AliUEHistograms*) obj;
1071       //final->GetEventCount()->Draw(); return;
1072       Printf("Events: %d", (Int_t) final->GetEventCount()->ProjectionX()->GetBinContent(4));
1073       finalList = list;
1074     }
1075     else
1076     {
1077       additional = (AliUEHistograms*) obj;
1078       Printf("Events: %d", (Int_t) additional->GetEventCount()->ProjectionX()->GetBinContent(4));
1079       
1080       if (!onlyPrintEvents)
1081       {
1082         TList list2;
1083         list2.Add(additional);
1084         final->Merge(&list2);
1085       }
1086       delete additional;
1087       gFile->Close();
1088     }
1089   }
1090   
1091   if (onlyPrintEvents)
1092     return;
1093     
1094   Printf("Total events (at step 0): %d", (Int_t) final->GetEventCount()->ProjectionX()->GetBinContent(4));
1095   
1096   file3 = TFile::Open("merged.root", "RECREATE");
1097   file3->mkdir(targetDir);
1098   file3->cd(targetDir);
1099   finalList->Write(0, TObject::kSingleKey);
1100   file3->Close();
1101 }
1102
1103 void PlotAll(const char* correctedFile, const char* mcFile)
1104 {
1105   gCache = 1;
1106   
1107   if (gEnergy == 900)
1108   {
1109     Float_t range[] = { 1.5, 2 };
1110   }
1111   else
1112   {
1113     Float_t range[] = { 3, 10 };
1114   }
1115   
1116   for (Int_t id=0; id<3; id++)
1117   {
1118     if (id < 2)
1119       gForceRange = range[id];
1120     else
1121       gForceRange = -1;
1122       
1123     if (id < 2)
1124     {
1125       for (Int_t region=0; region<3; region++)
1126       {
1127         CompareStep(correctedFile, mcFile, id, 0, region);
1128         gPad->GetCanvas()->SaveAs(Form("%s_%s_%d_%d.png", TString(correctedFile).Tokenize(".")->First()->GetName(), TString(mcFile).Tokenize(".")->First()->GetName(), id, region));
1129       }
1130     }
1131     else
1132     {
1133       Float_t leadingPtArr[] = { 0.50, 2.0, 4.0, 6.0, 10.0, 20.0, 50.0 };
1134       for (Int_t leadingPtID=0; leadingPtID<6; leadingPtID++)
1135       {
1136         CompareStep(correctedFile, mcFile, id, 0, 0, leadingPtArr[leadingPtID] + 0.01, leadingPtArr[leadingPtID+1] - 0.01);
1137         gPad->GetCanvas()->SaveAs(Form("%s_%s_%d_%.2f_%.2f.png", TString(correctedFile).Tokenize(".")->First()->GetName(), TString(mcFile).Tokenize(".")->First()->GetName(), id, leadingPtArr[leadingPtID], leadingPtArr[leadingPtID+1]));
1138       }
1139     }
1140   }
1141 }
1142
1143 /*
1144 TGraph* GetFlow2040()
1145 {
1146   // from first ALICE flow paper (provided by Raimond)
1147   // http://www-library.desy.de/spires/find/hep/www?eprint=arXiv:1011.3914
1148   
1149   // centrality 20-30% 
1150   Double_t xCumulant4th2030ALICE[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
1151   1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000,
1152   5.500000,7.000000,9.000000};
1153   Double_t yCumulant4th2030ALICE[] = {0.000000,0.000000,0.030926,0.041076,0.052063,0.059429,0.070500,0.084461,0.086745,0.099254,
1154   0.109691,0.116398,0.130831,0.141959,0.158932,0.169680,0.171387,0.178858,0.171475,0.140358,
1155   0.000000,0.000000,0.000000};
1156   Double_t xErrCumulant4th2030ALICE[23] = {0.};
1157   Double_t yErrCumulant4th2030ALICE[] = {0.000000,0.000000,0.002857,0.003451,0.003567,0.003859,0.004609,0.004976,0.005412,0.006277,
1158   0.004748,0.005808,0.006896,0.007987,0.008683,0.008080,0.013278,0.018413,0.024873,0.026057,
1159   0.000000,0.000000,0.000000};
1160   Int_t nPointsCumulant4th2030ALICE = sizeof(xCumulant4th2030ALICE)/sizeof(Double_t);                                      
1161   TGraphErrors *Cumulant4th2030ALICE = new TGraphErrors(nPointsCumulant4th2030ALICE,xCumulant4th2030ALICE,yCumulant4th2030ALICE,
1162                                                         xErrCumulant4th2030ALICE,yErrCumulant4th2030ALICE);
1163   Cumulant4th2030ALICE->SetMarkerStyle(kFullSquare);
1164   Cumulant4th2030ALICE->SetMarkerColor(kRed);
1165   Cumulant4th2030ALICE->SetMarkerSize(1.2);
1166   Cumulant4th2030ALICE->SetFillStyle(1001);
1167   Cumulant4th2030ALICE->SetFillColor(kRed-10);
1168   
1169   //===================================================================================================================
1170   // centrality 30-40% 
1171   Double_t xCumulant4th3040ALICE[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
1172   1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000,
1173   5.500000,7.000000,9.000000};
1174   Double_t yCumulant4th3040ALICE[] = {0.000000,0.000000,0.037071,0.048566,0.061083,0.070910,0.078831,0.091396,0.102026,0.109691,
1175   0.124449,0.139819,0.155561,0.165701,0.173678,0.191149,0.202015,0.204540,0.212560,0.195885,
1176   0.000000,0.000000,0.000000};
1177   Double_t xErrCumulant4th3040ALICE[23] = {0.};
1178   Double_t yErrCumulant4th3040ALICE[] = {0.000000,0.000000,0.002992,0.003364,0.003669,0.003931,0.004698,0.005261,0.005446,0.006151,
1179   0.004980,0.005741,0.007198,0.008576,0.010868,0.009926,0.015269,0.020691,0.027601,0.031834,
1180   0.000000,0.000000,0.000000};
1181   Int_t nPointsCumulant4th3040ALICE = sizeof(xCumulant4th3040ALICE)/sizeof(Double_t);
1182   TGraphErrors *Cumulant4th3040ALICE = new TGraphErrors(nPointsCumulant4th3040ALICE,xCumulant4th3040ALICE,yCumulant4th3040ALICE,
1183                                                         xErrCumulant4th3040ALICE,yErrCumulant4th3040ALICE);
1184   Cumulant4th3040ALICE->SetMarkerStyle(kFullTriangleUp);
1185   Cumulant4th3040ALICE->SetMarkerColor(kGreen+2);
1186   Cumulant4th3040ALICE->SetMarkerSize(1.2);
1187   Cumulant4th3040ALICE->SetFillStyle(1001);
1188   Cumulant4th3040ALICE->SetFillColor(kGreen+2);
1189   
1190   // build average between the two (for class 20-40%)
1191   Double_t* yAverage = new Double_t[nPointsCumulant4th3040ALICE];
1192   for (Int_t i=0; i<nPointsCumulant4th3040ALICE; i++)
1193     yAverage[i] = (yCumulant4th2030ALICE[i] + yCumulant4th3040ALICE[i]) / 2;
1194     
1195   // assume flow constant above highest pT; not neccessarily physically sound ;)
1196   if (1)
1197   {
1198     yAverage[20] = yAverage[19];
1199     xCumulant4th3040ALICE[20] = 100;
1200     nPointsCumulant4th3040ALICE -= 2;
1201   }
1202   
1203   TGraph *flow2040 = new TGraph(nPointsCumulant4th3040ALICE,xCumulant4th3040ALICE,yAverage);
1204   
1205   if (0)
1206   {
1207     flow2040->Draw("*A");
1208     Cumulant4th2030ALICE->Draw("PSAME");
1209     Cumulant4th3040ALICE->Draw("PSAME");
1210   }
1211   
1212   return flow2040;
1213 }
1214 */
1215
1216 /*
1217 TGraph* GetFlow1020()
1218 {
1219   // from first ALICE flow paper (provided by Raimond)
1220   // http://www-library.desy.de/spires/find/hep/www?eprint=arXiv:1011.3914
1221   
1222   //===================================================================================================================
1223   // centrality 10-20% 
1224   Double_t xCumulant4th1020ALICE[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
1225   1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000,
1226   5.500000,7.000000,9.000000};
1227   Double_t yCumulant4th1020ALICE[] = {0.000000,0.000000,0.024075,0.031505,0.040413,0.044981,0.055358,0.060563,0.063378,0.070030,
1228   0.082692,0.091611,0.099641,0.107223,0.122376,0.131240,0.137425,0.146050,0.131365,0.124708,
1229   0.000000,0.000000,0.000000};
1230   Double_t xErrCumulant4th1020ALICE[23] = {0.};
1231   Double_t yErrCumulant4th1020ALICE[] = {0.000000,0.000000,0.002413,0.002931,0.003444,0.003950,0.004338,0.004835,0.005059,0.005586,
1232   0.004521,0.005278,0.005999,0.007072,0.008260,0.007279,0.011897,0.017409,0.023995,0.025701,
1233   0.000000,0.000000,0.000000};
1234   Int_t nPointsCumulant4th1020ALICE = sizeof(xCumulant4th1020ALICE)/sizeof(Double_t);                                      
1235   
1236   // assume flow constant above highest pT; not neccessarily physically sound ;)
1237   if (1)
1238   {
1239     yCumulant4th1020ALICE[20] = yCumulant4th1020ALICE[19];
1240     xCumulant4th1020ALICE[20] = 100;
1241     nPointsCumulant4th1020ALICE -= 2;
1242   }
1243   
1244   TGraphErrors *Cumulant4th1020ALICE = new TGraphErrors(nPointsCumulant4th1020ALICE,xCumulant4th1020ALICE,yCumulant4th1020ALICE,
1245                                                         xErrCumulant4th1020ALICE,yErrCumulant4th1020ALICE);
1246   
1247  Cumulant4th1020ALICE->SetMarkerStyle(kFullCircle);
1248  Cumulant4th1020ALICE->SetMarkerColor(kBlue);
1249  Cumulant4th1020ALICE->SetMarkerSize(1.2);
1250  Cumulant4th1020ALICE->SetFillStyle(1001);
1251  Cumulant4th1020ALICE->SetFillColor(kBlue-10);
1252   
1253   TGraph *flow1020 = new TGraph(nPointsCumulant4th1020ALICE,xCumulant4th1020ALICE,yCumulant4th1020ALICE);
1254   
1255   if (0)
1256   {
1257     flow1020->Draw("*A");
1258     Cumulant4th1020ALICE->Draw("PSAME");
1259   }
1260   
1261   return flow1020;
1262 }
1263 */
1264
1265 /*
1266 TGraph* GetFlow05()
1267 {
1268   // takes flow measurement from 10-20% and scales by a factor extracted from Fig.3 in the ALICE flow paper
1269   // factor = integrated flow in 0-5% / integrated flow in 10-20%
1270   
1271   graph = GetFlow1020();
1272   for (Int_t i=0; i<graph->GetN(); i++)
1273     graph->GetY()[i] *= 0.016 / 0.055;
1274     
1275   return graph;
1276 }
1277 */
1278
1279 TGraphErrors* GetFlow02(Int_t n)
1280 {
1281   // private communication 28.01.11, Ante B. / Raimond
1282
1283   if (n == 2)
1284   {
1285     // v2{2}(pt):
1286     Double_t xCumulant2nd0002ALICE_v2[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
1287     1.050000,1.150000,1.250000,1.350000,1.450000,1.550000,1.650000,1.750000,1.850000,1.950000,
1288     2.250000,2.750000,3.250000,3.750000,4.250000,4.750000,5.500000,6.500000,7.500000,8.500000,
1289     9.500000};
1290     Double_t yCumulant2nd0002ALICE_v2[] = {0.000000,0.000000,0.012173,0.015186,0.018580,0.021114,0.024646,0.027040,0.030269,0.032677,
1291     0.035332,0.037382,0.039228,0.040614,0.042460,0.044658,0.046246,0.050392,0.051436,0.054669,
1292     0.057330,0.063439,0.067425,0.060144,0.071260,0.070206,0.000000,0.000000,0.000000,0.000000,
1293     0.000000};
1294     Double_t xErrCumulant2nd0002ALICE_v2[31] = {0.};
1295     Double_t yErrCumulant2nd0002ALICE_v2[] = {0.000000,0.000000,0.000256,0.000259,0.000271,0.000296,0.000322,0.000357,0.000397,0.000438,
1296     0.000483,0.000529,0.000590,0.000639,0.000713,0.000793,0.000877,0.000976,0.001070,0.001197,
1297     0.000725,0.001265,0.002069,0.003156,0.004605,0.006543,0.000000,0.000000,0.000000,0.000000,
1298     0.000000};
1299     Int_t nPointsCumulant2nd0002ALICE_v2 = sizeof(xCumulant2nd0002ALICE_v2)/sizeof(Double_t);                                      
1300     TGraphErrors *Cumulant2nd0002ALICE_v2 = new TGraphErrors(nPointsCumulant2nd0002ALICE_v2,xCumulant2nd0002ALICE_v2,yCumulant2nd0002ALICE_v2,
1301                                                           xErrCumulant2nd0002ALICE_v2,yErrCumulant2nd0002ALICE_v2);
1302     Cumulant2nd0002ALICE_v2->SetMarkerStyle(kFullCircle);
1303     Cumulant2nd0002ALICE_v2->SetMarkerColor(kBlue);
1304     
1305     return Cumulant2nd0002ALICE_v2;
1306   }
1307   
1308   if (n == 3)
1309   {
1310     // v3{2}(pt):
1311     Double_t xCumulant2nd0002ALICE_v3[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
1312     1.050000,1.150000,1.250000,1.350000,1.450000,1.550000,1.650000,1.750000,1.850000,1.950000,
1313     2.250000,2.750000,3.250000,3.750000,4.250000,4.750000,5.500000,6.500000,7.500000,8.500000,
1314     9.500000};
1315     Double_t yCumulant2nd0002ALICE_v3[] = {0.000000,0.000000,0.007696,0.008994,0.010544,0.013269,0.016330,0.019234,0.023465,0.026803,
1316     0.029906,0.032211,0.035300,0.038158,0.041861,0.046002,0.049382,0.053574,0.055773,0.059420,
1317     0.069373,0.079922,0.090265,0.103583,0.111358,0.090740,0.000000,0.000000,0.000000,0.000000,
1318     0.000000};
1319     Double_t xErrCumulant2nd0002ALICE_v3[31] = {0.};
1320     Double_t yErrCumulant2nd0002ALICE_v3[] = {0.000000,0.000000,0.000318,0.000317,0.000333,0.000360,0.000392,0.000431,0.000476,0.000523,
1321     0.000575,0.000637,0.000707,0.000785,0.000878,0.000964,0.001064,0.001175,0.001320,0.001459,
1322     0.000889,0.001539,0.002530,0.003826,0.005614,0.007892,0.000000,0.000000,0.000000,0.000000,
1323     0.000000};
1324     Int_t nPointsCumulant2nd0002ALICE_v3 = sizeof(xCumulant2nd0002ALICE_v3)/sizeof(Double_t);                                      
1325     TGraphErrors *Cumulant2nd0002ALICE_v3 = new TGraphErrors(nPointsCumulant2nd0002ALICE_v3,xCumulant2nd0002ALICE_v3,yCumulant2nd0002ALICE_v3,
1326                                                           xErrCumulant2nd0002ALICE_v3,yErrCumulant2nd0002ALICE_v3);
1327     Cumulant2nd0002ALICE_v3->SetMarkerStyle(kFullTriangleUp);
1328     Cumulant2nd0002ALICE_v3->SetMarkerSize(1.2);
1329     Cumulant2nd0002ALICE_v3->SetMarkerColor(kGreen+2); 
1330     
1331     return Cumulant2nd0002ALICE_v3;
1332   }
1333   
1334   if (n == 4)
1335   {
1336     // v4{2}(pt):
1337     Double_t xCumulant2nd0002ALICE_v4[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
1338     1.050000,1.150000,1.250000,1.350000,1.450000,1.550000,1.650000,1.750000,1.850000,1.950000,
1339     2.250000,2.750000,3.250000,3.750000,4.250000,4.750000,5.500000,6.500000,7.500000,8.500000,
1340     9.500000};
1341     Double_t yCumulant2nd0002ALICE_v4[] = {0.000000,0.000000,0.005710,0.006014,0.004483,0.005453,0.007714,0.006837,0.009721,0.011288,
1342     0.012531,0.016461,0.016606,0.018587,0.022722,0.025497,0.025832,0.030994,0.030349,0.034730,
1343     0.045529,0.061153,0.074238,0.079307,0.088885,0.085218,0.000000,0.000000,0.000000,0.000000,
1344     0.000000};
1345     Double_t xErrCumulant2nd0002ALICE_v4[31] = {0.};
1346     Double_t yErrCumulant2nd0002ALICE_v4[] = {0.000000,0.000000,0.000488,0.000493,0.000523,0.000571,0.000609,0.000678,0.000742,0.000805,
1347     0.000903,0.000985,0.001100,0.001219,0.001352,0.001503,0.001682,0.001847,0.002060,0.002303,
1348     0.001400,0.002431,0.003974,0.006040,0.008901,0.012343,0.000000,0.000000,0.000000,0.000000,
1349     0.000000};
1350     Int_t nPointsCumulant2nd0002ALICE_v4 = sizeof(xCumulant2nd0002ALICE_v4)/sizeof(Double_t);                                      
1351     TGraphErrors *Cumulant2nd0002ALICE_v4 = new TGraphErrors(nPointsCumulant2nd0002ALICE_v4,xCumulant2nd0002ALICE_v4,yCumulant2nd0002ALICE_v4,
1352                                                           xErrCumulant2nd0002ALICE_v4,yErrCumulant2nd0002ALICE_v4);
1353     Cumulant2nd0002ALICE_v4->SetMarkerStyle(kFullSquare);
1354     Cumulant2nd0002ALICE_v4->SetMarkerColor(kRed);  
1355     
1356     return Cumulant2nd0002ALICE_v4;
1357   }
1358   
1359   return 0;
1360 }
1361
1362 /* results up to 5 GeV/c
1363
1364 TGraphErrors* GetFlow05(Int_t n)
1365 {
1366   // private communication 02.02.11, Ante B. / Raimond
1367
1368   if (n == 2)
1369   {
1370     // v2{2}(pt) for 0-5%:
1371     Double_t xCumulant2nd0005ALICE_v2[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
1372     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
1373     Double_t yCumulant2nd0005ALICE_v2[] = {0.000000,0.000000,0.013891,0.017693,0.021693,0.025323,0.029131,0.032443,0.035781,0.038256,
1374     0.042801,0.047705,0.053229,0.057387,0.062677,0.068815,0.077695,0.082058,0.082511,0.079791};
1375     Double_t xErrCumulant2nd0005ALICE_v2[20] = {0.};
1376     Double_t yErrCumulant2nd0005ALICE_v2[] = {0.000000,0.000000,0.000149,0.000150,0.000160,0.000174,0.000191,0.000211,0.000233,0.000257,
1377     0.000208,0.000254,0.000311,0.000377,0.000464,0.000419,0.000726,0.001180,0.001791,0.002131};
1378     Int_t nPointsCumulant2nd0005ALICE_v2 = sizeof(xCumulant2nd0005ALICE_v2)/sizeof(Double_t);                                      
1379     TGraphErrors *Cumulant2nd0005ALICE_v2 = new TGraphErrors(nPointsCumulant2nd0005ALICE_v2,xCumulant2nd0005ALICE_v2,yCumulant2nd0005ALICE_v2,
1380                                                           xErrCumulant2nd0005ALICE_v2,yErrCumulant2nd0005ALICE_v2);
1381     Cumulant2nd0005ALICE_v2->SetMarkerStyle(kFullCircle);
1382     Cumulant2nd0005ALICE_v2->SetMarkerColor(kBlue);    
1383     
1384     return Cumulant2nd0005ALICE_v2;
1385   }
1386   
1387   if (n == 3)
1388   {
1389     // v3{2}(pt) for 0-5%:
1390     Double_t xCumulant2nd0005ALICE_v3[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
1391     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
1392     Double_t yCumulant2nd0005ALICE_v3[] = {0.000000,0.000000,0.007788,0.009472,0.011596,0.014618,0.017540,0.021020,0.024946,0.028004,
1393     0.032330,0.039491,0.046368,0.053620,0.060662,0.071750,0.086746,0.097857,0.103111,0.104796};
1394     Double_t xErrCumulant2nd0005ALICE_v3[20] = {0.};
1395     Double_t yErrCumulant2nd0005ALICE_v3[] = {0.000000,0.000000,0.000194,0.000192,0.000204,0.000221,0.000241,0.000265,0.000293,0.000323,
1396     0.000266,0.000323,0.000397,0.000486,0.000601,0.000545,0.000947,0.001541,0.002328,0.002777};
1397     Int_t nPointsCumulant2nd0005ALICE_v3 = sizeof(xCumulant2nd0005ALICE_v3)/sizeof(Double_t);                                      
1398     TGraphErrors *Cumulant2nd0005ALICE_v3 = new TGraphErrors(nPointsCumulant2nd0005ALICE_v3,xCumulant2nd0005ALICE_v3,yCumulant2nd0005ALICE_v3,
1399                                                           xErrCumulant2nd0005ALICE_v3,yErrCumulant2nd0005ALICE_v3);
1400     Cumulant2nd0005ALICE_v3->SetMarkerStyle(kFullCircle);
1401     Cumulant2nd0005ALICE_v3->SetMarkerColor(kBlue);
1402
1403     return Cumulant2nd0005ALICE_v3;
1404   }
1405   
1406   if (n == 4)
1407   {
1408     // v4{2}(pt) for 0-5%:
1409     Double_t xCumulant2nd0005ALICE_v4[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
1410     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
1411     Double_t yCumulant2nd0005ALICE_v4[] = {0.000000,0.000000,0.006121,0.006137,0.005598,0.005956,0.007262,0.007991,0.009159,0.012062,
1412     0.015085,0.019225,0.024782,0.030092,0.035708,0.046542,0.060077,0.076088,0.082964,0.085405};
1413     Double_t xErrCumulant2nd0005ALICE_v4[20] = {0.};
1414     Double_t yErrCumulant2nd0005ALICE_v4[] = {0.000000,0.000000,0.000275,0.000278,0.000294,0.000319,0.000346,0.000380,0.000419,0.000459,
1415     0.000378,0.000460,0.000570,0.000700,0.000865,0.000789,0.001370,0.002227,0.003370,0.004018};
1416     Int_t nPointsCumulant2nd0005ALICE_v4 = sizeof(xCumulant2nd0005ALICE_v4)/sizeof(Double_t);                                      
1417     TGraphErrors *Cumulant2nd0005ALICE_v4 = new TGraphErrors(nPointsCumulant2nd0005ALICE_v4,xCumulant2nd0005ALICE_v4,yCumulant2nd0005ALICE_v4,
1418                                                           xErrCumulant2nd0005ALICE_v4,yErrCumulant2nd0005ALICE_v4);
1419     Cumulant2nd0005ALICE_v4->SetMarkerStyle(kFullCircle);
1420     Cumulant2nd0005ALICE_v4->SetMarkerColor(kBlue); 
1421     
1422     return Cumulant2nd0005ALICE_v4;
1423   }
1424   
1425   return 0;
1426 }
1427
1428 TGraphErrors* GetFlow510(Int_t n)
1429 {
1430   // private communication 02.02.11, Ante B. / Raimond
1431
1432   if (n == 2)
1433   {
1434     // v2{2}(pt) for 5-10%:
1435     Double_t xCumulant2nd0510ALICE_v2[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
1436     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
1437     Double_t yCumulant2nd0510ALICE_v2[] = {0.000000,0.000000,0.019872,0.026451,0.032901,0.039085,0.044930,0.050200,0.054887,0.060253,
1438     0.066587,0.075080,0.083303,0.090298,0.098782,0.109632,0.124486,0.129621,0.132076,0.120697};
1439     Double_t xErrCumulant2nd0510ALICE_v2[20] = {0.};
1440     Double_t yErrCumulant2nd0510ALICE_v2[] = {0.000000,0.000000,0.000150,0.000152,0.000163,0.000178,0.000196,0.000215,0.000237,0.000261,
1441     0.000213,0.000256,0.000313,0.000381,0.000468,0.000423,0.000727,0.001157,0.001741,0.002064};
1442     Int_t nPointsCumulant2nd0510ALICE_v2 = sizeof(xCumulant2nd0510ALICE_v2)/sizeof(Double_t);                                      
1443     TGraphErrors *Cumulant2nd0510ALICE_v2 = new TGraphErrors(nPointsCumulant2nd0510ALICE_v2,xCumulant2nd0510ALICE_v2,yCumulant2nd0510ALICE_v2,
1444                                                           xErrCumulant2nd0510ALICE_v2,yErrCumulant2nd0510ALICE_v2);
1445     Cumulant2nd0510ALICE_v2->SetMarkerStyle(kOpenCircle);
1446     Cumulant2nd0510ALICE_v2->SetMarkerColor(kBlue);   
1447      
1448     return Cumulant2nd0510ALICE_v2;
1449   }
1450   
1451   if (n == 3)
1452   {
1453     // v3{2}(pt) for 5-10%:
1454     Double_t xCumulant2nd0510ALICE_v3[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
1455     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
1456     Double_t yCumulant2nd0510ALICE_v3[] = {0.000000,0.000000,0.008596,0.010700,0.013820,0.017524,0.021507,0.024316,0.028491,0.032880,
1457     0.038741,0.045830,0.052486,0.059560,0.067990,0.081006,0.097402,0.107050,0.111743,0.116434};
1458     Double_t xErrCumulant2nd0510ALICE_v3[20] = {0.};
1459     Double_t yErrCumulant2nd0510ALICE_v3[] = {0.000000,0.000000,0.000208,0.000207,0.000218,0.000235,0.000258,0.000284,0.000314,0.000347,
1460     0.000285,0.000345,0.000426,0.000521,0.000642,0.000586,0.001008,0.001611,0.002421,0.002853};
1461     Int_t nPointsCumulant2nd0510ALICE_v3 = sizeof(xCumulant2nd0510ALICE_v3)/sizeof(Double_t);                                      
1462     TGraphErrors *Cumulant2nd0510ALICE_v3 = new TGraphErrors(nPointsCumulant2nd0510ALICE_v3,xCumulant2nd0510ALICE_v3,yCumulant2nd0510ALICE_v3,
1463                                                           xErrCumulant2nd0510ALICE_v3,yErrCumulant2nd0510ALICE_v3);
1464     Cumulant2nd0510ALICE_v3->SetMarkerStyle(kOpenCircle);
1465     Cumulant2nd0510ALICE_v3->SetMarkerColor(kBlue);
1466     
1467     return Cumulant2nd0510ALICE_v3;
1468   }
1469   
1470   if (n == 4)
1471   {
1472     // v4{2}(pt) for 5-10%:
1473     Double_t xCumulant2nd0510ALICE_v4[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
1474     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
1475     Double_t yCumulant2nd0510ALICE_v4[] = {0.000000,0.000000,0.006466,0.006731,0.006344,0.007374,0.008775,0.010324,0.012323,0.014533,
1476     0.017261,0.022507,0.028776,0.035403,0.041936,0.051491,0.070340,0.080081,0.095077,0.088526};
1477     Double_t xErrCumulant2nd0510ALICE_v4[20] = {0.};
1478     Double_t yErrCumulant2nd0510ALICE_v4[] = {0.000000,0.000000,0.000292,0.000295,0.000312,0.000336,0.000366,0.000403,0.000443,0.000485,
1479     0.000399,0.000486,0.000603,0.000738,0.000914,0.000836,0.001443,0.002303,0.003448,0.004078};
1480     Int_t nPointsCumulant2nd0510ALICE_v4 = sizeof(xCumulant2nd0510ALICE_v4)/sizeof(Double_t);                                      
1481     TGraphErrors *Cumulant2nd0510ALICE_v4 = new TGraphErrors(nPointsCumulant2nd0510ALICE_v4,xCumulant2nd0510ALICE_v4,yCumulant2nd0510ALICE_v4,
1482                                                           xErrCumulant2nd0510ALICE_v4,yErrCumulant2nd0510ALICE_v4);
1483     Cumulant2nd0510ALICE_v4->SetMarkerStyle(kOpenCircle);
1484     Cumulant2nd0510ALICE_v4->SetMarkerColor(kBlue);    
1485     
1486     return Cumulant2nd0510ALICE_v4;
1487   }
1488   
1489   return 0;
1490 }
1491
1492 TGraphErrors* GetFlow1020(Int_t n)
1493 {
1494   // private communication 02.02.11, Ante B. / Raimond
1495
1496   if (n == 2)
1497   {
1498     // v2{2}(pt) for 10-20%:
1499     Double_t xCumulant2nd1020ALICE_v2[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
1500     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
1501     Double_t yCumulant2nd1020ALICE_v2[] = {0.000000,0.000000,0.027683,0.037083,0.046511,0.055519,0.063979,0.071626,0.078537,0.085975,
1502     0.095001,0.106979,0.118456,0.129721,0.140641,0.155161,0.173402,0.179870,0.180616,0.168921};
1503     Double_t xErrCumulant2nd1020ALICE_v2[20] = {0.};
1504     Double_t yErrCumulant2nd1020ALICE_v2[] = {0.000000,0.000000,0.000121,0.000124,0.000134,0.000147,0.000163,0.000179,0.000198,0.000217,
1505     0.000177,0.000212,0.000257,0.000311,0.000380,0.000341,0.000569,0.000882,0.001309,0.001537};
1506     Int_t nPointsCumulant2nd1020ALICE_v2 = sizeof(xCumulant2nd1020ALICE_v2)/sizeof(Double_t);                                      
1507     TGraphErrors *Cumulant2nd1020ALICE_v2 = new TGraphErrors(nPointsCumulant2nd1020ALICE_v2,xCumulant2nd1020ALICE_v2,yCumulant2nd1020ALICE_v2,
1508                                                           xErrCumulant2nd1020ALICE_v2,yErrCumulant2nd1020ALICE_v2);
1509     Cumulant2nd1020ALICE_v2->SetMarkerStyle(kFullSquare);
1510     Cumulant2nd1020ALICE_v2->SetMarkerColor(kRed);     
1511     
1512     return Cumulant2nd1020ALICE_v2;
1513   }
1514   
1515   if (n == 3)
1516   {
1517     // v3{2}(pt) for 10-20%:
1518     Double_t xCumulant2nd1020ALICE_v3[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
1519     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
1520     Double_t yCumulant2nd1020ALICE_v3[] = {0.000000,0.000000,0.009830,0.012858,0.016111,0.020120,0.023948,0.028349,0.032741,0.037244,
1521     0.043385,0.051803,0.059374,0.068686,0.076763,0.090151,0.106530,0.117448,0.121383,0.118247};
1522     Double_t xErrCumulant2nd1020ALICE_v3[20] = {0.};
1523     Double_t yErrCumulant2nd1020ALICE_v3[] = {0.000000,0.000000,0.000171,0.000170,0.000180,0.000195,0.000215,0.000236,0.000261,0.000287,
1524     0.000236,0.000288,0.000353,0.000434,0.000536,0.000488,0.000823,0.001277,0.001892,0.002224};
1525     Int_t nPointsCumulant2nd1020ALICE_v3 = sizeof(xCumulant2nd1020ALICE_v3)/sizeof(Double_t);                                      
1526     TGraphErrors *Cumulant2nd1020ALICE_v3 = new TGraphErrors(nPointsCumulant2nd1020ALICE_v3,xCumulant2nd1020ALICE_v3,yCumulant2nd1020ALICE_v3,
1527                                                           xErrCumulant2nd1020ALICE_v3,yErrCumulant2nd1020ALICE_v3);
1528     Cumulant2nd1020ALICE_v3->SetMarkerStyle(kFullSquare);
1529     Cumulant2nd1020ALICE_v3->SetMarkerColor(kRed); 
1530     
1531     return Cumulant2nd1020ALICE_v3;
1532   }
1533   
1534   if (n == 4)
1535   {
1536     // v4{2}(pt) for 10-20%:
1537     Double_t xCumulant2nd1020ALICE_v4[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
1538     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
1539     Double_t yCumulant2nd1020ALICE_v4[] = {0.000000,0.000000,0.007423,0.007647,0.008189,0.008592,0.009489,0.011671,0.013739,0.017199,
1540     0.020084,0.026004,0.031843,0.038388,0.047357,0.057251,0.072433,0.086326,0.094282,0.097432};
1541     Double_t xErrCumulant2nd1020ALICE_v4[20] = {0.};
1542     Double_t yErrCumulant2nd1020ALICE_v4[] = {0.000000,0.000000,0.000243,0.000244,0.000257,0.000279,0.000306,0.000335,0.000368,0.000405,
1543     0.000333,0.000406,0.000502,0.000618,0.000770,0.000701,0.001185,0.001845,0.002730,0.003193};
1544     Int_t nPointsCumulant2nd1020ALICE_v4 = sizeof(xCumulant2nd1020ALICE_v4)/sizeof(Double_t);                                      
1545     TGraphErrors *Cumulant2nd1020ALICE_v4 = new TGraphErrors(nPointsCumulant2nd1020ALICE_v4,xCumulant2nd1020ALICE_v4,yCumulant2nd1020ALICE_v4,
1546                                                           xErrCumulant2nd1020ALICE_v4,yErrCumulant2nd1020ALICE_v4);
1547     Cumulant2nd1020ALICE_v4->SetMarkerStyle(kFullSquare);
1548     Cumulant2nd1020ALICE_v4->SetMarkerColor(kRed); 
1549         
1550     return Cumulant2nd1020ALICE_v4;
1551   }
1552   
1553   return 0;
1554 }
1555
1556 TGraphErrors* GetFlow2030(Int_t n)
1557 {
1558   // private communication 02.02.11, Ante B. / Raimond
1559
1560   if (n == 2)
1561   {
1562     Double_t xCumulant2nd2030ALICE_v2[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
1563     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
1564     Double_t yCumulant2nd2030ALICE_v2[] = {0.000000,0.000000,0.035557,0.048064,0.060768,0.072585,0.083808,0.093772,0.103310,0.112602,
1565     0.124846,0.140603,0.155345,0.169450,0.183077,0.200173,0.219693,0.225741,0.223318,0.207356};
1566     Double_t xErrCumulant2nd2030ALICE_v2[20] = {0.};
1567     Double_t yErrCumulant2nd2030ALICE_v2[] = {0.000000,0.000000,0.000144,0.000147,0.000159,0.000175,0.000194,0.000214,0.000235,0.000259,
1568     0.000211,0.000254,0.000310,0.000377,0.000464,0.000418,0.000677,0.001027,0.001513,0.001761};
1569     Int_t nPointsCumulant2nd2030ALICE_v2 = sizeof(xCumulant2nd2030ALICE_v2)/sizeof(Double_t);                                      
1570     TGraphErrors *Cumulant2nd2030ALICE_v2 = new TGraphErrors(nPointsCumulant2nd2030ALICE_v2,xCumulant2nd2030ALICE_v2,yCumulant2nd2030ALICE_v2,
1571                                                           xErrCumulant2nd2030ALICE_v2,yErrCumulant2nd2030ALICE_v2);
1572     Cumulant2nd2030ALICE_v2->SetMarkerStyle(kOpenSquare);
1573     Cumulant2nd2030ALICE_v2->SetMarkerColor(kRed); 
1574         
1575     return Cumulant2nd2030ALICE_v2;
1576   }
1577   
1578   if (n == 3)
1579   {
1580     // v3{2}(pt) for 20-30%:
1581     Double_t xCumulant2nd2030ALICE_v3[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
1582     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
1583     Double_t yCumulant2nd2030ALICE_v3[] = {0.000000,0.000000,0.011287,0.014937,0.018479,0.022962,0.027854,0.031938,0.037038,0.041443,
1584     0.049872,0.058720,0.068353,0.077692,0.087859,0.099863,0.116141,0.124486,0.124786,0.119520};
1585     Double_t xErrCumulant2nd2030ALICE_v3[20] = {0.};
1586     Double_t yErrCumulant2nd2030ALICE_v3[] = {0.000000,0.000000,0.000215,0.000216,0.000228,0.000248,0.000272,0.000300,0.000332,0.000366,
1587     0.000301,0.000369,0.000456,0.000561,0.000700,0.000636,0.001038,0.001574,0.002307,0.002676};
1588     Int_t nPointsCumulant2nd2030ALICE_v3 = sizeof(xCumulant2nd2030ALICE_v3)/sizeof(Double_t);                                      
1589     TGraphErrors *Cumulant2nd2030ALICE_v3 = new TGraphErrors(nPointsCumulant2nd2030ALICE_v3,xCumulant2nd2030ALICE_v3,yCumulant2nd2030ALICE_v3,
1590                                                           xErrCumulant2nd2030ALICE_v3,yErrCumulant2nd2030ALICE_v3);
1591     Cumulant2nd2030ALICE_v3->SetMarkerStyle(kOpenSquare);
1592     Cumulant2nd2030ALICE_v3->SetMarkerColor(kRed); 
1593     
1594     return Cumulant2nd2030ALICE_v3;
1595   }
1596   
1597   if (n == 4)
1598   {
1599     // v4{2}(pt) for 20-30%:
1600     Double_t xCumulant2nd2030ALICE_v4[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
1601     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
1602     Double_t yCumulant2nd2030ALICE_v4[] = {0.000000,0.000000,0.008435,0.009824,0.009387,0.010408,0.011458,0.013770,0.016335,0.019165,
1603     0.023770,0.030071,0.036231,0.043950,0.051803,0.065222,0.082155,0.091864,0.105061,0.105167};
1604     Double_t xErrCumulant2nd2030ALICE_v4[20] = {0.};
1605     Double_t yErrCumulant2nd2030ALICE_v4[] = {0.000000,0.000000,0.000308,0.000308,0.000328,0.000355,0.000391,0.000430,0.000473,0.000524,
1606     0.000430,0.000524,0.000652,0.000807,0.001006,0.000919,0.001502,0.002277,0.003339,0.003871};
1607     Int_t nPointsCumulant2nd2030ALICE_v4 = sizeof(xCumulant2nd2030ALICE_v4)/sizeof(Double_t);                                      
1608     TGraphErrors *Cumulant2nd2030ALICE_v4 = new TGraphErrors(nPointsCumulant2nd2030ALICE_v4,xCumulant2nd2030ALICE_v4,yCumulant2nd2030ALICE_v4,
1609                                                           xErrCumulant2nd2030ALICE_v4,yErrCumulant2nd2030ALICE_v4);
1610     Cumulant2nd2030ALICE_v4->SetMarkerStyle(kOpenSquare);
1611     Cumulant2nd2030ALICE_v4->SetMarkerColor(kRed); 
1612         
1613     return Cumulant2nd2030ALICE_v4;
1614   }
1615   
1616   return 0;
1617 }
1618
1619 TGraphErrors* GetFlow3040(Int_t n)
1620 {
1621   // private communication 02.02.11, Ante B. / Raimond
1622
1623   if (n == 2)
1624   {
1625     // v2{2}(pt) for 30-40%:
1626     Double_t xCumulant2nd3040ALICE_v2[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
1627     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
1628     Double_t yCumulant2nd3040ALICE_v2[] = {0.000000,0.000000,0.040797,0.055427,0.070543,0.084024,0.096562,0.109411,0.119853,0.130964,
1629     0.145377,0.163806,0.179825,0.196178,0.210377,0.226556,0.245686,0.247898,0.240058,0.225011};
1630     Double_t xErrCumulant2nd3040ALICE_v2[20] = {0.};
1631     Double_t yErrCumulant2nd3040ALICE_v2[] = {0.000000,0.000000,0.000177,0.000182,0.000197,0.000216,0.000239,0.000265,0.000293,0.000325,
1632     0.000266,0.000321,0.000395,0.000486,0.000603,0.000536,0.000840,0.001258,0.001843,0.002118};
1633     Int_t nPointsCumulant2nd3040ALICE_v2 = sizeof(xCumulant2nd3040ALICE_v2)/sizeof(Double_t);                                      
1634     TGraphErrors *Cumulant2nd3040ALICE_v2 = new TGraphErrors(nPointsCumulant2nd3040ALICE_v2,xCumulant2nd3040ALICE_v2,yCumulant2nd3040ALICE_v2,
1635                                                           xErrCumulant2nd3040ALICE_v2,yErrCumulant2nd3040ALICE_v2);
1636     Cumulant2nd3040ALICE_v2->SetMarkerStyle(kFullTriangleUp);
1637     Cumulant2nd3040ALICE_v2->SetMarkerSize(1.2);
1638     Cumulant2nd3040ALICE_v2->SetMarkerColor(kGreen+2);     
1639     
1640     return Cumulant2nd3040ALICE_v2;
1641   }
1642   
1643   if (n == 3)
1644   {
1645     // v3{2}(pt) for 30-40%:
1646     Double_t xCumulant2nd3040ALICE_v3[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
1647     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
1648     Double_t yCumulant2nd3040ALICE_v3[] = {0.000000,0.000000,0.012226,0.016391,0.020792,0.026208,0.030380,0.035710,0.041025,0.047062,
1649     0.053075,0.064201,0.074116,0.085314,0.094391,0.106819,0.124012,0.129388,0.134315,0.132330};
1650     Double_t xErrCumulant2nd3040ALICE_v3[20] = {0.};
1651     Double_t yErrCumulant2nd3040ALICE_v3[] = {0.000000,0.000000,0.000284,0.000286,0.000303,0.000329,0.000364,0.000403,0.000443,0.000492,
1652     0.000408,0.000500,0.000627,0.000778,0.000973,0.000874,0.001375,0.002050,0.002992,0.003438};
1653     Int_t nPointsCumulant2nd3040ALICE_v3 = sizeof(xCumulant2nd3040ALICE_v3)/sizeof(Double_t);                                      
1654     TGraphErrors *Cumulant2nd3040ALICE_v3 = new TGraphErrors(nPointsCumulant2nd3040ALICE_v3,xCumulant2nd3040ALICE_v3,yCumulant2nd3040ALICE_v3,
1655                                                           xErrCumulant2nd3040ALICE_v3,yErrCumulant2nd3040ALICE_v3);
1656     Cumulant2nd3040ALICE_v3->SetMarkerStyle(kFullTriangleUp);
1657     Cumulant2nd3040ALICE_v3->SetMarkerSize(1.2);
1658     Cumulant2nd3040ALICE_v3->SetMarkerColor(kGreen+2); 
1659     
1660     return Cumulant2nd3040ALICE_v3;
1661   }
1662   
1663   if (n == 4)
1664   {
1665     // v4{2}(pt) for 30-40%:
1666     Double_t xCumulant2nd3040ALICE_v4[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
1667     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
1668     Double_t yCumulant2nd3040ALICE_v4[] = {0.000000,0.000000,0.010718,0.011490,0.010994,0.012527,0.013748,0.016425,0.018857,0.021622,
1669     0.026853,0.034636,0.042651,0.049892,0.057795,0.070865,0.088486,0.101656,0.113886,0.118202};
1670     Double_t xErrCumulant2nd3040ALICE_v4[20] = {0.};
1671     Double_t yErrCumulant2nd3040ALICE_v4[] = {0.000000,0.000000,0.000401,0.000406,0.000433,0.000472,0.000521,0.000575,0.000634,0.000704,
1672     0.000580,0.000714,0.000890,0.001114,0.001398,0.001253,0.001974,0.002945,0.004290,0.004909};
1673     Int_t nPointsCumulant2nd3040ALICE_v4 = sizeof(xCumulant2nd3040ALICE_v4)/sizeof(Double_t);                                      
1674     TGraphErrors *Cumulant2nd3040ALICE_v4 = new TGraphErrors(nPointsCumulant2nd3040ALICE_v4,xCumulant2nd3040ALICE_v4,yCumulant2nd3040ALICE_v4,
1675                                                           xErrCumulant2nd3040ALICE_v4,yErrCumulant2nd3040ALICE_v4);
1676     Cumulant2nd3040ALICE_v4->SetMarkerStyle(kFullTriangleUp);
1677     Cumulant2nd3040ALICE_v4->SetMarkerSize(1.2);
1678     Cumulant2nd3040ALICE_v4->SetMarkerColor(kGreen+2); 
1679         
1680     return Cumulant2nd3040ALICE_v4;
1681   }
1682   
1683   return 0;
1684 }
1685
1686 TGraphErrors* GetFlow4050(Int_t n)
1687 {
1688   // private communication 02.02.11, Ante B. / Raimond
1689
1690   if (n == 2)
1691   {
1692     // v2{2}(pt) for 40-50%:
1693     Double_t xCumulant2nd4050ALICE_v2[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
1694     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
1695     Double_t yCumulant2nd4050ALICE_v2[] = {0.000000,0.000000,0.043593,0.059522,0.075558,0.090681,0.104453,0.117913,0.129349,0.141743,
1696     0.157076,0.176121,0.193651,0.208844,0.222402,0.238407,0.252512,0.253592,0.243571,0.233018};
1697     Double_t xErrCumulant2nd4050ALICE_v2[20] = {0.};
1698     Double_t yErrCumulant2nd4050ALICE_v2[] = {0.000000,0.000000,0.000234,0.000241,0.000261,0.000288,0.000322,0.000357,0.000395,0.000438,
1699     0.000362,0.000447,0.000555,0.000685,0.000846,0.000733,0.001121,0.001665,0.002433,0.002768};
1700     Int_t nPointsCumulant2nd4050ALICE_v2 = sizeof(xCumulant2nd4050ALICE_v2)/sizeof(Double_t);                                      
1701     TGraphErrors *Cumulant2nd4050ALICE_v2 = new TGraphErrors(nPointsCumulant2nd4050ALICE_v2,xCumulant2nd4050ALICE_v2,yCumulant2nd4050ALICE_v2,
1702                                                           xErrCumulant2nd4050ALICE_v2,yErrCumulant2nd4050ALICE_v2);
1703     Cumulant2nd4050ALICE_v2->SetMarkerStyle(kOpenTriangleUp);
1704     Cumulant2nd4050ALICE_v2->SetMarkerSize(1.2);
1705     Cumulant2nd4050ALICE_v2->SetMarkerColor(kGreen+2);      
1706     
1707     return Cumulant2nd4050ALICE_v2;
1708   }
1709   
1710   return 0;
1711 }
1712 */
1713
1714 // results up to high pT
1715
1716 TGraphErrors* GetFlow05(Int_t n)
1717 {
1718   // private communication 09.03.11, Ante B. / Raimond
1719
1720   if (n == 2)
1721   {
1722     // v2{2}(pt) for 0-5%:
1723     Double_t xCumulant2nd0005ALICE[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
1724     1.050000,1.150000,1.250000,1.350000,1.450000,1.550000,1.650000,1.750000,1.850000,1.950000,
1725     2.100000,2.300000,2.500000,2.700000,2.900000,3.200000,3.600000,4.000000,4.400000,4.800000,
1726     5.500000,6.500000,7.500000,8.500000,9.500000,11.250000,13.750000,16.250000,18.750000,60.000000};
1727     Double_t yCumulant2nd0005ALICE[] = {0.000000,0.000000,0.018169,0.020988,0.024899,0.028309,0.031974,0.035188,0.038218,0.041202,
1728     0.043910,0.046560,0.048183,0.050640,0.052874,0.055334,0.056948,0.059427,0.061540,0.063218,
1729     0.065452,0.069222,0.072578,0.074723,0.077749,0.077178,0.080514,0.075325,0.077692,0.079710,
1730     0.073280,0.063849,0.068274,0.066045,0.071496,0.104352,0.091646,0.050220,0.124185,0.088535};
1731     Double_t xErrCumulant2nd0005ALICE[40] = {0.};
1732     Double_t yErrCumulant2nd0005ALICE[] = {0.000000,0.000000,0.000190,0.000191,0.000199,0.000212,0.000230,0.000248,0.000268,0.000293,
1733     0.000319,0.000346,0.000379,0.000418,0.000459,0.000502,0.000554,0.000614,0.000674,0.000749,
1734     0.000620,0.000769,0.000958,0.001182,0.001446,0.001331,0.001858,0.002552,0.003453,0.004606,
1735     0.004289,0.007006,0.010046,0.013853,0.017709,0.016630,0.025728,0.036763,0.045056,0.029011};
1736     Int_t nPointsCumulant2nd0005ALICE = sizeof(xCumulant2nd0005ALICE)/sizeof(Double_t);                                      
1737     TGraphErrors *Cumulant2nd0005ALICE = new TGraphErrors(nPointsCumulant2nd0005ALICE,xCumulant2nd0005ALICE,yCumulant2nd0005ALICE,
1738                                                           xErrCumulant2nd0005ALICE,yErrCumulant2nd0005ALICE);
1739     Cumulant2nd0005ALICE->SetMarkerStyle(kFullCircle);
1740     Cumulant2nd0005ALICE->SetMarkerColor(kBlue);
1741     
1742     return Cumulant2nd0005ALICE;
1743   }
1744   
1745   if (n == 3)
1746   {
1747   }
1748   
1749   if (n == 4)
1750   {
1751   }
1752   
1753   return 0;
1754 }
1755
1756 TGraphErrors* GetFlow510(Int_t n)
1757 {
1758   // private communication 09.03.11, Ante B. / Raimond
1759
1760   if (n == 2)
1761   {
1762     // v2{2}(pt) for 5-10%:
1763     Double_t xCumulant2nd0510ALICE[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
1764     1.050000,1.150000,1.250000,1.350000,1.450000,1.550000,1.650000,1.750000,1.850000,1.950000,
1765     2.100000,2.300000,2.500000,2.700000,2.900000,3.200000,3.600000,4.000000,4.400000,4.800000,
1766     5.500000,6.500000,7.500000,8.500000,9.500000,11.250000,13.750000,16.250000,18.750000,60.000000};
1767     Double_t yCumulant2nd0510ALICE[] = {0.000000,0.000000,0.022354,0.028064,0.034341,0.040769,0.046265,0.051160,0.056712,0.061354,
1768     0.066290,0.070340,0.074453,0.078444,0.082367,0.085785,0.088086,0.092676,0.096169,0.100366,
1769     0.104227,0.109710,0.117032,0.121784,0.122227,0.126537,0.127966,0.117790,0.117884,0.111436,
1770     0.104945,0.097640,0.086481,0.091663,0.091404,0.080132,0.015864,0.101500,0.033347,0.205130};
1771     Double_t xErrCumulant2nd0510ALICE[40] = {0.};
1772     Double_t yErrCumulant2nd0510ALICE[] = {0.000000,0.000000,0.000173,0.000176,0.000186,0.000199,0.000219,0.000236,0.000260,0.000283,
1773     0.000312,0.000340,0.000373,0.000410,0.000454,0.000501,0.000552,0.000610,0.000675,0.000753,
1774     0.000620,0.000774,0.000961,0.001183,0.001431,0.001309,0.001814,0.002481,0.003342,0.004379,
1775     0.004122,0.006716,0.009851,0.013626,0.017517,0.015790,0.025680,0.038041,0.054144,0.038987};
1776     Int_t nPointsCumulant2nd0510ALICE = sizeof(xCumulant2nd0510ALICE)/sizeof(Double_t);                                      
1777     TGraphErrors *Cumulant2nd0510ALICE = new TGraphErrors(nPointsCumulant2nd0510ALICE,xCumulant2nd0510ALICE,yCumulant2nd0510ALICE,
1778                                                           xErrCumulant2nd0510ALICE,yErrCumulant2nd0510ALICE);
1779     Cumulant2nd0510ALICE->SetMarkerStyle(kOpenCircle);
1780     Cumulant2nd0510ALICE->SetMarkerColor(kBlue);
1781     
1782     return Cumulant2nd0510ALICE;
1783   }
1784   
1785   if (n == 3)
1786   {
1787   }
1788   
1789   if (n == 4)
1790   {
1791   }
1792   
1793   return 0;
1794 }
1795
1796 TGraphErrors* GetFlow1020(Int_t n)
1797 {
1798   // private communication 09.03.11, Ante B. / Raimond
1799
1800   if (n == 2)
1801   {
1802     // v2{2}(pt) for 10-20%:
1803     Double_t xCumulant2nd1020ALICE[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
1804     1.050000,1.150000,1.250000,1.350000,1.450000,1.550000,1.650000,1.750000,1.850000,1.950000,
1805     2.100000,2.300000,2.500000,2.700000,2.900000,3.200000,3.600000,4.000000,4.400000,4.800000,
1806     5.500000,6.500000,7.500000,8.500000,9.500000,11.250000,13.750000,16.250000,18.750000,60.000000};
1807     Double_t yCumulant2nd1020ALICE[] = {0.000000,0.000000,0.028508,0.037698,0.046914,0.055750,0.063948,0.072298,0.079396,0.086829,
1808     0.093382,0.099676,0.105412,0.110792,0.116715,0.122327,0.127079,0.132302,0.137183,0.142346,
1809     0.149059,0.156729,0.164672,0.171840,0.175346,0.176824,0.178878,0.174979,0.169229,0.153109,
1810     0.139676,0.125686,0.120554,0.096537,0.084736,0.118152,0.116079,0.060032,0.093764,0.206506};
1811     Double_t xErrCumulant2nd1020ALICE[40] = {0.};
1812     Double_t yErrCumulant2nd1020ALICE[] = {0.000000,0.000000,0.000134,0.000136,0.000145,0.000158,0.000173,0.000190,0.000209,0.000229,
1813     0.000252,0.000275,0.000301,0.000331,0.000365,0.000401,0.000442,0.000488,0.000541,0.000599,
1814     0.000496,0.000614,0.000757,0.000915,0.001095,0.000989,0.001360,0.001847,0.002477,0.003234,
1815     0.003012,0.004867,0.007123,0.009774,0.012740,0.011682,0.019629,0.028568,0.039931,0.024776};
1816     Int_t nPointsCumulant2nd1020ALICE = sizeof(xCumulant2nd1020ALICE)/sizeof(Double_t);                                      
1817     TGraphErrors *Cumulant2nd1020ALICE = new TGraphErrors(nPointsCumulant2nd1020ALICE,xCumulant2nd1020ALICE,yCumulant2nd1020ALICE,
1818                                                           xErrCumulant2nd1020ALICE,yErrCumulant2nd1020ALICE);
1819     Cumulant2nd1020ALICE->SetMarkerStyle(kFullSquare);
1820     Cumulant2nd1020ALICE->SetMarkerColor(kRed); 
1821     
1822     return Cumulant2nd1020ALICE;
1823   }
1824   
1825   if (n == 3)
1826   {
1827   }
1828   
1829   if (n == 4)
1830   {
1831   }
1832   
1833   return 0;
1834 }
1835
1836 TGraphErrors* GetFlow2030(Int_t n)
1837 {
1838   // private communication 09.03.11, Ante B. / Raimond
1839
1840   if (n == 2)
1841   {
1842     // v2{2}(pt) for 20-30%:
1843     Double_t xCumulant2nd2030ALICE[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
1844     1.050000,1.150000,1.250000,1.350000,1.450000,1.550000,1.650000,1.750000,1.850000,1.950000,
1845     2.100000,2.300000,2.500000,2.700000,2.900000,3.200000,3.600000,4.000000,4.400000,4.800000,
1846     5.500000,6.500000,7.500000,8.500000,9.500000,11.250000,13.750000,16.250000,18.750000,60.000000};
1847     Double_t yCumulant2nd2030ALICE[] = {0.000000,0.000000,0.035366,0.047465,0.060083,0.072090,0.083418,0.093576,0.103842,0.113110,
1848     0.122193,0.130168,0.138158,0.145627,0.152851,0.159129,0.166073,0.173144,0.178698,0.186188,
1849     0.192045,0.202199,0.210535,0.215004,0.220457,0.223339,0.224050,0.211567,0.203955,0.189716,
1850     0.165994,0.147185,0.131953,0.139331,0.151293,0.127406,0.153764,0.089628,0.161247,0.511418};
1851     Double_t xErrCumulant2nd2030ALICE[40] = {0.};
1852     Double_t yErrCumulant2nd2030ALICE[] = {0.000000,0.000000,0.000155,0.000157,0.000169,0.000184,0.000202,0.000222,0.000244,0.000269,
1853     0.000296,0.000325,0.000357,0.000394,0.000435,0.000481,0.000532,0.000589,0.000655,0.000731,
1854     0.000605,0.000743,0.000904,0.001081,0.001277,0.001145,0.001568,0.002119,0.002806,0.003635,
1855     0.003383,0.005346,0.007935,0.010739,0.014682,0.013434,0.021531,0.032352,0.040396,0.028472};
1856     Int_t nPointsCumulant2nd2030ALICE = sizeof(xCumulant2nd2030ALICE)/sizeof(Double_t);                                      
1857     TGraphErrors *Cumulant2nd2030ALICE = new TGraphErrors(nPointsCumulant2nd2030ALICE,xCumulant2nd2030ALICE,yCumulant2nd2030ALICE,
1858                                                           xErrCumulant2nd2030ALICE,yErrCumulant2nd2030ALICE);
1859     Cumulant2nd2030ALICE->SetMarkerStyle(kOpenSquare);
1860     Cumulant2nd2030ALICE->SetMarkerColor(kRed); 
1861     
1862     return Cumulant2nd2030ALICE;
1863   }
1864   
1865   if (n == 3)
1866   {
1867   }
1868   
1869   if (n == 4)
1870   {
1871   }
1872   
1873   return 0;
1874 }
1875
1876 TGraphErrors* GetFlow3040(Int_t n)
1877 {
1878   // private communication 09.03.11, Ante B. / Raimond
1879
1880   if (n == 2)
1881   {
1882     // v2{2}(pt) for 30-40%:
1883     Double_t xCumulant2nd3040ALICE[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
1884     1.050000,1.150000,1.250000,1.350000,1.450000,1.550000,1.650000,1.750000,1.850000,1.950000,
1885     2.100000,2.300000,2.500000,2.700000,2.900000,3.200000,3.600000,4.000000,4.400000,4.800000,
1886     5.500000,6.500000,7.500000,8.500000,9.500000,11.250000,13.750000,16.250000,18.750000,60.000000};
1887     Double_t yCumulant2nd3040ALICE[] = {0.000000,0.000000,0.039584,0.054196,0.069291,0.082976,0.095622,0.108940,0.119830,0.131587,
1888     0.141091,0.150899,0.160573,0.168676,0.176301,0.183823,0.191672,0.199506,0.206854,0.212830,
1889     0.219526,0.229376,0.236513,0.240863,0.245961,0.245891,0.242608,0.234302,0.219580,0.212848,
1890     0.194666,0.190184,0.171036,0.159173,0.156932,0.141324,0.132809,0.182683,0.023272,0.032825};
1891     Double_t xErrCumulant2nd3040ALICE[40] = {0.};
1892     Double_t yErrCumulant2nd3040ALICE[] = {0.000000,0.000000,0.000189,0.000192,0.000205,0.000224,0.000247,0.000273,0.000302,0.000334,
1893     0.000369,0.000407,0.000448,0.000496,0.000552,0.000612,0.000682,0.000758,0.000844,0.000941,
1894     0.000774,0.000937,0.001123,0.001329,0.001565,0.001397,0.001911,0.002549,0.003378,0.004306,
1895     0.003987,0.006353,0.009128,0.013032,0.016891,0.015806,0.025150,0.035119,0.044487,0.050083};
1896     Int_t nPointsCumulant2nd3040ALICE = sizeof(xCumulant2nd3040ALICE)/sizeof(Double_t);                                      
1897     TGraphErrors *Cumulant2nd3040ALICE = new TGraphErrors(nPointsCumulant2nd3040ALICE,xCumulant2nd3040ALICE,yCumulant2nd3040ALICE,
1898                                                           xErrCumulant2nd3040ALICE,yErrCumulant2nd3040ALICE);
1899     Cumulant2nd3040ALICE->SetMarkerStyle(kFullTriangleUp);
1900     Cumulant2nd3040ALICE->SetMarkerColor(kGreen+2);
1901     
1902     return Cumulant2nd3040ALICE;
1903   }
1904   
1905   if (n == 3)
1906   {
1907   }
1908   
1909   if (n == 4)
1910   {
1911   }
1912   
1913   return 0;
1914 }
1915
1916 TGraphErrors* GetFlow4050(Int_t n)
1917 {
1918   // private communication 09.03.11, Ante B. / Raimond
1919
1920   if (n == 2)
1921   {
1922     // v2{2}(pt) for 40-50%:
1923     Double_t xCumulant2nd4050ALICE[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
1924     1.050000,1.150000,1.250000,1.350000,1.450000,1.550000,1.650000,1.750000,1.850000,1.950000,
1925     2.100000,2.300000,2.500000,2.700000,2.900000,3.200000,3.600000,4.000000,4.400000,4.800000,
1926     5.500000,6.500000,7.500000,8.500000,9.500000,11.250000,13.750000,16.250000,18.750000,60.000000};
1927     Double_t yCumulant2nd4050ALICE[] = {0.000000,0.000000,0.041872,0.058090,0.074444,0.089181,0.103780,0.117279,0.129769,0.142051,
1928     0.153185,0.163147,0.173309,0.181668,0.190998,0.197703,0.205011,0.211063,0.219587,0.223287,
1929     0.231163,0.239606,0.246533,0.251457,0.250034,0.252989,0.240823,0.236489,0.230268,0.204321,
1930     0.213476,0.200247,0.167065,0.190655,0.173573,0.166173,0.153232,0.173112,-0.123540,0.211999};
1931     Double_t xErrCumulant2nd4050ALICE[40] = {0.};
1932     Double_t yErrCumulant2nd4050ALICE[] = {0.000000,0.000000,0.000248,0.000251,0.000270,0.000296,0.000328,0.000363,0.000403,0.000447,
1933     0.000500,0.000556,0.000617,0.000687,0.000770,0.000857,0.000952,0.001057,0.001176,0.001297,
1934     0.001054,0.001265,0.001498,0.001767,0.002076,0.001849,0.002527,0.003358,0.004372,0.005573,
1935     0.005091,0.007981,0.011746,0.015732,0.021883,0.019866,0.032443,0.046521,0.051631,0.083717};
1936     Int_t nPointsCumulant2nd4050ALICE = sizeof(xCumulant2nd4050ALICE)/sizeof(Double_t);                                      
1937     TGraphErrors *Cumulant2nd4050ALICE = new TGraphErrors(nPointsCumulant2nd4050ALICE,xCumulant2nd4050ALICE,yCumulant2nd4050ALICE,
1938                                                           xErrCumulant2nd4050ALICE,yErrCumulant2nd4050ALICE);
1939     Cumulant2nd4050ALICE->SetMarkerStyle(kOpenTriangleUp);
1940     Cumulant2nd4050ALICE->SetMarkerColor(kGreen+2);
1941     
1942     return Cumulant2nd4050ALICE;
1943   }
1944   
1945   return 0;
1946 }
1947
1948
1949 Float_t CalculateFlow(TH1* ptDist, Float_t ptMin, Float_t ptMax, Int_t n, Int_t centralityBegin, Int_t centralityEnd)
1950 {
1951   if (centralityBegin == 0 && centralityEnd == 2)
1952     flow = GetFlow02(n);
1953   else if (centralityBegin == 0 && centralityEnd == 5)
1954     flow = GetFlow05(n);
1955   else if (centralityBegin == 5 && centralityEnd == 10)
1956     flow = GetFlow510(n);
1957   else if (centralityBegin == 20 && centralityEnd == 30)
1958     flow = GetFlow2030(n);
1959   else if (centralityBegin == 30 && centralityEnd == 40)
1960     flow = GetFlow3040(n);
1961   else if (centralityBegin == 40 && centralityEnd == 50)
1962     flow = GetFlow4050(n);
1963   else if (centralityBegin > 50)
1964     flow = GetFlow4050(n);
1965   else if (centralityBegin == 0 && centralityEnd == 20)
1966   {
1967     flow = GetFlow05(n);
1968     flow2 = GetFlow510(n);
1969     flow3 = GetFlow1020(n);
1970     
1971     // centrality width * dn/deta from http://arxiv.org/PS_cache/arxiv/pdf/1012/1012.1657v2.pdf
1972     Float_t mult[] = { 5 * 1601, 5 * 1294, 10 * 966 };
1973     
1974     if (flow->GetN() != flow2->GetN() || flow2->GetN() != flow3->GetN())
1975       AliFatal("Incompatible graphs");
1976     
1977     for (Int_t i=0; i<flow->GetN(); i++)
1978     {
1979 //       Printf("%f %f %f", flow->GetY()[i], flow2->GetY()[i], flow3->GetY()[i]);
1980       flow->GetY()[i] = flow->GetY()[i] * mult[0] + flow2->GetY()[i] * mult[1] + flow3->GetY()[i] * mult[2];
1981       flow->GetY()[i] /= mult[0] + mult[1] + mult[2];
1982 //       Printf(" --> %f", flow->GetY()[i]);
1983     }
1984   }
1985   else if (centralityBegin == 20 && centralityEnd == 60)
1986   {
1987     flow = GetFlow2030(n);
1988     flow2 = GetFlow3040(n);
1989     flow3 = GetFlow4050(n);
1990     
1991     // centrality width * dn/deta from http://arxiv.org/PS_cache/arxiv/pdf/1012/1012.1657v2.pdf
1992     Float_t mult[] = { 10 * 649, 10 * 426, 10 * (261+149) };
1993     
1994     if (flow->GetN() != flow2->GetN() || flow2->GetN() != flow3->GetN())
1995       AliFatal("Incompatible graphs");
1996     
1997     for (Int_t i=0; i<flow->GetN(); i++)
1998     {
1999 //       Printf("%f %f %f", flow->GetY()[i], flow2->GetY()[i], flow3->GetY()[i]);
2000       flow->GetY()[i] = flow->GetY()[i] * mult[0] + flow2->GetY()[i] * mult[1] + flow3->GetY()[i] * mult[2];
2001       flow->GetY()[i] /= mult[0] + mult[1] + mult[2];
2002 //       Printf(" --> %f", flow->GetY()[i]);
2003     }
2004   }
2005   else
2006   {
2007     Printf("Flow range %d %d not available", centralityBegin, centralityEnd);
2008     AliFatal("");
2009   }
2010
2011   Float_t vn = 0;
2012   Float_t sum = 0;
2013   for (Int_t bin = ptDist->FindBin(ptMin + 0.01); bin <= ptDist->FindBin(ptMax - 0.01); bin++)
2014   {
2015     if (ptDist->GetBinCenter(bin) > flow->GetX()[flow->GetN()-1])
2016       vn += ptDist->GetBinContent(bin) * flow->GetY()[flow->GetN()-1];
2017     else
2018       vn += ptDist->GetBinContent(bin) * flow->Eval(ptDist->GetBinCenter(bin));
2019     sum += ptDist->GetBinContent(bin);
2020   }
2021   
2022   vn /= sum;
2023   
2024   Printf("v_{%d} = %f for %f < pT < %f", n, vn, ptMin, ptMax);
2025   
2026   return vn;
2027 }
2028
2029 void CalculateFlow(const char* fileName, Int_t centralityBegin, Int_t centralityEnd)
2030 {
2031   Float_t ptTrigMin = 2;
2032   Float_t ptTrigMax = 3;
2033   
2034   Float_t ptMin = 1;
2035   Float_t ptMax = 2;
2036
2037   loadlibs();
2038
2039   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
2040   
2041   cont = h->GetUEHist(2)->GetTrackHist(0);
2042   cont->GetGrid(6)->GetGrid()->GetAxis(3)->SetRangeUser(0.01 + centralityBegin, -0.01 + centralityEnd);
2043   cont->GetGrid(6)->GetGrid()->GetAxis(2)->SetRangeUser(ptTrigMin + 0.01, ptTrigMax - 0.01);
2044   
2045   ptDist = cont->ShowProjection(1, 6);
2046   ptDist->Scale(1.0 / ptDist->Integral());
2047   
2048   cont = h->GetUEHist(2)->GetEventHist();
2049   cont->GetGrid(6)->GetGrid()->GetAxis(1)->SetRangeUser(0.01 + centralityBegin, -0.01 + centralityEnd);
2050   
2051   ptDist2 = cont->ShowProjection(0, 6);
2052   ptDist2->Scale(1.0 / ptDist2->Integral());
2053   
2054   TString str;
2055   
2056   for (Int_t n=2; n<=4; n++)
2057   {
2058     Float_t v2A = CalculateFlow(ptDist, ptMin, ptMax, n, centralityBegin, centralityEnd);
2059     Float_t v2T = CalculateFlow(ptDist2, ptTrigMin, ptTrigMax, n, centralityBegin, centralityEnd);
2060     
2061     str += Form("%f * %f, ", v2A, v2T);
2062   }
2063   
2064   ptDist->Draw();
2065   ptDist2->SetLineColor(2);
2066   ptDist2->Draw("SAME");
2067   
2068   Printf("%s", str.Data());
2069 }
2070
2071 // four dimensions for: nearside/awayside/normalization unc, trigger, centrality, case (same, same/mixed, same w/ v2 subtraction, same/mixed w/ v2 subtraction, some more cases...)
2072 TGraphErrors***** yields = 0;
2073 TString currentYieldFile;
2074
2075 void WriteYields()
2076 {
2077   TFile::Open("yields.root", "RECREATE");
2078   for (Int_t i=0; i<3; i++)
2079   {
2080     for (Int_t j=0; j<6; j++)
2081     {
2082       for (Int_t k=0; k<4; k++)
2083       {
2084         // CINT limitation here
2085         TGraphErrors** tmp = yields[i][j][k];
2086         for (Int_t l=0; l<31; l++)
2087         {
2088           //Printf("%d %d %d %d", i, j, k, l);
2089           tmp[l]->Write(Form("yield_%d_%d_%d_%d", i, j, k, l));
2090         }
2091       }
2092     }
2093   }
2094   gFile->Close();
2095 }
2096
2097 void ReadYields(const char* fileName = "yields.root")
2098 {
2099   if (currentYieldFile == fileName)
2100     return;
2101     
2102   currentYieldFile = fileName;
2103
2104   CreateYieldStructure();
2105   TFile::Open(fileName);
2106   for (Int_t i=0; i<3; i++)
2107   {
2108     for (Int_t j=0; j<6; j++)
2109     {
2110       for (Int_t k=0; k<4; k++)
2111       {
2112         // CINT limitation here
2113         TGraphErrors** tmp = yields[i][j][k];
2114         for (Int_t l=0; l<31; l++)
2115         {
2116           //Printf("%d %d %d %d", i, j, k, l);
2117           tmp[l] = gFile->Get(Form("yield_%d_%d_%d_%d", i, j, k, l));
2118         }
2119       }
2120     }
2121   }
2122 }
2123
2124 void CreateYieldStructure()
2125 {
2126   if (!yields)
2127   {
2128     yields = new TGraphErrors****[3];
2129     for (Int_t i=0; i<3; i++)
2130     {
2131       yields[i] = new TGraphErrors***[6];
2132       for (Int_t j=0; j<6; j++)
2133       {
2134         yields[i][j] = new TGraphErrors**[4];
2135         for (Int_t k=0; k<4; k++)
2136         {
2137           yields[i][j][k] = new TGraphErrors*[31];
2138           // CINT limitation here
2139           TGraphErrors** tmp = yields[i][j][k];
2140           for (Int_t l=0; l<31; l++)
2141           {
2142             //Printf("%d %d %d %d", i, j, k, l);
2143             TGraphErrors* graph = new TGraphErrors;
2144             tmp[l] = graph;
2145           }
2146         }
2147       }
2148     }
2149   }
2150 }
2151
2152 void GraphShiftX(TGraphErrors* graph, Float_t offset)
2153 {
2154   for (Int_t i=0; i<graph->GetN(); i++)
2155     graph->GetX()[i] += offset;
2156 }
2157
2158 const Float_t kPythiaScalingFactor = 0.935;
2159
2160 void DrawYields(const char* fileName = "yields.root")
2161 {
2162   ReadYields(fileName);
2163   
2164   c = new TCanvas("c", "c", 1800, 1200);
2165   c->Divide(6, 4);
2166   
2167   Int_t markers1[] = { 24, 25, 26, 30 };
2168   Int_t markers2[] = { 20, 21, 22, 29 };
2169   Int_t colors[] = { 1, 2, 3, 4 };
2170   //Int_t caseList[] = { 0, 10+1, 10+1, 8, 10, 11, 12, 13, 1, 9 };
2171   Int_t caseList[] = { 0, 18, 18, 23, 18, 19, 20, 21, 22, 9 };
2172   const char* caseString[] = { "", "baseline sub", "baseline vs v2 sub comp", 0, "baseline sub comp", "Same/Mixed", "Same/Mixed - v2 subtr" };
2173   
2174   Bool_t iaa = kTRUE;
2175   if (!iaa)
2176   {
2177     Int_t centralityList[] =  {  0,  1,  2, 0, 0, 1 };
2178     Int_t centralityList2[] = { -1, -1, -1, 1, 2, 2 };
2179     Float_t factors[]       = {  1,  1,  1, 1, 1, 1 };
2180     const char* centralityString[] = { "0-5%", "20-40%", "60-90%", "0-5% vs 20-40%", "0-5% vs 60-90%", "20-40% vs 60-90%" };
2181   }
2182   else
2183   {
2184     Int_t centralityList[] =  {  0,  2,  3, 0, 0, 2 };
2185     Int_t centralityList2[] = { -1, -1, -1, 2, 3, 3 };
2186     //Float_t factors[]       = {  1,  1,  1, 1, 1.0/0.9, 1.0/0.9 };
2187     //Float_t factors[]       = {  1,  1,  1, 1, 1.0/0.804, 1.0/0.804 };
2188     Float_t factors[]       = {  1,  1,  1, 1, 1.0/kPythiaScalingFactor, 1.0/kPythiaScalingFactor };
2189     //Float_t factors[]       = {  1,  1,  1, 1, 1.0, 1.0 };
2190     const char* centralityString[] = { "0-5%", "60-90%", "pp", "0-5% vs 60-90%", "0-5% vs pp", "60-90% vs pp" };
2191   }
2192   
2193   l = new TLegend(0.5, 0.5, 0.9, 0.9);
2194   l->SetFillColor(0);
2195   
2196   Float_t max[] = { 0.4, 2, 2, 2, 2, 10, 10 };
2197   Float_t max2[] = { 5, 2, 2, 2, 2, 2, 2, 2, 2 };
2198   
2199   dummy = new TH2F("dummy", ";p_{T,assoc};yield", 100, 0, 20, 20000, 0, 10);
2200   dummy->SetStats(0);
2201   
2202   TGraphErrors* prevNear[6];
2203   TGraphErrors* prevAway[6];
2204   for (Int_t caseId=0; caseId<9; caseId++) // case 0->9
2205   {
2206     for (Int_t k=0; k<6; k++) // centrality
2207     {
2208       if (caseId != 3 && caseId < 5)
2209       {
2210         if (caseId < 4)
2211           c->cd(1 + k + caseId*6);
2212         else
2213           c->cd(1 + k + (caseId-1)*6);
2214         currentDummy = dummy->DrawCopy();
2215         currentDummy->GetYaxis()->SetRangeUser(0, max[caseId]);
2216         gPad->SetGridx();
2217         gPad->SetGridy();
2218         
2219         latex = new TLatex(0.15, 0.95, Form("%s - %s", caseString[caseId], centralityString[k]));
2220         latex->SetNDC();
2221         latex->SetTextSize(0.05);
2222         latex->Draw();
2223       }
2224       else if (caseId == 3)
2225         c->cd(1 + k + 2*6);
2226       else
2227         c->cd(1 + k + 3*6);
2228       
2229       for (Int_t j=0; j<3; j++) // trigger pt
2230       {
2231         if (caseId >= 2 && j != 1)
2232           continue;
2233         Printf("%d %d %d %d", caseId, k, j, caseList[caseId]);
2234       
2235         if (k < 3)
2236         {
2237           // CINT limitation here
2238           TGraphErrors** tmp = yields[0][j][centralityList[k]];
2239           nearSide = tmp[caseList[caseId]];
2240           //new TCanvas; nearSide->Draw("AP"); return;
2241           
2242           nearSide->SetMarkerStyle(markers1[j]);
2243           nearSide->SetMarkerColor(colors[j]);
2244           nearSide->SetLineColor(colors[j]);
2245           
2246           if (caseId == 0 && k == 0)
2247             l->AddEntry(nearSide, Form("trig pt bin %d", j), "P");
2248             
2249           TGraphErrors** tmp = yields[1][j][centralityList[k]];
2250           awaySide = tmp[caseList[caseId]];
2251           awaySide->SetMarkerStyle(markers2[j]);
2252           awaySide->SetMarkerColor(colors[j]);
2253           awaySide->SetLineColor(colors[j]);
2254             
2255           GraphShiftX(nearSide, -0.1 + j*0.1);
2256           GraphShiftX(awaySide, -0.1 + j*0.1);
2257           
2258           if (caseId == 3)
2259           {
2260             nearSide->SetLineColor(caseId - 2);
2261             nearSide->SetMarkerColor(caseId - 2);
2262             awaySide->SetLineColor(caseId - 2);
2263             awaySide->SetMarkerColor(caseId - 2);
2264           }
2265           
2266           if (caseId >= 4)
2267           {
2268             nearSide->SetLineColor(caseId - 3);
2269             nearSide->SetMarkerColor(caseId - 3);
2270             awaySide->SetLineColor(caseId - 3);
2271             awaySide->SetMarkerColor(caseId - 3);
2272           }
2273           
2274           nearSide->Print();
2275           
2276           prevNear[k] = (TGraphErrors*) nearSide->DrawClone("PSAME");
2277           prevAway[k] = (TGraphErrors*) awaySide->DrawClone("PSAME");
2278           
2279           if (caseId == 4)
2280           {
2281             Printf("%d", k);
2282             for (Int_t i=0; i<nearSide->GetN(); i++)
2283             {
2284               Printf("%f: %.0f%%", nearSide->GetX()[i], 100.0 * nearSide->GetEY()[i] / nearSide->GetY()[i]);
2285               Printf("%f: %.0f%%", awaySide->GetX()[i], 100.0 * awaySide->GetEY()[i] / awaySide->GetY()[i]);
2286             }
2287           }
2288         }
2289         else
2290         {
2291           // CINT limitation here
2292           tmp = yields[0][j][centralityList[k]]; nearSideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
2293           tmp = yields[1][j][centralityList[k]]; awaySideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
2294           
2295           tmp = yields[0][j][centralityList2[k]]; 
2296           nearSidePeripheral = tmp[caseList[caseId]];
2297           if (iaa && caseId == 3 && k >= 4)
2298             nearSidePeripheral = tmp[caseList[caseId-1]];
2299           
2300           tmp = yields[1][j][centralityList2[k]]; 
2301           awaySidePeripheral = tmp[caseList[caseId]];
2302           if (iaa && caseId == 3 && k >= 4)
2303             awaySidePeripheral = tmp[caseList[caseId-1]];
2304             
2305 //           nearSideCentral->Print();
2306 //           nearSidePeripheral->Print();
2307           
2308           if (k == 3)
2309             currentDummy->GetYaxis()->SetTitle("I_{CP}");
2310           else
2311             currentDummy->GetYaxis()->SetTitle("I_{AA}");
2312           currentDummy->GetYaxis()->SetRangeUser(0, max2[caseId]);
2313           
2314           for (Int_t i=0; i<nearSideCentral->GetN(); i++)
2315           {
2316             if (i >= nearSidePeripheral->GetN())
2317             {
2318               nearSideCentral->RemovePoint(i);
2319               i--;
2320               continue;
2321             }
2322           
2323             //Printf("near %d %f %f", i, nearSideCentral->GetY()[i], nearSidePeripheral->GetY()[i]);
2324             if (nearSidePeripheral->GetY()[i] <= 1e-5 || nearSideCentral->GetY()[i] <= 1e-5)
2325             {
2326               nearSideCentral->RemovePoint(i);
2327               nearSidePeripheral->RemovePoint(i);
2328               i--;
2329               continue;
2330             }
2331           
2332             nearSideCentral->GetEY()[i] = TMath::Sqrt(
2333               TMath::Power(nearSideCentral->GetEY()[i] / nearSideCentral->GetY()[i], 2) + 
2334               TMath::Power(nearSidePeripheral->GetEY()[i] / nearSidePeripheral->GetY()[i], 2) );
2335               
2336             nearSideCentral->GetY()[i] /= nearSidePeripheral->GetY()[i];
2337             nearSideCentral->GetY()[i] *= factors[k];
2338             
2339             nearSideCentral->GetEY()[i] *= nearSideCentral->GetY()[i];
2340           }
2341           //Printf("done");
2342           
2343           for (Int_t i=0; i<awaySideCentral->GetN(); i++)
2344           {
2345             if (i >= awaySidePeripheral->GetN())
2346             {
2347               awaySideCentral->RemovePoint(i);
2348               i--;
2349               continue;
2350             }
2351             
2352             //Printf("away %d", i);
2353             if (awaySidePeripheral->GetY()[i] <= 1e-5 || awaySideCentral->GetY()[i] <= 1e-5)
2354             {
2355               awaySideCentral->RemovePoint(i);
2356               awaySidePeripheral->RemovePoint(i);
2357               i--;
2358               continue;
2359             }
2360             
2361             awaySideCentral->GetEY()[i] = TMath::Sqrt(
2362               TMath::Power(awaySideCentral->GetEY()[i] / awaySideCentral->GetY()[i], 2) + 
2363               TMath::Power(awaySidePeripheral->GetEY()[i] / awaySidePeripheral->GetY()[i], 2) );
2364             
2365             awaySideCentral->GetY()[i] /= awaySidePeripheral->GetY()[i];
2366             awaySideCentral->GetY()[i] *= factors[k];
2367           
2368             awaySideCentral->GetEY()[i] *= awaySideCentral->GetY()[i];
2369           }
2370           
2371           if (caseId == 3)
2372           {
2373             nearSideCentral = (TGraphErrors*) nearSideCentral->Clone();
2374             nearSideCentral->SetLineColor(1);
2375             nearSideCentral->SetMarkerColor(1);
2376           
2377             awaySideCentral = (TGraphErrors*) awaySideCentral->Clone();
2378             awaySideCentral->SetLineColor(1);
2379             awaySideCentral->SetMarkerColor(1);
2380           }
2381           
2382           if (caseId >= 4)
2383           {
2384             nearSideCentral = (TGraphErrors*) nearSideCentral->Clone();
2385             nearSideCentral->SetLineColor(caseId - 3);
2386             nearSideCentral->SetMarkerColor(caseId - 3);
2387           
2388             awaySideCentral = (TGraphErrors*) awaySideCentral->Clone();
2389             awaySideCentral->SetLineColor(caseId - 3);
2390             awaySideCentral->SetMarkerColor(caseId - 3);
2391           }
2392           
2393           //Printf("%d", caseList[caseId]);
2394           
2395 //           nearSideCentral->Print();
2396           
2397           nearSideCentral->Draw("PSAME");
2398           awaySideCentral->Draw("PSAME");
2399         
2400           if (caseId == 3)
2401           {
2402             for (Int_t i=0; i<nearSideCentral->GetN(); i++)
2403               Printf("Near, bin %d pt = %f, difference %.1f%%", i, nearSideCentral->GetX()[i], 100.0 - 100.0 * nearSideCentral->GetY()[i] / prevNear[k]->Eval(nearSideCentral->GetX()[i]));
2404             for (Int_t i=0; i<awaySideCentral->GetN(); i++)
2405               Printf("Away, bin %d pt = %f, difference %.1f%%", i, awaySideCentral->GetX()[i], 100.0 - 100.0 * awaySideCentral->GetY()[i] / prevAway[k]->Eval(awaySideCentral->GetX()[i]));
2406           }
2407         
2408           prevNear[k] = nearSideCentral;
2409           prevAway[k] = awaySideCentral;
2410         }
2411       }
2412       if (caseId == 0 && k == 0)
2413         l->Draw();
2414     }
2415   }
2416   
2417   c->SaveAs("yields.png");
2418 }
2419
2420 void FitGaussians(const char* fileName, Bool_t flat)
2421 {
2422   CreateYieldStructure();
2423
2424   aliceFile = TFile::Open(fileName);
2425
2426   Int_t maxLeadingPt = 3;
2427   Int_t maxAssocPt = 6;
2428   
2429   TCanvas* canvas = new TCanvas("FitGaussians", "FitGaussians", 1000, 700);
2430   canvas->Divide(maxAssocPt, maxLeadingPt);
2431   
2432   for (Int_t i=0; i<maxLeadingPt; i++)
2433     for (Int_t j=0; j<maxAssocPt; j++)
2434     {
2435       TH1* first = 0;
2436       for (Int_t aliceCentrality=0; aliceCentrality<4; aliceCentrality++)
2437       {
2438         Printf("%d %d %d", i, j, aliceCentrality);
2439         
2440         canvas->cd(j+1 + (i) * maxAssocPt);
2441         gPad->SetLeftMargin(0.15);
2442         gPad->SetBottomMargin(0.2);
2443         //gPad->SetTopMargin(0.01);
2444         gPad->SetRightMargin(0.01);
2445         
2446         hist = (TH1*) aliceFile->Get(Form("dphi_%d_%d_%d%s", i, j, aliceCentrality, (flat) ? "_fit_flat" : ""));
2447         if (!hist)
2448           continue;
2449         
2450         // two Gauss fits
2451         gausFit = new TF1("gausFit", "[0] + gaus(1) + gaus(4)", -0.5 * TMath::Pi(), 1.5 * TMath::Pi());
2452         gausFit->SetParameters(0, 1, 0, 1, 1, TMath::Pi(), 1);
2453         gausFit->SetParLimits(0, -1, 10000);
2454         gausFit->SetParLimits(1, 0.001, 10000);
2455         gausFit->FixParameter(2, 0);
2456         gausFit->SetParLimits(3, 0.05, 10);
2457         gausFit->SetParLimits(4, 0.001, 10000);
2458         gausFit->FixParameter(5, TMath::Pi());
2459         gausFit->SetParLimits(6, 0.1, 10);
2460         
2461         gausFit->SetLineWidth(1);
2462         gausFit->SetLineColor(hist->GetLineColor());
2463         
2464         hist->Fit(gausFit, "0RIQ");
2465         gausFit->FixParameter(0, gausFit->GetParameter(0));
2466         hist->Fit(gausFit, "RI", (aliceCentrality == 0) ? "" : "SAME");
2467         //gausFit->DrawCopy("SAME");
2468         
2469         // get pT,assoc
2470         TPRegexp reg("(\\d+\\.\\d+) \\< p_\\{T,assoc\\} \\< (\\d+\\.\\d+)");
2471         arr = reg.MatchS(hist->GetTitle(), "", 0, 10);
2472         if (arr->GetEntries() != 3)
2473           continue;
2474           
2475         Float_t pt1 = atof(arr->At(1)->GetName());
2476         Float_t pt2 = atof(arr->At(2)->GetName());
2477
2478         FillYield(i, aliceCentrality, (pt1 + pt2) / 2, (pt2 - pt1) / 2, 18, gausFit->GetParameter(3), gausFit->GetParError(3), gausFit->GetParameter(6), gausFit->GetParError(6));
2479         
2480         if (!first)
2481           first = hist;
2482         else
2483           first->GetYaxis()->SetRangeUser(TMath::Min(first->GetMinimum(), hist->GetMinimum()), TMath::Max(first->GetMaximum(), hist->GetMaximum()));
2484       }
2485       first->GetYaxis()->SetRangeUser(first->GetMinimum(), 2 * first->GetMaximum());
2486         
2487 //        break;
2488     }
2489     
2490     
2491   // draw
2492   
2493   for (Int_t j=0; j<3; j++)
2494   {
2495     new TCanvas;
2496     
2497     Int_t markers1[] = { 24, 25, 26, 30 };
2498     Int_t markers2[] = { 20, 21, 22, 29 };
2499     Int_t colors[] = { 1, 2, 3, 4 };
2500     
2501     dummy = new TH2F("dummy", ";p_{T,assoc};", 100, 0, 10, 1000, 0, 1);
2502     dummy->SetStats(0);
2503     dummy->Draw();
2504     
2505     for (Int_t k=0; k<4; k++) // centrality
2506     {
2507       // CINT limitation here
2508       TGraphErrors** tmp = yields[0][j][k];
2509       nearSide = tmp[18];
2510       nearSide->SetMarkerStyle(markers1[k]);
2511       nearSide->SetMarkerColor(colors[k]);
2512       nearSide->SetLineColor(colors[k]);  
2513     
2514       TGraphErrors** tmp = yields[1][j][k];
2515       awaySide = tmp[18];
2516       awaySide->SetMarkerStyle(markers2[k]);
2517       awaySide->SetMarkerColor(colors[k]);
2518       awaySide->SetLineColor(colors[k]);  
2519       
2520       nearSide->DrawClone("PSAME");
2521       awaySide->DrawClone("PSAME");
2522     }
2523   }
2524 }
2525
2526 void TsallisExamples()
2527 {
2528   tsallis = new TF1("tsallis", "[0] * (1-[2]*(1-[1])*x*x)**(1/(1-[1]))", -0.5 * TMath::Pi(), 1.5 * TMath::Pi());
2529   
2530   Float_t q[] = { 1.0000001, 1.5, 2 };
2531   Float_t beta[] = { 0.1, 1, 10, 100 };
2532   
2533   dummy = new TH2F("dummy", "", 100, -0.5 * TMath::Pi(), 1.5 * TMath::Pi(), 100, 0, 1.2);
2534   dummy->SetStats(0);
2535   dummy->Draw();
2536   
2537   legend = new TLegend(0.65, 0.5, 1, 1);
2538   legend->SetFillColor(0);
2539   
2540   for (Int_t i=0; i<3; i++)
2541     for (Int_t j=0; j<4; j++)
2542     {
2543       tsallis->SetParameters(1, q[i], beta[j]);
2544       tsallis->SetLineColor(i+1);
2545       tsallis->SetLineStyle(j+1);
2546       
2547       legend->AddEntry(tsallis->DrawCopy("SAME"), Form("q = %.1f, #beta = %.1f", q[i], beta[j]), "L");
2548     }
2549     
2550   legend->Draw();
2551 }
2552
2553 void DrawTsallisParams()
2554 {
2555   ReadYields();
2556   
2557   c = new TCanvas("c", "c", 900, 600);
2558   c->Divide(3, 2);
2559   
2560   Int_t markers1[] = { 24, 25, 26, 30 };
2561   Int_t markers2[] = { 20, 21, 22, 29 };
2562   Int_t colors[] = { 1, 2, 3, 4 };
2563   Int_t caseList[] = { 12, 13, 8, 6, 8, 9, 10, 11, 1, 7 };
2564   const char* caseString[] = { "q", "beta" };
2565   const char* centralityString[] = { "0-5%", "20-40%", "60-90%", "0-5% vs 20-40%", "0-5% vs 60-90%", "20-40% vs 60-90%" };
2566   
2567   l = new TLegend(0.5, 0.5, 0.9, 0.9);
2568   l->SetFillColor(0);
2569   
2570   Float_t max[] = { 3, 1000 };
2571   Float_t max2[] = { 5, 2 };
2572   
2573   dummy = new TH2F("dummy", ";p_{T,assoc};", 100, 0, 20, 1000, 0, 1000);
2574   dummy->SetStats(0);
2575   
2576   for (Int_t caseId=0; caseId<2; caseId++) // case
2577   {
2578     for (Int_t k=0; k<3; k++) // centrality
2579     {
2580       c->cd(1 + k + caseId*3);
2581         
2582       currentDummy = dummy->DrawCopy();
2583       currentDummy->GetYaxis()->SetRangeUser(0, max[caseId]);
2584       if (caseId == 1 && k < 3)
2585         gPad->SetLogy();
2586       
2587       latex = new TLatex(0.15, 0.95, Form("%s - %s", caseString[caseId], centralityString[k]));
2588       latex->SetNDC();
2589       latex->SetTextSize(0.05);
2590       latex->Draw();
2591       
2592       for (Int_t j=0; j<2; j++) // trigger pt
2593       {
2594         if (k < 3)
2595         {
2596           // CINT limitation here
2597           TGraphErrors** tmp = yields[0][j][k];
2598           nearSide = tmp[caseList[caseId]];
2599           nearSide->SetMarkerStyle(markers1[j]);
2600           nearSide->SetMarkerColor(colors[j]);
2601           nearSide->SetLineColor(colors[j]);
2602           
2603           if (caseId == 0 && k == 0)
2604             l->AddEntry(nearSide, Form("trig pt bin %d", j), "P");
2605             
2606           TGraphErrors** tmp = yields[1][j][k];
2607           awaySide = tmp[caseList[caseId]];
2608           awaySide->SetMarkerStyle(markers2[j]);
2609           awaySide->SetMarkerColor(colors[j]);
2610           awaySide->SetLineColor(colors[j]);
2611             
2612           GraphShiftX(nearSide, -0.1 + j*0.1);
2613           GraphShiftX(awaySide, -0.1 + j*0.1);
2614           
2615           Printf("%d %d %d", caseId, j, k);
2616           nearSide->Print();
2617           awaySide->Print();
2618           
2619           nearSide->DrawClone("PSAME");
2620           awaySide->DrawClone("PSAME");
2621         }
2622         else
2623         {
2624           // CINT limitation here
2625           if (k == 3)
2626           {
2627             tmp = yields[0][j][0]; nearSideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
2628             tmp = yields[1][j][0]; awaySideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
2629             tmp = yields[0][j][1]; nearSidePeripheral = tmp[caseList[caseId]];
2630             tmp = yields[1][j][1]; awaySidePeripheral = tmp[caseList[caseId]];
2631           }
2632           else if (k == 4)
2633           {
2634             tmp = yields[0][j][0]; nearSideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
2635             tmp = yields[1][j][0]; awaySideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
2636             tmp = yields[0][j][2]; nearSidePeripheral = tmp[caseList[caseId]];
2637             tmp = yields[1][j][2]; awaySidePeripheral = tmp[caseList[caseId]];
2638           }
2639           else if (k == 5)
2640           {
2641             tmp = yields[0][j][1]; nearSideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
2642             tmp = yields[1][j][1]; awaySideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
2643             tmp = yields[0][j][2]; nearSidePeripheral = tmp[caseList[caseId]];
2644             tmp = yields[1][j][2]; awaySidePeripheral = tmp[caseList[caseId]];
2645           }
2646           
2647           currentDummy->GetYaxis()->SetTitle("I_{CP}");
2648           currentDummy->GetYaxis()->SetRangeUser(0, max2[caseId]);
2649         
2650           for (Int_t i=0; i<nearSideCentral->GetN(); i++)
2651           {
2652             //Printf("near %d %f %f", i, nearSideCentral->GetY()[i], nearSidePeripheral->GetY()[i]);
2653             if (nearSidePeripheral->GetY()[i] <= 1e-5 || nearSideCentral->GetY()[i] <= 1e-5)
2654             {
2655               nearSideCentral->RemovePoint(i);
2656               nearSidePeripheral->RemovePoint(i);
2657               i--;
2658               continue;
2659             }
2660           
2661             nearSideCentral->GetEY()[i] = TMath::Sqrt(
2662               TMath::Power(nearSideCentral->GetEY()[i] / nearSideCentral->GetY()[i], 2) + 
2663               TMath::Power(nearSidePeripheral->GetEY()[i] / nearSidePeripheral->GetY()[i], 2) );
2664               
2665             nearSideCentral->GetY()[i] /= nearSidePeripheral->GetY()[i];
2666             
2667             nearSideCentral->GetEY()[i] *= nearSideCentral->GetY()[i];
2668           }
2669           //Printf("done");
2670           
2671           for (Int_t i=0; i<awaySideCentral->GetN(); i++)
2672           {
2673             //Printf("away %d", i);
2674             if (awaySidePeripheral->GetY()[i] <= 1e-5 || awaySideCentral->GetY()[i] <= 1e-5)
2675             {
2676               awaySideCentral->RemovePoint(i);
2677               awaySidePeripheral->RemovePoint(i);
2678               i--;
2679               continue;
2680             }
2681             
2682             awaySideCentral->GetEY()[i] = TMath::Sqrt(
2683               TMath::Power(awaySideCentral->GetEY()[i] / awaySideCentral->GetY()[i], 2) + 
2684               TMath::Power(awaySidePeripheral->GetEY()[i] / awaySidePeripheral->GetY()[i], 2) );
2685             
2686             awaySideCentral->GetY()[i] /= awaySidePeripheral->GetY()[i];
2687           
2688             awaySideCentral->GetEY()[i] *= awaySideCentral->GetY()[i];
2689           }
2690           
2691           if (caseId == 3)
2692           {
2693             nearSideCentral = (TGraphErrors*) nearSideCentral->Clone();
2694             nearSideCentral->SetLineColor(1);
2695             nearSideCentral->SetMarkerColor(1);
2696           
2697             awaySideCentral = (TGraphErrors*) awaySideCentral->Clone();
2698             awaySideCentral->SetLineColor(1);
2699             awaySideCentral->SetMarkerColor(1);
2700           }
2701           
2702           if (caseId >= 4)
2703           {
2704             nearSideCentral = (TGraphErrors*) nearSideCentral->Clone();
2705             nearSideCentral->SetLineColor(caseId - 3);
2706             nearSideCentral->SetMarkerColor(caseId - 3);
2707           
2708             awaySideCentral = (TGraphErrors*) awaySideCentral->Clone();
2709             awaySideCentral->SetLineColor(caseId - 3);
2710             awaySideCentral->SetMarkerColor(caseId - 3);
2711           }
2712           
2713           //Printf("%d", caseList[caseId]);
2714           
2715           nearSideCentral->Draw("PSAME");
2716           awaySideCentral->Draw("PSAME");
2717         }
2718       }
2719       if (caseId == 0 && k == 0)
2720         l->Draw();
2721     }
2722   }
2723   
2724   c->SaveAs("tsallisparams.png");
2725 }
2726
2727 void DrawYieldLHCRHIC_ICP(const char* fileName = "yields.root")
2728 {
2729   Int_t caseId = 0;
2730   Int_t caseList[] = { 18 };
2731   Int_t j = 1;
2732   
2733   ReadYields(fileName);
2734   
2735   c = new TCanvas("lhc_rhic", "lhc_rhic", 800, 600);
2736   gPad->SetGridx();
2737   gPad->SetGridy();
2738   
2739   dummy = new TH2F("dummy", ";p_{T,assoc};I_{CP}", 100, 0, 12, 1000, 0, 10);
2740   dummy->SetStats(0);
2741   currentDummy = dummy->DrawCopy();
2742   currentDummy->GetYaxis()->SetRangeUser(0, 2);
2743         
2744   TGraphErrors** tmp = yields[0][j][0]; nearSideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
2745   tmp = yields[1][j][0]; awaySideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
2746   tmp = yields[0][j][2]; nearSidePeripheral = tmp[caseList[caseId]];
2747   tmp = yields[1][j][2]; awaySidePeripheral = tmp[caseList[caseId]];
2748         
2749   for (Int_t i=0; i<nearSideCentral->GetN(); i++)
2750   {
2751     //Printf("near %d %f %f", i, nearSideCentral->GetY()[i], nearSidePeripheral->GetY()[i]);
2752     if (nearSidePeripheral->GetY()[i] <= 1e-5 || nearSideCentral->GetY()[i] <= 1e-5)
2753     {
2754       nearSideCentral->RemovePoint(i);
2755       nearSidePeripheral->RemovePoint(i);
2756       i--;
2757       continue;
2758     }
2759   
2760     nearSideCentral->GetEY()[i] = TMath::Sqrt(
2761       TMath::Power(nearSideCentral->GetEY()[i] / nearSideCentral->GetY()[i], 2) + 
2762       TMath::Power(nearSidePeripheral->GetEY()[i] / nearSidePeripheral->GetY()[i], 2) );
2763       
2764     nearSideCentral->GetY()[i] /= nearSidePeripheral->GetY()[i];
2765     
2766     nearSideCentral->GetEY()[i] *= nearSideCentral->GetY()[i];
2767   }
2768   //Printf("done");
2769   
2770   for (Int_t i=0; i<awaySideCentral->GetN(); i++)
2771   {
2772     //Printf("away %d", i);
2773     if (awaySidePeripheral->GetY()[i] <= 1e-5 || awaySideCentral->GetY()[i] <= 1e-5)
2774     {
2775       awaySideCentral->RemovePoint(i);
2776       awaySidePeripheral->RemovePoint(i);
2777       i--;
2778       continue;
2779     }
2780     
2781     awaySideCentral->GetEY()[i] = TMath::Sqrt(
2782       TMath::Power(awaySideCentral->GetEY()[i] / awaySideCentral->GetY()[i], 2) + 
2783       TMath::Power(awaySidePeripheral->GetEY()[i] / awaySidePeripheral->GetY()[i], 2) );
2784     
2785     awaySideCentral->GetY()[i] /= awaySidePeripheral->GetY()[i];
2786   
2787     awaySideCentral->GetEY()[i] *= awaySideCentral->GetY()[i];
2788   }
2789           
2790   nearSideCentral->SetMarkerStyle(21);
2791   nearSideCentral->SetLineColor(1);
2792   nearSideCentral->SetMarkerColor(1);
2793           
2794   awaySideCentral->SetMarkerStyle(25);
2795   awaySideCentral->SetLineColor(1);
2796   awaySideCentral->SetMarkerColor(1);
2797   
2798   nearSideCentral->Draw("PSAME");
2799   awaySideCentral->Draw("PSAME");        
2800
2801   legend = new TLegend(0.4, 0.8, 0.99, 0.99);
2802   legend->SetFillColor(0);
2803   legend->AddEntry(nearSideCentral, "ALICE I_{CP} Near 8-15 GeV 0-5%/60-90%", "P");
2804   legend->AddEntry(awaySideCentral, "ALICE I_{CP} Away 8-15 GeV 0-5%/60-90%", "P");
2805   
2806   if (0)
2807   {
2808     nearSideCentral->Fit("pol1", "", "SAME", 4.5, 11.5);
2809     awaySideCentral->Fit("pol1", "", "SAME", 4.5, 11.5);
2810     nearSideCentral->GetFunction("pol1")->SetLineWidth(1);
2811     awaySideCentral->GetFunction("pol1")->SetLineWidth(1);
2812   }
2813
2814   if (0)
2815   {
2816     // RCP, ALICE
2817     dndpt_central = ReadHepdata("raa_dndpt_central.txt", kFALSE, 3);
2818     dndpt_peripheral = ReadHepdata("raa_dndpt_peripheral.txt", kFALSE, 3);
2819     
2820     //dndpt_central->Print();
2821     //dndpt_peripheral->Print();
2822     
2823     // ratio of Ncoll (from paper)
2824     // TODO there is also an uncertainty on that
2825     Double_t scale = 1690. / 15.7;
2826     Double_t scaleUnc = TMath::Sqrt(TMath::Power(131. / 1690., 2) + TMath::Power(0.7 / 15.7, 2));
2827     
2828     for (Int_t i=0; i<dndpt_central->GetN(); i++)
2829     {
2830       dndpt_central->GetEY()[i] = TMath::Sqrt(TMath::Power(dndpt_central->GetEY()[i] / dndpt_central->GetY()[i], 2) + 
2831         TMath::Power(dndpt_peripheral->GetEY()[i] / dndpt_peripheral->GetY()[i], 2));
2832       dndpt_central->GetY()[i] /= dndpt_peripheral->GetY()[i] * scale;
2833       dndpt_central->GetEY()[i] *= dndpt_central->GetY()[i];
2834     }
2835     
2836     //new TCanvas;
2837     //dndpt_central->Print();
2838     //dndpt_central->Draw("AP");
2839     
2840     dndpt_central->Draw("*SAME");
2841     
2842     latex = new TLatex(0.34, 0.09, "9% N_{coll} scale uncertainty on R_{CP}");
2843     latex->SetTextSize(0.03);
2844     latex->Draw();
2845     
2846     // RAA, ALICE
2847     raa_central = ReadHepdata("raa_alice_central.txt", kFALSE, 3);
2848     raa_central->SetMarkerStyle(20);
2849     //raa_central->Draw("PSAME");
2850   
2851     legend->AddEntry(dndpt_central, "ALICE R_{CP} 0-5%/70-80%", "P");
2852   }
2853   
2854   if (0)
2855   {
2856     // IAA, RHIC
2857     // calculate ICP from IAA(0-20) / IAA (20-60)
2858     // TODO only using uncertainties from IAA(0-20)
2859     // TODO systematic uncertainty stored in graph with _sys appended
2860     TFile::Open("rhic/pi0h_graphs.root");
2861     
2862     for (Int_t i=0; i<3; i+=2)
2863     {
2864       // gIAA_<ptTrigBin>_<centBin>_<angularRegionBin>
2865       central = (TGraphErrors*) gFile->Get(Form("gIAA_3_0_%d", i));
2866       peripheral = (TGraphErrors*) gFile->Get(Form("gIAA_3_1_%d", i));
2867       
2868       for (Int_t j=0; j<central->GetN(); j++)
2869       {
2870         central->GetY()[j] /= peripheral->GetY()[j];
2871         central->GetEY()[j] /= peripheral->GetY()[j];
2872       }
2873       
2874       central->SetMarkerStyle((i == 0) ? 29 : 30);
2875       central->SetMarkerColor(2);
2876       central->SetLineColor(2);
2877       central->Draw("PSAME");
2878       legend->AddEntry(central, Form("PHENIX I_{CP} %s 9-12 GeV 0-20%/20-60%", (i == 0) ? "Near" : "Away"), "P");
2879     }
2880   }
2881   
2882   legend->Draw();
2883   
2884   c->SaveAs("icp.png");
2885 }
2886
2887 TGraphErrors* GetRatio(const char* fileName, Int_t centrality1, Int_t centrality2, Int_t triggerId, Int_t caseId, Int_t side, const char* fileName2 = 0)
2888 {
2889   // 0 = near side; 1 = away side
2890
2891   ReadYields(fileName);
2892   
2893   TGraphErrors** tmp = yields[side][triggerId][centrality1]; 
2894   nearSideCentral = (TGraphErrors*) tmp[caseId]->Clone();
2895   
2896   if (fileName2)
2897     ReadYields(fileName2);
2898   
2899   tmp = yields[side][triggerId][centrality2]; 
2900   nearSidePeripheral = (TGraphErrors*) tmp[caseId]->Clone();
2901   
2902   Printf("%d %d", nearSideCentral->GetN(), nearSidePeripheral->GetN());
2903         
2904   for (Int_t i=0; i<nearSideCentral->GetN(); i++)
2905   {
2906     if (nearSidePeripheral->GetY()[i] <= 1e-5 || nearSideCentral->GetY()[i] <= 1e-5)
2907     {
2908       nearSideCentral->RemovePoint(i);
2909       nearSidePeripheral->RemovePoint(i);
2910       i--;
2911       continue;
2912     }
2913     
2914     if (nearSideCentral->GetX()[i] != nearSidePeripheral->GetX()[i])
2915     {
2916       Printf("Inconsistent x values %f %f", nearSideCentral->GetX()[i], nearSidePeripheral->GetX()[i]);
2917       AliFatal("");
2918     }
2919   
2920     Printf("near %d %f %f", i, nearSideCentral->GetY()[i], nearSidePeripheral->GetY()[i]);
2921     
2922     nearSideCentral->GetEY()[i] = TMath::Sqrt(
2923       TMath::Power(nearSideCentral->GetEY()[i] / nearSideCentral->GetY()[i], 2) + 
2924       TMath::Power(nearSidePeripheral->GetEY()[i] / nearSidePeripheral->GetY()[i], 2) );
2925       
2926     nearSideCentral->GetY()[i] /= nearSidePeripheral->GetY()[i];
2927     // scaling for IAA
2928     if (centrality2 == 3)
2929       nearSideCentral->GetY()[i] /= kPythiaScalingFactor;
2930     
2931     nearSideCentral->GetEY()[i] *= nearSideCentral->GetY()[i];
2932   }
2933   
2934   //nearSideCentral->GetXaxis()->SetTitle("p_{T, assoc}");
2935   //nearSideCentral->GetYaxis()->SetTitle((centrality2 == 3) ? "I_{AA}" : "I_{CP}");
2936   
2937   return nearSideCentral;
2938 }
2939
2940 TGraphErrors* GetIAA(const char* fileName, Int_t centrality, Int_t triggerId, Int_t caseId, Int_t side)
2941 {
2942   return GetRatio(fileName, centrality, 3, triggerId, caseId, side);
2943 }
2944
2945 TGraphErrors* GetICP(const char* fileName, Int_t triggerId, Int_t caseId, Int_t side)
2946 {
2947   return GetRatio(fileName, 1, 2, triggerId, caseId, side);
2948 }
2949
2950 void DrawYieldLHCRHIC_IAA(const char* fileName, Bool_t central, Bool_t rhic)
2951 {
2952   Int_t caseId = 0;
2953   Int_t caseList[] = { 18 };
2954   Int_t j = 1;
2955   
2956   ReadYields(fileName);
2957   
2958   c = new TCanvas("lhc_rhic", "lhc_rhic", 800, 600);
2959   gPad->SetGridx();
2960   gPad->SetGridy();
2961   
2962   dummy = new TH2F("dummy", ";p_{T,assoc};I_{AA}", 100, 0, 12, 1000, 0, 10);
2963   dummy->SetStats(0);
2964   currentDummy = dummy->DrawCopy();
2965   currentDummy->GetYaxis()->SetRangeUser(0, 3);
2966         
2967   Int_t nominatorBin = 0;
2968   if (!central)
2969     nominatorBin = 2;
2970         
2971   nearSideCentral = GetIAA(fileName, nominatorBin, j, caseList[caseId], 0);
2972   awaySideCentral = GetIAA(fileName, nominatorBin, j, caseList[caseId], 1);
2973   
2974   nearSideCentral->SetMarkerStyle(21);
2975   nearSideCentral->SetLineColor(1);
2976   nearSideCentral->SetMarkerColor(1);
2977           
2978   awaySideCentral->SetMarkerStyle(25);
2979   awaySideCentral->SetLineColor(1);
2980   awaySideCentral->SetMarkerColor(1);
2981   
2982   nearSideCentral->Draw("PSAME");
2983   awaySideCentral->Draw("PSAME");        
2984   
2985   legend = new TLegend(0.4, 0.8, 0.99, 0.99);
2986   legend->SetFillColor(0);
2987   legend->AddEntry(nearSideCentral, Form("ALICE I_{AA} Near 8-15 GeV %s%%/Pythia6", (central) ? "0-5" : "60-90"), "P");
2988   legend->AddEntry(awaySideCentral, Form("ALICE I_{AA} Away 8-15 GeV %s%%/Pythia6", (central) ? "0-5" : "60-90"), "P");
2989   
2990   if (rhic)
2991   {
2992     // IAA, RHIC
2993     // systematic uncertainty stored in graph with _sys appended
2994     TFile::Open("rhic/pi0h_graphs.root");
2995     
2996     for (Int_t i=0; i<3; i+=2)
2997     {
2998       // gIAA_<ptTrigBin>_<centBin>_<angularRegionBin>
2999       rhic_iaa = (TGraphErrors*) gFile->Get(Form("gIAA_2_%d_%d", (central) ? 0 : 1, i));
3000       rhic_iaa_sys = (TGraphErrors*) gFile->Get(Form("gIAA_2_%d_%d_sys", (central) ? 0 : 1, i));
3001   
3002       rhic_iaa->SetMarkerStyle((i == 0) ? 29 : 30);
3003       rhic_iaa->SetMarkerColor(2);
3004       rhic_iaa->SetLineColor(2);
3005       rhic_iaa->Draw("PSAME");
3006       rhic_iaa_sys->SetLineColor(2);
3007       rhic_iaa_sys->SetMarkerColor(2);
3008       rhic_iaa_sys->Draw("PSAME");
3009       legend->AddEntry(rhic_iaa, Form("PHENIX I_{AA} %s 7-9 GeV %s%%/pp", (i == 0) ? "Near" : "Away", (central) ? "0-20" : "20-60"), "P");
3010     }
3011     for (Int_t i=0; i<3; i+=2)
3012     {
3013       // gIAA_<ptTrigBin>_<centBin>_<angularRegionBin>
3014       rhic_iaa = (TGraphErrors*) gFile->Get(Form("gIAA_3_%d_%d", (central) ? 0 : 1, i));
3015       rhic_iaa_sys = (TGraphErrors*) gFile->Get(Form("gIAA_3_%d_%d_sys", (central) ? 0 : 1, i));
3016   
3017       rhic_iaa->SetMarkerStyle((i == 0) ? 20 : 24);
3018       rhic_iaa->SetMarkerColor(4);
3019       rhic_iaa->SetLineColor(4);
3020       rhic_iaa->Draw("PSAME");
3021       rhic_iaa_sys->SetLineColor(4);
3022       rhic_iaa_sys->SetMarkerColor(4);
3023       rhic_iaa_sys->Draw("PSAME");
3024       legend->AddEntry(rhic_iaa, Form("PHENIX I_{AA} %s 9-12 GeV %s%%/pp", (i == 0) ? "Near" : "Away", (central) ? "0-20" : "20-60"), "P");
3025     }
3026   }
3027   
3028   legend->Draw();
3029   
3030   c->SaveAs("iaa.png");
3031 }
3032
3033 void CompareIAAICP(const char* fileName1, const char* fileName2, Int_t nominatorBin, Int_t denominatorBin)
3034 {
3035   Int_t j = 1;
3036   Int_t caseId = 18;
3037   //Int_t caseId = 12;
3038
3039   nearSide1 = GetRatio(fileName1, nominatorBin, denominatorBin, j, caseId, 0);
3040   nearSide2 = GetRatio(fileName2, nominatorBin, denominatorBin, j, caseId, 0);
3041   awaySide1 = GetRatio(fileName1, nominatorBin, denominatorBin, j, caseId, 1);
3042   awaySide2 = GetRatio(fileName2, nominatorBin, denominatorBin, j, caseId, 1);
3043   
3044 /*  ScaleGraph(nearSide2, 1.33);
3045   ScaleGraph(awaySide2, 1.33);*/
3046   
3047   new TCanvas;
3048   dummy = new TH2F("dummy", Form(";p_{T,assoc};%s", (denominatorBin == 3) ? "I_{AA}" : "I_{CP}"), 100, 0, 12, 1000, 0, 10);
3049   dummy->SetStats(0);
3050   currentDummy = dummy->DrawCopy();
3051   currentDummy->GetYaxis()->SetRangeUser(0, 3);
3052   
3053   nearSide1->SetMarkerStyle(21);
3054   nearSide1->SetLineColor(1);
3055   nearSide1->SetMarkerColor(1);
3056           
3057   nearSide2->SetMarkerStyle(21);
3058   nearSide2->SetLineColor(2);
3059   nearSide2->SetMarkerColor(2);
3060   
3061   awaySide1->SetMarkerStyle(25);
3062   awaySide1->SetLineColor(1);
3063   awaySide1->SetMarkerColor(1);
3064   
3065   awaySide2->SetMarkerStyle(25);
3066   awaySide2->SetLineColor(2);
3067   awaySide2->SetMarkerColor(2);
3068   
3069   RemovePointsBelowX(nearSide1, 3);
3070   RemovePointsBelowX(nearSide2, 3);
3071   RemovePointsBelowX(awaySide1, 3);
3072   RemovePointsBelowX(awaySide2, 3);
3073   
3074   nearSide1->DrawClone("PSAME");
3075   awaySide1->DrawClone("PSAME");        
3076   nearSide2->DrawClone("PSAME");
3077   awaySide2->DrawClone("PSAME");        
3078   
3079   new TCanvas;
3080   currentDummy = dummy->DrawCopy();
3081   currentDummy->GetYaxis()->SetRangeUser(0.5, 1.5);
3082   gPad->SetGridx();
3083   gPad->SetGridy();
3084   
3085   DivideGraphs(nearSide1, nearSide2);
3086   DivideGraphs(awaySide1, awaySide2);
3087   
3088   nearSide1->Draw("PSAME");
3089   awaySide1->Draw("PSAME");        
3090   
3091   nearSide1->Fit("pol0", "", "SAME", 3.01, 9.99);
3092   awaySide1->Fit("pol0", "", "SAME", 3.01, 9.99);
3093 }
3094
3095 void ScaleGraph(TGraphErrors* graph, Float_t factor)
3096 {
3097         for (Int_t i=0; i<graph->GetN(); i++)
3098         {
3099     graph->GetY()[i] *= factor;
3100     graph->GetEY()[i] *= factor;
3101   }
3102 }
3103
3104 TGraphErrors* DrawBaselines(const char* fileName, Int_t numeratorBin, Int_t denominatorBin, Int_t side, Bool_t verbose = kTRUE)
3105 {
3106   Int_t j = 1;
3107   
3108   TGraphErrors* first = 0;
3109   TGraphErrors* max = 0;
3110   
3111   if (verbose)
3112   {
3113     c = new TCanvas;
3114     dummy = new TH2F("dummy", Form(";p_{T,assoc};%s", (denominatorBin == 3) ? "I_{AA}" : "I_{CP}"), 100, 0, 12, 1000, 0, 10);
3115     dummy->SetStats(0);
3116     currentDummy = dummy->DrawCopy();
3117     currentDummy->GetYaxis()->SetRangeUser(0, 3);
3118     
3119     c2 = new TCanvas;
3120     currentDummy = dummy->DrawCopy();
3121     currentDummy->GetYaxis()->SetRangeUser(0, 2);
3122   }
3123   
3124   Int_t caseList[] = { 18, 19, 21, 22 };
3125   //Int_t caseList[] = { 23, 24, 26, 27 };
3126   
3127   for (Int_t caseId = 0; caseId < 4; caseId++)
3128   {
3129     graph = GetRatio(fileName, numeratorBin, denominatorBin, j, caseList[caseId], side);
3130     
3131     graph->SetLineColor(caseId + 1);
3132     graph->SetMarkerColor(caseId + 1);
3133     
3134     RemovePointsBelowX(graph, 3);
3135     
3136     if (verbose)
3137     {
3138       c->cd();
3139       graph->DrawClone("*SAME");
3140     }
3141     
3142     if (!first)
3143     {
3144       first = graph;
3145       max = (TGraphErrors*) graph->Clone();
3146       for (Int_t i=0; i<max->GetN(); i++)
3147       {
3148         max->GetY()[i] = 0;
3149         max->GetEY()[i] = 0;
3150       }
3151     }
3152     else
3153     {
3154       DivideGraphs(graph, first);
3155       
3156       if (verbose)
3157       {
3158         c2->cd();
3159         graph->DrawClone("*SAME");
3160       }
3161       
3162       for (Int_t i=0; i<graph->GetN(); i++)
3163       {
3164         if (max->GetY()[i] < TMath::Abs(graph->GetY()[i] - 1))
3165           max->GetY()[i] = TMath::Abs(graph->GetY()[i] - 1);
3166       }
3167     }
3168   }
3169   
3170   if (verbose)
3171   {
3172     new TCanvas;
3173     max->Draw("A*");
3174   }
3175   
3176   max->GetXaxis()->SetTitle("p_{T, assoc}");
3177   max->GetYaxis()->SetTitle((denominatorBin == 3) ? "Effect on I_{AA}" : "Effect on I_{CP}");
3178   max->GetYaxis()->SetRangeUser(0, 0.4);
3179   
3180   return max;
3181 }
3182
3183 void DrawBaselinesAll(const char* fileName)
3184 {
3185   c = new TCanvas("c", "c", 800, 600);
3186   c->Divide(3, 2);
3187   
3188   for (Int_t i=0; i<2; i++)
3189   {
3190     c->cd(1+i*3); DrawBaselines(fileName, 0, 3, i, kFALSE)->Draw("A*");
3191     c->cd(2+i*3); DrawBaselines(fileName, 2, 3, i, kFALSE)->Draw("A*");
3192     c->cd(3+i*3); DrawBaselines(fileName, 0, 2, i, kFALSE)->Draw("A*");
3193   }
3194 }
3195
3196 TGraphErrors* DrawSystUnc(TGraphErrors* graph, Int_t iaa_icp, Int_t awaySide)
3197 {
3198   // iaa = 0, icp = 1
3199
3200   Float_t baseline = 1;
3201   if (awaySide == 0)
3202     baseline = 0.07;
3203   else if (awaySide == 1)
3204     baseline = 0.2;
3205     
3206   /*
3207   Float_t reference = 0;
3208   if (iaa_icp == 0)
3209     reference = 0.13;
3210   */
3211     
3212   Float_t efficiency = 0.08;
3213   
3214   Float_t centrality = 1;
3215   if (iaa_icp == 0)
3216     centrality = (awaySide == 0) ? 0.02 : 0.06;
3217   else if (iaa_icp == 1)
3218     centrality = (awaySide == 0) ? 0.04 : 0.08;
3219   
3220   Float_t ptResolution = 0;
3221   
3222   Float_t total = TMath::Sqrt(baseline * baseline + efficiency * efficiency + centrality * centrality + ptResolution * ptResolution);
3223   
3224   Printf("Total syst: %f", total);
3225   
3226   systUnc = (TGraphErrors*) graph->Clone();
3227   for (Int_t i=0; i<systUnc->GetN(); i++)
3228   {
3229     systUnc->GetEY()[i] = systUnc->GetY()[i] * total;
3230     systUnc->GetEX()[i] = 0;
3231   }
3232     
3233   //systUnc->Print();
3234   
3235   systUnc->SetLineColor(kGray + 1);
3236   systUnc->SetLineWidth(6);
3237   
3238   systUnc->Draw("PSAME");
3239     
3240   return systUnc;
3241 }
3242
3243 void IAA(const char* fileName, Int_t iaa)
3244 {
3245   // iaa
3246   // 0 = IAA LHC1
3247   // 1 = IAA RHIC
3248   // 2 = ICP
3249
3250   style();
3251   
3252   Int_t j = 1;
3253   Int_t caseId[] = { 18, 23 };
3254
3255   c = new TCanvas((iaa != 1) ? ((iaa == 0) ? "iaa" : "iaarhic") : "icp", (iaa != 1) ? ((iaa == 0) ? "iaa" : "iaarhic") : "icp", 1200, 600);
3256   c->Range(0, 0, 1, 1);
3257
3258   TPad* pad1 = new TPad(Form("%s_2", fileName), "", 0, 0, 0.5, 1);
3259   pad1->Draw();
3260
3261   TPad* pad2 = new TPad(Form("%s_1", fileName), "", 0.5, 0, 1, 1);
3262   pad2->Draw();
3263   
3264   pad1->cd();
3265   gPad->SetRightMargin(0);
3266   gPad->SetTopMargin(0.05);
3267   gPad->SetLeftMargin(0.13);
3268   //gPad->SetGridx();
3269   gPad->SetGridy();
3270   
3271   pad2->cd();
3272   gPad->SetLeftMargin(0);
3273   gPad->SetTopMargin(0.05);
3274   gPad->SetRightMargin(0.13);
3275   //gPad->SetGridx();
3276   gPad->SetGridy();
3277   
3278   pad1->cd();
3279   dummy = new TH2F("dummy", Form(";p_{T,assoc} (GeV/c);%s", (iaa != 1) ? "I_{AA,Pythia}" : "I_{CP}"), 100, 1.5, 10.5, 1000, 0, 2.9);
3280   dummy->SetStats(0);
3281   dummy->GetYaxis()->SetTitleOffset(1.3);
3282   dummy->GetXaxis()->SetTitleOffset(1.1);
3283   currentDummy = dummy->DrawCopy();
3284   
3285   latex = new TLatex(0.17, 0.90, "Near side");
3286   latex->SetTextSize(0.04);
3287   latex->SetNDC();
3288   latex->Draw();
3289   
3290   if (iaa != 1)
3291   {
3292     box = new TBox(2, 0.87, 2.5, 1.13);
3293     box->SetFillColor(kGray + 1);
3294     box->SetLineColor(kGray + 1);
3295     box->Draw();
3296   
3297     box2 = new TBox(2, 0.87 * 1.5, 2.5, 1.13 * 1.5);
3298     box2->SetFillColor(kGray + 1);
3299     box2->SetLineColor(kGray + 1);
3300     box2->Draw();
3301   }
3302   
3303   pad2->cd();
3304   currentDummy = dummy->DrawCopy();
3305   
3306   if (iaa != 1)
3307     box->Draw();
3308   
3309   latex = new TLatex(0.05, 0.90, "Away side");
3310   latex->SetTextSize(0.04);
3311   latex->SetNDC();
3312   latex->Draw();
3313   
3314   legend = new TLegend(0.17, 0.65, (iaa != 2) ? 0.53 : 0.82, 0.80);
3315   legend->SetFillColor(0);
3316   legend->SetTextSize(0.04);
3317   
3318   for (Int_t i=0; i<2; i++)
3319   {
3320     nearSideCentral    = GetRatio(fileName, (iaa != 2) ? 0 : 1, (iaa != 1) ? 3 : 2, j, caseId[i], 0);
3321     if (iaa == 0)
3322       nearSidePeripheral = GetRatio(fileName, 2, 3, j, caseId[i], 0);
3323     awaySideCentral    = GetRatio(fileName, (iaa != 2) ? 0 : 1, (iaa != 1) ? 3 : 2, j, caseId[i], 1);
3324     if (iaa == 0)
3325       awaySidePeripheral = GetRatio(fileName, 2, 3, j, caseId[i], 1);
3326     
3327     RemovePointsBelowX(nearSideCentral, 3);
3328     RemovePointsBelowX(awaySideCentral, 3);
3329     RemovePointsAboveX(nearSideCentral, 10);
3330     RemovePointsAboveX(awaySideCentral, 10);
3331     
3332     RemoveXErrors(nearSideCentral); RemoveXErrors(awaySideCentral);
3333     
3334     if (iaa == 0)
3335     {
3336       RemovePointsBelowX(nearSidePeripheral, 3);
3337       RemovePointsBelowX(awaySidePeripheral, 3);
3338       RemovePointsAboveX(nearSidePeripheral, 10);
3339       RemovePointsAboveX(awaySidePeripheral, 10);
3340       ShiftPoints(nearSidePeripheral, 0.2);
3341       ShiftPoints(awaySidePeripheral, 0.2);
3342       RemoveXErrors(nearSidePeripheral); RemoveXErrors(awaySidePeripheral);
3343     }
3344     
3345     nearSideCentral->SetMarkerStyle(21);
3346     nearSideCentral->SetLineColor(1);
3347     nearSideCentral->SetMarkerColor(1);
3348             
3349     awaySideCentral->SetMarkerStyle(21);
3350     awaySideCentral->SetLineColor(1);
3351     awaySideCentral->SetMarkerColor(1);
3352     
3353     if (iaa == 0)
3354     {
3355       nearSidePeripheral->SetMarkerStyle(22);
3356       nearSidePeripheral->SetLineColor(2);
3357       nearSidePeripheral->SetMarkerColor(2);
3358       
3359       awaySidePeripheral->SetMarkerStyle(22);
3360       awaySidePeripheral->SetLineColor(2);
3361       awaySidePeripheral->SetMarkerColor(2);
3362     }
3363     
3364     if (i == 0)
3365     {
3366       if (iaa == 0)
3367       {
3368         legend->AddEntry(nearSideCentral, "0-5% / Pythia", "P");
3369         legend->AddEntry(nearSidePeripheral, "60-90% / Pythia", "P");
3370       }
3371       else if (iaa == 2)
3372       {
3373         legend->AddEntry(nearSideCentral, "0-20% / Pythia", "P");
3374       }
3375     }
3376     
3377     
3378     const char* style = "PSAME";
3379     if (i == 1)
3380       style = "LSAMEX";
3381     
3382     pad1->cd();
3383     if (i == 0)
3384       DrawSystUnc(nearSideCentral, (iaa == 1), 0);
3385     nearSideCentral->DrawClone(style);
3386     if (iaa == 0)
3387     {
3388       if (i == 0)
3389         DrawSystUnc(nearSidePeripheral, (iaa == 1), 0);
3390       nearSidePeripheral->DrawClone(style);        
3391     }
3392     
3393     pad2->cd();
3394     if (i == 0)
3395       DrawSystUnc(awaySideCentral, (iaa == 1), 1);
3396     awaySideCentral->DrawClone(style);
3397     if (iaa == 0)
3398     {
3399       if (i == 0)
3400         DrawSystUnc(awaySidePeripheral, (iaa == 1), 1);
3401       awaySidePeripheral->DrawClone(style);        
3402     }
3403   }
3404   
3405   if (iaa == 2)
3406   {
3407     // IAA, RHIC
3408     // systematic uncertainty stored in graph with _sys appended
3409     TFile::Open("rhic/pi0h_graphs.root");
3410     
3411     for (Int_t ptTrigBin=2; ptTrigBin<4; ptTrigBin++)
3412     {
3413       Bool_t central = kTRUE;
3414       for (Int_t i=0; i<3; i+=2)
3415       {
3416         // gIAA_<ptTrigBin>_<centBin>_<angularRegionBin>
3417         rhic_iaa = (TGraphErrors*) gFile->Get(Form("gIAA_%d_%d_%d", ptTrigBin, (central) ? 0 : 1, i));
3418         rhic_iaa_sys = (TGraphErrors*) gFile->Get(Form("gIAA_%d_%d_%d_sys", ptTrigBin, (central) ? 0 : 1, i));
3419     
3420         rhic_iaa->SetMarkerStyle((ptTrigBin == 2) ? 29 : 30);
3421         rhic_iaa->SetMarkerColor(2);
3422         rhic_iaa->SetLineColor(2);
3423         rhic_iaa_sys->SetLineColor(2);
3424         rhic_iaa_sys->SetMarkerColor(2);
3425         
3426         ShiftPoints(rhic_iaa, -0.05 + 0.05 * (ptTrigBin*2-4));
3427         ShiftPoints(rhic_iaa_sys, -0.05 + 0.05 * (ptTrigBin*2-4));
3428         
3429         if (i == 0)
3430           pad1->cd();
3431         else if (i == 2)
3432           pad2->cd();
3433         rhic_iaa->Draw("PSAME");
3434         rhic_iaa_sys->Draw("PSAME");
3435         
3436         if (i == 0)
3437           legend->AddEntry(rhic_iaa, Form("PHENIX %s GeV %s%% / pp", (ptTrigBin == 2) ? "7-9" : "9-12", (central) ? "0-20" : "20-60"), "P");
3438       }
3439     }
3440   }
3441   
3442   for (Int_t i=0; i<2; i++)
3443   {
3444     if (i == 0)
3445       pad1->cd();
3446     else
3447       pad2->cd();
3448       
3449     Float_t xC = 0.05;
3450     if (i == 0)
3451       xC = 0.17;
3452   
3453     latex = new TLatex(xC, 0.84, "8 GeV/c < p_{T,trig} < 15 GeV/c");
3454     latex->SetTextSize(0.04);
3455     latex->SetNDC();
3456     latex->Draw();
3457     
3458     if (iaa == 1)
3459     {
3460       latex = new TLatex(xC, 0.78, "0-5% / 60-90%");
3461       latex->SetTextSize(0.04);
3462       latex->SetNDC();
3463       latex->Draw();
3464     }
3465   
3466     latex = new TLatex(0.5+xC, 0.90, "ALICE preliminary");
3467     latex->SetTextSize(0.04);
3468     latex->SetNDC();
3469     latex->Draw();
3470     
3471     latex = new TLatex(0.5+xC, 0.84, "p_{T,assoc} < p_{T,trig}");
3472     latex->SetTextSize(0.04);
3473     latex->SetNDC();
3474     latex->Draw();
3475     
3476     latex = new TLatex(xC + 0.5 * i, 0.24, "Points: flat pedestal");
3477     latex->SetTextSize(0.04);
3478     latex->SetNDC();
3479     latex->Draw();
3480   
3481     latex = new TLatex(xC + 0.5 * i, 0.18, "Line: v_{2} subtracted");
3482     latex->SetTextSize(0.04);
3483     latex->SetNDC();
3484     latex->Draw();
3485     
3486     if (iaa != 1)
3487     {
3488       legend->DrawClone();
3489       legend->SetX1(legend->GetX1()-0.12);
3490       legend->SetX2(legend->GetX2()-0.12);
3491     }
3492   }
3493   
3494   c->SaveAs(Form("%s.eps", c->GetTitle()));
3495   c->SaveAs(Form("%s.png", c->GetTitle()));
3496 }
3497
3498 void RemoveXErrors(TGraphErrors* graph)
3499 {
3500         for (Int_t i=0; i<graph->GetN(); i++)
3501                 graph->GetEX()[i] = 0;
3502 }
3503
3504 void RemovePointsBelowX(TGraphErrors* graph, Float_t minX)
3505 {
3506   Int_t i=0;
3507   while (i<graph->GetN())
3508   {
3509     if (graph->GetX()[i] < minX)
3510       graph->RemovePoint(i);
3511     else
3512       i++;
3513   }
3514 }
3515
3516 void RemovePointsAboveX(TGraphErrors* graph, Float_t maxX)
3517 {
3518   Int_t i=0;
3519   while (i<graph->GetN())
3520   {
3521     if (graph->GetX()[i] > maxX)
3522       graph->RemovePoint(i);
3523     else
3524       i++;
3525   }
3526 }
3527
3528 void ShiftPoints(TGraphErrors* graph, Float_t dx)
3529 {
3530   Int_t i=0;
3531   while (i<graph->GetN())
3532   {
3533     graph->GetX()[i] += dx;
3534     i++;
3535   }
3536 }
3537
3538 void DivideGraphs(TGraphErrors* graph1, TGraphErrors* graph2)
3539 {
3540   graph1->Print();
3541   graph2->Print();
3542
3543   for (Int_t bin1 = 0; bin1 < graph1->GetN(); bin1++)
3544   {
3545     Float_t x = graph1->GetX()[bin1];
3546
3547     Int_t bin2 = 0;
3548     for (bin2 = 0; bin2<graph2->GetN(); bin2++)
3549       if (graph2->GetX()[bin2] >= x)
3550         break;
3551
3552     if (bin2 == graph2->GetN())
3553             bin2--;
3554
3555     if (bin2 > 0)
3556       if (TMath::Abs(graph2->GetX()[bin2-1] - x) < TMath::Abs(graph2->GetX()[bin2] - x))
3557         bin2--;
3558
3559     if (graph1->GetY()[bin1] == 0 || graph2->GetY()[bin2] == 0 || bin2 == graph2->GetN())
3560     {
3561       Printf("%d %d removed", bin1, bin2);
3562       graph1->RemovePoint(bin1--);
3563       continue;
3564     }
3565
3566     Float_t graph2Extrapolated = graph2->GetY()[bin2];
3567     if (TMath::Abs(x - graph2->GetX()[bin2]) > 0.0001)
3568     {
3569       Printf("%f %f %d %d not found", x, graph2->GetX()[bin2], bin1, bin2);
3570       graph1->RemovePoint(bin1--);
3571       continue;
3572     }
3573
3574     Float_t value = graph1->GetY()[bin1] / graph2Extrapolated;
3575     Float_t error = value * TMath::Sqrt(TMath::Power(graph1->GetEY()[bin1] / graph1->GetY()[bin1], 2) + TMath::Power(graph2->GetEY()[bin2] / graph2->GetY()[bin2], 2));
3576
3577     graph1->GetY()[bin1] = value;
3578     graph1->GetEY()[bin1] = error;
3579
3580     Printf("%d %d %f %f %f %f", bin1, bin2, x, graph2Extrapolated, value, error);
3581   }
3582 }
3583
3584 Float_t ExtractYields(TH1* hist, Int_t trigId, Int_t centralityId, Float_t ptA, Float_t ptW, Int_t caseId, Double_t normUnc)
3585 {
3586   CreateYieldStructure();
3587
3588   Float_t width = 0.69;
3589   //Float_t width = 0.5;
3590   //Float_t width = 0.85;
3591   
3592   //new TCanvas; hist->DrawCopy();
3593   
3594   Int_t binBegin = hist->FindBin(-width);
3595   Int_t binEnd = hist->FindBin(width);
3596   Double_t nearSideError = 0;
3597   Float_t nearSideYield = hist->IntegralAndError(binBegin, binEnd, nearSideError) / (binEnd - binBegin + 1);
3598   nearSideError /= (binEnd - binBegin + 1);
3599   
3600   Int_t binBegin = hist->FindBin(TMath::Pi() - width);
3601   Int_t binEnd = hist->FindBin(TMath::Pi() + width);
3602   Double_t awaySideError = 0;
3603   Float_t awaySideYield = hist->IntegralAndError(binBegin, binEnd, awaySideError) / (binEnd - binBegin + 1);
3604   awaySideError /= (binEnd - binBegin + 1);
3605   
3606   Printf("%d %d %f %d: %f+-%f %f+-%f (%f)", trigId, centralityId, ptA, caseId, nearSideYield, nearSideError, awaySideYield, awaySideError, normUnc);
3607   
3608   FillYield(trigId, centralityId, ptA, ptW, caseId, nearSideYield, TMath::Sqrt(nearSideError * nearSideError + normUnc * normUnc), awaySideYield, TMath::Sqrt(awaySideError * awaySideError + normUnc * normUnc));
3609   
3610   // store normUnc for error propagation later
3611   TGraphErrors** tmp = yields[2][trigId][centralityId];
3612   tmp[caseId]->SetPoint(tmp[caseId]->GetN(), ptA, normUnc);
3613   
3614   return awaySideYield;
3615 }
3616
3617 void FillYield(Int_t trigId, Int_t centralityId, Float_t ptA, Float_t ptW, Int_t caseId, Double_t nearSideYield, Double_t nearSideError, Double_t awaySideYield, Double_t awaySideError)
3618 {
3619   // CINT limitation here
3620   TGraphErrors** tmp = yields[0][trigId][centralityId];
3621   tmp[caseId]->SetPoint(tmp[caseId]->GetN(), ptA, nearSideYield);
3622   tmp[caseId]->SetPointError(tmp[caseId]->GetN()-1, ptW, nearSideError);
3623   //tmp[caseId]->Print();
3624   
3625   tmp = yields[1][trigId][centralityId];
3626   tmp[caseId]->SetPoint(tmp[caseId]->GetN(), ptA, awaySideYield);
3627   tmp[caseId]->SetPointError(tmp[caseId]->GetN()-1, ptW, awaySideError);
3628 }
3629
3630 Double_t hypgeo(Double_t a, Double_t b, Double_t c, Double_t z)
3631 {
3632   // ROOT::Math::hyperg is only defined for |z| < 1
3633   if (z > -1)
3634     return ROOT::Math::hyperg(a, b, c, z);
3635     
3636   // for z < -1 we can use an identity from http://en.wikipedia.org/wiki/Hypergeometric_function
3637   return TMath::Power(1-z, -b) * ROOT::Math::hyperg(c-a, b, c, z / (z-1));
3638 }
3639
3640 Double_t hypgeoder2(Double_t a, Double_t b, Double_t c, Double_t z)
3641 {
3642   // derivate of hypgeo with parameter b: d/db hypgeo
3643   
3644   static TF1* func = 0;
3645   if (!func)
3646     func = new TF1("hypgeoder2_func", "hypgeo([0], x, [1], [2])");
3647   
3648   func->SetParameters(a, c, z);
3649   return func->Derivative(b);
3650 }
3651
3652 void TsallisYieldUncertainty(Double_t n, Double_t q, Double_t beta, TMatrixDSym covMatrix, Int_t offset, Double_t& yield, Double_t& unc)
3653 {
3654   gSystem->Load("libMathMore");
3655
3656   TF1 tsallis("tsallis", "[0] * (1-[2]*(1-[1])*x*x)**(1/(1-[1]))", -0.5 * TMath::Pi(), 1.5 * TMath::Pi());
3657
3658   // Integrate[N (1 - b (1 - q) x^2)^(1/(1 - q)), x] --> N x Hypergeometric2F1[1/2, 1/(-1 + q), 3/2, -b (-1 + q) x^2]
3659   // [0] = n, [1] = q, [2] = beta
3660   TF1 tsallisIntegral("tsallisIntegral",               "[0]*x*hypgeo(0.5, 1/([1]-1), 1.5, -[2]*([1]-1)*x*x)");
3661   TF1 tsallisIntegralDerN("tsallisIntegralDerN",           "x*hypgeo(0.5, 1/([1]-1), 1.5, -[2]*([1]-1)*x*x)");
3662   
3663   TF1 tsallisIntegralDerq("tsallisIntegralDerq",       "[0]*x*(((1+[2]*([1]-1)*x*x)**(-1/([1]-1))-hypgeo(0.5, 1/([1]-1), 1.5, -[2]*([1]-1)*x*x))/2/([1]-1) - hypgeoder2(0.5, 1/([1]-1), 1.5, -[2]*([1]-1)*x*x)/([1]-1)**2)");
3664   
3665   TF1 tsallisIntegralDerbeta("tsallisIntegralDerbeta", "[0]*x*((1+[2]*([1]-1)*x*x)**(-1/([1]-1))-hypgeo(0.5, 1/([1]-1), 1.5, -[2]*([1]-1)*x*x))/2/[2]");
3666   
3667   const Float_t width = 0.7;
3668   
3669   TF1* derivates[4];
3670   derivates[0] = new TF1("const", "1");
3671   derivates[1] = &tsallisIntegralDerN;
3672   derivates[2] = &tsallisIntegralDerq;
3673   derivates[3] = &tsallisIntegralDerbeta;
3674   
3675   Printf("%f %f %f", n, q, beta);
3676   
3677   tsallis.SetParameters(n, q, beta);
3678   tsallisIntegral.SetParameters(n, q, beta);
3679   for (Int_t i=1; i<4; i++)
3680     derivates[i]->SetParameters(n, q, beta);
3681   
3682   yield = tsallisIntegral.Eval(width) - tsallisIntegral.Eval(-width);
3683   Double_t yield2 = tsallis.Integral(-width, width);
3684   
3685   unc = 0;
3686   for (Int_t i=0; i<4; i++)
3687     for (Int_t j=0; j<4; j++)
3688     {
3689       Int_t covI = i;
3690       Int_t covJ = j;
3691       if (i > 0)
3692         covI += offset;
3693       if (j > 0)
3694         covJ += offset;
3695         
3696       Double_t der1 = (derivates[i]->Eval(width) - derivates[i]->Eval(-width));
3697       Double_t der2 = (derivates[j]->Eval(width) - derivates[j]->Eval(-width));
3698         
3699       unc += der1 * der2 * covMatrix(covI, covJ);
3700       
3701       Printf("%d %d % .3e % .3e % .3e % .3e", i, j, der1, der2, covMatrix(covI, covJ), unc);
3702     }
3703     
3704   unc = TMath::Sqrt(unc);
3705   
3706   yield /= width * 2;
3707   yield2 /= width * 2;
3708   unc /= width * 2;
3709   
3710   Printf("%f (%f) +- %f", yield, yield2, unc);
3711 }
3712
3713 double NLowestBinAverage(TH1 &h, int N)
3714 {
3715   // Returns mean content of N lowest bins in h.
3716
3717   double avg = 0;
3718   int counter = 0;
3719   std::list<double> content;
3720   std::list<double>::iterator i;
3721
3722   for (int jbin=1; jbin<=h.GetNbinsX(); jbin++) {
3723     content.push_back(h.GetBinContent(jbin));
3724   }
3725   content.sort();
3726
3727   for (i = content.begin(); i != content.end(); ++i) {
3728
3729     if (counter == N)
3730       break;
3731
3732     avg += *i/N;
3733     counter++;
3734   }
3735
3736   if (counter < N)
3737     Warning("NLowestBinAverage()",
3738         "Avg. of %d bins requested, %d used", N, counter);
3739
3740   return avg;
3741
3742
3743 void DrawFlow(Float_t v2, TH1* hist, Float_t ptT, Float_t ptA, TH1* histMixed, Int_t trigId, Int_t centralityId, Int_t caseOffset, Float_t ptACenter, Float_t ptAWidth, Bool_t flatBaseLine = kFALSE, Int_t baseLineDetermination = 0)
3744 {
3745   // caseOffsets
3746   // 0 same with v2 (14 tsallis for baseline [28/29 tsallis params]; 15 yield from tsallis function)
3747   // [disabled] 1 same/mixed with v2 (15 tsallis for baseline)
3748   // 2 same no v2 (16 tsallis for baseline; 17 yield from tsallis function)
3749   // 4 same no v2 (18 flat fit 1)
3750   // 5 same no v2 (19 flat fit 2)
3751   // 6 same no v2 (20 flat avg over 2)
3752   // 7 same no v2 (21 flat avg over 4)
3753   // 8 same no v2 (22 flat avg over 8)
3754   // 9 same with v2 (23 flat fit 1)
3755   // 10 same with v2 (24 flat fit 2)
3756   // 11 same with v2 (25 flat avg over 2)
3757   // 12 same with v2 (26 flat avg over 4)
3758   // 13 same with v2 (27 flat avg over 8)
3759   
3760   // 30 gaussian fit width
3761
3762   // same stuff for same/mixed
3763   if (0 && caseOffset == 0 && histMixed)
3764   {
3765     TH1* clone = (TH1*) hist->Clone();
3766     clone->Divide(histMixed);
3767     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 1, ptACenter, ptAWidth);
3768   }
3769   
3770   // same for other baseline subtractions
3771   if (caseOffset == 0)
3772   {
3773     file = TFile::Open("dphi_corr.root", "UPDATE");
3774     hist->Write();
3775     file->Close();
3776     
3777     TH1* clone = (TH1*) hist->Clone();
3778     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 2, ptACenter, ptAWidth, kTRUE, 0);
3779   
3780     clone = (TH1*) hist->Clone();
3781     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 4, ptACenter, ptAWidth, kTRUE, 1);
3782   
3783     clone = (TH1*) hist->Clone();
3784     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 5, ptACenter, ptAWidth, kTRUE, 2);
3785     
3786     clone = (TH1*) hist->Clone();
3787     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 6, ptACenter, ptAWidth, kTRUE, 3);
3788     
3789     clone = (TH1*) hist->Clone();
3790     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 7, ptACenter, ptAWidth, kTRUE, 4);
3791     
3792     clone = (TH1*) hist->Clone();
3793     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 8, ptACenter, ptAWidth, kTRUE, 5);
3794     
3795     clone = (TH1*) hist->Clone();
3796     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 9, ptACenter, ptAWidth, kFALSE, 1);
3797   
3798     clone = (TH1*) hist->Clone();
3799     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 10, ptACenter, ptAWidth, kFALSE, 2);
3800   
3801     clone = (TH1*) hist->Clone();
3802     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 11, ptACenter, ptAWidth, kFALSE, 3);
3803   
3804     clone = (TH1*) hist->Clone();
3805     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 12, ptACenter, ptAWidth, kFALSE, 4);
3806   
3807     clone = (TH1*) hist->Clone();
3808     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 13, ptACenter, ptAWidth, kFALSE, 5);
3809   }
3810
3811   Float_t awaySideYield = ExtractYields(hist, trigId, centralityId, ptACenter, ptAWidth, 0 + caseOffset, 0);
3812   
3813   if (flatBaseLine)
3814     v2 = 0;
3815     
3816 /*    Float_t v2Trig  = flowGraph->Eval(ptT);
3817     Float_t v2Assoc = flowGraph->Eval(ptA);
3818     Float_t v2 = v2Trig * v2Assoc;
3819     Printf("%f %f: %.2f %.2f --> %.4f", ptT, ptA, v2Trig, v2Assoc, v2);*/
3820   
3821   TF1* flowFunc = new TF1("flowFunc", "[0] * (1+2*[1]*cos(2*x))", -0.5 * TMath::Pi(), 1.5 * TMath::Pi());
3822
3823   // find minimum
3824   if (0)
3825   {
3826     Float_t minBin = hist->FindBin(0.6);
3827     for (Int_t bin=hist->FindBin(0.6); bin<=hist->FindBin(1.8); bin++)
3828       if (hist->GetBinContent(bin) < hist->GetBinContent(minBin))
3829         minBin = bin;
3830             
3831     Float_t norm = hist->GetBinContent(minBin) / (1 + 2 * v2 * cos(2 * hist->GetBinCenter(minBin)));
3832     Double_t normUnc = 0;
3833   }
3834   else
3835   {
3836     if (baseLineDetermination == 0)
3837     {
3838       /*
3839       if (centralityId == 0)
3840         hist->Fit("pol0", "0", "", 0.8., 1.2);
3841       else
3842         hist->Fit("pol0", "0", "", 1.2, 1.6);
3843       */
3844       //tsallis = new TF1("tsallis", "(1-[1]*(1-[0])*x*x)**(1/(1-[0]))", 0, 10)
3845       // (1-b(1-q)x*x)**(1/(1-q))
3846       
3847       // combination of two tsallis functions
3848       total = new TF1("total", "[0] + [1] * (1-[3]*(1-[2])*x*x)**(1/(1-[2])) + [4] * (1-[6]*(1-[5])*(x-TMath::Pi())*(x-TMath::Pi()))**(1/(1-[5]))", -0.5 * TMath::Pi(), 1.5 * TMath::Pi());
3849       //total = new TF1("total", "[0] + [1] * (1-[3]*(1-[2])*x*x)**(1/(1-[2])) + [4] * (1-[6]*(1-[5])*(x-TMath::Pi())*(x-TMath::Pi()))**(1/(1-[5])) + [1] * (1-[3]*(1-[2])*(x-TMath::TwoPi())*(x-TMath::TwoPi()))**(1/(1-[2])) + [4] * (1-[6]*(1-[5])*(x+TMath::Pi())*(x+TMath::Pi()))**(1/(1-[5]))", -0.5 * TMath::Pi(), 1.5 * TMath::Pi());
3850       // the latter is the correct function, but a very wide tsallis on the away side can fake a baseline, and then the baseline is significantly off
3851       total->SetParLimits(0, 0, 10000);
3852       total->SetParLimits(1, 0, 10000);
3853       total->SetParLimits(4, 0, 10000);
3854       
3855       total->SetParLimits(2, 1.0000001, 5);
3856       total->SetParLimits(5, 1.0000001, 5);
3857       
3858       total->SetParLimits(3, 0.1, 1000);
3859       total->SetParLimits(6, 0.1, 1000);
3860       
3861       total->SetParameters(1, 1, 1.5, 3, 1, 1.5, 1.1);
3862       
3863       // limit q>1
3864       hist->Fit(total, "0RI");
3865       fitResult = hist->Fit(total, "0RSI");
3866       
3867       if (0 && fitResult->CovMatrixStatus() > 0)
3868       {
3869         TMatrixDSym cov(fitResult->GetCovarianceMatrix());
3870         cov.Print();
3871         
3872         Double_t nearSideYield, nearSideError;
3873         TsallisYieldUncertainty(total->GetParameter(1), total->GetParameter(2), total->GetParameter(3), cov, 0, nearSideYield, nearSideError);
3874         
3875         Double_t awaySideYield2, awaySideError;
3876         TsallisYieldUncertainty(total->GetParameter(4), total->GetParameter(5), total->GetParameter(6), cov, 3, awaySideYield2, awaySideError);
3877         
3878         FillYield(trigId, centralityId, ptACenter, ptAWidth, 14 + caseOffset + 1, nearSideYield, nearSideError, awaySideYield2, awaySideError);
3879         
3880         Printf("Chi2 %f / ndf %d = %f", total->GetChisquare(), total->GetNDF(), (total->GetNDF() > 0) ? total->GetChisquare() / total->GetNDF() : -1);
3881         
3882         total->SetLineColor(hist->GetLineColor());
3883         total->SetLineWidth(1);
3884         if (caseOffset == 2)
3885         {
3886           if (0)
3887             total->DrawCopy("SAME");
3888           //total->SetParameter(5, total->GetParameter(5) - TMath::Sqrt(cov[5][5]));
3889           //total->DrawCopy("SAME");
3890           //total->SetParameter(5, total->GetParameter(5) + 2 * TMath::Sqrt(cov[5][5]));
3891           //Printf("%f", total->Integral(-0.7,0.7));
3892           //total->DrawCopy("SAME");
3893         }
3894         
3895         if (caseOffset == 0)
3896         {
3897           // store fit parameters
3898           
3899           // q
3900           FillYield(trigId, centralityId, ptACenter, ptAWidth, 28, total->GetParameter(2), total->GetParError(2), total->GetParameter(5), total->GetParError(5));
3901           // beta
3902           FillYield(trigId, centralityId, ptACenter, ptAWidth, 29, total->GetParameter(3), total->GetParError(3), total->GetParameter(6), total->GetParError(6));
3903           
3904           if (0)
3905           {
3906             // two Gauss fits
3907             gausFit = new TF1("gausFit", "[0] + gaus(1) + gaus(4)", -0.5 * TMath::Pi(), 1.5 * TMath::Pi());
3908             gausFit->SetParameters(1, 1, 0, 1, 1, TMath::Pi(), 0);
3909             gausFit->SetParLimits(0, 0, 10000);
3910             gausFit->SetParLimits(1, 0, 10000);
3911             gausFit->FixParameter(2, 0);
3912             gausFit->SetParLimits(3, 0.01, 10);
3913             gausFit->SetParLimits(4, 0, 10000);
3914             gausFit->FixParameter(5, TMath::Pi());
3915             gausFit->SetParLimits(6, 0.01, 10);
3916             
3917             hist->Fit(gausFit, "0RI");
3918             gausFit->SetLineWidth(1);
3919             gausFit->DrawCopy("SAME");
3920           
3921             FillYield(trigId, centralityId, ptACenter, ptAWidth, 30, gausFit->GetParameter(3), total->GetParError(3), total->GetParameter(6), total->GetParError(6));
3922           }
3923         }
3924         
3925         if (0 && cov[0][0] > 0)
3926         {
3927           for (Int_t i=0; i<cov.GetNcols(); i++)
3928             for (Int_t j=0; j<cov.GetNrows(); j++)
3929               cov[j][i] /= TMath::Sqrt(cov[i][i]) * TMath::Sqrt(cov[j][j]);
3930           cov.Print();
3931         }
3932       }
3933       
3934       func = total;
3935       Float_t norm = func->GetParameter(0) / (1 - 2 * v2);
3936       Double_t normUnc = func->GetParError(0) / (1 - 2 * v2);
3937       //return;
3938     }
3939     else if (baseLineDetermination <= 2)
3940     {
3941       Float_t values[3];
3942       Float_t errors[3];
3943       
3944       if (baseLineDetermination == 1)
3945       {
3946         Float_t regionBegin[3] = { -TMath::Pi() / 2,        TMath::Pi() / 2 - 0.4, 1.5 * TMath::Pi() - 0.4 };
3947         Float_t regionEnd[3] =   { -TMath::Pi() / 2 + 0.4,  TMath::Pi() / 2 + 0.4, 1.5 * TMath::Pi() };
3948       }
3949       else if (baseLineDetermination == 2)
3950       {
3951         Float_t regionBegin[3] = { -TMath::Pi() / 2,              TMath::Pi() / 2 - 0.4 - 0.2, 1.5 * TMath::Pi() - 0.4 - 0.2};
3952         Float_t regionEnd[3] =   { -TMath::Pi() / 2 + 0.4 - 0.2,  TMath::Pi() / 2 + 0.4 - 0.2, 1.5 * TMath::Pi() };
3953       }
3954         
3955       // weighted mean
3956       Float_t sum = 0;
3957       Float_t weight = 0;
3958       for (Int_t i=0; i<3; i++)
3959       {
3960         hist->Fit("pol0", "0Q", "", regionBegin[i], regionEnd[i]);
3961         func = hist->GetFunction("pol0");
3962         if (!func)
3963           continue;
3964         sum += func->GetParameter(0) / func->GetParError(0) / func->GetParError(0);
3965         weight += 1. / func->GetParError(0) / func->GetParError(0);
3966       }
3967       
3968       if (weight == 0)
3969         return;
3970       
3971       sum /= weight;
3972       weight = TMath::Sqrt(1. / weight);
3973       
3974       Float_t norm = sum / (1 - 2 * v2);
3975       Double_t normUnc = weight / (1 - 2 * v2);
3976     }
3977     else
3978     {
3979       Int_t bins = 2;
3980       if (baseLineDetermination == 4)
3981         bins = 4;
3982       if (baseLineDetermination == 5)
3983         bins = 8;
3984       Float_t norm = NLowestBinAverage(*hist, bins);
3985       Double_t normUnc = 0;
3986       
3987       Printf("NLowestBinAverage %d --> %f", bins, norm);
3988       
3989       norm /= (1 - 2 * v2);
3990     }
3991     
3992     Printf("Baseline: %f +- %f", norm, normUnc);
3993   }
3994   
3995   if (caseOffset == 0)
3996   {
3997     Float_t awaySideYieldNoBaseline = awaySideYield - norm * (1 - 2 * v2);
3998     Float_t v2YieldNoBaseline = norm * 2 * v2 * (1 + 1.4) / 1.4;
3999     Printf("Relative v2 contribution at centrality = %d, pT,t = %.1f, pT,a = %.1f: %.1f%% (%f %f)", centralityId, ptT, ptA, 100.0 * v2YieldNoBaseline / awaySideYieldNoBaseline, awaySideYieldNoBaseline, v2YieldNoBaseline);
4000   }
4001
4002   //flowFunc->SetParameters(hist->GetBinContent(hist->FindBin(1.4)) / (1.0 - 2.0 * v2), v2);
4003   flowFunc->SetParameters(norm, v2);
4004   flowFunc->SetLineWidth(1);
4005   if (caseOffset >= 4 && caseOffset <= 9 && caseOffset != 6)
4006     flowFunc->DrawCopy("SAME"); //->SetLineColor(caseOffset - 3);
4007   
4008   hist->Add(flowFunc, -1);
4009   if (caseOffset == 0)
4010   {
4011     file = TFile::Open("dphi_corr.root", "UPDATE");
4012     hist->SetName(TString(hist->GetName()) + "_tsallis_v2");
4013     hist->Write();
4014     file->Close();
4015     //  hist->DrawCopy("SAME");
4016   }
4017   if (caseOffset == 2 && flatBaseLine)
4018   {
4019     file = TFile::Open("dphi_corr.root", "UPDATE");
4020     hist->SetName(TString(hist->GetName()) + "_tsallis_flat");
4021     hist->Write();
4022     file->Close();
4023     //  hist->DrawCopy("SAME");
4024   }
4025   if (caseOffset == 4 && flatBaseLine)
4026   {
4027     file = TFile::Open("dphi_corr.root", "UPDATE");
4028     hist->SetName(TString(hist->GetName()) + "_fit_flat");
4029     hist->Write();
4030     file->Close();
4031     //  hist->DrawCopy("SAME");
4032   }
4033   
4034   ExtractYields(hist, trigId, centralityId, ptACenter, ptAWidth, 14 + caseOffset, normUnc);
4035   
4036   if (0 && histMixed)
4037   {
4038     Printf("%f", histMixed->Integral() / histMixed->GetNbinsX());
4039     flowFunc->SetParameters(histMixed->Integral() / histMixed->GetNbinsX(), v2);
4040     flowFunc->SetLineColor(2);
4041     //if (caseOffset == 0)
4042     //  flowFunc->DrawCopy("SAME");
4043   }
4044 }
4045
4046 void RemoveBaseLine(TH1* hist)
4047 {
4048   if (!hist)
4049     return;
4050     
4051   //hist->Rebin(2);
4052   //hist->Scale(0.5);
4053
4054   hist->Fit("pol0", "0", "", 1.07, 2.07);
4055   
4056   if (!hist->GetFunction("pol0"))
4057     return;
4058   
4059   Float_t zyam = hist->GetFunction("pol0")->GetParameter(0);
4060   
4061   if (zyam <= 0)
4062     return;
4063     
4064   return;
4065   
4066   for (Int_t i=1; i<=hist->GetNbinsX(); i++)
4067     hist->SetBinContent(i, hist->GetBinContent(i) - zyam);
4068 }
4069  
4070 Int_t gHistCount = 0;
4071 void GetDistAndFlow(void* hVoid, void* hMixedVoid, TH1** hist, Float_t& v2, Int_t step, Int_t centralityBegin, Int_t centralityEnd, Float_t ptBegin, Float_t ptEnd, Int_t twoD = 0)
4072 {
4073   h = (AliUEHistograms*) hVoid;
4074   hMixed = (AliUEHistograms*) hMixedVoid;
4075
4076   *hist = h->GetUEHist(2)->GetUEHist(step, 0, ptBegin, ptEnd, h->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->FindBin(0.01 + centralityBegin), h->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->FindBin(-0.01 + centralityEnd), twoD);
4077   
4078   *hist = (TH1*) (*hist)->Clone(Form("GetDistAndFlow_%d", gHistCount++));
4079   
4080   TString str;
4081   str.Form("%.1f < p_{T,trig} < %.1f", ptBegin - 0.01, ptEnd + 0.01);
4082   
4083   TString str2;
4084   str2.Form("%.1f < p_{T,assoc} < %.1f", gpTMin - 0.01, gpTMax + 0.01);
4085     
4086   TString newTitle;
4087   newTitle.Form("%s - %s - %d-%d%%", str.Data(), str2.Data(), centralityBegin, centralityEnd);
4088   (*hist)->SetTitle(newTitle);
4089   
4090   if (hMixed)
4091   {
4092     histMixed = hMixed->GetUEHist(2)->GetUEHist(step, 0, ptBegin, ptEnd, hMixed->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->FindBin(0.01 + centralityBegin), hMixed->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->FindBin(-0.01 + centralityEnd));
4093     
4094     //new TCanvas; (*hist)->DrawCopy(); histMixed->DrawCopy("SAME")->SetLineColor(2);
4095     
4096     Float_t totalPairs = (*hist)->Integral();
4097     
4098     (*hist)->Divide(histMixed);
4099     (*hist)->Scale(totalPairs / (*hist)->Integral());
4100     
4101     //(*hist)->DrawCopy("SAME")->SetLineColor(4);
4102   }
4103   
4104   // calculate v2trigger
4105   h->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->SetRangeUser(0.01 + centralityBegin, -0.01 + centralityEnd);
4106   ptDist = h->GetUEHist(2)->GetEventHist()->Project(step, 0);
4107   Float_t v2Trig = CalculateFlow(ptDist, ptBegin, ptEnd, 2, centralityBegin, centralityEnd);
4108   delete ptDist;
4109   
4110   // calculate v2 assoc
4111   cont = h->GetUEHist(2)->GetTrackHist(0);
4112   h->GetUEHist(2)->GetTrackHist(0)->GetGrid(step)->GetGrid()->GetAxis(3)->SetRangeUser(0.01 + centralityBegin, -0.01 + centralityEnd);
4113   h->GetUEHist(2)->GetTrackHist(0)->GetGrid(step)->GetGrid()->GetAxis(2)->SetRangeUser(ptBegin, ptEnd);
4114   ptDist = h->GetUEHist(2)->GetTrackHist(0)->Project(step, 1);
4115   Float_t v2Assoc = CalculateFlow(ptDist, gpTMin, gpTMax, 2, centralityBegin, centralityEnd);
4116   delete ptDist;
4117   
4118   v2 = v2Trig * v2Assoc;
4119 }
4120  
4121 void PlotDeltaPhiDistributions(const char* fileName1, const char* fileName2, Float_t yMax = 0.1, Int_t twoD = 0, Int_t centrBegin = 1, Int_t centrEnd = 1)
4122 {
4123   loadlibs();
4124   
4125   Bool_t veryCentral = 0;
4126   Bool_t flowComparison = 0;
4127   Bool_t rhicOverlay = 0;
4128   Bool_t highStatBinning = 1;
4129
4130   file = TFile::Open("dphi_corr.root", "RECREATE");
4131   file->Close();
4132   
4133    Int_t leadingPtOffset = 1;
4134     
4135   if (veryCentral || flowComparison)
4136   {
4137     Int_t maxLeadingPt = 2;
4138     Int_t maxAssocPt = 2;
4139     Float_t leadingPtArr[] = { 2.0, 3.0, 4.0, 10.0, 20.0, 40.0 };
4140     //Float_t assocPtArr[] =   { 0.15, 0.5, 1.0, 2.0, 4.0, 6.0, 10.0, 20.0, 40.0 };
4141     Float_t assocPtArr[] =   { 1.0, 2.0, 3.0, 6.0, 10.0, 20.0, 40.0 };
4142   }
4143   else if (rhicOverlay) // RHIC binning
4144   {
4145     Int_t maxLeadingPt = 4;
4146     Int_t maxAssocPt = 5;
4147     Float_t leadingPtArr[] =   { 4.0, 5.0, 7.0, 9.0, 12.0 };
4148     Float_t assocPtArr[] =     { 0.5, 1.0, 2.0, 3.0, 5.0, 7.0 };
4149   }
4150   else if (highStatBinning) 
4151   {
4152     Int_t maxLeadingPt = 3;
4153     Int_t maxAssocPt = 2;
4154     Float_t leadingPtArr[] = { 4.0, 6.0, 8.0, 15.0 };
4155     Float_t assocPtArr[] =   { 1.0, 4.0, 10.0 };
4156   }
4157   else // ALICE binning
4158   {
4159     if (1)
4160     {
4161       Int_t maxLeadingPt = 3;
4162       Int_t maxAssocPt = 7;
4163 //       Float_t leadingPtArr[] = { 6.0, 8.0, 10.0, 10.0, 15.0 };
4164       Float_t leadingPtArr[] = { 6.0, 8.0, 10.0, 15.0, 15.0 };
4165       Float_t assocPtArr[] =     { 0.5, 1.5, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
4166       leadingPtOffset = 2;
4167     }
4168     else
4169     {
4170       Int_t maxLeadingPt = 1;
4171       Int_t maxAssocPt = 4;
4172       Float_t leadingPtArr[] = { 8.0, 10.0, 15.0, 15.0 };
4173       Float_t assocPtArr[] =     { 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
4174       leadingPtOffset = 2;
4175     }
4176   }
4177   
4178   Int_t nCentralityBins = 5;
4179   Int_t centralityBins[] = { 1, 7, 9, 11, 13, 16 };
4180   //Int_t centralityBins[] = { 1, 3, 5, 7, 9, 13 };
4181   
4182   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName1);
4183   AliUEHistograms* hMixed = 0;
4184   if (twoD)
4185     hMixed = (AliUEHistograms*) GetUEHistogram(fileName1, 0, kTRUE);
4186     
4187   AliUEHistograms* h2 = 0;
4188   if (!twoD)
4189     h2 = (AliUEHistograms*) GetUEHistogram(fileName2);
4190   
4191   TCanvas* canvas = new TCanvas("DeltaPhi", "DeltaPhi", 1000, 700);
4192   canvas->Divide(maxAssocPt, maxLeadingPt);
4193   
4194   TCanvas* canvas2 = new TCanvas("Centrality", "Centrality", 800, 600);
4195   centralityHist = (TH1*) h->GetCentralityDistribution();
4196   NormalizeToBinWidth(centralityHist);
4197   centralityHist->Draw();
4198   gPad->SetLogy();
4199   
4200   TLegend* legend = new TLegend(0.2, 0.5, 0.95, 0.90);
4201   TLegend* legend2 = new TLegend(0.5, 0.63, 0.95, 0.90);
4202   legend2->SetFillColor(0);
4203   legend2->SetTextSize(0.04);
4204   
4205   for (Int_t i=0; i<maxLeadingPt; i++)
4206     for (Int_t j=0; j<maxAssocPt; j++)
4207     {
4208       TString str;
4209       str.Form("%.1f < p_{T,trig} < %.1f", leadingPtArr[i], leadingPtArr[i+leadingPtOffset]);
4210       
4211       if (j == 0)
4212       {
4213         canvas2->cd();
4214         h->GetUEHist(2)->GetEventHist()->GetGrid(6)->SetRangeUser(0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01);
4215         centralityHist = h->GetUEHist(2)->GetEventHist()->ShowProjection(1, 6);
4216         centralityHist->SetLineColor(i+2);
4217         NormalizeToBinWidth(centralityHist);
4218         centralityHist->DrawCopy("SAME");
4219         h->GetUEHist(2)->GetEventHist()->GetGrid(6)->SetRangeUser(0, 0, -1);
4220         legend2->AddEntry(centralityHist, str);
4221       }
4222     
4223       canvas->cd(j+1 + i * maxAssocPt);
4224       gPad->SetLeftMargin(0.15);
4225       gPad->SetBottomMargin(0.2);
4226       gPad->SetTopMargin(0.01);
4227       gPad->SetRightMargin(0.01);
4228       
4229       if (i == 0 && j == 3)
4230         legend->Draw();
4231       
4232       gpTMin = assocPtArr[j] + 0.01;
4233       gpTMax = assocPtArr[j+1] - 0.01;
4234       
4235       TString str2;
4236       str2.Form("%.1f < p_{T,assoc} < %.1f", gpTMin - 0.01, gpTMax + 0.01);
4237       
4238       SetupRanges(h);
4239       // for HI file do not set range in eta anymore after it was changed to delta eta axis
4240       h->SetEtaRange(0, 0);
4241
4242       if (h2)
4243       {
4244         SetupRanges(h2); // SetEtaRange(0, 0) does not need to be called for the leading track result
4245         h2->SetEtaRange(0, 0);
4246       }
4247       
4248       if (hMixed)
4249       {
4250         SetupRanges(hMixed);
4251         hMixed->SetEtaRange(0, 0);
4252       }
4253       
4254       // delta phi
4255       if (!twoD)
4256       {
4257         if (assocPtArr[j] >= leadingPtArr[i+leadingPtOffset])
4258           continue;
4259     
4260         // 0-5% --> 1, 5
4261         // 0-10% --> 1, 6
4262         // 0-20% --> 1, 8
4263         // 20-40% --> 9, 10
4264         // 40-80% --> 11, 14
4265         // > 40% --> 11, 16
4266         
4267         TString hist1Str, hist2Str, hist2bStr;
4268         
4269         Float_t v2[3];
4270         for (Int_t k=0; k<3; k++)
4271           v2[k] = 0;
4272         
4273         if (veryCentral)
4274         {
4275           Int_t step = 6;
4276           TH1* hist1 = h->GetUEHist(2)->GetUEHist(step, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 1, 2);  hist1Str = "0-2%";
4277           TH1* hist2 = h->GetUEHist(2)->GetUEHist(step, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 2, 3);  hist2Str = "2-3%";
4278           TH1* hist2b = h->GetUEHist(2)->GetUEHist(step, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 10, 10); hist2bStr = "30-40%";
4279           TH1* hist3 = 0; // h2->GetUEHist(2)->GetUEHist(0, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01);
4280         }
4281         else if (flowComparison)
4282         {
4283           TH1* hist1 = h->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 1, 5);  hist1Str = "0-5%";
4284           TH1* hist2 = h->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 9, 10);  hist2Str = "20-40%";
4285           TH1* hist2b = h->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 10, 10); hist2bStr = "30-40%";
4286           TH1* hist3 = 0; // h2->GetUEHist(2)->GetUEHist(0, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01);
4287         }
4288         else if (rhicOverlay)
4289         {
4290           TH1* hist1 = h->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 1, 8);   hist1Str = "0-20%";
4291           TH1* hist2 = h->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 9, 12);  hist2Str = "20-60%";
4292           TH1* hist2b = h->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 13, 15);hist2bStr = "60-90%";
4293           TH1* hist3 = h2->GetUEHist(2)->GetUEHist(0, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01);
4294         }
4295         else
4296         {
4297           Int_t step = 6;
4298           TH1* hist1 = 0;
4299           TH1* hist2 = 0;
4300           TH1* hist2b = 0;
4301           GetDistAndFlow(h, hMixed, &hist1,  v2[0], step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01); hist1Str = "0-5%";
4302           GetDistAndFlow(h, hMixed, &hist2,  v2[1], step, 0, 20, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01); hist2Str = "0-20%";
4303 //           GetDistAndFlow(h, hMixed, &hist2b, v2[2], step, 60, 80, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01); hist2bStr = "60-80%";
4304           GetDistAndFlow(h, hMixed, &hist2b, v2[2], step, 60, 90, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01); hist2bStr = "60-90%";
4305           
4306           Printf("%f %f %f", v2[0], v2[1], v2[2]);
4307           
4308 //           TH1* hist1 = h->GetUEHist(2)->GetUEHist(step, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 1, 8);    hist1Str = "0-20%";
4309 //           TH1* hist2 = h->GetUEHist(2)->GetUEHist(step, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 9, 12);   hist2Str = "20-60%";
4310 //           TH1* hist2b = h->GetUEHist(2)->GetUEHist(step, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 13, 15); hist2bStr = "60-90%";
4311           
4312           step = 6;
4313           TH1* hist3 = h2->GetUEHist(2)->GetUEHist(step, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01);
4314         }
4315         
4316         /*
4317         RemoveBaseLine(hist1);
4318         RemoveBaseLine(hist2);
4319         RemoveBaseLine(hist2b);
4320         RemoveBaseLine(hist3);
4321         */
4322         
4323         TString newTitle;
4324         newTitle.Form("%s - %s", str.Data(), str2.Data());
4325         if (hist1)
4326         {
4327           hist1->SetName(Form("dphi_%d_%d_%d", i, j, 0));
4328           hist1->SetTitle(newTitle + " - " + hist1Str);
4329         }
4330         if (hist2)
4331         {
4332           hist2->SetName(Form("dphi_%d_%d_%d", i, j, 1));
4333           hist2->SetTitle(newTitle + " - " + hist2Str);
4334         }
4335         if (hist2b)
4336         {
4337           hist2b->SetName(Form("dphi_%d_%d_%d", i, j, 2));
4338           hist2b->SetTitle(newTitle + " - " + hist2bStr);
4339         }
4340         if (hist3)
4341         {
4342           hist3->SetName(Form("dphi_%d_%d_%d", i, j, 3));
4343           hist3->SetTitle(newTitle + " - pp");
4344         }
4345         
4346         if (0)
4347         {
4348           hist1->Scale(1.0 / hist1->Integral());
4349           hist2->Scale(1.0 / hist2->Integral());
4350           hist3->Scale(1.0 / hist3->Integral());
4351         }
4352       
4353         if (i == 0 && j == 0)
4354         {
4355           legend->SetFillColor(0);
4356           legend->AddEntry(hist1, "Pb+Pb 0-5%");
4357           if (hist2)
4358             legend->AddEntry(hist2, "Pb+Pb 20-40%");
4359           if (hist2b)
4360             legend->AddEntry(hist2b, "Pb+Pb 60-90%");
4361           if (hist3)
4362             legend->AddEntry(hist3, "p+p 7 TeV");
4363           legend->SetTextSize(0.08);
4364         }
4365       
4366         Prepare1DPlot(hist1);
4367         Prepare1DPlot(hist2);
4368         Prepare1DPlot(hist2b);
4369         Prepare1DPlot(hist3);
4370         
4371         Double_t yMin = 0.01;
4372         Double_t yMax2 = yMax;
4373         
4374         if (yMax < 0)
4375         {
4376           yMin = -0.01; //TMath::Min(hist1->GetMinimum(), hist2->GetMinimum()) * 0.97;
4377           yMax2 = TMath::Max((hist3) ? hist3->GetMaximum() : 0.0, TMath::Max(hist1->GetMaximum(), (hist2) ? hist2->GetMaximum() : 0.0)) * 1.03;
4378         }
4379         
4380         yMax2 *= 1.4;
4381       
4382         TH2F* dummy = new TH2F("dummy", "", 100, hist1->GetXaxis()->GetBinLowEdge(1), hist1->GetXaxis()->GetBinUpEdge(hist1->GetNbinsX()), 1000, yMin, yMax2); //TMath::Max(hist1->GetMaximum(), hist2->GetMaximum()) * 1.1);
4383         dummy->SetStats(kFALSE);
4384         dummy->SetXTitle(hist1->GetXaxis()->GetTitle());
4385         dummy->SetYTitle(hist1->GetYaxis()->GetTitle());
4386         dummy->SetYTitle("1/N_{trig} dN/d#Delta#phi"); 
4387         Prepare1DPlot(dummy);
4388         
4389         dummy->GetYaxis()->SetTitleOffset(0.8);
4390       
4391         dummy->GetXaxis()->SetLabelSize(0.08);
4392         dummy->GetYaxis()->SetLabelSize(0.08);
4393         dummy->GetXaxis()->SetTitleSize(0.08);
4394         dummy->GetYaxis()->SetTitleSize(0.08);
4395         /*
4396         dummy->GetYaxis()->SetTitleOffset(0.8);
4397         */
4398         
4399         dummyTmp = dummy->DrawCopy();
4400         
4401         hist1->DrawCopy("SAME");
4402         
4403         if (hMixed)
4404         {
4405           SetupRanges(hMixed);
4406           // for HI file do not set range in eta anymore after it was changed to delta eta axis
4407           hMixed->SetEtaRange(0, 0);
4408         }
4409         TH1* hist1Mixed = 0; //hMixed->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 1, 5);
4410         DrawFlow(v2[0], hist1, leadingPtArr[i], assocPtArr[j], hist1Mixed, i, 0, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
4411         
4412         //hist1Mixed->Draw("SAME");
4413         if (hist2)
4414         {
4415           hist2->SetLineColor(2);
4416           hist2->DrawCopy("SAME");
4417           
4418           TH1* hist2Mixed = 0; //hMixed->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 9, 10);
4419           //hist2Mixed->SetLineColor(2);
4420           //hist2Mixed->Draw("SAME");
4421
4422           DrawFlow(v2[1], hist2, leadingPtArr[i], assocPtArr[j], hist2Mixed, i, 1, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
4423           //DrawFlow(GetFlow05(), hist2, leadingPtArr[i], assocPtArr[j], hist2Mixed);
4424         }
4425         if (hist2b)
4426         {
4427           hist2b->SetLineColor(3);
4428           hist2b->DrawCopy("SAME");
4429         
4430           TH1* hist2bMixed = 0; //hMixed->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 13, 15);
4431           DrawFlow(v2[2], hist2b, leadingPtArr[i], assocPtArr[j], hist2bMixed, i, 2, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
4432           //DrawFlow(GetFlow05(), hist2b, leadingPtArr[i], assocPtArr[j], hist2bMixed);
4433         }
4434         if (hist3)
4435         {
4436           hist3->SetLineColor(4);
4437           hist3->DrawCopy("SAME");
4438           
4439           DrawFlow(0, hist3, leadingPtArr[i], assocPtArr[j], 0, i, 3, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
4440         }
4441         //dummyTmp->GetYaxis()->SetRangeUser(0, 1.1 * TMath::Max(TMath::Max(hist1->GetMaximum(), hist2->GetMaximum()), hist2b->GetMaximum()));
4442       }
4443       else // delta eta delta phi
4444       {
4445         if (twoD == 1)
4446         {
4447           if (assocPtArr[j] > leadingPtArr[i])
4448             continue;
4449         }
4450         else
4451         {
4452           Int_t jRef = 1;
4453         
4454           if (assocPtArr[jRef] > leadingPtArr[i])
4455             continue;
4456           
4457           // fix pt assoc
4458           gpTMin = assocPtArr[jRef] + 0.01;
4459           gpTMax = assocPtArr[jRef+1] - 0.01;
4460           
4461           str2.Form("%.1f < p_{T,assoc} < %.1f", gpTMin - 0.01, gpTMax + 0.01);
4462       
4463           // use j for centrality
4464           if (j >= nCentralityBins)
4465             continue;
4466             
4467           centrBegin = centralityBins[j];
4468           centrEnd = centralityBins[j+1] - 1;
4469         }
4470         
4471         SetupRanges(h);
4472         // for HI file do not set range in eta anymore after it was changed to delta eta axis
4473         h->SetEtaRange(0, 0);
4474         
4475         SetupRanges(hMixed);
4476         // for HI file do not set range in eta anymore after it was changed to delta eta axis
4477         hMixed->SetEtaRange(0, 0);
4478           
4479         TH2* histSame = (TH2*) h->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, centrBegin, centrEnd, kTRUE);
4480         TH2* histMixed = (TH2*) hMixed->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, centrBegin, centrEnd, kTRUE);
4481         
4482         // rebin 
4483         histSame->Rebin2D(2, 2);
4484         histMixed->Rebin2D(2, 2);
4485         
4486         if (1)
4487         {
4488           // fit delta eta, assuming no dependence on dphi
4489           
4490           //new TCanvas; histMixed->DrawCopy("SURF1");
4491           
4492           histMixedproj = histMixed->ProjectionY();
4493           histMixedproj->Scale(1.0 / histMixed->GetNbinsX());
4494           
4495           for (Int_t x=1; x<=histMixed->GetNbinsX(); x++)
4496             for (Int_t y=1; y<=histMixed->GetNbinsY(); y++)
4497               histMixed->SetBinContent(x, y, histMixedproj->GetBinContent(y));
4498           
4499           //new TCanvas; histMixed->DrawCopy("SURF1");
4500         }
4501         
4502         histSame->SetStats(0);
4503         histSame->GetYaxis()->SetRangeUser(-1.5, 1.5);
4504         histSame->SetTitle("");
4505         histSame->Divide(histMixed);
4506         histSame->DrawCopy("SURF1");
4507         
4508         TString str3;
4509         str3.Form("%d-%d%%", (Int_t) h->GetCentralityDistribution()->GetXaxis()->GetBinLowEdge(centrBegin), (Int_t) h->GetCentralityDistribution()->GetXaxis()->GetBinUpEdge(centrEnd));
4510         latex = new TLatex(0.15, 0.95, str3);
4511         latex->SetNDC();
4512         latex->SetTextSize(0.08);
4513         latex->Draw();
4514       }
4515       
4516       latex = new TLatex(0.55, 0.8, str);
4517       latex->SetNDC();
4518       latex->SetTextSize(0.06);
4519       latex->Draw();
4520       
4521       latex = new TLatex(0.55, 0.88, str2);
4522       latex->SetNDC();
4523       latex->SetTextSize(0.06);
4524       latex->Draw();
4525       
4526 //            if (i == 0)        return;
4527     }
4528
4529   canvas->SaveAs(Form("DeltaPhi_%.2f.png", yMax));
4530   
4531   canvas2->cd();
4532   legend2->Draw();
4533
4534   //TString name;
4535   //name.Form("%s_%.2f_%.2f_%.2f_%.2f.png", TString(gSystem->BaseName(fileName1)).Tokenize(".")->First()->GetName(), leadingPtArr[i], leadingPtArr[i+1], assocPtArr[j], assocPtArr[j+1]);
4536 }
4537   
4538 void PlotPtDistributions(const char* fileName1, Int_t centrBegin = 1, Int_t centrEnd = 2)
4539 {
4540   loadlibs();
4541
4542   Int_t maxLeadingPt = 3;
4543   Float_t leadingPtArr[] = { 1.0, 10.0, 20.0, 40.0 };
4544   
4545   Int_t nCentralityBins = 5;
4546   Int_t centralityBins[] = { 1, 7, 9, 11, 13, 16 };
4547   
4548   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName1);
4549     
4550   TCanvas* canvas = new TCanvas("Pt", "Pt", 1000, 1000);
4551   canvas->Divide(2, maxLeadingPt+2);
4552   
4553   TLegend* legend = new TLegend(0.2, 0.2, 0.95, 0.90);
4554   legend->SetFillColor(0);
4555   legend->SetTextSize(0.08);
4556   
4557   TLegend* legendB = new TLegend(0.2, 0.2, 0.95, 0.90);
4558   legendB->SetFillColor(0);
4559   legendB->SetTextSize(0.08);
4560   
4561   TLegend* legend2 = new TLegend(0.2, 0.2, 0.95, 0.90);
4562   legend2->SetFillColor(0);
4563   legend2->SetTextSize(0.08);
4564   
4565   Int_t colors[] = { 1, 2, 4, 6 };
4566   Int_t markers[] = { 20, 21, 22, 23, 24, 25 };
4567   
4568   for (Int_t i=0; i<maxLeadingPt; i++)
4569   {
4570     Double_t ptMin = leadingPtArr[i] + 0.01;
4571     //Double_t ptMax = leadingPtArr[i+1] - 0.01;
4572     Double_t ptMax = 39.99;
4573       
4574     TString str;
4575     str.Form("%.1f < p_{T,trig} < %.1f", ptMin - 0.01, ptMax + 0.01);
4576     
4577     canvas->cd(2*i+1+2);
4578     gPad->SetLeftMargin(0.15);
4579     gPad->SetBottomMargin(0.2);
4580     gPad->SetTopMargin(0.01);
4581     gPad->SetRightMargin(0.01);
4582     gPad->SetLogy();
4583     gPad->SetLogx();
4584     gPad->SetGridx();
4585     gPad->SetGridy();
4586     
4587     TH2F* dummy = new TH2F("dummy", "", 100, 1, 40, 100, 1e-5, 1e3);
4588     dummy->SetStats(kFALSE);
4589     dummy->SetXTitle("p_{T,assoc}");
4590     dummy->SetYTitle("");
4591     dummy->GetYaxis()->SetTitleOffset(1);
4592     Prepare1DPlot(dummy);
4593   
4594     dummy->GetXaxis()->SetLabelSize(0.06);
4595     dummy->GetYaxis()->SetLabelSize(0.06);
4596     dummy->GetXaxis()->SetTitleSize(0.06);
4597     dummy->GetYaxis()->SetTitleSize(0.06);
4598     dummy->DrawCopy();
4599     
4600     Float_t phiRange[] = { 0, TMath::Pi() / 2, TMath::Pi() };
4601     const char* phiLabels[] = { "Towards", "Transverse", "Away" };
4602     
4603     for (Int_t j=0; j<3; j++)
4604     {
4605       TH1* centralEta = 0;
4606       TH1* sideEta1 = 0;
4607       
4608       if (j == 0)
4609       {
4610         centralEta = h->GetUEHist(2)->GetPtHist(6, 0, ptMin, ptMax, centrBegin, centrEnd, phiRange[j] - TMath::Pi() / 4, phiRange[j] + TMath::Pi() / 4, -0.69, 0.69);
4611         sideEta1 = h->GetUEHist(2)->GetPtHist(6, 0, ptMin, ptMax, centrBegin, centrEnd, phiRange[j] - TMath::Pi() / 4, phiRange[j] + TMath::Pi() / 4, -1.39, -0.71);
4612         TH1* sideEta2 = h->GetUEHist(2)->GetPtHist(6, 0, ptMin, ptMax, centrBegin, centrEnd, phiRange[j] - TMath::Pi() / 4, phiRange[j] + TMath::Pi() / 4, 0.71, 1.39);
4613         sideEta1->Add(sideEta2); // TODO can be done smarter? what about the errors?
4614       
4615         Prepare1DPlot(sideEta1);
4616         Prepare1DPlot(centralEta);
4617         
4618         centralEta->SetLineColor(colors[j]);
4619         sideEta1->SetLineColor(colors[j+1]);
4620       
4621         if (i == 0)
4622         {
4623           legend->AddEntry(centralEta->Clone(), Form("Jet, %s: |#eta| < 0.7, #phi ~ %.1f", phiLabels[j], phiRange[j]));
4624           legend->AddEntry(sideEta1->Clone(), Form("Ridge, %s: 0.7 < |#eta| < 1.4, #phi ~ %.1f", phiLabels[j], phiRange[j]));
4625         }
4626       }
4627       else
4628       {
4629         centralEta = h->GetUEHist(2)->GetPtHist(6, 0, ptMin, ptMax, centrBegin, centrEnd, phiRange[j] - TMath::Pi() / 4, phiRange[j] + TMath::Pi() / 4, -1.39, 1.39);
4630         centralEta->Scale(0.5);
4631         centralEta->SetLineColor(colors[j+1]);
4632       
4633         Prepare1DPlot(centralEta);
4634         
4635         if (i == 0)
4636           legend->AddEntry(centralEta->Clone(), Form("%s: |#eta| < 1.4, #phi ~ %.1f", phiLabels[j], phiRange[j]));
4637       }
4638       
4639       canvas->cd(2*i+1+2);
4640       centralEta->DrawCopy("SAME");
4641       if (sideEta1)
4642         sideEta1->DrawCopy("SAME");
4643       
4644       centralEta->SetLineColor(colors[i]);
4645       centralEta->Scale(100.0 / centralEta->Integral());
4646       if (sideEta1)
4647       {
4648         sideEta1->SetLineColor(colors[i]);
4649         sideEta1->Scale(100.0 / sideEta1->Integral());
4650       }
4651     
4652       if (j < 2)
4653         canvas->cd(j*4+4);
4654       else
4655         canvas->cd(j*4+2);
4656       if (i == 0)
4657       {
4658         gPad->SetLeftMargin(0.15);
4659         gPad->SetBottomMargin(0.2);
4660         gPad->SetTopMargin(0.01);
4661         gPad->SetRightMargin(0.01);
4662         
4663         dummy->DrawCopy();
4664         
4665         gPad->SetLogy();
4666         gPad->SetLogx();
4667         gPad->SetGridx();
4668         gPad->SetGridy();
4669         
4670         TString str3;
4671         if (j == 0)
4672           str3.Form("Jet, %s: |#eta| < 0.7, #phi ~ %.1f", phiLabels[j], phiRange[j]);
4673         else
4674           str3.Form("%s: |#eta| < 1.4, #phi ~ %.1f", phiLabels[j], phiRange[j]);
4675         latex = new TLatex(0.2, 0.3, str3);
4676         latex->SetNDC();
4677         latex->SetTextSize(0.08);
4678         latex->Draw();
4679       }
4680       
4681       if (j == 0)
4682         legend2->AddEntry(centralEta->Clone(), str);
4683         
4684       centralEta->DrawCopy("SAME");
4685       
4686       if (sideEta1)
4687       {
4688         canvas->cd(j*4+4+2);
4689         if (i == 0)
4690         {
4691           gPad->SetLeftMargin(0.15);
4692           gPad->SetBottomMargin(0.2);
4693           gPad->SetTopMargin(0.01);
4694           gPad->SetRightMargin(0.01);
4695           
4696           dummy->DrawCopy();
4697           
4698           gPad->SetLogy();
4699           gPad->SetLogx();
4700           gPad->SetGridx();
4701           gPad->SetGridy();
4702           
4703           TString str3;
4704           if (j == 0)
4705             str3.Form("Ridge, %s: 0.7 < |#eta| < 1.4, #phi ~ %.1f", phiLabels[j], phiRange[j]);
4706           else
4707             str3.Form("%s: |#eta| < 1.4, #phi ~ %.1f", phiLabels[j], phiRange[j]);
4708           latex = new TLatex(0.2, 0.3, str3);
4709           latex->SetNDC();
4710           latex->SetTextSize(0.08);
4711           latex->Draw();
4712         }
4713         
4714         sideEta1->DrawCopy("SAME");
4715       }
4716     }
4717     
4718     TString str3;
4719     str3.Form("%d-%d%%", (Int_t) h->GetCentralityDistribution()->GetXaxis()->GetBinLowEdge(centrBegin), (Int_t) h->GetCentralityDistribution()->GetXaxis()->GetBinUpEdge(centrEnd));
4720     latex = new TLatex(0.2, 0.3, str3);
4721     latex->SetNDC();
4722     latex->SetTextSize(0.08);
4723     
4724     latex2 = new TLatex(0.55, 0.8, str);
4725     latex2->SetNDC();
4726     latex2->SetTextSize(0.06);
4727     
4728     canvas->cd(2*i+1+2);
4729     latex->Draw();
4730     latex2->Draw();
4731     
4732     //break;
4733   }
4734   
4735   canvas->cd(1);
4736   legend->Draw();
4737
4738   canvas->cd(2);
4739   legend2->Draw();
4740 }
4741
4742 TH1* GetNonSubtractedRHICYield(Int_t ptT, Int_t ptA, Int_t centrality)
4743 {
4744   rhicFile = TFile::Open("rhic/postcorr_AuAu_iter6_ppg106final.root");
4745   
4746   corrFunc = (TH1*) rhicFile->Get(Form("pi0hdphi_%d_%d_%d_2", ptT, ptA, centrality));
4747   //corrFunc->Draw();
4748   
4749   // integral
4750   corrFunc->Scale(1.0 / corrFunc->Integral());
4751   // bin width
4752   corrFunc->Scale(TMath::TwoPi() / corrFunc->GetBinWidth(1));
4753   
4754   same     = (TH1*) rhicFile->Get(Form("pi0hdphi_%d_%d_%d_0", ptT, ptA, centrality));
4755   Float_t nPairs = same->Integral();
4756   
4757   triggers = (TH1*) rhicFile->Get(Form("pi0pt_%d_%d", ptT, centrality));
4758   Float_t nTrigs = triggers->Integral();
4759   
4760   graph = (TGraph*) rhicFile->Get(Form("gS_%d_%d", ptT, centrality));
4761   
4762   Printf("%f %f %f %f", nPairs, nTrigs, nPairs / nTrigs, graph->GetY()[ptA]);
4763   
4764   corrFunc->Scale(nPairs / nTrigs);
4765  
4766   //corrFunc->Add(new TF1("func", "1", -5, 5), -1. / 3 * (corrFunc->GetBinContent(corrFunc->FindBin(1.5)) + corrFunc->GetBinContent(corrFunc->FindBin(1.2)) + corrFunc->GetBinContent(corrFunc->FindBin(1.0))));
4767   
4768   Float_t values[3];
4769   Float_t errors[3];
4770   
4771   Float_t regionBegin[3] = { -TMath::Pi() / 2,        TMath::Pi() / 2 - 0.4, 1.5 * TMath::Pi() - 0.4 };
4772   Float_t regionEnd[3] =   { -TMath::Pi() / 2 + 0.4,  TMath::Pi() / 2 + 0.4, 1.5 * TMath::Pi() };
4773     
4774   // weighted mean
4775   Float_t sum = 0;
4776   Float_t weight = 0;
4777   for (Int_t i=0; i<3; i++)
4778   {
4779     corrFunc->Fit("pol0", "0Q", "", regionBegin[i], regionEnd[i]);
4780     func = corrFunc->GetFunction("pol0");
4781     if (!func)
4782       continue;
4783     sum += func->GetParameter(0) / func->GetParError(0) / func->GetParError(0);
4784     weight += 1. / func->GetParError(0) / func->GetParError(0);
4785   }
4786   
4787   if (weight == 0)
4788     return 0;
4789   
4790   sum /= weight;
4791   weight = TMath::Sqrt(1. / weight);
4792   
4793   corrFunc->Add(new TF1("func", "1", -5, 5), -sum);
4794   
4795   return corrFunc;
4796   
4797   new TCanvas;
4798   corrFunc->Draw();
4799   compHist = (TH1*) rhicFile->Get(Form("ptyMSMP_0_%d%d%d", ptT, ptA, centrality));
4800   compHist->DrawCopy("SAME");
4801   
4802   //compHist->Add((TF1*) compHist->GetListOfFunctions()->First());
4803   //compHist->DrawCopy("SAME");
4804 }
4805   
4806 void DeltaPhiVsRHIC(Int_t rhicCentrality = 0, Int_t aliceCentrality = 0, Bool_t reduced = kFALSE)
4807 {
4808   aliceFile = TFile::Open("alice_dphi_corr_rhicbinning.root");
4809   rhicFile = TFile::Open("rhic/postcorr_AuAu_iter6_ppg106final.root");
4810
4811   Int_t maxLeadingPt = 4;
4812   Int_t maxAssocPt = 5;
4813   
4814   if (reduced)
4815   {
4816     Int_t maxSelected = 4;
4817     Int_t selectedLead[] = { 0, 0, 2, 2 };
4818     Int_t selectedAssoc[] = { 1, 2, 3, 4 };
4819    
4820     maxLeadingPt = TMath::Sqrt(maxSelected);
4821     maxAssocPt = TMath::Sqrt(maxSelected);
4822   }
4823     
4824   TCanvas* canvas = new TCanvas("DeltaPhi", "DeltaPhi", 1000, 700);
4825   canvas->Divide(maxAssocPt, maxLeadingPt);
4826   
4827   for (Int_t i=0; i<maxLeadingPt; i++)
4828     for (Int_t j=0; j<maxAssocPt; j++)
4829     {
4830       Printf("%d %d", i, j);
4831     
4832       canvas->cd(j+1 + i * maxAssocPt);
4833       gPad->SetLeftMargin(0.15);
4834       gPad->SetBottomMargin(0.2);
4835       //gPad->SetTopMargin(0.01);
4836       gPad->SetRightMargin(0.01);
4837       
4838       Int_t iSel = i;
4839       Int_t jSel = j;
4840       
4841       if (reduced)
4842       {
4843         iSel = selectedLead[j + i * maxAssocPt];
4844         jSel = selectedAssoc[j + i * maxAssocPt];
4845       }
4846       
4847       //rhic = (TH1*) rhicFile->Get(Form("VptyMSMP_0_%d%d%d", iSel, jSel, rhicCentrality));
4848       rhic = GetNonSubtractedRHICYield(iSel, jSel, rhicCentrality);
4849       if (!rhic)
4850         continue;
4851       rhic->SetLineColor(2);
4852       rhic->SetMarkerStyle(1);
4853       
4854       alice = (TH1*) aliceFile->Get(Form("dphi_%d_%d_%d_fit_flat", iSel, jSel, aliceCentrality));
4855       if (!alice)
4856         continue;
4857         
4858       // match near side yield
4859       if (1)
4860       {
4861         Float_t factor = 0.5 * alice->Integral(alice->FindBin(-0.1), alice->FindBin(0.1)) / rhic->Integral(rhic->FindBin(-0.1), rhic->FindBin(0.1));
4862         
4863         Printf("%f", factor);
4864         rhic->Scale(factor);
4865       }
4866         
4867       alice->SetLineColor(1);
4868         
4869       //alice->Rebin(36); rhic->Rebin(30);
4870       
4871       clone = alice->DrawCopy("");
4872       rhic->DrawCopy("SAME");
4873       
4874       //Printf("chi2 test: chi2/ndf = %f", alice->Chi2Test(rhic, "WW CHI2/NDF"));
4875       Float_t chi2 = 0;
4876       Float_t n = 0;
4877       for (Int_t k=1; k<=rhic->GetNbinsX(); k++)
4878       {
4879         chi2 += TMath::Power(rhic->GetBinContent(k) - alice->Interpolate(rhic->GetBinCenter(k)), 2) / (TMath::Power(rhic->GetBinError(k), 2) + TMath::Power(alice->GetBinError(alice->FindBin(rhic->GetBinCenter(k))), 2));
4880         n++;
4881       }
4882       
4883       chi2 /= n;
4884       Printf("chi2 test: chi2/ndf = %f", chi2);      
4885       
4886       clone->GetYaxis()->SetRangeUser(TMath::Min(alice->GetMinimum(), rhic->GetMinimum()) * 1.1, TMath::Max(alice->GetMaximum(), rhic->GetMaximum()) * 1.1);
4887       
4888       for (Int_t bin=1; bin<=rhic->GetNbinsX(); bin++)
4889       {
4890         Double_t aliceValue = alice->GetBinContent(alice->FindBin(rhic->GetXaxis()->GetBinCenter(bin)));
4891         if (aliceValue == 0)
4892           continue;
4893         rhic->SetBinContent(bin, rhic->GetBinContent(bin) / aliceValue);
4894         rhic->SetBinError(bin, 0);
4895       }
4896       
4897       rhic->Rebin(2);
4898       rhic->Scale(0.5);
4899       
4900       rhic->SetLineColor(3);
4901       //rhic->DrawCopy("SAME");
4902       
4903       //return;
4904     }
4905     
4906     canvas->SaveAs("yield_comparison.png");
4907 }
4908   
4909 void DeltaPhi(const char* fileName, const char* fileName2 = 0, Bool_t reduced = kFALSE, Bool_t ppComparison = kFALSE, Int_t mode = 0, const char* dataTag = "")
4910 {
4911   // DeltaPhi("high_stat_binning_pp7_pt8.root", "high_stat_binning_pp7_pythia_pt8.root", 0, 1, 0, "pp 7 TeV")
4912   // DeltaPhi("high_stat_binning_pp900_pt8.root", "high_stat_binning_pp900_pythia_pt8.root", 0, 1, 0, "pp 0.9 TeV")
4913
4914   style(2);
4915
4916   aliceFile = TFile::Open(fileName);
4917   if (fileName2)
4918     secondFile = TFile::Open(fileName2);
4919
4920   Int_t maxLeadingPt = 3;
4921   Int_t maxAssocPt = 2;
4922   
4923   if (reduced)
4924   {
4925     Int_t maxSelected = 4;
4926     Int_t selectedLead[] = { 0, 0, 2, 2 };
4927     Int_t selectedAssoc[] = { 1, 2, 3, 4 };
4928    
4929     maxLeadingPt = TMath::Sqrt(maxSelected);
4930     maxAssocPt = TMath::Sqrt(maxSelected);
4931   }
4932   
4933   factorGraph = new TGraphErrors;
4934     
4935   TCanvas* canvas = new TCanvas(Form("%s_%s", fileName, fileName2 ? fileName2 : ""), Form("%s_%s", fileName, fileName2 ? fileName2 : ""), 800, 1200);
4936   canvas->Divide(maxAssocPt, maxLeadingPt);
4937   
4938   for (Int_t i=0; i<maxLeadingPt; i++)
4939     for (Int_t j=0; j<maxAssocPt; j++)
4940     {
4941       TH1* first = 0;
4942       TH1* peripheral = 0;
4943       for (Int_t aliceCentrality=0; aliceCentrality<4; aliceCentrality++)
4944       {
4945         Printf("%d %d %d", i, j, aliceCentrality);
4946       
4947         canvas->cd(j+1 + i * maxAssocPt);
4948         
4949         Int_t iSel = i;
4950         Int_t jSel = j;
4951         Int_t centralitySel = aliceCentrality;
4952         currentFile = aliceFile;
4953         
4954         if (reduced)
4955         {
4956           iSel = selectedLead[j + i * maxAssocPt];
4957           jSel = selectedAssoc[j + i * maxAssocPt];
4958         }
4959         
4960         if (fileName2)
4961         {
4962           if (ppComparison)
4963           {
4964             centralitySel = 3;
4965             if (aliceCentrality == 1)
4966               currentFile = secondFile;
4967             else if (aliceCentrality == 2)
4968               break;
4969           }
4970           else
4971             if (aliceCentrality == 3)
4972               currentFile = secondFile;
4973         }
4974         
4975         //alice = (TH1*) currentFile->Get(Form("dphi_%d_%d_%d%s", iSel, jSel, centralitySel, (centralitySel < 3) ? "_tsallis_flat" : ((flatOrTsallis) ? "" : "_fit_flat")));
4976         alice = (TH1*) currentFile->Get(Form("dphi_%d_%d_%d%s", iSel, jSel, centralitySel, "_fit_flat"));
4977         if (!alice)
4978           continue;
4979           
4980         // match near side yield to peripheral
4981         if (1 && centralitySel == 3 && peripheral)
4982         {
4983          if (mode == 0 || mode == 1)
4984           {
4985             Double_t width = 0.5;
4986             Double_t error1, error2;
4987             Double_t integral1 = peripheral->IntegralAndError(peripheral->FindBin(-width), peripheral->FindBin(width), error1);
4988             Double_t integral2 = alice->IntegralAndError(alice->FindBin(-width), alice->FindBin(width), error2);
4989             if (mode == 1)
4990             {
4991               Double_t tmpErr = 0;
4992               integral1 += peripheral->IntegralAndError(peripheral->FindBin(TMath::Pi() - width), peripheral->FindBin(TMath::Pi() + width), tmpErr);
4993               error1 = TMath::Sqrt(error1 * error1 + tmpErr * tmpErr);
4994               
4995               integral2 += alice->IntegralAndError(alice->FindBin(TMath::Pi() - width), alice->FindBin(TMath::Pi() + width), tmpErr);
4996               error2 = TMath::Sqrt(error2 * error2 + tmpErr * tmpErr);
4997             }
4998           }
4999           else if (mode == 2)
5000           {
5001             Double_t error1, error2;
5002             Double_t integral1 = peripheral->IntegralAndError(1, peripheral->GetNbinsX(), error1);
5003             Double_t integral2 = alice->IntegralAndError(1, alice->GetNbinsX(), error2);
5004           }
5005           else if (mode == 3)
5006           {
5007             Double_t width = 1.0;
5008             Double_t error1, error2;
5009             Double_t integral1 = peripheral->IntegralAndError(peripheral->FindBin(TMath::Pi() - width), peripheral->FindBin(TMath::Pi() + width), error1);
5010             Double_t integral2 = alice->IntegralAndError(alice->FindBin(TMath::Pi() - width), alice->FindBin(TMath::Pi() + width), error2);
5011           }
5012             
5013           Double_t factor = integral1 / integral2;
5014           
5015           //factor = 0.804 * 0.9;
5016           Printf("%f", factor);
5017           alice->Scale(factor);
5018           factorGraph->SetPoint(factorGraph->GetN(), factorGraph->GetN(), factor);
5019           factorGraph->SetPointError(factorGraph->GetN() - 1, 0, factor * TMath::Sqrt(TMath::Power(error1 / integral1, 2) + TMath::Power(error2 / integral2, 2)));
5020         }
5021         
5022         if (ppComparison && aliceCentrality == 0)
5023           peripheral = alice;
5024         else if (aliceCentrality == 2)
5025           peripheral = alice;          
5026           
5027         alice->SetYTitle("1/N_{trig} dN_{assoc}/d#Delta#phi");
5028         alice->SetXTitle("#Delta#phi (rad.)");
5029         alice->SetLineColor(aliceCentrality+1);
5030         alice->SetLineWidth(2);
5031         alice->SetMarkerColor(aliceCentrality+1);
5032         alice->GetYaxis()->SetTitleOffset(1.7);
5033         clone = alice->DrawCopy((aliceCentrality > 0) ? "SAME" : "");
5034         clone->SetTitle("");
5035         
5036         TString str(alice->GetTitle());
5037         str.ReplaceAll(" - ", "#");
5038         tokens = str.Tokenize("#");
5039           
5040         if (aliceCentrality == 0)
5041         {
5042           for (Int_t k=0; k<2; k++)
5043           {
5044             TString str(tokens->At(k)->GetName());
5045             str.ReplaceAll(".0", "");
5046             str.ReplaceAll("< p", "GeV/c < p");
5047             str += " GeV/c";
5048             latex = new TLatex(0.52, 0.92-k*0.06, str);
5049             latex->SetNDC();
5050             latex->SetTextSize(0.04);
5051             latex->Draw();
5052           }
5053         }
5054         
5055         if (!first)
5056           first = clone;
5057         else
5058           first->GetYaxis()->SetRangeUser(TMath::Min(first->GetMinimum(), clone->GetMinimum()), TMath::Max(first->GetMaximum(), clone->GetMaximum()));
5059           
5060         
5061           
5062         //return;
5063       }
5064       if (first)
5065         //first->GetYaxis()->SetRangeUser(first->GetMinimum(), first->GetMaximum() * 1.2);
5066         first->GetYaxis()->SetRangeUser(first->GetMinimum(), first->GetMaximum() * 1.5);
5067     }
5068     
5069   for (Int_t i=1; i<=6; i++)
5070   {
5071     canvas->cd(i);
5072     
5073     latex = new TLatex(0.6, 0.8, "ALICE preliminary");
5074     latex->SetTextSize(0.04);
5075     latex->SetNDC();
5076     latex->Draw();
5077   
5078     latex = new TLatex(0.6, 0.74, Form("%s uncorrected", dataTag));
5079     latex->SetTextSize(0.04);
5080     latex->SetNDC();
5081     latex->Draw();
5082     
5083     latex = new TLatex(0.6, 0.68, "Stat. uncertainties only");
5084     latex->SetTextSize(0.04);
5085     latex->SetNDC();
5086     latex->Draw();
5087   
5088     if (ppComparison)
5089     {
5090       legend = new TLegend(0.3, 0.8, 0.47, 0.95);
5091       legend->SetFillColor(0);
5092       legend->SetTextSize(0.04);
5093       legend->AddEntry(peripheral, "Data");
5094       legend->AddEntry(alice, "Pythia");
5095       legend->Draw();
5096     }
5097   }
5098   
5099   canvas->SaveAs(Form("%s.eps", canvas->GetName()));
5100   canvas->SaveAs(Form("%s.png", canvas->GetName()));
5101     
5102   new TCanvas;
5103   peripheral->Divide(alice);
5104   peripheral->DrawCopy();
5105   //alice->DrawCopy("SAME");
5106   
5107     
5108   graphCanvas = (TCanvas*) gROOT->GetListOfCanvases()->FindObject("graphCanvas");
5109   factorGraph->SetMarkerStyle(20);
5110   if (!graphCanvas)
5111   {
5112     graphCanvas = new TCanvas("graphCanvas", "graphCanvas", 800, 600);
5113     factorGraph->Draw("AP");
5114   }
5115   else
5116   {
5117     graphCanvas->cd();
5118     factorGraph->SetLineColor(2);
5119     factorGraph->SetMarkerColor(2);
5120     factorGraph->Draw("SAMEP");
5121   }
5122   factorGraph->GetYaxis()->SetRangeUser(0.6, 1.4);
5123   
5124   factorGraph->Print();
5125 }
5126
5127 void ComparePPYields(const char* histName = "_fit_flat")
5128 {
5129   const char* files[] = { "high_stat_binning_pp900_pt8.root", "high_stat_binning_pp900_pythia_pt8.root", "high_stat_binning_pp276_pythia_pt8.root", "high_stat_binning_pp7_pythia_pt8.root", "high_stat_binning_pp7_pt8.root" };
5130   const char* titles[] = { "0.9 data", "0.9 Pythia", "2.76 Pythia", "7 Pythia", "7 data" };
5131   
5132   Int_t colors[] = { 1, 2, 3, 4, 6 };
5133   
5134   Int_t maxLeadingPt = 3;
5135   Int_t maxAssocPt = 2;
5136   
5137   TCanvas* canvas = new TCanvas("ComparePPYields", "ComparePPYields", 600, 900);
5138   canvas->Divide(maxAssocPt, maxLeadingPt);
5139   
5140   legend = new TLegend(0.5, 0.5, 0.8, 0.8);
5141   legend->SetFillColor(0);
5142   
5143   TGraphErrors** graphs = new TGraphErrors*[5];
5144   TGraphErrors** graphs2 = new TGraphErrors*[5];
5145       
5146   for (Int_t nFiles = 0; nFiles < 5; nFiles++)
5147   {
5148     graphs[nFiles] = new TGraphErrors;
5149     graphs2[nFiles] = new TGraphErrors;
5150   }
5151   
5152   for (Int_t i=0; i<maxLeadingPt; i++)
5153     for (Int_t j=0; j<maxAssocPt; j++)
5154     {
5155       canvas->cd(j+1 + i * maxAssocPt);
5156       gPad->SetLeftMargin(0.18);
5157       gPad->SetBottomMargin(0.1);
5158       gPad->SetTopMargin(0.01);
5159       gPad->SetRightMargin(0.01);
5160         
5161       TH1* first = 0;
5162         
5163       for (Int_t nFiles = 0; nFiles < 5; nFiles++)
5164       {
5165         currentFile = TFile::Open(files[nFiles]);
5166
5167         Int_t aliceCentrality = 3;
5168           
5169         Printf("%d %d %d", i, j, nFiles);
5170       
5171         alice = (TH1*) currentFile->Get(Form("dphi_%d_%d_%d%s", i, j, aliceCentrality, histName));
5172         if (!alice)
5173           continue;
5174           
5175         alice->SetYTitle("1/N_{trig} dN/dp_{T,assoc}");
5176         alice->SetLineColor(colors[nFiles]);
5177         alice->SetMarkerColor(colors[nFiles]);
5178         alice->GetYaxis()->SetTitleOffset(1.7);
5179         clone = alice->DrawCopy((nFiles > 0) ? "SAME" : "");
5180         clone->SetTitle("");
5181         
5182         Double_t width = 0.7;
5183         Double_t error, error2;
5184         Double_t integral = alice->IntegralAndError(alice->FindBin(-width), alice->FindBin(width), error);
5185         Double_t integral2 = alice->IntegralAndError(alice->FindBin(TMath::Pi() - width), alice->FindBin(TMath::Pi() + width), error2);
5186         
5187         graphs[nFiles]->SetPoint(graphs[nFiles]->GetN(), j + i * maxAssocPt - 0.2, integral);
5188         graphs[nFiles]->SetPointError(graphs[nFiles]->GetN()-1, 0, error);
5189         
5190         graphs2[nFiles]->SetPoint(graphs2[nFiles]->GetN(), j + i * maxAssocPt + 0.2, integral2);
5191         graphs2[nFiles]->SetPointError(graphs2[nFiles]->GetN()-1, 0, error2);
5192         
5193         if (!first)
5194           first = clone;
5195         else
5196           first->GetYaxis()->SetRangeUser(TMath::Min(first->GetMinimum(), clone->GetMinimum()), TMath::Max(first->GetMaximum(), clone->GetMaximum()));
5197           
5198         if (nFiles == 0)
5199         {
5200           TString str(alice->GetTitle());
5201           str.ReplaceAll(" - ", "#");
5202           tokens = str.Tokenize("#");
5203             
5204           for (Int_t k=0; k<2; k++)
5205           {
5206             latex = new TLatex(0.6, 0.88-k*0.07, tokens->At(k)->GetName());
5207             latex->SetNDC();
5208             latex->SetTextSize(0.04);
5209             latex->Draw();
5210           }
5211         }
5212           
5213         if (i == 0 && j == 0)
5214           legend->AddEntry(clone, titles[nFiles]);
5215       }
5216       if (first)
5217         first->GetYaxis()->SetRangeUser(first->GetMinimum(), first->GetMaximum() * 1.1);
5218     }
5219     
5220   canvas->cd(1);
5221   
5222   legend->Draw();
5223   
5224   new TCanvas;
5225   for (Int_t nFiles = 0; nFiles < 5; nFiles++)
5226   {
5227     graphs[nFiles]->SetMarkerStyle(25);
5228     graphs[nFiles]->SetLineColor(colors[nFiles]);
5229     graphs[nFiles]->SetMarkerColor(colors[nFiles]);
5230     clone2 = (TGraphErrors*) graphs[nFiles]->DrawClone((nFiles == 0) ? "AP" : "PSAME");
5231     clone2->GetYaxis()->SetRangeUser(0, 5);
5232   
5233     graphs2[nFiles]->SetMarkerStyle(26);
5234     graphs2[nFiles]->SetLineColor(colors[nFiles]);
5235     graphs2[nFiles]->SetMarkerColor(colors[nFiles]);
5236     graphs2[nFiles]->DrawClone("PSAME");
5237   }  
5238
5239   new TCanvas;
5240   for (Int_t nFiles = 0; nFiles < 5; nFiles++)
5241   {
5242     DivideGraphs(graphs[nFiles], graphs[4]);
5243     DivideGraphs(graphs2[nFiles], graphs2[4]);
5244     
5245     graphs[nFiles]->SetMarkerStyle(25);
5246     graphs[nFiles]->SetLineColor(colors[nFiles]);
5247     graphs[nFiles]->SetMarkerColor(colors[nFiles]);
5248     clone2 = (TGraphErrors*) graphs[nFiles]->DrawClone((nFiles == 0) ? "AP" : "PSAME");
5249     clone2->GetYaxis()->SetRangeUser(0, 1.5);
5250   
5251     graphs2[nFiles]->SetMarkerStyle(26);
5252     graphs2[nFiles]->SetLineColor(colors[nFiles]);
5253     graphs2[nFiles]->SetMarkerColor(colors[nFiles]);
5254     graphs2[nFiles]->DrawClone("PSAME");
5255   }  
5256 }
5257
5258 void DeltaPhiPreliminary(const char* fileName, const char* histName)
5259 {
5260   style(2);
5261
5262   currentFile = TFile::Open(fileName);
5263
5264   TCanvas* canvas = new TCanvas(Form("dphi%s", histName), "dphi", 800, 800);
5265   canvas->Divide(2, 2);
5266   
5267   TLegend* legend = new TLegend(0.55, 0.47, 0.85, 0.65);
5268   legend->SetFillColor(0);
5269   legend->SetTextSize(0.04);
5270   
5271   Int_t colors[] = { 1, 2, 4, 6 };
5272   
5273   Int_t pad = 1;
5274   for (Int_t i=1; i<2; i++)
5275     for (Int_t j=2; j<6; j++)
5276     {
5277       canvas->cd(pad++);
5278   
5279       for (Int_t aliceCentrality=0; aliceCentrality<3; aliceCentrality+=2)
5280       {
5281         Printf("%d %d %d", i, j, aliceCentrality);
5282       
5283         hist = (TH1*) currentFile->Get(Form("dphi_%d_%d_%d%s", i, j, aliceCentrality, histName));
5284         if (!hist)
5285           continue;
5286           
5287         if (aliceCentrality == 3)
5288           hist->Scale(kPythiaScalingFactor);
5289           
5290         hist->GetYaxis()->SetTitleOffset(1.9);
5291         hist->SetLineColor(colors[aliceCentrality]);
5292         hist->SetMarkerColor(colors[aliceCentrality]);
5293         hist->SetLineWidth(2);
5294         hist->SetYTitle("1/N_{trig} dN_{assoc}/d#Delta#phi");
5295         hist->SetXTitle("#Delta#phi (rad.)");
5296         
5297         clone = hist->DrawCopy((aliceCentrality > 0) ? "SAME" : "");
5298         clone->SetTitle("");
5299         
5300         TString str(hist->GetTitle());
5301         str.ReplaceAll(" - ", "#");
5302         tokens = str.Tokenize("#");
5303         hist->SetTitle("");
5304           
5305         if (aliceCentrality == 0)
5306         {
5307           for (Int_t k=0; k<2; k++)
5308           {
5309             TString str(tokens->At(k)->GetName());
5310             str.ReplaceAll(".0", "");
5311             str.ReplaceAll("< p", "GeV/c < p");
5312             str += " GeV/c";
5313           
5314             latex = new TLatex(0.5, 0.88-k*0.06, str);
5315             latex->SetNDC();
5316             latex->SetTextSize(0.04);
5317             latex->Draw();
5318           }
5319           
5320           latex = new TLatex(0.5, 0.76, "ALICE preliminary");
5321           latex->SetTextSize(0.04);
5322           latex->SetNDC();
5323           latex->Draw();
5324         
5325           latex = new TLatex(0.5, 0.70, "Stat. uncertainties only");
5326           latex->SetTextSize(0.04);
5327           latex->SetNDC();
5328           latex->Draw();
5329
5330           clone->GetYaxis()->SetRangeUser(0, clone->GetMaximum() * 1.2);
5331         }
5332         
5333         if (pad == 2)
5334         {
5335           if (aliceCentrality == 3)
5336             legend->AddEntry(hist, "Pythia");
5337           else
5338             legend->AddEntry(hist, tokens->At(2)->GetName());
5339         }
5340         
5341         legend->Draw();
5342         
5343       }
5344     }
5345     
5346   canvas->cd(3);
5347   
5348   canvas->SaveAs(Form("%s.eps", canvas->GetName()));
5349   canvas->SaveAs(Form("%s.png", canvas->GetName()));
5350 }
5351
5352 void DeltaPhiBaseLinePreliminary(const char* fileName)
5353 {
5354   style(2);
5355   
5356   loadlibs();
5357
5358   Float_t leadingPtArr[] = { 6.0, 8.0, 10.0, 15.0, 15.0 };
5359   Float_t assocPtArr[] =     { 0.5, 1.5, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
5360   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
5361
5362   Int_t i = 1;
5363   Int_t j = 3;
5364   Int_t step = 0;
5365
5366   gpTMin = assocPtArr[j] + 0.01;
5367   gpTMax = assocPtArr[j+1] - 0.01;
5368   SetupRanges(h);
5369       
5370   TString str;
5371   str.Form("%.0f GeV/c < p_{T,trig} < %.0f GeV/c", leadingPtArr[i], leadingPtArr[i+2]);
5372   
5373   TString str2;
5374   str2.Form("%.0f GeV/c < p_{T,assoc} < %.0f GeV/c", gpTMin - 0.01, gpTMax + 0.01);
5375           
5376   Float_t v2[3];
5377   TH1* hist1 = 0;
5378   TH1* hist2b = 0;
5379   
5380   GetDistAndFlow(h, 0, &hist1,  v2[0], step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+2] - 0.01); 
5381   GetDistAndFlow(h, 0, &hist2b, v2[2], step, 60, 90, leadingPtArr[i] + 0.01, leadingPtArr[i+2] - 0.01); 
5382   
5383   hist1->SetLineWidth(2);
5384   hist2b->SetLineWidth(2);
5385
5386   canvas = new TCanvas("dphi_baseline", "dphi_baseline", 1200, 1200);
5387   canvas->Divide(2, 2);
5388   
5389   canvas->cd(1);
5390 //   gPad->SetLeftMargin(0.20);
5391   
5392   hist1->GetYaxis()->SetTitleOffset(1.9);
5393   hist1->SetYTitle("1/N_{trig} dN_{assoc}/d#Delta#phi");
5394   hist1->SetXTitle("#Delta#phi (rad.)");
5395   hist1->SetTitle("");
5396   hist1->DrawCopy()->GetYaxis()->SetRangeUser(0, 0.59);
5397   
5398   DrawFlow(v2[0], (TH1*) hist1->Clone(), leadingPtArr[i], assocPtArr[j], 0, i, 0, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
5399           
5400   latex = new TLatex(0.5, 0.78, "0-5%");
5401   latex->SetNDC();
5402   latex->SetTextSize(0.04);
5403   latex->Draw();
5404   
5405   if (1)
5406   {
5407     canvas->cd(2);
5408   //   gPad->SetLeftMargin(0.20);
5409     
5410     hist1->DrawCopy()->GetYaxis()->SetRangeUser(0.18, 0.295);
5411     DrawFlow(v2[0], hist1, leadingPtArr[i], assocPtArr[j], 0, i, 0, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
5412     
5413     latex->Draw();
5414     
5415     canvas->cd(3);
5416   //   gPad->SetLeftMargin(0.20);
5417     
5418     hist2b->GetYaxis()->SetTitleOffset(1.9);
5419     hist2b->SetYTitle("1/N_{trig} dN_{assoc}/d#Delta#phi");
5420     hist2b->SetXTitle("#Delta#phi (rad.)");
5421     hist2b->SetTitle("");
5422     hist2b->DrawCopy();
5423             
5424     DrawFlow(v2[2], (TH1*) hist2b->Clone(), leadingPtArr[i], assocPtArr[j], 0, i, 2, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
5425     
5426     latex = new TLatex(0.5, 0.78, "60-90%");
5427     latex->SetNDC();
5428     latex->SetTextSize(0.04);
5429     latex->Draw();
5430     
5431     canvas->cd(4);
5432   //   gPad->SetLeftMargin(0.20);
5433         
5434     hist2b->DrawCopy()->GetYaxis()->SetRangeUser(0.01, 0.13);
5435     DrawFlow(v2[2], hist2b, leadingPtArr[i], assocPtArr[j], 0, i, 2, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
5436         
5437     latex->Draw();
5438   }
5439   
5440   for (Int_t i=1; i<=4; i++)
5441   {
5442     canvas->cd(i);
5443     
5444     latex = new TLatex(0.5, 0.84, str);
5445     latex->SetNDC();
5446     latex->SetTextSize(0.04);
5447     latex->Draw();
5448     
5449     latex = new TLatex(0.5, 0.90, str2);
5450     latex->SetNDC();
5451     latex->SetTextSize(0.04);
5452     latex->Draw();
5453   
5454     latex = new TLatex(0.5, 0.72, "ALICE preliminary");
5455     latex->SetTextSize(0.04);
5456     latex->SetNDC();
5457     latex->Draw();
5458   
5459     latex = new TLatex(0.5, 0.66, "Stat. uncertainties only");
5460     latex->SetTextSize(0.04);
5461     latex->SetNDC();
5462     latex->Draw();
5463   }
5464     
5465   canvas->SaveAs(Form("%s.eps", canvas->GetName()));
5466   canvas->SaveAs(Form("%s.png", canvas->GetName()));
5467 }
5468
5469 void DeltaPhiRidgePreliminary(const char* fileName)
5470 {
5471   style();
5472   
5473   loadlibs();
5474
5475   Float_t leadingPtArr[] = { 6.0, 8.0, 10.0, 15.0, 15.0 };
5476   Float_t assocPtArr[] =     { 0.5, 1.5, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
5477   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
5478
5479   Int_t i = 1;
5480   Int_t j = 3;
5481   Int_t step = 0;
5482
5483   gpTMin = assocPtArr[j] + 0.01;
5484   gpTMax = assocPtArr[j+1] - 0.01;
5485   SetupRanges(h);
5486       
5487   TString str;
5488   str.Form("%.1f < p_{T,trig} < %.1f", leadingPtArr[i], leadingPtArr[i+2]);
5489   
5490   TString str2;
5491   str2.Form("%.1f < p_{T,assoc} < %.1f", gpTMin - 0.01, gpTMax + 0.01);
5492           
5493   Float_t v2[3];
5494   TH1* hist1 = 0;
5495   TH1* hist2b = 0;
5496   TH1* hist1Peak = 0;
5497   TH1* hist2bPeak = 0;
5498   TH1* hist1Ridge = 0;
5499   TH1* hist2bRidge = 0;
5500   
5501   GetDistAndFlow(h, 0, &hist1,  v2[0], step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+2] - 0.01); 
5502 //   GetDistAndFlow(h, 0, &hist2b, v2[2], step, 60, 90, leadingPtArr[i] + 0.01, leadingPtArr[i+2] - 0.01); 
5503   GetDistAndFlow(h, 0, &hist1Peak,  v2[0], step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+2] - 0.01, 10); 
5504
5505   GetDistAndFlow(h, 0, &hist1Ridge,  v2[0], step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+2] - 0.01, 11); 
5506
5507   // TODO normalize
5508
5509   canvas = new TCanvas("dphi_baseline", "dphi_baseline", 800, 800);
5510   canvas->Divide(2, 2);
5511   
5512   canvas->cd(1);
5513   gPad->SetLeftMargin(0.20);
5514   
5515   hist1->GetYaxis()->SetTitleOffset(1.9);
5516   hist1->SetYTitle("1/N_{trig} dN/dp_{T,assoc}");
5517   hist1->SetTitle("");
5518   hist1->DrawCopy();
5519   
5520 /*  hist1Peak->Scale(1./0.75);
5521   hist1Ridge->Scale(1./0.25);*/
5522   
5523   hist1Peak->SetLineColor(2);
5524   hist1Peak->DrawCopy("SAME");
5525   
5526   hist1Ridge->SetLineColor(4);
5527   hist1Ridge->DrawCopy("SAME");
5528   
5529 //   hist1Peak->Add(hist1Ridge);
5530 //   hist1Peak->DrawCopy("SAME")->SetLineColor(3);
5531   
5532   return;
5533   
5534   DrawFlow(v2[0], (TH1*) hist1->Clone(), leadingPtArr[i], assocPtArr[j], 0, i, 0, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
5535           
5536   latex = new TLatex(0.65, 0.84, str);
5537   latex->SetNDC();
5538   latex->SetTextSize(0.04);
5539   latex->Draw();
5540   
5541   latex = new TLatex(0.65, 0.90, str2);
5542   latex->SetNDC();
5543   latex->SetTextSize(0.04);
5544   latex->Draw();
5545
5546   latex = new TLatex(0.84, 0.78, "0-5%");
5547   latex->SetNDC();
5548   latex->SetTextSize(0.04);
5549   latex->Draw();
5550   
5551   canvas->cd(2);
5552   gPad->SetLeftMargin(0.20);
5553   
5554   hist1->DrawCopy()->GetYaxis()->SetRangeUser(0.18, 0.28);
5555   DrawFlow(v2[0], hist1, leadingPtArr[i], assocPtArr[j], 0, i, 0, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
5556   
5557   latex->Draw();
5558   
5559   latex = new TLatex(0.5, 0.90, "ALICE preliminary");
5560   latex->SetTextSize(0.04);
5561   latex->SetNDC();
5562   latex->Draw();
5563
5564   latex = new TLatex(0.5, 0.84, "Statistical uncertainties only");
5565   latex->SetTextSize(0.04);
5566   latex->SetNDC();
5567   latex->Draw();
5568   
5569   canvas->cd(3);
5570   gPad->SetLeftMargin(0.20);
5571   
5572   hist2b->GetYaxis()->SetTitleOffset(1.9);
5573   hist2b->SetYTitle("1/N_{trig} dN/dp_{T,assoc}");
5574   hist2b->SetTitle("");
5575   hist2b->DrawCopy();
5576            
5577   DrawFlow(v2[2], (TH1*) hist2b->Clone(), leadingPtArr[i], assocPtArr[j], 0, i, 2, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
5578   
5579   latex = new TLatex(0.84, 0.78, "60-90%");
5580   latex->SetNDC();
5581   latex->SetTextSize(0.04);
5582   latex->Draw();
5583   
5584   canvas->cd(4);
5585   gPad->SetLeftMargin(0.20);
5586       
5587   hist2b->DrawCopy()->GetYaxis()->SetRangeUser(0.01, 0.1);
5588   DrawFlow(v2[2], hist2b, leadingPtArr[i], assocPtArr[j], 0, i, 2, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
5589       
5590   latex->Draw();
5591   
5592   canvas->SaveAs(Form("%s.eps", canvas->GetName()));
5593   canvas->SaveAs(Form("%s.png", canvas->GetName()));
5594 }
5595
5596 void MCScalingFactor(Int_t caseId)
5597 {
5598   // 900 GeV
5599   // x[5]=5, y[5]=0.813743, ex[5]=0, ey[5]=0.158446
5600   // x[5]=5, y[5]=1.09804, ex[5]=0, ey[5]=0.265434
5601   // 7 TeV
5602   // x[5]=5, y[5]=1.02276, ex[5]=0, ey[5]=0.0199991
5603   // x[5]=5, y[5]=0.870247, ex[5]=0, ey[5]=0.0294444
5604   
5605   Float_t factors[] = { 0.814, 1.098, 1.022, 0.870 };
5606   Float_t errors[]  = { 0.158, 0.265, 0.020, 0.029 };
5607   
5608   Float_t avgs[2];
5609   
5610   for (Int_t i=0; i<2; i++)
5611   {
5612     switch (caseId)
5613     {
5614       case 0:
5615         avgs[i] = factors[2*i] / errors[2*i] / errors[2*i] + factors[2*i+1] / errors[2*i+1] / errors[2*i+1];
5616         avgs[i] /= 1. / errors[2*i] / errors[2*i] + 1. / errors[2*i+1] / errors[2*i+1];
5617         break;
5618         
5619       case 1:
5620         avgs[i] = factors[2*i];
5621         break;
5622     
5623       case 2:
5624         avgs[i] = factors[2*i+1];
5625         break;
5626     
5627       case 3:
5628         avgs[0] = factors[0];
5629         avgs[1] = factors[3];
5630         break;
5631     
5632       case 4:
5633         avgs[0] = factors[1];
5634         avgs[1] = factors[2];
5635         break;
5636     }
5637   }
5638   
5639   Float_t a = avgs[0];
5640   Float_t b = avgs[1];
5641   
5642   Printf("%f %f", a, b);
5643   
5644   Float_t linEx = a + (b-a)/(7.-0.9) * (2.76-0.9);
5645   Float_t logEx = a + (b-a)/(log(7.)-log(0.9)) * (log(2.76)-log(0.9));
5646   
5647   Printf("%f %f", linEx, logEx);
5648 }
5649   
5650 void CompareDeltaPhi(const char* fileName1, const char* fileName2, Int_t centralityID, const char* dist = "_fit_flat", Bool_t reduced = kFALSE)
5651 {
5652   firstFile = TFile::Open(fileName1);
5653   secondFile = TFile::Open(fileName2);
5654
5655   Int_t maxLeadingPt = 3;
5656   Int_t maxAssocPt = 7;
5657   Int_t minLeadingPt = 0;
5658   Int_t minAssocPt = 0;
5659   
5660   if (reduced)
5661   {
5662     maxLeadingPt = 2;
5663     maxAssocPt = 5;
5664     minLeadingPt = 1;
5665     minAssocPt = 2;
5666   }
5667   
5668   TCanvas* canvas = new TCanvas(Form("%s %s", fileName1, fileName2 ? fileName2 : ""), Form("%s %s", fileName1, fileName2 ? fileName2 : ""), 1000, 700);
5669   canvas->Divide(maxAssocPt-minAssocPt, maxLeadingPt-minLeadingPt);
5670   
5671   for (Int_t i=minLeadingPt; i<maxLeadingPt; i++)
5672     for (Int_t j=minAssocPt; j<maxAssocPt; j++)
5673     {
5674       Printf("%d %d", i, j);
5675     
5676       canvas->cd(j+1-minAssocPt + (i-minLeadingPt) * maxAssocPt);
5677       gPad->SetLeftMargin(0.15);
5678       gPad->SetBottomMargin(0.2);
5679       //gPad->SetTopMargin(0.01);
5680       gPad->SetRightMargin(0.01);
5681       
5682       hist1 = (TH1*) firstFile->Get(Form("dphi_%d_%d_%d%s", i, j, centralityID, dist));
5683       hist2 = (TH1*) secondFile->Get(Form("dphi_%d_%d_%d%s", i, j, centralityID, dist));
5684       if (!hist1)
5685         continue;
5686         
5687       hist1->SetLineColor(1);
5688       hist2->SetLineColor(2);
5689       
5690       hist1->DrawCopy()->GetYaxis()->SetRangeUser(hist1->GetMinimum(), hist1->GetMaximum() * 1.2);
5691       hist2->DrawCopy("SAME");
5692       
5693       if (strlen(dist) == 0)
5694         Printf("chi2 test: %f", hist1->Chi2Test(hist2, "UU NORM CHI2/NDF"));
5695       
5696       //DrawRatio(hist1, hist2, hist1->GetTitle());
5697       
5698       //return;
5699     }
5700 }
5701   
5702 TH1* MACHCone(const char* fileName, Int_t centrality, const char* drawingOption, Bool_t plotContributions, Int_t twoD)
5703 {
5704   if (0)
5705   {
5706     TFile::Open("machcone_input.root");
5707     
5708     switch (centrality)
5709     {
5710       case 0:
5711         hist = (TH1*) gFile->Get("dphi_0_0_0");
5712         break;
5713       
5714       case 1:
5715         hist = (TH1*) gFile->Get("dphi_1_1_0");
5716         break;
5717         
5718       case 2:
5719         hist = (TH1*) gFile->Get("dphi_0_0_2");
5720         break;
5721     
5722       case 3:
5723         hist = (TH1*) gFile->Get("dphi_1_1_2");
5724         break;
5725     }
5726   }
5727   else
5728   {
5729     loadlibs();
5730     
5731     AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
5732     
5733     Float_t leadingPtArr[] = { 2.0, 3.0, 4.0, 10.0, 20.0, 40.0 };
5734     Float_t assocPtArr[] =   { 1.0, 2.0, 3.0, 6.0, 10.0, 20.0, 40.0 };
5735   
5736     Int_t i = centrality % 2;
5737     Int_t step = 6;
5738     
5739     gpTMin = assocPtArr[i] + 0.01;
5740     gpTMax = assocPtArr[i+1] - 0.01;
5741     
5742     Int_t centralityBegin = 0;
5743     Int_t centralityEnd = 2;
5744     
5745     if (centrality >= 2)
5746     {
5747       centralityBegin = 30;
5748       centralityEnd = 40;
5749     }
5750       
5751     SetupRanges(h);
5752     
5753     Float_t v2[1];
5754     TH1* hist = 0;
5755     GetDistAndFlow(h, 0, &hist,  v2[0], step, centralityBegin, centralityEnd, leadingPtArr[i] + 0.01, leadingPtArr[i+1] - 0.01, twoD); 
5756   }
5757   
5758   
5759   TString str(hist->GetTitle());
5760   str.ReplaceAll(" - ", "#");
5761   tokens = str.Tokenize("#");
5762   hist->SetTitle("");
5763   
5764   hist->SetLineColor(1);
5765   hist->SetYTitle("1/N_{trig} dN_{assoc}/d#Delta#phi");
5766   hist->SetXTitle("#Delta#phi (rad.)");
5767   hist = hist->DrawCopy(drawingOption);
5768   
5769   for (Int_t i=0; i<tokens->GetEntries(); i++)
5770   {
5771     latex = new TLatex(0.6, 0.8-i*0.05, tokens->At(i)->GetName());
5772     latex->SetNDC();
5773     latex->SetTextSize(0.04);
5774     latex->Draw();
5775   }
5776   
5777   // From CalculateFlow(...) above
5778   // v_{2} = 0.042293 for 1.000000 < pT < 2.000000
5779   // v_{2} = 0.060797 for 2.000000 < pT < 4.000000
5780   // v_{3} = 0.040318 for 1.000000 < pT < 2.000000
5781   // v_{3} = 0.077353 for 2.000000 < pT < 4.000000
5782   // v_{4} = 0.020557 for 1.000000 < pT < 2.000000
5783   // v_{4} = 0.056187 for 2.000000 < pT < 4.000000
5784   //Double_t vn[] = { 0, 0.042293 * 0.060797, 0.040318 * 0.077353, 0.020557 * 0.056187 };
5785   
5786   switch (centrality)
5787   {
5788     case 0: // 0-2%, 1-2 times 2-3
5789 /*      v_{2} = 0.042240 for 1.000000 < pT < 2.000000
5790       v_{2} = 0.060385 for 2.000000 < pT < 3.000000
5791       v_{3} = 0.040230 for 1.000000 < pT < 2.000000
5792       v_{3} = 0.074648 for 2.000000 < pT < 3.000000
5793       v_{4} = 0.020487 for 1.000000 < pT < 2.000000
5794       v_{4} = 0.053341 for 2.000000 < pT < 3.000000*/
5795       Double_t vn[] = { 0, 0.042240 * 0.060385, 0.040230 * 0.074648, 0.020487 * 0.053341 };
5796       break;
5797   
5798     case 1: // 0-2%, 2-3 times 3-4
5799       // v_{2} = 0.058958 for 2.000000 < pT < 3.000000
5800       // v_{2} = 0.063784 for 3.000000 < pT < 4.000000
5801       // v_{3} = 0.072185 for 2.000000 < pT < 3.000000
5802       // v_{3} = 0.096924 for 3.000000 < pT < 4.000000
5803       // v_{4} = 0.049694 for 2.000000 < pT < 3.000000
5804       // v_{4} = 0.076772 for 3.000000 < pT < 4.000000
5805       Double_t vn[] = { 0, 0.058958 * 0.063784, 0.072185 * 0.096924, 0.049694 * 0.076772 };
5806       break;
5807       
5808       
5809 //     case 1: 
5810 //    /* v_{2} = 0.113591 for 2.000000 < pT < 3.000000
5811 //       v_{2} = 0.130848 for 3.000000 < pT < 4.000000
5812 //       v_{3} = 0.085376 for 2.000000 < pT < 3.000000
5813 //       v_{3} = 0.109396 for 3.000000 < pT < 4.000000
5814 //       v_{4} = 0.056515 for 2.000000 < pT < 3.000000
5815 //       v_{4} = 0.087579 for 3.000000 < pT < 4.000000*/
5816 //       Double_t vn[] = { 0, 0.113591 * 0.130848, 0.085376 * 0.109396, 0.056515 * 0.087579 };
5817 //       break;
5818 //       
5819 //     case 2:
5820 //       /*v_{2} = 0.205376 for 2.000000 < pT < 3.000000
5821 //       v_{2} = 0.224529 for 3.000000 < pT < 4.000000
5822 //       v_{3} = 0.104202 for 2.000000 < pT < 3.000000
5823 //       v_{3} = 0.124636 for 3.000000 < pT < 4.000000
5824 //       v_{4} = 0.069736 for 2.000000 < pT < 3.000000
5825 //       v_{4} = 0.098462 for 3.000000 < pT < 4.000000*/
5826 //       Double_t vn[] = { 0, 0.205376 * 0.224529, 0.104202 * 0.124636, 0.069736 * 0.098462 };
5827 //       break;
5828 //       
5829    case 2: // 30-40%, 1-2 times 2-3
5830       /*v_{2} = 0.170185 for 1.000000 < pT < 2.000000
5831       v_{2} = 0.236121 for 2.000000 < pT < 3.000000
5832       v_{3} = 0.068512 for 1.000000 < pT < 2.000000
5833       v_{3} = 0.115416 for 2.000000 < pT < 3.000000
5834       v_{4} = 0.037889 for 1.000000 < pT < 2.000000
5835       v_{4} = 0.079676 for 2.000000 < pT < 3.000000*/
5836       Double_t vn[] = { 0, 0.170185 * 0.236121, 0.068512 * 0.115416, 0.037889 * 0.079676 };
5837       break;
5838    
5839    case 3: // 30-40%, 2-3 times 3-4
5840       /*v_{2} = 0.231893 for 2.000000 < pT < 3.000000
5841       v_{2} = 0.243978 for 3.000000 < pT < 4.000000
5842       v_{3} = 0.111616 for 2.000000 < pT < 3.000000
5843       v_{3} = 0.131851 for 3.000000 < pT < 4.000000
5844       v_{4} = 0.075781 for 2.000000 < pT < 3.000000
5845       v_{4} = 0.107771 for 3.000000 < pT < 4.000000*/
5846
5847       Double_t vn[] = { 0, 0.231893 * 0.243978, 0.111616 * 0.131851, 0.075781 * 0.107771 };
5848       break;
5849   }
5850   
5851   TF1* flowFunc = new TF1("flowFunc", "[0] * (1+2*[1]*cos(2*x)+2*[2]*cos(3*x)+2*[3]*cos(4*x))", -0.5 * TMath::Pi(), 1.5 * TMath::Pi());
5852   //flowFunc->SetLineWidth(1);
5853   flowFunc->SetLineColor(2);
5854   flowFunc->SetLineStyle(2);
5855   for (Int_t i=0; i<3; i++)
5856     flowFunc->FixParameter(i+1, vn[i+1]);
5857   //flowFunc->SetParameter(0, 84.95); flowFunc->DrawClone("SAME");
5858   
5859   //flowFunc->SetParameter(0, 85.4); flowFunc->DrawClone("SAME");
5860   //flowFunc->SetParameter(0, 85.6); flowFunc->DrawClone("SAME");
5861   
5862   hist->Fit(flowFunc, "", "SAME", 1.8, 4.5);
5863   hist->GetYaxis()->SetRangeUser(hist->GetMinimum() * 0.95, hist->GetMaximum() * 1.05);
5864   flowFunc->SetRange(-0.5 * TMath::Pi(), 1.5 * TMath::Pi());
5865   flowFunc->Draw("SAME");
5866   
5867   //hist->GetYaxis()->SetRangeUser(84, 89);
5868   //flowFunc->SetParameter(4, 1);
5869   
5870   Float_t chi2 = 0;
5871   Int_t n=0;
5872   for (Int_t bin=hist->FindBin(1.8); bin<=hist->FindBin(4.5); bin++)
5873   {
5874     chi2 += TMath::Power((hist->GetBinContent(bin) - flowFunc->Eval(hist->GetBinCenter(bin))) / hist->GetBinError(bin), 2);
5875     n++;
5876     //Printf("%f", TMath::Power((hist->GetBinContent(bin) - flowFunc->Eval(hist->GetBinCenter(bin))) / hist->GetBinError(bin), 2));
5877   }
5878     
5879   chi2 /= n;
5880   
5881   Printf("chi2/ndf = %f", chi2);
5882   
5883   if (!plotContributions)
5884     return hist;
5885   
5886   for (Int_t n=1; n<=4; n++)
5887   {
5888     flowFuncPart = new TF1("flowFuncPart", "[0] * (1+2*[1]*cos([2]*x))", -0.5 * TMath::Pi(), 1.5 * TMath::Pi());
5889     flowFuncPart->SetParameters(flowFunc->GetParameter(0), vn[n-1], n);
5890     flowFuncPart->SetLineWidth(1);
5891     flowFuncPart->SetLineStyle(n);
5892     flowFuncPart->Draw("SAME");
5893   }
5894   
5895   return hist;
5896 }
5897
5898 void MACHConeAll(const char* fileName, Int_t twoD)
5899 {
5900   loadlibs();
5901
5902   SetFlowStyle();
5903
5904   c = new TCanvas("c", "c", 800, 800);
5905   c->Divide(2, 2);
5906   
5907   Float_t rangesMin[] = { 42, 5.6, 9.5, 1.2 };
5908   Float_t rangesMax[] = { 44, 6.2, 12, 1.9 };
5909   
5910   if (twoD == 11)
5911   {
5912     rangesMin[0] += 1;
5913     rangesMax[0] += 1;
5914   }
5915   
5916   for (Int_t i=0; i<4; i++)
5917   {
5918     c->cd(i+1);
5919     MACHCone(fileName, i, "", kTRUE, twoD)->GetYaxis()->SetRangeUser(rangesMin[i], rangesMax[i]);
5920   }
5921   
5922   c->SaveAs(Form("machcone_%d.png", twoD));
5923   c->SaveAs(Form("machcone_%d.eps", twoD));
5924   c->SaveAs(Form("machcone_%d.C", twoD));
5925   
5926   return;
5927   
5928   c->cd(1);
5929   MACHCone(3, "", kTRUE)->SetTitle("");
5930   
5931   c->cd(2);
5932   hist1 = MACHCone(0, "", kFALSE);
5933   hist2 = MACHCone(1, "SAME", kFALSE);
5934   hist3 = MACHCone(2, "SAME", kFALSE);
5935   
5936   hist1->SetTitle("");
5937   hist1->GetYaxis()->SetRangeUser(1, 7);
5938 }
5939   
5940 void SetFlowStyle()
5941 {
5942  // Set style which will affect all plots.
5943  
5944  gStyle->Reset();
5945  // gStyle->SetOptitle(0);
5946  // gStyle->SetOptStat(0);
5947  //gStyle->SetOptDate(1);
5948  // gStyle->SetPalette(8,0);  // (1,0)
5949  gStyle->SetPalette(1);  // (1,0)
5950  gStyle->SetDrawBorder(0);
5951  // gStyle->SetFillColor(0);  // kills palete ???
5952  gStyle->SetCanvasColor(0);
5953  gStyle->SetPadColor(0);
5954  // gStyle->SetFillColor(0); // otherwize it affects Fill colors later
5955  gStyle->SetFrameFillColor(0);
5956  gStyle->SetCanvasBorderMode(0);
5957  gStyle->SetFrameLineWidth(2);
5958  // gStyle->SetFrameFillStyle(4000);
5959  gStyle->SetPadBorderMode(0);
5960  gStyle->SetPadTickX(1);
5961  gStyle->SetPadTickY(1);
5962  gStyle->SetPadBottomMargin(0.15);
5963  gStyle->SetPadLeftMargin(0.15);
5964  gStyle->SetHistLineWidth(2);
5965  gStyle->SetFuncWidth(2);
5966  gStyle->SetLineWidth(2);
5967  gStyle->SetLabelSize(0.05,"xyz");
5968  gStyle->SetLabelOffset(0.01,"y");
5969  gStyle->SetLabelColor(kBlack,"xyz");
5970  gStyle->SetTitleSize(0.06,"xyz");
5971  gStyle->SetTitleOffset(1.3,"y");
5972  gStyle->SetTitleFillColor(0);
5973  gStyle->SetLineWidth(2);  
5974  gStyle->SetHistLineColor(1);
5975  gStyle->SetTextColor(1);
5976  gStyle->SetTitleTextColor(1);
5977  TGaxis::SetMaxDigits(4);
5978  gStyle->SetOptStat(0); // removes stat. box from all histos
5979  gROOT->ForceStyle();
5980
5981 } // end of void SetFlowStyle()
5982
5983 void PlotPtDistributionsSubtracted(const char* fileName1, Int_t centrBegin = 1, Int_t centrEnd = 6, Int_t fit = 0)
5984 {
5985   loadlibs();
5986
5987   Int_t nCentralityBins = 5;
5988   Int_t centralityBins[] = { 1, 7, 9, 11, 13, 16 };
5989   
5990   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName1);
5991     
5992   TCanvas* canvas = new TCanvas("Pt", "Pt", 1000, 1000);
5993   canvas->Divide(2, 2);
5994   
5995   TLegend* legend = new TLegend(0.3, 0.8, 0.99, 0.99);
5996   legend->SetFillColor(0);
5997   
5998   Int_t colors[] = { 1, 2, 4, 6, 3, 5 };
5999   Int_t markers[] = { 20, 21, 22, 23, 24, 25 };
6000   
6001   Double_t ptMin = 10.01;
6002   Double_t ptMax = 39.99;
6003     
6004   TString str;
6005   str.Form("%.1f < p_{T,trig} < %.1f", ptMin - 0.01, ptMax + 0.01);
6006   
6007   canvas->cd(1);
6008   gPad->SetLeftMargin(0.15);
6009   gPad->SetBottomMargin(0.2);
6010   gPad->SetTopMargin(0.01);
6011   gPad->SetRightMargin(0.01);
6012   gPad->SetLogy();
6013   gPad->SetLogx();
6014   gPad->SetGridx();
6015   gPad->SetGridy();
6016   
6017   TH2F* dummy = new TH2F("dummy", "", 100, 1, 40, 100, 1e-5, 1e3);
6018   dummy->SetStats(kFALSE);
6019   dummy->SetXTitle("p_{T,assoc}");
6020   dummy->SetYTitle("1/N_{trig} dN/dp_{T,assoc}");
6021   dummy->GetYaxis()->SetTitleOffset(1);
6022   Prepare1DPlot(dummy);
6023
6024   dummy->GetXaxis()->SetLabelSize(0.05);
6025   dummy->GetYaxis()->SetLabelSize(0.05);
6026   dummy->GetXaxis()->SetTitleSize(0.05);
6027   dummy->GetYaxis()->SetTitleSize(0.05);
6028   dummy->DrawCopy();
6029   
6030   canvas->cd(2);
6031   gPad->SetLeftMargin(0.15);
6032   gPad->SetBottomMargin(0.2);
6033   gPad->SetTopMargin(0.01);
6034   gPad->SetRightMargin(0.01);
6035   gPad->SetLogy();
6036   gPad->SetLogx();
6037   gPad->SetGridx();
6038   gPad->SetGridy();
6039   dummy->DrawCopy();
6040   
6041   canvas->cd(3);
6042   gPad->SetLeftMargin(0.15);
6043   gPad->SetBottomMargin(0.2);
6044   gPad->SetTopMargin(0.01);
6045   gPad->SetRightMargin(0.01);
6046   gPad->SetLogx();
6047   gPad->SetGridx();
6048   gPad->SetGridy();
6049   
6050   dummy = new TH2F("dummy2", "", 100, 1, 40, 100, 0, 100);
6051   dummy->SetStats(kFALSE);
6052   dummy->SetXTitle("p_{T,assoc}");
6053   dummy->SetYTitle("Ratio: Distribution / Inclusive");
6054   dummy->GetYaxis()->SetTitleOffset(1);
6055   Prepare1DPlot(dummy);
6056   dummy->GetXaxis()->SetLabelSize(0.05);
6057   dummy->GetYaxis()->SetLabelSize(0.05);
6058   dummy->GetXaxis()->SetTitleSize(0.05);
6059   dummy->GetYaxis()->SetTitleSize(0.05);
6060   dummy->DrawCopy();
6061   
6062   canvas->cd(4);
6063   gPad->SetLeftMargin(0.15);
6064   gPad->SetBottomMargin(0.2);
6065   gPad->SetTopMargin(0.01);
6066   gPad->SetRightMargin(0.01);
6067   gPad->SetLogx();
6068   gPad->SetGridx();
6069   gPad->SetGridy();
6070   dummy->DrawCopy();
6071   
6072   
6073   // see GetAcceptanceScalingFactor
6074   Float_t scalingFactor = 0.328396; // 0.8
6075   //Float_t scalingFactor = 0.433268; // 0.7
6076   //Float_t scalingFactor = 0.895593; // 0.5 --> 1.6
6077       
6078   Float_t phiRange[] = { 0, TMath::Pi() / 2, TMath::Pi() };
6079   const char* phiLabels[] = { "Towards", "Transverse", "Away" };
6080   
6081   //Float_t phiSizeTowards = TMath::Pi() / 3;
6082   Float_t phiSizeTowards = 0.75;
6083   //Float_t etaLimit = 0.5;
6084   Float_t etaLimit = 0.8;
6085   
6086   towardsCentralEta = h->GetUEHist(2)->GetPtHist(6, 0, ptMin, ptMax, centrBegin, centrEnd, phiRange[0] - phiSizeTowards, phiRange[0] + phiSizeTowards, -etaLimit + 0.01, etaLimit - 0.01);
6087   towardsSideEta1 = h->GetUEHist(2)->GetPtHist(6, 0, ptMin, ptMax, centrBegin, centrEnd, phiRange[0] - phiSizeTowards, phiRange[0] + phiSizeTowards, -1.59, -etaLimit - 0.01);
6088   TH1* towardsSideEta2 = h->GetUEHist(2)->GetPtHist(6, 0, ptMin, ptMax, centrBegin, centrEnd, phiRange[0] - phiSizeTowards, phiRange[0] + phiSizeTowards, etaLimit + 0.01, 1.59);
6089   towardsSideEta1->Add(towardsSideEta2); // TODO can be done smarter? what about the errors?
6090
6091   Prepare1DPlot(towardsSideEta1);
6092   Prepare1DPlot(towardsCentralEta);
6093   
6094   towardsCentralEta->SetLineColor(colors[0]);
6095   towardsSideEta1->SetLineColor(colors[3]);
6096   //towardsSideEta1->SetLineStyle(2);
6097
6098   legend->AddEntry(towardsCentralEta->Clone(), Form("Jet, %s: |#Delta#eta| < 0.8, #phi ~ %.1f", phiLabels[0], phiRange[0]));
6099   legend->AddEntry(towardsSideEta1->Clone(), Form("Ridge, %s: 0.8 < |#Delta#eta| < 1.6, #phi ~ %.1f", phiLabels[0], phiRange[0]));
6100   
6101   // TODO update when data with new phi binning is available
6102   transverse = h->GetUEHist(2)->GetPtHist(6, 0, ptMin, ptMax, centrBegin, centrEnd, phiRange[1] - TMath::Pi() / 3, phiRange[1] + TMath::Pi() / 3, -1.59, 1.59);
6103   /*
6104   transverse2 = h->GetUEHist(2)->GetPtHist(6, 0, ptMin, ptMax, centrBegin, centrEnd, -0.5 * TMath::Pi(), -TMath::Pi() / 3, -1.59, 1.59, kTRUE);
6105   transverse3 = h->GetUEHist(2)->GetPtHist(6, 0, ptMin, ptMax, centrBegin, centrEnd, TMath::Pi() + TMath::Pi() / 3, 1.5 * TMath::Pi(), -1.59, 1.59, kTRUE);
6106   transverse->Add(transverse2);
6107   transverse->Add(transverse3);
6108   transverse->Scale(1.0 / (2.0 / 3 * TMath::Pi()));
6109   */
6110     
6111   //transverseSideEta1 = h->GetUEHist(2)->GetPtHist(6, 0, ptMin, ptMax, centrBegin, centrEnd, phiRange[1] - TMath::Pi() / 4, phiRange[1] + TMath::Pi() / 4, -1.59, -0.81);
6112   //TH1* transverseSideEta2 = h->GetUEHist(2)->GetPtHist(6, 0, ptMin, ptMax, centrBegin, centrEnd, phiRange[1] - TMath::Pi() / 4, phiRange[1] + TMath::Pi() / 4, 0.81, 1.59);
6113   //transverseSideEta1->Add(transverseSideEta2); // TODO can be done smarter? what about the errors?
6114   
6115   transverse->SetLineColor(colors[2]);
6116   //transverseSideEta1->SetLineColor(colors[2]);
6117   //transverseSideEta1->SetLineStyle(2);
6118
6119   Prepare1DPlot(transverse);
6120   //Prepare1DPlot(transverseSideEta1);
6121   legend->AddEntry(transverse->Clone(), Form("%s: |#Delta#eta| < 1.6, #phi ~ %.1f", phiLabels[1], phiRange[1]));
6122   //legend->AddEntry(transverseSideEta1->Clone(), Form("%s: 0.8 < |#Delta #eta| < 1.6, #phi ~ %.1f", phiLabels[1], phiRange[1]));
6123   
6124   away = h->GetUEHist(2)->GetPtHist(6, 0, ptMin, ptMax, centrBegin, centrEnd, phiRange[2] - TMath::Pi() / 3, phiRange[2] + TMath::Pi() / 3, -1.59, 1.59);
6125
6126   /*
6127   away2 = h->GetUEHist(2)->GetPtHist(6, 0, ptMin, ptMax, centrBegin, centrEnd, phiRange[2] - TMath::Pi() / 4, phiRange[2] + TMath::Pi() / 4, -0.79, 0.79);
6128   away3 = h->GetUEHist(2)->GetPtHist(6, 0, ptMin, ptMax, centrBegin, centrEnd, phiRange[2] - TMath::Pi() / 4, phiRange[2] + TMath::Pi() / 4, -1.59, -0.81);
6129   away4 = h->GetUEHist(2)->GetPtHist(6, 0, ptMin, ptMax, centrBegin, centrEnd, phiRange[2] - TMath::Pi() / 4, phiRange[2] + TMath::Pi() / 4,  0.81, 1.59);
6130   away3->Add(away4);
6131   */
6132   
6133   away->SetLineColor(colors[1]);
6134   //away3->SetLineColor(colors[1]);
6135   //away3->SetLineStyle(2);
6136   
6137   Prepare1DPlot(away);
6138   legend->AddEntry(away->Clone(), Form("%s: |#Delta#eta| < 1.6, #phi ~ %.1f", phiLabels[2], phiRange[2]));
6139   
6140   //inclusive = h->GetUEHist(2)->GetPtHist(6, 0, ptMin, ptMax, centrBegin, centrEnd, -0.5 * TMath::Pi(), 1.5 * TMath::Pi(), -1.59, 1.59);
6141   
6142   /*
6143   h->GetUEHist(2)->GetEventHist()->GetGrid(6)->GetGrid()->GetAxis(1)->SetRange(centrBegin, centrEnd);
6144   inclusive = h->GetUEHist(2)->GetEventHist()->ShowProjection(0, 6);
6145   h->GetUEHist(2)->GetEventHist()->GetGrid(6)->GetGrid()->GetAxis(1)->SetRange(0, -1);
6146   */
6147   
6148   axis = h->GetUEHist(2)->GetEventHist()->GetGrid(6)->GetGrid()->GetAxis(1);
6149   
6150   inclusiveTmp = h->GetCorrelationpT()->ProjectionY("inclusiveTmp", h->GetCorrelationpT()->GetXaxis()->FindBin(axis->GetBinLowEdge(centrBegin) + 0.01), h->GetCorrelationpT()->GetXaxis()->FindBin(axis->GetBinUpEdge(centrEnd) - 0.01));
6151   
6152   //rebin to match other histograms
6153   //inclusive2 = inclusive->Rebin(away->GetNbinsX(), "inclusive2", away->GetXaxis()->GetXbins()->GetArray());
6154   
6155   // manually, as usual the ROOT function makes a SEGV
6156   inclusive = (TH1*) away->Clone("inclusive");
6157   inclusive->Reset();
6158   inclusive->Sumw2();
6159   for (Int_t bin=1; bin<=inclusiveTmp->GetNbinsX(); bin++)
6160     inclusive->Fill(inclusiveTmp->GetBinCenter(bin), inclusiveTmp->GetBinContent(bin));
6161   
6162   for (Int_t bin=1; bin<=inclusive->GetNbinsX(); bin++)
6163     inclusive->SetBinError(bin, TMath::Sqrt(inclusive->GetBinContent(bin)));
6164     
6165   // normalization: events, phase space
6166   inclusive->Scale(1.0 / h->GetCentralityDistribution()->Integral(centrBegin, centrEnd));
6167   inclusive->Scale(1.0 / (TMath::TwoPi() * 0.8 * 2));
6168   
6169   // bin width
6170   for (Int_t i=1; i<=inclusive->GetNbinsX(); i++)
6171   {
6172     inclusive->SetBinContent(i, inclusive->GetBinContent(i) / inclusive->GetXaxis()->GetBinWidth(i));
6173     inclusive->SetBinError  (i, inclusive->GetBinError(i) / inclusive->GetXaxis()->GetBinWidth(i));
6174   }
6175   
6176   Prepare1DPlot(inclusive);
6177   inclusive->SetLineColor(colors[4]);
6178   legend->AddEntry(inclusive->Clone(), "Inclusive");
6179   
6180   //Prepare1DPlot(away3);
6181   //legend->AddEntry(away3->Clone(), Form("%s: 0.8 < |#Delta #eta| < 1.6, #phi ~ %.1f", phiLabels[2], phiRange[2]));
6182   
6183   // scale for acceptance to match acceptance of towardsCentralEta
6184   towardsSideEta1->Scale(1.0 / scalingFactor); // contains only "side-eta"
6185   transverse->Scale(1.0 / (1.0 + scalingFactor)); // full eta
6186   away->Scale(1.0 / (1.0 + scalingFactor)); // full eta
6187   inclusive->Scale(1.0 / (1.0 + scalingFactor)); // full eta (phi scaling implicit)
6188   
6189   canvas->cd(1);
6190   towardsCentralEtaClone = towardsCentralEta->DrawCopy("SAME");
6191   towardsSideEta1Clone = towardsSideEta1->DrawCopy("SAME");
6192   transverseClone = transverse->DrawCopy("SAME");
6193   //transverseSideEta1->DrawCopy("SAME");
6194   awayClone = away->DrawCopy("SAME");
6195   inclusiveClone = inclusive->DrawCopy("SAME");
6196   //inclusive2->DrawCopy("SAME");
6197   //away3->DrawCopy("SAME");
6198   
6199   canvas->cd(3);
6200   
6201   towardsCentralEtaR = (TH1*) towardsCentralEta->Clone("towardsCentralEtaR");
6202   towardsSideEta1R = (TH1*) towardsSideEta1->Clone("towardsSideEta1R");
6203   transverseR = (TH1*) transverse->Clone("transverseR");
6204   awayR = (TH1*) away->Clone("awayR");
6205   
6206   towardsCentralEtaR->Divide(inclusive);
6207   towardsSideEta1R->Divide(inclusive);
6208   transverseR->Divide(inclusive);
6209   awayR->Divide(inclusive);
6210   
6211   towardsCentralEtaR->DrawCopy("SAME");
6212   towardsSideEta1R->DrawCopy("SAME");
6213   transverseR->DrawCopy("SAME");
6214   awayR->DrawCopy("SAME");
6215   
6216   if (fit == 1)
6217   {
6218     canvas->cd(1);
6219     
6220     awayClone->Fit("expo", "", "SAME", 1.1, 2.9);
6221     awayClone->GetFunction("expo")->SetRange(1, 10);
6222     gPad->SetLogx(0);
6223   }
6224   else if (fit == 2)
6225   {
6226     canvas->cd(1);
6227     
6228     func = new TF1("func", "[0] * x**[1]");
6229     func->SetParameters(1, 1);
6230     
6231     Float_t limitLow = 2.1;
6232     Float_t limitHigh = 4.9;
6233     
6234     func2 = (TF1*) func->Clone();
6235     towardsCentralEtaClone->Fit(func2, "", "SAME", limitLow, limitHigh);
6236     towardsCentralEtaClone->GetFunction("func")->SetRange(1, 10);
6237     towardsCentralEtaClone->GetFunction("func")->SetLineColor(towardsCentralEtaClone->GetLineColor());
6238     
6239     func2 = (TF1*) func->Clone();
6240     towardsSideEta1Clone->Fit(func2, "", "SAME", limitLow, limitHigh);
6241     towardsSideEta1Clone->GetFunction("func")->SetRange(1, 10);
6242     towardsSideEta1Clone->GetFunction("func")->SetLineColor(towardsSideEta1Clone->GetLineColor());
6243   
6244     func2 = (TF1*) func->Clone();
6245     transverseClone->Fit(func2, "", "SAME", limitLow, limitHigh);
6246     transverseClone->GetFunction("func")->SetRange(1, 10);
6247     transverseClone->GetFunction("func")->SetLineColor(transverseClone->GetLineColor());
6248   
6249     func2 = (TF1*) func->Clone();
6250     awayClone->Fit(func2, "", "SAME", limitLow, limitHigh);
6251     awayClone->GetFunction("func")->SetRange(1, 10);
6252     awayClone->GetFunction("func")->SetLineColor(awayClone->GetLineColor());
6253   
6254     func2 = (TF1*) func->Clone();
6255     inclusiveClone->Fit(func2, "", "SAME", limitLow, limitHigh);
6256     inclusiveClone->GetFunction("func")->SetRange(1, 10);
6257     inclusiveClone->GetFunction("func")->SetLineColor(inclusiveClone->GetLineColor());
6258   }
6259   
6260   // subtract transverse part
6261   away->Add(transverse, -1);
6262   //away3->Add(transverseSideEta1, -1);
6263   towardsCentralEta->Add(transverse, -1);
6264   towardsSideEta1->Add(transverse, -1);
6265   //inclusive->Add(transverse, -1);
6266   
6267   canvas->cd(2);
6268   towardsCentralEta->DrawCopy("SAME");
6269   towardsSideEta1->DrawCopy("SAME");
6270   away->DrawCopy("SAME");
6271   inclusive->DrawCopy("SAME");
6272   //away3->DrawCopy("SAME");
6273   
6274   canvas->cd(4);
6275   
6276   towardsCentralEtaR = (TH1*) towardsCentralEta->Clone("towardsCentralEtaR2");
6277   towardsSideEta1R = (TH1*) towardsSideEta1->Clone("towardsSideEta1R2");
6278   awayR = (TH1*) away->Clone("awayR2");
6279   
6280   towardsCentralEtaR->Divide(inclusive);
6281   towardsSideEta1R->Divide(inclusive);
6282   awayR->Divide(inclusive);
6283   
6284   towardsCentralEtaR->DrawCopy("SAME");
6285   towardsSideEta1R->DrawCopy("SAME");
6286   awayR->DrawCopy("SAME");
6287   
6288   if (fit == 1)
6289   {
6290     canvas->cd(2);
6291     
6292     away->Fit("expo", "", "SAME", 1.1, 2.9);
6293     away->GetFunction("expo")->SetRange(1, 10);
6294     gPad->SetLogx(0);
6295   }
6296   else if (fit == 2)
6297   {
6298     canvas->cd(2);
6299     
6300     func = new TF1("func", "[0] * x**[1]");
6301     func->SetParameters(1, 1);
6302     
6303     func2 = (TF1*) func->Clone();
6304     towardsCentralEta->Fit(func2, "", "SAME", limitLow, limitHigh);
6305     func2->SetRange(1, 10);
6306     
6307     func2 = (TF1*) func->Clone();
6308     towardsSideEta1->Fit(func2, "", "SAME", limitLow, limitHigh);
6309     func2->SetRange(1, 10);
6310   
6311     func2 = (TF1*) func->Clone();
6312     away->Fit(func2, "", "SAME", limitLow, limitHigh);
6313     func2->SetRange(1, 10);
6314   
6315     func2 = (TF1*) func->Clone();
6316     inclusive->Fit(func2, "", "SAME", limitLow, limitHigh);
6317     func2->SetRange(1, 10);
6318   }
6319   
6320   for (Int_t i=1; i<=2; i++)
6321   {
6322     canvas->cd(i);
6323     
6324     TString str3;
6325     str3.Form("%d-%d%%", (Int_t) h->GetCentralityDistribution()->GetXaxis()->GetBinLowEdge(centrBegin), (Int_t) h->GetCentralityDistribution()->GetXaxis()->GetBinUpEdge(centrEnd));
6326     latex = new TLatex(0.2, 0.3, str3);
6327     latex->SetNDC();
6328     latex->SetTextSize(0.06);
6329     
6330     latex2 = new TLatex(0.55, 0.6, str);
6331     latex2->SetNDC();
6332     latex2->SetTextSize(0.06);
6333     
6334     latex->Draw();
6335     latex2->Draw();
6336     
6337     legend->Draw();
6338   }
6339 }
6340
6341 void CombineDeltaPhiWithWeighting()
6342 {
6343   // From Hermes:
6344   // For LHC11a2a:
6345   // xsection: 11.879829,  ntrials: 8132994.000000
6346   // 
6347   // For LHC11a2b:
6348   // xsection: 0.623421,  ntrials: 2293420.000000
6349   // 
6350   // For LHC11a2c:
6351   // xsection: 0.043815,  ntrials: 1314525.375000
6352   
6353   // TODO is merging only same event distribution at present
6354   
6355   loadlibs();
6356   
6357   Int_t nInput = 3;
6358   const char* inputList[] = { "mergejob/LHC11a2a_110124.root", "mergejob/LHC11a2b_110131.root", "mergejob/LHC11a2c_110131.root" };
6359   
6360   Float_t xSections[] = { 11.879829 * 1e6 / 8132994, 0.623421 * 1e6 / 2293420, 0.043815 * 1e6 / 1314525 };
6361   xSections[2] /= xSections[0];
6362   xSections[1] /= xSections[0];
6363   xSections[0] /= xSections[0];
6364   
6365   AliUEHistograms* files[3];
6366   TList* finalList = 0;
6367   for (Int_t i=0; i<nInput; i++)
6368   {
6369     files[i] = (AliUEHistograms*) GetUEHistogram(inputList[i], (i == 0) ? &finalList : 0);
6370     if (i > 0) 
6371     {
6372       files[i]->Scale(xSections[i]);
6373       
6374       TList* list2 = new TList;
6375       list2->Add(files[i]);
6376       files[0]->Merge(list2);
6377     }
6378   }
6379   
6380   TFile* file3 = TFile::Open("out.root", "RECREATE");
6381   file3->mkdir("PWG4_PhiCorrelations");
6382   file3->cd("PWG4_PhiCorrelations");
6383   finalList->Write(0, TObject::kSingleKey);
6384   file3->Close();       
6385 }
6386
6387 void NormalizeToBinWidth(TH1* hist)
6388 {
6389   //
6390   // normalizes a 1-d histogram to its bin width
6391   //
6392
6393   for (Int_t i=1; i<=hist->GetNbinsX(); ++i)
6394   {
6395     hist->SetBinContent(i, hist->GetBinContent(i) / hist->GetBinWidth(i));
6396     hist->SetBinError(i, hist->GetBinError(i) / hist->GetBinWidth(i));
6397   }
6398 }
6399
6400 void GetAcceptanceScalingFactor(const char* fileName1, Float_t eta1 = 0.8, Float_t eta2 = 1.6)
6401 {
6402   loadlibs();
6403
6404   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName1, 0, kTRUE);
6405   h->SetPtRange(1.01, 39.99);
6406  
6407   new TCanvas;
6408   mixed = ((TH2*)h->GetUEHist(2)->GetUEHist(6, 0, 1.01, 39.99, 0, 16, kTRUE))->ProjectionY();
6409   mixed->DrawCopy();
6410   
6411   Float_t left = mixed->Integral(mixed->FindBin(-eta2 + 0.01), mixed->FindBin(-eta1 - 0.01));
6412   Float_t center = mixed->Integral(mixed->FindBin(-eta1 + 0.01), mixed->FindBin(eta1 - 0.01));
6413   Float_t right = mixed->Integral(mixed->FindBin(eta1 + 0.01), mixed->FindBin(eta2 - 0.01));
6414   
6415   Printf("%f %f %f", left, center, right);
6416   Printf("%f", (left + right) / center);
6417 }
6418
6419 void TrackingEfficiencyCentralityDependence(const char* fileName, Int_t step1 = 2, Int_t step2 = 4)
6420 {
6421   Int_t nCentralityBins = 3;
6422   Float_t centralityBins[] = { 0, 20, 40, 90 };
6423   
6424   Int_t colors[] = { 1, 2, 4, 6 };
6425
6426   loadlibs();
6427
6428   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
6429   
6430   new TCanvas;
6431   dummy = new TH2F("dummy", ";p_{T};tracking efficiency", 100, 0, 20, 100, 0.7, 1.3);
6432   dummy->SetStats(0);
6433   dummy->Draw();
6434   
6435   legend = new TLegend(0.13, 0.67, 0.31, 0.87);
6436   legend->SetTextSize(0.04);
6437   legend->SetFillColor(0);
6438   
6439   for (Int_t i=0; i<nCentralityBins; i++)
6440   {
6441     eventHist = h->GetUEHist(2)->GetEventHist();
6442     
6443     eventHist->GetGrid(step1)->SetRangeUser(1, centralityBins[i] + 0.1, centralityBins[i+1] - 0.1);
6444     eventHist->GetGrid(step2)->SetRangeUser(1, centralityBins[i] + 0.1, centralityBins[i+1] - 0.1);
6445   
6446     TH1* hist1 = eventHist->ShowProjection(0, step1);
6447     TH1* hist2 = eventHist->ShowProjection(0, step2);
6448     
6449     hist2->Divide(hist1);
6450     
6451     hist2->SetLineColor(colors[i]);
6452     hist2->GetYaxis()->SetTitle("tracking efficiency");
6453     hist2->Draw("SAME");
6454     
6455     legend->AddEntry(hist2, Form("%.0f-%.0f%%", centralityBins[i], centralityBins[i+1]));
6456   }
6457   
6458   legend->Draw();
6459 }
6460
6461
6462 TGraphErrors* ReadHepdata(const char* fileName, Bool_t errorsAreAdded = kFALSE, Int_t skipYErrors = 0, Int_t skipXerrors = 1)
6463 {
6464   // expected format: x [x2] y [ye] [ye2] [xe]
6465   //
6466   // skipYErrors:   0 --> ye present
6467   //                1 --> no errors ye
6468   //                2 --> y and ye are lower and upper error, i.e. y' = (y + ye) / 2 and ye = (ye - y) / 2
6469   //                3 --> ye and ye2 are stat and syst error, will be added in quadrature
6470   // 
6471   // skipXerrors:   0 --> xe present
6472   //                1 --> no errors xe
6473   //                2 --> x2 present, xe not present and is calculated from x2 - x
6474   
6475   ifstream fin(fileName);
6476
6477   graph = new TGraphErrors(0);
6478
6479   Double_t sum = 0;
6480
6481   while (fin.good())
6482   {
6483     char buffer[2000];
6484     if (fin.peek() == '#')
6485     {
6486       fin.getline(buffer, 2000);
6487       continue;
6488     }
6489   
6490     Double_t x = -1;
6491     Double_t x2 = -1;
6492     Double_t y = -1;
6493     Double_t ye = 0;
6494     Double_t xe = 0;
6495
6496     fin >> x;
6497     
6498     if (skipXerrors == 2)
6499     {
6500       fin >> x2;
6501       xe = (x2 - x + 1) / 2;
6502       x = x + (x2 - x) / 2;
6503     }
6504     
6505     fin >> y;
6506
6507     if (y == -1)
6508       continue;
6509
6510     if (skipYErrors == 0)
6511     {
6512       ye = -1;
6513       fin >> ye;
6514       if (ye == -1)
6515         continue;
6516     }
6517     else if (skipYErrors == 2)
6518     {
6519       ye = -1;
6520       fin >> ye;
6521       if (ye == -1)
6522         continue;
6523       
6524       Double_t newy = (y + ye) / 2;
6525       ye = (ye - y) / 2;
6526       y = newy;
6527     }
6528     else if (skipYErrors == 3)
6529     {
6530       ye = -1;
6531       fin >> ye;
6532       if (ye == -1)
6533         continue;
6534       
6535       Double_t ye2 = -1;
6536       fin >> ye2;
6537       if (ye2 == -1)
6538         continue;
6539
6540       ye = TMath::Sqrt(ye*ye + ye2*ye2);
6541     }
6542
6543     if (skipXerrors == 0)
6544     {
6545       xe = -1;
6546       fin >> xe;
6547       if (xe == -1)
6548         continue;
6549     }
6550
6551     //Printf("%f %f %f %f", x, y, xe, ye);
6552
6553     if (errorsAreAdded)
6554       ye -= y;
6555
6556     graph->SetPoint(graph->GetN(), x, y);
6557     graph->SetPointError(graph->GetN()-1, xe, ye);
6558
6559     sum += y;
6560     
6561     // read rest until end of line...
6562     fin.getline(buffer, 2000);
6563   }
6564   fin.close();
6565
6566   Printf("%s: %f", fileName, sum);
6567
6568   return graph;
6569 }
6570
6571 void EvaluateParticleEfficiency(const char* fileName)
6572 {
6573   Int_t centralityBegin = 1;
6574   Int_t centralityEnd = 15;
6575   
6576   if (1)
6577   {
6578     Int_t step1 = 4;
6579     Int_t step2 = 5;
6580   }
6581   else
6582   {
6583     Int_t step1 = 2;
6584     Int_t step2 = 4;
6585   }
6586   
6587   Float_t ptTriggerBegin = 4.01;
6588   Float_t ptTriggerEnd = 19.99;
6589   
6590   Bool_t verbose = 1;
6591   
6592   loadlibs();
6593   
6594   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
6595   AliUEHist* cont = h->GetUEHist(2);
6596   
6597   cont->GetEventHist()->GetGrid(step1)->GetGrid()->GetAxis(1)->SetRange(centralityBegin, centralityEnd);
6598   cont->GetEventHist()->GetGrid(step2)->GetGrid()->GetAxis(1)->SetRange(centralityBegin, centralityEnd);
6599   
6600   Int_t stepEff1 = step1 - (Int_t) AliUEHist::kCFStepAnaTopology;
6601   if (stepEff1 == -1)
6602     stepEff1 = 0;
6603   Int_t stepEff2 = step2 - (Int_t) AliUEHist::kCFStepAnaTopology;
6604   if (stepEff2 == -1)
6605     stepEff2 = 0;
6606   
6607   cont->GetTrackHistEfficiency()->GetGrid(stepEff1)->GetGrid()->GetAxis(3)->SetRange(centralityBegin, centralityEnd);
6608   cont->GetTrackHistEfficiency()->GetGrid(stepEff2)->GetGrid()->GetAxis(3)->SetRange(centralityBegin, centralityEnd);
6609   
6610   TH1* triggerParticle = cont->GetEventHist()->Project(step2, 0);
6611   triggerParticle->Divide(cont->GetEventHist()->Project(step1, 0));
6612   
6613   TH1* singleParticle = cont->GetTrackHistEfficiency()->Project(stepEff2, 1);
6614   singleParticle->Divide(cont->GetTrackHistEfficiency()->Project(stepEff1, 1));
6615   
6616   //singleParticle = singleParticle->Rebin(triggerParticle->GetNbinsX(), "singleRebin", triggerParticle->GetXaxis()->GetXbins()->GetArray());
6617   
6618   TGraphErrors* effectiveEffect = new TGraphErrors;
6619   TGraphErrors* triggerCorrelatedEffect = new TGraphErrors;
6620   TGraphErrors* afterBaseLine = new TGraphErrors;
6621   TGraphErrors* triggerCorrelatedEffect2D = new TGraphErrors;
6622   
6623   //TVirtualFitter::SetDefaultFitter("Linear");
6624   
6625   for (Int_t bin=3; bin<=triggerParticle->GetNbinsX(); bin++)
6626   {
6627     if (triggerParticle->GetBinCenter(bin) > 10)
6628       continue;
6629     
6630     cont->SetPtRange(triggerParticle->GetXaxis()->GetBinLowEdge(bin) + 0.01, triggerParticle->GetXaxis()->GetBinUpEdge(bin) - 0.01);
6631       
6632     TH1* hist1 = cont->GetUEHist(step1, 0, ptTriggerBegin, ptTriggerEnd, centralityBegin, centralityEnd);
6633     TH1* hist2 = cont->GetUEHist(step2, 0, ptTriggerBegin, ptTriggerEnd, centralityBegin, centralityEnd);
6634     
6635     // TODO the uncertainties on the ratios should be properly calculated! (if that helps ;))
6636     clone = (TH1*) hist2->Clone("clone");
6637     clone->Divide(hist1);
6638     
6639     //func = new TF1("func", "[0]", -10, 10);
6640     
6641     if ((Int_t) clone->Fit("pol0", "0", "", -10, 10) == 0)
6642     {
6643       func = clone->GetFunction("pol0");
6644       effectiveEffect->SetPoint(effectiveEffect->GetN(), triggerParticle->GetBinCenter(bin) - 0.2, func->GetParameter(0));
6645       effectiveEffect->SetPointError(effectiveEffect->GetN()-1, 0, func->GetParError(0));
6646       
6647       if (verbose)
6648       {
6649         new TCanvas;
6650         clone->GetYaxis()->SetRangeUser(0.9, 1.3);
6651         clone->Draw();
6652         func->DrawClone("SAME");
6653       }
6654     }
6655     
6656     if ((Int_t) clone->Fit("pol0", "0", "", -0.3, 0.3) == 0)
6657     {
6658       func = clone->GetFunction("pol0");
6659       triggerCorrelatedEffect->SetPoint(triggerCorrelatedEffect->GetN(), triggerParticle->GetBinCenter(bin) - 0.1, func->GetParameter(0));
6660       triggerCorrelatedEffect->SetPointError(triggerCorrelatedEffect->GetN()-1, 0, func->GetParError(0));
6661       
6662       if (verbose)
6663       {
6664         func->SetLineColor(2);
6665         func->DrawClone("SAME");
6666       }
6667     }
6668     
6669     if ((Int_t) hist2->Fit("pol0", "0", "", 1, 2) == 0)
6670     {
6671       func = hist2->GetFunction("pol0");
6672       func->SetRange(-10, 10);
6673       hist2->Add(func, -1);
6674     
6675       if ((Int_t) hist1->Fit("pol0", "0", "", 1, 2) == 0)
6676       {
6677         func = hist1->GetFunction("pol0");
6678         func->SetRange(-10, 10);
6679         hist1->Add(func, -1);
6680         
6681         //new TCanvas; hist1->DrawCopy();
6682         
6683         hist2->Divide(hist1);
6684         
6685         if ((Int_t) hist2->Fit("pol0", "0", "", -0.3, 0.3) == 0)
6686         {
6687           func = hist2->GetFunction("pol0");
6688           afterBaseLine->SetPoint(afterBaseLine->GetN(), triggerParticle->GetBinCenter(bin) + 0.2, func->GetParameter(0));
6689           afterBaseLine->SetPointError(afterBaseLine->GetN()-1, 0, func->GetParError(0));
6690         
6691           if (verbose)
6692           {
6693             new TCanvas;
6694             hist2->GetYaxis()->SetRangeUser(0.9, 1.3);
6695             hist2->DrawCopy();
6696             func->SetLineColor(4);
6697             func->DrawClone("SAME");
6698           }
6699         }
6700       }
6701     }
6702       
6703     // 2d
6704     TH2* hist1_2D = cont->GetUEHist(step1, 0, ptTriggerBegin, ptTriggerEnd, centralityBegin, centralityEnd, 1);
6705     TH2* hist2_2D = cont->GetUEHist(step2, 0, ptTriggerBegin, ptTriggerEnd, centralityBegin, centralityEnd, 1);
6706     
6707     //((TH2*)hist1)->Rebin2D(2, 2); ((TH2*)hist2)->Rebin2D(2, 2);
6708     
6709     hist2_2D->Divide(hist1_2D);
6710     
6711     if (verbose)
6712     {
6713       new TCanvas;
6714       hist2_2D->Draw("COLZ");
6715     }
6716     
6717     //Printf("%d %d %d %d", hist2_2D->GetXaxis()->FindBin(-0.01), hist2_2D->GetXaxis()->FindBin(0.01), hist2_2D->GetYaxis()->FindBin(-0.01), hist2_2D->GetYaxis()->FindBin(0.01));
6718     
6719     Double_t error;
6720     Float_t integral = hist2_2D->IntegralAndError(hist2_2D->GetXaxis()->FindBin(-0.01), hist2_2D->GetXaxis()->FindBin(0.01), hist2_2D->GetYaxis()->FindBin(-0.01), hist2_2D->GetYaxis()->FindBin(0.01), error);
6721     
6722     integral /= hist2_2D->GetXaxis()->FindBin(0.01) - hist2_2D->GetXaxis()->FindBin(-0.01) + 1;
6723     integral /= hist2_2D->GetYaxis()->FindBin(0.01) - hist2_2D->GetYaxis()->FindBin(-0.01) + 1;
6724     
6725     error /= hist2_2D->GetXaxis()->FindBin(0.01) - hist2_2D->GetXaxis()->FindBin(-0.01) + 1;
6726     error /= hist2_2D->GetYaxis()->FindBin(0.01) - hist2_2D->GetYaxis()->FindBin(-0.01) + 1;
6727     
6728     triggerCorrelatedEffect2D->SetPoint(triggerCorrelatedEffect2D->GetN(), triggerParticle->GetBinCenter(bin) + 0.1, integral);
6729     triggerCorrelatedEffect2D->SetPointError(triggerCorrelatedEffect2D->GetN()-1, 0, error);
6730     
6731     if (verbose)
6732       break;
6733   }
6734   
6735   new TCanvas;
6736   triggerParticle->Draw();
6737   triggerParticle->GetXaxis()->SetRangeUser(0, 9.9);
6738   
6739   singleParticle->SetLineColor(2);
6740   //singleParticle->Draw("SAME");
6741   
6742   effectiveEffect->SetMarkerStyle(24);
6743   effectiveEffect->Draw("PSAME");
6744   
6745   triggerCorrelatedEffect->SetMarkerStyle(25);
6746   triggerCorrelatedEffect->SetMarkerColor(2);
6747   triggerCorrelatedEffect->SetLineColor(2);
6748   triggerCorrelatedEffect->Draw("PSAME");
6749   
6750   triggerCorrelatedEffect2D->SetMarkerStyle(27);
6751   triggerCorrelatedEffect2D->SetMarkerColor(3);
6752   triggerCorrelatedEffect2D->SetLineColor(3);
6753   triggerCorrelatedEffect2D->Draw("PSAME");
6754   
6755   afterBaseLine->SetMarkerStyle(26);
6756   afterBaseLine->SetMarkerColor(4);
6757   afterBaseLine->SetLineColor(4);
6758   afterBaseLine->Draw("PSAME");
6759
6760   legend = new TLegend(0.66, 0.15, 0.88, 0.38);
6761   legend->SetFillColor(0);
6762   legend->SetTextSize(0.04);
6763   legend->AddEntry(triggerParticle, "trigger", "L");
6764   //legend->AddEntry(singleParticle, "single", "L");
6765   legend->AddEntry(effectiveEffect, "effective", "P");
6766   legend->AddEntry(triggerCorrelatedEffect, "at 0", "P");
6767   legend->AddEntry(triggerCorrelatedEffect2D, "at 0 (2d)", "P");
6768   legend->AddEntry(afterBaseLine, "baseline", "P");
6769   legend->Draw();
6770 }
6771
6772 void EvaluateParticleEfficiency2D(const char* fileName)
6773 {
6774   Int_t centralityBegin = 1;
6775   Int_t centralityEnd = 15;
6776   
6777   if (1)
6778   {
6779     Int_t step1 = 4;
6780     Int_t step2 = 5;
6781   }
6782   else
6783   {
6784     Int_t step1 = 2;
6785     Int_t step2 = 4;
6786   }
6787   
6788   Bool_t verbose = 0;
6789   
6790   loadlibs();
6791   
6792   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
6793   AliUEHist* cont = h->GetUEHist(2);
6794   
6795   cont->GetEventHist()->GetGrid(step1)->GetGrid()->GetAxis(1)->SetRange(centralityBegin, centralityEnd);
6796   cont->GetEventHist()->GetGrid(step2)->GetGrid()->GetAxis(1)->SetRange(centralityBegin, centralityEnd);
6797   
6798   Int_t stepEff1 = step1 - (Int_t) AliUEHist::kCFStepAnaTopology;
6799   if (stepEff1 == -1)
6800     stepEff1 = 0;
6801   Int_t stepEff2 = step2 - (Int_t) AliUEHist::kCFStepAnaTopology;
6802   if (stepEff2 == -1)
6803     stepEff2 = 0;
6804   
6805   cont->GetTrackHistEfficiency()->GetGrid(stepEff1)->GetGrid()->GetAxis(3)->SetRange(centralityBegin, centralityEnd);
6806   cont->GetTrackHistEfficiency()->GetGrid(stepEff2)->GetGrid()->GetAxis(3)->SetRange(centralityBegin, centralityEnd);
6807   
6808   TH1* triggerParticle = cont->GetEventHist()->Project(step2, 0);
6809   triggerParticle->Divide(cont->GetEventHist()->Project(step1, 0));
6810   
6811   TH1* singleParticle = cont->GetTrackHistEfficiency()->Project(stepEff2, 1);
6812   singleParticle->Divide(cont->GetTrackHistEfficiency()->Project(stepEff1, 1));
6813   
6814   cont->GetTrackHist(0)->GetGrid(step1)->SetRangeUser(0, -0.01, 0.01); // delta eta
6815   cont->GetTrackHist(0)->GetGrid(step1)->SetRangeUser(4, -0.01, 0.01); // delta phi
6816   TH2* tracksStep1 = (TH2*) cont->GetTrackHist(0)->Project(step1, 1, 2);
6817   
6818   cont->GetTrackHist(0)->GetGrid(step2)->SetRangeUser(0, -0.01, 0.01); // delta eta
6819   cont->GetTrackHist(0)->GetGrid(step2)->SetRangeUser(4, -0.01, 0.01); // delta phi
6820   TH2* tracksStep2 = (TH2*) cont->GetTrackHist(0)->Project(step2, 1, 2);
6821   
6822   tracksStep2->Divide(tracksStep1);
6823   
6824   TH1* triggersStep1 = cont->GetEventHist()->Project(step1, 0);
6825   TH1* triggersStep2 = cont->GetEventHist()->Project(step2, 0);
6826   
6827   for (Int_t x=1; x<=tracksStep2->GetNbinsX(); x++)
6828     for (Int_t y=1; y<=tracksStep2->GetNbinsY(); y++)
6829       if (singleParticle->GetBinContent(x) > 0)
6830         tracksStep2->SetBinContent(x, y, tracksStep2->GetBinContent(x, y) / triggersStep2->GetBinContent(y) * triggersStep1->GetBinContent(y) / singleParticle->GetBinContent(x));
6831       else
6832         tracksStep2->SetBinContent(x, y, 0);
6833   
6834   new TCanvas;
6835   tracksStep2->Draw("COLZ");
6836   
6837   TGraphErrors** triggerCorrelatedEffect2D = new TGraphErrors*[triggerParticle->GetNbinsX()+1];
6838   TGraphErrors** triggerCorrelatedEffect2DSub = new TGraphErrors*[triggerParticle->GetNbinsX()+1];
6839   
6840   for (Int_t bin1=0; bin1<=triggerParticle->GetNbinsX(); bin1++)
6841   {
6842     triggerCorrelatedEffect2D[bin1] = 0;
6843     triggerCorrelatedEffect2DSub[bin1] = 0;
6844   }
6845   
6846   for (Int_t bin1=5; bin1<=triggerParticle->GetNbinsX(); bin1++)
6847   {
6848     if (triggerParticle->GetBinCenter(bin1) > 10)
6849       continue;
6850     
6851     Float_t ptTriggerBegin = triggerParticle->GetXaxis()->GetBinLowEdge(bin1) + 0.01;
6852     Float_t ptTriggerEnd = triggerParticle->GetXaxis()->GetBinUpEdge(bin1) - 0.01;
6853     
6854     for (Int_t bin2=3; bin2<=triggerParticle->GetNbinsX(); bin2++)
6855     {
6856       if (triggerParticle->GetBinCenter(bin2) > 8)
6857         continue;
6858         
6859       if (bin2 > bin1)
6860         continue;
6861     
6862       cont->SetPtRange(triggerParticle->GetXaxis()->GetBinLowEdge(bin2) + 0.01, triggerParticle->GetXaxis()->GetBinUpEdge(bin2) - 0.01);
6863   
6864       // 2d
6865       TH2* hist1_2D = cont->GetUEHist(step1, 0, ptTriggerBegin, ptTriggerEnd, centralityBegin, centralityEnd, 1);
6866       TH2* hist2_2D = cont->GetUEHist(step2, 0, ptTriggerBegin, ptTriggerEnd, centralityBegin, centralityEnd, 1);
6867       
6868       //((TH2*)hist1)->Rebin2D(2, 2); ((TH2*)hist2)->Rebin2D(2, 2);
6869       
6870       hist2_2D->Divide(hist1_2D);
6871       
6872       if (verbose)
6873       {
6874         new TCanvas;
6875         hist2_2D->Draw("COLZ");
6876       }
6877       
6878       //Printf("%d %d %d %d", hist2_2D->GetXaxis()->FindBin(-0.01), hist2_2D->GetXaxis()->FindBin(0.01), hist2_2D->GetYaxis()->FindBin(-0.01), hist2_2D->GetYaxis()->FindBin(0.01));
6879       
6880       Double_t error;
6881       Float_t integral = hist2_2D->IntegralAndError(hist2_2D->GetXaxis()->FindBin(-0.01), hist2_2D->GetXaxis()->FindBin(0.01), hist2_2D->GetYaxis()->FindBin(-0.01), hist2_2D->GetYaxis()->FindBin(0.01), error);
6882       
6883       integral /= hist2_2D->GetXaxis()->FindBin(0.01) - hist2_2D->GetXaxis()->FindBin(-0.01) + 1;
6884       integral /= hist2_2D->GetYaxis()->FindBin(0.01) - hist2_2D->GetYaxis()->FindBin(-0.01) + 1;
6885       
6886       error /= hist2_2D->GetXaxis()->FindBin(0.01) - hist2_2D->GetXaxis()->FindBin(-0.01) + 1;
6887       error /= hist2_2D->GetYaxis()->FindBin(0.01) - hist2_2D->GetYaxis()->FindBin(-0.01) + 1;
6888       
6889       if (integral <= 0)
6890         continue;
6891       
6892       if (!triggerCorrelatedEffect2D[bin1])
6893         triggerCorrelatedEffect2D[bin1] = new TGraphErrors;
6894         
6895       triggerCorrelatedEffect2D[bin1]->SetPoint(triggerCorrelatedEffect2D[bin1]->GetN(), triggerParticle->GetBinCenter(bin2) - 0.5 + 0.1 * bin1, integral);
6896       triggerCorrelatedEffect2D[bin1]->SetPointError(triggerCorrelatedEffect2D[bin1]->GetN()-1, 0, error);
6897     
6898       if (!triggerCorrelatedEffect2DSub[bin1])
6899         triggerCorrelatedEffect2DSub[bin1] = new TGraphErrors;
6900         
6901       triggerCorrelatedEffect2DSub[bin1]->SetPoint(triggerCorrelatedEffect2DSub[bin1]->GetN(), triggerParticle->GetBinCenter(bin2) - 0.5 + 0.1 * bin1, integral / triggerParticle->GetBinContent(bin2));
6902       triggerCorrelatedEffect2DSub[bin1]->SetPointError(triggerCorrelatedEffect2DSub[bin1]->GetN()-1, 0, error / triggerParticle->GetBinContent(bin2));
6903       
6904       if (verbose)
6905         break;
6906     }
6907       
6908     if (verbose)
6909       break;
6910   }
6911   
6912   new TCanvas;
6913   triggerParticle->Draw();
6914   triggerParticle->GetXaxis()->SetRangeUser(0, 9.9);
6915   
6916   legend = new TLegend(0.66, 0.15, 0.88, 0.38);
6917   legend->SetFillColor(0);
6918   legend->SetTextSize(0.04);
6919   legend->AddEntry(triggerParticle, "trigger", "L");
6920   
6921   Int_t marker = 20;
6922   Int_t color = 1;
6923   
6924   for (Int_t bin1=3; bin1<=triggerParticle->GetNbinsX(); bin1++)
6925     if (triggerCorrelatedEffect2D[bin1])
6926     {
6927       triggerCorrelatedEffect2D[bin1]->SetMarkerStyle(marker++);
6928       triggerCorrelatedEffect2D[bin1]->SetMarkerColor(color);
6929       triggerCorrelatedEffect2D[bin1]->SetLineColor(color++);
6930       triggerCorrelatedEffect2D[bin1]->Draw("PSAME");
6931       legend->AddEntry(triggerCorrelatedEffect2D[bin1], Form("pt %.2f", triggerParticle->GetBinCenter(bin1)), "P");
6932     }
6933   
6934   legend->Draw();
6935
6936   new TCanvas;
6937   triggerParticle->Draw();
6938   triggerParticle->GetXaxis()->SetRangeUser(0, 9.9);
6939   
6940   marker = 20;
6941   color = 1;
6942   
6943   for (Int_t bin1=3; bin1<=triggerParticle->GetNbinsX(); bin1++)
6944     if (triggerCorrelatedEffect2DSub[bin1])
6945     {
6946       triggerCorrelatedEffect2DSub[bin1]->SetMarkerStyle(marker++);
6947       triggerCorrelatedEffect2DSub[bin1]->SetMarkerColor(color);
6948       triggerCorrelatedEffect2DSub[bin1]->SetLineColor(color++);
6949       triggerCorrelatedEffect2DSub[bin1]->Draw("PSAME");
6950     }
6951   
6952   legend->Draw();
6953 }
6954
6955 void DrawEventCount(const char* fileName)
6956 {
6957   loadlibs();
6958   
6959   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
6960   h->GetEventCount()->Draw("TEXT");
6961 }
6962
6963 void CompareDCADistributions(const char* fileName1, const char* fileName2)
6964 {
6965   TFile::Open(fileName1);
6966   list = (TList*) gFile->Get("histosPhiCorrelationsQA");
6967   prim = (TH2*) list->FindObject("fDCAPrimaries");
6968   sec  = (TH2*) list->FindObject("fDCASecondaries");
6969   
6970   TFile::Open(fileName2);
6971   list = (TList*) gFile->Get("histosPhiCorrelationsQA");
6972   all = (TH2*) list->FindObject("fDCAPrimaries");
6973   
6974   Float_t zCut = 3.2;
6975   
6976   TH2* histList[] = { prim, sec, all };
6977   
6978   Float_t count = 0;
6979   
6980   TH1* primProj = 0;
6981   TH1* secProj = 0;
6982   
6983   new TCanvas;
6984   gPad->SetGridx();
6985   gPad->SetGridy();
6986   
6987   for (Int_t i=0; i<3; i++)
6988   {
6989     hist = histList[i]->ProjectionX("proj", prim->GetYaxis()->FindBin(-zCut), prim->GetYaxis()->FindBin(zCut))->DrawCopy(i>0?"SAME":"");
6990     hist->SetStats(0);
6991     //hist = histList[i]->ProjectionY("proj", prim->GetXaxis()->FindBin(-zCut), prim->GetXaxis()->FindBin(zCut))->DrawCopy(i>0?"SAME":"");
6992     hist->SetLineColor(i+1);
6993     if (i == 0)
6994       primProj = hist;
6995     if (i == 1)
6996       secProj = hist;
6997     if (i == 2)
6998       hist->Scale(1.0 / hist->Integral(hist->GetXaxis()->FindBin(-0.5), hist->GetXaxis()->FindBin(0.5)) * count);
6999     else
7000       count += hist->Integral(hist->GetXaxis()->FindBin(-0.5), hist->GetXaxis()->FindBin(0.5));
7001   }
7002   
7003   gPad->SetLogy();
7004   
7005   ratio = (TH1*) hist->Clone("ratio");
7006   ratio->Add(primProj, -1);
7007   
7008 /*  for (Int_t i=hist->GetXaxis()->FindBin(-0.1); i<=hist->GetXaxis()->FindBin(0.1); i++)
7009     ratio->SetBinContent(i, 0);*/
7010   
7011   for (Int_t i=1; i<=hist->GetNbinsX(); i++)
7012     ratio->SetBinError(i, 0);
7013   
7014   ratio->SetLineColor(4);
7015   ratio->DrawCopy("SAME E");
7016   
7017   new TCanvas;
7018   gPad->SetGridx();
7019   gPad->SetGridy();
7020   
7021   ratio->Rebin(4);
7022   secProj = (TH1*) secProj->Clone();
7023   secProj->Rebin(4);
7024   
7025   ratio->Divide(secProj);
7026   
7027 /*  for (Int_t i=1; i<=hist->GetNbinsX(); i++)
7028     ratio->SetBinError(i, 0);*/
7029   
7030   ratio->Draw("HIST");
7031   ratio->GetYaxis()->SetRangeUser(0.7, 1.3);
7032   
7033   ratio->Fit("pol0", "0+", "", -5, -1);
7034   ratio->Fit("pol0", "0+", "", 1, 5);
7035 }
7036  
7037 void TrackCuts_CompareParameters(const char* fileName1, const char* fileName2, const char* histName, const char* cutFolder = "cuts_quality_only")
7038 {
7039   // plotWhich: 0 = only before
7040   //            1 = both
7041   //            2 = only after
7042   //
7043   // mirror: kTRUE --> project negative values on the positive side
7044   
7045   Int_t plotWhich = 0;
7046   Bool_t mirror = kFALSE;
7047   
7048   TFile* files[2];
7049   files[0] = TFile::Open(fileName1);
7050   files[1] = TFile::Open(fileName2);
7051
7052   Int_t count = 0;
7053   Int_t colors[] = { 1, 2, 3, 4, 5, 6 };
7054
7055   TLegend* legend = new TLegend(0.7, 0.85, 0.93, 0.98);
7056   legend->SetTextSize(0.04);
7057   legend->SetFillColor(0);
7058
7059   TCanvas* c1 = new TCanvas(histName, histName, 1200, 600);
7060   c1->Divide(2, 1);
7061   //TCanvas* c2 = new TCanvas("c2", "c2", 800, 600);
7062   //TCanvas* c3 = new TCanvas("c3", "c3", 800, 600);
7063
7064   const char* folders2[] = { "before_cuts", "after_cuts" };
7065   const char* names[] = { "MC", "Data" };
7066   Bool_t first = kTRUE;
7067   for (Int_t j = ((plotWhich < 2) ? 0 : 1); j < ((plotWhich > 0) ? 2 : 1); j++)
7068   {
7069     TH1* base = 0;
7070     TH1* base2 = 0;
7071     for (Int_t i = 0; i < 2; i++)
7072     {
7073       Printf("%d %d", j, i);
7074       TString folder;
7075       folder.Form("%s/%s/%s", cutFolder, folders2[j], histName);
7076       TH1* hist = (TH1*) files[i]->Get(folder);
7077       
7078       if (mirror)
7079       {
7080         for (Int_t bin=1; bin<=hist->GetXaxis()->FindBin(-0.0001); bin++)
7081         {
7082           Int_t newBin = hist->GetXaxis()->FindBin(-hist->GetXaxis()->GetBinCenter(bin));
7083           if (bin != newBin)
7084           {
7085             hist->Fill(-hist->GetXaxis()->GetBinCenter(bin), hist->GetBinContent(bin));
7086             hist->SetBinContent(bin, 0);
7087           }
7088         }
7089       }
7090       
7091       legend->AddEntry(hist, Form("%s %s", names[i], (plotWhich == 1) ? folders2[j] : " "));
7092
7093       c1->cd(1);
7094       hist->SetLineColor(colors[count]);
7095       hist->Scale(1.0 / hist->Integral());
7096       hist->SetStats(0);
7097       hist->DrawCopy((count == 0) ? "" : "SAME");
7098
7099       switch (i)
7100       {
7101         case 0: base = hist; break;
7102         case 1: base2 = hist; break;
7103       }
7104
7105       count++;
7106     }
7107     
7108     TH1* ratio = base;
7109     ratio->Divide(base2);
7110
7111     ratio->GetYaxis()->SetRangeUser(0, 2);
7112     
7113     c1->cd(2);
7114     ratio->DrawCopy((first) ? "" : "SAME");
7115     first = kFALSE;
7116   }
7117
7118   c1->cd(1)->SetLogy();
7119   c1->cd(1)->SetGridx();
7120   c1->cd(1)->SetGridy();
7121   legend->Draw();
7122   
7123   c1->cd(2)->SetGridx();
7124   c1->cd(2)->SetGridy();
7125   
7126   c1->SaveAs(Form("%s.png", histName));
7127 }
7128
7129 void PlotQA(const char* fileName)
7130 {
7131   loadlibs();
7132   
7133   if (!gGrid && TString(fileName).BeginsWith("alien://"))
7134     TGrid::Connect("alien://");
7135   
7136   TFile::Open(fileName);
7137   
7138   // QA task
7139   list = (TList*) gFile->Get("histosPhiCorrelationsQA");
7140   
7141   prim = (TH2*) list->FindObject("fDCAPrimaries");
7142   dcaxy = prim->ProjectionX("dcaxy", prim->GetYaxis()->FindBin(-3.2), prim->GetYaxis()->FindBin(3.2));
7143   dcaz = prim->ProjectionY("dcaz", prim->GetXaxis()->FindBin(-2.4), prim->GetXaxis()->FindBin(2.4));
7144   centrCorr = (TH2*) list->FindObject("fCentralityCorrelation");
7145   
7146   cuts = (AliESDtrackCuts*) list->FindObject("cuts_quality_dca");
7147   cluster = cuts->GetNClustersTPC(1);
7148   
7149   ptall = (TH1F*) cuts->GetPtHist(1)->Clone("ptall");
7150   if (ptall->Integral() > 0)
7151     ptall->Scale(1.0 / ptall->Integral());
7152   
7153   check_its = (AliESDtrackCuts*) list->FindObject("check_its");
7154   ptIts = (TH1F*) check_its->GetPtHist(1)->Clone("ptIts");
7155   if (ptIts->Integral() > 0)
7156     ptIts->Scale(1.0 / ptIts->Integral());
7157   
7158   global_cuts = (AliESDtrackCuts*) list->FindObject("global_cuts");
7159   ptItsAcc = (TH1*) global_cuts->GetPtHist(1)->Clone("ptItsAcc");
7160   if (ptItsAcc->Integral() > 0)
7161     ptItsAcc->Scale(1.0 / ptItsAcc->Integral());
7162   
7163   // centrality task
7164   list = (TList*) gFile->Get("CentralityStat");
7165   centrQuality = (TH1*) list->FindObject("fHOutQuality");
7166   
7167   // phys sel
7168   list = (TList*) gFile->Get("PhysSel");
7169   physSel = (AliPhysicsSelection*) list->FindObject("AliPhysicsSelection");
7170   
7171   // phi corr task
7172   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
7173   centr = h->GetCentralityDistribution();
7174   NormalizeToBinWidth(centr);
7175   Int_t events = (Int_t) h->GetEventCount()->ProjectionX()->GetBinContent(3);
7176   
7177   h->SetPtRange(1.01, 3.99);
7178   dphi_corr = h->GetUEHist(2)->GetUEHist(AliUEHist::kCFStepReconstructed, 0, 4.01, 14.99, 1, 8);
7179   
7180   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
7181   hMixed->SetPtRange(1.01, 3.99);
7182   dphi_corr_mixed = hMixed->GetUEHist(2)->GetUEHist(AliUEHist::kCFStepReconstructed, 0, 4.01, 14.99, 1, 8);
7183   
7184   TString tmp(fileName);
7185   tmp.ReplaceAll("alien:///alice/cern.ch/user/j/jgrosseo/gridjob/dir_", "");
7186   tmp.ReplaceAll(".root", ".png");
7187   tmp.ReplaceAll("/", "-");
7188   TString title;
7189   title.Form("QA_%d_%s", physSel->GetCurrentRun(), tmp.Data());
7190   c = new TCanvas(title, title, 1200, 800);
7191   c->Divide(3, 3);
7192   
7193   latex = new TLatex(0.15, 0.8, Form("%d events", events));
7194   latex->SetTextSize(0.075);
7195   latex->SetNDC();
7196   
7197   c->cd(1); dcaxy->Draw(); dcaz->SetLineColor(2); dcaz->Draw("SAME");  gPad->SetLogy(); latex->Draw();
7198   c->cd(2); dphi_corr->Draw(); dphi_corr->GetYaxis()->SetRangeUser(dphi_corr->GetMinimum() * 0.9, dphi_corr->GetMaximum() * 1.1); dphi_corr_mixed->SetLineColor(2); dphi_corr_mixed->Draw("SAME");
7199   c->cd(3); cluster->Draw();
7200   c->cd(4); centrQuality->Draw();
7201   c->cd(5); centr->Draw("HIST");
7202   c->cd(6); centrCorr->Draw("COLZ"); gPad->SetLogz();
7203   c->cd(7); ptall->Draw(); ptIts->SetLineColor(2); ptIts->Draw("SAME"); ptItsAcc->SetLineColor(4); ptItsAcc->Draw("SAME"); gPad->SetLogy();
7204   
7205   c->SaveAs(Form("qa/%s", c->GetTitle()));
7206 }
7207
7208 void CompareStepsOnePlot(const char* fileName, Int_t caseId)
7209 {
7210   loadlibs();
7211
7212   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
7213   
7214   Int_t stepList[] = { 0, 2, 4, 5, 6 };
7215   Int_t stepListNames[] = { 0, 2, 3, 4, 5 };
7216   //const char* names[] = { "All", "PhysSel+Vertex", "Reco Primaries", "Reco "
7217 //   //Int_t stepList[] = { 2, 4, 5, 6 };
7218 //   
7219 //   
7220 //   TH1* hist1 = h->GetUEHist(2)->GetUEHist(0, 0, 6.01, 9.99, 6, 14);
7221 //   TH1* hist2 = h->GetUEHist(2)->GetUEHist(0, 0, 6.01, 7.99, 6, 14);
7222 //   TH1* hist3 = h->GetUEHist(2)->GetUEHist(0, 0, 8.01, 9.99, 6, 14);
7223 //   
7224 //   hist1->Draw();
7225 //   hist2->SetLineColor(2);
7226 //   hist2->Draw("SAME");
7227 //   hist3->SetLineColor(4);
7228 //   hist3->Draw("SAME");
7229 //   return;
7230 //   
7231   
7232   legend = new TLegend(0.65, 0.45, 0.85, 0.85);
7233   legend->SetTextSize(0.04);
7234   legend->SetFillColor(0);
7235   
7236   TH1* histList[5];
7237   
7238   for (Int_t i=0; i<5; i++)
7239   {
7240     //TH1* hist1 = h->GetUEHist(2)->GetEventHist()->Project(stepList[i], 0);
7241     
7242 /*    h->GetUEHist(2)->GetTrackHist(0)->GetGrid(stepList[i])->GetGrid()->GetAxis(1)->SetRangeUser(1.01, 3.99);
7243     h->GetUEHist(2)->GetTrackHist(0)->GetGrid(stepList[i])->GetGrid()->GetAxis(2)->SetRangeUser(4.01, 19.99);
7244     TH1* hist1 = h->GetUEHist(2)->GetTrackHist(0)->Project(stepList[i], 4);*/
7245     
7246     if (caseId == 0)
7247       TH1* hist1 = h->GetUEHist(2)->GetUEHist(stepList[i], 0, 4.01, 19.99, 6, 14);
7248     else if (caseId == 1)
7249       TH1* hist1 = h->GetUEHist(2)->GetEventHist()->Project(stepList[i], 0);
7250     
7251     //hist1->Rebin(2);
7252     //hist1->Rebin(4);
7253     hist1->SetMarkerStyle(24+i);
7254     hist1->SetTitle("");
7255     hist1->SetStats(0);
7256     hist1->DrawCopy((i==0)?"":"SAME");
7257     hist1->Fit("pol0", "0");
7258     //hist1->Fit("pol0");
7259     histList[i] = hist1;
7260     legend->AddEntry(hist1, Form("Step %d", stepListNames[i]), "P");
7261   }
7262   
7263   legend->Draw();
7264   
7265   new TCanvas;
7266   legend = new TLegend(0.65, 0.45, 0.85, 0.85);
7267   legend->SetTextSize(0.04);
7268   legend->SetFillColor(0);
7269   
7270   for (Int_t i=1; i<5; i++)
7271   {
7272     histList[i]->DrawCopy((i==1)?"":"SAME")->Divide(histList[i-1]);
7273     legend->AddEntry(hist1, Form("Step %d/%d", stepListNames[i], stepListNames[i-1]), "P");
7274   }
7275   
7276   legend->Draw();
7277   
7278   new TCanvas;
7279   for (Int_t i=0; i<5; i++)
7280   {
7281     hist1 = histList[i];
7282     func = new TF1("func", "[0]", -10, 10);
7283     hist1->Fit(func, "0", "", 1, 2);
7284     hist1->Add(func, -1);
7285     hist1->DrawCopy((i==0)?"":"SAME");
7286   }
7287   
7288   legend->Draw();
7289   
7290   new TCanvas;
7291   for (Int_t i=1; i<5; i++)
7292   {
7293     histList[i]->DrawCopy((i==1)?"":"SAME")->Divide(histList[i-1]);
7294   }
7295   
7296   legend->Draw();
7297 }
7298
7299 void PtShift(const char* fileName)
7300 {
7301   loadlibs();
7302
7303   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
7304   
7305   new TCanvas;
7306   gPad->SetLogy();
7307   
7308   ptHist3 = h->GetCorrelationpT()->ProjectionY();
7309   ptHist3->GetXaxis()->SetRangeUser(0, 20);
7310   //ptHist3->Sumw2();
7311   
7312   /*
7313   func = new TF1("func", "[0]+[1]*x**[2]", 4, 20);
7314   func->SetParLimits(2, -10, -1);
7315   func->SetParameters(0, 1, -4);
7316   ptHist3->Fit(func, "", "", 4, 20);
7317   
7318   return;
7319   */
7320   
7321   ptHist3Shifted = (TH1*) ptHist3->Clone("ptHist3Shifted");
7322   for (Int_t i=1; i<ptHist3Shifted->GetNbinsX(); i++)
7323     //ptHist3Shifted->SetBinContent(i, ptHist3Shifted->GetBinContent(i+3));
7324     ptHist3Shifted->SetBinContent(i, ptHist3Shifted->GetBinContent(1.1*i));
7325   
7326   // 10% or 750 MeV
7327     
7328   ptHist3Shifted->SetLineColor(2);
7329   
7330   ptHist3->Rebin(2);
7331   ptHist3Shifted->Rebin(2);
7332   
7333   ptHist3->DrawCopy();
7334   ptHist3Shifted->DrawCopy("SAME");
7335   
7336   new TCanvas;
7337   ptHist3->Divide(ptHist3Shifted);
7338   ptHist3->Draw();
7339   
7340   //ptHist3->Rebin(2); ptHist3->Scale(1.0 / 2);
7341   
7342   gPad->SetGridx();
7343   gPad->SetGridy();
7344 }
7345
7346 void RAA(const char* fileName, const char* fileName2)
7347 {
7348   loadlibs();
7349   
7350   TH1* hist[2];
7351   
7352   for (Int_t j=0; j<2; j++)
7353   {
7354     if (j == 0)
7355       AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
7356     else
7357     {
7358       if (!fileName2)
7359         break;
7360         
7361       AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName2);
7362     }
7363   
7364     ptHist3 = h->GetCorrelationpT()->ProjectionY(Form("proj1_%d", j), 1, 5);
7365     ptHist3->GetXaxis()->SetRangeUser(0, 20);
7366     
7367     //h->GetCentralityDistribution()->Draw(); new TCanvas;
7368     
7369     Int_t nEvents = h->GetCentralityDistribution()->Integral(h->GetCentralityDistribution()->FindBin(0.01), h->GetCentralityDistribution()->FindBin(4.99));
7370     Printf("%d", nEvents);
7371     ptHist3->Scale(1.0 / 1.6 / TMath::TwoPi() / nEvents / ptHist3->GetBinWidth(1));
7372     
7373     hist[j] = ptHist3;
7374   }
7375   
7376   new TCanvas;
7377   hist[0]->DrawCopy("");
7378   hist[1]->DrawCopy("SAME")->SetLineColor(2);
7379   gPad->SetLogy();
7380   
7381   new TCanvas;
7382   hist[1]->Divide(hist[0]);
7383   hist[1]->DrawCopy();
7384   
7385   raa_central = ReadHepdata("raa_alice_central.txt", kFALSE, 3);
7386   raa_central->SetMarkerStyle(20);
7387   raa_central->Draw("PSAME");
7388 }
7389
7390 void PtComparison(const char* fileName, const char* fileName2 = 0)
7391 {
7392   loadlibs();
7393
7394   c = new TCanvas;
7395   c2 = new TCanvas;
7396     
7397   for (Int_t j=0; j<2; j++)
7398   {
7399     if (j == 0)
7400       AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
7401     else
7402     {
7403       if (!fileName2)
7404         break;
7405         
7406       AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName2);
7407     }
7408     
7409     //new TCanvas; h->GetCorrelationpT()->Draw("COLZ");
7410     
7411     ptHist3 = h->GetCorrelationpT()->ProjectionY(Form("proj1_%d", j), 1, 5);
7412     ptHist3->GetXaxis()->SetRangeUser(0, 20);
7413     
7414     //h->GetCentralityDistribution()->Draw(); new TCanvas;
7415     
7416     Int_t nEvents = h->GetCentralityDistribution()->Integral(h->GetCentralityDistribution()->FindBin(0.01), h->GetCentralityDistribution()->FindBin(4.99));
7417     Printf("%d", nEvents);
7418     ptHist3->Scale(1.0 / 1.6 / TMath::TwoPi() / nEvents / ptHist3->GetBinWidth(1));
7419     
7420     //ptHist3->Scale(1690);
7421     //ptHist3->Scale(1.0 / ptHist3->Integral(ptHist3->GetXaxis()->FindBin(1.01), ptHist3->GetNbinsX()) / 3 / 0.6);
7422     
7423     for (Int_t i=2; i<ptHist3->GetNbinsX(); i++)
7424       ptHist3->SetBinContent(i, ptHist3->GetBinContent(i) / ptHist3->GetBinCenter(i));
7425       //ptHist3->SetBinContent(i, ptHist3->GetBinContent(i) / ptHist3->GetBinLowEdge(i));
7426     
7427     //AliPWG0Helper::NormalizeToBinWidth(ptHist3);
7428     
7429     c->cd();
7430     ptHist3->SetLineStyle(j+1);
7431     ptHist3->DrawCopy((j == 0) ? "HIST" : "HISTSAME")->SetLineColor(1);
7432
7433     centralPt = (TH1*) ptHist3->Clone();;
7434   
7435     if (1)
7436     {
7437       ptHist3 = h->GetCorrelationpT()->ProjectionY(Form("proj2_%d", j), 71, 80);
7438       ptHist3->GetXaxis()->SetRangeUser(0, 20);
7439     
7440       Int_t nEvents = h->GetCentralityDistribution()->Integral(h->GetCentralityDistribution()->FindBin(70.01), h->GetCentralityDistribution()->FindBin(79.99));
7441       ptHist3->Scale(1.0 / 1.6 / TMath::TwoPi() / nEvents / ptHist3->GetBinWidth(1));
7442       //ptHist3->Scale(10.0 / ptHist3->Integral(ptHist3->GetXaxis()->FindBin(1.01), ptHist3->GetNbinsX()) / 3 / 0.6);
7443       Printf("%d", nEvents);
7444     
7445       for (Int_t i=2; i<ptHist3->GetNbinsX(); i++)
7446         ptHist3->SetBinContent(i, ptHist3->GetBinContent(i) / ptHist3->GetBinCenter(i));
7447         //ptHist3->SetBinContent(i, ptHist3->GetBinContent(i) / ptHist3->GetBinLowEdge(i));
7448     }
7449     
7450     ptHist3->SetLineStyle(j+1);
7451     ptHist3->DrawCopy("HISTSAME")->SetLineColor(2);
7452     
7453     dndpt_central = ReadHepdata("raa_dndpt_central.txt", kFALSE, 3);
7454     dndpt_peripheral = ReadHepdata("raa_dndpt_peripheral.txt", kFALSE, 3);
7455   
7456 //   RemovePointsBelowX(dndpt_central, 1);
7457 //   RemovePointsBelowX(dndpt_peripheral, 1);
7458 //   
7459 //   NormalizeTo(dndpt_central, 1);
7460 //   NormalizeTo(dndpt_peripheral, 10);
7461
7462     dndpt_central->Draw("*SAME");
7463     dndpt_peripheral->SetLineColor(2);
7464     dndpt_peripheral->SetMarkerColor(2);
7465     dndpt_peripheral->Draw("*SAME");
7466     
7467     gPad->SetLogy();
7468     
7469     c2->cd();
7470     
7471     for (Int_t i=1; i<ptHist3->GetNbinsX(); i++)
7472       ptHist3->SetBinContent(i, ptHist3->GetBinContent(i) / dndpt_peripheral->Eval(ptHist3->GetBinCenter(i)));
7473   
7474     for (Int_t i=1; i<centralPt->GetNbinsX(); i++)
7475       centralPt->SetBinContent(i, centralPt->GetBinContent(i) / dndpt_central->Eval(centralPt->GetBinCenter(i)));
7476   
7477     ptHist3->Rebin(2); ptHist3->Scale(0.5);
7478     centralPt->Rebin(2); centralPt->Scale(0.5);
7479   
7480     ptHist3->DrawCopy((j == 0) ? "" : "SAME")->SetLineColor(2);
7481     centralPt->DrawCopy("SAME")->SetLineColor(1);
7482   }
7483
7484   return;
7485   
7486   ReadYields("preliminaries/yields_110303.root");
7487   
7488   ptHist3->Scale(100);
7489   
7490   TGraphErrors** tmp = yields[0][1][0];
7491   nearSide = tmp[18];
7492   nearSide->Draw("* SAME");  
7493  
7494   TGraphErrors** tmp = yields[1][1][0];
7495   awaySide = tmp[18];
7496   awaySide->SetLineColor(2);
7497   awaySide->SetMarkerColor(2);
7498   awaySide->Draw("* SAME");  
7499   
7500 }
7501
7502 void style(Int_t styleId = 1)
7503 {
7504   gStyle->SetPalette(1);
7505   gStyle->SetCanvasColor(10);
7506   gStyle->SetHistFillColor(10);
7507   gStyle->SetHistFillStyle(0);
7508   gStyle->SetOptStat(0);
7509   gStyle->SetPadTickX(1);
7510   gStyle->SetPadTickY(1);
7511   gStyle->SetAxisColor(1, "X");
7512   gStyle->SetAxisColor(1, "Y");
7513   gStyle->SetAxisColor(1, "Z");
7514   gStyle->SetLabelColor(1, "X");
7515   gStyle->SetLabelColor(1, "Y");
7516   gStyle->SetLabelColor(1, "Z");
7517   gStyle->SetTickLength(0.03, "X");
7518   gStyle->SetTickLength(0.03, "Y");
7519   gStyle->SetTickLength(0.03, "Z");
7520   gStyle->SetTitleXSize(0.05);
7521   gStyle->SetTitleYSize(0.05);
7522   gStyle->SetNdivisions(506, "X");
7523   gStyle->SetNdivisions(506, "Y");
7524   gStyle->SetNdivisions(506, "Z");
7525   
7526   //gStyle->SetPadGridX(1);
7527   //gStyle->SetPadGridY(1);
7528
7529   //gStyle->SetLabelOffset(0.02, "X");
7530   //gStyle->SetLabelOffset(0.02, "Y");
7531   //gStyle->SetLabelOffset(0.02, "Z");
7532   gStyle->SetLabelSize(0.05, "X");
7533   gStyle->SetLabelSize(0.05, "Y");
7534   gStyle->SetLabelSize(0.05, "Z");
7535
7536   gStyle->SetPadLeftMargin(0.12);
7537   gStyle->SetPadRightMargin(0.02);
7538   gStyle->SetPadBottomMargin(0.13);
7539   gStyle->SetPadTopMargin(0.02);
7540
7541   gStyle->SetMarkerSize(1.4); // CKB
7542
7543   const int iFont = 42; // type * 10 + prec  6: helvetica bold 13: times normal 2: times bold
7544
7545 /*                                                               italic     weigth
7546 *-*        1 : times-medium-i-normal      "Times New Roman"      1           4
7547 *-*        2 : times-bold-r-normal        "Times New Roman"      0           7
7548 *-*        3 : times-bold-i-normal        "Times New Roman"      1           7
7549 *-*        4 : helvetica-medium-r-normal  "Arial"                0           4
7550 *-*        5 : helvetica-medium-o-normal  "Arial"                1           4
7551 *-*        6 : helvetica-bold-r-normal    "Arial"                0           7
7552 *-*        7 : helvetica-bold-o-normal    "Arial"                1           7
7553 *-*        8 : courier-medium-r-normal    "Courier New"          0           4
7554 *-*        9 : courier-medium-o-normal    "Courier New"          1           4
7555 *-*       10 : courier-bold-r-normal      "Courier New"          0           7
7556 *-*       11 : courier-bold-o-normal      "Courier New"          1           7
7557 *-*       12 : symbol-medium-r-normal     "Symbol"               0           6
7558 *-*       13 : times-medium-r-normal      "Times New Roman"      0           4
7559 *-*       14 :                            "Wingdings"            0           4
7560 */
7561
7562   //gStyle->SetTitleXOffset(1); // 1.1
7563   //gStyle->SetTitleYOffset(1); // 1-4
7564
7565   gStyle->SetLabelFont(iFont, "xyz");
7566   gStyle->SetStatFont(iFont);
7567   gStyle->SetTitleFont(iFont, "xyz");
7568   gStyle->SetTextFont(iFont);
7569   
7570   if (styleId == 2)
7571   {
7572     gStyle->SetLabelSize(0.07, "X");
7573     gStyle->SetLabelSize(0.07, "Y");
7574     gStyle->SetLabelSize(0.07, "Z");
7575     gStyle->SetTitleXSize(0.07);
7576     gStyle->SetTitleYSize(0.07);
7577   
7578     gStyle->SetPadLeftMargin(0.26);
7579     gStyle->SetPadRightMargin(0.01);
7580     gStyle->SetPadBottomMargin(0.15);
7581     gStyle->SetPadTopMargin(0.01);
7582   }
7583
7584   //gStyle->SetEndErrorSize(0.0);
7585
7586   gROOT->ForceStyle();
7587
7588 }
7589
7590 void NormalizeTo(TGraphErrors* graph, Float_t normalizeTo)
7591 {
7592         Float_t sum = 0;
7593         for (Int_t i=0; i<graph->GetN(); i++)
7594                 sum += graph->GetY()[i];
7595         
7596         if (normalizeTo > 0 && sum > 0)
7597         {
7598                 sum /= normalizeTo;
7599                 for (Int_t i=0; i<graph->GetN(); i++)
7600                 {
7601                         graph->SetPoint(i, graph->GetX()[i],  graph->GetY()[i] / sum);
7602                         graph->SetPointError(i, graph->GetEX()[i],  graph->GetEY()[i] / sum);
7603                 }
7604         }       
7605 }
7606