]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGCF/Correlations/macros/dphicorrelations/correct.C
centrality weighting
[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
19 void SetRanges(TAxis* axis)
20 {
21   if (strcmp(axis->GetTitle(), "leading p_{T} (GeV/c)") == 0)
22     axis->SetRangeUser(0, (gEnergy == 900) ? 10 : 25);
23
24   if (strcmp(axis->GetTitle(), "multiplicity") == 0)
25     axis->SetRangeUser(0, 10);
26 }
27
28 void SetRanges(TH1* hist)
29 {
30   SetRanges(hist->GetXaxis());
31   SetRanges(hist->GetYaxis());
32   SetRanges(hist->GetZaxis());
33 }
34
35 void Prepare1DPlot(TH1* hist)
36 {
37   if (!hist)
38     return;
39
40   hist->SetLineWidth(2);
41   hist->SetStats(kFALSE);
42
43   hist->GetXaxis()->SetLabelOffset(0.02);
44   hist->GetXaxis()->SetTitleOffset(1.3);
45   hist->GetYaxis()->SetTitleOffset(1.3);
46
47   SetRanges(hist);
48 }
49
50 TH1* GetSystematicUncertainty(TH1* corr, TH1* trackHist)
51 {
52   if (!trackHist)
53   {
54     systError = (TH1*) corr->Clone("systError");
55     systError->Reset();
56   }
57   else  // for dphi evaluation
58     systError = new TH1F("systError", "", 100, 0, 50);
59   
60   Float_t constantUnc = 0;
61   
62   // particle composition
63   constantUnc += 0.8 ** 2;
64   
65   // tpc efficiency
66   if (gEnergy == 900 && gpTMin < 1.0)
67     constantUnc += 1.0 ** 2;
68   else if (gEnergy == 900 && gpTMin < 1.5)
69     constantUnc += 0.5 ** 2;
70   if (gEnergy == 7000 && gpTMin < 1.0)
71     constantUnc += 1.0 ** 2;
72   else if (gEnergy == 7000 && gpTMin < 1.5)
73     constantUnc += 0.6 ** 2;
74   
75   // track cuts
76   if (gEnergy == 900 && gpTMin < 1.0)
77     constantUnc += 2.5 ** 2;
78   else if (gEnergy == 900 && gpTMin < 1.5)
79     constantUnc += 2.0 ** 2;
80   if (gEnergy == 7000)
81     constantUnc += 3.0 ** 2;
82
83   // difference corrected with pythia and phojet
84   if (gEnergy == 900 && gpTMin < 1.0)
85     constantUnc += 0.6 ** 2;
86   else if (gEnergy == 900 && gpTMin < 1.5)
87     constantUnc += 0.8 ** 2;
88   
89   if (gEnergy == 7000 && gpTMin < 1.0)
90   {
91     if (gUEHist == 0)
92       constantUnc += 0.6 ** 2;
93     if (gUEHist == 1)
94       constantUnc += 0.8 ** 2;
95     if (gUEHist == 2)
96       constantUnc += 1.0 ** 2;
97   }
98   else if (gEnergy == 7000 && gpTMin < 1.5)
99     constantUnc += 1.0 ** 2;
100     
101   for (Int_t bin=1; bin<=systError->GetNbinsX(); bin++)
102     systError->SetBinContent(bin, constantUnc);
103
104   // mis id bias
105   if (gUEHist == 0 || gUEHist == 2)
106     systError->Fill(0.75, 4.0 ** 2);
107   if (gUEHist == 1)
108     systError->Fill(0.75, 5.0 ** 2);
109
110   if (gEnergy == 900)
111   {
112     if (gpTMin < 1.0)
113       systError->Fill(1.25, 1.0 ** 2);
114     else if (gpTMin < 1.5)
115       systError->Fill(1.25, 2.0 ** 2);
116   }
117   
118   // non-closure in MC
119   if (gEnergy == 900)
120     for (Int_t bin=1; bin<=systError->GetNbinsX(); bin++)
121       systError->Fill(systError->GetXaxis()->GetBinCenter(bin), 1.0 ** 2);
122       
123   if (gEnergy == 7000)
124   {
125     if (gUEHist == 0 && gUEHist == 1)
126       systError->Fill(0.75, 2.0 ** 2);
127     if (gUEHist == 2)
128       systError->Fill(0.75, 1.2 ** 2);
129   }
130   
131   // vertex efficiency
132   systError->Fill(0.75, 1.0 ** 2);
133
134   // strangeness
135   for (Int_t bin=1; bin<=systError->GetNbinsX(); bin++)
136   {
137     if (gEnergy == 900)
138       systError->Fill(systError->GetXaxis()->GetBinCenter(bin), 0.5 ** 2);
139     if (gEnergy == 7000 && systError->GetXaxis()->GetBinCenter(bin) < 1.5)
140       systError->Fill(systError->GetXaxis()->GetBinCenter(bin), 2.0 ** 2);
141     else if (gEnergy == 7000)
142       systError->Fill(systError->GetXaxis()->GetBinCenter(bin), 1.0 ** 2);
143   }  
144     
145   for (Int_t bin=1; bin<=systError->GetNbinsX(); bin++)
146     systError->SetBinContent(bin, TMath::Sqrt(systError->GetBinContent(bin)));
147   
148   if (trackHist)
149   {
150     //new TCanvas; trackHist->Draw();
151     //new TCanvas; systError->DrawCopy("");
152     
153     Float_t uncFlat = 0;
154     for (Int_t i=1; i<=trackHist->GetNbinsX(); i++)
155       uncFlat += trackHist->GetBinContent(i) * systError->GetBinContent(systError->FindBin(trackHist->GetBinCenter(i)));
156     if (trackHist->Integral() > 0)
157       uncFlat /= trackHist->Integral();
158     
159     systError = (TH1F*) corr->Clone("systError");
160     systError->Reset();
161   
162     for (Int_t i=1; i<=systError->GetNbinsX(); i++)
163       systError->SetBinContent(i, uncFlat);
164       
165     //new TCanvas; systError->DrawCopy("");
166   }
167   
168   systError->SetFillColor(kGray);
169   systError->SetFillStyle(1001);
170   systError->SetMarkerStyle(0);
171   systError->SetLineColor(0);
172   
173   return systError;
174 }
175
176 void DrawRatio(TH1* corr, TH1* mc, const char* name, TH1* syst = 0)
177 {
178   mc->SetLineColor(2);
179
180   TCanvas* canvas3 = new TCanvas(name, name, 600, 600);
181   canvas3->Range(0, 0, 1, 1);
182
183   TPad* pad1 = new TPad(Form("%s_1", name), "", 0, 0.5, 0.98, 0.98);
184   pad1->Draw();
185
186   TPad* pad2 = new TPad(Form("%s_2", name), "", 0, 0.02, 0.98, 0.5);
187   pad2->Draw();
188
189   pad1->SetRightMargin(0.01);
190   pad2->SetRightMargin(0.01);
191   pad1->SetTopMargin(0.05);
192   pad1->SetLeftMargin(0.13);
193   pad2->SetLeftMargin(0.13);
194   pad2->SetBottomMargin(0.22);
195   
196   // no border between them
197   pad1->SetBottomMargin(0);
198   pad2->SetTopMargin(0);
199
200   pad1->cd();
201   pad1->SetGridx();
202   pad1->SetGridy();
203
204   if (gUEHist != 2)
205     TLegend* legend = new TLegend(0.15, 0.65, 0.55, 0.90);
206   else
207     TLegend* legend = new TLegend(0.55, 0.65, 0.95, 0.90);
208
209   legend->SetFillColor(0);
210   legend->AddEntry(corr, "Corrected");
211   legend->AddEntry(mc, "MC prediction");
212   legend->SetTextSize(0.08);
213
214   Prepare1DPlot(corr);
215
216   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);
217   dummy->SetYTitle(corr->GetYaxis()->GetTitle());
218   
219   //dummy = new TH2F("dummy", "", 100, corr->GetXaxis()->GetBinLowEdge(1), corr->GetXaxis()->GetBinUpEdge(corr->GetNbinsX()), 1000, 13.5, 20.5);
220   //dummy->SetYTitle("1/N_{trig} dN/d#Delta#phi");
221   
222   dummy->SetStats(kFALSE);
223   dummy->SetXTitle(corr->GetXaxis()->GetTitle());
224   dummy->GetYaxis()->SetTitleOffset(1);
225   Prepare1DPlot(dummy);
226
227   dummy->GetXaxis()->SetLabelSize(0.08);
228   dummy->GetYaxis()->SetLabelSize(0.08);
229   dummy->GetXaxis()->SetTitleSize(0.08);
230   dummy->GetYaxis()->SetTitleSize(0.08);
231   dummy->GetYaxis()->SetTitleOffset(0.8);
232   
233   if (gForceRange > 0)
234     dummy->GetYaxis()->SetRangeUser(0, gForceRange);
235   
236   dummy->DrawCopy();
237   
238   if (0 && gUEHist != 2)
239   {
240     const char* regionStr[] = { "Toward Region", "Away Region", "Transverse Region" };
241     latex = new TLatex(0.65, 0.1, regionStr[gRegion]);
242     latex->SetTextSize(0.075);
243     latex->SetNDC();
244     latex->Draw();
245   }
246   
247   if (syst)
248   {
249     systError = (TH1*) syst->Clone("corrSystError");
250     for (Int_t bin=1; bin<=systError->GetNbinsX(); bin++)
251     {
252       systError->SetBinError(bin, corr->GetBinContent(bin) * syst->GetBinContent(bin) / 100);
253       systError->SetBinContent(bin, corr->GetBinContent(bin));
254     }
255     
256     systError->Draw("E2 ][ SAME");
257   }
258   
259   corr->Draw("SAME");
260   mc->Draw("SAME");
261   
262   if (strlen(gText) > 0)
263   {
264     latex = new TLatex(0.2, 0.2, gText);
265     latex->SetNDC();
266     latex->SetTextSize(0.06);
267     latex->Draw();
268   }
269
270   //legend->Draw();
271
272   pad2->cd();
273   //pad2->SetBottomMargin(0.15);
274   //pad2->SetGridx();
275   //pad2->SetGridy();
276
277   TH1* ratio = (TH1*) mc->Clone("ratio");
278   ratio->Divide(corr);
279
280   Float_t minR = TMath::Min(0.91, ratio->GetMinimum() * 0.95);
281   Float_t maxR = TMath::Max(1.09, ratio->GetMaximum() * 1.05);
282   
283   minR = 0.8;
284   maxR = 1.2;
285
286   TH1F dummy3("dummy3", ";;Ratio: MC / corr", 100, corr->GetXaxis()->GetBinLowEdge(1), corr->GetXaxis()->GetBinUpEdge(corr->GetNbinsX()));
287   dummy3.SetXTitle(corr->GetXaxis()->GetTitle());
288   Prepare1DPlot(&dummy3);
289   dummy3.SetStats(kFALSE);
290   for (Int_t i=1; i<=100; ++i)
291         dummy3.SetBinContent(i, 1);
292   dummy3.GetYaxis()->SetRangeUser(minR, maxR);
293   dummy3.SetLineWidth(2);
294   dummy3.GetXaxis()->SetLabelSize(0.08);
295   dummy3.GetYaxis()->SetLabelSize(0.08);
296   dummy3.GetXaxis()->SetTitleSize(0.08);
297   dummy3.GetYaxis()->SetTitleSize(0.08);
298   dummy3.GetYaxis()->SetTitleOffset(0.8);
299   dummy3.DrawCopy();
300   
301   if (syst)
302   {
303     // for the ratio add in quadrature
304     for (Int_t bin=1; bin<=syst->GetNbinsX(); bin++)
305     {
306       if (corr->GetBinError(bin) > 0)
307         syst->SetBinError(bin, TMath::Sqrt(TMath::Power(syst->GetBinContent(bin) / 100, 2) + TMath::Power(corr->GetBinError(bin) / corr->GetBinContent(bin), 2)));
308       else
309         syst->SetBinError(bin, 0);
310       syst->SetBinContent(bin, 1);
311     }
312     
313     syst->Draw("E2 ][ SAME");
314     dummy3.DrawCopy("SAME");
315   }
316
317   ratio->Draw("SAME");
318   
319   ratio->Fit("pol0", "N");
320
321   canvas3->Modified();
322   //canvas3->SaveAs(Form("%s.eps", canvas3->GetTitle()));
323 }
324
325 void loadlibs()
326 {
327   gSystem->Load("libANALYSIS");
328   gSystem->Load("libANALYSISalice");
329   gSystem->Load("libCORRFW");
330   gSystem->Load("libPWGTools");
331   gSystem->Load("libPWGCFCorrelationsBase");
332 }
333
334 const char* lastFileName = 0;
335 void* cacheSameEvent = 0;
336 void* cacheMixedEvent = 0;
337
338 void* GetUEHistogram(const char* fileName, TList** listRef = 0, Bool_t mixed = kFALSE, const char* tag = "")
339 {
340   if (!lastFileName || strcmp(lastFileName, fileName) != 0)
341   {
342     lastFileName = fileName;
343     file = TFile::Open(fileName);
344     if (!file)
345       return 0;
346     
347     list = (TList*) gFile->Get("PWG4_LeadingTrackUE/histosLeadingTrackUE");
348     if (!list)
349       list = (TList*) gFile->Get(Form("PWG4_PhiCorrelations/histosPhiCorrelations%s", tag));
350     if (!list)
351       list = (TList*) gFile->Get("PWG4_PhiCorrelations/histosPhiCorrelations_Syst");
352       
353     if (!list)
354       return 0;
355       
356     if (listRef)
357       *listRef = list;
358       
359     cacheMixedEvent = list->FindObject("AliUEHistogramsMixed");
360     cacheSameEvent = list->FindObject("AliUEHistogramsSame");
361
362     if (mixed)
363       return cacheMixedEvent;
364     
365     if (list->FindObject("AliUEHistograms"))
366       return list->FindObject("AliUEHistograms");
367       
368     return cacheSameEvent;
369   }
370   else
371   {
372     Printf("GetUEHistogram --> Using cache for %s", fileName);
373     
374     if (mixed)
375       return cacheMixedEvent;
376     else
377       return cacheSameEvent;
378   }
379 }
380
381 void CompareBias(const char* mcFile = "PWG4_JetTasksOutput.root", Int_t region, Int_t ueHist)
382 {
383   loadlibs();
384
385   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(mcFile);
386   SetupRanges(h);
387   
388   const char* axis = "z";
389   Float_t ptLeadMin = 0;
390   Float_t ptLeadMax = -1;
391   
392   if (ueHist == 2)
393   {
394     ptLeadMin = 0.51 + 0;
395     ptLeadMax = 1.99 + 0;
396     axis = "y";
397   }
398   
399   biasFromData = (TH1*) h->GetUEHist(ueHist)->GetBias(AliUEHist::kCFStepBiasStudy, AliUEHist::kCFStepReconstructed, region, axis, ptLeadMin, ptLeadMax)->Clone("biasFromData");
400   biasFromData2 = (TH1*) h->GetUEHist(ueHist)->GetBias(AliUEHist::kCFStepBiasStudy2, AliUEHist::kCFStepReconstructed, region, axis, ptLeadMin, ptLeadMax)->Clone("biasFromData2");
401   //biasFromData = (TH1*) h->GetUEHist(ueHist)->GetBias(AliUEHist::kCFStepReconstructed, AliUEHist::kCFStepRealLeading, region, axis)->Clone("biasFromData");
402   biasFromMC   = (TH1*) h->GetUEHist(ueHist)->GetBias(AliUEHist::kCFStepReconstructed, AliUEHist::kCFStepTracked, region, axis, ptLeadMin, ptLeadMax)->Clone("biasFromMC");
403   //biasFromMC   = (TH1*) h->GetUEHist(ueHist)->GetBias(AliUEHist::kCFStepReconstructed, AliUEHist::kCFStepRealLeading, region, axis)->Clone("biasFromMC");
404   
405 /*  biasFromData->Draw();
406   biasFromMC->SetLineColor(2);
407   biasFromMC->Draw("SAME");
408   return;*/
409   
410   DrawRatio(biasFromData, biasFromMC, "bias: data vs MC");
411   DrawRatio(biasFromData, biasFromData2, "bias: data vs data two step");
412 }
413   
414 void CompareBiasWithData(const char* mcFile = "PWG4_JetTasksOutput.root", const char* dataFile = "esd.root", Int_t region = 2)
415 {
416   loadlibs();
417
418   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(mcFile);
419   SetupRanges(h);
420   
421   biasFromMC   = (TH1*) h->GetNumberDensitypT()->GetBias(AliUEHist::kCFStepReconstructed, AliUEHist::kCFStepTracked, region, "z")->Clone("biasFromMC");
422   
423   AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(dataFile);
424   SetupRanges(h2);
425   
426   biasFromData = (TH1*) h2->GetNumberDensitypT()->GetBias(AliUEHist::kCFStepBiasStudy, AliUEHist::kCFStepReconstructed, region, "z")->Clone("biasFromData");
427   biasFromData2 = (TH1*) h2->GetNumberDensitypT()->GetBias(AliUEHist::kCFStepBiasStudy2, AliUEHist::kCFStepReconstructed, region, "z")->Clone("biasFromData2");
428   
429   DrawRatio(biasFromData, biasFromMC, "bias: data vs MC");
430   DrawRatio(biasFromData, biasFromData2, "bias: data vs data two step");
431 }
432
433 Int_t count = 0;
434
435 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)
436 {
437   loadlibs();
438   
439   if (!gCache || !gFirst)
440   {
441     AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName1);
442     AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(fileName2);
443   }
444   
445   if (gCache)
446   {
447     if (!gFirst)
448     {
449       gFirst = h;
450       gSecond = h2;
451     }
452     else
453     {
454       AliUEHistograms* h = (AliUEHistograms*) gFirst;
455       AliUEHistograms* h2 = (AliUEHistograms*) gSecond;
456     }
457   }
458   
459   SetupRanges(h);
460   SetupRanges(h2);
461   
462   TH1* hist1 = h->GetUEHist(id)->GetUEHist(step1, region, ptLeadMin, ptLeadMax, centralityBegin, centralityEnd);
463   //TH1* hist1 = h->GetUEHist(id)->GetUEHist(step1, region, ptLeadMin, ptLeadMax);
464   TH1* hist2 = h2->GetUEHist(id)->GetUEHist(step2, region, ptLeadMin, ptLeadMax, centralityBegin, centralityEnd);
465
466   //hist1->Scale(1.0 / hist1->Integral());
467   //hist2->Scale(1.0 / hist2->Integral());
468
469   TH1* trackHist = 0;
470   if (id == 2)
471   {
472     trackHist = h->GetUEHist(id)->GetTrackHist(region)->ShowProjection(2, 0);
473     // only keep bins under consideration
474     for (Int_t bin=1; bin<=trackHist->GetNbinsX(); bin++)
475       if (bin < trackHist->FindBin(ptLeadMin) || bin > trackHist->FindBin(ptLeadMax))
476         trackHist->SetBinContent(bin, 0);
477   }
478
479   // systematic uncertainty
480   TH1* syst = 0; //GetSystematicUncertainty(hist1, trackHist);
481   
482   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);
483 }  
484
485 void CompareEventHist(const char* fileName1, const char* fileName2, Int_t id, Int_t step, Int_t var)
486 {
487   loadlibs();
488
489   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName1);
490   SetupRanges(h);
491
492   AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(fileName2);
493   SetupRanges(h2);
494
495   TH1* hist1 = h->GetUEHist(id)->GetEventHist()->ShowProjection(var, step);
496   TH1* hist2 = h2->GetUEHist(id)->GetEventHist()->ShowProjection(var, step);
497   
498 //   hist1 = hist1->Rebin(hist2->GetNbinsX(), "new", hist2->GetXaxis()->GetXbins()->GetArray());
499   
500 //   hist2 = hist2->Rebin(hist1->GetNbinsX(), "new", hist1->GetXaxis()->GetXbins()->GetArray());
501  
502   DrawRatio(hist1, hist2, "compare");
503 }
504
505 void CompareEventHist(const char* fileName1, const char* fileName2, Int_t id, Int_t step1, Int_t step2, Int_t var)
506 {
507   loadlibs();
508
509   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName1);
510   SetupRanges(h);
511
512   AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(fileName2);
513   SetupRanges(h2);
514   
515 //   h->GetUEHist(id)->GetEventHist()->GetGrid(step1)->GetGrid()->GetAxis(1)->SetRange(1, 5);
516 //   h2->GetUEHist(id)->GetEventHist()->GetGrid(step2)->GetGrid()->GetAxis(1)->SetRange(1, 5);
517   
518   TH1* hist1 = h->GetUEHist(id)->GetEventHist()->ShowProjection(var, step1);
519   TH1* hist2 = h2->GetUEHist(id)->GetEventHist()->ShowProjection(var, step2);
520  
521   DrawRatio(hist1, hist2, "compare");
522 }
523
524 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)
525 {
526   // fileName1 is labelled Corrected in the plot
527
528   loadlibs();
529
530   gUEHist = id;
531   gRegion = region;
532   Compare(fileName1, fileName2, id, step, step, region, ptLeadMin, ptLeadMax);
533 }
534
535 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)
536 {
537   // fileName1 is labelled Corrected in the plot
538
539   loadlibs();
540
541   gUEHist = id;
542   gRegion = region;
543   Compare(fileName1, fileName2, id, step1, step2, region, ptLeadMin, ptLeadMax, centralityBegin, centralityEnd);
544 }
545
546 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)
547 {
548   loadlibs();
549
550   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName, 0, mixed);
551   SetupRanges(h);
552
553   new TCanvas;
554   return h->GetUEHist(id)->GetUEHist(step, region, ptLeadMin, ptLeadMax, centralityBegin, centralityEnd, twoD)->DrawCopy();
555 }
556
557 void DrawProjectionsRidge(const char* fileName, const char* fileNamePbPbMix = 0)
558 {
559   if (!fileNamePbPbMix)
560     fileNamePbPbMix = fileName;
561   
562   gpTMin = 1.01;
563   gpTMax = 2.99;
564   
565   loadlibs();
566   
567   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
568   hMixed = (AliUEHistograms*) GetUEHistogram(fileNamePbPbMix, 0, kTRUE);
569   
570   SetupRanges(h);
571   SetupRanges(hMixed);
572
573   TH1* hist1 = 0;
574   GetDistAndFlow(h, hMixed, &hist1,  0, 8, 0,  100, 3.01, 3.99, 1, kTRUE, 0, kTRUE); 
575   
576 //   ((TH2*) hist1)->Rebin2D(2, 2); hist1->Scale(0.25);
577
578 //   NormalizeToBinWidth(hist1);
579   
580   proj1y = ((TH2*) hist1)->ProjectionY("proj1y", hist1->GetXaxis()->FindBin(-0.5), hist1->GetXaxis()->FindBin(0.5));
581   proj1x = ((TH2*) hist1)->ProjectionX("proj1x", hist1->GetYaxis()->FindBin(-1.79), hist1->GetYaxis()->FindBin(1.79));
582   
583   proj1y->Scale(1.0 / (hist1->GetXaxis()->FindBin(0.5) - hist1->GetXaxis()->FindBin(-0.5) + 1));
584   proj1x->Scale(1.0 / (hist1->GetYaxis()->FindBin(1.79) - hist1->GetYaxis()->FindBin(-1.79) + 1));
585   
586   proj1y->GetXaxis()->SetTitleOffset(1);
587   proj1x->GetXaxis()->SetTitleOffset(1);
588   
589   Float_t zyam = proj1x->GetBinContent(proj1x->GetXaxis()->FindBin(TMath::Pi()/2));
590   proj1x->Add(new TF1("func", "-1", -100, 100), zyam);
591   proj1y->Add(new TF1("func", "-1", -100, 100), zyam);
592   
593   new TCanvas("c", "c", 800, 800);
594   gPad->SetLeftMargin(0.15);
595   hist1->SetTitle("");
596   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
597   hist1->GetXaxis()->SetTitleOffset(1.5);
598   hist1->GetYaxis()->SetTitleOffset(2);
599   hist1->SetStats(kFALSE);
600   hist1->DrawCopy("SURF1");
601   
602 //   new TCanvas; proj1y->Draw(); new TCanvas; proj1x->Draw();  return;
603   
604   TH1* hist2 = 0;
605   GetDistAndFlow(h, hMixed, &hist2,  0, 8, 40,  100, 4.01, 5.99, 1, kTRUE, 0, kTRUE); 
606   
607 //   ((TH2*) hist2)->Rebin2D(2, 2); hist2->Scale(0.25);
608 //   NormalizeToBinWidth(hist2);
609   
610   proj2y = ((TH2*) hist2)->ProjectionY("proj2y", hist1->GetXaxis()->FindBin(-0.5), hist1->GetXaxis()->FindBin(0.5));
611   proj2x = ((TH2*) hist2)->ProjectionX("proj2x", hist1->GetYaxis()->FindBin(-1.79), hist1->GetYaxis()->FindBin(1.79));
612
613   proj2y->Scale(1.0 / (hist1->GetXaxis()->FindBin(0.5) - hist1->GetXaxis()->FindBin(-0.5) + 1));
614   proj2x->Scale(1.0 / (hist1->GetYaxis()->FindBin(1.79) - hist1->GetYaxis()->FindBin(-1.79) + 1));
615  
616   zyam = proj2x->GetBinContent(proj2x->GetXaxis()->FindBin(TMath::Pi()/2));
617   proj2x->Add(new TF1("func", "-1", -100, 100), zyam);
618   proj2y->Add(new TF1("func", "-1", -100, 100), zyam);
619
620   proj2y->SetLineColor(2); proj2x->SetLineColor(2);
621   
622   new TCanvas; proj1y->Draw(); proj2y->Draw("SAME");
623   new TCanvas; proj1x->Draw(); proj2x->Draw("SAME");
624   
625   new TCanvas("c2", "c2", 800, 800);
626   gPad->SetLeftMargin(0.15);
627   hist2->SetTitle("");
628   hist2->GetYaxis()->SetRangeUser(-1.79, 1.79);
629   hist2->GetXaxis()->SetTitleOffset(1.5);
630   hist2->GetYaxis()->SetTitleOffset(2);
631   hist2->SetStats(kFALSE);
632   hist2->DrawCopy("SURF1");
633 }
634
635 void DrawExample(const char* fileName, const char* fileNamePbPbMix = 0)
636 {
637   if (!fileNamePbPbMix)
638     fileNamePbPbMix = fileName;
639   
640   gpTMin = 1.01;
641   gpTMax = 1.99;
642   
643   loadlibs();
644   
645   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
646   hMixed = (AliUEHistograms*) GetUEHistogram(fileNamePbPbMix, 0, kTRUE);
647   
648   SetupRanges(h);
649   SetupRanges(hMixed);
650
651   TH1* hist1 = 0;
652   GetDistAndFlow(h, hMixed, &hist1,  0, 8, 0,  40, 1.01, 1.99, 1, kTRUE, 0, kTRUE); 
653   
654   ((TH2*) hist1)->Rebin2D(2, 2);
655   hist1->Scale(0.25);
656
657 //   NormalizeToBinWidth(hist1);
658   
659   new TCanvas("c", "c", 800, 800);
660   gPad->SetLeftMargin(0.15);
661   hist1->SetTitle("");
662   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
663   hist1->GetXaxis()->SetTitleOffset(1.5);
664   hist1->GetYaxis()->SetTitleOffset(2);
665   hist1->SetStats(kFALSE);
666   hist1->DrawCopy("SURF1");
667   
668   TH1* hist2 = 0;
669   GetDistAndFlow(h, hMixed, &hist2,  0, 8, 40,  100, 1.01, 1.99, 1, kTRUE, 0, kTRUE); 
670   
671   ((TH2*) hist2)->Rebin2D(2, 2); hist2->Scale(0.25);
672
673 //   NormalizeToBinWidth(hist1);
674   
675   new TCanvas("c2", "c2", 800, 800);
676   gPad->SetLeftMargin(0.15);
677   hist2->SetTitle("");
678   hist2->GetYaxis()->SetRangeUser(-1.79, 1.79);
679   hist2->GetXaxis()->SetTitleOffset(1.5);
680   hist2->GetYaxis()->SetTitleOffset(2);
681   hist2->SetStats(kFALSE);
682   hist2->DrawCopy("SURF1");
683   
684   
685
686   return;
687   
688   hist2 = hist1;
689   /*
690   GetDistAndFlow(h, hMixed, &hist1,  0, 0, 0,  10, 2.01, 3.99, 1, kTRUE, 0, kTRUE); 
691
692   ((TH2*) hist1)->Rebin2D(2, 2);
693 //   NormalizeToBinWidth(hist1);
694
695   new TCanvas("c2", "c2", 800, 800);
696   gPad->SetLeftMargin(0.15);
697   hist1->SetTitle("");
698   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
699   hist1->GetXaxis()->SetTitleOffset(1.5);
700   hist1->GetYaxis()->SetTitleOffset(2);
701   hist1->SetStats(kFALSE);
702   hist1->DrawCopy("SURF1");  
703   
704   hist1->Divide(hist2);
705
706   new TCanvas("c5", "c5", 800, 800);
707   gPad->SetLeftMargin(0.15);
708   hist1->SetTitle("");
709   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
710   hist1->GetXaxis()->SetTitleOffset(1.5);
711   hist1->GetYaxis()->SetTitleOffset(2);
712   hist1->SetStats(kFALSE);
713   hist1->DrawCopy("SURF1");    
714   
715   return;
716
717   GetDistAndFlow(h, hMixed, &hist1,  0, 6, 0,  10, 2.01, 3.99, 1, kTRUE, 0, kTRUE, 6); 
718
719   ((TH2*) hist1)->Rebin2D(2, 2);
720 //   NormalizeToBinWidth(hist1);
721
722   new TCanvas("c3", "c3", 800, 800);
723   gPad->SetLeftMargin(0.15);
724   hist1->SetTitle("");
725   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
726   hist1->GetXaxis()->SetTitleOffset(1.5);
727   hist1->GetYaxis()->SetTitleOffset(2);
728   hist1->SetStats(kFALSE);
729   hist1->DrawCopy("SURF1");  
730   
731 //   return;
732   
733 //   TH1* hist1 = 0;
734 //   GetDistAndFlow(h, hMixed, &hist1,  0, 4, 0,  10, 2.01, 3.99, 1, kTRUE, 0, kTRUE, 6); 
735 //   
736 //   ((TH2*) hist1)->Rebin2D(2, 2);
737 // //   hist1->Scale(0.25);
738 // 
739 // //   NormalizeToBinWidth(hist1);
740 //   
741 //   new TCanvas("c1b", "c1b", 800, 800);
742 //   gPad->SetLeftMargin(0.15);
743 //   hist1->SetTitle("");
744 //   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
745 //   hist1->GetXaxis()->SetTitleOffset(1.5);
746 //   hist1->GetYaxis()->SetTitleOffset(2);
747 //   hist1->SetStats(kFALSE);
748 //   hist1->DrawCopy("SURF1");
749 //   hist2 = hist1;
750   
751 //   return;
752   
753 //   GetDistAndFlow(h, 0, &hist1,  0, 8, 0,  10, 2.01, 3.99, 1, kTRUE, 0, kTRUE); 
754 // 
755 //   NormalizeToBinWidth(hist1);
756 // //   
757 //   for (Int_t i=1; i<=hist1->GetNbinsX(); ++i)
758 //   {
759 //     for (Int_t j=1; j<=hist1->GetNbinsY(); ++j)
760 //     {
761 //       Float_t factor = 1.0 / (2.0 - TMath::Abs(hist1->GetYaxis()->GetBinCenter(j)));
762 //       hist1->SetBinContent(i, j, hist1->GetBinContent(i, j) * factor);
763 //       hist1->SetBinError(i, j, hist1->GetBinError(i, j) * factor);
764 //     }
765 //   }
766
767 /*  new TCanvas("c4", "c4", 800, 800);
768   gPad->SetLeftMargin(0.15);
769   hist1->SetTitle("");
770   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
771   hist1->GetXaxis()->SetTitleOffset(1.5);
772   hist1->GetYaxis()->SetTitleOffset(2);
773   hist1->SetStats(kFALSE);
774   hist1->DrawCopy("SURF1");  */
775   
776   AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram("corrected.root");
777   AliUEHistograms* h2Mixed = (AliUEHistograms*) GetUEHistogram("corrected.root", 0, kTRUE);
778   SetupRanges(h2);
779   SetupRanges(h2Mixed);
780  
781   GetDistAndFlow(h2, h2Mixed, &hist1,  0, 8, 0,  10, 2.01, 3.99, 1, kTRUE, 0, kTRUE); 
782   ((TH2*) hist1)->Rebin2D(2, 2);
783
784   new TCanvas("c4", "c4", 800, 800);
785   gPad->SetLeftMargin(0.15);
786   hist1->SetTitle("");
787   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
788   hist1->GetXaxis()->SetTitleOffset(1.5);
789   hist1->GetYaxis()->SetTitleOffset(2);
790   hist1->SetStats(kFALSE);
791   hist1->DrawCopy("SURF1");  
792   
793   hist1->Divide(hist2);
794
795   new TCanvas("c5", "c5", 800, 800);
796   gPad->SetLeftMargin(0.15);
797   hist1->SetTitle("");
798   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
799   hist1->GetXaxis()->SetTitleOffset(1.5);
800   hist1->GetYaxis()->SetTitleOffset(2);
801   hist1->SetStats(kFALSE);
802   hist1->DrawCopy("SURF1");  
803
804 //   hist1->Divide(histMixed);
805   
806 //   NormalizeToBinWidth(hist1);
807 // //   
808 //   for (Int_t i=1; i<=hist1->GetNbinsX(); ++i)
809 //   {
810 //     for (Int_t j=1; j<=hist1->GetNbinsY(); ++j)
811 //     {
812 //       Float_t factor = 1.0 / (2.0 - TMath::Abs(hist1->GetYaxis()->GetBinCenter(j)));
813 //       hist1->SetBinContent(i, j, hist1->GetBinContent(i, j) * factor);
814 //       hist1->SetBinError(i, j
815 //   }, hist1->GetBinError(i, j) * factor);
816 //     }
817
818 //   new TCanvas("c6", "c6", 800, 800);
819 //   gPad->SetLeftMargin(0.15);
820 //   hist1->SetTitle("");
821 //   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
822 //   hist1->GetXaxis()->SetTitleOffset(1.5);
823 //   hist1->GetYaxis()->SetTitleOffset(2);
824 //   hist1->SetStats(kFALSE);
825 //   hist1->DrawCopy("SURF1");  
826   
827   return;
828   
829   GetSumOfRatios(h, hMixed, &hist1,  6, 60,  90, 8.01, 9.99, kTRUE); 
830   new TCanvas("c2", "c2", 800, 800);
831   gPad->SetLeftMargin(0.15);
832   hist1->SetTitle("");
833   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
834   hist1->GetXaxis()->SetTitleOffset(1.5);
835   hist1->GetYaxis()->SetTitleOffset(2);
836   hist1->SetStats(kFALSE);
837   hist1->Draw("SURF1");
838
839   return;
840   
841   latex = new TLatex(0.82, 0.74, "ALICE performance");
842   latex->SetTextSize(0.02);
843   latex->SetTextAlign(22);
844   latex->SetNDC();
845   latex->Draw();
846   latex = new TLatex(0.82, 0.72, "Pb-Pb 2.76 TeV");
847   latex->SetTextSize(0.02);
848   latex->SetTextAlign(22);
849   latex->SetNDC();
850   latex->Draw();
851   latex = new TLatex(0.82, 0.70, "28.09.11");
852   latex->SetTextSize(0.02);
853   latex->SetTextAlign(22);
854   latex->SetNDC();
855   latex->Draw();
856
857   DrawALICELogo(0.75, 0.75, 0.9, 0.9);
858 }
859
860 void DrawExample2(const char* fileName)
861 {
862   loadlibs();
863   
864   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
865   hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
866   
867   gpTMin = 0.51;
868   gpTMax = 0.99;
869   SetupRanges(h);
870   SetupRanges(hMixed);
871
872   TH1* hist1 = 0;
873   GetSumOfRatios(h, hMixed, &hist1,  8, 0,  5, 0.51, 0.99);
874   
875   new TCanvas("c", "c", 800, 800);
876   gPad->SetLeftMargin(0.15);
877   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
878   hist1->GetXaxis()->SetTitleOffset(1.5);
879   hist1->GetYaxis()->SetTitleOffset(2);
880   hist1->SetStats(kFALSE);
881   hist1->DrawCopy("SURF1"); 
882 }  
883
884 void CompareZVtxWeighting(const char* fileName, Int_t step = 8)
885 {
886   gpTMin = 1.01;
887   gpTMax = 1.99;
888   
889   loadlibs();
890   
891   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
892   hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
893   
894   SetupRanges(h);
895   SetupRanges(hMixed);
896   
897   TH1* hist1 = 0;
898   GetDistAndFlow(h, hMixed, &hist1,  0, step, 0,  10, 5.01, 9.99, 1, kTRUE, 0, kTRUE); 
899   hist1->Scale(1.0 / 0.972222);
900   
901   TH1* hist2 = 0;
902   GetSumOfRatios(h, hMixed, &hist2,  step, 0,  10, 5.01, 9.99, kTRUE);
903   
904   c = new TCanvas("c", "c", 1200, 400);
905   c->Divide(3, 1);
906   
907   c->cd(1); hist1->DrawCopy("SURF1");
908   c->cd(2); hist2->DrawCopy("SURF1");
909   
910   hist1->SetStats(0);
911   hist1->Divide(hist2);
912   
913   c->cd(3); hist1->DrawCopy("COLZ");
914 }
915
916 void DrawSameMixed(const char* fileName, const char* fileNamePbPbMix = 0, Int_t step = 6)
917 {
918   if (!fileNamePbPbMix)
919     fileNamePbPbMix = fileName;
920   
921   gpTMin = 1.01;
922   gpTMax = 1.99;
923   
924   loadlibs();
925   
926   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
927   hMixed = (AliUEHistograms*) GetUEHistogram(fileNamePbPbMix, 0, kTRUE);
928   
929   SetupRanges(h);
930   SetupRanges(hMixed);
931   
932   TH1* hist1 = 0;
933   GetDistAndFlow(h, 0, &hist1,  0, step, 0,  80, 2.01, 3.99, 1, kTRUE, 0, kTRUE); 
934   
935 //   ((TH2*) hist1)->Rebin2D(2, 2);
936 //   hist1->Scale(0.25);
937
938   NormalizeToBinWidth(hist1);
939   
940 //   for (Int_t i=1; i<=hist1->GetNbinsX(); ++i)
941 //   {
942 //     for (Int_t j=1; j<=hist1->GetNbinsY(); ++j)
943 //     {
944 //       Float_t factor = 1.0 / (2.0 - TMath::Abs(hist1->GetYaxis()->GetBinCenter(j) / 0.9));
945 //       hist1->SetBinContent(i, j, hist1->GetBinContent(i, j) * factor);
946 //       hist1->SetBinError(i, j, hist1->GetBinError(i, j) * factor);
947 //     }
948 //   }
949
950   c = new TCanvas("c", "c", 1600, 800);
951   c->Divide(2, 1);
952   c->cd(1);
953   gPad->SetLeftMargin(0.15);
954   hist1->SetTitle("");
955   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
956   hist1->GetZaxis()->SetTitleOffset(1.8);
957   hist1->GetXaxis()->SetTitleOffset(1.5);
958   hist1->GetYaxis()->SetTitleOffset(2);
959   hist1->GetZaxis()->SetTitle("same event pairs (a.u.)");
960   hist1->SetStats(kFALSE);
961   hist1->DrawCopy("SURF1");
962   
963   DrawALICELogo(kFALSE, 0.2, 0.7, 0.4, 0.9);
964   
965   hist2 = hist1;
966   
967   GetDistAndFlow(hMixed, 0, &hist1,  0, step, 0,  80, 2.01, 3.99, 1, kTRUE, 0, kTRUE); 
968   
969 //   ((TH2*) hist1)->Rebin2D(2, 2);
970   NormalizeToBinWidth(hist1);
971   
972 //   for (Int_t j=1; j<=hist1->GetNbinsY(); ++j)
973 //   {
974 //     Float_t factor = 1.0 / (1.0 - TMath::Abs(hist1->GetYaxis()->GetBinCenter(j)) / 6.0);
975 //     Printf("%d %f", j, factor);
976 //     for (Int_t i=1; i<=hist1->GetNbinsX(); ++i)
977 //     {
978 //       hist1->SetBinContent(i, j, hist1->GetBinContent(i, j) * factor);
979 //       hist1->SetBinError(i, j, hist1->GetBinError(i, j) * factor);
980 //     }
981 //   }
982
983   c->cd(2);
984   gPad->SetLeftMargin(0.15);
985   hist1->SetTitle("");
986   hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
987   hist1->GetZaxis()->SetTitleOffset(1.8);
988   hist1->GetXaxis()->SetTitleOffset(1.5);
989   hist1->GetYaxis()->SetTitleOffset(2);
990   hist1->GetZaxis()->SetTitle("mixed event pairs (a.u.)");
991   hist1->SetStats(kFALSE);
992   hist1->DrawCopy("SURF1");
993   
994   DrawALICELogo(kFALSE, 0.2, 0.7, 0.4, 0.9);
995
996   c->SaveAs(Form("samemixed_%d.eps", step));
997   c->SaveAs(Form("samemixed_%d.png", step));
998
999   new TCanvas("c3", "c3", 800, 800);
1000   gPad->SetLeftMargin(0.15);
1001   hist2->Divide(hist1);
1002   hist2->DrawCopy("SURF1");
1003 }
1004
1005 void Validation2DAllStepsNew(const char* fileName, Int_t bin = 0)
1006 {
1007   Int_t centralityFrom = 0;
1008   Int_t centralityTo = 80;
1009   
1010   gpTMin = 1.01;
1011   gpTMax = 1.99;
1012   
1013   Float_t ptTrigBegin = 2.01;
1014   Float_t ptTrigEnd = 3.99;
1015   
1016   if (bin == 1)
1017   {
1018     gpTMin = 0.51;
1019     gpTMax = 0.99;
1020     ptTrigBegin = 1.01;
1021     ptTrigEnd = 1.99;
1022   }
1023   else if (bin == 2)
1024   {
1025     gpTMin = 0.51;
1026     gpTMax = 0.99;
1027     ptTrigBegin = 0.51;
1028     ptTrigEnd = 0.99;
1029   }
1030   else if (bin == 3)
1031   {
1032 /*    gpTMin = 0.51;
1033     gpTMax = 0.99;
1034     ptTrigBegin = 0.51;
1035     ptTrigEnd = 0.99;*/
1036     centralityFrom = 0;
1037     centralityTo = 20;
1038   }
1039   else if (bin == 4)
1040   {
1041 /*    gpTMin = 0.51;
1042     gpTMax = 0.99;
1043     ptTrigBegin = 0.51;
1044     ptTrigEnd = 0.99;*/
1045     centralityFrom = 60;
1046     centralityTo = 80;
1047   }
1048   else if (bin == 5)
1049   {
1050     gpTMin = 0.51;
1051     gpTMax = 0.74;
1052     ptTrigBegin = 0.51;
1053     ptTrigEnd = 0.99;
1054   }
1055   
1056   loadlibs();
1057   
1058   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
1059   hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
1060   
1061   SetupRanges(h);
1062   SetupRanges(hMixed);
1063
1064   TH1* hist[6];
1065
1066   GetSumOfRatios(h, hMixed, &hist[0],  0, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd); 
1067   GetSumOfRatios(h, hMixed, &hist[1],  4, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd); 
1068   GetSumOfRatios(h, hMixed, &hist[2],  5, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd); 
1069   GetSumOfRatios(h, hMixed, &hist[3],  6, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd); 
1070   GetSumOfRatios(h, hMixed, &hist[4],  8, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd); 
1071   GetSumOfRatios(h, hMixed, &hist[5],  10, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd); 
1072
1073   c = new TCanvas("c", "c", 1600, 1000);
1074   c->Divide(6, 4);
1075   
1076   Float_t peakYield1[6];
1077   Float_t baselineValues1[6];
1078
1079   for (Int_t i=0; i<6; i++)
1080   {
1081     if (!hist[i])
1082       continue;
1083     
1084     // NOTE fix normalization. these 2d correlations come out of AliUEHist normalized by dphi bin width, but not deta
1085     hist[i]->Scale(1.0 / hist[i]->GetYaxis()->GetBinWidth(1));
1086
1087     ((TH2*) hist[i])->Rebin2D(2, 2); hist[i]->Scale(0.25);
1088   }
1089   
1090   for (Int_t i=0; i<6; i++)
1091   {
1092     if (!hist[i])
1093       continue;
1094
1095     c->cd(i+1);
1096     hist[i]->GetYaxis()->SetRangeUser(-1.99, 1.99);
1097     hist[i]->GetXaxis()->SetTitleOffset(1.5);
1098     hist[i]->GetYaxis()->SetTitleOffset(2);
1099     hist[i]->GetZaxis()->SetTitleOffset(1.8);
1100     hist[i]->GetZaxis()->SetTitle("1/N_{trig} dN_{assoc}/d#Delta#etad#Delta#varphi (1/rad.)");
1101     hist[i]->SetStats(kFALSE);
1102     hist[i]->DrawCopy("SURF1");    
1103     
1104     if (hist[5])
1105     {
1106       c->cd(i+1+6);
1107       TH2* clone = (TH2*) hist[i]->Clone();
1108       clone->Divide(hist[5]);
1109       clone->DrawCopy("COLZ");
1110       gPad->SetRightMargin(0.15);
1111     }
1112     
1113     c->cd(i+1+12);
1114     proj1 = ((TH2*) hist[i])->ProjectionX(Form("proj1_%d", i), hist[i]->GetYaxis()->FindBin(-0.99), hist[i]->GetYaxis()->FindBin(0.99));
1115     proj1->DrawCopy();
1116     
1117     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);
1118     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];
1119     Printf("%d: %f %f", i, peakYield1[i], baselineValues1[i]);
1120
1121     if (hist[5])
1122     {
1123       proj2 = ((TH2*) hist[5])->ProjectionX(Form("proj2_%d", i), hist[5]->GetYaxis()->FindBin(-0.99), hist[5]->GetYaxis()->FindBin(0.99));
1124       proj2->SetLineColor(2);
1125       proj2->DrawCopy("SAME");
1126     
1127       c->cd(i+1+18);
1128       proj1->Divide(proj1, proj2, 1, 1, "B");
1129       proj1->Draw();
1130     }
1131   }
1132   
1133   c = new TCanvas("c2", "c2", 1600, 1000);
1134   c->Divide(6, 4);
1135
1136   for (Int_t i=0; i<6; i++)
1137   {
1138     if (!hist[i])
1139       continue;
1140
1141     c->cd(i+1);
1142     hist[i]->GetYaxis()->SetRangeUser(-1.99, 1.99);
1143     hist[i]->GetXaxis()->SetTitleOffset(1.5);
1144     hist[i]->GetYaxis()->SetTitleOffset(2);
1145     hist[i]->GetZaxis()->SetTitleOffset(1.8);
1146     hist[i]->GetZaxis()->SetTitle("1/N_{trig} dN_{assoc}/d#Delta#etad#Delta#varphi (1/rad.)");
1147     hist[i]->SetStats(kFALSE);
1148     hist[i]->DrawCopy("SURF1");    
1149     
1150     c->cd(i+1+6);
1151     TH2* clone = (TH2*) hist[i]->Clone();
1152     clone->Divide(hist[0]);
1153     clone->DrawCopy("COLZ");
1154     gPad->SetRightMargin(0.15);
1155     
1156     c->cd(i+1+12);
1157     proj1 = ((TH2*) hist[i])->ProjectionX(Form("proj3_%d", i), hist[i]->GetYaxis()->FindBin(-0.99), hist[i]->GetYaxis()->FindBin(0.99));
1158     proj1->DrawCopy();
1159     
1160     proj2 = ((TH2*) hist[0])->ProjectionX(Form("proj4_%d", i), hist[0]->GetYaxis()->FindBin(-0.99), hist[0]->GetYaxis()->FindBin(0.99));
1161     proj2->SetLineColor(2);
1162     proj2->DrawCopy("SAME");
1163     
1164     c->cd(i+1+18);
1165     proj1->Divide(proj1, proj2, 1, 1, "B");
1166     proj1->Draw();
1167   }
1168
1169   c = new TCanvas("c3", "c3", 1600, 1000);
1170   c->Divide(6, 4);
1171
1172   for (Int_t i=3; i<4; i++)
1173   {
1174     if (!hist[i])
1175       continue;
1176
1177     c->cd(i+1);
1178     hist[i]->GetYaxis()->SetRangeUser(-1.99, 1.99);
1179     hist[i]->GetXaxis()->SetTitleOffset(1.5);
1180     hist[i]->GetYaxis()->SetTitleOffset(2);
1181     hist[i]->GetZaxis()->SetTitleOffset(1.8);
1182     hist[i]->GetZaxis()->SetTitle("1/N_{trig} dN_{assoc}/d#Delta#etad#Delta#varphi (1/rad.)");
1183     hist[i]->SetStats(kFALSE);
1184     hist[i]->DrawCopy("SURF1");    
1185     
1186     c->cd(i+1+6);
1187     TH2* clone = (TH2*) hist[i]->Clone();
1188     clone->Divide(hist[4]);
1189     clone->DrawCopy("COLZ");
1190     gPad->SetRightMargin(0.15);
1191     
1192     c->cd(i+1+12);
1193     proj1 = ((TH2*) hist[i])->ProjectionX(Form("proj4_%d", i), hist[i]->GetYaxis()->FindBin(-0.99), hist[i]->GetYaxis()->FindBin(0.99));
1194     proj1->DrawCopy();
1195     
1196     proj2 = ((TH2*) hist[4])->ProjectionX(Form("proj5_%d", i), hist[4]->GetYaxis()->FindBin(-0.99), hist[4]->GetYaxis()->FindBin(0.99));
1197     proj2->SetLineColor(2);
1198     proj2->DrawCopy("SAME");
1199     
1200     c->cd(i+1+18);
1201     proj1->Divide(proj1, proj2, 1, 1, "B");
1202     proj1->Draw();
1203   }
1204   
1205   c = new TCanvas("c4", "c4", 1200, 400);
1206   c->Divide(3, 1);
1207  
1208   for (Int_t i=0; i<1; i++)
1209   {
1210     if (!hist[i])
1211       continue;
1212
1213     if (hist[5])
1214     {
1215       c->cd(1);
1216       TH2* clone = (TH2*) hist[i]->Clone();
1217       clone->Divide(hist[5]);
1218       clone->DrawCopy("COLZ");
1219       gPad->SetRightMargin(0.15);
1220     }
1221     
1222     c->cd(2);
1223     proj1 = ((TH2*) hist[i])->ProjectionX(Form("proj1_%d", i), hist[i]->GetYaxis()->FindBin(-0.99), hist[i]->GetYaxis()->FindBin(0.99));
1224     proj1->DrawCopy();
1225     
1226     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);
1227     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];
1228     Printf("%d: %f %f", i, peakYield1[i], baselineValues1[i]);
1229
1230     if (hist[5])
1231     {
1232       proj2 = ((TH2*) hist[5])->ProjectionX(Form("proj2_%d", i), hist[5]->GetYaxis()->FindBin(-0.99), hist[5]->GetYaxis()->FindBin(0.99));
1233       proj2->SetLineColor(2);
1234       proj2->DrawCopy("SAME");
1235     
1236       c->cd(3);
1237       proj1->Divide(proj1, proj2, 1, 1, "B");
1238       proj1->Draw();
1239     }
1240   }
1241   
1242   for (Int_t i=0; i<6; i++)
1243     Printf("%d/%d: %f %f", i, 0, peakYield1[i] / peakYield1[0] - 1, baselineValues1[i] / baselineValues1[0] - 1);
1244
1245   if (hist[5])
1246   {
1247     for (Int_t i=0; i<6; i++)
1248       Printf("%d/%d: %f %f", i, 5, peakYield1[i] / peakYield1[5] - 1, baselineValues1[i] / baselineValues1[5] - 1);
1249   }
1250 }
1251
1252 void Validation2DAllBins(const char* fileName, const char *fileName2)
1253 {
1254   /* Int_t is[] = { 0, 1, 2, 3, 4, 5};
1255   Int_t js[] = { 1, 2, 3, 4, 5, 6 };
1256   Int_t n = 5;*/
1257 /*  Int_t is[] = { 0, 1, 1, 2, 2, 2, 3, 3, 3 };
1258   Int_t js[] = { 1, 1, 2, 1, 2, 3, 1, 2, 3 };*/
1259   Int_t is[] = { 0, 1, 1, 2, 2, 2, 3 };
1260   Int_t js[] = { 1, 1, 2, 1, 2, 3, 3 };
1261   Int_t n = 6;
1262   
1263   file1 = TFile::Open(fileName);
1264   TFile* file2 = 0;
1265   if (fileName2)
1266     file2 = TFile::Open(fileName2);
1267   
1268   file3 = TFile::Open("non_closure.root", "RECREATE");
1269   file3->Close();
1270   
1271   Float_t baselineValues1, baselineValues2, peakYield1, peakYield2;
1272   
1273   Int_t padID = 0;
1274   Int_t padN = 4;
1275   for (Int_t centr=0; centr<4; centr++)
1276   {
1277     for (Int_t i=0; i<n; i++)
1278     {
1279       if (padN == 4)
1280       {
1281         c = new TCanvas(Form("c%d", padID), Form("c%d", padID), 1100, 750);
1282         c->Divide(3, 3);
1283         padN = 1;
1284         padID++;
1285       }
1286
1287       TH2* hist1 = (TH2*) file1->Get(Form("dphi_%d_%d_%d", is[i], js[i], centr));
1288       if (!hist1)
1289         continue;
1290       TH2* hist2 = 0;
1291       if (file2)
1292         hist2 = (TH2*) file2->Get(Form("dphi_%d_%d_%d", is[i], js[i], centr));
1293       else
1294         hist2 = (TH2*) file1->Get(Form("dphi_%d_%d_%d", is[i], js[i], centr+4));
1295     
1296       // NOTE fix normalization. these 2d correlations come out of AliUEHist normalized by dphi bin width, but not deta
1297       hist1->Scale(1.0 / hist1->GetYaxis()->GetBinWidth(1));
1298       hist2->Scale(1.0 / hist2->GetYaxis()->GetBinWidth(1));
1299
1300       ((TH2*) hist1)->Rebin2D(2, 2); hist1->Scale(0.25);
1301       ((TH2*) hist2)->Rebin2D(2, 2); hist2->Scale(0.25);
1302
1303       const Float_t outerEta = 1.8;
1304       const Float_t exclusion = 0.5;
1305       
1306       c->cd(padN);
1307       proj1 = ((TH2*) hist1)->ProjectionX(Form("proj1a_%d_%d", centr, i), hist1->GetYaxis()->FindBin(-outerEta + 0.01), hist1->GetYaxis()->FindBin(-exclusion - 0.01));
1308       proj1b = ((TH2*) hist1)->ProjectionX(Form("proj1b_%d_%d", centr, i), hist1->GetYaxis()->FindBin(exclusion + 0.01), hist1->GetYaxis()->FindBin(outerEta - 0.01));
1309       proj1->Add(proj1b);
1310       copy = proj1->DrawCopy();
1311       copy->GetYaxis()->SetRangeUser(proj1->GetMinimum() * 0.9, proj1->GetMaximum() * 1.2);
1312       proj1c = ((TH2*) hist1)->ProjectionX(Form("proj1c_%d_%d", centr, i), hist1->GetYaxis()->FindBin(-outerEta + 0.01), hist1->GetYaxis()->FindBin(outerEta - 0.01));
1313       proj1c->SetLineColor(2);
1314       proj1c->DrawCopy("SAME");
1315       copy->SetMinimum(TMath::Min(copy->GetMinimum(), proj1c->GetMinimum()));
1316       copy->SetMaximum(1.2 * TMath::Max(copy->GetMaximum(), proj1c->GetMaximum()));
1317       
1318       Double_t baselineValues1E, peakYield1E;
1319       baselineValues1 = proj1->IntegralAndError(proj1->FindBin(TMath::Pi()/2 - 0.2), proj1->FindBin(TMath::Pi()/2 + 0.2), baselineValues1E);
1320       baselineValues1 /= (proj1->FindBin(TMath::Pi()/2 + 0.2) - proj1->FindBin(TMath::Pi()/2 - 0.2) + 1);
1321       baselineValues1E /= (proj1->FindBin(TMath::Pi()/2 + 0.2) - proj1->FindBin(TMath::Pi()/2 - 0.2) + 1);
1322       peakYield1 = proj1->IntegralAndError(proj1->GetXaxis()->FindBin(-1), proj1->GetXaxis()->FindBin(1), peakYield1E);
1323       peakYield1 /= (proj1->GetXaxis()->FindBin(0.99) - proj1->GetXaxis()->FindBin(-0.99) + 1);
1324       peakYield1E /= (proj1->GetXaxis()->FindBin(0.99) - proj1->GetXaxis()->FindBin(-0.99) + 1);
1325       peakYield1 -= baselineValues1;
1326       peakYield1E = TMath::Sqrt(peakYield1E * peakYield1E + baselineValues1E * baselineValues1E);
1327
1328       proj2 = ((TH2*) hist2)->ProjectionX(Form("proj2a_%d_%d", centr, i), hist2->GetYaxis()->FindBin(-outerEta + 0.01), hist2->GetYaxis()->FindBin(-exclusion - 0.01));
1329       proj2b = ((TH2*) hist2)->ProjectionX(Form("proj2b_%d_%d", centr, i), hist2->GetYaxis()->FindBin(exclusion + 0.01), hist2->GetYaxis()->FindBin(outerEta - 0.01));
1330       proj2->Add(proj2b);
1331       proj2->SetLineColor(3);
1332       proj2->DrawCopy("SAME");
1333       proj2c = ((TH2*) hist2)->ProjectionX(Form("proj2c_%d_%d", centr, i), hist2->GetYaxis()->FindBin(-outerEta + 0.01), hist2->GetYaxis()->FindBin(outerEta - 0.01));
1334       proj2c->SetLineColor(4);
1335       proj2c->DrawCopy("SAME");
1336       
1337       Double_t baselineValues2E, peakYield2E;
1338       baselineValues2 = proj2->IntegralAndError(proj1->FindBin(TMath::Pi()/2 - 0.2), proj2->FindBin(TMath::Pi()/2 + 0.2), baselineValues2E);
1339       baselineValues2 /= (proj2->FindBin(TMath::Pi()/2 + 0.2) - proj2->FindBin(TMath::Pi()/2 - 0.2) + 1);
1340       baselineValues2E /= (proj2->FindBin(TMath::Pi()/2 + 0.2) - proj2->FindBin(TMath::Pi()/2 - 0.2) + 1);
1341       peakYield2 = proj2->IntegralAndError(proj2->GetXaxis()->FindBin(-1), proj2->GetXaxis()->FindBin(1), peakYield2E);
1342       peakYield2 /= (proj2->GetXaxis()->FindBin(0.99) - proj2->GetXaxis()->FindBin(-0.99) + 1);
1343       peakYield2E /= (proj2->GetXaxis()->FindBin(0.99) - proj2->GetXaxis()->FindBin(-0.99) + 1);
1344       peakYield2 -= baselineValues2;
1345       peakYield2E = TMath::Sqrt(peakYield2E * peakYield2E + baselineValues2E * baselineValues2E);
1346       
1347   //     Printf("%d: %f %f %f %f %.2f%% %.2f%%", i, peakYield1, baselineValues1, peakYield2, baselineValues2, 100.0 * peakYield1 / peakYield2 - 100, 100.0 * baselineValues1 / baselineValues2 - 100);
1348       Printf("%s: %.2f%% +- %.2f%%    %.2f%% +- %.2f%%", 
1349              hist1->GetTitle(), 
1350              100.0 * peakYield1 / peakYield2 - 100, 
1351              100.0 * peakYield1 / peakYield2 * TMath::Sqrt(TMath::Power(peakYield1E / peakYield1, 2) + TMath::Power(peakYield2E / peakYield2, 2)),
1352              100.0 * baselineValues1 / baselineValues2 - 100,
1353              100.0 * baselineValues1 / baselineValues2 * TMath::Sqrt(TMath::Power(baselineValues1E / baselineValues1, 2) + TMath::Power(baselineValues2E / baselineValues2, 2))
1354             );
1355       
1356       c->cd(padN+3);
1357       proj1->Divide(proj1, proj2, 1, 1, "B");
1358       proj1c->Divide(proj1c, proj2c, 1, 1, "B");
1359   //     proj1->Add(proj2, -1);
1360       proj1->Draw();
1361       proj1c->SetLineColor(2);
1362       proj1c->Draw("SAME");
1363       
1364       c->cd(padN+6);
1365       hist1->Divide(hist2);
1366       hist1->GetYaxis()->SetRangeUser(-1.79, 1.79);
1367       hist1->Draw("COLZ");
1368       
1369       file3 = TFile::Open("non_closure.root", "UPDATE");
1370       proj1->Write(Form("non_closure_%d_%d_%d", is[i], js[i], centr));
1371       proj1c->Write(Form("non_closure_all_%d_%d_%d", is[i], js[i], centr));
1372       hist1->Write(Form("non_closure_2d_%d_%d_%d", is[i], js[i], centr));
1373       file3->Close();
1374       
1375       padN++;
1376     }
1377   }
1378 }
1379
1380 void Validation2DAllSteps(const char* fileName, const char* fileNameCorrected = "corrected.root", Int_t startStep = 8)
1381 {
1382   Int_t centralityFrom = 0;
1383   Int_t centralityTo = 80;
1384   
1385   gpTMin = 1.01;
1386   gpTMax = 1.99;
1387   
1388   Float_t ptTrigBegin = 2.01;
1389   Float_t ptTrigEnd = 2.99;
1390   
1391   loadlibs();
1392   
1393   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
1394   hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
1395   
1396   AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(fileNameCorrected);
1397   hMixed2 = (AliUEHistograms*) GetUEHistogram(fileNameCorrected, 0, kTRUE);
1398
1399   SetupRanges(h);
1400   SetupRanges(hMixed);
1401   SetupRanges(h2);
1402   SetupRanges(hMixed2);
1403
1404   TH1* hist[6];
1405   TH1* hist2[6];
1406
1407 //   GetSumOfRatios(h, hMixed,   &hist[0],  0, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, kTRUE); 
1408   
1409   GetDistAndFlow(h, hMixed,   &hist[0],  0, 0, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, 0); 
1410   GetDistAndFlow(h, hMixed,   &hist[1],  0, 4, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, 6); 
1411   GetDistAndFlow(h, hMixed,   &hist[2],  0, 5, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, 6); 
1412   GetDistAndFlow(h, hMixed,   &hist[3],  0, startStep, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, startStep); 
1413   GetDistAndFlow(h2, hMixed2, &hist2[0],  0, 0, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, startStep); 
1414   GetDistAndFlow(h2, hMixed2, &hist2[1],  0, 4, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, startStep); 
1415   GetDistAndFlow(h2, hMixed2, &hist2[2],  0, 5, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, startStep); 
1416   GetDistAndFlow(h2, hMixed2, &hist2[3],  0, startStep, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, startStep); 
1417
1418   c = new TCanvas("c", "c", 1600, 1000);
1419   c->Divide(4, 5);
1420   
1421   Float_t peakYield1[4];
1422   Float_t baselineValues1[4];
1423   Float_t peakYield2[4];
1424   Float_t baselineValues2[4];
1425   for (Int_t i=0; i<4; i++)
1426   {
1427     // NOTE fix normalization. these 2d correlations come out of AliUEHist normalized by dphi bin width, but not deta
1428     hist[i]->Scale(1.0 / hist[i]->GetYaxis()->GetBinWidth(1));
1429     hist2[i]->Scale(1.0 / hist2[i]->GetYaxis()->GetBinWidth(1));
1430
1431     ((TH2*) hist[i])->Rebin2D(2, 2); hist[i]->Scale(0.25);
1432 //     ((TH2*) hist[i])->Rebin2D(2, 2); hist[i]->Scale(0.25);
1433     
1434     c->cd(i+1);
1435     hist[i]->GetYaxis()->SetRangeUser(-1.59, 1.59);
1436     hist[i]->GetXaxis()->SetTitleOffset(1.5);
1437     hist[i]->GetYaxis()->SetTitleOffset(2);
1438     hist[i]->GetZaxis()->SetTitleOffset(1.8);
1439     hist[i]->GetZaxis()->SetTitle("1/N_{trig} dN_{assoc}/d#Delta#etad#Delta#varphi (1/rad.)");
1440     hist[i]->SetStats(kFALSE);
1441     hist[i]->DrawCopy("SURF1");    
1442     
1443     ((TH2*) hist2[i])->Rebin2D(2, 2); hist2[i]->Scale(0.25);
1444 //     ((TH2*) hist2[i])->Rebin2D(2, 2); hist2[i]->Scale(0.25);
1445     
1446 //     TF2* func2 = new TF2("func2", "[0]+[1]*exp(-0.5*((x/[2])**2+(y/[3])**2))", -1, 1, -0.99, 0.99);
1447 //     func2->SetParameters(0, 1, 0.5, 0.5);
1448 //     hist[i]->Fit(func2, "0R");
1449 //     hist[i]->Fit(func2, "0R");
1450 //     
1451 //     c->cd(i+1+4);
1452 //     func2->DrawClone("SURF1");
1453 //     
1454 //     baselineValues1[i] = func2->GetParameter(0);
1455 //     func2->SetParameter(0, 0);
1456 //     peakYield1[i] = func2->Integral(-0.5 * TMath::Pi(), 0.5 * TMath::Pi(), -1.4, 1.4);
1457 //     Printf("%f %f", peakYield1[i], baselineValues1[i]);
1458
1459     c->cd(i+1+4);
1460     hist2[i]->GetYaxis()->SetRangeUser(-1.59, 1.59);
1461     hist2[i]->GetXaxis()->SetTitleOffset(1.5);
1462     hist2[i]->GetYaxis()->SetTitleOffset(2);
1463     hist2[i]->GetZaxis()->SetTitleOffset(1.8);
1464     hist2[i]->GetZaxis()->SetTitle("1/N_{trig} dN_{assoc}/d#Delta#etad#Delta#varphi (1/rad.)");
1465     hist2[i]->SetStats(kFALSE);
1466     hist2[i]->DrawCopy("SURF1");        
1467     
1468     c->cd(i+1+12);
1469     proj1 = ((TH2*) hist[i])->ProjectionX(Form("proj1_%d", i), hist[i]->GetYaxis()->FindBin(-0.99), hist[i]->GetYaxis()->FindBin(0.99));
1470     proj1->DrawCopy();
1471     
1472     baselineValues1[i] = proj1->GetMinimum();
1473     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];
1474     Printf("%f %f", peakYield1[i], baselineValues1[i]);
1475
1476     proj2 = ((TH2*) hist2[i])->ProjectionX(Form("proj2_%d", i), hist2[i]->GetYaxis()->FindBin(-0.99), hist2[i]->GetYaxis()->FindBin(0.99));
1477     proj2->SetLineColor(2);
1478     proj2->DrawCopy("SAME");
1479     
1480     baselineValues2[i] = proj2->GetMinimum();
1481     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];
1482     Printf("%f %f", peakYield2[i], baselineValues2[i]);
1483
1484     c->cd(i+1+16);
1485     proj1->Divide(proj2);
1486     proj1->Draw();
1487     
1488 //     func2 = new TF2("func2", "[0]+[1]*exp(-0.5*((x/[2])**2+(y/[3])**2))", -1, 1, -0.99, 0.99);
1489 //     func2->SetParameters(0, 1, 0.5, 0.5);
1490 //     hist2[i]->Fit(func2, "0R");
1491 //     hist2[i]->Fit(func2, "0R");
1492 //     
1493 //     c->cd(i+1+12);
1494 //     func2->DrawClone("SURF1");
1495 //     
1496 //     baselineValues2[i] = func2->GetParameter(0);
1497 //     func2->SetParameter(0, 0);
1498 //     peakYield2[i] = func2->Integral(-0.5 * TMath::Pi(), 0.5 * TMath::Pi(), -1.4, 1.4);
1499 //     Printf("%f %f", peakYield2[i], baselineValues2[i]);
1500
1501     c->cd(i+1+8);
1502     TH2* clone = (TH2*) hist[i]->Clone();
1503     clone->Divide(hist2[i]);
1504 //     clone->Add(hist2[i], -1);
1505     clone->DrawCopy("COLZ");
1506     gPad->SetRightMargin(0.15);
1507     
1508 /*    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);
1509     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);*/
1510     
1511 //     break;
1512   }
1513
1514   for (Int_t i=0; i<4; i++)
1515   {
1516     Printf("%d: %f %f", i, peakYield1[i] / peakYield2[i] - 1, baselineValues1[i] / baselineValues2[i] - 1);
1517 //     Printf("%d: %f %f", i, peakYield1[i] - 1, baselineValues1[i] - 1);
1518   }
1519 }
1520
1521 void CorrelatedContaminationEffect(const char* fileName, const char* fileNameCorrected = "corrected.root", Int_t bin = 0, Int_t startStep = 8)
1522 {
1523   Int_t centralityFrom = 0;
1524   Int_t centralityTo = 80;
1525   
1526   gpTMin = 1.01;
1527   gpTMax = 1.99;
1528   
1529   Float_t ptTrigBegin = 2.01;
1530   Float_t ptTrigEnd = 3.99;
1531   
1532   if (bin == 1)
1533   {
1534     ptTrigBegin = 1.01;
1535     ptTrigEnd = 1.99;
1536   }
1537   else if (bin == 2)
1538   {
1539     gpTMin = 0.51;
1540     gpTMax = 0.99;
1541     ptTrigBegin = 1.01;
1542     ptTrigEnd = 1.99;  
1543   }
1544   else if (bin == 3)
1545   {
1546     ptTrigBegin = 4.01;
1547     ptTrigEnd = 7.99;  
1548   }
1549   
1550   loadlibs();
1551   
1552   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
1553   hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
1554   
1555   AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(fileNameCorrected);
1556   hMixed2 = (AliUEHistograms*) GetUEHistogram(fileNameCorrected, 0, kTRUE);
1557
1558   SetupRanges(h);
1559   SetupRanges(hMixed);
1560   SetupRanges(h2);
1561   SetupRanges(hMixed2);
1562
1563   TH1* hist[6];
1564
1565   Int_t maxFilled = 5;
1566   GetSumOfRatios(h, hMixed, &hist[0],  0, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd); 
1567   GetSumOfRatios(h, hMixed, &hist[1],  4, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd); 
1568   GetSumOfRatios(h, hMixed, &hist[2],  5, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd); 
1569   GetSumOfRatios(h, hMixed, &hist[3],  6, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd); 
1570   GetSumOfRatios(h, hMixed, &hist[4],  startStep, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd); 
1571 //   GetSumOfRatios(h2, hMixed2, &hist[5],  startStep, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd); 
1572   
1573 //   GetDistAndFlow(h, hMixed, &hist[0],  0, 0, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, 0); 
1574 //   GetDistAndFlow(h, hMixed, &hist[1],  0, 4, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, 6); 
1575 //   GetDistAndFlow(h, hMixed, &hist[2],  0, 5, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, 6); 
1576 //   GetDistAndFlow(h, hMixed, &hist[3],  0, 6, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, 6); 
1577 //   GetDistAndFlow(h, hMixed, &hist[4],  0, startStep, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, startStep); 
1578 //   GetDistAndFlow(h2, hMixed2, &hist[5],  0, 0, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE, startStep); 
1579
1580   c = new TCanvas("c", "c", 1600, 1000);
1581   c->Divide(6, 2);
1582   
1583   for (Int_t i=0; i<maxFilled; i++)
1584   {
1585     // NOTE fix normalization. these 2d correlations come out of AliUEHist normalized by dphi bin width, but not deta
1586     hist[i]->Scale(1.0 / hist[i]->GetYaxis()->GetBinWidth(1));
1587
1588     ((TH2*) hist[i])->Rebin2D(2, 2); hist[i]->Scale(0.25);
1589 //     ((TH2*) hist[i])->Rebin2D(2, 2); hist[i]->Scale(0.25);
1590     
1591     c->cd(i+1);
1592     hist[i]->GetYaxis()->SetRangeUser(-1.59, 1.59);
1593     hist[i]->GetXaxis()->SetTitleOffset(1.5);
1594     hist[i]->GetYaxis()->SetTitleOffset(2);
1595     hist[i]->GetZaxis()->SetTitleOffset(1.8);
1596     hist[i]->GetZaxis()->SetTitle("1/N_{trig} dN_{assoc}/d#Delta#etad#Delta#varphi (1/rad.)");
1597     hist[i]->SetStats(kFALSE);
1598     hist[i]->DrawCopy("SURF1");    
1599   }
1600   
1601   for (Int_t i=1; i<maxFilled; i++)
1602   {
1603     TH2* clone = (TH2*) hist[i]->Clone();
1604     if (i < 4)
1605       clone->Divide(hist[i-1]);
1606     else if (i < 5)
1607       clone->Divide(hist[2]);
1608     else 
1609       clone->Divide(hist[0]);
1610   
1611     c->cd(6+i);
1612     gPad->SetRightMargin(0.15);
1613   //   hist1->SetTitle("");
1614 //     clone->GetZaxis()->SetRangeUser(0.8, 1.2);
1615     clone->GetZaxis()->SetTitle("1/N_{trig} dN_{assoc}/d#Delta#etad#Delta#varphi (1/rad.)");
1616     clone->SetStats(kFALSE);
1617     clone->DrawCopy("COLZ");
1618   }
1619
1620   Float_t peakYield[6];
1621   Float_t baselineValues[6];
1622   for (Int_t i=0; i<maxFilled; i++)
1623   {
1624     Int_t phi1 = hist[i]->GetXaxis()->FindBin(-1);
1625     Int_t phi2 = hist[i]->GetXaxis()->FindBin(1);
1626     Int_t eta1 = hist[i]->GetYaxis()->FindBin(-1.59);
1627     Int_t eta2 = hist[i]->GetYaxis()->FindBin(1.01);
1628     Int_t eta3 = hist[i]->GetYaxis()->FindBin(1.59);
1629     Float_t baseline = ((TH2*) hist[i])->Integral(phi1, phi2, eta2, eta3, "width") / (phi2 - phi1 + 1) / (eta3 - eta2 + 1);
1630     Float_t peak = ((TH2*) hist[i])->Integral(phi1, phi2, eta1, eta3, "width");
1631     Printf("%f %f", baseline, peak);
1632     peak -= baseline * (eta3 - eta1 + 1) * (phi2 - phi1 + 1);
1633     Printf("%f", peak);
1634     peakYield[i] = peak;
1635     baselineValues[i] = baseline;
1636   }
1637   
1638   for (Int_t i=1; i<maxFilled; i++)
1639   {
1640     if (i < 4)
1641       Printf("%d/%d: %f %f", i, i-1, peakYield[i] / peakYield[i-1] - 1, baselineValues[i] / baselineValues[i-1] - 1);
1642     else if (i < 5)
1643       Printf("%d/%d: %f %f", i, 2, peakYield[i] / peakYield[2] - 1, baselineValues[i] / baselineValues[2] - 1);
1644     else
1645       Printf("%d/%d: %f %f", 0, i, peakYield[0] / peakYield[i] - 1, baselineValues[0] / baselineValues[i] - 1);
1646   }
1647   
1648   c = new TCanvas("c2", "c2", 1600, 1000);
1649   c->Divide(6, 2);
1650   for (Int_t i=0; i<maxFilled; i++)
1651   {
1652     c->cd(i+1);
1653     hist[i]->DrawCopy("SURF1");
1654     
1655     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);
1656     func2->SetParameters(0, 1, 0.5, 0.5);
1657 //     func2->SetParLimits(1, 0, 10);
1658 //     func2->SetParLimits(2, sigmaFitLimit, 1);
1659 //     func2->SetParLimits(3, sigmaFitLimit, 1);
1660     hist[i]->Fit(func2, "0R");
1661     
1662     c->cd(i+7);
1663     func2->DrawClone("SURF1");
1664     
1665     baselineValues[i] = func2->GetParameter(0);
1666     func2->SetParameter(0, 0);
1667     peakYield[i] = func2->Integral(-0.5 * TMath::Pi(), 0.5 * TMath::Pi(), -1.4, 1.4);
1668     Printf("%f %f", peakYield[i], baselineValues[i]);
1669   }
1670
1671   for (Int_t i=1; i<maxFilled; i++)
1672   {
1673     if (i < 4)
1674       Printf("%d/%d: %f %f", i, i-1, peakYield[i] / peakYield[i-1] - 1, baselineValues[i] / baselineValues[i-1] - 1);
1675     else if (i < 5)
1676       Printf("%d/%d: %f %f", i, 2, peakYield[i] / peakYield[2] - 1, baselineValues[i] / baselineValues[2] - 1);
1677     else
1678       Printf("%d/%d: %f %f", 0, i, peakYield[0] / peakYield[i] - 1, baselineValues[0] / baselineValues[i] - 1);
1679   }
1680
1681   for (Int_t i=1; i<maxFilled; i++)
1682   {
1683     Printf("%d/%d: %f %f", 0, i, peakYield[0] / peakYield[i] - 1, baselineValues[0] / baselineValues[i] - 1);
1684   }
1685 }
1686
1687 void DrawValidation2D(const char* fileName, const char* fileNameCorrected = "corrected.root", Int_t startStep = 8)
1688 {
1689   Int_t centralityTo = 80;
1690   
1691   gpTMin = 1.01;
1692   gpTMax = 1.99;
1693   
1694   loadlibs();
1695   
1696   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
1697   hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
1698   
1699   SetupRanges(h);
1700   SetupRanges(hMixed);
1701
1702   TH1* hist1 = 0;
1703   GetDistAndFlow(h, hMixed, &hist1,  0, 0, 0,  centralityTo, 2.01, 3.99, 1, kTRUE, 0, kTRUE, 0); 
1704   // NOTE fix normalization. these 2d correlations come out of AliUEHist normalized by dphi bin width, but not deta
1705   hist1->Scale(1.0 / hist1->GetYaxis()->GetBinWidth(1));
1706   
1707 //   ((TH2*) hist1)->Rebin2D(2, 2); hist1->Scale(0.25);
1708   ((TH2*) hist1)->Rebin2D(2, 2); hist1->Scale(0.25);
1709
1710 //   NormalizeToBinWidth(hist1);
1711   
1712   c = new TCanvas("c", "c", 1000, 1000);
1713   c->Divide(2, 2);
1714   
1715   c->cd(1);
1716   gPad->SetLeftMargin(0.15);
1717 //   hist1->SetTitle("");
1718   hist1->GetYaxis()->SetRangeUser(-1.59, 1.59);
1719   hist1->GetXaxis()->SetTitleOffset(1.5);
1720   hist1->GetYaxis()->SetTitleOffset(2);
1721   hist1->GetZaxis()->SetTitleOffset(1.8);
1722   hist1->GetZaxis()->SetTitle("1/N_{trig} dN_{assoc}/d#Delta#etad#Delta#varphi (1/rad.)");
1723   hist1->SetStats(kFALSE);
1724   hist1->DrawCopy("SURF1");
1725   DrawLatex(0.1, 0.85, 1, "MC", 0.04);
1726 //   DrawALICELogo(kFALSE, 0.7, 0.7, 0.9, 0.9);
1727   
1728   hist2 = hist1;
1729   hist1 = 0;
1730   GetDistAndFlow(h, hMixed, &hist1,  0, startStep, 0,  centralityTo, 2.01, 3.99, 1, kTRUE, 0, kTRUE, startStep); 
1731   // NOTE fix normalization. these 2d correlations come out of AliUEHist normalized by dphi bin width, but not deta
1732   hist1->Scale(1.0 / hist1->GetYaxis()->GetBinWidth(1));
1733
1734 //   ((TH2*) hist1)->Rebin2D(2, 2); hist1->Scale(0.25);
1735   ((TH2*) hist1)->Rebin2D(2, 2); hist1->Scale(0.25);
1736 //   NormalizeToBinWidth(hist1);
1737
1738   c->cd(2);
1739   gPad->SetLeftMargin(0.15);
1740   hist1->SetTitle("");
1741   hist1->GetYaxis()->SetRangeUser(-1.59, 1.59);
1742   hist1->GetXaxis()->SetTitleOffset(1.5);
1743   hist1->GetYaxis()->SetTitleOffset(2);
1744   hist1->GetZaxis()->SetTitleOffset(1.8);
1745   hist1->SetStats(kFALSE);
1746   hist1->GetZaxis()->SetTitle("1/N_{trig} dN_{assoc}/d#Delta#etad#Delta#varphi (1/rad.)");
1747   hist1->DrawCopy("SURF1");  
1748   DrawLatex(0.1, 0.85, 1, "Uncorrected", 0.04);
1749 //   DrawALICELogo(kFALSE, 0.7, 0.7, 0.9, 0.9);
1750
1751   c2 = new TCanvas("c3", "c3", 800, 800);
1752 //   hist2->Scale(1.09);
1753   hist1->Divide(hist2);
1754 //   hist1->Add(hist2, -1);
1755   hist1->DrawCopy("SURF1");  
1756   
1757 //   return;
1758   
1759 //   AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram("LHC11a10a_bis_AOD090_120406_zvtx_rebinned_corrected.root");
1760   AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(fileNameCorrected);
1761   SetupRanges(h2);
1762  
1763   GetDistAndFlow(h2, hMixed, &hist1,  0, 0, 0,  centralityTo, 2.01, 3.99, 1, kTRUE, 0, kTRUE, startStep); 
1764   // NOTE fix normalization. these 2d correlations come out of AliUEHist normalized by dphi bin width, but not deta
1765   hist1->Scale(1.0 / hist1->GetYaxis()->GetBinWidth(1));
1766
1767   ((TH2*) hist1)->Rebin2D(2, 2); hist1->Scale(0.25);
1768 //   ((TH2*) hist1)->Rebin2D(2, 2); hist1->Scale(0.25);
1769
1770   c->cd(3);
1771   gPad->SetLeftMargin(0.15);
1772   hist1->SetTitle("");
1773   hist1->GetYaxis()->SetRangeUser(-1.59, 1.59);
1774   hist1->GetXaxis()->SetTitleOffset(1.5);
1775   hist1->GetZaxis()->SetTitleOffset(1.8);
1776   hist1->GetZaxis()->SetTitle("1/N_{trig} dN_{assoc}/d#Delta#etad#Delta#varphi (1/rad.)");
1777   hist1->GetYaxis()->SetTitleOffset(2);
1778   hist1->SetStats(kFALSE);
1779   hist1->DrawCopy("SURF1");  
1780   DrawLatex(0.1, 0.85, 1, "Corrected", 0.04);
1781 //   DrawALICELogo(kFALSE, 0.7, 0.7, 0.9, 0.9);
1782   
1783   hist1->Divide(hist2);
1784
1785   c->cd(4);
1786   gPad->SetRightMargin(0.15);
1787   hist1->SetTitle("");
1788   hist1->GetYaxis()->SetRangeUser(-1.59, 1.59);
1789   hist1->GetXaxis()->SetTitleOffset(1.2);
1790   hist1->GetYaxis()->SetTitleOffset(1.2);
1791   hist1->GetZaxis()->SetTitle("Ratio: Corrected / MC");
1792   hist1->SetStats(kFALSE);
1793   hist1->GetZaxis()->SetRangeUser(0.99, 1.01);
1794   hist1->DrawCopy("COLZ");  
1795
1796 //   DrawALICELogo(kFALSE, 0.7, 0.7, 0.9, 0.9);
1797   
1798   c->SaveAs("validation.eps");
1799   c->SaveAs("validation.gif");
1800 }
1801
1802 void DrawValidation(const char* fileName1, const char* fileName2)
1803 {
1804   gpTMin = 1.01;
1805   gpTMax = 3.99;
1806   
1807   CompareStep(fileName1, fileName2, 2, 6, 4, 0, 4.01, 19.99);
1808   CompareStep(fileName1, fileName2, 2, 4, 4, 0, 4.01, 19.99);
1809
1810   CompareStep(fileName1, fileName2, 2, 4, 2, 0, 4.01, 19.99);
1811   CompareStep(fileName1, fileName2, 2, 2, 2, 0, 4.01, 19.99);
1812 }
1813
1814 void ProfileMultiplicity(const char* fileName = "PWG4_JetTasksOutput.root")
1815 {
1816   loadlibs();
1817
1818   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
1819
1820   new TCanvas;
1821   h->GetCorrelationMultiplicity()->Draw("colz");
1822   gPad->SetLogz();
1823
1824   new TCanvas;
1825   h->GetCorrelationMultiplicity()->ProfileX()->DrawCopy()->Fit("pol1", "", "", 1, 10);
1826 }
1827
1828 void SetupRanges(void* obj)
1829 {
1830   if (!obj)
1831     return;
1832   ((AliUEHistograms*) obj)->SetEtaRange(0, 0);
1833 //   ((AliUEHistograms*) obj)->SetEtaRange(-0.99, 0.99); Printf("WARNING: Setting eta Range!");
1834   ((AliUEHistograms*) obj)->SetPtRange(gpTMin, gpTMax);
1835   ((AliUEHistograms*) obj)->SetCombineMinMax(kTRUE);
1836   if (gZVtxRange > 0)
1837     ((AliUEHistograms*) obj)->SetZVtxRange(-gZVtxRange+0.01, gZVtxRange-0.01);
1838 }
1839
1840 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)
1841 {
1842   AliUEHist* corrected = (AliUEHist*) correctedVoid;
1843   AliUEHist* comparison = (AliUEHist*) comparisonVoid;
1844
1845   Int_t beginStep = AliUEHist::kCFStepAll;
1846   Int_t endStep = AliUEHist::kCFStepReconstructed;
1847   
1848   if (compareStep != -1)
1849   {
1850     beginStep = compareStep;
1851     endStep = compareStep;
1852   }
1853   
1854   Int_t beginRegion = 0;
1855   Int_t endRegion = 2;
1856   
1857   if (compareRegion != -1)
1858   {
1859     beginRegion = compareRegion;
1860     endRegion = compareRegion;
1861   }
1862
1863   for (Int_t step=beginStep; step<=endStep; step++)
1864   {
1865     if (compareStep == -1 && (step == AliUEHist::kCFStepAnaTopology || step == AliUEHist::kCFStepTriggered))
1866       continue;
1867       
1868     for (Int_t region=beginRegion; region <= endRegion; region++)
1869     {
1870       Printf("%f %f", ptLeadMin, ptLeadMax);
1871       TH1* corrHist = corrected->GetUEHist(step, region, ptLeadMin, ptLeadMax);
1872       TH1* mcHist   = comparison->GetUEHist(step, region, ptLeadMin, ptLeadMax);
1873       
1874       DrawRatio(corrHist, mcHist, TString(Form("%s: step %d %s %s", name, step, corrected->GetStepTitle(step), corrected->GetRegionTitle(region))));
1875     }
1876   }
1877 }
1878
1879 void DrawRatios(void* correctedVoid, void* comparisonVoid, Int_t compareStep = -1, Int_t compareRegion = 2, Int_t compareUEHist = 0)
1880 {
1881   AliUEHistograms* corrected = (AliUEHistograms*) correctedVoid;
1882   AliUEHistograms* comparison = (AliUEHistograms*) comparisonVoid;
1883
1884   if (1 && compareUEHist == 2)
1885   {
1886     for (Float_t ptMin = 2.01; ptMin < 8; ptMin += 2)
1887     {
1888       ((AliUEHistograms*) corrected)->SetPtRange(ptMin, ptMin + 1.98);
1889       ((AliUEHistograms*) comparison)->SetPtRange(ptMin, ptMin + 1.98);
1890       
1891       DrawRatios(TString(Form("Dphi %d pT %f", compareUEHist, ptMin)), corrected->GetUEHist(compareUEHist), comparison->GetUEHist(compareUEHist), compareStep, compareRegion, 8.01, 19.99);      
1892     }
1893     return;
1894   }
1895
1896   if (compareUEHist == -1)
1897   {
1898     for (Int_t i=0; i<2; i++)
1899       DrawRatios(TString(Form("UE %d", i)), corrected->GetUEHist(i), comparison->GetUEHist(i), compareStep, compareRegion);
1900   }
1901   else
1902     DrawRatios(TString(Form("UE %d", compareUEHist)), corrected->GetUEHist(compareUEHist), comparison->GetUEHist(compareUEHist), compareStep, compareRegion);
1903 }
1904
1905 void CompareEventsTracks(void* corrVoid, void* mcVoid, Int_t compareStep, Int_t compareRegion, Int_t compareUEHist = 0)
1906 {
1907   AliUEHist* corr = ((AliUEHistograms*) corrVoid)->GetUEHist(compareUEHist);
1908   AliUEHist* mc   = ((AliUEHistograms*) mcVoid)->GetUEHist(compareUEHist);
1909
1910   Float_t ptLeadMin = 0;
1911   Float_t ptLeadMax = -1;
1912   Int_t axis = 2;
1913   
1914   if (compareUEHist == 2)
1915   {
1916     ptLeadMin = 1.01;
1917     ptLeadMax = 1.49;
1918     axis = 4;
1919   }
1920
1921   TH1* corrHist = corr->GetUEHist(compareStep, compareRegion, ptLeadMin, ptLeadMax);
1922   TH1* mcHist   = mc  ->GetUEHist(compareStep, compareRegion, ptLeadMin, ptLeadMax);
1923   
1924   DrawRatio(corrHist, mcHist, Form("check"));
1925   
1926   corr->SetBinLimits(corr->GetTrackHist(compareRegion)->GetGrid(compareStep));
1927   mc->SetBinLimits(corr->GetTrackHist(compareRegion)->GetGrid(compareStep));
1928
1929   corrHist =  corr->GetTrackHist(compareRegion)->GetGrid(compareStep)->Project(axis);
1930   mcHist   =  mc  ->GetTrackHist(compareRegion)->GetGrid(compareStep)->Project(axis);
1931   DrawRatio(corrHist, mcHist, Form("check2"));
1932   
1933   corrHist =  corr->GetEventHist()->GetGrid(compareStep)->Project(0);
1934   mcHist   =  mc  ->GetEventHist()->GetGrid(compareStep)->Project(0);
1935   DrawRatio(corrHist, mcHist, Form("check3"));
1936 }
1937
1938 void CopyReconstructedData(const char* fileName)
1939 {
1940   loadlibs();
1941   
1942   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
1943   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);  
1944
1945   // copy
1946   AliUEHistograms* onlyRec = (AliUEHistograms*) h->Clone();
1947   onlyRec->Reset();
1948   onlyRec->CopyReconstructedData(h);
1949   
1950   AliUEHistograms* onlyRecMixed = (AliUEHistograms*) hMixed->Clone();
1951   onlyRecMixed->Reset();
1952   onlyRecMixed->CopyReconstructedData(hMixed);
1953
1954   TString newFileName(fileName);
1955   newFileName.ReplaceAll(".root", "");
1956   newFileName += "_onlyreco.root";
1957
1958   list = new TList;
1959   list->Add(onlyRec);
1960   list->Add(onlyRecMixed);
1961
1962   file3 = TFile::Open(newFileName, "RECREATE");
1963   file3->mkdir("PWG4_PhiCorrelations");
1964   file3->cd("PWG4_PhiCorrelations");
1965   list->Write("histosPhiCorrelations", TObject::kSingleKey);
1966   file3->Close();  
1967 }
1968
1969 void correctMC(const char* fileNameCorrections, const char* fileNameESD = 0, Int_t compareStep = -1, Int_t compareRegion = 2, Int_t compareUEHist = 0)
1970 {
1971   // corrects the reconstructed step in fileNameESD with fileNameCorr
1972   // if fileNameESD is 0 data from fileNameCorr is taken
1973   // afterwards the corrected distributions are compared with the MC stored in fileNameESD
1974   
1975   loadlibs();
1976   
1977   AliUEHistograms* corr = (AliUEHistograms*) GetUEHistogram(fileNameCorrections);
1978   SetupRanges(corr);
1979   
1980   corr->ExtendTrackingEfficiency();
1981   
1982   AliUEHistograms* testSample = corr;
1983   if (fileNameESD)
1984     testSample = (AliUEHistograms*) GetUEHistogram(fileNameESD);
1985       
1986   // copy to esd object
1987   AliUEHistograms* esd = (AliUEHistograms*) corr->Clone();
1988   esd->Reset();
1989   esd->CopyReconstructedData(testSample);
1990   
1991   SetupRanges(corr);
1992   SetupRanges(testSample);
1993   SetupRanges(esd);
1994   
1995   esd->Correct(corr);
1996   
1997   list = new TList;
1998   list->Add(esd);
1999   
2000   file3 = TFile::Open("correctedMC.root", "RECREATE");
2001   file3->mkdir("PWG4_PhiCorrelations");
2002   file3->cd("PWG4_PhiCorrelations");
2003   list->Write("histosPhiCorrelations", TObject::kSingleKey);
2004   file3->Close();
2005   
2006   if (1)
2007     DrawRatios(esd, testSample, compareStep, compareRegion, compareUEHist);
2008   
2009   if (1)
2010   {
2011     esd->SetPtRange(2.01, 3.99);
2012     corrected = esd->GetUEHist(2)->GetUEHist(0, 0, 4.01, 7.99, 0, -1, 1);
2013     testSample->SetPtRange(2.01, 3.99);
2014     mc = testSample->GetUEHist(2)->GetUEHist(0, 0, 4.01, 7.99, 0, -1, 1);
2015     new TCanvas; corrected->DrawCopy("SURF1");
2016     new TCanvas; mc->DrawCopy("SURF1");
2017     new TCanvas; mc->DrawCopy("SURF1")->Divide(corrected);
2018   }
2019   
2020   //CompareEventsTracks(esd, testSample, compareStep, compareRegion, compareUEHist);
2021 }
2022
2023 // function to compare only final step for all regions and distributions
2024
2025 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)
2026 {
2027   // corrects fileNameESD with fileNameCorrections and compares the two
2028   
2029   loadlibs();
2030   
2031   AliUEHistograms* corr = (AliUEHistograms*) GetUEHistogram(fileNameCorrections);
2032   
2033   TList* list = 0;
2034   AliUEHistograms* esd = (AliUEHistograms*) GetUEHistogram(fileNameESD, &list);
2035   
2036   SetupRanges(corr);
2037   SetupRanges(esd);
2038   
2039   Float_t etaRange = 1.2;
2040   Printf(">>>>> Using eta range: |eta| < %f", etaRange);
2041   corr->SetEtaRange(-etaRange+0.01, etaRange-0.01);
2042   corr->ExtendTrackingEfficiency(0);
2043   
2044 //   corr->GetUEHist(2)->GetTrackEfficiency(AliUEHist::kCFStepTracked, AliUEHist::kCFStepTrackedOnlyPrim, 1, -1, 2);
2045 //   return;
2046   
2047   if (contEnhancement)
2048   {
2049     TFile::Open(contEnhancement);
2050     contEncHist = (TH1*) gFile->Get("histo");
2051     contEncHistFullRange = (TH1*) corr->GetUEHist(0)->GetTrackingEfficiency(1)->Clone("contEncHistFullRange");
2052     
2053     contEncHistFullRange->Reset();
2054     for (Int_t i=1; i<=contEncHistFullRange->GetNbinsX(); i++)
2055     {
2056       contEncHistFullRange->SetBinContent(i, 1);
2057       if (i <= contEncHist->GetNbinsX() && contEncHist->GetXaxis()->GetBinCenter(i) < contEncUpTo && contEncHist->GetBinContent(i) > 0)
2058         contEncHistFullRange->SetBinContent(i, contEncHist->GetBinContent(i));
2059     }
2060     corr->SetContaminationEnhancement((TH1F*) contEncHistFullRange);
2061   }
2062   
2063   esd->Correct(corr);
2064   //esd->GetUEHist(2)->AdditionalDPhiCorrection(0);
2065   
2066   file3 = TFile::Open("corrected.root", "RECREATE");
2067   file3->mkdir("PWG4_PhiCorrelations");
2068   file3->cd("PWG4_PhiCorrelations");
2069   list->Write("histosPhiCorrelations", TObject::kSingleKey);
2070   file3->Close();
2071   
2072 //   DrawRatios(esd, corr, compareStep, compareRegion, compareUEHist);
2073 }
2074
2075 void ITSTPCEfficiency(const char* fileNameData, Int_t id, Int_t itsTPC = 0)
2076 {
2077   // its = 0; tpc = 1
2078
2079   // uncertainty from dN/dpT paper
2080   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};
2081   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
2082   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
2083
2084   TH1F* effHist = new TH1F("effHist", "effHist", 39, pTBins);
2085   for (Int_t i=0; i<39; i++)
2086   {
2087     Int_t bin = i;
2088     if (i > 16)
2089       bin = 16;
2090     effHist->SetBinContent(i+1, (itsTPC == 0) ? effITS[bin] : effTPC[bin]);
2091   }
2092
2093   new TCanvas; effHist->Draw();
2094
2095   EffectOfModifiedTrackingEfficiency(fileNameData, id, 2, effHist, 1, -1, (itsTPC == 0) ? "ITS" : "TPC");
2096
2097
2098
2099 void EffectOfModifiedTrackingEfficiency(const char* fileNameData, Int_t id, Int_t region, TH1* trackingEff, Int_t axis1, Int_t axis2 = -1, const char* name = "EffectOfModifiedTrackingEfficiency")
2100 {
2101   // trackingEff should contain the change in tracking efficiency, i.e. between before and after in the eta-pT plane
2102
2103   loadlibs();
2104   
2105   AliUEHistograms* corrected = (AliUEHistograms*) GetUEHistogram(fileNameData);
2106   SetupRanges(corrected);
2107   
2108   AliUEHist* ueHist = corrected->GetUEHist(id);
2109   
2110   Float_t ptLeadMin = -1;
2111   Float_t ptLeadMax = -1;
2112   if (id == 2)
2113   {
2114     // the uncertainty is flat in delta phi, so use this trick to get directly the uncertainty as function of leading pT
2115     //ptLeadMin = 1.01;
2116     //ptLeadMax = 1.99;
2117   }
2118     
2119   // histogram before
2120   TH1* before = ueHist->GetUEHist(AliUEHist::kCFStepAll, region, ptLeadMin, ptLeadMax);
2121
2122   // copy histogram
2123   // the CFStepTriggered step is overwritten here and cannot be used for comparison afterwards anymore
2124   ueHist->CorrectTracks(AliUEHist::kCFStepAll, AliUEHist::kCFStepTriggered, (TH1*) 0, 0, -1);
2125
2126   // reapply tracking efficiency
2127   ueHist->CorrectTracks(AliUEHist::kCFStepTriggered, AliUEHist::kCFStepAll, trackingEff, axis1, axis2);
2128
2129   // histogram after
2130   TH1* after = ueHist->GetUEHist(AliUEHist::kCFStepAll, region, ptLeadMin, ptLeadMax);
2131   
2132   DrawRatio(before, after, name);
2133   gPad->GetCanvas()->SaveAs(Form("%s.png", name));
2134 }
2135
2136 void EffectOfTrackCuts(const char* fileNameData, Int_t id, const char* systFile)
2137 {
2138   loadlibs();
2139
2140   AliUEHistograms* corrected = (AliUEHistograms*) GetUEHistogram(fileNameData);
2141   effHist = (TH2D*) corrected->GetUEHist(0)->GetTrackingEfficiency()->Clone("effHist");
2142
2143   file = TFile::Open(systFile);
2144
2145   Int_t maxSyst = 3;
2146   const char* systNames[] = { "NClusTPC", "Chi2TPC", "SigmaDCA" };
2147
2148   for (Int_t i=0; i<maxSyst; i++)
2149   {
2150     for (Int_t j=0; j<2; j++)
2151     {
2152       TString histName;
2153       histName.Form("%s_syst_%s", systNames[i], (j == 0) ? "up" : "down");
2154       systEffect = (TH2*) file->Get(histName);
2155
2156       // rebin
2157       effHist->Reset();
2158       for (Int_t x=1; x <= effHist->GetNbinsX(); x++)
2159         for (Int_t y=1; y <= effHist->GetNbinsY(); y++)
2160           effHist->SetBinContent(x, y, 1);
2161
2162       for (Int_t x=1; x <= systEffect->GetNbinsX(); x++)
2163         for (Int_t y=1; y <= systEffect->GetNbinsY(); y++)
2164           if (systEffect->GetBinContent(x, y) != 0)
2165             effHist->SetBinContent(effHist->GetXaxis()->FindBin(systEffect->GetYaxis()->GetBinCenter(y)), effHist->GetYaxis()->FindBin(systEffect->GetXaxis()->GetBinCenter(x)), systEffect->GetBinContent(x, y));
2166            
2167    
2168       //new TCanvas; systEffect->Draw("COLZ"); new TCanvas; effHist->Draw("COLZ");
2169  
2170       EffectOfModifiedTrackingEfficiency(fileNameData, id, (id == 2) ? 0 : 2, effHist, 0, 1, histName);
2171
2172       //return;
2173     }
2174   } 
2175 }
2176
2177 void ModifyComposition(const char* fileNameData, const char* fileNameCorrections, Int_t id, Bool_t verbose = kFALSE)
2178 {
2179   loadlibs();
2180   
2181   AliUEHistograms* corrected = (AliUEHistograms*) GetUEHistogram(fileNameData);
2182   SetupRanges(corrected);
2183   
2184   AliUEHistograms* corrections = (AliUEHistograms*) GetUEHistogram(fileNameCorrections);
2185   SetupRanges(corrections);
2186   
2187   ueHistData        = (AliUEHist*) corrected->GetUEHist(id);
2188   ueHistCorrections = (AliUEHist*) corrections->GetUEHist(id);
2189   
2190   // copy histogram
2191   // the CFStepTriggered step is overwritten here and cannot be used for comparison afterwards anymore
2192   ueHistData->CorrectTracks(AliUEHist::kCFStepAll, AliUEHist::kCFStepTriggered, (TH1*) 0, 0);
2193   
2194   Int_t maxRegion = 3;
2195   Float_t ptLeadMin = -1;
2196   Float_t ptLeadMax = -1;
2197   if (id == 2)
2198   {
2199     maxRegion = 1;
2200     // the uncertainty is flat in delta phi, so use this trick to get directly the uncertainty as function of leading pT
2201     //ptLeadMin = 1.01;
2202     //ptLeadMax = 1.99;
2203   }
2204   
2205   // histogram before
2206   TH1* before[3];
2207   for (Int_t region=0; region<maxRegion; region++)
2208     before[region] = ueHistData->GetUEHist(AliUEHist::kCFStepAll, region, ptLeadMin, ptLeadMax);
2209   
2210   //defaultEff = ueHistCorrections->GetTrackingEfficiency();
2211   defaultEff = ueHistCorrections->GetTrackingCorrection();
2212   //defaultEffpT = ueHistCorrections->GetTrackingEfficiency(1);
2213   defaultEffpT = ueHistCorrections->GetTrackingCorrection(1);
2214   defaultContainer = ueHistCorrections->GetTrackHistEfficiency();
2215   
2216   c = new TCanvas;
2217   defaultEffpT->Draw("");
2218   
2219   Float_t largestDeviation[3];
2220   for (Int_t i=0; i<maxRegion; i++)
2221     largestDeviation[i] = 0;  
2222   
2223   for (Int_t i=0; i<7; i++)
2224   {
2225     // case 0: // default
2226     // case 1: // + 30% kaons
2227     // case 2: // - 30% kaons
2228     // case 3: // + 30% protons
2229     // case 4: // - 30% protons
2230     // case 5: // + 30% others
2231     // case 6: // - 30% others
2232     Int_t correctionIndex = (i+1) / 2 + 1; // bin 1 == protons, bin 2 == kaons, ...
2233     Double_t scaleFactor = (i % 2 == 1) ? 1.3 : 0.7;
2234     if (i == 0)
2235       scaleFactor = 1;
2236     
2237     newContainer = (AliCFContainer*) defaultContainer->Clone();
2238     
2239     // modify, change all steps
2240     for (Int_t j=0; j<newContainer->GetNStep(); j++)
2241     {
2242       THnSparse* grid = newContainer->GetGrid(j)->GetGrid();
2243       
2244       for (Int_t binIdx = 0; binIdx < grid->GetNbins(); binIdx++)
2245       {
2246         Int_t bins[5];
2247         Double_t value = grid->GetBinContent(binIdx, bins);
2248         Double_t error = grid->GetBinError(binIdx);
2249         
2250         if (bins[2] != correctionIndex)
2251           continue;
2252     
2253         value *= scaleFactor;
2254         error *= scaleFactor;
2255     
2256         grid->SetBinContent(bins, value);
2257         grid->SetBinError(bins, error);      
2258       }
2259     }
2260     
2261     // put in corrections
2262     ueHistCorrections->SetTrackHistEfficiency(newContainer);
2263     
2264     // ratio
2265     //modifiedEff = ueHistCorrections->GetTrackingEfficiency();
2266     modifiedEff = ueHistCorrections->GetTrackingCorrection();
2267     modifiedEff->Divide(modifiedEff, defaultEff);
2268     //modifiedEff->Draw("COLZ");
2269     
2270     c->cd();
2271     //modifiedEffpT = ueHistCorrections->GetTrackingEfficiency(1);
2272     modifiedEffpT = ueHistCorrections->GetTrackingCorrection(1);
2273     modifiedEffpT->SetLineColor(i+1);
2274     modifiedEffpT->Draw("SAME");
2275     
2276     // apply change in tracking efficiency
2277     ueHistData->CorrectTracks(AliUEHist::kCFStepTriggered, AliUEHist::kCFStepAll, modifiedEff, 0, 1);
2278   
2279     for (Int_t region=0; region<maxRegion; region++)
2280     {
2281       // histogram after
2282       TH1* after = ueHistData->GetUEHist(AliUEHist::kCFStepAll, region, ptLeadMin, ptLeadMax);
2283       
2284       if (verbose)
2285         DrawRatio(before[region], (TH1*) after->Clone(), Form("Region %d Composition %d", region, i));
2286       
2287       // ratio is flat, extract deviation
2288       after->Divide(before[region]);
2289       after->Fit("pol0", "0");
2290       Float_t deviation = 100.0 - 100.0 * after->GetFunction("pol0")->GetParameter(0);
2291       Printf("Deviation for region %d case %d is %.2f %%", region, i, deviation);
2292       
2293       if (TMath::Abs(deviation) > largestDeviation[region])
2294         largestDeviation[region] = TMath::Abs(deviation);
2295     }
2296     //return;
2297   }
2298   
2299   for (Int_t i=0; i<maxRegion; i++)
2300     Printf("Largest deviation in region %d is %f", i, largestDeviation[i]);
2301 }    
2302
2303 void MergeList(const char* prefix = "", const char* suffix = "", Bool_t copy = kFALSE)
2304 {
2305   loadlibs();
2306   gSystem->Load("libPWGflowBase");
2307   gSystem->Load("libPWGflowTasks");
2308
2309   ifstream in;
2310   in.open("list");
2311
2312   TFileMerger m(copy);
2313
2314   TString line;
2315   while (in.good())
2316   {
2317     in >> line;
2318
2319     if (line.Length() == 0)
2320       continue;
2321
2322     TString fileName;
2323     fileName.Form("%s%s%s", prefix, line.Data(), suffix);
2324 //     fileName.Form("alien://%s", line.Data());
2325     Printf("%s", fileName.Data());
2326     
2327     m.AddFile(fileName);
2328   }
2329   
2330   m.SetFastMethod();
2331   m.OutputFile("merged.root");
2332   m.Merge();
2333 }
2334
2335 void Merge2(const char* file1, const char* file2)
2336 {
2337   loadlibs();
2338   TFileMerger m(0);
2339
2340   m.AddFile(file1);
2341   m.AddFile(file2);
2342   
2343   m.SetFastMethod();
2344   m.OutputFile("merged.root");
2345   m.Merge();
2346 }
2347
2348 void Merge3(const char* file1, const char* file2, const char* file3)
2349 {
2350   loadlibs();
2351   TFileMerger m(1);
2352
2353   m.AddFile(file1);
2354   m.AddFile(file2);
2355   m.AddFile(file3);
2356   
2357   m.SetFastMethod();
2358   m.OutputFile("merged.root");
2359   m.Merge();
2360 }
2361
2362 void MergeList2(const char* listFile, const char* dir, Bool_t onlyPrintEvents = kFALSE, const char* targetDir = "PWG4_LeadingTrackUE")
2363 {
2364   loadlibs();
2365
2366   ifstream in;
2367   in.open(listFile);
2368   
2369   AliUEHistograms* final = 0;
2370   TList* finalList = 0;
2371
2372   TString line;
2373   while (in.good())
2374   {
2375     in >> line;
2376
2377     if (line.Length() == 0)
2378       continue;
2379
2380     TString fileName;
2381     fileName.Form("%s/%s/PWG4_JetTasksOutput.root", dir, line.Data());
2382     Printf("%s", fileName.Data());
2383     
2384     TList* list = 0;
2385     AliUEHistograms* obj = (AliUEHistograms*) GetUEHistogram(fileName, &list);
2386     if (!obj)
2387       continue;
2388     
2389     if (!final)
2390     {
2391       final = (AliUEHistograms*) obj;
2392       //final->GetEventCount()->Draw(); return;
2393       Printf("Events: %d", (Int_t) final->GetEventCount()->ProjectionX()->GetBinContent(4));
2394       finalList = list;
2395     }
2396     else
2397     {
2398       additional = (AliUEHistograms*) obj;
2399       Printf("Events: %d", (Int_t) additional->GetEventCount()->ProjectionX()->GetBinContent(4));
2400       
2401       if (!onlyPrintEvents)
2402       {
2403         TList list2;
2404         list2.Add(additional);
2405         final->Merge(&list2);
2406       }
2407       delete additional;
2408       gFile->Close();
2409     }
2410   }
2411   
2412   if (onlyPrintEvents)
2413     return;
2414     
2415   Printf("Total events (at step 0): %d", (Int_t) final->GetEventCount()->ProjectionX()->GetBinContent(4));
2416   
2417   file3 = TFile::Open("merged.root", "RECREATE");
2418   file3->mkdir(targetDir);
2419   file3->cd(targetDir);
2420   finalList->Write(0, TObject::kSingleKey);
2421   file3->Close();
2422 }
2423
2424 void PlotAll(const char* correctedFile, const char* mcFile)
2425 {
2426   gCache = 1;
2427   
2428   if (gEnergy == 900)
2429   {
2430     Float_t range[] = { 1.5, 2 };
2431   }
2432   else
2433   {
2434     Float_t range[] = { 3, 10 };
2435   }
2436   
2437   for (Int_t id=0; id<3; id++)
2438   {
2439     if (id < 2)
2440       gForceRange = range[id];
2441     else
2442       gForceRange = -1;
2443       
2444     if (id < 2)
2445     {
2446       for (Int_t region=0; region<3; region++)
2447       {
2448         CompareStep(correctedFile, mcFile, id, 0, region);
2449         gPad->GetCanvas()->SaveAs(Form("%s_%s_%d_%d.png", TString(correctedFile).Tokenize(".")->First()->GetName(), TString(mcFile).Tokenize(".")->First()->GetName(), id, region));
2450       }
2451     }
2452     else
2453     {
2454       Float_t leadingPtArr[] = { 0.50, 2.0, 4.0, 6.0, 10.0, 20.0, 50.0 };
2455       for (Int_t leadingPtID=0; leadingPtID<6; leadingPtID++)
2456       {
2457         CompareStep(correctedFile, mcFile, id, 0, 0, leadingPtArr[leadingPtID] + 0.01, leadingPtArr[leadingPtID+1] - 0.01);
2458         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]));
2459       }
2460     }
2461   }
2462 }
2463
2464 /*
2465 TGraph* GetFlow2040()
2466 {
2467   // from first ALICE flow paper (provided by Raimond)
2468   // http://www-library.desy.de/spires/find/hep/www?eprint=arXiv:1011.3914
2469   
2470   // centrality 20-30% 
2471   Double_t xCumulant4th2030ALICE[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
2472   1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000,
2473   5.500000,7.000000,9.000000};
2474   Double_t yCumulant4th2030ALICE[] = {0.000000,0.000000,0.030926,0.041076,0.052063,0.059429,0.070500,0.084461,0.086745,0.099254,
2475   0.109691,0.116398,0.130831,0.141959,0.158932,0.169680,0.171387,0.178858,0.171475,0.140358,
2476   0.000000,0.000000,0.000000};
2477   Double_t xErrCumulant4th2030ALICE[23] = {0.};
2478   Double_t yErrCumulant4th2030ALICE[] = {0.000000,0.000000,0.002857,0.003451,0.003567,0.003859,0.004609,0.004976,0.005412,0.006277,
2479   0.004748,0.005808,0.006896,0.007987,0.008683,0.008080,0.013278,0.018413,0.024873,0.026057,
2480   0.000000,0.000000,0.000000};
2481   Int_t nPointsCumulant4th2030ALICE = sizeof(xCumulant4th2030ALICE)/sizeof(Double_t);                                      
2482   TGraphErrors *Cumulant4th2030ALICE = new TGraphErrors(nPointsCumulant4th2030ALICE,xCumulant4th2030ALICE,yCumulant4th2030ALICE,
2483                                                         xErrCumulant4th2030ALICE,yErrCumulant4th2030ALICE);
2484   Cumulant4th2030ALICE->SetMarkerStyle(kFullSquare);
2485   Cumulant4th2030ALICE->SetMarkerColor(kRed);
2486   Cumulant4th2030ALICE->SetMarkerSize(1.2);
2487   Cumulant4th2030ALICE->SetFillStyle(1001);
2488   Cumulant4th2030ALICE->SetFillColor(kRed-10);
2489   
2490   //===================================================================================================================
2491   // centrality 30-40% 
2492   Double_t xCumulant4th3040ALICE[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
2493   1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000,
2494   5.500000,7.000000,9.000000};
2495   Double_t yCumulant4th3040ALICE[] = {0.000000,0.000000,0.037071,0.048566,0.061083,0.070910,0.078831,0.091396,0.102026,0.109691,
2496   0.124449,0.139819,0.155561,0.165701,0.173678,0.191149,0.202015,0.204540,0.212560,0.195885,
2497   0.000000,0.000000,0.000000};
2498   Double_t xErrCumulant4th3040ALICE[23] = {0.};
2499   Double_t yErrCumulant4th3040ALICE[] = {0.000000,0.000000,0.002992,0.003364,0.003669,0.003931,0.004698,0.005261,0.005446,0.006151,
2500   0.004980,0.005741,0.007198,0.008576,0.010868,0.009926,0.015269,0.020691,0.027601,0.031834,
2501   0.000000,0.000000,0.000000};
2502   Int_t nPointsCumulant4th3040ALICE = sizeof(xCumulant4th3040ALICE)/sizeof(Double_t);
2503   TGraphErrors *Cumulant4th3040ALICE = new TGraphErrors(nPointsCumulant4th3040ALICE,xCumulant4th3040ALICE,yCumulant4th3040ALICE,
2504                                                         xErrCumulant4th3040ALICE,yErrCumulant4th3040ALICE);
2505   Cumulant4th3040ALICE->SetMarkerStyle(kFullTriangleUp);
2506   Cumulant4th3040ALICE->SetMarkerColor(kGreen+2);
2507   Cumulant4th3040ALICE->SetMarkerSize(1.2);
2508   Cumulant4th3040ALICE->SetFillStyle(1001);
2509   Cumulant4th3040ALICE->SetFillColor(kGreen+2);
2510   
2511   // build average between the two (for class 20-40%)
2512   Double_t* yAverage = new Double_t[nPointsCumulant4th3040ALICE];
2513   for (Int_t i=0; i<nPointsCumulant4th3040ALICE; i++)
2514     yAverage[i] = (yCumulant4th2030ALICE[i] + yCumulant4th3040ALICE[i]) / 2;
2515     
2516   // assume flow constant above highest pT; not neccessarily physically sound ;)
2517   if (1)
2518   {
2519     yAverage[20] = yAverage[19];
2520     xCumulant4th3040ALICE[20] = 100;
2521     nPointsCumulant4th3040ALICE -= 2;
2522   }
2523   
2524   TGraph *flow2040 = new TGraph(nPointsCumulant4th3040ALICE,xCumulant4th3040ALICE,yAverage);
2525   
2526   if (0)
2527   {
2528     flow2040->Draw("*A");
2529     Cumulant4th2030ALICE->Draw("PSAME");
2530     Cumulant4th3040ALICE->Draw("PSAME");
2531   }
2532   
2533   return flow2040;
2534 }
2535 */
2536
2537 /*
2538 TGraph* GetFlow1020()
2539 {
2540   // from first ALICE flow paper (provided by Raimond)
2541   // http://www-library.desy.de/spires/find/hep/www?eprint=arXiv:1011.3914
2542   
2543   //===================================================================================================================
2544   // centrality 10-20% 
2545   Double_t xCumulant4th1020ALICE[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
2546   1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000,
2547   5.500000,7.000000,9.000000};
2548   Double_t yCumulant4th1020ALICE[] = {0.000000,0.000000,0.024075,0.031505,0.040413,0.044981,0.055358,0.060563,0.063378,0.070030,
2549   0.082692,0.091611,0.099641,0.107223,0.122376,0.131240,0.137425,0.146050,0.131365,0.124708,
2550   0.000000,0.000000,0.000000};
2551   Double_t xErrCumulant4th1020ALICE[23] = {0.};
2552   Double_t yErrCumulant4th1020ALICE[] = {0.000000,0.000000,0.002413,0.002931,0.003444,0.003950,0.004338,0.004835,0.005059,0.005586,
2553   0.004521,0.005278,0.005999,0.007072,0.008260,0.007279,0.011897,0.017409,0.023995,0.025701,
2554   0.000000,0.000000,0.000000};
2555   Int_t nPointsCumulant4th1020ALICE = sizeof(xCumulant4th1020ALICE)/sizeof(Double_t);                                      
2556   
2557   // assume flow constant above highest pT; not neccessarily physically sound ;)
2558   if (1)
2559   {
2560     yCumulant4th1020ALICE[20] = yCumulant4th1020ALICE[19];
2561     xCumulant4th1020ALICE[20] = 100;
2562     nPointsCumulant4th1020ALICE -= 2;
2563   }
2564   
2565   TGraphErrors *Cumulant4th1020ALICE = new TGraphErrors(nPointsCumulant4th1020ALICE,xCumulant4th1020ALICE,yCumulant4th1020ALICE,
2566                                                         xErrCumulant4th1020ALICE,yErrCumulant4th1020ALICE);
2567   
2568  Cumulant4th1020ALICE->SetMarkerStyle(kFullCircle);
2569  Cumulant4th1020ALICE->SetMarkerColor(kBlue);
2570  Cumulant4th1020ALICE->SetMarkerSize(1.2);
2571  Cumulant4th1020ALICE->SetFillStyle(1001);
2572  Cumulant4th1020ALICE->SetFillColor(kBlue-10);
2573   
2574   TGraph *flow1020 = new TGraph(nPointsCumulant4th1020ALICE,xCumulant4th1020ALICE,yCumulant4th1020ALICE);
2575   
2576   if (0)
2577   {
2578     flow1020->Draw("*A");
2579     Cumulant4th1020ALICE->Draw("PSAME");
2580   }
2581   
2582   return flow1020;
2583 }
2584 */
2585
2586 /*
2587 TGraph* GetFlow05()
2588 {
2589   // takes flow measurement from 10-20% and scales by a factor extracted from Fig.3 in the ALICE flow paper
2590   // factor = integrated flow in 0-5% / integrated flow in 10-20%
2591   
2592   graph = GetFlow1020();
2593   for (Int_t i=0; i<graph->GetN(); i++)
2594     graph->GetY()[i] *= 0.016 / 0.055;
2595     
2596   return graph;
2597 }
2598 */
2599 TGraphErrors* GetFlow01_Rap02(Int_t n)
2600 {
2601   // private communication 19.04.11, Raimond / Ante
2602
2603   if (n == 2)
2604   {
2605     //  v2{SP}(pt) for 0-1%, rapidity gap = 0.2:
2606     const Int_t nPointsSP_0001ALICE_v2_etaGap02 = 18;
2607     Double_t xSP_0001ALICE_v2_etaGap02[nPointsSP_0001ALICE_v2_etaGap02] = {0.250000,0.350000,0.450000,0.550000,0.650000,
2608     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};
2609     Double_t ySP_0001ALICE_v2_etaGap02[nPointsSP_0001ALICE_v2_etaGap02] = {0.009235,0.014105,0.017274,0.018245,0.023190,
2610     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};
2611     Double_t xErrSP_0001ALICE_v2_etaGap02[nPointsSP_0001ALICE_v2_etaGap02] = {0.};
2612     Double_t yErrSP_0001ALICE_v2_etaGap02[nPointsSP_0001ALICE_v2_etaGap02] = {0.000515,0.000504,0.000532,0.000585,0.000641,
2613     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};
2614     TGraphErrors *SP_0001ALICE_v2_etaGap02 = new TGraphErrors(nPointsSP_0001ALICE_v2_etaGap02,xSP_0001ALICE_v2_etaGap02,
2615                                                               ySP_0001ALICE_v2_etaGap02,xErrSP_0001ALICE_v2_etaGap02,yErrSP_0001ALICE_v2_etaGap02);
2616     SP_0001ALICE_v2_etaGap02->SetMarkerStyle(kFullCircle);
2617     SP_0001ALICE_v2_etaGap02->SetMarkerColor(kBlue);  
2618     SP_0001ALICE_v2_etaGap02->SetFillStyle(1001);
2619     SP_0001ALICE_v2_etaGap02->SetFillColor(kBlue-10);  
2620     
2621     return SP_0001ALICE_v2_etaGap02;
2622   }
2623   
2624   if (n == 3)
2625   {
2626     //  v3{SP}(pt) for 0-1%, rapidity gap = 0.2:
2627     const Int_t nPointsSP_0001ALICE_v3_etaGap02 = 18;
2628     Double_t xSP_0001ALICE_v3_etaGap02[nPointsSP_0001ALICE_v3_etaGap02] = {0.250000,0.350000,0.450000,0.550000,0.650000,
2629     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};
2630     Double_t ySP_0001ALICE_v3_etaGap02[nPointsSP_0001ALICE_v3_etaGap02] = {0.005688,0.007222,0.010305,0.013795,0.016077,
2631     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};
2632     Double_t xErrSP_0001ALICE_v3_etaGap02[nPointsSP_0001ALICE_v3_etaGap02] = {0.};
2633     Double_t yErrSP_0001ALICE_v3_etaGap02[nPointsSP_0001ALICE_v3_etaGap02] = {0.000585,0.000582,0.000614,0.000667,0.000734,
2634     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};
2635     TGraphErrors *SP_0001ALICE_v3_etaGap02 = new TGraphErrors(nPointsSP_0001ALICE_v3_etaGap02,xSP_0001ALICE_v3_etaGap02,ySP_0001ALICE_v3_etaGap02,
2636                                                               xErrSP_0001ALICE_v3_etaGap02,yErrSP_0001ALICE_v3_etaGap02);
2637     SP_0001ALICE_v3_etaGap02->SetMarkerStyle(kFullTriangleUp);
2638     SP_0001ALICE_v3_etaGap02->SetMarkerSize(1.4);  
2639     SP_0001ALICE_v3_etaGap02->SetMarkerColor(kGreen+2);
2640     SP_0001ALICE_v3_etaGap02->SetFillStyle(1001);
2641     SP_0001ALICE_v3_etaGap02->SetFillColor(kGreen-10);     
2642     
2643     return SP_0001ALICE_v3_etaGap02;
2644   }
2645    
2646   if (n == 4)
2647   {
2648     //  v4{SP}(pt) for 0-1%, rapidity gap = 0.2:
2649     const Int_t nPointsSP_0001ALICE_v4_etaGap02 = 18;
2650     Double_t xSP_0001ALICE_v4_etaGap02[nPointsSP_0001ALICE_v4_etaGap02] = {0.250000,0.350000,0.450000,0.550000,0.650000,
2651     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};
2652     Double_t ySP_0001ALICE_v4_etaGap02[nPointsSP_0001ALICE_v4_etaGap02] = {0.001189,0.003540,0.004682,0.004210,0.007032,
2653     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};
2654     Double_t xErrSP_0001ALICE_v4_etaGap02[nPointsSP_0001ALICE_v4_etaGap02] = {0.};
2655     Double_t yErrSP_0001ALICE_v4_etaGap02[nPointsSP_0001ALICE_v4_etaGap02] = {0.001035,0.001017,0.001081,0.001187,0.001299,
2656     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};
2657     TGraphErrors *SP_0001ALICE_v4_etaGap02 = new TGraphErrors(nPointsSP_0001ALICE_v4_etaGap02,xSP_0001ALICE_v4_etaGap02,ySP_0001ALICE_v4_etaGap02,
2658                                                               xErrSP_0001ALICE_v4_etaGap02,yErrSP_0001ALICE_v4_etaGap02);
2659     SP_0001ALICE_v4_etaGap02->SetMarkerStyle(kFullSquare);
2660     SP_0001ALICE_v4_etaGap02->SetMarkerColor(kRed);
2661     SP_0001ALICE_v4_etaGap02->SetFillStyle(1001);
2662     SP_0001ALICE_v4_etaGap02->SetFillColor(kRed-10);  
2663     
2664     return SP_0001ALICE_v4_etaGap02;
2665   }
2666   
2667   return 0;
2668 }
2669
2670 TGraphErrors* GetFlow01_Rap10(Int_t n)
2671 {
2672   if (n == 2)
2673   {
2674     //  v2{SP}(pt) for 0-1%, rapidity gap = 1.0:
2675     const Int_t nPointsSP_0001ALICE_v2_etaGap10 = 21;
2676     Double_t xSP_0001ALICE_v2_etaGap10[nPointsSP_0001ALICE_v2_etaGap10] = {0.250000,0.350000,0.450000,0.550000,0.650000,
2677     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,
2678     3.250000,3.750000,4.500000};
2679     Double_t ySP_0001ALICE_v2_etaGap10[nPointsSP_0001ALICE_v2_etaGap10] = {0.009129,0.013461,0.017567,0.018041,0.020384,
2680     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,
2681     0.036905,0.054836,0.030527};
2682     Double_t xErrSP_0001ALICE_v2_etaGap10[nPointsSP_0001ALICE_v2_etaGap10] = {0.};
2683     Double_t yErrSP_0001ALICE_v2_etaGap10[nPointsSP_0001ALICE_v2_etaGap10] = {0.001179,0.001152,0.001219,0.001339,0.001480,
2684     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,
2685     0.009145,0.014749,0.018698};
2686     TGraphErrors *SP_0001ALICE_v2_etaGap10 = new TGraphErrors(nPointsSP_0001ALICE_v2_etaGap10,xSP_0001ALICE_v2_etaGap10,
2687                                                               ySP_0001ALICE_v2_etaGap10,xErrSP_0001ALICE_v2_etaGap10,yErrSP_0001ALICE_v2_etaGap10);
2688     SP_0001ALICE_v2_etaGap10->SetMarkerStyle(kOpenCircle);
2689     SP_0001ALICE_v2_etaGap10->SetMarkerColor(kBlue);  
2690     SP_0001ALICE_v2_etaGap10->SetFillStyle(1001);
2691     SP_0001ALICE_v2_etaGap10->SetFillColor(kBlue-10);  
2692     
2693     return SP_0001ALICE_v2_etaGap10;
2694   }
2695
2696   if (n == 3)
2697   {
2698     //  v3{SP}(pt) for 0-1%, rapidity gap = 1.0:
2699     const Int_t nPointsSP_0001ALICE_v3_etaGap10 = 18;
2700     Double_t xSP_0001ALICE_v3_etaGap10[nPointsSP_0001ALICE_v3_etaGap10] = {0.250000,0.350000,0.450000,0.550000,0.650000,
2701     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};
2702     Double_t ySP_0001ALICE_v3_etaGap10[nPointsSP_0001ALICE_v3_etaGap10] = {0.006373,0.008403,0.010848,0.011505,0.016728,
2703     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};
2704     Double_t xErrSP_0001ALICE_v3_etaGap10[nPointsSP_0001ALICE_v3_etaGap10] = {0.};
2705     Double_t yErrSP_0001ALICE_v3_etaGap10[nPointsSP_0001ALICE_v3_etaGap10] = {0.001286,0.001269,0.001346,0.001474,0.001620,
2706     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};
2707     TGraphErrors *SP_0001ALICE_v3_etaGap10 = new TGraphErrors(nPointsSP_0001ALICE_v3_etaGap10,xSP_0001ALICE_v3_etaGap10,ySP_0001ALICE_v3_etaGap10,
2708                                                               xErrSP_0001ALICE_v3_etaGap10,yErrSP_0001ALICE_v3_etaGap10);
2709     SP_0001ALICE_v3_etaGap10->SetMarkerStyle(kOpenTriangleUp);
2710     SP_0001ALICE_v3_etaGap10->SetMarkerSize(1.2);  
2711     SP_0001ALICE_v3_etaGap10->SetMarkerColor(kGreen+2);
2712     SP_0001ALICE_v3_etaGap10->SetFillStyle(1001);
2713     SP_0001ALICE_v3_etaGap10->SetFillColor(kGreen-10);     
2714     
2715     return SP_0001ALICE_v3_etaGap10;
2716   }
2717
2718   if (n == 4)
2719   {
2720     //  v4{SP}(pt) for 0-1%, rapidity gap = 1.0:
2721     const Int_t nPointsSP_0001ALICE_v4_etaGap10 = 11;
2722     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};
2723     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};
2724     Double_t xErrSP_0001ALICE_v4_etaGap10[nPointsSP_0001ALICE_v4_etaGap10] = {0.};
2725     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};
2726     TGraphErrors *SP_0001ALICE_v4_etaGap10 = new TGraphErrors(nPointsSP_0001ALICE_v4_etaGap10,xSP_0001ALICE_v4_etaGap10,ySP_0001ALICE_v4_etaGap10,
2727                                                               xErrSP_0001ALICE_v4_etaGap10,yErrSP_0001ALICE_v4_etaGap10);
2728     SP_0001ALICE_v4_etaGap10->SetMarkerStyle(kOpenSquare);
2729     SP_0001ALICE_v4_etaGap10->SetMarkerColor(kRed);
2730     SP_0001ALICE_v4_etaGap10->SetFillStyle(1001);
2731     SP_0001ALICE_v4_etaGap10->SetFillColor(kRed-10);  
2732     
2733     return SP_0001ALICE_v4_etaGap10;
2734   }
2735   
2736   if (n == 5)
2737   {
2738     //  v5{SP}(pt) for 0-1%, rapidity gap = 1.0:
2739     const Int_t nPointsSP_0001ALICE_v5_etaGap10 = 11;
2740     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};
2741     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};
2742     Double_t xErrSP_0001ALICE_v5_etaGap10[nPointsSP_0001ALICE_v5_etaGap10] = {0.};
2743     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};
2744     TGraphErrors *SP_0001ALICE_v5_etaGap10 = new TGraphErrors(nPointsSP_0001ALICE_v5_etaGap10,xSP_0001ALICE_v5_etaGap10,ySP_0001ALICE_v5_etaGap10,
2745                                                               xErrSP_0001ALICE_v5_etaGap10,yErrSP_0001ALICE_v5_etaGap10);
2746     return SP_0001ALICE_v5_etaGap10;
2747   }
2748 }
2749
2750 TGraphErrors* GetFlow02_Rap10(Int_t n)
2751 {
2752   // private communication 20.04.11, Ante B. / Raimond
2753
2754   if (n == 2)
2755   {
2756      //  v2{SP}(pt) for 00-02%, eta gap = 1.0:
2757     const Int_t nPointsSP_0002_v2_etaGap10 = 15;
2758     Double_t xSP_0002_v2_etaGap10[nPointsSP_0002_v2_etaGap10] = {0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,
2759     0.900000,1.100000,1.350000,1.650000,1.950000,2.250000,2.700000,3.500000,4.500000};
2760     Double_t ySP_0002_v2_etaGap10[nPointsSP_0002_v2_etaGap10] = {0.010171,0.013190,0.017342,0.020629,0.022617,0.026549,
2761     0.027423,0.032261,0.037467,0.041001,0.045763,0.049327,0.049688,0.051480,0.038527};
2762     Double_t xErrSP_0002_v2_etaGap10[nPointsSP_0002_v2_etaGap10] = {0.};
2763     Double_t yErrSP_0002_v2_etaGap10[nPointsSP_0002_v2_etaGap10] = {0.000600,0.000590,0.000625,0.000683,0.000757,0.000839,
2764     0.000692,0.000848,0.000888,0.001209,0.001653,0.002252,0.002465,0.003968,0.009391};
2765     TGraphErrors *SP_0002_v2_etaGap10 = new TGraphErrors(nPointsSP_0002_v2_etaGap10,xSP_0002_v2_etaGap10,ySP_0002_v2_etaGap10,
2766                                                   xErrSP_0002_v2_etaGap10,yErrSP_0002_v2_etaGap10);
2767                                                   
2768     return SP_0002_v2_etaGap10;
2769   }
2770   
2771   if (n == 3)
2772   {
2773     const Int_t nPointsSP_0002_v3_etaGap10 = 15;
2774     Double_t xSP_0002_v3_etaGap10[nPointsSP_0002_v3_etaGap10] = {0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,
2775     0.900000,1.100000,1.350000,1.650000,1.950000,2.250000,2.700000,3.500000,4.500000};
2776     Double_t ySP_0002_v3_etaGap10[nPointsSP_0002_v3_etaGap10] = {0.006592,0.007286,0.012180,0.012242,0.017416,0.018393,
2777     0.024716,0.030980,0.037703,0.046558,0.051285,0.064613,0.074831,0.077093,0.082442};
2778     Double_t xErrSP_0002_v3_etaGap10[nPointsSP_0002_v3_etaGap10] = {0.};
2779     Double_t yErrSP_0002_v3_etaGap10[nPointsSP_0002_v3_etaGap10] = {0.000682,0.000676,0.000713,0.000782,0.000860,0.000953,
2780     0.000782,0.000957,0.001002,0.001361,0.001862,0.002541,0.002767,0.004466,0.010586};
2781     TGraphErrors *SP_0002_v3_etaGap10 = new TGraphErrors(nPointsSP_0002_v3_etaGap10,xSP_0002_v3_etaGap10,ySP_0002_v3_etaGap10,
2782                                                           xErrSP_0002_v3_etaGap10,yErrSP_0002_v3_etaGap10);    
2783                                                           
2784     return SP_0002_v3_etaGap10;
2785   }
2786   
2787   if (n == 4)
2788   {
2789     const Int_t nPointsSP_0002_v4_etaGap10 = 15;
2790     Double_t xSP_0002_v4_etaGap10[nPointsSP_0002_v4_etaGap10] = {0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,
2791     0.900000,1.100000,1.350000,1.650000,1.950000,2.250000,2.700000,3.500000,4.500000};
2792     Double_t ySP_0002_v4_etaGap10[nPointsSP_0002_v4_etaGap10] = {-0.000533,0.001167,0.002081,0.005218,0.006826,0.008440,
2793     0.013009,0.014812,0.017125,0.030106,0.038279,0.050488,0.067640,0.071637,0.084239};
2794     Double_t xErrSP_0002_v4_etaGap10[nPointsSP_0002_v4_etaGap10] = {0.};
2795     Double_t yErrSP_0002_v4_etaGap10[nPointsSP_0002_v4_etaGap10] = {0.001427,0.001398,0.001482,0.001594,0.001758,0.001945,
2796     0.001593,0.001951,0.002046,0.002787,0.003802,0.005182,0.005663,0.009064,0.021449};
2797     TGraphErrors *SP_0002_v4_etaGap10 = new TGraphErrors(nPointsSP_0002_v4_etaGap10,xSP_0002_v4_etaGap10,ySP_0002_v4_etaGap10,
2798                                                       xErrSP_0002_v4_etaGap10,yErrSP_0002_v4_etaGap10);
2799     return SP_0002_v4_etaGap10;
2800   }
2801   
2802   if (n == 5)
2803   {
2804     //  v5{SP}(pt) for 00-02%, eta gap = 0.2:
2805     const Int_t nPointsSP_0002_v5_etaGap02 = 13;
2806     Double_t xSP_0002_v5_etaGap02[nPointsSP_0002_v5_etaGap02] = {0.300000,0.500000,0.700000,0.900000,1.100000,1.300000,1.500000,
2807     1.700000,2.000000,2.550000,3.250000,3.950000,4.650000};
2808     Double_t ySP_0002_v5_etaGap02[nPointsSP_0002_v5_etaGap02] = {0.000570,0.002922,0.002151,0.005256,0.006287,0.005849,0.009399,
2809     0.011420,0.012455,0.032134,0.057009,0.020607,0.013551};
2810     Double_t xErrSP_0002_v5_etaGap02[nPointsSP_0002_v5_etaGap02] = {0.};
2811     Double_t yErrSP_0002_v5_etaGap02[nPointsSP_0002_v5_etaGap02] = {0.001074,0.001155,0.001433,0.001725,0.002123,0.002608,0.003196,
2812     0.003930,0.003755,0.004869,0.009719,0.018353,0.031814};
2813     TGraphErrors *SP_0002_v5_etaGap02 = new TGraphErrors(nPointsSP_0002_v5_etaGap02,xSP_0002_v5_etaGap02,ySP_0002_v5_etaGap02,
2814                                                           xErrSP_0002_v5_etaGap02,yErrSP_0002_v5_etaGap02);
2815     return SP_0002_v5_etaGap02;
2816   }
2817 }
2818
2819 TGraphErrors* GetFlow02(Int_t n)
2820 {
2821   // private communication 28.01.11, Ante B. / Raimond
2822
2823   if (n == 2)
2824   {
2825     // v2{2}(pt):
2826     Double_t xCumulant2nd0002ALICE_v2[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
2827     1.050000,1.150000,1.250000,1.350000,1.450000,1.550000,1.650000,1.750000,1.850000,1.950000,
2828     2.250000,2.750000,3.250000,3.750000,4.250000,4.750000,5.500000,6.500000,7.500000,8.500000,
2829     9.500000};
2830     Double_t yCumulant2nd0002ALICE_v2[] = {0.000000,0.000000,0.012173,0.015186,0.018580,0.021114,0.024646,0.027040,0.030269,0.032677,
2831     0.035332,0.037382,0.039228,0.040614,0.042460,0.044658,0.046246,0.050392,0.051436,0.054669,
2832     0.057330,0.063439,0.067425,0.060144,0.071260,0.070206,0.000000,0.000000,0.000000,0.000000,
2833     0.000000};
2834     Double_t xErrCumulant2nd0002ALICE_v2[31] = {0.};
2835     Double_t yErrCumulant2nd0002ALICE_v2[] = {0.000000,0.000000,0.000256,0.000259,0.000271,0.000296,0.000322,0.000357,0.000397,0.000438,
2836     0.000483,0.000529,0.000590,0.000639,0.000713,0.000793,0.000877,0.000976,0.001070,0.001197,
2837     0.000725,0.001265,0.002069,0.003156,0.004605,0.006543,0.000000,0.000000,0.000000,0.000000,
2838     0.000000};
2839     Int_t nPointsCumulant2nd0002ALICE_v2 = sizeof(xCumulant2nd0002ALICE_v2)/sizeof(Double_t);                                      
2840     TGraphErrors *Cumulant2nd0002ALICE_v2 = new TGraphErrors(nPointsCumulant2nd0002ALICE_v2,xCumulant2nd0002ALICE_v2,yCumulant2nd0002ALICE_v2,
2841                                                           xErrCumulant2nd0002ALICE_v2,yErrCumulant2nd0002ALICE_v2);
2842     Cumulant2nd0002ALICE_v2->SetMarkerStyle(kFullCircle);
2843     Cumulant2nd0002ALICE_v2->SetMarkerColor(kBlue);
2844     
2845     return Cumulant2nd0002ALICE_v2;
2846   }
2847   
2848   if (n == 3)
2849   {
2850     // v3{2}(pt):
2851     Double_t xCumulant2nd0002ALICE_v3[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
2852     1.050000,1.150000,1.250000,1.350000,1.450000,1.550000,1.650000,1.750000,1.850000,1.950000,
2853     2.250000,2.750000,3.250000,3.750000,4.250000,4.750000,5.500000,6.500000,7.500000,8.500000,
2854     9.500000};
2855     Double_t yCumulant2nd0002ALICE_v3[] = {0.000000,0.000000,0.007696,0.008994,0.010544,0.013269,0.016330,0.019234,0.023465,0.026803,
2856     0.029906,0.032211,0.035300,0.038158,0.041861,0.046002,0.049382,0.053574,0.055773,0.059420,
2857     0.069373,0.079922,0.090265,0.103583,0.111358,0.090740,0.000000,0.000000,0.000000,0.000000,
2858     0.000000};
2859     Double_t xErrCumulant2nd0002ALICE_v3[31] = {0.};
2860     Double_t yErrCumulant2nd0002ALICE_v3[] = {0.000000,0.000000,0.000318,0.000317,0.000333,0.000360,0.000392,0.000431,0.000476,0.000523,
2861     0.000575,0.000637,0.000707,0.000785,0.000878,0.000964,0.001064,0.001175,0.001320,0.001459,
2862     0.000889,0.001539,0.002530,0.003826,0.005614,0.007892,0.000000,0.000000,0.000000,0.000000,
2863     0.000000};
2864     Int_t nPointsCumulant2nd0002ALICE_v3 = sizeof(xCumulant2nd0002ALICE_v3)/sizeof(Double_t);                                      
2865     TGraphErrors *Cumulant2nd0002ALICE_v3 = new TGraphErrors(nPointsCumulant2nd0002ALICE_v3,xCumulant2nd0002ALICE_v3,yCumulant2nd0002ALICE_v3,
2866                                                           xErrCumulant2nd0002ALICE_v3,yErrCumulant2nd0002ALICE_v3);
2867     Cumulant2nd0002ALICE_v3->SetMarkerStyle(kFullTriangleUp);
2868     Cumulant2nd0002ALICE_v3->SetMarkerSize(1.2);
2869     Cumulant2nd0002ALICE_v3->SetMarkerColor(kGreen+2); 
2870     
2871     return Cumulant2nd0002ALICE_v3;
2872   }
2873   
2874   if (n == 4)
2875   {
2876     // v4{2}(pt):
2877     Double_t xCumulant2nd0002ALICE_v4[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
2878     1.050000,1.150000,1.250000,1.350000,1.450000,1.550000,1.650000,1.750000,1.850000,1.950000,
2879     2.250000,2.750000,3.250000,3.750000,4.250000,4.750000,5.500000,6.500000,7.500000,8.500000,
2880     9.500000};
2881     Double_t yCumulant2nd0002ALICE_v4[] = {0.000000,0.000000,0.005710,0.006014,0.004483,0.005453,0.007714,0.006837,0.009721,0.011288,
2882     0.012531,0.016461,0.016606,0.018587,0.022722,0.025497,0.025832,0.030994,0.030349,0.034730,
2883     0.045529,0.061153,0.074238,0.079307,0.088885,0.085218,0.000000,0.000000,0.000000,0.000000,
2884     0.000000};
2885     Double_t xErrCumulant2nd0002ALICE_v4[31] = {0.};
2886     Double_t yErrCumulant2nd0002ALICE_v4[] = {0.000000,0.000000,0.000488,0.000493,0.000523,0.000571,0.000609,0.000678,0.000742,0.000805,
2887     0.000903,0.000985,0.001100,0.001219,0.001352,0.001503,0.001682,0.001847,0.002060,0.002303,
2888     0.001400,0.002431,0.003974,0.006040,0.008901,0.012343,0.000000,0.000000,0.000000,0.000000,
2889     0.000000};
2890     Int_t nPointsCumulant2nd0002ALICE_v4 = sizeof(xCumulant2nd0002ALICE_v4)/sizeof(Double_t);                                      
2891     TGraphErrors *Cumulant2nd0002ALICE_v4 = new TGraphErrors(nPointsCumulant2nd0002ALICE_v4,xCumulant2nd0002ALICE_v4,yCumulant2nd0002ALICE_v4,
2892                                                           xErrCumulant2nd0002ALICE_v4,yErrCumulant2nd0002ALICE_v4);
2893     Cumulant2nd0002ALICE_v4->SetMarkerStyle(kFullSquare);
2894     Cumulant2nd0002ALICE_v4->SetMarkerColor(kRed);  
2895     
2896     return Cumulant2nd0002ALICE_v4;
2897   }
2898   
2899   return 0;
2900 }
2901
2902 /* results up to 5 GeV/c
2903
2904 TGraphErrors* GetFlow05(Int_t n)
2905 {
2906   // private communication 02.02.11, Ante B. / Raimond
2907
2908   if (n == 2)
2909   {
2910     // v2{2}(pt) for 0-5%:
2911     Double_t xCumulant2nd0005ALICE_v2[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
2912     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
2913     Double_t yCumulant2nd0005ALICE_v2[] = {0.000000,0.000000,0.013891,0.017693,0.021693,0.025323,0.029131,0.032443,0.035781,0.038256,
2914     0.042801,0.047705,0.053229,0.057387,0.062677,0.068815,0.077695,0.082058,0.082511,0.079791};
2915     Double_t xErrCumulant2nd0005ALICE_v2[20] = {0.};
2916     Double_t yErrCumulant2nd0005ALICE_v2[] = {0.000000,0.000000,0.000149,0.000150,0.000160,0.000174,0.000191,0.000211,0.000233,0.000257,
2917     0.000208,0.000254,0.000311,0.000377,0.000464,0.000419,0.000726,0.001180,0.001791,0.002131};
2918     Int_t nPointsCumulant2nd0005ALICE_v2 = sizeof(xCumulant2nd0005ALICE_v2)/sizeof(Double_t);                                      
2919     TGraphErrors *Cumulant2nd0005ALICE_v2 = new TGraphErrors(nPointsCumulant2nd0005ALICE_v2,xCumulant2nd0005ALICE_v2,yCumulant2nd0005ALICE_v2,
2920                                                           xErrCumulant2nd0005ALICE_v2,yErrCumulant2nd0005ALICE_v2);
2921     Cumulant2nd0005ALICE_v2->SetMarkerStyle(kFullCircle);
2922     Cumulant2nd0005ALICE_v2->SetMarkerColor(kBlue);    
2923     
2924     return Cumulant2nd0005ALICE_v2;
2925   }
2926   
2927   if (n == 3)
2928   {
2929     // v3{2}(pt) for 0-5%:
2930     Double_t xCumulant2nd0005ALICE_v3[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
2931     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
2932     Double_t yCumulant2nd0005ALICE_v3[] = {0.000000,0.000000,0.007788,0.009472,0.011596,0.014618,0.017540,0.021020,0.024946,0.028004,
2933     0.032330,0.039491,0.046368,0.053620,0.060662,0.071750,0.086746,0.097857,0.103111,0.104796};
2934     Double_t xErrCumulant2nd0005ALICE_v3[20] = {0.};
2935     Double_t yErrCumulant2nd0005ALICE_v3[] = {0.000000,0.000000,0.000194,0.000192,0.000204,0.000221,0.000241,0.000265,0.000293,0.000323,
2936     0.000266,0.000323,0.000397,0.000486,0.000601,0.000545,0.000947,0.001541,0.002328,0.002777};
2937     Int_t nPointsCumulant2nd0005ALICE_v3 = sizeof(xCumulant2nd0005ALICE_v3)/sizeof(Double_t);                                      
2938     TGraphErrors *Cumulant2nd0005ALICE_v3 = new TGraphErrors(nPointsCumulant2nd0005ALICE_v3,xCumulant2nd0005ALICE_v3,yCumulant2nd0005ALICE_v3,
2939                                                           xErrCumulant2nd0005ALICE_v3,yErrCumulant2nd0005ALICE_v3);
2940     Cumulant2nd0005ALICE_v3->SetMarkerStyle(kFullCircle);
2941     Cumulant2nd0005ALICE_v3->SetMarkerColor(kBlue);
2942
2943     return Cumulant2nd0005ALICE_v3;
2944   }
2945   
2946   if (n == 4)
2947   {
2948     // v4{2}(pt) for 0-5%:
2949     Double_t xCumulant2nd0005ALICE_v4[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
2950     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
2951     Double_t yCumulant2nd0005ALICE_v4[] = {0.000000,0.000000,0.006121,0.006137,0.005598,0.005956,0.007262,0.007991,0.009159,0.012062,
2952     0.015085,0.019225,0.024782,0.030092,0.035708,0.046542,0.060077,0.076088,0.082964,0.085405};
2953     Double_t xErrCumulant2nd0005ALICE_v4[20] = {0.};
2954     Double_t yErrCumulant2nd0005ALICE_v4[] = {0.000000,0.000000,0.000275,0.000278,0.000294,0.000319,0.000346,0.000380,0.000419,0.000459,
2955     0.000378,0.000460,0.000570,0.000700,0.000865,0.000789,0.001370,0.002227,0.003370,0.004018};
2956     Int_t nPointsCumulant2nd0005ALICE_v4 = sizeof(xCumulant2nd0005ALICE_v4)/sizeof(Double_t);                                      
2957     TGraphErrors *Cumulant2nd0005ALICE_v4 = new TGraphErrors(nPointsCumulant2nd0005ALICE_v4,xCumulant2nd0005ALICE_v4,yCumulant2nd0005ALICE_v4,
2958                                                           xErrCumulant2nd0005ALICE_v4,yErrCumulant2nd0005ALICE_v4);
2959     Cumulant2nd0005ALICE_v4->SetMarkerStyle(kFullCircle);
2960     Cumulant2nd0005ALICE_v4->SetMarkerColor(kBlue); 
2961     
2962     return Cumulant2nd0005ALICE_v4;
2963   }
2964   
2965   return 0;
2966 }
2967
2968 TGraphErrors* GetFlow510(Int_t n)
2969 {
2970   // private communication 02.02.11, Ante B. / Raimond
2971
2972   if (n == 2)
2973   {
2974     // v2{2}(pt) for 5-10%:
2975     Double_t xCumulant2nd0510ALICE_v2[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
2976     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
2977     Double_t yCumulant2nd0510ALICE_v2[] = {0.000000,0.000000,0.019872,0.026451,0.032901,0.039085,0.044930,0.050200,0.054887,0.060253,
2978     0.066587,0.075080,0.083303,0.090298,0.098782,0.109632,0.124486,0.129621,0.132076,0.120697};
2979     Double_t xErrCumulant2nd0510ALICE_v2[20] = {0.};
2980     Double_t yErrCumulant2nd0510ALICE_v2[] = {0.000000,0.000000,0.000150,0.000152,0.000163,0.000178,0.000196,0.000215,0.000237,0.000261,
2981     0.000213,0.000256,0.000313,0.000381,0.000468,0.000423,0.000727,0.001157,0.001741,0.002064};
2982     Int_t nPointsCumulant2nd0510ALICE_v2 = sizeof(xCumulant2nd0510ALICE_v2)/sizeof(Double_t);                                      
2983     TGraphErrors *Cumulant2nd0510ALICE_v2 = new TGraphErrors(nPointsCumulant2nd0510ALICE_v2,xCumulant2nd0510ALICE_v2,yCumulant2nd0510ALICE_v2,
2984                                                           xErrCumulant2nd0510ALICE_v2,yErrCumulant2nd0510ALICE_v2);
2985     Cumulant2nd0510ALICE_v2->SetMarkerStyle(kOpenCircle);
2986     Cumulant2nd0510ALICE_v2->SetMarkerColor(kBlue);   
2987      
2988     return Cumulant2nd0510ALICE_v2;
2989   }
2990   
2991   if (n == 3)
2992   {
2993     // v3{2}(pt) for 5-10%:
2994     Double_t xCumulant2nd0510ALICE_v3[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
2995     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
2996     Double_t yCumulant2nd0510ALICE_v3[] = {0.000000,0.000000,0.008596,0.010700,0.013820,0.017524,0.021507,0.024316,0.028491,0.032880,
2997     0.038741,0.045830,0.052486,0.059560,0.067990,0.081006,0.097402,0.107050,0.111743,0.116434};
2998     Double_t xErrCumulant2nd0510ALICE_v3[20] = {0.};
2999     Double_t yErrCumulant2nd0510ALICE_v3[] = {0.000000,0.000000,0.000208,0.000207,0.000218,0.000235,0.000258,0.000284,0.000314,0.000347,
3000     0.000285,0.000345,0.000426,0.000521,0.000642,0.000586,0.001008,0.001611,0.002421,0.002853};
3001     Int_t nPointsCumulant2nd0510ALICE_v3 = sizeof(xCumulant2nd0510ALICE_v3)/sizeof(Double_t);                                      
3002     TGraphErrors *Cumulant2nd0510ALICE_v3 = new TGraphErrors(nPointsCumulant2nd0510ALICE_v3,xCumulant2nd0510ALICE_v3,yCumulant2nd0510ALICE_v3,
3003                                                           xErrCumulant2nd0510ALICE_v3,yErrCumulant2nd0510ALICE_v3);
3004     Cumulant2nd0510ALICE_v3->SetMarkerStyle(kOpenCircle);
3005     Cumulant2nd0510ALICE_v3->SetMarkerColor(kBlue);
3006     
3007     return Cumulant2nd0510ALICE_v3;
3008   }
3009   
3010   if (n == 4)
3011   {
3012     // v4{2}(pt) for 5-10%:
3013     Double_t xCumulant2nd0510ALICE_v4[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3014     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
3015     Double_t yCumulant2nd0510ALICE_v4[] = {0.000000,0.000000,0.006466,0.006731,0.006344,0.007374,0.008775,0.010324,0.012323,0.014533,
3016     0.017261,0.022507,0.028776,0.035403,0.041936,0.051491,0.070340,0.080081,0.095077,0.088526};
3017     Double_t xErrCumulant2nd0510ALICE_v4[20] = {0.};
3018     Double_t yErrCumulant2nd0510ALICE_v4[] = {0.000000,0.000000,0.000292,0.000295,0.000312,0.000336,0.000366,0.000403,0.000443,0.000485,
3019     0.000399,0.000486,0.000603,0.000738,0.000914,0.000836,0.001443,0.002303,0.003448,0.004078};
3020     Int_t nPointsCumulant2nd0510ALICE_v4 = sizeof(xCumulant2nd0510ALICE_v4)/sizeof(Double_t);                                      
3021     TGraphErrors *Cumulant2nd0510ALICE_v4 = new TGraphErrors(nPointsCumulant2nd0510ALICE_v4,xCumulant2nd0510ALICE_v4,yCumulant2nd0510ALICE_v4,
3022                                                           xErrCumulant2nd0510ALICE_v4,yErrCumulant2nd0510ALICE_v4);
3023     Cumulant2nd0510ALICE_v4->SetMarkerStyle(kOpenCircle);
3024     Cumulant2nd0510ALICE_v4->SetMarkerColor(kBlue);    
3025     
3026     return Cumulant2nd0510ALICE_v4;
3027   }
3028   
3029   return 0;
3030 }
3031
3032 TGraphErrors* GetFlow1020(Int_t n)
3033 {
3034   // private communication 02.02.11, Ante B. / Raimond
3035
3036   if (n == 2)
3037   {
3038     // v2{2}(pt) for 10-20%:
3039     Double_t xCumulant2nd1020ALICE_v2[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3040     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
3041     Double_t yCumulant2nd1020ALICE_v2[] = {0.000000,0.000000,0.027683,0.037083,0.046511,0.055519,0.063979,0.071626,0.078537,0.085975,
3042     0.095001,0.106979,0.118456,0.129721,0.140641,0.155161,0.173402,0.179870,0.180616,0.168921};
3043     Double_t xErrCumulant2nd1020ALICE_v2[20] = {0.};
3044     Double_t yErrCumulant2nd1020ALICE_v2[] = {0.000000,0.000000,0.000121,0.000124,0.000134,0.000147,0.000163,0.000179,0.000198,0.000217,
3045     0.000177,0.000212,0.000257,0.000311,0.000380,0.000341,0.000569,0.000882,0.001309,0.001537};
3046     Int_t nPointsCumulant2nd1020ALICE_v2 = sizeof(xCumulant2nd1020ALICE_v2)/sizeof(Double_t);                                      
3047     TGraphErrors *Cumulant2nd1020ALICE_v2 = new TGraphErrors(nPointsCumulant2nd1020ALICE_v2,xCumulant2nd1020ALICE_v2,yCumulant2nd1020ALICE_v2,
3048                                                           xErrCumulant2nd1020ALICE_v2,yErrCumulant2nd1020ALICE_v2);
3049     Cumulant2nd1020ALICE_v2->SetMarkerStyle(kFullSquare);
3050     Cumulant2nd1020ALICE_v2->SetMarkerColor(kRed);     
3051     
3052     return Cumulant2nd1020ALICE_v2;
3053   }
3054   
3055   if (n == 3)
3056   {
3057     // v3{2}(pt) for 10-20%:
3058     Double_t xCumulant2nd1020ALICE_v3[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3059     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
3060     Double_t yCumulant2nd1020ALICE_v3[] = {0.000000,0.000000,0.009830,0.012858,0.016111,0.020120,0.023948,0.028349,0.032741,0.037244,
3061     0.043385,0.051803,0.059374,0.068686,0.076763,0.090151,0.106530,0.117448,0.121383,0.118247};
3062     Double_t xErrCumulant2nd1020ALICE_v3[20] = {0.};
3063     Double_t yErrCumulant2nd1020ALICE_v3[] = {0.000000,0.000000,0.000171,0.000170,0.000180,0.000195,0.000215,0.000236,0.000261,0.000287,
3064     0.000236,0.000288,0.000353,0.000434,0.000536,0.000488,0.000823,0.001277,0.001892,0.002224};
3065     Int_t nPointsCumulant2nd1020ALICE_v3 = sizeof(xCumulant2nd1020ALICE_v3)/sizeof(Double_t);                                      
3066     TGraphErrors *Cumulant2nd1020ALICE_v3 = new TGraphErrors(nPointsCumulant2nd1020ALICE_v3,xCumulant2nd1020ALICE_v3,yCumulant2nd1020ALICE_v3,
3067                                                           xErrCumulant2nd1020ALICE_v3,yErrCumulant2nd1020ALICE_v3);
3068     Cumulant2nd1020ALICE_v3->SetMarkerStyle(kFullSquare);
3069     Cumulant2nd1020ALICE_v3->SetMarkerColor(kRed); 
3070     
3071     return Cumulant2nd1020ALICE_v3;
3072   }
3073   
3074   if (n == 4)
3075   {
3076     // v4{2}(pt) for 10-20%:
3077     Double_t xCumulant2nd1020ALICE_v4[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3078     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
3079     Double_t yCumulant2nd1020ALICE_v4[] = {0.000000,0.000000,0.007423,0.007647,0.008189,0.008592,0.009489,0.011671,0.013739,0.017199,
3080     0.020084,0.026004,0.031843,0.038388,0.047357,0.057251,0.072433,0.086326,0.094282,0.097432};
3081     Double_t xErrCumulant2nd1020ALICE_v4[20] = {0.};
3082     Double_t yErrCumulant2nd1020ALICE_v4[] = {0.000000,0.000000,0.000243,0.000244,0.000257,0.000279,0.000306,0.000335,0.000368,0.000405,
3083     0.000333,0.000406,0.000502,0.000618,0.000770,0.000701,0.001185,0.001845,0.002730,0.003193};
3084     Int_t nPointsCumulant2nd1020ALICE_v4 = sizeof(xCumulant2nd1020ALICE_v4)/sizeof(Double_t);                                      
3085     TGraphErrors *Cumulant2nd1020ALICE_v4 = new TGraphErrors(nPointsCumulant2nd1020ALICE_v4,xCumulant2nd1020ALICE_v4,yCumulant2nd1020ALICE_v4,
3086                                                           xErrCumulant2nd1020ALICE_v4,yErrCumulant2nd1020ALICE_v4);
3087     Cumulant2nd1020ALICE_v4->SetMarkerStyle(kFullSquare);
3088     Cumulant2nd1020ALICE_v4->SetMarkerColor(kRed); 
3089         
3090     return Cumulant2nd1020ALICE_v4;
3091   }
3092   
3093   return 0;
3094 }
3095
3096 TGraphErrors* GetFlow2030(Int_t n)
3097 {
3098   // private communication 02.02.11, Ante B. / Raimond
3099
3100   if (n == 2)
3101   {
3102     Double_t xCumulant2nd2030ALICE_v2[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3103     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
3104     Double_t yCumulant2nd2030ALICE_v2[] = {0.000000,0.000000,0.035557,0.048064,0.060768,0.072585,0.083808,0.093772,0.103310,0.112602,
3105     0.124846,0.140603,0.155345,0.169450,0.183077,0.200173,0.219693,0.225741,0.223318,0.207356};
3106     Double_t xErrCumulant2nd2030ALICE_v2[20] = {0.};
3107     Double_t yErrCumulant2nd2030ALICE_v2[] = {0.000000,0.000000,0.000144,0.000147,0.000159,0.000175,0.000194,0.000214,0.000235,0.000259,
3108     0.000211,0.000254,0.000310,0.000377,0.000464,0.000418,0.000677,0.001027,0.001513,0.001761};
3109     Int_t nPointsCumulant2nd2030ALICE_v2 = sizeof(xCumulant2nd2030ALICE_v2)/sizeof(Double_t);                                      
3110     TGraphErrors *Cumulant2nd2030ALICE_v2 = new TGraphErrors(nPointsCumulant2nd2030ALICE_v2,xCumulant2nd2030ALICE_v2,yCumulant2nd2030ALICE_v2,
3111                                                           xErrCumulant2nd2030ALICE_v2,yErrCumulant2nd2030ALICE_v2);
3112     Cumulant2nd2030ALICE_v2->SetMarkerStyle(kOpenSquare);
3113     Cumulant2nd2030ALICE_v2->SetMarkerColor(kRed); 
3114         
3115     return Cumulant2nd2030ALICE_v2;
3116   }
3117   
3118   if (n == 3)
3119   {
3120     // v3{2}(pt) for 20-30%:
3121     Double_t xCumulant2nd2030ALICE_v3[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3122     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
3123     Double_t yCumulant2nd2030ALICE_v3[] = {0.000000,0.000000,0.011287,0.014937,0.018479,0.022962,0.027854,0.031938,0.037038,0.041443,
3124     0.049872,0.058720,0.068353,0.077692,0.087859,0.099863,0.116141,0.124486,0.124786,0.119520};
3125     Double_t xErrCumulant2nd2030ALICE_v3[20] = {0.};
3126     Double_t yErrCumulant2nd2030ALICE_v3[] = {0.000000,0.000000,0.000215,0.000216,0.000228,0.000248,0.000272,0.000300,0.000332,0.000366,
3127     0.000301,0.000369,0.000456,0.000561,0.000700,0.000636,0.001038,0.001574,0.002307,0.002676};
3128     Int_t nPointsCumulant2nd2030ALICE_v3 = sizeof(xCumulant2nd2030ALICE_v3)/sizeof(Double_t);                                      
3129     TGraphErrors *Cumulant2nd2030ALICE_v3 = new TGraphErrors(nPointsCumulant2nd2030ALICE_v3,xCumulant2nd2030ALICE_v3,yCumulant2nd2030ALICE_v3,
3130                                                           xErrCumulant2nd2030ALICE_v3,yErrCumulant2nd2030ALICE_v3);
3131     Cumulant2nd2030ALICE_v3->SetMarkerStyle(kOpenSquare);
3132     Cumulant2nd2030ALICE_v3->SetMarkerColor(kRed); 
3133     
3134     return Cumulant2nd2030ALICE_v3;
3135   }
3136   
3137   if (n == 4)
3138   {
3139     // v4{2}(pt) for 20-30%:
3140     Double_t xCumulant2nd2030ALICE_v4[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3141     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
3142     Double_t yCumulant2nd2030ALICE_v4[] = {0.000000,0.000000,0.008435,0.009824,0.009387,0.010408,0.011458,0.013770,0.016335,0.019165,
3143     0.023770,0.030071,0.036231,0.043950,0.051803,0.065222,0.082155,0.091864,0.105061,0.105167};
3144     Double_t xErrCumulant2nd2030ALICE_v4[20] = {0.};
3145     Double_t yErrCumulant2nd2030ALICE_v4[] = {0.000000,0.000000,0.000308,0.000308,0.000328,0.000355,0.000391,0.000430,0.000473,0.000524,
3146     0.000430,0.000524,0.000652,0.000807,0.001006,0.000919,0.001502,0.002277,0.003339,0.003871};
3147     Int_t nPointsCumulant2nd2030ALICE_v4 = sizeof(xCumulant2nd2030ALICE_v4)/sizeof(Double_t);                                      
3148     TGraphErrors *Cumulant2nd2030ALICE_v4 = new TGraphErrors(nPointsCumulant2nd2030ALICE_v4,xCumulant2nd2030ALICE_v4,yCumulant2nd2030ALICE_v4,
3149                                                           xErrCumulant2nd2030ALICE_v4,yErrCumulant2nd2030ALICE_v4);
3150     Cumulant2nd2030ALICE_v4->SetMarkerStyle(kOpenSquare);
3151     Cumulant2nd2030ALICE_v4->SetMarkerColor(kRed); 
3152         
3153     return Cumulant2nd2030ALICE_v4;
3154   }
3155   
3156   return 0;
3157 }
3158
3159 TGraphErrors* GetFlow3040(Int_t n)
3160 {
3161   // private communication 02.02.11, Ante B. / Raimond
3162
3163   if (n == 2)
3164   {
3165     // v2{2}(pt) for 30-40%:
3166     Double_t xCumulant2nd3040ALICE_v2[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3167     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
3168     Double_t yCumulant2nd3040ALICE_v2[] = {0.000000,0.000000,0.040797,0.055427,0.070543,0.084024,0.096562,0.109411,0.119853,0.130964,
3169     0.145377,0.163806,0.179825,0.196178,0.210377,0.226556,0.245686,0.247898,0.240058,0.225011};
3170     Double_t xErrCumulant2nd3040ALICE_v2[20] = {0.};
3171     Double_t yErrCumulant2nd3040ALICE_v2[] = {0.000000,0.000000,0.000177,0.000182,0.000197,0.000216,0.000239,0.000265,0.000293,0.000325,
3172     0.000266,0.000321,0.000395,0.000486,0.000603,0.000536,0.000840,0.001258,0.001843,0.002118};
3173     Int_t nPointsCumulant2nd3040ALICE_v2 = sizeof(xCumulant2nd3040ALICE_v2)/sizeof(Double_t);                                      
3174     TGraphErrors *Cumulant2nd3040ALICE_v2 = new TGraphErrors(nPointsCumulant2nd3040ALICE_v2,xCumulant2nd3040ALICE_v2,yCumulant2nd3040ALICE_v2,
3175                                                           xErrCumulant2nd3040ALICE_v2,yErrCumulant2nd3040ALICE_v2);
3176     Cumulant2nd3040ALICE_v2->SetMarkerStyle(kFullTriangleUp);
3177     Cumulant2nd3040ALICE_v2->SetMarkerSize(1.2);
3178     Cumulant2nd3040ALICE_v2->SetMarkerColor(kGreen+2);     
3179     
3180     return Cumulant2nd3040ALICE_v2;
3181   }
3182   
3183   if (n == 3)
3184   {
3185     // v3{2}(pt) for 30-40%:
3186     Double_t xCumulant2nd3040ALICE_v3[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3187     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
3188     Double_t yCumulant2nd3040ALICE_v3[] = {0.000000,0.000000,0.012226,0.016391,0.020792,0.026208,0.030380,0.035710,0.041025,0.047062,
3189     0.053075,0.064201,0.074116,0.085314,0.094391,0.106819,0.124012,0.129388,0.134315,0.132330};
3190     Double_t xErrCumulant2nd3040ALICE_v3[20] = {0.};
3191     Double_t yErrCumulant2nd3040ALICE_v3[] = {0.000000,0.000000,0.000284,0.000286,0.000303,0.000329,0.000364,0.000403,0.000443,0.000492,
3192     0.000408,0.000500,0.000627,0.000778,0.000973,0.000874,0.001375,0.002050,0.002992,0.003438};
3193     Int_t nPointsCumulant2nd3040ALICE_v3 = sizeof(xCumulant2nd3040ALICE_v3)/sizeof(Double_t);                                      
3194     TGraphErrors *Cumulant2nd3040ALICE_v3 = new TGraphErrors(nPointsCumulant2nd3040ALICE_v3,xCumulant2nd3040ALICE_v3,yCumulant2nd3040ALICE_v3,
3195                                                           xErrCumulant2nd3040ALICE_v3,yErrCumulant2nd3040ALICE_v3);
3196     Cumulant2nd3040ALICE_v3->SetMarkerStyle(kFullTriangleUp);
3197     Cumulant2nd3040ALICE_v3->SetMarkerSize(1.2);
3198     Cumulant2nd3040ALICE_v3->SetMarkerColor(kGreen+2); 
3199     
3200     return Cumulant2nd3040ALICE_v3;
3201   }
3202   
3203   if (n == 4)
3204   {
3205     // v4{2}(pt) for 30-40%:
3206     Double_t xCumulant2nd3040ALICE_v4[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3207     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
3208     Double_t yCumulant2nd3040ALICE_v4[] = {0.000000,0.000000,0.010718,0.011490,0.010994,0.012527,0.013748,0.016425,0.018857,0.021622,
3209     0.026853,0.034636,0.042651,0.049892,0.057795,0.070865,0.088486,0.101656,0.113886,0.118202};
3210     Double_t xErrCumulant2nd3040ALICE_v4[20] = {0.};
3211     Double_t yErrCumulant2nd3040ALICE_v4[] = {0.000000,0.000000,0.000401,0.000406,0.000433,0.000472,0.000521,0.000575,0.000634,0.000704,
3212     0.000580,0.000714,0.000890,0.001114,0.001398,0.001253,0.001974,0.002945,0.004290,0.004909};
3213     Int_t nPointsCumulant2nd3040ALICE_v4 = sizeof(xCumulant2nd3040ALICE_v4)/sizeof(Double_t);                                      
3214     TGraphErrors *Cumulant2nd3040ALICE_v4 = new TGraphErrors(nPointsCumulant2nd3040ALICE_v4,xCumulant2nd3040ALICE_v4,yCumulant2nd3040ALICE_v4,
3215                                                           xErrCumulant2nd3040ALICE_v4,yErrCumulant2nd3040ALICE_v4);
3216     Cumulant2nd3040ALICE_v4->SetMarkerStyle(kFullTriangleUp);
3217     Cumulant2nd3040ALICE_v4->SetMarkerSize(1.2);
3218     Cumulant2nd3040ALICE_v4->SetMarkerColor(kGreen+2); 
3219         
3220     return Cumulant2nd3040ALICE_v4;
3221   }
3222   
3223   return 0;
3224 }
3225
3226 TGraphErrors* GetFlow4050(Int_t n)
3227 {
3228   // private communication 02.02.11, Ante B. / Raimond
3229
3230   if (n == 2)
3231   {
3232     // v2{2}(pt) for 40-50%:
3233     Double_t xCumulant2nd4050ALICE_v2[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3234     1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.500000};
3235     Double_t yCumulant2nd4050ALICE_v2[] = {0.000000,0.000000,0.043593,0.059522,0.075558,0.090681,0.104453,0.117913,0.129349,0.141743,
3236     0.157076,0.176121,0.193651,0.208844,0.222402,0.238407,0.252512,0.253592,0.243571,0.233018};
3237     Double_t xErrCumulant2nd4050ALICE_v2[20] = {0.};
3238     Double_t yErrCumulant2nd4050ALICE_v2[] = {0.000000,0.000000,0.000234,0.000241,0.000261,0.000288,0.000322,0.000357,0.000395,0.000438,
3239     0.000362,0.000447,0.000555,0.000685,0.000846,0.000733,0.001121,0.001665,0.002433,0.002768};
3240     Int_t nPointsCumulant2nd4050ALICE_v2 = sizeof(xCumulant2nd4050ALICE_v2)/sizeof(Double_t);                                      
3241     TGraphErrors *Cumulant2nd4050ALICE_v2 = new TGraphErrors(nPointsCumulant2nd4050ALICE_v2,xCumulant2nd4050ALICE_v2,yCumulant2nd4050ALICE_v2,
3242                                                           xErrCumulant2nd4050ALICE_v2,yErrCumulant2nd4050ALICE_v2);
3243     Cumulant2nd4050ALICE_v2->SetMarkerStyle(kOpenTriangleUp);
3244     Cumulant2nd4050ALICE_v2->SetMarkerSize(1.2);
3245     Cumulant2nd4050ALICE_v2->SetMarkerColor(kGreen+2);      
3246     
3247     return Cumulant2nd4050ALICE_v2;
3248   }
3249   
3250   return 0;
3251 }
3252 */
3253
3254 // results up to high pT
3255
3256 TGraphErrors* GetFlow05(Int_t n)
3257 {
3258   // private communication 09.03.11, Ante B. / Raimond
3259
3260   if (n == 2)
3261   {
3262     // v2{2}(pt) for 0-5%:
3263     Double_t xCumulant2nd0005ALICE[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3264     1.050000,1.150000,1.250000,1.350000,1.450000,1.550000,1.650000,1.750000,1.850000,1.950000,
3265     2.100000,2.300000,2.500000,2.700000,2.900000,3.200000,3.600000,4.000000,4.400000,4.800000,
3266     5.500000,6.500000,7.500000,8.500000,9.500000,11.250000,13.750000,16.250000,18.750000,60.000000};
3267     Double_t yCumulant2nd0005ALICE[] = {0.000000,0.000000,0.018169,0.020988,0.024899,0.028309,0.031974,0.035188,0.038218,0.041202,
3268     0.043910,0.046560,0.048183,0.050640,0.052874,0.055334,0.056948,0.059427,0.061540,0.063218,
3269     0.065452,0.069222,0.072578,0.074723,0.077749,0.077178,0.080514,0.075325,0.077692,0.079710,
3270     0.073280,0.063849,0.068274,0.066045,0.071496,0.104352,0.091646,0.050220,0.124185,0.088535};
3271     Double_t xErrCumulant2nd0005ALICE[40] = {0.};
3272     Double_t yErrCumulant2nd0005ALICE[] = {0.000000,0.000000,0.000190,0.000191,0.000199,0.000212,0.000230,0.000248,0.000268,0.000293,
3273     0.000319,0.000346,0.000379,0.000418,0.000459,0.000502,0.000554,0.000614,0.000674,0.000749,
3274     0.000620,0.000769,0.000958,0.001182,0.001446,0.001331,0.001858,0.002552,0.003453,0.004606,
3275     0.004289,0.007006,0.010046,0.013853,0.017709,0.016630,0.025728,0.036763,0.045056,0.029011};
3276     Int_t nPointsCumulant2nd0005ALICE = sizeof(xCumulant2nd0005ALICE)/sizeof(Double_t);                                      
3277     TGraphErrors *Cumulant2nd0005ALICE = new TGraphErrors(nPointsCumulant2nd0005ALICE,xCumulant2nd0005ALICE,yCumulant2nd0005ALICE,
3278                                                           xErrCumulant2nd0005ALICE,yErrCumulant2nd0005ALICE);
3279     Cumulant2nd0005ALICE->SetMarkerStyle(kFullCircle);
3280     Cumulant2nd0005ALICE->SetMarkerColor(kBlue);
3281     
3282     return Cumulant2nd0005ALICE;
3283   }
3284   
3285   if (n == 3)
3286   {
3287   }
3288   
3289   if (n == 4)
3290   {
3291   }
3292   
3293   return 0;
3294 }
3295
3296 TGraphErrors* GetFlow05_Rap10(Int_t n)
3297 {
3298   // private communication 17.05.11, Ante B. / should correspond to machcone paper draft 
3299
3300   if (n == 2)
3301   {
3302     //  v2{SP}(pt) for 00-05%:
3303     const Int_t nPointsSP_0005ALICE_v2_etaGap10 = 17;
3304     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,
3305         1.300000,1.500000,1.700000,1.900000,2.200000,2.600000,3.000000,3.650000,4.550000};
3306     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,
3307         0.043103,0.046626,0.052386,0.057132,0.060070,0.068419,0.061459,0.056816,0.050311};
3308     Double_t xErrSP_0005ALICE_v2_etaGap10[nPointsSP_0005ALICE_v2_etaGap10] = {0.};
3309     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,
3310         0.001410,0.001736,0.002131,0.002620,0.002502,0.003759,0.005615,0.006617,0.014242};
3311     TGraphErrors *GrSP_0005ALICE_v2_etaGap10 = new TGraphErrors(nPointsSP_0005ALICE_v2_etaGap10,xSP_0005ALICE_v2_etaGap10,ySP_0005ALICE_v2_etaGap10,
3312                                                               xErrSP_0005ALICE_v2_etaGap10,yErrSP_0005ALICE_v2_etaGap10);
3313                                                               
3314     return GrSP_0005ALICE_v2_etaGap10;
3315   }
3316   
3317   if (n == 3)
3318   {
3319     //  v3{SP}(pt) for 00-05%:
3320     const Int_t nPointsSP_0005ALICE_v3_etaGap10 = 16;
3321     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,
3322         1.300000,1.500000,1.700000,1.900000,2.300000,2.900000,3.650000,4.550000};
3323     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,
3324         0.038730,0.045653,0.052469,0.062303,0.071522,0.082223,0.083373,0.076951};
3325     Double_t xErrSP_0005ALICE_v3_etaGap10[nPointsSP_0005ALICE_v3_etaGap10] = {0.};
3326     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,
3327         0.001734,0.002124,0.002610,0.003206,0.002724,0.004977,0.008123,0.017180};
3328     TGraphErrors *GrSP_0005ALICE_v3_etaGap10 = new TGraphErrors(nPointsSP_0005ALICE_v3_etaGap10,xSP_0005ALICE_v3_etaGap10,ySP_0005ALICE_v3_etaGap10,
3329                                                               xErrSP_0005ALICE_v3_etaGap10,yErrSP_0005ALICE_v3_etaGap10);
3330
3331                                                               
3332     return GrSP_0005ALICE_v3_etaGap10;
3333   }
3334   
3335   if (n == 4)
3336   {
3337     //  v4{SP}(pt) for 00-05%:
3338     const Int_t nPointsSP_0005ALICE_v4_etaGap10 = 11;
3339     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};
3340     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,
3341         0.095985,0.094607};
3342     Double_t xErrSP_0005ALICE_v4_etaGap10[nPointsSP_0005ALICE_v4_etaGap10] = {0.};
3343     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,
3344         0.016472,0.035083};
3345     TGraphErrors *GrSP_0005ALICE_v4_etaGap10 = new TGraphErrors(nPointsSP_0005ALICE_v4_etaGap10,xSP_0005ALICE_v4_etaGap10,ySP_0005ALICE_v4_etaGap10,
3346                                                               xErrSP_0005ALICE_v4_etaGap10,yErrSP_0005ALICE_v4_etaGap10);
3347    
3348     return GrSP_0005ALICE_v4_etaGap10;
3349   }
3350   
3351   if (n == 5)
3352   {
3353     //  v5{SP}(pt) for 00-05%:
3354     const Int_t nPointsSP_0005ALICE_v5_etaGap10 = 12;
3355     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,
3356         2.800000,3.500000,4.500000};
3357     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,
3358         0.031373,0.068504,0.017964};
3359     Double_t xErrSP_0005ALICE_v5_etaGap10[nPointsSP_0005ALICE_v5_etaGap10] = {0.};
3360     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,
3361         0.010073,0.011899,0.027756};
3362     TGraphErrors *GrSP_0005ALICE_v5_etaGap10 = new TGraphErrors(nPointsSP_0005ALICE_v5_etaGap10,xSP_0005ALICE_v5_etaGap10,ySP_0005ALICE_v5_etaGap10,
3363                                                               xErrSP_0005ALICE_v5_etaGap10,yErrSP_0005ALICE_v5_etaGap10);
3364     
3365     return GrSP_0005ALICE_v5_etaGap10;
3366   }
3367   
3368   return 0;
3369 }
3370
3371 TGraphErrors* GetFlow510(Int_t n)
3372 {
3373   // private communication 09.03.11, Ante B. / Raimond
3374
3375   if (n == 2)
3376   {
3377     // v2{2}(pt) for 5-10%:
3378     Double_t xCumulant2nd0510ALICE[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3379     1.050000,1.150000,1.250000,1.350000,1.450000,1.550000,1.650000,1.750000,1.850000,1.950000,
3380     2.100000,2.300000,2.500000,2.700000,2.900000,3.200000,3.600000,4.000000,4.400000,4.800000,
3381     5.500000,6.500000,7.500000,8.500000,9.500000,11.250000,13.750000,16.250000,18.750000,60.000000};
3382     Double_t yCumulant2nd0510ALICE[] = {0.000000,0.000000,0.022354,0.028064,0.034341,0.040769,0.046265,0.051160,0.056712,0.061354,
3383     0.066290,0.070340,0.074453,0.078444,0.082367,0.085785,0.088086,0.092676,0.096169,0.100366,
3384     0.104227,0.109710,0.117032,0.121784,0.122227,0.126537,0.127966,0.117790,0.117884,0.111436,
3385     0.104945,0.097640,0.086481,0.091663,0.091404,0.080132,0.015864,0.101500,0.033347,0.205130};
3386     Double_t xErrCumulant2nd0510ALICE[40] = {0.};
3387     Double_t yErrCumulant2nd0510ALICE[] = {0.000000,0.000000,0.000173,0.000176,0.000186,0.000199,0.000219,0.000236,0.000260,0.000283,
3388     0.000312,0.000340,0.000373,0.000410,0.000454,0.000501,0.000552,0.000610,0.000675,0.000753,
3389     0.000620,0.000774,0.000961,0.001183,0.001431,0.001309,0.001814,0.002481,0.003342,0.004379,
3390     0.004122,0.006716,0.009851,0.013626,0.017517,0.015790,0.025680,0.038041,0.054144,0.038987};
3391     Int_t nPointsCumulant2nd0510ALICE = sizeof(xCumulant2nd0510ALICE)/sizeof(Double_t);                                      
3392     TGraphErrors *Cumulant2nd0510ALICE = new TGraphErrors(nPointsCumulant2nd0510ALICE,xCumulant2nd0510ALICE,yCumulant2nd0510ALICE,
3393                                                           xErrCumulant2nd0510ALICE,yErrCumulant2nd0510ALICE);
3394     Cumulant2nd0510ALICE->SetMarkerStyle(kOpenCircle);
3395     Cumulant2nd0510ALICE->SetMarkerColor(kBlue);
3396     
3397     return Cumulant2nd0510ALICE;
3398   }
3399   
3400   if (n == 3)
3401   {
3402   }
3403   
3404   if (n == 4)
3405   {
3406   }
3407   
3408   return 0;
3409 }
3410
3411 TGraphErrors* GetFlow510_Rap10(Int_t n)
3412 {
3413   // private communication 18.05.11, Ante B.
3414
3415   if (n == 2)
3416   {
3417     //  v2{SP}(pt) for 05-10%, rapidity gap = 1.0:
3418     const Int_t nPointsSP_0510ALICE_v2_etaGap10 = 19;
3419     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,
3420 1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.250000,
3421 4.750000};
3422     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,
3423 0.066516,0.073891,0.080945,0.090386,0.094505,0.106393,0.120303,0.122586,0.121731,0.107343,
3424 0.104059};
3425     Double_t xErrSP_0510ALICE_v2_etaGap10[nPointsSP_0510ALICE_v2_etaGap10] = {0.};
3426     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,
3427 0.000586,0.000717,0.000880,0.001082,0.001333,0.001189,0.001969,0.003199,0.005011,0.007602,
3428 0.010906};
3429     TGraphErrors *GrSP_0510ALICE_v2_etaGap10 = new TGraphErrors(nPointsSP_0510ALICE_v2_etaGap10,xSP_0510ALICE_v2_etaGap10,
3430                                                               ySP_0510ALICE_v2_etaGap10,xErrSP_0510ALICE_v2_etaGap10,
3431                                                               yErrSP_0510ALICE_v2_etaGap10);
3432
3433     return GrSP_0510ALICE_v2_etaGap10;
3434   }
3435   
3436   return 0;
3437 }
3438
3439 TGraphErrors* GetFlow1020(Int_t n)
3440 {
3441   // private communication 09.03.11, Ante B. / Raimond
3442
3443   if (n == 2)
3444   {
3445     // v2{2}(pt) for 10-20%:
3446     Double_t xCumulant2nd1020ALICE[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3447     1.050000,1.150000,1.250000,1.350000,1.450000,1.550000,1.650000,1.750000,1.850000,1.950000,
3448     2.100000,2.300000,2.500000,2.700000,2.900000,3.200000,3.600000,4.000000,4.400000,4.800000,
3449     5.500000,6.500000,7.500000,8.500000,9.500000,11.250000,13.750000,16.250000,18.750000,60.000000};
3450     Double_t yCumulant2nd1020ALICE[] = {0.000000,0.000000,0.028508,0.037698,0.046914,0.055750,0.063948,0.072298,0.079396,0.086829,
3451     0.093382,0.099676,0.105412,0.110792,0.116715,0.122327,0.127079,0.132302,0.137183,0.142346,
3452     0.149059,0.156729,0.164672,0.171840,0.175346,0.176824,0.178878,0.174979,0.169229,0.153109,
3453     0.139676,0.125686,0.120554,0.096537,0.084736,0.118152,0.116079,0.060032,0.093764,0.206506};
3454     Double_t xErrCumulant2nd1020ALICE[40] = {0.};
3455     Double_t yErrCumulant2nd1020ALICE[] = {0.000000,0.000000,0.000134,0.000136,0.000145,0.000158,0.000173,0.000190,0.000209,0.000229,
3456     0.000252,0.000275,0.000301,0.000331,0.000365,0.000401,0.000442,0.000488,0.000541,0.000599,
3457     0.000496,0.000614,0.000757,0.000915,0.001095,0.000989,0.001360,0.001847,0.002477,0.003234,
3458     0.003012,0.004867,0.007123,0.009774,0.012740,0.011682,0.019629,0.028568,0.039931,0.024776};
3459     Int_t nPointsCumulant2nd1020ALICE = sizeof(xCumulant2nd1020ALICE)/sizeof(Double_t);                                      
3460     TGraphErrors *Cumulant2nd1020ALICE = new TGraphErrors(nPointsCumulant2nd1020ALICE,xCumulant2nd1020ALICE,yCumulant2nd1020ALICE,
3461                                                           xErrCumulant2nd1020ALICE,yErrCumulant2nd1020ALICE);
3462     Cumulant2nd1020ALICE->SetMarkerStyle(kFullSquare);
3463     Cumulant2nd1020ALICE->SetMarkerColor(kRed); 
3464     
3465     return Cumulant2nd1020ALICE;
3466   }
3467   
3468   if (n == 3)
3469   {
3470   }
3471   
3472   if (n == 4)
3473   {
3474   }
3475   
3476   return 0;
3477 }
3478
3479 TGraphErrors* GetFlow1020_Rap10(Int_t n)
3480 {
3481   // private communication 18.05.11, Ante B.
3482
3483   if (n == 2)
3484   {
3485    //  v2{SP}(pt) for 10-20%, rapidity gap = 1.0:
3486     const Int_t nPointsSP_1020ALICE_v2_etaGap10 = 19;
3487     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,
3488 1.100000,1.300000,1.500000,1.700000,1.900000,2.250000,2.750000,3.250000,3.750000,4.250000,
3489 4.750000};
3490     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,
3491 0.094701,0.105631,0.117906,0.128147,0.138505,0.153494,0.166651,0.172691,0.177337,0.155068,
3492 0.131586};
3493     Double_t xErrSP_1020ALICE_v2_etaGap10[nPointsSP_1020ALICE_v2_etaGap10] = {0.};
3494     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,
3495 0.000423,0.000517,0.000634,0.000779,0.000959,0.000856,0.001406,0.002266,0.003528,0.005281,
3496 0.007561};
3497     TGraphErrors *GrSP_1020ALICE_v2_etaGap10 = new TGraphErrors(nPointsSP_1020ALICE_v2_etaGap10,xSP_1020ALICE_v2_etaGap10,
3498                                                               ySP_1020ALICE_v2_etaGap10,xErrSP_1020ALICE_v2_etaGap10,
3499                                                               yErrSP_1020ALICE_v2_etaGap10);
3500
3501     return GrSP_1020ALICE_v2_etaGap10;
3502   }
3503   
3504   return 0;
3505 }
3506     
3507 TGraphErrors* GetFlow2030(Int_t n)
3508 {
3509   // private communication 09.03.11, Ante B. / Raimond
3510
3511   if (n == 2)
3512   {
3513     // v2{2}(pt) for 20-30%:
3514     Double_t xCumulant2nd2030ALICE[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3515     1.050000,1.150000,1.250000,1.350000,1.450000,1.550000,1.650000,1.750000,1.850000,1.950000,
3516     2.100000,2.300000,2.500000,2.700000,2.900000,3.200000,3.600000,4.000000,4.400000,4.800000,
3517     5.500000,6.500000,7.500000,8.500000,9.500000,11.250000,13.750000,16.250000,18.750000,60.000000};
3518     Double_t yCumulant2nd2030ALICE[] = {0.000000,0.000000,0.035366,0.047465,0.060083,0.072090,0.083418,0.093576,0.103842,0.113110,
3519     0.122193,0.130168,0.138158,0.145627,0.152851,0.159129,0.166073,0.173144,0.178698,0.186188,
3520     0.192045,0.202199,0.210535,0.215004,0.220457,0.223339,0.224050,0.211567,0.203955,0.189716,
3521     0.165994,0.147185,0.131953,0.139331,0.151293,0.127406,0.153764,0.089628,0.161247,0.511418};
3522     Double_t xErrCumulant2nd2030ALICE[40] = {0.};
3523     Double_t yErrCumulant2nd2030ALICE[] = {0.000000,0.000000,0.000155,0.000157,0.000169,0.000184,0.000202,0.000222,0.000244,0.000269,
3524     0.000296,0.000325,0.000357,0.000394,0.000435,0.000481,0.000532,0.000589,0.000655,0.000731,
3525     0.000605,0.000743,0.000904,0.001081,0.001277,0.001145,0.001568,0.002119,0.002806,0.003635,
3526     0.003383,0.005346,0.007935,0.010739,0.014682,0.013434,0.021531,0.032352,0.040396,0.028472};
3527     Int_t nPointsCumulant2nd2030ALICE = sizeof(xCumulant2nd2030ALICE)/sizeof(Double_t);                                      
3528     TGraphErrors *Cumulant2nd2030ALICE = new TGraphErrors(nPointsCumulant2nd2030ALICE,xCumulant2nd2030ALICE,yCumulant2nd2030ALICE,
3529                                                           xErrCumulant2nd2030ALICE,yErrCumulant2nd2030ALICE);
3530     Cumulant2nd2030ALICE->SetMarkerStyle(kOpenSquare);
3531     Cumulant2nd2030ALICE->SetMarkerColor(kRed); 
3532     
3533     return Cumulant2nd2030ALICE;
3534   }
3535   
3536   if (n == 3)
3537   {
3538   }
3539   
3540   if (n == 4)
3541   {
3542   }
3543   
3544   return 0;
3545 }
3546
3547 TGraphErrors* GetFlow3040(Int_t n)
3548 {
3549   // private communication 09.03.11, Ante B. / Raimond
3550
3551   if (n == 2)
3552   {
3553     // v2{2}(pt) for 30-40%:
3554     Double_t xCumulant2nd3040ALICE[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3555     1.050000,1.150000,1.250000,1.350000,1.450000,1.550000,1.650000,1.750000,1.850000,1.950000,
3556     2.100000,2.300000,2.500000,2.700000,2.900000,3.200000,3.600000,4.000000,4.400000,4.800000,
3557     5.500000,6.500000,7.500000,8.500000,9.500000,11.250000,13.750000,16.250000,18.750000,60.000000};
3558     Double_t yCumulant2nd3040ALICE[] = {0.000000,0.000000,0.039584,0.054196,0.069291,0.082976,0.095622,0.108940,0.119830,0.131587,
3559     0.141091,0.150899,0.160573,0.168676,0.176301,0.183823,0.191672,0.199506,0.206854,0.212830,
3560     0.219526,0.229376,0.236513,0.240863,0.245961,0.245891,0.242608,0.234302,0.219580,0.212848,
3561     0.194666,0.190184,0.171036,0.159173,0.156932,0.141324,0.132809,0.182683,0.023272,0.032825};
3562     Double_t xErrCumulant2nd3040ALICE[40] = {0.};
3563     Double_t yErrCumulant2nd3040ALICE[] = {0.000000,0.000000,0.000189,0.000192,0.000205,0.000224,0.000247,0.000273,0.000302,0.000334,
3564     0.000369,0.000407,0.000448,0.000496,0.000552,0.000612,0.000682,0.000758,0.000844,0.000941,
3565     0.000774,0.000937,0.001123,0.001329,0.001565,0.001397,0.001911,0.002549,0.003378,0.004306,
3566     0.003987,0.006353,0.009128,0.013032,0.016891,0.015806,0.025150,0.035119,0.044487,0.050083};
3567     Int_t nPointsCumulant2nd3040ALICE = sizeof(xCumulant2nd3040ALICE)/sizeof(Double_t);                                      
3568     TGraphErrors *Cumulant2nd3040ALICE = new TGraphErrors(nPointsCumulant2nd3040ALICE,xCumulant2nd3040ALICE,yCumulant2nd3040ALICE,
3569                                                           xErrCumulant2nd3040ALICE,yErrCumulant2nd3040ALICE);
3570     Cumulant2nd3040ALICE->SetMarkerStyle(kFullTriangleUp);
3571     Cumulant2nd3040ALICE->SetMarkerColor(kGreen+2);
3572     
3573     return Cumulant2nd3040ALICE;
3574   }
3575   
3576   if (n == 3)
3577   {
3578   }
3579   
3580   if (n == 4)
3581   {
3582   }
3583   
3584   return 0;
3585 }
3586
3587 TGraphErrors* GetFlow4050(Int_t n)
3588 {
3589   // private communication 09.03.11, Ante B. / Raimond
3590
3591   if (n == 2)
3592   {
3593     // v2{2}(pt) for 40-50%:
3594     Double_t xCumulant2nd4050ALICE[] = {0.050000,0.150000,0.250000,0.350000,0.450000,0.550000,0.650000,0.750000,0.850000,0.950000,
3595     1.050000,1.150000,1.250000,1.350000,1.450000,1.550000,1.650000,1.750000,1.850000,1.950000,
3596     2.100000,2.300000,2.500000,2.700000,2.900000,3.200000,3.600000,4.000000,4.400000,4.800000,
3597     5.500000,6.500000,7.500000,8.500000,9.500000,11.250000,13.750000,16.250000,18.750000,60.000000};
3598     Double_t yCumulant2nd4050ALICE[] = {0.000000,0.000000,0.041872,0.058090,0.074444,0.089181,0.103780,0.117279,0.129769,0.142051,
3599     0.153185,0.163147,0.173309,0.181668,0.190998,0.197703,0.205011,0.211063,0.219587,0.223287,
3600     0.231163,0.239606,0.246533,0.251457,0.250034,0.252989,0.240823,0.236489,0.230268,0.204321,
3601     0.213476,0.200247,0.167065,0.190655,0.173573,0.166173,0.153232,0.173112,-0.123540,0.211999};
3602     Double_t xErrCumulant2nd4050ALICE[40] = {0.};
3603     Double_t yErrCumulant2nd4050ALICE[] = {0.000000,0.000000,0.000248,0.000251,0.000270,0.000296,0.000328,0.000363,0.000403,0.000447,
3604     0.000500,0.000556,0.000617,0.000687,0.000770,0.000857,0.000952,0.001057,0.001176,0.001297,
3605     0.001054,0.001265,0.001498,0.001767,0.002076,0.001849,0.002527,0.003358,0.004372,0.005573,
3606     0.005091,0.007981,0.011746,0.015732,0.021883,0.019866,0.032443,0.046521,0.051631,0.083717};
3607     Int_t nPointsCumulant2nd4050ALICE = sizeof(xCumulant2nd4050ALICE)/sizeof(Double_t);                                      
3608     TGraphErrors *Cumulant2nd4050ALICE = new TGraphErrors(nPointsCumulant2nd4050ALICE,xCumulant2nd4050ALICE,yCumulant2nd4050ALICE,
3609                                                           xErrCumulant2nd4050ALICE,yErrCumulant2nd4050ALICE);
3610     Cumulant2nd4050ALICE->SetMarkerStyle(kOpenTriangleUp);
3611     Cumulant2nd4050ALICE->SetMarkerColor(kGreen+2);
3612     
3613     return Cumulant2nd4050ALICE;
3614   }
3615   
3616   return 0;
3617 }
3618
3619 TGraphErrors* GetFlow6070_Rap10(Int_t n)
3620 {
3621   // private communication 18.05.11, Ante B. 
3622
3623   if (n == 2)
3624   {
3625     //  v2{SP}(pt) for 60-70%, rapidity gap = 1.0:
3626     const Int_t nPointsSP_6070ALICE_v2_etaGap10 = 9;
3627     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};
3628     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};
3629     Double_t xErrSP_6070ALICE_v2_etaGap10[nPointsSP_6070ALICE_v2_etaGap10] = {0.};
3630     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};
3631     TGraphErrors *GrSP_6070ALICE_v2_etaGap10 = new TGraphErrors(nPointsSP_6070ALICE_v2_etaGap10,xSP_6070ALICE_v2_etaGap10,
3632                                                               ySP_6070ALICE_v2_etaGap10,xErrSP_6070ALICE_v2_etaGap10,
3633                                                               yErrSP_6070ALICE_v2_etaGap10);
3634
3635     return GrSP_6070ALICE_v2_etaGap10;
3636   }
3637   
3638   return 0;
3639 }
3640
3641 Float_t CalculateFlow(TH1* ptDist, Float_t ptMin, Float_t ptMax, Int_t n, Int_t centralityBegin, Int_t centralityEnd)
3642 {
3643   if (centralityBegin == 0 && centralityEnd == 1)
3644     flow = GetFlow01_Rap10(n);
3645   else if (centralityBegin == 0 && centralityEnd == 2)
3646     flow = GetFlow02_Rap10(n);
3647   else if (centralityBegin == 0 && centralityEnd == 5)
3648     flow = GetFlow05_Rap10(n);
3649   else if (centralityBegin == 5 && centralityEnd == 10)
3650     flow = GetFlow510_Rap10(n);
3651   else if (centralityBegin == 20 && centralityEnd == 30)
3652     flow = GetFlow2030(n);
3653   else if (centralityBegin == 30 && centralityEnd == 40)
3654     flow = GetFlow3040(n);
3655   else if (centralityBegin == 40 && centralityEnd == 50)
3656     flow = GetFlow4050(n);
3657   else if (centralityBegin > 50)
3658     flow = GetFlow6070_Rap10(n);
3659   else if (centralityBegin == 0 && centralityEnd == 20)
3660   {
3661     flow1 = GetFlow05_Rap10(n);
3662     flow2 = GetFlow510_Rap10(n);
3663     flow3 = GetFlow1020_Rap10(n);
3664     
3665     flow = (TGraphErrors*) flow2->Clone();
3666     
3667     // centrality width * dn/deta from http://arxiv.org/PS_cache/arxiv/pdf/1012/1012.1657v2.pdf
3668     Float_t mult[] = { 5 * 1601, 5 * 1294, 10 * 966 };
3669     
3670     for (Int_t i=0; i<flow->GetN(); i++)
3671     {
3672       Float_t x= flow->GetX()[i];
3673
3674 //       Printf("%f: %f %f %f", x, flow1->Eval(x), flow2->Eval(x), flow3->Eval(x));
3675       flow->GetY()[i] = flow1->Eval(x) * mult[0] + flow2->Eval(x) * mult[1] + flow3->Eval(x) * mult[2];
3676       flow->GetY()[i] /= mult[0] + mult[1] + mult[2];
3677 //       Printf(" --> %f", flow->GetY()[i]);
3678     }
3679   }
3680   else if (centralityBegin == 20 && centralityEnd == 60)
3681   {
3682     flow = GetFlow2030(n);
3683     flow2 = GetFlow3040(n);
3684     flow3 = GetFlow4050(n);
3685     
3686     // centrality width * dn/deta from http://arxiv.org/PS_cache/arxiv/pdf/1012/1012.1657v2.pdf
3687     Float_t mult[] = { 10 * 649, 10 * 426, 10 * (261+149) };
3688     
3689     if (flow->GetN() != flow2->GetN() || flow2->GetN() != flow3->GetN())
3690       AliFatal("Incompatible graphs");
3691     
3692     for (Int_t i=0; i<flow->GetN(); i++)
3693     {
3694 //       Printf("%f %f %f", flow->GetY()[i], flow2->GetY()[i], flow3->GetY()[i]);
3695       flow->GetY()[i] = flow->GetY()[i] * mult[0] + flow2->GetY()[i] * mult[1] + flow3->GetY()[i] * mult[2];
3696       flow->GetY()[i] /= mult[0] + mult[1] + mult[2];
3697 //       Printf(" --> %f", flow->GetY()[i]);
3698     }
3699   }
3700   else
3701   {
3702     Printf("Flow range %d %d not available", centralityBegin, centralityEnd);
3703     AliFatal("");
3704   }
3705
3706   Float_t vn = 0;
3707   Float_t sum = 0;
3708   for (Int_t bin = ptDist->FindBin(ptMin + 0.01); bin <= ptDist->FindBin(ptMax - 0.01); bin++)
3709   {
3710     if (ptDist->GetBinCenter(bin) > flow->GetX()[flow->GetN()-1])
3711       vn += ptDist->GetBinContent(bin) * flow->GetY()[flow->GetN()-1];
3712     else
3713       vn += ptDist->GetBinContent(bin) * flow->Eval(ptDist->GetBinCenter(bin));
3714     sum += ptDist->GetBinContent(bin);
3715   }
3716   
3717   if (sum > 0)
3718     vn /= sum;
3719   
3720   Printf("v_{%d} = %f for %f < pT < %f", n, vn, ptMin, ptMax);
3721   
3722   return vn;
3723 }
3724
3725 void CalculateFlow(const char* fileName, Int_t centralityBegin, Int_t centralityEnd)
3726 {
3727   Float_t ptTrigMin = 2;
3728   Float_t ptTrigMax = 3;
3729   
3730   Float_t ptMin = 1;
3731   Float_t ptMax = 2;
3732
3733   loadlibs();
3734
3735   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
3736   
3737   cont = h->GetUEHist(2)->GetTrackHist(0);
3738   cont->GetGrid(6)->GetGrid()->GetAxis(3)->SetRangeUser(0.01 + centralityBegin, -0.01 + centralityEnd);
3739   cont->GetGrid(6)->GetGrid()->GetAxis(2)->SetRangeUser(ptTrigMin + 0.01, ptTrigMax - 0.01);
3740   
3741   ptDist = cont->ShowProjection(1, 6);
3742   ptDist->Scale(1.0 / ptDist->Integral());
3743   
3744   cont = h->GetUEHist(2)->GetEventHist();
3745   cont->GetGrid(6)->GetGrid()->GetAxis(1)->SetRangeUser(0.01 + centralityBegin, -0.01 + centralityEnd);
3746   
3747   ptDist2 = cont->ShowProjection(0, 6);
3748   ptDist2->Scale(1.0 / ptDist2->Integral());
3749   
3750   TString str;
3751   
3752   for (Int_t n=2; n<=4; n++)
3753   {
3754     Float_t v2A = CalculateFlow(ptDist, ptMin, ptMax, n, centralityBegin, centralityEnd);
3755     Float_t v2T = CalculateFlow(ptDist2, ptTrigMin, ptTrigMax, n, centralityBegin, centralityEnd);
3756     
3757     str += Form("%f * %f, ", v2A, v2T);
3758   }
3759   
3760   ptDist->Draw();
3761   ptDist2->SetLineColor(2);
3762   ptDist2->Draw("SAME");
3763   
3764   Printf("%s", str.Data());
3765 }
3766
3767 // 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...)
3768 TGraphErrors***** yields = 0;
3769 TString currentYieldFile;
3770
3771 void WriteYields()
3772 {
3773   TFile::Open("yields.root", "RECREATE");
3774   for (Int_t i=0; i<3; i++)
3775   {
3776     for (Int_t j=0; j<6; j++)
3777     {
3778       for (Int_t k=0; k<4; k++)
3779       {
3780         // CINT limitation here
3781         TGraphErrors** tmp = yields[i][j][k];
3782         for (Int_t l=0; l<31; l++)
3783         {
3784           //Printf("%d %d %d %d", i, j, k, l);
3785           tmp[l]->Write(Form("yield_%d_%d_%d_%d", i, j, k, l));
3786         }
3787       }
3788     }
3789   }
3790   gFile->Close();
3791 }
3792
3793 void ReadYields(const char* fileName = "yields.root")
3794 {
3795   if (currentYieldFile == fileName)
3796     return;
3797     
3798   currentYieldFile = fileName;
3799
3800   CreateYieldStructure();
3801   TFile::Open(fileName);
3802   for (Int_t i=0; i<3; i++)
3803   {
3804     for (Int_t j=0; j<6; j++)
3805     {
3806       for (Int_t k=0; k<4; k++)
3807       {
3808         // CINT limitation here
3809         TGraphErrors** tmp = yields[i][j][k];
3810         for (Int_t l=0; l<31; l++)
3811         {
3812           //Printf("%d %d %d %d", i, j, k, l);
3813           tmp[l] = gFile->Get(Form("yield_%d_%d_%d_%d", i, j, k, l));
3814         }
3815       }
3816     }
3817   }
3818 }
3819
3820 void CreateYieldStructure()
3821 {
3822   if (!yields)
3823   {
3824     yields = new TGraphErrors****[3];
3825     for (Int_t i=0; i<3; i++)
3826     {
3827       yields[i] = new TGraphErrors***[6];
3828       for (Int_t j=0; j<6; j++)
3829       {
3830         yields[i][j] = new TGraphErrors**[4];
3831         for (Int_t k=0; k<4; k++)
3832         {
3833           yields[i][j][k] = new TGraphErrors*[31];
3834           // CINT limitation here
3835           TGraphErrors** tmp = yields[i][j][k];
3836           for (Int_t l=0; l<31; l++)
3837           {
3838             //Printf("%d %d %d %d", i, j, k, l);
3839             TGraphErrors* graph = new TGraphErrors;
3840             tmp[l] = graph;
3841           }
3842         }
3843       }
3844     }
3845   }
3846 }
3847
3848 void GraphShiftX(TGraphErrors* graph, Float_t offset)
3849 {
3850   for (Int_t i=0; i<graph->GetN(); i++)
3851     graph->GetX()[i] += offset;
3852 }
3853
3854 // Float_t kPythiaScalingFactor = 0.935;
3855 Float_t kPythiaScalingFactor = 1;
3856
3857 void DrawYields(const char* fileName = "yields.root")
3858 {
3859   ReadYields(fileName);
3860   
3861   c = new TCanvas("c", "c", 1800, 1200);
3862   c->Divide(6, 4);
3863   
3864   Int_t markers1[] = { 24, 25, 26, 30 };
3865   Int_t markers2[] = { 20, 21, 22, 29 };
3866   Int_t colors[] = { 1, 2, 3, 4 };
3867   //Int_t caseList[] = { 0, 10+1, 10+1, 8, 10, 11, 12, 13, 1, 9 };
3868   Int_t caseList[] = { 0, 18, 18, 23, 18, 19, 20, 21, 22, 9 };
3869   const char* caseString[] = { "", "baseline sub", "baseline vs v2 sub comp", 0, "baseline sub comp", "Same/Mixed", "Same/Mixed - v2 subtr" };
3870   
3871   Bool_t iaa = kTRUE;
3872   if (!iaa)
3873   {
3874     Int_t centralityList[] =  {  0,  1,  2, 0, 0, 1 };
3875     Int_t centralityList2[] = { -1, -1, -1, 1, 2, 2 };
3876     Float_t factors[]       = {  1,  1,  1, 1, 1, 1 };
3877     const char* centralityString[] = { "0-5%", "20-40%", "60-90%", "0-5% vs 20-40%", "0-5% vs 60-90%", "20-40% vs 60-90%" };
3878   }
3879   else
3880   {
3881     Int_t centralityList[] =  {  0,  2,  3, 0, 0, 2 };
3882     Int_t centralityList2[] = { -1, -1, -1, 2, 3, 3 };
3883     //Float_t factors[]       = {  1,  1,  1, 1, 1.0/0.9, 1.0/0.9 };
3884     //Float_t factors[]       = {  1,  1,  1, 1, 1.0/0.804, 1.0/0.804 };
3885     Float_t factors[]       = {  1,  1,  1, 1, 1.0/kPythiaScalingFactor, 1.0/kPythiaScalingFactor };
3886     //Float_t factors[]       = {  1,  1,  1, 1, 1.0, 1.0 };
3887     const char* centralityString[] = { "0-5%", "60-90%", "pp", "0-5% vs 60-90%", "0-5% vs pp", "60-90% vs pp" };
3888   }
3889   
3890   l = new TLegend(0.5, 0.5, 0.9, 0.9);
3891   l->SetFillColor(0);
3892   
3893   Float_t max[] = { 0.4, 2, 2, 2, 2, 10, 10 };
3894   Float_t max2[] = { 5, 2, 2, 2, 2, 2, 2, 2, 2 };
3895   
3896   dummy = new TH2F("dummy", ";p_{T,assoc};yield", 100, 0, 20, 20000, 0, 10);
3897   dummy->SetStats(0);
3898   
3899   TGraphErrors* prevNear[6];
3900   TGraphErrors* prevAway[6];
3901   for (Int_t caseId=0; caseId<9; caseId++) // case 0->9
3902   {
3903     for (Int_t k=0; k<6; k++) // centrality
3904     {
3905       if (caseId != 3 && caseId < 5)
3906       {
3907         if (caseId < 4)
3908           c->cd(1 + k + caseId*6);
3909         else
3910           c->cd(1 + k + (caseId-1)*6);
3911         currentDummy = dummy->DrawCopy();
3912         currentDummy->GetYaxis()->SetRangeUser(0, max[caseId]);
3913         gPad->SetGridx();
3914         gPad->SetGridy();
3915         
3916         latex = new TLatex(0.15, 0.95, Form("%s - %s", caseString[caseId], centralityString[k]));
3917         latex->SetNDC();
3918         latex->SetTextSize(0.05);
3919         latex->Draw();
3920       }
3921       else if (caseId == 3)
3922         c->cd(1 + k + 2*6);
3923       else
3924         c->cd(1 + k + 3*6);
3925       
3926       for (Int_t j=0; j<3; j++) // trigger pt
3927       {
3928         if (caseId >= 2 && j != 1)
3929           continue;
3930         Printf("%d %d %d %d", caseId, k, j, caseList[caseId]);
3931       
3932         if (k < 3)
3933         {
3934           // CINT limitation here
3935           TGraphErrors** tmp = yields[0][j][centralityList[k]];
3936           nearSide = tmp[caseList[caseId]];
3937           //new TCanvas; nearSide->Draw("AP"); return;
3938           
3939           nearSide->SetMarkerStyle(markers1[j]);
3940           nearSide->SetMarkerColor(colors[j]);
3941           nearSide->SetLineColor(colors[j]);
3942           
3943           if (caseId == 0 && k == 0)
3944             l->AddEntry(nearSide, Form("trig pt bin %d", j), "P");
3945             
3946           TGraphErrors** tmp = yields[1][j][centralityList[k]];
3947           awaySide = tmp[caseList[caseId]];
3948           awaySide->SetMarkerStyle(markers2[j]);
3949           awaySide->SetMarkerColor(colors[j]);
3950           awaySide->SetLineColor(colors[j]);
3951             
3952           GraphShiftX(nearSide, -0.1 + j*0.1);
3953           GraphShiftX(awaySide, -0.1 + j*0.1);
3954           
3955           if (caseId == 3)
3956           {
3957             nearSide->SetLineColor(caseId - 2);
3958             nearSide->SetMarkerColor(caseId - 2);
3959             awaySide->SetLineColor(caseId - 2);
3960             awaySide->SetMarkerColor(caseId - 2);
3961           }
3962           
3963           if (caseId >= 4)
3964           {
3965             nearSide->SetLineColor(caseId - 3);
3966             nearSide->SetMarkerColor(caseId - 3);
3967             awaySide->SetLineColor(caseId - 3);
3968             awaySide->SetMarkerColor(caseId - 3);
3969           }
3970           
3971           awaySide->Print();
3972           
3973           prevNear[k] = (TGraphErrors*) nearSide->DrawClone("PSAME");
3974           prevAway[k] = (TGraphErrors*) awaySide->DrawClone("PSAME");
3975           
3976           if (caseId == 4)
3977           {
3978             Printf("%d", k);
3979             for (Int_t i=0; i<nearSide->GetN(); i++)
3980             {
3981               Printf("%f: %.0f%%", nearSide->GetX()[i], 100.0 * nearSide->GetEY()[i] / nearSide->GetY()[i]);
3982               Printf("%f: %.0f%%", awaySide->GetX()[i], 100.0 * awaySide->GetEY()[i] / awaySide->GetY()[i]);
3983             }
3984           }
3985         }
3986         else
3987         {
3988           // CINT limitation here
3989           tmp = yields[0][j][centralityList[k]]; nearSideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
3990           tmp = yields[1][j][centralityList[k]]; awaySideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
3991           
3992           tmp = yields[0][j][centralityList2[k]]; 
3993           nearSidePeripheral = tmp[caseList[caseId]];
3994           if (iaa && caseId == 3 && k >= 4)
3995             nearSidePeripheral = tmp[caseList[caseId-1]];
3996           
3997           tmp = yields[1][j][centralityList2[k]]; 
3998           awaySidePeripheral = tmp[caseList[caseId]];
3999           if (iaa && caseId == 3 && k >= 4)
4000             awaySidePeripheral = tmp[caseList[caseId-1]];
4001             
4002 //           nearSideCentral->Print();
4003 //           nearSidePeripheral->Print();
4004           
4005           if (k == 3)
4006             currentDummy->GetYaxis()->SetTitle("I_{CP}");
4007           else
4008             currentDummy->GetYaxis()->SetTitle("I_{AA}");
4009           currentDummy->GetYaxis()->SetRangeUser(0, max2[caseId]);
4010           
4011           for (Int_t i=0; i<nearSideCentral->GetN(); i++)
4012           {
4013             if (i >= nearSidePeripheral->GetN())
4014             {
4015               nearSideCentral->RemovePoint(i);
4016               i--;
4017               continue;
4018             }
4019           
4020             //Printf("near %d %f %f", i, nearSideCentral->GetY()[i], nearSidePeripheral->GetY()[i]);
4021             if (nearSidePeripheral->GetY()[i] <= 1e-5 || nearSideCentral->GetY()[i] <= 1e-5)
4022             {
4023               nearSideCentral->RemovePoint(i);
4024               nearSidePeripheral->RemovePoint(i);
4025               i--;
4026               continue;
4027             }
4028           
4029             nearSideCentral->GetEY()[i] = TMath::Sqrt(
4030               TMath::Power(nearSideCentral->GetEY()[i] / nearSideCentral->GetY()[i], 2) + 
4031               TMath::Power(nearSidePeripheral->GetEY()[i] / nearSidePeripheral->GetY()[i], 2) );
4032               
4033             nearSideCentral->GetY()[i] /= nearSidePeripheral->GetY()[i];
4034             nearSideCentral->GetY()[i] *= factors[k];
4035             
4036             nearSideCentral->GetEY()[i] *= nearSideCentral->GetY()[i];
4037           }
4038           //Printf("done");
4039           
4040           for (Int_t i=0; i<awaySideCentral->GetN(); i++)
4041           {
4042             if (i >= awaySidePeripheral->GetN())
4043             {
4044               awaySideCentral->RemovePoint(i);
4045               i--;
4046               continue;
4047             }
4048             
4049             //Printf("away %d", i);
4050             if (awaySidePeripheral->GetY()[i] <= 1e-5 || awaySideCentral->GetY()[i] <= 1e-5)
4051             {
4052               awaySideCentral->RemovePoint(i);
4053               awaySidePeripheral->RemovePoint(i);
4054               i--;
4055               continue;
4056             }
4057             
4058             awaySideCentral->GetEY()[i] = TMath::Sqrt(
4059               TMath::Power(awaySideCentral->GetEY()[i] / awaySideCentral->GetY()[i], 2) + 
4060               TMath::Power(awaySidePeripheral->GetEY()[i] / awaySidePeripheral->GetY()[i], 2) );
4061             
4062             awaySideCentral->GetY()[i] /= awaySidePeripheral->GetY()[i];
4063             awaySideCentral->GetY()[i] *= factors[k];
4064           
4065             awaySideCentral->GetEY()[i] *= awaySideCentral->GetY()[i];
4066           }
4067           
4068           if (caseId == 3)
4069           {
4070             nearSideCentral = (TGraphErrors*) nearSideCentral->Clone();
4071             nearSideCentral->SetLineColor(1);
4072             nearSideCentral->SetMarkerColor(1);
4073           
4074             awaySideCentral = (TGraphErrors*) awaySideCentral->Clone();
4075             awaySideCentral->SetLineColor(1);
4076             awaySideCentral->SetMarkerColor(1);
4077           }
4078           
4079           if (caseId >= 4)
4080           {
4081             nearSideCentral = (TGraphErrors*) nearSideCentral->Clone();
4082             nearSideCentral->SetLineColor(caseId - 3);
4083             nearSideCentral->SetMarkerColor(caseId - 3);
4084           
4085             awaySideCentral = (TGraphErrors*) awaySideCentral->Clone();
4086             awaySideCentral->SetLineColor(caseId - 3);
4087             awaySideCentral->SetMarkerColor(caseId - 3);
4088           }
4089           
4090           //Printf("%d", caseList[caseId]);
4091           
4092 //           nearSideCentral->Print();
4093           
4094           nearSideCentral->Draw("PSAME");
4095           awaySideCentral->Draw("PSAME");
4096         
4097           if (caseId == 3)
4098           {
4099             for (Int_t i=0; i<nearSideCentral->GetN(); i++)
4100               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]));
4101             for (Int_t i=0; i<awaySideCentral->GetN(); i++)
4102               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]));
4103           }
4104         
4105           prevNear[k] = nearSideCentral;
4106           prevAway[k] = awaySideCentral;
4107         }
4108       }
4109       if (caseId == 0 && k == 0)
4110         l->Draw();
4111     }
4112   }
4113   
4114   c->SaveAs("yields.png");
4115 }
4116
4117 void FitGaussians(const char* fileName, Bool_t flat)
4118 {
4119   CreateYieldStructure();
4120
4121   aliceFile = TFile::Open(fileName);
4122
4123   Int_t maxLeadingPt = 3;
4124   Int_t maxAssocPt = 3;
4125   
4126   TCanvas* canvas = new TCanvas("FitGaussians", "FitGaussians", 1000, 700);
4127   canvas->Divide(maxAssocPt, maxLeadingPt);
4128   
4129   for (Int_t i=0; i<maxLeadingPt; i++)
4130     for (Int_t j=0; j<maxAssocPt; j++)
4131     {
4132       TH1* first = 0;
4133       for (Int_t aliceCentrality=0; aliceCentrality<4; aliceCentrality++)
4134       {
4135         Printf("%d %d %d", i, j, aliceCentrality);
4136         
4137         canvas->cd(j+1 + (i) * maxAssocPt);
4138         gPad->SetLeftMargin(0.15);
4139         gPad->SetBottomMargin(0.2);
4140         //gPad->SetTopMargin(0.01);
4141         gPad->SetRightMargin(0.01);
4142         
4143         hist = (TH1*) aliceFile->Get(Form("dphi_%d_%d_%d%s", i, j, aliceCentrality, (flat) ? "_fit_flat" : ""));
4144         if (!hist)
4145           continue;
4146         
4147 //      hist->Rebin(2);
4148         
4149         // two Gauss fits
4150         gausFit = new TF1("gausFit", "[0] + gaus(1) + gaus(4)", -0.5 * TMath::Pi(), 1.5 * TMath::Pi());
4151         gausFit->SetParameters(0, 1, 0, 1, 1, TMath::Pi(), 1);
4152         gausFit->SetParLimits(0, -1, 10000);
4153         gausFit->SetParLimits(1, 0.001, 10000);
4154         gausFit->FixParameter(2, 0);
4155         gausFit->SetParLimits(3, 0.05, 10);
4156         gausFit->SetParLimits(4, 0.001, 10000);
4157         gausFit->FixParameter(5, TMath::Pi());
4158         gausFit->SetParLimits(6, 0.1, 10);
4159         
4160         gausFit->SetLineWidth(1);
4161         gausFit->SetLineColor(hist->GetLineColor());
4162         
4163         hist->Fit(gausFit, "0RIQ");
4164         gausFit->FixParameter(0, gausFit->GetParameter(0));
4165         hist->Fit(gausFit, "RI", (aliceCentrality == 0) ? "" : "SAME");
4166         //gausFit->DrawCopy("SAME");
4167         
4168         // get pT,assoc
4169         TPRegexp reg("(\\d+\\.\\d+) \\< p_\\{T,assoc\\} \\< (\\d+\\.\\d+)");
4170         arr = reg.MatchS(hist->GetTitle(), "", 0, 10);
4171         if (arr->GetEntries() != 3)
4172           continue;
4173           
4174         Float_t pt1 = atof(arr->At(1)->GetName());
4175         Float_t pt2 = atof(arr->At(2)->GetName());
4176
4177         FillYield(i, aliceCentrality, (pt1 + pt2) / 2, (pt2 - pt1) / 2, 18, gausFit->GetParameter(3), gausFit->GetParError(3), gausFit->GetParameter(6), gausFit->GetParError(6));
4178         
4179         if (!first)
4180           first = hist;
4181         else
4182           first->GetYaxis()->SetRangeUser(TMath::Min(first->GetMinimum(), hist->GetMinimum()), TMath::Max(first->GetMaximum(), hist->GetMaximum()));
4183       }
4184       first->GetYaxis()->SetRangeUser(first->GetMinimum(), 2 * first->GetMaximum());
4185         
4186 //        break;
4187     }
4188     
4189     
4190   // draw
4191   
4192   for (Int_t j=0; j<maxLeadingPt; j++)
4193   {
4194     new TCanvas;
4195     
4196     Int_t markers1[] = { 24, 25, 26, 30 };
4197     Int_t markers2[] = { 20, 21, 22, 29 };
4198     Int_t colors[] = { 1, 2, 3, 4 };
4199     
4200     dummy = new TH2F("dummy", ";p_{T,assoc};", 100, 0, 10, 1000, 0, 1);
4201     dummy->SetStats(0);
4202     dummy->Draw();
4203     
4204     for (Int_t k=0; k<4; k++) // centrality
4205     {
4206       // CINT limitation here
4207       TGraphErrors** tmp = yields[0][j][k];
4208       nearSide = tmp[18];
4209       nearSide->SetMarkerStyle(markers1[k]);
4210       nearSide->SetMarkerColor(colors[k]);
4211       nearSide->SetLineColor(colors[k]);  
4212     
4213       TGraphErrors** tmp = yields[1][j][k];
4214       awaySide = tmp[18];
4215       awaySide->SetMarkerStyle(markers2[k]);
4216       awaySide->SetMarkerColor(colors[k]);
4217       awaySide->SetLineColor(colors[k]);  
4218       
4219       nearSide->DrawClone("PSAME");
4220       awaySide->DrawClone("PSAME");
4221     }
4222   }
4223 }
4224
4225 void TsallisExamples()
4226 {
4227   tsallis = new TF1("tsallis", "[0] * (1-[2]*(1-[1])*x*x)**(1/(1-[1]))", -0.5 * TMath::Pi(), 1.5 * TMath::Pi());
4228   
4229   Float_t q[] = { 1.0000001, 1.5, 2 };
4230   Float_t beta[] = { 0.1, 1, 10, 100 };
4231   
4232   dummy = new TH2F("dummy", "", 100, -0.5 * TMath::Pi(), 1.5 * TMath::Pi(), 100, 0, 1.2);
4233   dummy->SetStats(0);
4234   dummy->Draw();
4235   
4236   legend = new TLegend(0.65, 0.5, 1, 1);
4237   legend->SetFillColor(0);
4238   
4239   for (Int_t i=0; i<3; i++)
4240     for (Int_t j=0; j<4; j++)
4241     {
4242       tsallis->SetParameters(1, q[i], beta[j]);
4243       tsallis->SetLineColor(i+1);
4244       tsallis->SetLineStyle(j+1);
4245       
4246       legend->AddEntry(tsallis->DrawCopy("SAME"), Form("q = %.1f, #beta = %.1f", q[i], beta[j]), "L");
4247     }
4248     
4249   legend->Draw();
4250 }
4251
4252 void DrawTsallisParams()
4253 {
4254   ReadYields();
4255   
4256   c = new TCanvas("c", "c", 900, 600);
4257   c->Divide(3, 2);
4258   
4259   Int_t markers1[] = { 24, 25, 26, 30 };
4260   Int_t markers2[] = { 20, 21, 22, 29 };
4261   Int_t colors[] = { 1, 2, 3, 4 };
4262   Int_t caseList[] = { 12, 13, 8, 6, 8, 9, 10, 11, 1, 7 };
4263   const char* caseString[] = { "q", "beta" };
4264   const char* centralityString[] = { "0-5%", "20-40%", "60-90%", "0-5% vs 20-40%", "0-5% vs 60-90%", "20-40% vs 60-90%" };
4265   
4266   l = new TLegend(0.5, 0.5, 0.9, 0.9);
4267   l->SetFillColor(0);
4268   
4269   Float_t max[] = { 3, 1000 };
4270   Float_t max2[] = { 5, 2 };
4271   
4272   dummy = new TH2F("dummy", ";p_{T,assoc};", 100, 0, 20, 1000, 0, 1000);
4273   dummy->SetStats(0);
4274   
4275   for (Int_t caseId=0; caseId<2; caseId++) // case
4276   {
4277     for (Int_t k=0; k<3; k++) // centrality
4278     {
4279       c->cd(1 + k + caseId*3);
4280         
4281       currentDummy = dummy->DrawCopy();
4282       currentDummy->GetYaxis()->SetRangeUser(0, max[caseId]);
4283       if (caseId == 1 && k < 3)
4284         gPad->SetLogy();
4285       
4286       latex = new TLatex(0.15, 0.95, Form("%s - %s", caseString[caseId], centralityString[k]));
4287       latex->SetNDC();
4288       latex->SetTextSize(0.05);
4289       latex->Draw();
4290       
4291       for (Int_t j=0; j<2; j++) // trigger pt
4292       {
4293         if (k < 3)
4294         {
4295           // CINT limitation here
4296           TGraphErrors** tmp = yields[0][j][k];
4297           nearSide = tmp[caseList[caseId]];
4298           nearSide->SetMarkerStyle(markers1[j]);
4299           nearSide->SetMarkerColor(colors[j]);
4300           nearSide->SetLineColor(colors[j]);
4301           
4302           if (caseId == 0 && k == 0)
4303             l->AddEntry(nearSide, Form("trig pt bin %d", j), "P");
4304             
4305           TGraphErrors** tmp = yields[1][j][k];
4306           awaySide = tmp[caseList[caseId]];
4307           awaySide->SetMarkerStyle(markers2[j]);
4308           awaySide->SetMarkerColor(colors[j]);
4309           awaySide->SetLineColor(colors[j]);
4310             
4311           GraphShiftX(nearSide, -0.1 + j*0.1);
4312           GraphShiftX(awaySide, -0.1 + j*0.1);
4313           
4314           Printf("%d %d %d", caseId, j, k);
4315           nearSide->Print();
4316           awaySide->Print();
4317           
4318           nearSide->DrawClone("PSAME");
4319           awaySide->DrawClone("PSAME");
4320         }
4321         else
4322         {
4323           // CINT limitation here
4324           if (k == 3)
4325           {
4326             tmp = yields[0][j][0]; nearSideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
4327             tmp = yields[1][j][0]; awaySideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
4328             tmp = yields[0][j][1]; nearSidePeripheral = tmp[caseList[caseId]];
4329             tmp = yields[1][j][1]; awaySidePeripheral = tmp[caseList[caseId]];
4330           }
4331           else if (k == 4)
4332           {
4333             tmp = yields[0][j][0]; nearSideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
4334             tmp = yields[1][j][0]; awaySideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
4335             tmp = yields[0][j][2]; nearSidePeripheral = tmp[caseList[caseId]];
4336             tmp = yields[1][j][2]; awaySidePeripheral = tmp[caseList[caseId]];
4337           }
4338           else if (k == 5)
4339           {
4340             tmp = yields[0][j][1]; nearSideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
4341             tmp = yields[1][j][1]; awaySideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
4342             tmp = yields[0][j][2]; nearSidePeripheral = tmp[caseList[caseId]];
4343             tmp = yields[1][j][2]; awaySidePeripheral = tmp[caseList[caseId]];
4344           }
4345           
4346           currentDummy->GetYaxis()->SetTitle("I_{CP}");
4347           currentDummy->GetYaxis()->SetRangeUser(0, max2[caseId]);
4348         
4349           for (Int_t i=0; i<nearSideCentral->GetN(); i++)
4350           {
4351             //Printf("near %d %f %f", i, nearSideCentral->GetY()[i], nearSidePeripheral->GetY()[i]);
4352             if (nearSidePeripheral->GetY()[i] <= 1e-5 || nearSideCentral->GetY()[i] <= 1e-5)
4353             {
4354               nearSideCentral->RemovePoint(i);
4355               nearSidePeripheral->RemovePoint(i);
4356               i--;
4357               continue;
4358             }
4359           
4360             nearSideCentral->GetEY()[i] = TMath::Sqrt(
4361               TMath::Power(nearSideCentral->GetEY()[i] / nearSideCentral->GetY()[i], 2) + 
4362               TMath::Power(nearSidePeripheral->GetEY()[i] / nearSidePeripheral->GetY()[i], 2) );
4363               
4364             nearSideCentral->GetY()[i] /= nearSidePeripheral->GetY()[i];
4365             
4366             nearSideCentral->GetEY()[i] *= nearSideCentral->GetY()[i];
4367           }
4368           //Printf("done");
4369           
4370           for (Int_t i=0; i<awaySideCentral->GetN(); i++)
4371           {
4372             //Printf("away %d", i);
4373             if (awaySidePeripheral->GetY()[i] <= 1e-5 || awaySideCentral->GetY()[i] <= 1e-5)
4374             {
4375               awaySideCentral->RemovePoint(i);
4376               awaySidePeripheral->RemovePoint(i);
4377               i--;
4378               continue;
4379             }
4380             
4381             awaySideCentral->GetEY()[i] = TMath::Sqrt(
4382               TMath::Power(awaySideCentral->GetEY()[i] / awaySideCentral->GetY()[i], 2) + 
4383               TMath::Power(awaySidePeripheral->GetEY()[i] / awaySidePeripheral->GetY()[i], 2) );
4384             
4385             awaySideCentral->GetY()[i] /= awaySidePeripheral->GetY()[i];
4386           
4387             awaySideCentral->GetEY()[i] *= awaySideCentral->GetY()[i];
4388           }
4389           
4390           if (caseId == 3)
4391           {
4392             nearSideCentral = (TGraphErrors*) nearSideCentral->Clone();
4393             nearSideCentral->SetLineColor(1);
4394             nearSideCentral->SetMarkerColor(1);
4395           
4396             awaySideCentral = (TGraphErrors*) awaySideCentral->Clone();
4397             awaySideCentral->SetLineColor(1);
4398             awaySideCentral->SetMarkerColor(1);
4399           }
4400           
4401           if (caseId >= 4)
4402           {
4403             nearSideCentral = (TGraphErrors*) nearSideCentral->Clone();
4404             nearSideCentral->SetLineColor(caseId - 3);
4405             nearSideCentral->SetMarkerColor(caseId - 3);
4406           
4407             awaySideCentral = (TGraphErrors*) awaySideCentral->Clone();
4408             awaySideCentral->SetLineColor(caseId - 3);
4409             awaySideCentral->SetMarkerColor(caseId - 3);
4410           }
4411           
4412           //Printf("%d", caseList[caseId]);
4413           
4414           nearSideCentral->Draw("PSAME");
4415           awaySideCentral->Draw("PSAME");
4416         }
4417       }
4418       if (caseId == 0 && k == 0)
4419         l->Draw();
4420     }
4421   }
4422   
4423   c->SaveAs("tsallisparams.png");
4424 }
4425
4426 void DrawYieldLHCRHIC_ICP(const char* fileName = "yields.root")
4427 {
4428   Int_t caseId = 0;
4429   Int_t caseList[] = { 18 };
4430   Int_t j = 1;
4431   
4432   ReadYields(fileName);
4433   
4434   c = new TCanvas("lhc_rhic", "lhc_rhic", 800, 600);
4435   gPad->SetGridx();
4436   gPad->SetGridy();
4437   
4438   dummy = new TH2F("dummy", ";p_{T,assoc};I_{CP}", 100, 0, 12, 1000, 0, 10);
4439   dummy->SetStats(0);
4440   currentDummy = dummy->DrawCopy();
4441   currentDummy->GetYaxis()->SetRangeUser(0, 2);
4442         
4443   TGraphErrors** tmp = yields[0][j][0]; nearSideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
4444   tmp = yields[1][j][0]; awaySideCentral = (TGraphErrors*) tmp[caseList[caseId]]->Clone();
4445   tmp = yields[0][j][2]; nearSidePeripheral = tmp[caseList[caseId]];
4446   tmp = yields[1][j][2]; awaySidePeripheral = tmp[caseList[caseId]];
4447         
4448   for (Int_t i=0; i<nearSideCentral->GetN(); i++)
4449   {
4450     //Printf("near %d %f %f", i, nearSideCentral->GetY()[i], nearSidePeripheral->GetY()[i]);
4451     if (nearSidePeripheral->GetY()[i] <= 1e-5 || nearSideCentral->GetY()[i] <= 1e-5)
4452     {
4453       nearSideCentral->RemovePoint(i);
4454       nearSidePeripheral->RemovePoint(i);
4455       i--;
4456       continue;
4457     }
4458   
4459     nearSideCentral->GetEY()[i] = TMath::Sqrt(
4460       TMath::Power(nearSideCentral->GetEY()[i] / nearSideCentral->GetY()[i], 2) + 
4461       TMath::Power(nearSidePeripheral->GetEY()[i] / nearSidePeripheral->GetY()[i], 2) );
4462       
4463     nearSideCentral->GetY()[i] /= nearSidePeripheral->GetY()[i];
4464     
4465     nearSideCentral->GetEY()[i] *= nearSideCentral->GetY()[i];
4466   }
4467   //Printf("done");
4468   
4469   for (Int_t i=0; i<awaySideCentral->GetN(); i++)
4470   {
4471     //Printf("away %d", i);
4472     if (awaySidePeripheral->GetY()[i] <= 1e-5 || awaySideCentral->GetY()[i] <= 1e-5)
4473     {
4474       awaySideCentral->RemovePoint(i);
4475       awaySidePeripheral->RemovePoint(i);
4476       i--;
4477       continue;
4478     }
4479     
4480     awaySideCentral->GetEY()[i] = TMath::Sqrt(
4481       TMath::Power(awaySideCentral->GetEY()[i] / awaySideCentral->GetY()[i], 2) + 
4482       TMath::Power(awaySidePeripheral->GetEY()[i] / awaySidePeripheral->GetY()[i], 2) );
4483     
4484     awaySideCentral->GetY()[i] /= awaySidePeripheral->GetY()[i];
4485   
4486     awaySideCentral->GetEY()[i] *= awaySideCentral->GetY()[i];
4487   }
4488           
4489   nearSideCentral->SetMarkerStyle(21);
4490   nearSideCentral->SetLineColor(1);
4491   nearSideCentral->SetMarkerColor(1);
4492           
4493   awaySideCentral->SetMarkerStyle(25);
4494   awaySideCentral->SetLineColor(1);
4495   awaySideCentral->SetMarkerColor(1);
4496   
4497   nearSideCentral->Draw("PSAME");
4498   awaySideCentral->Draw("PSAME");        
4499
4500   legend = new TLegend(0.4, 0.8, 0.99, 0.99);
4501   legend->SetFillColor(0);
4502   legend->AddEntry(nearSideCentral, "ALICE I_{CP} Near 8-15 GeV 0-5%/60-90%", "P");
4503   legend->AddEntry(awaySideCentral, "ALICE I_{CP} Away 8-15 GeV 0-5%/60-90%", "P");
4504   
4505   if (0)
4506   {
4507     nearSideCentral->Fit("pol1", "", "SAME", 4.5, 11.5);
4508     awaySideCentral->Fit("pol1", "", "SAME", 4.5, 11.5);
4509     nearSideCentral->GetFunction("pol1")->SetLineWidth(1);
4510     awaySideCentral->GetFunction("pol1")->SetLineWidth(1);
4511   }
4512
4513   if (0)
4514   {
4515     // RCP, ALICE
4516     dndpt_central = ReadHepdata("raa_dndpt_central.txt", kFALSE, 3);
4517     dndpt_peripheral = ReadHepdata("raa_dndpt_peripheral.txt", kFALSE, 3);
4518     
4519     //dndpt_central->Print();
4520     //dndpt_peripheral->Print();
4521     
4522     // ratio of Ncoll (from paper)
4523     // TODO there is also an uncertainty on that
4524     Double_t scale = 1690. / 15.7;
4525     Double_t scaleUnc = TMath::Sqrt(TMath::Power(131. / 1690., 2) + TMath::Power(0.7 / 15.7, 2));
4526     
4527     for (Int_t i=0; i<dndpt_central->GetN(); i++)
4528     {
4529       dndpt_central->GetEY()[i] = TMath::Sqrt(TMath::Power(dndpt_central->GetEY()[i] / dndpt_central->GetY()[i], 2) + 
4530         TMath::Power(dndpt_peripheral->GetEY()[i] / dndpt_peripheral->GetY()[i], 2));
4531       dndpt_central->GetY()[i] /= dndpt_peripheral->GetY()[i] * scale;
4532       dndpt_central->GetEY()[i] *= dndpt_central->GetY()[i];
4533     }
4534     
4535     //new TCanvas;
4536     //dndpt_central->Print();
4537     //dndpt_central->Draw("AP");
4538     
4539     dndpt_central->Draw("*SAME");
4540     
4541     latex = new TLatex(0.34, 0.09, "9% N_{coll} scale uncertainty on R_{CP}");
4542     latex->SetTextSize(0.03);
4543     latex->Draw();
4544     
4545     // RAA, ALICE
4546     raa_central = ReadHepdata("raa_alice_central.txt", kFALSE, 3);
4547     raa_central->SetMarkerStyle(20);
4548     //raa_central->Draw("PSAME");
4549   
4550     legend->AddEntry(dndpt_central, "ALICE R_{CP} 0-5%/70-80%", "P");
4551   }
4552   
4553   if (0)
4554   {
4555     // IAA, RHIC
4556     // calculate ICP from IAA(0-20) / IAA (20-60)
4557     // TODO only using uncertainties from IAA(0-20)
4558     // TODO systematic uncertainty stored in graph with _sys appended
4559     TFile::Open("rhic/pi0h_graphs.root");
4560     
4561     for (Int_t i=0; i<3; i+=2)
4562     {
4563       // gIAA_<ptTrigBin>_<centBin>_<angularRegionBin>
4564       central = (TGraphErrors*) gFile->Get(Form("gIAA_3_0_%d", i));
4565       peripheral = (TGraphErrors*) gFile->Get(Form("gIAA_3_1_%d", i));
4566       
4567       for (Int_t j=0; j<central->GetN(); j++)
4568       {
4569         central->GetY()[j] /= peripheral->GetY()[j];
4570         central->GetEY()[j] /= peripheral->GetY()[j];
4571       }
4572       
4573       central->SetMarkerStyle((i == 0) ? 29 : 30);
4574       central->SetMarkerColor(2);
4575       central->SetLineColor(2);
4576       central->Draw("PSAME");
4577       legend->AddEntry(central, Form("PHENIX I_{CP} %s 9-12 GeV 0-20%/20-60%", (i == 0) ? "Near" : "Away"), "P");
4578     }
4579   }
4580   
4581   legend->Draw();
4582   
4583   c->SaveAs("icp.png");
4584 }
4585
4586 TGraphErrors* GetRatio(const char* fileName, Int_t centrality1, Int_t centrality2, Int_t triggerId, Int_t caseId, Int_t side, const char* fileName2 = 0)
4587 {
4588   // 0 = near side; 1 = away side
4589
4590   ReadYields(fileName);
4591   
4592   TGraphErrors** tmp = yields[side][triggerId][centrality1]; 
4593   nearSideCentral = (TGraphErrors*) tmp[caseId]->Clone();
4594   
4595   if (fileName2)
4596     ReadYields(fileName2);
4597   
4598   tmp = yields[side][triggerId][centrality2]; 
4599   nearSidePeripheral = (TGraphErrors*) tmp[caseId]->Clone();
4600   
4601 //   Printf("%d %d", nearSideCentral->GetN(), nearSidePeripheral->GetN());
4602         
4603   for (Int_t i=0; i<nearSideCentral->GetN(); i++)
4604   {
4605     if (nearSidePeripheral->GetY()[i] <= 1e-5 || nearSideCentral->GetY()[i] <= 1e-5)
4606     {
4607       nearSideCentral->RemovePoint(i);
4608       nearSidePeripheral->RemovePoint(i);
4609       i--;
4610       continue;
4611     }
4612     
4613     if (nearSideCentral->GetX()[i] != nearSidePeripheral->GetX()[i])
4614     {
4615       Printf("Inconsistent x values %f %f", nearSideCentral->GetX()[i], nearSidePeripheral->GetX()[i]);
4616       AliFatal("");
4617     }
4618   
4619 //     printf("%f %f %f", nearSideCentral->GetX()[i], nearSideCentral->GetY()[i], nearSidePeripheral->GetY()[i]);
4620     
4621     nearSideCentral->GetEY()[i] = TMath::Sqrt(
4622       TMath::Power(nearSideCentral->GetEY()[i] / nearSideCentral->GetY()[i], 2) + 
4623       TMath::Power(nearSidePeripheral->GetEY()[i] / nearSidePeripheral->GetY()[i], 2) );
4624       
4625     nearSideCentral->GetY()[i] /= nearSidePeripheral->GetY()[i];
4626     // scaling for IAA
4627     if (centrality2 == 3)
4628       nearSideCentral->GetY()[i] /= kPythiaScalingFactor;
4629     
4630 //     Printf(" %f", nearSideCentral->GetY()[i]);
4631     
4632     nearSideCentral->GetEY()[i] *= nearSideCentral->GetY()[i];
4633   }
4634   
4635   //nearSideCentral->GetXaxis()->SetTitle("p_{T, assoc}");
4636   //nearSideCentral->GetYaxis()->SetTitle((centrality2 == 3) ? "I_{AA}" : "I_{CP}");
4637
4638   if (0 && side == 1 && centrality2 == 3)
4639   {
4640     Printf("\n\n\nWARNING !!! Fudging different away side acceptance (only for second file)\n\n\n");
4641     ScaleGraph(nearSideCentral, 1.56);
4642   }
4643   
4644   return nearSideCentral;
4645 }
4646
4647 TGraphErrors* GetIAA(const char* fileName, Int_t centrality, Int_t triggerId, Int_t caseId, Int_t side)
4648 {
4649   return GetRatio(fileName, centrality, 3, triggerId, caseId, side);
4650 }
4651
4652 TGraphErrors* GetICP(const char* fileName, Int_t triggerId, Int_t caseId, Int_t side)
4653 {
4654   return GetRatio(fileName, 1, 2, triggerId, caseId, side);
4655 }
4656
4657 void DrawYieldLHCRHIC_IAA(const char* fileName, Bool_t central, Bool_t rhic)
4658 {
4659   Int_t caseId = 0;
4660   Int_t caseList[] = { 18 };
4661   Int_t j = 1;
4662   
4663   ReadYields(fileName);
4664   
4665   c = new TCanvas("lhc_rhic", "lhc_rhic", 800, 600);
4666   gPad->SetGridx();
4667   gPad->SetGridy();
4668   
4669   dummy = new TH2F("dummy", ";p_{T,assoc};I_{AA}", 100, 0, 12, 1000, 0, 10);
4670   dummy->SetStats(0);
4671   currentDummy = dummy->DrawCopy();
4672   currentDummy->GetYaxis()->SetRangeUser(0, 3);
4673         
4674   Int_t nominatorBin = 0;
4675   if (!central)
4676     nominatorBin = 2;
4677         
4678   nearSideCentral = GetIAA(fileName, nominatorBin, j, caseList[caseId], 0);
4679   awaySideCentral = GetIAA(fileName, nominatorBin, j, caseList[caseId], 1);
4680   
4681   nearSideCentral->SetMarkerStyle(21);
4682   nearSideCentral->SetLineColor(1);
4683   nearSideCentral->SetMarkerColor(1);
4684           
4685   awaySideCentral->SetMarkerStyle(25);
4686   awaySideCentral->SetLineColor(1);
4687   awaySideCentral->SetMarkerColor(1);
4688   
4689   nearSideCentral->Draw("PSAME");
4690   awaySideCentral->Draw("PSAME");        
4691   
4692   legend = new TLegend(0.4, 0.8, 0.99, 0.99);
4693   legend->SetFillColor(0);
4694   legend->AddEntry(nearSideCentral, Form("ALICE I_{AA} Near 8-15 GeV %s%%/Pythia6", (central) ? "0-5" : "60-90"), "P");
4695   legend->AddEntry(awaySideCentral, Form("ALICE I_{AA} Away 8-15 GeV %s%%/Pythia6", (central) ? "0-5" : "60-90"), "P");
4696   
4697   if (rhic)
4698   {
4699     // IAA, RHIC
4700     // systematic uncertainty stored in graph with _sys appended
4701     TFile::Open("rhic/pi0h_graphs.root");
4702     
4703     for (Int_t i=0; i<3; i+=2)
4704     {
4705       // gIAA_<ptTrigBin>_<centBin>_<angularRegionBin>
4706       rhic_iaa = (TGraphErrors*) gFile->Get(Form("gIAA_2_%d_%d", (central) ? 0 : 1, i));
4707       rhic_iaa_sys = (TGraphErrors*) gFile->Get(Form("gIAA_2_%d_%d_sys", (central) ? 0 : 1, i));
4708   
4709       rhic_iaa->SetMarkerStyle((i == 0) ? 29 : 30);
4710       rhic_iaa->SetMarkerColor(2);
4711       rhic_iaa->SetLineColor(2);
4712       rhic_iaa->Draw("PSAME");
4713       rhic_iaa_sys->SetLineColor(2);
4714       rhic_iaa_sys->SetMarkerColor(2);
4715       rhic_iaa_sys->Draw("PSAME");
4716       legend->AddEntry(rhic_iaa, Form("PHENIX I_{AA} %s 7-9 GeV %s%%/pp", (i == 0) ? "Near" : "Away", (central) ? "0-20" : "20-60"), "P");
4717     }
4718     for (Int_t i=0; i<3; i+=2)
4719     {
4720       // gIAA_<ptTrigBin>_<centBin>_<angularRegionBin>
4721       rhic_iaa = (TGraphErrors*) gFile->Get(Form("gIAA_3_%d_%d", (central) ? 0 : 1, i));
4722       rhic_iaa_sys = (TGraphErrors*) gFile->Get(Form("gIAA_3_%d_%d_sys", (central) ? 0 : 1, i));
4723   
4724       rhic_iaa->SetMarkerStyle((i == 0) ? 20 : 24);
4725       rhic_iaa->SetMarkerColor(4);
4726       rhic_iaa->SetLineColor(4);
4727       rhic_iaa->Draw("PSAME");
4728       rhic_iaa_sys->SetLineColor(4);
4729       rhic_iaa_sys->SetMarkerColor(4);
4730       rhic_iaa_sys->Draw("PSAME");
4731       legend->AddEntry(rhic_iaa, Form("PHENIX I_{AA} %s 9-12 GeV %s%%/pp", (i == 0) ? "Near" : "Away", (central) ? "0-20" : "20-60"), "P");
4732     }
4733   }
4734   
4735   legend->Draw();
4736   
4737   c->SaveAs("iaa.png");
4738 }
4739
4740 void CompareIAAICP(const char* fileName1, const char* fileName2, Int_t nominatorBin, Int_t denominatorBin, Bool_t skipAway = kFALSE)
4741 {
4742   Int_t j = 1;
4743   Int_t caseId = 18;
4744 //   caseId = 23; Printf("WARNING: Comparing case 23");
4745   //Int_t caseId = 12;
4746
4747   nearSide1 = GetRatio(fileName1, nominatorBin, denominatorBin, j, caseId, 0);
4748   if (!skipAway)
4749     awaySide1 = GetRatio(fileName1, nominatorBin, denominatorBin, j, caseId, 1);
4750   else
4751     awaySide1 = new TGraphErrors;
4752   
4753   kPythiaScalingFactor = 1;
4754   nearSide2 = GetRatio(fileName2, nominatorBin, denominatorBin, j, caseId, 0);
4755   if (!skipAway)
4756     awaySide2 = GetRatio(fileName2, nominatorBin, denominatorBin, j, caseId, 1);
4757   else
4758     awaySide2 = new TGraphErrors;
4759   
4760 //   Printf("\n\n\nWARNING !!! Fudging different away side acceptance (only for second file)\n\n\n");
4761 //   ScaleGraph(awaySide2, 1.56);
4762   
4763 /*  ScaleGraph(nearSide2, 1.33);
4764   ScaleGraph(awaySide2, 1.33);*/
4765   
4766   c = new TCanvas;
4767   dummy = new TH2F("dummy", Form(";p_{T,assoc};%s", (denominatorBin == 3) ? "I_{AA}" : "I_{CP}"), 100, 2, 12, 1000, 0, 10);
4768   dummy->SetStats(0);
4769   currentDummy = dummy->DrawCopy();
4770   currentDummy->GetYaxis()->SetRangeUser(0, 2.5);
4771   
4772   nearSide1->SetMarkerStyle(21);
4773   nearSide1->SetLineColor(1);
4774   nearSide1->SetMarkerColor(1);
4775           
4776   nearSide2->SetMarkerStyle(21);
4777   nearSide2->SetLineColor(2);
4778   nearSide2->SetMarkerColor(2);
4779   
4780   awaySide1->SetMarkerStyle(25);
4781   awaySide1->SetLineColor(1);
4782   awaySide1->SetMarkerColor(1);
4783   
4784   awaySide2->SetMarkerStyle(25);
4785   awaySide2->SetLineColor(2);
4786   awaySide2->SetMarkerColor(2);
4787   
4788   RemovePointsBelowX(nearSide1, 3);
4789   RemovePointsBelowX(nearSide2, 3);
4790   RemovePointsBelowX(awaySide1, 3);
4791   RemovePointsBelowX(awaySide2, 3);
4792   
4793   gPad->SetGridx();
4794   gPad->SetGridy();
4795   
4796   nearSide1->DrawClone("PSAME");
4797   awaySide1->DrawClone("PSAME");        
4798   nearSide2->DrawClone("PSAME");
4799   awaySide2->DrawClone("PSAME");        
4800   
4801   new TCanvas;
4802   currentDummy = dummy->DrawCopy();
4803   currentDummy->GetYaxis()->SetRangeUser(0.5, 1.5);
4804   gPad->SetGridx();
4805   gPad->SetGridy();
4806   
4807   DivideGraphs(nearSide1, nearSide2);
4808   DivideGraphs(awaySide1, awaySide2);
4809   
4810   nearSide1->Draw("PSAME");
4811   awaySide1->Draw("PSAME");        
4812   
4813   nearSide1->Fit("pol0", "", "SAME", 3.01, 9.99);
4814   awaySide1->Fit("pol0", "", "SAME", 3.01, 9.99);
4815 }
4816
4817 void ScaleGraph(TGraphErrors* graph, Float_t factor)
4818 {
4819         for (Int_t i=0; i<graph->GetN(); i++)
4820         {
4821     graph->GetY()[i] *= factor;
4822     graph->GetEY()[i] *= factor;
4823   }
4824 }
4825
4826 TGraphErrors* DrawBaselines(const char* fileName, Int_t numeratorBin, Int_t denominatorBin, Int_t side, Bool_t verbose = kTRUE)
4827 {
4828   Int_t j = 1;
4829   
4830   TGraphErrors* first = 0;
4831   TGraphErrors* max = 0;
4832   
4833   if (verbose)
4834   {
4835     c = new TCanvas;
4836     dummy = new TH2F("dummy", Form(";p_{T,assoc};%s", (denominatorBin == 3) ? "I_{AA}" : "I_{CP}"), 100, 0, 12, 1000, 0, 10);
4837     dummy->SetStats(0);
4838     currentDummy = dummy->DrawCopy();
4839     currentDummy->GetYaxis()->SetRangeUser(0, 3);
4840     
4841     c2 = new TCanvas;
4842     currentDummy = dummy->DrawCopy();
4843     currentDummy->GetYaxis()->SetRangeUser(0, 2);
4844   }
4845   
4846 //   Int_t caseList[] = { 18, 19, 21, 22 };
4847   //Int_t caseList[] = { 23, 24, 26, 27 };
4848   Int_t caseList[] = { 18, 19, 22 };
4849   
4850   for (Int_t caseId = 0; caseId < 3; caseId++)
4851   {
4852     graph = GetRatio(fileName, numeratorBin, denominatorBin, j, caseList[caseId], side);
4853     
4854     graph->SetLineColor(caseId + 1);
4855     graph->SetMarkerColor(caseId + 1);
4856     
4857     RemovePointsBelowX(graph, 3);
4858     
4859     if (verbose)
4860     {
4861       c->cd();
4862       graph->DrawClone("*SAME");
4863     }
4864     
4865     if (!first)
4866     {
4867       first = graph;
4868       max = (TGraphErrors*) graph->Clone();
4869       for (Int_t i=0; i<max->GetN(); i++)
4870       {
4871         max->GetY()[i] = 0;
4872         max->GetEY()[i] = 0;
4873       }
4874     }
4875     else
4876     {
4877       DivideGraphs(graph, first);
4878       
4879       if (verbose)
4880       {
4881         c2->cd();
4882         graph->DrawClone("*SAME");
4883       }
4884       
4885       for (Int_t i=0; i<graph->GetN(); i++)
4886       {
4887         if (max->GetY()[i] < TMath::Abs(graph->GetY()[i] - 1))
4888           max->GetY()[i] = TMath::Abs(graph->GetY()[i] - 1);
4889       }
4890     }
4891   }
4892   
4893   if (verbose)
4894   {
4895     new TCanvas;
4896     max->Draw("A*");
4897   }
4898   
4899   max->GetXaxis()->SetTitle("p_{T, assoc}");
4900   max->GetYaxis()->SetTitle((denominatorBin == 3) ? "Effect on I_{AA}" : "Effect on I_{CP}");
4901   max->GetYaxis()->SetRangeUser(0, 0.4);
4902   
4903   return max;
4904 }
4905
4906 void DrawBaselinesAll(const char* fileName)
4907 {
4908   c = new TCanvas("c", "c", 1000, 600);
4909   c->Divide(4, 2);
4910   
4911   for (Int_t i=0; i<2; i++)
4912   {
4913     c->cd(1+i*4); DrawBaselines(fileName, 0, 3, i, kFALSE)->Draw("A*"); gPad->SetGridy();
4914     c->cd(2+i*4); DrawBaselines(fileName, 1, 3, i, kFALSE)->Draw("A*"); gPad->SetGridy();
4915     c->cd(3+i*4); DrawBaselines(fileName, 2, 3, i, kFALSE)->Draw("A*"); gPad->SetGridy();
4916     c->cd(4+i*4); DrawBaselines(fileName, 0, 2, i, kFALSE)->Draw("A*"); gPad->SetGridy();
4917   }
4918 }
4919
4920 TGraphErrors* DrawSystUncIAAPYTHIA(TGraphErrors* graph, Int_t iaa_icp, Int_t awaySide)
4921 {
4922   // iaa = 0, icp = 1
4923
4924   Float_t baseline = 1;
4925   if (awaySide == 0)
4926     baseline = 0.07;
4927   else if (awaySide == 1)
4928     baseline = 0.2;
4929     
4930   /*
4931   Float_t reference = 0;
4932   if (iaa_icp == 0)
4933     reference = 0.13;
4934   */
4935     
4936   Float_t efficiency = 0.08;
4937   
4938   Float_t centrality = 1;
4939   if (iaa_icp == 0)
4940     centrality = (awaySide == 0) ? 0.02 : 0.06;
4941   else if (iaa_icp == 1)
4942     centrality = (awaySide == 0) ? 0.04 : 0.08;
4943   
4944   Float_t ptResolution = 0;
4945   
4946   Float_t total = TMath::Sqrt(baseline * baseline + efficiency * efficiency + centrality * centrality + ptResolution * ptResolution);
4947   
4948   Printf("Total syst: %f", total);
4949   
4950   systUnc = (TGraphErrors*) graph->Clone();
4951   for (Int_t i=0; i<systUnc->GetN(); i++)
4952   {
4953     systUnc->GetEY()[i] = systUnc->GetY()[i] * total;
4954     systUnc->GetEX()[i] = 0;
4955   }
4956     
4957   //systUnc->Print();
4958   
4959   systUnc->SetLineColor(kGray + 1);
4960   systUnc->SetLineWidth(6);
4961   
4962   systUnc->Draw("PSAME");
4963     
4964   return systUnc;
4965 }
4966
4967 TGraphErrors* DrawSystUncPreliminaries(TGraphErrors* graph, Int_t iaa_icp, Int_t awaySide, Int_t iaa, Bool_t central)
4968 {
4969   // iaa = 0, icp = 1
4970
4971   Float_t baseline = 1;
4972   if (awaySide == 0)
4973     baseline = 0.05;
4974   else if (awaySide == 1)
4975   {
4976     if (iaa == 0 && central || iaa == 1)
4977       baseline = 0.2;
4978     else if (iaa == 0 && !central)
4979       baseline = 0.05;
4980     else if (iaa == 2 && central)
4981       baseline = 0.1;
4982   }
4983     
4984   /*
4985   Float_t reference = 0;
4986   if (iaa_icp == 0)
4987     reference = 0.13;
4988   */
4989     
4990   Float_t efficiency = 0.08;
4991   if (iaa_icp == 1)
4992     efficiency = 0.05;
4993   
4994   Float_t centrality = 1;
4995   if (iaa_icp == 0)
4996     centrality = 0.04;
4997   else if (iaa_icp == 1)
4998     centrality = 0.06;
4999   
5000   Float_t ptResolution = 0.03;
5001   
5002   Float_t integrationWindow = 0;
5003   if (awaySide == 1)
5004     integrationWindow = 0.03;
5005   
5006   Float_t total = TMath::Sqrt(baseline * baseline + efficiency * efficiency + centrality * centrality + ptResolution * ptResolution + integrationWindow * integrationWindow);
5007   
5008   Printf("Total syst: %f", total);
5009   
5010   systUnc = (TGraphErrors*) graph->Clone();
5011   for (Int_t i=0; i<systUnc->GetN(); i++)
5012   {
5013     systUnc->GetEY()[i] = systUnc->GetY()[i] * total;
5014     systUnc->GetEX()[i] = 0;
5015   }
5016     
5017   //systUnc->Print();
5018   
5019   systUnc->SetLineColor(kGray + 1);
5020   systUnc->SetLineWidth(6);
5021   
5022   systUnc->Draw("PSAME");
5023     
5024   return systUnc;
5025 }
5026
5027 TGraphErrors* DrawSystUnc(TGraphErrors* graph, Int_t iaa_icp, Int_t awaySide, Int_t iaa, Bool_t central, Float_t shift = 0.0)
5028 {
5029   // iaa_icp: iaa = 0, icp = 1
5030
5031   Float_t baseline = 1;
5032   if (awaySide == 0)
5033     baseline = 0.05;
5034   else if (awaySide == 1)
5035   {
5036     if (iaa == 0 && central || iaa == 1)
5037       baseline = 0.2;
5038     else if (iaa == 0 && !central)
5039       baseline = 0.05;
5040     else if (iaa == 2 && central)
5041       baseline = 0.1;
5042   }
5043     
5044   /*
5045   Float_t reference = 0;
5046   if (iaa_icp == 0)
5047     reference = 0.13;
5048   */
5049     
5050   Float_t efficiency = 0.04;
5051   
5052   Float_t centrality = 1;
5053   if (iaa_icp == 0)
5054     centrality = 0.02;
5055   else if (iaa_icp == 1)
5056     centrality = 0.03;
5057   
5058   Float_t ptResolution = 0;
5059   
5060   Float_t integrationWindow = 0;
5061   if (awaySide == 1)
5062     integrationWindow = 0.03;
5063   
5064   Float_t corrections = 1;
5065   if (iaa_icp == 0)
5066     corrections = 0.02;
5067   else if (iaa_icp == 1)
5068     corrections = 0.01;
5069   
5070   Float_t twoTrack = 0.01;
5071   
5072   Float_t total = TMath::Sqrt(baseline * baseline + efficiency * efficiency + centrality * centrality + ptResolution * ptResolution + integrationWindow * integrationWindow + corrections * corrections + twoTrack * twoTrack);
5073   
5074   Printf("%f %f %f %f %f %f %f --> Total syst: %f", baseline, efficiency, centrality, ptResolution, integrationWindow, corrections, twoTrack, total);
5075   
5076   systUnc = (TGraphErrors*) graph->Clone();
5077   for (Int_t i=0; i<systUnc->GetN(); i++)
5078   {
5079     systUnc->GetEY()[i] = systUnc->GetY()[i] * total;
5080     systUnc->GetEX()[i] = 0;
5081     Printf("pt = %.2f  y = %.2f +- %.2f (stat.) +- %.2f (syst.)", graph->GetX()[i] - shift, graph->GetY()[i], graph->GetEY()[i], systUnc->GetEY()[i]);
5082   }
5083     
5084   //systUnc->Print();
5085   
5086   systUnc->SetLineColor(kGray + 1);
5087   systUnc->SetLineWidth(4);
5088   
5089   systUnc->Draw("PSAME e2");
5090     
5091   return systUnc;
5092 }
5093
5094 void IAA(const char* fileName, Int_t iaa, const char* fileNameEtaGap = 0)
5095 {
5096   // iaa
5097   // 0 = IAA LHC
5098   // 1 = ICP
5099   // 2 = IAA RHIC
5100   // 3 = IAA LHC with theory
5101   
5102   Bool_t showTheory = 0;
5103   Bool_t showSTAR = 0;
5104
5105   if (iaa == 3)
5106   {
5107     showTheory = kTRUE;
5108     iaa = 0;
5109   }
5110   
5111   if (iaa == 4)
5112   {
5113     showSTAR = kTRUE;
5114     iaa = 0;
5115   }
5116   
5117   if (kPythiaScalingFactor != 1)
5118     Printf("Using reference data scaling factor: %f", kPythiaScalingFactor);
5119
5120   style();
5121   
5122   Int_t j = 1;
5123   Int_t caseId[] = { 18, 23 };
5124
5125   c = new TCanvas((iaa != 1) ? ((iaa == 0) ? "iaa" : "iaarhic") : "icp", (iaa != 1) ? ((iaa == 0) ? "iaa" : "iaarhic") : "icp", 900, 450);
5126   c->Range(0, 0, 1, 1);
5127
5128   TPad* pad1 = new TPad(Form("%s_2", fileName), "", 0, 0, 0.5, 1);
5129   pad1->Draw();
5130
5131   TPad* pad2 = new TPad(Form("%s_1", fileName), "", 0.5, 0, 1, 1);
5132   pad2->Draw();
5133   
5134   pad1->cd();
5135   gPad->SetRightMargin(0);
5136   gPad->SetTopMargin(0.05);
5137   gPad->SetLeftMargin(0.13);
5138   //gPad->SetGridx();
5139 //   gPad->SetGridy();
5140   
5141   pad2->cd();
5142   gPad->SetLeftMargin(0);
5143   gPad->SetTopMargin(0.05);
5144   gPad->SetRightMargin(0.13);
5145   //gPad->SetGridx();
5146 //   gPad->SetGridy();
5147   
5148   pad1->cd();
5149 //   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);
5150   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);
5151   dummy->SetStats(0);
5152 //   dummy->GetYaxis()->SetTitleOffset(1.3);
5153   dummy->GetXaxis()->SetTitleOffset(1.1);
5154   currentDummy = dummy->DrawCopy();
5155   
5156   gStyle->SetTextAlign(13);
5157   
5158   latex = new TLatex(0.17, 0.90, "Near-side_{ }");
5159   latex->SetTextSize(0.04);
5160   latex->SetNDC();
5161   latex->Draw();
5162   
5163 //   if (iaa != 1)
5164 //   {
5165 //     box = new TBox(2, 0.87, 2.5, 1.13);
5166 //     box->SetFillColor(kGray + 1);
5167 //     box->SetLineColor(kGray + 1);
5168 //     box->Draw();
5169 //   
5170 //     box2 = new TBox(2, 0.87 * 1.5, 2.5, 1.13 * 1.5);
5171 //     box2->SetFillColor(kGray + 1);
5172 //     box2->SetLineColor(kGray + 1);
5173 //     box2->Draw();
5174 //   }
5175   
5176   pad2->cd();
5177   currentDummy = dummy->DrawCopy();
5178   
5179 /*  if (iaa != 1)
5180     box->Draw();*/
5181   
5182   latex = new TLatex(0.05, 0.90, "Away-side");
5183   latex->SetTextSize(0.04);
5184   latex->SetNDC();
5185   latex->Draw();
5186   
5187   legend = new TLegend(0.27, (showTheory) ? 0.60 : 0.62, (iaa != 2 && !showSTAR) ? 0.63 : 0.95, 0.77);
5188   legend->SetFillColor(0);
5189   legend->SetBorderSize(0);
5190   legend->SetTextSize((iaa != 2) ? 0.04 : 0.035);
5191   
5192   for (Int_t i=0; i<2; i++)
5193   {
5194     nearSideCentral    = GetRatio(fileName, (iaa != 2) ? 0 : 1, (iaa != 1) ? 3 : 2, j, caseId[i], 0);
5195     if (iaa == 0)
5196       nearSidePeripheral = GetRatio(fileName, 2, 3, j, caseId[i], 0);
5197     awaySideCentral    = GetRatio(fileName, (iaa != 2) ? 0 : 1, (iaa != 1) ? 3 : 2, j, caseId[i], 1);
5198     if (iaa == 0)
5199       awaySidePeripheral = GetRatio(fileName, 2, 3, j, caseId[i], 1);
5200     
5201     RemovePointsBelowX(nearSideCentral, 3);
5202     RemovePointsBelowX(awaySideCentral, 3);
5203     RemovePointsAboveX(nearSideCentral, 10);
5204     RemovePointsAboveX(awaySideCentral, 10);
5205     
5206     RemoveXErrors(nearSideCentral); RemoveXErrors(awaySideCentral);
5207     
5208     if (iaa == 0)
5209     {
5210       RemovePointsBelowX(nearSidePeripheral, 3);
5211       RemovePointsBelowX(awaySidePeripheral, 3);
5212       RemovePointsAboveX(nearSidePeripheral, 10);
5213       RemovePointsAboveX(awaySidePeripheral, 10);
5214       ShiftPoints(nearSidePeripheral, 0.2);
5215       ShiftPoints(awaySidePeripheral, 0.2);
5216       RemoveXErrors(nearSidePeripheral); RemoveXErrors(awaySidePeripheral);
5217     }
5218     
5219     nearSideCentral->SetMarkerStyle(21);
5220     nearSideCentral->SetLineColor(1);
5221     nearSideCentral->SetMarkerColor(1);
5222             
5223     awaySideCentral->SetMarkerStyle(21);
5224     awaySideCentral->SetLineColor(1);
5225     awaySideCentral->SetMarkerColor(1);
5226     
5227     if (showTheory)
5228     {
5229       nearSideCentral->SetLineColor(2);
5230       nearSideCentral->SetMarkerColor(2);
5231       awaySideCentral->SetLineColor(2);
5232       awaySideCentral->SetMarkerColor(2);
5233     }
5234     
5235     if (iaa == 0)
5236     {
5237       nearSidePeripheral->SetMarkerStyle(22);
5238       nearSidePeripheral->SetLineColor(2);
5239       nearSidePeripheral->SetMarkerColor(2);
5240       
5241       awaySidePeripheral->SetMarkerStyle(22);
5242       awaySidePeripheral->SetLineColor(2);
5243       awaySidePeripheral->SetMarkerColor(2);
5244     }
5245     
5246     if (i == 0)
5247     {
5248 //       TString denominatorStr("Pythia");
5249       TString denominatorStr("pp");
5250       if (iaa == 0)
5251       {
5252         legend->AddEntry(nearSideCentral, Form("%s0-5% / %s", (showSTAR) ? "ALICE Pb-Pb 2.76 TeV " : "", denominatorStr.Data()), "P");
5253         if (!showTheory)
5254           legend->AddEntry(nearSidePeripheral, Form("%s60-90% / %s", (showSTAR) ? "ALICE Pb-Pb 2.76 TeV " : "", denominatorStr.Data()), "P");
5255       }
5256       else if (iaa == 2)
5257       {
5258 //         legend->AddEntry(nearSideCentral, Form("0-20% / %s", denominatorStr.Data()), "P");
5259         legend->AddEntry(nearSideCentral, Form("ALICE 8 GeV/#font[12]{c} < p_{T,trig} < 15 GeV/#font[12]{c}", denominatorStr.Data()), "P");
5260       }
5261     }
5262     
5263     
5264     const char* style = "PSAME";
5265     if (i == 1)
5266       style = "LSAMEX";
5267     
5268     awaySideCentral->Print();
5269     
5270     pad1->cd();
5271     if (i == 0)
5272       DrawSystUnc(nearSideCentral, (iaa == 1), 0, iaa, kTRUE);
5273     nearSideCentral->DrawClone(style);
5274     if (iaa == 0 && !showTheory)
5275     {
5276       if (i == 0)
5277         DrawSystUnc(nearSidePeripheral, (iaa == 1), 0, iaa, kFALSE);
5278       nearSidePeripheral->DrawClone(style);        
5279     }
5280     
5281     pad2->cd();
5282     if (i == 0)
5283       DrawSystUnc(awaySideCentral, (iaa == 1), 1, iaa, kTRUE);
5284     awaySideCentral->DrawClone(style);
5285     if (iaa == 0 && !showTheory)
5286     {
5287       if (i == 0)
5288         DrawSystUnc(awaySidePeripheral, (iaa == 1), 1, iaa, kFALSE);
5289       awaySidePeripheral->DrawClone(style);        
5290     }
5291   }
5292   
5293   if (fileNameEtaGap)
5294   {
5295     pad1->cd();
5296     
5297     nearSideEtaGapCentral = GetRatio(fileNameEtaGap, (iaa != 2) ? 0 : 1, (iaa != 1) ? 3 : 2, j, caseId[0], 0);
5298     RemovePointsBelowX(nearSideEtaGapCentral, 3);
5299     RemovePointsAboveX(nearSideEtaGapCentral, 10);
5300     RemoveXErrors(nearSideEtaGapCentral); 
5301     nearSideEtaGapCentral->SetMarkerStyle(25);
5302     nearSideEtaGapCentral->SetLineColor(1);
5303     nearSideEtaGapCentral->SetMarkerColor(1);
5304     nearSideEtaGapCentral->Draw("PSAME");
5305
5306     if (iaa != 1)
5307     {
5308       nearSideEtaGapPeripheral = GetRatio(fileNameEtaGap, 2, 3, j, caseId[0], 0);
5309       RemovePointsBelowX(nearSideEtaGapPeripheral, 3);
5310       RemovePointsAboveX(nearSideEtaGapPeripheral, 10);
5311       RemoveXErrors(nearSideEtaGapPeripheral); 
5312       ShiftPoints(nearSideEtaGapPeripheral, 0.2);
5313       nearSideEtaGapPeripheral->SetMarkerStyle(26);
5314       nearSideEtaGapPeripheral->SetLineColor(2);
5315       nearSideEtaGapPeripheral->SetMarkerColor(2);
5316       nearSideEtaGapPeripheral->Draw("PSAME");
5317     }
5318   }
5319   
5320   if (iaa == 2)
5321   {
5322     // IAA, RHIC, PHENIX
5323     // systematic uncertainty stored in graph with _sys appended
5324     TFile::Open("rhic/pi0h_graphs.root");
5325     
5326     legend2 = new TLegend(0.5, 0.16, 0.96, 0.27);
5327     legend2->SetFillColor(0);
5328     
5329     for (Int_t ptTrigBin=2; ptTrigBin<4; ptTrigBin++)
5330     {
5331       Bool_t central = kTRUE;
5332       for (Int_t i=0; i<3; i+=2)
5333       {
5334         // gIAA_<ptTrigBin>_<centBin>_<angularRegionBin>
5335         rhic_iaa = (TGraphErrors*) gFile->Get(Form("gIAA_%d_%d_%d", ptTrigBin, (central) ? 0 : 1, i));
5336         rhic_iaa_sys = (TGraphErrors*) gFile->Get(Form("gIAA_%d_%d_%d_sys", ptTrigBin, (central) ? 0 : 1, i));
5337     
5338         rhic_iaa->SetMarkerStyle((ptTrigBin == 2) ? 20 : 33);
5339         rhic_iaa->SetMarkerColor(2);
5340         rhic_iaa->SetLineColor(2);
5341         rhic_iaa_sys->SetLineColor(2);
5342         rhic_iaa_sys->SetMarkerColor(2);
5343         
5344         RemovePointsBelowX(rhic_iaa, 2);
5345         RemovePointsBelowX(rhic_iaa_sys, 2);
5346         
5347         Printf("RHIC:");
5348         rhic_iaa->Print();
5349         rhic_iaa_sys->Print();
5350         
5351         ShiftPoints(rhic_iaa, -0.05 + 0.05 * (ptTrigBin*2-4));
5352         ShiftPoints(rhic_iaa_sys, -0.05 + 0.05 * (ptTrigBin*2-4));
5353         
5354         if (i == 0)
5355           pad1->cd();
5356         else if (i == 2)
5357           pad2->cd();
5358         rhic_iaa->Draw("PSAME");
5359         rhic_iaa_sys->Draw("PSAME");
5360         
5361         if (i == 0)
5362           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");
5363 //           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");
5364       }
5365     }
5366     
5367 //     pad1->cd();
5368 //     legend2->Draw();
5369   }
5370
5371   if (iaa == 0 && showSTAR)
5372   {
5373     for (Int_t i=0; i<2; i++)
5374     {
5375       const char* centralityStr = "05";
5376       if (i == 1)
5377         centralityStr = "4080";
5378       
5379       // IAA, RHIC, STAR
5380       // systematic uncertainty stored in graph with _sys appended
5381       nearSide = ReadHepdata(Form("rhic/star_iaa_%s_near.txt", centralityStr));
5382       awaySide = ReadHepdata(Form("rhic/star_iaa_%s_away.txt", centralityStr));
5383       
5384       nearSide->SetMarkerStyle(20 + i * 13);
5385       nearSide->SetMarkerColor(4);
5386       nearSide->SetLineColor(4);
5387       
5388       awaySide->SetMarkerStyle(20 + i * 13);
5389       awaySide->SetMarkerColor(4);
5390       awaySide->SetLineColor(4);
5391
5392       ShiftPoints(nearSide, -0.1 + 0.2 * i);
5393       ShiftPoints(awaySide, -0.1 + 0.2 * i);
5394           
5395       pad1->cd();
5396       nearSide->Draw("PSAME");
5397       pad2->cd();
5398       awaySide->Draw("PSAME");
5399         
5400       legend->AddEntry(nearSide, Form("STAR Au-Au 0.2 TeV %s / dAu", (i == 0) ? "0-5%" : "40-80%"), "P");
5401     }
5402   }
5403
5404   // Theory predictions
5405   if (showTheory && iaa == 0)
5406   {
5407     const char* theoryList[] = { "AdS", "ASW", "YaJEM", "YaJEM-D", "XinNian" };
5408     Int_t nTheory = 5;
5409     Int_t markers[] = { 27, 28, 29, 30, 34 };
5410     
5411     for (Int_t i=0; i<nTheory; i++)
5412     {
5413       nearSide = ReadHepdata(Form("theory/IAA_near_%s.dat", theoryList[i]));
5414       awaySide = ReadHepdata(Form("theory/IAA_away_%s.dat", theoryList[i]));
5415       
5416       nearSide->SetMarkerStyle(markers[i]);
5417       awaySide->SetMarkerStyle(markers[i]);
5418       
5419       RemovePointsBelowX(nearSide, 3);
5420       RemovePointsBelowX(awaySide, 3);
5421       
5422       Float_t shiftBy = (i % 2 == 0) ? -0.2 : 0.2;
5423       ShiftPoints(nearSide, shiftBy);
5424       ShiftPoints(awaySide, shiftBy);
5425       
5426       pad1->cd();
5427       nearSide->Draw("PSAME");
5428       
5429       pad2->cd();
5430       awaySide->Draw("PSAME");
5431       
5432       if (i == 0)
5433           theoryList[i] = "AdS/CFT";
5434       if (i == 4)
5435           theoryList[i] = "X-N Wang";
5436       legend->AddEntry(nearSide, theoryList[i], "P");
5437     }
5438   }
5439   
5440   for (Int_t i=0; i<2; i++)
5441   {
5442     if (i == 0)
5443       pad1->cd();
5444     else
5445       pad2->cd();
5446       
5447     Float_t xC = 0.05;
5448     if (i == 0)
5449       xC = 0.17;
5450
5451     if (iaa == 2)
5452       latex = new TLatex(xC, 0.84, "0-20% / pp");
5453     else
5454       latex = new TLatex(0.35+xC, 0.9, "8 GeV/#font[12]{c} < p_{T,trig} < 15 GeV/#font[12]{c}");
5455     latex->SetTextSize(0.04);
5456     latex->SetNDC();
5457     if (i == 0)
5458       latex->Draw();
5459     
5460     line = new TLine(1.5, 1, 10.5, 1);
5461     line->SetLineStyle(2);
5462     line->Draw();
5463   
5464     if (iaa == 1)
5465     {
5466       latex = new TLatex(xC, 0.84, "0-5% / 60-90%");
5467       latex->SetTextSize(0.04);
5468       latex->SetNDC();
5469       latex->Draw();
5470     }
5471   
5472     latex = new TLatex(0.65+xC, 0.90, "ALICE");
5473 //     latex = new TLatex(0.5+xC, 0.90, "-- work in progress --");
5474     latex->SetTextSize(0.04);
5475     latex->SetNDC();
5476     if (i == 1)
5477       latex->Draw();
5478     
5479     latex = new TLatex(0.35+xC, 0.84, "p_{T,assoc} < p_{T,trig}");
5480     latex->SetTextSize(0.04);
5481     latex->SetNDC();
5482     if (i == 0)
5483       latex->Draw();
5484     
5485     if (iaa == 1 || iaa == 0)
5486     {
5487       if (iaa == 0 && showSTAR)
5488         latex = new TLatex(0.3+xC, 0.90, "|#eta| < 1.0");
5489       else
5490         latex = new TLatex(xC + 0.65, 0.20, "|#eta| < 1.0");
5491       latex->SetTextSize(0.04);
5492       latex->SetNDC();
5493       if (i == 0)
5494         latex->Draw();
5495     }
5496     
5497     if (iaa == 1 || (iaa == 0 && !showSTAR))
5498     {
5499       latex = new TLatex(0.5+xC, 0.72, "Pb-Pb 2.76 TeV");
5500       latex->SetTextSize(0.04);
5501       latex->SetNDC();
5502 //       latex->Draw();
5503     }
5504     
5505     if (iaa == 2)
5506     {
5507       if (i == 0)
5508         latex = new TLatex(0.5, 0.24, "ALICE: Pb-Pb 2.76 TeV |#eta| < 1.0");
5509       else
5510         latex = new TLatex(xC, 0.6, "ALICE: Pb-Pb 2.76 TeV |#eta| < 1.0");
5511       latex->SetTextSize(0.035);
5512       latex->SetNDC();
5513       latex->Draw();
5514       
5515       if (i == 0)
5516         latex = new TLatex(0.5, 0.18, "PHENIX: Au-Au 0.2 TeV |#eta| < 0.35");
5517       else
5518         latex = new TLatex(xC, 0.54, "PHENIX: Au-Au 0.2 TeV |#eta| < 0.35");
5519       latex->SetTextSize(0.035);
5520       latex->SetNDC();
5521       latex->Draw();
5522     }
5523     
5524     if (showTheory && iaa == 0 && i == 1)
5525       latex = new TLatex(xC, 0.18, "Points: flat pedestal");
5526     else
5527       latex = new TLatex(xC + 0.5 * i, 0.26, "Points: flat pedestal");
5528     latex->SetTextSize(0.04);
5529     latex->SetNDC();
5530     if (i == 0)
5531       latex->Draw();
5532   
5533     latex = new TLatex(xC + 0.5 * i, 0.20, "Line: v_{2} subtracted");
5534     latex->SetTextSize(0.04);
5535     latex->SetNDC();
5536     if (i == 0)
5537       latex->Draw();
5538     
5539     if (iaa != 1 && i == 1)
5540     {
5541       legendClone = (TLegend*) legend->DrawClone();
5542       if (showTheory && iaa == 0 && i == 0)
5543         legendClone->GetListOfPrimitives()->RemoveLast();
5544 //       else
5545 //      legendClone->SetY1(legendClone->GetY1()-0.05);
5546         
5547       legend->SetX1(legend->GetX1()-0.12);
5548       legend->SetX2(legend->GetX2()-0.12);
5549     }
5550
5551 /*    if (i == 0 && iaa != 2)
5552       DrawALICELogo(0.83,0.15,0.98,0.30);
5553     else
5554       DrawALICELogo(0.62 + xC,0.48,0.77 + xC,0.63);*/
5555   }
5556   
5557   c->SaveAs(Form("%s.eps", c->GetTitle()));
5558   c->SaveAs(Form("%s.png", c->GetTitle()));
5559 }
5560
5561 void IAAPaper(const char* fileName, Int_t iaa, const char* fileNameEtaGap = 0)
5562 {
5563   // iaa
5564   // 0 = IAA LHC
5565   // 1 = ICP
5566   
5567   Bool_t showTheory = 0;
5568   Bool_t showSTAR = 0;
5569
5570   if (iaa == 3)
5571   {
5572     showTheory = kTRUE;
5573     iaa = 0;
5574   }
5575   
5576   if (iaa == 4)
5577   {
5578     showSTAR = kTRUE;
5579     iaa = 0;
5580   }
5581   
5582   if (kPythiaScalingFactor != 1)
5583     Printf("Using reference data scaling factor: %f", kPythiaScalingFactor);
5584
5585   style();
5586   
5587   Int_t j = 1;
5588   Int_t caseId[] = { 18, 23 };
5589
5590   c = new TCanvas((iaa != 1) ? ((iaa == 0) ? "iaa" : "iaarhic") : "icp", (iaa != 1) ? ((iaa == 0) ? "iaa" : "iaarhic") : "icp", 900, 450);
5591   c->Range(0, 0, 1, 1);
5592
5593   TPad* pad1 = new TPad(Form("%s_2", fileName), "", 0, 0, 0.5, 1);
5594   pad1->Draw();
5595
5596   TPad* pad2 = new TPad(Form("%s_1", fileName), "", 0.5, 0, 1, 1);
5597   pad2->Draw();
5598   
5599   pad1->cd();
5600   gPad->SetRightMargin(0);
5601   gPad->SetTopMargin(0.05);
5602   gPad->SetLeftMargin(0.13);
5603   //gPad->SetGridx();
5604 //   gPad->SetGridy();
5605   
5606   pad2->cd();
5607   gPad->SetLeftMargin(0);
5608   gPad->SetTopMargin(0.05);
5609   gPad->SetRightMargin(0.13);
5610   //gPad->SetGridx();
5611 //   gPad->SetGridy();
5612   
5613   pad1->cd();
5614 //   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);
5615   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);
5616   dummy->SetStats(0);
5617 //   dummy->GetYaxis()->SetTitleOffset(1.3);
5618   dummy->GetXaxis()->SetTitleOffset(1.1);
5619   currentDummy = dummy->DrawCopy();
5620   
5621   gStyle->SetTextAlign(13);
5622   
5623   latex = new TLatex(0.17, 0.90, "Near-side_{ }");
5624   latex->SetTextSize(0.04);
5625   latex->SetNDC();
5626   latex->Draw();
5627   
5628   latex = new TLatex(0.17, /*(iaa == 1) ? 0.78 :*/ 0.84, "#sqrt{#font[12]{s}_{NN}} = 2.76 TeV");
5629   latex->SetTextSize(0.04);
5630   latex->SetNDC();
5631   latex->Draw();
5632
5633   latex = new TLatex(0.17, 0.2, (iaa == 1) ? "b)" : "a)");
5634   latex->SetTextSize(0.04);
5635   latex->SetNDC();
5636   latex->Draw();
5637   
5638 //   if (iaa != 1)
5639 //   {
5640 //     box = new TBox(2, 0.87, 2.5, 1.13);
5641 //     box->SetFillColor(kGray + 1);
5642 //     box->SetLineColor(kGray + 1);
5643 //     box->Draw();
5644 //   
5645 //     box2 = new TBox(2, 0.87 * 1.5, 2.5, 1.13 * 1.5);
5646 //     box2->SetFillColor(kGray + 1);
5647 //     box2->SetLineColor(kGray + 1);
5648 //     box2->Draw();
5649 //   }
5650   
5651   pad2->cd();
5652   currentDummy = dummy->DrawCopy();
5653   
5654 /*  if (iaa != 1)
5655     box->Draw();*/
5656   
5657   latex = new TLatex(0.05, 0.90, "Away-side");
5658   latex->SetTextSize(0.04);
5659   latex->SetNDC();
5660   latex->Draw();
5661
5662   if (iaa == 1)
5663     legend = new TLegend(0.22, 0.60, 0.67, 0.73);
5664   else
5665     legend = new TLegend(0.12, 0.60, 0.76, 0.79);
5666   legend->SetFillColor(0);
5667   legend->SetBorderSize(0);
5668   legend->SetTextSize((iaa != 2) ? 0.04 : 0.035);
5669   
5670   for (Int_t i=0; i<2; i++)
5671   {
5672     nearSideCentral    = GetRatio(fileName, (iaa != 2) ? 0 : 1, (iaa != 1) ? 3 : 2, j, caseId[i], 0);
5673     if (iaa == 0)
5674       nearSidePeripheral = GetRatio(fileName, 2, 3, j, caseId[i], 0);
5675     awaySideCentral    = GetRatio(fileName, (iaa != 2) ? 0 : 1, (iaa != 1) ? 3 : 2, j, caseId[i], 1);
5676     if (iaa == 0)
5677       awaySidePeripheral = GetRatio(fileName, 2, 3, j, caseId[i], 1);
5678     
5679     RemovePointsBelowX(nearSideCentral, 3);
5680     RemovePointsBelowX(awaySideCentral, 3);
5681     RemovePointsAboveX(nearSideCentral, 10);
5682     RemovePointsAboveX(awaySideCentral, 10);
5683
5684     ShiftPoints(nearSideCentral, -0.05);
5685     ShiftPoints(awaySideCentral, -0.05);
5686
5687     if (i == 1)
5688     {
5689       ShiftPoints(nearSideCentral, -0.2);
5690       ShiftPoints(awaySideCentral, -0.2);
5691       
5692       if (iaa == 0)
5693       {
5694         ShiftPoints(nearSidePeripheral, 0.2);
5695         ShiftPoints(awaySidePeripheral, 0.2);
5696       }
5697     }
5698     
5699     RemoveXErrors(nearSideCentral); RemoveXErrors(awaySideCentral);
5700     
5701     if (iaa == 0)
5702     {
5703       RemovePointsBelowX(nearSidePeripheral, 3);
5704       RemovePointsBelowX(awaySidePeripheral, 3);
5705       RemovePointsAboveX(nearSidePeripheral, 10);
5706       RemovePointsAboveX(awaySidePeripheral, 10);
5707       ShiftPoints(nearSidePeripheral, 0.05);
5708       ShiftPoints(awaySidePeripheral, 0.05);
5709       RemoveXErrors(nearSidePeripheral); RemoveXErrors(awaySidePeripheral);
5710     }
5711     
5712     nearSideCentral->SetMarkerStyle((i == 0) ? 25 : 27);
5713     nearSideCentral->SetLineColor(1);
5714     nearSideCentral->SetMarkerColor(1);
5715             
5716     awaySideCentral->SetMarkerStyle((i == 0) ? 25 : 27);
5717     awaySideCentral->SetLineColor(1);
5718     awaySideCentral->SetMarkerColor(1);
5719     
5720     if (showTheory)
5721     {
5722       nearSideCentral->SetLineColor(2);
5723       nearSideCentral->SetMarkerColor(2);
5724       awaySideCentral->SetLineColor(2);
5725       awaySideCentral->SetMarkerColor(2);
5726     }
5727     
5728     if (iaa == 0)
5729     {
5730       nearSidePeripheral->SetMarkerStyle((i == 0) ? 21 : 33);
5731       nearSidePeripheral->SetLineColor(2);
5732       nearSidePeripheral->SetMarkerColor(2);
5733       
5734       awaySidePeripheral->SetMarkerStyle((i == 0) ? 21 : 33);
5735       awaySidePeripheral->SetLineColor(2);
5736       awaySidePeripheral->SetMarkerColor(2);
5737     }
5738     
5739 //     if (i == 0)
5740     {
5741 //       TString denominatorStr("Pythia");
5742       TString denominatorStr("pp");
5743       if (iaa == 0)
5744       {
5745         legend->SetHeader("0-5% Pb-Pb/pp     60-90% Pb-Pb/pp");
5746         legend->SetNColumns(2);
5747       }
5748       legend->AddEntry(nearSideCentral, (i == 0) ? "Flat bkg" : "#font[12]{v}_{2} bkg", "P");
5749       if (iaa == 0)
5750         legend->AddEntry(nearSidePeripheral, (i == 0) ? "Flat bkg" : "#font[12]{v}_{2} bkg", "P");
5751         
5752 //         legend->AddEntry(nearSideCentral, Form("%s0-5% / %s", (showSTAR) ? "ALICE Pb-Pb 2.76 TeV " : "", denominatorStr.Data()), "P");
5753 //      if (!showTheory)
5754 //        legend->AddEntry(nearSidePeripheral, Form("%s60-90% / %s", (showSTAR) ? "ALICE Pb-Pb 2.76 TeV " : "", denominatorStr.Data()), "P");
5755       if (iaa == 2)
5756       {
5757 //         legend->AddEntry(nearSideCentral, Form("0-20% / %s", denominatorStr.Data()), "P");
5758         legend->AddEntry(nearSideCentral, Form("ALICE 8 GeV/#font[12]{c} < p_{T,trig} < 15 GeV/#font[12]{c}", denominatorStr.Data()), "P");
5759       }
5760     }
5761     
5762     
5763     const char* style = "PSAME";
5764 //     if (i == 1)
5765 //       style = "LSAMEX";
5766     
5767     pad1->cd();
5768 //     if (i == 0)
5769       DrawSystUnc(nearSideCentral, (iaa == 1), 0, iaa, kTRUE, -0.05 - 0.2 * i);
5770     nearSideCentral->DrawClone(style);
5771     if (iaa == 0 && !showTheory)
5772     {
5773 //       if (i == 0)
5774         DrawSystUnc(nearSidePeripheral, (iaa == 1), 0, iaa, kFALSE, 0.05 + ((iaa == 0) ? i * 0.2 : 0));
5775       nearSidePeripheral->DrawClone(style);        
5776     }
5777     
5778     pad2->cd();
5779 //     if (i == 0)
5780       DrawSystUnc(awaySideCentral, (iaa == 1), 1, iaa, kTRUE, -0.05 - 0.2 * i);
5781     awaySideCentral->DrawClone(style);
5782     if (iaa == 0 && !showTheory)
5783     {
5784 //       if (i == 0)
5785         DrawSystUnc(awaySidePeripheral, (iaa == 1), 1, iaa, kFALSE, 0.05 + ((iaa == 0) ? i * 0.2 : 0));
5786       awaySidePeripheral->DrawClone(style);        
5787     }
5788   }
5789   
5790   if (fileNameEtaGap)
5791   {
5792     pad1->cd();
5793     
5794     nearSideEtaGapCentral = GetRatio(fileNameEtaGap, (iaa != 2) ? 0 : 1, (iaa != 1) ? 3 : 2, j, caseId[0], 0);
5795     RemovePointsBelowX(nearSideEtaGapCentral, 3);
5796     RemovePointsAboveX(nearSideEtaGapCentral, 10);
5797     RemoveXErrors(nearSideEtaGapCentral); 
5798     nearSideEtaGapCentral->SetMarkerStyle(24);
5799     nearSideEtaGapCentral->SetLineColor(1);
5800     nearSideEtaGapCentral->SetMarkerColor(1);
5801     ShiftPoints(nearSideEtaGapCentral, -0.45);
5802     DrawSystUnc(nearSideEtaGapCentral, (iaa == 1), 0, iaa, kTRUE, -0.45);
5803     nearSideEtaGapCentral->Draw("PSAME");
5804
5805     legend->AddEntry(nearSideEtaGapCentral, "#font[12]{#eta}-gap", "P");
5806
5807
5808     if (iaa != 1)
5809     {
5810       nearSideEtaGapPeripheral = GetRatio(fileNameEtaGap, 2, 3, j, caseId[0], 0);
5811       RemovePointsBelowX(nearSideEtaGapPeripheral, 3);
5812       RemovePointsAboveX(nearSideEtaGapPeripheral, 10);
5813       RemoveXErrors(nearSideEtaGapPeripheral); 
5814       nearSideEtaGapPeripheral->SetMarkerStyle(20);
5815       nearSideEtaGapPeripheral->SetLineColor(2);
5816       nearSideEtaGapPeripheral->SetMarkerColor(2);
5817       ShiftPoints(nearSideEtaGapPeripheral, 0.45);
5818       DrawSystUnc(nearSideEtaGapPeripheral, (iaa == 1), 0, iaa, kFALSE, 0.45);
5819       nearSideEtaGapPeripheral->Draw("PSAME");
5820
5821       legend->AddEntry(nearSideEtaGapPeripheral, "#font[12]{#eta}-gap", "P");
5822     }
5823   }
5824   
5825   if (0 && iaa == 0)
5826   {
5827     // add pythia line showing gluon filtering
5828     // from Jan Rak, by mail, 22.09.11
5829     // pp CF calculated without any adjustment
5830     // AA CF also no adjustment. Particles (h+-) in acceptance are identified with their parent string parton (status 71)
5831     // and the flavor of parent hard outgoing parton (status 23) which is  the parent of string parton 71 is checked.
5832     // If it is a gluon the  particle is ignored.
5833     
5834     Float_t xVal[] = { 3.5, 4.5, 5.5, 7, 9};
5835     Float_t yVal[] = { 0.779418, 0.794234, 0.82759, 0.856457, 0.880526 };
5836     gluonfiltering = new TGraph(5, xVal, yVal);
5837     pad1->cd();
5838     gluonfiltering->Draw("L");
5839     
5840     legend3 = new TLegend(0.38, 0.15, 0.58, 0.25);
5841     legend3->SetFillColor(0);
5842     legend3->SetBorderSize(0);
5843     legend3->SetTextSize(0.04);
5844     legend3->AddEntry(gluonfiltering, "PYTHIA quark-only fragmentation", "L");
5845     legend3->Draw();
5846   }
5847   
5848   if (iaa == 2)
5849   {
5850     // IAA, RHIC, PHENIX
5851     // systematic uncertainty stored in graph with _sys appended
5852     TFile::Open("rhic/pi0h_graphs.root");
5853     
5854     legend2 = new TLegend(0.5, 0.16, 0.96, 0.27);
5855     legend2->SetFillColor(0);
5856     
5857     for (Int_t ptTrigBin=2; ptTrigBin<4; ptTrigBin++)
5858     {
5859       Bool_t central = kTRUE;
5860       for (Int_t i=0; i<3; i+=2)
5861       {
5862         // gIAA_<ptTrigBin>_<centBin>_<angularRegionBin>
5863         rhic_iaa = (TGraphErrors*) gFile->Get(Form("gIAA_%d_%d_%d", ptTrigBin, (central) ? 0 : 1, i));
5864         rhic_iaa_sys = (TGraphErrors*) gFile->Get(Form("gIAA_%d_%d_%d_sys", ptTrigBin, (central) ? 0 : 1, i));
5865     
5866         rhic_iaa->SetMarkerStyle((ptTrigBin == 2) ? 20 : 33);
5867         rhic_iaa->SetMarkerColor(2);
5868         rhic_iaa->SetLineColor(2);
5869         rhic_iaa_sys->SetLineColor(2);
5870         rhic_iaa_sys->SetMarkerColor(2);
5871         
5872         ShiftPoints(rhic_iaa, -0.05 + 0.05 * (ptTrigBin*2-4));
5873         ShiftPoints(rhic_iaa_sys, -0.05 + 0.05 * (ptTrigBin*2-4));
5874         
5875         if (i == 0)
5876           pad1->cd();
5877         else if (i == 2)
5878           pad2->cd();
5879         rhic_iaa->Draw("PSAME");
5880         rhic_iaa_sys->Draw("PSAME");
5881         
5882         if (i == 0)
5883           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");
5884 //           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");
5885       }
5886     }
5887     
5888 //     pad1->cd();
5889 //     legend2->Draw();
5890   }
5891
5892   if (iaa == 0 && showSTAR)
5893   {
5894     for (Int_t i=0; i<2; i++)
5895     {
5896       const char* centralityStr = "05";
5897       if (i == 1)
5898         centralityStr = "4080";
5899       
5900       // IAA, RHIC, STAR
5901       // systematic uncertainty stored in graph with _sys appended
5902       nearSide = ReadHepdata(Form("rhic/star_iaa_%s_near.txt", centralityStr));
5903       awaySide = ReadHepdata(Form("rhic/star_iaa_%s_away.txt", centralityStr));
5904       
5905       nearSide->SetMarkerStyle(20 + i * 13);
5906       nearSide->SetMarkerColor(4);
5907       nearSide->SetLineColor(4);
5908       
5909       awaySide->SetMarkerStyle(20 + i * 13);
5910       awaySide->SetMarkerColor(4);
5911       awaySide->SetLineColor(4);
5912
5913       ShiftPoints(nearSide, -0.1 + 0.2 * i);
5914       ShiftPoints(awaySide, -0.1 + 0.2 * i);
5915           
5916       pad1->cd();
5917       nearSide->Draw("PSAME");
5918       pad2->cd();
5919       awaySide->Draw("PSAME");
5920         
5921       legend->AddEntry(nearSide, Form("STAR Au-Au 0.2 TeV %s / dAu", (i == 0) ? "0-5%" : "40-80%"), "P");
5922     }
5923   }
5924
5925   // Theory predictions
5926   if (showTheory && iaa == 0)
5927   {
5928     const char* theoryList[] = { "AdS", "ASW", "YaJEM", "YaJEM-D", "XinNian" };
5929     Int_t nTheory = 5;
5930     Int_t markers[] = { 27, 28, 29, 30, 34 };
5931     
5932     for (Int_t i=0; i<nTheory; i++)
5933     {
5934       nearSide = ReadHepdata(Form("theory/IAA_near_%s.dat", theoryList[i]));
5935       awaySide = ReadHepdata(Form("theory/IAA_away_%s.dat", theoryList[i]));
5936       
5937       nearSide->SetMarkerStyle(markers[i]);
5938       awaySide->SetMarkerStyle(markers[i]);
5939       
5940       RemovePointsBelowX(nearSide, 3);
5941       RemovePointsBelowX(awaySide, 3);
5942       
5943       Float_t shiftBy = (i % 2 == 0) ? -0.2 : 0.2;
5944       ShiftPoints(nearSide, shiftBy);
5945       ShiftPoints(awaySide, shiftBy);
5946       
5947       pad1->cd();
5948       nearSide->Draw("PSAME");
5949       
5950       pad2->cd();
5951       awaySide->Draw("PSAME");
5952       
5953       if (i == 0)
5954           theoryList[i] = "AdS/CFT";
5955       if (i == 4)
5956           theoryList[i] = "X-N Wang";
5957       legend->AddEntry(nearSide, theoryList[i], "P");
5958     }
5959   }
5960   
5961   for (Int_t i=0; i<2; i++)
5962   {
5963     if (i == 0)
5964       pad1->cd();
5965     else
5966       pad2->cd();
5967       
5968     Float_t xC = 0.05;
5969     if (i == 0)
5970       xC = 0.17;
5971
5972     if (iaa == 2)
5973       latex = new TLatex(xC, 0.84, "0-20% / pp");
5974     else
5975       latex = new TLatex(0.35+xC, 0.9, "8 GeV/#font[12]{c} < #font[12]{p}_{t,trig} < 15 GeV/#font[12]{c}");
5976     latex->SetTextSize(0.04);
5977     latex->SetNDC();
5978     if (i == 0)
5979       latex->Draw();
5980     
5981     line = new TLine(1.5, 1, 10.5, 1);
5982     line->SetLineStyle(2);
5983     line->Draw();
5984   
5985 //     if (iaa == 1 && i == 0)
5986 //     {
5987 //       latex = new TLatex(xC, 0.84, "0-5% / 60-90%");
5988 //       latex->SetTextSize(0.04);
5989 //       latex->SetNDC();
5990 //       latex->Draw();
5991 //     }
5992   
5993     latex = new TLatex(0.65+xC, 0.90, "ALICE");
5994 //     latex = new TLatex(0.5+xC, 0.90, "-- work in progress --");
5995     latex->SetTextSize(0.04);
5996     latex->SetNDC();
5997     if (i == 1)
5998       latex->Draw();
5999     
6000     latex = new TLatex(0.35+xC, 0.84, "#font[12]{p}_{t,assoc} < #font[12]{p}_{t,trig}");
6001     latex->SetTextSize(0.04);
6002     latex->SetNDC();
6003     if (i == 0)
6004       latex->Draw();
6005     
6006     if (iaa == 1 || iaa == 0)
6007     {
6008       if (iaa == 0 && showSTAR)
6009         latex = new TLatex(0.3+xC, 0.90, "|#font[12]{#eta}| < 1.0");
6010       else
6011         latex = new TLatex(0.82, 0.84, "|#font[12]{#eta}| < 1.0");
6012       latex->SetTextSize(0.04);
6013       latex->SetNDC();
6014       if (i == 0)
6015         latex->Draw();
6016     }
6017     
6018     if (iaa == 1 || (iaa == 0 && !showSTAR))
6019     {
6020       latex = new TLatex(0.5+xC, 0.72, "Pb-Pb 2.76 TeV");
6021       latex->SetTextSize(0.04);
6022       latex->SetNDC();
6023 //       latex->Draw();
6024     }
6025     
6026     if (iaa == 2)
6027     {
6028       if (i == 0)
6029         latex = new TLatex(0.5, 0.24, "ALICE: Pb-Pb 2.76 TeV |#eta| < 1.0");
6030       else
6031         latex = new TLatex(xC, 0.6, "ALICE: Pb-Pb 2.76 TeV |#eta| < 1.0");
6032       latex->SetTextSize(0.035);
6033       latex->SetNDC();
6034       latex->Draw();
6035       
6036       if (i == 0)
6037         latex = new TLatex(0.5, 0.18, "PHENIX: Au-Au 0.2 TeV |#eta| < 0.35");
6038       else
6039         latex = new TLatex(xC, 0.54, "PHENIX: Au-Au 0.2 TeV |#eta| < 0.35");
6040       latex->SetTextSize(0.035);
6041       latex->SetNDC();
6042       latex->Draw();
6043     }
6044     
6045     if (i == 1)
6046     {
6047       legendClone = (TLegend*) legend->DrawClone();
6048       if (showTheory && iaa == 0 && i == 0)
6049         legendClone->GetListOfPrimitives()->RemoveLast();
6050 //       else
6051 //      legendClone->SetY1(legendClone->GetY1()-0.05);
6052         
6053       legend->SetX1(legend->GetX1()-0.12);
6054       legend->SetX2(legend->GetX2()-0.12);
6055     }
6056     
6057     
6058
6059 /*    if (i == 0 && iaa != 2)
6060       DrawALICELogo(0.83,0.15,0.98,0.30);
6061     else
6062       DrawALICELogo(0.62 + xC,0.48,0.77 + xC,0.63);*/
6063   }
6064   
6065   c->SaveAs(Form("%s.eps", c->GetTitle()));
6066   c->SaveAs(Form("%s.png", c->GetTitle()));
6067 }
6068
6069
6070 void DrawALICELogo(Float_t x1, Float_t y1, Float_t x2, Float_t y2, Bool_t debug = kFALSE)
6071 {
6072   DrawALICELogo(kTRUE, x1, y1, x2, y2, debug);
6073 }
6074
6075 void DrawALICELogo(Bool_t prel, Float_t x1, Float_t y1, Float_t x2, Float_t y2, Bool_t debug = kFALSE)
6076 {
6077   // correct for aspect ratio of figure plus aspect ratio of pad (coordinates are NDC!)
6078 //   Printf("%d %f %d %f", gPad->GetCanvas()->GetWindowHeight(), gPad->GetHNDC(), gPad->GetCanvas()->GetWindowWidth(), gPad->GetWNDC());
6079   //x2 = x1 + (y2 - y1) * 0.891 * gPad->GetCanvas()->GetWindowHeight() * gPad->GetHNDC() / (gPad->GetWNDC() * gPad->GetCanvas()->GetWindowWidth());
6080   x2 = x1 + (y2 - y1) * (466. / 523) * gPad->GetWh() * gPad->GetHNDC() / (gPad->GetWNDC() * gPad->GetWw());
6081 //   Printf("%f %f %f %f", x1, x2, y1, y2);
6082   
6083   if (!prel)
6084     DrawLatex((x1+x2)/2, y1, 1, "09.05.12", 0.03)->SetTextAlign(23);
6085   TPad *myPadLogo = new TPad("myPadLogo", "Pad for ALICE Logo", x1, y1, x2, y2);
6086   if (debug)
6087     myPadLogo->SetFillColor(2); // color to first figure out where is the pad then comment !
6088   myPadLogo->SetLeftMargin(0);
6089   myPadLogo->SetTopMargin(0);
6090   myPadLogo->SetRightMargin(0);
6091   myPadLogo->SetBottomMargin(0);
6092   myPadLogo->Draw();
6093   myPadLogo->cd();
6094 //   TASImage *myAliceLogo = new TASImage("~/alice_logo_transparent.png");
6095   TASImage *myAliceLogo = new TASImage((prel) ? "~/alice_logo_preliminary.eps" : "~/alice_logo_performance.eps");
6096   myAliceLogo->Draw();
6097 }
6098
6099 void RemoveXErrors(TGraphErrors* graph)
6100 {
6101         for (Int_t i=0; i<graph->GetN(); i++)
6102                 graph->GetEX()[i] = 0;
6103 }
6104
6105 void RemovePointsBelowX(TGraphErrors* graph, Float_t minX)
6106 {
6107   Int_t i=0;
6108   while (i<graph->GetN())
6109   {
6110     if (graph->GetX()[i] < minX)
6111       graph->RemovePoint(i);
6112     else
6113       i++;
6114   }
6115 }
6116
6117 void RemovePointsAboveX(TGraphErrors* graph, Float_t maxX)
6118 {
6119   Int_t i=0;
6120   while (i<graph->GetN())
6121   {
6122     if (graph->GetX()[i] > maxX)
6123       graph->RemovePoint(i);
6124     else
6125       i++;
6126   }
6127 }
6128
6129 void ShiftPoints(TGraphErrors* graph, Float_t dx)
6130 {
6131   Int_t i=0;
6132   while (i<graph->GetN())
6133   {
6134     graph->GetX()[i] += dx;
6135     i++;
6136   }
6137 }
6138
6139 void DivideGraphs(TGraphErrors* graph1, TGraphErrors* graph2)
6140 {
6141   graph1->Print();
6142   graph2->Print();
6143
6144   for (Int_t bin1 = 0; bin1 < graph1->GetN(); bin1++)
6145   {
6146     Float_t x = graph1->GetX()[bin1];
6147
6148     Int_t bin2 = 0;
6149     for (bin2 = 0; bin2<graph2->GetN(); bin2++)
6150       if (graph2->GetX()[bin2] >= x)
6151         break;
6152
6153     if (bin2 == graph2->GetN())
6154             bin2--;
6155
6156     if (bin2 > 0)
6157       if (TMath::Abs(graph2->GetX()[bin2-1] - x) < TMath::Abs(graph2->GetX()[bin2] - x))
6158         bin2--;
6159
6160     if (graph1->GetY()[bin1] == 0 || graph2->GetY()[bin2] == 0 || bin2 == graph2->GetN())
6161     {
6162       Printf("%d %d removed", bin1, bin2);
6163       graph1->RemovePoint(bin1--);
6164       continue;
6165     }
6166
6167     Float_t graph2Extrapolated = graph2->GetY()[bin2];
6168     if (TMath::Abs(x - graph2->GetX()[bin2]) > 0.0001)
6169     {
6170       Printf("%f %f %d %d not found", x, graph2->GetX()[bin2], bin1, bin2);
6171       graph1->RemovePoint(bin1--);
6172       continue;
6173     }
6174
6175     Float_t value = graph1->GetY()[bin1] / graph2Extrapolated;
6176     Float_t error = value * TMath::Sqrt(TMath::Power(graph1->GetEY()[bin1] / graph1->GetY()[bin1], 2) + TMath::Power(graph2->GetEY()[bin2] / graph2->GetY()[bin2], 2));
6177
6178     graph1->GetY()[bin1] = value;
6179     graph1->GetEY()[bin1] = error;
6180
6181     Printf("%d %d %f %f %f %f", bin1, bin2, x, graph2Extrapolated, value, error);
6182   }
6183 }
6184
6185 Float_t ExtractYields(TH1* hist, Int_t trigId, Int_t centralityId, Float_t ptA, Float_t ptW, Int_t caseId, Double_t normUnc)
6186 {
6187   CreateYieldStructure();
6188
6189   Float_t width = 0.69;
6190 //   Float_t width = 0.5; Printf("WARNING. Using integration width 0.5");
6191 //   Float_t width = 0.85; Printf("WARNING. Using integration width 0.85");
6192   
6193   //new TCanvas; hist->DrawCopy();
6194   
6195   Int_t binBegin = hist->FindBin(-width);
6196   Int_t binEnd = hist->FindBin(width);
6197   Double_t nearSideError = 0;
6198   Float_t nearSideYield = hist->IntegralAndError(binBegin, binEnd, nearSideError);
6199   nearSideYield *= hist->GetXaxis()->GetBinWidth(1);
6200   nearSideError *= hist->GetXaxis()->GetBinWidth(1);
6201
6202   Int_t binBegin = hist->FindBin(TMath::Pi() - width);
6203   Int_t binEnd = hist->FindBin(TMath::Pi() + width);
6204   Double_t awaySideError = 0;
6205   Float_t awaySideYield = hist->IntegralAndError(binBegin, binEnd, awaySideError);
6206   awaySideYield *= hist->GetXaxis()->GetBinWidth(1);
6207   awaySideError *= hist->GetXaxis()->GetBinWidth(1);
6208   
6209   Printf("%d %d %f %d: %f+-%f %f+-%f (%f)", trigId, centralityId, ptA, caseId, nearSideYield, nearSideError, awaySideYield, awaySideError, normUnc);
6210   
6211   FillYield(trigId, centralityId, ptA, ptW, caseId, nearSideYield, TMath::Sqrt(nearSideError * nearSideError + normUnc * normUnc), awaySideYield, TMath::Sqrt(awaySideError * awaySideError + normUnc * normUnc));
6212   
6213   // store normUnc for error propagation later
6214   TGraphErrors** tmp = yields[2][trigId][centralityId];
6215   tmp[caseId]->SetPoint(tmp[caseId]->GetN(), ptA, normUnc);
6216   
6217   return awaySideYield;
6218 }
6219
6220 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)
6221 {
6222   // CINT limitation here
6223   TGraphErrors** tmp = yields[0][trigId][centralityId];
6224   tmp[caseId]->SetPoint(tmp[caseId]->GetN(), ptA, nearSideYield);
6225   tmp[caseId]->SetPointError(tmp[caseId]->GetN()-1, ptW, nearSideError);
6226   //tmp[caseId]->Print();
6227   
6228   tmp = yields[1][trigId][centralityId];
6229   tmp[caseId]->SetPoint(tmp[caseId]->GetN(), ptA, awaySideYield);
6230   tmp[caseId]->SetPointError(tmp[caseId]->GetN()-1, ptW, awaySideError);
6231 }
6232
6233 Double_t hypgeo(Double_t a, Double_t b, Double_t c, Double_t z)
6234 {
6235   // ROOT::Math::hyperg is only defined for |z| < 1
6236   if (z > -1)
6237     return ROOT::Math::hyperg(a, b, c, z);
6238     
6239   // for z < -1 we can use an identity from http://en.wikipedia.org/wiki/Hypergeometric_function
6240   return TMath::Power(1-z, -b) * ROOT::Math::hyperg(c-a, b, c, z / (z-1));
6241 }
6242
6243 Double_t hypgeoder2(Double_t a, Double_t b, Double_t c, Double_t z)
6244 {
6245   // derivate of hypgeo with parameter b: d/db hypgeo
6246   
6247   static TF1* func = 0;
6248   if (!func)
6249     func = new TF1("hypgeoder2_func", "hypgeo([0], x, [1], [2])");
6250   
6251   func->SetParameters(a, c, z);
6252   return func->Derivative(b);
6253 }
6254
6255 void TsallisYieldUncertainty(Double_t n, Double_t q, Double_t beta, TMatrixDSym covMatrix, Int_t offset, Double_t& yield, Double_t& unc)
6256 {
6257   gSystem->Load("libMathMore");
6258
6259   TF1 tsallis("tsallis", "[0] * (1-[2]*(1-[1])*x*x)**(1/(1-[1]))", -0.5 * TMath::Pi(), 1.5 * TMath::Pi());
6260
6261   // 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]
6262   // [0] = n, [1] = q, [2] = beta
6263   TF1 tsallisIntegral("tsallisIntegral",               "[0]*x*hypgeo(0.5, 1/([1]-1), 1.5, -[2]*([1]-1)*x*x)");
6264   TF1 tsallisIntegralDerN("tsallisIntegralDerN",           "x*hypgeo(0.5, 1/([1]-1), 1.5, -[2]*([1]-1)*x*x)");
6265   
6266   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)");
6267   
6268   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]");
6269   
6270   const Float_t width = 0.7;
6271   
6272   TF1* derivates[4];
6273   derivates[0] = new TF1("const", "1");
6274   derivates[1] = &tsallisIntegralDerN;
6275   derivates[2] = &tsallisIntegralDerq;
6276   derivates[3] = &tsallisIntegralDerbeta;
6277   
6278   Printf("%f %f %f", n, q, beta);
6279   
6280   tsallis.SetParameters(n, q, beta);
6281   tsallisIntegral.SetParameters(n, q, beta);
6282   for (Int_t i=1; i<4; i++)
6283     derivates[i]->SetParameters(n, q, beta);
6284   
6285   yield = tsallisIntegral.Eval(width) - tsallisIntegral.Eval(-width);
6286   Double_t yield2 = tsallis.Integral(-width, width);
6287   
6288   unc = 0;
6289   for (Int_t i=0; i<4; i++)
6290     for (Int_t j=0; j<4; j++)
6291     {
6292       Int_t covI = i;
6293       Int_t covJ = j;
6294       if (i > 0)
6295         covI += offset;
6296       if (j > 0)
6297         covJ += offset;
6298         
6299       Double_t der1 = (derivates[i]->Eval(width) - derivates[i]->Eval(-width));
6300       Double_t der2 = (derivates[j]->Eval(width) - derivates[j]->Eval(-width));
6301         
6302       unc += der1 * der2 * covMatrix(covI, covJ);
6303       
6304       Printf("%d %d % .3e % .3e % .3e % .3e", i, j, der1, der2, covMatrix(covI, covJ), unc);
6305     }
6306     
6307   unc = TMath::Sqrt(unc);
6308   
6309   yield /= width * 2;
6310   yield2 /= width * 2;
6311   unc /= width * 2;
6312   
6313   Printf("%f (%f) +- %f", yield, yield2, unc);
6314 }
6315
6316 double NLowestBinAverage(TH1 &h, int N)
6317 {
6318   // Returns mean content of N lowest bins in h.
6319
6320   double avg = 0;
6321   int counter = 0;
6322   std::list<double> content;
6323   std::list<double>::iterator i;
6324
6325   for (int jbin=1; jbin<=h.GetNbinsX(); jbin++) {
6326     content.push_back(h.GetBinContent(jbin));
6327   }
6328   content.sort();
6329
6330   for (i = content.begin(); i != content.end(); ++i) {
6331
6332     if (counter == N)
6333       break;
6334
6335     avg += *i/N;
6336     counter++;
6337   }
6338
6339   if (counter < N)
6340     Warning("NLowestBinAverage()",
6341         "Avg. of %d bins requested, %d used", N, counter);
6342
6343   return avg;
6344
6345
6346 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)
6347 {
6348   // caseOffsets
6349   // 0 same with v2 (14 tsallis for baseline [28/29 tsallis params]; 15 yield from tsallis function)
6350   // [disabled] 1 same/mixed with v2 (15 tsallis for baseline)
6351   // 2 same no v2 (16 tsallis for baseline; 17 yield from tsallis function)
6352   // 4 same no v2 (18 flat fit 1)
6353   // 5 same no v2 (19 flat fit 2)
6354   // 6 same no v2 (20 flat avg over 4)
6355   // 7 same no v2 (21 flat avg over 8)
6356   // 8 same no v2 (22 flat avg over 16)
6357   // 9 same with v2 (23 flat fit 1)
6358   // 10 same with v2 (24 flat fit 2)
6359   // 11 same with v2 (25 flat avg over 4)
6360   // 12 same with v2 (26 flat avg over 8)
6361   // 13 same with v2 (27 flat avg over 16)
6362   
6363   // 30 gaussian fit width
6364
6365   // same stuff for same/mixed
6366   if (0 && caseOffset == 0 && histMixed)
6367   {
6368     TH1* clone = (TH1*) hist->Clone();
6369     clone->Divide(histMixed);
6370     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 1, ptACenter, ptAWidth, kFALSE, 0, vn);
6371   }
6372   
6373   // same for other baseline subtractions
6374   if (caseOffset == 0)
6375   {
6376     file = TFile::Open("dphi_corr.root", "UPDATE");
6377     hist->Write();
6378     file->Close();
6379     
6380     TH1* clone = (TH1*) hist->Clone();
6381     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 2, ptACenter, ptAWidth, kTRUE, 0, vn);
6382   
6383     clone = (TH1*) hist->Clone();
6384     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 4, ptACenter, ptAWidth, kTRUE, 1, vn);
6385   
6386     clone = (TH1*) hist->Clone();
6387     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 5, ptACenter, ptAWidth, kTRUE, 2, vn);
6388     
6389     clone = (TH1*) hist->Clone();
6390     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 6, ptACenter, ptAWidth, kTRUE, 3, vn);
6391     
6392     clone = (TH1*) hist->Clone();
6393     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 7, ptACenter, ptAWidth, kTRUE, 4, vn);
6394     
6395     clone = (TH1*) hist->Clone();
6396     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 8, ptACenter, ptAWidth, kTRUE, 5, vn);
6397     
6398     clone = (TH1*) hist->Clone();
6399     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 9, ptACenter, ptAWidth, kFALSE, 1, vn);
6400   
6401     clone = (TH1*) hist->Clone();
6402     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 10, ptACenter, ptAWidth, kFALSE, 2, vn);
6403   
6404     clone = (TH1*) hist->Clone();
6405     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 11, ptACenter, ptAWidth, kFALSE, 3, vn);
6406   
6407     clone = (TH1*) hist->Clone();
6408     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 12, ptACenter, ptAWidth, kFALSE, 4, vn);
6409   
6410     clone = (TH1*) hist->Clone();
6411     DrawFlow(v2, clone, ptT, ptA, histMixed, trigId, centralityId, 13, ptACenter, ptAWidth, kFALSE, 5, vn);
6412   }
6413
6414   Float_t awaySideYield = ExtractYields(hist, trigId, centralityId, ptACenter, ptAWidth, 0 + caseOffset, 0);
6415   
6416   if (flatBaseLine)
6417   {
6418     v2 = 0;
6419     vn = 0;
6420   }
6421     
6422 /*    Float_t v2Trig  = flowGraph->Eval(ptT);
6423     Float_t v2Assoc = flowGraph->Eval(ptA);
6424     Float_t v2 = v2Trig * v2Assoc;
6425     Printf("%f %f: %.2f %.2f --> %.4f", ptT, ptA, v2Trig, v2Assoc, v2);*/
6426   
6427   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());
6428
6429   // find minimum
6430   if (0)
6431   {
6432     Float_t minBin = hist->FindBin(0.6);
6433     for (Int_t bin=hist->FindBin(0.6); bin<=hist->FindBin(1.8); bin++)
6434       if (hist->GetBinContent(bin) < hist->GetBinContent(minBin))
6435         minBin = bin;
6436             
6437     Float_t norm = hist->GetBinContent(minBin) / (1 + 2 * v2 * cos(2 * hist->GetBinCenter(minBin)));
6438     Double_t normUnc = 0;
6439   }
6440   else
6441   {
6442     if (baseLineDetermination == 0)
6443     {
6444       return;
6445       /*
6446       if (centralityId == 0)
6447         hist->Fit("pol0", "0", "", 0.8., 1.2);
6448       else
6449         hist->Fit("pol0", "0", "", 1.2, 1.6);
6450       */
6451       //tsallis = new TF1("tsallis", "(1-[1]*(1-[0])*x*x)**(1/(1-[0]))", 0, 10)
6452       // (1-b(1-q)x*x)**(1/(1-q))
6453       
6454       // combination of two tsallis functions
6455       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());
6456       //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());
6457       // 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
6458       total->SetParLimits(0, 0, 10000);
6459       total->SetParLimits(1, 0, 10000);
6460       total->SetParLimits(4, 0, 10000);
6461       
6462       total->SetParLimits(2, 1.0000001, 5);
6463       total->SetParLimits(5, 1.0000001, 5);
6464       
6465       total->SetParLimits(3, 0.1, 1000);
6466       total->SetParLimits(6, 0.1, 1000);
6467       
6468       total->SetParameters(1, 1, 1.5, 3, 1, 1.5, 1.1);
6469       
6470       // limit q>1
6471       hist->Fit(total, "0RI");
6472       fitResult = hist->Fit(total, "0RSI");
6473       
6474       if (0 && fitResult->CovMatrixStatus() > 0)
6475       {
6476         TMatrixDSym cov(fitResult->GetCovarianceMatrix());
6477         cov.Print();
6478         
6479         Double_t nearSideYield, nearSideError;
6480         TsallisYieldUncertainty(total->GetParameter(1), total->GetParameter(2), total->GetParameter(3), cov, 0, nearSideYield, nearSideError);
6481         
6482         Double_t awaySideYield2, awaySideError;
6483         TsallisYieldUncertainty(total->GetParameter(4), total->GetParameter(5), total->GetParameter(6), cov, 3, awaySideYield2, awaySideError);
6484         
6485         FillYield(trigId, centralityId, ptACenter, ptAWidth, 14 + caseOffset + 1, nearSideYield, nearSideError, awaySideYield2, awaySideError);
6486         
6487         Printf("Chi2 %f / ndf %d = %f", total->GetChisquare(), total->GetNDF(), (total->GetNDF() > 0) ? total->GetChisquare() / total->GetNDF() : -1);
6488         
6489         total->SetLineColor(hist->GetLineColor());
6490         total->SetLineWidth(1);
6491         if (caseOffset == 2)
6492         {
6493           if (0)
6494             total->DrawCopy("SAME");
6495           //total->SetParameter(5, total->GetParameter(5) - TMath::Sqrt(cov[5][5]));
6496           //total->DrawCopy("SAME");
6497           //total->SetParameter(5, total->GetParameter(5) + 2 * TMath::Sqrt(cov[5][5]));
6498           //Printf("%f", total->Integral(-0.7,0.7));
6499           //total->DrawCopy("SAME");
6500         }
6501         
6502         if (caseOffset == 0)
6503         {
6504           // store fit parameters
6505           
6506           // q
6507           FillYield(trigId, centralityId, ptACenter, ptAWidth, 28, total->GetParameter(2), total->GetParError(2), total->GetParameter(5), total->GetParError(5));
6508           // beta
6509           FillYield(trigId, centralityId, ptACenter, ptAWidth, 29, total->GetParameter(3), total->GetParError(3), total->GetParameter(6), total->GetParError(6));
6510           
6511           if (0)
6512           {
6513             // two Gauss fits
6514             gausFit = new TF1("gausFit", "[0] + gaus(1) + gaus(4)", -0.5 * TMath::Pi(), 1.5 * TMath::Pi());
6515             gausFit->SetParameters(1, 1, 0, 1, 1, TMath::Pi(), 0);
6516             gausFit->SetParLimits(0, 0, 10000);
6517             gausFit->SetParLimits(1, 0, 10000);
6518             gausFit->FixParameter(2, 0);
6519             gausFit->SetParLimits(3, 0.01, 10);
6520             gausFit->SetParLimits(4, 0, 10000);
6521             gausFit->FixParameter(5, TMath::Pi());
6522             gausFit->SetParLimits(6, 0.01, 10);
6523             
6524             hist->Fit(gausFit, "0RI");
6525             gausFit->SetLineWidth(1);
6526             gausFit->DrawCopy("SAME");
6527           
6528             FillYield(trigId, centralityId, ptACenter, ptAWidth, 30, gausFit->GetParameter(3), total->GetParError(3), total->GetParameter(6), total->GetParError(6));
6529           }
6530         }
6531         
6532         if (0 && cov[0][0] > 0)
6533         {
6534           for (Int_t i=0; i<cov.GetNcols(); i++)
6535             for (Int_t j=0; j<cov.GetNrows(); j++)
6536               cov[j][i] /= TMath::Sqrt(cov[i][i]) * TMath::Sqrt(cov[j][j]);
6537           cov.Print();
6538         }
6539       }
6540       
6541       func = total;
6542       Float_t norm = func->GetParameter(0) / (1 - 2 * v2);
6543       Double_t normUnc = func->GetParError(0) / (1 - 2 * v2);
6544       //return;
6545     }
6546     else if (baseLineDetermination <= 2)
6547     {
6548       Float_t values[3];
6549       Float_t errors[3];
6550       
6551       if (baseLineDetermination == 1)
6552       {
6553         Float_t regionBegin[3] = { -TMath::Pi() / 2,        TMath::Pi() / 2 - 0.4, 1.5 * TMath::Pi() - 0.4 };
6554         Float_t regionEnd[3] =   { -TMath::Pi() / 2 + 0.4,  TMath::Pi() / 2 + 0.4, 1.5 * TMath::Pi() };
6555       }
6556       else if (baseLineDetermination == 2)
6557       {
6558         Float_t regionBegin[3] = { -TMath::Pi() / 2,              TMath::Pi() / 2 - 0.4 - 0.2, 1.5 * TMath::Pi() - 0.4 - 0.2};
6559         Float_t regionEnd[3] =   { -TMath::Pi() / 2 + 0.4 - 0.2,  TMath::Pi() / 2 + 0.4 - 0.2, 1.5 * TMath::Pi() };
6560       }
6561         
6562       // weighted mean
6563       Float_t sum = 0;
6564       Float_t weight = 0;
6565       for (Int_t i=0; i<3; i++)
6566       {
6567         hist->Fit("pol0", "0Q", "", regionBegin[i], regionEnd[i]);
6568         func = hist->GetFunction("pol0");
6569         if (!func)
6570           continue;
6571         sum += func->GetParameter(0) / func->GetParError(0) / func->GetParError(0);
6572         weight += 1. / func->GetParError(0) / func->GetParError(0);
6573       }
6574       
6575       if (weight == 0)
6576         return;
6577       
6578       sum /= weight;
6579       weight = TMath::Sqrt(1. / weight);
6580       
6581       Float_t norm = sum / (1 - 2 * v2);
6582       Double_t normUnc = weight / (1 - 2 * v2);
6583     }
6584     else
6585     {
6586       Int_t bins = 2;
6587       if (baseLineDetermination == 4)
6588         bins = 4;
6589       if (baseLineDetermination == 5)
6590         bins = 8;
6591       Float_t norm = NLowestBinAverage(*hist, bins);
6592       Double_t normUnc = 0;
6593       
6594       Printf("NLowestBinAverage %d --> %f", bins, norm);
6595       
6596       norm /= (1 - 2 * v2);
6597     }
6598     
6599     Printf("Baseline: %f +- %f", norm, normUnc);
6600   }
6601   
6602   if (caseOffset == 0)
6603   {
6604     Float_t awaySideYieldNoBaseline = awaySideYield - norm * (1 - 2 * v2);
6605     Float_t v2YieldNoBaseline = norm * 2 * v2 * (1 + 1.4) / 1.4;
6606     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);
6607   }
6608
6609   //flowFunc->SetParameters(hist->GetBinContent(hist->FindBin(1.4)) / (1.0 - 2.0 * v2), v2);
6610   flowFunc->SetParameters(norm, v2, 0, 0, 0);
6611   if (vn)
6612     flowFunc->SetParameters(norm, vn[1], vn[2], vn[3], vn[4]);
6613   flowFunc->SetLineWidth(2);
6614   if (caseOffset >= 4 && caseOffset <= 9 && caseOffset != 6 && caseOffset != 7)
6615   {
6616     if (caseOffset != 4 && caseOffset != 9)
6617       flowFunc->SetLineStyle(2);
6618     flowFunc->DrawCopy("SAME"); //->SetLineColor(caseOffset - 3);
6619     if (vn)
6620     {
6621       flowFuncTmp = (TF1*) flowFunc->Clone("flowFuncTmp");
6622       for (Int_t i=1; i<=4; i++)
6623       {
6624         flowFuncTmp->SetParameters(flowFuncTmp->GetParameter(0), 0, 0, 0, 0);
6625         flowFuncTmp->SetParameter(i, vn[i]);
6626         flowFuncTmp->SetLineStyle(2);
6627         flowFuncTmp->Print();
6628         flowFuncTmp->DrawCopy("SAME");
6629       }
6630     }
6631   }
6632   
6633   hist->Add(flowFunc, -1);
6634   if (caseOffset == 0)
6635   {
6636     file = TFile::Open("dphi_corr.root", "UPDATE");
6637     hist->SetName(TString(hist->GetName()) + "_tsallis_v2");
6638     hist->Write();
6639     file->Close();
6640     //  hist->DrawCopy("SAME");
6641   }
6642   if (caseOffset == 2 && flatBaseLine)
6643   {
6644     file = TFile::Open("dphi_corr.root", "UPDATE");
6645     hist->SetName(TString(hist->GetName()) + "_tsallis_flat");
6646     hist->Write();
6647     file->Close();
6648     //  hist->DrawCopy("SAME");
6649   }
6650   if (caseOffset == 4 && flatBaseLine)
6651   {
6652     file = TFile::Open("dphi_corr.root", "UPDATE");
6653     hist->SetName(TString(hist->GetName()) + "_fit_flat");
6654     hist->Write();
6655     file->Close();
6656     //  hist->DrawCopy("SAME");
6657   }
6658   if (caseOffset == 9)
6659   {
6660     file = TFile::Open("dphi_corr.root", "UPDATE");
6661     hist->SetName(TString(hist->GetName()) + "_fit_v2");
6662     hist->Write();
6663     file->Close();
6664     //  hist->DrawCopy("SAME");
6665   }
6666   
6667   ExtractYields(hist, trigId, centralityId, ptACenter, ptAWidth, 14 + caseOffset, normUnc);
6668   
6669   if (0 && histMixed)
6670   {
6671     Printf("%f", histMixed->Integral() / histMixed->GetNbinsX());
6672     flowFunc->SetParameters(histMixed->Integral() / histMixed->GetNbinsX(), v2);
6673     flowFunc->SetLineColor(2);
6674     //if (caseOffset == 0)
6675     //  flowFunc->DrawCopy("SAME");
6676   }
6677 }
6678
6679 void RemoveBaseLine(TH1* hist)
6680 {
6681   if (!hist)
6682     return;
6683     
6684   //hist->Rebin(2);
6685   //hist->Scale(0.5);
6686
6687   hist->Fit("pol0", "0", "", 1.07, 2.07);
6688   
6689   if (!hist->GetFunction("pol0"))
6690     return;
6691   
6692   Float_t zyam = hist->GetFunction("pol0")->GetParameter(0);
6693   
6694   if (zyam <= 0)
6695     return;
6696     
6697   return;
6698   
6699   for (Int_t i=1; i<=hist->GetNbinsX(); i++)
6700     hist->SetBinContent(i, hist->GetBinContent(i) - zyam);
6701 }
6702  
6703 void* cacheIds[10];
6704 TH2* cacheMixed[10];
6705
6706 Int_t gHistCount = 0;
6707 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)
6708 {
6709   h = (AliUEHistograms*) hVoid;
6710   hMixed = (AliUEHistograms*) hMixedVoid;
6711   
6712   if (stepMixed < 0)
6713     stepMixed = step;
6714
6715   Int_t centralityBeginBin = 0;
6716   Int_t centralityEndBin = -1;
6717   
6718   if (!useCentralityBinsDirectly && centralityEnd >= centralityBegin)
6719   {
6720     centralityBeginBin = h->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->FindBin(0.01 + centralityBegin);
6721     centralityEndBin = h->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->FindBin(-0.01 + centralityEnd);
6722   }
6723   else if (useCentralityBinsDirectly)
6724   {
6725     centralityBeginBin = centralityBegin;
6726     centralityEndBin = centralityEnd;
6727   }
6728   
6729   // 2d same and mixed event
6730   TH2* sameTwoD  = h->GetUEHist(2)->GetUEHist(step, 0, ptBegin, ptEnd, centralityBeginBin, centralityEndBin, 1, kFALSE);
6731   
6732   if (hMixed)
6733   {
6734     if (!equivMixedBin)
6735     {
6736       // No centrality, nor pT associated dep of the mixed event observed. Use a larger range to get more statistics
6737       
6738       Int_t cacheId = -1;
6739       
6740       for (Int_t i=0; i<10; i++)
6741         if (cacheIds[i] == hMixed)
6742         {
6743           cacheId = i;
6744           break;
6745         }
6746         
6747       // not found
6748       if (cacheId == -1)
6749         for (Int_t i=0; i<10; i++)
6750           if (cacheIds[i] == 0)
6751           {
6752             cacheId = i;
6753             break;
6754           }
6755
6756       if (!cacheIds[cacheId])
6757       {
6758         hMixed->SetPtRange(3.0, 10);
6759         cacheMixed[cacheId] = (TH2*) hMixed->GetUEHist(2)->GetUEHist(stepMixed, 0, 3.0, 10.0, centralityBeginBin, centralityEndBin, 1, kFALSE);
6760         cacheIds[cacheId] = hMixed;
6761         Printf("GetDistAndFlow: Cached for %p on slot %d", hMixed, cacheId);
6762       }
6763       
6764       TH2* mixedTwoD = cacheMixed[cacheId];
6765     }
6766     else
6767     {
6768       // use same bin for mixing
6769       
6770       TH2* mixedTwoD = (TH2*) hMixed->GetUEHist(2)->GetUEHist(stepMixed, 0, ptBegin, ptEnd, centralityBeginBin, centralityEndBin, 1, kFALSE);
6771     }
6772     
6773     if (0)
6774     {
6775       // asssume flat in dphi, gain in statistics
6776       Printf("NOTE: Assuming flat acceptance in phi!");
6777       
6778       TH1* histMixedproj = mixedTwoD->ProjectionY();
6779       histMixedproj->Scale(1.0 / mixedTwoD->GetNbinsX());
6780       
6781       for (Int_t x=1; x<=mixedTwoD->GetNbinsX(); x++)
6782         for (Int_t y=1; y<=mixedTwoD->GetNbinsY(); y++)
6783           mixedTwoD->SetBinContent(x, y, histMixedproj->GetBinContent(y));
6784     }
6785     
6786     // get mixed event normalization by assuming full acceptance at deta of 0 (only works for flat dphi)
6787     if (scaleToPairs)
6788     {
6789       Double_t mixedNorm = mixedTwoD->Integral(1, mixedTwoD->GetNbinsX(), mixedTwoD->GetYaxis()->FindBin(-0.01), mixedTwoD->GetYaxis()->FindBin(0.01));
6790       mixedNorm /= mixedTwoD->GetNbinsX() * (mixedTwoD->GetYaxis()->FindBin(0.01) - mixedTwoD->GetYaxis()->FindBin(-0.01) + 1);
6791     }
6792     else
6793       Double_t mixedNorm = mixedTwoD->Integral() / sameTwoD->Integral();
6794     
6795     // divide and scale
6796     sameTwoD->Divide(mixedTwoD);
6797     sameTwoD->Scale(mixedNorm);
6798     
6799 /*    new TCanvas;
6800     sameTwoD->Draw("SURF1");
6801     dfdsafd;*/
6802   }
6803   
6804   TString histName;
6805   histName.Form("GetDistAndFlow%d", gHistCount++);
6806   
6807   // extract dphi distribution if requested
6808   if (twoD == 1)
6809   {
6810     *hist = sameTwoD;
6811   }
6812
6813   //  Float_t etaLimit = 0.8;
6814   Float_t etaLimit = 1.0;
6815
6816   // 20: return corr in |delta eta| < 1 from which 1 < |delta eta| < 2 is subtracted
6817   if (twoD == 0 || twoD == 10 || twoD == 20)
6818   {
6819     Int_t etaBegin = 1;
6820     Int_t etaEnd = sameTwoD->GetNbinsY();
6821     
6822     if (twoD == 10 || twoD == 20)
6823     {
6824       etaBegin = sameTwoD->GetYaxis()->FindBin(-etaLimit + 0.01);
6825       etaEnd   = sameTwoD->GetYaxis()->FindBin(etaLimit - 0.01);
6826     }
6827
6828     *hist = sameTwoD->ProjectionX(histName, etaBegin, etaEnd);
6829     
6830     if (!scaleToPairs)
6831       (*hist)->Scale(1.0 / (etaEnd - etaBegin + 1));
6832   }
6833   
6834   if (twoD == 11 || twoD == 20)
6835   {
6836     // errors --> are ok
6837     
6838 //       Float_t outerLimit = 2.0;
6839     Float_t outerLimit = 1.8;
6840     Printf("Phi dist: Using outer limit %.2f", outerLimit);
6841 //       Float_t outerLimit = etaLimit * 2;
6842     
6843     histTmp = sameTwoD->ProjectionX(histName + "1", TMath::Max(1, sameTwoD->GetYaxis()->FindBin(-outerLimit + 0.01)), sameTwoD->GetYaxis()->FindBin(-etaLimit - 0.01));
6844     Int_t etaBins = sameTwoD->GetYaxis()->FindBin(-etaLimit - 0.01) - TMath::Max(1, sameTwoD->GetYaxis()->FindBin(-outerLimit + 0.01)) + 1;
6845
6846     TH1D* tracksTmp = sameTwoD->ProjectionX(histName + "2", sameTwoD->GetYaxis()->FindBin(etaLimit + 0.01), TMath::Min(sameTwoD->GetYaxis()->GetNbins(), sameTwoD->GetYaxis()->FindBin(outerLimit - 0.01)));
6847     etaBins += TMath::Min(sameTwoD->GetYaxis()->GetNbins(), sameTwoD->GetYaxis()->FindBin(outerLimit - 0.01)) - sameTwoD->GetYaxis()->FindBin(etaLimit + 0.01) + 1;
6848
6849 //       printf("%f +- %f  %f +- %f ", (*hist)->GetBinContent(1), (*hist)->GetBinError(1), tracksTmp->GetBinContent(1), tracksTmp->GetBinError(1));
6850     histTmp->Add(tracksTmp);
6851 //       Printf(" --> %f +- %f", (*hist)->GetBinContent(1), (*hist)->GetBinError(1));
6852     
6853     if (!scaleToPairs)
6854       histTmp->Scale(1.0 / etaBins);
6855     
6856     if (twoD == 11)
6857       *hist = histTmp;
6858     else if (twoD == 20)
6859     {
6860       // calculate acc with 2 * (deta - 0.5 * deta*deta / 1.6)
6861       if (!hMixedVoid)
6862         histTmp->Scale(0.75 / 0.25);
6863       
6864       histTmp->Scale(1.0 / 0.8);
6865       
6866       (*hist)->Add(histTmp, -1);
6867     }
6868   }
6869   
6870 //   (*hist)->Rebin(2); (*hist)->Scale(0.5);
6871   
6872   //*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);
6873   
6874   TString str;
6875   str.Form("%.1f < p_{T,trig} < %.1f", ptBegin - 0.01, ptEnd + 0.01);
6876   
6877   TString str2;
6878   str2.Form("%.2f < p_{T,assoc} < %.2f", gpTMin - 0.01, gpTMax + 0.01);
6879     
6880   TString newTitle;
6881   newTitle.Form("%s - %s - %d-%d", str.Data(), str2.Data(), centralityBegin, centralityEnd);
6882   if (!useCentralityBinsDirectly)
6883     newTitle += "%";
6884   (*hist)->SetTitle(newTitle);
6885   
6886   if (0 && hMixed)
6887   {
6888     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));
6889     
6890     //new TCanvas; (*hist)->DrawCopy(); histMixed->DrawCopy("SAME")->SetLineColor(2);
6891     
6892     Float_t totalPairs = (*hist)->Integral();
6893     
6894     (*hist)->Divide(histMixed);
6895     (*hist)->Scale(totalPairs / (*hist)->Integral());
6896     
6897     //(*hist)->DrawCopy("SAME")->SetLineColor(4);
6898   }
6899   
6900   if (v2 || vn)
6901   {
6902     // calculate v2trigger
6903     h->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->SetRangeUser(0.01 + centralityBegin, -0.01 + centralityEnd);
6904     ptDist = h->GetUEHist(2)->GetEventHist()->Project(step, 0);
6905     Float_t vTrig[5];
6906     for (Int_t i=2; i<=((vn) ? 5 : 2); i++)
6907       vTrig[i-1] = CalculateFlow(ptDist, ptBegin, ptEnd, i, centralityBegin, centralityEnd);
6908     delete ptDist;
6909     
6910     // calculate v2 assoc
6911     cont = h->GetUEHist(2)->GetTrackHist(0);
6912     h->GetUEHist(2)->GetTrackHist(0)->GetGrid(step)->GetGrid()->GetAxis(3)->SetRangeUser(0.01 + centralityBegin, -0.01 + centralityEnd);
6913     h->GetUEHist(2)->GetTrackHist(0)->GetGrid(step)->GetGrid()->GetAxis(2)->SetRangeUser(ptBegin, ptEnd);
6914     ptDist = h->GetUEHist(2)->GetTrackHist(0)->Project(step, 1);
6915     Float_t vAssoc[5];
6916     for (Int_t i=2; i<=((vn) ? 5 : 2); i++)
6917       vAssoc[i-1] = CalculateFlow(ptDist, gpTMin, gpTMax, i, centralityBegin, centralityEnd);
6918     delete ptDist;
6919   
6920     if (v2)
6921       *v2 = vTrig[2-1] * vAssoc[2-1];
6922     if (vn)
6923       for (Int_t i=2; i<=5; i++)
6924         vn[i-1] = vTrig[i-1] * vAssoc[i-1];
6925   }
6926 }
6927
6928 void CompareNtrDist(const char* fileName1, const char* fileNameCentrality1)
6929 {
6930   loadlibs();
6931   Int_t step = 8;
6932
6933   TCanvas *c1 = new TCanvas("c1", "", 1400, 1100);
6934   TCanvas *c2 = new TCanvas("c2", "", 1400, 1100);
6935
6936   dndpt_central = ReadHepdata("/home/mkofarag/work/Project/2010/raa_dndpt_central.txt", kFALSE, 3);
6937   AliUEHistograms* h1 = (AliUEHistograms*) GetUEHistogram(fileName1);
6938   AliUEHistograms* hc1 = (AliUEHistograms*) GetUEHistogram(fileNameCentrality1);
6939
6940   h1->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->SetRangeUser(0.01 + 0, -0.01 + 5);
6941   ptDist1 = h1->GetUEHist(2)->GetEventHist()->Project(step, 0);
6942   ptDist1->Scale(1.0/1.8/TMath::TwoPi()/hc1->GetCentralityDistribution()->Integral(hc1->GetCentralityDistribution()->FindBin(0.01), hc1->GetCentralityDistribution()->FindBin(4.99)));
6943   for (Int_t i=1; i<=ptDist1->GetNbinsX(); i++)
6944   {
6945     ptDist1->SetBinContent(i, ptDist1->GetBinContent(i)/ptDist1->GetBinWidth(i));
6946   }
6947   for (Int_t i=0; i<dndpt_central->GetN();i++)
6948   {
6949     Double_t x = dndpt_central->GetX()[i];
6950     Double_t y = dndpt_central->GetY()[i]*x;
6951     dndpt_central->SetPoint(i,x,y);
6952   }
6953   ptDist2 = (TH1*) ptDist1->Clone("ptDist2");
6954   ptDist2->Reset();
6955   for (Int_t i=0; i<dndpt_central->GetN(); i++)
6956   {
6957     Float_t width = 0;
6958     if (i > 0)
6959       width += (dndpt_central->GetX()[i] - dndpt_central->GetX()[i-1]) / 2;
6960     if (i < dndpt_central->GetN()-1)
6961       width += (dndpt_central->GetX()[i+1] - dndpt_central->GetX()[i]) / 2;
6962     if (i == 0 || i == dndpt_central->GetN() - 1)
6963       width *= 2;
6964     ptDist2->Fill(dndpt_central->GetX()[i],dndpt_central->GetY()[i]*width);
6965   }
6966   for (Int_t i=1; i<=ptDist2->GetNbinsX(); i++)
6967   {
6968     ptDist2->SetBinContent(i, ptDist2->GetBinContent(i)/ptDist2->GetBinWidth(i));
6969     ptDist2->SetBinError(i,0);
6970   }
6971 /*  for (Int_t i=1; i<=ptDist1->GetNbinsX(); i++)
6972   {
6973     ptDist1->SetBinError(i,0);
6974   }
6975 */
6976   c1->cd();
6977   c1->SetLogy();
6978   ptDist1->SetMarkerStyle(3);
6979   ptDist2->SetMarkerStyle(2);
6980   ptDist1->SetMarkerColor(2);
6981   ptDist2->SetMarkerColor(3);
6982   ptDist1->SetLineColor(2);
6983   ptDist2->SetLineColor(3);
6984   ptDist1->DrawCopy("EP");
6985   ptDist2->Draw("EPSAME");
6986   ptDist1->Divide(ptDist1,ptDist2);
6987   c2->cd();
6988   ptDist1->Draw("EP");
6989
6990 }
6991
6992 void FitNtrDist(const char* fileName1, const char* fileNameCentrality1)
6993 {
6994   loadlibs();
6995   Int_t step = 8;
6996
6997   TCanvas *c1 = new TCanvas("c1", "", 1400, 1100);
6998   TCanvas *c2 = new TCanvas("c2", "", 1400, 1100);
6999   TCanvas *c3 = new TCanvas("c3", "", 1400, 1100);
7000
7001   dndpt_central = ReadHepdata("/home/mkofarag/work/Project/2010/raa_dndpt_central.txt", kFALSE, 3);
7002   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);
7003   TF1* func2 = new TF1("func2", "[0]*TMath::Power(x,-1*[1])",5,20);
7004
7005   func1->SetParLimits(0, 2000, 5000);
7006   func1->SetParLimits(1, 1, 6);
7007   func1->SetParLimits(2, 7, 20);
7008   dndpt_central->Fit(func1,"RB","",0.5,5);
7009
7010   func2->SetParLimits(0, 0, 1000);
7011   func2->SetParLimits(1, 4, 8);
7012   dndpt_central->Fit(func2,"RB","",5,20);
7013
7014   c1->cd();
7015   c1->SetLogy();
7016   c1->SetLogx();
7017   dndpt_central->Draw("AP");
7018   func1->Draw("SAME");
7019   func2->Draw("SAME");
7020
7021   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);
7022   TF1* func4 = new TF1("func4", "[0]*x*TMath::Power(x,-1*[1])",5,20);
7023
7024   func3->FixParameter(0,func1->GetParameter(0));
7025   func3->FixParameter(1,func1->GetParameter(1));
7026   func3->FixParameter(2,func1->GetParameter(2));
7027   func4->FixParameter(0,func2->GetParameter(0));
7028   func4->FixParameter(1,func2->GetParameter(1));
7029
7030   AliUEHistograms* h1 = (AliUEHistograms*) GetUEHistogram(fileName1);
7031   AliUEHistograms* hc1 = (AliUEHistograms*) GetUEHistogram(fileNameCentrality1);
7032
7033   h1->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->SetRangeUser(0.01 + 0, -0.01 + 5);
7034   ptDist1 = h1->GetUEHist(2)->GetEventHist()->Project(step, 0);
7035   ptDist1->Scale(1.0/1.8/TMath::TwoPi()/hc1->GetCentralityDistribution()->Integral(hc1->GetCentralityDistribution()->FindBin(0.01), hc1->GetCentralityDistribution()->FindBin(4.99)));
7036   ptDist2 = (TH1*) ptDist1->Clone("ptDist2");
7037   ptDist2->Reset();
7038   for (Int_t i=1; i<=ptDist1->GetNbinsX(); i++)
7039   {
7040     ptDist1->SetBinContent(i, ptDist1->GetBinContent(i)/ptDist1->GetBinWidth(i));
7041     if (ptDist1->GetBinLowEdge(i)<5) ptDist2->SetBinContent(i, func3->Integral(ptDist1->GetBinLowEdge(i),ptDist1->GetBinLowEdge(i+1)));
7042     else ptDist2->SetBinContent(i, func4->Integral(ptDist1->GetBinLowEdge(i),ptDist1->GetBinLowEdge(i+1)));
7043   }
7044
7045   for (Int_t i=1; i<=ptDist2->GetNbinsX(); i++)
7046   {
7047     ptDist2->SetBinContent(i, ptDist2->GetBinContent(i)/ptDist2->GetBinWidth(i));
7048   }
7049   c2->cd();
7050   c2->SetLogy();
7051   ptDist1->SetMarkerStyle(3);
7052   ptDist2->SetMarkerStyle(2);
7053   ptDist1->SetMarkerColor(2);
7054   ptDist2->SetMarkerColor(3);
7055   ptDist1->SetLineColor(2);
7056   ptDist2->SetLineColor(3);
7057   ptDist1->DrawCopy("EP");
7058   ptDist2->Draw("EPSAME");  
7059
7060   ptDist1->Divide(ptDist1,ptDist2);
7061   c3->cd();
7062   ptDist1->Draw("EP");
7063 }
7064
7065 void DrawNtrDist(const char* fileName1, const char* fileName2, const char* fileNameCentrality1, const char* fileNameCentrality2)
7066 {
7067   loadlibs();
7068
7069   Int_t step = 8;
7070
7071   new TCanvas("c", "", 1400, 1100);
7072   AliUEHistograms* h1 = (AliUEHistograms*) GetUEHistogram(fileName1);
7073   AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(fileName2);
7074   AliUEHistograms* hc1 = (AliUEHistograms*) GetUEHistogram(fileNameCentrality1);
7075   AliUEHistograms* hc2 = (AliUEHistograms*) GetUEHistogram(fileNameCentrality2);
7076   h1->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->SetRangeUser(0.01 + 0, -0.01 + 10);
7077   h2->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->SetRangeUser(0.01 + 0, -0.01 + 10);
7078   ptDist1 = h1->GetUEHist(2)->GetEventHist()->Project(step, 0);
7079   ptDist2 = h2->GetUEHist(2)->GetEventHist()->Project(step, 0);
7080   ptDist1->Scale(1/hc1->GetCentralityDistribution()->Integral(hc1->GetCentralityDistribution()->FindBin(0.01), hc1->GetCentralityDistribution()->FindBin(9.99)));
7081   ptDist2->Scale(1/hc2->GetCentralityDistribution()->Integral(hc2->GetCentralityDistribution()->FindBin(0.01), hc2->GetCentralityDistribution()->FindBin(9.99)));
7082   ptDist1->Divide(ptDist1,ptDist2);
7083   ptDist1->SetMarkerStyle(3);
7084   ptDist1->Draw();
7085 }
7086
7087 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)
7088 {
7089   Printf("GetSumOfRatios | step %d | %d-%d%% | %.1f - %.1f GeV/c | %.1f - %.1f GeV/c", step, centralityBegin, centralityEnd, gpTMin, gpTMax, ptBegin, ptEnd);
7090   
7091   h = (AliUEHistograms*) hVoid;
7092   hMixed = (AliUEHistograms*) hMixedVoid;
7093
7094   Int_t centralityBeginBin = 0;
7095   Int_t centralityEndBin = -1;
7096   
7097   if (!useCentralityBinsDirectly && centralityEnd >= centralityBegin)
7098   {
7099     centralityBeginBin = h->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->FindBin(0.01 + centralityBegin);
7100     centralityEndBin = h->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->FindBin(-0.01 + centralityEnd);
7101   }
7102   else if (useCentralityBinsDirectly)
7103   {
7104     centralityBeginBin = centralityBegin;
7105     centralityEndBin = centralityEnd;
7106   }
7107   
7108   *hist  = h->GetUEHist(2)->GetSumOfRatios2(hMixed->GetUEHist(2), step, 0, ptBegin, ptEnd, centralityBeginBin, centralityEndBin, normalizePerTrigger);
7109   
7110   TString str;
7111   str.Form("%.1f < p_{T,trig} < %.1f", ptBegin - 0.01, ptEnd + 0.01);
7112   
7113   TString str2;
7114   str2.Form("%.2f < p_{T,assoc} < %.2f", gpTMin - 0.01, gpTMax + 0.01);
7115     
7116   TString newTitle;
7117   newTitle.Form("%s - %s - %d-%d", str.Data(), str2.Data(), centralityBegin, centralityEnd);
7118   if (!useCentralityBinsDirectly)
7119     newTitle += "%";
7120   if ((*hist))
7121     (*hist)->SetTitle(newTitle);
7122 }
7123  
7124 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)
7125 {
7126   loadlibs();
7127   
7128   Bool_t veryCentral = 0;
7129   Bool_t flowComparison = 0;
7130   Bool_t rhicOverlay = 0;
7131   Bool_t highStatBinning = 0;
7132
7133   file = TFile::Open("dphi_corr.root", "RECREATE");
7134   file->Close();
7135   
7136    Int_t leadingPtOffset = 1;
7137     
7138   if (veryCentral || flowComparison)
7139   {
7140     Int_t maxLeadingPt = 2;
7141     Int_t maxAssocPt = 2;
7142     Float_t leadingPtArr[] = { 2.0, 3.0, 4.0, 10.0, 20.0, 40.0 };
7143     //Float_t assocPtArr[] =   { 0.15, 0.5, 1.0, 2.0, 4.0, 6.0, 10.0, 20.0, 40.0 };
7144     Float_t assocPtArr[] =   { 1.0, 2.0, 3.0, 6.0, 10.0, 20.0, 40.0 };
7145   }
7146   else if (rhicOverlay) // RHIC binning
7147   {
7148     Int_t maxLeadingPt = 4;
7149     Int_t maxAssocPt = 5;
7150     Float_t leadingPtArr[] =   { 4.0, 5.0, 7.0, 9.0, 12.0 };
7151     Float_t assocPtArr[] =     { 0.5, 1.0, 2.0, 3.0, 5.0, 7.0 };
7152   }
7153   else if (highStatBinning) 
7154   {
7155     Int_t maxLeadingPt = 3;
7156     Int_t maxAssocPt = 2;
7157     Float_t leadingPtArr[] = { 4.0, 6.0, 8.0, 15.0 };
7158     Float_t assocPtArr[] =   { 1.0, 4.0, 10.0 };
7159   }
7160   else // ALICE binning
7161   {
7162     if (1) // binning from preliminaries
7163     {
7164       Int_t maxLeadingPt = 2;
7165       Int_t maxAssocPt = 7;
7166 //       Float_t leadingPtArr[] = { 6.0, 8.0, 10.0, 10.0, 15.0 };
7167       Float_t leadingPtArr[] = { 6.0, 8.0, 10.0, 15.0, 15.0 };
7168       Float_t assocPtArr[] =     { 0.5, 1.5, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
7169       leadingPtOffset = 2;
7170     }
7171     else if (0)
7172     {
7173       Int_t maxLeadingPt = 1;
7174       Int_t maxAssocPt = 4;
7175       Float_t leadingPtArr[] = { 8.0, 10.0, 15.0, 15.0 };
7176       Float_t assocPtArr[] =     { 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
7177       leadingPtOffset = 2;
7178     }
7179     else
7180     {
7181       Int_t maxLeadingPt = 3;
7182       Int_t maxAssocPt = 3;
7183       Float_t leadingPtArr[] = { 6.0, 8.0, 10.0, 15.0, 20.0 };
7184       Float_t assocPtArr[] =     { 1.0, 2.0, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
7185       leadingPtOffset = 2;
7186     }
7187   }
7188   
7189   Int_t nCentralityBins = 5;
7190   Int_t centralityBins[] = { 1, 7, 9, 11, 13, 16 };
7191   //Int_t centralityBins[] = { 1, 3, 5, 7, 9, 13 };
7192   
7193   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName1);
7194   
7195 //   h->SetZVtxRange(-0.5, 0.5);
7196 //   h->SetZVtxRange(1.5, 2.5);
7197   
7198   AliUEHistograms* hMixed = 0;
7199   AliUEHistograms* hMixed2 = 0; // GetUEHistogram(fileName2, 0, kTRUE);
7200
7201   if (twoD)
7202   {
7203     hMixed = (AliUEHistograms*) GetUEHistogram(fileName1, 0, kTRUE);
7204     hMixed2 = (AliUEHistograms*) GetUEHistogram(fileName2, 0, kTRUE);
7205   }
7206
7207
7208   if (veryCentral)
7209   {
7210     Printf("WARNING: Reading mixed event from preliminaries/corrected_110317.root");
7211     hMixed = (AliUEHistograms*) GetUEHistogram("preliminaries/corrected_110317.root", 0, kTRUE);
7212   }
7213   
7214   AliUEHistograms* h2 = 0;
7215   if (!twoD)
7216     h2 = (AliUEHistograms*) GetUEHistogram(fileName2);
7217
7218   
7219   TCanvas* canvas = new TCanvas("DeltaPhi", "DeltaPhi", 1000, 700);
7220   canvas->Divide(maxAssocPt, maxLeadingPt);
7221   
7222   TCanvas* canvas2 = new TCanvas("Centrality", "Centrality", 800, 600);
7223   centralityHist = (TH1*) h->GetCentralityDistribution();
7224   NormalizeToBinWidth(centralityHist);
7225   centralityHist->Draw();
7226   gPad->SetLogy();
7227   
7228   TLegend* legend = new TLegend(0.2, 0.5, 0.95, 0.90);
7229   TLegend* legend2 = new TLegend(0.5, 0.63, 0.95, 0.90);
7230   legend2->SetFillColor(0);
7231   legend2->SetTextSize(0.04);
7232   
7233   for (Int_t i=0; i<maxLeadingPt; i++)
7234     for (Int_t j=0; j<maxAssocPt; j++)
7235     {
7236       TString str;
7237       str.Form("%.1f < p_{T,trig} < %.1f", leadingPtArr[i], leadingPtArr[i+leadingPtOffset]);
7238       
7239       if (j == 0)
7240       {
7241         canvas2->cd();
7242         h->GetUEHist(2)->GetEventHist()->GetGrid(6)->SetRangeUser(0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01);
7243         centralityHist = h->GetUEHist(2)->GetEventHist()->ShowProjection(1, 6);
7244         centralityHist->SetLineColor(i+2);
7245         NormalizeToBinWidth(centralityHist);
7246         centralityHist->DrawCopy("SAME");
7247         h->GetUEHist(2)->GetEventHist()->GetGrid(6)->SetRangeUser(0, 0, -1);
7248         legend2->AddEntry(centralityHist, str);
7249       }
7250     
7251       canvas->cd(j+1 + i * maxAssocPt);
7252       gPad->SetLeftMargin(0.15);
7253       gPad->SetBottomMargin(0.2);
7254       gPad->SetTopMargin(0.01);
7255       gPad->SetRightMargin(0.01);
7256       
7257       if (i == 0 && j == 3)
7258         legend->Draw();
7259       
7260       gpTMin = assocPtArr[j] + 0.01;
7261       gpTMax = assocPtArr[j+1] - 0.01;
7262       
7263       TString str2;
7264       str2.Form("%.1f < p_{T,assoc} < %.1f", gpTMin - 0.01, gpTMax + 0.01);
7265       
7266       SetupRanges(h);
7267
7268       if (h2)
7269       {
7270         SetupRanges(h2); // SetEtaRange(0, 0) does not need to be called for the leading track result
7271       }
7272       
7273       if (hMixed)
7274       {
7275         SetupRanges(hMixed);
7276       }
7277       
7278       // delta phi
7279       if (!twoD)
7280       {
7281         if (assocPtArr[j] >= leadingPtArr[i+leadingPtOffset])
7282           continue;
7283     
7284         // 0-5% --> 1, 5
7285         // 0-10% --> 1, 6
7286         // 0-20% --> 1, 8
7287         // 20-40% --> 9, 10
7288         // 40-80% --> 11, 14
7289         // > 40% --> 11, 16
7290         
7291         TString hist1Str, hist2Str, hist2bStr;
7292         
7293         Float_t v2[3];
7294         for (Int_t k=0; k<3; k++)
7295           v2[k] = 0;
7296         Float_t vn[3][3];
7297         
7298         if (veryCentral)
7299         {
7300           Int_t step = 0;
7301           TH1* hist1 = 0;
7302           TH1* hist2 = 0;
7303           TH1* hist2b = 0;
7304           TH1* hist3 = 0;
7305           
7306           GetDistAndFlow(h, hMixed, &hist1,  v2, step, 0,  2,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01); hist1Str = "0-2%";
7307 //        GetDistAndFlow(h, hMixed, &hist2,  v2, step, 1,  3,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01); hist2Str = "1-3%";
7308           GetDistAndFlow(h, hMixed, &hist2b,  v2+2, step, 30,  40,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01); hist2bStr = "30-40%";
7309           
7310           //TH1* hist1 = h->GetUEHist(2)->GetUEHist(step, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 1, 2);  hist1Str = "0-2%";
7311           //TH1* hist2 = h->GetUEHist(2)->GetUEHist(step, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 2, 3);  hist2Str = "2-3%";
7312           //TH1* hist2b = h->GetUEHist(2)->GetUEHist(step, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 10, 10); hist2bStr = "30-40%";
7313         }
7314         else if (flowComparison)
7315         {
7316           TH1* hist1 = h->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 1, 5);  hist1Str = "0-5%";
7317           TH1* hist2 = h->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 9, 10);  hist2Str = "20-40%";
7318           TH1* hist2b = h->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 10, 10); hist2bStr = "30-40%";
7319           TH1* hist3 = 0; // h2->GetUEHist(2)->GetUEHist(0, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01);
7320         }
7321         else if (rhicOverlay)
7322         {
7323           TH1* hist1 = h->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 1, 8);   hist1Str = "0-20%";
7324           TH1* hist2 = h->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 9, 12);  hist2Str = "20-60%";
7325           TH1* hist2b = h->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 13, 15);hist2bStr = "60-90%";
7326           TH1* hist3 = h2->GetUEHist(2)->GetUEHist(0, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01);
7327         }
7328         else
7329         {
7330           Int_t step = 6;
7331           TH1* hist1 = 0;
7332           TH1* hist2 = 0;
7333           TH1* hist2b = 0;
7334           
7335           Bool_t equivMixedBin = 1;
7336           Int_t histType = 0;
7337 //        histType = 20; Printf("WARNING: Using histogram type 20");
7338           
7339 //           GetDistAndFlow(h, hMixed, &hist1,  v2, step, 0,  2,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, vn[0]); hist1Str = "0-2%";
7340 //           GetDistAndFlow(h, hMixed, &hist1,  v2, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, vn[0]); hist1Str = "0-5%";
7341           GetDistAndFlow(h, hMixed, &hist1,  v2, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin); hist1Str = "0-5%";
7342           
7343           /*
7344           new TCanvas;
7345           hist1->Draw();
7346
7347           TH1* histTmp1 = 0;
7348           GetDistAndFlow(h, hMixed, &histTmp1,  v2, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 10, equivMixedBin); hist1Str = "0-5%";
7349           histTmp1->SetLineColor(2);
7350           histTmp1->Draw("SAME");
7351           histTmp1->Scale(1 / 0.75);
7352           
7353           histTmp1 = 0;
7354           GetDistAndFlow(h, hMixed, &histTmp1,  v2, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 20, equivMixedBin); hist1Str = "0-5%";
7355           histTmp1->SetLineColor(4);
7356           histTmp1->Draw("SAME");
7357           histTmp1->Scale(1 / 0.75);
7358
7359           histTmp1 = 0;
7360           GetDistAndFlow(h, hMixed, &histTmp1,  v2, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 11, equivMixedBin); hist1Str = "0-5%";
7361           histTmp1->SetLineColor(3);
7362           histTmp1->Draw("SAME");
7363           histTmp1->Scale(1 / 0.25);
7364
7365           return;
7366           */
7367
7368           GetDistAndFlow(h, hMixed, &hist2,  v2+1, step, 0, 20, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin); hist2Str = "0-20%";
7369 //           GetDistAndFlow(h, hMixed, &hist2b, v2[2], step, 60, 80, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 0, equivMixedBin); hist2bStr = "60-80%";
7370           GetDistAndFlow(h, hMixed, &hist2b, v2+2, step, 60, 90, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin); hist2bStr = "60-90%";
7371           
7372           Printf("%f %f %f", v2[0], v2[1], v2[2]);
7373 //           Printf("%f %f %f", vn[0][1], vn[0][2], vn[0][3]);
7374           
7375 //           TH1* hist1 = h->GetUEHist(2)->GetUEHist(step, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 1, 8);    hist1Str = "0-20%";
7376 //           TH1* hist2 = h->GetUEHist(2)->GetUEHist(step, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 9, 12);   hist2Str = "20-60%";
7377 //           TH1* hist2b = h->GetUEHist(2)->GetUEHist(step, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 13, 15); hist2bStr = "60-90%";
7378           
7379           step = 6;
7380 //           TH1* hist3Old = h2->GetUEHist(2)->GetUEHist(step, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01);
7381           TH1* hist3 = 0;
7382           GetDistAndFlow(h2, hMixed2, &hist3,  0, step, 0,  -1,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin);
7383 //        hist3->Rebin(2); hist3->Scale(0.5);
7384           
7385 /*        new TCanvas;
7386           hist3->Draw();
7387           hist3Old->DrawCopy("SAME")->SetLineColor(2); */
7388         }
7389         
7390         /*
7391         RemoveBaseLine(hist1);
7392         RemoveBaseLine(hist2);
7393         RemoveBaseLine(hist2b);
7394         RemoveBaseLine(hist3);
7395         */
7396         
7397         TString newTitle;
7398         newTitle.Form("%s - %s", str.Data(), str2.Data());
7399         if (hist1)
7400         {
7401           hist1->SetName(Form("dphi_%d_%d_%d", i, j, 0));
7402           hist1->SetTitle(newTitle + " - " + hist1Str);
7403         }
7404         if (hist2)
7405         {
7406           hist2->SetName(Form("dphi_%d_%d_%d", i, j, 1));
7407           hist2->SetTitle(newTitle + " - " + hist2Str);
7408         }
7409         if (hist2b)
7410         {
7411           hist2b->SetName(Form("dphi_%d_%d_%d", i, j, 2));
7412           hist2b->SetTitle(newTitle + " - " + hist2bStr);
7413         }
7414         if (hist3)
7415         {
7416           hist3->SetName(Form("dphi_%d_%d_%d", i, j, 3));
7417           hist3->SetTitle(newTitle + " - pp");
7418         }
7419         
7420         if (0)
7421         {
7422           hist1->Scale(1.0 / hist1->Integral());
7423           hist2->Scale(1.0 / hist2->Integral());
7424           hist3->Scale(1.0 / hist3->Integral());
7425         }
7426       
7427         if (i == 0 && j == 0)
7428         {
7429           legend->SetFillColor(0);
7430           legend->AddEntry(hist1, "Pb+Pb 0-5%");
7431           if (hist2)
7432             legend->AddEntry(hist2, "Pb+Pb 20-40%");
7433           if (hist2b)
7434             legend->AddEntry(hist2b, "Pb+Pb 60-90%");
7435           if (hist3)
7436             legend->AddEntry(hist3, "p+p 7 TeV");
7437           legend->SetTextSize(0.08);
7438         }
7439       
7440         Prepare1DPlot(hist1);
7441         Prepare1DPlot(hist2);
7442         Prepare1DPlot(hist2b);
7443         Prepare1DPlot(hist3);
7444         
7445         Double_t yMin = 0.01;
7446         Double_t yMax2 = yMax;
7447         
7448         if (yMax < 0)
7449         {
7450           yMin = -0.01; //TMath::Min(hist1->GetMinimum(), hist2->GetMinimum()) * 0.97;
7451           yMax2 = TMath::Max((hist3) ? hist3->GetMaximum() : 0.0, TMath::Max(hist1->GetMaximum(), (hist2) ? hist2->GetMaximum() : 0.0)) * 1.03;
7452         }
7453         
7454         yMax2 *= 1.4;
7455       
7456         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);
7457         dummy->SetStats(kFALSE);
7458         dummy->SetXTitle(hist1->GetXaxis()->GetTitle());
7459         dummy->SetYTitle(hist1->GetYaxis()->GetTitle());
7460         dummy->SetYTitle("1/N_{trig} dN/d#Delta#phi"); 
7461         Prepare1DPlot(dummy);
7462         
7463         dummy->GetYaxis()->SetTitleOffset(0.8);
7464       
7465         dummy->GetXaxis()->SetLabelSize(0.08);
7466         dummy->GetYaxis()->SetLabelSize(0.08);
7467         dummy->GetXaxis()->SetTitleSize(0.08);
7468         dummy->GetYaxis()->SetTitleSize(0.08);
7469         /*
7470         dummy->GetYaxis()->SetTitleOffset(0.8);
7471         */
7472         
7473         dummyTmp = dummy->DrawCopy();
7474         
7475         hist1->DrawCopy("SAME");
7476         
7477         if (hMixed)
7478         {
7479           SetupRanges(hMixed);
7480           // for HI file do not set range in eta anymore after it was changed to delta eta axis
7481           hMixed->SetEtaRange(0, 0);
7482         }
7483         TH1* hist1Mixed = 0; //hMixed->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 1, 5);
7484         //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]);
7485         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);
7486         
7487         //hist1Mixed->Draw("SAME");
7488         if (hist2)
7489         {
7490           hist2->SetLineColor(2);
7491           hist2->DrawCopy("SAME");
7492           
7493           TH1* hist2Mixed = 0; //hMixed->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 9, 10);
7494           //hist2Mixed->SetLineColor(2);
7495           //hist2Mixed->Draw("SAME");
7496
7497           DrawFlow(v2[1], hist2, leadingPtArr[i], assocPtArr[j], hist2Mixed, i, 1, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
7498           //DrawFlow(GetFlow05(), hist2, leadingPtArr[i], assocPtArr[j], hist2Mixed);
7499         }
7500         if (hist2b)
7501         {
7502           hist2b->SetLineColor(3);
7503           hist2b->DrawCopy("SAME");
7504         
7505           TH1* hist2bMixed = 0; //hMixed->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 13, 15);
7506           DrawFlow(v2[2], hist2b, leadingPtArr[i], assocPtArr[j], hist2bMixed, i, 2, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
7507           //DrawFlow(GetFlow05(), hist2b, leadingPtArr[i], assocPtArr[j], hist2bMixed);
7508         }
7509         if (hist3)
7510         {
7511           hist3->SetLineColor(4);
7512           hist3->DrawCopy("SAME");
7513           
7514           DrawFlow(0, hist3, leadingPtArr[i], assocPtArr[j], 0, i, 3, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
7515         }
7516         //dummyTmp->GetYaxis()->SetRangeUser(0, 1.1 * TMath::Max(TMath::Max(hist1->GetMaximum(), hist2->GetMaximum()), hist2b->GetMaximum()));
7517       }
7518       else // delta eta delta phi
7519       {
7520         if (twoD == 1)
7521         {
7522           if (assocPtArr[j] > leadingPtArr[i])
7523             continue;
7524         }
7525         else
7526         {
7527           Int_t jRef = 1;
7528         
7529           if (assocPtArr[jRef] > leadingPtArr[i])
7530             continue;
7531           
7532           // fix pt assoc
7533           gpTMin = assocPtArr[jRef] + 0.01;
7534           gpTMax = assocPtArr[jRef+1] - 0.01;
7535           
7536           str2.Form("%.1f < p_{T,assoc} < %.1f", gpTMin - 0.01, gpTMax + 0.01);
7537       
7538           // use j for centrality
7539           if (j >= nCentralityBins)
7540             continue;
7541             
7542           centrBegin = centralityBins[j];
7543           centrEnd = centralityBins[j+1] - 1;
7544         }
7545         
7546         SetupRanges(h);
7547         // for HI file do not set range in eta anymore after it was changed to delta eta axis
7548         h->SetEtaRange(0, 0);
7549         
7550         SetupRanges(hMixed);
7551         // for HI file do not set range in eta anymore after it was changed to delta eta axis
7552         hMixed->SetEtaRange(0, 0);
7553           
7554         TH2* histSame = (TH2*) h->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, centrBegin, centrEnd, kTRUE);
7555         TH2* histMixed = (TH2*) hMixed->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, centrBegin, centrEnd, kTRUE);
7556         
7557         // rebin 
7558         histSame->Rebin2D(2, 2);
7559         histMixed->Rebin2D(2, 2);
7560         
7561         if (1)
7562         {
7563           // fit delta eta, assuming no dependence on dphi
7564           
7565           //new TCanvas; histMixed->DrawCopy("SURF1");
7566           
7567           histMixedproj = histMixed->ProjectionY();
7568           histMixedproj->Scale(1.0 / histMixed->GetNbinsX());
7569           
7570           for (Int_t x=1; x<=histMixed->GetNbinsX(); x++)
7571             for (Int_t y=1; y<=histMixed->GetNbinsY(); y++)
7572               histMixed->SetBinContent(x, y, histMixedproj->GetBinContent(y));
7573           
7574           //new TCanvas; histMixed->DrawCopy("SURF1");
7575         }
7576         
7577         histSame->SetStats(0);
7578         histSame->GetYaxis()->SetRangeUser(-1.5, 1.5);
7579         histSame->SetTitle("");
7580         histSame->Divide(histMixed);
7581         histSame->DrawCopy("SURF1");
7582         
7583         TString str3;
7584         str3.Form("%d-%d%%", (Int_t) h->GetCentralityDistribution()->GetXaxis()->GetBinLowEdge(centrBegin), (Int_t) h->GetCentralityDistribution()->GetXaxis()->GetBinUpEdge(centrEnd));
7585         latex = new TLatex(0.15, 0.95, str3);
7586         latex->SetNDC();
7587         latex->SetTextSize(0.08);
7588         latex->Draw();
7589       }
7590       
7591       latex = new TLatex(0.55, 0.8, str);
7592       latex->SetNDC();
7593       latex->SetTextSize(0.06);
7594       latex->Draw();
7595       
7596       latex = new TLatex(0.55, 0.88, str2);
7597       latex->SetNDC();
7598       latex->SetTextSize(0.06);
7599       latex->Draw();
7600       
7601 //            if (i == 0)        return;
7602     }
7603
7604   canvas->SaveAs(Form("DeltaPhi_%.2f.png", yMax));
7605   
7606   canvas2->cd();
7607   legend2->Draw();
7608
7609   //TString name;
7610   //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]);
7611 }
7612    
7613 void ExamplePhiEtaGap(const char* fileNamePbPb, const char* fileNamePbPbMix)
7614 {
7615   loadlibs();
7616   
7617   if (!fileNamePbPbMix)
7618     fileNamePbPbMix = fileNamePbPb;
7619   
7620   Int_t leadingPtOffset = 1;
7621     
7622   Int_t maxLeadingPt = 4;
7623   Int_t maxAssocPt = 5;
7624   Float_t leadingPtArr[] = { 2.0, 3.0, 6.0, 6.0, 8.0, 10.0, 15.0, 20.0 };
7625   Float_t assocPtArr[] =     { 0.15, 0.5, 1.0, 2.0, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
7626   leadingPtOffset = 1;
7627   
7628   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileNamePbPb);
7629   hMixed = (AliUEHistograms*) GetUEHistogram(fileNamePbPbMix, 0, kTRUE);
7630   
7631   Int_t i=1;
7632   Int_t j=2;
7633   
7634   gpTMin = assocPtArr[j] + 0.01;
7635   gpTMax = assocPtArr[j+1] - 0.01;
7636   
7637   SetupRanges(h);
7638   SetupRanges(hMixed);
7639
7640   if (assocPtArr[j] >= leadingPtArr[i+leadingPtOffset])
7641     continue;
7642
7643   TString hist1Str, hist2Str, hist2bStr;
7644   
7645   Int_t step = 6;
7646   TH1* hist1 = 0;
7647   TH1* hist2 = 0;
7648   TH1* hist3 = 0;
7649   
7650   Float_t v2[3];
7651   
7652   Bool_t equivMixedBin = kTRUE;
7653   
7654   Int_t centralityBegin = 20;
7655   Int_t centralityEnd = 30;
7656   
7657   GetDistAndFlow(h, hMixed, &hist1,  0, step, centralityBegin, centralityEnd,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 20, equivMixedBin); 
7658
7659   GetDistAndFlow(h, hMixed, &hist2,  0, step, centralityBegin, centralityEnd,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 10, equivMixedBin); 
7660 //   hist2->Scale(1.0 / 0.8);
7661   
7662   GetDistAndFlow(h, hMixed, &hist3,  0, step, centralityBegin, centralityEnd,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 11, equivMixedBin); 
7663   hist3->Scale(1.0 / 0.8);
7664   
7665   hist1->Draw();
7666   hist2->SetLineColor(2);
7667   hist2->Draw("SAME");
7668   hist3->SetLineColor(4);
7669   hist3->Draw("SAME");
7670 }  
7671
7672 void ExampleDEtaDPhi(const char* fileNamePbPb, const char* fileNamePbPbMix)
7673 {
7674   loadlibs();
7675   
7676   if (!fileNamePbPbMix)
7677     fileNamePbPbMix = fileNamePbPb;
7678   
7679   Int_t leadingPtOffset = 1;
7680     
7681   Int_t maxLeadingPt = 4;
7682   Int_t maxAssocPt = 5;
7683   Float_t leadingPtArr[] = { 1.0, 2.0, 3.0, 6.0, 6.0, 8.0, 10.0, 15.0, 20.0 };
7684   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 };
7685   leadingPtOffset = 1;
7686   
7687   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileNamePbPb);
7688   hMixed = (AliUEHistograms*) GetUEHistogram(fileNamePbPbMix, 0, kTRUE);
7689   
7690   Int_t i=1;
7691   Int_t j=3;
7692   
7693   gpTMin = assocPtArr[j] + 0.01;
7694   gpTMax = assocPtArr[j+1] - 0.01;
7695   
7696   SetupRanges(h);
7697   SetupRanges(hMixed);
7698
7699   Int_t step = 6;
7700   TH1* hist1 = 0;
7701
7702   GetSumOfRatios(h, hMixed, &hist1,  step, 0,  5, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
7703
7704   hist1->Draw("SURF1");
7705 }
7706
7707 Double_t GetEtaCut(TTree* analysisSettings)
7708 {
7709   Double_t etaCut = 0;
7710   if (analysisSettings)
7711   {
7712     analysisSettings->GetBranch("fTrackEtaCut")->SetAddress(&etaCut);
7713     analysisSettings->GetEntry(0);
7714   }
7715   return etaCut;
7716 }
7717
7718 void PlotDeltaPhiEtaGap(const char* fileNamePbPb, const char* fileNamePbPbMix = 0, const char* fileNamepp = 0, const char* fileNamepp2 = 0, const char* outputFile = "dphi_corr.root")
7719 {
7720   loadlibs();
7721   
7722   if (!fileNamePbPbMix)
7723     fileNamePbPbMix = fileNamePbPb;
7724   
7725   file = TFile::Open(outputFile, "RECREATE");
7726   file->Close();
7727   
7728   Int_t leadingPtOffset = 1;
7729     
7730   Bool_t symmetrizePt = kFALSE;
7731   Int_t maxLeadingPt = 4;
7732   Int_t maxAssocPt = 6;
7733   if (1)
7734   {
7735     //PbPb, NS peak shapes
7736     Float_t leadingPtArr[] = { 1.0, 2.0, 3.0, 4.0, 8.0, 15.0, 20.0 };
7737 //     Float_t leadingPtArr[] = { 2.0, 3.0, 4.0, 8.0, 15.0, 20.0 };
7738     Float_t assocPtArr[] =     { 0.15, 0.5, 1.0, 2.0, 3.0, 4.0, 8.0, 10.0, 12.0 };
7739   }
7740   else if (0)
7741   {
7742     //Example for the Hadrons_Example wagon
7743     maxLeadingPt = 3;
7744     maxAssocPt = 6;
7745     Float_t leadingPtArr[] =     { 3.0, 5.0, 8.0, 16.0 };
7746     Float_t assocPtArr[] = {0.15, 0.3, 50.0, 0.5, 50.0, 1.0, 50.0 };
7747   }
7748   else if (0)
7749   {
7750     //pA, trigger from all pT
7751     maxLeadingPt = 1;
7752     maxAssocPt = 10;
7753     Float_t leadingPtArr[] =   { 0.3, 4.0 };
7754     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 };
7755 //     symmetrizePt = kTRUE;
7756   }
7757   else if (0)
7758   {
7759     //pA, associated from all pT
7760     maxLeadingPt = 6;
7761     maxAssocPt = 2;
7762     Float_t leadingPtArr[] =     { 0.5, 1.0, 2.0, 3.0, 4.0, 0.5, 4.0 };
7763     Float_t assocPtArr[] = { 0.15, 0.5, 4.0 };
7764 //     symmetrizePt = kTRUE;
7765   }  
7766   else if (0)
7767   {
7768     //pA
7769     maxLeadingPt = 5;
7770     maxAssocPt = 6;
7771     Float_t leadingPtArr[] = { 0.5, 1.0, 1.5, 2.0, 2.5,  4.0, 8.0, 15.0, 20.0 };
7772     Float_t assocPtArr[] =     { 0.15, 0.5, 1.0, 1.5, 2.0, 2.5, 4.0, 8.0, 10.0, 12.0 };
7773   }
7774   else if (0)
7775   {
7776     //pPb and PbPb with PID, with low pt points TPC only
7777     maxLeadingPt = 10;
7778     maxAssocPt = 11;
7779     Float_t leadingPtArr[] = {   0.2, 0.3, 0.5 , 0.75, 1.0, 1.25, 1.5, 2.0, 2.5, 3., 4.0};
7780     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 };
7781   }
7782   else if (1)
7783   {
7784     //PbPb for comaprison with You
7785     maxLeadingPt = 8;
7786     maxAssocPt = 9;
7787     Float_t leadingPtArr[] = {   0.2, 0.3, 0.5 , 1.0, 1.5, 2.0, 2.5, 3., 4.0};
7788     Float_t assocPtArr[] =   { 0.15, 0.2, 0.3, 0.5 , 1.0, 1.5, 2.0, 2.5, 3., 4.0 };
7789   }
7790   else if (1)
7791   {
7792     //pA, fine
7793     maxLeadingPt = 6;
7794     maxAssocPt = 7;
7795     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 };
7796     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 };
7797   }
7798   else if (0)
7799   {
7800     //pA, v3
7801     maxLeadingPt = 3;
7802     maxAssocPt = 4;
7803     Float_t leadingPtArr[] =   {       0.5, 1.5, 2.5, 4.0, 5.0, 8.0, 15.0, 20.0 };
7804     Float_t assocPtArr[] =     { 0.15, 0.5, 1.5, 2.5, 4.0, 5.0, 8.0, 10.0, 12.0 };
7805   }
7806   else if (0)
7807   {
7808     //pA 2012; MC validation (also PbPb)
7809     maxLeadingPt = 3;
7810     maxAssocPt = 4;
7811     Float_t leadingPtArr[] = { 0.5, 1.0, 2.0, 4.0, 8.0, 15.0, 20.0 };
7812     Float_t assocPtArr[] =     { 0.15, 0.5, 1.0, 2.0, 4.0, 8.0, 10.0, 12.0 };
7813   }
7814   else if (0)
7815   {
7816     // pA, CMS ridge comparison
7817     maxLeadingPt = 4;
7818     maxAssocPt = 5;
7819     Float_t leadingPtArr[] = { 0.5, 1.0, 2.0, 3.0, 4.0, 8.0, 15.0, 20.0 };
7820     Float_t assocPtArr[] =     { 0.15, 0.5, 1.0, 2.0, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
7821   }
7822   else if (0) 
7823   {
7824     maxLeadingPt = 1;
7825     maxAssocPt = 3;
7826     Float_t leadingPtArr[] = { 2.0, 3.0};
7827     Float_t assocPtArr[] =     {0.15, 0.5, 1.0, 2.0};
7828   }
7829   else if (0) //Comparison to STAR (p_T,t)
7830   {
7831     maxLeadingPt = 4;
7832     maxAssocPt = 3;
7833     Float_t leadingPtArr[] = { 2.0, 3.0, 4.0, 5.0, 6.0};
7834     Float_t assocPtArr[] =     {0.15, 0.5, 1.5, 6.0};
7835   }
7836   else if (0) //Comparison to STAR (p_T,a)
7837   {
7838     maxLeadingPt = 1;
7839     maxAssocPt = 6;
7840     Float_t leadingPtArr[] = { 3.0, 6.0};
7841     Float_t assocPtArr[] =     {0.15, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0};
7842   }
7843   else if (0) 
7844   {
7845     maxLeadingPt = 4;
7846     maxAssocPt = 4;
7847     Float_t leadingPtArr[] = { 2.0, 3.0, 4.0, 8.0, 15.0 };
7848     Float_t assocPtArr[] =     {0.15, 0.5, 1.0, 1.5, 2.0};
7849   }
7850   
7851   TList* list = 0;
7852   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileNamePbPb, &list);
7853   hMixed = (AliUEHistograms*) GetUEHistogram(fileNamePbPbMix, 0, kTRUE);
7854 //   hMixed3 = (AliUEHistograms*) hMixed->Clone();
7855   
7856   if (symmetrizePt)
7857   {
7858     h->GetUEHist(2)->SymmetrizepTBins();
7859     hMixed->GetUEHist(2)->SymmetrizepTBins();
7860   }
7861   
7862   TList* list2 = 0;
7863   AliUEHistograms* h2 = 0;
7864   AliUEHistograms* hMixed2 = 0;
7865   if (fileNamepp)
7866   {
7867     h2 = (AliUEHistograms*) GetUEHistogram(fileNamepp, &list2);
7868     hMixed2 = (AliUEHistograms*) GetUEHistogram(fileNamepp, 0, kTRUE);
7869   }
7870
7871   TList* list3 = 0;
7872   AliUEHistograms* h3 = 0;
7873   AliUEHistograms* hMixed3 = 0;
7874   if (fileNamepp2)
7875   {
7876     h3 = (AliUEHistograms*) GetUEHistogram(fileNamepp2, &list3);
7877     hMixed3 = (AliUEHistograms*) GetUEHistogram(fileNamepp2, 0, kTRUE);
7878   }
7879
7880 //   h->GetUEHist(2)->SetGetMultCache();
7881 //   hMixed->GetUEHist(2)->SetGetMultCache();
7882
7883   TH2* refMultRaw = (TH2*) list->FindObject("referenceMultiplicity");
7884   if (refMultRaw)
7885   {
7886 //     new TCanvas; refMultRaw->Draw("COLZ");
7887     Int_t nCentrBins = 4;
7888     Double_t centrBins[] = { 0., 20., 40., 60., 100. };
7889 //     Double_t centrBins[] = { 0., 3., 10., 50., 100. };
7890     TH1* refMult = new TH1F("refMult", ";centrality;<Nch>", nCentrBins, centrBins);
7891     for (Int_t i=0; i<nCentrBins; i++)
7892     {
7893       TH1* proj = refMultRaw->ProjectionY(Form("proj%d", i), refMultRaw->GetXaxis()->FindBin(centrBins[i] + 0.1), refMultRaw->GetXaxis()->FindBin(centrBins[i+1] - 0.1));
7894 //       new TCanvas; proj->DrawClone();
7895       refMult->SetBinContent(refMult->GetXaxis()->FindBin(centrBins[i] + 0.1), proj->GetMean());
7896       refMult->SetBinError(refMult->GetXaxis()->FindBin(centrBins[i] + 0.1), proj->GetMeanError());
7897       Printf("Ref multiplicity for centrality %f to %f: %f", centrBins[i], centrBins[i+1], proj->GetMean());
7898     }
7899 //     new TCanvas; refMult->Draw();
7900     file = TFile::Open(outputFile, "UPDATE");
7901     refMult->Write();
7902     file->Close();
7903 //     return;
7904   }
7905
7906   tree = (TTree*) list->FindObject("UEAnalysisSettings");
7907   Double_t etaCut = GetEtaCut(tree);
7908   Printf("Setting eta cut to %f", etaCut);
7909   h->SetTrackEtaCut(etaCut);
7910
7911   if (list2)
7912   {
7913     tree = (TTree*) list2->FindObject("UEAnalysisSettings");
7914     if (tree)
7915     {
7916       Double_t etaCut = GetEtaCut(tree);
7917       Printf("Setting eta cut to %f", etaCut);
7918       h2->SetTrackEtaCut(etaCut);
7919     }
7920     else
7921     {
7922       Double_t etaCut = 0.9;
7923       Printf("WARNING: Setting eta cut to %f without checking", etaCut);
7924       h2->SetTrackEtaCut(etaCut);
7925     }
7926   }
7927
7928   if (list3)
7929   {
7930     tree = (TTree*) list3->FindObject("UEAnalysisSettings");
7931     if (tree)
7932     {
7933       Double_t etaCut = GetEtaCut(tree);
7934       Printf("Setting eta cut to %f", etaCut);
7935       h3->SetTrackEtaCut(etaCut);
7936     }
7937     else
7938     {
7939       Double_t etaCut = 0.9;
7940       Printf("WARNING: Setting eta cut to %f without checking", etaCut);
7941       h3->SetTrackEtaCut(etaCut);
7942     }
7943   }
7944   
7945   for (Int_t i=0; i<maxLeadingPt; i++)
7946   {
7947     for (Int_t j=2; j<maxAssocPt; j++)
7948     {
7949       if(0){
7950         if(j!=(i+1))continue;
7951         Printf("\nOnly symmetric pt bins selected, leading pt: %f - %f     associated pt: %f - %f",leadingPtArr[i],leadingPtArr[i+leadingPtOffset],assocPtArr[j],assocPtArr[j+1]); 
7952       }
7953
7954       gpTMin = assocPtArr[j] + 0.01;
7955       gpTMax = assocPtArr[j+1] - 0.01;
7956       
7957       if(gpTMin >= gpTMax)continue;
7958         
7959       SetupRanges(h);
7960       SetupRanges(hMixed);
7961       SetupRanges(h2);
7962       SetupRanges(hMixed2);
7963       SetupRanges(h3);
7964       SetupRanges(hMixed3);
7965 //       SetupRanges(hMixed3);
7966
7967       if(1) if (assocPtArr[j] >= leadingPtArr[i+leadingPtOffset])
7968         continue;
7969   
7970       TH1* hist1 = 0;
7971       TH1* hist2 = 0;
7972       TH1* hist3 = 0;
7973       TH1* hist4 = 0;
7974       TH1* hist5 = 0;
7975       TH1* hist6 = 0;
7976       TH1* hist7 = 0;
7977       TH1* hist8 = 0;
7978       
7979       Bool_t equivMixedBin = 1; //kFALSE; // TODO ?
7980       Bool_t scaleToPairs = kTRUE;
7981       
7982       Int_t histType = 1;
7983
7984       if (1)
7985       {
7986         // PbPb
7987         Int_t step = 8;
7988         Bool_t normalizePerTrigger = kFALSE; // don't do if histograms are to be merged -> Use MergeDPhiFiles below
7989       
7990         GetSumOfRatios(h, hMixed, &hist1,  step, 0,   10, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, normalizePerTrigger); 
7991         GetSumOfRatios(h, hMixed, &hist5,  step, 10,  20, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, normalizePerTrigger); 
7992         GetSumOfRatios(h, hMixed, &hist4,  step, 20,  30, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, normalizePerTrigger); 
7993         GetSumOfRatios(h, hMixed, &hist6,  step, 30,  50, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, normalizePerTrigger); 
7994         GetSumOfRatios(h, hMixed, &hist2,  step, 50,  80, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, normalizePerTrigger); 
7995
7996         if (h2)
7997           GetSumOfRatios(h2, hMixed2, &hist3,  step, 0,  -1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
7998       }
7999       else if (0)
8000       {
8001         // pA, fine binning
8002         Int_t step = 8;
8003 //      Int_t step = 0;
8004       
8005         GetSumOfRatios(h, hMixed, &hist1,  step,  0, 20, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8006         GetSumOfRatios(h, hMixed, &hist2,  step, 20, 40, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8007         GetSumOfRatios(h, hMixed, &hist4,  step, 40, 60, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8008         GetSumOfRatios(h, hMixed, &hist5,  step, 60, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8009 //      GetSumOfRatios(h, hMixed, &hist7,  step, 70, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8010 //      GetSumOfRatios(h, hMixed, &hist8,  step, 80, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8011
8012         if (h2)
8013           GetSumOfRatios(h2, hMixed2, &hist3,  step, 0,  -1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8014         
8015         if (h3)
8016           GetSumOfRatios(h3, hMixed3, &hist6,  step, 0,  -1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8017       }      
8018       else if (0)
8019       {
8020         // pA, V0 as trigger particle detector
8021         Int_t step = 6;
8022       
8023         h->GetUEHist(2)->SetSkipScaleMixedEvent(kTRUE);
8024         GetSumOfRatios(h, hMixed, &hist1,  step,  0, 20, 1.01, 1.99, kTRUE); 
8025         GetSumOfRatios(h, hMixed, &hist2,  step, 20, 40, 1.01, 1.99, kTRUE); 
8026         GetSumOfRatios(h, hMixed, &hist4,  step, 40, 60, 1.01, 1.99, kTRUE); 
8027         GetSumOfRatios(h, hMixed, &hist5,  step, 60, 100, 1.01, 1.99, kTRUE); 
8028
8029         if (h2)
8030           GetSumOfRatios(h2, hMixed2, &hist3,  step, 0,  -1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8031         
8032         if (h3)
8033           GetSumOfRatios(h3, hMixed3, &hist6,  step, 0,  -1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8034       }      
8035       else if (0)
8036       {
8037         // pp, MB
8038         Int_t step = 8;      
8039         GetSumOfRatios(h, hMixed, &hist1,  step, 0, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE, kTRUE); 
8040       }      
8041       else if (0)
8042       {
8043         // pp
8044         Int_t step = 8;
8045       
8046         GetSumOfRatios(h, hMixed, &hist1,  step, 4, 4, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE, kTRUE); 
8047         GetSumOfRatios(h, hMixed, &hist2,  step, 3, 3, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE, kTRUE); 
8048         GetSumOfRatios(h, hMixed, &hist4,  step, 2, 2, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE, kTRUE); 
8049         GetSumOfRatios(h, hMixed, &hist5,  step, 1, 1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE, kTRUE); 
8050       }      
8051       else if (0)
8052       {
8053         // pA, course binning
8054         Int_t step = 8;
8055       
8056         GetSumOfRatios(h, hMixed, &hist1,  step,  0, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8057         GetSumOfRatios(h, hMixed, &hist2,  step,  0,  40, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8058         GetSumOfRatios(h, hMixed, &hist4,  step, 40, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8059
8060         GetDistAndFlow(h, hMixed, &hist5,  0, step, 0, 100,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8061
8062         GetSumOfRatios(h2, hMixed2, &hist3,  step, 0,  -1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8063       }      
8064       else if (0)
8065       {
8066         // pA, CMS ridge paper comparison
8067         Int_t step = 8;
8068       
8069         GetSumOfRatios(h, hMixed, &hist1,  step,  0, 3, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8070         GetSumOfRatios(h, hMixed, &hist2,  step,  3, 10, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8071         GetSumOfRatios(h, hMixed, &hist4,  step, 10, 50, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8072         GetSumOfRatios(h, hMixed, &hist5,  step, 50, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8073         GetSumOfRatios(h, hMixed, &hist7,  step, 80, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8074       }     
8075       else if (0)
8076       {
8077         // pA, MC, validation binning
8078         GetSumOfRatios(h, hMixed, &hist1,  0,  0, 80, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8079         GetSumOfRatios(h, hMixed, &hist5,  10,  0, 80, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8080       }        
8081       else if (0)
8082       {
8083         // pA, MC, validation binning
8084         GetSumOfRatios(h, hMixed, &hist1,  0,  0, 20, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8085         GetSumOfRatios(h, hMixed, &hist2,  0,  20, 40, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8086         GetSumOfRatios(h, hMixed, &hist3,  0,  40, 60, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8087         GetSumOfRatios(h, hMixed, &hist4,  0,  60, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8088         GetSumOfRatios(h, hMixed, &hist5,  10,  0, 20, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8089         GetSumOfRatios(h, hMixed, &hist6,  10,  20, 40, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8090         GetSumOfRatios(h, hMixed, &hist7,  10,  40, 60, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8091         GetSumOfRatios(h, hMixed, &hist8,  10,  60, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8092       }        
8093       else if (0)
8094       {
8095         // pp, MB
8096         Int_t step = 8;
8097         
8098         GetSumOfRatios(h, hMixed, &hist1,  step,  0, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8099       }      
8100       else if (0)
8101       {
8102         // pA, MC, validation binning, without vertex axis
8103         GetDistAndFlow(h, hMixed, &hist1,  0, 0,  0, 20, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8104         GetDistAndFlow(h, hMixed, &hist2,  0, 0,  20, 40, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8105         GetDistAndFlow(h, hMixed, &hist3,  0, 0,  40, 60, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8106         GetDistAndFlow(h, hMixed, &hist4,  0, 0,  60, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8107         GetDistAndFlow(h, hMixed, &hist5,  0, 10,  0, 20, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8108         GetDistAndFlow(h, hMixed, &hist6,  0, 10,  20, 40, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8109         GetDistAndFlow(h, hMixed, &hist7,  0, 10,  40, 60, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8110         GetDistAndFlow(h, hMixed, &hist8,  0, 10,  60, 100, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8111       }        
8112       else if (1)
8113       {
8114         // PbPb, MC, impact parameter binning
8115         Int_t step = 0;
8116         
8117         Printf(">>>>>>>> Not using GetSumOfRatios!!!");
8118
8119         GetDistAndFlow(h, hMixed, &hist1,  0, step, 1,   6,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs, -1, kTRUE); 
8120         GetDistAndFlow(h, hMixed, &hist5,  0, step, 7,  7, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs, -1, kTRUE); 
8121         GetDistAndFlow(h, hMixed, &hist4,  0, step, 8,  8, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs, -1, kTRUE); 
8122         GetDistAndFlow(h, hMixed, &hist6,  0, step, 9,  10, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs, -1, kTRUE); 
8123         GetDistAndFlow(h, hMixed, &hist2,  0, step, 11,  13, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs, -1, kTRUE);
8124
8125         if (h2)
8126           GetDistAndFlow(h2, hMixed2, &hist3,  0, step, 0, -1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs);
8127       }
8128       else if (1)
8129       {
8130         // PbPb, MC
8131         Int_t step = 0;
8132         
8133         Printf(">>>>>>>> Not using GetSumOfRatios!!!");
8134         GetDistAndFlow(h, hMixed, &hist1,  0, step, 0,   10,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8135 //      Printf("integral: %f", ((TH2*) hist1)->Integral(1, 36, 5, 36));
8136 //      return;
8137
8138         GetDistAndFlow(h, hMixed, &hist5,  0, step, 10,  20, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8139         GetDistAndFlow(h, hMixed, &hist4,  0, step, 20,  30, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8140         GetDistAndFlow(h, hMixed, &hist6,  0, step, 30,  50, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8141         GetDistAndFlow(h, hMixed, &hist2,  0, step, 50,  80, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs);
8142 //      step = 6;
8143         if (h2)
8144           GetDistAndFlow(h2, hMixed2, &hist3,  0, step, 0, -1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs);
8145 //      new TCanvas; hist3->DrawClone("SURF1");
8146 //      GetDistAndFlow(hMixed2, 0, &hist3,  0, step, 0, -1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs);
8147 //      new TCanvas; hist3->DrawClone("SURF1");
8148 //      Printf("integral: %f", ((TH2*) hist3)->Integral(1, 36, 5, 36));
8149 //      return;
8150         
8151         //MC closure test in pA and PbPb with PID
8152         // GetDistAndFlow(h, hMixed, &hist1,  0, step,  0,   20,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8153         // GetDistAndFlow(h, hMixed, &hist2,  0, step, 20,  40,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8154         // GetDistAndFlow(h, hMixed, &hist4,  0, step, 40,  60,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8155         // GetDistAndFlow(h, hMixed, &hist5,  0, step, 60, 100,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8156         // GetDistAndFlow(h, hMixed, &hist7,  0, step, 80, 100,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8157         // GetDistAndFlow(h, hMixed, &hist8,  0, step,  0,  100,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs); 
8158       }
8159       else if (0)
8160       {
8161         Int_t step = 8;
8162  
8163         GetSumOfRatios(h, hMixed, &hist1,  step, 60,  70, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8164         GetSumOfRatios(h, hMixed, &hist2,  step, 70,  80, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8165         GetSumOfRatios(h, hMixed, &hist3,  step, 80,  90, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8166       }
8167       else if (1)
8168       {
8169         Int_t step = 8;
8170  
8171         GetSumOfRatios(h, hMixed, &hist1,  step, 0,  1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8172         GetSumOfRatios(h, hMixed, &hist2,  step, 1,  3, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8173         GetSumOfRatios(h, hMixed, &hist4,  step, 3,  5, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8174         GetSumOfRatios(h, hMixed, &hist5,  step, 5,  10, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8175         GetSumOfRatios(h, hMixed, &hist6,  step, 10,  20, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kTRUE); 
8176       }
8177
8178       file = TFile::Open(outputFile, "UPDATE");
8179       
8180       if (hist1)
8181       {
8182         hist1->SetName(Form("dphi_%d_%d_%d", i, j, 0));
8183         hist1->Write();
8184       }
8185       
8186       if (hist2)
8187       {
8188         hist2->SetName(Form("dphi_%d_%d_%d", i, j, 1));
8189         hist2->Write();
8190       }
8191       
8192       if (hist4)
8193       {
8194         hist4->SetName(Form("dphi_%d_%d_%d", i, j, 3));
8195         hist4->Write();
8196       }
8197
8198       if (hist5)
8199       {
8200         hist5->SetName(Form("dphi_%d_%d_%d", i, j, 4));
8201         hist5->Write();
8202       }
8203       
8204       if (hist7)
8205       {
8206         hist7->SetName(Form("dphi_%d_%d_%d", i, j, 6));
8207         hist7->Write();
8208       }
8209
8210       if (hist8)
8211       {
8212         hist8->SetName(Form("dphi_%d_%d_%d", i, j, 7));
8213         hist8->Write();
8214       }
8215
8216       if (hist6)
8217       {
8218         hist6->SetName(Form("dphi_%d_%d_%d", i, j, 5));
8219         TString title(hist6->GetTitle());
8220         title.ReplaceAll("0--1%", "pp");
8221         hist6->SetTitle(title);
8222         hist6->Write();
8223       }
8224       
8225       if (hist3)
8226       {
8227         hist3->SetName(Form("dphi_%d_%d_%d", i, j, 2));
8228         TString title(hist3->GetTitle());
8229         title.ReplaceAll("0--1%", "pp");
8230         hist3->SetTitle(title);
8231         hist3->Write();
8232       }
8233       
8234       file->Close();
8235
8236       delete hist1;
8237       delete hist2;
8238       delete hist3;
8239       delete hist4;
8240       delete hist5;
8241       delete hist6;
8242       delete hist7;
8243       delete hist8;      
8244       
8245 //       return;
8246     }
8247     
8248     TH1* triggers = h->GetUEHist(2)->GetTriggersAsFunctionOfMultiplicity(step, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01);
8249     triggers->SetName(Form("triggers_%d", i));
8250     TString str;
8251     str.Form("%.1f < p_{T,trig} < %.1f", leadingPtArr[i], leadingPtArr[i+leadingPtOffset]);
8252     triggers->SetTitle(str);
8253
8254     file = TFile::Open(outputFile, "UPDATE");
8255     triggers->Write();
8256     file->Close();    
8257   }
8258     
8259   delete h;
8260   delete hMixed;
8261 }
8262
8263 Int_t gMCBinning = -1;
8264 void ExtractNSPeakShapesMC(const char* fileNamePbPb, const char* fileNamepp = 0, const char* outputFile = "dphi_corr.root")
8265 {
8266   loadlibs();
8267   
8268   file = TFile::Open(outputFile, "RECREATE");
8269   file->Close();
8270   
8271   Int_t leadingPtOffset = 1;
8272     
8273   Int_t maxLeadingPt = 4;
8274   Int_t maxAssocPt = 6;
8275
8276   //PbPb, NS peak shapes
8277   Float_t leadingPtArr[] = { 1.0, 2.0, 3.0, 4.0, 8.0, 15.0, 20.0 };
8278   Float_t assocPtArr[] =     { 0.15, 0.5, 1.0, 2.0, 3.0, 4.0, 8.0, 10.0, 12.0 };
8279   
8280   TList* list = 0;
8281   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileNamePbPb, &list);
8282   hMixed = (AliUEHistograms*) GetUEHistogram(fileNamePbPb, 0, kTRUE);
8283   
8284   TList* list2 = 0;
8285   AliUEHistograms* h2 = 0;
8286   AliUEHistograms* hMixed2 = 0;
8287   if (fileNamepp)
8288   {
8289     h2 = (AliUEHistograms*) GetUEHistogram(fileNamepp, &list2);
8290     hMixed2 = (AliUEHistograms*) GetUEHistogram(fileNamepp, 0, kTRUE);
8291   }
8292
8293   for (Int_t i=0; i<maxLeadingPt; i++)
8294   {
8295     for (Int_t j=2; j<maxAssocPt; j++)
8296     {
8297       gpTMin = assocPtArr[j] + 0.01;
8298       gpTMax = assocPtArr[j+1] - 0.01;
8299       
8300       if(gpTMin >= gpTMax)continue;
8301         
8302       SetupRanges(h);
8303       SetupRanges(hMixed);
8304       SetupRanges(h2);
8305       SetupRanges(hMixed2);
8306
8307       if(1) if (assocPtArr[j] >= leadingPtArr[i+leadingPtOffset])
8308         continue;
8309   
8310       TH1* hist1 = 0;
8311       TH1* hist2 = 0;
8312       TH1* hist3 = 0;
8313       TH1* hist4 = 0;
8314       TH1* hist5 = 0;
8315       TH1* hist6 = 0;
8316       
8317       Bool_t equivMixedBin = 1;
8318       Bool_t scaleToPairs = kTRUE;
8319       Int_t histType = 1;
8320
8321       if (gMCBinning == 1) // HIJING
8322       {
8323         // PbPb, MC, impact parameter binning
8324         Int_t step = 0;
8325         
8326         GetDistAndFlow(h, hMixed, &hist1,  0, step, 1,   6,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs, -1, kTRUE); 
8327         GetDistAndFlow(h, hMixed, &hist5,  0, step, 7,  7, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs, -1, kTRUE); 
8328         GetDistAndFlow(h, hMixed, &hist4,  0, step, 8,  8, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs, -1, kTRUE); 
8329         GetDistAndFlow(h, hMixed, &hist6,  0, step, 9,  10, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs, -1, kTRUE); 
8330         GetDistAndFlow(h, hMixed, &hist2,  0, step, 11,  13, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs, -1, kTRUE);
8331
8332         if (h2)
8333           GetDistAndFlow(h2, hMixed2, &hist3,  0, step, 0, -1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs);
8334       }
8335       else if (gMCBinning == 2) // AMPT
8336       {
8337         // PbPb, MC, impact parameter binning
8338         Int_t step = 0;
8339         
8340         GetDistAndFlow(h, hMixed, &hist1,  0, step, 1,   2,  leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs, -1, kTRUE); 
8341         GetDistAndFlow(h, hMixed, &hist5,  0, step, 3,  3, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs, -1, kTRUE); 
8342         GetDistAndFlow(h, hMixed, &hist4,  0, step, 4,  4, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs, -1, kTRUE); 
8343         GetDistAndFlow(h, hMixed, &hist6,  0, step, 5,  6, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs, -1, kTRUE); 
8344         GetDistAndFlow(h, hMixed, &hist2,  0, step, 7,  9, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs, -1, kTRUE);
8345
8346         if (h2)
8347           GetDistAndFlow(h2, hMixed2, &hist3,  0, step, 0, -1, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, histType, equivMixedBin, 0, scaleToPairs);
8348       }
8349       
8350       file = TFile::Open(outputFile, "UPDATE");
8351       
8352       if (hist1)
8353       {
8354         hist1->SetName(Form("dphi_%d_%d_%d", i, j, 0));
8355         hist1->Write();
8356       }
8357       
8358       if (hist2)
8359       {
8360         hist2->SetName(Form("dphi_%d_%d_%d", i, j, 1));
8361         hist2->Write();
8362       }
8363       
8364       if (hist4)
8365       {
8366         hist4->SetName(Form("dphi_%d_%d_%d", i, j, 3));
8367         hist4->Write();
8368       }
8369
8370       if (hist5)
8371       {
8372         hist5->SetName(Form("dphi_%d_%d_%d", i, j, 4));
8373         hist5->Write();
8374       }
8375       
8376       if (hist6)
8377       {
8378         hist6->SetName(Form("dphi_%d_%d_%d", i, j, 5));
8379         hist6->Write();
8380       }
8381       
8382       if (hist3)
8383       {
8384         hist3->SetName(Form("dphi_%d_%d_%d", i, j, 2));
8385         TString title(hist3->GetTitle());
8386         title.ReplaceAll("0--1%", "pp");
8387         hist3->SetTitle(title);
8388         hist3->Write();
8389       }
8390       
8391       file->Close();
8392
8393       delete hist1;
8394       delete hist2;
8395       delete hist3;
8396       delete hist4;
8397       delete hist5;
8398       delete hist6;
8399     }
8400   }
8401     
8402   delete h;
8403   delete hMixed;
8404 }
8405
8406 void MergeDPhiFiles(const char* fileName, const char* fileName2, const char* target)
8407 {
8408   // merges the dphi histograms (except the pp histogram at index "2") as well as the triggers
8409   // then divides the dphi histograms by the respective number of triggers
8410  
8411   file = TFile::Open(fileName);
8412   file2 = TFile::Open(fileName2);
8413
8414   fileTarget = TFile::Open(target, "RECREATE");
8415   fileTarget->Close();
8416   
8417   Int_t maxLeadingPt = 10;
8418   Int_t maxAssocPt = 11;
8419
8420   Int_t nHists = 8;
8421   for (Int_t i=0; i<maxLeadingPt; i++)
8422   {
8423     TH1* triggers = (TH1*) file->Get(Form("triggers_%d", i));
8424     if (!triggers)
8425       continue;
8426     
8427     TH1* triggers2 = (TH1*) ((file2) ? file2->Get(Form("triggers_%d", i)) : 0);
8428     if (!triggers2)
8429       Printf("WARNING: trigger %d missing", i);
8430     
8431     for (Int_t j=0; j<maxAssocPt; j++)
8432     {
8433       for (Int_t histId = 0; histId < nHists; histId++)
8434       {
8435         TH2* hist = (TH2*) file->Get(Form("dphi_%d_%d_%d", i, j, histId));
8436         if (!hist)
8437         {
8438           TH2* hist2 = (TH2*) ((file2) ? file2->Get(Form("dphi_%d_%d_%d", i, j, histId)) : 0);
8439           if (hist2)
8440             Printf("WARNING: %d %d %d exists only in file2, not copied!");
8441           continue;
8442         }
8443         
8444         if (histId != 2) // don't merge pp
8445         {
8446           TString title(hist->GetTitle());
8447           title.ReplaceAll("%", "");
8448           tokens = title.Tokenize("-");
8449           
8450           Float_t centralityBegin = ((TObjString*) tokens->At(2))->String().Atoi();
8451           Float_t centralityEnd = ((TObjString*) tokens->At(3))->String().Atoi();
8452           
8453           Double_t nTriggers = triggers->Integral(triggers->FindBin(centralityBegin + 0.001), triggers->FindBin(centralityEnd - 0.001));
8454           Double_t nTriggers2 = 0;
8455
8456           TH2* hist2 = (TH2*) ((file2) ? file2->Get(Form("dphi_%d_%d_%d", i, j, histId)) : 0);
8457           if (hist2 && triggers2) 
8458           {
8459             if (histId != 1 && histId != 5) // don't merge 60-80% and 40-60%
8460             {
8461               hist->Add(hist2);
8462               nTriggers2 = triggers2->Integral(triggers2->FindBin(centralityBegin + 0.001), triggers2->FindBin(centralityEnd - 0.001));
8463             }
8464           }
8465           else
8466             Printf("WARNING: %d %d %d missing", i, j, histId);
8467             
8468           if (nTriggers + nTriggers2 > 0)
8469             hist->Scale(1.0 / (nTriggers + nTriggers2));
8470
8471           Printf("%s %f %f %f %f", hist->GetTitle(), centralityBegin, centralityEnd, nTriggers, nTriggers2);
8472         }
8473
8474         fileTarget = TFile::Open(target, "UPDATE");
8475         hist->Write();
8476         fileTarget->Close();
8477       }
8478     }
8479   }
8480 }
8481
8482 void ExtractMiniJetHistograms(const char* fileNamePbPb, Bool_t useMixed = kTRUE, const char* outputFile = "dphi_corr.root")
8483 {
8484   loadlibs();
8485   
8486   file = TFile::Open(outputFile, "RECREATE");
8487   file->Close();
8488   
8489   Int_t leadingPtOffset = 1;
8490     
8491   if (1)
8492   { 
8493     // minijets
8494     Int_t maxLeadingPt = 1;
8495     Int_t maxAssocPt = 1;
8496     Float_t leadingPtArr[] = { 0.7, 5.0 };
8497     Float_t assocPtArr[] =   { 0.7, 5.0 };
8498   }
8499   
8500   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileNamePbPb);
8501   hMixed = (AliUEHistograms*) GetUEHistogram(fileNamePbPb, 0, kTRUE);
8502   
8503   Int_t step = 8;
8504
8505   for (Int_t i=0; i<maxLeadingPt; i++)
8506   {
8507     for (Int_t j=0; j<maxAssocPt; j++)
8508     {
8509 //       i = 3; j = 6;
8510       
8511       gpTMin = assocPtArr[j] + 0.01;
8512       gpTMax = assocPtArr[j+1] - 0.01;
8513       
8514       SetupRanges(h);
8515       SetupRanges(hMixed);
8516
8517       if (assocPtArr[j] >= leadingPtArr[i+leadingPtOffset])
8518         continue;
8519   
8520       if (1)
8521       {
8522         // pA, minijets, very fine binning
8523         
8524         for (Int_t centr=0; centr<20; centr++)
8525         {
8526           TH1* hist1 = 0;
8527           if (useMixed)
8528             GetSumOfRatios(h, hMixed, &hist1, step, 5*centr, 5*centr+5, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, kFALSE); 
8529           else
8530             GetDistAndFlow(h, 0, &hist1, 0, step, 5*centr, 5*centr+5, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, 1, 1, 0, kTRUE); 
8531           
8532           if (!hist1)
8533             continue;
8534
8535           file = TFile::Open(outputFile, "UPDATE");
8536           hist1->SetName(Form("dphi_%d_%d_%d", i, j, centr));
8537           hist1->Write();
8538           file->Close();
8539           
8540           delete hist1;
8541         }
8542       }
8543     }
8544     
8545     TH1* triggers = h->GetUEHist(2)->GetTriggersAsFunctionOfMultiplicity(step, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01);
8546     triggers->SetName(Form("triggers_%d", i));
8547     TString str;
8548     str.Form("%.1f < p_{T,trig} < %.1f", leadingPtArr[i], leadingPtArr[i+leadingPtOffset]);
8549     triggers->SetTitle(str);
8550
8551     file = TFile::Open(outputFile, "UPDATE");
8552     triggers->Write();
8553     file->Close();
8554   }
8555   
8556   TH1* events = h->GetEventCount()->ProjectionY("events", h->GetEventCount()->GetXaxis()->FindBin(step), h->GetEventCount()->GetXaxis()->FindBin(step));
8557   file = TFile::Open(outputFile, "UPDATE");
8558   events->Write("events");
8559   file->Close();
8560 }
8561
8562 TLatex* DrawLatex(Float_t x, Float_t y, Int_t color, const char* text, Float_t fontSize = 0.06)
8563 {
8564   latex = new TLatex(x, y, text);
8565   latex->SetNDC();
8566   latex->SetTextSize(fontSize);
8567   latex->SetTextColor(color);
8568   latex->Draw();
8569   return latex;
8570 }
8571
8572 void DrawChi2NDF(TF1* func, TH1* hist, Float_t x, Float_t y, Int_t color = 1)
8573 {
8574   Float_t chi2 = 0;
8575   Int_t ndf = 0;
8576   for (Int_t i=hist->GetXaxis()->FindBin(-0.8); i<=hist->GetXaxis()->FindBin(0.8); i++)
8577   {
8578     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);
8579     ndf++;
8580   }
8581   ndf -= func->GetNumberFreeParameters();
8582   
8583   printf("#chi^{2}/ndf = %.1f/%d = %.1f  ", func->GetChisquare(), func->GetNDF(), func->GetChisquare() / func->GetNDF());
8584   Printf("#chi^{2}/ndf = %.1f/%d = %.1f", chi2, ndf, chi2 / ndf);
8585
8586   DrawLatex(x, y, color, Form("#chi^{2}/ndf = %.1f/%d = %.1f", func->GetChisquare(), func->GetNDF(), func->GetChisquare() / func->GetNDF()));
8587   DrawLatex(x, y - 0.05, color, Form("#chi^{2}/ndf = %.1f/%d = %.1f", chi2, ndf, chi2 / ndf));
8588 }   
8589    
8590 void FitDeltaPhiEtaGap(TH1* hist, Int_t color, TGraphErrors* graph, Float_t x, Float_t yPosChi2)
8591 {
8592   hist->SetLineColor(color);
8593   hist->DrawCopy("SAME");
8594
8595   Bool_t twoGauss = kFALSE;
8596   
8597   if (!twoGauss)
8598     func = new TF1("func", "[0]+gaus(1)");
8599   else
8600   {
8601     func = new TF1("func", "[0]+gaus(1)+gaus(4)");
8602     func->FixParameter(5, 0);
8603     func->SetParLimits(3, 0.1, 10);
8604     func->SetParLimits(6, 0.1, 10);
8605     func->SetParLimits(1, 0, 10);
8606     func->SetParLimits(4, 0, 10);
8607   }
8608   
8609   func->SetParameters(0, 1, 0, 0.3, 1, 0, 1);
8610   func->FixParameter(2, 0);
8611   func->SetLineColor(color);
8612
8613   hist->Fit(func, "", "SAME");
8614 //   hist->Fit(func, "IM", "SAME");
8615   
8616   if (twoGauss)
8617   {
8618     func2 = new TF1("func2", "[0]+gaus(1)", -1.5, 4.5);
8619     func2->SetParameters(func->GetParameter(0), func->GetParameter(1), func->GetParameter(2), func->GetParameter(3));
8620     func2->SetLineColor(color);
8621     func2->SetLineWidth(1);
8622     func2->SetLineStyle(2);
8623     func2->Draw("SAME");
8624     
8625     func2 = new TF1("func2", "[0]+gaus(1)", -1.5, 4.5);
8626     func2->SetParameters(func->GetParameter(0), func->GetParameter(4), func->GetParameter(5), func->GetParameter(6));
8627     func2->SetLineColor(color);
8628     func2->SetLineWidth(1);
8629     func2->SetLineStyle(2);
8630     func2->Draw("SAME");
8631   }
8632       
8633   if (twoGauss)
8634   {
8635     Bool_t firstIsMin = func->GetParameter(3) < func->GetParameter(6);
8636     
8637     Bool_t onlyOne = kFALSE;
8638     if (func->GetParameter(1) / func->GetParameter(4) < 0.1)
8639     {
8640       firstIsMin = kFALSE;
8641       onlyOne = kTRUE;
8642     }
8643     if (func->GetParameter(1) / func->GetParameter(4) > 10)
8644     {
8645       firstIsMin = kTRUE;
8646       onlyOne = kTRUE;
8647     }
8648     
8649     graph->SetPoint(graph->GetN(), x - 0.1, func->GetParameter((firstIsMin) ? 3 : 6));
8650     graph->SetPointError(graph->GetN()-1, 0, func->GetParError((firstIsMin) ? 3 : 6));
8651
8652     if (!onlyOne)
8653     {
8654       graph->SetPoint(graph->GetN(), x + 0.1, TMath::Abs(func->GetParameter((!firstIsMin) ? 3 : 6)));
8655       graph->SetPointError(graph->GetN()-1, 0, func->GetParError((!firstIsMin) ? 3 : 6));
8656     }
8657   }
8658   else
8659   {
8660     graph->SetPoint(graph->GetN(), x, TMath::Abs(func->GetParameter(3)));
8661     graph->SetPointError(graph->GetN()-1, 0, func->GetParError(3));
8662   }  
8663     
8664   DrawChi2NDF(func, hist, 0.5, yPosChi2, color);
8665 }
8666
8667 void AnalyzeDeltaPhiEtaGap(const char* fileName)
8668 {
8669   TFile::Open(fileName);
8670   
8671   Int_t maxLeadingPt = 5;
8672   Int_t maxAssocPt = 6;
8673
8674   TCanvas* canvas = new TCanvas("DeltaPhi", "DeltaPhi", 1000, 700);
8675   canvas->Divide(maxAssocPt, maxLeadingPt);
8676       
8677   TGraphErrors* width1 = new TGraphErrors;
8678   TGraphErrors* width2 = new TGraphErrors;
8679   TGraphErrors* width3 = new TGraphErrors;
8680   
8681   for (Int_t i=0; i<maxLeadingPt; i++)
8682     for (Int_t j=0; j<maxAssocPt; j++)
8683     {
8684       canvas->cd(j+1 + i * maxAssocPt);
8685       gPad->SetLeftMargin(0.15);
8686       gPad->SetBottomMargin(0.2);
8687       gPad->SetTopMargin(0.01);
8688       gPad->SetRightMargin(0.01);
8689       
8690       hist1 = (TH1*) gFile->Get(Form("dphi_%d_%d_%d", i, j, 0));
8691       hist2 = (TH1*) gFile->Get(Form("dphi_%d_%d_%d", i, j, 1));
8692       hist3 = (TH1*) gFile->Get(Form("dphi_%d_%d_%d", i, j, 2));
8693       
8694       if (!hist1)
8695         continue;
8696
8697       TString tmpStr(hist1->GetTitle());
8698       tmpStr.ReplaceAll(" - ", "#");
8699       tokens = tmpStr.Tokenize("#");
8700       TString str(tokens->At(0)->GetName());
8701       TString str2(tokens->At(1)->GetName());
8702       
8703       Prepare1DPlot(hist1);
8704       Prepare1DPlot(hist2);
8705       Prepare1DPlot(hist3);
8706
8707       // remove baseline
8708       hist1->Fit("pol0", "0", "", 1, 4);
8709       if (!hist1->GetFunction("pol0"))
8710         continue;
8711       hist1->GetFunction("pol0")->SetRange(-10, 10);
8712       hist1->Add(hist1->GetFunction("pol0"), -1);
8713       
8714       hist3->Fit("pol0", "0", "", 1, 4);
8715       hist3->GetFunction("pol0")->SetRange(-10, 10);
8716       hist3->Add(hist3->GetFunction("pol0"), -1);
8717       
8718       Double_t yMin = 0.01;
8719       Double_t yMax = -1;
8720       
8721       if (yMax < 0)
8722       {
8723         yMin = TMath::Min(hist1->GetMinimum(), hist2->GetMinimum()) * 0.97;
8724         yMax = TMath::Max(hist1->GetMaximum(), (hist2) ? hist2->GetMaximum() : 0.0) * 1.1;
8725       }
8726       
8727 //       yMin = hist1->GetMinimum() * 0.9;
8728       yMax *= 1.5;
8729     
8730       TH2F* dummy = new TH2F("dummy", "", 100, hist1->GetXaxis()->GetBinLowEdge(1), hist1->GetXaxis()->GetBinUpEdge(hist1->GetNbinsX()), 1000, yMin, yMax);
8731       dummy->SetStats(kFALSE);
8732       dummy->SetXTitle(hist1->GetXaxis()->GetTitle());
8733       dummy->SetYTitle(hist1->GetYaxis()->GetTitle());
8734       dummy->SetYTitle("1/N_{trig} dN/d#Delta#phi"); 
8735       Prepare1DPlot(dummy);
8736       
8737       dummy->GetYaxis()->SetTitleOffset(0.8);
8738     
8739       dummy->GetXaxis()->SetLabelSize(0.08);
8740       dummy->GetYaxis()->SetLabelSize(0.08);
8741       dummy->GetXaxis()->SetTitleSize(0.08);
8742       dummy->GetYaxis()->SetTitleSize(0.08);
8743       /*
8744       dummy->GetYaxis()->SetTitleOffset(0.8);
8745       */
8746       
8747       dummyTmp = dummy->DrawCopy();
8748       
8749       // TODO plot yield? baseline problematic?
8750
8751       Float_t xPos = width1->GetN();
8752       xPos = j*7+i;
8753
8754       FitDeltaPhiEtaGap(hist1, 1, width1, xPos, 0.7);
8755       FitDeltaPhiEtaGap(hist2, 4, width2, xPos, 0.5);
8756       FitDeltaPhiEtaGap(hist3, 2, width3, xPos, 0.6);
8757       
8758       latex = new TLatex(0.3, 0.8, str);
8759       latex->SetNDC();
8760       latex->SetTextSize(0.06);
8761       latex->Draw();
8762       
8763       latex = new TLatex(0.3, 0.88, str2);
8764       latex->SetNDC();
8765       latex->SetTextSize(0.06);
8766       latex->Draw();
8767       
8768       DrawLatex(0.8, 0.9,  1, "0-5%");
8769       DrawLatex(0.8, 0.85, 2, "60-90%");
8770       DrawLatex(0.8, 0.8,  4, "pp");
8771
8772 //       return;
8773 //       i = 10; j = 10;
8774     }
8775     
8776   new TCanvas;
8777   width1->SetMarkerStyle(20);
8778   width1->Draw("AP");
8779
8780   width2->SetMarkerStyle(24);
8781   width2->SetMarkerColor(4);
8782   width2->Draw("P SAME");
8783
8784   width3->SetMarkerStyle(25);
8785   width3->SetMarkerColor(2);
8786   width3->Draw("P SAME");
8787 }
8788
8789 void CheckWing(const char* fileName)
8790 {
8791   TFile::Open(fileName);
8792   
8793   Int_t maxLeadingPt = 4;
8794   Int_t maxAssocPt = 5;
8795
8796   TCanvas* canvas = new TCanvas("DeltaPhi", "DeltaPhi", 1000, 700);
8797   canvas->Divide(maxAssocPt-1, maxLeadingPt);
8798       
8799   for (Int_t i=0; i<maxLeadingPt; i++)
8800     for (Int_t j=1; j<maxAssocPt; j++)
8801     {
8802       canvas->cd(j + i * (maxAssocPt - 1));
8803       gPad->SetLeftMargin(0.15);
8804       gPad->SetBottomMargin(0.2);
8805 //       gPad->SetTopMargin(0.01);
8806       gPad->SetRightMargin(0.01);
8807       
8808       hist1 = (TH1*) gFile->Get(Form("dphi_%d_%d_%d", i, j+1, 0));
8809       
8810       if (!hist1)
8811         continue;
8812       
8813 //       hist1->Draw("COLZ");
8814
8815       Float_t width = 0.25;
8816
8817       proj = ((TH2*) hist1)->ProjectionY(Form("%s_projx", hist1->GetName()), hist1->GetXaxis()->FindBin(TMath::Pi() - width),hist1->GetXaxis()->FindBin(TMath::Pi() + width));
8818       
8819       proj->GetXaxis()->SetRangeUser(-1.79, 1.79);
8820       proj->SetStats(kFALSE);
8821       proj->Draw();
8822
8823       proj2 = ((TH2*) hist1)->ProjectionY(Form("%s_proj2x", hist1->GetName()), hist1->GetXaxis()->FindBin(TMath::Pi() / 2 - width),hist1->GetXaxis()->FindBin(TMath::Pi() / 2 + width));
8824
8825       proj2->GetXaxis()->SetRangeUser(-1.79, 1.79);
8826       proj2->SetLineColor(2);
8827       proj2->Draw("SAME");
8828       
8829       proj->SetMinimum(0.999 * proj2->GetMinimum());
8830     }
8831 }
8832
8833 void CheckWing()
8834 {
8835   Int_t maxLeadingPt = 3;
8836   Int_t maxAssocPt = 3;
8837
8838   TCanvas* canvas = new TCanvas("DeltaPhi", "DeltaPhi", 1000, 700);
8839   canvas->Divide(maxAssocPt, maxLeadingPt);
8840
8841 //   const char* fileNames[] = { "dphi_corr_allpt_zcentral_01.root", "dphi_corr_allpt_01.root" };
8842 //   const char* fileNames[] = { "dphi_corr_allpt_zcentral.root", "dphi_corr_allpt.root" };
8843 //   const char* fileNames[] = { "dphi_corr_allpt_zcentral.root", "dphi_corr.root" };
8844 //   const char* fileNames[] = { "dphi_corr_allpt_01_zcentral.root", "dphi_corr_allpt_01_zsumofratios.root" };
8845 //   const char* fileNames[] = { "dphi_corr_allpt_cfct_01_zcentral.root", "dphi_corr_allpt_cfct_01_zsumofratios.root" };
8846 //   const char* fileNames[] = { "dphi_corr_2d.root", "dphi_corr.root" };
8847 //   const char* fileNames[] = { "dphi_corr_2d_01.root", "dphi_corr.root" };
8848 //   const char* fileNames[] = { "dphi_corr_2d.root", "dphi_corr_2d_vtxzcentral.root" };
8849 //   const char* fileNames[] = { "dphi_corr_2d_01.root", , "dphi_corr_2d_01centr_zvtxcentral.root" }; 
8850 //   const char* fileNames[] = { "dphi_corr_10k.root", "dphi_corr_50k.root" }; 
8851 //   const char* fileNames[] = { "wing1.root", "wing2.root" }; 
8852   const char* fileNames[] = { "dphi_corr_2d_120112.root", "dphi_corr_2d_p2_111105.root" }; 
8853   
8854   for (Int_t i=0; i<maxLeadingPt; i++)
8855     for (Int_t j=0; j<maxAssocPt; j++)
8856     {
8857       canvas->cd(j+1 + i * maxAssocPt);
8858       gPad->SetLeftMargin(0.15);
8859       gPad->SetBottomMargin(0.2);
8860 //       gPad->SetTopMargin(0.01);
8861       gPad->SetRightMargin(0.01);
8862
8863       TH1* first = 0;
8864       for (Int_t fileId = 0; fileId < 2; fileId++)
8865       {
8866         TFile::Open(fileNames[fileId]);
8867   
8868         hist1 = (TH1*) gFile->Get(Form("dphi_%d_%d_%d", i, j, 3));
8869         
8870         if (!hist1)
8871           continue;
8872         
8873   //       hist1->Draw("COLZ");
8874
8875         Float_t width = 0.5;
8876         
8877         for (Int_t areaId = 0; areaId < 3; areaId++)
8878         {
8879           Float_t center = TMath::Pi() / 2 * areaId;
8880           proj = ((TH2*) hist1)->ProjectionY(Form("%s_%d_%d_projx", hist1->GetName(), fileId, areaId), hist1->GetXaxis()->FindBin(center - width), hist1->GetXaxis()->FindBin(center + width));
8881   //    proj->Rebin(2); proj->Scale(0.5);
8882           
8883           proj->GetXaxis()->SetRangeUser(-1.79, 1.79);
8884           proj->SetStats(kFALSE);
8885           proj->SetLineColor(fileId + 1 + areaId * 2);
8886           proj->Draw((fileId == 0 && areaId == 0) ? "" : "SAME");
8887           if (!first)
8888             first = proj;
8889           
8890           proj->Scale(1. / 12);
8891           
8892           first->SetMinimum(0.999 * TMath::Min(first->GetMinimum() / 0.999, proj->GetMinimum()));
8893           first->SetMaximum(1.001 * TMath::Max(first->GetMaximum() / 1.001, proj->GetMaximum()));
8894         }
8895       }
8896   }
8897 }
8898 /*
8899 void FitDeltaPhiEtaGap2D(TH2* hist, Bool_t scale, TVirtualPad* pad1, TVirtualPad* pad2, TVirtualPad* pad3, TGraphErrors* width1, TGraphErrors* width2, Float_t x, Float_t yPosChi2)
8900 {
8901   Float_t etaLimit = 1.0;
8902   Float_t outerLimit = 1.8;
8903   
8904   TString histName(hist->GetName());
8905
8906   TH1D* etaGap = hist->ProjectionX(histName + "_1", TMath::Max(1, hist->GetYaxis()->FindBin(-outerLimit + 0.01)), hist->GetYaxis()->FindBin(-etaLimit - 0.01));
8907   Int_t etaBins = hist->GetYaxis()->FindBin(-etaLimit - 0.01) - TMath::Max(1, hist->GetYaxis()->FindBin(-outerLimit + 0.01)) + 1;
8908
8909   TH1D* tracksTmp = hist->ProjectionX(histName + "_2", hist->GetYaxis()->FindBin(etaLimit + 0.01), TMath::Min(hist->GetYaxis()->GetNbins(), hist->GetYaxis()->FindBin(outerLimit - 0.01)));
8910   etaBins += TMath::Min(hist->GetYaxis()->GetNbins(), hist->GetYaxis()->FindBin(outerLimit - 0.01)) - hist->GetYaxis()->FindBin(etaLimit + 0.01) + 1;
8911   
8912   etaGap->Add(tracksTmp);
8913
8914   // get per bin result
8915   etaGap->Scale(1.0 / etaBins);
8916   
8917 //   new TCanvas; etaGap->DrawCopy();
8918   
8919   histTmp2D = (TH2*) hist->Clone("histTmp2D");
8920   histTmp2D->Reset();
8921   
8922   for (Int_t xbin=1; xbin<=histTmp2D->GetNbinsX(); xbin++)
8923     for (Int_t y=1; y<=histTmp2D->GetNbinsY(); y++)
8924       histTmp2D->SetBinContent(xbin, y, etaGap->GetBinContent(xbin));
8925     
8926   if (scale)
8927   {
8928     // mixed event does not reproduce away-side perfectly
8929     // --> extract scaling factor on the away-side from ratios of eta gap and central region
8930     TH1D* centralRegion = hist->ProjectionX(histName + "_3", hist->GetYaxis()->FindBin(-etaLimit + 0.01), hist->GetYaxis()->FindBin(etaLimit - 0.01));
8931     etaBins = hist->GetYaxis()->FindBin(etaLimit - 0.01) - hist->GetYaxis()->FindBin(-etaLimit + 0.01) + 1;
8932     centralRegion->Scale(1.0 / etaBins);
8933     
8934 //     new TCanvas; centralRegion->DrawCopy(); etaGap->SetLineColor(2); etaGap->DrawCopy("SAME");
8935     centralRegion->Divide(etaGap);
8936 //     new TCanvas; centralRegion->Draw();
8937     centralRegion->Fit("pol0", "0", "", TMath::Pi() - 1, TMath::Pi() + 1);
8938     Float_t scalingFactor = centralRegion->GetFunction("pol0")->GetParameter(0);
8939     Printf("  scalingFactor = %f", scalingFactor);
8940     histTmp2D->Scale(scalingFactor);
8941   }
8942     
8943 //   new TCanvas; hist->DrawCopy("SURF1");
8944
8945   hist->Add(histTmp2D, -1);
8946
8947 //   new TCanvas; hist->DrawCopy("SURF1");
8948
8949   hist->GetYaxis()->SetRangeUser(-1.59, 1.59);
8950   
8951   pad1->cd();
8952   hist->SetStats(0);
8953   hist->DrawCopy("SURF1");
8954   
8955   Float_t min = hist->GetMinimum();
8956   Float_t max = hist->GetMaximum();
8957   
8958   // ranges are to exclude eta gap region from fit
8959   func = new TF2("func", "[0]+[1]*exp(-0.5*((x/[2])**2+(y/[3])**2))", -5, 5, -1, 1);
8960   func->SetParameters(0, 1, 0.3, 0.3);
8961   func->SetParLimits(1, 0, 10);
8962   func->SetParLimits(2, 0.1, 10);
8963   func->SetParLimits(3, 0.1, 10);
8964   
8965   hist->Fit(func, "0R", "");
8966 //   hist->Fit(func, "IM", "SAME");
8967
8968   pad2->cd();
8969   funcHist = (TH2*) hist->Clone("funcHist");
8970   funcHist->Reset();
8971   funcHist->Add(func);
8972   funcHist->SetMinimum(min);
8973   funcHist->SetMaximum(max);
8974   funcHist->Draw("SURF1");
8975   
8976   pad3->cd();
8977   hist->Add(func, -1);
8978   hist->SetMinimum(min);
8979   hist->SetMaximum(max);
8980   hist->DrawCopy("SURF1");
8981   
8982   width1->SetPoint(width1->GetN(), x, TMath::Abs(func->GetParameter(2)));
8983   width1->SetPointError(width1->GetN()-1, 0, func->GetParError(2));
8984     
8985   width2->SetPoint(width2->GetN(), x, TMath::Abs(func->GetParameter(3)));
8986   width2->SetPointError(width2->GetN()-1, 0, func->GetParError(3));
8987
8988   Float_t chi2 = 0;
8989   Int_t ndf = 0;
8990   for (Int_t i=hist->GetXaxis()->FindBin(-0.8); i<=hist->GetXaxis()->FindBin(0.8); i++)
8991     for (Int_t j=hist->GetYaxis()->FindBin(-0.8); j<=hist->GetYaxis()->FindBin(0.8); j++)
8992     {
8993       if (hist->GetBinError(i, j) > 0)
8994       {
8995         chi2 += TMath::Power(hist->GetBinContent(i, j) / hist->GetBinError(i, j), 2);
8996         ndf++;
8997       }
8998     }
8999   ndf -= func->GetNumberFreeParameters();
9000   
9001   printf("#chi^{2}/ndf = %.1f/%d = %.1f  ", func->GetChisquare(), func->GetNDF(), func->GetChisquare() / func->GetNDF());
9002   Printf("#chi^{2}/ndf = %.1f/%d = %.1f", chi2, ndf, chi2 / ndf);
9003
9004   DrawLatex(0.5, yPosChi2, 1, Form("#chi^{2}/ndf = %.1f/%d = %.1f", func->GetChisquare(), func->GetNDF(), func->GetChisquare() / func->GetNDF()));
9005   DrawLatex(0.5, yPosChi2 - 0.05, 1, Form("#chi^{2}/ndf = %.1f/%d = %.1f", chi2, ndf, chi2 / ndf));
9006 }
9007
9008 Double_t DeltaPhiWidth2DFitFunction(Double_t *x, Double_t *par)
9009 {
9010   // params: 0: gaussian amplitude, 1: phi width, 2: eta width
9011   //         3..bins+2 constants as fct of eta
9012   
9013   Int_t etaBin = (Int_t) ((x[1] + 2.0) / 0.1);
9014   
9015   return par[3+etaBin]+par[0]*TMath::Exp(-0.5*((x[0]/par[1])**2+(x[1]/par[2])**2));
9016 }
9017
9018 void FitDeltaPhi2DOneFunction(TH2* hist, TVirtualPad* pad1, TVirtualPad* pad2, TVirtualPad* pad3, TGraphErrors* width1, TGraphErrors* width2, Float_t x, Float_t yPosChi2)
9019 {
9020   Float_t outerLimit = 1.8;
9021
9022   hist->GetYaxis()->SetRangeUser(-1.59, 1.59);
9023   
9024   pad1->cd();
9025   hist->SetStats(0);
9026   hist->DrawCopy("SURF1");
9027   
9028   Float_t min = hist->GetMinimum();
9029   Float_t max = hist->GetMaximum();
9030   
9031   Int_t bins = hist->GetNbinsX();
9032   
9033   // ranges are to exclude eta gap region from fit
9034   func = new TF2("func", DeltaPhiWidth2DFitFunction, -5, 5, -outerLimit, outerLimit, bins+3);
9035   func->SetParameters(1, 0.3, 0.3);
9036   for (Int_t i=3; i<bins+3; i++)
9037     func->SetParameter(i, 0);
9038
9039   func->SetParLimits(0, 0, 10);
9040   func->SetParLimits(1, 0.1, 10);
9041   func->SetParLimits(2, 0.1, 10);
9042   
9043   hist->Fit(func, "0R", "");
9044 //   hist->Fit(func, "IM", "SAME");
9045
9046   pad2->cd();
9047   funcHist = (TH2*) hist->Clone("funcHist");
9048   funcHist->Reset();
9049   funcHist->Add(func);
9050   funcHist->SetMinimum(min);
9051   funcHist->SetMaximum(max);
9052   funcHist->Draw("SURF1");
9053   
9054   pad3->cd();
9055   hist->Add(func, -1);
9056   hist->SetMinimum(min);
9057   hist->SetMaximum(max);
9058   hist->DrawCopy("SURF1");
9059   
9060   width1->SetPoint(width1->GetN(), x, TMath::Abs(func->GetParameter(1)));
9061   width1->SetPointError(width1->GetN()-1, 0, func->GetParError(1));
9062     
9063   width2->SetPoint(width2->GetN(), x, TMath::Abs(func->GetParameter(2)));
9064   width2->SetPointError(width2->GetN()-1, 0, func->GetParError(2));
9065
9066   Float_t chi2 = 0;
9067   Int_t ndf = 0;
9068   for (Int_t i=hist->GetXaxis()->FindBin(-0.8); i<=hist->GetXaxis()->FindBin(0.8); i++)
9069     for (Int_t j=hist->GetYaxis()->FindBin(-0.8); j<=hist->GetYaxis()->FindBin(0.8); j++)
9070     {
9071       if (hist->GetBinError(i, j) > 0)
9072       {
9073         chi2 += TMath::Power(hist->GetBinContent(i, j) / hist->GetBinError(i, j), 2);
9074         ndf++;
9075       }
9076     }
9077   ndf -= func->GetNumberFreeParameters();
9078   
9079   printf("#chi^{2}/ndf = %.1f/%d = %.1f  ", func->GetChisquare(), func->GetNDF(), func->GetChisquare() / func->GetNDF());
9080   Printf("#chi^{2}/ndf = %.1f/%d = %.1f", chi2, ndf, chi2 / ndf);
9081
9082   DrawLatex(0.5, yPosChi2, 1, Form("#chi^{2}/ndf = %.1f/%d = %.1f", func->GetChisquare(), func->GetNDF(), func->GetChisquare() / func->GetNDF()));
9083   DrawLatex(0.5, yPosChi2 - 0.05, 1, Form("#chi^{2}/ndf = %.1f/%d = %.1f", chi2, ndf, chi2 / ndf));
9084 }
9085
9086 void AnalyzeDeltaPhiEtaGap2D(const char* fileName, Int_t method)
9087 {
9088   TFile::Open(fileName);
9089   
9090   Int_t maxLeadingPt = 5;
9091   Int_t maxAssocPt = 6;
9092
9093   TGraphErrors* width1[4];
9094   TGraphErrors* width2[4];
9095   
9096   Int_t nHists = 4;
9097   for (Int_t histId = 0; histId < nHists; histId++)
9098   {
9099     width1[histId] = new TGraphErrors;
9100     width2[histId] = new TGraphErrors;
9101     for (Int_t i=0; i<maxLeadingPt; i++)
9102     {
9103       TCanvas* canvas = new TCanvas(Form("DeltaPhi_%d_%d", histId, i), Form("DeltaPhi_%d_%d", histId, i), 1000, 1000);
9104       canvas->Divide(3, maxAssocPt);
9105       
9106       for (Int_t j=0; j<maxAssocPt; j++)
9107       {
9108         for (Int_t k=1; k<=3; k++)
9109         {
9110           canvas->cd(3 * j + k);
9111           gPad->SetLeftMargin(0.15);
9112           gPad->SetBottomMargin(0.2);
9113           gPad->SetTopMargin(0.01);
9114           gPad->SetRightMargin(0.01);
9115         }
9116         
9117 //      if (i != 1 || j != 2)
9118 //        continue;
9119     
9120         hist1 = (TH1*) gFile->Get(Form("dphi_%d_%d_%d", i, j, histId));
9121         if (!hist1)
9122           continue;
9123         
9124         Float_t xPos = j*8+i;
9125
9126         if (method == 0)
9127           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);
9128         else
9129           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);
9130         
9131         break;
9132       }
9133       
9134       break;
9135     }
9136     
9137     break;
9138   }
9139   
9140   return;
9141   
9142   Int_t marker[] = { 20, 24, 25, 26 };
9143   Int_t colors[] = { 2, 2, 4, 6 };
9144   const char* labels[] = { "0-5%", "60-90%", "pp", "30-40%" };
9145   
9146   Bool_t found = kTRUE;
9147   c1 = (TCanvas*) gROOT->GetListOfCanvases()->FindObject("width_phi");
9148   if (!c1)
9149   {
9150     c1 = new TCanvas("width_phi", "width_phi", 800, 600);
9151     colors[0] = 1;
9152     found = kFALSE;
9153   }
9154   c1->cd();
9155   
9156   for (Int_t histId = 0; histId < nHists; histId++)
9157   {
9158     width1[histId]->SetMarkerStyle(marker[histId]);
9159     width1[histId]->SetMarkerColor(colors[histId]);
9160     width1[histId]->Draw((histId == 0 && !found) ? "AP" : "PSAME");
9161     DrawLatex(0.7, 0.8 - 0.05 * histId, colors[histId], labels[histId]);
9162   }
9163   
9164   found = kTRUE;
9165   c1 = (TCanvas*) gROOT->GetListOfCanvases()->FindObject("width_eta");
9166   if (!c1)
9167   {
9168     c1 = new TCanvas("width_eta", "width_eta", 800, 600);
9169     colors[0] = 1;
9170     found = kFALSE;
9171   }
9172   c1->cd();
9173   for (Int_t histId = 0; histId < nHists; histId++)
9174   {
9175     width2[histId]->SetMarkerStyle(marker[histId]);
9176     width2[histId]->SetMarkerColor(colors[histId]);
9177     width2[histId]->Draw((histId == 0 && !found) ? "AP" : "PSAME");
9178     DrawLatex(0.7, 0.8 - 0.05 * histId, colors[histId], labels[histId]);
9179   }
9180 }
9181 */
9182
9183 void RemoveWing(const char* fileName, const char* outputFile)
9184 {
9185   // 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
9186
9187   file = TFile::Open(fileName);
9188   file2 = TFile::Open(outputFile, "RECREATE");
9189   file2->Close();
9190   
9191   Int_t maxLeadingPt = 10;
9192   Int_t maxAssocPt = 11;
9193
9194   Int_t nHists = 6;
9195   for (Int_t i=0; i<maxLeadingPt; i++)
9196   {
9197     triggers = (TH1*) file->Get(Form("triggers_%d", i));
9198     if (triggers)
9199     {
9200       file2 = TFile::Open(outputFile, "UPDATE");
9201       triggers->Write();
9202       file2->Close();
9203     }
9204     for (Int_t j=0; j<maxAssocPt; j++)
9205     {
9206       for (Int_t histId = 0; histId < nHists; histId++)
9207       {
9208         hist = (TH2*) file->Get(Form("dphi_%d_%d_%d", i, j, histId));
9209         if (!hist)
9210           continue;
9211         
9212         Float_t width = 1.5;
9213         TH1* proj = hist->ProjectionY(Form("projx", hist->GetName()), hist->GetXaxis()->FindBin(TMath::Pi() - width), hist->GetXaxis()->FindBin(TMath::Pi()+ width));
9214         proj->Fit("pol0", "0");
9215         //new TCanvas; proj->DrawCopy();
9216         proj->Divide(proj->GetFunction("pol0"));
9217         //new TCanvas; proj->DrawCopy();
9218         //new TCanvas; hist->DrawCopy("SURF1");
9219         for (Int_t x=1; x<=hist->GetNbinsX(); x++)
9220           for (Int_t y=1; y<=hist->GetNbinsY(); y++)
9221           {
9222             if (proj->GetBinContent(y) <= 0)
9223               continue;
9224             hist->SetBinContent(x, y, hist->GetBinContent(x, y) / proj->GetBinContent(y));
9225             hist->SetBinError(x, y, hist->GetBinError(x, y) / proj->GetBinContent(y));
9226           }
9227         //new TCanvas; hist->DrawCopy("SURF1");
9228
9229         file2 = TFile::Open(outputFile, "UPDATE");
9230         hist->Write();
9231         file2->Close();
9232       }
9233     }
9234   }  
9235 }
9236   
9237 void RemoveWingAllSpecies()
9238 {
9239   const char* suffix[] = { "Hadrons", "Pions", "Kaons", "Protons" };
9240   TString baseName = "dphi_corr_LHC13bc_20130604_";
9241   
9242   for (Int_t i=0; i<4; i++)
9243     RemoveWing(baseName + suffix[i] + ".root", baseName + suffix[i] + "_wingremoved.root");
9244 }  
9245   
9246 void PlotPtDistributions(const char* fileName1, Int_t centrBegin = 1, Int_t centrEnd = 2)
9247 {
9248   loadlibs();
9249
9250   Int_t maxLeadingPt = 3;
9251   Float_t leadingPtArr[] = { 1.0, 10.0, 20.0, 40.0 };
9252   
9253   Int_t nCentralityBins = 5;
9254   Int_t centralityBins[] = { 1, 7, 9, 11, 13, 16 };
9255   
9256   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName1);
9257     
9258   TCanvas* canvas = new TCanvas("Pt", "Pt", 1000, 1000);
9259   canvas->Divide(2, maxLeadingPt+2);
9260   
9261   TLegend* legend = new TLegend(0.2, 0.2, 0.95, 0.90);
9262   legend->SetFillColor(0);
9263   legend->SetTextSize(0.08);
9264   
9265   TLegend* legendB = new TLegend(0.2, 0.2, 0.95, 0.90);
9266   legendB->SetFillColor(0);
9267   legendB->SetTextSize(0.08);
9268   
9269   TLegend* legend2 = new TLegend(0.2, 0.2, 0.95, 0.90);
9270   legend2->SetFillColor(0);
9271   legend2->SetTextSize(0.08);
9272   
9273   Int_t colors[] = { 1, 2, 4, 6 };
9274   Int_t markers[] = { 20, 21, 22, 23, 24, 25 };
9275   
9276   for (Int_t i=0; i<maxLeadingPt; i++)
9277   {
9278     Double_t ptMin = leadingPtArr[i] + 0.01;
9279     //Double_t ptMax = leadingPtArr[i+1] - 0.01;
9280     Double_t ptMax = 39.99;
9281       
9282     TString str;
9283     str.Form("%.1f < p_{T,trig} < %.1f", ptMin - 0.01, ptMax + 0.01);
9284     
9285     canvas->cd(2*i+1+2);
9286     gPad->SetLeftMargin(0.15);
9287     gPad->SetBottomMargin(0.2);
9288     gPad->SetTopMargin(0.01);
9289     gPad->SetRightMargin(0.01);
9290     gPad->SetLogy();
9291     gPad->SetLogx();
9292     gPad->SetGridx();
9293     gPad->SetGridy();
9294     
9295     TH2F* dummy = new TH2F("dummy", "", 100, 1, 40, 100, 1e-5, 1e3);
9296     dummy->SetStats(kFALSE);
9297     dummy->SetXTitle("p_{T,assoc}");
9298     dummy->SetYTitle("");
9299     dummy->GetYaxis()->SetTitleOffset(1);
9300     Prepare1DPlot(dummy);
9301   
9302     dummy->GetXaxis()->SetLabelSize(0.06);
9303     dummy->GetYaxis()->SetLabelSize(0.06);
9304     dummy->GetXaxis()->SetTitleSize(0.06);
9305     dummy->GetYaxis()->SetTitleSize(0.06);
9306     dummy->DrawCopy();
9307     
9308     Float_t phiRange[] = { 0, TMath::Pi() / 2, TMath::Pi() };
9309     const char* phiLabels[] = { "Towards", "Transverse", "Away" };
9310     
9311     for (Int_t j=0; j<3; j++)
9312     {
9313       TH1* centralEta = 0;
9314       TH1* sideEta1 = 0;
9315       
9316       if (j == 0)
9317       {
9318         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);
9319         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);
9320         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);
9321         sideEta1->Add(sideEta2); // TODO can be done smarter? what about the errors?
9322       
9323         Prepare1DPlot(sideEta1);
9324         Prepare1DPlot(centralEta);
9325         
9326         centralEta->SetLineColor(colors[j]);
9327         sideEta1->SetLineColor(colors[j+1]);
9328       
9329         if (i == 0)
9330         {
9331           legend->AddEntry(centralEta->Clone(), Form("Jet, %s: |#eta| < 0.7, #phi ~ %.1f", phiLabels[j], phiRange[j]));
9332           legend->AddEntry(sideEta1->Clone(), Form("Ridge, %s: 0.7 < |#eta| < 1.4, #phi ~ %.1f", phiLabels[j], phiRange[j]));
9333         }
9334       }
9335       else
9336       {
9337         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);
9338         centralEta->Scale(0.5);
9339         centralEta->SetLineColor(colors[j+1]);
9340       
9341         Prepare1DPlot(centralEta);
9342         
9343         if (i == 0)
9344           legend->AddEntry(centralEta->Clone(), Form("%s: |#eta| < 1.4, #phi ~ %.1f", phiLabels[j], phiRange[j]));
9345       }
9346       
9347       canvas->cd(2*i+1+2);
9348       centralEta->DrawCopy("SAME");
9349       if (sideEta1)
9350         sideEta1->DrawCopy("SAME");
9351       
9352       centralEta->SetLineColor(colors[i]);
9353       centralEta->Scale(100.0 / centralEta->Integral());
9354       if (sideEta1)
9355       {
9356         sideEta1->SetLineColor(colors[i]);
9357         sideEta1->Scale(100.0 / sideEta1->Integral());
9358       }
9359     
9360       if (j < 2)
9361         canvas->cd(j*4+4);
9362       else
9363         canvas->cd(j*4+2);
9364       if (i == 0)
9365       {
9366         gPad->SetLeftMargin(0.15);
9367         gPad->SetBottomMargin(0.2);
9368         gPad->SetTopMargin(0.01);
9369         gPad->SetRightMargin(0.01);
9370         
9371         dummy->DrawCopy();
9372         
9373         gPad->SetLogy();
9374         gPad->SetLogx();
9375         gPad->SetGridx();
9376         gPad->SetGridy();
9377         
9378         TString str3;
9379         if (j == 0)
9380           str3.Form("Jet, %s: |#eta| < 0.7, #phi ~ %.1f", phiLabels[j], phiRange[j]);
9381         else
9382           str3.Form("%s: |#eta| < 1.4, #phi ~ %.1f", phiLabels[j], phiRange[j]);
9383         latex = new TLatex(0.2, 0.3, str3);
9384         latex->SetNDC();
9385         latex->SetTextSize(0.08);
9386         latex->Draw();
9387       }
9388       
9389       if (j == 0)
9390         legend2->AddEntry(centralEta->Clone(), str);
9391         
9392       centralEta->DrawCopy("SAME");
9393       
9394       if (sideEta1)
9395       {
9396         canvas->cd(j*4+4+2);
9397         if (i == 0)
9398         {
9399           gPad->SetLeftMargin(0.15);
9400           gPad->SetBottomMargin(0.2);
9401           gPad->SetTopMargin(0.01);
9402           gPad->SetRightMargin(0.01);
9403           
9404           dummy->DrawCopy();
9405           
9406           gPad->SetLogy();
9407           gPad->SetLogx();
9408           gPad->SetGridx();
9409           gPad->SetGridy();
9410           
9411           TString str3;
9412           if (j == 0)
9413             str3.Form("Ridge, %s: 0.7 < |#eta| < 1.4, #phi ~ %.1f", phiLabels[j], phiRange[j]);
9414           else
9415             str3.Form("%s: |#eta| < 1.4, #phi ~ %.1f", phiLabels[j], phiRange[j]);
9416           latex = new TLatex(0.2, 0.3, str3);
9417           latex->SetNDC();
9418           latex->SetTextSize(0.08);
9419           latex->Draw();
9420         }
9421         
9422         sideEta1->DrawCopy("SAME");
9423       }
9424     }
9425     
9426     TString str3;
9427     str3.Form("%d-%d%%", (Int_t) h->GetCentralityDistribution()->GetXaxis()->GetBinLowEdge(centrBegin), (Int_t) h->GetCentralityDistribution()->GetXaxis()->GetBinUpEdge(centrEnd));
9428     latex = new TLatex(0.2, 0.3, str3);
9429     latex->SetNDC();
9430     latex->SetTextSize(0.08);
9431     
9432     latex2 = new TLatex(0.55, 0.8, str);
9433     latex2->SetNDC();
9434     latex2->SetTextSize(0.06);
9435     
9436     canvas->cd(2*i+1+2);
9437     latex->Draw();
9438     latex2->Draw();
9439     
9440     //break;
9441   }
9442   
9443   canvas->cd(1);
9444   legend->Draw();
9445
9446   canvas->cd(2);
9447   legend2->Draw();
9448 }
9449
9450 TH1* GetNonSubtractedRHICYield(Int_t ptT, Int_t ptA, Int_t centrality)
9451 {
9452   rhicFile = TFile::Open("rhic/postcorr_AuAu_iter6_ppg106final.root");
9453   
9454   corrFunc = (TH1*) rhicFile->Get(Form("pi0hdphi_%d_%d_%d_2", ptT, ptA, centrality));
9455   //corrFunc->Draw();
9456   
9457   // integral
9458   corrFunc->Scale(1.0 / corrFunc->Integral());
9459   // bin width
9460   corrFunc->Scale(TMath::TwoPi() / corrFunc->GetBinWidth(1));
9461   
9462   same     = (TH1*) rhicFile->Get(Form("pi0hdphi_%d_%d_%d_0", ptT, ptA, centrality));
9463   Float_t nPairs = same->Integral();
9464   
9465   triggers = (TH1*) rhicFile->Get(Form("pi0pt_%d_%d", ptT, centrality));
9466   Float_t nTrigs = triggers->Integral();
9467   
9468   graph = (TGraph*) rhicFile->Get(Form("gS_%d_%d", ptT, centrality));
9469   
9470   Printf("%f %f %f %f", nPairs, nTrigs, nPairs / nTrigs, graph->GetY()[ptA]);
9471   
9472   corrFunc->Scale(nPairs / nTrigs);
9473  
9474   //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))));
9475   
9476   Float_t values[3];
9477   Float_t errors[3];
9478   
9479   Float_t regionBegin[3] = { -TMath::Pi() / 2,        TMath::Pi() / 2 - 0.4, 1.5 * TMath::Pi() - 0.4 };
9480   Float_t regionEnd[3] =   { -TMath::Pi() / 2 + 0.4,  TMath::Pi() / 2 + 0.4, 1.5 * TMath::Pi() };
9481     
9482   // weighted mean
9483   Float_t sum = 0;
9484   Float_t weight = 0;
9485   for (Int_t i=0; i<3; i++)
9486   {
9487     corrFunc->Fit("pol0", "0Q", "", regionBegin[i], regionEnd[i]);
9488     func = corrFunc->GetFunction("pol0");
9489     if (!func)
9490       continue;
9491     sum += func->GetParameter(0) / func->GetParError(0) / func->GetParError(0);
9492     weight += 1. / func->GetParError(0) / func->GetParError(0);
9493   }
9494   
9495   if (weight == 0)
9496     return 0;
9497   
9498   sum /= weight;
9499   weight = TMath::Sqrt(1. / weight);
9500   
9501   corrFunc->Add(new TF1("func", "1", -5, 5), -sum);
9502   
9503   return corrFunc;
9504   
9505   new TCanvas;
9506   corrFunc->Draw();
9507   compHist = (TH1*) rhicFile->Get(Form("ptyMSMP_0_%d%d%d", ptT, ptA, centrality));
9508   compHist->DrawCopy("SAME");
9509   
9510   //compHist->Add((TF1*) compHist->GetListOfFunctions()->First());
9511   //compHist->DrawCopy("SAME");
9512 }
9513   
9514 void DeltaPhiVsRHIC(Int_t rhicCentrality = 0, Int_t aliceCentrality = 0, Bool_t reduced = kFALSE)
9515 {
9516   aliceFile = TFile::Open("alice_dphi_corr_rhicbinning.root");
9517   rhicFile = TFile::Open("rhic/postcorr_AuAu_iter6_ppg106final.root");
9518
9519   Int_t maxLeadingPt = 4;
9520   Int_t maxAssocPt = 5;
9521   
9522   if (reduced)
9523   {
9524     Int_t maxSelected = 4;
9525     Int_t selectedLead[] = { 0, 0, 2, 2 };
9526     Int_t selectedAssoc[] = { 1, 2, 3, 4 };
9527    
9528     maxLeadingPt = TMath::Sqrt(maxSelected);
9529     maxAssocPt = TMath::Sqrt(maxSelected);
9530   }
9531     
9532   TCanvas* canvas = new TCanvas("DeltaPhi", "DeltaPhi", 1000, 700);
9533   canvas->Divide(maxAssocPt, maxLeadingPt);
9534   
9535   for (Int_t i=0; i<maxLeadingPt; i++)
9536     for (Int_t j=0; j<maxAssocPt; j++)
9537     {
9538       Printf("%d %d", i, j);
9539     
9540       canvas->cd(j+1 + i * maxAssocPt);
9541       gPad->SetLeftMargin(0.15);
9542       gPad->SetBottomMargin(0.2);
9543       //gPad->SetTopMargin(0.01);
9544       gPad->SetRightMargin(0.01);
9545       
9546       Int_t iSel = i;
9547       Int_t jSel = j;
9548       
9549       if (reduced)
9550       {
9551         iSel = selectedLead[j + i * maxAssocPt];
9552         jSel = selectedAssoc[j + i * maxAssocPt];
9553       }
9554       
9555       //rhic = (TH1*) rhicFile->Get(Form("VptyMSMP_0_%d%d%d", iSel, jSel, rhicCentrality));
9556       rhic = GetNonSubtractedRHICYield(iSel, jSel, rhicCentrality);
9557       if (!rhic)
9558         continue;
9559       rhic->SetLineColor(2);
9560       rhic->SetMarkerStyle(1);
9561       
9562       alice = (TH1*) aliceFile->Get(Form("dphi_%d_%d_%d_fit_flat", iSel, jSel, aliceCentrality));
9563       if (!alice)
9564         continue;
9565         
9566       // match near side yield
9567       if (1)
9568       {
9569         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));
9570         
9571         Printf("%f", factor);
9572         rhic->Scale(factor);
9573       }
9574         
9575       alice->SetLineColor(1);
9576         
9577       //alice->Rebin(36); rhic->Rebin(30);
9578       
9579       clone = alice->DrawCopy("");
9580       rhic->DrawCopy("SAME");
9581       
9582       //Printf("chi2 test: chi2/ndf = %f", alice->Chi2Test(rhic, "WW CHI2/NDF"));
9583       Float_t chi2 = 0;
9584       Float_t n = 0;
9585       for (Int_t k=1; k<=rhic->GetNbinsX(); k++)
9586       {
9587         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));
9588         n++;
9589       }
9590       
9591       chi2 /= n;
9592       Printf("chi2 test: chi2/ndf = %f", chi2);      
9593       
9594       clone->GetYaxis()->SetRangeUser(TMath::Min(alice->GetMinimum(), rhic->GetMinimum()) * 1.1, TMath::Max(alice->GetMaximum(), rhic->GetMaximum()) * 1.1);
9595       
9596       for (Int_t bin=1; bin<=rhic->GetNbinsX(); bin++)
9597       {
9598         Double_t aliceValue = alice->GetBinContent(alice->FindBin(rhic->GetXaxis()->GetBinCenter(bin)));
9599         if (aliceValue == 0)
9600           continue;
9601         rhic->SetBinContent(bin, rhic->GetBinContent(bin) / aliceValue);
9602         rhic->SetBinError(bin, 0);
9603       }
9604       
9605       rhic->Rebin(2);
9606       rhic->Scale(0.5);
9607       
9608       rhic->SetLineColor(3);
9609       //rhic->DrawCopy("SAME");
9610       
9611       //return;
9612     }
9613     
9614     canvas->SaveAs("yield_comparison.png");
9615 }
9616   
9617 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")
9618 {
9619   // DeltaPhi("high_stat_binning_pp7_pt8.root", "high_stat_binning_pp7_pythia_pt8.root", 0, 1, 0, "pp 7 TeV uncorrected")
9620   // DeltaPhi("high_stat_binning_pp900_pt8.root", "high_stat_binning_pp900_pythia_pt8.root", 0, 1, 0, "pp 0.9 TeV uncorrected")
9621
9622   style(2);
9623
9624   aliceFile = TFile::Open(fileName);
9625   if (fileName2)
9626     secondFile = TFile::Open(fileName2);
9627
9628   if (1)
9629   {
9630     Int_t maxLeadingPt = 3;
9631     Int_t maxAssocPt = 3;
9632   }
9633   else
9634   {
9635     Int_t maxLeadingPt = 3;
9636     Int_t maxAssocPt = 7;
9637   }
9638   
9639   if (reduced)
9640   {
9641     Int_t maxSelected = 4;
9642     Int_t selectedLead[] = { 1, 1, 1, 1 };
9643     Int_t selectedAssoc[] = { 2, 3, 4, 5 };
9644    
9645     maxLeadingPt = TMath::Sqrt(maxSelected);
9646     maxAssocPt = TMath::Sqrt(maxSelected);
9647   }
9648   
9649   factorGraph = new TGraphErrors;
9650     
9651 //   TCanvas* canvas = new TCanvas(Form("%s_%s", fileName, fileName2 ? fileName2 : ""), Form("%s_%s", fileName, fileName2 ? fileName2 : ""), 600, 900);
9652   TCanvas* canvas = new TCanvas(Form("%s_%s", fileName, fileName2 ? fileName2 : ""), Form("%s_%s", fileName, fileName2 ? fileName2 : ""), 1000, 1000);
9653   canvas->Divide(maxAssocPt, maxLeadingPt);
9654   
9655   for (Int_t i=0; i<maxLeadingPt; i++)
9656     for (Int_t j=0; j<maxAssocPt; j++)
9657     {
9658       TH1* first = 0;
9659       TH1* peripheral = 0;
9660       for (Int_t aliceCentrality=0; aliceCentrality<4; aliceCentrality++)
9661       {
9662         Printf("%d %d %d", i, j, aliceCentrality);
9663         
9664         if (aliceCentrality == 1)
9665           continue;
9666       
9667         canvas->cd(j+1 + i * maxAssocPt);
9668         
9669         Int_t iSel = i;
9670         Int_t jSel = j;
9671         Int_t centralitySel = aliceCentrality;
9672         currentFile = aliceFile;
9673         
9674         if (reduced)
9675         {
9676           iSel = selectedLead[j + i * maxAssocPt];
9677           jSel = selectedAssoc[j + i * maxAssocPt];
9678         }
9679         
9680         if (fileName2)
9681         {
9682           if (ppComparison)
9683           {
9684             centralitySel = 3;
9685             if (aliceCentrality == 1)
9686               currentFile = secondFile;
9687             else if (aliceCentrality == 2)
9688               break;
9689           }
9690           else
9691             if (aliceCentrality == 3)
9692               currentFile = secondFile;
9693         }
9694         
9695         //alice = (TH1*) currentFile->Get(Form("dphi_%d_%d_%d%s", iSel, jSel, centralitySel, (centralitySel < 3) ? "_tsallis_flat" : ((flatOrTsallis) ? "" : "_fit_flat")));
9696         alice = (TH1*) currentFile->Get(Form("dphi_%d_%d_%d%s", iSel, jSel, centralitySel, histName));
9697         if (!alice)
9698           continue;
9699
9700         if (0)
9701         {
9702           Printf("WARNING: Applying some scaling and rebinning! Only for 2.76 data-MC comparison!");
9703           if (aliceCentrality == 0)
9704           {
9705             alice->Rebin(2); alice->Scale(0.5); 
9706           alice->Scale(1.0 / 1.6);
9707           }
9708 //        else
9709 //          alice->Scale(1.6);
9710         }
9711         
9712             alice->Rebin(2); alice->Scale(0.5); 
9713 //          alice->Scale(1.0 / 1.6);
9714
9715         // match near side yield to peripheral
9716         if (1 && centralitySel == 3 && peripheral)
9717         {
9718          if (mode == 0 || mode == 1)
9719           {
9720             Double_t width = 0.5;
9721             Double_t error1, error2;
9722             Double_t integral1 = peripheral->IntegralAndError(peripheral->FindBin(-width), peripheral->FindBin(width), error1);
9723             Double_t integral2 = alice->IntegralAndError(alice->FindBin(-width), alice->FindBin(width), error2);
9724             if (mode == 1)
9725             {
9726               Double_t tmpErr = 0;
9727               integral1 += peripheral->IntegralAndError(peripheral->FindBin(TMath::Pi() - width), peripheral->FindBin(TMath::Pi() + width), tmpErr);
9728               error1 = TMath::Sqrt(error1 * error1 + tmpErr * tmpErr);
9729               
9730               integral2 += alice->IntegralAndError(alice->FindBin(TMath::Pi() - width), alice->FindBin(TMath::Pi() + width), tmpErr);
9731               error2 = TMath::Sqrt(error2 * error2 + tmpErr * tmpErr);
9732             }
9733           }
9734           else if (mode == 2)
9735           {
9736             Double_t error1, error2;
9737             Double_t integral1 = peripheral->IntegralAndError(1, peripheral->GetNbinsX(), error1);
9738             Double_t integral2 = alice->IntegralAndError(1, alice->GetNbinsX(), error2);
9739           }
9740           else if (mode == 3)
9741           {
9742             Double_t width = 1.0;
9743             Double_t error1, error2;
9744             Double_t integral1 = peripheral->IntegralAndError(peripheral->FindBin(TMath::Pi() - width), peripheral->FindBin(TMath::Pi() + width), error1);
9745             Double_t integral2 = alice->IntegralAndError(alice->FindBin(TMath::Pi() - width), alice->FindBin(TMath::Pi() + width), error2);
9746           }
9747             
9748           Double_t factor = integral1 / integral2;
9749           
9750           //factor = 0.804 * 0.9;
9751           Printf("%f", factor);
9752 //           alice->Scale(factor);
9753           factorGraph->SetPoint(factorGraph->GetN(), factorGraph->GetN(), factor);
9754           factorGraph->SetPointError(factorGraph->GetN() - 1, 0, factor * TMath::Sqrt(TMath::Power(error1 / integral1, 2) + TMath::Power(error2 / integral2, 2)));
9755         }
9756         
9757         if (ppComparison && aliceCentrality == 0)
9758           peripheral = alice;
9759         else if (aliceCentrality == 2)
9760           peripheral = alice;          
9761           
9762 //         alice->SetYTitle("1/(N_{trig} #Delta#eta) dN_{assoc}/d#Delta#phi (1/rad)");
9763         alice->SetYTitle("1/N_{trig} dN_{assoc}/d#Delta#phi (1/rad)");
9764         alice->SetXTitle("#Delta#phi (rad)");
9765         alice->SetLineColor(aliceCentrality+1);
9766         alice->SetLineWidth(2);
9767         alice->SetMarkerColor(aliceCentrality+1);
9768         alice->GetYaxis()->SetTitleOffset(1.7);
9769         clone = alice->DrawCopy((aliceCentrality > 0) ? "SAME" : "");
9770         clone->SetTitle("");
9771         
9772         TString str(alice->GetTitle());
9773         str.ReplaceAll(" - ", "#");
9774         tokens = str.Tokenize("#");
9775           
9776         if (aliceCentrality == 0)
9777         {
9778           for (Int_t k=0; k<2; k++)
9779           {
9780             TString str(tokens->At(k)->GetName());
9781             str.ReplaceAll(".0", "");
9782             str.ReplaceAll("< p", "GeV/c < p");
9783             str += " GeV/c";
9784             latex = new TLatex(0.48, 0.92-k*0.06, str);
9785             latex->SetNDC();
9786             latex->SetTextSize(0.04);
9787             latex->Draw();
9788           }
9789           
9790         }
9791         
9792         if (!first)
9793           first = clone;
9794         else
9795           first->GetYaxis()->SetRangeUser(TMath::Min(first->GetMinimum(), clone->GetMinimum()), TMath::Max(first->GetMaximum(), clone->GetMaximum()));
9796           
9797         
9798           
9799         //return;
9800       }
9801       if (first)
9802         //first->GetYaxis()->SetRangeUser(first->GetMinimum(), first->GetMaximum() * 1.2);
9803         first->GetYaxis()->SetRangeUser(first->GetMinimum(), first->GetMaximum() * 1.5);
9804     }
9805     
9806   if (0)
9807   {
9808     for (Int_t i=1; i<=6; i++)
9809     {
9810       canvas->cd(i);
9811       
9812       latex = new TLatex(0.58, 0.8, "ALICE preliminary");
9813       latex->SetTextSize(0.04);
9814       latex->SetNDC();
9815       latex->Draw();
9816     
9817       latex = new TLatex(0.58, 0.74, Form("%s", dataTag));
9818       latex->SetTextSize(0.04);
9819       latex->SetNDC();
9820       latex->Draw();
9821       
9822       latex = new TLatex(0.58, 0.68, "Stat. uncertainties only");
9823       latex->SetTextSize(0.04);
9824       latex->SetNDC();
9825       latex->Draw();
9826     
9827       latex = new TLatex(0.58, 0.62, "|#eta| < 0.8");
9828       latex->SetTextSize(0.04);
9829       latex->SetNDC();
9830       latex->Draw();
9831     
9832       if (ppComparison)
9833       {
9834         legend = new TLegend(0.3, 0.8, 0.47, 0.95);
9835         legend->SetFillColor(0);
9836         legend->SetTextSize(0.04);
9837         legend->AddEntry(peripheral, "Data");
9838         legend->AddEntry(alice, "Pythia");
9839         legend->Draw();
9840       }
9841
9842       DrawALICELogo(0.75, 0.47, 0.95, 0.6);
9843     }
9844   }
9845   
9846   canvas->SaveAs(Form("%s.eps", canvas->GetName()));
9847   canvas->SaveAs(Form("%s.png", canvas->GetName()));
9848     
9849   new TCanvas;
9850   peripheral->Divide(alice);
9851   peripheral->DrawCopy();
9852   //alice->DrawCopy("SAME");
9853   
9854     
9855   graphCanvas = (TCanvas*) gROOT->GetListOfCanvases()->FindObject("graphCanvas");
9856   factorGraph->SetMarkerStyle(20);
9857   if (!graphCanvas)
9858   {
9859     graphCanvas = new TCanvas("graphCanvas", "graphCanvas", 800, 600);
9860     factorGraph->Draw("AP");
9861   }
9862   else
9863   {
9864     graphCanvas->cd();
9865     factorGraph->SetLineColor(2);
9866     factorGraph->SetMarkerColor(2);
9867     factorGraph->Draw("SAMEP");
9868   }
9869   factorGraph->GetYaxis()->SetRangeUser(0.6, 1.4);
9870   
9871   factorGraph->Print();
9872 }
9873
9874 void ComparePPYields(const char* histName = "_fit_flat")
9875 {
9876   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" };
9877   const char* titles[] = { "0.9 data", "0.9 Pythia", "2.76 Pythia", "7 Pythia", "7 data" };
9878   
9879   Int_t colors[] = { 1, 2, 3, 4, 6 };
9880   
9881   Int_t maxLeadingPt = 3;
9882   Int_t maxAssocPt = 2;
9883   
9884   TCanvas* canvas = new TCanvas("ComparePPYields", "ComparePPYields", 600, 900);
9885   canvas->Divide(maxAssocPt, maxLeadingPt);
9886   
9887   legend = new TLegend(0.5, 0.5, 0.8, 0.8);
9888   legend->SetFillColor(0);
9889   
9890   TGraphErrors** graphs = new TGraphErrors*[5];
9891   TGraphErrors** graphs2 = new TGraphErrors*[5];
9892       
9893   for (Int_t nFiles = 0; nFiles < 5; nFiles++)
9894   {
9895     graphs[nFiles] = new TGraphErrors;
9896     graphs2[nFiles] = new TGraphErrors;
9897   }
9898   
9899   for (Int_t i=0; i<maxLeadingPt; i++)
9900     for (Int_t j=0; j<maxAssocPt; j++)
9901     {
9902       canvas->cd(j+1 + i * maxAssocPt);
9903       gPad->SetLeftMargin(0.18);
9904       gPad->SetBottomMargin(0.1);
9905       gPad->SetTopMargin(0.01);
9906       gPad->SetRightMargin(0.01);
9907         
9908       TH1* first = 0;
9909         
9910       for (Int_t nFiles = 0; nFiles < 5; nFiles++)
9911       {
9912         currentFile = TFile::Open(files[nFiles]);
9913
9914         Int_t aliceCentrality = 3;
9915           
9916         Printf("%d %d %d", i, j, nFiles);
9917       
9918         alice = (TH1*) currentFile->Get(Form("dphi_%d_%d_%d%s", i, j, aliceCentrality, histName));
9919         if (!alice)
9920           continue;
9921           
9922         alice->SetYTitle("1/N_{trig} dN/dp_{T,assoc}");
9923         alice->SetLineColor(colors[nFiles]);
9924         alice->SetMarkerColor(colors[nFiles]);
9925         alice->GetYaxis()->SetTitleOffset(1.7);
9926         clone = alice->DrawCopy((nFiles > 0) ? "SAME" : "");
9927         clone->SetTitle("");
9928         
9929         Double_t width = 0.7;
9930         Double_t error, error2;
9931         Double_t integral = alice->IntegralAndError(alice->FindBin(-width), alice->FindBin(width), error);
9932         Double_t integral2 = alice->IntegralAndError(alice->FindBin(TMath::Pi() - width), alice->FindBin(TMath::Pi() + width), error2);
9933         
9934         graphs[nFiles]->SetPoint(graphs[nFiles]->GetN(), j + i * maxAssocPt - 0.2, integral);
9935         graphs[nFiles]->SetPointError(graphs[nFiles]->GetN()-1, 0, error);
9936         
9937         graphs2[nFiles]->SetPoint(graphs2[nFiles]->GetN(), j + i * maxAssocPt + 0.2, integral2);
9938         graphs2[nFiles]->SetPointError(graphs2[nFiles]->GetN()-1, 0, error2);
9939         
9940         if (!first)
9941           first = clone;
9942         else
9943           first->GetYaxis()->SetRangeUser(TMath::Min(first->GetMinimum(), clone->GetMinimum()), TMath::Max(first->GetMaximum(), clone->GetMaximum()));
9944           
9945         if (nFiles == 0)
9946         {
9947           TString str(alice->GetTitle());
9948           str.ReplaceAll(" - ", "#");
9949           tokens = str.Tokenize("#");
9950             
9951           for (Int_t k=0; k<2; k++)
9952           {
9953             latex = new TLatex(0.6, 0.88-k*0.07, tokens->At(k)->GetName());
9954             latex->SetNDC();
9955             latex->SetTextSize(0.04);
9956             latex->Draw();
9957           }
9958         }
9959           
9960         if (i == 0 && j == 0)
9961           legend->AddEntry(clone, titles[nFiles]);
9962       }
9963       if (first)
9964         first->GetYaxis()->SetRangeUser(first->GetMinimum(), first->GetMaximum() * 1.1);
9965     }
9966     
9967   canvas->cd(1);
9968   
9969   legend->Draw();
9970   
9971   new TCanvas;
9972   for (Int_t nFiles = 0; nFiles < 5; nFiles++)
9973   {
9974     graphs[nFiles]->SetMarkerStyle(25);
9975     graphs[nFiles]->SetLineColor(colors[nFiles]);
9976     graphs[nFiles]->SetMarkerColor(colors[nFiles]);
9977     clone2 = (TGraphErrors*) graphs[nFiles]->DrawClone((nFiles == 0) ? "AP" : "PSAME");
9978     clone2->GetYaxis()->SetRangeUser(0, 5);
9979   
9980     graphs2[nFiles]->SetMarkerStyle(26);
9981     graphs2[nFiles]->SetLineColor(colors[nFiles]);
9982     graphs2[nFiles]->SetMarkerColor(colors[nFiles]);
9983     graphs2[nFiles]->DrawClone("PSAME");
9984   }  
9985
9986   new TCanvas;
9987   for (Int_t nFiles = 0; nFiles < 5; nFiles++)
9988   {
9989     DivideGraphs(graphs[nFiles], graphs[4]);
9990     DivideGraphs(graphs2[nFiles], graphs2[4]);
9991     
9992     graphs[nFiles]->SetMarkerStyle(25);
9993     graphs[nFiles]->SetLineColor(colors[nFiles]);
9994     graphs[nFiles]->SetMarkerColor(colors[nFiles]);
9995     clone2 = (TGraphErrors*) graphs[nFiles]->DrawClone((nFiles == 0) ? "AP" : "PSAME");
9996     clone2->GetYaxis()->SetRangeUser(0, 1.5);
9997   
9998     graphs2[nFiles]->SetMarkerStyle(26);
9999     graphs2[nFiles]->SetLineColor(colors[nFiles]);
10000     graphs2[nFiles]->SetMarkerColor(colors[nFiles]);
10001     graphs2[nFiles]->DrawClone("PSAME");
10002   }  
10003 }
10004
10005 void DeltaPhiPreliminary(const char* fileName, const char* histName)
10006 {
10007   style(2);
10008
10009   currentFile = TFile::Open(fileName);
10010
10011   TCanvas* canvas = new TCanvas(Form("dphi%s", histName), "dphi", 800, 800);
10012   canvas->Divide(2, 2);
10013   
10014   TLegend* legend = new TLegend(0.55, 0.47, 0.85, 0.65);
10015   legend->SetFillColor(0);
10016   legend->SetTextSize(0.04);
10017   
10018   Int_t colors[] = { 1, 2, 4, 6 };
10019   
10020   Int_t pad = 1;
10021   for (Int_t i=1; i<2; i++)
10022     for (Int_t j=2; j<6; j++)
10023     {
10024       canvas->cd(pad++);
10025   
10026       for (Int_t aliceCentrality=0; aliceCentrality<3; aliceCentrality+=2)
10027       {
10028         Printf("%d %d %d", i, j, aliceCentrality);
10029       
10030         hist = (TH1*) currentFile->Get(Form("dphi_%d_%d_%d%s", i, j, aliceCentrality, histName));
10031         if (!hist)
10032           continue;
10033           
10034         if (aliceCentrality == 3)
10035           hist->Scale(kPythiaScalingFactor);
10036           
10037         hist->GetYaxis()->SetTitleOffset(1.9);
10038         hist->SetLineColor(colors[aliceCentrality]);
10039         hist->SetMarkerColor(colors[aliceCentrality]);
10040         hist->SetLineWidth(2);
10041         hist->SetYTitle("1/N_{trig} dN_{assoc}/d#Delta#phi");
10042         hist->SetXTitle("#Delta#phi (rad)");
10043         
10044         clone = hist->DrawCopy((aliceCentrality > 0) ? "SAME" : "");
10045         clone->SetTitle("");
10046         
10047         TString str(hist->GetTitle());
10048         str.ReplaceAll(" - ", "#");
10049         tokens = str.Tokenize("#");
10050         hist->SetTitle("");
10051           
10052         if (aliceCentrality == 0)
10053         {
10054           for (Int_t k=0; k<2; k++)
10055           {
10056             TString str(tokens->At(k)->GetName());
10057             str.ReplaceAll(".0", "");
10058             str.ReplaceAll("< p", "GeV/c < p");
10059             str += " GeV/c";
10060           
10061             latex = new TLatex(0.5, 0.88-k*0.06, str);
10062             latex->SetNDC();
10063             latex->SetTextSize(0.04);
10064             latex->Draw();
10065           }
10066           
10067           latex = new TLatex(0.5, 0.76, "ALICE preliminary");
10068           latex->SetTextSize(0.04);
10069           latex->SetNDC();
10070           latex->Draw();
10071         
10072           latex = new TLatex(0.5, 0.70, "Stat. uncertainties only");
10073           latex->SetTextSize(0.04);
10074           latex->SetNDC();
10075           latex->Draw();
10076
10077           clone->GetYaxis()->SetRangeUser(0, clone->GetMaximum() * 1.2);
10078         }
10079         
10080         if (pad == 2)
10081         {
10082           if (aliceCentrality == 3)
10083             legend->AddEntry(hist, "Pythia");
10084           else
10085             legend->AddEntry(hist, tokens->At(2)->GetName());
10086         }
10087         
10088         legend->Draw();
10089         
10090       }
10091     }
10092     
10093   canvas->cd(3);
10094   
10095   canvas->SaveAs(Form("%s.eps", canvas->GetName()));
10096   canvas->SaveAs(Form("%s.png", canvas->GetName()));
10097 }
10098
10099 void DeltaPhiBaseLinePreliminary(const char* fileName)
10100 {
10101   style(2);
10102   
10103   loadlibs();
10104
10105   Float_t leadingPtArr[] = { 6.0, 8.0, 10.0, 15.0, 15.0 };
10106   Float_t assocPtArr[] =     { 0.5, 1.5, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
10107   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
10108
10109   Int_t i = 1;
10110   Int_t j = 3;
10111   Int_t step = 0;
10112
10113   gpTMin = assocPtArr[j] + 0.01;
10114   gpTMax = assocPtArr[j+1] - 0.01;
10115   SetupRanges(h);
10116       
10117   TString str;
10118   str.Form("%.0f GeV/c < p_{T,trig} < %.0f GeV/c", leadingPtArr[i], leadingPtArr[i+2]);
10119   
10120   TString str2;
10121   str2.Form("%.0f GeV/c < p_{T,assoc} < %.0f GeV/c", gpTMin - 0.01, gpTMax + 0.01);
10122           
10123   Float_t v2[3];
10124   TH1* hist1 = 0;
10125   TH1* hist2b = 0;
10126   
10127   GetDistAndFlow(h, 0, &hist1,  v2, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+2] - 0.01); 
10128   GetDistAndFlow(h, 0, &hist2b, v2+2, step, 60, 90, leadingPtArr[i] + 0.01, leadingPtArr[i+2] - 0.01); 
10129   
10130   hist1->SetLineWidth(2);
10131   hist2b->SetLineWidth(2);
10132
10133   canvas = new TCanvas("dphi_baseline", "dphi_baseline", 1200, 1200);
10134   canvas->Divide(2, 2);
10135   
10136   canvas->cd(1);
10137 //   gPad->SetLeftMargin(0.20);
10138   
10139   hist1->GetYaxis()->SetTitleOffset(1.9);
10140   hist1->SetYTitle("1/N_{trig} dN_{assoc}/d#Delta#phi");
10141   hist1->SetXTitle("#Delta#phi (rad)");
10142   hist1->SetTitle("");
10143   hist1->DrawCopy()->GetYaxis()->SetRangeUser(0, 0.59);
10144   
10145   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);
10146           
10147   latex = new TLatex(0.5, 0.78, "0-5%");
10148   latex->SetNDC();
10149   latex->SetTextSize(0.04);
10150   latex->Draw();
10151   
10152   if (1)
10153   {
10154     canvas->cd(2);
10155   //   gPad->SetLeftMargin(0.20);
10156     
10157     hist1->DrawCopy()->GetYaxis()->SetRangeUser(0.18, 0.295);
10158     DrawFlow(v2[0], hist1, leadingPtArr[i], assocPtArr[j], 0, i, 0, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
10159     
10160     latex->Draw();
10161     
10162     canvas->cd(3);
10163   //   gPad->SetLeftMargin(0.20);
10164     
10165     hist2b->GetYaxis()->SetTitleOffset(1.9);
10166     hist2b->SetYTitle("1/N_{trig} dN_{assoc}/d#Delta#phi");
10167     hist2b->SetXTitle("#Delta#phi (rad)");
10168     hist2b->SetTitle("");
10169     hist2b->DrawCopy();
10170             
10171     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);
10172     
10173     latex = new TLatex(0.5, 0.78, "60-90%");
10174     latex->SetNDC();
10175     latex->SetTextSize(0.04);
10176     latex->Draw();
10177     
10178     canvas->cd(4);
10179   //   gPad->SetLeftMargin(0.20);
10180         
10181     hist2b->DrawCopy()->GetYaxis()->SetRangeUser(0.01, 0.13);
10182     DrawFlow(v2[2], hist2b, leadingPtArr[i], assocPtArr[j], 0, i, 2, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
10183         
10184     latex->Draw();
10185   }
10186   
10187   for (Int_t i=1; i<=4; i++)
10188   {
10189     canvas->cd(i);
10190     
10191     latex = new TLatex(0.5, 0.84, str);
10192     latex->SetNDC();
10193     latex->SetTextSize(0.04);
10194     latex->Draw();
10195     
10196     latex = new TLatex(0.5, 0.90, str2);
10197     latex->SetNDC();
10198     latex->SetTextSize(0.04);
10199     latex->Draw();
10200   
10201     latex = new TLatex(0.5, 0.72, "ALICE preliminary");
10202     latex->SetTextSize(0.04);
10203     latex->SetNDC();
10204     latex->Draw();
10205   
10206     latex = new TLatex(0.5, 0.66, "Stat. uncertainties only");
10207     latex->SetTextSize(0.04);
10208     latex->SetNDC();
10209     latex->Draw();
10210   }
10211     
10212   canvas->SaveAs(Form("%s.eps", canvas->GetName()));
10213   canvas->SaveAs(Form("%s.png", canvas->GetName()));
10214 }
10215
10216 /*
10217 void DeltaPhiBaseLinePaperPlot(const char* fileName, const char* yieldFile)
10218 {
10219   style(2);
10220   
10221   Float_t fontSize = 0.08;
10222   Float_t titleOffset = 0.85;
10223   
10224   gStyle->SetTextSize(fontSize);
10225   gStyle->SetLabelSize(fontSize, "xy");
10226   gStyle->SetTitleSize(fontSize, "xy");
10227   gStyle->SetTitleOffset(titleOffset, "y");
10228   gStyle->SetHistLineWidth(2);
10229   gROOT->ForceStyle();
10230   
10231   loadlibs();
10232
10233   Float_t leadingPtArr[] = { 6.0, 8.0, 10.0, 15.0, 15.0 };
10234   Float_t assocPtArr[] =     { 0.5, 1.5, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
10235   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
10236
10237   Int_t i = 1;
10238   Int_t j = 3;
10239   Int_t step = 0;
10240
10241   gpTMin = assocPtArr[j] + 0.01;
10242   gpTMax = assocPtArr[j+1] - 0.01;
10243   SetupRanges(h);
10244       
10245   TString str;
10246   str.Form("%.0f GeV/#font[12]{c} < p_{t,trig} < %.0f GeV/#font[12]{c}", leadingPtArr[i], leadingPtArr[i+2]);
10247   
10248   TString str2;
10249   str2.Form("%.0f GeV/#font[12]{c} < p_{t,assoc} < %.0f GeV/#font[12]{c}", gpTMin - 0.01, gpTMax + 0.01);
10250           
10251   Float_t v2[3];
10252   TH1* hist1 = 0;
10253   TH1* hist2b = 0;
10254   
10255   GetDistAndFlow(h, 0, &hist1,  v2, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+2] - 0.01); 
10256   
10257   hist1->SetLineWidth(2);
10258
10259   canvas = new TCanvas("dphi_baseline", "dphi_baseline", 600, 840);
10260   canvas->Range(0, 0, 1, 1);
10261   
10262   pad1 = new TPad("pad1", "pad1", 0, 0.69, 1, 1);
10263   pad1->Draw();
10264   
10265   pad2 = new TPad("pad2", "pad2", 0, 0.38, 1, 0.69);
10266   pad2->Draw();
10267
10268   pad3 = new TPad("pad3", "pad3", 0, 0   , 1, 0.38);
10269   pad3->Draw();
10270   
10271   pad1->cd();
10272   gPad->SetMargin(0.15, 0.02, 0, 0.01);
10273
10274 //   hist1->GetYaxis()->SetTitleOffset(0.85);
10275   hist1->SetYTitle("1/N_{trig} dN_{assoc}/d#Delta#varphi");
10276   hist1->SetXTitle("#Delta#varphi (rad)");
10277   hist1->SetTitle("");
10278   
10279   hist1->SetLabelSize(fontSize * 0.38 / 0.31, "xy");
10280   hist1->SetTitleSize(fontSize * 0.38 / 0.31, "xy");
10281   hist1->SetTitleOffset(titleOffset / 0.38 * 0.31, "y");
10282   
10283   hist1->DrawCopy(); //->GetYaxis()->SetRangeUser(0, 0.59);
10284   
10285   //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);
10286           
10287   pad2->cd();
10288   gPad->SetMargin(0.15, 0.02, 0, 0);
10289
10290   hist1->DrawCopy()->GetYaxis()->SetRangeUser(0.381, 0.457);
10291   DrawFlow(v2[0], hist1, leadingPtArr[i], assocPtArr[j], 0, i, 0, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
10292   
10293   pad3->cd();
10294   gPad->SetMargin(0.15, 0.02, 0.2, 0);
10295   
10296   // get zero subtracted plots
10297   TFile::Open(yieldFile);
10298   hist1sub = (TH1*) gFile->Get(Form("dphi_%d_%d_%d_fit_flat", i, j, 0));
10299   hist1sub->SetYTitle("1/N_{trig} dN_{assoc}/d#Delta#varphi");
10300   hist1sub->SetXTitle("#Delta#varphi (rad)");
10301   hist1sub->SetTitle("");
10302   hist1sub->DrawCopy();
10303   
10304   hist2sub = (TH1*) gFile->Get(Form("dphi_%d_%d_%d_fit_flat", i, j, 2));
10305   hist2sub->SetMarkerStyle(24);
10306   hist2sub->SetLineColor(2);
10307   hist2sub->SetMarkerColor(2);
10308 //   hist2sub->SetMarkerSize(0.8);
10309   hist2sub->DrawCopy("SAMEP E X0");
10310   
10311   hist3sub = (TH1*) gFile->Get(Form("dphi_%d_%d_%d_fit_flat", i, j, 3));
10312   hist3sub->SetMarkerStyle(25);
10313   hist3sub->SetLineColor(4);
10314   hist3sub->SetMarkerColor(4);
10315 //   hist3sub->SetMarkerSize(0.8);
10316   hist3sub->DrawCopy("SAMEP E X0");
10317
10318   legend = new TLegend(0.4, 0.55, 0.9, 0.9);
10319   legend->SetFillColor(0);
10320   legend->SetBorderSize(0);
10321   legend->SetTextSize(0.08);
10322   legend->AddEntry(hist1sub, "Pb-Pb 0-5% centrality", "L");
10323   legend->AddEntry(hist2sub, "Pb-Pb 60-90% centrality", "P");
10324   legend->AddEntry(hist3sub, "pp", "P");
10325   legend->Draw();
10326
10327   pad1->cd();
10328   
10329   latex = new TLatex(0.47, 0.85, str);
10330   latex->SetTextSize(fontSize * 0.38 / 0.31);
10331   latex->SetNDC();
10332   latex->Draw();
10333     
10334   latex = new TLatex(0.47, 0.73, str2);
10335   latex->SetTextSize(fontSize * 0.38 / 0.31);
10336   latex->SetNDC();
10337   latex->Draw();
10338   
10339   latex = new TLatex(0.5, 0.42, "0-5% centrality");
10340   latex->SetNDC();
10341 //   latex->Draw();
10342   
10343   latex = new TLatex(0.45, 0.62, "Stat. uncertainties only");
10344   latex->SetNDC();
10345 //   latex->Draw();
10346     
10347   canvas->SaveAs(Form("%s.eps", canvas->GetName()));
10348   canvas->SaveAs(Form("%s.png", canvas->GetName()));
10349 }
10350 */
10351
10352 void DeltaPhiBaseLinePaperPlot(const char* fileName, const char* yieldFile)
10353 {
10354   style(2);
10355   
10356   Float_t fontSize = 0.08;
10357   Float_t titleOffset = 0.85;
10358   
10359   gStyle->SetTextSize(fontSize);
10360   gStyle->SetLabelSize(fontSize, "xy");
10361   gStyle->SetTitleSize(fontSize, "xy");
10362   gStyle->SetTitleOffset(titleOffset, "y");
10363   gStyle->SetHistLineWidth(2);
10364   gROOT->ForceStyle();
10365   
10366   loadlibs();
10367
10368   Float_t leadingPtArr[] = { 6.0, 8.0, 10.0, 15.0, 15.0 };
10369   Float_t assocPtArr[] =     { 0.5, 1.5, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
10370   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
10371
10372   Int_t i = 1;
10373   Int_t j = 3;
10374   Int_t step = 0;
10375
10376   gpTMin = assocPtArr[j] + 0.01;
10377   gpTMax = assocPtArr[j+1] - 0.01;
10378   SetupRanges(h);
10379       
10380   TString str;
10381   str.Form("%.0f < #font[12]{p}_{T,trig} < %.0f GeV/#font[12]{c}", leadingPtArr[i], leadingPtArr[i+2]);
10382   
10383   TString str2;
10384   str2.Form("%.0f < #font[12]{p}_{T,assoc} < %.0f GeV/#font[12]{c}", gpTMin - 0.01, gpTMax + 0.01);
10385           
10386   Float_t v2[3];
10387   TH1* hist1 = 0;
10388   TH1* hist2b = 0;
10389   
10390   GetDistAndFlow(h, 0, &hist1,  v2, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+2] - 0.01); 
10391   
10392   hist1->SetLineWidth(2);
10393
10394   canvas = new TCanvas("dphi_baseline", "dphi_baseline", 600, 840);
10395   canvas->Range(0, 0, 1, 1);
10396   
10397   pad1 = new TPad("pad1", "pad1", 0, 0.69, 1, 1);
10398   pad1->Draw();
10399   
10400   pad2 = new TPad("pad2", "pad2", 0, 0.38, 1, 0.69);
10401   pad2->Draw();
10402
10403   pad3 = new TPad("pad3", "pad3", 0, 0   , 1, 0.38);
10404   pad3->Draw();
10405   
10406   pad1->cd();
10407   gPad->SetMargin(0.15, 0.02, 0, 0.01);
10408
10409 //   hist1->GetYaxis()->SetTitleOffset(0.85);
10410   hist1->SetYTitle("");
10411   hist1->SetXTitle("#Delta#font[12]{#varphi} (rad)");
10412   hist1->SetTitle("");
10413   
10414   hist1->SetLabelSize(fontSize * 0.38 / 0.31, "xy");
10415   hist1->SetTitleSize(fontSize * 0.38 / 0.31, "xy");
10416   hist1->SetTitleOffset(titleOffset / 0.38 * 0.31, "y");
10417   
10418   hist1->DrawCopy("HISTE"); //->GetYaxis()->SetRangeUser(0, 0.59);
10419   
10420   //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);
10421           
10422   pad2->cd();
10423   gPad->SetMargin(0.15, 0.02, 0, 0);
10424
10425   hist1->SetYTitle("1/#font[12]{N}_{trig} d#font[12]{N}_{assoc}/d#Delta#font[12]{#varphi} (rad^{-1})");
10426   hist1->DrawCopy("HISTE")->GetYaxis()->SetRangeUser(0.381, 0.457);
10427   DrawFlow(v2[0], hist1, leadingPtArr[i], assocPtArr[j], 0, i, 0, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
10428   
10429   pad3->cd();
10430   gPad->SetMargin(0.15, 0.02, 0.2, 0);
10431   
10432   // get zero subtracted plots
10433   TFile::Open(yieldFile);
10434
10435   hist1sub = (TH1*) gFile->Get(Form("dphi_%d_%d_%d_fit_flat", i, j, 0));
10436   hist1sub->SetYTitle("");
10437   hist1sub->SetXTitle("#Delta#varphi (rad)");
10438   hist1sub->SetTitle("");
10439 //   hist1sub->SetMarkerStyle(25);
10440 //   hist1sub->SetLineColor(4);
10441 //   hist1sub->SetMarkerColor(4);
10442   hist1sub->SetMaximum(0.79);
10443   hist1sub->DrawCopy("HIST E");
10444   
10445   hist3sub = (TH1*) gFile->Get(Form("dphi_%d_%d_%d_fit_flat", i, j, 3));
10446 //   hist3sub->SetFillColor(4); 
10447 //   hist3sub->SetFillStyle(3354);
10448 //   hist3sub->SetLineWidth(0);
10449 //   hist3sub->SetLineColor(0);
10450   hist3sub->SetMarkerStyle(25);
10451   hist3sub->SetLineColor(4);
10452   hist3sub->SetMarkerColor(4);
10453   hist3sub->DrawCopy("SAME E X0");
10454
10455   hist1sub->DrawCopy("SAME HIST E");
10456   
10457   hist2sub = (TH1*) gFile->Get(Form("dphi_%d_%d_%d_fit_flat", i, j, 2));
10458   hist2sub->SetMarkerStyle(24);
10459   hist2sub->SetLineColor(2);
10460   hist2sub->SetMarkerColor(2);
10461   hist2sub->DrawCopy("SAMEP E X0");
10462   
10463   legend = new TLegend(0.4, 0.45, 0.9, 0.8);
10464   legend->SetFillColor(0);
10465   legend->SetBorderSize(0);
10466   legend->SetTextSize(fontSize);
10467   legend->AddEntry(hist1sub, "Pb-Pb 0-5% centrality", "L");
10468   legend->AddEntry(hist2sub, "Pb-Pb 60-90% centrality", "P");
10469   legend->AddEntry(hist3sub, "pp", "P");
10470   legend->Draw();
10471
10472   pad1->cd();
10473   
10474   latex = new TLatex(0.59, 0.70, str);
10475   latex->SetTextSize(fontSize * 0.38 / 0.31);
10476   latex->SetNDC();
10477   latex->Draw();
10478     
10479   latex = new TLatex(0.59, 0.58, str2);
10480   latex->SetTextSize(fontSize * 0.38 / 0.31);
10481   latex->SetNDC();
10482   latex->Draw();
10483   
10484   latex = new TLatex(0.59, 0.46, "#sqrt{#font[12]{s}_{NN}} = 2.76 TeV");
10485   latex->SetTextSize(fontSize * 0.38 / 0.31);
10486   latex->SetNDC();
10487   latex->Draw();
10488
10489   latex = new TLatex(0.43, 0.90, "a) not background subtracted");
10490   latex->SetTextSize(fontSize * 0.38 / 0.31);
10491   latex->SetNDC();
10492   latex->Draw();
10493
10494   latex = new TLatex(0.5, 0.42, "0-5% centrality");
10495   latex->SetNDC();
10496 //   latex->Draw();
10497   
10498   latex = new TLatex(0.45, 0.62, "Stat. uncertainties only");
10499   latex->SetNDC();
10500 //   latex->Draw();
10501
10502   pad2->cd();
10503
10504   latex = new TLatex(0.43, 0.90, "b) zoomed");
10505   latex->SetTextSize(fontSize * 0.38 / 0.31);
10506   latex->SetNDC();
10507   latex->Draw();
10508   
10509   pad3->cd();
10510
10511   latex = new TLatex(0.43, 0.90, "c) background subtracted");
10512   latex->SetNDC();
10513   latex->Draw();
10514   
10515     
10516   canvas->SaveAs(Form("%s.eps", canvas->GetName()));
10517   canvas->SaveAs(Form("%s.png", canvas->GetName()));
10518 }
10519
10520
10521 void DeltaPhiRidgePreliminary(const char* fileName)
10522 {
10523   style();
10524   
10525   loadlibs();
10526
10527   Float_t leadingPtArr[] = { 2.0, 2.0, 3.0, 4.0, 10.0, 20.0, 40.0 };
10528   Float_t assocPtArr[] =   { 1.0, 2.0, 3.0, 6.0, 10.0, 20.0, 40.0 };
10529 //   Float_t leadingPtArr[] = { 6.0, 8.0, 10.0, 15.0, 15.0 };
10530 //   Float_t assocPtArr[] =     { 0.5, 1.5, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
10531   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName, 0, kFALSE);
10532   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
10533
10534 //   Int_t i = 1;
10535 //   Int_t j = 3;
10536   Int_t i = 0;
10537   Int_t j = 0;
10538   Int_t step = 6;
10539
10540   gpTMin = assocPtArr[j] + 0.01;
10541   gpTMax = assocPtArr[j+1] - 0.01;
10542   SetupRanges(h);
10543   SetupRanges(hMixed);
10544       
10545   TString str;
10546   str.Form("%.1f < p_{T,trig} < %.1f", leadingPtArr[i], leadingPtArr[i+2]);
10547   
10548   TString str2;
10549   str2.Form("%.1f < p_{T,assoc} < %.1f", gpTMin - 0.01, gpTMax + 0.01);
10550           
10551   Float_t v2[3];
10552   TH1* hist1 = 0;
10553   TH1* hist2b = 0;
10554   TH1* hist1Peak = 0;
10555   TH1* hist2bPeak = 0;
10556   TH1* hist1Ridge = 0;
10557   TH1* hist2bRidge = 0;
10558   
10559   TH1* hist2d = 0;
10560   TH1* hist2dMixed = 0;
10561   
10562 //   GetDistAndFlow(h, 0, &hist2d,  v2, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+2] - 0.01, 1); 
10563 //   GetDistAndFlow(hMixed, 0, &hist2dMixed,  v2, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+2] - 0.01, 1); 
10564 //   new TCanvas;
10565 //   //hist2d->Divide(hist2dMixed);
10566 //   hist2dMixed->Draw("SURF1");
10567   
10568   GetDistAndFlow(h, hMixed, &hist1,  0, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+2] - 0.01); 
10569 //   GetDistAndFlow(h, 0, &hist2b, v2[2], step, 60, 90, leadingPtArr[i] + 0.01, leadingPtArr[i+2] - 0.01); 
10570   GetDistAndFlow(h, hMixed, &hist1Peak,  0, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+2] - 0.01, 10); 
10571
10572   GetDistAndFlow(h, hMixed, &hist1Ridge,  0, step, 0,  5,  leadingPtArr[i] + 0.01, leadingPtArr[i+2] - 0.01, 11); 
10573
10574   // TODO normalize
10575
10576   canvas = new TCanvas("dphi_baseline", "dphi_baseline", 800, 800);
10577   canvas->Divide(2, 2);
10578   
10579   canvas->cd(1);
10580   gPad->SetLeftMargin(0.20);
10581   
10582   hist1->GetYaxis()->SetTitleOffset(1.9);
10583   hist1->SetYTitle("1/N_{trig} dN/dp_{T,assoc}");
10584   hist1->SetTitle("");
10585   hist1->DrawCopy();
10586   
10587   hist1Peak->SetLineColor(2);
10588   hist1Peak->DrawCopy("SAME");
10589   
10590   hist1Ridge->SetLineColor(4);
10591   hist1Ridge->DrawCopy("SAME");
10592   
10593 //   hist1Peak->Add(hist1Ridge);
10594 //   hist1Peak->DrawCopy("SAME")->SetLineColor(3);
10595   
10596   return;
10597   
10598   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);
10599           
10600   latex = new TLatex(0.65, 0.84, str);
10601   latex->SetNDC();
10602   latex->SetTextSize(0.04);
10603   latex->Draw();
10604   
10605   latex = new TLatex(0.65, 0.90, str2);
10606   latex->SetNDC();
10607   latex->SetTextSize(0.04);
10608   latex->Draw();
10609
10610   latex = new TLatex(0.84, 0.78, "0-5%");
10611   latex->SetNDC();
10612   latex->SetTextSize(0.04);
10613   latex->Draw();
10614   
10615   canvas->cd(2);
10616   gPad->SetLeftMargin(0.20);
10617   
10618   hist1->DrawCopy()->GetYaxis()->SetRangeUser(0.18, 0.28);
10619   DrawFlow(v2[0], hist1, leadingPtArr[i], assocPtArr[j], 0, i, 0, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
10620   
10621   latex->Draw();
10622   
10623   latex = new TLatex(0.5, 0.90, "ALICE preliminary");
10624   latex->SetTextSize(0.04);
10625   latex->SetNDC();
10626   latex->Draw();
10627
10628   latex = new TLatex(0.5, 0.84, "Statistical uncertainties only");
10629   latex->SetTextSize(0.04);
10630   latex->SetNDC();
10631   latex->Draw();
10632   
10633   canvas->cd(3);
10634   gPad->SetLeftMargin(0.20);
10635   
10636   hist2b->GetYaxis()->SetTitleOffset(1.9);
10637   hist2b->SetYTitle("1/N_{trig} dN/dp_{T,assoc}");
10638   hist2b->SetTitle("");
10639   hist2b->DrawCopy();
10640            
10641   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);
10642   
10643   latex = new TLatex(0.84, 0.78, "60-90%");
10644   latex->SetNDC();
10645   latex->SetTextSize(0.04);
10646   latex->Draw();
10647   
10648   canvas->cd(4);
10649   gPad->SetLeftMargin(0.20);
10650       
10651   hist2b->DrawCopy()->GetYaxis()->SetRangeUser(0.01, 0.1);
10652   DrawFlow(v2[2], hist2b, leadingPtArr[i], assocPtArr[j], 0, i, 2, 0, (assocPtArr[j] + assocPtArr[j+1]) / 2, (assocPtArr[j+1] - assocPtArr[j]) / 2);
10653       
10654   latex->Draw();
10655   
10656   canvas->SaveAs(Form("%s.eps", canvas->GetName()));
10657   canvas->SaveAs(Form("%s.png", canvas->GetName()));
10658 }
10659
10660 void MCScalingFactor(Int_t caseId)
10661 {
10662   // 900 GeV
10663   // x[5]=5, y[5]=0.813743, ex[5]=0, ey[5]=0.158446
10664   // x[5]=5, y[5]=1.09804, ex[5]=0, ey[5]=0.265434
10665   // 7 TeV
10666   // x[5]=5, y[5]=1.02276, ex[5]=0, ey[5]=0.0199991
10667   // x[5]=5, y[5]=0.870247, ex[5]=0, ey[5]=0.0294444
10668   
10669   Float_t factors[] = { 0.814, 1.098, 1.022, 0.870 };
10670   Float_t errors[]  = { 0.158, 0.265, 0.020, 0.029 };
10671   
10672   Float_t avgs[2];
10673   
10674   for (Int_t i=0; i<2; i++)
10675   {
10676     switch (caseId)
10677     {
10678       case 0:
10679         avgs[i] = factors[2*i] / errors[2*i] / errors[2*i] + factors[2*i+1] / errors[2*i+1] / errors[2*i+1];
10680         avgs[i] /= 1. / errors[2*i] / errors[2*i] + 1. / errors[2*i+1] / errors[2*i+1];
10681         break;
10682         
10683       case 1:
10684         avgs[i] = factors[2*i];
10685         break;
10686     
10687       case 2:
10688         avgs[i] = factors[2*i+1];
10689         break;
10690     
10691       case 3:
10692         avgs[0] = factors[0];
10693         avgs[1] = factors[3];
10694         break;
10695     
10696       case 4:
10697         avgs[0] = factors[1];
10698         avgs[1] = factors[2];
10699         break;
10700     }
10701   }
10702   
10703   Float_t a = avgs[0];
10704   Float_t b = avgs[1];
10705   
10706   Printf("%f %f", a, b);
10707   
10708   Float_t linEx = a + (b-a)/(7.-0.9) * (2.76-0.9);
10709   Float_t logEx = a + (b-a)/(log(7.)-log(0.9)) * (log(2.76)-log(0.9));
10710   
10711   Printf("%f %f", linEx, logEx);
10712 }
10713   
10714 void CompareDeltaPhi(const char* fileName1, const char* fileName2, Int_t centralityID, const char* dist = "_fit_flat", Bool_t reduced = kFALSE)
10715 {
10716   firstFile = TFile::Open(fileName1);
10717   secondFile = TFile::Open(fileName2);
10718
10719   Int_t maxLeadingPt = 2;
10720   Int_t maxAssocPt = 7;
10721   Int_t minLeadingPt = 0;
10722   Int_t minAssocPt = 0;
10723   
10724   if (reduced)
10725   {
10726     maxLeadingPt = 2;
10727     maxAssocPt = 5;
10728     minLeadingPt = 1;
10729     minAssocPt = 2;
10730   }
10731   
10732   TCanvas* canvas = new TCanvas(Form("%s %s", fileName1, fileName2 ? fileName2 : ""), Form("%s %s", fileName1, fileName2 ? fileName2 : ""), 1000, 700);
10733   canvas->Divide(maxAssocPt-minAssocPt, maxLeadingPt-minLeadingPt);
10734   
10735   for (Int_t i=minLeadingPt; i<maxLeadingPt; i++)
10736     for (Int_t j=minAssocPt; j<maxAssocPt; j++)
10737     {
10738       Printf("%d %d", i, j);
10739     
10740       canvas->cd(j+1-minAssocPt + (i-minLeadingPt) * maxAssocPt);
10741       gPad->SetLeftMargin(0.15);
10742       gPad->SetBottomMargin(0.2);
10743       //gPad->SetTopMargin(0.01);
10744       gPad->SetRightMargin(0.01);
10745       
10746       hist1 = (TH1*) firstFile->Get(Form("dphi_%d_%d_%d%s", i, j, centralityID, dist));
10747       hist2 = (TH1*) secondFile->Get(Form("dphi_%d_%d_%d%s", i, j, centralityID, dist));
10748       
10749       if (!hist1)
10750         continue;
10751       
10752 /*      hist1->Rebin(2); hist1->Scale(0.5); 
10753       hist2->Rebin(2); hist2->Scale(0.5); */
10754 //       hist1->Scale(1.6);
10755         
10756       hist1->SetLineColor(1);
10757       hist2->SetLineColor(2);
10758       
10759       hist1->DrawCopy()->GetYaxis()->SetRangeUser(hist1->GetMinimum(), hist1->GetMaximum() * 1.2);
10760       hist2->DrawCopy("SAME");
10761       
10762 /*      if (strlen(dist) == 0)
10763         Printf("chi2 test: %f", hist1->Chi2Test(hist2, "UU NORM CHI2/NDF"));*/
10764       
10765       //DrawRatio(hist1, hist2, hist1->GetTitle());
10766       
10767       //return;
10768     }
10769 }
10770   
10771 TH1* MACHCone(const char* fileName, Int_t centrality, const char* drawingOption, Bool_t plotContributions, Int_t twoD, TF1** flowFuncP = 0)
10772 {
10773   if (0)
10774   {
10775     TFile::Open("machcone_input.root");
10776     
10777     switch (centrality)
10778     {
10779       case 0:
10780         hist = (TH1*) gFile->Get("dphi_0_0_0");
10781         break;
10782       
10783       case 1:
10784         hist = (TH1*) gFile->Get("dphi_1_1_0");
10785         break;
10786         
10787       case 2:
10788         hist = (TH1*) gFile->Get("dphi_0_0_2");
10789         break;
10790     
10791       case 3:
10792         hist = (TH1*) gFile->Get("dphi_1_1_2");
10793         break;
10794     }
10795   }
10796   else
10797   {
10798     loadlibs();
10799     
10800     AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
10801     AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
10802     
10803     Float_t leadingPtArr[] = { 2.0, 3.0, 4.0, 10.0, 20.0, 40.0 };
10804     Float_t assocPtArr[] =   { 1.0, 2.0, 3.0, 6.0, 10.0, 20.0, 40.0 };
10805 //     Float_t assocPtArr[] =   { 2.0, 3.0, 6.0, 10.0, 20.0, 40.0 };
10806   
10807     Int_t i = centrality % 2;
10808     Int_t step = 6;
10809     
10810     Int_t j = 0;
10811     
10812     gpTMin = assocPtArr[i] + 0.01;
10813     gpTMax = assocPtArr[i+1] - 0.01;
10814     
10815     Int_t centralityBegin = 0;
10816     Int_t centralityEnd = 1;
10817     
10818     if (centrality >= 2)
10819     {
10820       centralityBegin = 30;
10821       centralityEnd = 40;
10822     }
10823       
10824     SetupRanges(h);
10825     SetupRanges(hMixed);
10826     
10827     TH1* hist = 0;
10828     Float_t vn[5];
10829     vn[0] = 0;
10830     vn[1] = 0;
10831     vn[2] = 0;
10832     vn[3] = 0;
10833     vn[4] = 0;
10834     
10835     Bool_t scaleToPairs = 0;
10836     
10837     GetDistAndFlow(h, hMixed, &hist, 0, step, centralityBegin, centralityEnd, leadingPtArr[j] + 0.01, leadingPtArr[j+1] - 0.01, twoD, kTRUE, vn, scaleToPairs); 
10838     if (scaleToPairs && twoD == 11)
10839       hist->Scale(2);  
10840     
10841     Printf("%f %f %f", vn[2], vn[3], vn[4]);
10842     
10843     // mirror delta phi to improve stats
10844     if (1)
10845     {
10846       for (Int_t bin=1; bin<=hist->GetNbinsX(); bin++)
10847       {
10848         if (hist->GetBinCenter(bin) < 0 || hist->GetBinCenter(bin) > TMath::Pi())
10849         {
10850           if (hist->GetBinCenter(bin) < 0)
10851             Int_t bin2 = hist->FindBin(-1.0 * hist->GetBinCenter(bin));
10852           else
10853             Int_t bin2 = hist->FindBin(TMath::TwoPi() - hist->GetBinCenter(bin));
10854           
10855           Float_t combValue = hist->GetBinContent(bin) / hist->GetBinError(bin) / hist->GetBinError(bin) + hist->GetBinContent(bin2) / hist->GetBinError(bin2) / hist->GetBinError(bin2);
10856           
10857           Float_t weight = 1. / hist->GetBinError(bin) / hist->GetBinError(bin) + 1. / hist->GetBinError(bin2) / hist->GetBinError(bin2);
10858           combValue /= weight;
10859           
10860           Float_t combError = TMath::Sqrt(1.0 / weight);
10861           
10862           hist->SetBinContent(bin2, combValue);
10863           hist->SetBinError(bin2, combError);
10864
10865           hist->SetBinContent(bin, combValue);
10866           hist->SetBinError(bin, combError);
10867           
10868           Printf("%d %d %f %f", bin, bin2, combValue, combError);
10869         }
10870       }
10871     }
10872   }
10873   
10874   TString str(hist->GetTitle());
10875   str.ReplaceAll(" - ", "#");
10876   tokens = str.Tokenize("#");
10877   hist->SetTitle("");
10878   
10879   hist->SetLineColor(1);
10880   hist->SetYTitle("1/N_{trig} dN_{assoc}/d#Delta#phi");
10881   hist->SetXTitle("#Delta#phi (rad)");
10882   hist = (TH1*) hist->Clone();
10883   if (!drawingOption)
10884     return hist;
10885   
10886   hist = hist->DrawCopy(drawingOption);
10887   
10888   for (Int_t i=0; i<tokens->GetEntries()-1; i++)
10889   {
10890     if (centrality == 1)
10891       latex = new TLatex(0.6, 0.9 - i*0.05 - gPad->GetTopMargin(), tokens->At(i)->GetName());
10892     else
10893       latex = new TLatex(0.6, 0.12 - i*0.05, tokens->At(i)->GetName());
10894     
10895     latex->SetNDC();
10896     latex->SetTextSize(0.04);
10897     latex->Draw();
10898   }
10899   
10900   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());
10901   //flowFunc->SetLineWidth(1);
10902   flowFunc->SetLineColor(2);
10903   flowFunc->SetLineStyle(2);
10904   for (Int_t i=0; i<4; i++)
10905     flowFunc->FixParameter(i+1, vn[i+1]);
10906   //flowFunc->SetParameter(0, 84.95); flowFunc->DrawClone("SAME");
10907   
10908   //flowFunc->SetParameter(0, 85.4); flowFunc->DrawClone("SAME");
10909   //flowFunc->SetParameter(0, 85.6); flowFunc->DrawClone("SAME");
10910   
10911 //   hist->Fit(flowFunc, "", "SAME", 1.8, 4.5);
10912   hist->Fit(flowFunc, "N", "", -0.5 * TMath::Pi(), 1.5 * TMath::Pi());
10913   hist->GetYaxis()->SetRangeUser(hist->GetMinimum() * 0.95, hist->GetMaximum() * 1.05);
10914   flowFunc->SetRange(-0.5 * TMath::Pi(), 1.5 * TMath::Pi());
10915   flowFunc->Draw("SAME");
10916   
10917   if (flowFuncP)
10918     *flowFuncP = flowFunc;
10919   
10920   //hist->GetYaxis()->SetRangeUser(84, 89);
10921   //flowFunc->SetParameter(4, 1);
10922   
10923   Float_t chi2 = 0;
10924   Int_t n=0;
10925   for (Int_t bin=hist->FindBin(1.8); bin<=hist->FindBin(4.5); bin++)
10926   {
10927     chi2 += TMath::Power((hist->GetBinContent(bin) - flowFunc->Eval(hist->GetBinCenter(bin))) / hist->GetBinError(bin), 2);
10928     n++;
10929     //Printf("%f", TMath::Power((hist->GetBinContent(bin) - flowFunc->Eval(hist->GetBinCenter(bin))) / hist->GetBinError(bin), 2));
10930   }
10931     
10932   chi2 /= n;
10933   
10934   Printf("chi2/ndf = %f", chi2);
10935   
10936   if (!plotContributions)
10937     return hist;
10938   
10939   for (Int_t n=1; n<=5; n++)
10940   {
10941     flowFuncPart = new TF1("flowFuncPart", "[0] * (1+2*[1]*cos([2]*x))", -0.5 * TMath::Pi(), 1.5 * TMath::Pi());
10942     flowFuncPart->SetParameters(flowFunc->GetParameter(0), vn[n-1], n);
10943     flowFuncPart->SetLineWidth(1);
10944     flowFuncPart->SetLineStyle(n);
10945     flowFuncPart->Draw("SAME");
10946   }
10947   
10948   return hist;
10949 }
10950
10951 void MACHConeAll(const char* fileName)
10952 {
10953   loadlibs();
10954
10955   SetFlowStyle();
10956
10957   c = new TCanvas("c", "c", 300, 800);
10958   c->SetTopMargin(0);
10959   c->SetLeftMargin(0);
10960   c->SetRightMargin(0);
10961   c->SetBottomMargin(0);
10962   c->Divide(1, 2, 0, 0);
10963   
10964   Float_t rangesMin[] = { 136.1, 17.45, 18, 2.4 };
10965   Float_t rangesMax[] = { 139.4, 18.95, 23.5, 3.6 };
10966   
10967   for (Int_t i=0; i<2; i++)
10968   {
10969     c->cd(i+1);
10970
10971     gPad->SetRightMargin(0.05);
10972     gPad->SetLeftMargin(0.20);
10973     gPad->SetTopMargin(0.15);
10974     gPad->SetBottomMargin(0.15);
10975
10976     if (i == 0)
10977     {
10978       gPad->SetBottomMargin(0.01);
10979     }
10980     else if (i == 1)
10981     {
10982       gPad->SetTopMargin(0.01);
10983       gPad->SetBottomMargin(0.7);
10984     }
10985   }
10986
10987   Int_t i = 0;
10988
10989   TF1* flowFunc = 0;
10990   
10991   c->cd(i+1);
10992 //   hist = MACHCone(fileName, i, "", kTRUE, 0, &flowFunc);
10993   hist = (TH1*) MACHCone(fileName, i, 0, kFALSE, 0)->Clone("hist");
10994   hist->GetYaxis()->SetRangeUser(rangesMin[i], rangesMax[i]);
10995   hist->GetYaxis()->SetTitleOffset(1.7);
10996   hist->Draw();
10997 //     continue;
10998   
10999   c->cd(i+1);
11000   //c->cd(i+2);
11001 //   hist2 = MACHCone(fileName, i, 0, kFALSE, 11);
11002   hist2 = MACHCone(fileName, i, "SAME", kTRUE, 11, &flowFunc);
11003   //hist2->GetYaxis()->SetRangeUser(rangesMin[i], rangesMax[i]);
11004 //   hist2->Scale(2);
11005   hist2->SetLineColor(4);
11006   //hist2->Draw("SAME");
11007 //    return;
11008
11009   // sample flowFunc with same binning
11010   flowFuncHist = (TH1*) hist->Clone("flowFuncHist");
11011   flowFuncHist->Reset();
11012   
11013   for (Int_t i=1; i<=flowFuncHist->GetNbinsX(); i++)
11014   {
11015     flowFuncHist->SetBinContent(i, flowFunc->Integral(flowFuncHist->GetXaxis()->GetBinLowEdge(i), flowFuncHist->GetXaxis()->GetBinUpEdge(i)));
11016     flowFuncHist->SetBinError(i, 0);
11017   }
11018   
11019   i = 0;
11020   
11021   flowFuncHist->Scale(1.0 / flowFuncHist->GetBinWidth(1));
11022   
11023 //   new TCanvas;
11024 //   flowFuncHist->Draw();
11025 //   flowFunc->Draw("SAME");
11026 //   return;
11027
11028   // residuals
11029   residuals = (TH1*) hist->Clone("res1");
11030   residuals->SetYTitle("Residuals");
11031   residuals->Divide(flowFuncHist);
11032   c->cd(i+2);
11033   residuals->Draw();
11034   residuals->GetYaxis()->SetNdivisions(505);
11035   residuals->GetYaxis()->SetRangeUser(0.995, 1.005);
11036
11037   residuals = (TH1*) hist2->Clone("res2");
11038   residuals->Divide(flowFuncHist);
11039   c->cd(i+2);
11040   residuals->SetLineColor(4);
11041   residuals->Draw("SAME");
11042   
11043   gPad->SetGridy();
11044
11045   if (i == 0)
11046   {
11047     legend = new TLegend(0.43, 0.66, 0.91, 0.82);
11048     legend->SetFillColor(0);
11049     legend->SetTextSize(0.034);
11050     legend->SetTextAlign(22);
11051     
11052     legend->SetHeader("Centrality 0-1%");
11053     legend->AddEntry(hist, "|#eta| < 0.8 & All #Delta#eta", "L");
11054     legend->AddEntry(hist2, "|#eta| < 0.8 & |#Delta#eta| > 0.8 (2x)", "L");
11055     
11056     c->cd(i+1);
11057     legend->Draw();
11058   }
11059   
11060   c->SaveAs(Form("machcone_%d.png", 0));
11061   c->SaveAs(Form("machcone_%d.eps", 0));
11062   c->SaveAs(Form("machcone_%d.C", 0));
11063   
11064   return;
11065   
11066   c->cd(1);
11067   MACHCone(3, "", kTRUE)->SetTitle("");
11068   
11069   c->cd(2);
11070   hist1 = MACHCone(0, "", kFALSE);
11071   hist2 = MACHCone(1, "SAME", kFALSE);
11072   hist3 = MACHCone(2, "SAME", kFALSE);
11073   
11074   hist1->SetTitle("");
11075   hist1->GetYaxis()->SetRangeUser(1, 7);
11076 }
11077   
11078 void SetFlowStyle()
11079 {
11080  // Set style which will affect all plots.
11081  
11082  gStyle->Reset();
11083  // gStyle->SetOptitle(0);
11084  // gStyle->SetOptStat(0);
11085  //gStyle->SetOptDate(1);
11086  // gStyle->SetPalette(8,0);  // (1,0)
11087  gStyle->SetPalette(1);  // (1,0)
11088  gStyle->SetDrawBorder(0);
11089  // gStyle->SetFillColor(0);  // kills palete ???
11090  gStyle->SetCanvasColor(0);
11091  gStyle->SetPadColor(0);
11092  // gStyle->SetFillColor(0); // otherwize it affects Fill colors later
11093  gStyle->SetFrameFillColor(0);
11094  gStyle->SetCanvasBorderMode(0);
11095  gStyle->SetFrameLineWidth(2);
11096  // gStyle->SetFrameFillStyle(4000);
11097  gStyle->SetPadBorderMode(0);
11098  gStyle->SetPadTickX(1);
11099  gStyle->SetPadTickY(1);
11100  gStyle->SetPadBottomMargin(0.15);
11101  gStyle->SetPadLeftMargin(0.15);
11102  gStyle->SetHistLineWidth(2);
11103  gStyle->SetFuncWidth(2);
11104  gStyle->SetLineWidth(2);
11105  gStyle->SetLabelSize(0.05,"xyz");
11106  gStyle->SetLabelOffset(0.01,"y");
11107  gStyle->SetLabelColor(kBlack,"xyz");
11108  gStyle->SetTitleSize(0.06,"xyz");
11109  gStyle->SetTitleOffset(1.3,"y");
11110  gStyle->SetTitleFillColor(0);
11111  gStyle->SetLineWidth(2);  
11112  gStyle->SetHistLineColor(1);
11113  gStyle->SetTextColor(1);
11114  gStyle->SetTitleTextColor(1);
11115  TGaxis::SetMaxDigits(4);
11116  gStyle->SetOptStat(0); // removes stat. box from all histos
11117  gROOT->ForceStyle();
11118
11119 } // end of void SetFlowStyle()
11120
11121 void PlotPtDistributionsSubtracted(const char* fileName1, Int_t centrBegin = 1, Int_t centrEnd = 6, Int_t fit = 0)
11122 {
11123   loadlibs();
11124
11125   Int_t nCentralityBins = 5;
11126   Int_t centralityBins[] = { 1, 7, 9, 11, 13, 16 };
11127   
11128   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName1);
11129     
11130   TCanvas* canvas = new TCanvas("Pt", "Pt", 1000, 1000);
11131   canvas->Divide(2, 2);
11132   
11133   TLegend* legend = new TLegend(0.3, 0.8, 0.99, 0.99);
11134   legend->SetFillColor(0);
11135   
11136   Int_t colors[] = { 1, 2, 4, 6, 3, 5 };
11137   Int_t markers[] = { 20, 21, 22, 23, 24, 25 };
11138   
11139   Double_t ptMin = 10.01;
11140   Double_t ptMax = 39.99;
11141     
11142   TString str;
11143   str.Form("%.1f < p_{T,trig} < %.1f", ptMin - 0.01, ptMax + 0.01);
11144   
11145   canvas->cd(1);
11146   gPad->SetLeftMargin(0.15);
11147   gPad->SetBottomMargin(0.2);
11148   gPad->SetTopMargin(0.01);
11149   gPad->SetRightMargin(0.01);
11150   gPad->SetLogy();
11151   gPad->SetLogx();
11152   gPad->SetGridx();
11153   gPad->SetGridy();
11154   
11155   TH2F* dummy = new TH2F("dummy", "", 100, 1, 40, 100, 1e-5, 1e3);
11156   dummy->SetStats(kFALSE);
11157   dummy->SetXTitle("p_{T,assoc}");
11158   dummy->SetYTitle("1/N_{trig} dN/dp_{T,assoc}");
11159   dummy->GetYaxis()->SetTitleOffset(1);
11160   Prepare1DPlot(dummy);
11161
11162   dummy->GetXaxis()->SetLabelSize(0.05);
11163   dummy->GetYaxis()->SetLabelSize(0.05);
11164   dummy->GetXaxis()->SetTitleSize(0.05);
11165   dummy->GetYaxis()->SetTitleSize(0.05);
11166   dummy->DrawCopy();
11167   
11168   canvas->cd(2);
11169   gPad->SetLeftMargin(0.15);
11170   gPad->SetBottomMargin(0.2);
11171   gPad->SetTopMargin(0.01);
11172   gPad->SetRightMargin(0.01);
11173   gPad->SetLogy();
11174   gPad->SetLogx();
11175   gPad->SetGridx();
11176   gPad->SetGridy();
11177   dummy->DrawCopy();
11178   
11179   canvas->cd(3);
11180   gPad->SetLeftMargin(0.15);
11181   gPad->SetBottomMargin(0.2);
11182   gPad->SetTopMargin(0.01);
11183   gPad->SetRightMargin(0.01);
11184   gPad->SetLogx();
11185   gPad->SetGridx();
11186   gPad->SetGridy();
11187   
11188   dummy = new TH2F("dummy2", "", 100, 1, 40, 100, 0, 100);
11189   dummy->SetStats(kFALSE);
11190   dummy->SetXTitle("p_{T,assoc}");
11191   dummy->SetYTitle("Ratio: Distribution / Inclusive");
11192   dummy->GetYaxis()->SetTitleOffset(1);
11193   Prepare1DPlot(dummy);
11194   dummy->GetXaxis()->SetLabelSize(0.05);
11195   dummy->GetYaxis()->SetLabelSize(0.05);
11196   dummy->GetXaxis()->SetTitleSize(0.05);
11197   dummy->GetYaxis()->SetTitleSize(0.05);
11198   dummy->DrawCopy();
11199   
11200   canvas->cd(4);
11201   gPad->SetLeftMargin(0.15);
11202   gPad->SetBottomMargin(0.2);
11203   gPad->SetTopMargin(0.01);
11204   gPad->SetRightMargin(0.01);
11205   gPad->SetLogx();
11206   gPad->SetGridx();
11207   gPad->SetGridy();
11208   dummy->DrawCopy();
11209   
11210   
11211   // see GetAcceptanceScalingFactor
11212   Float_t scalingFactor = 0.328396; // 0.8
11213   //Float_t scalingFactor = 0.433268; // 0.7
11214   //Float_t scalingFactor = 0.895593; // 0.5 --> 1.6
11215       
11216   Float_t phiRange[] = { 0, TMath::Pi() / 2, TMath::Pi() };
11217   const char* phiLabels[] = { "Towards", "Transverse", "Away" };
11218   
11219   //Float_t phiSizeTowards = TMath::Pi() / 3;
11220   Float_t phiSizeTowards = 0.75;
11221   //Float_t etaLimit = 0.5;
11222   Float_t etaLimit = 0.8;
11223   
11224   towardsCentralEta = h->GetUEHist(2)->GetPtHist(6, 0, ptMin, ptMax, centrBegin, centrEnd, phiRange[0] - phiSizeTowards, phiRange[0] + phiSizeTowards, -etaLimit + 0.01, etaLimit - 0.01);
11225   towardsSideEta1 = h->GetUEHist(2)->GetPtHist(6, 0, ptMin, ptMax, centrBegin, centrEnd, phiRange[0] - phiSizeTowards, phiRange[0] + phiSizeTowards, -1.59, -etaLimit - 0.01);
11226   TH1* towardsSideEta2 = h->GetUEHist(2)->GetPtHist(6, 0, ptMin, ptMax, centrBegin, centrEnd, phiRange[0] - phiSizeTowards, phiRange[0] + phiSizeTowards, etaLimit + 0.01, 1.59);
11227   towardsSideEta1->Add(towardsSideEta2); // TODO can be done smarter? what about the errors?
11228
11229   Prepare1DPlot(towardsSideEta1);
11230   Prepare1DPlot(towardsCentralEta);
11231   
11232   towardsCentralEta->SetLineColor(colors[0]);
11233   towardsSideEta1->SetLineColor(colors[3]);
11234   //towardsSideEta1->SetLineStyle(2);
11235
11236   legend->AddEntry(towardsCentralEta->Clone(), Form("Jet, %s: |#Delta#eta| < 0.8, #phi ~ %.1f", phiLabels[0], phiRange[0]));
11237   legend->AddEntry(towardsSideEta1->Clone(), Form("Ridge, %s: 0.8 < |#Delta#eta| < 1.6, #phi ~ %.1f", phiLabels[0], phiRange[0]));
11238   
11239   // TODO update when data with new phi binning is available
11240   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);
11241   /*
11242   transverse2 = h->GetUEHist(2)->GetPtHist(6, 0, ptMin, ptMax, centrBegin, centrEnd, -0.5 * TMath::Pi(), -TMath::Pi() / 3, -1.59, 1.59, kTRUE);
11243   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);
11244   transverse->Add(transverse2);
11245   transverse->Add(transverse3);
11246   transverse->Scale(1.0 / (2.0 / 3 * TMath::Pi()));
11247   */
11248     
11249   //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);
11250   //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);
11251   //transverseSideEta1->Add(transverseSideEta2); // TODO can be done smarter? what about the errors?
11252   
11253   transverse->SetLineColor(colors[2]);
11254   //transverseSideEta1->SetLineColor(colors[2]);
11255   //transverseSideEta1->SetLineStyle(2);
11256
11257   Prepare1DPlot(transverse);
11258   //Prepare1DPlot(transverseSideEta1);
11259   legend->AddEntry(transverse->Clone(), Form("%s: |#Delta#eta| < 1.6, #phi ~ %.1f", phiLabels[1], phiRange[1]));
11260   //legend->AddEntry(transverseSideEta1->Clone(), Form("%s: 0.8 < |#Delta #eta| < 1.6, #phi ~ %.1f", phiLabels[1], phiRange[1]));
11261   
11262   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);
11263
11264   /*
11265   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);
11266   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);
11267   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);
11268   away3->Add(away4);
11269   */
11270   
11271   away->SetLineColor(colors[1]);
11272   //away3->SetLineColor(colors[1]);
11273   //away3->SetLineStyle(2);
11274   
11275   Prepare1DPlot(away);
11276   legend->AddEntry(away->Clone(), Form("%s: |#Delta#eta| < 1.6, #phi ~ %.1f", phiLabels[2], phiRange[2]));
11277   
11278   //inclusive = h->GetUEHist(2)->GetPtHist(6, 0, ptMin, ptMax, centrBegin, centrEnd, -0.5 * TMath::Pi(), 1.5 * TMath::Pi(), -1.59, 1.59);
11279   
11280   /*
11281   h->GetUEHist(2)->GetEventHist()->GetGrid(6)->GetGrid()->GetAxis(1)->SetRange(centrBegin, centrEnd);
11282   inclusive = h->GetUEHist(2)->GetEventHist()->ShowProjection(0, 6);
11283   h->GetUEHist(2)->GetEventHist()->GetGrid(6)->GetGrid()->GetAxis(1)->SetRange(0, -1);
11284   */
11285   
11286   axis = h->GetUEHist(2)->GetEventHist()->GetGrid(6)->GetGrid()->GetAxis(1);
11287   
11288   inclusiveTmp = h->GetCorrelationpT()->ProjectionY("inclusiveTmp", h->GetCorrelationpT()->GetXaxis()->FindBin(axis->GetBinLowEdge(centrBegin) + 0.01), h->GetCorrelationpT()->GetXaxis()->FindBin(axis->GetBinUpEdge(centrEnd) - 0.01));
11289   
11290   //rebin to match other histograms
11291   //inclusive2 = inclusive->Rebin(away->GetNbinsX(), "inclusive2", away->GetXaxis()->GetXbins()->GetArray());
11292   
11293   // manually, as usual the ROOT function makes a SEGV
11294   inclusive = (TH1*) away->Clone("inclusive");
11295   inclusive->Reset();
11296   inclusive->Sumw2();
11297   for (Int_t bin=1; bin<=inclusiveTmp->GetNbinsX(); bin++)
11298     inclusive->Fill(inclusiveTmp->GetBinCenter(bin), inclusiveTmp->GetBinContent(bin));
11299   
11300   for (Int_t bin=1; bin<=inclusive->GetNbinsX(); bin++)
11301     inclusive->SetBinError(bin, TMath::Sqrt(inclusive->GetBinContent(bin)));
11302     
11303   // normalization: events, phase space
11304   inclusive->Scale(1.0 / h->GetCentralityDistribution()->Integral(centrBegin, centrEnd));
11305   inclusive->Scale(1.0 / (TMath::TwoPi() * 0.8 * 2));
11306   
11307   // bin width
11308   for (Int_t i=1; i<=inclusive->GetNbinsX(); i++)
11309   {
11310     inclusive->SetBinContent(i, inclusive->GetBinContent(i) / inclusive->GetXaxis()->GetBinWidth(i));
11311     inclusive->SetBinError  (i, inclusive->GetBinError(i) / inclusive->GetXaxis()->GetBinWidth(i));
11312   }
11313   
11314   Prepare1DPlot(inclusive);
11315   inclusive->SetLineColor(colors[4]);
11316   legend->AddEntry(inclusive->Clone(), "Inclusive");
11317   
11318   //Prepare1DPlot(away3);
11319   //legend->AddEntry(away3->Clone(), Form("%s: 0.8 < |#Delta #eta| < 1.6, #phi ~ %.1f", phiLabels[2], phiRange[2]));
11320   
11321   // scale for acceptance to match acceptance of towardsCentralEta
11322   towardsSideEta1->Scale(1.0 / scalingFactor); // contains only "side-eta"
11323   transverse->Scale(1.0 / (1.0 + scalingFactor)); // full eta
11324   away->Scale(1.0 / (1.0 + scalingFactor)); // full eta
11325   inclusive->Scale(1.0 / (1.0 + scalingFactor)); // full eta (phi scaling implicit)
11326   
11327   canvas->cd(1);
11328   towardsCentralEtaClone = towardsCentralEta->DrawCopy("SAME");
11329   towardsSideEta1Clone = towardsSideEta1->DrawCopy("SAME");
11330   transverseClone = transverse->DrawCopy("SAME");
11331   //transverseSideEta1->DrawCopy("SAME");
11332   awayClone = away->DrawCopy("SAME");
11333   inclusiveClone = inclusive->DrawCopy("SAME");
11334   //inclusive2->DrawCopy("SAME");
11335   //away3->DrawCopy("SAME");
11336   
11337   canvas->cd(3);
11338   
11339   towardsCentralEtaR = (TH1*) towardsCentralEta->Clone("towardsCentralEtaR");
11340   towardsSideEta1R = (TH1*) towardsSideEta1->Clone("towardsSideEta1R");
11341   transverseR = (TH1*) transverse->Clone("transverseR");
11342   awayR = (TH1*) away->Clone("awayR");
11343   
11344   towardsCentralEtaR->Divide(inclusive);
11345   towardsSideEta1R->Divide(inclusive);
11346   transverseR->Divide(inclusive);
11347   awayR->Divide(inclusive);
11348   
11349   towardsCentralEtaR->DrawCopy("SAME");
11350   towardsSideEta1R->DrawCopy("SAME");
11351   transverseR->DrawCopy("SAME");
11352   awayR->DrawCopy("SAME");
11353   
11354   if (fit == 1)
11355   {
11356     canvas->cd(1);
11357     
11358     awayClone->Fit("expo", "", "SAME", 1.1, 2.9);
11359     awayClone->GetFunction("expo")->SetRange(1, 10);
11360     gPad->SetLogx(0);
11361   }
11362   else if (fit == 2)
11363   {
11364     canvas->cd(1);
11365     
11366     func = new TF1("func", "[0] * x**[1]");
11367     func->SetParameters(1, 1);
11368     
11369     Float_t limitLow = 2.1;
11370     Float_t limitHigh = 4.9;
11371     
11372     func2 = (TF1*) func->Clone();
11373     towardsCentralEtaClone->Fit(func2, "", "SAME", limitLow, limitHigh);
11374     towardsCentralEtaClone->GetFunction("func")->SetRange(1, 10);
11375     towardsCentralEtaClone->GetFunction("func")->SetLineColor(towardsCentralEtaClone->GetLineColor());
11376     
11377     func2 = (TF1*) func->Clone();
11378     towardsSideEta1Clone->Fit(func2, "", "SAME", limitLow, limitHigh);
11379     towardsSideEta1Clone->GetFunction("func")->SetRange(1, 10);
11380     towardsSideEta1Clone->GetFunction("func")->SetLineColor(towardsSideEta1Clone->GetLineColor());
11381   
11382     func2 = (TF1*) func->Clone();
11383     transverseClone->Fit(func2, "", "SAME", limitLow, limitHigh);
11384     transverseClone->GetFunction("func")->SetRange(1, 10);
11385     transverseClone->GetFunction("func")->SetLineColor(transverseClone->GetLineColor());
11386   
11387     func2 = (TF1*) func->Clone();
11388     awayClone->Fit(func2, "", "SAME", limitLow, limitHigh);
11389     awayClone->GetFunction("func")->SetRange(1, 10);
11390     awayClone->GetFunction("func")->SetLineColor(awayClone->GetLineColor());
11391   
11392     func2 = (TF1*) func->Clone();
11393     inclusiveClone->Fit(func2, "", "SAME", limitLow, limitHigh);
11394     inclusiveClone->GetFunction("func")->SetRange(1, 10);
11395     inclusiveClone->GetFunction("func")->SetLineColor(inclusiveClone->GetLineColor());
11396   }
11397   
11398   // subtract transverse part
11399   away->Add(transverse, -1);
11400   //away3->Add(transverseSideEta1, -1);
11401   towardsCentralEta->Add(transverse, -1);
11402   towardsSideEta1->Add(transverse, -1);
11403   //inclusive->Add(transverse, -1);
11404   
11405   canvas->cd(2);
11406   towardsCentralEta->DrawCopy("SAME");
11407   towardsSideEta1->DrawCopy("SAME");
11408   away->DrawCopy("SAME");
11409   inclusive->DrawCopy("SAME");
11410   //away3->DrawCopy("SAME");
11411   
11412   canvas->cd(4);
11413   
11414   towardsCentralEtaR = (TH1*) towardsCentralEta->Clone("towardsCentralEtaR2");
11415   towardsSideEta1R = (TH1*) towardsSideEta1->Clone("towardsSideEta1R2");
11416   awayR = (TH1*) away->Clone("awayR2");
11417   
11418   towardsCentralEtaR->Divide(inclusive);
11419   towardsSideEta1R->Divide(inclusive);
11420   awayR->Divide(inclusive);
11421   
11422   towardsCentralEtaR->DrawCopy("SAME");
11423   towardsSideEta1R->DrawCopy("SAME");
11424   awayR->DrawCopy("SAME");
11425   
11426   if (fit == 1)
11427   {
11428     canvas->cd(2);
11429     
11430     away->Fit("expo", "", "SAME", 1.1, 2.9);
11431     away->GetFunction("expo")->SetRange(1, 10);
11432     gPad->SetLogx(0);
11433   }
11434   else if (fit == 2)
11435   {
11436     canvas->cd(2);
11437     
11438     func = new TF1("func", "[0] * x**[1]");
11439     func->SetParameters(1, 1);
11440     
11441     func2 = (TF1*) func->Clone();
11442     towardsCentralEta->Fit(func2, "", "SAME", limitLow, limitHigh);
11443     func2->SetRange(1, 10);
11444     
11445     func2 = (TF1*) func->Clone();
11446     towardsSideEta1->Fit(func2, "", "SAME", limitLow, limitHigh);
11447     func2->SetRange(1, 10);
11448   
11449     func2 = (TF1*) func->Clone();
11450     away->Fit(func2, "", "SAME", limitLow, limitHigh);
11451     func2->SetRange(1, 10);
11452   
11453     func2 = (TF1*) func->Clone();
11454     inclusive->Fit(func2, "", "SAME", limitLow, limitHigh);
11455     func2->SetRange(1, 10);
11456   }
11457   
11458   for (Int_t i=1; i<=2; i++)
11459   {
11460     canvas->cd(i);
11461     
11462     TString str3;
11463     str3.Form("%d-%d%%", (Int_t) h->GetCentralityDistribution()->GetXaxis()->GetBinLowEdge(centrBegin), (Int_t) h->GetCentralityDistribution()->GetXaxis()->GetBinUpEdge(centrEnd));
11464     latex = new TLatex(0.2, 0.3, str3);
11465     latex->SetNDC();
11466     latex->SetTextSize(0.06);
11467     
11468     latex2 = new TLatex(0.55, 0.6, str);
11469     latex2->SetNDC();
11470     latex2->SetTextSize(0.06);
11471     
11472     latex->Draw();
11473     latex2->Draw();
11474     
11475     legend->Draw();
11476   }
11477 }
11478
11479 void CombineDeltaPhiWithWeighting()
11480 {
11481   // From Hermes:
11482   // For LHC11a2a:
11483   // xsection: 11.879829,  ntrials: 8132994.000000
11484   // 
11485   // For LHC11a2b:
11486   // xsection: 0.623421,  ntrials: 2293420.000000
11487   // 
11488   // For LHC11a2c:
11489   // xsection: 0.043815,  ntrials: 1314525.375000
11490   
11491   // TODO is merging only same event distribution at present
11492   
11493   loadlibs();
11494   
11495   Int_t nInput = 3;
11496   const char* inputList[] = { "mergejob/LHC11a2a_110124.root", "mergejob/LHC11a2b_110131.root", "mergejob/LHC11a2c_110131.root" };
11497   
11498   Float_t xSections[] = { 11.879829 * 1e6 / 8132994, 0.623421 * 1e6 / 2293420, 0.043815 * 1e6 / 1314525 };
11499   xSections[2] /= xSections[0];
11500   xSections[1] /= xSections[0];
11501   xSections[0] /= xSections[0];
11502   
11503   AliUEHistograms* files[3];
11504   TList* finalList = 0;
11505   for (Int_t i=0; i<nInput; i++)
11506   {
11507     files[i] = (AliUEHistograms*) GetUEHistogram(inputList[i], (i == 0) ? &finalList : 0);
11508     if (i > 0) 
11509     {
11510       files[i]->Scale(xSections[i]);
11511       
11512       TList* list2 = new TList;
11513       list2->Add(files[i]);
11514       files[0]->Merge(list2);
11515     }
11516   }
11517   
11518   TFile* file3 = TFile::Open("out.root", "RECREATE");
11519   file3->mkdir("PWG4_PhiCorrelations");
11520   file3->cd("PWG4_PhiCorrelations");
11521   finalList->Write(0, TObject::kSingleKey);
11522   file3->Close();       
11523 }
11524
11525 void NormalizeToBinWidth(TH1* hist)
11526 {
11527   //
11528   // normalizes a 1-d histogram to its bin width
11529   //
11530
11531   if (hist->GetDimension() == 1)
11532   {
11533     for (Int_t i=1; i<=hist->GetNbinsX(); ++i)
11534     {
11535       hist->SetBinContent(i, hist->GetBinContent(i) / hist->GetBinWidth(i));
11536       hist->SetBinError(i, hist->GetBinError(i) / hist->GetBinWidth(i));
11537     }
11538   }
11539   else if (hist->GetDimension() == 2)
11540   {
11541     for (Int_t i=1; i<=hist->GetNbinsX(); ++i)
11542     {
11543       for (Int_t j=1; j<=hist->GetNbinsY(); ++j)
11544       {
11545         hist->SetBinContent(i, j, hist->GetBinContent(i, j) / hist->GetXaxis()->GetBinWidth(i) / hist->GetYaxis()->GetBinWidth(j));
11546         hist->SetBinError(i, j, hist->GetBinError(i) / hist->GetXaxis()->GetBinWidth(i) / hist->GetYaxis()->GetBinWidth(j));
11547       }
11548     }
11549   }
11550 }
11551
11552 void GetAcceptanceScalingFactor(const char* fileName1, Float_t eta1 = 0.8, Float_t eta2 = 1.6)
11553 {
11554   loadlibs();
11555
11556   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName1, 0, kTRUE);
11557   h->SetPtRange(1.01, 39.99);
11558  
11559   new TCanvas;
11560   mixed = ((TH2*)h->GetUEHist(2)->GetUEHist(6, 0, 1.01, 39.99, 0, 16, kTRUE))->ProjectionY();
11561   mixed->DrawCopy();
11562   
11563   Float_t left = mixed->Integral(mixed->FindBin(-eta2 + 0.01), mixed->FindBin(-eta1 - 0.01));
11564   Float_t center = mixed->Integral(mixed->FindBin(-eta1 + 0.01), mixed->FindBin(eta1 - 0.01));
11565   Float_t right = mixed->Integral(mixed->FindBin(eta1 + 0.01), mixed->FindBin(eta2 - 0.01));
11566   
11567   Printf("%f %f %f", left, center, right);
11568   Printf("%f", (left + right) / center);
11569 }
11570
11571 void TrackingEfficiencyCentralityDependence(const char* fileName, Int_t step1 = 2, Int_t step2 = 4)
11572 {
11573   Int_t nCentralityBins = 3;
11574   Float_t centralityBins[] = { 0, 20, 40, 90 };
11575   
11576   Int_t colors[] = { 1, 2, 4, 6 };
11577
11578   loadlibs();
11579
11580   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
11581   
11582   new TCanvas;
11583   dummy = new TH2F("dummy", ";p_{T};tracking efficiency", 100, 0, 20, 100, 0.7, 1.3);
11584   dummy->SetStats(0);
11585   dummy->Draw();
11586   
11587   legend = new TLegend(0.13, 0.67, 0.31, 0.87);
11588   legend->SetTextSize(0.04);
11589   legend->SetFillColor(0);
11590   
11591   for (Int_t i=0; i<nCentralityBins; i++)
11592   {
11593     eventHist = h->GetUEHist(2)->GetEventHist();
11594     
11595     eventHist->GetGrid(step1)->SetRangeUser(1, centralityBins[i] + 0.1, centralityBins[i+1] - 0.1);
11596     eventHist->GetGrid(step2)->SetRangeUser(1, centralityBins[i] + 0.1, centralityBins[i+1] - 0.1);
11597   
11598     TH1* hist1 = eventHist->ShowProjection(0, step1);
11599     TH1* hist2 = eventHist->ShowProjection(0, step2);
11600     
11601     hist2->Divide(hist1);
11602     
11603     hist2->SetLineColor(colors[i]);
11604     hist2->GetYaxis()->SetTitle("tracking efficiency");
11605     hist2->Draw("SAME");
11606     
11607     legend->AddEntry(hist2, Form("%.0f-%.0f%%", centralityBins[i], centralityBins[i+1]));
11608   }
11609   
11610   legend->Draw();
11611 }
11612
11613
11614 TGraphErrors* ReadHepdata(const char* fileName, Bool_t errorsAreAdded = kFALSE, Int_t skipYErrors = 0, Int_t skipXerrors = 1)
11615 {
11616   // expected format: x [x2] [x3] y [ye] [ye2] [xe]
11617   //
11618   // skipYErrors:   0 --> ye present
11619   //                1 --> no errors ye
11620   //                2 --> y and ye are lower and upper error, i.e. y' = (y + ye) / 2 and ye = (ye - y) / 2
11621   //                3 --> ye and ye2 are stat and syst error, will be added in quadrature
11622   // 
11623   // skipXerrors:   0 --> xe present
11624   //                1 --> no errors xe
11625   //                2 --> x2 present, xe not present and is calculated from x2 - x
11626   //                3 --> x2 and x3 present, ignored
11627   
11628   ifstream fin(fileName);
11629
11630   graph = new TGraphErrors(0);
11631
11632   Double_t sum = 0;
11633
11634   while (fin.good())
11635   {
11636     char buffer[2000];
11637     if (fin.peek() == '#')
11638     {
11639       fin.getline(buffer, 2000);
11640       continue;
11641     }
11642   
11643     Double_t x = -1;
11644     Double_t x2 = -1;
11645     Double_t y = -1;
11646     Double_t ye = 0;
11647     Double_t xe = 0;
11648
11649     fin >> x;
11650     
11651     if (skipXerrors == 2)
11652     {
11653       fin >> x2;
11654       xe = (x2 - x + 1) / 2;
11655       x = x + (x2 - x) / 2;
11656     }
11657     
11658     if (skipXerrors == 3)
11659     {
11660       fin >> x2;
11661       fin >> x2;
11662     }
11663     
11664     fin >> y;
11665
11666     if (y == -1)
11667       continue;
11668
11669     if (skipYErrors == 0)
11670     {
11671       ye = -1;
11672       fin >> ye;
11673       if (ye == -1)
11674         continue;
11675     }
11676     else if (skipYErrors == 2)
11677     {
11678       ye = -1;
11679       fin >> ye;
11680       if (ye == -1)
11681         continue;
11682       
11683       Double_t newy = (y + ye) / 2;
11684       ye = (ye - y) / 2;
11685       y = newy;
11686     }
11687     else if (skipYErrors == 3)
11688     {
11689       ye = -1;
11690       fin >> ye;
11691       if (ye == -1)
11692         continue;
11693       
11694       Double_t ye2 = -1;
11695       fin >> ye2;
11696       if (ye2 == -1)
11697         continue;
11698
11699       ye = TMath::Sqrt(ye*ye + ye2*ye2);
11700     }
11701
11702     if (skipXerrors == 0)
11703     {
11704       xe = -1;
11705       fin >> xe;
11706       if (xe == -1)
11707         continue;
11708     }
11709
11710     //Printf("%f %f %f %f", x, y, xe, ye);
11711
11712     if (errorsAreAdded)
11713       ye -= y;
11714
11715     graph->SetPoint(graph->GetN(), x, y);
11716     graph->SetPointError(graph->GetN()-1, xe, ye);
11717
11718     sum += y;
11719     
11720     // read rest until end of line...
11721     fin.getline(buffer, 2000);
11722   }
11723   fin.close();
11724
11725   Printf("%s: %f", fileName, sum);
11726
11727   return graph;
11728 }
11729
11730 void EvaluateParticleEfficiency(const char* fileName)
11731 {
11732   Int_t centralityBegin = 1;
11733   Int_t centralityEnd = 15;
11734   
11735   if (1)
11736   {
11737     Int_t step1 = 4;
11738     Int_t step2 = 5;
11739   }
11740   else
11741   {
11742     Int_t step1 = 2;
11743     Int_t step2 = 4;
11744   }
11745   
11746   Float_t ptTriggerBegin = 4.01;
11747   Float_t ptTriggerEnd = 19.99;
11748   
11749   Bool_t verbose = 1;
11750   
11751   loadlibs();
11752   
11753   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
11754   AliUEHist* cont = h->GetUEHist(2);
11755   
11756   cont->GetEventHist()->GetGrid(step1)->GetGrid()->GetAxis(1)->SetRange(centralityBegin, centralityEnd);
11757   cont->GetEventHist()->GetGrid(step2)->GetGrid()->GetAxis(1)->SetRange(centralityBegin, centralityEnd);
11758   
11759   Int_t stepEff1 = step1 - (Int_t) AliUEHist::kCFStepAnaTopology;
11760   if (stepEff1 == -1)
11761     stepEff1 = 0;
11762   Int_t stepEff2 = step2 - (Int_t) AliUEHist::kCFStepAnaTopology;
11763   if (stepEff2 == -1)
11764     stepEff2 = 0;
11765   
11766   cont->GetTrackHistEfficiency()->GetGrid(stepEff1)->GetGrid()->GetAxis(3)->SetRange(centralityBegin, centralityEnd);
11767   cont->GetTrackHistEfficiency()->GetGrid(stepEff2)->GetGrid()->GetAxis(3)->SetRange(centralityBegin, centralityEnd);
11768   
11769   TH1* triggerParticle = cont->GetEventHist()->Project(step2, 0);
11770   triggerParticle->Divide(cont->GetEventHist()->Project(step1, 0));
11771   
11772   TH1* singleParticle = cont->GetTrackHistEfficiency()->Project(stepEff2, 1);
11773   singleParticle->Divide(cont->GetTrackHistEfficiency()->Project(stepEff1, 1));
11774   
11775   //singleParticle = singleParticle->Rebin(triggerParticle->GetNbinsX(), "singleRebin", triggerParticle->GetXaxis()->GetXbins()->GetArray());
11776   
11777   TGraphErrors* effectiveEffect = new TGraphErrors;
11778   TGraphErrors* triggerCorrelatedEffect = new TGraphErrors;
11779   TGraphErrors* afterBaseLine = new TGraphErrors;
11780   TGraphErrors* triggerCorrelatedEffect2D = new TGraphErrors;
11781   
11782   //TVirtualFitter::SetDefaultFitter("Linear");
11783   
11784   for (Int_t bin=3; bin<=triggerParticle->GetNbinsX(); bin++)
11785   {
11786     if (triggerParticle->GetBinCenter(bin) > 10)
11787       continue;
11788     
11789     cont->SetPtRange(triggerParticle->GetXaxis()->GetBinLowEdge(bin) + 0.01, triggerParticle->GetXaxis()->GetBinUpEdge(bin) - 0.01);
11790       
11791     TH1* hist1 = cont->GetUEHist(step1, 0, ptTriggerBegin, ptTriggerEnd, centralityBegin, centralityEnd);
11792     TH1* hist2 = cont->GetUEHist(step2, 0, ptTriggerBegin, ptTriggerEnd, centralityBegin, centralityEnd);
11793     
11794     // TODO the uncertainties on the ratios should be properly calculated! (if that helps ;))
11795     clone = (TH1*) hist2->Clone("clone");
11796     clone->Divide(hist1);
11797     
11798     //func = new TF1("func", "[0]", -10, 10);
11799     
11800     if ((Int_t) clone->Fit("pol0", "0", "", -10, 10) == 0)
11801     {
11802       func = clone->GetFunction("pol0");
11803       effectiveEffect->SetPoint(effectiveEffect->GetN(), triggerParticle->GetBinCenter(bin) - 0.2, func->GetParameter(0));
11804       effectiveEffect->SetPointError(effectiveEffect->GetN()-1, 0, func->GetParError(0));
11805       
11806       if (verbose)
11807       {
11808         new TCanvas;
11809         clone->GetYaxis()->SetRangeUser(0.9, 1.3);
11810         clone->Draw();
11811         func->DrawClone("SAME");
11812       }
11813     }
11814     
11815     if ((Int_t) clone->Fit("pol0", "0", "", -0.3, 0.3) == 0)
11816     {
11817       func = clone->GetFunction("pol0");
11818       triggerCorrelatedEffect->SetPoint(triggerCorrelatedEffect->GetN(), triggerParticle->GetBinCenter(bin) - 0.1, func->GetParameter(0));
11819       triggerCorrelatedEffect->SetPointError(triggerCorrelatedEffect->GetN()-1, 0, func->GetParError(0));
11820       
11821       if (verbose)
11822       {
11823         func->SetLineColor(2);
11824         func->DrawClone("SAME");
11825       }
11826     }
11827     
11828     if ((Int_t) hist2->Fit("pol0", "0", "", 1, 2) == 0)
11829     {
11830       func = hist2->GetFunction("pol0");
11831       func->SetRange(-10, 10);
11832       hist2->Add(func, -1);
11833     
11834       if ((Int_t) hist1->Fit("pol0", "0", "", 1, 2) == 0)
11835       {
11836         func = hist1->GetFunction("pol0");
11837         func->SetRange(-10, 10);
11838         hist1->Add(func, -1);
11839         
11840         //new TCanvas; hist1->DrawCopy();
11841         
11842         hist2->Divide(hist1);
11843         
11844         if ((Int_t) hist2->Fit("pol0", "0", "", -0.3, 0.3) == 0)
11845         {
11846           func = hist2->GetFunction("pol0");
11847           afterBaseLine->SetPoint(afterBaseLine->GetN(), triggerParticle->GetBinCenter(bin) + 0.2, func->GetParameter(0));
11848           afterBaseLine->SetPointError(afterBaseLine->GetN()-1, 0, func->GetParError(0));
11849         
11850           if (verbose)
11851           {
11852             new TCanvas;
11853             hist2->GetYaxis()->SetRangeUser(0.9, 1.3);
11854             hist2->DrawCopy();
11855             func->SetLineColor(4);
11856             func->DrawClone("SAME");
11857           }
11858         }
11859       }
11860     }
11861       
11862     // 2d
11863     TH2* hist1_2D = cont->GetUEHist(step1, 0, ptTriggerBegin, ptTriggerEnd, centralityBegin, centralityEnd, 1);
11864     TH2* hist2_2D = cont->GetUEHist(step2, 0, ptTriggerBegin, ptTriggerEnd, centralityBegin, centralityEnd, 1);
11865     
11866     //((TH2*)hist1)->Rebin2D(2, 2); ((TH2*)hist2)->Rebin2D(2, 2);
11867     
11868     hist2_2D->Divide(hist1_2D);
11869     
11870     if (verbose)
11871     {
11872       new TCanvas;
11873       hist2_2D->Draw("COLZ");
11874     }
11875     
11876     //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));
11877     
11878     Double_t error;
11879     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);
11880     
11881     integral /= hist2_2D->GetXaxis()->FindBin(0.01) - hist2_2D->GetXaxis()->FindBin(-0.01) + 1;
11882     integral /= hist2_2D->GetYaxis()->FindBin(0.01) - hist2_2D->GetYaxis()->FindBin(-0.01) + 1;
11883     
11884     error /= hist2_2D->GetXaxis()->FindBin(0.01) - hist2_2D->GetXaxis()->FindBin(-0.01) + 1;
11885     error /= hist2_2D->GetYaxis()->FindBin(0.01) - hist2_2D->GetYaxis()->FindBin(-0.01) + 1;
11886     
11887     triggerCorrelatedEffect2D->SetPoint(triggerCorrelatedEffect2D->GetN(), triggerParticle->GetBinCenter(bin) + 0.1, integral);
11888     triggerCorrelatedEffect2D->SetPointError(triggerCorrelatedEffect2D->GetN()-1, 0, error);
11889     
11890     if (verbose)
11891       break;
11892   }
11893   
11894   new TCanvas;
11895   triggerParticle->Draw();
11896   triggerParticle->GetXaxis()->SetRangeUser(0, 9.9);
11897   
11898   singleParticle->SetLineColor(2);
11899   //singleParticle->Draw("SAME");
11900   
11901   effectiveEffect->SetMarkerStyle(24);
11902   effectiveEffect->Draw("PSAME");
11903   
11904   triggerCorrelatedEffect->SetMarkerStyle(25);
11905   triggerCorrelatedEffect->SetMarkerColor(2);
11906   triggerCorrelatedEffect->SetLineColor(2);
11907   triggerCorrelatedEffect->Draw("PSAME");
11908   
11909   triggerCorrelatedEffect2D->SetMarkerStyle(27);
11910   triggerCorrelatedEffect2D->SetMarkerColor(3);
11911   triggerCorrelatedEffect2D->SetLineColor(3);
11912   triggerCorrelatedEffect2D->Draw("PSAME");
11913   
11914   afterBaseLine->SetMarkerStyle(26);
11915   afterBaseLine->SetMarkerColor(4);
11916   afterBaseLine->SetLineColor(4);
11917   afterBaseLine->Draw("PSAME");
11918
11919   legend = new TLegend(0.66, 0.15, 0.88, 0.38);
11920   legend->SetFillColor(0);
11921   legend->SetTextSize(0.04);
11922   legend->AddEntry(triggerParticle, "trigger", "L");
11923   //legend->AddEntry(singleParticle, "single", "L");
11924   legend->AddEntry(effectiveEffect, "effective", "P");
11925   legend->AddEntry(triggerCorrelatedEffect, "at 0", "P");
11926   legend->AddEntry(triggerCorrelatedEffect2D, "at 0 (2d)", "P");
11927   legend->AddEntry(afterBaseLine, "baseline", "P");
11928   legend->Draw();
11929 }
11930
11931 void EvaluateParticleEfficiency2D(const char* fileName)
11932 {
11933   Int_t centralityBegin = 1;
11934   Int_t centralityEnd = 15;
11935   
11936   if (1)
11937   {
11938     Int_t step1 = 4;
11939     Int_t step2 = 5;
11940   }
11941   else
11942   {
11943     Int_t step1 = 2;
11944     Int_t step2 = 4;
11945   }
11946   
11947   Bool_t verbose = 0;
11948   
11949   loadlibs();
11950   
11951   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
11952   AliUEHist* cont = h->GetUEHist(2);
11953   
11954   cont->GetEventHist()->GetGrid(step1)->GetGrid()->GetAxis(1)->SetRange(centralityBegin, centralityEnd);
11955   cont->GetEventHist()->GetGrid(step2)->GetGrid()->GetAxis(1)->SetRange(centralityBegin, centralityEnd);
11956   
11957   Int_t stepEff1 = step1 - (Int_t) AliUEHist::kCFStepAnaTopology;
11958   if (stepEff1 == -1)
11959     stepEff1 = 0;
11960   Int_t stepEff2 = step2 - (Int_t) AliUEHist::kCFStepAnaTopology;
11961   if (stepEff2 == -1)
11962     stepEff2 = 0;
11963   
11964   cont->GetTrackHistEfficiency()->GetGrid(stepEff1)->GetGrid()->GetAxis(3)->SetRange(centralityBegin, centralityEnd);
11965   cont->GetTrackHistEfficiency()->GetGrid(stepEff2)->GetGrid()->GetAxis(3)->SetRange(centralityBegin, centralityEnd);
11966   
11967   TH1* triggerParticle = cont->GetEventHist()->Project(step2, 0);
11968   triggerParticle->Divide(cont->GetEventHist()->Project(step1, 0));
11969   
11970   TH1* singleParticle = cont->GetTrackHistEfficiency()->Project(stepEff2, 1);
11971   singleParticle->Divide(cont->GetTrackHistEfficiency()->Project(stepEff1, 1));
11972   
11973   cont->GetTrackHist(0)->GetGrid(step1)->SetRangeUser(0, -0.01, 0.01); // delta eta
11974   cont->GetTrackHist(0)->GetGrid(step1)->SetRangeUser(4, -0.01, 0.01); // delta phi
11975   TH2* tracksStep1 = (TH2*) cont->GetTrackHist(0)->Project(step1, 1, 2);
11976   
11977   cont->GetTrackHist(0)->GetGrid(step2)->SetRangeUser(0, -0.01, 0.01); // delta eta
11978   cont->GetTrackHist(0)->GetGrid(step2)->SetRangeUser(4, -0.01, 0.01); // delta phi
11979   TH2* tracksStep2 = (TH2*) cont->GetTrackHist(0)->Project(step2, 1, 2);
11980   
11981   tracksStep2->Divide(tracksStep1);
11982   
11983   TH1* triggersStep1 = cont->GetEventHist()->Project(step1, 0);
11984   TH1* triggersStep2 = cont->GetEventHist()->Project(step2, 0);
11985   
11986   for (Int_t x=1; x<=tracksStep2->GetNbinsX(); x++)
11987     for (Int_t y=1; y<=tracksStep2->GetNbinsY(); y++)
11988       if (singleParticle->GetBinContent(x) > 0)
11989         tracksStep2->SetBinContent(x, y, tracksStep2->GetBinContent(x, y) / triggersStep2->GetBinContent(y) * triggersStep1->GetBinContent(y) / singleParticle->GetBinContent(x));
11990       else
11991         tracksStep2->SetBinContent(x, y, 0);
11992   
11993   new TCanvas;
11994   tracksStep2->Draw("COLZ");
11995   
11996   TGraphErrors** triggerCorrelatedEffect2D = new TGraphErrors*[triggerParticle->GetNbinsX()+1];
11997   TGraphErrors** triggerCorrelatedEffect2DSub = new TGraphErrors*[triggerParticle->GetNbinsX()+1];
11998   
11999   for (Int_t bin1=0; bin1<=triggerParticle->GetNbinsX(); bin1++)
12000   {
12001     triggerCorrelatedEffect2D[bin1] = 0;
12002     triggerCorrelatedEffect2DSub[bin1] = 0;
12003   }
12004   
12005   for (Int_t bin1=5; bin1<=triggerParticle->GetNbinsX(); bin1++)
12006   {
12007     if (triggerParticle->GetBinCenter(bin1) > 10)
12008       continue;
12009     
12010     Float_t ptTriggerBegin = triggerParticle->GetXaxis()->GetBinLowEdge(bin1) + 0.01;
12011     Float_t ptTriggerEnd = triggerParticle->GetXaxis()->GetBinUpEdge(bin1) - 0.01;
12012     
12013     for (Int_t bin2=3; bin2<=triggerParticle->GetNbinsX(); bin2++)
12014     {
12015       if (triggerParticle->GetBinCenter(bin2) > 8)
12016         continue;
12017         
12018       if (bin2 > bin1)
12019         continue;
12020     
12021       cont->SetPtRange(triggerParticle->GetXaxis()->GetBinLowEdge(bin2) + 0.01, triggerParticle->GetXaxis()->GetBinUpEdge(bin2) - 0.01);
12022   
12023       // 2d
12024       TH2* hist1_2D = cont->GetUEHist(step1, 0, ptTriggerBegin, ptTriggerEnd, centralityBegin, centralityEnd, 1);
12025       TH2* hist2_2D = cont->GetUEHist(step2, 0, ptTriggerBegin, ptTriggerEnd, centralityBegin, centralityEnd, 1);
12026       
12027       //((TH2*)hist1)->Rebin2D(2, 2); ((TH2*)hist2)->Rebin2D(2, 2);
12028       
12029       hist2_2D->Divide(hist1_2D);
12030       
12031       if (verbose)
12032       {
12033         new TCanvas;
12034         hist2_2D->Draw("COLZ");
12035       }
12036       
12037       //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));
12038       
12039       Double_t error;
12040       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);
12041       
12042       integral /= hist2_2D->GetXaxis()->FindBin(0.01) - hist2_2D->GetXaxis()->FindBin(-0.01) + 1;
12043       integral /= hist2_2D->GetYaxis()->FindBin(0.01) - hist2_2D->GetYaxis()->FindBin(-0.01) + 1;
12044       
12045       error /= hist2_2D->GetXaxis()->FindBin(0.01) - hist2_2D->GetXaxis()->FindBin(-0.01) + 1;
12046       error /= hist2_2D->GetYaxis()->FindBin(0.01) - hist2_2D->GetYaxis()->FindBin(-0.01) + 1;
12047       
12048       if (integral <= 0)
12049         continue;
12050       
12051       if (!triggerCorrelatedEffect2D[bin1])
12052         triggerCorrelatedEffect2D[bin1] = new TGraphErrors;
12053         
12054       triggerCorrelatedEffect2D[bin1]->SetPoint(triggerCorrelatedEffect2D[bin1]->GetN(), triggerParticle->GetBinCenter(bin2) - 0.5 + 0.1 * bin1, integral);
12055       triggerCorrelatedEffect2D[bin1]->SetPointError(triggerCorrelatedEffect2D[bin1]->GetN()-1, 0, error);
12056     
12057       if (!triggerCorrelatedEffect2DSub[bin1])
12058         triggerCorrelatedEffect2DSub[bin1] = new TGraphErrors;
12059         
12060       triggerCorrelatedEffect2DSub[bin1]->SetPoint(triggerCorrelatedEffect2DSub[bin1]->GetN(), triggerParticle->GetBinCenter(bin2) - 0.5 + 0.1 * bin1, integral / triggerParticle->GetBinContent(bin2));
12061       triggerCorrelatedEffect2DSub[bin1]->SetPointError(triggerCorrelatedEffect2DSub[bin1]->GetN()-1, 0, error / triggerParticle->GetBinContent(bin2));
12062       
12063       if (verbose)
12064         break;
12065     }
12066       
12067     if (verbose)
12068       break;
12069   }
12070   
12071   new TCanvas;
12072   triggerParticle->Draw();
12073   triggerParticle->GetXaxis()->SetRangeUser(0, 9.9);
12074   
12075   legend = new TLegend(0.66, 0.15, 0.88, 0.38);
12076   legend->SetFillColor(0);
12077   legend->SetTextSize(0.04);
12078   legend->AddEntry(triggerParticle, "trigger", "L");
12079   
12080   Int_t marker = 20;
12081   Int_t color = 1;
12082   
12083   for (Int_t bin1=3; bin1<=triggerParticle->GetNbinsX(); bin1++)
12084     if (triggerCorrelatedEffect2D[bin1])
12085     {
12086       triggerCorrelatedEffect2D[bin1]->SetMarkerStyle(marker++);
12087       triggerCorrelatedEffect2D[bin1]->SetMarkerColor(color);
12088       triggerCorrelatedEffect2D[bin1]->SetLineColor(color++);
12089       triggerCorrelatedEffect2D[bin1]->Draw("PSAME");
12090       legend->AddEntry(triggerCorrelatedEffect2D[bin1], Form("pt %.2f", triggerParticle->GetBinCenter(bin1)), "P");
12091     }
12092   
12093   legend->Draw();
12094
12095   new TCanvas;
12096   triggerParticle->Draw();
12097   triggerParticle->GetXaxis()->SetRangeUser(0, 9.9);
12098   
12099   marker = 20;
12100   color = 1;
12101   
12102   for (Int_t bin1=3; bin1<=triggerParticle->GetNbinsX(); bin1++)
12103     if (triggerCorrelatedEffect2DSub[bin1])
12104     {
12105       triggerCorrelatedEffect2DSub[bin1]->SetMarkerStyle(marker++);
12106       triggerCorrelatedEffect2DSub[bin1]->SetMarkerColor(color);
12107       triggerCorrelatedEffect2DSub[bin1]->SetLineColor(color++);
12108       triggerCorrelatedEffect2DSub[bin1]->Draw("PSAME");
12109     }
12110   
12111   legend->Draw();
12112 }
12113
12114 void DrawEventCount(const char* fileName, Int_t step = 8)
12115 {
12116   loadlibs();
12117   
12118   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
12119   h->GetEventCount()->Draw("TEXT");
12120   
12121   eventCount = h->GetEventCount();
12122   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));
12123   Printf("Events: %f", events);
12124 }
12125
12126 void FitDCADistributions(const char* fileName1)
12127 {
12128   loadlibs();
12129   
12130   TFile::Open(fileName1);
12131   list = (TList*) gFile->Get("histosPhiCorrelationsQA");
12132   prim = (TH2*) list->FindObject("fDCAPrimaries");
12133   sec  = (TH2*) list->FindObject("fDCASecondaries");
12134   
12135   Float_t zCut = 0.5;
12136
12137   TH2* histList[] = { prim, sec };
12138
12139   TH1* primProj = 0;
12140   TH1* secProj = 0;
12141   
12142   for (Int_t i=0; i<2; i++)
12143   {
12144     new TCanvas;
12145     gPad->SetGridx();
12146     gPad->SetGridy();
12147     gPad->SetLogy();
12148   
12149 //     hist = histList[i]->ProjectionX("proj", prim->GetYaxis()->FindBin(-zCut), prim->GetYaxis()->FindBin(zCut))->DrawCopy("");
12150     hist = histList[i]->ProjectionY("proj", prim->GetXaxis()->FindBin(-zCut), prim->GetXaxis()->FindBin(zCut))->DrawCopy("");
12151     hist->SetStats(0);
12152     
12153     func = new TF1("func", "gaus(0)+gaus(3)");
12154     func->SetParameters(1e6, 0, 0.02, 1e3, 0, 2);
12155     func->FixParameter(1, 0);
12156     func->FixParameter(4, 0);
12157     func->SetParLimits(2, 0, 0.1);
12158     func->SetParLimits(5, 1, 3);
12159     
12160     hist->Fit(func, "", "", -2, 2);
12161     
12162     func2 = new TF1("func2", "gaus(0)");
12163     func2->SetParameters(1e3, 0, 2);
12164     func2->FixParameter(1, 0);
12165     func2->SetParLimits(2, 0.5, 5);
12166     
12167     hist->Fit(func2, "+", "", -2, -1);
12168     func2->SetRange(-3, 3);
12169     func2->Draw("SAME");
12170
12171 //     break;
12172   }
12173 }
12174
12175 void CompareDCADistributions(const char* fileName1, const char* fileName2)
12176 {
12177   TFile::Open(fileName1);
12178   list = (TList*) gFile->Get("histosPhiCorrelationsQA");
12179   prim = (TH2*) list->FindObject("fDCAPrimaries");
12180   sec  = (TH2*) list->FindObject("fDCASecondaries");
12181   
12182   TFile::Open(fileName2);
12183   list = (TList*) gFile->Get("histosPhiCorrelationsQA");
12184   all = (TH2*) list->FindObject("fDCAPrimaries");
12185   
12186   Float_t zCut = 3.2;
12187   
12188   TH2* histList[] = { prim, sec, all };
12189   
12190   Float_t count = 0;
12191   
12192   TH1* primProj = 0;
12193   TH1* secProj = 0;
12194   
12195   new TCanvas;
12196   gPad->SetGridx();
12197   gPad->SetGridy();
12198   
12199   for (Int_t i=0; i<3; i++)
12200   {
12201     hist = histList[i]->ProjectionX("proj", prim->GetYaxis()->FindBin(-zCut), prim->GetYaxis()->FindBin(zCut))->DrawCopy(i>0?"SAME":"");
12202     hist->SetStats(0);
12203     //hist = histList[i]->ProjectionY("proj", prim->GetXaxis()->FindBin(-zCut), prim->GetXaxis()->FindBin(zCut))->DrawCopy(i>0?"SAME":"");
12204     hist->SetLineColor(i+1);
12205     if (i == 0)
12206       primProj = hist;
12207     if (i == 1)
12208       secProj = hist;
12209     if (i == 2)
12210       hist->Scale(1.0 / hist->Integral(hist->GetXaxis()->FindBin(-0.5), hist->GetXaxis()->FindBin(0.5)) * count);
12211     else
12212       count += hist->Integral(hist->GetXaxis()->FindBin(-0.5), hist->GetXaxis()->FindBin(0.5));
12213   }
12214   
12215   gPad->SetLogy();
12216   
12217   ratio = (TH1*) hist->Clone("ratio");
12218   ratio->Add(primProj, -1);
12219   
12220 /*  for (Int_t i=hist->GetXaxis()->FindBin(-0.1); i<=hist->GetXaxis()->FindBin(0.1); i++)
12221     ratio->SetBinContent(i, 0);*/
12222   
12223   for (Int_t i=1; i<=hist->GetNbinsX(); i++)
12224     ratio->SetBinError(i, 0);
12225   
12226   ratio->SetLineColor(4);
12227   ratio->DrawCopy("SAME E");
12228   
12229   new TCanvas;
12230   gPad->SetGridx();
12231   gPad->SetGridy();
12232   
12233   ratio->Rebin(4);
12234   secProj = (TH1*) secProj->Clone();
12235   secProj->Rebin(4);
12236   
12237   ratio->Divide(secProj);
12238   
12239 /*  for (Int_t i=1; i<=hist->GetNbinsX(); i++)
12240     ratio->SetBinError(i, 0);*/
12241   
12242   ratio->Draw("HIST");
12243   ratio->GetYaxis()->SetRangeUser(0.7, 1.3);
12244   
12245   ratio->Fit("pol0", "0+", "", -5, -1);
12246   ratio->Fit("pol0", "0+", "", 1, 5);
12247 }
12248  
12249 void TrackCuts_CompareParameters(const char* fileName1, const char* fileName2, const char* histName, const char* cutFolder = "cuts_quality_only")
12250 {
12251   // plotWhich: 0 = only before
12252   //            1 = both
12253   //            2 = only after
12254   //
12255   // mirror: kTRUE --> project negative values on the positive side
12256   
12257   Int_t plotWhich = 0;
12258   Bool_t mirror = kFALSE;
12259   
12260   TFile* files[2];
12261   files[0] = TFile::Open(fileName1);
12262   files[1] = TFile::Open(fileName2);
12263
12264   Int_t count = 0;
12265   Int_t colors[] = { 1, 2, 3, 4, 5, 6 };
12266
12267   TLegend* legend = new TLegend(0.7, 0.85, 0.93, 0.98);
12268   legend->SetTextSize(0.04);
12269   legend->SetFillColor(0);
12270
12271   TCanvas* c1 = new TCanvas(histName, histName, 1200, 600);
12272   c1->Divide(2, 1);
12273   //TCanvas* c2 = new TCanvas("c2", "c2", 800, 600);
12274   //TCanvas* c3 = new TCanvas("c3", "c3", 800, 600);
12275
12276   const char* folders2[] = { "before_cuts", "after_cuts" };
12277   const char* names[] = { "MC", "Data" };
12278   Bool_t first = kTRUE;
12279   for (Int_t j = ((plotWhich < 2) ? 0 : 1); j < ((plotWhich > 0) ? 2 : 1); j++)
12280   {
12281     TH1* base = 0;
12282     TH1* base2 = 0;
12283     for (Int_t i = 0; i < 2; i++)
12284     {
12285       Printf("%d %d", j, i);
12286       TString folder;
12287       folder.Form("%s/%s/%s", cutFolder, folders2[j], histName);
12288       TH1* hist = (TH1*) files[i]->Get(folder);
12289       
12290       if (mirror)
12291       {
12292         for (Int_t bin=1; bin<=hist->GetXaxis()->FindBin(-0.0001); bin++)
12293         {
12294           Int_t newBin = hist->GetXaxis()->FindBin(-hist->GetXaxis()->GetBinCenter(bin));
12295           if (bin != newBin)
12296           {
12297             hist->Fill(-hist->GetXaxis()->GetBinCenter(bin), hist->GetBinContent(bin));
12298             hist->SetBinContent(bin, 0);
12299           }
12300         }
12301       }
12302       
12303       legend->AddEntry(hist, Form("%s %s", names[i], (plotWhich == 1) ? folders2[j] : " "));
12304
12305       c1->cd(1);
12306       hist->SetLineColor(colors[count]);
12307       hist->Scale(1.0 / hist->Integral());
12308       hist->SetStats(0);
12309       hist->DrawCopy((count == 0) ? "" : "SAME");
12310
12311       switch (i)
12312       {
12313         case 0: base = hist; break;
12314         case 1: base2 = hist; break;
12315       }
12316
12317       count++;
12318     }
12319     
12320     TH1* ratio = base;
12321     ratio->Divide(base2);
12322
12323     ratio->GetYaxis()->SetRangeUser(0, 2);
12324     
12325     c1->cd(2);
12326     ratio->DrawCopy((first) ? "" : "SAME");
12327     first = kFALSE;
12328   }
12329
12330   c1->cd(1)->SetLogy();
12331   c1->cd(1)->SetGridx();
12332   c1->cd(1)->SetGridy();
12333   legend->Draw();
12334   
12335   c1->cd(2)->SetGridx();
12336   c1->cd(2)->SetGridy();
12337   
12338   c1->SaveAs(Form("%s.png", histName));
12339 }
12340
12341 void PlotQA(const char* fileName, const char* tag = "")
12342 {
12343   loadlibs();
12344   
12345   if (!gGrid && TString(fileName).BeginsWith("alien://"))
12346     TGrid::Connect("alien://");
12347   
12348   TFile::Open(fileName);
12349   
12350   // phys sel
12351   Int_t runNumber = 0;
12352   list = (TList*) gFile->Get("PhysSel");
12353   if (list)
12354   {
12355     physSel = (AliPhysicsSelection*) list->FindObject("AliPhysicsSelection");
12356 //     runNumber = physSel->GetCurrentRun();
12357   }
12358   
12359   TString tmp(fileName);
12360   tmp.ReplaceAll("alien:///alice/cern.ch/user/j/jgrosseo/gridjob/dir_", "");
12361   tmp.ReplaceAll(".root", ".png");
12362   tmp.ReplaceAll("/", "-");
12363   TString title;
12364   title.Form("QA_%d_%s", runNumber, tmp.Data());
12365   c = new TCanvas(title, title, 1200, 800);
12366   c->Divide(3, 3);
12367
12368   // QA task
12369   list = (TList*) gFile->Get("histosPhiCorrelationsQA");
12370   if (list)
12371   {
12372     prim = (TH2*) list->FindObject("fDCAPrimaries");
12373     dcaxy = prim->ProjectionX("dcaxy", prim->GetYaxis()->FindBin(-3.2), prim->GetYaxis()->FindBin(3.2));
12374     dcaz = prim->ProjectionY("dcaz", prim->GetXaxis()->FindBin(-2.4), prim->GetXaxis()->FindBin(2.4));
12375     centrCorr = (TH2*) list->FindObject("fCentralityCorrelation");
12376     
12377     c->cd(1); dcaxy->Draw(); dcaz->SetLineColor(2); dcaz->Draw("SAME");  gPad->SetLogy(); 
12378     c->cd(6); centrCorr->Draw("COLZ"); gPad->SetLogz();
12379   
12380     cuts = (AliESDtrackCuts*) list->FindObject("cuts_quality_dca");
12381     if (cuts)
12382     {
12383       cluster = cuts->GetNClustersTPC(1);
12384       c->cd(3); cluster->Draw();
12385     
12386       ptall = (TH1F*) cuts->GetPtHist(1)->Clone("ptall");
12387       if (ptall->Integral() > 0)
12388         ptall->Scale(1.0 / ptall->Integral());
12389     
12390       c->cd(7); 
12391       ptall->Draw(); 
12392
12393       TH1* ptIts = 0;
12394       check_its = (AliESDtrackCuts*) list->FindObject("check_its");
12395       if (check_its)
12396       {
12397         ptIts = (TH1F*) check_its->GetPtHist(1)->Clone("ptIts");
12398         if (ptIts->Integral() > 0)
12399           ptIts->Scale(1.0 / ptIts->Integral());
12400       }
12401       
12402       TH1* ptItsAcc = 0;
12403       global_cuts = (AliESDtrackCuts*) list->FindObject("global_cuts");
12404       if (global_cuts)
12405       {
12406         ptItsAcc = (TH1*) global_cuts->GetPtHist(1)->Clone("ptItsAcc");
12407         if (ptItsAcc->Integral() > 0)
12408           ptItsAcc->Scale(1.0 / ptItsAcc->Integral());
12409       }
12410     
12411       if (ptIts)
12412       {
12413         ptIts->SetLineColor(2); 
12414         ptIts->Draw("SAME");
12415       }
12416       
12417       if (ptItsAcc)
12418       {
12419         ptItsAcc->SetLineColor(4); 
12420         ptItsAcc->Draw("SAME"); 
12421       }
12422       
12423       gPad->SetLogy();
12424     }
12425   }
12426   
12427   // centrality task
12428   list = (TList*) gFile->Get("CentralityStat");
12429   TH1* centrQuality = 0;
12430   if (list)
12431   {
12432     centrQuality = (TH1*) list->FindObject("fHOutQuality");
12433     
12434     c->cd(4); if (centrQuality) centrQuality->Draw();
12435   }
12436   
12437   // phi corr task
12438   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName, 0, kFALSE, tag);
12439   
12440   if (h->GetUEHist(2)->GetTrackHist(0)->GetGrid(6)->GetGrid()->GetNbins() == 0)
12441   {
12442     Printf("We have %d axes", ((AliTHn*) h->GetUEHist(2)->GetTrackHist(0)->GetNVar()));
12443     
12444 //     ((AliTHn*) h->GetUEHist(2)->GetTrackHist(0))->ReduceAxis();
12445     ((AliTHn*) h->GetUEHist(2)->GetTrackHist(0))->FillParent();
12446     ((AliTHn*) h->GetUEHist(2)->GetTrackHist(0))->DeleteContainers();
12447   }
12448   centr = h->GetCentralityDistribution();
12449   NormalizeToBinWidth(centr);
12450   Int_t events = (Int_t) h->GetEventCount()->ProjectionX()->GetBinContent(3);
12451   Int_t mergeCount = h->GetMergeCount();
12452   
12453   h->SetPtRange(1.01, 3.99);
12454   dphi_corr = h->GetUEHist(2)->GetUEHist(AliUEHist::kCFStepReconstructed, 0, 1.01, 14.99, 1, 8);
12455   if (dphi_corr->GetEntries() == 0)
12456     dphi_corr = h->GetUEHist(2)->GetUEHist(AliUEHist::kCFStepReconstructed+2, 0, 1.01, 14.99, 1, 8);
12457   if (dphi_corr->GetEntries() == 0)
12458     dphi_corr = h->GetUEHist(2)->GetUEHist(AliUEHist::kCFStepAll, 0, 1.01, 14.99, 1, 8);
12459   
12460   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE, tag);
12461   if (hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(6)->GetGrid()->GetNbins() == 0)
12462   {
12463 //     ((AliTHn*) hMixed->GetUEHist(2)->GetTrackHist(0))->ReduceAxis();
12464     ((AliTHn*) hMixed->GetUEHist(2)->GetTrackHist(0))->FillParent();
12465   }
12466
12467   Float_t ptMin = 0.51;
12468   hMixed->SetPtRange(ptMin, 3.99);
12469   dphi_corr_mixed = hMixed->GetUEHist(2)->GetUEHist(AliUEHist::kCFStepReconstructed, 0, ptMin, 14.99, 1, 8);
12470   if (dphi_corr_mixed->GetEntries() == 0)
12471     dphi_corr_mixed = hMixed->GetUEHist(2)->GetUEHist(AliUEHist::kCFStepReconstructed+2, 0, ptMin, 14.99, 1, 8);
12472   if (dphi_corr_mixed->GetEntries() == 0)
12473     dphi_corr_mixed = hMixed->GetUEHist(2)->GetUEHist(AliUEHist::kCFStepAll, 0, ptMin, 14.99, 1, 8);
12474   
12475   if (runNumber != 0 && runNumber != h->GetRunNumber())
12476     AliFatal("Run numbers inconsistent");
12477
12478   Printf("%d", h->GetRunNumber());
12479   if (runNumber == 0)
12480     runNumber = h->GetRunNumber();
12481  
12482   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");
12483   c->cd(5); centr->Draw("HIST");
12484   
12485   c->cd(1);
12486   latex = new TLatex(0.15, 0.8, Form("%d events, %d merged objects", events, mergeCount));
12487   latex->SetTextSize(0.075);
12488   latex->SetNDC();
12489   latex->Draw();
12490   
12491   c->cd(8);
12492   h->GetEventCount()->Draw("TEXT");
12493   
12494   title.Form("QA_%d_%s", runNumber, tmp.Data());
12495   c->SetTitle(title);
12496   
12497   gpTMin = 1.01;
12498   gpTMax = 1.99;
12499   h->SetPtRange(gpTMin, gpTMax);
12500   hMixed->SetPtRange(gpTMin, gpTMax);
12501  
12502   TH2* hist1 = 0;
12503   
12504   //h->GetUEHist(2)->SetSkipScaleMixedEvent(kTRUE);
12505   
12506   if (h->GetUEHist(2)->GetTrackHist(0)->GetNVar() > 5)
12507   {
12508     Int_t step = 8;
12509     
12510     c->cd(3);
12511     GetDistAndFlow(h, 0, &hist1,  0, step, 0, 20, 2.01, 2.99, 1);
12512     hist1->DrawCopy("SURF1");
12513
12514     c->cd(6);
12515     GetDistAndFlow(hMixed, 0, &hist1,  0, step, 0, 20, 2.01, 2.99, 1);
12516     hist1->DrawCopy("SURF1");
12517     
12518     c->cd(9);
12519     GetSumOfRatios(h, hMixed, &hist1, step, 0, 20, 2.01, 2.99, kTRUE); 
12520     if (hist1)
12521       hist1->DrawCopy("SURF1");  
12522   }
12523
12524   c->SaveAs(Form("qa/%s", c->GetTitle()));
12525 }
12526
12527 void GetEventNumber(const char* fileName)
12528 {
12529   loadlibs();
12530   
12531   new TCanvas("c1", "", 800, 600);
12532  
12533   Int_t nEvent = 0;
12534
12535   TFile::Open(fileName);
12536   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
12537   centr = h->GetCentralityDistribution();
12538   nEvent = h->GetCentralityDistribution()->Integral(h->GetCentralityDistribution()->FindBin(0.01), h->GetCentralityDistribution()->FindBin(59.99));
12539
12540   cout << "Number of events: " <<  nEvent << endl;
12541   centr->Draw("HIST");
12542 }
12543 void CompareStepsOnePlot(const char* fileName, Int_t caseId)
12544 {
12545   loadlibs();
12546
12547   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
12548   
12549   Int_t stepList[] = { 0, 1, 2, 4, 5, 6 };
12550   Int_t stepListNames[] = { 0, 1, 2, 3, 4, 5 };
12551   Int_t nSteps = 6;
12552   //const char* names[] = { "All", "PhysSel+Vertex", "Reco Primaries", "Reco "
12553 //   //Int_t stepList[] = { 2, 4, 5, 6 };
12554 //   
12555 //   
12556 //   TH1* hist1 = h->GetUEHist(2)->GetUEHist(0, 0, 6.01, 9.99, 6, 14);
12557 //   TH1* hist2 = h->GetUEHist(2)->GetUEHist(0, 0, 6.01, 7.99, 6, 14);
12558 //   TH1* hist3 = h->GetUEHist(2)->GetUEHist(0, 0, 8.01, 9.99, 6, 14);
12559 //   
12560 //   hist1->Draw();
12561 //   hist2->SetLineColor(2);
12562 //   hist2->Draw("SAME");
12563 //   hist3->SetLineColor(4);
12564 //   hist3->Draw("SAME");
12565 //   return;
12566 //   
12567   
12568   legend = new TLegend(0.65, 0.45, 0.85, 0.85);
12569   legend->SetTextSize(0.04);
12570   legend->SetFillColor(0);
12571   
12572   TH1* histList[10];
12573   
12574   for (Int_t i=0; i<nSteps; i++)
12575   {
12576     //TH1* hist1 = h->GetUEHist(2)->GetEventHist()->Project(stepList[i], 0);
12577     
12578 /*    h->GetUEHist(2)->GetTrackHist(0)->GetGrid(stepList[i])->GetGrid()->GetAxis(1)->SetRangeUser(1.01, 3.99);
12579     h->GetUEHist(2)->GetTrackHist(0)->GetGrid(stepList[i])->GetGrid()->GetAxis(2)->SetRangeUser(4.01, 19.99);
12580     TH1* hist1 = h->GetUEHist(2)->GetTrackHist(0)->Project(stepList[i], 4);*/
12581     
12582     if (caseId == 0)
12583       TH1* hist1 = h->GetUEHist(2)->GetUEHist(stepList[i], 0, 1.01, 19.99);
12584     else if (caseId == 1)
12585       TH1* hist1 = h->GetUEHist(2)->GetEventHist()->Project(stepList[i], 0);
12586     
12587     //hist1->Rebin(2);
12588     //hist1->Rebin(4);
12589     hist1->SetMarkerStyle(24+i);
12590     hist1->SetTitle("");
12591     hist1->SetStats(0);
12592     hist1->DrawCopy((i==0)?"":"SAME");
12593     hist1->Fit("pol0", "0");
12594     //hist1->Fit("pol0");
12595     histList[i] = hist1;
12596     legend->AddEntry(hist1, Form("Step %d", stepListNames[i]), "P");
12597   }
12598   
12599   legend->Draw();
12600   
12601   new TCanvas;
12602   legend = new TLegend(0.65, 0.45, 0.85, 0.85);
12603   legend->SetTextSize(0.04);
12604   legend->SetFillColor(0);
12605   
12606   for (Int_t i=1; i<nSteps; i++)
12607   {
12608     histList[i]->DrawCopy((i==1)?"":"SAME")->Divide(histList[i-1]);
12609     legend->AddEntry(histList[i], Form("Step %d/%d", stepListNames[i], stepListNames[i-1]), "P");
12610   }
12611   
12612   legend->Draw();
12613   
12614   new TCanvas;
12615   for (Int_t i=0; i<nSteps; i++)
12616   {
12617     hist1 = histList[i];
12618     func = new TF1("func", "[0]", -10, 10);
12619     hist1->Fit(func, "0", "", 1, 2);
12620     hist1->Add(func, -1);
12621     hist1->DrawCopy((i==0)?"":"SAME");
12622   }
12623   
12624   legend->Draw();
12625   
12626   new TCanvas;
12627   for (Int_t i=1; i<nSteps; i++)
12628   {
12629     histList[i]->DrawCopy((i==1)?"":"SAME")->Divide(histList[i-1]);
12630   }
12631   
12632   legend->Draw();
12633 }
12634
12635 void PtShift(const char* fileName)
12636 {
12637   loadlibs();
12638
12639   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
12640   
12641   new TCanvas;
12642   gPad->SetLogy();
12643   
12644   ptHist3 = h->GetCorrelationpT()->ProjectionY();
12645   ptHist3->GetXaxis()->SetRangeUser(0, 20);
12646   //ptHist3->Sumw2();
12647   
12648   /*
12649   func = new TF1("func", "[0]+[1]*x**[2]", 4, 20);
12650   func->SetParLimits(2, -10, -1);
12651   func->SetParameters(0, 1, -4);
12652   ptHist3->Fit(func, "", "", 4, 20);
12653   
12654   return;
12655   */
12656   
12657   ptHist3Shifted = (TH1*) ptHist3->Clone("ptHist3Shifted");
12658   for (Int_t i=1; i<ptHist3Shifted->GetNbinsX(); i++)
12659     //ptHist3Shifted->SetBinContent(i, ptHist3Shifted->GetBinContent(i+3));
12660     ptHist3Shifted->SetBinContent(i, ptHist3Shifted->GetBinContent(1.1*i));
12661   
12662   // 10% or 750 MeV
12663     
12664   ptHist3Shifted->SetLineColor(2);
12665   
12666   ptHist3->Rebin(2);
12667   ptHist3Shifted->Rebin(2);
12668   
12669   ptHist3->DrawCopy();
12670   ptHist3Shifted->DrawCopy("SAME");
12671   
12672   new TCanvas;
12673   ptHist3->Divide(ptHist3Shifted);
12674   ptHist3->Draw();
12675   
12676   //ptHist3->Rebin(2); ptHist3->Scale(1.0 / 2);
12677   
12678   gPad->SetGridx();
12679   gPad->SetGridy();
12680 }
12681
12682 void RAA(const char* fileName, const char* fileName2)
12683 {
12684   loadlibs();
12685   
12686   TH1* hist[2];
12687   
12688   for (Int_t j=0; j<2; j++)
12689   {
12690     if (j == 0)
12691       AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
12692     else
12693     {
12694       if (!fileName2)
12695         break;
12696         
12697       AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName2);
12698     }
12699   
12700     ptHist3 = h->GetCorrelationpT()->ProjectionY(Form("proj1_%d", j), 1, 5);
12701     ptHist3->GetXaxis()->SetRangeUser(0, 20);
12702     
12703     //h->GetCentralityDistribution()->Draw(); new TCanvas;
12704     
12705     Int_t nEvents = h->GetCentralityDistribution()->Integral(h->GetCentralityDistribution()->FindBin(0.01), h->GetCentralityDistribution()->FindBin(4.99));
12706     Printf("%d", nEvents);
12707     ptHist3->Scale(1.0 / 1.6 / TMath::TwoPi() / nEvents / ptHist3->GetBinWidth(1));
12708     
12709     hist[j] = ptHist3;
12710   }
12711   
12712   new TCanvas;
12713   hist[0]->DrawCopy("");
12714   hist[1]->DrawCopy("SAME")->SetLineColor(2);
12715   gPad->SetLogy();
12716   
12717   new TCanvas;
12718   hist[1]->Divide(hist[0]);
12719   hist[1]->DrawCopy();
12720   
12721   raa_central = ReadHepdata("raa_alice_central.txt", kFALSE, 3);
12722   raa_central->SetMarkerStyle(20);
12723   raa_central->Draw("PSAME");
12724 }
12725
12726 void PtComparison(const char* fileName, const char* fileName2 = 0, const char* tag = 0)
12727 {
12728   loadlibs();
12729
12730   c = new TCanvas;
12731   c2 = new TCanvas;
12732   c2->SetGridx();
12733   c2->SetGridy();
12734     
12735   for (Int_t j=0; j<2; j++)
12736   {
12737     if (j == 0)
12738       AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName, 0, kFALSE, tag);
12739     else
12740     {
12741       if (!fileName2)
12742         break;
12743         
12744       AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName2, 0, kFALSE, tag);
12745     }
12746     
12747     ptHist3 = h->GetInvYield()->ProjectionY("pt1", h->GetInvYield()->GetXaxis()->FindBin(0.01), h->GetInvYield()->GetXaxis()->FindBin(4.99));
12748     ptHist3->GetXaxis()->SetRangeUser(0, 20);
12749     
12750     //h->GetCentralityDistribution()->Draw(); new TCanvas;
12751     
12752     Int_t nEvents = h->GetCentralityDistribution()->Integral(h->GetCentralityDistribution()->FindBin(0.01), h->GetCentralityDistribution()->FindBin(4.99));
12753     Printf("%d", nEvents);
12754     ptHist3->Scale(1.0 / 1.6 / TMath::TwoPi() / nEvents / ptHist3->GetBinWidth(1));
12755     
12756     c->cd();
12757     ptHist3->SetLineStyle(j+1);
12758     ptHist3->DrawCopy((j == 0) ? "HIST" : "HISTSAME")->SetLineColor(1);
12759     
12760     centralPt = (TH1*) ptHist3->Clone();
12761   
12762     if (1)
12763     {
12764       ptHist3 = h->GetInvYield()->ProjectionY("pt2", h->GetInvYield()->GetXaxis()->FindBin(70.01), h->GetInvYield()->GetXaxis()->FindBin(79.99));
12765       ptHist3->GetXaxis()->SetRangeUser(0, 20);
12766     
12767       Int_t nEvents = h->GetCentralityDistribution()->Integral(h->GetCentralityDistribution()->FindBin(70.1), h->GetCentralityDistribution()->FindBin(79.9));
12768       Printf("%d", nEvents);
12769       ptHist3->Scale(1.0 / 1.6 / TMath::TwoPi() / nEvents / ptHist3->GetBinWidth(1));
12770     
12771       ptHist3->SetLineStyle(j+1);
12772       ptHist3->DrawCopy("HISTSAME")->SetLineColor(2);
12773     }
12774     peripheralPt = (TH1*) ptHist3->Clone();
12775
12776     if (1)
12777     {
12778       ptHist3 = h->GetInvYield()->ProjectionY("pt3", h->GetInvYield()->GetXaxis()->FindBin(20.01), h->GetInvYield()->GetXaxis()->FindBin(29.99));
12779       ptHist3->GetXaxis()->SetRangeUser(0, 20);
12780     
12781       Int_t nEvents = h->GetCentralityDistribution()->Integral(h->GetCentralityDistribution()->FindBin(20.1), h->GetCentralityDistribution()->FindBin(29.9));
12782       Printf("%d", nEvents);
12783       ptHist3->Scale(1.0 / 1.6 / TMath::TwoPi() / nEvents / ptHist3->GetBinWidth(1));
12784     
12785       ptHist3->SetLineStyle(j+1);
12786       ptHist3->DrawCopy("HISTSAME")->SetLineColor(4);
12787     }
12788     
12789     if (0)
12790     {
12791       // first paper
12792       dndpt_central = ReadHepdata("raa_dndpt_central.txt", kFALSE, 3);
12793       dndpt_peripheral = ReadHepdata("raa_dndpt_peripheral.txt", kFALSE, 3);
12794     }
12795     else
12796     {
12797       // second paper
12798       dndpt_central = ReadHepdata("raa2_dndpt_05.txt", kFALSE, 1, 3);
12799       dndpt_midcentral = ReadHepdata("raa2_dndpt_2030.txt", kFALSE, 1, 3);
12800       dndpt_peripheral = ReadHepdata("raa2_dndpt_7080.txt", kFALSE, 1, 3);
12801     }
12802   
12803 //   RemovePointsBelowX(dndpt_central, 1);
12804 //   RemovePointsBelowX(dndpt_peripheral, 1);
12805 //   
12806 //   NormalizeTo(dndpt_central, 1);
12807 //   NormalizeTo(dndpt_peripheral, 10);
12808
12809     dndpt_central->Draw("*SAME");
12810     dndpt_peripheral->SetLineColor(2);
12811     dndpt_peripheral->SetMarkerColor(2);
12812     dndpt_peripheral->Draw("*SAME");
12813     dndpt_midcentral->SetLineColor(4);
12814     dndpt_midcentral->SetMarkerColor(4);
12815     dndpt_midcentral->Draw("*SAME");
12816     
12817     gPad->SetLogy();
12818     
12819     c2->cd();
12820     
12821     for (Int_t i=1; i<ptHist3->GetNbinsX(); i++)
12822       ptHist3->SetBinContent(i, ptHist3->GetBinContent(i) / dndpt_midcentral->Eval(ptHist3->GetBinCenter(i), 0, "S"));
12823   
12824     for (Int_t i=1; i<centralPt->GetNbinsX(); i++)
12825       centralPt->SetBinContent(i, centralPt->GetBinContent(i) / dndpt_central->Eval(centralPt->GetBinCenter(i), 0, "S"));
12826   
12827     for (Int_t i=1; i<peripheralPt->GetNbinsX(); i++)
12828       peripheralPt->SetBinContent(i, peripheralPt->GetBinContent(i) / dndpt_peripheral->Eval(peripheralPt->GetBinCenter(i), 0, "S"));
12829
12830 //     ptHist3->Rebin(2); ptHist3->Scale(0.5);
12831 //     centralPt->Rebin(2); centralPt->Scale(0.5);
12832   
12833     ptHist3->GetXaxis()->SetRangeUser(0.51, 19);
12834     ptHist3->GetYaxis()->SetRangeUser(0.5, 1.5);
12835     ptHist3->DrawCopy((j == 0) ? "" : "SAME")->SetLineColor(4);
12836     centralPt->DrawCopy("SAME")->SetLineColor(1);
12837     peripheralPt->DrawCopy("SAME")->SetLineColor(2);
12838   }
12839 }
12840
12841 void PtComparisonOld(const char* fileName, const char* fileName2 = 0)
12842 {
12843   // use GetCorrectedYields to get input file
12844   
12845   loadlibs();
12846
12847   c = new TCanvas;
12848   c2 = new TCanvas;
12849   c2->SetGridx();
12850   c2->SetGridy();
12851     
12852   for (Int_t j=0; j<2; j++)
12853   {
12854     if (j == 0)
12855     {
12856       TFile::Open(fileName);
12857     }
12858     else
12859     {
12860       if (!fileName2)
12861         break;
12862         
12863       TFile::Open(fileName2);
12864     }
12865     yieldCorr = (TH3F*) gFile->Get("fYieldsCorr");
12866     eventDist = (TH1*) gFile->Get("events");
12867     
12868     //new TCanvas; h->GetCorrelationpT()->Draw("COLZ");
12869     
12870     yieldCorr->GetXaxis()->SetRangeUser(0.1, 4.9);
12871     yieldCorr->GetZaxis()->SetRangeUser(-0.79, 0.79);
12872     
12873     ptHist3 = yieldCorr->Project3D(Form("y1_%d", j));
12874     ptHist3->GetXaxis()->SetRangeUser(0, 20);
12875     
12876     //h->GetCentralityDistribution()->Draw(); new TCanvas;
12877     
12878     Int_t nEvents = eventDist->Integral(eventDist->FindBin(0.1), eventDist->FindBin(4.9));
12879     Printf("%d", nEvents);
12880     ptHist3->Scale(1.0 / 1.6 / TMath::TwoPi() / nEvents / ptHist3->GetBinWidth(1));
12881     
12882     //ptHist3->Scale(1690);
12883     //ptHist3->Scale(1.0 / ptHist3->Integral(ptHist3->GetXaxis()->FindBin(1.01), ptHist3->GetNbinsX()) / 3 / 0.6);
12884     
12885     for (Int_t i=2; i<ptHist3->GetNbinsX(); i++)
12886       ptHist3->SetBinContent(i, ptHist3->GetBinContent(i) / ptHist3->GetBinCenter(i));
12887       //ptHist3->SetBinContent(i, ptHist3->GetBinContent(i) / ptHist3->GetBinLowEdge(i));
12888     
12889     //AliPWG0Helper::NormalizeToBinWidth(ptHist3);
12890     
12891     c->cd();
12892     ptHist3->SetLineStyle(j+1);
12893     ptHist3->DrawCopy((j == 0) ? "HIST" : "HISTSAME")->SetLineColor(1);
12894
12895     centralPt = (TH1*) ptHist3->Clone();
12896   
12897     if (1)
12898     {
12899       yieldCorr->GetZaxis()->SetRangeUser(-0.79, 0.79);
12900       yieldCorr->GetXaxis()->SetRangeUser(70.1, 79.9);
12901       ptHist3 = yieldCorr->Project3D(Form("y2_%d", j));
12902       ptHist3->GetXaxis()->SetRangeUser(0, 20);
12903     
12904       Int_t nEvents = eventDist->Integral(eventDist->FindBin(70.1), eventDist->FindBin(79.9));
12905       Printf("%d", nEvents);
12906       ptHist3->Scale(1.0 / 1.6 / TMath::TwoPi() / nEvents / ptHist3->GetBinWidth(1));
12907     
12908       for (Int_t i=2; i<ptHist3->GetNbinsX(); i++)
12909         ptHist3->SetBinContent(i, ptHist3->GetBinContent(i) / ptHist3->GetBinCenter(i));
12910         //ptHist3->SetBinContent(i, ptHist3->GetBinContent(i) / ptHist3->GetBinLowEdge(i));
12911
12912       ptHist3->SetLineStyle(j+1);
12913       ptHist3->DrawCopy("HISTSAME")->SetLineColor(2);
12914     }
12915     peripheralPt = (TH1*) ptHist3->Clone();
12916
12917     if (1)
12918     {
12919       yieldCorr->GetZaxis()->SetRangeUser(-0.79, 0.79);
12920       yieldCorr->GetXaxis()->SetRangeUser(20.1, 29.9);
12921       ptHist3 = yieldCorr->Project3D(Form("y2_%d", j));
12922       ptHist3->GetXaxis()->SetRangeUser(0, 20);
12923     
12924       Int_t nEvents = eventDist->Integral(eventDist->FindBin(20.1), eventDist->FindBin(29.9));
12925       Printf("%d", nEvents);
12926       ptHist3->Scale(1.0 / 1.6 / TMath::TwoPi() / nEvents / ptHist3->GetBinWidth(1));
12927     
12928       for (Int_t i=2; i<ptHist3->GetNbinsX(); i++)
12929         ptHist3->SetBinContent(i, ptHist3->GetBinContent(i) / ptHist3->GetBinCenter(i));
12930         //ptHist3->SetBinContent(i, ptHist3->GetBinContent(i) / ptHist3->GetBinLowEdge(i));
12931
12932       ptHist3->SetLineStyle(j+1);
12933       ptHist3->DrawCopy("HISTSAME")->SetLineColor(4);
12934     }
12935     
12936     if (0)
12937     {
12938       // first paper
12939       dndpt_central = ReadHepdata("raa_dndpt_central.txt", kFALSE, 3);
12940       dndpt_peripheral = ReadHepdata("raa_dndpt_peripheral.txt", kFALSE, 3);
12941     }
12942     else
12943     {
12944       // second paper
12945       dndpt_central = ReadHepdata("raa2_dndpt_05.txt", kFALSE, 1, 3);
12946       dndpt_midcentral = ReadHepdata("raa2_dndpt_2030.txt", kFALSE, 1, 3);
12947       dndpt_peripheral = ReadHepdata("raa2_dndpt_7080.txt", kFALSE, 1, 3);
12948     }
12949   
12950 //   RemovePointsBelowX(dndpt_central, 1);
12951 //   RemovePointsBelowX(dndpt_peripheral, 1);
12952 //   
12953 //   NormalizeTo(dndpt_central, 1);
12954 //   NormalizeTo(dndpt_peripheral, 10);
12955
12956     dndpt_central->Draw("*SAME");
12957     dndpt_peripheral->SetLineColor(2);
12958     dndpt_peripheral->SetMarkerColor(2);
12959     dndpt_peripheral->Draw("*SAME");
12960     dndpt_midcentral->SetLineColor(4);
12961     dndpt_midcentral->SetMarkerColor(4);
12962     dndpt_midcentral->Draw("*SAME");
12963     
12964     gPad->SetLogy();
12965     
12966     c2->cd();
12967     
12968     for (Int_t i=1; i<ptHist3->GetNbinsX(); i++)
12969       ptHist3->SetBinContent(i, ptHist3->GetBinContent(i) / dndpt_midcentral->Eval(ptHist3->GetBinCenter(i), 0, "S"));
12970   
12971     for (Int_t i=1; i<centralPt->GetNbinsX(); i++)
12972       centralPt->SetBinContent(i, centralPt->GetBinContent(i) / dndpt_central->Eval(centralPt->GetBinCenter(i), 0, "S"));
12973   
12974     for (Int_t i=1; i<peripheralPt->GetNbinsX(); i++)
12975       peripheralPt->SetBinContent(i, peripheralPt->GetBinContent(i) / dndpt_peripheral->Eval(peripheralPt->GetBinCenter(i), 0, "S"));
12976
12977 //     ptHist3->Rebin(2); ptHist3->Scale(0.5);
12978 //     centralPt->Rebin(2); centralPt->Scale(0.5);
12979   
12980     ptHist3->GetXaxis()->SetRangeUser(0.51, 19);
12981     ptHist3->GetYaxis()->SetRangeUser(0.5, 1.5);
12982     ptHist3->DrawCopy((j == 0) ? "" : "SAME")->SetLineColor(4);
12983     centralPt->DrawCopy("SAME")->SetLineColor(1);
12984     peripheralPt->DrawCopy("SAME")->SetLineColor(2);
12985   }
12986
12987   return;
12988   
12989   ReadYields("preliminaries/yields_110303.root");
12990   
12991   ptHist3->Scale(100);
12992   
12993   TGraphErrors** tmp = yields[0][1][0];
12994   nearSide = tmp[18];
12995   nearSide->Draw("* SAME");  
12996  
12997   TGraphErrors** tmp = yields[1][1][0];
12998   awaySide = tmp[18];
12999   awaySide->SetLineColor(2);
13000   awaySide->SetMarkerColor(2);
13001   awaySide->Draw("* SAME");  
13002   
13003 }
13004
13005 void style(Int_t styleId = 1)
13006 {
13007   gStyle->SetPalette(1);
13008   gStyle->SetCanvasColor(10);
13009   gStyle->SetHistFillColor(10);
13010   gStyle->SetHistFillStyle(0);
13011   gStyle->SetOptStat(0);
13012   gStyle->SetPadTickX(1);
13013   gStyle->SetPadTickY(1);
13014   gStyle->SetAxisColor(1, "X");
13015   gStyle->SetAxisColor(1, "Y");
13016   gStyle->SetAxisColor(1, "Z");
13017   gStyle->SetLabelColor(1, "X");
13018   gStyle->SetLabelColor(1, "Y");
13019   gStyle->SetLabelColor(1, "Z");
13020   gStyle->SetTickLength(0.03, "X");
13021   gStyle->SetTickLength(0.03, "Y");
13022   gStyle->SetTickLength(0.03, "Z");
13023   gStyle->SetTitleXSize(0.05);
13024   gStyle->SetTitleYSize(0.05);
13025   gStyle->SetNdivisions(506, "X");
13026   gStyle->SetNdivisions(506, "Y");
13027   gStyle->SetNdivisions(506, "Z");
13028   
13029   //gStyle->SetPadGridX(1);
13030   //gStyle->SetPadGridY(1);
13031
13032   //gStyle->SetLabelOffset(0.02, "X");
13033   //gStyle->SetLabelOffset(0.02, "Y");
13034   //gStyle->SetLabelOffset(0.02, "Z");
13035   gStyle->SetLabelSize(0.05, "X");
13036   gStyle->SetLabelSize(0.05, "Y");
13037   gStyle->SetLabelSize(0.05, "Z");
13038
13039   gStyle->SetPadLeftMargin(0.12);
13040   gStyle->SetPadRightMargin(0.02);
13041   gStyle->SetPadBottomMargin(0.13);
13042   gStyle->SetPadTopMargin(0.02);
13043
13044   gStyle->SetMarkerSize(1.4); // CKB
13045
13046   const int iFont = 42; // type * 10 + prec  6: helvetica bold 13: times normal 2: times bold
13047
13048 /*                                                               italic     weigth
13049 *-*        1 : times-medium-i-normal      "Times New Roman"      1           4
13050 *-*        2 : times-bold-r-normal        "Times New Roman"      0           7
13051 *-*        3 : times-bold-i-normal        "Times New Roman"      1           7
13052 *-*        4 : helvetica-medium-r-normal  "Arial"                0           4
13053 *-*        5 : helvetica-medium-o-normal  "Arial"                1           4
13054 *-*        6 : helvetica-bold-r-normal    "Arial"                0           7
13055 *-*        7 : helvetica-bold-o-normal    "Arial"                1           7
13056 *-*        8 : courier-medium-r-normal    "Courier New"          0           4
13057 *-*        9 : courier-medium-o-normal    "Courier New"          1           4
13058 *-*       10 : courier-bold-r-normal      "Courier New"          0           7
13059 *-*       11 : courier-bold-o-normal      "Courier New"          1           7
13060 *-*       12 : symbol-medium-r-normal     "Symbol"               0           6
13061 *-*       13 : times-medium-r-normal      "Times New Roman"      0           4
13062 *-*       14 :                            "Wingdings"            0           4
13063 */
13064
13065   //gStyle->SetTitleXOffset(1); // 1.1
13066   //gStyle->SetTitleYOffset(1); // 1-4
13067
13068   gStyle->SetLabelFont(iFont, "xyz");
13069   gStyle->SetStatFont(iFont);
13070   gStyle->SetTitleFont(iFont, "xyz");
13071   gStyle->SetTextFont(iFont);
13072   
13073   if (styleId == 2)
13074   {
13075     gStyle->SetLabelSize(0.07, "X");
13076     gStyle->SetLabelSize(0.07, "Y");
13077     gStyle->SetLabelSize(0.07, "Z");
13078     gStyle->SetTitleXSize(0.07);
13079     gStyle->SetTitleYSize(0.07);
13080   
13081     gStyle->SetPadLeftMargin(0.26);
13082     gStyle->SetPadRightMargin(0.01);
13083     gStyle->SetPadBottomMargin(0.15);
13084     gStyle->SetPadTopMargin(0.01);
13085   }
13086
13087   //gStyle->SetEndErrorSize(0.0);
13088
13089   gROOT->ForceStyle();
13090
13091 }
13092
13093 void NormalizeTo(TGraphErrors* graph, Float_t normalizeTo)
13094 {
13095         Float_t sum = 0;
13096         for (Int_t i=0; i<graph->GetN(); i++)
13097                 sum += graph->GetY()[i];
13098         
13099         if (normalizeTo > 0 && sum > 0)
13100         {
13101                 sum /= normalizeTo;
13102                 for (Int_t i=0; i<graph->GetN(); i++)
13103                 {
13104                         graph->SetPoint(i, graph->GetX()[i],  graph->GetY()[i] / sum);
13105                         graph->SetPointError(i, graph->GetEX()[i],  graph->GetEY()[i] / sum);
13106                 }
13107         }       
13108 }
13109
13110 void CompareMixedEvent(const char* fileName)
13111 {
13112   loadlibs();
13113   
13114   Float_t leadingPtArr[] = { 6.0, 8.0, 10.0, 15.0, 15.0 };
13115   Float_t assocPtArr[] =     { 0.5, 1.5, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
13116   Int_t leadingPtOffset = 2;
13117   Int_t centralityBins[] = { 0, 0, 1, 6, 9, 16 };
13118
13119   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);  
13120   
13121   Int_t i = 1;
13122   for (Int_t j=2; j<5; j++)
13123   {
13124     gpTMin = assocPtArr[j] + 0.01;
13125     gpTMax = assocPtArr[j+1] - 0.01;
13126     
13127     gpTMin = 3.0;
13128     gpTMax = 6.0;
13129
13130     SetupRanges(hMixed);
13131     
13132     TH2* mixed = hMixed->GetUEHist(2)->GetUEHist(6, 0, leadingPtArr[i] + 0.01, leadingPtArr[i+leadingPtOffset] - 0.01, centralityBins[j], centralityBins[j+1]-1, 1);
13133   
13134     // compare deta
13135     
13136     TH1* histMixedproj = mixed->ProjectionY();
13137     histMixedproj->Scale(1.0 / mixed->GetNbinsX());
13138     
13139     for (Int_t x=1; x<=mixed->GetNbinsX(); x++)
13140       for (Int_t y=1; y<=mixed->GetNbinsY(); y++)
13141         mixed->SetBinContent(x, y, histMixedproj->GetBinContent(y));
13142
13143     histMixedproj->Scale(1.0 / (0.5 * (histMixedproj->GetBinContent(histMixedproj->GetXaxis()->FindBin(-0.01)) + histMixedproj->GetBinContent(histMixedproj->GetXaxis()->FindBin(0.01)))));
13144       
13145     histMixedproj->DrawCopy((j == 2) ? "" : "SAME")->SetLineColor(j-1);
13146   }
13147 }
13148
13149 void FillParentTHnSparse(const char* fileName, Bool_t reduce = kFALSE, const char* tag = "")
13150 {
13151   TString fileNameStr(fileName);
13152   
13153   if (fileNameStr.BeginsWith("/alice"))
13154   {
13155     fileNameStr = Form("alien://%s", fileNameStr.Data());
13156     if (fileNameStr.EndsWith("merge"))
13157       fileNameStr += "/AnalysisResults.root";
13158   }
13159   
13160   if (fileNameStr.BeginsWith("alien:"))
13161     TGrid::Connect("alien:");
13162   
13163   loadlibs();
13164
13165   TList* list = 0;
13166   
13167   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileNameStr, &list, kFALSE, tag);
13168   Printf("We have %d axes", ((AliTHn*) h->GetUEHist(2)->GetTrackHist(0)->GetNVar()));
13169   
13170   if (reduce)
13171     ((AliTHn*) h->GetUEHist(2)->GetTrackHist(0))->ReduceAxis();
13172   ((AliTHn*) h->GetUEHist(2)->GetTrackHist(0))->FillParent();
13173   ((AliTHn*) h->GetUEHist(2)->GetTrackHist(0))->DeleteContainers();
13174   
13175   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileNameStr, 0, kTRUE, tag);
13176   if (reduce)
13177     ((AliTHn*) hMixed->GetUEHist(2)->GetTrackHist(0))->ReduceAxis();
13178   ((AliTHn*) hMixed->GetUEHist(2)->GetTrackHist(0))->FillParent();
13179   ((AliTHn*) hMixed->GetUEHist(2)->GetTrackHist(0))->DeleteContainers();
13180   
13181   TString newFileName(fileNameStr);
13182
13183   if (fileNameStr.BeginsWith("alien:"))
13184     newFileName = gSystem->BaseName(newFileName);
13185   
13186   newFileName.ReplaceAll(".root", "");
13187   if (reduce)
13188     newFileName += "_.root";
13189   else
13190     newFileName += "_zvtx.root";
13191
13192   file3 = TFile::Open(newFileName, "RECREATE");
13193   file3->mkdir("PWG4_PhiCorrelations");
13194   file3->cd("PWG4_PhiCorrelations");
13195   list->Write("histosPhiCorrelations", TObject::kSingleKey);
13196   file3->Close();
13197 }
13198
13199 void CompareZVertex(const char* fileName)
13200 {
13201   loadlibs();
13202   
13203   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
13204   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);  
13205   
13206   axis = h->GetUEHist(2)->GetEventHist()->GetAxis(2, 6);
13207   
13208   gpTMin = 2.01;
13209   gpTMax = 7.99;
13210   
13211   SetupRanges(h);
13212   SetupRanges(hMixed);
13213   
13214   TFile::Open("test.root", "RECREATE");
13215         
13216   for (Int_t i=0; i<=axis->GetNbins(); i++)
13217   {
13218     TH1* hist = 0;
13219     if (i > 0)
13220     {
13221       Printf("%d %f %f", i, axis->GetBinLowEdge(i) + 0.01, axis->GetBinUpEdge(i) - 0.01);
13222       h->SetZVtxRange(axis->GetBinLowEdge(i) + 0.01, axis->GetBinUpEdge(i) - 0.01);
13223       hMixed->SetZVtxRange(axis->GetBinLowEdge(i) + 0.01, axis->GetBinUpEdge(i) - 0.01);
13224     }
13225       
13226     GetDistAndFlow(h, hMixed, &hist, 0, 6, 0, 10, 2.01, 14.99, 1, kTRUE, 0, kFALSE);
13227     
13228     new TCanvas;
13229     hist->DrawCopy("SURF1");
13230     
13231     hist->Write(Form("detadphi_%d", i));
13232     
13233 //     if (i == 0)   break;
13234
13235     continue;
13236     
13237     hist->SetLineColor(i+1);
13238     hist->Scale(1.0 / hist->Integral() / hist->GetBinWidth(1));
13239     hist->Draw((i == 0) ? "" : "SAME");
13240   }
13241   
13242   gFile->Close();
13243 }
13244
13245 void DrawZRanges(Float_t min, Float_t max)
13246 {
13247   legend = new TLegend(0.5, 0.5, 0.8, 0.8);
13248   
13249   TFile::Open("test.root");
13250   
13251   for (Int_t i=0; i<8; i++)
13252   {
13253     if (i == 1 || i == 7)
13254       continue;
13255     
13256     hist = (TH2*) gFile->Get(Form("detadphi_%d", i));
13257     hist->Rebin2D(2, 2);
13258     hist->Scale(0.25);
13259     
13260     proj = hist->ProjectionY("proj", hist->GetXaxis()->FindBin(min), hist->GetXaxis()->FindBin(max));
13261     proj->Scale(1.0 / (hist->GetXaxis()->FindBin(max) - hist->GetXaxis()->FindBin(min) + 1));
13262     
13263     proj->SetLineColor(i+1);
13264     proj->DrawCopy((i == 0) ? "" : "SAME HIST");
13265     
13266     legend->AddEntry(proj->Clone(), Form("%d", i));
13267   }
13268   
13269   legend->Draw();
13270 }
13271
13272 void PlotTrackingEfficiency(const char* fileName)
13273 {
13274   loadlibs();
13275   
13276   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
13277   
13278   c = new TCanvas("c", "c", 600, 600);
13279   gPad->SetLeftMargin(0.15);
13280
13281   h->SetEtaRange(-0.89, 0.89);
13282   
13283   Float_t centralityBins[] = { 0, 10, 20, 40, 60, 100 };
13284   Int_t nCentralityBins = 5;
13285   
13286   legend = new TLegend(0.2, 0.15, 0.46, 0.42);
13287   legend->SetFillColor(0);
13288   
13289   Int_t colors[] = { 1, 2, 3, 4, 6 };
13290
13291   for (Int_t i=0; i<nCentralityBins; i++)
13292   {
13293     h->GetUEHist(2)->SetCentralityRange(centralityBins[i] + 0.1, centralityBins[i+1] - 0.1);
13294     proj = h->GetUEHist(2)->GetTrackingEfficiency(1);
13295     proj->GetYaxis()->SetRangeUser(0.7, 0.9);
13296     proj->GetXaxis()->SetRangeUser(0.5, 9.9);
13297     proj->GetYaxis()->SetTitleOffset(1.5);
13298     proj->SetTitle("");
13299     proj->GetYaxis()->SetTitle("Tracking efficiency");
13300     proj->SetMarkerColor(colors[i]);
13301     proj->SetLineColor(colors[i]);
13302     proj->SetStats(0);
13303     projClone = proj->DrawClone((i == 0) ? "" : "SAME");
13304     
13305     legend->AddEntry(projClone, Form("%.0f-%.0f%%", centralityBins[i], centralityBins[i+1]));
13306   }
13307   
13308   legend->Draw();  
13309 //   DrawLatex(0.58, 0.85, 1, "HIJING Pb-Pb 2.76 TeV", 0.03);
13310 //   DrawLatex(0.58, 0.81, 1, "|#eta| < 0.9", 0.03);
13311 //   
13312 //   DrawALICELogo(kFALSE, 0.7, 0.2, 0.9, 0.4);
13313   
13314   c->SaveAs("correction_tracking.eps");
13315   
13316   c = new TCanvas("c2", "c2", 600, 600);
13317   gPad->SetLeftMargin(0.15);
13318   
13319   proj = (TH1D*) h->GetUEHist(2)->GetTrackEfficiency(AliUEHist::kCFStepTracked, AliUEHist::kCFStepTrackedOnlyPrim, 1);
13320   proj->GetYaxis()->SetRangeUser(0.8, 1.0);
13321   proj->GetXaxis()->SetRangeUser(0.5, 9.9);
13322   proj->GetYaxis()->SetTitleOffset(1.5);
13323   proj->SetTitle("");
13324   proj->GetYaxis()->SetTitle("contamination correction");
13325   proj->SetStats(0);
13326   projClone = proj->DrawClone("");
13327
13328 //   DrawLatex(0.58, 0.85, 1, "HIJING Pb-Pb 2.76 TeV", 0.03);
13329 //   DrawLatex(0.58, 0.81, 1, "|#eta| < 0.9", 0.03);
13330 //   DrawALICELogo(kFALSE, 0.7, 0.2, 0.9, 0.4);
13331
13332   c->SaveAs("correction_contamination.eps");
13333   
13334   c = new TCanvas("c3", "c3", 600, 600);
13335   gPad->SetLeftMargin(0.15);
13336   
13337   proj = (TH1D*) h->GetUEHist(2)->GetTrackEfficiency(AliUEHist::kCFStepTrackedOnlyPrim, AliUEHist::kCFStepTracked, 1);
13338   proj->GetYaxis()->SetRangeUser(0.95, 1.15);
13339   proj->GetXaxis()->SetRangeUser(0.5, 9.9);
13340   proj->GetYaxis()->SetTitleOffset(1.5);
13341   proj->SetTitle("");
13342   proj->GetYaxis()->SetTitle("contamination");
13343   proj->SetStats(0);
13344   projClone = proj->DrawClone("");
13345
13346 //   DrawLatex(0.58, 0.85, 1, "HIJING Pb-Pb 2.76 TeV", 0.03);
13347 //   DrawLatex(0.58, 0.81, 1, "|#eta| < 0.9", 0.03);
13348 //   DrawALICELogo(kFALSE, 0.7, 0.2, 0.9, 0.4);
13349
13350   c->SaveAs("contamination.eps");  
13351 }
13352
13353 void PlotCorrections(const char* fileName, const char* tag = "")
13354 {
13355   loadlibs();
13356   
13357   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName, 0, kFALSE, tag);
13358   
13359   c = new TCanvas("c", "c", 1200, 800);
13360   c->Divide(3, 3);
13361
13362   c2 = new TCanvas("c2", "c2", 800, 900);
13363   c2->Divide(2, 3);
13364
13365   h->SetEtaRange(-0.89, 0.89);
13366 //   h->SetEtaRange(-1.19, 1.19);
13367   
13368   Float_t centrBins[] = { 0, 20, 40, 60, 100.1 };
13369   
13370   for (Int_t i=0; i<4; i++)
13371   {
13372     h->GetUEHist(2)->SetCentralityRange(centrBins[i] + 0.1, centrBins[i+1] - 0.1);
13373     c->cd(i+1);
13374     h->GetUEHist(2)->GetTrackingEfficiency()->DrawClone("COLZ");
13375     
13376     c2->cd(1);
13377     proj = h->GetUEHist(2)->GetTrackingEfficiency(1);
13378     proj->SetTitle(""); proj->SetStats(0);
13379     proj->GetYaxis()->SetTitle("tracking efficiency");
13380     proj->SetLineColor(i+1);
13381     proj->DrawClone((i == 0) ? "" : "SAME");
13382     
13383     c2->cd(2);
13384     proj = h->GetUEHist(2)->GetTrackingEfficiency(0);
13385     proj->GetYaxis()->SetTitle("tracking efficiency");
13386     proj->SetTitle(""); proj->SetStats(0);
13387     proj->GetXaxis()->SetTitle("#eta");
13388     proj->SetLineColor(i+1);
13389     proj->DrawClone((i == 0) ? "" : "SAME");
13390
13391     c2->cd(3);
13392     proj = h->GetUEHist(2)->GetTrackingContamination(1);
13393     proj->GetYaxis()->SetTitle("contamination correction");
13394     proj->SetTitle(""); proj->SetStats(0);
13395     proj->SetLineColor(i+1);
13396     proj->DrawClone((i == 0) ? "" : "SAME");
13397 //     return;
13398   }
13399
13400   h->GetUEHist(2)->SetCentralityRange(0, -1);
13401   for (Int_t i=0; i<10; i++)
13402   {
13403     c2->cd(4);
13404     h->SetZVtxRange(-10.0 + 2 * i, -8.0 + 2 * i);
13405     proj = h->GetUEHist(2)->GetTrackingEfficiency(0);
13406     proj->GetYaxis()->SetTitle("tracking efficiency");
13407     proj->SetTitle(""); proj->SetStats(0);
13408     proj->GetXaxis()->SetTitle("#eta");
13409     proj->SetLineColor(i+1);
13410     proj->DrawClone((i == 0) ? "" : "SAME");
13411   }
13412   
13413   h->SetZVtxRange(0, -1);
13414
13415   for (Int_t i=0; i<4; i++)
13416   {
13417     c2->cd(5);
13418     h->SetPartSpecies(i);
13419     proj = h->GetUEHist(2)->GetTrackingEfficiency(1);
13420     proj->GetYaxis()->SetTitle("tracking efficiency");
13421     proj->SetTitle(""); proj->SetStats(0);
13422 //     proj->GetXaxis()->SetTitle("#eta");
13423     proj->SetLineColor(i+1);
13424     proj->DrawClone((i == 0) ? "" : "SAME");
13425   }
13426   
13427   return;
13428   
13429 /*  c->cd(9);
13430   h->GetUEHist(2)->GetTrackingContamination()->Draw("COLZ");*/
13431   
13432   proj2 = h->GetUEHist(2)->GetTrackingEfficiency(1);
13433 //   proj2 = h->GetUEHist(2)->GetTrackEfficiency(AliUEHist::kCFStepAnaTopology, (AliUEHist::CFStep) (AliUEHist::kCFStepTrackedOnlyPrim+2), 1);
13434   new TCanvas;
13435   proj2->Draw();
13436   
13437   new TCanvas;
13438   hist = h->GetUEHist(2)->GetCorrelatedContamination();
13439 //   if (hist->GetEntries() > 0)
13440 //     hist->Draw("COLZ");
13441 }
13442
13443 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)
13444 {
13445   // partSpecies= -1 No PID, 0: Pions, 1: Kaons, 2: Protons
13446   // icharge is needed because GF correction applies only to negative particles, 0:Positive 1:negative
13447   // ApplyGFCorrection, for Geant3 version >= v1.14 this correction is not needed anymore for antiprotons
13448   // the number of TRD modules installed depends on the year
13449   
13450   Printf("condenseCentrality: %d; extrapolateHighpT: %d", condenseCentrality, extrapolateHighpT);
13451   
13452   loadlibs();
13453   
13454   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName, 0, kFALSE, tag);
13455   
13456   if(partSpecies!=-1){
13457     Double_t epsilon=0.001;
13458     h->GetUEHist(2)->GetTrackHistEfficiency()->GetGrid(0)->GetGrid()->GetAxis(2)->SetRangeUser(partSpecies-epsilon,partSpecies+epsilon);
13459     h->GetUEHist(2)->GetTrackHistEfficiency()->GetGrid(4)->GetGrid()->GetAxis(2)->SetRangeUser(partSpecies-epsilon,partSpecies+epsilon);
13460   }
13461   
13462   Int_t dimensions[] = { 0, 1, 3, 4 }; // eta, pT, centrality, vertex
13463   THnBase* generated = h->GetUEHist(2)->GetTrackHistEfficiency()->GetGrid(0)->GetGrid()->ProjectionND(4, dimensions);
13464   THnBase* measured = h->GetUEHist(2)->GetTrackHistEfficiency()->GetGrid((partSpecies==-1)?2:4)->GetGrid()->ProjectionND(4, dimensions); //for ID particle the matched+identified are taken
13465   
13466   //   new TCanvas; measured->Projection(0, 1, 3)->Draw();
13467   
13468   Printf("%f %f", generated->GetEntries(), measured->GetEntries());
13469   
13470   Int_t nBins[] = { generated->GetAxis(0)->GetNbins(), generated->GetAxis(1)->GetNbins(), 1, generated->GetAxis(3)->GetNbins() };
13471   
13472   if (condenseCentrality)
13473   {
13474     Double_t centrAxis[] = { 0, 101 };
13475   }
13476   else
13477   {
13478     Double_t centrAxis[] = { 0, 10, 20, 40, 60, 101 };
13479     nBins[2] = 5;
13480   }
13481   
13482   generated_new = new THnF("generated_new", "", 4, nBins, 0, 0);
13483   
13484   generated_new->SetBinEdges(0, generated->GetAxis(0)->GetXbins()->GetArray()); //eta
13485   generated_new->SetBinEdges(1, generated->GetAxis(1)->GetXbins()->GetArray()); //pT
13486   generated_new->SetBinEdges(2, centrAxis); //centrality
13487   generated_new->SetBinEdges(3, generated->GetAxis(3)->GetXbins()->GetArray()); //vertex
13488   
13489   for (Int_t i=0; i<4; i++)
13490     generated_new->GetAxis(i)->SetTitle(generated->GetAxis(i)->GetTitle());
13491   
13492   measured_new = (THnF*) generated_new->Clone("measured_new");
13493   effCorr = (THnF*) generated_new->Clone("correction");
13494
13495   generated_new->RebinnedAdd(generated);
13496   measured_new->RebinnedAdd(measured);
13497   
13498 //   new TCanvas; measured_new->Projection(0, 1, 3)->Draw();
13499
13500 //   return;
13501   
13502   Printf("%f %f", generated_new->GetEntries(), measured_new->GetEntries());
13503
13504   effCorr->Divide(generated_new, measured_new, 1, 1, "B");
13505 //   effCorr->Divide(measured_new);
13506
13507   if(ApplyGFCorrection && partSpecies!=-1){//define the functions for the GF correction
13508     TF1 *fGFTracking;
13509     TF1 *fGFMatching;
13510     Int_t ntrd=7;
13511     if(year==2011)ntrd=10;
13512     if(year>=2012)ntrd=13;
13513     Printf("Number of TRD module in %d : %d",year,ntrd);
13514     Printf("Applying GF correction for particle specie %d %s",partSpecies,Sign[icharge].Data());
13515     Int_t partSpeciesAliPID=partSpecies+2; //in AliPID 2: Pions 3:Kaons 4:protons
13516     fGFTracking = TrackingEff_geantflukaCorrection(partSpeciesAliPID,(icharge==0)?kPositive:kNegative);
13517     fGFMatching = TOFmatchMC_geantflukaCorrection(partSpeciesAliPID,(icharge==0)?kPositive:kNegative,ntrd);
13518     TCanvas *cGF=new TCanvas("cGF","cGF");
13519     fGFTracking->SetLineColor(1);
13520     fGFTracking->DrawClone();
13521     fGFMatching->DrawClone("same");
13522     gPad->BuildLegend(); 
13523   }
13524   
13525   Double_t maxEffValue=5;
13526   for (Int_t bin0 = 1; bin0<=effCorr->GetAxis(0)->GetNbins(); bin0++)
13527     for (Int_t bin1 = 1; bin1<=effCorr->GetAxis(1)->GetNbins(); bin1++)
13528       for (Int_t bin2 = 1; bin2<=effCorr->GetAxis(2)->GetNbins(); bin2++)
13529         for (Int_t bin3 = 1; bin3<=effCorr->GetAxis(3)->GetNbins(); bin3++)
13530         {
13531           nBins[0] = bin0;
13532           nBins[1] = bin1;
13533           nBins[2] = bin2;
13534           nBins[3] = bin3;
13535           
13536 //        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));
13537           if(ApplyGFCorrection  && partSpecies!=-1)
13538             {
13539               if(effCorr->GetBinContent(nBins) > 0)
13540                 {
13541                   Double_t pt=effCorr->GetAxis(1)->GetBinCenter(bin1);
13542                   Double_t GFTracking=fGFTracking->Eval(pt);
13543                   Double_t GFMatching=fGFMatching->Eval(pt);
13544                   //printf("pt: %.3f GFCorrectionTracking: %f GFCorrectionMatching: %f",pt,GFTracking,GFMatching);
13545                   //printf(" Eff before: %f",effCorr->GetBinContent(nBins));
13546                   effCorr->SetBinContent(nBins,effCorr->GetBinContent(nBins)*GFTracking*GFMatching);
13547                   //Printf(" Eff after: %f",effCorr->GetBinContent(nBins));
13548                 }
13549             }
13550           
13551           if (effCorr->GetBinContent(nBins) > maxEffValue)
13552           {
13553             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));
13554             effCorr->SetBinContent(nBins, 0);
13555           }
13556         
13557         
13558         }
13559
13560   const Float_t fitRangeBegin = 5.01;
13561   const Float_t fitRangeEnd = 14.99;
13562   const Float_t extendRangeBegin = 8.01;
13563   Bool_t verbose = kTRUE;
13564
13565   if (extrapolateHighpT)
13566   {
13567     Printf("Extrapolating high pT...");
13568     
13569     for (Int_t bin0 = 1; bin0<=effCorr->GetAxis(0)->GetNbins(); bin0++)
13570       for (Int_t bin2 = 1; bin2<=effCorr->GetAxis(2)->GetNbins(); bin2++)
13571         for (Int_t bin3 = 1; bin3<=effCorr->GetAxis(3)->GetNbins(); bin3++)
13572         {
13573           effCorr->GetAxis(0)->SetRange(bin0, bin0);
13574           effCorr->GetAxis(2)->SetRange(bin2, bin2);
13575           effCorr->GetAxis(3)->SetRange(bin3, bin3);
13576           
13577           if (gRandom->Uniform() < 0.02) verbose = kTRUE;
13578           
13579           proj = effCorr->Projection(1);
13580           
13581           if (proj->Integral(proj->FindBin(fitRangeBegin), proj->FindBin(fitRangeEnd)) <= 0)
13582             continue;
13583           
13584 //        Printf("%d %d %d %d %f", bin0, bin1, bin2, bin3, proj->Integral(proj->FindBin(fitRangeBegin), proj->FindBin(fitRangeEnd)));
13585           
13586           if (verbose)
13587           {
13588             new TCanvas; 
13589             proj->Draw();
13590           }
13591           
13592           proj->Fit("pol0", (verbose) ? "+" : "Q0+", "SAME", fitRangeBegin, fitRangeEnd);
13593           
13594           if (!proj->GetFunction("pol0"))
13595             continue;
13596           
13597           Float_t trackingEff = proj->GetFunction("pol0")->GetParameter(0);       
13598           
13599           for (Int_t bin1 = 1; bin1<=effCorr->GetAxis(1)->GetNbins(); bin1++)
13600           {
13601             if (effCorr->GetAxis(1)->GetBinCenter(bin1) < extendRangeBegin)
13602               continue;
13603               
13604             nBins[0] = bin0;
13605             nBins[1] = bin1;
13606             nBins[2] = bin2;
13607             nBins[3] = bin3;
13608             
13609 //          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));
13610             effCorr->SetBinContent(nBins, trackingEff);
13611           }
13612           
13613           if (verbose)
13614             verbose = kFALSE;
13615         }
13616
13617     effCorr->GetAxis(0)->UnZoom();
13618     effCorr->GetAxis(1)->UnZoom();
13619     effCorr->GetAxis(2)->UnZoom();
13620     effCorr->GetAxis(3)->UnZoom();
13621   }
13622   
13623   Printf("%f", effCorr->GetEntries());
13624   
13625   TObjString tag2(Form("corrections from file %s with tag %s", fileName, tag));
13626
13627   file = TFile::Open("correction.root", "RECREATE");
13628   effCorr->Write();
13629   tag2.Write();
13630   file->Close();
13631   
13632   new TCanvas;
13633   effCorr->GetAxis(0)->SetRangeUser(-0.49, 0.49);
13634   effCorr->GetAxis(2)->SetRangeUser(65, 65);
13635   effCorr->GetAxis(3)->SetRangeUser(0.01, 0.01);
13636   effCorr->Projection(1)->Draw();
13637 }
13638
13639 void CompareEfficiencyCorrection(const char* fileName1, const char* fileName2, Int_t axis1, Int_t axis2)
13640 {
13641   if (TString(fileName1).BeginsWith("alien") || TString(fileName2).BeginsWith("alien"))
13642     TGrid::Connect("alien:");
13643   
13644   file1 = TFile::Open(fileName1);
13645   corr1 = (THnBase*) file1->Get("correction");
13646   
13647   file2 = TFile::Open(fileName2);
13648   corr2 = (THnBase*) file2->Get("correction");
13649   
13650   corr1->GetAxis(0)->SetRangeUser(-1.19, 1.19);
13651   corr2->GetAxis(0)->SetRangeUser(-1.19, 1.19);
13652   corr1->GetAxis(1)->SetRangeUser(0.51, 3.99);
13653   corr2->GetAxis(1)->SetRangeUser(0.51, 3.99);
13654   corr1->GetAxis(3)->SetRangeUser(0.01, 0.01);
13655   corr2->GetAxis(3)->SetRangeUser(0.01, 0.01);
13656   
13657   proj1 = (TH1*) corr1->Projection(axis1, axis2)->Clone("proj1");
13658   new TCanvas; proj1->DrawCopy("COLZ");
13659
13660   proj2 = (TH1*) corr2->Projection(axis1, axis2)->Clone("proj2");
13661   new TCanvas; proj2->DrawCopy("COLZ");
13662
13663   proj1->Divide(proj2);
13664   new TCanvas; proj1->DrawCopy("COLZ");
13665   
13666   corr1->GetAxis(0)->SetRangeUser(-0.49, 0.49);
13667   corr2->GetAxis(0)->SetRangeUser(-0.49, 0.49);
13668
13669   proj1 = (TH1*) corr1->Projection(axis2)->Clone("proj3");
13670   new TCanvas; proj1->DrawCopy();
13671
13672   proj2 = (TH1*) corr2->Projection(axis2)->Clone("proj4");
13673   proj2->SetLineColor(2);
13674   proj2->DrawCopy("SAME");
13675
13676   proj1->Divide(proj2);
13677   new TCanvas; proj1->DrawCopy();
13678   
13679 }
13680
13681  
13682 void PlotFake(const char* fileName, const char* fileName2 = 0)
13683 {
13684   loadlibs();
13685   
13686   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
13687   if (fileName2) AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(fileName2); 
13688  
13689   TLegend* legend = new TLegend(0.7, 0.8, 0.95, 0.95);
13690   legend->SetFillColor(0);
13691   legend->SetTextSize(0.03);
13692   const char* title[] = {"0-20%", "20-40%", "40-60%", "60-80%", "80-100%"};
13693   TLegend* legend2 = new TLegend(0.7, 0.8, 0.95, 0.95);
13694   legend2->SetFillColor(0);
13695   legend2->SetTextSize(0.03);
13696
13697   c1 = new TCanvas("c1", "Ratio of fakes", 1200, 800);
13698   c1->Divide(2, 3);
13699   c2 = new TCanvas("c2", "pTrec vs pT", 1200, 800);
13700   c2->Divide(2, 3);
13701   c3 = new TCanvas("c3", "pTrec pT ratio", 1200, 800);
13702   c3->Divide(2, 3);
13703
13704   h->SetEtaRange(-0.79, 0.79);
13705   
13706   for (Int_t i=0; i<5; i++)
13707   {
13708 //     h->GetUEHist(2)->SetCentralityRange(100.0/5*i + 0.1, 100.0/5*(i+1) - 0.1);
13709     h->GetUEHist(2)->SetCentralityRange(0, 100);
13710     c1->cd(i+1);
13711     h->GetUEHist(2)->GetFakeRate()->DrawClone("COLZ");
13712     c1->cd(6);
13713     proj = h->GetUEHist(2)->GetFakeRate(1);
13714     proj->GetYaxis()->SetRangeUser(0,150);
13715     proj->SetLineColor((i==4) ? 6 : i+1);
13716     proj->DrawClone((i == 0) ? "" : "SAME");
13717     legend->AddEntry(proj, title[i] , "PL");
13718   }
13719
13720   legend->Draw();
13721
13722   c2->cd(1);
13723   h->GetUEHist(2)->GetMCRecoPtCorrelation()->GetXaxis()->SetTitle("p_{T,rec}");
13724   h->GetUEHist(2)->GetMCRecoPtCorrelation()->GetYaxis()->SetTitle("p_{T}");
13725   h->GetUEHist(2)->GetMCRecoPtCorrelation()->GetZaxis()->SetTitle("Centrality");
13726   h->GetUEHist(2)->GetMCRecoPtCorrelation()->DrawCopy();
13727
13728   Float_t difference = 0.05;
13729
13730   for (Int_t i=0; i<5; i++)
13731   {
13732     c2->cd(i+2);
13733     h->GetUEHist(2)->GetMCRecoPtCorrelation()->GetZaxis()->SetRangeUser(100.0/5*i + 0.1,100.0/5*(i+1) - 0.1);
13734     hist = h->GetUEHist(2)->GetMCRecoPtCorrelation()->Project3D("yx");
13735     hist->DrawClone("COLZ");
13736     c2->cd(i+2)->SetLogz();
13737     c3->cd(i+1);
13738     TH1* MisreconstructedPtRate = h->GetUEHist(2)->GetMCRecoPtCorrelation()->ProjectionX("MisreconstructedPtRate");
13739     MisreconstructedPtRate->Reset();
13740     MisreconstructedPtRate->GetYaxis()->SetRangeUser(0,1);
13741     
13742     for (Int_t x=0; x<=hist->GetNbinsX(); x++) 
13743     {
13744       Float_t ptRec = hist->GetXaxis()->GetBinCenter(x);
13745       Float_t Misreconstructed = 0;
13746       Float_t Reconstructed = 0;
13747       for (Int_t y=0; y<=hist->GetNbinsY(); y++) 
13748       {
13749         Float_t pt = hist->GetYaxis()->GetBinCenter(y);
13750         Reconstructed += hist->GetBinContent(x,y);
13751         if (TMath::Abs(ptRec-pt)/pt > difference)
13752           Misreconstructed += hist->GetBinContent(x,y);
13753       }
13754       if (Reconstructed!=0) MisreconstructedPtRate->Fill(ptRec,Misreconstructed/Reconstructed);
13755     }
13756     MisreconstructedPtRate->SetLineColor((i==4) ? 6 : i+1);
13757     MisreconstructedPtRate->DrawClone();
13758     if (i==0) legend2->AddEntry(MisreconstructedPtRate, "2010" , "L");
13759     c3->cd(6);
13760     MisreconstructedPtRate->DrawClone((i == 0) ? "" : "SAME");
13761     if (fileName2)
13762     {
13763       h2->GetUEHist(2)->GetMCRecoPtCorrelation()->GetZaxis()->SetRangeUser(100.0/5*i + 0.1,100.0/5*(i+1) - 0.1);
13764       hist = h2->GetUEHist(2)->GetMCRecoPtCorrelation()->Project3D("yx"); 
13765       TH1* MisreconstructedPtRate2 = h2->GetUEHist(2)->GetMCRecoPtCorrelation()->ProjectionX("MisreconstructedPtRate2");
13766       MisreconstructedPtRate2->Reset();
13767       MisreconstructedPtRate2->GetYaxis()->SetRangeUser(0,1);
13768       for (Int_t x=0; x<=hist->GetNbinsX(); x++)
13769       {
13770         Float_t ptRec = hist->GetXaxis()->GetBinCenter(x);
13771         Float_t Misreconstructed = 0;
13772         Float_t Reconstructed = 0;
13773         for (Int_t y=0; y<=hist->GetNbinsY(); y++)
13774         {
13775           Float_t pt = hist->GetYaxis()->GetBinCenter(y);
13776           Reconstructed += hist->GetBinContent(x,y);
13777           if (TMath::Abs(ptRec-pt)/pt > difference)
13778             Misreconstructed += hist->GetBinContent(x,y);
13779         }
13780         if (Reconstructed!=0) MisreconstructedPtRate2->Fill(ptRec,Misreconstructed/Reconstructed);
13781       }
13782       c3->cd(i+1);
13783       MisreconstructedPtRate2->SetLineColor((i==2) ? 12 : i+8);
13784       MisreconstructedPtRate2->DrawClone("SAME");
13785       if (i==0) legend2->AddEntry(MisreconstructedPtRate2, "2011" , "L");
13786       legend2->DrawClone();
13787     }
13788   }
13789   c3->cd(6);
13790  legend->Draw();
13791 }
13792
13793 void CompareCorrections(const char* fileName1, const char* fileName2)
13794 {
13795   loadlibs();
13796   
13797   AliUEHistograms* h1 = (AliUEHistograms*) GetUEHistogram(fileName1);
13798   AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(fileName2);
13799   
13800   c = new TCanvas("c", "c", 1200, 800);
13801
13802   TLegend* legend = new TLegend(0.7, 0.8, 0.95, 0.95);
13803   legend->SetFillColor(0);
13804   legend->SetTextSize(0.03);
13805
13806   h1->SetEtaRange(-0.89, 0.89);
13807   h2->SetEtaRange(-0.89, 0.89);  
13808
13809
13810 //  const char* title1[] = {"2010, 0-10%", "2010, 10-20%", "2010, 20-30%", "2010, 30-40%", "2010, 40-50%"};
13811   const char* title1[] = {"FullTPC, 0-10%", "FullTPC, 10-20%", "FullTPC, 20-30%", "FullTPC, 30-40%", "FullTPC, 40-50%"};
13812   const char* title1[] = {"FullTPC, 0-10%", "FullTPC, 10-20%", "FullTPC, 20-30%", "FullTPC, 30-40%", "FullTPC, 40-50%"};
13813 //  const char* title2[] = {"2011, 0-10%", "2011, 10-20%", "2011, 20-30%", "2011, 30-40%", "2011, 40-50%"};
13814   const char* title2[] = {"NotFullTPC, 0-10%", "NotFullTPC, 10-20%", "NotFullTPC, 20-30%", "NotFullTPC, 30-40%", "NotFullTPC, 40-50%"};
13815
13816   Int_t colors[16] =  { 1, 3, 2, 6, 4, 7, 8, 9, 11, 12, 28, 30, 36, 40, 46 };
13817   Int_t markers[16] = { 20, 21, 22, 23, 24, 25, 26, 27, 28, 30, 31, 32, 33, 34, 2, 5};
13818
13819   for (Int_t i=0; i<5; i++)
13820   {
13821     h1->GetUEHist(2)->SetCentralityRange(100.0/10*i + 0.1, 100.0/10*(i+1) - 0.1);
13822     h2->GetUEHist(2)->SetCentralityRange(100.0/10*i + 0.1, 100.0/10*(i+1) - 0.1);
13823     
13824     c->cd(1);
13825     proj = h1->GetUEHist(2)->GetTrackingEfficiency(1);
13826     proj->SetLineColor(colors[6]);
13827     proj->SetMarkerColor(colors[6]);
13828     proj->SetMarkerStyle(markers[i]);
13829     proj->DrawClone((i == 0) ? "" : "SAME");
13830     legend->AddEntry(proj, title1[i] , "PL");
13831
13832     proj = h2->GetUEHist(2)->GetTrackingEfficiency(1);
13833     proj->SetLineColor(colors[2]);
13834     proj->SetMarkerColor(colors[2]);
13835     proj->SetMarkerStyle(markers[i+5]);
13836     proj->SetMarkerStyle(markers[i]);
13837     proj->DrawClone("SAME");
13838     legend->AddEntry(proj, title2[i] , "PL");
13839   }
13840     
13841   legend->Draw();
13842 }
13843
13844 void ComparePPHIMixedEvent(const char* ppFile, const char* pbpbFile)
13845 {
13846   loadlibs();
13847   
13848   AliUEHistograms* hpp = (AliUEHistograms*) GetUEHistogram(ppFile);
13849   AliUEHistograms* hpbpb = (AliUEHistograms*) GetUEHistogram(pbpbFile);
13850   
13851   new TCanvas;
13852   hpp->SetPtRange(2, 10);
13853   ppEff = hpp->GetUEHist(2)->GetTrackingEfficiency(0);
13854   ppEff->Draw();
13855
13856   hpbpb->SetPtRange(2, 10);
13857   pbpbEff = hpbpb->GetUEHist(2)->GetTrackingEfficiency(0);
13858   pbpbEff->DrawCopy("SAME")->SetLineColor(2);
13859   
13860   new TCanvas;
13861   ppEff2 = hpp->GetUEHist(2)->GetTrackingEfficiency(1);
13862   ppEff2->Draw();
13863
13864   pbpbEff2 = hpbpb->GetUEHist(2)->GetTrackingEfficiency(1);
13865   pbpbEff2->DrawCopy("SAME")->SetLineColor(2);
13866
13867   mixed = ComparePPHIMixedEventGetMixed(ppEff);
13868   mixed2 = ComparePPHIMixedEventGetMixed(pbpbEff);
13869   
13870   new TCanvas;
13871   mixed->DrawCopy();
13872   mixed2->DrawCopy("SAME")->SetLineColor(2);
13873   
13874   new TCanvas;
13875   mixed->Divide(mixed2);
13876   mixed->Draw();
13877 }
13878
13879 TH1* ComparePPHIMixedEventGetMixed(TH1* eff)
13880 {
13881   eff->Fit("pol0", "0W");
13882   Float_t avgEff = eff->GetFunction("pol0")->GetParameter(0);
13883
13884   eff->Fit("pol0", "0W", "", -0.89, 0.89);
13885   Float_t avgEffCenter = eff->GetFunction("pol0")->GetParameter(0);
13886   Printf("Avg is %f and avg in center is %f", avgEff, avgEffCenter);
13887          
13888   TH1* mixed = new TH1F("mixed", "", 100, -2, 2);
13889   
13890   Float_t etaLimit = 1.0;
13891   
13892   Int_t n = 10000;
13893   Int_t n2 = 100;
13894   for (Int_t i=0; i<n; i++)
13895   {
13896     Float_t etaTrig = gRandom->Uniform(-etaLimit, etaLimit);
13897     
13898     for (Int_t j=0; j<n2; j++)
13899     {
13900       Float_t etaAssoc = gRandom->Uniform(-etaLimit, etaLimit);
13901       
13902       if (gRandom->Uniform(0, 1) > eff->GetBinContent(eff->FindBin(etaAssoc)))
13903         continue;
13904       
13905       mixed->Fill(etaTrig - etaAssoc);
13906     }
13907   }
13908   
13909 //   mixed->Scale(1.0 / avgEffCenter);
13910   mixed->Scale(1.0 / avgEff);
13911
13912   Printf("We have %f pairs and put in %d", mixed->Integral(), n*n2);    
13913   
13914   return mixed;
13915 }
13916
13917 void MACHConeEvolution(const char* fileName, const char* fileNameMixed = 0)
13918 {
13919   loadlibs();
13920   
13921   if (!fileNameMixed)
13922     fileNameMixed = fileName;
13923   
13924   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
13925   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileNameMixed, 0, kTRUE);
13926     
13927   Float_t leadingPtArr[] = { 2.0, 3.0, 4.0, 10.0, 20.0, 40.0 };
13928   Float_t assocPtArr[] =   { 1.0, 2.0, 3.0, 6.0, 10.0, 20.0, 40.0 };
13929   
13930   Int_t i = 1;
13931   Int_t step = 6;
13932   Int_t j = 0;
13933   
13934   gpTMin = assocPtArr[i] + 0.01;
13935   gpTMax = assocPtArr[i+1] - 0.01;
13936
13937   for (Int_t centrBin = 0; centrBin < 5; centrBin++)
13938   {
13939     Int_t centralityBegin = centrBin;
13940     Int_t centralityEnd = centrBin+1;
13941     
13942     SetupRanges(h);
13943     SetupRanges(hMixed);
13944     
13945     TH1* hist = 0;
13946
13947     Bool_t scaleToPairs = 0;
13948     
13949     GetDistAndFlow(h, hMixed, &hist, 0, step, centralityBegin, centralityEnd, leadingPtArr[j] + 0.01, leadingPtArr[j+1] - 0.01, 11, kTRUE, 0, scaleToPairs); 
13950     hist->Rebin(2); hist->Scale(0.5);
13951
13952     copy = hist->DrawCopy((centrBin == 0) ? "" : "SAME");
13953     copy->SetLineColor(centrBin+1);
13954   }
13955 }
13956     
13957 void PlotTwoTrackEfficiencyControlPlots(const char* fileName)
13958 {
13959   loadlibs();
13960   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
13961   
13962   Float_t ptRange[] = { 0.0, 1.0, 2.0, 3.0, 4.0, 6.0, 8.0, 10.0 };
13963   
13964   graph = new TGraphErrors;
13965   
13966   for (Int_t ptID = 0; ptID < 7; ptID++)
13967   {
13968     c = new TCanvas(Form("c%d", ptID), Form("%.0f < pT < %.0f", ptRange[ptID], ptRange[ptID+1]), 800, 400);
13969     c->Divide(2, 1);
13970   
13971     for (Int_t i=0; i<2; i++)
13972     {
13973       c->cd(i+1);
13974       h->GetTwoTrackDistance(i)->GetZaxis()->SetRangeUser(ptRange[ptID] + 0.01, ptRange[ptID+1] - 0.01);
13975       p = h->GetTwoTrackDistance(i)->Project3D(Form("yx_%d_%d", i, ptID));
13976 //       if (ptID == 0)
13977         p->SetStats(0);
13978       
13979       pc = (TH2*) p->Clone("pc");
13980       pc->Reset();
13981       
13982       p->DrawCopy("COLZ");
13983       
13984       continue;
13985       
13986       // reduce to one quadrant
13987       for (Int_t x=1; x<=p->GetNbinsX(); x++)
13988         for (Int_t y=1; y<=p->GetNbinsY(); y++)
13989           pc->Fill(TMath::Abs(p->GetXaxis()->GetBinCenter(x)), TMath::Abs(p->GetYaxis()->GetBinCenter(y)), p->GetBinContent(x, y));
13990       
13991       c->cd(i+2);
13992       copy = pc->DrawCopy("COLZ");
13993       copy->GetXaxis()->SetRangeUser(0, 10);
13994       copy->GetYaxis()->SetRangeUser(0.00101, 10);
13995       
13996       // extract excess
13997       if (1)
13998       {
13999         Float_t center = pc->Integral(pc->GetXaxis()->FindBin(0), pc->GetXaxis()->FindBin(0.009999), 1, pc->GetNbinsY());
14000         Float_t outside = pc->Integral(pc->GetXaxis()->FindBin(0.01001), pc->GetXaxis()->FindBin(0.04999), 1, pc->GetNbinsY());
14001         
14002         Float_t excess1 = center - outside / 4;
14003
14004         Float_t center = pc->Integral(pc->GetXaxis()->FindBin(0), pc->GetXaxis()->FindBin(0.001999), 1, pc->GetNbinsY());
14005         Float_t outside = pc->Integral(pc->GetXaxis()->FindBin(0.002001), pc->GetXaxis()->FindBin(0.00999), 1, pc->GetNbinsY());
14006
14007         Float_t excess2 = center - outside / 4;
14008
14009         Printf("%d %f %f", ptID, excess1, excess2);
14010       }
14011
14012       // fit
14013       if (0 && i == 0)
14014       {
14015         p2 = ((TH2*)pc)->ProjectionX("p2", 52, 52+4);
14016 //      p3 = ((TH2*)p)->ProjectionX("p3", 49-4, 49);
14017         //p2->Add(p3);
14018         //new TCanvas; p2->Draw();
14019         //return;
14020         p2->Fit("pol0", "0");
14021         Float_t avg = p2->GetFunction("pol0")->GetParameter(0);
14022         p2->Fit("pol0", "0", "", -0.002, 0.002); 
14023         Float_t min = p2->GetFunction("pol0")->GetParameter(0);
14024         Float_t mine = p2->GetFunction("pol0")->GetParError(0);
14025         
14026         if (avg > 0)
14027         {
14028           graph->SetPoint(graph->GetN(), ptRange[ptID], min / avg);
14029           graph->SetPointError(graph->GetN()-1, 0, mine / avg);
14030         }
14031       }
14032       
14033     }
14034     
14035     c->SaveAs(Form("twotrack_pt_%d_%d.png", (Int_t) ptRange[ptID], (Int_t) ptRange[ptID+1]));
14036     c->SaveAs(Form("twotrack_pt_%d_%d.eps", (Int_t) ptRange[ptID], (Int_t) ptRange[ptID+1]));
14037   }
14038   
14039   new TCanvas;
14040   graph->Print();
14041   graph->Draw("A*");
14042 }
14043
14044 void PlotTwoTrackEfficiencyControlPlots2(const char* fileName)
14045 {
14046   loadlibs();
14047   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
14048   
14049   Float_t ptRange[] = { 0.0, 1.0, 2.0, 3.0, 4.0, 6.0, 8.0, 10.0 };
14050   
14051   graph = new TGraphErrors;
14052   
14053   for (Int_t ptID = 0; ptID < 5; ptID++)
14054   {
14055     c = new TCanvas(Form("c%d", ptID), Form("%.0f < pT < %.0f", ptRange[ptID], ptRange[ptID+1]), 1200, 400);
14056     c->Divide(3, 1);
14057   
14058     TH2* proj[2];
14059     
14060     for (Int_t i=0; i<3; i++)
14061     {
14062       c->cd(i+1);
14063       gPad->SetRightMargin(0.2);
14064       
14065       if (i < 2)
14066       {
14067         h->GetTwoTrackDistance(i)->GetZaxis()->SetRangeUser(ptRange[ptID] + 0.01, ptRange[ptID+1] - 0.01);
14068         p = (TH2*) h->GetTwoTrackDistance(i)->Project3D(Form("yx_%d_%d", i, ptID));
14069         
14070         if (1)
14071         {
14072           // reduce to one quadrant
14073           pc = (TH2*) p->Clone(Form("%s_pc", p->GetName()));
14074           pc->Reset();
14075           pc->Rebin2D(2, 2);
14076           for (Int_t x=1; x<=p->GetNbinsX(); x++)
14077             for (Int_t y=1; y<=p->GetNbinsY(); y++)
14078               pc->Fill(TMath::Abs(p->GetXaxis()->GetBinCenter(x)), TMath::Abs(p->GetYaxis()->GetBinCenter(y)), p->GetBinContent(x, y));
14079           pc->GetXaxis()->SetRangeUser(0, 100);
14080           pc->GetYaxis()->SetRangeUser(0, 100);
14081           p = pc;
14082         }
14083         
14084         if (ptID == 0)
14085           p->SetStats(0);
14086         
14087         p->DrawCopy("COLZ");
14088         
14089         proj[i] = p;
14090       }
14091       else
14092       {
14093         proj[0]->Divide(proj[1]);
14094         proj[0]->SetStats(0);
14095
14096 //      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);
14097         Float_t scale = proj[0]->Integral(1, proj[1]->GetNbinsX(), 1, proj[1]->GetNbinsY()) / proj[1]->GetNbinsX() / proj[1]->GetNbinsY();
14098         proj[0]->Scale(1./ scale / 4);
14099         proj[0]->DrawCopy("COLZ");
14100       }
14101     }
14102   }
14103 }
14104
14105 void PlotTwoTrackEfficiencyControlPlots3(const char* fileName, Int_t histID = 0)
14106 {
14107   loadlibs();
14108   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
14109   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
14110   
14111   Float_t ptRange[] = { 0.0, 1.0, 2.0, 3.0, 4.0, 6.0, 8.0, 10.0 };
14112   
14113   graph = new TGraphErrors;
14114   
14115   for (Int_t ptID = 0; ptID < 5; ptID++)
14116   {
14117     c = new TCanvas(Form("c%d", ptID), Form("%.0f < pT < %.0f", ptRange[ptID], ptRange[ptID+1]), 1200, 400);
14118     c->Divide(3, 1);
14119   
14120     TH2* proj[2];
14121     
14122     for (Int_t i=0; i<3; i++)
14123     {
14124       c->cd(i+1);
14125       gPad->SetRightMargin(0.2);
14126       
14127       if (i < 2)
14128       {
14129         AliUEHistograms* input = ((i == 0) ? h : hMixed);
14130         input->GetTwoTrackDistance(histID)->GetZaxis()->SetRangeUser(ptRange[ptID] + 0.01, ptRange[ptID+1] - 0.01);
14131         p = (TH2*) input->GetTwoTrackDistance(histID)->Project3D(Form("yx_%d_%d", i, ptID));
14132         
14133         if (0)
14134         {
14135           // reduce to one quadrant
14136           pc = (TH2*) p->Clone(Form("%s_pc", p->GetName()));
14137           pc->Reset();
14138 //        pc->Rebin2D(2, 2);
14139           for (Int_t x=1; x<=p->GetNbinsX(); x++)
14140             for (Int_t y=1; y<=p->GetNbinsY(); y++)
14141               pc->Fill(TMath::Abs(p->GetXaxis()->GetBinCenter(x)), TMath::Abs(p->GetYaxis()->GetBinCenter(y)), p->GetBinContent(x, y));
14142           pc->GetXaxis()->SetRangeUser(0, 100);
14143           pc->GetYaxis()->SetRangeUser(0, 100);
14144           p = pc;
14145         }
14146         
14147 //      if (ptID == 0)
14148           p->SetStats(0);
14149         
14150         p->DrawCopy("COLZ");
14151         
14152         proj[i] = p;
14153       }
14154       else
14155       {
14156         Float_t scale = proj[0]->Integral() / proj[1]->Integral();
14157         proj[0]->Divide(proj[1]);
14158         proj[0]->SetStats(0);
14159
14160 //      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);
14161 //      Float_t scale = proj[0]->Integral(1, proj[1]->GetNbinsX(), 1, proj[1]->GetNbinsY()) / proj[1]->GetNbinsX() / proj[1]->GetNbinsY();
14162         proj[0]->Scale(1./ scale);
14163 //      proj[0]->Scale(1./ scale / 4);
14164         proj[0]->DrawCopy("COLZ");
14165       }
14166     }
14167   
14168     break;
14169   }
14170 }
14171
14172 void SystematicpTResolution(const char* inputYield, Int_t caseId = 18, Int_t triggerId = 1)
14173 {
14174   //   Study by Jacek comparing TPC only tracks with global tracks for new cuts (crossed rows) (Fwd by Andrew, 07.07.11)
14175   //   Resolution from tpc only tracks twice as worse than global tracks
14176   //   Parameterization for tpc-only tracks:
14177   //     f(pT) = a * pT * sqrt(1+b/(pT^abs(c)))
14178   //     a = 0.003; b = 2.08; c = 7.07e-7
14179   Float_t a = 0.003; Float_t b = 2.08; Float_t c = 7.07e-7;
14180   res = new TF1("res", "[0] * x * sqrt(1+[1]/(x**abs([2])))", 0, 15);
14181   res->SetParameters(a, b, c);
14182 //   res->Draw(); return;
14183   
14184   ReadYields(inputYield);
14185   
14186   for (Int_t side = 0; side < 2; side++)
14187   {
14188     for (Int_t centrality = 0; centrality < 4; centrality++)
14189     {
14190       TGraphErrors** tmp = yields[side][triggerId][centrality]; 
14191       graph = tmp[caseId];
14192       
14193 //       graph->DrawClone("A*");
14194       
14195       Float_t axisLimits[20];
14196       for (Int_t i=0; i<graph->GetN(); i++)
14197       {
14198         axisLimits[i] = graph->GetX()[i] - graph->GetEX()[i];
14199         axisLimits[i+1] = graph->GetX()[i] + graph->GetEX()[i];
14200       }
14201       
14202       hist = new TH1F("hist", "", graph->GetN(), axisLimits);
14203       
14204       for (Int_t i=0; i<graph->GetN(); i++)
14205       {
14206         gaus = new TF1("gaus", "gaus(0)", 0, 15);
14207         Float_t sigma = graph->GetX()[i] * res->Eval(graph->GetX()[i]);
14208         Float_t norm = graph->GetY()[i] / TMath::Sqrt(2 * TMath::Pi()) / sigma;
14209         gaus->SetParameters(norm, graph->GetX()[i], sigma);
14210 //      gaus->Draw("SAME");
14211 //      Printf("%f %f", graph->GetY()[i], gaus->Integral(0, 20));
14212         
14213         // fill histogram
14214         for (Int_t j=1; j<=hist->GetNbinsX(); j++)
14215           hist->SetBinContent(j, hist->GetBinContent(j) + gaus->Integral(hist->GetBinLowEdge(j), hist->GetXaxis()->GetBinUpEdge(j)));
14216       }
14217       
14218 //       hist->Draw("SAME"); return;
14219       
14220       for (Int_t i=0; i<graph->GetN(); i++)
14221         graph->GetY()[i] = hist->GetBinContent(i+1);
14222
14223 //       graph->SetMarkerColor(2); graph->DrawClone("*SAME");
14224     }
14225   }
14226 }
14227
14228 void DrawProcessIDPlot(const char* fileName)
14229 {
14230   if (gFile)
14231     gFile->Close();
14232   TFile::Open(fileName);
14233   list = (TList*) gFile->Get("PWG4_PhiCorrelations/histosPhiCorrelations");
14234   ((TH1*) list->FindObject("processIDs"))->Draw();
14235 }
14236  
14237 void GetExampleDphi(const char* fileName)
14238 {
14239   loadlibs();
14240   
14241   Int_t leadingPtOffset = 1;
14242     
14243   Int_t maxLeadingPt = 5;
14244   Int_t maxAssocPt = 6;
14245   if (1)
14246   {
14247     Float_t leadingPtArr[] = { 2.0, 3.0, 4.0, 6.0, 8.0, 10.0, 15.0, 20.0 };
14248     Float_t assocPtArr[] =     { 0.15, 0.5, 1.0, 2.0, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0 };
14249   }
14250   else
14251   {
14252     Float_t leadingPtArr[] = { 0.15, 10.0 };
14253     Float_t assocPtArr[] =     { 0.15, 10.0 };
14254   }
14255   leadingPtOffset = 1;
14256   
14257 //   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
14258   hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
14259   
14260   if (1)
14261   {
14262 //     h->SetZVtxRange(-0.99, 0.99);
14263     hMixed->SetZVtxRange(-0.99, 0.99);
14264   }
14265
14266   Int_t i=0;
14267   Int_t j=2;
14268
14269   gpTMin = assocPtArr[j] + 0.01;
14270   gpTMax = assocPtArr[j+1] - 0.01;
14271   
14272 //   SetupRanges(h);
14273   SetupRanges(hMixed);
14274
14275   Int_t bin[6];
14276   bin[0] =  hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(0)->GetGrid()->GetAxis(0)->FindBin(0.01);
14277   bin[1] =  hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(0)->GetGrid()->GetAxis(1)->FindBin(1.1);
14278   bin[2] =  hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(0)->GetGrid()->GetAxis(2)->FindBin(2.1);
14279   bin[3] =  hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(0)->GetGrid()->GetAxis(3)->FindBin(5.5);
14280   bin[4] =  hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(0)->GetGrid()->GetAxis(4)->FindBin(0);
14281   if (hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(0)->GetGrid()->GetAxis(5))
14282     bin[5] =  hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(0)->GetGrid()->GetAxis(5)->FindBin(0);
14283   Printf("tracks: %f +- %f", hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(6)->GetGrid()->GetBinContent(bin), hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(6)->GetGrid()->GetBinError(bin));
14284   
14285   bin[0] =  hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(0)->GetGrid()->GetAxis(2)->FindBin(2.1);
14286   bin[1] =  hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(0)->GetGrid()->GetAxis(3)->FindBin(5.5);
14287   if (hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(0)->GetGrid()->GetAxis(5))
14288     bin[2] =  hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(0)->GetGrid()->GetAxis(5)->FindBin(0);
14289   Printf("events: %f +- %f", hMixed->GetUEHist(2)->GetEventHist()->GetGrid(6)->GetGrid()->GetBinContent(bin), hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(6)->GetGrid()->GetBinError(bin));
14290   
14291   return;
14292
14293   Int_t stepMixed = 6;
14294   TH2* mixedTwoD = (TH2*) hMixed->GetUEHist(2)->GetUEHist(stepMixed, 0, leadingPtArr[i+leadingPtOffset], leadingPtArr[i+1+leadingPtOffset], 12, 13, 1, kFALSE);
14295   
14296   TH1* proj = mixedTwoD->ProjectionX("px", 11, 30);
14297   proj->Draw();
14298 }
14299
14300 void GaussToyFit()
14301 {
14302   func = new TF1("func", "gaus(0)", -2, 2);
14303   func->SetParameters(1, 0, 0.5);
14304   
14305   hist = new TH1F("hist", "", 100, -2, 2);
14306   hist->FillRandom("func", 10000);
14307   
14308   func = new TF1("func", "gaus(0)", -2, 2);
14309   func->SetParLimits(2, 0, 10);
14310   func->FixParameter(1, 0);
14311   func->SetParameters(2, 0, 0.1);
14312   hist->Fit(func, "", "", -1, 1);
14313   hist->DrawCopy();
14314   
14315   func2 = new TF1("func2", "gaus(0)+[3]", -2, 2);
14316   func2->SetParLimits(2, 0, 10);
14317   func2->FixParameter(1, 0);
14318   func2->SetParameters(2, 0, 0.1, 0);
14319   func2->SetLineColor(2);
14320   hist->Fit(func2, "+", "", -1, 1);
14321   
14322   return;
14323
14324   new TCanvas;
14325   constant = new TF1("constant", "1", -2, 2);
14326   hist->Add(constant, -30);
14327   func->SetParameters(2, 0, 0.1);
14328   hist->Fit(func, "", "", -1, 1);
14329 }
14330
14331 void GaussToyFit2()
14332 {
14333   func = new TF2("func", "[0]*exp(-0.5*((x/[1])**2+(y/[2])**2))", -2, 2, -2, 2);
14334   func->SetParameters(1, 0.4, 0.6);
14335   
14336   hist = new TH2F("hist", "", 100, -2, 2, 100, -2, 2);
14337   hist->FillRandom("func", 100000);
14338   
14339   func = new TF2("func", "[0]*exp(-0.5*((x/[1])**2+(y/[2])**2))", -2, 2, -2, 2);
14340   func->SetParameters(1, 0.2, 0.2);
14341   hist->Fit(func, "", "");
14342   hist->DrawCopy();
14343   
14344   new TCanvas;
14345   hist->ProjectionX()->Fit("gaus");
14346
14347   new TCanvas;
14348   hist->ProjectionY()->Fit("gaus");
14349 }
14350
14351 void AcceptanceToy()
14352 {
14353   // study a la Jan Rak presented in Corr PAG on 06.03.12
14354   
14355   hist = new TH1F("hist", "", 200, -1.5, 1.5);
14356   
14357   Float_t sigma = 0.3;
14358   for (Int_t i=0; i<1000000; i++)
14359   {
14360     // randomize mean
14361     Float_t mean = gRandom->Uniform(-5, 5);
14362     
14363     Float_t trig = gRandom->Gaus(mean, sigma);
14364     Float_t assoc = gRandom->Gaus(mean, sigma);
14365     
14366 //     Float_t trig = gRandom->Uniform(-5, 5);
14367 //     Float_t assoc = gRandom->Uniform(-5, 5);
14368
14369 /*    if (trig < 0 && assoc < trig)
14370       continue;
14371     if (trig > 0 && assoc > trig)
14372       continue;*/
14373     
14374     if (TMath::Abs(trig) < 1 && TMath::Abs(assoc) < 1)
14375 //       hist->Fill(trig - assoc);
14376       hist->Fill(trig - assoc, 1.0 / (1.0 - TMath::Abs(trig-assoc) / 2));
14377   }
14378   
14379   hist->Draw();
14380   hist->Fit("gaus", "", "", -1.5, 1.5);
14381   Printf("%f %f %f", sigma, hist->GetFunction("gaus")->GetParameter(2), hist->GetFunction("gaus")->GetParameter(2) / TMath::Sqrt(2));
14382   hist->GetFunction("gaus")->SetLineColor(2);
14383 }
14384
14385 void DrawEfficiency(const char* fileName, Int_t step1, Int_t step2)
14386 {
14387   gpTMin = 1.01;
14388   gpTMax = 1.99;
14389   
14390   loadlibs();
14391   
14392   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
14393   hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
14394   
14395   SetupRanges(h);
14396   SetupRanges(hMixed);
14397
14398   TH1* hist1 = 0;
14399   TH1* hist2 = 0;
14400   
14401   GetDistAndFlow(h, hMixed, &hist1,  0, step1, 0,  10, 2.01, 3.99, 1, kTRUE, 0, kTRUE); 
14402   GetDistAndFlow(h, hMixed, &hist2,  0, step2, 0,  10, 2.01, 3.99, 1, kTRUE, 0, kTRUE); 
14403   
14404   ((TH2*)hist1)->Rebin2D(2, 2);
14405   ((TH2*)hist2)->Rebin2D(2, 2);
14406   
14407   new TCanvas("c", "c", 800, 800);
14408   gPad->SetLeftMargin(0.15);
14409   hist1->SetTitle("");
14410   hist1->GetYaxis()->SetRangeUser(-1.39, 1.39);
14411   hist1->GetXaxis()->SetTitleOffset(1.5);
14412   hist1->GetYaxis()->SetTitleOffset(2);
14413   hist1->SetStats(kFALSE);
14414   hist1->DrawCopy("SURF1");
14415   
14416   new TCanvas("c2", "c2", 800, 800);
14417   gPad->SetLeftMargin(0.15);
14418   hist2->SetTitle("");
14419   hist2->GetYaxis()->SetRangeUser(-1.39, 1.39);
14420   hist2->GetXaxis()->SetTitleOffset(1.5);
14421   hist2->GetYaxis()->SetTitleOffset(2);
14422   hist2->SetStats(kFALSE);
14423   hist2->DrawCopy("SURF1");
14424   
14425   hist2->Divide(hist1);
14426
14427   new TCanvas("c3", "c3", 800, 800);
14428   gPad->SetLeftMargin(0.15);
14429   hist2->SetTitle("");
14430   hist2->GetYaxis()->SetRangeUser(-1.39, 1.39);
14431   hist2->GetXaxis()->SetTitleOffset(1.5);
14432   hist2->GetYaxis()->SetTitleOffset(2);
14433   hist2->SetStats(kFALSE);
14434   hist2->Draw("SURF1");
14435 }
14436
14437 void RewriteObjects(const char* fileName)
14438 {
14439   loadlibs();
14440
14441   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
14442   Int_t nAxes = ((AliTHn*) h->GetUEHist(2)->GetTrackHist(0)->GetNVar());
14443   Printf("We have %d axes", nAxes);
14444   
14445   TString histId; histId.Form("%dRC", nAxes-1);
14446   Printf("%s", histId.Data());
14447   
14448   AliUEHistograms* hNew = new AliUEHistograms(h->GetName(), histId);
14449   hNew->DeepCopy(h);
14450   delete h;
14451   
14452   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);  
14453   AliUEHistograms* hMixedNew = new AliUEHistograms(hMixed->GetName(), histId);
14454   hMixedNew->DeepCopy(hMixed);
14455   delete hMixed;
14456   
14457   TString newFileName(fileName);
14458   newFileName.ReplaceAll(".root", "");
14459   newFileName += "_rebinned.root";
14460
14461   list = new TList;
14462   list->Add(hNew);
14463   list->Add(hMixedNew);
14464
14465   file3 = TFile::Open(newFileName, "RECREATE");
14466   file3->mkdir("PWG4_PhiCorrelations");
14467   file3->cd("PWG4_PhiCorrelations");
14468   list->Write("histosPhiCorrelations", TObject::kSingleKey);
14469   file3->Close();
14470 }
14471
14472 void CondenseCentrality(const char* fileName, Float_t targetValue, Int_t step = 0, Float_t from = 0, Float_t to = -1)
14473 {
14474   loadlibs();
14475
14476   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
14477   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);  
14478   
14479   h->GetUEHist(2)->CondenseBin(step, 3, 1, targetValue, from, to);
14480   hMixed->GetUEHist(2)->CondenseBin(step, 3, 1, targetValue, from, to);
14481   
14482   Float_t events = h->GetCentralityDistribution()->Integral();
14483   h->GetCentralityDistribution()->Reset();
14484   h->GetCentralityDistribution()->Fill(targetValue, events);
14485   
14486   events = hMixed->GetCentralityDistribution()->Integral();
14487   hMixed->GetCentralityDistribution()->Reset();
14488   hMixed->GetCentralityDistribution()->Fill(targetValue, events);
14489   
14490   TString newFileName(fileName);
14491   newFileName.ReplaceAll(".root", "");
14492   newFileName += "_condensed.root";
14493
14494   list = new TList;
14495   list->Add(h);
14496   list->Add(hMixed);
14497
14498   file3 = TFile::Open(newFileName, "RECREATE");
14499   file3->mkdir("PWG4_PhiCorrelations");
14500   file3->cd("PWG4_PhiCorrelations");
14501   list->Write("histosPhiCorrelations", TObject::kSingleKey);
14502   file3->Close();
14503 }
14504
14505 void SymmetrizepTBins(const char* fileName)
14506 {
14507   // copy pt,a < pt,t bins to pt,a > pt,t
14508   
14509   loadlibs();
14510
14511   TList* list = 0;
14512   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName, &list);
14513   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);  
14514   
14515   h->GetUEHist(2)->SymmetrizepTBins();
14516   hMixed->GetUEHist(2)->SymmetrizepTBins();
14517
14518   TString newFileName(fileName);
14519   newFileName.ReplaceAll(".root", "");
14520   newFileName += "_symmetrized.root";
14521
14522   file3 = TFile::Open(newFileName, "RECREATE");
14523   file3->mkdir("PWG4_PhiCorrelations");
14524   file3->cd("PWG4_PhiCorrelations");
14525   list->Write("histosPhiCorrelations", TObject::kSingleKey);
14526   file3->Close();
14527 }
14528
14529 void PtDistributions(Int_t step = 8, Float_t centralityBegin = 1, Float_t centralityEnd = 10)
14530 {
14531   loadlibs();
14532
14533 //   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" };
14534   
14535 //   const char* fileNames[] = { "LHC10h_AOD086_120411_zvtx_rebinned.root", "LHC10h_AOD086_120411_hybrid_zvtx_rebinned.root", "LHC10h_AOD086_120430_raacuts_zvtx_rebinned.root" };
14536   const char* fileNames[] = { "pt_pos.root", "pt_neg.root" };
14537 //   const char* fileNames[] = { "LHC11a10a_bis_AOD090_120406_zvtx.root" };
14538
14539 //   Float_t eventCount[] = { 1098234., 1034306., 1369707. };
14540 //   Float_t eventCount[] = { 987360.000000, 930278.000000, 1231806.000000 };
14541   Float_t eventCount[] = { 1., 1. };
14542
14543   TH1* pt[3];
14544
14545   new TCanvas;
14546   for (Int_t i=0; i<2; i++)
14547   {
14548 /*    AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileNames[i]);
14549     
14550     h->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->SetRangeUser(0.01 + centralityBegin, -0.01 + centralityEnd);
14551     ptDist = h->GetUEHist(2)->GetEventHist()->Project(step, 0);*/
14552     
14553 /*    eventCount = h->GetEventCount();
14554     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));*/
14555     Float_t events = eventCount[i];
14556     
14557     TFile::Open(fileNames[i]);
14558     ptDist = (TH2*) gFile->Get("ptDist");
14559     
14560     ptDistProj = ptDist->ProjectionX(Form("ptDistProj_%d", i), ptDist->GetYaxis()->FindBin(0.01 + centralityBegin), ptDist->GetYaxis()->FindBin(-0.01 + centralityEnd));
14561   
14562 //     new TCanvas; ptDistProj->Draw(); gPad->SetLogy();
14563   
14564    
14565     ptDistProj->Scale(1.0 / events);
14566     
14567     ptDistProj->SetLineColor(i+1);
14568     ptDistProj->DrawCopy((i == 0) ? "" : "SAME");
14569
14570     pt[i] = (TH1*) ptDistProj->Clone(Form("clone_%d", i));
14571   }
14572   gPad->SetLogy();
14573
14574   new TCanvas;
14575   for (Int_t i=1; i<2; i++)
14576   {
14577     pt[i]->Divide(pt[0]);
14578     pt[i]->DrawCopy((i == 1) ? "" : "SAME");
14579   }  
14580 }
14581
14582 void test(const char* fileNameESD)
14583 {
14584   Int_t step = 8;
14585   
14586   loadlibs();
14587   AliUEHistograms* esd = (AliUEHistograms*) GetUEHistogram(fileNameESD);
14588   
14589   SetupRanges(esd);
14590
14591   ptDist = (TH2*) esd->GetUEHist(2)->GetEventHist()->Project(step, 0, 1);
14592   
14593   Printf("%f", ptDist->Integral());
14594 }
14595
14596 void CorrectPtDistribution(const char* fileNameCorrections, const char* fileNameESD, const char* outputFile)
14597 {
14598   Int_t step = 8;
14599   
14600   loadlibs();
14601   
14602   AliUEHistograms* corr = (AliUEHistograms*) GetUEHistogram(fileNameCorrections);
14603   
14604   TList* list = 0;
14605   AliUEHistograms* esd = (AliUEHistograms*) GetUEHistogram(fileNameESD, &list);
14606   
14607   SetupRanges(corr);
14608   SetupRanges(esd);
14609   
14610   corr->SetEtaRange(-0.89, 0.89);
14611   corr->ExtendTrackingEfficiency(0);
14612
14613   eff = corr->GetUEHist(2)->GetTrackingEfficiencyCorrectionCentrality();
14614   new TCanvas; eff->Draw("COLZ");
14615   
14616   cont = corr->GetUEHist(2)->GetTrackingContaminationCentrality();
14617   new TCanvas; cont->Draw("COLZ");
14618   
14619   ptDist = (TH2*) esd->GetUEHist(2)->GetEventHist()->Project(step, 0, 1);
14620   ptDist->SetStats(0);
14621   new TCanvas; ptDist->DrawCopy("COLZ");
14622   
14623   for (Int_t x=1; x<=ptDist->GetNbinsX(); x++)
14624     for (Int_t y=1; y<=ptDist->GetNbinsY(); y++)
14625     {
14626       Float_t factor = eff->GetBinContent(eff->GetXaxis()->FindBin(ptDist->GetXaxis()->GetBinCenter(x)), eff->GetYaxis()->FindBin(ptDist->GetYaxis()->GetBinCenter(y)));
14627       Float_t contFactor = cont->GetBinContent(cont->GetXaxis()->FindBin(ptDist->GetXaxis()->GetBinCenter(x)), cont->GetYaxis()->FindBin(ptDist->GetYaxis()->GetBinCenter(y)));
14628       
14629       printf("%f", contFactor);
14630       if (contFactor > 0)
14631         contFactor = 1.0 + 1.1 * (contFactor - 1.0);
14632       printf(" --> %f\n", contFactor);
14633       
14634       factor *= contFactor;
14635       
14636       ptDist->SetBinContent(x, y, ptDist->GetBinContent(x, y) * factor);
14637       ptDist->SetBinError(x, y, ptDist->GetBinError(x, y) * factor);
14638     }
14639   
14640   new TCanvas; ptDist->DrawCopy("COLZ");
14641   
14642   file3 = TFile::Open(outputFile, "RECREATE");
14643   ptDist->Write("ptDist");
14644   file3->Write();
14645   file3->Close();
14646   
14647   delete corr;
14648   delete esd;
14649 }
14650
14651 void CorrectPtDistributionAll()
14652 {
14653   CorrectPtDistribution("LHC11a10a_bis_AOD090_120406.root", "LHC10h_AOD086_120411_zvtx_rebinned.root", "ptdist1.root");
14654   CorrectPtDistribution("LHC11a10a_bis_AOD090_120505_zvtx_hybrid.root", "LHC10h_AOD086_120411_hybrid_zvtx_rebinned.root", "ptdist2.root");
14655   CorrectPtDistribution("LHC11a10a_bis_AOD090_120505_zvtx_raa.root", "LHC10h_AOD086_120430_raacuts_zvtx_rebinned.root", "ptdist3.root");
14656 }
14657   
14658 void CreateNormalizationTestObject(Bool_t addRidge = kFALSE)
14659 {
14660   loadlibs();
14661   gSystem->Load("libPWGCFCorrelationsDPhi");
14662
14663   AliUEHistograms* hNew = new AliUEHistograms("AliUEHistogramsSame", "5RC");
14664   
14665   // fill 1000 particles in one bin
14666   TObjArray* particles = new TObjArray;
14667   particles->Add(new AliDPhiBasicParticle(0, 0, 3.5, 1));
14668   for (Int_t i=0; i<2000; i++)
14669     particles->Add(new AliDPhiBasicParticle(gRandom->Gaus(0, 0.3), gRandom->Gaus(0, 0.3), 1.75, 1));
14670   
14671   hNew->FillCorrelations(61, 0, 8, particles);
14672
14673   if (addRidge)
14674   {
14675     for (Int_t i=0; i<10000; i++)
14676       particles->Add(new AliDPhiBasicParticle(gRandom->Uniform(-2, 2), gRandom->Gaus(0, 0.5), 1.75, 1));
14677   }
14678
14679   hNew->FillCorrelations(0.5, 0, 8, particles);
14680
14681   // fill flat mixed event
14682   AliUEHistograms* hMixedNew = new AliUEHistograms("AliUEHistogramsMixed", "5RC");
14683   THnSparse* sparse = hMixedNew->GetUEHist(2)->GetTrackHist(0)->GetGrid(8)->GetGrid();
14684   for (Int_t x=1; x<=sparse->GetAxis(0)->GetNbins(); x++)
14685     for (Int_t y=1; y<=sparse->GetAxis(4)->GetNbins(); y++)
14686     {
14687       Double_t bin[6];
14688       bin[0] = sparse->GetAxis(0)->GetBinCenter(x);
14689       bin[4] = sparse->GetAxis(4)->GetBinCenter(y);
14690       bin[1] = 1.75;
14691       bin[2] = 3.5;
14692       bin[3] = 0.5;
14693       bin[5] = 0;
14694       sparse->Fill(bin);
14695
14696       bin[3] = 61;
14697       sparse->Fill(bin);
14698
14699       bin[3] = 0.5;
14700       bin[2] = 1.75;
14701       sparse->Fill(bin);
14702
14703       bin[3] = 61;
14704       sparse->Fill(bin);
14705     }
14706     
14707   Double_t bin[6];
14708   bin[0] = 3.5;
14709   bin[1] = 0.5;
14710   bin[2] = 0;
14711   hMixedNew->GetUEHist(2)->GetEventHist()->GetGrid(8)->GetGrid()->Fill(bin);
14712   
14713   bin[1] = 61;
14714   hMixedNew->GetUEHist(2)->GetEventHist()->GetGrid(8)->GetGrid()->Fill(bin);
14715
14716   bin[1] = 0.5;
14717   bin[0] = 1.75;
14718   hMixedNew->GetUEHist(2)->GetEventHist()->GetGrid(8)->GetGrid()->Fill(bin);
14719
14720   bin[1] = 61;
14721   hMixedNew->GetUEHist(2)->GetEventHist()->GetGrid(8)->GetGrid()->Fill(bin);
14722
14723   ((AliTHn*) hNew->GetUEHist(2)->GetTrackHist(0))->FillParent();
14724   ((AliTHn*) hNew->GetUEHist(2)->GetTrackHist(0))->DeleteContainers();
14725
14726   ((AliTHn*) hMixedNew->GetUEHist(2)->GetTrackHist(0))->FillParent();
14727   ((AliTHn*) hMixedNew->GetUEHist(2)->GetTrackHist(0))->DeleteContainers();
14728
14729   list = new TList;
14730   list->Add(hNew);
14731   list->Add(hMixedNew);
14732
14733   file3 = TFile::Open("norm.root", "RECREATE");
14734   file3->mkdir("PWG4_PhiCorrelations");
14735   file3->cd("PWG4_PhiCorrelations");
14736   list->Write("histosPhiCorrelations", TObject::kSingleKey);
14737   file3->Close();
14738 }
14739
14740 void CompareSumOfRatiosAndDefault(const char* fileName, Int_t bin, Int_t step)
14741 {
14742   loadlibs();
14743  
14744   Int_t centralityFrom = 0;
14745   Int_t centralityTo = 20;
14746   
14747   gpTMin = 1.01;
14748   gpTMax = 1.99;
14749   
14750   Float_t ptTrigBegin = 2.01;
14751   Float_t ptTrigEnd = 3.99;
14752   
14753   if (bin == 1)
14754   {
14755     ptTrigBegin = 1.01;
14756     ptTrigEnd = 1.99;
14757   }
14758   else if (bin == 2)
14759   {
14760     gpTMin = 0.49;
14761     gpTMax = 0.99;
14762     ptTrigBegin = 0.49;
14763     ptTrigEnd = 0.99;
14764   }
14765   
14766   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
14767   hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
14768   
14769   SetupRanges(h);
14770   SetupRanges(hMixed);
14771   
14772   TH2* hist1 = 0;
14773   TH2* hist2 = 0;
14774   GetSumOfRatios(h, hMixed, &hist1,  step, centralityFrom, centralityTo, ptTrigBegin, ptTrigEnd, kTRUE); 
14775   GetDistAndFlow(h, hMixed, &hist2,  0, step, centralityFrom, centralityTo,  ptTrigBegin, ptTrigEnd, 1, kTRUE, 0, kTRUE);
14776   
14777   hist1->Rebin2D(2, 2); hist1->Scale(0.25);
14778   hist2->Rebin2D(2, 2); hist2->Scale(0.25);
14779   
14780   c = new TCanvas("c", "c", 1000, 1000);
14781   c->Divide(2, 3);
14782   
14783   c->cd(1);
14784   hist1->DrawCopy("SURF1");
14785
14786   c->cd(2);
14787   hist2->DrawCopy("SURF1");
14788   
14789   c->cd(4);
14790   proj1 = ((TH2*) hist1)->ProjectionY("proj1", hist1->GetXaxis()->FindBin(-0.99), hist1->GetXaxis()->FindBin(0.99));
14791   proj1->DrawCopy();
14792   proj2 = ((TH2*) hist2)->ProjectionY("proj2", hist2->GetXaxis()->FindBin(-0.99), hist2->GetXaxis()->FindBin(0.99));
14793   proj2->SetLineColor(2);
14794   proj2->DrawCopy("SAME");
14795   
14796   c->cd(5);
14797   proj1->Divide(proj1, proj2, 1, 1, "B");
14798   proj1->DrawCopy();
14799   
14800   c->cd(3);
14801   hist1->Divide(hist2);
14802   hist1->DrawCopy("SURF1");
14803 }
14804
14805 void PtDistribution(const char* fileName, Int_t step, Int_t bin = 0)
14806 {
14807   Int_t centralityFrom = 0;
14808   Int_t centralityTo = 80;
14809   
14810   Float_t ptTrigBegin = 2.01;
14811   Float_t ptTrigEnd = 3.99;
14812   
14813   if (bin == 1)
14814   {
14815     ptTrigBegin = 1.01;
14816     ptTrigEnd = 1.99;
14817   }
14818   else if (bin == 2)
14819   {
14820     ptTrigBegin = 0.51;
14821     ptTrigEnd = 0.99;
14822   }
14823   
14824   loadlibs();
14825   
14826   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
14827
14828   Int_t centralityBeginBin = 0;
14829   Int_t centralityEndBin = -1;
14830   
14831   if (centralityTo >= centralityFrom)
14832   {
14833     centralityBeginBin = h->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->FindBin(0.01 + centralityFrom);
14834     centralityEndBin = h->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->FindBin(-0.01 + centralityTo);
14835   }
14836
14837   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);
14838   pt2 = h->GetUEHist(2)->GetPtHist(step, 0, ptTrigBegin, ptTrigEnd, centralityBeginBin, centralityEndBin, -0.5, 0.5, -1.99, 1.99);
14839   
14840   new TCanvas;
14841   pt1->DrawCopy();
14842   pt2->SetLineColor(2);
14843   pt2->DrawCopy("SAME");
14844   gPad->SetLogy();
14845   
14846   // TODO proper subtraction, to get the pT distribution in the peak
14847 }
14848
14849 void GetRefMultiplicity(const char* fileNameESD, const char* tag = "")
14850 {
14851   Int_t step = 8;
14852   
14853   loadlibs();
14854   
14855   AliUEHistograms* esd = (AliUEHistograms*) GetUEHistogram(fileNameESD, 0, kFALSE, tag);
14856   
14857   Float_t centrBins[] = { 0, 20, 40, 60, 100 };
14858 //   Float_t centrBins[] = { 0, 100 };
14859   
14860   // NOTE Run it on data with limited zvtx range so that there are no empty bins in the corrections!
14861   
14862   for (Int_t i=0; i<4; i++)
14863   {
14864     Float_t centrBegin = centrBins[i] + 0.1;
14865     Float_t centrEnd   = centrBins[i+1] - 0.1;
14866     esd->GetUEHist(2)->GetEventHist()->GetGrid(step)->GetGrid()->GetAxis(1)->SetRangeUser(centrBegin, centrEnd);
14867   
14868     ptDist = (TH2*) esd->GetUEHist(2)->GetEventHist()->Project(step, 0);
14869   
14870     centrDist = esd->GetCentralityDistribution();
14871     
14872     if (1)
14873     {
14874       // add syst from R_pA
14875       for (Int_t j=1; j<=ptDist->GetNbinsX(); j++)
14876         ptDist->SetBinError(j, TMath::Sqrt(ptDist->GetBinError(j) * ptDist->GetBinError(j) + 0.052 * 0.052 * ptDist->GetBinContent(j) * ptDist->GetBinContent(j)));
14877     }
14878     
14879     Float_t events = centrDist->Integral(centrDist->FindBin(centrBegin), centrDist->FindBin(centrEnd));
14880     Double_t error = 0;
14881 //     Float_t integral = ptDist->IntegralAndError(ptDist->FindBin(0.51), ptDist->FindBin(3.99), error);
14882     Float_t integral = ptDist->IntegralAndError(ptDist->FindBin(0.51), ptDist->FindBin(7.99), error);
14883     Printf("%d: %f +- %f %f --> %f +- %F", i, integral, error, events, integral / events, error / events);
14884     
14885     ptDist->Scale(1.0 / events);
14886 //     ptDist->Scale(1.0 / integral);
14887   
14888 //     ptDist->Rebin(2); 
14889     
14890     NormalizeToBinWidth(ptDist);
14891     ptDist->SetLineColor(i + 1);
14892     ptDist->DrawCopy((i == 0) ? "" : "SAME");
14893   }
14894   gPad->SetLogy();
14895   
14896   TFile::Open("dNdPt_pPb_lab_MinBias_NEW.root");
14897   comparison = (TH1*) gFile->Get("dNdPt_pPb_eta08_stat");
14898   comparison->Scale(1.6); // normalize to my eta range
14899   comparison->SetLineColor(2);
14900   comparison->DrawCopy("SAME");
14901   
14902   //rebin
14903   for (Int_t i=1; i<=comparison->GetNbinsX(); i++)
14904   {
14905     // multiply by bin width
14906     comparison->SetBinContent(i, comparison->GetBinContent(i) * comparison->GetBinWidth(i));
14907     comparison->SetBinError(i, comparison->GetBinError(i) * comparison->GetBinWidth(i));
14908   }
14909
14910   Float_t integral = comparison->IntegralAndError(comparison->FindBin(0.51), comparison->FindBin(7.99), error);
14911   Float_t integral2 = comparison->IntegralAndError(comparison->FindBin(0.51), comparison->FindBin(19.99), error);
14912   Printf("%f %f", integral, integral2);
14913     
14914   Float_t integral = comparison->IntegralAndError(comparison->FindBin(0.51), comparison->FindBin(7.99), error);
14915   Float_t integral2 = comparison->IntegralAndError(comparison->FindBin(0.61), comparison->FindBin(7.99), error);
14916   Printf("%f %f", integral, integral2);
14917
14918   rebinned = comparison->Rebin(ptDist->GetNbinsX(), "rebinned", ptDist->GetXaxis()->GetXbins()->GetArray());
14919   
14920   
14921   NormalizeToBinWidth(rebinned);
14922   rebinned->Draw("SAME");
14923   
14924   new TCanvas;
14925   ptDist->Divide(rebinned);
14926   ptDist->Draw();
14927   
14928   return;
14929   
14930   new TCanvas;
14931   syst = (TH1*) gFile->Get("dNdPt_pPb_eta08_syst");
14932   syst->DrawCopy();
14933   
14934   new TCanvas;
14935   for (Int_t i=1; i<=syst->GetNbinsX(); i++)
14936   {
14937     if (syst->GetBinContent(i) > 0)
14938       syst->SetBinContent(i, syst->GetBinError(i) / syst->GetBinContent(i));
14939     syst->SetBinError(i, 0);
14940   }
14941   syst->Draw();
14942 }
14943
14944 void CheckBin(const char* fileName)
14945 {
14946   loadlibs();
14947
14948   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
14949   AliUEHistograms* hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
14950   
14951   sparse = h->GetUEHist(2)->GetTrackHist(0)->GetGrid(8)->GetGrid();
14952   sparse->GetAxis(1)->SetRangeUser(5, 5.1);
14953   sparse->GetAxis(2)->SetRangeUser(7, 7.1);
14954   sparse->GetAxis(3)->SetRangeUser(90, 91);
14955   sparse->GetAxis(4)->SetRangeUser(9, 9.1);
14956  
14957   new TCanvas;
14958   sparse->Projection(0, 4)->Draw("colz");
14959
14960   sparse = hMixed->GetUEHist(2)->GetTrackHist(0)->GetGrid(8)->GetGrid();
14961   sparse->GetAxis(1)->SetRangeUser(5, 5.1);
14962   sparse->GetAxis(2)->SetRangeUser(7, 7.1);
14963   sparse->GetAxis(3)->SetRangeUser(90, 91);
14964   sparse->GetAxis(4)->SetRangeUser(9, 9.1);
14965  
14966   new TCanvas;
14967   sparse->Projection(0, 4)->Draw("colz");
14968 }
14969
14970 void GetCorrectedYields(const char* fileName, const char* correctionFile, const char* tagCorrections = "", Int_t partSpecies=-1 )
14971 {
14972   loadlibs();
14973
14974   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
14975   
14976   // centrality, pT, eta
14977   yieldsUncorr = h->GetYield();
14978   new TCanvas; yieldsUncorr->DrawCopy();
14979 //   new TCanvas; yieldsUncorr->ProjectionX("x1")->DrawCopy();
14980  
14981   AliUEHistograms* hCorr = (AliUEHistograms*) GetUEHistogram(correctionFile, 0, kFALSE, tagCorrections);
14982   if(partSpecies!=-1){
14983     Double_t epsilon=0.001;
14984     hCorr->GetUEHist(2)->GetTrackHistEfficiency()->GetGrid(0)->GetGrid()->GetAxis(2)->SetRangeUser(partSpecies-epsilon,partSpecies+epsilon);
14985     hCorr->GetUEHist(2)->GetTrackHistEfficiency()->GetGrid(4)->GetGrid()->GetAxis(2)->SetRangeUser(partSpecies-epsilon,partSpecies+epsilon);
14986   }
14987   
14988   hCorr->GetUEHist(2)->GetTrackHistEfficiency()->GetGrid(0)->GetGrid()->GetAxis(4)->SetRangeUser(-1.9, 1.9);
14989   hCorr->GetUEHist(2)->GetTrackHistEfficiency()->GetGrid(2)->GetGrid()->GetAxis(4)->SetRangeUser(-1.9, 1.9);
14990   hCorr->GetUEHist(2)->GetTrackHistEfficiency()->GetGrid(4)->GetGrid()->GetAxis(4)->SetRangeUser(-1.9, 1.9);
14991   
14992   // eta, pT
14993   TH2* generated = hCorr->GetUEHist(2)->GetTrackHistEfficiency()->GetGrid(0)->GetGrid()->Projection(1, 0);
14994   TH2* measured = hCorr->GetUEHist(2)->GetTrackHistEfficiency()->GetGrid((partSpecies==-1)?2:4)->GetGrid()->Projection(1, 0);
14995   
14996   Printf("%f %f", generated->GetEntries(), measured->GetEntries());
14997
14998   new TCanvas; generated->Draw("COLZ");
14999   new TCanvas; measured->Draw("COLZ");
15000   
15001   effCorr = (TH2*) generated->Clone("correction");
15002   effCorr->Divide(generated, measured, 1, 1, "B");
15003   
15004   new TCanvas; effCorr->Draw("COLZ");
15005   
15006 //   return;
15007   
15008   yieldsCorr = (TH3F*) yieldsUncorr->Clone("fYieldsCorr");
15009   yieldsCorr->Reset();
15010   
15011   for (Int_t x=1; x<=yieldsUncorr->GetNbinsX(); x++)
15012     for (Int_t y=1; y<=yieldsUncorr->GetNbinsY(); y++)
15013       for (Int_t z=1; z<=yieldsUncorr->GetNbinsZ(); z++)
15014       {
15015         Double_t factor = effCorr->GetBinContent(effCorr->GetXaxis()->FindBin(yieldsUncorr->GetZaxis()->GetBinCenter(z)), effCorr->GetYaxis()->FindBin(yieldsUncorr->GetYaxis()->GetBinCenter(y)));
15016         yieldsCorr->SetBinContent(x, y, z, yieldsUncorr->GetBinContent(x, y, z) * factor);
15017         yieldsCorr->SetBinError(x, y, z, yieldsUncorr->GetBinError(x, y, z) * factor);
15018       }
15019
15020   new TCanvas; yieldsCorr->DrawCopy();
15021   
15022   TFile::Open("corr_yield.root", "RECREATE");
15023   yieldsCorr->Write();
15024   gFile->Close();
15025   
15026   // normalize per event
15027   centrDist = h->GetCentralityCorrelation()->ProjectionX();
15028   new TCanvas; centrDist->Draw();
15029
15030   for (Int_t x=1; x<=yieldsCorr->GetNbinsX(); x++)
15031   {
15032     Double_t factor = centrDist->Integral(centrDist->FindBin(yieldsCorr->GetXaxis()->GetBinLowEdge(x)+0.0001), centrDist->FindBin(yieldsCorr->GetXaxis()->GetBinUpEdge(x)-0.0001));
15033 //     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);
15034     if (factor <= 0)
15035       continue;
15036     
15037     for (Int_t y=0; y<=yieldsCorr->GetNbinsY()+1; y++)
15038       for (Int_t z=0; z<=yieldsCorr->GetNbinsZ()+1; z++)
15039       {
15040         if (yieldsCorr->GetBinContent(x, y, z) > 0)
15041         {
15042           yieldsCorr->SetBinContent(x, y, z, yieldsCorr->GetBinContent(x, y, z) / factor);
15043           yieldsCorr->SetBinError(x, y, z, yieldsCorr->GetBinError(x, y, z) / factor);
15044         }
15045         if (yieldsUncorr->GetBinContent(x, y, z) > 0)
15046         {
15047           yieldsUncorr->SetBinContent(x, y, z, yieldsUncorr->GetBinContent(x, y, z) / factor);
15048           yieldsUncorr->SetBinError(x, y, z, yieldsUncorr->GetBinError(x, y, z) / factor);
15049         }
15050       }
15051   }
15052
15053   TFile::Open("corr_yield.root", "UPDATE");
15054   yieldsCorr->Write("fYieldsCorr_per_event");
15055   centrDist->Write("events");
15056   gFile->Close();
15057
15058   //   new TCanvas; yieldsUncorr->ProjectionX("x2")->DrawCopy(); return;
15059   
15060   yieldsUncorr->GetXaxis()->SetRangeUser(1, yieldsUncorr->GetNbinsX());
15061
15062   new TCanvas; yieldsUncorr->Project3D("z1")->DrawCopy()->SetLineColor(1); yieldsCorr->Project3D("z2")->DrawCopy("SAME")->SetLineColor(2);
15063
15064   yieldsUncorr->GetXaxis()->SetRangeUser(0.1, 9.9);
15065   yieldsCorr->GetXaxis()->SetRangeUser(0.1, 9.9);
15066   new TCanvas; yieldsUncorr->Project3D("z3")->DrawCopy()->SetLineColor(1); yieldsCorr->Project3D("z4")->DrawCopy("SAME")->SetLineColor(2);
15067   yieldsUncorr->GetXaxis()->SetRangeUser(60.1, 99.9);
15068   yieldsCorr->GetXaxis()->SetRangeUser(60.1, 99.9);
15069   yieldsUncorr->Project3D("z5")->DrawCopy("SAME")->SetLineColor(3); yieldsCorr->Project3D("z6")->DrawCopy("SAME")->SetLineColor(4);
15070 }
15071
15072 void PlotPtCentrality()
15073 {
15074   TFile::Open("corr_yield.root");
15075   yieldsCorr = (TH3F*) gFile->Get("fYieldsCorr");
15076   
15077   yieldsCorr->GetZaxis()->SetRangeUser(-0.4999, 0.4999);
15078   yieldsProj = (TH2*) yieldsCorr->Project3D("yx");
15079   Printf("%f", yieldsProj->Integral());
15080   
15081   Float_t ptMin[] = { 0.5001, 1.0001, 2.0001 };
15082   Float_t ptMax = 10;
15083   
15084   for (Int_t i=0; i<3; i++)
15085   {
15086     profile = yieldsProj->ProjectionX(Form("x%d", i), yieldsProj->GetYaxis()->FindBin(ptMin[i]), yieldsProj->GetYaxis()->FindBin(ptMax));
15087     profile->SetLineColor(i+1);
15088     profile->Draw((i > 0) ? "SAME" : "");
15089   }
15090 }
15091
15092 void ExtractForAllSpecies()
15093 {
15094   TString baseName = "LHC13b2_fix_1_Train";
15095   const char* suffix[] = { "55_Hadrons_symmetrized", "63_Pions", "63_Kaons", "63_Protons" };
15096   TString baseNameOutput = "dphi_corr_mc_130531_allpt_";
15097   
15098   for (Int_t i=0; i<4; i++)
15099     PlotDeltaPhiEtaGap(baseName + suffix[i] + ".root", 0, 0, 0, baseNameOutput + suffix[i] + ".root");
15100 }
15101
15102 void Compare2D(const char* fileName, const char* fileName2)
15103 {
15104   Int_t step = 8;
15105   
15106   gpTMin = 1.01;
15107   gpTMax = 1.99;
15108   
15109   loadlibs();
15110   
15111   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
15112   hMixed = (AliUEHistograms*) GetUEHistogram(fileName, 0, kTRUE);
15113   
15114   AliUEHistograms* h2 = (AliUEHistograms*) GetUEHistogram(fileName2);
15115   hMixed2 = (AliUEHistograms*) GetUEHistogram(fileName2, 0, kTRUE);
15116
15117   SetupRanges(h);
15118   SetupRanges(hMixed);
15119   SetupRanges(h2);
15120   SetupRanges(hMixed2);
15121   
15122 //   h->SetZVtxRange(0.1, 0.5);
15123 //   hMixed->SetZVtxRange(0.1, 0.5);
15124 //   h2->SetZVtxRange(0.1, 0.5);
15125 //   hMixed2->SetZVtxRange(0.1, 0.5);
15126   
15127   TH1* hist1 = 0;
15128   GetDistAndFlow(h, 0, &hist1,  0, step, 0,  20, 1.01, 1.99, 1, kTRUE, 0, kTRUE); 
15129   
15130   TH1* hist2 = 0;
15131   GetDistAndFlow(h2, 0, &hist2,  0, step, 0,  20, 1.01, 1.99, 1, kTRUE, 0, kTRUE); 
15132
15133   c = new TCanvas("c", "c", 1600, 800);
15134   c->Divide(2, 1);
15135   c->cd(1);
15136   gPad->SetLeftMargin(0.15);
15137
15138   hist1->DrawCopy("SURF1");
15139   
15140   c->cd(2);
15141   gPad->SetLeftMargin(0.15);
15142
15143   hist2->DrawCopy("SURF1");
15144   
15145   Printf("%f %f", hist1->Integral(), hist2->Integral());
15146   
15147   new TCanvas("c3", "c3", 800, 800);
15148   gPad->SetLeftMargin(0.15);
15149   hist2->Divide(hist1);
15150   hist2->DrawCopy("COLZ");
15151 }
15152
15153 //Geant3/Fluka correction for tracking from the spectra analysis
15154 TF1 *
15155 TrackingEff_geantflukaCorrection(Int_t ipart, Int_t icharge)
15156 {
15157
15158   if (ipart == 3 && icharge == kNegative) {
15159     TF1 *f = new TF1(Form("fGeantFluka_%s_%s", AliPID::ParticleName(ipart), Sign[icharge]), "TrackingPtGeantFlukaCorrectionKaMinus(x);p_{T};GF correction", 0., 5.);
15160     return f;
15161   }
15162   else if (ipart == 4 && icharge == kNegative) {
15163     TF1 *f = new TF1(Form("fGeantFluka_%s_%s", AliPID::ParticleName(ipart), Sign[icharge]), "TrackingPtGeantFlukaCorrectionPrMinus(x);p_{T};GF correction", 0., 5.);
15164   }
15165   else
15166     TF1 *f = new TF1(Form("fGeantFluka_%s_%s", AliPID::ParticleName(ipart), Sign[icharge]), "TrackingPtGeantFlukaCorrectionNull(x);p_{T};GF correction", 0., 5.);
15167
15168   return f;
15169 }
15170
15171 Double_t
15172 TrackingPtGeantFlukaCorrectionNull(Double_t pTmc)
15173 {
15174   return 1.;
15175 }
15176
15177 Double_t
15178 TrackingPtGeantFlukaCorrectionPrMinus(Double_t pTmc)
15179 {
15180   return (1 - 0.129758 *TMath::Exp(-pTmc*0.679612));
15181 }
15182
15183 Double_t
15184 TrackingPtGeantFlukaCorrectionKaMinus(Double_t pTmc)
15185 {
15186   return TMath::Min((0.972865 + 0.0117093*pTmc), 1.);
15187 }
15188
15189 //Geant3/Fluka correction for matching from the spectra analysis
15190 TF1 *
15191 TOFmatchMC_geantflukaCorrection(Int_t ipart, Int_t icharge,Int_t ntrd)
15192 {
15193   if (ipart == 3 && icharge == kNegative) {
15194     TF1 *f = new TF1(Form("fGeantFluka_%s_%s", AliPID::ParticleName(ipart), Sign[icharge]),Form("MatchingPtGeantFlukaCorrectionKaMinus(x,%d);p_{T};GF correction",ntrd), 0., 5.);
15195     return f;
15196   }
15197   else if (ipart == 4 && icharge == kNegative) {
15198     TF1 *f = new TF1(Form("fGeantFluka_%s_%s", AliPID::ParticleName(ipart), Sign[icharge]),Form("MatchingPtGeantFlukaCorrectionPrMinus(x,%d);p_{T};GF correction",ntrd), 0., 5.);
15199   }
15200   else
15201     TF1 *f = new TF1(Form("fGeantFluka_%s_%s", AliPID::ParticleName(ipart), Sign[icharge]), "MatchingPtGeantFlukaCorrectionNull(x);p_{T};GF correction", 0., 5.);
15202   
15203   return f;
15204 }
15205
15206
15207 Double_t
15208 MatchingPtGeantFlukaCorrectionNull(Double_t pTmc)
15209 {
15210   return 1.;
15211 }
15212 Double_t
15213 MatchingPtGeantFlukaCorrectionKaMinus(Double_t pTmc, Int_t ntrd = 7)//ntrd is 7 in 2010, 10 in 2011, 13 in 2012+2013
15214 {
15215   Float_t ptTPCoutK=pTmc*(1- 3.37297e-03/pTmc/pTmc - 3.26544e-03/pTmc);
15216   Float_t scale = (ntrd * 0.14638485 + (18 - ntrd) * 0.02406) / 18.;
15217   return TMath::Min((TMath::Power(0.972865 + 0.0117093*ptTPCoutK,scale/0.03471)), 1.);
15218 }
15219 Double_t
15220 MatchingPtGeantFlukaCorrectionPrMinus(Double_t pTmc, Int_t ntrd = 7)//ntrd is 7 in 2010, 10 in 2011, 13 in 2012+2013
15221 {
15222   Float_t ptTPCoutP =pTmc*(1-6.81059e-01*TMath::Exp(-pTmc*4.20094));
15223   Float_t scale = (ntrd * 0.14638485 + (18 - ntrd) * 0.02406) / 18.;
15224   return (TMath::Power(1 - 0.129758*TMath::Exp(-ptTPCoutP*0.679612),scale/0.03471));
15225 }
15226
15227 void Browse(const char* fileName)
15228 {
15229   loadlibs();
15230
15231   if (!gGrid && TString(fileName).BeginsWith("alien://"))
15232     TGrid::Connect("alien://");
15233   
15234   TFile::Open(fileName);
15235
15236   new TBrowser;
15237 }
15238
15239 void CalculateCentralityWeights(const char* fileName)
15240 {
15241   loadlibs();
15242
15243   AliUEHistograms* h = (AliUEHistograms*) GetUEHistogram(fileName);
15244
15245   // data
15246 //   Bool_t bins = kFALSE;
15247 //   Int_t n = 5;
15248 //   Int_t binning[] = { 0, 10, 20, 30, 50, 80 };
15249 //   TH1* centralityDist = h->GetCentralityCorrelation()->ProjectionX();
15250
15251   // AMPT
15252   Bool_t bins = kTRUE;
15253   Int_t n = 5;
15254   Int_t binning[] = { 1, 3, 4, 5, 7, 10 };
15255   TH1* centralityDist = h->GetCentralityDistribution();
15256   
15257   new TCanvas;
15258   centralityDist->DrawCopy();
15259   
15260   for (Int_t i=0; i<n; i++)
15261   {
15262     if (bins)
15263     {
15264       Int_t minBin = binning[i];
15265       Int_t maxBin = binning[i+1]-1;
15266     }
15267     else
15268     {
15269       Int_t minBin = centralityDist->FindBin(binning[i]+0.01);
15270       Int_t maxBin = centralityDist->FindBin(binning[i+1]-0.01);
15271     }
15272     
15273     Float_t min = centralityDist->GetBinContent(minBin);
15274     for (Int_t bin=minBin; bin<=maxBin; bin++)
15275       min = TMath::Min(min, centralityDist->GetBinContent(bin));
15276     
15277     for (Int_t bin=minBin; bin<=maxBin; bin++)
15278       centralityDist->SetBinContent(bin, min / centralityDist->GetBinContent(bin));
15279   }
15280   
15281   for (Int_t bin=centralityDist->FindBin(binning[n]+0.01); bin<=centralityDist->GetNbinsX(); bin++)
15282     centralityDist->SetBinContent(bin, 1);
15283   
15284   new TCanvas;
15285   centralityDist->DrawCopy();
15286   
15287   file = TFile::Open("centralityWeights.root", "RECREATE");
15288   centralityDist->Write("weights");
15289   file->Close();  
15290 }
15291
15292 Double_t gIntegral = 0;
15293 Double_t FitFunctionGauss(Double_t *x, Double_t *par)
15294 {
15295   Double_t integralGaussian = TMath::Erf(1.8/TMath::Sqrt(2)/par[2]);
15296   Double_t par0 = gIntegral / integralGaussian;
15297   
15298   return par0/TMath::Sqrt(TMath::TwoPi())/par[2] * TMath::Exp(-0.5*x[0]*x[0]/par[2]/par[2]); 
15299 }
15300
15301 void correction_gauss_one(Float_t begin, Float_t end, Bool_t silent = kTRUE)
15302 {
15303   graph = new TGraph;
15304   graph2 = new TGraph;
15305   for (Float_t f=0.1; f<1.0; f+=0.01)
15306   {
15307     TH1* hist = new TH1F("hist", "", 60, -3, 3);
15308     TF1* func = new TF1("func", "gaus(0)", -5, 5);
15309     if (!silent)
15310       f = 0.85;
15311     func->SetParameters(1, 0, f);
15312     hist->FillRandom("func", 1000000);
15313     hist->Sumw2();
15314     hist->Scale(1.0 / hist->GetMaximum());
15315   //   hist->GetXaxis()->SetRangeUser(-1.39, 1.39);
15316     hist->SetLineWidth(2);
15317     
15318     clone = (TH1*) hist->Clone("clone");
15319     
15320     if (1)
15321     {
15322       for (Int_t i=hist->FindBin(-0.29); i<=hist->FindBin(0.29); i++)
15323         hist->SetBinError(i, 1e4);
15324     }    
15325
15326     if (!silent)
15327     {
15328       new TCanvas;
15329       hist->Draw();
15330     }
15331     
15332     func = new TF1("func", &FitFunctionGauss, -end, end, 3);
15333     func->FixParameter(0, 0);
15334     func->FixParameter(1, 0);
15335     func->SetParLimits(2, 0, 2);
15336     func->SetParameters(1, 0, 0.5);
15337     
15338 //     hist->Fit("gaus", (silent) ? "0" : "", "", -end+0.01, end-0.01);
15339     gIntegral = hist->Integral(hist->FindBin(-1.79), hist->FindBin(1.79), "width");
15340     hist->Fit(func, (silent) ? "0" : "", "", -end+0.01, end-0.01);
15341     Float_t first = ((TF1*) hist->GetListOfFunctions()->First())->GetParameter(2);
15342     hist->GetYaxis()->SetRangeUser(-0.2, 1.05);
15343     
15344     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);
15345     Printf("%f", offset);
15346     
15347     TF1* constant = new TF1("constant", "1", -5, 5);
15348     clone->Add(constant, -offset);
15349     clone->SetLineColor(2);
15350     if (!silent)
15351       clone->Draw("same");
15352 //     clone->Fit("gaus", (silent) ? "0" : "", "SAME", -end+0.01, end-0.01);
15353     gIntegral = clone->Integral(clone->FindBin(-1.79), clone->FindBin(1.79), "width");
15354     clone->Fit(func, (silent) ? "0" : "", "SAME", -end+0.01, end-0.01);
15355     Float_t second = ((TF1*) clone->GetListOfFunctions()->First())->GetParameter(2);
15356
15357     Printf("%f %f", first, second);
15358     graph->SetPoint(graph->GetN(), second, first);
15359     graph2->SetPoint(graph2->GetN(), second, first / second);
15360     
15361     if (!silent)
15362       return;
15363   }
15364   
15365   new TCanvas;
15366   graph->Draw("A*");
15367
15368   new TCanvas;
15369   graph2->Draw("A*");
15370 //   Printf("%f %f", hist->GetRMS(), clone->GetRMS());
15371   
15372   graph2->Write(Form("corr_%.1f_%.1f", begin, end));
15373 }
15374
15375 void correction_gauss()
15376 {
15377   new TCanvas;
15378   
15379   TFile::Open("sigma_correction.root", "RECREATE");
15380   
15381   gauss_one(1.4, 1.8);
15382   gauss_one(1.2, 1.8);
15383   gauss_one(0.5, 1.0);
15384   
15385   gFile->Close();
15386 }