]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGGA/PHOSTasks/PHOS_PbPb/AliAnalysisTaskPi0Flow.cxx
Made vertex z cut dynamic.
[u/mrichter/AliRoot.git] / PWGGA / PHOSTasks / PHOS_PbPb / AliAnalysisTaskPi0Flow.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 #include "TChain.h"
17 #include "TTree.h"
18 #include "TObjArray.h"
19 #include "TF1.h"
20 #include "TFile.h"
21 #include "TH1F.h"
22 #include "TH2F.h"
23 #include "TH2I.h"
24 #include "TH3F.h"
25 #include "TParticle.h"
26 #include "TCanvas.h"
27 #include "TStyle.h"
28 #include "TRandom.h"
29 #include "THashList.h"
30
31 #include "AliAnalysisManager.h"
32 #include "AliMCEventHandler.h"
33 #include "AliMCEvent.h"
34 #include "AliStack.h"
35 #include "AliAnalysisTaskSE.h"
36 #include "AliAnalysisTaskPi0Flow.h"
37 #include "AliCaloPhoton.h"
38 #include "AliPHOSGeometry.h"
39 #include "TGeoManager.h"
40 #include "AliPHOSEsdCluster.h"
41 #include "AliPHOSCalibData.h"
42 #include "AliESDEvent.h"
43 #include "AliESDCaloCells.h"
44 #include "AliESDVertex.h"
45 #include "AliESDtrackCuts.h"
46 #include "AliAODEvent.h"
47 #include "AliLog.h"
48 #include "AliPID.h"
49 #include "AliCDBManager.h"
50 #include <AliAODCaloCluster.h>
51 #include "AliCentrality.h"
52 #include "AliESDtrackCuts.h"
53 #include "AliEventplane.h"
54 #include "TProfile.h"
55 #include "AliOADBContainer.h"
56 #include "AliPHOSEPFlattener.h"
57
58 // Analysis task to fill histograms with PHOS ESD or AOD clusters and cells
59 // Authors : Dmitri Peressounko
60 // Date    : 28.05.2011
61 // Modified: 03.08.2012 Henrik Qvigstad
62 /* $Id$ */
63
64 ClassImp(AliAnalysisTaskPi0Flow);
65
66 //________________________________________________________________________
67 Double_t rnlin(Double_t *x, Double_t * /*par*/)
68 {
69   //a = par[0], b = par[1].
70   //1+a*exp(-e/b)
71
72 // return 0.0241+1.0504*x[0]+0.000249*x[0]*x[0] ;
73  return 1.015*(0.0241+1.0504*x[0]+0.000249*x[0]*x[0]) ;
74
75 }
76
77 //________________________________________________________________________
78 AliAnalysisTaskPi0Flow::AliAnalysisTaskPi0Flow(const char *name, Period period)
79 : AliAnalysisTaskSE(name),
80   fCentEdges(10),
81   fCentNMixed(10),
82   fNEMRPBins(9),
83   fPeriod(period),
84   fMaxAbsVertexZ(10.),
85   fManualV0EPCalc(false),
86   fOutputContainer(0x0),
87   fNonLinCorr(0),
88   fEvent(0x0),
89   fEventESD(0x0),
90   fEventAOD(0x0),
91   fMCStack(0x0),
92   fRunNumber(-999),
93   fInternalRunNumber(0),
94   fPHOSGeo(0),
95   fMultV0(0x0),
96   fV0Cpol(0.),fV0Apol(0.),
97   fESDtrackCuts(0x0),
98   fPHOSCalibData(0x0),
99   fEPcalibFileName("$ALICE_ROOT/OADB/PHOS/PHOSflat.root"), 
100   fTPCFlat(0x0),
101   fV0AFlat(0x0),
102   fV0CFlat(0x0),
103   fVertexVector(),
104   fVtxBin(0),
105   fCentralityV0M(0.),
106   fCentBin(0),
107   fHaveTPCRP(0),
108   fRP(0),
109   fRPV0A(0),
110   fRPV0C(0),
111   fEMRPBin(0),
112   fCaloPhotonsPHOS(0x0),
113   fCaloPhotonsPHOSLists(0x0)
114 {
115   const int nbins = 9;
116   Double_t edges[nbins+1] = {0., 5., 10., 20., 30., 40., 50., 60., 70., 80.};
117   TArrayD centEdges(nbins+1, edges);
118   Int_t nMixed[nbins] = {4,4,6,10,20,30,50,100,100};
119   TArrayI centNMixed(nbins, nMixed);
120   SetCentralityBinning(centEdges, centNMixed);
121   
122   for(Int_t i=0;i<kNCenBins;i++){
123     for(Int_t j=0;j<2; j++)
124       for(Int_t k=0; k<2; k++) {
125         fMeanQ[i][j][k]=0.;
126         fWidthQ[i][j][k]=0.;
127       }
128   }
129   
130   fVertex[0]=0; fVertex[1]=0; fVertex[2]=0; 
131
132   // Output slots #0 write into a TH1 container
133   DefineOutput(1,TList::Class());
134
135
136
137   // Set bad channel map
138   char key[55] ;
139   for(Int_t i=0; i<6; i++){
140     snprintf(key,55,"PHOS_BadMap_mod%d",i) ;
141     fPHOSBadMap[i]=new TH2I(key,"Bad Modules map",64,0.,64.,56,0.,56.) ;
142   }
143
144
145   // Initialize non-linrarity correction
146   fNonLinCorr = new TF1("nonlib",rnlin,0.,40.,0);
147
148
149 }
150 //___________________________________________________________________________
151 AliAnalysisTaskPi0Flow::~AliAnalysisTaskPi0Flow()
152 {
153   delete fNonLinCorr;
154   delete fESDtrackCuts;
155   delete fPHOSCalibData;
156   delete fCaloPhotonsPHOSLists;
157   if(fTPCFlat)delete fTPCFlat;  fTPCFlat=0x0;
158   if(fV0AFlat)delete fV0AFlat;  fV0AFlat=0x0;
159   if(fV0CFlat)delete fV0CFlat;  fV0CFlat=0x0;
160   
161 }
162 //________________________________________________________________________
163 void AliAnalysisTaskPi0Flow::UserCreateOutputObjects()
164 {
165   // Create histograms
166   // Called once
167   const Int_t nRuns=200 ;
168
169   // histograms
170   if(fOutputContainer != NULL){
171     delete fOutputContainer;
172   }
173   fOutputContainer = new THashList();
174   fOutputContainer->SetOwner(kTRUE);
175
176   //========QA histograms=======
177
178   //Event selection
179   fOutputContainer->Add(new TH2F("hSelEvents","Event selection", 12,0.,13.,nRuns,0.,float(nRuns))) ;
180   fOutputContainer->Add(new TH1F("hTotSelEvents","Event selection", 12,0.,12.)) ;
181
182   //vertex distribution
183   fOutputContainer->Add(new TH2F("hZvertex","Z vertex position", 50,-25.,25.,nRuns,0.,float(nRuns))) ;
184
185   //Centrality
186   fOutputContainer->Add(new TH2F("hCentrality","Event centrality", 100,0.,100.,nRuns,0.,float(nRuns))) ;
187   fOutputContainer->Add(new TH2F("hCenPHOS","Centrality vs PHOSclusters", 100,0.,100.,200,0.,200.)) ;
188   fOutputContainer->Add(new TH2F("hCenPHOSCells","Centrality vs PHOS cells", 100,0.,100.,100,0.,1000.)) ;
189   fOutputContainer->Add(new TH2F("hCenTrack","Centrality vs tracks", 100,0.,100.,100,0.,15000.)) ;
190   fOutputContainer->Add(new TH2F("hCluEvsClu","ClusterMult vs E",200,0.,10.,100,0.,100.)) ;
191
192
193   //Reaction plane
194   fOutputContainer->Add(new TH3F("hPHOSphi","cos" ,10,0.,100.,20,0.,10.,100,-TMath::Pi(),TMath::Pi()));
195
196   fOutputContainer->Add(new TH2F("cos2AC","RP correlation between TPC subs", 100,-1.,1.,20,0.,100.)) ;
197   fOutputContainer->Add(new TH2F("cos2V0AC","RP correlation between VO A and C sides", 100,-1.,1.,20,0.,100.)) ;
198   fOutputContainer->Add(new TH2F("cos2V0ATPC","RP correlation between TPC and V0A", 100,-1.,1.,20,0.,100.)) ;
199   fOutputContainer->Add(new TH2F("cos2V0CTPC","RP correlation between TPC and V0C", 100,-1.,1.,20,0.,100.)) ;
200
201   fOutputContainer->Add(new TH2F("phiRP","RP distribution with TPC", 100,0.,TMath::Pi(),20,0.,100.)) ;
202   fOutputContainer->Add(new TH2F("phiRPflat","RP distribution with TPC flat", 100,0.,TMath::Pi(),20,0.,100.)) ;
203   fOutputContainer->Add(new TH2F("phiRPV0A","RP distribution with V0A", 100,0.,TMath::Pi(),20,0.,100.)) ;
204   fOutputContainer->Add(new TH2F("phiRPV0C","RP distribution with V0C", 100,0.,TMath::Pi(),20,0.,100.)) ;
205   fOutputContainer->Add(new TH3F("phiRPV0AC","RP distribution with V0A and V0C", 100,0.,TMath::Pi(),100,0.,TMath::Pi(),20,0.,100.)) ;
206   fOutputContainer->Add(new TH2F("phiRPV0Aflat","RP distribution with V0 flat", 100,0.,TMath::Pi(),20,0.,100.)) ;
207   fOutputContainer->Add(new TH2F("phiRPV0Cflat","RP distribution with V0 flat", 100,0.,TMath::Pi(),20,0.,100.)) ;
208   fOutputContainer->Add(new TH3F("phiRPV0ATPC","RP distribution with V0A + TPC", 100,0.,TMath::Pi(),100,0.,TMath::Pi(),20,0.,100.)) ;
209   fOutputContainer->Add(new TH3F("phiRPV0CTPC","RP distribution with V0C + TPC", 100,0.,TMath::Pi(),100,0.,TMath::Pi(),20,0.,100.)) ;
210
211
212   //PHOS QA
213   fOutputContainer->Add(new TH1I("hCellMultEvent"  ,"PHOS cell multiplicity per event"    ,2000,0,2000));
214   fOutputContainer->Add(new TH1I("hCellMultEventM1","PHOS cell multiplicity per event, M1",2000,0,2000));
215   fOutputContainer->Add(new TH1I("hCellMultEventM2","PHOS cell multiplicity per event, M2",2000,0,2000));
216   fOutputContainer->Add(new TH1I("hCellMultEventM3","PHOS cell multiplicity per event, M3",2000,0,2000));
217
218   fOutputContainer->Add(new TH1F("hCellEnergy"  ,"Cell energy"            ,3000,0.,30.));
219   fOutputContainer->Add(new TH1F("hCellEnergyM1","Cell energy in module 1",3000,0.,30.));
220   fOutputContainer->Add(new TH1F("hCellEnergyM2","Cell energy in module 2",3000,0.,30.));
221   fOutputContainer->Add(new TH1F("hCellEnergyM3","Cell energy in module 3",3000,0.,30.));
222
223   fOutputContainer->Add(new TH2F("hCellNXZM1","Cell (X,Z), M1" ,64,0.5,64.5, 56,0.5,56.5));
224   fOutputContainer->Add(new TH2F("hCellNXZM2","Cell (X,Z), M2" ,64,0.5,64.5, 56,0.5,56.5));
225   fOutputContainer->Add(new TH2F("hCellNXZM3","Cell (X,Z), M3" ,64,0.5,64.5, 56,0.5,56.5));
226   fOutputContainer->Add(new TH2F("hCellEXZM1","Cell E(X,Z), M1",64,0.5,64.5, 56,0.5,56.5));
227   fOutputContainer->Add(new TH2F("hCellEXZM2","Cell E(X,Z), M2",64,0.5,64.5, 56,0.5,56.5));
228   fOutputContainer->Add(new TH2F("hCellEXZM3","Cell E(X,Z), M3",64,0.5,64.5, 56,0.5,56.5));
229
230   //Bad Map
231   fOutputContainer->Add(new TH2F("hCluLowM1","Cell (X,Z), M1" ,64,0.5,64.5, 56,0.5,56.5));
232   fOutputContainer->Add(new TH2F("hCluLowM2","Cell (X,Z), M2" ,64,0.5,64.5, 56,0.5,56.5));
233   fOutputContainer->Add(new TH2F("hCluLowM3","Cell (X,Z), M3" ,64,0.5,64.5, 56,0.5,56.5));
234
235   fOutputContainer->Add(new TH2F("hCluHighM1","Cell (X,Z), M1" ,64,0.5,64.5, 56,0.5,56.5));
236   fOutputContainer->Add(new TH2F("hCluHighM2","Cell (X,Z), M2" ,64,0.5,64.5, 56,0.5,56.5));
237   fOutputContainer->Add(new TH2F("hCluHighM3","Cell (X,Z), M3" ,64,0.5,64.5, 56,0.5,56.5));
238
239   fOutputContainer->Add(new TH2F("hCluVetoM1","Cell (X,Z), M1" ,64,0.5,64.5, 56,0.5,56.5));
240   fOutputContainer->Add(new TH2F("hCluVetoM2","Cell (X,Z), M2" ,64,0.5,64.5, 56,0.5,56.5));
241   fOutputContainer->Add(new TH2F("hCluVetoM3","Cell (X,Z), M3" ,64,0.5,64.5, 56,0.5,56.5));
242
243   fOutputContainer->Add(new TH2F("hCluDispM1","Cell (X,Z), M1" ,64,0.5,64.5, 56,0.5,56.5));
244   fOutputContainer->Add(new TH2F("hCluDispM2","Cell (X,Z), M2" ,64,0.5,64.5, 56,0.5,56.5));
245   fOutputContainer->Add(new TH2F("hCluDispM3","Cell (X,Z), M3" ,64,0.5,64.5, 56,0.5,56.5));
246
247
248   //Single photon and pi0 spectrum
249   const Int_t nPtPhot = 400 ;
250   const Double_t ptPhotMax = 40 ;
251   const Int_t nM       = 500;
252   const Double_t mMin  = 0.0;
253   const Double_t mMax  = 1.0;
254
255   //PHOS calibration QA
256   fOutputContainer->Add(new TH2F("hPi0M11","Pairs in modules",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
257   fOutputContainer->Add(new TH2F("hPi0M12","Pairs in modules",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
258   fOutputContainer->Add(new TH2F("hPi0M13","Pairs in modules",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
259   fOutputContainer->Add(new TH2F("hPi0M22","Pairs in modules",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
260   fOutputContainer->Add(new TH2F("hPi0M23","Pairs in modules",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
261   fOutputContainer->Add(new TH2F("hPi0M33","Pairs in modules",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
262
263   // Histograms for different centralities
264   char key[55] ;
265   for(Int_t cent=0; cent < fCentEdges.GetSize(); cent++){
266     snprintf(key,55,"hPhotAll_cen%d",cent) ;
267     fOutputContainer->Add(new TH1F(key,"All clusters",nPtPhot,0.,ptPhotMax));
268     snprintf(key,55,"hPhotAllcore_cen%d",cent) ;
269     fOutputContainer->Add(new TH1F(key,"All clusters",nPtPhot,0.,ptPhotMax));
270     snprintf(key,55,"hPhotAllwou_cen%d",cent) ;
271     fOutputContainer->Add(new TH1F(key,"All clusters",nPtPhot,0.,ptPhotMax));
272     snprintf(key,55,"hPhotDisp_cen%d",cent) ;
273     fOutputContainer->Add(new TH1F(key,"Disp clusters",nPtPhot,0.,ptPhotMax));
274     snprintf(key,55,"hPhotDisp2_cen%d",cent) ;
275     fOutputContainer->Add(new TH1F(key,"Disp clusters",nPtPhot,0.,ptPhotMax));
276     snprintf(key,55,"hPhotDispcore_cen%d",cent) ;
277     fOutputContainer->Add(new TH1F(key,"Disp clusters",nPtPhot,0.,ptPhotMax));
278     snprintf(key,55,"hPhotDispwou_cen%d",cent) ;
279     fOutputContainer->Add(new TH1F(key,"Disp clusters",nPtPhot,0.,ptPhotMax));
280     snprintf(key,55,"hPhotCPV_cen%d",cent) ;
281     fOutputContainer->Add(new TH1F(key,"CPV clusters",nPtPhot,0.,ptPhotMax));
282     snprintf(key,55,"hPhotCPVcore_cen%d",cent) ;
283     fOutputContainer->Add(new TH1F(key,"CPV clusters",nPtPhot,0.,ptPhotMax));
284     snprintf(key,55,"hPhotCPV2_cen%d",cent) ;
285     fOutputContainer->Add(new TH1F(key,"CPV clusters",nPtPhot,0.,ptPhotMax));
286     snprintf(key,55,"hPhotBoth_cen%d",cent) ;
287     fOutputContainer->Add(new TH1F(key,"Both clusters",nPtPhot,0.,ptPhotMax));
288     snprintf(key,55,"hPhotBothcore_cen%d",cent) ;
289     fOutputContainer->Add(new TH1F(key,"Both clusters",nPtPhot,0.,ptPhotMax));
290
291     snprintf(key,55,"hPi0All_cen%d",cent) ;
292     fOutputContainer->Add(new TH2F(key,"All clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
293     snprintf(key,55,"hPi0Allcore_cen%d",cent) ;
294     fOutputContainer->Add(new TH2F(key,"All clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
295     snprintf(key,55,"hPi0Allwou_cen%d",cent) ;
296     fOutputContainer->Add(new TH2F(key,"All clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
297     snprintf(key,55,"hPi0Disp_cen%d",cent) ;
298     fOutputContainer->Add(new TH2F(key,"Disp clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
299     snprintf(key,55,"hPi0Disp2_cen%d",cent) ;
300     fOutputContainer->Add(new TH2F(key,"Disp clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
301     snprintf(key,55,"hPi0Dispcore_cen%d",cent) ;
302     fOutputContainer->Add(new TH2F(key,"Disp clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
303     snprintf(key,55,"hPi0Dispwou_cen%d",cent) ;
304     fOutputContainer->Add(new TH2F(key,"Disp clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
305     snprintf(key,55,"hPi0CPV_cen%d",cent) ;
306     fOutputContainer->Add(new TH2F(key,"CPV clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
307     snprintf(key,55,"hPi0CPVcore_cen%d",cent) ;
308     fOutputContainer->Add(new TH2F(key,"CPV clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
309     snprintf(key,55,"hPi0CPV2_cen%d",cent) ;
310     fOutputContainer->Add(new TH2F(key,"CPV clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
311     snprintf(key,55,"hPi0Both_cen%d",cent) ;
312     fOutputContainer->Add(new TH2F(key,"Both clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
313     snprintf(key,55,"hPi0Bothcore_cen%d",cent) ;
314     fOutputContainer->Add(new TH2F(key,"Both clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
315
316     snprintf(key,55,"hPi0All_a07_cen%d",cent) ;
317     fOutputContainer->Add(new TH2F(key,"All clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
318     snprintf(key,55,"hPi0Disp_a07_cen%d",cent) ;
319     fOutputContainer->Add(new TH2F(key,"Disp clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
320     snprintf(key,55,"hPi0CPV_a07_cen%d",cent) ;
321     fOutputContainer->Add(new TH2F(key,"CPV clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
322     snprintf(key,55,"hPi0CPV2_a07_cen%d",cent) ;
323     fOutputContainer->Add(new TH2F(key,"CPV clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
324     snprintf(key,55,"hPi0Both_a07_cen%d",cent) ;
325     fOutputContainer->Add(new TH2F(key,"Both clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
326
327     snprintf(key,55,"hSingleAll_cen%d",cent) ;
328     fOutputContainer->Add(new TH2F(key,"All clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
329     snprintf(key,55,"hSingleAllcore_cen%d",cent) ;
330     fOutputContainer->Add(new TH2F(key,"All clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
331     snprintf(key,55,"hSingleAllwou_cen%d",cent) ;
332     fOutputContainer->Add(new TH2F(key,"All clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
333     snprintf(key,55,"hSingleDisp_cen%d",cent) ;
334     fOutputContainer->Add(new TH2F(key,"Disp clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
335     snprintf(key,55,"hSingleDisp2_cen%d",cent) ;
336     fOutputContainer->Add(new TH2F(key,"Disp clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
337     snprintf(key,55,"hSingleDispcore_cen%d",cent) ;
338     fOutputContainer->Add(new TH2F(key,"Disp clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
339     snprintf(key,55,"hSingleDispwou_cen%d",cent) ;
340     fOutputContainer->Add(new TH2F(key,"Disp clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
341     snprintf(key,55,"hSingleCPV_cen%d",cent) ;
342     fOutputContainer->Add(new TH2F(key,"CPV clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
343     snprintf(key,55,"hSingleCPVcore_cen%d",cent) ;
344     fOutputContainer->Add(new TH2F(key,"CPV clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
345     snprintf(key,55,"hSingleCPV2_cen%d",cent) ;
346     fOutputContainer->Add(new TH2F(key,"CPV clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
347     snprintf(key,55,"hSingleBoth_cen%d",cent) ;
348     fOutputContainer->Add(new TH2F(key,"Both clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
349     snprintf(key,55,"hSingleBothcore_cen%d",cent) ;
350     fOutputContainer->Add(new TH2F(key,"Both clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
351
352
353     snprintf(key,55,"hMiPi0All_cen%d",cent) ;
354     fOutputContainer->Add(new TH2F(key,"All clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
355     snprintf(key,55,"hMiPi0Allcore_cen%d",cent) ;
356     fOutputContainer->Add(new TH2F(key,"All clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
357     snprintf(key,55,"hMiPi0Allwou_cen%d",cent) ;
358     fOutputContainer->Add(new TH2F(key,"All clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
359     snprintf(key,55,"hMiPi0Disp_cen%d",cent) ;
360     fOutputContainer->Add(new TH2F(key,"Disp clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
361     snprintf(key,55,"hMiPi0Disp2_cen%d",cent) ;
362     fOutputContainer->Add(new TH2F(key,"Disp clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
363     snprintf(key,55,"hMiPi0Dispwou_cen%d",cent) ;
364     fOutputContainer->Add(new TH2F(key,"Disp clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
365     snprintf(key,55,"hMiPi0Dispcore_cen%d",cent) ;
366     fOutputContainer->Add(new TH2F(key,"Disp clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
367     snprintf(key,55,"hMiPi0CPV_cen%d",cent) ;
368     fOutputContainer->Add(new TH2F(key,"CPV clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
369     snprintf(key,55,"hMiPi0CPVcore_cen%d",cent) ;
370     fOutputContainer->Add(new TH2F(key,"CPV clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
371     snprintf(key,55,"hMiPi0CPV2_cen%d",cent) ;
372     fOutputContainer->Add(new TH2F(key,"CPV clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
373     snprintf(key,55,"hMiPi0Both_cen%d",cent) ;
374     fOutputContainer->Add(new TH2F(key,"Both clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
375     snprintf(key,55,"hMiPi0Bothcore_cen%d",cent) ;
376     fOutputContainer->Add(new TH2F(key,"Both clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
377
378     snprintf(key,55,"hMiPi0All_a07_cen%d",cent) ;
379     fOutputContainer->Add(new TH2F(key,"All clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
380     snprintf(key,55,"hMiPi0Disp_a07_cen%d",cent) ;
381     fOutputContainer->Add(new TH2F(key,"Disp clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
382     snprintf(key,55,"hMiPi0CPV_a07_cen%d",cent) ;
383     fOutputContainer->Add(new TH2F(key,"CPV clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
384     snprintf(key,55,"hMiPi0CPV2_a07_cen%d",cent) ;
385     fOutputContainer->Add(new TH2F(key,"CPV clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
386     snprintf(key,55,"hMiPi0Both_a07_cen%d",cent) ;
387     fOutputContainer->Add(new TH2F(key,"Both clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
388
389     snprintf(key,55,"hMiSingleAll_cen%d",cent) ;
390     fOutputContainer->Add(new TH2F(key,"All clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
391     snprintf(key,55,"hMiSingleAllwou_cen%d",cent) ;
392     fOutputContainer->Add(new TH2F(key,"All clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
393     snprintf(key,55,"hMiSingleAllcore_cen%d",cent) ;
394     fOutputContainer->Add(new TH2F(key,"All clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
395     snprintf(key,55,"hMiSingleDisp_cen%d",cent) ;
396     fOutputContainer->Add(new TH2F(key,"Disp clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
397     snprintf(key,55,"hMiSingleDisp2_cen%d",cent) ;
398     fOutputContainer->Add(new TH2F(key,"Disp clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
399     snprintf(key,55,"hMiSingleDispwou_cen%d",cent) ;
400     fOutputContainer->Add(new TH2F(key,"Disp clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
401     snprintf(key,55,"hMiSingleDispcore_cen%d",cent) ;
402     fOutputContainer->Add(new TH2F(key,"Disp clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
403     snprintf(key,55,"hMiSingleCPV_cen%d",cent) ;
404     fOutputContainer->Add(new TH2F(key,"CPV clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
405     snprintf(key,55,"hMiSingleCPVcore_cen%d",cent) ;
406     fOutputContainer->Add(new TH2F(key,"CPV clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
407     snprintf(key,55,"hMiSingleCPV2_cen%d",cent) ;
408     fOutputContainer->Add(new TH2F(key,"CPV clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
409     snprintf(key,55,"hMiSingleBoth_cen%d",cent) ;
410     fOutputContainer->Add(new TH2F(key,"Both clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
411     snprintf(key,55,"hMiSingleBothcore_cen%d",cent) ;
412     fOutputContainer->Add(new TH2F(key,"Both clusters",nM,mMin,mMax,nPtPhot,0.,ptPhotMax));
413   }
414
415
416
417   const Int_t nPt      = 20;
418   const Double_t xPt[21]={0.6,1.,1.5,2.,2.5,3.,3.5,4.,4.5,5.,5.5,6.,7.,8.,9.,10.,12.,14.,16.,18.,20.} ;
419   const Int_t nPhi=10 ;
420   Double_t xPhi[nPhi+1] ;
421   for(Int_t i=0;i<=nPhi;i++)
422     xPhi[i]=i*TMath::Pi() /nPhi ;
423   const Int_t nMm=200 ;
424   Double_t xM[nMm+1] ;
425   for(Int_t i=0;i<=nMm;i++)
426     xM[i]=i*0.5 /nMm;
427
428   char phiTitle[15] ;
429   for(Int_t iRP=0; iRP<3; iRP++){
430     if(iRP==0)
431       snprintf(phiTitle,15,"TPC") ;
432     if(iRP==1)
433       snprintf(phiTitle,15,"V0A") ;
434     if(iRP==2)
435       snprintf(phiTitle,15,"V0C") ;
436     for(Int_t cent=0; cent<fCentEdges.GetSize(); cent++){
437       snprintf(key,55,"hPhotPhi%sAll_cen%d",phiTitle,cent) ;
438       fOutputContainer->Add(new TH2F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nPt,xPt,nPhi,xPhi));
439       snprintf(key,55,"hPhotPhi%sAllcore_cen%d",phiTitle,cent) ;
440       fOutputContainer->Add(new TH2F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nPt,xPt,nPhi,xPhi));
441       snprintf(key,55,"hPhotPhi%sDisp_cen%d",phiTitle,cent) ;
442       fOutputContainer->Add(new TH2F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nPt,xPt,nPhi,xPhi));
443       snprintf(key,55,"hPhotPhi%sDispcore_cen%d",phiTitle,cent) ;
444       fOutputContainer->Add(new TH2F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nPt,xPt,nPhi,xPhi));
445       snprintf(key,55,"hPhotPhi%sCPV_cen%d",phiTitle,cent) ;
446       fOutputContainer->Add(new TH2F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nPt,xPt,nPhi,xPhi));
447       snprintf(key,55,"hPhotPhi%sCPVcore_cen%d",phiTitle,cent) ;
448       fOutputContainer->Add(new TH2F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nPt,xPt,nPhi,xPhi));
449       snprintf(key,55,"hPhotPhi%sBoth_cen%d",phiTitle,cent) ;
450       fOutputContainer->Add(new TH2F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nPt,xPt,nPhi,xPhi));
451       snprintf(key,55,"hPhotPhi%sBothcore_cen%d",phiTitle,cent) ;
452       fOutputContainer->Add(new TH2F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nPt,xPt,nPhi,xPhi));
453
454       //Pions
455       snprintf(key,55,"hMassPt%sAll_cen%d",phiTitle,cent) ;
456       fOutputContainer->Add(new TH3F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nMm,xM,nPt,xPt,nPhi,xPhi));
457       snprintf(key,55,"hMassPt%sAllcore_cen%d",phiTitle,cent) ;
458       fOutputContainer->Add(new TH3F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nMm,xM,nPt,xPt,nPhi,xPhi));
459       snprintf(key,55,"hMassPt%sCPV_cen%d",phiTitle,cent) ;
460       fOutputContainer->Add(new TH3F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nMm,xM,nPt,xPt,nPhi,xPhi));
461       snprintf(key,55,"hMassPt%sCPVcore_cen%d",phiTitle,cent) ;
462       fOutputContainer->Add(new TH3F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nMm,xM,nPt,xPt,nPhi,xPhi));
463       snprintf(key,55,"hMassPt%sDisp_cen%d",phiTitle,cent) ;
464       fOutputContainer->Add(new TH3F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nMm,xM,nPt,xPt,nPhi,xPhi));
465       snprintf(key,55,"hMassPt%sDispcore_cen%d",phiTitle,cent) ;
466       fOutputContainer->Add(new TH3F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nMm,xM,nPt,xPt,nPhi,xPhi));
467       snprintf(key,55,"hMassPt%sBoth_cen%d",phiTitle,cent) ;
468       fOutputContainer->Add(new TH3F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nMm,xM,nPt,xPt,nPhi,xPhi));
469       snprintf(key,55,"hMassPt%sBothcore_cen%d",phiTitle,cent) ;
470       fOutputContainer->Add(new TH3F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nMm,xM,nPt,xPt,nPhi,xPhi));
471
472       //Mixed
473       snprintf(key,55,"hMiMassPt%sAll_cen%d",phiTitle,cent) ;
474       fOutputContainer->Add(new TH3F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nMm,xM,nPt,xPt,nPhi,xPhi));
475       snprintf(key,55,"hMiMassPt%sAllcore_cen%d",phiTitle,cent) ;
476       fOutputContainer->Add(new TH3F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nMm,xM,nPt,xPt,nPhi,xPhi));
477       snprintf(key,55,"hMiMassPt%sCPV_cen%d",phiTitle,cent) ;
478       fOutputContainer->Add(new TH3F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nMm,xM,nPt,xPt,nPhi,xPhi));
479       snprintf(key,55,"hMiMassPt%sCPVcore_cen%d",phiTitle,cent) ;
480       fOutputContainer->Add(new TH3F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nMm,xM,nPt,xPt,nPhi,xPhi));
481       snprintf(key,55,"hMiMassPt%sDisp_cen%d",phiTitle,cent) ;
482       fOutputContainer->Add(new TH3F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nMm,xM,nPt,xPt,nPhi,xPhi));
483       snprintf(key,55,"hMiMassPt%sDispcore_cen%d",phiTitle,cent) ;
484       fOutputContainer->Add(new TH3F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nMm,xM,nPt,xPt,nPhi,xPhi));
485       snprintf(key,55,"hMiMassPt%sBoth_cen%d",phiTitle,cent) ;
486       fOutputContainer->Add(new TH3F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nMm,xM,nPt,xPt,nPhi,xPhi));
487       snprintf(key,55,"hMiMassPt%sBothcore_cen%d",phiTitle,cent) ;
488       fOutputContainer->Add(new TH3F(key,"(M,p_{T},d#phi)_{#gamma#gamma}" ,nMm,xM,nPt,xPt,nPhi,xPhi));
489     }
490   }
491   
492   // Setup photon lists
493   Int_t kapacity = kNVtxZBins * GetNumberOfCentralityBins() * fNEMRPBins;
494   fCaloPhotonsPHOSLists = new TObjArray(kapacity);
495   fCaloPhotonsPHOSLists->SetOwner();
496   
497   PostData(1, fOutputContainer);
498 }
499
500 //________________________________________________________________________
501 void AliAnalysisTaskPi0Flow::UserExec(Option_t *)
502 {
503   // Main loop, called for each event
504   // Analyze ESD/AOD
505
506
507   // Step 0: Event Objects
508   fEvent = GetEvent();
509   fEventESD = dynamic_cast<AliESDEvent*> (fEvent);
510   fEventAOD = dynamic_cast<AliAODEvent*> (fEvent);
511   fMCStack = GetMCStack();
512   LogProgress(0);
513
514
515   // Step 1: Run Number, Misalignment Matrix, and Calibration
516   // fRunNumber, fInternalRunNumber, fMultV0, fV0Cpol, fV0Apol, fMeanQ, fWidthQ
517   if( fRunNumber != fEvent->GetRunNumber()) { // Check run number
518     // this should run only at first call of UserExec(),
519     // or if task runs over multiple runs, which should not occur in normal use.
520
521     // if run number has changed, set run variables
522     fRunNumber = fEvent->GetRunNumber();
523     fInternalRunNumber = ConvertToInternalRunNumber(fRunNumber);
524     // then set misalignment and V0 calibration
525     SetGeometry();
526     SetMisalignment();
527     SetV0Calibration();
528     SetESDTrackCuts();
529     SetPHOSCalibData();
530     SetFlatteningData();
531   }
532   LogProgress(1);
533   LogSelection(0, fInternalRunNumber);
534
535
536   // Step 2: Vertex
537   // fVertex, fVertexVector, fVtxBin
538   SetVertex();
539   if( RejectEventVertex() ) {
540     PostData(1, fOutputContainer);
541     return; // Reject!
542   }
543   LogProgress(2);
544
545 // Step 3:
546 //   if(event->IsPileupFromSPD()){
547 //     PostData(1, fOutputContainer);
548 //     return; // Reject!
549 //   }
550   LogProgress(3);
551
552
553   // Step 4: Centrality
554   // fCentralityV0M, fCentBin
555   SetCentrality();
556   if( RejectCentrality() ){
557     PostData(1, fOutputContainer);
558     return; // Reject! 
559   }
560   LogProgress(4);
561
562
563   // Step 5: Reaction Plane
564   // fHaveTPCRP, fRP, fRPV0A, fRPV0C, fRPBin
565   EvalReactionPlane(); //TODO: uncomment this, or at least deal with it
566   EvalV0ReactionPlane(); //TODO: uncomment this, or at least deal with it
567   fEMRPBin = GetRPBin(); //TODO: uncomment this, or at least deal with it
568   LogProgress(5);
569
570
571   // Step 6: MC
572   //  ProcessMC() ;
573   LogProgress(6);
574
575
576   // Step 7: QA PHOS cells
577   FillPHOSCellQAHists();
578   LogProgress(7);
579
580
581   // Step 8: Event Photons (PHOS Clusters) selection
582   SelectPhotonClusters();
583   FillSelectedClusterHistograms();
584   LogProgress(8);
585
586   if( ! fCaloPhotonsPHOS->GetEntriesFast() )
587     return;
588   else
589     LogSelection(6, fInternalRunNumber);
590
591
592   // Step 9: Consider pi0 (photon/cluster) pairs.
593   ConsiderPi0s();
594   LogProgress(9);
595
596   // Step 10; Mixing
597   ConsiderPi0sMix();
598   LogProgress(10);
599   
600   // Step 11: Update lists
601   UpdateLists();
602   LogProgress(11);
603
604   
605   // Post output data.
606   PostData(1, fOutputContainer);
607 }
608
609 //________________________________________________________________________
610 // void AliAnalysisTaskPi0Flow::Terminate(Option_t *)
611 // {
612 //   // Draw result to the screen
613 //   // Called once at the end of the query
614 //   // new TCanvas;
615 //   // TH1 * hTotSelEvents = dynamic_cast<TH1*>(fOutputContainer->FindObject("hTotSelEvents"));
616 //   // hTotSelEvents->Draw();
617 // }
618 //________________________________________________________________________
619 void AliAnalysisTaskPi0Flow::SetCentralityBinning(const TArrayD& edges, const TArrayI& nMixed)
620 {
621   // Define centrality bins by their edges
622   if( edges.At(0) < 0.) AliFatal("lower edge less then 0");
623   if( 90. < edges.At(edges.GetSize()-1)  ) AliFatal("upper edge larger then 90.");
624   for(int i=0; i<edges.GetSize()-1; ++i)
625     if(edges.At(i) > edges.At(i+1)) AliFatal("edges are not sorted");
626   if( edges.GetSize() != nMixed.GetSize()+1) AliFatal("edges and nMixed don't have appropriate relative sizes");
627   
628   fCentEdges = edges;
629   fCentNMixed = nMixed;
630 }
631
632
633
634 //________________________________________________________________________
635 void AliAnalysisTaskPi0Flow::SetPHOSBadMap(Int_t mod, TH2I* badMapHist)
636   {
637     if(fPHOSBadMap[mod])
638       delete fPHOSBadMap[mod];
639
640     fPHOSBadMap[mod]=new TH2I(*badMapHist);
641     if(fDebug)
642       AliInfo(Form("Setting Bad Map Histogram  %s",fPHOSBadMap[mod]->GetName()));
643   }
644
645 //________________________________________________________________________
646 Bool_t AliAnalysisTaskPi0Flow::IsGoodChannel(const char * det, Int_t mod, Int_t ix, Int_t iz)
647 {
648   //Check if this channel belogs to the good ones
649
650   if(strcmp(det,"PHOS")==0){
651     if(mod>5 || mod<1){
652       AliError(Form("No bad map for PHOS module %d",mod)) ;
653       return kTRUE ;
654     }
655     if(!fPHOSBadMap[mod]){
656       AliError(Form("No Bad map for PHOS module %d, !fPHOSBadMap[mod]",mod)) ;
657       return kTRUE ;
658     }
659     if(fPHOSBadMap[mod]->GetBinContent(ix,iz)>0)
660       return kFALSE ;
661     else
662       return kTRUE ;
663   }
664   else{
665     AliError(Form("Can not find bad channels for detector %s ",det)) ;
666   }
667
668   //Remove 6 noisy channels in run 139036, LHC10h
669   if( 139036 == fRunNumber
670     && mod==1
671     && (ix==9||ix==10||ix==11)
672     && (iz==45 || iz==46))
673     return kFALSE;
674
675   return kTRUE ;
676 }
677 //_____________________________________________________________________________
678 void AliAnalysisTaskPi0Flow::FillPHOSCellQAHists()
679 {
680   // Fill cell occupancy per module
681
682   AliVCaloCells * cells = fEvent->GetPHOSCells();
683
684   FillHistogram("hCenPHOSCells",fCentralityV0M,cells->GetNumberOfCells()) ;
685   FillHistogram("hCenTrack",fCentralityV0M,fEvent->GetNumberOfTracks()) ;
686
687
688   Int_t nCellModule[3] = {0,0,0};
689   for (Int_t iCell=0; iCell<cells->GetNumberOfCells(); iCell++) {
690     Int_t cellAbsId = cells->GetCellNumber(iCell);
691     Int_t relId[4] = {0,0,0,0};
692     fPHOSGeo->AbsToRelNumbering(cellAbsId,relId);
693     Int_t mod1  = relId[0];
694     Int_t cellX = relId[2];
695     Int_t cellZ = relId[3] ;
696     Float_t energy = cells->GetAmplitude(iCell);
697     FillHistogram("hCellEnergy",energy);
698     if(mod1==1) {
699       nCellModule[0]++;
700       FillHistogram("hCellEnergyM1",cells->GetAmplitude(iCell));
701       FillHistogram("hCellNXZM1",cellX,cellZ,1.);
702       FillHistogram("hCellEXZM1",cellX,cellZ,energy);
703     }
704     else if (mod1==2) {
705       nCellModule[1]++;
706       FillHistogram("hCellEnergyM2",cells->GetAmplitude(iCell));
707       FillHistogram("hCellNXZM2",cellX,cellZ,1.);
708       FillHistogram("hCellEXZM2",cellX,cellZ,energy);
709     }
710     else if (mod1==3) {
711       nCellModule[2]++;
712       FillHistogram("hCellEnergyM3",cells->GetAmplitude(iCell));
713       FillHistogram("hCellNXZM3",cellX,cellZ,1.);
714       FillHistogram("hCellEXZM3",cellX,cellZ,energy);
715     }
716   }
717   FillHistogram("hCellMultEventM1",nCellModule[0]);
718   FillHistogram("hCellMultEventM2",nCellModule[1]);
719   FillHistogram("hCellMultEventM3",nCellModule[2]);
720
721 }
722 //_____________________________________________________________________________
723 void AliAnalysisTaskPi0Flow::SelectPhotonClusters()
724 {
725   // clear (or create) array for holding events photons/clusters
726   if(fCaloPhotonsPHOS)
727     fCaloPhotonsPHOS->Clear();
728   else {
729     fCaloPhotonsPHOS = new TObjArray(200);
730     fCaloPhotonsPHOS->SetOwner();
731   }
732
733   
734   AliVCaloCells* cells = dynamic_cast<AliVCaloCells*> (fEvent->GetPHOSCells());
735   for (Int_t i=0; i<fEvent->GetNumberOfCaloClusters(); i++) {
736     AliVCluster *clu = fEvent->GetCaloCluster(i);
737
738     if ( !clu->IsPHOS() || clu->E()< kMinClusterEnergy) continue; // reject cluster
739
740     // check if cell/channel is good.
741     Float_t  position[3];
742     clu->GetPosition(position);
743     TVector3 global(position) ;
744     Int_t relId[4] ;
745     fPHOSGeo->GlobalPos2RelId(global,relId) ;
746     Int_t mod  = relId[0] ;
747     Int_t cellX = relId[2];
748     Int_t cellZ = relId[3] ;
749     if ( !IsGoodChannel("PHOS",mod,cellX,cellZ) )
750       continue ; // reject if not.
751
752
753     FillHistogram("hCluEvsClu", clu->E(), clu->GetNCells()) ;
754
755     if(clu->GetNCells() < kMinNCells) continue ;
756     if(clu->GetM02() < kMinM02)   continue ;
757
758     TLorentzVector lorentzMomentum;
759     Double_t ecore;
760     ecore = CoreEnergy(clu,cells);
761
762     //if ESD, Apply re-Calibreation
763     Double_t origo[3] = {0,0,0}; // don't rely on event vertex, assume (0,0,0)
764     if( fEventESD ) {
765       AliPHOSEsdCluster cluPHOS1( *(AliESDCaloCluster*) (clu) );
766       cluPHOS1.Recalibrate(fPHOSCalibData, dynamic_cast<AliESDCaloCells*> (cells)); // modify the cell energies
767       Reclusterize(&cluPHOS1) ;
768       cluPHOS1.EvalAll(kLogWeight, fVertexVector);         // recalculate the cluster parameters
769       cluPHOS1.SetE(fNonLinCorr->Eval(cluPHOS1.E()));// Users's nonlinearity
770
771       if(cluPHOS1.E()<0.3) continue; // check energy again
772
773       //correct misalignment
774       TVector3 localPos;
775       const Float_t shiftX[6]={0.,-2.3,-2.11,-1.53,0.,0.} ;
776       const Float_t shiftZ[6]={0.,-0.4, 0.52, 0.8,0.,0.} ;
777       fPHOSGeo->Global2Local(localPos,global,mod) ;
778       fPHOSGeo->Local2Global(mod,localPos.X()+shiftX[mod],localPos.Z()+shiftZ[mod],global);
779       position[0]=global.X() ;
780       position[1]=global.Y() ;
781       position[2]=global.Z() ;
782       cluPHOS1.SetPosition(position);
783
784       cluPHOS1.GetMomentum(lorentzMomentum ,origo);
785       
786       //TODO: Check, this may be LHC10h specific:
787       if(mod==2) lorentzMomentum*=135.5/134.0 ;
788       if(mod==3) lorentzMomentum*=135.5/137.2 ;
789       if(mod==2) ecore*=135.5/134.0 ;
790       if(mod==3) ecore*=135.5/137.2 ;
791         
792     }
793     else if (fEventAOD) { // is ! ESD, AOD.
794       AliESDCaloCluster* aodCluster = (AliESDCaloCluster*) (clu);
795       aodCluster->GetMomentum(lorentzMomentum ,origo);
796     }
797     else {
798       AliError("(Calo)Cluster is neither ESD nor AOD");
799       continue;
800     }
801
802
803     char skey[55];
804     snprintf(skey,55,"hCluLowM%d",mod) ;
805     FillHistogram(skey,cellX,cellZ,1.);
806     if(lorentzMomentum.E()>1.5){
807       sprintf(skey,"hCluHighM%d",mod) ;
808       FillHistogram(skey,cellX,cellZ,1.);
809     }
810
811     fCaloPhotonsPHOS->Add(new  AliCaloPhoton(lorentzMomentum.X(),lorentzMomentum.Py(),lorentzMomentum.Z(),lorentzMomentum.E()) );
812     AliCaloPhoton * ph = (AliCaloPhoton*) fCaloPhotonsPHOS->At( fCaloPhotonsPHOS->GetLast() );
813
814     ph->SetModule(mod) ;
815     lorentzMomentum*= ecore/lorentzMomentum.E() ;
816     ph->SetMomV2(&lorentzMomentum) ;
817     ph->SetNCells(clu->GetNCells());
818     ph->SetDispBit(TestLambda(clu->E(),clu->GetM20(),clu->GetM02())) ;
819     ph->SetDisp2Bit(TestLambda2(clu->E(),clu->GetM20(),clu->GetM02())) ;
820     if(ph->IsDispOK()){
821       sprintf(skey,"hCluDispM%d",mod) ;
822       FillHistogram(skey,cellX,cellZ,1.);
823     }
824
825     // Track Matching
826     Double_t dx=clu->GetTrackDx() ;
827     Double_t dz=clu->GetTrackDz() ;
828     Bool_t cpvBit=kTRUE ; //No track matched by default. True means: not from charged, according to veto.
829     Bool_t cpvBit2=kTRUE ; //More Strict criterion
830     if( fEventESD ) {
831       
832       TArrayI * itracks = static_cast<AliESDCaloCluster*> (clu)->GetTracksMatched() ;
833       if(itracks->GetSize()>0){
834         Int_t iTr = itracks->At(0);
835         if(iTr>=0 && iTr<fEvent->GetNumberOfTracks()){
836           AliVParticle* track = fEvent->GetTrack(iTr);
837           Double_t pt = track->Pt() ;
838           Short_t charge = track->Charge() ;
839           Double_t r=TestCPV(dx, dz, pt, charge) ;
840           cpvBit=(r>2.) ;
841           cpvBit2=(r>4.) ;
842         }
843       }
844     }
845     else if ( fEventAOD ) {
846       int nTracksMatched = clu->GetNTracksMatched();
847       if(nTracksMatched > 0) {
848         AliVTrack* track = dynamic_cast<AliVTrack*> (clu->GetTrackMatched(0));
849         if ( track ) {
850           Double_t pt = track->Pt();
851           Short_t charge = track->Charge();
852           Double_t r = TestCPV(dx, dz, pt, charge) ;
853           cpvBit=(r>2.) ;
854           cpvBit2=(r>4.) ;
855         }
856       }
857     }
858     ph->SetCPVBit(cpvBit) ;
859     ph->SetCPV2Bit(cpvBit2) ;
860     if(cpvBit){
861       sprintf(skey,"hCluVetoM%d",mod) ;
862       FillHistogram(skey,cellX,cellZ,1.);
863     }
864     ph->SetEMCx(float(cellX)) ;
865     ph->SetEMCz(float(cellZ)) ;
866     //    ph->SetLambdas(clu->GetM20(),clu->GetM02()) ;
867     ph->SetUnfolded(clu->GetNExMax()<2); // Remember, if it is unfolde
868
869   }
870   FillHistogram("hCenPHOS",fCentralityV0M, fCaloPhotonsPHOS->GetEntriesFast()) ;
871 }
872 //_____________________________________________________________________________
873 void AliAnalysisTaskPi0Flow::FillSelectedClusterHistograms()
874 {
875   for (Int_t i1=0; i1<fCaloPhotonsPHOS->GetEntriesFast(); i1++) {
876     AliCaloPhoton * ph1=(AliCaloPhoton*)fCaloPhotonsPHOS->At(i1) ;
877
878     Double_t dphiA=ph1->Phi()-fRPV0A ;
879     while(dphiA<0)dphiA+=TMath::Pi() ;
880     while(dphiA>TMath::Pi())dphiA-=TMath::Pi() ;
881
882     Double_t dphiC=ph1->Phi()-fRPV0C ;
883     while(dphiC<0)dphiC+=TMath::Pi() ;
884     while(dphiC>TMath::Pi())dphiC-=TMath::Pi() ;
885
886     Double_t dphiT=ph1->Phi()-fRP ;
887     while(dphiT<0)dphiT+=TMath::Pi() ;
888     while(dphiT>TMath::Pi())dphiT-=TMath::Pi() ;
889
890     FillHistogram(Form("hPhotPhiV0AAll_cen%d",fCentBin),ph1->Pt(),dphiA) ;
891     FillHistogram(Form("hPhotPhiV0CAll_cen%d",fCentBin),ph1->Pt(),dphiC) ;
892     if(fHaveTPCRP)
893       FillHistogram(Form("hPhotPhiTPCAll_cen%d",fCentBin),ph1->Pt(),dphiT) ;
894
895     FillHistogram(Form("hPhotAll_cen%d",fCentBin),ph1->Pt()) ;
896     FillHistogram(Form("hPhotAllcore_cen%d",fCentBin),ph1->GetMomV2()->Pt()) ;
897     if(ph1->IsntUnfolded()){
898       FillHistogram(Form("hPhotAllwou_cen%d",fCentBin),ph1->Pt()) ;
899     }
900     if(ph1->IsCPVOK()){
901       FillHistogram(Form("hPhotPhiV0ACPV_cen%d",fCentBin),ph1->Pt(),dphiA) ;
902       FillHistogram(Form("hPhotPhiV0CCPV_cen%d",fCentBin),ph1->Pt(),dphiC) ;
903       if(fHaveTPCRP)
904         FillHistogram(Form("hPhotPhiTPCCPV_cen%d",fCentBin),ph1->Pt(),dphiT) ;
905
906       FillHistogram(Form("hPhotPhiV0ACPVcore_cen%d",fCentBin),ph1->GetMomV2()->Pt(),dphiA) ;
907       FillHistogram(Form("hPhotPhiV0CCPVcore_cen%d",fCentBin),ph1->GetMomV2()->Pt(),dphiC) ;
908       if(fHaveTPCRP)
909         FillHistogram(Form("hPhotPhiTPCCPVcore_cen%d",fCentBin),ph1->GetMomV2()->Pt(),dphiT) ;
910
911       FillHistogram(Form("hPhotCPV_cen%d",fCentBin),ph1->Pt()) ;
912       FillHistogram(Form("hPhotCPVcore_cen%d",fCentBin),ph1->GetMomV2()->Pt()) ;
913     }
914     if(ph1->IsCPV2OK()){
915       FillHistogram(Form("hPhotCPV2_cen%d",fCentBin),ph1->Pt()) ;
916     }
917     if(ph1->IsDispOK()){
918       FillHistogram(Form("hPhotPhiV0ADisp_cen%d",fCentBin),ph1->Pt(),dphiA) ;
919       FillHistogram(Form("hPhotPhiV0CDisp_cen%d",fCentBin),ph1->Pt(),dphiC) ;
920       if(fHaveTPCRP)
921         FillHistogram(Form("hPhotPhiTPCDisp_cen%d",fCentBin),ph1->Pt(),dphiT) ;
922
923       FillHistogram(Form("hPhotPhiV0ADispcore_cen%d",fCentBin),ph1->GetMomV2()->Pt(),dphiA) ;
924       FillHistogram(Form("hPhotPhiV0CDispcore_cen%d",fCentBin),ph1->GetMomV2()->Pt(),dphiC) ;
925       if(fHaveTPCRP)
926         FillHistogram(Form("hPhotPhiTPCDispcore_cen%d",fCentBin),ph1->GetMomV2()->Pt(),dphiT) ;
927
928       FillHistogram(Form("hPhotDisp_cen%d",fCentBin),ph1->Pt()) ;
929       if(ph1->IsDisp2OK()){
930         FillHistogram(Form("hPhotDisp2_cen%d",fCentBin),ph1->Pt()) ;
931       }
932       FillHistogram(Form("hPhotDispcore_cen%d",fCentBin),ph1->GetMomV2()->Pt()) ;
933       if(ph1->IsntUnfolded()){
934         FillHistogram(Form("hPhotDispwou_cen%d",fCentBin),ph1->Pt()) ;
935       }
936       if(ph1->IsCPVOK()){
937         FillHistogram(Form("hPhotPhiV0ABoth_cen%d",fCentBin),ph1->Pt(),dphiA) ;
938         FillHistogram(Form("hPhotPhiV0CBoth_cen%d",fCentBin),ph1->Pt(),dphiC) ;
939         if(fHaveTPCRP)
940           FillHistogram(Form("hPhotPhiTPCBoth_cen%d",fCentBin),ph1->Pt(),dphiT) ;
941
942         FillHistogram(Form("hPhotPhiV0ABothcore_cen%d",fCentBin),ph1->GetMomV2()->Pt(),dphiA) ;
943         FillHistogram(Form("hPhotPhiV0CBothcore_cen%d",fCentBin),ph1->GetMomV2()->Pt(),dphiC) ;
944         if(fHaveTPCRP)
945           FillHistogram(Form("hPhotPhiTPCBothcore_cen%d",fCentBin),ph1->GetMomV2()->Pt(),dphiT) ;
946
947         FillHistogram(Form("hPhotBoth_cen%d",fCentBin),ph1->Pt()) ;
948         FillHistogram(Form("hPhotBothcore_cen%d",fCentBin),ph1->GetMomV2()->Pt()) ;
949       }
950     }
951   }
952 }
953 //_____________________________________________________________________________
954 void AliAnalysisTaskPi0Flow::ConsiderPi0s()
955 {
956   char key[55];
957   for (Int_t i1=0; i1 < fCaloPhotonsPHOS->GetEntriesFast()-1; i1++) {
958     AliCaloPhoton * ph1=(AliCaloPhoton*)fCaloPhotonsPHOS->At(i1) ;
959     for (Int_t i2=i1+1; i2<fCaloPhotonsPHOS->GetEntriesFast(); i2++) {
960       AliCaloPhoton * ph2=(AliCaloPhoton*)fCaloPhotonsPHOS->At(i2) ;
961       TLorentzVector p12  = *ph1  + *ph2;
962       TLorentzVector pv12 = *(ph1->GetMomV2()) + *(ph2->GetMomV2());
963       FillHistogram("hPHOSphi",fCentralityV0M,p12.Pt(),p12.Phi());
964       Double_t dphiA=p12.Phi()-fRPV0A ;
965       while(dphiA<0)dphiA+=TMath::Pi() ;
966       while(dphiA>TMath::Pi())dphiA-=TMath::Pi() ;
967
968       Double_t dphiC=p12.Phi()-fRPV0C ;
969       while(dphiC<0)dphiC+=TMath::Pi() ;
970       while(dphiC>TMath::Pi())dphiC-=TMath::Pi() ;
971
972       Double_t dphiT=p12.Phi()-fRP ;
973       while(dphiT<0)dphiT+=TMath::Pi() ;
974       while(dphiT>TMath::Pi())dphiT-=TMath::Pi() ;
975
976       Double_t a=TMath::Abs((ph1->E()-ph2->E())/(ph1->E()+ph2->E())) ;
977
978       FillHistogram(Form("hMassPtV0AAll_cen%d",fCentBin),p12.M() ,p12.Pt(),dphiA) ;
979       FillHistogram(Form("hMassPtV0CAll_cen%d",fCentBin),p12.M() ,p12.Pt(),dphiC) ;
980       if(fHaveTPCRP)
981         FillHistogram(Form("hMassPtTPCAll_cen%d",fCentBin),p12.M() ,p12.Pt(),dphiT) ;
982
983       FillHistogram(Form("hMassPtV0AAllcore_cen%d",fCentBin),pv12.M() ,pv12.Pt(),dphiA) ;
984       FillHistogram(Form("hMassPtV0CAllcore_cen%d",fCentBin),pv12.M() ,pv12.Pt(),dphiC) ;
985       if(fHaveTPCRP)
986         FillHistogram(Form("hMassPtTPCAllcore_cen%d",fCentBin),pv12.M() ,pv12.Pt(),dphiT) ;
987
988
989       FillHistogram(Form("hPi0All_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
990       FillHistogram(Form("hPi0Allcore_cen%d",fCentBin),pv12.M() ,pv12.Pt()) ;
991       if(ph1->IsntUnfolded() && ph2->IsntUnfolded()){
992         FillHistogram(Form("hPi0Allwou_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
993       }
994
995       FillHistogram(Form("hSingleAll_cen%d",fCentBin),p12.M(),ph1->Pt()) ;
996       FillHistogram(Form("hSingleAll_cen%d",fCentBin),p12.M(),ph2->Pt()) ;
997       FillHistogram(Form("hSingleAllcore_cen%d",fCentBin),pv12.M(),ph1->GetMomV2()->Pt()) ;
998       FillHistogram(Form("hSingleAllcore_cen%d",fCentBin),pv12.M(),ph2->GetMomV2()->Pt()) ;
999       if(ph1->IsntUnfolded())
1000         FillHistogram(Form("hSingleAllwou_cen%d",fCentBin),p12.M(),ph1->Pt()) ;
1001       if(ph2->IsntUnfolded())
1002         FillHistogram(Form("hSingleAllwou_cen%d",fCentBin),p12.M(),ph2->Pt()) ;
1003       if(ph1->IsCPVOK()){
1004         FillHistogram(Form("hSingleCPV_cen%d",fCentBin),p12.M(),ph1->Pt()) ;
1005         FillHistogram(Form("hSingleCPVcore_cen%d",fCentBin),pv12.M(),ph1->GetMomV2()->Pt()) ;
1006       }
1007       if(ph2->IsCPVOK()){
1008         FillHistogram(Form("hSingleCPV_cen%d",fCentBin),p12.M(),ph2->Pt()) ;
1009         FillHistogram(Form("hSingleCPV_cen%d",fCentBin),pv12.M(),ph2->GetMomV2()->Pt()) ;
1010       }
1011       if(ph1->IsCPV2OK()){
1012         FillHistogram(Form("hSingleCPV2_cen%d",fCentBin),p12.M(),ph1->Pt()) ;
1013       }
1014       if(ph2->IsCPV2OK()){
1015         FillHistogram(Form("hSingleCPV2_cen%d",fCentBin),p12.M(),ph2->Pt()) ;
1016       }
1017       if(ph1->IsDispOK()){
1018         FillHistogram(Form("hSingleDisp_cen%d",fCentBin),p12.M(),ph1->Pt()) ;
1019         if(ph1->IsntUnfolded()){
1020           FillHistogram(Form("hSingleDispwou_cen%d",fCentBin),p12.M(),ph1->Pt()) ;
1021         }
1022         FillHistogram(Form("hSingleDispcore_cen%d",fCentBin),pv12.M(),ph1->GetMomV2()->Pt()) ;
1023       }
1024       if(ph2->IsDispOK()){
1025         FillHistogram(Form("hSingleDisp_cen%d",fCentBin),p12.M(),ph2->Pt()) ;
1026         if(ph1->IsntUnfolded()){
1027           FillHistogram(Form("hSingleDispwou_cen%d",fCentBin),p12.M(),ph2->Pt()) ;
1028         }
1029         FillHistogram(Form("hSingleDispcore_cen%d",fCentBin),pv12.M(),ph2->GetMomV2()->Pt()) ;
1030       }
1031       if(ph1->IsDisp2OK()){
1032         FillHistogram(Form("hSingleDisp2_cen%d",fCentBin),p12.M(),ph1->Pt()) ;
1033       }
1034       if(ph2->IsDisp2OK()){
1035         FillHistogram(Form("hSingleDisp2_cen%d",fCentBin),p12.M(),ph2->Pt()) ;
1036       }
1037       if(ph1->IsDispOK() && ph1->IsCPVOK()){
1038         FillHistogram(Form("hSingleBoth_cen%d",fCentBin),p12.M(),ph1->Pt()) ;
1039         FillHistogram(Form("hSingleBothcore_cen%d",fCentBin),pv12.M(),ph1->GetMomV2()->Pt()) ;
1040       }
1041       if(ph2->IsDispOK() && ph2->IsCPVOK()){
1042         FillHistogram(Form("hSingleBoth_cen%d",fCentBin),p12.M(),ph2->Pt()) ;
1043         FillHistogram(Form("hSingleBothcore_cen%d",fCentBin),pv12.M(),ph2->GetMomV2()->Pt()) ;
1044       }
1045
1046
1047       if(a<kAlphaCut){
1048         FillHistogram(Form("hPi0All_a07_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
1049       }
1050
1051       if(ph1->IsCPVOK() && ph2->IsCPVOK()){
1052         snprintf(key,55,"hMassPtCPV_cen%d",fCentBin) ;
1053         FillHistogram(Form("hMassPtV0ACPV_cen%d",fCentBin),p12.M() ,p12.Pt(),dphiA) ;
1054         FillHistogram(Form("hMassPtV0CCPV_cen%d",fCentBin),p12.M() ,p12.Pt(),dphiC) ;
1055         if(fHaveTPCRP)
1056           FillHistogram(Form("hMassPtTPCCPV_cen%d",fCentBin),p12.M() ,p12.Pt(),dphiT) ;
1057
1058         FillHistogram(Form("hMassPtV0ACPVcore_cen%d",fCentBin),pv12.M() ,pv12.Pt(),dphiA) ;
1059         FillHistogram(Form("hMassPtV0CCPVcore_cen%d",fCentBin),pv12.M() ,pv12.Pt(),dphiC) ;
1060         if(fHaveTPCRP)
1061           FillHistogram(Form("hMassPtTPCCPVcore_cen%d",fCentBin),pv12.M() ,pv12.Pt(),dphiT) ;
1062
1063         FillHistogram(Form("hPi0CPV_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
1064         FillHistogram(Form("hPi0CPVcore_cen%d",fCentBin),pv12.M(), pv12.Pt()) ;
1065
1066         if(a<kAlphaCut){
1067           FillHistogram(Form("hPi0CPV_a07_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
1068         }
1069       }
1070       if(ph1->IsCPV2OK() && ph2->IsCPV2OK()){
1071         FillHistogram(Form("hPi0CPV2_cen%d",fCentBin),p12.M(),p12.Pt()) ;
1072         if(a<kAlphaCut){
1073           FillHistogram(Form("hPi0CPV2_a07_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
1074         }
1075       }
1076       if(ph1->IsDispOK() && ph2->IsDispOK()){
1077         snprintf(key,55,"hMassPtDisp_cen%d",fCentBin) ;
1078         FillHistogram(Form("hMassPtV0ADisp_cen%d",fCentBin),p12.M() ,p12.Pt(),dphiA) ;
1079         FillHistogram(Form("hMassPtV0CDisp_cen%d",fCentBin),p12.M() ,p12.Pt(),dphiC) ;
1080         if(fHaveTPCRP)
1081           FillHistogram(Form("hMassPtTPCDisp_cen%d",fCentBin),p12.M() ,p12.Pt(),dphiT) ;
1082
1083         FillHistogram(Form("hMassPtV0ADispcore_cen%d",fCentBin),pv12.M(), pv12.Pt(),dphiA) ;
1084         FillHistogram(Form("hMassPtV0CDispcore_cen%d",fCentBin),pv12.M(), pv12.Pt(),dphiC) ;
1085         if(fHaveTPCRP)
1086           FillHistogram(Form("hMassPtTPCDispcore_cen%d",fCentBin),pv12.M(), pv12.Pt(),dphiT) ;
1087
1088         FillHistogram(Form("hPi0Disp_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
1089         FillHistogram(Form("hPi0Dispcore_cen%d",fCentBin),pv12.M(), pv12.Pt()) ;
1090         if(ph1->IsDisp2OK() && ph2->IsDisp2OK()){
1091           FillHistogram(Form("hPi0Disp2_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
1092         }
1093         if(ph1->IsntUnfolded() && ph2->IsntUnfolded()){
1094           FillHistogram(Form("hPi0Dispwou_cen%d",fCentBin),p12.M(), p12.Pt()) ;
1095         }
1096
1097         if(a<kAlphaCut){
1098           FillHistogram(Form("hPi0Disp_a07_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
1099         }
1100
1101         if(ph1->IsCPVOK() && ph2->IsCPVOK()){
1102           FillHistogram(Form("hMassPtV0ABoth_cen%d",fCentBin),p12.M() ,p12.Pt(),dphiA) ;
1103           FillHistogram(Form("hMassPtV0CBoth_cen%d",fCentBin),p12.M() ,p12.Pt(),dphiC) ;
1104           if(fHaveTPCRP)
1105             FillHistogram(Form("hMassPtTPCBoth_cen%d",fCentBin),p12.M() ,p12.Pt(),dphiT) ;
1106
1107           FillHistogram(Form("hMassPtV0ABothcore_cen%d",fCentBin),pv12.M() ,pv12.Pt(),dphiA) ;
1108           FillHistogram(Form("hMassPtV0CBothcore_cen%d",fCentBin),pv12.M() ,pv12.Pt(),dphiC) ;
1109           if(fHaveTPCRP)
1110             FillHistogram(Form("hMassPtTPCBothcore_cen%d",fCentBin),pv12.M() ,pv12.Pt(),dphiT) ;
1111
1112           FillHistogram(Form("hPi0Both_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
1113           FillHistogram(Form("hPi0Bothcore_cen%d",fCentBin),pv12.M() ,pv12.Pt()) ;
1114
1115           if(a<kAlphaCut){
1116             snprintf(key,55,"hPi0Both_a07_cen%d",fCentBin) ;
1117             FillHistogram(Form("hPi0Both_a07_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
1118           }
1119           if(ph1->Module()==1 && ph2->Module()==1)
1120             FillHistogram("hPi0M11",p12.M(),p12.Pt() );
1121           else if(ph1->Module()==2 && ph2->Module()==2)
1122             FillHistogram("hPi0M22",p12.M(),p12.Pt() );
1123           else if(ph1->Module()==3 && ph2->Module()==3)
1124             FillHistogram("hPi0M33",p12.M(),p12.Pt() );
1125           else if(ph1->Module()==1 && ph2->Module()==2)
1126             FillHistogram("hPi0M12",p12.M(),p12.Pt() );
1127           else if(ph1->Module()==1 && ph2->Module()==3)
1128             FillHistogram("hPi0M13",p12.M(),p12.Pt() );
1129           else if(ph1->Module()==2 && ph2->Module()==3)
1130             FillHistogram("hPi0M23",p12.M(),p12.Pt() );
1131
1132         }
1133       }
1134     } // end of loop i2
1135   } // end of loop i1
1136 }
1137 //_____________________________________________________________________________
1138 void AliAnalysisTaskPi0Flow::ConsiderPi0sMix()
1139 {
1140   char key[55];
1141
1142   TList * arrayList = GetCaloPhotonsPHOSList(fVtxBin, fCentBin, fEMRPBin);
1143
1144   for (Int_t i1=0; i1<fCaloPhotonsPHOS->GetEntriesFast(); i1++) {
1145     AliCaloPhoton * ph1=(AliCaloPhoton*)fCaloPhotonsPHOS->At(i1) ;
1146     for(Int_t evi=0; evi<arrayList->GetEntries();evi++){
1147       TObjArray * mixPHOS = static_cast<TObjArray*>(arrayList->At(evi));
1148       for(Int_t i2=0; i2<mixPHOS->GetEntriesFast();i2++){
1149         AliCaloPhoton * ph2=(AliCaloPhoton*)mixPHOS->At(i2) ;
1150         TLorentzVector p12  = *ph1  + *ph2;
1151         TLorentzVector pv12 = *(ph1->GetMomV2()) + *(ph2->GetMomV2());
1152
1153         Double_t dphiA=p12.Phi()-fRPV0A ;
1154         while(dphiA<0)dphiA+=TMath::Pi() ;
1155         while(dphiA>TMath::Pi())dphiA-=TMath::Pi() ;
1156
1157         Double_t dphiC=p12.Phi()-fRPV0C ;
1158         while(dphiC<0)dphiC+=TMath::Pi() ;
1159         while(dphiC>TMath::Pi())dphiC-=TMath::Pi() ;
1160
1161         Double_t dphiT=p12.Phi()-fRP ;
1162         while(dphiT<0)dphiT+=TMath::Pi() ;
1163         while(dphiT>TMath::Pi())dphiT-=TMath::Pi() ;
1164
1165
1166         Double_t a=TMath::Abs((ph1->E()-ph2->E())/(ph1->E()+ph2->E())) ;
1167
1168         snprintf(key,55,"hMiMassPtAll_cen%d",fCentBin) ;
1169         FillHistogram(Form("hMiMassPtV0AAll_cen%d",fCentBin),p12.M() ,p12.Pt(),dphiA) ;
1170         FillHistogram(Form("hMiMassPtV0CAll_cen%d",fCentBin),p12.M() ,p12.Pt(),dphiC) ;
1171         if(fHaveTPCRP)
1172           FillHistogram(Form("hMiMassPtTPCAll_cen%d",fCentBin),p12.M() ,p12.Pt(),dphiT) ;
1173
1174         FillHistogram(Form("hMiMassPtV0AAllcore_cen%d",fCentBin),pv12.M(), pv12.Pt(), dphiA) ;
1175         FillHistogram(Form("hMiMassPtV0CAllcore_cen%d",fCentBin),pv12.M(), pv12.Pt(), dphiC) ;
1176         if(fHaveTPCRP)
1177           FillHistogram(Form("hMiMassPtTPCAllcore_cen%d",fCentBin),pv12.M(), pv12.Pt(), dphiT) ;
1178
1179         FillHistogram(Form("hMiPi0All_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
1180         FillHistogram(Form("hMiPi0Allcore_cen%d",fCentBin),pv12.M() ,pv12.Pt()) ;
1181         if(ph1->IsntUnfolded() && ph2->IsntUnfolded()){
1182           FillHistogram(Form("hMiPi0Allwou_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
1183         }
1184
1185         FillHistogram(Form("hMiSingleAll_cen%d",fCentBin),p12.M(),ph1->Pt()) ;
1186         FillHistogram(Form("hMiSingleAll_cen%d",fCentBin),p12.M(),ph2->Pt()) ;
1187         FillHistogram(Form("hMiSingleAllcore_cen%d",fCentBin),pv12.M(),ph1->GetMomV2()->Pt()) ;
1188         FillHistogram(Form("hMiSingleAllcore_cen%d",fCentBin),pv12.M(),ph2->GetMomV2()->Pt()) ;
1189         if(ph1->IsntUnfolded())
1190           FillHistogram(Form("hMiSingleAllwou_cen%d",fCentBin),p12.M(),ph1->Pt()) ;
1191         if(ph2->IsntUnfolded())
1192           FillHistogram(Form("hMiSingleAllwou_cen%d",fCentBin),p12.M(),ph2->Pt()) ;
1193         if(ph1->IsCPVOK()){
1194           FillHistogram(Form("hMiSingleCPV_cen%d",fCentBin),p12.M(),ph1->Pt()) ;
1195           FillHistogram(Form("hMiSingleCPVcore_cen%d",fCentBin),pv12.M(),ph1->GetMomV2()->Pt()) ;
1196         }
1197         if(ph2->IsCPVOK()){
1198           FillHistogram(Form("hMiSingleCPV_cen%d",fCentBin),p12.M(),ph2->Pt()) ;
1199           FillHistogram(Form("hMiSingleCPVcore_cen%d",fCentBin),pv12.M(),ph2->GetMomV2()->Pt()) ;
1200         }
1201         if(ph1->IsCPV2OK()){
1202           FillHistogram(Form("hMiSingleCPV2_cen%d",fCentBin),p12.M(),ph1->Pt()) ;
1203         }
1204         if(ph2->IsCPV2OK()){
1205           FillHistogram(Form("hMiSingleCPV2_cen%d",fCentBin),p12.M(),ph2->Pt()) ;
1206         }
1207         if(ph1->IsDispOK()){
1208           FillHistogram(Form("hMiSingleDisp_cen%d",fCentBin),p12.M(),ph1->Pt()) ;
1209           if(ph1->IsntUnfolded()){
1210             FillHistogram(Form("hMiSingleDispwou_cen%d",fCentBin),p12.M(),ph1->Pt()) ;
1211           }
1212           FillHistogram(Form("hMiSingleDispcore_cen%d",fCentBin),pv12.M(),ph1->GetMomV2()->Pt()) ;
1213         }
1214         if(ph2->IsDispOK()){
1215           FillHistogram(Form("hMiSingleDisp_cen%d",fCentBin),p12.M(),ph2->Pt()) ;
1216           if(ph1->IsntUnfolded()){
1217             FillHistogram(Form("hMiSingleDispwou_cen%d",fCentBin),p12.M(),ph2->Pt()) ;
1218           }
1219           FillHistogram(Form("hMiSingleDispcore_cen%d",fCentBin),pv12.M(),ph2->GetMomV2()->Pt()) ;
1220         }
1221         if(ph1->IsDisp2OK()){
1222           FillHistogram(Form("hMiSingleDisp2_cen%d",fCentBin),p12.M(),ph1->Pt()) ;
1223         }
1224         if(ph2->IsDisp2OK()){
1225           FillHistogram(Form("hMiSingleDisp2_cen%d",fCentBin),p12.M(),ph2->Pt()) ;
1226         }
1227         if(ph1->IsDispOK() && ph1->IsCPVOK()){
1228           snprintf(key,55,"hMiSingleBoth_cen%d",fCentBin) ;
1229           FillHistogram(key,p12.M(),ph1->Pt()) ;
1230           snprintf(key,55,"hMiSingleBothcore_cen%d",fCentBin) ;
1231           FillHistogram(key,pv12.M(),ph1->GetMomV2()->Pt()) ;
1232         }
1233         if(ph2->IsDispOK() && ph2->IsCPVOK()){
1234           snprintf(key,55,"hMiSingleBoth_cen%d",fCentBin) ;
1235           FillHistogram(key,p12.M(),ph2->Pt()) ;
1236           snprintf(key,55,"hMiSingleBothcore_cen%d",fCentBin) ;
1237           FillHistogram(key,pv12.M(),ph2->GetMomV2()->Pt()) ;
1238         }
1239
1240
1241
1242         if(a<kAlphaCut){
1243           snprintf(key,55,"hMiPi0All_a07_cen%d",fCentBin) ;
1244           FillHistogram(key,p12.M() ,p12.Pt()) ;
1245         }
1246         if(ph1->IsCPVOK() && ph2->IsCPVOK()){
1247           FillHistogram(Form("hMiMassPtV0ACPV_cen%d",fCentBin),p12.M(), p12.Pt(),dphiA) ;
1248           FillHistogram(Form("hMiMassPtV0CCPV_cen%d",fCentBin),p12.M(), p12.Pt(),dphiC) ;
1249           if(fHaveTPCRP)
1250             FillHistogram(Form("hMiMassPtTPCCPV_cen%d",fCentBin),p12.M(), p12.Pt(),dphiT) ;
1251
1252           FillHistogram(Form("hMiMassPtV0ACPVcore_cen%d",fCentBin),pv12.M(), pv12.Pt(),dphiA) ;
1253           FillHistogram(Form("hMiMassPtV0CCPVcore_cen%d",fCentBin),pv12.M(), pv12.Pt(),dphiC) ;
1254           if(fHaveTPCRP)
1255             FillHistogram(Form("hMiMassPtTPCCPVcore_cen%d",fCentBin),pv12.M(), pv12.Pt(),dphiT) ;
1256
1257           FillHistogram(Form("hMiPi0CPV_cen%d",fCentBin),p12.M(), p12.Pt()) ;
1258           FillHistogram(Form("hMiPi0CPVcore_cen%d",fCentBin),pv12.M(), pv12.Pt()) ;
1259
1260           if(a<kAlphaCut){
1261             FillHistogram(Form("hMiPi0CPV_a07_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
1262           }
1263         }
1264         if(ph1->IsCPV2OK() && ph2->IsCPV2OK()){
1265           FillHistogram(Form("hMiPi0CPV2_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
1266
1267           if(a<kAlphaCut){
1268             FillHistogram(Form("hMiPi0CPV2_a07_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
1269           }
1270         }
1271         if(ph1->IsDispOK() && ph2->IsDispOK()){
1272           FillHistogram(Form("hMiMassPtV0ADisp_cen%d",fCentBin),p12.M(),p12.Pt(),dphiA) ;
1273           FillHistogram(Form("hMiMassPtV0CDisp_cen%d",fCentBin),p12.M(),p12.Pt(),dphiC) ;
1274           if(fHaveTPCRP)
1275             FillHistogram(Form("hMiMassPtTPCDisp_cen%d",fCentBin),p12.M(),p12.Pt(),dphiT) ;
1276
1277           FillHistogram(Form("hMiMassPtV0ADispcore_cen%d",fCentBin),pv12.M(),pv12.Pt(),dphiA) ;
1278           FillHistogram(Form("hMiMassPtV0CDispcore_cen%d",fCentBin),pv12.M(),pv12.Pt(),dphiC) ;
1279           if(fHaveTPCRP)
1280             FillHistogram(Form("hMiMassPtTPCDispcore_cen%d",fCentBin),pv12.M(),pv12.Pt(),dphiT) ;
1281
1282
1283           FillHistogram(Form("hMiPi0Disp_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
1284           FillHistogram(Form("hMiPi0Dispcore_cen%d",fCentBin),pv12.M(),pv12.Pt()) ;
1285           if(ph1->IsntUnfolded() && ph2->IsntUnfolded()){
1286             FillHistogram(Form("hMiPi0Dispwou_cen%d",fCentBin),p12.M(),p12.Pt()) ;
1287           }
1288
1289           if(a<kAlphaCut){
1290             FillHistogram(Form("hMiPi0Disp_a07_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
1291           }
1292           if(ph1->IsCPVOK() && ph2->IsCPVOK()){
1293             FillHistogram(Form("hMiMassPtV0ABoth_cen%d",fCentBin),p12.M(),p12.Pt(),dphiA) ;
1294             FillHistogram(Form("hMiMassPtV0CBoth_cen%d",fCentBin),p12.M(),p12.Pt(),dphiC) ;
1295             if(fHaveTPCRP)
1296               FillHistogram(Form("hMiMassPtTPCBoth_cen%d",fCentBin),p12.M(),p12.Pt(),dphiT) ;
1297
1298             FillHistogram(Form("hMiMassPtV0ABothcore_cen%d",fCentBin),pv12.M(),pv12.Pt(),dphiA) ;
1299             FillHistogram(Form("hMiMassPtV0CBothcore_cen%d",fCentBin),pv12.M(),pv12.Pt(),dphiC) ;
1300             if(fHaveTPCRP)
1301               FillHistogram(Form("hMiMassPtTPCBothcore_cen%d",fCentBin),pv12.M(),pv12.Pt(),dphiT) ;
1302
1303             FillHistogram(Form("hMiPi0Both_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
1304             FillHistogram(Form("hMiPi0Bothcore_cen%d",fCentBin),pv12.M(),pv12.Pt()) ;
1305
1306             if(a<kAlphaCut){
1307               FillHistogram(Form("hMiPi0Both_a07_cen%d",fCentBin),p12.M() ,p12.Pt()) ;
1308             }
1309           }
1310         }
1311       } // end of loop i2
1312     }
1313   } // end of loop i1
1314 }
1315 //_____________________________________________________________________________
1316 void AliAnalysisTaskPi0Flow::UpdateLists()
1317 {
1318   //Now we either add current events to stack or remove
1319   //If no photons in current event - no need to add it to mixed
1320
1321   TList * arrayList = GetCaloPhotonsPHOSList(fVtxBin, fCentBin, fEMRPBin);
1322   if( fDebug >= 2 )
1323     AliInfo( Form("fCentBin=%d, fCentNMixed[]=%d",fCentBin,fCentNMixed[fCentBin]) );
1324   if(fCaloPhotonsPHOS->GetEntriesFast()>0){
1325     arrayList->AddFirst(fCaloPhotonsPHOS) ;
1326     fCaloPhotonsPHOS=0;
1327     if(arrayList->GetEntries() > fCentNMixed[fCentBin]){ // Remove redundant events
1328       TObjArray * tmp = static_cast<TObjArray*>(arrayList->Last()) ;
1329       arrayList->RemoveLast() ;
1330       delete tmp ; // TODO: may conflict with delete done by list being owner.
1331     }
1332   }
1333   else
1334     fCaloPhotonsPHOS->Clear(); // TODO: redundant???
1335 }
1336 //_____________________________________________________________________________
1337 void AliAnalysisTaskPi0Flow::FillHistogram(const char * key,Double_t x)const{
1338   //FillHistogram
1339   TH1 * hist = dynamic_cast<TH1*>(fOutputContainer->FindObject(key)) ;
1340   if(hist)
1341     hist->Fill(x) ;
1342   else
1343     AliError(Form("can not find histogram (of instance TH1) <%s> ",key)) ;
1344 }
1345 //_____________________________________________________________________________
1346 void AliAnalysisTaskPi0Flow::FillHistogram(const char * key,Double_t x,Double_t y)const{
1347   //FillHistogram
1348   TH1 * th1 = dynamic_cast<TH1*> (fOutputContainer->FindObject(key));
1349   if(th1)
1350     th1->Fill(x, y) ;
1351   else
1352     AliError(Form("can not find histogram (of instance TH1) <%s> ",key)) ;
1353 }
1354
1355 //_____________________________________________________________________________
1356 void AliAnalysisTaskPi0Flow::FillHistogram(const char * key,Double_t x,Double_t y, Double_t z) const{
1357   //Fills 1D histograms with key
1358   TObject * obj = fOutputContainer->FindObject(key);
1359   
1360   TH2 * th2 = dynamic_cast<TH2*> (obj);
1361   if(th2) {
1362     th2->Fill(x, y, z) ;
1363     return;
1364   }
1365
1366   TH3 * th3 = dynamic_cast<TH3*> (obj);
1367   if(th3) {
1368     th3->Fill(x, y, z) ;
1369     return;
1370   }
1371   
1372   AliError(Form("can not find histogram (of instance TH2) <%s> ",key)) ;
1373 }
1374
1375 //_____________________________________________________________________________
1376 AliVEvent* AliAnalysisTaskPi0Flow::GetEvent()
1377 {
1378   fEvent = InputEvent();
1379   if( ! fEvent ) {
1380     AliError("Event could not be retrieved");
1381     PostData(1, fOutputContainer);
1382   }
1383   return fEvent;
1384 }
1385
1386
1387 //___________________________________________________________________________
1388 AliStack* AliAnalysisTaskPi0Flow::GetMCStack()
1389 {
1390   fMCStack = 0;
1391   AliVEventHandler* eventHandler = AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler();
1392   if(eventHandler){
1393     AliMCEventHandler* mcEventHandler = dynamic_cast<AliMCEventHandler*> (eventHandler);
1394     if( mcEventHandler)
1395       fMCStack = static_cast<AliMCEventHandler*>(AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler())->MCEvent()->Stack();
1396   }
1397   return fMCStack;
1398 }
1399
1400 //___________________________________________________________________________
1401 Int_t AliAnalysisTaskPi0Flow::GetCentralityBin(Float_t centralityV0M)
1402 {
1403  /* fCentBin=1+Int_t(centralityV0M/100. *kNCenBins) ;
1404   if(centralityV0M < 5. || fCentBin < 0)
1405    fCentBin=0 ;
1406   if(fCentBin > kNCenBins-1)
1407     fCentBin = kNCenBins-1 ;
1408  */
1409   int lastBinUpperIndex = fCentEdges.GetSize() -1;
1410   if( centralityV0M > fCentEdges[lastBinUpperIndex] ) {
1411     if( fDebug >= 1 )
1412       AliWarning( Form("centrality (%f) larger then upper edge of last centrality bin (%f)!", centralityV0M, fCentEdges[lastBinUpperIndex]) );
1413     return lastBinUpperIndex-1;
1414   }
1415   if( centralityV0M < fCentEdges[0] ) {
1416     if( fDebug >= 1 )
1417       AliWarning( Form("centrality (%f) smaller then lower edge of first bin (%f)!", centralityV0M, fCentEdges[0]) );
1418     return 0;
1419   }
1420   
1421   fCentBin = TMath::BinarySearch<Double_t> ( GetNumberOfCentralityBins(), fCentEdges.GetArray(), centralityV0M );
1422   return fCentBin;
1423 }
1424
1425 //___________________________________________________________________________
1426 Int_t AliAnalysisTaskPi0Flow::GetRPBin()
1427 {
1428   Double_t averageRP;
1429   if(fHaveTPCRP)
1430     averageRP = fRPV0A+fRPV0C+fRP /3.;
1431   else
1432     averageRP = fRPV0A+fRPV0C /2.;
1433
1434   fEMRPBin = Int_t(fNEMRPBins*(averageRP)/TMath::Pi());
1435
1436   if(fEMRPBin> (Int_t) fNEMRPBins-1)
1437     fEMRPBin=fNEMRPBins-1 ;
1438   else if(fEMRPBin<0)
1439     fEMRPBin=0;
1440
1441   if ( fDebug >= 2 )
1442     AliInfo(Form("Event Mixing Reaction Plane bin is: %d", fEMRPBin));
1443
1444   return fEMRPBin;
1445 }
1446
1447
1448 //_____________________________________________________________________________
1449 void AliAnalysisTaskPi0Flow::LogProgress(int step)
1450 {
1451   if(fDebug >= 2) {
1452     AliInfo(Form("step %d completed", step));
1453   }
1454   // the +0.5 is not realy neccisarry, but oh well... -henrik
1455   //FillHistogram("hSelEvents", step+0.5, internalRunNumber-0.5);
1456   //FillHistogram("hTotSelEvents", step+0.5);
1457 }
1458
1459 void AliAnalysisTaskPi0Flow::LogSelection(int step, int internalRunNumber)
1460 {
1461   // if(fDebug > 1) {
1462   //   AliInfo(Form("step %d completed", step));
1463   // }
1464   // the +0.5 is not realy neccisarry, but oh well... -henrik
1465   FillHistogram("hSelEvents", step+0.5, internalRunNumber-0.5);
1466   FillHistogram("hTotSelEvents", step+0.5);
1467 }
1468
1469
1470 //___________________________________________________________________________
1471 Int_t AliAnalysisTaskPi0Flow::ConvertToInternalRunNumber(Int_t run){
1472   if( kLHC11h == fPeriod ) {
1473     switch(run){
1474     case  170593 : return 179 ;
1475     case  170572 : return 178 ;
1476     case  170556 : return 177 ;
1477     case  170552 : return 176 ;
1478     case  170546 : return 175 ;
1479     case  170390 : return 174 ;
1480     case  170389 : return 173 ;
1481     case  170388 : return 172 ;
1482     case  170387 : return 171 ;
1483     case  170315 : return 170 ;
1484     case  170313 : return 169 ;
1485     case  170312 : return 168 ;
1486     case  170311 : return 167 ;
1487     case  170309 : return 166 ;
1488     case  170308 : return 165 ;
1489     case  170306 : return 164 ;
1490     case  170270 : return 163 ;
1491     case  170269 : return 162 ;
1492     case  170268 : return 161 ;
1493     case  170267 : return 160 ;
1494     case  170264 : return 159 ;
1495     case  170230 : return 158 ;
1496     case  170228 : return 157 ;
1497     case  170208 : return 156 ;
1498     case  170207 : return 155 ;
1499     case  170205 : return 154 ;
1500     case  170204 : return 153 ;
1501     case  170203 : return 152 ;
1502     case  170195 : return 151 ;
1503     case  170193 : return 150 ;
1504     case  170163 : return 149 ;
1505     case  170162 : return 148 ;
1506     case  170159 : return 147 ;
1507     case  170155 : return 146 ;
1508     case  170152 : return 145 ;
1509     case  170091 : return 144 ;
1510     case  170089 : return 143 ;
1511     case  170088 : return 142 ;
1512     case  170085 : return 141 ;
1513     case  170084 : return 140 ;
1514     case  170083 : return 139 ;
1515     case  170081 : return 138 ;
1516     case  170040 : return 137 ;
1517     case  170038 : return 136 ;
1518     case  170036 : return 135 ;
1519     case  170027 : return 134 ;
1520     case  169981 : return 133 ;
1521     case  169975 : return 132 ;
1522     case  169969 : return 131 ;
1523     case  169965 : return 130 ;
1524     case  169961 : return 129 ;
1525     case  169956 : return 128 ;
1526     case  169926 : return 127 ;
1527     case  169924 : return 126 ;
1528     case  169923 : return 125 ;
1529     case  169922 : return 124 ;
1530     case  169919 : return 123 ;
1531     case  169918 : return 122 ;
1532     case  169914 : return 121 ;
1533     case  169859 : return 120 ;
1534     case  169858 : return 119 ;
1535     case  169855 : return 118 ;
1536     case  169846 : return 117 ;
1537     case  169838 : return 116 ;
1538     case  169837 : return 115 ;
1539     case  169835 : return 114 ;
1540     case  169683 : return 113 ;
1541     case  169628 : return 112 ;
1542     case  169591 : return 111 ;
1543     case  169590 : return 110 ;
1544     case  169588 : return 109 ;
1545     case  169587 : return 108 ;
1546     case  169586 : return 107 ;
1547     case  169584 : return 106 ;
1548     case  169557 : return 105 ;
1549     case  169555 : return 104 ;
1550     case  169554 : return 103 ;
1551     case  169553 : return 102 ;
1552     case  169550 : return 101 ;
1553     case  169515 : return 100 ;
1554     case  169512 : return 99 ;
1555     case  169506 : return 98 ;
1556     case  169504 : return 97 ;
1557     case  169498 : return 96 ;
1558     case  169475 : return 95 ;
1559     case  169420 : return 94 ;
1560     case  169419 : return 93 ;
1561     case  169418 : return 92 ;
1562     case  169417 : return 91 ;
1563     case  169415 : return 90 ;
1564     case  169411 : return 89 ;
1565     case  169238 : return 88 ;
1566     case  169236 : return 87 ;
1567     case  169167 : return 86 ;
1568     case  169160 : return 85 ;
1569     case  169156 : return 84 ;
1570     case  169148 : return 83 ;
1571     case  169145 : return 82 ;
1572     case  169144 : return 81 ;
1573     case  169143 : return 80 ;
1574     case  169138 : return 79 ;
1575     case  169099 : return 78 ;
1576     case  169094 : return 77 ;
1577     case  169091 : return 76 ;
1578     case  169045 : return 75 ;
1579     case  169044 : return 74 ;
1580     case  169040 : return 73 ;
1581     case  169035 : return 72 ;
1582     case  168992 : return 71 ;
1583     case  168988 : return 70 ;
1584     case  168984 : return 69 ;
1585     case  168826 : return 68 ;
1586     case  168777 : return 67 ;
1587     case  168514 : return 66 ;
1588     case  168512 : return 65 ;
1589     case  168511 : return 64 ;
1590     case  168467 : return 63 ;
1591     case  168464 : return 62 ;
1592     case  168461 : return 61 ;
1593     case  168460 : return 60 ;
1594     case  168458 : return 59 ;
1595     case  168362 : return 58 ;
1596     case  168361 : return 57 ;
1597     case  168356 : return 56 ;
1598     case  168342 : return 55 ;
1599     case  168341 : return 54 ;
1600     case  168325 : return 53 ;
1601     case  168322 : return 52 ;
1602     case  168318 : return 51 ;
1603     case  168311 : return 50 ;
1604     case  168310 : return 49 ;
1605     case  168213 : return 48 ;
1606     case  168212 : return 47 ;
1607     case  168208 : return 46 ;
1608     case  168207 : return 45 ;
1609     case  168206 : return 44 ;
1610     case  168205 : return 43 ;
1611     case  168204 : return 42 ;
1612     case  168203 : return 41 ;
1613     case  168181 : return 40 ;
1614     case  168177 : return 39 ;
1615     case  168175 : return 38 ;
1616     case  168173 : return 37 ;
1617     case  168172 : return 36 ;
1618     case  168171 : return 35 ;
1619     case  168115 : return 34 ;
1620     case  168108 : return 33 ;
1621     case  168107 : return 32 ;
1622     case  168105 : return 31 ;
1623     case  168104 : return 30 ;
1624     case  168103 : return 29 ;
1625     case  168076 : return 28 ;
1626     case  168069 : return 27 ;
1627     case  168068 : return 26 ;
1628     case  168066 : return 25 ;
1629     case  167988 : return 24 ;
1630     case  167987 : return 23 ;
1631     case  167986 : return 22 ;
1632     case  167985 : return 21 ;
1633     case  167921 : return 20 ;
1634     case  167920 : return 19 ;
1635     case  167915 : return 18 ;
1636     case  167909 : return 17 ;
1637     case  167903 : return 16 ;
1638     case  167902 : return 15 ;
1639     case  167818 : return 14 ;
1640     case  167814 : return 13 ;
1641     case  167813 : return 12 ;
1642     case  167808 : return 11 ;
1643     case  167807 : return 10 ;
1644     case  167806 : return 9 ;
1645     case  167713 : return 8 ;
1646     case  167712 : return 7 ;
1647     case  167711 : return 6 ;
1648     case  167706 : return 5 ;
1649     case  167693 : return 4 ;
1650     case  166532 : return 3 ;
1651     case  166530 : return 2 ;
1652     case  166529 : return 1 ;
1653
1654     default : return 199;
1655     }
1656   }
1657   if( kLHC10h == fPeriod ) {
1658     switch(run){
1659     case  139517 : return 137;
1660     case  139514 : return 136;
1661     case  139513 : return 135;
1662     case  139511 : return 134;
1663     case  139510 : return 133;
1664     case  139507 : return 132;
1665     case  139505 : return 131;
1666     case  139504 : return 130;
1667     case  139503 : return 129;
1668     case  139470 : return 128;
1669     case  139467 : return 127;
1670     case  139466 : return 126;
1671     case  139465 : return 125;
1672     case  139440 : return 124;
1673     case  139439 : return 123;
1674     case  139438 : return 122;
1675     case  139437 : return 121;
1676     case  139360 : return 120;
1677     case  139329 : return 119;
1678     case  139328 : return 118;
1679     case  139314 : return 117;
1680     case  139311 : return 116;
1681     case  139310 : return 115;
1682     case  139309 : return 114;
1683     case  139308 : return 113;
1684     case  139173 : return 112;
1685     case  139172 : return 111;
1686     case  139110 : return 110;
1687     case  139107 : return 109;
1688     case  139105 : return 108;
1689     case  139104 : return 107;
1690     case  139042 : return 106;
1691     case  139038 : return 105;
1692     case  139037 : return 104;
1693     case  139036 : return 103;
1694     case  139029 : return 102;
1695     case  139028 : return 101;
1696     case  138983 : return 100;
1697     case  138982 : return 99;
1698     case  138980 : return 98;
1699     case  138979 : return 97;
1700     case  138978 : return 96;
1701     case  138977 : return 95;
1702     case  138976 : return 94;
1703     case  138973 : return 93;
1704     case  138972 : return 92;
1705     case  138965 : return 91;
1706     case  138924 : return 90;
1707     case  138872 : return 89;
1708     case  138871 : return 88;
1709     case  138870 : return 87;
1710     case  138837 : return 86;
1711     case  138830 : return 85;
1712     case  138828 : return 84;
1713     case  138826 : return 83;
1714     case  138796 : return 82;
1715     case  138795 : return 81;
1716     case  138742 : return 80;
1717     case  138732 : return 79;
1718     case  138730 : return 78;
1719     case  138666 : return 77;
1720     case  138662 : return 76;
1721     case  138653 : return 75;
1722     case  138652 : return 74;
1723     case  138638 : return 73;
1724     case  138624 : return 72;
1725     case  138621 : return 71;
1726     case  138583 : return 70;
1727     case  138582 : return 69;
1728     case  138579 : return 68;
1729     case  138578 : return 67;
1730     case  138534 : return 66;
1731     case  138469 : return 65;
1732     case  138442 : return 64;
1733     case  138439 : return 63;
1734     case  138438 : return 62;
1735     case  138396 : return 61;
1736     case  138364 : return 60;
1737     case  138359 : return 59;
1738     case  138275 : return 58;
1739     case  138225 : return 57;
1740     case  138201 : return 56;
1741     case  138200 : return 55;
1742     case  138197 : return 54;
1743     case  138192 : return 53;
1744     case  138190 : return 52;
1745     case  138154 : return 51;
1746     case  138153 : return 50;
1747     case  138151 : return 49;
1748     case  138150 : return 48;
1749     case  138126 : return 47;
1750     case  138125 : return 46;
1751     case  137848 : return 45;
1752     case  137847 : return 44;
1753     case  137844 : return 43;
1754     case  137843 : return 42;
1755     case  137752 : return 41;
1756     case  137751 : return 40;
1757     case  137748 : return 39;
1758     case  137724 : return 38;
1759     case  137722 : return 37;
1760     case  137718 : return 36;
1761     case  137704 : return 35;
1762     case  137693 : return 34;
1763     case  137692 : return 33;
1764     case  137691 : return 32;
1765     case  137689 : return 31;
1766     case  137686 : return 30;
1767     case  137685 : return 29;
1768     case  137639 : return 28;
1769     case  137638 : return 27;
1770     case  137608 : return 26;
1771     case  137595 : return 25;
1772     case  137549 : return 24;
1773     case  137546 : return 23;
1774     case  137544 : return 22;
1775     case  137541 : return 21;
1776     case  137539 : return 20;
1777     case  137531 : return 19;
1778     case  137530 : return 18;
1779     case  137443 : return 17;
1780     case  137441 : return 16;
1781     case  137440 : return 15;
1782     case  137439 : return 14;
1783     case  137434 : return 13;
1784     case  137432 : return 12;
1785     case  137431 : return 11;
1786     case  137430 : return 10;
1787     case  137366 : return 9;
1788     case  137243 : return 8;
1789     case  137236 : return 7;
1790     case  137235 : return 6;
1791     case  137232 : return 5;
1792     case  137231 : return 4;
1793     case  137165 : return 3;
1794     case  137162 : return 2;
1795     case  137161 : return 1;
1796     default : return 199;
1797     }
1798   }
1799   if(kUndefinedPeriod && fDebug >= 1 ) {
1800     AliWarning("Period not defined");
1801   }
1802   return 1;
1803 }
1804 //_____________________________________________________________________________
1805 Bool_t AliAnalysisTaskPi0Flow::TestLambda(Double_t pt,Double_t l1,Double_t l2){
1806
1807   Double_t l2Mean  = 1.53126+9.50835e+06/(1.+1.08728e+07*pt+1.73420e+06*pt*pt) ;
1808   Double_t l1Mean  = 1.12365+0.123770*TMath::Exp(-pt*0.246551)+5.30000e-03*pt ;
1809   Double_t l2Sigma = 6.48260e-02+7.60261e+10/(1.+1.53012e+11*pt+5.01265e+05*pt*pt)+9.00000e-03*pt;
1810   Double_t l1Sigma = 4.44719e-04+6.99839e-01/(1.+1.22497e+00*pt+6.78604e-07*pt*pt)+9.00000e-03*pt;
1811   Double_t c=-0.35-0.550*TMath::Exp(-0.390730*pt) ;
1812   Double_t R2=0.5*(l1-l1Mean)*(l1-l1Mean)/l1Sigma/l1Sigma +
1813     0.5*(l2-l2Mean)*(l2-l2Mean)/l2Sigma/l2Sigma +
1814     0.5*c*(l1-l1Mean)*(l2-l2Mean)/l1Sigma/l2Sigma ;
1815   return (R2<2.5*2.5) ;
1816
1817 }
1818 //_____________________________________________________________________________
1819 Bool_t AliAnalysisTaskPi0Flow::TestLambda2(Double_t pt,Double_t l1,Double_t l2){
1820
1821   Double_t l2Mean  = 1.53126+9.50835e+06/(1.+1.08728e+07*pt+1.73420e+06*pt*pt) ;
1822   Double_t l1Mean  = 1.12365+0.123770*TMath::Exp(-pt*0.246551)+5.30000e-03*pt ;
1823   Double_t l2Sigma = 6.48260e-02+7.60261e+10/(1.+1.53012e+11*pt+5.01265e+05*pt*pt)+9.00000e-03*pt;
1824   Double_t l1Sigma = 4.44719e-04+6.99839e-01/(1.+1.22497e+00*pt+6.78604e-07*pt*pt)+9.00000e-03*pt;
1825   Double_t c=-0.35-0.550*TMath::Exp(-0.390730*pt) ;
1826   Double_t R2=0.5*(l1-l1Mean)*(l1-l1Mean)/l1Sigma/l1Sigma +
1827     0.5*(l2-l2Mean)*(l2-l2Mean)/l2Sigma/l2Sigma +
1828     0.5*c*(l1-l1Mean)*(l2-l2Mean)/l1Sigma/l2Sigma ;
1829   return (R2<1.5*1.5) ;
1830
1831 }
1832 //____________________________________________________________________________
1833 TList* AliAnalysisTaskPi0Flow::GetCaloPhotonsPHOSList(UInt_t vtxBin, UInt_t centBin, UInt_t rpBin)
1834 {
1835   int offset = vtxBin * GetNumberOfCentralityBins() * fNEMRPBins
1836               + centBin * fNEMRPBins
1837               + rpBin;
1838   if( fCaloPhotonsPHOSLists->At(offset) ) { // list exists
1839     TList* list = dynamic_cast<TList*> (fCaloPhotonsPHOSLists->At(offset));
1840     if( ! list )
1841       AliError("object in fCaloPhotonsPHOSLists at %i did not cast");
1842     return list;
1843   }
1844   else {// no list for this bin has been created, yet
1845     TList* list = new TList();
1846     list->SetOwner();
1847     fCaloPhotonsPHOSLists->AddAt(list, offset);
1848     return list;
1849   }
1850 }
1851
1852 //____________________________________________________________________________
1853 Double_t AliAnalysisTaskPi0Flow::TestCPV(Double_t dx, Double_t dz, Double_t pt, Int_t charge){
1854   //Parameterization of LHC10h period
1855   //_true if neutral_
1856
1857   Double_t meanX=0;
1858   Double_t meanZ=0.;
1859   Double_t sx=TMath::Min(5.4,2.59719e+02*TMath::Exp(-pt/1.02053e-01)+
1860                          6.58365e-01*5.91917e-01*5.91917e-01/((pt-9.61306e-01)*(pt-9.61306e-01)+5.91917e-01*5.91917e-01)+1.59219);
1861   Double_t sz=TMath::Min(2.75,4.90341e+02*1.91456e-02*1.91456e-02/(pt*pt+1.91456e-02*1.91456e-02)+1.60) ;
1862   AliVEvent *event = InputEvent();
1863   Double_t mf = 0.; //
1864   if(event) mf = event->GetMagneticField(); //Positive for ++ and negative for --
1865
1866   if(mf<0.){ //field --
1867     meanZ = -0.468318 ;
1868     if(charge>0)
1869       meanX=TMath::Min(7.3, 3.89994*1.20679*1.20679/(pt*pt+1.20679*1.20679)+0.249029+2.49088e+07*TMath::Exp(-pt*3.33650e+01)) ;
1870     else
1871       meanX=-TMath::Min(7.7,3.86040*0.912499*0.912499/(pt*pt+0.912499*0.912499)+1.23114+4.48277e+05*TMath::Exp(-pt*2.57070e+01)) ;
1872   }
1873   else{ //Field ++
1874     meanZ= -0.468318;
1875     if(charge>0)
1876       meanX=-TMath::Min(8.0,3.86040*1.31357*1.31357/(pt*pt+1.31357*1.31357)+0.880579+7.56199e+06*TMath::Exp(-pt*3.08451e+01)) ;
1877     else
1878       meanX= TMath::Min(6.85, 3.89994*1.16240*1.16240/(pt*pt+1.16240*1.16240)-0.120787+2.20275e+05*TMath::Exp(-pt*2.40913e+01)) ;
1879   }
1880
1881   Double_t rz=(dz-meanZ)/sz ;
1882   Double_t rx=(dx-meanX)/sx ;
1883   return TMath::Sqrt(rx*rx+rz*rz) ;
1884 }
1885 //____________________________________________________________________________
1886 void AliAnalysisTaskPi0Flow::SetFlatteningData(){
1887   //Read objects with flattening parameters 
1888   AliOADBContainer flatContainer("phosFlat");
1889   flatContainer.InitFromFile(fEPcalibFileName.Data(),"phosFlat");
1890   TObjArray *maps = (TObjArray*)flatContainer.GetObject(fRunNumber,"phosFlat");
1891   if(!maps){
1892       AliError(Form("Can not read Flattening for run %d. \n From file >%s<\n",fRunNumber,fEPcalibFileName.Data())) ;    
1893   }
1894   else{
1895     AliInfo(Form("Setting PHOS flattening with name %s \n",maps->GetName())) ;
1896     AliPHOSEPFlattener * h = (AliPHOSEPFlattener*)maps->At(0) ;  
1897     if(fTPCFlat) delete fTPCFlat ;
1898     fTPCFlat = new AliPHOSEPFlattener() ;
1899     fTPCFlat = h ;
1900     h = (AliPHOSEPFlattener*)maps->At(1) ;  
1901     if(fV0AFlat) delete fV0AFlat ;
1902     fV0AFlat = new AliPHOSEPFlattener() ;
1903     fV0AFlat = h ;
1904     h = (AliPHOSEPFlattener*)maps->At(2) ;  
1905     if(fV0CFlat) delete fV0CFlat ;
1906     fV0CFlat = new AliPHOSEPFlattener() ;
1907     fV0CFlat = h ;
1908   }    
1909   
1910 }
1911  //____________________________________________________________________________
1912 Double_t  AliAnalysisTaskPi0Flow::ApplyFlattening(Double_t phi, Double_t c){
1913   
1914   if(fTPCFlat)
1915     return fTPCFlat->MakeFlat(phi,c);
1916   return phi ;
1917
1918 }
1919 //____________________________________________________________________________
1920 Double_t  AliAnalysisTaskPi0Flow::ApplyFlatteningV0A(Double_t phi, Double_t c){
1921   
1922   if(fV0AFlat)
1923     return fV0AFlat->MakeFlat(phi,c);
1924   return phi ;
1925
1926 }
1927 //____________________________________________________________________________
1928 Double_t  AliAnalysisTaskPi0Flow::ApplyFlatteningV0C(Double_t phi, Double_t c){
1929   
1930   if(fV0CFlat)
1931     return fV0CFlat->MakeFlat(phi,c);
1932   return phi ;
1933
1934 }
1935 //____________________________________________________________________________
1936 Double_t  AliAnalysisTaskPi0Flow::CoreEnergy(AliVCluster * clu, AliVCaloCells * cells)
1937 {
1938   //calculate energy of the cluster in the circle with radius distanceCut around the maximum
1939
1940   //Can not use already calculated coordinates?
1941   //They have incidence correction...
1942   const Double_t distanceCut =3.5 ;
1943   const Double_t logWeight=4.5 ;
1944
1945   Double32_t * elist = clu->GetCellsAmplitudeFraction() ;
1946 // Calculates the center of gravity in the local PHOS-module coordinates
1947   Float_t wtot = 0;
1948   Double_t xc[100]={0} ;
1949   Double_t zc[100]={0} ;
1950   Double_t x = 0 ;
1951   Double_t z = 0 ;
1952   Int_t mulDigit=TMath::Min(100,clu->GetNCells()) ;
1953   for(Int_t iDigit=0; iDigit<mulDigit; iDigit++) {
1954     Int_t relid[4] ;
1955     Float_t xi ;
1956     Float_t zi ;
1957     fPHOSGeo->AbsToRelNumbering(clu->GetCellAbsId(iDigit), relid) ;
1958     fPHOSGeo->RelPosInModule(relid, xi, zi);
1959     xc[iDigit]=xi ;
1960     zc[iDigit]=zi ;
1961     elist[iDigit] *= cells->GetCellAmplitude(clu->GetCellsAbsId()[iDigit]);
1962     if( fDebug >= 3 )
1963       printf("%f ",elist[iDigit]);
1964     if (clu->E()>0 && elist[iDigit]>0) {
1965       Float_t w = TMath::Max( 0., logWeight + TMath::Log( elist[iDigit] / clu->E() ) ) ;
1966       x    += xc[iDigit] * w ;
1967       z    += zc[iDigit] * w ;
1968       wtot += w ;
1969     }
1970   }
1971   if (wtot>0) {
1972     x /= wtot ;
1973     z /= wtot ;
1974   }
1975   Double_t coreE=0. ;
1976   for(Int_t iDigit=0; iDigit < mulDigit; iDigit++) {
1977     Double_t distance = TMath::Sqrt((xc[iDigit]-x)*(xc[iDigit]-x)+(zc[iDigit]-z)*(zc[iDigit]-z)) ;
1978     if(distance < distanceCut)
1979       coreE += elist[iDigit] ;
1980   }
1981   //Apply non-linearity correction
1982   return fNonLinCorr->Eval(coreE) ;
1983 }
1984 //____________________________________________________________________________
1985 Bool_t  AliAnalysisTaskPi0Flow::AreNeibors(Int_t id1,Int_t id2){
1986   // return true if absId are "Neighbors" (adjacent, including diagornaly,)
1987   // false if not.
1988
1989   Int_t relid1[4] ;
1990   fPHOSGeo->AbsToRelNumbering(id1, relid1) ;
1991
1992   Int_t relid2[4] ;
1993   fPHOSGeo->AbsToRelNumbering(id2, relid2) ;
1994
1995   // if inside the same PHOS module
1996   if ( (relid1[0] == relid2[0]) && (relid1[1]==relid2[1]) ) {
1997     const Int_t rowdiff = TMath::Abs( relid1[2] - relid2[2] ) ;
1998     const Int_t coldiff = TMath::Abs( relid1[3] - relid2[3] ) ;
1999
2000     // and if diff in both direction is 1 or less
2001     if (( coldiff <= 1 )  && ( rowdiff <= 1 ))
2002       return true; // are neighbors
2003   }
2004
2005   // else false
2006   return false;
2007 }
2008 //____________________________________________________________________________
2009 void  AliAnalysisTaskPi0Flow::Reclusterize(AliVCluster * clu){
2010   //Re-clusterize to make continues cluster
2011
2012   const Int_t oldMulDigit=clu->GetNCells() ;
2013   Double32_t * elist = clu->GetCellsAmplitudeFraction() ;
2014   UShort_t * dlist = clu->GetCellsAbsId();
2015
2016   Int_t index[oldMulDigit] ;
2017   Bool_t used[oldMulDigit] ;
2018   for(Int_t i=0; i<oldMulDigit; i++) used[i]=0 ;
2019   Int_t inClu=0 ;
2020   Double_t eMax=0. ;
2021   //find maximum
2022   for(Int_t iDigit=0; iDigit<oldMulDigit; iDigit++) {
2023     if(eMax<elist[iDigit]){
2024       eMax=elist[iDigit];
2025       index[0]=iDigit ;
2026       inClu=1 ;
2027     }
2028   }
2029   if(inClu==0){ //empty cluster
2030     return ;
2031   }
2032   used[index[0]]=kTRUE ; //mark as used
2033   for(Int_t i=0; i<inClu; i++){
2034     for(Int_t iDigit=0 ;iDigit<oldMulDigit; iDigit++){
2035        if(used[iDigit]) //already used
2036          continue ;
2037        if(AreNeibors(dlist[index[i]],dlist[iDigit])){
2038          index[inClu]= iDigit ;
2039          inClu++ ;
2040          used[iDigit]=kTRUE ;
2041        }
2042     }
2043   }
2044
2045   if(inClu==oldMulDigit) //no need to modify
2046     return ;
2047
2048   clu->SetNCells(inClu);
2049   //copy
2050   UShort_t tmpD[oldMulDigit] ;
2051   Double_t tmpE[oldMulDigit] ;
2052   for(Int_t i=0; i<oldMulDigit; i++){
2053     tmpD[i]=dlist[i] ;
2054     tmpE[i]=elist[i] ;
2055   }
2056   //change order of digits in list so that
2057   //first inClu cells were true ones
2058   for(Int_t i=0; i<inClu; i++){
2059     dlist[i]=tmpD[index[i]] ;
2060     elist[i]=tmpE[index[i]] ;
2061   }
2062
2063
2064 }
2065
2066 //_____________________________________________________________________________
2067 void AliAnalysisTaskPi0Flow::SetMisalignment(){
2068   // sets the misalignment vertex if ESD
2069   if( fEventESD ) {
2070     for(Int_t mod=0; mod<5; mod++) {
2071       const TGeoHMatrix* modMatrix = fEvent->GetPHOSMatrix(mod);
2072       if( ! modMatrix) {
2073         if( fDebug )
2074           AliInfo(Form("no PHOS Geometric Misalignment Matrix for module %d", mod));
2075         continue;
2076       }
2077       else {
2078         fPHOSGeo->SetMisalMatrix(modMatrix, mod);
2079         if( fDebug )
2080           AliInfo(Form("PHOS Geometric Misalignment Matrix set for module %d", mod));
2081       }
2082     }
2083   }
2084 }
2085
2086 //_____________________________________________________________________________
2087 void AliAnalysisTaskPi0Flow::SetV0Calibration(){
2088     // assigns: fMultV0, fV0Cpol, fV0Apol, fMeanQ, and fWidthQ
2089
2090     if ( ! fManualV0EPCalc ) {
2091       if( fDebug >=2 )
2092         AliInfo("Not setting V0Calibration, only needed for manual V0 EP Calculation");
2093       return; 
2094     }
2095
2096     int runNumber = this->fRunNumber;
2097     
2098     TString oadbfilename = "$ALICE_ROOT/OADB/PWGCF/VZERO/VZEROcalibEP.root";
2099     TFile *foadb = TFile::Open(oadbfilename.Data());
2100
2101     if(!foadb){
2102         AliError(Form("OADB file %s cannot be opened\n", oadbfilename.Data()));
2103         AliError("V0 Calibration not set !\n");
2104         return;
2105     }
2106
2107     AliOADBContainer *cont = (AliOADBContainer*) foadb->Get("hMultV0BefCorr");
2108     if(!cont){
2109         AliError("OADB object hMultV0BefCorr is not available in the file");
2110         AliError("V0 Calibration not set!\n");
2111         return;
2112     }
2113
2114     if(!(cont->GetObject(runNumber))){
2115         AliError(Form("OADB object hMultV0BefCorr is not available for run %i, trying 137366)",runNumber));
2116         runNumber = 137366;
2117     }
2118     if(!(cont->GetObject(runNumber))){
2119         AliError(Form("OADB object hMultV0BefCorr is not available for run %i ",runNumber));
2120         AliError("V0 Calibration not set!\n");
2121         return;
2122     }
2123
2124     if( fDebug )  AliInfo("Setting V0 calibration") ;
2125     fMultV0 = ((TH2F *) cont->GetObject(runNumber))->ProfileX();
2126
2127     TF1 *fpol0 = new TF1("fpol0","pol0");
2128     fMultV0->Fit(fpol0,"Q0","",0,31);
2129     fV0Cpol = fpol0->GetParameter(0);
2130     fMultV0->Fit(fpol0,"Q0","",32,64);
2131     fV0Apol = fpol0->GetParameter(0);
2132
2133     for(Int_t iside=0;iside<2;iside++){
2134         for(Int_t icoord=0;icoord<2;icoord++){
2135             for(Int_t i=0;i  < kNCenBins;i++){
2136                 char namecont[100];
2137                 if(iside==0 && icoord==0)
2138                     snprintf(namecont,100,"hQxc2_%i",i);
2139                 else if(iside==1 && icoord==0)
2140                     snprintf(namecont,100,"hQxa2_%i",i);
2141                 else if(iside==0 && icoord==1)
2142                     snprintf(namecont,100,"hQyc2_%i",i);
2143                 else if(iside==1 && icoord==1)
2144                     snprintf(namecont,100,"hQya2_%i",i);
2145
2146                 cont = (AliOADBContainer*) foadb->Get(namecont);
2147                 if(!cont){
2148                     AliError(Form("OADB object %s is not available in the file %s", namecont, oadbfilename.Data()));
2149                     AliError("V0 Calibration not fully set!\n");
2150                     return;
2151                 }
2152
2153                 if(!(cont->GetObject(runNumber))){
2154                     AliError(Form("OADB object %s is not available for run %i, trying run 137366",namecont,runNumber));
2155                     runNumber = 137366;
2156                 }
2157                 if(!(cont->GetObject(runNumber))){
2158                   AliError(Form("OADB object %s is not available for run %i",namecont,runNumber));
2159                   AliError("V0 Calibration not fully set!\n");
2160                   return;
2161                 }
2162                 fMeanQ[i][iside][icoord] = ((TH1F *) cont->GetObject(runNumber))->GetMean();
2163                 fWidthQ[i][iside][icoord] = ((TH1F *) cont->GetObject(runNumber))->GetRMS();
2164
2165                 //for v3
2166 //              if(iside==0 && icoord==0)
2167 //                  snprintf(namecont,100,"hQxc3_%i",i);
2168 //              else if(iside==1 && icoord==0)
2169 //                  snprintf(namecont,100,"hQxa3_%i",i);
2170 //              else if(iside==0 && icoord==1)
2171 //                  snprintf(namecont,100,"hQyc3_%i",i);
2172 //              else if(iside==1 && icoord==1)
2173 //                  snprintf(namecont,100,"hQya3_%i",i);
2174 // 
2175 //              cont = (AliOADBContainer*) foadb->Get(namecont);
2176 //              if(!cont){
2177 //                  AliError(Form("OADB object %s is not available in the file",namecont));
2178 //                  AliError("V0 Calibration not fully set!\n");
2179 //                  return;
2180 //              }
2181 // 
2182 //              if(!(cont->GetObject(runNumber))){
2183 //                  AliError(Form("OADB object %s is not available for run %i, trying run 137366",namecont,runNumber));
2184 //                  runNumber = 137366;
2185 //              }
2186 //              if(!(cont->GetObject(runNumber))){
2187 //                AliError(Form("OADB object %s is not available for run %i",namecont,runNumber));
2188 //                AliError("V0 Calibration not fully set!\n");
2189 //                return;
2190 //              }
2191 //              fMeanQv3[i][iside][icoord] = ((TH1F *) cont->GetObject(run))->GetMean();
2192 //              fWidthQv3[i][iside][icoord] = ((TH1F *) cont->GetObject(run))->GetRMS();
2193
2194             }
2195         }
2196     }
2197
2198     delete fpol0; fpol0=0;
2199 }
2200
2201 //_____________________________________________________________________________
2202 void AliAnalysisTaskPi0Flow::SetESDTrackCuts()
2203 {
2204   if( fEventESD ) {
2205     // Create ESD track cut
2206     fESDtrackCuts = AliESDtrackCuts::GetStandardTPCOnlyTrackCuts() ;
2207     //fESDtrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010();
2208     fESDtrackCuts->SetRequireTPCRefit(kTRUE);
2209   }
2210 }
2211
2212 //_____________________________________________________________________________
2213 void AliAnalysisTaskPi0Flow::SetGeometry()
2214 {
2215   // Initialize the PHOS geometry
2216   if( kLHC10h == fPeriod && fEventESD ) {
2217     TGeoManager::Import("geometry.root"); //TODO: should perhaps not be done
2218     fPHOSGeo = AliPHOSGeometry::GetInstance("IHEP") ;
2219     if( ! fPHOSGeo )
2220       AliError("geometry (fPHOSGeo) not initialised");
2221   }
2222
2223   //Init geometry
2224   if(!fPHOSGeo){
2225     AliOADBContainer geomContainer("phosGeo");
2226     geomContainer.InitFromFile("$ALICE_ROOT/OADB/PHOS/PHOSGeometry.root","PHOSRotationMatrixes");
2227     TObjArray *matrixes = (TObjArray*)geomContainer.GetObject(fRunNumber,"PHOSRotationMatrixes");
2228     fPHOSGeo =  AliPHOSGeometry::GetInstance("IHEP") ;
2229     for(Int_t mod=0; mod<5; mod++) {
2230       if(!matrixes->At(mod)) {
2231         continue;
2232         if( fDebug )
2233           AliInfo(Form("No PHOS Matrix for mod:%d, geo=%p\n", mod, fPHOSGeo));
2234       }
2235       else {
2236         fPHOSGeo->SetMisalMatrix(((TGeoHMatrix*)matrixes->At(mod)),mod) ;
2237         if( fDebug >1 )
2238           AliInfo(Form("Adding PHOS Matrix for mod:%d, geo=%p\n", mod, fPHOSGeo));
2239       }
2240     }
2241   } 
2242 }
2243
2244 //_____________________________________________________________________________
2245 void AliAnalysisTaskPi0Flow::SetPHOSCalibData()
2246 {
2247   if( fPHOSCalibData )
2248     delete fPHOSCalibData; 
2249   fPHOSCalibData = 0;
2250   
2251   // Calibration only needed for ESD
2252   if( fEventESD /*&& */ ) {
2253     if( kLHC10h == fPeriod && fEventESD ) {
2254       //We have to apply re-calibration for pass1 LCH10h
2255       // Initialize decalibration factors in the form of the OCDB object
2256       AliCDBManager * man = AliCDBManager::Instance();
2257       man->SetRun(140000) ; //TODO; revise, this should probably not b done.
2258       man->SetDefaultStorage("local://OCDB");
2259     }
2260     fPHOSCalibData = new AliPHOSCalibData();
2261   }
2262 }
2263
2264 //_____________________________________________________________________________
2265 void AliAnalysisTaskPi0Flow::SetVertex()
2266 {
2267   const AliVVertex *primaryVertex = fEvent->GetPrimaryVertex();
2268   if( primaryVertex ) {
2269     fVertex[0] = primaryVertex->GetX();
2270     fVertex[1] = primaryVertex->GetY();
2271     fVertex[2] = primaryVertex->GetZ();
2272   }
2273   else {
2274     AliError("Event has 0x0 Primary Vertex, defaulting to origo");
2275     fVertex[0] = 0;
2276     fVertex[1] = 0;
2277     fVertex[2] = 0;
2278   }
2279   fVertexVector = TVector3(fVertex);
2280   FillHistogram("hZvertex", fVertexVector.z(), fInternalRunNumber-0.5);
2281   
2282   if( fDebug >= 2 )
2283     AliInfo(Form("Vertex is set to (%.1f,%.1f,%.1f)", fVertex[0], fVertex[1], fVertex[2]));
2284
2285   fVtxBin=0 ;// No support for vtx binning implemented.
2286 }
2287
2288 //_____________________________________________________________________________
2289 Bool_t AliAnalysisTaskPi0Flow::RejectEventVertex()
2290 {
2291   if( ! fEvent->GetPrimaryVertex() )
2292     return true; // reject
2293   LogSelection(1, fInternalRunNumber);
2294
2295   if ( TMath::Abs(fVertexVector.z()) > fMaxAbsVertexZ )
2296     return true; // reject
2297   LogSelection(2, fInternalRunNumber);
2298
2299   return false; // accept event.
2300 }
2301
2302 //_____________________________________________________________________________
2303 void AliAnalysisTaskPi0Flow::SetCentrality()
2304 {
2305   AliCentrality *centrality = fEvent->GetCentrality();
2306   if( centrality )
2307     fCentralityV0M=centrality->GetCentralityPercentile("V0M");
2308   else {
2309     AliError("Event has 0x0 centrality");
2310     fCentralityV0M = -1.;
2311   }
2312   FillHistogram("hCentrality",fCentralityV0M,fInternalRunNumber-0.5) ;
2313
2314   fCentBin = GetCentralityBin(fCentralityV0M);
2315
2316   if ( fDebug >= 2 )
2317     AliInfo(Form("Centrality (bin) is: %f (%d)", fCentralityV0M, fCentBin));
2318 }
2319
2320 //_____________________________________________________________________________
2321 Bool_t AliAnalysisTaskPi0Flow::RejectCentrality()
2322 {
2323   if( ! fEvent->GetCentrality() )
2324     return true; // reject
2325   LogSelection(3, fInternalRunNumber);
2326
2327 //   if( fCentralityV0M <= 0. || fCentralityV0M>80. )
2328 //     return true; // reject
2329     
2330   int lastBinUpperIndex = fCentEdges.GetSize() -1;
2331   if( fCentralityV0M > fCentEdges[lastBinUpperIndex] ) {
2332     if( fDebug )
2333       AliInfo("Rejecting due to centrality outside of binning.");
2334     return true; // reject
2335   }
2336   LogSelection(4, fInternalRunNumber);
2337
2338   if( fCentralityV0M < fCentEdges[0] ) {
2339     if( fDebug )
2340       AliInfo("Rejecting due to centrality outside of binning.");
2341     return true; // reject
2342   }
2343   LogSelection(5, fInternalRunNumber);
2344
2345   return false;
2346 }
2347
2348
2349 //_____________________________________________________________________________
2350 void AliAnalysisTaskPi0Flow::EvalReactionPlane()
2351 {
2352   // assigns: fHaveTPCRP and fRP
2353   // also does a few histogram fills
2354
2355   AliEventplane *eventPlane = fEvent->GetEventplane();
2356   if( ! eventPlane ) { AliError("Event has no event plane"); return; }
2357   
2358   Double_t reactionPlaneQ = eventPlane->GetEventplane("Q");
2359   FillHistogram("phiRP",reactionPlaneQ,fCentralityV0M) ;
2360
2361   if(reactionPlaneQ==999 || reactionPlaneQ < 0.){ //reaction plain was not defined
2362     if( fDebug ) AliInfo(Form("No Q Reaction Plane, value is %f", reactionPlaneQ));
2363     fHaveTPCRP = kFALSE;
2364   }
2365   else{
2366     if( fDebug >= 2 ) AliInfo(Form("Q Reaction Plane is %f", reactionPlaneQ));
2367     fHaveTPCRP = kTRUE;
2368   }
2369
2370   if(fHaveTPCRP){
2371     fRP = ApplyFlattening(reactionPlaneQ, fCentralityV0M) ;
2372
2373     while(fRP<0)  fRP+=TMath::Pi();
2374     while(fRP>TMath::Pi())  fRP-=TMath::Pi();
2375     FillHistogram("phiRPflat",fRP,fCentralityV0M) ;
2376     Double_t dPsi = eventPlane->GetQsubRes() ;
2377     FillHistogram("cos2AC",TMath::Cos(2.*dPsi),fCentralityV0M) ;
2378   }
2379   else
2380     fRP=0.;
2381 }
2382
2383
2384 //____________________________________________________________________________
2385 void  AliAnalysisTaskPi0Flow::EvalV0ReactionPlane(){
2386   // set: fRPV0A and fRPV0C
2387
2388   // Do Manual V0 EP Calculation
2389   if ( fManualV0EPCalc ) 
2390     {
2391       //VZERO data
2392       AliVVZERO* v0 = fEvent->GetVZEROData();
2393
2394       //reset Q vector info
2395       Double_t Qxa2 = 0, Qya2 = 0;
2396       Double_t Qxc2 = 0, Qyc2 = 0;
2397
2398       for (Int_t iv0 = 0; iv0 < 64; iv0++) {
2399         Double_t phiV0 = TMath::PiOver4()*(0.5 + iv0 % 8);
2400         Float_t multv0 = v0->GetMultiplicity(iv0);
2401         if (iv0 < 32){ // V0C
2402           Qxc2 += TMath::Cos(2*phiV0) * multv0*fV0Cpol/fMultV0->GetBinContent(iv0+1);
2403           Qyc2 += TMath::Sin(2*phiV0) * multv0*fV0Cpol/fMultV0->GetBinContent(iv0+1);
2404         } else {       // V0A
2405           Qxa2 += TMath::Cos(2*phiV0) * multv0*fV0Apol/fMultV0->GetBinContent(iv0+1);
2406           Qya2 += TMath::Sin(2*phiV0) * multv0*fV0Apol/fMultV0->GetBinContent(iv0+1);
2407         }
2408       }
2409
2410       Int_t iC = -1;
2411       // centrality bins
2412       if(fCentralityV0M < 5) iC = 0;
2413       else if(fCentralityV0M < 10) iC = 1;
2414       else if(fCentralityV0M < 20) iC = 2;
2415       else if(fCentralityV0M < 30) iC = 3;
2416       else if(fCentralityV0M < 40) iC = 4;
2417       else if(fCentralityV0M < 50) iC = 5;
2418       else if(fCentralityV0M < 60) iC = 6;
2419       else if(fCentralityV0M < 70) iC = 7;
2420       else iC = 8;
2421
2422       //grab for each centrality the proper histo with the Qx and Qy to do the recentering
2423       Double_t Qxamean2 = fMeanQ[iC][1][0];
2424       Double_t Qxarms2  = fWidthQ[iC][1][0];
2425       Double_t Qyamean2 = fMeanQ[iC][1][1];
2426       Double_t Qyarms2  = fWidthQ[iC][1][1];
2427
2428       Double_t Qxcmean2 = fMeanQ[iC][0][0];
2429       Double_t Qxcrms2  = fWidthQ[iC][0][0];
2430       Double_t Qycmean2 = fMeanQ[iC][0][1];
2431       Double_t Qycrms2  = fWidthQ[iC][0][1];
2432
2433       Double_t QxaCor2 = (Qxa2 - Qxamean2)/Qxarms2;
2434       Double_t QyaCor2 = (Qya2 - Qyamean2)/Qyarms2;
2435       Double_t QxcCor2 = (Qxc2 - Qxcmean2)/Qxcrms2;
2436       Double_t QycCor2 = (Qyc2 - Qycmean2)/Qycrms2;
2437
2438       fRPV0A = TMath::ATan2(QyaCor2, QxaCor2)/2.;
2439       fRPV0C = TMath::ATan2(QycCor2, QxcCor2)/2.;
2440     }
2441   else // Use Official V0 EP Calculation. 
2442     {
2443       AliEventplane *eventPlane = fEvent->GetEventplane();
2444       if( ! eventPlane ) { AliError("Event has no event plane"); return; }
2445       fRPV0A = eventPlane->GetEventplane("V0A", fEvent);
2446       fRPV0C = eventPlane->GetEventplane("V0C", fEvent);
2447     }
2448   
2449   // Check that the A&C RP are within allowed range.
2450   if( fDebug >= 3 && (fRPV0A<0 || fRPV0A>TMath::Pi() ) )
2451     AliInfo(Form("RPV0A outside of permited range [0,pi]: %f, correcting", fRPV0A));
2452   if( fDebug >= 3 && (fRPV0C<0 || fRPV0C>TMath::Pi() ) )
2453     AliInfo(Form("RPV0C outside of permited range [0,pi]: %f, correcting", fRPV0C));
2454   while (fRPV0A<0          ) fRPV0A+=TMath::Pi() ;
2455   while (fRPV0A>TMath::Pi()) fRPV0A-=TMath::Pi() ;
2456   while (fRPV0C<0          ) fRPV0C+=TMath::Pi() ;
2457   while (fRPV0C>TMath::Pi()) fRPV0C-=TMath::Pi() ;
2458
2459   // Reaction plane histograms before flattening
2460   if( fDebug >= 2 )
2461     AliInfo(Form("V0 Reaction Plane before flattening: A side: %f, C side: %f", fRPV0A, fRPV0C));
2462
2463   FillHistogram("phiRPV0A" ,fRPV0A,fCentralityV0M);
2464   FillHistogram("phiRPV0C" ,fRPV0C,fCentralityV0M);
2465   FillHistogram("phiRPV0AC",fRPV0A,fRPV0C,fCentralityV0M) ;
2466
2467   // Flattening
2468   fRPV0A=ApplyFlatteningV0A(fRPV0A,fCentralityV0M) ;
2469   while (fRPV0A<0          ) fRPV0A+=TMath::Pi() ;
2470   while (fRPV0A>TMath::Pi()) fRPV0A-=TMath::Pi() ;
2471
2472   fRPV0C=ApplyFlatteningV0C(fRPV0C,fCentralityV0M) ;
2473   while (fRPV0C<0          ) fRPV0C+=TMath::Pi() ;
2474   while (fRPV0C>TMath::Pi()) fRPV0C-=TMath::Pi() ;
2475   
2476   if( fDebug >= 2 )
2477     AliInfo(Form("V0 Reaction Plane after  flattening: A side: %f, C side: %f", fRPV0A, fRPV0C));
2478
2479   FillHistogram("phiRPV0Aflat",fRPV0A,fCentralityV0M) ;
2480   FillHistogram("cos2V0AC",TMath::Cos(2.*(fRPV0A-fRPV0C)),fCentralityV0M) ;
2481   if(fHaveTPCRP){
2482     FillHistogram("phiRPV0ATPC",fRP,fRPV0A,fCentralityV0M) ;
2483     FillHistogram("cos2V0ATPC",TMath::Cos(2.*(fRP-fRPV0A)),fCentralityV0M) ;
2484   }
2485
2486   FillHistogram("phiRPV0Cflat",fRPV0C,fCentralityV0M) ;
2487   if(fHaveTPCRP){
2488     FillHistogram("phiRPV0CTPC",fRP,fRPV0C,fCentralityV0M) ;
2489     FillHistogram("cos2V0CTPC",TMath::Cos(2.*(fRP-fRPV0C)),fCentralityV0M) ;
2490   }
2491 }