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