]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGCF/Correlations/macros/twoplusone/output_TwoPlusOne.C
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / PWGCF / Correlations / macros / twoplusone / output_TwoPlusOne.C
1 Float_t gpTMin_T1 = 6.0;
2 Float_t gpTMax_T1 = 14.0;
3 Float_t gpTMin_T2 = 4.0;
4 Float_t gpTMax_T2 = 10.0;
5 Float_t gpTMin_assoc = 1.0;
6 Float_t gpTMax_assoc = 4.0;
7 Float_t gVertex = 6.9;
8 Float_t gZVtxRange = -1;
9 Float_t gAxis = 0;
10 Float_t gBasisSize = 350;
11 Float_t g_phi_bin = 0.32;//0.32;//bins of 0.174532  //maximum is pi/4, because max(delta phi) + 2 alpha < pi/2 (because at Delta phi = pi/2 the number of background triggers are measured)
12 Float_t g_eta_bin = 0.39;//bins of 0.2
13 //char* path = "PWGCF_TwoPlusOne/histosTwoPlusOne";//before 1091
14 //char* path = "PWGCF_TwoPlusOne/addedEvents_";
15 char* path = "PWGCF_TwoPlusOne/histosTwoPlusOne_lowPt";//1095
16
17 //static const int pt_assoc_bins_number = 8;
18 //Double_t pt_assoc_bins[pt_assoc_bins_number] = {0.5, 1.0, 2.0, 3.0, 4.0, 6.0, 8.0, 10.0};
19 //Double_t pt_assoc_bin_center[pt_assoc_bins_number-1] = {0.75, 1.5, 2.5, 3.5, 5.0, 7.0, 9.0};
20 //Double_t pt_assoc_bin_error[pt_assoc_bins_number-1] = {0.25, 0.5, 0.5, 0.5, 1.0, 1.0, 1.0};
21
22 static const int pt_assoc_bins_number = 6;
23 Double_t pt_assoc_bins[pt_assoc_bins_number] = {0.5, 1.0, 2.0, 3.0, 4.0, 6.0};
24 Double_t pt_assoc_bin_center[pt_assoc_bins_number-1] = {0.75, 1.5, 2.5, 3.5, 5.0};
25 Double_t pt_assoc_bin_error[pt_assoc_bins_number-1] = {0.25, 0.5, 0.5, 0.5, 1.0};
26
27 //static const int pt_assoc_bins_number = 12;
28 //Double_t pt_assoc_bins[pt_assoc_bins_number] = {0.5, 0.75, 1.0, 1.25, 1.50, 2.0, 2.5, 3.0, 3.5, 4.0, 5.0, 6.0};
29 //Double_t pt_assoc_bin_center[pt_assoc_bins_number-1] = {0.625, 0.875, 1.125, 1.375, 1.75, 2.25, 2.75, 3.25, 3.75, 4.5, 5.5};
30 //Double_t pt_assoc_bin_error[pt_assoc_bins_number-1] = {0.125, 0.125, 0.125, 0.125, 0.25, 0.25, 0.25, 0.25, 0.25, 0.5, 0.5};
31
32 void loadlibs()
33 {
34   gSystem->Load("libANALYSIS");
35   gSystem->Load("libANALYSISalice");
36   gSystem->Load("libCORRFW");
37   gSystem->Load("libPWGTools");
38   gSystem->Load("libPWGCFCorrelationsBase");
39 }
40
41
42 void* getList(const char* fileName, const char* folder)
43 {
44     file = TFile::Open(fileName);
45     if (!file)
46       return 0;
47  
48     list = (TList*) gFile->Get(folder);
49     //list = (TList*) gFile->Get("PWGCF_TwoPlusOne/histosTwoPlusOne");
50       
51     if (!list)
52       return 0;
53
54     return list;
55 }
56
57 const char* lastFileName = 0;
58 const char* lastFileName2 = 0;
59 void* cacheEvent = 0;
60 void* cacheEvent2 = 0;
61
62
63 void* GetTwoPlusOne(const char* fileName)
64 {
65
66   if (lastFileName && strcmp(lastFileName, fileName) == 0){
67     Printf("GetTwoPlusOne --> Using cache for %s", fileName);
68     return cacheEvent;
69   }
70   if (lastFileName2 && strcmp(lastFileName2, fileName) == 0){
71     Printf("GetTwoPlusOne --> Using cache for %s", fileName);
72     return cacheEvent2;
73   }
74   if(lastFileName)
75     lastFileName2 = fileName;
76   else
77     lastFileName = fileName;
78
79   //list = (TList*) getList(fileName, "PWGCF_TwoPlusOne/histosTwoPlusOne");
80   list = (TList*) getList(fileName, path);
81   
82   AliTwoPlusOneContainer* container = (AliTwoPlusOneContainer*) list->FindObject("AliTwoPlusOneContainer");
83
84   if (container->GetData()->GetTrackHist(0)->GetGrid(6)->GetGrid()->GetNbins() == 0)
85   {
86     Printf("We have %d axes", ((AliTHn*) container->GetData()->GetTrackHist(0)->GetNVar()));
87     
88     ((AliTHn*) container->GetData()->GetTrackHist(0))->FillParent();
89     ((AliTHn*) container->GetData()->GetTrackHist(0))->DeleteContainers();
90   }
91
92   if(lastFileName2 && strcmp(lastFileName2, fileName) == 0){
93     cacheEvent2 = container;
94     return cacheEvent2;
95   }
96
97   cacheEvent = container;
98
99   return cacheEvent;
100 }
101
102 void* GetPhiCorrelations(const char* fileName)
103 {
104   list = (TList*) getList(fileName, "PWG4_PhiCorrelations/histosPhiCorrelations");
105   
106
107   AliUEHistograms* container = list->FindObject("AliUEHistogramsSame");
108
109   if (container->GetUEHist(2)->GetTrackHist(0)->GetGrid(6)->GetGrid()->GetNbins() == 0)
110   {
111     Printf("We have %d axes", ((AliTHn*) container->GetUEHist(2)->GetTrackHist(0)->GetNVar()));
112     
113     ((AliTHn*) container->GetUEHist(2)->GetTrackHist(0))->FillParent();
114     ((AliTHn*) container->GetUEHist(2)->GetTrackHist(0))->DeleteContainers();
115   }
116
117   return container;
118 }
119
120 void* showEvents(const char* fileName, int twoPlusOne = 1)
121 {
122   if(twoPlusOne)
123     //list = (TList*) getList(fileName, "PWGCF_TwoPlusOne/histosTwoPlusOne");
124     list = (TList*) getList(fileName, path);
125   else
126     list = (TList*) getList(fileName, "PWG4_PhiCorrelations/histosPhiCorrelations");
127
128   TH1F* event_stat = (TH1F*) list->FindObject("eventStat");
129   TCanvas* can = new TCanvas();
130   event_stat->DrawCopy();
131 }
132
133 //returns maximum of the flow
134 //flow from 1.0 > |eta| > 1.6 is subtracted from the rest of the histogram
135 //the flow in the TH2 is subtracted
136 void subtractFlow(TH2* etaPhi){
137   int firstbin = etaPhi->GetYaxis()->FindBin(1.01);
138   int lastbin = etaPhi->GetYaxis()->FindBin(1.39);
139
140   TH1D* etaPhi_proj = etaPhi->ProjectionX("_px", firstbin, lastbin);
141   int usedBins = lastbin - firstbin + 1;
142
143   firstbin = etaPhi->GetYaxis()->FindBin(-1.39);
144   lastbin = etaPhi->GetYaxis()->FindBin(-1.01);
145   TH1D* signal2 = etaPhi->ProjectionX("_px2", firstbin, lastbin);
146   usedBins += lastbin - firstbin + 1;
147   etaPhi_proj->Add(signal2, 1.0);
148
149   etaPhi_proj->Scale(1.0/usedBins);
150
151   etaPhi->GetYaxis()->SetRangeUser(-1.0, 1.0);
152
153   for(int i=0;i<=etaPhi->GetNbinsX();i++){
154     double subtract = etaPhi_proj->GetBinContent(i);
155
156     for(int j=0;j<etaPhi->GetNbinsY();j++){
157       double content = etaPhi->GetBinContent(i,j)-subtract;
158       etaPhi->SetBinContent(i,j,content);
159     }
160   }
161 }
162
163   //use fit method to subtract the baseline if the subtractFlow method doesn't work because of poor statistics
164 Double_t subtractBaseline(TH1D* h1_phi){
165   
166   TF1* fit = new TF1("fit", "[0]", -TMath::Pi()/2+0.01, TMath::Pi()/2-0.01);
167
168   h1_phi->Fit("fit", "N", "", -TMath::Pi()/2+0.01, -1.0);
169   Double_t par0 = fit->GetParameter(0);
170  
171   h1_phi->Fit("fit", "N", "", 1.0, TMath::Pi()/2-0.01);
172   Double_t par1 = fit->GetParameter(0);
173
174   //this is done so that the fit is not drawn
175   //h1_phi->Fit("fit", "0", "", 1.0, TMath::Pi()/2-0.01);
176  
177   Double_t subtract = (par0+par1)/2;//h1_phi->GetMinimum();
178
179   
180   for(int i=0; i<h1_phi->GetNbinsX(); i++)
181     h1_phi->SetBinContent(i, h1_phi->GetBinContent(i) - subtract);
182
183   return subtract;
184 }
185
186
187 void showAllTriggerPt(const char* fileName, Int_t multBinBegin = 5, Int_t multBinEnd = 7, Int_t side = 0){
188   
189   const Int_t pt1_bins_length = 3;
190   //Int_t pt1_bins[pt1_bins_length+1] = {6.0, 8.0, 10.0, 12.0, 14.0};
191   Int_t pt1_bins[pt1_bins_length+1] = {6.0, 8.0, 10.0, 12.0};
192   const Int_t pt2_bins_length = 2;
193   Int_t pt2_bins[pt2_bins_length] = {4.0, 6.0};
194
195   for(Int_t i=0; i<pt1_bins_length; i++){
196     Double_t pt1Minimum = pt1_bins[i];
197     Double_t pt1Maximum = pt1_bins[i+1];
198     for(Int_t j=0; j<pt2_bins_length; j++){
199       Double_t pt2Minimum = pt2_bins[j];
200       getAnalysis(fileName, pt1Minimum, pt1Maximum, pt2Minimum, gpTMin_assoc, gpTMax_assoc, gVertex, multBinBegin, multBinEnd, side, i, j, 1, 0);
201     }
202   }
203 }
204
205 void showAllTrigger1Pt(const char* fileName, Int_t multBinBegin = 5, Int_t multBinEnd = 7, Int_t pt2Minimum = 4.0, Double_t ptAssocMin = 0.5, Double_t ptAssocMax = 8.0){
206
207   const Int_t pt1_bins_length = 3;
208   Int_t pt1_bins[pt1_bins_length+1] = {6.0, 8.0, 10.0, 12.0};
209
210   for(Int_t i=0; i<pt1_bins_length; i++){
211     TH1D* near = getAnalysis(fileName, pt1_bins[i], pt1_bins[i+1], pt2Minimum, ptAssocMin, ptAssocMax, gVertex, multBinBegin, multBinEnd, 0, i, 0, 1, 0);
212
213     TH1D* away = getAnalysis(fileName, pt1_bins[i], pt1_bins[i+1], pt2Minimum, ptAssocMin, ptAssocMax, gVertex, multBinBegin, multBinEnd, 1, i, 1, 1, 0);
214     /*
215     near->Divide(near, away);
216     TCanvas* c1 = new TCanvas(Form("can %i %i", i, 0), Form("can %i %i", i, 0), i*gBasisSize+50, 0, gBasisSize, gBasisSize);
217     near->DrawCopy();
218     */
219   }
220
221 }
222
223 void showAllAssocPt(const char* fileName, Int_t multBinBegin = 0, Int_t multBinEnd = 16, Int_t pt1Minimum = 4.0, Int_t pt1Maximum = 14.0, Int_t pt2Minimum = 2.0){
224
225   //const Int_t ptAssoc_bins_length = 5;
226   //Int_t ptAssoc_bins[ptAssoc_bins_length+1] = {1.0, 2.0, 3.0, 4.0, 6.0, 8.0};
227   const Int_t ptAssoc_bins_length = 3;
228   Int_t ptAssoc_bins[ptAssoc_bins_length+1] = {1.0, 3.0, 6.0, 8.0};
229
230   for(Int_t i=0; i<ptAssoc_bins_length; i++){
231     Int_t draw = 0;
232
233     TH1D* near = getAnalysis(fileName, pt1Minimum, pt1Maximum, pt2Minimum, ptAssoc_bins[i], ptAssoc_bins[i+1], gVertex, multBinBegin, multBinEnd, 0, i, 0, draw, 0)->Clone();
234
235     TH1D* away = getAnalysis(fileName, pt1Minimum, pt1Maximum, pt2Minimum, ptAssoc_bins[i], ptAssoc_bins[i+1], gVertex, multBinBegin, multBinEnd, 1, i, 1, draw, 0)->Clone();
236
237     if(!draw){
238       near->Divide(near, away);
239       
240       TCanvas* c1 = new TCanvas(Form("can %i %i", i, 0), Form("can %i %i", i, 0), i*gBasisSize+50, 0, gBasisSize, gBasisSize);
241       near->DrawCopy();
242       //TCanvas* c2 = new TCanvas(Form("can2 %i %i", i, 0), Form("can2 %i %i", i, 0), i*gBasisSize+50, gBasisSize+50, gBasisSize, gBasisSize);
243       //away->DrawCopy();
244     }
245   }
246 }
247
248 void showAllMult(const char* fileName, Int_t pt1Minimum = 4.0, Int_t pt1Maximum = 14.0, Int_t pt2Minimum = 2.0, Double_t ptAssocMin = 0.5, Double_t ptAssocMax = 8.0){
249
250   //in multiplicity this are the bins
251   //standard binning: 0, 1, 2, 3, 4, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100.1
252   const Int_t mult_bins_length = 5;
253   //Int_t mult_bins[mult_bins_length+1] = {1, 5, 6, 8, 11, 15};
254   Int_t mult_bins[mult_bins_length+1] = {1, 1, 5, 7, 9, 10};
255
256     for(Int_t i=0; i<mult_bins_length; i++){
257       TH1D* near = getAnalysis(fileName, pt1Minimum, pt1Maximum, pt2Minimum, ptAssocMin, ptAssocMax, gVertex, mult_bins[i], mult_bins[i+1], 0, i, 0, 1, 0);
258
259       TH1D* away = getAnalysis(fileName, pt1Minimum, pt1Maximum, pt2Minimum, ptAssocMin, ptAssocMax, gVertex, mult_bins[i], mult_bins[i+1], 1, i, 1, 1, 0);
260       /*
261       near->Divide(near, away);
262
263       TCanvas* c1 = new TCanvas(Form("can %i %i", i, 0), Form("can %i %i", i, 0), i*gBasisSize+50, 0, gBasisSize, gBasisSize);
264       near->DrawCopy();
265       */
266     }
267
268 }
269
270 void showMultCompare(const char* filename, Int_t pt1Minimum = 4.0, Int_t pt1Maximum = 14.0, Int_t pt2Minimum = 2.0, Double_t ptAssocMin = 0.5, Double_t ptAssocMax = 8.0, Int_t side = 0, Int_t subtractMixedComb = 1, Int_t subtractFlow = 1){
271
272   TLegend *leg  = new TLegend(0.65,0.7,0.85,0.9);
273   leg->SetFillColor(10);
274   leg->SetFillStyle(0);
275   leg->SetBorderSize(0);
276   leg->SetTextFont(gStyle->GetTextFont());
277   leg->SetTextSize(gStyle->GetTextSize()*1.0);
278
279   TH1D* central = getAnalysis(filename, pt1Minimum, pt1Maximum, pt2Minimum, ptAssocMin, ptAssocMax, 6.9, 1, 5, side, 1, 1, 0, subtractMixedComb, subtractFlow);
280
281   TCanvas* multCompare = new TCanvas("multCompare", "multCompare", gBasisSize+100, gBasisSize+50, 2*gBasisSize, 2*gBasisSize);
282   central->SetLineColor(kBlue);
283   leg->AddEntry(central->Clone(),"central","l");
284   subtractBaseline(central);
285   central->DrawCopy();
286
287   TH1D* semiCentral = getAnalysis(filename, pt1Minimum, pt1Maximum, pt2Minimum, ptAssocMin, ptAssocMax, 6.9, 9, 10, side, 1, 1, 0, subtractMixedComb, subtractFlow);
288
289   semiCentral->SetLineColor(kRed);
290   subtractBaseline(semiCentral);
291   semiCentral->DrawCopy("same");  
292   leg->AddEntry(semiCentral->Clone(),"semiCentral","l");
293   /*
294   TH1D* peripheral = getAnalysis(filename, pt1Minimum, pt1Maximum, pt2Minimum, ptAssocMin, ptAssocMax, 6.9, 11, 14, side, 1, 1, 0, subtractMixedComb);
295
296   peripheral->SetLineColor(kGreen);
297    leg->AddEntry(peripheral,"peripheral","l");
298   peripheral->DrawCopy("same");
299   */
300
301   leg->Draw("same");
302
303   //show same and mixed event of one vertex and multiplicity bin
304   //getRawAnalysis(filename, pt1Minimum, pt1Maximum, pt2Minimum, ptAssocMin, ptAssocMax, 3, 3);
305 }
306
307 void showAnalysis(const char* fileName, double pt1Min = 4.0, double pt1Max = 14.0, double pt2Min = 2.0, Double_t ptAssocMin = 0.5, Double_t ptAssocMax = 8.0, Int_t multBinBegin = 1, Int_t multBinEnd = 5, Int_t subtractMixedComb = 0, Int_t subtractFlow = 0){
308
309   TLegend* leg = getLegend();
310   Int_t showPlots = 1;
311
312   TH1* near = (TH1*)getAnalysis(fileName, pt1Min, pt1Max, pt2Min, ptAssocMin, ptAssocMax, 6.9, multBinBegin, multBinEnd, 0, 1, 1, showPlots, subtractMixedComb, subtractFlow)->Clone();
313   /*
314   subtractFlow(h2_etaPhi);
315   h2_etaPhi->GetYaxis()->SetRangeUser(-1.6, 1.6);//corresponds to the really used eta range
316  
317   int firstbin = h2_etaPhi->GetYaxis()->FindBin(-0.59);
318   int lastbin = h2_etaPhi->GetYaxis()->FindBin(0.59);
319
320   TH1D* h1_phi = projectToTH1D(h2_etaPhi, "fully corrected", firstbin, lastbin, 1.0);//last number is triggers
321   */
322   leg->AddEntry(near->Clone(), "near side", "l");
323   if(true) return;
324   TH1* away = getAnalysis(fileName, pt1Min, pt1Max, pt2Min, ptAssocMin, ptAssocMax, 6.9, multBinBegin, multBinEnd, 1, 2, 1, showPlots, subtractMixedComb, subtractFlow);
325   leg->AddEntry(away, "away side", "l");
326
327
328
329   TCanvas* c1 = new TCanvas("can", "can", gBasisSize+50, gBasisSize+50, gBasisSize, gBasisSize);
330   near->DrawCopy();
331
332   away->SetLineColor(kRed);
333   away->DrawCopy("same");
334   leg->Draw("same");
335 }
336
337 void peakDifference_mult(const char* fileName, double pt1Min = 4.0, double pt1Max = 14.0, double pt2Min = 2.0, Int_t subtractMixedComb = 1, Int_t subtractFlow = 1){
338
339   Int_t side = 0;//no effect because here both sides for one multiplicity are shown
340   Int_t mode = 0;
341   peakDifference(fileName, pt1Min, pt1Max, pt2Min, 1, 5, side, 0, mode, subtractMixedComb, subtractFlow);
342   peakDifference(fileName, pt1Min, pt1Max, pt2Min, 9, 10, side, 1, mode, subtractMixedComb, subtractFlow);
343
344 }
345
346 void peakDifference_side(const char* fileName, double pt1Min = 4.0, double pt1Max = 14.0, double pt2Min = 2.0, Int_t subtractMixedComb = 1, Int_t subtractFlow = 1){
347
348   Int_t mult = 0;//no effect because here both multiplicities for one side are shown
349   Int_t mode = 1;
350   peakDifference(fileName, pt1Min, pt1Max, pt2Min, mult, mult, 0, 0, mode, subtractMixedComb, subtractFlow);
351   peakDifference(fileName, pt1Min, pt1Max, pt2Min, mult, mult, 1, 1, mode, subtractMixedComb, subtractFlow);
352
353 }
354
355 //mode 0 near and away side (two different multiplicities in the two rows)
356 //mode 1 central and semi central (near side in top and away side in bottom row)
357 void peakDifference(const char* fileName, double pt1Min = 4.0, double pt1Max = 14.0, double pt2Min = 2.0, Int_t multBinBegin = 1, Int_t multBinEnd = 5, Int_t side = 0, Int_t yPos = 0, Int_t mode = 0,  Int_t subtractMixedComb = 1, Int_t subtractFlow = 1, Int_t draw = 0){
358
359   Double_t near_content[pt_assoc_bins_number-1];
360   Double_t away_content[pt_assoc_bins_number-1];
361   Double_t onePlusOne_content[pt_assoc_bins_number-1];
362   Double_t near_error[pt_assoc_bins_number-1];
363   Double_t away_error[pt_assoc_bins_number-1];
364   Double_t onePlusOne_error[pt_assoc_bins_number-1];
365
366   for(int i=0; i<pt_assoc_bins_number-1; i++){
367     TH1* near;
368     TH1* away;
369     TH1* onePlusOne;
370     TCanvas* can;
371
372     if(mode==0){
373       near = (TH1*)getAnalysis(fileName, pt1Min, pt1Max, pt2Min, pt_assoc_bins[i], pt_assoc_bins[i+1], 6.9, multBinBegin, multBinEnd, 0, 1, 1, 0, subtractMixedComb, subtractFlow)->Clone();
374       away = (TH1*)getAnalysis(fileName, pt1Min, pt1Max, pt2Min, pt_assoc_bins[i], pt_assoc_bins[i+1], 6.9, multBinBegin, multBinEnd, 1, 2, 1, 0, subtractMixedComb, subtractFlow)->Clone();
375       onePlusOne = (TH1*)getAnalysis(fileName, pt1Min, pt1Max, pt2Min, pt_assoc_bins[i], pt_assoc_bins[i+1], 6.9, multBinBegin, multBinEnd, 6, 2, 1, 0, subtractMixedComb, subtractFlow);
376         //onePlusOne = (TH1*)getAnalysis(fileName, pt2Min, pt1Min, pt2Min, pt_assoc_bins[i], pt_assoc_bins[i+1], 6.9, multBinBegin, multBinEnd, 6, 2, 1, 0, subtractMixedComb, subtractFlow);
377
378       can = new TCanvas(Form(" %i, mult %i-%i ", i, multBinBegin, multBinEnd), Form(" %i, mult %i-%i ", i, multBinBegin, multBinEnd), i*gBasisSize+100, yPos*(gBasisSize+50), gBasisSize, gBasisSize);
379       
380     }else if(mode==1){
381       near = (TH1*)getAnalysis(fileName, pt1Min, pt1Max, pt2Min, pt_assoc_bins[i], pt_assoc_bins[i+1], 6.9, 1, 5, side, 1, 1, 0, subtractMixedComb, subtractFlow)->Clone();
382       away = (TH1*)getAnalysis(fileName, pt1Min, pt1Max, pt2Min, pt_assoc_bins[i], pt_assoc_bins[i+1], 6.9, 9, 10, side, 2, 1, 0, subtractMixedComb, subtractFlow);
383
384       can = new TCanvas(Form(" %i, side %i ", i, side), Form(" %i, side %i ", i, side), i*gBasisSize+50, yPos*(gBasisSize+50), gBasisSize, gBasisSize);
385     }else{
386       Printf("mode does not exist!");
387       return;
388     }
389     away->SetLineColor(kRed);
390     if(mode==0)
391       onePlusOne->SetLineColor(kGreen);
392     
393     Int_t bin_start = near->FindBin(-1*g_phi_bin);
394     Int_t bin_end = near->FindBin(g_phi_bin);
395
396     near_content[i] = near->IntegralAndError(bin_start, bin_end, near_error[i]);
397     away_content[i] = away->IntegralAndError(bin_start, bin_end, away_error[i]);
398     if(mode==0)
399       onePlusOne_content[i] = onePlusOne->IntegralAndError(bin_start, bin_end, onePlusOne_error[i]);
400
401     ((TH1*)(near->Clone()))->DrawCopy();
402     ((TH1*)(away->Clone()))->DrawCopy("same");
403     if(mode==0)
404       ((TH1*)(onePlusOne->Clone()))->DrawCopy("same");
405
406     if(i==4){
407       TLegend* leg = getLegend();
408       if(mode==0){
409         leg->AddEntry(near,"near side","l");
410         leg->AddEntry(away,"away side","l");
411         leg->AddEntry(onePlusOne, "1plus1", "l");
412       }else if(mode==1){
413         leg->AddEntry(near,"central","l");
414         leg->AddEntry(away,"semi central","l");
415       }
416       leg->Draw("same");
417     }
418   }
419
420   double sum_near = 0;
421   double sum_away = 0;
422   double sum_1plus1 = 0;
423   double err_near = 0;
424   double err_away = 0;
425   double err_1plus1 = 0;
426
427   for(int i=0; i<pt_assoc_bins_number-1; i++){
428     Double_t diff = near_content[i] - away_content[i];
429     Double_t err = TMath::Sqrt(TMath::Power(near_error[i], 2) + TMath::Power(away_error[i], 2));
430
431     if(mode==0){
432       Printf("near side (%.1f - %.1f): %f +/- %f, away side %f +/- %f, difference: %f +/- %f ", pt_assoc_bins[i], pt_assoc_bins[i+1], near_content[i], near_error[i], away_content[i], away_error[i], diff, err);
433       sum_near += near_content[i]*(pt_assoc_bins[i] + pt_assoc_bins[i+1])/2;
434       sum_away += away_content[i]*(pt_assoc_bins[i] + pt_assoc_bins[i+1])/2;
435       sum_1plus1 += onePlusOne_content[i]*(pt_assoc_bins[i] + pt_assoc_bins[i+1])/2;
436       err_near += near_error[i]*(pt_assoc_bins[i] + pt_assoc_bins[i+1])/2;
437       err_away += away_error[i]*(pt_assoc_bins[i] + pt_assoc_bins[i+1])/2;
438       err_1plus1 += onePlusOne_error[i]*(pt_assoc_bins[i] + pt_assoc_bins[i+1])/2;
439     }else
440       Printf("central (%.1f - %.1f): %f +/- %f, semi central %f +/- %f, difference: %f +/- %f ", pt_assoc_bins[i], pt_assoc_bins[i+1], near_content[i], near_error[i], away_content[i], away_error[i], diff, err);
441   }
442
443   if(mode==0){
444     Printf("Near side pT: %f +/- %f", sum_near, err_near);
445     Printf("Away side pT: %f +/- %f", sum_away, err_away);
446     Printf("1plus1 pT: %f +/- %f", sum_1plus1, err_1plus1);
447   }
448
449   //scale content with the bin width
450   for(int i=0; i<pt_assoc_bins_number-1; i++){
451     near_content[i] /= 2*pt_assoc_bin_error[i];
452     near_error[i] /= 2*pt_assoc_bin_error[i];
453     away_content[i] /= 2*pt_assoc_bin_error[i];
454     away_error[i] /= 2*pt_assoc_bin_error[i];
455     if(mode==0){
456       onePlusOne_content[i] /= 2*pt_assoc_bin_error[i];
457       onePlusOne_error[i] /= 2*pt_assoc_bin_error[i];
458     }
459   }
460   /*
461   //divide content by 1+1 content
462   for(int i=0; i<pt_assoc_bins_number-1; i++){
463     near_content[i] /= onePlusOne_content[i];
464     near_error[i] /= onePlusOne_content[i];
465     away_content[i] /= onePlusOne_content[i];
466     away_error[i] /= onePlusOne_content[i];
467   }
468   */
469   TGraphErrors* graph_near = new TGraphErrors(pt_assoc_bins_number, pt_assoc_bin_center, near_content, pt_assoc_bin_error, near_error);
470   TGraphErrors* graph_away = new TGraphErrors(pt_assoc_bins_number, pt_assoc_bin_center, away_content, pt_assoc_bin_error, away_error);
471   TGraphErrors* graph_onePlusone = new TGraphErrors(pt_assoc_bins_number, pt_assoc_bin_center, onePlusOne_content, pt_assoc_bin_error, onePlusOne_error);
472
473   TCanvas* can_graph = new TCanvas(Form("result %i", yPos), Form("result %i", yPos), pt_assoc_bins_number*gBasisSize+50, yPos*(gBasisSize+50), gBasisSize, gBasisSize);
474
475   graph_near->GetXaxis()->SetTitle("p_{T,assoc} (GeV/c)");
476   graph_near->GetYaxis()->SetTitle("1/N dN/dpT");
477   graph_near->SetMarkerSize(2);
478   graph_near->SetLineWidth(2);
479   graph_near->SetMarkerColor(kBlue);
480   graph_near->SetLineColor(kBlue);
481   graph_near->SetMarkerStyle(20);
482   graph_away->GetXaxis()->SetTitle("p_{T,assoc} (GeV/c)");
483   graph_away->GetYaxis()->SetTitle("1/N dN/dpT");
484   graph_away->SetMarkerSize(2);
485   graph_away->SetLineWidth(2);
486   graph_away->SetMarkerColor(kRed);
487   graph_away->SetLineColor(kRed);
488   graph_away->SetMarkerStyle(22);
489   graph_near->Draw("AP");
490   graph_away->Draw("P");
491
492   if(false && mode==0){
493     graph_onePlusone->GetXaxis()->SetTitle("p_{T,assoc} (GeV/c)");
494     graph_onePlusone->GetYaxis()->SetTitle("1/N dN/dpT");
495     graph_onePlusone->SetMarkerSize(2);
496     graph_onePlusone->SetLineWidth(2);
497     graph_onePlusone->SetMarkerColor(kGreen);
498     graph_onePlusone->SetLineColor(kGreen);
499     graph_onePlusone->SetMarkerStyle(22);
500     graph_onePlusone->Draw("P");
501   }
502   gPad->SetLogy();
503
504   TLegend* leg2 = getLegend();
505   if(mode==0){
506     leg2->AddEntry(graph_near,"near side","l");
507     leg2->AddEntry(graph_away,"away side","l");
508     leg2->AddEntry(graph_onePlusone,"1plus1","l");
509   }else if(mode==1){
510     leg2->AddEntry(graph_near,"central","l");
511     leg2->AddEntry(graph_away,"semi central","l");
512   }
513   leg2->Draw("same");
514   
515 }
516
517
518
519
520
521
522
523 void create_peakDifference_pictures(const char* fileName){
524
525   gROOT->SetBatch(kTRUE);
526   
527   Printf("peakDifference_draw(fileName, 6, 8, 4, 1, 1, 1");
528   peakDifference_draw(fileName, 6, 8, 4, 1, 1, 1);
529   
530   Printf("peakDifference_draw(fileName, 6, 8, 6, 1, 1, 1");
531   peakDifference_draw(fileName, 6, 8, 6, 1, 1, 1);
532   Printf("peakDifference_draw(fileName, 8, 10, 4, 1, 1, 1");
533   peakDifference_draw(fileName, 8, 10, 4, 1, 1, 1);
534   Printf("peakDifference_draw(fileName, 8, 10, 6, 1, 1, 1");
535   peakDifference_draw(fileName, 8, 10, 6, 1, 1, 1);
536   Printf("peakDifference_draw(fileName, 10, 12, 4, 1, 1, 1");
537   peakDifference_draw(fileName, 10, 12, 4, 1, 1, 1);
538   Printf("peakDifference_draw(fileName, 10, 12, 6, 1, 1, 1");
539   peakDifference_draw(fileName, 10, 12, 6, 1, 1, 1);
540     
541
542   TCanvas* can = new TCanvas("can_filename", "can_filename");
543   TH1F* mixedDist = getMixedDist(fileName);
544   mixedDist->SetTitle(fileName);
545   mixedDist->Draw("colz");
546   can->SaveAs("pt_spectra/filename.eps");
547   
548 }
549
550
551
552
553 void peakDifference_draw(const char* fileName, double pt1Min = 4.0, double pt1Max = 14.0, double pt2Min = 2.0, Int_t yPos = 0,  Int_t subtractMixedComb = 1, Int_t subtractFlow = 1){
554
555   TGraphErrors* graph_central_near = (TGraphErrors*)(peakDifference_graph(fileName, pt1Min, pt1Max, pt2Min, 1, 5, 0, yPos, subtractMixedComb, subtractFlow)->Clone());
556   TGraphErrors* graph_central_away = (TGraphErrors*)(peakDifference_graph(fileName, pt1Min, pt1Max, pt2Min, 1, 5, 1, yPos, subtractMixedComb, subtractFlow)->Clone());
557
558   TGraphErrors* graph_semi_near = (TGraphErrors*)(peakDifference_graph(fileName, pt1Min, pt1Max, pt2Min, 9, 10, 0, yPos, subtractMixedComb, subtractFlow)->Clone());
559   TGraphErrors* graph_semi_away = (TGraphErrors*)(peakDifference_graph(fileName, pt1Min, pt1Max, pt2Min, 9, 10, 1, yPos, subtractMixedComb, subtractFlow)->Clone());
560
561   TCanvas* can_graph = new TCanvas(Form("result %i", yPos), Form("result %i", yPos), gBasisSize+50, yPos*(gBasisSize+50), gBasisSize, gBasisSize);
562
563   Int_t elements = 7;
564   
565   Double_t maximum = TMath::MaxElement(elements, graph_central_near->GetY());
566   Printf("maximum of central near is %f ", maximum);
567   Double_t max  = TMath::MaxElement(elements, graph_central_away->GetY());
568   Printf("maximum of central away is %f ", max);
569   if(max>maximum) maximum = max;
570   max = TMath::MaxElement(elements, graph_semi_near->GetY());
571   Printf("maximum of semi near is %f ", max);
572   if(max>maximum) maximum = max;
573   max = TMath::MaxElement(elements, graph_semi_away->GetY());
574   Printf("maximum of semi away is %f ", max);
575   if(max>maximum) maximum = max;
576   graph_central_near->SetMaximum(maximum*1.25);
577   
578   Double_t minimum = TMath::MinElement(elements, graph_central_near->GetY());
579   //if(minimum==0) minimum = maximum;
580   Printf("minimum of central near is %f ", minimum);
581   Double_t min = TMath::MinElement(elements, graph_central_away->GetY());
582   Printf("minimum of central away is %f ", min);
583   if(min>0 && min<minimum) minimum = min;
584   min = TMath::MinElement(elements, graph_semi_near->GetY());
585   Printf("minimum of semi near is %f ", min);
586   if(min>0 && min<minimum) minimum = min;
587   min = TMath::MinElement(elements, graph_semi_away->GetY());
588   Printf("minimum of semi away is %f ", min);
589   if(min>0 && min<minimum) minimum = min;
590   graph_central_near->SetMinimum(minimum/1.30);
591   
592     
593   graph_central_near->SetTitle(Form("p_{T,assoc} spectrum for %.1f < p_{T,1} < %.1f and %.1f < p_{T,2} < p_{T,1}", pt1Min, pt1Max, pt2Min));
594   graph_central_near->Draw("AP");
595
596   graph_central_away->SetMarkerColor(kRed);
597   graph_central_away->SetLineColor(kRed);
598   graph_central_away->Draw("P");
599   
600   graph_semi_near->SetMarkerColor(kCyan);
601   graph_semi_near->SetLineColor(kCyan);
602   graph_semi_near->Draw("P");
603
604   graph_semi_away->SetMarkerColor(kOrange);
605   graph_semi_away->SetLineColor(kOrange);
606   graph_semi_away->Draw("P");
607
608   gPad->SetLogy();
609
610   TLegend* leg = getLegend(0.40,0.75,0.85,0.9);
611   leg->AddEntry(graph_central_near,"central near","l");
612   leg->AddEntry(graph_central_away,"central away side","l");
613   leg->AddEntry(graph_semi_near,"semi central near","l");
614   leg->AddEntry(graph_semi_away,"semi central away","l");
615   leg->Draw("same");
616
617   can_graph->SaveAs(Form("pt_spectra/pt_spectrum_%.0f_%.0f_%.0f.eps", pt1Min, pt1Max, pt2Min));
618   /*
619   save_graph_ratio(graph_central_near, graph_central_away, graph_semi_near, graph_semi_away, elements, Form("central and semi near over away p_{T,assoc} spectrum for %.1f < p_{T,1} < %.1f and %.1f < p_{T,2} < p_{T,1}", pt1Min, pt1Max, pt2Min), Form("pt_spectra/centralANDsemi_near_away_ratio_%.0f_%.0f_%.0f.eps", pt1Min, pt1Max, pt2Min), "central", "semi central");
620
621   save_graph_ratio(graph_central_near, graph_semi_near, graph_central_away, graph_semi_away, elements, Form("near and semi central over semi p_{T,assoc} spectrum for %.1f < p_{T,1} < %.1f and %.1f < p_{T,2} < p_{T,1}", pt1Min, pt1Max, pt2Min), Form("pt_spectra/nearANDaway_central_semi_ratio_%.0f_%.0f_%.0f.eps", pt1Min, pt1Max, pt2Min), "near", "away");
622
623   save_graph_difference(graph_central_near, graph_central_away, graph_semi_near, graph_semi_away, elements, Form("central and semi near minus away p_{T,assoc} spectrum for %.1f < p_{T,1} < %.1f and %.1f < p_{T,2} < p_{T,1}", pt1Min, pt1Max, pt2Min), Form("pt_spectra/centralANDsemi_near_away_diff_%.0f_%.0f_%.0f.eps", pt1Min, pt1Max, pt2Min));
624   */
625 }
626
627
628 void save_graph_ratio(TGraphErrors* first, TGraphErrors* second, TGraphErrors* third, TGraphErrors* forth, const Int_t bins, char* title, char* name, char* legend1, char* legend2){
629
630   Double_t start_x = 0.45;
631   if(legend1=="near")
632     start_x = 0.70;
633
634   TLegend *leg  = getLegend(start_x,0.75,0.85,0.9);
635
636   TGraphErrors* graph = (TGraphErrors*)(save_graph_compute(first, second, bins, title, 0, NULL, NULL)->Clone());
637   if(third!=NULL && forth!=NULL){
638     TGraphErrors* graph2 = (TGraphErrors*)(save_graph_compute(third, forth, bins, title, 0, NULL, NULL)->Clone());
639
640     leg->AddEntry(graph, legend1, "p");
641     leg->AddEntry(graph2, legend2, "p");
642     
643     save_graph(graph, graph2, name, 0, leg);
644   }else{
645     save_graph(graph, NULL, name, 0, leg);
646   }
647
648 }
649
650
651 void save_graph_difference(TGraphErrors* first, TGraphErrors* second, TGraphErrors* third, TGraphErrors* forth, const Int_t bins, char* title, char* name){
652
653   Double_t diff1 = 0;
654   Double_t diff1_err = 0;
655   Double_t diff2 = 0;
656   Double_t diff2_err = 0;
657
658   TGraphErrors* graph = (TGraphErrors*)(save_graph_compute(first, second, bins, title, 1, &diff1, &diff1_err)->Clone());
659   TGraphErrors* graph2 = (TGraphErrors*)(save_graph_compute(third, forth, bins, title, 1, &diff2, &diff2_err)->Clone());
660
661   TLegend *leg  = getLegend(0.45,0.15,0.85,0.3);
662   leg->AddEntry(graph, "central", "p");
663   leg->AddEntry(graph2, "semi central", "p");
664   leg->AddEntry(graph,  Form("\\Delta E = %.1f \\pm %.1f", diff1, diff1_err),"");
665   leg->AddEntry(graph2,  Form("\\Delta E = %.1f \\pm %.1f", diff2, diff2_err),"");
666
667   save_graph(graph, graph2, name, 1, leg);
668
669 }
670
671
672 //mode: 0 ratio of the graphs
673 //mode: 1 difference of the graphs
674 //returns difference of the graphs
675 void save_graph(TGraphErrors* first, TGraphErrors* second, char* name, int mode, TLegend *leg){
676   TCanvas* can_graph_ratio = new TCanvas("can_saveGraph", "can_saveGraph", gBasisSize+50, gBasisSize+50, gBasisSize, gBasisSize);
677   if(mode==0){
678     first->SetMinimum(0.4);
679     first->SetMaximum(1.6);
680   }
681   first->SetMarkerSize(1);
682   first->SetLineWidth(3);
683   first->SetMarkerColor(kBlue);
684   first->SetLineColor(kBlue);
685   first->SetMarkerStyle(20);
686   first->Draw("AP");
687
688   if(second!=NULL){
689     second->SetMarkerSize(1);
690     second->SetLineWidth(3);
691     second->SetMarkerColor(kRed);
692     second->SetLineColor(kRed);
693     second->SetMarkerStyle(20);
694     second->Draw("P");
695   }
696
697   leg->Draw("same");
698  
699   can_graph_ratio->SaveAs(name);
700 }
701
702 TGraphErrors* save_graph_compute(TGraphErrors* first, TGraphErrors* second, const Int_t bins, char* title, int mode, Double_t* diff, Double_t* diff_err){
703   Double_t content_x[bins];
704   Double_t content_y[bins];
705   Double_t x_error[bins];
706   Double_t y_error[bins];
707   for(int i=0; i<bins; i++){
708     content_x[i] = 0;
709     content_y[i] = 0;
710     x_error[i] = 0;
711     y_error[i] = 0;
712
713     Double_t error_first;
714     Double_t error_second;
715     first->GetPoint(i, content_x[i], content_y[i]);
716     x_error[i] = first->GetErrorX(i);
717     error_first = first->GetErrorY(i);
718     Double_t content_second;
719     second->GetPoint(i, content_x[i], content_second);
720     error_second = second->GetErrorY(i);
721     if(content_second>0 && error_second>0){
722       if(mode==0){
723         content_y[i] /= content_second;
724         y_error[i] = TMath::Sqrt(TMath::Power(error_first/content_second, 2) + TMath::Power(error_second/content_second*content_y[i], 2));
725       }else if(mode==1){
726         content_y[i] -= content_second;
727         y_error[i] = TMath::Sqrt(TMath::Power(error_first, 2) + TMath::Power(error_second, 2));
728       }else{
729         Printf("calls save graph with no correct mode");
730         return;
731       }
732     }else{Printf("content or content error is smaller or equal to 0");}
733   }
734    //if this is mode 1 (difference of the graphs) this calculates the difference of the plots
735   //Double_t diff = 0;
736   //Double_t diff_err = 0;
737   if(mode==1){
738     for(int i=0; i<bins; i++){
739       *diff += content_y[i] * content_x[i];
740       *diff_err += TMath::Power(y_error[i]*content_x[i], 2);
741     }
742     *diff_err = TMath::Sqrt(*diff_err);
743
744   }
745   TGraphErrors* graph = new TGraphErrors(bins, content_x, content_y, x_error, y_error);
746   graph->SetTitle(title);
747   graph->GetXaxis()->SetTitle("p_{T,assoc} (GeV/c)");
748
749   return graph;
750 }
751
752
753 TGraphErrors* peakDifference_graph(const char* fileName, double pt1Min = 4.0, double pt1Max = 14.0, double pt2Min = 2.0, Int_t multBinBegin = 1, Int_t multBinEnd = 5, Int_t side = 0, Int_t yPos = 0, Int_t subtractMixedComb = 1, Int_t subtractFlow = 1, Int_t draw = 0){
754   Double_t content[pt_assoc_bins_number-1];
755   Double_t error[pt_assoc_bins_number-1];
756
757   for(int i=0; i<pt_assoc_bins_number-1; i++){
758     TH1* near = (TH1*)getAnalysis(fileName, pt1Min, pt1Max, pt2Min, pt_assoc_bins[i], pt_assoc_bins[i+1], 6.9, multBinBegin, multBinEnd, side, 1, 1, 0, subtractMixedComb, subtractFlow)->Clone();
759     
760     Int_t bin_start = near->FindBin(-1*g_phi_bin);
761     Int_t bin_end = near->FindBin(g_phi_bin);
762
763     content[i] = near->IntegralAndError(bin_start, bin_end, error[i]);
764   }
765
766   //scale content with the bin width
767   for(int i=0; i<pt_assoc_bins_number-1; i++){
768     content[i] /= 2*pt_assoc_bin_error[i];
769     error[i] /= 2*pt_assoc_bin_error[i];
770   }
771
772   TGraphErrors* graph = new TGraphErrors(pt_assoc_bins_number-1, pt_assoc_bin_center, content, pt_assoc_bin_error, error);
773
774   graph->GetXaxis()->SetTitle("p_{T,assoc} (GeV/c)");
775   graph->GetYaxis()->SetTitle("1/N dN/dpT");
776   graph->SetMarkerSize(1);
777   graph->SetLineWidth(3);
778   graph->SetMarkerColor(kBlue);
779   graph->SetLineColor(kBlue);
780   graph->SetMarkerStyle(20);
781
782   return graph;
783   
784 }
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801 void showAll1plus1(const char* fileName, double pt1Min = 4.0, double pt1Max = 14.0, double pt2Min = 2.0, Int_t subtractMixedComb = 1, Int_t subtractFlow = 1){
802
803   show1plus1("AnalysisResults_1045.root", pt1Min, pt1Max, 1, 5, 0, subtractFlow);
804
805   show1plus1("AnalysisResults_1045.root", pt1Min, pt1Max, 9, 10, 1, subtractFlow);
806 }
807
808 void show1plus1(const char* fileName, double pt1Min = 4.0, double pt1Max = 14.0, Int_t multBinBegin = 1, Int_t multBinEnd = 5, Int_t yPos = 0, Int_t subtractFlow = 1){
809
810   //for 1+1 there is no mixed comb
811   Int_t subtractMixedComb = 0;
812
813   const int pt1_bins = 2;//(pt1Max-pt1Min)/2;
814   static const int pt1_bins_max = 20;
815
816   if(pt1_bins>pt1_bins_max){
817     printf("error not enough pt1_bins");
818     return;
819   }
820
821   Double_t content[pt1_bins_max][pt_assoc_bins_number-1];
822   Double_t error[pt1_bins_max][pt_assoc_bins_number-1];
823
824   for(int i=0; i<pt_assoc_bins_number-1; i++){
825     TCanvas* can = new TCanvas(Form("1plus1 %i, pT %i", yPos, i), Form("1plus1 %i, pT %i", yPos, i), i*gBasisSize+50, yPos*(gBasisSize+50), gBasisSize, gBasisSize);
826      
827     TLegend *leg  = getLegend();
828
829     for(int j=0; j<pt1_bins; j++){
830       double pt1Minimum = pt1Min+j*2.0;
831       TH1D* onePlusOne = (TH1*)getAnalysis(fileName, pt1Minimum, pt1Minimum + 2.0, 0, pt_assoc_bins[i], pt_assoc_bins[i+1], 6.9, multBinBegin, multBinEnd, 6, 2, 1, 0, subtractMixedComb, subtractFlow);
832       
833       Int_t bin_start = onePlusOne->FindBin(-1*g_phi_bin);
834       Int_t bin_end = onePlusOne->FindBin(g_phi_bin);
835
836       content[j][i] = onePlusOne->IntegralAndError(bin_start, bin_end, error[j][i]);
837
838       if(j==1)
839         onePlusOne->SetLineColor(kRed);
840       else if(j==2)
841         onePlusOne->SetLineColor(kGreen);
842       else if(j==3)
843         onePlusOne->SetLineColor(kMagenta);
844
845       if(j==0){
846         ((TH1*)(onePlusOne->Clone()))->DrawCopy();
847       }else{
848         ((TH1*)(onePlusOne->Clone()))->DrawCopy("same");
849       }
850
851       leg->AddEntry((TH1*)(onePlusOne->Clone()), Form("pT %.0f", pt1Minimum) ,"l");
852       if(j==pt1_bins-1)
853         leg->Draw("same");
854     }
855   }
856
857
858   TCanvas* can_graph = new TCanvas(Form("result %i", yPos), Form("result %i", yPos), pt_assoc_bins_number*gBasisSize+50, yPos*(gBasisSize+50), gBasisSize, gBasisSize);
859
860   TLegend *leg  = getLegend();
861
862   for(int j=0; j<pt1_bins; j++){
863     TGraphErrors* graph = new TGraphErrors(pt_assoc_bins_number, pt_assoc_bin_center, content[j], pt_assoc_bin_error, error[j]);
864
865     graph->GetXaxis()->SetTitle("p_{T,assoc} (GeV/c)");
866     graph->GetYaxis()->SetTitle("1/N dN/dpT");
867     graph->SetMarkerSize(2);
868     graph->SetLineWidth(2);
869     graph->SetMarkerStyle(20);
870
871     if(j==0){
872       //graph->SetMarkerColor(kCyan);
873       //graph->SetLineColor(kCyan);
874       graph->SetMarkerColor(kBlue);
875       graph->SetLineColor(kBlue);
876       (TGraphErrors*)(graph->Clone())->Draw("AP");
877       //(TGraphErrors*)(graph->Clone())->Draw("P");
878     }else if(j==1){
879       //graph->SetMarkerColor(kOrange);
880       //graph->SetLineColor(kOrange);
881       graph->SetMarkerColor(kRed);
882       graph->SetLineColor(kRed);
883       (TGraphErrors*)(graph->Clone())->Draw("P");
884     }else if(j==2){
885       //graph->SetMarkerColor(kMagenta);
886       //graph->SetLineColor(kMagenta);
887       graph->SetMarkerColor(kGreen);
888       graph->SetLineColor(kGreen);
889       (TGraphErrors*)(graph->Clone())->Draw("P");
890     }
891
892     double pt1Minimum = pt1Min+j*2.0;
893     leg->AddEntry((TGraphErrors*)(graph->Clone()),Form("pT %.0f", pt1Minimum),"l");
894     if(j==pt1_bins-1)
895       leg->Draw("same");
896   }
897   
898
899 }
900
901
902 //does the reading out of the results
903 //divides the same event by the mixed events
904 //subtracts the mixed combinatorics
905 TH1D* getAnalysis(const char* fileName, double pt1Min = 4.0, double pt1Max = 14.0, Double_t pt2Min = 2.0, Double_t ptAssocMin = 0.5, Double_t ptAssocMax = 8.0, Double_t setVertex = 7, Int_t multBinBegin = 1, Int_t multBinEnd = 5, Int_t step = 0, Int_t posX = 1, Int_t posY = 1, Int_t showPlots = 0, Int_t subtractMixedComb = 0, Int_t subtractFlow =0, Int_t* trigger = NULL)
906 {
907   loadlibs();
908   //to guarantee to pick only the bins from the choosen pt on
909   pt1Min += 0.01;
910   pt1Max -= 0.01;
911   pt2Min += 0.01;
912   ptAssocMin += 0.01;
913   ptAssocMax -= 0.01;
914   
915   AliTwoPlusOneContainer* h = (AliTwoPlusOneContainer*) GetTwoPlusOne(fileName);
916
917   AliUEHist::CFStep step_same = step;//(AliUEHist::CFStep) AliTwoPlusOneContainer::kSameNS;
918   AliUEHist::CFStep step_mixed = (step%2)+2;//(AliUEHist::CFStep) AliTwoPlusOneContainer::kMixedNS;
919   if(step>=7) step_mixed = ((step+1)%2)+2;
920   AliUEHist::CFStep step_mixedComb = (step%2)+4;//(AliUEHist::CStep) AliTwoPlusOneContainer::kMixedCombNS;
921   AliUEHist::CFStep step_backgroundSame = (step%2)+7;//(AliUEHist::CStep) AliTwoPlusOneContainer::kBackgroundSameNS;
922
923   AliUEHist::CFStep step_1plus1 = (AliUEHist::CFStep) AliTwoPlusOneContainer::k1plus1;
924   AliUEHist::CFStep step_1plus1_mixed = (AliUEHist::CFStep) AliTwoPlusOneContainer::kMixed1plus1;
925
926   h->GetData()->SetPtRange(ptAssocMin, ptAssocMax);
927   h->GetData()->SetPt2Min(pt2Min);
928   h->GetData()->SetZVtxRange(-1*setVertex, setVertex);
929  
930   //GetSumOfRatios2(mixed, step, region, ptLeadMin, ptLeadMax, multBinBegin, multBinEnd, normalizePerTrigger, stepForMixed)
931   TH2D* h2_etaPhi;
932   TH2D* h2_etaPhi_mixedComb;
933   TH2D* h2_etaPhi_backgroundSame;
934
935   //TH2D* h2_etaPhi2;
936   //TH2D* h2_etaPhi_mixedComb2;
937
938   TH1D* h1_phi_cloneProject;
939
940   if(step>=2||!subtractMixedComb){
941     Int_t trigger_etaPhi;
942     if(step!=6)
943       h2_etaPhi = (TH2D*) h->GetData()->GetSumOfRatios2(h->GetData(), step_same, 0, pt1Min, pt1Max, multBinBegin, multBinEnd, kTRUE, step_mixed, &trigger_etaPhi);
944     else  if(step==6)
945       h2_etaPhi = (TH2D*) h->GetData()->GetSumOfRatios2(h->GetData(), step_1plus1, 0, pt1Min, pt1Max, multBinBegin, multBinEnd, kTRUE, step_1plus1_mixed, &trigger_etaPhi);
946
947     if(trigger!=NULL)
948       *trigger = (Int_t)trigger_etaPhi;
949   }else if(step<2 && subtractMixedComb){
950     Int_t trigger_same;
951     Int_t trigger_mixed_comb;
952     Int_t trigger_background_same;
953
954     //h2_etaPhi = (TH2D*) h->GetData()->GetSumOfRatios2(h->GetData(), step_same, 0, pt1Min, pt1Max, multBinBegin, multBinEnd, kFALSE, step_mixed, &trigger_same);
955     h2_etaPhi = (TH2D*) h->GetData()->GetSumOfRatios2(h->GetData(), step_same, 0, pt1Min, pt1Max, multBinBegin, multBinEnd, kFALSE, step_1plus1_mixed, &trigger_same);
956     TH2D* h2_etaPhi_clone = h2_etaPhi->Clone();
957     if(subtractFlow)
958       subtractFlow(h2_etaPhi_clone);
959     h2_etaPhi_clone->Scale(1.0/trigger_same);
960
961     //don't need to use getMixedComb_scaled_backgroundSame, see compareScaledMixedComb which shows that both methods are identical but here getSumOfRatios is used which makes it easier (and safer against errors)
962     //the 1+1 analysis can only be used if the full analysis was done within the same pt bins
963     
964     
965     if(step==0)
966       h2_etaPhi_mixedComb = (TH2D*) h->GetData()->GetSumOfRatios2(h->GetData(), step_1plus1, 0, pt1Min, pt1Max, multBinBegin, multBinEnd, kFALSE, step_1plus1_mixed, &trigger_mixed_comb);
967     else if(step==1)
968       h2_etaPhi_mixedComb = (TH2D*) h->GetData()->GetSumOfRatios2(h->GetData(), step_1plus1, 0, pt2Min, pt1Min, multBinBegin, multBinEnd, kFALSE, step_1plus1_mixed, &trigger_mixed_comb);
969     else //this is never used, it's the old method of getting the background
970       h2_etaPhi_mixedComb = (TH2D*) h->GetData()->GetSumOfRatios2(h->GetData(), step_mixedComb, 0, pt1Min, pt1Max, multBinBegin, multBinEnd, kFALSE, step_mixed, &trigger_mixed_comb);
971
972     h2_etaPhi_backgroundSame = (TH2D*) h->GetData()->GetSumOfRatios2(h->GetData(), step_backgroundSame, 0, pt1Min, pt1Max, multBinBegin, multBinEnd, kFALSE, step_mixed, &trigger_background_same);
973
974     //trigger_background_same *= 2;//error in the plots for runs 968 and 973
975     double trigger_ratio = (double)trigger_background_same;
976     if(trigger_mixed_comb>0)
977       trigger_ratio /= trigger_mixed_comb;
978     Printf("trigger mixed comb: %i, trigger background same %i, ratio %f", trigger_mixed_comb, trigger_background_same, trigger_ratio);
979     h2_etaPhi_mixedComb->Scale(trigger_ratio);
980     trigger_mixed_comb = trigger_background_same;
981     Printf("trigger same: %i, trigger mixed comb %i ", trigger_same, trigger_mixed_comb);
982
983     int firstbin = h2_etaPhi->GetYaxis()->FindBin(-1*g_eta_bin);
984     int lastbin = h2_etaPhi->GetYaxis()->FindBin(g_eta_bin);
985
986     if(showPlots==1){
987       TCanvas* can_1 = new TCanvas("sameEvent near side", "sameEvent near side", 100, 50, gBasisSize, gBasisSize);
988       h2_etaPhi->DrawCopy("surf1");
989     
990       //TH1D* h1_phi_1 = projectToTH1D(h2_etaPhi, "same near", firstbin, lastbin, trigger_same);
991       TH1D* h1_phi_1 = projectToTH1D(h2_etaPhi, "same near", firstbin, lastbin, 1.0);
992       h1_phi_1->SetLineColor(kRed);
993       //h1_phi_1->DrawCopy();
994       
995       TLegend *leg  = getLegend();
996       leg->AddEntry(h1_phi_1,"same event","l");
997     
998       TCanvas* can_2 = new TCanvas("sameEvent mixed comb", "sameEvent mixed comb", gBasisSize+100, 50, gBasisSize, gBasisSize);
999       h2_etaPhi_mixedComb->DrawCopy("surf1");
1000       //TH1D* h1_phi_2 = projectToTH1D(h2_etaPhi_mixedComb, "mixedComb near", firstbin, lastbin, trigger_mixed_comb);
1001       TH1D* h1_phi_2 = projectToTH1D(h2_etaPhi_mixedComb, "mixedComb near", firstbin, lastbin, 1.0);
1002       Printf(Form("trigger mixed_comb", trigger_mixed_comb));
1003       //h1_phi_2->DrawCopy();
1004       leg->AddEntry(h1_phi_2->Clone(),"mixed comb","l");
1005       //leg->Draw("same");
1006       //if(true) return;
1007       TCanvas* can_2 = new TCanvas("sameEvent flow subtracted", "sameEvent flow subtracted", 100, 2*(gBasisSize+50), gBasisSize, gBasisSize);
1008       //TH2D* h2_etaPhi_clone = h2_etaPhi->Clone(); // is already cloned earlier
1009       //subtractFlow(h2_etaPhi_clone);
1010       
1011       h1_phi_cloneProject = projectToTH1D(h2_etaPhi_clone, "same flow subtracted", firstbin, lastbin, trigger_same);
1012       h1_phi_cloneProject->DrawCopy();
1013     
1014       TCanvas* can_3 = new TCanvas("mixed comb subtracted", "mixed comb subtracted", 2*gBasisSize+100, 2*(gBasisSize+50), gBasisSize, gBasisSize);
1015       h2_etaPhi->Add(h2_etaPhi_mixedComb, -1);
1016       //h2_etaPhi2->Add(h2_etaPhi_mixedComb2, -1);
1017     
1018       if(trigger_same-trigger_mixed_comb>0)
1019         h2_etaPhi->Scale(1.0/(trigger_same-trigger_mixed_comb));
1020       //h2_etaPhi2->Scale(1.0/(trigger_same2-trigger_mixed_comb2));
1021
1022       //h2_etaPhi->DrawCopy("surf1");
1023       h1_phi_3 = projectToTH1D(h2_etaPhi, "same minus mixedComb", firstbin, lastbin, 1.0);
1024       //h1_phi_3_b = projectToTH1D(h2_etaPhi2, "same minus mixedComb away", firstbin, lastbin, 1.0);
1025       h1_phi_3->SetLineColor(kRed);
1026       h1_phi_3->DrawCopy();
1027       //h1_phi_3_b->DrawCopy("same");
1028     
1029       TLegend* leg2 = getLegend();
1030       leg2->AddEntry(h1_phi_3, "near side", "l");
1031       //leg2->AddEntry(h1_phi_3_b, "away side", "l");
1032       leg2->Draw("same");
1033     }else{
1034       
1035        h2_etaPhi->Add(h2_etaPhi_mixedComb, -1);
1036     
1037       if(trigger_same-trigger_mixed_comb>0)
1038         h2_etaPhi->Scale(1.0/(trigger_same-trigger_mixed_comb));
1039       //using backgroundSame as correction, can only be used if the used phi and eta bins of the associated particles are very close to the trigger particles
1040       /*
1041       h2_etaPhi->Add(h2_etaPhi_backgroundSame, -1);
1042       h2_etaPhi->Scale(1.0/(trigger_same-trigger_background_same));
1043       */
1044
1045       if(subtractFlow)
1046         subtractFlow(h2_etaPhi_mixedComb);
1047       if(trigger_mixed_comb>0)
1048         h2_etaPhi_mixedComb->Scale(1.0/trigger_mixed_comb);
1049     }
1050     
1051     if(trigger!=NULL)
1052       *trigger = (Int_t)trigger_same-trigger_mixed_comb;
1053
1054   }else{
1055     Printf("cannot subtract mixed combinatorics from step %i ", step);
1056     return 0;
1057   }
1058
1059   if(subtractFlow)
1060     subtractFlow(h2_etaPhi);
1061   h2_etaPhi->GetYaxis()->SetRangeUser(-1.6, 1.6);//corresponds to the really used eta range
1062  
1063   int firstbin = h2_etaPhi->GetYaxis()->FindBin(-1*g_eta_bin);
1064   int lastbin = h2_etaPhi->GetYaxis()->FindBin(g_eta_bin);
1065
1066   TH1D* h1_phi = projectToTH1D(h2_etaPhi, "fully corrected", firstbin, lastbin, 1.0);
1067   //TH1D* h1_phi = projectToTH1D(h2_etaPhi_mixedComb, "fully corrected", firstbin, lastbin, 1.0);//shows background distributions
1068
1069   if(showPlots>0){
1070     TLegend *leg  = getLegend();
1071     
1072     TCanvas* can_4 = new TCanvas(Form("fully corrected, %i, %i ", posX, posY), Form("fully corrected, %i, %i ", posX, posY), posX*gBasisSize+100, 50, gBasisSize, gBasisSize);
1073     h2_etaPhi->GetYaxis()->SetRangeUser(-1.4, 1.4);
1074     h2_etaPhi->DrawCopy("surf1");
1075     //h2_etaPhi_mixedComb->DrawCopy("surf1");
1076     //h1_phi->DrawCopy();
1077     //h1_phi_cloneProject->SetLineColor(kRed);
1078     //h1_phi_cloneProject->DrawCopy("same");
1079
1080     leg->AddEntry(h1_phi,"with mixed comb","l");
1081     leg->AddEntry(h1_phi_cloneProject,"without mixed comb","l");
1082
1083     //leg->Draw("same");
1084   }
1085
1086   if(showPlots==2){
1087     TCanvas* can_5 = new TCanvas(Form("compare projection, %i, %i ", posX, posY), Form("compare projection, %i, %i ", posX, posY), posX*gBasisSize+100, posY*gBasisSize+50, gBasisSize, gBasisSize);
1088     TLegend *leg2  = getLegend();
1089
1090     h1_phi->DrawCopy();
1091     leg2->AddEntry(h1_phi,"chosen correction","l");
1092     TH1D* h1_phi_raw = projectToTH1D(h2_etaPhi_clone, "raw same event", firstbin, lastbin, 1.0);
1093     h1_phi_raw->SetLineColor(kRed);
1094     h1_phi_raw->DrawCopy("same");
1095     leg2->AddEntry(h1_phi_raw,"raw same event","l");
1096     TH1D* h1_phi_mixedComb = projectToTH1D(h2_etaPhi_mixedComb, "mixed comb", firstbin, lastbin, 1.0);
1097     h1_phi_mixedComb->SetLineColor(kGreen);
1098     h1_phi_mixedComb->DrawCopy("same");
1099     leg2->AddEntry(h1_phi_mixedComb,"mixed comb","l");
1100     leg2->Draw("same");
1101   }
1102
1103   return h1_phi;
1104 }
1105
1106
1107 TH1D* projectToTH1D(TH2D* etaPhi, char* name, int firstbin, int lastbin, int trigger){
1108   //  Printf(Form("name %s", name));
1109
1110   TH1D* h1_phi_1 = etaPhi->ProjectionX(Form("px_%s", name), firstbin, lastbin);
1111   h1_phi_1->SetLineWidth(3);
1112   h1_phi_1->SetStats(kFALSE);
1113   h1_phi_1->Scale(1.0/trigger);
1114   h1_phi_1->Scale(1.0/(double)(lastbin-firstbin+1));
1115   h1_phi_1->Scale(etaPhi->GetYaxis()->GetBinWidth(firstbin));//scale with eta bin width 
1116   h1_phi_1->GetXaxis()->SetRangeUser(-TMath::Pi()/2+0.01, TMath::Pi()/2-0.01);
1117   //h1_phi_1->GetXaxis()->SetRangeUser(-TMath::Pi()/2+0.01, 3*TMath::Pi()/2-0.01);
1118   h1_phi_1->SetYTitle("1/N \\ dN/(d \\Delta \\varphi)");
1119
1120   symmetrize(h1_phi_1);
1121   subtractBaseline(h1_phi_1);
1122
1123   return h1_phi_1;
1124 }
1125
1126 TLegend* getLegend(double x_start = 0.65, double y_start = 0.7, double x_end = 0.85, double y_end = 0.9){
1127   TLegend *leg  = new TLegend(x_start, y_start, x_end, y_end);
1128   leg->SetFillColor(10);
1129   leg->SetFillStyle(0);
1130   leg->SetBorderSize(0);
1131   leg->SetTextFont(gStyle->GetTextFont());
1132   leg->SetTextSize(gStyle->GetTextSize()*1.0);
1133   return leg;
1134 }
1135
1136 void compareAllBackground(const char* fileName, double pt1Min = 4.0, double pt1Max = 14.0, Double_t pt2Min = 2.0, Int_t subtractMixedComb = 0, Int_t subtractFlow = 0){
1137
1138   //static const int pt_assoc_bins_number = 8;
1139   //Double_t pt_assoc_bins[pt_assoc_bins_number] = {0.5, 1.0, 2.0, 3.0, 4.0, 6.0, 8.0, 10.0};
1140
1141   for(int i=0; i<pt_assoc_bins_number-1; i++){
1142     compareBackground(fileName, pt1Min, pt1Max, pt2Min, pt_assoc_bins[i], pt_assoc_bins[i+1], 1, 5,  i, 0, subtractMixedComb, subtractFlow);
1143     compareBackground(fileName, pt1Min, pt1Max, pt2Min, pt_assoc_bins[i], pt_assoc_bins[i+1], 9, 10,  i, 1, subtractMixedComb, subtractFlow);
1144   }
1145
1146 }
1147
1148
1149 //compares the background of the mixed comb analysis with the 1+1 background
1150 //statistics for background same is the worst because in each event at 2 places is searched for T2
1151 //for mixed comb a lot of events are searched for the second trigger particle
1152 //for 1+1 no second trigger particle needs to be found at all so the statistics is the highest
1153 void compareBackground(const char* fileName, double pt1Min = 4.0, double pt1Max = 14.0, Double_t pt2Min = 2.0, Double_t ptAssocMin = 0.5, Double_t ptAssocMax = 8.0, Int_t multBinBegin = 1, Int_t multBinEnd = 5, Int_t posX = 1, Int_t posY = 1, Int_t subtractMixedComb = 0, Int_t subtractFlow = 0){
1154
1155   Int_t trigger_mixed_comb=0;
1156   Int_t trigger_1plus1=0;
1157   Int_t trigger_background_same=0;
1158
1159   TH1D* mixedComb = (TH1*)getAnalysis(fileName, pt1Min, pt1Max, pt2Min, ptAssocMin, ptAssocMax, 6.9, multBinBegin, multBinEnd, 4, 1, 1, 0, subtractMixedComb, subtractFlow, &trigger_mixed_comb)->Clone();
1160
1161   TH1D* backgroundSame = (TH1*)getAnalysis(fileName, pt1Min, pt1Max, pt2Min, ptAssocMin, ptAssocMax, 6.9, multBinBegin, multBinEnd, 7, 1, 1, 0, subtractMixedComb, subtractFlow, &trigger_background_same)->Clone();
1162
1163   //near side
1164   TH1D* onePlusOne = (TH1*)getAnalysis(fileName, pt1Min, pt1Max, pt2Min, ptAssocMin, ptAssocMax, 6.9, multBinBegin, multBinEnd, 6, 1, 1, 0, subtractMixedComb, subtractFlow, &trigger_1plus1)->Clone();
1165   //away side
1166   //TH1D* onePlusOne = (TH1*)getAnalysis(fileName, pt2Min, pt1Min, pt2Min, ptAssocMin, ptAssocMax, 6.9, multBinBegin, multBinEnd, 6, 1, 1, 0, subtractMixedComb, subtractFlow, &trigger_1plus1)->Clone();
1167
1168   onePlusOne->SetLineColor(kRed);
1169   backgroundSame->SetLineColor(kGreen);
1170
1171   Printf("found trigger: mixed comb %i, 1plus1 %i, background_same %i", trigger_mixed_comb, trigger_1plus1, trigger_background_same);
1172   //do not need to scale these distributions because both are already divided by the number of triggers
1173
1174   TCanvas* can = new TCanvas(Form("compare background, %i, %i ", posX, posY), Form("compare background, %i, %i ", posX, posY), posX*gBasisSize+100, posY*gBasisSize+50, gBasisSize, gBasisSize);
1175
1176   ((TH1*)(backgroundSame->Clone()))->DrawCopy();
1177   ((TH1*)(mixedComb->Clone()))->DrawCopy("same");
1178   ((TH1*)(onePlusOne->Clone()))->DrawCopy("same");
1179
1180   TLegend *leg  = getLegend();
1181   leg->AddEntry(mixedComb, "mixed combinatorics","l");
1182   leg->AddEntry(onePlusOne, "1plus1 background","l");
1183   leg->AddEntry(backgroundSame, "background same","l");
1184   leg->Draw("same");
1185 }
1186
1187 void compareAllMixedComb(const char* fileName, double pt1Min = 4.0, double pt1Max = 14.0, Double_t pt2Min = 2.0, Int_t subtractMixedComb = 0, Int_t subtractFlow = 0){
1188
1189   //static const int pt_assoc_bins_number = 8;
1190   //Double_t pt_assoc_bins[pt_assoc_bins_number] = {0.5, 1.0, 2.0, 3.0, 4.0, 6.0, 8.0, 10.0};
1191
1192   for(int i=0; i<pt_assoc_bins_number-1; i++){
1193     compareMixedComb_sides(fileName, pt1Min, pt1Max, pt2Min, pt_assoc_bins[i], pt_assoc_bins[i+1], 1, 5,  i, 0, subtractMixedComb, subtractFlow);
1194     compareMixedComb_sides(fileName, pt1Min, pt1Max, pt2Min, pt_assoc_bins[i], pt_assoc_bins[i+1], 9, 10,  i, 1, subtractMixedComb, subtractFlow);
1195   }
1196
1197 }
1198
1199
1200 void compareMixedComb_sides(const char* fileName, double pt1Min = 4.0, double pt1Max = 14.0, Double_t pt2Min = 2.0, Double_t ptAssocMin = 0.5, Double_t ptAssocMax = 8.0, Int_t multBinBegin = 1, Int_t multBinEnd = 5, Int_t posX = 1, Int_t posY = 1, Int_t subtractMixedComb = 0, Int_t subtractFlow = 0){
1201
1202   Int_t trigger_mixed_comb=0;
1203
1204   TH1D* mixedComb_near = (TH1*)getAnalysis(fileName, pt1Min, pt1Max, pt2Min, ptAssocMin, ptAssocMax, 6.9, multBinBegin, multBinEnd, 4, 1, 1, 0, subtractMixedComb, subtractFlow, &trigger_mixed_comb)->Clone();
1205
1206   TH1D* mixedComb_away = (TH1*)getAnalysis(fileName, pt1Min, pt1Max, pt2Min, ptAssocMin, ptAssocMax, 6.9, multBinBegin, multBinEnd, 5, 1, 1, 0, subtractMixedComb, subtractFlow, &trigger_mixed_comb)->Clone();
1207
1208  TCanvas* can = new TCanvas(Form("compare mixedComb, %i, %i ", posX, posY), Form("compare mixedComb, %i, %i ", posX, posY), posX*gBasisSize+100, posY*gBasisSize+50, gBasisSize, gBasisSize);
1209
1210  mixedComb_away->SetLineColor(kRed);
1211
1212   ((TH1*)(mixedComb_near->Clone()))->DrawCopy();
1213   ((TH1*)(mixedComb_away->Clone()))->DrawCopy("same");
1214
1215   TLegend *leg  = getLegend();
1216   leg->AddEntry(mixedComb_near, "near side","l");
1217   leg->AddEntry(mixedComb_away, "away side","l");
1218   //leg->Draw("same");
1219 }
1220
1221
1222
1223
1224 //calculates the mixed comb by scaling it up to the amount of trigger in same background
1225 //this method can probably not be used because the statistics is too smal
1226 //within one vertex and multiplicity bin there are 12 to 30 trigger combinations -> the error on the correction factor is too high.
1227 TH2D* getMixedComb_scaled_backgroundSame(const char* fileName, double pt1Min = 4.0, double pt1Max = 14.0, double pt2Min = 4.0, double ptAssocMin = 2.0, double ptAssocMax = 4.0, Int_t multBinBegin = 1, Int_t multBinEnd = 5, Double_t setVertex = 7, Int_t step = 4, Int_t* trigger = NULL){
1228
1229  loadlibs();
1230
1231   printf("#############################");
1232   printf(Form("step %i", step));
1233   printf("#############################");
1234   AliTwoPlusOneContainer* h = (AliTwoPlusOneContainer*) GetTwoPlusOne(fileName);
1235   h->GetData()->SetPtRange(ptAssocMin, ptAssocMax);
1236   h->GetData()->SetPt2Min(pt2Min);
1237
1238   TH2D* return_mixed_comb = 0;
1239   
1240   if(step!=4 && step!=5){
1241     Printf("#############################");
1242     Printf("ERROR wrong step in getMixedComb_scaled_backgroundSame");
1243     Printf("#############################");
1244     return return_mixed_comb;
1245   }
1246
1247   THnBase* trackMixedCombAll = 0;
1248   TH2* eventMixedCombAll = 0;
1249   h->GetData()->GetHistsZVtxMult((AliUEHist::CFStep)step, AliUEHist::kToward, pt1Min, pt1Max, &trackMixedCombAll, &eventMixedCombAll);
1250   
1251   THnBase* trackBackgroundSameAll = 0;
1252   TH2* eventBackgroundSameAll = 0;
1253   h->GetData()->GetHistsZVtxMult((AliUEHist::CFStep)(step+3), AliUEHist::kToward, pt1Min, pt1Max, &trackBackgroundSameAll, &eventBackgroundSameAll);
1254   
1255   TAxis* vertexAxis = trackMixedCombAll->GetAxis(2);
1256   Int_t vertexBinBegin = vertexAxis->FindBin(-1*setVertex);
1257   Int_t vertexBinEnd = vertexAxis->FindBin(setVertex);
1258   
1259   Printf(Form("vertex bin begin %i, end %i ", vertexBinBegin, vertexBinEnd));
1260
1261   for(Int_t multBin=multBinBegin; multBin<=multBinEnd; multBin++){
1262     for(Int_t vertexBin=vertexBinBegin; vertexBin<=vertexBinEnd; vertexBin++){
1263       Printf(" multBin %i, vertexBin %i ", multBin, vertexBin);
1264
1265       trackMixedCombAll->GetAxis(3)->SetRange(multBin, multBin);
1266       trackMixedCombAll->GetAxis(2)->SetRange(vertexBin, vertexBin);
1267
1268       trackBackgroundSameAll->GetAxis(3)->SetRange(multBin, multBin);
1269       trackBackgroundSameAll->GetAxis(2)->SetRange(vertexBin, vertexBin);
1270
1271       TH2D* tracks_mixedComb = trackMixedCombAll->Projection(1, 0, "E");
1272       Int_t trigger_mixed_comb = eventMixedCombAll->Integral(vertexBin, vertexBin, multBin, multBin);
1273
1274       TH2D* tracks_background_same = trackBackgroundSameAll->Projection(1, 0, "E");
1275       Int_t trigger_background_same = eventBackgroundSameAll->Integral(vertexBin, vertexBin, multBin, multBin);
1276  
1277       //this has to be done because of a bug in the AliRoot code
1278       //because of an absolute cast in the dphi computation only half of this background is considered
1279       //wrong runs are 968 and 973
1280       //trigger_background_same *= 2;
1281
1282       Double_t trigger_ratio = 0;
1283       if(trigger_background_same>0)
1284         trigger_ratio = (Double_t)trigger_background_same/trigger_mixed_comb;
1285       Printf("(getMixedComb_scaled_backgroundSame) Triggers: mixed comb %i, background same %i, trigger ratio %f ", trigger_mixed_comb, trigger_background_same, trigger_ratio);
1286       
1287       double b1 = tracks_mixedComb->GetBinContent(tracks_mixedComb->FindBin(0.001,0.001));
1288       double b2 = tracks_mixedComb->GetBinContent(tracks_mixedComb->FindBin(0.001,-0.001));
1289       double b3 = tracks_mixedComb->GetBinContent(tracks_mixedComb->FindBin(-0.001,0.001));
1290       double b4 = tracks_mixedComb->GetBinContent(tracks_mixedComb->FindBin(-0.001,-0.001));
1291
1292       double b1_bsame = tracks_background_same->GetBinContent(tracks_background_same->FindBin(0.001,0.001));
1293       double b2_bsame = tracks_background_same->GetBinContent(tracks_background_same->FindBin(0.001,-0.001));
1294       double b3_bsame = tracks_background_same->GetBinContent(tracks_background_same->FindBin(-0.001,0.001));
1295       double b4_bsame = tracks_background_same->GetBinContent(tracks_background_same->FindBin(-0.001,-0.001));
1296
1297       Double_t content_ratio = 0;
1298       if(b1 + b2 + b3 + b4 > 0)
1299         content_ratio = (b1_bsame + b2_bsame + b3_bsame + b4_bsame)/(b1 + b2 + b3 + b4);
1300       Printf(" trigger_ratio %f, content_ratio %f", trigger_ratio, content_ratio);
1301       
1302       //Printf("Maximum: mixed comb %f, background same %f, normalization ratio %f ", content_mixed_comb, content_background_same, content_ratio);
1303       
1304       tracks_mixedComb->Scale(trigger_ratio);
1305       //tracks_mixedComb->Scale(content_ratio);
1306
1307       //correct event with mixed event
1308       TH2D* mixedEvent =  getMixedEvent(fileName, pt1Min, pt1Max, pt2Min, ptAssocMin, ptAssocMax, multBin, multBin, vertexBin, vertexBin, (AliUEHist::CFStep)(step-2), 0);
1309       //TH2D* mixedEvent =  getMixedEvent(fileName, pt1Min, pt1Max, pt2Min, ptAssocMin, ptAssocMax, multBin, multBin, vertexBinBegin, vertexBinEnd, (AliUEHist::CFStep)(step-2), 1);
1310       tracks_mixedComb->Divide(mixedEvent);
1311
1312       //TCanvas* can_1 = new TCanvas("mixed comb", "mixed comb", 100, 50, gBasisSize, gBasisSize);
1313       //tracks_mixedComb->DrawCopy("surf1");
1314       //TCanvas* can_2 = new TCanvas("mixed", "mixed", gBasisSize+100, 50, gBasisSize, gBasisSize);
1315       //mixedEvent->DrawCopy("surf1");
1316
1317       if(!return_mixed_comb)
1318         return_mixed_comb = (TH2D*) tracks_mixedComb->Clone("total tracks");
1319       else
1320         return_mixed_comb->Add(tracks_mixedComb);
1321
1322       if(trigger!=NULL)
1323         *trigger += trigger_background_same ;
1324     }
1325   }
1326
1327   // normalizate to dphi widht
1328   Float_t normalization = return_mixed_comb->GetXaxis()->GetBinWidth(1);
1329   return_mixed_comb->Scale(1.0 / normalization);
1330
1331   return return_mixed_comb;
1332 }
1333
1334
1335 //shows alpha dependent significance of the signal, signal/background for different centralities
1336 void get1plus1(const char* fileName, Double_t pt1Min, Double_t pt1Max, Double_t ptAssocMin, Double_t ptAssocMax){
1337   loadlibs();
1338   TFile::Open(fileName);
1339
1340   //to guarantee to pick only the bins from the choosen pt on
1341   pt1Min += 0.01;
1342   pt1Max -= 0.01;
1343   ptAssocMin += 0.01;
1344   ptAssocMax -= 0.01;
1345
1346   Int_t alpha_bins = 5;//number of alpha bins maximal used around the two bins close to pi, maximum usable would be 5 because than already the full away side is searched for a trigger 2
1347   Int_t showAlpha = 1;
1348   Double_t alpha_bin_width = 0.174532;
1349   Int_t draw = 1;
1350
1351   Int_t multBinBegin = 9;
1352   Int_t multBinEnd = 10;
1353
1354   AliTwoPlusOneContainer* h = (AliTwoPlusOneContainer*) GetTwoPlusOne(fileName);
1355
1356   AliUEHist::CFStep step_1plus1 = (AliUEHist::CFStep) AliTwoPlusOneContainer::k1plus1;
1357   AliUEHist::CFStep step_mixed = (AliUEHist::CFStep) AliTwoPlusOneContainer::kMixedNS;
1358   
1359   TH1D* alpha_plot_significance = new TH1D("alpha_plot", "", alpha_bins, 0, alpha_bins*alpha_bin_width);
1360   alpha_plot_significance->SetXTitle("\\alpha");
1361   alpha_plot_significance->SetYTitle("significance");
1362
1363   TH1D* alpha_plot_sigBack = new TH1D("alpha_plot", "", alpha_bins, 0, alpha_bins*alpha_bin_width);
1364   alpha_plot_sigBack->SetXTitle("\\alpha");
1365   alpha_plot_sigBack->SetYTitle("signal/background");
1366
1367   for(Int_t cent = 0; cent<4; cent++){
1368     char* cent_string = "";
1369     if(cent==0){
1370       multBinBegin = 1;
1371       multBinEnd = 5;
1372       cent_string = "0-5%";
1373     }else if(cent==1){
1374       multBinBegin = 6;
1375       multBinEnd = 6;
1376       cent_string = "5-10%";
1377     }else if(cent==2){
1378       multBinBegin = 7;
1379       multBinEnd = 8;
1380       cent_string = "10-30%";
1381     }else if(cent==3){
1382       multBinBegin = 9;
1383       multBinEnd = 10;
1384       cent_string = "30-50%";
1385     }
1386
1387     for(Int_t alpha = 0; alpha <alpha_bins; alpha++){
1388       if(alpha==showAlpha) draw = 1; else draw = 0;
1389       
1390       h->GetData()->SetPtRange(ptAssocMin, ptAssocMax);
1391       TH2* h2_etaPhi = h->GetData()->GetSumOfRatios2(h->GetData(), step_1plus1, 0, pt1Min, pt1Max, multBinBegin, multBinEnd, kFALSE, step_mixed);
1392       Double_t arr1[4];
1393       showResult(h2_etaPhi, cent, 0, alpha, arr1, draw);
1394       alpha_plot_significance->SetBinContent(alpha+1, arr1[0]);
1395       alpha_plot_significance->SetBinError(alpha+1, arr1[2]);
1396       alpha_plot_sigBack->SetBinContent(alpha+1, arr1[1]);
1397       alpha_plot_sigBack->SetBinError(alpha+1, arr1[3]);
1398     }
1399
1400     TCanvas* c1 = new TCanvas(Form("alpha_plot_significance %s ", cent_string), Form("alpha_plot_significance %s ", cent_string), cent*gBasisSize+50, 1*gBasisSize+50, gBasisSize, gBasisSize);
1401     alpha_plot_significance->DrawCopy("E");
1402
1403     TCanvas* c2 = new TCanvas(Form("alpha_plot_signalBackground %s ", cent_string), Form("alpha_plot_signalBackground %s ", cent_string), cent*gBasisSize+50, 2*gBasisSize+50, gBasisSize, gBasisSize);
1404     alpha_plot_sigBack->DrawCopy("E");
1405   }
1406
1407 }
1408
1409
1410
1411 //method used just in get1plus1 to calculate the significance and the signal/background
1412 void showResult(TH2* h2_etaPhi, Int_t posX, Int_t posY, Int_t alpha_bins, Double_t* arr, Int_t draw){
1413
1414   int firstbin = h2_etaPhi->GetYaxis()->FindBin(-1*g_eta_bin);
1415   int lastbin = h2_etaPhi->GetYaxis()->FindBin(g_eta_bin);
1416
1417   Printf("firstbin %i, lastbin %i, \n", firstbin, lastbin);
1418
1419   TH1D* h1_phi = h2_etaPhi->ProjectionX(Form("px_%i_%i", posX, posY), firstbin, lastbin);
1420   
1421   double alpha = 0.15;// use 0.15 to get only the next two bins which are a bit smaller than 0.2//0.2;
1422   //Pi is exactely the bin edge
1423   int bin_1 = 27 - alpha_bins;//h1_phi->FindBin(TMath::Pi()-alpha+0.01);
1424   int bin_2 = 28 + alpha_bins;//h1_phi->FindBin(TMath::Pi()+alpha-0.01);
1425
1426   Int_t bin_start = h1_phi->FindBin(TMath::Pi()/3+0.01);
1427   Int_t bin_end = h1_phi->FindBin(2*TMath::Pi()/3-0.01);
1428   Double_t par0 = 0;
1429   Double_t err0 = 0;
1430
1431   for(int i=bin_start; i<=bin_end; i++){
1432     par0 += h1_phi->GetBinContent(i);
1433     err0 += h1_phi->GetBinError(i);
1434   }
1435   par0 /= bin_end - bin_start + 1;  
1436   err0 /= bin_end - bin_start + 1;
1437
1438
1439   double sum = 0;
1440   double sum_err = 0;
1441   for(int bin = bin_1; bin<=bin_2; bin++){
1442     sum += h1_phi->GetBinContent(bin);
1443     sum_err += h1_phi->GetBinError(bin);
1444   }
1445   sum_err /= (bin_2-bin_1+1);
1446   double background = (bin_2 - bin_1 + 1)*par0;
1447   double background_err = (bin_2 - bin_1 + 1)*err0;
1448   double signal2 = sum - background;
1449   double signal2_err = TMath::Sqrt(sum_err*sum_err+background_err*background_err);
1450
1451   Double_t significance = signal2/h1_phi->GetBinError((bin_1+bin_2)/2);
1452   Double_t significance_err = signal2_err/(TMath::Sqrt(sum));
1453   //Double_t significance = signal2/(TMath::Sqrt(sum));
1454   //Double_t significance_err = TMath::Sqrt(TMath::Power(signal2_err/(TMath::Sqrt(sum)), 2) + TMath::Power(signal2/(TMath::Sqrt(sum*sum*sum)*sum_err), 2));
1455
1456   Double_t significance_rel = signal2/background;//signal over background
1457   Double_t significance_rel_err = TMath::Sqrt(TMath::Power(signal2_err/background,2)+TMath::Power(signal2/(background*background)*background_err,2));//signal over background
1458
1459   Printf("X %i, Y %i, significance: %f, signal over background %f ", posX, posY, significance, significance_rel);
1460
1461   h1_phi->SetYTitle("1/N_{trig} \\  dN_{assoc}/d \\varphi");
1462   h1_phi->SetTitle("");
1463   h1_phi->SetStats(kFALSE);
1464   //h1_phi->Scale(1/(lastbin - firstbin + 1));
1465   if(draw>0){
1466     TCanvas* c1 = new TCanvas(Form("can %i %i", posX, posY), Form("can %i %i", posX, posY), posX*gBasisSize+50, posY*gBasisSize+50, gBasisSize, gBasisSize);
1467     //h1_phi->DrawCopy();
1468     h2_etaPhi->DrawCopy("surf1");
1469   }
1470
1471   arr[0] = significance;
1472   arr[1] = significance_rel;
1473   arr[2] = significance_err;
1474   arr[3] = significance_rel_err;
1475 }
1476
1477
1478 //this method is not further maintained after the copy into this file
1479 //it was used to compare the different kind of background distributions
1480 //this method compares the expected amount of background trigger combinations for 3 methods:
1481 //1. get background from the arithmetical average between delta phi = pi/3 and 2pi/3
1482 //2. mixed combinatorics (they are lacking some combinations because the buffers have to be filled first)
1483 //3. background same, search at delta phi = pi/2 for trigger particles the same way as it is done in mixed comb
1484 void printBackground2plus1(const char* fileName, double pt1Min = 4.0, double pt1Max = 14.0, Double_t pt2Min = 2.0, Double_t ptAssocMin = 2.0, Double_t ptAssocMax = 4.0, Double_t setVertex = 7, Int_t multBinBegin = 1, Int_t multBinEnd = 5, Int_t step = 0){
1485
1486   loadlibs();
1487   TFile::Open(fileName);
1488
1489   //to guarantee to pick only the bins from the choosen pt on
1490   pt1Min += 0.01;
1491   pt1Max -= 0.01;
1492   pt2Min += 0.01;
1493   ptAssocMin += 0.01;
1494   ptAssocMax -= 0.01;
1495
1496   Double_t alpha_radius = 0.393;// =pi/8 //0.2;//use radius which was used by the mixed comb and background same method in the loaded file
1497
1498   AliTwoPlusOneContainer* h = (AliTwoPlusOneContainer*) GetTwoPlusOne(fileName);
1499   AliUEHist::CFStep step_1plus1 = (AliUEHist::CFStep) AliTwoPlusOneContainer::k1plus1;
1500   AliUEHist::CFStep step_mixed = (AliUEHist::CFStep) AliTwoPlusOneContainer::kMixedAS;
1501   AliUEHist::CFStep step_mixedComb = (AliUEHist::CFStep) AliTwoPlusOneContainer::kMixedCombAS;
1502   AliUEHist::CFStep step_backgroundSame = (AliUEHist::CFStep) AliTwoPlusOneContainer::kBackgroundSameAS;
1503
1504   //get error from the 1+1 correlation
1505   
1506   THnBase* trackSameAll = 0;
1507   TH2* eventSameAll = 0;
1508   //h->GetData()->SetPtRange(pt2Min, pt1Max);
1509   h->GetData()->SetPtRange(ptAssocMin, ptAssocMax);
1510   //h->GetData()->SetPtRange(6, 10);
1511   h->GetData()->SetPt2Min(pt2Min);
1512   h->GetData()->SetZVtxRange(-1*setVertex, setVertex);
1513   /*
1514   h->GetData()->GetHistsZVtxMult(step_1plus1, AliUEHist::kToward, pt1Min, pt1Max, &trackSameAll, &eventSameAll);
1515   trackSameAll->GetAxis(3)->SetRange(multBinBegin, multBinEnd);
1516
1517   TAxis* vertexAxis = trackSameAll->GetAxis(2);
1518   Int_t vertexBinBegin = vertexAxis->FindBin(-1*setVertex);
1519   Int_t vertexBinEnd = vertexAxis->FindBin(setVertex);
1520
1521   trackSameAll->GetAxis(2)->SetRange(vertexBinBegin, vertexBinEnd);
1522
1523   TH2* tracksSame = trackSameAll->Projection(1, 0, "E");
1524   TH1D* h1_phi = tracksSame->ProjectionX();
1525   h1_phi->Scale(1/h1_phi->GetXaxis()->GetBinWidth(1));
1526   
1527   */
1528   
1529   TH2* h2_etaPhi = h->GetData()->GetSumOfRatios2(h->GetData(), step_1plus1, 0, pt1Min, pt1Max, multBinBegin, multBinEnd, kFALSE, step_mixed);
1530
1531   int firstbin = -1;//h2_etaPhi->GetYaxis()->FindBin(-0.99);
1532   int lastbin = -1;//h2_etaPhi->GetYaxis()->FindBin(0.99);
1533   TH1D* h1_phi = h2_etaPhi->ProjectionX("px", firstbin, lastbin);
1534   
1535
1536   //undo phi normalization
1537   //h1_phi->Scale(h1_phi->GetXaxis()->GetBinWidth(1));
1538   /*
1539   TF1* fit = new TF1("fit", "[0]", 1.01, 1.99);
1540   h1_phi->Fit("fit", "N", "", 1.01, 1.99);
1541   Double_t par0 = fit->GetParameter(0);
1542   Double_t err0 = fit->GetParError(0);
1543   */
1544   Int_t bin_start = h1_phi->FindBin(TMath::Pi()/3+0.01);
1545   Int_t bin_end = h1_phi->FindBin(2*TMath::Pi()/3-0.01);
1546   //Int_t bin_start = h1_phi->FindBin(1.37);
1547   //Int_t bin_end = h1_phi->FindBin(1.57);
1548   Double_t sum = 0;
1549   Double_t err = 0;
1550
1551   for(int i=bin_start; i<=bin_end; i++){
1552     sum += h1_phi->GetBinContent(i);
1553     err += h1_phi->GetBinError(i);
1554   }
1555   Printf("bin start %i, bin end %i, sum %f ", bin_start, bin_end, sum);
1556   sum /= (bin_end - bin_start + 1);
1557   err /= (bin_end - bin_start + 1);
1558   Printf(" sum %f ", sum);  
1559
1560   Printf("sum %f, bin width %f ", sum, h1_phi->GetBinWidth(bin_start));
1561
1562   double background = 2*alpha_radius*sum;//the plot is already normalized for the bin_width by getting it from getSumOfRatios2
1563   double background_err = 2*alpha_radius*err;
1564
1565   //TCanvas* can = new TCanvas();
1566   //h1_phi->DrawCopy();
1567
1568   //get error from mixed combinatorics
1569   Int_t trigger_mixed_comb;
1570
1571
1572
1573
1574   //TH2* h2_etaPhi_mixedComb = (TH2D*) h->GetData()->GetSumOfRatios2(h->GetData(), step_mixedComb, 0, pt1Min, pt1Max, multBinBegin, multBinEnd, kFALSE, step_mixed, &trigger_mixed_comb);
1575   h2_etaPhi_mixedComb = getMixedComb_scaled_backgroundSame(fileName, pt1Min, pt1Max, pt2Min, ptAssocMin, ptAssocMax, multBinBegin, multBinEnd, setVertex, step_mixedComb, &trigger_mixed_comb);
1576
1577   int firstbin_eta = h2_etaPhi_mixedComb->GetYaxis()->FindBin(-0.39);
1578   int lastbin_eta = h2_etaPhi_mixedComb->GetYaxis()->FindBin(0.39);
1579   TH1* h1_phi_mixedComb = h2_etaPhi_mixedComb->ProjectionX("mixedComb_px", firstbin_eta, lastbin_eta);
1580
1581   //get error from mixed combinatorics
1582   Int_t trigger_backgroundSame;
1583   
1584   TH2* h2_etaPhi_backgroundSame = (TH2D*) h->GetData()->GetSumOfRatios2(h->GetData(), step_backgroundSame, 0, pt1Min, pt1Max, multBinBegin, multBinEnd, kFALSE, step_mixed, &trigger_backgroundSame);
1585   TH1* h1_phi_backgroundSame = h2_etaPhi_backgroundSame->ProjectionX("backgroundSame_px", firstbin_eta, lastbin_eta);
1586
1587   
1588   TCanvas* can = new TCanvas("can", "can",  gBasisSize+50, gBasisSize+50, 2*gBasisSize, 2*gBasisSize);
1589   h1_phi_mixedComb->SetLineWidth(3);
1590   h1_phi_mixedComb->SetStats(kFALSE);
1591   h1_phi_mixedComb->DrawCopy();
1592   h1_phi_backgroundSame->SetLineWidth(3);
1593   h1_phi_backgroundSame->SetLineColor(kRed);
1594   h1_phi_backgroundSame->DrawCopy("same");
1595
1596   TLegend *leg  = getLegend();
1597   leg->AddEntry(h1_phi_mixedComb, "mixed combinatorics","l");
1598   leg->AddEntry(h1_phi_backgroundSame, "background same","l");
1599   leg->Draw("same");
1600   
1601   Printf("expect from 1+1 %f +/- %f", background, background_err);
1602   Printf("expect from trigger_mixed_comb %i ", trigger_mixed_comb);
1603   Printf("expect from trigger_backgroundSame %i ", trigger_backgroundSame); 
1604 }
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616 void symmetrize(TH1D* tracks)
1617 {
1618   int bins = tracks->FindBin(TMath::Pi()/2-0.01);
1619   for(int i=0; i<=bins/2; i++){
1620     double tmp =  (tracks->GetBinContent(i)+tracks->GetBinContent(bins-i+1))/2;
1621     tracks->SetBinContent(i, tmp);
1622     tracks->SetBinContent(bins-i+1, tmp);
1623   }
1624 }
1625
1626
1627
1628
1629
1630
1631
1632
1633 TH2D* getMixedEvent(const char* fileName, double pt1Min = 4.0, double pt1Max = 14.0, double pt2Min = 2.0, Double_t ptAssocMin = 0.5, Double_t ptAssocMax = 8.0, Int_t multBinBegin = 1, Int_t multBinEnd = 5, Int_t vertexBinBegin = 1, Int_t vertexBinEnd = 5, Int_t step = 1, Int_t symmetrize = 0)
1634 {
1635
1636   TH2D* tracksMixed = getCorrelationStep(fileName, pt1Min, pt1Max, pt2Min, ptAssocMin, ptAssocMax, multBinBegin, multBinEnd, vertexBinBegin, vertexBinEnd, step);
1637
1638   double b1 = tracksMixed->GetBinContent(tracksMixed->FindBin(0.001,0.001));
1639   double b2 = tracksMixed->GetBinContent(tracksMixed->FindBin(0.001,-0.001));
1640   double b3 = tracksMixed->GetBinContent(tracksMixed->FindBin(-0.001,0.001));
1641   double b4 = tracksMixed->GetBinContent(tracksMixed->FindBin(-0.001,-0.001));
1642   double divide = (b1 + b2 + b3 + b4)/4;//=value at zero
1643   double error = TMath::Power(b1/divide-1, 2)+TMath::Power(b2/divide-1, 2)+TMath::Power(b3/divide-1, 2)+TMath::Power(b4/divide-1, 2);//not further used
1644   Printf(Form(" filename: %s, four bins: %f, %f, %f, %f, divide: %f", fileName, b1/divide, b2/divide, b3/divide, b4/divide, divide));
1645   
1646   //symmetrize
1647   if(symmetrize>0)
1648     for(i=0; i<=tracksMixed->GetNbinsX(); i++){
1649       int y_bins = tracksMixed->GetNbinsY();
1650       for(j=0; j<=y_bins/2; j++){
1651         double tmp =  (tracksMixed->GetBinContent(i, j)+tracksMixed->GetBinContent(i, y_bins-j+1))/2;
1652         tracksMixed->SetBinContent(i, j, tmp);
1653         tracksMixed->SetBinContent(i, y_bins-j+1, tmp);
1654       }
1655     }
1656   
1657   //finite bin correction
1658   //ftrackEtaCut = 0.9; 
1659   Double_t finiteBinCorrection = -1.0 / (2*0.9) * tracksMixed->GetYaxis()->GetBinWidth(1) / 2 + 1;
1660   Printf("Finite bin correction: %f", finiteBinCorrection);
1661   divide /= finiteBinCorrection;
1662   error /= finiteBinCorrection;//not further used
1663
1664   tracksMixed->Scale(1.0/divide);
1665
1666   TH1D* proj = tracksMixed->ProjectionY("_norm");
1667   Int_t bins_X = tracksMixed->GetNbinsX();
1668
1669   double norm1 = proj->GetBinContent(proj->FindBin(-0.001));
1670   double norm2 = proj->GetBinContent(proj->FindBin(0.001));
1671   double norm = (norm1+norm2)/2.0;
1672
1673   //tracksMixed->Scale(1.0/(bins_X*norm));
1674   Printf("norm1 %f, norm2 %f, norm %f", norm1/norm, norm2/norm, norm);
1675
1676   TCanvas* c2 = new TCanvas("mixedEvent", "mixedEvent", gBasisSize+50, 2*gBasisSize+50, gBasisSize, gBasisSize);
1677   tracksMixed->DrawCopy("surf1");
1678
1679   return tracksMixed;
1680 }
1681
1682
1683
1684
1685 //old method with an double cache
1686 //used to compare results but very difficult to read
1687 const char* lastFileName_corStep = 0;
1688 double lastPt1Min = 0;
1689 double lastPt1Max = 0;
1690 double lastPt2Min = 0;
1691 double lastPtAssocMin = 0;
1692 double lastPtAssocMax = 0;
1693 int laststep = 0;
1694 void* cacheHistsZVTxMult = 0;
1695 void* cacheEvtZVTxMult = 0;
1696
1697 const char* lastFileName2_corStep = 0;
1698 double lastPt1Min2 = 0;
1699 double lastPt1Max2 = 0;
1700 double lastPt2Min2 = 0;
1701 double lastPtAssocMin2 = 0;
1702 double lastPtAssocMax2 = 0;
1703 int laststep2 = 0;
1704 void* cacheHistsZVTxMult2 = 0;
1705 void* cacheEvtZVTxMult2 = 0;
1706
1707 int next = 1;
1708
1709 TH2D* getCorrelationStep(const char* fileName, double pt1Min = 4.0, double pt1Max = 14.0, double pt2Min = 2.0, Double_t ptAssocMin = 0.5, Double_t ptAssocMax = 8.0, Int_t multBinBegin = 1, Int_t multBinEnd = 5, Int_t vertexBinBegin = 1, Int_t vertexBinEnd = 5, Int_t step = 1, Int_t* trigger = NULL){
1710
1711     //to guarantee to pick only the bins from the choosen pt on
1712     pt1Min += 0.01;
1713     pt1Max -= 0.01;
1714     pt2Min += 0.01;
1715     ptAssocMin += 0.01;
1716     ptAssocMax -= 0.01;
1717   
1718
1719   THnBase* trackMixedAll = 0;
1720   TH2* eventMixedAll = 0;
1721
1722   //look if the THnBase is already in the cache
1723   if(lastFileName_corStep && strcmp(lastFileName_corStep, fileName) == 0 && lastPt1Min==pt1Min && lastPt1Max==pt1Max && lastPt2Min==pt2Min && lastPtAssocMin==ptAssocMin && lastPtAssocMax==ptAssocMax && laststep==step){
1724     Printf("use cache 1");
1725
1726       trackMixedAll = cacheHistsZVTxMult;
1727       eventMixedAll = cacheEvtZVTxMult;
1728
1729   }else if(lastFileName2_corStep && strcmp(lastFileName2_corStep, fileName) == 0 && lastPt1Min2==pt1Min && lastPt1Max2==pt1Max && lastPt2Min2==pt2Min && lastPtAssocMin2==ptAssocMin && lastPtAssocMax2==ptAssocMax && laststep2==step){
1730     Printf("use cache 2");
1731
1732       trackMixedAll = cacheHistsZVTxMult2;
1733       eventMixedAll = cacheEvtZVTxMult2;
1734
1735       //if it is in no cache continue getting it (by always recomputing it a memory leak is introduced)
1736   }else{
1737     loadlibs();
1738
1739     AliTwoPlusOneContainer* twoPlusOne = (AliTwoPlusOneContainer*) GetTwoPlusOne(fileName);
1740
1741     twoPlusOne->GetData()->SetPtRange(ptAssocMin, ptAssocMax);
1742     twoPlusOne->GetData()->SetPt2Min(pt2Min);
1743     
1744     twoPlusOne->GetData()->GetHistsZVtxMult((AliUEHist::CFStep)step, AliUEHist::kToward, pt1Min, pt1Max, &trackMixedAll, &eventMixedAll);
1745
1746     if(next == 1){
1747       cacheHistsZVTxMult = trackMixedAll;
1748       cacheEvtZVTxMult = eventMixedAll;
1749
1750       lastFileName_corStep = fileName;
1751       lastPt1Min = pt1Min;
1752       lastPt1Max = pt1Max;
1753       lastPt2Min = pt2Min;
1754       lastPtAssocMin = ptAssocMin;
1755       lastPtAssocMax = ptAssocMax;
1756       laststep = step;
1757
1758       next = 2;
1759
1760     }else if(next ==2){
1761       cacheHistsZVTxMult2 = trackMixedAll;
1762       cacheEvtZVTxMult2 = eventMixedAll;
1763
1764       lastFileName2_corStep = fileName;
1765       lastPt1Min2 = pt1Min;
1766       lastPt1Max2 = pt1Max;
1767       lastPt2Min2 = pt2Min;
1768       lastPtAssocMin2 = ptAssocMin;
1769       lastPtAssocMax2 = ptAssocMax;
1770       laststep2 = step;
1771      
1772       next = 1;
1773     }
1774   }
1775
1776   trackMixedAll->GetAxis(3)->SetRange(multBinBegin, multBinEnd);
1777   trackMixedAll->GetAxis(2)->SetRange(vertexBinBegin, vertexBinEnd);
1778
1779   TH2D* tracksMixed = trackMixedAll->Projection(1, 0, "E");
1780
1781   if(trigger!=NULL)
1782     *trigger = eventMixedAll->Integral(vertexBinBegin, vertexBinEnd, multBinBegin, multBinEnd);
1783
1784   return tracksMixed;
1785 }
1786
1787
1788 void showMixedDist(const char* fileName){
1789   loadlibs();
1790
1791   TH1F* mixedDist = getMixedDist(fileName);
1792   TCanvas* can = new TCanvas();
1793   mixedDist->DrawCopy("colz");
1794 }
1795
1796 TH1F* getMixedDist(const char* fileName){
1797   loadlibs();
1798
1799   //list = (TList*) getList(fileName, "PWGCF_TwoPlusOne/histosTwoPlusOne");
1800   //list = (TList*) getList(fileName, "PWGCF_TwoPlusOne/addedEvents_");
1801   list = (TList*) getList(fileName, path);
1802
1803   TH1F* mixedDist = (TH1F*) list->FindObject("mixedDist");
1804   return mixedDist;
1805 }
1806
1807
1808
1809 void compareScaledMixedComb(const char* fileName, double pt1Min = 4.0, double pt1Max = 14.0, Double_t pt2Min = 2.0, Double_t ptAssocMin = 0.5, Double_t ptAssocMax = 8.0, Double_t setVertex = 7, Int_t multBinBegin = 1, Int_t multBinEnd = 5, Int_t step = 0){
1810
1811   loadlibs();
1812
1813   //to guarantee to pick only the bins from the choosen pt on
1814   pt1Min += 0.01;
1815   pt1Max -= 0.01;
1816   pt2Min += 0.01;
1817   ptAssocMin += 0.01;
1818   ptAssocMax -= 0.01;
1819   
1820   AliTwoPlusOneContainer* h = (AliTwoPlusOneContainer*) GetTwoPlusOne(fileName);
1821
1822   AliUEHist::CFStep step_same = step;//(AliUEHist::CFStep) AliTwoPlusOneContainer::kSameNS;
1823   AliUEHist::CFStep step_mixed = step+2;//(AliUEHist::CFStep) AliTwoPlusOneContainer::kMixedNS;
1824   AliUEHist::CFStep step_mixedComb = step+4;//(AliUEHist::CStep) AliTwoPlusOneContainer::kMixedCombNS;
1825   AliUEHist::CFStep step_backgroundSame = step+7;//(AliUEHist::CStep) AliTwoPlusOneContainer::kBackgroundSameNS;
1826
1827   h->GetData()->SetPtRange(ptAssocMin, ptAssocMax);
1828   h->GetData()->SetPt2Min(pt2Min);
1829   h->GetData()->SetZVtxRange(-1*setVertex, setVertex);
1830  
1831   //GetSumOfRatios2(mixed, step, region, ptLeadMin, ptLeadMax, multBinBegin, multBinEnd, normalizePerTrigger, stepForMixed)
1832   TH2D* h2_etaPhi;
1833   TH2D* h2_etaPhi_mixedComb;
1834   TH2D* h2_etaPhi_backgroundSame;
1835
1836
1837     Int_t trigger_same;
1838     Int_t trigger_mixed_comb;
1839     Int_t trigger_mixed_comb_method;
1840     Int_t trigger_background_same;
1841
1842
1843     h2_etaPhi_mixedComb_sumOfRatios = (TH2D*) h->GetData()->GetSumOfRatios2(h->GetData(), step_mixedComb, 0, pt1Min, pt1Max, multBinBegin, multBinEnd, kFALSE, step_mixed, &trigger_mixed_comb);
1844     h2_etaPhi_backgroundSame_sumOfRatios = (TH2D*) h->GetData()->GetSumOfRatios2(h->GetData(), step_backgroundSame, 0, pt1Min, pt1Max, multBinBegin, multBinEnd, kFALSE, step_mixed, &trigger_background_same);
1845     //trigger_background_same *= 2;//error in the plots for run 968 and 973
1846     double trigger_ratio = (double)trigger_background_same/trigger_mixed_comb;
1847     Printf("trigger mixed comb: %i, trigger background same %i, ratio %f", trigger_mixed_comb, trigger_background_same, trigger_ratio);
1848     h2_etaPhi_mixedComb_sumOfRatios->Scale(trigger_ratio);
1849     trigger_mixed_comb = trigger_background_same;
1850       
1851     h2_etaPhi_mixedComb_method = getMixedComb_scaled_backgroundSame(fileName, pt1Min, pt1Max, pt2Min, ptAssocMin, ptAssocMax, multBinBegin, multBinEnd, setVertex, step_mixedComb, &trigger_mixed_comb_method);
1852
1853     
1854     TCanvas* can = new TCanvas("can", "can",  gBasisSize+50, gBasisSize+50, gBasisSize, gBasisSize);
1855     h2_etaPhi_mixedComb_sumOfRatios->DrawCopy("surf1");
1856
1857     TCanvas* can2 = new TCanvas("can2", "can2",  gBasisSize+50, 2*(gBasisSize+50), gBasisSize, gBasisSize);
1858     h2_etaPhi_mixedComb_method->DrawCopy("surf1");
1859
1860    TCanvas* can3 = new TCanvas("can3", "can3",  gBasisSize+50, 3*(gBasisSize+50), gBasisSize, gBasisSize);
1861    h2_etaPhi_mixedComb_sumOfRatios->Add(h2_etaPhi_mixedComb_method, -1);
1862    h2_etaPhi_mixedComb_sumOfRatios->Divide(h2_etaPhi_mixedComb_method);
1863    h2_etaPhi_mixedComb_sumOfRatios->GetYaxis()->SetRangeUser(-1.5, 1.5);
1864    h2_etaPhi_mixedComb_sumOfRatios->DrawCopy("surf1");
1865
1866     Printf("mixed comb sumofratios %i, method %i", trigger_mixed_comb, h2_etaPhi_mixedComb_sumOfRatios);
1867
1868
1869 }
1870
1871
1872 void Plot_oneAxis(const char* fileName, int project)
1873 {
1874   loadlibs();
1875
1876   TFile::Open(fileName);
1877
1878   AliTwoPlusOneContainer* h = (AliTwoPlusOneContainer*) GetTwoPlusOne(fileName);
1879
1880   TCanvas* c1 = new TCanvas("can1", "can1", 1200, 800);
1881   c1->Divide(2, 1);
1882
1883   AliCFGridSparse* near_plot = h->GetData()->GetTrackHist(0)->GetGrid((AliUEHist::CFStep) AliTwoPlusOneContainer::k1plus1);
1884   //near_plot->SetRangeUser(2, gpTMin_T1, gpTMax_T1);
1885   //near_plot->SetRangeUser(6, gpTMin_T2, gpTMax_T2);
1886   //near_plot->SetRangeUser(1, gpTMin_assoc, gpTMax_assoc);
1887   TH1D* tracks_near = near_plot->Project(project);
1888
1889   c1->cd(1);
1890   tracks_near->DrawCopy();
1891
1892   AliCFGridSparse* away_plot = h->GetData()->GetTrackHist(0)->GetGrid((AliUEHist::CFStep) AliTwoPlusOneContainer::kSameNS);
1893   TH1D* tracks_away = away_plot->Project(project);
1894
1895   c1->cd(2);
1896   tracks_away->DrawCopy();
1897 }  
1898
1899 void test(const char* fileName, double pt1Min, double pt1Max, double pt2Min, double ptAssocMin, double ptAssocMax)
1900 {
1901   loadlibs();
1902   Int_t multBinBegin = 1;
1903   Int_t multBinEnd = 5;
1904   Int_t trigger_mixed_comb;
1905
1906   TFile::Open(fileName);
1907
1908   AliTwoPlusOneContainer* h = (AliTwoPlusOneContainer*) GetTwoPlusOne(fileName);
1909
1910   h->GetData()->SetPtRange(ptAssocMin, ptAssocMax);
1911   h->GetData()->SetPt2Min(pt2Min);
1912   h->GetData()->SetZVtxRange(-1*6.9, 6.9);
1913
1914   AliUEHist::CFStep step_same = (AliUEHist::CFStep) AliTwoPlusOneContainer::kSameNS;
1915   AliUEHist::CFStep step_mixed = (AliUEHist::CFStep) AliTwoPlusOneContainer::kMixedNS;
1916
1917   AliUEHist::CFStep step_1plus1 = (AliUEHist::CFStep) AliTwoPlusOneContainer::k1plus1;
1918
1919   //GetSumOfRatios2(mixed, step, region, ptLeadMin, ptLeadMax, multBinBegin, multBinEnd, normalizePerTrigger, stepForMixed)
1920   TH2D* h2_etaPhi;
1921   TH2D* h2_etaPhi_mixedComb;
1922
1923     h2_etaPhi_mixedComb = (TH2D*) h->GetData()->GetSumOfRatios2(h->GetData(), step_1plus1, 0, pt1Min, pt1Max, multBinBegin, multBinEnd, kFALSE, step_mixed, &trigger_mixed_comb);
1924
1925  TCanvas* c1 = new TCanvas("can1", "can1", 1200, 800);
1926  h2_etaPhi_mixedComb->DrawCopy("surf1");
1927 }
1928
1929 void showAsymmetry(const char* fileName, Int_t mixed){
1930   loadlibs();
1931
1932   TFile::Open(fileName);
1933   AliTwoPlusOneContainer* h = (AliTwoPlusOneContainer*) GetTwoPlusOne(fileName);
1934
1935   TH1F* asymm_same = h->GetAsymmetry();
1936   TH1F* asymm_mixed = h->GetAsymmetryMixed();
1937
1938   TCanvas* c1 = new TCanvas("can1", "can1", 1200, 800);
1939   if(mixed==0)
1940     asymm_same->DrawCopy();
1941   else if(mixed==1)
1942     asymm_mixed->DrawCopy();
1943   else if(mixed==2){
1944     asymm_same->DrawCopy();
1945     asymm_mixed->SetLineColor(kRed);
1946     asymm_mixed->Scale(1.0/80);
1947     asymm_mixed->DrawCopy("same");
1948   }
1949 }
1950
1951 void showTriggerPt(const char* fileName){
1952   loadlibs();
1953
1954   TFile::Open(fileName);
1955   AliTwoPlusOneContainer* h = (AliTwoPlusOneContainer*) GetTwoPlusOne(fileName);
1956
1957   TCanvas* c1 = new TCanvas("can1", "can1", 1200, 800);
1958   h->GetTriggerPt()->DrawCopy("colz");
1959 }
1960