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