]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGCF/Correlations/macros/dphicorrelations/correct.C
1973649afff771062948f574bbcc05ca74b86169
[u/mrichter/AliRoot.git] / PWGCF / Correlations / 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 TString Sign[]={"Plus","Minus"};
12 enum ECharge_t {
13   kPositive,
14   kNegative,
15   kNCharges
16 };
17
18 void SetRanges(TAxis* axis)
19 {
20   if (strcmp(axis->GetTitle(), "leading p_{T} (GeV/c)") == 0)
21     axis->SetRangeUser(0, (gEnergy == 900) ? 10 : 25);
22
23   if (strcmp(axis->GetTitle(), "multiplicity") == 0)
24     axis->SetRangeUser(0, 10);
25 }
26
27 void SetRanges(TH1* hist)
28 {
29   SetRanges(hist->GetXaxis());
30   SetRanges(hist->GetYaxis());
31   SetRanges(hist->GetZaxis());
32 }
33
34 void Prepare1DPlot(TH1* hist)
35 {
36   if (!hist)
37     return;
38
39   hist->SetLineWidth(2);
40   hist->SetStats(kFALSE);
41
42   hist->GetXaxis()->SetLabelOffset(0.02);
43   hist->GetXaxis()->SetTitleOffset(1.3);
44   hist->GetYaxis()->SetTitleOffset(1.3);
45
46   SetRanges(hist);
47 }
48
49 TH1* GetSystematicUncertainty(TH1* corr, TH1* trackHist)
50 {
51   if (!trackHist)
52   {
53     systError = (TH1*) corr->Clone("systError");
54     systError->Reset();
55   }
56   else  // for dphi evaluation
57     systError = new TH1F("systError", "", 100, 0, 50);
58   
59   Float_t constantUnc = 0;
60   
61   // particle composition
62   constantUnc += 0.8 ** 2;
63   
64   // tpc efficiency
65   if (gEnergy == 900 && gpTMin < 1.0)
66     constantUnc += 1.0 ** 2;
67   else if (gEnergy == 900 && gpTMin < 1.5)
68     constantUnc += 0.5 ** 2;
69   if (gEnergy == 7000 && gpTMin < 1.0)
70     constantUnc += 1.0 ** 2;
71   else if (gEnergy == 7000 && gpTMin < 1.5)
72     constantUnc += 0.6 ** 2;
73   
74   // track cuts
75   if (gEnergy == 900 && gpTMin < 1.0)
76     constantUnc += 2.5 ** 2;
77   else if (gEnergy == 900 && gpTMin < 1.5)
78     constantUnc += 2.0 ** 2;
79   if (gEnergy == 7000)
80     constantUnc += 3.0 ** 2;
81
82   // difference corrected with pythia and phojet
83   if (gEnergy == 900 && gpTMin < 1.0)
84     constantUnc += 0.6 ** 2;
85   else if (gEnergy == 900 && gpTMin < 1.5)
86     constantUnc += 0.8 ** 2;
87   
88   if (gEnergy == 7000 && gpTMin < 1.0)
89   {
90     if (gUEHist == 0)
91       constantUnc += 0.6 ** 2;
92     if (gUEHist == 1)
93       constantUnc += 0.8 ** 2;
94     if (gUEHist == 2)
95       constantUnc += 1.0 ** 2;
96   }
97   else if (gEnergy == 7000 && gpTMin < 1.5)
98     constantUnc += 1.0 ** 2;
99     
100   for (Int_t bin=1; bin<=systError->GetNbinsX(); bin++)
101     systError->SetBinContent(bin, constantUnc);
102
103   // mis id bias
104   if (gUEHist == 0 || gUEHist == 2)
105     systError->Fill(0.75, 4.0 ** 2);
106   if (gUEHist == 1)
107     systError->Fill(0.75, 5.0 ** 2);
108
109   if (gEnergy == 900)
110   {
111     if (gpTMin < 1.0)
112       systError->Fill(1.25, 1.0 ** 2);
113     else if (gpTMin < 1.5)
114       systError->Fill(1.25, 2.0 ** 2);
115   }
116   
117   // non-closure in MC
118   if (gEnergy == 900)
119     for (Int_t bin=1; bin<=systError->GetNbinsX(); bin++)
120       systError->Fill(systError->GetXaxis()->GetBinCenter(bin), 1.0 ** 2);
121       
122   if (gEnergy == 7000)
123   {
124     if (gUEHist == 0 && gUEHist == 1)
125       systError->Fill(0.75, 2.0 ** 2);
126     if (gUEHist == 2)
127       systError->Fill(0.75, 1.2 ** 2);
128   }
129   
130   // vertex efficiency
131   systError->Fill(0.75, 1.0 ** 2);
132
133   // strangeness
134   for (Int_t bin=1; bin<=systError->GetNbinsX(); bin++)
135   {
136     if (gEnergy == 900)
137       systError->Fill(systError->GetXaxis()->GetBinCenter(bin), 0.5 ** 2);
138     if (gEnergy == 7000 && systError->GetXaxis()->GetBinCenter(bin) < 1.5)
139       systError->Fill(systError->GetXaxis()->GetBinCenter(bin), 2.0 ** 2);
140     else if (gEnergy == 7000)
141       systError->Fill(systError->GetXaxis()->GetBinCenter(bin), 1.0 ** 2);
142   }  
143     
144   for (Int_t bin=1; bin<=systError->GetNbinsX(); bin++)
145     systError->SetBinContent(bin, TMath::Sqrt(systError->GetBinContent(bin)));
146   
147   if (trackHist)
148   {
149     //new TCanvas; trackHist->Draw();
150     //new TCanvas; systError->DrawCopy("");
151     
152     Float_t uncFlat = 0;
153     for (Int_t i=1; i<=trackHist->GetNbinsX(); i++)
154       uncFlat += trackHist->GetBinContent(i) * systError->GetBinContent(systError->FindBin(trackHist->GetBinCenter(i)));
155     if (trackHist->Integral() > 0)
156       uncFlat /= trackHist->Integral();
157     
158     systError = (TH1F*) corr->Clone("systError");
159     systError->Reset();
160   
161     for (Int_t i=1; i<=systError->GetNbinsX(); i++)
162       systError->SetBinContent(i, uncFlat);
163       
164     //new TCanvas; systError->DrawCopy("");
165   }
166   
167   systError->SetFillColor(kGray);
168   systError->SetFillStyle(1001);
169   systError->SetMarkerStyle(0);
170   systError->SetLineColor(0);
171   
172   return systError;
173 }
174
175 void DrawRatio(TH1* corr, TH1* mc, const char* name, TH1* syst = 0)
176 {
177   mc->SetLineColor(2);
178
179   TCanvas* canvas3 = new TCanvas(name, name, 600, 600);
180   canvas3->Range(0, 0, 1, 1);
181
182   TPad* pad1 = new TPad(Form("%s_1", name), "", 0, 0.5, 0.98, 0.98);
183   pad1->Draw();
184
185   TPad* pad2 = new TPad(Form("%s_2", name), "", 0, 0.02, 0.98, 0.5);
186   pad2->Draw();
187
188   pad1->SetRightMargin(0.01);
189   pad2->SetRightMargin(0.01);
190   pad1->SetTopMargin(0.05);
191   pad1->SetLeftMargin(0.13);
192   pad2->SetLeftMargin(0.13);
193   pad2->SetBottomMargin(0.22);
194   
195   // no border between them
196   pad1->SetBottomMargin(0);
197   pad2->SetTopMargin(0);
198
199   pad1->cd();
200   pad1->SetGridx();
201   pad1->SetGridy();
202
203   if (gUEHist != 2)
204     TLegend* legend = new TLegend(0.15, 0.65, 0.55, 0.90);
205   else
206     TLegend* legend = new TLegend(0.55, 0.65, 0.95, 0.90);
207
208   legend->SetFillColor(0);
209   legend->AddEntry(corr, "Corrected");
210   legend->AddEntry(mc, "MC prediction");
211   legend->SetTextSize(0.08);
212
213   Prepare1DPlot(corr);
214
215   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);
216   dummy->SetYTitle(corr->GetYaxis()->GetTitle());
217   
218   //dummy = new TH2F("dummy", "", 100, corr->GetXaxis()->GetBinLowEdge(1), corr->GetXaxis()->GetBinUpEdge(corr->GetNbinsX()), 1000, 13.5, 20.5);
219   //dummy->SetYTitle("1/N_{trig} dN/d#Delta#phi");
220   
221   dummy->SetStats(kFALSE);
222   dummy->SetXTitle(corr->GetXaxis()->GetTitle());
223   dummy->GetYaxis()->SetTitleOffset(1);
224   Prepare1DPlot(dummy);
225
226   dummy->GetXaxis()->SetLabelSize(0.08);
227   dummy->GetYaxis()->SetLabelSize(0.08);
228   dummy->GetXaxis()->SetTitleSize(0.08);
229   dummy->GetYaxis()->SetTitleSize(0.08);
230   dummy->GetYaxis()->SetTitleOffset(0.8);
231   
232   if (gForceRange > 0)
233     dummy->GetYaxis()->SetRangeUser(0, gForceRange);
234   
235   dummy->DrawCopy();
236   
237   if (0 && gUEHist != 2)
238   {
239     const char* regionStr[] = { "Toward Region", "Away Region", "Transverse Region" };
240     latex = new TLatex(0.65, 0.1, regionStr[gRegion]);
241     latex->SetTextSize(0.075);
242     latex->SetNDC();
243     latex->Draw();
244   }
245   
246   if (syst)
247   {
248     systError = (TH1*) syst->Clone("corrSystError");
249     for (Int_t bin=1; bin<=systError->GetNbinsX(); bin++)
250     {
251       systError->SetBinError(bin, corr->GetBinContent(bin) * syst->GetBinContent(bin) / 100);
252       systError->SetBinContent(bin, corr->GetBinContent(bin));
253     }
254     
255     systError->Draw("E2 ][ SAME");
256   }
257   
258   corr->Draw("SAME");
259   mc->Draw("SAME");
260   
261   if (strlen(gText) > 0)
262   {
263     latex = new TLatex(0.2, 0.2, gText);
264     latex->SetNDC();
265     latex->SetTextSize(0.06);
266     latex->Draw();
267   }
268
269   //legend->Draw();
270
271   pad2->cd();
272   //pad2->SetBottomMargin(0.15);
273   //pad2->SetGridx();
274   //pad2->SetGridy();
275
276   TH1* ratio = (TH1*) mc->Clone("ratio");
277   ratio->Divide(corr);
278
279   Float_t minR = TMath::Min(0.91, ratio->GetMinimum() * 0.95);
280   Float_t maxR = TMath::Max(1.09, ratio->GetMaximum() * 1.05);
281   
282   minR = 0.8;
283   maxR = 1.2;
284
285   TH1F dummy3("dummy3", ";;Ratio: MC / corr", 100, corr->GetXaxis()->GetBinLowEdge(1), corr->GetXaxis()->GetBinUpEdge(corr->GetNbinsX()));
286   dummy3.SetXTitle(corr->GetXaxis()->GetTitle());
287   Prepare1DPlot(&dummy3);
288   dummy3.SetStats(kFALSE);
289   for (Int_t i=1; i<=100; ++i)
290         dummy3.SetBinContent(i, 1);
291   dummy3.GetYaxis()->SetRangeUser(minR, maxR);
292   dummy3.SetLineWidth(2);
293   dummy3.GetXaxis()->SetLabelSize(0.08);
294   dummy3.GetYaxis()->SetLabelSize(0.08);
295   dummy3.GetXaxis()->SetTitleSize(0.08);
296   dummy3.GetYaxis()->SetTitleSize(0.08);
297   dummy3.GetYaxis()->SetTitleOffset(0.8);
298   dummy3.DrawCopy();
299   
300   if (syst)
301   {
302     // for the ratio add in quadrature
303     for (Int_t bin=1; bin<=syst->GetNbinsX(); bin++)
304     {
305       if (corr->GetBinError(bin) > 0)
306         syst->SetBinError(bin, TMath::Sqrt(TMath::Power(syst->GetBinContent(bin) / 100, 2) + TMath::Power(corr->GetBinError(bin) / corr->GetBinContent(bin), 2)));
307       else
308         syst->SetBinError(bin, 0);
309       syst->SetBinContent(bin, 1);
310     }
311     
312     syst->Draw("E2 ][ SAME");
313     dummy3.DrawCopy("SAME");
314   }
315
316   ratio->Draw("SAME");
317   
318   ratio->Fit("pol0", "N");
319
320   canvas3->Modified();
321   //canvas3->SaveAs(Form("%s.eps", canvas3->GetTitle()));
322 }
323
324 void loadlibs()
325 {
326   gSystem->Load("libANALYSIS");
327   gSystem->Load("libANALYSISalice");
328   gSystem->Load("libCORRFW");
329   gSystem->Load("libPWGTools");
330   gSystem->Load("libPWGCFCorrelationsBase");
331 }
332
333 const char* lastFileName = 0;
334 void* cacheSameEvent = 0;
335 void* cacheMixedEvent = 0;
336
337 void* GetUEHistogram(const char* fileName, TList** listRef = 0, Bool_t mixed = kFALSE, const char* tag = "")
338 {
339   if (!lastFileName || strcmp(lastFileName, fileName) != 0)
340   {
341     lastFileName = fileName;
342     file = TFile::Open(fileName);
343     if (!file)
344       return 0;
345     
346     list = (TList*) gFile->Get("PWG4_LeadingTrackUE/histosLeadingTrackUE");
347     if (!list)
348       list = (TList*) gFile->Get(Form("PWG4_PhiCorrelations/histosPhiCorrelations%s", tag));
349     if (!list)
350       list = (TList*) gFile->Get("PWG4_PhiCorrelations/histosPhiCorrelations_Syst");
351       
352     if (!list)
353       return 0;
354       
355     if (listRef)
356       *listRef = list;
357       
358     cacheMixedEvent = list->FindObject("AliUEHistogramsMixed");
359     cacheSameEvent = list->FindObject("AliUEHistogramsSame");
360
361     if (mixed)
362       return cacheMixedEvent;
363     
364     if (list->FindObject("AliUEHistograms"))
365       return list->FindObject("AliUEHistograms");
366       
367     return cacheSameEvent;
368   }
369   else
370   {
371     Printf("GetUEHistogram --> Using cache for %s", fileName);
372     
373     if (mixed)
374       return cacheMixedEvent;
375     else
376       return cacheSameEvent;
377   }
378 }
379
380 void CompareBias(const char* mcFile = "PWG4_JetTasksOutput.root", Int_t region, Int_t ueHist)
381 {
382   loadlibs();
383
384   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(mcFile);
385   SetupRanges(h);
386   
387   const char* axis = "z";
388   Float_t ptLeadMin = 0;
389   Float_t ptLeadMax = -1;
390   
391   if (ueHist == 2)
392   {
393     ptLeadMin = 0.51 + 0;
394     ptLeadMax = 1.99 + 0;
395     axis = "y";
396   }
397   
398   biasFromData = (TH1*) h->GetUEHist(ueHist)->GetBias(AliUEHist::kCFStepBiasStudy, AliUEHist::kCFStepReconstructed, region, axis, ptLeadMin, ptLeadMax)->Clone("biasFromData");
399   biasFromData2 = (TH1*) h->GetUEHist(ueHist)->GetBias(AliUEHist::kCFStepBiasStudy2, AliUEHist::kCFStepReconstructed, region, axis, ptLeadMin, ptLeadMax)->Clone("biasFromData2");
400   //biasFromData = (TH1*) h->GetUEHist(ueHist)->GetBias(AliUEHist::kCFStepReconstructed, AliUEHist::kCFStepRealLeading, region, axis)->Clone("biasFromData");
401   biasFromMC   = (TH1*) h->GetUEHist(ueHist)->GetBias(AliUEHist::kCFStepReconstructed, AliUEHist::kCFStepTracked, region, axis, ptLeadMin, ptLeadMax)->Clone("biasFromMC");
402   //biasFromMC   = (TH1*) h->GetUEHist(ueHist)->GetBias(AliUEHist::kCFStepReconstructed, AliUEHist::kCFStepRealLeading, region, axis)->Clone("biasFromMC");
403   
404 /*  biasFromData->Draw();
405   biasFromMC->SetLineColor(2);
406   biasFromMC->Draw("SAME");
407   return;*/
408   
409   DrawRatio(biasFromData, biasFromMC, "bias: data vs MC");
410   DrawRatio(biasFromData, biasFromData2, "bias: data vs data two step");
411 }
412   
413 void CompareBiasWithData(const char* mcFile = "PWG4_JetTasksOutput.root", const char* dataFile = "esd.root", Int_t region = 2)
414 {
415   loadlibs();
416
417   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(mcFile);
418   SetupRanges(h);
419   
420   biasFromMC   = (TH1*) h->GetNumberDensitypT()->GetBias(AliUEHist::kCFStepReconstructed, AliUEHist::kCFStepTracked, region, "z")->Clone("biasFromMC");
421   
422   AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(dataFile);
423   SetupRanges(h2);
424   
425   biasFromData = (TH1*) h2->GetNumberDensitypT()->GetBias(AliUEHist::kCFStepBiasStudy, AliUEHist::kCFStepReconstructed, region, "z")->Clone("biasFromData");
426   biasFromData2 = (TH1*) h2->GetNumberDensitypT()->GetBias(AliUEHist::kCFStepBiasStudy2, AliUEHist::kCFStepReconstructed, region, "z")->Clone("biasFromData2");
427   
428   DrawRatio(biasFromData, biasFromMC, "bias: data vs MC");
429   DrawRatio(biasFromData, biasFromData2, "bias: data vs data two step");
430 }
431
432 Int_t count = 0;
433
434 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)
435 {
436   loadlibs();
437   
438   if (!gCache || !gFirst)
439   {
440     AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName1);
441     AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(fileName2);
442   }
443   
444   if (gCache)
445   {
446     if (!gFirst)
447     {
448       gFirst = h;
449       gSecond = h2;
450     }
451     else
452     {
453       AliUEHistograms* h = (AliUEHistograms*) gFirst;
454       AliUEHistograms* h2 = (AliUEHistograms*) gSecond;
455     }
456   }
457   
458   SetupRanges(h);
459   SetupRanges(h2);
460   
461   TH1* hist1 = h->GetUEHist(id)->GetUEHist(step1, region, ptLeadMin, ptLeadMax, centralityBegin, centralityEnd);
462   //TH1* hist1 = h->GetUEHist(id)->GetUEHist(step1, region, ptLeadMin, ptLeadMax);
463   TH1* hist2 = h2->GetUEHist(id)->GetUEHist(step2, region, ptLeadMin, ptLeadMax, centralityBegin, centralityEnd);
464
465   //hist1->Scale(1.0 / hist1->Integral());
466   //hist2->Scale(1.0 / hist2->Integral());
467
468   TH1* trackHist = 0;
469   if (id == 2)
470   {
471     trackHist = h->GetUEHist(id)->GetTrackHist(region)->ShowProjection(2, 0);
472     // only keep bins under consideration
473     for (Int_t bin=1; bin<=trackHist->GetNbinsX(); bin++)
474       if (bin < trackHist->FindBin(ptLeadMin) || bin > trackHist->FindBin(ptLeadMax))
475         trackHist->SetBinContent(bin, 0);
476   }
477
478   // systematic uncertainty
479   TH1* syst = 0; //GetSystematicUncertainty(hist1, trackHist);
480   
481   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);
482 }  
483
484 void CompareEventHist(const char* fileName1, const char* fileName2, Int_t id, Int_t step, Int_t var)
485 {
486   loadlibs();
487
488   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName1);
489   SetupRanges(h);
490
491   AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(fileName2);
492   SetupRanges(h2);
493
494   TH1* hist1 = h->GetUEHist(id)->GetEventHist()->ShowProjection(var, step);
495   TH1* hist2 = h2->GetUEHist(id)->GetEventHist()->ShowProjection(var, step);
496   
497 //   hist1 = hist1->Rebin(hist2->GetNbinsX(), "new", hist2->GetXaxis()->GetXbins()->GetArray());
498   
499 //   hist2 = hist2->Rebin(hist1->GetNbinsX(), "new", hist1->GetXaxis()->GetXbins()->GetArray());
500  
501   DrawRatio(hist1, hist2, "compare");
502 }
503
504 void CompareEventHist(const char* fileName1, const char* fileName2, Int_t id, Int_t step1, Int_t step2, Int_t var)
505 {
506   loadlibs();
507
508   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName1);
509   SetupRanges(h);
510
511   AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(fileName2);
512   SetupRanges(h2);
513   
514 //   h->GetUEHist(id)->GetEventHist()->GetGrid(step1)->GetGrid()->GetAxis(1)->SetRange(1, 5);
515 //   h2->GetUEHist(id)->GetEventHist()->GetGrid(step2)->GetGrid()->GetAxis(1)->SetRange(1, 5);
516   
517   TH1* hist1 = h->GetUEHist(id)->GetEventHist()->ShowProjection(var, step1);
518   TH1* hist2 = h2->GetUEHist(id)->GetEventHist()->ShowProjection(var, step2);
519  
520   DrawRatio(hist1, hist2, "compare");
521 }
522
523 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)
524 {
525   // fileName1 is labelled Corrected in the plot
526
527   loadlibs();
528
529   gUEHist = id;
530   gRegion = region;
531   Compare(fileName1, fileName2, id, step, step, region, ptLeadMin, ptLeadMax);
532 }
533
534 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)
535 {
536   // fileName1 is labelled Corrected in the plot
537
538   loadlibs();
539
540   gUEHist = id;
541   gRegion = region;
542   Compare(fileName1, fileName2, id, step1, step2, region, ptLeadMin, ptLeadMax, centralityBegin, centralityEnd);
543 }
544
545 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)
546 {
547   loadlibs();
548
549   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName, 0, mixed);
550   SetupRanges(h);
551
552   new TCanvas;
553   return h->GetUEHist(id)->GetUEHist(step, region, ptLeadMin, ptLeadMax, centralityBegin, centralityEnd, twoD)->DrawCopy();
554 }
555
556 void DrawProjectionsRidge(const char* fileName, const char* fileNamePbPbMix = 0)
557 {
558   if (!fileNamePbPbMix)
559     fileNamePbPbMix = fileName;
560   
561   gpTMin = 1.01;
562   gpTMax = 2.99;
563   
564   loadlibs();
565   
566   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
567   hMixed = (AliUEHistograms*) GetUEHistogram(fileNamePbPbMix, 0, kTRUE);
568   
569   SetupRanges(h);
570   SetupRanges(hMixed);
571
572   TH1* hist1 = 0;
573   GetDistAndFlow(h, hMixed, &hist1,  0, 8, 0,  100, 3.01, 3.99, 1, kTRUE, 0, kTRUE); 
574   
575 //   ((TH2*) hist1)->Rebin2D(2, 2); hist1->Scale(0.25);
576
577 //   NormalizeToBinWidth(hist1);
578   
579   proj1y = ((TH2*) hist1)->ProjectionY("proj1y", hist1->GetXaxis()->FindBin(-0.5), hist1->GetXaxis()->FindBin(0.5));
580   proj1x = ((TH2*) hist1)->ProjectionX("proj1x", hist1->GetYaxis()->FindBin(-1.79), hist1->GetYaxis()->FindBin(1.79));
581   
582   proj1y->Scale(1.0 / (hist1->GetXaxis()->FindBin(0.5) - hist1->GetXaxis()->FindBin(-0.5) + 1));
583   proj1x->Scale(1.0 / (hist1->GetYaxis()->FindBin(1.79) - hist1->GetYaxis()->FindBin(-1.79) + 1));
584   
585   proj1y->GetXaxis()->SetTitleOffset(1);
586   proj1x->GetXaxis()->SetTitleOffset(1);
587   
588   Float_t zyam = proj1x->GetBinContent(proj1x->GetXaxis()->FindBin(TMath::Pi()/2));
589   proj1x->Add(new TF1("func", "-1", -100, 100), zyam);
590   proj1y->Add(new TF1("func", "-1", -100, 100), zyam);
591   
592   new TCanvas("c", "c", 800, 800);
593   gPad->SetLeftMargin(0.15);
594   hist1->SetTitle("");
595   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
596   hist1->GetXaxis()->SetTitleOffset(1.5);
597   hist1->GetYaxis()->SetTitleOffset(2);
598   hist1->SetStats(kFALSE);
599   hist1->DrawCopy("SURF1");
600   
601 //   new TCanvas; proj1y->Draw(); new TCanvas; proj1x->Draw();  return;
602   
603   TH1* hist2 = 0;
604   GetDistAndFlow(h, hMixed, &hist2,  0, 8, 40,  100, 4.01, 5.99, 1, kTRUE, 0, kTRUE); 
605   
606 //   ((TH2*) hist2)->Rebin2D(2, 2); hist2->Scale(0.25);
607 //   NormalizeToBinWidth(hist2);
608   
609   proj2y = ((TH2*) hist2)->ProjectionY("proj2y", hist1->GetXaxis()->FindBin(-0.5), hist1->GetXaxis()->FindBin(0.5));
610   proj2x = ((TH2*) hist2)->ProjectionX("proj2x", hist1->GetYaxis()->FindBin(-1.79), hist1->GetYaxis()->FindBin(1.79));
611
612   proj2y->Scale(1.0 / (hist1->GetXaxis()->FindBin(0.5) - hist1->GetXaxis()->FindBin(-0.5) + 1));
613   proj2x->Scale(1.0 / (hist1->GetYaxis()->FindBin(1.79) - hist1->GetYaxis()->FindBin(-1.79) + 1));
614  
615   zyam = proj2x->GetBinContent(proj2x->GetXaxis()->FindBin(TMath::Pi()/2));
616   proj2x->Add(new TF1("func", "-1", -100, 100), zyam);
617   proj2y->Add(new TF1("func", "-1", -100, 100), zyam);
618
619   proj2y->SetLineColor(2); proj2x->SetLineColor(2);
620   
621   new TCanvas; proj1y->Draw(); proj2y->Draw("SAME");
622   new TCanvas; proj1x->Draw(); proj2x->Draw("SAME");
623   
624   new TCanvas("c2", "c2", 800, 800);
625   gPad->SetLeftMargin(0.15);
626   hist2->SetTitle("");
627   hist2->GetYaxis()->SetRangeUser(-1.79, 1.79);
628   hist2->GetXaxis()->SetTitleOffset(1.5);
629   hist2->GetYaxis()->SetTitleOffset(2);
630   hist2->SetStats(kFALSE);
631   hist2->DrawCopy("SURF1");
632 }
633
634 void DrawExample(const char* fileName, const char* fileNamePbPbMix = 0)
635 {
636   if (!fileNamePbPbMix)
637     fileNamePbPbMix = fileName;
638   
639   gpTMin = 1.01;
640   gpTMax = 1.99;
641   
642   loadlibs();
643   
644   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
645   hMixed = (AliUEHistograms*) GetUEHistogram(fileNamePbPbMix, 0, kTRUE);
646   
647   SetupRanges(h);
648   SetupRanges(hMixed);
649
650   TH1* hist1 = 0;
651   GetDistAndFlow(h, hMixed, &hist1,  0, 8, 0,  40, 1.01, 1.99, 1, kTRUE, 0, kTRUE); 
652   
653   ((TH2*) hist1)->Rebin2D(2, 2);
654   hist1->Scale(0.25);
655
656 //   NormalizeToBinWidth(hist1);
657   
658   new TCanvas("c", "c", 800, 800);
659   gPad->SetLeftMargin(0.15);
660   hist1->SetTitle("");
661   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
662   hist1->GetXaxis()->SetTitleOffset(1.5);
663   hist1->GetYaxis()->SetTitleOffset(2);
664   hist1->SetStats(kFALSE);
665   hist1->DrawCopy("SURF1");
666   
667   TH1* hist2 = 0;
668   GetDistAndFlow(h, hMixed, &hist2,  0, 8, 40,  100, 1.01, 1.99, 1, kTRUE, 0, kTRUE); 
669   
670   ((TH2*) hist2)->Rebin2D(2, 2); hist2->Scale(0.25);
671
672 //   NormalizeToBinWidth(hist1);
673   
674   new TCanvas("c2", "c2", 800, 800);
675   gPad->SetLeftMargin(0.15);
676   hist2->SetTitle("");
677   hist2->GetYaxis()->SetRangeUser(-1.79, 1.79);
678   hist2->GetXaxis()->SetTitleOffset(1.5);
679   hist2->GetYaxis()->SetTitleOffset(2);
680   hist2->SetStats(kFALSE);
681   hist2->DrawCopy("SURF1");
682   
683   
684
685   return;
686   
687   hist2 = hist1;
688   /*
689   GetDistAndFlow(h, hMixed, &hist1,  0, 0, 0,  10, 2.01, 3.99, 1, kTRUE, 0, kTRUE); 
690
691   ((TH2*) hist1)->Rebin2D(2, 2);
692 //   NormalizeToBinWidth(hist1);
693
694   new TCanvas("c2", "c2", 800, 800);
695   gPad->SetLeftMargin(0.15);
696   hist1->SetTitle("");
697   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
698   hist1->GetXaxis()->SetTitleOffset(1.5);
699   hist1->GetYaxis()->SetTitleOffset(2);
700   hist1->SetStats(kFALSE);
701   hist1->DrawCopy("SURF1");  
702   
703   hist1->Divide(hist2);
704
705   new TCanvas("c5", "c5", 800, 800);
706   gPad->SetLeftMargin(0.15);
707   hist1->SetTitle("");
708   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
709   hist1->GetXaxis()->SetTitleOffset(1.5);
710   hist1->GetYaxis()->SetTitleOffset(2);
711   hist1->SetStats(kFALSE);
712   hist1->DrawCopy("SURF1");    
713   
714   return;
715
716   GetDistAndFlow(h, hMixed, &hist1,  0, 6, 0,  10, 2.01, 3.99, 1, kTRUE, 0, kTRUE, 6); 
717
718   ((TH2*) hist1)->Rebin2D(2, 2);
719 //   NormalizeToBinWidth(hist1);
720
721   new TCanvas("c3", "c3", 800, 800);
722   gPad->SetLeftMargin(0.15);
723   hist1->SetTitle("");
724   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
725   hist1->GetXaxis()->SetTitleOffset(1.5);
726   hist1->GetYaxis()->SetTitleOffset(2);
727   hist1->SetStats(kFALSE);
728   hist1->DrawCopy("SURF1");  
729   
730 //   return;
731   
732 //   TH1* hist1 = 0;
733 //   GetDistAndFlow(h, hMixed, &hist1,  0, 4, 0,  10, 2.01, 3.99, 1, kTRUE, 0, kTRUE, 6); 
734 //   
735 //   ((TH2*) hist1)->Rebin2D(2, 2);
736 // //   hist1->Scale(0.25);
737 // 
738 // //   NormalizeToBinWidth(hist1);
739 //   
740 //   new TCanvas("c1b", "c1b", 800, 800);
741 //   gPad->SetLeftMargin(0.15);
742 //   hist1->SetTitle("");
743 //   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
744 //   hist1->GetXaxis()->SetTitleOffset(1.5);
745 //   hist1->GetYaxis()->SetTitleOffset(2);
746 //   hist1->SetStats(kFALSE);
747 //   hist1->DrawCopy("SURF1");
748 //   hist2 = hist1;
749   
750 //   return;
751   
752 //   GetDistAndFlow(h, 0, &hist1,  0, 8, 0,  10, 2.01, 3.99, 1, kTRUE, 0, kTRUE); 
753 // 
754 //   NormalizeToBinWidth(hist1);
755 // //   
756 //   for (Int_t i=1; i<=hist1->GetNbinsX(); ++i)
757 //   {
758 //     for (Int_t j=1; j<=hist1->GetNbinsY(); ++j)
759 //     {
760 //       Float_t factor = 1.0 / (2.0 - TMath::Abs(hist1->GetYaxis()->GetBinCenter(j)));
761 //       hist1->SetBinContent(i, j, hist1->GetBinContent(i, j) * factor);
762 //       hist1->SetBinError(i, j, hist1->GetBinError(i, j) * factor);
763 //     }
764 //   }
765
766 /*  new TCanvas("c4", "c4", 800, 800);
767   gPad->SetLeftMargin(0.15);
768   hist1->SetTitle("");
769   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
770   hist1->GetXaxis()->SetTitleOffset(1.5);
771   hist1->GetYaxis()->SetTitleOffset(2);
772   hist1->SetStats(kFALSE);
773   hist1->DrawCopy("SURF1");  */
774   
775   AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram("corrected.root");
776   AliUEHistograms* h2Mixed = (AliUEHistograms*) GetUEHistogram("corrected.root", 0, kTRUE);
777   SetupRanges(h2);
778   SetupRanges(h2Mixed);
779  
780   GetDistAndFlow(h2, h2Mixed, &hist1,  0, 8, 0,  10, 2.01, 3.99, 1, kTRUE, 0, kTRUE); 
781   ((TH2*) hist1)->Rebin2D(2, 2);
782
783   new TCanvas("c4", "c4", 800, 800);
784   gPad->SetLeftMargin(0.15);
785   hist1->SetTitle("");
786   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
787   hist1->GetXaxis()->SetTitleOffset(1.5);
788   hist1->GetYaxis()->SetTitleOffset(2);
789   hist1->SetStats(kFALSE);
790   hist1->DrawCopy("SURF1");  
791   
792   hist1->Divide(hist2);
793
794   new TCanvas("c5", "c5", 800, 800);
795   gPad->SetLeftMargin(0.15);
796   hist1->SetTitle("");
797   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
798   hist1->GetXaxis()->SetTitleOffset(1.5);
799   hist1->GetYaxis()->SetTitleOffset(2);
800   hist1->SetStats(kFALSE);
801   hist1->DrawCopy("SURF1");  
802
803 //   hist1->Divide(histMixed);
804   
805 //   NormalizeToBinWidth(hist1);
806 // //   
807 //   for (Int_t i=1; i<=hist1->GetNbinsX(); ++i)
808 //   {
809 //     for (Int_t j=1; j<=hist1->GetNbinsY(); ++j)
810 //     {
811 //       Float_t factor = 1.0 / (2.0 - TMath::Abs(hist1->GetYaxis()->GetBinCenter(j)));
812 //       hist1->SetBinContent(i, j, hist1->GetBinContent(i, j) * factor);
813 //       hist1->SetBinError(i, j
814 //   }, hist1->GetBinError(i, j) * factor);
815 //     }
816
817 //   new TCanvas("c6", "c6", 800, 800);
818 //   gPad->SetLeftMargin(0.15);
819 //   hist1->SetTitle("");
820 //   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
821 //   hist1->GetXaxis()->SetTitleOffset(1.5);
822 //   hist1->GetYaxis()->SetTitleOffset(2);
823 //   hist1->SetStats(kFALSE);
824 //   hist1->DrawCopy("SURF1");  
825   
826   return;
827   
828   GetSumOfRatios(h, hMixed, &hist1,  6, 60,  90, 8.01, 9.99, kTRUE); 
829   new TCanvas("c2", "c2", 800, 800);
830   gPad->SetLeftMargin(0.15);
831   hist1->SetTitle("");
832   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
833   hist1->GetXaxis()->SetTitleOffset(1.5);
834   hist1->GetYaxis()->SetTitleOffset(2);
835   hist1->SetStats(kFALSE);
836   hist1->Draw("SURF1");
837
838   return;
839   
840   latex = new TLatex(0.82, 0.74, "ALICE performance");
841   latex->SetTextSize(0.02);
842   latex->SetTextAlign(22);
843   latex->SetNDC();
844   latex->Draw();
845   latex = new TLatex(0.82, 0.72, "Pb-Pb 2.76 TeV");
846   latex->SetTextSize(0.02);
847   latex->SetTextAlign(22);
848   latex->SetNDC();
849   latex->Draw();
850   latex = new TLatex(0.82, 0.70, "28.09.11");
851   latex->SetTextSize(0.02);
852   latex->SetTextAlign(22);
853   latex->SetNDC();
854   latex->Draw();
855
856   DrawALICELogo(0.75, 0.75, 0.9, 0.9);
857 }
858
859 void DrawExample2(const char* fileName)
860 {
861   loadlibs();
862   
863   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
864   hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
865   
866   gpTMin = 0.51;
867   gpTMax = 0.99;
868   SetupRanges(h);
869   SetupRanges(hMixed);
870
871   TH1* hist1 = 0;
872   GetSumOfRatios(h, hMixed, &hist1,  8, 0,  5, 0.51, 0.99);
873   
874   new TCanvas("c", "c", 800, 800);
875   gPad->SetLeftMargin(0.15);
876   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
877   hist1->GetXaxis()->SetTitleOffset(1.5);
878   hist1->GetYaxis()->SetTitleOffset(2);
879   hist1->SetStats(kFALSE);
880   hist1->DrawCopy("SURF1"); 
881 }  
882
883 void CompareZVtxWeighting(const char* fileName, Int_t step = 8)
884 {
885   gpTMin = 1.01;
886   gpTMax = 1.99;
887   
888   loadlibs();
889   
890   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
891   hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
892   
893   SetupRanges(h);
894   SetupRanges(hMixed);
895   
896   TH1* hist1 = 0;
897   GetDistAndFlow(h, hMixed, &hist1,  0, step, 0,  10, 5.01, 9.99, 1, kTRUE, 0, kTRUE); 
898   hist1->Scale(1.0 / 0.972222);
899   
900   TH1* hist2 = 0;
901   GetSumOfRatios(h, hMixed, &hist2,  step, 0,  10, 5.01, 9.99, kTRUE);
902   
903   c = new TCanvas("c", "c", 1200, 400);
904   c->Divide(3, 1);
905   
906   c->cd(1); hist1->DrawCopy("SURF1");
907   c->cd(2); hist2->DrawCopy("SURF1");
908   
909   hist1->SetStats(0);
910   hist1->Divide(hist2);
911   
912   c->cd(3); hist1->DrawCopy("COLZ");
913 }
914
915 void DrawSameMixed(const char* fileName, const char* fileNamePbPbMix = 0, Int_t step = 6)
916 {
917   if (!fileNamePbPbMix)
918     fileNamePbPbMix = fileName;
919   
920   gpTMin = 1.01;
921   gpTMax = 1.99;
922   
923   loadlibs();
924   
925   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
926   hMixed = (AliUEHistograms*) GetUEHistogram(fileNamePbPbMix, 0, kTRUE);
927   
928   SetupRanges(h);
929   SetupRanges(hMixed);
930   
931   TH1* hist1 = 0;
932   GetDistAndFlow(h, 0, &hist1,  0, step, 0,  80, 2.01, 3.99, 1, kTRUE, 0, kTRUE); 
933   
934 //   ((TH2*) hist1)->Rebin2D(2, 2);
935 //   hist1->Scale(0.25);
936
937   NormalizeToBinWidth(hist1);
938   
939 //   for (Int_t i=1; i<=hist1->GetNbinsX(); ++i)
940 //   {
941 //     for (Int_t j=1; j<=hist1->GetNbinsY(); ++j)
942 //     {
943 //       Float_t factor = 1.0 / (2.0 - TMath::Abs(hist1->GetYaxis()->GetBinCenter(j) / 0.9));
944 //       hist1->SetBinContent(i, j, hist1->GetBinContent(i, j) * factor);
945 //       hist1->SetBinError(i, j, hist1->GetBinError(i, j) * factor);
946 //     }
947 //   }
948
949   c = new TCanvas("c", "c", 1600, 800);
950   c->Divide(2, 1);
951   c->cd(1);
952   gPad->SetLeftMargin(0.15);
953   hist1->SetTitle("");
954   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
955   hist1->GetZaxis()->SetTitleOffset(1.8);
956   hist1->GetXaxis()->SetTitleOffset(1.5);
957   hist1->GetYaxis()->SetTitleOffset(2);
958   hist1->GetZaxis()->SetTitle("same event pairs (a.u.)");
959   hist1->SetStats(kFALSE);
960   hist1->DrawCopy("SURF1");
961   
962   DrawALICELogo(kFALSE, 0.2, 0.7, 0.4, 0.9);
963   
964   hist2 = hist1;
965   
966   GetDistAndFlow(hMixed, 0, &hist1,  0, step, 0,  80, 2.01, 3.99, 1, kTRUE, 0, kTRUE); 
967   
968 //   ((TH2*) hist1)->Rebin2D(2, 2);
969   NormalizeToBinWidth(hist1);
970   
971 //   for (Int_t j=1; j<=hist1->GetNbinsY(); ++j)
972 //   {
973 //     Float_t factor = 1.0 / (1.0 - TMath::Abs(hist1->GetYaxis()->GetBinCenter(j)) / 6.0);
974 //     Printf("%d %f", j, factor);
975 //     for (Int_t i=1; i<=hist1->GetNbinsX(); ++i)
976 //     {
977 //       hist1->SetBinContent(i, j, hist1->GetBinContent(i, j) * factor);
978 //       hist1->SetBinError(i, j, hist1->GetBinError(i, j) * factor);
979 //     }
980 //   }
981
982   c->cd(2);
983   gPad->SetLeftMargin(0.15);
984   hist1->SetTitle("");
985   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
986   hist1->GetZaxis()->SetTitleOffset(1.8);
987   hist1->GetXaxis()->SetTitleOffset(1.5);
988   hist1->GetYaxis()->SetTitleOffset(2);
989   hist1->GetZaxis()->SetTitle("mixed event pairs (a.u.)");
990   hist1->SetStats(kFALSE);
991   hist1->DrawCopy("SURF1");
992   
993   DrawALICELogo(kFALSE, 0.2, 0.7, 0.4, 0.9);
994
995   c->SaveAs(Form("samemixed_%d.eps", step));
996   c->SaveAs(Form("samemixed_%d.png", step));
997
998   new TCanvas("c3", "c3", 800, 800);
999   gPad->SetLeftMargin(0.15);
1000   hist2->Divide(hist1);
1001   hist2->DrawCopy("SURF1");
1002 }
1003
1004 void Validation2DAllStepsNew(const char* fileName, Int_t bin = 0)
1005 {
1006   Int_t centralityFrom = 0;
1007   Int_t centralityTo = 80;
1008   
1009   gpTMin = 1.01;
1010   gpTMax = 1.99;
1011   
1012   Float_t ptTrigBegin = 2.01;
1013   Float_t ptTrigEnd = 3.99;
1014   
1015   if (bin == 1)
1016   {
1017     gpTMin = 0.51;
1018     gpTMax = 0.99;
1019     ptTrigBegin = 1.01;
1020     ptTrigEnd = 1.99;
1021   }
1022   else if (bin == 2)
1023   {
1024     gpTMin = 0.51;
1025     gpTMax = 0.99;
1026     ptTrigBegin = 0.51;
1027     ptTrigEnd = 0.99;
1028   }
1029   else if (bin == 3)
1030   {
1031 /*    gpTMin = 0.51;
1032     gpTMax = 0.99;
1033     ptTrigBegin = 0.51;
1034     ptTrigEnd = 0.99;*/
1035     centralityFrom = 0;
1036     centralityTo = 20;
1037   }
1038   else if (bin == 4)
1039   {
1040 /*    gpTMin = 0.51;
1041     gpTMax = 0.99;
1042     ptTrigBegin = 0.51;
1043     ptTrigEnd = 0.99;*/
1044     centralityFrom = 60;
1045     centralityTo = 80;
1046   }
1047   else if (bin == 5)
1048   {
1049     gpTMin = 0.51;
1050     gpTMax = 0.74;
1051     ptTrigBegin = 0.51;
1052     ptTrigEnd = 0.99;
1053   }
1054   
1055   loadlibs();
1056   
1057   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
1058   hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
1059   
1060   SetupRanges(h);
1061   SetupRanges(hMixed);
1062
1063   TH1* hist[6];
1064
1065   GetSumOfRatios(h, hMixed, &hist[0],  0, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd); 
1066   GetSumOfRatios(h, hMixed, &hist[1],  4, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd); 
1067   GetSumOfRatios(h, hMixed, &hist[2],  5, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd); 
1068   GetSumOfRatios(h, hMixed, &hist[3],  6, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd); 
1069   GetSumOfRatios(h, hMixed, &hist[4],  8, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd); 
1070   GetSumOfRatios(h, hMixed, &hist[5],  10, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd); 
1071
1072   c = new TCanvas("c", "c", 1600, 1000);
1073   c->Divide(6, 4);
1074   
1075   Float_t peakYield1[6];
1076   Float_t baselineValues1[6];
1077
1078   for (Int_t i=0; i<6; i++)
1079   {
1080     if (!hist[i])
1081       continue;
1082     
1083     // NOTE fix normalization. these 2d correlations come out of AliUEHist normalized by dphi bin width, but not deta
1084     hist[i]->Scale(1.0 / hist[i]->GetYaxis()->GetBinWidth(1));
1085
1086     ((TH2*) hist[i])->Rebin2D(2, 2); hist[i]->Scale(0.25);
1087   }
1088   
1089   for (Int_t i=0; i<6; i++)
1090   {
1091     if (!hist[i])
1092       continue;
1093
1094     c->cd(i+1);
1095     hist[i]->GetYaxis()->SetRangeUser(-1.99, 1.99);
1096     hist[i]->GetXaxis()->SetTitleOffset(1.5);
1097     hist[i]->GetYaxis()->SetTitleOffset(2);
1098     hist[i]->GetZaxis()->SetTitleOffset(1.8);
1099     hist[i]->GetZaxis()->SetTitle("1/N_{trig} dN_{assoc}/d#Delta#etad#Delta#varphi (1/rad.)");
1100     hist[i]->SetStats(kFALSE);
1101     hist[i]->DrawCopy("SURF1");    
1102     
1103     if (hist[5])
1104     {
1105       c->cd(i+1+6);
1106       TH2* clone = (TH2*) hist[i]->Clone();
1107       clone->Divide(hist[5]);
1108       clone->DrawCopy("COLZ");
1109       gPad->SetRightMargin(0.15);
1110     }
1111     
1112     c->cd(i+1+12);
1113     proj1 = ((TH2*) hist[i])->ProjectionX(Form("proj1_%d", i), hist[i]->GetYaxis()->FindBin(-0.99), hist[i]->GetYaxis()->FindBin(0.99));
1114     proj1->DrawCopy();
1115     
1116     baselineValues1[i] = proj1->Integral(proj1->FindBin(TMath::Pi()/2 - 0.2), proj1->FindBin(TMath::Pi()/2 + 0.2)) / (proj1->FindBin(TMath::Pi()/2 + 0.2) - proj1->FindBin(TMath::Pi()/2 - 0.2) + 1);
1117     peakYield1[i] = proj1->Integral(proj1->GetXaxis()->FindBin(-1), proj1->GetXaxis()->FindBin(1)) / (proj1->GetXaxis()->FindBin(0.99) - proj1->GetXaxis()->FindBin(-0.99) + 1) - baselineValues1[i];
1118     Printf("%d: %f %f", i, peakYield1[i], baselineValues1[i]);
1119
1120     if (hist[5])
1121     {
1122       proj2 = ((TH2*) hist[5])->ProjectionX(Form("proj2_%d", i), hist[5]->GetYaxis()->FindBin(-0.99), hist[5]->GetYaxis()->FindBin(0.99));
1123       proj2->SetLineColor(2);
1124       proj2->DrawCopy("SAME");
1125     
1126       c->cd(i+1+18);
1127       proj1->Divide(proj1, proj2, 1, 1, "B");
1128       proj1->Draw();
1129     }
1130   }
1131   
1132   c = new TCanvas("c2", "c2", 1600, 1000);
1133   c->Divide(6, 4);
1134
1135   for (Int_t i=0; i<6; i++)
1136   {
1137     if (!hist[i])
1138       continue;
1139
1140     c->cd(i+1);
1141     hist[i]->GetYaxis()->SetRangeUser(-1.99, 1.99);
1142     hist[i]->GetXaxis()->SetTitleOffset(1.5);
1143     hist[i]->GetYaxis()->SetTitleOffset(2);
1144     hist[i]->GetZaxis()->SetTitleOffset(1.8);
1145     hist[i]->GetZaxis()->SetTitle("1/N_{trig} dN_{assoc}/d#Delta#etad#Delta#varphi (1/rad.)");
1146     hist[i]->SetStats(kFALSE);
1147     hist[i]->DrawCopy("SURF1");    
1148     
1149     c->cd(i+1+6);
1150     TH2* clone = (TH2*) hist[i]->Clone();
1151     clone->Divide(hist[0]);
1152     clone->DrawCopy("COLZ");
1153     gPad->SetRightMargin(0.15);
1154     
1155     c->cd(i+1+12);
1156     proj1 = ((TH2*) hist[i])->ProjectionX(Form("proj3_%d", i), hist[i]->GetYaxis()->FindBin(-0.99), hist[i]->GetYaxis()->FindBin(0.99));
1157     proj1->DrawCopy();
1158     
1159     proj2 = ((TH2*) hist[0])->ProjectionX(Form("proj4_%d", i), hist[0]->GetYaxis()->FindBin(-0.99), hist[0]->GetYaxis()->FindBin(0.99));
1160     proj2->SetLineColor(2);
1161     proj2->DrawCopy("SAME");
1162     
1163     c->cd(i+1+18);
1164     proj1->Divide(proj1, proj2, 1, 1, "B");
1165     proj1->Draw();
1166   }
1167
1168   c = new TCanvas("c3", "c3", 1600, 1000);
1169   c->Divide(6, 4);
1170
1171   for (Int_t i=3; i<4; i++)
1172   {
1173     if (!hist[i])
1174       continue;
1175
1176     c->cd(i+1);
1177     hist[i]->GetYaxis()->SetRangeUser(-1.99, 1.99);
1178     hist[i]->GetXaxis()->SetTitleOffset(1.5);
1179     hist[i]->GetYaxis()->SetTitleOffset(2);
1180     hist[i]->GetZaxis()->SetTitleOffset(1.8);
1181     hist[i]->GetZaxis()->SetTitle("1/N_{trig} dN_{assoc}/d#Delta#etad#Delta#varphi (1/rad.)");
1182     hist[i]->SetStats(kFALSE);
1183     hist[i]->DrawCopy("SURF1");    
1184     
1185     c->cd(i+1+6);
1186     TH2* clone = (TH2*) hist[i]->Clone();
1187     clone->Divide(hist[4]);
1188     clone->DrawCopy("COLZ");
1189     gPad->SetRightMargin(0.15);
1190     
1191     c->cd(i+1+12);
1192     proj1 = ((TH2*) hist[i])->ProjectionX(Form("proj4_%d", i), hist[i]->GetYaxis()->FindBin(-0.99), hist[i]->GetYaxis()->FindBin(0.99));
1193     proj1->DrawCopy();
1194     
1195     proj2 = ((TH2*) hist[4])->ProjectionX(Form("proj5_%d", i), hist[4]->GetYaxis()->FindBin(-0.99), hist[4]->GetYaxis()->FindBin(0.99));
1196     proj2->SetLineColor(2);
1197     proj2->DrawCopy("SAME");
1198     
1199     c->cd(i+1+18);
1200     proj1->Divide(proj1, proj2, 1, 1, "B");
1201     proj1->Draw();
1202   }
1203   
1204   c = new TCanvas("c4", "c4", 1200, 400);
1205   c->Divide(3, 1);
1206  
1207   for (Int_t i=0; i<1; i++)
1208   {
1209     if (!hist[i])
1210       continue;
1211
1212     if (hist[5])
1213     {
1214       c->cd(1);
1215       TH2* clone = (TH2*) hist[i]->Clone();
1216       clone->Divide(hist[5]);
1217       clone->DrawCopy("COLZ");
1218       gPad->SetRightMargin(0.15);
1219     }
1220     
1221     c->cd(2);
1222     proj1 = ((TH2*) hist[i])->ProjectionX(Form("proj1_%d", i), hist[i]->GetYaxis()->FindBin(-0.99), hist[i]->GetYaxis()->FindBin(0.99));
1223     proj1->DrawCopy();
1224     
1225     baselineValues1[i] = proj1->Integral(proj1->FindBin(TMath::Pi()/2 - 0.2), proj1->FindBin(TMath::Pi()/2 + 0.2)) / (proj1->FindBin(TMath::Pi()/2 + 0.2) - proj1->FindBin(TMath::Pi()/2 - 0.2) + 1);
1226     peakYield1[i] = proj1->Integral(proj1->GetXaxis()->FindBin(-1), proj1->GetXaxis()->FindBin(1)) / (proj1->GetXaxis()->FindBin(0.99) - proj1->GetXaxis()->FindBin(-0.99) + 1) - baselineValues1[i];
1227     Printf("%d: %f %f", i, peakYield1[i], baselineValues1[i]);
1228
1229     if (hist[5])
1230     {
1231       proj2 = ((TH2*) hist[5])->ProjectionX(Form("proj2_%d", i), hist[5]->GetYaxis()->FindBin(-0.99), hist[5]->GetYaxis()->FindBin(0.99));
1232       proj2->SetLineColor(2);
1233       proj2->DrawCopy("SAME");
1234     
1235       c->cd(3);
1236       proj1->Divide(proj1, proj2, 1, 1, "B");
1237       proj1->Draw();
1238     }
1239   }
1240   
1241   for (Int_t i=0; i<6; i++)
1242     Printf("%d/%d: %f %f", i, 0, peakYield1[i] / peakYield1[0] - 1, baselineValues1[i] / baselineValues1[0] - 1);
1243
1244   if (hist[5])
1245   {
1246     for (Int_t i=0; i<6; i++)
1247       Printf("%d/%d: %f %f", i, 5, peakYield1[i] / peakYield1[5] - 1, baselineValues1[i] / baselineValues1[5] - 1);
1248   }
1249 }
1250
1251 void Validation2DAllBins(const char* fileName, const char *fileName2)
1252 {
1253   /* Int_t is[] = { 0, 1, 2, 3, 4, 5};
1254   Int_t js[] = { 1, 2, 3, 4, 5, 6 };
1255   Int_t n = 5;*/
1256 /*  Int_t is[] = { 0, 1, 1, 2, 2, 2, 3, 3, 3 };
1257   Int_t js[] = { 1, 1, 2, 1, 2, 3, 1, 2, 3 };*/
1258   Int_t is[] = { 0, 1, 1, 2, 2, 2, 3 };
1259   Int_t js[] = { 1, 1, 2, 1, 2, 3, 3 };
1260   Int_t n = 6;
1261   
1262   file1 = TFile::Open(fileName);
1263   TFile* file2 = 0;
1264   if (fileName2)
1265     file2 = TFile::Open(fileName2);
1266   
1267   file3 = TFile::Open("non_closure.root", "RECREATE");
1268   file3->Close();
1269   
1270   Float_t baselineValues1, baselineValues2, peakYield1, peakYield2;
1271   
1272   Int_t padID = 0;
1273   Int_t padN = 4;
1274   for (Int_t centr=0; centr<4; centr++)
1275   {
1276     for (Int_t i=0; i<n; i++)
1277     {
1278       if (padN == 4)
1279       {
1280         c = new TCanvas(Form("c%d", padID), Form("c%d", padID), 1100, 750);
1281         c->Divide(3, 3);
1282         padN = 1;
1283         padID++;
1284       }
1285
1286       TH2* hist1 = (TH2*) file1->Get(Form("dphi_%d_%d_%d", is[i], js[i], centr));
1287       if (!hist1)
1288         continue;
1289       TH2* hist2 = 0;
1290       if (file2)
1291         hist2 = (TH2*) file2->Get(Form("dphi_%d_%d_%d", is[i], js[i], centr));
1292       else
1293         hist2 = (TH2*) file1->Get(Form("dphi_%d_%d_%d", is[i], js[i], centr+4));
1294     
1295       // NOTE fix normalization. these 2d correlations come out of AliUEHist normalized by dphi bin width, but not deta
1296       hist1->Scale(1.0 / hist1->GetYaxis()->GetBinWidth(1));
1297       hist2->Scale(1.0 / hist2->GetYaxis()->GetBinWidth(1));
1298
1299       ((TH2*) hist1)->Rebin2D(2, 2); hist1->Scale(0.25);
1300       ((TH2*) hist2)->Rebin2D(2, 2); hist2->Scale(0.25);
1301
1302       const Float_t outerEta = 1.8;
1303       const Float_t exclusion = 0.5;
1304       
1305       c->cd(padN);
1306       proj1 = ((TH2*) hist1)->ProjectionX(Form("proj1a_%d_%d", centr, i), hist1->GetYaxis()->FindBin(-outerEta + 0.01), hist1->GetYaxis()->FindBin(-exclusion - 0.01));
1307       proj1b = ((TH2*) hist1)->ProjectionX(Form("proj1b_%d_%d", centr, i), hist1->GetYaxis()->FindBin(exclusion + 0.01), hist1->GetYaxis()->FindBin(outerEta - 0.01));
1308       proj1->Add(proj1b);
1309       copy = proj1->DrawCopy();
1310       copy->GetYaxis()->SetRangeUser(proj1->GetMinimum() * 0.9, proj1->GetMaximum() * 1.2);
1311       proj1c = ((TH2*) hist1)->ProjectionX(Form("proj1c_%d_%d", centr, i), hist1->GetYaxis()->FindBin(-outerEta + 0.01), hist1->GetYaxis()->FindBin(outerEta - 0.01));
1312       proj1c->SetLineColor(2);
1313       proj1c->DrawCopy("SAME");
1314       copy->SetMinimum(TMath::Min(copy->GetMinimum(), proj1c->GetMinimum()));
1315       copy->SetMaximum(1.2 * TMath::Max(copy->GetMaximum(), proj1c->GetMaximum()));
1316       
1317       Double_t baselineValues1E, peakYield1E;
1318       baselineValues1 = proj1->IntegralAndError(proj1->FindBin(TMath::Pi()/2 - 0.2), proj1->FindBin(TMath::Pi()/2 + 0.2), baselineValues1E);
1319       baselineValues1 /= (proj1->FindBin(TMath::Pi()/2 + 0.2) - proj1->FindBin(TMath::Pi()/2 - 0.2) + 1);
1320       baselineValues1E /= (proj1->FindBin(TMath::Pi()/2 + 0.2) - proj1->FindBin(TMath::Pi()/2 - 0.2) + 1);
1321       peakYield1 = proj1->IntegralAndError(proj1->GetXaxis()->FindBin(-1), proj1->GetXaxis()->FindBin(1), peakYield1E);
1322       peakYield1 /= (proj1->GetXaxis()->FindBin(0.99) - proj1->GetXaxis()->FindBin(-0.99) + 1);
1323       peakYield1E /= (proj1->GetXaxis()->FindBin(0.99) - proj1->GetXaxis()->FindBin(-0.99) + 1);
1324       peakYield1 -= baselineValues1;
1325       peakYield1E = TMath::Sqrt(peakYield1E * peakYield1E + baselineValues1E * baselineValues1E);
1326
1327       proj2 = ((TH2*) hist2)->ProjectionX(Form("proj2a_%d_%d", centr, i), hist2->GetYaxis()->FindBin(-outerEta + 0.01), hist2->GetYaxis()->FindBin(-exclusion - 0.01));
1328       proj2b = ((TH2*) hist2)->ProjectionX(Form("proj2b_%d_%d", centr, i), hist2->GetYaxis()->FindBin(exclusion + 0.01), hist2->GetYaxis()->FindBin(outerEta - 0.01));
1329       proj2->Add(proj2b);
1330       proj2->SetLineColor(3);
1331       proj2->DrawCopy("SAME");
1332       proj2c = ((TH2*) hist2)->ProjectionX(Form("proj2c_%d_%d", centr, i), hist2->GetYaxis()->FindBin(-outerEta + 0.01), hist2->GetYaxis()->FindBin(outerEta - 0.01));
1333       proj2c->SetLineColor(4);
1334       proj2c->DrawCopy("SAME");
1335       
1336       Double_t baselineValues2E, peakYield2E;
1337       baselineValues2 = proj2->IntegralAndError(proj1->FindBin(TMath::Pi()/2 - 0.2), proj2->FindBin(TMath::Pi()/2 + 0.2), baselineValues2E);
1338       baselineValues2 /= (proj2->FindBin(TMath::Pi()/2 + 0.2) - proj2->FindBin(TMath::Pi()/2 - 0.2) + 1);
1339       baselineValues2E /= (proj2->FindBin(TMath::Pi()/2 + 0.2) - proj2->FindBin(TMath::Pi()/2 - 0.2) + 1);
1340       peakYield2 = proj2->IntegralAndError(proj2->GetXaxis()->FindBin(-1), proj2->GetXaxis()->FindBin(1), peakYield2E);
1341       peakYield2 /= (proj2->GetXaxis()->FindBin(0.99) - proj2->GetXaxis()->FindBin(-0.99) + 1);
1342       peakYield2E /= (proj2->GetXaxis()->FindBin(0.99) - proj2->GetXaxis()->FindBin(-0.99) + 1);
1343       peakYield2 -= baselineValues2;
1344       peakYield2E = TMath::Sqrt(peakYield2E * peakYield2E + baselineValues2E * baselineValues2E);
1345       
1346   //     Printf("%d: %f %f %f %f %.2f%% %.2f%%", i, peakYield1, baselineValues1, peakYield2, baselineValues2, 100.0 * peakYield1 / peakYield2 - 100, 100.0 * baselineValues1 / baselineValues2 - 100);
1347       Printf("%s: %.2f%% +- %.2f%%    %.2f%% +- %.2f%%", 
1348              hist1->GetTitle(), 
1349              100.0 * peakYield1 / peakYield2 - 100, 
1350              100.0 * peakYield1 / peakYield2 * TMath::Sqrt(TMath::Power(peakYield1E / peakYield1, 2) + TMath::Power(peakYield2E / peakYield2, 2)),
1351              100.0 * baselineValues1 / baselineValues2 - 100,
1352              100.0 * baselineValues1 / baselineValues2 * TMath::Sqrt(TMath::Power(baselineValues1E / baselineValues1, 2) + TMath::Power(baselineValues2E / baselineValues2, 2))
1353             );
1354       
1355       c->cd(padN+3);
1356       proj1->Divide(proj1, proj2, 1, 1, "B");
1357       proj1c->Divide(proj1c, proj2c, 1, 1, "B");
1358   //     proj1->Add(proj2, -1);
1359       proj1->Draw();
1360       proj1c->SetLineColor(2);
1361       proj1c->Draw("SAME");
1362       
1363       c->cd(padN+6);
1364       hist1->Divide(hist2);
1365       hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
1366       hist1->Draw("COLZ");
1367       
1368       file3 = TFile::Open("non_closure.root", "UPDATE");
1369       proj1->Write(Form("non_closure_%d_%d_%d", is[i], js[i], centr));
1370       proj1c->Write(Form("non_closure_all_%d_%d_%d", is[i], js[i], centr));
1371       hist1->Write(Form("non_closure_2d_%d_%d_%d", is[i], js[i], centr));
1372       file3->Close();
1373       
1374       padN++;
1375     }
1376   }
1377 }
1378
1379 void Validation2DAllSteps(const char* fileName, const char* fileNameCorrected = "corrected.root", Int_t startStep = 8)
1380 {
1381   Int_t centralityFrom = 0;
1382   Int_t centralityTo = 80;
1383   
1384   gpTMin = 1.01;
1385   gpTMax = 1.99;
1386   
1387   Float_t ptTrigBegin = 2.01;
1388   Float_t ptTrigEnd = 2.99;
1389   
1390   loadlibs();
1391   
1392   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
1393   hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
1394   
1395   AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(fileNameCorrected);
1396   hMixed2 = (AliUEHistograms*) GetUEHistogram(fileNameCorrected, 0, kTRUE);
1397
1398   SetupRanges(h);
1399   SetupRanges(hMixed);
1400   SetupRanges(h2);
1401   SetupRanges(hMixed2);
1402
1403   TH1* hist[6];
1404   TH1* hist2[6];
1405
1406 //   GetSumOfRatios(h, hMixed,   &hist[0],  0, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, kTRUE); 
1407   
1408   GetDistAndFlow(h, hMixed,   &hist[0],  0, 0, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, 0); 
1409   GetDistAndFlow(h, hMixed,   &hist[1],  0, 4, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, 6); 
1410   GetDistAndFlow(h, hMixed,   &hist[2],  0, 5, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, 6); 
1411   GetDistAndFlow(h, hMixed,   &hist[3],  0, startStep, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, startStep); 
1412   GetDistAndFlow(h2, hMixed2, &hist2[0],  0, 0, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, startStep); 
1413   GetDistAndFlow(h2, hMixed2, &hist2[1],  0, 4, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, startStep); 
1414   GetDistAndFlow(h2, hMixed2, &hist2[2],  0, 5, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, startStep); 
1415   GetDistAndFlow(h2, hMixed2, &hist2[3],  0, startStep, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, startStep); 
1416
1417   c = new TCanvas("c", "c", 1600, 1000);
1418   c->Divide(4, 5);
1419   
1420   Float_t peakYield1[4];
1421   Float_t baselineValues1[4];
1422   Float_t peakYield2[4];
1423   Float_t baselineValues2[4];
1424   for (Int_t i=0; i<4; i++)
1425   {
1426     // NOTE fix normalization. these 2d correlations come out of AliUEHist normalized by dphi bin width, but not deta
1427     hist[i]->Scale(1.0 / hist[i]->GetYaxis()->GetBinWidth(1));
1428     hist2[i]->Scale(1.0 / hist2[i]->GetYaxis()->GetBinWidth(1));
1429
1430     ((TH2*) hist[i])->Rebin2D(2, 2); hist[i]->Scale(0.25);
1431 //     ((TH2*) hist[i])->Rebin2D(2, 2); hist[i]->Scale(0.25);
1432     
1433     c->cd(i+1);
1434     hist[i]->GetYaxis()->SetRangeUser(-1.59, 1.59);
1435     hist[i]->GetXaxis()->SetTitleOffset(1.5);
1436     hist[i]->GetYaxis()->SetTitleOffset(2);
1437     hist[i]->GetZaxis()->SetTitleOffset(1.8);
1438     hist[i]->GetZaxis()->SetTitle("1/N_{trig} dN_{assoc}/d#Delta#etad#Delta#varphi (1/rad.)");
1439     hist[i]->SetStats(kFALSE);
1440     hist[i]->DrawCopy("SURF1");    
1441     
1442     ((TH2*) hist2[i])->Rebin2D(2, 2); hist2[i]->Scale(0.25);
1443 //     ((TH2*) hist2[i])->Rebin2D(2, 2); hist2[i]->Scale(0.25);
1444     
1445 //     TF2* func2 = new TF2("func2", "[0]+[1]*exp(-0.5*((x/[2])**2+(y/[3])**2))", -1, 1, -0.99, 0.99);
1446 //     func2->SetParameters(0, 1, 0.5, 0.5);
1447 //     hist[i]->Fit(func2, "0R");
1448 //     hist[i]->Fit(func2, "0R");
1449 //     
1450 //     c->cd(i+1+4);
1451 //     func2->DrawClone("SURF1");
1452 //     
1453 //     baselineValues1[i] = func2->GetParameter(0);
1454 //     func2->SetParameter(0, 0);
1455 //     peakYield1[i] = func2->Integral(-0.5 * TMath::Pi(), 0.5 * TMath::Pi(), -1.4, 1.4);
1456 //     Printf("%f %f", peakYield1[i], baselineValues1[i]);
1457
1458     c->cd(i+1+4);
1459     hist2[i]->GetYaxis()->SetRangeUser(-1.59, 1.59);
1460     hist2[i]->GetXaxis()->SetTitleOffset(1.5);
1461     hist2[i]->GetYaxis()->SetTitleOffset(2);
1462     hist2[i]->GetZaxis()->SetTitleOffset(1.8);
1463     hist2[i]->GetZaxis()->SetTitle("1/N_{trig} dN_{assoc}/d#Delta#etad#Delta#varphi (1/rad.)");
1464     hist2[i]->SetStats(kFALSE);
1465     hist2[i]->DrawCopy("SURF1");        
1466     
1467     c->cd(i+1+12);
1468     proj1 = ((TH2*) hist[i])->ProjectionX(Form("proj1_%d", i), hist[i]->GetYaxis()->FindBin(-0.99), hist[i]->GetYaxis()->FindBin(0.99));
1469     proj1->DrawCopy();
1470     
1471     baselineValues1[i] = proj1->GetMinimum();
1472     peakYield1[i] = proj1->Integral(proj1->GetXaxis()->FindBin(-1), proj1->GetXaxis()->FindBin(1)) / (proj1->GetXaxis()->FindBin(0.99) - proj1->GetXaxis()->FindBin(-0.99) + 1) - baselineValues1[i];
1473     Printf("%f %f", peakYield1[i], baselineValues1[i]);
1474
1475     proj2 = ((TH2*) hist2[i])->ProjectionX(Form("proj2_%d", i), hist2[i]->GetYaxis()->FindBin(-0.99), hist2[i]->GetYaxis()->FindBin(0.99));
1476     proj2->SetLineColor(2);
1477     proj2->DrawCopy("SAME");
1478     
1479     baselineValues2[i] = proj2->GetMinimum();
1480     peakYield2[i] = proj2->Integral(proj2->GetXaxis()->FindBin(-1), proj2->GetXaxis()->FindBin(1)) / (proj2->GetXaxis()->FindBin(0.99) - proj2->GetXaxis()->FindBin(-0.99) + 1) - baselineValues2[i];
1481     Printf("%f %f", peakYield2[i], baselineValues2[i]);
1482
1483     c->cd(i+1+16);
1484     proj1->Divide(proj2);
1485     proj1->Draw();
1486     
1487 //     func2 = new TF2("func2", "[0]+[1]*exp(-0.5*((x/[2])**2+(y/[3])**2))", -1, 1, -0.99, 0.99);
1488 //     func2->SetParameters(0, 1, 0.5, 0.5);
1489 //     hist2[i]->Fit(func2, "0R");
1490 //     hist2[i]->Fit(func2, "0R");
1491 //     
1492 //     c->cd(i+1+12);
1493 //     func2->DrawClone("SURF1");
1494 //     
1495 //     baselineValues2[i] = func2->GetParameter(0);
1496 //     func2->SetParameter(0, 0);
1497 //     peakYield2[i] = func2->Integral(-0.5 * TMath::Pi(), 0.5 * TMath::Pi(), -1.4, 1.4);
1498 //     Printf("%f %f", peakYield2[i], baselineValues2[i]);
1499
1500     c->cd(i+1+8);
1501     TH2* clone = (TH2*) hist[i]->Clone();
1502     clone->Divide(hist2[i]);
1503 //     clone->Add(hist2[i], -1);
1504     clone->DrawCopy("COLZ");
1505     gPad->SetRightMargin(0.15);
1506     
1507 /*    baselineValues1[i] = clone->Integral(1, clone->GetNbinsX(), clone->GetYaxis()->FindBin(-0.99), clone->GetYaxis()->FindBin(0.99)) / clone->GetNbinsX() / (clone->GetYaxis()->FindBin(0.99) - clone->GetYaxis()->FindBin(-0.99) + 1);
1508     peakYield1[i] = clone->Integral(clone->GetXaxis()->FindBin(-0.5), clone->GetXaxis()->FindBin(0.5), clone->GetYaxis()->FindBin(-0.49), clone->GetYaxis()->FindBin(0.49)) / (clone->GetXaxis()->FindBin(0.5) - clone->GetXaxis()->FindBin(-0.5) + 1) / (clone->GetYaxis()->FindBin(0.49) - clone->GetYaxis()->FindBin(-0.49) + 1);*/
1509     
1510 //     break;
1511   }
1512
1513   for (Int_t i=0; i<4; i++)
1514   {
1515     Printf("%d: %f %f", i, peakYield1[i] / peakYield2[i] - 1, baselineValues1[i] / baselineValues2[i] - 1);
1516 //     Printf("%d: %f %f", i, peakYield1[i] - 1, baselineValues1[i] - 1);
1517   }
1518 }
1519
1520 void CorrelatedContaminationEffect(const char* fileName, const char* fileNameCorrected = "corrected.root", Int_t bin = 0, Int_t startStep = 8)
1521 {
1522   Int_t centralityFrom = 0;
1523   Int_t centralityTo = 80;
1524   
1525   gpTMin = 1.01;
1526   gpTMax = 1.99;
1527   
1528   Float_t ptTrigBegin = 2.01;
1529   Float_t ptTrigEnd = 3.99;
1530   
1531   if (bin == 1)
1532   {
1533     ptTrigBegin = 1.01;
1534     ptTrigEnd = 1.99;
1535   }
1536   else if (bin == 2)
1537   {
1538     gpTMin = 0.51;
1539     gpTMax = 0.99;
1540     ptTrigBegin = 1.01;
1541     ptTrigEnd = 1.99;  
1542   }
1543   else if (bin == 3)
1544   {
1545     ptTrigBegin = 4.01;
1546     ptTrigEnd = 7.99;  
1547   }
1548   
1549   loadlibs();
1550   
1551   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
1552   hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
1553   
1554   AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(fileNameCorrected);
1555   hMixed2 = (AliUEHistograms*) GetUEHistogram(fileNameCorrected, 0, kTRUE);
1556
1557   SetupRanges(h);
1558   SetupRanges(hMixed);
1559   SetupRanges(h2);
1560   SetupRanges(hMixed2);
1561
1562   TH1* hist[6];
1563
1564   Int_t maxFilled = 5;
1565   GetSumOfRatios(h, hMixed, &hist[0],  0, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd); 
1566   GetSumOfRatios(h, hMixed, &hist[1],  4, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd); 
1567   GetSumOfRatios(h, hMixed, &hist[2],  5, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd); 
1568   GetSumOfRatios(h, hMixed, &hist[3],  6, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd); 
1569   GetSumOfRatios(h, hMixed, &hist[4],  startStep, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd); 
1570 //   GetSumOfRatios(h2, hMixed2, &hist[5],  startStep, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd); 
1571   
1572 //   GetDistAndFlow(h, hMixed, &hist[0],  0, 0, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, 0); 
1573 //   GetDistAndFlow(h, hMixed, &hist[1],  0, 4, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, 6); 
1574 //   GetDistAndFlow(h, hMixed, &hist[2],  0, 5, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, 6); 
1575 //   GetDistAndFlow(h, hMixed, &hist[3],  0, 6, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, 6); 
1576 //   GetDistAndFlow(h, hMixed, &hist[4],  0, startStep, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, startStep); 
1577 //   GetDistAndFlow(h2, hMixed2, &hist[5],  0, 0, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, startStep); 
1578
1579   c = new TCanvas("c", "c", 1600, 1000);
1580   c->Divide(6, 2);
1581   
1582   for (Int_t i=0; i<maxFilled; i++)
1583   {
1584     // NOTE fix normalization. these 2d correlations come out of AliUEHist normalized by dphi bin width, but not deta
1585     hist[i]->Scale(1.0 / hist[i]->GetYaxis()->GetBinWidth(1));
1586
1587     ((TH2*) hist[i])->Rebin2D(2, 2); hist[i]->Scale(0.25);
1588 //     ((TH2*) hist[i])->Rebin2D(2, 2); hist[i]->Scale(0.25);
1589     
1590     c->cd(i+1);
1591     hist[i]->GetYaxis()->SetRangeUser(-1.59, 1.59);
1592     hist[i]->GetXaxis()->SetTitleOffset(1.5);
1593     hist[i]->GetYaxis()->SetTitleOffset(2);
1594     hist[i]->GetZaxis()->SetTitleOffset(1.8);
1595     hist[i]->GetZaxis()->SetTitle("1/N_{trig} dN_{assoc}/d#Delta#etad#Delta#varphi (1/rad.)");
1596     hist[i]->SetStats(kFALSE);
1597     hist[i]->DrawCopy("SURF1");    
1598   }
1599   
1600   for (Int_t i=1; i<maxFilled; i++)
1601   {
1602     TH2* clone = (TH2*) hist[i]->Clone();
1603     if (i < 4)
1604       clone->Divide(hist[i-1]);
1605     else if (i < 5)
1606       clone->Divide(hist[2]);
1607     else 
1608       clone->Divide(hist[0]);
1609   
1610     c->cd(6+i);
1611     gPad->SetRightMargin(0.15);
1612   //   hist1->SetTitle("");
1613 //     clone->GetZaxis()->SetRangeUser(0.8, 1.2);
1614     clone->GetZaxis()->SetTitle("1/N_{trig} dN_{assoc}/d#Delta#etad#Delta#varphi (1/rad.)");
1615     clone->SetStats(kFALSE);
1616     clone->DrawCopy("COLZ");
1617   }
1618
1619   Float_t peakYield[6];
1620   Float_t baselineValues[6];
1621   for (Int_t i=0; i<maxFilled; i++)
1622   {
1623     Int_t phi1 = hist[i]->GetXaxis()->FindBin(-1);
1624     Int_t phi2 = hist[i]->GetXaxis()->FindBin(1);
1625     Int_t eta1 = hist[i]->GetYaxis()->FindBin(-1.59);
1626     Int_t eta2 = hist[i]->GetYaxis()->FindBin(1.01);
1627     Int_t eta3 = hist[i]->GetYaxis()->FindBin(1.59);
1628     Float_t baseline = ((TH2*) hist[i])->Integral(phi1, phi2, eta2, eta3, "width") / (phi2 - phi1 + 1) / (eta3 - eta2 + 1);
1629     Float_t peak = ((TH2*) hist[i])->Integral(phi1, phi2, eta1, eta3, "width");
1630     Printf("%f %f", baseline, peak);
1631     peak -= baseline * (eta3 - eta1 + 1) * (phi2 - phi1 + 1);
1632     Printf("%f", peak);
1633     peakYield[i] = peak;
1634     baselineValues[i] = baseline;
1635   }
1636   
1637   for (Int_t i=1; i<maxFilled; i++)
1638   {
1639     if (i < 4)
1640       Printf("%d/%d: %f %f", i, i-1, peakYield[i] / peakYield[i-1] - 1, baselineValues[i] / baselineValues[i-1] - 1);
1641     else if (i < 5)
1642       Printf("%d/%d: %f %f", i, 2, peakYield[i] / peakYield[2] - 1, baselineValues[i] / baselineValues[2] - 1);
1643     else
1644       Printf("%d/%d: %f %f", 0, i, peakYield[0] / peakYield[i] - 1, baselineValues[0] / baselineValues[i] - 1);
1645   }
1646   
1647   c = new TCanvas("c2", "c2", 1600, 1000);
1648   c->Divide(6, 2);
1649   for (Int_t i=0; i<maxFilled; i++)
1650   {
1651     c->cd(i+1);
1652     hist[i]->DrawCopy("SURF1");
1653     
1654     TF2* func2 = new TF2("func2", "[0]+[1]*exp(-0.5*((x/[2])**2+(y/[3])**2))", -0.5 * TMath::Pi(), 0.5 * TMath::Pi(), -1.4, 1.4);
1655     func2->SetParameters(0, 1, 0.5, 0.5);
1656 //     func2->SetParLimits(1, 0, 10);
1657 //     func2->SetParLimits(2, sigmaFitLimit, 1);
1658 //     func2->SetParLimits(3, sigmaFitLimit, 1);
1659     hist[i]->Fit(func2, "0R");
1660     
1661     c->cd(i+7);
1662     func2->DrawClone("SURF1");
1663     
1664     baselineValues[i] = func2->GetParameter(0);
1665     func2->SetParameter(0, 0);
1666     peakYield[i] = func2->Integral(-0.5 * TMath::Pi(), 0.5 * TMath::Pi(), -1.4, 1.4);
1667     Printf("%f %f", peakYield[i], baselineValues[i]);
1668   }
1669
1670   for (Int_t i=1; i<maxFilled; i++)
1671   {
1672     if (i < 4)
1673       Printf("%d/%d: %f %f", i, i-1, peakYield[i] / peakYield[i-1] - 1, baselineValues[i] / baselineValues[i-1] - 1);
1674     else if (i < 5)
1675       Printf("%d/%d: %f %f", i, 2, peakYield[i] / peakYield[2] - 1, baselineValues[i] / baselineValues[2] - 1);
1676     else
1677       Printf("%d/%d: %f %f", 0, i, peakYield[0] / peakYield[i] - 1, baselineValues[0] / baselineValues[i] - 1);
1678   }
1679
1680   for (Int_t i=1; i<maxFilled; i++)
1681   {
1682     Printf("%d/%d: %f %f", 0, i, peakYield[0] / peakYield[i] - 1, baselineValues[0] / baselineValues[i] - 1);
1683   }
1684 }
1685
1686 void DrawValidation2D(const char* fileName, const char* fileNameCorrected = "corrected.root", Int_t startStep = 8)
1687 {
1688   Int_t centralityTo = 80;
1689   
1690   gpTMin = 1.01;
1691   gpTMax = 1.99;
1692   
1693   loadlibs();
1694   
1695   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
1696   hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
1697   
1698   SetupRanges(h);
1699   SetupRanges(hMixed);
1700
1701   TH1* hist1 = 0;
1702   GetDistAndFlow(h, hMixed, &hist1,  0, 0, 0,  centralityTo, 2.01, 3.99, 1, kTRUE, 0, kTRUE, 0); 
1703   // NOTE fix normalization. these 2d correlations come out of AliUEHist normalized by dphi bin width, but not deta
1704   hist1->Scale(1.0 / hist1->GetYaxis()->GetBinWidth(1));
1705   
1706 //   ((TH2*) hist1)->Rebin2D(2, 2); hist1->Scale(0.25);
1707   ((TH2*) hist1)->Rebin2D(2, 2); hist1->Scale(0.25);
1708
1709 //   NormalizeToBinWidth(hist1);
1710   
1711   c = new TCanvas("c", "c", 1000, 1000);
1712   c->Divide(2, 2);
1713   
1714   c->cd(1);
1715   gPad->SetLeftMargin(0.15);
1716 //   hist1->SetTitle("");
1717   hist1->GetYaxis()->SetRangeUser(-1.59, 1.59);
1718   hist1->GetXaxis()->SetTitleOffset(1.5);
1719   hist1->GetYaxis()->SetTitleOffset(2);
1720   hist1->GetZaxis()->SetTitleOffset(1.8);
1721   hist1->GetZaxis()->SetTitle("1/N_{trig} dN_{assoc}/d#Delta#etad#Delta#varphi (1/rad.)");
1722   hist1->SetStats(kFALSE);
1723   hist1->DrawCopy("SURF1");
1724   DrawLatex(0.1, 0.85, 1, "MC", 0.04);
1725 //   DrawALICELogo(kFALSE, 0.7, 0.7, 0.9, 0.9);
1726   
1727   hist2 = hist1;
1728   hist1 = 0;
1729   GetDistAndFlow(h, hMixed, &hist1,  0, startStep, 0,  centralityTo, 2.01, 3.99, 1, kTRUE, 0, kTRUE, startStep); 
1730   // NOTE fix normalization. these 2d correlations come out of AliUEHist normalized by dphi bin width, but not deta
1731   hist1->Scale(1.0 / hist1->GetYaxis()->GetBinWidth(1));
1732
1733 //   ((TH2*) hist1)->Rebin2D(2, 2); hist1->Scale(0.25);
1734   ((TH2*) hist1)->Rebin2D(2, 2); hist1->Scale(0.25);
1735 //   NormalizeToBinWidth(hist1);
1736
1737   c->cd(2);
1738   gPad->SetLeftMargin(0.15);
1739   hist1->SetTitle("");
1740   hist1->GetYaxis()->SetRangeUser(-1.59, 1.59);
1741   hist1->GetXaxis()->SetTitleOffset(1.5);
1742   hist1->GetYaxis()->SetTitleOffset(2);
1743   hist1->GetZaxis()->SetTitleOffset(1.8);
1744   hist1->SetStats(kFALSE);
1745   hist1->GetZaxis()->SetTitle("1/N_{trig} dN_{assoc}/d#Delta#etad#Delta#varphi (1/rad.)");
1746   hist1->DrawCopy("SURF1");  
1747   DrawLatex(0.1, 0.85, 1, "Uncorrected", 0.04);
1748 //   DrawALICELogo(kFALSE, 0.7, 0.7, 0.9, 0.9);
1749
1750   c2 = new TCanvas("c3", "c3", 800, 800);
1751 //   hist2->Scale(1.09);
1752   hist1->Divide(hist2);
1753 //   hist1->Add(hist2, -1);
1754   hist1->DrawCopy("SURF1");  
1755   
1756 //   return;
1757   
1758 //   AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram("LHC11a10a_bis_AOD090_120406_zvtx_rebinned_corrected.root");
1759   AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(fileNameCorrected);
1760   SetupRanges(h2);
1761  
1762   GetDistAndFlow(h2, hMixed, &hist1,  0, 0, 0,  centralityTo, 2.01, 3.99, 1, kTRUE, 0, kTRUE, startStep); 
1763   // NOTE fix normalization. these 2d correlations come out of AliUEHist normalized by dphi bin width, but not deta
1764   hist1->Scale(1.0 / hist1->GetYaxis()->GetBinWidth(1));
1765
1766   ((TH2*) hist1)->Rebin2D(2, 2); hist1->Scale(0.25);
1767 //   ((TH2*) hist1)->Rebin2D(2, 2); hist1->Scale(0.25);
1768
1769   c->cd(3);
1770   gPad->SetLeftMargin(0.15);
1771   hist1->SetTitle("");
1772   hist1->GetYaxis()->SetRangeUser(-1.59, 1.59);
1773   hist1->GetXaxis()->SetTitleOffset(1.5);
1774   hist1->GetZaxis()->SetTitleOffset(1.8);
1775   hist1->GetZaxis()->SetTitle("1/N_{trig} dN_{assoc}/d#Delta#etad#Delta#varphi (1/rad.)");
1776   hist1->GetYaxis()->SetTitleOffset(2);
1777   hist1->SetStats(kFALSE);
1778   hist1->DrawCopy("SURF1");  
1779   DrawLatex(0.1, 0.85, 1, "Corrected", 0.04);
1780 //   DrawALICELogo(kFALSE, 0.7, 0.7, 0.9, 0.9);
1781   
1782   hist1->Divide(hist2);
1783
1784   c->cd(4);
1785   gPad->SetRightMargin(0.15);
1786   hist1->SetTitle("");
1787   hist1->GetYaxis()->SetRangeUser(-1.59, 1.59);
1788   hist1->GetXaxis()->SetTitleOffset(1.2);
1789   hist1->GetYaxis()->SetTitleOffset(1.2);
1790   hist1->GetZaxis()->SetTitle("Ratio: Corrected / MC");
1791   hist1->SetStats(kFALSE);
1792   hist1->GetZaxis()->SetRangeUser(0.99, 1.01);
1793   hist1->DrawCopy("COLZ");  
1794
1795 //   DrawALICELogo(kFALSE, 0.7, 0.7, 0.9, 0.9);
1796   
1797   c->SaveAs("validation.eps");
1798   c->SaveAs("validation.gif");
1799 }
1800
1801 void DrawValidation(const char* fileName1, const char* fileName2)
1802 {
1803   gpTMin = 1.01;
1804   gpTMax = 3.99;
1805   
1806   CompareStep(fileName1, fileName2, 2, 6, 4, 0, 4.01, 19.99);
1807   CompareStep(fileName1, fileName2, 2, 4, 4, 0, 4.01, 19.99);
1808
1809   CompareStep(fileName1, fileName2, 2, 4, 2, 0, 4.01, 19.99);
1810   CompareStep(fileName1, fileName2, 2, 2, 2, 0, 4.01, 19.99);
1811 }
1812
1813 void ProfileMultiplicity(const char* fileName = "PWG4_JetTasksOutput.root")
1814 {
1815   loadlibs();
1816
1817   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
1818
1819   new TCanvas;
1820   h->GetCorrelationMultiplicity()->Draw("colz");
1821   gPad->SetLogz();
1822
1823   new TCanvas;
1824   h->GetCorrelationMultiplicity()->ProfileX()->DrawCopy()->Fit("pol1", "", "", 1, 10);
1825 }
1826
1827 void SetupRanges(void* obj)
1828 {
1829   if (!obj)
1830     return;
1831   ((AliUEHistograms*) obj)->SetEtaRange(0, 0);
1832 //   ((AliUEHistograms*) obj)->SetEtaRange(-0.99, 0.99); Printf("WARNING: Setting eta Range!");
1833   ((AliUEHistograms*) obj)->SetPtRange(gpTMin, gpTMax);
1834   ((AliUEHistograms*) obj)->SetCombineMinMax(kTRUE);
1835 }
1836
1837 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)
1838 {
1839   AliUEHist* corrected = (AliUEHist*) correctedVoid;
1840   AliUEHist* comparison = (AliUEHist*) comparisonVoid;
1841
1842   Int_t beginStep = AliUEHist::kCFStepAll;
1843   Int_t endStep = AliUEHist::kCFStepReconstructed;
1844   
1845   if (compareStep != -1)
1846   {
1847     beginStep = compareStep;
1848     endStep = compareStep;
1849   }
1850   
1851   Int_t beginRegion = 0;
1852   Int_t endRegion = 2;
1853   
1854   if (compareRegion != -1)
1855   {
1856     beginRegion = compareRegion;
1857     endRegion = compareRegion;
1858   }
1859
1860   for (Int_t step=beginStep; step<=endStep; step++)
1861   {
1862     if (compareStep == -1 && (step == AliUEHist::kCFStepAnaTopology || step == AliUEHist::kCFStepTriggered))
1863       continue;
1864       
1865     for (Int_t region=beginRegion; region <= endRegion; region++)
1866     {
1867       Printf("%f %f", ptLeadMin, ptLeadMax);
1868       TH1* corrHist = corrected->GetUEHist(step, region, ptLeadMin, ptLeadMax);
1869       TH1* mcHist   = comparison->GetUEHist(step, region, ptLeadMin, ptLeadMax);
1870       
1871       DrawRatio(corrHist, mcHist, TString(Form("%s: step %d %s %s", name, step, corrected->GetStepTitle(step), corrected->GetRegionTitle(region))));
1872     }
1873   }
1874 }
1875
1876 void DrawRatios(void* correctedVoid, void* comparisonVoid, Int_t compareStep = -1, Int_t compareRegion = 2, Int_t compareUEHist = 0)
1877 {
1878   AliUEHistograms* corrected = (AliUEHistograms*) correctedVoid;
1879   AliUEHistograms* comparison = (AliUEHistograms*) comparisonVoid;
1880
1881   if (1 && compareUEHist == 2)
1882   {
1883     for (Float_t ptMin = 2.01; ptMin < 8; ptMin += 2)
1884     {
1885       ((AliUEHistograms*) corrected)->SetPtRange(ptMin, ptMin + 1.98);
1886       ((AliUEHistograms*) comparison)->SetPtRange(ptMin, ptMin + 1.98);
1887       
1888       DrawRatios(TString(Form("Dphi %d pT %f", compareUEHist, ptMin)), corrected->GetUEHist(compareUEHist), comparison->GetUEHist(compareUEHist), compareStep, compareRegion, 8.01, 19.99);      
1889     }
1890     return;
1891   }
1892
1893   if (compareUEHist == -1)
1894   {
1895     for (Int_t i=0; i<2; i++)
1896       DrawRatios(TString(Form("UE %d", i)), corrected->GetUEHist(i), comparison->GetUEHist(i), compareStep, compareRegion);
1897   }
1898   else
1899     DrawRatios(TString(Form("UE %d", compareUEHist)), corrected->GetUEHist(compareUEHist), comparison->GetUEHist(compareUEHist), compareStep, compareRegion);
1900 }
1901
1902 void CompareEventsTracks(void* corrVoid, void* mcVoid, Int_t compareStep, Int_t compareRegion, Int_t compareUEHist = 0)
1903 {
1904   AliUEHist* corr = ((AliUEHistograms*) corrVoid)->GetUEHist(compareUEHist);
1905   AliUEHist* mc   = ((AliUEHistograms*) mcVoid)->GetUEHist(compareUEHist);
1906
1907   Float_t ptLeadMin = 0;
1908   Float_t ptLeadMax = -1;
1909   Int_t axis = 2;
1910   
1911   if (compareUEHist == 2)
1912   {
1913     ptLeadMin = 1.01;
1914     ptLeadMax = 1.49;
1915     axis = 4;
1916   }
1917
1918   TH1* corrHist = corr->GetUEHist(compareStep, compareRegion, ptLeadMin, ptLeadMax);
1919   TH1* mcHist   = mc  ->GetUEHist(compareStep, compareRegion, ptLeadMin, ptLeadMax);
1920   
1921   DrawRatio(corrHist, mcHist, Form("check"));
1922   
1923   corr->SetBinLimits(corr->GetTrackHist(compareRegion)->GetGrid(compareStep));
1924   mc->SetBinLimits(corr->GetTrackHist(compareRegion)->GetGrid(compareStep));
1925
1926   corrHist =  corr->GetTrackHist(compareRegion)->GetGrid(compareStep)->Project(axis);
1927   mcHist   =  mc  ->GetTrackHist(compareRegion)->GetGrid(compareStep)->Project(axis);
1928   DrawRatio(corrHist, mcHist, Form("check2"));
1929   
1930   corrHist =  corr->GetEventHist()->GetGrid(compareStep)->Project(0);
1931   mcHist   =  mc  ->GetEventHist()->GetGrid(compareStep)->Project(0);
1932   DrawRatio(corrHist, mcHist, Form("check3"));
1933 }
1934
1935 void CopyReconstructedData(const char* fileName)
1936 {
1937   loadlibs();
1938   
1939   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
1940   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);  
1941
1942   // copy
1943   AliUEHistograms* onlyRec = (AliUEHistograms*) h->Clone();
1944   onlyRec->Reset();
1945   onlyRec->CopyReconstructedData(h);
1946   
1947   AliUEHistograms* onlyRecMixed = (AliUEHistograms*) hMixed->Clone();
1948   onlyRecMixed->Reset();
1949   onlyRecMixed->CopyReconstructedData(hMixed);
1950
1951   TString newFileName(fileName);
1952   newFileName.ReplaceAll(".root", "");
1953   newFileName += "_onlyreco.root";
1954
1955   list = new TList;
1956   list->Add(onlyRec);
1957   list->Add(onlyRecMixed);
1958
1959   file3 = TFile::Open(newFileName, "RECREATE");
1960   file3->mkdir("PWG4_PhiCorrelations");
1961   file3->cd("PWG4_PhiCorrelations");
1962   list->Write("histosPhiCorrelations", TObject::kSingleKey);
1963   file3->Close();  
1964 }
1965
1966 void correctMC(const char* fileNameCorrections, const char* fileNameESD = 0, Int_t compareStep = -1, Int_t compareRegion = 2, Int_t compareUEHist = 0)
1967 {
1968   // corrects the reconstructed step in fileNameESD with fileNameCorr
1969   // if fileNameESD is 0 data from fileNameCorr is taken
1970   // afterwards the corrected distributions are compared with the MC stored in fileNameESD
1971   
1972   loadlibs();
1973   
1974   AliUEHistograms* corr = (AliUEHistograms*) GetUEHistogram(fileNameCorrections);
1975   SetupRanges(corr);
1976   
1977   corr->ExtendTrackingEfficiency();
1978   
1979   AliUEHistograms* testSample = corr;
1980   if (fileNameESD)
1981     testSample = (AliUEHistograms*) GetUEHistogram(fileNameESD);
1982       
1983   // copy to esd object
1984   AliUEHistograms* esd = (AliUEHistograms*) corr->Clone();
1985   esd->Reset();
1986   esd->CopyReconstructedData(testSample);
1987   
1988   SetupRanges(corr);
1989   SetupRanges(testSample);
1990   SetupRanges(esd);
1991   
1992   esd->Correct(corr);
1993   
1994   list = new TList;
1995   list->Add(esd);
1996   
1997   file3 = TFile::Open("correctedMC.root", "RECREATE");
1998   file3->mkdir("PWG4_PhiCorrelations");
1999   file3->cd("PWG4_PhiCorrelations");
2000   list->Write("histosPhiCorrelations", TObject::kSingleKey);
2001   file3->Close();
2002   
2003   if (1)
2004     DrawRatios(esd, testSample, compareStep, compareRegion, compareUEHist);
2005   
2006   if (1)
2007   {
2008     esd->SetPtRange(2.01, 3.99);
2009     corrected = esd->GetUEHist(2)->GetUEHist(0, 0, 4.01, 7.99, 0, -1, 1);
2010     testSample->SetPtRange(2.01, 3.99);
2011     mc = testSample->GetUEHist(2)->GetUEHist(0, 0, 4.01, 7.99, 0, -1, 1);
2012     new TCanvas; corrected->DrawCopy("SURF1");
2013     new TCanvas; mc->DrawCopy("SURF1");
2014     new TCanvas; mc->DrawCopy("SURF1")->Divide(corrected);
2015   }
2016   
2017   //CompareEventsTracks(esd, testSample, compareStep, compareRegion, compareUEHist);
2018 }
2019
2020 // function to compare only final step for all regions and distributions
2021
2022 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)
2023 {
2024   // corrects fileNameESD with fileNameCorrections and compares the two
2025   
2026   loadlibs();
2027   
2028   AliUEHistograms* corr = (AliUEHistograms*) GetUEHistogram(fileNameCorrections);
2029   
2030   TList* list = 0;
2031   AliUEHistograms* esd = (AliUEHistograms*) GetUEHistogram(fileNameESD, &list);
2032   
2033   SetupRanges(corr);
2034   SetupRanges(esd);
2035   
2036   Float_t etaRange = 1.2;
2037   Printf(">>>>> Using eta range: |eta| < %f", etaRange);
2038   corr->SetEtaRange(-etaRange+0.01, etaRange-0.01);
2039   corr->ExtendTrackingEfficiency(0);
2040   
2041 //   corr->GetUEHist(2)->GetTrackEfficiency(AliUEHist::kCFStepTracked, AliUEHist::kCFStepTrackedOnlyPrim, 1, -1, 2);
2042 //   return;
2043   
2044   if (contEnhancement)
2045   {
2046     TFile::Open(contEnhancement);
2047     contEncHist = (TH1*) gFile->Get("histo");
2048     contEncHistFullRange = (TH1*) corr->GetUEHist(0)->GetTrackingEfficiency(1)->Clone("contEncHistFullRange");
2049     
2050     contEncHistFullRange->Reset();
2051     for (Int_t i=1; i<=contEncHistFullRange->GetNbinsX(); i++)
2052     {
2053       contEncHistFullRange->SetBinContent(i, 1);
2054       if (i <= contEncHist->GetNbinsX() && contEncHist->GetXaxis()->GetBinCenter(i) < contEncUpTo && contEncHist->GetBinContent(i) > 0)
2055         contEncHistFullRange->SetBinContent(i, contEncHist->GetBinContent(i));
2056     }
2057     corr->SetContaminationEnhancement((TH1F*) contEncHistFullRange);
2058   }
2059   
2060   esd->Correct(corr);
2061   //esd->GetUEHist(2)->AdditionalDPhiCorrection(0);
2062   
2063   file3 = TFile::Open("corrected.root", "RECREATE");
2064   file3->mkdir("PWG4_PhiCorrelations");
2065   file3->cd("PWG4_PhiCorrelations");
2066   list->Write("histosPhiCorrelations", TObject::kSingleKey);
2067   file3->Close();
2068   
2069 //   DrawRatios(esd, corr, compareStep, compareRegion, compareUEHist);
2070 }
2071
2072 void ITSTPCEfficiency(const char* fileNameData, Int_t id, Int_t itsTPC = 0)
2073 {
2074   // its = 0; tpc = 1
2075
2076   // uncertainty from dN/dpT paper
2077   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};
2078   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
2079   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
2080
2081   TH1F* effHist = new TH1F("effHist", "effHist", 39, pTBins);
2082   for (Int_t i=0; i<39; i++)
2083   {
2084     Int_t bin = i;
2085     if (i > 16)
2086       bin = 16;
2087     effHist->SetBinContent(i+1, (itsTPC == 0) ? effITS[bin] : effTPC[bin]);
2088   }
2089
2090   new TCanvas; effHist->Draw();
2091
2092   EffectOfModifiedTrackingEfficiency(fileNameData, id, 2, effHist, 1, -1, (itsTPC == 0) ? "ITS" : "TPC");
2093
2094
2095
2096 void EffectOfModifiedTrackingEfficiency(const char* fileNameData, Int_t id, Int_t region, TH1* trackingEff, Int_t axis1, Int_t axis2 = -1, const char* name = "EffectOfModifiedTrackingEfficiency")
2097 {
2098   // trackingEff should contain the change in tracking efficiency, i.e. between before and after in the eta-pT plane
2099
2100   loadlibs();
2101   
2102   AliUEHistograms* corrected = (AliUEHistograms*) GetUEHistogram(fileNameData);
2103   SetupRanges(corrected);
2104   
2105   AliUEHist* ueHist = corrected->GetUEHist(id);
2106   
2107   Float_t ptLeadMin = -1;
2108   Float_t ptLeadMax = -1;
2109   if (id == 2)
2110   {
2111     // the uncertainty is flat in delta phi, so use this trick to get directly the uncertainty as function of leading pT
2112     //ptLeadMin = 1.01;
2113     //ptLeadMax = 1.99;
2114   }
2115     
2116   // histogram before
2117   TH1* before = ueHist->GetUEHist(AliUEHist::kCFStepAll, region, ptLeadMin, ptLeadMax);
2118
2119   // copy histogram
2120   // the CFStepTriggered step is overwritten here and cannot be used for comparison afterwards anymore
2121   ueHist->CorrectTracks(AliUEHist::kCFStepAll, AliUEHist::kCFStepTriggered, (TH1*) 0, 0, -1);
2122
2123   // reapply tracking efficiency
2124   ueHist->CorrectTracks(AliUEHist::kCFStepTriggered, AliUEHist::kCFStepAll, trackingEff, axis1, axis2);
2125
2126   // histogram after
2127   TH1* after = ueHist->GetUEHist(AliUEHist::kCFStepAll, region, ptLeadMin, ptLeadMax);
2128   
2129   DrawRatio(before, after, name);
2130   gPad->GetCanvas()->SaveAs(Form("%s.png", name));
2131 }
2132
2133 void EffectOfTrackCuts(const char* fileNameData, Int_t id, const char* systFile)
2134 {
2135   loadlibs();
2136
2137   AliUEHistograms* corrected = (AliUEHistograms*) GetUEHistogram(fileNameData);
2138   effHist = (TH2D*) corrected->GetUEHist(0)->GetTrackingEfficiency()->Clone("effHist");
2139
2140   file = TFile::Open(systFile);
2141
2142   Int_t maxSyst = 3;
2143   const char* systNames[] = { "NClusTPC", "Chi2TPC", "SigmaDCA" };
2144
2145   for (Int_t i=0; i<maxSyst; i++)
2146   {
2147     for (Int_t j=0; j<2; j++)
2148     {
2149       TString histName;
2150       histName.Form("%s_syst_%s", systNames[i], (j == 0) ? "up" : "down");
2151       systEffect = (TH2*) file->Get(histName);
2152
2153       // rebin
2154       effHist->Reset();
2155       for (Int_t x=1; x <= effHist->GetNbinsX(); x++)
2156         for (Int_t y=1; y <= effHist->GetNbinsY(); y++)
2157           effHist->SetBinContent(x, y, 1);
2158
2159       for (Int_t x=1; x <= systEffect->GetNbinsX(); x++)
2160         for (Int_t y=1; y <= systEffect->GetNbinsY(); y++)
2161           if (systEffect->GetBinContent(x, y) != 0)
2162             effHist->SetBinContent(effHist->GetXaxis()->FindBin(systEffect->GetYaxis()->GetBinCenter(y)), effHist->GetYaxis()->FindBin(systEffect->GetXaxis()->GetBinCenter(x)), systEffect->GetBinContent(x, y));
2163            
2164    
2165       //new TCanvas; systEffect->Draw("COLZ"); new TCanvas; effHist->Draw("COLZ");
2166  
2167       EffectOfModifiedTrackingEfficiency(fileNameData, id, (id == 2) ? 0 : 2, effHist, 0, 1, histName);
2168
2169       //return;
2170     }
2171   } 
2172 }
2173
2174 void ModifyComposition(const char* fileNameData, const char* fileNameCorrections, Int_t id, Bool_t verbose = kFALSE)
2175 {
2176   loadlibs();
2177   
2178   AliUEHistograms* corrected = (AliUEHistograms*) GetUEHistogram(fileNameData);
2179   SetupRanges(corrected);
2180   
2181   AliUEHistograms* corrections = (AliUEHistograms*) GetUEHistogram(fileNameCorrections);
2182   SetupRanges(corrections);
2183   
2184   ueHistData        = (AliUEHist*) corrected->GetUEHist(id);
2185   ueHistCorrections = (AliUEHist*) corrections->GetUEHist(id);
2186   
2187   // copy histogram
2188   // the CFStepTriggered step is overwritten here and cannot be used for comparison afterwards anymore
2189   ueHistData->CorrectTracks(AliUEHist::kCFStepAll, AliUEHist::kCFStepTriggered, (TH1*) 0, 0);
2190   
2191   Int_t maxRegion = 3;
2192   Float_t ptLeadMin = -1;
2193   Float_t ptLeadMax = -1;
2194   if (id == 2)
2195   {
2196     maxRegion = 1;
2197     // the uncertainty is flat in delta phi, so use this trick to get directly the uncertainty as function of leading pT
2198     //ptLeadMin = 1.01;
2199     //ptLeadMax = 1.99;
2200   }
2201   
2202   // histogram before
2203   TH1* before[3];
2204   for (Int_t region=0; region<maxRegion; region++)
2205     before[region] = ueHistData->GetUEHist(AliUEHist::kCFStepAll, region, ptLeadMin, ptLeadMax);
2206   
2207   //defaultEff = ueHistCorrections->GetTrackingEfficiency();
2208   defaultEff = ueHistCorrections->GetTrackingCorrection();
2209   //defaultEffpT = ueHistCorrections->GetTrackingEfficiency(1);
2210   defaultEffpT = ueHistCorrections->GetTrackingCorrection(1);
2211   defaultContainer = ueHistCorrections->GetTrackHistEfficiency();
2212   
2213   c = new TCanvas;
2214   defaultEffpT->Draw("");
2215   
2216   Float_t largestDeviation[3];
2217   for (Int_t i=0; i<maxRegion; i++)
2218     largestDeviation[i] = 0;  
2219   
2220   for (Int_t i=0; i<7; i++)
2221   {
2222     // case 0: // default
2223     // case 1: // + 30% kaons
2224     // case 2: // - 30% kaons
2225     // case 3: // + 30% protons
2226     // case 4: // - 30% protons
2227     // case 5: // + 30% others
2228     // case 6: // - 30% others
2229     Int_t correctionIndex = (i+1) / 2 + 1; // bin 1 == protons, bin 2 == kaons, ...
2230     Double_t scaleFactor = (i % 2 == 1) ? 1.3 : 0.7;
2231     if (i == 0)
2232       scaleFactor = 1;
2233     
2234     newContainer = (AliCFContainer*) defaultContainer->Clone();
2235     
2236     // modify, change all steps
2237     for (Int_t j=0; j<newContainer->GetNStep(); j++)
2238     {
2239       THnSparse* grid = newContainer->GetGrid(j)->GetGrid();
2240       
2241       for (Int_t binIdx = 0; binIdx < grid->GetNbins(); binIdx++)
2242       {
2243         Int_t bins[5];
2244         Double_t value = grid->GetBinContent(binIdx, bins);
2245         Double_t error = grid->GetBinError(binIdx);
2246         
2247         if (bins[2] != correctionIndex)
2248           continue;
2249     
2250         value *= scaleFactor;
2251         error *= scaleFactor;
2252     
2253         grid->SetBinContent(bins, value);
2254         grid->SetBinError(bins, error);      
2255       }
2256     }
2257     
2258     // put in corrections
2259     ueHistCorrections->SetTrackHistEfficiency(newContainer);
2260     
2261     // ratio
2262     //modifiedEff = ueHistCorrections->GetTrackingEfficiency();
2263     modifiedEff = ueHistCorrections->GetTrackingCorrection();
2264     modifiedEff->Divide(modifiedEff, defaultEff);
2265     //modifiedEff->Draw("COLZ");
2266     
2267     c->cd();
2268     //modifiedEffpT = ueHistCorrections->GetTrackingEfficiency(1);
2269     modifiedEffpT = ueHistCorrections->GetTrackingCorrection(1);
2270     modifiedEffpT->SetLineColor(i+1);
2271     modifiedEffpT->Draw("SAME");
2272     
2273     // apply change in tracking efficiency
2274     ueHistData->CorrectTracks(AliUEHist::kCFStepTriggered, AliUEHist::kCFStepAll, modifiedEff, 0, 1);
2275   
2276     for (Int_t region=0; region<maxRegion; region++)
2277     {
2278       // histogram after
2279       TH1* after = ueHistData->GetUEHist(AliUEHist::kCFStepAll, region, ptLeadMin, ptLeadMax);
2280       
2281       if (verbose)
2282         DrawRatio(before[region], (TH1*) after->Clone(), Form("Region %d Composition %d", region, i));
2283       
2284       // ratio is flat, extract deviation
2285       after->Divide(before[region]);
2286       after->Fit("pol0", "0");
2287       Float_t deviation = 100.0 - 100.0 * after->GetFunction("pol0")->GetParameter(0);
2288       Printf("Deviation for region %d case %d is %.2f %%", region, i, deviation);
2289       
2290       if (TMath::Abs(deviation) > largestDeviation[region])
2291         largestDeviation[region] = TMath::Abs(deviation);
2292     }
2293     //return;
2294   }
2295   
2296   for (Int_t i=0; i<maxRegion; i++)
2297     Printf("Largest deviation in region %d is %f", i, largestDeviation[i]);
2298 }    
2299
2300 void MergeList(const char* prefix = "", Bool_t copy = kFALSE)
2301 {
2302   loadlibs();
2303   gSystem->Load("libPWGflowBase");
2304   gSystem->Load("libPWGflowTasks");
2305
2306   ifstream in;
2307   in.open("list");
2308
2309   TFileMerger m(copy);
2310
2311   TString line;
2312   while (in.good())
2313   {
2314     in >> line;
2315
2316     if (line.Length() == 0)
2317       continue;
2318
2319     TString fileName;
2320     fileName.Form("%s%s", prefix, line.Data());
2321 //     fileName.Form("alien://%s", line.Data());
2322     Printf("%s", fileName.Data());
2323     
2324     m.AddFile(fileName);
2325   }
2326   
2327   m.SetFastMethod();
2328   m.OutputFile("merged.root");
2329   m.Merge();
2330 }
2331
2332 void Merge2(const char* file1, const char* file2)
2333 {
2334   loadlibs();
2335   TFileMerger m(0);
2336
2337   m.AddFile(file1);
2338   m.AddFile(file2);
2339   
2340   m.SetFastMethod();
2341   m.OutputFile("merged.root");
2342   m.Merge();
2343 }
2344
2345 void Merge3(const char* file1, const char* file2, const char* file3)
2346 {
2347   loadlibs();
2348   TFileMerger m(1);
2349
2350   m.AddFile(file1);
2351   m.AddFile(file2);
2352   m.AddFile(file3);
2353   
2354   m.SetFastMethod();
2355   m.OutputFile("merged.root");
2356   m.Merge();
2357 }
2358
2359 void MergeList2(const char* listFile, const char* dir, Bool_t onlyPrintEvents = kFALSE, const char* targetDir = "PWG4_LeadingTrackUE")
2360 {
2361   loadlibs();
2362
2363   ifstream in;
2364   in.open(listFile);
2365   
2366   AliUEHistograms* final = 0;
2367   TList* finalList = 0;
2368
2369   TString line;
2370   while (in.good())
2371   {
2372     in >> line;
2373
2374     if (line.Length() == 0)
2375       continue;
2376
2377     TString fileName;
2378     fileName.Form("%s/%s/PWG4_JetTasksOutput.root", dir, line.Data());
2379     Printf("%s", fileName.Data());
2380     
2381     TList* list = 0;
2382     AliUEHistograms* obj = (AliUEHistograms*) GetUEHistogram(fileName, &list);
2383     if (!obj)
2384       continue;
2385     
2386     if (!final)
2387     {
2388       final = (AliUEHistograms*) obj;
2389       //final->GetEventCount()->Draw(); return;
2390       Printf("Events: %d", (Int_t) final->GetEventCount()->ProjectionX()->GetBinContent(4));
2391       finalList = list;
2392     }
2393     else
2394     {
2395       additional = (AliUEHistograms*) obj;
2396       Printf("Events: %d", (Int_t) additional->GetEventCount()->ProjectionX()->GetBinContent(4));
2397       
2398       if (!onlyPrintEvents)
2399       {
2400         TList list2;
2401         list2.Add(additional);
2402         final->Merge(&list2);
2403       }
2404       delete additional;
2405       gFile->Close();
2406     }
2407   }
2408   
2409   if (onlyPrintEvents)
2410     return;
2411     
2412   Printf("Total events (at step 0): %d", (Int_t) final->GetEventCount()->ProjectionX()->GetBinContent(4));
2413   
2414   file3 = TFile::Open("merged.root", "RECREATE");
2415   file3->mkdir(targetDir);
2416   file3->cd(targetDir);
2417   finalList->Write(0, TObject::kSingleKey);
2418   file3->Close();
2419 }
2420
2421 void PlotAll(const char* correctedFile, const char* mcFile)
2422 {
2423   gCache = 1;
2424   
2425   if (gEnergy == 900)
2426   {
2427     Float_t range[] = { 1.5, 2 };
2428   }
2429   else
2430   {
2431     Float_t range[] = { 3, 10 };
2432   }
2433   
2434   for (Int_t id=0; id<3; id++)
2435   {
2436     if (id < 2)
2437       gForceRange = range[id];
2438     else
2439       gForceRange = -1;
2440       
2441     if (id < 2)
2442     {
2443       for (Int_t region=0; region<3; region++)
2444       {
2445         CompareStep(correctedFile, mcFile, id, 0, region);
2446         gPad->GetCanvas()->SaveAs(Form("%s_%s_%d_%d.png", TString(correctedFile).Tokenize(".")->First()->GetName(), TString(mcFile).Tokenize(".")->First()->GetName(), id, region));
2447       }
2448     }
2449     else
2450     {
2451       Float_t leadingPtArr[] = { 0.50, 2.0, 4.0, 6.0, 10.0, 20.0, 50.0 };
2452       for (Int_t leadingPtID=0; leadingPtID<6; leadingPtID++)
2453       {
2454         CompareStep(correctedFile, mcFile, id, 0, 0, leadingPtArr[leadingPtID] + 0.01, leadingPtArr[leadingPtID+1] - 0.01);
2455         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]));
2456       }
2457     }
2458   }
2459 }
2460
2461 /*
2462 TGraph* GetFlow2040()
2463 {
2464   // from first ALICE flow paper (provided by Raimond)
2465   // http://www-library.desy.de/spires/find/hep/www?eprint=arXiv:1011.3914
2466   
2467   // centrality 20-30% 
2468   Double_t xCumulant4th2030ALICE[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
2469   1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000,
2470   5.500000,7.000000,9.000000};
2471   Double_t yCumulant4th2030ALICE[] = {0.000000,0.000000,0.030926,0.041076,0.052063,0.059429,0.070500,0.084461,0.086745,0.099254,
2472   0.109691,0.116398,0.130831,0.141959,0.158932,0.169680,0.171387,0.178858,0.171475,0.140358,
2473   0.000000,0.000000,0.000000};
2474   Double_t xErrCumulant4th2030ALICE[23] = {0.};
2475   Double_t yErrCumulant4th2030ALICE[] = {0.000000,0.000000,0.002857,0.003451,0.003567,0.003859,0.004609,0.004976,0.005412,0.006277,
2476   0.004748,0.005808,0.006896,0.007987,0.008683,0.008080,0.013278,0.018413,0.024873,0.026057,
2477   0.000000,0.000000,0.000000};
2478   Int_t nPointsCumulant4th2030ALICE = sizeof(xCumulant4th2030ALICE)/sizeof(Double_t);                                      
2479   TGraphErrors *Cumulant4th2030ALICE = new TGraphErrors(nPointsCumulant4th2030ALICE,xCumulant4th2030ALICE,yCumulant4th2030ALICE,
2480                                                         xErrCumulant4th2030ALICE,yErrCumulant4th2030ALICE);
2481   Cumulant4th2030ALICE->SetMarkerStyle(kFullSquare);
2482   Cumulant4th2030ALICE->SetMarkerColor(kRed);
2483   Cumulant4th2030ALICE->SetMarkerSize(1.2);
2484   Cumulant4th2030ALICE->SetFillStyle(1001);
2485   Cumulant4th2030ALICE->SetFillColor(kRed-10);
2486   
2487   //===================================================================================================================
2488   // centrality 30-40% 
2489   Double_t xCumulant4th3040ALICE[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
2490   1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000,
2491   5.500000,7.000000,9.000000};
2492   Double_t yCumulant4th3040ALICE[] = {0.000000,0.000000,0.037071,0.048566,0.061083,0.070910,0.078831,0.091396,0.102026,0.109691,
2493   0.124449,0.139819,0.155561,0.165701,0.173678,0.191149,0.202015,0.204540,0.212560,0.195885,
2494   0.000000,0.000000,0.000000};
2495   Double_t xErrCumulant4th3040ALICE[23] = {0.};
2496   Double_t yErrCumulant4th3040ALICE[] = {0.000000,0.000000,0.002992,0.003364,0.003669,0.003931,0.004698,0.005261,0.005446,0.006151,
2497   0.004980,0.005741,0.007198,0.008576,0.010868,0.009926,0.015269,0.020691,0.027601,0.031834,
2498   0.000000,0.000000,0.000000};
2499   Int_t nPointsCumulant4th3040ALICE = sizeof(xCumulant4th3040ALICE)/sizeof(Double_t);
2500   TGraphErrors *Cumulant4th3040ALICE = new TGraphErrors(nPointsCumulant4th3040ALICE,xCumulant4th3040ALICE,yCumulant4th3040ALICE,
2501                                                         xErrCumulant4th3040ALICE,yErrCumulant4th3040ALICE);
2502   Cumulant4th3040ALICE->SetMarkerStyle(kFullTriangleUp);
2503   Cumulant4th3040ALICE->SetMarkerColor(kGreen+2);
2504   Cumulant4th3040ALICE->SetMarkerSize(1.2);
2505   Cumulant4th3040ALICE->SetFillStyle(1001);
2506   Cumulant4th3040ALICE->SetFillColor(kGreen+2);
2507   
2508   // build average between the two (for class 20-40%)
2509   Double_t* yAverage = new Double_t[nPointsCumulant4th3040ALICE];
2510   for (Int_t i=0; i<nPointsCumulant4th3040ALICE; i++)
2511     yAverage[i] = (yCumulant4th2030ALICE[i] + yCumulant4th3040ALICE[i]) / 2;
2512     
2513   // assume flow constant above highest pT; not neccessarily physically sound ;)
2514   if (1)
2515   {
2516     yAverage[20] = yAverage[19];
2517     xCumulant4th3040ALICE[20] = 100;
2518     nPointsCumulant4th3040ALICE -= 2;
2519   }
2520   
2521   TGraph *flow2040 = new TGraph(nPointsCumulant4th3040ALICE,xCumulant4th3040ALICE,yAverage);
2522   
2523   if (0)
2524   {
2525     flow2040->Draw("*A");
2526     Cumulant4th2030ALICE->Draw("PSAME");
2527     Cumulant4th3040ALICE->Draw("PSAME");
2528   }
2529   
2530   return flow2040;
2531 }
2532 */
2533
2534 /*
2535 TGraph* GetFlow1020()
2536 {
2537   // from first ALICE flow paper (provided by Raimond)
2538   // http://www-library.desy.de/spires/find/hep/www?eprint=arXiv:1011.3914
2539   
2540   //===================================================================================================================
2541   // centrality 10-20% 
2542   Double_t xCumulant4th1020ALICE[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
2543   1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000,
2544   5.500000,7.000000,9.000000};
2545   Double_t yCumulant4th1020ALICE[] = {0.000000,0.000000,0.024075,0.031505,0.040413,0.044981,0.055358,0.060563,0.063378,0.070030,
2546   0.082692,0.091611,0.099641,0.107223,0.122376,0.131240,0.137425,0.146050,0.131365,0.124708,
2547   0.000000,0.000000,0.000000};
2548   Double_t xErrCumulant4th1020ALICE[23] = {0.};
2549   Double_t yErrCumulant4th1020ALICE[] = {0.000000,0.000000,0.002413,0.002931,0.003444,0.003950,0.004338,0.004835,0.005059,0.005586,
2550   0.004521,0.005278,0.005999,0.007072,0.008260,0.007279,0.011897,0.017409,0.023995,0.025701,
2551   0.000000,0.000000,0.000000};
2552   Int_t nPointsCumulant4th1020ALICE = sizeof(xCumulant4th1020ALICE)/sizeof(Double_t);                                      
2553   
2554   // assume flow constant above highest pT; not neccessarily physically sound ;)
2555   if (1)
2556   {
2557     yCumulant4th1020ALICE[20] = yCumulant4th1020ALICE[19];
2558     xCumulant4th1020ALICE[20] = 100;
2559     nPointsCumulant4th1020ALICE -= 2;
2560   }
2561   
2562   TGraphErrors *Cumulant4th1020ALICE = new TGraphErrors(nPointsCumulant4th1020ALICE,xCumulant4th1020ALICE,yCumulant4th1020ALICE,
2563                                                         xErrCumulant4th1020ALICE,yErrCumulant4th1020ALICE);
2564   
2565  Cumulant4th1020ALICE->SetMarkerStyle(kFullCircle);
2566  Cumulant4th1020ALICE->SetMarkerColor(kBlue);
2567  Cumulant4th1020ALICE->SetMarkerSize(1.2);
2568  Cumulant4th1020ALICE->SetFillStyle(1001);
2569  Cumulant4th1020ALICE->SetFillColor(kBlue-10);
2570   
2571   TGraph *flow1020 = new TGraph(nPointsCumulant4th1020ALICE,xCumulant4th1020ALICE,yCumulant4th1020ALICE);
2572   
2573   if (0)
2574   {
2575     flow1020->Draw("*A");
2576     Cumulant4th1020ALICE->Draw("PSAME");
2577   }
2578   
2579   return flow1020;
2580 }
2581 */
2582
2583 /*
2584 TGraph* GetFlow05()
2585 {
2586   // takes flow measurement from 10-20% and scales by a factor extracted from Fig.3 in the ALICE flow paper
2587   // factor = integrated flow in 0-5% / integrated flow in 10-20%
2588   
2589   graph = GetFlow1020();
2590   for (Int_t i=0; i<graph->GetN(); i++)
2591     graph->GetY()[i] *= 0.016 / 0.055;
2592     
2593   return graph;
2594 }
2595 */
2596 TGraphErrors* GetFlow01_Rap02(Int_t n)
2597 {
2598   // private communication 19.04.11, Raimond / Ante
2599
2600   if (n == 2)
2601   {
2602     //  v2{SP}(pt) for 0-1%, rapidity gap = 0.2:
2603     const Int_t nPointsSP_0001ALICE_v2_etaGap02 = 18;
2604     Double_t xSP_0001ALICE_v2_etaGap02[nPointsSP_0001ALICE_v2_etaGap02] = {0.250000,0.350000,0.450000,0.550000,0.650000,
2605     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};
2606     Double_t ySP_0001ALICE_v2_etaGap02[nPointsSP_0001ALICE_v2_etaGap02] = {0.009235,0.014105,0.017274,0.018245,0.023190,
2607     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};
2608     Double_t xErrSP_0001ALICE_v2_etaGap02[nPointsSP_0001ALICE_v2_etaGap02] = {0.};
2609     Double_t yErrSP_0001ALICE_v2_etaGap02[nPointsSP_0001ALICE_v2_etaGap02] = {0.000515,0.000504,0.000532,0.000585,0.000641,
2610     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};
2611     TGraphErrors *SP_0001ALICE_v2_etaGap02 = new TGraphErrors(nPointsSP_0001ALICE_v2_etaGap02,xSP_0001ALICE_v2_etaGap02,
2612                                                               ySP_0001ALICE_v2_etaGap02,xErrSP_0001ALICE_v2_etaGap02,yErrSP_0001ALICE_v2_etaGap02);
2613     SP_0001ALICE_v2_etaGap02->SetMarkerStyle(kFullCircle);
2614     SP_0001ALICE_v2_etaGap02->SetMarkerColor(kBlue);  
2615     SP_0001ALICE_v2_etaGap02->SetFillStyle(1001);
2616     SP_0001ALICE_v2_etaGap02->SetFillColor(kBlue-10);  
2617     
2618     return SP_0001ALICE_v2_etaGap02;
2619   }
2620   
2621   if (n == 3)
2622   {
2623     //  v3{SP}(pt) for 0-1%, rapidity gap = 0.2:
2624     const Int_t nPointsSP_0001ALICE_v3_etaGap02 = 18;
2625     Double_t xSP_0001ALICE_v3_etaGap02[nPointsSP_0001ALICE_v3_etaGap02] = {0.250000,0.350000,0.450000,0.550000,0.650000,
2626     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};
2627     Double_t ySP_0001ALICE_v3_etaGap02[nPointsSP_0001ALICE_v3_etaGap02] = {0.005688,0.007222,0.010305,0.013795,0.016077,
2628     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};
2629     Double_t xErrSP_0001ALICE_v3_etaGap02[nPointsSP_0001ALICE_v3_etaGap02] = {0.};
2630     Double_t yErrSP_0001ALICE_v3_etaGap02[nPointsSP_0001ALICE_v3_etaGap02] = {0.000585,0.000582,0.000614,0.000667,0.000734,
2631     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};
2632     TGraphErrors *SP_0001ALICE_v3_etaGap02 = new TGraphErrors(nPointsSP_0001ALICE_v3_etaGap02,xSP_0001ALICE_v3_etaGap02,ySP_0001ALICE_v3_etaGap02,
2633                                                               xErrSP_0001ALICE_v3_etaGap02,yErrSP_0001ALICE_v3_etaGap02);
2634     SP_0001ALICE_v3_etaGap02->SetMarkerStyle(kFullTriangleUp);
2635     SP_0001ALICE_v3_etaGap02->SetMarkerSize(1.4);  
2636     SP_0001ALICE_v3_etaGap02->SetMarkerColor(kGreen+2);
2637     SP_0001ALICE_v3_etaGap02->SetFillStyle(1001);
2638     SP_0001ALICE_v3_etaGap02->SetFillColor(kGreen-10);     
2639     
2640     return SP_0001ALICE_v3_etaGap02;
2641   }
2642    
2643   if (n == 4)
2644   {
2645     //  v4{SP}(pt) for 0-1%, rapidity gap = 0.2:
2646     const Int_t nPointsSP_0001ALICE_v4_etaGap02 = 18;
2647     Double_t xSP_0001ALICE_v4_etaGap02[nPointsSP_0001ALICE_v4_etaGap02] = {0.250000,0.350000,0.450000,0.550000,0.650000,
2648     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};
2649     Double_t ySP_0001ALICE_v4_etaGap02[nPointsSP_0001ALICE_v4_etaGap02] = {0.001189,0.003540,0.004682,0.004210,0.007032,
2650     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};
2651     Double_t xErrSP_0001ALICE_v4_etaGap02[nPointsSP_0001ALICE_v4_etaGap02] = {0.};
2652     Double_t yErrSP_0001ALICE_v4_etaGap02[nPointsSP_0001ALICE_v4_etaGap02] = {0.001035,0.001017,0.001081,0.001187,0.001299,
2653     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};
2654     TGraphErrors *SP_0001ALICE_v4_etaGap02 = new TGraphErrors(nPointsSP_0001ALICE_v4_etaGap02,xSP_0001ALICE_v4_etaGap02,ySP_0001ALICE_v4_etaGap02,
2655                                                               xErrSP_0001ALICE_v4_etaGap02,yErrSP_0001ALICE_v4_etaGap02);
2656     SP_0001ALICE_v4_etaGap02->SetMarkerStyle(kFullSquare);
2657     SP_0001ALICE_v4_etaGap02->SetMarkerColor(kRed);
2658     SP_0001ALICE_v4_etaGap02->SetFillStyle(1001);
2659     SP_0001ALICE_v4_etaGap02->SetFillColor(kRed-10);  
2660     
2661     return SP_0001ALICE_v4_etaGap02;
2662   }
2663   
2664   return 0;
2665 }
2666
2667 TGraphErrors* GetFlow01_Rap10(Int_t n)
2668 {
2669   if (n == 2)
2670   {
2671     //  v2{SP}(pt) for 0-1%, rapidity gap = 1.0:
2672     const Int_t nPointsSP_0001ALICE_v2_etaGap10 = 21;
2673     Double_t xSP_0001ALICE_v2_etaGap10[nPointsSP_0001ALICE_v2_etaGap10] = {0.250000,0.350000,0.450000,0.550000,0.650000,
2674     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,
2675     3.250000,3.750000,4.500000};
2676     Double_t ySP_0001ALICE_v2_etaGap10[nPointsSP_0001ALICE_v2_etaGap10] = {0.009129,0.013461,0.017567,0.018041,0.020384,
2677     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,
2678     0.036905,0.054836,0.030527};
2679     Double_t xErrSP_0001ALICE_v2_etaGap10[nPointsSP_0001ALICE_v2_etaGap10] = {0.};
2680     Double_t yErrSP_0001ALICE_v2_etaGap10[nPointsSP_0001ALICE_v2_etaGap10] = {0.001179,0.001152,0.001219,0.001339,0.001480,
2681     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,
2682     0.009145,0.014749,0.018698};
2683     TGraphErrors *SP_0001ALICE_v2_etaGap10 = new TGraphErrors(nPointsSP_0001ALICE_v2_etaGap10,xSP_0001ALICE_v2_etaGap10,
2684                                                               ySP_0001ALICE_v2_etaGap10,xErrSP_0001ALICE_v2_etaGap10,yErrSP_0001ALICE_v2_etaGap10);
2685     SP_0001ALICE_v2_etaGap10->SetMarkerStyle(kOpenCircle);
2686     SP_0001ALICE_v2_etaGap10->SetMarkerColor(kBlue);  
2687     SP_0001ALICE_v2_etaGap10->SetFillStyle(1001);
2688     SP_0001ALICE_v2_etaGap10->SetFillColor(kBlue-10);  
2689     
2690     return SP_0001ALICE_v2_etaGap10;
2691   }
2692
2693   if (n == 3)
2694   {
2695     //  v3{SP}(pt) for 0-1%, rapidity gap = 1.0:
2696     const Int_t nPointsSP_0001ALICE_v3_etaGap10 = 18;
2697     Double_t xSP_0001ALICE_v3_etaGap10[nPointsSP_0001ALICE_v3_etaGap10] = {0.250000,0.350000,0.450000,0.550000,0.650000,
2698     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};
2699     Double_t ySP_0001ALICE_v3_etaGap10[nPointsSP_0001ALICE_v3_etaGap10] = {0.006373,0.008403,0.010848,0.011505,0.016728,
2700     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};
2701     Double_t xErrSP_0001ALICE_v3_etaGap10[nPointsSP_0001ALICE_v3_etaGap10] = {0.};
2702     Double_t yErrSP_0001ALICE_v3_etaGap10[nPointsSP_0001ALICE_v3_etaGap10] = {0.001286,0.001269,0.001346,0.001474,0.001620,
2703     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};
2704     TGraphErrors *SP_0001ALICE_v3_etaGap10 = new TGraphErrors(nPointsSP_0001ALICE_v3_etaGap10,xSP_0001ALICE_v3_etaGap10,ySP_0001ALICE_v3_etaGap10,
2705                                                               xErrSP_0001ALICE_v3_etaGap10,yErrSP_0001ALICE_v3_etaGap10);
2706     SP_0001ALICE_v3_etaGap10->SetMarkerStyle(kOpenTriangleUp);
2707     SP_0001ALICE_v3_etaGap10->SetMarkerSize(1.2);  
2708     SP_0001ALICE_v3_etaGap10->SetMarkerColor(kGreen+2);
2709     SP_0001ALICE_v3_etaGap10->SetFillStyle(1001);
2710     SP_0001ALICE_v3_etaGap10->SetFillColor(kGreen-10);     
2711     
2712     return SP_0001ALICE_v3_etaGap10;
2713   }
2714
2715   if (n == 4)
2716   {
2717     //  v4{SP}(pt) for 0-1%, rapidity gap = 1.0:
2718     const Int_t nPointsSP_0001ALICE_v4_etaGap10 = 11;
2719     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};
2720     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};
2721     Double_t xErrSP_0001ALICE_v4_etaGap10[nPointsSP_0001ALICE_v4_etaGap10] = {0.};
2722     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};
2723     TGraphErrors *SP_0001ALICE_v4_etaGap10 = new TGraphErrors(nPointsSP_0001ALICE_v4_etaGap10,xSP_0001ALICE_v4_etaGap10,ySP_0001ALICE_v4_etaGap10,
2724                                                               xErrSP_0001ALICE_v4_etaGap10,yErrSP_0001ALICE_v4_etaGap10);
2725     SP_0001ALICE_v4_etaGap10->SetMarkerStyle(kOpenSquare);
2726     SP_0001ALICE_v4_etaGap10->SetMarkerColor(kRed);
2727     SP_0001ALICE_v4_etaGap10->SetFillStyle(1001);
2728     SP_0001ALICE_v4_etaGap10->SetFillColor(kRed-10);  
2729     
2730     return SP_0001ALICE_v4_etaGap10;
2731   }
2732   
2733   if (n == 5)
2734   {
2735     //  v5{SP}(pt) for 0-1%, rapidity gap = 1.0:
2736     const Int_t nPointsSP_0001ALICE_v5_etaGap10 = 11;
2737     Double_t xSP_0001ALICE_v5_etaGap10[nPointsSP_0001ALICE_v5_etaGap10] = {0.300000,0.500000,0.700000,0.900000,1.200000,1.600000,2.000000,2.400000,2.800000,3.500000,4.500000};
2738     Double_t ySP_0001ALICE_v5_etaGap10[nPointsSP_0001ALICE_v5_etaGap10] = {0.007022,0.001344,0.008380,0.004298,-0.001444,0.014114,0.015012,0.041880,0.019820,0.042083,0.015268};
2739     Double_t xErrSP_0001ALICE_v5_etaGap10[nPointsSP_0001ALICE_v5_etaGap10] = {0.};
2740     Double_t yErrSP_0001ALICE_v5_etaGap10[nPointsSP_0001ALICE_v5_etaGap10] = {0.002713,0.003167,0.003741,0.004650,0.004525,0.006578,0.009986,0.015185,0.022535,0.026356,0.064773};
2741     TGraphErrors *SP_0001ALICE_v5_etaGap10 = new TGraphErrors(nPointsSP_0001ALICE_v5_etaGap10,xSP_0001ALICE_v5_etaGap10,ySP_0001ALICE_v5_etaGap10,
2742                                                               xErrSP_0001ALICE_v5_etaGap10,yErrSP_0001ALICE_v5_etaGap10);
2743     return SP_0001ALICE_v5_etaGap10;
2744   }
2745 }
2746
2747 TGraphErrors* GetFlow02_Rap10(Int_t n)
2748 {
2749   // private communication 20.04.11, Ante B. / Raimond
2750
2751   if (n == 2)
2752   {
2753      //  v2{SP}(pt) for 00-02%, eta gap = 1.0:
2754     const Int_t nPointsSP_0002_v2_etaGap10 = 15;
2755     Double_t xSP_0002_v2_etaGap10[nPointsSP_0002_v2_etaGap10] = {0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,
2756     0.900000,1.100000,1.350000,1.650000,1.950000,2.250000,2.700000,3.500000,4.500000};
2757     Double_t ySP_0002_v2_etaGap10[nPointsSP_0002_v2_etaGap10] = {0.010171,0.013190,0.017342,0.020629,0.022617,0.026549,
2758     0.027423,0.032261,0.037467,0.041001,0.045763,0.049327,0.049688,0.051480,0.038527};
2759     Double_t xErrSP_0002_v2_etaGap10[nPointsSP_0002_v2_etaGap10] = {0.};
2760     Double_t yErrSP_0002_v2_etaGap10[nPointsSP_0002_v2_etaGap10] = {0.000600,0.000590,0.000625,0.000683,0.000757,0.000839,
2761     0.000692,0.000848,0.000888,0.001209,0.001653,0.002252,0.002465,0.003968,0.009391};
2762     TGraphErrors *SP_0002_v2_etaGap10 = new TGraphErrors(nPointsSP_0002_v2_etaGap10,xSP_0002_v2_etaGap10,ySP_0002_v2_etaGap10,
2763                                                   xErrSP_0002_v2_etaGap10,yErrSP_0002_v2_etaGap10);
2764                                                   
2765     return SP_0002_v2_etaGap10;
2766   }
2767   
2768   if (n == 3)
2769   {
2770     const Int_t nPointsSP_0002_v3_etaGap10 = 15;
2771     Double_t xSP_0002_v3_etaGap10[nPointsSP_0002_v3_etaGap10] = {0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,
2772     0.900000,1.100000,1.350000,1.650000,1.950000,2.250000,2.700000,3.500000,4.500000};
2773     Double_t ySP_0002_v3_etaGap10[nPointsSP_0002_v3_etaGap10] = {0.006592,0.007286,0.012180,0.012242,0.017416,0.018393,
2774     0.024716,0.030980,0.037703,0.046558,0.051285,0.064613,0.074831,0.077093,0.082442};
2775     Double_t xErrSP_0002_v3_etaGap10[nPointsSP_0002_v3_etaGap10] = {0.};
2776     Double_t yErrSP_0002_v3_etaGap10[nPointsSP_0002_v3_etaGap10] = {0.000682,0.000676,0.000713,0.000782,0.000860,0.000953,
2777     0.000782,0.000957,0.001002,0.001361,0.001862,0.002541,0.002767,0.004466,0.010586};
2778     TGraphErrors *SP_0002_v3_etaGap10 = new TGraphErrors(nPointsSP_0002_v3_etaGap10,xSP_0002_v3_etaGap10,ySP_0002_v3_etaGap10,
2779                                                           xErrSP_0002_v3_etaGap10,yErrSP_0002_v3_etaGap10);    
2780                                                           
2781     return SP_0002_v3_etaGap10;
2782   }
2783   
2784   if (n == 4)
2785   {
2786     const Int_t nPointsSP_0002_v4_etaGap10 = 15;
2787     Double_t xSP_0002_v4_etaGap10[nPointsSP_0002_v4_etaGap10] = {0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,
2788     0.900000,1.100000,1.350000,1.650000,1.950000,2.250000,2.700000,3.500000,4.500000};
2789     Double_t ySP_0002_v4_etaGap10[nPointsSP_0002_v4_etaGap10] = {-0.000533,0.001167,0.002081,0.005218,0.006826,0.008440,
2790     0.013009,0.014812,0.017125,0.030106,0.038279,0.050488,0.067640,0.071637,0.084239};
2791     Double_t xErrSP_0002_v4_etaGap10[nPointsSP_0002_v4_etaGap10] = {0.};
2792     Double_t yErrSP_0002_v4_etaGap10[nPointsSP_0002_v4_etaGap10] = {0.001427,0.001398,0.001482,0.001594,0.001758,0.001945,
2793     0.001593,0.001951,0.002046,0.002787,0.003802,0.005182,0.005663,0.009064,0.021449};
2794     TGraphErrors *SP_0002_v4_etaGap10 = new TGraphErrors(nPointsSP_0002_v4_etaGap10,xSP_0002_v4_etaGap10,ySP_0002_v4_etaGap10,
2795                                                       xErrSP_0002_v4_etaGap10,yErrSP_0002_v4_etaGap10);
2796     return SP_0002_v4_etaGap10;
2797   }
2798   
2799   if (n == 5)
2800   {
2801     //  v5{SP}(pt) for 00-02%, eta gap = 0.2:
2802     const Int_t nPointsSP_0002_v5_etaGap02 = 13;
2803     Double_t xSP_0002_v5_etaGap02[nPointsSP_0002_v5_etaGap02] = {0.300000,0.500000,0.700000,0.900000,1.100000,1.300000,1.500000,
2804     1.700000,2.000000,2.550000,3.250000,3.950000,4.650000};
2805     Double_t ySP_0002_v5_etaGap02[nPointsSP_0002_v5_etaGap02] = {0.000570,0.002922,0.002151,0.005256,0.006287,0.005849,0.009399,
2806     0.011420,0.012455,0.032134,0.057009,0.020607,0.013551};
2807     Double_t xErrSP_0002_v5_etaGap02[nPointsSP_0002_v5_etaGap02] = {0.};
2808     Double_t yErrSP_0002_v5_etaGap02[nPointsSP_0002_v5_etaGap02] = {0.001074,0.001155,0.001433,0.001725,0.002123,0.002608,0.003196,
2809     0.003930,0.003755,0.004869,0.009719,0.018353,0.031814};
2810     TGraphErrors *SP_0002_v5_etaGap02 = new TGraphErrors(nPointsSP_0002_v5_etaGap02,xSP_0002_v5_etaGap02,ySP_0002_v5_etaGap02,
2811                                                           xErrSP_0002_v5_etaGap02,yErrSP_0002_v5_etaGap02);
2812     return SP_0002_v5_etaGap02;
2813   }
2814 }
2815
2816 TGraphErrors* GetFlow02(Int_t n)
2817 {
2818   // private communication 28.01.11, Ante B. / Raimond
2819
2820   if (n == 2)
2821   {
2822     // v2{2}(pt):
2823     Double_t xCumulant2nd0002ALICE_v2[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
2824     1.050000,1.150000,1.250000,1.350000,1.450000,1.550000,1.650000,1.750000,1.850000,1.950000,
2825     2.250000,2.750000,3.250000,3.750000,4.250000,4.750000,5.500000,6.500000,7.500000,8.500000,
2826     9.500000};
2827     Double_t yCumulant2nd0002ALICE_v2[] = {0.000000,0.000000,0.012173,0.015186,0.018580,0.021114,0.024646,0.027040,0.030269,0.032677,
2828     0.035332,0.037382,0.039228,0.040614,0.042460,0.044658,0.046246,0.050392,0.051436,0.054669,
2829     0.057330,0.063439,0.067425,0.060144,0.071260,0.070206,0.000000,0.000000,0.000000,0.000000,
2830     0.000000};
2831     Double_t xErrCumulant2nd0002ALICE_v2[31] = {0.};
2832     Double_t yErrCumulant2nd0002ALICE_v2[] = {0.000000,0.000000,0.000256,0.000259,0.000271,0.000296,0.000322,0.000357,0.000397,0.000438,
2833     0.000483,0.000529,0.000590,0.000639,0.000713,0.000793,0.000877,0.000976,0.001070,0.001197,
2834     0.000725,0.001265,0.002069,0.003156,0.004605,0.006543,0.000000,0.000000,0.000000,0.000000,
2835     0.000000};
2836     Int_t nPointsCumulant2nd0002ALICE_v2 = sizeof(xCumulant2nd0002ALICE_v2)/sizeof(Double_t);                                      
2837     TGraphErrors *Cumulant2nd0002ALICE_v2 = new TGraphErrors(nPointsCumulant2nd0002ALICE_v2,xCumulant2nd0002ALICE_v2,yCumulant2nd0002ALICE_v2,
2838                                                           xErrCumulant2nd0002ALICE_v2,yErrCumulant2nd0002ALICE_v2);
2839     Cumulant2nd0002ALICE_v2->SetMarkerStyle(kFullCircle);
2840     Cumulant2nd0002ALICE_v2->SetMarkerColor(kBlue);
2841     
2842     return Cumulant2nd0002ALICE_v2;
2843   }
2844   
2845   if (n == 3)
2846   {
2847     // v3{2}(pt):
2848     Double_t xCumulant2nd0002ALICE_v3[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
2849     1.050000,1.150000,1.250000,1.350000,1.450000,1.550000,1.650000,1.750000,1.850000,1.950000,
2850     2.250000,2.750000,3.250000,3.750000,4.250000,4.750000,5.500000,6.500000,7.500000,8.500000,
2851     9.500000};
2852     Double_t yCumulant2nd0002ALICE_v3[] = {0.000000,0.000000,0.007696,0.008994,0.010544,0.013269,0.016330,0.019234,0.023465,0.026803,
2853     0.029906,0.032211,0.035300,0.038158,0.041861,0.046002,0.049382,0.053574,0.055773,0.059420,
2854     0.069373,0.079922,0.090265,0.103583,0.111358,0.090740,0.000000,0.000000,0.000000,0.000000,
2855     0.000000};
2856     Double_t xErrCumulant2nd0002ALICE_v3[31] = {0.};
2857     Double_t yErrCumulant2nd0002ALICE_v3[] = {0.000000,0.000000,0.000318,0.000317,0.000333,0.000360,0.000392,0.000431,0.000476,0.000523,
2858     0.000575,0.000637,0.000707,0.000785,0.000878,0.000964,0.001064,0.001175,0.001320,0.001459,
2859     0.000889,0.001539,0.002530,0.003826,0.005614,0.007892,0.000000,0.000000,0.000000,0.000000,
2860     0.000000};
2861     Int_t nPointsCumulant2nd0002ALICE_v3 = sizeof(xCumulant2nd0002ALICE_v3)/sizeof(Double_t);                                      
2862     TGraphErrors *Cumulant2nd0002ALICE_v3 = new TGraphErrors(nPointsCumulant2nd0002ALICE_v3,xCumulant2nd0002ALICE_v3,yCumulant2nd0002ALICE_v3,
2863                                                           xErrCumulant2nd0002ALICE_v3,yErrCumulant2nd0002ALICE_v3);
2864     Cumulant2nd0002ALICE_v3->SetMarkerStyle(kFullTriangleUp);
2865     Cumulant2nd0002ALICE_v3->SetMarkerSize(1.2);
2866     Cumulant2nd0002ALICE_v3->SetMarkerColor(kGreen+2); 
2867     
2868     return Cumulant2nd0002ALICE_v3;
2869   }
2870   
2871   if (n == 4)
2872   {
2873     // v4{2}(pt):
2874     Double_t xCumulant2nd0002ALICE_v4[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
2875     1.050000,1.150000,1.250000,1.350000,1.450000,1.550000,1.650000,1.750000,1.850000,1.950000,
2876     2.250000,2.750000,3.250000,3.750000,4.250000,4.750000,5.500000,6.500000,7.500000,8.500000,
2877     9.500000};
2878     Double_t yCumulant2nd0002ALICE_v4[] = {0.000000,0.000000,0.005710,0.006014,0.004483,0.005453,0.007714,0.006837,0.009721,0.011288,
2879     0.012531,0.016461,0.016606,0.018587,0.022722,0.025497,0.025832,0.030994,0.030349,0.034730,
2880     0.045529,0.061153,0.074238,0.079307,0.088885,0.085218,0.000000,0.000000,0.000000,0.000000,
2881     0.000000};
2882     Double_t xErrCumulant2nd0002ALICE_v4[31] = {0.};
2883     Double_t yErrCumulant2nd0002ALICE_v4[] = {0.000000,0.000000,0.000488,0.000493,0.000523,0.000571,0.000609,0.000678,0.000742,0.000805,
2884     0.000903,0.000985,0.001100,0.001219,0.001352,0.001503,0.001682,0.001847,0.002060,0.002303,
2885     0.001400,0.002431,0.003974,0.006040,0.008901,0.012343,0.000000,0.000000,0.000000,0.000000,
2886     0.000000};
2887     Int_t nPointsCumulant2nd0002ALICE_v4 = sizeof(xCumulant2nd0002ALICE_v4)/sizeof(Double_t);                                      
2888     TGraphErrors *Cumulant2nd0002ALICE_v4 = new TGraphErrors(nPointsCumulant2nd0002ALICE_v4,xCumulant2nd0002ALICE_v4,yCumulant2nd0002ALICE_v4,
2889                                                           xErrCumulant2nd0002ALICE_v4,yErrCumulant2nd0002ALICE_v4);
2890     Cumulant2nd0002ALICE_v4->SetMarkerStyle(kFullSquare);
2891     Cumulant2nd0002ALICE_v4->SetMarkerColor(kRed);  
2892     
2893     return Cumulant2nd0002ALICE_v4;
2894   }
2895   
2896   return 0;
2897 }
2898
2899 /* results up to 5 GeV/c
2900
2901 TGraphErrors* GetFlow05(Int_t n)
2902 {
2903   // private communication 02.02.11, Ante B. / Raimond
2904
2905   if (n == 2)
2906   {
2907     // v2{2}(pt) for 0-5%:
2908     Double_t xCumulant2nd0005ALICE_v2[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
2909     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
2910     Double_t yCumulant2nd0005ALICE_v2[] = {0.000000,0.000000,0.013891,0.017693,0.021693,0.025323,0.029131,0.032443,0.035781,0.038256,
2911     0.042801,0.047705,0.053229,0.057387,0.062677,0.068815,0.077695,0.082058,0.082511,0.079791};
2912     Double_t xErrCumulant2nd0005ALICE_v2[20] = {0.};
2913     Double_t yErrCumulant2nd0005ALICE_v2[] = {0.000000,0.000000,0.000149,0.000150,0.000160,0.000174,0.000191,0.000211,0.000233,0.000257,
2914     0.000208,0.000254,0.000311,0.000377,0.000464,0.000419,0.000726,0.001180,0.001791,0.002131};
2915     Int_t nPointsCumulant2nd0005ALICE_v2 = sizeof(xCumulant2nd0005ALICE_v2)/sizeof(Double_t);                                      
2916     TGraphErrors *Cumulant2nd0005ALICE_v2 = new TGraphErrors(nPointsCumulant2nd0005ALICE_v2,xCumulant2nd0005ALICE_v2,yCumulant2nd0005ALICE_v2,
2917                                                           xErrCumulant2nd0005ALICE_v2,yErrCumulant2nd0005ALICE_v2);
2918     Cumulant2nd0005ALICE_v2->SetMarkerStyle(kFullCircle);
2919     Cumulant2nd0005ALICE_v2->SetMarkerColor(kBlue);    
2920     
2921     return Cumulant2nd0005ALICE_v2;
2922   }
2923   
2924   if (n == 3)
2925   {
2926     // v3{2}(pt) for 0-5%:
2927     Double_t xCumulant2nd0005ALICE_v3[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
2928     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
2929     Double_t yCumulant2nd0005ALICE_v3[] = {0.000000,0.000000,0.007788,0.009472,0.011596,0.014618,0.017540,0.021020,0.024946,0.028004,
2930     0.032330,0.039491,0.046368,0.053620,0.060662,0.071750,0.086746,0.097857,0.103111,0.104796};
2931     Double_t xErrCumulant2nd0005ALICE_v3[20] = {0.};
2932     Double_t yErrCumulant2nd0005ALICE_v3[] = {0.000000,0.000000,0.000194,0.000192,0.000204,0.000221,0.000241,0.000265,0.000293,0.000323,
2933     0.000266,0.000323,0.000397,0.000486,0.000601,0.000545,0.000947,0.001541,0.002328,0.002777};
2934     Int_t nPointsCumulant2nd0005ALICE_v3 = sizeof(xCumulant2nd0005ALICE_v3)/sizeof(Double_t);                                      
2935     TGraphErrors *Cumulant2nd0005ALICE_v3 = new TGraphErrors(nPointsCumulant2nd0005ALICE_v3,xCumulant2nd0005ALICE_v3,yCumulant2nd0005ALICE_v3,
2936                                                           xErrCumulant2nd0005ALICE_v3,yErrCumulant2nd0005ALICE_v3);
2937     Cumulant2nd0005ALICE_v3->SetMarkerStyle(kFullCircle);
2938     Cumulant2nd0005ALICE_v3->SetMarkerColor(kBlue);
2939
2940     return Cumulant2nd0005ALICE_v3;
2941   }
2942   
2943   if (n == 4)
2944   {
2945     // v4{2}(pt) for 0-5%:
2946     Double_t xCumulant2nd0005ALICE_v4[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
2947     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
2948     Double_t yCumulant2nd0005ALICE_v4[] = {0.000000,0.000000,0.006121,0.006137,0.005598,0.005956,0.007262,0.007991,0.009159,0.012062,
2949     0.015085,0.019225,0.024782,0.030092,0.035708,0.046542,0.060077,0.076088,0.082964,0.085405};
2950     Double_t xErrCumulant2nd0005ALICE_v4[20] = {0.};
2951     Double_t yErrCumulant2nd0005ALICE_v4[] = {0.000000,0.000000,0.000275,0.000278,0.000294,0.000319,0.000346,0.000380,0.000419,0.000459,
2952     0.000378,0.000460,0.000570,0.000700,0.000865,0.000789,0.001370,0.002227,0.003370,0.004018};
2953     Int_t nPointsCumulant2nd0005ALICE_v4 = sizeof(xCumulant2nd0005ALICE_v4)/sizeof(Double_t);                                      
2954     TGraphErrors *Cumulant2nd0005ALICE_v4 = new TGraphErrors(nPointsCumulant2nd0005ALICE_v4,xCumulant2nd0005ALICE_v4,yCumulant2nd0005ALICE_v4,
2955                                                           xErrCumulant2nd0005ALICE_v4,yErrCumulant2nd0005ALICE_v4);
2956     Cumulant2nd0005ALICE_v4->SetMarkerStyle(kFullCircle);
2957     Cumulant2nd0005ALICE_v4->SetMarkerColor(kBlue); 
2958     
2959     return Cumulant2nd0005ALICE_v4;
2960   }
2961   
2962   return 0;
2963 }
2964
2965 TGraphErrors* GetFlow510(Int_t n)
2966 {
2967   // private communication 02.02.11, Ante B. / Raimond
2968
2969   if (n == 2)
2970   {
2971     // v2{2}(pt) for 5-10%:
2972     Double_t xCumulant2nd0510ALICE_v2[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
2973     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
2974     Double_t yCumulant2nd0510ALICE_v2[] = {0.000000,0.000000,0.019872,0.026451,0.032901,0.039085,0.044930,0.050200,0.054887,0.060253,
2975     0.066587,0.075080,0.083303,0.090298,0.098782,0.109632,0.124486,0.129621,0.132076,0.120697};
2976     Double_t xErrCumulant2nd0510ALICE_v2[20] = {0.};
2977     Double_t yErrCumulant2nd0510ALICE_v2[] = {0.000000,0.000000,0.000150,0.000152,0.000163,0.000178,0.000196,0.000215,0.000237,0.000261,
2978     0.000213,0.000256,0.000313,0.000381,0.000468,0.000423,0.000727,0.001157,0.001741,0.002064};
2979     Int_t nPointsCumulant2nd0510ALICE_v2 = sizeof(xCumulant2nd0510ALICE_v2)/sizeof(Double_t);                                      
2980     TGraphErrors *Cumulant2nd0510ALICE_v2 = new TGraphErrors(nPointsCumulant2nd0510ALICE_v2,xCumulant2nd0510ALICE_v2,yCumulant2nd0510ALICE_v2,
2981                                                           xErrCumulant2nd0510ALICE_v2,yErrCumulant2nd0510ALICE_v2);
2982     Cumulant2nd0510ALICE_v2->SetMarkerStyle(kOpenCircle);
2983     Cumulant2nd0510ALICE_v2->SetMarkerColor(kBlue);   
2984      
2985     return Cumulant2nd0510ALICE_v2;
2986   }
2987   
2988   if (n == 3)
2989   {
2990     // v3{2}(pt) for 5-10%:
2991     Double_t xCumulant2nd0510ALICE_v3[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
2992     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
2993     Double_t yCumulant2nd0510ALICE_v3[] = {0.000000,0.000000,0.008596,0.010700,0.013820,0.017524,0.021507,0.024316,0.028491,0.032880,
2994     0.038741,0.045830,0.052486,0.059560,0.067990,0.081006,0.097402,0.107050,0.111743,0.116434};
2995     Double_t xErrCumulant2nd0510ALICE_v3[20] = {0.};
2996     Double_t yErrCumulant2nd0510ALICE_v3[] = {0.000000,0.000000,0.000208,0.000207,0.000218,0.000235,0.000258,0.000284,0.000314,0.000347,
2997     0.000285,0.000345,0.000426,0.000521,0.000642,0.000586,0.001008,0.001611,0.002421,0.002853};
2998     Int_t nPointsCumulant2nd0510ALICE_v3 = sizeof(xCumulant2nd0510ALICE_v3)/sizeof(Double_t);                                      
2999     TGraphErrors *Cumulant2nd0510ALICE_v3 = new TGraphErrors(nPointsCumulant2nd0510ALICE_v3,xCumulant2nd0510ALICE_v3,yCumulant2nd0510ALICE_v3,
3000                                                           xErrCumulant2nd0510ALICE_v3,yErrCumulant2nd0510ALICE_v3);
3001     Cumulant2nd0510ALICE_v3->SetMarkerStyle(kOpenCircle);
3002     Cumulant2nd0510ALICE_v3->SetMarkerColor(kBlue);
3003     
3004     return Cumulant2nd0510ALICE_v3;
3005   }
3006   
3007   if (n == 4)
3008   {
3009     // v4{2}(pt) for 5-10%:
3010     Double_t xCumulant2nd0510ALICE_v4[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3011     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
3012     Double_t yCumulant2nd0510ALICE_v4[] = {0.000000,0.000000,0.006466,0.006731,0.006344,0.007374,0.008775,0.010324,0.012323,0.014533,
3013     0.017261,0.022507,0.028776,0.035403,0.041936,0.051491,0.070340,0.080081,0.095077,0.088526};
3014     Double_t xErrCumulant2nd0510ALICE_v4[20] = {0.};
3015     Double_t yErrCumulant2nd0510ALICE_v4[] = {0.000000,0.000000,0.000292,0.000295,0.000312,0.000336,0.000366,0.000403,0.000443,0.000485,
3016     0.000399,0.000486,0.000603,0.000738,0.000914,0.000836,0.001443,0.002303,0.003448,0.004078};
3017     Int_t nPointsCumulant2nd0510ALICE_v4 = sizeof(xCumulant2nd0510ALICE_v4)/sizeof(Double_t);                                      
3018     TGraphErrors *Cumulant2nd0510ALICE_v4 = new TGraphErrors(nPointsCumulant2nd0510ALICE_v4,xCumulant2nd0510ALICE_v4,yCumulant2nd0510ALICE_v4,
3019                                                           xErrCumulant2nd0510ALICE_v4,yErrCumulant2nd0510ALICE_v4);
3020     Cumulant2nd0510ALICE_v4->SetMarkerStyle(kOpenCircle);
3021     Cumulant2nd0510ALICE_v4->SetMarkerColor(kBlue);    
3022     
3023     return Cumulant2nd0510ALICE_v4;
3024   }
3025   
3026   return 0;
3027 }
3028
3029 TGraphErrors* GetFlow1020(Int_t n)
3030 {
3031   // private communication 02.02.11, Ante B. / Raimond
3032
3033   if (n == 2)
3034   {
3035     // v2{2}(pt) for 10-20%:
3036     Double_t xCumulant2nd1020ALICE_v2[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3037     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
3038     Double_t yCumulant2nd1020ALICE_v2[] = {0.000000,0.000000,0.027683,0.037083,0.046511,0.055519,0.063979,0.071626,0.078537,0.085975,
3039     0.095001,0.106979,0.118456,0.129721,0.140641,0.155161,0.173402,0.179870,0.180616,0.168921};
3040     Double_t xErrCumulant2nd1020ALICE_v2[20] = {0.};
3041     Double_t yErrCumulant2nd1020ALICE_v2[] = {0.000000,0.000000,0.000121,0.000124,0.000134,0.000147,0.000163,0.000179,0.000198,0.000217,
3042     0.000177,0.000212,0.000257,0.000311,0.000380,0.000341,0.000569,0.000882,0.001309,0.001537};
3043     Int_t nPointsCumulant2nd1020ALICE_v2 = sizeof(xCumulant2nd1020ALICE_v2)/sizeof(Double_t);                                      
3044     TGraphErrors *Cumulant2nd1020ALICE_v2 = new TGraphErrors(nPointsCumulant2nd1020ALICE_v2,xCumulant2nd1020ALICE_v2,yCumulant2nd1020ALICE_v2,
3045                                                           xErrCumulant2nd1020ALICE_v2,yErrCumulant2nd1020ALICE_v2);
3046     Cumulant2nd1020ALICE_v2->SetMarkerStyle(kFullSquare);
3047     Cumulant2nd1020ALICE_v2->SetMarkerColor(kRed);     
3048     
3049     return Cumulant2nd1020ALICE_v2;
3050   }
3051   
3052   if (n == 3)
3053   {
3054     // v3{2}(pt) for 10-20%:
3055     Double_t xCumulant2nd1020ALICE_v3[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3056     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
3057     Double_t yCumulant2nd1020ALICE_v3[] = {0.000000,0.000000,0.009830,0.012858,0.016111,0.020120,0.023948,0.028349,0.032741,0.037244,
3058     0.043385,0.051803,0.059374,0.068686,0.076763,0.090151,0.106530,0.117448,0.121383,0.118247};
3059     Double_t xErrCumulant2nd1020ALICE_v3[20] = {0.};
3060     Double_t yErrCumulant2nd1020ALICE_v3[] = {0.000000,0.000000,0.000171,0.000170,0.000180,0.000195,0.000215,0.000236,0.000261,0.000287,
3061     0.000236,0.000288,0.000353,0.000434,0.000536,0.000488,0.000823,0.001277,0.001892,0.002224};
3062     Int_t nPointsCumulant2nd1020ALICE_v3 = sizeof(xCumulant2nd1020ALICE_v3)/sizeof(Double_t);                                      
3063     TGraphErrors *Cumulant2nd1020ALICE_v3 = new TGraphErrors(nPointsCumulant2nd1020ALICE_v3,xCumulant2nd1020ALICE_v3,yCumulant2nd1020ALICE_v3,
3064                                                           xErrCumulant2nd1020ALICE_v3,yErrCumulant2nd1020ALICE_v3);
3065     Cumulant2nd1020ALICE_v3->SetMarkerStyle(kFullSquare);
3066     Cumulant2nd1020ALICE_v3->SetMarkerColor(kRed); 
3067     
3068     return Cumulant2nd1020ALICE_v3;
3069   }
3070   
3071   if (n == 4)
3072   {
3073     // v4{2}(pt) for 10-20%:
3074     Double_t xCumulant2nd1020ALICE_v4[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3075     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
3076     Double_t yCumulant2nd1020ALICE_v4[] = {0.000000,0.000000,0.007423,0.007647,0.008189,0.008592,0.009489,0.011671,0.013739,0.017199,
3077     0.020084,0.026004,0.031843,0.038388,0.047357,0.057251,0.072433,0.086326,0.094282,0.097432};
3078     Double_t xErrCumulant2nd1020ALICE_v4[20] = {0.};
3079     Double_t yErrCumulant2nd1020ALICE_v4[] = {0.000000,0.000000,0.000243,0.000244,0.000257,0.000279,0.000306,0.000335,0.000368,0.000405,
3080     0.000333,0.000406,0.000502,0.000618,0.000770,0.000701,0.001185,0.001845,0.002730,0.003193};
3081     Int_t nPointsCumulant2nd1020ALICE_v4 = sizeof(xCumulant2nd1020ALICE_v4)/sizeof(Double_t);                                      
3082     TGraphErrors *Cumulant2nd1020ALICE_v4 = new TGraphErrors(nPointsCumulant2nd1020ALICE_v4,xCumulant2nd1020ALICE_v4,yCumulant2nd1020ALICE_v4,
3083                                                           xErrCumulant2nd1020ALICE_v4,yErrCumulant2nd1020ALICE_v4);
3084     Cumulant2nd1020ALICE_v4->SetMarkerStyle(kFullSquare);
3085     Cumulant2nd1020ALICE_v4->SetMarkerColor(kRed); 
3086         
3087     return Cumulant2nd1020ALICE_v4;
3088   }
3089   
3090   return 0;
3091 }
3092
3093 TGraphErrors* GetFlow2030(Int_t n)
3094 {
3095   // private communication 02.02.11, Ante B. / Raimond
3096
3097   if (n == 2)
3098   {
3099     Double_t xCumulant2nd2030ALICE_v2[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3100     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
3101     Double_t yCumulant2nd2030ALICE_v2[] = {0.000000,0.000000,0.035557,0.048064,0.060768,0.072585,0.083808,0.093772,0.103310,0.112602,
3102     0.124846,0.140603,0.155345,0.169450,0.183077,0.200173,0.219693,0.225741,0.223318,0.207356};
3103     Double_t xErrCumulant2nd2030ALICE_v2[20] = {0.};
3104     Double_t yErrCumulant2nd2030ALICE_v2[] = {0.000000,0.000000,0.000144,0.000147,0.000159,0.000175,0.000194,0.000214,0.000235,0.000259,
3105     0.000211,0.000254,0.000310,0.000377,0.000464,0.000418,0.000677,0.001027,0.001513,0.001761};
3106     Int_t nPointsCumulant2nd2030ALICE_v2 = sizeof(xCumulant2nd2030ALICE_v2)/sizeof(Double_t);                                      
3107     TGraphErrors *Cumulant2nd2030ALICE_v2 = new TGraphErrors(nPointsCumulant2nd2030ALICE_v2,xCumulant2nd2030ALICE_v2,yCumulant2nd2030ALICE_v2,
3108                                                           xErrCumulant2nd2030ALICE_v2,yErrCumulant2nd2030ALICE_v2);
3109     Cumulant2nd2030ALICE_v2->SetMarkerStyle(kOpenSquare);
3110     Cumulant2nd2030ALICE_v2->SetMarkerColor(kRed); 
3111         
3112     return Cumulant2nd2030ALICE_v2;
3113   }
3114   
3115   if (n == 3)
3116   {
3117     // v3{2}(pt) for 20-30%:
3118     Double_t xCumulant2nd2030ALICE_v3[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3119     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
3120     Double_t yCumulant2nd2030ALICE_v3[] = {0.000000,0.000000,0.011287,0.014937,0.018479,0.022962,0.027854,0.031938,0.037038,0.041443,
3121     0.049872,0.058720,0.068353,0.077692,0.087859,0.099863,0.116141,0.124486,0.124786,0.119520};
3122     Double_t xErrCumulant2nd2030ALICE_v3[20] = {0.};
3123     Double_t yErrCumulant2nd2030ALICE_v3[] = {0.000000,0.000000,0.000215,0.000216,0.000228,0.000248,0.000272,0.000300,0.000332,0.000366,
3124     0.000301,0.000369,0.000456,0.000561,0.000700,0.000636,0.001038,0.001574,0.002307,0.002676};
3125     Int_t nPointsCumulant2nd2030ALICE_v3 = sizeof(xCumulant2nd2030ALICE_v3)/sizeof(Double_t);                                      
3126     TGraphErrors *Cumulant2nd2030ALICE_v3 = new TGraphErrors(nPointsCumulant2nd2030ALICE_v3,xCumulant2nd2030ALICE_v3,yCumulant2nd2030ALICE_v3,
3127                                                           xErrCumulant2nd2030ALICE_v3,yErrCumulant2nd2030ALICE_v3);
3128     Cumulant2nd2030ALICE_v3->SetMarkerStyle(kOpenSquare);
3129     Cumulant2nd2030ALICE_v3->SetMarkerColor(kRed); 
3130     
3131     return Cumulant2nd2030ALICE_v3;
3132   }
3133   
3134   if (n == 4)
3135   {
3136     // v4{2}(pt) for 20-30%:
3137     Double_t xCumulant2nd2030ALICE_v4[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3138     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
3139     Double_t yCumulant2nd2030ALICE_v4[] = {0.000000,0.000000,0.008435,0.009824,0.009387,0.010408,0.011458,0.013770,0.016335,0.019165,
3140     0.023770,0.030071,0.036231,0.043950,0.051803,0.065222,0.082155,0.091864,0.105061,0.105167};
3141     Double_t xErrCumulant2nd2030ALICE_v4[20] = {0.};
3142     Double_t yErrCumulant2nd2030ALICE_v4[] = {0.000000,0.000000,0.000308,0.000308,0.000328,0.000355,0.000391,0.000430,0.000473,0.000524,
3143     0.000430,0.000524,0.000652,0.000807,0.001006,0.000919,0.001502,0.002277,0.003339,0.003871};
3144     Int_t nPointsCumulant2nd2030ALICE_v4 = sizeof(xCumulant2nd2030ALICE_v4)/sizeof(Double_t);                                      
3145     TGraphErrors *Cumulant2nd2030ALICE_v4 = new TGraphErrors(nPointsCumulant2nd2030ALICE_v4,xCumulant2nd2030ALICE_v4,yCumulant2nd2030ALICE_v4,
3146                                                           xErrCumulant2nd2030ALICE_v4,yErrCumulant2nd2030ALICE_v4);
3147     Cumulant2nd2030ALICE_v4->SetMarkerStyle(kOpenSquare);
3148     Cumulant2nd2030ALICE_v4->SetMarkerColor(kRed); 
3149         
3150     return Cumulant2nd2030ALICE_v4;
3151   }
3152   
3153   return 0;
3154 }
3155
3156 TGraphErrors* GetFlow3040(Int_t n)
3157 {
3158   // private communication 02.02.11, Ante B. / Raimond
3159
3160   if (n == 2)
3161   {
3162     // v2{2}(pt) for 30-40%:
3163     Double_t xCumulant2nd3040ALICE_v2[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3164     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
3165     Double_t yCumulant2nd3040ALICE_v2[] = {0.000000,0.000000,0.040797,0.055427,0.070543,0.084024,0.096562,0.109411,0.119853,0.130964,
3166     0.145377,0.163806,0.179825,0.196178,0.210377,0.226556,0.245686,0.247898,0.240058,0.225011};
3167     Double_t xErrCumulant2nd3040ALICE_v2[20] = {0.};
3168     Double_t yErrCumulant2nd3040ALICE_v2[] = {0.000000,0.000000,0.000177,0.000182,0.000197,0.000216,0.000239,0.000265,0.000293,0.000325,
3169     0.000266,0.000321,0.000395,0.000486,0.000603,0.000536,0.000840,0.001258,0.001843,0.002118};
3170     Int_t nPointsCumulant2nd3040ALICE_v2 = sizeof(xCumulant2nd3040ALICE_v2)/sizeof(Double_t);                                      
3171     TGraphErrors *Cumulant2nd3040ALICE_v2 = new TGraphErrors(nPointsCumulant2nd3040ALICE_v2,xCumulant2nd3040ALICE_v2,yCumulant2nd3040ALICE_v2,
3172                                                           xErrCumulant2nd3040ALICE_v2,yErrCumulant2nd3040ALICE_v2);
3173     Cumulant2nd3040ALICE_v2->SetMarkerStyle(kFullTriangleUp);
3174     Cumulant2nd3040ALICE_v2->SetMarkerSize(1.2);
3175     Cumulant2nd3040ALICE_v2->SetMarkerColor(kGreen+2);     
3176     
3177     return Cumulant2nd3040ALICE_v2;
3178   }
3179   
3180   if (n == 3)
3181   {
3182     // v3{2}(pt) for 30-40%:
3183     Double_t xCumulant2nd3040ALICE_v3[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3184     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
3185     Double_t yCumulant2nd3040ALICE_v3[] = {0.000000,0.000000,0.012226,0.016391,0.020792,0.026208,0.030380,0.035710,0.041025,0.047062,
3186     0.053075,0.064201,0.074116,0.085314,0.094391,0.106819,0.124012,0.129388,0.134315,0.132330};
3187     Double_t xErrCumulant2nd3040ALICE_v3[20] = {0.};
3188     Double_t yErrCumulant2nd3040ALICE_v3[] = {0.000000,0.000000,0.000284,0.000286,0.000303,0.000329,0.000364,0.000403,0.000443,0.000492,
3189     0.000408,0.000500,0.000627,0.000778,0.000973,0.000874,0.001375,0.002050,0.002992,0.003438};
3190     Int_t nPointsCumulant2nd3040ALICE_v3 = sizeof(xCumulant2nd3040ALICE_v3)/sizeof(Double_t);                                      
3191     TGraphErrors *Cumulant2nd3040ALICE_v3 = new TGraphErrors(nPointsCumulant2nd3040ALICE_v3,xCumulant2nd3040ALICE_v3,yCumulant2nd3040ALICE_v3,
3192                                                           xErrCumulant2nd3040ALICE_v3,yErrCumulant2nd3040ALICE_v3);
3193     Cumulant2nd3040ALICE_v3->SetMarkerStyle(kFullTriangleUp);
3194     Cumulant2nd3040ALICE_v3->SetMarkerSize(1.2);
3195     Cumulant2nd3040ALICE_v3->SetMarkerColor(kGreen+2); 
3196     
3197     return Cumulant2nd3040ALICE_v3;
3198   }
3199   
3200   if (n == 4)
3201   {
3202     // v4{2}(pt) for 30-40%:
3203     Double_t xCumulant2nd3040ALICE_v4[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3204     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
3205     Double_t yCumulant2nd3040ALICE_v4[] = {0.000000,0.000000,0.010718,0.011490,0.010994,0.012527,0.013748,0.016425,0.018857,0.021622,
3206     0.026853,0.034636,0.042651,0.049892,0.057795,0.070865,0.088486,0.101656,0.113886,0.118202};
3207     Double_t xErrCumulant2nd3040ALICE_v4[20] = {0.};
3208     Double_t yErrCumulant2nd3040ALICE_v4[] = {0.000000,0.000000,0.000401,0.000406,0.000433,0.000472,0.000521,0.000575,0.000634,0.000704,
3209     0.000580,0.000714,0.000890,0.001114,0.001398,0.001253,0.001974,0.002945,0.004290,0.004909};
3210     Int_t nPointsCumulant2nd3040ALICE_v4 = sizeof(xCumulant2nd3040ALICE_v4)/sizeof(Double_t);                                      
3211     TGraphErrors *Cumulant2nd3040ALICE_v4 = new TGraphErrors(nPointsCumulant2nd3040ALICE_v4,xCumulant2nd3040ALICE_v4,yCumulant2nd3040ALICE_v4,
3212                                                           xErrCumulant2nd3040ALICE_v4,yErrCumulant2nd3040ALICE_v4);
3213     Cumulant2nd3040ALICE_v4->SetMarkerStyle(kFullTriangleUp);
3214     Cumulant2nd3040ALICE_v4->SetMarkerSize(1.2);
3215     Cumulant2nd3040ALICE_v4->SetMarkerColor(kGreen+2); 
3216         
3217     return Cumulant2nd3040ALICE_v4;
3218   }
3219   
3220   return 0;
3221 }
3222
3223 TGraphErrors* GetFlow4050(Int_t n)
3224 {
3225   // private communication 02.02.11, Ante B. / Raimond
3226
3227   if (n == 2)
3228   {
3229     // v2{2}(pt) for 40-50%:
3230     Double_t xCumulant2nd4050ALICE_v2[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3231     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
3232     Double_t yCumulant2nd4050ALICE_v2[] = {0.000000,0.000000,0.043593,0.059522,0.075558,0.090681,0.104453,0.117913,0.129349,0.141743,
3233     0.157076,0.176121,0.193651,0.208844,0.222402,0.238407,0.252512,0.253592,0.243571,0.233018};
3234     Double_t xErrCumulant2nd4050ALICE_v2[20] = {0.};
3235     Double_t yErrCumulant2nd4050ALICE_v2[] = {0.000000,0.000000,0.000234,0.000241,0.000261,0.000288,0.000322,0.000357,0.000395,0.000438,
3236     0.000362,0.000447,0.000555,0.000685,0.000846,0.000733,0.001121,0.001665,0.002433,0.002768};
3237     Int_t nPointsCumulant2nd4050ALICE_v2 = sizeof(xCumulant2nd4050ALICE_v2)/sizeof(Double_t);                                      
3238     TGraphErrors *Cumulant2nd4050ALICE_v2 = new TGraphErrors(nPointsCumulant2nd4050ALICE_v2,xCumulant2nd4050ALICE_v2,yCumulant2nd4050ALICE_v2,
3239                                                           xErrCumulant2nd4050ALICE_v2,yErrCumulant2nd4050ALICE_v2);
3240     Cumulant2nd4050ALICE_v2->SetMarkerStyle(kOpenTriangleUp);
3241     Cumulant2nd4050ALICE_v2->SetMarkerSize(1.2);
3242     Cumulant2nd4050ALICE_v2->SetMarkerColor(kGreen+2);      
3243     
3244     return Cumulant2nd4050ALICE_v2;
3245   }
3246   
3247   return 0;
3248 }
3249 */
3250
3251 // results up to high pT
3252
3253 TGraphErrors* GetFlow05(Int_t n)
3254 {
3255   // private communication 09.03.11, Ante B. / Raimond
3256
3257   if (n == 2)
3258   {
3259     // v2{2}(pt) for 0-5%:
3260     Double_t xCumulant2nd0005ALICE[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3261     1.050000,1.150000,1.250000,1.350000,1.450000,1.550000,1.650000,1.750000,1.850000,1.950000,
3262     2.100000,2.300000,2.500000,2.700000,2.900000,3.200000,3.600000,4.000000,4.400000,4.800000,
3263     5.500000,6.500000,7.500000,8.500000,9.500000,11.250000,13.750000,16.250000,18.750000,60.000000};
3264     Double_t yCumulant2nd0005ALICE[] = {0.000000,0.000000,0.018169,0.020988,0.024899,0.028309,0.031974,0.035188,0.038218,0.041202,
3265     0.043910,0.046560,0.048183,0.050640,0.052874,0.055334,0.056948,0.059427,0.061540,0.063218,
3266     0.065452,0.069222,0.072578,0.074723,0.077749,0.077178,0.080514,0.075325,0.077692,0.079710,
3267     0.073280,0.063849,0.068274,0.066045,0.071496,0.104352,0.091646,0.050220,0.124185,0.088535};
3268     Double_t xErrCumulant2nd0005ALICE[40] = {0.};
3269     Double_t yErrCumulant2nd0005ALICE[] = {0.000000,0.000000,0.000190,0.000191,0.000199,0.000212,0.000230,0.000248,0.000268,0.000293,
3270     0.000319,0.000346,0.000379,0.000418,0.000459,0.000502,0.000554,0.000614,0.000674,0.000749,
3271     0.000620,0.000769,0.000958,0.001182,0.001446,0.001331,0.001858,0.002552,0.003453,0.004606,
3272     0.004289,0.007006,0.010046,0.013853,0.017709,0.016630,0.025728,0.036763,0.045056,0.029011};
3273     Int_t nPointsCumulant2nd0005ALICE = sizeof(xCumulant2nd0005ALICE)/sizeof(Double_t);                                      
3274     TGraphErrors *Cumulant2nd0005ALICE = new TGraphErrors(nPointsCumulant2nd0005ALICE,xCumulant2nd0005ALICE,yCumulant2nd0005ALICE,
3275                                                           xErrCumulant2nd0005ALICE,yErrCumulant2nd0005ALICE);
3276     Cumulant2nd0005ALICE->SetMarkerStyle(kFullCircle);
3277     Cumulant2nd0005ALICE->SetMarkerColor(kBlue);
3278     
3279     return Cumulant2nd0005ALICE;
3280   }
3281   
3282   if (n == 3)
3283   {
3284   }
3285   
3286   if (n == 4)
3287   {
3288   }
3289   
3290   return 0;
3291 }
3292
3293 TGraphErrors* GetFlow05_Rap10(Int_t n)
3294 {
3295   // private communication 17.05.11, Ante B. / should correspond to machcone paper draft 
3296
3297   if (n == 2)
3298   {
3299     //  v2{SP}(pt) for 00-05%:
3300     const Int_t nPointsSP_0005ALICE_v2_etaGap10 = 17;
3301     Double_t xSP_0005ALICE_v2_etaGap10[nPointsSP_0005ALICE_v2_etaGap10] = {0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.900000,1.100000,
3302         1.300000,1.500000,1.700000,1.900000,2.200000,2.600000,3.000000,3.650000,4.550000};
3303     Double_t ySP_0005ALICE_v2_etaGap10[nPointsSP_0005ALICE_v2_etaGap10] = {0.013672,0.015745,0.019944,0.024169,0.026921,0.030296,0.034916,0.038472,
3304         0.043103,0.046626,0.052386,0.057132,0.060070,0.068419,0.061459,0.056816,0.050311};
3305     Double_t xErrSP_0005ALICE_v2_etaGap10[nPointsSP_0005ALICE_v2_etaGap10] = {0.};
3306     Double_t yErrSP_0005ALICE_v2_etaGap10[nPointsSP_0005ALICE_v2_etaGap10] = {0.000813,0.000804,0.000852,0.000930,0.001029,0.001140,0.000939,0.001155,
3307         0.001410,0.001736,0.002131,0.002620,0.002502,0.003759,0.005615,0.006617,0.014242};
3308     TGraphErrors *GrSP_0005ALICE_v2_etaGap10 = new TGraphErrors(nPointsSP_0005ALICE_v2_etaGap10,xSP_0005ALICE_v2_etaGap10,ySP_0005ALICE_v2_etaGap10,
3309                                                               xErrSP_0005ALICE_v2_etaGap10,yErrSP_0005ALICE_v2_etaGap10);
3310                                                               
3311     return GrSP_0005ALICE_v2_etaGap10;
3312   }
3313   
3314   if (n == 3)
3315   {
3316     //  v3{SP}(pt) for 00-05%:
3317     const Int_t nPointsSP_0005ALICE_v3_etaGap10 = 16;
3318     Double_t xSP_0005ALICE_v3_etaGap10[nPointsSP_0005ALICE_v3_etaGap10] = {0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.900000,1.100000,
3319         1.300000,1.500000,1.700000,1.900000,2.300000,2.900000,3.650000,4.550000};
3320     Double_t ySP_0005ALICE_v3_etaGap10[nPointsSP_0005ALICE_v3_etaGap10] = {0.006303,0.009800,0.011143,0.014246,0.017628,0.019437,0.028412,0.030580,
3321         0.038730,0.045653,0.052469,0.062303,0.071522,0.082223,0.083373,0.076951};
3322     Double_t xErrSP_0005ALICE_v3_etaGap10[nPointsSP_0005ALICE_v3_etaGap10] = {0.};
3323     Double_t yErrSP_0005ALICE_v3_etaGap10[nPointsSP_0005ALICE_v3_etaGap10] = {0.001012,0.000996,0.001062,0.001158,0.001277,0.001415,0.001158,0.001422,
3324         0.001734,0.002124,0.002610,0.003206,0.002724,0.004977,0.008123,0.017180};
3325     TGraphErrors *GrSP_0005ALICE_v3_etaGap10 = new TGraphErrors(nPointsSP_0005ALICE_v3_etaGap10,xSP_0005ALICE_v3_etaGap10,ySP_0005ALICE_v3_etaGap10,
3326                                                               xErrSP_0005ALICE_v3_etaGap10,yErrSP_0005ALICE_v3_etaGap10);
3327
3328                                                               
3329     return GrSP_0005ALICE_v3_etaGap10;
3330   }
3331   
3332   if (n == 4)
3333   {
3334     //  v4{SP}(pt) for 00-05%:
3335     const Int_t nPointsSP_0005ALICE_v4_etaGap10 = 11;
3336     Double_t xSP_0005ALICE_v4_etaGap10[nPointsSP_0005ALICE_v4_etaGap10] = {0.300000,0.500000,0.700000,0.950000,1.250000,1.550000,1.850000,2.300000,2.900000,3.650000,4.550000};
3337     Double_t ySP_0005ALICE_v4_etaGap10[nPointsSP_0005ALICE_v4_etaGap10] = {0.002042,0.002556,0.009693,0.013286,0.016780,0.027865,0.031797,0.051101,0.060164,
3338         0.095985,0.094607};
3339     Double_t xErrSP_0005ALICE_v4_etaGap10[nPointsSP_0005ALICE_v4_etaGap10] = {0.};
3340     Double_t yErrSP_0005ALICE_v4_etaGap10[nPointsSP_0005ALICE_v4_etaGap10] = {0.001460,0.001624,0.001930,0.002021,0.002737,0.003717,0.005042,0.005564,0.010160,
3341         0.016472,0.035083};
3342     TGraphErrors *GrSP_0005ALICE_v4_etaGap10 = new TGraphErrors(nPointsSP_0005ALICE_v4_etaGap10,xSP_0005ALICE_v4_etaGap10,ySP_0005ALICE_v4_etaGap10,
3343                                                               xErrSP_0005ALICE_v4_etaGap10,yErrSP_0005ALICE_v4_etaGap10);
3344    
3345     return GrSP_0005ALICE_v4_etaGap10;
3346   }
3347   
3348   if (n == 5)
3349   {
3350     //  v5{SP}(pt) for 00-05%:
3351     const Int_t nPointsSP_0005ALICE_v5_etaGap10 = 12;
3352     Double_t xSP_0005ALICE_v5_etaGap10[nPointsSP_0005ALICE_v5_etaGap10] = {0.300000,0.500000,0.700000,0.900000,1.100000,1.300000,1.600000,2.000000,2.400000,
3353         2.800000,3.500000,4.500000};
3354     Double_t ySP_0005ALICE_v5_etaGap10[nPointsSP_0005ALICE_v5_etaGap10] = {0.002016,0.003409,0.004029,0.002665,0.002765,0.003042,0.013241,0.015430,0.031845,
3355         0.031373,0.068504,0.017964};
3356     Double_t xErrSP_0005ALICE_v5_etaGap10[nPointsSP_0005ALICE_v5_etaGap10] = {0.};
3357     Double_t yErrSP_0005ALICE_v5_etaGap10[nPointsSP_0005ALICE_v5_etaGap10] = {0.001260,0.001386,0.001696,0.002101,0.002560,0.003119,0.002970,0.004472,0.006802,
3358         0.010073,0.011899,0.027756};
3359     TGraphErrors *GrSP_0005ALICE_v5_etaGap10 = new TGraphErrors(nPointsSP_0005ALICE_v5_etaGap10,xSP_0005ALICE_v5_etaGap10,ySP_0005ALICE_v5_etaGap10,
3360                                                               xErrSP_0005ALICE_v5_etaGap10,yErrSP_0005ALICE_v5_etaGap10);
3361     
3362     return GrSP_0005ALICE_v5_etaGap10;
3363   }
3364   
3365   return 0;
3366 }
3367
3368 TGraphErrors* GetFlow510(Int_t n)
3369 {
3370   // private communication 09.03.11, Ante B. / Raimond
3371
3372   if (n == 2)
3373   {
3374     // v2{2}(pt) for 5-10%:
3375     Double_t xCumulant2nd0510ALICE[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3376     1.050000,1.150000,1.250000,1.350000,1.450000,1.550000,1.650000,1.750000,1.850000,1.950000,
3377     2.100000,2.300000,2.500000,2.700000,2.900000,3.200000,3.600000,4.000000,4.400000,4.800000,
3378     5.500000,6.500000,7.500000,8.500000,9.500000,11.250000,13.750000,16.250000,18.750000,60.000000};
3379     Double_t yCumulant2nd0510ALICE[] = {0.000000,0.000000,0.022354,0.028064,0.034341,0.040769,0.046265,0.051160,0.056712,0.061354,
3380     0.066290,0.070340,0.074453,0.078444,0.082367,0.085785,0.088086,0.092676,0.096169,0.100366,
3381     0.104227,0.109710,0.117032,0.121784,0.122227,0.126537,0.127966,0.117790,0.117884,0.111436,
3382     0.104945,0.097640,0.086481,0.091663,0.091404,0.080132,0.015864,0.101500,0.033347,0.205130};
3383     Double_t xErrCumulant2nd0510ALICE[40] = {0.};
3384     Double_t yErrCumulant2nd0510ALICE[] = {0.000000,0.000000,0.000173,0.000176,0.000186,0.000199,0.000219,0.000236,0.000260,0.000283,
3385     0.000312,0.000340,0.000373,0.000410,0.000454,0.000501,0.000552,0.000610,0.000675,0.000753,
3386     0.000620,0.000774,0.000961,0.001183,0.001431,0.001309,0.001814,0.002481,0.003342,0.004379,
3387     0.004122,0.006716,0.009851,0.013626,0.017517,0.015790,0.025680,0.038041,0.054144,0.038987};
3388     Int_t nPointsCumulant2nd0510ALICE = sizeof(xCumulant2nd0510ALICE)/sizeof(Double_t);                                      
3389     TGraphErrors *Cumulant2nd0510ALICE = new TGraphErrors(nPointsCumulant2nd0510ALICE,xCumulant2nd0510ALICE,yCumulant2nd0510ALICE,
3390                                                           xErrCumulant2nd0510ALICE,yErrCumulant2nd0510ALICE);
3391     Cumulant2nd0510ALICE->SetMarkerStyle(kOpenCircle);
3392     Cumulant2nd0510ALICE->SetMarkerColor(kBlue);
3393     
3394     return Cumulant2nd0510ALICE;
3395   }
3396   
3397   if (n == 3)
3398   {
3399   }
3400   
3401   if (n == 4)
3402   {
3403   }
3404   
3405   return 0;
3406 }
3407
3408 TGraphErrors* GetFlow510_Rap10(Int_t n)
3409 {
3410   // private communication 18.05.11, Ante B.
3411
3412   if (n == 2)
3413   {
3414     //  v2{SP}(pt) for 05-10%, rapidity gap = 1.0:
3415     const Int_t nPointsSP_0510ALICE_v2_etaGap10 = 19;
3416     Double_t xSP_0510ALICE_v2_etaGap10[nPointsSP_0510ALICE_v2_etaGap10] = {0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3417 1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.250000,
3418 4.750000};
3419     Double_t ySP_0510ALICE_v2_etaGap10[nPointsSP_0510ALICE_v2_etaGap10] = {0.018634,0.025538,0.032157,0.038272,0.044020,0.049252,0.055627,0.059272,
3420 0.066516,0.073891,0.080945,0.090386,0.094505,0.106393,0.120303,0.122586,0.121731,0.107343,
3421 0.104059};
3422     Double_t xErrSP_0510ALICE_v2_etaGap10[nPointsSP_0510ALICE_v2_etaGap10] = {0.};
3423     Double_t yErrSP_0510ALICE_v2_etaGap10[nPointsSP_0510ALICE_v2_etaGap10] = {0.000419,0.000411,0.000435,0.000474,0.000523,0.000580,0.000643,0.000712,
3424 0.000586,0.000717,0.000880,0.001082,0.001333,0.001189,0.001969,0.003199,0.005011,0.007602,
3425 0.010906};
3426     TGraphErrors *GrSP_0510ALICE_v2_etaGap10 = new TGraphErrors(nPointsSP_0510ALICE_v2_etaGap10,xSP_0510ALICE_v2_etaGap10,
3427                                                               ySP_0510ALICE_v2_etaGap10,xErrSP_0510ALICE_v2_etaGap10,
3428                                                               yErrSP_0510ALICE_v2_etaGap10);
3429
3430     return GrSP_0510ALICE_v2_etaGap10;
3431   }
3432   
3433   return 0;
3434 }
3435
3436 TGraphErrors* GetFlow1020(Int_t n)
3437 {
3438   // private communication 09.03.11, Ante B. / Raimond
3439
3440   if (n == 2)
3441   {
3442     // v2{2}(pt) for 10-20%:
3443     Double_t xCumulant2nd1020ALICE[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3444     1.050000,1.150000,1.250000,1.350000,1.450000,1.550000,1.650000,1.750000,1.850000,1.950000,
3445     2.100000,2.300000,2.500000,2.700000,2.900000,3.200000,3.600000,4.000000,4.400000,4.800000,
3446     5.500000,6.500000,7.500000,8.500000,9.500000,11.250000,13.750000,16.250000,18.750000,60.000000};
3447     Double_t yCumulant2nd1020ALICE[] = {0.000000,0.000000,0.028508,0.037698,0.046914,0.055750,0.063948,0.072298,0.079396,0.086829,
3448     0.093382,0.099676,0.105412,0.110792,0.116715,0.122327,0.127079,0.132302,0.137183,0.142346,
3449     0.149059,0.156729,0.164672,0.171840,0.175346,0.176824,0.178878,0.174979,0.169229,0.153109,
3450     0.139676,0.125686,0.120554,0.096537,0.084736,0.118152,0.116079,0.060032,0.093764,0.206506};
3451     Double_t xErrCumulant2nd1020ALICE[40] = {0.};
3452     Double_t yErrCumulant2nd1020ALICE[] = {0.000000,0.000000,0.000134,0.000136,0.000145,0.000158,0.000173,0.000190,0.000209,0.000229,
3453     0.000252,0.000275,0.000301,0.000331,0.000365,0.000401,0.000442,0.000488,0.000541,0.000599,
3454     0.000496,0.000614,0.000757,0.000915,0.001095,0.000989,0.001360,0.001847,0.002477,0.003234,
3455     0.003012,0.004867,0.007123,0.009774,0.012740,0.011682,0.019629,0.028568,0.039931,0.024776};
3456     Int_t nPointsCumulant2nd1020ALICE = sizeof(xCumulant2nd1020ALICE)/sizeof(Double_t);                                      
3457     TGraphErrors *Cumulant2nd1020ALICE = new TGraphErrors(nPointsCumulant2nd1020ALICE,xCumulant2nd1020ALICE,yCumulant2nd1020ALICE,
3458                                                           xErrCumulant2nd1020ALICE,yErrCumulant2nd1020ALICE);
3459     Cumulant2nd1020ALICE->SetMarkerStyle(kFullSquare);
3460     Cumulant2nd1020ALICE->SetMarkerColor(kRed); 
3461     
3462     return Cumulant2nd1020ALICE;
3463   }
3464   
3465   if (n == 3)
3466   {
3467   }
3468   
3469   if (n == 4)
3470   {
3471   }
3472   
3473   return 0;
3474 }
3475
3476 TGraphErrors* GetFlow1020_Rap10(Int_t n)
3477 {
3478   // private communication 18.05.11, Ante B.
3479
3480   if (n == 2)
3481   {
3482    //  v2{SP}(pt) for 10-20%, rapidity gap = 1.0:
3483     const Int_t nPointsSP_1020ALICE_v2_etaGap10 = 19;
3484     Double_t xSP_1020ALICE_v2_etaGap10[nPointsSP_1020ALICE_v2_etaGap10] = {0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3485 1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.250000,
3486 4.750000};
3487     Double_t ySP_1020ALICE_v2_etaGap10[nPointsSP_1020ALICE_v2_etaGap10] = {0.026592,0.036955,0.046103,0.055537,0.063461,0.070993,0.078751,0.085723,
3488 0.094701,0.105631,0.117906,0.128147,0.138505,0.153494,0.166651,0.172691,0.177337,0.155068,
3489 0.131586};
3490     Double_t xErrSP_1020ALICE_v2_etaGap10[nPointsSP_1020ALICE_v2_etaGap10] = {0.};
3491     Double_t yErrSP_1020ALICE_v2_etaGap10[nPointsSP_1020ALICE_v2_etaGap10] = {0.000302,0.000296,0.000314,0.000342,0.000377,0.000418,0.000465,0.000515,
3492 0.000423,0.000517,0.000634,0.000779,0.000959,0.000856,0.001406,0.002266,0.003528,0.005281,
3493 0.007561};
3494     TGraphErrors *GrSP_1020ALICE_v2_etaGap10 = new TGraphErrors(nPointsSP_1020ALICE_v2_etaGap10,xSP_1020ALICE_v2_etaGap10,
3495                                                               ySP_1020ALICE_v2_etaGap10,xErrSP_1020ALICE_v2_etaGap10,
3496                                                               yErrSP_1020ALICE_v2_etaGap10);
3497
3498     return GrSP_1020ALICE_v2_etaGap10;
3499   }
3500   
3501   return 0;
3502 }
3503     
3504 TGraphErrors* GetFlow2030(Int_t n)
3505 {
3506   // private communication 09.03.11, Ante B. / Raimond
3507
3508   if (n == 2)
3509   {
3510     // v2{2}(pt) for 20-30%:
3511     Double_t xCumulant2nd2030ALICE[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3512     1.050000,1.150000,1.250000,1.350000,1.450000,1.550000,1.650000,1.750000,1.850000,1.950000,
3513     2.100000,2.300000,2.500000,2.700000,2.900000,3.200000,3.600000,4.000000,4.400000,4.800000,
3514     5.500000,6.500000,7.500000,8.500000,9.500000,11.250000,13.750000,16.250000,18.750000,60.000000};
3515     Double_t yCumulant2nd2030ALICE[] = {0.000000,0.000000,0.035366,0.047465,0.060083,0.072090,0.083418,0.093576,0.103842,0.113110,
3516     0.122193,0.130168,0.138158,0.145627,0.152851,0.159129,0.166073,0.173144,0.178698,0.186188,
3517     0.192045,0.202199,0.210535,0.215004,0.220457,0.223339,0.224050,0.211567,0.203955,0.189716,
3518     0.165994,0.147185,0.131953,0.139331,0.151293,0.127406,0.153764,0.089628,0.161247,0.511418};
3519     Double_t xErrCumulant2nd2030ALICE[40] = {0.};
3520     Double_t yErrCumulant2nd2030ALICE[] = {0.000000,0.000000,0.000155,0.000157,0.000169,0.000184,0.000202,0.000222,0.000244,0.000269,
3521     0.000296,0.000325,0.000357,0.000394,0.000435,0.000481,0.000532,0.000589,0.000655,0.000731,
3522     0.000605,0.000743,0.000904,0.001081,0.001277,0.001145,0.001568,0.002119,0.002806,0.003635,
3523     0.003383,0.005346,0.007935,0.010739,0.014682,0.013434,0.021531,0.032352,0.040396,0.028472};
3524     Int_t nPointsCumulant2nd2030ALICE = sizeof(xCumulant2nd2030ALICE)/sizeof(Double_t);                                      
3525     TGraphErrors *Cumulant2nd2030ALICE = new TGraphErrors(nPointsCumulant2nd2030ALICE,xCumulant2nd2030ALICE,yCumulant2nd2030ALICE,
3526                                                           xErrCumulant2nd2030ALICE,yErrCumulant2nd2030ALICE);
3527     Cumulant2nd2030ALICE->SetMarkerStyle(kOpenSquare);
3528     Cumulant2nd2030ALICE->SetMarkerColor(kRed); 
3529     
3530     return Cumulant2nd2030ALICE;
3531   }
3532   
3533   if (n == 3)
3534   {
3535   }
3536   
3537   if (n == 4)
3538   {
3539   }
3540   
3541   return 0;
3542 }
3543
3544 TGraphErrors* GetFlow3040(Int_t n)
3545 {
3546   // private communication 09.03.11, Ante B. / Raimond
3547
3548   if (n == 2)
3549   {
3550     // v2{2}(pt) for 30-40%:
3551     Double_t xCumulant2nd3040ALICE[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3552     1.050000,1.150000,1.250000,1.350000,1.450000,1.550000,1.650000,1.750000,1.850000,1.950000,
3553     2.100000,2.300000,2.500000,2.700000,2.900000,3.200000,3.600000,4.000000,4.400000,4.800000,
3554     5.500000,6.500000,7.500000,8.500000,9.500000,11.250000,13.750000,16.250000,18.750000,60.000000};
3555     Double_t yCumulant2nd3040ALICE[] = {0.000000,0.000000,0.039584,0.054196,0.069291,0.082976,0.095622,0.108940,0.119830,0.131587,
3556     0.141091,0.150899,0.160573,0.168676,0.176301,0.183823,0.191672,0.199506,0.206854,0.212830,
3557     0.219526,0.229376,0.236513,0.240863,0.245961,0.245891,0.242608,0.234302,0.219580,0.212848,
3558     0.194666,0.190184,0.171036,0.159173,0.156932,0.141324,0.132809,0.182683,0.023272,0.032825};
3559     Double_t xErrCumulant2nd3040ALICE[40] = {0.};
3560     Double_t yErrCumulant2nd3040ALICE[] = {0.000000,0.000000,0.000189,0.000192,0.000205,0.000224,0.000247,0.000273,0.000302,0.000334,
3561     0.000369,0.000407,0.000448,0.000496,0.000552,0.000612,0.000682,0.000758,0.000844,0.000941,
3562     0.000774,0.000937,0.001123,0.001329,0.001565,0.001397,0.001911,0.002549,0.003378,0.004306,
3563     0.003987,0.006353,0.009128,0.013032,0.016891,0.015806,0.025150,0.035119,0.044487,0.050083};
3564     Int_t nPointsCumulant2nd3040ALICE = sizeof(xCumulant2nd3040ALICE)/sizeof(Double_t);                                      
3565     TGraphErrors *Cumulant2nd3040ALICE = new TGraphErrors(nPointsCumulant2nd3040ALICE,xCumulant2nd3040ALICE,yCumulant2nd3040ALICE,
3566                                                           xErrCumulant2nd3040ALICE,yErrCumulant2nd3040ALICE);
3567     Cumulant2nd3040ALICE->SetMarkerStyle(kFullTriangleUp);
3568     Cumulant2nd3040ALICE->SetMarkerColor(kGreen+2);
3569     
3570     return Cumulant2nd3040ALICE;
3571   }
3572   
3573   if (n == 3)
3574   {
3575   }
3576   
3577   if (n == 4)
3578   {
3579   }
3580   
3581   return 0;
3582 }
3583
3584 TGraphErrors* GetFlow4050(Int_t n)
3585 {
3586   // private communication 09.03.11, Ante B. / Raimond
3587
3588   if (n == 2)
3589   {
3590     // v2{2}(pt) for 40-50%:
3591     Double_t xCumulant2nd4050ALICE[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3592     1.050000,1.150000,1.250000,1.350000,1.450000,1.550000,1.650000,1.750000,1.850000,1.950000,
3593     2.100000,2.300000,2.500000,2.700000,2.900000,3.200000,3.600000,4.000000,4.400000,4.800000,
3594     5.500000,6.500000,7.500000,8.500000,9.500000,11.250000,13.750000,16.250000,18.750000,60.000000};
3595     Double_t yCumulant2nd4050ALICE[] = {0.000000,0.000000,0.041872,0.058090,0.074444,0.089181,0.103780,0.117279,0.129769,0.142051,
3596     0.153185,0.163147,0.173309,0.181668,0.190998,0.197703,0.205011,0.211063,0.219587,0.223287,
3597     0.231163,0.239606,0.246533,0.251457,0.250034,0.252989,0.240823,0.236489,0.230268,0.204321,
3598     0.213476,0.200247,0.167065,0.190655,0.173573,0.166173,0.153232,0.173112,-0.123540,0.211999};
3599     Double_t xErrCumulant2nd4050ALICE[40] = {0.};
3600     Double_t yErrCumulant2nd4050ALICE[] = {0.000000,0.000000,0.000248,0.000251,0.000270,0.000296,0.000328,0.000363,0.000403,0.000447,
3601     0.000500,0.000556,0.000617,0.000687,0.000770,0.000857,0.000952,0.001057,0.001176,0.001297,
3602     0.001054,0.001265,0.001498,0.001767,0.002076,0.001849,0.002527,0.003358,0.004372,0.005573,
3603     0.005091,0.007981,0.011746,0.015732,0.021883,0.019866,0.032443,0.046521,0.051631,0.083717};
3604     Int_t nPointsCumulant2nd4050ALICE = sizeof(xCumulant2nd4050ALICE)/sizeof(Double_t);                                      
3605     TGraphErrors *Cumulant2nd4050ALICE = new TGraphErrors(nPointsCumulant2nd4050ALICE,xCumulant2nd4050ALICE,yCumulant2nd4050ALICE,
3606                                                           xErrCumulant2nd4050ALICE,yErrCumulant2nd4050ALICE);
3607     Cumulant2nd4050ALICE->SetMarkerStyle(kOpenTriangleUp);
3608     Cumulant2nd4050ALICE->SetMarkerColor(kGreen+2);
3609     
3610     return Cumulant2nd4050ALICE;
3611   }
3612   
3613   return 0;
3614 }
3615
3616 TGraphErrors* GetFlow6070_Rap10(Int_t n)
3617 {
3618   // private communication 18.05.11, Ante B. 
3619
3620   if (n == 2)
3621   {
3622     //  v2{SP}(pt) for 60-70%, rapidity gap = 1.0:
3623     const Int_t nPointsSP_6070ALICE_v2_etaGap10 = 9;
3624     Double_t xSP_6070ALICE_v2_etaGap10[nPointsSP_6070ALICE_v2_etaGap10] = {0.300000,0.500000,0.700000,0.900000,1.250000,1.750000,2.500000,3.500000,4.500000};
3625     Double_t ySP_6070ALICE_v2_etaGap10[nPointsSP_6070ALICE_v2_etaGap10] = {0.044958,0.073313,0.105726,0.120423,0.147537,0.186749,0.205423,0.208575,0.185938};
3626     Double_t xErrSP_6070ALICE_v2_etaGap10[nPointsSP_6070ALICE_v2_etaGap10] = {0.};
3627     Double_t yErrSP_6070ALICE_v2_etaGap10[nPointsSP_6070ALICE_v2_etaGap10] = {0.001520,0.001772,0.002245,0.002842,0.002600,0.004443,0.006240,0.014665,0.028810};
3628     TGraphErrors *GrSP_6070ALICE_v2_etaGap10 = new TGraphErrors(nPointsSP_6070ALICE_v2_etaGap10,xSP_6070ALICE_v2_etaGap10,
3629                                                               ySP_6070ALICE_v2_etaGap10,xErrSP_6070ALICE_v2_etaGap10,
3630                                                               yErrSP_6070ALICE_v2_etaGap10);
3631
3632     return GrSP_6070ALICE_v2_etaGap10;
3633   }
3634   
3635   return 0;
3636 }
3637
3638 Float_t CalculateFlow(TH1* ptDist, Float_t ptMin, Float_t ptMax, Int_t n, Int_t centralityBegin, Int_t centralityEnd)
3639 {
3640   if (centralityBegin == 0 && centralityEnd == 1)
3641     flow = GetFlow01_Rap10(n);
3642   else if (centralityBegin == 0 && centralityEnd == 2)
3643     flow = GetFlow02_Rap10(n);
3644   else if (centralityBegin == 0 && centralityEnd == 5)
3645     flow = GetFlow05_Rap10(n);
3646   else if (centralityBegin == 5 && centralityEnd == 10)
3647     flow = GetFlow510_Rap10(n);
3648   else if (centralityBegin == 20 && centralityEnd == 30)
3649     flow = GetFlow2030(n);
3650   else if (centralityBegin == 30 && centralityEnd == 40)
3651     flow = GetFlow3040(n);
3652   else if (centralityBegin == 40 && centralityEnd == 50)
3653     flow = GetFlow4050(n);
3654   else if (centralityBegin > 50)
3655     flow = GetFlow6070_Rap10(n);
3656   else if (centralityBegin == 0 && centralityEnd == 20)
3657   {
3658     flow1 = GetFlow05_Rap10(n);
3659     flow2 = GetFlow510_Rap10(n);
3660     flow3 = GetFlow1020_Rap10(n);
3661     
3662     flow = (TGraphErrors*) flow2->Clone();
3663     
3664     // centrality width * dn/deta from http://arxiv.org/PS_cache/arxiv/pdf/1012/1012.1657v2.pdf
3665     Float_t mult[] = { 5 * 1601, 5 * 1294, 10 * 966 };
3666     
3667     for (Int_t i=0; i<flow->GetN(); i++)
3668     {
3669       Float_t x= flow->GetX()[i];
3670
3671 //       Printf("%f: %f %f %f", x, flow1->Eval(x), flow2->Eval(x), flow3->Eval(x));
3672       flow->GetY()[i] = flow1->Eval(x) * mult[0] + flow2->Eval(x) * mult[1] + flow3->Eval(x) * mult[2];
3673       flow->GetY()[i] /= mult[0] + mult[1] + mult[2];
3674 //       Printf(" --> %f", flow->GetY()[i]);
3675     }
3676   }
3677   else if (centralityBegin == 20 && centralityEnd == 60)
3678   {
3679     flow = GetFlow2030(n);
3680     flow2 = GetFlow3040(n);
3681     flow3 = GetFlow4050(n);
3682     
3683     // centrality width * dn/deta from http://arxiv.org/PS_cache/arxiv/pdf/1012/1012.1657v2.pdf
3684     Float_t mult[] = { 10 * 649, 10 * 426, 10 * (261+149) };
3685     
3686     if (flow->GetN() != flow2->GetN() || flow2->GetN() != flow3->GetN())
3687       AliFatal("Incompatible graphs");
3688     
3689     for (Int_t i=0; i<flow->GetN(); i++)
3690     {
3691 //       Printf("%f %f %f", flow->GetY()[i], flow2->GetY()[i], flow3->GetY()[i]);
3692       flow->GetY()[i] = flow->GetY()[i] * mult[0] + flow2->GetY()[i] * mult[1] + flow3->GetY()[i] * mult[2];
3693       flow->GetY()[i] /= mult[0] + mult[1] + mult[2];
3694 //       Printf(" --> %f", flow->GetY()[i]);
3695     }
3696   }
3697   else
3698   {
3699     Printf("Flow range %d %d not available", centralityBegin, centralityEnd);
3700     AliFatal("");
3701   }
3702
3703   Float_t vn = 0;
3704   Float_t sum = 0;
3705   for (Int_t bin = ptDist->FindBin(ptMin + 0.01); bin <= ptDist->FindBin(ptMax - 0.01); bin++)
3706   {
3707     if (ptDist->GetBinCenter(bin) > flow->GetX()[flow->GetN()-1])
3708       vn += ptDist->GetBinContent(bin) * flow->GetY()[flow->GetN()-1];
3709     else
3710       vn += ptDist->GetBinContent(bin) * flow->Eval(ptDist->GetBinCenter(bin));
3711     sum += ptDist->GetBinContent(bin);
3712   }
3713   
3714   if (sum > 0)
3715     vn /= sum;
3716   
3717   Printf("v_{%d} = %f for %f < pT < %f", n, vn, ptMin, ptMax);
3718   
3719   return vn;
3720 }
3721
3722 void CalculateFlow(const char* fileName, Int_t centralityBegin, Int_t centralityEnd)
3723 {
3724   Float_t ptTrigMin = 2;
3725   Float_t ptTrigMax = 3;
3726   
3727   Float_t ptMin = 1;
3728   Float_t ptMax = 2;
3729
3730   loadlibs();
3731
3732   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
3733   
3734   cont = h->GetUEHist(2)->GetTrackHist(0);
3735   cont->GetGrid(6)->GetGrid()->GetAxis(3)->SetRangeUser(0.01 + centralityBegin, -0.01 + centralityEnd);
3736   cont->GetGrid(6)->GetGrid()->GetAxis(2)->SetRangeUser(ptTrigMin + 0.01, ptTrigMax - 0.01);
3737   
3738   ptDist = cont->ShowProjection(1, 6);
3739   ptDist->Scale(1.0 / ptDist->Integral());
3740   
3741   cont = h->GetUEHist(2)->GetEventHist();
3742   cont->GetGrid(6)->GetGrid()->GetAxis(1)->SetRangeUser(0.01 + centralityBegin, -0.01 + centralityEnd);
3743   
3744   ptDist2 = cont->ShowProjection(0, 6);
3745   ptDist2->Scale(1.0 / ptDist2->Integral());
3746   
3747   TString str;
3748   
3749   for (Int_t n=2; n<=4; n++)
3750   {
3751     Float_t v2A = CalculateFlow(ptDist, ptMin, ptMax, n, centralityBegin, centralityEnd);
3752     Float_t v2T = CalculateFlow(ptDist2, ptTrigMin, ptTrigMax, n, centralityBegin, centralityEnd);
3753     
3754     str += Form("%f * %f, ", v2A, v2T);
3755   }
3756   
3757   ptDist->Draw();
3758   ptDist2->SetLineColor(2);
3759   ptDist2->Draw("SAME");
3760   
3761   Printf("%s", str.Data());
3762 }
3763
3764 // 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...)
3765 TGraphErrors***** yields = 0;
3766 TString currentYieldFile;
3767
3768 void WriteYields()
3769 {
3770   TFile::Open("yields.root", "RECREATE");
3771   for (Int_t i=0; i<3; i++)
3772   {
3773     for (Int_t j=0; j<6; j++)
3774     {
3775       for (Int_t k=0; k<4; k++)
3776       {
3777         // CINT limitation here
3778         TGraphErrors** tmp = yields[i][j][k];
3779         for (Int_t l=0; l<31; l++)
3780         {
3781           //Printf("%d %d %d %d", i, j, k, l);
3782           tmp[l]->Write(Form("yield_%d_%d_%d_%d", i, j, k, l));
3783         }
3784       }
3785     }
3786   }
3787   gFile->Close();
3788 }
3789
3790 void ReadYields(const char* fileName = "yields.root")
3791 {
3792   if (currentYieldFile == fileName)
3793     return;
3794     
3795   currentYieldFile = fileName;
3796
3797   CreateYieldStructure();
3798   TFile::Open(fileName);
3799   for (Int_t i=0; i<3; i++)
3800   {
3801     for (Int_t j=0; j<6; j++)
3802     {
3803       for (Int_t k=0; k<4; k++)
3804       {
3805         // CINT limitation here
3806         TGraphErrors** tmp = yields[i][j][k];
3807         for (Int_t l=0; l<31; l++)
3808         {
3809           //Printf("%d %d %d %d", i, j, k, l);
3810           tmp[l] = gFile->Get(Form("yield_%d_%d_%d_%d", i, j, k, l));
3811         }
3812       }
3813     }
3814   }
3815 }
3816
3817 void CreateYieldStructure()
3818 {
3819   if (!yields)
3820   {
3821     yields = new TGraphErrors****[3];
3822     for (Int_t i=0; i<3; i++)
3823     {
3824       yields[i] = new TGraphErrors***[6];
3825       for (Int_t j=0; j<6; j++)
3826       {
3827         yields[i][j] = new TGraphErrors**[4];
3828         for (Int_t k=0; k<4; k++)
3829         {
3830           yields[i][j][k] = new TGraphErrors*[31];
3831           // CINT limitation here
3832           TGraphErrors** tmp = yields[i][j][k];
3833           for (Int_t l=0; l<31; l++)
3834           {
3835             //Printf("%d %d %d %d", i, j, k, l);
3836             TGraphErrors* graph = new TGraphErrors;
3837             tmp[l] = graph;
3838           }
3839         }
3840       }
3841     }
3842   }
3843 }
3844
3845 void GraphShiftX(TGraphErrors* graph, Float_t offset)
3846 {
3847   for (Int_t i=0; i<graph->GetN(); i++)
3848     graph->GetX()[i] += offset;
3849 }
3850
3851 // Float_t kPythiaScalingFactor = 0.935;
3852 Float_t kPythiaScalingFactor = 1;
3853
3854 void DrawYields(const char* fileName = "yields.root")
3855 {
3856   ReadYields(fileName);
3857   
3858   c = new TCanvas("c", "c", 1800, 1200);
3859   c->Divide(6, 4);
3860   
3861   Int_t markers1[] = { 24, 25, 26, 30 };
3862   Int_t markers2[] = { 20, 21, 22, 29 };
3863   Int_t colors[] = { 1, 2, 3, 4 };
3864   //Int_t caseList[] = { 0, 10+1, 10+1, 8, 10, 11, 12, 13, 1, 9 };
3865   Int_t caseList[] = { 0, 18, 18, 23, 18, 19, 20, 21, 22, 9 };
3866   const char* caseString[] = { "", "baseline sub", "baseline vs v2 sub comp", 0, "baseline sub comp", "Same/Mixed", "Same/Mixed - v2 subtr" };
3867   
3868   Bool_t iaa = kTRUE;
3869   if (!iaa)
3870   {
3871     Int_t centralityList[] =  {  0,  1,  2, 0, 0, 1 };
3872     Int_t centralityList2[] = { -1, -1, -1, 1, 2, 2 };
3873     Float_t factors[]       = {  1,  1,  1, 1, 1, 1 };
3874     const char* centralityString[] = { "0-5%", "20-40%", "60-90%", "0-5% vs 20-40%", "0-5% vs 60-90%", "20-40% vs 60-90%" };
3875   }
3876   else
3877   {
3878     Int_t centralityList[] =  {  0,  2,  3, 0, 0, 2 };
3879     Int_t centralityList2[] = { -1, -1, -1, 2, 3, 3 };
3880     //Float_t factors[]       = {  1,  1,  1, 1, 1.0/0.9, 1.0/0.9 };
3881     //Float_t factors[]       = {  1,  1,  1, 1, 1.0/0.804, 1.0/0.804 };
3882     Float_t factors[]       = {  1,  1,  1, 1, 1.0/kPythiaScalingFactor, 1.0/kPythiaScalingFactor };
3883     //Float_t factors[]       = {  1,  1,  1, 1, 1.0, 1.0 };
3884     const char* centralityString[] = { "0-5%", "60-90%", "pp", "0-5% vs 60-90%", "0-5% vs pp", "60-90% vs pp" };
3885   }
3886   
3887   l = new TLegend(0.5, 0.5, 0.9, 0.9);
3888   l->SetFillColor(0);
3889   
3890   Float_t max[] = { 0.4, 2, 2, 2, 2, 10, 10 };
3891   Float_t max2[] = { 5, 2, 2, 2, 2, 2, 2, 2, 2 };
3892   
3893   dummy = new TH2F("dummy", ";p_{T,assoc};yield", 100, 0, 20, 20000, 0, 10);
3894   dummy->SetStats(0);
3895   
3896   TGraphErrors* prevNear[6];
3897   TGraphErrors* prevAway[6];
3898   for (Int_t caseId=0; caseId<9; caseId++) // case 0->9
3899   {
3900     for (Int_t k=0; k<6; k++) // centrality
3901     {
3902       if (caseId != 3 && caseId < 5)
3903       {
3904         if (caseId < 4)
3905           c->cd(1 + k + caseId*6);
3906         else
3907           c->cd(1 + k + (caseId-1)*6);
3908         currentDummy = dummy->DrawCopy();
3909         currentDummy->GetYaxis()->SetRangeUser(0, max[caseId]);
3910         gPad->SetGridx();
3911         gPad->SetGridy();
3912         
3913         latex = new TLatex(0.15, 0.95, Form("%s - %s", caseString[caseId], centralityString[k]));
3914         latex->SetNDC();
3915         latex->SetTextSize(0.05);
3916         latex->Draw();
3917       }
3918       else if (caseId == 3)
3919         c->cd(1 + k + 2*6);
3920       else
3921         c->cd(1 + k + 3*6);
3922       
3923       for (Int_t j=0; j<3; j++) // trigger pt
3924       {
3925         if (caseId >= 2 && j != 1)
3926           continue;
3927         Printf("%d %d %d %d", caseId, k, j, caseList[caseId]);
3928       
3929         if (k < 3)
3930         {
3931           // CINT limitation here
3932           TGraphErrors** tmp = yields[0][j][centralityList[k]];
3933           nearSide = tmp[caseList[caseId]];
3934           //new TCanvas; nearSide->Draw("AP"); return;
3935           
3936           nearSide->SetMarkerStyle(markers1[j]);
3937           nearSide->SetMarkerColor(colors[j]);
3938           nearSide->SetLineColor(colors[j]);
3939           
3940           if (caseId == 0 && k == 0)
3941             l->AddEntry(nearSide, Form("trig pt bin %d", j), "P");
3942             
3943           TGraphErrors** tmp = yields[1][j][centralityList[k]];
3944           awaySide = tmp[caseList[caseId]];
3945           awaySide->SetMarkerStyle(markers2[j]);
3946           awaySide->SetMarkerColor(colors[j]);
3947           awaySide->SetLineColor(colors[j]);
3948             
3949           GraphShiftX(nearSide, -0.1 + j*0.1);
3950           GraphShiftX(awaySide, -0.1 + j*0.1);
3951           
3952           if (caseId == 3)
3953           {
3954             nearSide->SetLineColor(caseId - 2);
3955             nearSide->SetMarkerColor(caseId - 2);
3956             awaySide->SetLineColor(caseId - 2);
3957             awaySide->SetMarkerColor(caseId - 2);
3958           }
3959           
3960           if (caseId >= 4)
3961           {
3962             nearSide->SetLineColor(caseId - 3);
3963             nearSide->SetMarkerColor(caseId - 3);
3964             awaySide->SetLineColor(caseId - 3);
3965             awaySide->SetMarkerColor(caseId - 3);
3966           }
3967           
3968           awaySide->Print();
3969           
3970           prevNear[k] = (TGraphErrors*) nearSide->DrawClone("PSAME");
3971           prevAway[k] = (TGraphErrors*) awaySide->DrawClone("PSAME");
3972           
3973           if (caseId == 4)
3974           {
3975             Printf("%d", k);
3976             for (Int_t i=0; i<nearSide->GetN(); i++)
3977             {
3978               Printf("%f: %.0f%%", nearSide->GetX()[i], 100.0 * nearSide->GetEY()[i] / nearSide->GetY()[i]);
3979               Printf("%f: %.0f%%", awaySide->GetX()[i], 100.0 * awaySide->GetEY()[i] / awaySide->GetY()[i]);
3980             }
3981           }
3982         }
3983         else
3984         {
3985           // CINT limitation here
3986           tmp = yields[0][j][centralityList[k]]; nearSideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
3987           tmp = yields[1][j][centralityList[k]]; awaySideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
3988           
3989           tmp = yields[0][j][centralityList2[k]]; 
3990           nearSidePeripheral = tmp[caseList[caseId]];
3991           if (iaa && caseId == 3 && k >= 4)
3992             nearSidePeripheral = tmp[caseList[caseId-1]];
3993           
3994           tmp = yields[1][j][centralityList2[k]]; 
3995           awaySidePeripheral = tmp[caseList[caseId]];
3996           if (iaa && caseId == 3 && k >= 4)
3997             awaySidePeripheral = tmp[caseList[caseId-1]];
3998             
3999 //           nearSideCentral->Print();
4000 //           nearSidePeripheral->Print();
4001           
4002           if (k == 3)
4003             currentDummy->GetYaxis()->SetTitle("I_{CP}");
4004           else
4005             currentDummy->GetYaxis()->SetTitle("I_{AA}");
4006           currentDummy->GetYaxis()->SetRangeUser(0, max2[caseId]);
4007           
4008           for (Int_t i=0; i<nearSideCentral->GetN(); i++)
4009           {
4010             if (i >= nearSidePeripheral->GetN())
4011             {
4012               nearSideCentral->RemovePoint(i);
4013               i--;
4014               continue;
4015             }
4016           
4017             //Printf("near %d %f %f", i, nearSideCentral->GetY()[i], nearSidePeripheral->GetY()[i]);
4018             if (nearSidePeripheral->GetY()[i] <= 1e-5 || nearSideCentral->GetY()[i] <= 1e-5)
4019             {
4020               nearSideCentral->RemovePoint(i);
4021               nearSidePeripheral->RemovePoint(i);
4022               i--;
4023               continue;
4024             }
4025           
4026             nearSideCentral->GetEY()[i] = TMath::Sqrt(
4027               TMath::Power(nearSideCentral->GetEY()[i] / nearSideCentral->GetY()[i], 2) + 
4028               TMath::Power(nearSidePeripheral->GetEY()[i] / nearSidePeripheral->GetY()[i], 2) );
4029               
4030             nearSideCentral->GetY()[i] /= nearSidePeripheral->GetY()[i];
4031             nearSideCentral->GetY()[i] *= factors[k];
4032             
4033             nearSideCentral->GetEY()[i] *= nearSideCentral->GetY()[i];
4034           }
4035           //Printf("done");
4036           
4037           for (Int_t i=0; i<awaySideCentral->GetN(); i++)
4038           {
4039             if (i >= awaySidePeripheral->GetN())
4040             {
4041               awaySideCentral->RemovePoint(i);
4042               i--;
4043               continue;
4044             }
4045             
4046             //Printf("away %d", i);
4047             if (awaySidePeripheral->GetY()[i] <= 1e-5 || awaySideCentral->GetY()[i] <= 1e-5)
4048             {
4049               awaySideCentral->RemovePoint(i);
4050               awaySidePeripheral->RemovePoint(i);
4051               i--;
4052               continue;
4053             }
4054             
4055             awaySideCentral->GetEY()[i] = TMath::Sqrt(
4056               TMath::Power(awaySideCentral->GetEY()[i] / awaySideCentral->GetY()[i], 2) + 
4057               TMath::Power(awaySidePeripheral->GetEY()[i] / awaySidePeripheral->GetY()[i], 2) );
4058             
4059             awaySideCentral->GetY()[i] /= awaySidePeripheral->GetY()[i];
4060             awaySideCentral->GetY()[i] *= factors[k];
4061           
4062             awaySideCentral->GetEY()[i] *= awaySideCentral->GetY()[i];
4063           }
4064           
4065           if (caseId == 3)
4066           {
4067             nearSideCentral = (TGraphErrors*) nearSideCentral->Clone();
4068             nearSideCentral->SetLineColor(1);
4069             nearSideCentral->SetMarkerColor(1);
4070           
4071             awaySideCentral = (TGraphErrors*) awaySideCentral->Clone();
4072             awaySideCentral->SetLineColor(1);
4073             awaySideCentral->SetMarkerColor(1);
4074           }
4075           
4076           if (caseId >= 4)
4077           {
4078             nearSideCentral = (TGraphErrors*) nearSideCentral->Clone();
4079             nearSideCentral->SetLineColor(caseId - 3);
4080             nearSideCentral->SetMarkerColor(caseId - 3);
4081           
4082             awaySideCentral = (TGraphErrors*) awaySideCentral->Clone();
4083             awaySideCentral->SetLineColor(caseId - 3);
4084             awaySideCentral->SetMarkerColor(caseId - 3);
4085           }
4086           
4087           //Printf("%d", caseList[caseId]);
4088           
4089 //           nearSideCentral->Print();
4090           
4091           nearSideCentral->Draw("PSAME");
4092           awaySideCentral->Draw("PSAME");
4093         
4094           if (caseId == 3)
4095           {
4096             for (Int_t i=0; i<nearSideCentral->GetN(); i++)
4097               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]));
4098             for (Int_t i=0; i<awaySideCentral->GetN(); i++)
4099               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]));
4100           }
4101         
4102           prevNear[k] = nearSideCentral;
4103           prevAway[k] = awaySideCentral;
4104         }
4105       }
4106       if (caseId == 0 && k == 0)
4107         l->Draw();
4108     }
4109   }
4110   
4111   c->SaveAs("yields.png");
4112 }
4113
4114 void FitGaussians(const char* fileName, Bool_t flat)
4115 {
4116   CreateYieldStructure();
4117
4118   aliceFile = TFile::Open(fileName);
4119
4120   Int_t maxLeadingPt = 3;
4121   Int_t maxAssocPt = 3;
4122   
4123   TCanvas* canvas = new TCanvas("FitGaussians", "FitGaussians", 1000, 700);
4124   canvas->Divide(maxAssocPt, maxLeadingPt);
4125   
4126   for (Int_t i=0; i<maxLeadingPt; i++)
4127     for (Int_t j=0; j<maxAssocPt; j++)
4128     {
4129       TH1* first = 0;
4130       for (Int_t aliceCentrality=0; aliceCentrality<4; aliceCentrality++)
4131       {
4132         Printf("%d %d %d", i, j, aliceCentrality);
4133         
4134         canvas->cd(j+1 + (i) * maxAssocPt);
4135         gPad->SetLeftMargin(0.15);
4136         gPad->SetBottomMargin(0.2);
4137         //gPad->SetTopMargin(0.01);
4138         gPad->SetRightMargin(0.01);
4139         
4140         hist = (TH1*) aliceFile->Get(Form("dphi_%d_%d_%d%s", i, j, aliceCentrality, (flat) ? "_fit_flat" : ""));
4141         if (!hist)
4142           continue;
4143         
4144 //      hist->Rebin(2);
4145         
4146         // two Gauss fits
4147         gausFit = new TF1("gausFit", "[0] + gaus(1) + gaus(4)", -0.5 * TMath::Pi(), 1.5 * TMath::Pi());
4148         gausFit->SetParameters(0, 1, 0, 1, 1, TMath::Pi(), 1);
4149         gausFit->SetParLimits(0, -1, 10000);
4150         gausFit->SetParLimits(1, 0.001, 10000);
4151         gausFit->FixParameter(2, 0);
4152         gausFit->SetParLimits(3, 0.05, 10);
4153         gausFit->SetParLimits(4, 0.001, 10000);
4154         gausFit->FixParameter(5, TMath::Pi());
4155         gausFit->SetParLimits(6, 0.1, 10);
4156         
4157         gausFit->SetLineWidth(1);
4158         gausFit->SetLineColor(hist->GetLineColor());
4159         
4160         hist->Fit(gausFit, "0RIQ");
4161         gausFit->FixParameter(0, gausFit->GetParameter(0));
4162         hist->Fit(gausFit, "RI", (aliceCentrality == 0) ? "" : "SAME");
4163         //gausFit->DrawCopy("SAME");
4164         
4165         // get pT,assoc
4166         TPRegexp reg("(\\d+\\.\\d+) \\< p_\\{T,assoc\\} \\< (\\d+\\.\\d+)");
4167         arr = reg.MatchS(hist->GetTitle(), "", 0, 10);
4168         if (arr->GetEntries() != 3)
4169           continue;
4170           
4171         Float_t pt1 = atof(arr->At(1)->GetName());
4172         Float_t pt2 = atof(arr->At(2)->GetName());
4173
4174         FillYield(i, aliceCentrality, (pt1 + pt2) / 2, (pt2 - pt1) / 2, 18, gausFit->GetParameter(3), gausFit->GetParError(3), gausFit->GetParameter(6), gausFit->GetParError(6));
4175         
4176         if (!first)
4177           first = hist;
4178         else
4179           first->GetYaxis()->SetRangeUser(TMath::Min(first->GetMinimum(), hist->GetMinimum()), TMath::Max(first->GetMaximum(), hist->GetMaximum()));
4180       }
4181       first->GetYaxis()->SetRangeUser(first->GetMinimum(), 2 * first->GetMaximum());
4182         
4183 //        break;
4184     }
4185     
4186     
4187   // draw
4188   
4189   for (Int_t j=0; j<maxLeadingPt; j++)
4190   {
4191     new TCanvas;
4192     
4193     Int_t markers1[] = { 24, 25, 26, 30 };
4194     Int_t markers2[] = { 20, 21, 22, 29 };
4195     Int_t colors[] = { 1, 2, 3, 4 };
4196     
4197     dummy = new TH2F("dummy", ";p_{T,assoc};", 100, 0, 10, 1000, 0, 1);
4198     dummy->SetStats(0);
4199     dummy->Draw();
4200     
4201     for (Int_t k=0; k<4; k++) // centrality
4202     {
4203       // CINT limitation here
4204       TGraphErrors** tmp = yields[0][j][k];
4205       nearSide = tmp[18];
4206       nearSide->SetMarkerStyle(markers1[k]);
4207       nearSide->SetMarkerColor(colors[k]);
4208       nearSide->SetLineColor(colors[k]);  
4209     
4210       TGraphErrors** tmp = yields[1][j][k];
4211       awaySide = tmp[18];
4212       awaySide->SetMarkerStyle(markers2[k]);
4213       awaySide->SetMarkerColor(colors[k]);
4214       awaySide->SetLineColor(colors[k]);  
4215       
4216       nearSide->DrawClone("PSAME");
4217       awaySide->DrawClone("PSAME");
4218     }
4219   }
4220 }
4221
4222 void TsallisExamples()
4223 {
4224   tsallis = new TF1("tsallis", "[0] * (1-[2]*(1-[1])*x*x)**(1/(1-[1]))", -0.5 * TMath::Pi(), 1.5 * TMath::Pi());
4225   
4226   Float_t q[] = { 1.0000001, 1.5, 2 };
4227   Float_t beta[] = { 0.1, 1, 10, 100 };
4228   
4229   dummy = new TH2F("dummy", "", 100, -0.5 * TMath::Pi(), 1.5 * TMath::Pi(), 100, 0, 1.2);
4230   dummy->SetStats(0);
4231   dummy->Draw();
4232   
4233   legend = new TLegend(0.65, 0.5, 1, 1);
4234   legend->SetFillColor(0);
4235   
4236   for (Int_t i=0; i<3; i++)
4237     for (Int_t j=0; j<4; j++)
4238     {
4239       tsallis->SetParameters(1, q[i], beta[j]);
4240       tsallis->SetLineColor(i+1);
4241       tsallis->SetLineStyle(j+1);
4242       
4243       legend->AddEntry(tsallis->DrawCopy("SAME"), Form("q = %.1f, #beta = %.1f", q[i], beta[j]), "L");
4244     }
4245     
4246   legend->Draw();
4247 }
4248
4249 void DrawTsallisParams()
4250 {
4251   ReadYields();
4252   
4253   c = new TCanvas("c", "c", 900, 600);
4254   c->Divide(3, 2);
4255   
4256   Int_t markers1[] = { 24, 25, 26, 30 };
4257   Int_t markers2[] = { 20, 21, 22, 29 };
4258   Int_t colors[] = { 1, 2, 3, 4 };
4259   Int_t caseList[] = { 12, 13, 8, 6, 8, 9, 10, 11, 1, 7 };
4260   const char* caseString[] = { "q", "beta" };
4261   const char* centralityString[] = { "0-5%", "20-40%", "60-90%", "0-5% vs 20-40%", "0-5% vs 60-90%", "20-40% vs 60-90%" };
4262   
4263   l = new TLegend(0.5, 0.5, 0.9, 0.9);
4264   l->SetFillColor(0);
4265   
4266   Float_t max[] = { 3, 1000 };
4267   Float_t max2[] = { 5, 2 };
4268   
4269   dummy = new TH2F("dummy", ";p_{T,assoc};", 100, 0, 20, 1000, 0, 1000);
4270   dummy->SetStats(0);
4271   
4272   for (Int_t caseId=0; caseId<2; caseId++) // case
4273   {
4274     for (Int_t k=0; k<3; k++) // centrality
4275     {
4276       c->cd(1 + k + caseId*3);
4277         
4278       currentDummy = dummy->DrawCopy();
4279       currentDummy->GetYaxis()->SetRangeUser(0, max[caseId]);
4280       if (caseId == 1 && k < 3)
4281         gPad->SetLogy();
4282       
4283       latex = new TLatex(0.15, 0.95, Form("%s - %s", caseString[caseId], centralityString[k]));
4284       latex->SetNDC();
4285       latex->SetTextSize(0.05);
4286       latex->Draw();
4287       
4288       for (Int_t j=0; j<2; j++) // trigger pt
4289       {
4290         if (k < 3)
4291         {
4292           // CINT limitation here
4293           TGraphErrors** tmp = yields[0][j][k];
4294           nearSide = tmp[caseList[caseId]];
4295           nearSide->SetMarkerStyle(markers1[j]);
4296           nearSide->SetMarkerColor(colors[j]);
4297           nearSide->SetLineColor(colors[j]);
4298           
4299           if (caseId == 0 && k == 0)
4300             l->AddEntry(nearSide, Form("trig pt bin %d", j), "P");
4301             
4302           TGraphErrors** tmp = yields[1][j][k];
4303           awaySide = tmp[caseList[caseId]];
4304           awaySide->SetMarkerStyle(markers2[j]);
4305           awaySide->SetMarkerColor(colors[j]);
4306           awaySide->SetLineColor(colors[j]);
4307             
4308           GraphShiftX(nearSide, -0.1 + j*0.1);
4309           GraphShiftX(awaySide, -0.1 + j*0.1);
4310           
4311           Printf("%d %d %d", caseId, j, k);
4312           nearSide->Print();
4313           awaySide->Print();
4314           
4315           nearSide->DrawClone("PSAME");
4316           awaySide->DrawClone("PSAME");
4317         }
4318         else
4319         {
4320           // CINT limitation here
4321           if (k == 3)
4322           {
4323             tmp = yields[0][j][0]; nearSideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
4324             tmp = yields[1][j][0]; awaySideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
4325             tmp = yields[0][j][1]; nearSidePeripheral = tmp[caseList[caseId]];
4326             tmp = yields[1][j][1]; awaySidePeripheral = tmp[caseList[caseId]];
4327           }
4328           else if (k == 4)
4329           {
4330             tmp = yields[0][j][0]; nearSideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
4331             tmp = yields[1][j][0]; awaySideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
4332             tmp = yields[0][j][2]; nearSidePeripheral = tmp[caseList[caseId]];
4333             tmp = yields[1][j][2]; awaySidePeripheral = tmp[caseList[caseId]];
4334           }
4335           else if (k == 5)
4336           {
4337             tmp = yields[0][j][1]; nearSideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
4338             tmp = yields[1][j][1]; awaySideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
4339             tmp = yields[0][j][2]; nearSidePeripheral = tmp[caseList[caseId]];
4340             tmp = yields[1][j][2]; awaySidePeripheral = tmp[caseList[caseId]];
4341           }
4342           
4343           currentDummy->GetYaxis()->SetTitle("I_{CP}");
4344           currentDummy->GetYaxis()->SetRangeUser(0, max2[caseId]);
4345         
4346           for (Int_t i=0; i<nearSideCentral->GetN(); i++)
4347           {
4348             //Printf("near %d %f %f", i, nearSideCentral->GetY()[i], nearSidePeripheral->GetY()[i]);
4349             if (nearSidePeripheral->GetY()[i] <= 1e-5 || nearSideCentral->GetY()[i] <= 1e-5)
4350             {
4351               nearSideCentral->RemovePoint(i);
4352               nearSidePeripheral->RemovePoint(i);
4353               i--;
4354               continue;
4355             }
4356           
4357             nearSideCentral->GetEY()[i] = TMath::Sqrt(
4358               TMath::Power(nearSideCentral->GetEY()[i] / nearSideCentral->GetY()[i], 2) + 
4359               TMath::Power(nearSidePeripheral->GetEY()[i] / nearSidePeripheral->GetY()[i], 2) );
4360               
4361             nearSideCentral->GetY()[i] /= nearSidePeripheral->GetY()[i];
4362             
4363             nearSideCentral->GetEY()[i] *= nearSideCentral->GetY()[i];
4364           }
4365           //Printf("done");
4366           
4367           for (Int_t i=0; i<awaySideCentral->GetN(); i++)
4368           {
4369             //Printf("away %d", i);
4370             if (awaySidePeripheral->GetY()[i] <= 1e-5 || awaySideCentral->GetY()[i] <= 1e-5)
4371             {
4372               awaySideCentral->RemovePoint(i);
4373               awaySidePeripheral->RemovePoint(i);
4374               i--;
4375               continue;
4376             }
4377             
4378             awaySideCentral->GetEY()[i] = TMath::Sqrt(
4379               TMath::Power(awaySideCentral->GetEY()[i] / awaySideCentral->GetY()[i], 2) + 
4380               TMath::Power(awaySidePeripheral->GetEY()[i] / awaySidePeripheral->GetY()[i], 2) );
4381             
4382             awaySideCentral->GetY()[i] /= awaySidePeripheral->GetY()[i];
4383           
4384             awaySideCentral->GetEY()[i] *= awaySideCentral->GetY()[i];
4385           }
4386           
4387           if (caseId == 3)
4388           {
4389             nearSideCentral = (TGraphErrors*) nearSideCentral->Clone();
4390             nearSideCentral->SetLineColor(1);
4391             nearSideCentral->SetMarkerColor(1);
4392           
4393             awaySideCentral = (TGraphErrors*) awaySideCentral->Clone();
4394             awaySideCentral->SetLineColor(1);
4395             awaySideCentral->SetMarkerColor(1);
4396           }
4397           
4398           if (caseId >= 4)
4399           {
4400             nearSideCentral = (TGraphErrors*) nearSideCentral->Clone();
4401             nearSideCentral->SetLineColor(caseId - 3);
4402             nearSideCentral->SetMarkerColor(caseId - 3);
4403           
4404             awaySideCentral = (TGraphErrors*) awaySideCentral->Clone();
4405             awaySideCentral->SetLineColor(caseId - 3);
4406             awaySideCentral->SetMarkerColor(caseId - 3);
4407           }
4408           
4409           //Printf("%d", caseList[caseId]);
4410           
4411           nearSideCentral->Draw("PSAME");
4412           awaySideCentral->Draw("PSAME");
4413         }
4414       }
4415       if (caseId == 0 && k == 0)
4416         l->Draw();
4417     }
4418   }
4419   
4420   c->SaveAs("tsallisparams.png");
4421 }
4422
4423 void DrawYieldLHCRHIC_ICP(const char* fileName = "yields.root")
4424 {
4425   Int_t caseId = 0;
4426   Int_t caseList[] = { 18 };
4427   Int_t j = 1;
4428   
4429   ReadYields(fileName);
4430   
4431   c = new TCanvas("lhc_rhic", "lhc_rhic", 800, 600);
4432   gPad->SetGridx();
4433   gPad->SetGridy();
4434   
4435   dummy = new TH2F("dummy", ";p_{T,assoc};I_{CP}", 100, 0, 12, 1000, 0, 10);
4436   dummy->SetStats(0);
4437   currentDummy = dummy->DrawCopy();
4438   currentDummy->GetYaxis()->SetRangeUser(0, 2);
4439         
4440   TGraphErrors** tmp = yields[0][j][0]; nearSideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
4441   tmp = yields[1][j][0]; awaySideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
4442   tmp = yields[0][j][2]; nearSidePeripheral = tmp[caseList[caseId]];
4443   tmp = yields[1][j][2]; awaySidePeripheral = tmp[caseList[caseId]];
4444         
4445   for (Int_t i=0; i<nearSideCentral->GetN(); i++)
4446   {
4447     //Printf("near %d %f %f", i, nearSideCentral->GetY()[i], nearSidePeripheral->GetY()[i]);
4448     if (nearSidePeripheral->GetY()[i] <= 1e-5 || nearSideCentral->GetY()[i] <= 1e-5)
4449     {
4450       nearSideCentral->RemovePoint(i);
4451       nearSidePeripheral->RemovePoint(i);
4452       i--;
4453       continue;
4454     }
4455   
4456     nearSideCentral->GetEY()[i] = TMath::Sqrt(
4457       TMath::Power(nearSideCentral->GetEY()[i] / nearSideCentral->GetY()[i], 2) + 
4458       TMath::Power(nearSidePeripheral->GetEY()[i] / nearSidePeripheral->GetY()[i], 2) );
4459       
4460     nearSideCentral->GetY()[i] /= nearSidePeripheral->GetY()[i];
4461     
4462     nearSideCentral->GetEY()[i] *= nearSideCentral->GetY()[i];
4463   }
4464   //Printf("done");
4465   
4466   for (Int_t i=0; i<awaySideCentral->GetN(); i++)
4467   {
4468     //Printf("away %d", i);
4469     if (awaySidePeripheral->GetY()[i] <= 1e-5 || awaySideCentral->GetY()[i] <= 1e-5)
4470     {
4471       awaySideCentral->RemovePoint(i);
4472       awaySidePeripheral->RemovePoint(i);
4473       i--;
4474       continue;
4475     }
4476     
4477     awaySideCentral->GetEY()[i] = TMath::Sqrt(
4478       TMath::Power(awaySideCentral->GetEY()[i] / awaySideCentral->GetY()[i], 2) + 
4479       TMath::Power(awaySidePeripheral->GetEY()[i] / awaySidePeripheral->GetY()[i], 2) );
4480     
4481     awaySideCentral->GetY()[i] /= awaySidePeripheral->GetY()[i];
4482   
4483     awaySideCentral->GetEY()[i] *= awaySideCentral->GetY()[i];
4484   }
4485           
4486   nearSideCentral->SetMarkerStyle(21);
4487   nearSideCentral->SetLineColor(1);
4488   nearSideCentral->SetMarkerColor(1);
4489           
4490   awaySideCentral->SetMarkerStyle(25);
4491   awaySideCentral->SetLineColor(1);
4492   awaySideCentral->SetMarkerColor(1);
4493   
4494   nearSideCentral->Draw("PSAME");
4495   awaySideCentral->Draw("PSAME");        
4496
4497   legend = new TLegend(0.4, 0.8, 0.99, 0.99);
4498   legend->SetFillColor(0);
4499   legend->AddEntry(nearSideCentral, "ALICE I_{CP} Near 8-15 GeV 0-5%/60-90%", "P");
4500   legend->AddEntry(awaySideCentral, "ALICE I_{CP} Away 8-15 GeV 0-5%/60-90%", "P");
4501   
4502   if (0)
4503   {
4504     nearSideCentral->Fit("pol1", "", "SAME", 4.5, 11.5);
4505     awaySideCentral->Fit("pol1", "", "SAME", 4.5, 11.5);
4506     nearSideCentral->GetFunction("pol1")->SetLineWidth(1);
4507     awaySideCentral->GetFunction("pol1")->SetLineWidth(1);
4508   }
4509
4510   if (0)
4511   {
4512     // RCP, ALICE
4513     dndpt_central = ReadHepdata("raa_dndpt_central.txt", kFALSE, 3);
4514     dndpt_peripheral = ReadHepdata("raa_dndpt_peripheral.txt", kFALSE, 3);
4515     
4516     //dndpt_central->Print();
4517     //dndpt_peripheral->Print();
4518     
4519     // ratio of Ncoll (from paper)
4520     // TODO there is also an uncertainty on that
4521     Double_t scale = 1690. / 15.7;
4522     Double_t scaleUnc = TMath::Sqrt(TMath::Power(131. / 1690., 2) + TMath::Power(0.7 / 15.7, 2));
4523     
4524     for (Int_t i=0; i<dndpt_central->GetN(); i++)
4525     {
4526       dndpt_central->GetEY()[i] = TMath::Sqrt(TMath::Power(dndpt_central->GetEY()[i] / dndpt_central->GetY()[i], 2) + 
4527         TMath::Power(dndpt_peripheral->GetEY()[i] / dndpt_peripheral->GetY()[i], 2));
4528       dndpt_central->GetY()[i] /= dndpt_peripheral->GetY()[i] * scale;
4529       dndpt_central->GetEY()[i] *= dndpt_central->GetY()[i];
4530     }
4531     
4532     //new TCanvas;
4533     //dndpt_central->Print();
4534     //dndpt_central->Draw("AP");
4535     
4536     dndpt_central->Draw("*SAME");
4537     
4538     latex = new TLatex(0.34, 0.09, "9% N_{coll} scale uncertainty on R_{CP}");
4539     latex->SetTextSize(0.03);
4540     latex->Draw();
4541     
4542     // RAA, ALICE
4543     raa_central = ReadHepdata("raa_alice_central.txt", kFALSE, 3);
4544     raa_central->SetMarkerStyle(20);
4545     //raa_central->Draw("PSAME");
4546   
4547     legend->AddEntry(dndpt_central, "ALICE R_{CP} 0-5%/70-80%", "P");
4548   }
4549   
4550   if (0)
4551   {
4552     // IAA, RHIC
4553     // calculate ICP from IAA(0-20) / IAA (20-60)
4554     // TODO only using uncertainties from IAA(0-20)
4555     // TODO systematic uncertainty stored in graph with _sys appended
4556     TFile::Open("rhic/pi0h_graphs.root");
4557     
4558     for (Int_t i=0; i<3; i+=2)
4559     {
4560       // gIAA_<ptTrigBin>_<centBin>_<angularRegionBin>
4561       central = (TGraphErrors*) gFile->Get(Form("gIAA_3_0_%d", i));
4562       peripheral = (TGraphErrors*) gFile->Get(Form("gIAA_3_1_%d", i));
4563       
4564       for (Int_t j=0; j<central->GetN(); j++)
4565       {
4566         central->GetY()[j] /= peripheral->GetY()[j];
4567         central->GetEY()[j] /= peripheral->GetY()[j];
4568       }
4569       
4570       central->SetMarkerStyle((i == 0) ? 29 : 30);
4571       central->SetMarkerColor(2);
4572       central->SetLineColor(2);
4573       central->Draw("PSAME");
4574       legend->AddEntry(central, Form("PHENIX I_{CP} %s 9-12 GeV 0-20%/20-60%", (i == 0) ? "Near" : "Away"), "P");
4575     }
4576   }
4577   
4578   legend->Draw();
4579   
4580   c->SaveAs("icp.png");
4581 }
4582
4583 TGraphErrors* GetRatio(const char* fileName, Int_t centrality1, Int_t centrality2, Int_t triggerId, Int_t caseId, Int_t side, const char* fileName2 = 0)
4584 {
4585   // 0 = near side; 1 = away side
4586
4587   ReadYields(fileName);
4588   
4589   TGraphErrors** tmp = yields[side][triggerId][centrality1]; 
4590   nearSideCentral = (TGraphErrors*) tmp[caseId]->Clone();
4591   
4592   if (fileName2)
4593     ReadYields(fileName2);
4594   
4595   tmp = yields[side][triggerId][centrality2]; 
4596   nearSidePeripheral = (TGraphErrors*) tmp[caseId]->Clone();
4597   
4598 //   Printf("%d %d", nearSideCentral->GetN(), nearSidePeripheral->GetN());
4599         
4600   for (Int_t i=0; i<nearSideCentral->GetN(); i++)
4601   {
4602     if (nearSidePeripheral->GetY()[i] <= 1e-5 || nearSideCentral->GetY()[i] <= 1e-5)
4603     {
4604       nearSideCentral->RemovePoint(i);
4605       nearSidePeripheral->RemovePoint(i);
4606       i--;
4607       continue;
4608     }
4609     
4610     if (nearSideCentral->GetX()[i] != nearSidePeripheral->GetX()[i])
4611     {
4612       Printf("Inconsistent x values %f %f", nearSideCentral->GetX()[i], nearSidePeripheral->GetX()[i]);
4613       AliFatal("");
4614     }
4615   
4616 //     printf("%f %f %f", nearSideCentral->GetX()[i], nearSideCentral->GetY()[i], nearSidePeripheral->GetY()[i]);
4617     
4618     nearSideCentral->GetEY()[i] = TMath::Sqrt(
4619       TMath::Power(nearSideCentral->GetEY()[i] / nearSideCentral->GetY()[i], 2) + 
4620       TMath::Power(nearSidePeripheral->GetEY()[i] / nearSidePeripheral->GetY()[i], 2) );
4621       
4622     nearSideCentral->GetY()[i] /= nearSidePeripheral->GetY()[i];
4623     // scaling for IAA
4624     if (centrality2 == 3)
4625       nearSideCentral->GetY()[i] /= kPythiaScalingFactor;
4626     
4627 //     Printf(" %f", nearSideCentral->GetY()[i]);
4628     
4629     nearSideCentral->GetEY()[i] *= nearSideCentral->GetY()[i];
4630   }
4631   
4632   //nearSideCentral->GetXaxis()->SetTitle("p_{T, assoc}");
4633   //nearSideCentral->GetYaxis()->SetTitle((centrality2 == 3) ? "I_{AA}" : "I_{CP}");
4634
4635   if (0 && side == 1 && centrality2 == 3)
4636   {
4637     Printf("\n\n\nWARNING !!! Fudging different away side acceptance (only for second file)\n\n\n");
4638     ScaleGraph(nearSideCentral, 1.56);
4639   }
4640   
4641   return nearSideCentral;
4642 }
4643
4644 TGraphErrors* GetIAA(const char* fileName, Int_t centrality, Int_t triggerId, Int_t caseId, Int_t side)
4645 {
4646   return GetRatio(fileName, centrality, 3, triggerId, caseId, side);
4647 }
4648
4649 TGraphErrors* GetICP(const char* fileName, Int_t triggerId, Int_t caseId, Int_t side)
4650 {
4651   return GetRatio(fileName, 1, 2, triggerId, caseId, side);
4652 }
4653
4654 void DrawYieldLHCRHIC_IAA(const char* fileName, Bool_t central, Bool_t rhic)
4655 {
4656   Int_t caseId = 0;
4657   Int_t caseList[] = { 18 };
4658   Int_t j = 1;
4659   
4660   ReadYields(fileName);
4661   
4662   c = new TCanvas("lhc_rhic", "lhc_rhic", 800, 600);
4663   gPad->SetGridx();
4664   gPad->SetGridy();
4665   
4666   dummy = new TH2F("dummy", ";p_{T,assoc};I_{AA}", 100, 0, 12, 1000, 0, 10);
4667   dummy->SetStats(0);
4668   currentDummy = dummy->DrawCopy();
4669   currentDummy->GetYaxis()->SetRangeUser(0, 3);
4670         
4671   Int_t nominatorBin = 0;
4672   if (!central)
4673     nominatorBin = 2;
4674         
4675   nearSideCentral = GetIAA(fileName, nominatorBin, j, caseList[caseId], 0);
4676   awaySideCentral = GetIAA(fileName, nominatorBin, j, caseList[caseId], 1);
4677   
4678   nearSideCentral->SetMarkerStyle(21);
4679   nearSideCentral->SetLineColor(1);
4680   nearSideCentral->SetMarkerColor(1);
4681           
4682   awaySideCentral->SetMarkerStyle(25);
4683   awaySideCentral->SetLineColor(1);
4684   awaySideCentral->SetMarkerColor(1);
4685   
4686   nearSideCentral->Draw("PSAME");
4687   awaySideCentral->Draw("PSAME");        
4688   
4689   legend = new TLegend(0.4, 0.8, 0.99, 0.99);
4690   legend->SetFillColor(0);
4691   legend->AddEntry(nearSideCentral, Form("ALICE I_{AA} Near 8-15 GeV %s%%/Pythia6", (central) ? "0-5" : "60-90"), "P");
4692   legend->AddEntry(awaySideCentral, Form("ALICE I_{AA} Away 8-15 GeV %s%%/Pythia6", (central) ? "0-5" : "60-90"), "P");
4693   
4694   if (rhic)
4695   {
4696     // IAA, RHIC
4697     // systematic uncertainty stored in graph with _sys appended
4698     TFile::Open("rhic/pi0h_graphs.root");
4699     
4700     for (Int_t i=0; i<3; i+=2)
4701     {
4702       // gIAA_<ptTrigBin>_<centBin>_<angularRegionBin>
4703       rhic_iaa = (TGraphErrors*) gFile->Get(Form("gIAA_2_%d_%d", (central) ? 0 : 1, i));
4704       rhic_iaa_sys = (TGraphErrors*) gFile->Get(Form("gIAA_2_%d_%d_sys", (central) ? 0 : 1, i));
4705   
4706       rhic_iaa->SetMarkerStyle((i == 0) ? 29 : 30);
4707       rhic_iaa->SetMarkerColor(2);
4708       rhic_iaa->SetLineColor(2);
4709       rhic_iaa->Draw("PSAME");
4710       rhic_iaa_sys->SetLineColor(2);
4711       rhic_iaa_sys->SetMarkerColor(2);
4712       rhic_iaa_sys->Draw("PSAME");
4713       legend->AddEntry(rhic_iaa, Form("PHENIX I_{AA} %s 7-9 GeV %s%%/pp", (i == 0) ? "Near" : "Away", (central) ? "0-20" : "20-60"), "P");
4714     }
4715     for (Int_t i=0; i<3; i+=2)
4716     {
4717       // gIAA_<ptTrigBin>_<centBin>_<angularRegionBin>
4718       rhic_iaa = (TGraphErrors*) gFile->Get(Form("gIAA_3_%d_%d", (central) ? 0 : 1, i));
4719       rhic_iaa_sys = (TGraphErrors*) gFile->Get(Form("gIAA_3_%d_%d_sys", (central) ? 0 : 1, i));
4720   
4721       rhic_iaa->SetMarkerStyle((i == 0) ? 20 : 24);
4722       rhic_iaa->SetMarkerColor(4);
4723       rhic_iaa->SetLineColor(4);
4724       rhic_iaa->Draw("PSAME");
4725       rhic_iaa_sys->SetLineColor(4);
4726       rhic_iaa_sys->SetMarkerColor(4);
4727       rhic_iaa_sys->Draw("PSAME");
4728       legend->AddEntry(rhic_iaa, Form("PHENIX I_{AA} %s 9-12 GeV %s%%/pp", (i == 0) ? "Near" : "Away", (central) ? "0-20" : "20-60"), "P");
4729     }
4730   }
4731   
4732   legend->Draw();
4733   
4734   c->SaveAs("iaa.png");
4735 }
4736
4737 void CompareIAAICP(const char* fileName1, const char* fileName2, Int_t nominatorBin, Int_t denominatorBin, Bool_t skipAway = kFALSE)
4738 {
4739   Int_t j = 1;
4740   Int_t caseId = 18;
4741 //   caseId = 23; Printf("WARNING: Comparing case 23");
4742   //Int_t caseId = 12;
4743
4744   nearSide1 = GetRatio(fileName1, nominatorBin, denominatorBin, j, caseId, 0);
4745   if (!skipAway)
4746     awaySide1 = GetRatio(fileName1, nominatorBin, denominatorBin, j, caseId, 1);
4747   else
4748     awaySide1 = new TGraphErrors;
4749   
4750   kPythiaScalingFactor = 1;
4751   nearSide2 = GetRatio(fileName2, nominatorBin, denominatorBin, j, caseId, 0);
4752   if (!skipAway)
4753     awaySide2 = GetRatio(fileName2, nominatorBin, denominatorBin, j, caseId, 1);
4754   else
4755     awaySide2 = new TGraphErrors;
4756   
4757 //   Printf("\n\n\nWARNING !!! Fudging different away side acceptance (only for second file)\n\n\n");
4758 //   ScaleGraph(awaySide2, 1.56);
4759   
4760 /*  ScaleGraph(nearSide2, 1.33);
4761   ScaleGraph(awaySide2, 1.33);*/
4762   
4763   c = new TCanvas;
4764   dummy = new TH2F("dummy", Form(";p_{T,assoc};%s", (denominatorBin == 3) ? "I_{AA}" : "I_{CP}"), 100, 2, 12, 1000, 0, 10);
4765   dummy->SetStats(0);
4766   currentDummy = dummy->DrawCopy();
4767   currentDummy->GetYaxis()->SetRangeUser(0, 2.5);
4768   
4769   nearSide1->SetMarkerStyle(21);
4770   nearSide1->SetLineColor(1);
4771   nearSide1->SetMarkerColor(1);
4772           
4773   nearSide2->SetMarkerStyle(21);
4774   nearSide2->SetLineColor(2);
4775   nearSide2->SetMarkerColor(2);
4776   
4777   awaySide1->SetMarkerStyle(25);
4778   awaySide1->SetLineColor(1);
4779   awaySide1->SetMarkerColor(1);
4780   
4781   awaySide2->SetMarkerStyle(25);
4782   awaySide2->SetLineColor(2);
4783   awaySide2->SetMarkerColor(2);
4784   
4785   RemovePointsBelowX(nearSide1, 3);
4786   RemovePointsBelowX(nearSide2, 3);
4787   RemovePointsBelowX(awaySide1, 3);
4788   RemovePointsBelowX(awaySide2, 3);
4789   
4790   gPad->SetGridx();
4791   gPad->SetGridy();
4792   
4793   nearSide1->DrawClone("PSAME");
4794   awaySide1->DrawClone("PSAME");        
4795   nearSide2->DrawClone("PSAME");
4796   awaySide2->DrawClone("PSAME");        
4797   
4798   new TCanvas;
4799   currentDummy = dummy->DrawCopy();
4800   currentDummy->GetYaxis()->SetRangeUser(0.5, 1.5);
4801   gPad->SetGridx();
4802   gPad->SetGridy();
4803   
4804   DivideGraphs(nearSide1, nearSide2);
4805   DivideGraphs(awaySide1, awaySide2);
4806   
4807   nearSide1->Draw("PSAME");
4808   awaySide1->Draw("PSAME");        
4809   
4810   nearSide1->Fit("pol0", "", "SAME", 3.01, 9.99);
4811   awaySide1->Fit("pol0", "", "SAME", 3.01, 9.99);
4812 }
4813
4814 void ScaleGraph(TGraphErrors* graph, Float_t factor)
4815 {
4816         for (Int_t i=0; i<graph->GetN(); i++)
4817         {
4818     graph->GetY()[i] *= factor;
4819     graph->GetEY()[i] *= factor;
4820   }
4821 }
4822
4823 TGraphErrors* DrawBaselines(const char* fileName, Int_t numeratorBin, Int_t denominatorBin, Int_t side, Bool_t verbose = kTRUE)
4824 {
4825   Int_t j = 1;
4826   
4827   TGraphErrors* first = 0;
4828   TGraphErrors* max = 0;
4829   
4830   if (verbose)
4831   {
4832     c = new TCanvas;
4833     dummy = new TH2F("dummy", Form(";p_{T,assoc};%s", (denominatorBin == 3) ? "I_{AA}" : "I_{CP}"), 100, 0, 12, 1000, 0, 10);
4834     dummy->SetStats(0);
4835     currentDummy = dummy->DrawCopy();
4836     currentDummy->GetYaxis()->SetRangeUser(0, 3);
4837     
4838     c2 = new TCanvas;
4839     currentDummy = dummy->DrawCopy();
4840     currentDummy->GetYaxis()->SetRangeUser(0, 2);
4841   }
4842   
4843 //   Int_t caseList[] = { 18, 19, 21, 22 };
4844   //Int_t caseList[] = { 23, 24, 26, 27 };
4845   Int_t caseList[] = { 18, 19, 22 };
4846   
4847   for (Int_t caseId = 0; caseId < 3; caseId++)
4848   {
4849     graph = GetRatio(fileName, numeratorBin, denominatorBin, j, caseList[caseId], side);
4850     
4851     graph->SetLineColor(caseId + 1);
4852     graph->SetMarkerColor(caseId + 1);
4853     
4854     RemovePointsBelowX(graph, 3);
4855     
4856     if (verbose)
4857     {
4858       c->cd();
4859       graph->DrawClone("*SAME");
4860     }
4861     
4862     if (!first)
4863     {
4864       first = graph;
4865       max = (TGraphErrors*) graph->Clone();
4866       for (Int_t i=0; i<max->GetN(); i++)
4867       {
4868         max->GetY()[i] = 0;
4869         max->GetEY()[i] = 0;
4870       }
4871     }
4872     else
4873     {
4874       DivideGraphs(graph, first);
4875       
4876       if (verbose)
4877       {
4878         c2->cd();
4879         graph->DrawClone("*SAME");
4880       }
4881       
4882       for (Int_t i=0; i<graph->GetN(); i++)
4883       {
4884         if (max->GetY()[i] < TMath::Abs(graph->GetY()[i] - 1))
4885           max->GetY()[i] = TMath::Abs(graph->GetY()[i] - 1);
4886       }
4887     }
4888   }
4889   
4890   if (verbose)
4891   {
4892     new TCanvas;
4893     max->Draw("A*");
4894   }
4895   
4896   max->GetXaxis()->SetTitle("p_{T, assoc}");
4897   max->GetYaxis()->SetTitle((denominatorBin == 3) ? "Effect on I_{AA}" : "Effect on I_{CP}");
4898   max->GetYaxis()->SetRangeUser(0, 0.4);
4899   
4900   return max;
4901 }
4902
4903 void DrawBaselinesAll(const char* fileName)
4904 {
4905   c = new TCanvas("c", "c", 1000, 600);
4906   c->Divide(4, 2);
4907   
4908   for (Int_t i=0; i<2; i++)
4909   {
4910     c->cd(1+i*4); DrawBaselines(fileName, 0, 3, i, kFALSE)->Draw("A*"); gPad->SetGridy();
4911     c->cd(2+i*4); DrawBaselines(fileName, 1, 3, i, kFALSE)->Draw("A*"); gPad->SetGridy();
4912     c->cd(3+i*4); DrawBaselines(fileName, 2, 3, i, kFALSE)->Draw("A*"); gPad->SetGridy();
4913     c->cd(4+i*4); DrawBaselines(fileName, 0, 2, i, kFALSE)->Draw("A*"); gPad->SetGridy();
4914   }
4915 }
4916
4917 TGraphErrors* DrawSystUncIAAPYTHIA(TGraphErrors* graph, Int_t iaa_icp, Int_t awaySide)
4918 {
4919   // iaa = 0, icp = 1
4920
4921   Float_t baseline = 1;
4922   if (awaySide == 0)
4923     baseline = 0.07;
4924   else if (awaySide == 1)
4925     baseline = 0.2;
4926     
4927   /*
4928   Float_t reference = 0;
4929   if (iaa_icp == 0)
4930     reference = 0.13;
4931   */
4932     
4933   Float_t efficiency = 0.08;
4934   
4935   Float_t centrality = 1;
4936   if (iaa_icp == 0)
4937     centrality = (awaySide == 0) ? 0.02 : 0.06;
4938   else if (iaa_icp == 1)
4939     centrality = (awaySide == 0) ? 0.04 : 0.08;
4940   
4941   Float_t ptResolution = 0;
4942   
4943   Float_t total = TMath::Sqrt(baseline * baseline + efficiency * efficiency + centrality * centrality + ptResolution * ptResolution);
4944   
4945   Printf("Total syst: %f", total);
4946   
4947   systUnc = (TGraphErrors*) graph->Clone();
4948   for (Int_t i=0; i<systUnc->GetN(); i++)
4949   {
4950     systUnc->GetEY()[i] = systUnc->GetY()[i] * total;
4951     systUnc->GetEX()[i] = 0;
4952   }
4953     
4954   //systUnc->Print();
4955   
4956   systUnc->SetLineColor(kGray + 1);
4957   systUnc->SetLineWidth(6);
4958   
4959   systUnc->Draw("PSAME");
4960     
4961   return systUnc;
4962 }
4963
4964 TGraphErrors* DrawSystUncPreliminaries(TGraphErrors* graph, Int_t iaa_icp, Int_t awaySide, Int_t iaa, Bool_t central)
4965 {
4966   // iaa = 0, icp = 1
4967
4968   Float_t baseline = 1;
4969   if (awaySide == 0)
4970     baseline = 0.05;
4971   else if (awaySide == 1)
4972   {
4973     if (iaa == 0 && central || iaa == 1)
4974       baseline = 0.2;
4975     else if (iaa == 0 && !central)
4976       baseline = 0.05;
4977     else if (iaa == 2 && central)
4978       baseline = 0.1;
4979   }
4980     
4981   /*
4982   Float_t reference = 0;
4983   if (iaa_icp == 0)
4984     reference = 0.13;
4985   */
4986     
4987   Float_t efficiency = 0.08;
4988   if (iaa_icp == 1)
4989     efficiency = 0.05;
4990   
4991   Float_t centrality = 1;
4992   if (iaa_icp == 0)
4993     centrality = 0.04;
4994   else if (iaa_icp == 1)
4995     centrality = 0.06;
4996   
4997   Float_t ptResolution = 0.03;
4998   
4999   Float_t integrationWindow = 0;
5000   if (awaySide == 1)
5001     integrationWindow = 0.03;
5002   
5003   Float_t total = TMath::Sqrt(baseline * baseline + efficiency * efficiency + centrality * centrality + ptResolution * ptResolution + integrationWindow * integrationWindow);
5004   
5005   Printf("Total syst: %f", total);
5006   
5007   systUnc = (TGraphErrors*) graph->Clone();
5008   for (Int_t i=0; i<systUnc->GetN(); i++)
5009   {
5010     systUnc->GetEY()[i] = systUnc->GetY()[i] * total;
5011     systUnc->GetEX()[i] = 0;
5012   }
5013     
5014   //systUnc->Print();
5015   
5016   systUnc->SetLineColor(kGray + 1);
5017   systUnc->SetLineWidth(6);
5018   
5019   systUnc->Draw("PSAME");
5020     
5021   return systUnc;
5022 }
5023
5024 TGraphErrors* DrawSystUnc(TGraphErrors* graph, Int_t iaa_icp, Int_t awaySide, Int_t iaa, Bool_t central, Float_t shift = 0.0)
5025 {
5026   // iaa_icp: iaa = 0, icp = 1
5027
5028   Float_t baseline = 1;
5029   if (awaySide == 0)
5030     baseline = 0.05;
5031   else if (awaySide == 1)
5032   {
5033     if (iaa == 0 && central || iaa == 1)
5034       baseline = 0.2;
5035     else if (iaa == 0 && !central)
5036       baseline = 0.05;
5037     else if (iaa == 2 && central)
5038       baseline = 0.1;
5039   }
5040     
5041   /*
5042   Float_t reference = 0;
5043   if (iaa_icp == 0)
5044     reference = 0.13;
5045   */
5046     
5047   Float_t efficiency = 0.04;
5048   
5049   Float_t centrality = 1;
5050   if (iaa_icp == 0)
5051     centrality = 0.02;
5052   else if (iaa_icp == 1)
5053     centrality = 0.03;
5054   
5055   Float_t ptResolution = 0;
5056   
5057   Float_t integrationWindow = 0;
5058   if (awaySide == 1)
5059     integrationWindow = 0.03;
5060   
5061   Float_t corrections = 1;
5062   if (iaa_icp == 0)
5063     corrections = 0.02;
5064   else if (iaa_icp == 1)
5065     corrections = 0.01;
5066   
5067   Float_t twoTrack = 0.01;
5068   
5069   Float_t total = TMath::Sqrt(baseline * baseline + efficiency * efficiency + centrality * centrality + ptResolution * ptResolution + integrationWindow * integrationWindow + corrections * corrections + twoTrack * twoTrack);
5070   
5071   Printf("%f %f %f %f %f %f %f --> Total syst: %f", baseline, efficiency, centrality, ptResolution, integrationWindow, corrections, twoTrack, total);
5072   
5073   systUnc = (TGraphErrors*) graph->Clone();
5074   for (Int_t i=0; i<systUnc->GetN(); i++)
5075   {
5076     systUnc->GetEY()[i] = systUnc->GetY()[i] * total;
5077     systUnc->GetEX()[i] = 0;
5078     Printf("pt = %.2f  y = %.2f +- %.2f (stat.) +- %.2f (syst.)", graph->GetX()[i] - shift, graph->GetY()[i], graph->GetEY()[i], systUnc->GetEY()[i]);
5079   }
5080     
5081   //systUnc->Print();
5082   
5083   systUnc->SetLineColor(kGray + 1);
5084   systUnc->SetLineWidth(4);
5085   
5086   systUnc->Draw("PSAME e2");
5087     
5088   return systUnc;
5089 }
5090
5091 void IAA(const char* fileName, Int_t iaa, const char* fileNameEtaGap = 0)
5092 {
5093   // iaa
5094   // 0 = IAA LHC
5095   // 1 = ICP
5096   // 2 = IAA RHIC
5097   // 3 = IAA LHC with theory
5098   
5099   Bool_t showTheory = 0;
5100   Bool_t showSTAR = 0;
5101
5102   if (iaa == 3)
5103   {
5104     showTheory = kTRUE;
5105     iaa = 0;
5106   }
5107   
5108   if (iaa == 4)
5109   {
5110     showSTAR = kTRUE;
5111     iaa = 0;
5112   }
5113   
5114   if (kPythiaScalingFactor != 1)
5115     Printf("Using reference data scaling factor: %f", kPythiaScalingFactor);
5116
5117   style();
5118   
5119   Int_t j = 1;
5120   Int_t caseId[] = { 18, 23 };
5121
5122   c = new TCanvas((iaa != 1) ? ((iaa == 0) ? "iaa" : "iaarhic") : "icp", (iaa != 1) ? ((iaa == 0) ? "iaa" : "iaarhic") : "icp", 900, 450);
5123   c->Range(0, 0, 1, 1);
5124
5125   TPad* pad1 = new TPad(Form("%s_2", fileName), "", 0, 0, 0.5, 1);
5126   pad1->Draw();
5127
5128   TPad* pad2 = new TPad(Form("%s_1", fileName), "", 0.5, 0, 1, 1);
5129   pad2->Draw();
5130   
5131   pad1->cd();
5132   gPad->SetRightMargin(0);
5133   gPad->SetTopMargin(0.05);
5134   gPad->SetLeftMargin(0.13);
5135   //gPad->SetGridx();
5136 //   gPad->SetGridy();
5137   
5138   pad2->cd();
5139   gPad->SetLeftMargin(0);
5140   gPad->SetTopMargin(0.05);
5141   gPad->SetRightMargin(0.13);
5142   //gPad->SetGridx();
5143 //   gPad->SetGridy();
5144   
5145   pad1->cd();
5146 //   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);
5147   dummy = new TH2F("dummy", Form(";p_{T,assoc} (GeV/#font[12]{c});%s", (iaa != 1) ? "I_{AA}" : "I_{CP}"), 100, 1.5, 10.5, 1000, 0, 2.4);
5148   dummy->SetStats(0);
5149 //   dummy->GetYaxis()->SetTitleOffset(1.3);
5150   dummy->GetXaxis()->SetTitleOffset(1.1);
5151   currentDummy = dummy->DrawCopy();
5152   
5153   gStyle->SetTextAlign(13);
5154   
5155   latex = new TLatex(0.17, 0.90, "Near-side_{ }");
5156   latex->SetTextSize(0.04);
5157   latex->SetNDC();
5158   latex->Draw();
5159   
5160 //   if (iaa != 1)
5161 //   {
5162 //     box = new TBox(2, 0.87, 2.5, 1.13);
5163 //     box->SetFillColor(kGray + 1);
5164 //     box->SetLineColor(kGray + 1);
5165 //     box->Draw();
5166 //   
5167 //     box2 = new TBox(2, 0.87 * 1.5, 2.5, 1.13 * 1.5);
5168 //     box2->SetFillColor(kGray + 1);
5169 //     box2->SetLineColor(kGray + 1);
5170 //     box2->Draw();
5171 //   }
5172   
5173   pad2->cd();
5174   currentDummy = dummy->DrawCopy();
5175   
5176 /*  if (iaa != 1)
5177     box->Draw();*/
5178   
5179   latex = new TLatex(0.05, 0.90, "Away-side");
5180   latex->SetTextSize(0.04);
5181   latex->SetNDC();
5182   latex->Draw();
5183   
5184   legend = new TLegend(0.27, (showTheory) ? 0.60 : 0.62, (iaa != 2 && !showSTAR) ? 0.63 : 0.95, 0.77);
5185   legend->SetFillColor(0);
5186   legend->SetBorderSize(0);
5187   legend->SetTextSize((iaa != 2) ? 0.04 : 0.035);
5188   
5189   for (Int_t i=0; i<2; i++)
5190   {
5191     nearSideCentral    = GetRatio(fileName, (iaa != 2) ? 0 : 1, (iaa != 1) ? 3 : 2, j, caseId[i], 0);
5192     if (iaa == 0)
5193       nearSidePeripheral = GetRatio(fileName, 2, 3, j, caseId[i], 0);
5194     awaySideCentral    = GetRatio(fileName, (iaa != 2) ? 0 : 1, (iaa != 1) ? 3 : 2, j, caseId[i], 1);
5195     if (iaa == 0)
5196       awaySidePeripheral = GetRatio(fileName, 2, 3, j, caseId[i], 1);
5197     
5198     RemovePointsBelowX(nearSideCentral, 3);
5199     RemovePointsBelowX(awaySideCentral, 3);
5200     RemovePointsAboveX(nearSideCentral, 10);
5201     RemovePointsAboveX(awaySideCentral, 10);
5202     
5203     RemoveXErrors(nearSideCentral); RemoveXErrors(awaySideCentral);
5204     
5205     if (iaa == 0)
5206     {
5207       RemovePointsBelowX(nearSidePeripheral, 3);
5208       RemovePointsBelowX(awaySidePeripheral, 3);
5209       RemovePointsAboveX(nearSidePeripheral, 10);
5210       RemovePointsAboveX(awaySidePeripheral, 10);
5211       ShiftPoints(nearSidePeripheral, 0.2);
5212       ShiftPoints(awaySidePeripheral, 0.2);
5213       RemoveXErrors(nearSidePeripheral); RemoveXErrors(awaySidePeripheral);
5214     }
5215     
5216     nearSideCentral->SetMarkerStyle(21);
5217     nearSideCentral->SetLineColor(1);
5218     nearSideCentral->SetMarkerColor(1);
5219             
5220     awaySideCentral->SetMarkerStyle(21);
5221     awaySideCentral->SetLineColor(1);
5222     awaySideCentral->SetMarkerColor(1);
5223     
5224     if (showTheory)
5225     {
5226       nearSideCentral->SetLineColor(2);
5227       nearSideCentral->SetMarkerColor(2);
5228       awaySideCentral->SetLineColor(2);
5229       awaySideCentral->SetMarkerColor(2);
5230     }
5231     
5232     if (iaa == 0)
5233     {
5234       nearSidePeripheral->SetMarkerStyle(22);
5235       nearSidePeripheral->SetLineColor(2);
5236       nearSidePeripheral->SetMarkerColor(2);
5237       
5238       awaySidePeripheral->SetMarkerStyle(22);
5239       awaySidePeripheral->SetLineColor(2);
5240       awaySidePeripheral->SetMarkerColor(2);
5241     }
5242     
5243     if (i == 0)
5244     {
5245 //       TString denominatorStr("Pythia");
5246       TString denominatorStr("pp");
5247       if (iaa == 0)
5248       {
5249         legend->AddEntry(nearSideCentral, Form("%s0-5% / %s", (showSTAR) ? "ALICE Pb-Pb 2.76 TeV " : "", denominatorStr.Data()), "P");
5250         if (!showTheory)
5251           legend->AddEntry(nearSidePeripheral, Form("%s60-90% / %s", (showSTAR) ? "ALICE Pb-Pb 2.76 TeV " : "", denominatorStr.Data()), "P");
5252       }
5253       else if (iaa == 2)
5254       {
5255 //         legend->AddEntry(nearSideCentral, Form("0-20% / %s", denominatorStr.Data()), "P");
5256         legend->AddEntry(nearSideCentral, Form("ALICE 8 GeV/#font[12]{c} < p_{T,trig} < 15 GeV/#font[12]{c}", denominatorStr.Data()), "P");
5257       }
5258     }
5259     
5260     
5261     const char* style = "PSAME";
5262     if (i == 1)
5263       style = "LSAMEX";
5264     
5265     awaySideCentral->Print();
5266     
5267     pad1->cd();
5268     if (i == 0)
5269       DrawSystUnc(nearSideCentral, (iaa == 1), 0, iaa, kTRUE);
5270     nearSideCentral->DrawClone(style);
5271     if (iaa == 0 && !showTheory)
5272     {
5273       if (i == 0)
5274         DrawSystUnc(nearSidePeripheral, (iaa == 1), 0, iaa, kFALSE);
5275       nearSidePeripheral->DrawClone(style);        
5276     }
5277     
5278     pad2->cd();
5279     if (i == 0)
5280       DrawSystUnc(awaySideCentral, (iaa == 1), 1, iaa, kTRUE);
5281     awaySideCentral->DrawClone(style);
5282     if (iaa == 0 && !showTheory)
5283     {
5284       if (i == 0)
5285         DrawSystUnc(awaySidePeripheral, (iaa == 1), 1, iaa, kFALSE);
5286       awaySidePeripheral->DrawClone(style);        
5287     }
5288   }
5289   
5290   if (fileNameEtaGap)
5291   {
5292     pad1->cd();
5293     
5294     nearSideEtaGapCentral = GetRatio(fileNameEtaGap, (iaa != 2) ? 0 : 1, (iaa != 1) ? 3 : 2, j, caseId[0], 0);
5295     RemovePointsBelowX(nearSideEtaGapCentral, 3);
5296     RemovePointsAboveX(nearSideEtaGapCentral, 10);
5297     RemoveXErrors(nearSideEtaGapCentral); 
5298     nearSideEtaGapCentral->SetMarkerStyle(25);
5299     nearSideEtaGapCentral->SetLineColor(1);
5300     nearSideEtaGapCentral->SetMarkerColor(1);
5301     nearSideEtaGapCentral->Draw("PSAME");
5302
5303     if (iaa != 1)
5304     {
5305       nearSideEtaGapPeripheral = GetRatio(fileNameEtaGap, 2, 3, j, caseId[0], 0);
5306       RemovePointsBelowX(nearSideEtaGapPeripheral, 3);
5307       RemovePointsAboveX(nearSideEtaGapPeripheral, 10);
5308       RemoveXErrors(nearSideEtaGapPeripheral); 
5309       ShiftPoints(nearSideEtaGapPeripheral, 0.2);
5310       nearSideEtaGapPeripheral->SetMarkerStyle(26);
5311       nearSideEtaGapPeripheral->SetLineColor(2);
5312       nearSideEtaGapPeripheral->SetMarkerColor(2);
5313       nearSideEtaGapPeripheral->Draw("PSAME");
5314     }
5315   }
5316   
5317   if (iaa == 2)
5318   {
5319     // IAA, RHIC, PHENIX
5320     // systematic uncertainty stored in graph with _sys appended
5321     TFile::Open("rhic/pi0h_graphs.root");
5322     
5323     legend2 = new TLegend(0.5, 0.16, 0.96, 0.27);
5324     legend2->SetFillColor(0);
5325     
5326     for (Int_t ptTrigBin=2; ptTrigBin<4; ptTrigBin++)
5327     {
5328       Bool_t central = kTRUE;
5329       for (Int_t i=0; i<3; i+=2)
5330       {
5331         // gIAA_<ptTrigBin>_<centBin>_<angularRegionBin>
5332         rhic_iaa = (TGraphErrors*) gFile->Get(Form("gIAA_%d_%d_%d", ptTrigBin, (central) ? 0 : 1, i));
5333         rhic_iaa_sys = (TGraphErrors*) gFile->Get(Form("gIAA_%d_%d_%d_sys", ptTrigBin, (central) ? 0 : 1, i));
5334     
5335         rhic_iaa->SetMarkerStyle((ptTrigBin == 2) ? 20 : 33);
5336         rhic_iaa->SetMarkerColor(2);
5337         rhic_iaa->SetLineColor(2);
5338         rhic_iaa_sys->SetLineColor(2);
5339         rhic_iaa_sys->SetMarkerColor(2);
5340         
5341         RemovePointsBelowX(rhic_iaa, 2);
5342         RemovePointsBelowX(rhic_iaa_sys, 2);
5343         
5344         Printf("RHIC:");
5345         rhic_iaa->Print();
5346         rhic_iaa_sys->Print();
5347         
5348         ShiftPoints(rhic_iaa, -0.05 + 0.05 * (ptTrigBin*2-4));
5349         ShiftPoints(rhic_iaa_sys, -0.05 + 0.05 * (ptTrigBin*2-4));
5350         
5351         if (i == 0)
5352           pad1->cd();
5353         else if (i == 2)
5354           pad2->cd();
5355         rhic_iaa->Draw("PSAME");
5356         rhic_iaa_sys->Draw("PSAME");
5357         
5358         if (i == 0)
5359           legend->AddEntry(rhic_iaa, Form("PHENIX %s GeV/c < p_{T,trig} < %s GeV/c", (ptTrigBin == 2) ? "7" : "9", (ptTrigBin == 2) ? "9" : "12", (central) ? "0-20" : "20-60"), "P");
5360 //           legend->AddEntry(rhic_iaa, Form("PHENIX %s GeV/c < p_{T,trig} < %s GeV/c %s%% / pp", (ptTrigBin == 2) ? "7" : "9", (ptTrigBin == 2) ? "9" : "12", (central) ? "0-20" : "20-60"), "P");
5361       }
5362     }
5363     
5364 //     pad1->cd();
5365 //     legend2->Draw();
5366   }
5367
5368   if (iaa == 0 && showSTAR)
5369   {
5370     for (Int_t i=0; i<2; i++)
5371     {
5372       const char* centralityStr = "05";
5373       if (i == 1)
5374         centralityStr = "4080";
5375       
5376       // IAA, RHIC, STAR
5377       // systematic uncertainty stored in graph with _sys appended
5378       nearSide = ReadHepdata(Form("rhic/star_iaa_%s_near.txt", centralityStr));
5379       awaySide = ReadHepdata(Form("rhic/star_iaa_%s_away.txt", centralityStr));
5380       
5381       nearSide->SetMarkerStyle(20 + i * 13);
5382       nearSide->SetMarkerColor(4);
5383       nearSide->SetLineColor(4);
5384       
5385       awaySide->SetMarkerStyle(20 + i * 13);
5386       awaySide->SetMarkerColor(4);
5387       awaySide->SetLineColor(4);
5388
5389       ShiftPoints(nearSide, -0.1 + 0.2 * i);
5390       ShiftPoints(awaySide, -0.1 + 0.2 * i);
5391           
5392       pad1->cd();
5393       nearSide->Draw("PSAME");
5394       pad2->cd();
5395       awaySide->Draw("PSAME");
5396         
5397       legend->AddEntry(nearSide, Form("STAR Au-Au 0.2 TeV %s / dAu", (i == 0) ? "0-5%" : "40-80%"), "P");
5398     }
5399   }
5400
5401   // Theory predictions
5402   if (showTheory && iaa == 0)
5403   {
5404     const char* theoryList[] = { "AdS", "ASW", "YaJEM", "YaJEM-D", "XinNian" };
5405     Int_t nTheory = 5;
5406     Int_t markers[] = { 27, 28, 29, 30, 34 };
5407     
5408     for (Int_t i=0; i<nTheory; i++)
5409     {
5410       nearSide = ReadHepdata(Form("theory/IAA_near_%s.dat", theoryList[i]));
5411       awaySide = ReadHepdata(Form("theory/IAA_away_%s.dat", theoryList[i]));
5412       
5413       nearSide->SetMarkerStyle(markers[i]);
5414       awaySide->SetMarkerStyle(markers[i]);
5415       
5416       RemovePointsBelowX(nearSide, 3);
5417       RemovePointsBelowX(awaySide, 3);
5418       
5419       Float_t shiftBy = (i % 2 == 0) ? -0.2 : 0.2;
5420       ShiftPoints(nearSide, shiftBy);
5421       ShiftPoints(awaySide, shiftBy);
5422       
5423       pad1->cd();
5424       nearSide->Draw("PSAME");
5425       
5426       pad2->cd();
5427       awaySide->Draw("PSAME");
5428       
5429       if (i == 0)
5430           theoryList[i] = "AdS/CFT";
5431       if (i == 4)
5432           theoryList[i] = "X-N Wang";
5433       legend->AddEntry(nearSide, theoryList[i], "P");
5434     }
5435   }
5436   
5437   for (Int_t i=0; i<2; i++)
5438   {
5439     if (i == 0)
5440       pad1->cd();
5441     else
5442       pad2->cd();
5443       
5444     Float_t xC = 0.05;
5445     if (i == 0)
5446       xC = 0.17;
5447
5448     if (iaa == 2)
5449       latex = new TLatex(xC, 0.84, "0-20% / pp");
5450     else
5451       latex = new TLatex(0.35+xC, 0.9, "8 GeV/#font[12]{c} < p_{T,trig} < 15 GeV/#font[12]{c}");
5452     latex->SetTextSize(0.04);
5453     latex->SetNDC();
5454     if (i == 0)
5455       latex->Draw();
5456     
5457     line = new TLine(1.5, 1, 10.5, 1);
5458     line->SetLineStyle(2);
5459     line->Draw();
5460   
5461     if (iaa == 1)
5462     {
5463       latex = new TLatex(xC, 0.84, "0-5% / 60-90%");
5464       latex->SetTextSize(0.04);
5465       latex->SetNDC();
5466       latex->Draw();
5467     }
5468   
5469     latex = new TLatex(0.65+xC, 0.90, "ALICE");
5470 //     latex = new TLatex(0.5+xC, 0.90, "-- work in progress --");
5471     latex->SetTextSize(0.04);
5472     latex->SetNDC();
5473     if (i == 1)
5474       latex->Draw();
5475     
5476     latex = new TLatex(0.35+xC, 0.84, "p_{T,assoc} < p_{T,trig}");
5477     latex->SetTextSize(0.04);
5478     latex->SetNDC();
5479     if (i == 0)
5480       latex->Draw();
5481     
5482     if (iaa == 1 || iaa == 0)
5483     {
5484       if (iaa == 0 && showSTAR)
5485         latex = new TLatex(0.3+xC, 0.90, "|#eta| < 1.0");
5486       else
5487         latex = new TLatex(xC + 0.65, 0.20, "|#eta| < 1.0");
5488       latex->SetTextSize(0.04);
5489       latex->SetNDC();
5490       if (i == 0)
5491         latex->Draw();
5492     }
5493     
5494     if (iaa == 1 || (iaa == 0 && !showSTAR))
5495     {
5496       latex = new TLatex(0.5+xC, 0.72, "Pb-Pb 2.76 TeV");
5497       latex->SetTextSize(0.04);
5498       latex->SetNDC();
5499 //       latex->Draw();
5500     }
5501     
5502     if (iaa == 2)
5503     {
5504       if (i == 0)
5505         latex = new TLatex(0.5, 0.24, "ALICE: Pb-Pb 2.76 TeV |#eta| < 1.0");
5506       else
5507         latex = new TLatex(xC, 0.6, "ALICE: Pb-Pb 2.76 TeV |#eta| < 1.0");
5508       latex->SetTextSize(0.035);
5509       latex->SetNDC();
5510       latex->Draw();
5511       
5512       if (i == 0)
5513         latex = new TLatex(0.5, 0.18, "PHENIX: Au-Au 0.2 TeV |#eta| < 0.35");
5514       else
5515         latex = new TLatex(xC, 0.54, "PHENIX: Au-Au 0.2 TeV |#eta| < 0.35");
5516       latex->SetTextSize(0.035);
5517       latex->SetNDC();
5518       latex->Draw();
5519     }
5520     
5521     if (showTheory && iaa == 0 && i == 1)
5522       latex = new TLatex(xC, 0.18, "Points: flat pedestal");
5523     else
5524       latex = new TLatex(xC + 0.5 * i, 0.26, "Points: flat pedestal");
5525     latex->SetTextSize(0.04);
5526     latex->SetNDC();
5527     if (i == 0)
5528       latex->Draw();
5529   
5530     latex = new TLatex(xC + 0.5 * i, 0.20, "Line: v_{2} subtracted");
5531     latex->SetTextSize(0.04);
5532     latex->SetNDC();
5533     if (i == 0)
5534       latex->Draw();
5535     
5536     if (iaa != 1 && i == 1)
5537     {
5538       legendClone = (TLegend*) legend->DrawClone();
5539       if (showTheory && iaa == 0 && i == 0)
5540         legendClone->GetListOfPrimitives()->RemoveLast();
5541 //       else
5542 //      legendClone->SetY1(legendClone->GetY1()-0.05);
5543         
5544       legend->SetX1(legend->GetX1()-0.12);
5545       legend->SetX2(legend->GetX2()-0.12);
5546     }
5547
5548 /*    if (i == 0 && iaa != 2)
5549       DrawALICELogo(0.83,0.15,0.98,0.30);
5550     else
5551       DrawALICELogo(0.62 + xC,0.48,0.77 + xC,0.63);*/
5552   }
5553   
5554   c->SaveAs(Form("%s.eps", c->GetTitle()));
5555   c->SaveAs(Form("%s.png", c->GetTitle()));
5556 }
5557
5558 void IAAPaper(const char* fileName, Int_t iaa, const char* fileNameEtaGap = 0)
5559 {
5560   // iaa
5561   // 0 = IAA LHC
5562   // 1 = ICP
5563   
5564   Bool_t showTheory = 0;
5565   Bool_t showSTAR = 0;
5566
5567   if (iaa == 3)
5568   {
5569     showTheory = kTRUE;
5570     iaa = 0;
5571   }
5572   
5573   if (iaa == 4)
5574   {
5575     showSTAR = kTRUE;
5576     iaa = 0;
5577   }
5578   
5579   if (kPythiaScalingFactor != 1)
5580     Printf("Using reference data scaling factor: %f", kPythiaScalingFactor);
5581
5582   style();
5583   
5584   Int_t j = 1;
5585   Int_t caseId[] = { 18, 23 };
5586
5587   c = new TCanvas((iaa != 1) ? ((iaa == 0) ? "iaa" : "iaarhic") : "icp", (iaa != 1) ? ((iaa == 0) ? "iaa" : "iaarhic") : "icp", 900, 450);
5588   c->Range(0, 0, 1, 1);
5589
5590   TPad* pad1 = new TPad(Form("%s_2", fileName), "", 0, 0, 0.5, 1);
5591   pad1->Draw();
5592
5593   TPad* pad2 = new TPad(Form("%s_1", fileName), "", 0.5, 0, 1, 1);
5594   pad2->Draw();
5595   
5596   pad1->cd();
5597   gPad->SetRightMargin(0);
5598   gPad->SetTopMargin(0.05);
5599   gPad->SetLeftMargin(0.13);
5600   //gPad->SetGridx();
5601 //   gPad->SetGridy();
5602   
5603   pad2->cd();
5604   gPad->SetLeftMargin(0);
5605   gPad->SetTopMargin(0.05);
5606   gPad->SetRightMargin(0.13);
5607   //gPad->SetGridx();
5608 //   gPad->SetGridy();
5609   
5610   pad1->cd();
5611 //   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);
5612   dummy = new TH2F("dummy", Form(";#font[12]{p}_{t,assoc} (GeV/#font[12]{c});%s", (iaa != 1) ? "#font[12]{I}_{AA}" : "#font[12]{I}_{CP} (0-5% / 60-90%)"), 100, 1.5, 10.5, 1000, 0, 2.4);
5613   dummy->SetStats(0);
5614 //   dummy->GetYaxis()->SetTitleOffset(1.3);
5615   dummy->GetXaxis()->SetTitleOffset(1.1);
5616   currentDummy = dummy->DrawCopy();
5617   
5618   gStyle->SetTextAlign(13);
5619   
5620   latex = new TLatex(0.17, 0.90, "Near-side_{ }");
5621   latex->SetTextSize(0.04);
5622   latex->SetNDC();
5623   latex->Draw();
5624   
5625   latex = new TLatex(0.17, /*(iaa == 1) ? 0.78 :*/ 0.84, "#sqrt{#font[12]{s}_{NN}} = 2.76 TeV");
5626   latex->SetTextSize(0.04);
5627   latex->SetNDC();
5628   latex->Draw();
5629
5630   latex = new TLatex(0.17, 0.2, (iaa == 1) ? "b)" : "a)");
5631   latex->SetTextSize(0.04);
5632   latex->SetNDC();
5633   latex->Draw();
5634   
5635 //   if (iaa != 1)
5636 //   {
5637 //     box = new TBox(2, 0.87, 2.5, 1.13);
5638 //     box->SetFillColor(kGray + 1);
5639 //     box->SetLineColor(kGray + 1);
5640 //     box->Draw();
5641 //   
5642 //     box2 = new TBox(2, 0.87 * 1.5, 2.5, 1.13 * 1.5);
5643 //     box2->SetFillColor(kGray + 1);
5644 //     box2->SetLineColor(kGray + 1);
5645 //     box2->Draw();
5646 //   }
5647   
5648   pad2->cd();
5649   currentDummy = dummy->DrawCopy();
5650   
5651 /*  if (iaa != 1)
5652     box->Draw();*/
5653   
5654   latex = new TLatex(0.05, 0.90, "Away-side");
5655   latex->SetTextSize(0.04);
5656   latex->SetNDC();
5657   latex->Draw();
5658
5659   if (iaa == 1)
5660     legend = new TLegend(0.22, 0.60, 0.67, 0.73);
5661   else
5662     legend = new TLegend(0.12, 0.60, 0.76, 0.79);
5663   legend->SetFillColor(0);
5664   legend->SetBorderSize(0);
5665   legend->SetTextSize((iaa != 2) ? 0.04 : 0.035);
5666   
5667   for (Int_t i=0; i<2; i++)
5668   {
5669     nearSideCentral    = GetRatio(fileName, (iaa != 2) ? 0 : 1, (iaa != 1) ? 3 : 2, j, caseId[i], 0);
5670     if (iaa == 0)
5671       nearSidePeripheral = GetRatio(fileName, 2, 3, j, caseId[i], 0);
5672     awaySideCentral    = GetRatio(fileName, (iaa != 2) ? 0 : 1, (iaa != 1) ? 3 : 2, j, caseId[i], 1);
5673     if (iaa == 0)
5674       awaySidePeripheral = GetRatio(fileName, 2, 3, j, caseId[i], 1);
5675     
5676     RemovePointsBelowX(nearSideCentral, 3);
5677     RemovePointsBelowX(awaySideCentral, 3);
5678     RemovePointsAboveX(nearSideCentral, 10);
5679     RemovePointsAboveX(awaySideCentral, 10);
5680
5681     ShiftPoints(nearSideCentral, -0.05);
5682     ShiftPoints(awaySideCentral, -0.05);
5683
5684     if (i == 1)
5685     {
5686       ShiftPoints(nearSideCentral, -0.2);
5687       ShiftPoints(awaySideCentral, -0.2);
5688       
5689       if (iaa == 0)
5690       {
5691         ShiftPoints(nearSidePeripheral, 0.2);
5692         ShiftPoints(awaySidePeripheral, 0.2);
5693       }
5694     }
5695     
5696     RemoveXErrors(nearSideCentral); RemoveXErrors(awaySideCentral);
5697     
5698     if (iaa == 0)
5699     {
5700       RemovePointsBelowX(nearSidePeripheral, 3);
5701       RemovePointsBelowX(awaySidePeripheral, 3);
5702       RemovePointsAboveX(nearSidePeripheral, 10);
5703       RemovePointsAboveX(awaySidePeripheral, 10);
5704       ShiftPoints(nearSidePeripheral, 0.05);
5705       ShiftPoints(awaySidePeripheral, 0.05);
5706       RemoveXErrors(nearSidePeripheral); RemoveXErrors(awaySidePeripheral);
5707     }
5708     
5709     nearSideCentral->SetMarkerStyle((i == 0) ? 25 : 27);
5710     nearSideCentral->SetLineColor(1);
5711     nearSideCentral->SetMarkerColor(1);
5712             
5713     awaySideCentral->SetMarkerStyle((i == 0) ? 25 : 27);
5714     awaySideCentral->SetLineColor(1);
5715     awaySideCentral->SetMarkerColor(1);
5716     
5717     if (showTheory)
5718     {
5719       nearSideCentral->SetLineColor(2);
5720       nearSideCentral->SetMarkerColor(2);
5721       awaySideCentral->SetLineColor(2);
5722       awaySideCentral->SetMarkerColor(2);
5723     }
5724     
5725     if (iaa == 0)
5726     {
5727       nearSidePeripheral->SetMarkerStyle((i == 0) ? 21 : 33);
5728       nearSidePeripheral->SetLineColor(2);
5729       nearSidePeripheral->SetMarkerColor(2);
5730       
5731       awaySidePeripheral->SetMarkerStyle((i == 0) ? 21 : 33);
5732       awaySidePeripheral->SetLineColor(2);
5733       awaySidePeripheral->SetMarkerColor(2);
5734     }
5735     
5736 //     if (i == 0)
5737     {
5738 //       TString denominatorStr("Pythia");
5739       TString denominatorStr("pp");
5740       if (iaa == 0)
5741       {
5742         legend->SetHeader("0-5% Pb-Pb/pp     60-90% Pb-Pb/pp");
5743         legend->SetNColumns(2);
5744       }
5745       legend->AddEntry(nearSideCentral, (i == 0) ? "Flat bkg" : "#font[12]{v}_{2} bkg", "P");
5746       if (iaa == 0)
5747         legend->AddEntry(nearSidePeripheral, (i == 0) ? "Flat bkg" : "#font[12]{v}_{2} bkg", "P");
5748         
5749 //         legend->AddEntry(nearSideCentral, Form("%s0-5% / %s", (showSTAR) ? "ALICE Pb-Pb 2.76 TeV " : "", denominatorStr.Data()), "P");
5750 //      if (!showTheory)
5751 //        legend->AddEntry(nearSidePeripheral, Form("%s60-90% / %s", (showSTAR) ? "ALICE Pb-Pb 2.76 TeV " : "", denominatorStr.Data()), "P");
5752       if (iaa == 2)
5753       {
5754 //         legend->AddEntry(nearSideCentral, Form("0-20% / %s", denominatorStr.Data()), "P");
5755         legend->AddEntry(nearSideCentral, Form("ALICE 8 GeV/#font[12]{c} < p_{T,trig} < 15 GeV/#font[12]{c}", denominatorStr.Data()), "P");
5756       }
5757     }
5758     
5759     
5760     const char* style = "PSAME";
5761 //     if (i == 1)
5762 //       style = "LSAMEX";
5763     
5764     pad1->cd();
5765 //     if (i == 0)
5766       DrawSystUnc(nearSideCentral, (iaa == 1), 0, iaa, kTRUE, -0.05 - 0.2 * i);
5767     nearSideCentral->DrawClone(style);
5768     if (iaa == 0 && !showTheory)
5769     {
5770 //       if (i == 0)
5771         DrawSystUnc(nearSidePeripheral, (iaa == 1), 0, iaa, kFALSE, 0.05 + ((iaa == 0) ? i * 0.2 : 0));
5772       nearSidePeripheral->DrawClone(style);        
5773     }
5774     
5775     pad2->cd();
5776 //     if (i == 0)
5777       DrawSystUnc(awaySideCentral, (iaa == 1), 1, iaa, kTRUE, -0.05 - 0.2 * i);
5778     awaySideCentral->DrawClone(style);
5779     if (iaa == 0 && !showTheory)
5780     {
5781 //       if (i == 0)
5782         DrawSystUnc(awaySidePeripheral, (iaa == 1), 1, iaa, kFALSE, 0.05 + ((iaa == 0) ? i * 0.2 : 0));
5783       awaySidePeripheral->DrawClone(style);        
5784     }
5785   }
5786   
5787   if (fileNameEtaGap)
5788   {
5789     pad1->cd();
5790     
5791     nearSideEtaGapCentral = GetRatio(fileNameEtaGap, (iaa != 2) ? 0 : 1, (iaa != 1) ? 3 : 2, j, caseId[0], 0);
5792     RemovePointsBelowX(nearSideEtaGapCentral, 3);
5793     RemovePointsAboveX(nearSideEtaGapCentral, 10);
5794     RemoveXErrors(nearSideEtaGapCentral); 
5795     nearSideEtaGapCentral->SetMarkerStyle(24);
5796     nearSideEtaGapCentral->SetLineColor(1);
5797     nearSideEtaGapCentral->SetMarkerColor(1);
5798     ShiftPoints(nearSideEtaGapCentral, -0.45);
5799     DrawSystUnc(nearSideEtaGapCentral, (iaa == 1), 0, iaa, kTRUE, -0.45);
5800     nearSideEtaGapCentral->Draw("PSAME");
5801
5802     legend->AddEntry(nearSideEtaGapCentral, "#font[12]{#eta}-gap", "P");
5803
5804
5805     if (iaa != 1)
5806     {
5807       nearSideEtaGapPeripheral = GetRatio(fileNameEtaGap, 2, 3, j, caseId[0], 0);
5808       RemovePointsBelowX(nearSideEtaGapPeripheral, 3);
5809       RemovePointsAboveX(nearSideEtaGapPeripheral, 10);
5810       RemoveXErrors(nearSideEtaGapPeripheral); 
5811       nearSideEtaGapPeripheral->SetMarkerStyle(20);
5812       nearSideEtaGapPeripheral->SetLineColor(2);
5813       nearSideEtaGapPeripheral->SetMarkerColor(2);
5814       ShiftPoints(nearSideEtaGapPeripheral, 0.45);
5815       DrawSystUnc(nearSideEtaGapPeripheral, (iaa == 1), 0, iaa, kFALSE, 0.45);
5816       nearSideEtaGapPeripheral->Draw("PSAME");
5817
5818       legend->AddEntry(nearSideEtaGapPeripheral, "#font[12]{#eta}-gap", "P");
5819     }
5820   }
5821   
5822   if (0 && iaa == 0)
5823   {
5824     // add pythia line showing gluon filtering
5825     // from Jan Rak, by mail, 22.09.11
5826     // pp CF calculated without any adjustment
5827     // AA CF also no adjustment. Particles (h+-) in acceptance are identified with their parent string parton (status 71)
5828     // and the flavor of parent hard outgoing parton (status 23) which is  the parent of string parton 71 is checked.
5829     // If it is a gluon the  particle is ignored.
5830     
5831     Float_t xVal[] = { 3.5, 4.5, 5.5, 7, 9};
5832     Float_t yVal[] = { 0.779418, 0.794234, 0.82759, 0.856457, 0.880526 };
5833     gluonfiltering = new TGraph(5, xVal, yVal);
5834     pad1->cd();
5835     gluonfiltering->Draw("L");
5836     
5837     legend3 = new TLegend(0.38, 0.15, 0.58, 0.25);
5838     legend3->SetFillColor(0);
5839     legend3->SetBorderSize(0);
5840     legend3->SetTextSize(0.04);
5841     legend3->AddEntry(gluonfiltering, "PYTHIA quark-only fragmentation", "L");
5842     legend3->Draw();
5843   }
5844   
5845   if (iaa == 2)
5846   {
5847     // IAA, RHIC, PHENIX
5848     // systematic uncertainty stored in graph with _sys appended
5849     TFile::Open("rhic/pi0h_graphs.root");
5850     
5851     legend2 = new TLegend(0.5, 0.16, 0.96, 0.27);
5852     legend2->SetFillColor(0);
5853     
5854     for (Int_t ptTrigBin=2; ptTrigBin<4; ptTrigBin++)
5855     {
5856       Bool_t central = kTRUE;
5857       for (Int_t i=0; i<3; i+=2)
5858       {
5859         // gIAA_<ptTrigBin>_<centBin>_<angularRegionBin>
5860         rhic_iaa = (TGraphErrors*) gFile->Get(Form("gIAA_%d_%d_%d", ptTrigBin, (central) ? 0 : 1, i));
5861         rhic_iaa_sys = (TGraphErrors*) gFile->Get(Form("gIAA_%d_%d_%d_sys", ptTrigBin, (central) ? 0 : 1, i));
5862     
5863         rhic_iaa->SetMarkerStyle((ptTrigBin == 2) ? 20 : 33);
5864         rhic_iaa->SetMarkerColor(2);
5865         rhic_iaa->SetLineColor(2);
5866         rhic_iaa_sys->SetLineColor(2);
5867         rhic_iaa_sys->SetMarkerColor(2);
5868         
5869         ShiftPoints(rhic_iaa, -0.05 + 0.05 * (ptTrigBin*2-4));
5870         ShiftPoints(rhic_iaa_sys, -0.05 + 0.05 * (ptTrigBin*2-4));
5871         
5872         if (i == 0)
5873           pad1->cd();
5874         else if (i == 2)
5875           pad2->cd();
5876         rhic_iaa->Draw("PSAME");
5877         rhic_iaa_sys->Draw("PSAME");
5878         
5879         if (i == 0)
5880           legend->AddEntry(rhic_iaa, Form("PHENIX %s GeV/c < p_{T,trig} < %s GeV/c", (ptTrigBin == 2) ? "7" : "9", (ptTrigBin == 2) ? "9" : "12", (central) ? "0-20" : "20-60"), "P");
5881 //           legend->AddEntry(rhic_iaa, Form("PHENIX %s GeV/c < p_{T,trig} < %s GeV/c %s%% / pp", (ptTrigBin == 2) ? "7" : "9", (ptTrigBin == 2) ? "9" : "12", (central) ? "0-20" : "20-60"), "P");
5882       }
5883     }
5884     
5885 //     pad1->cd();
5886 //     legend2->Draw();
5887   }
5888
5889   if (iaa == 0 && showSTAR)
5890   {
5891     for (Int_t i=0; i<2; i++)
5892     {
5893       const char* centralityStr = "05";
5894       if (i == 1)
5895         centralityStr = "4080";
5896       
5897       // IAA, RHIC, STAR
5898       // systematic uncertainty stored in graph with _sys appended
5899       nearSide = ReadHepdata(Form("rhic/star_iaa_%s_near.txt", centralityStr));
5900       awaySide = ReadHepdata(Form("rhic/star_iaa_%s_away.txt", centralityStr));
5901       
5902       nearSide->SetMarkerStyle(20 + i * 13);
5903       nearSide->SetMarkerColor(4);
5904       nearSide->SetLineColor(4);
5905       
5906       awaySide->SetMarkerStyle(20 + i * 13);
5907       awaySide->SetMarkerColor(4);
5908       awaySide->SetLineColor(4);
5909
5910       ShiftPoints(nearSide, -0.1 + 0.2 * i);
5911       ShiftPoints(awaySide, -0.1 + 0.2 * i);
5912           
5913       pad1->cd();
5914       nearSide->Draw("PSAME");
5915       pad2->cd();
5916       awaySide->Draw("PSAME");
5917         
5918       legend->AddEntry(nearSide, Form("STAR Au-Au 0.2 TeV %s / dAu", (i == 0) ? "0-5%" : "40-80%"), "P");
5919     }
5920   }
5921
5922   // Theory predictions
5923   if (showTheory && iaa == 0)
5924   {
5925     const char* theoryList[] = { "AdS", "ASW", "YaJEM", "YaJEM-D", "XinNian" };
5926     Int_t nTheory = 5;
5927     Int_t markers[] = { 27, 28, 29, 30, 34 };
5928     
5929     for (Int_t i=0; i<nTheory; i++)
5930     {
5931       nearSide = ReadHepdata(Form("theory/IAA_near_%s.dat", theoryList[i]));
5932       awaySide = ReadHepdata(Form("theory/IAA_away_%s.dat", theoryList[i]));
5933       
5934       nearSide->SetMarkerStyle(markers[i]);
5935       awaySide->SetMarkerStyle(markers[i]);
5936       
5937       RemovePointsBelowX(nearSide, 3);
5938       RemovePointsBelowX(awaySide, 3);
5939       
5940       Float_t shiftBy = (i % 2 == 0) ? -0.2 : 0.2;
5941       ShiftPoints(nearSide, shiftBy);
5942       ShiftPoints(awaySide, shiftBy);
5943       
5944       pad1->cd();
5945       nearSide->Draw("PSAME");
5946       
5947       pad2->cd();
5948       awaySide->Draw("PSAME");
5949       
5950       if (i == 0)
5951           theoryList[i] = "AdS/CFT";
5952       if (i == 4)
5953           theoryList[i] = "X-N Wang";
5954       legend->AddEntry(nearSide, theoryList[i], "P");
5955     }
5956   }
5957   
5958   for (Int_t i=0; i<2; i++)
5959   {
5960     if (i == 0)
5961       pad1->cd();
5962     else
5963       pad2->cd();
5964       
5965     Float_t xC = 0.05;
5966     if (i == 0)
5967       xC = 0.17;
5968
5969     if (iaa == 2)
5970       latex = new TLatex(xC, 0.84, "0-20% / pp");
5971     else
5972       latex = new TLatex(0.35+xC, 0.9, "8 GeV/#font[12]{c} < #font[12]{p}_{t,trig} < 15 GeV/#font[12]{c}");
5973     latex->SetTextSize(0.04);
5974     latex->SetNDC();
5975     if (i == 0)
5976       latex->Draw();
5977     
5978     line = new TLine(1.5, 1, 10.5, 1);
5979     line->SetLineStyle(2);
5980     line->Draw();
5981   
5982 //     if (iaa == 1 && i == 0)
5983 //     {
5984 //       latex = new TLatex(xC, 0.84, "0-5% / 60-90%");
5985 //       latex->SetTextSize(0.04);
5986 //       latex->SetNDC();
5987 //       latex->Draw();
5988 //     }
5989   
5990     latex = new TLatex(0.65+xC, 0.90, "ALICE");
5991 //     latex = new TLatex(0.5+xC, 0.90, "-- work in progress --");
5992     latex->SetTextSize(0.04);
5993     latex->SetNDC();
5994     if (i == 1)
5995       latex->Draw();
5996     
5997     latex = new TLatex(0.35+xC, 0.84, "#font[12]{p}_{t,assoc} < #font[12]{p}_{t,trig}");
5998     latex->SetTextSize(0.04);
5999     latex->SetNDC();
6000     if (i == 0)
6001       latex->Draw();
6002     
6003     if (iaa == 1 || iaa == 0)
6004     {
6005       if (iaa == 0 && showSTAR)
6006         latex = new TLatex(0.3+xC, 0.90, "|#font[12]{#eta}| < 1.0");
6007       else
6008         latex = new TLatex(0.82, 0.84, "|#font[12]{#eta}| < 1.0");
6009       latex->SetTextSize(0.04);
6010       latex->SetNDC();
6011       if (i == 0)
6012         latex->Draw();
6013     }
6014     
6015     if (iaa == 1 || (iaa == 0 && !showSTAR))
6016     {
6017       latex = new TLatex(0.5+xC, 0.72, "Pb-Pb 2.76 TeV");
6018       latex->SetTextSize(0.04);
6019       latex->SetNDC();
6020 //       latex->Draw();
6021     }
6022     
6023     if (iaa == 2)
6024     {
6025       if (i == 0)
6026         latex = new TLatex(0.5, 0.24, "ALICE: Pb-Pb 2.76 TeV |#eta| < 1.0");
6027       else
6028         latex = new TLatex(xC, 0.6, "ALICE: Pb-Pb 2.76 TeV |#eta| < 1.0");
6029       latex->SetTextSize(0.035);
6030       latex->SetNDC();
6031       latex->Draw();
6032       
6033       if (i == 0)
6034         latex = new TLatex(0.5, 0.18, "PHENIX: Au-Au 0.2 TeV |#eta| < 0.35");
6035       else
6036         latex = new TLatex(xC, 0.54, "PHENIX: Au-Au 0.2 TeV |#eta| < 0.35");
6037       latex->SetTextSize(0.035);
6038       latex->SetNDC();
6039       latex->Draw();
6040     }
6041     
6042     if (i == 1)
6043     {
6044       legendClone = (TLegend*) legend->DrawClone();
6045       if (showTheory && iaa == 0 && i == 0)
6046         legendClone->GetListOfPrimitives()->RemoveLast();
6047 //       else
6048 //      legendClone->SetY1(legendClone->GetY1()-0.05);
6049         
6050       legend->SetX1(legend->GetX1()-0.12);
6051       legend->SetX2(legend->GetX2()-0.12);
6052     }
6053     
6054     
6055
6056 /*    if (i == 0 && iaa != 2)
6057       DrawALICELogo(0.83,0.15,0.98,0.30);
6058     else
6059       DrawALICELogo(0.62 + xC,0.48,0.77 + xC,0.63);*/
6060   }
6061   
6062   c->SaveAs(Form("%s.eps", c->GetTitle()));
6063   c->SaveAs(Form("%s.png", c->GetTitle()));
6064 }
6065
6066
6067 void DrawALICELogo(Float_t x1, Float_t y1, Float_t x2, Float_t y2, Bool_t debug = kFALSE)
6068 {
6069   DrawALICELogo(kTRUE, x1, y1, x2, y2, debug);
6070 }
6071
6072 void DrawALICELogo(Bool_t prel, Float_t x1, Float_t y1, Float_t x2, Float_t y2, Bool_t debug = kFALSE)
6073 {
6074   // correct for aspect ratio of figure plus aspect ratio of pad (coordinates are NDC!)
6075 //   Printf("%d %f %d %f", gPad->GetCanvas()->GetWindowHeight(), gPad->GetHNDC(), gPad->GetCanvas()->GetWindowWidth(), gPad->GetWNDC());
6076   //x2 = x1 + (y2 - y1) * 0.891 * gPad->GetCanvas()->GetWindowHeight() * gPad->GetHNDC() / (gPad->GetWNDC() * gPad->GetCanvas()->GetWindowWidth());
6077   x2 = x1 + (y2 - y1) * (466. / 523) * gPad->GetWh() * gPad->GetHNDC() / (gPad->GetWNDC() * gPad->GetWw());
6078 //   Printf("%f %f %f %f", x1, x2, y1, y2);
6079   
6080   if (!prel)
6081     DrawLatex((x1+x2)/2, y1, 1, "09.05.12", 0.03)->SetTextAlign(23);
6082   TPad *myPadLogo = new TPad("myPadLogo", "Pad for ALICE Logo", x1, y1, x2, y2);
6083   if (debug)
6084     myPadLogo->SetFillColor(2); // color to first figure out where is the pad then comment !
6085   myPadLogo->SetLeftMargin(0);
6086   myPadLogo->SetTopMargin(0);
6087   myPadLogo->SetRightMargin(0);
6088   myPadLogo->SetBottomMargin(0);
6089   myPadLogo->Draw();
6090   myPadLogo->cd();
6091 //   TASImage *myAliceLogo = new TASImage("~/alice_logo_transparent.png");
6092   TASImage *myAliceLogo = new TASImage((prel) ? "~/alice_logo_preliminary.eps" : "~/alice_logo_performance.eps");
6093   myAliceLogo->Draw();
6094 }
6095
6096 void RemoveXErrors(TGraphErrors* graph)
6097 {
6098         for (Int_t i=0; i<graph->GetN(); i++)
6099                 graph->GetEX()[i] = 0;
6100 }
6101
6102 void RemovePointsBelowX(TGraphErrors* graph, Float_t minX)
6103 {
6104   Int_t i=0;
6105   while (i<graph->GetN())
6106   {
6107     if (graph->GetX()[i] < minX)
6108       graph->RemovePoint(i);
6109     else
6110       i++;
6111   }
6112 }
6113
6114 void RemovePointsAboveX(TGraphErrors* graph, Float_t maxX)
6115 {
6116   Int_t i=0;
6117   while (i<graph->GetN())
6118   {
6119     if (graph->GetX()[i] > maxX)
6120       graph->RemovePoint(i);
6121     else
6122       i++;
6123   }
6124 }
6125
6126 void ShiftPoints(TGraphErrors* graph, Float_t dx)
6127 {
6128   Int_t i=0;
6129   while (i<graph->GetN())
6130   {
6131     graph->GetX()[i] += dx;
6132     i++;
6133   }
6134 }
6135
6136 void DivideGraphs(TGraphErrors* graph1, TGraphErrors* graph2)
6137 {
6138   graph1->Print();
6139   graph2->Print();
6140
6141   for (Int_t bin1 = 0; bin1 < graph1->GetN(); bin1++)
6142   {
6143     Float_t x = graph1->GetX()[bin1];
6144
6145     Int_t bin2 = 0;
6146     for (bin2 = 0; bin2<graph2->GetN(); bin2++)
6147       if (graph2->GetX()[bin2] >= x)
6148         break;
6149
6150     if (bin2 == graph2->GetN())
6151             bin2--;
6152
6153     if (bin2 > 0)
6154       if (TMath::Abs(graph2->GetX()[bin2-1] - x) < TMath::Abs(graph2->GetX()[bin2] - x))
6155         bin2--;
6156
6157     if (graph1->GetY()[bin1] == 0 || graph2->GetY()[bin2] == 0 || bin2 == graph2->GetN())
6158     {
6159       Printf("%d %d removed", bin1, bin2);
6160       graph1->RemovePoint(bin1--);
6161       continue;
6162     }
6163
6164     Float_t graph2Extrapolated = graph2->GetY()[bin2];
6165     if (TMath::Abs(x - graph2->GetX()[bin2]) > 0.0001)
6166     {
6167       Printf("%f %f %d %d not found", x, graph2->GetX()[bin2], bin1, bin2);
6168       graph1->RemovePoint(bin1--);
6169       continue;
6170     }
6171
6172     Float_t value = graph1->GetY()[bin1] / graph2Extrapolated;
6173     Float_t error = value * TMath::Sqrt(TMath::Power(graph1->GetEY()[bin1] / graph1->GetY()[bin1], 2) + TMath::Power(graph2->GetEY()[bin2] / graph2->GetY()[bin2], 2));
6174
6175     graph1->GetY()[bin1] = value;
6176     graph1->GetEY()[bin1] = error;
6177
6178     Printf("%d %d %f %f %f %f", bin1, bin2, x, graph2Extrapolated, value, error);
6179   }
6180 }
6181
6182 Float_t ExtractYields(TH1* hist, Int_t trigId, Int_t centralityId, Float_t ptA, Float_t ptW, Int_t caseId, Double_t normUnc)
6183 {
6184   CreateYieldStructure();
6185
6186   Float_t width = 0.69;
6187 //   Float_t width = 0.5; Printf("WARNING. Using integration width 0.5");
6188 //   Float_t width = 0.85; Printf("WARNING. Using integration width 0.85");
6189   
6190   //new TCanvas; hist->DrawCopy();
6191   
6192   Int_t binBegin = hist->FindBin(-width);
6193   Int_t binEnd = hist->FindBin(width);
6194   Double_t nearSideError = 0;
6195   Float_t nearSideYield = hist->IntegralAndError(binBegin, binEnd, nearSideError);
6196   nearSideYield *= hist->GetXaxis()->GetBinWidth(1);
6197   nearSideError *= hist->GetXaxis()->GetBinWidth(1);
6198
6199   Int_t binBegin = hist->FindBin(TMath::Pi() - width);
6200   Int_t binEnd = hist->FindBin(TMath::Pi() + width);
6201   Double_t awaySideError = 0;
6202   Float_t awaySideYield = hist->IntegralAndError(binBegin, binEnd, awaySideError);
6203   awaySideYield *= hist->GetXaxis()->GetBinWidth(1);
6204   awaySideError *= hist->GetXaxis()->GetBinWidth(1);
6205   
6206   Printf("%d %d %f %d: %f+-%f %f+-%f (%f)", trigId, centralityId, ptA, caseId, nearSideYield, nearSideError, awaySideYield, awaySideError, normUnc);
6207   
6208   FillYield(trigId, centralityId, ptA, ptW, caseId, nearSideYield, TMath::Sqrt(nearSideError * nearSideError + normUnc * normUnc), awaySideYield, TMath::Sqrt(awaySideError * awaySideError + normUnc * normUnc));
6209   
6210   // store normUnc for error propagation later
6211   TGraphErrors** tmp = yields[2][trigId][centralityId];
6212   tmp[caseId]->SetPoint(tmp[caseId]->GetN(), ptA, normUnc);
6213   
6214   return awaySideYield;
6215 }
6216
6217 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)
6218 {
6219   // CINT limitation here
6220   TGraphErrors** tmp = yields[0][trigId][centralityId];
6221   tmp[caseId]->SetPoint(tmp[caseId]->GetN(), ptA, nearSideYield);
6222   tmp[caseId]->SetPointError(tmp[caseId]->GetN()-1, ptW, nearSideError);
6223   //tmp[caseId]->Print();
6224   
6225   tmp = yields[1][trigId][centralityId];
6226   tmp[caseId]->SetPoint(tmp[caseId]->GetN(), ptA, awaySideYield);
6227   tmp[caseId]->SetPointError(tmp[caseId]->GetN()-1, ptW, awaySideError);
6228 }
6229
6230 Double_t hypgeo(Double_t a, Double_t b, Double_t c, Double_t z)
6231 {
6232   // ROOT::Math::hyperg is only defined for |z| < 1
6233   if (z > -1)
6234     return ROOT::Math::hyperg(a, b, c, z);
6235     
6236   // for z < -1 we can use an identity from http://en.wikipedia.org/wiki/Hypergeometric_function
6237   return TMath::Power(1-z, -b) * ROOT::Math::hyperg(c-a, b, c, z / (z-1));
6238 }
6239
6240 Double_t hypgeoder2(Double_t a, Double_t b, Double_t c, Double_t z)
6241 {
6242   // derivate of hypgeo with parameter b: d/db hypgeo
6243   
6244   static TF1* func = 0;
6245   if (!func)
6246     func = new TF1("hypgeoder2_func", "hypgeo([0], x, [1], [2])");
6247   
6248   func->SetParameters(a, c, z);
6249   return func->Derivative(b);
6250 }
6251
6252 void TsallisYieldUncertainty(Double_t n, Double_t q, Double_t beta, TMatrixDSym covMatrix, Int_t offset, Double_t& yield, Double_t& unc)
6253 {
6254   gSystem->Load("libMathMore");
6255
6256   TF1 tsallis("tsallis", "[0] * (1-[2]*(1-[1])*x*x)**(1/(1-[1]))", -0.5 * TMath::Pi(), 1.5 * TMath::Pi());
6257
6258   // 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]
6259   // [0] = n, [1] = q, [2] = beta
6260   TF1 tsallisIntegral("tsallisIntegral",               "[0]*x*hypgeo(0.5, 1/([1]-1), 1.5, -[2]*([1]-1)*x*x)");
6261   TF1 tsallisIntegralDerN("tsallisIntegralDerN",           "x*hypgeo(0.5, 1/([1]-1), 1.5, -[2]*([1]-1)*x*x)");
6262   
6263   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)");
6264   
6265   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]");
6266   
6267   const Float_t width = 0.7;
6268   
6269   TF1* derivates[4];
6270   derivates[0] = new TF1("const", "1");
6271   derivates[1] = &tsallisIntegralDerN;
6272   derivates[2] = &tsallisIntegralDerq;
6273   derivates[3] = &tsallisIntegralDerbeta;
6274   
6275   Printf("%f %f %f", n, q, beta);
6276   
6277   tsallis.SetParameters(n, q, beta);
6278   tsallisIntegral.SetParameters(n, q, beta);
6279   for (Int_t i=1; i<4; i++)
6280     derivates[i]->SetParameters(n, q, beta);
6281   
6282   yield = tsallisIntegral.Eval(width) - tsallisIntegral.Eval(-width);
6283   Double_t yield2 = tsallis.Integral(-width, width);
6284   
6285   unc = 0;
6286   for (Int_t i=0; i<4; i++)
6287     for (Int_t j=0; j<4; j++)
6288     {
6289       Int_t covI = i;
6290       Int_t covJ = j;
6291       if (i > 0)
6292         covI += offset;
6293       if (j > 0)
6294         covJ += offset;
6295         
6296       Double_t der1 = (derivates[i]->Eval(width) - derivates[i]->Eval(-width));
6297       Double_t der2 = (derivates[j]->Eval(width) - derivates[j]->Eval(-width));
6298         
6299       unc += der1 * der2 * covMatrix(covI, covJ);
6300       
6301       Printf("%d %d % .3e % .3e % .3e % .3e", i, j, der1, der2, covMatrix(covI, covJ), unc);
6302     }
6303     
6304   unc = TMath::Sqrt(unc);
6305   
6306   yield /= width * 2;
6307   yield2 /= width * 2;
6308   unc /= width * 2;
6309   
6310   Printf("%f (%f) +- %f", yield, yield2, unc);
6311 }
6312
6313 double NLowestBinAverage(TH1 &h, int N)
6314 {
6315   // Returns mean content of N lowest bins in h.
6316
6317   double avg = 0;
6318   int counter = 0;
6319   std::list<double> content;
6320   std::list<double>::iterator i;
6321
6322   for (int jbin=1; jbin<=h.GetNbinsX(); jbin++) {
6323     content.push_back(h.GetBinContent(jbin));
6324   }
6325   content.sort();
6326
6327   for (i = content.begin(); i != content.end(); ++i) {
6328
6329     if (counter == N)
6330       break;
6331
6332     avg += *i/N;
6333     counter++;
6334   }
6335
6336   if (counter < N)
6337     Warning("NLowestBinAverage()",
6338         "Avg. of %d bins requested, %d used", N, counter);
6339
6340   return avg;
6341
6342
6343 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, Float_t* vn = 0)
6344 {
6345   // caseOffsets
6346   // 0 same with v2 (14 tsallis for baseline [28/29 tsallis params]; 15 yield from tsallis function)
6347   // [disabled] 1 same/mixed with v2 (15 tsallis for baseline)
6348   // 2 same no v2 (16 tsallis for baseline; 17 yield from tsallis function)
6349   // 4 same no v2 (18 flat fit 1)
6350   // 5 same no v2 (19 flat fit 2)
6351   // 6 same no v2 (20 flat avg over 4)
6352   // 7 same no v2 (21 flat avg over 8)
6353   // 8 same no v2 (22 flat avg over 16)
6354   // 9 same with v2 (23 flat fit 1)
6355   // 10 same with v2 (24 flat fit 2)
6356   // 11 same with v2 (25 flat avg over 4)
6357   // 12 same with v2 (26 flat avg over 8)
6358   // 13 same with v2 (27 flat avg over 16)
6359   
6360   // 30 gaussian fit width
6361
6362   // same stuff for same/mixed
6363   if (0 && caseOffset == 0 && histMixed)
6364   {
6365     TH1* clone = (TH1*) hist->Clone();
6366     clone->Divide(histMixed);
6367     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 1, ptACenter, ptAWidth, kFALSE, 0, vn);
6368   }
6369   
6370   // same for other baseline subtractions
6371   if (caseOffset == 0)
6372   {
6373     file = TFile::Open("dphi_corr.root", "UPDATE");
6374     hist->Write();
6375     file->Close();
6376     
6377     TH1* clone = (TH1*) hist->Clone();
6378     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 2, ptACenter, ptAWidth, kTRUE, 0, vn);
6379   
6380     clone = (TH1*) hist->Clone();
6381     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 4, ptACenter, ptAWidth, kTRUE, 1, vn);
6382   
6383     clone = (TH1*) hist->Clone();
6384     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 5, ptACenter, ptAWidth, kTRUE, 2, vn);
6385     
6386     clone = (TH1*) hist->Clone();
6387     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 6, ptACenter, ptAWidth, kTRUE, 3, vn);
6388     
6389     clone = (TH1*) hist->Clone();
6390     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 7, ptACenter, ptAWidth, kTRUE, 4, vn);
6391     
6392     clone = (TH1*) hist->Clone();
6393     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 8, ptACenter, ptAWidth, kTRUE, 5, vn);
6394     
6395     clone = (TH1*) hist->Clone();
6396     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 9, ptACenter, ptAWidth, kFALSE, 1, vn);
6397   
6398     clone = (TH1*) hist->Clone();
6399     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 10, ptACenter, ptAWidth, kFALSE, 2, vn);
6400   
6401     clone = (TH1*) hist->Clone();
6402     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 11, ptACenter, ptAWidth, kFALSE, 3, vn);
6403   
6404     clone = (TH1*) hist->Clone();
6405     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 12, ptACenter, ptAWidth, kFALSE, 4, vn);
6406   
6407     clone = (TH1*) hist->Clone();
6408     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 13, ptACenter, ptAWidth, kFALSE, 5, vn);
6409   }
6410
6411   Float_t awaySideYield = ExtractYields(hist, trigId, centralityId, ptACenter, ptAWidth, 0 + caseOffset, 0);
6412   
6413   if (flatBaseLine)
6414   {
6415     v2 = 0;
6416     vn = 0;
6417   }
6418     
6419 /*    Float_t v2Trig  = flowGraph->Eval(ptT);
6420     Float_t v2Assoc = flowGraph->Eval(ptA);
6421     Float_t v2 = v2Trig * v2Assoc;
6422     Printf("%f %f: %.2f %.2f --> %.4f", ptT, ptA, v2Trig, v2Assoc, v2);*/
6423   
6424   TF1* flowFunc = new TF1("flowFunc", "[0] * (1+2*[1]*cos(2*x)+2*[2]*cos(3*x)+2*[3]*cos(4*x)+2*[4]*cos(5*x))", -0.5 * TMath::Pi(), 1.5 * TMath::Pi());
6425
6426   // find minimum
6427   if (0)
6428   {
6429     Float_t minBin = hist->FindBin(0.6);
6430     for (Int_t bin=hist->FindBin(0.6); bin<=hist->FindBin(1.8); bin++)
6431       if (hist->GetBinContent(bin) < hist->GetBinContent(minBin))
6432         minBin = bin;
6433             
6434     Float_t norm = hist->GetBinContent(minBin) / (1 + 2 * v2 * cos(2 * hist->GetBinCenter(minBin)));
6435     Double_t normUnc = 0;
6436   }
6437   else
6438   {
6439     if (baseLineDetermination == 0)
6440     {
6441       return;
6442       /*
6443       if (centralityId == 0)
6444         hist->Fit("pol0", "0", "", 0.8., 1.2);
6445       else
6446         hist->Fit("pol0", "0", "", 1.2, 1.6);
6447       */
6448       //tsallis = new TF1("tsallis", "(1-[1]*(1-[0])*x*x)**(1/(1-[0]))", 0, 10)
6449       // (1-b(1-q)x*x)**(1/(1-q))
6450       
6451       // combination of two tsallis functions
6452       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());
6453       //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());
6454       // 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
6455       total->SetParLimits(0, 0, 10000);
6456       total->SetParLimits(1, 0, 10000);
6457       total->SetParLimits(4, 0, 10000);
6458       
6459       total->SetParLimits(2, 1.0000001, 5);
6460       total->SetParLimits(5, 1.0000001, 5);
6461       
6462       total->SetParLimits(3, 0.1, 1000);
6463       total->SetParLimits(6, 0.1, 1000);
6464       
6465       total->SetParameters(1, 1, 1.5, 3, 1, 1.5, 1.1);
6466       
6467       // limit q>1
6468       hist->Fit(total, "0RI");
6469       fitResult = hist->Fit(total, "0RSI");
6470       
6471       if (0 && fitResult->CovMatrixStatus() > 0)
6472       {
6473         TMatrixDSym cov(fitResult->GetCovarianceMatrix());
6474         cov.Print();
6475         
6476         Double_t nearSideYield, nearSideError;
6477         TsallisYieldUncertainty(total->GetParameter(1), total->GetParameter(2), total->GetParameter(3), cov, 0, nearSideYield, nearSideError);
6478         
6479         Double_t awaySideYield2, awaySideError;
6480         TsallisYieldUncertainty(total->GetParameter(4), total->GetParameter(5), total->GetParameter(6), cov, 3, awaySideYield2, awaySideError);
6481         
6482         FillYield(trigId, centralityId, ptACenter, ptAWidth, 14 + caseOffset + 1, nearSideYield, nearSideError, awaySideYield2, awaySideError);
6483         
6484         Printf("Chi2 %f / ndf %d = %f", total->GetChisquare(), total->GetNDF(), (total->GetNDF() > 0) ? total->GetChisquare() / total->GetNDF() : -1);
6485         
6486         total->SetLineColor(hist->GetLineColor());
6487         total->SetLineWidth(1);
6488         if (caseOffset == 2)
6489         {
6490           if (0)
6491             total->DrawCopy("SAME");
6492           //total->SetParameter(5, total->GetParameter(5) - TMath::Sqrt(cov[5][5]));
6493           //total->DrawCopy("SAME");
6494           //total->SetParameter(5, total->GetParameter(5) + 2 * TMath::Sqrt(cov[5][5]));
6495           //Printf("%f", total->Integral(-0.7,0.7));
6496           //total->DrawCopy("SAME");
6497         }
6498         
6499         if (caseOffset == 0)
6500         {
6501           // store fit parameters
6502           
6503           // q
6504           FillYield(trigId, centralityId, ptACenter, ptAWidth, 28, total->GetParameter(2), total->GetParError(2), total->GetParameter(5), total->GetParError(5));
6505           // beta
6506           FillYield(trigId, centralityId, ptACenter, ptAWidth, 29, total->GetParameter(3), total->GetParError(3), total->GetParameter(6), total->GetParError(6));
6507           
6508           if (0)
6509           {
6510             // two Gauss fits
6511             gausFit = new TF1("gausFit", "[0] + gaus(1) + gaus(4)", -0.5 * TMath::Pi(), 1.5 * TMath::Pi());
6512             gausFit->SetParameters(1, 1, 0, 1, 1, TMath::Pi(), 0);
6513             gausFit->SetParLimits(0, 0, 10000);
6514             gausFit->SetParLimits(1, 0, 10000);
6515             gausFit->FixParameter(2, 0);
6516             gausFit->SetParLimits(3, 0.01, 10);
6517             gausFit->SetParLimits(4, 0, 10000);
6518             gausFit->FixParameter(5, TMath::Pi());
6519             gausFit->SetParLimits(6, 0.01, 10);
6520             
6521             hist->Fit(gausFit, "0RI");
6522             gausFit->SetLineWidth(1);
6523             gausFit->DrawCopy("SAME");
6524           
6525             FillYield(trigId, centralityId, ptACenter, ptAWidth, 30, gausFit->GetParameter(3), total->GetParError(3), total->GetParameter(6), total->GetParError(6));
6526           }
6527         }
6528         
6529         if (0 && cov[0][0] > 0)
6530         {
6531           for (Int_t i=0; i<cov.GetNcols(); i++)
6532             for (Int_t j=0; j<cov.GetNrows(); j++)
6533               cov[j][i] /= TMath::Sqrt(cov[i][i]) * TMath::Sqrt(cov[j][j]);
6534           cov.Print();
6535         }
6536       }
6537       
6538       func = total;
6539       Float_t norm = func->GetParameter(0) / (1 - 2 * v2);
6540       Double_t normUnc = func->GetParError(0) / (1 - 2 * v2);
6541       //return;
6542     }
6543     else if (baseLineDetermination <= 2)
6544     {
6545       Float_t values[3];
6546       Float_t errors[3];
6547       
6548       if (baseLineDetermination == 1)
6549       {
6550         Float_t regionBegin[3] = { -TMath::Pi() / 2,        TMath::Pi() / 2 - 0.4, 1.5 * TMath::Pi() - 0.4 };
6551         Float_t regionEnd[3] =   { -TMath::Pi() / 2 + 0.4,  TMath::Pi() / 2 + 0.4, 1.5 * TMath::Pi() };
6552       }
6553       else if (baseLineDetermination == 2)
6554       {
6555         Float_t regionBegin[3] = { -TMath::Pi() / 2,              TMath::Pi() / 2 - 0.4 - 0.2, 1.5 * TMath::Pi() - 0.4 - 0.2};
6556         Float_t regionEnd[3] =   { -TMath::Pi() / 2 + 0.4 - 0.2,  TMath::Pi() / 2 + 0.4 - 0.2, 1.5 * TMath::Pi() };
6557       }
6558         
6559       // weighted mean
6560       Float_t sum = 0;
6561       Float_t weight = 0;
6562       for (Int_t i=0; i<3; i++)
6563       {
6564         hist->Fit("pol0", "0Q", "", regionBegin[i], regionEnd[i]);
6565         func = hist->GetFunction("pol0");
6566         if (!func)
6567           continue;
6568         sum += func->GetParameter(0) / func->GetParError(0) / func->GetParError(0);
6569         weight += 1. / func->GetParError(0) / func->GetParError(0);
6570       }
6571       
6572       if (weight == 0)
6573         return;
6574       
6575       sum /= weight;
6576       weight = TMath::Sqrt(1. / weight);
6577       
6578       Float_t norm = sum / (1 - 2 * v2);
6579       Double_t normUnc = weight / (1 - 2 * v2);
6580     }
6581     else
6582     {
6583       Int_t bins = 2;
6584       if (baseLineDetermination == 4)
6585         bins = 4;
6586       if (baseLineDetermination == 5)
6587         bins = 8;
6588       Float_t norm = NLowestBinAverage(*hist, bins);
6589       Double_t normUnc = 0;
6590       
6591       Printf("NLowestBinAverage %d --> %f", bins, norm);
6592       
6593       norm /= (1 - 2 * v2);
6594     }
6595     
6596     Printf("Baseline: %f +- %f", norm, normUnc);
6597   }
6598   
6599   if (caseOffset == 0)
6600   {
6601     Float_t awaySideYieldNoBaseline = awaySideYield - norm * (1 - 2 * v2);
6602     Float_t v2YieldNoBaseline = norm * 2 * v2 * (1 + 1.4) / 1.4;
6603     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);
6604   }
6605
6606   //flowFunc->SetParameters(hist->GetBinContent(hist->FindBin(1.4)) / (1.0 - 2.0 * v2), v2);
6607   flowFunc->SetParameters(norm, v2, 0, 0, 0);
6608   if (vn)
6609     flowFunc->SetParameters(norm, vn[1], vn[2], vn[3], vn[4]);
6610   flowFunc->SetLineWidth(2);
6611   if (caseOffset >= 4 && caseOffset <= 9 && caseOffset != 6 && caseOffset != 7)
6612   {
6613     if (caseOffset != 4 && caseOffset != 9)
6614       flowFunc->SetLineStyle(2);
6615     flowFunc->DrawCopy("SAME"); //->SetLineColor(caseOffset - 3);
6616     if (vn)
6617     {
6618       flowFuncTmp = (TF1*) flowFunc->Clone("flowFuncTmp");
6619       for (Int_t i=1; i<=4; i++)
6620       {
6621         flowFuncTmp->SetParameters(flowFuncTmp->GetParameter(0), 0, 0, 0, 0);
6622         flowFuncTmp->SetParameter(i, vn[i]);
6623         flowFuncTmp->SetLineStyle(2);
6624         flowFuncTmp->Print();
6625         flowFuncTmp->DrawCopy("SAME");
6626       }
6627     }
6628   }
6629   
6630   hist->Add(flowFunc, -1);
6631   if (caseOffset == 0)
6632   {
6633     file = TFile::Open("dphi_corr.root", "UPDATE");
6634     hist->SetName(TString(hist->GetName()) + "_tsallis_v2");
6635     hist->Write();
6636     file->Close();
6637     //  hist->DrawCopy("SAME");
6638   }
6639   if (caseOffset == 2 && flatBaseLine)
6640   {
6641     file = TFile::Open("dphi_corr.root", "UPDATE");
6642     hist->SetName(TString(hist->GetName()) + "_tsallis_flat");
6643     hist->Write();
6644     file->Close();
6645     //  hist->DrawCopy("SAME");
6646   }
6647   if (caseOffset == 4 && flatBaseLine)
6648   {
6649     file = TFile::Open("dphi_corr.root", "UPDATE");
6650     hist->SetName(TString(hist->GetName()) + "_fit_flat");
6651     hist->Write();
6652     file->Close();
6653     //  hist->DrawCopy("SAME");
6654   }
6655   if (caseOffset == 9)
6656   {
6657     file = TFile::Open("dphi_corr.root", "UPDATE");
6658     hist->SetName(TString(hist->GetName()) + "_fit_v2");
6659     hist->Write();
6660     file->Close();
6661     //  hist->DrawCopy("SAME");
6662   }
6663   
6664   ExtractYields(hist, trigId, centralityId, ptACenter, ptAWidth, 14 + caseOffset, normUnc);
6665   
6666   if (0 && histMixed)
6667   {
6668     Printf("%f", histMixed->Integral() / histMixed->GetNbinsX());
6669     flowFunc->SetParameters(histMixed->Integral() / histMixed->GetNbinsX(), v2);
6670     flowFunc->SetLineColor(2);
6671     //if (caseOffset == 0)
6672     //  flowFunc->DrawCopy("SAME");
6673   }
6674 }
6675
6676 void RemoveBaseLine(TH1* hist)
6677 {
6678   if (!hist)
6679     return;
6680     
6681   //hist->Rebin(2);
6682   //hist->Scale(0.5);
6683
6684   hist->Fit("pol0", "0", "", 1.07, 2.07);
6685   
6686   if (!hist->GetFunction("pol0"))
6687     return;
6688   
6689   Float_t zyam = hist->GetFunction("pol0")->GetParameter(0);
6690   
6691   if (zyam <= 0)
6692     return;
6693     
6694   return;
6695   
6696   for (Int_t i=1; i<=hist->GetNbinsX(); i++)
6697     hist->SetBinContent(i, hist->GetBinContent(i) - zyam);
6698 }
6699  
6700 void* cacheIds[10];
6701 TH2* cacheMixed[10];
6702
6703 Int_t gHistCount = 0;
6704 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, Int_t stepMixed = -1, Bool_t useCentralityBinsDirectly = kFALSE)
6705 {
6706   h = (AliUEHistograms*) hVoid;
6707   hMixed = (AliUEHistograms*) hMixedVoid;
6708   
6709   if (stepMixed < 0)
6710     stepMixed = step;
6711
6712   Int_t centralityBeginBin = 0;
6713   Int_t centralityEndBin = -1;
6714   
6715   if (!useCentralityBinsDirectly && centralityEnd >= centralityBegin)
6716   {
6717     centralityBeginBin = h->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->FindBin(0.01 + centralityBegin);
6718     centralityEndBin = h->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->FindBin(-0.01 + centralityEnd);
6719   }
6720   else if (useCentralityBinsDirectly)
6721   {
6722     centralityBeginBin = centralityBegin;
6723     centralityEndBin = centralityEnd;
6724   }
6725   
6726   // 2d same and mixed event
6727   TH2* sameTwoD  = h->GetUEHist(2)->GetUEHist(step, 0, ptBegin, ptEnd, centralityBeginBin, centralityEndBin, 1, kFALSE);
6728   
6729   if (hMixed)
6730   {
6731     if (!equivMixedBin)
6732     {
6733       // No centrality, nor pT associated dep of the mixed event observed. Use a larger range to get more statistics
6734       
6735       Int_t cacheId = -1;
6736       
6737       for (Int_t i=0; i<10; i++)
6738         if (cacheIds[i] == hMixed)
6739         {
6740           cacheId = i;
6741           break;
6742         }
6743         
6744       // not found
6745       if (cacheId == -1)
6746         for (Int_t i=0; i<10; i++)
6747           if (cacheIds[i] == 0)
6748           {
6749             cacheId = i;
6750             break;
6751           }
6752
6753       if (!cacheIds[cacheId])
6754       {
6755         hMixed->SetPtRange(3.0, 10);
6756         cacheMixed[cacheId] = (TH2*) hMixed->GetUEHist(2)->GetUEHist(stepMixed, 0, 3.0, 10.0, centralityBeginBin, centralityEndBin, 1, kFALSE);
6757         cacheIds[cacheId] = hMixed;
6758         Printf("GetDistAndFlow: Cached for %p on slot %d", hMixed, cacheId);
6759       }
6760       
6761       TH2* mixedTwoD = cacheMixed[cacheId];
6762     }
6763     else
6764     {
6765       // use same bin for mixing
6766       
6767       TH2* mixedTwoD = (TH2*) hMixed->GetUEHist(2)->GetUEHist(stepMixed, 0, ptBegin, ptEnd, centralityBeginBin, centralityEndBin, 1, kFALSE);
6768     }
6769     
6770     if (0)
6771     {
6772       // asssume flat in dphi, gain in statistics
6773       Printf("NOTE: Assuming flat acceptance in phi!");
6774       
6775       TH1* histMixedproj = mixedTwoD->ProjectionY();
6776       histMixedproj->Scale(1.0 / mixedTwoD->GetNbinsX());
6777       
6778       for (Int_t x=1; x<=mixedTwoD->GetNbinsX(); x++)
6779         for (Int_t y=1; y<=mixedTwoD->GetNbinsY(); y++)
6780           mixedTwoD->SetBinContent(x, y, histMixedproj->GetBinContent(y));
6781     }
6782     
6783     // get mixed event normalization by assuming full acceptance at deta of 0 (only works for flat dphi)
6784     if (scaleToPairs)
6785     {
6786       Double_t mixedNorm = mixedTwoD->Integral(1, mixedTwoD->GetNbinsX(), mixedTwoD->GetYaxis()->FindBin(-0.01), mixedTwoD->GetYaxis()->FindBin(0.01));
6787       mixedNorm /= mixedTwoD->GetNbinsX() * (mixedTwoD->GetYaxis()->FindBin(0.01) - mixedTwoD->GetYaxis()->FindBin(-0.01) + 1);
6788     }
6789     else
6790       Double_t mixedNorm = mixedTwoD->Integral() / sameTwoD->Integral();
6791     
6792     // divide and scale
6793     sameTwoD->Divide(mixedTwoD);
6794     sameTwoD->Scale(mixedNorm);
6795     
6796 /*    new TCanvas;
6797     sameTwoD->Draw("SURF1");
6798     dfdsafd;*/
6799   }
6800   
6801   TString histName;
6802   histName.Form("GetDistAndFlow%d", gHistCount++);
6803   
6804   // extract dphi distribution if requested
6805   if (twoD == 1)
6806   {
6807     *hist = sameTwoD;
6808   }
6809
6810   //  Float_t etaLimit = 0.8;
6811   Float_t etaLimit = 1.0;
6812
6813   // 20: return corr in |delta eta| < 1 from which 1 < |delta eta| < 2 is subtracted
6814   if (twoD == 0 || twoD == 10 || twoD == 20)
6815   {
6816     Int_t etaBegin = 1;
6817     Int_t etaEnd = sameTwoD->GetNbinsY();
6818     
6819     if (twoD == 10 || twoD == 20)
6820     {
6821       etaBegin = sameTwoD->GetYaxis()->FindBin(-etaLimit + 0.01);
6822       etaEnd   = sameTwoD->GetYaxis()->FindBin(etaLimit - 0.01);
6823     }
6824
6825     *hist = sameTwoD->ProjectionX(histName, etaBegin, etaEnd);
6826     
6827     if (!scaleToPairs)
6828       (*hist)->Scale(1.0 / (etaEnd - etaBegin + 1));
6829   }
6830   
6831   if (twoD == 11 || twoD == 20)
6832   {
6833     // errors --> are ok
6834     
6835 //       Float_t outerLimit = 2.0;
6836     Float_t outerLimit = 1.8;
6837     Printf("Phi dist: Using outer limit %.2f", outerLimit);
6838 //       Float_t outerLimit = etaLimit * 2;
6839     
6840     histTmp = sameTwoD->ProjectionX(histName + "1", TMath::Max(1, sameTwoD->GetYaxis()->FindBin(-outerLimit + 0.01)), sameTwoD->GetYaxis()->FindBin(-etaLimit - 0.01));
6841     Int_t etaBins = sameTwoD->GetYaxis()->FindBin(-etaLimit - 0.01) - TMath::Max(1, sameTwoD->GetYaxis()->FindBin(-outerLimit + 0.01)) + 1;
6842
6843     TH1D* tracksTmp = sameTwoD->ProjectionX(histName + "2", sameTwoD->GetYaxis()->FindBin(etaLimit + 0.01), TMath::Min(sameTwoD->GetYaxis()->GetNbins(), sameTwoD->GetYaxis()->FindBin(outerLimit - 0.01)));
6844     etaBins += TMath::Min(sameTwoD->GetYaxis()->GetNbins(), sameTwoD->GetYaxis()->FindBin(outerLimit - 0.01)) - sameTwoD->GetYaxis()->FindBin(etaLimit + 0.01) + 1;
6845
6846 //       printf("%f +- %f  %f +- %f ", (*hist)->GetBinContent(1), (*hist)->GetBinError(1), tracksTmp->GetBinContent(1), tracksTmp->GetBinError(1));
6847     histTmp->Add(tracksTmp);
6848 //       Printf(" --> %f +- %f", (*hist)->GetBinContent(1), (*hist)->GetBinError(1));
6849     
6850     if (!scaleToPairs)
6851       histTmp->Scale(1.0 / etaBins);
6852     
6853     if (twoD == 11)
6854       *hist = histTmp;
6855     else if (twoD == 20)
6856     {
6857       // calculate acc with 2 * (deta - 0.5 * deta*deta / 1.6)
6858       if (!hMixedVoid)
6859         histTmp->Scale(0.75 / 0.25);
6860       
6861       histTmp->Scale(1.0 / 0.8);
6862       
6863       (*hist)->Add(histTmp, -1);
6864     }
6865   }
6866   
6867 //   (*hist)->Rebin(2); (*hist)->Scale(0.5);
6868   
6869   //*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);
6870   
6871   TString str;
6872   str.Form("%.1f < p_{T,trig} < %.1f", ptBegin - 0.01, ptEnd + 0.01);
6873   
6874   TString str2;
6875   str2.Form("%.2f < p_{T,assoc} < %.2f", gpTMin - 0.01, gpTMax + 0.01);
6876     
6877   TString newTitle;
6878   newTitle.Form("%s - %s - %d-%d", str.Data(), str2.Data(), centralityBegin, centralityEnd);
6879   if (!useCentralityBinsDirectly)
6880     newTitle += "%";
6881   (*hist)->SetTitle(newTitle);
6882   
6883   if (0 && hMixed)
6884   {
6885     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));
6886     
6887     //new TCanvas; (*hist)->DrawCopy(); histMixed->DrawCopy("SAME")->SetLineColor(2);
6888     
6889     Float_t totalPairs = (*hist)->Integral();
6890     
6891     (*hist)->Divide(histMixed);
6892     (*hist)->Scale(totalPairs / (*hist)->Integral());
6893     
6894     //(*hist)->DrawCopy("SAME")->SetLineColor(4);
6895   }
6896   
6897   if (v2 || vn)
6898   {
6899     // calculate v2trigger
6900     h->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->SetRangeUser(0.01 + centralityBegin, -0.01 + centralityEnd);
6901     ptDist = h->GetUEHist(2)->GetEventHist()->Project(step, 0);
6902     Float_t vTrig[5];
6903     for (Int_t i=2; i<=((vn) ? 5 : 2); i++)
6904       vTrig[i-1] = CalculateFlow(ptDist, ptBegin, ptEnd, i, centralityBegin, centralityEnd);
6905     delete ptDist;
6906     
6907     // calculate v2 assoc
6908     cont = h->GetUEHist(2)->GetTrackHist(0);
6909     h->GetUEHist(2)->GetTrackHist(0)->GetGrid(step)->GetGrid()->GetAxis(3)->SetRangeUser(0.01 + centralityBegin, -0.01 + centralityEnd);
6910     h->GetUEHist(2)->GetTrackHist(0)->GetGrid(step)->GetGrid()->GetAxis(2)->SetRangeUser(ptBegin, ptEnd);
6911     ptDist = h->GetUEHist(2)->GetTrackHist(0)->Project(step, 1);
6912     Float_t vAssoc[5];
6913     for (Int_t i=2; i<=((vn) ? 5 : 2); i++)
6914       vAssoc[i-1] = CalculateFlow(ptDist, gpTMin, gpTMax, i, centralityBegin, centralityEnd);
6915     delete ptDist;
6916   
6917     if (v2)
6918       *v2 = vTrig[2-1] * vAssoc[2-1];
6919     if (vn)
6920       for (Int_t i=2; i<=5; i++)
6921         vn[i-1] = vTrig[i-1] * vAssoc[i-1];
6922   }
6923 }
6924
6925 void CompareNtrDist(const char* fileName1, const char* fileNameCentrality1)
6926 {
6927   loadlibs();
6928   Int_t step = 8;
6929
6930   TCanvas *c1 = new TCanvas("c1", "", 1400, 1100);
6931   TCanvas *c2 = new TCanvas("c2", "", 1400, 1100);
6932
6933   dndpt_central = ReadHepdata("/home/mkofarag/work/Project/2010/raa_dndpt_central.txt", kFALSE, 3);
6934   AliUEHistograms* h1 = (AliUEHistograms*) GetUEHistogram(fileName1);
6935   AliUEHistograms* hc1 = (AliUEHistograms*) GetUEHistogram(fileNameCentrality1);
6936
6937   h1->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->SetRangeUser(0.01 + 0, -0.01 + 5);
6938   ptDist1 = h1->GetUEHist(2)->GetEventHist()->Project(step, 0);
6939   ptDist1->Scale(1.0/1.8/TMath::TwoPi()/hc1->GetCentralityDistribution()->Integral(hc1->GetCentralityDistribution()->FindBin(0.01), hc1->GetCentralityDistribution()->FindBin(4.99)));
6940   for (Int_t i=1; i<=ptDist1->GetNbinsX(); i++)
6941   {
6942     ptDist1->SetBinContent(i, ptDist1->GetBinContent(i)/ptDist1->GetBinWidth(i));
6943   }
6944   for (Int_t i=0; i<dndpt_central->GetN();i++)
6945   {
6946     Double_t x = dndpt_central->GetX()[i];
6947     Double_t y = dndpt_central->GetY()[i]*x;
6948     dndpt_central->SetPoint(i,x,y);
6949   }
6950   ptDist2 = (TH1*) ptDist1->Clone("ptDist2");
6951   ptDist2->Reset();
6952   for (Int_t i=0; i<dndpt_central->GetN(); i++)
6953   {
6954     Float_t width = 0;
6955     if (i > 0)
6956       width += (dndpt_central->GetX()[i] - dndpt_central->GetX()[i-1]) / 2;
6957     if (i < dndpt_central->GetN()-1)
6958       width += (dndpt_central->GetX()[i+1] - dndpt_central->GetX()[i]) / 2;
6959     if (i == 0 || i == dndpt_central->GetN() - 1)
6960       width *= 2;
6961     ptDist2->Fill(dndpt_central->GetX()[i],dndpt_central->GetY()[i]*width);
6962   }
6963   for (Int_t i=1; i<=ptDist2->GetNbinsX(); i++)
6964   {
6965     ptDist2->SetBinContent(i, ptDist2->GetBinContent(i)/ptDist2->GetBinWidth(i));
6966     ptDist2->SetBinError(i,0);
6967   }
6968 /*  for (Int_t i=1; i<=ptDist1->GetNbinsX(); i++)
6969   {
6970     ptDist1->SetBinError(i,0);
6971   }
6972 */
6973   c1->cd();
6974   c1->SetLogy();
6975   ptDist1->SetMarkerStyle(3);
6976   ptDist2->SetMarkerStyle(2);
6977   ptDist1->SetMarkerColor(2);
6978   ptDist2->SetMarkerColor(3);
6979   ptDist1->SetLineColor(2);
6980   ptDist2->SetLineColor(3);
6981   ptDist1->DrawCopy("EP");
6982   ptDist2->Draw("EPSAME");
6983   ptDist1->Divide(ptDist1,ptDist2);
6984   c2->cd();
6985   ptDist1->Draw("EP");
6986
6987 }
6988
6989 void FitNtrDist(const char* fileName1, const char* fileNameCentrality1)
6990 {
6991   loadlibs();
6992   Int_t step = 8;
6993
6994   TCanvas *c1 = new TCanvas("c1", "", 1400, 1100);
6995   TCanvas *c2 = new TCanvas("c2", "", 1400, 1100);
6996   TCanvas *c3 = new TCanvas("c3", "", 1400, 1100);
6997
6998   dndpt_central = ReadHepdata("/home/mkofarag/work/Project/2010/raa_dndpt_central.txt", kFALSE, 3);
6999   TF1* func1 = new TF1("func1", "[0]*x/TMath::Sqrt(0.1396*0.1396+x*x)*TMath::Power(1+x/[1],-1*[2])",0.5,5);
7000   TF1* func2 = new TF1("func2", "[0]*TMath::Power(x,-1*[1])",5,20);
7001
7002   func1->SetParLimits(0, 2000, 5000);
7003   func1->SetParLimits(1, 1, 6);
7004   func1->SetParLimits(2, 7, 20);
7005   dndpt_central->Fit(func1,"RB","",0.5,5);
7006
7007   func2->SetParLimits(0, 0, 1000);
7008   func2->SetParLimits(1, 4, 8);
7009   dndpt_central->Fit(func2,"RB","",5,20);
7010
7011   c1->cd();
7012   c1->SetLogy();
7013   c1->SetLogx();
7014   dndpt_central->Draw("AP");
7015   func1->Draw("SAME");
7016   func2->Draw("SAME");
7017
7018   TF1* func3 = new TF1("func3", "[0]*x*x/TMath::Sqrt(0.1396*0.1396+x*x)*TMath::Power(1+x/[1],-1*[2])",0.5,5);
7019   TF1* func4 = new TF1("func4", "[0]*x*TMath::Power(x,-1*[1])",5,20);
7020
7021   func3->FixParameter(0,func1->GetParameter(0));
7022   func3->FixParameter(1,func1->GetParameter(1));
7023   func3->FixParameter(2,func1->GetParameter(2));
7024   func4->FixParameter(0,func2->GetParameter(0));
7025   func4->FixParameter(1,func2->GetParameter(1));
7026
7027   AliUEHistograms* h1 = (AliUEHistograms*) GetUEHistogram(fileName1);
7028   AliUEHistograms* hc1 = (AliUEHistograms*) GetUEHistogram(fileNameCentrality1);
7029
7030   h1->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->SetRangeUser(0.01 + 0, -0.01 + 5);
7031   ptDist1 = h1->GetUEHist(2)->GetEventHist()->Project(step, 0);
7032   ptDist1->Scale(1.0/1.8/TMath::TwoPi()/hc1->GetCentralityDistribution()->Integral(hc1->GetCentralityDistribution()->FindBin(0.01), hc1->GetCentralityDistribution()->FindBin(4.99)));
7033   ptDist2 = (TH1*) ptDist1->Clone("ptDist2");
7034   ptDist2->Reset();
7035   for (Int_t i=1; i<=ptDist1->GetNbinsX(); i++)
7036   {
7037     ptDist1->SetBinContent(i, ptDist1->GetBinContent(i)/ptDist1->GetBinWidth(i));
7038     if (ptDist1->GetBinLowEdge(i)<5) ptDist2->SetBinContent(i, func3->Integral(ptDist1->GetBinLowEdge(i),ptDist1->GetBinLowEdge(i+1)));
7039     else ptDist2->SetBinContent(i, func4->Integral(ptDist1->GetBinLowEdge(i),ptDist1->GetBinLowEdge(i+1)));
7040   }
7041
7042   for (Int_t i=1; i<=ptDist2->GetNbinsX(); i++)
7043   {
7044     ptDist2->SetBinContent(i, ptDist2->GetBinContent(i)/ptDist2->GetBinWidth(i));
7045   }
7046   c2->cd();
7047   c2->SetLogy();
7048   ptDist1->SetMarkerStyle(3);
7049   ptDist2->SetMarkerStyle(2);
7050   ptDist1->SetMarkerColor(2);
7051   ptDist2->SetMarkerColor(3);
7052   ptDist1->SetLineColor(2);
7053   ptDist2->SetLineColor(3);
7054   ptDist1->DrawCopy("EP");
7055   ptDist2->Draw("EPSAME");  
7056
7057   ptDist1->Divide(ptDist1,ptDist2);
7058   c3->cd();
7059   ptDist1->Draw("EP");
7060 }
7061
7062 void DrawNtrDist(const char* fileName1, const char* fileName2, const char* fileNameCentrality1, const char* fileNameCentrality2)
7063 {
7064   loadlibs();
7065
7066   Int_t step = 8;
7067
7068   new TCanvas("c", "", 1400, 1100);
7069   AliUEHistograms* h1 = (AliUEHistograms*) GetUEHistogram(fileName1);
7070   AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(fileName2);
7071   AliUEHistograms* hc1 = (AliUEHistograms*) GetUEHistogram(fileNameCentrality1);
7072   AliUEHistograms* hc2 = (AliUEHistograms*) GetUEHistogram(fileNameCentrality2);
7073   h1->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->SetRangeUser(0.01 + 0, -0.01 + 10);
7074   h2->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->SetRangeUser(0.01 + 0, -0.01 + 10);
7075   ptDist1 = h1->GetUEHist(2)->GetEventHist()->Project(step, 0);
7076   ptDist2 = h2->GetUEHist(2)->GetEventHist()->Project(step, 0);
7077   ptDist1->Scale(1/hc1->GetCentralityDistribution()->Integral(hc1->GetCentralityDistribution()->FindBin(0.01), hc1->GetCentralityDistribution()->FindBin(9.99)));
7078   ptDist2->Scale(1/hc2->GetCentralityDistribution()->Integral(hc2->GetCentralityDistribution()->FindBin(0.01), hc2->GetCentralityDistribution()->FindBin(9.99)));
7079   ptDist1->Divide(ptDist1,ptDist2);
7080   ptDist1->SetMarkerStyle(3);
7081   ptDist1->Draw();
7082 }
7083
7084 void GetSumOfRatios(void* hVoid, void* hMixedVoid, TH1** hist, Int_t step, Int_t centralityBegin, Int_t centralityEnd, Float_t ptBegin, Float_t ptEnd, Bool_t normalizePerTrigger = kTRUE, Bool_t useCentralityBinsDirectly = kFALSE)
7085 {
7086   Printf("GetSumOfRatios | step %d | %d-%d%% | %.1f - %.1f GeV/c | %.1f - %.1f GeV/c", step, centralityBegin, centralityEnd, gpTMin, gpTMax, ptBegin, ptEnd);
7087   
7088   h = (AliUEHistograms*) hVoid;
7089   hMixed = (AliUEHistograms*) hMixedVoid;
7090
7091   Int_t centralityBeginBin = 0;
7092   Int_t centralityEndBin = -1;
7093   
7094   if (!useCentralityBinsDirectly && centralityEnd >= centralityBegin)
7095   {
7096     centralityBeginBin = h->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->FindBin(0.01 + centralityBegin);
7097     centralityEndBin = h->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->FindBin(-0.01 + centralityEnd);
7098   }
7099   else if (useCentralityBinsDirectly)
7100   {
7101     centralityBeginBin = centralityBegin;
7102     centralityEndBin = centralityEnd;
7103   }
7104   
7105   *hist  = h->GetUEHist(2)->GetSumOfRatios2(hMixed->GetUEHist(2), step, 0, ptBegin, ptEnd, centralityBeginBin, centralityEndBin, normalizePerTrigger);
7106   
7107   TString str;
7108   str.Form("%.1f < p_{T,trig} < %.1f", ptBegin - 0.01, ptEnd + 0.01);
7109   
7110   TString str2;
7111   str2.Form("%.2f < p_{T,assoc} < %.2f", gpTMin - 0.01, gpTMax + 0.01);
7112     
7113   TString newTitle;
7114   newTitle.Form("%s - %s - %d-%d", str.Data(), str2.Data(), centralityBegin, centralityEnd);
7115   if (!useCentralityBinsDirectly)
7116     newTitle += "%";
7117   if ((*hist))
7118     (*hist)->SetTitle(newTitle);
7119 }
7120  
7121 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)
7122 {
7123   loadlibs();
7124   
7125   Bool_t veryCentral = 0;
7126   Bool_t flowComparison = 0;
7127   Bool_t rhicOverlay = 0;
7128   Bool_t highStatBinning = 0;
7129
7130   file = TFile::Open("dphi_corr.root", "RECREATE");
7131   file->Close();
7132   
7133    Int_t leadingPtOffset = 1;
7134     
7135   if (veryCentral || flowComparison)
7136   {
7137     Int_t maxLeadingPt = 2;
7138     Int_t maxAssocPt = 2;
7139     Float_t leadingPtArr[] = { 2.0, 3.0, 4.0, 10.0, 20.0, 40.0 };
7140     //Float_t assocPtArr[] =   { 0.15, 0.5, 1.0, 2.0, 4.0, 6.0, 10.0, 20.0, 40.0 };
7141     Float_t assocPtArr[] =   { 1.0, 2.0, 3.0, 6.0, 10.0, 20.0, 40.0 };
7142   }
7143   else if (rhicOverlay) // RHIC binning
7144   {
7145     Int_t maxLeadingPt = 4;
7146     Int_t maxAssocPt = 5;
7147     Float_t leadingPtArr[] =   { 4.0, 5.0, 7.0, 9.0, 12.0 };
7148     Float_t assocPtArr[] =     { 0.5, 1.0, 2.0, 3.0, 5.0, 7.0 };
7149   }
7150   else if (highStatBinning) 
7151   {
7152     Int_t maxLeadingPt = 3;
7153     Int_t maxAssocPt = 2;
7154     Float_t leadingPtArr[] = { 4.0, 6.0, 8.0, 15.0 };
7155     Float_t assocPtArr[] =   { 1.0, 4.0, 10.0 };
7156   }
7157   else // ALICE binning
7158   {
7159     if (1) // binning from preliminaries
7160     {
7161       Int_t maxLeadingPt = 2;
7162       Int_t maxAssocPt = 7;
7163 //       Float_t leadingPtArr[] = { 6.0, 8.0, 10.0, 10.0, 15.0 };
7164       Float_t leadingPtArr[] = { 6.0, 8.0, 10.0, 15.0, 15.0 };
7165       Float_t assocPtArr[] =     { 0.5, 1.5, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
7166       leadingPtOffset = 2;
7167     }
7168     else if (0)
7169     {
7170       Int_t maxLeadingPt = 1;
7171       Int_t maxAssocPt = 4;
7172       Float_t leadingPtArr[] = { 8.0, 10.0, 15.0, 15.0 };
7173       Float_t assocPtArr[] =     { 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
7174       leadingPtOffset = 2;
7175     }
7176     else
7177     {
7178       Int_t maxLeadingPt = 3;
7179       Int_t maxAssocPt = 3;
7180       Float_t leadingPtArr[] = { 6.0, 8.0, 10.0, 15.0, 20.0 };
7181       Float_t assocPtArr[] =     { 1.0, 2.0, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
7182       leadingPtOffset = 2;
7183     }
7184   }
7185   
7186   Int_t nCentralityBins = 5;
7187   Int_t centralityBins[] = { 1, 7, 9, 11, 13, 16 };
7188   //Int_t centralityBins[] = { 1, 3, 5, 7, 9, 13 };
7189   
7190   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName1);
7191   
7192 //   h->SetZVtxRange(-0.5, 0.5);
7193 //   h->SetZVtxRange(1.5, 2.5);
7194   
7195   AliUEHistograms* hMixed = 0;
7196   AliUEHistograms* hMixed2 = 0; // GetUEHistogram(fileName2, 0, kTRUE);
7197
7198   if (twoD)
7199   {
7200     hMixed = (AliUEHistograms*) GetUEHistogram(fileName1, 0, kTRUE);
7201     hMixed2 = (AliUEHistograms*) GetUEHistogram(fileName2, 0, kTRUE);
7202   }
7203
7204
7205   if (veryCentral)
7206   {
7207     Printf("WARNING: Reading mixed event from preliminaries/corrected_110317.root");
7208     hMixed = (AliUEHistograms*) GetUEHistogram("preliminaries/corrected_110317.root", 0, kTRUE);
7209   }
7210   
7211   AliUEHistograms* h2 = 0;
7212   if (!twoD)
7213     h2 = (AliUEHistograms*) GetUEHistogram(fileName2);
7214
7215   
7216   TCanvas* canvas = new TCanvas("DeltaPhi", "DeltaPhi", 1000, 700);
7217   canvas->Divide(maxAssocPt, maxLeadingPt);
7218   
7219   TCanvas* canvas2 = new TCanvas("Centrality", "Centrality", 800, 600);
7220   centralityHist = (TH1*) h->GetCentralityDistribution();
7221   NormalizeToBinWidth(centralityHist);
7222   centralityHist->Draw();
7223   gPad->SetLogy();
7224   
7225   TLegend* legend = new TLegend(0.2, 0.5, 0.95, 0.90);
7226   TLegend* legend2 = new TLegend(0.5, 0.63, 0.95, 0.90);
7227   legend2->SetFillColor(0);
7228   legend2->SetTextSize(0.04);
7229   
7230   for (Int_t i=0; i<maxLeadingPt; i++)
7231     for (Int_t j=0; j<maxAssocPt; j++)
7232     {
7233       TString str;
7234       str.Form("%.1f < p_{T,trig} < %.1f", leadingPtArr[i], leadingPtArr[i+leadingPtOffset]);
7235       
7236       if (j == 0)
7237       {
7238         canvas2->cd();
7239         h->GetUEHist(2)->GetEventHist()->GetGrid(6)->SetRangeUser(0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01);
7240         centralityHist = h->GetUEHist(2)->GetEventHist()->ShowProjection(1, 6);
7241         centralityHist->SetLineColor(i+2);
7242         NormalizeToBinWidth(centralityHist);
7243         centralityHist->DrawCopy("SAME");
7244         h->GetUEHist(2)->GetEventHist()->GetGrid(6)->SetRangeUser(0, 0, -1);
7245         legend2->AddEntry(centralityHist, str);
7246       }
7247     
7248       canvas->cd(j+1 + i * maxAssocPt);
7249       gPad->SetLeftMargin(0.15);
7250       gPad->SetBottomMargin(0.2);
7251       gPad->SetTopMargin(0.01);
7252       gPad->SetRightMargin(0.01);
7253       
7254       if (i == 0 && j == 3)
7255         legend->Draw();
7256       
7257       gpTMin = assocPtArr[j] + 0.01;
7258       gpTMax = assocPtArr[j+1] - 0.01;
7259       
7260       TString str2;
7261       str2.Form("%.1f < p_{T,assoc} < %.1f", gpTMin - 0.01, gpTMax + 0.01);
7262       
7263       SetupRanges(h);
7264
7265       if (h2)
7266       {
7267         SetupRanges(h2); // SetEtaRange(0, 0) does not need to be called for the leading track result
7268       }
7269       
7270       if (hMixed)
7271       {
7272         SetupRanges(hMixed);
7273       }
7274       
7275       // delta phi
7276       if (!twoD)
7277       {
7278         if (assocPtArr[j] >= leadingPtArr[i+leadingPtOffset])
7279           continue;
7280     
7281         // 0-5% --> 1, 5
7282         // 0-10% --> 1, 6
7283         // 0-20% --> 1, 8
7284         // 20-40% --> 9, 10
7285         // 40-80% --> 11, 14
7286         // > 40% --> 11, 16
7287         
7288         TString hist1Str, hist2Str, hist2bStr;
7289         
7290         Float_t v2[3];
7291         for (Int_t k=0; k<3; k++)
7292           v2[k] = 0;
7293         Float_t vn[3][3];
7294         
7295         if (veryCentral)
7296         {
7297           Int_t step = 0;
7298           TH1* hist1 = 0;
7299           TH1* hist2 = 0;
7300           TH1* hist2b = 0;
7301           TH1* hist3 = 0;
7302           
7303           GetDistAndFlow(h, hMixed, &hist1,  v2, step, 0,  2,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01); hist1Str = "0-2%";
7304 //        GetDistAndFlow(h, hMixed, &hist2,  v2, step, 1,  3,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01); hist2Str = "1-3%";
7305           GetDistAndFlow(h, hMixed, &hist2b,  v2+2, step, 30,  40,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01); hist2bStr = "30-40%";
7306           
7307           //TH1* hist1 = h->GetUEHist(2)->GetUEHist(step, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 1, 2);  hist1Str = "0-2%";
7308           //TH1* hist2 = h->GetUEHist(2)->GetUEHist(step, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 2, 3);  hist2Str = "2-3%";
7309           //TH1* hist2b = h->GetUEHist(2)->GetUEHist(step, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 10, 10); hist2bStr = "30-40%";
7310         }
7311         else if (flowComparison)
7312         {
7313           TH1* hist1 = h->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 1, 5);  hist1Str = "0-5%";
7314           TH1* hist2 = h->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 9, 10);  hist2Str = "20-40%";
7315           TH1* hist2b = h->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 10, 10); hist2bStr = "30-40%";
7316           TH1* hist3 = 0; // h2->GetUEHist(2)->GetUEHist(0, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01);
7317         }
7318         else if (rhicOverlay)
7319         {
7320           TH1* hist1 = h->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 1, 8);   hist1Str = "0-20%";
7321           TH1* hist2 = h->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 9, 12);  hist2Str = "20-60%";
7322           TH1* hist2b = h->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 13, 15);hist2bStr = "60-90%";
7323           TH1* hist3 = h2->GetUEHist(2)->GetUEHist(0, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01);
7324         }
7325         else
7326         {
7327           Int_t step = 6;
7328           TH1* hist1 = 0;
7329           TH1* hist2 = 0;
7330           TH1* hist2b = 0;
7331           
7332           Bool_t equivMixedBin = 1;
7333           Int_t histType = 0;
7334 //        histType = 20; Printf("WARNING: Using histogram type 20");
7335           
7336 //           GetDistAndFlow(h, hMixed, &hist1,  v2, step, 0,  2,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, vn[0]); hist1Str = "0-2%";
7337 //           GetDistAndFlow(h, hMixed, &hist1,  v2, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, vn[0]); hist1Str = "0-5%";
7338           GetDistAndFlow(h, hMixed, &hist1,  v2, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin); hist1Str = "0-5%";
7339           
7340           /*
7341           new TCanvas;
7342           hist1->Draw();
7343
7344           TH1* histTmp1 = 0;
7345           GetDistAndFlow(h, hMixed, &histTmp1,  v2, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 10, equivMixedBin); hist1Str = "0-5%";
7346           histTmp1->SetLineColor(2);
7347           histTmp1->Draw("SAME");
7348           histTmp1->Scale(1 / 0.75);
7349           
7350           histTmp1 = 0;
7351           GetDistAndFlow(h, hMixed, &histTmp1,  v2, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 20, equivMixedBin); hist1Str = "0-5%";
7352           histTmp1->SetLineColor(4);
7353           histTmp1->Draw("SAME");
7354           histTmp1->Scale(1 / 0.75);
7355
7356           histTmp1 = 0;
7357           GetDistAndFlow(h, hMixed, &histTmp1,  v2, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 11, equivMixedBin); hist1Str = "0-5%";
7358           histTmp1->SetLineColor(3);
7359           histTmp1->Draw("SAME");
7360           histTmp1->Scale(1 / 0.25);
7361
7362           return;
7363           */
7364
7365           GetDistAndFlow(h, hMixed, &hist2,  v2+1, step, 0, 20, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin); hist2Str = "0-20%";
7366 //           GetDistAndFlow(h, hMixed, &hist2b, v2[2], step, 60, 80, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 0, equivMixedBin); hist2bStr = "60-80%";
7367           GetDistAndFlow(h, hMixed, &hist2b, v2+2, step, 60, 90, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin); hist2bStr = "60-90%";
7368           
7369           Printf("%f %f %f", v2[0], v2[1], v2[2]);
7370 //           Printf("%f %f %f", vn[0][1], vn[0][2], vn[0][3]);
7371           
7372 //           TH1* hist1 = h->GetUEHist(2)->GetUEHist(step, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 1, 8);    hist1Str = "0-20%";
7373 //           TH1* hist2 = h->GetUEHist(2)->GetUEHist(step, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 9, 12);   hist2Str = "20-60%";
7374 //           TH1* hist2b = h->GetUEHist(2)->GetUEHist(step, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 13, 15); hist2bStr = "60-90%";
7375           
7376           step = 6;
7377 //           TH1* hist3Old = h2->GetUEHist(2)->GetUEHist(step, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01);
7378           TH1* hist3 = 0;
7379           GetDistAndFlow(h2, hMixed2, &hist3,  0, step, 0,  -1,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin);
7380 //        hist3->Rebin(2); hist3->Scale(0.5);
7381           
7382 /*        new TCanvas;
7383           hist3->Draw();
7384           hist3Old->DrawCopy("SAME")->SetLineColor(2); */
7385         }
7386         
7387         /*
7388         RemoveBaseLine(hist1);
7389         RemoveBaseLine(hist2);
7390         RemoveBaseLine(hist2b);
7391         RemoveBaseLine(hist3);
7392         */
7393         
7394         TString newTitle;
7395         newTitle.Form("%s - %s", str.Data(), str2.Data());
7396         if (hist1)
7397         {
7398           hist1->SetName(Form("dphi_%d_%d_%d", i, j, 0));
7399           hist1->SetTitle(newTitle + " - " + hist1Str);
7400         }
7401         if (hist2)
7402         {
7403           hist2->SetName(Form("dphi_%d_%d_%d", i, j, 1));
7404           hist2->SetTitle(newTitle + " - " + hist2Str);
7405         }
7406         if (hist2b)
7407         {
7408           hist2b->SetName(Form("dphi_%d_%d_%d", i, j, 2));
7409           hist2b->SetTitle(newTitle + " - " + hist2bStr);
7410         }
7411         if (hist3)
7412         {
7413           hist3->SetName(Form("dphi_%d_%d_%d", i, j, 3));
7414           hist3->SetTitle(newTitle + " - pp");
7415         }
7416         
7417         if (0)
7418         {
7419           hist1->Scale(1.0 / hist1->Integral());
7420           hist2->Scale(1.0 / hist2->Integral());
7421           hist3->Scale(1.0 / hist3->Integral());
7422         }
7423       
7424         if (i == 0 && j == 0)
7425         {
7426           legend->SetFillColor(0);
7427           legend->AddEntry(hist1, "Pb+Pb 0-5%");
7428           if (hist2)
7429             legend->AddEntry(hist2, "Pb+Pb 20-40%");
7430           if (hist2b)
7431             legend->AddEntry(hist2b, "Pb+Pb 60-90%");
7432           if (hist3)
7433             legend->AddEntry(hist3, "p+p 7 TeV");
7434           legend->SetTextSize(0.08);
7435         }
7436       
7437         Prepare1DPlot(hist1);
7438         Prepare1DPlot(hist2);
7439         Prepare1DPlot(hist2b);
7440         Prepare1DPlot(hist3);
7441         
7442         Double_t yMin = 0.01;
7443         Double_t yMax2 = yMax;
7444         
7445         if (yMax < 0)
7446         {
7447           yMin = -0.01; //TMath::Min(hist1->GetMinimum(), hist2->GetMinimum()) * 0.97;
7448           yMax2 = TMath::Max((hist3) ? hist3->GetMaximum() : 0.0, TMath::Max(hist1->GetMaximum(), (hist2) ? hist2->GetMaximum() : 0.0)) * 1.03;
7449         }
7450         
7451         yMax2 *= 1.4;
7452       
7453         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);
7454         dummy->SetStats(kFALSE);
7455         dummy->SetXTitle(hist1->GetXaxis()->GetTitle());
7456         dummy->SetYTitle(hist1->GetYaxis()->GetTitle());
7457         dummy->SetYTitle("1/N_{trig} dN/d#Delta#phi"); 
7458         Prepare1DPlot(dummy);
7459         
7460         dummy->GetYaxis()->SetTitleOffset(0.8);
7461       
7462         dummy->GetXaxis()->SetLabelSize(0.08);
7463         dummy->GetYaxis()->SetLabelSize(0.08);
7464         dummy->GetXaxis()->SetTitleSize(0.08);
7465         dummy->GetYaxis()->SetTitleSize(0.08);
7466         /*
7467         dummy->GetYaxis()->SetTitleOffset(0.8);
7468         */
7469         
7470         dummyTmp = dummy->DrawCopy();
7471         
7472         hist1->DrawCopy("SAME");
7473         
7474         if (hMixed)
7475         {
7476           SetupRanges(hMixed);
7477           // for HI file do not set range in eta anymore after it was changed to delta eta axis
7478           hMixed->SetEtaRange(0, 0);
7479         }
7480         TH1* hist1Mixed = 0; //hMixed->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 1, 5);
7481         //DrawFlow(v2[0], hist1, leadingPtArr[i], assocPtArr[j], hist1Mixed, i, 0, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2, kFALSE, 0, vn[0]);
7482         DrawFlow(v2[0], hist1, leadingPtArr[i], assocPtArr[j], hist1Mixed, i, 0, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2, kFALSE, 0);
7483         
7484         //hist1Mixed->Draw("SAME");
7485         if (hist2)
7486         {
7487           hist2->SetLineColor(2);
7488           hist2->DrawCopy("SAME");
7489           
7490           TH1* hist2Mixed = 0; //hMixed->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 9, 10);
7491           //hist2Mixed->SetLineColor(2);
7492           //hist2Mixed->Draw("SAME");
7493
7494           DrawFlow(v2[1], hist2, leadingPtArr[i], assocPtArr[j], hist2Mixed, i, 1, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
7495           //DrawFlow(GetFlow05(), hist2, leadingPtArr[i], assocPtArr[j], hist2Mixed);
7496         }
7497         if (hist2b)
7498         {
7499           hist2b->SetLineColor(3);
7500           hist2b->DrawCopy("SAME");
7501         
7502           TH1* hist2bMixed = 0; //hMixed->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 13, 15);
7503           DrawFlow(v2[2], hist2b, leadingPtArr[i], assocPtArr[j], hist2bMixed, i, 2, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
7504           //DrawFlow(GetFlow05(), hist2b, leadingPtArr[i], assocPtArr[j], hist2bMixed);
7505         }
7506         if (hist3)
7507         {
7508           hist3->SetLineColor(4);
7509           hist3->DrawCopy("SAME");
7510           
7511           DrawFlow(0, hist3, leadingPtArr[i], assocPtArr[j], 0, i, 3, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
7512         }
7513         //dummyTmp->GetYaxis()->SetRangeUser(0, 1.1 * TMath::Max(TMath::Max(hist1->GetMaximum(), hist2->GetMaximum()), hist2b->GetMaximum()));
7514       }
7515       else // delta eta delta phi
7516       {
7517         if (twoD == 1)
7518         {
7519           if (assocPtArr[j] > leadingPtArr[i])
7520             continue;
7521         }
7522         else
7523         {
7524           Int_t jRef = 1;
7525         
7526           if (assocPtArr[jRef] > leadingPtArr[i])
7527             continue;
7528           
7529           // fix pt assoc
7530           gpTMin = assocPtArr[jRef] + 0.01;
7531           gpTMax = assocPtArr[jRef+1] - 0.01;
7532           
7533           str2.Form("%.1f < p_{T,assoc} < %.1f", gpTMin - 0.01, gpTMax + 0.01);
7534       
7535           // use j for centrality
7536           if (j >= nCentralityBins)
7537             continue;
7538             
7539           centrBegin = centralityBins[j];
7540           centrEnd = centralityBins[j+1] - 1;
7541         }
7542         
7543         SetupRanges(h);
7544         // for HI file do not set range in eta anymore after it was changed to delta eta axis
7545         h->SetEtaRange(0, 0);
7546         
7547         SetupRanges(hMixed);
7548         // for HI file do not set range in eta anymore after it was changed to delta eta axis
7549         hMixed->SetEtaRange(0, 0);
7550           
7551         TH2* histSame = (TH2*) h->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, centrBegin, centrEnd, kTRUE);
7552         TH2* histMixed = (TH2*) hMixed->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, centrBegin, centrEnd, kTRUE);
7553         
7554         // rebin 
7555         histSame->Rebin2D(2, 2);
7556         histMixed->Rebin2D(2, 2);
7557         
7558         if (1)
7559         {
7560           // fit delta eta, assuming no dependence on dphi
7561           
7562           //new TCanvas; histMixed->DrawCopy("SURF1");
7563           
7564           histMixedproj = histMixed->ProjectionY();
7565           histMixedproj->Scale(1.0 / histMixed->GetNbinsX());
7566           
7567           for (Int_t x=1; x<=histMixed->GetNbinsX(); x++)
7568             for (Int_t y=1; y<=histMixed->GetNbinsY(); y++)
7569               histMixed->SetBinContent(x, y, histMixedproj->GetBinContent(y));
7570           
7571           //new TCanvas; histMixed->DrawCopy("SURF1");
7572         }
7573         
7574         histSame->SetStats(0);
7575         histSame->GetYaxis()->SetRangeUser(-1.5, 1.5);
7576         histSame->SetTitle("");
7577         histSame->Divide(histMixed);
7578         histSame->DrawCopy("SURF1");
7579         
7580         TString str3;
7581         str3.Form("%d-%d%%", (Int_t) h->GetCentralityDistribution()->GetXaxis()->GetBinLowEdge(centrBegin), (Int_t) h->GetCentralityDistribution()->GetXaxis()->GetBinUpEdge(centrEnd));
7582         latex = new TLatex(0.15, 0.95, str3);
7583         latex->SetNDC();
7584         latex->SetTextSize(0.08);
7585         latex->Draw();
7586       }
7587       
7588       latex = new TLatex(0.55, 0.8, str);
7589       latex->SetNDC();
7590       latex->SetTextSize(0.06);
7591       latex->Draw();
7592       
7593       latex = new TLatex(0.55, 0.88, str2);
7594       latex->SetNDC();
7595       latex->SetTextSize(0.06);
7596       latex->Draw();
7597       
7598 //            if (i == 0)        return;
7599     }
7600
7601   canvas->SaveAs(Form("DeltaPhi_%.2f.png", yMax));
7602   
7603   canvas2->cd();
7604   legend2->Draw();
7605
7606   //TString name;
7607   //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]);
7608 }
7609    
7610 void ExamplePhiEtaGap(const char* fileNamePbPb, const char* fileNamePbPbMix)
7611 {
7612   loadlibs();
7613   
7614   if (!fileNamePbPbMix)
7615     fileNamePbPbMix = fileNamePbPb;
7616   
7617   Int_t leadingPtOffset = 1;
7618     
7619   Int_t maxLeadingPt = 4;
7620   Int_t maxAssocPt = 5;
7621   Float_t leadingPtArr[] = { 2.0, 3.0, 6.0, 6.0, 8.0, 10.0, 15.0, 20.0 };
7622   Float_t assocPtArr[] =     { 0.15, 0.5, 1.0, 2.0, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
7623   leadingPtOffset = 1;
7624   
7625   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileNamePbPb);
7626   hMixed = (AliUEHistograms*) GetUEHistogram(fileNamePbPbMix, 0, kTRUE);
7627   
7628   Int_t i=1;
7629   Int_t j=2;
7630   
7631   gpTMin = assocPtArr[j] + 0.01;
7632   gpTMax = assocPtArr[j+1] - 0.01;
7633   
7634   SetupRanges(h);
7635   SetupRanges(hMixed);
7636
7637   if (assocPtArr[j] >= leadingPtArr[i+leadingPtOffset])
7638     continue;
7639
7640   TString hist1Str, hist2Str, hist2bStr;
7641   
7642   Int_t step = 6;
7643   TH1* hist1 = 0;
7644   TH1* hist2 = 0;
7645   TH1* hist3 = 0;
7646   
7647   Float_t v2[3];
7648   
7649   Bool_t equivMixedBin = kTRUE;
7650   
7651   Int_t centralityBegin = 20;
7652   Int_t centralityEnd = 30;
7653   
7654   GetDistAndFlow(h, hMixed, &hist1,  0, step, centralityBegin, centralityEnd,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 20, equivMixedBin); 
7655
7656   GetDistAndFlow(h, hMixed, &hist2,  0, step, centralityBegin, centralityEnd,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 10, equivMixedBin); 
7657 //   hist2->Scale(1.0 / 0.8);
7658   
7659   GetDistAndFlow(h, hMixed, &hist3,  0, step, centralityBegin, centralityEnd,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 11, equivMixedBin); 
7660   hist3->Scale(1.0 / 0.8);
7661   
7662   hist1->Draw();
7663   hist2->SetLineColor(2);
7664   hist2->Draw("SAME");
7665   hist3->SetLineColor(4);
7666   hist3->Draw("SAME");
7667 }  
7668
7669 void ExampleDEtaDPhi(const char* fileNamePbPb, const char* fileNamePbPbMix)
7670 {
7671   loadlibs();
7672   
7673   if (!fileNamePbPbMix)
7674     fileNamePbPbMix = fileNamePbPb;
7675   
7676   Int_t leadingPtOffset = 1;
7677     
7678   Int_t maxLeadingPt = 4;
7679   Int_t maxAssocPt = 5;
7680   Float_t leadingPtArr[] = { 1.0, 2.0, 3.0, 6.0, 6.0, 8.0, 10.0, 15.0, 20.0 };
7681   Float_t assocPtArr[] =     { 0.15, 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
7682   leadingPtOffset = 1;
7683   
7684   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileNamePbPb);
7685   hMixed = (AliUEHistograms*) GetUEHistogram(fileNamePbPbMix, 0, kTRUE);
7686   
7687   Int_t i=1;
7688   Int_t j=3;
7689   
7690   gpTMin = assocPtArr[j] + 0.01;
7691   gpTMax = assocPtArr[j+1] - 0.01;
7692   
7693   SetupRanges(h);
7694   SetupRanges(hMixed);
7695
7696   Int_t step = 6;
7697   TH1* hist1 = 0;
7698
7699   GetSumOfRatios(h, hMixed, &hist1,  step, 0,  5, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
7700
7701   hist1->Draw("SURF1");
7702 }
7703
7704 Double_t GetEtaCut(TTree* analysisSettings)
7705 {
7706   Double_t etaCut = 0;
7707   if (analysisSettings)
7708   {
7709     analysisSettings->GetBranch("fTrackEtaCut")->SetAddress(&etaCut);
7710     analysisSettings->GetEntry(0);
7711   }
7712   return etaCut;
7713 }
7714
7715 void PlotDeltaPhiEtaGap(const char* fileNamePbPb, const char* fileNamePbPbMix = 0, const char* fileNamepp = 0, const char* fileNamepp2 = 0, const char* outputFile = "dphi_corr.root")
7716 {
7717   loadlibs();
7718   
7719   if (!fileNamePbPbMix)
7720     fileNamePbPbMix = fileNamePbPb;
7721   
7722   file = TFile::Open(outputFile, "RECREATE");
7723   file->Close();
7724   
7725   Int_t leadingPtOffset = 1;
7726     
7727   Bool_t symmetrizePt = kFALSE;
7728   Int_t maxLeadingPt = 4;
7729   Int_t maxAssocPt = 6;
7730   if (1)
7731   {
7732     //PbPb, NS peak shapes
7733     Float_t leadingPtArr[] = { 1.0, 2.0, 3.0, 4.0, 8.0, 15.0, 20.0 };
7734 //     Float_t leadingPtArr[] = { 2.0, 3.0, 4.0, 8.0, 15.0, 20.0 };
7735     Float_t assocPtArr[] =     { 0.15, 0.5, 1.0, 2.0, 3.0, 4.0, 8.0, 10.0, 12.0 };
7736   }
7737   else if (0)
7738   {
7739     //Example for the Hadrons_Example wagon
7740     maxLeadingPt = 3;
7741     maxAssocPt = 6;
7742     Float_t leadingPtArr[] =     { 3.0, 5.0, 8.0, 16.0 };
7743     Float_t assocPtArr[] = {0.15, 0.3, 50.0, 0.5, 50.0, 1.0, 50.0 };
7744   }
7745   else if (0)
7746   {
7747     //pA, trigger from all pT
7748     maxLeadingPt = 1;
7749     maxAssocPt = 10;
7750     Float_t leadingPtArr[] =   { 0.3, 4.0 };
7751     Float_t assocPtArr[] =     { 0.15, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 4.0, 5.0, 0.5, 4.0 };
7752 //     symmetrizePt = kTRUE;
7753   }
7754   else if (0)
7755   {
7756     //pA, associated from all pT
7757     maxLeadingPt = 6;
7758     maxAssocPt = 2;
7759     Float_t leadingPtArr[] =     { 0.5, 1.0, 2.0, 3.0, 4.0, 0.5, 4.0 };
7760     Float_t assocPtArr[] = { 0.15, 0.5, 4.0 };
7761 //     symmetrizePt = kTRUE;
7762   }  
7763   else if (0)
7764   {
7765     //pA
7766     maxLeadingPt = 5;
7767     maxAssocPt = 6;
7768     Float_t leadingPtArr[] = { 0.5, 1.0, 1.5, 2.0, 2.5,  4.0, 8.0, 15.0, 20.0 };
7769     Float_t assocPtArr[] =     { 0.15, 0.5, 1.0, 1.5, 2.0, 2.5, 4.0, 8.0, 10.0, 12.0 };
7770   }
7771   else if (0)
7772   {
7773     //pPb and PbPb with PID, with low pt points TPC only
7774     maxLeadingPt = 10;
7775     maxAssocPt = 11;
7776     Float_t leadingPtArr[] = {   0.2, 0.3, 0.5 , 0.75, 1.0, 1.25, 1.5, 2.0, 2.5, 3., 4.0};
7777     Float_t assocPtArr[] =   { 0.15, 0.2, 0.3, 0.5 , 0.75, 1.0, 1.25, 1.5, 2.0, 2.5, 3., 4.0 };
7778   }
7779   else if (1)
7780   {
7781     //PbPb for comaprison with You
7782     maxLeadingPt = 8;
7783     maxAssocPt = 9;
7784     Float_t leadingPtArr[] = {   0.2, 0.3, 0.5 , 1.0, 1.5, 2.0, 2.5, 3., 4.0};
7785     Float_t assocPtArr[] =   { 0.15, 0.2, 0.3, 0.5 , 1.0, 1.5, 2.0, 2.5, 3., 4.0 };
7786   }
7787   else if (1)
7788   {
7789     //pA, fine
7790     maxLeadingPt = 6;
7791     maxAssocPt = 7;
7792     Float_t leadingPtArr[] =   {       0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 4.0, 5.0, 0.5, 4.0, 20.0 };
7793     Float_t assocPtArr[] =     { 0.15, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 4.0, 5.0, 0.5, 4.0, 12.0 };
7794   }
7795   else if (0)
7796   {
7797     //pA, v3
7798     maxLeadingPt = 3;
7799     maxAssocPt = 4;
7800     Float_t leadingPtArr[] =   {       0.5, 1.5, 2.5, 4.0, 5.0, 8.0, 15.0, 20.0 };
7801     Float_t assocPtArr[] =     { 0.15, 0.5, 1.5, 2.5, 4.0, 5.0, 8.0, 10.0, 12.0 };
7802   }
7803   else if (0)
7804   {
7805     //pA 2012; MC validation (also PbPb)
7806     maxLeadingPt = 3;
7807     maxAssocPt = 4;
7808     Float_t leadingPtArr[] = { 0.5, 1.0, 2.0, 4.0, 8.0, 15.0, 20.0 };
7809     Float_t assocPtArr[] =     { 0.15, 0.5, 1.0, 2.0, 4.0, 8.0, 10.0, 12.0 };
7810   }
7811   else if (0)
7812   {
7813     // pA, CMS ridge comparison
7814     maxLeadingPt = 4;
7815     maxAssocPt = 5;
7816     Float_t leadingPtArr[] = { 0.5, 1.0, 2.0, 3.0, 4.0, 8.0, 15.0, 20.0 };
7817     Float_t assocPtArr[] =     { 0.15, 0.5, 1.0, 2.0, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
7818   }
7819   else if (0) 
7820   {
7821     maxLeadingPt = 1;
7822     maxAssocPt = 3;
7823     Float_t leadingPtArr[] = { 2.0, 3.0};
7824     Float_t assocPtArr[] =     {0.15, 0.5, 1.0, 2.0};
7825   }
7826   else if (0) //Comparison to STAR (p_T,t)
7827   {
7828     maxLeadingPt = 4;
7829     maxAssocPt = 3;
7830     Float_t leadingPtArr[] = { 2.0, 3.0, 4.0, 5.0, 6.0};
7831     Float_t assocPtArr[] =     {0.15, 0.5, 1.5, 6.0};
7832   }
7833   else if (0) //Comparison to STAR (p_T,a)
7834   {
7835     maxLeadingPt = 1;
7836     maxAssocPt = 6;
7837     Float_t leadingPtArr[] = { 3.0, 6.0};
7838     Float_t assocPtArr[] =     {0.15, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0};
7839   }
7840   else if (0) 
7841   {
7842     maxLeadingPt = 4;
7843     maxAssocPt = 4;
7844     Float_t leadingPtArr[] = { 2.0, 3.0, 4.0, 8.0, 15.0 };
7845     Float_t assocPtArr[] =     {0.15, 0.5, 1.0, 1.5, 2.0};
7846   }
7847   
7848   TList* list = 0;
7849   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileNamePbPb, &list);
7850   hMixed = (AliUEHistograms*) GetUEHistogram(fileNamePbPbMix, 0, kTRUE);
7851 //   hMixed3 = (AliUEHistograms*) hMixed->Clone();
7852   
7853   if (symmetrizePt)
7854   {
7855     h->GetUEHist(2)->SymmetrizepTBins();
7856     hMixed->GetUEHist(2)->SymmetrizepTBins();
7857   }
7858   
7859   TList* list2 = 0;
7860   AliUEHistograms* h2 = 0;
7861   AliUEHistograms* hMixed2 = 0;
7862   if (fileNamepp)
7863   {
7864     h2 = (AliUEHistograms*) GetUEHistogram(fileNamepp, &list2);
7865     hMixed2 = (AliUEHistograms*) GetUEHistogram(fileNamepp, 0, kTRUE);
7866   }
7867
7868   TList* list3 = 0;
7869   AliUEHistograms* h3 = 0;
7870   AliUEHistograms* hMixed3 = 0;
7871   if (fileNamepp2)
7872   {
7873     h3 = (AliUEHistograms*) GetUEHistogram(fileNamepp2, &list3);
7874     hMixed3 = (AliUEHistograms*) GetUEHistogram(fileNamepp2, 0, kTRUE);
7875   }
7876
7877 //   h->GetUEHist(2)->SetGetMultCache();
7878 //   hMixed->GetUEHist(2)->SetGetMultCache();
7879
7880   TH2* refMultRaw = (TH2*) list->FindObject("referenceMultiplicity");
7881   if (refMultRaw)
7882   {
7883 //     new TCanvas; refMultRaw->Draw("COLZ");
7884     Int_t nCentrBins = 4;
7885     Double_t centrBins[] = { 0., 20., 40., 60., 100. };
7886 //     Double_t centrBins[] = { 0., 3., 10., 50., 100. };
7887     TH1* refMult = new TH1F("refMult", ";centrality;<Nch>", nCentrBins, centrBins);
7888     for (Int_t i=0; i<nCentrBins; i++)
7889     {
7890       TH1* proj = refMultRaw->ProjectionY(Form("proj%d", i), refMultRaw->GetXaxis()->FindBin(centrBins[i] + 0.1), refMultRaw->GetXaxis()->FindBin(centrBins[i+1] - 0.1));
7891 //       new TCanvas; proj->DrawClone();
7892       refMult->SetBinContent(refMult->GetXaxis()->FindBin(centrBins[i] + 0.1), proj->GetMean());
7893       refMult->SetBinError(refMult->GetXaxis()->FindBin(centrBins[i] + 0.1), proj->GetMeanError());
7894       Printf("Ref multiplicity for centrality %f to %f: %f", centrBins[i], centrBins[i+1], proj->GetMean());
7895     }
7896 //     new TCanvas; refMult->Draw();
7897     file = TFile::Open(outputFile, "UPDATE");
7898     refMult->Write();
7899     file->Close();
7900 //     return;
7901   }
7902
7903   tree = (TTree*) list->FindObject("UEAnalysisSettings");
7904   Double_t etaCut = GetEtaCut(tree);
7905   Printf("Setting eta cut to %f", etaCut);
7906   h->SetTrackEtaCut(etaCut);
7907
7908   if (list2)
7909   {
7910     tree = (TTree*) list2->FindObject("UEAnalysisSettings");
7911     if (tree)
7912     {
7913       Double_t etaCut = GetEtaCut(tree);
7914       Printf("Setting eta cut to %f", etaCut);
7915       h2->SetTrackEtaCut(etaCut);
7916     }
7917     else
7918     {
7919       Double_t etaCut = 0.9;
7920       Printf("WARNING: Setting eta cut to %f without checking", etaCut);
7921       h2->SetTrackEtaCut(etaCut);
7922     }
7923   }
7924
7925   if (list3)
7926   {
7927     tree = (TTree*) list3->FindObject("UEAnalysisSettings");
7928     if (tree)
7929     {
7930       Double_t etaCut = GetEtaCut(tree);
7931       Printf("Setting eta cut to %f", etaCut);
7932       h3->SetTrackEtaCut(etaCut);
7933     }
7934     else
7935     {
7936       Double_t etaCut = 0.9;
7937       Printf("WARNING: Setting eta cut to %f without checking", etaCut);
7938       h3->SetTrackEtaCut(etaCut);
7939     }
7940   }
7941   
7942   //   return;
7943   
7944   if (0)
7945   {
7946     h->SetZVtxRange(-0.99, 0.99);
7947     hMixed->SetZVtxRange(-0.99, 0.99);
7948     h2->SetZVtxRange(-0.99, 0.99);
7949     hMixed2->SetZVtxRange(-0.99, 0.99);
7950   }
7951   
7952   for (Int_t i=0; i<maxLeadingPt; i++)
7953   {
7954     for (Int_t j=1; j<maxAssocPt; j++)
7955     {
7956       if(0){
7957         if(j!=(i+1))continue;
7958         Printf("\nOnly symmetric pt bins selected, leading pt: %f - %f     associated pt: %f - %f",leadingPtArr[i],leadingPtArr[i+leadingPtOffset],assocPtArr[j],assocPtArr[j+1]); 
7959       }
7960
7961       gpTMin = assocPtArr[j] + 0.01;
7962       gpTMax = assocPtArr[j+1] - 0.01;
7963       
7964       if(gpTMin >= gpTMax)continue;
7965         
7966       SetupRanges(h);
7967       SetupRanges(hMixed);
7968       SetupRanges(h2);
7969       SetupRanges(hMixed2);
7970       SetupRanges(h3);
7971       SetupRanges(hMixed3);
7972 //       SetupRanges(hMixed3);
7973
7974       if(1) if (assocPtArr[j] >= leadingPtArr[i+leadingPtOffset])
7975         continue;
7976   
7977       TH1* hist1 = 0;
7978       TH1* hist2 = 0;
7979       TH1* hist3 = 0;
7980       TH1* hist4 = 0;
7981       TH1* hist5 = 0;
7982       TH1* hist6 = 0;
7983       TH1* hist7 = 0;
7984       TH1* hist8 = 0;
7985       
7986       Bool_t equivMixedBin = 1; //kFALSE; // TODO ?
7987       Bool_t scaleToPairs = kTRUE;
7988       
7989       Int_t histType = 1;
7990
7991       if (1)
7992       {
7993         // PbPb
7994         Int_t step = 8;
7995         Bool_t normalizePerTrigger = kFALSE; // don't do if histograms are to be merged -> Use MergeDPhiFiles below
7996       
7997         GetSumOfRatios(h, hMixed, &hist1,  step, 0,   10, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, normalizePerTrigger); 
7998         GetSumOfRatios(h, hMixed, &hist5,  step, 10,  20, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, normalizePerTrigger); 
7999         GetSumOfRatios(h, hMixed, &hist4,  step, 20,  40, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, normalizePerTrigger); 
8000         GetSumOfRatios(h, hMixed, &hist6,  step, 40,  60, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, normalizePerTrigger); 
8001         GetSumOfRatios(h, hMixed, &hist2,  step, 60,  80, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, normalizePerTrigger); 
8002 //      GetSumOfRatios(h, hMixed, &hist7,  step, 70,  80, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, normalizePerTrigger); 
8003 //      GetSumOfRatios(h, hMixed, &hist8,  step, 80,  90, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, normalizePerTrigger); 
8004
8005         if (h2)
8006           GetSumOfRatios(h2, hMixed2, &hist3,  step, 0,  -1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8007       }
8008       else if (0)
8009       {
8010         // pA, fine binning
8011         Int_t step = 8;
8012 //      Int_t step = 0;
8013       
8014         GetSumOfRatios(h, hMixed, &hist1,  step,  0, 20, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8015         GetSumOfRatios(h, hMixed, &hist2,  step, 20, 40, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8016         GetSumOfRatios(h, hMixed, &hist4,  step, 40, 60, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8017         GetSumOfRatios(h, hMixed, &hist5,  step, 60, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8018 //      GetSumOfRatios(h, hMixed, &hist7,  step, 70, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8019 //      GetSumOfRatios(h, hMixed, &hist8,  step, 80, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8020
8021         if (h2)
8022           GetSumOfRatios(h2, hMixed2, &hist3,  step, 0,  -1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8023         
8024         if (h3)
8025           GetSumOfRatios(h3, hMixed3, &hist6,  step, 0,  -1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8026       }      
8027       else if (0)
8028       {
8029         // pA, V0 as trigger particle detector
8030         Int_t step = 6;
8031       
8032         h->GetUEHist(2)->SetSkipScaleMixedEvent(kTRUE);
8033         GetSumOfRatios(h, hMixed, &hist1,  step,  0, 20, 1.01, 1.99, kTRUE); 
8034         GetSumOfRatios(h, hMixed, &hist2,  step, 20, 40, 1.01, 1.99, kTRUE); 
8035         GetSumOfRatios(h, hMixed, &hist4,  step, 40, 60, 1.01, 1.99, kTRUE); 
8036         GetSumOfRatios(h, hMixed, &hist5,  step, 60, 100, 1.01, 1.99, kTRUE); 
8037
8038         if (h2)
8039           GetSumOfRatios(h2, hMixed2, &hist3,  step, 0,  -1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8040         
8041         if (h3)
8042           GetSumOfRatios(h3, hMixed3, &hist6,  step, 0,  -1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8043       }      
8044       else if (0)
8045       {
8046         // pp, MB
8047         Int_t step = 8;      
8048         GetSumOfRatios(h, hMixed, &hist1,  step, 0, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE, kTRUE); 
8049       }      
8050       else if (0)
8051       {
8052         // pp
8053         Int_t step = 8;
8054       
8055         GetSumOfRatios(h, hMixed, &hist1,  step, 4, 4, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE, kTRUE); 
8056         GetSumOfRatios(h, hMixed, &hist2,  step, 3, 3, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE, kTRUE); 
8057         GetSumOfRatios(h, hMixed, &hist4,  step, 2, 2, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE, kTRUE); 
8058         GetSumOfRatios(h, hMixed, &hist5,  step, 1, 1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE, kTRUE); 
8059       }      
8060       else if (0)
8061       {
8062         // pA, course binning
8063         Int_t step = 8;
8064       
8065         GetSumOfRatios(h, hMixed, &hist1,  step,  0, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8066         GetSumOfRatios(h, hMixed, &hist2,  step,  0,  40, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8067         GetSumOfRatios(h, hMixed, &hist4,  step, 40, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8068
8069         GetDistAndFlow(h, hMixed, &hist5,  0, step, 0, 100,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8070
8071         GetSumOfRatios(h2, hMixed2, &hist3,  step, 0,  -1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8072       }      
8073       else if (0)
8074       {
8075         // pA, CMS ridge paper comparison
8076         Int_t step = 8;
8077       
8078         GetSumOfRatios(h, hMixed, &hist1,  step,  0, 3, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8079         GetSumOfRatios(h, hMixed, &hist2,  step,  3, 10, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8080         GetSumOfRatios(h, hMixed, &hist4,  step, 10, 50, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8081         GetSumOfRatios(h, hMixed, &hist5,  step, 50, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8082         GetSumOfRatios(h, hMixed, &hist7,  step, 80, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8083       }     
8084       else if (0)
8085       {
8086         // pA, MC, validation binning
8087         GetSumOfRatios(h, hMixed, &hist1,  0,  0, 80, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8088         GetSumOfRatios(h, hMixed, &hist5,  10,  0, 80, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8089       }        
8090       else if (0)
8091       {
8092         // pA, MC, validation binning
8093         GetSumOfRatios(h, hMixed, &hist1,  0,  0, 20, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8094         GetSumOfRatios(h, hMixed, &hist2,  0,  20, 40, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8095         GetSumOfRatios(h, hMixed, &hist3,  0,  40, 60, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8096         GetSumOfRatios(h, hMixed, &hist4,  0,  60, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8097         GetSumOfRatios(h, hMixed, &hist5,  10,  0, 20, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8098         GetSumOfRatios(h, hMixed, &hist6,  10,  20, 40, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8099         GetSumOfRatios(h, hMixed, &hist7,  10,  40, 60, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8100         GetSumOfRatios(h, hMixed, &hist8,  10,  60, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8101       }        
8102       else if (0)
8103       {
8104         // pp, MB
8105         Int_t step = 8;
8106         
8107         GetSumOfRatios(h, hMixed, &hist1,  step,  0, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8108       }      
8109       else if (0)
8110       {
8111         // pA, MC, validation binning, without vertex axis
8112         GetDistAndFlow(h, hMixed, &hist1,  0, 0,  0, 20, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8113         GetDistAndFlow(h, hMixed, &hist2,  0, 0,  20, 40, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8114         GetDistAndFlow(h, hMixed, &hist3,  0, 0,  40, 60, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8115         GetDistAndFlow(h, hMixed, &hist4,  0, 0,  60, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8116         GetDistAndFlow(h, hMixed, &hist5,  0, 10,  0, 20, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8117         GetDistAndFlow(h, hMixed, &hist6,  0, 10,  20, 40, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8118         GetDistAndFlow(h, hMixed, &hist7,  0, 10,  40, 60, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8119         GetDistAndFlow(h, hMixed, &hist8,  0, 10,  60, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8120       }        
8121       else if (1)
8122       {
8123         // PbPb, MC, impact parameter binning
8124         Int_t step = 0;
8125         
8126         Printf(">>>>>>>> Not using GetSumOfRatios!!!");
8127
8128         GetDistAndFlow(h, hMixed, &hist1,  0, step, 1,   6,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs, -1, kTRUE); 
8129         GetDistAndFlow(h, hMixed, &hist5,  0, step, 7,  7, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs, -1, kTRUE); 
8130         GetDistAndFlow(h, hMixed, &hist4,  0, step, 8,  9, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs, -1, kTRUE); 
8131         GetDistAndFlow(h, hMixed, &hist6,  0, step, 10,  11, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs, -1, kTRUE); 
8132         GetDistAndFlow(h, hMixed, &hist2,  0, step, 12,  13, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs, -1, kTRUE);
8133
8134         if (h2)
8135           GetDistAndFlow(h2, hMixed2, &hist3,  0, step, 0, -1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs);
8136       }
8137       else if (1)
8138       {
8139         // PbPb, MC
8140         Int_t step = 0;
8141         
8142         Printf(">>>>>>>> Not using GetSumOfRatios!!!");
8143         GetDistAndFlow(h, hMixed, &hist1,  0, step, 0,   10,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8144 //      Printf("integral: %f", ((TH2*) hist1)->Integral(1, 36, 5, 36));
8145 //      return;
8146
8147         GetDistAndFlow(h, hMixed, &hist5,  0, step, 10,  20, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8148         GetDistAndFlow(h, hMixed, &hist4,  0, step, 20,  40, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8149         GetDistAndFlow(h, hMixed, &hist6,  0, step, 40,  60, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8150         GetDistAndFlow(h, hMixed, &hist2,  0, step, 60,  80, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs);
8151 //      step = 6;
8152         if (h2)
8153           GetDistAndFlow(h2, hMixed2, &hist3,  0, step, 0, -1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs);
8154 //      new TCanvas; hist3->DrawClone("SURF1");
8155 //      GetDistAndFlow(hMixed2, 0, &hist3,  0, step, 0, -1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs);
8156 //      new TCanvas; hist3->DrawClone("SURF1");
8157 //      Printf("integral: %f", ((TH2*) hist3)->Integral(1, 36, 5, 36));
8158 //      return;
8159         
8160         //MC closure test in pA and PbPb with PID
8161         // GetDistAndFlow(h, hMixed, &hist1,  0, step,  0,   20,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8162         // GetDistAndFlow(h, hMixed, &hist2,  0, step, 20,  40,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8163         // GetDistAndFlow(h, hMixed, &hist4,  0, step, 40,  60,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8164         // GetDistAndFlow(h, hMixed, &hist5,  0, step, 60, 100,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8165         // GetDistAndFlow(h, hMixed, &hist7,  0, step, 80, 100,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8166         // GetDistAndFlow(h, hMixed, &hist8,  0, step,  0,  100,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8167       }
8168       else if (0)
8169       {
8170         Int_t step = 8;
8171  
8172         GetSumOfRatios(h, hMixed, &hist1,  step, 60,  70, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8173         GetSumOfRatios(h, hMixed, &hist2,  step, 70,  80, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8174         GetSumOfRatios(h, hMixed, &hist3,  step, 80,  90, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8175       }
8176       else if (1)
8177       {
8178         Int_t step = 8;
8179  
8180         GetSumOfRatios(h, hMixed, &hist1,  step, 0,  1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8181         GetSumOfRatios(h, hMixed, &hist2,  step, 1,  3, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8182         GetSumOfRatios(h, hMixed, &hist4,  step, 3,  5, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8183         GetSumOfRatios(h, hMixed, &hist5,  step, 5,  10, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8184         GetSumOfRatios(h, hMixed, &hist6,  step, 10,  20, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8185       }
8186
8187       file = TFile::Open(outputFile, "UPDATE");
8188       
8189       if (hist1)
8190       {
8191         hist1->SetName(Form("dphi_%d_%d_%d", i, j, 0));
8192         hist1->Write();
8193       }
8194       
8195       if (hist2)
8196       {
8197         hist2->SetName(Form("dphi_%d_%d_%d", i, j, 1));
8198         hist2->Write();
8199       }
8200       
8201       if (hist4)
8202       {
8203         hist4->SetName(Form("dphi_%d_%d_%d", i, j, 3));
8204         hist4->Write();
8205       }
8206
8207       if (hist5)
8208       {
8209         hist5->SetName(Form("dphi_%d_%d_%d", i, j, 4));
8210         hist5->Write();
8211       }
8212       
8213       if (hist7)
8214       {
8215         hist7->SetName(Form("dphi_%d_%d_%d", i, j, 6));
8216         hist7->Write();
8217       }
8218
8219       if (hist8)
8220       {
8221         hist8->SetName(Form("dphi_%d_%d_%d", i, j, 7));
8222         hist8->Write();
8223       }
8224
8225       if (hist6)
8226       {
8227         hist6->SetName(Form("dphi_%d_%d_%d", i, j, 5));
8228         TString title(hist6->GetTitle());
8229         title.ReplaceAll("0--1%", "pp");
8230         hist6->SetTitle(title);
8231         hist6->Write();
8232       }
8233       
8234       if (hist3)
8235       {
8236         hist3->SetName(Form("dphi_%d_%d_%d", i, j, 2));
8237         TString title(hist3->GetTitle());
8238         title.ReplaceAll("0--1%", "pp");
8239         hist3->SetTitle(title);
8240         hist3->Write();
8241       }
8242       
8243       file->Close();
8244
8245       delete hist1;
8246       delete hist2;
8247       delete hist3;
8248       delete hist4;
8249       delete hist5;
8250       delete hist6;
8251       delete hist7;
8252       delete hist8;      
8253       
8254 //       return;
8255     }
8256     
8257     TH1* triggers = h->GetUEHist(2)->GetTriggersAsFunctionOfMultiplicity(step, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01);
8258     triggers->SetName(Form("triggers_%d", i));
8259     TString str;
8260     str.Form("%.1f < p_{T,trig} < %.1f", leadingPtArr[i], leadingPtArr[i+leadingPtOffset]);
8261     triggers->SetTitle(str);
8262
8263     file = TFile::Open(outputFile, "UPDATE");
8264     triggers->Write();
8265     file->Close();    
8266   }
8267     
8268   delete h;
8269   delete hMixed;
8270 }
8271
8272 void MergeDPhiFiles(const char* fileName, const char* fileName2, const char* target)
8273 {
8274   // merges the dphi histograms (except the pp histogram at index "2") as well as the triggers
8275   // then divides the dphi histograms by the respective number of triggers
8276  
8277   file = TFile::Open(fileName);
8278   file2 = TFile::Open(fileName2);
8279
8280   fileTarget = TFile::Open(target, "RECREATE");
8281   fileTarget->Close();
8282   
8283   Int_t maxLeadingPt = 10;
8284   Int_t maxAssocPt = 11;
8285
8286   Int_t nHists = 8;
8287   for (Int_t i=0; i<maxLeadingPt; i++)
8288   {
8289     TH1* triggers = (TH1*) file->Get(Form("triggers_%d", i));
8290     if (!triggers)
8291       continue;
8292     
8293     TH1* triggers2 = (TH1*) ((file2) ? file2->Get(Form("triggers_%d", i)) : 0);
8294     if (!triggers2)
8295       Printf("WARNING: trigger %d missing", i);
8296     
8297     for (Int_t j=0; j<maxAssocPt; j++)
8298     {
8299       for (Int_t histId = 0; histId < nHists; histId++)
8300       {
8301         TH2* hist = (TH2*) file->Get(Form("dphi_%d_%d_%d", i, j, histId));
8302         if (!hist)
8303         {
8304           TH2* hist2 = (TH2*) ((file2) ? file2->Get(Form("dphi_%d_%d_%d", i, j, histId)) : 0);
8305           if (hist2)
8306             Printf("WARNING: %d %d %d exists only in file2, not copied!");
8307           continue;
8308         }
8309         
8310         if (histId != 2) // don't merge pp
8311         {
8312           TString title(hist->GetTitle());
8313           title.ReplaceAll("%", "");
8314           tokens = title.Tokenize("-");
8315           
8316           Float_t centralityBegin = ((TObjString*) tokens->At(2))->String().Atoi();
8317           Float_t centralityEnd = ((TObjString*) tokens->At(3))->String().Atoi();
8318           
8319           Double_t nTriggers = triggers->Integral(triggers->FindBin(centralityBegin + 0.001), triggers->FindBin(centralityEnd - 0.001));
8320           Double_t nTriggers2 = 0;
8321
8322           TH2* hist2 = (TH2*) ((file2) ? file2->Get(Form("dphi_%d_%d_%d", i, j, histId)) : 0);
8323           if (hist2 && triggers2) 
8324           {
8325             if (histId != 1 && histId != 5) // don't merge 60-80% and 40-60%
8326             {
8327               hist->Add(hist2);
8328               nTriggers2 = triggers2->Integral(triggers2->FindBin(centralityBegin + 0.001), triggers2->FindBin(centralityEnd - 0.001));
8329             }
8330           }
8331           else
8332             Printf("WARNING: %d %d %d missing", i, j, histId);
8333             
8334           if (nTriggers + nTriggers2 > 0)
8335             hist->Scale(1.0 / (nTriggers + nTriggers2));
8336
8337           Printf("%s %f %f %f %f", hist->GetTitle(), centralityBegin, centralityEnd, nTriggers, nTriggers2);
8338         }
8339
8340         fileTarget = TFile::Open(target, "UPDATE");
8341         hist->Write();
8342         fileTarget->Close();
8343       }
8344     }
8345   }
8346 }
8347
8348 void ExtractMiniJetHistograms(const char* fileNamePbPb, Bool_t useMixed = kTRUE, const char* outputFile = "dphi_corr.root")
8349 {
8350   loadlibs();
8351   
8352   file = TFile::Open(outputFile, "RECREATE");
8353   file->Close();
8354   
8355   Int_t leadingPtOffset = 1;
8356     
8357   if (1)
8358   { 
8359     // minijets
8360     Int_t maxLeadingPt = 1;
8361     Int_t maxAssocPt = 1;
8362     Float_t leadingPtArr[] = { 0.7, 5.0 };
8363     Float_t assocPtArr[] =   { 0.7, 5.0 };
8364   }
8365   
8366   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileNamePbPb);
8367   hMixed = (AliUEHistograms*) GetUEHistogram(fileNamePbPb, 0, kTRUE);
8368   
8369   Int_t step = 8;
8370
8371   for (Int_t i=0; i<maxLeadingPt; i++)
8372   {
8373     for (Int_t j=0; j<maxAssocPt; j++)
8374     {
8375 //       i = 3; j = 6;
8376       
8377       gpTMin = assocPtArr[j] + 0.01;
8378       gpTMax = assocPtArr[j+1] - 0.01;
8379       
8380       SetupRanges(h);
8381       SetupRanges(hMixed);
8382
8383       if (assocPtArr[j] >= leadingPtArr[i+leadingPtOffset])
8384         continue;
8385   
8386       if (1)
8387       {
8388         // pA, minijets, very fine binning
8389         
8390         for (Int_t centr=0; centr<20; centr++)
8391         {
8392           TH1* hist1 = 0;
8393           if (useMixed)
8394             GetSumOfRatios(h, hMixed, &hist1, step, 5*centr, 5*centr+5, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kFALSE); 
8395           else
8396             GetDistAndFlow(h, 0, &hist1, 0, step, 5*centr, 5*centr+5, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 1, 1, 0, kTRUE); 
8397           
8398           if (!hist1)
8399             continue;
8400
8401           file = TFile::Open(outputFile, "UPDATE");
8402           hist1->SetName(Form("dphi_%d_%d_%d", i, j, centr));
8403           hist1->Write();
8404           file->Close();
8405           
8406           delete hist1;
8407         }
8408       }
8409     }
8410     
8411     TH1* triggers = h->GetUEHist(2)->GetTriggersAsFunctionOfMultiplicity(step, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01);
8412     triggers->SetName(Form("triggers_%d", i));
8413     TString str;
8414     str.Form("%.1f < p_{T,trig} < %.1f", leadingPtArr[i], leadingPtArr[i+leadingPtOffset]);
8415     triggers->SetTitle(str);
8416
8417     file = TFile::Open(outputFile, "UPDATE");
8418     triggers->Write();
8419     file->Close();
8420   }
8421   
8422   TH1* events = h->GetEventCount()->ProjectionY("events", h->GetEventCount()->GetXaxis()->FindBin(step), h->GetEventCount()->GetXaxis()->FindBin(step));
8423   file = TFile::Open(outputFile, "UPDATE");
8424   events->Write("events");
8425   file->Close();
8426 }
8427
8428 TLatex* DrawLatex(Float_t x, Float_t y, Int_t color, const char* text, Float_t fontSize = 0.06)
8429 {
8430   latex = new TLatex(x, y, text);
8431   latex->SetNDC();
8432   latex->SetTextSize(fontSize);
8433   latex->SetTextColor(color);
8434   latex->Draw();
8435   return latex;
8436 }
8437
8438 void DrawChi2NDF(TF1* func, TH1* hist, Float_t x, Float_t y, Int_t color = 1)
8439 {
8440   Float_t chi2 = 0;
8441   Int_t ndf = 0;
8442   for (Int_t i=hist->GetXaxis()->FindBin(-0.8); i<=hist->GetXaxis()->FindBin(0.8); i++)
8443   {
8444     chi2 += TMath::Power((hist->GetBinContent(i) - func->Integral(hist->GetXaxis()->GetBinLowEdge(i), hist->GetXaxis()->GetBinUpEdge(i)) / (hist->GetXaxis()->GetBinUpEdge(i) - hist->GetXaxis()->GetBinLowEdge(i))) / hist->GetBinError(i), 2);
8445     ndf++;
8446   }
8447   ndf -= func->GetNumberFreeParameters();
8448   
8449   printf("#chi^{2}/ndf = %.1f/%d = %.1f  ", func->GetChisquare(), func->GetNDF(), func->GetChisquare() / func->GetNDF());
8450   Printf("#chi^{2}/ndf = %.1f/%d = %.1f", chi2, ndf, chi2 / ndf);
8451
8452   DrawLatex(x, y, color, Form("#chi^{2}/ndf = %.1f/%d = %.1f", func->GetChisquare(), func->GetNDF(), func->GetChisquare() / func->GetNDF()));
8453   DrawLatex(x, y - 0.05, color, Form("#chi^{2}/ndf = %.1f/%d = %.1f", chi2, ndf, chi2 / ndf));
8454 }   
8455    
8456 void FitDeltaPhiEtaGap(TH1* hist, Int_t color, TGraphErrors* graph, Float_t x, Float_t yPosChi2)
8457 {
8458   hist->SetLineColor(color);
8459   hist->DrawCopy("SAME");
8460
8461   Bool_t twoGauss = kFALSE;
8462   
8463   if (!twoGauss)
8464     func = new TF1("func", "[0]+gaus(1)");
8465   else
8466   {
8467     func = new TF1("func", "[0]+gaus(1)+gaus(4)");
8468     func->FixParameter(5, 0);
8469     func->SetParLimits(3, 0.1, 10);
8470     func->SetParLimits(6, 0.1, 10);
8471     func->SetParLimits(1, 0, 10);
8472     func->SetParLimits(4, 0, 10);
8473   }
8474   
8475   func->SetParameters(0, 1, 0, 0.3, 1, 0, 1);
8476   func->FixParameter(2, 0);
8477   func->SetLineColor(color);
8478
8479   hist->Fit(func, "", "SAME");
8480 //   hist->Fit(func, "IM", "SAME");
8481   
8482   if (twoGauss)
8483   {
8484     func2 = new TF1("func2", "[0]+gaus(1)", -1.5, 4.5);
8485     func2->SetParameters(func->GetParameter(0), func->GetParameter(1), func->GetParameter(2), func->GetParameter(3));
8486     func2->SetLineColor(color);
8487     func2->SetLineWidth(1);
8488     func2->SetLineStyle(2);
8489     func2->Draw("SAME");
8490     
8491     func2 = new TF1("func2", "[0]+gaus(1)", -1.5, 4.5);
8492     func2->SetParameters(func->GetParameter(0), func->GetParameter(4), func->GetParameter(5), func->GetParameter(6));
8493     func2->SetLineColor(color);
8494     func2->SetLineWidth(1);
8495     func2->SetLineStyle(2);
8496     func2->Draw("SAME");
8497   }
8498       
8499   if (twoGauss)
8500   {
8501     Bool_t firstIsMin = func->GetParameter(3) < func->GetParameter(6);
8502     
8503     Bool_t onlyOne = kFALSE;
8504     if (func->GetParameter(1) / func->GetParameter(4) < 0.1)
8505     {
8506       firstIsMin = kFALSE;
8507       onlyOne = kTRUE;
8508     }
8509     if (func->GetParameter(1) / func->GetParameter(4) > 10)
8510     {
8511       firstIsMin = kTRUE;
8512       onlyOne = kTRUE;
8513     }
8514     
8515     graph->SetPoint(graph->GetN(), x - 0.1, func->GetParameter((firstIsMin) ? 3 : 6));
8516     graph->SetPointError(graph->GetN()-1, 0, func->GetParError((firstIsMin) ? 3 : 6));
8517
8518     if (!onlyOne)
8519     {
8520       graph->SetPoint(graph->GetN(), x + 0.1, TMath::Abs(func->GetParameter((!firstIsMin) ? 3 : 6)));
8521       graph->SetPointError(graph->GetN()-1, 0, func->GetParError((!firstIsMin) ? 3 : 6));
8522     }
8523   }
8524   else
8525   {
8526     graph->SetPoint(graph->GetN(), x, TMath::Abs(func->GetParameter(3)));
8527     graph->SetPointError(graph->GetN()-1, 0, func->GetParError(3));
8528   }  
8529     
8530   DrawChi2NDF(func, hist, 0.5, yPosChi2, color);
8531 }
8532
8533 void AnalyzeDeltaPhiEtaGap(const char* fileName)
8534 {
8535   TFile::Open(fileName);
8536   
8537   Int_t maxLeadingPt = 5;
8538   Int_t maxAssocPt = 6;
8539
8540   TCanvas* canvas = new TCanvas("DeltaPhi", "DeltaPhi", 1000, 700);
8541   canvas->Divide(maxAssocPt, maxLeadingPt);
8542       
8543   TGraphErrors* width1 = new TGraphErrors;
8544   TGraphErrors* width2 = new TGraphErrors;
8545   TGraphErrors* width3 = new TGraphErrors;
8546   
8547   for (Int_t i=0; i<maxLeadingPt; i++)
8548     for (Int_t j=0; j<maxAssocPt; j++)
8549     {
8550       canvas->cd(j+1 + i * maxAssocPt);
8551       gPad->SetLeftMargin(0.15);
8552       gPad->SetBottomMargin(0.2);
8553       gPad->SetTopMargin(0.01);
8554       gPad->SetRightMargin(0.01);
8555       
8556       hist1 = (TH1*) gFile->Get(Form("dphi_%d_%d_%d", i, j, 0));
8557       hist2 = (TH1*) gFile->Get(Form("dphi_%d_%d_%d", i, j, 1));
8558       hist3 = (TH1*) gFile->Get(Form("dphi_%d_%d_%d", i, j, 2));
8559       
8560       if (!hist1)
8561         continue;
8562
8563       TString tmpStr(hist1->GetTitle());
8564       tmpStr.ReplaceAll(" - ", "#");
8565       tokens = tmpStr.Tokenize("#");
8566       TString str(tokens->At(0)->GetName());
8567       TString str2(tokens->At(1)->GetName());
8568       
8569       Prepare1DPlot(hist1);
8570       Prepare1DPlot(hist2);
8571       Prepare1DPlot(hist3);
8572
8573       // remove baseline
8574       hist1->Fit("pol0", "0", "", 1, 4);
8575       if (!hist1->GetFunction("pol0"))
8576         continue;
8577       hist1->GetFunction("pol0")->SetRange(-10, 10);
8578       hist1->Add(hist1->GetFunction("pol0"), -1);
8579       
8580       hist3->Fit("pol0", "0", "", 1, 4);
8581       hist3->GetFunction("pol0")->SetRange(-10, 10);
8582       hist3->Add(hist3->GetFunction("pol0"), -1);
8583       
8584       Double_t yMin = 0.01;
8585       Double_t yMax = -1;
8586       
8587       if (yMax < 0)
8588       {
8589         yMin = TMath::Min(hist1->GetMinimum(), hist2->GetMinimum()) * 0.97;
8590         yMax = TMath::Max(hist1->GetMaximum(), (hist2) ? hist2->GetMaximum() : 0.0) * 1.1;
8591       }
8592       
8593 //       yMin = hist1->GetMinimum() * 0.9;
8594       yMax *= 1.5;
8595     
8596       TH2F* dummy = new TH2F("dummy", "", 100, hist1->GetXaxis()->GetBinLowEdge(1), hist1->GetXaxis()->GetBinUpEdge(hist1->GetNbinsX()), 1000, yMin, yMax);
8597       dummy->SetStats(kFALSE);
8598       dummy->SetXTitle(hist1->GetXaxis()->GetTitle());
8599       dummy->SetYTitle(hist1->GetYaxis()->GetTitle());
8600       dummy->SetYTitle("1/N_{trig} dN/d#Delta#phi"); 
8601       Prepare1DPlot(dummy);
8602       
8603       dummy->GetYaxis()->SetTitleOffset(0.8);
8604     
8605       dummy->GetXaxis()->SetLabelSize(0.08);
8606       dummy->GetYaxis()->SetLabelSize(0.08);
8607       dummy->GetXaxis()->SetTitleSize(0.08);
8608       dummy->GetYaxis()->SetTitleSize(0.08);
8609       /*
8610       dummy->GetYaxis()->SetTitleOffset(0.8);
8611       */
8612       
8613       dummyTmp = dummy->DrawCopy();
8614       
8615       // TODO plot yield? baseline problematic?
8616
8617       Float_t xPos = width1->GetN();
8618       xPos = j*7+i;
8619
8620       FitDeltaPhiEtaGap(hist1, 1, width1, xPos, 0.7);
8621       FitDeltaPhiEtaGap(hist2, 4, width2, xPos, 0.5);
8622       FitDeltaPhiEtaGap(hist3, 2, width3, xPos, 0.6);
8623       
8624       latex = new TLatex(0.3, 0.8, str);
8625       latex->SetNDC();
8626       latex->SetTextSize(0.06);
8627       latex->Draw();
8628       
8629       latex = new TLatex(0.3, 0.88, str2);
8630       latex->SetNDC();
8631       latex->SetTextSize(0.06);
8632       latex->Draw();
8633       
8634       DrawLatex(0.8, 0.9,  1, "0-5%");
8635       DrawLatex(0.8, 0.85, 2, "60-90%");
8636       DrawLatex(0.8, 0.8,  4, "pp");
8637
8638 //       return;
8639 //       i = 10; j = 10;
8640     }
8641     
8642   new TCanvas;
8643   width1->SetMarkerStyle(20);
8644   width1->Draw("AP");
8645
8646   width2->SetMarkerStyle(24);
8647   width2->SetMarkerColor(4);
8648   width2->Draw("P SAME");
8649
8650   width3->SetMarkerStyle(25);
8651   width3->SetMarkerColor(2);
8652   width3->Draw("P SAME");
8653 }
8654
8655 void CheckWing(const char* fileName)
8656 {
8657   TFile::Open(fileName);
8658   
8659   Int_t maxLeadingPt = 4;
8660   Int_t maxAssocPt = 5;
8661
8662   TCanvas* canvas = new TCanvas("DeltaPhi", "DeltaPhi", 1000, 700);
8663   canvas->Divide(maxAssocPt-1, maxLeadingPt);
8664       
8665   for (Int_t i=0; i<maxLeadingPt; i++)
8666     for (Int_t j=1; j<maxAssocPt; j++)
8667     {
8668       canvas->cd(j + i * (maxAssocPt - 1));
8669       gPad->SetLeftMargin(0.15);
8670       gPad->SetBottomMargin(0.2);
8671 //       gPad->SetTopMargin(0.01);
8672       gPad->SetRightMargin(0.01);
8673       
8674       hist1 = (TH1*) gFile->Get(Form("dphi_%d_%d_%d", i, j+1, 0));
8675       
8676       if (!hist1)
8677         continue;
8678       
8679 //       hist1->Draw("COLZ");
8680
8681       Float_t width = 0.25;
8682
8683       proj = ((TH2*) hist1)->ProjectionY(Form("%s_projx", hist1->GetName()), hist1->GetXaxis()->FindBin(TMath::Pi() - width),hist1->GetXaxis()->FindBin(TMath::Pi() + width));
8684       
8685       proj->GetXaxis()->SetRangeUser(-1.79, 1.79);
8686       proj->SetStats(kFALSE);
8687       proj->Draw();
8688
8689       proj2 = ((TH2*) hist1)->ProjectionY(Form("%s_proj2x", hist1->GetName()), hist1->GetXaxis()->FindBin(TMath::Pi() / 2 - width),hist1->GetXaxis()->FindBin(TMath::Pi() / 2 + width));
8690
8691       proj2->GetXaxis()->SetRangeUser(-1.79, 1.79);
8692       proj2->SetLineColor(2);
8693       proj2->Draw("SAME");
8694       
8695       proj->SetMinimum(0.999 * proj2->GetMinimum());
8696     }
8697 }
8698
8699 void CheckWing()
8700 {
8701   Int_t maxLeadingPt = 3;
8702   Int_t maxAssocPt = 3;
8703
8704   TCanvas* canvas = new TCanvas("DeltaPhi", "DeltaPhi", 1000, 700);
8705   canvas->Divide(maxAssocPt, maxLeadingPt);
8706
8707 //   const char* fileNames[] = { "dphi_corr_allpt_zcentral_01.root", "dphi_corr_allpt_01.root" };
8708 //   const char* fileNames[] = { "dphi_corr_allpt_zcentral.root", "dphi_corr_allpt.root" };
8709 //   const char* fileNames[] = { "dphi_corr_allpt_zcentral.root", "dphi_corr.root" };
8710 //   const char* fileNames[] = { "dphi_corr_allpt_01_zcentral.root", "dphi_corr_allpt_01_zsumofratios.root" };
8711 //   const char* fileNames[] = { "dphi_corr_allpt_cfct_01_zcentral.root", "dphi_corr_allpt_cfct_01_zsumofratios.root" };
8712 //   const char* fileNames[] = { "dphi_corr_2d.root", "dphi_corr.root" };
8713 //   const char* fileNames[] = { "dphi_corr_2d_01.root", "dphi_corr.root" };
8714 //   const char* fileNames[] = { "dphi_corr_2d.root", "dphi_corr_2d_vtxzcentral.root" };
8715 //   const char* fileNames[] = { "dphi_corr_2d_01.root", , "dphi_corr_2d_01centr_zvtxcentral.root" }; 
8716 //   const char* fileNames[] = { "dphi_corr_10k.root", "dphi_corr_50k.root" }; 
8717 //   const char* fileNames[] = { "wing1.root", "wing2.root" }; 
8718   const char* fileNames[] = { "dphi_corr_2d_120112.root", "dphi_corr_2d_p2_111105.root" }; 
8719   
8720   for (Int_t i=0; i<maxLeadingPt; i++)
8721     for (Int_t j=0; j<maxAssocPt; j++)
8722     {
8723       canvas->cd(j+1 + i * maxAssocPt);
8724       gPad->SetLeftMargin(0.15);
8725       gPad->SetBottomMargin(0.2);
8726 //       gPad->SetTopMargin(0.01);
8727       gPad->SetRightMargin(0.01);
8728
8729       TH1* first = 0;
8730       for (Int_t fileId = 0; fileId < 2; fileId++)
8731       {
8732         TFile::Open(fileNames[fileId]);
8733   
8734         hist1 = (TH1*) gFile->Get(Form("dphi_%d_%d_%d", i, j, 3));
8735         
8736         if (!hist1)
8737           continue;
8738         
8739   //       hist1->Draw("COLZ");
8740
8741         Float_t width = 0.5;
8742         
8743         for (Int_t areaId = 0; areaId < 3; areaId++)
8744         {
8745           Float_t center = TMath::Pi() / 2 * areaId;
8746           proj = ((TH2*) hist1)->ProjectionY(Form("%s_%d_%d_projx", hist1->GetName(), fileId, areaId), hist1->GetXaxis()->FindBin(center - width), hist1->GetXaxis()->FindBin(center + width));
8747   //    proj->Rebin(2); proj->Scale(0.5);
8748           
8749           proj->GetXaxis()->SetRangeUser(-1.79, 1.79);
8750           proj->SetStats(kFALSE);
8751           proj->SetLineColor(fileId + 1 + areaId * 2);
8752           proj->Draw((fileId == 0 && areaId == 0) ? "" : "SAME");
8753           if (!first)
8754             first = proj;
8755           
8756           proj->Scale(1. / 12);
8757           
8758           first->SetMinimum(0.999 * TMath::Min(first->GetMinimum() / 0.999, proj->GetMinimum()));
8759           first->SetMaximum(1.001 * TMath::Max(first->GetMaximum() / 1.001, proj->GetMaximum()));
8760         }
8761       }
8762   }
8763 }
8764 /*
8765 void FitDeltaPhiEtaGap2D(TH2* hist, Bool_t scale, TVirtualPad* pad1, TVirtualPad* pad2, TVirtualPad* pad3, TGraphErrors* width1, TGraphErrors* width2, Float_t x, Float_t yPosChi2)
8766 {
8767   Float_t etaLimit = 1.0;
8768   Float_t outerLimit = 1.8;
8769   
8770   TString histName(hist->GetName());
8771
8772   TH1D* etaGap = hist->ProjectionX(histName + "_1", TMath::Max(1, hist->GetYaxis()->FindBin(-outerLimit + 0.01)), hist->GetYaxis()->FindBin(-etaLimit - 0.01));
8773   Int_t etaBins = hist->GetYaxis()->FindBin(-etaLimit - 0.01) - TMath::Max(1, hist->GetYaxis()->FindBin(-outerLimit + 0.01)) + 1;
8774
8775   TH1D* tracksTmp = hist->ProjectionX(histName + "_2", hist->GetYaxis()->FindBin(etaLimit + 0.01), TMath::Min(hist->GetYaxis()->GetNbins(), hist->GetYaxis()->FindBin(outerLimit - 0.01)));
8776   etaBins += TMath::Min(hist->GetYaxis()->GetNbins(), hist->GetYaxis()->FindBin(outerLimit - 0.01)) - hist->GetYaxis()->FindBin(etaLimit + 0.01) + 1;
8777   
8778   etaGap->Add(tracksTmp);
8779
8780   // get per bin result
8781   etaGap->Scale(1.0 / etaBins);
8782   
8783 //   new TCanvas; etaGap->DrawCopy();
8784   
8785   histTmp2D = (TH2*) hist->Clone("histTmp2D");
8786   histTmp2D->Reset();
8787   
8788   for (Int_t xbin=1; xbin<=histTmp2D->GetNbinsX(); xbin++)
8789     for (Int_t y=1; y<=histTmp2D->GetNbinsY(); y++)
8790       histTmp2D->SetBinContent(xbin, y, etaGap->GetBinContent(xbin));
8791     
8792   if (scale)
8793   {
8794     // mixed event does not reproduce away-side perfectly
8795     // --> extract scaling factor on the away-side from ratios of eta gap and central region
8796     TH1D* centralRegion = hist->ProjectionX(histName + "_3", hist->GetYaxis()->FindBin(-etaLimit + 0.01), hist->GetYaxis()->FindBin(etaLimit - 0.01));
8797     etaBins = hist->GetYaxis()->FindBin(etaLimit - 0.01) - hist->GetYaxis()->FindBin(-etaLimit + 0.01) + 1;
8798     centralRegion->Scale(1.0 / etaBins);
8799     
8800 //     new TCanvas; centralRegion->DrawCopy(); etaGap->SetLineColor(2); etaGap->DrawCopy("SAME");
8801     centralRegion->Divide(etaGap);
8802 //     new TCanvas; centralRegion->Draw();
8803     centralRegion->Fit("pol0", "0", "", TMath::Pi() - 1, TMath::Pi() + 1);
8804     Float_t scalingFactor = centralRegion->GetFunction("pol0")->GetParameter(0);
8805     Printf("  scalingFactor = %f", scalingFactor);
8806     histTmp2D->Scale(scalingFactor);
8807   }
8808     
8809 //   new TCanvas; hist->DrawCopy("SURF1");
8810
8811   hist->Add(histTmp2D, -1);
8812
8813 //   new TCanvas; hist->DrawCopy("SURF1");
8814
8815   hist->GetYaxis()->SetRangeUser(-1.59, 1.59);
8816   
8817   pad1->cd();
8818   hist->SetStats(0);
8819   hist->DrawCopy("SURF1");
8820   
8821   Float_t min = hist->GetMinimum();
8822   Float_t max = hist->GetMaximum();
8823   
8824   // ranges are to exclude eta gap region from fit
8825   func = new TF2("func", "[0]+[1]*exp(-0.5*((x/[2])**2+(y/[3])**2))", -5, 5, -1, 1);
8826   func->SetParameters(0, 1, 0.3, 0.3);
8827   func->SetParLimits(1, 0, 10);
8828   func->SetParLimits(2, 0.1, 10);
8829   func->SetParLimits(3, 0.1, 10);
8830   
8831   hist->Fit(func, "0R", "");
8832 //   hist->Fit(func, "IM", "SAME");
8833
8834   pad2->cd();
8835   funcHist = (TH2*) hist->Clone("funcHist");
8836   funcHist->Reset();
8837   funcHist->Add(func);
8838   funcHist->SetMinimum(min);
8839   funcHist->SetMaximum(max);
8840   funcHist->Draw("SURF1");
8841   
8842   pad3->cd();
8843   hist->Add(func, -1);
8844   hist->SetMinimum(min);
8845   hist->SetMaximum(max);
8846   hist->DrawCopy("SURF1");
8847   
8848   width1->SetPoint(width1->GetN(), x, TMath::Abs(func->GetParameter(2)));
8849   width1->SetPointError(width1->GetN()-1, 0, func->GetParError(2));
8850     
8851   width2->SetPoint(width2->GetN(), x, TMath::Abs(func->GetParameter(3)));
8852   width2->SetPointError(width2->GetN()-1, 0, func->GetParError(3));
8853
8854   Float_t chi2 = 0;
8855   Int_t ndf = 0;
8856   for (Int_t i=hist->GetXaxis()->FindBin(-0.8); i<=hist->GetXaxis()->FindBin(0.8); i++)
8857     for (Int_t j=hist->GetYaxis()->FindBin(-0.8); j<=hist->GetYaxis()->FindBin(0.8); j++)
8858     {
8859       if (hist->GetBinError(i, j) > 0)
8860       {
8861         chi2 += TMath::Power(hist->GetBinContent(i, j) / hist->GetBinError(i, j), 2);
8862         ndf++;
8863       }
8864     }
8865   ndf -= func->GetNumberFreeParameters();
8866   
8867   printf("#chi^{2}/ndf = %.1f/%d = %.1f  ", func->GetChisquare(), func->GetNDF(), func->GetChisquare() / func->GetNDF());
8868   Printf("#chi^{2}/ndf = %.1f/%d = %.1f", chi2, ndf, chi2 / ndf);
8869
8870   DrawLatex(0.5, yPosChi2, 1, Form("#chi^{2}/ndf = %.1f/%d = %.1f", func->GetChisquare(), func->GetNDF(), func->GetChisquare() / func->GetNDF()));
8871   DrawLatex(0.5, yPosChi2 - 0.05, 1, Form("#chi^{2}/ndf = %.1f/%d = %.1f", chi2, ndf, chi2 / ndf));
8872 }
8873
8874 Double_t DeltaPhiWidth2DFitFunction(Double_t *x, Double_t *par)
8875 {
8876   // params: 0: gaussian amplitude, 1: phi width, 2: eta width
8877   //         3..bins+2 constants as fct of eta
8878   
8879   Int_t etaBin = (Int_t) ((x[1] + 2.0) / 0.1);
8880   
8881   return par[3+etaBin]+par[0]*TMath::Exp(-0.5*((x[0]/par[1])**2+(x[1]/par[2])**2));
8882 }
8883
8884 void FitDeltaPhi2DOneFunction(TH2* hist, TVirtualPad* pad1, TVirtualPad* pad2, TVirtualPad* pad3, TGraphErrors* width1, TGraphErrors* width2, Float_t x, Float_t yPosChi2)
8885 {
8886   Float_t outerLimit = 1.8;
8887
8888   hist->GetYaxis()->SetRangeUser(-1.59, 1.59);
8889   
8890   pad1->cd();
8891   hist->SetStats(0);
8892   hist->DrawCopy("SURF1");
8893   
8894   Float_t min = hist->GetMinimum();
8895   Float_t max = hist->GetMaximum();
8896   
8897   Int_t bins = hist->GetNbinsX();
8898   
8899   // ranges are to exclude eta gap region from fit
8900   func = new TF2("func", DeltaPhiWidth2DFitFunction, -5, 5, -outerLimit, outerLimit, bins+3);
8901   func->SetParameters(1, 0.3, 0.3);
8902   for (Int_t i=3; i<bins+3; i++)
8903     func->SetParameter(i, 0);
8904
8905   func->SetParLimits(0, 0, 10);
8906   func->SetParLimits(1, 0.1, 10);
8907   func->SetParLimits(2, 0.1, 10);
8908   
8909   hist->Fit(func, "0R", "");
8910 //   hist->Fit(func, "IM", "SAME");
8911
8912   pad2->cd();
8913   funcHist = (TH2*) hist->Clone("funcHist");
8914   funcHist->Reset();
8915   funcHist->Add(func);
8916   funcHist->SetMinimum(min);
8917   funcHist->SetMaximum(max);
8918   funcHist->Draw("SURF1");
8919   
8920   pad3->cd();
8921   hist->Add(func, -1);
8922   hist->SetMinimum(min);
8923   hist->SetMaximum(max);
8924   hist->DrawCopy("SURF1");
8925   
8926   width1->SetPoint(width1->GetN(), x, TMath::Abs(func->GetParameter(1)));
8927   width1->SetPointError(width1->GetN()-1, 0, func->GetParError(1));
8928     
8929   width2->SetPoint(width2->GetN(), x, TMath::Abs(func->GetParameter(2)));
8930   width2->SetPointError(width2->GetN()-1, 0, func->GetParError(2));
8931
8932   Float_t chi2 = 0;
8933   Int_t ndf = 0;
8934   for (Int_t i=hist->GetXaxis()->FindBin(-0.8); i<=hist->GetXaxis()->FindBin(0.8); i++)
8935     for (Int_t j=hist->GetYaxis()->FindBin(-0.8); j<=hist->GetYaxis()->FindBin(0.8); j++)
8936     {
8937       if (hist->GetBinError(i, j) > 0)
8938       {
8939         chi2 += TMath::Power(hist->GetBinContent(i, j) / hist->GetBinError(i, j), 2);
8940         ndf++;
8941       }
8942     }
8943   ndf -= func->GetNumberFreeParameters();
8944   
8945   printf("#chi^{2}/ndf = %.1f/%d = %.1f  ", func->GetChisquare(), func->GetNDF(), func->GetChisquare() / func->GetNDF());
8946   Printf("#chi^{2}/ndf = %.1f/%d = %.1f", chi2, ndf, chi2 / ndf);
8947
8948   DrawLatex(0.5, yPosChi2, 1, Form("#chi^{2}/ndf = %.1f/%d = %.1f", func->GetChisquare(), func->GetNDF(), func->GetChisquare() / func->GetNDF()));
8949   DrawLatex(0.5, yPosChi2 - 0.05, 1, Form("#chi^{2}/ndf = %.1f/%d = %.1f", chi2, ndf, chi2 / ndf));
8950 }
8951
8952 void AnalyzeDeltaPhiEtaGap2D(const char* fileName, Int_t method)
8953 {
8954   TFile::Open(fileName);
8955   
8956   Int_t maxLeadingPt = 5;
8957   Int_t maxAssocPt = 6;
8958
8959   TGraphErrors* width1[4];
8960   TGraphErrors* width2[4];
8961   
8962   Int_t nHists = 4;
8963   for (Int_t histId = 0; histId < nHists; histId++)
8964   {
8965     width1[histId] = new TGraphErrors;
8966     width2[histId] = new TGraphErrors;
8967     for (Int_t i=0; i<maxLeadingPt; i++)
8968     {
8969       TCanvas* canvas = new TCanvas(Form("DeltaPhi_%d_%d", histId, i), Form("DeltaPhi_%d_%d", histId, i), 1000, 1000);
8970       canvas->Divide(3, maxAssocPt);
8971       
8972       for (Int_t j=0; j<maxAssocPt; j++)
8973       {
8974         for (Int_t k=1; k<=3; k++)
8975         {
8976           canvas->cd(3 * j + k);
8977           gPad->SetLeftMargin(0.15);
8978           gPad->SetBottomMargin(0.2);
8979           gPad->SetTopMargin(0.01);
8980           gPad->SetRightMargin(0.01);
8981         }
8982         
8983 //      if (i != 1 || j != 2)
8984 //        continue;
8985     
8986         hist1 = (TH1*) gFile->Get(Form("dphi_%d_%d_%d", i, j, histId));
8987         if (!hist1)
8988           continue;
8989         
8990         Float_t xPos = j*8+i;
8991
8992         if (method == 0)
8993           FitDeltaPhiEtaGap2D((TH2*) hist1, kFALSE, canvas->cd(3 * j + 1), canvas->cd(3 * j + 2), canvas->cd(3 * j + 3), width1[histId], width2[histId], xPos, 0.9);
8994         else
8995           FitDeltaPhi2DOneFunction((TH2*) hist1, canvas->cd(3 * j + 1), canvas->cd(3 * j + 2), canvas->cd(3 * j + 3), width1[histId], width2[histId], xPos, 0.9);
8996         
8997         break;
8998       }
8999       
9000       break;
9001     }
9002     
9003     break;
9004   }
9005   
9006   return;
9007   
9008   Int_t marker[] = { 20, 24, 25, 26 };
9009   Int_t colors[] = { 2, 2, 4, 6 };
9010   const char* labels[] = { "0-5%", "60-90%", "pp", "30-40%" };
9011   
9012   Bool_t found = kTRUE;
9013   c1 = (TCanvas*) gROOT->GetListOfCanvases()->FindObject("width_phi");
9014   if (!c1)
9015   {
9016     c1 = new TCanvas("width_phi", "width_phi", 800, 600);
9017     colors[0] = 1;
9018     found = kFALSE;
9019   }
9020   c1->cd();
9021   
9022   for (Int_t histId = 0; histId < nHists; histId++)
9023   {
9024     width1[histId]->SetMarkerStyle(marker[histId]);
9025     width1[histId]->SetMarkerColor(colors[histId]);
9026     width1[histId]->Draw((histId == 0 && !found) ? "AP" : "PSAME");
9027     DrawLatex(0.7, 0.8 - 0.05 * histId, colors[histId], labels[histId]);
9028   }
9029   
9030   found = kTRUE;
9031   c1 = (TCanvas*) gROOT->GetListOfCanvases()->FindObject("width_eta");
9032   if (!c1)
9033   {
9034     c1 = new TCanvas("width_eta", "width_eta", 800, 600);
9035     colors[0] = 1;
9036     found = kFALSE;
9037   }
9038   c1->cd();
9039   for (Int_t histId = 0; histId < nHists; histId++)
9040   {
9041     width2[histId]->SetMarkerStyle(marker[histId]);
9042     width2[histId]->SetMarkerColor(colors[histId]);
9043     width2[histId]->Draw((histId == 0 && !found) ? "AP" : "PSAME");
9044     DrawLatex(0.7, 0.8 - 0.05 * histId, colors[histId], labels[histId]);
9045   }
9046 }
9047 */
9048
9049 void RemoveWing(const char* fileName, const char* outputFile)
9050 {
9051   // remove wing by flattening using the ratio of a flat line to the corr fct at phi = pi +- 1.5 as fct of delta eta
9052
9053   file = TFile::Open(fileName);
9054   file2 = TFile::Open(outputFile, "RECREATE");
9055   file2->Close();
9056   
9057   Int_t maxLeadingPt = 10;
9058   Int_t maxAssocPt = 11;
9059
9060   Int_t nHists = 6;
9061   for (Int_t histId = 0; histId < nHists; histId++)
9062   {
9063     for (Int_t i=0; i<maxLeadingPt; i++)
9064     {
9065       for (Int_t j=0; j<maxAssocPt; j++)
9066       {
9067         hist = (TH2*) file->Get(Form("dphi_%d_%d_%d", i, j, histId));
9068         if (!hist)
9069           continue;
9070         
9071         Float_t width = 1.5;
9072         TH1* proj = hist->ProjectionY(Form("projx", hist->GetName()), hist->GetXaxis()->FindBin(TMath::Pi() - width), hist->GetXaxis()->FindBin(TMath::Pi()+ width));
9073         proj->Fit("pol0", "0");
9074         //new TCanvas; proj->DrawCopy();
9075         proj->Divide(proj->GetFunction("pol0"));
9076         //new TCanvas; proj->DrawCopy();
9077         //new TCanvas; hist->DrawCopy("SURF1");
9078         for (Int_t x=1; x<=hist->GetNbinsX(); x++)
9079           for (Int_t y=1; y<=hist->GetNbinsY(); y++)
9080           {
9081             if (proj->GetBinContent(y) <= 0)
9082               continue;
9083             hist->SetBinContent(x, y, hist->GetBinContent(x, y) / proj->GetBinContent(y));
9084             hist->SetBinError(x, y, hist->GetBinError(x, y) / proj->GetBinContent(y));
9085           }
9086         //new TCanvas; hist->DrawCopy("SURF1");
9087
9088         file2 = TFile::Open(outputFile, "UPDATE");
9089         hist->Write();
9090         file2->Close();
9091       }
9092     }
9093   }  
9094 }
9095   
9096 void RemoveWingAllSpecies()
9097 {
9098   const char* suffix[] = { "Hadrons", "Pions", "Kaons", "Protons" };
9099   TString baseName = "dphi_corr_LHC13bc_20130604_";
9100   
9101   for (Int_t i=0; i<4; i++)
9102     RemoveWing(baseName + suffix[i] + ".root", baseName + suffix[i] + "_wingremoved.root");
9103 }  
9104   
9105 void PlotPtDistributions(const char* fileName1, Int_t centrBegin = 1, Int_t centrEnd = 2)
9106 {
9107   loadlibs();
9108
9109   Int_t maxLeadingPt = 3;
9110   Float_t leadingPtArr[] = { 1.0, 10.0, 20.0, 40.0 };
9111   
9112   Int_t nCentralityBins = 5;
9113   Int_t centralityBins[] = { 1, 7, 9, 11, 13, 16 };
9114   
9115   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName1);
9116     
9117   TCanvas* canvas = new TCanvas("Pt", "Pt", 1000, 1000);
9118   canvas->Divide(2, maxLeadingPt+2);
9119   
9120   TLegend* legend = new TLegend(0.2, 0.2, 0.95, 0.90);
9121   legend->SetFillColor(0);
9122   legend->SetTextSize(0.08);
9123   
9124   TLegend* legendB = new TLegend(0.2, 0.2, 0.95, 0.90);
9125   legendB->SetFillColor(0);
9126   legendB->SetTextSize(0.08);
9127   
9128   TLegend* legend2 = new TLegend(0.2, 0.2, 0.95, 0.90);
9129   legend2->SetFillColor(0);
9130   legend2->SetTextSize(0.08);
9131   
9132   Int_t colors[] = { 1, 2, 4, 6 };
9133   Int_t markers[] = { 20, 21, 22, 23, 24, 25 };
9134   
9135   for (Int_t i=0; i<maxLeadingPt; i++)
9136   {
9137     Double_t ptMin = leadingPtArr[i] + 0.01;
9138     //Double_t ptMax = leadingPtArr[i+1] - 0.01;
9139     Double_t ptMax = 39.99;
9140       
9141     TString str;
9142     str.Form("%.1f < p_{T,trig} < %.1f", ptMin - 0.01, ptMax + 0.01);
9143     
9144     canvas->cd(2*i+1+2);
9145     gPad->SetLeftMargin(0.15);
9146     gPad->SetBottomMargin(0.2);
9147     gPad->SetTopMargin(0.01);
9148     gPad->SetRightMargin(0.01);
9149     gPad->SetLogy();
9150     gPad->SetLogx();
9151     gPad->SetGridx();
9152     gPad->SetGridy();
9153     
9154     TH2F* dummy = new TH2F("dummy", "", 100, 1, 40, 100, 1e-5, 1e3);
9155     dummy->SetStats(kFALSE);
9156     dummy->SetXTitle("p_{T,assoc}");
9157     dummy->SetYTitle("");
9158     dummy->GetYaxis()->SetTitleOffset(1);
9159     Prepare1DPlot(dummy);
9160   
9161     dummy->GetXaxis()->SetLabelSize(0.06);
9162     dummy->GetYaxis()->SetLabelSize(0.06);
9163     dummy->GetXaxis()->SetTitleSize(0.06);
9164     dummy->GetYaxis()->SetTitleSize(0.06);
9165     dummy->DrawCopy();
9166     
9167     Float_t phiRange[] = { 0, TMath::Pi() / 2, TMath::Pi() };
9168     const char* phiLabels[] = { "Towards", "Transverse", "Away" };
9169     
9170     for (Int_t j=0; j<3; j++)
9171     {
9172       TH1* centralEta = 0;
9173       TH1* sideEta1 = 0;
9174       
9175       if (j == 0)
9176       {
9177         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);
9178         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);
9179         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);
9180         sideEta1->Add(sideEta2); // TODO can be done smarter? what about the errors?
9181       
9182         Prepare1DPlot(sideEta1);
9183         Prepare1DPlot(centralEta);
9184         
9185         centralEta->SetLineColor(colors[j]);
9186         sideEta1->SetLineColor(colors[j+1]);
9187       
9188         if (i == 0)
9189         {
9190           legend->AddEntry(centralEta->Clone(), Form("Jet, %s: |#eta| < 0.7, #phi ~ %.1f", phiLabels[j], phiRange[j]));
9191           legend->AddEntry(sideEta1->Clone(), Form("Ridge, %s: 0.7 < |#eta| < 1.4, #phi ~ %.1f", phiLabels[j], phiRange[j]));
9192         }
9193       }
9194       else
9195       {
9196         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);
9197         centralEta->Scale(0.5);
9198         centralEta->SetLineColor(colors[j+1]);
9199       
9200         Prepare1DPlot(centralEta);
9201         
9202         if (i == 0)
9203           legend->AddEntry(centralEta->Clone(), Form("%s: |#eta| < 1.4, #phi ~ %.1f", phiLabels[j], phiRange[j]));
9204       }
9205       
9206       canvas->cd(2*i+1+2);
9207       centralEta->DrawCopy("SAME");
9208       if (sideEta1)
9209         sideEta1->DrawCopy("SAME");
9210       
9211       centralEta->SetLineColor(colors[i]);
9212       centralEta->Scale(100.0 / centralEta->Integral());
9213       if (sideEta1)
9214       {
9215         sideEta1->SetLineColor(colors[i]);
9216         sideEta1->Scale(100.0 / sideEta1->Integral());
9217       }
9218     
9219       if (j < 2)
9220         canvas->cd(j*4+4);
9221       else
9222         canvas->cd(j*4+2);
9223       if (i == 0)
9224       {
9225         gPad->SetLeftMargin(0.15);
9226         gPad->SetBottomMargin(0.2);
9227         gPad->SetTopMargin(0.01);
9228         gPad->SetRightMargin(0.01);
9229         
9230         dummy->DrawCopy();
9231         
9232         gPad->SetLogy();
9233         gPad->SetLogx();
9234         gPad->SetGridx();
9235         gPad->SetGridy();
9236         
9237         TString str3;
9238         if (j == 0)
9239           str3.Form("Jet, %s: |#eta| < 0.7, #phi ~ %.1f", phiLabels[j], phiRange[j]);
9240         else
9241           str3.Form("%s: |#eta| < 1.4, #phi ~ %.1f", phiLabels[j], phiRange[j]);
9242         latex = new TLatex(0.2, 0.3, str3);
9243         latex->SetNDC();
9244         latex->SetTextSize(0.08);
9245         latex->Draw();
9246       }
9247       
9248       if (j == 0)
9249         legend2->AddEntry(centralEta->Clone(), str);
9250         
9251       centralEta->DrawCopy("SAME");
9252       
9253       if (sideEta1)
9254       {
9255         canvas->cd(j*4+4+2);
9256         if (i == 0)
9257         {
9258           gPad->SetLeftMargin(0.15);
9259           gPad->SetBottomMargin(0.2);
9260           gPad->SetTopMargin(0.01);
9261           gPad->SetRightMargin(0.01);
9262           
9263           dummy->DrawCopy();
9264           
9265           gPad->SetLogy();
9266           gPad->SetLogx();
9267           gPad->SetGridx();
9268           gPad->SetGridy();
9269           
9270           TString str3;
9271           if (j == 0)
9272             str3.Form("Ridge, %s: 0.7 < |#eta| < 1.4, #phi ~ %.1f", phiLabels[j], phiRange[j]);
9273           else
9274             str3.Form("%s: |#eta| < 1.4, #phi ~ %.1f", phiLabels[j], phiRange[j]);
9275           latex = new TLatex(0.2, 0.3, str3);
9276           latex->SetNDC();
9277           latex->SetTextSize(0.08);
9278           latex->Draw();
9279         }
9280         
9281         sideEta1->DrawCopy("SAME");
9282       }
9283     }
9284     
9285     TString str3;
9286     str3.Form("%d-%d%%", (Int_t) h->GetCentralityDistribution()->GetXaxis()->GetBinLowEdge(centrBegin), (Int_t) h->GetCentralityDistribution()->GetXaxis()->GetBinUpEdge(centrEnd));
9287     latex = new TLatex(0.2, 0.3, str3);
9288     latex->SetNDC();
9289     latex->SetTextSize(0.08);
9290     
9291     latex2 = new TLatex(0.55, 0.8, str);
9292     latex2->SetNDC();
9293     latex2->SetTextSize(0.06);
9294     
9295     canvas->cd(2*i+1+2);
9296     latex->Draw();
9297     latex2->Draw();
9298     
9299     //break;
9300   }
9301   
9302   canvas->cd(1);
9303   legend->Draw();
9304
9305   canvas->cd(2);
9306   legend2->Draw();
9307 }
9308
9309 TH1* GetNonSubtractedRHICYield(Int_t ptT, Int_t ptA, Int_t centrality)
9310 {
9311   rhicFile = TFile::Open("rhic/postcorr_AuAu_iter6_ppg106final.root");
9312   
9313   corrFunc = (TH1*) rhicFile->Get(Form("pi0hdphi_%d_%d_%d_2", ptT, ptA, centrality));
9314   //corrFunc->Draw();
9315   
9316   // integral
9317   corrFunc->Scale(1.0 / corrFunc->Integral());
9318   // bin width
9319   corrFunc->Scale(TMath::TwoPi() / corrFunc->GetBinWidth(1));
9320   
9321   same     = (TH1*) rhicFile->Get(Form("pi0hdphi_%d_%d_%d_0", ptT, ptA, centrality));
9322   Float_t nPairs = same->Integral();
9323   
9324   triggers = (TH1*) rhicFile->Get(Form("pi0pt_%d_%d", ptT, centrality));
9325   Float_t nTrigs = triggers->Integral();
9326   
9327   graph = (TGraph*) rhicFile->Get(Form("gS_%d_%d", ptT, centrality));
9328   
9329   Printf("%f %f %f %f", nPairs, nTrigs, nPairs / nTrigs, graph->GetY()[ptA]);
9330   
9331   corrFunc->Scale(nPairs / nTrigs);
9332  
9333   //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))));
9334   
9335   Float_t values[3];
9336   Float_t errors[3];
9337   
9338   Float_t regionBegin[3] = { -TMath::Pi() / 2,        TMath::Pi() / 2 - 0.4, 1.5 * TMath::Pi() - 0.4 };
9339   Float_t regionEnd[3] =   { -TMath::Pi() / 2 + 0.4,  TMath::Pi() / 2 + 0.4, 1.5 * TMath::Pi() };
9340     
9341   // weighted mean
9342   Float_t sum = 0;
9343   Float_t weight = 0;
9344   for (Int_t i=0; i<3; i++)
9345   {
9346     corrFunc->Fit("pol0", "0Q", "", regionBegin[i], regionEnd[i]);
9347     func = corrFunc->GetFunction("pol0");
9348     if (!func)
9349       continue;
9350     sum += func->GetParameter(0) / func->GetParError(0) / func->GetParError(0);
9351     weight += 1. / func->GetParError(0) / func->GetParError(0);
9352   }
9353   
9354   if (weight == 0)
9355     return 0;
9356   
9357   sum /= weight;
9358   weight = TMath::Sqrt(1. / weight);
9359   
9360   corrFunc->Add(new TF1("func", "1", -5, 5), -sum);
9361   
9362   return corrFunc;
9363   
9364   new TCanvas;
9365   corrFunc->Draw();
9366   compHist = (TH1*) rhicFile->Get(Form("ptyMSMP_0_%d%d%d", ptT, ptA, centrality));
9367   compHist->DrawCopy("SAME");
9368   
9369   //compHist->Add((TF1*) compHist->GetListOfFunctions()->First());
9370   //compHist->DrawCopy("SAME");
9371 }
9372   
9373 void DeltaPhiVsRHIC(Int_t rhicCentrality = 0, Int_t aliceCentrality = 0, Bool_t reduced = kFALSE)
9374 {
9375   aliceFile = TFile::Open("alice_dphi_corr_rhicbinning.root");
9376   rhicFile = TFile::Open("rhic/postcorr_AuAu_iter6_ppg106final.root");
9377
9378   Int_t maxLeadingPt = 4;
9379   Int_t maxAssocPt = 5;
9380   
9381   if (reduced)
9382   {
9383     Int_t maxSelected = 4;
9384     Int_t selectedLead[] = { 0, 0, 2, 2 };
9385     Int_t selectedAssoc[] = { 1, 2, 3, 4 };
9386    
9387     maxLeadingPt = TMath::Sqrt(maxSelected);
9388     maxAssocPt = TMath::Sqrt(maxSelected);
9389   }
9390     
9391   TCanvas* canvas = new TCanvas("DeltaPhi", "DeltaPhi", 1000, 700);
9392   canvas->Divide(maxAssocPt, maxLeadingPt);
9393   
9394   for (Int_t i=0; i<maxLeadingPt; i++)
9395     for (Int_t j=0; j<maxAssocPt; j++)
9396     {
9397       Printf("%d %d", i, j);
9398     
9399       canvas->cd(j+1 + i * maxAssocPt);
9400       gPad->SetLeftMargin(0.15);
9401       gPad->SetBottomMargin(0.2);
9402       //gPad->SetTopMargin(0.01);
9403       gPad->SetRightMargin(0.01);
9404       
9405       Int_t iSel = i;
9406       Int_t jSel = j;
9407       
9408       if (reduced)
9409       {
9410         iSel = selectedLead[j + i * maxAssocPt];
9411         jSel = selectedAssoc[j + i * maxAssocPt];
9412       }
9413       
9414       //rhic = (TH1*) rhicFile->Get(Form("VptyMSMP_0_%d%d%d", iSel, jSel, rhicCentrality));
9415       rhic = GetNonSubtractedRHICYield(iSel, jSel, rhicCentrality);
9416       if (!rhic)
9417         continue;
9418       rhic->SetLineColor(2);
9419       rhic->SetMarkerStyle(1);
9420       
9421       alice = (TH1*) aliceFile->Get(Form("dphi_%d_%d_%d_fit_flat", iSel, jSel, aliceCentrality));
9422       if (!alice)
9423         continue;
9424         
9425       // match near side yield
9426       if (1)
9427       {
9428         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));
9429         
9430         Printf("%f", factor);
9431         rhic->Scale(factor);
9432       }
9433         
9434       alice->SetLineColor(1);
9435         
9436       //alice->Rebin(36); rhic->Rebin(30);
9437       
9438       clone = alice->DrawCopy("");
9439       rhic->DrawCopy("SAME");
9440       
9441       //Printf("chi2 test: chi2/ndf = %f", alice->Chi2Test(rhic, "WW CHI2/NDF"));
9442       Float_t chi2 = 0;
9443       Float_t n = 0;
9444       for (Int_t k=1; k<=rhic->GetNbinsX(); k++)
9445       {
9446         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));
9447         n++;
9448       }
9449       
9450       chi2 /= n;
9451       Printf("chi2 test: chi2/ndf = %f", chi2);      
9452       
9453       clone->GetYaxis()->SetRangeUser(TMath::Min(alice->GetMinimum(), rhic->GetMinimum()) * 1.1, TMath::Max(alice->GetMaximum(), rhic->GetMaximum()) * 1.1);
9454       
9455       for (Int_t bin=1; bin<=rhic->GetNbinsX(); bin++)
9456       {
9457         Double_t aliceValue = alice->GetBinContent(alice->FindBin(rhic->GetXaxis()->GetBinCenter(bin)));
9458         if (aliceValue == 0)
9459           continue;
9460         rhic->SetBinContent(bin, rhic->GetBinContent(bin) / aliceValue);
9461         rhic->SetBinError(bin, 0);
9462       }
9463       
9464       rhic->Rebin(2);
9465       rhic->Scale(0.5);
9466       
9467       rhic->SetLineColor(3);
9468       //rhic->DrawCopy("SAME");
9469       
9470       //return;
9471     }
9472     
9473     canvas->SaveAs("yield_comparison.png");
9474 }
9475   
9476 void DeltaPhi(const char* fileName, const char* fileName2 = 0, Bool_t reduced = kFALSE, Bool_t ppComparison = kFALSE, Int_t mode = 0, const char* dataTag = "", const char* histName = "_fit_flat")
9477 {
9478   // DeltaPhi("high_stat_binning_pp7_pt8.root", "high_stat_binning_pp7_pythia_pt8.root", 0, 1, 0, "pp 7 TeV uncorrected")
9479   // DeltaPhi("high_stat_binning_pp900_pt8.root", "high_stat_binning_pp900_pythia_pt8.root", 0, 1, 0, "pp 0.9 TeV uncorrected")
9480
9481   style(2);
9482
9483   aliceFile = TFile::Open(fileName);
9484   if (fileName2)
9485     secondFile = TFile::Open(fileName2);
9486
9487   if (1)
9488   {
9489     Int_t maxLeadingPt = 3;
9490     Int_t maxAssocPt = 3;
9491   }
9492   else
9493   {
9494     Int_t maxLeadingPt = 3;
9495     Int_t maxAssocPt = 7;
9496   }
9497   
9498   if (reduced)
9499   {
9500     Int_t maxSelected = 4;
9501     Int_t selectedLead[] = { 1, 1, 1, 1 };
9502     Int_t selectedAssoc[] = { 2, 3, 4, 5 };
9503    
9504     maxLeadingPt = TMath::Sqrt(maxSelected);
9505     maxAssocPt = TMath::Sqrt(maxSelected);
9506   }
9507   
9508   factorGraph = new TGraphErrors;
9509     
9510 //   TCanvas* canvas = new TCanvas(Form("%s_%s", fileName, fileName2 ? fileName2 : ""), Form("%s_%s", fileName, fileName2 ? fileName2 : ""), 600, 900);
9511   TCanvas* canvas = new TCanvas(Form("%s_%s", fileName, fileName2 ? fileName2 : ""), Form("%s_%s", fileName, fileName2 ? fileName2 : ""), 1000, 1000);
9512   canvas->Divide(maxAssocPt, maxLeadingPt);
9513   
9514   for (Int_t i=0; i<maxLeadingPt; i++)
9515     for (Int_t j=0; j<maxAssocPt; j++)
9516     {
9517       TH1* first = 0;
9518       TH1* peripheral = 0;
9519       for (Int_t aliceCentrality=0; aliceCentrality<4; aliceCentrality++)
9520       {
9521         Printf("%d %d %d", i, j, aliceCentrality);
9522         
9523         if (aliceCentrality == 1)
9524           continue;
9525       
9526         canvas->cd(j+1 + i * maxAssocPt);
9527         
9528         Int_t iSel = i;
9529         Int_t jSel = j;
9530         Int_t centralitySel = aliceCentrality;
9531         currentFile = aliceFile;
9532         
9533         if (reduced)
9534         {
9535           iSel = selectedLead[j + i * maxAssocPt];
9536           jSel = selectedAssoc[j + i * maxAssocPt];
9537         }
9538         
9539         if (fileName2)
9540         {
9541           if (ppComparison)
9542           {
9543             centralitySel = 3;
9544             if (aliceCentrality == 1)
9545               currentFile = secondFile;
9546             else if (aliceCentrality == 2)
9547               break;
9548           }
9549           else
9550             if (aliceCentrality == 3)
9551               currentFile = secondFile;
9552         }
9553         
9554         //alice = (TH1*) currentFile->Get(Form("dphi_%d_%d_%d%s", iSel, jSel, centralitySel, (centralitySel < 3) ? "_tsallis_flat" : ((flatOrTsallis) ? "" : "_fit_flat")));
9555         alice = (TH1*) currentFile->Get(Form("dphi_%d_%d_%d%s", iSel, jSel, centralitySel, histName));
9556         if (!alice)
9557           continue;
9558
9559         if (0)
9560         {
9561           Printf("WARNING: Applying some scaling and rebinning! Only for 2.76 data-MC comparison!");
9562           if (aliceCentrality == 0)
9563           {
9564             alice->Rebin(2); alice->Scale(0.5); 
9565           alice->Scale(1.0 / 1.6);
9566           }
9567 //        else
9568 //          alice->Scale(1.6);
9569         }
9570         
9571             alice->Rebin(2); alice->Scale(0.5); 
9572 //          alice->Scale(1.0 / 1.6);
9573
9574         // match near side yield to peripheral
9575         if (1 && centralitySel == 3 && peripheral)
9576         {
9577          if (mode == 0 || mode == 1)
9578           {
9579             Double_t width = 0.5;
9580             Double_t error1, error2;
9581             Double_t integral1 = peripheral->IntegralAndError(peripheral->FindBin(-width), peripheral->FindBin(width), error1);
9582             Double_t integral2 = alice->IntegralAndError(alice->FindBin(-width), alice->FindBin(width), error2);
9583             if (mode == 1)
9584             {
9585               Double_t tmpErr = 0;
9586               integral1 += peripheral->IntegralAndError(peripheral->FindBin(TMath::Pi() - width), peripheral->FindBin(TMath::Pi() + width), tmpErr);
9587               error1 = TMath::Sqrt(error1 * error1 + tmpErr * tmpErr);
9588               
9589               integral2 += alice->IntegralAndError(alice->FindBin(TMath::Pi() - width), alice->FindBin(TMath::Pi() + width), tmpErr);
9590               error2 = TMath::Sqrt(error2 * error2 + tmpErr * tmpErr);
9591             }
9592           }
9593           else if (mode == 2)
9594           {
9595             Double_t error1, error2;
9596             Double_t integral1 = peripheral->IntegralAndError(1, peripheral->GetNbinsX(), error1);
9597             Double_t integral2 = alice->IntegralAndError(1, alice->GetNbinsX(), error2);
9598           }
9599           else if (mode == 3)
9600           {
9601             Double_t width = 1.0;
9602             Double_t error1, error2;
9603             Double_t integral1 = peripheral->IntegralAndError(peripheral->FindBin(TMath::Pi() - width), peripheral->FindBin(TMath::Pi() + width), error1);
9604             Double_t integral2 = alice->IntegralAndError(alice->FindBin(TMath::Pi() - width), alice->FindBin(TMath::Pi() + width), error2);
9605           }
9606             
9607           Double_t factor = integral1 / integral2;
9608           
9609           //factor = 0.804 * 0.9;
9610           Printf("%f", factor);
9611 //           alice->Scale(factor);
9612           factorGraph->SetPoint(factorGraph->GetN(), factorGraph->GetN(), factor);
9613           factorGraph->SetPointError(factorGraph->GetN() - 1, 0, factor * TMath::Sqrt(TMath::Power(error1 / integral1, 2) + TMath::Power(error2 / integral2, 2)));
9614         }
9615         
9616         if (ppComparison && aliceCentrality == 0)
9617           peripheral = alice;
9618         else if (aliceCentrality == 2)
9619           peripheral = alice;          
9620           
9621 //         alice->SetYTitle("1/(N_{trig} #Delta#eta) dN_{assoc}/d#Delta#phi (1/rad)");
9622         alice->SetYTitle("1/N_{trig} dN_{assoc}/d#Delta#phi (1/rad)");
9623         alice->SetXTitle("#Delta#phi (rad)");
9624         alice->SetLineColor(aliceCentrality+1);
9625         alice->SetLineWidth(2);
9626         alice->SetMarkerColor(aliceCentrality+1);
9627         alice->GetYaxis()->SetTitleOffset(1.7);
9628         clone = alice->DrawCopy((aliceCentrality > 0) ? "SAME" : "");
9629         clone->SetTitle("");
9630         
9631         TString str(alice->GetTitle());
9632         str.ReplaceAll(" - ", "#");
9633         tokens = str.Tokenize("#");
9634           
9635         if (aliceCentrality == 0)
9636         {
9637           for (Int_t k=0; k<2; k++)
9638           {
9639             TString str(tokens->At(k)->GetName());
9640             str.ReplaceAll(".0", "");
9641             str.ReplaceAll("< p", "GeV/c < p");
9642             str += " GeV/c";
9643             latex = new TLatex(0.48, 0.92-k*0.06, str);
9644             latex->SetNDC();
9645             latex->SetTextSize(0.04);
9646             latex->Draw();
9647           }
9648           
9649         }
9650         
9651         if (!first)
9652           first = clone;
9653         else
9654           first->GetYaxis()->SetRangeUser(TMath::Min(first->GetMinimum(), clone->GetMinimum()), TMath::Max(first->GetMaximum(), clone->GetMaximum()));
9655           
9656         
9657           
9658         //return;
9659       }
9660       if (first)
9661         //first->GetYaxis()->SetRangeUser(first->GetMinimum(), first->GetMaximum() * 1.2);
9662         first->GetYaxis()->SetRangeUser(first->GetMinimum(), first->GetMaximum() * 1.5);
9663     }
9664     
9665   if (0)
9666   {
9667     for (Int_t i=1; i<=6; i++)
9668     {
9669       canvas->cd(i);
9670       
9671       latex = new TLatex(0.58, 0.8, "ALICE preliminary");
9672       latex->SetTextSize(0.04);
9673       latex->SetNDC();
9674       latex->Draw();
9675     
9676       latex = new TLatex(0.58, 0.74, Form("%s", dataTag));
9677       latex->SetTextSize(0.04);
9678       latex->SetNDC();
9679       latex->Draw();
9680       
9681       latex = new TLatex(0.58, 0.68, "Stat. uncertainties only");
9682       latex->SetTextSize(0.04);
9683       latex->SetNDC();
9684       latex->Draw();
9685     
9686       latex = new TLatex(0.58, 0.62, "|#eta| < 0.8");
9687       latex->SetTextSize(0.04);
9688       latex->SetNDC();
9689       latex->Draw();
9690     
9691       if (ppComparison)
9692       {
9693         legend = new TLegend(0.3, 0.8, 0.47, 0.95);
9694         legend->SetFillColor(0);
9695         legend->SetTextSize(0.04);
9696         legend->AddEntry(peripheral, "Data");
9697         legend->AddEntry(alice, "Pythia");
9698         legend->Draw();
9699       }
9700
9701       DrawALICELogo(0.75, 0.47, 0.95, 0.6);
9702     }
9703   }
9704   
9705   canvas->SaveAs(Form("%s.eps", canvas->GetName()));
9706   canvas->SaveAs(Form("%s.png", canvas->GetName()));
9707     
9708   new TCanvas;
9709   peripheral->Divide(alice);
9710   peripheral->DrawCopy();
9711   //alice->DrawCopy("SAME");
9712   
9713     
9714   graphCanvas = (TCanvas*) gROOT->GetListOfCanvases()->FindObject("graphCanvas");
9715   factorGraph->SetMarkerStyle(20);
9716   if (!graphCanvas)
9717   {
9718     graphCanvas = new TCanvas("graphCanvas", "graphCanvas", 800, 600);
9719     factorGraph->Draw("AP");
9720   }
9721   else
9722   {
9723     graphCanvas->cd();
9724     factorGraph->SetLineColor(2);
9725     factorGraph->SetMarkerColor(2);
9726     factorGraph->Draw("SAMEP");
9727   }
9728   factorGraph->GetYaxis()->SetRangeUser(0.6, 1.4);
9729   
9730   factorGraph->Print();
9731 }
9732
9733 void ComparePPYields(const char* histName = "_fit_flat")
9734 {
9735   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" };
9736   const char* titles[] = { "0.9 data", "0.9 Pythia", "2.76 Pythia", "7 Pythia", "7 data" };
9737   
9738   Int_t colors[] = { 1, 2, 3, 4, 6 };
9739   
9740   Int_t maxLeadingPt = 3;
9741   Int_t maxAssocPt = 2;
9742   
9743   TCanvas* canvas = new TCanvas("ComparePPYields", "ComparePPYields", 600, 900);
9744   canvas->Divide(maxAssocPt, maxLeadingPt);
9745   
9746   legend = new TLegend(0.5, 0.5, 0.8, 0.8);
9747   legend->SetFillColor(0);
9748   
9749   TGraphErrors** graphs = new TGraphErrors*[5];
9750   TGraphErrors** graphs2 = new TGraphErrors*[5];
9751       
9752   for (Int_t nFiles = 0; nFiles < 5; nFiles++)
9753   {
9754     graphs[nFiles] = new TGraphErrors;
9755     graphs2[nFiles] = new TGraphErrors;
9756   }
9757   
9758   for (Int_t i=0; i<maxLeadingPt; i++)
9759     for (Int_t j=0; j<maxAssocPt; j++)
9760     {
9761       canvas->cd(j+1 + i * maxAssocPt);
9762       gPad->SetLeftMargin(0.18);
9763       gPad->SetBottomMargin(0.1);
9764       gPad->SetTopMargin(0.01);
9765       gPad->SetRightMargin(0.01);
9766         
9767       TH1* first = 0;
9768         
9769       for (Int_t nFiles = 0; nFiles < 5; nFiles++)
9770       {
9771         currentFile = TFile::Open(files[nFiles]);
9772
9773         Int_t aliceCentrality = 3;
9774           
9775         Printf("%d %d %d", i, j, nFiles);
9776       
9777         alice = (TH1*) currentFile->Get(Form("dphi_%d_%d_%d%s", i, j, aliceCentrality, histName));
9778         if (!alice)
9779           continue;
9780           
9781         alice->SetYTitle("1/N_{trig} dN/dp_{T,assoc}");
9782         alice->SetLineColor(colors[nFiles]);
9783         alice->SetMarkerColor(colors[nFiles]);
9784         alice->GetYaxis()->SetTitleOffset(1.7);
9785         clone = alice->DrawCopy((nFiles > 0) ? "SAME" : "");
9786         clone->SetTitle("");
9787         
9788         Double_t width = 0.7;
9789         Double_t error, error2;
9790         Double_t integral = alice->IntegralAndError(alice->FindBin(-width), alice->FindBin(width), error);
9791         Double_t integral2 = alice->IntegralAndError(alice->FindBin(TMath::Pi() - width), alice->FindBin(TMath::Pi() + width), error2);
9792         
9793         graphs[nFiles]->SetPoint(graphs[nFiles]->GetN(), j + i * maxAssocPt - 0.2, integral);
9794         graphs[nFiles]->SetPointError(graphs[nFiles]->GetN()-1, 0, error);
9795         
9796         graphs2[nFiles]->SetPoint(graphs2[nFiles]->GetN(), j + i * maxAssocPt + 0.2, integral2);
9797         graphs2[nFiles]->SetPointError(graphs2[nFiles]->GetN()-1, 0, error2);
9798         
9799         if (!first)
9800           first = clone;
9801         else
9802           first->GetYaxis()->SetRangeUser(TMath::Min(first->GetMinimum(), clone->GetMinimum()), TMath::Max(first->GetMaximum(), clone->GetMaximum()));
9803           
9804         if (nFiles == 0)
9805         {
9806           TString str(alice->GetTitle());
9807           str.ReplaceAll(" - ", "#");
9808           tokens = str.Tokenize("#");
9809             
9810           for (Int_t k=0; k<2; k++)
9811           {
9812             latex = new TLatex(0.6, 0.88-k*0.07, tokens->At(k)->GetName());
9813             latex->SetNDC();
9814             latex->SetTextSize(0.04);
9815             latex->Draw();
9816           }
9817         }
9818           
9819         if (i == 0 && j == 0)
9820           legend->AddEntry(clone, titles[nFiles]);
9821       }
9822       if (first)
9823         first->GetYaxis()->SetRangeUser(first->GetMinimum(), first->GetMaximum() * 1.1);
9824     }
9825     
9826   canvas->cd(1);
9827   
9828   legend->Draw();
9829   
9830   new TCanvas;
9831   for (Int_t nFiles = 0; nFiles < 5; nFiles++)
9832   {
9833     graphs[nFiles]->SetMarkerStyle(25);
9834     graphs[nFiles]->SetLineColor(colors[nFiles]);
9835     graphs[nFiles]->SetMarkerColor(colors[nFiles]);
9836     clone2 = (TGraphErrors*) graphs[nFiles]->DrawClone((nFiles == 0) ? "AP" : "PSAME");
9837     clone2->GetYaxis()->SetRangeUser(0, 5);
9838   
9839     graphs2[nFiles]->SetMarkerStyle(26);
9840     graphs2[nFiles]->SetLineColor(colors[nFiles]);
9841     graphs2[nFiles]->SetMarkerColor(colors[nFiles]);
9842     graphs2[nFiles]->DrawClone("PSAME");
9843   }  
9844
9845   new TCanvas;
9846   for (Int_t nFiles = 0; nFiles < 5; nFiles++)
9847   {
9848     DivideGraphs(graphs[nFiles], graphs[4]);
9849     DivideGraphs(graphs2[nFiles], graphs2[4]);
9850     
9851     graphs[nFiles]->SetMarkerStyle(25);
9852     graphs[nFiles]->SetLineColor(colors[nFiles]);
9853     graphs[nFiles]->SetMarkerColor(colors[nFiles]);
9854     clone2 = (TGraphErrors*) graphs[nFiles]->DrawClone((nFiles == 0) ? "AP" : "PSAME");
9855     clone2->GetYaxis()->SetRangeUser(0, 1.5);
9856   
9857     graphs2[nFiles]->SetMarkerStyle(26);
9858     graphs2[nFiles]->SetLineColor(colors[nFiles]);
9859     graphs2[nFiles]->SetMarkerColor(colors[nFiles]);
9860     graphs2[nFiles]->DrawClone("PSAME");
9861   }  
9862 }
9863
9864 void DeltaPhiPreliminary(const char* fileName, const char* histName)
9865 {
9866   style(2);
9867
9868   currentFile = TFile::Open(fileName);
9869
9870   TCanvas* canvas = new TCanvas(Form("dphi%s", histName), "dphi", 800, 800);
9871   canvas->Divide(2, 2);
9872   
9873   TLegend* legend = new TLegend(0.55, 0.47, 0.85, 0.65);
9874   legend->SetFillColor(0);
9875   legend->SetTextSize(0.04);
9876   
9877   Int_t colors[] = { 1, 2, 4, 6 };
9878   
9879   Int_t pad = 1;
9880   for (Int_t i=1; i<2; i++)
9881     for (Int_t j=2; j<6; j++)
9882     {
9883       canvas->cd(pad++);
9884   
9885       for (Int_t aliceCentrality=0; aliceCentrality<3; aliceCentrality+=2)
9886       {
9887         Printf("%d %d %d", i, j, aliceCentrality);
9888       
9889         hist = (TH1*) currentFile->Get(Form("dphi_%d_%d_%d%s", i, j, aliceCentrality, histName));
9890         if (!hist)
9891           continue;
9892           
9893         if (aliceCentrality == 3)
9894           hist->Scale(kPythiaScalingFactor);
9895           
9896         hist->GetYaxis()->SetTitleOffset(1.9);
9897         hist->SetLineColor(colors[aliceCentrality]);
9898         hist->SetMarkerColor(colors[aliceCentrality]);
9899         hist->SetLineWidth(2);
9900         hist->SetYTitle("1/N_{trig} dN_{assoc}/d#Delta#phi");
9901         hist->SetXTitle("#Delta#phi (rad)");
9902         
9903         clone = hist->DrawCopy((aliceCentrality > 0) ? "SAME" : "");
9904         clone->SetTitle("");
9905         
9906         TString str(hist->GetTitle());
9907         str.ReplaceAll(" - ", "#");
9908         tokens = str.Tokenize("#");
9909         hist->SetTitle("");
9910           
9911         if (aliceCentrality == 0)
9912         {
9913           for (Int_t k=0; k<2; k++)
9914           {
9915             TString str(tokens->At(k)->GetName());
9916             str.ReplaceAll(".0", "");
9917             str.ReplaceAll("< p", "GeV/c < p");
9918             str += " GeV/c";
9919           
9920             latex = new TLatex(0.5, 0.88-k*0.06, str);
9921             latex->SetNDC();
9922             latex->SetTextSize(0.04);
9923             latex->Draw();
9924           }
9925           
9926           latex = new TLatex(0.5, 0.76, "ALICE preliminary");
9927           latex->SetTextSize(0.04);
9928           latex->SetNDC();
9929           latex->Draw();
9930         
9931           latex = new TLatex(0.5, 0.70, "Stat. uncertainties only");
9932           latex->SetTextSize(0.04);
9933           latex->SetNDC();
9934           latex->Draw();
9935
9936           clone->GetYaxis()->SetRangeUser(0, clone->GetMaximum() * 1.2);
9937         }
9938         
9939         if (pad == 2)
9940         {
9941           if (aliceCentrality == 3)
9942             legend->AddEntry(hist, "Pythia");
9943           else
9944             legend->AddEntry(hist, tokens->At(2)->GetName());
9945         }
9946         
9947         legend->Draw();
9948         
9949       }
9950     }
9951     
9952   canvas->cd(3);
9953   
9954   canvas->SaveAs(Form("%s.eps", canvas->GetName()));
9955   canvas->SaveAs(Form("%s.png", canvas->GetName()));
9956 }
9957
9958 void DeltaPhiBaseLinePreliminary(const char* fileName)
9959 {
9960   style(2);
9961   
9962   loadlibs();
9963
9964   Float_t leadingPtArr[] = { 6.0, 8.0, 10.0, 15.0, 15.0 };
9965   Float_t assocPtArr[] =     { 0.5, 1.5, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
9966   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
9967
9968   Int_t i = 1;
9969   Int_t j = 3;
9970   Int_t step = 0;
9971
9972   gpTMin = assocPtArr[j] + 0.01;
9973   gpTMax = assocPtArr[j+1] - 0.01;
9974   SetupRanges(h);
9975       
9976   TString str;
9977   str.Form("%.0f GeV/c < p_{T,trig} < %.0f GeV/c", leadingPtArr[i], leadingPtArr[i+2]);
9978   
9979   TString str2;
9980   str2.Form("%.0f GeV/c < p_{T,assoc} < %.0f GeV/c", gpTMin - 0.01, gpTMax + 0.01);
9981           
9982   Float_t v2[3];
9983   TH1* hist1 = 0;
9984   TH1* hist2b = 0;
9985   
9986   GetDistAndFlow(h, 0, &hist1,  v2, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+2] - 0.01); 
9987   GetDistAndFlow(h, 0, &hist2b, v2+2, step, 60, 90, leadingPtArr[i] + 0.01, leadingPtArr[i+2] - 0.01); 
9988   
9989   hist1->SetLineWidth(2);
9990   hist2b->SetLineWidth(2);
9991
9992   canvas = new TCanvas("dphi_baseline", "dphi_baseline", 1200, 1200);
9993   canvas->Divide(2, 2);
9994   
9995   canvas->cd(1);
9996 //   gPad->SetLeftMargin(0.20);
9997   
9998   hist1->GetYaxis()->SetTitleOffset(1.9);
9999   hist1->SetYTitle("1/N_{trig} dN_{assoc}/d#Delta#phi");
10000   hist1->SetXTitle("#Delta#phi (rad)");
10001   hist1->SetTitle("");
10002   hist1->DrawCopy()->GetYaxis()->SetRangeUser(0, 0.59);
10003   
10004   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);
10005           
10006   latex = new TLatex(0.5, 0.78, "0-5%");
10007   latex->SetNDC();
10008   latex->SetTextSize(0.04);
10009   latex->Draw();
10010   
10011   if (1)
10012   {
10013     canvas->cd(2);
10014   //   gPad->SetLeftMargin(0.20);
10015     
10016     hist1->DrawCopy()->GetYaxis()->SetRangeUser(0.18, 0.295);
10017     DrawFlow(v2[0], hist1, leadingPtArr[i], assocPtArr[j], 0, i, 0, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
10018     
10019     latex->Draw();
10020     
10021     canvas->cd(3);
10022   //   gPad->SetLeftMargin(0.20);
10023     
10024     hist2b->GetYaxis()->SetTitleOffset(1.9);
10025     hist2b->SetYTitle("1/N_{trig} dN_{assoc}/d#Delta#phi");
10026     hist2b->SetXTitle("#Delta#phi (rad)");
10027     hist2b->SetTitle("");
10028     hist2b->DrawCopy();
10029             
10030     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);
10031     
10032     latex = new TLatex(0.5, 0.78, "60-90%");
10033     latex->SetNDC();
10034     latex->SetTextSize(0.04);
10035     latex->Draw();
10036     
10037     canvas->cd(4);
10038   //   gPad->SetLeftMargin(0.20);
10039         
10040     hist2b->DrawCopy()->GetYaxis()->SetRangeUser(0.01, 0.13);
10041     DrawFlow(v2[2], hist2b, leadingPtArr[i], assocPtArr[j], 0, i, 2, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
10042         
10043     latex->Draw();
10044   }
10045   
10046   for (Int_t i=1; i<=4; i++)
10047   {
10048     canvas->cd(i);
10049     
10050     latex = new TLatex(0.5, 0.84, str);
10051     latex->SetNDC();
10052     latex->SetTextSize(0.04);
10053     latex->Draw();
10054     
10055     latex = new TLatex(0.5, 0.90, str2);
10056     latex->SetNDC();
10057     latex->SetTextSize(0.04);
10058     latex->Draw();
10059   
10060     latex = new TLatex(0.5, 0.72, "ALICE preliminary");
10061     latex->SetTextSize(0.04);
10062     latex->SetNDC();
10063     latex->Draw();
10064   
10065     latex = new TLatex(0.5, 0.66, "Stat. uncertainties only");
10066     latex->SetTextSize(0.04);
10067     latex->SetNDC();
10068     latex->Draw();
10069   }
10070     
10071   canvas->SaveAs(Form("%s.eps", canvas->GetName()));
10072   canvas->SaveAs(Form("%s.png", canvas->GetName()));
10073 }
10074
10075 /*
10076 void DeltaPhiBaseLinePaperPlot(const char* fileName, const char* yieldFile)
10077 {
10078   style(2);
10079   
10080   Float_t fontSize = 0.08;
10081   Float_t titleOffset = 0.85;
10082   
10083   gStyle->SetTextSize(fontSize);
10084   gStyle->SetLabelSize(fontSize, "xy");
10085   gStyle->SetTitleSize(fontSize, "xy");
10086   gStyle->SetTitleOffset(titleOffset, "y");
10087   gStyle->SetHistLineWidth(2);
10088   gROOT->ForceStyle();
10089   
10090   loadlibs();
10091
10092   Float_t leadingPtArr[] = { 6.0, 8.0, 10.0, 15.0, 15.0 };
10093   Float_t assocPtArr[] =     { 0.5, 1.5, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
10094   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
10095
10096   Int_t i = 1;
10097   Int_t j = 3;
10098   Int_t step = 0;
10099
10100   gpTMin = assocPtArr[j] + 0.01;
10101   gpTMax = assocPtArr[j+1] - 0.01;
10102   SetupRanges(h);
10103       
10104   TString str;
10105   str.Form("%.0f GeV/#font[12]{c} < p_{t,trig} < %.0f GeV/#font[12]{c}", leadingPtArr[i], leadingPtArr[i+2]);
10106   
10107   TString str2;
10108   str2.Form("%.0f GeV/#font[12]{c} < p_{t,assoc} < %.0f GeV/#font[12]{c}", gpTMin - 0.01, gpTMax + 0.01);
10109           
10110   Float_t v2[3];
10111   TH1* hist1 = 0;
10112   TH1* hist2b = 0;
10113   
10114   GetDistAndFlow(h, 0, &hist1,  v2, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+2] - 0.01); 
10115   
10116   hist1->SetLineWidth(2);
10117
10118   canvas = new TCanvas("dphi_baseline", "dphi_baseline", 600, 840);
10119   canvas->Range(0, 0, 1, 1);
10120   
10121   pad1 = new TPad("pad1", "pad1", 0, 0.69, 1, 1);
10122   pad1->Draw();
10123   
10124   pad2 = new TPad("pad2", "pad2", 0, 0.38, 1, 0.69);
10125   pad2->Draw();
10126
10127   pad3 = new TPad("pad3", "pad3", 0, 0   , 1, 0.38);
10128   pad3->Draw();
10129   
10130   pad1->cd();
10131   gPad->SetMargin(0.15, 0.02, 0, 0.01);
10132
10133 //   hist1->GetYaxis()->SetTitleOffset(0.85);
10134   hist1->SetYTitle("1/N_{trig} dN_{assoc}/d#Delta#varphi");
10135   hist1->SetXTitle("#Delta#varphi (rad)");
10136   hist1->SetTitle("");
10137   
10138   hist1->SetLabelSize(fontSize * 0.38 / 0.31, "xy");
10139   hist1->SetTitleSize(fontSize * 0.38 / 0.31, "xy");
10140   hist1->SetTitleOffset(titleOffset / 0.38 * 0.31, "y");
10141   
10142   hist1->DrawCopy(); //->GetYaxis()->SetRangeUser(0, 0.59);
10143   
10144   //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);
10145           
10146   pad2->cd();
10147   gPad->SetMargin(0.15, 0.02, 0, 0);
10148
10149   hist1->DrawCopy()->GetYaxis()->SetRangeUser(0.381, 0.457);
10150   DrawFlow(v2[0], hist1, leadingPtArr[i], assocPtArr[j], 0, i, 0, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
10151   
10152   pad3->cd();
10153   gPad->SetMargin(0.15, 0.02, 0.2, 0);
10154   
10155   // get zero subtracted plots
10156   TFile::Open(yieldFile);
10157   hist1sub = (TH1*) gFile->Get(Form("dphi_%d_%d_%d_fit_flat", i, j, 0));
10158   hist1sub->SetYTitle("1/N_{trig} dN_{assoc}/d#Delta#varphi");
10159   hist1sub->SetXTitle("#Delta#varphi (rad)");
10160   hist1sub->SetTitle("");
10161   hist1sub->DrawCopy();
10162   
10163   hist2sub = (TH1*) gFile->Get(Form("dphi_%d_%d_%d_fit_flat", i, j, 2));
10164   hist2sub->SetMarkerStyle(24);
10165   hist2sub->SetLineColor(2);
10166   hist2sub->SetMarkerColor(2);
10167 //   hist2sub->SetMarkerSize(0.8);
10168   hist2sub->DrawCopy("SAMEP E X0");
10169   
10170   hist3sub = (TH1*) gFile->Get(Form("dphi_%d_%d_%d_fit_flat", i, j, 3));
10171   hist3sub->SetMarkerStyle(25);
10172   hist3sub->SetLineColor(4);
10173   hist3sub->SetMarkerColor(4);
10174 //   hist3sub->SetMarkerSize(0.8);
10175   hist3sub->DrawCopy("SAMEP E X0");
10176
10177   legend = new TLegend(0.4, 0.55, 0.9, 0.9);
10178   legend->SetFillColor(0);
10179   legend->SetBorderSize(0);
10180   legend->SetTextSize(0.08);
10181   legend->AddEntry(hist1sub, "Pb-Pb 0-5% centrality", "L");
10182   legend->AddEntry(hist2sub, "Pb-Pb 60-90% centrality", "P");
10183   legend->AddEntry(hist3sub, "pp", "P");
10184   legend->Draw();
10185
10186   pad1->cd();
10187   
10188   latex = new TLatex(0.47, 0.85, str);
10189   latex->SetTextSize(fontSize * 0.38 / 0.31);
10190   latex->SetNDC();
10191   latex->Draw();
10192     
10193   latex = new TLatex(0.47, 0.73, str2);
10194   latex->SetTextSize(fontSize * 0.38 / 0.31);
10195   latex->SetNDC();
10196   latex->Draw();
10197   
10198   latex = new TLatex(0.5, 0.42, "0-5% centrality");
10199   latex->SetNDC();
10200 //   latex->Draw();
10201   
10202   latex = new TLatex(0.45, 0.62, "Stat. uncertainties only");
10203   latex->SetNDC();
10204 //   latex->Draw();
10205     
10206   canvas->SaveAs(Form("%s.eps", canvas->GetName()));
10207   canvas->SaveAs(Form("%s.png", canvas->GetName()));
10208 }
10209 */
10210
10211 void DeltaPhiBaseLinePaperPlot(const char* fileName, const char* yieldFile)
10212 {
10213   style(2);
10214   
10215   Float_t fontSize = 0.08;
10216   Float_t titleOffset = 0.85;
10217   
10218   gStyle->SetTextSize(fontSize);
10219   gStyle->SetLabelSize(fontSize, "xy");
10220   gStyle->SetTitleSize(fontSize, "xy");
10221   gStyle->SetTitleOffset(titleOffset, "y");
10222   gStyle->SetHistLineWidth(2);
10223   gROOT->ForceStyle();
10224   
10225   loadlibs();
10226
10227   Float_t leadingPtArr[] = { 6.0, 8.0, 10.0, 15.0, 15.0 };
10228   Float_t assocPtArr[] =     { 0.5, 1.5, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
10229   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
10230
10231   Int_t i = 1;
10232   Int_t j = 3;
10233   Int_t step = 0;
10234
10235   gpTMin = assocPtArr[j] + 0.01;
10236   gpTMax = assocPtArr[j+1] - 0.01;
10237   SetupRanges(h);
10238       
10239   TString str;
10240   str.Form("%.0f < #font[12]{p}_{T,trig} < %.0f GeV/#font[12]{c}", leadingPtArr[i], leadingPtArr[i+2]);
10241   
10242   TString str2;
10243   str2.Form("%.0f < #font[12]{p}_{T,assoc} < %.0f GeV/#font[12]{c}", gpTMin - 0.01, gpTMax + 0.01);
10244           
10245   Float_t v2[3];
10246   TH1* hist1 = 0;
10247   TH1* hist2b = 0;
10248   
10249   GetDistAndFlow(h, 0, &hist1,  v2, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+2] - 0.01); 
10250   
10251   hist1->SetLineWidth(2);
10252
10253   canvas = new TCanvas("dphi_baseline", "dphi_baseline", 600, 840);
10254   canvas->Range(0, 0, 1, 1);
10255   
10256   pad1 = new TPad("pad1", "pad1", 0, 0.69, 1, 1);
10257   pad1->Draw();
10258   
10259   pad2 = new TPad("pad2", "pad2", 0, 0.38, 1, 0.69);
10260   pad2->Draw();
10261
10262   pad3 = new TPad("pad3", "pad3", 0, 0   , 1, 0.38);
10263   pad3->Draw();
10264   
10265   pad1->cd();
10266   gPad->SetMargin(0.15, 0.02, 0, 0.01);
10267
10268 //   hist1->GetYaxis()->SetTitleOffset(0.85);
10269   hist1->SetYTitle("");
10270   hist1->SetXTitle("#Delta#font[12]{#varphi} (rad)");
10271   hist1->SetTitle("");
10272   
10273   hist1->SetLabelSize(fontSize * 0.38 / 0.31, "xy");
10274   hist1->SetTitleSize(fontSize * 0.38 / 0.31, "xy");
10275   hist1->SetTitleOffset(titleOffset / 0.38 * 0.31, "y");
10276   
10277   hist1->DrawCopy("HISTE"); //->GetYaxis()->SetRangeUser(0, 0.59);
10278   
10279   //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);
10280           
10281   pad2->cd();
10282   gPad->SetMargin(0.15, 0.02, 0, 0);
10283
10284   hist1->SetYTitle("1/#font[12]{N}_{trig} d#font[12]{N}_{assoc}/d#Delta#font[12]{#varphi} (rad^{-1})");
10285   hist1->DrawCopy("HISTE")->GetYaxis()->SetRangeUser(0.381, 0.457);
10286   DrawFlow(v2[0], hist1, leadingPtArr[i], assocPtArr[j], 0, i, 0, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
10287   
10288   pad3->cd();
10289   gPad->SetMargin(0.15, 0.02, 0.2, 0);
10290   
10291   // get zero subtracted plots
10292   TFile::Open(yieldFile);
10293
10294   hist1sub = (TH1*) gFile->Get(Form("dphi_%d_%d_%d_fit_flat", i, j, 0));
10295   hist1sub->SetYTitle("");
10296   hist1sub->SetXTitle("#Delta#varphi (rad)");
10297   hist1sub->SetTitle("");
10298 //   hist1sub->SetMarkerStyle(25);
10299 //   hist1sub->SetLineColor(4);
10300 //   hist1sub->SetMarkerColor(4);
10301   hist1sub->SetMaximum(0.79);
10302   hist1sub->DrawCopy("HIST E");
10303   
10304   hist3sub = (TH1*) gFile->Get(Form("dphi_%d_%d_%d_fit_flat", i, j, 3));
10305 //   hist3sub->SetFillColor(4); 
10306 //   hist3sub->SetFillStyle(3354);
10307 //   hist3sub->SetLineWidth(0);
10308 //   hist3sub->SetLineColor(0);
10309   hist3sub->SetMarkerStyle(25);
10310   hist3sub->SetLineColor(4);
10311   hist3sub->SetMarkerColor(4);
10312   hist3sub->DrawCopy("SAME E X0");
10313
10314   hist1sub->DrawCopy("SAME HIST E");
10315   
10316   hist2sub = (TH1*) gFile->Get(Form("dphi_%d_%d_%d_fit_flat", i, j, 2));
10317   hist2sub->SetMarkerStyle(24);
10318   hist2sub->SetLineColor(2);
10319   hist2sub->SetMarkerColor(2);
10320   hist2sub->DrawCopy("SAMEP E X0");
10321   
10322   legend = new TLegend(0.4, 0.45, 0.9, 0.8);
10323   legend->SetFillColor(0);
10324   legend->SetBorderSize(0);
10325   legend->SetTextSize(fontSize);
10326   legend->AddEntry(hist1sub, "Pb-Pb 0-5% centrality", "L");
10327   legend->AddEntry(hist2sub, "Pb-Pb 60-90% centrality", "P");
10328   legend->AddEntry(hist3sub, "pp", "P");
10329   legend->Draw();
10330
10331   pad1->cd();
10332   
10333   latex = new TLatex(0.59, 0.70, str);
10334   latex->SetTextSize(fontSize * 0.38 / 0.31);
10335   latex->SetNDC();
10336   latex->Draw();
10337     
10338   latex = new TLatex(0.59, 0.58, str2);
10339   latex->SetTextSize(fontSize * 0.38 / 0.31);
10340   latex->SetNDC();
10341   latex->Draw();
10342   
10343   latex = new TLatex(0.59, 0.46, "#sqrt{#font[12]{s}_{NN}} = 2.76 TeV");
10344   latex->SetTextSize(fontSize * 0.38 / 0.31);
10345   latex->SetNDC();
10346   latex->Draw();
10347
10348   latex = new TLatex(0.43, 0.90, "a) not background subtracted");
10349   latex->SetTextSize(fontSize * 0.38 / 0.31);
10350   latex->SetNDC();
10351   latex->Draw();
10352
10353   latex = new TLatex(0.5, 0.42, "0-5% centrality");
10354   latex->SetNDC();
10355 //   latex->Draw();
10356   
10357   latex = new TLatex(0.45, 0.62, "Stat. uncertainties only");
10358   latex->SetNDC();
10359 //   latex->Draw();
10360
10361   pad2->cd();
10362
10363   latex = new TLatex(0.43, 0.90, "b) zoomed");
10364   latex->SetTextSize(fontSize * 0.38 / 0.31);
10365   latex->SetNDC();
10366   latex->Draw();
10367   
10368   pad3->cd();
10369
10370   latex = new TLatex(0.43, 0.90, "c) background subtracted");
10371   latex->SetNDC();
10372   latex->Draw();
10373   
10374     
10375   canvas->SaveAs(Form("%s.eps", canvas->GetName()));
10376   canvas->SaveAs(Form("%s.png", canvas->GetName()));
10377 }
10378
10379
10380 void DeltaPhiRidgePreliminary(const char* fileName)
10381 {
10382   style();
10383   
10384   loadlibs();
10385
10386   Float_t leadingPtArr[] = { 2.0, 2.0, 3.0, 4.0, 10.0, 20.0, 40.0 };
10387   Float_t assocPtArr[] =   { 1.0, 2.0, 3.0, 6.0, 10.0, 20.0, 40.0 };
10388 //   Float_t leadingPtArr[] = { 6.0, 8.0, 10.0, 15.0, 15.0 };
10389 //   Float_t assocPtArr[] =     { 0.5, 1.5, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
10390   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName, 0, kFALSE);
10391   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
10392
10393 //   Int_t i = 1;
10394 //   Int_t j = 3;
10395   Int_t i = 0;
10396   Int_t j = 0;
10397   Int_t step = 6;
10398
10399   gpTMin = assocPtArr[j] + 0.01;
10400   gpTMax = assocPtArr[j+1] - 0.01;
10401   SetupRanges(h);
10402   SetupRanges(hMixed);
10403       
10404   TString str;
10405   str.Form("%.1f < p_{T,trig} < %.1f", leadingPtArr[i], leadingPtArr[i+2]);
10406   
10407   TString str2;
10408   str2.Form("%.1f < p_{T,assoc} < %.1f", gpTMin - 0.01, gpTMax + 0.01);
10409           
10410   Float_t v2[3];
10411   TH1* hist1 = 0;
10412   TH1* hist2b = 0;
10413   TH1* hist1Peak = 0;
10414   TH1* hist2bPeak = 0;
10415   TH1* hist1Ridge = 0;
10416   TH1* hist2bRidge = 0;
10417   
10418   TH1* hist2d = 0;
10419   TH1* hist2dMixed = 0;
10420   
10421 //   GetDistAndFlow(h, 0, &hist2d,  v2, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+2] - 0.01, 1); 
10422 //   GetDistAndFlow(hMixed, 0, &hist2dMixed,  v2, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+2] - 0.01, 1); 
10423 //   new TCanvas;
10424 //   //hist2d->Divide(hist2dMixed);
10425 //   hist2dMixed->Draw("SURF1");
10426   
10427   GetDistAndFlow(h, hMixed, &hist1,  0, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+2] - 0.01); 
10428 //   GetDistAndFlow(h, 0, &hist2b, v2[2], step, 60, 90, leadingPtArr[i] + 0.01, leadingPtArr[i+2] - 0.01); 
10429   GetDistAndFlow(h, hMixed, &hist1Peak,  0, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+2] - 0.01, 10); 
10430
10431   GetDistAndFlow(h, hMixed, &hist1Ridge,  0, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+2] - 0.01, 11); 
10432
10433   // TODO normalize
10434
10435   canvas = new TCanvas("dphi_baseline", "dphi_baseline", 800, 800);
10436   canvas->Divide(2, 2);
10437   
10438   canvas->cd(1);
10439   gPad->SetLeftMargin(0.20);
10440   
10441   hist1->GetYaxis()->SetTitleOffset(1.9);
10442   hist1->SetYTitle("1/N_{trig} dN/dp_{T,assoc}");
10443   hist1->SetTitle("");
10444   hist1->DrawCopy();
10445   
10446   hist1Peak->SetLineColor(2);
10447   hist1Peak->DrawCopy("SAME");
10448   
10449   hist1Ridge->SetLineColor(4);
10450   hist1Ridge->DrawCopy("SAME");
10451   
10452 //   hist1Peak->Add(hist1Ridge);
10453 //   hist1Peak->DrawCopy("SAME")->SetLineColor(3);
10454   
10455   return;
10456   
10457   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);
10458           
10459   latex = new TLatex(0.65, 0.84, str);
10460   latex->SetNDC();
10461   latex->SetTextSize(0.04);
10462   latex->Draw();
10463   
10464   latex = new TLatex(0.65, 0.90, str2);
10465   latex->SetNDC();
10466   latex->SetTextSize(0.04);
10467   latex->Draw();
10468
10469   latex = new TLatex(0.84, 0.78, "0-5%");
10470   latex->SetNDC();
10471   latex->SetTextSize(0.04);
10472   latex->Draw();
10473   
10474   canvas->cd(2);
10475   gPad->SetLeftMargin(0.20);
10476   
10477   hist1->DrawCopy()->GetYaxis()->SetRangeUser(0.18, 0.28);
10478   DrawFlow(v2[0], hist1, leadingPtArr[i], assocPtArr[j], 0, i, 0, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
10479   
10480   latex->Draw();
10481   
10482   latex = new TLatex(0.5, 0.90, "ALICE preliminary");
10483   latex->SetTextSize(0.04);
10484   latex->SetNDC();
10485   latex->Draw();
10486
10487   latex = new TLatex(0.5, 0.84, "Statistical uncertainties only");
10488   latex->SetTextSize(0.04);
10489   latex->SetNDC();
10490   latex->Draw();
10491   
10492   canvas->cd(3);
10493   gPad->SetLeftMargin(0.20);
10494   
10495   hist2b->GetYaxis()->SetTitleOffset(1.9);
10496   hist2b->SetYTitle("1/N_{trig} dN/dp_{T,assoc}");
10497   hist2b->SetTitle("");
10498   hist2b->DrawCopy();
10499            
10500   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);
10501   
10502   latex = new TLatex(0.84, 0.78, "60-90%");
10503   latex->SetNDC();
10504   latex->SetTextSize(0.04);
10505   latex->Draw();
10506   
10507   canvas->cd(4);
10508   gPad->SetLeftMargin(0.20);
10509       
10510   hist2b->DrawCopy()->GetYaxis()->SetRangeUser(0.01, 0.1);
10511   DrawFlow(v2[2], hist2b, leadingPtArr[i], assocPtArr[j], 0, i, 2, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
10512       
10513   latex->Draw();
10514   
10515   canvas->SaveAs(Form("%s.eps", canvas->GetName()));
10516   canvas->SaveAs(Form("%s.png", canvas->GetName()));
10517 }
10518
10519 void MCScalingFactor(Int_t caseId)
10520 {
10521   // 900 GeV
10522   // x[5]=5, y[5]=0.813743, ex[5]=0, ey[5]=0.158446
10523   // x[5]=5, y[5]=1.09804, ex[5]=0, ey[5]=0.265434
10524   // 7 TeV
10525   // x[5]=5, y[5]=1.02276, ex[5]=0, ey[5]=0.0199991
10526   // x[5]=5, y[5]=0.870247, ex[5]=0, ey[5]=0.0294444
10527   
10528   Float_t factors[] = { 0.814, 1.098, 1.022, 0.870 };
10529   Float_t errors[]  = { 0.158, 0.265, 0.020, 0.029 };
10530   
10531   Float_t avgs[2];
10532   
10533   for (Int_t i=0; i<2; i++)
10534   {
10535     switch (caseId)
10536     {
10537       case 0:
10538         avgs[i] = factors[2*i] / errors[2*i] / errors[2*i] + factors[2*i+1] / errors[2*i+1] / errors[2*i+1];
10539         avgs[i] /= 1. / errors[2*i] / errors[2*i] + 1. / errors[2*i+1] / errors[2*i+1];
10540         break;
10541         
10542       case 1:
10543         avgs[i] = factors[2*i];
10544         break;
10545     
10546       case 2:
10547         avgs[i] = factors[2*i+1];
10548         break;
10549     
10550       case 3:
10551         avgs[0] = factors[0];
10552         avgs[1] = factors[3];
10553         break;
10554     
10555       case 4:
10556         avgs[0] = factors[1];
10557         avgs[1] = factors[2];
10558         break;
10559     }
10560   }
10561   
10562   Float_t a = avgs[0];
10563   Float_t b = avgs[1];
10564   
10565   Printf("%f %f", a, b);
10566   
10567   Float_t linEx = a + (b-a)/(7.-0.9) * (2.76-0.9);
10568   Float_t logEx = a + (b-a)/(log(7.)-log(0.9)) * (log(2.76)-log(0.9));
10569   
10570   Printf("%f %f", linEx, logEx);
10571 }
10572   
10573 void CompareDeltaPhi(const char* fileName1, const char* fileName2, Int_t centralityID, const char* dist = "_fit_flat", Bool_t reduced = kFALSE)
10574 {
10575   firstFile = TFile::Open(fileName1);
10576   secondFile = TFile::Open(fileName2);
10577
10578   Int_t maxLeadingPt = 2;
10579   Int_t maxAssocPt = 7;
10580   Int_t minLeadingPt = 0;
10581   Int_t minAssocPt = 0;
10582   
10583   if (reduced)
10584   {
10585     maxLeadingPt = 2;
10586     maxAssocPt = 5;
10587     minLeadingPt = 1;
10588     minAssocPt = 2;
10589   }
10590   
10591   TCanvas* canvas = new TCanvas(Form("%s %s", fileName1, fileName2 ? fileName2 : ""), Form("%s %s", fileName1, fileName2 ? fileName2 : ""), 1000, 700);
10592   canvas->Divide(maxAssocPt-minAssocPt, maxLeadingPt-minLeadingPt);
10593   
10594   for (Int_t i=minLeadingPt; i<maxLeadingPt; i++)
10595     for (Int_t j=minAssocPt; j<maxAssocPt; j++)
10596     {
10597       Printf("%d %d", i, j);
10598     
10599       canvas->cd(j+1-minAssocPt + (i-minLeadingPt) * maxAssocPt);
10600       gPad->SetLeftMargin(0.15);
10601       gPad->SetBottomMargin(0.2);
10602       //gPad->SetTopMargin(0.01);
10603       gPad->SetRightMargin(0.01);
10604       
10605       hist1 = (TH1*) firstFile->Get(Form("dphi_%d_%d_%d%s", i, j, centralityID, dist));
10606       hist2 = (TH1*) secondFile->Get(Form("dphi_%d_%d_%d%s", i, j, centralityID, dist));
10607       
10608       if (!hist1)
10609         continue;
10610       
10611 /*      hist1->Rebin(2); hist1->Scale(0.5); 
10612       hist2->Rebin(2); hist2->Scale(0.5); */
10613 //       hist1->Scale(1.6);
10614         
10615       hist1->SetLineColor(1);
10616       hist2->SetLineColor(2);
10617       
10618       hist1->DrawCopy()->GetYaxis()->SetRangeUser(hist1->GetMinimum(), hist1->GetMaximum() * 1.2);
10619       hist2->DrawCopy("SAME");
10620       
10621 /*      if (strlen(dist) == 0)
10622         Printf("chi2 test: %f", hist1->Chi2Test(hist2, "UU NORM CHI2/NDF"));*/
10623       
10624       //DrawRatio(hist1, hist2, hist1->GetTitle());
10625       
10626       //return;
10627     }
10628 }
10629   
10630 TH1* MACHCone(const char* fileName, Int_t centrality, const char* drawingOption, Bool_t plotContributions, Int_t twoD, TF1** flowFuncP = 0)
10631 {
10632   if (0)
10633   {
10634     TFile::Open("machcone_input.root");
10635     
10636     switch (centrality)
10637     {
10638       case 0:
10639         hist = (TH1*) gFile->Get("dphi_0_0_0");
10640         break;
10641       
10642       case 1:
10643         hist = (TH1*) gFile->Get("dphi_1_1_0");
10644         break;
10645         
10646       case 2:
10647         hist = (TH1*) gFile->Get("dphi_0_0_2");
10648         break;
10649     
10650       case 3:
10651         hist = (TH1*) gFile->Get("dphi_1_1_2");
10652         break;
10653     }
10654   }
10655   else
10656   {
10657     loadlibs();
10658     
10659     AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
10660     AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
10661     
10662     Float_t leadingPtArr[] = { 2.0, 3.0, 4.0, 10.0, 20.0, 40.0 };
10663     Float_t assocPtArr[] =   { 1.0, 2.0, 3.0, 6.0, 10.0, 20.0, 40.0 };
10664 //     Float_t assocPtArr[] =   { 2.0, 3.0, 6.0, 10.0, 20.0, 40.0 };
10665   
10666     Int_t i = centrality % 2;
10667     Int_t step = 6;
10668     
10669     Int_t j = 0;
10670     
10671     gpTMin = assocPtArr[i] + 0.01;
10672     gpTMax = assocPtArr[i+1] - 0.01;
10673     
10674     Int_t centralityBegin = 0;
10675     Int_t centralityEnd = 1;
10676     
10677     if (centrality >= 2)
10678     {
10679       centralityBegin = 30;
10680       centralityEnd = 40;
10681     }
10682       
10683     SetupRanges(h);
10684     SetupRanges(hMixed);
10685     
10686     TH1* hist = 0;
10687     Float_t vn[5];
10688     vn[0] = 0;
10689     vn[1] = 0;
10690     vn[2] = 0;
10691     vn[3] = 0;
10692     vn[4] = 0;
10693     
10694     Bool_t scaleToPairs = 0;
10695     
10696     GetDistAndFlow(h, hMixed, &hist, 0, step, centralityBegin, centralityEnd, leadingPtArr[j] + 0.01, leadingPtArr[j+1] - 0.01, twoD, kTRUE, vn, scaleToPairs); 
10697     if (scaleToPairs && twoD == 11)
10698       hist->Scale(2);  
10699     
10700     Printf("%f %f %f", vn[2], vn[3], vn[4]);
10701     
10702     // mirror delta phi to improve stats
10703     if (1)
10704     {
10705       for (Int_t bin=1; bin<=hist->GetNbinsX(); bin++)
10706       {
10707         if (hist->GetBinCenter(bin) < 0 || hist->GetBinCenter(bin) > TMath::Pi())
10708         {
10709           if (hist->GetBinCenter(bin) < 0)
10710             Int_t bin2 = hist->FindBin(-1.0 * hist->GetBinCenter(bin));
10711           else
10712             Int_t bin2 = hist->FindBin(TMath::TwoPi() - hist->GetBinCenter(bin));
10713           
10714           Float_t combValue = hist->GetBinContent(bin) / hist->GetBinError(bin) / hist->GetBinError(bin) + hist->GetBinContent(bin2) / hist->GetBinError(bin2) / hist->GetBinError(bin2);
10715           
10716           Float_t weight = 1. / hist->GetBinError(bin) / hist->GetBinError(bin) + 1. / hist->GetBinError(bin2) / hist->GetBinError(bin2);
10717           combValue /= weight;
10718           
10719           Float_t combError = TMath::Sqrt(1.0 / weight);
10720           
10721           hist->SetBinContent(bin2, combValue);
10722           hist->SetBinError(bin2, combError);
10723
10724           hist->SetBinContent(bin, combValue);
10725           hist->SetBinError(bin, combError);
10726           
10727           Printf("%d %d %f %f", bin, bin2, combValue, combError);
10728         }
10729       }
10730     }
10731   }
10732   
10733   TString str(hist->GetTitle());
10734   str.ReplaceAll(" - ", "#");
10735   tokens = str.Tokenize("#");
10736   hist->SetTitle("");
10737   
10738   hist->SetLineColor(1);
10739   hist->SetYTitle("1/N_{trig} dN_{assoc}/d#Delta#phi");
10740   hist->SetXTitle("#Delta#phi (rad)");
10741   hist = (TH1*) hist->Clone();
10742   if (!drawingOption)
10743     return hist;
10744   
10745   hist = hist->DrawCopy(drawingOption);
10746   
10747   for (Int_t i=0; i<tokens->GetEntries()-1; i++)
10748   {
10749     if (centrality == 1)
10750       latex = new TLatex(0.6, 0.9 - i*0.05 - gPad->GetTopMargin(), tokens->At(i)->GetName());
10751     else
10752       latex = new TLatex(0.6, 0.12 - i*0.05, tokens->At(i)->GetName());
10753     
10754     latex->SetNDC();
10755     latex->SetTextSize(0.04);
10756     latex->Draw();
10757   }
10758   
10759   TF1* flowFunc = new TF1("flowFunc", "[0] * (1+2*[1]*cos(2*x)+2*[2]*cos(3*x)+2*[3]*cos(4*x)+2*[4]*cos(5*x))", -0.5 * TMath::Pi(), 1.5 * TMath::Pi());
10760   //flowFunc->SetLineWidth(1);
10761   flowFunc->SetLineColor(2);
10762   flowFunc->SetLineStyle(2);
10763   for (Int_t i=0; i<4; i++)
10764     flowFunc->FixParameter(i+1, vn[i+1]);
10765   //flowFunc->SetParameter(0, 84.95); flowFunc->DrawClone("SAME");
10766   
10767   //flowFunc->SetParameter(0, 85.4); flowFunc->DrawClone("SAME");
10768   //flowFunc->SetParameter(0, 85.6); flowFunc->DrawClone("SAME");
10769   
10770 //   hist->Fit(flowFunc, "", "SAME", 1.8, 4.5);
10771   hist->Fit(flowFunc, "N", "", -0.5 * TMath::Pi(), 1.5 * TMath::Pi());
10772   hist->GetYaxis()->SetRangeUser(hist->GetMinimum() * 0.95, hist->GetMaximum() * 1.05);
10773   flowFunc->SetRange(-0.5 * TMath::Pi(), 1.5 * TMath::Pi());
10774   flowFunc->Draw("SAME");
10775   
10776   if (flowFuncP)
10777     *flowFuncP = flowFunc;
10778   
10779   //hist->GetYaxis()->SetRangeUser(84, 89);
10780   //flowFunc->SetParameter(4, 1);
10781   
10782   Float_t chi2 = 0;
10783   Int_t n=0;
10784   for (Int_t bin=hist->FindBin(1.8); bin<=hist->FindBin(4.5); bin++)
10785   {
10786     chi2 += TMath::Power((hist->GetBinContent(bin) - flowFunc->Eval(hist->GetBinCenter(bin))) / hist->GetBinError(bin), 2);
10787     n++;
10788     //Printf("%f", TMath::Power((hist->GetBinContent(bin) - flowFunc->Eval(hist->GetBinCenter(bin))) / hist->GetBinError(bin), 2));
10789   }
10790     
10791   chi2 /= n;
10792   
10793   Printf("chi2/ndf = %f", chi2);
10794   
10795   if (!plotContributions)
10796     return hist;
10797   
10798   for (Int_t n=1; n<=5; n++)
10799   {
10800     flowFuncPart = new TF1("flowFuncPart", "[0] * (1+2*[1]*cos([2]*x))", -0.5 * TMath::Pi(), 1.5 * TMath::Pi());
10801     flowFuncPart->SetParameters(flowFunc->GetParameter(0), vn[n-1], n);
10802     flowFuncPart->SetLineWidth(1);
10803     flowFuncPart->SetLineStyle(n);
10804     flowFuncPart->Draw("SAME");
10805   }
10806   
10807   return hist;
10808 }
10809
10810 void MACHConeAll(const char* fileName)
10811 {
10812   loadlibs();
10813
10814   SetFlowStyle();
10815
10816   c = new TCanvas("c", "c", 300, 800);
10817   c->SetTopMargin(0);
10818   c->SetLeftMargin(0);
10819   c->SetRightMargin(0);
10820   c->SetBottomMargin(0);
10821   c->Divide(1, 2, 0, 0);
10822   
10823   Float_t rangesMin[] = { 136.1, 17.45, 18, 2.4 };
10824   Float_t rangesMax[] = { 139.4, 18.95, 23.5, 3.6 };
10825   
10826   for (Int_t i=0; i<2; i++)
10827   {
10828     c->cd(i+1);
10829
10830     gPad->SetRightMargin(0.05);
10831     gPad->SetLeftMargin(0.20);
10832     gPad->SetTopMargin(0.15);
10833     gPad->SetBottomMargin(0.15);
10834
10835     if (i == 0)
10836     {
10837       gPad->SetBottomMargin(0.01);
10838     }
10839     else if (i == 1)
10840     {
10841       gPad->SetTopMargin(0.01);
10842       gPad->SetBottomMargin(0.7);
10843     }
10844   }
10845
10846   Int_t i = 0;
10847
10848   TF1* flowFunc = 0;
10849   
10850   c->cd(i+1);
10851 //   hist = MACHCone(fileName, i, "", kTRUE, 0, &flowFunc);
10852   hist = (TH1*) MACHCone(fileName, i, 0, kFALSE, 0)->Clone("hist");
10853   hist->GetYaxis()->SetRangeUser(rangesMin[i], rangesMax[i]);
10854   hist->GetYaxis()->SetTitleOffset(1.7);
10855   hist->Draw();
10856 //     continue;
10857   
10858   c->cd(i+1);
10859   //c->cd(i+2);
10860 //   hist2 = MACHCone(fileName, i, 0, kFALSE, 11);
10861   hist2 = MACHCone(fileName, i, "SAME", kTRUE, 11, &flowFunc);
10862   //hist2->GetYaxis()->SetRangeUser(rangesMin[i], rangesMax[i]);
10863 //   hist2->Scale(2);
10864   hist2->SetLineColor(4);
10865   //hist2->Draw("SAME");
10866 //    return;
10867
10868   // sample flowFunc with same binning
10869   flowFuncHist = (TH1*) hist->Clone("flowFuncHist");
10870   flowFuncHist->Reset();
10871   
10872   for (Int_t i=1; i<=flowFuncHist->GetNbinsX(); i++)
10873   {
10874     flowFuncHist->SetBinContent(i, flowFunc->Integral(flowFuncHist->GetXaxis()->GetBinLowEdge(i), flowFuncHist->GetXaxis()->GetBinUpEdge(i)));
10875     flowFuncHist->SetBinError(i, 0);
10876   }
10877   
10878   i = 0;
10879   
10880   flowFuncHist->Scale(1.0 / flowFuncHist->GetBinWidth(1));
10881   
10882 //   new TCanvas;
10883 //   flowFuncHist->Draw();
10884 //   flowFunc->Draw("SAME");
10885 //   return;
10886
10887   // residuals
10888   residuals = (TH1*) hist->Clone("res1");
10889   residuals->SetYTitle("Residuals");
10890   residuals->Divide(flowFuncHist);
10891   c->cd(i+2);
10892   residuals->Draw();
10893   residuals->GetYaxis()->SetNdivisions(505);
10894   residuals->GetYaxis()->SetRangeUser(0.995, 1.005);
10895
10896   residuals = (TH1*) hist2->Clone("res2");
10897   residuals->Divide(flowFuncHist);
10898   c->cd(i+2);
10899   residuals->SetLineColor(4);
10900   residuals->Draw("SAME");
10901   
10902   gPad->SetGridy();
10903
10904   if (i == 0)
10905   {
10906     legend = new TLegend(0.43, 0.66, 0.91, 0.82);
10907     legend->SetFillColor(0);
10908     legend->SetTextSize(0.034);
10909     legend->SetTextAlign(22);
10910     
10911     legend->SetHeader("Centrality 0-1%");
10912     legend->AddEntry(hist, "|#eta| < 0.8 & All #Delta#eta", "L");
10913     legend->AddEntry(hist2, "|#eta| < 0.8 & |#Delta#eta| > 0.8 (2x)", "L");
10914     
10915     c->cd(i+1);
10916     legend->Draw();
10917   }
10918   
10919   c->SaveAs(Form("machcone_%d.png", 0));
10920   c->SaveAs(Form("machcone_%d.eps", 0));
10921   c->SaveAs(Form("machcone_%d.C", 0));
10922   
10923   return;
10924   
10925   c->cd(1);
10926   MACHCone(3, "", kTRUE)->SetTitle("");
10927   
10928   c->cd(2);
10929   hist1 = MACHCone(0, "", kFALSE);
10930   hist2 = MACHCone(1, "SAME", kFALSE);
10931   hist3 = MACHCone(2, "SAME", kFALSE);
10932   
10933   hist1->SetTitle("");
10934   hist1->GetYaxis()->SetRangeUser(1, 7);
10935 }
10936   
10937 void SetFlowStyle()
10938 {
10939  // Set style which will affect all plots.
10940  
10941  gStyle->Reset();
10942  // gStyle->SetOptitle(0);
10943  // gStyle->SetOptStat(0);
10944  //gStyle->SetOptDate(1);
10945  // gStyle->SetPalette(8,0);  // (1,0)
10946  gStyle->SetPalette(1);  // (1,0)
10947  gStyle->SetDrawBorder(0);
10948  // gStyle->SetFillColor(0);  // kills palete ???
10949  gStyle->SetCanvasColor(0);
10950  gStyle->SetPadColor(0);
10951  // gStyle->SetFillColor(0); // otherwize it affects Fill colors later
10952  gStyle->SetFrameFillColor(0);
10953  gStyle->SetCanvasBorderMode(0);
10954  gStyle->SetFrameLineWidth(2);
10955  // gStyle->SetFrameFillStyle(4000);
10956  gStyle->SetPadBorderMode(0);
10957  gStyle->SetPadTickX(1);
10958  gStyle->SetPadTickY(1);
10959  gStyle->SetPadBottomMargin(0.15);
10960  gStyle->SetPadLeftMargin(0.15);
10961  gStyle->SetHistLineWidth(2);
10962  gStyle->SetFuncWidth(2);
10963  gStyle->SetLineWidth(2);
10964  gStyle->SetLabelSize(0.05,"xyz");
10965  gStyle->SetLabelOffset(0.01,"y");
10966  gStyle->SetLabelColor(kBlack,"xyz");
10967  gStyle->SetTitleSize(0.06,"xyz");
10968  gStyle->SetTitleOffset(1.3,"y");
10969  gStyle->SetTitleFillColor(0);
10970  gStyle->SetLineWidth(2);  
10971  gStyle->SetHistLineColor(1);
10972  gStyle->SetTextColor(1);
10973  gStyle->SetTitleTextColor(1);
10974  TGaxis::SetMaxDigits(4);
10975  gStyle->SetOptStat(0); // removes stat. box from all histos
10976  gROOT->ForceStyle();
10977
10978 } // end of void SetFlowStyle()
10979
10980 void PlotPtDistributionsSubtracted(const char* fileName1, Int_t centrBegin = 1, Int_t centrEnd = 6, Int_t fit = 0)
10981 {
10982   loadlibs();
10983
10984   Int_t nCentralityBins = 5;
10985   Int_t centralityBins[] = { 1, 7, 9, 11, 13, 16 };
10986   
10987   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName1);
10988     
10989   TCanvas* canvas = new TCanvas("Pt", "Pt", 1000, 1000);
10990   canvas->Divide(2, 2);
10991   
10992   TLegend* legend = new TLegend(0.3, 0.8, 0.99, 0.99);
10993   legend->SetFillColor(0);
10994   
10995   Int_t colors[] = { 1, 2, 4, 6, 3, 5 };
10996   Int_t markers[] = { 20, 21, 22, 23, 24, 25 };
10997   
10998   Double_t ptMin = 10.01;
10999   Double_t ptMax = 39.99;
11000     
11001   TString str;
11002   str.Form("%.1f < p_{T,trig} < %.1f", ptMin - 0.01, ptMax + 0.01);
11003   
11004   canvas->cd(1);
11005   gPad->SetLeftMargin(0.15);
11006   gPad->SetBottomMargin(0.2);
11007   gPad->SetTopMargin(0.01);
11008   gPad->SetRightMargin(0.01);
11009   gPad->SetLogy();
11010   gPad->SetLogx();
11011   gPad->SetGridx();
11012   gPad->SetGridy();
11013   
11014   TH2F* dummy = new TH2F("dummy", "", 100, 1, 40, 100, 1e-5, 1e3);
11015   dummy->SetStats(kFALSE);
11016   dummy->SetXTitle("p_{T,assoc}");
11017   dummy->SetYTitle("1/N_{trig} dN/dp_{T,assoc}");
11018   dummy->GetYaxis()->SetTitleOffset(1);
11019   Prepare1DPlot(dummy);
11020
11021   dummy->GetXaxis()->SetLabelSize(0.05);
11022   dummy->GetYaxis()->SetLabelSize(0.05);
11023   dummy->GetXaxis()->SetTitleSize(0.05);
11024   dummy->GetYaxis()->SetTitleSize(0.05);
11025   dummy->DrawCopy();
11026   
11027   canvas->cd(2);
11028   gPad->SetLeftMargin(0.15);
11029   gPad->SetBottomMargin(0.2);
11030   gPad->SetTopMargin(0.01);
11031   gPad->SetRightMargin(0.01);
11032   gPad->SetLogy();
11033   gPad->SetLogx();
11034   gPad->SetGridx();
11035   gPad->SetGridy();
11036   dummy->DrawCopy();
11037   
11038   canvas->cd(3);
11039   gPad->SetLeftMargin(0.15);
11040   gPad->SetBottomMargin(0.2);
11041   gPad->SetTopMargin(0.01);
11042   gPad->SetRightMargin(0.01);
11043   gPad->SetLogx();
11044   gPad->SetGridx();
11045   gPad->SetGridy();
11046   
11047   dummy = new TH2F("dummy2", "", 100, 1, 40, 100, 0, 100);
11048   dummy->SetStats(kFALSE);
11049   dummy->SetXTitle("p_{T,assoc}");
11050   dummy->SetYTitle("Ratio: Distribution / Inclusive");
11051   dummy->GetYaxis()->SetTitleOffset(1);
11052   Prepare1DPlot(dummy);
11053   dummy->GetXaxis()->SetLabelSize(0.05);
11054   dummy->GetYaxis()->SetLabelSize(0.05);
11055   dummy->GetXaxis()->SetTitleSize(0.05);
11056   dummy->GetYaxis()->SetTitleSize(0.05);
11057   dummy->DrawCopy();
11058   
11059   canvas->cd(4);
11060   gPad->SetLeftMargin(0.15);
11061   gPad->SetBottomMargin(0.2);
11062   gPad->SetTopMargin(0.01);
11063   gPad->SetRightMargin(0.01);
11064   gPad->SetLogx();
11065   gPad->SetGridx();
11066   gPad->SetGridy();
11067   dummy->DrawCopy();
11068   
11069   
11070   // see GetAcceptanceScalingFactor
11071   Float_t scalingFactor = 0.328396; // 0.8
11072   //Float_t scalingFactor = 0.433268; // 0.7
11073   //Float_t scalingFactor = 0.895593; // 0.5 --> 1.6
11074       
11075   Float_t phiRange[] = { 0, TMath::Pi() / 2, TMath::Pi() };
11076   const char* phiLabels[] = { "Towards", "Transverse", "Away" };
11077   
11078   //Float_t phiSizeTowards = TMath::Pi() / 3;
11079   Float_t phiSizeTowards = 0.75;
11080   //Float_t etaLimit = 0.5;
11081   Float_t etaLimit = 0.8;
11082   
11083   towardsCentralEta = h->GetUEHist(2)->GetPtHist(6, 0, ptMin, ptMax, centrBegin, centrEnd, phiRange[0] - phiSizeTowards, phiRange[0] + phiSizeTowards, -etaLimit + 0.01, etaLimit - 0.01);
11084   towardsSideEta1 = h->GetUEHist(2)->GetPtHist(6, 0, ptMin, ptMax, centrBegin, centrEnd, phiRange[0] - phiSizeTowards, phiRange[0] + phiSizeTowards, -1.59, -etaLimit - 0.01);
11085   TH1* towardsSideEta2 = h->GetUEHist(2)->GetPtHist(6, 0, ptMin, ptMax, centrBegin, centrEnd, phiRange[0] - phiSizeTowards, phiRange[0] + phiSizeTowards, etaLimit + 0.01, 1.59);
11086   towardsSideEta1->Add(towardsSideEta2); // TODO can be done smarter? what about the errors?
11087
11088   Prepare1DPlot(towardsSideEta1);
11089   Prepare1DPlot(towardsCentralEta);
11090   
11091   towardsCentralEta->SetLineColor(colors[0]);
11092   towardsSideEta1->SetLineColor(colors[3]);
11093   //towardsSideEta1->SetLineStyle(2);
11094
11095   legend->AddEntry(towardsCentralEta->Clone(), Form("Jet, %s: |#Delta#eta| < 0.8, #phi ~ %.1f", phiLabels[0], phiRange[0]));
11096   legend->AddEntry(towardsSideEta1->Clone(), Form("Ridge, %s: 0.8 < |#Delta#eta| < 1.6, #phi ~ %.1f", phiLabels[0], phiRange[0]));
11097   
11098   // TODO update when data with new phi binning is available
11099   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);
11100   /*
11101   transverse2 = h->GetUEHist(2)->GetPtHist(6, 0, ptMin, ptMax, centrBegin, centrEnd, -0.5 * TMath::Pi(), -TMath::Pi() / 3, -1.59, 1.59, kTRUE);
11102   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);
11103   transverse->Add(transverse2);
11104   transverse->Add(transverse3);
11105   transverse->Scale(1.0 / (2.0 / 3 * TMath::Pi()));
11106   */
11107     
11108   //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);
11109   //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);
11110   //transverseSideEta1->Add(transverseSideEta2); // TODO can be done smarter? what about the errors?
11111   
11112   transverse->SetLineColor(colors[2]);
11113   //transverseSideEta1->SetLineColor(colors[2]);
11114   //transverseSideEta1->SetLineStyle(2);
11115
11116   Prepare1DPlot(transverse);
11117   //Prepare1DPlot(transverseSideEta1);
11118   legend->AddEntry(transverse->Clone(), Form("%s: |#Delta#eta| < 1.6, #phi ~ %.1f", phiLabels[1], phiRange[1]));
11119   //legend->AddEntry(transverseSideEta1->Clone(), Form("%s: 0.8 < |#Delta #eta| < 1.6, #phi ~ %.1f", phiLabels[1], phiRange[1]));
11120   
11121   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);
11122
11123   /*
11124   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);
11125   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);
11126   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);
11127   away3->Add(away4);
11128   */
11129   
11130   away->SetLineColor(colors[1]);
11131   //away3->SetLineColor(colors[1]);
11132   //away3->SetLineStyle(2);
11133   
11134   Prepare1DPlot(away);
11135   legend->AddEntry(away->Clone(), Form("%s: |#Delta#eta| < 1.6, #phi ~ %.1f", phiLabels[2], phiRange[2]));
11136   
11137   //inclusive = h->GetUEHist(2)->GetPtHist(6, 0, ptMin, ptMax, centrBegin, centrEnd, -0.5 * TMath::Pi(), 1.5 * TMath::Pi(), -1.59, 1.59);
11138   
11139   /*
11140   h->GetUEHist(2)->GetEventHist()->GetGrid(6)->GetGrid()->GetAxis(1)->SetRange(centrBegin, centrEnd);
11141   inclusive = h->GetUEHist(2)->GetEventHist()->ShowProjection(0, 6);
11142   h->GetUEHist(2)->GetEventHist()->GetGrid(6)->GetGrid()->GetAxis(1)->SetRange(0, -1);
11143   */
11144   
11145   axis = h->GetUEHist(2)->GetEventHist()->GetGrid(6)->GetGrid()->GetAxis(1);
11146   
11147   inclusiveTmp = h->GetCorrelationpT()->ProjectionY("inclusiveTmp", h->GetCorrelationpT()->GetXaxis()->FindBin(axis->GetBinLowEdge(centrBegin) + 0.01), h->GetCorrelationpT()->GetXaxis()->FindBin(axis->GetBinUpEdge(centrEnd) - 0.01));
11148   
11149   //rebin to match other histograms
11150   //inclusive2 = inclusive->Rebin(away->GetNbinsX(), "inclusive2", away->GetXaxis()->GetXbins()->GetArray());
11151   
11152   // manually, as usual the ROOT function makes a SEGV
11153   inclusive = (TH1*) away->Clone("inclusive");
11154   inclusive->Reset();
11155   inclusive->Sumw2();
11156   for (Int_t bin=1; bin<=inclusiveTmp->GetNbinsX(); bin++)
11157     inclusive->Fill(inclusiveTmp->GetBinCenter(bin), inclusiveTmp->GetBinContent(bin));
11158   
11159   for (Int_t bin=1; bin<=inclusive->GetNbinsX(); bin++)
11160     inclusive->SetBinError(bin, TMath::Sqrt(inclusive->GetBinContent(bin)));
11161     
11162   // normalization: events, phase space
11163   inclusive->Scale(1.0 / h->GetCentralityDistribution()->Integral(centrBegin, centrEnd));
11164   inclusive->Scale(1.0 / (TMath::TwoPi() * 0.8 * 2));
11165   
11166   // bin width
11167   for (Int_t i=1; i<=inclusive->GetNbinsX(); i++)
11168   {
11169     inclusive->SetBinContent(i, inclusive->GetBinContent(i) / inclusive->GetXaxis()->GetBinWidth(i));
11170     inclusive->SetBinError  (i, inclusive->GetBinError(i) / inclusive->GetXaxis()->GetBinWidth(i));
11171   }
11172   
11173   Prepare1DPlot(inclusive);
11174   inclusive->SetLineColor(colors[4]);
11175   legend->AddEntry(inclusive->Clone(), "Inclusive");
11176   
11177   //Prepare1DPlot(away3);
11178   //legend->AddEntry(away3->Clone(), Form("%s: 0.8 < |#Delta #eta| < 1.6, #phi ~ %.1f", phiLabels[2], phiRange[2]));
11179   
11180   // scale for acceptance to match acceptance of towardsCentralEta
11181   towardsSideEta1->Scale(1.0 / scalingFactor); // contains only "side-eta"
11182   transverse->Scale(1.0 / (1.0 + scalingFactor)); // full eta
11183   away->Scale(1.0 / (1.0 + scalingFactor)); // full eta
11184   inclusive->Scale(1.0 / (1.0 + scalingFactor)); // full eta (phi scaling implicit)
11185   
11186   canvas->cd(1);
11187   towardsCentralEtaClone = towardsCentralEta->DrawCopy("SAME");
11188   towardsSideEta1Clone = towardsSideEta1->DrawCopy("SAME");
11189   transverseClone = transverse->DrawCopy("SAME");
11190   //transverseSideEta1->DrawCopy("SAME");
11191   awayClone = away->DrawCopy("SAME");
11192   inclusiveClone = inclusive->DrawCopy("SAME");
11193   //inclusive2->DrawCopy("SAME");
11194   //away3->DrawCopy("SAME");
11195   
11196   canvas->cd(3);
11197   
11198   towardsCentralEtaR = (TH1*) towardsCentralEta->Clone("towardsCentralEtaR");
11199   towardsSideEta1R = (TH1*) towardsSideEta1->Clone("towardsSideEta1R");
11200   transverseR = (TH1*) transverse->Clone("transverseR");
11201   awayR = (TH1*) away->Clone("awayR");
11202   
11203   towardsCentralEtaR->Divide(inclusive);
11204   towardsSideEta1R->Divide(inclusive);
11205   transverseR->Divide(inclusive);
11206   awayR->Divide(inclusive);
11207   
11208   towardsCentralEtaR->DrawCopy("SAME");
11209   towardsSideEta1R->DrawCopy("SAME");
11210   transverseR->DrawCopy("SAME");
11211   awayR->DrawCopy("SAME");
11212   
11213   if (fit == 1)
11214   {
11215     canvas->cd(1);
11216     
11217     awayClone->Fit("expo", "", "SAME", 1.1, 2.9);
11218     awayClone->GetFunction("expo")->SetRange(1, 10);
11219     gPad->SetLogx(0);
11220   }
11221   else if (fit == 2)
11222   {
11223     canvas->cd(1);
11224     
11225     func = new TF1("func", "[0] * x**[1]");
11226     func->SetParameters(1, 1);
11227     
11228     Float_t limitLow = 2.1;
11229     Float_t limitHigh = 4.9;
11230     
11231     func2 = (TF1*) func->Clone();
11232     towardsCentralEtaClone->Fit(func2, "", "SAME", limitLow, limitHigh);
11233     towardsCentralEtaClone->GetFunction("func")->SetRange(1, 10);
11234     towardsCentralEtaClone->GetFunction("func")->SetLineColor(towardsCentralEtaClone->GetLineColor());
11235     
11236     func2 = (TF1*) func->Clone();
11237     towardsSideEta1Clone->Fit(func2, "", "SAME", limitLow, limitHigh);
11238     towardsSideEta1Clone->GetFunction("func")->SetRange(1, 10);
11239     towardsSideEta1Clone->GetFunction("func")->SetLineColor(towardsSideEta1Clone->GetLineColor());
11240   
11241     func2 = (TF1*) func->Clone();
11242     transverseClone->Fit(func2, "", "SAME", limitLow, limitHigh);
11243     transverseClone->GetFunction("func")->SetRange(1, 10);
11244     transverseClone->GetFunction("func")->SetLineColor(transverseClone->GetLineColor());
11245   
11246     func2 = (TF1*) func->Clone();
11247     awayClone->Fit(func2, "", "SAME", limitLow, limitHigh);
11248     awayClone->GetFunction("func")->SetRange(1, 10);
11249     awayClone->GetFunction("func")->SetLineColor(awayClone->GetLineColor());
11250   
11251     func2 = (TF1*) func->Clone();
11252     inclusiveClone->Fit(func2, "", "SAME", limitLow, limitHigh);
11253     inclusiveClone->GetFunction("func")->SetRange(1, 10);
11254     inclusiveClone->GetFunction("func")->SetLineColor(inclusiveClone->GetLineColor());
11255   }
11256   
11257   // subtract transverse part
11258   away->Add(transverse, -1);
11259   //away3->Add(transverseSideEta1, -1);
11260   towardsCentralEta->Add(transverse, -1);
11261   towardsSideEta1->Add(transverse, -1);
11262   //inclusive->Add(transverse, -1);
11263   
11264   canvas->cd(2);
11265   towardsCentralEta->DrawCopy("SAME");
11266   towardsSideEta1->DrawCopy("SAME");
11267   away->DrawCopy("SAME");
11268   inclusive->DrawCopy("SAME");
11269   //away3->DrawCopy("SAME");
11270   
11271   canvas->cd(4);
11272   
11273   towardsCentralEtaR = (TH1*) towardsCentralEta->Clone("towardsCentralEtaR2");
11274   towardsSideEta1R = (TH1*) towardsSideEta1->Clone("towardsSideEta1R2");
11275   awayR = (TH1*) away->Clone("awayR2");
11276   
11277   towardsCentralEtaR->Divide(inclusive);
11278   towardsSideEta1R->Divide(inclusive);
11279   awayR->Divide(inclusive);
11280   
11281   towardsCentralEtaR->DrawCopy("SAME");
11282   towardsSideEta1R->DrawCopy("SAME");
11283   awayR->DrawCopy("SAME");
11284   
11285   if (fit == 1)
11286   {
11287     canvas->cd(2);
11288     
11289     away->Fit("expo", "", "SAME", 1.1, 2.9);
11290     away->GetFunction("expo")->SetRange(1, 10);
11291     gPad->SetLogx(0);
11292   }
11293   else if (fit == 2)
11294   {
11295     canvas->cd(2);
11296     
11297     func = new TF1("func", "[0] * x**[1]");
11298     func->SetParameters(1, 1);
11299     
11300     func2 = (TF1*) func->Clone();
11301     towardsCentralEta->Fit(func2, "", "SAME", limitLow, limitHigh);
11302     func2->SetRange(1, 10);
11303     
11304     func2 = (TF1*) func->Clone();
11305     towardsSideEta1->Fit(func2, "", "SAME", limitLow, limitHigh);
11306     func2->SetRange(1, 10);
11307   
11308     func2 = (TF1*) func->Clone();
11309     away->Fit(func2, "", "SAME", limitLow, limitHigh);
11310     func2->SetRange(1, 10);
11311   
11312     func2 = (TF1*) func->Clone();
11313     inclusive->Fit(func2, "", "SAME", limitLow, limitHigh);
11314     func2->SetRange(1, 10);
11315   }
11316   
11317   for (Int_t i=1; i<=2; i++)
11318   {
11319     canvas->cd(i);
11320     
11321     TString str3;
11322     str3.Form("%d-%d%%", (Int_t) h->GetCentralityDistribution()->GetXaxis()->GetBinLowEdge(centrBegin), (Int_t) h->GetCentralityDistribution()->GetXaxis()->GetBinUpEdge(centrEnd));
11323     latex = new TLatex(0.2, 0.3, str3);
11324     latex->SetNDC();
11325     latex->SetTextSize(0.06);
11326     
11327     latex2 = new TLatex(0.55, 0.6, str);
11328     latex2->SetNDC();
11329     latex2->SetTextSize(0.06);
11330     
11331     latex->Draw();
11332     latex2->Draw();
11333     
11334     legend->Draw();
11335   }
11336 }
11337
11338 void CombineDeltaPhiWithWeighting()
11339 {
11340   // From Hermes:
11341   // For LHC11a2a:
11342   // xsection: 11.879829,  ntrials: 8132994.000000
11343   // 
11344   // For LHC11a2b:
11345   // xsection: 0.623421,  ntrials: 2293420.000000
11346   // 
11347   // For LHC11a2c:
11348   // xsection: 0.043815,  ntrials: 1314525.375000
11349   
11350   // TODO is merging only same event distribution at present
11351   
11352   loadlibs();
11353   
11354   Int_t nInput = 3;
11355   const char* inputList[] = { "mergejob/LHC11a2a_110124.root", "mergejob/LHC11a2b_110131.root", "mergejob/LHC11a2c_110131.root" };
11356   
11357   Float_t xSections[] = { 11.879829 * 1e6 / 8132994, 0.623421 * 1e6 / 2293420, 0.043815 * 1e6 / 1314525 };
11358   xSections[2] /= xSections[0];
11359   xSections[1] /= xSections[0];
11360   xSections[0] /= xSections[0];
11361   
11362   AliUEHistograms* files[3];
11363   TList* finalList = 0;
11364   for (Int_t i=0; i<nInput; i++)
11365   {
11366     files[i] = (AliUEHistograms*) GetUEHistogram(inputList[i], (i == 0) ? &finalList : 0);
11367     if (i > 0) 
11368     {
11369       files[i]->Scale(xSections[i]);
11370       
11371       TList* list2 = new TList;
11372       list2->Add(files[i]);
11373       files[0]->Merge(list2);
11374     }
11375   }
11376   
11377   TFile* file3 = TFile::Open("out.root", "RECREATE");
11378   file3->mkdir("PWG4_PhiCorrelations");
11379   file3->cd("PWG4_PhiCorrelations");
11380   finalList->Write(0, TObject::kSingleKey);
11381   file3->Close();       
11382 }
11383
11384 void NormalizeToBinWidth(TH1* hist)
11385 {
11386   //
11387   // normalizes a 1-d histogram to its bin width
11388   //
11389
11390   if (hist->GetDimension() == 1)
11391   {
11392     for (Int_t i=1; i<=hist->GetNbinsX(); ++i)
11393     {
11394       hist->SetBinContent(i, hist->GetBinContent(i) / hist->GetBinWidth(i));
11395       hist->SetBinError(i, hist->GetBinError(i) / hist->GetBinWidth(i));
11396     }
11397   }
11398   else if (hist->GetDimension() == 2)
11399   {
11400     for (Int_t i=1; i<=hist->GetNbinsX(); ++i)
11401     {
11402       for (Int_t j=1; j<=hist->GetNbinsY(); ++j)
11403       {
11404         hist->SetBinContent(i, j, hist->GetBinContent(i, j) / hist->GetXaxis()->GetBinWidth(i) / hist->GetYaxis()->GetBinWidth(j));
11405         hist->SetBinError(i, j, hist->GetBinError(i) / hist->GetXaxis()->GetBinWidth(i) / hist->GetYaxis()->GetBinWidth(j));
11406       }
11407     }
11408   }
11409 }
11410
11411 void GetAcceptanceScalingFactor(const char* fileName1, Float_t eta1 = 0.8, Float_t eta2 = 1.6)
11412 {
11413   loadlibs();
11414
11415   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName1, 0, kTRUE);
11416   h->SetPtRange(1.01, 39.99);
11417  
11418   new TCanvas;
11419   mixed = ((TH2*)h->GetUEHist(2)->GetUEHist(6, 0, 1.01, 39.99, 0, 16, kTRUE))->ProjectionY();
11420   mixed->DrawCopy();
11421   
11422   Float_t left = mixed->Integral(mixed->FindBin(-eta2 + 0.01), mixed->FindBin(-eta1 - 0.01));
11423   Float_t center = mixed->Integral(mixed->FindBin(-eta1 + 0.01), mixed->FindBin(eta1 - 0.01));
11424   Float_t right = mixed->Integral(mixed->FindBin(eta1 + 0.01), mixed->FindBin(eta2 - 0.01));
11425   
11426   Printf("%f %f %f", left, center, right);
11427   Printf("%f", (left + right) / center);
11428 }
11429
11430 void TrackingEfficiencyCentralityDependence(const char* fileName, Int_t step1 = 2, Int_t step2 = 4)
11431 {
11432   Int_t nCentralityBins = 3;
11433   Float_t centralityBins[] = { 0, 20, 40, 90 };
11434   
11435   Int_t colors[] = { 1, 2, 4, 6 };
11436
11437   loadlibs();
11438
11439   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
11440   
11441   new TCanvas;
11442   dummy = new TH2F("dummy", ";p_{T};tracking efficiency", 100, 0, 20, 100, 0.7, 1.3);
11443   dummy->SetStats(0);
11444   dummy->Draw();
11445   
11446   legend = new TLegend(0.13, 0.67, 0.31, 0.87);
11447   legend->SetTextSize(0.04);
11448   legend->SetFillColor(0);
11449   
11450   for (Int_t i=0; i<nCentralityBins; i++)
11451   {
11452     eventHist = h->GetUEHist(2)->GetEventHist();
11453     
11454     eventHist->GetGrid(step1)->SetRangeUser(1, centralityBins[i] + 0.1, centralityBins[i+1] - 0.1);
11455     eventHist->GetGrid(step2)->SetRangeUser(1, centralityBins[i] + 0.1, centralityBins[i+1] - 0.1);
11456   
11457     TH1* hist1 = eventHist->ShowProjection(0, step1);
11458     TH1* hist2 = eventHist->ShowProjection(0, step2);
11459     
11460     hist2->Divide(hist1);
11461     
11462     hist2->SetLineColor(colors[i]);
11463     hist2->GetYaxis()->SetTitle("tracking efficiency");
11464     hist2->Draw("SAME");
11465     
11466     legend->AddEntry(hist2, Form("%.0f-%.0f%%", centralityBins[i], centralityBins[i+1]));
11467   }
11468   
11469   legend->Draw();
11470 }
11471
11472
11473 TGraphErrors* ReadHepdata(const char* fileName, Bool_t errorsAreAdded = kFALSE, Int_t skipYErrors = 0, Int_t skipXerrors = 1)
11474 {
11475   // expected format: x [x2] y [ye] [ye2] [xe]
11476   //
11477   // skipYErrors:   0 --> ye present
11478   //                1 --> no errors ye
11479   //                2 --> y and ye are lower and upper error, i.e. y' = (y + ye) / 2 and ye = (ye - y) / 2
11480   //                3 --> ye and ye2 are stat and syst error, will be added in quadrature
11481   // 
11482   // skipXerrors:   0 --> xe present
11483   //                1 --> no errors xe
11484   //                2 --> x2 present, xe not present and is calculated from x2 - x
11485   
11486   ifstream fin(fileName);
11487
11488   graph = new TGraphErrors(0);
11489
11490   Double_t sum = 0;
11491
11492   while (fin.good())
11493   {
11494     char buffer[2000];
11495     if (fin.peek() == '#')
11496     {
11497       fin.getline(buffer, 2000);
11498       continue;
11499     }
11500   
11501     Double_t x = -1;
11502     Double_t x2 = -1;
11503     Double_t y = -1;
11504     Double_t ye = 0;
11505     Double_t xe = 0;
11506
11507     fin >> x;
11508     
11509     if (skipXerrors == 2)
11510     {
11511       fin >> x2;
11512       xe = (x2 - x + 1) / 2;
11513       x = x + (x2 - x) / 2;
11514     }
11515     
11516     fin >> y;
11517
11518     if (y == -1)
11519       continue;
11520
11521     if (skipYErrors == 0)
11522     {
11523       ye = -1;
11524       fin >> ye;
11525       if (ye == -1)
11526         continue;
11527     }
11528     else if (skipYErrors == 2)
11529     {
11530       ye = -1;
11531       fin >> ye;
11532       if (ye == -1)
11533         continue;
11534       
11535       Double_t newy = (y + ye) / 2;
11536       ye = (ye - y) / 2;
11537       y = newy;
11538     }
11539     else if (skipYErrors == 3)
11540     {
11541       ye = -1;
11542       fin >> ye;
11543       if (ye == -1)
11544         continue;
11545       
11546       Double_t ye2 = -1;
11547       fin >> ye2;
11548       if (ye2 == -1)
11549         continue;
11550
11551       ye = TMath::Sqrt(ye*ye + ye2*ye2);
11552     }
11553
11554     if (skipXerrors == 0)
11555     {
11556       xe = -1;
11557       fin >> xe;
11558       if (xe == -1)
11559         continue;
11560     }
11561
11562     //Printf("%f %f %f %f", x, y, xe, ye);
11563
11564     if (errorsAreAdded)
11565       ye -= y;
11566
11567     graph->SetPoint(graph->GetN(), x, y);
11568     graph->SetPointError(graph->GetN()-1, xe, ye);
11569
11570     sum += y;
11571     
11572     // read rest until end of line...
11573     fin.getline(buffer, 2000);
11574   }
11575   fin.close();
11576
11577   Printf("%s: %f", fileName, sum);
11578
11579   return graph;
11580 }
11581
11582 void EvaluateParticleEfficiency(const char* fileName)
11583 {
11584   Int_t centralityBegin = 1;
11585   Int_t centralityEnd = 15;
11586   
11587   if (1)
11588   {
11589     Int_t step1 = 4;
11590     Int_t step2 = 5;
11591   }
11592   else
11593   {
11594     Int_t step1 = 2;
11595     Int_t step2 = 4;
11596   }
11597   
11598   Float_t ptTriggerBegin = 4.01;
11599   Float_t ptTriggerEnd = 19.99;
11600   
11601   Bool_t verbose = 1;
11602   
11603   loadlibs();
11604   
11605   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
11606   AliUEHist* cont = h->GetUEHist(2);
11607   
11608   cont->GetEventHist()->GetGrid(step1)->GetGrid()->GetAxis(1)->SetRange(centralityBegin, centralityEnd);
11609   cont->GetEventHist()->GetGrid(step2)->GetGrid()->GetAxis(1)->SetRange(centralityBegin, centralityEnd);
11610   
11611   Int_t stepEff1 = step1 - (Int_t) AliUEHist::kCFStepAnaTopology;
11612   if (stepEff1 == -1)
11613     stepEff1 = 0;
11614   Int_t stepEff2 = step2 - (Int_t) AliUEHist::kCFStepAnaTopology;
11615   if (stepEff2 == -1)
11616     stepEff2 = 0;
11617   
11618   cont->GetTrackHistEfficiency()->GetGrid(stepEff1)->GetGrid()->GetAxis(3)->SetRange(centralityBegin, centralityEnd);
11619   cont->GetTrackHistEfficiency()->GetGrid(stepEff2)->GetGrid()->GetAxis(3)->SetRange(centralityBegin, centralityEnd);
11620   
11621   TH1* triggerParticle = cont->GetEventHist()->Project(step2, 0);
11622   triggerParticle->Divide(cont->GetEventHist()->Project(step1, 0));
11623   
11624   TH1* singleParticle = cont->GetTrackHistEfficiency()->Project(stepEff2, 1);
11625   singleParticle->Divide(cont->GetTrackHistEfficiency()->Project(stepEff1, 1));
11626   
11627   //singleParticle = singleParticle->Rebin(triggerParticle->GetNbinsX(), "singleRebin", triggerParticle->GetXaxis()->GetXbins()->GetArray());
11628   
11629   TGraphErrors* effectiveEffect = new TGraphErrors;
11630   TGraphErrors* triggerCorrelatedEffect = new TGraphErrors;
11631   TGraphErrors* afterBaseLine = new TGraphErrors;
11632   TGraphErrors* triggerCorrelatedEffect2D = new TGraphErrors;
11633   
11634   //TVirtualFitter::SetDefaultFitter("Linear");
11635   
11636   for (Int_t bin=3; bin<=triggerParticle->GetNbinsX(); bin++)
11637   {
11638     if (triggerParticle->GetBinCenter(bin) > 10)
11639       continue;
11640     
11641     cont->SetPtRange(triggerParticle->GetXaxis()->GetBinLowEdge(bin) + 0.01, triggerParticle->GetXaxis()->GetBinUpEdge(bin) - 0.01);
11642       
11643     TH1* hist1 = cont->GetUEHist(step1, 0, ptTriggerBegin, ptTriggerEnd, centralityBegin, centralityEnd);
11644     TH1* hist2 = cont->GetUEHist(step2, 0, ptTriggerBegin, ptTriggerEnd, centralityBegin, centralityEnd);
11645     
11646     // TODO the uncertainties on the ratios should be properly calculated! (if that helps ;))
11647     clone = (TH1*) hist2->Clone("clone");
11648     clone->Divide(hist1);
11649     
11650     //func = new TF1("func", "[0]", -10, 10);
11651     
11652     if ((Int_t) clone->Fit("pol0", "0", "", -10, 10) == 0)
11653     {
11654       func = clone->GetFunction("pol0");
11655       effectiveEffect->SetPoint(effectiveEffect->GetN(), triggerParticle->GetBinCenter(bin) - 0.2, func->GetParameter(0));
11656       effectiveEffect->SetPointError(effectiveEffect->GetN()-1, 0, func->GetParError(0));
11657       
11658       if (verbose)
11659       {
11660         new TCanvas;
11661         clone->GetYaxis()->SetRangeUser(0.9, 1.3);
11662         clone->Draw();
11663         func->DrawClone("SAME");
11664       }
11665     }
11666     
11667     if ((Int_t) clone->Fit("pol0", "0", "", -0.3, 0.3) == 0)
11668     {
11669       func = clone->GetFunction("pol0");
11670       triggerCorrelatedEffect->SetPoint(triggerCorrelatedEffect->GetN(), triggerParticle->GetBinCenter(bin) - 0.1, func->GetParameter(0));
11671       triggerCorrelatedEffect->SetPointError(triggerCorrelatedEffect->GetN()-1, 0, func->GetParError(0));
11672       
11673       if (verbose)
11674       {
11675         func->SetLineColor(2);
11676         func->DrawClone("SAME");
11677       }
11678     }
11679     
11680     if ((Int_t) hist2->Fit("pol0", "0", "", 1, 2) == 0)
11681     {
11682       func = hist2->GetFunction("pol0");
11683       func->SetRange(-10, 10);
11684       hist2->Add(func, -1);
11685     
11686       if ((Int_t) hist1->Fit("pol0", "0", "", 1, 2) == 0)
11687       {
11688         func = hist1->GetFunction("pol0");
11689         func->SetRange(-10, 10);
11690         hist1->Add(func, -1);
11691         
11692         //new TCanvas; hist1->DrawCopy();
11693         
11694         hist2->Divide(hist1);
11695         
11696         if ((Int_t) hist2->Fit("pol0", "0", "", -0.3, 0.3) == 0)
11697         {
11698           func = hist2->GetFunction("pol0");
11699           afterBaseLine->SetPoint(afterBaseLine->GetN(), triggerParticle->GetBinCenter(bin) + 0.2, func->GetParameter(0));
11700           afterBaseLine->SetPointError(afterBaseLine->GetN()-1, 0, func->GetParError(0));
11701         
11702           if (verbose)
11703           {
11704             new TCanvas;
11705             hist2->GetYaxis()->SetRangeUser(0.9, 1.3);
11706             hist2->DrawCopy();
11707             func->SetLineColor(4);
11708             func->DrawClone("SAME");
11709           }
11710         }
11711       }
11712     }
11713       
11714     // 2d
11715     TH2* hist1_2D = cont->GetUEHist(step1, 0, ptTriggerBegin, ptTriggerEnd, centralityBegin, centralityEnd, 1);
11716     TH2* hist2_2D = cont->GetUEHist(step2, 0, ptTriggerBegin, ptTriggerEnd, centralityBegin, centralityEnd, 1);
11717     
11718     //((TH2*)hist1)->Rebin2D(2, 2); ((TH2*)hist2)->Rebin2D(2, 2);
11719     
11720     hist2_2D->Divide(hist1_2D);
11721     
11722     if (verbose)
11723     {
11724       new TCanvas;
11725       hist2_2D->Draw("COLZ");
11726     }
11727     
11728     //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));
11729     
11730     Double_t error;
11731     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);
11732     
11733     integral /= hist2_2D->GetXaxis()->FindBin(0.01) - hist2_2D->GetXaxis()->FindBin(-0.01) + 1;
11734     integral /= hist2_2D->GetYaxis()->FindBin(0.01) - hist2_2D->GetYaxis()->FindBin(-0.01) + 1;
11735     
11736     error /= hist2_2D->GetXaxis()->FindBin(0.01) - hist2_2D->GetXaxis()->FindBin(-0.01) + 1;
11737     error /= hist2_2D->GetYaxis()->FindBin(0.01) - hist2_2D->GetYaxis()->FindBin(-0.01) + 1;
11738     
11739     triggerCorrelatedEffect2D->SetPoint(triggerCorrelatedEffect2D->GetN(), triggerParticle->GetBinCenter(bin) + 0.1, integral);
11740     triggerCorrelatedEffect2D->SetPointError(triggerCorrelatedEffect2D->GetN()-1, 0, error);
11741     
11742     if (verbose)
11743       break;
11744   }
11745   
11746   new TCanvas;
11747   triggerParticle->Draw();
11748   triggerParticle->GetXaxis()->SetRangeUser(0, 9.9);
11749   
11750   singleParticle->SetLineColor(2);
11751   //singleParticle->Draw("SAME");
11752   
11753   effectiveEffect->SetMarkerStyle(24);
11754   effectiveEffect->Draw("PSAME");
11755   
11756   triggerCorrelatedEffect->SetMarkerStyle(25);
11757   triggerCorrelatedEffect->SetMarkerColor(2);
11758   triggerCorrelatedEffect->SetLineColor(2);
11759   triggerCorrelatedEffect->Draw("PSAME");
11760   
11761   triggerCorrelatedEffect2D->SetMarkerStyle(27);
11762   triggerCorrelatedEffect2D->SetMarkerColor(3);
11763   triggerCorrelatedEffect2D->SetLineColor(3);
11764   triggerCorrelatedEffect2D->Draw("PSAME");
11765   
11766   afterBaseLine->SetMarkerStyle(26);
11767   afterBaseLine->SetMarkerColor(4);
11768   afterBaseLine->SetLineColor(4);
11769   afterBaseLine->Draw("PSAME");
11770
11771   legend = new TLegend(0.66, 0.15, 0.88, 0.38);
11772   legend->SetFillColor(0);
11773   legend->SetTextSize(0.04);
11774   legend->AddEntry(triggerParticle, "trigger", "L");
11775   //legend->AddEntry(singleParticle, "single", "L");
11776   legend->AddEntry(effectiveEffect, "effective", "P");
11777   legend->AddEntry(triggerCorrelatedEffect, "at 0", "P");
11778   legend->AddEntry(triggerCorrelatedEffect2D, "at 0 (2d)", "P");
11779   legend->AddEntry(afterBaseLine, "baseline", "P");
11780   legend->Draw();
11781 }
11782
11783 void EvaluateParticleEfficiency2D(const char* fileName)
11784 {
11785   Int_t centralityBegin = 1;
11786   Int_t centralityEnd = 15;
11787   
11788   if (1)
11789   {
11790     Int_t step1 = 4;
11791     Int_t step2 = 5;
11792   }
11793   else
11794   {
11795     Int_t step1 = 2;
11796     Int_t step2 = 4;
11797   }
11798   
11799   Bool_t verbose = 0;
11800   
11801   loadlibs();
11802   
11803   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
11804   AliUEHist* cont = h->GetUEHist(2);
11805   
11806   cont->GetEventHist()->GetGrid(step1)->GetGrid()->GetAxis(1)->SetRange(centralityBegin, centralityEnd);
11807   cont->GetEventHist()->GetGrid(step2)->GetGrid()->GetAxis(1)->SetRange(centralityBegin, centralityEnd);
11808   
11809   Int_t stepEff1 = step1 - (Int_t) AliUEHist::kCFStepAnaTopology;
11810   if (stepEff1 == -1)
11811     stepEff1 = 0;
11812   Int_t stepEff2 = step2 - (Int_t) AliUEHist::kCFStepAnaTopology;
11813   if (stepEff2 == -1)
11814     stepEff2 = 0;
11815   
11816   cont->GetTrackHistEfficiency()->GetGrid(stepEff1)->GetGrid()->GetAxis(3)->SetRange(centralityBegin, centralityEnd);
11817   cont->GetTrackHistEfficiency()->GetGrid(stepEff2)->GetGrid()->GetAxis(3)->SetRange(centralityBegin, centralityEnd);
11818   
11819   TH1* triggerParticle = cont->GetEventHist()->Project(step2, 0);
11820   triggerParticle->Divide(cont->GetEventHist()->Project(step1, 0));
11821   
11822   TH1* singleParticle = cont->GetTrackHistEfficiency()->Project(stepEff2, 1);
11823   singleParticle->Divide(cont->GetTrackHistEfficiency()->Project(stepEff1, 1));
11824   
11825   cont->GetTrackHist(0)->GetGrid(step1)->SetRangeUser(0, -0.01, 0.01); // delta eta
11826   cont->GetTrackHist(0)->GetGrid(step1)->SetRangeUser(4, -0.01, 0.01); // delta phi
11827   TH2* tracksStep1 = (TH2*) cont->GetTrackHist(0)->Project(step1, 1, 2);
11828   
11829   cont->GetTrackHist(0)->GetGrid(step2)->SetRangeUser(0, -0.01, 0.01); // delta eta
11830   cont->GetTrackHist(0)->GetGrid(step2)->SetRangeUser(4, -0.01, 0.01); // delta phi
11831   TH2* tracksStep2 = (TH2*) cont->GetTrackHist(0)->Project(step2, 1, 2);
11832   
11833   tracksStep2->Divide(tracksStep1);
11834   
11835   TH1* triggersStep1 = cont->GetEventHist()->Project(step1, 0);
11836   TH1* triggersStep2 = cont->GetEventHist()->Project(step2, 0);
11837   
11838   for (Int_t x=1; x<=tracksStep2->GetNbinsX(); x++)
11839     for (Int_t y=1; y<=tracksStep2->GetNbinsY(); y++)
11840       if (singleParticle->GetBinContent(x) > 0)
11841         tracksStep2->SetBinContent(x, y, tracksStep2->GetBinContent(x, y) / triggersStep2->GetBinContent(y) * triggersStep1->GetBinContent(y) / singleParticle->GetBinContent(x));
11842       else
11843         tracksStep2->SetBinContent(x, y, 0);
11844   
11845   new TCanvas;
11846   tracksStep2->Draw("COLZ");
11847   
11848   TGraphErrors** triggerCorrelatedEffect2D = new TGraphErrors*[triggerParticle->GetNbinsX()+1];
11849   TGraphErrors** triggerCorrelatedEffect2DSub = new TGraphErrors*[triggerParticle->GetNbinsX()+1];
11850   
11851   for (Int_t bin1=0; bin1<=triggerParticle->GetNbinsX(); bin1++)
11852   {
11853     triggerCorrelatedEffect2D[bin1] = 0;
11854     triggerCorrelatedEffect2DSub[bin1] = 0;
11855   }
11856   
11857   for (Int_t bin1=5; bin1<=triggerParticle->GetNbinsX(); bin1++)
11858   {
11859     if (triggerParticle->GetBinCenter(bin1) > 10)
11860       continue;
11861     
11862     Float_t ptTriggerBegin = triggerParticle->GetXaxis()->GetBinLowEdge(bin1) + 0.01;
11863     Float_t ptTriggerEnd = triggerParticle->GetXaxis()->GetBinUpEdge(bin1) - 0.01;
11864     
11865     for (Int_t bin2=3; bin2<=triggerParticle->GetNbinsX(); bin2++)
11866     {
11867       if (triggerParticle->GetBinCenter(bin2) > 8)
11868         continue;
11869         
11870       if (bin2 > bin1)
11871         continue;
11872     
11873       cont->SetPtRange(triggerParticle->GetXaxis()->GetBinLowEdge(bin2) + 0.01, triggerParticle->GetXaxis()->GetBinUpEdge(bin2) - 0.01);
11874   
11875       // 2d
11876       TH2* hist1_2D = cont->GetUEHist(step1, 0, ptTriggerBegin, ptTriggerEnd, centralityBegin, centralityEnd, 1);
11877       TH2* hist2_2D = cont->GetUEHist(step2, 0, ptTriggerBegin, ptTriggerEnd, centralityBegin, centralityEnd, 1);
11878       
11879       //((TH2*)hist1)->Rebin2D(2, 2); ((TH2*)hist2)->Rebin2D(2, 2);
11880       
11881       hist2_2D->Divide(hist1_2D);
11882       
11883       if (verbose)
11884       {
11885         new TCanvas;
11886         hist2_2D->Draw("COLZ");
11887       }
11888       
11889       //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));
11890       
11891       Double_t error;
11892       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);
11893       
11894       integral /= hist2_2D->GetXaxis()->FindBin(0.01) - hist2_2D->GetXaxis()->FindBin(-0.01) + 1;
11895       integral /= hist2_2D->GetYaxis()->FindBin(0.01) - hist2_2D->GetYaxis()->FindBin(-0.01) + 1;
11896       
11897       error /= hist2_2D->GetXaxis()->FindBin(0.01) - hist2_2D->GetXaxis()->FindBin(-0.01) + 1;
11898       error /= hist2_2D->GetYaxis()->FindBin(0.01) - hist2_2D->GetYaxis()->FindBin(-0.01) + 1;
11899       
11900       if (integral <= 0)
11901         continue;
11902       
11903       if (!triggerCorrelatedEffect2D[bin1])
11904         triggerCorrelatedEffect2D[bin1] = new TGraphErrors;
11905         
11906       triggerCorrelatedEffect2D[bin1]->SetPoint(triggerCorrelatedEffect2D[bin1]->GetN(), triggerParticle->GetBinCenter(bin2) - 0.5 + 0.1 * bin1, integral);
11907       triggerCorrelatedEffect2D[bin1]->SetPointError(triggerCorrelatedEffect2D[bin1]->GetN()-1, 0, error);
11908     
11909       if (!triggerCorrelatedEffect2DSub[bin1])
11910         triggerCorrelatedEffect2DSub[bin1] = new TGraphErrors;
11911         
11912       triggerCorrelatedEffect2DSub[bin1]->SetPoint(triggerCorrelatedEffect2DSub[bin1]->GetN(), triggerParticle->GetBinCenter(bin2) - 0.5 + 0.1 * bin1, integral / triggerParticle->GetBinContent(bin2));
11913       triggerCorrelatedEffect2DSub[bin1]->SetPointError(triggerCorrelatedEffect2DSub[bin1]->GetN()-1, 0, error / triggerParticle->GetBinContent(bin2));
11914       
11915       if (verbose)
11916         break;
11917     }
11918       
11919     if (verbose)
11920       break;
11921   }
11922   
11923   new TCanvas;
11924   triggerParticle->Draw();
11925   triggerParticle->GetXaxis()->SetRangeUser(0, 9.9);
11926   
11927   legend = new TLegend(0.66, 0.15, 0.88, 0.38);
11928   legend->SetFillColor(0);
11929   legend->SetTextSize(0.04);
11930   legend->AddEntry(triggerParticle, "trigger", "L");
11931   
11932   Int_t marker = 20;
11933   Int_t color = 1;
11934   
11935   for (Int_t bin1=3; bin1<=triggerParticle->GetNbinsX(); bin1++)
11936     if (triggerCorrelatedEffect2D[bin1])
11937     {
11938       triggerCorrelatedEffect2D[bin1]->SetMarkerStyle(marker++);
11939       triggerCorrelatedEffect2D[bin1]->SetMarkerColor(color);
11940       triggerCorrelatedEffect2D[bin1]->SetLineColor(color++);
11941       triggerCorrelatedEffect2D[bin1]->Draw("PSAME");
11942       legend->AddEntry(triggerCorrelatedEffect2D[bin1], Form("pt %.2f", triggerParticle->GetBinCenter(bin1)), "P");
11943     }
11944   
11945   legend->Draw();
11946
11947   new TCanvas;
11948   triggerParticle->Draw();
11949   triggerParticle->GetXaxis()->SetRangeUser(0, 9.9);
11950   
11951   marker = 20;
11952   color = 1;
11953   
11954   for (Int_t bin1=3; bin1<=triggerParticle->GetNbinsX(); bin1++)
11955     if (triggerCorrelatedEffect2DSub[bin1])
11956     {
11957       triggerCorrelatedEffect2DSub[bin1]->SetMarkerStyle(marker++);
11958       triggerCorrelatedEffect2DSub[bin1]->SetMarkerColor(color);
11959       triggerCorrelatedEffect2DSub[bin1]->SetLineColor(color++);
11960       triggerCorrelatedEffect2DSub[bin1]->Draw("PSAME");
11961     }
11962   
11963   legend->Draw();
11964 }
11965
11966 void DrawEventCount(const char* fileName, Int_t step = 8)
11967 {
11968   loadlibs();
11969   
11970   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
11971   h->GetEventCount()->Draw("TEXT");
11972   
11973   eventCount = h->GetEventCount();
11974   Float_t events = eventCount->Integral(eventCount->GetXaxis()->FindBin(step), eventCount->GetXaxis()->FindBin(step), eventCount->GetYaxis()->FindBin(0.01 + 1), eventCount->GetYaxis()->FindBin(-0.01 + 10));
11975   Printf("Events: %f", events);
11976 }
11977
11978 void FitDCADistributions(const char* fileName1)
11979 {
11980   loadlibs();
11981   
11982   TFile::Open(fileName1);
11983   list = (TList*) gFile->Get("histosPhiCorrelationsQA");
11984   prim = (TH2*) list->FindObject("fDCAPrimaries");
11985   sec  = (TH2*) list->FindObject("fDCASecondaries");
11986   
11987   Float_t zCut = 0.5;
11988
11989   TH2* histList[] = { prim, sec };
11990
11991   TH1* primProj = 0;
11992   TH1* secProj = 0;
11993   
11994   for (Int_t i=0; i<2; i++)
11995   {
11996     new TCanvas;
11997     gPad->SetGridx();
11998     gPad->SetGridy();
11999     gPad->SetLogy();
12000   
12001 //     hist = histList[i]->ProjectionX("proj", prim->GetYaxis()->FindBin(-zCut), prim->GetYaxis()->FindBin(zCut))->DrawCopy("");
12002     hist = histList[i]->ProjectionY("proj", prim->GetXaxis()->FindBin(-zCut), prim->GetXaxis()->FindBin(zCut))->DrawCopy("");
12003     hist->SetStats(0);
12004     
12005     func = new TF1("func", "gaus(0)+gaus(3)");
12006     func->SetParameters(1e6, 0, 0.02, 1e3, 0, 2);
12007     func->FixParameter(1, 0);
12008     func->FixParameter(4, 0);
12009     func->SetParLimits(2, 0, 0.1);
12010     func->SetParLimits(5, 1, 3);
12011     
12012     hist->Fit(func, "", "", -2, 2);
12013     
12014     func2 = new TF1("func2", "gaus(0)");
12015     func2->SetParameters(1e3, 0, 2);
12016     func2->FixParameter(1, 0);
12017     func2->SetParLimits(2, 0.5, 5);
12018     
12019     hist->Fit(func2, "+", "", -2, -1);
12020     func2->SetRange(-3, 3);
12021     func2->Draw("SAME");
12022
12023 //     break;
12024   }
12025 }
12026
12027 void CompareDCADistributions(const char* fileName1, const char* fileName2)
12028 {
12029   TFile::Open(fileName1);
12030   list = (TList*) gFile->Get("histosPhiCorrelationsQA");
12031   prim = (TH2*) list->FindObject("fDCAPrimaries");
12032   sec  = (TH2*) list->FindObject("fDCASecondaries");
12033   
12034   TFile::Open(fileName2);
12035   list = (TList*) gFile->Get("histosPhiCorrelationsQA");
12036   all = (TH2*) list->FindObject("fDCAPrimaries");
12037   
12038   Float_t zCut = 3.2;
12039   
12040   TH2* histList[] = { prim, sec, all };
12041   
12042   Float_t count = 0;
12043   
12044   TH1* primProj = 0;
12045   TH1* secProj = 0;
12046   
12047   new TCanvas;
12048   gPad->SetGridx();
12049   gPad->SetGridy();
12050   
12051   for (Int_t i=0; i<3; i++)
12052   {
12053     hist = histList[i]->ProjectionX("proj", prim->GetYaxis()->FindBin(-zCut), prim->GetYaxis()->FindBin(zCut))->DrawCopy(i>0?"SAME":"");
12054     hist->SetStats(0);
12055     //hist = histList[i]->ProjectionY("proj", prim->GetXaxis()->FindBin(-zCut), prim->GetXaxis()->FindBin(zCut))->DrawCopy(i>0?"SAME":"");
12056     hist->SetLineColor(i+1);
12057     if (i == 0)
12058       primProj = hist;
12059     if (i == 1)
12060       secProj = hist;
12061     if (i == 2)
12062       hist->Scale(1.0 / hist->Integral(hist->GetXaxis()->FindBin(-0.5), hist->GetXaxis()->FindBin(0.5)) * count);
12063     else
12064       count += hist->Integral(hist->GetXaxis()->FindBin(-0.5), hist->GetXaxis()->FindBin(0.5));
12065   }
12066   
12067   gPad->SetLogy();
12068   
12069   ratio = (TH1*) hist->Clone("ratio");
12070   ratio->Add(primProj, -1);
12071   
12072 /*  for (Int_t i=hist->GetXaxis()->FindBin(-0.1); i<=hist->GetXaxis()->FindBin(0.1); i++)
12073     ratio->SetBinContent(i, 0);*/
12074   
12075   for (Int_t i=1; i<=hist->GetNbinsX(); i++)
12076     ratio->SetBinError(i, 0);
12077   
12078   ratio->SetLineColor(4);
12079   ratio->DrawCopy("SAME E");
12080   
12081   new TCanvas;
12082   gPad->SetGridx();
12083   gPad->SetGridy();
12084   
12085   ratio->Rebin(4);
12086   secProj = (TH1*) secProj->Clone();
12087   secProj->Rebin(4);
12088   
12089   ratio->Divide(secProj);
12090   
12091 /*  for (Int_t i=1; i<=hist->GetNbinsX(); i++)
12092     ratio->SetBinError(i, 0);*/
12093   
12094   ratio->Draw("HIST");
12095   ratio->GetYaxis()->SetRangeUser(0.7, 1.3);
12096   
12097   ratio->Fit("pol0", "0+", "", -5, -1);
12098   ratio->Fit("pol0", "0+", "", 1, 5);
12099 }
12100  
12101 void TrackCuts_CompareParameters(const char* fileName1, const char* fileName2, const char* histName, const char* cutFolder = "cuts_quality_only")
12102 {
12103   // plotWhich: 0 = only before
12104   //            1 = both
12105   //            2 = only after
12106   //
12107   // mirror: kTRUE --> project negative values on the positive side
12108   
12109   Int_t plotWhich = 0;
12110   Bool_t mirror = kFALSE;
12111   
12112   TFile* files[2];
12113   files[0] = TFile::Open(fileName1);
12114   files[1] = TFile::Open(fileName2);
12115
12116   Int_t count = 0;
12117   Int_t colors[] = { 1, 2, 3, 4, 5, 6 };
12118
12119   TLegend* legend = new TLegend(0.7, 0.85, 0.93, 0.98);
12120   legend->SetTextSize(0.04);
12121   legend->SetFillColor(0);
12122
12123   TCanvas* c1 = new TCanvas(histName, histName, 1200, 600);
12124   c1->Divide(2, 1);
12125   //TCanvas* c2 = new TCanvas("c2", "c2", 800, 600);
12126   //TCanvas* c3 = new TCanvas("c3", "c3", 800, 600);
12127
12128   const char* folders2[] = { "before_cuts", "after_cuts" };
12129   const char* names[] = { "MC", "Data" };
12130   Bool_t first = kTRUE;
12131   for (Int_t j = ((plotWhich < 2) ? 0 : 1); j < ((plotWhich > 0) ? 2 : 1); j++)
12132   {
12133     TH1* base = 0;
12134     TH1* base2 = 0;
12135     for (Int_t i = 0; i < 2; i++)
12136     {
12137       Printf("%d %d", j, i);
12138       TString folder;
12139       folder.Form("%s/%s/%s", cutFolder, folders2[j], histName);
12140       TH1* hist = (TH1*) files[i]->Get(folder);
12141       
12142       if (mirror)
12143       {
12144         for (Int_t bin=1; bin<=hist->GetXaxis()->FindBin(-0.0001); bin++)
12145         {
12146           Int_t newBin = hist->GetXaxis()->FindBin(-hist->GetXaxis()->GetBinCenter(bin));
12147           if (bin != newBin)
12148           {
12149             hist->Fill(-hist->GetXaxis()->GetBinCenter(bin), hist->GetBinContent(bin));
12150             hist->SetBinContent(bin, 0);
12151           }
12152         }
12153       }
12154       
12155       legend->AddEntry(hist, Form("%s %s", names[i], (plotWhich == 1) ? folders2[j] : " "));
12156
12157       c1->cd(1);
12158       hist->SetLineColor(colors[count]);
12159       hist->Scale(1.0 / hist->Integral());
12160       hist->SetStats(0);
12161       hist->DrawCopy((count == 0) ? "" : "SAME");
12162
12163       switch (i)
12164       {
12165         case 0: base = hist; break;
12166         case 1: base2 = hist; break;
12167       }
12168
12169       count++;
12170     }
12171     
12172     TH1* ratio = base;
12173     ratio->Divide(base2);
12174
12175     ratio->GetYaxis()->SetRangeUser(0, 2);
12176     
12177     c1->cd(2);
12178     ratio->DrawCopy((first) ? "" : "SAME");
12179     first = kFALSE;
12180   }
12181
12182   c1->cd(1)->SetLogy();
12183   c1->cd(1)->SetGridx();
12184   c1->cd(1)->SetGridy();
12185   legend->Draw();
12186   
12187   c1->cd(2)->SetGridx();
12188   c1->cd(2)->SetGridy();
12189   
12190   c1->SaveAs(Form("%s.png", histName));
12191 }
12192
12193 void PlotQA(const char* fileName, const char* tag = "")
12194 {
12195   loadlibs();
12196   
12197   if (!gGrid && TString(fileName).BeginsWith("alien://"))
12198     TGrid::Connect("alien://");
12199   
12200   TFile::Open(fileName);
12201   
12202   // phys sel
12203   Int_t runNumber = 0;
12204   list = (TList*) gFile->Get("PhysSel");
12205   if (list)
12206   {
12207     physSel = (AliPhysicsSelection*) list->FindObject("AliPhysicsSelection");
12208 //     runNumber = physSel->GetCurrentRun();
12209   }
12210   
12211   TString tmp(fileName);
12212   tmp.ReplaceAll("alien:///alice/cern.ch/user/j/jgrosseo/gridjob/dir_", "");
12213   tmp.ReplaceAll(".root", ".png");
12214   tmp.ReplaceAll("/", "-");
12215   TString title;
12216   title.Form("QA_%d_%s", runNumber, tmp.Data());
12217   c = new TCanvas(title, title, 1200, 800);
12218   c->Divide(3, 3);
12219
12220   // QA task
12221   list = (TList*) gFile->Get("histosPhiCorrelationsQA");
12222   if (list)
12223   {
12224     prim = (TH2*) list->FindObject("fDCAPrimaries");
12225     dcaxy = prim->ProjectionX("dcaxy", prim->GetYaxis()->FindBin(-3.2), prim->GetYaxis()->FindBin(3.2));
12226     dcaz = prim->ProjectionY("dcaz", prim->GetXaxis()->FindBin(-2.4), prim->GetXaxis()->FindBin(2.4));
12227     centrCorr = (TH2*) list->FindObject("fCentralityCorrelation");
12228     
12229     c->cd(1); dcaxy->Draw(); dcaz->SetLineColor(2); dcaz->Draw("SAME");  gPad->SetLogy(); 
12230     c->cd(6); centrCorr->Draw("COLZ"); gPad->SetLogz();
12231   
12232     cuts = (AliESDtrackCuts*) list->FindObject("cuts_quality_dca");
12233     if (cuts)
12234     {
12235       cluster = cuts->GetNClustersTPC(1);
12236       c->cd(3); cluster->Draw();
12237     
12238       ptall = (TH1F*) cuts->GetPtHist(1)->Clone("ptall");
12239       if (ptall->Integral() > 0)
12240         ptall->Scale(1.0 / ptall->Integral());
12241     
12242       c->cd(7); 
12243       ptall->Draw(); 
12244
12245       TH1* ptIts = 0;
12246       check_its = (AliESDtrackCuts*) list->FindObject("check_its");
12247       if (check_its)
12248       {
12249         ptIts = (TH1F*) check_its->GetPtHist(1)->Clone("ptIts");
12250         if (ptIts->Integral() > 0)
12251           ptIts->Scale(1.0 / ptIts->Integral());
12252       }
12253       
12254       TH1* ptItsAcc = 0;
12255       global_cuts = (AliESDtrackCuts*) list->FindObject("global_cuts");
12256       if (global_cuts)
12257       {
12258         ptItsAcc = (TH1*) global_cuts->GetPtHist(1)->Clone("ptItsAcc");
12259         if (ptItsAcc->Integral() > 0)
12260           ptItsAcc->Scale(1.0 / ptItsAcc->Integral());
12261       }
12262     
12263       if (ptIts)
12264       {
12265         ptIts->SetLineColor(2); 
12266         ptIts->Draw("SAME");
12267       }
12268       
12269       if (ptItsAcc)
12270       {
12271         ptItsAcc->SetLineColor(4); 
12272         ptItsAcc->Draw("SAME"); 
12273       }
12274       
12275       gPad->SetLogy();
12276     }
12277   }
12278   
12279   // centrality task
12280   list = (TList*) gFile->Get("CentralityStat");
12281   TH1* centrQuality = 0;
12282   if (list)
12283   {
12284     centrQuality = (TH1*) list->FindObject("fHOutQuality");
12285     
12286     c->cd(4); if (centrQuality) centrQuality->Draw();
12287   }
12288   
12289   // phi corr task
12290   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName, 0, kFALSE, tag);
12291   
12292   if (h->GetUEHist(2)->GetTrackHist(0)->GetGrid(6)->GetGrid()->GetNbins() == 0)
12293   {
12294     Printf("We have %d axes", ((AliTHn*) h->GetUEHist(2)->GetTrackHist(0)->GetNVar()));
12295     
12296 //     ((AliTHn*) h->GetUEHist(2)->GetTrackHist(0))->ReduceAxis();
12297     ((AliTHn*) h->GetUEHist(2)->GetTrackHist(0))->FillParent();
12298     ((AliTHn*) h->GetUEHist(2)->GetTrackHist(0))->DeleteContainers();
12299   }
12300   centr = h->GetCentralityDistribution();
12301   NormalizeToBinWidth(centr);
12302   Int_t events = (Int_t) h->GetEventCount()->ProjectionX()->GetBinContent(3);
12303   Int_t mergeCount = h->GetMergeCount();
12304   
12305   h->SetPtRange(1.01, 3.99);
12306   dphi_corr = h->GetUEHist(2)->GetUEHist(AliUEHist::kCFStepReconstructed, 0, 1.01, 14.99, 1, 8);
12307   if (dphi_corr->GetEntries() == 0)
12308     dphi_corr = h->GetUEHist(2)->GetUEHist(AliUEHist::kCFStepReconstructed+2, 0, 1.01, 14.99, 1, 8);
12309   if (dphi_corr->GetEntries() == 0)
12310     dphi_corr = h->GetUEHist(2)->GetUEHist(AliUEHist::kCFStepAll, 0, 1.01, 14.99, 1, 8);
12311   
12312   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE, tag);
12313   if (hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(6)->GetGrid()->GetNbins() == 0)
12314   {
12315 //     ((AliTHn*) hMixed->GetUEHist(2)->GetTrackHist(0))->ReduceAxis();
12316     ((AliTHn*) hMixed->GetUEHist(2)->GetTrackHist(0))->FillParent();
12317   }
12318
12319   Float_t ptMin = 0.51;
12320   hMixed->SetPtRange(ptMin, 3.99);
12321   dphi_corr_mixed = hMixed->GetUEHist(2)->GetUEHist(AliUEHist::kCFStepReconstructed, 0, ptMin, 14.99, 1, 8);
12322   if (dphi_corr_mixed->GetEntries() == 0)
12323     dphi_corr_mixed = hMixed->GetUEHist(2)->GetUEHist(AliUEHist::kCFStepReconstructed+2, 0, ptMin, 14.99, 1, 8);
12324   if (dphi_corr_mixed->GetEntries() == 0)
12325     dphi_corr_mixed = hMixed->GetUEHist(2)->GetUEHist(AliUEHist::kCFStepAll, 0, ptMin, 14.99, 1, 8);
12326   
12327   if (runNumber != 0 && runNumber != h->GetRunNumber())
12328     AliFatal("Run numbers inconsistent");
12329
12330   Printf("%d", h->GetRunNumber());
12331   if (runNumber == 0)
12332     runNumber = h->GetRunNumber();
12333  
12334   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");
12335   c->cd(5); centr->Draw("HIST");
12336   
12337   c->cd(1);
12338   latex = new TLatex(0.15, 0.8, Form("%d events, %d merged objects", events, mergeCount));
12339   latex->SetTextSize(0.075);
12340   latex->SetNDC();
12341   latex->Draw();
12342   
12343   c->cd(8);
12344   h->GetEventCount()->Draw("TEXT");
12345   
12346   title.Form("QA_%d_%s", runNumber, tmp.Data());
12347   c->SetTitle(title);
12348   
12349   gpTMin = 1.01;
12350   gpTMax = 1.99;
12351   h->SetPtRange(gpTMin, gpTMax);
12352   hMixed->SetPtRange(gpTMin, gpTMax);
12353  
12354   TH2* hist1 = 0;
12355   
12356   //h->GetUEHist(2)->SetSkipScaleMixedEvent(kTRUE);
12357   
12358   if (h->GetUEHist(2)->GetTrackHist(0)->GetNVar() > 5)
12359   {
12360     Int_t step = 8;
12361     
12362     c->cd(3);
12363     GetDistAndFlow(h, 0, &hist1,  0, step, 0, 20, 2.01, 2.99, 1);
12364     hist1->DrawCopy("SURF1");
12365
12366     c->cd(6);
12367     GetDistAndFlow(hMixed, 0, &hist1,  0, step, 0, 20, 2.01, 2.99, 1);
12368     hist1->DrawCopy("SURF1");
12369     
12370     c->cd(9);
12371     GetSumOfRatios(h, hMixed, &hist1, step, 0, 20, 2.01, 2.99, kTRUE); 
12372     if (hist1)
12373       hist1->DrawCopy("SURF1");  
12374   }
12375
12376   c->SaveAs(Form("qa/%s", c->GetTitle()));
12377 }
12378
12379 void GetEventNumber(const char* fileName)
12380 {
12381   loadlibs();
12382   
12383   new TCanvas("c1", "", 800, 600);
12384  
12385   Int_t nEvent = 0;
12386
12387   TFile::Open(fileName);
12388   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
12389   centr = h->GetCentralityDistribution();
12390   nEvent = h->GetCentralityDistribution()->Integral(h->GetCentralityDistribution()->FindBin(0.01), h->GetCentralityDistribution()->FindBin(59.99));
12391
12392   cout << "Number of events: " <<  nEvent << endl;
12393   centr->Draw("HIST");
12394 }
12395 void CompareStepsOnePlot(const char* fileName, Int_t caseId)
12396 {
12397   loadlibs();
12398
12399   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
12400   
12401   Int_t stepList[] = { 0, 1, 2, 4, 5, 6 };
12402   Int_t stepListNames[] = { 0, 1, 2, 3, 4, 5 };
12403   Int_t nSteps = 6;
12404   //const char* names[] = { "All", "PhysSel+Vertex", "Reco Primaries", "Reco "
12405 //   //Int_t stepList[] = { 2, 4, 5, 6 };
12406 //   
12407 //   
12408 //   TH1* hist1 = h->GetUEHist(2)->GetUEHist(0, 0, 6.01, 9.99, 6, 14);
12409 //   TH1* hist2 = h->GetUEHist(2)->GetUEHist(0, 0, 6.01, 7.99, 6, 14);
12410 //   TH1* hist3 = h->GetUEHist(2)->GetUEHist(0, 0, 8.01, 9.99, 6, 14);
12411 //   
12412 //   hist1->Draw();
12413 //   hist2->SetLineColor(2);
12414 //   hist2->Draw("SAME");
12415 //   hist3->SetLineColor(4);
12416 //   hist3->Draw("SAME");
12417 //   return;
12418 //   
12419   
12420   legend = new TLegend(0.65, 0.45, 0.85, 0.85);
12421   legend->SetTextSize(0.04);
12422   legend->SetFillColor(0);
12423   
12424   TH1* histList[10];
12425   
12426   for (Int_t i=0; i<nSteps; i++)
12427   {
12428     //TH1* hist1 = h->GetUEHist(2)->GetEventHist()->Project(stepList[i], 0);
12429     
12430 /*    h->GetUEHist(2)->GetTrackHist(0)->GetGrid(stepList[i])->GetGrid()->GetAxis(1)->SetRangeUser(1.01, 3.99);
12431     h->GetUEHist(2)->GetTrackHist(0)->GetGrid(stepList[i])->GetGrid()->GetAxis(2)->SetRangeUser(4.01, 19.99);
12432     TH1* hist1 = h->GetUEHist(2)->GetTrackHist(0)->Project(stepList[i], 4);*/
12433     
12434     if (caseId == 0)
12435       TH1* hist1 = h->GetUEHist(2)->GetUEHist(stepList[i], 0, 1.01, 19.99);
12436     else if (caseId == 1)
12437       TH1* hist1 = h->GetUEHist(2)->GetEventHist()->Project(stepList[i], 0);
12438     
12439     //hist1->Rebin(2);
12440     //hist1->Rebin(4);
12441     hist1->SetMarkerStyle(24+i);
12442     hist1->SetTitle("");
12443     hist1->SetStats(0);
12444     hist1->DrawCopy((i==0)?"":"SAME");
12445     hist1->Fit("pol0", "0");
12446     //hist1->Fit("pol0");
12447     histList[i] = hist1;
12448     legend->AddEntry(hist1, Form("Step %d", stepListNames[i]), "P");
12449   }
12450   
12451   legend->Draw();
12452   
12453   new TCanvas;
12454   legend = new TLegend(0.65, 0.45, 0.85, 0.85);
12455   legend->SetTextSize(0.04);
12456   legend->SetFillColor(0);
12457   
12458   for (Int_t i=1; i<nSteps; i++)
12459   {
12460     histList[i]->DrawCopy((i==1)?"":"SAME")->Divide(histList[i-1]);
12461     legend->AddEntry(histList[i], Form("Step %d/%d", stepListNames[i], stepListNames[i-1]), "P");
12462   }
12463   
12464   legend->Draw();
12465   
12466   new TCanvas;
12467   for (Int_t i=0; i<nSteps; i++)
12468   {
12469     hist1 = histList[i];
12470     func = new TF1("func", "[0]", -10, 10);
12471     hist1->Fit(func, "0", "", 1, 2);
12472     hist1->Add(func, -1);
12473     hist1->DrawCopy((i==0)?"":"SAME");
12474   }
12475   
12476   legend->Draw();
12477   
12478   new TCanvas;
12479   for (Int_t i=1; i<nSteps; i++)
12480   {
12481     histList[i]->DrawCopy((i==1)?"":"SAME")->Divide(histList[i-1]);
12482   }
12483   
12484   legend->Draw();
12485 }
12486
12487 void PtShift(const char* fileName)
12488 {
12489   loadlibs();
12490
12491   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
12492   
12493   new TCanvas;
12494   gPad->SetLogy();
12495   
12496   ptHist3 = h->GetCorrelationpT()->ProjectionY();
12497   ptHist3->GetXaxis()->SetRangeUser(0, 20);
12498   //ptHist3->Sumw2();
12499   
12500   /*
12501   func = new TF1("func", "[0]+[1]*x**[2]", 4, 20);
12502   func->SetParLimits(2, -10, -1);
12503   func->SetParameters(0, 1, -4);
12504   ptHist3->Fit(func, "", "", 4, 20);
12505   
12506   return;
12507   */
12508   
12509   ptHist3Shifted = (TH1*) ptHist3->Clone("ptHist3Shifted");
12510   for (Int_t i=1; i<ptHist3Shifted->GetNbinsX(); i++)
12511     //ptHist3Shifted->SetBinContent(i, ptHist3Shifted->GetBinContent(i+3));
12512     ptHist3Shifted->SetBinContent(i, ptHist3Shifted->GetBinContent(1.1*i));
12513   
12514   // 10% or 750 MeV
12515     
12516   ptHist3Shifted->SetLineColor(2);
12517   
12518   ptHist3->Rebin(2);
12519   ptHist3Shifted->Rebin(2);
12520   
12521   ptHist3->DrawCopy();
12522   ptHist3Shifted->DrawCopy("SAME");
12523   
12524   new TCanvas;
12525   ptHist3->Divide(ptHist3Shifted);
12526   ptHist3->Draw();
12527   
12528   //ptHist3->Rebin(2); ptHist3->Scale(1.0 / 2);
12529   
12530   gPad->SetGridx();
12531   gPad->SetGridy();
12532 }
12533
12534 void RAA(const char* fileName, const char* fileName2)
12535 {
12536   loadlibs();
12537   
12538   TH1* hist[2];
12539   
12540   for (Int_t j=0; j<2; j++)
12541   {
12542     if (j == 0)
12543       AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
12544     else
12545     {
12546       if (!fileName2)
12547         break;
12548         
12549       AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName2);
12550     }
12551   
12552     ptHist3 = h->GetCorrelationpT()->ProjectionY(Form("proj1_%d", j), 1, 5);
12553     ptHist3->GetXaxis()->SetRangeUser(0, 20);
12554     
12555     //h->GetCentralityDistribution()->Draw(); new TCanvas;
12556     
12557     Int_t nEvents = h->GetCentralityDistribution()->Integral(h->GetCentralityDistribution()->FindBin(0.01), h->GetCentralityDistribution()->FindBin(4.99));
12558     Printf("%d", nEvents);
12559     ptHist3->Scale(1.0 / 1.6 / TMath::TwoPi() / nEvents / ptHist3->GetBinWidth(1));
12560     
12561     hist[j] = ptHist3;
12562   }
12563   
12564   new TCanvas;
12565   hist[0]->DrawCopy("");
12566   hist[1]->DrawCopy("SAME")->SetLineColor(2);
12567   gPad->SetLogy();
12568   
12569   new TCanvas;
12570   hist[1]->Divide(hist[0]);
12571   hist[1]->DrawCopy();
12572   
12573   raa_central = ReadHepdata("raa_alice_central.txt", kFALSE, 3);
12574   raa_central->SetMarkerStyle(20);
12575   raa_central->Draw("PSAME");
12576 }
12577
12578 void PtComparison(const char* fileName, const char* fileName2 = 0)
12579 {
12580   loadlibs();
12581
12582   c = new TCanvas;
12583   c2 = new TCanvas;
12584     
12585   for (Int_t j=0; j<2; j++)
12586   {
12587     if (j == 0)
12588       AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
12589     else
12590     {
12591       if (!fileName2)
12592         break;
12593         
12594       AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName2);
12595     }
12596     
12597     //new TCanvas; h->GetCorrelationpT()->Draw("COLZ");
12598     
12599     ptHist3 = h->GetCorrelationpT()->ProjectionY(Form("proj1_%d", j), 1, 5);
12600     ptHist3->GetXaxis()->SetRangeUser(0, 20);
12601     
12602     //h->GetCentralityDistribution()->Draw(); new TCanvas;
12603     
12604     Int_t nEvents = h->GetCentralityDistribution()->Integral(h->GetCentralityDistribution()->FindBin(0.01), h->GetCentralityDistribution()->FindBin(4.99));
12605     Printf("%d", nEvents);
12606     ptHist3->Scale(1.0 / 1.6 / TMath::TwoPi() / nEvents / ptHist3->GetBinWidth(1));
12607     
12608     //ptHist3->Scale(1690);
12609     //ptHist3->Scale(1.0 / ptHist3->Integral(ptHist3->GetXaxis()->FindBin(1.01), ptHist3->GetNbinsX()) / 3 / 0.6);
12610     
12611     for (Int_t i=2; i<ptHist3->GetNbinsX(); i++)
12612       ptHist3->SetBinContent(i, ptHist3->GetBinContent(i) / ptHist3->GetBinCenter(i));
12613       //ptHist3->SetBinContent(i, ptHist3->GetBinContent(i) / ptHist3->GetBinLowEdge(i));
12614     
12615     //AliPWG0Helper::NormalizeToBinWidth(ptHist3);
12616     
12617     c->cd();
12618     ptHist3->SetLineStyle(j+1);
12619     ptHist3->DrawCopy((j == 0) ? "HIST" : "HISTSAME")->SetLineColor(1);
12620
12621     centralPt = (TH1*) ptHist3->Clone();;
12622   
12623     if (1)
12624     {
12625       ptHist3 = h->GetCorrelationpT()->ProjectionY(Form("proj2_%d", j), 71, 80);
12626       ptHist3->GetXaxis()->SetRangeUser(0, 20);
12627     
12628       Int_t nEvents = h->GetCentralityDistribution()->Integral(h->GetCentralityDistribution()->FindBin(70.01), h->GetCentralityDistribution()->FindBin(79.99));
12629       ptHist3->Scale(1.0 / 1.6 / TMath::TwoPi() / nEvents / ptHist3->GetBinWidth(1));
12630       //ptHist3->Scale(10.0 / ptHist3->Integral(ptHist3->GetXaxis()->FindBin(1.01), ptHist3->GetNbinsX()) / 3 / 0.6);
12631       Printf("%d", nEvents);
12632     
12633       for (Int_t i=2; i<ptHist3->GetNbinsX(); i++)
12634         ptHist3->SetBinContent(i, ptHist3->GetBinContent(i) / ptHist3->GetBinCenter(i));
12635         //ptHist3->SetBinContent(i, ptHist3->GetBinContent(i) / ptHist3->GetBinLowEdge(i));
12636     }
12637     
12638     ptHist3->SetLineStyle(j+1);
12639     ptHist3->DrawCopy("HISTSAME")->SetLineColor(2);
12640     
12641     dndpt_central = ReadHepdata("raa_dndpt_central.txt", kFALSE, 3);
12642     dndpt_peripheral = ReadHepdata("raa_dndpt_peripheral.txt", kFALSE, 3);
12643   
12644 //   RemovePointsBelowX(dndpt_central, 1);
12645 //   RemovePointsBelowX(dndpt_peripheral, 1);
12646 //   
12647 //   NormalizeTo(dndpt_central, 1);
12648 //   NormalizeTo(dndpt_peripheral, 10);
12649
12650     dndpt_central->Draw("*SAME");
12651     dndpt_peripheral->SetLineColor(2);
12652     dndpt_peripheral->SetMarkerColor(2);
12653     dndpt_peripheral->Draw("*SAME");
12654     
12655     gPad->SetLogy();
12656     
12657     c2->cd();
12658     
12659     for (Int_t i=1; i<ptHist3->GetNbinsX(); i++)
12660       ptHist3->SetBinContent(i, ptHist3->GetBinContent(i) / dndpt_peripheral->Eval(ptHist3->GetBinCenter(i)));
12661   
12662     for (Int_t i=1; i<centralPt->GetNbinsX(); i++)
12663       centralPt->SetBinContent(i, centralPt->GetBinContent(i) / dndpt_central->Eval(centralPt->GetBinCenter(i)));
12664   
12665     ptHist3->Rebin(2); ptHist3->Scale(0.5);
12666     centralPt->Rebin(2); centralPt->Scale(0.5);
12667   
12668     ptHist3->DrawCopy((j == 0) ? "" : "SAME")->SetLineColor(2);
12669     centralPt->DrawCopy("SAME")->SetLineColor(1);
12670   }
12671
12672   return;
12673   
12674   ReadYields("preliminaries/yields_110303.root");
12675   
12676   ptHist3->Scale(100);
12677   
12678   TGraphErrors** tmp = yields[0][1][0];
12679   nearSide = tmp[18];
12680   nearSide->Draw("* SAME");  
12681  
12682   TGraphErrors** tmp = yields[1][1][0];
12683   awaySide = tmp[18];
12684   awaySide->SetLineColor(2);
12685   awaySide->SetMarkerColor(2);
12686   awaySide->Draw("* SAME");  
12687   
12688 }
12689
12690 void style(Int_t styleId = 1)
12691 {
12692   gStyle->SetPalette(1);
12693   gStyle->SetCanvasColor(10);
12694   gStyle->SetHistFillColor(10);
12695   gStyle->SetHistFillStyle(0);
12696   gStyle->SetOptStat(0);
12697   gStyle->SetPadTickX(1);
12698   gStyle->SetPadTickY(1);
12699   gStyle->SetAxisColor(1, "X");
12700   gStyle->SetAxisColor(1, "Y");
12701   gStyle->SetAxisColor(1, "Z");
12702   gStyle->SetLabelColor(1, "X");
12703   gStyle->SetLabelColor(1, "Y");
12704   gStyle->SetLabelColor(1, "Z");
12705   gStyle->SetTickLength(0.03, "X");
12706   gStyle->SetTickLength(0.03, "Y");
12707   gStyle->SetTickLength(0.03, "Z");
12708   gStyle->SetTitleXSize(0.05);
12709   gStyle->SetTitleYSize(0.05);
12710   gStyle->SetNdivisions(506, "X");
12711   gStyle->SetNdivisions(506, "Y");
12712   gStyle->SetNdivisions(506, "Z");
12713   
12714   //gStyle->SetPadGridX(1);
12715   //gStyle->SetPadGridY(1);
12716
12717   //gStyle->SetLabelOffset(0.02, "X");
12718   //gStyle->SetLabelOffset(0.02, "Y");
12719   //gStyle->SetLabelOffset(0.02, "Z");
12720   gStyle->SetLabelSize(0.05, "X");
12721   gStyle->SetLabelSize(0.05, "Y");
12722   gStyle->SetLabelSize(0.05, "Z");
12723
12724   gStyle->SetPadLeftMargin(0.12);
12725   gStyle->SetPadRightMargin(0.02);
12726   gStyle->SetPadBottomMargin(0.13);
12727   gStyle->SetPadTopMargin(0.02);
12728
12729   gStyle->SetMarkerSize(1.4); // CKB
12730
12731   const int iFont = 42; // type * 10 + prec  6: helvetica bold 13: times normal 2: times bold
12732
12733 /*                                                               italic     weigth
12734 *-*        1 : times-medium-i-normal      "Times New Roman"      1           4
12735 *-*        2 : times-bold-r-normal        "Times New Roman"      0           7
12736 *-*        3 : times-bold-i-normal        "Times New Roman"      1           7
12737 *-*        4 : helvetica-medium-r-normal  "Arial"                0           4
12738 *-*        5 : helvetica-medium-o-normal  "Arial"                1           4
12739 *-*        6 : helvetica-bold-r-normal    "Arial"                0           7
12740 *-*        7 : helvetica-bold-o-normal    "Arial"                1           7
12741 *-*        8 : courier-medium-r-normal    "Courier New"          0           4
12742 *-*        9 : courier-medium-o-normal    "Courier New"          1           4
12743 *-*       10 : courier-bold-r-normal      "Courier New"          0           7
12744 *-*       11 : courier-bold-o-normal      "Courier New"          1           7
12745 *-*       12 : symbol-medium-r-normal     "Symbol"               0           6
12746 *-*       13 : times-medium-r-normal      "Times New Roman"      0           4
12747 *-*       14 :                            "Wingdings"            0           4
12748 */
12749
12750   //gStyle->SetTitleXOffset(1); // 1.1
12751   //gStyle->SetTitleYOffset(1); // 1-4
12752
12753   gStyle->SetLabelFont(iFont, "xyz");
12754   gStyle->SetStatFont(iFont);
12755   gStyle->SetTitleFont(iFont, "xyz");
12756   gStyle->SetTextFont(iFont);
12757   
12758   if (styleId == 2)
12759   {
12760     gStyle->SetLabelSize(0.07, "X");
12761     gStyle->SetLabelSize(0.07, "Y");
12762     gStyle->SetLabelSize(0.07, "Z");
12763     gStyle->SetTitleXSize(0.07);
12764     gStyle->SetTitleYSize(0.07);
12765   
12766     gStyle->SetPadLeftMargin(0.26);
12767     gStyle->SetPadRightMargin(0.01);
12768     gStyle->SetPadBottomMargin(0.15);
12769     gStyle->SetPadTopMargin(0.01);
12770   }
12771
12772   //gStyle->SetEndErrorSize(0.0);
12773
12774   gROOT->ForceStyle();
12775
12776 }
12777
12778 void NormalizeTo(TGraphErrors* graph, Float_t normalizeTo)
12779 {
12780         Float_t sum = 0;
12781         for (Int_t i=0; i<graph->GetN(); i++)
12782                 sum += graph->GetY()[i];
12783         
12784         if (normalizeTo > 0 && sum > 0)
12785         {
12786                 sum /= normalizeTo;
12787                 for (Int_t i=0; i<graph->GetN(); i++)
12788                 {
12789                         graph->SetPoint(i, graph->GetX()[i],  graph->GetY()[i] / sum);
12790                         graph->SetPointError(i, graph->GetEX()[i],  graph->GetEY()[i] / sum);
12791                 }
12792         }       
12793 }
12794
12795 void CompareMixedEvent(const char* fileName)
12796 {
12797   loadlibs();
12798   
12799   Float_t leadingPtArr[] = { 6.0, 8.0, 10.0, 15.0, 15.0 };
12800   Float_t assocPtArr[] =     { 0.5, 1.5, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
12801   Int_t leadingPtOffset = 2;
12802   Int_t centralityBins[] = { 0, 0, 1, 6, 9, 16 };
12803
12804   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);  
12805   
12806   Int_t i = 1;
12807   for (Int_t j=2; j<5; j++)
12808   {
12809     gpTMin = assocPtArr[j] + 0.01;
12810     gpTMax = assocPtArr[j+1] - 0.01;
12811     
12812     gpTMin = 3.0;
12813     gpTMax = 6.0;
12814
12815     SetupRanges(hMixed);
12816     
12817     TH2* mixed = hMixed->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, centralityBins[j], centralityBins[j+1]-1, 1);
12818   
12819     // compare deta
12820     
12821     TH1* histMixedproj = mixed->ProjectionY();
12822     histMixedproj->Scale(1.0 / mixed->GetNbinsX());
12823     
12824     for (Int_t x=1; x<=mixed->GetNbinsX(); x++)
12825       for (Int_t y=1; y<=mixed->GetNbinsY(); y++)
12826         mixed->SetBinContent(x, y, histMixedproj->GetBinContent(y));
12827
12828     histMixedproj->Scale(1.0 / (0.5 * (histMixedproj->GetBinContent(histMixedproj->GetXaxis()->FindBin(-0.01)) + histMixedproj->GetBinContent(histMixedproj->GetXaxis()->FindBin(0.01)))));
12829       
12830     histMixedproj->DrawCopy((j == 2) ? "" : "SAME")->SetLineColor(j-1);
12831   }
12832 }
12833
12834 void FillParentTHnSparse(const char* fileName, Bool_t reduce = kFALSE, const char* tag = "")
12835 {
12836   TString fileNameStr(fileName);
12837   
12838   if (fileNameStr.BeginsWith("/alice"))
12839   {
12840     fileNameStr = Form("alien://%s", fileNameStr.Data());
12841     if (fileNameStr.EndsWith("merge"))
12842       fileNameStr += "/AnalysisResults.root";
12843   }
12844   
12845   if (fileNameStr.BeginsWith("alien:"))
12846     TGrid::Connect("alien:");
12847   
12848   loadlibs();
12849
12850   TList* list = 0;
12851   
12852   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileNameStr, &list, kFALSE, tag);
12853   Printf("We have %d axes", ((AliTHn*) h->GetUEHist(2)->GetTrackHist(0)->GetNVar()));
12854   
12855   if (reduce)
12856     ((AliTHn*) h->GetUEHist(2)->GetTrackHist(0))->ReduceAxis();
12857   ((AliTHn*) h->GetUEHist(2)->GetTrackHist(0))->FillParent();
12858   ((AliTHn*) h->GetUEHist(2)->GetTrackHist(0))->DeleteContainers();
12859   
12860   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileNameStr, 0, kTRUE, tag);
12861   if (reduce)
12862     ((AliTHn*) hMixed->GetUEHist(2)->GetTrackHist(0))->ReduceAxis();
12863   ((AliTHn*) hMixed->GetUEHist(2)->GetTrackHist(0))->FillParent();
12864   ((AliTHn*) hMixed->GetUEHist(2)->GetTrackHist(0))->DeleteContainers();
12865   
12866   TString newFileName(fileNameStr);
12867
12868   if (fileNameStr.BeginsWith("alien:"))
12869     newFileName = gSystem->BaseName(newFileName);
12870   
12871   newFileName.ReplaceAll(".root", "");
12872   if (reduce)
12873     newFileName += "_.root";
12874   else
12875     newFileName += "_zvtx.root";
12876
12877   file3 = TFile::Open(newFileName, "RECREATE");
12878   file3->mkdir("PWG4_PhiCorrelations");
12879   file3->cd("PWG4_PhiCorrelations");
12880   list->Write("histosPhiCorrelations", TObject::kSingleKey);
12881   file3->Close();
12882 }
12883
12884 void CompareZVertex(const char* fileName)
12885 {
12886   loadlibs();
12887   
12888   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
12889   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);  
12890   
12891   axis = h->GetUEHist(2)->GetEventHist()->GetAxis(2, 6);
12892   
12893   gpTMin = 2.01;
12894   gpTMax = 7.99;
12895   
12896   SetupRanges(h);
12897   SetupRanges(hMixed);
12898   
12899   TFile::Open("test.root", "RECREATE");
12900         
12901   for (Int_t i=0; i<=axis->GetNbins(); i++)
12902   {
12903     TH1* hist = 0;
12904     if (i > 0)
12905     {
12906       Printf("%d %f %f", i, axis->GetBinLowEdge(i) + 0.01, axis->GetBinUpEdge(i) - 0.01);
12907       h->SetZVtxRange(axis->GetBinLowEdge(i) + 0.01, axis->GetBinUpEdge(i) - 0.01);
12908       hMixed->SetZVtxRange(axis->GetBinLowEdge(i) + 0.01, axis->GetBinUpEdge(i) - 0.01);
12909     }
12910       
12911     GetDistAndFlow(h, hMixed, &hist, 0, 6, 0, 10, 2.01, 14.99, 1, kTRUE, 0, kFALSE);
12912     
12913     new TCanvas;
12914     hist->DrawCopy("SURF1");
12915     
12916     hist->Write(Form("detadphi_%d", i));
12917     
12918 //     if (i == 0)   break;
12919
12920     continue;
12921     
12922     hist->SetLineColor(i+1);
12923     hist->Scale(1.0 / hist->Integral() / hist->GetBinWidth(1));
12924     hist->Draw((i == 0) ? "" : "SAME");
12925   }
12926   
12927   gFile->Close();
12928 }
12929
12930 void DrawZRanges(Float_t min, Float_t max)
12931 {
12932   legend = new TLegend(0.5, 0.5, 0.8, 0.8);
12933   
12934   TFile::Open("test.root");
12935   
12936   for (Int_t i=0; i<8; i++)
12937   {
12938     if (i == 1 || i == 7)
12939       continue;
12940     
12941     hist = (TH2*) gFile->Get(Form("detadphi_%d", i));
12942     hist->Rebin2D(2, 2);
12943     hist->Scale(0.25);
12944     
12945     proj = hist->ProjectionY("proj", hist->GetXaxis()->FindBin(min), hist->GetXaxis()->FindBin(max));
12946     proj->Scale(1.0 / (hist->GetXaxis()->FindBin(max) - hist->GetXaxis()->FindBin(min) + 1));
12947     
12948     proj->SetLineColor(i+1);
12949     proj->DrawCopy((i == 0) ? "" : "SAME HIST");
12950     
12951     legend->AddEntry(proj->Clone(), Form("%d", i));
12952   }
12953   
12954   legend->Draw();
12955 }
12956
12957 void PlotTrackingEfficiency(const char* fileName)
12958 {
12959   loadlibs();
12960   
12961   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
12962   
12963   c = new TCanvas("c", "c", 600, 600);
12964   gPad->SetLeftMargin(0.15);
12965
12966   h->SetEtaRange(-0.89, 0.89);
12967   
12968   Float_t centralityBins[] = { 0, 10, 20, 40, 60, 100 };
12969   Int_t nCentralityBins = 5;
12970   
12971   legend = new TLegend(0.2, 0.15, 0.46, 0.42);
12972   legend->SetFillColor(0);
12973   
12974   Int_t colors[] = { 1, 2, 3, 4, 6 };
12975
12976   for (Int_t i=0; i<nCentralityBins; i++)
12977   {
12978     h->GetUEHist(2)->SetCentralityRange(centralityBins[i] + 0.1, centralityBins[i+1] - 0.1);
12979     proj = h->GetUEHist(2)->GetTrackingEfficiency(1);
12980     proj->GetYaxis()->SetRangeUser(0.7, 0.9);
12981     proj->GetXaxis()->SetRangeUser(0.5, 9.9);
12982     proj->GetYaxis()->SetTitleOffset(1.5);
12983     proj->SetTitle("");
12984     proj->GetYaxis()->SetTitle("Tracking efficiency");
12985     proj->SetMarkerColor(colors[i]);
12986     proj->SetLineColor(colors[i]);
12987     proj->SetStats(0);
12988     projClone = proj->DrawClone((i == 0) ? "" : "SAME");
12989     
12990     legend->AddEntry(projClone, Form("%.0f-%.0f%%", centralityBins[i], centralityBins[i+1]));
12991   }
12992   
12993   legend->Draw();  
12994 //   DrawLatex(0.58, 0.85, 1, "HIJING Pb-Pb 2.76 TeV", 0.03);
12995 //   DrawLatex(0.58, 0.81, 1, "|#eta| < 0.9", 0.03);
12996 //   
12997 //   DrawALICELogo(kFALSE, 0.7, 0.2, 0.9, 0.4);
12998   
12999   c->SaveAs("correction_tracking.eps");
13000   
13001   c = new TCanvas("c2", "c2", 600, 600);
13002   gPad->SetLeftMargin(0.15);
13003   
13004   proj = (TH1D*) h->GetUEHist(2)->GetTrackEfficiency(AliUEHist::kCFStepTracked, AliUEHist::kCFStepTrackedOnlyPrim, 1);
13005   proj->GetYaxis()->SetRangeUser(0.8, 1.0);
13006   proj->GetXaxis()->SetRangeUser(0.5, 9.9);
13007   proj->GetYaxis()->SetTitleOffset(1.5);
13008   proj->SetTitle("");
13009   proj->GetYaxis()->SetTitle("contamination correction");
13010   proj->SetStats(0);
13011   projClone = proj->DrawClone("");
13012
13013 //   DrawLatex(0.58, 0.85, 1, "HIJING Pb-Pb 2.76 TeV", 0.03);
13014 //   DrawLatex(0.58, 0.81, 1, "|#eta| < 0.9", 0.03);
13015 //   DrawALICELogo(kFALSE, 0.7, 0.2, 0.9, 0.4);
13016
13017   c->SaveAs("correction_contamination.eps");
13018   
13019   c = new TCanvas("c3", "c3", 600, 600);
13020   gPad->SetLeftMargin(0.15);
13021   
13022   proj = (TH1D*) h->GetUEHist(2)->GetTrackEfficiency(AliUEHist::kCFStepTrackedOnlyPrim, AliUEHist::kCFStepTracked, 1);
13023   proj->GetYaxis()->SetRangeUser(0.95, 1.15);
13024   proj->GetXaxis()->SetRangeUser(0.5, 9.9);
13025   proj->GetYaxis()->SetTitleOffset(1.5);
13026   proj->SetTitle("");
13027   proj->GetYaxis()->SetTitle("contamination");
13028   proj->SetStats(0);
13029   projClone = proj->DrawClone("");
13030
13031 //   DrawLatex(0.58, 0.85, 1, "HIJING Pb-Pb 2.76 TeV", 0.03);
13032 //   DrawLatex(0.58, 0.81, 1, "|#eta| < 0.9", 0.03);
13033 //   DrawALICELogo(kFALSE, 0.7, 0.2, 0.9, 0.4);
13034
13035   c->SaveAs("contamination.eps");  
13036 }
13037
13038 void PlotCorrections(const char* fileName, const char* tag = "")
13039 {
13040   loadlibs();
13041   
13042   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName, 0, kFALSE, tag);
13043   
13044   c = new TCanvas("c", "c", 1200, 800);
13045   c->Divide(3, 3);
13046
13047   c2 = new TCanvas("c2", "c2", 800, 900);
13048   c2->Divide(2, 3);
13049
13050   h->SetEtaRange(-0.89, 0.89);
13051 //   h->SetEtaRange(-1.19, 1.19);
13052   
13053   Float_t centrBins[] = { 0, 20, 40, 60, 100.1 };
13054   
13055   for (Int_t i=0; i<4; i++)
13056   {
13057     h->GetUEHist(2)->SetCentralityRange(centrBins[i] + 0.1, centrBins[i+1] - 0.1);
13058     c->cd(i+1);
13059     h->GetUEHist(2)->GetTrackingEfficiency()->DrawClone("COLZ");
13060     
13061     c2->cd(1);
13062     proj = h->GetUEHist(2)->GetTrackingEfficiency(1);
13063     proj->SetTitle(""); proj->SetStats(0);
13064     proj->GetYaxis()->SetTitle("tracking efficiency");
13065     proj->SetLineColor(i+1);
13066     proj->DrawClone((i == 0) ? "" : "SAME");
13067     
13068     c2->cd(2);
13069     proj = h->GetUEHist(2)->GetTrackingEfficiency(0);
13070     proj->GetYaxis()->SetTitle("tracking efficiency");
13071     proj->SetTitle(""); proj->SetStats(0);
13072     proj->GetXaxis()->SetTitle("#eta");
13073     proj->SetLineColor(i+1);
13074     proj->DrawClone((i == 0) ? "" : "SAME");
13075
13076     c2->cd(3);
13077     proj = h->GetUEHist(2)->GetTrackingContamination(1);
13078     proj->GetYaxis()->SetTitle("contamination correction");
13079     proj->SetTitle(""); proj->SetStats(0);
13080     proj->SetLineColor(i+1);
13081     proj->DrawClone((i == 0) ? "" : "SAME");
13082 //     return;
13083   }
13084
13085   h->GetUEHist(2)->SetCentralityRange(0, -1);
13086   for (Int_t i=0; i<10; i++)
13087   {
13088     c2->cd(4);
13089     h->SetZVtxRange(-10.0 + 2 * i, -8.0 + 2 * i);
13090     proj = h->GetUEHist(2)->GetTrackingEfficiency(0);
13091     proj->GetYaxis()->SetTitle("tracking efficiency");
13092     proj->SetTitle(""); proj->SetStats(0);
13093     proj->GetXaxis()->SetTitle("#eta");
13094     proj->SetLineColor(i+1);
13095     proj->DrawClone((i == 0) ? "" : "SAME");
13096   }
13097   
13098   h->SetZVtxRange(0, -1);
13099
13100   for (Int_t i=0; i<4; i++)
13101   {
13102     c2->cd(5);
13103     h->SetPartSpecies(i);
13104     proj = h->GetUEHist(2)->GetTrackingEfficiency(1);
13105     proj->GetYaxis()->SetTitle("tracking efficiency");
13106     proj->SetTitle(""); proj->SetStats(0);
13107 //     proj->GetXaxis()->SetTitle("#eta");
13108     proj->SetLineColor(i+1);
13109     proj->DrawClone((i == 0) ? "" : "SAME");
13110   }
13111   
13112   return;
13113   
13114 /*  c->cd(9);
13115   h->GetUEHist(2)->GetTrackingContamination()->Draw("COLZ");*/
13116   
13117   proj2 = h->GetUEHist(2)->GetTrackingEfficiency(1);
13118 //   proj2 = h->GetUEHist(2)->GetTrackEfficiency(AliUEHist::kCFStepAnaTopology, (AliUEHist::CFStep) (AliUEHist::kCFStepTrackedOnlyPrim+2), 1);
13119   new TCanvas;
13120   proj2->Draw();
13121   
13122   new TCanvas;
13123   hist = h->GetUEHist(2)->GetCorrelatedContamination();
13124 //   if (hist->GetEntries() > 0)
13125 //     hist->Draw("COLZ");
13126 }
13127
13128 void SaveEfficiencyCorrection(const char* fileName, const char* tag = "", Bool_t condenseCentrality = kTRUE, Bool_t extrapolateHighpT = kFALSE, Int_t partSpecies=-1, Int_t icharge=0, Bool_t ApplyGFCorrection=0, Int_t year=2013)
13129 {
13130   // partSpecies= -1 No PID, 0: Pions, 1: Kaons, 2: Protons
13131   // icharge is needed because GF correction applies only to negative particles, 0:Positive 1:negative
13132   // ApplyGFCorrection, for Geant3 version >= v1.14 this correction is not needed anymore for antiprotons
13133   // the number of TRD modules installed depends on the year
13134   
13135   loadlibs();
13136   
13137   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName, 0, kFALSE, tag);
13138   
13139   if(partSpecies!=-1){
13140     Double_t epsilon=0.001;
13141     h->GetUEHist(2)->GetTrackHistEfficiency()->GetGrid(0)->GetGrid()->GetAxis(2)->SetRangeUser(partSpecies-epsilon,partSpecies+epsilon);
13142     h->GetUEHist(2)->GetTrackHistEfficiency()->GetGrid(4)->GetGrid()->GetAxis(2)->SetRangeUser(partSpecies-epsilon,partSpecies+epsilon);
13143   }
13144   
13145   Int_t dimensions[] = { 0, 1, 3, 4 }; // eta, pT, centrality, vertex
13146   THnBase* generated = h->GetUEHist(2)->GetTrackHistEfficiency()->GetGrid(0)->GetGrid()->ProjectionND(4, dimensions);
13147   THnBase* measured = h->GetUEHist(2)->GetTrackHistEfficiency()->GetGrid((partSpecies==-1)?2:4)->GetGrid()->ProjectionND(4, dimensions); //for ID particle the matched+identified are taken
13148   
13149   //   new TCanvas; measured->Projection(0, 1, 3)->Draw();
13150   
13151   Printf("%f %f", generated->GetEntries(), measured->GetEntries());
13152   
13153   Int_t nBins[] = { generated->GetAxis(0)->GetNbins(), generated->GetAxis(1)->GetNbins(), 1, generated->GetAxis(3)->GetNbins() };
13154   
13155   if (condenseCentrality)
13156   {
13157     Double_t centrAxis[] = { 0, 101 };
13158   }
13159   else
13160   {
13161     Double_t centrAxis[] = { 0, 10, 20, 40, 60, 101 };
13162     nBins[2] = 5;
13163   }
13164   
13165   generated_new = new THnF("generated_new", "", 4, nBins, 0, 0);
13166   
13167   generated_new->SetBinEdges(0, generated->GetAxis(0)->GetXbins()->GetArray()); //eta
13168   generated_new->SetBinEdges(1, generated->GetAxis(1)->GetXbins()->GetArray()); //pT
13169   generated_new->SetBinEdges(2, centrAxis); //centrality
13170   generated_new->SetBinEdges(3, generated->GetAxis(3)->GetXbins()->GetArray()); //vertex
13171   
13172   for (Int_t i=0; i<4; i++)
13173     generated_new->GetAxis(i)->SetTitle(generated->GetAxis(i)->GetTitle());
13174   
13175   measured_new = (THnF*) generated_new->Clone("measured_new");
13176   effCorr = (THnF*) generated_new->Clone("correction");
13177
13178   generated_new->RebinnedAdd(generated);
13179   measured_new->RebinnedAdd(measured);
13180   
13181 //   new TCanvas; measured_new->Projection(0, 1, 3)->Draw();
13182
13183 //   return;
13184   
13185   Printf("%f %f", generated_new->GetEntries(), measured_new->GetEntries());
13186
13187   effCorr->Divide(generated_new, measured_new, 1, 1, "B");
13188 //   effCorr->Divide(measured_new);
13189
13190   if(ApplyGFCorrection && partSpecies!=-1){//define the functions for the GF correction
13191     TF1 *fGFTracking;
13192     TF1 *fGFMatching;
13193     Int_t ntrd=7;
13194     if(year==2011)ntrd=10;
13195     if(year>=2012)ntrd=13;
13196     Printf("Number of TRD module in %d : %d",year,ntrd);
13197     Printf("Applying GF correction for particle specie %d %s",partSpecies,Sign[icharge].Data());
13198     Int_t partSpeciesAliPID=partSpecies+2; //in AliPID 2: Pions 3:Kaons 4:protons
13199     fGFTracking = TrackingEff_geantflukaCorrection(partSpeciesAliPID,(icharge==0)?kPositive:kNegative);
13200     fGFMatching = TOFmatchMC_geantflukaCorrection(partSpeciesAliPID,(icharge==0)?kPositive:kNegative,ntrd);
13201     TCanvas *cGF=new TCanvas("cGF","cGF");
13202     fGFTracking->SetLineColor(1);
13203     fGFTracking->DrawClone();
13204     fGFMatching->DrawClone("same");
13205     gPad->BuildLegend(); 
13206   }
13207   
13208   Double_t maxEffValue=5;
13209   for (Int_t bin0 = 1; bin0<=effCorr->GetAxis(0)->GetNbins(); bin0++)
13210     for (Int_t bin1 = 1; bin1<=effCorr->GetAxis(1)->GetNbins(); bin1++)
13211       for (Int_t bin2 = 1; bin2<=effCorr->GetAxis(2)->GetNbins(); bin2++)
13212         for (Int_t bin3 = 1; bin3<=effCorr->GetAxis(3)->GetNbins(); bin3++)
13213         {
13214           nBins[0] = bin0;
13215           nBins[1] = bin1;
13216           nBins[2] = bin2;
13217           nBins[3] = bin3;
13218           
13219 //        Printf("%d %d %d %d %.2f %.2f %.2f %.2f is %f", bin0, bin1, bin2, bin3, effCorr->GetAxis(0)->GetBinCenter(bin0), effCorr->GetAxis(1)->GetBinCenter(bin1), effCorr->GetAxis(2)->GetBinCenter(bin2), effCorr->GetAxis(3)->GetBinCenter(bin3), effCorr->GetBinContent(nBins));
13220           if(ApplyGFCorrection  && partSpecies!=-1)
13221             {
13222               if(effCorr->GetBinContent(nBins) > 0)
13223                 {
13224                   Double_t pt=effCorr->GetAxis(1)->GetBinCenter(bin1);
13225                   Double_t GFTracking=fGFTracking->Eval(pt);
13226                   Double_t GFMatching=fGFMatching->Eval(pt);
13227                   //printf("pt: %.3f GFCorrectionTracking: %f GFCorrectionMatching: %f",pt,GFTracking,GFMatching);
13228                   //printf(" Eff before: %f",effCorr->GetBinContent(nBins));
13229                   effCorr->SetBinContent(nBins,effCorr->GetBinContent(nBins)*GFTracking*GFMatching);
13230                   //Printf(" Eff after: %f",effCorr->GetBinContent(nBins));
13231                 }
13232             }
13233           
13234           if (effCorr->GetBinContent(nBins) > maxEffValue)
13235           {
13236             Printf("Nulling %d %d %d %d %.2f %.2f %.2f %.2f which was %f", bin0, bin1, bin2, bin3, effCorr->GetAxis(0)->GetBinCenter(bin0), effCorr->GetAxis(1)->GetBinCenter(bin1), effCorr->GetAxis(2)->GetBinCenter(bin2), effCorr->GetAxis(3)->GetBinCenter(bin3), effCorr->GetBinContent(nBins));
13237             effCorr->SetBinContent(nBins, 0);
13238           }
13239         
13240         
13241         }
13242
13243   const Float_t fitRangeBegin = 5.01;
13244   const Float_t fitRangeEnd = 14.99;
13245   const Float_t extendRangeBegin = 8.01;
13246   Bool_t verbose = kTRUE;
13247
13248   if (extrapolateHighpT)
13249   {
13250     Printf("Extrapolating high pT...");
13251     
13252     for (Int_t bin0 = 1; bin0<=effCorr->GetAxis(0)->GetNbins(); bin0++)
13253       for (Int_t bin2 = 1; bin2<=effCorr->GetAxis(2)->GetNbins(); bin2++)
13254         for (Int_t bin3 = 1; bin3<=effCorr->GetAxis(3)->GetNbins(); bin3++)
13255         {
13256           effCorr->GetAxis(0)->SetRange(bin0, bin0);
13257           effCorr->GetAxis(2)->SetRange(bin2, bin2);
13258           effCorr->GetAxis(3)->SetRange(bin3, bin3);
13259           
13260           if (gRandom->Uniform() < 0.02) verbose = kTRUE;
13261           
13262           proj = effCorr->Projection(1);
13263           
13264           if (proj->Integral(proj->FindBin(fitRangeBegin), proj->FindBin(fitRangeEnd)) <= 0)
13265             continue;
13266           
13267 //        Printf("%d %d %d %d %f", bin0, bin1, bin2, bin3, proj->Integral(proj->FindBin(fitRangeBegin), proj->FindBin(fitRangeEnd)));
13268           
13269           if (verbose)
13270           {
13271             new TCanvas; 
13272             proj->Draw();
13273           }
13274           
13275           proj->Fit("pol0", (verbose) ? "+" : "Q0+", "SAME", fitRangeBegin, fitRangeEnd);
13276           
13277           if (!proj->GetFunction("pol0"))
13278             continue;
13279           
13280           Float_t trackingEff = proj->GetFunction("pol0")->GetParameter(0);       
13281           
13282           for (Int_t bin1 = 1; bin1<=effCorr->GetAxis(1)->GetNbins(); bin1++)
13283           {
13284             if (effCorr->GetAxis(1)->GetBinCenter(bin1) < extendRangeBegin)
13285               continue;
13286               
13287             nBins[0] = bin0;
13288             nBins[1] = bin1;
13289             nBins[2] = bin2;
13290             nBins[3] = bin3;
13291             
13292 //          Printf("Setting %d %d %d %d %.2f %.2f %.2f %.2f to %f which was %f", bin0, bin1, bin2, bin3, effCorr->GetAxis(0)->GetBinCenter(bin0), effCorr->GetAxis(1)->GetBinCenter(bin1), effCorr->GetAxis(2)->GetBinCenter(bin2), effCorr->GetAxis(3)->GetBinCenter(bin3), trackingEff, effCorr->GetBinContent(nBins));
13293             effCorr->SetBinContent(nBins, trackingEff);
13294           }
13295           
13296           if (verbose)
13297             verbose = kFALSE;
13298         }
13299
13300     effCorr->GetAxis(0)->UnZoom();
13301     effCorr->GetAxis(1)->UnZoom();
13302     effCorr->GetAxis(2)->UnZoom();
13303     effCorr->GetAxis(3)->UnZoom();
13304   }
13305   
13306   Printf("%f", effCorr->GetEntries());
13307   
13308   TObjString tag2(Form("corrections from file %s with tag %s", fileName, tag));
13309
13310   file = TFile::Open("correction.root", "RECREATE");
13311   effCorr->Write();
13312   tag2.Write();
13313   file->Close();
13314   
13315   new TCanvas;
13316   effCorr->GetAxis(0)->SetRangeUser(-0.49, 0.49);
13317   effCorr->GetAxis(2)->SetRangeUser(65, 65);
13318   effCorr->GetAxis(3)->SetRangeUser(0.01, 0.01);
13319   effCorr->Projection(1)->Draw();
13320 }
13321
13322 void CompareEfficiencyCorrection(const char* fileName1, const char* fileName2, Int_t axis1, Int_t axis2)
13323 {
13324   if (TString(fileName1).BeginsWith("alien") || TString(fileName2).BeginsWith("alien"))
13325     TGrid::Connect("alien:");
13326   
13327   file1 = TFile::Open(fileName1);
13328   corr1 = (THnBase*) file1->Get("correction");
13329   
13330   file2 = TFile::Open(fileName2);
13331   corr2 = (THnBase*) file2->Get("correction");
13332   
13333   corr1->GetAxis(0)->SetRangeUser(-1.19, 1.19);
13334   corr2->GetAxis(0)->SetRangeUser(-1.19, 1.19);
13335   corr1->GetAxis(1)->SetRangeUser(0.51, 3.99);
13336   corr2->GetAxis(1)->SetRangeUser(0.51, 3.99);
13337   corr1->GetAxis(3)->SetRangeUser(0.01, 0.01);
13338   corr2->GetAxis(3)->SetRangeUser(0.01, 0.01);
13339   
13340   proj1 = (TH1*) corr1->Projection(axis1, axis2)->Clone("proj1");
13341   new TCanvas; proj1->DrawCopy("COLZ");
13342
13343   proj2 = (TH1*) corr2->Projection(axis1, axis2)->Clone("proj2");
13344   new TCanvas; proj2->DrawCopy("COLZ");
13345
13346   proj1->Divide(proj2);
13347   new TCanvas; proj1->DrawCopy("COLZ");
13348   
13349   corr1->GetAxis(0)->SetRangeUser(-0.49, 0.49);
13350   corr2->GetAxis(0)->SetRangeUser(-0.49, 0.49);
13351
13352   proj1 = (TH1*) corr1->Projection(axis2)->Clone("proj3");
13353   new TCanvas; proj1->DrawCopy();
13354
13355   proj2 = (TH1*) corr2->Projection(axis2)->Clone("proj4");
13356   proj2->SetLineColor(2);
13357   proj2->DrawCopy("SAME");
13358
13359   proj1->Divide(proj2);
13360   new TCanvas; proj1->DrawCopy();
13361   
13362 }
13363
13364  
13365 void PlotFake(const char* fileName, const char* fileName2 = 0)
13366 {
13367   loadlibs();
13368   
13369   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
13370   if (fileName2) AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(fileName2); 
13371  
13372   TLegend* legend = new TLegend(0.7, 0.8, 0.95, 0.95);
13373   legend->SetFillColor(0);
13374   legend->SetTextSize(0.03);
13375   const char* title[] = {"0-20%", "20-40%", "40-60%", "60-80%", "80-100%"};
13376   TLegend* legend2 = new TLegend(0.7, 0.8, 0.95, 0.95);
13377   legend2->SetFillColor(0);
13378   legend2->SetTextSize(0.03);
13379
13380   c1 = new TCanvas("c1", "Ratio of fakes", 1200, 800);
13381   c1->Divide(2, 3);
13382   c2 = new TCanvas("c2", "pTrec vs pT", 1200, 800);
13383   c2->Divide(2, 3);
13384   c3 = new TCanvas("c3", "pTrec pT ratio", 1200, 800);
13385   c3->Divide(2, 3);
13386
13387   h->SetEtaRange(-0.79, 0.79);
13388   
13389   for (Int_t i=0; i<5; i++)
13390   {
13391 //     h->GetUEHist(2)->SetCentralityRange(100.0/5*i + 0.1, 100.0/5*(i+1) - 0.1);
13392     h->GetUEHist(2)->SetCentralityRange(0, 100);
13393     c1->cd(i+1);
13394     h->GetUEHist(2)->GetFakeRate()->DrawClone("COLZ");
13395     c1->cd(6);
13396     proj = h->GetUEHist(2)->GetFakeRate(1);
13397     proj->GetYaxis()->SetRangeUser(0,150);
13398     proj->SetLineColor((i==4) ? 6 : i+1);
13399     proj->DrawClone((i == 0) ? "" : "SAME");
13400     legend->AddEntry(proj, title[i] , "PL");
13401   }
13402
13403   legend->Draw();
13404
13405   c2->cd(1);
13406   h->GetUEHist(2)->GetMCRecoPtCorrelation()->GetXaxis()->SetTitle("p_{T,rec}");
13407   h->GetUEHist(2)->GetMCRecoPtCorrelation()->GetYaxis()->SetTitle("p_{T}");
13408   h->GetUEHist(2)->GetMCRecoPtCorrelation()->GetZaxis()->SetTitle("Centrality");
13409   h->GetUEHist(2)->GetMCRecoPtCorrelation()->DrawCopy();
13410
13411   Float_t difference = 0.05;
13412
13413   for (Int_t i=0; i<5; i++)
13414   {
13415     c2->cd(i+2);
13416     h->GetUEHist(2)->GetMCRecoPtCorrelation()->GetZaxis()->SetRangeUser(100.0/5*i + 0.1,100.0/5*(i+1) - 0.1);
13417     hist = h->GetUEHist(2)->GetMCRecoPtCorrelation()->Project3D("yx");
13418     hist->DrawClone("COLZ");
13419     c2->cd(i+2)->SetLogz();
13420     c3->cd(i+1);
13421     TH1* MisreconstructedPtRate = h->GetUEHist(2)->GetMCRecoPtCorrelation()->ProjectionX("MisreconstructedPtRate");
13422     MisreconstructedPtRate->Reset();
13423     MisreconstructedPtRate->GetYaxis()->SetRangeUser(0,1);
13424     
13425     for (Int_t x=0; x<=hist->GetNbinsX(); x++) 
13426     {
13427       Float_t ptRec = hist->GetXaxis()->GetBinCenter(x);
13428       Float_t Misreconstructed = 0;
13429       Float_t Reconstructed = 0;
13430       for (Int_t y=0; y<=hist->GetNbinsY(); y++) 
13431       {
13432         Float_t pt = hist->GetYaxis()->GetBinCenter(y);
13433         Reconstructed += hist->GetBinContent(x,y);
13434         if (TMath::Abs(ptRec-pt)/pt > difference)
13435           Misreconstructed += hist->GetBinContent(x,y);
13436       }
13437       if (Reconstructed!=0) MisreconstructedPtRate->Fill(ptRec,Misreconstructed/Reconstructed);
13438     }
13439     MisreconstructedPtRate->SetLineColor((i==4) ? 6 : i+1);
13440     MisreconstructedPtRate->DrawClone();
13441     if (i==0) legend2->AddEntry(MisreconstructedPtRate, "2010" , "L");
13442     c3->cd(6);
13443     MisreconstructedPtRate->DrawClone((i == 0) ? "" : "SAME");
13444     if (fileName2)
13445     {
13446       h2->GetUEHist(2)->GetMCRecoPtCorrelation()->GetZaxis()->SetRangeUser(100.0/5*i + 0.1,100.0/5*(i+1) - 0.1);
13447       hist = h2->GetUEHist(2)->GetMCRecoPtCorrelation()->Project3D("yx"); 
13448       TH1* MisreconstructedPtRate2 = h2->GetUEHist(2)->GetMCRecoPtCorrelation()->ProjectionX("MisreconstructedPtRate2");
13449       MisreconstructedPtRate2->Reset();
13450       MisreconstructedPtRate2->GetYaxis()->SetRangeUser(0,1);
13451       for (Int_t x=0; x<=hist->GetNbinsX(); x++)
13452       {
13453         Float_t ptRec = hist->GetXaxis()->GetBinCenter(x);
13454         Float_t Misreconstructed = 0;
13455         Float_t Reconstructed = 0;
13456         for (Int_t y=0; y<=hist->GetNbinsY(); y++)
13457         {
13458           Float_t pt = hist->GetYaxis()->GetBinCenter(y);
13459           Reconstructed += hist->GetBinContent(x,y);
13460           if (TMath::Abs(ptRec-pt)/pt > difference)
13461             Misreconstructed += hist->GetBinContent(x,y);
13462         }
13463         if (Reconstructed!=0) MisreconstructedPtRate2->Fill(ptRec,Misreconstructed/Reconstructed);
13464       }
13465       c3->cd(i+1);
13466       MisreconstructedPtRate2->SetLineColor((i==2) ? 12 : i+8);
13467       MisreconstructedPtRate2->DrawClone("SAME");
13468       if (i==0) legend2->AddEntry(MisreconstructedPtRate2, "2011" , "L");
13469       legend2->DrawClone();
13470     }
13471   }
13472   c3->cd(6);
13473  legend->Draw();
13474 }
13475
13476 void CompareCorrections(const char* fileName1, const char* fileName2)
13477 {
13478   loadlibs();
13479   
13480   AliUEHistograms* h1 = (AliUEHistograms*) GetUEHistogram(fileName1);
13481   AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(fileName2);
13482   
13483   c = new TCanvas("c", "c", 1200, 800);
13484
13485   TLegend* legend = new TLegend(0.7, 0.8, 0.95, 0.95);
13486   legend->SetFillColor(0);
13487   legend->SetTextSize(0.03);
13488
13489   h1->SetEtaRange(-0.89, 0.89);
13490   h2->SetEtaRange(-0.89, 0.89);  
13491
13492
13493 //  const char* title1[] = {"2010, 0-10%", "2010, 10-20%", "2010, 20-30%", "2010, 30-40%", "2010, 40-50%"};
13494   const char* title1[] = {"FullTPC, 0-10%", "FullTPC, 10-20%", "FullTPC, 20-30%", "FullTPC, 30-40%", "FullTPC, 40-50%"};
13495   const char* title1[] = {"FullTPC, 0-10%", "FullTPC, 10-20%", "FullTPC, 20-30%", "FullTPC, 30-40%", "FullTPC, 40-50%"};
13496 //  const char* title2[] = {"2011, 0-10%", "2011, 10-20%", "2011, 20-30%", "2011, 30-40%", "2011, 40-50%"};
13497   const char* title2[] = {"NotFullTPC, 0-10%", "NotFullTPC, 10-20%", "NotFullTPC, 20-30%", "NotFullTPC, 30-40%", "NotFullTPC, 40-50%"};
13498
13499   Int_t colors[16] =  { 1, 3, 2, 6, 4, 7, 8, 9, 11, 12, 28, 30, 36, 40, 46 };
13500   Int_t markers[16] = { 20, 21, 22, 23, 24, 25, 26, 27, 28, 30, 31, 32, 33, 34, 2, 5};
13501
13502   for (Int_t i=0; i<5; i++)
13503   {
13504     h1->GetUEHist(2)->SetCentralityRange(100.0/10*i + 0.1, 100.0/10*(i+1) - 0.1);
13505     h2->GetUEHist(2)->SetCentralityRange(100.0/10*i + 0.1, 100.0/10*(i+1) - 0.1);
13506     
13507     c->cd(1);
13508     proj = h1->GetUEHist(2)->GetTrackingEfficiency(1);
13509     proj->SetLineColor(colors[6]);
13510     proj->SetMarkerColor(colors[6]);
13511     proj->SetMarkerStyle(markers[i]);
13512     proj->DrawClone((i == 0) ? "" : "SAME");
13513     legend->AddEntry(proj, title1[i] , "PL");
13514
13515     proj = h2->GetUEHist(2)->GetTrackingEfficiency(1);
13516     proj->SetLineColor(colors[2]);
13517     proj->SetMarkerColor(colors[2]);
13518     proj->SetMarkerStyle(markers[i+5]);
13519     proj->SetMarkerStyle(markers[i]);
13520     proj->DrawClone("SAME");
13521     legend->AddEntry(proj, title2[i] , "PL");
13522   }
13523     
13524   legend->Draw();
13525 }
13526
13527 void ComparePPHIMixedEvent(const char* ppFile, const char* pbpbFile)
13528 {
13529   loadlibs();
13530   
13531   AliUEHistograms* hpp = (AliUEHistograms*) GetUEHistogram(ppFile);
13532   AliUEHistograms* hpbpb = (AliUEHistograms*) GetUEHistogram(pbpbFile);
13533   
13534   new TCanvas;
13535   hpp->SetPtRange(2, 10);
13536   ppEff = hpp->GetUEHist(2)->GetTrackingEfficiency(0);
13537   ppEff->Draw();
13538
13539   hpbpb->SetPtRange(2, 10);
13540   pbpbEff = hpbpb->GetUEHist(2)->GetTrackingEfficiency(0);
13541   pbpbEff->DrawCopy("SAME")->SetLineColor(2);
13542   
13543   new TCanvas;
13544   ppEff2 = hpp->GetUEHist(2)->GetTrackingEfficiency(1);
13545   ppEff2->Draw();
13546
13547   pbpbEff2 = hpbpb->GetUEHist(2)->GetTrackingEfficiency(1);
13548   pbpbEff2->DrawCopy("SAME")->SetLineColor(2);
13549
13550   mixed = ComparePPHIMixedEventGetMixed(ppEff);
13551   mixed2 = ComparePPHIMixedEventGetMixed(pbpbEff);
13552   
13553   new TCanvas;
13554   mixed->DrawCopy();
13555   mixed2->DrawCopy("SAME")->SetLineColor(2);
13556   
13557   new TCanvas;
13558   mixed->Divide(mixed2);
13559   mixed->Draw();
13560 }
13561
13562 TH1* ComparePPHIMixedEventGetMixed(TH1* eff)
13563 {
13564   eff->Fit("pol0", "0W");
13565   Float_t avgEff = eff->GetFunction("pol0")->GetParameter(0);
13566
13567   eff->Fit("pol0", "0W", "", -0.89, 0.89);
13568   Float_t avgEffCenter = eff->GetFunction("pol0")->GetParameter(0);
13569   Printf("Avg is %f and avg in center is %f", avgEff, avgEffCenter);
13570          
13571   TH1* mixed = new TH1F("mixed", "", 100, -2, 2);
13572   
13573   Float_t etaLimit = 1.0;
13574   
13575   Int_t n = 10000;
13576   Int_t n2 = 100;
13577   for (Int_t i=0; i<n; i++)
13578   {
13579     Float_t etaTrig = gRandom->Uniform(-etaLimit, etaLimit);
13580     
13581     for (Int_t j=0; j<n2; j++)
13582     {
13583       Float_t etaAssoc = gRandom->Uniform(-etaLimit, etaLimit);
13584       
13585       if (gRandom->Uniform(0, 1) > eff->GetBinContent(eff->FindBin(etaAssoc)))
13586         continue;
13587       
13588       mixed->Fill(etaTrig - etaAssoc);
13589     }
13590   }
13591   
13592 //   mixed->Scale(1.0 / avgEffCenter);
13593   mixed->Scale(1.0 / avgEff);
13594
13595   Printf("We have %f pairs and put in %d", mixed->Integral(), n*n2);    
13596   
13597   return mixed;
13598 }
13599
13600 void MACHConeEvolution(const char* fileName, const char* fileNameMixed = 0)
13601 {
13602   loadlibs();
13603   
13604   if (!fileNameMixed)
13605     fileNameMixed = fileName;
13606   
13607   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
13608   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileNameMixed, 0, kTRUE);
13609     
13610   Float_t leadingPtArr[] = { 2.0, 3.0, 4.0, 10.0, 20.0, 40.0 };
13611   Float_t assocPtArr[] =   { 1.0, 2.0, 3.0, 6.0, 10.0, 20.0, 40.0 };
13612   
13613   Int_t i = 1;
13614   Int_t step = 6;
13615   Int_t j = 0;
13616   
13617   gpTMin = assocPtArr[i] + 0.01;
13618   gpTMax = assocPtArr[i+1] - 0.01;
13619
13620   for (Int_t centrBin = 0; centrBin < 5; centrBin++)
13621   {
13622     Int_t centralityBegin = centrBin;
13623     Int_t centralityEnd = centrBin+1;
13624     
13625     SetupRanges(h);
13626     SetupRanges(hMixed);
13627     
13628     TH1* hist = 0;
13629
13630     Bool_t scaleToPairs = 0;
13631     
13632     GetDistAndFlow(h, hMixed, &hist, 0, step, centralityBegin, centralityEnd, leadingPtArr[j] + 0.01, leadingPtArr[j+1] - 0.01, 11, kTRUE, 0, scaleToPairs); 
13633     hist->Rebin(2); hist->Scale(0.5);
13634
13635     copy = hist->DrawCopy((centrBin == 0) ? "" : "SAME");
13636     copy->SetLineColor(centrBin+1);
13637   }
13638 }
13639     
13640 void PlotTwoTrackEfficiencyControlPlots(const char* fileName)
13641 {
13642   loadlibs();
13643   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
13644   
13645   Float_t ptRange[] = { 0.0, 1.0, 2.0, 3.0, 4.0, 6.0, 8.0, 10.0 };
13646   
13647   graph = new TGraphErrors;
13648   
13649   for (Int_t ptID = 0; ptID < 7; ptID++)
13650   {
13651     c = new TCanvas(Form("c%d", ptID), Form("%.0f < pT < %.0f", ptRange[ptID], ptRange[ptID+1]), 800, 400);
13652     c->Divide(2, 1);
13653   
13654     for (Int_t i=0; i<2; i++)
13655     {
13656       c->cd(i+1);
13657       h->GetTwoTrackDistance(i)->GetZaxis()->SetRangeUser(ptRange[ptID] + 0.01, ptRange[ptID+1] - 0.01);
13658       p = h->GetTwoTrackDistance(i)->Project3D(Form("yx_%d_%d", i, ptID));
13659 //       if (ptID == 0)
13660         p->SetStats(0);
13661       
13662       pc = (TH2*) p->Clone("pc");
13663       pc->Reset();
13664       
13665       p->DrawCopy("COLZ");
13666       
13667       continue;
13668       
13669       // reduce to one quadrant
13670       for (Int_t x=1; x<=p->GetNbinsX(); x++)
13671         for (Int_t y=1; y<=p->GetNbinsY(); y++)
13672           pc->Fill(TMath::Abs(p->GetXaxis()->GetBinCenter(x)), TMath::Abs(p->GetYaxis()->GetBinCenter(y)), p->GetBinContent(x, y));
13673       
13674       c->cd(i+2);
13675       copy = pc->DrawCopy("COLZ");
13676       copy->GetXaxis()->SetRangeUser(0, 10);
13677       copy->GetYaxis()->SetRangeUser(0.00101, 10);
13678       
13679       // extract excess
13680       if (1)
13681       {
13682         Float_t center = pc->Integral(pc->GetXaxis()->FindBin(0), pc->GetXaxis()->FindBin(0.009999), 1, pc->GetNbinsY());
13683         Float_t outside = pc->Integral(pc->GetXaxis()->FindBin(0.01001), pc->GetXaxis()->FindBin(0.04999), 1, pc->GetNbinsY());
13684         
13685         Float_t excess1 = center - outside / 4;
13686
13687         Float_t center = pc->Integral(pc->GetXaxis()->FindBin(0), pc->GetXaxis()->FindBin(0.001999), 1, pc->GetNbinsY());
13688         Float_t outside = pc->Integral(pc->GetXaxis()->FindBin(0.002001), pc->GetXaxis()->FindBin(0.00999), 1, pc->GetNbinsY());
13689
13690         Float_t excess2 = center - outside / 4;
13691
13692         Printf("%d %f %f", ptID, excess1, excess2);
13693       }
13694
13695       // fit
13696       if (0 && i == 0)
13697       {
13698         p2 = ((TH2*)pc)->ProjectionX("p2", 52, 52+4);
13699 //      p3 = ((TH2*)p)->ProjectionX("p3", 49-4, 49);
13700         //p2->Add(p3);
13701         //new TCanvas; p2->Draw();
13702         //return;
13703         p2->Fit("pol0", "0");
13704         Float_t avg = p2->GetFunction("pol0")->GetParameter(0);
13705         p2->Fit("pol0", "0", "", -0.002, 0.002); 
13706         Float_t min = p2->GetFunction("pol0")->GetParameter(0);
13707         Float_t mine = p2->GetFunction("pol0")->GetParError(0);
13708         
13709         if (avg > 0)
13710         {
13711           graph->SetPoint(graph->GetN(), ptRange[ptID], min / avg);
13712           graph->SetPointError(graph->GetN()-1, 0, mine / avg);
13713         }
13714       }
13715       
13716     }
13717     
13718     c->SaveAs(Form("twotrack_pt_%d_%d.png", (Int_t) ptRange[ptID], (Int_t) ptRange[ptID+1]));
13719     c->SaveAs(Form("twotrack_pt_%d_%d.eps", (Int_t) ptRange[ptID], (Int_t) ptRange[ptID+1]));
13720   }
13721   
13722   new TCanvas;
13723   graph->Print();
13724   graph->Draw("A*");
13725 }
13726
13727 void PlotTwoTrackEfficiencyControlPlots2(const char* fileName)
13728 {
13729   loadlibs();
13730   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
13731   
13732   Float_t ptRange[] = { 0.0, 1.0, 2.0, 3.0, 4.0, 6.0, 8.0, 10.0 };
13733   
13734   graph = new TGraphErrors;
13735   
13736   for (Int_t ptID = 0; ptID < 5; ptID++)
13737   {
13738     c = new TCanvas(Form("c%d", ptID), Form("%.0f < pT < %.0f", ptRange[ptID], ptRange[ptID+1]), 1200, 400);
13739     c->Divide(3, 1);
13740   
13741     TH2* proj[2];
13742     
13743     for (Int_t i=0; i<3; i++)
13744     {
13745       c->cd(i+1);
13746       gPad->SetRightMargin(0.2);
13747       
13748       if (i < 2)
13749       {
13750         h->GetTwoTrackDistance(i)->GetZaxis()->SetRangeUser(ptRange[ptID] + 0.01, ptRange[ptID+1] - 0.01);
13751         p = (TH2*) h->GetTwoTrackDistance(i)->Project3D(Form("yx_%d_%d", i, ptID));
13752         
13753         if (1)
13754         {
13755           // reduce to one quadrant
13756           pc = (TH2*) p->Clone(Form("%s_pc", p->GetName()));
13757           pc->Reset();
13758           pc->Rebin2D(2, 2);
13759           for (Int_t x=1; x<=p->GetNbinsX(); x++)
13760             for (Int_t y=1; y<=p->GetNbinsY(); y++)
13761               pc->Fill(TMath::Abs(p->GetXaxis()->GetBinCenter(x)), TMath::Abs(p->GetYaxis()->GetBinCenter(y)), p->GetBinContent(x, y));
13762           pc->GetXaxis()->SetRangeUser(0, 100);
13763           pc->GetYaxis()->SetRangeUser(0, 100);
13764           p = pc;
13765         }
13766         
13767         if (ptID == 0)
13768           p->SetStats(0);
13769         
13770         p->DrawCopy("COLZ");
13771         
13772         proj[i] = p;
13773       }
13774       else
13775       {
13776         proj[0]->Divide(proj[1]);
13777         proj[0]->SetStats(0);
13778
13779 //      Float_t scale = proj[1]->Integral(0, proj[1]->GetNbinsX()+1, 0, proj[1]->GetNbinsY()+1) / proj[0]->Integral(0, proj[1]->GetNbinsX()+1, 0,  proj[1]->GetNbinsY()+1);
13780         Float_t scale = proj[0]->Integral(1, proj[1]->GetNbinsX(), 1, proj[1]->GetNbinsY()) / proj[1]->GetNbinsX() / proj[1]->GetNbinsY();
13781         proj[0]->Scale(1./ scale / 4);
13782         proj[0]->DrawCopy("COLZ");
13783       }
13784     }
13785   }
13786 }
13787
13788 void PlotTwoTrackEfficiencyControlPlots3(const char* fileName, Int_t histID = 0)
13789 {
13790   loadlibs();
13791   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
13792   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
13793   
13794   Float_t ptRange[] = { 0.0, 1.0, 2.0, 3.0, 4.0, 6.0, 8.0, 10.0 };
13795   
13796   graph = new TGraphErrors;
13797   
13798   for (Int_t ptID = 0; ptID < 5; ptID++)
13799   {
13800     c = new TCanvas(Form("c%d", ptID), Form("%.0f < pT < %.0f", ptRange[ptID], ptRange[ptID+1]), 1200, 400);
13801     c->Divide(3, 1);
13802   
13803     TH2* proj[2];
13804     
13805     for (Int_t i=0; i<3; i++)
13806     {
13807       c->cd(i+1);
13808       gPad->SetRightMargin(0.2);
13809       
13810       if (i < 2)
13811       {
13812         AliUEHistograms* input = ((i == 0) ? h : hMixed);
13813         input->GetTwoTrackDistance(histID)->GetZaxis()->SetRangeUser(ptRange[ptID] + 0.01, ptRange[ptID+1] - 0.01);
13814         p = (TH2*) input->GetTwoTrackDistance(histID)->Project3D(Form("yx_%d_%d", i, ptID));
13815         
13816         if (0)
13817         {
13818           // reduce to one quadrant
13819           pc = (TH2*) p->Clone(Form("%s_pc", p->GetName()));
13820           pc->Reset();
13821 //        pc->Rebin2D(2, 2);
13822           for (Int_t x=1; x<=p->GetNbinsX(); x++)
13823             for (Int_t y=1; y<=p->GetNbinsY(); y++)
13824               pc->Fill(TMath::Abs(p->GetXaxis()->GetBinCenter(x)), TMath::Abs(p->GetYaxis()->GetBinCenter(y)), p->GetBinContent(x, y));
13825           pc->GetXaxis()->SetRangeUser(0, 100);
13826           pc->GetYaxis()->SetRangeUser(0, 100);
13827           p = pc;
13828         }
13829         
13830 //      if (ptID == 0)
13831           p->SetStats(0);
13832         
13833         p->DrawCopy("COLZ");
13834         
13835         proj[i] = p;
13836       }
13837       else
13838       {
13839         Float_t scale = proj[0]->Integral() / proj[1]->Integral();
13840         proj[0]->Divide(proj[1]);
13841         proj[0]->SetStats(0);
13842
13843 //      Float_t scale = proj[1]->Integral(0, proj[1]->GetNbinsX()+1, 0, proj[1]->GetNbinsY()+1) / proj[0]->Integral(0, proj[1]->GetNbinsX()+1, 0,  proj[1]->GetNbinsY()+1);
13844 //      Float_t scale = proj[0]->Integral(1, proj[1]->GetNbinsX(), 1, proj[1]->GetNbinsY()) / proj[1]->GetNbinsX() / proj[1]->GetNbinsY();
13845         proj[0]->Scale(1./ scale);
13846 //      proj[0]->Scale(1./ scale / 4);
13847         proj[0]->DrawCopy("COLZ");
13848       }
13849     }
13850   
13851     break;
13852   }
13853 }
13854
13855 void SystematicpTResolution(const char* inputYield, Int_t caseId = 18, Int_t triggerId = 1)
13856 {
13857   //   Study by Jacek comparing TPC only tracks with global tracks for new cuts (crossed rows) (Fwd by Andrew, 07.07.11)
13858   //   Resolution from tpc only tracks twice as worse than global tracks
13859   //   Parameterization for tpc-only tracks:
13860   //     f(pT) = a * pT * sqrt(1+b/(pT^abs(c)))
13861   //     a = 0.003; b = 2.08; c = 7.07e-7
13862   Float_t a = 0.003; Float_t b = 2.08; Float_t c = 7.07e-7;
13863   res = new TF1("res", "[0] * x * sqrt(1+[1]/(x**abs([2])))", 0, 15);
13864   res->SetParameters(a, b, c);
13865 //   res->Draw(); return;
13866   
13867   ReadYields(inputYield);
13868   
13869   for (Int_t side = 0; side < 2; side++)
13870   {
13871     for (Int_t centrality = 0; centrality < 4; centrality++)
13872     {
13873       TGraphErrors** tmp = yields[side][triggerId][centrality]; 
13874       graph = tmp[caseId];
13875       
13876 //       graph->DrawClone("A*");
13877       
13878       Float_t axisLimits[20];
13879       for (Int_t i=0; i<graph->GetN(); i++)
13880       {
13881         axisLimits[i] = graph->GetX()[i] - graph->GetEX()[i];
13882         axisLimits[i+1] = graph->GetX()[i] + graph->GetEX()[i];
13883       }
13884       
13885       hist = new TH1F("hist", "", graph->GetN(), axisLimits);
13886       
13887       for (Int_t i=0; i<graph->GetN(); i++)
13888       {
13889         gaus = new TF1("gaus", "gaus(0)", 0, 15);
13890         Float_t sigma = graph->GetX()[i] * res->Eval(graph->GetX()[i]);
13891         Float_t norm = graph->GetY()[i] / TMath::Sqrt(2 * TMath::Pi()) / sigma;
13892         gaus->SetParameters(norm, graph->GetX()[i], sigma);
13893 //      gaus->Draw("SAME");
13894 //      Printf("%f %f", graph->GetY()[i], gaus->Integral(0, 20));
13895         
13896         // fill histogram
13897         for (Int_t j=1; j<=hist->GetNbinsX(); j++)
13898           hist->SetBinContent(j, hist->GetBinContent(j) + gaus->Integral(hist->GetBinLowEdge(j), hist->GetXaxis()->GetBinUpEdge(j)));
13899       }
13900       
13901 //       hist->Draw("SAME"); return;
13902       
13903       for (Int_t i=0; i<graph->GetN(); i++)
13904         graph->GetY()[i] = hist->GetBinContent(i+1);
13905
13906 //       graph->SetMarkerColor(2); graph->DrawClone("*SAME");
13907     }
13908   }
13909 }
13910
13911 void DrawProcessIDPlot(const char* fileName)
13912 {
13913   if (gFile)
13914     gFile->Close();
13915   TFile::Open(fileName);
13916   list = (TList*) gFile->Get("PWG4_PhiCorrelations/histosPhiCorrelations");
13917   ((TH1*) list->FindObject("processIDs"))->Draw();
13918 }
13919  
13920 void GetExampleDphi(const char* fileName)
13921 {
13922   loadlibs();
13923   
13924   Int_t leadingPtOffset = 1;
13925     
13926   Int_t maxLeadingPt = 5;
13927   Int_t maxAssocPt = 6;
13928   if (1)
13929   {
13930     Float_t leadingPtArr[] = { 2.0, 3.0, 4.0, 6.0, 8.0, 10.0, 15.0, 20.0 };
13931     Float_t assocPtArr[] =     { 0.15, 0.5, 1.0, 2.0, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
13932   }
13933   else
13934   {
13935     Float_t leadingPtArr[] = { 0.15, 10.0 };
13936     Float_t assocPtArr[] =     { 0.15, 10.0 };
13937   }
13938   leadingPtOffset = 1;
13939   
13940 //   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
13941   hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
13942   
13943   if (1)
13944   {
13945 //     h->SetZVtxRange(-0.99, 0.99);
13946     hMixed->SetZVtxRange(-0.99, 0.99);
13947   }
13948
13949   Int_t i=0;
13950   Int_t j=2;
13951
13952   gpTMin = assocPtArr[j] + 0.01;
13953   gpTMax = assocPtArr[j+1] - 0.01;
13954   
13955 //   SetupRanges(h);
13956   SetupRanges(hMixed);
13957
13958   Int_t bin[6];
13959   bin[0] =  hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(0)->GetGrid()->GetAxis(0)->FindBin(0.01);
13960   bin[1] =  hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(0)->GetGrid()->GetAxis(1)->FindBin(1.1);
13961   bin[2] =  hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(0)->GetGrid()->GetAxis(2)->FindBin(2.1);
13962   bin[3] =  hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(0)->GetGrid()->GetAxis(3)->FindBin(5.5);
13963   bin[4] =  hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(0)->GetGrid()->GetAxis(4)->FindBin(0);
13964   if (hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(0)->GetGrid()->GetAxis(5))
13965     bin[5] =  hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(0)->GetGrid()->GetAxis(5)->FindBin(0);
13966   Printf("tracks: %f +- %f", hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(6)->GetGrid()->GetBinContent(bin), hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(6)->GetGrid()->GetBinError(bin));
13967   
13968   bin[0] =  hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(0)->GetGrid()->GetAxis(2)->FindBin(2.1);
13969   bin[1] =  hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(0)->GetGrid()->GetAxis(3)->FindBin(5.5);
13970   if (hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(0)->GetGrid()->GetAxis(5))
13971     bin[2] =  hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(0)->GetGrid()->GetAxis(5)->FindBin(0);
13972   Printf("events: %f +- %f", hMixed->GetUEHist(2)->GetEventHist()->GetGrid(6)->GetGrid()->GetBinContent(bin), hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(6)->GetGrid()->GetBinError(bin));
13973   
13974   return;
13975
13976   Int_t stepMixed = 6;
13977   TH2* mixedTwoD = (TH2*) hMixed->GetUEHist(2)->GetUEHist(stepMixed, 0, leadingPtArr[i+leadingPtOffset], leadingPtArr[i+1+leadingPtOffset], 12, 13, 1, kFALSE);
13978   
13979   TH1* proj = mixedTwoD->ProjectionX("px", 11, 30);
13980   proj->Draw();
13981 }
13982
13983 void GaussToyFit()
13984 {
13985   func = new TF1("func", "gaus(0)", -2, 2);
13986   func->SetParameters(1, 0, 0.5);
13987   
13988   hist = new TH1F("hist", "", 100, -2, 2);
13989   hist->FillRandom("func", 10000);
13990   
13991   func = new TF1("func", "gaus(0)", -2, 2);
13992   func->SetParLimits(2, 0, 10);
13993   func->FixParameter(1, 0);
13994   func->SetParameters(2, 0, 0.1);
13995   hist->Fit(func, "", "", -1, 1);
13996   hist->DrawCopy();
13997   
13998   func2 = new TF1("func2", "gaus(0)+[3]", -2, 2);
13999   func2->SetParLimits(2, 0, 10);
14000   func2->FixParameter(1, 0);
14001   func2->SetParameters(2, 0, 0.1, 0);
14002   func2->SetLineColor(2);
14003   hist->Fit(func2, "+", "", -1, 1);
14004   
14005   return;
14006
14007   new TCanvas;
14008   constant = new TF1("constant", "1", -2, 2);
14009   hist->Add(constant, -30);
14010   func->SetParameters(2, 0, 0.1);
14011   hist->Fit(func, "", "", -1, 1);
14012 }
14013
14014 void GaussToyFit2()
14015 {
14016   func = new TF2("func", "[0]*exp(-0.5*((x/[1])**2+(y/[2])**2))", -2, 2, -2, 2);
14017   func->SetParameters(1, 0.4, 0.6);
14018   
14019   hist = new TH2F("hist", "", 100, -2, 2, 100, -2, 2);
14020   hist->FillRandom("func", 100000);
14021   
14022   func = new TF2("func", "[0]*exp(-0.5*((x/[1])**2+(y/[2])**2))", -2, 2, -2, 2);
14023   func->SetParameters(1, 0.2, 0.2);
14024   hist->Fit(func, "", "");
14025   hist->DrawCopy();
14026   
14027   new TCanvas;
14028   hist->ProjectionX()->Fit("gaus");
14029
14030   new TCanvas;
14031   hist->ProjectionY()->Fit("gaus");
14032 }
14033
14034 void AcceptanceToy()
14035 {
14036   // study a la Jan Rak presented in Corr PAG on 06.03.12
14037   
14038   hist = new TH1F("hist", "", 200, -1.5, 1.5);
14039   
14040   Float_t sigma = 0.3;
14041   for (Int_t i=0; i<1000000; i++)
14042   {
14043     // randomize mean
14044     Float_t mean = gRandom->Uniform(-5, 5);
14045     
14046     Float_t trig = gRandom->Gaus(mean, sigma);
14047     Float_t assoc = gRandom->Gaus(mean, sigma);
14048     
14049 //     Float_t trig = gRandom->Uniform(-5, 5);
14050 //     Float_t assoc = gRandom->Uniform(-5, 5);
14051
14052 /*    if (trig < 0 && assoc < trig)
14053       continue;
14054     if (trig > 0 && assoc > trig)
14055       continue;*/
14056     
14057     if (TMath::Abs(trig) < 1 && TMath::Abs(assoc) < 1)
14058 //       hist->Fill(trig - assoc);
14059       hist->Fill(trig - assoc, 1.0 / (1.0 - TMath::Abs(trig-assoc) / 2));
14060   }
14061   
14062   hist->Draw();
14063   hist->Fit("gaus", "", "", -1.5, 1.5);
14064   Printf("%f %f %f", sigma, hist->GetFunction("gaus")->GetParameter(2), hist->GetFunction("gaus")->GetParameter(2) / TMath::Sqrt(2));
14065   hist->GetFunction("gaus")->SetLineColor(2);
14066 }
14067
14068 void DrawEfficiency(const char* fileName, Int_t step1, Int_t step2)
14069 {
14070   gpTMin = 1.01;
14071   gpTMax = 1.99;
14072   
14073   loadlibs();
14074   
14075   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
14076   hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
14077   
14078   SetupRanges(h);
14079   SetupRanges(hMixed);
14080
14081   TH1* hist1 = 0;
14082   TH1* hist2 = 0;
14083   
14084   GetDistAndFlow(h, hMixed, &hist1,  0, step1, 0,  10, 2.01, 3.99, 1, kTRUE, 0, kTRUE); 
14085   GetDistAndFlow(h, hMixed, &hist2,  0, step2, 0,  10, 2.01, 3.99, 1, kTRUE, 0, kTRUE); 
14086   
14087   ((TH2*)hist1)->Rebin2D(2, 2);
14088   ((TH2*)hist2)->Rebin2D(2, 2);
14089   
14090   new TCanvas("c", "c", 800, 800);
14091   gPad->SetLeftMargin(0.15);
14092   hist1->SetTitle("");
14093   hist1->GetYaxis()->SetRangeUser(-1.39, 1.39);
14094   hist1->GetXaxis()->SetTitleOffset(1.5);
14095   hist1->GetYaxis()->SetTitleOffset(2);
14096   hist1->SetStats(kFALSE);
14097   hist1->DrawCopy("SURF1");
14098   
14099   new TCanvas("c2", "c2", 800, 800);
14100   gPad->SetLeftMargin(0.15);
14101   hist2->SetTitle("");
14102   hist2->GetYaxis()->SetRangeUser(-1.39, 1.39);
14103   hist2->GetXaxis()->SetTitleOffset(1.5);
14104   hist2->GetYaxis()->SetTitleOffset(2);
14105   hist2->SetStats(kFALSE);
14106   hist2->DrawCopy("SURF1");
14107   
14108   hist2->Divide(hist1);
14109
14110   new TCanvas("c3", "c3", 800, 800);
14111   gPad->SetLeftMargin(0.15);
14112   hist2->SetTitle("");
14113   hist2->GetYaxis()->SetRangeUser(-1.39, 1.39);
14114   hist2->GetXaxis()->SetTitleOffset(1.5);
14115   hist2->GetYaxis()->SetTitleOffset(2);
14116   hist2->SetStats(kFALSE);
14117   hist2->Draw("SURF1");
14118 }
14119
14120 void RewriteObjects(const char* fileName)
14121 {
14122   loadlibs();
14123
14124   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
14125   Int_t nAxes = ((AliTHn*) h->GetUEHist(2)->GetTrackHist(0)->GetNVar());
14126   Printf("We have %d axes", nAxes);
14127   
14128   TString histId; histId.Form("%dR", nAxes-1);
14129   Printf("%s", histId.Data());
14130   
14131   AliUEHistograms* hNew = new AliUEHistograms(h->GetName(), histId);
14132   hNew->DeepCopy(h);
14133   delete h;
14134   
14135   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);  
14136   AliUEHistograms* hMixedNew = new AliUEHistograms(hMixed->GetName(), histId);
14137   hMixedNew->DeepCopy(hMixed);
14138   delete hMixed;
14139   
14140   TString newFileName(fileName);
14141   newFileName.ReplaceAll(".root", "");
14142   newFileName += "_rebinned.root";
14143
14144   list = new TList;
14145   list->Add(hNew);
14146   list->Add(hMixedNew);
14147
14148   file3 = TFile::Open(newFileName, "RECREATE");
14149   file3->mkdir("PWG4_PhiCorrelations");
14150   file3->cd("PWG4_PhiCorrelations");
14151   list->Write("histosPhiCorrelations", TObject::kSingleKey);
14152   file3->Close();
14153 }
14154
14155 void CondenseCentrality(const char* fileName, Float_t targetValue, Int_t step = 0, Float_t from = 0, Float_t to = -1)
14156 {
14157   loadlibs();
14158
14159   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
14160   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);  
14161   
14162   h->GetUEHist(2)->CondenseBin(step, 3, 1, targetValue, from, to);
14163   hMixed->GetUEHist(2)->CondenseBin(step, 3, 1, targetValue, from, to);
14164   
14165   Float_t events = h->GetCentralityDistribution()->Integral();
14166   h->GetCentralityDistribution()->Reset();
14167   h->GetCentralityDistribution()->Fill(targetValue, events);
14168   
14169   events = hMixed->GetCentralityDistribution()->Integral();
14170   hMixed->GetCentralityDistribution()->Reset();
14171   hMixed->GetCentralityDistribution()->Fill(targetValue, events);
14172   
14173   TString newFileName(fileName);
14174   newFileName.ReplaceAll(".root", "");
14175   newFileName += "_condensed.root";
14176
14177   list = new TList;
14178   list->Add(h);
14179   list->Add(hMixed);
14180
14181   file3 = TFile::Open(newFileName, "RECREATE");
14182   file3->mkdir("PWG4_PhiCorrelations");
14183   file3->cd("PWG4_PhiCorrelations");
14184   list->Write("histosPhiCorrelations", TObject::kSingleKey);
14185   file3->Close();
14186 }
14187
14188 void SymmetrizepTBins(const char* fileName)
14189 {
14190   // copy pt,a < pt,t bins to pt,a > pt,t
14191   
14192   loadlibs();
14193
14194   TList* list = 0;
14195   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName, &list);
14196   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);  
14197   
14198   h->GetUEHist(2)->SymmetrizepTBins();
14199   hMixed->GetUEHist(2)->SymmetrizepTBins();
14200
14201   TString newFileName(fileName);
14202   newFileName.ReplaceAll(".root", "");
14203   newFileName += "_symmetrized.root";
14204
14205   file3 = TFile::Open(newFileName, "RECREATE");
14206   file3->mkdir("PWG4_PhiCorrelations");
14207   file3->cd("PWG4_PhiCorrelations");
14208   list->Write("histosPhiCorrelations", TObject::kSingleKey);
14209   file3->Close();
14210 }
14211
14212 void PtDistributions(Int_t step = 8, Float_t centralityBegin = 1, Float_t centralityEnd = 10)
14213 {
14214   loadlibs();
14215
14216 //   const char* fileNames[] = { "LHC10h_AOD086_120411_zvtx_rebinned_corrected.root", "LHC10h_AOD086_120411_hybrid_zvtx_rebinned_corrected.root", "LHC10h_AOD086_120430_raacuts_zvtx_rebinned_corrected.root" };
14217   
14218 //   const char* fileNames[] = { "LHC10h_AOD086_120411_zvtx_rebinned.root", "LHC10h_AOD086_120411_hybrid_zvtx_rebinned.root", "LHC10h_AOD086_120430_raacuts_zvtx_rebinned.root" };
14219   const char* fileNames[] = { "pt_pos.root", "pt_neg.root" };
14220 //   const char* fileNames[] = { "LHC11a10a_bis_AOD090_120406_zvtx.root" };
14221
14222 //   Float_t eventCount[] = { 1098234., 1034306., 1369707. };
14223 //   Float_t eventCount[] = { 987360.000000, 930278.000000, 1231806.000000 };
14224   Float_t eventCount[] = { 1., 1. };
14225
14226   TH1* pt[3];
14227
14228   new TCanvas;
14229   for (Int_t i=0; i<2; i++)
14230   {
14231 /*    AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileNames[i]);
14232     
14233     h->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->SetRangeUser(0.01 + centralityBegin, -0.01 + centralityEnd);
14234     ptDist = h->GetUEHist(2)->GetEventHist()->Project(step, 0);*/
14235     
14236 /*    eventCount = h->GetEventCount();
14237     Float_t events = eventCount->Integral(eventCount->GetXaxis()->FindBin(step), eventCount->GetXaxis()->FindBin(step), eventCount->GetYaxis()->FindBin(0.01 + centralityBegin), eventCount->GetYaxis()->FindBin(-0.01 + centralityEnd));*/
14238     Float_t events = eventCount[i];
14239     
14240     TFile::Open(fileNames[i]);
14241     ptDist = (TH2*) gFile->Get("ptDist");
14242     
14243     ptDistProj = ptDist->ProjectionX(Form("ptDistProj_%d", i), ptDist->GetYaxis()->FindBin(0.01 + centralityBegin), ptDist->GetYaxis()->FindBin(-0.01 + centralityEnd));
14244   
14245 //     new TCanvas; ptDistProj->Draw(); gPad->SetLogy();
14246   
14247    
14248     ptDistProj->Scale(1.0 / events);
14249     
14250     ptDistProj->SetLineColor(i+1);
14251     ptDistProj->DrawCopy((i == 0) ? "" : "SAME");
14252
14253     pt[i] = (TH1*) ptDistProj->Clone(Form("clone_%d", i));
14254   }
14255   gPad->SetLogy();
14256
14257   new TCanvas;
14258   for (Int_t i=1; i<2; i++)
14259   {
14260     pt[i]->Divide(pt[0]);
14261     pt[i]->DrawCopy((i == 1) ? "" : "SAME");
14262   }  
14263 }
14264
14265 void test(const char* fileNameESD)
14266 {
14267   Int_t step = 8;
14268   
14269   loadlibs();
14270   AliUEHistograms* esd = (AliUEHistograms*) GetUEHistogram(fileNameESD);
14271   
14272   SetupRanges(esd);
14273
14274   ptDist = (TH2*) esd->GetUEHist(2)->GetEventHist()->Project(step, 0, 1);
14275   
14276   Printf("%f", ptDist->Integral());
14277 }
14278
14279 void CorrectPtDistribution(const char* fileNameCorrections, const char* fileNameESD, const char* outputFile)
14280 {
14281   Int_t step = 8;
14282   
14283   loadlibs();
14284   
14285   AliUEHistograms* corr = (AliUEHistograms*) GetUEHistogram(fileNameCorrections);
14286   
14287   TList* list = 0;
14288   AliUEHistograms* esd = (AliUEHistograms*) GetUEHistogram(fileNameESD, &list);
14289   
14290   SetupRanges(corr);
14291   SetupRanges(esd);
14292   
14293   corr->SetEtaRange(-0.89, 0.89);
14294   corr->ExtendTrackingEfficiency(0);
14295
14296   eff = corr->GetUEHist(2)->GetTrackingEfficiencyCorrectionCentrality();
14297   new TCanvas; eff->Draw("COLZ");
14298   
14299   cont = corr->GetUEHist(2)->GetTrackingContaminationCentrality();
14300   new TCanvas; cont->Draw("COLZ");
14301   
14302   ptDist = (TH2*) esd->GetUEHist(2)->GetEventHist()->Project(step, 0, 1);
14303   ptDist->SetStats(0);
14304   new TCanvas; ptDist->DrawCopy("COLZ");
14305   
14306   for (Int_t x=1; x<=ptDist->GetNbinsX(); x++)
14307     for (Int_t y=1; y<=ptDist->GetNbinsY(); y++)
14308     {
14309       Float_t factor = eff->GetBinContent(eff->GetXaxis()->FindBin(ptDist->GetXaxis()->GetBinCenter(x)), eff->GetYaxis()->FindBin(ptDist->GetYaxis()->GetBinCenter(y)));
14310       Float_t contFactor = cont->GetBinContent(cont->GetXaxis()->FindBin(ptDist->GetXaxis()->GetBinCenter(x)), cont->GetYaxis()->FindBin(ptDist->GetYaxis()->GetBinCenter(y)));
14311       
14312       printf("%f", contFactor);
14313       if (contFactor > 0)
14314         contFactor = 1.0 + 1.1 * (contFactor - 1.0);
14315       printf(" --> %f\n", contFactor);
14316       
14317       factor *= contFactor;
14318       
14319       ptDist->SetBinContent(x, y, ptDist->GetBinContent(x, y) * factor);
14320       ptDist->SetBinError(x, y, ptDist->GetBinError(x, y) * factor);
14321     }
14322   
14323   new TCanvas; ptDist->DrawCopy("COLZ");
14324   
14325   file3 = TFile::Open(outputFile, "RECREATE");
14326   ptDist->Write("ptDist");
14327   file3->Write();
14328   file3->Close();
14329   
14330   delete corr;
14331   delete esd;
14332 }
14333
14334 void CorrectPtDistributionAll()
14335 {
14336   CorrectPtDistribution("LHC11a10a_bis_AOD090_120406.root", "LHC10h_AOD086_120411_zvtx_rebinned.root", "ptdist1.root");
14337   CorrectPtDistribution("LHC11a10a_bis_AOD090_120505_zvtx_hybrid.root", "LHC10h_AOD086_120411_hybrid_zvtx_rebinned.root", "ptdist2.root");
14338   CorrectPtDistribution("LHC11a10a_bis_AOD090_120505_zvtx_raa.root", "LHC10h_AOD086_120430_raacuts_zvtx_rebinned.root", "ptdist3.root");
14339 }
14340   
14341 void CreateNormalizationTestObject(Bool_t addRidge = kFALSE)
14342 {
14343   loadlibs();
14344   gSystem->Load("libPWGCFCorrelationsDPhi");
14345
14346   AliUEHistograms* hNew = new AliUEHistograms("AliUEHistogramsSame", "5RC");
14347   
14348   // fill 1000 particles in one bin
14349   TObjArray* particles = new TObjArray;
14350   particles->Add(new AliDPhiBasicParticle(0, 0, 3.5, 1));
14351   for (Int_t i=0; i<2000; i++)
14352     particles->Add(new AliDPhiBasicParticle(gRandom->Gaus(0, 0.3), gRandom->Gaus(0, 0.3), 1.75, 1));
14353   
14354   hNew->FillCorrelations(61, 0, 8, particles);
14355
14356   if (addRidge)
14357   {
14358     for (Int_t i=0; i<10000; i++)
14359       particles->Add(new AliDPhiBasicParticle(gRandom->Uniform(-2, 2), gRandom->Gaus(0, 0.5), 1.75, 1));
14360   }
14361
14362   hNew->FillCorrelations(0.5, 0, 8, particles);
14363
14364   // fill flat mixed event
14365   AliUEHistograms* hMixedNew = new AliUEHistograms("AliUEHistogramsMixed", "5RC");
14366   THnSparse* sparse = hMixedNew->GetUEHist(2)->GetTrackHist(0)->GetGrid(8)->GetGrid();
14367   for (Int_t x=1; x<=sparse->GetAxis(0)->GetNbins(); x++)
14368     for (Int_t y=1; y<=sparse->GetAxis(4)->GetNbins(); y++)
14369     {
14370       Double_t bin[6];
14371       bin[0] = sparse->GetAxis(0)->GetBinCenter(x);
14372       bin[4] = sparse->GetAxis(4)->GetBinCenter(y);
14373       bin[1] = 1.75;
14374       bin[2] = 3.5;
14375       bin[3] = 0.5;
14376       bin[5] = 0;
14377       sparse->Fill(bin);
14378
14379       bin[3] = 61;
14380       sparse->Fill(bin);
14381
14382       bin[3] = 0.5;
14383       bin[2] = 1.75;
14384       sparse->Fill(bin);
14385
14386       bin[3] = 61;
14387       sparse->Fill(bin);
14388     }
14389     
14390   Double_t bin[6];
14391   bin[0] = 3.5;
14392   bin[1] = 0.5;
14393   bin[2] = 0;
14394   hMixedNew->GetUEHist(2)->GetEventHist()->GetGrid(8)->GetGrid()->Fill(bin);
14395   
14396   bin[1] = 61;
14397   hMixedNew->GetUEHist(2)->GetEventHist()->GetGrid(8)->GetGrid()->Fill(bin);
14398
14399   bin[1] = 0.5;
14400   bin[0] = 1.75;
14401   hMixedNew->GetUEHist(2)->GetEventHist()->GetGrid(8)->GetGrid()->Fill(bin);
14402
14403   bin[1] = 61;
14404   hMixedNew->GetUEHist(2)->GetEventHist()->GetGrid(8)->GetGrid()->Fill(bin);
14405
14406   ((AliTHn*) hNew->GetUEHist(2)->GetTrackHist(0))->FillParent();
14407   ((AliTHn*) hNew->GetUEHist(2)->GetTrackHist(0))->DeleteContainers();
14408
14409   ((AliTHn*) hMixedNew->GetUEHist(2)->GetTrackHist(0))->FillParent();
14410   ((AliTHn*) hMixedNew->GetUEHist(2)->GetTrackHist(0))->DeleteContainers();
14411
14412   list = new TList;
14413   list->Add(hNew);
14414   list->Add(hMixedNew);
14415
14416   file3 = TFile::Open("norm.root", "RECREATE");
14417   file3->mkdir("PWG4_PhiCorrelations");
14418   file3->cd("PWG4_PhiCorrelations");
14419   list->Write("histosPhiCorrelations", TObject::kSingleKey);
14420   file3->Close();
14421 }
14422
14423 void CompareSumOfRatiosAndDefault(const char* fileName, Int_t bin, Int_t step)
14424 {
14425   loadlibs();
14426  
14427   Int_t centralityFrom = 0;
14428   Int_t centralityTo = 20;
14429   
14430   gpTMin = 1.01;
14431   gpTMax = 1.99;
14432   
14433   Float_t ptTrigBegin = 2.01;
14434   Float_t ptTrigEnd = 3.99;
14435   
14436   if (bin == 1)
14437   {
14438     ptTrigBegin = 1.01;
14439     ptTrigEnd = 1.99;
14440   }
14441   else if (bin == 2)
14442   {
14443     gpTMin = 0.49;
14444     gpTMax = 0.99;
14445     ptTrigBegin = 0.49;
14446     ptTrigEnd = 0.99;
14447   }
14448   
14449   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
14450   hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
14451   
14452   SetupRanges(h);
14453   SetupRanges(hMixed);
14454   
14455   TH2* hist1 = 0;
14456   TH2* hist2 = 0;
14457   GetSumOfRatios(h, hMixed, &hist1,  step, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, kTRUE); 
14458   GetDistAndFlow(h, hMixed, &hist2,  0, step, centralityFrom, centralityTo,  ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE);
14459   
14460   hist1->Rebin2D(2, 2); hist1->Scale(0.25);
14461   hist2->Rebin2D(2, 2); hist2->Scale(0.25);
14462   
14463   c = new TCanvas("c", "c", 1000, 1000);
14464   c->Divide(2, 3);
14465   
14466   c->cd(1);
14467   hist1->DrawCopy("SURF1");
14468
14469   c->cd(2);
14470   hist2->DrawCopy("SURF1");
14471   
14472   c->cd(4);
14473   proj1 = ((TH2*) hist1)->ProjectionY("proj1", hist1->GetXaxis()->FindBin(-0.99), hist1->GetXaxis()->FindBin(0.99));
14474   proj1->DrawCopy();
14475   proj2 = ((TH2*) hist2)->ProjectionY("proj2", hist2->GetXaxis()->FindBin(-0.99), hist2->GetXaxis()->FindBin(0.99));
14476   proj2->SetLineColor(2);
14477   proj2->DrawCopy("SAME");
14478   
14479   c->cd(5);
14480   proj1->Divide(proj1, proj2, 1, 1, "B");
14481   proj1->DrawCopy();
14482   
14483   c->cd(3);
14484   hist1->Divide(hist2);
14485   hist1->DrawCopy("SURF1");
14486 }
14487
14488 void PtDistribution(const char* fileName, Int_t step, Int_t bin = 0)
14489 {
14490   Int_t centralityFrom = 0;
14491   Int_t centralityTo = 80;
14492   
14493   Float_t ptTrigBegin = 2.01;
14494   Float_t ptTrigEnd = 3.99;
14495   
14496   if (bin == 1)
14497   {
14498     ptTrigBegin = 1.01;
14499     ptTrigEnd = 1.99;
14500   }
14501   else if (bin == 2)
14502   {
14503     ptTrigBegin = 0.51;
14504     ptTrigEnd = 0.99;
14505   }
14506   
14507   loadlibs();
14508   
14509   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
14510
14511   Int_t centralityBeginBin = 0;
14512   Int_t centralityEndBin = -1;
14513   
14514   if (centralityTo >= centralityFrom)
14515   {
14516     centralityBeginBin = h->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->FindBin(0.01 + centralityFrom);
14517     centralityEndBin = h->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->FindBin(-0.01 + centralityTo);
14518   }
14519
14520   pt1 = h->GetUEHist(2)->GetPtHist(step, 0, ptTrigBegin, ptTrigEnd, centralityBeginBin, centralityEndBin, TMath::Pi()/2 - 0.2, TMath::Pi()/2 + 0.2, -1.99, 1.99);
14521   pt2 = h->GetUEHist(2)->GetPtHist(step, 0, ptTrigBegin, ptTrigEnd, centralityBeginBin, centralityEndBin, -0.5, 0.5, -1.99, 1.99);
14522   
14523   new TCanvas;
14524   pt1->DrawCopy();
14525   pt2->SetLineColor(2);
14526   pt2->DrawCopy("SAME");
14527   gPad->SetLogy();
14528   
14529   // TODO proper subtraction, to get the pT distribution in the peak
14530 }
14531
14532 void GetRefMultiplicity(const char* fileNameESD, const char* tag = "")
14533 {
14534   Int_t step = 8;
14535   
14536   loadlibs();
14537   
14538   AliUEHistograms* esd = (AliUEHistograms*) GetUEHistogram(fileNameESD, 0, kFALSE, tag);
14539   
14540   Float_t centrBins[] = { 0, 20, 40, 60, 100 };
14541 //   Float_t centrBins[] = { 0, 100 };
14542   
14543   // NOTE Run it on data with limited zvtx range so that there are no empty bins in the corrections!
14544   
14545   for (Int_t i=0; i<4; i++)
14546   {
14547     Float_t centrBegin = centrBins[i] + 0.1;
14548     Float_t centrEnd   = centrBins[i+1] - 0.1;
14549     esd->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->SetRangeUser(centrBegin, centrEnd);
14550   
14551     ptDist = (TH2*) esd->GetUEHist(2)->GetEventHist()->Project(step, 0);
14552   
14553     centrDist = esd->GetCentralityDistribution();
14554     
14555     if (1)
14556     {
14557       // add syst from R_pA
14558       for (Int_t j=1; j<=ptDist->GetNbinsX(); j++)
14559         ptDist->SetBinError(j, TMath::Sqrt(ptDist->GetBinError(j) * ptDist->GetBinError(j) + 0.052 * 0.052 * ptDist->GetBinContent(j) * ptDist->GetBinContent(j)));
14560     }
14561     
14562     Float_t events = centrDist->Integral(centrDist->FindBin(centrBegin), centrDist->FindBin(centrEnd));
14563     Double_t error = 0;
14564 //     Float_t integral = ptDist->IntegralAndError(ptDist->FindBin(0.51), ptDist->FindBin(3.99), error);
14565     Float_t integral = ptDist->IntegralAndError(ptDist->FindBin(0.51), ptDist->FindBin(7.99), error);
14566     Printf("%d: %f +- %f %f --> %f +- %F", i, integral, error, events, integral / events, error / events);
14567     
14568     ptDist->Scale(1.0 / events);
14569 //     ptDist->Scale(1.0 / integral);
14570   
14571 //     ptDist->Rebin(2); 
14572     
14573     NormalizeToBinWidth(ptDist);
14574     ptDist->SetLineColor(i + 1);
14575     ptDist->DrawCopy((i == 0) ? "" : "SAME");
14576   }
14577   gPad->SetLogy();
14578   
14579   TFile::Open("dNdPt_pPb_lab_MinBias_NEW.root");
14580   comparison = (TH1*) gFile->Get("dNdPt_pPb_eta08_stat");
14581   comparison->Scale(1.6); // normalize to my eta range
14582   comparison->SetLineColor(2);
14583   comparison->DrawCopy("SAME");
14584   
14585   //rebin
14586   for (Int_t i=1; i<=comparison->GetNbinsX(); i++)
14587   {
14588     // multiply by bin width
14589     comparison->SetBinContent(i, comparison->GetBinContent(i) * comparison->GetBinWidth(i));
14590     comparison->SetBinError(i, comparison->GetBinError(i) * comparison->GetBinWidth(i));
14591   }
14592
14593   Float_t integral = comparison->IntegralAndError(comparison->FindBin(0.51), comparison->FindBin(7.99), error);
14594   Float_t integral2 = comparison->IntegralAndError(comparison->FindBin(0.51), comparison->FindBin(19.99), error);
14595   Printf("%f %f", integral, integral2);
14596     
14597   Float_t integral = comparison->IntegralAndError(comparison->FindBin(0.51), comparison->FindBin(7.99), error);
14598   Float_t integral2 = comparison->IntegralAndError(comparison->FindBin(0.61), comparison->FindBin(7.99), error);
14599   Printf("%f %f", integral, integral2);
14600
14601   rebinned = comparison->Rebin(ptDist->GetNbinsX(), "rebinned", ptDist->GetXaxis()->GetXbins()->GetArray());
14602   
14603   
14604   NormalizeToBinWidth(rebinned);
14605   rebinned->Draw("SAME");
14606   
14607   new TCanvas;
14608   ptDist->Divide(rebinned);
14609   ptDist->Draw();
14610   
14611   return;
14612   
14613   new TCanvas;
14614   syst = (TH1*) gFile->Get("dNdPt_pPb_eta08_syst");
14615   syst->DrawCopy();
14616   
14617   new TCanvas;
14618   for (Int_t i=1; i<=syst->GetNbinsX(); i++)
14619   {
14620     if (syst->GetBinContent(i) > 0)
14621       syst->SetBinContent(i, syst->GetBinError(i) / syst->GetBinContent(i));
14622     syst->SetBinError(i, 0);
14623   }
14624   syst->Draw();
14625 }
14626
14627 void CheckBin(const char* fileName)
14628 {
14629   loadlibs();
14630
14631   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
14632   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
14633   
14634   sparse = h->GetUEHist(2)->GetTrackHist(0)->GetGrid(8)->GetGrid();
14635   sparse->GetAxis(1)->SetRangeUser(5, 5.1);
14636   sparse->GetAxis(2)->SetRangeUser(7, 7.1);
14637   sparse->GetAxis(3)->SetRangeUser(90, 91);
14638   sparse->GetAxis(4)->SetRangeUser(9, 9.1);
14639  
14640   new TCanvas;
14641   sparse->Projection(0, 4)->Draw("colz");
14642
14643   sparse = hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(8)->GetGrid();
14644   sparse->GetAxis(1)->SetRangeUser(5, 5.1);
14645   sparse->GetAxis(2)->SetRangeUser(7, 7.1);
14646   sparse->GetAxis(3)->SetRangeUser(90, 91);
14647   sparse->GetAxis(4)->SetRangeUser(9, 9.1);
14648  
14649   new TCanvas;
14650   sparse->Projection(0, 4)->Draw("colz");
14651 }
14652
14653 void GetCorrectedYields(const char* fileName, const char* correctionFile, Int_t partSpecies=-1 )
14654 {
14655   loadlibs();
14656
14657   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
14658   
14659   // centrality, pT, eta
14660   yieldsUncorr = h->GetYield();
14661   new TCanvas; yieldsUncorr->DrawCopy();
14662 //   new TCanvas; yieldsUncorr->ProjectionX("x1")->DrawCopy();
14663  
14664   // normalize per event
14665   centrDist = h->GetCentralityCorrelation()->ProjectionX();
14666   new TCanvas; centrDist->Draw();
14667
14668   for (Int_t x=1; x<=yieldsUncorr->GetNbinsX(); x++)
14669   {
14670     Double_t factor = centrDist->GetBinContent(centrDist->FindBin(yieldsUncorr->GetXaxis()->GetBinCenter(x)));
14671 //     Printf("%d %f %d %f", x, yieldsUncorr->GetXaxis()->GetBinCenter(x), centrDist->FindBin(yieldsUncorr->GetXaxis()->GetBinCenter(x)), factor);
14672     if (factor <= 0)
14673       continue;
14674     
14675     for (Int_t y=0; y<=yieldsUncorr->GetNbinsY()+1; y++)
14676       for (Int_t z=0; z<=yieldsUncorr->GetNbinsZ()+1; z++)
14677       {
14678         if (yieldsUncorr->GetBinContent(x, y, z) <= 0)
14679           continue;
14680         yieldsUncorr->SetBinContent(x, y, z, yieldsUncorr->GetBinContent(x, y, z) / factor);
14681         yieldsUncorr->SetBinError(x, y, z, yieldsUncorr->GetBinError(x, y, z) / factor);
14682       }
14683   }
14684
14685 //   new TCanvas; yieldsUncorr->ProjectionX("x2")->DrawCopy(); return;
14686   
14687   AliUEHistograms* hCorr = (AliUEHistograms*) GetUEHistogram(correctionFile);
14688   if(partSpecies!=-1){
14689     Double_t epsilon=0.001;
14690     hCorr->GetUEHist(2)->GetTrackHistEfficiency()->GetGrid(0)->GetGrid()->GetAxis(2)->SetRangeUser(partSpecies-epsilon,partSpecies+epsilon);
14691     hCorr->GetUEHist(2)->GetTrackHistEfficiency()->GetGrid(4)->GetGrid()->GetAxis(2)->SetRangeUser(partSpecies-epsilon,partSpecies+epsilon);
14692   }
14693   
14694   hCorr->GetUEHist(2)->GetTrackHistEfficiency()->GetGrid(0)->GetGrid()->GetAxis(4)->SetRangeUser(-1.9, 1.9);
14695   hCorr->GetUEHist(2)->GetTrackHistEfficiency()->GetGrid(2)->GetGrid()->GetAxis(4)->SetRangeUser(-1.9, 1.9);
14696   hCorr->GetUEHist(2)->GetTrackHistEfficiency()->GetGrid(4)->GetGrid()->GetAxis(4)->SetRangeUser(-1.9, 1.9);
14697   
14698   // eta, pT
14699   TH2* generated = hCorr->GetUEHist(2)->GetTrackHistEfficiency()->GetGrid(0)->GetGrid()->Projection(1, 0);
14700   TH2* measured = hCorr->GetUEHist(2)->GetTrackHistEfficiency()->GetGrid((partSpecies==-1)?2:4)->GetGrid()->Projection(1, 0);
14701   
14702   Printf("%f %f", generated->GetEntries(), measured->GetEntries());
14703
14704   new TCanvas; generated->Draw("COLZ");
14705   new TCanvas; measured->Draw("COLZ");
14706   
14707   effCorr = (TH2*) generated->Clone("correction");
14708   effCorr->Divide(generated, measured, 1, 1, "B");
14709   
14710   new TCanvas; effCorr->Draw("COLZ");
14711   
14712 //   return;
14713   
14714   yieldsCorr = (TH3F*) yieldsUncorr->Clone("fYieldsCorr");
14715   yieldsCorr->Reset();
14716   
14717   for (Int_t x=1; x<=yieldsUncorr->GetNbinsX(); x++)
14718     for (Int_t y=1; y<=yieldsUncorr->GetNbinsY(); y++)
14719       for (Int_t z=1; z<=yieldsUncorr->GetNbinsZ(); z++)
14720       {
14721         Double_t factor = effCorr->GetBinContent(effCorr->GetXaxis()->FindBin(yieldsUncorr->GetZaxis()->GetBinCenter(z)), effCorr->GetYaxis()->FindBin(yieldsUncorr->GetYaxis()->GetBinCenter(y)));
14722         yieldsCorr->SetBinContent(x, y, z, yieldsUncorr->GetBinContent(x, y, z) * factor);
14723         yieldsCorr->SetBinError(x, y, z, yieldsUncorr->GetBinError(x, y, z) * factor);
14724       }
14725
14726   new TCanvas; yieldsCorr->DrawCopy();
14727   
14728   TFile::Open("corr_yield.root", "RECREATE");
14729   yieldsCorr->Write();
14730   gFile->Close();
14731   
14732   yieldsUncorr->GetXaxis()->SetRangeUser(1, yieldsUncorr->GetNbinsX());
14733
14734   new TCanvas; yieldsUncorr->Project3D("z1")->DrawCopy()->SetLineColor(1); yieldsCorr->Project3D("z2")->DrawCopy("SAME")->SetLineColor(2);
14735
14736   yieldsUncorr->GetXaxis()->SetRangeUser(0.1, 9.9);
14737   yieldsCorr->GetXaxis()->SetRangeUser(0.1, 9.9);
14738   new TCanvas; yieldsUncorr->Project3D("z3")->DrawCopy()->SetLineColor(1); yieldsCorr->Project3D("z4")->DrawCopy("SAME")->SetLineColor(2);
14739   yieldsUncorr->GetXaxis()->SetRangeUser(60.1, 99.9);
14740   yieldsCorr->GetXaxis()->SetRangeUser(60.1, 99.9);
14741   yieldsUncorr->Project3D("z5")->DrawCopy("SAME")->SetLineColor(3); yieldsCorr->Project3D("z6")->DrawCopy("SAME")->SetLineColor(4);
14742 }
14743
14744 void PlotPtCentrality()
14745 {
14746   TFile::Open("corr_yield.root");
14747   yieldsCorr = (TH3F*) gFile->Get("fYieldsCorr");
14748   
14749   yieldsCorr->GetZaxis()->SetRangeUser(-0.4999, 0.4999);
14750   yieldsProj = (TH2*) yieldsCorr->Project3D("yx");
14751   Printf("%f", yieldsProj->Integral());
14752   
14753   Float_t ptMin[] = { 0.5001, 1.0001, 2.0001 };
14754   Float_t ptMax = 10;
14755   
14756   for (Int_t i=0; i<3; i++)
14757   {
14758     profile = yieldsProj->ProjectionX(Form("x%d", i), yieldsProj->GetYaxis()->FindBin(ptMin[i]), yieldsProj->GetYaxis()->FindBin(ptMax));
14759     profile->SetLineColor(i+1);
14760     profile->Draw((i > 0) ? "SAME" : "");
14761   }
14762 }
14763
14764 void ExtractForAllSpecies()
14765 {
14766   TString baseName = "LHC13b2_fix_1_Train";
14767   const char* suffix[] = { "55_Hadrons_symmetrized", "63_Pions", "63_Kaons", "63_Protons" };
14768   TString baseNameOutput = "dphi_corr_mc_130531_allpt_";
14769   
14770   for (Int_t i=0; i<4; i++)
14771     PlotDeltaPhiEtaGap(baseName + suffix[i] + ".root", 0, 0, 0, baseNameOutput + suffix[i] + ".root");
14772 }
14773
14774 void Compare2D(const char* fileName, const char* fileName2)
14775 {
14776   Int_t step = 8;
14777   
14778   gpTMin = 1.01;
14779   gpTMax = 1.99;
14780   
14781   loadlibs();
14782   
14783   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
14784   hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
14785   
14786   AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(fileName2);
14787   hMixed2 = (AliUEHistograms*) GetUEHistogram(fileName2, 0, kTRUE);
14788
14789   SetupRanges(h);
14790   SetupRanges(hMixed);
14791   SetupRanges(h2);
14792   SetupRanges(hMixed2);
14793   
14794 //   h->SetZVtxRange(0.1, 0.5);
14795 //   hMixed->SetZVtxRange(0.1, 0.5);
14796 //   h2->SetZVtxRange(0.1, 0.5);
14797 //   hMixed2->SetZVtxRange(0.1, 0.5);
14798   
14799   TH1* hist1 = 0;
14800   GetDistAndFlow(h, 0, &hist1,  0, step, 0,  20, 1.01, 1.99, 1, kTRUE, 0, kTRUE); 
14801   
14802   TH1* hist2 = 0;
14803   GetDistAndFlow(h2, 0, &hist2,  0, step, 0,  20, 1.01, 1.99, 1, kTRUE, 0, kTRUE); 
14804
14805   c = new TCanvas("c", "c", 1600, 800);
14806   c->Divide(2, 1);
14807   c->cd(1);
14808   gPad->SetLeftMargin(0.15);
14809
14810   hist1->DrawCopy("SURF1");
14811   
14812   c->cd(2);
14813   gPad->SetLeftMargin(0.15);
14814
14815   hist2->DrawCopy("SURF1");
14816   
14817   Printf("%f %f", hist1->Integral(), hist2->Integral());
14818   
14819   new TCanvas("c3", "c3", 800, 800);
14820   gPad->SetLeftMargin(0.15);
14821   hist2->Divide(hist1);
14822   hist2->DrawCopy("COLZ");
14823 }
14824
14825 //Geant3/Fluka correction for tracking from the spectra analysis
14826 TF1 *
14827 TrackingEff_geantflukaCorrection(Int_t ipart, Int_t icharge)
14828 {
14829
14830   if (ipart == 3 && icharge == kNegative) {
14831     TF1 *f = new TF1(Form("fGeantFluka_%s_%s", AliPID::ParticleName(ipart), Sign[icharge]), "TrackingPtGeantFlukaCorrectionKaMinus(x);p_{T};GF correction", 0., 5.);
14832     return f;
14833   }
14834   else if (ipart == 4 && icharge == kNegative) {
14835     TF1 *f = new TF1(Form("fGeantFluka_%s_%s", AliPID::ParticleName(ipart), Sign[icharge]), "TrackingPtGeantFlukaCorrectionPrMinus(x);p_{T};GF correction", 0., 5.);
14836   }
14837   else
14838     TF1 *f = new TF1(Form("fGeantFluka_%s_%s", AliPID::ParticleName(ipart), Sign[icharge]), "TrackingPtGeantFlukaCorrectionNull(x);p_{T};GF correction", 0., 5.);
14839
14840   return f;
14841 }
14842
14843 Double_t
14844 TrackingPtGeantFlukaCorrectionNull(Double_t pTmc)
14845 {
14846   return 1.;
14847 }
14848
14849 Double_t
14850 TrackingPtGeantFlukaCorrectionPrMinus(Double_t pTmc)
14851 {
14852   return (1 - 0.129758 *TMath::Exp(-pTmc*0.679612));
14853 }
14854
14855 Double_t
14856 TrackingPtGeantFlukaCorrectionKaMinus(Double_t pTmc)
14857 {
14858   return TMath::Min((0.972865 + 0.0117093*pTmc), 1.);
14859 }
14860
14861 //Geant3/Fluka correction for matching from the spectra analysis
14862 TF1 *
14863 TOFmatchMC_geantflukaCorrection(Int_t ipart, Int_t icharge,Int_t ntrd)
14864 {
14865   if (ipart == 3 && icharge == kNegative) {
14866     TF1 *f = new TF1(Form("fGeantFluka_%s_%s", AliPID::ParticleName(ipart), Sign[icharge]),Form("MatchingPtGeantFlukaCorrectionKaMinus(x,%d);p_{T};GF correction",ntrd), 0., 5.);
14867     return f;
14868   }
14869   else if (ipart == 4 && icharge == kNegative) {
14870     TF1 *f = new TF1(Form("fGeantFluka_%s_%s", AliPID::ParticleName(ipart), Sign[icharge]),Form("MatchingPtGeantFlukaCorrectionPrMinus(x,%d);p_{T};GF correction",ntrd), 0., 5.);
14871   }
14872   else
14873     TF1 *f = new TF1(Form("fGeantFluka_%s_%s", AliPID::ParticleName(ipart), Sign[icharge]), "MatchingPtGeantFlukaCorrectionNull(x);p_{T};GF correction", 0., 5.);
14874   
14875   return f;
14876 }
14877
14878
14879 Double_t
14880 MatchingPtGeantFlukaCorrectionNull(Double_t pTmc)
14881 {
14882   return 1.;
14883 }
14884 Double_t
14885 MatchingPtGeantFlukaCorrectionKaMinus(Double_t pTmc, Int_t ntrd = 7)//ntrd is 7 in 2010, 10 in 2011, 13 in 2012+2013
14886 {
14887   Float_t ptTPCoutK=pTmc*(1- 3.37297e-03/pTmc/pTmc - 3.26544e-03/pTmc);
14888   Float_t scale = (ntrd * 0.14638485 + (18 - ntrd) * 0.02406) / 18.;
14889   return TMath::Min((TMath::Power(0.972865 + 0.0117093*ptTPCoutK,scale/0.03471)), 1.);
14890 }
14891 Double_t
14892 MatchingPtGeantFlukaCorrectionPrMinus(Double_t pTmc, Int_t ntrd = 7)//ntrd is 7 in 2010, 10 in 2011, 13 in 2012+2013
14893 {
14894   Float_t ptTPCoutP =pTmc*(1-6.81059e-01*TMath::Exp(-pTmc*4.20094));
14895   Float_t scale = (ntrd * 0.14638485 + (18 - ntrd) * 0.02406) / 18.;
14896   return (TMath::Power(1 - 0.129758*TMath::Exp(-ptTPCoutP*0.679612),scale/0.03471));
14897 }
14898
14899 void Browse(const char* fileName)
14900 {
14901   loadlibs();
14902
14903   if (!gGrid && TString(fileName).BeginsWith("alien://"))
14904     TGrid::Connect("alien://");
14905   
14906   TFile::Open(fileName);
14907
14908   new TBrowser;
14909 }
14910