]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGGA/EMCALTasks/AliAnalysisTaskPi0V2.cxx
changes from fzhou
[u/mrichter/AliRoot.git] / PWGGA / EMCALTasks / AliAnalysisTaskPi0V2.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id: AliAnalysisTaskPi0V2.cxx 55404 2012-03-29 10:10:19Z fca $ */
17
18 /* AliAnalysisTaskPi0V2.cxx
19  *
20  * Template task producing a P_t spectrum and pseudorapidity distribution.
21  * Includes explanations of physics and primary track selections
22  *
23  * Instructions for adding histograms can be found below, starting with NEW HISTO
24  *
25  * Based on tutorial example from offline pages
26  * Edited by Arvinder Palaha
27  */
28 #include "AliAnalysisTaskPi0V2.h"
29
30 #include "Riostream.h"
31 #include "TChain.h"
32 #include "TTree.h"
33 #include "TH1F.h"
34 #include "TH2F.h"
35 #include "TH3F.h"
36 #include "TCanvas.h"
37 #include "TList.h"
38
39 #include "AliAnalysisTaskSE.h"
40 #include "AliAnalysisManager.h"
41 #include "AliStack.h"
42 #include "AliESDtrackCuts.h"
43 #include "AliESDEvent.h"
44 #include "AliESDInputHandler.h"
45 #include "AliAODEvent.h"
46 #include "AliMCEvent.h"
47
48 #include "AliEventplane.h"
49 #include "AliEMCALGeometry.h"
50 #include "THnSparse.h"
51
52 using std::cout;
53 using std::endl;
54
55 ClassImp(AliAnalysisTaskPi0V2)
56
57 //________________________________________________________________________
58 //AliAnalysisTaskPi0V2::AliAnalysisTaskPi0V2() // All data members should be initialised here
59 AliAnalysisTaskPi0V2::AliAnalysisTaskPi0V2(const char *name) // All data members should be initialised here
60    :AliAnalysisTaskSE(name),
61     fOutput(0),
62     fESD(0),
63     fcheckEP2sub(1),
64     fCentrality(99.),
65     fEPTPC(-999.),
66     fEPTPCreso(0.), 
67     fEPV0(-999.), fEPV0A(-999.), fEPV0C(-999.), fEPV0Ar(-999.), fEPV0Cr(-999.), fEPV0r(-999.),
68     fEPV0AR4(-999.), fEPV0AR5(-999.), fEPV0AR6(-999.), fEPV0AR7(-999.), fEPV0CR0(-999.), fEPV0CR1(-999.), fEPV0CR2(-999.), fEPV0CR3(-999.),
69     hEvtCount(0), hAllcentV0(0), hAllcentV0r(0), hAllcentV0A(0), hAllcentV0C(0), hAllcentTPC(0),
70     hEPTPC(0), hresoTPC(0),
71     hEPV0(0), hEPV0A(0), hEPV0C(0), hEPV0Ar(0), hEPV0Cr(0), hEPV0r(0), hEPV0AR4(0), hEPV0AR7(0), hEPV0CR0(0), hEPV0CR3(0),
72     hdifV0A_V0CR0(0), hdifV0A_V0CR3(0), hdifV0ACR0_V0CR3(0), hdifV0C_V0AR4(0), hdifV0C_V0AR7(0), hdifV0AR4_V0AR7(0),
73     hdifV0A_V0C(0), hdifV0A_TPC(0), hdifV0C_TPC(0), hdifV0C_V0A(0), 
74     hdifEMC_EP(0), hdifful_EP(0), hdifout_EP(0),
75     fHEPV0r(0), fHEPV0A(0), fHEPV0C(0), fHEPTPC(0)
76
77 {
78     // Dummy constructor ALWAYS needed for I/O.
79     DefineInput(0, TChain::Class());
80     DefineOutput(1, TList::Class());                                            // for output list
81 }
82
83 //________________________________________________________________________
84 //AliAnalysisTaskPi0V2::AliAnalysisTaskPi0V2(const char *name) // All data members should be initialised here
85 AliAnalysisTaskPi0V2::AliAnalysisTaskPi0V2() // All data members should be initialised here
86    :AliAnalysisTaskSE(),
87     fOutput(0),
88     fESD(0),
89     fcheckEP2sub(1),
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), hAllcentV0(0), hAllcentV0r(0), hAllcentV0A(0), hAllcentV0C(0), hAllcentTPC(0),
96     hEPTPC(0), hresoTPC(0),
97     hEPV0(0), hEPV0A(0), hEPV0C(0), hEPV0Ar(0), hEPV0Cr(0), hEPV0r(0), hEPV0AR4(0), hEPV0AR7(0), hEPV0CR0(0), hEPV0CR3(0),
98     hdifV0A_V0CR0(0), hdifV0A_V0CR3(0), hdifV0ACR0_V0CR3(0), hdifV0C_V0AR4(0), hdifV0C_V0AR7(0), hdifV0AR4_V0AR7(0),
99     hdifV0A_V0C(0), hdifV0A_TPC(0), hdifV0C_TPC(0), hdifV0C_V0A(0),  
100     hdifEMC_EP(0), hdifful_EP(0), hdifout_EP(0),
101     fHEPV0r(0), fHEPV0A(0), fHEPV0C(0), fHEPTPC(0)
102 {
103     // Constructor
104     // Define input and output slots here (never in the dummy constructor)
105     // Input slot #0 works with a TChain - it is connected to the default input container
106     // Output slot #1 writes into a TH1 container
107     DefineInput(0, TChain::Class());
108     DefineOutput(1, TList::Class());                                            // for output list
109 }
110
111 //________________________________________________________________________
112 AliAnalysisTaskPi0V2::~AliAnalysisTaskPi0V2()
113 {
114     // Destructor. Clean-up the output list, but not the histograms that are put inside
115     // (the list is owner and will clean-up these histograms). Protect in PROOF case.
116     if (fOutput && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()) {
117         delete fOutput;
118     }
119 }
120 //_____________________________________________________________________
121 Double_t AliAnalysisTaskPi0V2::GetMaxCellEnergy(const AliVCluster *cluster, Short_t &id) const
122 {
123   // Get maximum energy of attached cell.
124
125   id = -1;
126
127   AliVCaloCells *cells = 0;
128   if (fESD)
129     cells = fESD->GetEMCALCells();
130 //  else
131 //    cells = fAOD->GetEMCALCells();
132   if (!cells)
133     return 0;
134
135   Double_t maxe = 0;
136   const Int_t ncells = cluster->GetNCells();
137   for (Int_t i=0; i<ncells; i++) {
138     Double_t e = cells->GetCellAmplitude(TMath::Abs(cluster->GetCellAbsId(i)));
139     if (e>maxe) {
140       maxe = e;
141       id   = cluster->GetCellAbsId(i);
142     }
143   }
144   return maxe;
145 }
146 //_____________________________________________________________________
147 Double_t AliAnalysisTaskPi0V2::GetCrossEnergy(const AliVCluster *cluster, Short_t &idmax) const
148 {
149   // Calculate the energy of cross cells around the leading cell.
150
151   AliVCaloCells *cells = 0;
152   if (fESD)
153     cells = fESD->GetEMCALCells();
154 //  else
155 //    cells = fAOD->GetEMCALCells();
156   if (!cells)
157     return 0;
158
159   AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance();
160   if (!geom)
161     return 0;
162
163   Int_t iSupMod = -1;
164   Int_t iTower  = -1;
165   Int_t iIphi   = -1;
166   Int_t iIeta   = -1;
167   Int_t iphi    = -1;
168   Int_t ieta    = -1;
169   Int_t iphis   = -1;
170   Int_t ietas   = -1;
171
172   Double_t crossEnergy = 0.;
173
174   geom->GetCellIndex(idmax,iSupMod,iTower,iIphi,iIeta);
175   geom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,iIphi, iIeta,iphis,ietas);
176
177   Int_t ncells = cluster->GetNCells();
178   for (Int_t i=0; i<ncells; i++) {
179     Int_t cellAbsId = cluster->GetCellAbsId(i);
180     geom->GetCellIndex(cellAbsId,iSupMod,iTower,iIphi,iIeta);
181     geom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,iIphi, iIeta,iphi,ieta);
182     Int_t aphidiff = TMath::Abs(iphi-iphis);
183     if (aphidiff>1)
184       continue;
185     Int_t aetadiff = TMath::Abs(ieta-ietas);
186     if (aetadiff>1)
187       continue;
188     if ( (aphidiff==1 && aetadiff==0) ||
189         (aphidiff==0 && aetadiff==1) ) {
190       crossEnergy += cells->GetCellAmplitude(cellAbsId);
191     }
192   }
193
194   return crossEnergy;
195 }
196 //_____________________________________________________________________
197 Bool_t AliAnalysisTaskPi0V2::IsWithinFiducialVolume(Short_t id) const
198 {
199   // Check if cell is within given fiducial volume.
200
201   Double_t fNFiducial = 1;
202
203   Int_t iSupMod = -1;
204   Int_t iTower  = -1;
205   Int_t iIphi   = -1;
206   Int_t iIeta   = -1;
207   Int_t iphi    = -1;
208   Int_t ieta    = -1;
209
210   Bool_t okrow = kFALSE;
211   Bool_t okcol = kFALSE;
212
213   AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance();
214   if (!geom)
215     return kFALSE;
216
217   Int_t cellAbsId = id;
218   geom->GetCellIndex(cellAbsId,iSupMod,iTower,iIphi,iIeta);
219   geom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,iIphi, iIeta,iphi,ieta);
220
221   // Check rows/phi
222   if (iSupMod < 10) {
223     if (iphi >= fNFiducial && iphi < 24-fNFiducial)
224       okrow = kTRUE;
225   } else {
226     if (iphi >= fNFiducial && iphi < 12-fNFiducial)
227       okrow = kTRUE;
228   }
229   // Check columns/eta
230   Bool_t noEMCALBorderAtEta0 = kTRUE;
231   if (!noEMCALBorderAtEta0) {
232     if (ieta > fNFiducial && ieta < 48-fNFiducial)
233       okcol = kTRUE;
234   } else {
235     if (iSupMod%2==0) {
236       if (ieta >= fNFiducial)
237         okcol = kTRUE;
238     } else {
239       if (ieta < 48-fNFiducial)
240         okcol = kTRUE;
241     }
242   }
243   if (okrow && okcol)
244      return kTRUE;
245
246   return kFALSE;
247 }
248 //______________________________________________________________________
249 Bool_t AliAnalysisTaskPi0V2::IsGoodCluster(const AliESDCaloCluster *c) const
250 {
251
252   if(!c)
253     return kFALSE;
254
255   if(c->GetNCells() < 2)
256    return kFALSE;
257
258   if(c->E() < 1.)
259    return kFALSE;
260
261   Short_t id = -1;
262   Double_t maxE = GetMaxCellEnergy(c, id); 
263      if((1. - double(GetCrossEnergy(c,id))/maxE) > 0.97)
264     return kFALSE;
265
266
267   Float_t pos1[3];
268   c->GetPosition(pos1);
269   TVector3 clsPos(pos1);
270   Double_t eta = clsPos.Eta();
271
272   if(eta > 0.65 || eta < -0.65)
273     return kFALSE;  
274
275   if (!IsWithinFiducialVolume(id))
276     return kFALSE;
277
278   if(c->GetM02() >0.5 )
279     return kFALSE;
280
281 //  if(c->M20 >)
282
283   return kTRUE;
284
285 }
286 //_____________________________________________________________________
287 Bool_t AliAnalysisTaskPi0V2::IsGoodPion(const TLorentzVector &p1, const TLorentzVector &p2) const
288 {
289   // Is good pion?
290
291
292 //  Double_t asym = TMath::Abs(p1.E()-p2.E())/(p1.E()+p2.E());
293 //  if (asym>0.7)
294 //    return kFALSE;
295
296 //    if (TMath::Abs(p1.Eta()-p2.Eta())>0.5)
297 //      return kFALSE;
298
299   TLorentzVector pion;
300   pion = p1 + p2;
301   Double_t eta = pion.Eta();
302   if (eta<-0.65)
303     return kFALSE;
304   if (eta>0.65)
305     return kFALSE;
306
307   return kTRUE;
308 }
309 //_______________________________________________________________________
310 void AliAnalysisTaskPi0V2::FillPion(const TLorentzVector& p1, const TLorentzVector& p2, Double_t EPV0r, Double_t EPV0A, Double_t EPV0C, Double_t EPTPC)
311 {
312   // Fill histogram.
313
314   if (!IsGoodPion(p1,p2))
315     return;
316   TLorentzVector pion;
317   pion = p1 + p2;
318
319   Double_t mass = pion.M();
320   Double_t pt   = pion.Pt();
321   Double_t phi  = pion.Phi();
322
323   Double_t dphiV0   = phi-EPV0r;
324   Double_t dphiV0A  = phi-EPV0A;
325   Double_t dphiV0C  = phi-EPV0C;
326   Double_t dphiTPC  = phi-EPTPC;
327
328   Double_t cos2phiV0  = TMath::Cos(2.*(dphiV0));
329   Double_t cos2phiV0A = TMath::Cos(2.*(dphiV0A));
330   Double_t cos2phiV0C = TMath::Cos(2.*(dphiV0C));
331   Double_t cos2phiTPC = TMath::Cos(2.*(dphiTPC));
332
333   dphiV0  = TVector2::Phi_0_2pi(dphiV0);  if(dphiV0  >TMath::Pi())  dphiV0 -= TMath::Pi();
334   dphiV0A = TVector2::Phi_0_2pi(dphiV0A); if(dphiV0A >TMath::Pi())  dphiV0A -= TMath::Pi();
335   dphiV0C = TVector2::Phi_0_2pi(dphiV0C); if(dphiV0C >TMath::Pi())  dphiV0C -= TMath::Pi();
336   dphiTPC = TVector2::Phi_0_2pi(dphiTPC); if(dphiTPC >TMath::Pi())  dphiTPC -= TMath::Pi();
337
338   //cout<<"cos2V0: "<<cos2phiV0<<"  cos2V0A: "<<cos2phiV0A<<"  cos2V0C: "<<cos2phiV0C<<endl;
339   //cout<<mass<<"  "<<pt<<"  "<<phi<<"  "<<endl;
340   //cout<<" dphiV0: "<<dphiV0<<"    dphiV0A: "<<dphiV0A<<"  dphiV0C: "<<dphiV0C<<"+++++++"<<endl;
341
342   Double_t xV0[5]; // Match ndims in fH  V0 EP
343   xV0[0]       = mass;
344   xV0[1]       = pt;
345   xV0[2]       = fCentrality;
346   xV0[3]       = dphiV0;
347   xV0[4]       = cos2phiV0;
348   fHEPV0r->Fill(xV0);
349
350   Double_t xV0A[5]; // Match ndims in fH V0A EP
351   xV0A[0]       = mass;
352   xV0A[1]       = pt;
353   xV0A[2]       = fCentrality;
354   xV0A[3]       = dphiV0A;
355   xV0A[4]       = cos2phiV0A;
356   fHEPV0A->Fill(xV0A);
357
358   Double_t xV0C[5]; // Match ndims in fH V0C EP
359   xV0C[0]       = mass;
360   xV0C[1]       = pt;
361   xV0C[2]       = fCentrality;
362   xV0C[3]       = dphiV0C;
363   xV0C[4]       = cos2phiV0C;
364   fHEPV0C->Fill(xV0C);
365
366   Double_t xTPC[5]; // Match ndims in fH TPC EP
367   xTPC[0]       = mass;
368   xTPC[1]       = pt;
369   xTPC[2]       = fCentrality;
370   xTPC[3]       = dphiTPC;
371   xTPC[4]       = cos2phiTPC;
372   fHEPTPC->Fill(xTPC);
373
374
375 }
376 //_________________________________________________________________________________________________
377 void AliAnalysisTaskPi0V2::GetMom(TLorentzVector& p, const AliESDCaloCluster *c, Double_t *vertex)
378 {
379   // Calculate momentum.
380   Float_t posMom[3];
381   c->GetPosition(posMom);
382   TVector3 clsPos2(posMom);
383
384   Double_t e   = c->E();
385   Double_t r   = clsPos2.Perp();
386   Double_t eta = clsPos2.Eta();
387   Double_t phi = clsPos2.Phi();
388
389   TVector3 pos;
390   pos.SetPtEtaPhi(r,eta,phi);
391
392   if (vertex) { //calculate direction relative to vertex
393     pos -= vertex;
394   }
395
396   Double_t rad = pos.Mag();
397   p.SetPxPyPzE(e*pos.x()/rad, e*pos.y()/rad, e*pos.z()/rad, e);
398
399 }
400 //________________________________________________________________________
401 void AliAnalysisTaskPi0V2::UserCreateOutputObjects()
402 {
403     // Create histograms
404     // Called once (on the worker node)
405         
406     fOutput = new TList();
407     fOutput->SetOwner();  // IMPORTANT!
408
409     hEvtCount = new TH1F("hEvtCount", " Event Plane", 10, 0.5, 10.5);
410     hEvtCount->GetXaxis()->SetBinLabel(1,"SemiMB");
411     hEvtCount->GetXaxis()->SetBinLabel(2,"vert");
412     hEvtCount->GetXaxis()->SetBinLabel(3,"cent");
413     hEvtCount->GetXaxis()->SetBinLabel(4,"EPtask");
414     hEvtCount->GetXaxis()->SetBinLabel(5,"EPvalue");
415     hEvtCount->GetXaxis()->SetBinLabel(6,"Pass");
416     fOutput->Add(hEvtCount);
417     
418     hEPTPC   = new TH2F("hEPTPC",   "EPTPC     vs cent", 100, 0., 100., 100, 0., TMath::Pi());
419     hresoTPC = new TH2F("hresoTPC", "TPc reso  vs cent", 100, 0., 100., 100, 0., 1.);
420     hEPV0    = new TH2F("hEPV0",    "EPV0      vs cent", 100, 0., 100., 100, 0., TMath::Pi());
421     hEPV0A   = new TH2F("hEPV0A",   "EPV0A     vs cent", 100, 0., 100., 100, 0., TMath::Pi());
422     hEPV0C   = new TH2F("hEPV0C",   "EPV0C     vs cent", 100, 0., 100., 100, 0., TMath::Pi());
423     hEPV0Ar  = new TH2F("hEPV0Ar",  "EPV0Ar    vs cent", 100, 0., 100., 100, 0., TMath::Pi());
424     hEPV0Cr  = new TH2F("hEPV0Cr",  "EPV0Cr    vs cent", 100, 0., 100., 100, 0., TMath::Pi());
425     hEPV0r   = new TH2F("hEPV0r",   "EPV0r     vs cent", 100, 0., 100., 100, 0., TMath::Pi());
426     hEPV0AR4 = new TH2F("hEPV0AR4", "EPV0AR4   vs cent", 100, 0., 100., 100, 0., TMath::Pi());
427     hEPV0AR7 = new TH2F("hEPV0AR7", "EPV0AR7   vs cent", 100, 0., 100., 100, 0., TMath::Pi());
428     hEPV0CR0 = new TH2F("hEPV0CR0", "EPV0CR0   vs cent", 100, 0., 100., 100, 0., TMath::Pi());
429     hEPV0CR3 = new TH2F("hEPV0CR3", "EPV0CR3   vs cent", 100, 0., 100., 100, 0., TMath::Pi());
430     fOutput->Add(hEPTPC);
431     fOutput->Add(hresoTPC);
432     fOutput->Add(hEPV0);
433     fOutput->Add(hEPV0A);
434     fOutput->Add(hEPV0C);
435     fOutput->Add(hEPV0Ar);
436     fOutput->Add(hEPV0Cr);
437     fOutput->Add(hEPV0r);
438     fOutput->Add(hEPV0AR4);
439     fOutput->Add(hEPV0AR7);
440     fOutput->Add(hEPV0CR0);
441     fOutput->Add(hEPV0CR3);
442
443     hdifV0A_V0CR0    = new TH2F("hdifV0A_V0CR0",    "EP A-R0 ",  100, 0., 100., 100, -1., 1.);    
444     hdifV0A_V0CR3    = new TH2F("hdifV0A_V0CR3",    "EP A-R3 ",  100, 0., 100., 100, -1., 1.);    
445     hdifV0ACR0_V0CR3 = new TH2F("hdifV0ACR0_V0CR3", "EP R0-R3 ", 100, 0., 100., 100, -1., 1.);    
446     hdifV0C_V0AR4    = new TH2F("hdifV0C_V0AR4",    "EP C-R4 ",  100, 0., 100., 100, -1., 1.);    
447     hdifV0C_V0AR7    = new TH2F("hdifV0C_V0AR7",    "EP C-R7 ",  100, 0., 100., 100, -1., 1.);    
448     hdifV0AR4_V0AR7  = new TH2F("hdifV0AR4_V0AR7",  "EP R4-R7 ", 100, 0., 100., 100, -1., 1.);    
449     fOutput->Add(hdifV0A_V0CR0);
450     fOutput->Add(hdifV0A_V0CR3);
451     fOutput->Add(hdifV0ACR0_V0CR3);
452     fOutput->Add(hdifV0C_V0AR4);
453     fOutput->Add(hdifV0C_V0AR7);
454     fOutput->Add(hdifV0AR4_V0AR7);
455
456     hdifV0A_V0C = new TH2F("hdifV0A_V0C", "EP A-C  ", 100, 0., 100., 100, -1., 1.);
457     hdifV0A_TPC = new TH2F("hdifV0A_TPC", "EP A-TPC", 100, 0., 100., 100, -1., 1.);
458     hdifV0C_TPC = new TH2F("hdifV0C_TPC", "EP C-TPC", 100, 0., 100., 100, -1., 1.);
459     hdifV0C_V0A = new TH2F("hdifV0C_V0A", "EP C-A  ", 100, 0., 100., 100, -1., 1.);
460     fOutput->Add(hdifV0A_V0C);
461     fOutput->Add(hdifV0A_TPC);
462     fOutput->Add(hdifV0C_TPC);
463     fOutput->Add(hdifV0C_V0A);
464
465
466
467     hdifEMC_EP = new TH3F("hdifEMC_EP", "dif phi in EMC with EP",  100, 0., 100., 100, 0., TMath::Pi(), 15, 0., 15.);
468     hdifful_EP = new TH3F("hdifful_EP", "dif phi in full with EP", 100, 0., 100., 100, 0., TMath::Pi(), 15, 0., 15.);
469     hdifout_EP = new TH3F("hdifout_EP", "dif phi NOT in EMC with EP", 100, 0., 100., 100, 0., TMath::Pi(), 15, 0., 15.);
470     fOutput->Add(hdifEMC_EP);
471     fOutput->Add(hdifful_EP);
472     fOutput->Add(hdifout_EP);
473
474     hAllcentV0  = new TH1F("hAllcentV0",  "All cent EP V0",  100, 0., TMath::Pi());
475     hAllcentV0r = new TH1F("hAllcentV0r", "All cent EP V0r", 100, 0., TMath::Pi());
476     hAllcentV0A = new TH1F("hAllcentV0A", "All cent EP V0A", 100, 0., TMath::Pi());
477     hAllcentV0C = new TH1F("hAllcentV0C", "All cent EP V0C", 100, 0., TMath::Pi());
478     hAllcentTPC = new TH1F("hAllcentTPC", "All cent EP TPC", 100, 0., TMath::Pi());
479     fOutput->Add(hAllcentV0);
480     fOutput->Add(hAllcentV0r);
481     fOutput->Add(hAllcentV0A);
482     fOutput->Add(hAllcentV0C);
483     fOutput->Add(hAllcentTPC);
484
485     const Int_t ndims = 5;
486     Int_t nMgg=500, nPt=40, nCent=20, nDeltaPhi=315,  ncos2phi=500;
487     Int_t bins[ndims] = {nMgg, nPt, nCent, nDeltaPhi, ncos2phi};
488     Double_t xmin[ndims] = { 0,   0.,  0,   0.,     -1.};
489     Double_t xmax[ndims] = { 0.5, 20., 100, 3.15,   1.};
490     fHEPV0r  = new THnSparseF("fHEPV0r",  "Flow histogram EPV0",  ndims, bins, xmin, xmax);
491     fHEPV0A = new THnSparseF("fHEPV0A",   "Flow histogram EPV0A", ndims, bins, xmin, xmax);
492     fHEPV0C = new THnSparseF("fHEPV0C",   "Flow histogram EPV0C", ndims, bins, xmin, xmax);
493     fHEPTPC = new THnSparseF("fHEPTPC",   "Flow histogram EPTPC", ndims, bins, xmin, xmax);
494     fOutput->Add(fHEPV0r);
495     fOutput->Add(fHEPV0A);
496     fOutput->Add(fHEPV0C);
497     fOutput->Add(fHEPTPC);
498
499     
500
501     PostData(1, fOutput); // Post data for ALL output slots >0 here, to get at least an empty histogram
502 }
503
504 //________________________________________________________________________
505 void AliAnalysisTaskPi0V2::UserExec(Option_t *) 
506 {
507     // Main loop
508     // Called for each event
509         
510     // Create pointer to reconstructed event
511    AliVEvent *event = InputEvent();
512    if (!event) { Printf("ERROR: Could not retrieve event"); return; }
513
514   Bool_t isSelected =0;      
515   isSelected = (((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected() & (AliVEvent::kMB | AliVEvent::kSemiCentral));
516     if(!isSelected )
517         return; 
518
519     // create pointer to event
520     fESD = dynamic_cast<AliESDEvent*>(event);
521     if (!fESD) {
522         AliError("Cannot get the ESD event");
523         return;
524     }  
525
526     hEvtCount->Fill(1);
527     
528     const AliESDVertex* fvertex = fESD->GetPrimaryVertex();
529     if(TMath::Abs(fvertex->GetZ())>10.)
530       return;
531     Double_t vertex[3] = {fvertex->GetX(), fvertex->GetY(), fvertex->GetZ()};
532
533     hEvtCount->Fill(2);
534
535     if(fESD->GetCentrality()) {
536       fCentrality = 
537         fESD->GetCentrality()->GetCentralityPercentile("V0M");
538     } else{
539            return;
540     }
541
542     hEvtCount->Fill(3);
543     AliEventplane *ep = fESD->GetEventplane();
544       if (ep) {
545       if (ep->GetQVector())
546         fEPTPC    = ep->GetQVector()->Phi()/2. ;
547       else
548         fEPTPC = -999.;
549       if (ep->GetQsub1()&&ep->GetQsub2())
550         fEPTPCreso  = TMath::Cos(2.*(ep->GetQsub1()->Phi()/2.-ep->GetQsub2()->Phi()/2.));
551       else
552         fEPTPCreso = -1;
553
554       fEPV0    = ep->GetEventplane("V0",  fESD);
555       fEPV0A   = ep->GetEventplane("V0A", fESD);
556       fEPV0C   = ep->GetEventplane("V0C", fESD);
557       Double_t qx=0, qy=0;
558       Double_t qxr=0, qyr=0;
559       fEPV0Ar  = ep->CalculateVZEROEventPlane(fESD, 4, 5, 2, qxr, qyr);
560       fEPV0Cr  = ep->CalculateVZEROEventPlane(fESD, 2, 3, 2, qx,  qy);
561       qxr += qx;
562       qyr += qy;
563       fEPV0r   = TMath::ATan2(qyr,qxr)/2.;
564       fEPV0AR4 = ep->CalculateVZEROEventPlane(fESD, 4, 2, qx, qy);
565       fEPV0AR5 = ep->CalculateVZEROEventPlane(fESD, 5, 2, qx, qy);
566       fEPV0AR6 = ep->CalculateVZEROEventPlane(fESD, 6, 2, qx, qy);
567       fEPV0AR7 = ep->CalculateVZEROEventPlane(fESD, 7, 2, qx, qy);
568       fEPV0CR0 = ep->CalculateVZEROEventPlane(fESD, 0, 2, qx, qy);
569       fEPV0CR1 = ep->CalculateVZEROEventPlane(fESD, 1, 2, qx, qy);
570       fEPV0CR2 = ep->CalculateVZEROEventPlane(fESD, 2, 2, qx, qy);
571       fEPV0CR3 = ep->CalculateVZEROEventPlane(fESD, 3, 2, qx, qy);
572
573     }
574 //cout<<" fEPV0:"<<fEPV0<<" fEPV0A:"<<fEPV0A<<" fEPV0C:"<<fEPV0C<<" fEPV0Ar:"<<fEPV0Ar<<" fEPV0Cr:"<<fEPV0Cr<<" fEPV0r:"<<fEPV0AR4<<" fEPV0AR7:"<<fEPV0AR7<<" fEPV0CR0:"<<fEPV0CR0<<" fEPV0CR3:"<<fEPV0CR3<<"--------------------------------------------"<<endl;
575     
576 //cout<<" EPTPC: "<<fEPTPC<<" resoTPC: "<<fEPTPCreso<<"---------------"<<endl;
577
578     hEvtCount->Fill(4);
579
580     if(fcheckEP2sub){
581       if(fEPV0r<-2. || fEPV0Ar<-2. || fEPV0Cr<-2.) return; 
582     }
583     if(!fcheckEP2sub){
584       if(fEPV0A<-2. || fEPV0C<-2. || fEPV0AR4<-2. || fEPV0AR7<-2. || fEPV0CR0<-2. || fEPV0CR3<-2. || fEPTPC<-2.) return;
585     }
586
587     hEvtCount->Fill(5);
588
589     fEPV0   = TVector2::Phi_0_2pi(fEPV0);    if(fEPV0>TMath::Pi())   fEPV0  = fEPV0  - TMath::Pi();
590     fEPV0r  = TVector2::Phi_0_2pi(fEPV0r);   if(fEPV0r>TMath::Pi())  fEPV0r = fEPV0r - TMath::Pi();
591     fEPV0A  = TVector2::Phi_0_2pi(fEPV0A);   if(fEPV0A>TMath::Pi())  fEPV0A = fEPV0A - TMath::Pi();
592     fEPV0C  = TVector2::Phi_0_2pi(fEPV0C);   if(fEPV0C>TMath::Pi())  fEPV0C = fEPV0C - TMath::Pi();
593     fEPV0Ar = TVector2::Phi_0_2pi(fEPV0Ar);  if(fEPV0Ar>TMath::Pi()) fEPV0Ar = fEPV0Ar - TMath::Pi();
594     fEPV0Cr = TVector2::Phi_0_2pi(fEPV0Cr);  if(fEPV0Cr>TMath::Pi()) fEPV0Cr = fEPV0Cr - TMath::Pi();
595     fEPV0AR4   = TVector2::Phi_0_2pi(fEPV0AR4);    if(fEPV0AR4>TMath::Pi())   fEPV0AR4  = fEPV0AR4 - TMath::Pi();
596     fEPV0AR7   = TVector2::Phi_0_2pi(fEPV0AR7);    if(fEPV0AR7>TMath::Pi())   fEPV0AR7  = fEPV0AR7 - TMath::Pi();
597     fEPV0CR0   = TVector2::Phi_0_2pi(fEPV0CR0);    if(fEPV0CR0>TMath::Pi())   fEPV0CR0  = fEPV0CR0 - TMath::Pi();
598     fEPV0CR3   = TVector2::Phi_0_2pi(fEPV0CR3);    if(fEPV0CR3>TMath::Pi())   fEPV0CR3  = fEPV0CR3 - TMath::Pi();
599
600 cout<<" EPTPC: "<<fEPTPC<<" reso: "<<fEPTPCreso<<" -------------------"<<endl;
601 cout<<" cent: "<<fCentrality<<" fEPV0:"<<fEPV0<<" fEPV0A:"<<fEPV0A<<" fEPV0C:"<<fEPV0C<<" fEPV0Ar:"<<fEPV0Ar<<" fEPV0Cr:"<<fEPV0Cr<<" fEPV0r:"<<fEPV0AR4<<" fEPV0AR7:"<<fEPV0AR7<<" fEPV0CR0:"<<fEPV0CR0<<" fEPV0CR3:"<<fEPV0CR3<<"--------------------------------------------"<<endl;
602
603    hEPTPC->Fill(fCentrality,  fEPTPC); 
604    if(fEPTPCreso!=-1) hresoTPC->Fill(fCentrality, fEPTPCreso);
605    hEPV0->Fill(fCentrality,   fEPV0);
606    hEPV0A->Fill(fCentrality,  fEPV0A);
607    hEPV0C->Fill(fCentrality,  fEPV0C);
608    hEPV0Ar->Fill(fCentrality, fEPV0Ar);
609    hEPV0Cr->Fill(fCentrality, fEPV0Cr);
610    hEPV0r->Fill(fCentrality,  fEPV0r);
611    hEPV0AR4->Fill(fCentrality, fEPV0AR4);
612    hEPV0AR7->Fill(fCentrality, fEPV0AR7);
613    hEPV0CR0->Fill(fCentrality, fEPV0CR0);
614    hEPV0CR3->Fill(fCentrality, fEPV0CR3);
615
616    hAllcentV0->Fill(fEPV0);
617    hAllcentV0r->Fill(fEPV0r);
618    hAllcentV0A->Fill(fEPV0A);
619    hAllcentV0C->Fill(fEPV0C);  
620    hAllcentTPC->Fill(fEPTPC);
621
622    hdifV0A_V0CR0->Fill(fCentrality, TMath::Cos(2.*(fEPV0A - fEPV0CR0)));
623    hdifV0A_V0CR3->Fill(fCentrality, TMath::Cos(2.*(fEPV0A - fEPV0CR3)));
624    hdifV0ACR0_V0CR3->Fill(fCentrality, TMath::Cos(2*(fEPV0CR0 - fEPV0CR3)));
625    hdifV0C_V0AR4->Fill(fCentrality, TMath::Cos(2*(fEPV0C - fEPV0AR4)));
626    hdifV0C_V0AR7->Fill(fCentrality, TMath::Cos(2*(fEPV0C - fEPV0AR7)));
627    hdifV0AR4_V0AR7->Fill(fCentrality, TMath::Cos(2*(fEPV0AR4 - fEPV0AR7)));
628         
629    hdifV0A_V0C->Fill(fCentrality, TMath::Cos(2*(fEPV0A - fEPV0C)));
630    hdifV0A_TPC->Fill(fCentrality, TMath::Cos(2*(fEPV0A - fEPTPC)));
631    hdifV0C_TPC->Fill(fCentrality, TMath::Cos(2*(fEPV0C - fEPTPC)));
632    hdifV0C_V0A->Fill(fCentrality, TMath::Cos(2*(fEPV0C - fEPV0A)));
633     // Cluster loop for reconstructed event
634    
635
636     Int_t nCluster =  fESD->GetNumberOfCaloClusters(); 
637     for(Int_t i=0; i<nCluster; ++i){
638       AliESDCaloCluster *c1 = fESD->GetCaloCluster(i);
639       if(!c1->IsEMCAL()) continue;
640       if(!IsGoodCluster(c1)) continue;
641       for(Int_t j=i+1; j<nCluster; ++j){
642         AliESDCaloCluster *c2 = fESD->GetCaloCluster(j);
643         if(!c2->IsEMCAL()) continue;
644         if(!IsGoodCluster(c2)) continue;
645         TLorentzVector p1;
646         GetMom(p1, c1, vertex);
647         TLorentzVector p2;
648         GetMom(p2, c2, vertex);
649         FillPion(p1, p2, fEPV0r, fEPV0A, fEPV0C, fEPTPC);
650       } 
651     }
652
653     Int_t nTrack = fESD->GetNumberOfTracks();
654     for(Int_t i=0; i<nTrack; ++i){
655         AliESDtrack* esdtrack = fESD->GetTrack(i); // pointer to reconstructed to track          
656         if(!esdtrack) {
657             AliError(Form("ERROR: Could not retrieve esdtrack %d",i));
658             continue;
659         }
660         Double_t tPhi = esdtrack->Phi();
661         Double_t tPt  = esdtrack->Pt();
662
663         Double_t difTrack = TVector2::Phi_0_2pi(tPhi-fEPV0);  if(difTrack >TMath::Pi()) difTrack -= TMath::Pi();
664         if(esdtrack->IsEMCAL()){        
665           hdifEMC_EP->Fill(fCentrality, difTrack, tPt);
666         }else{
667           hdifout_EP->Fill(fCentrality, difTrack, tPt);
668         }
669         hdifful_EP->Fill(fCentrality,   difTrack, tPt);
670     }
671     hEvtCount->Fill(6);
672
673     // NEW HISTO should be filled before this point, as PostData puts the
674     // information for this iteration of the UserExec in the container
675     PostData(1, fOutput);
676 }
677
678
679 //________________________________________________________________________
680 void AliAnalysisTaskPi0V2::Terminate(Option_t *) 
681 {
682     // Draw result to screen, or perform fitting, normalizations
683     // Called once at the end of the query
684 //    fOutput = dynamic_cast<TList*> (GetOutputData(1));
685  //   if(!fOutput) { Printf("ERROR: could not retrieve TList fOutput"); return; }
686         
687     // Get the physics selection histograms with the selection statistics
688     //AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
689     //AliESDInputHandler *inputH = dynamic_cast<AliESDInputHandler*>(mgr->GetInputEventHandler());
690     //TH2F *histStat = (TH2F*)inputH->GetStatistics();
691    
692    
693     // NEW HISTO should be retrieved from the TList container in the above way,
694     // so it is available to draw on a canvas such as below
695
696 }