]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGCF/EBYE/BalanceFunctions/AliBalancePsi.cxx
Adding safety check for missing matrix in GetTrackByTrackCorrection; Adding possibili...
[u/mrichter/AliRoot.git] / PWGCF / EBYE / BalanceFunctions / AliBalancePsi.cxx
1 /**************************************************************************
2  * Author: Panos Christakoglou.                                           *
3  * Contributors are mentioned in the code where appropriate.              *
4  *                                                                        *
5  * Permission to use, copy, modify and distribute this software and its   *
6  * documentation strictly for non-commercial purposes is hereby granted   *
7  * without fee, provided that the above copyright notice appears in all   *
8  * copies and that both the copyright notice and this permission notice   *
9  * appear in the supporting documentation. The authors make no claims     *
10  * about the suitability of this software for any purpose. It is          *
11  * provided "as is" without express or implied warranty.                  *
12  **************************************************************************/
13
14 /* $Id: AliBalancePsi.cxx 54125 2012-01-24 21:07:41Z miweber $ */
15
16 //-----------------------------------------------------------------
17 //           Balance Function class
18 //   This is the class to deal with the Balance Function wrt Psi analysis
19 //   Origin: Panos Christakoglou, Nikhef, Panos.Christakoglou@cern.ch
20 //-----------------------------------------------------------------
21
22
23 //ROOT
24 #include <Riostream.h>
25 #include <TCanvas.h>
26 #include <TMath.h>
27 #include <TAxis.h>
28 #include <TH2D.h>
29 #include <TH3D.h>
30 #include <TLorentzVector.h>
31 #include <TObjArray.h>
32 #include <TGraphErrors.h>
33 #include <TString.h>
34
35 #include "AliVParticle.h"
36 #include "AliMCParticle.h"
37 #include "AliESDtrack.h"
38 #include "AliAODTrack.h"
39 #include "AliTHn.h"
40 #include "AliAnalysisTaskTriggeredBF.h"
41
42 #include "AliBalancePsi.h"
43
44 ClassImp(AliBalancePsi)
45
46 //____________________________________________________________________//
47 AliBalancePsi::AliBalancePsi() :
48   TObject(), 
49   fShuffle(kFALSE),
50   fAnalysisLevel("ESD"),
51   fAnalyzedEvents(0) ,
52   fCentralityId(0) ,
53   fCentStart(0.),
54   fCentStop(0.),
55   fHistP(0),
56   fHistN(0),
57   fHistPN(0),
58   fHistNP(0),
59   fHistPP(0),
60   fHistNN(0),
61   fHistHBTbefore(0),
62   fHistHBTafter(0),
63   fHistConversionbefore(0),
64   fHistConversionafter(0),
65   fHistPsiMinusPhi(0),
66   fPsiInterval(15.),
67   fDeltaEtaMax(2.0),
68   fHBTCut(kFALSE),
69   fConversionCut(kFALSE),
70   fEventClass("EventPlane"){
71   // Default constructor
72 }
73
74 //____________________________________________________________________//
75 AliBalancePsi::AliBalancePsi(const AliBalancePsi& balance):
76   TObject(balance), fShuffle(balance.fShuffle), 
77   fAnalysisLevel(balance.fAnalysisLevel),
78   fAnalyzedEvents(balance.fAnalyzedEvents), 
79   fCentralityId(balance.fCentralityId),
80   fCentStart(balance.fCentStart),
81   fCentStop(balance.fCentStop),
82   fHistP(balance.fHistP),
83   fHistN(balance.fHistN),
84   fHistPN(balance.fHistPN),
85   fHistNP(balance.fHistNP),
86   fHistPP(balance.fHistPP),
87   fHistNN(balance.fHistNN),
88   fHistHBTbefore(balance.fHistHBTbefore),
89   fHistHBTafter(balance.fHistHBTafter),
90   fHistConversionbefore(balance.fHistConversionbefore),
91   fHistConversionafter(balance.fHistConversionafter),
92   fHistPsiMinusPhi(balance.fHistPsiMinusPhi),
93   fPsiInterval(balance.fPsiInterval),
94   fDeltaEtaMax(balance.fDeltaEtaMax),
95   fHBTCut(balance.fHBTCut),
96   fConversionCut(balance.fConversionCut),
97   fEventClass("EventPlane"){
98   //copy constructor
99 }
100
101 //____________________________________________________________________//
102 AliBalancePsi::~AliBalancePsi() {
103   // Destructor
104   delete fHistP;
105   delete fHistN;
106   delete fHistPN;
107   delete fHistNP;
108   delete fHistPP;
109   delete fHistNN;
110
111   delete fHistHBTbefore;
112   delete fHistHBTafter;
113   delete fHistConversionbefore;
114   delete fHistConversionafter;
115   delete fHistPsiMinusPhi;
116     
117 }
118
119 //____________________________________________________________________//
120 void AliBalancePsi::InitHistograms() {
121   // single particle histograms
122
123   // global switch disabling the reference 
124   // (to avoid "Replacing existing TH1" if several wagons are created in train)
125   Bool_t oldStatus = TH1::AddDirectoryStatus();
126   TH1::AddDirectory(kFALSE);
127
128   Int_t anaSteps   = 1;       // analysis steps
129   Int_t iBinSingle[kTrackVariablesSingle];        // binning for track variables
130   Double_t* dBinsSingle[kTrackVariablesSingle];   // bins for track variables  
131   TString axisTitleSingle[kTrackVariablesSingle]; // axis titles for track variables
132   
133   // two particle histograms
134   Int_t iBinPair[kTrackVariablesPair];         // binning for track variables
135   Double_t* dBinsPair[kTrackVariablesPair];    // bins for track variables  
136   TString axisTitlePair[kTrackVariablesPair];  // axis titles for track variables
137   /**********************************************************
138    
139   ======> Modification: Change Event Classification Scheme
140     
141   ---> fEventClass == "EventPlane"
142    
143    Default operation with Event Plane 
144    
145   ---> fEventClass == "Multiplicity"
146    
147    Work with kTPCITStracklet multiplicity (from GetReferenceMultiplicity)
148    
149   ---> fEventClass == "Centrality" 
150    
151    Work with Centrality Bins
152
153   ***********************************************************/
154    
155   //--- Multiplicity Bins ------------------------------------
156     const Int_t kMultBins = 8;
157     //A first rough attempt at four bins
158     Double_t kMultBinLimits[kMultBins+1]={0,10,20,30,40,50,60,70,80};
159   //----------------------------------------------------------
160     
161   //--- Centrality Bins --------------------------------------
162     const Int_t kNCentralityBins = 9;
163     Double_t centralityBins[kNCentralityBins+1] = {0.,5.,10.,20.,30.,40.,50.,60.,70.,80.};
164   //----------------------------------------------------------
165     
166   //--- Event Plane Bins -------------------------------------
167     //Psi_2: -0.5->0.5 (in plane), 0.5->1.5 (intermediate), 1.5->2.5 (out of plane), 2.5->3.5 (rest)
168     const Int_t kNPsi2Bins = 4;
169     Double_t psi2Bins[kNPsi2Bins+1] = {-0.5,0.5,1.5,2.5,3.5};
170   //----------------------------------------------------------
171     
172   //Depending on fEventClass Variable, do one thing or the other...
173     if(fEventClass == "Multiplicity"){
174         iBinSingle[0]       = kMultBins;
175         dBinsSingle[0]      = kMultBinLimits;
176         axisTitleSingle[0]  = "kTPCITStracklet multiplicity";
177         iBinPair[0]       = kMultBins;
178         dBinsPair[0]      = kMultBinLimits;
179         axisTitlePair[0]  = "kTPCITStracklet multiplicity";
180     }
181     if(fEventClass == "Centrality"){
182         iBinSingle[0]       = kNCentralityBins;
183         dBinsSingle[0]      = centralityBins;
184         axisTitleSingle[0]  = "Centrality percentile [%]";
185         iBinPair[0]       = kNCentralityBins;
186         dBinsPair[0]      = centralityBins;
187         axisTitlePair[0]  = "Centrality percentile [%]";
188     }
189     if(fEventClass == "EventPlane"){
190         iBinSingle[0]       = kNPsi2Bins;
191         dBinsSingle[0]      = psi2Bins;
192         axisTitleSingle[0]  = "#varphi - #Psi_{2} (a.u.)";
193         iBinPair[0]       = kNPsi2Bins;
194         dBinsPair[0]      = psi2Bins;
195         axisTitlePair[0]  = "#varphi - #Psi_{2} (a.u.)";
196     }
197   
198    // delta eta
199   const Int_t kNDeltaEtaBins = 80;
200   Double_t deltaEtaBins[kNDeltaEtaBins+1];
201   for(Int_t i = 0; i < kNDeltaEtaBins+1; i++)
202     deltaEtaBins[i] = - fDeltaEtaMax + i * 2 * fDeltaEtaMax / (Double_t)kNDeltaEtaBins;
203   iBinPair[1]       = kNDeltaEtaBins;
204   dBinsPair[1]      = deltaEtaBins;
205   axisTitlePair[1]  = "#Delta#eta"; 
206
207    // delta phi
208   const Int_t kNDeltaPhiBins = 72;
209   Double_t deltaPhiBins[kNDeltaPhiBins+1];
210   for(Int_t i = 0; i < kNDeltaPhiBins+1; i++){
211     //deltaPhiBins[i] = -180.0 + i * 5.;
212     deltaPhiBins[i] = -TMath::Pi()/2. + i * 5.*TMath::Pi()/180.;
213   } 
214   iBinPair[2]       = kNDeltaPhiBins;
215   dBinsPair[2]      = deltaPhiBins;
216   axisTitlePair[2]  = "#Delta#varphi (rad)"; 
217
218   // pt(trigger-associated)
219   const Int_t kNPtBins = 16;
220   Double_t ptBins[kNPtBins+1] = {0.2,0.6,1.0,1.5,2.0,2.5,3.0,3.5,4.0,5.0,6.0,7.0,8.0,10.,12.,15.,20.};
221   //for(Int_t i = 0; i < kNPtBins+1; i++){
222   //ptBins[i] = 0.2 + i * 0.5;
223   //} 
224   iBinSingle[1]       = kNPtBins;
225   dBinsSingle[1]      = ptBins;
226   axisTitleSingle[1]  = "p_{T,trig.} (GeV/c)"; 
227
228   iBinPair[3]       = kNPtBins;
229   dBinsPair[3]      = ptBins;
230   axisTitlePair[3]  = "p_{T,trig.} (GeV/c)"; 
231
232   iBinPair[4]       = kNPtBins;
233   dBinsPair[4]      = ptBins;
234   axisTitlePair[4]  = "p_{T,assoc.} (GeV/c)";   
235
236   TString histName;
237   //+ triggered particles
238   histName = "fHistP"; 
239   if(fShuffle) histName.Append("_shuffle");
240   if(fCentralityId) histName += fCentralityId.Data();
241   fHistP = new AliTHn(histName.Data(),histName.Data(),anaSteps,kTrackVariablesSingle,iBinSingle);
242   for (Int_t j=0; j<kTrackVariablesSingle; j++) {
243     fHistP->SetBinLimits(j, dBinsSingle[j]);
244     fHistP->SetVarTitle(j, axisTitleSingle[j]);
245   }
246
247   //- triggered particles
248   histName = "fHistN"; 
249   if(fShuffle) histName.Append("_shuffle");
250   if(fCentralityId) histName += fCentralityId.Data();
251   fHistN = new AliTHn(histName.Data(),histName.Data(),anaSteps,kTrackVariablesSingle,iBinSingle);
252   for (Int_t j=0; j<kTrackVariablesSingle; j++) {
253     fHistN->SetBinLimits(j, dBinsSingle[j]);
254     fHistN->SetVarTitle(j, axisTitleSingle[j]);
255   }
256   
257   //+- pairs
258   histName = "fHistPN";
259   if(fShuffle) histName.Append("_shuffle");
260   if(fCentralityId) histName += fCentralityId.Data();
261   fHistPN = new AliTHn(histName.Data(),histName.Data(),anaSteps, kTrackVariablesPair, iBinPair);
262   for (Int_t j=0; j<kTrackVariablesPair; j++) {
263     fHistPN->SetBinLimits(j, dBinsPair[j]);
264     fHistPN->SetVarTitle(j, axisTitlePair[j]);
265   }
266
267   //-+ pairs
268   histName = "fHistNP";
269   if(fShuffle) histName.Append("_shuffle");
270   if(fCentralityId) histName += fCentralityId.Data();
271   fHistNP = new AliTHn(histName.Data(),histName.Data(),anaSteps, kTrackVariablesPair, iBinPair);
272   for (Int_t j=0; j<kTrackVariablesPair; j++) {
273     fHistNP->SetBinLimits(j, dBinsPair[j]);
274     fHistNP->SetVarTitle(j, axisTitlePair[j]);
275   }
276
277   //++ pairs
278   histName = "fHistPP";
279   if(fShuffle) histName.Append("_shuffle");
280   if(fCentralityId) histName += fCentralityId.Data();
281   fHistPP = new AliTHn(histName.Data(),histName.Data(),anaSteps, kTrackVariablesPair, iBinPair);
282   for (Int_t j=0; j<kTrackVariablesPair; j++) {
283     fHistPP->SetBinLimits(j, dBinsPair[j]);
284     fHistPP->SetVarTitle(j, axisTitlePair[j]);
285   }
286
287   //-- pairs
288   histName = "fHistNN";
289   if(fShuffle) histName.Append("_shuffle");
290   if(fCentralityId) histName += fCentralityId.Data();
291   fHistNN = new AliTHn(histName.Data(),histName.Data(),anaSteps, kTrackVariablesPair, iBinPair);
292   for (Int_t j=0; j<kTrackVariablesPair; j++) {
293     fHistNN->SetBinLimits(j, dBinsPair[j]);
294     fHistNN->SetVarTitle(j, axisTitlePair[j]);
295   }
296   AliInfo("Finished setting up the AliTHn");
297
298   // QA histograms
299   fHistHBTbefore        = new TH2D("fHistHBTbefore","before HBT cut",200,0,2,200,0,2.*TMath::Pi());
300   fHistHBTafter         = new TH2D("fHistHBTafter","after HBT cut",200,0,2,200,0,2.*TMath::Pi());
301   fHistConversionbefore = new TH2D("fHistConversionbefore","before Conversion cut",200,0,2,200,0,2.*TMath::Pi());
302   fHistConversionafter  = new TH2D("fHistConversionafter","after Conversion cut",200,0,2,200,0,2.*TMath::Pi());
303   fHistPsiMinusPhi     = new TH2D("fHistPsiMinusPhi","",4,-0.5,3.5,100,0,2.*TMath::Pi());
304
305   TH1::AddDirectory(oldStatus);
306
307 }
308
309 //____________________________________________________________________//
310 void AliBalancePsi::CalculateBalance(Double_t gReactionPlane,
311                                      TObjArray *particles, 
312                                      TObjArray *particlesMixed,
313                      Float_t bSign,
314                      Double_t kMultorCent) {
315   // Calculates the balance function
316   fAnalyzedEvents++;
317     
318   // Initialize histograms if not done yet
319   if(!fHistPN){
320     AliWarning("Histograms not yet initialized! --> Will be done now");
321     AliWarning("This works only in local mode --> Add 'gBalance->InitHistograms()' in your configBalanceFunction");
322     InitHistograms();
323   }
324
325   Double_t trackVariablesSingle[kTrackVariablesSingle];
326   Double_t trackVariablesPair[kTrackVariablesPair];
327
328   if (!particles){
329     AliWarning("particles TObjArray is NULL pointer --> return");
330     return;
331   }
332   
333   // define end of particle loops
334   Int_t iMax = particles->GetEntriesFast();
335   Int_t jMax = iMax;
336   if (particlesMixed)
337     jMax = particlesMixed->GetEntriesFast();
338
339   // Eta() is extremely time consuming, therefore cache it for the inner loop here:
340   TObjArray* particlesSecond = (particlesMixed) ? particlesMixed : particles;
341
342   TArrayF secondEta(jMax);
343   TArrayF secondPhi(jMax);
344   TArrayF secondPt(jMax);
345   TArrayS secondCharge(jMax);
346   TArrayD secondCorrection(jMax);
347
348   for (Int_t i=0; i<jMax; i++){
349     secondEta[i] = ((AliVParticle*) particlesSecond->At(i))->Eta();
350     secondPhi[i] = ((AliVParticle*) particlesSecond->At(i))->Phi();
351     secondPt[i]  = ((AliVParticle*) particlesSecond->At(i))->Pt();
352     secondCharge[i]  = (Short_t)((AliVParticle*) particlesSecond->At(i))->Charge();
353     secondCorrection[i]  = (Double_t)((AliBFBasicParticle*) particlesSecond->At(i))->Correction();   //==========================correction
354   }
355   
356   // 1st particle loop
357   for (Int_t i = 0; i < iMax; i++) {
358     //AliVParticle* firstParticle = (AliVParticle*) particles->At(i);
359     AliBFBasicParticle* firstParticle = (AliBFBasicParticle*) particles->At(i); //==========================correction
360     
361     // some optimization
362     Float_t firstEta = firstParticle->Eta();
363     Float_t firstPhi = firstParticle->Phi();
364     Float_t firstPt  = firstParticle->Pt();
365     Float_t firstCorrection  = firstParticle->Correction();//==========================correction
366
367     // Event plane (determine psi bin)
368     Double_t gPsiMinusPhi    =   0.;
369     Double_t gPsiMinusPhiBin = -10.;
370     gPsiMinusPhi   = TMath::Abs(firstPhi - gReactionPlane);
371     //in-plane
372     if((gPsiMinusPhi <= 7.5*TMath::DegToRad())||
373        ((172.5*TMath::DegToRad() <= gPsiMinusPhi)&&(gPsiMinusPhi <= 187.5*TMath::DegToRad())))
374       gPsiMinusPhiBin = 0.0;
375     //intermediate
376     else if(((37.5*TMath::DegToRad() <= gPsiMinusPhi)&&(gPsiMinusPhi <= 52.5*TMath::DegToRad()))||
377             ((127.5*TMath::DegToRad() <= gPsiMinusPhi)&&(gPsiMinusPhi <= 142.5*TMath::DegToRad()))||
378             ((217.5*TMath::DegToRad() <= gPsiMinusPhi)&&(gPsiMinusPhi <= 232.5*TMath::DegToRad()))||
379             ((307.5*TMath::DegToRad() <= gPsiMinusPhi)&&(gPsiMinusPhi <= 322.5*TMath::DegToRad())))
380       gPsiMinusPhiBin = 1.0;
381     //out of plane
382     else if(((82.5*TMath::DegToRad() <= gPsiMinusPhi)&&(gPsiMinusPhi <= 97.5*TMath::DegToRad()))||
383             ((262.5*TMath::DegToRad() <= gPsiMinusPhi)&&(gPsiMinusPhi <= 277.5*TMath::DegToRad())))
384       gPsiMinusPhiBin = 2.0;
385     //everything else
386     else 
387       gPsiMinusPhiBin = 3.0;
388     
389     fHistPsiMinusPhi->Fill(gPsiMinusPhiBin,gPsiMinusPhi);
390
391     Short_t  charge1 = (Short_t) firstParticle->Charge();
392     
393     trackVariablesSingle[0]    =  gPsiMinusPhiBin;
394     trackVariablesSingle[1]    =  firstPt;
395       if(fEventClass=="Multiplicity" || fEventClass == "Centrality" ) trackVariablesSingle[0] = kMultorCent;
396     
397     //fill single particle histograms
398     if(charge1 > 0)      fHistP->Fill(trackVariablesSingle,0,firstCorrection); //==========================correction
399     else if(charge1 < 0) fHistN->Fill(trackVariablesSingle,0,firstCorrection);  //==========================correction
400     
401     // 2nd particle loop
402     for(Int_t j = 0; j < jMax; j++) {   
403
404       if(!particlesMixed && j == i) continue; // no auto correlations (only for non mixing)
405
406       Short_t charge2 = secondCharge[j];
407       
408       trackVariablesPair[0]    =  trackVariablesSingle[0];
409       trackVariablesPair[1]    =  firstEta - secondEta[j];  // delta eta
410       trackVariablesPair[2]    =  firstPhi - secondPhi[j];  // delta phi
411       //if (trackVariablesPair[2] > 180.)   // delta phi between -180 and 180 
412       //trackVariablesPair[2] -= 360.;
413       //if (trackVariablesPair[2] <  - 180.) 
414       //trackVariablesPair[2] += 360.;
415       if (trackVariablesPair[2] > TMath::Pi()) // delta phi between -pi and pi 
416         trackVariablesPair[2] -= 2.*TMath::Pi();
417       if (trackVariablesPair[2] <  - TMath::Pi()) 
418         trackVariablesPair[2] += 2.*TMath::Pi();
419       if (trackVariablesPair[2] <  - TMath::Pi()/2.) 
420       trackVariablesPair[2] += 2.*TMath::Pi();
421       
422       trackVariablesPair[3]    =  firstPt;      // pt trigger
423       trackVariablesPair[4]    =  secondPt[j];  // pt
424       //        trackVariablesPair[5]    =  fCentrality;  // centrality
425
426       // HBT like cut
427       if(fHBTCut && charge1 * charge2 > 0){
428         //if( dphi < 3 || deta < 0.01 ){   // VERSION 1
429         //  continue;
430         
431         Double_t deta = firstEta - secondEta[j];
432         Double_t dphi = firstPhi - secondPhi[j];
433         // VERSION 2 (Taken from DPhiCorrelations)
434         // the variables & cuthave been developed by the HBT group 
435         // see e.g. https://indico.cern.ch/materialDisplay.py?contribId=36&sessionId=6&materialId=slides&confId=142700
436         fHistHBTbefore->Fill(deta,dphi);
437         
438         // optimization
439         if (TMath::Abs(deta) < 0.02 * 2.5 * 3) //twoTrackEfficiencyCutValue = 0.02 [default for dphicorrelations]
440           {
441             // phi in rad
442             //Float_t phi1rad = firstPhi*TMath::DegToRad();
443             //Float_t phi2rad = secondPhi[j]*TMath::DegToRad();
444             Float_t phi1rad = firstPhi;
445             Float_t phi2rad = secondPhi[j];
446             
447             // check first boundaries to see if is worth to loop and find the minimum
448             Float_t dphistar1 = GetDPhiStar(phi1rad, firstPt, charge1, phi2rad, secondPt[j], charge2, 0.8, bSign);
449             Float_t dphistar2 = GetDPhiStar(phi1rad, firstPt, charge1, phi2rad, secondPt[j], charge2, 2.5, bSign);
450             
451             const Float_t kLimit = 0.02 * 3;
452             
453             Float_t dphistarminabs = 1e5;
454             Float_t dphistarmin = 1e5;
455             
456             if (TMath::Abs(dphistar1) < kLimit || TMath::Abs(dphistar2) < kLimit || dphistar1 * dphistar2 < 0 ) {
457               for (Double_t rad=0.8; rad<2.51; rad+=0.01) {
458                 Float_t dphistar = GetDPhiStar(phi1rad, firstPt, charge1, phi2rad, secondPt[j], charge2, rad, bSign);
459                 Float_t dphistarabs = TMath::Abs(dphistar);
460                 
461                 if (dphistarabs < dphistarminabs) {
462                   dphistarmin = dphistar;
463                   dphistarminabs = dphistarabs;
464                 }
465               }
466               
467               if (dphistarminabs < 0.02 && TMath::Abs(deta) < 0.02) {
468                 //AliInfo(Form("HBT: Removed track pair %d %d with [[%f %f]] %f %f %f | %f %f %d %f %f %d %f", i, j, deta, dphi, dphistarminabs, dphistar1, dphistar2, phi1rad, pt1, charge1, phi2rad, pt2, charge2, bSign));
469                 continue;
470               }
471             }
472           }
473         fHistHBTafter->Fill(deta,dphi);
474       }//HBT cut
475         
476       // conversions
477       if(fConversionCut) {
478         if (charge1 * charge2 < 0) {
479           Double_t deta = firstEta - secondEta[j];
480           Double_t dphi = firstPhi - secondPhi[j];
481           fHistConversionbefore->Fill(deta,dphi);
482           
483           Float_t m0 = 0.510e-3;
484           Float_t tantheta1 = 1e10;
485           
486           // phi in rad
487           //Float_t phi1rad = firstPhi*TMath::DegToRad();
488           //Float_t phi2rad = secondPhi[j]*TMath::DegToRad();
489           Float_t phi1rad = firstPhi;
490           Float_t phi2rad = secondPhi[j];
491           
492           if (firstEta < -1e-10 || firstEta > 1e-10)
493             tantheta1 = 2 * TMath::Exp(-firstEta) / ( 1 - TMath::Exp(-2*firstEta));
494           
495           Float_t tantheta2 = 1e10;
496           if (secondEta[j] < -1e-10 || secondEta[j] > 1e-10)
497             tantheta2 = 2 * TMath::Exp(-secondEta[j]) / ( 1 - TMath::Exp(-2*secondEta[j]));
498           
499           Float_t e1squ = m0 * m0 + firstPt * firstPt * (1.0 + 1.0 / tantheta1 / tantheta1);
500           Float_t e2squ = m0 * m0 + secondPt[j] * secondPt[j] * (1.0 + 1.0 / tantheta2 / tantheta2);
501           
502           Float_t masssqu = 2 * m0 * m0 + 2 * ( TMath::Sqrt(e1squ * e2squ) - ( firstPt * secondPt[j] * ( TMath::Cos(phi1rad - phi2rad) + 1.0 / tantheta1 / tantheta2 ) ) );
503           
504           if (masssqu < 0.04*0.04){
505             //AliInfo(Form("Conversion: Removed track pair %d %d with [[%f %f] %f %f] %d %d <- %f %f  %f %f   %f %f ", i, j, deta, dphi, masssqu, charge1, charge2,eta1,eta2,phi1,phi2,pt1,pt2));
506             continue;
507           }
508           fHistConversionafter->Fill(deta,dphi);
509         }
510       }//conversion cut
511       
512       if( charge1 > 0 && charge2 < 0)  fHistPN->Fill(trackVariablesPair,0,firstCorrection*secondCorrection[j]); //==========================correction
513       else if( charge1 < 0 && charge2 > 0)  fHistNP->Fill(trackVariablesPair,0,firstCorrection*secondCorrection[j]);//==========================correction 
514       else if( charge1 > 0 && charge2 > 0)  fHistPP->Fill(trackVariablesPair,0,firstCorrection*secondCorrection[j]);//==========================correction 
515       else if( charge1 < 0 && charge2 < 0)  fHistNN->Fill(trackVariablesPair,0,firstCorrection*secondCorrection[j]);//==========================correction 
516       else {
517         //AliWarning(Form("Wrong charge combination: charge1 = %d and charge2 = %d",charge,charge2));
518         continue;
519       }
520     }//end of 2nd particle loop
521   }//end of 1st particle loop
522 }  
523
524 //____________________________________________________________________//
525 TH1D *AliBalancePsi::GetBalanceFunctionHistogram(Int_t iVariableSingle,
526                                                  Int_t iVariablePair,
527                                                  Double_t psiMin, 
528                                                  Double_t psiMax,
529                                                  Double_t ptTriggerMin,
530                                                  Double_t ptTriggerMax,
531                                                  Double_t ptAssociatedMin,
532                                                  Double_t ptAssociatedMax) {
533   //Returns the BF histogram, extracted from the 6 AliTHn objects 
534   //(private members) of the AliBalancePsi class.
535   //iVariableSingle: 0(phi-Psi), 1(pt-trigger)
536   //iVariablePair: 0(phi-Psi) 1(Delta eta), 2(Delta phi), 3(pt-trigger), 4(pt-associated
537   // Psi_2
538   fHistP->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
539   fHistN->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
540   fHistPN->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
541   fHistNP->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
542   fHistPP->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
543   fHistNN->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
544
545   // pt trigger
546   if((ptTriggerMin != -1.)&&(ptTriggerMax != -1.)) {
547     fHistP->GetGrid(0)->GetGrid()->GetAxis(1)->SetRangeUser(ptTriggerMin,ptTriggerMax);
548     fHistN->GetGrid(0)->GetGrid()->GetAxis(1)->SetRangeUser(ptTriggerMin,ptTriggerMax);
549     fHistPN->GetGrid(0)->GetGrid()->GetAxis(3)->SetRangeUser(ptTriggerMin,ptTriggerMax);
550     fHistNP->GetGrid(0)->GetGrid()->GetAxis(3)->SetRangeUser(ptTriggerMin,ptTriggerMax);
551     fHistPP->GetGrid(0)->GetGrid()->GetAxis(3)->SetRangeUser(ptTriggerMin,ptTriggerMax);
552     fHistNN->GetGrid(0)->GetGrid()->GetAxis(3)->SetRangeUser(ptTriggerMin,ptTriggerMax);
553   }
554
555   // pt associated
556   if((ptAssociatedMin != -1.)&&(ptAssociatedMax != -1.)) {
557     fHistPN->GetGrid(0)->GetGrid()->GetAxis(4)->SetRangeUser(ptAssociatedMin,ptAssociatedMax);
558     fHistNP->GetGrid(0)->GetGrid()->GetAxis(4)->SetRangeUser(ptAssociatedMin,ptAssociatedMax);
559     fHistPP->GetGrid(0)->GetGrid()->GetAxis(4)->SetRangeUser(ptAssociatedMin,ptAssociatedMax);
560     fHistNN->GetGrid(0)->GetGrid()->GetAxis(4)->SetRangeUser(ptAssociatedMin,ptAssociatedMax);
561   }
562
563   //Printf("P:%lf - N:%lf - PN:%lf - NP:%lf - PP:%lf - NN:%lf",fHistP->GetEntries(0),fHistN->GetEntries(0),fHistPN->GetEntries(0),fHistNP->GetEntries(0),fHistPP->GetEntries(0),fHistNN->GetEntries(0));
564
565   // Project into the wanted space (1st: analysis step, 2nd: axis)
566   TH1D* hTemp1 = (TH1D*)fHistPN->Project(0,iVariablePair);
567   TH1D* hTemp2 = (TH1D*)fHistNP->Project(0,iVariablePair);
568   TH1D* hTemp3 = (TH1D*)fHistPP->Project(0,iVariablePair);
569   TH1D* hTemp4 = (TH1D*)fHistNN->Project(0,iVariablePair);
570   TH1D* hTemp5 = (TH1D*)fHistP->Project(0,iVariableSingle);
571   TH1D* hTemp6 = (TH1D*)fHistN->Project(0,iVariableSingle);
572
573   TH1D *gHistBalanceFunctionHistogram = 0x0;
574   if((hTemp1)&&(hTemp2)&&(hTemp3)&&(hTemp4)&&(hTemp5)&&(hTemp6)) {
575     gHistBalanceFunctionHistogram = (TH1D*)hTemp1->Clone();
576     gHistBalanceFunctionHistogram->Reset();
577     
578     switch(iVariablePair) {
579     case 1:
580       gHistBalanceFunctionHistogram->GetXaxis()->SetTitle("#Delta#eta");
581       gHistBalanceFunctionHistogram->GetYaxis()->SetTitle("B(#Delta#eta)");
582       break;
583     case 2:
584       gHistBalanceFunctionHistogram->GetXaxis()->SetTitle("#Delta#varphi (rad)");
585       gHistBalanceFunctionHistogram->GetYaxis()->SetTitle("B(#Delta#varphi)");
586       break;
587     default:
588       break;
589     }
590
591     hTemp1->Sumw2();
592     hTemp2->Sumw2();
593     hTemp3->Sumw2();
594     hTemp4->Sumw2();
595     hTemp1->Add(hTemp3,-1.);
596     hTemp1->Scale(1./hTemp5->GetEntries());
597     hTemp2->Add(hTemp4,-1.);
598     hTemp2->Scale(1./hTemp6->GetEntries());
599     gHistBalanceFunctionHistogram->Add(hTemp1,hTemp2,1.,1.);
600     gHistBalanceFunctionHistogram->Scale(0.5);
601
602     //normalize to bin width
603     gHistBalanceFunctionHistogram->Scale(1./((Double_t)gHistBalanceFunctionHistogram->GetXaxis()->GetBinWidth(1)*(Double_t)gHistBalanceFunctionHistogram->GetYaxis()->GetBinWidth(1)));
604   }
605
606   return gHistBalanceFunctionHistogram;
607 }
608
609 //____________________________________________________________________//
610 TH1D *AliBalancePsi::GetBalanceFunctionHistogram2pMethod(Int_t iVariableSingle,
611                                                          Int_t iVariablePair,
612                                                          Double_t psiMin, 
613                                                          Double_t psiMax,
614                                                          Double_t ptTriggerMin,
615                                                          Double_t ptTriggerMax,
616                                                          Double_t ptAssociatedMin,
617                                                          Double_t ptAssociatedMax,
618                                                          AliBalancePsi *bfMix) {
619   //Returns the BF histogram, extracted from the 6 AliTHn objects 
620   //after dividing each correlation function by the Event Mixing one 
621   //(private members) of the AliBalancePsi class.
622   //iVariableSingle: 0(phi-Psi), 1(pt-trigger)
623   //iVariablePair: 0(phi-Psi) 1(Delta eta), 2(Delta phi), 3(pt-trigger), 4(pt-associated
624   // Psi_2
625   fHistP->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
626   fHistN->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
627   fHistPN->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
628   fHistNP->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
629   fHistPP->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
630   fHistNN->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
631
632   // pt trigger
633   if((ptTriggerMin != -1.)&&(ptTriggerMax != -1.)) {
634     fHistP->GetGrid(0)->GetGrid()->GetAxis(1)->SetRangeUser(ptTriggerMin,ptTriggerMax);
635     fHistN->GetGrid(0)->GetGrid()->GetAxis(1)->SetRangeUser(ptTriggerMin,ptTriggerMax);
636     fHistPN->GetGrid(0)->GetGrid()->GetAxis(3)->SetRangeUser(ptTriggerMin,ptTriggerMax);
637     fHistNP->GetGrid(0)->GetGrid()->GetAxis(3)->SetRangeUser(ptTriggerMin,ptTriggerMax);
638     fHistPP->GetGrid(0)->GetGrid()->GetAxis(3)->SetRangeUser(ptTriggerMin,ptTriggerMax);
639     fHistNN->GetGrid(0)->GetGrid()->GetAxis(3)->SetRangeUser(ptTriggerMin,ptTriggerMax);
640   }
641
642   // pt associated
643   if((ptAssociatedMin != -1.)&&(ptAssociatedMax != -1.)) {
644     fHistPN->GetGrid(0)->GetGrid()->GetAxis(4)->SetRangeUser(ptAssociatedMin,ptAssociatedMax);
645     fHistNP->GetGrid(0)->GetGrid()->GetAxis(4)->SetRangeUser(ptAssociatedMin,ptAssociatedMax);
646     fHistPP->GetGrid(0)->GetGrid()->GetAxis(4)->SetRangeUser(ptAssociatedMin,ptAssociatedMax);
647     fHistNN->GetGrid(0)->GetGrid()->GetAxis(4)->SetRangeUser(ptAssociatedMin,ptAssociatedMax);
648   }
649
650   // ============================================================================================
651   // the same for event mixing
652   AliTHn *fHistPMix = bfMix->GetHistNp();
653   AliTHn *fHistNMix = bfMix->GetHistNn();
654   AliTHn *fHistPNMix = bfMix->GetHistNpn();
655   AliTHn *fHistNPMix = bfMix->GetHistNnp();
656   AliTHn *fHistPPMix = bfMix->GetHistNpp();
657   AliTHn *fHistNNMix = bfMix->GetHistNnn();
658
659   // Psi_2
660   fHistPMix->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
661   fHistNMix->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
662   fHistPNMix->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
663   fHistNPMix->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
664   fHistPPMix->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
665   fHistNNMix->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
666
667   // pt trigger
668   if((ptTriggerMin != -1.)&&(ptTriggerMax != -1.)) {
669     fHistPMix->GetGrid(0)->GetGrid()->GetAxis(1)->SetRangeUser(ptTriggerMin,ptTriggerMax);
670     fHistNMix->GetGrid(0)->GetGrid()->GetAxis(1)->SetRangeUser(ptTriggerMin,ptTriggerMax);
671     fHistPNMix->GetGrid(0)->GetGrid()->GetAxis(3)->SetRangeUser(ptTriggerMin,ptTriggerMax);
672     fHistNPMix->GetGrid(0)->GetGrid()->GetAxis(3)->SetRangeUser(ptTriggerMin,ptTriggerMax);
673     fHistPPMix->GetGrid(0)->GetGrid()->GetAxis(3)->SetRangeUser(ptTriggerMin,ptTriggerMax);
674     fHistNNMix->GetGrid(0)->GetGrid()->GetAxis(3)->SetRangeUser(ptTriggerMin,ptTriggerMax);
675   }
676
677   // pt associated
678   if((ptAssociatedMin != -1.)&&(ptAssociatedMax != -1.)) {
679     fHistPNMix->GetGrid(0)->GetGrid()->GetAxis(4)->SetRangeUser(ptAssociatedMin,ptAssociatedMax);
680     fHistNPMix->GetGrid(0)->GetGrid()->GetAxis(4)->SetRangeUser(ptAssociatedMin,ptAssociatedMax);
681     fHistPPMix->GetGrid(0)->GetGrid()->GetAxis(4)->SetRangeUser(ptAssociatedMin,ptAssociatedMax);
682     fHistNNMix->GetGrid(0)->GetGrid()->GetAxis(4)->SetRangeUser(ptAssociatedMin,ptAssociatedMax);
683   }
684   // ============================================================================================
685
686   //Printf("P:%lf - N:%lf - PN:%lf - NP:%lf - PP:%lf - NN:%lf",fHistP->GetEntries(0),fHistN->GetEntries(0),fHistPN->GetEntries(0),fHistNP->GetEntries(0),fHistPP->GetEntries(0),fHistNN->GetEntries(0));
687
688   // Project into the wanted space (1st: analysis step, 2nd: axis)
689   TH1D* hTemp1 = (TH1D*)fHistPN->Project(0,iVariablePair);
690   TH1D* hTemp2 = (TH1D*)fHistNP->Project(0,iVariablePair);
691   TH1D* hTemp3 = (TH1D*)fHistPP->Project(0,iVariablePair);
692   TH1D* hTemp4 = (TH1D*)fHistNN->Project(0,iVariablePair);
693   TH1D* hTemp5 = (TH1D*)fHistP->Project(0,iVariableSingle);
694   TH1D* hTemp6 = (TH1D*)fHistN->Project(0,iVariableSingle);
695
696   // ============================================================================================
697   // the same for event mixing
698   TH2D* hTemp1Mix = (TH2D*)fHistPNMix->Project(0,iVariablePair);
699   TH2D* hTemp2Mix = (TH2D*)fHistNPMix->Project(0,iVariablePair);
700   TH2D* hTemp3Mix = (TH2D*)fHistPPMix->Project(0,iVariablePair);
701   TH2D* hTemp4Mix = (TH2D*)fHistNNMix->Project(0,iVariablePair);
702   TH1D* hTemp5Mix = (TH1D*)fHistPMix->Project(0,iVariableSingle);
703   TH1D* hTemp6Mix = (TH1D*)fHistNMix->Project(0,iVariableSingle);
704   // ============================================================================================
705
706   TH1D *gHistBalanceFunctionHistogram = 0x0;
707   if((hTemp1)&&(hTemp2)&&(hTemp3)&&(hTemp4)&&(hTemp5)&&(hTemp6)) {
708     gHistBalanceFunctionHistogram = (TH1D*)hTemp1->Clone();
709     gHistBalanceFunctionHistogram->Reset();
710     
711     switch(iVariablePair) {
712     case 1:
713       gHistBalanceFunctionHistogram->GetXaxis()->SetTitle("#Delta#eta");
714       gHistBalanceFunctionHistogram->GetYaxis()->SetTitle("B(#Delta#eta)");
715       break;
716     case 2:
717       gHistBalanceFunctionHistogram->GetXaxis()->SetTitle("#Delta#varphi (rad)");
718       gHistBalanceFunctionHistogram->GetYaxis()->SetTitle("B(#Delta#varphi)");
719       break;
720     default:
721       break;
722     }
723
724     hTemp1->Sumw2();
725     hTemp2->Sumw2();
726     hTemp3->Sumw2();
727     hTemp4->Sumw2();
728     hTemp1Mix->Sumw2();
729     hTemp2Mix->Sumw2();
730     hTemp3Mix->Sumw2();
731     hTemp4Mix->Sumw2();
732
733     hTemp1->Scale(1./hTemp5->GetEntries());
734     hTemp3->Scale(1./hTemp5->GetEntries());
735     hTemp2->Scale(1./hTemp6->GetEntries());
736     hTemp4->Scale(1./hTemp6->GetEntries());
737     hTemp1Mix->Scale(1./hTemp5Mix->GetEntries());
738     hTemp3Mix->Scale(1./hTemp5Mix->GetEntries());
739     hTemp2Mix->Scale(1./hTemp6Mix->GetEntries());
740     hTemp4Mix->Scale(1./hTemp6Mix->GetEntries());
741
742     hTemp1->Divide(hTemp1Mix);
743     hTemp2->Divide(hTemp2Mix);
744     hTemp3->Divide(hTemp3Mix);
745     hTemp4->Divide(hTemp4Mix);
746
747     hTemp1->Add(hTemp3,-1.);
748     hTemp2->Add(hTemp4,-1.);
749
750     gHistBalanceFunctionHistogram->Add(hTemp1,hTemp2,1.,1.);
751     gHistBalanceFunctionHistogram->Scale(0.5);
752
753     //normalize to bin width
754     gHistBalanceFunctionHistogram->Scale(1./((Double_t)gHistBalanceFunctionHistogram->GetXaxis()->GetBinWidth(1)*(Double_t)gHistBalanceFunctionHistogram->GetYaxis()->GetBinWidth(1)));
755   }
756
757   return gHistBalanceFunctionHistogram;
758 }
759
760 //____________________________________________________________________//
761 TH2D *AliBalancePsi::GetBalanceFunctionDeltaEtaDeltaPhi(Double_t psiMin, 
762                                                         Double_t psiMax,
763                                                         Double_t ptTriggerMin,
764                                                         Double_t ptTriggerMax,
765                                                         Double_t ptAssociatedMin,
766                                                         Double_t ptAssociatedMax) {
767   //Returns the BF histogram in Delta eta vs Delta phi, 
768   //extracted from the 6 AliTHn objects 
769   //(private members) of the AliBalancePsi class.
770   //iVariableSingle: 0(phi-Psi), 1(pt-trigger)
771   //iVariablePair: 0(phi-Psi) 1(Delta eta), 2(Delta phi), 3(pt-trigger), 4(pt-associated
772   TString histName = "gHistBalanceFunctionHistogram2D";
773
774   // Psi_2
775   fHistP->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
776   fHistN->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
777   fHistPN->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
778   fHistNP->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
779   fHistPP->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
780   fHistNN->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
781
782   // pt trigger
783   if((ptTriggerMin != -1.)&&(ptTriggerMax != -1.)) {
784     fHistP->GetGrid(0)->GetGrid()->GetAxis(1)->SetRangeUser(ptTriggerMin,ptTriggerMax);
785     fHistN->GetGrid(0)->GetGrid()->GetAxis(1)->SetRangeUser(ptTriggerMin,ptTriggerMax);
786     fHistPN->GetGrid(0)->GetGrid()->GetAxis(3)->SetRangeUser(ptTriggerMin,ptTriggerMax);
787     fHistNP->GetGrid(0)->GetGrid()->GetAxis(3)->SetRangeUser(ptTriggerMin,ptTriggerMax);
788     fHistPP->GetGrid(0)->GetGrid()->GetAxis(3)->SetRangeUser(ptTriggerMin,ptTriggerMax);
789     fHistNN->GetGrid(0)->GetGrid()->GetAxis(3)->SetRangeUser(ptTriggerMin,ptTriggerMax);
790   }
791
792   // pt associated
793   if((ptAssociatedMin != -1.)&&(ptAssociatedMax != -1.)) {
794     fHistPN->GetGrid(0)->GetGrid()->GetAxis(4)->SetRangeUser(ptAssociatedMin,ptAssociatedMax);
795     fHistNP->GetGrid(0)->GetGrid()->GetAxis(4)->SetRangeUser(ptAssociatedMin,ptAssociatedMax);
796     fHistPP->GetGrid(0)->GetGrid()->GetAxis(4)->SetRangeUser(ptAssociatedMin,ptAssociatedMax);
797     fHistNN->GetGrid(0)->GetGrid()->GetAxis(4)->SetRangeUser(ptAssociatedMin,ptAssociatedMax);
798   }
799
800   //AliInfo(Form("P:%lf - N:%lf - PN:%lf - NP:%lf - PP:%lf - NN:%lf",fHistP->GetEntries(0),fHistN->GetEntries(0),fHistPN->GetEntries(0),fHistNP->GetEntries(0),fHistPP->GetEntries(0),fHistNN->GetEntries(0)));
801
802   // Project into the wanted space (1st: analysis step, 2nd: axis)
803   TH2D* hTemp1 = (TH2D*)fHistPN->Project(0,1,2);
804   TH2D* hTemp2 = (TH2D*)fHistNP->Project(0,1,2);
805   TH2D* hTemp3 = (TH2D*)fHistPP->Project(0,1,2);
806   TH2D* hTemp4 = (TH2D*)fHistNN->Project(0,1,2);
807   TH1D* hTemp5 = (TH1D*)fHistP->Project(0,1);
808   TH1D* hTemp6 = (TH1D*)fHistN->Project(0,1);
809
810   TH2D *gHistBalanceFunctionHistogram = 0x0;
811   if((hTemp1)&&(hTemp2)&&(hTemp3)&&(hTemp4)&&(hTemp5)&&(hTemp6)) {
812     gHistBalanceFunctionHistogram = (TH2D*)hTemp1->Clone();
813     gHistBalanceFunctionHistogram->Reset();
814     gHistBalanceFunctionHistogram->GetXaxis()->SetTitle("#Delta#eta");   
815     gHistBalanceFunctionHistogram->GetYaxis()->SetTitle("#Delta#varphi (rad)");
816     gHistBalanceFunctionHistogram->GetZaxis()->SetTitle("B(#Delta#eta,#Delta#varphi)");   
817     
818     hTemp1->Sumw2();
819     hTemp2->Sumw2();
820     hTemp3->Sumw2();
821     hTemp4->Sumw2();
822     hTemp1->Add(hTemp3,-1.);
823     hTemp1->Scale(1./hTemp5->GetEntries());
824     hTemp2->Add(hTemp4,-1.);
825     hTemp2->Scale(1./hTemp6->GetEntries());
826     gHistBalanceFunctionHistogram->Add(hTemp1,hTemp2,1.,1.);
827     gHistBalanceFunctionHistogram->Scale(0.5);
828
829     //normalize to bin width
830     gHistBalanceFunctionHistogram->Scale(1./((Double_t)gHistBalanceFunctionHistogram->GetXaxis()->GetBinWidth(1)*(Double_t)gHistBalanceFunctionHistogram->GetYaxis()->GetBinWidth(1)));
831   }
832
833   return gHistBalanceFunctionHistogram;
834 }
835
836 //____________________________________________________________________//
837 TH2D *AliBalancePsi::GetBalanceFunctionDeltaEtaDeltaPhi2pMethod(Double_t psiMin, 
838                                                                 Double_t psiMax,
839                                                                 Double_t ptTriggerMin,
840                                                                 Double_t ptTriggerMax,
841                                                                 Double_t ptAssociatedMin,
842                                                                 Double_t ptAssociatedMax,
843                                                                 AliBalancePsi *bfMix) {
844   //Returns the BF histogram in Delta eta vs Delta phi,
845   //after dividing each correlation function by the Event Mixing one 
846   //extracted from the 6 AliTHn objects 
847   //(private members) of the AliBalancePsi class.
848   //iVariableSingle: 0(phi-Psi), 1(pt-trigger)
849   //iVariablePair: 0(phi-Psi) 1(Delta eta), 2(Delta phi), 3(pt-trigger), 4(pt-associated
850   TString histName = "gHistBalanceFunctionHistogram2D";
851
852   if(!bfMix){
853     AliError("balance function object for event mixing not available");
854     return NULL;
855   }
856
857   // Psi_2
858   fHistP->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
859   fHistN->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
860   fHistPN->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
861   fHistNP->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
862   fHistPP->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
863   fHistNN->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
864
865   // pt trigger
866   if((ptTriggerMin != -1.)&&(ptTriggerMax != -1.)) {
867     fHistP->GetGrid(0)->GetGrid()->GetAxis(1)->SetRangeUser(ptTriggerMin,ptTriggerMax);
868     fHistN->GetGrid(0)->GetGrid()->GetAxis(1)->SetRangeUser(ptTriggerMin,ptTriggerMax);
869     fHistPN->GetGrid(0)->GetGrid()->GetAxis(3)->SetRangeUser(ptTriggerMin,ptTriggerMax);
870     fHistNP->GetGrid(0)->GetGrid()->GetAxis(3)->SetRangeUser(ptTriggerMin,ptTriggerMax);
871     fHistPP->GetGrid(0)->GetGrid()->GetAxis(3)->SetRangeUser(ptTriggerMin,ptTriggerMax);
872     fHistNN->GetGrid(0)->GetGrid()->GetAxis(3)->SetRangeUser(ptTriggerMin,ptTriggerMax);
873   }
874
875   // pt associated
876   if((ptAssociatedMin != -1.)&&(ptAssociatedMax != -1.)) {
877     fHistPN->GetGrid(0)->GetGrid()->GetAxis(4)->SetRangeUser(ptAssociatedMin,ptAssociatedMax);
878     fHistNP->GetGrid(0)->GetGrid()->GetAxis(4)->SetRangeUser(ptAssociatedMin,ptAssociatedMax);
879     fHistPP->GetGrid(0)->GetGrid()->GetAxis(4)->SetRangeUser(ptAssociatedMin,ptAssociatedMax);
880     fHistNN->GetGrid(0)->GetGrid()->GetAxis(4)->SetRangeUser(ptAssociatedMin,ptAssociatedMax);
881   }
882
883
884   // ============================================================================================
885   // the same for event mixing
886   AliTHn *fHistPMix = bfMix->GetHistNp();
887   AliTHn *fHistNMix = bfMix->GetHistNn();
888   AliTHn *fHistPNMix = bfMix->GetHistNpn();
889   AliTHn *fHistNPMix = bfMix->GetHistNnp();
890   AliTHn *fHistPPMix = bfMix->GetHistNpp();
891   AliTHn *fHistNNMix = bfMix->GetHistNnn();
892
893   // Psi_2
894   fHistPMix->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
895   fHistNMix->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
896   fHistPNMix->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
897   fHistNPMix->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
898   fHistPPMix->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
899   fHistNNMix->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
900
901   // pt trigger
902   if((ptTriggerMin != -1.)&&(ptTriggerMax != -1.)) {
903     fHistPMix->GetGrid(0)->GetGrid()->GetAxis(1)->SetRangeUser(ptTriggerMin,ptTriggerMax);
904     fHistNMix->GetGrid(0)->GetGrid()->GetAxis(1)->SetRangeUser(ptTriggerMin,ptTriggerMax);
905     fHistPNMix->GetGrid(0)->GetGrid()->GetAxis(3)->SetRangeUser(ptTriggerMin,ptTriggerMax);
906     fHistNPMix->GetGrid(0)->GetGrid()->GetAxis(3)->SetRangeUser(ptTriggerMin,ptTriggerMax);
907     fHistPPMix->GetGrid(0)->GetGrid()->GetAxis(3)->SetRangeUser(ptTriggerMin,ptTriggerMax);
908     fHistNNMix->GetGrid(0)->GetGrid()->GetAxis(3)->SetRangeUser(ptTriggerMin,ptTriggerMax);
909   }
910
911   // pt associated
912   if((ptAssociatedMin != -1.)&&(ptAssociatedMax != -1.)) {
913     fHistPNMix->GetGrid(0)->GetGrid()->GetAxis(4)->SetRangeUser(ptAssociatedMin,ptAssociatedMax);
914     fHistNPMix->GetGrid(0)->GetGrid()->GetAxis(4)->SetRangeUser(ptAssociatedMin,ptAssociatedMax);
915     fHistPPMix->GetGrid(0)->GetGrid()->GetAxis(4)->SetRangeUser(ptAssociatedMin,ptAssociatedMax);
916     fHistNNMix->GetGrid(0)->GetGrid()->GetAxis(4)->SetRangeUser(ptAssociatedMin,ptAssociatedMax);
917   }
918   // ============================================================================================
919
920
921   //AliInfo(Form("P:%lf - N:%lf - PN:%lf - NP:%lf - PP:%lf - NN:%lf",fHistP->GetEntries(0),fHistN->GetEntries(0),fHistPN->GetEntries(0),fHistNP->GetEntries(0),fHistPP->GetEntries(0),fHistNN->GetEntries(0)));
922
923   // Project into the wanted space (1st: analysis step, 2nd: axis)
924   TH2D* hTemp1 = (TH2D*)fHistPN->Project(0,1,2);
925   TH2D* hTemp2 = (TH2D*)fHistNP->Project(0,1,2);
926   TH2D* hTemp3 = (TH2D*)fHistPP->Project(0,1,2);
927   TH2D* hTemp4 = (TH2D*)fHistNN->Project(0,1,2);
928   TH1D* hTemp5 = (TH1D*)fHistP->Project(0,1);
929   TH1D* hTemp6 = (TH1D*)fHistN->Project(0,1);
930
931   // ============================================================================================
932   // the same for event mixing
933   TH2D* hTemp1Mix = (TH2D*)fHistPNMix->Project(0,1,2);
934   TH2D* hTemp2Mix = (TH2D*)fHistNPMix->Project(0,1,2);
935   TH2D* hTemp3Mix = (TH2D*)fHistPPMix->Project(0,1,2);
936   TH2D* hTemp4Mix = (TH2D*)fHistNNMix->Project(0,1,2);
937   TH1D* hTemp5Mix = (TH1D*)fHistPMix->Project(0,1);
938   TH1D* hTemp6Mix = (TH1D*)fHistNMix->Project(0,1);
939   // ============================================================================================
940
941   TH2D *gHistBalanceFunctionHistogram = 0x0;
942   if((hTemp1)&&(hTemp2)&&(hTemp3)&&(hTemp4)&&(hTemp5)&&(hTemp6)) {
943     gHistBalanceFunctionHistogram = (TH2D*)hTemp1->Clone();
944     gHistBalanceFunctionHistogram->Reset();
945     gHistBalanceFunctionHistogram->GetXaxis()->SetTitle("#Delta#eta");   
946     gHistBalanceFunctionHistogram->GetYaxis()->SetTitle("#Delta#varphi (rad)");
947     gHistBalanceFunctionHistogram->GetZaxis()->SetTitle("B(#Delta#eta,#Delta#varphi)");   
948     
949     hTemp1->Sumw2();
950     hTemp2->Sumw2();
951     hTemp3->Sumw2();
952     hTemp4->Sumw2();
953     hTemp1Mix->Sumw2();
954     hTemp2Mix->Sumw2();
955     hTemp3Mix->Sumw2();
956     hTemp4Mix->Sumw2();
957
958     hTemp1->Scale(1./hTemp5->GetEntries());
959     hTemp3->Scale(1./hTemp5->GetEntries());
960     hTemp2->Scale(1./hTemp6->GetEntries());
961     hTemp4->Scale(1./hTemp6->GetEntries());
962     hTemp1Mix->Scale(1./hTemp5Mix->GetEntries());
963     hTemp3Mix->Scale(1./hTemp5Mix->GetEntries());
964     hTemp2Mix->Scale(1./hTemp6Mix->GetEntries());
965     hTemp4Mix->Scale(1./hTemp6Mix->GetEntries());
966
967     hTemp1->Divide(hTemp1Mix);
968     hTemp2->Divide(hTemp2Mix);
969     hTemp3->Divide(hTemp3Mix);
970     hTemp4->Divide(hTemp4Mix);
971
972     hTemp1->Add(hTemp3,-1.);
973     hTemp2->Add(hTemp4,-1.);
974
975     gHistBalanceFunctionHistogram->Add(hTemp1,hTemp2,1.,1.);
976     gHistBalanceFunctionHistogram->Scale(0.5);
977   
978     //normalize to bin width
979     gHistBalanceFunctionHistogram->Scale(1./((Double_t)gHistBalanceFunctionHistogram->GetXaxis()->GetBinWidth(1)*(Double_t)gHistBalanceFunctionHistogram->GetYaxis()->GetBinWidth(1)));
980   }
981
982   return gHistBalanceFunctionHistogram;
983 }
984
985
986 //____________________________________________________________________//
987 TH2D *AliBalancePsi::GetCorrelationFunctionPN(Double_t psiMin, 
988                                               Double_t psiMax,
989                                               Double_t ptTriggerMin,
990                                               Double_t ptTriggerMax,
991                                               Double_t ptAssociatedMin,
992                                               Double_t ptAssociatedMax) {
993   //Returns the 2D correlation function for (+-) pairs
994   // Psi_2: axis 0
995   fHistP->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
996   fHistPN->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
997
998   // pt trigger
999   if((ptTriggerMin != -1.)&&(ptTriggerMax != -1.)) {
1000     fHistP->GetGrid(0)->GetGrid()->GetAxis(1)->SetRangeUser(ptTriggerMin,ptTriggerMax);
1001     fHistPN->GetGrid(0)->GetGrid()->GetAxis(3)->SetRangeUser(ptTriggerMin,ptTriggerMax);
1002   }
1003
1004   // pt associated
1005   if((ptAssociatedMin != -1.)&&(ptAssociatedMax != -1.))
1006     fHistPN->GetGrid(0)->GetGrid()->GetAxis(4)->SetRangeUser(ptAssociatedMin,ptAssociatedMax);
1007
1008   //fHistP->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(-0.5,2.5); 
1009   //fHistPN->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(-0.5,2.5); 
1010
1011   //TH2D *gHistTest = dynamic_cast<TH2D *>(fHistP->Project(0,0,1));
1012   //TCanvas *c1 = new TCanvas("c1","");
1013   //c1->cd();
1014   //if(!gHistTest){
1015   //AliError("Projection of fHistP = NULL");
1016   //return gHistTest;
1017   //}
1018   //else{
1019   //gHistTest->DrawCopy("colz");
1020   //}
1021
1022   //0:step, 1: Delta eta, 2: Delta phi
1023   TH2D *gHist = dynamic_cast<TH2D *>(fHistPN->Project(0,1,2));
1024   if(!gHist){
1025     AliError("Projection of fHistPN = NULL");
1026     return gHist;
1027   }
1028
1029   //AliInfo(Form("Entries (test): %lf",(Double_t)(gHistTest->GetEntries())));
1030   //AliInfo(Form("Entries (1D): %lf",(Double_t)(fHistP->Project(0,1)->GetEntries())));
1031   //AliInfo(Form("Entries (2D): %lf",(Double_t)(fHistPN->Project(0,1,2)->GetEntries())));
1032   
1033   //TCanvas *c2 = new TCanvas("c2","");
1034   //c2->cd();
1035   //fHistPN->Project(0,1,2)->DrawCopy("colz");
1036
1037   if((Double_t)(fHistP->Project(0,1)->GetEntries())!=0)
1038     gHist->Scale(1./(Double_t)(fHistP->Project(0,1)->GetEntries()));
1039
1040   //normalize to bin width
1041   gHist->Scale(1./((Double_t)gHist->GetXaxis()->GetBinWidth(1)*(Double_t)gHist->GetYaxis()->GetBinWidth(1)));
1042     
1043   return gHist;
1044 }
1045
1046 //____________________________________________________________________//
1047 TH2D *AliBalancePsi::GetCorrelationFunctionNP(Double_t psiMin, 
1048                                               Double_t psiMax,
1049                                               Double_t ptTriggerMin,
1050                                               Double_t ptTriggerMax,
1051                                               Double_t ptAssociatedMin,
1052                                               Double_t ptAssociatedMax) {
1053   //Returns the 2D correlation function for (+-) pairs
1054   // Psi_2: axis 0
1055   fHistN->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
1056   fHistNP->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
1057     
1058   // pt trigger
1059   if((ptTriggerMin != -1.)&&(ptTriggerMax != -1.)) {
1060     fHistN->GetGrid(0)->GetGrid()->GetAxis(1)->SetRangeUser(ptTriggerMin,ptTriggerMax);
1061     fHistNP->GetGrid(0)->GetGrid()->GetAxis(3)->SetRangeUser(ptTriggerMin,ptTriggerMax);
1062   }
1063
1064   // pt associated
1065   if((ptAssociatedMin != -1.)&&(ptAssociatedMax != -1.))
1066     fHistNP->GetGrid(0)->GetGrid()->GetAxis(4)->SetRangeUser(ptAssociatedMin,ptAssociatedMax);
1067
1068   //0:step, 1: Delta eta, 2: Delta phi
1069   TH2D *gHist = dynamic_cast<TH2D *>(fHistNP->Project(0,1,2));
1070   if(!gHist){
1071     AliError("Projection of fHistPN = NULL");
1072     return gHist;
1073   }
1074
1075   //Printf("Entries (1D): %lf",(Double_t)(fHistN->Project(0,2)->GetEntries()));
1076   //Printf("Entries (2D): %lf",(Double_t)(fHistNP->Project(0,2,3)->GetEntries()));
1077   if((Double_t)(fHistN->Project(0,1)->GetEntries())!=0)
1078     gHist->Scale(1./(Double_t)(fHistN->Project(0,1)->GetEntries()));
1079
1080   //normalize to bin width
1081   gHist->Scale(1./((Double_t)gHist->GetXaxis()->GetBinWidth(1)*(Double_t)gHist->GetYaxis()->GetBinWidth(1)));
1082     
1083   return gHist;
1084 }
1085
1086 //____________________________________________________________________//
1087 TH2D *AliBalancePsi::GetCorrelationFunctionPP(Double_t psiMin, 
1088                                               Double_t psiMax,
1089                                               Double_t ptTriggerMin,
1090                                               Double_t ptTriggerMax,
1091                                               Double_t ptAssociatedMin,
1092                                               Double_t ptAssociatedMax) {
1093   //Returns the 2D correlation function for (+-) pairs
1094   // Psi_2: axis 0
1095   fHistP->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
1096   fHistPP->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
1097
1098   // pt trigger
1099   if((ptTriggerMin != -1.)&&(ptTriggerMax != -1.)) {
1100     fHistP->GetGrid(0)->GetGrid()->GetAxis(1)->SetRangeUser(ptTriggerMin,ptTriggerMax);
1101     fHistPP->GetGrid(0)->GetGrid()->GetAxis(3)->SetRangeUser(ptTriggerMin,ptTriggerMax);
1102   }
1103
1104   // pt associated
1105   if((ptAssociatedMin != -1.)&&(ptAssociatedMax != -1.))
1106     fHistPP->GetGrid(0)->GetGrid()->GetAxis(4)->SetRangeUser(ptAssociatedMin,ptAssociatedMax);
1107       
1108   //0:step, 1: Delta eta, 2: Delta phi
1109   TH2D *gHist = dynamic_cast<TH2D *>(fHistPP->Project(0,1,2));
1110   if(!gHist){
1111     AliError("Projection of fHistPN = NULL");
1112     return gHist;
1113   }
1114
1115   //Printf("Entries (1D): %lf",(Double_t)(fHistP->Project(0,2)->GetEntries()));
1116   //Printf("Entries (2D): %lf",(Double_t)(fHistPP->Project(0,2,3)->GetEntries()));
1117   if((Double_t)(fHistP->Project(0,1)->GetEntries())!=0)
1118     gHist->Scale(1./(Double_t)(fHistP->Project(0,1)->GetEntries()));
1119
1120   //normalize to bin width
1121   gHist->Scale(1./((Double_t)gHist->GetXaxis()->GetBinWidth(1)*(Double_t)gHist->GetYaxis()->GetBinWidth(1)));
1122   
1123   return gHist;
1124 }
1125
1126 //____________________________________________________________________//
1127 TH2D *AliBalancePsi::GetCorrelationFunctionNN(Double_t psiMin, 
1128                                               Double_t psiMax,
1129                                               Double_t ptTriggerMin,
1130                                               Double_t ptTriggerMax,
1131                                               Double_t ptAssociatedMin,
1132                                               Double_t ptAssociatedMax) {
1133   //Returns the 2D correlation function for (+-) pairs
1134   // Psi_2: axis 0
1135   fHistN->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
1136   fHistNN->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
1137
1138   // pt trigger
1139   if((ptTriggerMin != -1.)&&(ptTriggerMax != -1.)) {
1140     fHistN->GetGrid(0)->GetGrid()->GetAxis(1)->SetRangeUser(ptTriggerMin,ptTriggerMax);
1141     fHistNN->GetGrid(0)->GetGrid()->GetAxis(3)->SetRangeUser(ptTriggerMin,ptTriggerMax);
1142   }
1143
1144   // pt associated
1145   if((ptAssociatedMin != -1.)&&(ptAssociatedMax != -1.))
1146     fHistNN->GetGrid(0)->GetGrid()->GetAxis(4)->SetRangeUser(ptAssociatedMin,ptAssociatedMax);
1147     
1148   //0:step, 1: Delta eta, 2: Delta phi
1149   TH2D *gHist = dynamic_cast<TH2D *>(fHistNN->Project(0,1,2));
1150   if(!gHist){
1151     AliError("Projection of fHistPN = NULL");
1152     return gHist;
1153   }
1154
1155   //Printf("Entries (1D): %lf",(Double_t)(fHistN->Project(0,2)->GetEntries()));
1156   //Printf("Entries (2D): %lf",(Double_t)(fHistNN->Project(0,2,3)->GetEntries()));
1157   if((Double_t)(fHistN->Project(0,1)->GetEntries())!=0)
1158     gHist->Scale(1./(Double_t)(fHistN->Project(0,1)->GetEntries()));
1159
1160   //normalize to bin width
1161   gHist->Scale(1./((Double_t)gHist->GetXaxis()->GetBinWidth(1)*(Double_t)gHist->GetYaxis()->GetBinWidth(1)));
1162     
1163   return gHist;
1164 }
1165
1166 //____________________________________________________________________//
1167 TH2D *AliBalancePsi::GetCorrelationFunctionChargeIndependent(Double_t psiMin, 
1168                                                              Double_t psiMax,
1169                                                              Double_t ptTriggerMin,
1170                                                              Double_t ptTriggerMax,
1171                                                              Double_t ptAssociatedMin,
1172                                                              Double_t ptAssociatedMax) {
1173   //Returns the 2D correlation function for the sum of all charge combination pairs
1174   // Psi_2: axis 0
1175   fHistN->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
1176   fHistP->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
1177   fHistNN->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
1178   fHistPP->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
1179   fHistNP->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
1180   fHistPN->GetGrid(0)->GetGrid()->GetAxis(0)->SetRangeUser(psiMin,psiMax); 
1181
1182   // pt trigger
1183   if((ptTriggerMin != -1.)&&(ptTriggerMax != -1.)) {
1184     fHistN->GetGrid(0)->GetGrid()->GetAxis(1)->SetRangeUser(ptTriggerMin,ptTriggerMax);
1185     fHistP->GetGrid(0)->GetGrid()->GetAxis(1)->SetRangeUser(ptTriggerMin,ptTriggerMax);
1186     fHistNN->GetGrid(0)->GetGrid()->GetAxis(3)->SetRangeUser(ptTriggerMin,ptTriggerMax);
1187     fHistPP->GetGrid(0)->GetGrid()->GetAxis(3)->SetRangeUser(ptTriggerMin,ptTriggerMax);
1188     fHistNP->GetGrid(0)->GetGrid()->GetAxis(3)->SetRangeUser(ptTriggerMin,ptTriggerMax);
1189     fHistPN->GetGrid(0)->GetGrid()->GetAxis(3)->SetRangeUser(ptTriggerMin,ptTriggerMax);
1190   }
1191
1192   // pt associated
1193   if((ptAssociatedMin != -1.)&&(ptAssociatedMax != -1.))
1194     fHistNN->GetGrid(0)->GetGrid()->GetAxis(4)->SetRangeUser(ptAssociatedMin,ptAssociatedMax);
1195     fHistPP->GetGrid(0)->GetGrid()->GetAxis(4)->SetRangeUser(ptAssociatedMin,ptAssociatedMax);
1196     fHistNP->GetGrid(0)->GetGrid()->GetAxis(4)->SetRangeUser(ptAssociatedMin,ptAssociatedMax);
1197     fHistPN->GetGrid(0)->GetGrid()->GetAxis(4)->SetRangeUser(ptAssociatedMin,ptAssociatedMax);
1198     
1199   //0:step, 1: Delta eta, 2: Delta phi
1200   TH2D *gHistNN = dynamic_cast<TH2D *>(fHistNN->Project(0,1,2));
1201   if(!gHistNN){
1202     AliError("Projection of fHistNN = NULL");
1203     return gHistNN;
1204   }
1205   TH2D *gHistPP = dynamic_cast<TH2D *>(fHistPP->Project(0,1,2));
1206   if(!gHistPP){
1207     AliError("Projection of fHistPP = NULL");
1208     return gHistPP;
1209   }
1210   TH2D *gHistNP = dynamic_cast<TH2D *>(fHistNP->Project(0,1,2));
1211   if(!gHistNP){
1212     AliError("Projection of fHistNP = NULL");
1213     return gHistNP;
1214   }
1215   TH2D *gHistPN = dynamic_cast<TH2D *>(fHistPN->Project(0,1,2));
1216   if(!gHistPN){
1217     AliError("Projection of fHistPN = NULL");
1218     return gHistPN;
1219   }
1220
1221   // sum all 2 particle histograms
1222   gHistNN->Add(gHistPP);
1223   gHistNN->Add(gHistNP);
1224   gHistNN->Add(gHistPN);
1225
1226   // divide by sum of + and - triggers
1227   if((Double_t)(fHistN->Project(0,1)->GetEntries())!=0 && (Double_t)(fHistP->Project(0,1)->GetEntries())!=0)
1228     gHistNN->Scale(1./(Double_t)(fHistN->Project(0,1)->GetEntries() + fHistN->Project(0,1)->GetEntries()));
1229
1230   //normalize to bin width
1231   gHistNN->Scale(1./((Double_t)gHistNN->GetXaxis()->GetBinWidth(1)*(Double_t)gHistNN->GetYaxis()->GetBinWidth(1)));
1232   
1233   return gHistNN;
1234 }
1235
1236 //____________________________________________________________________//
1237 Float_t AliBalancePsi::GetDPhiStar(Float_t phi1, Float_t pt1, Float_t charge1, Float_t phi2, Float_t pt2, Float_t charge2, Float_t radius, Float_t bSign) { 
1238   //
1239   // calculates dphistar
1240   //
1241   Float_t dphistar = phi1 - phi2 - charge1 * bSign * TMath::ASin(0.075 * radius / pt1) + charge2 * bSign * TMath::ASin(0.075 * radius / pt2);
1242   
1243   static const Double_t kPi = TMath::Pi();
1244   
1245   // circularity
1246 //   if (dphistar > 2 * kPi)
1247 //     dphistar -= 2 * kPi;
1248 //   if (dphistar < -2 * kPi)
1249 //     dphistar += 2 * kPi;
1250   
1251   if (dphistar > kPi)
1252     dphistar = kPi * 2 - dphistar;
1253   if (dphistar < -kPi)
1254     dphistar = -kPi * 2 - dphistar;
1255   if (dphistar > kPi) // might look funny but is needed
1256     dphistar = kPi * 2 - dphistar;
1257   
1258   return dphistar;
1259 }
1260