]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGGA/EMCALTasks/AliAnalysisTaskPi0V2.cxx
fix
[u/mrichter/AliRoot.git] / PWGGA / EMCALTasks / AliAnalysisTaskPi0V2.cxx
1 /* $Id: AliAnalysisTaskPi0V2.cxx 55404 2012-03-29 10:10:19Z fca $ */
2
3 #include "AliAnalysisTaskPi0V2.h"
4
5 #include <Riostream.h>
6 #include <TCanvas.h>
7 #include <TChain.h>
8 #include <TClonesArray.h>
9 #include <TH1F.h>
10 #include <TH2F.h>
11 #include <TH3F.h>
12 #include <THnSparse.h>
13 #include <TList.h>
14 #include <TProfile.h>
15 #include <TString.h>
16 #include <TTree.h>
17
18 #include "AliAODEvent.h"
19 #include "AliAnalysisManager.h"
20 #include "AliAnalysisTaskSE.h"
21 #include "AliCaloPID.h"
22 #include "AliCaloTrackReader.h"
23 #include "AliCalorimeterUtils.h"
24 #include "AliEMCALGeometry.h"
25 #include "AliEPFlattener.h"
26 #include "AliESDEvent.h"
27 #include "AliESDInputHandler.h"
28 #include "AliESDtrackCuts.h"
29 #include "AliEventplane.h"
30 #include "AliMCEvent.h"
31 #include "AliOADBContainer.h"
32 #include "AliStack.h"
33 #include "AliVCluster.h"
34
35 using std::cout;
36 using std::endl;
37
38 ClassImp(AliAnalysisTaskPi0V2)
39
40 //________________________________________________________________________
41 AliAnalysisTaskPi0V2::AliAnalysisTaskPi0V2(const char *name) :
42   AliAnalysisTaskSE(name),
43   fOutput(0),
44   fESD(0),fAOD(0),
45   fTracksName("PicoTrack"), fV1ClusName("CaloCluster"), fV2ClusName("CaloCluster"),
46   fTrigClass("CVLN_|CSEMI_|CCENT|CVHN"),
47   fTracks(0), fV1Clus(0), fV2Clus(0),
48   fRunNumber(-999),fInterRunNumber(-999),
49   fVtxCut(15.),
50   fNcellCut(2.), fECut(1.), fEtaCut(0.65), fM02Cut(0.5),fDrCut(0.025), fPi0AsyCut(0), isV1Clus(1), isPhosCali(0),
51   fCentrality(99.),
52   fEPTPC(-999.),
53   fEPTPCreso(0.), 
54   fEPV0(-999.), fEPV0A(-999.), fEPV0C(-999.), fEPV0Ar(-999.), fEPV0Cr(-999.), fEPV0r(-999.),
55   fEPV0AR4(-999.), fEPV0AR5(-999.), fEPV0AR6(-999.), fEPV0AR7(-999.), fEPV0CR0(-999.), fEPV0CR1(-999.), fEPV0CR2(-999.), fEPV0CR3(-999.),
56   hEvtCount(0), 
57   h2DcosV0A(0), h2DsinV0A(0), h2DcosV0C(0), h2DsinV0C(0), h2DcosTPC(0), h2DsinTPC(0), 
58   hEPTPC(0), hresoTPC(0),
59   hEPV0(0), hEPV0A(0), hEPV0C(0), hEPV0Ar(0), hEPV0Cr(0), hEPV0r(0), hEPV0AR4(0), hEPV0AR7(0), hEPV0CR0(0), hEPV0CR3(0),
60   hEPTPCCor(0), hEPV0ACor(0), hEPV0CCor(0),
61   hdifV0Ar_V0Cr(0), hdifV0A_V0CR0(0), hdifV0A_V0CR3(0), hdifV0ACR0_V0CR3(0), hdifV0C_V0AR4(0), hdifV0C_V0AR7(0), hdifV0AR4_V0AR7(0),
62   hdifV0A_V0C(0), hdifV0A_TPC(0), hdifV0C_TPC(0), hdifV0C_V0A(0), 
63   hM02vsPtA(0), hM02vsPtB(0), hClusDxDZA(0), hClusDxDZB(0),
64   hdifEMC_EPV0(0), hdifEMC_EPV0A(0), hdifEMC_EPV0C(0), hdifful_EPV0(0), hdifful_EPV0A(0), hdifful_EPV0C(0), 
65   hdifout_EPV0(0), hdifout_EPV0A(0), hdifout_EPV0C(0), 
66   fEPcalibFileName("$ALICE_ROOT/OADB/PHOS/PHOSflat.root"), fTPCFlat(0x0), fV0AFlat(0x0),  fV0CFlat(0x0),
67   fClusterPbV0(0), fClusterPbV0A(0), fClusterPbV0C(0), fClusterPbTPC(0),    
68   fHEPV0r(0x0), fHEPV0A(0x0), fHEPV0C(0x0), fHEPTPC(0x0)
69 {
70   // Dummy constructor ALWAYS needed for I/O.
71   DefineInput(0, TChain::Class());
72   DefineOutput(1, TList::Class());                                            // for output list
73 }
74
75 //________________________________________________________________________
76 AliAnalysisTaskPi0V2::AliAnalysisTaskPi0V2() :
77   AliAnalysisTaskSE("default_name"),
78   fOutput(0),
79   fESD(0),fAOD(0),
80   fTracksName("PicoTrack"), fV1ClusName("CaloCluster"), fV2ClusName("CaloCluster"),
81   fTrigClass("CVLN_|CSEMI_|CCENT|CVHN"),
82   fTracks(0), fV1Clus(0), fV2Clus(0),
83   fRunNumber(-999),fInterRunNumber(-999),
84   fVtxCut(15.),
85   fNcellCut(2.), fECut(1.), fEtaCut(0.65), fM02Cut(0.5), fDrCut(0.025), fPi0AsyCut(0), isV1Clus(1),isPhosCali(0),
86   fCentrality(99.),
87   fEPTPC(-999.),
88   fEPTPCreso(0.),
89   fEPV0(-999.), fEPV0A(-999.), fEPV0C(-999.), fEPV0Ar(-999.), fEPV0Cr(-999.), fEPV0r(-999.),
90   fEPV0AR4(-999.), fEPV0AR5(-999.), fEPV0AR6(-999.), fEPV0AR7(-999.), fEPV0CR0(-999.), fEPV0CR1(-999.), fEPV0CR2(-999.), fEPV0CR3(-999.),
91   hEvtCount(0), 
92   h2DcosV0A(0), h2DsinV0A(0), h2DcosV0C(0), h2DsinV0C(0), h2DcosTPC(0), h2DsinTPC(0),
93   hEPTPC(0), hresoTPC(0),
94   hEPV0(0), hEPV0A(0), hEPV0C(0), hEPV0Ar(0), hEPV0Cr(0), hEPV0r(0), hEPV0AR4(0), hEPV0AR7(0), hEPV0CR0(0), hEPV0CR3(0),
95   hEPTPCCor(0), hEPV0ACor(0), hEPV0CCor(0),
96   hdifV0Ar_V0Cr(0), hdifV0A_V0CR0(0), hdifV0A_V0CR3(0), hdifV0ACR0_V0CR3(0), hdifV0C_V0AR4(0), hdifV0C_V0AR7(0), hdifV0AR4_V0AR7(0),
97   hdifV0A_V0C(0), hdifV0A_TPC(0), hdifV0C_TPC(0), hdifV0C_V0A(0),
98   hM02vsPtA(0), hM02vsPtB(0), hClusDxDZA(0), hClusDxDZB(0),
99   hdifEMC_EPV0(0), hdifEMC_EPV0A(0), hdifEMC_EPV0C(0), hdifful_EPV0(0), hdifful_EPV0A(0), hdifful_EPV0C(0),
100   hdifout_EPV0(0), hdifout_EPV0A(0), hdifout_EPV0C(0), 
101   fEPcalibFileName("$ALICE_ROOT/OADB/PHOS/PHOSflat.root"), fTPCFlat(0x0), fV0AFlat(0x0),  fV0CFlat(0x0),
102   fClusterPbV0(0), fClusterPbV0A(0), fClusterPbV0C(0), fClusterPbTPC(0),    
103   fHEPV0r(0x0), fHEPV0A(0x0), fHEPV0C(0x0), fHEPTPC(0x0)
104 {
105   // Constructor
106   // Define input and output slots here (never in the dummy constructor)
107   // Input slot #0 works with a TChain - it is connected to the default input container
108   // Output slot #1 writes into a TH1 container
109   DefineInput(0, TChain::Class());
110   DefineOutput(1, TList::Class());                                            // for output list
111 }
112
113 //________________________________________________________________________
114 AliAnalysisTaskPi0V2::~AliAnalysisTaskPi0V2()
115 {
116   // Destructor. Clean-up the output list, but not the histograms that are put inside
117   // (the list is owner and will clean-up these histograms). Protect in PROOF case.
118   if (fTPCFlat) 
119     delete fTPCFlat;  
120   fTPCFlat=0x0;
121   if (fV0AFlat) 
122     delete fV0AFlat;  
123   fV0AFlat=0x0;
124   if (fV0CFlat) 
125     delete fV0CFlat;  
126   fV0CFlat=0x0;
127   delete fOutput;
128 }
129
130 //_____________________________________________________________________
131 Double_t AliAnalysisTaskPi0V2::GetMaxCellEnergy(const AliVCluster *cluster, Short_t &id) const
132 {
133   // Get maximum energy of attached cell.
134
135   id = -1;
136
137   AliVCaloCells *cells = 0;
138   if (fESD) {
139     cells = fESD->GetEMCALCells();
140   } else {
141     cells = fAOD->GetEMCALCells();
142   }
143   if (!cells)
144     return 0;
145
146   Double_t maxe = 0;
147   const Int_t ncells = cluster->GetNCells();
148   for (Int_t i=0; i<ncells; i++) {
149     Double_t e = cells->GetCellAmplitude(TMath::Abs(cluster->GetCellAbsId(i)));
150     if (e>maxe) {
151       maxe = e;
152       id   = cluster->GetCellAbsId(i);
153     }
154   }
155   return maxe;
156 }
157
158 //_____________________________________________________________________
159 Double_t AliAnalysisTaskPi0V2::GetCrossEnergy(const AliVCluster *cluster, Short_t &idmax) const
160 {
161   // Calculate the energy of cross cells around the leading cell.
162
163   AliVCaloCells *cells;
164   if (fESD) {
165     cells = fESD->GetEMCALCells();
166   } else {
167     cells = fAOD->GetEMCALCells();
168   }
169   if (!cells)
170     return 0;
171
172   AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance();
173   if (!geom)
174     return 0;
175
176   Int_t iSupMod = -1;
177   Int_t iTower  = -1;
178   Int_t iIphi   = -1;
179   Int_t iIeta   = -1;
180   Int_t iphi    = -1;
181   Int_t ieta    = -1;
182   Int_t iphis   = -1;
183   Int_t ietas   = -1;
184
185   Double_t crossEnergy = 0.;
186
187   geom->GetCellIndex(idmax,iSupMod,iTower,iIphi,iIeta);
188   geom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,iIphi, iIeta,iphis,ietas);
189
190   Int_t ncells = cluster->GetNCells();
191   for (Int_t i=0; i<ncells; i++) {
192     Int_t cellAbsId = cluster->GetCellAbsId(i);
193     geom->GetCellIndex(cellAbsId,iSupMod,iTower,iIphi,iIeta);
194     geom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,iIphi, iIeta,iphi,ieta);
195     Int_t aphidiff = TMath::Abs(iphi-iphis);
196     if (aphidiff>1)
197       continue;
198     Int_t aetadiff = TMath::Abs(ieta-ietas);
199     if (aetadiff>1)
200       continue;
201     if ( (aphidiff==1 && aetadiff==0) ||
202         (aphidiff==0 && aetadiff==1) ) {
203       crossEnergy += cells->GetCellAmplitude(cellAbsId);
204     }
205   }
206
207   return crossEnergy;
208 }
209
210 //_____________________________________________________________________
211 Bool_t AliAnalysisTaskPi0V2::IsWithinFiducialVolume(Short_t id) const
212 {
213   // Check if cell is within given fiducial volume.
214
215   Double_t fNFiducial = 1;
216
217   Int_t iSupMod = -1;
218   Int_t iTower  = -1;
219   Int_t iIphi   = -1;
220   Int_t iIeta   = -1;
221   Int_t iphi    = -1;
222   Int_t ieta    = -1;
223
224   Bool_t okrow = kFALSE;
225   Bool_t okcol = kFALSE;
226
227   AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance();
228   if (!geom)
229     return kFALSE;
230
231   Int_t cellAbsId = id;
232   geom->GetCellIndex(cellAbsId,iSupMod,iTower,iIphi,iIeta);
233   geom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,iIphi, iIeta,iphi,ieta);
234
235   // Check rows/phi
236   if (iSupMod < 10) {
237     if (iphi >= fNFiducial && iphi < 24-fNFiducial)
238       okrow = kTRUE;
239   } else {
240     if (iphi >= fNFiducial && iphi < 12-fNFiducial)
241       okrow = kTRUE;
242   }
243   // Check columns/eta
244   Bool_t noEMCALBorderAtEta0 = kTRUE;
245   if (!noEMCALBorderAtEta0) {
246     if (ieta > fNFiducial && ieta < 48-fNFiducial)
247       okcol = kTRUE;
248   } else {
249     if (iSupMod%2==0) {
250       if (ieta >= fNFiducial)
251         okcol = kTRUE;
252     } else {
253       if (ieta < 48-fNFiducial)
254         okcol = kTRUE;
255     }
256   }
257   if (okrow && okcol)
258      return kTRUE;
259
260   return kFALSE;
261 }
262
263 //______________________________________________________________________
264 Bool_t AliAnalysisTaskPi0V2::IsGoodCluster(const AliVCluster *c) const
265 {
266   if (!c)
267     return kFALSE;
268
269   if(c->GetNCells() < fNcellCut)
270    return kFALSE;
271
272   if(c->E() < fECut)
273    return kFALSE;
274   Short_t id = -1;
275   Double_t maxE = GetMaxCellEnergy(c, id); 
276      if((1. - double(GetCrossEnergy(c,id))/maxE) > 0.97)
277     return kFALSE;
278
279
280   Float_t pos1[3];
281   c->GetPosition(pos1);
282   TVector3 clsPos(pos1);
283   Double_t eta = clsPos.Eta();
284
285   if (TMath::Abs(eta) > fEtaCut)
286     return kFALSE;  
287
288   if (!IsWithinFiducialVolume(id))
289     return kFALSE;
290
291   if(c->GetM02() >fM02Cut)
292     return kFALSE;
293
294
295   return kTRUE;
296
297 }
298 //________________________________________________________________________________________________
299 Bool_t AliAnalysisTaskPi0V2::IsGoodClusterV1(const AliVCluster *c) const
300 {
301   if (!c)
302     return kFALSE;
303
304   if (c->GetNCells() < fNcellCut)
305    return kFALSE;
306
307   if (c->E() < fECut)
308    return kFALSE;
309
310   Short_t id = -1;
311   Double_t maxE = GetMaxCellEnergy(c, id);
312   if((1. - double(GetCrossEnergy(c,id))/maxE) > 0.97)
313     return kFALSE;
314
315
316   Float_t pos1[3];
317   c->GetPosition(pos1);
318   TVector3 clsPos(pos1);
319   Double_t eta = clsPos.Eta();
320
321   if (TMath::Abs(eta) > fEtaCut)
322     return kFALSE;
323
324   if (!IsWithinFiducialVolume(id))
325     return kFALSE;
326
327   if (c->GetM02() <fM02Cut)
328     return kFALSE;
329
330   Double_t dr = TMath::Sqrt(c->GetTrackDx()*c->GetTrackDx() + c->GetTrackDz()*c->GetTrackDz());
331   if(dr<fDrCut)
332     return kFALSE;
333
334   return kTRUE;
335 }
336
337 //_____________________________________________________________________
338 Bool_t AliAnalysisTaskPi0V2::IsGoodPion(const TLorentzVector &p1, const TLorentzVector &p2) const
339 {
340   // Is good pion?
341
342   if(fPi0AsyCut){
343     Double_t asym = TMath::Abs(p1.E()-p2.E())/(p1.E()+p2.E());
344     if (asym>0.7)
345       return kFALSE;
346   }
347   TLorentzVector pion;
348   pion = p1 + p2;
349   Double_t eta = pion.Eta();
350   if(TMath::Abs(eta) > fEtaCut)
351     return kFALSE;
352
353   return kTRUE;
354 }
355
356 //_______________________________________________________________________
357 void AliAnalysisTaskPi0V2::FillPion(const TLorentzVector& p1, const TLorentzVector& p2, Double_t EPV0A, Double_t EPV0C, Double_t EPTPC)
358 {
359   // Fill histogram.
360
361   if (!IsGoodPion(p1,p2))
362     return;
363   TLorentzVector pion;
364   pion = p1 + p2;
365
366   Double_t mass = pion.M();
367   Double_t pt   = pion.Pt();
368   Double_t phi  = pion.Phi();
369
370   Double_t dphiV0A  = phi-EPV0A;
371   Double_t dphiV0C  = phi-EPV0C;
372   Double_t dphiTPC  = phi-EPTPC;
373
374   dphiV0A = TVector2::Phi_0_2pi(dphiV0A); if(dphiV0A >TMath::Pi())  dphiV0A -= TMath::Pi();
375   dphiV0C = TVector2::Phi_0_2pi(dphiV0C); if(dphiV0C >TMath::Pi())  dphiV0C -= TMath::Pi();
376   dphiTPC = TVector2::Phi_0_2pi(dphiTPC); if(dphiTPC >TMath::Pi())  dphiTPC -= TMath::Pi();
377
378   Double_t xV0A[4]; // Match ndims in fH V0A EP
379   xV0A[0]       = mass;
380   xV0A[1]       = pt;
381   xV0A[2]       = fCentrality;
382   xV0A[3]       = dphiV0A;
383   fHEPV0A->Fill(xV0A);
384
385   Double_t xV0C[4]; // Match ndims in fH V0C EP
386   xV0C[0]       = mass;
387   xV0C[1]       = pt;
388   xV0C[2]       = fCentrality;
389   xV0C[3]       = dphiV0C;
390   fHEPV0C->Fill(xV0C);
391
392   if (fEPTPC!=-999.){
393     Double_t xTPC[4]; // Match ndims in fH TPC EP
394     xTPC[0]       = mass;
395     xTPC[1]       = pt;
396     xTPC[2]       = fCentrality;
397     xTPC[3]       = dphiTPC;
398     fHEPTPC->Fill(xTPC);
399   }
400 }
401
402 //________________________________________________________________________________________________________________________________
403 void AliAnalysisTaskPi0V2::FillCluster(const TLorentzVector& p1, Double_t EPV0A, Double_t EPV0C, Double_t EPTPC, AliVCluster *c)
404 {
405   // Cluster(photon) v2 method
406
407   Double_t Et   = p1.Et();
408   Double_t Phi  = p1.Phi();
409   Double_t M02  = c->GetM02();
410   Double_t DxClus = c->GetTrackDx();
411   Double_t DzClus = c->GetTrackDz();
412   Double_t dr = TMath::Sqrt(DxClus*DxClus + DzClus*DzClus);
413
414   Double_t difClusV0A = TVector2::Phi_0_2pi(Phi-EPV0A);  if(difClusV0A >TMath::Pi()) difClusV0A -= TMath::Pi();
415   Double_t difClusV0C = TVector2::Phi_0_2pi(Phi-EPV0C);  if(difClusV0C >TMath::Pi()) difClusV0C -= TMath::Pi();
416   Double_t difClusTPC = TVector2::Phi_0_2pi(Phi-EPTPC);  if(difClusTPC >TMath::Pi()) difClusTPC -= TMath::Pi();
417
418   Double_t DataV0A[5];
419   DataV0A[0] = Et;
420   DataV0A[1] = M02;
421   DataV0A[2] = fCentrality;
422   DataV0A[3] = difClusV0A;
423   DataV0A[4] = dr;
424   fClusterPbV0A->Fill(DataV0A);
425
426   Double_t DataV0C[5];
427   DataV0C[0] = Et;
428   DataV0C[1] = M02;
429   DataV0C[2] = fCentrality;
430   DataV0C[3] = difClusV0C;
431   DataV0C[4] = dr;
432   fClusterPbV0C->Fill(DataV0C);
433
434   Double_t DataTPC[5];
435   DataTPC[0] = Et;
436   DataTPC[1] = M02;
437   DataTPC[2] = fCentrality;
438   DataTPC[3] = difClusTPC;
439   DataTPC[4] = dr;
440   fClusterPbTPC->Fill(DataTPC);
441 }
442
443 //_________________________________________________________________________________________________
444 void AliAnalysisTaskPi0V2::GetMom(TLorentzVector& p, const AliVCluster *c, Double_t *vertex)
445 {
446   // Calculate momentum.
447   Float_t posMom[3];
448   c->GetPosition(posMom);
449   TVector3 clsPos2(posMom);
450
451   Double_t e   = c->E();
452   Double_t r   = clsPos2.Perp();
453   Double_t eta = clsPos2.Eta();
454   Double_t phi = clsPos2.Phi();
455
456   TVector3 pos;
457   pos.SetPtEtaPhi(r,eta,phi);
458
459   if (vertex) { //calculate direction relative to vertex
460     pos -= vertex;
461   }
462
463   Double_t rad = pos.Mag();
464   p.SetPxPyPzE(e*pos.x()/rad, e*pos.y()/rad, e*pos.z()/rad, e);
465
466 }
467
468 //________________________________________________________________________
469 void AliAnalysisTaskPi0V2::UserCreateOutputObjects()
470 {
471   // Create histograms
472   // Called once (on the worker node)
473         
474   fOutput = new TList();
475   fOutput->SetOwner();  // IMPORTANT!
476
477   hEvtCount = new TH1F("hEvtCount", " Event Plane", 9, 0.5, 9.5);
478   hEvtCount->GetXaxis()->SetBinLabel(1,"All");
479   hEvtCount->GetXaxis()->SetBinLabel(2,"Evt");
480   hEvtCount->GetXaxis()->SetBinLabel(3,"Trg Class");
481   hEvtCount->GetXaxis()->SetBinLabel(4,"Vtx");
482   hEvtCount->GetXaxis()->SetBinLabel(5,"Cent");
483   hEvtCount->GetXaxis()->SetBinLabel(6,"EPtask");
484   hEvtCount->GetXaxis()->SetBinLabel(7,"ClusterTask");
485   hEvtCount->GetXaxis()->SetBinLabel(8,"Pass");
486   fOutput->Add(hEvtCount);
487     
488   hEPTPC   = new TH2F("hEPTPC",   "EPTPC     vs cent", 100, 0., 100., 100, 0., TMath::Pi());
489   hresoTPC = new TH2F("hresoTPC", "TPc reso  vs cent", 100, 0., 100., 100, 0., 1.);
490   hEPV0    = new TH2F("hEPV0",    "EPV0      vs cent", 100, 0., 100., 100, 0., TMath::Pi());
491   hEPV0A   = new TH2F("hEPV0A",   "EPV0A     vs cent", 100, 0., 100., 100, 0., TMath::Pi());
492   hEPV0C   = new TH2F("hEPV0C",   "EPV0C     vs cent", 100, 0., 100., 100, 0., TMath::Pi());
493   hEPV0Ar  = new TH2F("hEPV0Ar",  "EPV0Ar    vs cent", 100, 0., 100., 100, 0., TMath::Pi());
494   hEPV0Cr  = new TH2F("hEPV0Cr",  "EPV0Cr    vs cent", 100, 0., 100., 100, 0., TMath::Pi());
495   hEPV0r   = new TH2F("hEPV0r",   "EPV0r     vs cent", 100, 0., 100., 100, 0., TMath::Pi());
496   hEPV0AR4 = new TH2F("hEPV0AR4", "EPV0AR4   vs cent", 100, 0., 100., 100, 0., TMath::Pi());
497   hEPV0AR7 = new TH2F("hEPV0AR7", "EPV0AR7   vs cent", 100, 0., 100., 100, 0., TMath::Pi());
498   hEPV0CR0 = new TH2F("hEPV0CR0", "EPV0CR0   vs cent", 100, 0., 100., 100, 0., TMath::Pi());
499   hEPV0CR3 = new TH2F("hEPV0CR3", "EPV0CR3   vs cent", 100, 0., 100., 100, 0., TMath::Pi());
500   fOutput->Add(hEPTPC);
501   fOutput->Add(hresoTPC);
502   fOutput->Add(hEPV0);
503   fOutput->Add(hEPV0A);
504   fOutput->Add(hEPV0C);
505   fOutput->Add(hEPV0Ar);
506   fOutput->Add(hEPV0Cr);
507   fOutput->Add(hEPV0r);
508   fOutput->Add(hEPV0AR4);
509   fOutput->Add(hEPV0AR7);
510   fOutput->Add(hEPV0CR0);
511   fOutput->Add(hEPV0CR3);
512
513   hEPTPCCor  = new TH2F("hEPTPCCor",   "EPTPC  vs cent after PHOS Correct", 100, 0., 100., 100, 0., TMath::Pi());
514   hEPV0ACor  = new TH2F("hEPV0ACor",   "EPV0A  vs cent after PHOS Correct", 100, 0., 100., 100, 0., TMath::Pi());
515   hEPV0CCor  = new TH2F("hEPV0CCor",   "EPV0C  vs cent after PHOS Correct", 100, 0., 100., 100, 0., TMath::Pi());
516   fOutput->Add(hEPTPCCor);
517   fOutput->Add(hEPV0ACor);
518   fOutput->Add(hEPV0CCor);
519
520   hdifV0Ar_V0Cr    = new TH2F("hdifV0Ar_V0Cr",    "EP Ar-Cr ", 100, 0., 100., 100, -1., 1.);    
521   hdifV0A_V0CR0    = new TH2F("hdifV0A_V0CR0",    "EP A-R0 ",  100, 0., 100., 100, -1., 1.);    
522   hdifV0A_V0CR3    = new TH2F("hdifV0A_V0CR3",    "EP A-R3 ",  100, 0., 100., 100, -1., 1.);    
523   hdifV0ACR0_V0CR3 = new TH2F("hdifV0ACR0_V0CR3", "EP R0-R3 ", 100, 0., 100., 100, -1., 1.);    
524   hdifV0C_V0AR4    = new TH2F("hdifV0C_V0AR4",    "EP C-R4 ",  100, 0., 100., 100, -1., 1.);    
525   hdifV0C_V0AR7    = new TH2F("hdifV0C_V0AR7",    "EP C-R7 ",  100, 0., 100., 100, -1., 1.);    
526   hdifV0AR4_V0AR7  = new TH2F("hdifV0AR4_V0AR7",  "EP R4-R7 ", 100, 0., 100., 100, -1., 1.);    
527   fOutput->Add(hdifV0Ar_V0Cr);
528   fOutput->Add(hdifV0A_V0CR0);
529   fOutput->Add(hdifV0A_V0CR3);
530   fOutput->Add(hdifV0ACR0_V0CR3);
531   fOutput->Add(hdifV0C_V0AR4);
532   fOutput->Add(hdifV0C_V0AR7);
533   fOutput->Add(hdifV0AR4_V0AR7);
534
535   hdifV0A_V0C = new TH2F("hdifV0A_V0C", "EP A-C  ", 100, 0., 100., 100, -1., 1.);
536   hdifV0A_TPC = new TH2F("hdifV0A_TPC", "EP A-TPC", 100, 0., 100., 100, -1., 1.);
537   hdifV0C_TPC = new TH2F("hdifV0C_TPC", "EP C-TPC", 100, 0., 100., 100, -1., 1.);
538   hdifV0C_V0A = new TH2F("hdifV0C_V0A", "EP C-A  ", 100, 0., 100., 100, -1., 1.);
539   fOutput->Add(hdifV0A_V0C);
540   fOutput->Add(hdifV0A_TPC);
541   fOutput->Add(hdifV0C_TPC);
542   fOutput->Add(hdifV0C_V0A);
543
544   hdifEMC_EPV0  = new TH3F("hdifEMC_EPV0",  "dif phi in EMC with EP",  100, 0., 100., 100, 0., TMath::Pi(), 15, 0., 15.);
545   hdifEMC_EPV0A = new TH3F("hdifEMC_EPV0A", "dif phi in EMC with EP",  100, 0., 100., 100, 0., TMath::Pi(), 15, 0., 15.);
546   hdifEMC_EPV0C = new TH3F("hdifEMC_EPV0C", "dif phi in EMC with EP",  100, 0., 100., 100, 0., TMath::Pi(), 15, 0., 15.);
547   fOutput->Add(hdifEMC_EPV0);
548   fOutput->Add(hdifEMC_EPV0A);
549   fOutput->Add(hdifEMC_EPV0C);
550
551   hdifful_EPV0 = new TH3F("hdifful_EPV0",    "dif phi in full with EP", 100, 0., 100., 100, 0., TMath::Pi(), 15, 0., 15.);
552   hdifful_EPV0A = new TH3F("hdifful_EPV0A",  "dif phi in full with EP", 100, 0., 100., 100, 0., TMath::Pi(), 15, 0., 15.);
553   hdifful_EPV0C = new TH3F("hdifful_EPV0C",  "dif phi in full with EP", 100, 0., 100., 100, 0., TMath::Pi(), 15, 0., 15.);
554   fOutput->Add(hdifful_EPV0);
555   fOutput->Add(hdifful_EPV0A);
556   fOutput->Add(hdifful_EPV0C);
557
558   hdifout_EPV0  = new TH3F("hdifout_EPV0",  "dif phi NOT in EMC with EP", 100, 0., 100., 100, 0., TMath::Pi(), 15, 0., 15.);
559   hdifout_EPV0A = new TH3F("hdifout_EPV0A", "dif phi NOT in EMC with EP", 100, 0., 100., 100, 0., TMath::Pi(), 15, 0., 15.);
560   hdifout_EPV0C = new TH3F("hdifout_EPV0C", "dif phi NOT in EMC with EP", 100, 0., 100., 100, 0., TMath::Pi(), 15, 0., 15.);
561   fOutput->Add(hdifout_EPV0);
562   fOutput->Add(hdifout_EPV0A);
563   fOutput->Add(hdifout_EPV0C);
564
565   if (isV1Clus) {
566     //  Et   M02  spdcent DeltaPhi    Dr  
567     Int_t    bins[5] = {  500, 350,  100,     100,      100}; // binning
568     Double_t min[5]  = {  0.0, 0.0,    0,     0.0,      0 }; // min x
569     Double_t max[5]  = { 50.0, 3.5,  100,  TMath::Pi(), 0.1}; // max x
570
571     fClusterPbV0A = new THnSparseF("fClusterPbV0A","",5,bins,min,max);
572     fClusterPbV0A->GetAxis(0)->SetTitle("Transverse Energy [GeV]"); 
573     fClusterPbV0A->GetAxis(1)->SetTitle("M02"); 
574     fClusterPbV0A->GetAxis(2)->SetTitle("V0M Centrality");
575     fClusterPbV0A->GetAxis(3)->SetTitle("Delta(#phi) [rad]"); 
576     fClusterPbV0A->GetAxis(4)->SetTitle("Dr"); 
577     fOutput->Add(fClusterPbV0A);
578
579     fClusterPbV0C = new THnSparseF("fClusterPbV0C","",5,bins,min,max);
580     fClusterPbV0C->GetAxis(0)->SetTitle("Transverse Energy [GeV]"); 
581     fClusterPbV0C->GetAxis(1)->SetTitle("M02"); 
582     fClusterPbV0C->GetAxis(2)->SetTitle("V0M Centrality");
583     fClusterPbV0C->GetAxis(3)->SetTitle("Delta(#phi) [rad]"); 
584     fClusterPbV0C->GetAxis(4)->SetTitle("Dr");
585     fOutput->Add(fClusterPbV0C);
586
587     fClusterPbTPC = new THnSparseF("fClusterPbTPC","",5,bins,min,max);
588     fClusterPbTPC->GetAxis(0)->SetTitle("Transverse Energy [GeV]"); 
589     fClusterPbTPC->GetAxis(1)->SetTitle("M02"); 
590     fClusterPbTPC->GetAxis(2)->SetTitle("V0M Centrality");
591     fClusterPbTPC->GetAxis(3)->SetTitle("Delta(#phi) [rad]"); 
592     fClusterPbTPC->GetAxis(4)->SetTitle("Dr");
593     fOutput->Add(fClusterPbTPC);
594   }
595   
596   h2DcosV0A = new TProfile("h2DcosV0A", "cos(Phi) V0r vs Run NUmber", 200, 0., 200.);
597   h2DsinV0A = new TProfile("h2DsinV0A", "sin(Phi) V0r vs Run NUmber", 200, 0., 200.);
598   h2DcosV0C = new TProfile("h2DcosV0C", "cos(Phi) V0r vs Run NUmber", 200, 0., 200.);
599   h2DsinV0C = new TProfile("h2DsinV0C", "sin(Phi) V0r vs Run NUmber", 200, 0., 200.);
600   h2DcosTPC = new TProfile("h2DcosTPC", "cos(Phi) V0r vs Run NUmber", 200, 0., 200.);
601   h2DsinTPC = new TProfile("h2DsinTPC", "sin(Phi) V0r vs Run NUmber", 200, 0., 200.);
602   fOutput->Add(h2DcosV0A);
603   fOutput->Add(h2DsinV0A);
604   fOutput->Add(h2DcosV0C);
605   fOutput->Add(h2DsinV0C);
606   fOutput->Add(h2DcosTPC);
607   fOutput->Add(h2DsinTPC);
608
609   if (isV1Clus) {
610     hM02vsPtA = new TH2F("hM02vsPtA", "M02 vs Et before cut", 5000, 0, 50, 400, 0, 4.);
611     hM02vsPtB = new TH2F("hM02vsPtB", "M02 vs Et before cut", 5000, 0, 50, 400, 0, 4.);
612     fOutput->Add(hM02vsPtA);
613     fOutput->Add(hM02vsPtB);
614   }
615   hClusDxDZA = new TH2F("hClusDxDZA", "clus Dx vs Dz", 1000, -1., 1., 1000, -1., 1);  
616   hClusDxDZB = new TH2F("hClusDxDZB", "clus Dx vs Dz", 1000, -1., 1., 1000, -1., 1);
617   fOutput->Add(hClusDxDZA);
618   fOutput->Add(hClusDxDZB);
619     
620   if (!isV1Clus) {
621     const Int_t ndims = 4;
622     Int_t nMgg=500, nPt=40, nCent=20, nDeltaPhi=315;
623     Int_t binsv1[ndims] = {nMgg, nPt, nCent, nDeltaPhi};
624     Double_t xmin[ndims] = { 0,   0.,  0,   0.};
625     Double_t xmax[ndims] = { 0.5, 20., 100, 3.15};
626     fHEPV0A = new THnSparseF("fHEPV0A",   "Flow histogram EPV0A", ndims, binsv1, xmin, xmax);
627     fHEPV0C = new THnSparseF("fHEPV0C",   "Flow histogram EPV0C", ndims, binsv1, xmin, xmax);
628     fHEPTPC = new THnSparseF("fHEPTPC",   "Flow histogram EPTPC", ndims, binsv1, xmin, xmax);
629     fHEPV0A->GetAxis(0)->SetTitle("m_{#gamma#gamma} "); 
630     fHEPV0A->GetAxis(1)->SetTitle("p_{T}[GeV]"); 
631     fHEPV0A->GetAxis(2)->SetTitle("centrality");
632     fHEPV0A->GetAxis(3)->SetTitle("#delta #phi");
633     fHEPV0C->GetAxis(0)->SetTitle("m_{#gamma#gamma} "); 
634     fHEPV0C->GetAxis(1)->SetTitle("p_{T}[GeV]"); 
635     fHEPV0C->GetAxis(2)->SetTitle("centrality");
636     fHEPV0C->GetAxis(3)->SetTitle("#delta #phi");
637     fHEPTPC->GetAxis(0)->SetTitle("m_{#gamma#gamma} "); 
638     fHEPTPC->GetAxis(1)->SetTitle("p_{T}[GeV]"); 
639     fHEPTPC->GetAxis(2)->SetTitle("centrality");
640     fHEPTPC->GetAxis(3)->SetTitle("#delta #phi");
641     fOutput->Add(fHEPV0A);
642     fOutput->Add(fHEPV0C);
643     fOutput->Add(fHEPTPC);
644   }
645   PostData(1, fOutput); // Post data for ALL output slots >0 here, to get at least an empty histogram
646 }
647
648 //________________________________________________________________________
649 void AliAnalysisTaskPi0V2::UserExec(Option_t *) 
650 {
651   // Main loop
652   // Called for each event
653
654   hEvtCount->Fill(1);
655   // Create pointer to reconstructed event
656
657   AliVEvent *event = InputEvent();
658   if (!event) { 
659     AliError("Could not retrieve event"); 
660     return; 
661   }
662
663   // create pointer to event
664   TString type = AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()->GetDataType();
665   if (type=="ESD") {
666     fESD = dynamic_cast<AliESDEvent*>(event);
667     if (!fESD) {
668       AliError("Cannot get the ESD event");
669       return;
670     }
671   } else if (type=="AOD") {
672     fAOD = dynamic_cast<AliAODEvent*>(event);
673     if (!fAOD) {
674       AliError("Cannot get the AOD event");
675       return;
676     }
677   } else {
678     AliError("Cannot happen");
679     return;
680   }
681
682   hEvtCount->Fill(2);
683   if (!fTrigClass.IsNull()) {
684     TString fired;
685     if (fESD) {
686       fired = fESD->GetFiredTriggerClasses();
687     } else {
688       fired = fAOD->GetFiredTriggerClasses();
689     }
690     if (!fired.Contains("-B-"))
691       return;
692     TObjArray *arr = fTrigClass.Tokenize("|");
693     if (!arr)
694       return;
695     Bool_t match = 0;
696     for (Int_t i=0;i<arr->GetEntriesFast();++i) {
697       TObject *obj = arr->At(i);
698       if (!obj)
699         continue;
700       if (fired.Contains(obj->GetName())) {
701         match = 1;
702         break;
703       }
704     }
705     delete arr;
706     if (!match)
707       return;
708   }
709   hEvtCount->Fill(3);
710
711   if (fRunNumber != event->GetRunNumber()) {
712     fRunNumber = event->GetRunNumber();
713     SetFlatteningData();
714   }
715
716   fInterRunNumber = ConvertToInternalRunNumber(fRunNumber);
717
718   const AliVVertex* fvertex;
719   fvertex = event->GetPrimaryVertex();
720
721   if (TMath::Abs(fvertex->GetZ())>fVtxCut)
722     return;
723   Double_t vertex[3] = {fvertex->GetX(), fvertex->GetY(), fvertex->GetZ()};
724
725   hEvtCount->Fill(4);
726
727   fCentrality = event->GetCentrality()->GetCentralityPercentile("CL1"); //spd vertex
728
729   hEvtCount->Fill(5);
730
731   AliEventplane *ep = event->GetEventplane();
732   if (ep) {
733     if (ep->GetEventplane("Q") != -1)
734       fEPTPC    = ep->GetEventplane("Q");
735     else
736       fEPTPC = -999.;
737     if (ep->GetEventplane("Q") != -1)
738       fEPTPCreso  = TMath::Cos(2.*(ep->GetQsubRes()));
739     else
740       fEPTPCreso = -1;
741
742     fEPV0    = ep->GetEventplane("V0",  event);
743     fEPV0A   = ep->GetEventplane("V0A", event);
744     fEPV0C   = ep->GetEventplane("V0C", event);
745     Double_t qx=0, qy=0;
746     Double_t qxr=0, qyr=0;
747     fEPV0Ar  = ep->CalculateVZEROEventPlane(event, 4, 5, 2, qxr, qyr);
748     fEPV0Cr  = ep->CalculateVZEROEventPlane(event, 2, 3, 2, qx,  qy);
749     qxr += qx;
750     qyr += qy;
751     fEPV0r   = TMath::ATan2(qyr,qxr)/2.;
752     fEPV0AR4 = ep->CalculateVZEROEventPlane(event, 4, 2, qx, qy);
753     fEPV0AR5 = ep->CalculateVZEROEventPlane(event, 5, 2, qx, qy);
754     fEPV0AR6 = ep->CalculateVZEROEventPlane(event, 6, 2, qx, qy);
755     fEPV0AR7 = ep->CalculateVZEROEventPlane(event, 7, 2, qx, qy);
756     fEPV0CR0 = ep->CalculateVZEROEventPlane(event, 0, 2, qx, qy);
757     fEPV0CR1 = ep->CalculateVZEROEventPlane(event, 1, 2, qx, qy);
758     fEPV0CR2 = ep->CalculateVZEROEventPlane(event, 2, 2, qx, qy);
759     fEPV0CR3 = ep->CalculateVZEROEventPlane(event, 3, 2, qx, qy);
760   } 
761
762   FillEPQA(); //Fill the EP QA
763
764   hEvtCount->Fill(6);
765
766   fEPV0   = TVector2::Phi_0_2pi(fEPV0);    
767   if (fEPV0>TMath::Pi())   
768     fEPV0  = fEPV0 - TMath::Pi();
769   fEPV0r  = TVector2::Phi_0_2pi(fEPV0r);   
770   if (fEPV0r>TMath::Pi())  
771     fEPV0r = fEPV0r - TMath::Pi();
772   fEPV0A  = TVector2::Phi_0_2pi(fEPV0A);   
773   if (fEPV0A>TMath::Pi())  
774     fEPV0A = fEPV0A - TMath::Pi();
775   fEPV0C  = TVector2::Phi_0_2pi(fEPV0C);   
776   if (fEPV0C>TMath::Pi())  
777     fEPV0C = fEPV0C - TMath::Pi();
778   fEPV0Ar = TVector2::Phi_0_2pi(fEPV0Ar);  
779   if (fEPV0Ar>TMath::Pi()) 
780     fEPV0Ar = fEPV0Ar - TMath::Pi();
781   fEPV0Cr = TVector2::Phi_0_2pi(fEPV0Cr);  
782   if (fEPV0Cr>TMath::Pi()) 
783     fEPV0Cr = fEPV0Cr - TMath::Pi();
784   fEPV0AR4   = TVector2::Phi_0_2pi(fEPV0AR4);    
785   if (fEPV0AR4>TMath::Pi())   
786     fEPV0AR4  = fEPV0AR4 - TMath::Pi();
787   fEPV0AR7   = TVector2::Phi_0_2pi(fEPV0AR7);    
788   if (fEPV0AR7>TMath::Pi())   
789     fEPV0AR7  = fEPV0AR7 - TMath::Pi();
790   fEPV0CR0   = TVector2::Phi_0_2pi(fEPV0CR0);    
791   if (fEPV0CR0>TMath::Pi())   
792     fEPV0CR0  = fEPV0CR0 - TMath::Pi();
793   fEPV0CR3   = TVector2::Phi_0_2pi(fEPV0CR3);    
794   if (fEPV0CR3>TMath::Pi())   
795     fEPV0CR3  = fEPV0CR3 - TMath::Pi();
796   if (fEPTPC != -999. )
797     hEPTPC->Fill(fCentrality,  fEPTPC); 
798   if (fEPTPCreso!=-1) 
799     hresoTPC->Fill(fCentrality, fEPTPCreso);
800   hEPV0->Fill(fCentrality,   fEPV0);
801   hEPV0A->Fill(fCentrality,  fEPV0A);
802   hEPV0C->Fill(fCentrality,  fEPV0C);
803   hEPV0Ar->Fill(fCentrality, fEPV0Ar);
804   hEPV0Cr->Fill(fCentrality, fEPV0Cr);
805   hEPV0r->Fill(fCentrality,  fEPV0r);
806   hEPV0AR4->Fill(fCentrality, fEPV0AR4);
807   hEPV0AR7->Fill(fCentrality, fEPV0AR7);
808   hEPV0CR0->Fill(fCentrality, fEPV0CR0);
809   hEPV0CR3->Fill(fCentrality, fEPV0CR3);
810
811   if (isPhosCali) {
812     // PHOS Flattening
813     fEPV0A = ApplyFlatteningV0A(fEPV0A, fCentrality); //V0A after Phos flatten
814     fEPV0C = ApplyFlatteningV0C(fEPV0C, fCentrality); //V0C after Phos flatten
815     if(fEPTPC != -999.)
816       fEPTPC = ApplyFlattening(fEPTPC, fCentrality);  //TPC after Phos flatten
817   }
818
819   if (!isPhosCali) { 
820     if(fEPTPC != -999.)
821       hEPTPCCor->Fill(fCentrality, ApplyFlattening(fEPTPC, fCentrality));
822     hEPV0ACor->Fill(fCentrality, ApplyFlatteningV0A(fEPV0A, fCentrality));
823     hEPV0CCor->Fill(fCentrality, ApplyFlatteningV0C(fEPV0C, fCentrality));
824   } else {
825     if(fEPTPC != -999.)
826       hEPTPCCor->Fill(fCentrality, fEPTPC);
827     hEPV0ACor->Fill(fCentrality, fEPV0A);
828     hEPV0CCor->Fill(fCentrality, fEPV0C);
829   } 
830
831   hdifV0Ar_V0Cr->Fill(fCentrality, TMath::Cos(2.*(fEPV0Ar - fEPV0Cr)));
832   hdifV0A_V0CR0->Fill(fCentrality, TMath::Cos(2.*(fEPV0A - fEPV0CR0)));
833   hdifV0A_V0CR3->Fill(fCentrality, TMath::Cos(2.*(fEPV0A - fEPV0CR3)));
834   hdifV0ACR0_V0CR3->Fill(fCentrality, TMath::Cos(2*(fEPV0CR0 - fEPV0CR3)));
835   hdifV0C_V0AR4->Fill(fCentrality, TMath::Cos(2*(fEPV0C - fEPV0AR4)));
836   hdifV0C_V0AR7->Fill(fCentrality, TMath::Cos(2*(fEPV0C - fEPV0AR7)));
837   hdifV0AR4_V0AR7->Fill(fCentrality, TMath::Cos(2*(fEPV0AR4 - fEPV0AR7)));
838         
839   hdifV0A_V0C->Fill(fCentrality, TMath::Cos(2*(fEPV0A - fEPV0C)));
840   if (fEPTPC!=-999.){
841     hdifV0A_TPC->Fill(fCentrality, TMath::Cos(2*(fEPV0A - fEPTPC)));
842     hdifV0C_TPC->Fill(fCentrality, TMath::Cos(2*(fEPV0C - fEPTPC)));
843   }
844   hdifV0C_V0A->Fill(fCentrality, TMath::Cos(2*(fEPV0C - fEPV0A)));
845
846   // Cluster loop for reconstructed event
847
848   //================ for v2 clusterize analysis==============================================
849   if (!isV1Clus) {
850     if (!fV2ClusName.IsNull() && !fV2Clus) {
851       fV2Clus = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fV2ClusName));
852       if (!fV2Clus) {
853         AliError(Form("%s: Could not retrieve v2 cluster name %s!", GetName(), fV2ClusName.Data()));
854         return;
855       }
856     }
857     Int_t nCluster =  fV2Clus->GetEntries(); 
858     for (Int_t i=0; i<nCluster; ++i) {
859       AliVCluster *c1 = static_cast<AliVCluster*>(fV2Clus->At(i));      
860       if (!c1) 
861         continue;
862       hClusDxDZA->Fill(c1->GetTrackDz(), c1->GetTrackDx());
863       if (!c1->IsEMCAL()) 
864         continue;
865       if (!IsGoodCluster(c1)) 
866         continue;
867       hClusDxDZB->Fill(c1->GetTrackDz(), c1->GetTrackDx());
868       TLorentzVector p1;
869       GetMom(p1, c1, vertex);
870       for (Int_t j=i+1; j<nCluster; ++j) {
871         AliVCluster *c2 = static_cast<AliVCluster*>(fV2Clus->At(j));      
872         if (!c2) 
873           continue;
874         if (!c2->IsEMCAL()) 
875           continue;
876         if (!IsGoodCluster(c2)) 
877           continue;
878         TLorentzVector p2;
879         GetMom(p2, c2, vertex);
880         FillPion(p1, p2, fEPV0A, fEPV0C, fEPTPC);
881       }
882     }
883   }
884
885   //================ for v1 clusterize analysis==============================================
886   if (isV1Clus) {
887     if (!fV2ClusName.IsNull() && !fV1Clus) {
888       fV1Clus = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fV1ClusName));
889       if (!fV1Clus) {
890         AliError(Form("%s: Could not retrieve v1 cluster name %s!", GetName(), fV1ClusName.Data()));
891         return;
892       }
893     }
894     Int_t nClusterV1 = fV1Clus->GetEntries();
895     for (Int_t i=0; i<nClusterV1; ++i) {
896       AliVCluster *c3 = dynamic_cast<AliVCluster*>(fV1Clus->At(i));      
897       if (!c3) 
898         continue;
899       if (!c3->IsEMCAL()) 
900         continue;
901       Double_t M02c3 = c3->GetM02();
902       Double_t Dxc3  = c3->GetTrackDx();
903       Double_t Dzc3  = c3->GetTrackDz(); 
904
905       hClusDxDZA->Fill(Dzc3, Dxc3);
906       Float_t clsPosEt[3] = {0,0,0};
907       c3->GetPosition(clsPosEt);
908       TVector3 clsVec(clsPosEt);
909       Double_t Et = c3->E()*TMath::Sin(clsVec.Theta());
910       hM02vsPtA->Fill(Et, M02c3);
911       if (!IsGoodClusterV1(c3)) 
912         continue;
913       hM02vsPtB->Fill(Et, M02c3);
914       hClusDxDZB->Fill(Dzc3, Dxc3);
915       TLorentzVector p3;
916       GetMom(p3, c3, vertex);
917       FillCluster(p3, fEPV0A, fEPV0C, fEPTPC, c3);
918     }
919   }
920
921   hEvtCount->Fill(7);
922
923   if (!fTracksName.IsNull() && !fTracks) {
924     fTracks = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fTracksName));
925     if (!fTracks) {
926       AliError(Form("%s: Could not retrieve tracks %s!", GetName(), fTracksName.Data())); 
927       return;
928     }
929   }
930
931   Int_t ntracks = fTracks->GetEntries();
932   for (Int_t i=0; i<ntracks; ++i){
933     AliVTrack *track = static_cast<AliVTrack*>(fTracks->At(i));
934     if (!track) 
935       continue;
936     Double_t tPhi = track->Phi();
937     Double_t tPt  = track->Pt();
938     Double_t Eta  = track->Eta();
939     
940     Double_t difTrackV0  = TVector2::Phi_0_2pi(tPhi-fEPV0);   
941     if (difTrackV0  >TMath::Pi()) 
942       difTrackV0  -= TMath::Pi();
943     Double_t difTrackV0A = TVector2::Phi_0_2pi(tPhi-fEPV0A);  
944     if (difTrackV0A >TMath::Pi()) 
945       difTrackV0A -= TMath::Pi();
946     Double_t difTrackV0C = TVector2::Phi_0_2pi(tPhi-fEPV0C);  
947     if (difTrackV0C >TMath::Pi()) 
948       difTrackV0C -= TMath::Pi();
949     Double_t difTrackTPC = TVector2::Phi_0_2pi(tPhi-fEPTPC);  
950     if (difTrackTPC >TMath::Pi()) 
951       difTrackTPC -= TMath::Pi();
952     if (tPhi*TMath::RadToDeg()>80. && tPhi*TMath::RadToDeg()<180. && Eta <0.7 && Eta >(-0.7)){  
953       hdifEMC_EPV0->Fill(fCentrality, difTrackV0, tPt);
954       hdifEMC_EPV0A->Fill(fCentrality, difTrackV0A, tPt);
955       hdifEMC_EPV0C->Fill(fCentrality, difTrackV0C, tPt);
956     } else {
957       hdifout_EPV0->Fill(fCentrality, difTrackV0, tPt);
958       hdifout_EPV0A->Fill(fCentrality, difTrackV0A, tPt);
959       hdifout_EPV0C->Fill(fCentrality, difTrackV0C, tPt);
960     }
961     hdifful_EPV0->Fill(fCentrality,    difTrackV0, tPt);
962     hdifful_EPV0A->Fill(fCentrality,   difTrackV0A, tPt);
963     hdifful_EPV0C->Fill(fCentrality,   difTrackV0C, tPt);
964   } 
965   hEvtCount->Fill(8);
966
967   // NEW HISTO should be filled before this point, as PostData puts the
968   // information for this iteration of the UserExec in the container
969   PostData(1, fOutput);
970 }
971
972 //____________________________________________________________________
973 Int_t AliAnalysisTaskPi0V2::ConvertToInternalRunNumber(Int_t n)
974 {
975   switch(n) {
976     case  170593 : return 179;
977     case  170572 : return 178;
978     case  170556 : return 177;
979     case  170552 : return 176;
980     case  170546 : return 175;
981     case  170390 : return 174;
982     case  170389 : return 173;
983     case  170388 : return 172;
984     case  170387 : return 171;
985     case  170315 : return 170;
986     case  170313 : return 169;
987     case  170312 : return 168;
988     case  170311 : return 167;
989     case  170309 : return 166;
990     case  170308 : return 165;
991     case  170306 : return 164;
992     case  170270 : return 163;
993     case  170269 : return 162;
994     case  170268 : return 161;
995     case  170267 : return 160;
996     case  170264 : return 159;
997     case  170230 : return 158;
998     case  170228 : return 157;
999     case  170208 : return 156;
1000     case  170207 : return 155;
1001     case  170205 : return 154;
1002     case  170204 : return 153;
1003     case  170203 : return 152;
1004     case  170195 : return 151;
1005     case  170193 : return 150;
1006     case  170163 : return 149;
1007     case  170162 : return 148;
1008     case  170159 : return 147;
1009     case  170155 : return 146;
1010     case  170152 : return 145;
1011     case  170091 : return 144;
1012     case  170089 : return 143;
1013     case  170088 : return 142;
1014     case  170085 : return 141;
1015     case  170084 : return 140;
1016     case  170083 : return 139;
1017     case  170081 : return 138;
1018     case  170040 : return 137;
1019     case  170038 : return 136;
1020     case  170036 : return 135;
1021     case  170027 : return 134;
1022     case  169981 : return 133;
1023     case  169975 : return 132;
1024     case  169969 : return 131;
1025     case  169965 : return 130;
1026     case  169961 : return 129;
1027     case  169956 : return 128;
1028     case  169926 : return 127;
1029     case  169924 : return 126;
1030     case  169923 : return 125;
1031     case  169922 : return 124;
1032     case  169919 : return 123;
1033     case  169918 : return 122;
1034     case  169914 : return 121;
1035     case  169859 : return 120;
1036     case  169858 : return 119;
1037     case  169855 : return 118;
1038     case  169846 : return 117;
1039     case  169838 : return 116;
1040     case  169837 : return 115;
1041     case  169835 : return 114;
1042     case  169683 : return 113;
1043     case  169628 : return 112;
1044     case  169591 : return 111;
1045     case  169590 : return 110;
1046     case  169588 : return 109;
1047     case  169587 : return 108;
1048     case  169586 : return 107;
1049     case  169584 : return 106;
1050     case  169557 : return 105;
1051     case  169555 : return 104;
1052     case  169554 : return 103;
1053     case  169553 : return 102;
1054     case  169550 : return 101;
1055     case  169515 : return 100;
1056     case  169512 : return 99;
1057     case  169506 : return 98;
1058     case  169504 : return 97;
1059     case  169498 : return 96;
1060     case  169475 : return 95;
1061     case  169420 : return 94;
1062     case  169419 : return 93;
1063     case  169418 : return 92;
1064     case  169417 : return 91;
1065     case  169415 : return 90;
1066     case  169411 : return 89;
1067     case  169238 : return 88;
1068     case  169236 : return 87;
1069     case  169167 : return 86;
1070     case  169160 : return 85;
1071     case  169156 : return 84;
1072     case  169148 : return 83;
1073     case  169145 : return 82;
1074     case  169144 : return 81;
1075     case  169143 : return 80;
1076     case  169138 : return 79;
1077     case  169099 : return 78;
1078     case  169094 : return 77;
1079     case  169091 : return 76;
1080     case  169045 : return 75;
1081     case  169044 : return 74;
1082     case  169040 : return 73;
1083     case  169035 : return 72;
1084     case  168992 : return 71;
1085     case  168988 : return 70;
1086     case  168984 : return 69;
1087     case  168826 : return 68;
1088     case  168777 : return 67;
1089     case  168514 : return 66;
1090     case  168512 : return 65;
1091     case  168511 : return 64;
1092     case  168467 : return 63;
1093     case  168464 : return 62;
1094     case  168461 : return 61;
1095     case  168460 : return 60;
1096     case  168458 : return 59;
1097     case  168362 : return 58;
1098     case  168361 : return 57;
1099     case  168356 : return 56;
1100     case  168342 : return 55;
1101     case  168341 : return 54;
1102     case  168325 : return 53;
1103     case  168322 : return 52;
1104     case  168318 : return 51;
1105     case  168311 : return 50;
1106     case  168310 : return 49;
1107     case  168213 : return 48;
1108     case  168212 : return 47;
1109     case  168208 : return 46;
1110     case  168207 : return 45;
1111     case  168206 : return 44;
1112     case  168205 : return 43;
1113     case  168204 : return 42;
1114     case  168203 : return 41;
1115     case  168181 : return 40;
1116     case  168177 : return 39;
1117     case  168175 : return 38;
1118     case  168173 : return 37;
1119     case  168172 : return 36;
1120     case  168171 : return 35;
1121     case  168115 : return 34;
1122     case  168108 : return 33;
1123     case  168107 : return 32;
1124     case  168105 : return 31;
1125     case  168104 : return 30;
1126     case  168103 : return 29;
1127     case  168076 : return 28;
1128     case  168069 : return 27;
1129     case  168068 : return 26;
1130     case  168066 : return 25;
1131     case  167988 : return 24;
1132     case  167987 : return 23;
1133     case  167986 : return 22;
1134     case  167985 : return 21;
1135     case  167921 : return 20;
1136     case  167920 : return 19;
1137     case  167915 : return 18;
1138     case  167909 : return 17;
1139     case  167903 : return 16;
1140     case  167902 : return 15;
1141     case  167818 : return 14;
1142     case  167814 : return 13;
1143     case  167813 : return 12;
1144     case  167808 : return 11;
1145     case  167807 : return 10;
1146     case  167806 : return 9;
1147     case  167713 : return 8;
1148     case  167712 : return 7;
1149     case  167711 : return 6;
1150     case  167706 : return 5;
1151     case  167693 : return 4;
1152     case  166532 : return 3;
1153     case  166530 : return 2;
1154     case  166529 : return 1;
1155
1156     default : return 199;
1157   }
1158 }
1159
1160 //_______________________________________________________________________
1161 void AliAnalysisTaskPi0V2::FillEPQA()
1162 {
1163   h2DcosV0A->Fill(fInterRunNumber, TMath::Cos(fEPV0A));
1164   h2DsinV0A->Fill(fInterRunNumber, TMath::Sin(fEPV0A));
1165   h2DcosV0C->Fill(fInterRunNumber, TMath::Cos(fEPV0C));
1166   h2DsinV0C->Fill(fInterRunNumber, TMath::Sin(fEPV0C));
1167   if (fEPTPC!=-999.){
1168     h2DcosTPC->Fill(fInterRunNumber, TMath::Cos(fEPTPC));
1169     h2DsinTPC->Fill(fInterRunNumber, TMath::Sin(fEPTPC));
1170   }
1171 }
1172
1173 //_________________________________________________________________________________
1174 void AliAnalysisTaskPi0V2::SetFlatteningData()
1175 {
1176   //Read objects with flattening parameters
1177   AliOADBContainer flatContainer("phosFlat");
1178   flatContainer.InitFromFile(fEPcalibFileName.Data(),"phosFlat");
1179   TObjArray *maps = (TObjArray*)flatContainer.GetObject(fRunNumber,"phosFlat");
1180   if (!maps) {
1181     AliError(Form("Can not read Flattening for run %d. \n From file >%s<\n",fRunNumber,fEPcalibFileName.Data())) ;    
1182   } else {
1183     AliInfo(Form("Setting PHOS flattening with name %s \n",maps->GetName())) ;
1184     AliEPFlattener * h = (AliEPFlattener*)maps->At(0) ;  
1185     if(fTPCFlat) delete fTPCFlat ;
1186     fTPCFlat = new AliEPFlattener();
1187     fTPCFlat = h ;
1188     h = (AliEPFlattener*)maps->At(1);  
1189     if(fV0AFlat) delete fV0AFlat ;
1190     fV0AFlat = new AliEPFlattener();
1191     fV0AFlat = h ;
1192     h = (AliEPFlattener*)maps->At(2);  
1193     if(fV0CFlat) delete fV0CFlat ;
1194     fV0CFlat = new AliEPFlattener();
1195     fV0CFlat = h;
1196   }    
1197 }
1198  
1199 //____________________________________________________________________________
1200 Double_t  AliAnalysisTaskPi0V2::ApplyFlattening(Double_t phi, Double_t c)
1201 {
1202   if(fTPCFlat)
1203     return fTPCFlat->MakeFlat(phi,c);
1204   return phi;
1205 }
1206
1207 //____________________________________________________________________________
1208 Double_t  AliAnalysisTaskPi0V2::ApplyFlatteningV0A(Double_t phi, Double_t c)
1209 {
1210   if(fV0AFlat)
1211     return fV0AFlat->MakeFlat(phi,c);
1212   return phi;
1213 }
1214
1215 //____________________________________________________________________________
1216 Double_t  AliAnalysisTaskPi0V2::ApplyFlatteningV0C(Double_t phi, Double_t c){
1217  
1218   if(fV0CFlat)
1219     return fV0CFlat->MakeFlat(phi,c);
1220   return phi;
1221 }
1222
1223 //________________________________________________________________________
1224 void AliAnalysisTaskPi0V2::Terminate(Option_t *) 
1225 {
1226 }