]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGCF/Correlations/macros/dphicorrelations/correct.C
update from marco
[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 Float_t gZVtxRange = -1;
11 const char* gText = "";
12 TString Sign[]={"Plus","Minus"};
13 enum ECharge_t {
14   kPositive,
15   kNegative,
16   kNCharges
17 };
18 Bool_t gIsTrkletsTrklets=kFALSE;
19 Bool_t gIsMuTrklets=kFALSE;
20   
21 void SetRanges(TAxis* axis)
22 {
23   if (strcmp(axis->GetTitle(), "leading p_{T} (GeV/c)") == 0)
24     axis->SetRangeUser(0, (gEnergy == 900) ? 10 : 25);
25
26   if (strcmp(axis->GetTitle(), "multiplicity") == 0)
27     axis->SetRangeUser(0, 10);
28 }
29
30 void SetRanges(TH1* hist)
31 {
32   SetRanges(hist->GetXaxis());
33   SetRanges(hist->GetYaxis());
34   SetRanges(hist->GetZaxis());
35 }
36
37 void Prepare1DPlot(TH1* hist)
38 {
39   if (!hist)
40     return;
41
42   hist->SetLineWidth(2);
43   hist->SetStats(kFALSE);
44
45   hist->GetXaxis()->SetLabelOffset(0.02);
46   hist->GetXaxis()->SetTitleOffset(1.3);
47   hist->GetYaxis()->SetTitleOffset(1.3);
48
49   SetRanges(hist);
50 }
51
52 TH1* GetSystematicUncertainty(TH1* corr, TH1* trackHist)
53 {
54   if (!trackHist)
55   {
56     systError = (TH1*) corr->Clone("systError");
57     systError->Reset();
58   }
59   else  // for dphi evaluation
60     systError = new TH1F("systError", "", 100, 0, 50);
61   
62   Float_t constantUnc = 0;
63   
64   // particle composition
65   constantUnc += 0.8 ** 2;
66   
67   // tpc efficiency
68   if (gEnergy == 900 && gpTMin < 1.0)
69     constantUnc += 1.0 ** 2;
70   else if (gEnergy == 900 && gpTMin < 1.5)
71     constantUnc += 0.5 ** 2;
72   if (gEnergy == 7000 && gpTMin < 1.0)
73     constantUnc += 1.0 ** 2;
74   else if (gEnergy == 7000 && gpTMin < 1.5)
75     constantUnc += 0.6 ** 2;
76   
77   // track cuts
78   if (gEnergy == 900 && gpTMin < 1.0)
79     constantUnc += 2.5 ** 2;
80   else if (gEnergy == 900 && gpTMin < 1.5)
81     constantUnc += 2.0 ** 2;
82   if (gEnergy == 7000)
83     constantUnc += 3.0 ** 2;
84
85   // difference corrected with pythia and phojet
86   if (gEnergy == 900 && gpTMin < 1.0)
87     constantUnc += 0.6 ** 2;
88   else if (gEnergy == 900 && gpTMin < 1.5)
89     constantUnc += 0.8 ** 2;
90   
91   if (gEnergy == 7000 && gpTMin < 1.0)
92   {
93     if (gUEHist == 0)
94       constantUnc += 0.6 ** 2;
95     if (gUEHist == 1)
96       constantUnc += 0.8 ** 2;
97     if (gUEHist == 2)
98       constantUnc += 1.0 ** 2;
99   }
100   else if (gEnergy == 7000 && gpTMin < 1.5)
101     constantUnc += 1.0 ** 2;
102     
103   for (Int_t bin=1; bin<=systError->GetNbinsX(); bin++)
104     systError->SetBinContent(bin, constantUnc);
105
106   // mis id bias
107   if (gUEHist == 0 || gUEHist == 2)
108     systError->Fill(0.75, 4.0 ** 2);
109   if (gUEHist == 1)
110     systError->Fill(0.75, 5.0 ** 2);
111
112   if (gEnergy == 900)
113   {
114     if (gpTMin < 1.0)
115       systError->Fill(1.25, 1.0 ** 2);
116     else if (gpTMin < 1.5)
117       systError->Fill(1.25, 2.0 ** 2);
118   }
119   
120   // non-closure in MC
121   if (gEnergy == 900)
122     for (Int_t bin=1; bin<=systError->GetNbinsX(); bin++)
123       systError->Fill(systError->GetXaxis()->GetBinCenter(bin), 1.0 ** 2);
124       
125   if (gEnergy == 7000)
126   {
127     if (gUEHist == 0 && gUEHist == 1)
128       systError->Fill(0.75, 2.0 ** 2);
129     if (gUEHist == 2)
130       systError->Fill(0.75, 1.2 ** 2);
131   }
132   
133   // vertex efficiency
134   systError->Fill(0.75, 1.0 ** 2);
135
136   // strangeness
137   for (Int_t bin=1; bin<=systError->GetNbinsX(); bin++)
138   {
139     if (gEnergy == 900)
140       systError->Fill(systError->GetXaxis()->GetBinCenter(bin), 0.5 ** 2);
141     if (gEnergy == 7000 && systError->GetXaxis()->GetBinCenter(bin) < 1.5)
142       systError->Fill(systError->GetXaxis()->GetBinCenter(bin), 2.0 ** 2);
143     else if (gEnergy == 7000)
144       systError->Fill(systError->GetXaxis()->GetBinCenter(bin), 1.0 ** 2);
145   }  
146     
147   for (Int_t bin=1; bin<=systError->GetNbinsX(); bin++)
148     systError->SetBinContent(bin, TMath::Sqrt(systError->GetBinContent(bin)));
149   
150   if (trackHist)
151   {
152     //new TCanvas; trackHist->Draw();
153     //new TCanvas; systError->DrawCopy("");
154     
155     Float_t uncFlat = 0;
156     for (Int_t i=1; i<=trackHist->GetNbinsX(); i++)
157       uncFlat += trackHist->GetBinContent(i) * systError->GetBinContent(systError->FindBin(trackHist->GetBinCenter(i)));
158     if (trackHist->Integral() > 0)
159       uncFlat /= trackHist->Integral();
160     
161     systError = (TH1F*) corr->Clone("systError");
162     systError->Reset();
163   
164     for (Int_t i=1; i<=systError->GetNbinsX(); i++)
165       systError->SetBinContent(i, uncFlat);
166       
167     //new TCanvas; systError->DrawCopy("");
168   }
169   
170   systError->SetFillColor(kGray);
171   systError->SetFillStyle(1001);
172   systError->SetMarkerStyle(0);
173   systError->SetLineColor(0);
174   
175   return systError;
176 }
177
178 void DrawRatio(TH1* corr, TH1* mc, const char* name, TH1* syst = 0)
179 {
180   mc->SetLineColor(2);
181
182   TCanvas* canvas3 = new TCanvas(name, name, 600, 600);
183   canvas3->Range(0, 0, 1, 1);
184
185   TPad* pad1 = new TPad(Form("%s_1", name), "", 0, 0.5, 0.98, 0.98);
186   pad1->Draw();
187
188   TPad* pad2 = new TPad(Form("%s_2", name), "", 0, 0.02, 0.98, 0.5);
189   pad2->Draw();
190
191   pad1->SetRightMargin(0.01);
192   pad2->SetRightMargin(0.01);
193   pad1->SetTopMargin(0.05);
194   pad1->SetLeftMargin(0.13);
195   pad2->SetLeftMargin(0.13);
196   pad2->SetBottomMargin(0.22);
197   
198   // no border between them
199   pad1->SetBottomMargin(0);
200   pad2->SetTopMargin(0);
201
202   pad1->cd();
203   pad1->SetGridx();
204   pad1->SetGridy();
205
206   if (gUEHist != 2)
207     TLegend* legend = new TLegend(0.15, 0.65, 0.55, 0.90);
208   else
209     TLegend* legend = new TLegend(0.55, 0.65, 0.95, 0.90);
210
211   legend->SetFillColor(0);
212   legend->AddEntry(corr, "Corrected");
213   legend->AddEntry(mc, "MC prediction");
214   legend->SetTextSize(0.08);
215
216   Prepare1DPlot(corr);
217
218   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);
219   dummy->SetYTitle(corr->GetYaxis()->GetTitle());
220   
221   //dummy = new TH2F("dummy", "", 100, corr->GetXaxis()->GetBinLowEdge(1), corr->GetXaxis()->GetBinUpEdge(corr->GetNbinsX()), 1000, 13.5, 20.5);
222   //dummy->SetYTitle("1/N_{trig} dN/d#Delta#phi");
223   
224   dummy->SetStats(kFALSE);
225   dummy->SetXTitle(corr->GetXaxis()->GetTitle());
226   dummy->GetYaxis()->SetTitleOffset(1);
227   Prepare1DPlot(dummy);
228
229   dummy->GetXaxis()->SetLabelSize(0.08);
230   dummy->GetYaxis()->SetLabelSize(0.08);
231   dummy->GetXaxis()->SetTitleSize(0.08);
232   dummy->GetYaxis()->SetTitleSize(0.08);
233   dummy->GetYaxis()->SetTitleOffset(0.8);
234   
235   if (gForceRange > 0)
236     dummy->GetYaxis()->SetRangeUser(0, gForceRange);
237   
238   dummy->DrawCopy();
239   
240   if (0 && gUEHist != 2)
241   {
242     const char* regionStr[] = { "Toward Region", "Away Region", "Transverse Region" };
243     latex = new TLatex(0.65, 0.1, regionStr[gRegion]);
244     latex->SetTextSize(0.075);
245     latex->SetNDC();
246     latex->Draw();
247   }
248   
249   if (syst)
250   {
251     systError = (TH1*) syst->Clone("corrSystError");
252     for (Int_t bin=1; bin<=systError->GetNbinsX(); bin++)
253     {
254       systError->SetBinError(bin, corr->GetBinContent(bin) * syst->GetBinContent(bin) / 100);
255       systError->SetBinContent(bin, corr->GetBinContent(bin));
256     }
257     
258     systError->Draw("E2 ][ SAME");
259   }
260   
261   corr->Draw("SAME");
262   mc->Draw("SAME");
263   
264   if (strlen(gText) > 0)
265   {
266     latex = new TLatex(0.2, 0.2, gText);
267     latex->SetNDC();
268     latex->SetTextSize(0.06);
269     latex->Draw();
270   }
271
272   //legend->Draw();
273
274   pad2->cd();
275   //pad2->SetBottomMargin(0.15);
276   //pad2->SetGridx();
277   //pad2->SetGridy();
278
279   TH1* ratio = (TH1*) mc->Clone("ratio");
280   ratio->Divide(corr);
281
282   Float_t minR = TMath::Min(0.91, ratio->GetMinimum() * 0.95);
283   Float_t maxR = TMath::Max(1.09, ratio->GetMaximum() * 1.05);
284   
285   minR = 0.8;
286   maxR = 1.2;
287
288   TH1F dummy3("dummy3", ";;Ratio: MC / corr", 100, corr->GetXaxis()->GetBinLowEdge(1), corr->GetXaxis()->GetBinUpEdge(corr->GetNbinsX()));
289   dummy3.SetXTitle(corr->GetXaxis()->GetTitle());
290   Prepare1DPlot(&dummy3);
291   dummy3.SetStats(kFALSE);
292   for (Int_t i=1; i<=100; ++i)
293         dummy3.SetBinContent(i, 1);
294   dummy3.GetYaxis()->SetRangeUser(minR, maxR);
295   dummy3.SetLineWidth(2);
296   dummy3.GetXaxis()->SetLabelSize(0.08);
297   dummy3.GetYaxis()->SetLabelSize(0.08);
298   dummy3.GetXaxis()->SetTitleSize(0.08);
299   dummy3.GetYaxis()->SetTitleSize(0.08);
300   dummy3.GetYaxis()->SetTitleOffset(0.8);
301   dummy3.DrawCopy();
302   
303   if (syst)
304   {
305     // for the ratio add in quadrature
306     for (Int_t bin=1; bin<=syst->GetNbinsX(); bin++)
307     {
308       if (corr->GetBinError(bin) > 0)
309         syst->SetBinError(bin, TMath::Sqrt(TMath::Power(syst->GetBinContent(bin) / 100, 2) + TMath::Power(corr->GetBinError(bin) / corr->GetBinContent(bin), 2)));
310       else
311         syst->SetBinError(bin, 0);
312       syst->SetBinContent(bin, 1);
313     }
314     
315     syst->Draw("E2 ][ SAME");
316     dummy3.DrawCopy("SAME");
317   }
318
319   ratio->Draw("SAME");
320   
321   ratio->Fit("pol0", "N");
322
323   canvas3->Modified();
324   //canvas3->SaveAs(Form("%s.eps", canvas3->GetTitle()));
325 }
326
327 void loadlibs()
328 {
329   gSystem->Load("libANALYSIS");
330   gSystem->Load("libANALYSISalice");
331   gSystem->Load("libCORRFW");
332   gSystem->Load("libPWGTools");
333   gSystem->Load("libPWGCFCorrelationsBase");
334 }
335
336 const char* lastFileName = 0;
337 void* cacheSameEvent = 0;
338 void* cacheMixedEvent = 0;
339
340 void* GetUEHistogram(const char* fileName, TList** listRef = 0, Bool_t mixed = kFALSE, const char* tag = "")
341 {
342   if (!lastFileName || strcmp(lastFileName, fileName) != 0)
343   {
344     lastFileName = fileName;
345     file = TFile::Open(fileName);
346     if (!file)
347       return 0;
348     
349     list = (TList*) gFile->Get("PWG4_LeadingTrackUE/histosLeadingTrackUE");
350     if (!list)
351       list = (TList*) gFile->Get(Form("PWG4_PhiCorrelations/histosPhiCorrelations%s", tag));
352     if (!list)
353       list = (TList*) gFile->Get("PWG4_PhiCorrelations/histosPhiCorrelations_Syst");
354       
355     if (!list)
356       return 0;
357       
358     if (listRef)
359       *listRef = list;
360       
361     cacheMixedEvent = list->FindObject("AliUEHistogramsMixed");
362     cacheSameEvent = list->FindObject("AliUEHistogramsSame");
363
364     if (mixed)
365       return cacheMixedEvent;
366     
367     if (list->FindObject("AliUEHistograms"))
368       return list->FindObject("AliUEHistograms");
369       
370     return cacheSameEvent;
371   }
372   else
373   {
374     Printf("GetUEHistogram --> Using cache for %s", fileName);
375     
376     if (mixed)
377       return cacheMixedEvent;
378     else
379       return cacheSameEvent;
380   }
381 }
382
383 void CompareBias(const char* mcFile = "PWG4_JetTasksOutput.root", Int_t region, Int_t ueHist)
384 {
385   loadlibs();
386
387   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(mcFile);
388   SetupRanges(h);
389   
390   const char* axis = "z";
391   Float_t ptLeadMin = 0;
392   Float_t ptLeadMax = -1;
393   
394   if (ueHist == 2)
395   {
396     ptLeadMin = 0.51 + 0;
397     ptLeadMax = 1.99 + 0;
398     axis = "y";
399   }
400   
401   biasFromData = (TH1*) h->GetUEHist(ueHist)->GetBias(AliUEHist::kCFStepBiasStudy, AliUEHist::kCFStepReconstructed, region, axis, ptLeadMin, ptLeadMax)->Clone("biasFromData");
402   biasFromData2 = (TH1*) h->GetUEHist(ueHist)->GetBias(AliUEHist::kCFStepBiasStudy2, AliUEHist::kCFStepReconstructed, region, axis, ptLeadMin, ptLeadMax)->Clone("biasFromData2");
403   //biasFromData = (TH1*) h->GetUEHist(ueHist)->GetBias(AliUEHist::kCFStepReconstructed, AliUEHist::kCFStepRealLeading, region, axis)->Clone("biasFromData");
404   biasFromMC   = (TH1*) h->GetUEHist(ueHist)->GetBias(AliUEHist::kCFStepReconstructed, AliUEHist::kCFStepTracked, region, axis, ptLeadMin, ptLeadMax)->Clone("biasFromMC");
405   //biasFromMC   = (TH1*) h->GetUEHist(ueHist)->GetBias(AliUEHist::kCFStepReconstructed, AliUEHist::kCFStepRealLeading, region, axis)->Clone("biasFromMC");
406   
407 /*  biasFromData->Draw();
408   biasFromMC->SetLineColor(2);
409   biasFromMC->Draw("SAME");
410   return;*/
411   
412   DrawRatio(biasFromData, biasFromMC, "bias: data vs MC");
413   DrawRatio(biasFromData, biasFromData2, "bias: data vs data two step");
414 }
415   
416 void CompareBiasWithData(const char* mcFile = "PWG4_JetTasksOutput.root", const char* dataFile = "esd.root", Int_t region = 2)
417 {
418   loadlibs();
419
420   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(mcFile);
421   SetupRanges(h);
422   
423   biasFromMC   = (TH1*) h->GetNumberDensitypT()->GetBias(AliUEHist::kCFStepReconstructed, AliUEHist::kCFStepTracked, region, "z")->Clone("biasFromMC");
424   
425   AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(dataFile);
426   SetupRanges(h2);
427   
428   biasFromData = (TH1*) h2->GetNumberDensitypT()->GetBias(AliUEHist::kCFStepBiasStudy, AliUEHist::kCFStepReconstructed, region, "z")->Clone("biasFromData");
429   biasFromData2 = (TH1*) h2->GetNumberDensitypT()->GetBias(AliUEHist::kCFStepBiasStudy2, AliUEHist::kCFStepReconstructed, region, "z")->Clone("biasFromData2");
430   
431   DrawRatio(biasFromData, biasFromMC, "bias: data vs MC");
432   DrawRatio(biasFromData, biasFromData2, "bias: data vs data two step");
433 }
434
435 Int_t count = 0;
436
437 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)
438 {
439   loadlibs();
440   
441   if (!gCache || !gFirst)
442   {
443     AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName1);
444     AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(fileName2);
445   }
446   
447   if (gCache)
448   {
449     if (!gFirst)
450     {
451       gFirst = h;
452       gSecond = h2;
453     }
454     else
455     {
456       AliUEHistograms* h = (AliUEHistograms*) gFirst;
457       AliUEHistograms* h2 = (AliUEHistograms*) gSecond;
458     }
459   }
460   
461   SetupRanges(h);
462   SetupRanges(h2);
463   
464   TH1* hist1 = h->GetUEHist(id)->GetUEHist(step1, region, ptLeadMin, ptLeadMax, centralityBegin, centralityEnd);
465   //TH1* hist1 = h->GetUEHist(id)->GetUEHist(step1, region, ptLeadMin, ptLeadMax);
466   TH1* hist2 = h2->GetUEHist(id)->GetUEHist(step2, region, ptLeadMin, ptLeadMax, centralityBegin, centralityEnd);
467
468   //hist1->Scale(1.0 / hist1->Integral());
469   //hist2->Scale(1.0 / hist2->Integral());
470
471   TH1* trackHist = 0;
472   if (id == 2)
473   {
474     trackHist = h->GetUEHist(id)->GetTrackHist(region)->ShowProjection(2, 0);
475     // only keep bins under consideration
476     for (Int_t bin=1; bin<=trackHist->GetNbinsX(); bin++)
477       if (bin < trackHist->FindBin(ptLeadMin) || bin > trackHist->FindBin(ptLeadMax))
478         trackHist->SetBinContent(bin, 0);
479   }
480
481   // systematic uncertainty
482   TH1* syst = 0; //GetSystematicUncertainty(hist1, trackHist);
483   
484   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);
485 }  
486
487 void CompareEventHist(const char* fileName1, const char* fileName2, Int_t id, Int_t step, Int_t var)
488 {
489   loadlibs();
490
491   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName1);
492   SetupRanges(h);
493
494   AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(fileName2);
495   SetupRanges(h2);
496
497   TH1* hist1 = h->GetUEHist(id)->GetEventHist()->ShowProjection(var, step);
498   TH1* hist2 = h2->GetUEHist(id)->GetEventHist()->ShowProjection(var, step);
499   
500 //   hist1 = hist1->Rebin(hist2->GetNbinsX(), "new", hist2->GetXaxis()->GetXbins()->GetArray());
501   
502 //   hist2 = hist2->Rebin(hist1->GetNbinsX(), "new", hist1->GetXaxis()->GetXbins()->GetArray());
503  
504   DrawRatio(hist1, hist2, "compare");
505 }
506
507 void CompareEventHist(const char* fileName1, const char* fileName2, Int_t id, Int_t step1, Int_t step2, Int_t var)
508 {
509   loadlibs();
510
511   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName1);
512   SetupRanges(h);
513
514   AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(fileName2);
515   SetupRanges(h2);
516   
517 //   h->GetUEHist(id)->GetEventHist()->GetGrid(step1)->GetGrid()->GetAxis(1)->SetRange(1, 5);
518 //   h2->GetUEHist(id)->GetEventHist()->GetGrid(step2)->GetGrid()->GetAxis(1)->SetRange(1, 5);
519   
520   TH1* hist1 = h->GetUEHist(id)->GetEventHist()->ShowProjection(var, step1);
521   TH1* hist2 = h2->GetUEHist(id)->GetEventHist()->ShowProjection(var, step2);
522  
523   DrawRatio(hist1, hist2, "compare");
524 }
525
526 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)
527 {
528   // fileName1 is labelled Corrected in the plot
529
530   loadlibs();
531
532   gUEHist = id;
533   gRegion = region;
534   Compare(fileName1, fileName2, id, step, step, region, ptLeadMin, ptLeadMax);
535 }
536
537 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)
538 {
539   // fileName1 is labelled Corrected in the plot
540
541   loadlibs();
542
543   gUEHist = id;
544   gRegion = region;
545   Compare(fileName1, fileName2, id, step1, step2, region, ptLeadMin, ptLeadMax, centralityBegin, centralityEnd);
546 }
547
548 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)
549 {
550   loadlibs();
551
552   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName, 0, mixed);
553   SetupRanges(h);
554
555   new TCanvas;
556   return h->GetUEHist(id)->GetUEHist(step, region, ptLeadMin, ptLeadMax, centralityBegin, centralityEnd, twoD)->DrawCopy();
557 }
558
559 void DrawProjectionsRidge(const char* fileName, const char* fileNamePbPbMix = 0)
560 {
561   if (!fileNamePbPbMix)
562     fileNamePbPbMix = fileName;
563   
564   gpTMin = 1.01;
565   gpTMax = 2.99;
566   
567   loadlibs();
568   
569   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
570   hMixed = (AliUEHistograms*) GetUEHistogram(fileNamePbPbMix, 0, kTRUE);
571   
572   SetupRanges(h);
573   SetupRanges(hMixed);
574
575   TH1* hist1 = 0;
576   GetDistAndFlow(h, hMixed, &hist1,  0, 8, 0,  100, 3.01, 3.99, 1, kTRUE, 0, kTRUE); 
577   
578 //   ((TH2*) hist1)->Rebin2D(2, 2); hist1->Scale(0.25);
579
580 //   NormalizeToBinWidth(hist1);
581   
582   proj1y = ((TH2*) hist1)->ProjectionY("proj1y", hist1->GetXaxis()->FindBin(-0.5), hist1->GetXaxis()->FindBin(0.5));
583   proj1x = ((TH2*) hist1)->ProjectionX("proj1x", hist1->GetYaxis()->FindBin(-1.79), hist1->GetYaxis()->FindBin(1.79));
584   
585   proj1y->Scale(1.0 / (hist1->GetXaxis()->FindBin(0.5) - hist1->GetXaxis()->FindBin(-0.5) + 1));
586   proj1x->Scale(1.0 / (hist1->GetYaxis()->FindBin(1.79) - hist1->GetYaxis()->FindBin(-1.79) + 1));
587   
588   proj1y->GetXaxis()->SetTitleOffset(1);
589   proj1x->GetXaxis()->SetTitleOffset(1);
590   
591   Float_t zyam = proj1x->GetBinContent(proj1x->GetXaxis()->FindBin(TMath::Pi()/2));
592   proj1x->Add(new TF1("func", "-1", -100, 100), zyam);
593   proj1y->Add(new TF1("func", "-1", -100, 100), zyam);
594   
595   new TCanvas("c", "c", 800, 800);
596   gPad->SetLeftMargin(0.15);
597   hist1->SetTitle("");
598   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
599   hist1->GetXaxis()->SetTitleOffset(1.5);
600   hist1->GetYaxis()->SetTitleOffset(2);
601   hist1->SetStats(kFALSE);
602   hist1->DrawCopy("SURF1");
603   
604 //   new TCanvas; proj1y->Draw(); new TCanvas; proj1x->Draw();  return;
605   
606   TH1* hist2 = 0;
607   GetDistAndFlow(h, hMixed, &hist2,  0, 8, 40,  100, 4.01, 5.99, 1, kTRUE, 0, kTRUE); 
608   
609 //   ((TH2*) hist2)->Rebin2D(2, 2); hist2->Scale(0.25);
610 //   NormalizeToBinWidth(hist2);
611   
612   proj2y = ((TH2*) hist2)->ProjectionY("proj2y", hist1->GetXaxis()->FindBin(-0.5), hist1->GetXaxis()->FindBin(0.5));
613   proj2x = ((TH2*) hist2)->ProjectionX("proj2x", hist1->GetYaxis()->FindBin(-1.79), hist1->GetYaxis()->FindBin(1.79));
614
615   proj2y->Scale(1.0 / (hist1->GetXaxis()->FindBin(0.5) - hist1->GetXaxis()->FindBin(-0.5) + 1));
616   proj2x->Scale(1.0 / (hist1->GetYaxis()->FindBin(1.79) - hist1->GetYaxis()->FindBin(-1.79) + 1));
617  
618   zyam = proj2x->GetBinContent(proj2x->GetXaxis()->FindBin(TMath::Pi()/2));
619   proj2x->Add(new TF1("func", "-1", -100, 100), zyam);
620   proj2y->Add(new TF1("func", "-1", -100, 100), zyam);
621
622   proj2y->SetLineColor(2); proj2x->SetLineColor(2);
623   
624   new TCanvas; proj1y->Draw(); proj2y->Draw("SAME");
625   new TCanvas; proj1x->Draw(); proj2x->Draw("SAME");
626   
627   new TCanvas("c2", "c2", 800, 800);
628   gPad->SetLeftMargin(0.15);
629   hist2->SetTitle("");
630   hist2->GetYaxis()->SetRangeUser(-1.79, 1.79);
631   hist2->GetXaxis()->SetTitleOffset(1.5);
632   hist2->GetYaxis()->SetTitleOffset(2);
633   hist2->SetStats(kFALSE);
634   hist2->DrawCopy("SURF1");
635 }
636
637 void DrawExample(const char* fileName, const char* fileNamePbPbMix = 0)
638 {
639   if (!fileNamePbPbMix)
640     fileNamePbPbMix = fileName;
641   
642   gpTMin = 1.01;
643   gpTMax = 1.99;
644   
645   loadlibs();
646   
647   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
648   hMixed = (AliUEHistograms*) GetUEHistogram(fileNamePbPbMix, 0, kTRUE);
649   
650   SetupRanges(h);
651   SetupRanges(hMixed);
652
653   TH1* hist1 = 0;
654   GetDistAndFlow(h, hMixed, &hist1,  0, 8, 0,  40, 1.01, 1.99, 1, kTRUE, 0, kTRUE); 
655   
656   ((TH2*) hist1)->Rebin2D(2, 2);
657   hist1->Scale(0.25);
658
659 //   NormalizeToBinWidth(hist1);
660   
661   new TCanvas("c", "c", 800, 800);
662   gPad->SetLeftMargin(0.15);
663   hist1->SetTitle("");
664   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
665   hist1->GetXaxis()->SetTitleOffset(1.5);
666   hist1->GetYaxis()->SetTitleOffset(2);
667   hist1->SetStats(kFALSE);
668   hist1->DrawCopy("SURF1");
669   
670   TH1* hist2 = 0;
671   GetDistAndFlow(h, hMixed, &hist2,  0, 8, 40,  100, 1.01, 1.99, 1, kTRUE, 0, kTRUE); 
672   
673   ((TH2*) hist2)->Rebin2D(2, 2); hist2->Scale(0.25);
674
675 //   NormalizeToBinWidth(hist1);
676   
677   new TCanvas("c2", "c2", 800, 800);
678   gPad->SetLeftMargin(0.15);
679   hist2->SetTitle("");
680   hist2->GetYaxis()->SetRangeUser(-1.79, 1.79);
681   hist2->GetXaxis()->SetTitleOffset(1.5);
682   hist2->GetYaxis()->SetTitleOffset(2);
683   hist2->SetStats(kFALSE);
684   hist2->DrawCopy("SURF1");
685   
686   
687
688   return;
689   
690   hist2 = hist1;
691   /*
692   GetDistAndFlow(h, hMixed, &hist1,  0, 0, 0,  10, 2.01, 3.99, 1, kTRUE, 0, kTRUE); 
693
694   ((TH2*) hist1)->Rebin2D(2, 2);
695 //   NormalizeToBinWidth(hist1);
696
697   new TCanvas("c2", "c2", 800, 800);
698   gPad->SetLeftMargin(0.15);
699   hist1->SetTitle("");
700   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
701   hist1->GetXaxis()->SetTitleOffset(1.5);
702   hist1->GetYaxis()->SetTitleOffset(2);
703   hist1->SetStats(kFALSE);
704   hist1->DrawCopy("SURF1");  
705   
706   hist1->Divide(hist2);
707
708   new TCanvas("c5", "c5", 800, 800);
709   gPad->SetLeftMargin(0.15);
710   hist1->SetTitle("");
711   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
712   hist1->GetXaxis()->SetTitleOffset(1.5);
713   hist1->GetYaxis()->SetTitleOffset(2);
714   hist1->SetStats(kFALSE);
715   hist1->DrawCopy("SURF1");    
716   
717   return;
718
719   GetDistAndFlow(h, hMixed, &hist1,  0, 6, 0,  10, 2.01, 3.99, 1, kTRUE, 0, kTRUE, 6); 
720
721   ((TH2*) hist1)->Rebin2D(2, 2);
722 //   NormalizeToBinWidth(hist1);
723
724   new TCanvas("c3", "c3", 800, 800);
725   gPad->SetLeftMargin(0.15);
726   hist1->SetTitle("");
727   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
728   hist1->GetXaxis()->SetTitleOffset(1.5);
729   hist1->GetYaxis()->SetTitleOffset(2);
730   hist1->SetStats(kFALSE);
731   hist1->DrawCopy("SURF1");  
732   
733 //   return;
734   
735 //   TH1* hist1 = 0;
736 //   GetDistAndFlow(h, hMixed, &hist1,  0, 4, 0,  10, 2.01, 3.99, 1, kTRUE, 0, kTRUE, 6); 
737 //   
738 //   ((TH2*) hist1)->Rebin2D(2, 2);
739 // //   hist1->Scale(0.25);
740 // 
741 // //   NormalizeToBinWidth(hist1);
742 //   
743 //   new TCanvas("c1b", "c1b", 800, 800);
744 //   gPad->SetLeftMargin(0.15);
745 //   hist1->SetTitle("");
746 //   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
747 //   hist1->GetXaxis()->SetTitleOffset(1.5);
748 //   hist1->GetYaxis()->SetTitleOffset(2);
749 //   hist1->SetStats(kFALSE);
750 //   hist1->DrawCopy("SURF1");
751 //   hist2 = hist1;
752   
753 //   return;
754   
755 //   GetDistAndFlow(h, 0, &hist1,  0, 8, 0,  10, 2.01, 3.99, 1, kTRUE, 0, kTRUE); 
756 // 
757 //   NormalizeToBinWidth(hist1);
758 // //   
759 //   for (Int_t i=1; i<=hist1->GetNbinsX(); ++i)
760 //   {
761 //     for (Int_t j=1; j<=hist1->GetNbinsY(); ++j)
762 //     {
763 //       Float_t factor = 1.0 / (2.0 - TMath::Abs(hist1->GetYaxis()->GetBinCenter(j)));
764 //       hist1->SetBinContent(i, j, hist1->GetBinContent(i, j) * factor);
765 //       hist1->SetBinError(i, j, hist1->GetBinError(i, j) * factor);
766 //     }
767 //   }
768
769 /*  new TCanvas("c4", "c4", 800, 800);
770   gPad->SetLeftMargin(0.15);
771   hist1->SetTitle("");
772   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
773   hist1->GetXaxis()->SetTitleOffset(1.5);
774   hist1->GetYaxis()->SetTitleOffset(2);
775   hist1->SetStats(kFALSE);
776   hist1->DrawCopy("SURF1");  */
777   
778   AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram("corrected.root");
779   AliUEHistograms* h2Mixed = (AliUEHistograms*) GetUEHistogram("corrected.root", 0, kTRUE);
780   SetupRanges(h2);
781   SetupRanges(h2Mixed);
782  
783   GetDistAndFlow(h2, h2Mixed, &hist1,  0, 8, 0,  10, 2.01, 3.99, 1, kTRUE, 0, kTRUE); 
784   ((TH2*) hist1)->Rebin2D(2, 2);
785
786   new TCanvas("c4", "c4", 800, 800);
787   gPad->SetLeftMargin(0.15);
788   hist1->SetTitle("");
789   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
790   hist1->GetXaxis()->SetTitleOffset(1.5);
791   hist1->GetYaxis()->SetTitleOffset(2);
792   hist1->SetStats(kFALSE);
793   hist1->DrawCopy("SURF1");  
794   
795   hist1->Divide(hist2);
796
797   new TCanvas("c5", "c5", 800, 800);
798   gPad->SetLeftMargin(0.15);
799   hist1->SetTitle("");
800   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
801   hist1->GetXaxis()->SetTitleOffset(1.5);
802   hist1->GetYaxis()->SetTitleOffset(2);
803   hist1->SetStats(kFALSE);
804   hist1->DrawCopy("SURF1");  
805
806 //   hist1->Divide(histMixed);
807   
808 //   NormalizeToBinWidth(hist1);
809 // //   
810 //   for (Int_t i=1; i<=hist1->GetNbinsX(); ++i)
811 //   {
812 //     for (Int_t j=1; j<=hist1->GetNbinsY(); ++j)
813 //     {
814 //       Float_t factor = 1.0 / (2.0 - TMath::Abs(hist1->GetYaxis()->GetBinCenter(j)));
815 //       hist1->SetBinContent(i, j, hist1->GetBinContent(i, j) * factor);
816 //       hist1->SetBinError(i, j
817 //   }, hist1->GetBinError(i, j) * factor);
818 //     }
819
820 //   new TCanvas("c6", "c6", 800, 800);
821 //   gPad->SetLeftMargin(0.15);
822 //   hist1->SetTitle("");
823 //   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
824 //   hist1->GetXaxis()->SetTitleOffset(1.5);
825 //   hist1->GetYaxis()->SetTitleOffset(2);
826 //   hist1->SetStats(kFALSE);
827 //   hist1->DrawCopy("SURF1");  
828   
829   return;
830   
831   GetSumOfRatios(h, hMixed, &hist1,  6, 60,  90, 8.01, 9.99, kTRUE); 
832   new TCanvas("c2", "c2", 800, 800);
833   gPad->SetLeftMargin(0.15);
834   hist1->SetTitle("");
835   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
836   hist1->GetXaxis()->SetTitleOffset(1.5);
837   hist1->GetYaxis()->SetTitleOffset(2);
838   hist1->SetStats(kFALSE);
839   hist1->Draw("SURF1");
840
841   return;
842   
843   latex = new TLatex(0.82, 0.74, "ALICE performance");
844   latex->SetTextSize(0.02);
845   latex->SetTextAlign(22);
846   latex->SetNDC();
847   latex->Draw();
848   latex = new TLatex(0.82, 0.72, "Pb-Pb 2.76 TeV");
849   latex->SetTextSize(0.02);
850   latex->SetTextAlign(22);
851   latex->SetNDC();
852   latex->Draw();
853   latex = new TLatex(0.82, 0.70, "28.09.11");
854   latex->SetTextSize(0.02);
855   latex->SetTextAlign(22);
856   latex->SetNDC();
857   latex->Draw();
858
859   DrawALICELogo(0.75, 0.75, 0.9, 0.9);
860 }
861
862 void DrawExample2(const char* fileName)
863 {
864   loadlibs();
865   
866   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
867   hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
868   
869   gpTMin = 0.51;
870   gpTMax = 0.99;
871   SetupRanges(h);
872   SetupRanges(hMixed);
873
874   TH1* hist1 = 0;
875   GetSumOfRatios(h, hMixed, &hist1,  8, 0,  5, 0.51, 0.99);
876   
877   new TCanvas("c", "c", 800, 800);
878   gPad->SetLeftMargin(0.15);
879   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
880   hist1->GetXaxis()->SetTitleOffset(1.5);
881   hist1->GetYaxis()->SetTitleOffset(2);
882   hist1->SetStats(kFALSE);
883   hist1->DrawCopy("SURF1"); 
884 }  
885
886 void CompareZVtxWeighting(const char* fileName, Int_t step = 8)
887 {
888   gpTMin = 1.01;
889   gpTMax = 1.99;
890   
891   loadlibs();
892   
893   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
894   hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
895   
896   SetupRanges(h);
897   SetupRanges(hMixed);
898   
899   TH1* hist1 = 0;
900   GetDistAndFlow(h, hMixed, &hist1,  0, step, 0,  10, 5.01, 9.99, 1, kTRUE, 0, kTRUE); 
901   hist1->Scale(1.0 / 0.972222);
902   
903   TH1* hist2 = 0;
904   GetSumOfRatios(h, hMixed, &hist2,  step, 0,  10, 5.01, 9.99, kTRUE);
905   
906   c = new TCanvas("c", "c", 1200, 400);
907   c->Divide(3, 1);
908   
909   c->cd(1); hist1->DrawCopy("SURF1");
910   c->cd(2); hist2->DrawCopy("SURF1");
911   
912   hist1->SetStats(0);
913   hist1->Divide(hist2);
914   
915   c->cd(3); hist1->DrawCopy("COLZ");
916 }
917
918 void DrawSameMixed(const char* fileName, const char* fileNamePbPbMix = 0, Int_t step = 6)
919 {
920   if (!fileNamePbPbMix)
921     fileNamePbPbMix = fileName;
922   
923   gpTMin = 1.01;
924   gpTMax = 1.99;
925   
926   loadlibs();
927   
928   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
929   hMixed = (AliUEHistograms*) GetUEHistogram(fileNamePbPbMix, 0, kTRUE);
930   
931   SetupRanges(h);
932   SetupRanges(hMixed);
933   
934   TH1* hist1 = 0;
935   GetDistAndFlow(h, 0, &hist1,  0, step, 0,  80, 2.01, 3.99, 1, kTRUE, 0, kTRUE); 
936   
937 //   ((TH2*) hist1)->Rebin2D(2, 2);
938 //   hist1->Scale(0.25);
939
940   NormalizeToBinWidth(hist1);
941   
942 //   for (Int_t i=1; i<=hist1->GetNbinsX(); ++i)
943 //   {
944 //     for (Int_t j=1; j<=hist1->GetNbinsY(); ++j)
945 //     {
946 //       Float_t factor = 1.0 / (2.0 - TMath::Abs(hist1->GetYaxis()->GetBinCenter(j) / 0.9));
947 //       hist1->SetBinContent(i, j, hist1->GetBinContent(i, j) * factor);
948 //       hist1->SetBinError(i, j, hist1->GetBinError(i, j) * factor);
949 //     }
950 //   }
951
952   c = new TCanvas("c", "c", 1600, 800);
953   c->Divide(2, 1);
954   c->cd(1);
955   gPad->SetLeftMargin(0.15);
956   hist1->SetTitle("");
957   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
958   hist1->GetZaxis()->SetTitleOffset(1.8);
959   hist1->GetXaxis()->SetTitleOffset(1.5);
960   hist1->GetYaxis()->SetTitleOffset(2);
961   hist1->GetZaxis()->SetTitle("same event pairs (a.u.)");
962   hist1->SetStats(kFALSE);
963   hist1->DrawCopy("SURF1");
964   
965   DrawALICELogo(kFALSE, 0.2, 0.7, 0.4, 0.9);
966   
967   hist2 = hist1;
968   
969   GetDistAndFlow(hMixed, 0, &hist1,  0, step, 0,  80, 2.01, 3.99, 1, kTRUE, 0, kTRUE); 
970   
971 //   ((TH2*) hist1)->Rebin2D(2, 2);
972   NormalizeToBinWidth(hist1);
973   
974 //   for (Int_t j=1; j<=hist1->GetNbinsY(); ++j)
975 //   {
976 //     Float_t factor = 1.0 / (1.0 - TMath::Abs(hist1->GetYaxis()->GetBinCenter(j)) / 6.0);
977 //     Printf("%d %f", j, factor);
978 //     for (Int_t i=1; i<=hist1->GetNbinsX(); ++i)
979 //     {
980 //       hist1->SetBinContent(i, j, hist1->GetBinContent(i, j) * factor);
981 //       hist1->SetBinError(i, j, hist1->GetBinError(i, j) * factor);
982 //     }
983 //   }
984
985   c->cd(2);
986   gPad->SetLeftMargin(0.15);
987   hist1->SetTitle("");
988   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
989   hist1->GetZaxis()->SetTitleOffset(1.8);
990   hist1->GetXaxis()->SetTitleOffset(1.5);
991   hist1->GetYaxis()->SetTitleOffset(2);
992   hist1->GetZaxis()->SetTitle("mixed event pairs (a.u.)");
993   hist1->SetStats(kFALSE);
994   hist1->DrawCopy("SURF1");
995   
996   DrawALICELogo(kFALSE, 0.2, 0.7, 0.4, 0.9);
997
998   c->SaveAs(Form("samemixed_%d.eps", step));
999   c->SaveAs(Form("samemixed_%d.png", step));
1000
1001   new TCanvas("c3", "c3", 800, 800);
1002   gPad->SetLeftMargin(0.15);
1003   hist2->Divide(hist1);
1004   hist2->DrawCopy("SURF1");
1005 }
1006
1007 void Validation2DAllStepsNew(const char* fileName, Int_t bin = 0)
1008 {
1009   Int_t centralityFrom = 0;
1010   Int_t centralityTo = 80;
1011   
1012   gpTMin = 1.01;
1013   gpTMax = 1.99;
1014   
1015   Float_t ptTrigBegin = 2.01;
1016   Float_t ptTrigEnd = 3.99;
1017   
1018   if (bin == 1)
1019   {
1020     gpTMin = 0.51;
1021     gpTMax = 0.99;
1022     ptTrigBegin = 1.01;
1023     ptTrigEnd = 1.99;
1024   }
1025   else if (bin == 2)
1026   {
1027     gpTMin = 0.51;
1028     gpTMax = 0.99;
1029     ptTrigBegin = 0.51;
1030     ptTrigEnd = 0.99;
1031   }
1032   else if (bin == 3)
1033   {
1034 /*    gpTMin = 0.51;
1035     gpTMax = 0.99;
1036     ptTrigBegin = 0.51;
1037     ptTrigEnd = 0.99;*/
1038     centralityFrom = 0;
1039     centralityTo = 20;
1040   }
1041   else if (bin == 4)
1042   {
1043 /*    gpTMin = 0.51;
1044     gpTMax = 0.99;
1045     ptTrigBegin = 0.51;
1046     ptTrigEnd = 0.99;*/
1047     centralityFrom = 60;
1048     centralityTo = 80;
1049   }
1050   else if (bin == 5)
1051   {
1052     gpTMin = 0.51;
1053     gpTMax = 0.74;
1054     ptTrigBegin = 0.51;
1055     ptTrigEnd = 0.99;
1056   }
1057   
1058   loadlibs();
1059   
1060   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
1061   hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
1062   
1063   SetupRanges(h);
1064   SetupRanges(hMixed);
1065
1066   TH1* hist[6];
1067
1068   GetSumOfRatios(h, hMixed, &hist[0],  0, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd); 
1069   GetSumOfRatios(h, hMixed, &hist[1],  4, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd); 
1070   GetSumOfRatios(h, hMixed, &hist[2],  5, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd); 
1071   GetSumOfRatios(h, hMixed, &hist[3],  6, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd); 
1072   GetSumOfRatios(h, hMixed, &hist[4],  8, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd); 
1073   GetSumOfRatios(h, hMixed, &hist[5],  10, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd); 
1074
1075   c = new TCanvas("c", "c", 1600, 1000);
1076   c->Divide(6, 4);
1077   
1078   Float_t peakYield1[6];
1079   Float_t baselineValues1[6];
1080
1081   for (Int_t i=0; i<6; i++)
1082   {
1083     if (!hist[i])
1084       continue;
1085     
1086     // NOTE fix normalization. these 2d correlations come out of AliUEHist normalized by dphi bin width, but not deta
1087     hist[i]->Scale(1.0 / hist[i]->GetYaxis()->GetBinWidth(1));
1088
1089     ((TH2*) hist[i])->Rebin2D(2, 2); hist[i]->Scale(0.25);
1090   }
1091   
1092   for (Int_t i=0; i<6; i++)
1093   {
1094     if (!hist[i])
1095       continue;
1096
1097     c->cd(i+1);
1098     hist[i]->GetYaxis()->SetRangeUser(-1.99, 1.99);
1099     hist[i]->GetXaxis()->SetTitleOffset(1.5);
1100     hist[i]->GetYaxis()->SetTitleOffset(2);
1101     hist[i]->GetZaxis()->SetTitleOffset(1.8);
1102     hist[i]->GetZaxis()->SetTitle("1/N_{trig} dN_{assoc}/d#Delta#etad#Delta#varphi (1/rad.)");
1103     hist[i]->SetStats(kFALSE);
1104     hist[i]->DrawCopy("SURF1");    
1105     
1106     if (hist[5])
1107     {
1108       c->cd(i+1+6);
1109       TH2* clone = (TH2*) hist[i]->Clone();
1110       clone->Divide(hist[5]);
1111       clone->DrawCopy("COLZ");
1112       gPad->SetRightMargin(0.15);
1113     }
1114     
1115     c->cd(i+1+12);
1116     proj1 = ((TH2*) hist[i])->ProjectionX(Form("proj1_%d", i), hist[i]->GetYaxis()->FindBin(-0.99), hist[i]->GetYaxis()->FindBin(0.99));
1117     proj1->DrawCopy();
1118     
1119     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);
1120     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];
1121     Printf("%d: %f %f", i, peakYield1[i], baselineValues1[i]);
1122
1123     if (hist[5])
1124     {
1125       proj2 = ((TH2*) hist[5])->ProjectionX(Form("proj2_%d", i), hist[5]->GetYaxis()->FindBin(-0.99), hist[5]->GetYaxis()->FindBin(0.99));
1126       proj2->SetLineColor(2);
1127       proj2->DrawCopy("SAME");
1128     
1129       c->cd(i+1+18);
1130       proj1->Divide(proj1, proj2, 1, 1, "B");
1131       proj1->Draw();
1132     }
1133   }
1134   
1135   c = new TCanvas("c2", "c2", 1600, 1000);
1136   c->Divide(6, 4);
1137
1138   for (Int_t i=0; i<6; i++)
1139   {
1140     if (!hist[i])
1141       continue;
1142
1143     c->cd(i+1);
1144     hist[i]->GetYaxis()->SetRangeUser(-1.99, 1.99);
1145     hist[i]->GetXaxis()->SetTitleOffset(1.5);
1146     hist[i]->GetYaxis()->SetTitleOffset(2);
1147     hist[i]->GetZaxis()->SetTitleOffset(1.8);
1148     hist[i]->GetZaxis()->SetTitle("1/N_{trig} dN_{assoc}/d#Delta#etad#Delta#varphi (1/rad.)");
1149     hist[i]->SetStats(kFALSE);
1150     hist[i]->DrawCopy("SURF1");    
1151     
1152     c->cd(i+1+6);
1153     TH2* clone = (TH2*) hist[i]->Clone();
1154     clone->Divide(hist[0]);
1155     clone->DrawCopy("COLZ");
1156     gPad->SetRightMargin(0.15);
1157     
1158     c->cd(i+1+12);
1159     proj1 = ((TH2*) hist[i])->ProjectionX(Form("proj3_%d", i), hist[i]->GetYaxis()->FindBin(-0.99), hist[i]->GetYaxis()->FindBin(0.99));
1160     proj1->DrawCopy();
1161     
1162     proj2 = ((TH2*) hist[0])->ProjectionX(Form("proj4_%d", i), hist[0]->GetYaxis()->FindBin(-0.99), hist[0]->GetYaxis()->FindBin(0.99));
1163     proj2->SetLineColor(2);
1164     proj2->DrawCopy("SAME");
1165     
1166     c->cd(i+1+18);
1167     proj1->Divide(proj1, proj2, 1, 1, "B");
1168     proj1->Draw();
1169   }
1170
1171   c = new TCanvas("c3", "c3", 1600, 1000);
1172   c->Divide(6, 4);
1173
1174   for (Int_t i=3; i<4; i++)
1175   {
1176     if (!hist[i])
1177       continue;
1178
1179     c->cd(i+1);
1180     hist[i]->GetYaxis()->SetRangeUser(-1.99, 1.99);
1181     hist[i]->GetXaxis()->SetTitleOffset(1.5);
1182     hist[i]->GetYaxis()->SetTitleOffset(2);
1183     hist[i]->GetZaxis()->SetTitleOffset(1.8);
1184     hist[i]->GetZaxis()->SetTitle("1/N_{trig} dN_{assoc}/d#Delta#etad#Delta#varphi (1/rad.)");
1185     hist[i]->SetStats(kFALSE);
1186     hist[i]->DrawCopy("SURF1");    
1187     
1188     c->cd(i+1+6);
1189     TH2* clone = (TH2*) hist[i]->Clone();
1190     clone->Divide(hist[4]);
1191     clone->DrawCopy("COLZ");
1192     gPad->SetRightMargin(0.15);
1193     
1194     c->cd(i+1+12);
1195     proj1 = ((TH2*) hist[i])->ProjectionX(Form("proj4_%d", i), hist[i]->GetYaxis()->FindBin(-0.99), hist[i]->GetYaxis()->FindBin(0.99));
1196     proj1->DrawCopy();
1197     
1198     proj2 = ((TH2*) hist[4])->ProjectionX(Form("proj5_%d", i), hist[4]->GetYaxis()->FindBin(-0.99), hist[4]->GetYaxis()->FindBin(0.99));
1199     proj2->SetLineColor(2);
1200     proj2->DrawCopy("SAME");
1201     
1202     c->cd(i+1+18);
1203     proj1->Divide(proj1, proj2, 1, 1, "B");
1204     proj1->Draw();
1205   }
1206   
1207   c = new TCanvas("c4", "c4", 1200, 400);
1208   c->Divide(3, 1);
1209  
1210   for (Int_t i=0; i<1; i++)
1211   {
1212     if (!hist[i])
1213       continue;
1214
1215     if (hist[5])
1216     {
1217       c->cd(1);
1218       TH2* clone = (TH2*) hist[i]->Clone();
1219       clone->Divide(hist[5]);
1220       clone->DrawCopy("COLZ");
1221       gPad->SetRightMargin(0.15);
1222     }
1223     
1224     c->cd(2);
1225     proj1 = ((TH2*) hist[i])->ProjectionX(Form("proj1_%d", i), hist[i]->GetYaxis()->FindBin(-0.99), hist[i]->GetYaxis()->FindBin(0.99));
1226     proj1->DrawCopy();
1227     
1228     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);
1229     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];
1230     Printf("%d: %f %f", i, peakYield1[i], baselineValues1[i]);
1231
1232     if (hist[5])
1233     {
1234       proj2 = ((TH2*) hist[5])->ProjectionX(Form("proj2_%d", i), hist[5]->GetYaxis()->FindBin(-0.99), hist[5]->GetYaxis()->FindBin(0.99));
1235       proj2->SetLineColor(2);
1236       proj2->DrawCopy("SAME");
1237     
1238       c->cd(3);
1239       proj1->Divide(proj1, proj2, 1, 1, "B");
1240       proj1->Draw();
1241     }
1242   }
1243   
1244   for (Int_t i=0; i<6; i++)
1245     Printf("%d/%d: %f %f", i, 0, peakYield1[i] / peakYield1[0] - 1, baselineValues1[i] / baselineValues1[0] - 1);
1246
1247   if (hist[5])
1248   {
1249     for (Int_t i=0; i<6; i++)
1250       Printf("%d/%d: %f %f", i, 5, peakYield1[i] / peakYield1[5] - 1, baselineValues1[i] / baselineValues1[5] - 1);
1251   }
1252 }
1253
1254 void Validation2DAllBins(const char* fileName, const char *fileName2)
1255 {
1256   /* Int_t is[] = { 0, 1, 2, 3, 4, 5};
1257   Int_t js[] = { 1, 2, 3, 4, 5, 6 };
1258   Int_t n = 5;*/
1259 /*  Int_t is[] = { 0, 1, 1, 2, 2, 2, 3, 3, 3 };
1260   Int_t js[] = { 1, 1, 2, 1, 2, 3, 1, 2, 3 };*/
1261   Int_t is[] = { 0, 1, 1, 2, 2, 2, 3 };
1262   Int_t js[] = { 1, 1, 2, 1, 2, 3, 3 };
1263   Int_t n = 6;
1264   
1265   file1 = TFile::Open(fileName);
1266   TFile* file2 = 0;
1267   if (fileName2)
1268     file2 = TFile::Open(fileName2);
1269   
1270   file3 = TFile::Open("non_closure.root", "RECREATE");
1271   file3->Close();
1272   
1273   Float_t baselineValues1, baselineValues2, peakYield1, peakYield2;
1274   
1275   Int_t padID = 0;
1276   Int_t padN = 4;
1277   for (Int_t centr=0; centr<4; centr++)
1278   {
1279     for (Int_t i=0; i<n; i++)
1280     {
1281       if (padN == 4)
1282       {
1283         c = new TCanvas(Form("c%d", padID), Form("c%d", padID), 1100, 750);
1284         c->Divide(3, 3);
1285         padN = 1;
1286         padID++;
1287       }
1288
1289       TH2* hist1 = (TH2*) file1->Get(Form("dphi_%d_%d_%d", is[i], js[i], centr));
1290       if (!hist1)
1291         continue;
1292       TH2* hist2 = 0;
1293       if (file2)
1294         hist2 = (TH2*) file2->Get(Form("dphi_%d_%d_%d", is[i], js[i], centr));
1295       else
1296         hist2 = (TH2*) file1->Get(Form("dphi_%d_%d_%d", is[i], js[i], centr+4));
1297     
1298       // NOTE fix normalization. these 2d correlations come out of AliUEHist normalized by dphi bin width, but not deta
1299       hist1->Scale(1.0 / hist1->GetYaxis()->GetBinWidth(1));
1300       hist2->Scale(1.0 / hist2->GetYaxis()->GetBinWidth(1));
1301
1302       ((TH2*) hist1)->Rebin2D(2, 2); hist1->Scale(0.25);
1303       ((TH2*) hist2)->Rebin2D(2, 2); hist2->Scale(0.25);
1304
1305       const Float_t outerEta = 1.8;
1306       const Float_t exclusion = 0.5;
1307       
1308       c->cd(padN);
1309       proj1 = ((TH2*) hist1)->ProjectionX(Form("proj1a_%d_%d", centr, i), hist1->GetYaxis()->FindBin(-outerEta + 0.01), hist1->GetYaxis()->FindBin(-exclusion - 0.01));
1310       proj1b = ((TH2*) hist1)->ProjectionX(Form("proj1b_%d_%d", centr, i), hist1->GetYaxis()->FindBin(exclusion + 0.01), hist1->GetYaxis()->FindBin(outerEta - 0.01));
1311       proj1->Add(proj1b);
1312       copy = proj1->DrawCopy();
1313       copy->GetYaxis()->SetRangeUser(proj1->GetMinimum() * 0.9, proj1->GetMaximum() * 1.2);
1314       proj1c = ((TH2*) hist1)->ProjectionX(Form("proj1c_%d_%d", centr, i), hist1->GetYaxis()->FindBin(-outerEta + 0.01), hist1->GetYaxis()->FindBin(outerEta - 0.01));
1315       proj1c->SetLineColor(2);
1316       proj1c->DrawCopy("SAME");
1317       copy->SetMinimum(TMath::Min(copy->GetMinimum(), proj1c->GetMinimum()));
1318       copy->SetMaximum(1.2 * TMath::Max(copy->GetMaximum(), proj1c->GetMaximum()));
1319       
1320       Double_t baselineValues1E, peakYield1E;
1321       baselineValues1 = proj1->IntegralAndError(proj1->FindBin(TMath::Pi()/2 - 0.2), proj1->FindBin(TMath::Pi()/2 + 0.2), baselineValues1E);
1322       baselineValues1 /= (proj1->FindBin(TMath::Pi()/2 + 0.2) - proj1->FindBin(TMath::Pi()/2 - 0.2) + 1);
1323       baselineValues1E /= (proj1->FindBin(TMath::Pi()/2 + 0.2) - proj1->FindBin(TMath::Pi()/2 - 0.2) + 1);
1324       peakYield1 = proj1->IntegralAndError(proj1->GetXaxis()->FindBin(-1), proj1->GetXaxis()->FindBin(1), peakYield1E);
1325       peakYield1 /= (proj1->GetXaxis()->FindBin(0.99) - proj1->GetXaxis()->FindBin(-0.99) + 1);
1326       peakYield1E /= (proj1->GetXaxis()->FindBin(0.99) - proj1->GetXaxis()->FindBin(-0.99) + 1);
1327       peakYield1 -= baselineValues1;
1328       peakYield1E = TMath::Sqrt(peakYield1E * peakYield1E + baselineValues1E * baselineValues1E);
1329
1330       proj2 = ((TH2*) hist2)->ProjectionX(Form("proj2a_%d_%d", centr, i), hist2->GetYaxis()->FindBin(-outerEta + 0.01), hist2->GetYaxis()->FindBin(-exclusion - 0.01));
1331       proj2b = ((TH2*) hist2)->ProjectionX(Form("proj2b_%d_%d", centr, i), hist2->GetYaxis()->FindBin(exclusion + 0.01), hist2->GetYaxis()->FindBin(outerEta - 0.01));
1332       proj2->Add(proj2b);
1333       proj2->SetLineColor(3);
1334       proj2->DrawCopy("SAME");
1335       proj2c = ((TH2*) hist2)->ProjectionX(Form("proj2c_%d_%d", centr, i), hist2->GetYaxis()->FindBin(-outerEta + 0.01), hist2->GetYaxis()->FindBin(outerEta - 0.01));
1336       proj2c->SetLineColor(4);
1337       proj2c->DrawCopy("SAME");
1338       
1339       Double_t baselineValues2E, peakYield2E;
1340       baselineValues2 = proj2->IntegralAndError(proj1->FindBin(TMath::Pi()/2 - 0.2), proj2->FindBin(TMath::Pi()/2 + 0.2), baselineValues2E);
1341       baselineValues2 /= (proj2->FindBin(TMath::Pi()/2 + 0.2) - proj2->FindBin(TMath::Pi()/2 - 0.2) + 1);
1342       baselineValues2E /= (proj2->FindBin(TMath::Pi()/2 + 0.2) - proj2->FindBin(TMath::Pi()/2 - 0.2) + 1);
1343       peakYield2 = proj2->IntegralAndError(proj2->GetXaxis()->FindBin(-1), proj2->GetXaxis()->FindBin(1), peakYield2E);
1344       peakYield2 /= (proj2->GetXaxis()->FindBin(0.99) - proj2->GetXaxis()->FindBin(-0.99) + 1);
1345       peakYield2E /= (proj2->GetXaxis()->FindBin(0.99) - proj2->GetXaxis()->FindBin(-0.99) + 1);
1346       peakYield2 -= baselineValues2;
1347       peakYield2E = TMath::Sqrt(peakYield2E * peakYield2E + baselineValues2E * baselineValues2E);
1348       
1349   //     Printf("%d: %f %f %f %f %.2f%% %.2f%%", i, peakYield1, baselineValues1, peakYield2, baselineValues2, 100.0 * peakYield1 / peakYield2 - 100, 100.0 * baselineValues1 / baselineValues2 - 100);
1350       Printf("%s: %.2f%% +- %.2f%%    %.2f%% +- %.2f%%", 
1351              hist1->GetTitle(), 
1352              100.0 * peakYield1 / peakYield2 - 100, 
1353              100.0 * peakYield1 / peakYield2 * TMath::Sqrt(TMath::Power(peakYield1E / peakYield1, 2) + TMath::Power(peakYield2E / peakYield2, 2)),
1354              100.0 * baselineValues1 / baselineValues2 - 100,
1355              100.0 * baselineValues1 / baselineValues2 * TMath::Sqrt(TMath::Power(baselineValues1E / baselineValues1, 2) + TMath::Power(baselineValues2E / baselineValues2, 2))
1356             );
1357       
1358       c->cd(padN+3);
1359       proj1->Divide(proj1, proj2, 1, 1, "B");
1360       proj1c->Divide(proj1c, proj2c, 1, 1, "B");
1361   //     proj1->Add(proj2, -1);
1362       proj1->Draw();
1363       proj1c->SetLineColor(2);
1364       proj1c->Draw("SAME");
1365       
1366       c->cd(padN+6);
1367       hist1->Divide(hist2);
1368       hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
1369       hist1->Draw("COLZ");
1370       
1371       file3 = TFile::Open("non_closure.root", "UPDATE");
1372       proj1->Write(Form("non_closure_%d_%d_%d", is[i], js[i], centr));
1373       proj1c->Write(Form("non_closure_all_%d_%d_%d", is[i], js[i], centr));
1374       hist1->Write(Form("non_closure_2d_%d_%d_%d", is[i], js[i], centr));
1375       file3->Close();
1376       
1377       padN++;
1378     }
1379   }
1380 }
1381
1382 void Validation2DAllSteps(const char* fileName, const char* fileNameCorrected = "corrected.root", Int_t startStep = 8)
1383 {
1384   Int_t centralityFrom = 0;
1385   Int_t centralityTo = 80;
1386   
1387   gpTMin = 1.01;
1388   gpTMax = 1.99;
1389   
1390   Float_t ptTrigBegin = 2.01;
1391   Float_t ptTrigEnd = 2.99;
1392   
1393   loadlibs();
1394   
1395   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
1396   hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
1397   
1398   AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(fileNameCorrected);
1399   hMixed2 = (AliUEHistograms*) GetUEHistogram(fileNameCorrected, 0, kTRUE);
1400
1401   SetupRanges(h);
1402   SetupRanges(hMixed);
1403   SetupRanges(h2);
1404   SetupRanges(hMixed2);
1405
1406   TH1* hist[6];
1407   TH1* hist2[6];
1408
1409 //   GetSumOfRatios(h, hMixed,   &hist[0],  0, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, kTRUE); 
1410   
1411   GetDistAndFlow(h, hMixed,   &hist[0],  0, 0, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, 0); 
1412   GetDistAndFlow(h, hMixed,   &hist[1],  0, 4, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, 6); 
1413   GetDistAndFlow(h, hMixed,   &hist[2],  0, 5, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, 6); 
1414   GetDistAndFlow(h, hMixed,   &hist[3],  0, startStep, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, startStep); 
1415   GetDistAndFlow(h2, hMixed2, &hist2[0],  0, 0, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, startStep); 
1416   GetDistAndFlow(h2, hMixed2, &hist2[1],  0, 4, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, startStep); 
1417   GetDistAndFlow(h2, hMixed2, &hist2[2],  0, 5, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, startStep); 
1418   GetDistAndFlow(h2, hMixed2, &hist2[3],  0, startStep, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, startStep); 
1419
1420   c = new TCanvas("c", "c", 1600, 1000);
1421   c->Divide(4, 5);
1422   
1423   Float_t peakYield1[4];
1424   Float_t baselineValues1[4];
1425   Float_t peakYield2[4];
1426   Float_t baselineValues2[4];
1427   for (Int_t i=0; i<4; i++)
1428   {
1429     // NOTE fix normalization. these 2d correlations come out of AliUEHist normalized by dphi bin width, but not deta
1430     hist[i]->Scale(1.0 / hist[i]->GetYaxis()->GetBinWidth(1));
1431     hist2[i]->Scale(1.0 / hist2[i]->GetYaxis()->GetBinWidth(1));
1432
1433     ((TH2*) hist[i])->Rebin2D(2, 2); hist[i]->Scale(0.25);
1434 //     ((TH2*) hist[i])->Rebin2D(2, 2); hist[i]->Scale(0.25);
1435     
1436     c->cd(i+1);
1437     hist[i]->GetYaxis()->SetRangeUser(-1.59, 1.59);
1438     hist[i]->GetXaxis()->SetTitleOffset(1.5);
1439     hist[i]->GetYaxis()->SetTitleOffset(2);
1440     hist[i]->GetZaxis()->SetTitleOffset(1.8);
1441     hist[i]->GetZaxis()->SetTitle("1/N_{trig} dN_{assoc}/d#Delta#etad#Delta#varphi (1/rad.)");
1442     hist[i]->SetStats(kFALSE);
1443     hist[i]->DrawCopy("SURF1");    
1444     
1445     ((TH2*) hist2[i])->Rebin2D(2, 2); hist2[i]->Scale(0.25);
1446 //     ((TH2*) hist2[i])->Rebin2D(2, 2); hist2[i]->Scale(0.25);
1447     
1448 //     TF2* func2 = new TF2("func2", "[0]+[1]*exp(-0.5*((x/[2])**2+(y/[3])**2))", -1, 1, -0.99, 0.99);
1449 //     func2->SetParameters(0, 1, 0.5, 0.5);
1450 //     hist[i]->Fit(func2, "0R");
1451 //     hist[i]->Fit(func2, "0R");
1452 //     
1453 //     c->cd(i+1+4);
1454 //     func2->DrawClone("SURF1");
1455 //     
1456 //     baselineValues1[i] = func2->GetParameter(0);
1457 //     func2->SetParameter(0, 0);
1458 //     peakYield1[i] = func2->Integral(-0.5 * TMath::Pi(), 0.5 * TMath::Pi(), -1.4, 1.4);
1459 //     Printf("%f %f", peakYield1[i], baselineValues1[i]);
1460
1461     c->cd(i+1+4);
1462     hist2[i]->GetYaxis()->SetRangeUser(-1.59, 1.59);
1463     hist2[i]->GetXaxis()->SetTitleOffset(1.5);
1464     hist2[i]->GetYaxis()->SetTitleOffset(2);
1465     hist2[i]->GetZaxis()->SetTitleOffset(1.8);
1466     hist2[i]->GetZaxis()->SetTitle("1/N_{trig} dN_{assoc}/d#Delta#etad#Delta#varphi (1/rad.)");
1467     hist2[i]->SetStats(kFALSE);
1468     hist2[i]->DrawCopy("SURF1");        
1469     
1470     c->cd(i+1+12);
1471     proj1 = ((TH2*) hist[i])->ProjectionX(Form("proj1_%d", i), hist[i]->GetYaxis()->FindBin(-0.99), hist[i]->GetYaxis()->FindBin(0.99));
1472     proj1->DrawCopy();
1473     
1474     baselineValues1[i] = proj1->GetMinimum();
1475     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];
1476     Printf("%f %f", peakYield1[i], baselineValues1[i]);
1477
1478     proj2 = ((TH2*) hist2[i])->ProjectionX(Form("proj2_%d", i), hist2[i]->GetYaxis()->FindBin(-0.99), hist2[i]->GetYaxis()->FindBin(0.99));
1479     proj2->SetLineColor(2);
1480     proj2->DrawCopy("SAME");
1481     
1482     baselineValues2[i] = proj2->GetMinimum();
1483     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];
1484     Printf("%f %f", peakYield2[i], baselineValues2[i]);
1485
1486     c->cd(i+1+16);
1487     proj1->Divide(proj2);
1488     proj1->Draw();
1489     
1490 //     func2 = new TF2("func2", "[0]+[1]*exp(-0.5*((x/[2])**2+(y/[3])**2))", -1, 1, -0.99, 0.99);
1491 //     func2->SetParameters(0, 1, 0.5, 0.5);
1492 //     hist2[i]->Fit(func2, "0R");
1493 //     hist2[i]->Fit(func2, "0R");
1494 //     
1495 //     c->cd(i+1+12);
1496 //     func2->DrawClone("SURF1");
1497 //     
1498 //     baselineValues2[i] = func2->GetParameter(0);
1499 //     func2->SetParameter(0, 0);
1500 //     peakYield2[i] = func2->Integral(-0.5 * TMath::Pi(), 0.5 * TMath::Pi(), -1.4, 1.4);
1501 //     Printf("%f %f", peakYield2[i], baselineValues2[i]);
1502
1503     c->cd(i+1+8);
1504     TH2* clone = (TH2*) hist[i]->Clone();
1505     clone->Divide(hist2[i]);
1506 //     clone->Add(hist2[i], -1);
1507     clone->DrawCopy("COLZ");
1508     gPad->SetRightMargin(0.15);
1509     
1510 /*    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);
1511     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);*/
1512     
1513 //     break;
1514   }
1515
1516   for (Int_t i=0; i<4; i++)
1517   {
1518     Printf("%d: %f %f", i, peakYield1[i] / peakYield2[i] - 1, baselineValues1[i] / baselineValues2[i] - 1);
1519 //     Printf("%d: %f %f", i, peakYield1[i] - 1, baselineValues1[i] - 1);
1520   }
1521 }
1522
1523 void CorrelatedContaminationEffect(const char* fileName, const char* fileNameCorrected = "corrected.root", Int_t bin = 0, Int_t startStep = 8)
1524 {
1525   Int_t centralityFrom = 0;
1526   Int_t centralityTo = 80;
1527   
1528   gpTMin = 1.01;
1529   gpTMax = 1.99;
1530   
1531   Float_t ptTrigBegin = 2.01;
1532   Float_t ptTrigEnd = 3.99;
1533   
1534   if (bin == 1)
1535   {
1536     ptTrigBegin = 1.01;
1537     ptTrigEnd = 1.99;
1538   }
1539   else if (bin == 2)
1540   {
1541     gpTMin = 0.51;
1542     gpTMax = 0.99;
1543     ptTrigBegin = 1.01;
1544     ptTrigEnd = 1.99;  
1545   }
1546   else if (bin == 3)
1547   {
1548     ptTrigBegin = 4.01;
1549     ptTrigEnd = 7.99;  
1550   }
1551   
1552   loadlibs();
1553   
1554   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
1555   hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
1556   
1557   AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(fileNameCorrected);
1558   hMixed2 = (AliUEHistograms*) GetUEHistogram(fileNameCorrected, 0, kTRUE);
1559
1560   SetupRanges(h);
1561   SetupRanges(hMixed);
1562   SetupRanges(h2);
1563   SetupRanges(hMixed2);
1564
1565   TH1* hist[6];
1566
1567   Int_t maxFilled = 5;
1568   GetSumOfRatios(h, hMixed, &hist[0],  0, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd); 
1569   GetSumOfRatios(h, hMixed, &hist[1],  4, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd); 
1570   GetSumOfRatios(h, hMixed, &hist[2],  5, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd); 
1571   GetSumOfRatios(h, hMixed, &hist[3],  6, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd); 
1572   GetSumOfRatios(h, hMixed, &hist[4],  startStep, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd); 
1573 //   GetSumOfRatios(h2, hMixed2, &hist[5],  startStep, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd); 
1574   
1575 //   GetDistAndFlow(h, hMixed, &hist[0],  0, 0, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, 0); 
1576 //   GetDistAndFlow(h, hMixed, &hist[1],  0, 4, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, 6); 
1577 //   GetDistAndFlow(h, hMixed, &hist[2],  0, 5, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, 6); 
1578 //   GetDistAndFlow(h, hMixed, &hist[3],  0, 6, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, 6); 
1579 //   GetDistAndFlow(h, hMixed, &hist[4],  0, startStep, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, startStep); 
1580 //   GetDistAndFlow(h2, hMixed2, &hist[5],  0, 0, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, startStep); 
1581
1582   c = new TCanvas("c", "c", 1600, 1000);
1583   c->Divide(6, 2);
1584   
1585   for (Int_t i=0; i<maxFilled; i++)
1586   {
1587     // NOTE fix normalization. these 2d correlations come out of AliUEHist normalized by dphi bin width, but not deta
1588     hist[i]->Scale(1.0 / hist[i]->GetYaxis()->GetBinWidth(1));
1589
1590     ((TH2*) hist[i])->Rebin2D(2, 2); hist[i]->Scale(0.25);
1591 //     ((TH2*) hist[i])->Rebin2D(2, 2); hist[i]->Scale(0.25);
1592     
1593     c->cd(i+1);
1594     hist[i]->GetYaxis()->SetRangeUser(-1.59, 1.59);
1595     hist[i]->GetXaxis()->SetTitleOffset(1.5);
1596     hist[i]->GetYaxis()->SetTitleOffset(2);
1597     hist[i]->GetZaxis()->SetTitleOffset(1.8);
1598     hist[i]->GetZaxis()->SetTitle("1/N_{trig} dN_{assoc}/d#Delta#etad#Delta#varphi (1/rad.)");
1599     hist[i]->SetStats(kFALSE);
1600     hist[i]->DrawCopy("SURF1");    
1601   }
1602   
1603   for (Int_t i=1; i<maxFilled; i++)
1604   {
1605     TH2* clone = (TH2*) hist[i]->Clone();
1606     if (i < 4)
1607       clone->Divide(hist[i-1]);
1608     else if (i < 5)
1609       clone->Divide(hist[2]);
1610     else 
1611       clone->Divide(hist[0]);
1612   
1613     c->cd(6+i);
1614     gPad->SetRightMargin(0.15);
1615   //   hist1->SetTitle("");
1616 //     clone->GetZaxis()->SetRangeUser(0.8, 1.2);
1617     clone->GetZaxis()->SetTitle("1/N_{trig} dN_{assoc}/d#Delta#etad#Delta#varphi (1/rad.)");
1618     clone->SetStats(kFALSE);
1619     clone->DrawCopy("COLZ");
1620   }
1621
1622   Float_t peakYield[6];
1623   Float_t baselineValues[6];
1624   for (Int_t i=0; i<maxFilled; i++)
1625   {
1626     Int_t phi1 = hist[i]->GetXaxis()->FindBin(-1);
1627     Int_t phi2 = hist[i]->GetXaxis()->FindBin(1);
1628     Int_t eta1 = hist[i]->GetYaxis()->FindBin(-1.59);
1629     Int_t eta2 = hist[i]->GetYaxis()->FindBin(1.01);
1630     Int_t eta3 = hist[i]->GetYaxis()->FindBin(1.59);
1631     Float_t baseline = ((TH2*) hist[i])->Integral(phi1, phi2, eta2, eta3, "width") / (phi2 - phi1 + 1) / (eta3 - eta2 + 1);
1632     Float_t peak = ((TH2*) hist[i])->Integral(phi1, phi2, eta1, eta3, "width");
1633     Printf("%f %f", baseline, peak);
1634     peak -= baseline * (eta3 - eta1 + 1) * (phi2 - phi1 + 1);
1635     Printf("%f", peak);
1636     peakYield[i] = peak;
1637     baselineValues[i] = baseline;
1638   }
1639   
1640   for (Int_t i=1; i<maxFilled; i++)
1641   {
1642     if (i < 4)
1643       Printf("%d/%d: %f %f", i, i-1, peakYield[i] / peakYield[i-1] - 1, baselineValues[i] / baselineValues[i-1] - 1);
1644     else if (i < 5)
1645       Printf("%d/%d: %f %f", i, 2, peakYield[i] / peakYield[2] - 1, baselineValues[i] / baselineValues[2] - 1);
1646     else
1647       Printf("%d/%d: %f %f", 0, i, peakYield[0] / peakYield[i] - 1, baselineValues[0] / baselineValues[i] - 1);
1648   }
1649   
1650   c = new TCanvas("c2", "c2", 1600, 1000);
1651   c->Divide(6, 2);
1652   for (Int_t i=0; i<maxFilled; i++)
1653   {
1654     c->cd(i+1);
1655     hist[i]->DrawCopy("SURF1");
1656     
1657     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);
1658     func2->SetParameters(0, 1, 0.5, 0.5);
1659 //     func2->SetParLimits(1, 0, 10);
1660 //     func2->SetParLimits(2, sigmaFitLimit, 1);
1661 //     func2->SetParLimits(3, sigmaFitLimit, 1);
1662     hist[i]->Fit(func2, "0R");
1663     
1664     c->cd(i+7);
1665     func2->DrawClone("SURF1");
1666     
1667     baselineValues[i] = func2->GetParameter(0);
1668     func2->SetParameter(0, 0);
1669     peakYield[i] = func2->Integral(-0.5 * TMath::Pi(), 0.5 * TMath::Pi(), -1.4, 1.4);
1670     Printf("%f %f", peakYield[i], baselineValues[i]);
1671   }
1672
1673   for (Int_t i=1; i<maxFilled; i++)
1674   {
1675     if (i < 4)
1676       Printf("%d/%d: %f %f", i, i-1, peakYield[i] / peakYield[i-1] - 1, baselineValues[i] / baselineValues[i-1] - 1);
1677     else if (i < 5)
1678       Printf("%d/%d: %f %f", i, 2, peakYield[i] / peakYield[2] - 1, baselineValues[i] / baselineValues[2] - 1);
1679     else
1680       Printf("%d/%d: %f %f", 0, i, peakYield[0] / peakYield[i] - 1, baselineValues[0] / baselineValues[i] - 1);
1681   }
1682
1683   for (Int_t i=1; i<maxFilled; i++)
1684   {
1685     Printf("%d/%d: %f %f", 0, i, peakYield[0] / peakYield[i] - 1, baselineValues[0] / baselineValues[i] - 1);
1686   }
1687 }
1688
1689 void DrawValidation2D(const char* fileName, const char* fileNameCorrected = "corrected.root", Int_t startStep = 8)
1690 {
1691   Int_t centralityTo = 80;
1692   
1693   gpTMin = 1.01;
1694   gpTMax = 1.99;
1695   
1696   loadlibs();
1697   
1698   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
1699   hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
1700   
1701   SetupRanges(h);
1702   SetupRanges(hMixed);
1703
1704   TH1* hist1 = 0;
1705   GetDistAndFlow(h, hMixed, &hist1,  0, 0, 0,  centralityTo, 2.01, 3.99, 1, kTRUE, 0, kTRUE, 0); 
1706   // NOTE fix normalization. these 2d correlations come out of AliUEHist normalized by dphi bin width, but not deta
1707   hist1->Scale(1.0 / hist1->GetYaxis()->GetBinWidth(1));
1708   
1709 //   ((TH2*) hist1)->Rebin2D(2, 2); hist1->Scale(0.25);
1710   ((TH2*) hist1)->Rebin2D(2, 2); hist1->Scale(0.25);
1711
1712 //   NormalizeToBinWidth(hist1);
1713   
1714   c = new TCanvas("c", "c", 1000, 1000);
1715   c->Divide(2, 2);
1716   
1717   c->cd(1);
1718   gPad->SetLeftMargin(0.15);
1719 //   hist1->SetTitle("");
1720   hist1->GetYaxis()->SetRangeUser(-1.59, 1.59);
1721   hist1->GetXaxis()->SetTitleOffset(1.5);
1722   hist1->GetYaxis()->SetTitleOffset(2);
1723   hist1->GetZaxis()->SetTitleOffset(1.8);
1724   hist1->GetZaxis()->SetTitle("1/N_{trig} dN_{assoc}/d#Delta#etad#Delta#varphi (1/rad.)");
1725   hist1->SetStats(kFALSE);
1726   hist1->DrawCopy("SURF1");
1727   DrawLatex(0.1, 0.85, 1, "MC", 0.04);
1728 //   DrawALICELogo(kFALSE, 0.7, 0.7, 0.9, 0.9);
1729   
1730   hist2 = hist1;
1731   hist1 = 0;
1732   GetDistAndFlow(h, hMixed, &hist1,  0, startStep, 0,  centralityTo, 2.01, 3.99, 1, kTRUE, 0, kTRUE, startStep); 
1733   // NOTE fix normalization. these 2d correlations come out of AliUEHist normalized by dphi bin width, but not deta
1734   hist1->Scale(1.0 / hist1->GetYaxis()->GetBinWidth(1));
1735
1736 //   ((TH2*) hist1)->Rebin2D(2, 2); hist1->Scale(0.25);
1737   ((TH2*) hist1)->Rebin2D(2, 2); hist1->Scale(0.25);
1738 //   NormalizeToBinWidth(hist1);
1739
1740   c->cd(2);
1741   gPad->SetLeftMargin(0.15);
1742   hist1->SetTitle("");
1743   hist1->GetYaxis()->SetRangeUser(-1.59, 1.59);
1744   hist1->GetXaxis()->SetTitleOffset(1.5);
1745   hist1->GetYaxis()->SetTitleOffset(2);
1746   hist1->GetZaxis()->SetTitleOffset(1.8);
1747   hist1->SetStats(kFALSE);
1748   hist1->GetZaxis()->SetTitle("1/N_{trig} dN_{assoc}/d#Delta#etad#Delta#varphi (1/rad.)");
1749   hist1->DrawCopy("SURF1");  
1750   DrawLatex(0.1, 0.85, 1, "Uncorrected", 0.04);
1751 //   DrawALICELogo(kFALSE, 0.7, 0.7, 0.9, 0.9);
1752
1753   c2 = new TCanvas("c3", "c3", 800, 800);
1754 //   hist2->Scale(1.09);
1755   hist1->Divide(hist2);
1756 //   hist1->Add(hist2, -1);
1757   hist1->DrawCopy("SURF1");  
1758   
1759 //   return;
1760   
1761 //   AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram("LHC11a10a_bis_AOD090_120406_zvtx_rebinned_corrected.root");
1762   AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(fileNameCorrected);
1763   SetupRanges(h2);
1764  
1765   GetDistAndFlow(h2, hMixed, &hist1,  0, 0, 0,  centralityTo, 2.01, 3.99, 1, kTRUE, 0, kTRUE, startStep); 
1766   // NOTE fix normalization. these 2d correlations come out of AliUEHist normalized by dphi bin width, but not deta
1767   hist1->Scale(1.0 / hist1->GetYaxis()->GetBinWidth(1));
1768
1769   ((TH2*) hist1)->Rebin2D(2, 2); hist1->Scale(0.25);
1770 //   ((TH2*) hist1)->Rebin2D(2, 2); hist1->Scale(0.25);
1771
1772   c->cd(3);
1773   gPad->SetLeftMargin(0.15);
1774   hist1->SetTitle("");
1775   hist1->GetYaxis()->SetRangeUser(-1.59, 1.59);
1776   hist1->GetXaxis()->SetTitleOffset(1.5);
1777   hist1->GetZaxis()->SetTitleOffset(1.8);
1778   hist1->GetZaxis()->SetTitle("1/N_{trig} dN_{assoc}/d#Delta#etad#Delta#varphi (1/rad.)");
1779   hist1->GetYaxis()->SetTitleOffset(2);
1780   hist1->SetStats(kFALSE);
1781   hist1->DrawCopy("SURF1");  
1782   DrawLatex(0.1, 0.85, 1, "Corrected", 0.04);
1783 //   DrawALICELogo(kFALSE, 0.7, 0.7, 0.9, 0.9);
1784   
1785   hist1->Divide(hist2);
1786
1787   c->cd(4);
1788   gPad->SetRightMargin(0.15);
1789   hist1->SetTitle("");
1790   hist1->GetYaxis()->SetRangeUser(-1.59, 1.59);
1791   hist1->GetXaxis()->SetTitleOffset(1.2);
1792   hist1->GetYaxis()->SetTitleOffset(1.2);
1793   hist1->GetZaxis()->SetTitle("Ratio: Corrected / MC");
1794   hist1->SetStats(kFALSE);
1795   hist1->GetZaxis()->SetRangeUser(0.99, 1.01);
1796   hist1->DrawCopy("COLZ");  
1797
1798 //   DrawALICELogo(kFALSE, 0.7, 0.7, 0.9, 0.9);
1799   
1800   c->SaveAs("validation.eps");
1801   c->SaveAs("validation.gif");
1802 }
1803
1804 void DrawValidation(const char* fileName1, const char* fileName2)
1805 {
1806   gpTMin = 1.01;
1807   gpTMax = 3.99;
1808   
1809   CompareStep(fileName1, fileName2, 2, 6, 4, 0, 4.01, 19.99);
1810   CompareStep(fileName1, fileName2, 2, 4, 4, 0, 4.01, 19.99);
1811
1812   CompareStep(fileName1, fileName2, 2, 4, 2, 0, 4.01, 19.99);
1813   CompareStep(fileName1, fileName2, 2, 2, 2, 0, 4.01, 19.99);
1814 }
1815
1816 void ProfileMultiplicity(const char* fileName = "PWG4_JetTasksOutput.root")
1817 {
1818   loadlibs();
1819
1820   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
1821
1822   new TCanvas;
1823   h->GetCorrelationMultiplicity()->Draw("colz");
1824   gPad->SetLogz();
1825
1826   new TCanvas;
1827   h->GetCorrelationMultiplicity()->ProfileX()->DrawCopy()->Fit("pol1", "", "", 1, 10);
1828 }
1829
1830 void SetupRanges(void* obj)
1831 {
1832   if (!obj)
1833     return;
1834   ((AliUEHistograms*) obj)->SetEtaRange(0, 0);
1835 //   ((AliUEHistograms*) obj)->SetEtaRange(-0.99, 0.99); Printf("WARNING: Setting eta Range!");
1836   ((AliUEHistograms*) obj)->SetPtRange(gpTMin, gpTMax);
1837   ((AliUEHistograms*) obj)->SetCombineMinMax(kTRUE);
1838   if (gZVtxRange > 0)
1839     ((AliUEHistograms*) obj)->SetZVtxRange(-gZVtxRange+0.01, gZVtxRange-0.01);
1840 }
1841
1842 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)
1843 {
1844   AliUEHist* corrected = (AliUEHist*) correctedVoid;
1845   AliUEHist* comparison = (AliUEHist*) comparisonVoid;
1846
1847   Int_t beginStep = AliUEHist::kCFStepAll;
1848   Int_t endStep = AliUEHist::kCFStepReconstructed;
1849   
1850   if (compareStep != -1)
1851   {
1852     beginStep = compareStep;
1853     endStep = compareStep;
1854   }
1855   
1856   Int_t beginRegion = 0;
1857   Int_t endRegion = 2;
1858   
1859   if (compareRegion != -1)
1860   {
1861     beginRegion = compareRegion;
1862     endRegion = compareRegion;
1863   }
1864
1865   for (Int_t step=beginStep; step<=endStep; step++)
1866   {
1867     if (compareStep == -1 && (step == AliUEHist::kCFStepAnaTopology || step == AliUEHist::kCFStepTriggered))
1868       continue;
1869       
1870     for (Int_t region=beginRegion; region <= endRegion; region++)
1871     {
1872       Printf("%f %f", ptLeadMin, ptLeadMax);
1873       TH1* corrHist = corrected->GetUEHist(step, region, ptLeadMin, ptLeadMax);
1874       TH1* mcHist   = comparison->GetUEHist(step, region, ptLeadMin, ptLeadMax);
1875       
1876       DrawRatio(corrHist, mcHist, TString(Form("%s: step %d %s %s", name, step, corrected->GetStepTitle(step), corrected->GetRegionTitle(region))));
1877     }
1878   }
1879 }
1880
1881 void DrawRatios(void* correctedVoid, void* comparisonVoid, Int_t compareStep = -1, Int_t compareRegion = 2, Int_t compareUEHist = 0)
1882 {
1883   AliUEHistograms* corrected = (AliUEHistograms*) correctedVoid;
1884   AliUEHistograms* comparison = (AliUEHistograms*) comparisonVoid;
1885
1886   if (1 && compareUEHist == 2)
1887   {
1888     for (Float_t ptMin = 2.01; ptMin < 8; ptMin += 2)
1889     {
1890       ((AliUEHistograms*) corrected)->SetPtRange(ptMin, ptMin + 1.98);
1891       ((AliUEHistograms*) comparison)->SetPtRange(ptMin, ptMin + 1.98);
1892       
1893       DrawRatios(TString(Form("Dphi %d pT %f", compareUEHist, ptMin)), corrected->GetUEHist(compareUEHist), comparison->GetUEHist(compareUEHist), compareStep, compareRegion, 8.01, 19.99);      
1894     }
1895     return;
1896   }
1897
1898   if (compareUEHist == -1)
1899   {
1900     for (Int_t i=0; i<2; i++)
1901       DrawRatios(TString(Form("UE %d", i)), corrected->GetUEHist(i), comparison->GetUEHist(i), compareStep, compareRegion);
1902   }
1903   else
1904     DrawRatios(TString(Form("UE %d", compareUEHist)), corrected->GetUEHist(compareUEHist), comparison->GetUEHist(compareUEHist), compareStep, compareRegion);
1905 }
1906
1907 void CompareEventsTracks(void* corrVoid, void* mcVoid, Int_t compareStep, Int_t compareRegion, Int_t compareUEHist = 0)
1908 {
1909   AliUEHist* corr = ((AliUEHistograms*) corrVoid)->GetUEHist(compareUEHist);
1910   AliUEHist* mc   = ((AliUEHistograms*) mcVoid)->GetUEHist(compareUEHist);
1911
1912   Float_t ptLeadMin = 0;
1913   Float_t ptLeadMax = -1;
1914   Int_t axis = 2;
1915   
1916   if (compareUEHist == 2)
1917   {
1918     ptLeadMin = 1.01;
1919     ptLeadMax = 1.49;
1920     axis = 4;
1921   }
1922
1923   TH1* corrHist = corr->GetUEHist(compareStep, compareRegion, ptLeadMin, ptLeadMax);
1924   TH1* mcHist   = mc  ->GetUEHist(compareStep, compareRegion, ptLeadMin, ptLeadMax);
1925   
1926   DrawRatio(corrHist, mcHist, Form("check"));
1927   
1928   corr->SetBinLimits(corr->GetTrackHist(compareRegion)->GetGrid(compareStep));
1929   mc->SetBinLimits(corr->GetTrackHist(compareRegion)->GetGrid(compareStep));
1930
1931   corrHist =  corr->GetTrackHist(compareRegion)->GetGrid(compareStep)->Project(axis);
1932   mcHist   =  mc  ->GetTrackHist(compareRegion)->GetGrid(compareStep)->Project(axis);
1933   DrawRatio(corrHist, mcHist, Form("check2"));
1934   
1935   corrHist =  corr->GetEventHist()->GetGrid(compareStep)->Project(0);
1936   mcHist   =  mc  ->GetEventHist()->GetGrid(compareStep)->Project(0);
1937   DrawRatio(corrHist, mcHist, Form("check3"));
1938 }
1939
1940 void CopyReconstructedData(const char* fileName)
1941 {
1942   loadlibs();
1943   
1944   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
1945   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);  
1946
1947   // copy
1948   AliUEHistograms* onlyRec = (AliUEHistograms*) h->Clone();
1949   onlyRec->Reset();
1950   onlyRec->CopyReconstructedData(h);
1951   
1952   AliUEHistograms* onlyRecMixed = (AliUEHistograms*) hMixed->Clone();
1953   onlyRecMixed->Reset();
1954   onlyRecMixed->CopyReconstructedData(hMixed);
1955
1956   TString newFileName(fileName);
1957   newFileName.ReplaceAll(".root", "");
1958   newFileName += "_onlyreco.root";
1959
1960   list = new TList;
1961   list->Add(onlyRec);
1962   list->Add(onlyRecMixed);
1963
1964   file3 = TFile::Open(newFileName, "RECREATE");
1965   file3->mkdir("PWG4_PhiCorrelations");
1966   file3->cd("PWG4_PhiCorrelations");
1967   list->Write("histosPhiCorrelations", TObject::kSingleKey);
1968   file3->Close();  
1969 }
1970
1971 void correctMC(const char* fileNameCorrections, const char* fileNameESD = 0, Int_t compareStep = -1, Int_t compareRegion = 2, Int_t compareUEHist = 0)
1972 {
1973   // corrects the reconstructed step in fileNameESD with fileNameCorr
1974   // if fileNameESD is 0 data from fileNameCorr is taken
1975   // afterwards the corrected distributions are compared with the MC stored in fileNameESD
1976   
1977   loadlibs();
1978   
1979   AliUEHistograms* corr = (AliUEHistograms*) GetUEHistogram(fileNameCorrections);
1980   SetupRanges(corr);
1981   
1982   corr->ExtendTrackingEfficiency();
1983   
1984   AliUEHistograms* testSample = corr;
1985   if (fileNameESD)
1986     testSample = (AliUEHistograms*) GetUEHistogram(fileNameESD);
1987       
1988   // copy to esd object
1989   AliUEHistograms* esd = (AliUEHistograms*) corr->Clone();
1990   esd->Reset();
1991   esd->CopyReconstructedData(testSample);
1992   
1993   SetupRanges(corr);
1994   SetupRanges(testSample);
1995   SetupRanges(esd);
1996   
1997   esd->Correct(corr);
1998   
1999   list = new TList;
2000   list->Add(esd);
2001   
2002   file3 = TFile::Open("correctedMC.root", "RECREATE");
2003   file3->mkdir("PWG4_PhiCorrelations");
2004   file3->cd("PWG4_PhiCorrelations");
2005   list->Write("histosPhiCorrelations", TObject::kSingleKey);
2006   file3->Close();
2007   
2008   if (1)
2009     DrawRatios(esd, testSample, compareStep, compareRegion, compareUEHist);
2010   
2011   if (1)
2012   {
2013     esd->SetPtRange(2.01, 3.99);
2014     corrected = esd->GetUEHist(2)->GetUEHist(0, 0, 4.01, 7.99, 0, -1, 1);
2015     testSample->SetPtRange(2.01, 3.99);
2016     mc = testSample->GetUEHist(2)->GetUEHist(0, 0, 4.01, 7.99, 0, -1, 1);
2017     new TCanvas; corrected->DrawCopy("SURF1");
2018     new TCanvas; mc->DrawCopy("SURF1");
2019     new TCanvas; mc->DrawCopy("SURF1")->Divide(corrected);
2020   }
2021   
2022   //CompareEventsTracks(esd, testSample, compareStep, compareRegion, compareUEHist);
2023 }
2024
2025 // function to compare only final step for all regions and distributions
2026
2027 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)
2028 {
2029   // corrects fileNameESD with fileNameCorrections and compares the two
2030   
2031   loadlibs();
2032   
2033   AliUEHistograms* corr = (AliUEHistograms*) GetUEHistogram(fileNameCorrections);
2034   
2035   TList* list = 0;
2036   AliUEHistograms* esd = (AliUEHistograms*) GetUEHistogram(fileNameESD, &list);
2037   
2038   SetupRanges(corr);
2039   SetupRanges(esd);
2040   
2041   Float_t etaRange = 1.2;
2042   Printf(">>>>> Using eta range: |eta| < %f", etaRange);
2043   corr->SetEtaRange(-etaRange+0.01, etaRange-0.01);
2044   corr->ExtendTrackingEfficiency(0);
2045   
2046 //   corr->GetUEHist(2)->GetTrackEfficiency(AliUEHist::kCFStepTracked, AliUEHist::kCFStepTrackedOnlyPrim, 1, -1, 2);
2047 //   return;
2048   
2049   if (contEnhancement)
2050   {
2051     TFile::Open(contEnhancement);
2052     contEncHist = (TH1*) gFile->Get("histo");
2053     contEncHistFullRange = (TH1*) corr->GetUEHist(0)->GetTrackingEfficiency(1)->Clone("contEncHistFullRange");
2054     
2055     contEncHistFullRange->Reset();
2056     for (Int_t i=1; i<=contEncHistFullRange->GetNbinsX(); i++)
2057     {
2058       contEncHistFullRange->SetBinContent(i, 1);
2059       if (i <= contEncHist->GetNbinsX() && contEncHist->GetXaxis()->GetBinCenter(i) < contEncUpTo && contEncHist->GetBinContent(i) > 0)
2060         contEncHistFullRange->SetBinContent(i, contEncHist->GetBinContent(i));
2061     }
2062     corr->SetContaminationEnhancement((TH1F*) contEncHistFullRange);
2063   }
2064   
2065   esd->Correct(corr);
2066   //esd->GetUEHist(2)->AdditionalDPhiCorrection(0);
2067   
2068   file3 = TFile::Open("corrected.root", "RECREATE");
2069   file3->mkdir("PWG4_PhiCorrelations");
2070   file3->cd("PWG4_PhiCorrelations");
2071   list->Write("histosPhiCorrelations", TObject::kSingleKey);
2072   file3->Close();
2073   
2074 //   DrawRatios(esd, corr, compareStep, compareRegion, compareUEHist);
2075 }
2076
2077 void ITSTPCEfficiency(const char* fileNameData, Int_t id, Int_t itsTPC = 0)
2078 {
2079   // its = 0; tpc = 1
2080
2081   // uncertainty from dN/dpT paper
2082   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};
2083   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
2084   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
2085
2086   TH1F* effHist = new TH1F("effHist", "effHist", 39, pTBins);
2087   for (Int_t i=0; i<39; i++)
2088   {
2089     Int_t bin = i;
2090     if (i > 16)
2091       bin = 16;
2092     effHist->SetBinContent(i+1, (itsTPC == 0) ? effITS[bin] : effTPC[bin]);
2093   }
2094
2095   new TCanvas; effHist->Draw();
2096
2097   EffectOfModifiedTrackingEfficiency(fileNameData, id, 2, effHist, 1, -1, (itsTPC == 0) ? "ITS" : "TPC");
2098
2099
2100
2101 void EffectOfModifiedTrackingEfficiency(const char* fileNameData, Int_t id, Int_t region, TH1* trackingEff, Int_t axis1, Int_t axis2 = -1, const char* name = "EffectOfModifiedTrackingEfficiency")
2102 {
2103   // trackingEff should contain the change in tracking efficiency, i.e. between before and after in the eta-pT plane
2104
2105   loadlibs();
2106   
2107   AliUEHistograms* corrected = (AliUEHistograms*) GetUEHistogram(fileNameData);
2108   SetupRanges(corrected);
2109   
2110   AliUEHist* ueHist = corrected->GetUEHist(id);
2111   
2112   Float_t ptLeadMin = -1;
2113   Float_t ptLeadMax = -1;
2114   if (id == 2)
2115   {
2116     // the uncertainty is flat in delta phi, so use this trick to get directly the uncertainty as function of leading pT
2117     //ptLeadMin = 1.01;
2118     //ptLeadMax = 1.99;
2119   }
2120     
2121   // histogram before
2122   TH1* before = ueHist->GetUEHist(AliUEHist::kCFStepAll, region, ptLeadMin, ptLeadMax);
2123
2124   // copy histogram
2125   // the CFStepTriggered step is overwritten here and cannot be used for comparison afterwards anymore
2126   ueHist->CorrectTracks(AliUEHist::kCFStepAll, AliUEHist::kCFStepTriggered, (TH1*) 0, 0, -1);
2127
2128   // reapply tracking efficiency
2129   ueHist->CorrectTracks(AliUEHist::kCFStepTriggered, AliUEHist::kCFStepAll, trackingEff, axis1, axis2);
2130
2131   // histogram after
2132   TH1* after = ueHist->GetUEHist(AliUEHist::kCFStepAll, region, ptLeadMin, ptLeadMax);
2133   
2134   DrawRatio(before, after, name);
2135   gPad->GetCanvas()->SaveAs(Form("%s.png", name));
2136 }
2137
2138 void EffectOfTrackCuts(const char* fileNameData, Int_t id, const char* systFile)
2139 {
2140   loadlibs();
2141
2142   AliUEHistograms* corrected = (AliUEHistograms*) GetUEHistogram(fileNameData);
2143   effHist = (TH2D*) corrected->GetUEHist(0)->GetTrackingEfficiency()->Clone("effHist");
2144
2145   file = TFile::Open(systFile);
2146
2147   Int_t maxSyst = 3;
2148   const char* systNames[] = { "NClusTPC", "Chi2TPC", "SigmaDCA" };
2149
2150   for (Int_t i=0; i<maxSyst; i++)
2151   {
2152     for (Int_t j=0; j<2; j++)
2153     {
2154       TString histName;
2155       histName.Form("%s_syst_%s", systNames[i], (j == 0) ? "up" : "down");
2156       systEffect = (TH2*) file->Get(histName);
2157
2158       // rebin
2159       effHist->Reset();
2160       for (Int_t x=1; x <= effHist->GetNbinsX(); x++)
2161         for (Int_t y=1; y <= effHist->GetNbinsY(); y++)
2162           effHist->SetBinContent(x, y, 1);
2163
2164       for (Int_t x=1; x <= systEffect->GetNbinsX(); x++)
2165         for (Int_t y=1; y <= systEffect->GetNbinsY(); y++)
2166           if (systEffect->GetBinContent(x, y) != 0)
2167             effHist->SetBinContent(effHist->GetXaxis()->FindBin(systEffect->GetYaxis()->GetBinCenter(y)), effHist->GetYaxis()->FindBin(systEffect->GetXaxis()->GetBinCenter(x)), systEffect->GetBinContent(x, y));
2168            
2169    
2170       //new TCanvas; systEffect->Draw("COLZ"); new TCanvas; effHist->Draw("COLZ");
2171  
2172       EffectOfModifiedTrackingEfficiency(fileNameData, id, (id == 2) ? 0 : 2, effHist, 0, 1, histName);
2173
2174       //return;
2175     }
2176   } 
2177 }
2178
2179 void ModifyComposition(const char* fileNameData, const char* fileNameCorrections, Int_t id, Bool_t verbose = kFALSE)
2180 {
2181   loadlibs();
2182   
2183   AliUEHistograms* corrected = (AliUEHistograms*) GetUEHistogram(fileNameData);
2184   SetupRanges(corrected);
2185   
2186   AliUEHistograms* corrections = (AliUEHistograms*) GetUEHistogram(fileNameCorrections);
2187   SetupRanges(corrections);
2188   
2189   ueHistData        = (AliUEHist*) corrected->GetUEHist(id);
2190   ueHistCorrections = (AliUEHist*) corrections->GetUEHist(id);
2191   
2192   // copy histogram
2193   // the CFStepTriggered step is overwritten here and cannot be used for comparison afterwards anymore
2194   ueHistData->CorrectTracks(AliUEHist::kCFStepAll, AliUEHist::kCFStepTriggered, (TH1*) 0, 0);
2195   
2196   Int_t maxRegion = 3;
2197   Float_t ptLeadMin = -1;
2198   Float_t ptLeadMax = -1;
2199   if (id == 2)
2200   {
2201     maxRegion = 1;
2202     // the uncertainty is flat in delta phi, so use this trick to get directly the uncertainty as function of leading pT
2203     //ptLeadMin = 1.01;
2204     //ptLeadMax = 1.99;
2205   }
2206   
2207   // histogram before
2208   TH1* before[3];
2209   for (Int_t region=0; region<maxRegion; region++)
2210     before[region] = ueHistData->GetUEHist(AliUEHist::kCFStepAll, region, ptLeadMin, ptLeadMax);
2211   
2212   //defaultEff = ueHistCorrections->GetTrackingEfficiency();
2213   defaultEff = ueHistCorrections->GetTrackingCorrection();
2214   //defaultEffpT = ueHistCorrections->GetTrackingEfficiency(1);
2215   defaultEffpT = ueHistCorrections->GetTrackingCorrection(1);
2216   defaultContainer = ueHistCorrections->GetTrackHistEfficiency();
2217   
2218   c = new TCanvas;
2219   defaultEffpT->Draw("");
2220   
2221   Float_t largestDeviation[3];
2222   for (Int_t i=0; i<maxRegion; i++)
2223     largestDeviation[i] = 0;  
2224   
2225   for (Int_t i=0; i<7; i++)
2226   {
2227     // case 0: // default
2228     // case 1: // + 30% kaons
2229     // case 2: // - 30% kaons
2230     // case 3: // + 30% protons
2231     // case 4: // - 30% protons
2232     // case 5: // + 30% others
2233     // case 6: // - 30% others
2234     Int_t correctionIndex = (i+1) / 2 + 1; // bin 1 == protons, bin 2 == kaons, ...
2235     Double_t scaleFactor = (i % 2 == 1) ? 1.3 : 0.7;
2236     if (i == 0)
2237       scaleFactor = 1;
2238     
2239     newContainer = (AliCFContainer*) defaultContainer->Clone();
2240     
2241     // modify, change all steps
2242     for (Int_t j=0; j<newContainer->GetNStep(); j++)
2243     {
2244       THnSparse* grid = newContainer->GetGrid(j)->GetGrid();
2245       
2246       for (Int_t binIdx = 0; binIdx < grid->GetNbins(); binIdx++)
2247       {
2248         Int_t bins[5];
2249         Double_t value = grid->GetBinContent(binIdx, bins);
2250         Double_t error = grid->GetBinError(binIdx);
2251         
2252         if (bins[2] != correctionIndex)
2253           continue;
2254     
2255         value *= scaleFactor;
2256         error *= scaleFactor;
2257     
2258         grid->SetBinContent(bins, value);
2259         grid->SetBinError(bins, error);      
2260       }
2261     }
2262     
2263     // put in corrections
2264     ueHistCorrections->SetTrackHistEfficiency(newContainer);
2265     
2266     // ratio
2267     //modifiedEff = ueHistCorrections->GetTrackingEfficiency();
2268     modifiedEff = ueHistCorrections->GetTrackingCorrection();
2269     modifiedEff->Divide(modifiedEff, defaultEff);
2270     //modifiedEff->Draw("COLZ");
2271     
2272     c->cd();
2273     //modifiedEffpT = ueHistCorrections->GetTrackingEfficiency(1);
2274     modifiedEffpT = ueHistCorrections->GetTrackingCorrection(1);
2275     modifiedEffpT->SetLineColor(i+1);
2276     modifiedEffpT->Draw("SAME");
2277     
2278     // apply change in tracking efficiency
2279     ueHistData->CorrectTracks(AliUEHist::kCFStepTriggered, AliUEHist::kCFStepAll, modifiedEff, 0, 1);
2280   
2281     for (Int_t region=0; region<maxRegion; region++)
2282     {
2283       // histogram after
2284       TH1* after = ueHistData->GetUEHist(AliUEHist::kCFStepAll, region, ptLeadMin, ptLeadMax);
2285       
2286       if (verbose)
2287         DrawRatio(before[region], (TH1*) after->Clone(), Form("Region %d Composition %d", region, i));
2288       
2289       // ratio is flat, extract deviation
2290       after->Divide(before[region]);
2291       after->Fit("pol0", "0");
2292       Float_t deviation = 100.0 - 100.0 * after->GetFunction("pol0")->GetParameter(0);
2293       Printf("Deviation for region %d case %d is %.2f %%", region, i, deviation);
2294       
2295       if (TMath::Abs(deviation) > largestDeviation[region])
2296         largestDeviation[region] = TMath::Abs(deviation);
2297     }
2298     //return;
2299   }
2300   
2301   for (Int_t i=0; i<maxRegion; i++)
2302     Printf("Largest deviation in region %d is %f", i, largestDeviation[i]);
2303 }    
2304
2305 void MergeList(const char* prefix = "", const char* suffix = "", Bool_t copy = kFALSE)
2306 {
2307   loadlibs();
2308   gSystem->Load("libPWGflowBase");
2309   gSystem->Load("libPWGflowTasks");
2310
2311   ifstream in;
2312   in.open("list");
2313
2314   TFileMerger m(copy);
2315
2316   TString line;
2317   while (in.good())
2318   {
2319     in >> line;
2320
2321     if (line.Length() == 0)
2322       continue;
2323
2324     TString fileName;
2325     fileName.Form("%s%s%s", prefix, line.Data(), suffix);
2326 //     fileName.Form("alien://%s", line.Data());
2327     Printf("%s", fileName.Data());
2328     
2329     m.AddFile(fileName);
2330   }
2331   
2332   m.SetFastMethod();
2333   m.OutputFile("merged.root");
2334   m.Merge();
2335 }
2336
2337 void Merge2(const char* file1, const char* file2)
2338 {
2339   loadlibs();
2340   TFileMerger m(0);
2341
2342   m.AddFile(file1);
2343   m.AddFile(file2);
2344   
2345   m.SetFastMethod();
2346   m.OutputFile("merged.root");
2347   m.Merge();
2348 }
2349
2350 void Merge3(const char* file1, const char* file2, const char* file3)
2351 {
2352   loadlibs();
2353   TFileMerger m(1);
2354
2355   m.AddFile(file1);
2356   m.AddFile(file2);
2357   m.AddFile(file3);
2358   
2359   m.SetFastMethod();
2360   m.OutputFile("merged.root");
2361   m.Merge();
2362 }
2363
2364 void MergeList2(const char* listFile, const char* dir, Bool_t onlyPrintEvents = kFALSE, const char* targetDir = "PWG4_LeadingTrackUE")
2365 {
2366   loadlibs();
2367
2368   ifstream in;
2369   in.open(listFile);
2370   
2371   AliUEHistograms* final = 0;
2372   TList* finalList = 0;
2373
2374   TString line;
2375   while (in.good())
2376   {
2377     in >> line;
2378
2379     if (line.Length() == 0)
2380       continue;
2381
2382     TString fileName;
2383     fileName.Form("%s/%s/PWG4_JetTasksOutput.root", dir, line.Data());
2384     Printf("%s", fileName.Data());
2385     
2386     TList* list = 0;
2387     AliUEHistograms* obj = (AliUEHistograms*) GetUEHistogram(fileName, &list);
2388     if (!obj)
2389       continue;
2390     
2391     if (!final)
2392     {
2393       final = (AliUEHistograms*) obj;
2394       //final->GetEventCount()->Draw(); return;
2395       Printf("Events: %d", (Int_t) final->GetEventCount()->ProjectionX()->GetBinContent(4));
2396       finalList = list;
2397     }
2398     else
2399     {
2400       additional = (AliUEHistograms*) obj;
2401       Printf("Events: %d", (Int_t) additional->GetEventCount()->ProjectionX()->GetBinContent(4));
2402       
2403       if (!onlyPrintEvents)
2404       {
2405         TList list2;
2406         list2.Add(additional);
2407         final->Merge(&list2);
2408       }
2409       delete additional;
2410       gFile->Close();
2411     }
2412   }
2413   
2414   if (onlyPrintEvents)
2415     return;
2416     
2417   Printf("Total events (at step 0): %d", (Int_t) final->GetEventCount()->ProjectionX()->GetBinContent(4));
2418   
2419   file3 = TFile::Open("merged.root", "RECREATE");
2420   file3->mkdir(targetDir);
2421   file3->cd(targetDir);
2422   finalList->Write(0, TObject::kSingleKey);
2423   file3->Close();
2424 }
2425
2426 void PlotAll(const char* correctedFile, const char* mcFile)
2427 {
2428   gCache = 1;
2429   
2430   if (gEnergy == 900)
2431   {
2432     Float_t range[] = { 1.5, 2 };
2433   }
2434   else
2435   {
2436     Float_t range[] = { 3, 10 };
2437   }
2438   
2439   for (Int_t id=0; id<3; id++)
2440   {
2441     if (id < 2)
2442       gForceRange = range[id];
2443     else
2444       gForceRange = -1;
2445       
2446     if (id < 2)
2447     {
2448       for (Int_t region=0; region<3; region++)
2449       {
2450         CompareStep(correctedFile, mcFile, id, 0, region);
2451         gPad->GetCanvas()->SaveAs(Form("%s_%s_%d_%d.png", TString(correctedFile).Tokenize(".")->First()->GetName(), TString(mcFile).Tokenize(".")->First()->GetName(), id, region));
2452       }
2453     }
2454     else
2455     {
2456       Float_t leadingPtArr[] = { 0.50, 2.0, 4.0, 6.0, 10.0, 20.0, 50.0 };
2457       for (Int_t leadingPtID=0; leadingPtID<6; leadingPtID++)
2458       {
2459         CompareStep(correctedFile, mcFile, id, 0, 0, leadingPtArr[leadingPtID] + 0.01, leadingPtArr[leadingPtID+1] - 0.01);
2460         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]));
2461       }
2462     }
2463   }
2464 }
2465
2466 /*
2467 TGraph* GetFlow2040()
2468 {
2469   // from first ALICE flow paper (provided by Raimond)
2470   // http://www-library.desy.de/spires/find/hep/www?eprint=arXiv:1011.3914
2471   
2472   // centrality 20-30% 
2473   Double_t xCumulant4th2030ALICE[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
2474   1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000,
2475   5.500000,7.000000,9.000000};
2476   Double_t yCumulant4th2030ALICE[] = {0.000000,0.000000,0.030926,0.041076,0.052063,0.059429,0.070500,0.084461,0.086745,0.099254,
2477   0.109691,0.116398,0.130831,0.141959,0.158932,0.169680,0.171387,0.178858,0.171475,0.140358,
2478   0.000000,0.000000,0.000000};
2479   Double_t xErrCumulant4th2030ALICE[23] = {0.};
2480   Double_t yErrCumulant4th2030ALICE[] = {0.000000,0.000000,0.002857,0.003451,0.003567,0.003859,0.004609,0.004976,0.005412,0.006277,
2481   0.004748,0.005808,0.006896,0.007987,0.008683,0.008080,0.013278,0.018413,0.024873,0.026057,
2482   0.000000,0.000000,0.000000};
2483   Int_t nPointsCumulant4th2030ALICE = sizeof(xCumulant4th2030ALICE)/sizeof(Double_t);                                      
2484   TGraphErrors *Cumulant4th2030ALICE = new TGraphErrors(nPointsCumulant4th2030ALICE,xCumulant4th2030ALICE,yCumulant4th2030ALICE,
2485                                                         xErrCumulant4th2030ALICE,yErrCumulant4th2030ALICE);
2486   Cumulant4th2030ALICE->SetMarkerStyle(kFullSquare);
2487   Cumulant4th2030ALICE->SetMarkerColor(kRed);
2488   Cumulant4th2030ALICE->SetMarkerSize(1.2);
2489   Cumulant4th2030ALICE->SetFillStyle(1001);
2490   Cumulant4th2030ALICE->SetFillColor(kRed-10);
2491   
2492   //===================================================================================================================
2493   // centrality 30-40% 
2494   Double_t xCumulant4th3040ALICE[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
2495   1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000,
2496   5.500000,7.000000,9.000000};
2497   Double_t yCumulant4th3040ALICE[] = {0.000000,0.000000,0.037071,0.048566,0.061083,0.070910,0.078831,0.091396,0.102026,0.109691,
2498   0.124449,0.139819,0.155561,0.165701,0.173678,0.191149,0.202015,0.204540,0.212560,0.195885,
2499   0.000000,0.000000,0.000000};
2500   Double_t xErrCumulant4th3040ALICE[23] = {0.};
2501   Double_t yErrCumulant4th3040ALICE[] = {0.000000,0.000000,0.002992,0.003364,0.003669,0.003931,0.004698,0.005261,0.005446,0.006151,
2502   0.004980,0.005741,0.007198,0.008576,0.010868,0.009926,0.015269,0.020691,0.027601,0.031834,
2503   0.000000,0.000000,0.000000};
2504   Int_t nPointsCumulant4th3040ALICE = sizeof(xCumulant4th3040ALICE)/sizeof(Double_t);
2505   TGraphErrors *Cumulant4th3040ALICE = new TGraphErrors(nPointsCumulant4th3040ALICE,xCumulant4th3040ALICE,yCumulant4th3040ALICE,
2506                                                         xErrCumulant4th3040ALICE,yErrCumulant4th3040ALICE);
2507   Cumulant4th3040ALICE->SetMarkerStyle(kFullTriangleUp);
2508   Cumulant4th3040ALICE->SetMarkerColor(kGreen+2);
2509   Cumulant4th3040ALICE->SetMarkerSize(1.2);
2510   Cumulant4th3040ALICE->SetFillStyle(1001);
2511   Cumulant4th3040ALICE->SetFillColor(kGreen+2);
2512   
2513   // build average between the two (for class 20-40%)
2514   Double_t* yAverage = new Double_t[nPointsCumulant4th3040ALICE];
2515   for (Int_t i=0; i<nPointsCumulant4th3040ALICE; i++)
2516     yAverage[i] = (yCumulant4th2030ALICE[i] + yCumulant4th3040ALICE[i]) / 2;
2517     
2518   // assume flow constant above highest pT; not neccessarily physically sound ;)
2519   if (1)
2520   {
2521     yAverage[20] = yAverage[19];
2522     xCumulant4th3040ALICE[20] = 100;
2523     nPointsCumulant4th3040ALICE -= 2;
2524   }
2525   
2526   TGraph *flow2040 = new TGraph(nPointsCumulant4th3040ALICE,xCumulant4th3040ALICE,yAverage);
2527   
2528   if (0)
2529   {
2530     flow2040->Draw("*A");
2531     Cumulant4th2030ALICE->Draw("PSAME");
2532     Cumulant4th3040ALICE->Draw("PSAME");
2533   }
2534   
2535   return flow2040;
2536 }
2537 */
2538
2539 /*
2540 TGraph* GetFlow1020()
2541 {
2542   // from first ALICE flow paper (provided by Raimond)
2543   // http://www-library.desy.de/spires/find/hep/www?eprint=arXiv:1011.3914
2544   
2545   //===================================================================================================================
2546   // centrality 10-20% 
2547   Double_t xCumulant4th1020ALICE[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
2548   1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000,
2549   5.500000,7.000000,9.000000};
2550   Double_t yCumulant4th1020ALICE[] = {0.000000,0.000000,0.024075,0.031505,0.040413,0.044981,0.055358,0.060563,0.063378,0.070030,
2551   0.082692,0.091611,0.099641,0.107223,0.122376,0.131240,0.137425,0.146050,0.131365,0.124708,
2552   0.000000,0.000000,0.000000};
2553   Double_t xErrCumulant4th1020ALICE[23] = {0.};
2554   Double_t yErrCumulant4th1020ALICE[] = {0.000000,0.000000,0.002413,0.002931,0.003444,0.003950,0.004338,0.004835,0.005059,0.005586,
2555   0.004521,0.005278,0.005999,0.007072,0.008260,0.007279,0.011897,0.017409,0.023995,0.025701,
2556   0.000000,0.000000,0.000000};
2557   Int_t nPointsCumulant4th1020ALICE = sizeof(xCumulant4th1020ALICE)/sizeof(Double_t);                                      
2558   
2559   // assume flow constant above highest pT; not neccessarily physically sound ;)
2560   if (1)
2561   {
2562     yCumulant4th1020ALICE[20] = yCumulant4th1020ALICE[19];
2563     xCumulant4th1020ALICE[20] = 100;
2564     nPointsCumulant4th1020ALICE -= 2;
2565   }
2566   
2567   TGraphErrors *Cumulant4th1020ALICE = new TGraphErrors(nPointsCumulant4th1020ALICE,xCumulant4th1020ALICE,yCumulant4th1020ALICE,
2568                                                         xErrCumulant4th1020ALICE,yErrCumulant4th1020ALICE);
2569   
2570  Cumulant4th1020ALICE->SetMarkerStyle(kFullCircle);
2571  Cumulant4th1020ALICE->SetMarkerColor(kBlue);
2572  Cumulant4th1020ALICE->SetMarkerSize(1.2);
2573  Cumulant4th1020ALICE->SetFillStyle(1001);
2574  Cumulant4th1020ALICE->SetFillColor(kBlue-10);
2575   
2576   TGraph *flow1020 = new TGraph(nPointsCumulant4th1020ALICE,xCumulant4th1020ALICE,yCumulant4th1020ALICE);
2577   
2578   if (0)
2579   {
2580     flow1020->Draw("*A");
2581     Cumulant4th1020ALICE->Draw("PSAME");
2582   }
2583   
2584   return flow1020;
2585 }
2586 */
2587
2588 /*
2589 TGraph* GetFlow05()
2590 {
2591   // takes flow measurement from 10-20% and scales by a factor extracted from Fig.3 in the ALICE flow paper
2592   // factor = integrated flow in 0-5% / integrated flow in 10-20%
2593   
2594   graph = GetFlow1020();
2595   for (Int_t i=0; i<graph->GetN(); i++)
2596     graph->GetY()[i] *= 0.016 / 0.055;
2597     
2598   return graph;
2599 }
2600 */
2601 TGraphErrors* GetFlow01_Rap02(Int_t n)
2602 {
2603   // private communication 19.04.11, Raimond / Ante
2604
2605   if (n == 2)
2606   {
2607     //  v2{SP}(pt) for 0-1%, rapidity gap = 0.2:
2608     const Int_t nPointsSP_0001ALICE_v2_etaGap02 = 18;
2609     Double_t xSP_0001ALICE_v2_etaGap02[nPointsSP_0001ALICE_v2_etaGap02] = {0.250000,0.350000,0.450000,0.550000,0.650000,
2610     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};
2611     Double_t ySP_0001ALICE_v2_etaGap02[nPointsSP_0001ALICE_v2_etaGap02] = {0.009235,0.014105,0.017274,0.018245,0.023190,
2612     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};
2613     Double_t xErrSP_0001ALICE_v2_etaGap02[nPointsSP_0001ALICE_v2_etaGap02] = {0.};
2614     Double_t yErrSP_0001ALICE_v2_etaGap02[nPointsSP_0001ALICE_v2_etaGap02] = {0.000515,0.000504,0.000532,0.000585,0.000641,
2615     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};
2616     TGraphErrors *SP_0001ALICE_v2_etaGap02 = new TGraphErrors(nPointsSP_0001ALICE_v2_etaGap02,xSP_0001ALICE_v2_etaGap02,
2617                                                               ySP_0001ALICE_v2_etaGap02,xErrSP_0001ALICE_v2_etaGap02,yErrSP_0001ALICE_v2_etaGap02);
2618     SP_0001ALICE_v2_etaGap02->SetMarkerStyle(kFullCircle);
2619     SP_0001ALICE_v2_etaGap02->SetMarkerColor(kBlue);  
2620     SP_0001ALICE_v2_etaGap02->SetFillStyle(1001);
2621     SP_0001ALICE_v2_etaGap02->SetFillColor(kBlue-10);  
2622     
2623     return SP_0001ALICE_v2_etaGap02;
2624   }
2625   
2626   if (n == 3)
2627   {
2628     //  v3{SP}(pt) for 0-1%, rapidity gap = 0.2:
2629     const Int_t nPointsSP_0001ALICE_v3_etaGap02 = 18;
2630     Double_t xSP_0001ALICE_v3_etaGap02[nPointsSP_0001ALICE_v3_etaGap02] = {0.250000,0.350000,0.450000,0.550000,0.650000,
2631     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};
2632     Double_t ySP_0001ALICE_v3_etaGap02[nPointsSP_0001ALICE_v3_etaGap02] = {0.005688,0.007222,0.010305,0.013795,0.016077,
2633     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};
2634     Double_t xErrSP_0001ALICE_v3_etaGap02[nPointsSP_0001ALICE_v3_etaGap02] = {0.};
2635     Double_t yErrSP_0001ALICE_v3_etaGap02[nPointsSP_0001ALICE_v3_etaGap02] = {0.000585,0.000582,0.000614,0.000667,0.000734,
2636     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};
2637     TGraphErrors *SP_0001ALICE_v3_etaGap02 = new TGraphErrors(nPointsSP_0001ALICE_v3_etaGap02,xSP_0001ALICE_v3_etaGap02,ySP_0001ALICE_v3_etaGap02,
2638                                                               xErrSP_0001ALICE_v3_etaGap02,yErrSP_0001ALICE_v3_etaGap02);
2639     SP_0001ALICE_v3_etaGap02->SetMarkerStyle(kFullTriangleUp);
2640     SP_0001ALICE_v3_etaGap02->SetMarkerSize(1.4);  
2641     SP_0001ALICE_v3_etaGap02->SetMarkerColor(kGreen+2);
2642     SP_0001ALICE_v3_etaGap02->SetFillStyle(1001);
2643     SP_0001ALICE_v3_etaGap02->SetFillColor(kGreen-10);     
2644     
2645     return SP_0001ALICE_v3_etaGap02;
2646   }
2647    
2648   if (n == 4)
2649   {
2650     //  v4{SP}(pt) for 0-1%, rapidity gap = 0.2:
2651     const Int_t nPointsSP_0001ALICE_v4_etaGap02 = 18;
2652     Double_t xSP_0001ALICE_v4_etaGap02[nPointsSP_0001ALICE_v4_etaGap02] = {0.250000,0.350000,0.450000,0.550000,0.650000,
2653     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};
2654     Double_t ySP_0001ALICE_v4_etaGap02[nPointsSP_0001ALICE_v4_etaGap02] = {0.001189,0.003540,0.004682,0.004210,0.007032,
2655     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};
2656     Double_t xErrSP_0001ALICE_v4_etaGap02[nPointsSP_0001ALICE_v4_etaGap02] = {0.};
2657     Double_t yErrSP_0001ALICE_v4_etaGap02[nPointsSP_0001ALICE_v4_etaGap02] = {0.001035,0.001017,0.001081,0.001187,0.001299,
2658     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};
2659     TGraphErrors *SP_0001ALICE_v4_etaGap02 = new TGraphErrors(nPointsSP_0001ALICE_v4_etaGap02,xSP_0001ALICE_v4_etaGap02,ySP_0001ALICE_v4_etaGap02,
2660                                                               xErrSP_0001ALICE_v4_etaGap02,yErrSP_0001ALICE_v4_etaGap02);
2661     SP_0001ALICE_v4_etaGap02->SetMarkerStyle(kFullSquare);
2662     SP_0001ALICE_v4_etaGap02->SetMarkerColor(kRed);
2663     SP_0001ALICE_v4_etaGap02->SetFillStyle(1001);
2664     SP_0001ALICE_v4_etaGap02->SetFillColor(kRed-10);  
2665     
2666     return SP_0001ALICE_v4_etaGap02;
2667   }
2668   
2669   return 0;
2670 }
2671
2672 TGraphErrors* GetFlow01_Rap10(Int_t n)
2673 {
2674   if (n == 2)
2675   {
2676     //  v2{SP}(pt) for 0-1%, rapidity gap = 1.0:
2677     const Int_t nPointsSP_0001ALICE_v2_etaGap10 = 21;
2678     Double_t xSP_0001ALICE_v2_etaGap10[nPointsSP_0001ALICE_v2_etaGap10] = {0.250000,0.350000,0.450000,0.550000,0.650000,
2679     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,
2680     3.250000,3.750000,4.500000};
2681     Double_t ySP_0001ALICE_v2_etaGap10[nPointsSP_0001ALICE_v2_etaGap10] = {0.009129,0.013461,0.017567,0.018041,0.020384,
2682     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,
2683     0.036905,0.054836,0.030527};
2684     Double_t xErrSP_0001ALICE_v2_etaGap10[nPointsSP_0001ALICE_v2_etaGap10] = {0.};
2685     Double_t yErrSP_0001ALICE_v2_etaGap10[nPointsSP_0001ALICE_v2_etaGap10] = {0.001179,0.001152,0.001219,0.001339,0.001480,
2686     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,
2687     0.009145,0.014749,0.018698};
2688     TGraphErrors *SP_0001ALICE_v2_etaGap10 = new TGraphErrors(nPointsSP_0001ALICE_v2_etaGap10,xSP_0001ALICE_v2_etaGap10,
2689                                                               ySP_0001ALICE_v2_etaGap10,xErrSP_0001ALICE_v2_etaGap10,yErrSP_0001ALICE_v2_etaGap10);
2690     SP_0001ALICE_v2_etaGap10->SetMarkerStyle(kOpenCircle);
2691     SP_0001ALICE_v2_etaGap10->SetMarkerColor(kBlue);  
2692     SP_0001ALICE_v2_etaGap10->SetFillStyle(1001);
2693     SP_0001ALICE_v2_etaGap10->SetFillColor(kBlue-10);  
2694     
2695     return SP_0001ALICE_v2_etaGap10;
2696   }
2697
2698   if (n == 3)
2699   {
2700     //  v3{SP}(pt) for 0-1%, rapidity gap = 1.0:
2701     const Int_t nPointsSP_0001ALICE_v3_etaGap10 = 18;
2702     Double_t xSP_0001ALICE_v3_etaGap10[nPointsSP_0001ALICE_v3_etaGap10] = {0.250000,0.350000,0.450000,0.550000,0.650000,
2703     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};
2704     Double_t ySP_0001ALICE_v3_etaGap10[nPointsSP_0001ALICE_v3_etaGap10] = {0.006373,0.008403,0.010848,0.011505,0.016728,
2705     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};
2706     Double_t xErrSP_0001ALICE_v3_etaGap10[nPointsSP_0001ALICE_v3_etaGap10] = {0.};
2707     Double_t yErrSP_0001ALICE_v3_etaGap10[nPointsSP_0001ALICE_v3_etaGap10] = {0.001286,0.001269,0.001346,0.001474,0.001620,
2708     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};
2709     TGraphErrors *SP_0001ALICE_v3_etaGap10 = new TGraphErrors(nPointsSP_0001ALICE_v3_etaGap10,xSP_0001ALICE_v3_etaGap10,ySP_0001ALICE_v3_etaGap10,
2710                                                               xErrSP_0001ALICE_v3_etaGap10,yErrSP_0001ALICE_v3_etaGap10);
2711     SP_0001ALICE_v3_etaGap10->SetMarkerStyle(kOpenTriangleUp);
2712     SP_0001ALICE_v3_etaGap10->SetMarkerSize(1.2);  
2713     SP_0001ALICE_v3_etaGap10->SetMarkerColor(kGreen+2);
2714     SP_0001ALICE_v3_etaGap10->SetFillStyle(1001);
2715     SP_0001ALICE_v3_etaGap10->SetFillColor(kGreen-10);     
2716     
2717     return SP_0001ALICE_v3_etaGap10;
2718   }
2719
2720   if (n == 4)
2721   {
2722     //  v4{SP}(pt) for 0-1%, rapidity gap = 1.0:
2723     const Int_t nPointsSP_0001ALICE_v4_etaGap10 = 11;
2724     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};
2725     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};
2726     Double_t xErrSP_0001ALICE_v4_etaGap10[nPointsSP_0001ALICE_v4_etaGap10] = {0.};
2727     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};
2728     TGraphErrors *SP_0001ALICE_v4_etaGap10 = new TGraphErrors(nPointsSP_0001ALICE_v4_etaGap10,xSP_0001ALICE_v4_etaGap10,ySP_0001ALICE_v4_etaGap10,
2729                                                               xErrSP_0001ALICE_v4_etaGap10,yErrSP_0001ALICE_v4_etaGap10);
2730     SP_0001ALICE_v4_etaGap10->SetMarkerStyle(kOpenSquare);
2731     SP_0001ALICE_v4_etaGap10->SetMarkerColor(kRed);
2732     SP_0001ALICE_v4_etaGap10->SetFillStyle(1001);
2733     SP_0001ALICE_v4_etaGap10->SetFillColor(kRed-10);  
2734     
2735     return SP_0001ALICE_v4_etaGap10;
2736   }
2737   
2738   if (n == 5)
2739   {
2740     //  v5{SP}(pt) for 0-1%, rapidity gap = 1.0:
2741     const Int_t nPointsSP_0001ALICE_v5_etaGap10 = 11;
2742     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};
2743     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};
2744     Double_t xErrSP_0001ALICE_v5_etaGap10[nPointsSP_0001ALICE_v5_etaGap10] = {0.};
2745     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};
2746     TGraphErrors *SP_0001ALICE_v5_etaGap10 = new TGraphErrors(nPointsSP_0001ALICE_v5_etaGap10,xSP_0001ALICE_v5_etaGap10,ySP_0001ALICE_v5_etaGap10,
2747                                                               xErrSP_0001ALICE_v5_etaGap10,yErrSP_0001ALICE_v5_etaGap10);
2748     return SP_0001ALICE_v5_etaGap10;
2749   }
2750 }
2751
2752 TGraphErrors* GetFlow02_Rap10(Int_t n)
2753 {
2754   // private communication 20.04.11, Ante B. / Raimond
2755
2756   if (n == 2)
2757   {
2758      //  v2{SP}(pt) for 00-02%, eta gap = 1.0:
2759     const Int_t nPointsSP_0002_v2_etaGap10 = 15;
2760     Double_t xSP_0002_v2_etaGap10[nPointsSP_0002_v2_etaGap10] = {0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,
2761     0.900000,1.100000,1.350000,1.650000,1.950000,2.250000,2.700000,3.500000,4.500000};
2762     Double_t ySP_0002_v2_etaGap10[nPointsSP_0002_v2_etaGap10] = {0.010171,0.013190,0.017342,0.020629,0.022617,0.026549,
2763     0.027423,0.032261,0.037467,0.041001,0.045763,0.049327,0.049688,0.051480,0.038527};
2764     Double_t xErrSP_0002_v2_etaGap10[nPointsSP_0002_v2_etaGap10] = {0.};
2765     Double_t yErrSP_0002_v2_etaGap10[nPointsSP_0002_v2_etaGap10] = {0.000600,0.000590,0.000625,0.000683,0.000757,0.000839,
2766     0.000692,0.000848,0.000888,0.001209,0.001653,0.002252,0.002465,0.003968,0.009391};
2767     TGraphErrors *SP_0002_v2_etaGap10 = new TGraphErrors(nPointsSP_0002_v2_etaGap10,xSP_0002_v2_etaGap10,ySP_0002_v2_etaGap10,
2768                                                   xErrSP_0002_v2_etaGap10,yErrSP_0002_v2_etaGap10);
2769                                                   
2770     return SP_0002_v2_etaGap10;
2771   }
2772   
2773   if (n == 3)
2774   {
2775     const Int_t nPointsSP_0002_v3_etaGap10 = 15;
2776     Double_t xSP_0002_v3_etaGap10[nPointsSP_0002_v3_etaGap10] = {0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,
2777     0.900000,1.100000,1.350000,1.650000,1.950000,2.250000,2.700000,3.500000,4.500000};
2778     Double_t ySP_0002_v3_etaGap10[nPointsSP_0002_v3_etaGap10] = {0.006592,0.007286,0.012180,0.012242,0.017416,0.018393,
2779     0.024716,0.030980,0.037703,0.046558,0.051285,0.064613,0.074831,0.077093,0.082442};
2780     Double_t xErrSP_0002_v3_etaGap10[nPointsSP_0002_v3_etaGap10] = {0.};
2781     Double_t yErrSP_0002_v3_etaGap10[nPointsSP_0002_v3_etaGap10] = {0.000682,0.000676,0.000713,0.000782,0.000860,0.000953,
2782     0.000782,0.000957,0.001002,0.001361,0.001862,0.002541,0.002767,0.004466,0.010586};
2783     TGraphErrors *SP_0002_v3_etaGap10 = new TGraphErrors(nPointsSP_0002_v3_etaGap10,xSP_0002_v3_etaGap10,ySP_0002_v3_etaGap10,
2784                                                           xErrSP_0002_v3_etaGap10,yErrSP_0002_v3_etaGap10);    
2785                                                           
2786     return SP_0002_v3_etaGap10;
2787   }
2788   
2789   if (n == 4)
2790   {
2791     const Int_t nPointsSP_0002_v4_etaGap10 = 15;
2792     Double_t xSP_0002_v4_etaGap10[nPointsSP_0002_v4_etaGap10] = {0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,
2793     0.900000,1.100000,1.350000,1.650000,1.950000,2.250000,2.700000,3.500000,4.500000};
2794     Double_t ySP_0002_v4_etaGap10[nPointsSP_0002_v4_etaGap10] = {-0.000533,0.001167,0.002081,0.005218,0.006826,0.008440,
2795     0.013009,0.014812,0.017125,0.030106,0.038279,0.050488,0.067640,0.071637,0.084239};
2796     Double_t xErrSP_0002_v4_etaGap10[nPointsSP_0002_v4_etaGap10] = {0.};
2797     Double_t yErrSP_0002_v4_etaGap10[nPointsSP_0002_v4_etaGap10] = {0.001427,0.001398,0.001482,0.001594,0.001758,0.001945,
2798     0.001593,0.001951,0.002046,0.002787,0.003802,0.005182,0.005663,0.009064,0.021449};
2799     TGraphErrors *SP_0002_v4_etaGap10 = new TGraphErrors(nPointsSP_0002_v4_etaGap10,xSP_0002_v4_etaGap10,ySP_0002_v4_etaGap10,
2800                                                       xErrSP_0002_v4_etaGap10,yErrSP_0002_v4_etaGap10);
2801     return SP_0002_v4_etaGap10;
2802   }
2803   
2804   if (n == 5)
2805   {
2806     //  v5{SP}(pt) for 00-02%, eta gap = 0.2:
2807     const Int_t nPointsSP_0002_v5_etaGap02 = 13;
2808     Double_t xSP_0002_v5_etaGap02[nPointsSP_0002_v5_etaGap02] = {0.300000,0.500000,0.700000,0.900000,1.100000,1.300000,1.500000,
2809     1.700000,2.000000,2.550000,3.250000,3.950000,4.650000};
2810     Double_t ySP_0002_v5_etaGap02[nPointsSP_0002_v5_etaGap02] = {0.000570,0.002922,0.002151,0.005256,0.006287,0.005849,0.009399,
2811     0.011420,0.012455,0.032134,0.057009,0.020607,0.013551};
2812     Double_t xErrSP_0002_v5_etaGap02[nPointsSP_0002_v5_etaGap02] = {0.};
2813     Double_t yErrSP_0002_v5_etaGap02[nPointsSP_0002_v5_etaGap02] = {0.001074,0.001155,0.001433,0.001725,0.002123,0.002608,0.003196,
2814     0.003930,0.003755,0.004869,0.009719,0.018353,0.031814};
2815     TGraphErrors *SP_0002_v5_etaGap02 = new TGraphErrors(nPointsSP_0002_v5_etaGap02,xSP_0002_v5_etaGap02,ySP_0002_v5_etaGap02,
2816                                                           xErrSP_0002_v5_etaGap02,yErrSP_0002_v5_etaGap02);
2817     return SP_0002_v5_etaGap02;
2818   }
2819 }
2820
2821 TGraphErrors* GetFlow02(Int_t n)
2822 {
2823   // private communication 28.01.11, Ante B. / Raimond
2824
2825   if (n == 2)
2826   {
2827     // v2{2}(pt):
2828     Double_t xCumulant2nd0002ALICE_v2[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
2829     1.050000,1.150000,1.250000,1.350000,1.450000,1.550000,1.650000,1.750000,1.850000,1.950000,
2830     2.250000,2.750000,3.250000,3.750000,4.250000,4.750000,5.500000,6.500000,7.500000,8.500000,
2831     9.500000};
2832     Double_t yCumulant2nd0002ALICE_v2[] = {0.000000,0.000000,0.012173,0.015186,0.018580,0.021114,0.024646,0.027040,0.030269,0.032677,
2833     0.035332,0.037382,0.039228,0.040614,0.042460,0.044658,0.046246,0.050392,0.051436,0.054669,
2834     0.057330,0.063439,0.067425,0.060144,0.071260,0.070206,0.000000,0.000000,0.000000,0.000000,
2835     0.000000};
2836     Double_t xErrCumulant2nd0002ALICE_v2[31] = {0.};
2837     Double_t yErrCumulant2nd0002ALICE_v2[] = {0.000000,0.000000,0.000256,0.000259,0.000271,0.000296,0.000322,0.000357,0.000397,0.000438,
2838     0.000483,0.000529,0.000590,0.000639,0.000713,0.000793,0.000877,0.000976,0.001070,0.001197,
2839     0.000725,0.001265,0.002069,0.003156,0.004605,0.006543,0.000000,0.000000,0.000000,0.000000,
2840     0.000000};
2841     Int_t nPointsCumulant2nd0002ALICE_v2 = sizeof(xCumulant2nd0002ALICE_v2)/sizeof(Double_t);                                      
2842     TGraphErrors *Cumulant2nd0002ALICE_v2 = new TGraphErrors(nPointsCumulant2nd0002ALICE_v2,xCumulant2nd0002ALICE_v2,yCumulant2nd0002ALICE_v2,
2843                                                           xErrCumulant2nd0002ALICE_v2,yErrCumulant2nd0002ALICE_v2);
2844     Cumulant2nd0002ALICE_v2->SetMarkerStyle(kFullCircle);
2845     Cumulant2nd0002ALICE_v2->SetMarkerColor(kBlue);
2846     
2847     return Cumulant2nd0002ALICE_v2;
2848   }
2849   
2850   if (n == 3)
2851   {
2852     // v3{2}(pt):
2853     Double_t xCumulant2nd0002ALICE_v3[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
2854     1.050000,1.150000,1.250000,1.350000,1.450000,1.550000,1.650000,1.750000,1.850000,1.950000,
2855     2.250000,2.750000,3.250000,3.750000,4.250000,4.750000,5.500000,6.500000,7.500000,8.500000,
2856     9.500000};
2857     Double_t yCumulant2nd0002ALICE_v3[] = {0.000000,0.000000,0.007696,0.008994,0.010544,0.013269,0.016330,0.019234,0.023465,0.026803,
2858     0.029906,0.032211,0.035300,0.038158,0.041861,0.046002,0.049382,0.053574,0.055773,0.059420,
2859     0.069373,0.079922,0.090265,0.103583,0.111358,0.090740,0.000000,0.000000,0.000000,0.000000,
2860     0.000000};
2861     Double_t xErrCumulant2nd0002ALICE_v3[31] = {0.};
2862     Double_t yErrCumulant2nd0002ALICE_v3[] = {0.000000,0.000000,0.000318,0.000317,0.000333,0.000360,0.000392,0.000431,0.000476,0.000523,
2863     0.000575,0.000637,0.000707,0.000785,0.000878,0.000964,0.001064,0.001175,0.001320,0.001459,
2864     0.000889,0.001539,0.002530,0.003826,0.005614,0.007892,0.000000,0.000000,0.000000,0.000000,
2865     0.000000};
2866     Int_t nPointsCumulant2nd0002ALICE_v3 = sizeof(xCumulant2nd0002ALICE_v3)/sizeof(Double_t);                                      
2867     TGraphErrors *Cumulant2nd0002ALICE_v3 = new TGraphErrors(nPointsCumulant2nd0002ALICE_v3,xCumulant2nd0002ALICE_v3,yCumulant2nd0002ALICE_v3,
2868                                                           xErrCumulant2nd0002ALICE_v3,yErrCumulant2nd0002ALICE_v3);
2869     Cumulant2nd0002ALICE_v3->SetMarkerStyle(kFullTriangleUp);
2870     Cumulant2nd0002ALICE_v3->SetMarkerSize(1.2);
2871     Cumulant2nd0002ALICE_v3->SetMarkerColor(kGreen+2); 
2872     
2873     return Cumulant2nd0002ALICE_v3;
2874   }
2875   
2876   if (n == 4)
2877   {
2878     // v4{2}(pt):
2879     Double_t xCumulant2nd0002ALICE_v4[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
2880     1.050000,1.150000,1.250000,1.350000,1.450000,1.550000,1.650000,1.750000,1.850000,1.950000,
2881     2.250000,2.750000,3.250000,3.750000,4.250000,4.750000,5.500000,6.500000,7.500000,8.500000,
2882     9.500000};
2883     Double_t yCumulant2nd0002ALICE_v4[] = {0.000000,0.000000,0.005710,0.006014,0.004483,0.005453,0.007714,0.006837,0.009721,0.011288,
2884     0.012531,0.016461,0.016606,0.018587,0.022722,0.025497,0.025832,0.030994,0.030349,0.034730,
2885     0.045529,0.061153,0.074238,0.079307,0.088885,0.085218,0.000000,0.000000,0.000000,0.000000,
2886     0.000000};
2887     Double_t xErrCumulant2nd0002ALICE_v4[31] = {0.};
2888     Double_t yErrCumulant2nd0002ALICE_v4[] = {0.000000,0.000000,0.000488,0.000493,0.000523,0.000571,0.000609,0.000678,0.000742,0.000805,
2889     0.000903,0.000985,0.001100,0.001219,0.001352,0.001503,0.001682,0.001847,0.002060,0.002303,
2890     0.001400,0.002431,0.003974,0.006040,0.008901,0.012343,0.000000,0.000000,0.000000,0.000000,
2891     0.000000};
2892     Int_t nPointsCumulant2nd0002ALICE_v4 = sizeof(xCumulant2nd0002ALICE_v4)/sizeof(Double_t);                                      
2893     TGraphErrors *Cumulant2nd0002ALICE_v4 = new TGraphErrors(nPointsCumulant2nd0002ALICE_v4,xCumulant2nd0002ALICE_v4,yCumulant2nd0002ALICE_v4,
2894                                                           xErrCumulant2nd0002ALICE_v4,yErrCumulant2nd0002ALICE_v4);
2895     Cumulant2nd0002ALICE_v4->SetMarkerStyle(kFullSquare);
2896     Cumulant2nd0002ALICE_v4->SetMarkerColor(kRed);  
2897     
2898     return Cumulant2nd0002ALICE_v4;
2899   }
2900   
2901   return 0;
2902 }
2903
2904 /* results up to 5 GeV/c
2905
2906 TGraphErrors* GetFlow05(Int_t n)
2907 {
2908   // private communication 02.02.11, Ante B. / Raimond
2909
2910   if (n == 2)
2911   {
2912     // v2{2}(pt) for 0-5%:
2913     Double_t xCumulant2nd0005ALICE_v2[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
2914     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
2915     Double_t yCumulant2nd0005ALICE_v2[] = {0.000000,0.000000,0.013891,0.017693,0.021693,0.025323,0.029131,0.032443,0.035781,0.038256,
2916     0.042801,0.047705,0.053229,0.057387,0.062677,0.068815,0.077695,0.082058,0.082511,0.079791};
2917     Double_t xErrCumulant2nd0005ALICE_v2[20] = {0.};
2918     Double_t yErrCumulant2nd0005ALICE_v2[] = {0.000000,0.000000,0.000149,0.000150,0.000160,0.000174,0.000191,0.000211,0.000233,0.000257,
2919     0.000208,0.000254,0.000311,0.000377,0.000464,0.000419,0.000726,0.001180,0.001791,0.002131};
2920     Int_t nPointsCumulant2nd0005ALICE_v2 = sizeof(xCumulant2nd0005ALICE_v2)/sizeof(Double_t);                                      
2921     TGraphErrors *Cumulant2nd0005ALICE_v2 = new TGraphErrors(nPointsCumulant2nd0005ALICE_v2,xCumulant2nd0005ALICE_v2,yCumulant2nd0005ALICE_v2,
2922                                                           xErrCumulant2nd0005ALICE_v2,yErrCumulant2nd0005ALICE_v2);
2923     Cumulant2nd0005ALICE_v2->SetMarkerStyle(kFullCircle);
2924     Cumulant2nd0005ALICE_v2->SetMarkerColor(kBlue);    
2925     
2926     return Cumulant2nd0005ALICE_v2;
2927   }
2928   
2929   if (n == 3)
2930   {
2931     // v3{2}(pt) for 0-5%:
2932     Double_t xCumulant2nd0005ALICE_v3[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
2933     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
2934     Double_t yCumulant2nd0005ALICE_v3[] = {0.000000,0.000000,0.007788,0.009472,0.011596,0.014618,0.017540,0.021020,0.024946,0.028004,
2935     0.032330,0.039491,0.046368,0.053620,0.060662,0.071750,0.086746,0.097857,0.103111,0.104796};
2936     Double_t xErrCumulant2nd0005ALICE_v3[20] = {0.};
2937     Double_t yErrCumulant2nd0005ALICE_v3[] = {0.000000,0.000000,0.000194,0.000192,0.000204,0.000221,0.000241,0.000265,0.000293,0.000323,
2938     0.000266,0.000323,0.000397,0.000486,0.000601,0.000545,0.000947,0.001541,0.002328,0.002777};
2939     Int_t nPointsCumulant2nd0005ALICE_v3 = sizeof(xCumulant2nd0005ALICE_v3)/sizeof(Double_t);                                      
2940     TGraphErrors *Cumulant2nd0005ALICE_v3 = new TGraphErrors(nPointsCumulant2nd0005ALICE_v3,xCumulant2nd0005ALICE_v3,yCumulant2nd0005ALICE_v3,
2941                                                           xErrCumulant2nd0005ALICE_v3,yErrCumulant2nd0005ALICE_v3);
2942     Cumulant2nd0005ALICE_v3->SetMarkerStyle(kFullCircle);
2943     Cumulant2nd0005ALICE_v3->SetMarkerColor(kBlue);
2944
2945     return Cumulant2nd0005ALICE_v3;
2946   }
2947   
2948   if (n == 4)
2949   {
2950     // v4{2}(pt) for 0-5%:
2951     Double_t xCumulant2nd0005ALICE_v4[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
2952     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
2953     Double_t yCumulant2nd0005ALICE_v4[] = {0.000000,0.000000,0.006121,0.006137,0.005598,0.005956,0.007262,0.007991,0.009159,0.012062,
2954     0.015085,0.019225,0.024782,0.030092,0.035708,0.046542,0.060077,0.076088,0.082964,0.085405};
2955     Double_t xErrCumulant2nd0005ALICE_v4[20] = {0.};
2956     Double_t yErrCumulant2nd0005ALICE_v4[] = {0.000000,0.000000,0.000275,0.000278,0.000294,0.000319,0.000346,0.000380,0.000419,0.000459,
2957     0.000378,0.000460,0.000570,0.000700,0.000865,0.000789,0.001370,0.002227,0.003370,0.004018};
2958     Int_t nPointsCumulant2nd0005ALICE_v4 = sizeof(xCumulant2nd0005ALICE_v4)/sizeof(Double_t);                                      
2959     TGraphErrors *Cumulant2nd0005ALICE_v4 = new TGraphErrors(nPointsCumulant2nd0005ALICE_v4,xCumulant2nd0005ALICE_v4,yCumulant2nd0005ALICE_v4,
2960                                                           xErrCumulant2nd0005ALICE_v4,yErrCumulant2nd0005ALICE_v4);
2961     Cumulant2nd0005ALICE_v4->SetMarkerStyle(kFullCircle);
2962     Cumulant2nd0005ALICE_v4->SetMarkerColor(kBlue); 
2963     
2964     return Cumulant2nd0005ALICE_v4;
2965   }
2966   
2967   return 0;
2968 }
2969
2970 TGraphErrors* GetFlow510(Int_t n)
2971 {
2972   // private communication 02.02.11, Ante B. / Raimond
2973
2974   if (n == 2)
2975   {
2976     // v2{2}(pt) for 5-10%:
2977     Double_t xCumulant2nd0510ALICE_v2[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
2978     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
2979     Double_t yCumulant2nd0510ALICE_v2[] = {0.000000,0.000000,0.019872,0.026451,0.032901,0.039085,0.044930,0.050200,0.054887,0.060253,
2980     0.066587,0.075080,0.083303,0.090298,0.098782,0.109632,0.124486,0.129621,0.132076,0.120697};
2981     Double_t xErrCumulant2nd0510ALICE_v2[20] = {0.};
2982     Double_t yErrCumulant2nd0510ALICE_v2[] = {0.000000,0.000000,0.000150,0.000152,0.000163,0.000178,0.000196,0.000215,0.000237,0.000261,
2983     0.000213,0.000256,0.000313,0.000381,0.000468,0.000423,0.000727,0.001157,0.001741,0.002064};
2984     Int_t nPointsCumulant2nd0510ALICE_v2 = sizeof(xCumulant2nd0510ALICE_v2)/sizeof(Double_t);                                      
2985     TGraphErrors *Cumulant2nd0510ALICE_v2 = new TGraphErrors(nPointsCumulant2nd0510ALICE_v2,xCumulant2nd0510ALICE_v2,yCumulant2nd0510ALICE_v2,
2986                                                           xErrCumulant2nd0510ALICE_v2,yErrCumulant2nd0510ALICE_v2);
2987     Cumulant2nd0510ALICE_v2->SetMarkerStyle(kOpenCircle);
2988     Cumulant2nd0510ALICE_v2->SetMarkerColor(kBlue);   
2989      
2990     return Cumulant2nd0510ALICE_v2;
2991   }
2992   
2993   if (n == 3)
2994   {
2995     // v3{2}(pt) for 5-10%:
2996     Double_t xCumulant2nd0510ALICE_v3[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
2997     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
2998     Double_t yCumulant2nd0510ALICE_v3[] = {0.000000,0.000000,0.008596,0.010700,0.013820,0.017524,0.021507,0.024316,0.028491,0.032880,
2999     0.038741,0.045830,0.052486,0.059560,0.067990,0.081006,0.097402,0.107050,0.111743,0.116434};
3000     Double_t xErrCumulant2nd0510ALICE_v3[20] = {0.};
3001     Double_t yErrCumulant2nd0510ALICE_v3[] = {0.000000,0.000000,0.000208,0.000207,0.000218,0.000235,0.000258,0.000284,0.000314,0.000347,
3002     0.000285,0.000345,0.000426,0.000521,0.000642,0.000586,0.001008,0.001611,0.002421,0.002853};
3003     Int_t nPointsCumulant2nd0510ALICE_v3 = sizeof(xCumulant2nd0510ALICE_v3)/sizeof(Double_t);                                      
3004     TGraphErrors *Cumulant2nd0510ALICE_v3 = new TGraphErrors(nPointsCumulant2nd0510ALICE_v3,xCumulant2nd0510ALICE_v3,yCumulant2nd0510ALICE_v3,
3005                                                           xErrCumulant2nd0510ALICE_v3,yErrCumulant2nd0510ALICE_v3);
3006     Cumulant2nd0510ALICE_v3->SetMarkerStyle(kOpenCircle);
3007     Cumulant2nd0510ALICE_v3->SetMarkerColor(kBlue);
3008     
3009     return Cumulant2nd0510ALICE_v3;
3010   }
3011   
3012   if (n == 4)
3013   {
3014     // v4{2}(pt) for 5-10%:
3015     Double_t xCumulant2nd0510ALICE_v4[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3016     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
3017     Double_t yCumulant2nd0510ALICE_v4[] = {0.000000,0.000000,0.006466,0.006731,0.006344,0.007374,0.008775,0.010324,0.012323,0.014533,
3018     0.017261,0.022507,0.028776,0.035403,0.041936,0.051491,0.070340,0.080081,0.095077,0.088526};
3019     Double_t xErrCumulant2nd0510ALICE_v4[20] = {0.};
3020     Double_t yErrCumulant2nd0510ALICE_v4[] = {0.000000,0.000000,0.000292,0.000295,0.000312,0.000336,0.000366,0.000403,0.000443,0.000485,
3021     0.000399,0.000486,0.000603,0.000738,0.000914,0.000836,0.001443,0.002303,0.003448,0.004078};
3022     Int_t nPointsCumulant2nd0510ALICE_v4 = sizeof(xCumulant2nd0510ALICE_v4)/sizeof(Double_t);                                      
3023     TGraphErrors *Cumulant2nd0510ALICE_v4 = new TGraphErrors(nPointsCumulant2nd0510ALICE_v4,xCumulant2nd0510ALICE_v4,yCumulant2nd0510ALICE_v4,
3024                                                           xErrCumulant2nd0510ALICE_v4,yErrCumulant2nd0510ALICE_v4);
3025     Cumulant2nd0510ALICE_v4->SetMarkerStyle(kOpenCircle);
3026     Cumulant2nd0510ALICE_v4->SetMarkerColor(kBlue);    
3027     
3028     return Cumulant2nd0510ALICE_v4;
3029   }
3030   
3031   return 0;
3032 }
3033
3034 TGraphErrors* GetFlow1020(Int_t n)
3035 {
3036   // private communication 02.02.11, Ante B. / Raimond
3037
3038   if (n == 2)
3039   {
3040     // v2{2}(pt) for 10-20%:
3041     Double_t xCumulant2nd1020ALICE_v2[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3042     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
3043     Double_t yCumulant2nd1020ALICE_v2[] = {0.000000,0.000000,0.027683,0.037083,0.046511,0.055519,0.063979,0.071626,0.078537,0.085975,
3044     0.095001,0.106979,0.118456,0.129721,0.140641,0.155161,0.173402,0.179870,0.180616,0.168921};
3045     Double_t xErrCumulant2nd1020ALICE_v2[20] = {0.};
3046     Double_t yErrCumulant2nd1020ALICE_v2[] = {0.000000,0.000000,0.000121,0.000124,0.000134,0.000147,0.000163,0.000179,0.000198,0.000217,
3047     0.000177,0.000212,0.000257,0.000311,0.000380,0.000341,0.000569,0.000882,0.001309,0.001537};
3048     Int_t nPointsCumulant2nd1020ALICE_v2 = sizeof(xCumulant2nd1020ALICE_v2)/sizeof(Double_t);                                      
3049     TGraphErrors *Cumulant2nd1020ALICE_v2 = new TGraphErrors(nPointsCumulant2nd1020ALICE_v2,xCumulant2nd1020ALICE_v2,yCumulant2nd1020ALICE_v2,
3050                                                           xErrCumulant2nd1020ALICE_v2,yErrCumulant2nd1020ALICE_v2);
3051     Cumulant2nd1020ALICE_v2->SetMarkerStyle(kFullSquare);
3052     Cumulant2nd1020ALICE_v2->SetMarkerColor(kRed);     
3053     
3054     return Cumulant2nd1020ALICE_v2;
3055   }
3056   
3057   if (n == 3)
3058   {
3059     // v3{2}(pt) for 10-20%:
3060     Double_t xCumulant2nd1020ALICE_v3[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3061     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
3062     Double_t yCumulant2nd1020ALICE_v3[] = {0.000000,0.000000,0.009830,0.012858,0.016111,0.020120,0.023948,0.028349,0.032741,0.037244,
3063     0.043385,0.051803,0.059374,0.068686,0.076763,0.090151,0.106530,0.117448,0.121383,0.118247};
3064     Double_t xErrCumulant2nd1020ALICE_v3[20] = {0.};
3065     Double_t yErrCumulant2nd1020ALICE_v3[] = {0.000000,0.000000,0.000171,0.000170,0.000180,0.000195,0.000215,0.000236,0.000261,0.000287,
3066     0.000236,0.000288,0.000353,0.000434,0.000536,0.000488,0.000823,0.001277,0.001892,0.002224};
3067     Int_t nPointsCumulant2nd1020ALICE_v3 = sizeof(xCumulant2nd1020ALICE_v3)/sizeof(Double_t);                                      
3068     TGraphErrors *Cumulant2nd1020ALICE_v3 = new TGraphErrors(nPointsCumulant2nd1020ALICE_v3,xCumulant2nd1020ALICE_v3,yCumulant2nd1020ALICE_v3,
3069                                                           xErrCumulant2nd1020ALICE_v3,yErrCumulant2nd1020ALICE_v3);
3070     Cumulant2nd1020ALICE_v3->SetMarkerStyle(kFullSquare);
3071     Cumulant2nd1020ALICE_v3->SetMarkerColor(kRed); 
3072     
3073     return Cumulant2nd1020ALICE_v3;
3074   }
3075   
3076   if (n == 4)
3077   {
3078     // v4{2}(pt) for 10-20%:
3079     Double_t xCumulant2nd1020ALICE_v4[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3080     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
3081     Double_t yCumulant2nd1020ALICE_v4[] = {0.000000,0.000000,0.007423,0.007647,0.008189,0.008592,0.009489,0.011671,0.013739,0.017199,
3082     0.020084,0.026004,0.031843,0.038388,0.047357,0.057251,0.072433,0.086326,0.094282,0.097432};
3083     Double_t xErrCumulant2nd1020ALICE_v4[20] = {0.};
3084     Double_t yErrCumulant2nd1020ALICE_v4[] = {0.000000,0.000000,0.000243,0.000244,0.000257,0.000279,0.000306,0.000335,0.000368,0.000405,
3085     0.000333,0.000406,0.000502,0.000618,0.000770,0.000701,0.001185,0.001845,0.002730,0.003193};
3086     Int_t nPointsCumulant2nd1020ALICE_v4 = sizeof(xCumulant2nd1020ALICE_v4)/sizeof(Double_t);                                      
3087     TGraphErrors *Cumulant2nd1020ALICE_v4 = new TGraphErrors(nPointsCumulant2nd1020ALICE_v4,xCumulant2nd1020ALICE_v4,yCumulant2nd1020ALICE_v4,
3088                                                           xErrCumulant2nd1020ALICE_v4,yErrCumulant2nd1020ALICE_v4);
3089     Cumulant2nd1020ALICE_v4->SetMarkerStyle(kFullSquare);
3090     Cumulant2nd1020ALICE_v4->SetMarkerColor(kRed); 
3091         
3092     return Cumulant2nd1020ALICE_v4;
3093   }
3094   
3095   return 0;
3096 }
3097
3098 TGraphErrors* GetFlow2030(Int_t n)
3099 {
3100   // private communication 02.02.11, Ante B. / Raimond
3101
3102   if (n == 2)
3103   {
3104     Double_t xCumulant2nd2030ALICE_v2[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3105     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
3106     Double_t yCumulant2nd2030ALICE_v2[] = {0.000000,0.000000,0.035557,0.048064,0.060768,0.072585,0.083808,0.093772,0.103310,0.112602,
3107     0.124846,0.140603,0.155345,0.169450,0.183077,0.200173,0.219693,0.225741,0.223318,0.207356};
3108     Double_t xErrCumulant2nd2030ALICE_v2[20] = {0.};
3109     Double_t yErrCumulant2nd2030ALICE_v2[] = {0.000000,0.000000,0.000144,0.000147,0.000159,0.000175,0.000194,0.000214,0.000235,0.000259,
3110     0.000211,0.000254,0.000310,0.000377,0.000464,0.000418,0.000677,0.001027,0.001513,0.001761};
3111     Int_t nPointsCumulant2nd2030ALICE_v2 = sizeof(xCumulant2nd2030ALICE_v2)/sizeof(Double_t);                                      
3112     TGraphErrors *Cumulant2nd2030ALICE_v2 = new TGraphErrors(nPointsCumulant2nd2030ALICE_v2,xCumulant2nd2030ALICE_v2,yCumulant2nd2030ALICE_v2,
3113                                                           xErrCumulant2nd2030ALICE_v2,yErrCumulant2nd2030ALICE_v2);
3114     Cumulant2nd2030ALICE_v2->SetMarkerStyle(kOpenSquare);
3115     Cumulant2nd2030ALICE_v2->SetMarkerColor(kRed); 
3116         
3117     return Cumulant2nd2030ALICE_v2;
3118   }
3119   
3120   if (n == 3)
3121   {
3122     // v3{2}(pt) for 20-30%:
3123     Double_t xCumulant2nd2030ALICE_v3[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3124     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
3125     Double_t yCumulant2nd2030ALICE_v3[] = {0.000000,0.000000,0.011287,0.014937,0.018479,0.022962,0.027854,0.031938,0.037038,0.041443,
3126     0.049872,0.058720,0.068353,0.077692,0.087859,0.099863,0.116141,0.124486,0.124786,0.119520};
3127     Double_t xErrCumulant2nd2030ALICE_v3[20] = {0.};
3128     Double_t yErrCumulant2nd2030ALICE_v3[] = {0.000000,0.000000,0.000215,0.000216,0.000228,0.000248,0.000272,0.000300,0.000332,0.000366,
3129     0.000301,0.000369,0.000456,0.000561,0.000700,0.000636,0.001038,0.001574,0.002307,0.002676};
3130     Int_t nPointsCumulant2nd2030ALICE_v3 = sizeof(xCumulant2nd2030ALICE_v3)/sizeof(Double_t);                                      
3131     TGraphErrors *Cumulant2nd2030ALICE_v3 = new TGraphErrors(nPointsCumulant2nd2030ALICE_v3,xCumulant2nd2030ALICE_v3,yCumulant2nd2030ALICE_v3,
3132                                                           xErrCumulant2nd2030ALICE_v3,yErrCumulant2nd2030ALICE_v3);
3133     Cumulant2nd2030ALICE_v3->SetMarkerStyle(kOpenSquare);
3134     Cumulant2nd2030ALICE_v3->SetMarkerColor(kRed); 
3135     
3136     return Cumulant2nd2030ALICE_v3;
3137   }
3138   
3139   if (n == 4)
3140   {
3141     // v4{2}(pt) for 20-30%:
3142     Double_t xCumulant2nd2030ALICE_v4[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3143     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
3144     Double_t yCumulant2nd2030ALICE_v4[] = {0.000000,0.000000,0.008435,0.009824,0.009387,0.010408,0.011458,0.013770,0.016335,0.019165,
3145     0.023770,0.030071,0.036231,0.043950,0.051803,0.065222,0.082155,0.091864,0.105061,0.105167};
3146     Double_t xErrCumulant2nd2030ALICE_v4[20] = {0.};
3147     Double_t yErrCumulant2nd2030ALICE_v4[] = {0.000000,0.000000,0.000308,0.000308,0.000328,0.000355,0.000391,0.000430,0.000473,0.000524,
3148     0.000430,0.000524,0.000652,0.000807,0.001006,0.000919,0.001502,0.002277,0.003339,0.003871};
3149     Int_t nPointsCumulant2nd2030ALICE_v4 = sizeof(xCumulant2nd2030ALICE_v4)/sizeof(Double_t);                                      
3150     TGraphErrors *Cumulant2nd2030ALICE_v4 = new TGraphErrors(nPointsCumulant2nd2030ALICE_v4,xCumulant2nd2030ALICE_v4,yCumulant2nd2030ALICE_v4,
3151                                                           xErrCumulant2nd2030ALICE_v4,yErrCumulant2nd2030ALICE_v4);
3152     Cumulant2nd2030ALICE_v4->SetMarkerStyle(kOpenSquare);
3153     Cumulant2nd2030ALICE_v4->SetMarkerColor(kRed); 
3154         
3155     return Cumulant2nd2030ALICE_v4;
3156   }
3157   
3158   return 0;
3159 }
3160
3161 TGraphErrors* GetFlow3040(Int_t n)
3162 {
3163   // private communication 02.02.11, Ante B. / Raimond
3164
3165   if (n == 2)
3166   {
3167     // v2{2}(pt) for 30-40%:
3168     Double_t xCumulant2nd3040ALICE_v2[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3169     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
3170     Double_t yCumulant2nd3040ALICE_v2[] = {0.000000,0.000000,0.040797,0.055427,0.070543,0.084024,0.096562,0.109411,0.119853,0.130964,
3171     0.145377,0.163806,0.179825,0.196178,0.210377,0.226556,0.245686,0.247898,0.240058,0.225011};
3172     Double_t xErrCumulant2nd3040ALICE_v2[20] = {0.};
3173     Double_t yErrCumulant2nd3040ALICE_v2[] = {0.000000,0.000000,0.000177,0.000182,0.000197,0.000216,0.000239,0.000265,0.000293,0.000325,
3174     0.000266,0.000321,0.000395,0.000486,0.000603,0.000536,0.000840,0.001258,0.001843,0.002118};
3175     Int_t nPointsCumulant2nd3040ALICE_v2 = sizeof(xCumulant2nd3040ALICE_v2)/sizeof(Double_t);                                      
3176     TGraphErrors *Cumulant2nd3040ALICE_v2 = new TGraphErrors(nPointsCumulant2nd3040ALICE_v2,xCumulant2nd3040ALICE_v2,yCumulant2nd3040ALICE_v2,
3177                                                           xErrCumulant2nd3040ALICE_v2,yErrCumulant2nd3040ALICE_v2);
3178     Cumulant2nd3040ALICE_v2->SetMarkerStyle(kFullTriangleUp);
3179     Cumulant2nd3040ALICE_v2->SetMarkerSize(1.2);
3180     Cumulant2nd3040ALICE_v2->SetMarkerColor(kGreen+2);     
3181     
3182     return Cumulant2nd3040ALICE_v2;
3183   }
3184   
3185   if (n == 3)
3186   {
3187     // v3{2}(pt) for 30-40%:
3188     Double_t xCumulant2nd3040ALICE_v3[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3189     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
3190     Double_t yCumulant2nd3040ALICE_v3[] = {0.000000,0.000000,0.012226,0.016391,0.020792,0.026208,0.030380,0.035710,0.041025,0.047062,
3191     0.053075,0.064201,0.074116,0.085314,0.094391,0.106819,0.124012,0.129388,0.134315,0.132330};
3192     Double_t xErrCumulant2nd3040ALICE_v3[20] = {0.};
3193     Double_t yErrCumulant2nd3040ALICE_v3[] = {0.000000,0.000000,0.000284,0.000286,0.000303,0.000329,0.000364,0.000403,0.000443,0.000492,
3194     0.000408,0.000500,0.000627,0.000778,0.000973,0.000874,0.001375,0.002050,0.002992,0.003438};
3195     Int_t nPointsCumulant2nd3040ALICE_v3 = sizeof(xCumulant2nd3040ALICE_v3)/sizeof(Double_t);                                      
3196     TGraphErrors *Cumulant2nd3040ALICE_v3 = new TGraphErrors(nPointsCumulant2nd3040ALICE_v3,xCumulant2nd3040ALICE_v3,yCumulant2nd3040ALICE_v3,
3197                                                           xErrCumulant2nd3040ALICE_v3,yErrCumulant2nd3040ALICE_v3);
3198     Cumulant2nd3040ALICE_v3->SetMarkerStyle(kFullTriangleUp);
3199     Cumulant2nd3040ALICE_v3->SetMarkerSize(1.2);
3200     Cumulant2nd3040ALICE_v3->SetMarkerColor(kGreen+2); 
3201     
3202     return Cumulant2nd3040ALICE_v3;
3203   }
3204   
3205   if (n == 4)
3206   {
3207     // v4{2}(pt) for 30-40%:
3208     Double_t xCumulant2nd3040ALICE_v4[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3209     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
3210     Double_t yCumulant2nd3040ALICE_v4[] = {0.000000,0.000000,0.010718,0.011490,0.010994,0.012527,0.013748,0.016425,0.018857,0.021622,
3211     0.026853,0.034636,0.042651,0.049892,0.057795,0.070865,0.088486,0.101656,0.113886,0.118202};
3212     Double_t xErrCumulant2nd3040ALICE_v4[20] = {0.};
3213     Double_t yErrCumulant2nd3040ALICE_v4[] = {0.000000,0.000000,0.000401,0.000406,0.000433,0.000472,0.000521,0.000575,0.000634,0.000704,
3214     0.000580,0.000714,0.000890,0.001114,0.001398,0.001253,0.001974,0.002945,0.004290,0.004909};
3215     Int_t nPointsCumulant2nd3040ALICE_v4 = sizeof(xCumulant2nd3040ALICE_v4)/sizeof(Double_t);                                      
3216     TGraphErrors *Cumulant2nd3040ALICE_v4 = new TGraphErrors(nPointsCumulant2nd3040ALICE_v4,xCumulant2nd3040ALICE_v4,yCumulant2nd3040ALICE_v4,
3217                                                           xErrCumulant2nd3040ALICE_v4,yErrCumulant2nd3040ALICE_v4);
3218     Cumulant2nd3040ALICE_v4->SetMarkerStyle(kFullTriangleUp);
3219     Cumulant2nd3040ALICE_v4->SetMarkerSize(1.2);
3220     Cumulant2nd3040ALICE_v4->SetMarkerColor(kGreen+2); 
3221         
3222     return Cumulant2nd3040ALICE_v4;
3223   }
3224   
3225   return 0;
3226 }
3227
3228 TGraphErrors* GetFlow4050(Int_t n)
3229 {
3230   // private communication 02.02.11, Ante B. / Raimond
3231
3232   if (n == 2)
3233   {
3234     // v2{2}(pt) for 40-50%:
3235     Double_t xCumulant2nd4050ALICE_v2[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3236     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
3237     Double_t yCumulant2nd4050ALICE_v2[] = {0.000000,0.000000,0.043593,0.059522,0.075558,0.090681,0.104453,0.117913,0.129349,0.141743,
3238     0.157076,0.176121,0.193651,0.208844,0.222402,0.238407,0.252512,0.253592,0.243571,0.233018};
3239     Double_t xErrCumulant2nd4050ALICE_v2[20] = {0.};
3240     Double_t yErrCumulant2nd4050ALICE_v2[] = {0.000000,0.000000,0.000234,0.000241,0.000261,0.000288,0.000322,0.000357,0.000395,0.000438,
3241     0.000362,0.000447,0.000555,0.000685,0.000846,0.000733,0.001121,0.001665,0.002433,0.002768};
3242     Int_t nPointsCumulant2nd4050ALICE_v2 = sizeof(xCumulant2nd4050ALICE_v2)/sizeof(Double_t);                                      
3243     TGraphErrors *Cumulant2nd4050ALICE_v2 = new TGraphErrors(nPointsCumulant2nd4050ALICE_v2,xCumulant2nd4050ALICE_v2,yCumulant2nd4050ALICE_v2,
3244                                                           xErrCumulant2nd4050ALICE_v2,yErrCumulant2nd4050ALICE_v2);
3245     Cumulant2nd4050ALICE_v2->SetMarkerStyle(kOpenTriangleUp);
3246     Cumulant2nd4050ALICE_v2->SetMarkerSize(1.2);
3247     Cumulant2nd4050ALICE_v2->SetMarkerColor(kGreen+2);      
3248     
3249     return Cumulant2nd4050ALICE_v2;
3250   }
3251   
3252   return 0;
3253 }
3254 */
3255
3256 // results up to high pT
3257
3258 TGraphErrors* GetFlow05(Int_t n)
3259 {
3260   // private communication 09.03.11, Ante B. / Raimond
3261
3262   if (n == 2)
3263   {
3264     // v2{2}(pt) for 0-5%:
3265     Double_t xCumulant2nd0005ALICE[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3266     1.050000,1.150000,1.250000,1.350000,1.450000,1.550000,1.650000,1.750000,1.850000,1.950000,
3267     2.100000,2.300000,2.500000,2.700000,2.900000,3.200000,3.600000,4.000000,4.400000,4.800000,
3268     5.500000,6.500000,7.500000,8.500000,9.500000,11.250000,13.750000,16.250000,18.750000,60.000000};
3269     Double_t yCumulant2nd0005ALICE[] = {0.000000,0.000000,0.018169,0.020988,0.024899,0.028309,0.031974,0.035188,0.038218,0.041202,
3270     0.043910,0.046560,0.048183,0.050640,0.052874,0.055334,0.056948,0.059427,0.061540,0.063218,
3271     0.065452,0.069222,0.072578,0.074723,0.077749,0.077178,0.080514,0.075325,0.077692,0.079710,
3272     0.073280,0.063849,0.068274,0.066045,0.071496,0.104352,0.091646,0.050220,0.124185,0.088535};
3273     Double_t xErrCumulant2nd0005ALICE[40] = {0.};
3274     Double_t yErrCumulant2nd0005ALICE[] = {0.000000,0.000000,0.000190,0.000191,0.000199,0.000212,0.000230,0.000248,0.000268,0.000293,
3275     0.000319,0.000346,0.000379,0.000418,0.000459,0.000502,0.000554,0.000614,0.000674,0.000749,
3276     0.000620,0.000769,0.000958,0.001182,0.001446,0.001331,0.001858,0.002552,0.003453,0.004606,
3277     0.004289,0.007006,0.010046,0.013853,0.017709,0.016630,0.025728,0.036763,0.045056,0.029011};
3278     Int_t nPointsCumulant2nd0005ALICE = sizeof(xCumulant2nd0005ALICE)/sizeof(Double_t);                                      
3279     TGraphErrors *Cumulant2nd0005ALICE = new TGraphErrors(nPointsCumulant2nd0005ALICE,xCumulant2nd0005ALICE,yCumulant2nd0005ALICE,
3280                                                           xErrCumulant2nd0005ALICE,yErrCumulant2nd0005ALICE);
3281     Cumulant2nd0005ALICE->SetMarkerStyle(kFullCircle);
3282     Cumulant2nd0005ALICE->SetMarkerColor(kBlue);
3283     
3284     return Cumulant2nd0005ALICE;
3285   }
3286   
3287   if (n == 3)
3288   {
3289   }
3290   
3291   if (n == 4)
3292   {
3293   }
3294   
3295   return 0;
3296 }
3297
3298 TGraphErrors* GetFlow05_Rap10(Int_t n)
3299 {
3300   // private communication 17.05.11, Ante B. / should correspond to machcone paper draft 
3301
3302   if (n == 2)
3303   {
3304     //  v2{SP}(pt) for 00-05%:
3305     const Int_t nPointsSP_0005ALICE_v2_etaGap10 = 17;
3306     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,
3307         1.300000,1.500000,1.700000,1.900000,2.200000,2.600000,3.000000,3.650000,4.550000};
3308     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,
3309         0.043103,0.046626,0.052386,0.057132,0.060070,0.068419,0.061459,0.056816,0.050311};
3310     Double_t xErrSP_0005ALICE_v2_etaGap10[nPointsSP_0005ALICE_v2_etaGap10] = {0.};
3311     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,
3312         0.001410,0.001736,0.002131,0.002620,0.002502,0.003759,0.005615,0.006617,0.014242};
3313     TGraphErrors *GrSP_0005ALICE_v2_etaGap10 = new TGraphErrors(nPointsSP_0005ALICE_v2_etaGap10,xSP_0005ALICE_v2_etaGap10,ySP_0005ALICE_v2_etaGap10,
3314                                                               xErrSP_0005ALICE_v2_etaGap10,yErrSP_0005ALICE_v2_etaGap10);
3315                                                               
3316     return GrSP_0005ALICE_v2_etaGap10;
3317   }
3318   
3319   if (n == 3)
3320   {
3321     //  v3{SP}(pt) for 00-05%:
3322     const Int_t nPointsSP_0005ALICE_v3_etaGap10 = 16;
3323     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,
3324         1.300000,1.500000,1.700000,1.900000,2.300000,2.900000,3.650000,4.550000};
3325     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,
3326         0.038730,0.045653,0.052469,0.062303,0.071522,0.082223,0.083373,0.076951};
3327     Double_t xErrSP_0005ALICE_v3_etaGap10[nPointsSP_0005ALICE_v3_etaGap10] = {0.};
3328     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,
3329         0.001734,0.002124,0.002610,0.003206,0.002724,0.004977,0.008123,0.017180};
3330     TGraphErrors *GrSP_0005ALICE_v3_etaGap10 = new TGraphErrors(nPointsSP_0005ALICE_v3_etaGap10,xSP_0005ALICE_v3_etaGap10,ySP_0005ALICE_v3_etaGap10,
3331                                                               xErrSP_0005ALICE_v3_etaGap10,yErrSP_0005ALICE_v3_etaGap10);
3332
3333                                                               
3334     return GrSP_0005ALICE_v3_etaGap10;
3335   }
3336   
3337   if (n == 4)
3338   {
3339     //  v4{SP}(pt) for 00-05%:
3340     const Int_t nPointsSP_0005ALICE_v4_etaGap10 = 11;
3341     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};
3342     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,
3343         0.095985,0.094607};
3344     Double_t xErrSP_0005ALICE_v4_etaGap10[nPointsSP_0005ALICE_v4_etaGap10] = {0.};
3345     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,
3346         0.016472,0.035083};
3347     TGraphErrors *GrSP_0005ALICE_v4_etaGap10 = new TGraphErrors(nPointsSP_0005ALICE_v4_etaGap10,xSP_0005ALICE_v4_etaGap10,ySP_0005ALICE_v4_etaGap10,
3348                                                               xErrSP_0005ALICE_v4_etaGap10,yErrSP_0005ALICE_v4_etaGap10);
3349    
3350     return GrSP_0005ALICE_v4_etaGap10;
3351   }
3352   
3353   if (n == 5)
3354   {
3355     //  v5{SP}(pt) for 00-05%:
3356     const Int_t nPointsSP_0005ALICE_v5_etaGap10 = 12;
3357     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,
3358         2.800000,3.500000,4.500000};
3359     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,
3360         0.031373,0.068504,0.017964};
3361     Double_t xErrSP_0005ALICE_v5_etaGap10[nPointsSP_0005ALICE_v5_etaGap10] = {0.};
3362     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,
3363         0.010073,0.011899,0.027756};
3364     TGraphErrors *GrSP_0005ALICE_v5_etaGap10 = new TGraphErrors(nPointsSP_0005ALICE_v5_etaGap10,xSP_0005ALICE_v5_etaGap10,ySP_0005ALICE_v5_etaGap10,
3365                                                               xErrSP_0005ALICE_v5_etaGap10,yErrSP_0005ALICE_v5_etaGap10);
3366     
3367     return GrSP_0005ALICE_v5_etaGap10;
3368   }
3369   
3370   return 0;
3371 }
3372
3373 TGraphErrors* GetFlow510(Int_t n)
3374 {
3375   // private communication 09.03.11, Ante B. / Raimond
3376
3377   if (n == 2)
3378   {
3379     // v2{2}(pt) for 5-10%:
3380     Double_t xCumulant2nd0510ALICE[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3381     1.050000,1.150000,1.250000,1.350000,1.450000,1.550000,1.650000,1.750000,1.850000,1.950000,
3382     2.100000,2.300000,2.500000,2.700000,2.900000,3.200000,3.600000,4.000000,4.400000,4.800000,
3383     5.500000,6.500000,7.500000,8.500000,9.500000,11.250000,13.750000,16.250000,18.750000,60.000000};
3384     Double_t yCumulant2nd0510ALICE[] = {0.000000,0.000000,0.022354,0.028064,0.034341,0.040769,0.046265,0.051160,0.056712,0.061354,
3385     0.066290,0.070340,0.074453,0.078444,0.082367,0.085785,0.088086,0.092676,0.096169,0.100366,
3386     0.104227,0.109710,0.117032,0.121784,0.122227,0.126537,0.127966,0.117790,0.117884,0.111436,
3387     0.104945,0.097640,0.086481,0.091663,0.091404,0.080132,0.015864,0.101500,0.033347,0.205130};
3388     Double_t xErrCumulant2nd0510ALICE[40] = {0.};
3389     Double_t yErrCumulant2nd0510ALICE[] = {0.000000,0.000000,0.000173,0.000176,0.000186,0.000199,0.000219,0.000236,0.000260,0.000283,
3390     0.000312,0.000340,0.000373,0.000410,0.000454,0.000501,0.000552,0.000610,0.000675,0.000753,
3391     0.000620,0.000774,0.000961,0.001183,0.001431,0.001309,0.001814,0.002481,0.003342,0.004379,
3392     0.004122,0.006716,0.009851,0.013626,0.017517,0.015790,0.025680,0.038041,0.054144,0.038987};
3393     Int_t nPointsCumulant2nd0510ALICE = sizeof(xCumulant2nd0510ALICE)/sizeof(Double_t);                                      
3394     TGraphErrors *Cumulant2nd0510ALICE = new TGraphErrors(nPointsCumulant2nd0510ALICE,xCumulant2nd0510ALICE,yCumulant2nd0510ALICE,
3395                                                           xErrCumulant2nd0510ALICE,yErrCumulant2nd0510ALICE);
3396     Cumulant2nd0510ALICE->SetMarkerStyle(kOpenCircle);
3397     Cumulant2nd0510ALICE->SetMarkerColor(kBlue);
3398     
3399     return Cumulant2nd0510ALICE;
3400   }
3401   
3402   if (n == 3)
3403   {
3404   }
3405   
3406   if (n == 4)
3407   {
3408   }
3409   
3410   return 0;
3411 }
3412
3413 TGraphErrors* GetFlow510_Rap10(Int_t n)
3414 {
3415   // private communication 18.05.11, Ante B.
3416
3417   if (n == 2)
3418   {
3419     //  v2{SP}(pt) for 05-10%, rapidity gap = 1.0:
3420     const Int_t nPointsSP_0510ALICE_v2_etaGap10 = 19;
3421     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,
3422 1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.250000,
3423 4.750000};
3424     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,
3425 0.066516,0.073891,0.080945,0.090386,0.094505,0.106393,0.120303,0.122586,0.121731,0.107343,
3426 0.104059};
3427     Double_t xErrSP_0510ALICE_v2_etaGap10[nPointsSP_0510ALICE_v2_etaGap10] = {0.};
3428     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,
3429 0.000586,0.000717,0.000880,0.001082,0.001333,0.001189,0.001969,0.003199,0.005011,0.007602,
3430 0.010906};
3431     TGraphErrors *GrSP_0510ALICE_v2_etaGap10 = new TGraphErrors(nPointsSP_0510ALICE_v2_etaGap10,xSP_0510ALICE_v2_etaGap10,
3432                                                               ySP_0510ALICE_v2_etaGap10,xErrSP_0510ALICE_v2_etaGap10,
3433                                                               yErrSP_0510ALICE_v2_etaGap10);
3434
3435     return GrSP_0510ALICE_v2_etaGap10;
3436   }
3437   
3438   return 0;
3439 }
3440
3441 TGraphErrors* GetFlow1020(Int_t n)
3442 {
3443   // private communication 09.03.11, Ante B. / Raimond
3444
3445   if (n == 2)
3446   {
3447     // v2{2}(pt) for 10-20%:
3448     Double_t xCumulant2nd1020ALICE[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3449     1.050000,1.150000,1.250000,1.350000,1.450000,1.550000,1.650000,1.750000,1.850000,1.950000,
3450     2.100000,2.300000,2.500000,2.700000,2.900000,3.200000,3.600000,4.000000,4.400000,4.800000,
3451     5.500000,6.500000,7.500000,8.500000,9.500000,11.250000,13.750000,16.250000,18.750000,60.000000};
3452     Double_t yCumulant2nd1020ALICE[] = {0.000000,0.000000,0.028508,0.037698,0.046914,0.055750,0.063948,0.072298,0.079396,0.086829,
3453     0.093382,0.099676,0.105412,0.110792,0.116715,0.122327,0.127079,0.132302,0.137183,0.142346,
3454     0.149059,0.156729,0.164672,0.171840,0.175346,0.176824,0.178878,0.174979,0.169229,0.153109,
3455     0.139676,0.125686,0.120554,0.096537,0.084736,0.118152,0.116079,0.060032,0.093764,0.206506};
3456     Double_t xErrCumulant2nd1020ALICE[40] = {0.};
3457     Double_t yErrCumulant2nd1020ALICE[] = {0.000000,0.000000,0.000134,0.000136,0.000145,0.000158,0.000173,0.000190,0.000209,0.000229,
3458     0.000252,0.000275,0.000301,0.000331,0.000365,0.000401,0.000442,0.000488,0.000541,0.000599,
3459     0.000496,0.000614,0.000757,0.000915,0.001095,0.000989,0.001360,0.001847,0.002477,0.003234,
3460     0.003012,0.004867,0.007123,0.009774,0.012740,0.011682,0.019629,0.028568,0.039931,0.024776};
3461     Int_t nPointsCumulant2nd1020ALICE = sizeof(xCumulant2nd1020ALICE)/sizeof(Double_t);                                      
3462     TGraphErrors *Cumulant2nd1020ALICE = new TGraphErrors(nPointsCumulant2nd1020ALICE,xCumulant2nd1020ALICE,yCumulant2nd1020ALICE,
3463                                                           xErrCumulant2nd1020ALICE,yErrCumulant2nd1020ALICE);
3464     Cumulant2nd1020ALICE->SetMarkerStyle(kFullSquare);
3465     Cumulant2nd1020ALICE->SetMarkerColor(kRed); 
3466     
3467     return Cumulant2nd1020ALICE;
3468   }
3469   
3470   if (n == 3)
3471   {
3472   }
3473   
3474   if (n == 4)
3475   {
3476   }
3477   
3478   return 0;
3479 }
3480
3481 TGraphErrors* GetFlow1020_Rap10(Int_t n)
3482 {
3483   // private communication 18.05.11, Ante B.
3484
3485   if (n == 2)
3486   {
3487    //  v2{SP}(pt) for 10-20%, rapidity gap = 1.0:
3488     const Int_t nPointsSP_1020ALICE_v2_etaGap10 = 19;
3489     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,
3490 1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.250000,
3491 4.750000};
3492     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,
3493 0.094701,0.105631,0.117906,0.128147,0.138505,0.153494,0.166651,0.172691,0.177337,0.155068,
3494 0.131586};
3495     Double_t xErrSP_1020ALICE_v2_etaGap10[nPointsSP_1020ALICE_v2_etaGap10] = {0.};
3496     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,
3497 0.000423,0.000517,0.000634,0.000779,0.000959,0.000856,0.001406,0.002266,0.003528,0.005281,
3498 0.007561};
3499     TGraphErrors *GrSP_1020ALICE_v2_etaGap10 = new TGraphErrors(nPointsSP_1020ALICE_v2_etaGap10,xSP_1020ALICE_v2_etaGap10,
3500                                                               ySP_1020ALICE_v2_etaGap10,xErrSP_1020ALICE_v2_etaGap10,
3501                                                               yErrSP_1020ALICE_v2_etaGap10);
3502
3503     return GrSP_1020ALICE_v2_etaGap10;
3504   }
3505   
3506   return 0;
3507 }
3508     
3509 TGraphErrors* GetFlow2030(Int_t n)
3510 {
3511   // private communication 09.03.11, Ante B. / Raimond
3512
3513   if (n == 2)
3514   {
3515     // v2{2}(pt) for 20-30%:
3516     Double_t xCumulant2nd2030ALICE[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3517     1.050000,1.150000,1.250000,1.350000,1.450000,1.550000,1.650000,1.750000,1.850000,1.950000,
3518     2.100000,2.300000,2.500000,2.700000,2.900000,3.200000,3.600000,4.000000,4.400000,4.800000,
3519     5.500000,6.500000,7.500000,8.500000,9.500000,11.250000,13.750000,16.250000,18.750000,60.000000};
3520     Double_t yCumulant2nd2030ALICE[] = {0.000000,0.000000,0.035366,0.047465,0.060083,0.072090,0.083418,0.093576,0.103842,0.113110,
3521     0.122193,0.130168,0.138158,0.145627,0.152851,0.159129,0.166073,0.173144,0.178698,0.186188,
3522     0.192045,0.202199,0.210535,0.215004,0.220457,0.223339,0.224050,0.211567,0.203955,0.189716,
3523     0.165994,0.147185,0.131953,0.139331,0.151293,0.127406,0.153764,0.089628,0.161247,0.511418};
3524     Double_t xErrCumulant2nd2030ALICE[40] = {0.};
3525     Double_t yErrCumulant2nd2030ALICE[] = {0.000000,0.000000,0.000155,0.000157,0.000169,0.000184,0.000202,0.000222,0.000244,0.000269,
3526     0.000296,0.000325,0.000357,0.000394,0.000435,0.000481,0.000532,0.000589,0.000655,0.000731,
3527     0.000605,0.000743,0.000904,0.001081,0.001277,0.001145,0.001568,0.002119,0.002806,0.003635,
3528     0.003383,0.005346,0.007935,0.010739,0.014682,0.013434,0.021531,0.032352,0.040396,0.028472};
3529     Int_t nPointsCumulant2nd2030ALICE = sizeof(xCumulant2nd2030ALICE)/sizeof(Double_t);                                      
3530     TGraphErrors *Cumulant2nd2030ALICE = new TGraphErrors(nPointsCumulant2nd2030ALICE,xCumulant2nd2030ALICE,yCumulant2nd2030ALICE,
3531                                                           xErrCumulant2nd2030ALICE,yErrCumulant2nd2030ALICE);
3532     Cumulant2nd2030ALICE->SetMarkerStyle(kOpenSquare);
3533     Cumulant2nd2030ALICE->SetMarkerColor(kRed); 
3534     
3535     return Cumulant2nd2030ALICE;
3536   }
3537   
3538   if (n == 3)
3539   {
3540   }
3541   
3542   if (n == 4)
3543   {
3544   }
3545   
3546   return 0;
3547 }
3548
3549 TGraphErrors* GetFlow3040(Int_t n)
3550 {
3551   // private communication 09.03.11, Ante B. / Raimond
3552
3553   if (n == 2)
3554   {
3555     // v2{2}(pt) for 30-40%:
3556     Double_t xCumulant2nd3040ALICE[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3557     1.050000,1.150000,1.250000,1.350000,1.450000,1.550000,1.650000,1.750000,1.850000,1.950000,
3558     2.100000,2.300000,2.500000,2.700000,2.900000,3.200000,3.600000,4.000000,4.400000,4.800000,
3559     5.500000,6.500000,7.500000,8.500000,9.500000,11.250000,13.750000,16.250000,18.750000,60.000000};
3560     Double_t yCumulant2nd3040ALICE[] = {0.000000,0.000000,0.039584,0.054196,0.069291,0.082976,0.095622,0.108940,0.119830,0.131587,
3561     0.141091,0.150899,0.160573,0.168676,0.176301,0.183823,0.191672,0.199506,0.206854,0.212830,
3562     0.219526,0.229376,0.236513,0.240863,0.245961,0.245891,0.242608,0.234302,0.219580,0.212848,
3563     0.194666,0.190184,0.171036,0.159173,0.156932,0.141324,0.132809,0.182683,0.023272,0.032825};
3564     Double_t xErrCumulant2nd3040ALICE[40] = {0.};
3565     Double_t yErrCumulant2nd3040ALICE[] = {0.000000,0.000000,0.000189,0.000192,0.000205,0.000224,0.000247,0.000273,0.000302,0.000334,
3566     0.000369,0.000407,0.000448,0.000496,0.000552,0.000612,0.000682,0.000758,0.000844,0.000941,
3567     0.000774,0.000937,0.001123,0.001329,0.001565,0.001397,0.001911,0.002549,0.003378,0.004306,
3568     0.003987,0.006353,0.009128,0.013032,0.016891,0.015806,0.025150,0.035119,0.044487,0.050083};
3569     Int_t nPointsCumulant2nd3040ALICE = sizeof(xCumulant2nd3040ALICE)/sizeof(Double_t);                                      
3570     TGraphErrors *Cumulant2nd3040ALICE = new TGraphErrors(nPointsCumulant2nd3040ALICE,xCumulant2nd3040ALICE,yCumulant2nd3040ALICE,
3571                                                           xErrCumulant2nd3040ALICE,yErrCumulant2nd3040ALICE);
3572     Cumulant2nd3040ALICE->SetMarkerStyle(kFullTriangleUp);
3573     Cumulant2nd3040ALICE->SetMarkerColor(kGreen+2);
3574     
3575     return Cumulant2nd3040ALICE;
3576   }
3577   
3578   if (n == 3)
3579   {
3580   }
3581   
3582   if (n == 4)
3583   {
3584   }
3585   
3586   return 0;
3587 }
3588
3589 TGraphErrors* GetFlow4050(Int_t n)
3590 {
3591   // private communication 09.03.11, Ante B. / Raimond
3592
3593   if (n == 2)
3594   {
3595     // v2{2}(pt) for 40-50%:
3596     Double_t xCumulant2nd4050ALICE[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3597     1.050000,1.150000,1.250000,1.350000,1.450000,1.550000,1.650000,1.750000,1.850000,1.950000,
3598     2.100000,2.300000,2.500000,2.700000,2.900000,3.200000,3.600000,4.000000,4.400000,4.800000,
3599     5.500000,6.500000,7.500000,8.500000,9.500000,11.250000,13.750000,16.250000,18.750000,60.000000};
3600     Double_t yCumulant2nd4050ALICE[] = {0.000000,0.000000,0.041872,0.058090,0.074444,0.089181,0.103780,0.117279,0.129769,0.142051,
3601     0.153185,0.163147,0.173309,0.181668,0.190998,0.197703,0.205011,0.211063,0.219587,0.223287,
3602     0.231163,0.239606,0.246533,0.251457,0.250034,0.252989,0.240823,0.236489,0.230268,0.204321,
3603     0.213476,0.200247,0.167065,0.190655,0.173573,0.166173,0.153232,0.173112,-0.123540,0.211999};
3604     Double_t xErrCumulant2nd4050ALICE[40] = {0.};
3605     Double_t yErrCumulant2nd4050ALICE[] = {0.000000,0.000000,0.000248,0.000251,0.000270,0.000296,0.000328,0.000363,0.000403,0.000447,
3606     0.000500,0.000556,0.000617,0.000687,0.000770,0.000857,0.000952,0.001057,0.001176,0.001297,
3607     0.001054,0.001265,0.001498,0.001767,0.002076,0.001849,0.002527,0.003358,0.004372,0.005573,
3608     0.005091,0.007981,0.011746,0.015732,0.021883,0.019866,0.032443,0.046521,0.051631,0.083717};
3609     Int_t nPointsCumulant2nd4050ALICE = sizeof(xCumulant2nd4050ALICE)/sizeof(Double_t);                                      
3610     TGraphErrors *Cumulant2nd4050ALICE = new TGraphErrors(nPointsCumulant2nd4050ALICE,xCumulant2nd4050ALICE,yCumulant2nd4050ALICE,
3611                                                           xErrCumulant2nd4050ALICE,yErrCumulant2nd4050ALICE);
3612     Cumulant2nd4050ALICE->SetMarkerStyle(kOpenTriangleUp);
3613     Cumulant2nd4050ALICE->SetMarkerColor(kGreen+2);
3614     
3615     return Cumulant2nd4050ALICE;
3616   }
3617   
3618   return 0;
3619 }
3620
3621 TGraphErrors* GetFlow6070_Rap10(Int_t n)
3622 {
3623   // private communication 18.05.11, Ante B. 
3624
3625   if (n == 2)
3626   {
3627     //  v2{SP}(pt) for 60-70%, rapidity gap = 1.0:
3628     const Int_t nPointsSP_6070ALICE_v2_etaGap10 = 9;
3629     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};
3630     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};
3631     Double_t xErrSP_6070ALICE_v2_etaGap10[nPointsSP_6070ALICE_v2_etaGap10] = {0.};
3632     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};
3633     TGraphErrors *GrSP_6070ALICE_v2_etaGap10 = new TGraphErrors(nPointsSP_6070ALICE_v2_etaGap10,xSP_6070ALICE_v2_etaGap10,
3634                                                               ySP_6070ALICE_v2_etaGap10,xErrSP_6070ALICE_v2_etaGap10,
3635                                                               yErrSP_6070ALICE_v2_etaGap10);
3636
3637     return GrSP_6070ALICE_v2_etaGap10;
3638   }
3639   
3640   return 0;
3641 }
3642
3643 Float_t CalculateFlow(TH1* ptDist, Float_t ptMin, Float_t ptMax, Int_t n, Int_t centralityBegin, Int_t centralityEnd)
3644 {
3645   if (centralityBegin == 0 && centralityEnd == 1)
3646     flow = GetFlow01_Rap10(n);
3647   else if (centralityBegin == 0 && centralityEnd == 2)
3648     flow = GetFlow02_Rap10(n);
3649   else if (centralityBegin == 0 && centralityEnd == 5)
3650     flow = GetFlow05_Rap10(n);
3651   else if (centralityBegin == 5 && centralityEnd == 10)
3652     flow = GetFlow510_Rap10(n);
3653   else if (centralityBegin == 20 && centralityEnd == 30)
3654     flow = GetFlow2030(n);
3655   else if (centralityBegin == 30 && centralityEnd == 40)
3656     flow = GetFlow3040(n);
3657   else if (centralityBegin == 40 && centralityEnd == 50)
3658     flow = GetFlow4050(n);
3659   else if (centralityBegin > 50)
3660     flow = GetFlow6070_Rap10(n);
3661   else if (centralityBegin == 0 && centralityEnd == 20)
3662   {
3663     flow1 = GetFlow05_Rap10(n);
3664     flow2 = GetFlow510_Rap10(n);
3665     flow3 = GetFlow1020_Rap10(n);
3666     
3667     flow = (TGraphErrors*) flow2->Clone();
3668     
3669     // centrality width * dn/deta from http://arxiv.org/PS_cache/arxiv/pdf/1012/1012.1657v2.pdf
3670     Float_t mult[] = { 5 * 1601, 5 * 1294, 10 * 966 };
3671     
3672     for (Int_t i=0; i<flow->GetN(); i++)
3673     {
3674       Float_t x= flow->GetX()[i];
3675
3676 //       Printf("%f: %f %f %f", x, flow1->Eval(x), flow2->Eval(x), flow3->Eval(x));
3677       flow->GetY()[i] = flow1->Eval(x) * mult[0] + flow2->Eval(x) * mult[1] + flow3->Eval(x) * mult[2];
3678       flow->GetY()[i] /= mult[0] + mult[1] + mult[2];
3679 //       Printf(" --> %f", flow->GetY()[i]);
3680     }
3681   }
3682   else if (centralityBegin == 20 && centralityEnd == 60)
3683   {
3684     flow = GetFlow2030(n);
3685     flow2 = GetFlow3040(n);
3686     flow3 = GetFlow4050(n);
3687     
3688     // centrality width * dn/deta from http://arxiv.org/PS_cache/arxiv/pdf/1012/1012.1657v2.pdf
3689     Float_t mult[] = { 10 * 649, 10 * 426, 10 * (261+149) };
3690     
3691     if (flow->GetN() != flow2->GetN() || flow2->GetN() != flow3->GetN())
3692       AliFatal("Incompatible graphs");
3693     
3694     for (Int_t i=0; i<flow->GetN(); i++)
3695     {
3696 //       Printf("%f %f %f", flow->GetY()[i], flow2->GetY()[i], flow3->GetY()[i]);
3697       flow->GetY()[i] = flow->GetY()[i] * mult[0] + flow2->GetY()[i] * mult[1] + flow3->GetY()[i] * mult[2];
3698       flow->GetY()[i] /= mult[0] + mult[1] + mult[2];
3699 //       Printf(" --> %f", flow->GetY()[i]);
3700     }
3701   }
3702   else
3703   {
3704     Printf("Flow range %d %d not available", centralityBegin, centralityEnd);
3705     AliFatal("");
3706   }
3707
3708   Float_t vn = 0;
3709   Float_t sum = 0;
3710   for (Int_t bin = ptDist->FindBin(ptMin + 0.01); bin <= ptDist->FindBin(ptMax - 0.01); bin++)
3711   {
3712     if (ptDist->GetBinCenter(bin) > flow->GetX()[flow->GetN()-1])
3713       vn += ptDist->GetBinContent(bin) * flow->GetY()[flow->GetN()-1];
3714     else
3715       vn += ptDist->GetBinContent(bin) * flow->Eval(ptDist->GetBinCenter(bin));
3716     sum += ptDist->GetBinContent(bin);
3717   }
3718   
3719   if (sum > 0)
3720     vn /= sum;
3721   
3722   Printf("v_{%d} = %f for %f < pT < %f", n, vn, ptMin, ptMax);
3723   
3724   return vn;
3725 }
3726
3727 void CalculateFlow(const char* fileName, Int_t centralityBegin, Int_t centralityEnd)
3728 {
3729   Float_t ptTrigMin = 2;
3730   Float_t ptTrigMax = 3;
3731   
3732   Float_t ptMin = 1;
3733   Float_t ptMax = 2;
3734
3735   loadlibs();
3736
3737   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
3738   
3739   cont = h->GetUEHist(2)->GetTrackHist(0);
3740   cont->GetGrid(6)->GetGrid()->GetAxis(3)->SetRangeUser(0.01 + centralityBegin, -0.01 + centralityEnd);
3741   cont->GetGrid(6)->GetGrid()->GetAxis(2)->SetRangeUser(ptTrigMin + 0.01, ptTrigMax - 0.01);
3742   
3743   ptDist = cont->ShowProjection(1, 6);
3744   ptDist->Scale(1.0 / ptDist->Integral());
3745   
3746   cont = h->GetUEHist(2)->GetEventHist();
3747   cont->GetGrid(6)->GetGrid()->GetAxis(1)->SetRangeUser(0.01 + centralityBegin, -0.01 + centralityEnd);
3748   
3749   ptDist2 = cont->ShowProjection(0, 6);
3750   ptDist2->Scale(1.0 / ptDist2->Integral());
3751   
3752   TString str;
3753   
3754   for (Int_t n=2; n<=4; n++)
3755   {
3756     Float_t v2A = CalculateFlow(ptDist, ptMin, ptMax, n, centralityBegin, centralityEnd);
3757     Float_t v2T = CalculateFlow(ptDist2, ptTrigMin, ptTrigMax, n, centralityBegin, centralityEnd);
3758     
3759     str += Form("%f * %f, ", v2A, v2T);
3760   }
3761   
3762   ptDist->Draw();
3763   ptDist2->SetLineColor(2);
3764   ptDist2->Draw("SAME");
3765   
3766   Printf("%s", str.Data());
3767 }
3768
3769 // 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...)
3770 TGraphErrors***** yields = 0;
3771 TString currentYieldFile;
3772
3773 void WriteYields()
3774 {
3775   TFile::Open("yields.root", "RECREATE");
3776   for (Int_t i=0; i<3; i++)
3777   {
3778     for (Int_t j=0; j<6; j++)
3779     {
3780       for (Int_t k=0; k<4; k++)
3781       {
3782         // CINT limitation here
3783         TGraphErrors** tmp = yields[i][j][k];
3784         for (Int_t l=0; l<31; l++)
3785         {
3786           //Printf("%d %d %d %d", i, j, k, l);
3787           tmp[l]->Write(Form("yield_%d_%d_%d_%d", i, j, k, l));
3788         }
3789       }
3790     }
3791   }
3792   gFile->Close();
3793 }
3794
3795 void ReadYields(const char* fileName = "yields.root")
3796 {
3797   if (currentYieldFile == fileName)
3798     return;
3799     
3800   currentYieldFile = fileName;
3801
3802   CreateYieldStructure();
3803   TFile::Open(fileName);
3804   for (Int_t i=0; i<3; i++)
3805   {
3806     for (Int_t j=0; j<6; j++)
3807     {
3808       for (Int_t k=0; k<4; k++)
3809       {
3810         // CINT limitation here
3811         TGraphErrors** tmp = yields[i][j][k];
3812         for (Int_t l=0; l<31; l++)
3813         {
3814           //Printf("%d %d %d %d", i, j, k, l);
3815           tmp[l] = gFile->Get(Form("yield_%d_%d_%d_%d", i, j, k, l));
3816         }
3817       }
3818     }
3819   }
3820 }
3821
3822 void CreateYieldStructure()
3823 {
3824   if (!yields)
3825   {
3826     yields = new TGraphErrors****[3];
3827     for (Int_t i=0; i<3; i++)
3828     {
3829       yields[i] = new TGraphErrors***[6];
3830       for (Int_t j=0; j<6; j++)
3831       {
3832         yields[i][j] = new TGraphErrors**[4];
3833         for (Int_t k=0; k<4; k++)
3834         {
3835           yields[i][j][k] = new TGraphErrors*[31];
3836           // CINT limitation here
3837           TGraphErrors** tmp = yields[i][j][k];
3838           for (Int_t l=0; l<31; l++)
3839           {
3840             //Printf("%d %d %d %d", i, j, k, l);
3841             TGraphErrors* graph = new TGraphErrors;
3842             tmp[l] = graph;
3843           }
3844         }
3845       }
3846     }
3847   }
3848 }
3849
3850 void GraphShiftX(TGraphErrors* graph, Float_t offset)
3851 {
3852   for (Int_t i=0; i<graph->GetN(); i++)
3853     graph->GetX()[i] += offset;
3854 }
3855
3856 // Float_t kPythiaScalingFactor = 0.935;
3857 Float_t kPythiaScalingFactor = 1;
3858
3859 void DrawYields(const char* fileName = "yields.root")
3860 {
3861   ReadYields(fileName);
3862   
3863   c = new TCanvas("c", "c", 1800, 1200);
3864   c->Divide(6, 4);
3865   
3866   Int_t markers1[] = { 24, 25, 26, 30 };
3867   Int_t markers2[] = { 20, 21, 22, 29 };
3868   Int_t colors[] = { 1, 2, 3, 4 };
3869   //Int_t caseList[] = { 0, 10+1, 10+1, 8, 10, 11, 12, 13, 1, 9 };
3870   Int_t caseList[] = { 0, 18, 18, 23, 18, 19, 20, 21, 22, 9 };
3871   const char* caseString[] = { "", "baseline sub", "baseline vs v2 sub comp", 0, "baseline sub comp", "Same/Mixed", "Same/Mixed - v2 subtr" };
3872   
3873   Bool_t iaa = kTRUE;
3874   if (!iaa)
3875   {
3876     Int_t centralityList[] =  {  0,  1,  2, 0, 0, 1 };
3877     Int_t centralityList2[] = { -1, -1, -1, 1, 2, 2 };
3878     Float_t factors[]       = {  1,  1,  1, 1, 1, 1 };
3879     const char* centralityString[] = { "0-5%", "20-40%", "60-90%", "0-5% vs 20-40%", "0-5% vs 60-90%", "20-40% vs 60-90%" };
3880   }
3881   else
3882   {
3883     Int_t centralityList[] =  {  0,  2,  3, 0, 0, 2 };
3884     Int_t centralityList2[] = { -1, -1, -1, 2, 3, 3 };
3885     //Float_t factors[]       = {  1,  1,  1, 1, 1.0/0.9, 1.0/0.9 };
3886     //Float_t factors[]       = {  1,  1,  1, 1, 1.0/0.804, 1.0/0.804 };
3887     Float_t factors[]       = {  1,  1,  1, 1, 1.0/kPythiaScalingFactor, 1.0/kPythiaScalingFactor };
3888     //Float_t factors[]       = {  1,  1,  1, 1, 1.0, 1.0 };
3889     const char* centralityString[] = { "0-5%", "60-90%", "pp", "0-5% vs 60-90%", "0-5% vs pp", "60-90% vs pp" };
3890   }
3891   
3892   l = new TLegend(0.5, 0.5, 0.9, 0.9);
3893   l->SetFillColor(0);
3894   
3895   Float_t max[] = { 0.4, 2, 2, 2, 2, 10, 10 };
3896   Float_t max2[] = { 5, 2, 2, 2, 2, 2, 2, 2, 2 };
3897   
3898   dummy = new TH2F("dummy", ";p_{T,assoc};yield", 100, 0, 20, 20000, 0, 10);
3899   dummy->SetStats(0);
3900   
3901   TGraphErrors* prevNear[6];
3902   TGraphErrors* prevAway[6];
3903   for (Int_t caseId=0; caseId<9; caseId++) // case 0->9
3904   {
3905     for (Int_t k=0; k<6; k++) // centrality
3906     {
3907       if (caseId != 3 && caseId < 5)
3908       {
3909         if (caseId < 4)
3910           c->cd(1 + k + caseId*6);
3911         else
3912           c->cd(1 + k + (caseId-1)*6);
3913         currentDummy = dummy->DrawCopy();
3914         currentDummy->GetYaxis()->SetRangeUser(0, max[caseId]);
3915         gPad->SetGridx();
3916         gPad->SetGridy();
3917         
3918         latex = new TLatex(0.15, 0.95, Form("%s - %s", caseString[caseId], centralityString[k]));
3919         latex->SetNDC();
3920         latex->SetTextSize(0.05);
3921         latex->Draw();
3922       }
3923       else if (caseId == 3)
3924         c->cd(1 + k + 2*6);
3925       else
3926         c->cd(1 + k + 3*6);
3927       
3928       for (Int_t j=0; j<3; j++) // trigger pt
3929       {
3930         if (caseId >= 2 && j != 1)
3931           continue;
3932         Printf("%d %d %d %d", caseId, k, j, caseList[caseId]);
3933       
3934         if (k < 3)
3935         {
3936           // CINT limitation here
3937           TGraphErrors** tmp = yields[0][j][centralityList[k]];
3938           nearSide = tmp[caseList[caseId]];
3939           //new TCanvas; nearSide->Draw("AP"); return;
3940           
3941           nearSide->SetMarkerStyle(markers1[j]);
3942           nearSide->SetMarkerColor(colors[j]);
3943           nearSide->SetLineColor(colors[j]);
3944           
3945           if (caseId == 0 && k == 0)
3946             l->AddEntry(nearSide, Form("trig pt bin %d", j), "P");
3947             
3948           TGraphErrors** tmp = yields[1][j][centralityList[k]];
3949           awaySide = tmp[caseList[caseId]];
3950           awaySide->SetMarkerStyle(markers2[j]);
3951           awaySide->SetMarkerColor(colors[j]);
3952           awaySide->SetLineColor(colors[j]);
3953             
3954           GraphShiftX(nearSide, -0.1 + j*0.1);
3955           GraphShiftX(awaySide, -0.1 + j*0.1);
3956           
3957           if (caseId == 3)
3958           {
3959             nearSide->SetLineColor(caseId - 2);
3960             nearSide->SetMarkerColor(caseId - 2);
3961             awaySide->SetLineColor(caseId - 2);
3962             awaySide->SetMarkerColor(caseId - 2);
3963           }
3964           
3965           if (caseId >= 4)
3966           {
3967             nearSide->SetLineColor(caseId - 3);
3968             nearSide->SetMarkerColor(caseId - 3);
3969             awaySide->SetLineColor(caseId - 3);
3970             awaySide->SetMarkerColor(caseId - 3);
3971           }
3972           
3973           awaySide->Print();
3974           
3975           prevNear[k] = (TGraphErrors*) nearSide->DrawClone("PSAME");
3976           prevAway[k] = (TGraphErrors*) awaySide->DrawClone("PSAME");
3977           
3978           if (caseId == 4)
3979           {
3980             Printf("%d", k);
3981             for (Int_t i=0; i<nearSide->GetN(); i++)
3982             {
3983               Printf("%f: %.0f%%", nearSide->GetX()[i], 100.0 * nearSide->GetEY()[i] / nearSide->GetY()[i]);
3984               Printf("%f: %.0f%%", awaySide->GetX()[i], 100.0 * awaySide->GetEY()[i] / awaySide->GetY()[i]);
3985             }
3986           }
3987         }
3988         else
3989         {
3990           // CINT limitation here
3991           tmp = yields[0][j][centralityList[k]]; nearSideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
3992           tmp = yields[1][j][centralityList[k]]; awaySideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
3993           
3994           tmp = yields[0][j][centralityList2[k]]; 
3995           nearSidePeripheral = tmp[caseList[caseId]];
3996           if (iaa && caseId == 3 && k >= 4)
3997             nearSidePeripheral = tmp[caseList[caseId-1]];
3998           
3999           tmp = yields[1][j][centralityList2[k]]; 
4000           awaySidePeripheral = tmp[caseList[caseId]];
4001           if (iaa && caseId == 3 && k >= 4)
4002             awaySidePeripheral = tmp[caseList[caseId-1]];
4003             
4004 //           nearSideCentral->Print();
4005 //           nearSidePeripheral->Print();
4006           
4007           if (k == 3)
4008             currentDummy->GetYaxis()->SetTitle("I_{CP}");
4009           else
4010             currentDummy->GetYaxis()->SetTitle("I_{AA}");
4011           currentDummy->GetYaxis()->SetRangeUser(0, max2[caseId]);
4012           
4013           for (Int_t i=0; i<nearSideCentral->GetN(); i++)
4014           {
4015             if (i >= nearSidePeripheral->GetN())
4016             {
4017               nearSideCentral->RemovePoint(i);
4018               i--;
4019               continue;
4020             }
4021           
4022             //Printf("near %d %f %f", i, nearSideCentral->GetY()[i], nearSidePeripheral->GetY()[i]);
4023             if (nearSidePeripheral->GetY()[i] <= 1e-5 || nearSideCentral->GetY()[i] <= 1e-5)
4024             {
4025               nearSideCentral->RemovePoint(i);
4026               nearSidePeripheral->RemovePoint(i);
4027               i--;
4028               continue;
4029             }
4030           
4031             nearSideCentral->GetEY()[i] = TMath::Sqrt(
4032               TMath::Power(nearSideCentral->GetEY()[i] / nearSideCentral->GetY()[i], 2) + 
4033               TMath::Power(nearSidePeripheral->GetEY()[i] / nearSidePeripheral->GetY()[i], 2) );
4034               
4035             nearSideCentral->GetY()[i] /= nearSidePeripheral->GetY()[i];
4036             nearSideCentral->GetY()[i] *= factors[k];
4037             
4038             nearSideCentral->GetEY()[i] *= nearSideCentral->GetY()[i];
4039           }
4040           //Printf("done");
4041           
4042           for (Int_t i=0; i<awaySideCentral->GetN(); i++)
4043           {
4044             if (i >= awaySidePeripheral->GetN())
4045             {
4046               awaySideCentral->RemovePoint(i);
4047               i--;
4048               continue;
4049             }
4050             
4051             //Printf("away %d", i);
4052             if (awaySidePeripheral->GetY()[i] <= 1e-5 || awaySideCentral->GetY()[i] <= 1e-5)
4053             {
4054               awaySideCentral->RemovePoint(i);
4055               awaySidePeripheral->RemovePoint(i);
4056               i--;
4057               continue;
4058             }
4059             
4060             awaySideCentral->GetEY()[i] = TMath::Sqrt(
4061               TMath::Power(awaySideCentral->GetEY()[i] / awaySideCentral->GetY()[i], 2) + 
4062               TMath::Power(awaySidePeripheral->GetEY()[i] / awaySidePeripheral->GetY()[i], 2) );
4063             
4064             awaySideCentral->GetY()[i] /= awaySidePeripheral->GetY()[i];
4065             awaySideCentral->GetY()[i] *= factors[k];
4066           
4067             awaySideCentral->GetEY()[i] *= awaySideCentral->GetY()[i];
4068           }
4069           
4070           if (caseId == 3)
4071           {
4072             nearSideCentral = (TGraphErrors*) nearSideCentral->Clone();
4073             nearSideCentral->SetLineColor(1);
4074             nearSideCentral->SetMarkerColor(1);
4075           
4076             awaySideCentral = (TGraphErrors*) awaySideCentral->Clone();
4077             awaySideCentral->SetLineColor(1);
4078             awaySideCentral->SetMarkerColor(1);
4079           }
4080           
4081           if (caseId >= 4)
4082           {
4083             nearSideCentral = (TGraphErrors*) nearSideCentral->Clone();
4084             nearSideCentral->SetLineColor(caseId - 3);
4085             nearSideCentral->SetMarkerColor(caseId - 3);
4086           
4087             awaySideCentral = (TGraphErrors*) awaySideCentral->Clone();
4088             awaySideCentral->SetLineColor(caseId - 3);
4089             awaySideCentral->SetMarkerColor(caseId - 3);
4090           }
4091           
4092           //Printf("%d", caseList[caseId]);
4093           
4094 //           nearSideCentral->Print();
4095           
4096           nearSideCentral->Draw("PSAME");
4097           awaySideCentral->Draw("PSAME");
4098         
4099           if (caseId == 3)
4100           {
4101             for (Int_t i=0; i<nearSideCentral->GetN(); i++)
4102               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]));
4103             for (Int_t i=0; i<awaySideCentral->GetN(); i++)
4104               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]));
4105           }
4106         
4107           prevNear[k] = nearSideCentral;
4108           prevAway[k] = awaySideCentral;
4109         }
4110       }
4111       if (caseId == 0 && k == 0)
4112         l->Draw();
4113     }
4114   }
4115   
4116   c->SaveAs("yields.png");
4117 }
4118
4119 void FitGaussians(const char* fileName, Bool_t flat)
4120 {
4121   CreateYieldStructure();
4122
4123   aliceFile = TFile::Open(fileName);
4124
4125   Int_t maxLeadingPt = 3;
4126   Int_t maxAssocPt = 3;
4127   
4128   TCanvas* canvas = new TCanvas("FitGaussians", "FitGaussians", 1000, 700);
4129   canvas->Divide(maxAssocPt, maxLeadingPt);
4130   
4131   for (Int_t i=0; i<maxLeadingPt; i++)
4132     for (Int_t j=0; j<maxAssocPt; j++)
4133     {
4134       TH1* first = 0;
4135       for (Int_t aliceCentrality=0; aliceCentrality<4; aliceCentrality++)
4136       {
4137         Printf("%d %d %d", i, j, aliceCentrality);
4138         
4139         canvas->cd(j+1 + (i) * maxAssocPt);
4140         gPad->SetLeftMargin(0.15);
4141         gPad->SetBottomMargin(0.2);
4142         //gPad->SetTopMargin(0.01);
4143         gPad->SetRightMargin(0.01);
4144         
4145         hist = (TH1*) aliceFile->Get(Form("dphi_%d_%d_%d%s", i, j, aliceCentrality, (flat) ? "_fit_flat" : ""));
4146         if (!hist)
4147           continue;
4148         
4149 //      hist->Rebin(2);
4150         
4151         // two Gauss fits
4152         gausFit = new TF1("gausFit", "[0] + gaus(1) + gaus(4)", -0.5 * TMath::Pi(), 1.5 * TMath::Pi());
4153         gausFit->SetParameters(0, 1, 0, 1, 1, TMath::Pi(), 1);
4154         gausFit->SetParLimits(0, -1, 10000);
4155         gausFit->SetParLimits(1, 0.001, 10000);
4156         gausFit->FixParameter(2, 0);
4157         gausFit->SetParLimits(3, 0.05, 10);
4158         gausFit->SetParLimits(4, 0.001, 10000);
4159         gausFit->FixParameter(5, TMath::Pi());
4160         gausFit->SetParLimits(6, 0.1, 10);
4161         
4162         gausFit->SetLineWidth(1);
4163         gausFit->SetLineColor(hist->GetLineColor());
4164         
4165         hist->Fit(gausFit, "0RIQ");
4166         gausFit->FixParameter(0, gausFit->GetParameter(0));
4167         hist->Fit(gausFit, "RI", (aliceCentrality == 0) ? "" : "SAME");
4168         //gausFit->DrawCopy("SAME");
4169         
4170         // get pT,assoc
4171         TPRegexp reg("(\\d+\\.\\d+) \\< p_\\{T,assoc\\} \\< (\\d+\\.\\d+)");
4172         arr = reg.MatchS(hist->GetTitle(), "", 0, 10);
4173         if (arr->GetEntries() != 3)
4174           continue;
4175           
4176         Float_t pt1 = atof(arr->At(1)->GetName());
4177         Float_t pt2 = atof(arr->At(2)->GetName());
4178
4179         FillYield(i, aliceCentrality, (pt1 + pt2) / 2, (pt2 - pt1) / 2, 18, gausFit->GetParameter(3), gausFit->GetParError(3), gausFit->GetParameter(6), gausFit->GetParError(6));
4180         
4181         if (!first)
4182           first = hist;
4183         else
4184           first->GetYaxis()->SetRangeUser(TMath::Min(first->GetMinimum(), hist->GetMinimum()), TMath::Max(first->GetMaximum(), hist->GetMaximum()));
4185       }
4186       first->GetYaxis()->SetRangeUser(first->GetMinimum(), 2 * first->GetMaximum());
4187         
4188 //        break;
4189     }
4190     
4191     
4192   // draw
4193   
4194   for (Int_t j=0; j<maxLeadingPt; j++)
4195   {
4196     new TCanvas;
4197     
4198     Int_t markers1[] = { 24, 25, 26, 30 };
4199     Int_t markers2[] = { 20, 21, 22, 29 };
4200     Int_t colors[] = { 1, 2, 3, 4 };
4201     
4202     dummy = new TH2F("dummy", ";p_{T,assoc};", 100, 0, 10, 1000, 0, 1);
4203     dummy->SetStats(0);
4204     dummy->Draw();
4205     
4206     for (Int_t k=0; k<4; k++) // centrality
4207     {
4208       // CINT limitation here
4209       TGraphErrors** tmp = yields[0][j][k];
4210       nearSide = tmp[18];
4211       nearSide->SetMarkerStyle(markers1[k]);
4212       nearSide->SetMarkerColor(colors[k]);
4213       nearSide->SetLineColor(colors[k]);  
4214     
4215       TGraphErrors** tmp = yields[1][j][k];
4216       awaySide = tmp[18];
4217       awaySide->SetMarkerStyle(markers2[k]);
4218       awaySide->SetMarkerColor(colors[k]);
4219       awaySide->SetLineColor(colors[k]);  
4220       
4221       nearSide->DrawClone("PSAME");
4222       awaySide->DrawClone("PSAME");
4223     }
4224   }
4225 }
4226
4227 void TsallisExamples()
4228 {
4229   tsallis = new TF1("tsallis", "[0] * (1-[2]*(1-[1])*x*x)**(1/(1-[1]))", -0.5 * TMath::Pi(), 1.5 * TMath::Pi());
4230   
4231   Float_t q[] = { 1.0000001, 1.5, 2 };
4232   Float_t beta[] = { 0.1, 1, 10, 100 };
4233   
4234   dummy = new TH2F("dummy", "", 100, -0.5 * TMath::Pi(), 1.5 * TMath::Pi(), 100, 0, 1.2);
4235   dummy->SetStats(0);
4236   dummy->Draw();
4237   
4238   legend = new TLegend(0.65, 0.5, 1, 1);
4239   legend->SetFillColor(0);
4240   
4241   for (Int_t i=0; i<3; i++)
4242     for (Int_t j=0; j<4; j++)
4243     {
4244       tsallis->SetParameters(1, q[i], beta[j]);
4245       tsallis->SetLineColor(i+1);
4246       tsallis->SetLineStyle(j+1);
4247       
4248       legend->AddEntry(tsallis->DrawCopy("SAME"), Form("q = %.1f, #beta = %.1f", q[i], beta[j]), "L");
4249     }
4250     
4251   legend->Draw();
4252 }
4253
4254 void DrawTsallisParams()
4255 {
4256   ReadYields();
4257   
4258   c = new TCanvas("c", "c", 900, 600);
4259   c->Divide(3, 2);
4260   
4261   Int_t markers1[] = { 24, 25, 26, 30 };
4262   Int_t markers2[] = { 20, 21, 22, 29 };
4263   Int_t colors[] = { 1, 2, 3, 4 };
4264   Int_t caseList[] = { 12, 13, 8, 6, 8, 9, 10, 11, 1, 7 };
4265   const char* caseString[] = { "q", "beta" };
4266   const char* centralityString[] = { "0-5%", "20-40%", "60-90%", "0-5% vs 20-40%", "0-5% vs 60-90%", "20-40% vs 60-90%" };
4267   
4268   l = new TLegend(0.5, 0.5, 0.9, 0.9);
4269   l->SetFillColor(0);
4270   
4271   Float_t max[] = { 3, 1000 };
4272   Float_t max2[] = { 5, 2 };
4273   
4274   dummy = new TH2F("dummy", ";p_{T,assoc};", 100, 0, 20, 1000, 0, 1000);
4275   dummy->SetStats(0);
4276   
4277   for (Int_t caseId=0; caseId<2; caseId++) // case
4278   {
4279     for (Int_t k=0; k<3; k++) // centrality
4280     {
4281       c->cd(1 + k + caseId*3);
4282         
4283       currentDummy = dummy->DrawCopy();
4284       currentDummy->GetYaxis()->SetRangeUser(0, max[caseId]);
4285       if (caseId == 1 && k < 3)
4286         gPad->SetLogy();
4287       
4288       latex = new TLatex(0.15, 0.95, Form("%s - %s", caseString[caseId], centralityString[k]));
4289       latex->SetNDC();
4290       latex->SetTextSize(0.05);
4291       latex->Draw();
4292       
4293       for (Int_t j=0; j<2; j++) // trigger pt
4294       {
4295         if (k < 3)
4296         {
4297           // CINT limitation here
4298           TGraphErrors** tmp = yields[0][j][k];
4299           nearSide = tmp[caseList[caseId]];
4300           nearSide->SetMarkerStyle(markers1[j]);
4301           nearSide->SetMarkerColor(colors[j]);
4302           nearSide->SetLineColor(colors[j]);
4303           
4304           if (caseId == 0 && k == 0)
4305             l->AddEntry(nearSide, Form("trig pt bin %d", j), "P");
4306             
4307           TGraphErrors** tmp = yields[1][j][k];
4308           awaySide = tmp[caseList[caseId]];
4309           awaySide->SetMarkerStyle(markers2[j]);
4310           awaySide->SetMarkerColor(colors[j]);
4311           awaySide->SetLineColor(colors[j]);
4312             
4313           GraphShiftX(nearSide, -0.1 + j*0.1);
4314           GraphShiftX(awaySide, -0.1 + j*0.1);
4315           
4316           Printf("%d %d %d", caseId, j, k);
4317           nearSide->Print();
4318           awaySide->Print();
4319           
4320           nearSide->DrawClone("PSAME");
4321           awaySide->DrawClone("PSAME");
4322         }
4323         else
4324         {
4325           // CINT limitation here
4326           if (k == 3)
4327           {
4328             tmp = yields[0][j][0]; nearSideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
4329             tmp = yields[1][j][0]; awaySideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
4330             tmp = yields[0][j][1]; nearSidePeripheral = tmp[caseList[caseId]];
4331             tmp = yields[1][j][1]; awaySidePeripheral = tmp[caseList[caseId]];
4332           }
4333           else if (k == 4)
4334           {
4335             tmp = yields[0][j][0]; nearSideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
4336             tmp = yields[1][j][0]; awaySideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
4337             tmp = yields[0][j][2]; nearSidePeripheral = tmp[caseList[caseId]];
4338             tmp = yields[1][j][2]; awaySidePeripheral = tmp[caseList[caseId]];
4339           }
4340           else if (k == 5)
4341           {
4342             tmp = yields[0][j][1]; nearSideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
4343             tmp = yields[1][j][1]; awaySideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
4344             tmp = yields[0][j][2]; nearSidePeripheral = tmp[caseList[caseId]];
4345             tmp = yields[1][j][2]; awaySidePeripheral = tmp[caseList[caseId]];
4346           }
4347           
4348           currentDummy->GetYaxis()->SetTitle("I_{CP}");
4349           currentDummy->GetYaxis()->SetRangeUser(0, max2[caseId]);
4350         
4351           for (Int_t i=0; i<nearSideCentral->GetN(); i++)
4352           {
4353             //Printf("near %d %f %f", i, nearSideCentral->GetY()[i], nearSidePeripheral->GetY()[i]);
4354             if (nearSidePeripheral->GetY()[i] <= 1e-5 || nearSideCentral->GetY()[i] <= 1e-5)
4355             {
4356               nearSideCentral->RemovePoint(i);
4357               nearSidePeripheral->RemovePoint(i);
4358               i--;
4359               continue;
4360             }
4361           
4362             nearSideCentral->GetEY()[i] = TMath::Sqrt(
4363               TMath::Power(nearSideCentral->GetEY()[i] / nearSideCentral->GetY()[i], 2) + 
4364               TMath::Power(nearSidePeripheral->GetEY()[i] / nearSidePeripheral->GetY()[i], 2) );
4365               
4366             nearSideCentral->GetY()[i] /= nearSidePeripheral->GetY()[i];
4367             
4368             nearSideCentral->GetEY()[i] *= nearSideCentral->GetY()[i];
4369           }
4370           //Printf("done");
4371           
4372           for (Int_t i=0; i<awaySideCentral->GetN(); i++)
4373           {
4374             //Printf("away %d", i);
4375             if (awaySidePeripheral->GetY()[i] <= 1e-5 || awaySideCentral->GetY()[i] <= 1e-5)
4376             {
4377               awaySideCentral->RemovePoint(i);
4378               awaySidePeripheral->RemovePoint(i);
4379               i--;
4380               continue;
4381             }
4382             
4383             awaySideCentral->GetEY()[i] = TMath::Sqrt(
4384               TMath::Power(awaySideCentral->GetEY()[i] / awaySideCentral->GetY()[i], 2) + 
4385               TMath::Power(awaySidePeripheral->GetEY()[i] / awaySidePeripheral->GetY()[i], 2) );
4386             
4387             awaySideCentral->GetY()[i] /= awaySidePeripheral->GetY()[i];
4388           
4389             awaySideCentral->GetEY()[i] *= awaySideCentral->GetY()[i];
4390           }
4391           
4392           if (caseId == 3)
4393           {
4394             nearSideCentral = (TGraphErrors*) nearSideCentral->Clone();
4395             nearSideCentral->SetLineColor(1);
4396             nearSideCentral->SetMarkerColor(1);
4397           
4398             awaySideCentral = (TGraphErrors*) awaySideCentral->Clone();
4399             awaySideCentral->SetLineColor(1);
4400             awaySideCentral->SetMarkerColor(1);
4401           }
4402           
4403           if (caseId >= 4)
4404           {
4405             nearSideCentral = (TGraphErrors*) nearSideCentral->Clone();
4406             nearSideCentral->SetLineColor(caseId - 3);
4407             nearSideCentral->SetMarkerColor(caseId - 3);
4408           
4409             awaySideCentral = (TGraphErrors*) awaySideCentral->Clone();
4410             awaySideCentral->SetLineColor(caseId - 3);
4411             awaySideCentral->SetMarkerColor(caseId - 3);
4412           }
4413           
4414           //Printf("%d", caseList[caseId]);
4415           
4416           nearSideCentral->Draw("PSAME");
4417           awaySideCentral->Draw("PSAME");
4418         }
4419       }
4420       if (caseId == 0 && k == 0)
4421         l->Draw();
4422     }
4423   }
4424   
4425   c->SaveAs("tsallisparams.png");
4426 }
4427
4428 void DrawYieldLHCRHIC_ICP(const char* fileName = "yields.root")
4429 {
4430   Int_t caseId = 0;
4431   Int_t caseList[] = { 18 };
4432   Int_t j = 1;
4433   
4434   ReadYields(fileName);
4435   
4436   c = new TCanvas("lhc_rhic", "lhc_rhic", 800, 600);
4437   gPad->SetGridx();
4438   gPad->SetGridy();
4439   
4440   dummy = new TH2F("dummy", ";p_{T,assoc};I_{CP}", 100, 0, 12, 1000, 0, 10);
4441   dummy->SetStats(0);
4442   currentDummy = dummy->DrawCopy();
4443   currentDummy->GetYaxis()->SetRangeUser(0, 2);
4444         
4445   TGraphErrors** tmp = yields[0][j][0]; nearSideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
4446   tmp = yields[1][j][0]; awaySideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
4447   tmp = yields[0][j][2]; nearSidePeripheral = tmp[caseList[caseId]];
4448   tmp = yields[1][j][2]; awaySidePeripheral = tmp[caseList[caseId]];
4449         
4450   for (Int_t i=0; i<nearSideCentral->GetN(); i++)
4451   {
4452     //Printf("near %d %f %f", i, nearSideCentral->GetY()[i], nearSidePeripheral->GetY()[i]);
4453     if (nearSidePeripheral->GetY()[i] <= 1e-5 || nearSideCentral->GetY()[i] <= 1e-5)
4454     {
4455       nearSideCentral->RemovePoint(i);
4456       nearSidePeripheral->RemovePoint(i);
4457       i--;
4458       continue;
4459     }
4460   
4461     nearSideCentral->GetEY()[i] = TMath::Sqrt(
4462       TMath::Power(nearSideCentral->GetEY()[i] / nearSideCentral->GetY()[i], 2) + 
4463       TMath::Power(nearSidePeripheral->GetEY()[i] / nearSidePeripheral->GetY()[i], 2) );
4464       
4465     nearSideCentral->GetY()[i] /= nearSidePeripheral->GetY()[i];
4466     
4467     nearSideCentral->GetEY()[i] *= nearSideCentral->GetY()[i];
4468   }
4469   //Printf("done");
4470   
4471   for (Int_t i=0; i<awaySideCentral->GetN(); i++)
4472   {
4473     //Printf("away %d", i);
4474     if (awaySidePeripheral->GetY()[i] <= 1e-5 || awaySideCentral->GetY()[i] <= 1e-5)
4475     {
4476       awaySideCentral->RemovePoint(i);
4477       awaySidePeripheral->RemovePoint(i);
4478       i--;
4479       continue;
4480     }
4481     
4482     awaySideCentral->GetEY()[i] = TMath::Sqrt(
4483       TMath::Power(awaySideCentral->GetEY()[i] / awaySideCentral->GetY()[i], 2) + 
4484       TMath::Power(awaySidePeripheral->GetEY()[i] / awaySidePeripheral->GetY()[i], 2) );
4485     
4486     awaySideCentral->GetY()[i] /= awaySidePeripheral->GetY()[i];
4487   
4488     awaySideCentral->GetEY()[i] *= awaySideCentral->GetY()[i];
4489   }
4490           
4491   nearSideCentral->SetMarkerStyle(21);
4492   nearSideCentral->SetLineColor(1);
4493   nearSideCentral->SetMarkerColor(1);
4494           
4495   awaySideCentral->SetMarkerStyle(25);
4496   awaySideCentral->SetLineColor(1);
4497   awaySideCentral->SetMarkerColor(1);
4498   
4499   nearSideCentral->Draw("PSAME");
4500   awaySideCentral->Draw("PSAME");        
4501
4502   legend = new TLegend(0.4, 0.8, 0.99, 0.99);
4503   legend->SetFillColor(0);
4504   legend->AddEntry(nearSideCentral, "ALICE I_{CP} Near 8-15 GeV 0-5%/60-90%", "P");
4505   legend->AddEntry(awaySideCentral, "ALICE I_{CP} Away 8-15 GeV 0-5%/60-90%", "P");
4506   
4507   if (0)
4508   {
4509     nearSideCentral->Fit("pol1", "", "SAME", 4.5, 11.5);
4510     awaySideCentral->Fit("pol1", "", "SAME", 4.5, 11.5);
4511     nearSideCentral->GetFunction("pol1")->SetLineWidth(1);
4512     awaySideCentral->GetFunction("pol1")->SetLineWidth(1);
4513   }
4514
4515   if (0)
4516   {
4517     // RCP, ALICE
4518     dndpt_central = ReadHepdata("raa_dndpt_central.txt", kFALSE, 3);
4519     dndpt_peripheral = ReadHepdata("raa_dndpt_peripheral.txt", kFALSE, 3);
4520     
4521     //dndpt_central->Print();
4522     //dndpt_peripheral->Print();
4523     
4524     // ratio of Ncoll (from paper)
4525     // TODO there is also an uncertainty on that
4526     Double_t scale = 1690. / 15.7;
4527     Double_t scaleUnc = TMath::Sqrt(TMath::Power(131. / 1690., 2) + TMath::Power(0.7 / 15.7, 2));
4528     
4529     for (Int_t i=0; i<dndpt_central->GetN(); i++)
4530     {
4531       dndpt_central->GetEY()[i] = TMath::Sqrt(TMath::Power(dndpt_central->GetEY()[i] / dndpt_central->GetY()[i], 2) + 
4532         TMath::Power(dndpt_peripheral->GetEY()[i] / dndpt_peripheral->GetY()[i], 2));
4533       dndpt_central->GetY()[i] /= dndpt_peripheral->GetY()[i] * scale;
4534       dndpt_central->GetEY()[i] *= dndpt_central->GetY()[i];
4535     }
4536     
4537     //new TCanvas;
4538     //dndpt_central->Print();
4539     //dndpt_central->Draw("AP");
4540     
4541     dndpt_central->Draw("*SAME");
4542     
4543     latex = new TLatex(0.34, 0.09, "9% N_{coll} scale uncertainty on R_{CP}");
4544     latex->SetTextSize(0.03);
4545     latex->Draw();
4546     
4547     // RAA, ALICE
4548     raa_central = ReadHepdata("raa_alice_central.txt", kFALSE, 3);
4549     raa_central->SetMarkerStyle(20);
4550     //raa_central->Draw("PSAME");
4551   
4552     legend->AddEntry(dndpt_central, "ALICE R_{CP} 0-5%/70-80%", "P");
4553   }
4554   
4555   if (0)
4556   {
4557     // IAA, RHIC
4558     // calculate ICP from IAA(0-20) / IAA (20-60)
4559     // TODO only using uncertainties from IAA(0-20)
4560     // TODO systematic uncertainty stored in graph with _sys appended
4561     TFile::Open("rhic/pi0h_graphs.root");
4562     
4563     for (Int_t i=0; i<3; i+=2)
4564     {
4565       // gIAA_<ptTrigBin>_<centBin>_<angularRegionBin>
4566       central = (TGraphErrors*) gFile->Get(Form("gIAA_3_0_%d", i));
4567       peripheral = (TGraphErrors*) gFile->Get(Form("gIAA_3_1_%d", i));
4568       
4569       for (Int_t j=0; j<central->GetN(); j++)
4570       {
4571         central->GetY()[j] /= peripheral->GetY()[j];
4572         central->GetEY()[j] /= peripheral->GetY()[j];
4573       }
4574       
4575       central->SetMarkerStyle((i == 0) ? 29 : 30);
4576       central->SetMarkerColor(2);
4577       central->SetLineColor(2);
4578       central->Draw("PSAME");
4579       legend->AddEntry(central, Form("PHENIX I_{CP} %s 9-12 GeV 0-20%/20-60%", (i == 0) ? "Near" : "Away"), "P");
4580     }
4581   }
4582   
4583   legend->Draw();
4584   
4585   c->SaveAs("icp.png");
4586 }
4587
4588 TGraphErrors* GetRatio(const char* fileName, Int_t centrality1, Int_t centrality2, Int_t triggerId, Int_t caseId, Int_t side, const char* fileName2 = 0)
4589 {
4590   // 0 = near side; 1 = away side
4591
4592   ReadYields(fileName);
4593   
4594   TGraphErrors** tmp = yields[side][triggerId][centrality1]; 
4595   nearSideCentral = (TGraphErrors*) tmp[caseId]->Clone();
4596   
4597   if (fileName2)
4598     ReadYields(fileName2);
4599   
4600   tmp = yields[side][triggerId][centrality2]; 
4601   nearSidePeripheral = (TGraphErrors*) tmp[caseId]->Clone();
4602   
4603 //   Printf("%d %d", nearSideCentral->GetN(), nearSidePeripheral->GetN());
4604         
4605   for (Int_t i=0; i<nearSideCentral->GetN(); i++)
4606   {
4607     if (nearSidePeripheral->GetY()[i] <= 1e-5 || nearSideCentral->GetY()[i] <= 1e-5)
4608     {
4609       nearSideCentral->RemovePoint(i);
4610       nearSidePeripheral->RemovePoint(i);
4611       i--;
4612       continue;
4613     }
4614     
4615     if (nearSideCentral->GetX()[i] != nearSidePeripheral->GetX()[i])
4616     {
4617       Printf("Inconsistent x values %f %f", nearSideCentral->GetX()[i], nearSidePeripheral->GetX()[i]);
4618       AliFatal("");
4619     }
4620   
4621 //     printf("%f %f %f", nearSideCentral->GetX()[i], nearSideCentral->GetY()[i], nearSidePeripheral->GetY()[i]);
4622     
4623     nearSideCentral->GetEY()[i] = TMath::Sqrt(
4624       TMath::Power(nearSideCentral->GetEY()[i] / nearSideCentral->GetY()[i], 2) + 
4625       TMath::Power(nearSidePeripheral->GetEY()[i] / nearSidePeripheral->GetY()[i], 2) );
4626       
4627     nearSideCentral->GetY()[i] /= nearSidePeripheral->GetY()[i];
4628     // scaling for IAA
4629     if (centrality2 == 3)
4630       nearSideCentral->GetY()[i] /= kPythiaScalingFactor;
4631     
4632 //     Printf(" %f", nearSideCentral->GetY()[i]);
4633     
4634     nearSideCentral->GetEY()[i] *= nearSideCentral->GetY()[i];
4635   }
4636   
4637   //nearSideCentral->GetXaxis()->SetTitle("p_{T, assoc}");
4638   //nearSideCentral->GetYaxis()->SetTitle((centrality2 == 3) ? "I_{AA}" : "I_{CP}");
4639
4640   if (0 && side == 1 && centrality2 == 3)
4641   {
4642     Printf("\n\n\nWARNING !!! Fudging different away side acceptance (only for second file)\n\n\n");
4643     ScaleGraph(nearSideCentral, 1.56);
4644   }
4645   
4646   return nearSideCentral;
4647 }
4648
4649 TGraphErrors* GetIAA(const char* fileName, Int_t centrality, Int_t triggerId, Int_t caseId, Int_t side)
4650 {
4651   return GetRatio(fileName, centrality, 3, triggerId, caseId, side);
4652 }
4653
4654 TGraphErrors* GetICP(const char* fileName, Int_t triggerId, Int_t caseId, Int_t side)
4655 {
4656   return GetRatio(fileName, 1, 2, triggerId, caseId, side);
4657 }
4658
4659 void DrawYieldLHCRHIC_IAA(const char* fileName, Bool_t central, Bool_t rhic)
4660 {
4661   Int_t caseId = 0;
4662   Int_t caseList[] = { 18 };
4663   Int_t j = 1;
4664   
4665   ReadYields(fileName);
4666   
4667   c = new TCanvas("lhc_rhic", "lhc_rhic", 800, 600);
4668   gPad->SetGridx();
4669   gPad->SetGridy();
4670   
4671   dummy = new TH2F("dummy", ";p_{T,assoc};I_{AA}", 100, 0, 12, 1000, 0, 10);
4672   dummy->SetStats(0);
4673   currentDummy = dummy->DrawCopy();
4674   currentDummy->GetYaxis()->SetRangeUser(0, 3);
4675         
4676   Int_t nominatorBin = 0;
4677   if (!central)
4678     nominatorBin = 2;
4679         
4680   nearSideCentral = GetIAA(fileName, nominatorBin, j, caseList[caseId], 0);
4681   awaySideCentral = GetIAA(fileName, nominatorBin, j, caseList[caseId], 1);
4682   
4683   nearSideCentral->SetMarkerStyle(21);
4684   nearSideCentral->SetLineColor(1);
4685   nearSideCentral->SetMarkerColor(1);
4686           
4687   awaySideCentral->SetMarkerStyle(25);
4688   awaySideCentral->SetLineColor(1);
4689   awaySideCentral->SetMarkerColor(1);
4690   
4691   nearSideCentral->Draw("PSAME");
4692   awaySideCentral->Draw("PSAME");        
4693   
4694   legend = new TLegend(0.4, 0.8, 0.99, 0.99);
4695   legend->SetFillColor(0);
4696   legend->AddEntry(nearSideCentral, Form("ALICE I_{AA} Near 8-15 GeV %s%%/Pythia6", (central) ? "0-5" : "60-90"), "P");
4697   legend->AddEntry(awaySideCentral, Form("ALICE I_{AA} Away 8-15 GeV %s%%/Pythia6", (central) ? "0-5" : "60-90"), "P");
4698   
4699   if (rhic)
4700   {
4701     // IAA, RHIC
4702     // systematic uncertainty stored in graph with _sys appended
4703     TFile::Open("rhic/pi0h_graphs.root");
4704     
4705     for (Int_t i=0; i<3; i+=2)
4706     {
4707       // gIAA_<ptTrigBin>_<centBin>_<angularRegionBin>
4708       rhic_iaa = (TGraphErrors*) gFile->Get(Form("gIAA_2_%d_%d", (central) ? 0 : 1, i));
4709       rhic_iaa_sys = (TGraphErrors*) gFile->Get(Form("gIAA_2_%d_%d_sys", (central) ? 0 : 1, i));
4710   
4711       rhic_iaa->SetMarkerStyle((i == 0) ? 29 : 30);
4712       rhic_iaa->SetMarkerColor(2);
4713       rhic_iaa->SetLineColor(2);
4714       rhic_iaa->Draw("PSAME");
4715       rhic_iaa_sys->SetLineColor(2);
4716       rhic_iaa_sys->SetMarkerColor(2);
4717       rhic_iaa_sys->Draw("PSAME");
4718       legend->AddEntry(rhic_iaa, Form("PHENIX I_{AA} %s 7-9 GeV %s%%/pp", (i == 0) ? "Near" : "Away", (central) ? "0-20" : "20-60"), "P");
4719     }
4720     for (Int_t i=0; i<3; i+=2)
4721     {
4722       // gIAA_<ptTrigBin>_<centBin>_<angularRegionBin>
4723       rhic_iaa = (TGraphErrors*) gFile->Get(Form("gIAA_3_%d_%d", (central) ? 0 : 1, i));
4724       rhic_iaa_sys = (TGraphErrors*) gFile->Get(Form("gIAA_3_%d_%d_sys", (central) ? 0 : 1, i));
4725   
4726       rhic_iaa->SetMarkerStyle((i == 0) ? 20 : 24);
4727       rhic_iaa->SetMarkerColor(4);
4728       rhic_iaa->SetLineColor(4);
4729       rhic_iaa->Draw("PSAME");
4730       rhic_iaa_sys->SetLineColor(4);
4731       rhic_iaa_sys->SetMarkerColor(4);
4732       rhic_iaa_sys->Draw("PSAME");
4733       legend->AddEntry(rhic_iaa, Form("PHENIX I_{AA} %s 9-12 GeV %s%%/pp", (i == 0) ? "Near" : "Away", (central) ? "0-20" : "20-60"), "P");
4734     }
4735   }
4736   
4737   legend->Draw();
4738   
4739   c->SaveAs("iaa.png");
4740 }
4741
4742 void CompareIAAICP(const char* fileName1, const char* fileName2, Int_t nominatorBin, Int_t denominatorBin, Bool_t skipAway = kFALSE)
4743 {
4744   Int_t j = 1;
4745   Int_t caseId = 18;
4746 //   caseId = 23; Printf("WARNING: Comparing case 23");
4747   //Int_t caseId = 12;
4748
4749   nearSide1 = GetRatio(fileName1, nominatorBin, denominatorBin, j, caseId, 0);
4750   if (!skipAway)
4751     awaySide1 = GetRatio(fileName1, nominatorBin, denominatorBin, j, caseId, 1);
4752   else
4753     awaySide1 = new TGraphErrors;
4754   
4755   kPythiaScalingFactor = 1;
4756   nearSide2 = GetRatio(fileName2, nominatorBin, denominatorBin, j, caseId, 0);
4757   if (!skipAway)
4758     awaySide2 = GetRatio(fileName2, nominatorBin, denominatorBin, j, caseId, 1);
4759   else
4760     awaySide2 = new TGraphErrors;
4761   
4762 //   Printf("\n\n\nWARNING !!! Fudging different away side acceptance (only for second file)\n\n\n");
4763 //   ScaleGraph(awaySide2, 1.56);
4764   
4765 /*  ScaleGraph(nearSide2, 1.33);
4766   ScaleGraph(awaySide2, 1.33);*/
4767   
4768   c = new TCanvas;
4769   dummy = new TH2F("dummy", Form(";p_{T,assoc};%s", (denominatorBin == 3) ? "I_{AA}" : "I_{CP}"), 100, 2, 12, 1000, 0, 10);
4770   dummy->SetStats(0);
4771   currentDummy = dummy->DrawCopy();
4772   currentDummy->GetYaxis()->SetRangeUser(0, 2.5);
4773   
4774   nearSide1->SetMarkerStyle(21);
4775   nearSide1->SetLineColor(1);
4776   nearSide1->SetMarkerColor(1);
4777           
4778   nearSide2->SetMarkerStyle(21);
4779   nearSide2->SetLineColor(2);
4780   nearSide2->SetMarkerColor(2);
4781   
4782   awaySide1->SetMarkerStyle(25);
4783   awaySide1->SetLineColor(1);
4784   awaySide1->SetMarkerColor(1);
4785   
4786   awaySide2->SetMarkerStyle(25);
4787   awaySide2->SetLineColor(2);
4788   awaySide2->SetMarkerColor(2);
4789   
4790   RemovePointsBelowX(nearSide1, 3);
4791   RemovePointsBelowX(nearSide2, 3);
4792   RemovePointsBelowX(awaySide1, 3);
4793   RemovePointsBelowX(awaySide2, 3);
4794   
4795   gPad->SetGridx();
4796   gPad->SetGridy();
4797   
4798   nearSide1->DrawClone("PSAME");
4799   awaySide1->DrawClone("PSAME");        
4800   nearSide2->DrawClone("PSAME");
4801   awaySide2->DrawClone("PSAME");        
4802   
4803   new TCanvas;
4804   currentDummy = dummy->DrawCopy();
4805   currentDummy->GetYaxis()->SetRangeUser(0.5, 1.5);
4806   gPad->SetGridx();
4807   gPad->SetGridy();
4808   
4809   DivideGraphs(nearSide1, nearSide2);
4810   DivideGraphs(awaySide1, awaySide2);
4811   
4812   nearSide1->Draw("PSAME");
4813   awaySide1->Draw("PSAME");        
4814   
4815   nearSide1->Fit("pol0", "", "SAME", 3.01, 9.99);
4816   awaySide1->Fit("pol0", "", "SAME", 3.01, 9.99);
4817 }
4818
4819 void ScaleGraph(TGraphErrors* graph, Float_t factor)
4820 {
4821         for (Int_t i=0; i<graph->GetN(); i++)
4822         {
4823     graph->GetY()[i] *= factor;
4824     graph->GetEY()[i] *= factor;
4825   }
4826 }
4827
4828 TGraphErrors* DrawBaselines(const char* fileName, Int_t numeratorBin, Int_t denominatorBin, Int_t side, Bool_t verbose = kTRUE)
4829 {
4830   Int_t j = 1;
4831   
4832   TGraphErrors* first = 0;
4833   TGraphErrors* max = 0;
4834   
4835   if (verbose)
4836   {
4837     c = new TCanvas;
4838     dummy = new TH2F("dummy", Form(";p_{T,assoc};%s", (denominatorBin == 3) ? "I_{AA}" : "I_{CP}"), 100, 0, 12, 1000, 0, 10);
4839     dummy->SetStats(0);
4840     currentDummy = dummy->DrawCopy();
4841     currentDummy->GetYaxis()->SetRangeUser(0, 3);
4842     
4843     c2 = new TCanvas;
4844     currentDummy = dummy->DrawCopy();
4845     currentDummy->GetYaxis()->SetRangeUser(0, 2);
4846   }
4847   
4848 //   Int_t caseList[] = { 18, 19, 21, 22 };
4849   //Int_t caseList[] = { 23, 24, 26, 27 };
4850   Int_t caseList[] = { 18, 19, 22 };
4851   
4852   for (Int_t caseId = 0; caseId < 3; caseId++)
4853   {
4854     graph = GetRatio(fileName, numeratorBin, denominatorBin, j, caseList[caseId], side);
4855     
4856     graph->SetLineColor(caseId + 1);
4857     graph->SetMarkerColor(caseId + 1);
4858     
4859     RemovePointsBelowX(graph, 3);
4860     
4861     if (verbose)
4862     {
4863       c->cd();
4864       graph->DrawClone("*SAME");
4865     }
4866     
4867     if (!first)
4868     {
4869       first = graph;
4870       max = (TGraphErrors*) graph->Clone();
4871       for (Int_t i=0; i<max->GetN(); i++)
4872       {
4873         max->GetY()[i] = 0;
4874         max->GetEY()[i] = 0;
4875       }
4876     }
4877     else
4878     {
4879       DivideGraphs(graph, first);
4880       
4881       if (verbose)
4882       {
4883         c2->cd();
4884         graph->DrawClone("*SAME");
4885       }
4886       
4887       for (Int_t i=0; i<graph->GetN(); i++)
4888       {
4889         if (max->GetY()[i] < TMath::Abs(graph->GetY()[i] - 1))
4890           max->GetY()[i] = TMath::Abs(graph->GetY()[i] - 1);
4891       }
4892     }
4893   }
4894   
4895   if (verbose)
4896   {
4897     new TCanvas;
4898     max->Draw("A*");
4899   }
4900   
4901   max->GetXaxis()->SetTitle("p_{T, assoc}");
4902   max->GetYaxis()->SetTitle((denominatorBin == 3) ? "Effect on I_{AA}" : "Effect on I_{CP}");
4903   max->GetYaxis()->SetRangeUser(0, 0.4);
4904   
4905   return max;
4906 }
4907
4908 void DrawBaselinesAll(const char* fileName)
4909 {
4910   c = new TCanvas("c", "c", 1000, 600);
4911   c->Divide(4, 2);
4912   
4913   for (Int_t i=0; i<2; i++)
4914   {
4915     c->cd(1+i*4); DrawBaselines(fileName, 0, 3, i, kFALSE)->Draw("A*"); gPad->SetGridy();
4916     c->cd(2+i*4); DrawBaselines(fileName, 1, 3, i, kFALSE)->Draw("A*"); gPad->SetGridy();
4917     c->cd(3+i*4); DrawBaselines(fileName, 2, 3, i, kFALSE)->Draw("A*"); gPad->SetGridy();
4918     c->cd(4+i*4); DrawBaselines(fileName, 0, 2, i, kFALSE)->Draw("A*"); gPad->SetGridy();
4919   }
4920 }
4921
4922 TGraphErrors* DrawSystUncIAAPYTHIA(TGraphErrors* graph, Int_t iaa_icp, Int_t awaySide)
4923 {
4924   // iaa = 0, icp = 1
4925
4926   Float_t baseline = 1;
4927   if (awaySide == 0)
4928     baseline = 0.07;
4929   else if (awaySide == 1)
4930     baseline = 0.2;
4931     
4932   /*
4933   Float_t reference = 0;
4934   if (iaa_icp == 0)
4935     reference = 0.13;
4936   */
4937     
4938   Float_t efficiency = 0.08;
4939   
4940   Float_t centrality = 1;
4941   if (iaa_icp == 0)
4942     centrality = (awaySide == 0) ? 0.02 : 0.06;
4943   else if (iaa_icp == 1)
4944     centrality = (awaySide == 0) ? 0.04 : 0.08;
4945   
4946   Float_t ptResolution = 0;
4947   
4948   Float_t total = TMath::Sqrt(baseline * baseline + efficiency * efficiency + centrality * centrality + ptResolution * ptResolution);
4949   
4950   Printf("Total syst: %f", total);
4951   
4952   systUnc = (TGraphErrors*) graph->Clone();
4953   for (Int_t i=0; i<systUnc->GetN(); i++)
4954   {
4955     systUnc->GetEY()[i] = systUnc->GetY()[i] * total;
4956     systUnc->GetEX()[i] = 0;
4957   }
4958     
4959   //systUnc->Print();
4960   
4961   systUnc->SetLineColor(kGray + 1);
4962   systUnc->SetLineWidth(6);
4963   
4964   systUnc->Draw("PSAME");
4965     
4966   return systUnc;
4967 }
4968
4969 TGraphErrors* DrawSystUncPreliminaries(TGraphErrors* graph, Int_t iaa_icp, Int_t awaySide, Int_t iaa, Bool_t central)
4970 {
4971   // iaa = 0, icp = 1
4972
4973   Float_t baseline = 1;
4974   if (awaySide == 0)
4975     baseline = 0.05;
4976   else if (awaySide == 1)
4977   {
4978     if (iaa == 0 && central || iaa == 1)
4979       baseline = 0.2;
4980     else if (iaa == 0 && !central)
4981       baseline = 0.05;
4982     else if (iaa == 2 && central)
4983       baseline = 0.1;
4984   }
4985     
4986   /*
4987   Float_t reference = 0;
4988   if (iaa_icp == 0)
4989     reference = 0.13;
4990   */
4991     
4992   Float_t efficiency = 0.08;
4993   if (iaa_icp == 1)
4994     efficiency = 0.05;
4995   
4996   Float_t centrality = 1;
4997   if (iaa_icp == 0)
4998     centrality = 0.04;
4999   else if (iaa_icp == 1)
5000     centrality = 0.06;
5001   
5002   Float_t ptResolution = 0.03;
5003   
5004   Float_t integrationWindow = 0;
5005   if (awaySide == 1)
5006     integrationWindow = 0.03;
5007   
5008   Float_t total = TMath::Sqrt(baseline * baseline + efficiency * efficiency + centrality * centrality + ptResolution * ptResolution + integrationWindow * integrationWindow);
5009   
5010   Printf("Total syst: %f", total);
5011   
5012   systUnc = (TGraphErrors*) graph->Clone();
5013   for (Int_t i=0; i<systUnc->GetN(); i++)
5014   {
5015     systUnc->GetEY()[i] = systUnc->GetY()[i] * total;
5016     systUnc->GetEX()[i] = 0;
5017   }
5018     
5019   //systUnc->Print();
5020   
5021   systUnc->SetLineColor(kGray + 1);
5022   systUnc->SetLineWidth(6);
5023   
5024   systUnc->Draw("PSAME");
5025     
5026   return systUnc;
5027 }
5028
5029 TGraphErrors* DrawSystUnc(TGraphErrors* graph, Int_t iaa_icp, Int_t awaySide, Int_t iaa, Bool_t central, Float_t shift = 0.0)
5030 {
5031   // iaa_icp: iaa = 0, icp = 1
5032
5033   Float_t baseline = 1;
5034   if (awaySide == 0)
5035     baseline = 0.05;
5036   else if (awaySide == 1)
5037   {
5038     if (iaa == 0 && central || iaa == 1)
5039       baseline = 0.2;
5040     else if (iaa == 0 && !central)
5041       baseline = 0.05;
5042     else if (iaa == 2 && central)
5043       baseline = 0.1;
5044   }
5045     
5046   /*
5047   Float_t reference = 0;
5048   if (iaa_icp == 0)
5049     reference = 0.13;
5050   */
5051     
5052   Float_t efficiency = 0.04;
5053   
5054   Float_t centrality = 1;
5055   if (iaa_icp == 0)
5056     centrality = 0.02;
5057   else if (iaa_icp == 1)
5058     centrality = 0.03;
5059   
5060   Float_t ptResolution = 0;
5061   
5062   Float_t integrationWindow = 0;
5063   if (awaySide == 1)
5064     integrationWindow = 0.03;
5065   
5066   Float_t corrections = 1;
5067   if (iaa_icp == 0)
5068     corrections = 0.02;
5069   else if (iaa_icp == 1)
5070     corrections = 0.01;
5071   
5072   Float_t twoTrack = 0.01;
5073   
5074   Float_t total = TMath::Sqrt(baseline * baseline + efficiency * efficiency + centrality * centrality + ptResolution * ptResolution + integrationWindow * integrationWindow + corrections * corrections + twoTrack * twoTrack);
5075   
5076   Printf("%f %f %f %f %f %f %f --> Total syst: %f", baseline, efficiency, centrality, ptResolution, integrationWindow, corrections, twoTrack, total);
5077   
5078   systUnc = (TGraphErrors*) graph->Clone();
5079   for (Int_t i=0; i<systUnc->GetN(); i++)
5080   {
5081     systUnc->GetEY()[i] = systUnc->GetY()[i] * total;
5082     systUnc->GetEX()[i] = 0;
5083     Printf("pt = %.2f  y = %.2f +- %.2f (stat.) +- %.2f (syst.)", graph->GetX()[i] - shift, graph->GetY()[i], graph->GetEY()[i], systUnc->GetEY()[i]);
5084   }
5085     
5086   //systUnc->Print();
5087   
5088   systUnc->SetLineColor(kGray + 1);
5089   systUnc->SetLineWidth(4);
5090   
5091   systUnc->Draw("PSAME e2");
5092     
5093   return systUnc;
5094 }
5095
5096 void IAA(const char* fileName, Int_t iaa, const char* fileNameEtaGap = 0)
5097 {
5098   // iaa
5099   // 0 = IAA LHC
5100   // 1 = ICP
5101   // 2 = IAA RHIC
5102   // 3 = IAA LHC with theory
5103   
5104   Bool_t showTheory = 0;
5105   Bool_t showSTAR = 0;
5106
5107   if (iaa == 3)
5108   {
5109     showTheory = kTRUE;
5110     iaa = 0;
5111   }
5112   
5113   if (iaa == 4)
5114   {
5115     showSTAR = kTRUE;
5116     iaa = 0;
5117   }
5118   
5119   if (kPythiaScalingFactor != 1)
5120     Printf("Using reference data scaling factor: %f", kPythiaScalingFactor);
5121
5122   style();
5123   
5124   Int_t j = 1;
5125   Int_t caseId[] = { 18, 23 };
5126
5127   c = new TCanvas((iaa != 1) ? ((iaa == 0) ? "iaa" : "iaarhic") : "icp", (iaa != 1) ? ((iaa == 0) ? "iaa" : "iaarhic") : "icp", 900, 450);
5128   c->Range(0, 0, 1, 1);
5129
5130   TPad* pad1 = new TPad(Form("%s_2", fileName), "", 0, 0, 0.5, 1);
5131   pad1->Draw();
5132
5133   TPad* pad2 = new TPad(Form("%s_1", fileName), "", 0.5, 0, 1, 1);
5134   pad2->Draw();
5135   
5136   pad1->cd();
5137   gPad->SetRightMargin(0);
5138   gPad->SetTopMargin(0.05);
5139   gPad->SetLeftMargin(0.13);
5140   //gPad->SetGridx();
5141 //   gPad->SetGridy();
5142   
5143   pad2->cd();
5144   gPad->SetLeftMargin(0);
5145   gPad->SetTopMargin(0.05);
5146   gPad->SetRightMargin(0.13);
5147   //gPad->SetGridx();
5148 //   gPad->SetGridy();
5149   
5150   pad1->cd();
5151 //   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);
5152   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);
5153   dummy->SetStats(0);
5154 //   dummy->GetYaxis()->SetTitleOffset(1.3);
5155   dummy->GetXaxis()->SetTitleOffset(1.1);
5156   currentDummy = dummy->DrawCopy();
5157   
5158   gStyle->SetTextAlign(13);
5159   
5160   latex = new TLatex(0.17, 0.90, "Near-side_{ }");
5161   latex->SetTextSize(0.04);
5162   latex->SetNDC();
5163   latex->Draw();
5164   
5165 //   if (iaa != 1)
5166 //   {
5167 //     box = new TBox(2, 0.87, 2.5, 1.13);
5168 //     box->SetFillColor(kGray + 1);
5169 //     box->SetLineColor(kGray + 1);
5170 //     box->Draw();
5171 //   
5172 //     box2 = new TBox(2, 0.87 * 1.5, 2.5, 1.13 * 1.5);
5173 //     box2->SetFillColor(kGray + 1);
5174 //     box2->SetLineColor(kGray + 1);
5175 //     box2->Draw();
5176 //   }
5177   
5178   pad2->cd();
5179   currentDummy = dummy->DrawCopy();
5180   
5181 /*  if (iaa != 1)
5182     box->Draw();*/
5183   
5184   latex = new TLatex(0.05, 0.90, "Away-side");
5185   latex->SetTextSize(0.04);
5186   latex->SetNDC();
5187   latex->Draw();
5188   
5189   legend = new TLegend(0.27, (showTheory) ? 0.60 : 0.62, (iaa != 2 && !showSTAR) ? 0.63 : 0.95, 0.77);
5190   legend->SetFillColor(0);
5191   legend->SetBorderSize(0);
5192   legend->SetTextSize((iaa != 2) ? 0.04 : 0.035);
5193   
5194   for (Int_t i=0; i<2; i++)
5195   {
5196     nearSideCentral    = GetRatio(fileName, (iaa != 2) ? 0 : 1, (iaa != 1) ? 3 : 2, j, caseId[i], 0);
5197     if (iaa == 0)
5198       nearSidePeripheral = GetRatio(fileName, 2, 3, j, caseId[i], 0);
5199     awaySideCentral    = GetRatio(fileName, (iaa != 2) ? 0 : 1, (iaa != 1) ? 3 : 2, j, caseId[i], 1);
5200     if (iaa == 0)
5201       awaySidePeripheral = GetRatio(fileName, 2, 3, j, caseId[i], 1);
5202     
5203     RemovePointsBelowX(nearSideCentral, 3);
5204     RemovePointsBelowX(awaySideCentral, 3);
5205     RemovePointsAboveX(nearSideCentral, 10);
5206     RemovePointsAboveX(awaySideCentral, 10);
5207     
5208     RemoveXErrors(nearSideCentral); RemoveXErrors(awaySideCentral);
5209     
5210     if (iaa == 0)
5211     {
5212       RemovePointsBelowX(nearSidePeripheral, 3);
5213       RemovePointsBelowX(awaySidePeripheral, 3);
5214       RemovePointsAboveX(nearSidePeripheral, 10);
5215       RemovePointsAboveX(awaySidePeripheral, 10);
5216       ShiftPoints(nearSidePeripheral, 0.2);
5217       ShiftPoints(awaySidePeripheral, 0.2);
5218       RemoveXErrors(nearSidePeripheral); RemoveXErrors(awaySidePeripheral);
5219     }
5220     
5221     nearSideCentral->SetMarkerStyle(21);
5222     nearSideCentral->SetLineColor(1);
5223     nearSideCentral->SetMarkerColor(1);
5224             
5225     awaySideCentral->SetMarkerStyle(21);
5226     awaySideCentral->SetLineColor(1);
5227     awaySideCentral->SetMarkerColor(1);
5228     
5229     if (showTheory)
5230     {
5231       nearSideCentral->SetLineColor(2);
5232       nearSideCentral->SetMarkerColor(2);
5233       awaySideCentral->SetLineColor(2);
5234       awaySideCentral->SetMarkerColor(2);
5235     }
5236     
5237     if (iaa == 0)
5238     {
5239       nearSidePeripheral->SetMarkerStyle(22);
5240       nearSidePeripheral->SetLineColor(2);
5241       nearSidePeripheral->SetMarkerColor(2);
5242       
5243       awaySidePeripheral->SetMarkerStyle(22);
5244       awaySidePeripheral->SetLineColor(2);
5245       awaySidePeripheral->SetMarkerColor(2);
5246     }
5247     
5248     if (i == 0)
5249     {
5250 //       TString denominatorStr("Pythia");
5251       TString denominatorStr("pp");
5252       if (iaa == 0)
5253       {
5254         legend->AddEntry(nearSideCentral, Form("%s0-5% / %s", (showSTAR) ? "ALICE Pb-Pb 2.76 TeV " : "", denominatorStr.Data()), "P");
5255         if (!showTheory)
5256           legend->AddEntry(nearSidePeripheral, Form("%s60-90% / %s", (showSTAR) ? "ALICE Pb-Pb 2.76 TeV " : "", denominatorStr.Data()), "P");
5257       }
5258       else if (iaa == 2)
5259       {
5260 //         legend->AddEntry(nearSideCentral, Form("0-20% / %s", denominatorStr.Data()), "P");
5261         legend->AddEntry(nearSideCentral, Form("ALICE 8 GeV/#font[12]{c} < p_{T,trig} < 15 GeV/#font[12]{c}", denominatorStr.Data()), "P");
5262       }
5263     }
5264     
5265     
5266     const char* style = "PSAME";
5267     if (i == 1)
5268       style = "LSAMEX";
5269     
5270     awaySideCentral->Print();
5271     
5272     pad1->cd();
5273     if (i == 0)
5274       DrawSystUnc(nearSideCentral, (iaa == 1), 0, iaa, kTRUE);
5275     nearSideCentral->DrawClone(style);
5276     if (iaa == 0 && !showTheory)
5277     {
5278       if (i == 0)
5279         DrawSystUnc(nearSidePeripheral, (iaa == 1), 0, iaa, kFALSE);
5280       nearSidePeripheral->DrawClone(style);        
5281     }
5282     
5283     pad2->cd();
5284     if (i == 0)
5285       DrawSystUnc(awaySideCentral, (iaa == 1), 1, iaa, kTRUE);
5286     awaySideCentral->DrawClone(style);
5287     if (iaa == 0 && !showTheory)
5288     {
5289       if (i == 0)
5290         DrawSystUnc(awaySidePeripheral, (iaa == 1), 1, iaa, kFALSE);
5291       awaySidePeripheral->DrawClone(style);        
5292     }
5293   }
5294   
5295   if (fileNameEtaGap)
5296   {
5297     pad1->cd();
5298     
5299     nearSideEtaGapCentral = GetRatio(fileNameEtaGap, (iaa != 2) ? 0 : 1, (iaa != 1) ? 3 : 2, j, caseId[0], 0);
5300     RemovePointsBelowX(nearSideEtaGapCentral, 3);
5301     RemovePointsAboveX(nearSideEtaGapCentral, 10);
5302     RemoveXErrors(nearSideEtaGapCentral); 
5303     nearSideEtaGapCentral->SetMarkerStyle(25);
5304     nearSideEtaGapCentral->SetLineColor(1);
5305     nearSideEtaGapCentral->SetMarkerColor(1);
5306     nearSideEtaGapCentral->Draw("PSAME");
5307
5308     if (iaa != 1)
5309     {
5310       nearSideEtaGapPeripheral = GetRatio(fileNameEtaGap, 2, 3, j, caseId[0], 0);
5311       RemovePointsBelowX(nearSideEtaGapPeripheral, 3);
5312       RemovePointsAboveX(nearSideEtaGapPeripheral, 10);
5313       RemoveXErrors(nearSideEtaGapPeripheral); 
5314       ShiftPoints(nearSideEtaGapPeripheral, 0.2);
5315       nearSideEtaGapPeripheral->SetMarkerStyle(26);
5316       nearSideEtaGapPeripheral->SetLineColor(2);
5317       nearSideEtaGapPeripheral->SetMarkerColor(2);
5318       nearSideEtaGapPeripheral->Draw("PSAME");
5319     }
5320   }
5321   
5322   if (iaa == 2)
5323   {
5324     // IAA, RHIC, PHENIX
5325     // systematic uncertainty stored in graph with _sys appended
5326     TFile::Open("rhic/pi0h_graphs.root");
5327     
5328     legend2 = new TLegend(0.5, 0.16, 0.96, 0.27);
5329     legend2->SetFillColor(0);
5330     
5331     for (Int_t ptTrigBin=2; ptTrigBin<4; ptTrigBin++)
5332     {
5333       Bool_t central = kTRUE;
5334       for (Int_t i=0; i<3; i+=2)
5335       {
5336         // gIAA_<ptTrigBin>_<centBin>_<angularRegionBin>
5337         rhic_iaa = (TGraphErrors*) gFile->Get(Form("gIAA_%d_%d_%d", ptTrigBin, (central) ? 0 : 1, i));
5338         rhic_iaa_sys = (TGraphErrors*) gFile->Get(Form("gIAA_%d_%d_%d_sys", ptTrigBin, (central) ? 0 : 1, i));
5339     
5340         rhic_iaa->SetMarkerStyle((ptTrigBin == 2) ? 20 : 33);
5341         rhic_iaa->SetMarkerColor(2);
5342         rhic_iaa->SetLineColor(2);
5343         rhic_iaa_sys->SetLineColor(2);
5344         rhic_iaa_sys->SetMarkerColor(2);
5345         
5346         RemovePointsBelowX(rhic_iaa, 2);
5347         RemovePointsBelowX(rhic_iaa_sys, 2);
5348         
5349         Printf("RHIC:");
5350         rhic_iaa->Print();
5351         rhic_iaa_sys->Print();
5352         
5353         ShiftPoints(rhic_iaa, -0.05 + 0.05 * (ptTrigBin*2-4));
5354         ShiftPoints(rhic_iaa_sys, -0.05 + 0.05 * (ptTrigBin*2-4));
5355         
5356         if (i == 0)
5357           pad1->cd();
5358         else if (i == 2)
5359           pad2->cd();
5360         rhic_iaa->Draw("PSAME");
5361         rhic_iaa_sys->Draw("PSAME");
5362         
5363         if (i == 0)
5364           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");
5365 //           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");
5366       }
5367     }
5368     
5369 //     pad1->cd();
5370 //     legend2->Draw();
5371   }
5372
5373   if (iaa == 0 && showSTAR)
5374   {
5375     for (Int_t i=0; i<2; i++)
5376     {
5377       const char* centralityStr = "05";
5378       if (i == 1)
5379         centralityStr = "4080";
5380       
5381       // IAA, RHIC, STAR
5382       // systematic uncertainty stored in graph with _sys appended
5383       nearSide = ReadHepdata(Form("rhic/star_iaa_%s_near.txt", centralityStr));
5384       awaySide = ReadHepdata(Form("rhic/star_iaa_%s_away.txt", centralityStr));
5385       
5386       nearSide->SetMarkerStyle(20 + i * 13);
5387       nearSide->SetMarkerColor(4);
5388       nearSide->SetLineColor(4);
5389       
5390       awaySide->SetMarkerStyle(20 + i * 13);
5391       awaySide->SetMarkerColor(4);
5392       awaySide->SetLineColor(4);
5393
5394       ShiftPoints(nearSide, -0.1 + 0.2 * i);
5395       ShiftPoints(awaySide, -0.1 + 0.2 * i);
5396           
5397       pad1->cd();
5398       nearSide->Draw("PSAME");
5399       pad2->cd();
5400       awaySide->Draw("PSAME");
5401         
5402       legend->AddEntry(nearSide, Form("STAR Au-Au 0.2 TeV %s / dAu", (i == 0) ? "0-5%" : "40-80%"), "P");
5403     }
5404   }
5405
5406   // Theory predictions
5407   if (showTheory && iaa == 0)
5408   {
5409     const char* theoryList[] = { "AdS", "ASW", "YaJEM", "YaJEM-D", "XinNian" };
5410     Int_t nTheory = 5;
5411     Int_t markers[] = { 27, 28, 29, 30, 34 };
5412     
5413     for (Int_t i=0; i<nTheory; i++)
5414     {
5415       nearSide = ReadHepdata(Form("theory/IAA_near_%s.dat", theoryList[i]));
5416       awaySide = ReadHepdata(Form("theory/IAA_away_%s.dat", theoryList[i]));
5417       
5418       nearSide->SetMarkerStyle(markers[i]);
5419       awaySide->SetMarkerStyle(markers[i]);
5420       
5421       RemovePointsBelowX(nearSide, 3);
5422       RemovePointsBelowX(awaySide, 3);
5423       
5424       Float_t shiftBy = (i % 2 == 0) ? -0.2 : 0.2;
5425       ShiftPoints(nearSide, shiftBy);
5426       ShiftPoints(awaySide, shiftBy);
5427       
5428       pad1->cd();
5429       nearSide->Draw("PSAME");
5430       
5431       pad2->cd();
5432       awaySide->Draw("PSAME");
5433       
5434       if (i == 0)
5435           theoryList[i] = "AdS/CFT";
5436       if (i == 4)
5437           theoryList[i] = "X-N Wang";
5438       legend->AddEntry(nearSide, theoryList[i], "P");
5439     }
5440   }
5441   
5442   for (Int_t i=0; i<2; i++)
5443   {
5444     if (i == 0)
5445       pad1->cd();
5446     else
5447       pad2->cd();
5448       
5449     Float_t xC = 0.05;
5450     if (i == 0)
5451       xC = 0.17;
5452
5453     if (iaa == 2)
5454       latex = new TLatex(xC, 0.84, "0-20% / pp");
5455     else
5456       latex = new TLatex(0.35+xC, 0.9, "8 GeV/#font[12]{c} < p_{T,trig} < 15 GeV/#font[12]{c}");
5457     latex->SetTextSize(0.04);
5458     latex->SetNDC();
5459     if (i == 0)
5460       latex->Draw();
5461     
5462     line = new TLine(1.5, 1, 10.5, 1);
5463     line->SetLineStyle(2);
5464     line->Draw();
5465   
5466     if (iaa == 1)
5467     {
5468       latex = new TLatex(xC, 0.84, "0-5% / 60-90%");
5469       latex->SetTextSize(0.04);
5470       latex->SetNDC();
5471       latex->Draw();
5472     }
5473   
5474     latex = new TLatex(0.65+xC, 0.90, "ALICE");
5475 //     latex = new TLatex(0.5+xC, 0.90, "-- work in progress --");
5476     latex->SetTextSize(0.04);
5477     latex->SetNDC();
5478     if (i == 1)
5479       latex->Draw();
5480     
5481     latex = new TLatex(0.35+xC, 0.84, "p_{T,assoc} < p_{T,trig}");
5482     latex->SetTextSize(0.04);
5483     latex->SetNDC();
5484     if (i == 0)
5485       latex->Draw();
5486     
5487     if (iaa == 1 || iaa == 0)
5488     {
5489       if (iaa == 0 && showSTAR)
5490         latex = new TLatex(0.3+xC, 0.90, "|#eta| < 1.0");
5491       else
5492         latex = new TLatex(xC + 0.65, 0.20, "|#eta| < 1.0");
5493       latex->SetTextSize(0.04);
5494       latex->SetNDC();
5495       if (i == 0)
5496         latex->Draw();
5497     }
5498     
5499     if (iaa == 1 || (iaa == 0 && !showSTAR))
5500     {
5501       latex = new TLatex(0.5+xC, 0.72, "Pb-Pb 2.76 TeV");
5502       latex->SetTextSize(0.04);
5503       latex->SetNDC();
5504 //       latex->Draw();
5505     }
5506     
5507     if (iaa == 2)
5508     {
5509       if (i == 0)
5510         latex = new TLatex(0.5, 0.24, "ALICE: Pb-Pb 2.76 TeV |#eta| < 1.0");
5511       else
5512         latex = new TLatex(xC, 0.6, "ALICE: Pb-Pb 2.76 TeV |#eta| < 1.0");
5513       latex->SetTextSize(0.035);
5514       latex->SetNDC();
5515       latex->Draw();
5516       
5517       if (i == 0)
5518         latex = new TLatex(0.5, 0.18, "PHENIX: Au-Au 0.2 TeV |#eta| < 0.35");
5519       else
5520         latex = new TLatex(xC, 0.54, "PHENIX: Au-Au 0.2 TeV |#eta| < 0.35");
5521       latex->SetTextSize(0.035);
5522       latex->SetNDC();
5523       latex->Draw();
5524     }
5525     
5526     if (showTheory && iaa == 0 && i == 1)
5527       latex = new TLatex(xC, 0.18, "Points: flat pedestal");
5528     else
5529       latex = new TLatex(xC + 0.5 * i, 0.26, "Points: flat pedestal");
5530     latex->SetTextSize(0.04);
5531     latex->SetNDC();
5532     if (i == 0)
5533       latex->Draw();
5534   
5535     latex = new TLatex(xC + 0.5 * i, 0.20, "Line: v_{2} subtracted");
5536     latex->SetTextSize(0.04);
5537     latex->SetNDC();
5538     if (i == 0)
5539       latex->Draw();
5540     
5541     if (iaa != 1 && i == 1)
5542     {
5543       legendClone = (TLegend*) legend->DrawClone();
5544       if (showTheory && iaa == 0 && i == 0)
5545         legendClone->GetListOfPrimitives()->RemoveLast();
5546 //       else
5547 //      legendClone->SetY1(legendClone->GetY1()-0.05);
5548         
5549       legend->SetX1(legend->GetX1()-0.12);
5550       legend->SetX2(legend->GetX2()-0.12);
5551     }
5552
5553 /*    if (i == 0 && iaa != 2)
5554       DrawALICELogo(0.83,0.15,0.98,0.30);
5555     else
5556       DrawALICELogo(0.62 + xC,0.48,0.77 + xC,0.63);*/
5557   }
5558   
5559   c->SaveAs(Form("%s.eps", c->GetTitle()));
5560   c->SaveAs(Form("%s.png", c->GetTitle()));
5561 }
5562
5563 void IAAPaper(const char* fileName, Int_t iaa, const char* fileNameEtaGap = 0)
5564 {
5565   // iaa
5566   // 0 = IAA LHC
5567   // 1 = ICP
5568   
5569   Bool_t showTheory = 0;
5570   Bool_t showSTAR = 0;
5571
5572   if (iaa == 3)
5573   {
5574     showTheory = kTRUE;
5575     iaa = 0;
5576   }
5577   
5578   if (iaa == 4)
5579   {
5580     showSTAR = kTRUE;
5581     iaa = 0;
5582   }
5583   
5584   if (kPythiaScalingFactor != 1)
5585     Printf("Using reference data scaling factor: %f", kPythiaScalingFactor);
5586
5587   style();
5588   
5589   Int_t j = 1;
5590   Int_t caseId[] = { 18, 23 };
5591
5592   c = new TCanvas((iaa != 1) ? ((iaa == 0) ? "iaa" : "iaarhic") : "icp", (iaa != 1) ? ((iaa == 0) ? "iaa" : "iaarhic") : "icp", 900, 450);
5593   c->Range(0, 0, 1, 1);
5594
5595   TPad* pad1 = new TPad(Form("%s_2", fileName), "", 0, 0, 0.5, 1);
5596   pad1->Draw();
5597
5598   TPad* pad2 = new TPad(Form("%s_1", fileName), "", 0.5, 0, 1, 1);
5599   pad2->Draw();
5600   
5601   pad1->cd();
5602   gPad->SetRightMargin(0);
5603   gPad->SetTopMargin(0.05);
5604   gPad->SetLeftMargin(0.13);
5605   //gPad->SetGridx();
5606 //   gPad->SetGridy();
5607   
5608   pad2->cd();
5609   gPad->SetLeftMargin(0);
5610   gPad->SetTopMargin(0.05);
5611   gPad->SetRightMargin(0.13);
5612   //gPad->SetGridx();
5613 //   gPad->SetGridy();
5614   
5615   pad1->cd();
5616 //   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);
5617   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);
5618   dummy->SetStats(0);
5619 //   dummy->GetYaxis()->SetTitleOffset(1.3);
5620   dummy->GetXaxis()->SetTitleOffset(1.1);
5621   currentDummy = dummy->DrawCopy();
5622   
5623   gStyle->SetTextAlign(13);
5624   
5625   latex = new TLatex(0.17, 0.90, "Near-side_{ }");
5626   latex->SetTextSize(0.04);
5627   latex->SetNDC();
5628   latex->Draw();
5629   
5630   latex = new TLatex(0.17, /*(iaa == 1) ? 0.78 :*/ 0.84, "#sqrt{#font[12]{s}_{NN}} = 2.76 TeV");
5631   latex->SetTextSize(0.04);
5632   latex->SetNDC();
5633   latex->Draw();
5634
5635   latex = new TLatex(0.17, 0.2, (iaa == 1) ? "b)" : "a)");
5636   latex->SetTextSize(0.04);
5637   latex->SetNDC();
5638   latex->Draw();
5639   
5640 //   if (iaa != 1)
5641 //   {
5642 //     box = new TBox(2, 0.87, 2.5, 1.13);
5643 //     box->SetFillColor(kGray + 1);
5644 //     box->SetLineColor(kGray + 1);
5645 //     box->Draw();
5646 //   
5647 //     box2 = new TBox(2, 0.87 * 1.5, 2.5, 1.13 * 1.5);
5648 //     box2->SetFillColor(kGray + 1);
5649 //     box2->SetLineColor(kGray + 1);
5650 //     box2->Draw();
5651 //   }
5652   
5653   pad2->cd();
5654   currentDummy = dummy->DrawCopy();
5655   
5656 /*  if (iaa != 1)
5657     box->Draw();*/
5658   
5659   latex = new TLatex(0.05, 0.90, "Away-side");
5660   latex->SetTextSize(0.04);
5661   latex->SetNDC();
5662   latex->Draw();
5663
5664   if (iaa == 1)
5665     legend = new TLegend(0.22, 0.60, 0.67, 0.73);
5666   else
5667     legend = new TLegend(0.12, 0.60, 0.76, 0.79);
5668   legend->SetFillColor(0);
5669   legend->SetBorderSize(0);
5670   legend->SetTextSize((iaa != 2) ? 0.04 : 0.035);
5671   
5672   for (Int_t i=0; i<2; i++)
5673   {
5674     nearSideCentral    = GetRatio(fileName, (iaa != 2) ? 0 : 1, (iaa != 1) ? 3 : 2, j, caseId[i], 0);
5675     if (iaa == 0)
5676       nearSidePeripheral = GetRatio(fileName, 2, 3, j, caseId[i], 0);
5677     awaySideCentral    = GetRatio(fileName, (iaa != 2) ? 0 : 1, (iaa != 1) ? 3 : 2, j, caseId[i], 1);
5678     if (iaa == 0)
5679       awaySidePeripheral = GetRatio(fileName, 2, 3, j, caseId[i], 1);
5680     
5681     RemovePointsBelowX(nearSideCentral, 3);
5682     RemovePointsBelowX(awaySideCentral, 3);
5683     RemovePointsAboveX(nearSideCentral, 10);
5684     RemovePointsAboveX(awaySideCentral, 10);
5685
5686     ShiftPoints(nearSideCentral, -0.05);
5687     ShiftPoints(awaySideCentral, -0.05);
5688
5689     if (i == 1)
5690     {
5691       ShiftPoints(nearSideCentral, -0.2);
5692       ShiftPoints(awaySideCentral, -0.2);
5693       
5694       if (iaa == 0)
5695       {
5696         ShiftPoints(nearSidePeripheral, 0.2);
5697         ShiftPoints(awaySidePeripheral, 0.2);
5698       }
5699     }
5700     
5701     RemoveXErrors(nearSideCentral); RemoveXErrors(awaySideCentral);
5702     
5703     if (iaa == 0)
5704     {
5705       RemovePointsBelowX(nearSidePeripheral, 3);
5706       RemovePointsBelowX(awaySidePeripheral, 3);
5707       RemovePointsAboveX(nearSidePeripheral, 10);
5708       RemovePointsAboveX(awaySidePeripheral, 10);
5709       ShiftPoints(nearSidePeripheral, 0.05);
5710       ShiftPoints(awaySidePeripheral, 0.05);
5711       RemoveXErrors(nearSidePeripheral); RemoveXErrors(awaySidePeripheral);
5712     }
5713     
5714     nearSideCentral->SetMarkerStyle((i == 0) ? 25 : 27);
5715     nearSideCentral->SetLineColor(1);
5716     nearSideCentral->SetMarkerColor(1);
5717             
5718     awaySideCentral->SetMarkerStyle((i == 0) ? 25 : 27);
5719     awaySideCentral->SetLineColor(1);
5720     awaySideCentral->SetMarkerColor(1);
5721     
5722     if (showTheory)
5723     {
5724       nearSideCentral->SetLineColor(2);
5725       nearSideCentral->SetMarkerColor(2);
5726       awaySideCentral->SetLineColor(2);
5727       awaySideCentral->SetMarkerColor(2);
5728     }
5729     
5730     if (iaa == 0)
5731     {
5732       nearSidePeripheral->SetMarkerStyle((i == 0) ? 21 : 33);
5733       nearSidePeripheral->SetLineColor(2);
5734       nearSidePeripheral->SetMarkerColor(2);
5735       
5736       awaySidePeripheral->SetMarkerStyle((i == 0) ? 21 : 33);
5737       awaySidePeripheral->SetLineColor(2);
5738       awaySidePeripheral->SetMarkerColor(2);
5739     }
5740     
5741 //     if (i == 0)
5742     {
5743 //       TString denominatorStr("Pythia");
5744       TString denominatorStr("pp");
5745       if (iaa == 0)
5746       {
5747         legend->SetHeader("0-5% Pb-Pb/pp     60-90% Pb-Pb/pp");
5748         legend->SetNColumns(2);
5749       }
5750       legend->AddEntry(nearSideCentral, (i == 0) ? "Flat bkg" : "#font[12]{v}_{2} bkg", "P");
5751       if (iaa == 0)
5752         legend->AddEntry(nearSidePeripheral, (i == 0) ? "Flat bkg" : "#font[12]{v}_{2} bkg", "P");
5753         
5754 //         legend->AddEntry(nearSideCentral, Form("%s0-5% / %s", (showSTAR) ? "ALICE Pb-Pb 2.76 TeV " : "", denominatorStr.Data()), "P");
5755 //      if (!showTheory)
5756 //        legend->AddEntry(nearSidePeripheral, Form("%s60-90% / %s", (showSTAR) ? "ALICE Pb-Pb 2.76 TeV " : "", denominatorStr.Data()), "P");
5757       if (iaa == 2)
5758       {
5759 //         legend->AddEntry(nearSideCentral, Form("0-20% / %s", denominatorStr.Data()), "P");
5760         legend->AddEntry(nearSideCentral, Form("ALICE 8 GeV/#font[12]{c} < p_{T,trig} < 15 GeV/#font[12]{c}", denominatorStr.Data()), "P");
5761       }
5762     }
5763     
5764     
5765     const char* style = "PSAME";
5766 //     if (i == 1)
5767 //       style = "LSAMEX";
5768     
5769     pad1->cd();
5770 //     if (i == 0)
5771       DrawSystUnc(nearSideCentral, (iaa == 1), 0, iaa, kTRUE, -0.05 - 0.2 * i);
5772     nearSideCentral->DrawClone(style);
5773     if (iaa == 0 && !showTheory)
5774     {
5775 //       if (i == 0)
5776         DrawSystUnc(nearSidePeripheral, (iaa == 1), 0, iaa, kFALSE, 0.05 + ((iaa == 0) ? i * 0.2 : 0));
5777       nearSidePeripheral->DrawClone(style);        
5778     }
5779     
5780     pad2->cd();
5781 //     if (i == 0)
5782       DrawSystUnc(awaySideCentral, (iaa == 1), 1, iaa, kTRUE, -0.05 - 0.2 * i);
5783     awaySideCentral->DrawClone(style);
5784     if (iaa == 0 && !showTheory)
5785     {
5786 //       if (i == 0)
5787         DrawSystUnc(awaySidePeripheral, (iaa == 1), 1, iaa, kFALSE, 0.05 + ((iaa == 0) ? i * 0.2 : 0));
5788       awaySidePeripheral->DrawClone(style);        
5789     }
5790   }
5791   
5792   if (fileNameEtaGap)
5793   {
5794     pad1->cd();
5795     
5796     nearSideEtaGapCentral = GetRatio(fileNameEtaGap, (iaa != 2) ? 0 : 1, (iaa != 1) ? 3 : 2, j, caseId[0], 0);
5797     RemovePointsBelowX(nearSideEtaGapCentral, 3);
5798     RemovePointsAboveX(nearSideEtaGapCentral, 10);
5799     RemoveXErrors(nearSideEtaGapCentral); 
5800     nearSideEtaGapCentral->SetMarkerStyle(24);
5801     nearSideEtaGapCentral->SetLineColor(1);
5802     nearSideEtaGapCentral->SetMarkerColor(1);
5803     ShiftPoints(nearSideEtaGapCentral, -0.45);
5804     DrawSystUnc(nearSideEtaGapCentral, (iaa == 1), 0, iaa, kTRUE, -0.45);
5805     nearSideEtaGapCentral->Draw("PSAME");
5806
5807     legend->AddEntry(nearSideEtaGapCentral, "#font[12]{#eta}-gap", "P");
5808
5809
5810     if (iaa != 1)
5811     {
5812       nearSideEtaGapPeripheral = GetRatio(fileNameEtaGap, 2, 3, j, caseId[0], 0);
5813       RemovePointsBelowX(nearSideEtaGapPeripheral, 3);
5814       RemovePointsAboveX(nearSideEtaGapPeripheral, 10);
5815       RemoveXErrors(nearSideEtaGapPeripheral); 
5816       nearSideEtaGapPeripheral->SetMarkerStyle(20);
5817       nearSideEtaGapPeripheral->SetLineColor(2);
5818       nearSideEtaGapPeripheral->SetMarkerColor(2);
5819       ShiftPoints(nearSideEtaGapPeripheral, 0.45);
5820       DrawSystUnc(nearSideEtaGapPeripheral, (iaa == 1), 0, iaa, kFALSE, 0.45);
5821       nearSideEtaGapPeripheral->Draw("PSAME");
5822
5823       legend->AddEntry(nearSideEtaGapPeripheral, "#font[12]{#eta}-gap", "P");
5824     }
5825   }
5826   
5827   if (0 && iaa == 0)
5828   {
5829     // add pythia line showing gluon filtering
5830     // from Jan Rak, by mail, 22.09.11
5831     // pp CF calculated without any adjustment
5832     // AA CF also no adjustment. Particles (h+-) in acceptance are identified with their parent string parton (status 71)
5833     // and the flavor of parent hard outgoing parton (status 23) which is  the parent of string parton 71 is checked.
5834     // If it is a gluon the  particle is ignored.
5835     
5836     Float_t xVal[] = { 3.5, 4.5, 5.5, 7, 9};
5837     Float_t yVal[] = { 0.779418, 0.794234, 0.82759, 0.856457, 0.880526 };
5838     gluonfiltering = new TGraph(5, xVal, yVal);
5839     pad1->cd();
5840     gluonfiltering->Draw("L");
5841     
5842     legend3 = new TLegend(0.38, 0.15, 0.58, 0.25);
5843     legend3->SetFillColor(0);
5844     legend3->SetBorderSize(0);
5845     legend3->SetTextSize(0.04);
5846     legend3->AddEntry(gluonfiltering, "PYTHIA quark-only fragmentation", "L");
5847     legend3->Draw();
5848   }
5849   
5850   if (iaa == 2)
5851   {
5852     // IAA, RHIC, PHENIX
5853     // systematic uncertainty stored in graph with _sys appended
5854     TFile::Open("rhic/pi0h_graphs.root");
5855     
5856     legend2 = new TLegend(0.5, 0.16, 0.96, 0.27);
5857     legend2->SetFillColor(0);
5858     
5859     for (Int_t ptTrigBin=2; ptTrigBin<4; ptTrigBin++)
5860     {
5861       Bool_t central = kTRUE;
5862       for (Int_t i=0; i<3; i+=2)
5863       {
5864         // gIAA_<ptTrigBin>_<centBin>_<angularRegionBin>
5865         rhic_iaa = (TGraphErrors*) gFile->Get(Form("gIAA_%d_%d_%d", ptTrigBin, (central) ? 0 : 1, i));
5866         rhic_iaa_sys = (TGraphErrors*) gFile->Get(Form("gIAA_%d_%d_%d_sys", ptTrigBin, (central) ? 0 : 1, i));
5867     
5868         rhic_iaa->SetMarkerStyle((ptTrigBin == 2) ? 20 : 33);
5869         rhic_iaa->SetMarkerColor(2);
5870         rhic_iaa->SetLineColor(2);
5871         rhic_iaa_sys->SetLineColor(2);
5872         rhic_iaa_sys->SetMarkerColor(2);
5873         
5874         ShiftPoints(rhic_iaa, -0.05 + 0.05 * (ptTrigBin*2-4));
5875         ShiftPoints(rhic_iaa_sys, -0.05 + 0.05 * (ptTrigBin*2-4));
5876         
5877         if (i == 0)
5878           pad1->cd();
5879         else if (i == 2)
5880           pad2->cd();
5881         rhic_iaa->Draw("PSAME");
5882         rhic_iaa_sys->Draw("PSAME");
5883         
5884         if (i == 0)
5885           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");
5886 //           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");
5887       }
5888     }
5889     
5890 //     pad1->cd();
5891 //     legend2->Draw();
5892   }
5893
5894   if (iaa == 0 && showSTAR)
5895   {
5896     for (Int_t i=0; i<2; i++)
5897     {
5898       const char* centralityStr = "05";
5899       if (i == 1)
5900         centralityStr = "4080";
5901       
5902       // IAA, RHIC, STAR
5903       // systematic uncertainty stored in graph with _sys appended
5904       nearSide = ReadHepdata(Form("rhic/star_iaa_%s_near.txt", centralityStr));
5905       awaySide = ReadHepdata(Form("rhic/star_iaa_%s_away.txt", centralityStr));
5906       
5907       nearSide->SetMarkerStyle(20 + i * 13);
5908       nearSide->SetMarkerColor(4);
5909       nearSide->SetLineColor(4);
5910       
5911       awaySide->SetMarkerStyle(20 + i * 13);
5912       awaySide->SetMarkerColor(4);
5913       awaySide->SetLineColor(4);
5914
5915       ShiftPoints(nearSide, -0.1 + 0.2 * i);
5916       ShiftPoints(awaySide, -0.1 + 0.2 * i);
5917           
5918       pad1->cd();
5919       nearSide->Draw("PSAME");
5920       pad2->cd();
5921       awaySide->Draw("PSAME");
5922         
5923       legend->AddEntry(nearSide, Form("STAR Au-Au 0.2 TeV %s / dAu", (i == 0) ? "0-5%" : "40-80%"), "P");
5924     }
5925   }
5926
5927   // Theory predictions
5928   if (showTheory && iaa == 0)
5929   {
5930     const char* theoryList[] = { "AdS", "ASW", "YaJEM", "YaJEM-D", "XinNian" };
5931     Int_t nTheory = 5;
5932     Int_t markers[] = { 27, 28, 29, 30, 34 };
5933     
5934     for (Int_t i=0; i<nTheory; i++)
5935     {
5936       nearSide = ReadHepdata(Form("theory/IAA_near_%s.dat", theoryList[i]));
5937       awaySide = ReadHepdata(Form("theory/IAA_away_%s.dat", theoryList[i]));
5938       
5939       nearSide->SetMarkerStyle(markers[i]);
5940       awaySide->SetMarkerStyle(markers[i]);
5941       
5942       RemovePointsBelowX(nearSide, 3);
5943       RemovePointsBelowX(awaySide, 3);
5944       
5945       Float_t shiftBy = (i % 2 == 0) ? -0.2 : 0.2;
5946       ShiftPoints(nearSide, shiftBy);
5947       ShiftPoints(awaySide, shiftBy);
5948       
5949       pad1->cd();
5950       nearSide->Draw("PSAME");
5951       
5952       pad2->cd();
5953       awaySide->Draw("PSAME");
5954       
5955       if (i == 0)
5956           theoryList[i] = "AdS/CFT";
5957       if (i == 4)
5958           theoryList[i] = "X-N Wang";
5959       legend->AddEntry(nearSide, theoryList[i], "P");
5960     }
5961   }
5962   
5963   for (Int_t i=0; i<2; i++)
5964   {
5965     if (i == 0)
5966       pad1->cd();
5967     else
5968       pad2->cd();
5969       
5970     Float_t xC = 0.05;
5971     if (i == 0)
5972       xC = 0.17;
5973
5974     if (iaa == 2)
5975       latex = new TLatex(xC, 0.84, "0-20% / pp");
5976     else
5977       latex = new TLatex(0.35+xC, 0.9, "8 GeV/#font[12]{c} < #font[12]{p}_{t,trig} < 15 GeV/#font[12]{c}");
5978     latex->SetTextSize(0.04);
5979     latex->SetNDC();
5980     if (i == 0)
5981       latex->Draw();
5982     
5983     line = new TLine(1.5, 1, 10.5, 1);
5984     line->SetLineStyle(2);
5985     line->Draw();
5986   
5987 //     if (iaa == 1 && i == 0)
5988 //     {
5989 //       latex = new TLatex(xC, 0.84, "0-5% / 60-90%");
5990 //       latex->SetTextSize(0.04);
5991 //       latex->SetNDC();
5992 //       latex->Draw();
5993 //     }
5994   
5995     latex = new TLatex(0.65+xC, 0.90, "ALICE");
5996 //     latex = new TLatex(0.5+xC, 0.90, "-- work in progress --");
5997     latex->SetTextSize(0.04);
5998     latex->SetNDC();
5999     if (i == 1)
6000       latex->Draw();
6001     
6002     latex = new TLatex(0.35+xC, 0.84, "#font[12]{p}_{t,assoc} < #font[12]{p}_{t,trig}");
6003     latex->SetTextSize(0.04);
6004     latex->SetNDC();
6005     if (i == 0)
6006       latex->Draw();
6007     
6008     if (iaa == 1 || iaa == 0)
6009     {
6010       if (iaa == 0 && showSTAR)
6011         latex = new TLatex(0.3+xC, 0.90, "|#font[12]{#eta}| < 1.0");
6012       else
6013         latex = new TLatex(0.82, 0.84, "|#font[12]{#eta}| < 1.0");
6014       latex->SetTextSize(0.04);
6015       latex->SetNDC();
6016       if (i == 0)
6017         latex->Draw();
6018     }
6019     
6020     if (iaa == 1 || (iaa == 0 && !showSTAR))
6021     {
6022       latex = new TLatex(0.5+xC, 0.72, "Pb-Pb 2.76 TeV");
6023       latex->SetTextSize(0.04);
6024       latex->SetNDC();
6025 //       latex->Draw();
6026     }
6027     
6028     if (iaa == 2)
6029     {
6030       if (i == 0)
6031         latex = new TLatex(0.5, 0.24, "ALICE: Pb-Pb 2.76 TeV |#eta| < 1.0");
6032       else
6033         latex = new TLatex(xC, 0.6, "ALICE: Pb-Pb 2.76 TeV |#eta| < 1.0");
6034       latex->SetTextSize(0.035);
6035       latex->SetNDC();
6036       latex->Draw();
6037       
6038       if (i == 0)
6039         latex = new TLatex(0.5, 0.18, "PHENIX: Au-Au 0.2 TeV |#eta| < 0.35");
6040       else
6041         latex = new TLatex(xC, 0.54, "PHENIX: Au-Au 0.2 TeV |#eta| < 0.35");
6042       latex->SetTextSize(0.035);
6043       latex->SetNDC();
6044       latex->Draw();
6045     }
6046     
6047     if (i == 1)
6048     {
6049       legendClone = (TLegend*) legend->DrawClone();
6050       if (showTheory && iaa == 0 && i == 0)
6051         legendClone->GetListOfPrimitives()->RemoveLast();
6052 //       else
6053 //      legendClone->SetY1(legendClone->GetY1()-0.05);
6054         
6055       legend->SetX1(legend->GetX1()-0.12);
6056       legend->SetX2(legend->GetX2()-0.12);
6057     }
6058     
6059     
6060
6061 /*    if (i == 0 && iaa != 2)
6062       DrawALICELogo(0.83,0.15,0.98,0.30);
6063     else
6064       DrawALICELogo(0.62 + xC,0.48,0.77 + xC,0.63);*/
6065   }
6066   
6067   c->SaveAs(Form("%s.eps", c->GetTitle()));
6068   c->SaveAs(Form("%s.png", c->GetTitle()));
6069 }
6070
6071
6072 void DrawALICELogo(Float_t x1, Float_t y1, Float_t x2, Float_t y2, Bool_t debug = kFALSE)
6073 {
6074   DrawALICELogo(kTRUE, x1, y1, x2, y2, debug);
6075 }
6076
6077 void DrawALICELogo(Bool_t prel, Float_t x1, Float_t y1, Float_t x2, Float_t y2, Bool_t debug = kFALSE)
6078 {
6079   // correct for aspect ratio of figure plus aspect ratio of pad (coordinates are NDC!)
6080 //   Printf("%d %f %d %f", gPad->GetCanvas()->GetWindowHeight(), gPad->GetHNDC(), gPad->GetCanvas()->GetWindowWidth(), gPad->GetWNDC());
6081   //x2 = x1 + (y2 - y1) * 0.891 * gPad->GetCanvas()->GetWindowHeight() * gPad->GetHNDC() / (gPad->GetWNDC() * gPad->GetCanvas()->GetWindowWidth());
6082   x2 = x1 + (y2 - y1) * (466. / 523) * gPad->GetWh() * gPad->GetHNDC() / (gPad->GetWNDC() * gPad->GetWw());
6083 //   Printf("%f %f %f %f", x1, x2, y1, y2);
6084   
6085   if (!prel)
6086     DrawLatex((x1+x2)/2, y1, 1, "09.05.12", 0.03)->SetTextAlign(23);
6087   TPad *myPadLogo = new TPad("myPadLogo", "Pad for ALICE Logo", x1, y1, x2, y2);
6088   if (debug)
6089     myPadLogo->SetFillColor(2); // color to first figure out where is the pad then comment !
6090   myPadLogo->SetLeftMargin(0);
6091   myPadLogo->SetTopMargin(0);
6092   myPadLogo->SetRightMargin(0);
6093   myPadLogo->SetBottomMargin(0);
6094   myPadLogo->Draw();
6095   myPadLogo->cd();
6096 //   TASImage *myAliceLogo = new TASImage("~/alice_logo_transparent.png");
6097   TASImage *myAliceLogo = new TASImage((prel) ? "~/alice_logo_preliminary.eps" : "~/alice_logo_performance.eps");
6098   myAliceLogo->Draw();
6099 }
6100
6101 void RemoveXErrors(TGraphErrors* graph)
6102 {
6103         for (Int_t i=0; i<graph->GetN(); i++)
6104                 graph->GetEX()[i] = 0;
6105 }
6106
6107 void RemovePointsBelowX(TGraphErrors* graph, Float_t minX)
6108 {
6109   Int_t i=0;
6110   while (i<graph->GetN())
6111   {
6112     if (graph->GetX()[i] < minX)
6113       graph->RemovePoint(i);
6114     else
6115       i++;
6116   }
6117 }
6118
6119 void RemovePointsAboveX(TGraphErrors* graph, Float_t maxX)
6120 {
6121   Int_t i=0;
6122   while (i<graph->GetN())
6123   {
6124     if (graph->GetX()[i] > maxX)
6125       graph->RemovePoint(i);
6126     else
6127       i++;
6128   }
6129 }
6130
6131 void ShiftPoints(TGraphErrors* graph, Float_t dx)
6132 {
6133   Int_t i=0;
6134   while (i<graph->GetN())
6135   {
6136     graph->GetX()[i] += dx;
6137     i++;
6138   }
6139 }
6140
6141 void DivideGraphs(TGraphErrors* graph1, TGraphErrors* graph2)
6142 {
6143   graph1->Print();
6144   graph2->Print();
6145
6146   for (Int_t bin1 = 0; bin1 < graph1->GetN(); bin1++)
6147   {
6148     Float_t x = graph1->GetX()[bin1];
6149
6150     Int_t bin2 = 0;
6151     for (bin2 = 0; bin2<graph2->GetN(); bin2++)
6152       if (graph2->GetX()[bin2] >= x)
6153         break;
6154
6155     if (bin2 == graph2->GetN())
6156             bin2--;
6157
6158     if (bin2 > 0)
6159       if (TMath::Abs(graph2->GetX()[bin2-1] - x) < TMath::Abs(graph2->GetX()[bin2] - x))
6160         bin2--;
6161
6162     if (graph1->GetY()[bin1] == 0 || graph2->GetY()[bin2] == 0 || bin2 == graph2->GetN())
6163     {
6164       Printf("%d %d removed", bin1, bin2);
6165       graph1->RemovePoint(bin1--);
6166       continue;
6167     }
6168
6169     Float_t graph2Extrapolated = graph2->GetY()[bin2];
6170     if (TMath::Abs(x - graph2->GetX()[bin2]) > 0.0001)
6171     {
6172       Printf("%f %f %d %d not found", x, graph2->GetX()[bin2], bin1, bin2);
6173       graph1->RemovePoint(bin1--);
6174       continue;
6175     }
6176
6177     Float_t value = graph1->GetY()[bin1] / graph2Extrapolated;
6178     Float_t error = value * TMath::Sqrt(TMath::Power(graph1->GetEY()[bin1] / graph1->GetY()[bin1], 2) + TMath::Power(graph2->GetEY()[bin2] / graph2->GetY()[bin2], 2));
6179
6180     graph1->GetY()[bin1] = value;
6181     graph1->GetEY()[bin1] = error;
6182
6183     Printf("%d %d %f %f %f %f", bin1, bin2, x, graph2Extrapolated, value, error);
6184   }
6185 }
6186
6187 Float_t ExtractYields(TH1* hist, Int_t trigId, Int_t centralityId, Float_t ptA, Float_t ptW, Int_t caseId, Double_t normUnc)
6188 {
6189   CreateYieldStructure();
6190
6191   Float_t width = 0.69;
6192 //   Float_t width = 0.5; Printf("WARNING. Using integration width 0.5");
6193 //   Float_t width = 0.85; Printf("WARNING. Using integration width 0.85");
6194   
6195   //new TCanvas; hist->DrawCopy();
6196   
6197   Int_t binBegin = hist->FindBin(-width);
6198   Int_t binEnd = hist->FindBin(width);
6199   Double_t nearSideError = 0;
6200   Float_t nearSideYield = hist->IntegralAndError(binBegin, binEnd, nearSideError);
6201   nearSideYield *= hist->GetXaxis()->GetBinWidth(1);
6202   nearSideError *= hist->GetXaxis()->GetBinWidth(1);
6203
6204   Int_t binBegin = hist->FindBin(TMath::Pi() - width);
6205   Int_t binEnd = hist->FindBin(TMath::Pi() + width);
6206   Double_t awaySideError = 0;
6207   Float_t awaySideYield = hist->IntegralAndError(binBegin, binEnd, awaySideError);
6208   awaySideYield *= hist->GetXaxis()->GetBinWidth(1);
6209   awaySideError *= hist->GetXaxis()->GetBinWidth(1);
6210   
6211   Printf("%d %d %f %d: %f+-%f %f+-%f (%f)", trigId, centralityId, ptA, caseId, nearSideYield, nearSideError, awaySideYield, awaySideError, normUnc);
6212   
6213   FillYield(trigId, centralityId, ptA, ptW, caseId, nearSideYield, TMath::Sqrt(nearSideError * nearSideError + normUnc * normUnc), awaySideYield, TMath::Sqrt(awaySideError * awaySideError + normUnc * normUnc));
6214   
6215   // store normUnc for error propagation later
6216   TGraphErrors** tmp = yields[2][trigId][centralityId];
6217   tmp[caseId]->SetPoint(tmp[caseId]->GetN(), ptA, normUnc);
6218   
6219   return awaySideYield;
6220 }
6221
6222 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)
6223 {
6224   // CINT limitation here
6225   TGraphErrors** tmp = yields[0][trigId][centralityId];
6226   tmp[caseId]->SetPoint(tmp[caseId]->GetN(), ptA, nearSideYield);
6227   tmp[caseId]->SetPointError(tmp[caseId]->GetN()-1, ptW, nearSideError);
6228   //tmp[caseId]->Print();
6229   
6230   tmp = yields[1][trigId][centralityId];
6231   tmp[caseId]->SetPoint(tmp[caseId]->GetN(), ptA, awaySideYield);
6232   tmp[caseId]->SetPointError(tmp[caseId]->GetN()-1, ptW, awaySideError);
6233 }
6234
6235 Double_t hypgeo(Double_t a, Double_t b, Double_t c, Double_t z)
6236 {
6237   // ROOT::Math::hyperg is only defined for |z| < 1
6238   if (z > -1)
6239     return ROOT::Math::hyperg(a, b, c, z);
6240     
6241   // for z < -1 we can use an identity from http://en.wikipedia.org/wiki/Hypergeometric_function
6242   return TMath::Power(1-z, -b) * ROOT::Math::hyperg(c-a, b, c, z / (z-1));
6243 }
6244
6245 Double_t hypgeoder2(Double_t a, Double_t b, Double_t c, Double_t z)
6246 {
6247   // derivate of hypgeo with parameter b: d/db hypgeo
6248   
6249   static TF1* func = 0;
6250   if (!func)
6251     func = new TF1("hypgeoder2_func", "hypgeo([0], x, [1], [2])");
6252   
6253   func->SetParameters(a, c, z);
6254   return func->Derivative(b);
6255 }
6256
6257 void TsallisYieldUncertainty(Double_t n, Double_t q, Double_t beta, TMatrixDSym covMatrix, Int_t offset, Double_t& yield, Double_t& unc)
6258 {
6259   gSystem->Load("libMathMore");
6260
6261   TF1 tsallis("tsallis", "[0] * (1-[2]*(1-[1])*x*x)**(1/(1-[1]))", -0.5 * TMath::Pi(), 1.5 * TMath::Pi());
6262
6263   // 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]
6264   // [0] = n, [1] = q, [2] = beta
6265   TF1 tsallisIntegral("tsallisIntegral",               "[0]*x*hypgeo(0.5, 1/([1]-1), 1.5, -[2]*([1]-1)*x*x)");
6266   TF1 tsallisIntegralDerN("tsallisIntegralDerN",           "x*hypgeo(0.5, 1/([1]-1), 1.5, -[2]*([1]-1)*x*x)");
6267   
6268   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)");
6269   
6270   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]");
6271   
6272   const Float_t width = 0.7;
6273   
6274   TF1* derivates[4];
6275   derivates[0] = new TF1("const", "1");
6276   derivates[1] = &tsallisIntegralDerN;
6277   derivates[2] = &tsallisIntegralDerq;
6278   derivates[3] = &tsallisIntegralDerbeta;
6279   
6280   Printf("%f %f %f", n, q, beta);
6281   
6282   tsallis.SetParameters(n, q, beta);
6283   tsallisIntegral.SetParameters(n, q, beta);
6284   for (Int_t i=1; i<4; i++)
6285     derivates[i]->SetParameters(n, q, beta);
6286   
6287   yield = tsallisIntegral.Eval(width) - tsallisIntegral.Eval(-width);
6288   Double_t yield2 = tsallis.Integral(-width, width);
6289   
6290   unc = 0;
6291   for (Int_t i=0; i<4; i++)
6292     for (Int_t j=0; j<4; j++)
6293     {
6294       Int_t covI = i;
6295       Int_t covJ = j;
6296       if (i > 0)
6297         covI += offset;
6298       if (j > 0)
6299         covJ += offset;
6300         
6301       Double_t der1 = (derivates[i]->Eval(width) - derivates[i]->Eval(-width));
6302       Double_t der2 = (derivates[j]->Eval(width) - derivates[j]->Eval(-width));
6303         
6304       unc += der1 * der2 * covMatrix(covI, covJ);
6305       
6306       Printf("%d %d % .3e % .3e % .3e % .3e", i, j, der1, der2, covMatrix(covI, covJ), unc);
6307     }
6308     
6309   unc = TMath::Sqrt(unc);
6310   
6311   yield /= width * 2;
6312   yield2 /= width * 2;
6313   unc /= width * 2;
6314   
6315   Printf("%f (%f) +- %f", yield, yield2, unc);
6316 }
6317
6318 double NLowestBinAverage(TH1 &h, int N)
6319 {
6320   // Returns mean content of N lowest bins in h.
6321
6322   double avg = 0;
6323   int counter = 0;
6324   std::list<double> content;
6325   std::list<double>::iterator i;
6326
6327   for (int jbin=1; jbin<=h.GetNbinsX(); jbin++) {
6328     content.push_back(h.GetBinContent(jbin));
6329   }
6330   content.sort();
6331
6332   for (i = content.begin(); i != content.end(); ++i) {
6333
6334     if (counter == N)
6335       break;
6336
6337     avg += *i/N;
6338     counter++;
6339   }
6340
6341   if (counter < N)
6342     Warning("NLowestBinAverage()",
6343         "Avg. of %d bins requested, %d used", N, counter);
6344
6345   return avg;
6346
6347
6348 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)
6349 {
6350   // caseOffsets
6351   // 0 same with v2 (14 tsallis for baseline [28/29 tsallis params]; 15 yield from tsallis function)
6352   // [disabled] 1 same/mixed with v2 (15 tsallis for baseline)
6353   // 2 same no v2 (16 tsallis for baseline; 17 yield from tsallis function)
6354   // 4 same no v2 (18 flat fit 1)
6355   // 5 same no v2 (19 flat fit 2)
6356   // 6 same no v2 (20 flat avg over 4)
6357   // 7 same no v2 (21 flat avg over 8)
6358   // 8 same no v2 (22 flat avg over 16)
6359   // 9 same with v2 (23 flat fit 1)
6360   // 10 same with v2 (24 flat fit 2)
6361   // 11 same with v2 (25 flat avg over 4)
6362   // 12 same with v2 (26 flat avg over 8)
6363   // 13 same with v2 (27 flat avg over 16)
6364   
6365   // 30 gaussian fit width
6366
6367   // same stuff for same/mixed
6368   if (0 && caseOffset == 0 && histMixed)
6369   {
6370     TH1* clone = (TH1*) hist->Clone();
6371     clone->Divide(histMixed);
6372     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 1, ptACenter, ptAWidth, kFALSE, 0, vn);
6373   }
6374   
6375   // same for other baseline subtractions
6376   if (caseOffset == 0)
6377   {
6378     file = TFile::Open("dphi_corr.root", "UPDATE");
6379     hist->Write();
6380     file->Close();
6381     
6382     TH1* clone = (TH1*) hist->Clone();
6383     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 2, ptACenter, ptAWidth, kTRUE, 0, vn);
6384   
6385     clone = (TH1*) hist->Clone();
6386     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 4, ptACenter, ptAWidth, kTRUE, 1, vn);
6387   
6388     clone = (TH1*) hist->Clone();
6389     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 5, ptACenter, ptAWidth, kTRUE, 2, vn);
6390     
6391     clone = (TH1*) hist->Clone();
6392     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 6, ptACenter, ptAWidth, kTRUE, 3, vn);
6393     
6394     clone = (TH1*) hist->Clone();
6395     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 7, ptACenter, ptAWidth, kTRUE, 4, vn);
6396     
6397     clone = (TH1*) hist->Clone();
6398     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 8, ptACenter, ptAWidth, kTRUE, 5, vn);
6399     
6400     clone = (TH1*) hist->Clone();
6401     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 9, ptACenter, ptAWidth, kFALSE, 1, vn);
6402   
6403     clone = (TH1*) hist->Clone();
6404     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 10, ptACenter, ptAWidth, kFALSE, 2, vn);
6405   
6406     clone = (TH1*) hist->Clone();
6407     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 11, ptACenter, ptAWidth, kFALSE, 3, vn);
6408   
6409     clone = (TH1*) hist->Clone();
6410     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 12, ptACenter, ptAWidth, kFALSE, 4, vn);
6411   
6412     clone = (TH1*) hist->Clone();
6413     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 13, ptACenter, ptAWidth, kFALSE, 5, vn);
6414   }
6415
6416   Float_t awaySideYield = ExtractYields(hist, trigId, centralityId, ptACenter, ptAWidth, 0 + caseOffset, 0);
6417   
6418   if (flatBaseLine)
6419   {
6420     v2 = 0;
6421     vn = 0;
6422   }
6423     
6424 /*    Float_t v2Trig  = flowGraph->Eval(ptT);
6425     Float_t v2Assoc = flowGraph->Eval(ptA);
6426     Float_t v2 = v2Trig * v2Assoc;
6427     Printf("%f %f: %.2f %.2f --> %.4f", ptT, ptA, v2Trig, v2Assoc, v2);*/
6428   
6429   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());
6430
6431   // find minimum
6432   if (0)
6433   {
6434     Float_t minBin = hist->FindBin(0.6);
6435     for (Int_t bin=hist->FindBin(0.6); bin<=hist->FindBin(1.8); bin++)
6436       if (hist->GetBinContent(bin) < hist->GetBinContent(minBin))
6437         minBin = bin;
6438             
6439     Float_t norm = hist->GetBinContent(minBin) / (1 + 2 * v2 * cos(2 * hist->GetBinCenter(minBin)));
6440     Double_t normUnc = 0;
6441   }
6442   else
6443   {
6444     if (baseLineDetermination == 0)
6445     {
6446       return;
6447       /*
6448       if (centralityId == 0)
6449         hist->Fit("pol0", "0", "", 0.8., 1.2);
6450       else
6451         hist->Fit("pol0", "0", "", 1.2, 1.6);
6452       */
6453       //tsallis = new TF1("tsallis", "(1-[1]*(1-[0])*x*x)**(1/(1-[0]))", 0, 10)
6454       // (1-b(1-q)x*x)**(1/(1-q))
6455       
6456       // combination of two tsallis functions
6457       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());
6458       //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());
6459       // 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
6460       total->SetParLimits(0, 0, 10000);
6461       total->SetParLimits(1, 0, 10000);
6462       total->SetParLimits(4, 0, 10000);
6463       
6464       total->SetParLimits(2, 1.0000001, 5);
6465       total->SetParLimits(5, 1.0000001, 5);
6466       
6467       total->SetParLimits(3, 0.1, 1000);
6468       total->SetParLimits(6, 0.1, 1000);
6469       
6470       total->SetParameters(1, 1, 1.5, 3, 1, 1.5, 1.1);
6471       
6472       // limit q>1
6473       hist->Fit(total, "0RI");
6474       fitResult = hist->Fit(total, "0RSI");
6475       
6476       if (0 && fitResult->CovMatrixStatus() > 0)
6477       {
6478         TMatrixDSym cov(fitResult->GetCovarianceMatrix());
6479         cov.Print();
6480         
6481         Double_t nearSideYield, nearSideError;
6482         TsallisYieldUncertainty(total->GetParameter(1), total->GetParameter(2), total->GetParameter(3), cov, 0, nearSideYield, nearSideError);
6483         
6484         Double_t awaySideYield2, awaySideError;
6485         TsallisYieldUncertainty(total->GetParameter(4), total->GetParameter(5), total->GetParameter(6), cov, 3, awaySideYield2, awaySideError);
6486         
6487         FillYield(trigId, centralityId, ptACenter, ptAWidth, 14 + caseOffset + 1, nearSideYield, nearSideError, awaySideYield2, awaySideError);
6488         
6489         Printf("Chi2 %f / ndf %d = %f", total->GetChisquare(), total->GetNDF(), (total->GetNDF() > 0) ? total->GetChisquare() / total->GetNDF() : -1);
6490         
6491         total->SetLineColor(hist->GetLineColor());
6492         total->SetLineWidth(1);
6493         if (caseOffset == 2)
6494         {
6495           if (0)
6496             total->DrawCopy("SAME");
6497           //total->SetParameter(5, total->GetParameter(5) - TMath::Sqrt(cov[5][5]));
6498           //total->DrawCopy("SAME");
6499           //total->SetParameter(5, total->GetParameter(5) + 2 * TMath::Sqrt(cov[5][5]));
6500           //Printf("%f", total->Integral(-0.7,0.7));
6501           //total->DrawCopy("SAME");
6502         }
6503         
6504         if (caseOffset == 0)
6505         {
6506           // store fit parameters
6507           
6508           // q
6509           FillYield(trigId, centralityId, ptACenter, ptAWidth, 28, total->GetParameter(2), total->GetParError(2), total->GetParameter(5), total->GetParError(5));
6510           // beta
6511           FillYield(trigId, centralityId, ptACenter, ptAWidth, 29, total->GetParameter(3), total->GetParError(3), total->GetParameter(6), total->GetParError(6));
6512           
6513           if (0)
6514           {
6515             // two Gauss fits
6516             gausFit = new TF1("gausFit", "[0] + gaus(1) + gaus(4)", -0.5 * TMath::Pi(), 1.5 * TMath::Pi());
6517             gausFit->SetParameters(1, 1, 0, 1, 1, TMath::Pi(), 0);
6518             gausFit->SetParLimits(0, 0, 10000);
6519             gausFit->SetParLimits(1, 0, 10000);
6520             gausFit->FixParameter(2, 0);
6521             gausFit->SetParLimits(3, 0.01, 10);
6522             gausFit->SetParLimits(4, 0, 10000);
6523             gausFit->FixParameter(5, TMath::Pi());
6524             gausFit->SetParLimits(6, 0.01, 10);
6525             
6526             hist->Fit(gausFit, "0RI");
6527             gausFit->SetLineWidth(1);
6528             gausFit->DrawCopy("SAME");
6529           
6530             FillYield(trigId, centralityId, ptACenter, ptAWidth, 30, gausFit->GetParameter(3), total->GetParError(3), total->GetParameter(6), total->GetParError(6));
6531           }
6532         }
6533         
6534         if (0 && cov[0][0] > 0)
6535         {
6536           for (Int_t i=0; i<cov.GetNcols(); i++)
6537             for (Int_t j=0; j<cov.GetNrows(); j++)
6538               cov[j][i] /= TMath::Sqrt(cov[i][i]) * TMath::Sqrt(cov[j][j]);
6539           cov.Print();
6540         }
6541       }
6542       
6543       func = total;
6544       Float_t norm = func->GetParameter(0) / (1 - 2 * v2);
6545       Double_t normUnc = func->GetParError(0) / (1 - 2 * v2);
6546       //return;
6547     }
6548     else if (baseLineDetermination <= 2)
6549     {
6550       Float_t values[3];
6551       Float_t errors[3];
6552       
6553       if (baseLineDetermination == 1)
6554       {
6555         Float_t regionBegin[3] = { -TMath::Pi() / 2,        TMath::Pi() / 2 - 0.4, 1.5 * TMath::Pi() - 0.4 };
6556         Float_t regionEnd[3] =   { -TMath::Pi() / 2 + 0.4,  TMath::Pi() / 2 + 0.4, 1.5 * TMath::Pi() };
6557       }
6558       else if (baseLineDetermination == 2)
6559       {
6560         Float_t regionBegin[3] = { -TMath::Pi() / 2,              TMath::Pi() / 2 - 0.4 - 0.2, 1.5 * TMath::Pi() - 0.4 - 0.2};
6561         Float_t regionEnd[3] =   { -TMath::Pi() / 2 + 0.4 - 0.2,  TMath::Pi() / 2 + 0.4 - 0.2, 1.5 * TMath::Pi() };
6562       }
6563         
6564       // weighted mean
6565       Float_t sum = 0;
6566       Float_t weight = 0;
6567       for (Int_t i=0; i<3; i++)
6568       {
6569         hist->Fit("pol0", "0Q", "", regionBegin[i], regionEnd[i]);
6570         func = hist->GetFunction("pol0");
6571         if (!func)
6572           continue;
6573         sum += func->GetParameter(0) / func->GetParError(0) / func->GetParError(0);
6574         weight += 1. / func->GetParError(0) / func->GetParError(0);
6575       }
6576       
6577       if (weight == 0)
6578         return;
6579       
6580       sum /= weight;
6581       weight = TMath::Sqrt(1. / weight);
6582       
6583       Float_t norm = sum / (1 - 2 * v2);
6584       Double_t normUnc = weight / (1 - 2 * v2);
6585     }
6586     else
6587     {
6588       Int_t bins = 2;
6589       if (baseLineDetermination == 4)
6590         bins = 4;
6591       if (baseLineDetermination == 5)
6592         bins = 8;
6593       Float_t norm = NLowestBinAverage(*hist, bins);
6594       Double_t normUnc = 0;
6595       
6596       Printf("NLowestBinAverage %d --> %f", bins, norm);
6597       
6598       norm /= (1 - 2 * v2);
6599     }
6600     
6601     Printf("Baseline: %f +- %f", norm, normUnc);
6602   }
6603   
6604   if (caseOffset == 0)
6605   {
6606     Float_t awaySideYieldNoBaseline = awaySideYield - norm * (1 - 2 * v2);
6607     Float_t v2YieldNoBaseline = norm * 2 * v2 * (1 + 1.4) / 1.4;
6608     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);
6609   }
6610
6611   //flowFunc->SetParameters(hist->GetBinContent(hist->FindBin(1.4)) / (1.0 - 2.0 * v2), v2);
6612   flowFunc->SetParameters(norm, v2, 0, 0, 0);
6613   if (vn)
6614     flowFunc->SetParameters(norm, vn[1], vn[2], vn[3], vn[4]);
6615   flowFunc->SetLineWidth(2);
6616   if (caseOffset >= 4 && caseOffset <= 9 && caseOffset != 6 && caseOffset != 7)
6617   {
6618     if (caseOffset != 4 && caseOffset != 9)
6619       flowFunc->SetLineStyle(2);
6620     flowFunc->DrawCopy("SAME"); //->SetLineColor(caseOffset - 3);
6621     if (vn)
6622     {
6623       flowFuncTmp = (TF1*) flowFunc->Clone("flowFuncTmp");
6624       for (Int_t i=1; i<=4; i++)
6625       {
6626         flowFuncTmp->SetParameters(flowFuncTmp->GetParameter(0), 0, 0, 0, 0);
6627         flowFuncTmp->SetParameter(i, vn[i]);
6628         flowFuncTmp->SetLineStyle(2);
6629         flowFuncTmp->Print();
6630         flowFuncTmp->DrawCopy("SAME");
6631       }
6632     }
6633   }
6634   
6635   hist->Add(flowFunc, -1);
6636   if (caseOffset == 0)
6637   {
6638     file = TFile::Open("dphi_corr.root", "UPDATE");
6639     hist->SetName(TString(hist->GetName()) + "_tsallis_v2");
6640     hist->Write();
6641     file->Close();
6642     //  hist->DrawCopy("SAME");
6643   }
6644   if (caseOffset == 2 && flatBaseLine)
6645   {
6646     file = TFile::Open("dphi_corr.root", "UPDATE");
6647     hist->SetName(TString(hist->GetName()) + "_tsallis_flat");
6648     hist->Write();
6649     file->Close();
6650     //  hist->DrawCopy("SAME");
6651   }
6652   if (caseOffset == 4 && flatBaseLine)
6653   {
6654     file = TFile::Open("dphi_corr.root", "UPDATE");
6655     hist->SetName(TString(hist->GetName()) + "_fit_flat");
6656     hist->Write();
6657     file->Close();
6658     //  hist->DrawCopy("SAME");
6659   }
6660   if (caseOffset == 9)
6661   {
6662     file = TFile::Open("dphi_corr.root", "UPDATE");
6663     hist->SetName(TString(hist->GetName()) + "_fit_v2");
6664     hist->Write();
6665     file->Close();
6666     //  hist->DrawCopy("SAME");
6667   }
6668   
6669   ExtractYields(hist, trigId, centralityId, ptACenter, ptAWidth, 14 + caseOffset, normUnc);
6670   
6671   if (0 && histMixed)
6672   {
6673     Printf("%f", histMixed->Integral() / histMixed->GetNbinsX());
6674     flowFunc->SetParameters(histMixed->Integral() / histMixed->GetNbinsX(), v2);
6675     flowFunc->SetLineColor(2);
6676     //if (caseOffset == 0)
6677     //  flowFunc->DrawCopy("SAME");
6678   }
6679 }
6680
6681 void RemoveBaseLine(TH1* hist)
6682 {
6683   if (!hist)
6684     return;
6685     
6686   //hist->Rebin(2);
6687   //hist->Scale(0.5);
6688
6689   hist->Fit("pol0", "0", "", 1.07, 2.07);
6690   
6691   if (!hist->GetFunction("pol0"))
6692     return;
6693   
6694   Float_t zyam = hist->GetFunction("pol0")->GetParameter(0);
6695   
6696   if (zyam <= 0)
6697     return;
6698     
6699   return;
6700   
6701   for (Int_t i=1; i<=hist->GetNbinsX(); i++)
6702     hist->SetBinContent(i, hist->GetBinContent(i) - zyam);
6703 }
6704  
6705 void* cacheIds[10];
6706 TH2* cacheMixed[10];
6707
6708 Int_t gHistCount = 0;
6709 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)
6710 {
6711   h = (AliUEHistograms*) hVoid;
6712   hMixed = (AliUEHistograms*) hMixedVoid;
6713   
6714   if (stepMixed < 0)
6715     stepMixed = step;
6716
6717   Int_t centralityBeginBin = 0;
6718   Int_t centralityEndBin = -1;
6719   
6720   if (!useCentralityBinsDirectly && centralityEnd >= centralityBegin)
6721   {
6722     centralityBeginBin = h->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->FindBin(0.01 + centralityBegin);
6723     centralityEndBin = h->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->FindBin(-0.01 + centralityEnd);
6724   }
6725   else if (useCentralityBinsDirectly)
6726   {
6727     centralityBeginBin = centralityBegin;
6728     centralityEndBin = centralityEnd;
6729   }
6730   
6731   // 2d same and mixed event
6732   TH2* sameTwoD  = h->GetUEHist(2)->GetUEHist(step, 0, ptBegin, ptEnd, centralityBeginBin, centralityEndBin, 1, kFALSE);
6733   
6734   if (hMixed)
6735   {
6736     if (!equivMixedBin)
6737     {
6738       // No centrality, nor pT associated dep of the mixed event observed. Use a larger range to get more statistics
6739       
6740       Int_t cacheId = -1;
6741       
6742       for (Int_t i=0; i<10; i++)
6743         if (cacheIds[i] == hMixed)
6744         {
6745           cacheId = i;
6746           break;
6747         }
6748         
6749       // not found
6750       if (cacheId == -1)
6751         for (Int_t i=0; i<10; i++)
6752           if (cacheIds[i] == 0)
6753           {
6754             cacheId = i;
6755             break;
6756           }
6757
6758       if (!cacheIds[cacheId])
6759       {
6760         hMixed->SetPtRange(3.0, 10);
6761         cacheMixed[cacheId] = (TH2*) hMixed->GetUEHist(2)->GetUEHist(stepMixed, 0, 3.0, 10.0, centralityBeginBin, centralityEndBin, 1, kFALSE);
6762         cacheIds[cacheId] = hMixed;
6763         Printf("GetDistAndFlow: Cached for %p on slot %d", hMixed, cacheId);
6764       }
6765       
6766       TH2* mixedTwoD = cacheMixed[cacheId];
6767     }
6768     else
6769     {
6770       // use same bin for mixing
6771       
6772       TH2* mixedTwoD = (TH2*) hMixed->GetUEHist(2)->GetUEHist(stepMixed, 0, ptBegin, ptEnd, centralityBeginBin, centralityEndBin, 1, kFALSE);
6773     }
6774     
6775     if (0)
6776     {
6777       // asssume flat in dphi, gain in statistics
6778       Printf("NOTE: Assuming flat acceptance in phi!");
6779       
6780       TH1* histMixedproj = mixedTwoD->ProjectionY();
6781       histMixedproj->Scale(1.0 / mixedTwoD->GetNbinsX());
6782       
6783       for (Int_t x=1; x<=mixedTwoD->GetNbinsX(); x++)
6784         for (Int_t y=1; y<=mixedTwoD->GetNbinsY(); y++)
6785           mixedTwoD->SetBinContent(x, y, histMixedproj->GetBinContent(y));
6786     }
6787     
6788     // get mixed event normalization by assuming full acceptance at deta of 0 (only works for flat dphi)
6789     if (scaleToPairs)
6790     {
6791       Double_t mixedNorm = mixedTwoD->Integral(1, mixedTwoD->GetNbinsX(), mixedTwoD->GetYaxis()->FindBin(-0.01), mixedTwoD->GetYaxis()->FindBin(0.01));
6792       mixedNorm /= mixedTwoD->GetNbinsX() * (mixedTwoD->GetYaxis()->FindBin(0.01) - mixedTwoD->GetYaxis()->FindBin(-0.01) + 1);
6793     }
6794     else
6795       Double_t mixedNorm = mixedTwoD->Integral() / sameTwoD->Integral();
6796     
6797     // divide and scale
6798     sameTwoD->Divide(mixedTwoD);
6799     sameTwoD->Scale(mixedNorm);
6800     
6801 /*    new TCanvas;
6802     sameTwoD->Draw("SURF1");
6803     dfdsafd;*/
6804   }
6805   
6806   TString histName;
6807   histName.Form("GetDistAndFlow%d", gHistCount++);
6808   
6809   // extract dphi distribution if requested
6810   if (twoD == 1)
6811   {
6812     *hist = sameTwoD;
6813   }
6814
6815   //  Float_t etaLimit = 0.8;
6816   Float_t etaLimit = 1.0;
6817
6818   // 20: return corr in |delta eta| < 1 from which 1 < |delta eta| < 2 is subtracted
6819   if (twoD == 0 || twoD == 10 || twoD == 20)
6820   {
6821     Int_t etaBegin = 1;
6822     Int_t etaEnd = sameTwoD->GetNbinsY();
6823     
6824     if (twoD == 10 || twoD == 20)
6825     {
6826       etaBegin = sameTwoD->GetYaxis()->FindBin(-etaLimit + 0.01);
6827       etaEnd   = sameTwoD->GetYaxis()->FindBin(etaLimit - 0.01);
6828     }
6829
6830     *hist = sameTwoD->ProjectionX(histName, etaBegin, etaEnd);
6831     
6832     if (!scaleToPairs)
6833       (*hist)->Scale(1.0 / (etaEnd - etaBegin + 1));
6834   }
6835   
6836   if (twoD == 11 || twoD == 20)
6837   {
6838     // errors --> are ok
6839     
6840 //       Float_t outerLimit = 2.0;
6841     Float_t outerLimit = 1.8;
6842     Printf("Phi dist: Using outer limit %.2f", outerLimit);
6843 //       Float_t outerLimit = etaLimit * 2;
6844     
6845     histTmp = sameTwoD->ProjectionX(histName + "1", TMath::Max(1, sameTwoD->GetYaxis()->FindBin(-outerLimit + 0.01)), sameTwoD->GetYaxis()->FindBin(-etaLimit - 0.01));
6846     Int_t etaBins = sameTwoD->GetYaxis()->FindBin(-etaLimit - 0.01) - TMath::Max(1, sameTwoD->GetYaxis()->FindBin(-outerLimit + 0.01)) + 1;
6847
6848     TH1D* tracksTmp = sameTwoD->ProjectionX(histName + "2", sameTwoD->GetYaxis()->FindBin(etaLimit + 0.01), TMath::Min(sameTwoD->GetYaxis()->GetNbins(), sameTwoD->GetYaxis()->FindBin(outerLimit - 0.01)));
6849     etaBins += TMath::Min(sameTwoD->GetYaxis()->GetNbins(), sameTwoD->GetYaxis()->FindBin(outerLimit - 0.01)) - sameTwoD->GetYaxis()->FindBin(etaLimit + 0.01) + 1;
6850
6851 //       printf("%f +- %f  %f +- %f ", (*hist)->GetBinContent(1), (*hist)->GetBinError(1), tracksTmp->GetBinContent(1), tracksTmp->GetBinError(1));
6852     histTmp->Add(tracksTmp);
6853 //       Printf(" --> %f +- %f", (*hist)->GetBinContent(1), (*hist)->GetBinError(1));
6854     
6855     if (!scaleToPairs)
6856       histTmp->Scale(1.0 / etaBins);
6857     
6858     if (twoD == 11)
6859       *hist = histTmp;
6860     else if (twoD == 20)
6861     {
6862       // calculate acc with 2 * (deta - 0.5 * deta*deta / 1.6)
6863       if (!hMixedVoid)
6864         histTmp->Scale(0.75 / 0.25);
6865       
6866       histTmp->Scale(1.0 / 0.8);
6867       
6868       (*hist)->Add(histTmp, -1);
6869     }
6870   }
6871   
6872 //   (*hist)->Rebin(2); (*hist)->Scale(0.5);
6873   
6874   //*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);
6875   
6876   TString str;
6877   str.Form("%.1f < p_{T,trig} < %.1f", ptBegin - 0.01, ptEnd + 0.01);
6878   
6879   TString str2;
6880   str2.Form("%.2f < p_{T,assoc} < %.2f", gpTMin - 0.01, gpTMax + 0.01);
6881     
6882   TString newTitle;
6883   newTitle.Form("%s - %s - %d-%d", str.Data(), str2.Data(), centralityBegin, centralityEnd);
6884   if (!useCentralityBinsDirectly)
6885     newTitle += "%";
6886   (*hist)->SetTitle(newTitle);
6887   
6888   if (0 && hMixed)
6889   {
6890     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));
6891     
6892     //new TCanvas; (*hist)->DrawCopy(); histMixed->DrawCopy("SAME")->SetLineColor(2);
6893     
6894     Float_t totalPairs = (*hist)->Integral();
6895     
6896     (*hist)->Divide(histMixed);
6897     (*hist)->Scale(totalPairs / (*hist)->Integral());
6898     
6899     //(*hist)->DrawCopy("SAME")->SetLineColor(4);
6900   }
6901   
6902   if (v2 || vn)
6903   {
6904     // calculate v2trigger
6905     h->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->SetRangeUser(0.01 + centralityBegin, -0.01 + centralityEnd);
6906     ptDist = h->GetUEHist(2)->GetEventHist()->Project(step, 0);
6907     Float_t vTrig[5];
6908     for (Int_t i=2; i<=((vn) ? 5 : 2); i++)
6909       vTrig[i-1] = CalculateFlow(ptDist, ptBegin, ptEnd, i, centralityBegin, centralityEnd);
6910     delete ptDist;
6911     
6912     // calculate v2 assoc
6913     cont = h->GetUEHist(2)->GetTrackHist(0);
6914     h->GetUEHist(2)->GetTrackHist(0)->GetGrid(step)->GetGrid()->GetAxis(3)->SetRangeUser(0.01 + centralityBegin, -0.01 + centralityEnd);
6915     h->GetUEHist(2)->GetTrackHist(0)->GetGrid(step)->GetGrid()->GetAxis(2)->SetRangeUser(ptBegin, ptEnd);
6916     ptDist = h->GetUEHist(2)->GetTrackHist(0)->Project(step, 1);
6917     Float_t vAssoc[5];
6918     for (Int_t i=2; i<=((vn) ? 5 : 2); i++)
6919       vAssoc[i-1] = CalculateFlow(ptDist, gpTMin, gpTMax, i, centralityBegin, centralityEnd);
6920     delete ptDist;
6921   
6922     if (v2)
6923       *v2 = vTrig[2-1] * vAssoc[2-1];
6924     if (vn)
6925       for (Int_t i=2; i<=5; i++)
6926         vn[i-1] = vTrig[i-1] * vAssoc[i-1];
6927   }
6928 }
6929
6930 void CompareNtrDist(const char* fileName1, const char* fileNameCentrality1)
6931 {
6932   loadlibs();
6933   Int_t step = 8;
6934
6935   TCanvas *c1 = new TCanvas("c1", "", 1400, 1100);
6936   TCanvas *c2 = new TCanvas("c2", "", 1400, 1100);
6937
6938   dndpt_central = ReadHepdata("/home/mkofarag/work/Project/2010/raa_dndpt_central.txt", kFALSE, 3);
6939   AliUEHistograms* h1 = (AliUEHistograms*) GetUEHistogram(fileName1);
6940   AliUEHistograms* hc1 = (AliUEHistograms*) GetUEHistogram(fileNameCentrality1);
6941
6942   h1->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->SetRangeUser(0.01 + 0, -0.01 + 5);
6943   ptDist1 = h1->GetUEHist(2)->GetEventHist()->Project(step, 0);
6944   ptDist1->Scale(1.0/1.8/TMath::TwoPi()/hc1->GetCentralityDistribution()->Integral(hc1->GetCentralityDistribution()->FindBin(0.01), hc1->GetCentralityDistribution()->FindBin(4.99)));
6945   for (Int_t i=1; i<=ptDist1->GetNbinsX(); i++)
6946   {
6947     ptDist1->SetBinContent(i, ptDist1->GetBinContent(i)/ptDist1->GetBinWidth(i));
6948   }
6949   for (Int_t i=0; i<dndpt_central->GetN();i++)
6950   {
6951     Double_t x = dndpt_central->GetX()[i];
6952     Double_t y = dndpt_central->GetY()[i]*x;
6953     dndpt_central->SetPoint(i,x,y);
6954   }
6955   ptDist2 = (TH1*) ptDist1->Clone("ptDist2");
6956   ptDist2->Reset();
6957   for (Int_t i=0; i<dndpt_central->GetN(); i++)
6958   {
6959     Float_t width = 0;
6960     if (i > 0)
6961       width += (dndpt_central->GetX()[i] - dndpt_central->GetX()[i-1]) / 2;
6962     if (i < dndpt_central->GetN()-1)
6963       width += (dndpt_central->GetX()[i+1] - dndpt_central->GetX()[i]) / 2;
6964     if (i == 0 || i == dndpt_central->GetN() - 1)
6965       width *= 2;
6966     ptDist2->Fill(dndpt_central->GetX()[i],dndpt_central->GetY()[i]*width);
6967   }
6968   for (Int_t i=1; i<=ptDist2->GetNbinsX(); i++)
6969   {
6970     ptDist2->SetBinContent(i, ptDist2->GetBinContent(i)/ptDist2->GetBinWidth(i));
6971     ptDist2->SetBinError(i,0);
6972   }
6973 /*  for (Int_t i=1; i<=ptDist1->GetNbinsX(); i++)
6974   {
6975     ptDist1->SetBinError(i,0);
6976   }
6977 */
6978   c1->cd();
6979   c1->SetLogy();
6980   ptDist1->SetMarkerStyle(3);
6981   ptDist2->SetMarkerStyle(2);
6982   ptDist1->SetMarkerColor(2);
6983   ptDist2->SetMarkerColor(3);
6984   ptDist1->SetLineColor(2);
6985   ptDist2->SetLineColor(3);
6986   ptDist1->DrawCopy("EP");
6987   ptDist2->Draw("EPSAME");
6988   ptDist1->Divide(ptDist1,ptDist2);
6989   c2->cd();
6990   ptDist1->Draw("EP");
6991
6992 }
6993
6994 void FitNtrDist(const char* fileName1, const char* fileNameCentrality1)
6995 {
6996   loadlibs();
6997   Int_t step = 8;
6998
6999   TCanvas *c1 = new TCanvas("c1", "", 1400, 1100);
7000   TCanvas *c2 = new TCanvas("c2", "", 1400, 1100);
7001   TCanvas *c3 = new TCanvas("c3", "", 1400, 1100);
7002
7003   dndpt_central = ReadHepdata("/home/mkofarag/work/Project/2010/raa_dndpt_central.txt", kFALSE, 3);
7004   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);
7005   TF1* func2 = new TF1("func2", "[0]*TMath::Power(x,-1*[1])",5,20);
7006
7007   func1->SetParLimits(0, 2000, 5000);
7008   func1->SetParLimits(1, 1, 6);
7009   func1->SetParLimits(2, 7, 20);
7010   dndpt_central->Fit(func1,"RB","",0.5,5);
7011
7012   func2->SetParLimits(0, 0, 1000);
7013   func2->SetParLimits(1, 4, 8);
7014   dndpt_central->Fit(func2,"RB","",5,20);
7015
7016   c1->cd();
7017   c1->SetLogy();
7018   c1->SetLogx();
7019   dndpt_central->Draw("AP");
7020   func1->Draw("SAME");
7021   func2->Draw("SAME");
7022
7023   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);
7024   TF1* func4 = new TF1("func4", "[0]*x*TMath::Power(x,-1*[1])",5,20);
7025
7026   func3->FixParameter(0,func1->GetParameter(0));
7027   func3->FixParameter(1,func1->GetParameter(1));
7028   func3->FixParameter(2,func1->GetParameter(2));
7029   func4->FixParameter(0,func2->GetParameter(0));
7030   func4->FixParameter(1,func2->GetParameter(1));
7031
7032   AliUEHistograms* h1 = (AliUEHistograms*) GetUEHistogram(fileName1);
7033   AliUEHistograms* hc1 = (AliUEHistograms*) GetUEHistogram(fileNameCentrality1);
7034
7035   h1->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->SetRangeUser(0.01 + 0, -0.01 + 5);
7036   ptDist1 = h1->GetUEHist(2)->GetEventHist()->Project(step, 0);
7037   ptDist1->Scale(1.0/1.8/TMath::TwoPi()/hc1->GetCentralityDistribution()->Integral(hc1->GetCentralityDistribution()->FindBin(0.01), hc1->GetCentralityDistribution()->FindBin(4.99)));
7038   ptDist2 = (TH1*) ptDist1->Clone("ptDist2");
7039   ptDist2->Reset();
7040   for (Int_t i=1; i<=ptDist1->GetNbinsX(); i++)
7041   {
7042     ptDist1->SetBinContent(i, ptDist1->GetBinContent(i)/ptDist1->GetBinWidth(i));
7043     if (ptDist1->GetBinLowEdge(i)<5) ptDist2->SetBinContent(i, func3->Integral(ptDist1->GetBinLowEdge(i),ptDist1->GetBinLowEdge(i+1)));
7044     else ptDist2->SetBinContent(i, func4->Integral(ptDist1->GetBinLowEdge(i),ptDist1->GetBinLowEdge(i+1)));
7045   }
7046
7047   for (Int_t i=1; i<=ptDist2->GetNbinsX(); i++)
7048   {
7049     ptDist2->SetBinContent(i, ptDist2->GetBinContent(i)/ptDist2->GetBinWidth(i));
7050   }
7051   c2->cd();
7052   c2->SetLogy();
7053   ptDist1->SetMarkerStyle(3);
7054   ptDist2->SetMarkerStyle(2);
7055   ptDist1->SetMarkerColor(2);
7056   ptDist2->SetMarkerColor(3);
7057   ptDist1->SetLineColor(2);
7058   ptDist2->SetLineColor(3);
7059   ptDist1->DrawCopy("EP");
7060   ptDist2->Draw("EPSAME");  
7061
7062   ptDist1->Divide(ptDist1,ptDist2);
7063   c3->cd();
7064   ptDist1->Draw("EP");
7065 }
7066
7067 void DrawNtrDist(const char* fileName1, const char* fileName2, const char* fileNameCentrality1, const char* fileNameCentrality2)
7068 {
7069   loadlibs();
7070
7071   Int_t step = 8;
7072
7073   new TCanvas("c", "", 1400, 1100);
7074   AliUEHistograms* h1 = (AliUEHistograms*) GetUEHistogram(fileName1);
7075   AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(fileName2);
7076   AliUEHistograms* hc1 = (AliUEHistograms*) GetUEHistogram(fileNameCentrality1);
7077   AliUEHistograms* hc2 = (AliUEHistograms*) GetUEHistogram(fileNameCentrality2);
7078   h1->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->SetRangeUser(0.01 + 0, -0.01 + 10);
7079   h2->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->SetRangeUser(0.01 + 0, -0.01 + 10);
7080   ptDist1 = h1->GetUEHist(2)->GetEventHist()->Project(step, 0);
7081   ptDist2 = h2->GetUEHist(2)->GetEventHist()->Project(step, 0);
7082   ptDist1->Scale(1/hc1->GetCentralityDistribution()->Integral(hc1->GetCentralityDistribution()->FindBin(0.01), hc1->GetCentralityDistribution()->FindBin(9.99)));
7083   ptDist2->Scale(1/hc2->GetCentralityDistribution()->Integral(hc2->GetCentralityDistribution()->FindBin(0.01), hc2->GetCentralityDistribution()->FindBin(9.99)));
7084   ptDist1->Divide(ptDist1,ptDist2);
7085   ptDist1->SetMarkerStyle(3);
7086   ptDist1->Draw();
7087 }
7088
7089 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)
7090 {
7091   Printf("GetSumOfRatios | step %d | %d-%d%% | %.1f - %.1f GeV/c | %.1f - %.1f GeV/c", step, centralityBegin, centralityEnd, gpTMin, gpTMax, ptBegin, ptEnd);
7092   
7093   h = (AliUEHistograms*) hVoid;
7094   hMixed = (AliUEHistograms*) hMixedVoid;
7095
7096   Int_t centralityBeginBin = 0;
7097   Int_t centralityEndBin = -1;
7098   
7099   if (!useCentralityBinsDirectly && centralityEnd >= centralityBegin)
7100   {
7101     centralityBeginBin = h->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->FindBin(0.01 + centralityBegin);
7102     centralityEndBin = h->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->FindBin(-0.01 + centralityEnd);
7103   }
7104   else if (useCentralityBinsDirectly)
7105   {
7106     centralityBeginBin = centralityBegin;
7107     centralityEndBin = centralityEnd;
7108   }
7109   
7110   *hist  = h->GetUEHist(2)->GetSumOfRatios2(hMixed->GetUEHist(2), step, 0, ptBegin, ptEnd, centralityBeginBin, centralityEndBin, normalizePerTrigger);
7111   
7112   TString str;
7113   str.Form("%.1f < %s < %.1f", ptBegin - 0.001,(gIsTrkletsTrklets)?"Dphi_{trig}":"p_{T,trig}", ptEnd + 0.01);
7114   
7115   TString str2;
7116   str2.Form("%.1f < %s < %.1f", gpTMin - 0.001, (gIsTrkletsTrklets || gIsMuTrklets)?"Dphi_{ass}":"p_{T,ass}",gpTMax + 0.01);
7117     
7118   TString newTitle;
7119   newTitle.Form("%s - %s - %d-%d", str.Data(), str2.Data(), centralityBegin, centralityEnd);
7120   if (!useCentralityBinsDirectly)
7121     newTitle += "%";
7122   if ((*hist))
7123     (*hist)->SetTitle(newTitle);
7124   //Printf("\n\n\n\n %s\n\n\n",newTitle.Data());
7125 }
7126  
7127 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)
7128 {
7129   loadlibs();
7130   
7131   Bool_t veryCentral = 0;
7132   Bool_t flowComparison = 0;
7133   Bool_t rhicOverlay = 0;
7134   Bool_t highStatBinning = 0;
7135
7136   file = TFile::Open("dphi_corr.root", "RECREATE");
7137   file->Close();
7138   
7139    Int_t leadingPtOffset = 1;
7140     
7141   if (veryCentral || flowComparison)
7142   {
7143     Int_t maxLeadingPt = 2;
7144     Int_t maxAssocPt = 2;
7145     Float_t leadingPtArr[] = { 2.0, 3.0, 4.0, 10.0, 20.0, 40.0 };
7146     //Float_t assocPtArr[] =   { 0.15, 0.5, 1.0, 2.0, 4.0, 6.0, 10.0, 20.0, 40.0 };
7147     Float_t assocPtArr[] =   { 1.0, 2.0, 3.0, 6.0, 10.0, 20.0, 40.0 };
7148   }
7149   else if (rhicOverlay) // RHIC binning
7150   {
7151     Int_t maxLeadingPt = 4;
7152     Int_t maxAssocPt = 5;
7153     Float_t leadingPtArr[] =   { 4.0, 5.0, 7.0, 9.0, 12.0 };
7154     Float_t assocPtArr[] =     { 0.5, 1.0, 2.0, 3.0, 5.0, 7.0 };
7155   }
7156   else if (highStatBinning) 
7157   {
7158     Int_t maxLeadingPt = 3;
7159     Int_t maxAssocPt = 2;
7160     Float_t leadingPtArr[] = { 4.0, 6.0, 8.0, 15.0 };
7161     Float_t assocPtArr[] =   { 1.0, 4.0, 10.0 };
7162   }
7163   else // ALICE binning
7164   {
7165     if (1) // binning from preliminaries
7166     {
7167       Int_t maxLeadingPt = 2;
7168       Int_t maxAssocPt = 7;
7169 //       Float_t leadingPtArr[] = { 6.0, 8.0, 10.0, 10.0, 15.0 };
7170       Float_t leadingPtArr[] = { 6.0, 8.0, 10.0, 15.0, 15.0 };
7171       Float_t assocPtArr[] =     { 0.5, 1.5, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
7172       leadingPtOffset = 2;
7173     }
7174     else if (0)
7175     {
7176       Int_t maxLeadingPt = 1;
7177       Int_t maxAssocPt = 4;
7178       Float_t leadingPtArr[] = { 8.0, 10.0, 15.0, 15.0 };
7179       Float_t assocPtArr[] =     { 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
7180       leadingPtOffset = 2;
7181     }
7182     else
7183     {
7184       Int_t maxLeadingPt = 3;
7185       Int_t maxAssocPt = 3;
7186       Float_t leadingPtArr[] = { 6.0, 8.0, 10.0, 15.0, 20.0 };
7187       Float_t assocPtArr[] =     { 1.0, 2.0, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
7188       leadingPtOffset = 2;
7189     }
7190   }
7191   
7192   Int_t nCentralityBins = 5;
7193   Int_t centralityBins[] = { 1, 7, 9, 11, 13, 16 };
7194   //Int_t centralityBins[] = { 1, 3, 5, 7, 9, 13 };
7195   
7196   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName1);
7197   
7198 //   h->SetZVtxRange(-0.5, 0.5);
7199 //   h->SetZVtxRange(1.5, 2.5);
7200   
7201   AliUEHistograms* hMixed = 0;
7202   AliUEHistograms* hMixed2 = 0; // GetUEHistogram(fileName2, 0, kTRUE);
7203
7204   if (twoD)
7205   {
7206     hMixed = (AliUEHistograms*) GetUEHistogram(fileName1, 0, kTRUE);
7207     hMixed2 = (AliUEHistograms*) GetUEHistogram(fileName2, 0, kTRUE);
7208   }
7209
7210
7211   if (veryCentral)
7212   {
7213     Printf("WARNING: Reading mixed event from preliminaries/corrected_110317.root");
7214     hMixed = (AliUEHistograms*) GetUEHistogram("preliminaries/corrected_110317.root", 0, kTRUE);
7215   }
7216   
7217   AliUEHistograms* h2 = 0;
7218   if (!twoD)
7219     h2 = (AliUEHistograms*) GetUEHistogram(fileName2);
7220
7221   
7222   TCanvas* canvas = new TCanvas("DeltaPhi", "DeltaPhi", 1000, 700);
7223   canvas->Divide(maxAssocPt, maxLeadingPt);
7224   
7225   TCanvas* canvas2 = new TCanvas("Centrality", "Centrality", 800, 600);
7226   centralityHist = (TH1*) h->GetCentralityDistribution();
7227   NormalizeToBinWidth(centralityHist);
7228   centralityHist->Draw();
7229   gPad->SetLogy();
7230   
7231   TLegend* legend = new TLegend(0.2, 0.5, 0.95, 0.90);
7232   TLegend* legend2 = new TLegend(0.5, 0.63, 0.95, 0.90);
7233   legend2->SetFillColor(0);
7234   legend2->SetTextSize(0.04);
7235   
7236   for (Int_t i=0; i<maxLeadingPt; i++)
7237     for (Int_t j=0; j<maxAssocPt; j++)
7238     {
7239       TString str;
7240       str.Form("%.1f < p_{T,trig} < %.1f", leadingPtArr[i], leadingPtArr[i+leadingPtOffset]);
7241       
7242       if (j == 0)
7243       {
7244         canvas2->cd();
7245         h->GetUEHist(2)->GetEventHist()->GetGrid(6)->SetRangeUser(0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01);
7246         centralityHist = h->GetUEHist(2)->GetEventHist()->ShowProjection(1, 6);
7247         centralityHist->SetLineColor(i+2);
7248         NormalizeToBinWidth(centralityHist);
7249         centralityHist->DrawCopy("SAME");
7250         h->GetUEHist(2)->GetEventHist()->GetGrid(6)->SetRangeUser(0, 0, -1);
7251         legend2->AddEntry(centralityHist, str);
7252       }
7253     
7254       canvas->cd(j+1 + i * maxAssocPt);
7255       gPad->SetLeftMargin(0.15);
7256       gPad->SetBottomMargin(0.2);
7257       gPad->SetTopMargin(0.01);
7258       gPad->SetRightMargin(0.01);
7259       
7260       if (i == 0 && j == 3)
7261         legend->Draw();
7262       
7263       gpTMin = assocPtArr[j] + 0.01;
7264       gpTMax = assocPtArr[j+1] - 0.01;
7265       
7266       TString str2;
7267       str2.Form("%.1f < p_{T,assoc} < %.1f", gpTMin - 0.01, gpTMax + 0.01);
7268       
7269       SetupRanges(h);
7270
7271       if (h2)
7272       {
7273         SetupRanges(h2); // SetEtaRange(0, 0) does not need to be called for the leading track result
7274       }
7275       
7276       if (hMixed)
7277       {
7278         SetupRanges(hMixed);
7279       }
7280       
7281       // delta phi
7282       if (!twoD)
7283       {
7284         if (assocPtArr[j] >= leadingPtArr[i+leadingPtOffset])
7285           continue;
7286     
7287         // 0-5% --> 1, 5
7288         // 0-10% --> 1, 6
7289         // 0-20% --> 1, 8
7290         // 20-40% --> 9, 10
7291         // 40-80% --> 11, 14
7292         // > 40% --> 11, 16
7293         
7294         TString hist1Str, hist2Str, hist2bStr;
7295         
7296         Float_t v2[3];
7297         for (Int_t k=0; k<3; k++)
7298           v2[k] = 0;
7299         Float_t vn[3][3];
7300         
7301         if (veryCentral)
7302         {
7303           Int_t step = 0;
7304           TH1* hist1 = 0;
7305           TH1* hist2 = 0;
7306           TH1* hist2b = 0;
7307           TH1* hist3 = 0;
7308           
7309           GetDistAndFlow(h, hMixed, &hist1,  v2, step, 0,  2,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01); hist1Str = "0-2%";
7310 //        GetDistAndFlow(h, hMixed, &hist2,  v2, step, 1,  3,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01); hist2Str = "1-3%";
7311           GetDistAndFlow(h, hMixed, &hist2b,  v2+2, step, 30,  40,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01); hist2bStr = "30-40%";
7312           
7313           //TH1* hist1 = h->GetUEHist(2)->GetUEHist(step, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 1, 2);  hist1Str = "0-2%";
7314           //TH1* hist2 = h->GetUEHist(2)->GetUEHist(step, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 2, 3);  hist2Str = "2-3%";
7315           //TH1* hist2b = h->GetUEHist(2)->GetUEHist(step, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 10, 10); hist2bStr = "30-40%";
7316         }
7317         else if (flowComparison)
7318         {
7319           TH1* hist1 = h->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 1, 5);  hist1Str = "0-5%";
7320           TH1* hist2 = h->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 9, 10);  hist2Str = "20-40%";
7321           TH1* hist2b = h->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 10, 10); hist2bStr = "30-40%";
7322           TH1* hist3 = 0; // h2->GetUEHist(2)->GetUEHist(0, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01);
7323         }
7324         else if (rhicOverlay)
7325         {
7326           TH1* hist1 = h->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 1, 8);   hist1Str = "0-20%";
7327           TH1* hist2 = h->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 9, 12);  hist2Str = "20-60%";
7328           TH1* hist2b = h->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 13, 15);hist2bStr = "60-90%";
7329           TH1* hist3 = h2->GetUEHist(2)->GetUEHist(0, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01);
7330         }
7331         else
7332         {
7333           Int_t step = 6;
7334           TH1* hist1 = 0;
7335           TH1* hist2 = 0;
7336           TH1* hist2b = 0;
7337           
7338           Bool_t equivMixedBin = 1;
7339           Int_t histType = 0;
7340 //        histType = 20; Printf("WARNING: Using histogram type 20");
7341           
7342 //           GetDistAndFlow(h, hMixed, &hist1,  v2, step, 0,  2,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, vn[0]); hist1Str = "0-2%";
7343 //           GetDistAndFlow(h, hMixed, &hist1,  v2, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, vn[0]); hist1Str = "0-5%";
7344           GetDistAndFlow(h, hMixed, &hist1,  v2, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin); hist1Str = "0-5%";
7345           
7346           /*
7347           new TCanvas;
7348           hist1->Draw();
7349
7350           TH1* histTmp1 = 0;
7351           GetDistAndFlow(h, hMixed, &histTmp1,  v2, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 10, equivMixedBin); hist1Str = "0-5%";
7352           histTmp1->SetLineColor(2);
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, 20, equivMixedBin); hist1Str = "0-5%";
7358           histTmp1->SetLineColor(4);
7359           histTmp1->Draw("SAME");
7360           histTmp1->Scale(1 / 0.75);
7361
7362           histTmp1 = 0;
7363           GetDistAndFlow(h, hMixed, &histTmp1,  v2, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 11, equivMixedBin); hist1Str = "0-5%";
7364           histTmp1->SetLineColor(3);
7365           histTmp1->Draw("SAME");
7366           histTmp1->Scale(1 / 0.25);
7367
7368           return;
7369           */
7370
7371           GetDistAndFlow(h, hMixed, &hist2,  v2+1, step, 0, 20, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin); hist2Str = "0-20%";
7372 //           GetDistAndFlow(h, hMixed, &hist2b, v2[2], step, 60, 80, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 0, equivMixedBin); hist2bStr = "60-80%";
7373           GetDistAndFlow(h, hMixed, &hist2b, v2+2, step, 60, 90, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin); hist2bStr = "60-90%";
7374           
7375           Printf("%f %f %f", v2[0], v2[1], v2[2]);
7376 //           Printf("%f %f %f", vn[0][1], vn[0][2], vn[0][3]);
7377           
7378 //           TH1* hist1 = h->GetUEHist(2)->GetUEHist(step, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 1, 8);    hist1Str = "0-20%";
7379 //           TH1* hist2 = h->GetUEHist(2)->GetUEHist(step, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 9, 12);   hist2Str = "20-60%";
7380 //           TH1* hist2b = h->GetUEHist(2)->GetUEHist(step, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 13, 15); hist2bStr = "60-90%";
7381           
7382           step = 6;
7383 //           TH1* hist3Old = h2->GetUEHist(2)->GetUEHist(step, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01);
7384           TH1* hist3 = 0;
7385           GetDistAndFlow(h2, hMixed2, &hist3,  0, step, 0,  -1,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin);
7386 //        hist3->Rebin(2); hist3->Scale(0.5);
7387           
7388 /*        new TCanvas;
7389           hist3->Draw();
7390           hist3Old->DrawCopy("SAME")->SetLineColor(2); */
7391         }
7392         
7393         /*
7394         RemoveBaseLine(hist1);
7395         RemoveBaseLine(hist2);
7396         RemoveBaseLine(hist2b);
7397         RemoveBaseLine(hist3);
7398         */
7399         
7400         TString newTitle;
7401         newTitle.Form("%s - %s", str.Data(), str2.Data());
7402         if (hist1)
7403         {
7404           hist1->SetName(Form("dphi_%d_%d_%d", i, j, 0));
7405           hist1->SetTitle(newTitle + " - " + hist1Str);
7406         }
7407         if (hist2)
7408         {
7409           hist2->SetName(Form("dphi_%d_%d_%d", i, j, 1));
7410           hist2->SetTitle(newTitle + " - " + hist2Str);
7411         }
7412         if (hist2b)
7413         {
7414           hist2b->SetName(Form("dphi_%d_%d_%d", i, j, 2));
7415           hist2b->SetTitle(newTitle + " - " + hist2bStr);
7416         }
7417         if (hist3)
7418         {
7419           hist3->SetName(Form("dphi_%d_%d_%d", i, j, 3));
7420           hist3->SetTitle(newTitle + " - pp");
7421         }
7422         
7423         if (0)
7424         {
7425           hist1->Scale(1.0 / hist1->Integral());
7426           hist2->Scale(1.0 / hist2->Integral());
7427           hist3->Scale(1.0 / hist3->Integral());
7428         }
7429       
7430         if (i == 0 && j == 0)
7431         {
7432           legend->SetFillColor(0);
7433           legend->AddEntry(hist1, "Pb+Pb 0-5%");
7434           if (hist2)
7435             legend->AddEntry(hist2, "Pb+Pb 20-40%");
7436           if (hist2b)
7437             legend->AddEntry(hist2b, "Pb+Pb 60-90%");
7438           if (hist3)
7439             legend->AddEntry(hist3, "p+p 7 TeV");
7440           legend->SetTextSize(0.08);
7441         }
7442       
7443         Prepare1DPlot(hist1);
7444         Prepare1DPlot(hist2);
7445         Prepare1DPlot(hist2b);
7446         Prepare1DPlot(hist3);
7447         
7448         Double_t yMin = 0.01;
7449         Double_t yMax2 = yMax;
7450         
7451         if (yMax < 0)
7452         {
7453           yMin = -0.01; //TMath::Min(hist1->GetMinimum(), hist2->GetMinimum()) * 0.97;
7454           yMax2 = TMath::Max((hist3) ? hist3->GetMaximum() : 0.0, TMath::Max(hist1->GetMaximum(), (hist2) ? hist2->GetMaximum() : 0.0)) * 1.03;
7455         }
7456         
7457         yMax2 *= 1.4;
7458       
7459         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);
7460         dummy->SetStats(kFALSE);
7461         dummy->SetXTitle(hist1->GetXaxis()->GetTitle());
7462         dummy->SetYTitle(hist1->GetYaxis()->GetTitle());
7463         dummy->SetYTitle("1/N_{trig} dN/d#Delta#phi"); 
7464         Prepare1DPlot(dummy);
7465         
7466         dummy->GetYaxis()->SetTitleOffset(0.8);
7467       
7468         dummy->GetXaxis()->SetLabelSize(0.08);
7469         dummy->GetYaxis()->SetLabelSize(0.08);
7470         dummy->GetXaxis()->SetTitleSize(0.08);
7471         dummy->GetYaxis()->SetTitleSize(0.08);
7472         /*
7473         dummy->GetYaxis()->SetTitleOffset(0.8);
7474         */
7475         
7476         dummyTmp = dummy->DrawCopy();
7477         
7478         hist1->DrawCopy("SAME");
7479         
7480         if (hMixed)
7481         {
7482           SetupRanges(hMixed);
7483           // for HI file do not set range in eta anymore after it was changed to delta eta axis
7484           hMixed->SetEtaRange(0, 0);
7485         }
7486         TH1* hist1Mixed = 0; //hMixed->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 1, 5);
7487         //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]);
7488         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);
7489         
7490         //hist1Mixed->Draw("SAME");
7491         if (hist2)
7492         {
7493           hist2->SetLineColor(2);
7494           hist2->DrawCopy("SAME");
7495           
7496           TH1* hist2Mixed = 0; //hMixed->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 9, 10);
7497           //hist2Mixed->SetLineColor(2);
7498           //hist2Mixed->Draw("SAME");
7499
7500           DrawFlow(v2[1], hist2, leadingPtArr[i], assocPtArr[j], hist2Mixed, i, 1, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
7501           //DrawFlow(GetFlow05(), hist2, leadingPtArr[i], assocPtArr[j], hist2Mixed);
7502         }
7503         if (hist2b)
7504         {
7505           hist2b->SetLineColor(3);
7506           hist2b->DrawCopy("SAME");
7507         
7508           TH1* hist2bMixed = 0; //hMixed->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 13, 15);
7509           DrawFlow(v2[2], hist2b, leadingPtArr[i], assocPtArr[j], hist2bMixed, i, 2, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
7510           //DrawFlow(GetFlow05(), hist2b, leadingPtArr[i], assocPtArr[j], hist2bMixed);
7511         }
7512         if (hist3)
7513         {
7514           hist3->SetLineColor(4);
7515           hist3->DrawCopy("SAME");
7516           
7517           DrawFlow(0, hist3, leadingPtArr[i], assocPtArr[j], 0, i, 3, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
7518         }
7519         //dummyTmp->GetYaxis()->SetRangeUser(0, 1.1 * TMath::Max(TMath::Max(hist1->GetMaximum(), hist2->GetMaximum()), hist2b->GetMaximum()));
7520       }
7521       else // delta eta delta phi
7522       {
7523         if (twoD == 1)
7524         {
7525           if (assocPtArr[j] > leadingPtArr[i])
7526             continue;
7527         }
7528         else
7529         {
7530           Int_t jRef = 1;
7531         
7532           if (assocPtArr[jRef] > leadingPtArr[i])
7533             continue;
7534           
7535           // fix pt assoc
7536           gpTMin = assocPtArr[jRef] + 0.01;
7537           gpTMax = assocPtArr[jRef+1] - 0.01;
7538           
7539           str2.Form("%.1f < p_{T,assoc} < %.1f", gpTMin - 0.01, gpTMax + 0.01);
7540       
7541           // use j for centrality
7542           if (j >= nCentralityBins)
7543             continue;
7544             
7545           centrBegin = centralityBins[j];
7546           centrEnd = centralityBins[j+1] - 1;
7547         }
7548         
7549         SetupRanges(h);
7550         // for HI file do not set range in eta anymore after it was changed to delta eta axis
7551         h->SetEtaRange(0, 0);
7552         
7553         SetupRanges(hMixed);
7554         // for HI file do not set range in eta anymore after it was changed to delta eta axis
7555         hMixed->SetEtaRange(0, 0);
7556           
7557         TH2* histSame = (TH2*) h->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, centrBegin, centrEnd, kTRUE);
7558         TH2* histMixed = (TH2*) hMixed->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, centrBegin, centrEnd, kTRUE);
7559         
7560         // rebin 
7561         histSame->Rebin2D(2, 2);
7562         histMixed->Rebin2D(2, 2);
7563         
7564         if (1)
7565         {
7566           // fit delta eta, assuming no dependence on dphi
7567           
7568           //new TCanvas; histMixed->DrawCopy("SURF1");
7569           
7570           histMixedproj = histMixed->ProjectionY();
7571           histMixedproj->Scale(1.0 / histMixed->GetNbinsX());
7572           
7573           for (Int_t x=1; x<=histMixed->GetNbinsX(); x++)
7574             for (Int_t y=1; y<=histMixed->GetNbinsY(); y++)
7575               histMixed->SetBinContent(x, y, histMixedproj->GetBinContent(y));
7576           
7577           //new TCanvas; histMixed->DrawCopy("SURF1");
7578         }
7579         
7580         histSame->SetStats(0);
7581         histSame->GetYaxis()->SetRangeUser(-1.5, 1.5);
7582         histSame->SetTitle("");
7583         histSame->Divide(histMixed);
7584         histSame->DrawCopy("SURF1");
7585         
7586         TString str3;
7587         str3.Form("%d-%d%%", (Int_t) h->GetCentralityDistribution()->GetXaxis()->GetBinLowEdge(centrBegin), (Int_t) h->GetCentralityDistribution()->GetXaxis()->GetBinUpEdge(centrEnd));
7588         latex = new TLatex(0.15, 0.95, str3);
7589         latex->SetNDC();
7590         latex->SetTextSize(0.08);
7591         latex->Draw();
7592       }
7593       
7594       latex = new TLatex(0.55, 0.8, str);
7595       latex->SetNDC();
7596       latex->SetTextSize(0.06);
7597       latex->Draw();
7598       
7599       latex = new TLatex(0.55, 0.88, str2);
7600       latex->SetNDC();
7601       latex->SetTextSize(0.06);
7602       latex->Draw();
7603       
7604 //            if (i == 0)        return;
7605     }
7606
7607   canvas->SaveAs(Form("DeltaPhi_%.2f.png", yMax));
7608   
7609   canvas2->cd();
7610   legend2->Draw();
7611
7612   //TString name;
7613   //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]);
7614 }
7615    
7616 void ExamplePhiEtaGap(const char* fileNamePbPb, const char* fileNamePbPbMix)
7617 {
7618   loadlibs();
7619   
7620   if (!fileNamePbPbMix)
7621     fileNamePbPbMix = fileNamePbPb;
7622   
7623   Int_t leadingPtOffset = 1;
7624     
7625   Int_t maxLeadingPt = 4;
7626   Int_t maxAssocPt = 5;
7627   Float_t leadingPtArr[] = { 2.0, 3.0, 6.0, 6.0, 8.0, 10.0, 15.0, 20.0 };
7628   Float_t assocPtArr[] =     { 0.15, 0.5, 1.0, 2.0, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
7629   leadingPtOffset = 1;
7630   
7631   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileNamePbPb);
7632   hMixed = (AliUEHistograms*) GetUEHistogram(fileNamePbPbMix, 0, kTRUE);
7633   
7634   Int_t i=1;
7635   Int_t j=2;
7636   
7637   gpTMin = assocPtArr[j] + 0.01;
7638   gpTMax = assocPtArr[j+1] - 0.01;
7639   
7640   SetupRanges(h);
7641   SetupRanges(hMixed);
7642
7643   if (assocPtArr[j] >= leadingPtArr[i+leadingPtOffset])
7644     continue;
7645
7646   TString hist1Str, hist2Str, hist2bStr;
7647   
7648   Int_t step = 6;
7649   TH1* hist1 = 0;
7650   TH1* hist2 = 0;
7651   TH1* hist3 = 0;
7652   
7653   Float_t v2[3];
7654   
7655   Bool_t equivMixedBin = kTRUE;
7656   
7657   Int_t centralityBegin = 20;
7658   Int_t centralityEnd = 30;
7659   
7660   GetDistAndFlow(h, hMixed, &hist1,  0, step, centralityBegin, centralityEnd,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 20, equivMixedBin); 
7661
7662   GetDistAndFlow(h, hMixed, &hist2,  0, step, centralityBegin, centralityEnd,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 10, equivMixedBin); 
7663 //   hist2->Scale(1.0 / 0.8);
7664   
7665   GetDistAndFlow(h, hMixed, &hist3,  0, step, centralityBegin, centralityEnd,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 11, equivMixedBin); 
7666   hist3->Scale(1.0 / 0.8);
7667   
7668   hist1->Draw();
7669   hist2->SetLineColor(2);
7670   hist2->Draw("SAME");
7671   hist3->SetLineColor(4);
7672   hist3->Draw("SAME");
7673 }  
7674
7675 void ExampleDEtaDPhi(const char* fileNamePbPb, const char* fileNamePbPbMix)
7676 {
7677   loadlibs();
7678   
7679   if (!fileNamePbPbMix)
7680     fileNamePbPbMix = fileNamePbPb;
7681   
7682   Int_t leadingPtOffset = 1;
7683     
7684   Int_t maxLeadingPt = 4;
7685   Int_t maxAssocPt = 5;
7686   Float_t leadingPtArr[] = { 1.0, 2.0, 3.0, 6.0, 6.0, 8.0, 10.0, 15.0, 20.0 };
7687   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 };
7688   leadingPtOffset = 1;
7689   
7690   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileNamePbPb);
7691   hMixed = (AliUEHistograms*) GetUEHistogram(fileNamePbPbMix, 0, kTRUE);
7692   
7693   Int_t i=1;
7694   Int_t j=3;
7695   
7696   gpTMin = assocPtArr[j] + 0.01;
7697   gpTMax = assocPtArr[j+1] - 0.01;
7698   
7699   SetupRanges(h);
7700   SetupRanges(hMixed);
7701
7702   Int_t step = 6;
7703   TH1* hist1 = 0;
7704
7705   GetSumOfRatios(h, hMixed, &hist1,  step, 0,  5, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
7706
7707   hist1->Draw("SURF1");
7708 }
7709
7710 Double_t GetEtaCut(TTree* analysisSettings)
7711 {
7712   Double_t etaCut = 0;
7713   if (analysisSettings)
7714   {
7715     analysisSettings->GetBranch("fTrackEtaCut")->SetAddress(&etaCut);
7716     analysisSettings->GetEntry(0);
7717   }
7718   return etaCut;
7719 }
7720
7721 void PlotDeltaPhiEtaGap(const char* fileNamePbPb, const char* fileNamePbPbMix = 0, const char* fileNamepp = 0, const char* fileNamepp2 = 0, const char* outputFile = "dphi_corr.root")
7722 {
7723   loadlibs();
7724   
7725   if (!fileNamePbPbMix)
7726     fileNamePbPbMix = fileNamePbPb;
7727   
7728   file = TFile::Open(outputFile, "RECREATE");
7729   file->Close();
7730   
7731   Int_t leadingPtOffset = 1;
7732     
7733   Bool_t symmetrizePt = kFALSE;
7734   Int_t maxLeadingPt = 4;
7735   Int_t maxAssocPt = 6;
7736   if (0)
7737   {
7738     //PbPb, NS peak shapes
7739     Float_t leadingPtArr[] = { 1.0, 2.0, 3.0, 4.0, 8.0, 15.0, 20.0 };
7740 //     Float_t leadingPtArr[] = { 2.0, 3.0, 4.0, 8.0, 15.0, 20.0 };
7741     Float_t assocPtArr[] =     { 0.15, 0.5, 1.0, 2.0, 3.0, 4.0, 8.0, 10.0, 12.0 };
7742   }
7743   else if (0)
7744   {
7745     //Example for the Hadrons_Example wagon
7746     maxLeadingPt = 3;
7747     maxAssocPt = 6;
7748     Float_t leadingPtArr[] =     { 3.0, 5.0, 8.0, 16.0 };
7749     Float_t assocPtArr[] = {0.15, 0.3, 50.0, 0.5, 50.0, 1.0, 50.0 };
7750   }
7751   else if (gIsMuTrklets)
7752     {
7753     //mu-trklets
7754     maxLeadingPt = 8;
7755     maxAssocPt = 6;
7756     Float_t leadingPtArr[] =     {., 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 6.0, 10.0};
7757     Float_t assocPtArr[] = {0.0,0.0,0.0, 1.0, 2.0,5.0,10. };
7758     gIsMuTrklets=kTRUE;
7759     }
7760   else if (gIsTrkletsTrklets)
7761     {
7762     //trklets-trklets
7763     maxLeadingPt = 4;
7764     maxAssocPt = 6;
7765     Float_t leadingPtArr[] =     {0.0, 1.0,2.0,5.0,10.0};
7766     Float_t assocPtArr[] = {0.0,0.0,0.0, 1.0, 2.0,5.0,10.0};
7767     gIsTrkletsTrklets=kTRUE;
7768     }
7769   else if (0)
7770   {
7771     //pA, trigger from all pT
7772     maxLeadingPt = 1;
7773     maxAssocPt = 10;
7774     Float_t leadingPtArr[] =   { 0.3, 4.0 };
7775     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 };
7776 //     symmetrizePt = kTRUE;
7777   }
7778   else if (0)
7779   {
7780     //pA, associated from all pT
7781     maxLeadingPt = 6;
7782     maxAssocPt = 2;
7783     Float_t leadingPtArr[] =     { 0.5, 1.0, 2.0, 3.0, 4.0, 0.5, 4.0 };
7784     Float_t assocPtArr[] = { 0.15, 0.5, 4.0 };
7785 //     symmetrizePt = kTRUE;
7786   }  
7787   else if (0)
7788   {
7789     //pA
7790     maxLeadingPt = 5;
7791     maxAssocPt = 6;
7792     Float_t leadingPtArr[] = { 0.5, 1.0, 1.5, 2.0, 2.5,  4.0, 8.0, 15.0, 20.0 };
7793     Float_t assocPtArr[] =     { 0.15, 0.5, 1.0, 1.5, 2.0, 2.5, 4.0, 8.0, 10.0, 12.0 };
7794   }
7795   else if (1)
7796   {
7797     //pp, for Ilya
7798     maxLeadingPt = 5;
7799     maxAssocPt = 6;
7800     Float_t leadingPtArr[] = { 0.5, 1.0, 2.0, 3.0, 4.0, 8.0, 20. };
7801     Float_t assocPtArr[] =  { 0.15, 0.5, 1.0, 2.0, 3.0, 4.0, 8.0, 20. };
7802   }
7803   else if (1)
7804   {
7805     //pA, for Tim
7806     maxLeadingPt = 3;
7807     maxAssocPt = 4;
7808     Float_t leadingPtArr[] = { 0.5, 1.0, 2.0, 4.0 };
7809     Float_t assocPtArr[] =  { 0.15, 0.5, 1.0, 2.0, 4.0 };
7810   }
7811   else if (0)
7812   {
7813     //pPb and PbPb with PID, with low pt points TPC only
7814     maxLeadingPt = 10;
7815     maxAssocPt = 11;
7816     Float_t leadingPtArr[] = {   0.2, 0.3, 0.5 , 0.75, 1.0, 1.25, 1.5, 2.0, 2.5, 3., 4.0};
7817     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 };
7818   }
7819   else if (0)
7820   {
7821     //PbPb for comaprison with You
7822     maxLeadingPt = 8;
7823     maxAssocPt = 9;
7824     Float_t leadingPtArr[] = {   0.2, 0.3, 0.5 , 1.0, 1.5, 2.0, 2.5, 3., 4.0};
7825     Float_t assocPtArr[] =   { 0.15, 0.2, 0.3, 0.5 , 1.0, 1.5, 2.0, 2.5, 3., 4.0 };
7826   }
7827   else if (1)
7828   {
7829     //pA, fine
7830     maxLeadingPt = 6;
7831     maxAssocPt = 7;
7832     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 };
7833     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 };
7834   }
7835   else if (0)
7836   {
7837     //pA, v3
7838     maxLeadingPt = 3;
7839     maxAssocPt = 4;
7840     Float_t leadingPtArr[] =   {       0.5, 1.5, 2.5, 4.0, 5.0, 8.0, 15.0, 20.0 };
7841     Float_t assocPtArr[] =     { 0.15, 0.5, 1.5, 2.5, 4.0, 5.0, 8.0, 10.0, 12.0 };
7842   }
7843   else if (0)
7844   {
7845     //pA 2012; MC validation (also PbPb)
7846     maxLeadingPt = 3;
7847     maxAssocPt = 4;
7848     Float_t leadingPtArr[] = { 0.5, 1.0, 2.0, 4.0, 8.0, 15.0, 20.0 };
7849     Float_t assocPtArr[] =     { 0.15, 0.5, 1.0, 2.0, 4.0, 8.0, 10.0, 12.0 };
7850   }
7851   else if (0)
7852   {
7853     // pA, CMS ridge comparison
7854     maxLeadingPt = 4;
7855     maxAssocPt = 5;
7856     Float_t leadingPtArr[] = { 0.5, 1.0, 2.0, 3.0, 4.0, 8.0, 15.0, 20.0 };
7857     Float_t assocPtArr[] =     { 0.15, 0.5, 1.0, 2.0, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
7858   }
7859   else if (0) 
7860   {
7861     maxLeadingPt = 1;
7862     maxAssocPt = 3;
7863     Float_t leadingPtArr[] = { 2.0, 3.0};
7864     Float_t assocPtArr[] =     {0.15, 0.5, 1.0, 2.0};
7865   }
7866   else if (0) //Comparison to STAR (p_T,t)
7867   {
7868     maxLeadingPt = 4;
7869     maxAssocPt = 3;
7870     Float_t leadingPtArr[] = { 2.0, 3.0, 4.0, 5.0, 6.0};
7871     Float_t assocPtArr[] =     {0.15, 0.5, 1.5, 6.0};
7872   }
7873   else if (0) //Comparison to STAR (p_T,a)
7874   {
7875     maxLeadingPt = 1;
7876     maxAssocPt = 6;
7877     Float_t leadingPtArr[] = { 3.0, 6.0};
7878     Float_t assocPtArr[] =     {0.15, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0};
7879   }
7880   else if (0) 
7881   {
7882     maxLeadingPt = 4;
7883     maxAssocPt = 4;
7884     Float_t leadingPtArr[] = { 2.0, 3.0, 4.0, 8.0, 15.0 };
7885     Float_t assocPtArr[] =     {0.15, 0.5, 1.0, 1.5, 2.0};
7886   }
7887   
7888   TList* list = 0;
7889   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileNamePbPb, &list);
7890   hMixed = (AliUEHistograms*) GetUEHistogram(fileNamePbPbMix, 0, kTRUE);
7891 //   hMixed3 = (AliUEHistograms*) hMixed->Clone();
7892   
7893   if (symmetrizePt)
7894   {
7895     h->GetUEHist(2)->SymmetrizepTBins();
7896     hMixed->GetUEHist(2)->SymmetrizepTBins();
7897   }
7898   if(0){
7899     h->GetUEHist(2)->SetSkipScaleMixedEvent(1);
7900     hMixed->GetUEHist(2)->SetSkipScaleMixedEvent(1);
7901   }
7902   
7903   TList* list2 = 0;
7904   AliUEHistograms* h2 = 0;
7905   AliUEHistograms* hMixed2 = 0;
7906   if (fileNamepp)
7907   {
7908     h2 = (AliUEHistograms*) GetUEHistogram(fileNamepp, &list2);
7909     hMixed2 = (AliUEHistograms*) GetUEHistogram(fileNamepp, 0, kTRUE);
7910   }
7911
7912   TList* list3 = 0;
7913   AliUEHistograms* h3 = 0;
7914   AliUEHistograms* hMixed3 = 0;
7915   if (fileNamepp2)
7916   {
7917     h3 = (AliUEHistograms*) GetUEHistogram(fileNamepp2, &list3);
7918     hMixed3 = (AliUEHistograms*) GetUEHistogram(fileNamepp2, 0, kTRUE);
7919   }
7920
7921 //   h->GetUEHist(2)->SetGetMultCache();
7922 //   hMixed->GetUEHist(2)->SetGetMultCache();
7923
7924   TH2* refMultRaw = (TH2*) list->FindObject("referenceMultiplicity");
7925   if (refMultRaw)
7926   {
7927 //     new TCanvas; refMultRaw->Draw("COLZ");
7928     //Int_t nCentrBins = 4;
7929     Int_t nCentrBins = 5;
7930     Double_t centrBins[] = { 0., 20., 40., 60., 80., 100. };
7931     Double_t centrBins[] = { 0., 20., 40., 60., 100. };
7932
7933     //     Double_t centrBins[] = { 0., 3., 10., 50., 100. };
7934     TH1* refMult = new TH1F("refMult", ";centrality;<Nch>", nCentrBins, centrBins);
7935     for (Int_t i=0; i<nCentrBins; i++)
7936     {
7937       TH1* proj = refMultRaw->ProjectionY(Form("proj%d", i), refMultRaw->GetXaxis()->FindBin(centrBins[i] + 0.1), refMultRaw->GetXaxis()->FindBin(centrBins[i+1] - 0.1));
7938 //       new TCanvas; proj->DrawClone();
7939       refMult->SetBinContent(refMult->GetXaxis()->FindBin(centrBins[i] + 0.1), proj->GetMean());
7940       refMult->SetBinError(refMult->GetXaxis()->FindBin(centrBins[i] + 0.1), proj->GetMeanError());
7941       Printf("Ref multiplicity for centrality %f to %f: %f", centrBins[i], centrBins[i+1], proj->GetMean());
7942     }
7943 //     new TCanvas; refMult->Draw();
7944     file = TFile::Open(outputFile, "UPDATE");
7945     refMult->Write();
7946     file->Close();
7947 //     return;
7948   }
7949
7950   tree = (TTree*) list->FindObject("UEAnalysisSettings");
7951   Double_t etaCut = GetEtaCut(tree);
7952   Printf("Setting eta cut to %f", etaCut);
7953   h->SetTrackEtaCut(etaCut);
7954
7955   if (list2)
7956   {
7957     tree = (TTree*) list2->FindObject("UEAnalysisSettings");
7958     if (tree)
7959     {
7960       Double_t etaCut = GetEtaCut(tree);
7961       Printf("Setting eta cut to %f", etaCut);
7962       h2->SetTrackEtaCut(etaCut);
7963     }
7964     else
7965     {
7966       Double_t etaCut = 0.9;
7967       Printf("WARNING: Setting eta cut to %f without checking", etaCut);
7968       h2->SetTrackEtaCut(etaCut);
7969     }
7970   }
7971
7972   if (list3)
7973   {
7974     tree = (TTree*) list3->FindObject("UEAnalysisSettings");
7975     if (tree)
7976     {
7977       Double_t etaCut = GetEtaCut(tree);
7978       Printf("Setting eta cut to %f", etaCut);
7979       h3->SetTrackEtaCut(etaCut);
7980     }
7981     else
7982     {
7983       Double_t etaCut = 0.9;
7984       Printf("WARNING: Setting eta cut to %f without checking", etaCut);
7985       h3->SetTrackEtaCut(etaCut);
7986     }
7987   }
7988   
7989   for (Int_t i=0; i<maxLeadingPt; i++)
7990   {
7991     for (Int_t j=1; j<maxAssocPt; j++)
7992     {
7993       if(0){
7994         if(j!=(i+1))continue;
7995         Printf("\nOnly symmetric pt bins selected, leading pt: %f - %f     associated pt: %f - %f",leadingPtArr[i],leadingPtArr[i+leadingPtOffset],assocPtArr[j],assocPtArr[j+1]); 
7996       }
7997
7998       gpTMin = assocPtArr[j] + 0.01;
7999       gpTMax = assocPtArr[j+1] - 0.01;
8000
8001       if(gIsTrkletsTrklets || gIsMuTrklets)=gpTMin=0.01;
8002       
8003       if(gpTMin >= gpTMax)continue;
8004         
8005       SetupRanges(h);
8006       SetupRanges(hMixed);
8007       SetupRanges(h2);
8008       SetupRanges(hMixed2);
8009       SetupRanges(h3);
8010       SetupRanges(hMixed3);
8011 //       SetupRanges(hMixed3);
8012
8013       if(0) if (assocPtArr[j] >= leadingPtArr[i+leadingPtOffset])
8014         continue;
8015   
8016       TH1* hist0 = 0;
8017       TH1* hist1 = 0;
8018       TH1* hist2 = 0;
8019       TH1* hist3 = 0;
8020       TH1* hist4 = 0;
8021       TH1* hist5 = 0;
8022       TH1* hist6 = 0;
8023       TH1* hist7 = 0;
8024       TH1* hist8 = 0;
8025       TH1* hist9 = 0;
8026       TH1* hist10 = 0;
8027       
8028       Bool_t equivMixedBin = 1; //kFALSE; // TODO ?
8029       Bool_t scaleToPairs = kTRUE;
8030       
8031       Int_t histType = 1;
8032
8033       if (0)
8034       {
8035         // PbPb
8036         Int_t step = 8;
8037         Bool_t normalizePerTrigger = kFALSE; // don't do if histograms are to be merged -> Use MergeDPhiFiles below
8038       
8039         GetSumOfRatios(h, hMixed, &hist1,  step, 0,   10, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, normalizePerTrigger); 
8040         GetSumOfRatios(h, hMixed, &hist5,  step, 10,  20, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, normalizePerTrigger); 
8041         GetSumOfRatios(h, hMixed, &hist4,  step, 20,  30, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, normalizePerTrigger); 
8042         GetSumOfRatios(h, hMixed, &hist6,  step, 30,  50, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, normalizePerTrigger); 
8043         GetSumOfRatios(h, hMixed, &hist2,  step, 50,  80, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, normalizePerTrigger); 
8044
8045         if (h2)
8046           GetSumOfRatios(h2, hMixed2, &hist3,  step, 0,  -1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8047       }
8048       else if (1)
8049       {
8050         // pp vs Mult for Ilya
8051         Int_t step = 8;
8052 //      Int_t step = 0;
8053       
8054         GetSumOfRatios(h, hMixed, &hist0,  step,  0,  1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8055         GetSumOfRatios(h, hMixed, &hist1,  step,  0, 10, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8056         GetSumOfRatios(h, hMixed, &hist2,  step, 10, 20, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8057         GetSumOfRatios(h, hMixed, &hist3,  step, 20, 30, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8058         GetSumOfRatios(h, hMixed, &hist4,  step, 30, 40, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8059         GetSumOfRatios(h, hMixed, &hist5,  step, 40, 50, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8060         GetSumOfRatios(h, hMixed, &hist6,  step, 50, 60, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8061         GetSumOfRatios(h, hMixed, &hist7,  step, 60, 70, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8062         GetSumOfRatios(h, hMixed, &hist8,  step, 70, 80, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8063         GetSumOfRatios(h, hMixed, &hist9,  step, 80, 90, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8064         GetSumOfRatios(h, hMixed, &hist10,step, 90,100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8065         }      
8066       else if (1)
8067       {
8068         // pA, fine binning
8069         Int_t step = 8;
8070 //      Int_t step = 0;
8071       
8072         GetSumOfRatios(h, hMixed, &hist1,  step,  0, 20, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8073         GetSumOfRatios(h, hMixed, &hist2,  step, 20, 40, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8074         GetSumOfRatios(h, hMixed, &hist4,  step, 40, 60, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8075         GetSumOfRatios(h, hMixed, &hist5,  step, 60, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8076 //      GetSumOfRatios(h, hMixed, &hist7,  step, 70, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8077 //      GetSumOfRatios(h, hMixed, &hist8,  step, 80, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8078
8079         if (h2)
8080           GetSumOfRatios(h2, hMixed2, &hist3,  step, 0,  -1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8081         
8082         if (h3)
8083           GetSumOfRatios(h3, hMixed3, &hist6,  step, 0,  -1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8084       }      
8085       else if (1)
8086       {
8087         // trkletstrklets
8088         Int_t step = 6;
8089         //Int_t step = 0;
8090         GetSumOfRatios(h, hMixed, &hist1,  step,  0, 20, (gIsTrkletsTrklets)?0.01:leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8091         GetSumOfRatios(h, hMixed, &hist2,  step, 20, 40, (gIsTrkletsTrklets)?0.01:leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8092         GetSumOfRatios(h, hMixed, &hist4,  step, 40, 60, (gIsTrkletsTrklets)?0.01:leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8093         GetSumOfRatios(h, hMixed, &hist5,  step, 60, 100, (gIsTrkletsTrklets)?0.01:leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8094         // GetSumOfRatios(h, hMixed, &hist2,  step,  20, 40, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8095         // GetSumOfRatios(h, hMixed, &hist4,  step,  40, 60, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8096         // GetSumOfRatios(h, hMixed, &hist5,  step,  60, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8097       }      
8098       else if (0)
8099       {
8100         // pA, V0 as trigger particle detector
8101         Int_t step = 6;
8102       
8103         h->GetUEHist(2)->SetSkipScaleMixedEvent(kTRUE);
8104         GetSumOfRatios(h, hMixed, &hist1,  step,  0, 20, 1.01, 1.99, kTRUE); 
8105         GetSumOfRatios(h, hMixed, &hist2,  step, 20, 40, 1.01, 1.99, kTRUE); 
8106         GetSumOfRatios(h, hMixed, &hist4,  step, 40, 60, 1.01, 1.99, kTRUE); 
8107         GetSumOfRatios(h, hMixed, &hist5,  step, 60, 100, 1.01, 1.99, kTRUE); 
8108
8109         if (h2)
8110           GetSumOfRatios(h2, hMixed2, &hist3,  step, 0,  -1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8111         
8112         if (h3)
8113           GetSumOfRatios(h3, hMixed3, &hist6,  step, 0,  -1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8114       }      
8115       else if (0)
8116       {
8117         // pp, MB
8118         Int_t step = 8;      
8119         GetSumOfRatios(h, hMixed, &hist1,  step, 0, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE, kTRUE); 
8120       }      
8121       else if (0)
8122       {
8123         // pp
8124         Int_t step = 8;
8125       
8126         GetSumOfRatios(h, hMixed, &hist1,  step, 4, 4, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE, kTRUE); 
8127         GetSumOfRatios(h, hMixed, &hist2,  step, 3, 3, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE, kTRUE); 
8128         GetSumOfRatios(h, hMixed, &hist4,  step, 2, 2, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE, kTRUE); 
8129         GetSumOfRatios(h, hMixed, &hist5,  step, 1, 1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE, kTRUE); 
8130       }      
8131       else if (0)
8132       {
8133         // pA, course binning
8134         Int_t step = 8;
8135       
8136         GetSumOfRatios(h, hMixed, &hist1,  step,  0, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8137         GetSumOfRatios(h, hMixed, &hist2,  step,  0,  40, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8138         GetSumOfRatios(h, hMixed, &hist4,  step, 40, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8139
8140         GetDistAndFlow(h, hMixed, &hist5,  0, step, 0, 100,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8141
8142         GetSumOfRatios(h2, hMixed2, &hist3,  step, 0,  -1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8143       }      
8144       else if (0)
8145       {
8146         // pA, CMS ridge paper comparison
8147         Int_t step = 8;
8148       
8149         GetSumOfRatios(h, hMixed, &hist1,  step,  0, 3, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8150         GetSumOfRatios(h, hMixed, &hist2,  step,  3, 10, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8151         GetSumOfRatios(h, hMixed, &hist4,  step, 10, 50, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8152         GetSumOfRatios(h, hMixed, &hist5,  step, 50, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8153         GetSumOfRatios(h, hMixed, &hist7,  step, 80, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8154       }     
8155       else if (0)
8156       {
8157         // pA, MC, validation binning
8158         GetSumOfRatios(h, hMixed, &hist1,  0,  0, 80, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8159         GetSumOfRatios(h, hMixed, &hist5,  10,  0, 80, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8160       }        
8161       else if (0)
8162       {
8163         // pA, MC, validation binning
8164         GetSumOfRatios(h, hMixed, &hist1,  0,  0, 20, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8165         GetSumOfRatios(h, hMixed, &hist2,  0,  20, 40, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8166         GetSumOfRatios(h, hMixed, &hist3,  0,  40, 60, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8167         GetSumOfRatios(h, hMixed, &hist4,  0,  60, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8168         GetSumOfRatios(h, hMixed, &hist5,  10,  0, 20, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8169         GetSumOfRatios(h, hMixed, &hist6,  10,  20, 40, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8170         GetSumOfRatios(h, hMixed, &hist7,  10,  40, 60, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8171         GetSumOfRatios(h, hMixed, &hist8,  10,  60, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8172       }        
8173       else if (0)
8174       {
8175         // pp, MB
8176         Int_t step = 8;
8177         
8178         GetSumOfRatios(h, hMixed, &hist1,  step,  0, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8179       }      
8180       else if (0)
8181       {
8182         // pA, MC, validation binning, without vertex axis
8183         GetDistAndFlow(h, hMixed, &hist1,  0, 0,  0, 20, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8184         GetDistAndFlow(h, hMixed, &hist2,  0, 0,  20, 40, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8185         GetDistAndFlow(h, hMixed, &hist3,  0, 0,  40, 60, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8186         GetDistAndFlow(h, hMixed, &hist4,  0, 0,  60, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8187         GetDistAndFlow(h, hMixed, &hist5,  0, 10,  0, 20, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8188         GetDistAndFlow(h, hMixed, &hist6,  0, 10,  20, 40, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8189         GetDistAndFlow(h, hMixed, &hist7,  0, 10,  40, 60, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8190         GetDistAndFlow(h, hMixed, &hist8,  0, 10,  60, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8191       }        
8192       else if (1)
8193       {
8194         // PbPb, MC, impact parameter binning
8195         Int_t step = 0;
8196         
8197         Printf(">>>>>>>> Not using GetSumOfRatios!!!");
8198
8199         GetDistAndFlow(h, hMixed, &hist1,  0, step, 1,   6,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs, -1, kTRUE); 
8200         GetDistAndFlow(h, hMixed, &hist5,  0, step, 7,  7, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs, -1, kTRUE); 
8201         GetDistAndFlow(h, hMixed, &hist4,  0, step, 8,  8, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs, -1, kTRUE); 
8202         GetDistAndFlow(h, hMixed, &hist6,  0, step, 9,  10, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs, -1, kTRUE); 
8203         GetDistAndFlow(h, hMixed, &hist2,  0, step, 11,  13, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs, -1, kTRUE);
8204
8205         if (h2)
8206           GetDistAndFlow(h2, hMixed2, &hist3,  0, step, 0, -1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs);
8207       }
8208       else if (1)
8209       {
8210         // PbPb, MC
8211         Int_t step = 0;
8212         
8213         Printf(">>>>>>>> Not using GetSumOfRatios!!!");
8214         GetDistAndFlow(h, hMixed, &hist1,  0, step, 0,   10,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8215 //      Printf("integral: %f", ((TH2*) hist1)->Integral(1, 36, 5, 36));
8216 //      return;
8217
8218         GetDistAndFlow(h, hMixed, &hist5,  0, step, 10,  20, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8219         GetDistAndFlow(h, hMixed, &hist4,  0, step, 20,  30, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8220         GetDistAndFlow(h, hMixed, &hist6,  0, step, 30,  50, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8221         GetDistAndFlow(h, hMixed, &hist2,  0, step, 50,  80, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs);
8222 //      step = 6;
8223         if (h2)
8224           GetDistAndFlow(h2, hMixed2, &hist3,  0, step, 0, -1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs);
8225 //      new TCanvas; hist3->DrawClone("SURF1");
8226 //      GetDistAndFlow(hMixed2, 0, &hist3,  0, step, 0, -1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs);
8227 //      new TCanvas; hist3->DrawClone("SURF1");
8228 //      Printf("integral: %f", ((TH2*) hist3)->Integral(1, 36, 5, 36));
8229 //      return;
8230         
8231         //MC closure test in pA and PbPb with PID
8232         // GetDistAndFlow(h, hMixed, &hist1,  0, step,  0,   20,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8233         // GetDistAndFlow(h, hMixed, &hist2,  0, step, 20,  40,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8234         // GetDistAndFlow(h, hMixed, &hist4,  0, step, 40,  60,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8235         // GetDistAndFlow(h, hMixed, &hist5,  0, step, 60, 100,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8236         // GetDistAndFlow(h, hMixed, &hist7,  0, step, 80, 100,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8237         // GetDistAndFlow(h, hMixed, &hist8,  0, step,  0,  100,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8238       }
8239       else if (0)
8240       {
8241         Int_t step = 8;
8242  
8243         GetSumOfRatios(h, hMixed, &hist1,  step, 60,  70, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8244         GetSumOfRatios(h, hMixed, &hist2,  step, 70,  80, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8245         GetSumOfRatios(h, hMixed, &hist3,  step, 80,  90, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8246       }
8247       else if (1)
8248       {
8249         Int_t step = 8;
8250  
8251         GetSumOfRatios(h, hMixed, &hist1,  step, 0,  1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8252         GetSumOfRatios(h, hMixed, &hist2,  step, 1,  3, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8253         GetSumOfRatios(h, hMixed, &hist4,  step, 3,  5, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8254         GetSumOfRatios(h, hMixed, &hist5,  step, 5,  10, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8255         GetSumOfRatios(h, hMixed, &hist6,  step, 10,  20, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8256       }
8257
8258       file = TFile::Open(outputFile, "UPDATE");
8259       
8260       if (hist0)
8261         {
8262           hist0->SetName(Form("dphi_%d_%d_%d", i, j, 0));
8263           hist0->Write();
8264         }
8265       if (hist1)
8266         {
8267           hist1->SetName(Form("dphi_%d_%d_%d", i, j, 1));
8268           hist1->Write();
8269         }
8270       if (hist2)
8271         {
8272           hist2->SetName(Form("dphi_%d_%d_%d", i, j, 2));
8273           hist2->Write();
8274         }
8275       if (hist3)
8276         {
8277           hist3->SetName(Form("dphi_%d_%d_%d", i, j, 3));
8278           hist3->Write();
8279         }
8280       if (hist4)
8281         {
8282           hist4->SetName(Form("dphi_%d_%d_%d", i, j, 4));
8283           hist4->Write();
8284         }
8285       if (hist5)
8286         {
8287           hist5->SetName(Form("dphi_%d_%d_%d", i, j, 5));
8288           hist5->Write();
8289         }
8290       if (hist6)
8291         {
8292           hist6->SetName(Form("dphi_%d_%d_%d", i, j, 6));
8293           hist6->Write();
8294         }
8295       if (hist7)
8296         {
8297           hist7->SetName(Form("dphi_%d_%d_%d", i, j, 7));
8298           hist7->Write();
8299         }
8300       if (hist8)
8301         {
8302           hist8->SetName(Form("dphi_%d_%d_%d", i, j, 8));
8303           hist8->Write();
8304         }
8305       if (hist9)
8306         {
8307           hist9->SetName(Form("dphi_%d_%d_%d", i, j, 9));
8308           hist9->Write();
8309         }
8310       if (hist10)
8311         {
8312           hist10->SetName(Form("dphi_%d_%d_%d", i, j, 10));
8313           hist10->Write();
8314         }
8315       
8316       // if (hist1)
8317       // {
8318       //        hist1->SetName(Form("dphi_%d_%d_%d", i, j, 0));
8319       //        hist1->Write();
8320       // }
8321       
8322       // if (hist2)
8323       // {
8324       //        hist2->SetName(Form("dphi_%d_%d_%d", i, j, 1));
8325       //        hist2->Write();
8326       // }
8327       
8328       // if (hist4)
8329       // {
8330       //        hist4->SetName(Form("dphi_%d_%d_%d", i, j, 3));
8331       //        hist4->Write();
8332       // }
8333
8334       // if (hist5)
8335       // {
8336       //        hist5->SetName(Form("dphi_%d_%d_%d", i, j, 4));
8337       //        hist5->Write();
8338       // }
8339       
8340       // if (hist7)
8341       // {
8342       //        hist7->SetName(Form("dphi_%d_%d_%d", i, j, 6));
8343       //        hist7->Write();
8344       // }
8345
8346       // if (hist8)
8347       // {
8348       //        hist8->SetName(Form("dphi_%d_%d_%d", i, j, 7));
8349       //        hist8->Write();
8350       // }
8351
8352       // if (hist6)
8353       // {
8354       //        hist6->SetName(Form("dphi_%d_%d_%d", i, j, 5));
8355       //        TString title(hist6->GetTitle());
8356       //        title.ReplaceAll("0--1%", "pp");
8357       //        hist6->SetTitle(title);
8358       //        hist6->Write();
8359       // }
8360       
8361       // if (hist3)
8362       // {
8363       //        hist3->SetName(Form("dphi_%d_%d_%d", i, j, 2));
8364       //        TString title(hist3->GetTitle());
8365       //        title.ReplaceAll("0--1%", "pp");
8366       //        hist3->SetTitle(title);
8367       //        hist3->Write();
8368       // }
8369       
8370       file->Close();
8371
8372       delete hist0;
8373       delete hist1;
8374       delete hist2;
8375       delete hist3;
8376       delete hist4;
8377       delete hist5;
8378       delete hist6;
8379       delete hist7;
8380       delete hist8;      
8381       delete hist9;      
8382       delete hist10;      
8383       
8384 //       return;
8385     }
8386     
8387     TH1* triggers = h->GetUEHist(2)->GetTriggersAsFunctionOfMultiplicity(step, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01);
8388     triggers->SetName(Form("triggers_%d", i));
8389     TString str;
8390     str.Form("%.1f < p_{T,trig} < %.1f", leadingPtArr[i], leadingPtArr[i+leadingPtOffset]);
8391     triggers->SetTitle(str);
8392
8393     file = TFile::Open(outputFile, "UPDATE");
8394     triggers->Write();
8395     file->Close();    
8396   }
8397     
8398   delete h;
8399   delete hMixed;
8400 }
8401
8402 Int_t gMCBinning = -1;
8403 void ExtractNSPeakShapesMC(const char* fileNamePbPb, const char* fileNamepp = 0, const char* outputFile = "dphi_corr.root")
8404 {
8405   loadlibs();
8406   
8407   file = TFile::Open(outputFile, "RECREATE");
8408   file->Close();
8409   
8410   Int_t leadingPtOffset = 1;
8411     
8412   Int_t maxLeadingPt = 4;
8413   Int_t maxAssocPt = 6;
8414
8415   //PbPb, NS peak shapes
8416   Float_t leadingPtArr[] = { 1.0, 2.0, 3.0, 4.0, 8.0, 15.0, 20.0 };
8417   Float_t assocPtArr[] =     { 0.15, 0.5, 1.0, 2.0, 3.0, 4.0, 8.0, 10.0, 12.0 };
8418   
8419   TList* list = 0;
8420   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileNamePbPb, &list);
8421   hMixed = (AliUEHistograms*) GetUEHistogram(fileNamePbPb, 0, kTRUE);
8422   
8423   TList* list2 = 0;
8424   AliUEHistograms* h2 = 0;
8425   AliUEHistograms* hMixed2 = 0;
8426   if (fileNamepp)
8427   {
8428     h2 = (AliUEHistograms*) GetUEHistogram(fileNamepp, &list2);
8429     hMixed2 = (AliUEHistograms*) GetUEHistogram(fileNamepp, 0, kTRUE);
8430   }
8431
8432   for (Int_t i=0; i<maxLeadingPt; i++)
8433   {
8434     for (Int_t j=2; j<maxAssocPt; j++)
8435     {
8436       gpTMin = assocPtArr[j] + 0.01;
8437       gpTMax = assocPtArr[j+1] - 0.01;
8438       
8439       if(gpTMin >= gpTMax)continue;
8440         
8441       SetupRanges(h);
8442       SetupRanges(hMixed);
8443       SetupRanges(h2);
8444       SetupRanges(hMixed2);
8445
8446       if(1) if (assocPtArr[j] >= leadingPtArr[i+leadingPtOffset])
8447         continue;
8448   
8449       TH1* hist1 = 0;
8450       TH1* hist2 = 0;
8451       TH1* hist3 = 0;
8452       TH1* hist4 = 0;
8453       TH1* hist5 = 0;
8454       TH1* hist6 = 0;
8455       
8456       Bool_t equivMixedBin = 1;
8457       Bool_t scaleToPairs = kTRUE;
8458       Int_t histType = 1;
8459
8460       if (gMCBinning == 1) // HIJING
8461       {
8462         // PbPb, MC, impact parameter binning
8463         Int_t step = 0;
8464         
8465         GetDistAndFlow(h, hMixed, &hist1,  0, step, 1,   6,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs, -1, kTRUE); 
8466         GetDistAndFlow(h, hMixed, &hist5,  0, step, 7,  7, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs, -1, kTRUE); 
8467         GetDistAndFlow(h, hMixed, &hist4,  0, step, 8,  8, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs, -1, kTRUE); 
8468         GetDistAndFlow(h, hMixed, &hist6,  0, step, 9,  10, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs, -1, kTRUE); 
8469         GetDistAndFlow(h, hMixed, &hist2,  0, step, 11,  13, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs, -1, kTRUE);
8470
8471         if (h2)
8472           GetDistAndFlow(h2, hMixed2, &hist3,  0, step, 0, -1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs);
8473       }
8474       else if (gMCBinning == 2) // AMPT
8475       {
8476         // PbPb, MC, impact parameter binning
8477         Int_t step = 0;
8478         
8479         GetDistAndFlow(h, hMixed, &hist1,  0, step, 1,   2,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs, -1, kTRUE); 
8480         GetDistAndFlow(h, hMixed, &hist5,  0, step, 3,  3, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs, -1, kTRUE); 
8481         GetDistAndFlow(h, hMixed, &hist4,  0, step, 4,  4, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs, -1, kTRUE); 
8482         GetDistAndFlow(h, hMixed, &hist6,  0, step, 5,  6, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs, -1, kTRUE); 
8483         GetDistAndFlow(h, hMixed, &hist2,  0, step, 7,  9, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs, -1, kTRUE);
8484
8485         if (h2)
8486           GetDistAndFlow(h2, hMixed2, &hist3,  0, step, 0, -1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs);
8487       }
8488       
8489       file = TFile::Open(outputFile, "UPDATE");
8490       
8491       if (hist1)
8492       {
8493         hist1->SetName(Form("dphi_%d_%d_%d", i, j, 0));
8494         hist1->Write();
8495       }
8496       
8497       if (hist2)
8498       {
8499         hist2->SetName(Form("dphi_%d_%d_%d", i, j, 1));
8500         hist2->Write();
8501       }
8502       
8503       if (hist4)
8504       {
8505         hist4->SetName(Form("dphi_%d_%d_%d", i, j, 3));
8506         hist4->Write();
8507       }
8508
8509       if (hist5)
8510       {
8511         hist5->SetName(Form("dphi_%d_%d_%d", i, j, 4));
8512         hist5->Write();
8513       }
8514       
8515       if (hist6)
8516       {
8517         hist6->SetName(Form("dphi_%d_%d_%d", i, j, 5));
8518         hist6->Write();
8519       }
8520       
8521       if (hist3)
8522       {
8523         hist3->SetName(Form("dphi_%d_%d_%d", i, j, 2));
8524         TString title(hist3->GetTitle());
8525         title.ReplaceAll("0--1%", "pp");
8526         hist3->SetTitle(title);
8527         hist3->Write();
8528       }
8529       
8530       file->Close();
8531
8532       delete hist1;
8533       delete hist2;
8534       delete hist3;
8535       delete hist4;
8536       delete hist5;
8537       delete hist6;
8538     }
8539   }
8540     
8541   delete h;
8542   delete hMixed;
8543 }
8544
8545 void MergeDPhiFiles(const char* fileName, const char* fileName2, const char* target)
8546 {
8547   // merges the dphi histograms (except the pp histogram at index "2") as well as the triggers
8548   // then divides the dphi histograms by the respective number of triggers
8549  
8550   file = TFile::Open(fileName);
8551   file2 = TFile::Open(fileName2);
8552
8553   fileTarget = TFile::Open(target, "RECREATE");
8554   fileTarget->Close();
8555   
8556   Int_t maxLeadingPt = 10;
8557   Int_t maxAssocPt = 11;
8558
8559   Int_t nHists = 8;
8560   for (Int_t i=0; i<maxLeadingPt; i++)
8561   {
8562     TH1* triggers = (TH1*) file->Get(Form("triggers_%d", i));
8563     if (!triggers)
8564       continue;
8565     
8566     TH1* triggers2 = (TH1*) ((file2) ? file2->Get(Form("triggers_%d", i)) : 0);
8567     if (!triggers2)
8568       Printf("WARNING: trigger %d missing", i);
8569     
8570     for (Int_t j=0; j<maxAssocPt; j++)
8571     {
8572       for (Int_t histId = 0; histId < nHists; histId++)
8573       {
8574         TH2* hist = (TH2*) file->Get(Form("dphi_%d_%d_%d", i, j, histId));
8575         if (!hist)
8576         {
8577           TH2* hist2 = (TH2*) ((file2) ? file2->Get(Form("dphi_%d_%d_%d", i, j, histId)) : 0);
8578           if (hist2)
8579             Printf("WARNING: %d %d %d exists only in file2, not copied!");
8580           continue;
8581         }
8582         
8583         if (histId != 2) // don't merge pp
8584         {
8585           TString title(hist->GetTitle());
8586           title.ReplaceAll("%", "");
8587           tokens = title.Tokenize("-");
8588           
8589           Float_t centralityBegin = ((TObjString*) tokens->At(2))->String().Atoi();
8590           Float_t centralityEnd = ((TObjString*) tokens->At(3))->String().Atoi();
8591           
8592           Double_t nTriggers = triggers->Integral(triggers->FindBin(centralityBegin + 0.001), triggers->FindBin(centralityEnd - 0.001));
8593           Double_t nTriggers2 = 0;
8594
8595           TH2* hist2 = (TH2*) ((file2) ? file2->Get(Form("dphi_%d_%d_%d", i, j, histId)) : 0);
8596           if (hist2 && triggers2) 
8597           {
8598             if (histId != 1 && histId != 5) // don't merge 60-80% and 40-60%
8599             {
8600               hist->Add(hist2);
8601               nTriggers2 = triggers2->Integral(triggers2->FindBin(centralityBegin + 0.001), triggers2->FindBin(centralityEnd - 0.001));
8602             }
8603           }
8604           else
8605             Printf("WARNING: %d %d %d missing", i, j, histId);
8606             
8607           if (nTriggers + nTriggers2 > 0)
8608             hist->Scale(1.0 / (nTriggers + nTriggers2));
8609
8610           Printf("%s %f %f %f %f", hist->GetTitle(), centralityBegin, centralityEnd, nTriggers, nTriggers2);
8611         }
8612
8613         fileTarget = TFile::Open(target, "UPDATE");
8614         hist->Write();
8615         fileTarget->Close();
8616       }
8617     }
8618   }
8619 }
8620
8621 void ExtractMiniJetHistograms(const char* fileNamePbPb, Bool_t useMixed = kTRUE, const char* outputFile = "dphi_corr.root")
8622 {
8623   loadlibs();
8624   
8625   file = TFile::Open(outputFile, "RECREATE");
8626   file->Close();
8627   
8628   Int_t leadingPtOffset = 1;
8629     
8630   if (1)
8631   { 
8632     // minijets
8633     Int_t maxLeadingPt = 1;
8634     Int_t maxAssocPt = 1;
8635     Float_t leadingPtArr[] = { 0.7, 5.0 };
8636     Float_t assocPtArr[] =   { 0.7, 5.0 };
8637   }
8638   
8639   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileNamePbPb);
8640   hMixed = (AliUEHistograms*) GetUEHistogram(fileNamePbPb, 0, kTRUE);
8641   
8642   Int_t step = 8;
8643
8644   for (Int_t i=0; i<maxLeadingPt; i++)
8645   {
8646     for (Int_t j=0; j<maxAssocPt; j++)
8647     {
8648 //       i = 3; j = 6;
8649       
8650       gpTMin = assocPtArr[j] + 0.01;
8651       gpTMax = assocPtArr[j+1] - 0.01;
8652       
8653       SetupRanges(h);
8654       SetupRanges(hMixed);
8655
8656       if (assocPtArr[j] >= leadingPtArr[i+leadingPtOffset])
8657         continue;
8658   
8659       if (1)
8660       {
8661         // pA, minijets, very fine binning
8662         
8663         for (Int_t centr=0; centr<20; centr++)
8664         {
8665           TH1* hist1 = 0;
8666           if (useMixed)
8667             GetSumOfRatios(h, hMixed, &hist1, step, 5*centr, 5*centr+5, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kFALSE); 
8668           else
8669             GetDistAndFlow(h, 0, &hist1, 0, step, 5*centr, 5*centr+5, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 1, 1, 0, kTRUE); 
8670           
8671           if (!hist1)
8672             continue;
8673
8674           file = TFile::Open(outputFile, "UPDATE");
8675           hist1->SetName(Form("dphi_%d_%d_%d", i, j, centr));
8676           hist1->Write();
8677           file->Close();
8678           
8679           delete hist1;
8680         }
8681       }
8682     }
8683     
8684     TH1* triggers = h->GetUEHist(2)->GetTriggersAsFunctionOfMultiplicity(step, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01);
8685     triggers->SetName(Form("triggers_%d", i));
8686     TString str;
8687     str.Form("%.1f < p_{T,trig} < %.1f", leadingPtArr[i], leadingPtArr[i+leadingPtOffset]);
8688     triggers->SetTitle(str);
8689
8690     file = TFile::Open(outputFile, "UPDATE");
8691     triggers->Write();
8692     file->Close();
8693   }
8694   
8695   TH1* events = h->GetEventCount()->ProjectionY("events", h->GetEventCount()->GetXaxis()->FindBin(step), h->GetEventCount()->GetXaxis()->FindBin(step));
8696   file = TFile::Open(outputFile, "UPDATE");
8697   events->Write("events");
8698   file->Close();
8699 }
8700
8701 TLatex* DrawLatex(Float_t x, Float_t y, Int_t color, const char* text, Float_t fontSize = 0.06)
8702 {
8703   latex = new TLatex(x, y, text);
8704   latex->SetNDC();
8705   latex->SetTextSize(fontSize);
8706   latex->SetTextColor(color);
8707   latex->Draw();
8708   return latex;
8709 }
8710
8711 void DrawChi2NDF(TF1* func, TH1* hist, Float_t x, Float_t y, Int_t color = 1)
8712 {
8713   Float_t chi2 = 0;
8714   Int_t ndf = 0;
8715   for (Int_t i=hist->GetXaxis()->FindBin(-0.8); i<=hist->GetXaxis()->FindBin(0.8); i++)
8716   {
8717     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);
8718     ndf++;
8719   }
8720   ndf -= func->GetNumberFreeParameters();
8721   
8722   printf("#chi^{2}/ndf = %.1f/%d = %.1f  ", func->GetChisquare(), func->GetNDF(), func->GetChisquare() / func->GetNDF());
8723   Printf("#chi^{2}/ndf = %.1f/%d = %.1f", chi2, ndf, chi2 / ndf);
8724
8725   DrawLatex(x, y, color, Form("#chi^{2}/ndf = %.1f/%d = %.1f", func->GetChisquare(), func->GetNDF(), func->GetChisquare() / func->GetNDF()));
8726   DrawLatex(x, y - 0.05, color, Form("#chi^{2}/ndf = %.1f/%d = %.1f", chi2, ndf, chi2 / ndf));
8727 }   
8728    
8729 void FitDeltaPhiEtaGap(TH1* hist, Int_t color, TGraphErrors* graph, Float_t x, Float_t yPosChi2)
8730 {
8731   hist->SetLineColor(color);
8732   hist->DrawCopy("SAME");
8733
8734   Bool_t twoGauss = kFALSE;
8735   
8736   if (!twoGauss)
8737     func = new TF1("func", "[0]+gaus(1)");
8738   else
8739   {
8740     func = new TF1("func", "[0]+gaus(1)+gaus(4)");
8741     func->FixParameter(5, 0);
8742     func->SetParLimits(3, 0.1, 10);
8743     func->SetParLimits(6, 0.1, 10);
8744     func->SetParLimits(1, 0, 10);
8745     func->SetParLimits(4, 0, 10);
8746   }
8747   
8748   func->SetParameters(0, 1, 0, 0.3, 1, 0, 1);
8749   func->FixParameter(2, 0);
8750   func->SetLineColor(color);
8751
8752   hist->Fit(func, "", "SAME");
8753 //   hist->Fit(func, "IM", "SAME");
8754   
8755   if (twoGauss)
8756   {
8757     func2 = new TF1("func2", "[0]+gaus(1)", -1.5, 4.5);
8758     func2->SetParameters(func->GetParameter(0), func->GetParameter(1), func->GetParameter(2), func->GetParameter(3));
8759     func2->SetLineColor(color);
8760     func2->SetLineWidth(1);
8761     func2->SetLineStyle(2);
8762     func2->Draw("SAME");
8763     
8764     func2 = new TF1("func2", "[0]+gaus(1)", -1.5, 4.5);
8765     func2->SetParameters(func->GetParameter(0), func->GetParameter(4), func->GetParameter(5), func->GetParameter(6));
8766     func2->SetLineColor(color);
8767     func2->SetLineWidth(1);
8768     func2->SetLineStyle(2);
8769     func2->Draw("SAME");
8770   }
8771       
8772   if (twoGauss)
8773   {
8774     Bool_t firstIsMin = func->GetParameter(3) < func->GetParameter(6);
8775     
8776     Bool_t onlyOne = kFALSE;
8777     if (func->GetParameter(1) / func->GetParameter(4) < 0.1)
8778     {
8779       firstIsMin = kFALSE;
8780       onlyOne = kTRUE;
8781     }
8782     if (func->GetParameter(1) / func->GetParameter(4) > 10)
8783     {
8784       firstIsMin = kTRUE;
8785       onlyOne = kTRUE;
8786     }
8787     
8788     graph->SetPoint(graph->GetN(), x - 0.1, func->GetParameter((firstIsMin) ? 3 : 6));
8789     graph->SetPointError(graph->GetN()-1, 0, func->GetParError((firstIsMin) ? 3 : 6));
8790
8791     if (!onlyOne)
8792     {
8793       graph->SetPoint(graph->GetN(), x + 0.1, TMath::Abs(func->GetParameter((!firstIsMin) ? 3 : 6)));
8794       graph->SetPointError(graph->GetN()-1, 0, func->GetParError((!firstIsMin) ? 3 : 6));
8795     }
8796   }
8797   else
8798   {
8799     graph->SetPoint(graph->GetN(), x, TMath::Abs(func->GetParameter(3)));
8800     graph->SetPointError(graph->GetN()-1, 0, func->GetParError(3));
8801   }  
8802     
8803   DrawChi2NDF(func, hist, 0.5, yPosChi2, color);
8804 }
8805
8806 void AnalyzeDeltaPhiEtaGap(const char* fileName)
8807 {
8808   TFile::Open(fileName);
8809   
8810   Int_t maxLeadingPt = 5;
8811   Int_t maxAssocPt = 6;
8812
8813   TCanvas* canvas = new TCanvas("DeltaPhi", "DeltaPhi", 1000, 700);
8814   canvas->Divide(maxAssocPt, maxLeadingPt);
8815       
8816   TGraphErrors* width1 = new TGraphErrors;
8817   TGraphErrors* width2 = new TGraphErrors;
8818   TGraphErrors* width3 = new TGraphErrors;
8819   
8820   for (Int_t i=0; i<maxLeadingPt; i++)
8821     for (Int_t j=0; j<maxAssocPt; j++)
8822     {
8823       canvas->cd(j+1 + i * maxAssocPt);
8824       gPad->SetLeftMargin(0.15);
8825       gPad->SetBottomMargin(0.2);
8826       gPad->SetTopMargin(0.01);
8827       gPad->SetRightMargin(0.01);
8828       
8829       hist1 = (TH1*) gFile->Get(Form("dphi_%d_%d_%d", i, j, 0));
8830       hist2 = (TH1*) gFile->Get(Form("dphi_%d_%d_%d", i, j, 1));
8831       hist3 = (TH1*) gFile->Get(Form("dphi_%d_%d_%d", i, j, 2));
8832       
8833       if (!hist1)
8834         continue;
8835
8836       TString tmpStr(hist1->GetTitle());
8837       tmpStr.ReplaceAll(" - ", "#");
8838       tokens = tmpStr.Tokenize("#");
8839       TString str(tokens->At(0)->GetName());
8840       TString str2(tokens->At(1)->GetName());
8841       
8842       Prepare1DPlot(hist1);
8843       Prepare1DPlot(hist2);
8844       Prepare1DPlot(hist3);
8845
8846       // remove baseline
8847       hist1->Fit("pol0", "0", "", 1, 4);
8848       if (!hist1->GetFunction("pol0"))
8849         continue;
8850       hist1->GetFunction("pol0")->SetRange(-10, 10);
8851       hist1->Add(hist1->GetFunction("pol0"), -1);
8852       
8853       hist3->Fit("pol0", "0", "", 1, 4);
8854       hist3->GetFunction("pol0")->SetRange(-10, 10);
8855       hist3->Add(hist3->GetFunction("pol0"), -1);
8856       
8857       Double_t yMin = 0.01;
8858       Double_t yMax = -1;
8859       
8860       if (yMax < 0)
8861       {
8862         yMin = TMath::Min(hist1->GetMinimum(), hist2->GetMinimum()) * 0.97;
8863         yMax = TMath::Max(hist1->GetMaximum(), (hist2) ? hist2->GetMaximum() : 0.0) * 1.1;
8864       }
8865       
8866 //       yMin = hist1->GetMinimum() * 0.9;
8867       yMax *= 1.5;
8868     
8869       TH2F* dummy = new TH2F("dummy", "", 100, hist1->GetXaxis()->GetBinLowEdge(1), hist1->GetXaxis()->GetBinUpEdge(hist1->GetNbinsX()), 1000, yMin, yMax);
8870       dummy->SetStats(kFALSE);
8871       dummy->SetXTitle(hist1->GetXaxis()->GetTitle());
8872       dummy->SetYTitle(hist1->GetYaxis()->GetTitle());
8873       dummy->SetYTitle("1/N_{trig} dN/d#Delta#phi"); 
8874       Prepare1DPlot(dummy);
8875       
8876       dummy->GetYaxis()->SetTitleOffset(0.8);
8877     
8878       dummy->GetXaxis()->SetLabelSize(0.08);
8879       dummy->GetYaxis()->SetLabelSize(0.08);
8880       dummy->GetXaxis()->SetTitleSize(0.08);
8881       dummy->GetYaxis()->SetTitleSize(0.08);
8882       /*
8883       dummy->GetYaxis()->SetTitleOffset(0.8);
8884       */
8885       
8886       dummyTmp = dummy->DrawCopy();
8887       
8888       // TODO plot yield? baseline problematic?
8889
8890       Float_t xPos = width1->GetN();
8891       xPos = j*7+i;
8892
8893       FitDeltaPhiEtaGap(hist1, 1, width1, xPos, 0.7);
8894       FitDeltaPhiEtaGap(hist2, 4, width2, xPos, 0.5);
8895       FitDeltaPhiEtaGap(hist3, 2, width3, xPos, 0.6);
8896       
8897       latex = new TLatex(0.3, 0.8, str);
8898       latex->SetNDC();
8899       latex->SetTextSize(0.06);
8900       latex->Draw();
8901       
8902       latex = new TLatex(0.3, 0.88, str2);
8903       latex->SetNDC();
8904       latex->SetTextSize(0.06);
8905       latex->Draw();
8906       
8907       DrawLatex(0.8, 0.9,  1, "0-5%");
8908       DrawLatex(0.8, 0.85, 2, "60-90%");
8909       DrawLatex(0.8, 0.8,  4, "pp");
8910
8911 //       return;
8912 //       i = 10; j = 10;
8913     }
8914     
8915   new TCanvas;
8916   width1->SetMarkerStyle(20);
8917   width1->Draw("AP");
8918
8919   width2->SetMarkerStyle(24);
8920   width2->SetMarkerColor(4);
8921   width2->Draw("P SAME");
8922
8923   width3->SetMarkerStyle(25);
8924   width3->SetMarkerColor(2);
8925   width3->Draw("P SAME");
8926 }
8927
8928 void CheckWing(const char* fileName)
8929 {
8930   TFile::Open(fileName);
8931   
8932   Int_t maxLeadingPt = 4;
8933   Int_t maxAssocPt = 5;
8934
8935   TCanvas* canvas = new TCanvas("DeltaPhi", "DeltaPhi", 1000, 700);
8936   canvas->Divide(maxAssocPt-1, maxLeadingPt);
8937       
8938   for (Int_t i=0; i<maxLeadingPt; i++)
8939     for (Int_t j=1; j<maxAssocPt; j++)
8940     {
8941       canvas->cd(j + i * (maxAssocPt - 1));
8942       gPad->SetLeftMargin(0.15);
8943       gPad->SetBottomMargin(0.2);
8944 //       gPad->SetTopMargin(0.01);
8945       gPad->SetRightMargin(0.01);
8946       
8947       hist1 = (TH1*) gFile->Get(Form("dphi_%d_%d_%d", i, j+1, 0));
8948       
8949       if (!hist1)
8950         continue;
8951       
8952 //       hist1->Draw("COLZ");
8953
8954       Float_t width = 0.25;
8955
8956       proj = ((TH2*) hist1)->ProjectionY(Form("%s_projx", hist1->GetName()), hist1->GetXaxis()->FindBin(TMath::Pi() - width),hist1->GetXaxis()->FindBin(TMath::Pi() + width));
8957       
8958       proj->GetXaxis()->SetRangeUser(-1.79, 1.79);
8959       proj->SetStats(kFALSE);
8960       proj->Draw();
8961
8962       proj2 = ((TH2*) hist1)->ProjectionY(Form("%s_proj2x", hist1->GetName()), hist1->GetXaxis()->FindBin(TMath::Pi() / 2 - width),hist1->GetXaxis()->FindBin(TMath::Pi() / 2 + width));
8963
8964       proj2->GetXaxis()->SetRangeUser(-1.79, 1.79);
8965       proj2->SetLineColor(2);
8966       proj2->Draw("SAME");
8967       
8968       proj->SetMinimum(0.999 * proj2->GetMinimum());
8969     }
8970 }
8971
8972 void CheckWing()
8973 {
8974   Int_t maxLeadingPt = 3;
8975   Int_t maxAssocPt = 3;
8976
8977   TCanvas* canvas = new TCanvas("DeltaPhi", "DeltaPhi", 1000, 700);
8978   canvas->Divide(maxAssocPt, maxLeadingPt);
8979
8980 //   const char* fileNames[] = { "dphi_corr_allpt_zcentral_01.root", "dphi_corr_allpt_01.root" };
8981 //   const char* fileNames[] = { "dphi_corr_allpt_zcentral.root", "dphi_corr_allpt.root" };
8982 //   const char* fileNames[] = { "dphi_corr_allpt_zcentral.root", "dphi_corr.root" };
8983 //   const char* fileNames[] = { "dphi_corr_allpt_01_zcentral.root", "dphi_corr_allpt_01_zsumofratios.root" };
8984 //   const char* fileNames[] = { "dphi_corr_allpt_cfct_01_zcentral.root", "dphi_corr_allpt_cfct_01_zsumofratios.root" };
8985 //   const char* fileNames[] = { "dphi_corr_2d.root", "dphi_corr.root" };
8986 //   const char* fileNames[] = { "dphi_corr_2d_01.root", "dphi_corr.root" };
8987 //   const char* fileNames[] = { "dphi_corr_2d.root", "dphi_corr_2d_vtxzcentral.root" };
8988 //   const char* fileNames[] = { "dphi_corr_2d_01.root", , "dphi_corr_2d_01centr_zvtxcentral.root" }; 
8989 //   const char* fileNames[] = { "dphi_corr_10k.root", "dphi_corr_50k.root" }; 
8990 //   const char* fileNames[] = { "wing1.root", "wing2.root" }; 
8991   const char* fileNames[] = { "dphi_corr_2d_120112.root", "dphi_corr_2d_p2_111105.root" }; 
8992   
8993   for (Int_t i=0; i<maxLeadingPt; i++)
8994     for (Int_t j=0; j<maxAssocPt; j++)
8995     {
8996       canvas->cd(j+1 + i * maxAssocPt);
8997       gPad->SetLeftMargin(0.15);
8998       gPad->SetBottomMargin(0.2);
8999 //       gPad->SetTopMargin(0.01);
9000       gPad->SetRightMargin(0.01);
9001
9002       TH1* first = 0;
9003       for (Int_t fileId = 0; fileId < 2; fileId++)
9004       {
9005         TFile::Open(fileNames[fileId]);
9006   
9007         hist1 = (TH1*) gFile->Get(Form("dphi_%d_%d_%d", i, j, 3));
9008         
9009         if (!hist1)
9010           continue;
9011         
9012   //       hist1->Draw("COLZ");
9013
9014         Float_t width = 0.5;
9015         
9016         for (Int_t areaId = 0; areaId < 3; areaId++)
9017         {
9018           Float_t center = TMath::Pi() / 2 * areaId;
9019           proj = ((TH2*) hist1)->ProjectionY(Form("%s_%d_%d_projx", hist1->GetName(), fileId, areaId), hist1->GetXaxis()->FindBin(center - width), hist1->GetXaxis()->FindBin(center + width));
9020   //    proj->Rebin(2); proj->Scale(0.5);
9021           
9022           proj->GetXaxis()->SetRangeUser(-1.79, 1.79);
9023           proj->SetStats(kFALSE);
9024           proj->SetLineColor(fileId + 1 + areaId * 2);
9025           proj->Draw((fileId == 0 && areaId == 0) ? "" : "SAME");
9026           if (!first)
9027             first = proj;
9028           
9029           proj->Scale(1. / 12);
9030           
9031           first->SetMinimum(0.999 * TMath::Min(first->GetMinimum() / 0.999, proj->GetMinimum()));
9032           first->SetMaximum(1.001 * TMath::Max(first->GetMaximum() / 1.001, proj->GetMaximum()));
9033         }
9034       }
9035   }
9036 }
9037 /*
9038 void FitDeltaPhiEtaGap2D(TH2* hist, Bool_t scale, TVirtualPad* pad1, TVirtualPad* pad2, TVirtualPad* pad3, TGraphErrors* width1, TGraphErrors* width2, Float_t x, Float_t yPosChi2)
9039 {
9040   Float_t etaLimit = 1.0;
9041   Float_t outerLimit = 1.8;
9042   
9043   TString histName(hist->GetName());
9044
9045   TH1D* etaGap = hist->ProjectionX(histName + "_1", TMath::Max(1, hist->GetYaxis()->FindBin(-outerLimit + 0.01)), hist->GetYaxis()->FindBin(-etaLimit - 0.01));
9046   Int_t etaBins = hist->GetYaxis()->FindBin(-etaLimit - 0.01) - TMath::Max(1, hist->GetYaxis()->FindBin(-outerLimit + 0.01)) + 1;
9047
9048   TH1D* tracksTmp = hist->ProjectionX(histName + "_2", hist->GetYaxis()->FindBin(etaLimit + 0.01), TMath::Min(hist->GetYaxis()->GetNbins(), hist->GetYaxis()->FindBin(outerLimit - 0.01)));
9049   etaBins += TMath::Min(hist->GetYaxis()->GetNbins(), hist->GetYaxis()->FindBin(outerLimit - 0.01)) - hist->GetYaxis()->FindBin(etaLimit + 0.01) + 1;
9050   
9051   etaGap->Add(tracksTmp);
9052
9053   // get per bin result
9054   etaGap->Scale(1.0 / etaBins);
9055   
9056 //   new TCanvas; etaGap->DrawCopy();
9057   
9058   histTmp2D = (TH2*) hist->Clone("histTmp2D");
9059   histTmp2D->Reset();
9060   
9061   for (Int_t xbin=1; xbin<=histTmp2D->GetNbinsX(); xbin++)
9062     for (Int_t y=1; y<=histTmp2D->GetNbinsY(); y++)
9063       histTmp2D->SetBinContent(xbin, y, etaGap->GetBinContent(xbin));
9064     
9065   if (scale)
9066   {
9067     // mixed event does not reproduce away-side perfectly
9068     // --> extract scaling factor on the away-side from ratios of eta gap and central region
9069     TH1D* centralRegion = hist->ProjectionX(histName + "_3", hist->GetYaxis()->FindBin(-etaLimit + 0.01), hist->GetYaxis()->FindBin(etaLimit - 0.01));
9070     etaBins = hist->GetYaxis()->FindBin(etaLimit - 0.01) - hist->GetYaxis()->FindBin(-etaLimit + 0.01) + 1;
9071     centralRegion->Scale(1.0 / etaBins);
9072     
9073 //     new TCanvas; centralRegion->DrawCopy(); etaGap->SetLineColor(2); etaGap->DrawCopy("SAME");
9074     centralRegion->Divide(etaGap);
9075 //     new TCanvas; centralRegion->Draw();
9076     centralRegion->Fit("pol0", "0", "", TMath::Pi() - 1, TMath::Pi() + 1);
9077     Float_t scalingFactor = centralRegion->GetFunction("pol0")->GetParameter(0);
9078     Printf("  scalingFactor = %f", scalingFactor);
9079     histTmp2D->Scale(scalingFactor);
9080   }
9081     
9082 //   new TCanvas; hist->DrawCopy("SURF1");
9083
9084   hist->Add(histTmp2D, -1);
9085
9086 //   new TCanvas; hist->DrawCopy("SURF1");
9087
9088   hist->GetYaxis()->SetRangeUser(-1.59, 1.59);
9089   
9090   pad1->cd();
9091   hist->SetStats(0);
9092   hist->DrawCopy("SURF1");
9093   
9094   Float_t min = hist->GetMinimum();
9095   Float_t max = hist->GetMaximum();
9096   
9097   // ranges are to exclude eta gap region from fit
9098   func = new TF2("func", "[0]+[1]*exp(-0.5*((x/[2])**2+(y/[3])**2))", -5, 5, -1, 1);
9099   func->SetParameters(0, 1, 0.3, 0.3);
9100   func->SetParLimits(1, 0, 10);
9101   func->SetParLimits(2, 0.1, 10);
9102   func->SetParLimits(3, 0.1, 10);
9103   
9104   hist->Fit(func, "0R", "");
9105 //   hist->Fit(func, "IM", "SAME");
9106
9107   pad2->cd();
9108   funcHist = (TH2*) hist->Clone("funcHist");
9109   funcHist->Reset();
9110   funcHist->Add(func);
9111   funcHist->SetMinimum(min);
9112   funcHist->SetMaximum(max);
9113   funcHist->Draw("SURF1");
9114   
9115   pad3->cd();
9116   hist->Add(func, -1);
9117   hist->SetMinimum(min);
9118   hist->SetMaximum(max);
9119   hist->DrawCopy("SURF1");
9120   
9121   width1->SetPoint(width1->GetN(), x, TMath::Abs(func->GetParameter(2)));
9122   width1->SetPointError(width1->GetN()-1, 0, func->GetParError(2));
9123     
9124   width2->SetPoint(width2->GetN(), x, TMath::Abs(func->GetParameter(3)));
9125   width2->SetPointError(width2->GetN()-1, 0, func->GetParError(3));
9126
9127   Float_t chi2 = 0;
9128   Int_t ndf = 0;
9129   for (Int_t i=hist->GetXaxis()->FindBin(-0.8); i<=hist->GetXaxis()->FindBin(0.8); i++)
9130     for (Int_t j=hist->GetYaxis()->FindBin(-0.8); j<=hist->GetYaxis()->FindBin(0.8); j++)
9131     {
9132       if (hist->GetBinError(i, j) > 0)
9133       {
9134         chi2 += TMath::Power(hist->GetBinContent(i, j) / hist->GetBinError(i, j), 2);
9135         ndf++;
9136       }
9137     }
9138   ndf -= func->GetNumberFreeParameters();
9139   
9140   printf("#chi^{2}/ndf = %.1f/%d = %.1f  ", func->GetChisquare(), func->GetNDF(), func->GetChisquare() / func->GetNDF());
9141   Printf("#chi^{2}/ndf = %.1f/%d = %.1f", chi2, ndf, chi2 / ndf);
9142
9143   DrawLatex(0.5, yPosChi2, 1, Form("#chi^{2}/ndf = %.1f/%d = %.1f", func->GetChisquare(), func->GetNDF(), func->GetChisquare() / func->GetNDF()));
9144   DrawLatex(0.5, yPosChi2 - 0.05, 1, Form("#chi^{2}/ndf = %.1f/%d = %.1f", chi2, ndf, chi2 / ndf));
9145 }
9146
9147 Double_t DeltaPhiWidth2DFitFunction(Double_t *x, Double_t *par)
9148 {
9149   // params: 0: gaussian amplitude, 1: phi width, 2: eta width
9150   //         3..bins+2 constants as fct of eta
9151   
9152   Int_t etaBin = (Int_t) ((x[1] + 2.0) / 0.1);
9153   
9154   return par[3+etaBin]+par[0]*TMath::Exp(-0.5*((x[0]/par[1])**2+(x[1]/par[2])**2));
9155 }
9156
9157 void FitDeltaPhi2DOneFunction(TH2* hist, TVirtualPad* pad1, TVirtualPad* pad2, TVirtualPad* pad3, TGraphErrors* width1, TGraphErrors* width2, Float_t x, Float_t yPosChi2)
9158 {
9159   Float_t outerLimit = 1.8;
9160
9161   hist->GetYaxis()->SetRangeUser(-1.59, 1.59);
9162   
9163   pad1->cd();
9164   hist->SetStats(0);
9165   hist->DrawCopy("SURF1");
9166   
9167   Float_t min = hist->GetMinimum();
9168   Float_t max = hist->GetMaximum();
9169   
9170   Int_t bins = hist->GetNbinsX();
9171   
9172   // ranges are to exclude eta gap region from fit
9173   func = new TF2("func", DeltaPhiWidth2DFitFunction, -5, 5, -outerLimit, outerLimit, bins+3);
9174   func->SetParameters(1, 0.3, 0.3);
9175   for (Int_t i=3; i<bins+3; i++)
9176     func->SetParameter(i, 0);
9177
9178   func->SetParLimits(0, 0, 10);
9179   func->SetParLimits(1, 0.1, 10);
9180   func->SetParLimits(2, 0.1, 10);
9181   
9182   hist->Fit(func, "0R", "");
9183 //   hist->Fit(func, "IM", "SAME");
9184
9185   pad2->cd();
9186   funcHist = (TH2*) hist->Clone("funcHist");
9187   funcHist->Reset();
9188   funcHist->Add(func);
9189   funcHist->SetMinimum(min);
9190   funcHist->SetMaximum(max);
9191   funcHist->Draw("SURF1");
9192   
9193   pad3->cd();
9194   hist->Add(func, -1);
9195   hist->SetMinimum(min);
9196   hist->SetMaximum(max);
9197   hist->DrawCopy("SURF1");
9198   
9199   width1->SetPoint(width1->GetN(), x, TMath::Abs(func->GetParameter(1)));
9200   width1->SetPointError(width1->GetN()-1, 0, func->GetParError(1));
9201     
9202   width2->SetPoint(width2->GetN(), x, TMath::Abs(func->GetParameter(2)));
9203   width2->SetPointError(width2->GetN()-1, 0, func->GetParError(2));
9204
9205   Float_t chi2 = 0;
9206   Int_t ndf = 0;
9207   for (Int_t i=hist->GetXaxis()->FindBin(-0.8); i<=hist->GetXaxis()->FindBin(0.8); i++)
9208     for (Int_t j=hist->GetYaxis()->FindBin(-0.8); j<=hist->GetYaxis()->FindBin(0.8); j++)
9209     {
9210       if (hist->GetBinError(i, j) > 0)
9211       {
9212         chi2 += TMath::Power(hist->GetBinContent(i, j) / hist->GetBinError(i, j), 2);
9213         ndf++;
9214       }
9215     }
9216   ndf -= func->GetNumberFreeParameters();
9217   
9218   printf("#chi^{2}/ndf = %.1f/%d = %.1f  ", func->GetChisquare(), func->GetNDF(), func->GetChisquare() / func->GetNDF());
9219   Printf("#chi^{2}/ndf = %.1f/%d = %.1f", chi2, ndf, chi2 / ndf);
9220
9221   DrawLatex(0.5, yPosChi2, 1, Form("#chi^{2}/ndf = %.1f/%d = %.1f", func->GetChisquare(), func->GetNDF(), func->GetChisquare() / func->GetNDF()));
9222   DrawLatex(0.5, yPosChi2 - 0.05, 1, Form("#chi^{2}/ndf = %.1f/%d = %.1f", chi2, ndf, chi2 / ndf));
9223 }
9224
9225 void AnalyzeDeltaPhiEtaGap2D(const char* fileName, Int_t method)
9226 {
9227   TFile::Open(fileName);
9228   
9229   Int_t maxLeadingPt = 5;
9230   Int_t maxAssocPt = 6;
9231
9232   TGraphErrors* width1[4];
9233   TGraphErrors* width2[4];
9234   
9235   Int_t nHists = 4;
9236   for (Int_t histId = 0; histId < nHists; histId++)
9237   {
9238     width1[histId] = new TGraphErrors;
9239     width2[histId] = new TGraphErrors;
9240     for (Int_t i=0; i<maxLeadingPt; i++)
9241     {
9242       TCanvas* canvas = new TCanvas(Form("DeltaPhi_%d_%d", histId, i), Form("DeltaPhi_%d_%d", histId, i), 1000, 1000);
9243       canvas->Divide(3, maxAssocPt);
9244       
9245       for (Int_t j=0; j<maxAssocPt; j++)
9246       {
9247         for (Int_t k=1; k<=3; k++)
9248         {
9249           canvas->cd(3 * j + k);
9250           gPad->SetLeftMargin(0.15);
9251           gPad->SetBottomMargin(0.2);
9252           gPad->SetTopMargin(0.01);
9253           gPad->SetRightMargin(0.01);
9254         }
9255         
9256 //      if (i != 1 || j != 2)
9257 //        continue;
9258     
9259         hist1 = (TH1*) gFile->Get(Form("dphi_%d_%d_%d", i, j, histId));
9260         if (!hist1)
9261           continue;
9262         
9263         Float_t xPos = j*8+i;
9264
9265         if (method == 0)
9266           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);
9267         else
9268           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);
9269         
9270         break;
9271       }
9272       
9273       break;
9274     }
9275     
9276     break;
9277   }
9278   
9279   return;
9280   
9281   Int_t marker[] = { 20, 24, 25, 26 };
9282   Int_t colors[] = { 2, 2, 4, 6 };
9283   const char* labels[] = { "0-5%", "60-90%", "pp", "30-40%" };
9284   
9285   Bool_t found = kTRUE;
9286   c1 = (TCanvas*) gROOT->GetListOfCanvases()->FindObject("width_phi");
9287   if (!c1)
9288   {
9289     c1 = new TCanvas("width_phi", "width_phi", 800, 600);
9290     colors[0] = 1;
9291     found = kFALSE;
9292   }
9293   c1->cd();
9294   
9295   for (Int_t histId = 0; histId < nHists; histId++)
9296   {
9297     width1[histId]->SetMarkerStyle(marker[histId]);
9298     width1[histId]->SetMarkerColor(colors[histId]);
9299     width1[histId]->Draw((histId == 0 && !found) ? "AP" : "PSAME");
9300     DrawLatex(0.7, 0.8 - 0.05 * histId, colors[histId], labels[histId]);
9301   }
9302   
9303   found = kTRUE;
9304   c1 = (TCanvas*) gROOT->GetListOfCanvases()->FindObject("width_eta");
9305   if (!c1)
9306   {
9307     c1 = new TCanvas("width_eta", "width_eta", 800, 600);
9308     colors[0] = 1;
9309     found = kFALSE;
9310   }
9311   c1->cd();
9312   for (Int_t histId = 0; histId < nHists; histId++)
9313   {
9314     width2[histId]->SetMarkerStyle(marker[histId]);
9315     width2[histId]->SetMarkerColor(colors[histId]);
9316     width2[histId]->Draw((histId == 0 && !found) ? "AP" : "PSAME");
9317     DrawLatex(0.7, 0.8 - 0.05 * histId, colors[histId], labels[histId]);
9318   }
9319 }
9320 */
9321
9322 void RemoveWing(const char* fileName, const char* outputFile)
9323 {
9324   // 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
9325
9326   file = TFile::Open(fileName);
9327   file2 = TFile::Open(outputFile, "RECREATE");
9328   file2->Close();
9329   
9330   Int_t maxLeadingPt = 10;
9331   Int_t maxAssocPt = 11;
9332
9333   Int_t nHists = 6;
9334   for (Int_t i=0; i<maxLeadingPt; i++)
9335   {
9336     triggers = (TH1*) file->Get(Form("triggers_%d", i));
9337     if (triggers)
9338     {
9339       file2 = TFile::Open(outputFile, "UPDATE");
9340       triggers->Write();
9341       file2->Close();
9342     }
9343     for (Int_t j=0; j<maxAssocPt; j++)
9344     {
9345       for (Int_t histId = 0; histId < nHists; histId++)
9346       {
9347         hist = (TH2*) file->Get(Form("dphi_%d_%d_%d", i, j, histId));
9348         if (!hist)
9349           continue;
9350         
9351         Float_t width = 1.5;
9352         TH1* proj = hist->ProjectionY(Form("projx", hist->GetName()), hist->GetXaxis()->FindBin(TMath::Pi() - width), hist->GetXaxis()->FindBin(TMath::Pi()+ width));
9353         proj->Fit("pol0", "0");
9354         //new TCanvas; proj->DrawCopy();
9355         proj->Divide(proj->GetFunction("pol0"));
9356         //new TCanvas; proj->DrawCopy();
9357         //new TCanvas; hist->DrawCopy("SURF1");
9358         for (Int_t x=1; x<=hist->GetNbinsX(); x++)
9359           for (Int_t y=1; y<=hist->GetNbinsY(); y++)
9360           {
9361             if (proj->GetBinContent(y) <= 0)
9362               continue;
9363             hist->SetBinContent(x, y, hist->GetBinContent(x, y) / proj->GetBinContent(y));
9364             hist->SetBinError(x, y, hist->GetBinError(x, y) / proj->GetBinContent(y));
9365           }
9366         //new TCanvas; hist->DrawCopy("SURF1");
9367
9368         file2 = TFile::Open(outputFile, "UPDATE");
9369         hist->Write();
9370         file2->Close();
9371       }
9372     }
9373   }  
9374 }
9375   
9376 void RemoveWingAllSpecies()
9377 {
9378   const char* suffix[] = { "Hadrons", "Pions", "Kaons", "Protons" };
9379   TString baseName = "dphi_corr_LHC13bc_20130604_";
9380   
9381   for (Int_t i=0; i<4; i++)
9382     RemoveWing(baseName + suffix[i] + ".root", baseName + suffix[i] + "_wingremoved.root");
9383 }  
9384   
9385 void PlotPtDistributions(const char* fileName1, Int_t centrBegin = 1, Int_t centrEnd = 2)
9386 {
9387   loadlibs();
9388
9389   Int_t maxLeadingPt = 3;
9390   Float_t leadingPtArr[] = { 1.0, 10.0, 20.0, 40.0 };
9391   
9392   Int_t nCentralityBins = 5;
9393   Int_t centralityBins[] = { 1, 7, 9, 11, 13, 16 };
9394   
9395   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName1);
9396     
9397   TCanvas* canvas = new TCanvas("Pt", "Pt", 1000, 1000);
9398   canvas->Divide(2, maxLeadingPt+2);
9399   
9400   TLegend* legend = new TLegend(0.2, 0.2, 0.95, 0.90);
9401   legend->SetFillColor(0);
9402   legend->SetTextSize(0.08);
9403   
9404   TLegend* legendB = new TLegend(0.2, 0.2, 0.95, 0.90);
9405   legendB->SetFillColor(0);
9406   legendB->SetTextSize(0.08);
9407   
9408   TLegend* legend2 = new TLegend(0.2, 0.2, 0.95, 0.90);
9409   legend2->SetFillColor(0);
9410   legend2->SetTextSize(0.08);
9411   
9412   Int_t colors[] = { 1, 2, 4, 6 };
9413   Int_t markers[] = { 20, 21, 22, 23, 24, 25 };
9414   
9415   for (Int_t i=0; i<maxLeadingPt; i++)
9416   {
9417     Double_t ptMin = leadingPtArr[i] + 0.01;
9418     //Double_t ptMax = leadingPtArr[i+1] - 0.01;
9419     Double_t ptMax = 39.99;
9420       
9421     TString str;
9422     str.Form("%.1f < p_{T,trig} < %.1f", ptMin - 0.01, ptMax + 0.01);
9423     
9424     canvas->cd(2*i+1+2);
9425     gPad->SetLeftMargin(0.15);
9426     gPad->SetBottomMargin(0.2);
9427     gPad->SetTopMargin(0.01);
9428     gPad->SetRightMargin(0.01);
9429     gPad->SetLogy();
9430     gPad->SetLogx();
9431     gPad->SetGridx();
9432     gPad->SetGridy();
9433     
9434     TH2F* dummy = new TH2F("dummy", "", 100, 1, 40, 100, 1e-5, 1e3);
9435     dummy->SetStats(kFALSE);
9436     dummy->SetXTitle("p_{T,assoc}");
9437     dummy->SetYTitle("");
9438     dummy->GetYaxis()->SetTitleOffset(1);
9439     Prepare1DPlot(dummy);
9440   
9441     dummy->GetXaxis()->SetLabelSize(0.06);
9442     dummy->GetYaxis()->SetLabelSize(0.06);
9443     dummy->GetXaxis()->SetTitleSize(0.06);
9444     dummy->GetYaxis()->SetTitleSize(0.06);
9445     dummy->DrawCopy();
9446     
9447     Float_t phiRange[] = { 0, TMath::Pi() / 2, TMath::Pi() };
9448     const char* phiLabels[] = { "Towards", "Transverse", "Away" };
9449     
9450     for (Int_t j=0; j<3; j++)
9451     {
9452       TH1* centralEta = 0;
9453       TH1* sideEta1 = 0;
9454       
9455       if (j == 0)
9456       {
9457         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);
9458         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);
9459         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);
9460         sideEta1->Add(sideEta2); // TODO can be done smarter? what about the errors?
9461       
9462         Prepare1DPlot(sideEta1);
9463         Prepare1DPlot(centralEta);
9464         
9465         centralEta->SetLineColor(colors[j]);
9466         sideEta1->SetLineColor(colors[j+1]);
9467       
9468         if (i == 0)
9469         {
9470           legend->AddEntry(centralEta->Clone(), Form("Jet, %s: |#eta| < 0.7, #phi ~ %.1f", phiLabels[j], phiRange[j]));
9471           legend->AddEntry(sideEta1->Clone(), Form("Ridge, %s: 0.7 < |#eta| < 1.4, #phi ~ %.1f", phiLabels[j], phiRange[j]));
9472         }
9473       }
9474       else
9475       {
9476         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);
9477         centralEta->Scale(0.5);
9478         centralEta->SetLineColor(colors[j+1]);
9479       
9480         Prepare1DPlot(centralEta);
9481         
9482         if (i == 0)
9483           legend->AddEntry(centralEta->Clone(), Form("%s: |#eta| < 1.4, #phi ~ %.1f", phiLabels[j], phiRange[j]));
9484       }
9485       
9486       canvas->cd(2*i+1+2);
9487       centralEta->DrawCopy("SAME");
9488       if (sideEta1)
9489         sideEta1->DrawCopy("SAME");
9490       
9491       centralEta->SetLineColor(colors[i]);
9492       centralEta->Scale(100.0 / centralEta->Integral());
9493       if (sideEta1)
9494       {
9495         sideEta1->SetLineColor(colors[i]);
9496         sideEta1->Scale(100.0 / sideEta1->Integral());
9497       }
9498     
9499       if (j < 2)
9500         canvas->cd(j*4+4);
9501       else
9502         canvas->cd(j*4+2);
9503       if (i == 0)
9504       {
9505         gPad->SetLeftMargin(0.15);
9506         gPad->SetBottomMargin(0.2);
9507         gPad->SetTopMargin(0.01);
9508         gPad->SetRightMargin(0.01);
9509         
9510         dummy->DrawCopy();
9511         
9512         gPad->SetLogy();
9513         gPad->SetLogx();
9514         gPad->SetGridx();
9515         gPad->SetGridy();
9516         
9517         TString str3;
9518         if (j == 0)
9519           str3.Form("Jet, %s: |#eta| < 0.7, #phi ~ %.1f", phiLabels[j], phiRange[j]);
9520         else
9521           str3.Form("%s: |#eta| < 1.4, #phi ~ %.1f", phiLabels[j], phiRange[j]);
9522         latex = new TLatex(0.2, 0.3, str3);
9523         latex->SetNDC();
9524         latex->SetTextSize(0.08);
9525         latex->Draw();
9526       }
9527       
9528       if (j == 0)
9529         legend2->AddEntry(centralEta->Clone(), str);
9530         
9531       centralEta->DrawCopy("SAME");
9532       
9533       if (sideEta1)
9534       {
9535         canvas->cd(j*4+4+2);
9536         if (i == 0)
9537         {
9538           gPad->SetLeftMargin(0.15);
9539           gPad->SetBottomMargin(0.2);
9540           gPad->SetTopMargin(0.01);
9541           gPad->SetRightMargin(0.01);
9542           
9543           dummy->DrawCopy();
9544           
9545           gPad->SetLogy();
9546           gPad->SetLogx();
9547           gPad->SetGridx();
9548           gPad->SetGridy();
9549           
9550           TString str3;
9551           if (j == 0)
9552             str3.Form("Ridge, %s: 0.7 < |#eta| < 1.4, #phi ~ %.1f", phiLabels[j], phiRange[j]);
9553           else
9554             str3.Form("%s: |#eta| < 1.4, #phi ~ %.1f", phiLabels[j], phiRange[j]);
9555           latex = new TLatex(0.2, 0.3, str3);
9556           latex->SetNDC();
9557           latex->SetTextSize(0.08);
9558           latex->Draw();
9559         }
9560         
9561         sideEta1->DrawCopy("SAME");
9562       }
9563     }
9564     
9565     TString str3;
9566     str3.Form("%d-%d%%", (Int_t) h->GetCentralityDistribution()->GetXaxis()->GetBinLowEdge(centrBegin), (Int_t) h->GetCentralityDistribution()->GetXaxis()->GetBinUpEdge(centrEnd));
9567     latex = new TLatex(0.2, 0.3, str3);
9568     latex->SetNDC();
9569     latex->SetTextSize(0.08);
9570     
9571     latex2 = new TLatex(0.55, 0.8, str);
9572     latex2->SetNDC();
9573     latex2->SetTextSize(0.06);
9574     
9575     canvas->cd(2*i+1+2);
9576     latex->Draw();
9577     latex2->Draw();
9578     
9579     //break;
9580   }
9581   
9582   canvas->cd(1);
9583   legend->Draw();
9584
9585   canvas->cd(2);
9586   legend2->Draw();
9587 }
9588
9589 TH1* GetNonSubtractedRHICYield(Int_t ptT, Int_t ptA, Int_t centrality)
9590 {
9591   rhicFile = TFile::Open("rhic/postcorr_AuAu_iter6_ppg106final.root");
9592   
9593   corrFunc = (TH1*) rhicFile->Get(Form("pi0hdphi_%d_%d_%d_2", ptT, ptA, centrality));
9594   //corrFunc->Draw();
9595   
9596   // integral
9597   corrFunc->Scale(1.0 / corrFunc->Integral());
9598   // bin width
9599   corrFunc->Scale(TMath::TwoPi() / corrFunc->GetBinWidth(1));
9600   
9601   same     = (TH1*) rhicFile->Get(Form("pi0hdphi_%d_%d_%d_0", ptT, ptA, centrality));
9602   Float_t nPairs = same->Integral();
9603   
9604   triggers = (TH1*) rhicFile->Get(Form("pi0pt_%d_%d", ptT, centrality));
9605   Float_t nTrigs = triggers->Integral();
9606   
9607   graph = (TGraph*) rhicFile->Get(Form("gS_%d_%d", ptT, centrality));
9608   
9609   Printf("%f %f %f %f", nPairs, nTrigs, nPairs / nTrigs, graph->GetY()[ptA]);
9610   
9611   corrFunc->Scale(nPairs / nTrigs);
9612  
9613   //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))));
9614   
9615   Float_t values[3];
9616   Float_t errors[3];
9617   
9618   Float_t regionBegin[3] = { -TMath::Pi() / 2,        TMath::Pi() / 2 - 0.4, 1.5 * TMath::Pi() - 0.4 };
9619   Float_t regionEnd[3] =   { -TMath::Pi() / 2 + 0.4,  TMath::Pi() / 2 + 0.4, 1.5 * TMath::Pi() };
9620     
9621   // weighted mean
9622   Float_t sum = 0;
9623   Float_t weight = 0;
9624   for (Int_t i=0; i<3; i++)
9625   {
9626     corrFunc->Fit("pol0", "0Q", "", regionBegin[i], regionEnd[i]);
9627     func = corrFunc->GetFunction("pol0");
9628     if (!func)
9629       continue;
9630     sum += func->GetParameter(0) / func->GetParError(0) / func->GetParError(0);
9631     weight += 1. / func->GetParError(0) / func->GetParError(0);
9632   }
9633   
9634   if (weight == 0)
9635     return 0;
9636   
9637   sum /= weight;
9638   weight = TMath::Sqrt(1. / weight);
9639   
9640   corrFunc->Add(new TF1("func", "1", -5, 5), -sum);
9641   
9642   return corrFunc;
9643   
9644   new TCanvas;
9645   corrFunc->Draw();
9646   compHist = (TH1*) rhicFile->Get(Form("ptyMSMP_0_%d%d%d", ptT, ptA, centrality));
9647   compHist->DrawCopy("SAME");
9648   
9649   //compHist->Add((TF1*) compHist->GetListOfFunctions()->First());
9650   //compHist->DrawCopy("SAME");
9651 }
9652   
9653 void DeltaPhiVsRHIC(Int_t rhicCentrality = 0, Int_t aliceCentrality = 0, Bool_t reduced = kFALSE)
9654 {
9655   aliceFile = TFile::Open("alice_dphi_corr_rhicbinning.root");
9656   rhicFile = TFile::Open("rhic/postcorr_AuAu_iter6_ppg106final.root");
9657
9658   Int_t maxLeadingPt = 4;
9659   Int_t maxAssocPt = 5;
9660   
9661   if (reduced)
9662   {
9663     Int_t maxSelected = 4;
9664     Int_t selectedLead[] = { 0, 0, 2, 2 };
9665     Int_t selectedAssoc[] = { 1, 2, 3, 4 };
9666    
9667     maxLeadingPt = TMath::Sqrt(maxSelected);
9668     maxAssocPt = TMath::Sqrt(maxSelected);
9669   }
9670     
9671   TCanvas* canvas = new TCanvas("DeltaPhi", "DeltaPhi", 1000, 700);
9672   canvas->Divide(maxAssocPt, maxLeadingPt);
9673   
9674   for (Int_t i=0; i<maxLeadingPt; i++)
9675     for (Int_t j=0; j<maxAssocPt; j++)
9676     {
9677       Printf("%d %d", i, j);
9678     
9679       canvas->cd(j+1 + i * maxAssocPt);
9680       gPad->SetLeftMargin(0.15);
9681       gPad->SetBottomMargin(0.2);
9682       //gPad->SetTopMargin(0.01);
9683       gPad->SetRightMargin(0.01);
9684       
9685       Int_t iSel = i;
9686       Int_t jSel = j;
9687       
9688       if (reduced)
9689       {
9690         iSel = selectedLead[j + i * maxAssocPt];
9691         jSel = selectedAssoc[j + i * maxAssocPt];
9692       }
9693       
9694       //rhic = (TH1*) rhicFile->Get(Form("VptyMSMP_0_%d%d%d", iSel, jSel, rhicCentrality));
9695       rhic = GetNonSubtractedRHICYield(iSel, jSel, rhicCentrality);
9696       if (!rhic)
9697         continue;
9698       rhic->SetLineColor(2);
9699       rhic->SetMarkerStyle(1);
9700       
9701       alice = (TH1*) aliceFile->Get(Form("dphi_%d_%d_%d_fit_flat", iSel, jSel, aliceCentrality));
9702       if (!alice)
9703         continue;
9704         
9705       // match near side yield
9706       if (1)
9707       {
9708         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));
9709         
9710         Printf("%f", factor);
9711         rhic->Scale(factor);
9712       }
9713         
9714       alice->SetLineColor(1);
9715         
9716       //alice->Rebin(36); rhic->Rebin(30);
9717       
9718       clone = alice->DrawCopy("");
9719       rhic->DrawCopy("SAME");
9720       
9721       //Printf("chi2 test: chi2/ndf = %f", alice->Chi2Test(rhic, "WW CHI2/NDF"));
9722       Float_t chi2 = 0;
9723       Float_t n = 0;
9724       for (Int_t k=1; k<=rhic->GetNbinsX(); k++)
9725       {
9726         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));
9727         n++;
9728       }
9729       
9730       chi2 /= n;
9731       Printf("chi2 test: chi2/ndf = %f", chi2);      
9732       
9733       clone->GetYaxis()->SetRangeUser(TMath::Min(alice->GetMinimum(), rhic->GetMinimum()) * 1.1, TMath::Max(alice->GetMaximum(), rhic->GetMaximum()) * 1.1);
9734       
9735       for (Int_t bin=1; bin<=rhic->GetNbinsX(); bin++)
9736       {
9737         Double_t aliceValue = alice->GetBinContent(alice->FindBin(rhic->GetXaxis()->GetBinCenter(bin)));
9738         if (aliceValue == 0)
9739           continue;
9740         rhic->SetBinContent(bin, rhic->GetBinContent(bin) / aliceValue);
9741         rhic->SetBinError(bin, 0);
9742       }
9743       
9744       rhic->Rebin(2);
9745       rhic->Scale(0.5);
9746       
9747       rhic->SetLineColor(3);
9748       //rhic->DrawCopy("SAME");
9749       
9750       //return;
9751     }
9752     
9753     canvas->SaveAs("yield_comparison.png");
9754 }
9755   
9756 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")
9757 {
9758   // DeltaPhi("high_stat_binning_pp7_pt8.root", "high_stat_binning_pp7_pythia_pt8.root", 0, 1, 0, "pp 7 TeV uncorrected")
9759   // DeltaPhi("high_stat_binning_pp900_pt8.root", "high_stat_binning_pp900_pythia_pt8.root", 0, 1, 0, "pp 0.9 TeV uncorrected")
9760
9761   style(2);
9762
9763   aliceFile = TFile::Open(fileName);
9764   if (fileName2)
9765     secondFile = TFile::Open(fileName2);
9766
9767   if (1)
9768   {
9769     Int_t maxLeadingPt = 3;
9770     Int_t maxAssocPt = 3;
9771   }
9772   else
9773   {
9774     Int_t maxLeadingPt = 3;
9775     Int_t maxAssocPt = 7;
9776   }
9777   
9778   if (reduced)
9779   {
9780     Int_t maxSelected = 4;
9781     Int_t selectedLead[] = { 1, 1, 1, 1 };
9782     Int_t selectedAssoc[] = { 2, 3, 4, 5 };
9783    
9784     maxLeadingPt = TMath::Sqrt(maxSelected);
9785     maxAssocPt = TMath::Sqrt(maxSelected);
9786   }
9787   
9788   factorGraph = new TGraphErrors;
9789     
9790 //   TCanvas* canvas = new TCanvas(Form("%s_%s", fileName, fileName2 ? fileName2 : ""), Form("%s_%s", fileName, fileName2 ? fileName2 : ""), 600, 900);
9791   TCanvas* canvas = new TCanvas(Form("%s_%s", fileName, fileName2 ? fileName2 : ""), Form("%s_%s", fileName, fileName2 ? fileName2 : ""), 1000, 1000);
9792   canvas->Divide(maxAssocPt, maxLeadingPt);
9793   
9794   for (Int_t i=0; i<maxLeadingPt; i++)
9795     for (Int_t j=0; j<maxAssocPt; j++)
9796     {
9797       TH1* first = 0;
9798       TH1* peripheral = 0;
9799       for (Int_t aliceCentrality=0; aliceCentrality<4; aliceCentrality++)
9800       {
9801         Printf("%d %d %d", i, j, aliceCentrality);
9802         
9803         if (aliceCentrality == 1)
9804           continue;
9805       
9806         canvas->cd(j+1 + i * maxAssocPt);
9807         
9808         Int_t iSel = i;
9809         Int_t jSel = j;
9810         Int_t centralitySel = aliceCentrality;
9811         currentFile = aliceFile;
9812         
9813         if (reduced)
9814         {
9815           iSel = selectedLead[j + i * maxAssocPt];
9816           jSel = selectedAssoc[j + i * maxAssocPt];
9817         }
9818         
9819         if (fileName2)
9820         {
9821           if (ppComparison)
9822           {
9823             centralitySel = 3;
9824             if (aliceCentrality == 1)
9825               currentFile = secondFile;
9826             else if (aliceCentrality == 2)
9827               break;
9828           }
9829           else
9830             if (aliceCentrality == 3)
9831               currentFile = secondFile;
9832         }
9833         
9834         //alice = (TH1*) currentFile->Get(Form("dphi_%d_%d_%d%s", iSel, jSel, centralitySel, (centralitySel < 3) ? "_tsallis_flat" : ((flatOrTsallis) ? "" : "_fit_flat")));
9835         alice = (TH1*) currentFile->Get(Form("dphi_%d_%d_%d%s", iSel, jSel, centralitySel, histName));
9836         if (!alice)
9837           continue;
9838
9839         if (0)
9840         {
9841           Printf("WARNING: Applying some scaling and rebinning! Only for 2.76 data-MC comparison!");
9842           if (aliceCentrality == 0)
9843           {
9844             alice->Rebin(2); alice->Scale(0.5); 
9845           alice->Scale(1.0 / 1.6);
9846           }
9847 //        else
9848 //          alice->Scale(1.6);
9849         }
9850         
9851             alice->Rebin(2); alice->Scale(0.5); 
9852 //          alice->Scale(1.0 / 1.6);
9853
9854         // match near side yield to peripheral
9855         if (1 && centralitySel == 3 && peripheral)
9856         {
9857          if (mode == 0 || mode == 1)
9858           {
9859             Double_t width = 0.5;
9860             Double_t error1, error2;
9861             Double_t integral1 = peripheral->IntegralAndError(peripheral->FindBin(-width), peripheral->FindBin(width), error1);
9862             Double_t integral2 = alice->IntegralAndError(alice->FindBin(-width), alice->FindBin(width), error2);
9863             if (mode == 1)
9864             {
9865               Double_t tmpErr = 0;
9866               integral1 += peripheral->IntegralAndError(peripheral->FindBin(TMath::Pi() - width), peripheral->FindBin(TMath::Pi() + width), tmpErr);
9867               error1 = TMath::Sqrt(error1 * error1 + tmpErr * tmpErr);
9868               
9869               integral2 += alice->IntegralAndError(alice->FindBin(TMath::Pi() - width), alice->FindBin(TMath::Pi() + width), tmpErr);
9870               error2 = TMath::Sqrt(error2 * error2 + tmpErr * tmpErr);
9871             }
9872           }
9873           else if (mode == 2)
9874           {
9875             Double_t error1, error2;
9876             Double_t integral1 = peripheral->IntegralAndError(1, peripheral->GetNbinsX(), error1);
9877             Double_t integral2 = alice->IntegralAndError(1, alice->GetNbinsX(), error2);
9878           }
9879           else if (mode == 3)
9880           {
9881             Double_t width = 1.0;
9882             Double_t error1, error2;
9883             Double_t integral1 = peripheral->IntegralAndError(peripheral->FindBin(TMath::Pi() - width), peripheral->FindBin(TMath::Pi() + width), error1);
9884             Double_t integral2 = alice->IntegralAndError(alice->FindBin(TMath::Pi() - width), alice->FindBin(TMath::Pi() + width), error2);
9885           }
9886             
9887           Double_t factor = integral1 / integral2;
9888           
9889           //factor = 0.804 * 0.9;
9890           Printf("%f", factor);
9891 //           alice->Scale(factor);
9892           factorGraph->SetPoint(factorGraph->GetN(), factorGraph->GetN(), factor);
9893           factorGraph->SetPointError(factorGraph->GetN() - 1, 0, factor * TMath::Sqrt(TMath::Power(error1 / integral1, 2) + TMath::Power(error2 / integral2, 2)));
9894         }
9895         
9896         if (ppComparison && aliceCentrality == 0)
9897           peripheral = alice;
9898         else if (aliceCentrality == 2)
9899           peripheral = alice;          
9900           
9901 //         alice->SetYTitle("1/(N_{trig} #Delta#eta) dN_{assoc}/d#Delta#phi (1/rad)");
9902         alice->SetYTitle("1/N_{trig} dN_{assoc}/d#Delta#phi (1/rad)");
9903         alice->SetXTitle("#Delta#phi (rad)");
9904         alice->SetLineColor(aliceCentrality+1);
9905         alice->SetLineWidth(2);
9906         alice->SetMarkerColor(aliceCentrality+1);
9907         alice->GetYaxis()->SetTitleOffset(1.7);
9908         clone = alice->DrawCopy((aliceCentrality > 0) ? "SAME" : "");
9909         clone->SetTitle("");
9910         
9911         TString str(alice->GetTitle());
9912         str.ReplaceAll(" - ", "#");
9913         tokens = str.Tokenize("#");
9914           
9915         if (aliceCentrality == 0)
9916         {
9917           for (Int_t k=0; k<2; k++)
9918           {
9919             TString str(tokens->At(k)->GetName());
9920             str.ReplaceAll(".0", "");
9921             str.ReplaceAll("< p", "GeV/c < p");
9922             str += " GeV/c";
9923             latex = new TLatex(0.48, 0.92-k*0.06, str);
9924             latex->SetNDC();
9925             latex->SetTextSize(0.04);
9926             latex->Draw();
9927           }
9928           
9929         }
9930         
9931         if (!first)
9932           first = clone;
9933         else
9934           first->GetYaxis()->SetRangeUser(TMath::Min(first->GetMinimum(), clone->GetMinimum()), TMath::Max(first->GetMaximum(), clone->GetMaximum()));
9935           
9936         
9937           
9938         //return;
9939       }
9940       if (first)
9941         //first->GetYaxis()->SetRangeUser(first->GetMinimum(), first->GetMaximum() * 1.2);
9942         first->GetYaxis()->SetRangeUser(first->GetMinimum(), first->GetMaximum() * 1.5);
9943     }
9944     
9945   if (0)
9946   {
9947     for (Int_t i=1; i<=6; i++)
9948     {
9949       canvas->cd(i);
9950       
9951       latex = new TLatex(0.58, 0.8, "ALICE preliminary");
9952       latex->SetTextSize(0.04);
9953       latex->SetNDC();
9954       latex->Draw();
9955     
9956       latex = new TLatex(0.58, 0.74, Form("%s", dataTag));
9957       latex->SetTextSize(0.04);
9958       latex->SetNDC();
9959       latex->Draw();
9960       
9961       latex = new TLatex(0.58, 0.68, "Stat. uncertainties only");
9962       latex->SetTextSize(0.04);
9963       latex->SetNDC();
9964       latex->Draw();
9965     
9966       latex = new TLatex(0.58, 0.62, "|#eta| < 0.8");
9967       latex->SetTextSize(0.04);
9968       latex->SetNDC();
9969       latex->Draw();
9970     
9971       if (ppComparison)
9972       {
9973         legend = new TLegend(0.3, 0.8, 0.47, 0.95);
9974         legend->SetFillColor(0);
9975         legend->SetTextSize(0.04);
9976         legend->AddEntry(peripheral, "Data");
9977         legend->AddEntry(alice, "Pythia");
9978         legend->Draw();
9979       }
9980
9981       DrawALICELogo(0.75, 0.47, 0.95, 0.6);
9982     }
9983   }
9984   
9985   canvas->SaveAs(Form("%s.eps", canvas->GetName()));
9986   canvas->SaveAs(Form("%s.png", canvas->GetName()));
9987     
9988   new TCanvas;
9989   peripheral->Divide(alice);
9990   peripheral->DrawCopy();
9991   //alice->DrawCopy("SAME");
9992   
9993     
9994   graphCanvas = (TCanvas*) gROOT->GetListOfCanvases()->FindObject("graphCanvas");
9995   factorGraph->SetMarkerStyle(20);
9996   if (!graphCanvas)
9997   {
9998     graphCanvas = new TCanvas("graphCanvas", "graphCanvas", 800, 600);
9999     factorGraph->Draw("AP");
10000   }
10001   else
10002   {
10003     graphCanvas->cd();
10004     factorGraph->SetLineColor(2);
10005     factorGraph->SetMarkerColor(2);
10006     factorGraph->Draw("SAMEP");
10007   }
10008   factorGraph->GetYaxis()->SetRangeUser(0.6, 1.4);
10009   
10010   factorGraph->Print();
10011 }
10012
10013 void ComparePPYields(const char* histName = "_fit_flat")
10014 {
10015   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" };
10016   const char* titles[] = { "0.9 data", "0.9 Pythia", "2.76 Pythia", "7 Pythia", "7 data" };
10017   
10018   Int_t colors[] = { 1, 2, 3, 4, 6 };
10019   
10020   Int_t maxLeadingPt = 3;
10021   Int_t maxAssocPt = 2;
10022   
10023   TCanvas* canvas = new TCanvas("ComparePPYields", "ComparePPYields", 600, 900);
10024   canvas->Divide(maxAssocPt, maxLeadingPt);
10025   
10026   legend = new TLegend(0.5, 0.5, 0.8, 0.8);
10027   legend->SetFillColor(0);
10028   
10029   TGraphErrors** graphs = new TGraphErrors*[5];
10030   TGraphErrors** graphs2 = new TGraphErrors*[5];
10031       
10032   for (Int_t nFiles = 0; nFiles < 5; nFiles++)
10033   {
10034     graphs[nFiles] = new TGraphErrors;
10035     graphs2[nFiles] = new TGraphErrors;
10036   }
10037   
10038   for (Int_t i=0; i<maxLeadingPt; i++)
10039     for (Int_t j=0; j<maxAssocPt; j++)
10040     {
10041       canvas->cd(j+1 + i * maxAssocPt);
10042       gPad->SetLeftMargin(0.18);
10043       gPad->SetBottomMargin(0.1);
10044       gPad->SetTopMargin(0.01);
10045       gPad->SetRightMargin(0.01);
10046         
10047       TH1* first = 0;
10048         
10049       for (Int_t nFiles = 0; nFiles < 5; nFiles++)
10050       {
10051         currentFile = TFile::Open(files[nFiles]);
10052
10053         Int_t aliceCentrality = 3;
10054           
10055         Printf("%d %d %d", i, j, nFiles);
10056       
10057         alice = (TH1*) currentFile->Get(Form("dphi_%d_%d_%d%s", i, j, aliceCentrality, histName));
10058         if (!alice)
10059           continue;
10060           
10061         alice->SetYTitle("1/N_{trig} dN/dp_{T,assoc}");
10062         alice->SetLineColor(colors[nFiles]);
10063         alice->SetMarkerColor(colors[nFiles]);
10064         alice->GetYaxis()->SetTitleOffset(1.7);
10065         clone = alice->DrawCopy((nFiles > 0) ? "SAME" : "");
10066         clone->SetTitle("");
10067         
10068         Double_t width = 0.7;
10069         Double_t error, error2;
10070         Double_t integral = alice->IntegralAndError(alice->FindBin(-width), alice->FindBin(width), error);
10071         Double_t integral2 = alice->IntegralAndError(alice->FindBin(TMath::Pi() - width), alice->FindBin(TMath::Pi() + width), error2);
10072         
10073         graphs[nFiles]->SetPoint(graphs[nFiles]->GetN(), j + i * maxAssocPt - 0.2, integral);
10074         graphs[nFiles]->SetPointError(graphs[nFiles]->GetN()-1, 0, error);
10075         
10076         graphs2[nFiles]->SetPoint(graphs2[nFiles]->GetN(), j + i * maxAssocPt + 0.2, integral2);
10077         graphs2[nFiles]->SetPointError(graphs2[nFiles]->GetN()-1, 0, error2);
10078         
10079         if (!first)
10080           first = clone;
10081         else
10082           first->GetYaxis()->SetRangeUser(TMath::Min(first->GetMinimum(), clone->GetMinimum()), TMath::Max(first->GetMaximum(), clone->GetMaximum()));
10083           
10084         if (nFiles == 0)
10085         {
10086           TString str(alice->GetTitle());
10087           str.ReplaceAll(" - ", "#");
10088           tokens = str.Tokenize("#");
10089             
10090           for (Int_t k=0; k<2; k++)
10091           {
10092             latex = new TLatex(0.6, 0.88-k*0.07, tokens->At(k)->GetName());
10093             latex->SetNDC();
10094             latex->SetTextSize(0.04);
10095             latex->Draw();
10096           }
10097         }
10098           
10099         if (i == 0 && j == 0)
10100           legend->AddEntry(clone, titles[nFiles]);
10101       }
10102       if (first)
10103         first->GetYaxis()->SetRangeUser(first->GetMinimum(), first->GetMaximum() * 1.1);
10104     }
10105     
10106   canvas->cd(1);
10107   
10108   legend->Draw();
10109   
10110   new TCanvas;
10111   for (Int_t nFiles = 0; nFiles < 5; nFiles++)
10112   {
10113     graphs[nFiles]->SetMarkerStyle(25);
10114     graphs[nFiles]->SetLineColor(colors[nFiles]);
10115     graphs[nFiles]->SetMarkerColor(colors[nFiles]);
10116     clone2 = (TGraphErrors*) graphs[nFiles]->DrawClone((nFiles == 0) ? "AP" : "PSAME");
10117     clone2->GetYaxis()->SetRangeUser(0, 5);
10118   
10119     graphs2[nFiles]->SetMarkerStyle(26);
10120     graphs2[nFiles]->SetLineColor(colors[nFiles]);
10121     graphs2[nFiles]->SetMarkerColor(colors[nFiles]);
10122     graphs2[nFiles]->DrawClone("PSAME");
10123   }  
10124
10125   new TCanvas;
10126   for (Int_t nFiles = 0; nFiles < 5; nFiles++)
10127   {
10128     DivideGraphs(graphs[nFiles], graphs[4]);
10129     DivideGraphs(graphs2[nFiles], graphs2[4]);
10130     
10131     graphs[nFiles]->SetMarkerStyle(25);
10132     graphs[nFiles]->SetLineColor(colors[nFiles]);
10133     graphs[nFiles]->SetMarkerColor(colors[nFiles]);
10134     clone2 = (TGraphErrors*) graphs[nFiles]->DrawClone((nFiles == 0) ? "AP" : "PSAME");
10135     clone2->GetYaxis()->SetRangeUser(0, 1.5);
10136   
10137     graphs2[nFiles]->SetMarkerStyle(26);
10138     graphs2[nFiles]->SetLineColor(colors[nFiles]);
10139     graphs2[nFiles]->SetMarkerColor(colors[nFiles]);
10140     graphs2[nFiles]->DrawClone("PSAME");
10141   }  
10142 }
10143
10144 void DeltaPhiPreliminary(const char* fileName, const char* histName)
10145 {
10146   style(2);
10147
10148   currentFile = TFile::Open(fileName);
10149
10150   TCanvas* canvas = new TCanvas(Form("dphi%s", histName), "dphi", 800, 800);
10151   canvas->Divide(2, 2);
10152   
10153   TLegend* legend = new TLegend(0.55, 0.47, 0.85, 0.65);
10154   legend->SetFillColor(0);
10155   legend->SetTextSize(0.04);
10156   
10157   Int_t colors[] = { 1, 2, 4, 6 };
10158   
10159   Int_t pad = 1;
10160   for (Int_t i=1; i<2; i++)
10161     for (Int_t j=2; j<6; j++)
10162     {
10163       canvas->cd(pad++);
10164   
10165       for (Int_t aliceCentrality=0; aliceCentrality<3; aliceCentrality+=2)
10166       {
10167         Printf("%d %d %d", i, j, aliceCentrality);
10168       
10169         hist = (TH1*) currentFile->Get(Form("dphi_%d_%d_%d%s", i, j, aliceCentrality, histName));
10170         if (!hist)
10171           continue;
10172           
10173         if (aliceCentrality == 3)
10174           hist->Scale(kPythiaScalingFactor);
10175           
10176         hist->GetYaxis()->SetTitleOffset(1.9);
10177         hist->SetLineColor(colors[aliceCentrality]);
10178         hist->SetMarkerColor(colors[aliceCentrality]);
10179         hist->SetLineWidth(2);
10180         hist->SetYTitle("1/N_{trig} dN_{assoc}/d#Delta#phi");
10181         hist->SetXTitle("#Delta#phi (rad)");
10182         
10183         clone = hist->DrawCopy((aliceCentrality > 0) ? "SAME" : "");
10184         clone->SetTitle("");
10185         
10186         TString str(hist->GetTitle());
10187         str.ReplaceAll(" - ", "#");
10188         tokens = str.Tokenize("#");
10189         hist->SetTitle("");
10190           
10191         if (aliceCentrality == 0)
10192         {
10193           for (Int_t k=0; k<2; k++)
10194           {
10195             TString str(tokens->At(k)->GetName());
10196             str.ReplaceAll(".0", "");
10197             str.ReplaceAll("< p", "GeV/c < p");
10198             str += " GeV/c";
10199           
10200             latex = new TLatex(0.5, 0.88-k*0.06, str);
10201             latex->SetNDC();
10202             latex->SetTextSize(0.04);
10203             latex->Draw();
10204           }
10205           
10206           latex = new TLatex(0.5, 0.76, "ALICE preliminary");
10207           latex->SetTextSize(0.04);
10208           latex->SetNDC();
10209           latex->Draw();
10210         
10211           latex = new TLatex(0.5, 0.70, "Stat. uncertainties only");
10212           latex->SetTextSize(0.04);
10213           latex->SetNDC();
10214           latex->Draw();
10215
10216           clone->GetYaxis()->SetRangeUser(0, clone->GetMaximum() * 1.2);
10217         }
10218         
10219         if (pad == 2)
10220         {
10221           if (aliceCentrality == 3)
10222             legend->AddEntry(hist, "Pythia");
10223           else
10224             legend->AddEntry(hist, tokens->At(2)->GetName());
10225         }
10226         
10227         legend->Draw();
10228         
10229       }
10230     }
10231     
10232   canvas->cd(3);
10233   
10234   canvas->SaveAs(Form("%s.eps", canvas->GetName()));
10235   canvas->SaveAs(Form("%s.png", canvas->GetName()));
10236 }
10237
10238 void DeltaPhiBaseLinePreliminary(const char* fileName)
10239 {
10240   style(2);
10241   
10242   loadlibs();
10243
10244   Float_t leadingPtArr[] = { 6.0, 8.0, 10.0, 15.0, 15.0 };
10245   Float_t assocPtArr[] =     { 0.5, 1.5, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
10246   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
10247
10248   Int_t i = 1;
10249   Int_t j = 3;
10250   Int_t step = 0;
10251
10252   gpTMin = assocPtArr[j] + 0.01;
10253   gpTMax = assocPtArr[j+1] - 0.01;
10254   SetupRanges(h);
10255       
10256   TString str;
10257   str.Form("%.0f GeV/c < p_{T,trig} < %.0f GeV/c", leadingPtArr[i], leadingPtArr[i+2]);
10258   
10259   TString str2;
10260   str2.Form("%.0f GeV/c < p_{T,assoc} < %.0f GeV/c", gpTMin - 0.01, gpTMax + 0.01);
10261           
10262   Float_t v2[3];
10263   TH1* hist1 = 0;
10264   TH1* hist2b = 0;
10265   
10266   GetDistAndFlow(h, 0, &hist1,  v2, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+2] - 0.01); 
10267   GetDistAndFlow(h, 0, &hist2b, v2+2, step, 60, 90, leadingPtArr[i] + 0.01, leadingPtArr[i+2] - 0.01); 
10268   
10269   hist1->SetLineWidth(2);
10270   hist2b->SetLineWidth(2);
10271
10272   canvas = new TCanvas("dphi_baseline", "dphi_baseline", 1200, 1200);
10273   canvas->Divide(2, 2);
10274   
10275   canvas->cd(1);
10276 //   gPad->SetLeftMargin(0.20);
10277   
10278   hist1->GetYaxis()->SetTitleOffset(1.9);
10279   hist1->SetYTitle("1/N_{trig} dN_{assoc}/d#Delta#phi");
10280   hist1->SetXTitle("#Delta#phi (rad)");
10281   hist1->SetTitle("");
10282   hist1->DrawCopy()->GetYaxis()->SetRangeUser(0, 0.59);
10283   
10284   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);
10285           
10286   latex = new TLatex(0.5, 0.78, "0-5%");
10287   latex->SetNDC();
10288   latex->SetTextSize(0.04);
10289   latex->Draw();
10290   
10291   if (1)
10292   {
10293     canvas->cd(2);
10294   //   gPad->SetLeftMargin(0.20);
10295     
10296     hist1->DrawCopy()->GetYaxis()->SetRangeUser(0.18, 0.295);
10297     DrawFlow(v2[0], hist1, leadingPtArr[i], assocPtArr[j], 0, i, 0, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
10298     
10299     latex->Draw();
10300     
10301     canvas->cd(3);
10302   //   gPad->SetLeftMargin(0.20);
10303     
10304     hist2b->GetYaxis()->SetTitleOffset(1.9);
10305     hist2b->SetYTitle("1/N_{trig} dN_{assoc}/d#Delta#phi");
10306     hist2b->SetXTitle("#Delta#phi (rad)");
10307     hist2b->SetTitle("");
10308     hist2b->DrawCopy();
10309             
10310     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);
10311     
10312     latex = new TLatex(0.5, 0.78, "60-90%");
10313     latex->SetNDC();
10314     latex->SetTextSize(0.04);
10315     latex->Draw();
10316     
10317     canvas->cd(4);
10318   //   gPad->SetLeftMargin(0.20);
10319         
10320     hist2b->DrawCopy()->GetYaxis()->SetRangeUser(0.01, 0.13);
10321     DrawFlow(v2[2], hist2b, leadingPtArr[i], assocPtArr[j], 0, i, 2, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
10322         
10323     latex->Draw();
10324   }
10325   
10326   for (Int_t i=1; i<=4; i++)
10327   {
10328     canvas->cd(i);
10329     
10330     latex = new TLatex(0.5, 0.84, str);
10331     latex->SetNDC();
10332     latex->SetTextSize(0.04);
10333     latex->Draw();
10334     
10335     latex = new TLatex(0.5, 0.90, str2);
10336     latex->SetNDC();
10337     latex->SetTextSize(0.04);
10338     latex->Draw();
10339   
10340     latex = new TLatex(0.5, 0.72, "ALICE preliminary");
10341     latex->SetTextSize(0.04);
10342     latex->SetNDC();
10343     latex->Draw();
10344   
10345     latex = new TLatex(0.5, 0.66, "Stat. uncertainties only");
10346     latex->SetTextSize(0.04);
10347     latex->SetNDC();
10348     latex->Draw();
10349   }
10350     
10351   canvas->SaveAs(Form("%s.eps", canvas->GetName()));
10352   canvas->SaveAs(Form("%s.png", canvas->GetName()));
10353 }
10354
10355 /*
10356 void DeltaPhiBaseLinePaperPlot(const char* fileName, const char* yieldFile)
10357 {
10358   style(2);
10359   
10360   Float_t fontSize = 0.08;
10361   Float_t titleOffset = 0.85;
10362   
10363   gStyle->SetTextSize(fontSize);
10364   gStyle->SetLabelSize(fontSize, "xy");
10365   gStyle->SetTitleSize(fontSize, "xy");
10366   gStyle->SetTitleOffset(titleOffset, "y");
10367   gStyle->SetHistLineWidth(2);
10368   gROOT->ForceStyle();
10369   
10370   loadlibs();
10371
10372   Float_t leadingPtArr[] = { 6.0, 8.0, 10.0, 15.0, 15.0 };
10373   Float_t assocPtArr[] =     { 0.5, 1.5, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
10374   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
10375
10376   Int_t i = 1;
10377   Int_t j = 3;
10378   Int_t step = 0;
10379
10380   gpTMin = assocPtArr[j] + 0.01;
10381   gpTMax = assocPtArr[j+1] - 0.01;
10382   SetupRanges(h);
10383       
10384   TString str;
10385   str.Form("%.0f GeV/#font[12]{c} < p_{t,trig} < %.0f GeV/#font[12]{c}", leadingPtArr[i], leadingPtArr[i+2]);
10386   
10387   TString str2;
10388   str2.Form("%.0f GeV/#font[12]{c} < p_{t,assoc} < %.0f GeV/#font[12]{c}", gpTMin - 0.01, gpTMax + 0.01);
10389           
10390   Float_t v2[3];
10391   TH1* hist1 = 0;
10392   TH1* hist2b = 0;
10393   
10394   GetDistAndFlow(h, 0, &hist1,  v2, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+2] - 0.01); 
10395   
10396   hist1->SetLineWidth(2);
10397
10398   canvas = new TCanvas("dphi_baseline", "dphi_baseline", 600, 840);
10399   canvas->Range(0, 0, 1, 1);
10400   
10401   pad1 = new TPad("pad1", "pad1", 0, 0.69, 1, 1);
10402   pad1->Draw();
10403   
10404   pad2 = new TPad("pad2", "pad2", 0, 0.38, 1, 0.69);
10405   pad2->Draw();
10406
10407   pad3 = new TPad("pad3", "pad3", 0, 0   , 1, 0.38);
10408   pad3->Draw();
10409   
10410   pad1->cd();
10411   gPad->SetMargin(0.15, 0.02, 0, 0.01);
10412
10413 //   hist1->GetYaxis()->SetTitleOffset(0.85);
10414   hist1->SetYTitle("1/N_{trig} dN_{assoc}/d#Delta#varphi");
10415   hist1->SetXTitle("#Delta#varphi (rad)");
10416   hist1->SetTitle("");
10417   
10418   hist1->SetLabelSize(fontSize * 0.38 / 0.31, "xy");
10419   hist1->SetTitleSize(fontSize * 0.38 / 0.31, "xy");
10420   hist1->SetTitleOffset(titleOffset / 0.38 * 0.31, "y");
10421   
10422   hist1->DrawCopy(); //->GetYaxis()->SetRangeUser(0, 0.59);
10423   
10424   //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);
10425           
10426   pad2->cd();
10427   gPad->SetMargin(0.15, 0.02, 0, 0);
10428
10429   hist1->DrawCopy()->GetYaxis()->SetRangeUser(0.381, 0.457);
10430   DrawFlow(v2[0], hist1, leadingPtArr[i], assocPtArr[j], 0, i, 0, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
10431   
10432   pad3->cd();
10433   gPad->SetMargin(0.15, 0.02, 0.2, 0);
10434   
10435   // get zero subtracted plots
10436   TFile::Open(yieldFile);
10437   hist1sub = (TH1*) gFile->Get(Form("dphi_%d_%d_%d_fit_flat", i, j, 0));
10438   hist1sub->SetYTitle("1/N_{trig} dN_{assoc}/d#Delta#varphi");
10439   hist1sub->SetXTitle("#Delta#varphi (rad)");
10440   hist1sub->SetTitle("");
10441   hist1sub->DrawCopy();
10442   
10443   hist2sub = (TH1*) gFile->Get(Form("dphi_%d_%d_%d_fit_flat", i, j, 2));
10444   hist2sub->SetMarkerStyle(24);
10445   hist2sub->SetLineColor(2);
10446   hist2sub->SetMarkerColor(2);
10447 //   hist2sub->SetMarkerSize(0.8);
10448   hist2sub->DrawCopy("SAMEP E X0");
10449   
10450   hist3sub = (TH1*) gFile->Get(Form("dphi_%d_%d_%d_fit_flat", i, j, 3));
10451   hist3sub->SetMarkerStyle(25);
10452   hist3sub->SetLineColor(4);
10453   hist3sub->SetMarkerColor(4);
10454 //   hist3sub->SetMarkerSize(0.8);
10455   hist3sub->DrawCopy("SAMEP E X0");
10456
10457   legend = new TLegend(0.4, 0.55, 0.9, 0.9);
10458   legend->SetFillColor(0);
10459   legend->SetBorderSize(0);
10460   legend->SetTextSize(0.08);
10461   legend->AddEntry(hist1sub, "Pb-Pb 0-5% centrality", "L");
10462   legend->AddEntry(hist2sub, "Pb-Pb 60-90% centrality", "P");
10463   legend->AddEntry(hist3sub, "pp", "P");
10464   legend->Draw();
10465
10466   pad1->cd();
10467   
10468   latex = new TLatex(0.47, 0.85, str);
10469   latex->SetTextSize(fontSize * 0.38 / 0.31);
10470   latex->SetNDC();
10471   latex->Draw();
10472     
10473   latex = new TLatex(0.47, 0.73, str2);
10474   latex->SetTextSize(fontSize * 0.38 / 0.31);
10475   latex->SetNDC();
10476   latex->Draw();
10477   
10478   latex = new TLatex(0.5, 0.42, "0-5% centrality");
10479   latex->SetNDC();
10480 //   latex->Draw();
10481   
10482   latex = new TLatex(0.45, 0.62, "Stat. uncertainties only");
10483   latex->SetNDC();
10484 //   latex->Draw();
10485     
10486   canvas->SaveAs(Form("%s.eps", canvas->GetName()));
10487   canvas->SaveAs(Form("%s.png", canvas->GetName()));
10488 }
10489 */
10490
10491 void DeltaPhiBaseLinePaperPlot(const char* fileName, const char* yieldFile)
10492 {
10493   style(2);
10494   
10495   Float_t fontSize = 0.08;
10496   Float_t titleOffset = 0.85;
10497   
10498   gStyle->SetTextSize(fontSize);
10499   gStyle->SetLabelSize(fontSize, "xy");
10500   gStyle->SetTitleSize(fontSize, "xy");
10501   gStyle->SetTitleOffset(titleOffset, "y");
10502   gStyle->SetHistLineWidth(2);
10503   gROOT->ForceStyle();
10504   
10505   loadlibs();
10506
10507   Float_t leadingPtArr[] = { 6.0, 8.0, 10.0, 15.0, 15.0 };
10508   Float_t assocPtArr[] =     { 0.5, 1.5, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
10509   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
10510
10511   Int_t i = 1;
10512   Int_t j = 3;
10513   Int_t step = 0;
10514
10515   gpTMin = assocPtArr[j] + 0.01;
10516   gpTMax = assocPtArr[j+1] - 0.01;
10517   SetupRanges(h);
10518       
10519   TString str;
10520   str.Form("%.0f < #font[12]{p}_{T,trig} < %.0f GeV/#font[12]{c}", leadingPtArr[i], leadingPtArr[i+2]);
10521   
10522   TString str2;
10523   str2.Form("%.0f < #font[12]{p}_{T,assoc} < %.0f GeV/#font[12]{c}", gpTMin - 0.01, gpTMax + 0.01);
10524           
10525   Float_t v2[3];
10526   TH1* hist1 = 0;
10527   TH1* hist2b = 0;
10528   
10529   GetDistAndFlow(h, 0, &hist1,  v2, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+2] - 0.01); 
10530   
10531   hist1->SetLineWidth(2);
10532
10533   canvas = new TCanvas("dphi_baseline", "dphi_baseline", 600, 840);
10534   canvas->Range(0, 0, 1, 1);
10535   
10536   pad1 = new TPad("pad1", "pad1", 0, 0.69, 1, 1);
10537   pad1->Draw();
10538   
10539   pad2 = new TPad("pad2", "pad2", 0, 0.38, 1, 0.69);
10540   pad2->Draw();
10541
10542   pad3 = new TPad("pad3", "pad3", 0, 0   , 1, 0.38);
10543   pad3->Draw();
10544   
10545   pad1->cd();
10546   gPad->SetMargin(0.15, 0.02, 0, 0.01);
10547
10548 //   hist1->GetYaxis()->SetTitleOffset(0.85);
10549   hist1->SetYTitle("");
10550   hist1->SetXTitle("#Delta#font[12]{#varphi} (rad)");
10551   hist1->SetTitle("");
10552   
10553   hist1->SetLabelSize(fontSize * 0.38 / 0.31, "xy");
10554   hist1->SetTitleSize(fontSize * 0.38 / 0.31, "xy");
10555   hist1->SetTitleOffset(titleOffset / 0.38 * 0.31, "y");
10556   
10557   hist1->DrawCopy("HISTE"); //->GetYaxis()->SetRangeUser(0, 0.59);
10558   
10559   //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);
10560           
10561   pad2->cd();
10562   gPad->SetMargin(0.15, 0.02, 0, 0);
10563
10564   hist1->SetYTitle("1/#font[12]{N}_{trig} d#font[12]{N}_{assoc}/d#Delta#font[12]{#varphi} (rad^{-1})");
10565   hist1->DrawCopy("HISTE")->GetYaxis()->SetRangeUser(0.381, 0.457);
10566   DrawFlow(v2[0], hist1, leadingPtArr[i], assocPtArr[j], 0, i, 0, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
10567   
10568   pad3->cd();
10569   gPad->SetMargin(0.15, 0.02, 0.2, 0);
10570   
10571   // get zero subtracted plots
10572   TFile::Open(yieldFile);
10573
10574   hist1sub = (TH1*) gFile->Get(Form("dphi_%d_%d_%d_fit_flat", i, j, 0));
10575   hist1sub->SetYTitle("");
10576   hist1sub->SetXTitle("#Delta#varphi (rad)");
10577   hist1sub->SetTitle("");
10578 //   hist1sub->SetMarkerStyle(25);
10579 //   hist1sub->SetLineColor(4);
10580 //   hist1sub->SetMarkerColor(4);
10581   hist1sub->SetMaximum(0.79);
10582   hist1sub->DrawCopy("HIST E");
10583   
10584   hist3sub = (TH1*) gFile->Get(Form("dphi_%d_%d_%d_fit_flat", i, j, 3));
10585 //   hist3sub->SetFillColor(4); 
10586 //   hist3sub->SetFillStyle(3354);
10587 //   hist3sub->SetLineWidth(0);
10588 //   hist3sub->SetLineColor(0);
10589   hist3sub->SetMarkerStyle(25);
10590   hist3sub->SetLineColor(4);
10591   hist3sub->SetMarkerColor(4);
10592   hist3sub->DrawCopy("SAME E X0");
10593
10594   hist1sub->DrawCopy("SAME HIST E");
10595   
10596   hist2sub = (TH1*) gFile->Get(Form("dphi_%d_%d_%d_fit_flat", i, j, 2));
10597   hist2sub->SetMarkerStyle(24);
10598   hist2sub->SetLineColor(2);
10599   hist2sub->SetMarkerColor(2);
10600   hist2sub->DrawCopy("SAMEP E X0");
10601   
10602   legend = new TLegend(0.4, 0.45, 0.9, 0.8);
10603   legend->SetFillColor(0);
10604   legend->SetBorderSize(0);
10605   legend->SetTextSize(fontSize);
10606   legend->AddEntry(hist1sub, "Pb-Pb 0-5% centrality", "L");
10607   legend->AddEntry(hist2sub, "Pb-Pb 60-90% centrality", "P");
10608   legend->AddEntry(hist3sub, "pp", "P");
10609   legend->Draw();
10610
10611   pad1->cd();
10612   
10613   latex = new TLatex(0.59, 0.70, str);
10614   latex->SetTextSize(fontSize * 0.38 / 0.31);
10615   latex->SetNDC();
10616   latex->Draw();
10617     
10618   latex = new TLatex(0.59, 0.58, str2);
10619   latex->SetTextSize(fontSize * 0.38 / 0.31);
10620   latex->SetNDC();
10621   latex->Draw();
10622   
10623   latex = new TLatex(0.59, 0.46, "#sqrt{#font[12]{s}_{NN}} = 2.76 TeV");
10624   latex->SetTextSize(fontSize * 0.38 / 0.31);
10625   latex->SetNDC();
10626   latex->Draw();
10627
10628   latex = new TLatex(0.43, 0.90, "a) not background subtracted");
10629   latex->SetTextSize(fontSize * 0.38 / 0.31);
10630   latex->SetNDC();
10631   latex->Draw();
10632
10633   latex = new TLatex(0.5, 0.42, "0-5% centrality");
10634   latex->SetNDC();
10635 //   latex->Draw();
10636   
10637   latex = new TLatex(0.45, 0.62, "Stat. uncertainties only");
10638   latex->SetNDC();
10639 //   latex->Draw();
10640
10641   pad2->cd();
10642
10643   latex = new TLatex(0.43, 0.90, "b) zoomed");
10644   latex->SetTextSize(fontSize * 0.38 / 0.31);
10645   latex->SetNDC();
10646   latex->Draw();
10647   
10648   pad3->cd();
10649
10650   latex = new TLatex(0.43, 0.90, "c) background subtracted");
10651   latex->SetNDC();
10652   latex->Draw();
10653   
10654     
10655   canvas->SaveAs(Form("%s.eps", canvas->GetName()));
10656   canvas->SaveAs(Form("%s.png", canvas->GetName()));
10657 }
10658
10659
10660 void DeltaPhiRidgePreliminary(const char* fileName)
10661 {
10662   style();
10663   
10664   loadlibs();
10665
10666   Float_t leadingPtArr[] = { 2.0, 2.0, 3.0, 4.0, 10.0, 20.0, 40.0 };
10667   Float_t assocPtArr[] =   { 1.0, 2.0, 3.0, 6.0, 10.0, 20.0, 40.0 };
10668 //   Float_t leadingPtArr[] = { 6.0, 8.0, 10.0, 15.0, 15.0 };
10669 //   Float_t assocPtArr[] =     { 0.5, 1.5, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
10670   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName, 0, kFALSE);
10671   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
10672
10673 //   Int_t i = 1;
10674 //   Int_t j = 3;
10675   Int_t i = 0;
10676   Int_t j = 0;
10677   Int_t step = 6;
10678
10679   gpTMin = assocPtArr[j] + 0.01;
10680   gpTMax = assocPtArr[j+1] - 0.01;
10681   SetupRanges(h);
10682   SetupRanges(hMixed);
10683       
10684   TString str;
10685   str.Form("%.1f < p_{T,trig} < %.1f", leadingPtArr[i], leadingPtArr[i+2]);
10686   
10687   TString str2;
10688   str2.Form("%.1f < p_{T,assoc} < %.1f", gpTMin - 0.01, gpTMax + 0.01);
10689           
10690   Float_t v2[3];
10691   TH1* hist1 = 0;
10692   TH1* hist2b = 0;
10693   TH1* hist1Peak = 0;
10694   TH1* hist2bPeak = 0;
10695   TH1* hist1Ridge = 0;
10696   TH1* hist2bRidge = 0;
10697   
10698   TH1* hist2d = 0;
10699   TH1* hist2dMixed = 0;
10700   
10701 //   GetDistAndFlow(h, 0, &hist2d,  v2, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+2] - 0.01, 1); 
10702 //   GetDistAndFlow(hMixed, 0, &hist2dMixed,  v2, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+2] - 0.01, 1); 
10703 //   new TCanvas;
10704 //   //hist2d->Divide(hist2dMixed);
10705 //   hist2dMixed->Draw("SURF1");
10706   
10707   GetDistAndFlow(h, hMixed, &hist1,  0, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+2] - 0.01); 
10708 //   GetDistAndFlow(h, 0, &hist2b, v2[2], step, 60, 90, leadingPtArr[i] + 0.01, leadingPtArr[i+2] - 0.01); 
10709   GetDistAndFlow(h, hMixed, &hist1Peak,  0, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+2] - 0.01, 10); 
10710
10711   GetDistAndFlow(h, hMixed, &hist1Ridge,  0, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+2] - 0.01, 11); 
10712
10713   // TODO normalize
10714
10715   canvas = new TCanvas("dphi_baseline", "dphi_baseline", 800, 800);
10716   canvas->Divide(2, 2);
10717   
10718   canvas->cd(1);
10719   gPad->SetLeftMargin(0.20);
10720   
10721   hist1->GetYaxis()->SetTitleOffset(1.9);
10722   hist1->SetYTitle("1/N_{trig} dN/dp_{T,assoc}");
10723   hist1->SetTitle("");
10724   hist1->DrawCopy();
10725   
10726   hist1Peak->SetLineColor(2);
10727   hist1Peak->DrawCopy("SAME");
10728   
10729   hist1Ridge->SetLineColor(4);
10730   hist1Ridge->DrawCopy("SAME");
10731   
10732 //   hist1Peak->Add(hist1Ridge);
10733 //   hist1Peak->DrawCopy("SAME")->SetLineColor(3);
10734   
10735   return;
10736   
10737   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);
10738           
10739   latex = new TLatex(0.65, 0.84, str);
10740   latex->SetNDC();
10741   latex->SetTextSize(0.04);
10742   latex->Draw();
10743   
10744   latex = new TLatex(0.65, 0.90, str2);
10745   latex->SetNDC();
10746   latex->SetTextSize(0.04);
10747   latex->Draw();
10748
10749   latex = new TLatex(0.84, 0.78, "0-5%");
10750   latex->SetNDC();
10751   latex->SetTextSize(0.04);
10752   latex->Draw();
10753   
10754   canvas->cd(2);
10755   gPad->SetLeftMargin(0.20);
10756   
10757   hist1->DrawCopy()->GetYaxis()->SetRangeUser(0.18, 0.28);
10758   DrawFlow(v2[0], hist1, leadingPtArr[i], assocPtArr[j], 0, i, 0, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
10759   
10760   latex->Draw();
10761   
10762   latex = new TLatex(0.5, 0.90, "ALICE preliminary");
10763   latex->SetTextSize(0.04);
10764   latex->SetNDC();
10765   latex->Draw();
10766
10767   latex = new TLatex(0.5, 0.84, "Statistical uncertainties only");
10768   latex->SetTextSize(0.04);
10769   latex->SetNDC();
10770   latex->Draw();
10771   
10772   canvas->cd(3);
10773   gPad->SetLeftMargin(0.20);
10774   
10775   hist2b->GetYaxis()->SetTitleOffset(1.9);
10776   hist2b->SetYTitle("1/N_{trig} dN/dp_{T,assoc}");
10777   hist2b->SetTitle("");
10778   hist2b->DrawCopy();
10779            
10780   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);
10781   
10782   latex = new TLatex(0.84, 0.78, "60-90%");
10783   latex->SetNDC();
10784   latex->SetTextSize(0.04);
10785   latex->Draw();
10786   
10787   canvas->cd(4);
10788   gPad->SetLeftMargin(0.20);
10789       
10790   hist2b->DrawCopy()->GetYaxis()->SetRangeUser(0.01, 0.1);
10791   DrawFlow(v2[2], hist2b, leadingPtArr[i], assocPtArr[j], 0, i, 2, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
10792       
10793   latex->Draw();
10794   
10795   canvas->SaveAs(Form("%s.eps", canvas->GetName()));
10796   canvas->SaveAs(Form("%s.png", canvas->GetName()));
10797 }
10798
10799 void MCScalingFactor(Int_t caseId)
10800 {
10801   // 900 GeV
10802   // x[5]=5, y[5]=0.813743, ex[5]=0, ey[5]=0.158446
10803   // x[5]=5, y[5]=1.09804, ex[5]=0, ey[5]=0.265434
10804   // 7 TeV
10805   // x[5]=5, y[5]=1.02276, ex[5]=0, ey[5]=0.0199991
10806   // x[5]=5, y[5]=0.870247, ex[5]=0, ey[5]=0.0294444
10807   
10808   Float_t factors[] = { 0.814, 1.098, 1.022, 0.870 };
10809   Float_t errors[]  = { 0.158, 0.265, 0.020, 0.029 };
10810   
10811   Float_t avgs[2];
10812   
10813   for (Int_t i=0; i<2; i++)
10814   {
10815     switch (caseId)
10816     {
10817       case 0:
10818         avgs[i] = factors[2*i] / errors[2*i] / errors[2*i] + factors[2*i+1] / errors[2*i+1] / errors[2*i+1];
10819         avgs[i] /= 1. / errors[2*i] / errors[2*i] + 1. / errors[2*i+1] / errors[2*i+1];
10820         break;
10821         
10822       case 1:
10823         avgs[i] = factors[2*i];
10824         break;
10825     
10826       case 2:
10827         avgs[i] = factors[2*i+1];
10828         break;
10829     
10830       case 3:
10831         avgs[0] = factors[0];
10832         avgs[1] = factors[3];
10833         break;
10834     
10835       case 4:
10836         avgs[0] = factors[1];
10837         avgs[1] = factors[2];
10838         break;
10839     }
10840   }
10841   
10842   Float_t a = avgs[0];
10843   Float_t b = avgs[1];
10844   
10845   Printf("%f %f", a, b);
10846   
10847   Float_t linEx = a + (b-a)/(7.-0.9) * (2.76-0.9);
10848   Float_t logEx = a + (b-a)/(log(7.)-log(0.9)) * (log(2.76)-log(0.9));
10849   
10850   Printf("%f %f", linEx, logEx);
10851 }
10852   
10853 void CompareDeltaPhi(const char* fileName1, const char* fileName2, Int_t centralityID, const char* dist = "_fit_flat", Bool_t reduced = kFALSE)
10854 {
10855   firstFile = TFile::Open(fileName1);
10856   secondFile = TFile::Open(fileName2);
10857
10858   Int_t maxLeadingPt = 2;
10859   Int_t maxAssocPt = 7;
10860   Int_t minLeadingPt = 0;
10861   Int_t minAssocPt = 0;
10862   
10863   if (reduced)
10864   {
10865     maxLeadingPt = 2;
10866     maxAssocPt = 5;
10867     minLeadingPt = 1;
10868     minAssocPt = 2;
10869   }
10870   
10871   TCanvas* canvas = new TCanvas(Form("%s %s", fileName1, fileName2 ? fileName2 : ""), Form("%s %s", fileName1, fileName2 ? fileName2 : ""), 1000, 700);
10872   canvas->Divide(maxAssocPt-minAssocPt, maxLeadingPt-minLeadingPt);
10873   
10874   for (Int_t i=minLeadingPt; i<maxLeadingPt; i++)
10875     for (Int_t j=minAssocPt; j<maxAssocPt; j++)
10876     {
10877       Printf("%d %d", i, j);
10878     
10879       canvas->cd(j+1-minAssocPt + (i-minLeadingPt) * maxAssocPt);
10880       gPad->SetLeftMargin(0.15);
10881       gPad->SetBottomMargin(0.2);
10882       //gPad->SetTopMargin(0.01);
10883       gPad->SetRightMargin(0.01);
10884       
10885       hist1 = (TH1*) firstFile->Get(Form("dphi_%d_%d_%d%s", i, j, centralityID, dist));
10886       hist2 = (TH1*) secondFile->Get(Form("dphi_%d_%d_%d%s", i, j, centralityID, dist));
10887       
10888       if (!hist1)
10889         continue;
10890       
10891 /*      hist1->Rebin(2); hist1->Scale(0.5); 
10892       hist2->Rebin(2); hist2->Scale(0.5); */
10893 //       hist1->Scale(1.6);
10894         
10895       hist1->SetLineColor(1);
10896       hist2->SetLineColor(2);
10897       
10898       hist1->DrawCopy()->GetYaxis()->SetRangeUser(hist1->GetMinimum(), hist1->GetMaximum() * 1.2);
10899       hist2->DrawCopy("SAME");
10900       
10901 /*      if (strlen(dist) == 0)
10902         Printf("chi2 test: %f", hist1->Chi2Test(hist2, "UU NORM CHI2/NDF"));*/
10903       
10904       //DrawRatio(hist1, hist2, hist1->GetTitle());
10905       
10906       //return;
10907     }
10908 }
10909   
10910 TH1* MACHCone(const char* fileName, Int_t centrality, const char* drawingOption, Bool_t plotContributions, Int_t twoD, TF1** flowFuncP = 0)
10911 {
10912   if (0)
10913   {
10914     TFile::Open("machcone_input.root");
10915     
10916     switch (centrality)
10917     {
10918       case 0:
10919         hist = (TH1*) gFile->Get("dphi_0_0_0");
10920         break;
10921       
10922       case 1:
10923         hist = (TH1*) gFile->Get("dphi_1_1_0");
10924         break;
10925         
10926       case 2:
10927         hist = (TH1*) gFile->Get("dphi_0_0_2");
10928         break;
10929     
10930       case 3:
10931         hist = (TH1*) gFile->Get("dphi_1_1_2");
10932         break;
10933     }
10934   }
10935   else
10936   {
10937     loadlibs();
10938     
10939     AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
10940     AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
10941     
10942     Float_t leadingPtArr[] = { 2.0, 3.0, 4.0, 10.0, 20.0, 40.0 };
10943     Float_t assocPtArr[] =   { 1.0, 2.0, 3.0, 6.0, 10.0, 20.0, 40.0 };
10944 //     Float_t assocPtArr[] =   { 2.0, 3.0, 6.0, 10.0, 20.0, 40.0 };
10945   
10946     Int_t i = centrality % 2;
10947     Int_t step = 6;
10948     
10949     Int_t j = 0;
10950     
10951     gpTMin = assocPtArr[i] + 0.01;
10952     gpTMax = assocPtArr[i+1] - 0.01;
10953     
10954     Int_t centralityBegin = 0;
10955     Int_t centralityEnd = 1;
10956     
10957     if (centrality >= 2)
10958     {
10959       centralityBegin = 30;
10960       centralityEnd = 40;
10961     }
10962       
10963     SetupRanges(h);
10964     SetupRanges(hMixed);
10965     
10966     TH1* hist = 0;
10967     Float_t vn[5];
10968     vn[0] = 0;
10969     vn[1] = 0;
10970     vn[2] = 0;
10971     vn[3] = 0;
10972     vn[4] = 0;
10973     
10974     Bool_t scaleToPairs = 0;
10975     
10976     GetDistAndFlow(h, hMixed, &hist, 0, step, centralityBegin, centralityEnd, leadingPtArr[j] + 0.01, leadingPtArr[j+1] - 0.01, twoD, kTRUE, vn, scaleToPairs); 
10977     if (scaleToPairs && twoD == 11)
10978       hist->Scale(2);  
10979     
10980     Printf("%f %f %f", vn[2], vn[3], vn[4]);
10981     
10982     // mirror delta phi to improve stats
10983     if (1)
10984     {
10985       for (Int_t bin=1; bin<=hist->GetNbinsX(); bin++)
10986       {
10987         if (hist->GetBinCenter(bin) < 0 || hist->GetBinCenter(bin) > TMath::Pi())
10988         {
10989           if (hist->GetBinCenter(bin) < 0)
10990             Int_t bin2 = hist->FindBin(-1.0 * hist->GetBinCenter(bin));
10991           else
10992             Int_t bin2 = hist->FindBin(TMath::TwoPi() - hist->GetBinCenter(bin));
10993           
10994           Float_t combValue = hist->GetBinContent(bin) / hist->GetBinError(bin) / hist->GetBinError(bin) + hist->GetBinContent(bin2) / hist->GetBinError(bin2) / hist->GetBinError(bin2);
10995           
10996           Float_t weight = 1. / hist->GetBinError(bin) / hist->GetBinError(bin) + 1. / hist->GetBinError(bin2) / hist->GetBinError(bin2);
10997           combValue /= weight;
10998           
10999           Float_t combError = TMath::Sqrt(1.0 / weight);
11000           
11001           hist->SetBinContent(bin2, combValue);
11002           hist->SetBinError(bin2, combError);
11003
11004           hist->SetBinContent(bin, combValue);
11005           hist->SetBinError(bin, combError);
11006           
11007           Printf("%d %d %f %f", bin, bin2, combValue, combError);
11008         }
11009       }
11010     }
11011   }
11012   
11013   TString str(hist->GetTitle());
11014   str.ReplaceAll(" - ", "#");
11015   tokens = str.Tokenize("#");
11016   hist->SetTitle("");
11017   
11018   hist->SetLineColor(1);
11019   hist->SetYTitle("1/N_{trig} dN_{assoc}/d#Delta#phi");
11020   hist->SetXTitle("#Delta#phi (rad)");
11021   hist = (TH1*) hist->Clone();
11022   if (!drawingOption)
11023     return hist;
11024   
11025   hist = hist->DrawCopy(drawingOption);
11026   
11027   for (Int_t i=0; i<tokens->GetEntries()-1; i++)
11028   {
11029     if (centrality == 1)
11030       latex = new TLatex(0.6, 0.9 - i*0.05 - gPad->GetTopMargin(), tokens->At(i)->GetName());
11031     else
11032       latex = new TLatex(0.6, 0.12 - i*0.05, tokens->At(i)->GetName());
11033     
11034     latex->SetNDC();
11035     latex->SetTextSize(0.04);
11036     latex->Draw();
11037   }
11038   
11039   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());
11040   //flowFunc->SetLineWidth(1);
11041   flowFunc->SetLineColor(2);
11042   flowFunc->SetLineStyle(2);
11043   for (Int_t i=0; i<4; i++)
11044     flowFunc->FixParameter(i+1, vn[i+1]);
11045   //flowFunc->SetParameter(0, 84.95); flowFunc->DrawClone("SAME");
11046   
11047   //flowFunc->SetParameter(0, 85.4); flowFunc->DrawClone("SAME");
11048   //flowFunc->SetParameter(0, 85.6); flowFunc->DrawClone("SAME");
11049   
11050 //   hist->Fit(flowFunc, "", "SAME", 1.8, 4.5);
11051   hist->Fit(flowFunc, "N", "", -0.5 * TMath::Pi(), 1.5 * TMath::Pi());
11052   hist->GetYaxis()->SetRangeUser(hist->GetMinimum() * 0.95, hist->GetMaximum() * 1.05);
11053   flowFunc->SetRange(-0.5 * TMath::Pi(), 1.5 * TMath::Pi());
11054   flowFunc->Draw("SAME");
11055   
11056   if (flowFuncP)
11057     *flowFuncP = flowFunc;
11058   
11059   //hist->GetYaxis()->SetRangeUser(84, 89);
11060   //flowFunc->SetParameter(4, 1);
11061   
11062   Float_t chi2 = 0;
11063   Int_t n=0;
11064   for (Int_t bin=hist->FindBin(1.8); bin<=hist->FindBin(4.5); bin++)
11065   {
11066     chi2 += TMath::Power((hist->GetBinContent(bin) - flowFunc->Eval(hist->GetBinCenter(bin))) / hist->GetBinError(bin), 2);
11067     n++;
11068     //Printf("%f", TMath::Power((hist->GetBinContent(bin) - flowFunc->Eval(hist->GetBinCenter(bin))) / hist->GetBinError(bin), 2));
11069   }
11070     
11071   chi2 /= n;
11072   
11073   Printf("chi2/ndf = %f", chi2);
11074   
11075   if (!plotContributions)
11076     return hist;
11077   
11078   for (Int_t n=1; n<=5; n++)
11079   {
11080     flowFuncPart = new TF1("flowFuncPart", "[0] * (1+2*[1]*cos([2]*x))", -0.5 * TMath::Pi(), 1.5 * TMath::Pi());
11081     flowFuncPart->SetParameters(flowFunc->GetParameter(0), vn[n-1], n);
11082     flowFuncPart->SetLineWidth(1);
11083     flowFuncPart->SetLineStyle(n);
11084     flowFuncPart->Draw("SAME");
11085   }
11086   
11087   return hist;
11088 }
11089
11090 void MACHConeAll(const char* fileName)
11091 {
11092   loadlibs();
11093
11094   SetFlowStyle();
11095
11096   c = new TCanvas("c", "c", 300, 800);
11097   c->SetTopMargin(0);
11098   c->SetLeftMargin(0);
11099   c->SetRightMargin(0);
11100   c->SetBottomMargin(0);
11101   c->Divide(1, 2, 0, 0);
11102   
11103   Float_t rangesMin[] = { 136.1, 17.45, 18, 2.4 };
11104   Float_t rangesMax[] = { 139.4, 18.95, 23.5, 3.6 };
11105   
11106   for (Int_t i=0; i<2; i++)
11107   {
11108     c->cd(i+1);
11109
11110     gPad->SetRightMargin(0.05);
11111     gPad->SetLeftMargin(0.20);
11112     gPad->SetTopMargin(0.15);
11113     gPad->SetBottomMargin(0.15);
11114
11115     if (i == 0)
11116     {
11117       gPad->SetBottomMargin(0.01);
11118     }
11119     else if (i == 1)
11120     {
11121       gPad->SetTopMargin(0.01);
11122       gPad->SetBottomMargin(0.7);
11123     }
11124   }
11125
11126   Int_t i = 0;
11127
11128   TF1* flowFunc = 0;
11129   
11130   c->cd(i+1);
11131 //   hist = MACHCone(fileName, i, "", kTRUE, 0, &flowFunc);
11132   hist = (TH1*) MACHCone(fileName, i, 0, kFALSE, 0)->Clone("hist");
11133   hist->GetYaxis()->SetRangeUser(rangesMin[i], rangesMax[i]);
11134   hist->GetYaxis()->SetTitleOffset(1.7);
11135   hist->Draw();
11136 //     continue;
11137   
11138   c->cd(i+1);
11139   //c->cd(i+2);
11140 //   hist2 = MACHCone(fileName, i, 0, kFALSE, 11);
11141   hist2 = MACHCone(fileName, i, "SAME", kTRUE, 11, &flowFunc);
11142   //hist2->GetYaxis()->SetRangeUser(rangesMin[i], rangesMax[i]);
11143 //   hist2->Scale(2);
11144   hist2->SetLineColor(4);
11145   //hist2->Draw("SAME");
11146 //    return;
11147
11148   // sample flowFunc with same binning
11149   flowFuncHist = (TH1*) hist->Clone("flowFuncHist");
11150   flowFuncHist->Reset();
11151   
11152   for (Int_t i=1; i<=flowFuncHist->GetNbinsX(); i++)
11153   {
11154     flowFuncHist->SetBinContent(i, flowFunc->Integral(flowFuncHist->GetXaxis()->GetBinLowEdge(i), flowFuncHist->GetXaxis()->GetBinUpEdge(i)));
11155     flowFuncHist->SetBinError(i, 0);
11156   }
11157   
11158   i = 0;
11159   
11160   flowFuncHist->Scale(1.0 / flowFuncHist->GetBinWidth(1));
11161   
11162 //   new TCanvas;
11163 //   flowFuncHist->Draw();
11164 //   flowFunc->Draw("SAME");
11165 //   return;
11166
11167   // residuals
11168   residuals = (TH1*) hist->Clone("res1");
11169   residuals->SetYTitle("Residuals");
11170   residuals->Divide(flowFuncHist);
11171   c->cd(i+2);
11172   residuals->Draw();
11173   residuals->GetYaxis()->SetNdivisions(505);
11174   residuals->GetYaxis()->SetRangeUser(0.995, 1.005);
11175
11176   residuals = (TH1*) hist2->Clone("res2");
11177   residuals->Divide(flowFuncHist);
11178   c->cd(i+2);
11179   residuals->SetLineColor(4);
11180   residuals->Draw("SAME");
11181   
11182   gPad->SetGridy();
11183
11184   if (i == 0)
11185   {
11186     legend = new TLegend(0.43, 0.66, 0.91, 0.82);
11187     legend->SetFillColor(0);
11188     legend->SetTextSize(0.034);
11189     legend->SetTextAlign(22);
11190     
11191     legend->SetHeader("Centrality 0-1%");
11192     legend->AddEntry(hist, "|#eta| < 0.8 & All #Delta#eta", "L");
11193     legend->AddEntry(hist2, "|#eta| < 0.8 & |#Delta#eta| > 0.8 (2x)", "L");
11194     
11195     c->cd(i+1);
11196     legend->Draw();
11197   }
11198   
11199   c->SaveAs(Form("machcone_%d.png", 0));
11200   c->SaveAs(Form("machcone_%d.eps", 0));
11201   c->SaveAs(Form("machcone_%d.C", 0));
11202   
11203   return;
11204   
11205   c->cd(1);
11206   MACHCone(3, "", kTRUE)->SetTitle("");
11207   
11208   c->cd(2);
11209   hist1 = MACHCone(0, "", kFALSE);
11210   hist2 = MACHCone(1, "SAME", kFALSE);
11211   hist3 = MACHCone(2, "SAME", kFALSE);
11212   
11213   hist1->SetTitle("");
11214   hist1->GetYaxis()->SetRangeUser(1, 7);
11215 }
11216   
11217 void SetFlowStyle()
11218 {
11219  // Set style which will affect all plots.
11220  
11221  gStyle->Reset();
11222  // gStyle->SetOptitle(0);
11223  // gStyle->SetOptStat(0);
11224  //gStyle->SetOptDate(1);
11225  // gStyle->SetPalette(8,0);  // (1,0)
11226  gStyle->SetPalette(1);  // (1,0)
11227  gStyle->SetDrawBorder(0);
11228  // gStyle->SetFillColor(0);  // kills palete ???
11229  gStyle->SetCanvasColor(0);
11230  gStyle->SetPadColor(0);
11231  // gStyle->SetFillColor(0); // otherwize it affects Fill colors later
11232  gStyle->SetFrameFillColor(0);
11233  gStyle->SetCanvasBorderMode(0);
11234  gStyle->SetFrameLineWidth(2);
11235  // gStyle->SetFrameFillStyle(4000);
11236  gStyle->SetPadBorderMode(0);
11237  gStyle->SetPadTickX(1);
11238  gStyle->SetPadTickY(1);
11239  gStyle->SetPadBottomMargin(0.15);
11240  gStyle->SetPadLeftMargin(0.15);
11241  gStyle->SetHistLineWidth(2);
11242  gStyle->SetFuncWidth(2);
11243  gStyle->SetLineWidth(2);
11244  gStyle->SetLabelSize(0.05,"xyz");
11245  gStyle->SetLabelOffset(0.01,"y");
11246  gStyle->SetLabelColor(kBlack,"xyz");
11247  gStyle->SetTitleSize(0.06,"xyz");
11248  gStyle->SetTitleOffset(1.3,"y");
11249  gStyle->SetTitleFillColor(0);
11250  gStyle->SetLineWidth(2);  
11251  gStyle->SetHistLineColor(1);
11252  gStyle->SetTextColor(1);
11253  gStyle->SetTitleTextColor(1);
11254  TGaxis::SetMaxDigits(4);
11255  gStyle->SetOptStat(0); // removes stat. box from all histos
11256  gROOT->ForceStyle();
11257
11258 } // end of void SetFlowStyle()
11259
11260 void PlotPtDistributionsSubtracted(const char* fileName1, Int_t centrBegin = 1, Int_t centrEnd = 6, Int_t fit = 0)
11261 {
11262   loadlibs();
11263
11264   Int_t nCentralityBins = 5;
11265   Int_t centralityBins[] = { 1, 7, 9, 11, 13, 16 };
11266   
11267   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName1);
11268     
11269   TCanvas* canvas = new TCanvas("Pt", "Pt", 1000, 1000);
11270   canvas->Divide(2, 2);
11271   
11272   TLegend* legend = new TLegend(0.3, 0.8, 0.99, 0.99);
11273   legend->SetFillColor(0);
11274   
11275   Int_t colors[] = { 1, 2, 4, 6, 3, 5 };
11276   Int_t markers[] = { 20, 21, 22, 23, 24, 25 };
11277   
11278   Double_t ptMin = 10.01;
11279   Double_t ptMax = 39.99;
11280     
11281   TString str;
11282   str.Form("%.1f < p_{T,trig} < %.1f", ptMin - 0.01, ptMax + 0.01);
11283   
11284   canvas->cd(1);
11285   gPad->SetLeftMargin(0.15);
11286   gPad->SetBottomMargin(0.2);
11287   gPad->SetTopMargin(0.01);
11288   gPad->SetRightMargin(0.01);
11289   gPad->SetLogy();
11290   gPad->SetLogx();
11291   gPad->SetGridx();
11292   gPad->SetGridy();
11293   
11294   TH2F* dummy = new TH2F("dummy", "", 100, 1, 40, 100, 1e-5, 1e3);
11295   dummy->SetStats(kFALSE);
11296   dummy->SetXTitle("p_{T,assoc}");
11297   dummy->SetYTitle("1/N_{trig} dN/dp_{T,assoc}");
11298   dummy->GetYaxis()->SetTitleOffset(1);
11299   Prepare1DPlot(dummy);
11300
11301   dummy->GetXaxis()->SetLabelSize(0.05);
11302   dummy->GetYaxis()->SetLabelSize(0.05);
11303   dummy->GetXaxis()->SetTitleSize(0.05);
11304   dummy->GetYaxis()->SetTitleSize(0.05);
11305   dummy->DrawCopy();
11306   
11307   canvas->cd(2);
11308   gPad->SetLeftMargin(0.15);
11309   gPad->SetBottomMargin(0.2);
11310   gPad->SetTopMargin(0.01);
11311   gPad->SetRightMargin(0.01);
11312   gPad->SetLogy();
11313   gPad->SetLogx();
11314   gPad->SetGridx();
11315   gPad->SetGridy();
11316   dummy->DrawCopy();
11317   
11318   canvas->cd(3);
11319   gPad->SetLeftMargin(0.15);
11320   gPad->SetBottomMargin(0.2);
11321   gPad->SetTopMargin(0.01);
11322   gPad->SetRightMargin(0.01);
11323   gPad->SetLogx();
11324   gPad->SetGridx();
11325   gPad->SetGridy();
11326   
11327   dummy = new TH2F("dummy2", "", 100, 1, 40, 100, 0, 100);
11328   dummy->SetStats(kFALSE);
11329   dummy->SetXTitle("p_{T,assoc}");
11330   dummy->SetYTitle("Ratio: Distribution / Inclusive");
11331   dummy->GetYaxis()->SetTitleOffset(1);
11332   Prepare1DPlot(dummy);
11333   dummy->GetXaxis()->SetLabelSize(0.05);
11334   dummy->GetYaxis()->SetLabelSize(0.05);
11335   dummy->GetXaxis()->SetTitleSize(0.05);
11336   dummy->GetYaxis()->SetTitleSize(0.05);
11337   dummy->DrawCopy();
11338   
11339   canvas->cd(4);
11340   gPad->SetLeftMargin(0.15);
11341   gPad->SetBottomMargin(0.2);
11342   gPad->SetTopMargin(0.01);
11343   gPad->SetRightMargin(0.01);
11344   gPad->SetLogx();
11345   gPad->SetGridx();
11346   gPad->SetGridy();
11347   dummy->DrawCopy();
11348   
11349   
11350   // see GetAcceptanceScalingFactor
11351   Float_t scalingFactor = 0.328396; // 0.8
11352   //Float_t scalingFactor = 0.433268; // 0.7
11353   //Float_t scalingFactor = 0.895593; // 0.5 --> 1.6
11354       
11355   Float_t phiRange[] = { 0, TMath::Pi() / 2, TMath::Pi() };
11356   const char* phiLabels[] = { "Towards", "Transverse", "Away" };
11357   
11358   //Float_t phiSizeTowards = TMath::Pi() / 3;
11359   Float_t phiSizeTowards = 0.75;
11360   //Float_t etaLimit = 0.5;
11361   Float_t etaLimit = 0.8;
11362   
11363   towardsCentralEta = h->GetUEHist(2)->GetPtHist(6, 0, ptMin, ptMax, centrBegin, centrEnd, phiRange[0] - phiSizeTowards, phiRange[0] + phiSizeTowards, -etaLimit + 0.01, etaLimit - 0.01);
11364   towardsSideEta1 = h->GetUEHist(2)->GetPtHist(6, 0, ptMin, ptMax, centrBegin, centrEnd, phiRange[0] - phiSizeTowards, phiRange[0] + phiSizeTowards, -1.59, -etaLimit - 0.01);
11365   TH1* towardsSideEta2 = h->GetUEHist(2)->GetPtHist(6, 0, ptMin, ptMax, centrBegin, centrEnd, phiRange[0] - phiSizeTowards, phiRange[0] + phiSizeTowards, etaLimit + 0.01, 1.59);
11366   towardsSideEta1->Add(towardsSideEta2); // TODO can be done smarter? what about the errors?
11367
11368   Prepare1DPlot(towardsSideEta1);
11369   Prepare1DPlot(towardsCentralEta);
11370   
11371   towardsCentralEta->SetLineColor(colors[0]);
11372   towardsSideEta1->SetLineColor(colors[3]);
11373   //towardsSideEta1->SetLineStyle(2);
11374
11375   legend->AddEntry(towardsCentralEta->Clone(), Form("Jet, %s: |#Delta#eta| < 0.8, #phi ~ %.1f", phiLabels[0], phiRange[0]));
11376   legend->AddEntry(towardsSideEta1->Clone(), Form("Ridge, %s: 0.8 < |#Delta#eta| < 1.6, #phi ~ %.1f", phiLabels[0], phiRange[0]));
11377   
11378   // TODO update when data with new phi binning is available
11379   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);
11380   /*
11381   transverse2 = h->GetUEHist(2)->GetPtHist(6, 0, ptMin, ptMax, centrBegin, centrEnd, -0.5 * TMath::Pi(), -TMath::Pi() / 3, -1.59, 1.59, kTRUE);
11382   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);
11383   transverse->Add(transverse2);
11384   transverse->Add(transverse3);
11385   transverse->Scale(1.0 / (2.0 / 3 * TMath::Pi()));
11386   */
11387     
11388   //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);
11389   //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);
11390   //transverseSideEta1->Add(transverseSideEta2); // TODO can be done smarter? what about the errors?
11391   
11392   transverse->SetLineColor(colors[2]);
11393   //transverseSideEta1->SetLineColor(colors[2]);
11394   //transverseSideEta1->SetLineStyle(2);
11395
11396   Prepare1DPlot(transverse);
11397   //Prepare1DPlot(transverseSideEta1);
11398   legend->AddEntry(transverse->Clone(), Form("%s: |#Delta#eta| < 1.6, #phi ~ %.1f", phiLabels[1], phiRange[1]));
11399   //legend->AddEntry(transverseSideEta1->Clone(), Form("%s: 0.8 < |#Delta #eta| < 1.6, #phi ~ %.1f", phiLabels[1], phiRange[1]));
11400   
11401   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);
11402
11403   /*
11404   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);
11405   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);
11406   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);
11407   away3->Add(away4);
11408   */
11409   
11410   away->SetLineColor(colors[1]);
11411   //away3->SetLineColor(colors[1]);
11412   //away3->SetLineStyle(2);
11413   
11414   Prepare1DPlot(away);
11415   legend->AddEntry(away->Clone(), Form("%s: |#Delta#eta| < 1.6, #phi ~ %.1f", phiLabels[2], phiRange[2]));
11416   
11417   //inclusive = h->GetUEHist(2)->GetPtHist(6, 0, ptMin, ptMax, centrBegin, centrEnd, -0.5 * TMath::Pi(), 1.5 * TMath::Pi(), -1.59, 1.59);
11418   
11419   /*
11420   h->GetUEHist(2)->GetEventHist()->GetGrid(6)->GetGrid()->GetAxis(1)->SetRange(centrBegin, centrEnd);
11421   inclusive = h->GetUEHist(2)->GetEventHist()->ShowProjection(0, 6);
11422   h->GetUEHist(2)->GetEventHist()->GetGrid(6)->GetGrid()->GetAxis(1)->SetRange(0, -1);
11423   */
11424   
11425   axis = h->GetUEHist(2)->GetEventHist()->GetGrid(6)->GetGrid()->GetAxis(1);
11426   
11427   inclusiveTmp = h->GetCorrelationpT()->ProjectionY("inclusiveTmp", h->GetCorrelationpT()->GetXaxis()->FindBin(axis->GetBinLowEdge(centrBegin) + 0.01), h->GetCorrelationpT()->GetXaxis()->FindBin(axis->GetBinUpEdge(centrEnd) - 0.01));
11428   
11429   //rebin to match other histograms
11430   //inclusive2 = inclusive->Rebin(away->GetNbinsX(), "inclusive2", away->GetXaxis()->GetXbins()->GetArray());
11431   
11432   // manually, as usual the ROOT function makes a SEGV
11433   inclusive = (TH1*) away->Clone("inclusive");
11434   inclusive->Reset();
11435   inclusive->Sumw2();
11436   for (Int_t bin=1; bin<=inclusiveTmp->GetNbinsX(); bin++)
11437     inclusive->Fill(inclusiveTmp->GetBinCenter(bin), inclusiveTmp->GetBinContent(bin));
11438   
11439   for (Int_t bin=1; bin<=inclusive->GetNbinsX(); bin++)
11440     inclusive->SetBinError(bin, TMath::Sqrt(inclusive->GetBinContent(bin)));
11441     
11442   // normalization: events, phase space
11443   inclusive->Scale(1.0 / h->GetCentralityDistribution()->Integral(centrBegin, centrEnd));
11444   inclusive->Scale(1.0 / (TMath::TwoPi() * 0.8 * 2));
11445   
11446   // bin width
11447   for (Int_t i=1; i<=inclusive->GetNbinsX(); i++)
11448   {
11449     inclusive->SetBinContent(i, inclusive->GetBinContent(i) / inclusive->GetXaxis()->GetBinWidth(i));
11450     inclusive->SetBinError  (i, inclusive->GetBinError(i) / inclusive->GetXaxis()->GetBinWidth(i));
11451   }
11452   
11453   Prepare1DPlot(inclusive);
11454   inclusive->SetLineColor(colors[4]);
11455   legend->AddEntry(inclusive->Clone(), "Inclusive");
11456   
11457   //Prepare1DPlot(away3);
11458   //legend->AddEntry(away3->Clone(), Form("%s: 0.8 < |#Delta #eta| < 1.6, #phi ~ %.1f", phiLabels[2], phiRange[2]));
11459   
11460   // scale for acceptance to match acceptance of towardsCentralEta
11461   towardsSideEta1->Scale(1.0 / scalingFactor); // contains only "side-eta"
11462   transverse->Scale(1.0 / (1.0 + scalingFactor)); // full eta
11463   away->Scale(1.0 / (1.0 + scalingFactor)); // full eta
11464   inclusive->Scale(1.0 / (1.0 + scalingFactor)); // full eta (phi scaling implicit)
11465   
11466   canvas->cd(1);
11467   towardsCentralEtaClone = towardsCentralEta->DrawCopy("SAME");
11468   towardsSideEta1Clone = towardsSideEta1->DrawCopy("SAME");
11469   transverseClone = transverse->DrawCopy("SAME");
11470   //transverseSideEta1->DrawCopy("SAME");
11471   awayClone = away->DrawCopy("SAME");
11472   inclusiveClone = inclusive->DrawCopy("SAME");
11473   //inclusive2->DrawCopy("SAME");
11474   //away3->DrawCopy("SAME");
11475   
11476   canvas->cd(3);
11477   
11478   towardsCentralEtaR = (TH1*) towardsCentralEta->Clone("towardsCentralEtaR");
11479   towardsSideEta1R = (TH1*) towardsSideEta1->Clone("towardsSideEta1R");
11480   transverseR = (TH1*) transverse->Clone("transverseR");
11481   awayR = (TH1*) away->Clone("awayR");
11482   
11483   towardsCentralEtaR->Divide(inclusive);
11484   towardsSideEta1R->Divide(inclusive);
11485   transverseR->Divide(inclusive);
11486   awayR->Divide(inclusive);
11487   
11488   towardsCentralEtaR->DrawCopy("SAME");
11489   towardsSideEta1R->DrawCopy("SAME");
11490   transverseR->DrawCopy("SAME");
11491   awayR->DrawCopy("SAME");
11492   
11493   if (fit == 1)
11494   {
11495     canvas->cd(1);
11496     
11497     awayClone->Fit("expo", "", "SAME", 1.1, 2.9);
11498     awayClone->GetFunction("expo")->SetRange(1, 10);
11499     gPad->SetLogx(0);
11500   }
11501   else if (fit == 2)
11502   {
11503     canvas->cd(1);
11504     
11505     func = new TF1("func", "[0] * x**[1]");
11506     func->SetParameters(1, 1);
11507     
11508     Float_t limitLow = 2.1;
11509     Float_t limitHigh = 4.9;
11510     
11511     func2 = (TF1*) func->Clone();
11512     towardsCentralEtaClone->Fit(func2, "", "SAME", limitLow, limitHigh);
11513     towardsCentralEtaClone->GetFunction("func")->SetRange(1, 10);
11514     towardsCentralEtaClone->GetFunction("func")->SetLineColor(towardsCentralEtaClone->GetLineColor());
11515     
11516     func2 = (TF1*) func->Clone();
11517     towardsSideEta1Clone->Fit(func2, "", "SAME", limitLow, limitHigh);
11518     towardsSideEta1Clone->GetFunction("func")->SetRange(1, 10);
11519     towardsSideEta1Clone->GetFunction("func")->SetLineColor(towardsSideEta1Clone->GetLineColor());
11520   
11521     func2 = (TF1*) func->Clone();
11522     transverseClone->Fit(func2, "", "SAME", limitLow, limitHigh);
11523     transverseClone->GetFunction("func")->SetRange(1, 10);
11524     transverseClone->GetFunction("func")->SetLineColor(transverseClone->GetLineColor());
11525   
11526     func2 = (TF1*) func->Clone();
11527     awayClone->Fit(func2, "", "SAME", limitLow, limitHigh);
11528     awayClone->GetFunction("func")->SetRange(1, 10);
11529     awayClone->GetFunction("func")->SetLineColor(awayClone->GetLineColor());
11530   
11531     func2 = (TF1*) func->Clone();
11532     inclusiveClone->Fit(func2, "", "SAME", limitLow, limitHigh);
11533     inclusiveClone->GetFunction("func")->SetRange(1, 10);
11534     inclusiveClone->GetFunction("func")->SetLineColor(inclusiveClone->GetLineColor());
11535   }
11536   
11537   // subtract transverse part
11538   away->Add(transverse, -1);
11539   //away3->Add(transverseSideEta1, -1);
11540   towardsCentralEta->Add(transverse, -1);
11541   towardsSideEta1->Add(transverse, -1);
11542   //inclusive->Add(transverse, -1);
11543   
11544   canvas->cd(2);
11545   towardsCentralEta->DrawCopy("SAME");
11546   towardsSideEta1->DrawCopy("SAME");
11547   away->DrawCopy("SAME");
11548   inclusive->DrawCopy("SAME");
11549   //away3->DrawCopy("SAME");
11550   
11551   canvas->cd(4);
11552   
11553   towardsCentralEtaR = (TH1*) towardsCentralEta->Clone("towardsCentralEtaR2");
11554   towardsSideEta1R = (TH1*) towardsSideEta1->Clone("towardsSideEta1R2");
11555   awayR = (TH1*) away->Clone("awayR2");
11556   
11557   towardsCentralEtaR->Divide(inclusive);
11558   towardsSideEta1R->Divide(inclusive);
11559   awayR->Divide(inclusive);
11560   
11561   towardsCentralEtaR->DrawCopy("SAME");
11562   towardsSideEta1R->DrawCopy("SAME");
11563   awayR->DrawCopy("SAME");
11564   
11565   if (fit == 1)
11566   {
11567     canvas->cd(2);
11568     
11569     away->Fit("expo", "", "SAME", 1.1, 2.9);
11570     away->GetFunction("expo")->SetRange(1, 10);
11571     gPad->SetLogx(0);
11572   }
11573   else if (fit == 2)
11574   {
11575     canvas->cd(2);
11576     
11577     func = new TF1("func", "[0] * x**[1]");
11578     func->SetParameters(1, 1);
11579     
11580     func2 = (TF1*) func->Clone();
11581     towardsCentralEta->Fit(func2, "", "SAME", limitLow, limitHigh);
11582     func2->SetRange(1, 10);
11583     
11584     func2 = (TF1*) func->Clone();
11585     towardsSideEta1->Fit(func2, "", "SAME", limitLow, limitHigh);
11586     func2->SetRange(1, 10);
11587   
11588     func2 = (TF1*) func->Clone();
11589     away->Fit(func2, "", "SAME", limitLow, limitHigh);
11590     func2->SetRange(1, 10);
11591   
11592     func2 = (TF1*) func->Clone();
11593     inclusive->Fit(func2, "", "SAME", limitLow, limitHigh);
11594     func2->SetRange(1, 10);
11595   }
11596   
11597   for (Int_t i=1; i<=2; i++)
11598   {
11599     canvas->cd(i);
11600     
11601     TString str3;
11602     str3.Form("%d-%d%%", (Int_t) h->GetCentralityDistribution()->GetXaxis()->GetBinLowEdge(centrBegin), (Int_t) h->GetCentralityDistribution()->GetXaxis()->GetBinUpEdge(centrEnd));
11603     latex = new TLatex(0.2, 0.3, str3);
11604     latex->SetNDC();
11605     latex->SetTextSize(0.06);
11606     
11607     latex2 = new TLatex(0.55, 0.6, str);
11608     latex2->SetNDC();
11609     latex2->SetTextSize(0.06);
11610     
11611     latex->Draw();
11612     latex2->Draw();
11613     
11614     legend->Draw();
11615   }
11616 }
11617
11618 void CombineDeltaPhiWithWeighting()
11619 {
11620   // From Hermes:
11621   // For LHC11a2a:
11622   // xsection: 11.879829,  ntrials: 8132994.000000
11623   // 
11624   // For LHC11a2b:
11625   // xsection: 0.623421,  ntrials: 2293420.000000
11626   // 
11627   // For LHC11a2c:
11628   // xsection: 0.043815,  ntrials: 1314525.375000
11629   
11630   // TODO is merging only same event distribution at present
11631   
11632   loadlibs();
11633   
11634   Int_t nInput = 3;
11635   const char* inputList[] = { "mergejob/LHC11a2a_110124.root", "mergejob/LHC11a2b_110131.root", "mergejob/LHC11a2c_110131.root" };
11636   
11637   Float_t xSections[] = { 11.879829 * 1e6 / 8132994, 0.623421 * 1e6 / 2293420, 0.043815 * 1e6 / 1314525 };
11638   xSections[2] /= xSections[0];
11639   xSections[1] /= xSections[0];
11640   xSections[0] /= xSections[0];
11641   
11642   AliUEHistograms* files[3];
11643   TList* finalList = 0;
11644   for (Int_t i=0; i<nInput; i++)
11645   {
11646     files[i] = (AliUEHistograms*) GetUEHistogram(inputList[i], (i == 0) ? &finalList : 0);
11647     if (i > 0) 
11648     {
11649       files[i]->Scale(xSections[i]);
11650       
11651       TList* list2 = new TList;
11652       list2->Add(files[i]);
11653       files[0]->Merge(list2);
11654     }
11655   }
11656   
11657   TFile* file3 = TFile::Open("out.root", "RECREATE");
11658   file3->mkdir("PWG4_PhiCorrelations");
11659   file3->cd("PWG4_PhiCorrelations");
11660   finalList->Write(0, TObject::kSingleKey);
11661   file3->Close();       
11662 }
11663
11664 void NormalizeToBinWidth(TH1* hist)
11665 {
11666   //
11667   // normalizes a 1-d histogram to its bin width
11668   //
11669
11670   if (hist->GetDimension() == 1)
11671   {
11672     for (Int_t i=1; i<=hist->GetNbinsX(); ++i)
11673     {
11674       hist->SetBinContent(i, hist->GetBinContent(i) / hist->GetBinWidth(i));
11675       hist->SetBinError(i, hist->GetBinError(i) / hist->GetBinWidth(i));
11676     }
11677   }
11678   else if (hist->GetDimension() == 2)
11679   {
11680     for (Int_t i=1; i<=hist->GetNbinsX(); ++i)
11681     {
11682       for (Int_t j=1; j<=hist->GetNbinsY(); ++j)
11683       {
11684         hist->SetBinContent(i, j, hist->GetBinContent(i, j) / hist->GetXaxis()->GetBinWidth(i) / hist->GetYaxis()->GetBinWidth(j));
11685         hist->SetBinError(i, j, hist->GetBinError(i) / hist->GetXaxis()->GetBinWidth(i) / hist->GetYaxis()->GetBinWidth(j));
11686       }
11687     }
11688   }
11689 }
11690
11691 void GetAcceptanceScalingFactor(const char* fileName1, Float_t eta1 = 0.8, Float_t eta2 = 1.6)
11692 {
11693   loadlibs();
11694
11695   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName1, 0, kTRUE);
11696   h->SetPtRange(1.01, 39.99);
11697  
11698   new TCanvas;
11699   mixed = ((TH2*)h->GetUEHist(2)->GetUEHist(6, 0, 1.01, 39.99, 0, 16, kTRUE))->ProjectionY();
11700   mixed->DrawCopy();
11701   
11702   Float_t left = mixed->Integral(mixed->FindBin(-eta2 + 0.01), mixed->FindBin(-eta1 - 0.01));
11703   Float_t center = mixed->Integral(mixed->FindBin(-eta1 + 0.01), mixed->FindBin(eta1 - 0.01));
11704   Float_t right = mixed->Integral(mixed->FindBin(eta1 + 0.01), mixed->FindBin(eta2 - 0.01));
11705   
11706   Printf("%f %f %f", left, center, right);
11707   Printf("%f", (left + right) / center);
11708 }
11709
11710 void TrackingEfficiencyCentralityDependence(const char* fileName, Int_t step1 = 2, Int_t step2 = 4)
11711 {
11712   Int_t nCentralityBins = 3;
11713   Float_t centralityBins[] = { 0, 20, 40, 90 };
11714   
11715   Int_t colors[] = { 1, 2, 4, 6 };
11716
11717   loadlibs();
11718
11719   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
11720   
11721   new TCanvas;
11722   dummy = new TH2F("dummy", ";p_{T};tracking efficiency", 100, 0, 20, 100, 0.7, 1.3);
11723   dummy->SetStats(0);
11724   dummy->Draw();
11725   
11726   legend = new TLegend(0.13, 0.67, 0.31, 0.87);
11727   legend->SetTextSize(0.04);
11728   legend->SetFillColor(0);
11729   
11730   for (Int_t i=0; i<nCentralityBins; i++)
11731   {
11732     eventHist = h->GetUEHist(2)->GetEventHist();
11733     
11734     eventHist->GetGrid(step1)->SetRangeUser(1, centralityBins[i] + 0.1, centralityBins[i+1] - 0.1);
11735     eventHist->GetGrid(step2)->SetRangeUser(1, centralityBins[i] + 0.1, centralityBins[i+1] - 0.1);
11736   
11737     TH1* hist1 = eventHist->ShowProjection(0, step1);
11738     TH1* hist2 = eventHist->ShowProjection(0, step2);
11739     
11740     hist2->Divide(hist1);
11741     
11742     hist2->SetLineColor(colors[i]);
11743     hist2->GetYaxis()->SetTitle("tracking efficiency");
11744     hist2->Draw("SAME");
11745     
11746     legend->AddEntry(hist2, Form("%.0f-%.0f%%", centralityBins[i], centralityBins[i+1]));
11747   }
11748   
11749   legend->Draw();
11750 }
11751
11752
11753 TGraphErrors* ReadHepdata(const char* fileName, Bool_t errorsAreAdded = kFALSE, Int_t skipYErrors = 0, Int_t skipXerrors = 1)
11754 {
11755   // expected format: x [x2] [x3] y [ye] [ye2] [xe]
11756   //
11757   // skipYErrors:   0 --> ye present
11758   //                1 --> no errors ye
11759   //                2 --> y and ye are lower and upper error, i.e. y' = (y + ye) / 2 and ye = (ye - y) / 2
11760   //                3 --> ye and ye2 are stat and syst error, will be added in quadrature
11761   // 
11762   // skipXerrors:   0 --> xe present
11763   //                1 --> no errors xe
11764   //                2 --> x2 present, xe not present and is calculated from x2 - x
11765   //                3 --> x2 and x3 present, ignored
11766   
11767   ifstream fin(fileName);
11768
11769   graph = new TGraphErrors(0);
11770
11771   Double_t sum = 0;
11772
11773   while (fin.good())
11774   {
11775     char buffer[2000];
11776     if (fin.peek() == '#')
11777     {
11778       fin.getline(buffer, 2000);
11779       continue;
11780     }
11781   
11782     Double_t x = -1;
11783     Double_t x2 = -1;
11784     Double_t y = -1;
11785     Double_t ye = 0;
11786     Double_t xe = 0;
11787
11788     fin >> x;
11789     
11790     if (skipXerrors == 2)
11791     {
11792       fin >> x2;
11793       xe = (x2 - x + 1) / 2;
11794       x = x + (x2 - x) / 2;
11795     }
11796     
11797     if (skipXerrors == 3)
11798     {
11799       fin >> x2;
11800       fin >> x2;
11801     }
11802     
11803     fin >> y;
11804
11805     if (y == -1)
11806       continue;
11807
11808     if (skipYErrors == 0)
11809     {
11810       ye = -1;
11811       fin >> ye;
11812       if (ye == -1)
11813         continue;
11814     }
11815     else if (skipYErrors == 2)
11816     {
11817       ye = -1;
11818       fin >> ye;
11819       if (ye == -1)
11820         continue;
11821       
11822       Double_t newy = (y + ye) / 2;
11823       ye = (ye - y) / 2;
11824       y = newy;
11825     }
11826     else if (skipYErrors == 3)
11827     {
11828       ye = -1;
11829       fin >> ye;
11830       if (ye == -1)
11831         continue;
11832       
11833       Double_t ye2 = -1;
11834       fin >> ye2;
11835       if (ye2 == -1)
11836         continue;
11837
11838       ye = TMath::Sqrt(ye*ye + ye2*ye2);
11839     }
11840
11841     if (skipXerrors == 0)
11842     {
11843       xe = -1;
11844       fin >> xe;
11845       if (xe == -1)
11846         continue;
11847     }
11848
11849     //Printf("%f %f %f %f", x, y, xe, ye);
11850
11851     if (errorsAreAdded)
11852       ye -= y;
11853
11854     graph->SetPoint(graph->GetN(), x, y);
11855     graph->SetPointError(graph->GetN()-1, xe, ye);
11856
11857     sum += y;
11858     
11859     // read rest until end of line...
11860     fin.getline(buffer, 2000);
11861   }
11862   fin.close();
11863
11864   Printf("%s: %f", fileName, sum);
11865
11866   return graph;
11867 }
11868
11869 void EvaluateParticleEfficiency(const char* fileName)
11870 {
11871   Int_t centralityBegin = 1;
11872   Int_t centralityEnd = 15;
11873   
11874   if (1)
11875   {
11876     Int_t step1 = 4;
11877     Int_t step2 = 5;
11878   }
11879   else
11880   {
11881     Int_t step1 = 2;
11882     Int_t step2 = 4;
11883   }
11884   
11885   Float_t ptTriggerBegin = 4.01;
11886   Float_t ptTriggerEnd = 19.99;
11887   
11888   Bool_t verbose = 1;
11889   
11890   loadlibs();
11891   
11892   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
11893   AliUEHist* cont = h->GetUEHist(2);
11894   
11895   cont->GetEventHist()->GetGrid(step1)->GetGrid()->GetAxis(1)->SetRange(centralityBegin, centralityEnd);
11896   cont->GetEventHist()->GetGrid(step2)->GetGrid()->GetAxis(1)->SetRange(centralityBegin, centralityEnd);
11897   
11898   Int_t stepEff1 = step1 - (Int_t) AliUEHist::kCFStepAnaTopology;
11899   if (stepEff1 == -1)
11900     stepEff1 = 0;
11901   Int_t stepEff2 = step2 - (Int_t) AliUEHist::kCFStepAnaTopology;
11902   if (stepEff2 == -1)
11903     stepEff2 = 0;
11904   
11905   cont->GetTrackHistEfficiency()->GetGrid(stepEff1)->GetGrid()->GetAxis(3)->SetRange(centralityBegin, centralityEnd);
11906   cont->GetTrackHistEfficiency()->GetGrid(stepEff2)->GetGrid()->GetAxis(3)->SetRange(centralityBegin, centralityEnd);
11907   
11908   TH1* triggerParticle = cont->GetEventHist()->Project(step2, 0);
11909   triggerParticle->Divide(cont->GetEventHist()->Project(step1, 0));
11910   
11911   TH1* singleParticle = cont->GetTrackHistEfficiency()->Project(stepEff2, 1);
11912   singleParticle->Divide(cont->GetTrackHistEfficiency()->Project(stepEff1, 1));
11913   
11914   //singleParticle = singleParticle->Rebin(triggerParticle->GetNbinsX(), "singleRebin", triggerParticle->GetXaxis()->GetXbins()->GetArray());
11915   
11916   TGraphErrors* effectiveEffect = new TGraphErrors;
11917   TGraphErrors* triggerCorrelatedEffect = new TGraphErrors;
11918   TGraphErrors* afterBaseLine = new TGraphErrors;
11919   TGraphErrors* triggerCorrelatedEffect2D = new TGraphErrors;
11920   
11921   //TVirtualFitter::SetDefaultFitter("Linear");
11922   
11923   for (Int_t bin=3; bin<=triggerParticle->GetNbinsX(); bin++)
11924   {
11925     if (triggerParticle->GetBinCenter(bin) > 10)
11926       continue;
11927     
11928     cont->SetPtRange(triggerParticle->GetXaxis()->GetBinLowEdge(bin) + 0.01, triggerParticle->GetXaxis()->GetBinUpEdge(bin) - 0.01);
11929       
11930     TH1* hist1 = cont->GetUEHist(step1, 0, ptTriggerBegin, ptTriggerEnd, centralityBegin, centralityEnd);
11931     TH1* hist2 = cont->GetUEHist(step2, 0, ptTriggerBegin, ptTriggerEnd, centralityBegin, centralityEnd);
11932     
11933     // TODO the uncertainties on the ratios should be properly calculated! (if that helps ;))
11934     clone = (TH1*) hist2->Clone("clone");
11935     clone->Divide(hist1);
11936     
11937     //func = new TF1("func", "[0]", -10, 10);
11938     
11939     if ((Int_t) clone->Fit("pol0", "0", "", -10, 10) == 0)
11940     {
11941       func = clone->GetFunction("pol0");
11942       effectiveEffect->SetPoint(effectiveEffect->GetN(), triggerParticle->GetBinCenter(bin) - 0.2, func->GetParameter(0));
11943       effectiveEffect->SetPointError(effectiveEffect->GetN()-1, 0, func->GetParError(0));
11944       
11945       if (verbose)
11946       {
11947         new TCanvas;
11948         clone->GetYaxis()->SetRangeUser(0.9, 1.3);
11949         clone->Draw();
11950         func->DrawClone("SAME");
11951       }
11952     }
11953     
11954     if ((Int_t) clone->Fit("pol0", "0", "", -0.3, 0.3) == 0)
11955     {
11956       func = clone->GetFunction("pol0");
11957       triggerCorrelatedEffect->SetPoint(triggerCorrelatedEffect->GetN(), triggerParticle->GetBinCenter(bin) - 0.1, func->GetParameter(0));
11958       triggerCorrelatedEffect->SetPointError(triggerCorrelatedEffect->GetN()-1, 0, func->GetParError(0));
11959       
11960       if (verbose)
11961       {
11962         func->SetLineColor(2);
11963         func->DrawClone("SAME");
11964       }
11965     }
11966     
11967     if ((Int_t) hist2->Fit("pol0", "0", "", 1, 2) == 0)
11968     {
11969       func = hist2->GetFunction("pol0");
11970       func->SetRange(-10, 10);
11971       hist2->Add(func, -1);
11972     
11973       if ((Int_t) hist1->Fit("pol0", "0", "", 1, 2) == 0)
11974       {
11975         func = hist1->GetFunction("pol0");
11976         func->SetRange(-10, 10);
11977         hist1->Add(func, -1);
11978         
11979         //new TCanvas; hist1->DrawCopy();
11980         
11981         hist2->Divide(hist1);
11982         
11983         if ((Int_t) hist2->Fit("pol0", "0", "", -0.3, 0.3) == 0)
11984         {
11985           func = hist2->GetFunction("pol0");
11986           afterBaseLine->SetPoint(afterBaseLine->GetN(), triggerParticle->GetBinCenter(bin) + 0.2, func->GetParameter(0));
11987           afterBaseLine->SetPointError(afterBaseLine->GetN()-1, 0, func->GetParError(0));
11988         
11989           if (verbose)
11990           {
11991             new TCanvas;
11992             hist2->GetYaxis()->SetRangeUser(0.9, 1.3);
11993             hist2->DrawCopy();
11994             func->SetLineColor(4);
11995             func->DrawClone("SAME");
11996           }
11997         }
11998       }
11999     }
12000       
12001     // 2d
12002     TH2* hist1_2D = cont->GetUEHist(step1, 0, ptTriggerBegin, ptTriggerEnd, centralityBegin, centralityEnd, 1);
12003     TH2* hist2_2D = cont->GetUEHist(step2, 0, ptTriggerBegin, ptTriggerEnd, centralityBegin, centralityEnd, 1);
12004     
12005     //((TH2*)hist1)->Rebin2D(2, 2); ((TH2*)hist2)->Rebin2D(2, 2);
12006     
12007     hist2_2D->Divide(hist1_2D);
12008     
12009     if (verbose)
12010     {
12011       new TCanvas;
12012       hist2_2D->Draw("COLZ");
12013     }
12014     
12015     //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));
12016     
12017     Double_t error;
12018     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);
12019     
12020     integral /= hist2_2D->GetXaxis()->FindBin(0.01) - hist2_2D->GetXaxis()->FindBin(-0.01) + 1;
12021     integral /= hist2_2D->GetYaxis()->FindBin(0.01) - hist2_2D->GetYaxis()->FindBin(-0.01) + 1;
12022     
12023     error /= hist2_2D->GetXaxis()->FindBin(0.01) - hist2_2D->GetXaxis()->FindBin(-0.01) + 1;
12024     error /= hist2_2D->GetYaxis()->FindBin(0.01) - hist2_2D->GetYaxis()->FindBin(-0.01) + 1;
12025     
12026     triggerCorrelatedEffect2D->SetPoint(triggerCorrelatedEffect2D->GetN(), triggerParticle->GetBinCenter(bin) + 0.1, integral);
12027     triggerCorrelatedEffect2D->SetPointError(triggerCorrelatedEffect2D->GetN()-1, 0, error);
12028     
12029     if (verbose)
12030       break;
12031   }
12032   
12033   new TCanvas;
12034   triggerParticle->Draw();
12035   triggerParticle->GetXaxis()->SetRangeUser(0, 9.9);
12036   
12037   singleParticle->SetLineColor(2);
12038   //singleParticle->Draw("SAME");
12039   
12040   effectiveEffect->SetMarkerStyle(24);
12041   effectiveEffect->Draw("PSAME");
12042   
12043   triggerCorrelatedEffect->SetMarkerStyle(25);
12044   triggerCorrelatedEffect->SetMarkerColor(2);
12045   triggerCorrelatedEffect->SetLineColor(2);
12046   triggerCorrelatedEffect->Draw("PSAME");
12047   
12048   triggerCorrelatedEffect2D->SetMarkerStyle(27);
12049   triggerCorrelatedEffect2D->SetMarkerColor(3);
12050   triggerCorrelatedEffect2D->SetLineColor(3);
12051   triggerCorrelatedEffect2D->Draw("PSAME");
12052   
12053   afterBaseLine->SetMarkerStyle(26);
12054   afterBaseLine->SetMarkerColor(4);
12055   afterBaseLine->SetLineColor(4);
12056   afterBaseLine->Draw("PSAME");
12057
12058   legend = new TLegend(0.66, 0.15, 0.88, 0.38);
12059   legend->SetFillColor(0);
12060   legend->SetTextSize(0.04);
12061   legend->AddEntry(triggerParticle, "trigger", "L");
12062   //legend->AddEntry(singleParticle, "single", "L");
12063   legend->AddEntry(effectiveEffect, "effective", "P");
12064   legend->AddEntry(triggerCorrelatedEffect, "at 0", "P");
12065   legend->AddEntry(triggerCorrelatedEffect2D, "at 0 (2d)", "P");
12066   legend->AddEntry(afterBaseLine, "baseline", "P");
12067   legend->Draw();
12068 }
12069
12070 void EvaluateParticleEfficiency2D(const char* fileName)
12071 {
12072   Int_t centralityBegin = 1;
12073   Int_t centralityEnd = 15;
12074   
12075   if (1)
12076   {
12077     Int_t step1 = 4;
12078     Int_t step2 = 5;
12079   }
12080   else
12081   {
12082     Int_t step1 = 2;
12083     Int_t step2 = 4;
12084   }
12085   
12086   Bool_t verbose = 0;
12087   
12088   loadlibs();
12089   
12090   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
12091   AliUEHist* cont = h->GetUEHist(2);
12092   
12093   cont->GetEventHist()->GetGrid(step1)->GetGrid()->GetAxis(1)->SetRange(centralityBegin, centralityEnd);
12094   cont->GetEventHist()->GetGrid(step2)->GetGrid()->GetAxis(1)->SetRange(centralityBegin, centralityEnd);
12095   
12096   Int_t stepEff1 = step1 - (Int_t) AliUEHist::kCFStepAnaTopology;
12097   if (stepEff1 == -1)
12098     stepEff1 = 0;
12099   Int_t stepEff2 = step2 - (Int_t) AliUEHist::kCFStepAnaTopology;
12100   if (stepEff2 == -1)
12101     stepEff2 = 0;
12102   
12103   cont->GetTrackHistEfficiency()->GetGrid(stepEff1)->GetGrid()->GetAxis(3)->SetRange(centralityBegin, centralityEnd);
12104   cont->GetTrackHistEfficiency()->GetGrid(stepEff2)->GetGrid()->GetAxis(3)->SetRange(centralityBegin, centralityEnd);
12105   
12106   TH1* triggerParticle = cont->GetEventHist()->Project(step2, 0);
12107   triggerParticle->Divide(cont->GetEventHist()->Project(step1, 0));
12108   
12109   TH1* singleParticle = cont->GetTrackHistEfficiency()->Project(stepEff2, 1);
12110   singleParticle->Divide(cont->GetTrackHistEfficiency()->Project(stepEff1, 1));
12111   
12112   cont->GetTrackHist(0)->GetGrid(step1)->SetRangeUser(0, -0.01, 0.01); // delta eta
12113   cont->GetTrackHist(0)->GetGrid(step1)->SetRangeUser(4, -0.01, 0.01); // delta phi
12114   TH2* tracksStep1 = (TH2*) cont->GetTrackHist(0)->Project(step1, 1, 2);
12115   
12116   cont->GetTrackHist(0)->GetGrid(step2)->SetRangeUser(0, -0.01, 0.01); // delta eta
12117   cont->GetTrackHist(0)->GetGrid(step2)->SetRangeUser(4, -0.01, 0.01); // delta phi
12118   TH2* tracksStep2 = (TH2*) cont->GetTrackHist(0)->Project(step2, 1, 2);
12119   
12120   tracksStep2->Divide(tracksStep1);
12121   
12122   TH1* triggersStep1 = cont->GetEventHist()->Project(step1, 0);
12123   TH1* triggersStep2 = cont->GetEventHist()->Project(step2, 0);
12124   
12125   for (Int_t x=1; x<=tracksStep2->GetNbinsX(); x++)
12126     for (Int_t y=1; y<=tracksStep2->GetNbinsY(); y++)
12127       if (singleParticle->GetBinContent(x) > 0)
12128         tracksStep2->SetBinContent(x, y, tracksStep2->GetBinContent(x, y) / triggersStep2->GetBinContent(y) * triggersStep1->GetBinContent(y) / singleParticle->GetBinContent(x));
12129       else
12130         tracksStep2->SetBinContent(x, y, 0);
12131   
12132   new TCanvas;
12133   tracksStep2->Draw("COLZ");
12134   
12135   TGraphErrors** triggerCorrelatedEffect2D = new TGraphErrors*[triggerParticle->GetNbinsX()+1];
12136   TGraphErrors** triggerCorrelatedEffect2DSub = new TGraphErrors*[triggerParticle->GetNbinsX()+1];
12137   
12138   for (Int_t bin1=0; bin1<=triggerParticle->GetNbinsX(); bin1++)
12139   {
12140     triggerCorrelatedEffect2D[bin1] = 0;
12141     triggerCorrelatedEffect2DSub[bin1] = 0;
12142   }
12143   
12144   for (Int_t bin1=5; bin1<=triggerParticle->GetNbinsX(); bin1++)
12145   {
12146     if (triggerParticle->GetBinCenter(bin1) > 10)
12147       continue;
12148     
12149     Float_t ptTriggerBegin = triggerParticle->GetXaxis()->GetBinLowEdge(bin1) + 0.01;
12150     Float_t ptTriggerEnd = triggerParticle->GetXaxis()->GetBinUpEdge(bin1) - 0.01;
12151     
12152     for (Int_t bin2=3; bin2<=triggerParticle->GetNbinsX(); bin2++)
12153     {
12154       if (triggerParticle->GetBinCenter(bin2) > 8)
12155         continue;
12156         
12157       if (bin2 > bin1)
12158         continue;
12159     
12160       cont->SetPtRange(triggerParticle->GetXaxis()->GetBinLowEdge(bin2) + 0.01, triggerParticle->GetXaxis()->GetBinUpEdge(bin2) - 0.01);
12161   
12162       // 2d
12163       TH2* hist1_2D = cont->GetUEHist(step1, 0, ptTriggerBegin, ptTriggerEnd, centralityBegin, centralityEnd, 1);
12164       TH2* hist2_2D = cont->GetUEHist(step2, 0, ptTriggerBegin, ptTriggerEnd, centralityBegin, centralityEnd, 1);
12165       
12166       //((TH2*)hist1)->Rebin2D(2, 2); ((TH2*)hist2)->Rebin2D(2, 2);
12167       
12168       hist2_2D->Divide(hist1_2D);
12169       
12170       if (verbose)
12171       {
12172         new TCanvas;
12173         hist2_2D->Draw("COLZ");
12174       }
12175       
12176       //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));
12177       
12178       Double_t error;
12179       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);
12180       
12181       integral /= hist2_2D->GetXaxis()->FindBin(0.01) - hist2_2D->GetXaxis()->FindBin(-0.01) + 1;
12182       integral /= hist2_2D->GetYaxis()->FindBin(0.01) - hist2_2D->GetYaxis()->FindBin(-0.01) + 1;
12183       
12184       error /= hist2_2D->GetXaxis()->FindBin(0.01) - hist2_2D->GetXaxis()->FindBin(-0.01) + 1;
12185       error /= hist2_2D->GetYaxis()->FindBin(0.01) - hist2_2D->GetYaxis()->FindBin(-0.01) + 1;
12186       
12187       if (integral <= 0)
12188         continue;
12189       
12190       if (!triggerCorrelatedEffect2D[bin1])
12191         triggerCorrelatedEffect2D[bin1] = new TGraphErrors;
12192         
12193       triggerCorrelatedEffect2D[bin1]->SetPoint(triggerCorrelatedEffect2D[bin1]->GetN(), triggerParticle->GetBinCenter(bin2) - 0.5 + 0.1 * bin1, integral);
12194       triggerCorrelatedEffect2D[bin1]->SetPointError(triggerCorrelatedEffect2D[bin1]->GetN()-1, 0, error);
12195     
12196       if (!triggerCorrelatedEffect2DSub[bin1])
12197         triggerCorrelatedEffect2DSub[bin1] = new TGraphErrors;
12198         
12199       triggerCorrelatedEffect2DSub[bin1]->SetPoint(triggerCorrelatedEffect2DSub[bin1]->GetN(), triggerParticle->GetBinCenter(bin2) - 0.5 + 0.1 * bin1, integral / triggerParticle->GetBinContent(bin2));
12200       triggerCorrelatedEffect2DSub[bin1]->SetPointError(triggerCorrelatedEffect2DSub[bin1]->GetN()-1, 0, error / triggerParticle->GetBinContent(bin2));
12201       
12202       if (verbose)
12203         break;
12204     }
12205       
12206     if (verbose)
12207       break;
12208   }
12209   
12210   new TCanvas;
12211   triggerParticle->Draw();
12212   triggerParticle->GetXaxis()->SetRangeUser(0, 9.9);
12213   
12214   legend = new TLegend(0.66, 0.15, 0.88, 0.38);
12215   legend->SetFillColor(0);
12216   legend->SetTextSize(0.04);
12217   legend->AddEntry(triggerParticle, "trigger", "L");
12218   
12219   Int_t marker = 20;
12220   Int_t color = 1;
12221   
12222   for (Int_t bin1=3; bin1<=triggerParticle->GetNbinsX(); bin1++)
12223     if (triggerCorrelatedEffect2D[bin1])
12224     {
12225       triggerCorrelatedEffect2D[bin1]->SetMarkerStyle(marker++);
12226       triggerCorrelatedEffect2D[bin1]->SetMarkerColor(color);
12227       triggerCorrelatedEffect2D[bin1]->SetLineColor(color++);
12228       triggerCorrelatedEffect2D[bin1]->Draw("PSAME");
12229       legend->AddEntry(triggerCorrelatedEffect2D[bin1], Form("pt %.2f", triggerParticle->GetBinCenter(bin1)), "P");
12230     }
12231   
12232   legend->Draw();
12233
12234   new TCanvas;
12235   triggerParticle->Draw();
12236   triggerParticle->GetXaxis()->SetRangeUser(0, 9.9);
12237   
12238   marker = 20;
12239   color = 1;
12240   
12241   for (Int_t bin1=3; bin1<=triggerParticle->GetNbinsX(); bin1++)
12242     if (triggerCorrelatedEffect2DSub[bin1])
12243     {
12244       triggerCorrelatedEffect2DSub[bin1]->SetMarkerStyle(marker++);
12245       triggerCorrelatedEffect2DSub[bin1]->SetMarkerColor(color);
12246       triggerCorrelatedEffect2DSub[bin1]->SetLineColor(color++);
12247       triggerCorrelatedEffect2DSub[bin1]->Draw("PSAME");
12248     }
12249   
12250   legend->Draw();
12251 }
12252
12253 void DrawEventCount(const char* fileName, Int_t step = 8)
12254 {
12255   loadlibs();
12256   
12257   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
12258   h->GetEventCount()->Draw("TEXT");
12259   
12260   eventCount = h->GetEventCount();
12261   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));
12262   Printf("Events: %f", events);
12263 }
12264
12265 void FitDCADistributions(const char* fileName1)
12266 {
12267   loadlibs();
12268   
12269   TFile::Open(fileName1);
12270   list = (TList*) gFile->Get("histosPhiCorrelationsQA");
12271   prim = (TH2*) list->FindObject("fDCAPrimaries");
12272   sec  = (TH2*) list->FindObject("fDCASecondaries");
12273   
12274   Float_t zCut = 0.5;
12275
12276   TH2* histList[] = { prim, sec };
12277
12278   TH1* primProj = 0;
12279   TH1* secProj = 0;
12280   
12281   for (Int_t i=0; i<2; i++)
12282   {
12283     new TCanvas;
12284     gPad->SetGridx();
12285     gPad->SetGridy();
12286     gPad->SetLogy();
12287   
12288 //     hist = histList[i]->ProjectionX("proj", prim->GetYaxis()->FindBin(-zCut), prim->GetYaxis()->FindBin(zCut))->DrawCopy("");
12289     hist = histList[i]->ProjectionY("proj", prim->GetXaxis()->FindBin(-zCut), prim->GetXaxis()->FindBin(zCut))->DrawCopy("");
12290     hist->SetStats(0);
12291     
12292     func = new TF1("func", "gaus(0)+gaus(3)");
12293     func->SetParameters(1e6, 0, 0.02, 1e3, 0, 2);
12294     func->FixParameter(1, 0);
12295     func->FixParameter(4, 0);
12296     func->SetParLimits(2, 0, 0.1);
12297     func->SetParLimits(5, 1, 3);
12298     
12299     hist->Fit(func, "", "", -2, 2);
12300     
12301     func2 = new TF1("func2", "gaus(0)");
12302     func2->SetParameters(1e3, 0, 2);
12303     func2->FixParameter(1, 0);
12304     func2->SetParLimits(2, 0.5, 5);
12305     
12306     hist->Fit(func2, "+", "", -2, -1);
12307     func2->SetRange(-3, 3);
12308     func2->Draw("SAME");
12309
12310 //     break;
12311   }
12312 }
12313
12314 void CompareDCADistributions(const char* fileName1, const char* fileName2)
12315 {
12316   TFile::Open(fileName1);
12317   list = (TList*) gFile->Get("histosPhiCorrelationsQA");
12318   prim = (TH2*) list->FindObject("fDCAPrimaries");
12319   sec  = (TH2*) list->FindObject("fDCASecondaries");
12320   
12321   TFile::Open(fileName2);
12322   list = (TList*) gFile->Get("histosPhiCorrelationsQA");
12323   all = (TH2*) list->FindObject("fDCAPrimaries");
12324   
12325   Float_t zCut = 3.2;
12326   
12327   TH2* histList[] = { prim, sec, all };
12328   
12329   Float_t count = 0;
12330   
12331   TH1* primProj = 0;
12332   TH1* secProj = 0;
12333   
12334   new TCanvas;
12335   gPad->SetGridx();
12336   gPad->SetGridy();
12337   
12338   for (Int_t i=0; i<3; i++)
12339   {
12340     hist = histList[i]->ProjectionX("proj", prim->GetYaxis()->FindBin(-zCut), prim->GetYaxis()->FindBin(zCut))->DrawCopy(i>0?"SAME":"");
12341     hist->SetStats(0);
12342     //hist = histList[i]->ProjectionY("proj", prim->GetXaxis()->FindBin(-zCut), prim->GetXaxis()->FindBin(zCut))->DrawCopy(i>0?"SAME":"");
12343     hist->SetLineColor(i+1);
12344     if (i == 0)
12345       primProj = hist;
12346     if (i == 1)
12347       secProj = hist;
12348     if (i == 2)
12349       hist->Scale(1.0 / hist->Integral(hist->GetXaxis()->FindBin(-0.5), hist->GetXaxis()->FindBin(0.5)) * count);
12350     else
12351       count += hist->Integral(hist->GetXaxis()->FindBin(-0.5), hist->GetXaxis()->FindBin(0.5));
12352   }
12353   
12354   gPad->SetLogy();
12355   
12356   ratio = (TH1*) hist->Clone("ratio");
12357   ratio->Add(primProj, -1);
12358   
12359 /*  for (Int_t i=hist->GetXaxis()->FindBin(-0.1); i<=hist->GetXaxis()->FindBin(0.1); i++)
12360     ratio->SetBinContent(i, 0);*/
12361   
12362   for (Int_t i=1; i<=hist->GetNbinsX(); i++)
12363     ratio->SetBinError(i, 0);
12364   
12365   ratio->SetLineColor(4);
12366   ratio->DrawCopy("SAME E");
12367   
12368   new TCanvas;
12369   gPad->SetGridx();
12370   gPad->SetGridy();
12371   
12372   ratio->Rebin(4);
12373   secProj = (TH1*) secProj->Clone();
12374   secProj->Rebin(4);
12375   
12376   ratio->Divide(secProj);
12377   
12378 /*  for (Int_t i=1; i<=hist->GetNbinsX(); i++)
12379     ratio->SetBinError(i, 0);*/
12380   
12381   ratio->Draw("HIST");
12382   ratio->GetYaxis()->SetRangeUser(0.7, 1.3);
12383   
12384   ratio->Fit("pol0", "0+", "", -5, -1);
12385   ratio->Fit("pol0", "0+", "", 1, 5);
12386 }
12387  
12388 void TrackCuts_CompareParameters(const char* fileName1, const char* fileName2, const char* histName, const char* cutFolder = "cuts_quality_only")
12389 {
12390   // plotWhich: 0 = only before
12391   //            1 = both
12392   //            2 = only after
12393   //
12394   // mirror: kTRUE --> project negative values on the positive side
12395   
12396   Int_t plotWhich = 0;
12397   Bool_t mirror = kFALSE;
12398   
12399   TFile* files[2];
12400   files[0] = TFile::Open(fileName1);
12401   files[1] = TFile::Open(fileName2);
12402
12403   Int_t count = 0;
12404   Int_t colors[] = { 1, 2, 3, 4, 5, 6 };
12405
12406   TLegend* legend = new TLegend(0.7, 0.85, 0.93, 0.98);
12407   legend->SetTextSize(0.04);
12408   legend->SetFillColor(0);
12409
12410   TCanvas* c1 = new TCanvas(histName, histName, 1200, 600);
12411   c1->Divide(2, 1);
12412   //TCanvas* c2 = new TCanvas("c2", "c2", 800, 600);
12413   //TCanvas* c3 = new TCanvas("c3", "c3", 800, 600);
12414
12415   const char* folders2[] = { "before_cuts", "after_cuts" };
12416   const char* names[] = { "MC", "Data" };
12417   Bool_t first = kTRUE;
12418   for (Int_t j = ((plotWhich < 2) ? 0 : 1); j < ((plotWhich > 0) ? 2 : 1); j++)
12419   {
12420     TH1* base = 0;
12421     TH1* base2 = 0;
12422     for (Int_t i = 0; i < 2; i++)
12423     {
12424       Printf("%d %d", j, i);
12425       TString folder;
12426       folder.Form("%s/%s/%s", cutFolder, folders2[j], histName);
12427       TH1* hist = (TH1*) files[i]->Get(folder);
12428       
12429       if (mirror)
12430       {
12431         for (Int_t bin=1; bin<=hist->GetXaxis()->FindBin(-0.0001); bin++)
12432         {
12433           Int_t newBin = hist->GetXaxis()->FindBin(-hist->GetXaxis()->GetBinCenter(bin));
12434           if (bin != newBin)
12435           {
12436             hist->Fill(-hist->GetXaxis()->GetBinCenter(bin), hist->GetBinContent(bin));
12437             hist->SetBinContent(bin, 0);
12438           }
12439         }
12440       }
12441       
12442       legend->AddEntry(hist, Form("%s %s", names[i], (plotWhich == 1) ? folders2[j] : " "));
12443
12444       c1->cd(1);
12445       hist->SetLineColor(colors[count]);
12446       hist->Scale(1.0 / hist->Integral());
12447       hist->SetStats(0);
12448       hist->DrawCopy((count == 0) ? "" : "SAME");
12449
12450       switch (i)
12451       {
12452         case 0: base = hist; break;
12453         case 1: base2 = hist; break;
12454       }
12455
12456       count++;
12457     }
12458     
12459     TH1* ratio = base;
12460     ratio->Divide(base2);
12461
12462     ratio->GetYaxis()->SetRangeUser(0, 2);
12463     
12464     c1->cd(2);
12465     ratio->DrawCopy((first) ? "" : "SAME");
12466     first = kFALSE;
12467   }
12468
12469   c1->cd(1)->SetLogy();
12470   c1->cd(1)->SetGridx();
12471   c1->cd(1)->SetGridy();
12472   legend->Draw();
12473   
12474   c1->cd(2)->SetGridx();
12475   c1->cd(2)->SetGridy();
12476   
12477   c1->SaveAs(Form("%s.png", histName));
12478 }
12479
12480 void PlotQA(const char* fileName, const char* tag = "")
12481 {
12482   loadlibs();
12483   
12484   if (!gGrid && TString(fileName).BeginsWith("alien://"))
12485     TGrid::Connect("alien://");
12486   
12487   TFile::Open(fileName);
12488   
12489   // phys sel
12490   Int_t runNumber = 0;
12491   list = (TList*) gFile->Get("PhysSel");
12492   if (list)
12493   {
12494     physSel = (AliPhysicsSelection*) list->FindObject("AliPhysicsSelection");
12495 //     runNumber = physSel->GetCurrentRun();
12496   }
12497   
12498   TString tmp(fileName);
12499   tmp.ReplaceAll("alien:///alice/cern.ch/user/j/jgrosseo/gridjob/dir_", "");
12500   tmp.ReplaceAll(".root", ".png");
12501   tmp.ReplaceAll("/", "-");
12502   TString title;
12503   title.Form("QA_%d_%s", runNumber, tmp.Data());
12504   c = new TCanvas(title, title, 1200, 800);
12505   c->Divide(3, 3);
12506
12507   // QA task
12508   list = (TList*) gFile->Get("histosPhiCorrelationsQA");
12509   if (list)
12510   {
12511     prim = (TH2*) list->FindObject("fDCAPrimaries");
12512     dcaxy = prim->ProjectionX("dcaxy", prim->GetYaxis()->FindBin(-3.2), prim->GetYaxis()->FindBin(3.2));
12513     dcaz = prim->ProjectionY("dcaz", prim->GetXaxis()->FindBin(-2.4), prim->GetXaxis()->FindBin(2.4));
12514     centrCorr = (TH2*) list->FindObject("fCentralityCorrelation");
12515     
12516     c->cd(1); dcaxy->Draw(); dcaz->SetLineColor(2); dcaz->Draw("SAME");  gPad->SetLogy(); 
12517     c->cd(6); centrCorr->Draw("COLZ"); gPad->SetLogz();
12518   
12519     cuts = (AliESDtrackCuts*) list->FindObject("cuts_quality_dca");
12520     if (cuts)
12521     {
12522       cluster = cuts->GetNClustersTPC(1);
12523       c->cd(3); cluster->Draw();
12524     
12525       ptall = (TH1F*) cuts->GetPtHist(1)->Clone("ptall");
12526       if (ptall->Integral() > 0)
12527         ptall->Scale(1.0 / ptall->Integral());
12528     
12529       c->cd(7); 
12530       ptall->Draw(); 
12531
12532       TH1* ptIts = 0;
12533       check_its = (AliESDtrackCuts*) list->FindObject("check_its");
12534       if (check_its)
12535       {
12536         ptIts = (TH1F*) check_its->GetPtHist(1)->Clone("ptIts");
12537         if (ptIts->Integral() > 0)
12538           ptIts->Scale(1.0 / ptIts->Integral());
12539       }
12540       
12541       TH1* ptItsAcc = 0;
12542       global_cuts = (AliESDtrackCuts*) list->FindObject("global_cuts");
12543       if (global_cuts)
12544       {
12545         ptItsAcc = (TH1*) global_cuts->GetPtHist(1)->Clone("ptItsAcc");
12546         if (ptItsAcc->Integral() > 0)
12547           ptItsAcc->Scale(1.0 / ptItsAcc->Integral());
12548       }
12549     
12550       if (ptIts)
12551       {
12552         ptIts->SetLineColor(2); 
12553         ptIts->Draw("SAME");
12554       }
12555       
12556       if (ptItsAcc)
12557       {
12558         ptItsAcc->SetLineColor(4); 
12559         ptItsAcc->Draw("SAME"); 
12560       }
12561       
12562       gPad->SetLogy();
12563     }
12564   }
12565   
12566   // centrality task
12567   list = (TList*) gFile->Get("CentralityStat");
12568   TH1* centrQuality = 0;
12569   if (list)
12570   {
12571     centrQuality = (TH1*) list->FindObject("fHOutQuality");
12572     
12573     c->cd(4); if (centrQuality) centrQuality->Draw();
12574   }
12575   
12576   // phi corr task
12577   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName, 0, kFALSE, tag);
12578   
12579   if (h->GetUEHist(2)->GetTrackHist(0)->GetGrid(6)->GetGrid()->GetNbins() == 0)
12580   {
12581     Printf("We have %d axes", ((AliTHn*) h->GetUEHist(2)->GetTrackHist(0)->GetNVar()));
12582     
12583 //     ((AliTHn*) h->GetUEHist(2)->GetTrackHist(0))->ReduceAxis();
12584     ((AliTHn*) h->GetUEHist(2)->GetTrackHist(0))->FillParent();
12585     ((AliTHn*) h->GetUEHist(2)->GetTrackHist(0))->DeleteContainers();
12586   }
12587   centr = h->GetCentralityDistribution();
12588   NormalizeToBinWidth(centr);
12589   Int_t events = (Int_t) h->GetEventCount()->ProjectionX()->GetBinContent(3);
12590   Int_t mergeCount = h->GetMergeCount();
12591   
12592   h->SetPtRange(1.01, 3.99);
12593   dphi_corr = h->GetUEHist(2)->GetUEHist(AliUEHist::kCFStepReconstructed, 0, 1.01, 14.99, 1, 8);
12594   if (dphi_corr->GetEntries() == 0)
12595     dphi_corr = h->GetUEHist(2)->GetUEHist(AliUEHist::kCFStepReconstructed+2, 0, 1.01, 14.99, 1, 8);
12596   if (dphi_corr->GetEntries() == 0)
12597     dphi_corr = h->GetUEHist(2)->GetUEHist(AliUEHist::kCFStepAll, 0, 1.01, 14.99, 1, 8);
12598   
12599   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE, tag);
12600   if (hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(6)->GetGrid()->GetNbins() == 0)
12601   {
12602 //     ((AliTHn*) hMixed->GetUEHist(2)->GetTrackHist(0))->ReduceAxis();
12603     ((AliTHn*) hMixed->GetUEHist(2)->GetTrackHist(0))->FillParent();
12604   }
12605
12606   Float_t ptMin = 0.51;
12607   hMixed->SetPtRange(ptMin, 3.99);
12608   dphi_corr_mixed = hMixed->GetUEHist(2)->GetUEHist(AliUEHist::kCFStepReconstructed, 0, ptMin, 14.99, 1, 8);
12609   if (dphi_corr_mixed->GetEntries() == 0)
12610     dphi_corr_mixed = hMixed->GetUEHist(2)->GetUEHist(AliUEHist::kCFStepReconstructed+2, 0, ptMin, 14.99, 1, 8);
12611   if (dphi_corr_mixed->GetEntries() == 0)
12612     dphi_corr_mixed = hMixed->GetUEHist(2)->GetUEHist(AliUEHist::kCFStepAll, 0, ptMin, 14.99, 1, 8);
12613   
12614   if (runNumber != 0 && runNumber != h->GetRunNumber())
12615     AliFatal("Run numbers inconsistent");
12616
12617   Printf("%d", h->GetRunNumber());
12618   if (runNumber == 0)
12619     runNumber = h->GetRunNumber();
12620  
12621   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");
12622   c->cd(5); centr->Draw("HIST");
12623   
12624   c->cd(1);
12625   latex = new TLatex(0.15, 0.8, Form("%d events, %d merged objects", events, mergeCount));
12626   latex->SetTextSize(0.075);
12627   latex->SetNDC();
12628   latex->Draw();
12629   
12630   c->cd(8);
12631   h->GetEventCount()->Draw("TEXT");
12632   
12633   title.Form("QA_%d_%s", runNumber, tmp.Data());
12634   c->SetTitle(title);
12635   
12636   gpTMin = 1.01;
12637   gpTMax = 1.99;
12638   h->SetPtRange(gpTMin, gpTMax);
12639   hMixed->SetPtRange(gpTMin, gpTMax);
12640  
12641   TH2* hist1 = 0;
12642   
12643   //h->GetUEHist(2)->SetSkipScaleMixedEvent(kTRUE);
12644   
12645   if (h->GetUEHist(2)->GetTrackHist(0)->GetNVar() > 5)
12646   {
12647     Int_t step = 8;
12648     
12649     c->cd(3);
12650     GetDistAndFlow(h, 0, &hist1,  0, step, 0, 20, 2.01, 2.99, 1);
12651     hist1->DrawCopy("SURF1");
12652
12653     c->cd(6);
12654     GetDistAndFlow(hMixed, 0, &hist1,  0, step, 0, 20, 2.01, 2.99, 1);
12655     hist1->DrawCopy("SURF1");
12656     
12657     c->cd(9);
12658     GetSumOfRatios(h, hMixed, &hist1, step, 0, 20, 2.01, 2.99, kTRUE); 
12659     if (hist1)
12660       hist1->DrawCopy("SURF1");  
12661   }
12662
12663   c->SaveAs(Form("qa/%s", c->GetTitle()));
12664 }
12665
12666 void GetEventNumber(const char* fileName)
12667 {
12668   loadlibs();
12669   
12670   new TCanvas("c1", "", 800, 600);
12671  
12672   Int_t nEvent = 0;
12673
12674   TFile::Open(fileName);
12675   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
12676   centr = h->GetCentralityDistribution();
12677   nEvent = h->GetCentralityDistribution()->Integral(h->GetCentralityDistribution()->FindBin(0.01), h->GetCentralityDistribution()->FindBin(59.99));
12678
12679   cout << "Number of events: " <<  nEvent << endl;
12680   centr->Draw("HIST");
12681 }
12682 void CompareStepsOnePlot(const char* fileName, Int_t caseId)
12683 {
12684   loadlibs();
12685
12686   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
12687   
12688   Int_t stepList[] = { 0, 1, 2, 4, 5, 6 };
12689   Int_t stepListNames[] = { 0, 1, 2, 3, 4, 5 };
12690   Int_t nSteps = 6;
12691   //const char* names[] = { "All", "PhysSel+Vertex", "Reco Primaries", "Reco "
12692 //   //Int_t stepList[] = { 2, 4, 5, 6 };
12693 //   
12694 //   
12695 //   TH1* hist1 = h->GetUEHist(2)->GetUEHist(0, 0, 6.01, 9.99, 6, 14);
12696 //   TH1* hist2 = h->GetUEHist(2)->GetUEHist(0, 0, 6.01, 7.99, 6, 14);
12697 //   TH1* hist3 = h->GetUEHist(2)->GetUEHist(0, 0, 8.01, 9.99, 6, 14);
12698 //   
12699 //   hist1->Draw();
12700 //   hist2->SetLineColor(2);
12701 //   hist2->Draw("SAME");
12702 //   hist3->SetLineColor(4);
12703 //   hist3->Draw("SAME");
12704 //   return;
12705 //   
12706   
12707   legend = new TLegend(0.65, 0.45, 0.85, 0.85);
12708   legend->SetTextSize(0.04);
12709   legend->SetFillColor(0);
12710   
12711   TH1* histList[10];
12712   
12713   for (Int_t i=0; i<nSteps; i++)
12714   {
12715     //TH1* hist1 = h->GetUEHist(2)->GetEventHist()->Project(stepList[i], 0);
12716     
12717 /*    h->GetUEHist(2)->GetTrackHist(0)->GetGrid(stepList[i])->GetGrid()->GetAxis(1)->SetRangeUser(1.01, 3.99);
12718     h->GetUEHist(2)->GetTrackHist(0)->GetGrid(stepList[i])->GetGrid()->GetAxis(2)->SetRangeUser(4.01, 19.99);
12719     TH1* hist1 = h->GetUEHist(2)->GetTrackHist(0)->Project(stepList[i], 4);*/
12720     
12721     if (caseId == 0)
12722       TH1* hist1 = h->GetUEHist(2)->GetUEHist(stepList[i], 0, 1.01, 19.99);
12723     else if (caseId == 1)
12724       TH1* hist1 = h->GetUEHist(2)->GetEventHist()->Project(stepList[i], 0);
12725     
12726     //hist1->Rebin(2);
12727     //hist1->Rebin(4);
12728     hist1->SetMarkerStyle(24+i);
12729     hist1->SetTitle("");
12730     hist1->SetStats(0);
12731     hist1->DrawCopy((i==0)?"":"SAME");
12732     hist1->Fit("pol0", "0");
12733     //hist1->Fit("pol0");
12734     histList[i] = hist1;
12735     legend->AddEntry(hist1, Form("Step %d", stepListNames[i]), "P");
12736   }
12737   
12738   legend->Draw();
12739   
12740   new TCanvas;
12741   legend = new TLegend(0.65, 0.45, 0.85, 0.85);
12742   legend->SetTextSize(0.04);
12743   legend->SetFillColor(0);
12744   
12745   for (Int_t i=1; i<nSteps; i++)
12746   {
12747     histList[i]->DrawCopy((i==1)?"":"SAME")->Divide(histList[i-1]);
12748     legend->AddEntry(histList[i], Form("Step %d/%d", stepListNames[i], stepListNames[i-1]), "P");
12749   }
12750   
12751   legend->Draw();
12752   
12753   new TCanvas;
12754   for (Int_t i=0; i<nSteps; i++)
12755   {
12756     hist1 = histList[i];
12757     func = new TF1("func", "[0]", -10, 10);
12758     hist1->Fit(func, "0", "", 1, 2);
12759     hist1->Add(func, -1);
12760     hist1->DrawCopy((i==0)?"":"SAME");
12761   }
12762   
12763   legend->Draw();
12764   
12765   new TCanvas;
12766   for (Int_t i=1; i<nSteps; i++)
12767   {
12768     histList[i]->DrawCopy((i==1)?"":"SAME")->Divide(histList[i-1]);
12769   }
12770   
12771   legend->Draw();
12772 }
12773
12774 void PtShift(const char* fileName)
12775 {
12776   loadlibs();
12777
12778   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
12779   
12780   new TCanvas;
12781   gPad->SetLogy();
12782   
12783   ptHist3 = h->GetCorrelationpT()->ProjectionY();
12784   ptHist3->GetXaxis()->SetRangeUser(0, 20);
12785   //ptHist3->Sumw2();
12786   
12787   /*
12788   func = new TF1("func", "[0]+[1]*x**[2]", 4, 20);
12789   func->SetParLimits(2, -10, -1);
12790   func->SetParameters(0, 1, -4);
12791   ptHist3->Fit(func, "", "", 4, 20);
12792   
12793   return;
12794   */
12795   
12796   ptHist3Shifted = (TH1*) ptHist3->Clone("ptHist3Shifted");
12797   for (Int_t i=1; i<ptHist3Shifted->GetNbinsX(); i++)
12798     //ptHist3Shifted->SetBinContent(i, ptHist3Shifted->GetBinContent(i+3));
12799     ptHist3Shifted->SetBinContent(i, ptHist3Shifted->GetBinContent(1.1*i));
12800   
12801   // 10% or 750 MeV
12802     
12803   ptHist3Shifted->SetLineColor(2);
12804   
12805   ptHist3->Rebin(2);
12806   ptHist3Shifted->Rebin(2);
12807   
12808   ptHist3->DrawCopy();
12809   ptHist3Shifted->DrawCopy("SAME");
12810   
12811   new TCanvas;
12812   ptHist3->Divide(ptHist3Shifted);
12813   ptHist3->Draw();
12814   
12815   //ptHist3->Rebin(2); ptHist3->Scale(1.0 / 2);
12816   
12817   gPad->SetGridx();
12818   gPad->SetGridy();
12819 }
12820
12821 void RAA(const char* fileName, const char* fileName2)
12822 {
12823   loadlibs();
12824   
12825   TH1* hist[2];
12826   
12827   for (Int_t j=0; j<2; j++)
12828   {
12829     if (j == 0)
12830       AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
12831     else
12832     {
12833       if (!fileName2)
12834         break;
12835         
12836       AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName2);
12837     }
12838   
12839     ptHist3 = h->GetCorrelationpT()->ProjectionY(Form("proj1_%d", j), 1, 5);
12840     ptHist3->GetXaxis()->SetRangeUser(0, 20);
12841     
12842     //h->GetCentralityDistribution()->Draw(); new TCanvas;
12843     
12844     Int_t nEvents = h->GetCentralityDistribution()->Integral(h->GetCentralityDistribution()->FindBin(0.01), h->GetCentralityDistribution()->FindBin(4.99));
12845     Printf("%d", nEvents);
12846     ptHist3->Scale(1.0 / 1.6 / TMath::TwoPi() / nEvents / ptHist3->GetBinWidth(1));
12847     
12848     hist[j] = ptHist3;
12849   }
12850   
12851   new TCanvas;
12852   hist[0]->DrawCopy("");
12853   hist[1]->DrawCopy("SAME")->SetLineColor(2);
12854   gPad->SetLogy();
12855   
12856   new TCanvas;
12857   hist[1]->Divide(hist[0]);
12858   hist[1]->DrawCopy();
12859   
12860   raa_central = ReadHepdata("raa_alice_central.txt", kFALSE, 3);
12861   raa_central->SetMarkerStyle(20);
12862   raa_central->Draw("PSAME");
12863 }
12864
12865 void PtComparison(const char* fileName, const char* fileName2 = 0, const char* tag = 0)
12866 {
12867   loadlibs();
12868
12869   c = new TCanvas;
12870   c2 = new TCanvas;
12871   c2->SetGridx();
12872   c2->SetGridy();
12873     
12874   for (Int_t j=0; j<2; j++)
12875   {
12876     if (j == 0)
12877       AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName, 0, kFALSE, tag);
12878     else
12879     {
12880       if (!fileName2)
12881         break;
12882         
12883       AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName2, 0, kFALSE, tag);
12884     }
12885     
12886     ptHist3 = h->GetInvYield()->ProjectionY("pt1", h->GetInvYield()->GetXaxis()->FindBin(0.01), h->GetInvYield()->GetXaxis()->FindBin(4.99));
12887     ptHist3->GetXaxis()->SetRangeUser(0, 20);
12888     
12889     //h->GetCentralityDistribution()->Draw(); new TCanvas;
12890     
12891     Int_t nEvents = h->GetCentralityDistribution()->Integral(h->GetCentralityDistribution()->FindBin(0.01), h->GetCentralityDistribution()->FindBin(4.99));
12892     Printf("%d", nEvents);
12893     ptHist3->Scale(1.0 / 1.6 / TMath::TwoPi() / nEvents / ptHist3->GetBinWidth(1));
12894     
12895     c->cd();
12896     ptHist3->SetLineStyle(j+1);
12897     ptHist3->DrawCopy((j == 0) ? "HIST" : "HISTSAME")->SetLineColor(1);
12898     
12899     centralPt = (TH1*) ptHist3->Clone();
12900   
12901     if (1)
12902     {
12903       ptHist3 = h->GetInvYield()->ProjectionY("pt2", h->GetInvYield()->GetXaxis()->FindBin(70.01), h->GetInvYield()->GetXaxis()->FindBin(79.99));
12904       ptHist3->GetXaxis()->SetRangeUser(0, 20);
12905     
12906       Int_t nEvents = h->GetCentralityDistribution()->Integral(h->GetCentralityDistribution()->FindBin(70.1), h->GetCentralityDistribution()->FindBin(79.9));
12907       Printf("%d", nEvents);
12908       ptHist3->Scale(1.0 / 1.6 / TMath::TwoPi() / nEvents / ptHist3->GetBinWidth(1));
12909     
12910       ptHist3->SetLineStyle(j+1);
12911       ptHist3->DrawCopy("HISTSAME")->SetLineColor(2);
12912     }
12913     peripheralPt = (TH1*) ptHist3->Clone();
12914
12915     if (1)
12916     {
12917       ptHist3 = h->GetInvYield()->ProjectionY("pt3", h->GetInvYield()->GetXaxis()->FindBin(20.01), h->GetInvYield()->GetXaxis()->FindBin(29.99));
12918       ptHist3->GetXaxis()->SetRangeUser(0, 20);
12919     
12920       Int_t nEvents = h->GetCentralityDistribution()->Integral(h->GetCentralityDistribution()->FindBin(20.1), h->GetCentralityDistribution()->FindBin(29.9));
12921       Printf("%d", nEvents);
12922       ptHist3->Scale(1.0 / 1.6 / TMath::TwoPi() / nEvents / ptHist3->GetBinWidth(1));
12923     
12924       ptHist3->SetLineStyle(j+1);
12925       ptHist3->DrawCopy("HISTSAME")->SetLineColor(4);
12926     }
12927     
12928     if (0)
12929     {
12930       // first paper
12931       dndpt_central = ReadHepdata("raa_dndpt_central.txt", kFALSE, 3);
12932       dndpt_peripheral = ReadHepdata("raa_dndpt_peripheral.txt", kFALSE, 3);
12933     }
12934     else
12935     {
12936       // second paper
12937       dndpt_central = ReadHepdata("raa2_dndpt_05.txt", kFALSE, 1, 3);
12938       dndpt_midcentral = ReadHepdata("raa2_dndpt_2030.txt", kFALSE, 1, 3);
12939       dndpt_peripheral = ReadHepdata("raa2_dndpt_7080.txt", kFALSE, 1, 3);
12940     }
12941   
12942 //   RemovePointsBelowX(dndpt_central, 1);
12943 //   RemovePointsBelowX(dndpt_peripheral, 1);
12944 //   
12945 //   NormalizeTo(dndpt_central, 1);
12946 //   NormalizeTo(dndpt_peripheral, 10);
12947
12948     dndpt_central->Draw("*SAME");
12949     dndpt_peripheral->SetLineColor(2);
12950     dndpt_peripheral->SetMarkerColor(2);
12951     dndpt_peripheral->Draw("*SAME");
12952     dndpt_midcentral->SetLineColor(4);
12953     dndpt_midcentral->SetMarkerColor(4);
12954     dndpt_midcentral->Draw("*SAME");
12955     
12956     gPad->SetLogy();
12957     
12958     c2->cd();
12959     
12960     for (Int_t i=1; i<ptHist3->GetNbinsX(); i++)
12961       ptHist3->SetBinContent(i, ptHist3->GetBinContent(i) / dndpt_midcentral->Eval(ptHist3->GetBinCenter(i), 0, "S"));
12962   
12963     for (Int_t i=1; i<centralPt->GetNbinsX(); i++)
12964       centralPt->SetBinContent(i, centralPt->GetBinContent(i) / dndpt_central->Eval(centralPt->GetBinCenter(i), 0, "S"));
12965   
12966     for (Int_t i=1; i<peripheralPt->GetNbinsX(); i++)
12967       peripheralPt->SetBinContent(i, peripheralPt->GetBinContent(i) / dndpt_peripheral->Eval(peripheralPt->GetBinCenter(i), 0, "S"));
12968
12969 //     ptHist3->Rebin(2); ptHist3->Scale(0.5);
12970 //     centralPt->Rebin(2); centralPt->Scale(0.5);
12971   
12972     ptHist3->GetXaxis()->SetRangeUser(0.51, 19);
12973     ptHist3->GetYaxis()->SetRangeUser(0.5, 1.5);
12974     ptHist3->DrawCopy((j == 0) ? "" : "SAME")->SetLineColor(4);
12975     centralPt->DrawCopy("SAME")->SetLineColor(1);
12976     peripheralPt->DrawCopy("SAME")->SetLineColor(2);
12977   }
12978 }
12979
12980 void PtComparisonOld(const char* fileName, const char* fileName2 = 0)
12981 {
12982   // use GetCorrectedYields to get input file
12983   
12984   loadlibs();
12985
12986   c = new TCanvas;
12987   c2 = new TCanvas;
12988   c2->SetGridx();
12989   c2->SetGridy();
12990     
12991   for (Int_t j=0; j<2; j++)
12992   {
12993     if (j == 0)
12994     {
12995       TFile::Open(fileName);
12996     }
12997     else
12998     {
12999       if (!fileName2)
13000         break;
13001         
13002       TFile::Open(fileName2);
13003     }
13004     yieldCorr = (TH3F*) gFile->Get("fYieldsCorr");
13005     eventDist = (TH1*) gFile->Get("events");
13006     
13007     //new TCanvas; h->GetCorrelationpT()->Draw("COLZ");
13008     
13009     yieldCorr->GetXaxis()->SetRangeUser(0.1, 4.9);
13010     yieldCorr->GetZaxis()->SetRangeUser(-0.79, 0.79);
13011     
13012     ptHist3 = yieldCorr->Project3D(Form("y1_%d", j));
13013     ptHist3->GetXaxis()->SetRangeUser(0, 20);
13014     
13015     //h->GetCentralityDistribution()->Draw(); new TCanvas;
13016     
13017     Int_t nEvents = eventDist->Integral(eventDist->FindBin(0.1), eventDist->FindBin(4.9));
13018     Printf("%d", nEvents);
13019     ptHist3->Scale(1.0 / 1.6 / TMath::TwoPi() / nEvents / ptHist3->GetBinWidth(1));
13020     
13021     //ptHist3->Scale(1690);
13022     //ptHist3->Scale(1.0 / ptHist3->Integral(ptHist3->GetXaxis()->FindBin(1.01), ptHist3->GetNbinsX()) / 3 / 0.6);
13023     
13024     for (Int_t i=2; i<ptHist3->GetNbinsX(); i++)
13025       ptHist3->SetBinContent(i, ptHist3->GetBinContent(i) / ptHist3->GetBinCenter(i));
13026       //ptHist3->SetBinContent(i, ptHist3->GetBinContent(i) / ptHist3->GetBinLowEdge(i));
13027     
13028     //AliPWG0Helper::NormalizeToBinWidth(ptHist3);
13029     
13030     c->cd();
13031     ptHist3->SetLineStyle(j+1);
13032     ptHist3->DrawCopy((j == 0) ? "HIST" : "HISTSAME")->SetLineColor(1);
13033
13034     centralPt = (TH1*) ptHist3->Clone();
13035   
13036     if (1)
13037     {
13038       yieldCorr->GetZaxis()->SetRangeUser(-0.79, 0.79);
13039       yieldCorr->GetXaxis()->SetRangeUser(70.1, 79.9);
13040       ptHist3 = yieldCorr->Project3D(Form("y2_%d", j));
13041       ptHist3->GetXaxis()->SetRangeUser(0, 20);
13042     
13043       Int_t nEvents = eventDist->Integral(eventDist->FindBin(70.1), eventDist->FindBin(79.9));
13044       Printf("%d", nEvents);
13045       ptHist3->Scale(1.0 / 1.6 / TMath::TwoPi() / nEvents / ptHist3->GetBinWidth(1));
13046     
13047       for (Int_t i=2; i<ptHist3->GetNbinsX(); i++)
13048         ptHist3->SetBinContent(i, ptHist3->GetBinContent(i) / ptHist3->GetBinCenter(i));
13049         //ptHist3->SetBinContent(i, ptHist3->GetBinContent(i) / ptHist3->GetBinLowEdge(i));
13050
13051       ptHist3->SetLineStyle(j+1);
13052       ptHist3->DrawCopy("HISTSAME")->SetLineColor(2);
13053     }
13054     peripheralPt = (TH1*) ptHist3->Clone();
13055
13056     if (1)
13057     {
13058       yieldCorr->GetZaxis()->SetRangeUser(-0.79, 0.79);
13059       yieldCorr->GetXaxis()->SetRangeUser(20.1, 29.9);
13060       ptHist3 = yieldCorr->Project3D(Form("y2_%d", j));
13061       ptHist3->GetXaxis()->SetRangeUser(0, 20);
13062     
13063       Int_t nEvents = eventDist->Integral(eventDist->FindBin(20.1), eventDist->FindBin(29.9));
13064       Printf("%d", nEvents);
13065       ptHist3->Scale(1.0 / 1.6 / TMath::TwoPi() / nEvents / ptHist3->GetBinWidth(1));
13066     
13067       for (Int_t i=2; i<ptHist3->GetNbinsX(); i++)
13068         ptHist3->SetBinContent(i, ptHist3->GetBinContent(i) / ptHist3->GetBinCenter(i));
13069         //ptHist3->SetBinContent(i, ptHist3->GetBinContent(i) / ptHist3->GetBinLowEdge(i));
13070
13071       ptHist3->SetLineStyle(j+1);
13072       ptHist3->DrawCopy("HISTSAME")->SetLineColor(4);
13073     }
13074     
13075     if (0)
13076     {
13077       // first paper
13078       dndpt_central = ReadHepdata("raa_dndpt_central.txt", kFALSE, 3);
13079       dndpt_peripheral = ReadHepdata("raa_dndpt_peripheral.txt", kFALSE, 3);
13080     }
13081     else
13082     {
13083       // second paper
13084       dndpt_central = ReadHepdata("raa2_dndpt_05.txt", kFALSE, 1, 3);
13085       dndpt_midcentral = ReadHepdata("raa2_dndpt_2030.txt", kFALSE, 1, 3);
13086       dndpt_peripheral = ReadHepdata("raa2_dndpt_7080.txt", kFALSE, 1, 3);
13087     }
13088   
13089 //   RemovePointsBelowX(dndpt_central, 1);
13090 //   RemovePointsBelowX(dndpt_peripheral, 1);
13091 //   
13092 //   NormalizeTo(dndpt_central, 1);
13093 //   NormalizeTo(dndpt_peripheral, 10);
13094
13095     dndpt_central->Draw("*SAME");
13096     dndpt_peripheral->SetLineColor(2);
13097     dndpt_peripheral->SetMarkerColor(2);
13098     dndpt_peripheral->Draw("*SAME");
13099     dndpt_midcentral->SetLineColor(4);
13100     dndpt_midcentral->SetMarkerColor(4);
13101     dndpt_midcentral->Draw("*SAME");
13102     
13103     gPad->SetLogy();
13104     
13105     c2->cd();
13106     
13107     for (Int_t i=1; i<ptHist3->GetNbinsX(); i++)
13108       ptHist3->SetBinContent(i, ptHist3->GetBinContent(i) / dndpt_midcentral->Eval(ptHist3->GetBinCenter(i), 0, "S"));
13109   
13110     for (Int_t i=1; i<centralPt->GetNbinsX(); i++)
13111       centralPt->SetBinContent(i, centralPt->GetBinContent(i) / dndpt_central->Eval(centralPt->GetBinCenter(i), 0, "S"));
13112   
13113     for (Int_t i=1; i<peripheralPt->GetNbinsX(); i++)
13114       peripheralPt->SetBinContent(i, peripheralPt->GetBinContent(i) / dndpt_peripheral->Eval(peripheralPt->GetBinCenter(i), 0, "S"));
13115
13116 //     ptHist3->Rebin(2); ptHist3->Scale(0.5);
13117 //     centralPt->Rebin(2); centralPt->Scale(0.5);
13118   
13119     ptHist3->GetXaxis()->SetRangeUser(0.51, 19);
13120     ptHist3->GetYaxis()->SetRangeUser(0.5, 1.5);
13121     ptHist3->DrawCopy((j == 0) ? "" : "SAME")->SetLineColor(4);
13122     centralPt->DrawCopy("SAME")->SetLineColor(1);
13123     peripheralPt->DrawCopy("SAME")->SetLineColor(2);
13124   }
13125
13126   return;
13127   
13128   ReadYields("preliminaries/yields_110303.root");
13129   
13130   ptHist3->Scale(100);
13131   
13132   TGraphErrors** tmp = yields[0][1][0];
13133   nearSide = tmp[18];
13134   nearSide->Draw("* SAME");  
13135  
13136   TGraphErrors** tmp = yields[1][1][0];
13137   awaySide = tmp[18];
13138   awaySide->SetLineColor(2);
13139   awaySide->SetMarkerColor(2);
13140   awaySide->Draw("* SAME");  
13141   
13142 }
13143
13144 void style(Int_t styleId = 1)
13145 {
13146   gStyle->SetPalette(1);
13147   gStyle->SetCanvasColor(10);
13148   gStyle->SetHistFillColor(10);
13149   gStyle->SetHistFillStyle(0);
13150   gStyle->SetOptStat(0);
13151   gStyle->SetPadTickX(1);
13152   gStyle->SetPadTickY(1);
13153   gStyle->SetAxisColor(1, "X");
13154   gStyle->SetAxisColor(1, "Y");
13155   gStyle->SetAxisColor(1, "Z");
13156   gStyle->SetLabelColor(1, "X");
13157   gStyle->SetLabelColor(1, "Y");
13158   gStyle->SetLabelColor(1, "Z");
13159   gStyle->SetTickLength(0.03, "X");
13160   gStyle->SetTickLength(0.03, "Y");
13161   gStyle->SetTickLength(0.03, "Z");
13162   gStyle->SetTitleXSize(0.05);
13163   gStyle->SetTitleYSize(0.05);
13164   gStyle->SetNdivisions(506, "X");
13165   gStyle->SetNdivisions(506, "Y");
13166   gStyle->SetNdivisions(506, "Z");
13167   
13168   //gStyle->SetPadGridX(1);
13169   //gStyle->SetPadGridY(1);
13170
13171   //gStyle->SetLabelOffset(0.02, "X");
13172   //gStyle->SetLabelOffset(0.02, "Y");
13173   //gStyle->SetLabelOffset(0.02, "Z");
13174   gStyle->SetLabelSize(0.05, "X");
13175   gStyle->SetLabelSize(0.05, "Y");
13176   gStyle->SetLabelSize(0.05, "Z");
13177
13178   gStyle->SetPadLeftMargin(0.12);
13179   gStyle->SetPadRightMargin(0.02);
13180   gStyle->SetPadBottomMargin(0.13);
13181   gStyle->SetPadTopMargin(0.02);
13182
13183   gStyle->SetMarkerSize(1.4); // CKB
13184
13185   const int iFont = 42; // type * 10 + prec  6: helvetica bold 13: times normal 2: times bold
13186
13187 /*                                                               italic     weigth
13188 *-*        1 : times-medium-i-normal      "Times New Roman"      1           4
13189 *-*        2 : times-bold-r-normal        "Times New Roman"      0           7
13190 *-*        3 : times-bold-i-normal        "Times New Roman"      1           7
13191 *-*        4 : helvetica-medium-r-normal  "Arial"                0           4
13192 *-*        5 : helvetica-medium-o-normal  "Arial"                1           4
13193 *-*        6 : helvetica-bold-r-normal    "Arial"                0           7
13194 *-*        7 : helvetica-bold-o-normal    "Arial"                1           7
13195 *-*        8 : courier-medium-r-normal    "Courier New"          0           4
13196 *-*        9 : courier-medium-o-normal    "Courier New"          1           4
13197 *-*       10 : courier-bold-r-normal      "Courier New"          0           7
13198 *-*       11 : courier-bold-o-normal      "Courier New"          1           7
13199 *-*       12 : symbol-medium-r-normal     "Symbol"               0           6
13200 *-*       13 : times-medium-r-normal      "Times New Roman"      0           4
13201 *-*       14 :                            "Wingdings"            0           4
13202 */
13203
13204   //gStyle->SetTitleXOffset(1); // 1.1
13205   //gStyle->SetTitleYOffset(1); // 1-4
13206
13207   gStyle->SetLabelFont(iFont, "xyz");
13208   gStyle->SetStatFont(iFont);
13209   gStyle->SetTitleFont(iFont, "xyz");
13210   gStyle->SetTextFont(iFont);
13211   
13212   if (styleId == 2)
13213   {
13214     gStyle->SetLabelSize(0.07, "X");
13215     gStyle->SetLabelSize(0.07, "Y");
13216     gStyle->SetLabelSize(0.07, "Z");
13217     gStyle->SetTitleXSize(0.07);
13218     gStyle->SetTitleYSize(0.07);
13219   
13220     gStyle->SetPadLeftMargin(0.26);
13221     gStyle->SetPadRightMargin(0.01);
13222     gStyle->SetPadBottomMargin(0.15);
13223     gStyle->SetPadTopMargin(0.01);
13224   }
13225
13226   //gStyle->SetEndErrorSize(0.0);
13227
13228   gROOT->ForceStyle();
13229
13230 }
13231
13232 void NormalizeTo(TGraphErrors* graph, Float_t normalizeTo)
13233 {
13234         Float_t sum = 0;
13235         for (Int_t i=0; i<graph->GetN(); i++)
13236                 sum += graph->GetY()[i];
13237         
13238         if (normalizeTo > 0 && sum > 0)
13239         {
13240                 sum /= normalizeTo;
13241                 for (Int_t i=0; i<graph->GetN(); i++)
13242                 {
13243                         graph->SetPoint(i, graph->GetX()[i],  graph->GetY()[i] / sum);
13244                         graph->SetPointError(i, graph->GetEX()[i],  graph->GetEY()[i] / sum);
13245                 }
13246         }       
13247 }
13248
13249 void CompareMixedEvent(const char* fileName)
13250 {
13251   loadlibs();
13252   
13253   Float_t leadingPtArr[] = { 6.0, 8.0, 10.0, 15.0, 15.0 };
13254   Float_t assocPtArr[] =     { 0.5, 1.5, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
13255   Int_t leadingPtOffset = 2;
13256   Int_t centralityBins[] = { 0, 0, 1, 6, 9, 16 };
13257
13258   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);  
13259   
13260   Int_t i = 1;
13261   for (Int_t j=2; j<5; j++)
13262   {
13263     gpTMin = assocPtArr[j] + 0.01;
13264     gpTMax = assocPtArr[j+1] - 0.01;
13265     
13266     gpTMin = 3.0;
13267     gpTMax = 6.0;
13268
13269     SetupRanges(hMixed);
13270     
13271     TH2* mixed = hMixed->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, centralityBins[j], centralityBins[j+1]-1, 1);
13272   
13273     // compare deta
13274     
13275     TH1* histMixedproj = mixed->ProjectionY();
13276     histMixedproj->Scale(1.0 / mixed->GetNbinsX());
13277     
13278     for (Int_t x=1; x<=mixed->GetNbinsX(); x++)
13279       for (Int_t y=1; y<=mixed->GetNbinsY(); y++)
13280         mixed->SetBinContent(x, y, histMixedproj->GetBinContent(y));
13281
13282     histMixedproj->Scale(1.0 / (0.5 * (histMixedproj->GetBinContent(histMixedproj->GetXaxis()->FindBin(-0.01)) + histMixedproj->GetBinContent(histMixedproj->GetXaxis()->FindBin(0.01)))));
13283       
13284     histMixedproj->DrawCopy((j == 2) ? "" : "SAME")->SetLineColor(j-1);
13285   }
13286 }
13287
13288 void FillParentTHnSparse(const char* fileName, Bool_t reduce = kFALSE, const char* tag = "")
13289 {
13290   TString fileNameStr(fileName);
13291   
13292   if (fileNameStr.BeginsWith("/alice"))
13293   {
13294     fileNameStr = Form("alien://%s", fileNameStr.Data());
13295     if (fileNameStr.EndsWith("merge"))
13296       fileNameStr += "/AnalysisResults.root";
13297   }
13298   
13299   if (fileNameStr.BeginsWith("alien:"))
13300     TGrid::Connect("alien:");
13301   
13302   loadlibs();
13303
13304   TList* list = 0;
13305   
13306   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileNameStr, &list, kFALSE, tag);
13307   Printf("We have %d axes", ((AliTHn*) h->GetUEHist(2)->GetTrackHist(0)->GetNVar()));
13308   
13309   if (reduce)
13310     ((AliTHn*) h->GetUEHist(2)->GetTrackHist(0))->ReduceAxis();
13311   ((AliTHn*) h->GetUEHist(2)->GetTrackHist(0))->FillParent();
13312   ((AliTHn*) h->GetUEHist(2)->GetTrackHist(0))->DeleteContainers();
13313   
13314   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileNameStr, 0, kTRUE, tag);
13315   if (reduce)
13316     ((AliTHn*) hMixed->GetUEHist(2)->GetTrackHist(0))->ReduceAxis();
13317   ((AliTHn*) hMixed->GetUEHist(2)->GetTrackHist(0))->FillParent();
13318   ((AliTHn*) hMixed->GetUEHist(2)->GetTrackHist(0))->DeleteContainers();
13319   
13320   TString newFileName(fileNameStr);
13321
13322   if (fileNameStr.BeginsWith("alien:"))
13323     newFileName = gSystem->BaseName(newFileName);
13324   
13325   newFileName.ReplaceAll(".root", "");
13326   if (reduce)
13327     newFileName += "_.root";
13328   else
13329     newFileName += "_zvtx.root";
13330
13331   TFile *file3 = TFile::Open(newFileName, "RECREATE");
13332   file3->mkdir("PWG4_PhiCorrelations");
13333   file3->cd("PWG4_PhiCorrelations");
13334   list->Write("histosPhiCorrelations", TObject::kSingleKey);
13335   file3->Close();
13336   delete file3;
13337 }
13338
13339 void CompareZVertex(const char* fileName)
13340 {
13341   loadlibs();
13342   
13343   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
13344   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);  
13345   
13346   axis = h->GetUEHist(2)->GetEventHist()->GetAxis(2, 6);
13347   
13348   gpTMin = 2.01;
13349   gpTMax = 7.99;
13350   
13351   SetupRanges(h);
13352   SetupRanges(hMixed);
13353   
13354   TFile::Open("test.root", "RECREATE");
13355         
13356   for (Int_t i=0; i<=axis->GetNbins(); i++)
13357   {
13358     TH1* hist = 0;
13359     if (i > 0)
13360     {
13361       Printf("%d %f %f", i, axis->GetBinLowEdge(i) + 0.01, axis->GetBinUpEdge(i) - 0.01);
13362       h->SetZVtxRange(axis->GetBinLowEdge(i) + 0.01, axis->GetBinUpEdge(i) - 0.01);
13363       hMixed->SetZVtxRange(axis->GetBinLowEdge(i) + 0.01, axis->GetBinUpEdge(i) - 0.01);
13364     }
13365       
13366     GetDistAndFlow(h, hMixed, &hist, 0, 6, 0, 10, 2.01, 14.99, 1, kTRUE, 0, kFALSE);
13367     
13368     new TCanvas;
13369     hist->DrawCopy("SURF1");
13370     
13371     hist->Write(Form("detadphi_%d", i));
13372     
13373 //     if (i == 0)   break;
13374
13375     continue;
13376     
13377     hist->SetLineColor(i+1);
13378     hist->Scale(1.0 / hist->Integral() / hist->GetBinWidth(1));
13379     hist->Draw((i == 0) ? "" : "SAME");
13380   }
13381   
13382   gFile->Close();
13383 }
13384
13385 void DrawZRanges(Float_t min, Float_t max)
13386 {
13387   legend = new TLegend(0.5, 0.5, 0.8, 0.8);
13388   
13389   TFile::Open("test.root");
13390   
13391   for (Int_t i=0; i<8; i++)
13392   {
13393     if (i == 1 || i == 7)
13394       continue;
13395     
13396     hist = (TH2*) gFile->Get(Form("detadphi_%d", i));
13397     hist->Rebin2D(2, 2);
13398     hist->Scale(0.25);
13399     
13400     proj = hist->ProjectionY("proj", hist->GetXaxis()->FindBin(min), hist->GetXaxis()->FindBin(max));
13401     proj->Scale(1.0 / (hist->GetXaxis()->FindBin(max) - hist->GetXaxis()->FindBin(min) + 1));
13402     
13403     proj->SetLineColor(i+1);
13404     proj->DrawCopy((i == 0) ? "" : "SAME HIST");
13405     
13406     legend->AddEntry(proj->Clone(), Form("%d", i));
13407   }
13408   
13409   legend->Draw();
13410 }
13411
13412 void PlotTrackingEfficiency(const char* fileName)
13413 {
13414   loadlibs();
13415   
13416   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
13417   
13418   c = new TCanvas("c", "c", 600, 600);
13419   gPad->SetLeftMargin(0.15);
13420
13421   h->SetEtaRange(-0.89, 0.89);
13422   
13423   Float_t centralityBins[] = { 0, 10, 20, 40, 60, 100 };
13424   Int_t nCentralityBins = 5;
13425   
13426   legend = new TLegend(0.2, 0.15, 0.46, 0.42);
13427   legend->SetFillColor(0);
13428   
13429   Int_t colors[] = { 1, 2, 3, 4, 6 };
13430
13431   for (Int_t i=0; i<nCentralityBins; i++)
13432   {
13433     h->GetUEHist(2)->SetCentralityRange(centralityBins[i] + 0.1, centralityBins[i+1] - 0.1);
13434     proj = h->GetUEHist(2)->GetTrackingEfficiency(1);
13435     proj->GetYaxis()->SetRangeUser(0.7, 0.9);
13436     proj->GetXaxis()->SetRangeUser(0.5, 9.9);
13437     proj->GetYaxis()->SetTitleOffset(1.5);
13438     proj->SetTitle("");
13439     proj->GetYaxis()->SetTitle("Tracking efficiency");
13440     proj->SetMarkerColor(colors[i]);
13441     proj->SetLineColor(colors[i]);
13442     proj->SetStats(0);
13443     projClone = proj->DrawClone((i == 0) ? "" : "SAME");
13444     
13445     legend->AddEntry(projClone, Form("%.0f-%.0f%%", centralityBins[i], centralityBins[i+1]));
13446   }
13447   
13448   legend->Draw();  
13449 //   DrawLatex(0.58, 0.85, 1, "HIJING Pb-Pb 2.76 TeV", 0.03);
13450 //   DrawLatex(0.58, 0.81, 1, "|#eta| < 0.9", 0.03);
13451 //   
13452 //   DrawALICELogo(kFALSE, 0.7, 0.2, 0.9, 0.4);
13453   
13454   c->SaveAs("correction_tracking.eps");
13455   
13456   c = new TCanvas("c2", "c2", 600, 600);
13457   gPad->SetLeftMargin(0.15);
13458   
13459   proj = (TH1D*) h->GetUEHist(2)->GetTrackEfficiency(AliUEHist::kCFStepTracked, AliUEHist::kCFStepTrackedOnlyPrim, 1);
13460   proj->GetYaxis()->SetRangeUser(0.8, 1.0);
13461   proj->GetXaxis()->SetRangeUser(0.5, 9.9);
13462   proj->GetYaxis()->SetTitleOffset(1.5);
13463   proj->SetTitle("");
13464   proj->GetYaxis()->SetTitle("contamination correction");
13465   proj->SetStats(0);
13466   projClone = proj->DrawClone("");
13467
13468 //   DrawLatex(0.58, 0.85, 1, "HIJING Pb-Pb 2.76 TeV", 0.03);
13469 //   DrawLatex(0.58, 0.81, 1, "|#eta| < 0.9", 0.03);
13470 //   DrawALICELogo(kFALSE, 0.7, 0.2, 0.9, 0.4);
13471
13472   c->SaveAs("correction_contamination.eps");
13473   
13474   c = new TCanvas("c3", "c3", 600, 600);
13475   gPad->SetLeftMargin(0.15);
13476   
13477   proj = (TH1D*) h->GetUEHist(2)->GetTrackEfficiency(AliUEHist::kCFStepTrackedOnlyPrim, AliUEHist::kCFStepTracked, 1);
13478   proj->GetYaxis()->SetRangeUser(0.95, 1.15);
13479   proj->GetXaxis()->SetRangeUser(0.5, 9.9);
13480   proj->GetYaxis()->SetTitleOffset(1.5);
13481   proj->SetTitle("");
13482   proj->GetYaxis()->SetTitle("contamination");
13483   proj->SetStats(0);
13484   projClone = proj->DrawClone("");
13485
13486 //   DrawLatex(0.58, 0.85, 1, "HIJING Pb-Pb 2.76 TeV", 0.03);
13487 //   DrawLatex(0.58, 0.81, 1, "|#eta| < 0.9", 0.03);
13488 //   DrawALICELogo(kFALSE, 0.7, 0.2, 0.9, 0.4);
13489
13490   c->SaveAs("contamination.eps");  
13491 }
13492
13493 void PlotCorrections(const char* fileName, const char* tag = "")
13494 {
13495   loadlibs();
13496   
13497   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName, 0, kFALSE, tag);
13498   
13499   c = new TCanvas("c", "c", 1200, 800);
13500   c->Divide(3, 3);
13501
13502   c2 = new TCanvas("c2", "c2", 800, 900);
13503   c2->Divide(2, 3);
13504
13505   h->SetEtaRange(-0.89, 0.89);
13506 //   h->SetEtaRange(-1.19, 1.19);
13507   
13508   Float_t centrBins[] = { 0, 20, 40, 60, 100.1 };
13509   
13510   for (Int_t i=0; i<4; i++)
13511   {
13512     h->GetUEHist(2)->SetCentralityRange(centrBins[i] + 0.1, centrBins[i+1] - 0.1);
13513     c->cd(i+1);
13514     h->GetUEHist(2)->GetTrackingEfficiency()->DrawClone("COLZ");
13515     
13516     c2->cd(1);
13517     proj = h->GetUEHist(2)->GetTrackingEfficiency(1);
13518     proj->SetTitle(""); proj->SetStats(0);
13519     proj->GetYaxis()->SetTitle("tracking efficiency");
13520     proj->SetLineColor(i+1);
13521     proj->DrawClone((i == 0) ? "" : "SAME");
13522     
13523     c2->cd(2);
13524     proj = h->GetUEHist(2)->GetTrackingEfficiency(0);
13525     proj->GetYaxis()->SetTitle("tracking efficiency");
13526     proj->SetTitle(""); proj->SetStats(0);
13527     proj->GetXaxis()->SetTitle("#eta");
13528     proj->SetLineColor(i+1);
13529     proj->DrawClone((i == 0) ? "" : "SAME");
13530
13531     c2->cd(3);
13532     proj = h->GetUEHist(2)->GetTrackingContamination(1);
13533     proj->GetYaxis()->SetTitle("contamination correction");
13534     proj->SetTitle(""); proj->SetStats(0);
13535     proj->SetLineColor(i+1);
13536     proj->DrawClone((i == 0) ? "" : "SAME");
13537 //     return;
13538   }
13539
13540   h->GetUEHist(2)->SetCentralityRange(0, -1);
13541   for (Int_t i=0; i<10; i++)
13542   {
13543     c2->cd(4);
13544     h->SetZVtxRange(-10.0 + 2 * i, -8.0 + 2 * i);
13545     proj = h->GetUEHist(2)->GetTrackingEfficiency(0);
13546     proj->GetYaxis()->SetTitle("tracking efficiency");
13547     proj->SetTitle(""); proj->SetStats(0);
13548     proj->GetXaxis()->SetTitle("#eta");
13549     proj->SetLineColor(i+1);
13550     proj->DrawClone((i == 0) ? "" : "SAME");
13551   }
13552   
13553   h->SetZVtxRange(0, -1);
13554
13555   for (Int_t i=0; i<4; i++)
13556   {
13557     c2->cd(5);
13558     h->SetPartSpecies(i);
13559     proj = h->GetUEHist(2)->GetTrackingEfficiency(1);
13560     proj->GetYaxis()->SetTitle("tracking efficiency");
13561     proj->SetTitle(""); proj->SetStats(0);
13562 //     proj->GetXaxis()->SetTitle("#eta");
13563     proj->SetLineColor(i+1);
13564     proj->DrawClone((i == 0) ? "" : "SAME");
13565   }
13566   
13567   return;
13568   
13569 /*  c->cd(9);
13570   h->GetUEHist(2)->GetTrackingContamination()->Draw("COLZ");*/
13571   
13572   proj2 = h->GetUEHist(2)->GetTrackingEfficiency(1);
13573 //   proj2 = h->GetUEHist(2)->GetTrackEfficiency(AliUEHist::kCFStepAnaTopology, (AliUEHist::CFStep) (AliUEHist::kCFStepTrackedOnlyPrim+2), 1);
13574   new TCanvas;
13575   proj2->Draw();
13576   
13577   new TCanvas;
13578   hist = h->GetUEHist(2)->GetCorrelatedContamination();
13579 //   if (hist->GetEntries() > 0)
13580 //     hist->Draw("COLZ");
13581 }
13582
13583 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)
13584 {
13585   // partSpecies= -1 No PID, 0: Pions, 1: Kaons, 2: Protons
13586   // icharge is needed because GF correction applies only to negative particles, 0:Positive 1:negative
13587   // ApplyGFCorrection, for Geant3 version >= v1.14 this correction is not needed anymore for antiprotons
13588   // the number of TRD modules installed depends on the year
13589   
13590   Printf("condenseCentrality: %d; extrapolateHighpT: %d", condenseCentrality, extrapolateHighpT);
13591   
13592   loadlibs();
13593   
13594   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName, 0, kFALSE, tag);
13595   
13596   if(partSpecies!=-1){
13597     Double_t epsilon=0.001;
13598     h->GetUEHist(2)->GetTrackHistEfficiency()->GetGrid(0)->GetGrid()->GetAxis(2)->SetRangeUser(partSpecies-epsilon,partSpecies+epsilon);
13599     h->GetUEHist(2)->GetTrackHistEfficiency()->GetGrid(4)->GetGrid()->GetAxis(2)->SetRangeUser(partSpecies-epsilon,partSpecies+epsilon);
13600   }
13601   
13602   Int_t dimensions[] = { 0, 1, 3, 4 }; // eta, pT, centrality, vertex
13603   THnBase* generated = h->GetUEHist(2)->GetTrackHistEfficiency()->GetGrid(0)->GetGrid()->ProjectionND(4, dimensions);
13604   THnBase* measured = h->GetUEHist(2)->GetTrackHistEfficiency()->GetGrid((partSpecies==-1)?2:4)->GetGrid()->ProjectionND(4, dimensions); //for ID particle the matched+identified are taken
13605   
13606   //   new TCanvas; measured->Projection(0, 1, 3)->Draw();
13607   
13608   Printf("%f %f", generated->GetEntries(), measured->GetEntries());
13609   
13610   Int_t nBins[] = { generated->GetAxis(0)->GetNbins(), generated->GetAxis(1)->GetNbins(), 1, generated->GetAxis(3)->GetNbins() };
13611   
13612   if (condenseCentrality)
13613   {
13614     Double_t centrAxis[] = { 0, 101 };
13615   }
13616   else
13617   {
13618     Double_t centrAxis[] = { 0, 10, 20, 40, 60, 101 };
13619     nBins[2] = 5;
13620   }
13621   
13622   generated_new = new THnF("generated_new", "", 4, nBins, 0, 0);
13623   
13624   generated_new->SetBinEdges(0, generated->GetAxis(0)->GetXbins()->GetArray()); //eta
13625   generated_new->SetBinEdges(1, generated->GetAxis(1)->GetXbins()->GetArray()); //pT
13626   generated_new->SetBinEdges(2, centrAxis); //centrality
13627   generated_new->SetBinEdges(3, generated->GetAxis(3)->GetXbins()->GetArray()); //vertex
13628   
13629   for (Int_t i=0; i<4; i++)
13630     generated_new->GetAxis(i)->SetTitle(generated->GetAxis(i)->GetTitle());
13631   
13632   measured_new = (THnF*) generated_new->Clone("measured_new");
13633   effCorr = (THnF*) generated_new->Clone("correction");
13634
13635   generated_new->RebinnedAdd(generated);
13636   measured_new->RebinnedAdd(measured);
13637   
13638 //   new TCanvas; measured_new->Projection(0, 1, 3)->Draw();
13639
13640 //   return;
13641   
13642   Printf("%f %f", generated_new->GetEntries(), measured_new->GetEntries());
13643
13644   effCorr->Divide(generated_new, measured_new, 1, 1, "B");
13645 //   effCorr->Divide(measured_new);
13646
13647   if(ApplyGFCorrection && partSpecies!=-1){//define the functions for the GF correction
13648     TF1 *fGFTracking;
13649     TF1 *fGFMatching;
13650     Int_t ntrd=7;
13651     if(year==2011)ntrd=10;
13652     if(year>=2012)ntrd=13;
13653     Printf("Number of TRD module in %d : %d",year,ntrd);
13654     Printf("Applying GF correction for particle specie %d %s",partSpecies,Sign[icharge].Data());
13655     Int_t partSpeciesAliPID=partSpecies+2; //in AliPID 2: Pions 3:Kaons 4:protons
13656     fGFTracking = TrackingEff_geantflukaCorrection(partSpeciesAliPID,(icharge==0)?kPositive:kNegative);
13657     fGFMatching = TOFmatchMC_geantflukaCorrection(partSpeciesAliPID,(icharge==0)?kPositive:kNegative,ntrd);
13658     TCanvas *cGF=new TCanvas("cGF","cGF");
13659     fGFTracking->SetLineColor(1);
13660     fGFTracking->DrawClone();
13661     fGFMatching->DrawClone("same");
13662     gPad->BuildLegend(); 
13663   }
13664   
13665   Double_t maxEffValue=5;
13666   for (Int_t bin0 = 1; bin0<=effCorr->GetAxis(0)->GetNbins(); bin0++)
13667     for (Int_t bin1 = 1; bin1<=effCorr->GetAxis(1)->GetNbins(); bin1++)
13668       for (Int_t bin2 = 1; bin2<=effCorr->GetAxis(2)->GetNbins(); bin2++)
13669         for (Int_t bin3 = 1; bin3<=effCorr->GetAxis(3)->GetNbins(); bin3++)
13670         {
13671           nBins[0] = bin0;
13672           nBins[1] = bin1;
13673           nBins[2] = bin2;
13674           nBins[3] = bin3;
13675           
13676 //        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));
13677           if(ApplyGFCorrection  && partSpecies!=-1)
13678             {
13679               if(effCorr->GetBinContent(nBins) > 0)
13680                 {
13681                   Double_t pt=effCorr->GetAxis(1)->GetBinCenter(bin1);
13682                   Double_t GFTracking=fGFTracking->Eval(pt);
13683                   Double_t GFMatching=fGFMatching->Eval(pt);
13684                   //printf("pt: %.3f GFCorrectionTracking: %f GFCorrectionMatching: %f",pt,GFTracking,GFMatching);
13685                   //printf(" Eff before: %f",effCorr->GetBinContent(nBins));
13686                   effCorr->SetBinContent(nBins,effCorr->GetBinContent(nBins)*GFTracking*GFMatching);
13687                   //Printf(" Eff after: %f",effCorr->GetBinContent(nBins));
13688                 }
13689             }
13690           
13691           if (effCorr->GetBinContent(nBins) > maxEffValue)
13692           {
13693             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));
13694             effCorr->SetBinContent(nBins, 0);
13695           }
13696         
13697         
13698         }
13699
13700   const Float_t fitRangeBegin = 5.01;
13701   const Float_t fitRangeEnd = 14.99;
13702   const Float_t extendRangeBegin = 8.01;
13703   Bool_t verbose = kTRUE;
13704
13705   if (extrapolateHighpT)
13706   {
13707     Printf("Extrapolating high pT...");
13708     
13709     for (Int_t bin0 = 1; bin0<=effCorr->GetAxis(0)->GetNbins(); bin0++)
13710       for (Int_t bin2 = 1; bin2<=effCorr->GetAxis(2)->GetNbins(); bin2++)
13711         for (Int_t bin3 = 1; bin3<=effCorr->GetAxis(3)->GetNbins(); bin3++)
13712         {
13713           effCorr->GetAxis(0)->SetRange(bin0, bin0);
13714           effCorr->GetAxis(2)->SetRange(bin2, bin2);
13715           effCorr->GetAxis(3)->SetRange(bin3, bin3);
13716           
13717           if (gRandom->Uniform() < 0.02) verbose = kTRUE;
13718           
13719           proj = effCorr->Projection(1);
13720           
13721           if (proj->Integral(proj->FindBin(fitRangeBegin), proj->FindBin(fitRangeEnd)) <= 0)
13722             continue;
13723           
13724 //        Printf("%d %d %d %d %f", bin0, bin1, bin2, bin3, proj->Integral(proj->FindBin(fitRangeBegin), proj->FindBin(fitRangeEnd)));
13725           
13726           if (verbose)
13727           {
13728             new TCanvas; 
13729             proj->Draw();
13730           }
13731           
13732           proj->Fit("pol0", (verbose) ? "+" : "Q0+", "SAME", fitRangeBegin, fitRangeEnd);
13733           
13734           if (!proj->GetFunction("pol0"))
13735             continue;
13736           
13737           Float_t trackingEff = proj->GetFunction("pol0")->GetParameter(0);       
13738           
13739           for (Int_t bin1 = 1; bin1<=effCorr->GetAxis(1)->GetNbins(); bin1++)
13740           {
13741             if (effCorr->GetAxis(1)->GetBinCenter(bin1) < extendRangeBegin)
13742               continue;
13743               
13744             nBins[0] = bin0;
13745             nBins[1] = bin1;
13746             nBins[2] = bin2;
13747             nBins[3] = bin3;
13748             
13749 //          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));
13750             effCorr->SetBinContent(nBins, trackingEff);
13751           }
13752           
13753           if (verbose)
13754             verbose = kFALSE;
13755         }
13756
13757     effCorr->GetAxis(0)->UnZoom();
13758     effCorr->GetAxis(1)->UnZoom();
13759     effCorr->GetAxis(2)->UnZoom();
13760     effCorr->GetAxis(3)->UnZoom();
13761   }
13762   
13763   Printf("%f", effCorr->GetEntries());
13764   
13765   TObjString tag2(Form("corrections from file %s with tag %s", fileName, tag));
13766
13767   file = TFile::Open("correction.root", "RECREATE");
13768   effCorr->Write();
13769   tag2.Write();
13770   file->Close();
13771   
13772   new TCanvas;
13773   effCorr->GetAxis(0)->SetRangeUser(-0.49, 0.49);
13774   effCorr->GetAxis(2)->SetRangeUser(65, 65);
13775   effCorr->GetAxis(3)->SetRangeUser(0.01, 0.01);
13776   effCorr->Projection(1)->Draw();
13777 }
13778
13779 void CompareEfficiencyCorrection(const char* fileName1, const char* fileName2, Int_t axis1, Int_t axis2)
13780 {
13781   if (TString(fileName1).BeginsWith("alien") || TString(fileName2).BeginsWith("alien"))
13782     TGrid::Connect("alien:");
13783   
13784   file1 = TFile::Open(fileName1);
13785   corr1 = (THnBase*) file1->Get("correction");
13786   
13787   file2 = TFile::Open(fileName2);
13788   corr2 = (THnBase*) file2->Get("correction");
13789   
13790   corr1->GetAxis(0)->SetRangeUser(-1.19, 1.19);
13791   corr2->GetAxis(0)->SetRangeUser(-1.19, 1.19);
13792   corr1->GetAxis(1)->SetRangeUser(0.51, 3.99);
13793   corr2->GetAxis(1)->SetRangeUser(0.51, 3.99);
13794   corr1->GetAxis(3)->SetRangeUser(0.01, 0.01);
13795   corr2->GetAxis(3)->SetRangeUser(0.01, 0.01);
13796   
13797   proj1 = (TH1*) corr1->Projection(axis1, axis2)->Clone("proj1");
13798   new TCanvas; proj1->DrawCopy("COLZ");
13799
13800   proj2 = (TH1*) corr2->Projection(axis1, axis2)->Clone("proj2");
13801   new TCanvas; proj2->DrawCopy("COLZ");
13802
13803   proj1->Divide(proj2);
13804   new TCanvas; proj1->DrawCopy("COLZ");
13805   
13806   corr1->GetAxis(0)->SetRangeUser(-0.49, 0.49);
13807   corr2->GetAxis(0)->SetRangeUser(-0.49, 0.49);
13808
13809   proj1 = (TH1*) corr1->Projection(axis2)->Clone("proj3");
13810   new TCanvas; proj1->DrawCopy();
13811
13812   proj2 = (TH1*) corr2->Projection(axis2)->Clone("proj4");
13813   proj2->SetLineColor(2);
13814   proj2->DrawCopy("SAME");
13815
13816   proj1->Divide(proj2);
13817   new TCanvas; proj1->DrawCopy();
13818   
13819 }
13820
13821  
13822 void PlotFake(const char* fileName, const char* fileName2 = 0)
13823 {
13824   loadlibs();
13825   
13826   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
13827   if (fileName2) AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(fileName2); 
13828  
13829   TLegend* legend = new TLegend(0.7, 0.8, 0.95, 0.95);
13830   legend->SetFillColor(0);
13831   legend->SetTextSize(0.03);
13832   const char* title[] = {"0-20%", "20-40%", "40-60%", "60-80%", "80-100%"};
13833   TLegend* legend2 = new TLegend(0.7, 0.8, 0.95, 0.95);
13834   legend2->SetFillColor(0);
13835   legend2->SetTextSize(0.03);
13836
13837   c1 = new TCanvas("c1", "Ratio of fakes", 1200, 800);
13838   c1->Divide(2, 3);
13839   c2 = new TCanvas("c2", "pTrec vs pT", 1200, 800);
13840   c2->Divide(2, 3);
13841   c3 = new TCanvas("c3", "pTrec pT ratio", 1200, 800);
13842   c3->Divide(2, 3);
13843
13844   h->SetEtaRange(-0.79, 0.79);
13845   
13846   for (Int_t i=0; i<5; i++)
13847   {
13848 //     h->GetUEHist(2)->SetCentralityRange(100.0/5*i + 0.1, 100.0/5*(i+1) - 0.1);
13849     h->GetUEHist(2)->SetCentralityRange(0, 100);
13850     c1->cd(i+1);
13851     h->GetUEHist(2)->GetFakeRate()->DrawClone("COLZ");
13852     c1->cd(6);
13853     proj = h->GetUEHist(2)->GetFakeRate(1);
13854     proj->GetYaxis()->SetRangeUser(0,150);
13855     proj->SetLineColor((i==4) ? 6 : i+1);
13856     proj->DrawClone((i == 0) ? "" : "SAME");
13857     legend->AddEntry(proj, title[i] , "PL");
13858   }
13859
13860   legend->Draw();
13861
13862   c2->cd(1);
13863   h->GetUEHist(2)->GetMCRecoPtCorrelation()->GetXaxis()->SetTitle("p_{T,rec}");
13864   h->GetUEHist(2)->GetMCRecoPtCorrelation()->GetYaxis()->SetTitle("p_{T}");
13865   h->GetUEHist(2)->GetMCRecoPtCorrelation()->GetZaxis()->SetTitle("Centrality");
13866   h->GetUEHist(2)->GetMCRecoPtCorrelation()->DrawCopy();
13867
13868   Float_t difference = 0.05;
13869
13870   for (Int_t i=0; i<5; i++)
13871   {
13872     c2->cd(i+2);
13873     h->GetUEHist(2)->GetMCRecoPtCorrelation()->GetZaxis()->SetRangeUser(100.0/5*i + 0.1,100.0/5*(i+1) - 0.1);
13874     hist = h->GetUEHist(2)->GetMCRecoPtCorrelation()->Project3D("yx");
13875     hist->DrawClone("COLZ");
13876     c2->cd(i+2)->SetLogz();
13877     c3->cd(i+1);
13878     TH1* MisreconstructedPtRate = h->GetUEHist(2)->GetMCRecoPtCorrelation()->ProjectionX("MisreconstructedPtRate");
13879     MisreconstructedPtRate->Reset();
13880     MisreconstructedPtRate->GetYaxis()->SetRangeUser(0,1);
13881     
13882     for (Int_t x=0; x<=hist->GetNbinsX(); x++) 
13883     {
13884       Float_t ptRec = hist->GetXaxis()->GetBinCenter(x);
13885       Float_t Misreconstructed = 0;
13886       Float_t Reconstructed = 0;
13887       for (Int_t y=0; y<=hist->GetNbinsY(); y++) 
13888       {
13889         Float_t pt = hist->GetYaxis()->GetBinCenter(y);
13890         Reconstructed += hist->GetBinContent(x,y);
13891         if (TMath::Abs(ptRec-pt)/pt > difference)
13892           Misreconstructed += hist->GetBinContent(x,y);
13893       }
13894       if (Reconstructed!=0) MisreconstructedPtRate->Fill(ptRec,Misreconstructed/Reconstructed);
13895     }
13896     MisreconstructedPtRate->SetLineColor((i==4) ? 6 : i+1);
13897     MisreconstructedPtRate->DrawClone();
13898     if (i==0) legend2->AddEntry(MisreconstructedPtRate, "2010" , "L");
13899     c3->cd(6);
13900     MisreconstructedPtRate->DrawClone((i == 0) ? "" : "SAME");
13901     if (fileName2)
13902     {
13903       h2->GetUEHist(2)->GetMCRecoPtCorrelation()->GetZaxis()->SetRangeUser(100.0/5*i + 0.1,100.0/5*(i+1) - 0.1);
13904       hist = h2->GetUEHist(2)->GetMCRecoPtCorrelation()->Project3D("yx"); 
13905       TH1* MisreconstructedPtRate2 = h2->GetUEHist(2)->GetMCRecoPtCorrelation()->ProjectionX("MisreconstructedPtRate2");
13906       MisreconstructedPtRate2->Reset();
13907       MisreconstructedPtRate2->GetYaxis()->SetRangeUser(0,1);
13908       for (Int_t x=0; x<=hist->GetNbinsX(); x++)
13909       {
13910         Float_t ptRec = hist->GetXaxis()->GetBinCenter(x);
13911         Float_t Misreconstructed = 0;
13912         Float_t Reconstructed = 0;
13913         for (Int_t y=0; y<=hist->GetNbinsY(); y++)
13914         {
13915           Float_t pt = hist->GetYaxis()->GetBinCenter(y);
13916           Reconstructed += hist->GetBinContent(x,y);
13917           if (TMath::Abs(ptRec-pt)/pt > difference)
13918             Misreconstructed += hist->GetBinContent(x,y);
13919         }
13920         if (Reconstructed!=0) MisreconstructedPtRate2->Fill(ptRec,Misreconstructed/Reconstructed);
13921       }
13922       c3->cd(i+1);
13923       MisreconstructedPtRate2->SetLineColor((i==2) ? 12 : i+8);
13924       MisreconstructedPtRate2->DrawClone("SAME");
13925       if (i==0) legend2->AddEntry(MisreconstructedPtRate2, "2011" , "L");
13926       legend2->DrawClone();
13927     }
13928   }
13929   c3->cd(6);
13930  legend->Draw();
13931 }
13932
13933 void CompareCorrections(const char* fileName1, const char* fileName2)
13934 {
13935   loadlibs();
13936   
13937   AliUEHistograms* h1 = (AliUEHistograms*) GetUEHistogram(fileName1);
13938   AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(fileName2);
13939   
13940   c = new TCanvas("c", "c", 1200, 800);
13941
13942   TLegend* legend = new TLegend(0.7, 0.8, 0.95, 0.95);
13943   legend->SetFillColor(0);
13944   legend->SetTextSize(0.03);
13945
13946   h1->SetEtaRange(-0.89, 0.89);
13947   h2->SetEtaRange(-0.89, 0.89);  
13948
13949
13950 //  const char* title1[] = {"2010, 0-10%", "2010, 10-20%", "2010, 20-30%", "2010, 30-40%", "2010, 40-50%"};
13951   const char* title1[] = {"FullTPC, 0-10%", "FullTPC, 10-20%", "FullTPC, 20-30%", "FullTPC, 30-40%", "FullTPC, 40-50%"};
13952   const char* title1[] = {"FullTPC, 0-10%", "FullTPC, 10-20%", "FullTPC, 20-30%", "FullTPC, 30-40%", "FullTPC, 40-50%"};
13953 //  const char* title2[] = {"2011, 0-10%", "2011, 10-20%", "2011, 20-30%", "2011, 30-40%", "2011, 40-50%"};
13954   const char* title2[] = {"NotFullTPC, 0-10%", "NotFullTPC, 10-20%", "NotFullTPC, 20-30%", "NotFullTPC, 30-40%", "NotFullTPC, 40-50%"};
13955
13956   Int_t colors[16] =  { 1, 3, 2, 6, 4, 7, 8, 9, 11, 12, 28, 30, 36, 40, 46 };
13957   Int_t markers[16] = { 20, 21, 22, 23, 24, 25, 26, 27, 28, 30, 31, 32, 33, 34, 2, 5};
13958
13959   for (Int_t i=0; i<5; i++)
13960   {
13961     h1->GetUEHist(2)->SetCentralityRange(100.0/10*i + 0.1, 100.0/10*(i+1) - 0.1);
13962     h2->GetUEHist(2)->SetCentralityRange(100.0/10*i + 0.1, 100.0/10*(i+1) - 0.1);
13963     
13964     c->cd(1);
13965     proj = h1->GetUEHist(2)->GetTrackingEfficiency(1);
13966     proj->SetLineColor(colors[6]);
13967     proj->SetMarkerColor(colors[6]);
13968     proj->SetMarkerStyle(markers[i]);
13969     proj->DrawClone((i == 0) ? "" : "SAME");
13970     legend->AddEntry(proj, title1[i] , "PL");
13971
13972     proj = h2->GetUEHist(2)->GetTrackingEfficiency(1);
13973     proj->SetLineColor(colors[2]);
13974     proj->SetMarkerColor(colors[2]);
13975     proj->SetMarkerStyle(markers[i+5]);
13976     proj->SetMarkerStyle(markers[i]);
13977     proj->DrawClone("SAME");
13978     legend->AddEntry(proj, title2[i] , "PL");
13979   }
13980     
13981   legend->Draw();
13982 }
13983
13984 void ComparePPHIMixedEvent(const char* ppFile, const char* pbpbFile)
13985 {
13986   loadlibs();
13987   
13988   AliUEHistograms* hpp = (AliUEHistograms*) GetUEHistogram(ppFile);
13989   AliUEHistograms* hpbpb = (AliUEHistograms*) GetUEHistogram(pbpbFile);
13990   
13991   new TCanvas;
13992   hpp->SetPtRange(2, 10);
13993   ppEff = hpp->GetUEHist(2)->GetTrackingEfficiency(0);
13994   ppEff->Draw();
13995
13996   hpbpb->SetPtRange(2, 10);
13997   pbpbEff = hpbpb->GetUEHist(2)->GetTrackingEfficiency(0);
13998   pbpbEff->DrawCopy("SAME")->SetLineColor(2);
13999   
14000   new TCanvas;
14001   ppEff2 = hpp->GetUEHist(2)->GetTrackingEfficiency(1);
14002   ppEff2->Draw();
14003
14004   pbpbEff2 = hpbpb->GetUEHist(2)->GetTrackingEfficiency(1);
14005   pbpbEff2->DrawCopy("SAME")->SetLineColor(2);
14006
14007   mixed = ComparePPHIMixedEventGetMixed(ppEff);
14008   mixed2 = ComparePPHIMixedEventGetMixed(pbpbEff);
14009   
14010   new TCanvas;
14011   mixed->DrawCopy();
14012   mixed2->DrawCopy("SAME")->SetLineColor(2);
14013   
14014   new TCanvas;
14015   mixed->Divide(mixed2);
14016   mixed->Draw();
14017 }
14018
14019 TH1* ComparePPHIMixedEventGetMixed(TH1* eff)
14020 {
14021   eff->Fit("pol0", "0W");
14022   Float_t avgEff = eff->GetFunction("pol0")->GetParameter(0);
14023
14024   eff->Fit("pol0", "0W", "", -0.89, 0.89);
14025   Float_t avgEffCenter = eff->GetFunction("pol0")->GetParameter(0);
14026   Printf("Avg is %f and avg in center is %f", avgEff, avgEffCenter);
14027          
14028   TH1* mixed = new TH1F("mixed", "", 100, -2, 2);
14029   
14030   Float_t etaLimit = 1.0;
14031   
14032   Int_t n = 10000;
14033   Int_t n2 = 100;
14034   for (Int_t i=0; i<n; i++)
14035   {
14036     Float_t etaTrig = gRandom->Uniform(-etaLimit, etaLimit);
14037     
14038     for (Int_t j=0; j<n2; j++)
14039     {
14040       Float_t etaAssoc = gRandom->Uniform(-etaLimit, etaLimit);
14041       
14042       if (gRandom->Uniform(0, 1) > eff->GetBinContent(eff->FindBin(etaAssoc)))
14043         continue;
14044       
14045       mixed->Fill(etaTrig - etaAssoc);
14046     }
14047   }
14048   
14049 //   mixed->Scale(1.0 / avgEffCenter);
14050   mixed->Scale(1.0 / avgEff);
14051
14052   Printf("We have %f pairs and put in %d", mixed->Integral(), n*n2);    
14053   
14054   return mixed;
14055 }
14056
14057 void MACHConeEvolution(const char* fileName, const char* fileNameMixed = 0)
14058 {
14059   loadlibs();
14060   
14061   if (!fileNameMixed)
14062     fileNameMixed = fileName;
14063   
14064   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
14065   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileNameMixed, 0, kTRUE);
14066     
14067   Float_t leadingPtArr[] = { 2.0, 3.0, 4.0, 10.0, 20.0, 40.0 };
14068   Float_t assocPtArr[] =   { 1.0, 2.0, 3.0, 6.0, 10.0, 20.0, 40.0 };
14069   
14070   Int_t i = 1;
14071   Int_t step = 6;
14072   Int_t j = 0;
14073   
14074   gpTMin = assocPtArr[i] + 0.01;
14075   gpTMax = assocPtArr[i+1] - 0.01;
14076
14077   for (Int_t centrBin = 0; centrBin < 5; centrBin++)
14078   {
14079     Int_t centralityBegin = centrBin;
14080     Int_t centralityEnd = centrBin+1;
14081     
14082     SetupRanges(h);
14083     SetupRanges(hMixed);
14084     
14085     TH1* hist = 0;
14086
14087     Bool_t scaleToPairs = 0;
14088     
14089     GetDistAndFlow(h, hMixed, &hist, 0, step, centralityBegin, centralityEnd, leadingPtArr[j] + 0.01, leadingPtArr[j+1] - 0.01, 11, kTRUE, 0, scaleToPairs); 
14090     hist->Rebin(2); hist->Scale(0.5);
14091
14092     copy = hist->DrawCopy((centrBin == 0) ? "" : "SAME");
14093     copy->SetLineColor(centrBin+1);
14094   }
14095 }
14096     
14097 void PlotTwoTrackEfficiencyControlPlots(const char* fileName)
14098 {
14099   loadlibs();
14100   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
14101   
14102   Float_t ptRange[] = { 0.0, 1.0, 2.0, 3.0, 4.0, 6.0, 8.0, 10.0 };
14103   
14104   graph = new TGraphErrors;
14105   
14106   for (Int_t ptID = 0; ptID < 7; ptID++)
14107   {
14108     c = new TCanvas(Form("c%d", ptID), Form("%.0f < pT < %.0f", ptRange[ptID], ptRange[ptID+1]), 800, 400);
14109     c->Divide(2, 1);
14110   
14111     for (Int_t i=0; i<2; i++)
14112     {
14113       c->cd(i+1);
14114       h->GetTwoTrackDistance(i)->GetZaxis()->SetRangeUser(ptRange[ptID] + 0.01, ptRange[ptID+1] - 0.01);
14115       p = h->GetTwoTrackDistance(i)->Project3D(Form("yx_%d_%d", i, ptID));
14116 //       if (ptID == 0)
14117         p->SetStats(0);
14118       
14119       pc = (TH2*) p->Clone("pc");
14120       pc->Reset();
14121       
14122       p->DrawCopy("COLZ");
14123       
14124       continue;
14125       
14126       // reduce to one quadrant
14127       for (Int_t x=1; x<=p->GetNbinsX(); x++)
14128         for (Int_t y=1; y<=p->GetNbinsY(); y++)
14129           pc->Fill(TMath::Abs(p->GetXaxis()->GetBinCenter(x)), TMath::Abs(p->GetYaxis()->GetBinCenter(y)), p->GetBinContent(x, y));
14130       
14131       c->cd(i+2);
14132       copy = pc->DrawCopy("COLZ");
14133       copy->GetXaxis()->SetRangeUser(0, 10);
14134       copy->GetYaxis()->SetRangeUser(0.00101, 10);
14135       
14136       // extract excess
14137       if (1)
14138       {
14139         Float_t center = pc->Integral(pc->GetXaxis()->FindBin(0), pc->GetXaxis()->FindBin(0.009999), 1, pc->GetNbinsY());
14140         Float_t outside = pc->Integral(pc->GetXaxis()->FindBin(0.01001), pc->GetXaxis()->FindBin(0.04999), 1, pc->GetNbinsY());
14141         
14142         Float_t excess1 = center - outside / 4;
14143
14144         Float_t center = pc->Integral(pc->GetXaxis()->FindBin(0), pc->GetXaxis()->FindBin(0.001999), 1, pc->GetNbinsY());
14145         Float_t outside = pc->Integral(pc->GetXaxis()->FindBin(0.002001), pc->GetXaxis()->FindBin(0.00999), 1, pc->GetNbinsY());
14146
14147         Float_t excess2 = center - outside / 4;
14148
14149         Printf("%d %f %f", ptID, excess1, excess2);
14150       }
14151
14152       // fit
14153       if (0 && i == 0)
14154       {
14155         p2 = ((TH2*)pc)->ProjectionX("p2", 52, 52+4);
14156 //      p3 = ((TH2*)p)->ProjectionX("p3", 49-4, 49);
14157         //p2->Add(p3);
14158         //new TCanvas; p2->Draw();
14159         //return;
14160         p2->Fit("pol0", "0");
14161         Float_t avg = p2->GetFunction("pol0")->GetParameter(0);
14162         p2->Fit("pol0", "0", "", -0.002, 0.002); 
14163         Float_t min = p2->GetFunction("pol0")->GetParameter(0);
14164         Float_t mine = p2->GetFunction("pol0")->GetParError(0);
14165         
14166         if (avg > 0)
14167         {
14168           graph->SetPoint(graph->GetN(), ptRange[ptID], min / avg);
14169           graph->SetPointError(graph->GetN()-1, 0, mine / avg);
14170         }
14171       }
14172       
14173     }
14174     
14175     c->SaveAs(Form("twotrack_pt_%d_%d.png", (Int_t) ptRange[ptID], (Int_t) ptRange[ptID+1]));
14176     c->SaveAs(Form("twotrack_pt_%d_%d.eps", (Int_t) ptRange[ptID], (Int_t) ptRange[ptID+1]));
14177   }
14178   
14179   new TCanvas;
14180   graph->Print();
14181   graph->Draw("A*");
14182 }
14183
14184 void PlotTwoTrackEfficiencyControlPlots2(const char* fileName)
14185 {
14186   loadlibs();
14187   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
14188   
14189   Float_t ptRange[] = { 0.0, 1.0, 2.0, 3.0, 4.0, 6.0, 8.0, 10.0 };
14190   
14191   graph = new TGraphErrors;
14192   
14193   for (Int_t ptID = 0; ptID < 5; ptID++)
14194   {
14195     c = new TCanvas(Form("c%d", ptID), Form("%.0f < pT < %.0f", ptRange[ptID], ptRange[ptID+1]), 1200, 400);
14196     c->Divide(3, 1);
14197   
14198     TH2* proj[2];
14199     
14200     for (Int_t i=0; i<3; i++)
14201     {
14202       c->cd(i+1);
14203       gPad->SetRightMargin(0.2);
14204       
14205       if (i < 2)
14206       {
14207         h->GetTwoTrackDistance(i)->GetZaxis()->SetRangeUser(ptRange[ptID] + 0.01, ptRange[ptID+1] - 0.01);
14208         p = (TH2*) h->GetTwoTrackDistance(i)->Project3D(Form("yx_%d_%d", i, ptID));
14209         
14210         if (1)
14211         {
14212           // reduce to one quadrant
14213           pc = (TH2*) p->Clone(Form("%s_pc", p->GetName()));
14214           pc->Reset();
14215           pc->Rebin2D(2, 2);
14216           for (Int_t x=1; x<=p->GetNbinsX(); x++)
14217             for (Int_t y=1; y<=p->GetNbinsY(); y++)
14218               pc->Fill(TMath::Abs(p->GetXaxis()->GetBinCenter(x)), TMath::Abs(p->GetYaxis()->GetBinCenter(y)), p->GetBinContent(x, y));
14219           pc->GetXaxis()->SetRangeUser(0, 100);
14220           pc->GetYaxis()->SetRangeUser(0, 100);
14221           p = pc;
14222         }
14223         
14224         if (ptID == 0)
14225           p->SetStats(0);
14226         
14227         p->DrawCopy("COLZ");
14228         
14229         proj[i] = p;
14230       }
14231       else
14232       {
14233         proj[0]->Divide(proj[1]);
14234         proj[0]->SetStats(0);
14235
14236 //      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);
14237         Float_t scale = proj[0]->Integral(1, proj[1]->GetNbinsX(), 1, proj[1]->GetNbinsY()) / proj[1]->GetNbinsX() / proj[1]->GetNbinsY();
14238         proj[0]->Scale(1./ scale / 4);
14239         proj[0]->DrawCopy("COLZ");
14240       }
14241     }
14242   }
14243 }
14244
14245 void PlotTwoTrackEfficiencyControlPlots3(const char* fileName, Int_t histID = 0)
14246 {
14247   loadlibs();
14248   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
14249   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
14250   
14251   Float_t ptRange[] = { 0.0, 1.0, 2.0, 3.0, 4.0, 6.0, 8.0, 10.0 };
14252   
14253   graph = new TGraphErrors;
14254   
14255   for (Int_t ptID = 0; ptID < 5; ptID++)
14256   {
14257     c = new TCanvas(Form("c%d", ptID), Form("%.0f < pT < %.0f", ptRange[ptID], ptRange[ptID+1]), 1200, 400);
14258     c->Divide(3, 1);
14259   
14260     TH2* proj[2];
14261     
14262     for (Int_t i=0; i<3; i++)
14263     {
14264       c->cd(i+1);
14265       gPad->SetRightMargin(0.2);
14266       
14267       if (i < 2)
14268       {
14269         AliUEHistograms* input = ((i == 0) ? h : hMixed);
14270         input->GetTwoTrackDistance(histID)->GetZaxis()->SetRangeUser(ptRange[ptID] + 0.01, ptRange[ptID+1] - 0.01);
14271         p = (TH2*) input->GetTwoTrackDistance(histID)->Project3D(Form("yx_%d_%d", i, ptID));
14272         
14273         if (0)
14274         {
14275           // reduce to one quadrant
14276           pc = (TH2*) p->Clone(Form("%s_pc", p->GetName()));
14277           pc->Reset();
14278 //        pc->Rebin2D(2, 2);
14279           for (Int_t x=1; x<=p->GetNbinsX(); x++)
14280             for (Int_t y=1; y<=p->GetNbinsY(); y++)
14281               pc->Fill(TMath::Abs(p->GetXaxis()->GetBinCenter(x)), TMath::Abs(p->GetYaxis()->GetBinCenter(y)), p->GetBinContent(x, y));
14282           pc->GetXaxis()->SetRangeUser(0, 100);
14283           pc->GetYaxis()->SetRangeUser(0, 100);
14284           p = pc;
14285         }
14286         
14287 //      if (ptID == 0)
14288           p->SetStats(0);
14289         
14290         p->DrawCopy("COLZ");
14291         
14292         proj[i] = p;
14293       }
14294       else
14295       {
14296         Float_t scale = proj[0]->Integral() / proj[1]->Integral();
14297         proj[0]->Divide(proj[1]);
14298         proj[0]->SetStats(0);
14299
14300 //      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);
14301 //      Float_t scale = proj[0]->Integral(1, proj[1]->GetNbinsX(), 1, proj[1]->GetNbinsY()) / proj[1]->GetNbinsX() / proj[1]->GetNbinsY();
14302         proj[0]->Scale(1./ scale);
14303 //      proj[0]->Scale(1./ scale / 4);
14304         proj[0]->DrawCopy("COLZ");
14305       }
14306     }
14307   
14308     break;
14309   }
14310 }
14311
14312 void SystematicpTResolution(const char* inputYield, Int_t caseId = 18, Int_t triggerId = 1)
14313 {
14314   //   Study by Jacek comparing TPC only tracks with global tracks for new cuts (crossed rows) (Fwd by Andrew, 07.07.11)
14315   //   Resolution from tpc only tracks twice as worse than global tracks
14316   //   Parameterization for tpc-only tracks:
14317   //     f(pT) = a * pT * sqrt(1+b/(pT^abs(c)))
14318   //     a = 0.003; b = 2.08; c = 7.07e-7
14319   Float_t a = 0.003; Float_t b = 2.08; Float_t c = 7.07e-7;
14320   res = new TF1("res", "[0] * x * sqrt(1+[1]/(x**abs([2])))", 0, 15);
14321   res->SetParameters(a, b, c);
14322 //   res->Draw(); return;
14323   
14324   ReadYields(inputYield);
14325   
14326   for (Int_t side = 0; side < 2; side++)
14327   {
14328     for (Int_t centrality = 0; centrality < 4; centrality++)
14329     {
14330       TGraphErrors** tmp = yields[side][triggerId][centrality]; 
14331       graph = tmp[caseId];
14332       
14333 //       graph->DrawClone("A*");
14334       
14335       Float_t axisLimits[20];
14336       for (Int_t i=0; i<graph->GetN(); i++)
14337       {
14338         axisLimits[i] = graph->GetX()[i] - graph->GetEX()[i];
14339         axisLimits[i+1] = graph->GetX()[i] + graph->GetEX()[i];
14340       }
14341       
14342       hist = new TH1F("hist", "", graph->GetN(), axisLimits);
14343       
14344       for (Int_t i=0; i<graph->GetN(); i++)
14345       {
14346         gaus = new TF1("gaus", "gaus(0)", 0, 15);
14347         Float_t sigma = graph->GetX()[i] * res->Eval(graph->GetX()[i]);
14348         Float_t norm = graph->GetY()[i] / TMath::Sqrt(2 * TMath::Pi()) / sigma;
14349         gaus->SetParameters(norm, graph->GetX()[i], sigma);
14350 //      gaus->Draw("SAME");
14351 //      Printf("%f %f", graph->GetY()[i], gaus->Integral(0, 20));
14352         
14353         // fill histogram
14354         for (Int_t j=1; j<=hist->GetNbinsX(); j++)
14355           hist->SetBinContent(j, hist->GetBinContent(j) + gaus->Integral(hist->GetBinLowEdge(j), hist->GetXaxis()->GetBinUpEdge(j)));
14356       }
14357       
14358 //       hist->Draw("SAME"); return;
14359       
14360       for (Int_t i=0; i<graph->GetN(); i++)
14361         graph->GetY()[i] = hist->GetBinContent(i+1);
14362
14363 //       graph->SetMarkerColor(2); graph->DrawClone("*SAME");
14364     }
14365   }
14366 }
14367
14368 void DrawProcessIDPlot(const char* fileName)
14369 {
14370   if (gFile)
14371     gFile->Close();
14372   TFile::Open(fileName);
14373   list = (TList*) gFile->Get("PWG4_PhiCorrelations/histosPhiCorrelations");
14374   ((TH1*) list->FindObject("processIDs"))->Draw();
14375 }
14376  
14377 void GetExampleDphi(const char* fileName)
14378 {
14379   loadlibs();
14380   
14381   Int_t leadingPtOffset = 1;
14382     
14383   Int_t maxLeadingPt = 5;
14384   Int_t maxAssocPt = 6;
14385   if (1)
14386   {
14387     Float_t leadingPtArr[] = { 2.0, 3.0, 4.0, 6.0, 8.0, 10.0, 15.0, 20.0 };
14388     Float_t assocPtArr[] =     { 0.15, 0.5, 1.0, 2.0, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
14389   }
14390   else
14391   {
14392     Float_t leadingPtArr[] = { 0.15, 10.0 };
14393     Float_t assocPtArr[] =     { 0.15, 10.0 };
14394   }
14395   leadingPtOffset = 1;
14396   
14397 //   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
14398   hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
14399   
14400   if (1)
14401   {
14402 //     h->SetZVtxRange(-0.99, 0.99);
14403     hMixed->SetZVtxRange(-0.99, 0.99);
14404   }
14405
14406   Int_t i=0;
14407   Int_t j=2;
14408
14409   gpTMin = assocPtArr[j] + 0.01;
14410   gpTMax = assocPtArr[j+1] - 0.01;
14411   
14412 //   SetupRanges(h);
14413   SetupRanges(hMixed);
14414
14415   Int_t bin[6];
14416   bin[0] =  hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(0)->GetGrid()->GetAxis(0)->FindBin(0.01);
14417   bin[1] =  hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(0)->GetGrid()->GetAxis(1)->FindBin(1.1);
14418   bin[2] =  hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(0)->GetGrid()->GetAxis(2)->FindBin(2.1);
14419   bin[3] =  hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(0)->GetGrid()->GetAxis(3)->FindBin(5.5);
14420   bin[4] =  hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(0)->GetGrid()->GetAxis(4)->FindBin(0);
14421   if (hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(0)->GetGrid()->GetAxis(5))
14422     bin[5] =  hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(0)->GetGrid()->GetAxis(5)->FindBin(0);
14423   Printf("tracks: %f +- %f", hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(6)->GetGrid()->GetBinContent(bin), hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(6)->GetGrid()->GetBinError(bin));
14424   
14425   bin[0] =  hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(0)->GetGrid()->GetAxis(2)->FindBin(2.1);
14426   bin[1] =  hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(0)->GetGrid()->GetAxis(3)->FindBin(5.5);
14427   if (hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(0)->GetGrid()->GetAxis(5))
14428     bin[2] =  hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(0)->GetGrid()->GetAxis(5)->FindBin(0);
14429   Printf("events: %f +- %f", hMixed->GetUEHist(2)->GetEventHist()->GetGrid(6)->GetGrid()->GetBinContent(bin), hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(6)->GetGrid()->GetBinError(bin));
14430   
14431   return;
14432
14433   Int_t stepMixed = 6;
14434   TH2* mixedTwoD = (TH2*) hMixed->GetUEHist(2)->GetUEHist(stepMixed, 0, leadingPtArr[i+leadingPtOffset], leadingPtArr[i+1+leadingPtOffset], 12, 13, 1, kFALSE);
14435   
14436   TH1* proj = mixedTwoD->ProjectionX("px", 11, 30);
14437   proj->Draw();
14438 }
14439
14440 void GaussToyFit()
14441 {
14442   func = new TF1("func", "gaus(0)", -2, 2);
14443   func->SetParameters(1, 0, 0.5);
14444   
14445   hist = new TH1F("hist", "", 100, -2, 2);
14446   hist->FillRandom("func", 10000);
14447   
14448   func = new TF1("func", "gaus(0)", -2, 2);
14449   func->SetParLimits(2, 0, 10);
14450   func->FixParameter(1, 0);
14451   func->SetParameters(2, 0, 0.1);
14452   hist->Fit(func, "", "", -1, 1);
14453   hist->DrawCopy();
14454   
14455   func2 = new TF1("func2", "gaus(0)+[3]", -2, 2);
14456   func2->SetParLimits(2, 0, 10);
14457   func2->FixParameter(1, 0);
14458   func2->SetParameters(2, 0, 0.1, 0);
14459   func2->SetLineColor(2);
14460   hist->Fit(func2, "+", "", -1, 1);
14461   
14462   return;
14463
14464   new TCanvas;
14465   constant = new TF1("constant", "1", -2, 2);
14466   hist->Add(constant, -30);
14467   func->SetParameters(2, 0, 0.1);
14468   hist->Fit(func, "", "", -1, 1);
14469 }
14470
14471 void GaussToyFit2()
14472 {
14473   func = new TF2("func", "[0]*exp(-0.5*((x/[1])**2+(y/[2])**2))", -2, 2, -2, 2);
14474   func->SetParameters(1, 0.4, 0.6);
14475   
14476   hist = new TH2F("hist", "", 100, -2, 2, 100, -2, 2);
14477   hist->FillRandom("func", 100000);
14478   
14479   func = new TF2("func", "[0]*exp(-0.5*((x/[1])**2+(y/[2])**2))", -2, 2, -2, 2);
14480   func->SetParameters(1, 0.2, 0.2);
14481   hist->Fit(func, "", "");
14482   hist->DrawCopy();
14483   
14484   new TCanvas;
14485   hist->ProjectionX()->Fit("gaus");
14486
14487   new TCanvas;
14488   hist->ProjectionY()->Fit("gaus");
14489 }
14490
14491 void AcceptanceToy()
14492 {
14493   // study a la Jan Rak presented in Corr PAG on 06.03.12
14494   
14495   hist = new TH1F("hist", "", 200, -1.5, 1.5);
14496   
14497   Float_t sigma = 0.3;
14498   for (Int_t i=0; i<1000000; i++)
14499   {
14500     // randomize mean
14501     Float_t mean = gRandom->Uniform(-5, 5);
14502     
14503     Float_t trig = gRandom->Gaus(mean, sigma);
14504     Float_t assoc = gRandom->Gaus(mean, sigma);
14505     
14506 //     Float_t trig = gRandom->Uniform(-5, 5);
14507 //     Float_t assoc = gRandom->Uniform(-5, 5);
14508
14509 /*    if (trig < 0 && assoc < trig)
14510       continue;
14511     if (trig > 0 && assoc > trig)
14512       continue;*/
14513     
14514     if (TMath::Abs(trig) < 1 && TMath::Abs(assoc) < 1)
14515 //       hist->Fill(trig - assoc);
14516       hist->Fill(trig - assoc, 1.0 / (1.0 - TMath::Abs(trig-assoc) / 2));
14517   }
14518   
14519   hist->Draw();
14520   hist->Fit("gaus", "", "", -1.5, 1.5);
14521   Printf("%f %f %f", sigma, hist->GetFunction("gaus")->GetParameter(2), hist->GetFunction("gaus")->GetParameter(2) / TMath::Sqrt(2));
14522   hist->GetFunction("gaus")->SetLineColor(2);
14523 }
14524
14525 void DrawEfficiency(const char* fileName, Int_t step1, Int_t step2)
14526 {
14527   gpTMin = 1.01;
14528   gpTMax = 1.99;
14529   
14530   loadlibs();
14531   
14532   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
14533   hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
14534   
14535   SetupRanges(h);
14536   SetupRanges(hMixed);
14537
14538   TH1* hist1 = 0;
14539   TH1* hist2 = 0;
14540   
14541   GetDistAndFlow(h, hMixed, &hist1,  0, step1, 0,  10, 2.01, 3.99, 1, kTRUE, 0, kTRUE); 
14542   GetDistAndFlow(h, hMixed, &hist2,  0, step2, 0,  10, 2.01, 3.99, 1, kTRUE, 0, kTRUE); 
14543   
14544   ((TH2*)hist1)->Rebin2D(2, 2);
14545   ((TH2*)hist2)->Rebin2D(2, 2);
14546   
14547   new TCanvas("c", "c", 800, 800);
14548   gPad->SetLeftMargin(0.15);
14549   hist1->SetTitle("");
14550   hist1->GetYaxis()->SetRangeUser(-1.39, 1.39);
14551   hist1->GetXaxis()->SetTitleOffset(1.5);
14552   hist1->GetYaxis()->SetTitleOffset(2);
14553   hist1->SetStats(kFALSE);
14554   hist1->DrawCopy("SURF1");
14555   
14556   new TCanvas("c2", "c2", 800, 800);
14557   gPad->SetLeftMargin(0.15);
14558   hist2->SetTitle("");
14559   hist2->GetYaxis()->SetRangeUser(-1.39, 1.39);
14560   hist2->GetXaxis()->SetTitleOffset(1.5);
14561   hist2->GetYaxis()->SetTitleOffset(2);
14562   hist2->SetStats(kFALSE);
14563   hist2->DrawCopy("SURF1");
14564   
14565   hist2->Divide(hist1);
14566
14567   new TCanvas("c3", "c3", 800, 800);
14568   gPad->SetLeftMargin(0.15);
14569   hist2->SetTitle("");
14570   hist2->GetYaxis()->SetRangeUser(-1.39, 1.39);
14571   hist2->GetXaxis()->SetTitleOffset(1.5);
14572   hist2->GetYaxis()->SetTitleOffset(2);
14573   hist2->SetStats(kFALSE);
14574   hist2->Draw("SURF1");
14575 }
14576
14577 void RewriteObjects(const char* fileName)
14578 {
14579   loadlibs();
14580
14581   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
14582   Int_t nAxes = ((AliTHn*) h->GetUEHist(2)->GetTrackHist(0)->GetNVar());
14583   Printf("We have %d axes", nAxes);
14584   
14585   TString histId; histId.Form("%dRC", nAxes-1);
14586   Printf("%s", histId.Data());
14587   
14588   AliUEHistograms* hNew = new AliUEHistograms(h->GetName(), histId);
14589   hNew->DeepCopy(h);
14590   delete h;
14591   
14592   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);  
14593   AliUEHistograms* hMixedNew = new AliUEHistograms(hMixed->GetName(), histId);
14594   hMixedNew->DeepCopy(hMixed);
14595   delete hMixed;
14596   
14597   TString newFileName(fileName);
14598   newFileName.ReplaceAll(".root", "");
14599   newFileName += "_rebinned.root";
14600
14601   list = new TList;
14602   list->Add(hNew);
14603   list->Add(hMixedNew);
14604
14605   file3 = TFile::Open(newFileName, "RECREATE");
14606   file3->mkdir("PWG4_PhiCorrelations");
14607   file3->cd("PWG4_PhiCorrelations");
14608   list->Write("histosPhiCorrelations", TObject::kSingleKey);
14609   file3->Close();
14610 }
14611
14612 void CondenseCentrality(const char* fileName, Float_t targetValue, Int_t step = 0, Float_t from = 0, Float_t to = -1)
14613 {
14614   loadlibs();
14615
14616   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
14617   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);  
14618   
14619   h->GetUEHist(2)->CondenseBin(step, 3, 1, targetValue, from, to);
14620   hMixed->GetUEHist(2)->CondenseBin(step, 3, 1, targetValue, from, to);
14621   
14622   Float_t events = h->GetCentralityDistribution()->Integral();
14623   h->GetCentralityDistribution()->Reset();
14624   h->GetCentralityDistribution()->Fill(targetValue, events);
14625   
14626   events = hMixed->GetCentralityDistribution()->Integral();
14627   hMixed->GetCentralityDistribution()->Reset();
14628   hMixed->GetCentralityDistribution()->Fill(targetValue, events);
14629   
14630   TString newFileName(fileName);
14631   newFileName.ReplaceAll(".root", "");
14632   newFileName += "_condensed.root";
14633
14634   list = new TList;
14635   list->Add(h);
14636   list->Add(hMixed);
14637
14638   file3 = TFile::Open(newFileName, "RECREATE");
14639   file3->mkdir("PWG4_PhiCorrelations");
14640   file3->cd("PWG4_PhiCorrelations");
14641   list->Write("histosPhiCorrelations", TObject::kSingleKey);
14642   file3->Close();
14643 }
14644
14645 void SymmetrizepTBins(const char* fileName)
14646 {
14647   // copy pt,a < pt,t bins to pt,a > pt,t
14648   
14649   loadlibs();
14650
14651   TList* list = 0;
14652   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName, &list);
14653   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);  
14654   
14655   h->GetUEHist(2)->SymmetrizepTBins();
14656   hMixed->GetUEHist(2)->SymmetrizepTBins();
14657
14658   TString newFileName(fileName);
14659   newFileName.ReplaceAll(".root", "");
14660   newFileName += "_symmetrized.root";
14661
14662   file3 = TFile::Open(newFileName, "RECREATE");
14663   file3->mkdir("PWG4_PhiCorrelations");
14664   file3->cd("PWG4_PhiCorrelations");
14665   list->Write("histosPhiCorrelations", TObject::kSingleKey);
14666   file3->Close();
14667 }
14668
14669 void PtDistributions(Int_t step = 8, Float_t centralityBegin = 1, Float_t centralityEnd = 10)
14670 {
14671   loadlibs();
14672
14673 //   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" };
14674   
14675 //   const char* fileNames[] = { "LHC10h_AOD086_120411_zvtx_rebinned.root", "LHC10h_AOD086_120411_hybrid_zvtx_rebinned.root", "LHC10h_AOD086_120430_raacuts_zvtx_rebinned.root" };
14676   const char* fileNames[] = { "pt_pos.root", "pt_neg.root" };
14677 //   const char* fileNames[] = { "LHC11a10a_bis_AOD090_120406_zvtx.root" };
14678
14679 //   Float_t eventCount[] = { 1098234., 1034306., 1369707. };
14680 //   Float_t eventCount[] = { 987360.000000, 930278.000000, 1231806.000000 };
14681   Float_t eventCount[] = { 1., 1. };
14682
14683   TH1* pt[3];
14684
14685   new TCanvas;
14686   for (Int_t i=0; i<2; i++)
14687   {
14688 /*    AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileNames[i]);
14689     
14690     h->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->SetRangeUser(0.01 + centralityBegin, -0.01 + centralityEnd);
14691     ptDist = h->GetUEHist(2)->GetEventHist()->Project(step, 0);*/
14692     
14693 /*    eventCount = h->GetEventCount();
14694     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));*/
14695     Float_t events = eventCount[i];
14696     
14697     TFile::Open(fileNames[i]);
14698     ptDist = (TH2*) gFile->Get("ptDist");
14699     
14700     ptDistProj = ptDist->ProjectionX(Form("ptDistProj_%d", i), ptDist->GetYaxis()->FindBin(0.01 + centralityBegin), ptDist->GetYaxis()->FindBin(-0.01 + centralityEnd));
14701   
14702 //     new TCanvas; ptDistProj->Draw(); gPad->SetLogy();
14703   
14704    
14705     ptDistProj->Scale(1.0 / events);
14706     
14707     ptDistProj->SetLineColor(i+1);
14708     ptDistProj->DrawCopy((i == 0) ? "" : "SAME");
14709
14710     pt[i] = (TH1*) ptDistProj->Clone(Form("clone_%d", i));
14711   }
14712   gPad->SetLogy();
14713
14714   new TCanvas;
14715   for (Int_t i=1; i<2; i++)
14716   {
14717     pt[i]->Divide(pt[0]);
14718     pt[i]->DrawCopy((i == 1) ? "" : "SAME");
14719   }  
14720 }
14721
14722 void test(const char* fileNameESD)
14723 {
14724   Int_t step = 8;
14725   
14726   loadlibs();
14727   AliUEHistograms* esd = (AliUEHistograms*) GetUEHistogram(fileNameESD);
14728   
14729   SetupRanges(esd);
14730
14731   ptDist = (TH2*) esd->GetUEHist(2)->GetEventHist()->Project(step, 0, 1);
14732   
14733   Printf("%f", ptDist->Integral());
14734 }
14735
14736 void CorrectPtDistribution(const char* fileNameCorrections, const char* fileNameESD, const char* outputFile)
14737 {
14738   Int_t step = 8;
14739   
14740   loadlibs();
14741   
14742   AliUEHistograms* corr = (AliUEHistograms*) GetUEHistogram(fileNameCorrections);
14743   
14744   TList* list = 0;
14745   AliUEHistograms* esd = (AliUEHistograms*) GetUEHistogram(fileNameESD, &list);
14746   
14747   SetupRanges(corr);
14748   SetupRanges(esd);
14749   
14750   corr->SetEtaRange(-0.89, 0.89);
14751   corr->ExtendTrackingEfficiency(0);
14752
14753   eff = corr->GetUEHist(2)->GetTrackingEfficiencyCorrectionCentrality();
14754   new TCanvas; eff->Draw("COLZ");
14755   
14756   cont = corr->GetUEHist(2)->GetTrackingContaminationCentrality();
14757   new TCanvas; cont->Draw("COLZ");
14758   
14759   ptDist = (TH2*) esd->GetUEHist(2)->GetEventHist()->Project(step, 0, 1);
14760   ptDist->SetStats(0);
14761   new TCanvas; ptDist->DrawCopy("COLZ");
14762   
14763   for (Int_t x=1; x<=ptDist->GetNbinsX(); x++)
14764     for (Int_t y=1; y<=ptDist->GetNbinsY(); y++)
14765     {
14766       Float_t factor = eff->GetBinContent(eff->GetXaxis()->FindBin(ptDist->GetXaxis()->GetBinCenter(x)), eff->GetYaxis()->FindBin(ptDist->GetYaxis()->GetBinCenter(y)));
14767       Float_t contFactor = cont->GetBinContent(cont->GetXaxis()->FindBin(ptDist->GetXaxis()->GetBinCenter(x)), cont->GetYaxis()->FindBin(ptDist->GetYaxis()->GetBinCenter(y)));
14768       
14769       printf("%f", contFactor);
14770       if (contFactor > 0)
14771         contFactor = 1.0 + 1.1 * (contFactor - 1.0);
14772       printf(" --> %f\n", contFactor);
14773       
14774       factor *= contFactor;
14775       
14776       ptDist->SetBinContent(x, y, ptDist->GetBinContent(x, y) * factor);
14777       ptDist->SetBinError(x, y, ptDist->GetBinError(x, y) * factor);
14778     }
14779   
14780   new TCanvas; ptDist->DrawCopy("COLZ");
14781   
14782   file3 = TFile::Open(outputFile, "RECREATE");
14783   ptDist->Write("ptDist");
14784   file3->Write();
14785   file3->Close();
14786   
14787   delete corr;
14788   delete esd;
14789 }
14790
14791 void CorrectPtDistributionAll()
14792 {
14793   CorrectPtDistribution("LHC11a10a_bis_AOD090_120406.root", "LHC10h_AOD086_120411_zvtx_rebinned.root", "ptdist1.root");
14794   CorrectPtDistribution("LHC11a10a_bis_AOD090_120505_zvtx_hybrid.root", "LHC10h_AOD086_120411_hybrid_zvtx_rebinned.root", "ptdist2.root");
14795   CorrectPtDistribution("LHC11a10a_bis_AOD090_120505_zvtx_raa.root", "LHC10h_AOD086_120430_raacuts_zvtx_rebinned.root", "ptdist3.root");
14796 }
14797   
14798 void CreateNormalizationTestObject(Bool_t addRidge = kFALSE)
14799 {
14800   loadlibs();
14801   gSystem->Load("libPWGCFCorrelationsDPhi");
14802
14803   AliUEHistograms* hNew = new AliUEHistograms("AliUEHistogramsSame", "5RC");
14804   
14805   // fill 1000 particles in one bin
14806   TObjArray* particles = new TObjArray;
14807   particles->Add(new AliDPhiBasicParticle(0, 0, 3.5, 1));
14808   for (Int_t i=0; i<2000; i++)
14809     particles->Add(new AliDPhiBasicParticle(gRandom->Gaus(0, 0.3), gRandom->Gaus(0, 0.3), 1.75, 1));
14810   
14811   hNew->FillCorrelations(61, 0, 8, particles);
14812
14813   if (addRidge)
14814   {
14815     for (Int_t i=0; i<10000; i++)
14816       particles->Add(new AliDPhiBasicParticle(gRandom->Uniform(-2, 2), gRandom->Gaus(0, 0.5), 1.75, 1));
14817   }
14818
14819   hNew->FillCorrelations(0.5, 0, 8, particles);
14820
14821   // fill flat mixed event
14822   AliUEHistograms* hMixedNew = new AliUEHistograms("AliUEHistogramsMixed", "5RC");
14823   THnSparse* sparse = hMixedNew->GetUEHist(2)->GetTrackHist(0)->GetGrid(8)->GetGrid();
14824   for (Int_t x=1; x<=sparse->GetAxis(0)->GetNbins(); x++)
14825     for (Int_t y=1; y<=sparse->GetAxis(4)->GetNbins(); y++)
14826     {
14827       Double_t bin[6];
14828       bin[0] = sparse->GetAxis(0)->GetBinCenter(x);
14829       bin[4] = sparse->GetAxis(4)->GetBinCenter(y);
14830       bin[1] = 1.75;
14831       bin[2] = 3.5;
14832       bin[3] = 0.5;
14833       bin[5] = 0;
14834       sparse->Fill(bin);
14835
14836       bin[3] = 61;
14837       sparse->Fill(bin);
14838
14839       bin[3] = 0.5;
14840       bin[2] = 1.75;
14841       sparse->Fill(bin);
14842
14843       bin[3] = 61;
14844       sparse->Fill(bin);
14845     }
14846     
14847   Double_t bin[6];
14848   bin[0] = 3.5;
14849   bin[1] = 0.5;
14850   bin[2] = 0;
14851   hMixedNew->GetUEHist(2)->GetEventHist()->GetGrid(8)->GetGrid()->Fill(bin);
14852   
14853   bin[1] = 61;
14854   hMixedNew->GetUEHist(2)->GetEventHist()->GetGrid(8)->GetGrid()->Fill(bin);
14855
14856   bin[1] = 0.5;
14857   bin[0] = 1.75;
14858   hMixedNew->GetUEHist(2)->GetEventHist()->GetGrid(8)->GetGrid()->Fill(bin);
14859
14860   bin[1] = 61;
14861   hMixedNew->GetUEHist(2)->GetEventHist()->GetGrid(8)->GetGrid()->Fill(bin);
14862
14863   ((AliTHn*) hNew->GetUEHist(2)->GetTrackHist(0))->FillParent();
14864   ((AliTHn*) hNew->GetUEHist(2)->GetTrackHist(0))->DeleteContainers();
14865
14866   ((AliTHn*) hMixedNew->GetUEHist(2)->GetTrackHist(0))->FillParent();
14867   ((AliTHn*) hMixedNew->GetUEHist(2)->GetTrackHist(0))->DeleteContainers();
14868
14869   list = new TList;
14870   list->Add(hNew);
14871   list->Add(hMixedNew);
14872
14873   file3 = TFile::Open("norm.root", "RECREATE");
14874   file3->mkdir("PWG4_PhiCorrelations");
14875   file3->cd("PWG4_PhiCorrelations");
14876   list->Write("histosPhiCorrelations", TObject::kSingleKey);
14877   file3->Close();
14878 }
14879
14880 void CompareSumOfRatiosAndDefault(const char* fileName, Int_t bin, Int_t step)
14881 {
14882   loadlibs();
14883  
14884   Int_t centralityFrom = 0;
14885   Int_t centralityTo = 20;
14886   
14887   gpTMin = 1.01;
14888   gpTMax = 1.99;
14889   
14890   Float_t ptTrigBegin = 2.01;
14891   Float_t ptTrigEnd = 3.99;
14892   
14893   if (bin == 1)
14894   {
14895     ptTrigBegin = 1.01;
14896     ptTrigEnd = 1.99;
14897   }
14898   else if (bin == 2)
14899   {
14900     gpTMin = 0.49;
14901     gpTMax = 0.99;
14902     ptTrigBegin = 0.49;
14903     ptTrigEnd = 0.99;
14904   }
14905   
14906   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
14907   hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
14908   
14909   SetupRanges(h);
14910   SetupRanges(hMixed);
14911   
14912   TH2* hist1 = 0;
14913   TH2* hist2 = 0;
14914   GetSumOfRatios(h, hMixed, &hist1,  step, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, kTRUE); 
14915   GetDistAndFlow(h, hMixed, &hist2,  0, step, centralityFrom, centralityTo,  ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE);
14916   
14917   hist1->Rebin2D(2, 2); hist1->Scale(0.25);
14918   hist2->Rebin2D(2, 2); hist2->Scale(0.25);
14919   
14920   c = new TCanvas("c", "c", 1000, 1000);
14921   c->Divide(2, 3);
14922   
14923   c->cd(1);
14924   hist1->DrawCopy("SURF1");
14925
14926   c->cd(2);
14927   hist2->DrawCopy("SURF1");
14928   
14929   c->cd(4);
14930   proj1 = ((TH2*) hist1)->ProjectionY("proj1", hist1->GetXaxis()->FindBin(-0.99), hist1->GetXaxis()->FindBin(0.99));
14931   proj1->DrawCopy();
14932   proj2 = ((TH2*) hist2)->ProjectionY("proj2", hist2->GetXaxis()->FindBin(-0.99), hist2->GetXaxis()->FindBin(0.99));
14933   proj2->SetLineColor(2);
14934   proj2->DrawCopy("SAME");
14935   
14936   c->cd(5);
14937   proj1->Divide(proj1, proj2, 1, 1, "B");
14938   proj1->DrawCopy();
14939   
14940   c->cd(3);
14941   hist1->Divide(hist2);
14942   hist1->DrawCopy("SURF1");
14943 }
14944
14945 void PtDistribution(const char* fileName, Int_t step, Int_t bin = 0)
14946 {
14947   Int_t centralityFrom = 0;
14948   Int_t centralityTo = 80;
14949   
14950   Float_t ptTrigBegin = 2.01;
14951   Float_t ptTrigEnd = 3.99;
14952   
14953   if (bin == 1)
14954   {
14955     ptTrigBegin = 1.01;
14956     ptTrigEnd = 1.99;
14957   }
14958   else if (bin == 2)
14959   {
14960     ptTrigBegin = 0.51;
14961     ptTrigEnd = 0.99;
14962   }
14963   
14964   loadlibs();
14965   
14966   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
14967
14968   Int_t centralityBeginBin = 0;
14969   Int_t centralityEndBin = -1;
14970   
14971   if (centralityTo >= centralityFrom)
14972   {
14973     centralityBeginBin = h->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->FindBin(0.01 + centralityFrom);
14974     centralityEndBin = h->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->FindBin(-0.01 + centralityTo);
14975   }
14976
14977   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);
14978   pt2 = h->GetUEHist(2)->GetPtHist(step, 0, ptTrigBegin, ptTrigEnd, centralityBeginBin, centralityEndBin, -0.5, 0.5, -1.99, 1.99);
14979   
14980   new TCanvas;
14981   pt1->DrawCopy();
14982   pt2->SetLineColor(2);
14983   pt2->DrawCopy("SAME");
14984   gPad->SetLogy();
14985   
14986   // TODO proper subtraction, to get the pT distribution in the peak
14987 }
14988
14989 void GetRefMultiplicity(const char* fileNameESD, const char* tag = "")
14990 {
14991   Int_t step = 8;
14992   
14993   loadlibs();
14994   
14995   AliUEHistograms* esd = (AliUEHistograms*) GetUEHistogram(fileNameESD, 0, kFALSE, tag);
14996   
14997   Float_t centrBins[] = { 0, 20, 40, 60, 100 };
14998 //   Float_t centrBins[] = { 0, 100 };
14999   
15000   // NOTE Run it on data with limited zvtx range so that there are no empty bins in the corrections!
15001   
15002   for (Int_t i=0; i<4; i++)
15003   {
15004     Float_t centrBegin = centrBins[i] + 0.1;
15005     Float_t centrEnd   = centrBins[i+1] - 0.1;
15006     esd->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->SetRangeUser(centrBegin, centrEnd);
15007   
15008     ptDist = (TH2*) esd->GetUEHist(2)->GetEventHist()->Project(step, 0);
15009   
15010     centrDist = esd->GetCentralityDistribution();
15011     
15012     if (1)
15013     {
15014       // add syst from R_pA
15015       for (Int_t j=1; j<=ptDist->GetNbinsX(); j++)
15016         ptDist->SetBinError(j, TMath::Sqrt(ptDist->GetBinError(j) * ptDist->GetBinError(j) + 0.052 * 0.052 * ptDist->GetBinContent(j) * ptDist->GetBinContent(j)));
15017     }
15018     
15019     Float_t events = centrDist->Integral(centrDist->FindBin(centrBegin), centrDist->FindBin(centrEnd));
15020     Double_t error = 0;
15021 //     Float_t integral = ptDist->IntegralAndError(ptDist->FindBin(0.51), ptDist->FindBin(3.99), error);
15022     Float_t integral = ptDist->IntegralAndError(ptDist->FindBin(0.51), ptDist->FindBin(7.99), error);
15023     Printf("%d: %f +- %f %f --> %f +- %F", i, integral, error, events, integral / events, error / events);
15024     
15025     ptDist->Scale(1.0 / events);
15026 //     ptDist->Scale(1.0 / integral);
15027   
15028 //     ptDist->Rebin(2); 
15029     
15030     NormalizeToBinWidth(ptDist);
15031     ptDist->SetLineColor(i + 1);
15032     ptDist->DrawCopy((i == 0) ? "" : "SAME");
15033   }
15034   gPad->SetLogy();
15035   
15036   TFile::Open("dNdPt_pPb_lab_MinBias_NEW.root");
15037   comparison = (TH1*) gFile->Get("dNdPt_pPb_eta08_stat");
15038   comparison->Scale(1.6); // normalize to my eta range
15039   comparison->SetLineColor(2);
15040   comparison->DrawCopy("SAME");
15041   
15042   //rebin
15043   for (Int_t i=1; i<=comparison->GetNbinsX(); i++)
15044   {
15045     // multiply by bin width
15046     comparison->SetBinContent(i, comparison->GetBinContent(i) * comparison->GetBinWidth(i));
15047     comparison->SetBinError(i, comparison->GetBinError(i) * comparison->GetBinWidth(i));
15048   }
15049
15050   Float_t integral = comparison->IntegralAndError(comparison->FindBin(0.51), comparison->FindBin(7.99), error);
15051   Float_t integral2 = comparison->IntegralAndError(comparison->FindBin(0.51), comparison->FindBin(19.99), error);
15052   Printf("%f %f", integral, integral2);
15053     
15054   Float_t integral = comparison->IntegralAndError(comparison->FindBin(0.51), comparison->FindBin(7.99), error);
15055   Float_t integral2 = comparison->IntegralAndError(comparison->FindBin(0.61), comparison->FindBin(7.99), error);
15056   Printf("%f %f", integral, integral2);
15057
15058   rebinned = comparison->Rebin(ptDist->GetNbinsX(), "rebinned", ptDist->GetXaxis()->GetXbins()->GetArray());
15059   
15060   
15061   NormalizeToBinWidth(rebinned);
15062   rebinned->Draw("SAME");
15063   
15064   new TCanvas;
15065   ptDist->Divide(rebinned);
15066   ptDist->Draw();
15067   
15068   return;
15069   
15070   new TCanvas;
15071   syst = (TH1*) gFile->Get("dNdPt_pPb_eta08_syst");
15072   syst->DrawCopy();
15073   
15074   new TCanvas;
15075   for (Int_t i=1; i<=syst->GetNbinsX(); i++)
15076   {
15077     if (syst->GetBinContent(i) > 0)
15078       syst->SetBinContent(i, syst->GetBinError(i) / syst->GetBinContent(i));
15079     syst->SetBinError(i, 0);
15080   }
15081   syst->Draw();
15082 }
15083
15084 void CheckBin(const char* fileName)
15085 {
15086   loadlibs();
15087
15088   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
15089   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
15090   
15091   sparse = h->GetUEHist(2)->GetTrackHist(0)->GetGrid(8)->GetGrid();
15092   sparse->GetAxis(1)->SetRangeUser(5, 5.1);
15093   sparse->GetAxis(2)->SetRangeUser(7, 7.1);
15094   sparse->GetAxis(3)->SetRangeUser(90, 91);
15095   sparse->GetAxis(4)->SetRangeUser(9, 9.1);
15096  
15097   new TCanvas;
15098   sparse->Projection(0, 4)->Draw("colz");
15099
15100   sparse = hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(8)->GetGrid();
15101   sparse->GetAxis(1)->SetRangeUser(5, 5.1);
15102   sparse->GetAxis(2)->SetRangeUser(7, 7.1);
15103   sparse->GetAxis(3)->SetRangeUser(90, 91);
15104   sparse->GetAxis(4)->SetRangeUser(9, 9.1);
15105  
15106   new TCanvas;
15107   sparse->Projection(0, 4)->Draw("colz");
15108 }
15109
15110 void GetCorrectedYields(const char* fileName, const char* correctionFile, const char* tagCorrections = "", Int_t partSpecies=-1 )
15111 {
15112   loadlibs();
15113
15114   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
15115   
15116   // centrality, pT, eta
15117   yieldsUncorr = h->GetYield();
15118   new TCanvas; yieldsUncorr->DrawCopy();
15119 //   new TCanvas; yieldsUncorr->ProjectionX("x1")->DrawCopy();
15120  
15121   AliUEHistograms* hCorr = (AliUEHistograms*) GetUEHistogram(correctionFile, 0, kFALSE, tagCorrections);
15122   if(partSpecies!=-1){
15123     Double_t epsilon=0.001;
15124     hCorr->GetUEHist(2)->GetTrackHistEfficiency()->GetGrid(0)->GetGrid()->GetAxis(2)->SetRangeUser(partSpecies-epsilon,partSpecies+epsilon);
15125     hCorr->GetUEHist(2)->GetTrackHistEfficiency()->GetGrid(4)->GetGrid()->GetAxis(2)->SetRangeUser(partSpecies-epsilon,partSpecies+epsilon);
15126   }
15127   
15128   hCorr->GetUEHist(2)->GetTrackHistEfficiency()->GetGrid(0)->GetGrid()->GetAxis(4)->SetRangeUser(-1.9, 1.9);
15129   hCorr->GetUEHist(2)->GetTrackHistEfficiency()->GetGrid(2)->GetGrid()->GetAxis(4)->SetRangeUser(-1.9, 1.9);
15130   hCorr->GetUEHist(2)->GetTrackHistEfficiency()->GetGrid(4)->GetGrid()->GetAxis(4)->SetRangeUser(-1.9, 1.9);
15131   
15132   // eta, pT
15133   TH2* generated = hCorr->GetUEHist(2)->GetTrackHistEfficiency()->GetGrid(0)->GetGrid()->Projection(1, 0);
15134   TH2* measured = hCorr->GetUEHist(2)->GetTrackHistEfficiency()->GetGrid((partSpecies==-1)?2:4)->GetGrid()->Projection(1, 0);
15135   
15136   Printf("%f %f", generated->GetEntries(), measured->GetEntries());
15137
15138   new TCanvas; generated->Draw("COLZ");
15139   new TCanvas; measured->Draw("COLZ");
15140   
15141   effCorr = (TH2*) generated->Clone("correction");
15142   effCorr->Divide(generated, measured, 1, 1, "B");
15143   
15144   new TCanvas; effCorr->Draw("COLZ");
15145   
15146 //   return;
15147   
15148   yieldsCorr = (TH3F*) yieldsUncorr->Clone("fYieldsCorr");
15149   yieldsCorr->Reset();
15150   
15151   for (Int_t x=1; x<=yieldsUncorr->GetNbinsX(); x++)
15152     for (Int_t y=1; y<=yieldsUncorr->GetNbinsY(); y++)
15153       for (Int_t z=1; z<=yieldsUncorr->GetNbinsZ(); z++)
15154       {
15155         Double_t factor = effCorr->GetBinContent(effCorr->GetXaxis()->FindBin(yieldsUncorr->GetZaxis()->GetBinCenter(z)), effCorr->GetYaxis()->FindBin(yieldsUncorr->GetYaxis()->GetBinCenter(y)));
15156         yieldsCorr->SetBinContent(x, y, z, yieldsUncorr->GetBinContent(x, y, z) * factor);
15157         yieldsCorr->SetBinError(x, y, z, yieldsUncorr->GetBinError(x, y, z) * factor);
15158       }
15159
15160   new TCanvas; yieldsCorr->DrawCopy();
15161   
15162   TFile::Open("corr_yield.root", "RECREATE");
15163   yieldsCorr->Write();
15164   gFile->Close();
15165   
15166   // normalize per event
15167   centrDist = h->GetCentralityCorrelation()->ProjectionX();
15168   new TCanvas; centrDist->Draw();
15169
15170   for (Int_t x=1; x<=yieldsCorr->GetNbinsX(); x++)
15171   {
15172     Double_t factor = centrDist->Integral(centrDist->FindBin(yieldsCorr->GetXaxis()->GetBinLowEdge(x)+0.0001), centrDist->FindBin(yieldsCorr->GetXaxis()->GetBinUpEdge(x)-0.0001));
15173 //     Printf("%d %f %f %d %d %f", x, yieldsCorr->GetXaxis()->GetBinLowEdge(x), yieldsCorr->GetXaxis()->GetBinUpEdge(x), centrDist->FindBin(yieldsCorr->GetXaxis()->GetBinLowEdge(x)+0.0001), centrDist->FindBin(yieldsCorr->GetXaxis()->GetBinUpEdge(x)-0.0001), factor);
15174     if (factor <= 0)
15175       continue;
15176     
15177     for (Int_t y=0; y<=yieldsCorr->GetNbinsY()+1; y++)
15178       for (Int_t z=0; z<=yieldsCorr->GetNbinsZ()+1; z++)
15179       {
15180         if (yieldsCorr->GetBinContent(x, y, z) > 0)
15181         {
15182           yieldsCorr->SetBinContent(x, y, z, yieldsCorr->GetBinContent(x, y, z) / factor);
15183           yieldsCorr->SetBinError(x, y, z, yieldsCorr->GetBinError(x, y, z) / factor);
15184         }
15185         if (yieldsUncorr->GetBinContent(x, y, z) > 0)
15186         {
15187           yieldsUncorr->SetBinContent(x, y, z, yieldsUncorr->GetBinContent(x, y, z) / factor);
15188           yieldsUncorr->SetBinError(x, y, z, yieldsUncorr->GetBinError(x, y, z) / factor);
15189         }
15190       }
15191   }
15192
15193   TFile::Open("corr_yield.root", "UPDATE");
15194   yieldsCorr->Write("fYieldsCorr_per_event");
15195   centrDist->Write("events");
15196   gFile->Close();
15197
15198   //   new TCanvas; yieldsUncorr->ProjectionX("x2")->DrawCopy(); return;
15199   
15200   yieldsUncorr->GetXaxis()->SetRangeUser(1, yieldsUncorr->GetNbinsX());
15201
15202   new TCanvas; yieldsUncorr->Project3D("z1")->DrawCopy()->SetLineColor(1); yieldsCorr->Project3D("z2")->DrawCopy("SAME")->SetLineColor(2);
15203
15204   yieldsUncorr->GetXaxis()->SetRangeUser(0.1, 9.9);
15205   yieldsCorr->GetXaxis()->SetRangeUser(0.1, 9.9);
15206   new TCanvas; yieldsUncorr->Project3D("z3")->DrawCopy()->SetLineColor(1); yieldsCorr->Project3D("z4")->DrawCopy("SAME")->SetLineColor(2);
15207   yieldsUncorr->GetXaxis()->SetRangeUser(60.1, 99.9);
15208   yieldsCorr->GetXaxis()->SetRangeUser(60.1, 99.9);
15209   yieldsUncorr->Project3D("z5")->DrawCopy("SAME")->SetLineColor(3); yieldsCorr->Project3D("z6")->DrawCopy("SAME")->SetLineColor(4);
15210 }
15211
15212 void PlotPtCentrality()
15213 {
15214   TFile::Open("corr_yield.root");
15215   yieldsCorr = (TH3F*) gFile->Get("fYieldsCorr");
15216   
15217   yieldsCorr->GetZaxis()->SetRangeUser(-0.4999, 0.4999);
15218   yieldsProj = (TH2*) yieldsCorr->Project3D("yx");
15219   Printf("%f", yieldsProj->Integral());
15220   
15221   Float_t ptMin[] = { 0.5001, 1.0001, 2.0001 };
15222   Float_t ptMax = 10;
15223   
15224   for (Int_t i=0; i<3; i++)
15225   {
15226     profile = yieldsProj->ProjectionX(Form("x%d", i), yieldsProj->GetYaxis()->FindBin(ptMin[i]), yieldsProj->GetYaxis()->FindBin(ptMax));
15227     profile->SetLineColor(i+1);
15228     profile->Draw((i > 0) ? "SAME" : "");
15229   }
15230 }
15231
15232 void ExtractForAllSpecies()
15233 {
15234   TString baseName = "LHC13b2_fix_1_Train";
15235   const char* suffix[] = { "55_Hadrons_symmetrized", "63_Pions", "63_Kaons", "63_Protons" };
15236   TString baseNameOutput = "dphi_corr_mc_130531_allpt_";
15237   
15238   for (Int_t i=0; i<4; i++)
15239     PlotDeltaPhiEtaGap(baseName + suffix[i] + ".root", 0, 0, 0, baseNameOutput + suffix[i] + ".root");
15240 }
15241
15242 void Compare2D(const char* fileName, const char* fileName2)
15243 {
15244   Int_t step = 8;
15245   
15246   gpTMin = 1.01;
15247   gpTMax = 1.99;
15248   
15249   loadlibs();
15250   
15251   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
15252   hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
15253   
15254   AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(fileName2);
15255   hMixed2 = (AliUEHistograms*) GetUEHistogram(fileName2, 0, kTRUE);
15256
15257   SetupRanges(h);
15258   SetupRanges(hMixed);
15259   SetupRanges(h2);
15260   SetupRanges(hMixed2);
15261   
15262 //   h->SetZVtxRange(0.1, 0.5);
15263 //   hMixed->SetZVtxRange(0.1, 0.5);
15264 //   h2->SetZVtxRange(0.1, 0.5);
15265 //   hMixed2->SetZVtxRange(0.1, 0.5);
15266   
15267   TH1* hist1 = 0;
15268   GetDistAndFlow(h, 0, &hist1,  0, step, 0,  20, 1.01, 1.99, 1, kTRUE, 0, kTRUE); 
15269   
15270   TH1* hist2 = 0;
15271   GetDistAndFlow(h2, 0, &hist2,  0, step, 0,  20, 1.01, 1.99, 1, kTRUE, 0, kTRUE); 
15272
15273   c = new TCanvas("c", "c", 1600, 800);
15274   c->Divide(2, 1);
15275   c->cd(1);
15276   gPad->SetLeftMargin(0.15);
15277
15278   hist1->DrawCopy("SURF1");
15279   
15280   c->cd(2);
15281   gPad->SetLeftMargin(0.15);
15282
15283   hist2->DrawCopy("SURF1");
15284   
15285   Printf("%f %f", hist1->Integral(), hist2->Integral());
15286   
15287   new TCanvas("c3", "c3", 800, 800);
15288   gPad->SetLeftMargin(0.15);
15289   hist2->Divide(hist1);
15290   hist2->DrawCopy("COLZ");
15291 }
15292
15293 //Geant3/Fluka correction for tracking from the spectra analysis
15294 TF1 *
15295 TrackingEff_geantflukaCorrection(Int_t ipart, Int_t icharge)
15296 {
15297
15298   if (ipart == 3 && icharge == kNegative) {
15299     TF1 *f = new TF1(Form("fGeantFluka_%s_%s", AliPID::ParticleName(ipart), Sign[icharge]), "TrackingPtGeantFlukaCorrectionKaMinus(x);p_{T};GF correction", 0., 5.);
15300     return f;
15301   }
15302   else if (ipart == 4 && icharge == kNegative) {
15303     TF1 *f = new TF1(Form("fGeantFluka_%s_%s", AliPID::ParticleName(ipart), Sign[icharge]), "TrackingPtGeantFlukaCorrectionPrMinus(x);p_{T};GF correction", 0., 5.);
15304   }
15305   else
15306     TF1 *f = new TF1(Form("fGeantFluka_%s_%s", AliPID::ParticleName(ipart), Sign[icharge]), "TrackingPtGeantFlukaCorrectionNull(x);p_{T};GF correction", 0., 5.);
15307
15308   return f;
15309 }
15310
15311 Double_t
15312 TrackingPtGeantFlukaCorrectionNull(Double_t pTmc)
15313 {
15314   return 1.;
15315 }
15316
15317 Double_t
15318 TrackingPtGeantFlukaCorrectionPrMinus(Double_t pTmc)
15319 {
15320   return (1 - 0.129758 *TMath::Exp(-pTmc*0.679612));
15321 }
15322
15323 Double_t
15324 TrackingPtGeantFlukaCorrectionKaMinus(Double_t pTmc)
15325 {
15326   return TMath::Min((0.972865 + 0.0117093*pTmc), 1.);
15327 }
15328
15329 //Geant3/Fluka correction for matching from the spectra analysis
15330 TF1 *
15331 TOFmatchMC_geantflukaCorrection(Int_t ipart, Int_t icharge,Int_t ntrd)
15332 {
15333   if (ipart == 3 && icharge == kNegative) {
15334     TF1 *f = new TF1(Form("fGeantFluka_%s_%s", AliPID::ParticleName(ipart), Sign[icharge]),Form("MatchingPtGeantFlukaCorrectionKaMinus(x,%d);p_{T};GF correction",ntrd), 0., 5.);
15335     return f;
15336   }
15337   else if (ipart == 4 && icharge == kNegative) {
15338     TF1 *f = new TF1(Form("fGeantFluka_%s_%s", AliPID::ParticleName(ipart), Sign[icharge]),Form("MatchingPtGeantFlukaCorrectionPrMinus(x,%d);p_{T};GF correction",ntrd), 0., 5.);
15339   }
15340   else
15341     TF1 *f = new TF1(Form("fGeantFluka_%s_%s", AliPID::ParticleName(ipart), Sign[icharge]), "MatchingPtGeantFlukaCorrectionNull(x);p_{T};GF correction", 0., 5.);
15342   
15343   return f;
15344 }
15345
15346
15347 Double_t
15348 MatchingPtGeantFlukaCorrectionNull(Double_t pTmc)
15349 {
15350   return 1.;
15351 }
15352 Double_t
15353 MatchingPtGeantFlukaCorrectionKaMinus(Double_t pTmc, Int_t ntrd = 7)//ntrd is 7 in 2010, 10 in 2011, 13 in 2012+2013
15354 {
15355   Float_t ptTPCoutK=pTmc*(1- 3.37297e-03/pTmc/pTmc - 3.26544e-03/pTmc);
15356   Float_t scale = (ntrd * 0.14638485 + (18 - ntrd) * 0.02406) / 18.;
15357   return TMath::Min((TMath::Power(0.972865 + 0.0117093*ptTPCoutK,scale/0.03471)), 1.);
15358 }
15359 Double_t
15360 MatchingPtGeantFlukaCorrectionPrMinus(Double_t pTmc, Int_t ntrd = 7)//ntrd is 7 in 2010, 10 in 2011, 13 in 2012+2013
15361 {
15362   Float_t ptTPCoutP =pTmc*(1-6.81059e-01*TMath::Exp(-pTmc*4.20094));
15363   Float_t scale = (ntrd * 0.14638485 + (18 - ntrd) * 0.02406) / 18.;
15364   return (TMath::Power(1 - 0.129758*TMath::Exp(-ptTPCoutP*0.679612),scale/0.03471));
15365 }
15366
15367 void Browse(const char* fileName)
15368 {
15369   loadlibs();
15370
15371   if (!gGrid && TString(fileName).BeginsWith("alien://"))
15372     TGrid::Connect("alien://");
15373   
15374   TFile::Open(fileName);
15375
15376   new TBrowser;
15377 }
15378
15379 void CalculateCentralityWeights(const char* fileName)
15380 {
15381   loadlibs();
15382
15383   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
15384
15385   // data
15386 //   Bool_t bins = kFALSE;
15387 //   Int_t n = 5;
15388 //   Int_t binning[] = { 0, 10, 20, 30, 50, 80 };
15389 //   TH1* centralityDist = h->GetCentralityCorrelation()->ProjectionX();
15390
15391   // AMPT
15392   Bool_t bins = kTRUE;
15393   Int_t n = 5;
15394   Int_t binning[] = { 1, 3, 4, 5, 7, 10 };
15395   TH1* centralityDist = h->GetCentralityDistribution();
15396   
15397   new TCanvas;
15398   centralityDist->DrawCopy();
15399   
15400   for (Int_t i=0; i<n; i++)
15401   {
15402     if (bins)
15403     {
15404       Int_t minBin = binning[i];
15405       Int_t maxBin = binning[i+1]-1;
15406     }
15407     else
15408     {
15409       Int_t minBin = centralityDist->FindBin(binning[i]+0.01);
15410       Int_t maxBin = centralityDist->FindBin(binning[i+1]-0.01);
15411     }
15412     
15413     Float_t min = centralityDist->GetBinContent(minBin);
15414     for (Int_t bin=minBin; bin<=maxBin; bin++)
15415       min = TMath::Min(min, centralityDist->GetBinContent(bin));
15416     
15417     for (Int_t bin=minBin; bin<=maxBin; bin++)
15418       centralityDist->SetBinContent(bin, min / centralityDist->GetBinContent(bin));
15419   }
15420   
15421   for (Int_t bin=centralityDist->FindBin(binning[n]+0.01); bin<=centralityDist->GetNbinsX(); bin++)
15422     centralityDist->SetBinContent(bin, 1);
15423   
15424   new TCanvas;
15425   centralityDist->DrawCopy();
15426   
15427   file = TFile::Open("centralityWeights.root", "RECREATE");
15428   centralityDist->Write("weights");
15429   file->Close();  
15430 }
15431
15432 Double_t gIntegral = 0;
15433 Double_t FitFunctionGauss(Double_t *x, Double_t *par)
15434 {
15435   Double_t integralGaussian = TMath::Erf(1.8/TMath::Sqrt(2)/par[2]);
15436   Double_t par0 = gIntegral / integralGaussian;
15437   
15438   return par0/TMath::Sqrt(TMath::TwoPi())/par[2] * TMath::Exp(-0.5*x[0]*x[0]/par[2]/par[2]); 
15439 }
15440
15441 void correction_gauss_one(Float_t begin, Float_t end, Bool_t silent = kTRUE)
15442 {
15443   graph = new TGraph;
15444   graph2 = new TGraph;
15445   for (Float_t f=0.1; f<1.0; f+=0.01)
15446   {
15447     TH1* hist = new TH1F("hist", "", 60, -3, 3);
15448     TF1* func = new TF1("func", "gaus(0)", -5, 5);
15449     if (!silent)
15450       f = 0.85;
15451     func->SetParameters(1, 0, f);
15452     hist->FillRandom("func", 1000000);
15453     hist->Sumw2();
15454     hist->Scale(1.0 / hist->GetMaximum());
15455   //   hist->GetXaxis()->SetRangeUser(-1.39, 1.39);
15456     hist->SetLineWidth(2);
15457     
15458     clone = (TH1*) hist->Clone("clone");
15459     
15460     if (1)
15461     {
15462       for (Int_t i=hist->FindBin(-0.29); i<=hist->FindBin(0.29); i++)
15463         hist->SetBinError(i, 1e4);
15464     }    
15465
15466     if (!silent)
15467     {
15468       new TCanvas;
15469       hist->Draw();
15470     }
15471     
15472     func = new TF1("func", &FitFunctionGauss, -end, end, 3);
15473     func->FixParameter(0, 0);
15474     func->FixParameter(1, 0);
15475     func->SetParLimits(2, 0, 2);
15476     func->SetParameters(1, 0, 0.5);
15477     
15478 //     hist->Fit("gaus", (silent) ? "0" : "", "", -end+0.01, end-0.01);
15479     gIntegral = hist->Integral(hist->FindBin(-1.79), hist->FindBin(1.79), "width");
15480     hist->Fit(func, (silent) ? "0" : "", "", -end+0.01, end-0.01);
15481     Float_t first = ((TF1*) hist->GetListOfFunctions()->First())->GetParameter(2);
15482     hist->GetYaxis()->SetRangeUser(-0.2, 1.05);
15483     
15484     Float_t offset = hist->Integral(hist->FindBin(begin+0.01), hist->FindBin(end-0.01)) / (hist->FindBin(end-0.01) - hist->FindBin(begin+0.01) + 1);
15485     Printf("%f", offset);
15486     
15487     TF1* constant = new TF1("constant", "1", -5, 5);
15488     clone->Add(constant, -offset);
15489     clone->SetLineColor(2);
15490     if (!silent)
15491       clone->Draw("same");
15492 //     clone->Fit("gaus", (silent) ? "0" : "", "SAME", -end+0.01, end-0.01);
15493     gIntegral = clone->Integral(clone->FindBin(-1.79), clone->FindBin(1.79), "width");
15494     clone->Fit(func, (silent) ? "0" : "", "SAME", -end+0.01, end-0.01);
15495     Float_t second = ((TF1*) clone->GetListOfFunctions()->First())->GetParameter(2);
15496
15497     Printf("%f %f", first, second);
15498     graph->SetPoint(graph->GetN(), second, first);
15499     graph2->SetPoint(graph2->GetN(), second, first / second);
15500     
15501     if (!silent)
15502       return;
15503   }
15504   
15505   new TCanvas;
15506   graph->Draw("A*");
15507
15508   new TCanvas;
15509   graph2->Draw("A*");
15510 //   Printf("%f %f", hist->GetRMS(), clone->GetRMS());
15511   
15512   graph2->Write(Form("corr_%.1f_%.1f", begin, end));
15513 }
15514
15515 void correction_gauss()
15516 {
15517   new TCanvas;
15518   
15519   TFile::Open("sigma_correction.root", "RECREATE");
15520   
15521   gauss_one(1.4, 1.8);
15522   gauss_one(1.2, 1.8);
15523   gauss_one(0.5, 1.0);
15524   
15525   gFile->Close();
15526 }