]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGCF/Correlations/Base/AliUEHistograms.cxx
2+1 correlation analysis (Markus)
[u/mrichter/AliRoot.git] / PWGCF / Correlations / Base / AliUEHistograms.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id: AliUEHistograms.cxx 20164 2007-08-14 15:31:50Z morsch $ */
17
18 //
19 //
20 // encapsulates several AliUEHist objects for a full UE analysis plus additional control histograms
21 //
22 //
23 // Author: Jan Fiete Grosse-Oetringhaus, Sara Vallero
24
25 #include "AliUEHistograms.h"
26
27 #include "AliCFContainer.h"
28 #include "AliVParticle.h"
29 #include "AliAODTrack.h"
30
31 #include "TList.h"
32 #include "TCanvas.h"
33 #include "TH2F.h"
34 #include "TH1F.h"
35 #include "TH3F.h"
36 #include "TMath.h"
37 #include "TLorentzVector.h"
38
39 ClassImp(AliUEHistograms)
40
41 const Int_t AliUEHistograms::fgkUEHists = 3;
42
43 AliUEHistograms::AliUEHistograms(const char* name, const char* histograms, const char* binning) : 
44   TNamed(name, name),
45   fNumberDensitypT(0),
46   fSumpT(0),
47   fNumberDensityPhi(0),
48   fCorrelationpT(0),
49   fCorrelationEta(0),
50   fCorrelationPhi(0),
51   fCorrelationR(0),
52   fCorrelationLeading2Phi(0),
53   fCorrelationMultiplicity(0),
54   fYields(0),
55   fInvYield2(0),
56   fEventCount(0),
57   fEventCountDifferential(0),
58   fVertexContributors(0),
59   fCentralityDistribution(0),
60   fCentralityCorrelation(0),
61   fITSClusterMap(0),
62   fControlConvResoncances(0),
63   fEfficiencyCorrectionTriggers(0),
64   fEfficiencyCorrectionAssociated(0),
65   fSelectCharge(0),
66   fTriggerSelectCharge(0),
67   fAssociatedSelectCharge(0),
68   fTriggerRestrictEta(-1),
69   fEtaOrdering(kFALSE),
70   fCutConversions(kFALSE),
71   fCutResonances(kFALSE),
72   fRejectResonanceDaughters(-1),
73   fOnlyOneEtaSide(0),
74   fWeightPerEvent(kFALSE),
75   fPtOrder(kTRUE),
76   fTwoTrackCutMinRadius(0.8),
77   fRunNumber(0),
78   fMergeCount(1)
79 {
80   // Constructor
81   //
82   // the string histograms defines which histograms are created:
83   //    1 = NumberDensitypT
84   //    2 = SumpT
85   //    3 = NumberDensityPhi
86   //    4 = NumberDensityPhiCentrality (other multiplicity for Pb)
87   
88   AliLog::SetClassDebugLevel("AliCFContainer", -1);
89   AliLog::SetClassDebugLevel("AliCFGridSparse", -3);
90
91   fTwoTrackDistancePt[0] = 0;
92   fTwoTrackDistancePt[1] = 0;
93   
94   TString histogramsStr(histograms);
95   
96   TString defaultBinningStr;
97   defaultBinningStr = "eta: -1.0, -0.9, -0.8, -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, 0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0\n"
98     "p_t_assoc: 0.5, 0.75, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 8.0\n"
99     "p_t_leading: 0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5, 7.0, 7.5, 8.0, 8.5, 9.0, 9.5, 10.0, 10.5, 11.0, 11.5, 12.0, 12.5, 13.0, 13.5, 14.0, 14.5, 15.0, 15.5, 16.0, 16.5, 17.0, 17.5, 18.0, 18.5, 19.0, 19.5, 20.0, 20.5, 21.0, 21.5, 22.0, 22.5, 23.0, 23.5, 24.0, 24.5, 25.0, 25.5, 26.0, 26.5, 27.0, 27.5, 28.0, 28.5, 29.0, 29.5, 30.0, 30.5, 31.0, 31.5, 32.0, 32.5, 33.0, 33.5, 34.0, 34.5, 35.0, 35.5, 36.0, 36.5, 37.0, 37.5, 38.0, 38.5, 39.0, 39.5, 40.0, 40.5, 41.0, 41.5, 42.0, 42.5, 43.0, 43.5, 44.0, 44.5, 45.0, 45.5, 46.0, 46.5, 47.0, 47.5, 48.0, 48.5, 49.0, 49.5, 50.0\n"
100     "p_t_leading_course: 0.5, 1.0, 2.0, 3.0, 4.0, 6.0, 8.0\n"
101     "p_t_eff: 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.25, 1.5, 1.75, 2.0, 2.25, 2.5, 2.75, 3.0, 3.25, 3.5, 3.75, 4.0, 4.5, 5.0, 6.0, 7.0, 8.0\n"
102     "vertex_eff: -10, -8, -6, -4, -2, 0, 2, 4, 6, 8, 10\n"
103   ;
104
105   if (histogramsStr.Contains("4") || histogramsStr.Contains("5") || histogramsStr.Contains("6")) // Dphi Corr
106   {
107     if (histogramsStr.Contains("C"))
108       defaultBinningStr += "multiplicity: 0, 20, 40, 60, 80, 100.1\n"; // course
109     else
110       defaultBinningStr += "multiplicity: 0, 1, 2, 3, 4, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100.1\n";
111
112     if (histogramsStr.Contains("5"))
113       defaultBinningStr += "vertex: -7, -5, -3, -1, 1, 3, 5, 7\n";
114     else
115       defaultBinningStr += "vertex: -10, -8, -6, -4, -2, 0, 2, 4, 6, 8, 10\n";
116     
117     if (histogramsStr.Contains("R"))
118       defaultBinningStr += "delta_phi: -1.570796, -1.483530, -1.396263, -1.308997, -1.221730, -1.134464, -1.047198, -0.959931, -0.872665, -0.785398, -0.698132, -0.610865, -0.523599, -0.436332, -0.349066, -0.261799, -0.174533, -0.087266, 0.0, 0.087266, 0.174533, 0.261799, 0.349066, 0.436332, 0.523599, 0.610865, 0.698132, 0.785398, 0.872665, 0.959931, 1.047198, 1.134464, 1.221730, 1.308997, 1.396263, 1.483530, 1.570796, 1.658063, 1.745329, 1.832596, 1.919862, 2.007129, 2.094395, 2.181662, 2.268928, 2.356194, 2.443461, 2.530727, 2.617994, 2.705260, 2.792527, 2.879793, 2.967060, 3.054326, 3.141593, 3.228859, 3.316126, 3.403392, 3.490659, 3.577925, 3.665191, 3.752458, 3.839724, 3.926991, 4.014257, 4.101524, 4.188790, 4.276057, 4.363323, 4.450590, 4.537856, 4.625123, 4.712389\n" // this binning starts at -pi/2 and is modulo 3 
119         "delta_eta: -2.4, -2.3, -2.2, -2.1, -2.0, -1.9, -1.8, -1.7, -1.6, -1.5, -1.4, -1.3, -1.2, -1.1, -1.0, -0.9, -0.8, -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, 0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0,2.1, 2.2, 2.3, 2.4\n"
120       ;
121     else // for TTR studies
122       defaultBinningStr += "delta_phi: -1.570796, -1.483530, -1.396263, -1.308997, -1.221730, -1.134464, -1.047198, -0.959931, -0.872665, -0.785398, -0.698132, -0.610865, -0.523599, -0.436332, -0.349066, -0.261799, -0.174533, -0.087266, -0.043633, -0.021817, 0.0, 0.021817, 0.043633, 0.087266, 0.174533, 0.261799, 0.349066, 0.436332, 0.523599, 0.610865, 0.698132, 0.785398, 0.872665, 0.959931, 1.047198, 1.134464, 1.221730, 1.308997, 1.396263, 1.483530, 1.570796, 1.658063, 1.745329, 1.832596, 1.919862, 2.007129, 2.094395, 2.181662, 2.268928, 2.356194, 2.443461, 2.530727, 2.617994, 2.705260, 2.792527, 2.879793, 2.967060, 3.054326, 3.141593, 3.228859, 3.316126, 3.403392, 3.490659, 3.577925, 3.665191, 3.752458, 3.839724, 3.926991, 4.014257, 4.101524, 4.188790, 4.276057, 4.363323, 4.450590, 4.537856, 4.625123, 4.712389\n"
123         "delta_eta: -2.0, -1.9, -1.8, -1.7, -1.6, -1.5, -1.4, -1.3, -1.2, -1.1, -1.0, -0.9, -0.8, -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, -0.05, -0.025, 0, 0.025, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0\n"
124       ;
125   }
126   else // UE
127     defaultBinningStr += "multiplicity: -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 200.0\n"
128       "delta_phi: -1.570796, -1.483530, -1.396263, -1.308997, -1.221730, -1.134464, -1.047198, -0.959931, -0.872665, -0.785398, -0.698132, -0.610865, -0.523599, -0.436332, -0.349066, -0.261799, -0.174533, -0.087266, 0.0, 0.087266, 0.174533, 0.261799, 0.349066, 0.436332, 0.523599, 0.610865, 0.698132, 0.785398, 0.872665, 0.959931, 1.047198, 1.134464, 1.221730, 1.308997, 1.396263, 1.483530, 1.570796, 1.658063, 1.745329, 1.832596, 1.919862, 2.007129, 2.094395, 2.181662, 2.268928, 2.356194, 2.443461, 2.530727, 2.617994, 2.705260, 2.792527, 2.879793, 2.967060, 3.054326, 3.141593, 3.228859, 3.316126, 3.403392, 3.490659, 3.577925, 3.665191, 3.752458, 3.839724, 3.926991, 4.014257, 4.101524, 4.188790, 4.276057, 4.363323, 4.450590, 4.537856, 4.625123, 4.712389\n"
129       "vertex: -10, -8, -6, -4, -2, 0, 2, 4, 6, 8, 10\n"
130     ;
131
132   // combine customBinning with defaultBinningStr -> use customBinning where available and otherwise defaultBinningStr
133   TString binningStr = AliUEHist::CombineBinning(defaultBinningStr, TString(binning));
134
135   if (histogramsStr.Contains("1"))
136     fNumberDensitypT = new AliUEHist("NumberDensitypT", binningStr);
137   if (histogramsStr.Contains("2"))
138     fSumpT = new AliUEHist("SumpT", binningStr);
139   
140   if (histogramsStr.Contains("3"))
141     fNumberDensityPhi = new AliUEHist("NumberDensityPhi", binningStr);
142   else if (histogramsStr.Contains("4"))
143     fNumberDensityPhi = new AliUEHist("NumberDensityPhiCentrality", binningStr);
144   else if (histogramsStr.Contains("5") || histogramsStr.Contains("6"))
145     fNumberDensityPhi = new AliUEHist("NumberDensityPhiCentralityVtx", binningStr);
146   
147   // do not add this hists to the directory
148   Bool_t oldStatus = TH1::AddDirectoryStatus();
149   TH1::AddDirectory(kFALSE);
150   
151   if (!histogramsStr.Contains("4") && !histogramsStr.Contains("5") && !histogramsStr.Contains("6"))
152   {
153     fCorrelationpT  = new TH2F("fCorrelationpT", ";p_{T,lead} (MC);p_{T,lead} (RECO)", 200, 0, 50, 200, 0, 50);
154     fCorrelationEta = new TH2F("fCorrelationEta", ";#eta_{lead} (MC);#eta_{T,lead} (RECO)", 200, -1, 1, 200, -1, 1);
155     fCorrelationPhi = new TH2F("fCorrelationPhi", ";#varphi_{lead} (MC);#varphi_{T,lead} (RECO)", 200, 0, TMath::TwoPi(), 200, 0, TMath::TwoPi());
156   }
157   else
158   {
159     fCorrelationpT  = new TH2F("fCorrelationpT", ";Centrality;p_{T} (RECO)", 100, 0, 100.001, 200, 0, 50);
160     fCorrelationEta = new TH2F("fCorrelationEta", ";Centrality;#eta (RECO)", 100, 0, 100.001, 200, -5, 5);
161     fCorrelationPhi = new TH2F("fCorrelationPhi", ";Centrality;#varphi (RECO)", 100, 0, 100.001, 200, 0, TMath::TwoPi());
162   }
163   
164   fCorrelationR =   new TH2F("fCorrelationR", ";R;p_{T,lead} (MC)", 200, 0, 2, 200, 0, 50);
165   fCorrelationLeading2Phi = new TH2F("fCorrelationLeading2Phi", ";#Delta #varphi;p_{T,lead} (MC)", 200, -TMath::Pi(), TMath::Pi(), 200, 0, 50);
166   fCorrelationMultiplicity = new TH2F("fCorrelationMultiplicity", ";MC tracks;Reco tracks", 100, -0.5, 99.5, 100, -0.5, 99.5);
167   fYields = new TH3F("fYields", ";centrality;pT;eta", 100, 0, 100, 40, 0, 20, 100, -1, 1);
168   fInvYield2 = new TH2F("fInvYield2", ";centrality;pT;1/pT dNch/dpT", 100, 0, 100, 80, 0, 20);
169
170   if (!histogramsStr.Contains("4") && !histogramsStr.Contains("5") && !histogramsStr.Contains("6"))
171   {
172     fEventCount = new TH2F("fEventCount", ";step;event type;count", AliUEHist::fgkCFSteps+2, -2.5, -0.5 + AliUEHist::fgkCFSteps, 3, -0.5, 2.5);
173     fEventCount->GetYaxis()->SetBinLabel(1, "ND");
174     fEventCount->GetYaxis()->SetBinLabel(2, "SD");
175     fEventCount->GetYaxis()->SetBinLabel(3, "DD");
176   }
177   else
178   {
179     fEventCount = new TH2F("fEventCount", ";step;centrality;count", AliUEHist::fgkCFSteps+2, -2.5, -0.5 + AliUEHist::fgkCFSteps, fNumberDensityPhi->GetEventHist()->GetNBins(1), fNumberDensityPhi->GetEventHist()->GetAxis(1, 0)->GetXbins()->GetArray());
180   }
181   
182   fEventCountDifferential = new TH3F("fEventCountDifferential", ";p_{T,lead};step;event type", 100, 0, 50, AliUEHist::fgkCFSteps, -0.5, -0.5 + AliUEHist::fgkCFSteps, 3, -0.5, 2.5);
183   fEventCountDifferential->GetZaxis()->SetBinLabel(1, "ND");
184   fEventCountDifferential->GetZaxis()->SetBinLabel(2, "SD");
185   fEventCountDifferential->GetZaxis()->SetBinLabel(3, "DD");
186   
187   fVertexContributors = new TH1F("fVertexContributors", ";contributors;count", 100, -0.5, 99.5);
188   
189   if (fNumberDensityPhi)
190   {
191     fCentralityDistribution = new TH1F("fCentralityDistribution", ";centrality;count", fNumberDensityPhi->GetEventHist()->GetNBins(1), fNumberDensityPhi->GetEventHist()->GetAxis(1, 0)->GetXbins()->GetArray());
192     fCentralityCorrelation = new TH2F("fCentralityCorrelation", ";centrality;multiplicity", 404, 0, 101, 200, 0, 4000);
193   }
194   
195   fITSClusterMap = new TH3F("fITSClusterMap", "; its cluster map; centrality; pT", 256, -0.5, 255.5, 20, 0, 100.001, 100, 0, 20);
196   
197   fControlConvResoncances = new TH2F("fControlConvResoncances", ";id;delta mass", 3, -0.5, 2.5, 100, -0.1, 0.1);
198   
199   TH1::AddDirectory(oldStatus);
200 }
201
202 //_____________________________________________________________________________
203 AliUEHistograms::AliUEHistograms(const AliUEHistograms &c) :
204   TNamed(fName, fTitle),
205   fNumberDensitypT(0),
206   fSumpT(0),
207   fNumberDensityPhi(0),
208   fCorrelationpT(0),
209   fCorrelationEta(0),
210   fCorrelationPhi(0),
211   fCorrelationR(0),
212   fCorrelationLeading2Phi(0),
213   fCorrelationMultiplicity(0),
214   fYields(0),
215   fInvYield2(0),
216   fEventCount(0),
217   fEventCountDifferential(0),
218   fVertexContributors(0),
219   fCentralityDistribution(0),
220   fCentralityCorrelation(0),
221   fITSClusterMap(0),
222   fControlConvResoncances(0),
223   fEfficiencyCorrectionTriggers(0),
224   fEfficiencyCorrectionAssociated(0),
225   fSelectCharge(0),
226   fTriggerSelectCharge(0),
227   fAssociatedSelectCharge(0),
228   fTriggerRestrictEta(-1),
229   fEtaOrdering(kFALSE),
230   fCutConversions(kFALSE),
231   fCutResonances(kFALSE),
232   fRejectResonanceDaughters(-1),
233   fOnlyOneEtaSide(0),
234   fWeightPerEvent(kFALSE),
235   fPtOrder(kTRUE),
236   fTwoTrackCutMinRadius(0.8),
237   fRunNumber(0),
238   fMergeCount(1)
239 {
240   //
241   // AliUEHistograms copy constructor
242   //
243
244   fTwoTrackDistancePt[0] = 0;
245   fTwoTrackDistancePt[1] = 0;
246
247   ((AliUEHistograms &) c).Copy(*this);
248 }
249
250 //____________________________________________________________________
251 AliUEHistograms::~AliUEHistograms()
252 {
253   // Destructor
254   
255   DeleteContainers();
256 }
257
258 void AliUEHistograms::DeleteContainers()
259 {
260   if (fNumberDensitypT)
261   {
262     delete fNumberDensitypT;
263     fNumberDensitypT = 0;
264   }
265   
266   if (fSumpT)
267   {
268     delete fSumpT;
269     fSumpT = 0;
270   }
271   
272   if (fNumberDensityPhi)
273   {
274     delete fNumberDensityPhi;
275     fNumberDensityPhi = 0;
276   }
277   
278   if (fCorrelationpT)
279   {
280     delete fCorrelationpT;
281     fCorrelationpT = 0;
282   }
283   
284   if (fCorrelationEta)
285   {
286     delete fCorrelationEta;
287     fCorrelationEta = 0;
288   }
289   
290   if (fCorrelationPhi)
291   {
292     delete fCorrelationPhi;
293     fCorrelationPhi = 0;
294   }
295   
296   if (fCorrelationR)
297   {
298     delete fCorrelationR;
299     fCorrelationR = 0;
300   }
301
302   if (fCorrelationLeading2Phi)
303   {
304     delete fCorrelationLeading2Phi;
305     fCorrelationLeading2Phi = 0;
306   }
307   
308   if (fCorrelationMultiplicity)
309   {
310     delete fCorrelationMultiplicity;
311     fCorrelationMultiplicity = 0;
312   }
313   
314   if (fYields)
315   {
316     delete fYields;
317     fYields = 0;
318   }
319   
320   if (fInvYield2)
321   {
322     delete fInvYield2;
323     fInvYield2 = 0;
324   }
325   
326   if (fEventCount)
327   {
328     delete fEventCount;
329     fEventCount = 0;
330   }
331
332   if (fEventCountDifferential)
333   {
334     delete fEventCountDifferential;
335     fEventCountDifferential = 0;
336   }
337   
338   if (fVertexContributors)
339   {
340     delete fVertexContributors;
341     fVertexContributors = 0;
342   }
343   
344   if (fCentralityDistribution)
345   {
346     delete fCentralityDistribution;
347     fCentralityDistribution = 0;
348   }
349   
350   if (fCentralityCorrelation)
351   {
352     delete fCentralityCorrelation;
353     fCentralityCorrelation = 0;
354   }
355   
356   if (fITSClusterMap)
357   {
358     delete fITSClusterMap;
359     fITSClusterMap = 0;
360   }
361   
362   for (Int_t i=0; i<2; i++)
363     if (fTwoTrackDistancePt[i])
364     {
365       delete fTwoTrackDistancePt[i];
366       fTwoTrackDistancePt[i] = 0;
367     }
368     
369   if (fControlConvResoncances)
370   {
371     delete fControlConvResoncances;
372     fControlConvResoncances = 0;
373   }
374     
375   if (fEfficiencyCorrectionTriggers)
376   {
377     delete fEfficiencyCorrectionTriggers;
378     fEfficiencyCorrectionTriggers = 0;
379   }
380   
381   if (fEfficiencyCorrectionAssociated)
382   {
383     delete fEfficiencyCorrectionAssociated;
384     fEfficiencyCorrectionAssociated = 0;
385   }
386 }
387
388 AliUEHist* AliUEHistograms::GetUEHist(Int_t id)
389 {
390   // returns AliUEHist object, useful for loops
391   
392   switch (id)
393   {
394     case 0: return fNumberDensitypT; break;
395     case 1: return fSumpT; break;
396     case 2: return fNumberDensityPhi; break;
397   }
398   
399   return 0;
400 }
401
402 //____________________________________________________________________
403 Int_t AliUEHistograms::CountParticles(TList* list, Float_t ptMin)
404 {
405   // counts the number of particles in the list with a pT above ptMin
406   // TODO eta cut needed here?
407   
408   Int_t count = 0;
409   for (Int_t j=0; j<list->GetEntries(); j++)
410     if (((AliVParticle*) list->At(j))->Pt() > ptMin)
411       count++;
412       
413   return count;
414 }
415   
416 //____________________________________________________________________
417 void AliUEHistograms::Fill(Int_t eventType, Float_t zVtx, AliUEHist::CFStep step, AliVParticle* leading, TList* toward, TList* away, TList* min, TList* max)
418 {
419   // fills the UE event histograms
420   //
421   // this function needs the leading (track or jet or ...) and four lists of AliVParticles which contain the particles/tracks to be filled in the four regions
422   
423   // if leading is not set, just fill event statistics
424   if (leading)
425   {
426     Int_t multiplicity = 0;
427     
428     // TODO configurable?
429     Float_t ptMin = 0.15;
430     if (leading->Pt() > ptMin)
431       multiplicity++;
432     
433     multiplicity += CountParticles(toward, ptMin);
434     multiplicity += CountParticles(away, ptMin);
435     multiplicity += CountParticles(min, ptMin);
436     multiplicity += CountParticles(max, ptMin);
437      
438     FillRegion(AliUEHist::kToward, zVtx, step, leading, toward, multiplicity);
439     FillRegion(AliUEHist::kAway,   zVtx, step, leading, away, multiplicity);
440     FillRegion(AliUEHist::kMin,    zVtx, step, leading, min, multiplicity);
441     FillRegion(AliUEHist::kMax,    zVtx, step, leading, max, multiplicity);
442  
443     Double_t vars[3];
444     vars[0] = leading->Pt();
445     vars[1] = multiplicity;
446     vars[2] = zVtx;
447     for (Int_t i=0; i<fgkUEHists; i++)
448       if (GetUEHist(i))
449         GetUEHist(i)->GetEventHist()->Fill(vars, step);
450   
451     fEventCountDifferential->Fill(leading->Pt(), step, eventType);
452   }
453   
454   FillEvent(eventType, step);
455 }
456   
457 //____________________________________________________________________
458 void AliUEHistograms::FillRegion(AliUEHist::Region region, Float_t zVtx, AliUEHist::CFStep step, AliVParticle* leading, TList* list, Int_t multiplicity)
459 {
460   // loops over AliVParticles in list and fills the given region at the given step
461   //
462   // See also Fill(...)
463
464   for (Int_t i=0; i<list->GetEntries(); i++)
465   {
466     AliVParticle* particle = (AliVParticle*) list->At(i);
467     
468     Double_t vars[6];
469     vars[0] = particle->Eta();
470     vars[1] = particle->Pt();
471     vars[2] = leading->Pt();
472     vars[3] = multiplicity;
473     vars[4] = leading->Phi() - particle->Phi();
474     if (vars[4] > 1.5 * TMath::Pi()) 
475       vars[4] -= TMath::TwoPi();
476     if (vars[4] < -0.5 * TMath::Pi())
477       vars[4] += TMath::TwoPi();
478     vars[5] = zVtx;
479     
480     if (fNumberDensitypT)
481       fNumberDensitypT->GetTrackHist(region)->Fill(vars, step);
482       
483     if (fSumpT)
484       fSumpT->GetTrackHist(region)->Fill(vars, step, particle->Pt());
485     
486     // fill all in toward region (is anyway as function of delta phi!)
487     if (fNumberDensityPhi)
488       fNumberDensityPhi->GetTrackHist(AliUEHist::kToward)->Fill(vars, step);
489   }
490 }
491
492 //____________________________________________________________________
493 void AliUEHistograms::Fill(AliVParticle* leadingMC, AliVParticle* leadingReco)
494 {
495   // fills the correlation histograms
496   
497   if (leadingMC)
498   {
499     fCorrelationpT->Fill(leadingMC->Pt(), leadingReco->Pt());
500     if (leadingMC->Pt() > 0.5)
501     {
502       fCorrelationEta->Fill(leadingMC->Eta(), leadingReco->Eta());
503       fCorrelationPhi->Fill(leadingMC->Phi(), leadingReco->Phi());
504     }
505     
506     Float_t phiDiff = leadingMC->Phi() - leadingReco->Phi();
507     if (phiDiff > TMath::Pi())
508       phiDiff -= TMath::TwoPi();
509     if (phiDiff < -TMath::Pi())
510       phiDiff += TMath::TwoPi();
511       
512     Float_t etaDiff = leadingMC->Eta() - leadingReco->Eta();
513     
514     fCorrelationR->Fill(TMath::Sqrt(phiDiff * phiDiff + etaDiff * etaDiff), leadingMC->Pt());
515     fCorrelationLeading2Phi->Fill(phiDiff, leadingMC->Pt());
516   }
517   else
518   {
519     fCorrelationpT->Fill(1.0, leadingReco->Pt());
520     if (leadingReco->Pt() > 0.5)
521     {
522       fCorrelationEta->Fill(0.0, leadingReco->Eta());
523       fCorrelationPhi->Fill(0.0, leadingReco->Phi());
524     }
525   }
526 }
527
528 //____________________________________________________________________
529 void AliUEHistograms::FillCorrelations(Double_t centrality, Float_t zVtx, AliUEHist::CFStep step, TObjArray* particles, TObjArray* mixed, Float_t weight, Bool_t firstTime, Bool_t twoTrackEfficiencyCut, Float_t bSign, Float_t twoTrackEfficiencyCutValue, Bool_t applyEfficiency)
530 {
531   // fills the fNumberDensityPhi histogram
532   //
533   // this function need a list of AliVParticles which contain the particles/tracks to be filled
534   //
535   // if mixed is non-0, mixed events are filled, the trigger particle is from particles, the associated from mixed
536   // if weight < 0, then the pt of the associated particle is filled as weight
537   
538   Bool_t fillpT = kFALSE;
539   if (weight < 0)
540     fillpT = kTRUE;
541   
542   if (twoTrackEfficiencyCut && !fTwoTrackDistancePt[0])
543   {
544     // do not add this hists to the directory
545     Bool_t oldStatus = TH1::AddDirectoryStatus();
546     TH1::AddDirectory(kFALSE);
547
548     fTwoTrackDistancePt[0] = new TH3F("fTwoTrackDistancePt[0]", ";#Delta#eta;#Delta#varphi^{*}_{min};#Delta p_{T}", 100, -0.15, 0.15, 100, -0.05, 0.05, 20, 0, 10);
549     fTwoTrackDistancePt[1] = (TH3F*) fTwoTrackDistancePt[0]->Clone("fTwoTrackDistancePt[1]");
550
551     TH1::AddDirectory(oldStatus);
552   }
553
554   // Eta() is extremely time consuming, therefore cache it for the inner loop here:
555   TObjArray* input = (mixed) ? mixed : particles;
556   TArrayF eta(input->GetEntriesFast());
557   for (Int_t i=0; i<input->GetEntriesFast(); i++)
558     eta[i] = ((AliVParticle*) input->UncheckedAt(i))->Eta();
559   
560   // if particles is not set, just fill event statistics
561   if (particles)
562   {
563     Int_t jMax = particles->GetEntriesFast();
564     if (mixed)
565       jMax = mixed->GetEntriesFast();
566     
567     TH1* triggerWeighting = 0;
568     if (fWeightPerEvent)
569     {
570       TAxis* axis = fNumberDensityPhi->GetTrackHist(AliUEHist::kToward)->GetGrid(0)->GetGrid()->GetAxis(2);
571       triggerWeighting = new TH1F("triggerWeighting", "", axis->GetNbins(), axis->GetXbins()->GetArray());
572     
573       for (Int_t i=0; i<particles->GetEntriesFast(); i++)
574       {
575         AliVParticle* triggerParticle = (AliVParticle*) particles->UncheckedAt(i);
576         
577         // some optimization
578         Float_t triggerEta = triggerParticle->Eta();
579
580         if (fTriggerRestrictEta > 0 && TMath::Abs(triggerEta) > fTriggerRestrictEta)
581           continue;
582
583         if (fOnlyOneEtaSide != 0)
584         {
585           if (fOnlyOneEtaSide * triggerEta < 0)
586             continue;
587         }
588         
589         if (fTriggerSelectCharge != 0)
590           if (triggerParticle->Charge() * fTriggerSelectCharge < 0)
591             continue;
592         
593         triggerWeighting->Fill(triggerParticle->Pt());
594       }
595     }
596     
597     // identify K, Lambda candidates and flag those particles
598     // a TObject bit is used for this
599     const UInt_t kResonanceDaughterFlag = 1 << 14;
600     if (fRejectResonanceDaughters > 0)
601     {
602       Double_t resonanceMass = -1;
603       Double_t massDaughter1 = -1;
604       Double_t massDaughter2 = -1;
605       const Double_t interval = 0.02;
606       
607       switch (fRejectResonanceDaughters)
608       {
609         case 1: resonanceMass = 1.2; massDaughter1 = 0.1396; massDaughter2 = 0.9383; break; // method test
610         case 2: resonanceMass = 0.4976; massDaughter1 = 0.1396; massDaughter2 = massDaughter1; break; // k0
611         case 3: resonanceMass = 1.115; massDaughter1 = 0.1396; massDaughter2 = 0.9383; break; // lambda
612         default: AliFatal(Form("Invalid setting %d", fRejectResonanceDaughters));
613       }
614
615       for (Int_t i=0; i<particles->GetEntriesFast(); i++)
616         particles->UncheckedAt(i)->ResetBit(kResonanceDaughterFlag);
617       if (mixed)
618         for (Int_t i=0; i<jMax; i++)
619           mixed->UncheckedAt(i)->ResetBit(kResonanceDaughterFlag);
620       
621       for (Int_t i=0; i<particles->GetEntriesFast(); i++)
622       {
623         AliVParticle* triggerParticle = (AliVParticle*) particles->UncheckedAt(i);
624         
625         for (Int_t j=0; j<jMax; j++)
626         {
627           if (!mixed && i == j)
628             continue;
629         
630           AliVParticle* particle = 0;
631           if (!mixed)
632             particle = (AliVParticle*) particles->UncheckedAt(j);
633           else
634             particle = (AliVParticle*) mixed->UncheckedAt(j);
635           
636           // check if both particles point to the same element (does not occur for mixed events, but if subsets are mixed within the same event)
637           if (mixed && triggerParticle->IsEqual(particle))
638             continue;
639          
640           if (triggerParticle->Charge() * particle->Charge() > 0)
641             continue;
642       
643           Float_t mass = GetInvMassSquaredCheap(triggerParticle->Pt(), triggerParticle->Eta(), triggerParticle->Phi(), particle->Pt(), particle->Eta(), particle->Phi(), massDaughter1, massDaughter2);
644               
645           if (TMath::Abs(mass - resonanceMass*resonanceMass) < interval*5)
646           {
647             mass = GetInvMassSquared(triggerParticle->Pt(), triggerParticle->Eta(), triggerParticle->Phi(), particle->Pt(), particle->Eta(), particle->Phi(), massDaughter1, massDaughter2);
648
649             if (mass > (resonanceMass-interval)*(resonanceMass-interval) && mass < (resonanceMass+interval)*(resonanceMass+interval))
650             {
651               triggerParticle->SetBit(kResonanceDaughterFlag);
652               particle->SetBit(kResonanceDaughterFlag);
653               
654 //            Printf("Flagged %d %d %f", i, j, TMath::Sqrt(mass));
655             }
656           }
657         }
658       }
659     }
660     
661     for (Int_t i=0; i<particles->GetEntriesFast(); i++)
662     {
663       AliVParticle* triggerParticle = (AliVParticle*) particles->UncheckedAt(i);
664       
665       // some optimization
666       Float_t triggerEta = triggerParticle->Eta();
667       
668       if (fTriggerRestrictEta > 0 && TMath::Abs(triggerEta) > fTriggerRestrictEta)
669         continue;
670
671       if (fOnlyOneEtaSide != 0)
672       {
673         if (fOnlyOneEtaSide * triggerEta < 0)
674           continue;
675       }
676       
677       if (fTriggerSelectCharge != 0)
678         if (triggerParticle->Charge() * fTriggerSelectCharge < 0)
679           continue;
680         
681       if (fRejectResonanceDaughters > 0)
682         if (triggerParticle->TestBit(kResonanceDaughterFlag))
683         {
684 //        Printf("Skipped i=%d", i);
685           continue;
686         }
687         
688       for (Int_t j=0; j<jMax; j++)
689       {
690         if (!mixed && i == j)
691           continue;
692       
693         AliVParticle* particle = 0;
694         if (!mixed)
695           particle = (AliVParticle*) particles->UncheckedAt(j);
696         else
697           particle = (AliVParticle*) mixed->UncheckedAt(j);
698         
699         // check if both particles point to the same element (does not occur for mixed events, but if subsets are mixed within the same event)
700         if (mixed && triggerParticle->IsEqual(particle))
701           continue;
702         
703         if (fPtOrder)
704           if (particle->Pt() >= triggerParticle->Pt())
705             continue;
706         
707         if (fAssociatedSelectCharge != 0)
708           if (particle->Charge() * fAssociatedSelectCharge < 0)
709             continue;
710
711         if (fSelectCharge > 0)
712         {
713           // skip like sign
714           if (fSelectCharge == 1 && particle->Charge() * triggerParticle->Charge() > 0)
715             continue;
716             
717           // skip unlike sign
718           if (fSelectCharge == 2 && particle->Charge() * triggerParticle->Charge() < 0)
719             continue;
720         }
721         
722         if (fEtaOrdering)
723         {
724           if (triggerEta < 0 && eta[j] < triggerEta)
725             continue;
726           if (triggerEta > 0 && eta[j] > triggerEta)
727             continue;
728         }
729
730         if (fRejectResonanceDaughters > 0)
731           if (particle->TestBit(kResonanceDaughterFlag))
732           {
733 //          Printf("Skipped j=%d", j);
734             continue;
735           }
736
737         // conversions
738         if (fCutConversions && particle->Charge() * triggerParticle->Charge() < 0)
739         {
740           Float_t mass = GetInvMassSquaredCheap(triggerParticle->Pt(), triggerEta, triggerParticle->Phi(), particle->Pt(), eta[j], particle->Phi(), 0.510e-3, 0.510e-3);
741           
742           if (mass < 0.1)
743           {
744             mass = GetInvMassSquared(triggerParticle->Pt(), triggerEta, triggerParticle->Phi(), particle->Pt(), eta[j], particle->Phi(), 0.510e-3, 0.510e-3);
745             
746             fControlConvResoncances->Fill(0.0, mass);
747
748             if (mass < 0.04*0.04) 
749               continue;
750           }
751         }
752         
753         // K0s
754         if (fCutResonances && particle->Charge() * triggerParticle->Charge() < 0)
755         {
756           Float_t mass = GetInvMassSquaredCheap(triggerParticle->Pt(), triggerEta, triggerParticle->Phi(), particle->Pt(), eta[j], particle->Phi(), 0.1396, 0.1396);
757           
758           const Float_t kK0smass = 0.4976;
759           
760           if (TMath::Abs(mass - kK0smass*kK0smass) < 0.1)
761           {
762             mass = GetInvMassSquared(triggerParticle->Pt(), triggerEta, triggerParticle->Phi(), particle->Pt(), eta[j], particle->Phi(), 0.1396, 0.1396);
763             
764             fControlConvResoncances->Fill(1, mass - kK0smass*kK0smass);
765
766             if (mass > (kK0smass-0.02)*(kK0smass-0.02) && mass < (kK0smass+0.02)*(kK0smass+0.02))
767               continue;
768           }
769         }
770         
771         // Lambda
772         if (fCutResonances && particle->Charge() * triggerParticle->Charge() < 0)
773         {
774           Float_t mass1 = GetInvMassSquaredCheap(triggerParticle->Pt(), triggerEta, triggerParticle->Phi(), particle->Pt(), eta[j], particle->Phi(), 0.1396, 0.9383);
775           Float_t mass2 = GetInvMassSquaredCheap(triggerParticle->Pt(), triggerEta, triggerParticle->Phi(), particle->Pt(), eta[j], particle->Phi(), 0.9383, 0.1396);
776           
777           const Float_t kLambdaMass = 1.115;
778
779           if (TMath::Abs(mass1 - kLambdaMass*kLambdaMass) < 0.1)
780           {
781             mass1 = GetInvMassSquared(triggerParticle->Pt(), triggerEta, triggerParticle->Phi(), particle->Pt(), eta[j], particle->Phi(), 0.1396, 0.9383);
782
783             fControlConvResoncances->Fill(2, mass1 - kLambdaMass*kLambdaMass);
784             
785             if (mass1 > (kLambdaMass-0.02)*(kLambdaMass-0.02) && mass1 < (kLambdaMass+0.02)*(kLambdaMass+0.02))
786               continue;
787           }
788           if (TMath::Abs(mass2 - kLambdaMass*kLambdaMass) < 0.1)
789           {
790             mass2 = GetInvMassSquared(triggerParticle->Pt(), triggerEta, triggerParticle->Phi(), particle->Pt(), eta[j], particle->Phi(), 0.9383, 0.1396);
791
792             fControlConvResoncances->Fill(2, mass2 - kLambdaMass*kLambdaMass);
793
794             if (mass2 > (kLambdaMass-0.02)*(kLambdaMass-0.02) && mass2 < (kLambdaMass+0.02)*(kLambdaMass+0.02))
795               continue;
796           }
797         }
798
799         if (twoTrackEfficiencyCut)
800         {
801           // the variables & cuthave been developed by the HBT group 
802           // see e.g. https://indico.cern.ch/materialDisplay.py?contribId=36&sessionId=6&materialId=slides&confId=142700
803
804           Float_t phi1 = triggerParticle->Phi();
805           Float_t pt1 = triggerParticle->Pt();
806           Float_t charge1 = triggerParticle->Charge();
807             
808           Float_t phi2 = particle->Phi();
809           Float_t pt2 = particle->Pt();
810           Float_t charge2 = particle->Charge();
811               
812           Float_t deta = triggerEta - eta[j];
813               
814           // optimization
815           if (TMath::Abs(deta) < twoTrackEfficiencyCutValue * 2.5 * 3)
816           {
817             // check first boundaries to see if is worth to loop and find the minimum
818             Float_t dphistar1 = GetDPhiStar(phi1, pt1, charge1, phi2, pt2, charge2, fTwoTrackCutMinRadius, bSign);
819             Float_t dphistar2 = GetDPhiStar(phi1, pt1, charge1, phi2, pt2, charge2, 2.5, bSign);
820             
821             const Float_t kLimit = twoTrackEfficiencyCutValue * 3;
822
823             Float_t dphistarminabs = 1e5;
824             Float_t dphistarmin = 1e5;
825             if (TMath::Abs(dphistar1) < kLimit || TMath::Abs(dphistar2) < kLimit || dphistar1 * dphistar2 < 0)
826             {
827               for (Double_t rad=fTwoTrackCutMinRadius; rad<2.51; rad+=0.01) 
828               {
829                 Float_t dphistar = GetDPhiStar(phi1, pt1, charge1, phi2, pt2, charge2, rad, bSign);
830
831                 Float_t dphistarabs = TMath::Abs(dphistar);
832                 
833                 if (dphistarabs < dphistarminabs)
834                 {
835                   dphistarmin = dphistar;
836                   dphistarminabs = dphistarabs;
837                 }
838               }
839               
840               fTwoTrackDistancePt[0]->Fill(deta, dphistarmin, TMath::Abs(pt1 - pt2));
841               
842               if (dphistarminabs < twoTrackEfficiencyCutValue && TMath::Abs(deta) < twoTrackEfficiencyCutValue)
843               {
844 //              Printf("Removed track pair %d %d with %f %f %f %f %f %f %f %f %f", i, j, deta, dphistarminabs, phi1, pt1, charge1, phi2, pt2, charge2, bSign);
845                 continue;
846               }
847
848               fTwoTrackDistancePt[1]->Fill(deta, dphistarmin, TMath::Abs(pt1 - pt2));
849             }
850           }
851         }
852         
853         Double_t vars[6];
854         vars[0] = triggerEta - eta[j];
855         vars[1] = particle->Pt();
856         vars[2] = triggerParticle->Pt();
857         vars[3] = centrality;
858         vars[4] = triggerParticle->Phi() - particle->Phi();
859         if (vars[4] > 1.5 * TMath::Pi()) 
860           vars[4] -= TMath::TwoPi();
861         if (vars[4] < -0.5 * TMath::Pi())
862           vars[4] += TMath::TwoPi();
863         vars[5] = zVtx;
864         
865         if (fillpT)
866           weight = particle->Pt();
867         
868         Double_t useWeight = weight;
869         if (applyEfficiency)
870         {
871           if (fEfficiencyCorrectionAssociated)
872           {
873             Int_t effVars[4];
874             // associated particle
875             effVars[0] = fEfficiencyCorrectionAssociated->GetAxis(0)->FindBin(eta[j]);
876             effVars[1] = fEfficiencyCorrectionAssociated->GetAxis(1)->FindBin(vars[1]); //pt
877             effVars[2] = fEfficiencyCorrectionAssociated->GetAxis(2)->FindBin(vars[3]); //centrality
878             effVars[3] = fEfficiencyCorrectionAssociated->GetAxis(3)->FindBin(vars[5]); //zVtx
879             
880             //    Printf("%d %d %d %d %f", effVars[0], effVars[1], effVars[2], effVars[3], fEfficiencyCorrectionAssociated->GetBinContent(effVars));
881           
882             useWeight *= fEfficiencyCorrectionAssociated->GetBinContent(effVars);
883           }
884           if (fEfficiencyCorrectionTriggers)
885           {
886             Int_t effVars[4];
887
888             effVars[0] = fEfficiencyCorrectionTriggers->GetAxis(0)->FindBin(triggerEta);
889             effVars[1] = fEfficiencyCorrectionTriggers->GetAxis(1)->FindBin(vars[2]); //pt
890             effVars[2] = fEfficiencyCorrectionTriggers->GetAxis(2)->FindBin(vars[3]); //centrality
891             effVars[3] = fEfficiencyCorrectionTriggers->GetAxis(3)->FindBin(vars[5]); //zVtx
892             useWeight *= fEfficiencyCorrectionTriggers->GetBinContent(effVars);
893           }
894         }
895
896         if (fWeightPerEvent)
897         {
898           Int_t weightBin = triggerWeighting->GetXaxis()->FindBin(vars[2]);
899 //        Printf("Using weight %f", triggerWeighting->GetBinContent(weightBin));
900           useWeight /= triggerWeighting->GetBinContent(weightBin);
901         }
902     
903         // fill all in toward region and do not use the other regions
904         fNumberDensityPhi->GetTrackHist(AliUEHist::kToward)->Fill(vars, step, useWeight);
905
906 //      Printf("%.2f %.2f --> %.2f", triggerEta, eta[j], vars[0]);
907       }
908  
909       if (firstTime)
910       {
911         // once per trigger particle
912         Double_t vars[3];
913         vars[0] = triggerParticle->Pt();
914         vars[1] = centrality;
915         vars[2] = zVtx;
916
917         Double_t useWeight = 1;
918         if (fEfficiencyCorrectionTriggers && applyEfficiency)
919         {
920           Int_t effVars[4];
921           
922           // trigger particle
923           effVars[0] = fEfficiencyCorrectionTriggers->GetAxis(0)->FindBin(triggerEta);
924           effVars[1] = fEfficiencyCorrectionTriggers->GetAxis(1)->FindBin(vars[0]); //pt
925           effVars[2] = fEfficiencyCorrectionTriggers->GetAxis(2)->FindBin(vars[1]); //centrality
926           effVars[3] = fEfficiencyCorrectionTriggers->GetAxis(3)->FindBin(vars[2]); //zVtx
927           useWeight *= fEfficiencyCorrectionTriggers->GetBinContent(effVars);
928         }
929
930         if (TMath::Abs(triggerEta) < 0.8 && triggerParticle->Pt() > 0)
931           fInvYield2->Fill(centrality, triggerParticle->Pt(), useWeight / triggerParticle->Pt());
932
933         if (fWeightPerEvent)
934         {
935           // leads effectively to a filling of one entry per filled trigger particle pT bin
936           Int_t weightBin = triggerWeighting->GetXaxis()->FindBin(vars[0]);
937 //        Printf("Using weight %f", triggerWeighting->GetBinContent(weightBin));
938           useWeight /= triggerWeighting->GetBinContent(weightBin);
939         }
940         
941         fNumberDensityPhi->GetEventHist()->Fill(vars, step, useWeight);
942
943         // QA
944         fCorrelationpT->Fill(centrality, triggerParticle->Pt());
945         fCorrelationEta->Fill(centrality, triggerEta);
946         fCorrelationPhi->Fill(centrality, triggerParticle->Phi());
947         fYields->Fill(centrality, triggerParticle->Pt(), triggerEta);
948         
949 /*        if (dynamic_cast<AliAODTrack*>(triggerParticle))
950           fITSClusterMap->Fill(((AliAODTrack*) triggerParticle)->GetITSClusterMap(), centrality, triggerParticle->Pt());*/
951       }
952     }
953     
954     if (triggerWeighting)
955     {
956       delete triggerWeighting;
957       triggerWeighting = 0;
958     }
959   }
960   
961   fCentralityDistribution->Fill(centrality);
962   fCentralityCorrelation->Fill(centrality, particles->GetEntriesFast());
963   FillEvent(centrality, step);
964 }
965   
966 //____________________________________________________________________
967 void AliUEHistograms::FillTrackingEfficiency(TObjArray* mc, TObjArray* recoPrim, TObjArray* recoAll, TObjArray* recoPrimPID, TObjArray* recoAllPID, TObjArray* fake, Int_t particleType, Double_t centrality, Double_t zVtx)
968 {
969   // fills the tracking efficiency objects
970   //
971   // mc: all primary MC particles
972   // recoPrim: reconstructed primaries (again MC particles)
973   // recoAll: reconstructed (again MC particles)
974   // recoPrim: reconstructed primaries with checks on PID (again MC particles)
975   // recoAll: reconstructed with checks on PID (again MC particles)
976   // particleType is: 0 for pion, 1 for kaon, 2 for proton, 3 for others
977  
978   for (Int_t step=0; step<6; step++)
979   {
980     TObjArray* list = mc;
981     if (step == 1)
982       list = recoPrim;
983     else if (step == 2)
984       list = recoAll;
985     else if (step == 3)
986       list = recoPrimPID;
987     else if (step == 4)
988       list = recoAllPID;
989     else if (step == 5)
990       list = fake;
991     
992     if (!list)
993       continue;
994
995     for (Int_t i=0; i<list->GetEntriesFast(); i++)
996     {
997       AliVParticle* particle = (AliVParticle*) list->UncheckedAt(i);
998       Double_t vars[5];
999       vars[0] = particle->Eta();
1000       vars[1] = particle->Pt();
1001       vars[2] = particleType;
1002       vars[3] = centrality;
1003       vars[4] = zVtx;
1004       
1005       for (Int_t j=0; j<fgkUEHists; j++)
1006         if (GetUEHist(j))
1007           GetUEHist(j)->GetTrackHistEfficiency()->Fill(vars, step);
1008     }
1009   }
1010 }
1011
1012 //____________________________________________________________________
1013 void AliUEHistograms::FillFakePt(TObjArray* fake, Double_t centrality)
1014 {
1015   TObjArray* tracksReco = (TObjArray*) fake->At(0);
1016   TObjArray* tracksMC = (TObjArray*) fake->At(1);
1017   
1018   if (tracksReco->GetEntriesFast() != tracksMC->GetEntriesFast())
1019     AliFatal(Form("Inconsistent arrays: %d vs %d", tracksReco->GetEntriesFast(), tracksMC->GetEntriesFast()));
1020   
1021   for (Int_t i=0; i<tracksReco->GetEntriesFast(); i++)
1022   {
1023     AliVParticle* particle1 = (AliVParticle*) tracksReco->At(i);
1024     AliVParticle* particle2 = (AliVParticle*) tracksMC->At(i);
1025     Double_t vars[3];
1026     vars[0] = particle1->Pt();
1027     vars[1] = particle2->Pt();
1028     vars[2] = centrality;
1029     for (Int_t j=0; j<fgkUEHists; j++)
1030       if (GetUEHist(j))
1031         GetUEHist(j)->GetMCRecoPtCorrelation()->Fill(vars[0],vars[1],vars[2]);
1032   }
1033 }
1034
1035 //____________________________________________________________________
1036 void AliUEHistograms::FillEvent(Int_t eventType, Int_t step)
1037 {
1038   // fills the number of events at the given step and the given enty type
1039   //
1040   // WARNING: This function is called from Fill, so only call it for steps where Fill is not called
1041   
1042   fEventCount->Fill(step, eventType);
1043 }
1044
1045 //____________________________________________________________________
1046 void AliUEHistograms::FillEvent(Double_t centrality, Int_t step)
1047 {
1048   // fills the number of events at the given step and the given centrality
1049   //
1050   // WARNING: This function is called from Fill, so only call it for steps where Fill is not called
1051   
1052   fEventCount->Fill(step, centrality);
1053 }
1054
1055 //____________________________________________________________________
1056 void AliUEHistograms::SetEtaRange(Float_t etaMin, Float_t etaMax)
1057 {
1058   // sets eta min and max for all contained AliUEHist classes
1059   
1060   for (Int_t i=0; i<fgkUEHists; i++)
1061     if (GetUEHist(i))
1062       GetUEHist(i)->SetEtaRange(etaMin, etaMax);
1063 }
1064
1065 //____________________________________________________________________
1066 void AliUEHistograms::SetPtRange(Float_t ptMin, Float_t ptMax)
1067 {
1068   // sets pT min and max for all contained AliUEHist classes
1069   
1070   for (Int_t i=0; i<fgkUEHists; i++)
1071     if (GetUEHist(i))
1072       GetUEHist(i)->SetPtRange(ptMin, ptMax);
1073 }
1074
1075 //____________________________________________________________________
1076 void AliUEHistograms::SetPartSpecies(Int_t species)
1077 {
1078   // sets PartSpecie for all contained AliUEHist classes
1079   
1080   for (Int_t i=0; i<fgkUEHists; i++)
1081     if (GetUEHist(i))
1082       GetUEHist(i)->SetPartSpecies(species);
1083 }
1084
1085 //____________________________________________________________________
1086 void AliUEHistograms::SetZVtxRange(Float_t min, Float_t max)
1087 {
1088   // sets pT min and max for all contained AliUEHist classes
1089   
1090   for (Int_t i=0; i<fgkUEHists; i++)
1091     if (GetUEHist(i))
1092       GetUEHist(i)->SetZVtxRange(min, max);
1093 }
1094
1095 //____________________________________________________________________
1096 void AliUEHistograms::SetContaminationEnhancement(TH1F* hist)
1097 {
1098   // sets the contamination enhancement histogram in all contained AliUEHist classes
1099   
1100   for (Int_t i=0; i<fgkUEHists; i++)
1101     if (GetUEHist(i))
1102       GetUEHist(i)->SetContaminationEnhancement(hist);
1103 }  
1104
1105 //____________________________________________________________________
1106 void AliUEHistograms::SetCombineMinMax(Bool_t flag)
1107 {
1108   // sets pT min and max for all contained AliUEHist classes
1109   
1110   for (Int_t i=0; i<fgkUEHists; i++)
1111     if (GetUEHist(i))
1112       GetUEHist(i)->SetCombineMinMax(flag);
1113 }
1114
1115 //____________________________________________________________________
1116 void AliUEHistograms::SetTrackEtaCut(Float_t value)
1117 {
1118   // sets track eta cut for all contained AliUEHist classes
1119   
1120   for (Int_t i=0; i<fgkUEHists; i++)
1121     if (GetUEHist(i))
1122       GetUEHist(i)->SetTrackEtaCut(value);
1123 }
1124
1125 //____________________________________________________________________
1126 void AliUEHistograms::SetWeightPerEvent(Bool_t flag)
1127 {
1128   // sets fWeightPerEvent for all contained AliUEHist classes
1129   
1130   fWeightPerEvent = flag;
1131   
1132   for (Int_t i=0; i<fgkUEHists; i++)
1133     if (GetUEHist(i))
1134       GetUEHist(i)->SetWeightPerEvent(fWeightPerEvent);
1135 }
1136
1137 //____________________________________________________________________
1138 void AliUEHistograms::Correct(AliUEHistograms* corrections)
1139 {
1140   // corrects the contained histograms by calling AliUEHist::Correct
1141   
1142   for (Int_t i=0; i<fgkUEHists; i++)
1143     if (GetUEHist(i))
1144       GetUEHist(i)->Correct(corrections->GetUEHist(i));
1145 }
1146
1147 //____________________________________________________________________
1148 AliUEHistograms &AliUEHistograms::operator=(const AliUEHistograms &c)
1149 {
1150   // assigment operator
1151
1152   DeleteContainers();
1153
1154   if (this != &c)
1155     ((AliUEHistograms &) c).Copy(*this);
1156
1157   return *this;
1158 }
1159
1160 //____________________________________________________________________
1161 void AliUEHistograms::Copy(TObject& c) const
1162 {
1163   // copy function
1164
1165   AliUEHistograms& target = (AliUEHistograms &) c;
1166
1167   if (fNumberDensitypT)
1168     target.fNumberDensitypT = dynamic_cast<AliUEHist*> (fNumberDensitypT->Clone());
1169
1170   if (fSumpT)
1171     target.fSumpT = dynamic_cast<AliUEHist*> (fSumpT->Clone());
1172
1173   if (fNumberDensityPhi)
1174     target.fNumberDensityPhi = dynamic_cast<AliUEHist*> (fNumberDensityPhi->Clone());
1175
1176   if (fCorrelationpT)
1177     target.fCorrelationpT = dynamic_cast<TH2F*> (fCorrelationpT->Clone());
1178
1179   if (fCorrelationEta)
1180     target.fCorrelationEta = dynamic_cast<TH2F*> (fCorrelationEta->Clone());
1181
1182   if (fCorrelationPhi)
1183     target.fCorrelationPhi = dynamic_cast<TH2F*> (fCorrelationPhi->Clone());
1184
1185   if (fCorrelationR)
1186     target.fCorrelationR = dynamic_cast<TH2F*> (fCorrelationR->Clone());
1187
1188   if (fCorrelationLeading2Phi)
1189     target.fCorrelationLeading2Phi = dynamic_cast<TH2F*> (fCorrelationLeading2Phi->Clone());
1190
1191   if (fCorrelationMultiplicity)
1192     target.fCorrelationMultiplicity = dynamic_cast<TH2F*> (fCorrelationMultiplicity->Clone());
1193   
1194   if (fYields)
1195     target.fYields = dynamic_cast<TH3F*> (fYields->Clone());
1196   
1197   if (fInvYield2)
1198     target.fInvYield2 = dynamic_cast<TH2F*> (fInvYield2->Clone());
1199   
1200   if (fEventCount)
1201     target.fEventCount = dynamic_cast<TH2F*> (fEventCount->Clone());
1202
1203   if (fEventCountDifferential)
1204     target.fEventCountDifferential = dynamic_cast<TH3F*> (fEventCountDifferential->Clone());
1205     
1206   if (fVertexContributors)
1207     target.fVertexContributors = dynamic_cast<TH1F*> (fVertexContributors->Clone());
1208
1209   if (fCentralityDistribution)
1210     target.fCentralityDistribution = dynamic_cast<TH1F*> (fCentralityDistribution->Clone());
1211     
1212   if (fCentralityCorrelation)
1213     target.fCentralityCorrelation = dynamic_cast<TH2F*> (fCentralityCorrelation->Clone());
1214
1215   if (fITSClusterMap)
1216     target.fITSClusterMap = dynamic_cast<TH3F*> (fITSClusterMap->Clone());
1217   
1218   if (fControlConvResoncances)
1219     target.fControlConvResoncances = dynamic_cast<TH2F*> (fControlConvResoncances->Clone());
1220   
1221   for (Int_t i=0; i<2; i++)
1222     if (fTwoTrackDistancePt[i])
1223       target.fTwoTrackDistancePt[i] = dynamic_cast<TH3F*> (fTwoTrackDistancePt[i]->Clone());
1224
1225   if (fEfficiencyCorrectionTriggers)
1226     target.fEfficiencyCorrectionTriggers = dynamic_cast<THnF*> (fEfficiencyCorrectionTriggers->Clone());
1227  
1228  if (fEfficiencyCorrectionAssociated)
1229     target.fEfficiencyCorrectionAssociated = dynamic_cast<THnF*> (fEfficiencyCorrectionAssociated->Clone());
1230     
1231   target.fSelectCharge = fSelectCharge;
1232   target.fTriggerSelectCharge = fTriggerSelectCharge;
1233   target.fAssociatedSelectCharge = fAssociatedSelectCharge;
1234   target.fTriggerRestrictEta = fTriggerRestrictEta;
1235   target.fEtaOrdering = fEtaOrdering;
1236   target.fCutConversions = fCutConversions;
1237   target.fCutResonances = fCutResonances;
1238   target.fOnlyOneEtaSide = fOnlyOneEtaSide;
1239   target.fWeightPerEvent = fWeightPerEvent;
1240   target.fRunNumber = fRunNumber;
1241   target.fMergeCount = fMergeCount;
1242   target.fWeightPerEvent = fWeightPerEvent;
1243   target.fPtOrder = fPtOrder;
1244   target.fTwoTrackCutMinRadius = fTwoTrackCutMinRadius;
1245 }
1246
1247 //____________________________________________________________________
1248 Long64_t AliUEHistograms::Merge(TCollection* list)
1249 {
1250   // Merge a list of AliUEHistograms objects with this (needed for
1251   // PROOF). 
1252   // Returns the number of merged objects (including this).
1253
1254   if (!list)
1255     return 0;
1256   
1257   if (list->IsEmpty())
1258     return 1;
1259
1260   TIterator* iter = list->MakeIterator();
1261   TObject* obj;
1262
1263   // collections of objects
1264   const Int_t kMaxLists = 20;
1265   TList* lists[kMaxLists];
1266   
1267   for (Int_t i=0; i<kMaxLists; i++)
1268     lists[i] = new TList;
1269   
1270   Int_t count = 0;
1271   while ((obj = iter->Next())) {
1272     
1273     AliUEHistograms* entry = dynamic_cast<AliUEHistograms*> (obj);
1274     if (entry == 0) 
1275       continue;
1276
1277     if (entry->fNumberDensitypT)
1278       lists[0]->Add(entry->fNumberDensitypT);
1279     if (entry->fSumpT)
1280       lists[1]->Add(entry->fSumpT);
1281     if (entry->fNumberDensityPhi)
1282       lists[2]->Add(entry->fNumberDensityPhi);
1283     lists[3]->Add(entry->fCorrelationpT);
1284     lists[4]->Add(entry->fCorrelationEta);
1285     lists[5]->Add(entry->fCorrelationPhi);
1286     lists[6]->Add(entry->fCorrelationR);
1287     lists[7]->Add(entry->fCorrelationLeading2Phi);
1288     lists[8]->Add(entry->fCorrelationMultiplicity);
1289     lists[9]->Add(entry->fEventCount);
1290     lists[10]->Add(entry->fEventCountDifferential);
1291     lists[11]->Add(entry->fVertexContributors);
1292     lists[12]->Add(entry->fCentralityDistribution);
1293     lists[13]->Add(entry->fITSClusterMap);
1294     if (entry->fTwoTrackDistancePt[0])
1295       lists[14]->Add(entry->fTwoTrackDistancePt[0]);
1296     if (entry->fTwoTrackDistancePt[1])
1297       lists[15]->Add(entry->fTwoTrackDistancePt[1]);
1298     if (entry->fCentralityCorrelation)
1299       lists[16]->Add(entry->fCentralityCorrelation);
1300     if (entry->fYields)
1301       lists[17]->Add(entry->fYields);
1302     if (entry->fInvYield2)
1303       lists[18]->Add(entry->fInvYield2);
1304     if (entry->fControlConvResoncances)
1305       lists[19]->Add(entry->fControlConvResoncances);
1306
1307     fMergeCount += entry->fMergeCount;
1308
1309     count++;
1310   }
1311     
1312   if (fNumberDensitypT)
1313     fNumberDensitypT->Merge(lists[0]);
1314   if (fSumpT)
1315     fSumpT->Merge(lists[1]);
1316   if (fNumberDensityPhi)
1317     fNumberDensityPhi->Merge(lists[2]);
1318   fCorrelationpT->Merge(lists[3]);
1319   fCorrelationEta->Merge(lists[4]);
1320   fCorrelationPhi->Merge(lists[5]);
1321   fCorrelationR->Merge(lists[6]);
1322   fCorrelationLeading2Phi->Merge(lists[7]);
1323   fCorrelationMultiplicity->Merge(lists[8]);
1324   fEventCount->Merge(lists[9]);
1325   fEventCountDifferential->Merge(lists[10]);
1326   fVertexContributors->Merge(lists[11]);
1327   fCentralityDistribution->Merge(lists[12]);
1328   fITSClusterMap->Merge(lists[13]);
1329   if (fTwoTrackDistancePt[0] && lists[14]->GetEntries() > 0)
1330     fTwoTrackDistancePt[0]->Merge(lists[14]);
1331   if (fTwoTrackDistancePt[1] && lists[15]->GetEntries() > 0)
1332     fTwoTrackDistancePt[1]->Merge(lists[15]);
1333   if (fCentralityCorrelation)
1334     fCentralityCorrelation->Merge(lists[16]);
1335   if (fYields && lists[17]->GetEntries() > 0)
1336     fYields->Merge(lists[17]);
1337   if (fInvYield2 && lists[18]->GetEntries() > 0)
1338     fInvYield2->Merge(lists[18]);
1339   if (fControlConvResoncances && lists[19]->GetEntries() > 0)
1340     fControlConvResoncances->Merge(lists[19]);
1341   
1342   for (Int_t i=0; i<kMaxLists; i++)
1343     delete lists[i];
1344   
1345   return count+1;
1346 }
1347
1348 void AliUEHistograms::CopyReconstructedData(AliUEHistograms* from)
1349 {
1350   // copies those histograms extracted from ESD to this object
1351   
1352   for (Int_t i=0; i<fgkUEHists; i++)
1353     if (GetUEHist(i))
1354       GetUEHist(i)->CopyReconstructedData(from->GetUEHist(i));
1355 }
1356
1357 void AliUEHistograms::DeepCopy(AliUEHistograms* from)
1358 {
1359   // copies the entries of this object's members from the object <from> to this object
1360
1361   for (Int_t i=0; i<fgkUEHists; i++)
1362     if (GetUEHist(i) && from->GetUEHist(i))
1363       GetUEHist(i)->DeepCopy(from->GetUEHist(i));
1364 }
1365
1366 void AliUEHistograms::ExtendTrackingEfficiency(Bool_t verbose)
1367 {
1368   // delegates to AliUEHists
1369
1370   for (Int_t i=0; i<fgkUEHists; i++)
1371     if (GetUEHist(i))
1372       GetUEHist(i)->ExtendTrackingEfficiency(verbose);
1373 }
1374
1375 void AliUEHistograms::Scale(Double_t factor)
1376 {
1377   // scales all contained histograms by the given factor
1378   
1379   for (Int_t i=0; i<fgkUEHists; i++)
1380     if (GetUEHist(i))
1381       GetUEHist(i)->Scale(factor);
1382       
1383   TList list;
1384   list.Add(fCorrelationpT);
1385   list.Add(fCorrelationEta);
1386   list.Add(fCorrelationPhi);
1387   list.Add(fCorrelationR);
1388   list.Add(fCorrelationLeading2Phi);
1389   list.Add(fCorrelationMultiplicity);
1390   list.Add(fYields);
1391   list.Add(fInvYield2);
1392   list.Add(fEventCount);
1393   list.Add(fEventCountDifferential);
1394   list.Add(fVertexContributors);
1395   list.Add(fCentralityDistribution);
1396   list.Add(fCentralityCorrelation);
1397   list.Add(fITSClusterMap);
1398   list.Add(fTwoTrackDistancePt[0]);
1399   list.Add(fTwoTrackDistancePt[1]);
1400   list.Add(fControlConvResoncances);
1401   
1402   for (Int_t i=0; i<list.GetEntries(); i++)
1403     ((TH1*) list.At(i))->Scale(factor);
1404 }
1405
1406 void AliUEHistograms::Reset()
1407 {
1408   // delegates to AliUEHists
1409
1410   for (Int_t i=0; i<fgkUEHists; i++)
1411     if (GetUEHist(i))
1412       GetUEHist(i)->Reset();
1413 }