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