updated
[u/mrichter/AliRoot.git] / PWGHF / hfe / AliAnalysisTaskElecHadronCorrel.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
17 ////////////////////////////////////////////////////////////////////////
18 //                                                                    //
19 //  Task for Heavy Flavour Electron-Hadron DeltaPhi Correlation       //
20 //  Non-Photonic Electron identified with Invariant mass              //
21 //  analysis methos in function  SelectPhotonicElectron               //
22 //  DeltaPhi calculated in function  ElectronHadCorrel                // 
23 //                                                                    //
24 //  Author: Deepa Thomas (Utrecht University)                         //
25 //                                                                    //
26 ////////////////////////////////////////////////////////////////////////
27
28 #include "TChain.h"
29 #include "TTree.h"
30 #include "TH2F.h"
31 #include "TMath.h"
32 #include "TCanvas.h"
33 #include "THnSparse.h"
34 #include "TLorentzVector.h"
35 #include "TString.h"
36 #include "TFile.h"
37
38 #include "AliAnalysisTask.h"
39 #include "AliAnalysisManager.h"
40
41 #include "AliESDEvent.h"
42 #include "AliESDHandler.h"
43 #include "AliAODEvent.h"
44 #include "AliAODHandler.h"
45
46 #include "AliAnalysisTaskElecHadronCorrel.h"
47 #include "TGeoGlobalMagField.h"
48 #include "AliLog.h"
49 #include "AliAnalysisTaskSE.h"
50 #include "TRefArray.h"
51 #include "TVector.h"
52
53 #include "AliESDInputHandler.h"
54 #include "AliAODInputHandler.h"
55 #include "AliESDpid.h"
56 #include "AliAODPid.h"
57 #include "AliESDtrackCuts.h"
58 #include "AliPhysicsSelection.h"
59 #include "AliCentralitySelectionTask.h"
60 #include "AliESDCaloCluster.h"
61 #include "AliAODCaloCluster.h"
62 #include "AliESDCaloTrigger.h"
63 #include "AliEMCALRecoUtils.h"
64 #include "AliEMCALGeometry.h"
65 #include "AliGeomManager.h"
66 #include "stdio.h"
67 #include "TGeoManager.h"
68 #include "iostream"
69 #include "fstream"
70
71 //#include "AliEventPoolManager.h"
72
73 #include "AliCentrality.h"
74 #include "AliMagF.h"
75
76 #include "AliKFParticle.h"
77 #include "AliKFVertex.h"
78
79 #include "AliPID.h"
80 #include "AliPIDResponse.h"
81 #include "AliHFEcontainer.h"
82 #include "AliHFEcuts.h"
83 #include "AliHFEpid.h"
84 #include "AliHFEpidBase.h"
85 #include "AliHFEpidQAmanager.h"
86 #include "AliHFEtools.h"
87 #include "AliCFContainer.h"
88 #include "AliCFManager.h"
89 #include "AliVEvent.h"
90 #include "AliStack.h"
91 #include "AliMCEvent.h"
92 #include "TProfile.h"
93 #include "AliESDVZERO.h"
94 #include "AliAODVZERO.h"
95 #include "TVector3.h"
96 #include "TRandom2.h"
97
98 ClassImp(AliAnalysisTaskElecHadronCorrel)
99 //ClassImp(AliehDPhiBasicParticle)  
100 //________________________________________________________________________
101   AliAnalysisTaskElecHadronCorrel::AliAnalysisTaskElecHadronCorrel(const char *name) 
102   : AliAnalysisTaskSE(name)
103   ,fVevent(0)  
104   ,fESD(0)
105   ,fAOD(0)
106   ,fGeom(0)
107   ,fOutputList(0)
108   ,fTrackCuts1(new AliESDtrackCuts)
109   ,fTrackCuts2(new AliESDtrackCuts)
110   ,fCuts(0)
111   ,fIdentifiedAsOutInz(kFALSE)
112   ,fPassTheEventCut(kFALSE)
113   ,fRejectKinkMother(kFALSE)
114   ,fVz(0.0)
115   ,fCFM(0)      
116   ,fPID(0)
117   ,fPIDqa(0)           
118   ,fInvmassCut(0.01)    
119   ,fCentrality(0)
120   ,fCentralityMin(0)
121   ,fCentralityMax(0)
122   ,fkCentralityMethod(0)  
123 //  ,fPoolMgr(0x0)  
124   ,fNoEvents(0)
125 //  ,fTrkpt(0)
126   ,fTrkEovPBef(0)        
127   ,fTrkEovPBefHad(0)     
128  // ,fdEdxBef(0)         
129   ,fSemiIncElecDphi(0)  
130   ,fSemiIncElecDphi1(0)         
131   ,fSemiIncElecDphi2(0)         
132   ,fSemiIncElecDphi3(0)         
133   ,fSemiIncElecDphi4(0)         
134   ,fPhotElecDphi(0)     
135   ,fPhotElecDphi1(0)    
136   ,fPhotElecDphi2(0)    
137   ,fPhotElecDphi3(0)    
138   ,fPhotElecDphi4(0)    
139   ,fInclusiveElecDphi(0)        
140   ,fInclusiveElecDphi1(0)       
141   ,fInclusiveElecDphi2(0)       
142   ,fInclusiveElecDphi3(0)       
143   ,fInclusiveElecDphi4(0)       
144   ,fDphiULSMassLow(0)   
145   ,fDphiULSMassLow1(0)  
146   ,fDphiULSMassLow2(0)  
147   ,fDphiULSMassLow3(0)  
148   ,fDphiULSMassLow4(0)  
149   ,fDphiLSMassLow(0)
150   ,fDphiLSMassLow1(0)
151   ,fDphiLSMassLow2(0)
152   ,fDphiLSMassLow3(0)
153   ,fDphiLSMassLow4(0)
154   ,fDphiULSMassLowNoPartner(0)   
155   ,fDphiULSMassLowNoPartner1(0)   
156   ,fDphiULSMassLowNoPartner2(0)   
157   ,fDphiULSMassLowNoPartner3(0)   
158   ,fDphiULSMassLowNoPartner4(0)   
159   ,fDphiLSMassLowNoPartner(0)
160   ,fDphiLSMassLowNoPartner1(0)
161   ,fDphiLSMassLowNoPartner2(0)
162   ,fDphiLSMassLowNoPartner3(0)
163   ,fDphiLSMassLowNoPartner4(0)
164   ,fPhotoElecPt(0)
165   ,fSemiInclElecPt(0)
166   ,fInclusiveElecPt(0)
167   ,fULSElecPt(0)
168   ,fLSElecPt(0)  
169   ,fTrackPtBefTrkCuts(0)         
170   ,fTrackPtAftTrkCuts(0)
171   ,fTPCnsigma(0)
172   ,fNCellv1(0)
173   ,fClsEv1(0)
174   ,fNClusv1(0)
175   ,fInvmassLS1(0)       
176   ,fInvmassLS2(0)       
177   ,fInvmassLS3(0)       
178   ,fInvmassLS4(0)       
179   ,fInvmassLS5(0)       
180   ,fInvmassULS1(0)
181   ,fInvmassULS2(0)
182   ,fInvmassULS3(0)
183   ,fInvmassULS4(0)
184   ,fInvmassULS5(0)
185   ,fcentrality(0)     
186   ,fElecPhi(0)  
187   ,fElecPhiTPChalf(0)
188   ,fElecPhiPt(0)  
189 //  ,fElecPhiTPC(0)  
190 //  ,fElecPhiTPCEovP(0)  
191   ,fHadronPhi(0)  
192   ,fHadronPhiTPChalf(0)  
193   ,fHadronPhiPt(0)  
194 /*  ,fTrackHFEcuts(0)
195   ,fTrakPhiSPD1(0)
196   ,fTrakPhiSPD2(0)
197   ,fTrakPhiSPDOr(0)
198   ,fTrakPhiSPDAnd(0)
199   ,fTrackHFEcutsITS(0)  
200 */
201 /*  ,fNoMixedEvents(0)
202   ,fMixStat(0)       
203   ,fMixStat1(0)        
204   ,fMixedIncElecDphi(0)  
205   ,fMixedIncElecDphi1(0)  
206   ,fMixedIncElecDphi2(0)  
207   ,fMixedPhotElecDphi(0)
208   ,fMixedPhotElecDphi1(0)
209   ,fMixedPhotElecDphi2(0)
210   ,fMixedSemiIncElecDphi(0)  
211   ,fMixedSemiIncElecDphi1(0)  
212   ,fMixedSemiIncElecDphi2(0)  
213   ,fMixedDphiULSMassLow(0)  
214   ,fMixedDphiULSMassLow1(0)  
215   ,fMixedDphiULSMassLow2(0)  
216   ,fMixedDphiLSMassLow(0)  
217   ,fMixedDphiLSMassLow1(0)  
218   ,fMixedDphiLSMassLow2(0)  
219 */   
220   ,fHadronPt(0)  
221   ,fCentralityPass(0)
222   ,fCentralityNoPass(0)
223 //  ,fSparseElectron(0)  
224 //  ,fvalueElectron(0)   
225 {
226   //Named constructor
227
228   fPID = new AliHFEpid("hfePid");
229 //  fvalueElectron = new Double_t[8];
230
231   // Define input and output slots here
232   // Input slot #0 works with a TChain
233   DefineInput(0, TChain::Class());
234   // Output slot #0 id reserved by the base class for AOD
235   // Output slot #1 writes into a TH1 container
236   // DefineOutput(1, TH1I::Class());
237   DefineOutput(1, TList::Class());
238   //  DefineOutput(3, TTree::Class());
239 }
240
241 //________________________________________________________________________
242 AliAnalysisTaskElecHadronCorrel::AliAnalysisTaskElecHadronCorrel() 
243   : AliAnalysisTaskSE("DefaultAnalysis_AliAnalysisElecHadCorrel")
244   ,fVevent(0)  
245   ,fESD(0)
246   ,fAOD(0)
247   ,fGeom(0)  
248   ,fOutputList(0)
249   ,fTrackCuts1(new AliESDtrackCuts)
250   ,fTrackCuts2(new AliESDtrackCuts)
251   ,fCuts(0)
252   ,fIdentifiedAsOutInz(kFALSE)
253   ,fPassTheEventCut(kFALSE)
254   ,fRejectKinkMother(kFALSE)
255   ,fVz(0.0)
256   ,fCFM(0)      
257   ,fPID(0)       
258   ,fPIDqa(0)           
259   ,fInvmassCut(0.01)    
260   ,fCentrality(0)
261   ,fCentralityMin(0)
262   ,fCentralityMax(0)
263   ,fkCentralityMethod(0)  
264 //  ,fPoolMgr(0x0)    
265   ,fNoEvents(0)
266 //  ,fTrkpt(0)
267   ,fTrkEovPBef(0)        
268   ,fTrkEovPBefHad(0)     
269 //  ,fdEdxBef(0)         
270   ,fSemiIncElecDphi(0)  
271   ,fSemiIncElecDphi1(0)         
272   ,fSemiIncElecDphi2(0)         
273   ,fSemiIncElecDphi3(0)         
274   ,fSemiIncElecDphi4(0)         
275   ,fPhotElecDphi(0)     
276   ,fPhotElecDphi1(0)    
277   ,fPhotElecDphi2(0)    
278   ,fPhotElecDphi3(0)    
279   ,fPhotElecDphi4(0)    
280   ,fInclusiveElecDphi(0)        
281   ,fInclusiveElecDphi1(0)       
282   ,fInclusiveElecDphi2(0)       
283   ,fInclusiveElecDphi3(0)       
284   ,fInclusiveElecDphi4(0)       
285   ,fDphiULSMassLow(0)   
286   ,fDphiULSMassLow1(0)  
287   ,fDphiULSMassLow2(0)  
288   ,fDphiULSMassLow3(0)  
289   ,fDphiULSMassLow4(0)  
290   ,fDphiLSMassLow(0)
291   ,fDphiLSMassLow1(0)
292   ,fDphiLSMassLow2(0)
293   ,fDphiLSMassLow3(0)
294   ,fDphiLSMassLow4(0)
295   ,fDphiULSMassLowNoPartner(0)   
296   ,fDphiULSMassLowNoPartner1(0)   
297   ,fDphiULSMassLowNoPartner2(0)   
298   ,fDphiULSMassLowNoPartner3(0)   
299   ,fDphiULSMassLowNoPartner4(0)   
300   ,fDphiLSMassLowNoPartner(0)
301   ,fDphiLSMassLowNoPartner1(0)
302   ,fDphiLSMassLowNoPartner2(0)
303   ,fDphiLSMassLowNoPartner3(0)
304   ,fDphiLSMassLowNoPartner4(0)
305   ,fPhotoElecPt(0)
306   ,fSemiInclElecPt(0)
307   ,fInclusiveElecPt(0)
308   ,fULSElecPt(0)
309   ,fLSElecPt(0)  
310   ,fTrackPtBefTrkCuts(0)         
311   ,fTrackPtAftTrkCuts(0)                  
312   ,fTPCnsigma(0)        
313   ,fNCellv1(0)  
314   ,fClsEv1(0)
315   ,fNClusv1(0)
316   ,fInvmassLS1(0)   
317   ,fInvmassLS2(0)   
318   ,fInvmassLS3(0)   
319   ,fInvmassLS4(0)   
320   ,fInvmassLS5(0)   
321   ,fInvmassULS1(0)  
322   ,fInvmassULS2(0)  
323   ,fInvmassULS3(0)  
324   ,fInvmassULS4(0)  
325   ,fInvmassULS5(0)  
326   ,fcentrality(0)     
327   ,fElecPhi(0)
328   ,fElecPhiTPChalf(0)  
329   ,fElecPhiPt(0)
330 //  ,fElecPhiTPC(0)
331 //  ,fElecPhiTPCEovP(0)  
332   ,fHadronPhi(0)
333   ,fHadronPhiTPChalf(0)
334   ,fHadronPhiPt(0)
335 /*  ,fTrackHFEcuts(0)
336   ,fTrakPhiSPD1(0)
337   ,fTrakPhiSPD2(0)
338   ,fTrakPhiSPDOr(0)
339   ,fTrakPhiSPDAnd(0)
340   ,fTrackHFEcutsITS(0)  
341 */
342 /*  ,fNoMixedEvents(0)
343   ,fMixStat(0)      
344   ,fMixStat1(0)     
345   ,fMixedIncElecDphi(0)  
346   ,fMixedIncElecDphi1(0)  
347   ,fMixedIncElecDphi2(0)  
348   ,fMixedPhotElecDphi(0)
349   ,fMixedPhotElecDphi1(0)
350   ,fMixedPhotElecDphi2(0)
351   ,fMixedSemiIncElecDphi(0)
352   ,fMixedSemiIncElecDphi1(0)
353   ,fMixedSemiIncElecDphi2(0)
354   ,fMixedDphiULSMassLow(0) 
355   ,fMixedDphiULSMassLow1(0) 
356   ,fMixedDphiULSMassLow2(0) 
357   ,fMixedDphiLSMassLow(0)      
358   ,fMixedDphiLSMassLow1(0)      
359   ,fMixedDphiLSMassLow2(0)      
360 */
361   ,fHadronPt(0)  
362   ,fCentralityPass(0)
363   ,fCentralityNoPass(0)
364     //  ,fSparseElectron(0)  
365     //    ,fvalueElectron(0)  
366 {
367   //Default constructor
368   fPID = new AliHFEpid("hfePid");
369   //  fvalueElectron = new Double_t[8];
370
371   // Constructor
372   // Define input and output slots here
373   // Input slot #0 works with a TChain
374   DefineInput(0, TChain::Class());
375   // Output slot #0 id reserved by the base class for AOD
376   // Output slot #1 writes into a TH1 container
377   // DefineOutput(1, TH1I::Class());
378   DefineOutput(1, TList::Class());
379   //DefineOutput(3, TTree::Class());
380 }
381 //_________________________________________
382
383 AliAnalysisTaskElecHadronCorrel::~AliAnalysisTaskElecHadronCorrel()
384 {
385   //Destructor 
386
387   delete fOutputList;
388   delete fGeom;
389   delete fPID;
390   delete fCFM;
391   delete fPIDqa;
392   delete fTrackCuts1;
393   delete fTrackCuts2;
394   //   delete fSparseElectron;
395   //   delete []fvalueElectron;
396 }
397 //_________________________________________
398
399 void AliAnalysisTaskElecHadronCorrel::UserExec(Option_t*)
400 {
401   //Main loop
402   //Called for each event
403
404   // create pointer to event
405   fAOD = dynamic_cast<AliAODEvent*>(InputEvent());
406   fESD = dynamic_cast<AliESDEvent*>(InputEvent());
407   
408   if(!(fESD || fAOD)){
409     printf("ERROR: fESD & fAOD not available\n");
410     return;
411   }
412   fVevent = dynamic_cast<AliVEvent*>(InputEvent());
413   if (!fVevent) {
414     printf("ERROR: fVEvent not available\n");
415     return;
416   }
417
418   if(!fCuts){
419     AliError("HFE cuts not available");
420     return;
421   }
422
423   if(!fPID->IsInitialized()){ 
424     // Initialize PID with the given run number
425     AliWarning("PID not initialised, get from Run no");
426  
427     if(IsAODanalysis())fPID->InitializePID(fAOD->GetRunNumber());
428     else fPID->InitializePID(fESD->GetRunNumber());
429   }
430
431   // trigger selection
432   if(!(((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected() & (AliVEvent::kCentral))) return;
433
434   // centrality selection 
435   SetCentralityParameters(0., 10., "V0M");
436   Bool_t pass = kFALSE; 
437   CheckCentrality(fVevent,pass);
438   if(!pass)return;
439
440   Int_t fNOtrks =  fVevent->GetNumberOfTracks();
441   const AliVVertex *pVtx = fVevent->GetPrimaryVertex();
442
443   Double_t pVtxZ = -999;
444   pVtxZ = pVtx->GetZ();
445
446   if(TMath::Abs(pVtxZ)>10) return;
447   fNoEvents->Fill(0);
448
449   if(fNOtrks<2) return;
450
451   AliPIDResponse *pidResponse = fInputHandler->GetPIDResponse();
452   if(!pidResponse){
453     AliDebug(1, "Using default PID Response");
454      pidResponse = AliHFEtools::GetDefaultPID(kFALSE, fInputEvent->IsA() == AliAODEvent::Class()); 
455    }
456
457    fPID->SetPIDResponse(pidResponse);
458
459    fCFM->SetRecEventInfo(fVevent);
460
461    /*
462    //Event mixing
463    AliEventPool* pool = fPoolMgr->GetEventPool(centvalue, pVtxZ); // Get the buffer associated with the current centrality and z-vtx
464    if (!pool)
465      AliFatal(Form("No pool found for centrality = %f, zVtx = %f", centvalue, pVtxZ));     
466 */
467
468    // Look for kink mother for AOD
469    Double_t *listofmotherkink =0;
470    Int_t numberofvertices = 0, numberofmotherkink = 0;
471    if(IsAODanalysis()){
472      numberofvertices = fAOD->GetNumberOfVertices();
473      listofmotherkink = new Double_t[numberofvertices];
474      for(Int_t ivertex=0; ivertex < numberofvertices; ivertex++) {
475        AliAODVertex *aodvertex = fAOD->GetVertex(ivertex);
476        if(!aodvertex) continue;
477        if(aodvertex->GetType()==AliAODVertex::kKink) {
478          AliAODTrack *mother = (AliAODTrack *) aodvertex->GetParent();
479          if(!mother) continue;
480          Int_t idmother = mother->GetID();
481          listofmotherkink[numberofmotherkink] = idmother;
482          numberofmotherkink++;
483        }
484      }
485    }
486
487    // Track loop 
488    for (Int_t iTracks = 0; iTracks < fVevent->GetNumberOfTracks(); iTracks++) {
489      AliVParticle* Vtrack = fVevent->GetTrack(iTracks);
490      if (!Vtrack) {
491        printf("ERROR: Could not receive track %d\n", iTracks);
492        continue;
493      }
494      AliVTrack *track = dynamic_cast<AliVTrack*>(Vtrack);
495      AliESDtrack *etrack = dynamic_cast<AliESDtrack*>(Vtrack);
496      AliAODTrack *atrack = dynamic_cast<AliAODTrack*>(Vtrack);
497      
498      if(IsAODanalysis())
499        if(!atrack->TestFilterMask(AliAODTrack::kTrkGlobalNoDCA)) continue;
500
501      if(track->Pt()<1) continue;
502
503       fTrackPtBefTrkCuts->Fill(track->Pt());            
504
505      // RecKine: ITSTPC cuts  
506      if(!ProcessCutStep(AliHFEcuts::kStepRecKineITSTPC, track)) continue;
507
508      // Reject kink mother
509      if(fRejectKinkMother) { // Quick and dirty fix to reject both kink mothers and daughters
510        if(IsAODanalysis()){
511          Bool_t kinkmotherpass = kTRUE;
512          for(Int_t kinkmother = 0; kinkmother < numberofmotherkink; kinkmother++) {
513            if(track->GetID() == listofmotherkink[kinkmother]) {
514              kinkmotherpass = kFALSE;
515              continue;
516            }
517          }
518          if(!kinkmotherpass) continue;
519        }
520        else{
521          if(etrack->GetKinkIndex(0) != 0) continue;
522        }
523      }
524      // RecPrim
525      //     if(!ProcessCutStep(AliHFEcuts::kStepRecPrim, track)) continue; //gives warning for AOD, so not using
526
527      // HFE cuts: TPC PID cleanup
528      if(!ProcessCutStep(AliHFEcuts::kStepHFEcutsTPC, track)) continue;
529
530      // fTrackHFEcuts->Fill(track->Phi());
531
532      // HFEcuts: ITS layers cuts
533      if(!ProcessCutStep(AliHFEcuts::kStepHFEcutsITS, track)) continue;
534
535      //     fTrackHFEcutsITS->Fill(track->Phi());
536      fTrackPtAftTrkCuts->Fill(track->Pt());             
537
538      Double_t fClsE = -999, p = -999, fEovP=-999, pt = -999, dEdx=-999, fTPCnSigma=0;
539      pt = track->Pt();
540      p = track->P();
541      dEdx = track->GetTPCsignal();
542      fTPCnSigma = fPID->GetPIDResponse() ? fPID->GetPIDResponse()->NumberOfSigmasTPC(track, AliPID::kElectron) : 1000;
543
544      //TPC electron phi
545     // if(fTPCnSigma >= -2 && fTPCnSigma <= 2){
546        //       fElecPhiTPC->Fill(track->Phi());
547     // }
548
549      //eta cut (-0.7,0.7)
550      if(track->Eta() < -0.7 || track->Eta() > 0.7) continue;
551
552      // Track extrapolation to EMCAL
553      Int_t fClsId = track->GetEMCALcluster();
554      if(fClsId <0) continue;
555      AliVCluster *cluster = fVevent->GetCaloCluster(fClsId);
556      if(!cluster->IsEMCAL()) continue;
557      if(TMath::Abs(cluster->GetTrackDx())>0.05 || TMath::Abs(cluster->GetTrackDz())>0.05) continue;    
558      //     fdEdxBef->Fill(p,dEdx);
559      fTPCnsigma->Fill(p,fTPCnSigma);
560
561      //     fTrkpt->Fill(pt);
562      fClsE = cluster->E();
563      fEovP = fClsE/p;
564      /*
565         fvalueElectron[0] = pt;
566         fvalueElectron[1] = p;
567         fvalueElectron[2] = fTPCnSigma;
568         fvalueElectron[3] = dEdx;
569         fvalueElectron[4] = fEovP;
570         fvalueElectron[5] = cluster->GetM20();
571         fvalueElectron[6] = cluster->GetM02();
572         fvalueElectron[7] = cluster->GetDispersion();
573
574         fSparseElectron->Fill(fvalueElectron);
575       */
576      if(fTPCnSigma >= -2 && fTPCnSigma <= 2 && cluster->GetM20()<0.2 && cluster->GetM02()<0.5 && cluster->GetDispersion()<1){
577        fTrkEovPBef->Fill(pt,fEovP);
578      }
579      if(fTPCnSigma < -3.5)fTrkEovPBefHad->Fill(pt,fEovP);
580
581      //Electron id with TPC and E/p
582      if(fTPCnSigma >= -2 && fTPCnSigma <= 2 && fEovP >= 0.8 && fEovP <=1.2) {
583        //   fElecPhiTPCEovP->Fill(track->Phi());
584
585        //Electron id with shower shape  
586        if(cluster->GetM20()<0.2 && cluster->GetM02()< 0.5 && cluster->GetDispersion()<1){
587
588          fElecPhi->Fill(track->Phi());
589          fElecPhiPt->Fill(track->Phi(),track->Pt());
590          if (track->Eta() >0 && track->Eta() <0.7) fElecPhiTPChalf->Fill(track->Phi());
591          
592          HadronInfo(iTracks);
593
594          Bool_t fFlagPhotonicElec = kFALSE;
595          // select photonic electron
596          SelectPhotonicElectron(iTracks,track,fFlagPhotonicElec);
597
598          //Inclusive electron-hadron correlation
599          ElectronHadCorrel(iTracks, track, fInclusiveElecDphi, fInclusiveElecDphi1,fInclusiveElecDphi2,fInclusiveElecDphi3,fInclusiveElecDphi4);
600          fInclusiveElecPt->Fill(pt);
601          //       MixedEvent(track,fMixedIncElecDphi, fMixedIncElecDphi1,fMixedIncElecDphi2);
602
603          // photonic electron
604          if(fFlagPhotonicElec){
605            //Electron hadron correlation
606            ElectronHadCorrel(iTracks, track, fPhotElecDphi,fPhotElecDphi1,fPhotElecDphi2,fPhotElecDphi3,fPhotElecDphi4);
607            fPhotoElecPt->Fill(pt);
608            //       MixedEvent(track,fMixedPhotElecDphi, fMixedPhotElecDphi1,fMixedPhotElecDphi2);
609          }
610
611          // Semi inclusive electron 
612          if(!fFlagPhotonicElec){
613            //Electron hadron correlation
614            ElectronHadCorrel(iTracks, track, fSemiIncElecDphi, fSemiIncElecDphi1,fSemiIncElecDphi2,fSemiIncElecDphi3,fSemiIncElecDphi4);
615            fSemiInclElecPt->Fill(pt);
616    //        MixedEvent(track,fMixedSemiIncElecDphi,fMixedSemiIncElecDphi1,fMixedSemiIncElecDphi2);
617          }
618          
619        }
620      }
621    }
622    
623    //EMC clusters  
624    Int_t clsNo = fVevent->GetNumberOfCaloClusters();
625    fNClusv1->Fill(clsNo); 
626    for(Int_t iclus=0; iclus<clsNo ; iclus++){ 
627      AliVCluster* clus = fVevent->GetCaloCluster(iclus);
628      if(!clus->IsEMCAL()) continue; 
629      fNCellv1->Fill(clus->GetNCells());
630      fClsEv1->Fill(clus->E());  
631    }
632
633 /*
634    TObjArray* tracksClone = CloneAndReduceTrackList();
635    tracksClone->SetOwner();
636    pool->UpdatePool(tracksClone);
637    */
638    delete listofmotherkink;
639    PostData(1, fOutputList);
640 }
641 //_________________________________________
642 void AliAnalysisTaskElecHadronCorrel::UserCreateOutputObjects()
643 {
644   //Create histograms
645
646   AliDebug(3, "Creating Output Objects");
647   // Automatic determination of the analysis mode
648   AliVEventHandler *inputHandler = dynamic_cast<AliVEventHandler *>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
649   if(!TString(inputHandler->IsA()->GetName()).CompareTo("AliAODInputHandler")){
650     SetAODAnalysis();
651   } else {
652     SetESDAnalysis();
653   }
654   printf("Analysis Mode: %s Analysis\n", IsAODanalysis() ? "AOD" : "ESD");
655
656   //--------Initialize PID
657   fPID->SetHasMCData(kFALSE);
658   if(!fPID->GetNumberOfPIDdetectors()) 
659   {
660     fPID->AddDetector("TPC", 0);
661     fPID->AddDetector("EMCAL", 1);
662   }
663
664   fPID->SortDetectors(); 
665   fPIDqa = new AliHFEpidQAmanager();
666   fPIDqa->Initialize(fPID);
667
668   //--------Initialize correction Framework and Cuts
669   fCFM = new AliCFManager;
670   const Int_t kNcutSteps = AliHFEcuts::kNcutStepsMCTrack + AliHFEcuts::kNcutStepsRecTrack + AliHFEcuts::kNcutStepsDETrack;
671   fCFM->SetNStepParticle(kNcutSteps);
672   for(Int_t istep = 0; istep < kNcutSteps; istep++)
673     fCFM->SetParticleCutsList(istep, NULL);
674
675   if(!fCuts){
676     AliWarning("Cuts not available. Default cuts will be used");
677     fCuts = new AliHFEcuts;
678     fCuts->CreateStandardCuts();
679   }
680
681   if(IsAODanalysis()) fCuts->SetAOD(); 
682   fCuts->Initialize(fCFM);
683   /*
684   //Mixed event initialising
685   Int_t trackDepth = 2000;
686   Int_t poolsize   = 1000;
687
688   Int_t nCentralityBins  = 5;
689   Double_t CentralityBins[] = {0,2,4,6,8,10};
690
691   Int_t nZvtxBins  = 4;
692   Double_t vertexBins[] = {-10,-5,0,5,10};
693
694   fPoolMgr = new AliEventPoolManager(poolsize, trackDepth, nCentralityBins, (Double_t*) CentralityBins, nZvtxBins, (Double_t*) vertexBins);
695 */
696   //---------Output Tlist
697   fOutputList = new TList();
698   fOutputList->SetOwner();
699   fOutputList->Add(fPIDqa->MakeList("PIDQA"));
700
701   fNoEvents = new TH1F("fNoEvents","",1,0,1) ;
702   fOutputList->Add(fNoEvents);
703
704   fcentrality = new TH1F("fcentrality","centrality", 100,0,100);
705   fOutputList->Add(fcentrality);
706
707 //  fTrkpt = new TH1F("fTrkpt","track pt",1000,0,50);
708 //  fOutputList->Add(fTrkpt);
709
710   fTrackPtBefTrkCuts = new TH1F("fTrackPtBefTrkCuts","track pt before track cuts",1000,0,50);
711   fOutputList->Add(fTrackPtBefTrkCuts);
712
713   fTrackPtAftTrkCuts = new TH1F("fTrackPtAftTrkCuts","track pt after track cuts",1000,0,50);
714   fOutputList->Add(fTrackPtAftTrkCuts);
715
716   fTPCnsigma = new TH2F("fTPCnsigma", "TPC - n sigma",1000,0,50,200,-10,10);
717   fOutputList->Add(fTPCnsigma);
718   
719   fTrkEovPBef = new TH2F("fTrkEovPBef","track E/p before HFE pid",1000,0,50,100,0,2);
720   fOutputList->Add(fTrkEovPBef);
721
722   fTrkEovPBefHad = new TH2F("fTrkEovPBefHad","track E/p for TPCnsig < 3.5",1000,0,50,100,0,2);
723   fOutputList->Add(fTrkEovPBefHad);
724
725 //  fdEdxBef = new TH2F("fdEdxBef","track dEdx vs p before HFE pid",1000,0,50,150,0,150);
726 //  fOutputList->Add(fdEdxBef);
727
728   fElecPhi = new TH1F("fElecPhi", "Electron phi",1000,0,6.28);
729   fOutputList->Add(fElecPhi);
730
731   fElecPhiPt = new TH2F("fElecPhiPt", "Electron phi vs pt; Electron phi; pt (GeV/c)",1000,0,6.28,1000,0,100);
732   fOutputList->Add(fElecPhiPt);
733
734   fElecPhiTPChalf = new TH1F("fElecPhiTPChalf", "Electron phi for 0<eta<0.7",1000,0,6.28);                            
735   fOutputList->Add(fElecPhiTPChalf);
736
737 /*  fElecPhiTPC = new TH1F("fElecPhiTPC", "Electron phi after TPC cut",1000,0,6.28);
738   fOutputList->Add(fElecPhiTPC);
739
740   fElecPhiTPCEovP = new TH1F("fElecPhiTPCEovP", "Electron phi after TPC and E/p cut",1000,0,6.28);
741   fOutputList->Add(fElecPhiTPCEovP);
742 */
743   fHadronPhi = new TH1F("fHadronPhi", "Hadron phi",1000,0,6.28);
744   fOutputList->Add(fHadronPhi);
745
746   fHadronPhiTPChalf = new TH1F("fHadronPhiTPChalf", "Hadron phi for 0<eta<0.9",1000,0,6.28);                          
747   fOutputList->Add(fHadronPhiTPChalf);
748
749   fHadronPhiPt = new TH2F("fHadronPhiPt", "Hadron phi vs pt; hadron phi; pt (GeV/c)",1000,0,6.28,1000,0,100);
750   fOutputList->Add(fHadronPhiPt);
751
752 /*
753   fTrackHFEcuts = new TH1F("fTrackHFEcuts","Track phi for HFE cuts",1000,0,6.28);
754   fOutputList->Add(fTrackHFEcuts);
755
756   fTrakPhiSPD1 = new TH1F("fTrakPhiSPD1","Track phi for hit in SPD layer 1",1000,0,6.28);
757   fOutputList->Add(fTrakPhiSPD1);
758
759   fTrakPhiSPD2 = new TH1F("fTrakPhiSPD2","Track phi for hit in SPD layer 2",1000,0,6.28);
760   fOutputList->Add(fTrakPhiSPD2);
761
762   fTrakPhiSPDOr = new TH1F("fTrakPhiSPDOr","Track phi for hit in any SPD layer",1000,0,6.28);
763   fOutputList->Add(fTrakPhiSPDOr);
764
765   fTrakPhiSPDAnd = new TH1F("fTrakPhiSPDAnd","Track phi for hit in both SPD layer",1000,0,6.28);
766   fOutputList->Add(fTrakPhiSPDAnd);
767
768   fTrackHFEcutsITS = new TH1F("fTrackHFEcutsITS","Track phi for HFE cuts + ITS HFE cuts",1000,0,6.28);
769   fOutputList->Add(fTrackHFEcutsITS);
770 */
771   fSemiIncElecDphi = new TH2F("fSemiIncElecDphi", "Semi Inclusive elec-had Dphi correlation",200,0,20,64,-1.57,4.71);
772   fOutputList->Add(fSemiIncElecDphi);
773
774   fSemiIncElecDphi1 = new TH2F("fSemiIncElecDphi1", "Semi Inclusive elec-had Dphi correlation for 1<pt^{asso}<3",200,0,20,64,-1.57,4.71);
775   fOutputList->Add(fSemiIncElecDphi1);
776
777   fSemiIncElecDphi2 = new TH2F("fSemiIncElecDphi2", "Semi Inclusive elec-had Dphi correlation for 3<pt^{asso}<5",200,0,20,64,-1.57,4.71);
778   fOutputList->Add(fSemiIncElecDphi2);
779
780   fSemiIncElecDphi3 = new TH2F("fSemiIncElecDphi3", "Semi Inclusive elec-had Dphi correlation for 5<pt^{asso}<7",200,0,20,64,-1.57,4.71);
781   fOutputList->Add(fSemiIncElecDphi3);
782
783   fSemiIncElecDphi4 = new TH2F("fSemiIncElecDphi4", "Semi Inclusive elec-had Dphi correlation for 7<pt^{asso}<9",200,0,20,64,-1.57,4.71);
784   fOutputList->Add(fSemiIncElecDphi4);
785
786   fPhotElecDphi = new TH2F("fPhotElecDphi", "Photon elec-had Dphi correlation",200,0,20,64,-1.57,4.71);
787   fOutputList->Add(fPhotElecDphi);
788
789   fPhotElecDphi1 = new TH2F("fPhotElecDphi1", "Photon elec-had Dphi correlation for 1<pt^{asso}<3",200,0,20,64,-1.57,4.71);
790   fOutputList->Add(fPhotElecDphi1);
791
792   fPhotElecDphi2 = new TH2F("fPhotElecDphi2", "Photon elec-had Dphi correlation for 3<pt^{asso}<5",200,0,20,64,-1.57,4.71);
793   fOutputList->Add(fPhotElecDphi2);
794
795   fPhotElecDphi3 = new TH2F("fPhotElecDphi3", "Photon elec-had Dphi correlation for 5<pt^{asso}<7",200,0,20,64,-1.57,4.71);
796   fOutputList->Add(fPhotElecDphi3);
797
798   fPhotElecDphi4 = new TH2F("fPhotElecDphi4", "Photon elec-had Dphi correlation for 7<pt^{asso}<9",200,0,20,64,-1.57,4.71);
799   fOutputList->Add(fPhotElecDphi4);
800
801   fInclusiveElecDphi = new TH2F("fInclusiveElecDphi", "Inclusive elec-had Dphi correlation",200,0,20,64,-1.57,4.71);
802   fOutputList->Add(fInclusiveElecDphi);
803
804   fInclusiveElecDphi1 = new TH2F("fInclusiveElecDphi1", "Inclusive elec-had Dphi correlation for 1<pt^{asso}<3",200,0,20,64,-1.57,4.71);
805   fOutputList->Add(fInclusiveElecDphi1);
806
807   fInclusiveElecDphi2 = new TH2F("fInclusiveElecDphi2", "Inclusive elec-had Dphi correlation for 3<pt^{asso}<5",200,0,20,64,-1.57,4.71);
808   fOutputList->Add(fInclusiveElecDphi2);
809
810   fInclusiveElecDphi3 = new TH2F("fInclusiveElecDphi3", "Inclusive elec-had Dphi correlation for 5<pt^{asso}<7",200,0,20,64,-1.57,4.71);
811   fOutputList->Add(fInclusiveElecDphi3);
812
813   fInclusiveElecDphi4 = new TH2F("fInclusiveElecDphi4", "Inclusive elec-had Dphi correlation for 7<pt^{asso}<9",200,0,20,64,-1.57,4.71);
814   fOutputList->Add(fInclusiveElecDphi4);
815
816   fDphiULSMassLow = new TH2F("fDphiULSMassLow", "e-h Dphi ULS, mass<cut",200,0,20,64,-1.57,4.71);
817   fOutputList->Add(fDphiULSMassLow);
818
819   fDphiULSMassLow1 = new TH2F("fDphiULSMassLow1", "e-h Dphi ULS, mass<cut for 1<pt^{asso}<3",200,0,20,64,-1.57,4.71);
820   fOutputList->Add(fDphiULSMassLow1);
821
822   fDphiULSMassLow2 = new TH2F("fDphiULSMassLow2", "e-h Dphi ULS, mass<cut for 3<pt^{asso}<5",200,0,20,64,-1.57,4.71);
823   fOutputList->Add(fDphiULSMassLow2);
824
825   fDphiULSMassLow3 = new TH2F("fDphiULSMassLow3", "e-h Dphi ULS, mass<cut for 5<pt^{asso}<7",200,0,20,64,-1.57,4.71);
826   fOutputList->Add(fDphiULSMassLow3);
827
828   fDphiULSMassLow4 = new TH2F("fDphiULSMassLow4", "e-h Dphi ULS, mass<cut for 7<pt^{asso}<9",200,0,20,64,-1.57,4.71);
829   fOutputList->Add(fDphiULSMassLow4);
830
831   fDphiLSMassLow = new TH2F("fDphiLSMassLow", "e-h Dphi LS, mass<cut",200,0,20,64,-1.57,4.71);
832   fOutputList->Add(fDphiLSMassLow);
833
834   fDphiLSMassLow1 = new TH2F("fDphiLSMassLow1", "e-h Dphi LS, mass<cut for 1<pt^{asso}<3",200,0,20,64,-1.57,4.71);
835   fOutputList->Add(fDphiLSMassLow1);
836
837   fDphiLSMassLow2 = new TH2F("fDphiLSMassLow2", "e-h Dphi LS, mass<cut for 3<pt^{asso}<5",200,0,20,64,-1.57,4.71);
838   fOutputList->Add(fDphiLSMassLow2);
839
840   fDphiLSMassLow3 = new TH2F("fDphiLSMassLow3", "e-h Dphi LS, mass<cut for 5<pt^{asso}<7",200,0,20,64,-1.57,4.71);
841   fOutputList->Add(fDphiLSMassLow3);
842
843   fDphiLSMassLow4 = new TH2F("fDphiLSMassLow4", "e-h Dphi LS, mass<cut for 7<pt^{asso}<9",200,0,20,64,-1.57,4.71);
844   fOutputList->Add(fDphiLSMassLow4);
845
846   fDphiULSMassLowNoPartner = new TH2F("fDphiULSMassLowNoPartner", "e-h Dphi ULS with no partner, mass<mass cut,",200,0,20,64,-1.57,4.71);
847   fOutputList->Add(fDphiULSMassLowNoPartner);
848
849   fDphiULSMassLowNoPartner1 = new TH2F("fDphiULSMassLowNoPartner1", "e-h Dphi ULS with no partner, mass<mass cut for 1<pt^{asso}<3,",200,0,20,64,-1.57,4.71);
850   fOutputList->Add(fDphiULSMassLowNoPartner1);
851
852   fDphiULSMassLowNoPartner2 = new TH2F("fDphiULSMassLowNoPartner2", "e-h Dphi ULS with no partner, mass<mass cut for 3<pt^{asso}<5,",200,0,20,64,-1.57,4.71);
853   fOutputList->Add(fDphiULSMassLowNoPartner2);
854
855   fDphiULSMassLowNoPartner3 = new TH2F("fDphiULSMassLowNoPartner3", "e-h Dphi ULS with no partner, mass<mass cut for 5<pt^{asso}<7,",200,0,20,64,-1.57,4.71);
856   fOutputList->Add(fDphiULSMassLowNoPartner3);
857
858   fDphiULSMassLowNoPartner4 = new TH2F("fDphiULSMassLowNoPartner4", "e-h Dphi ULS with no partner, mass<mass cut for 7<pt^{asso}<9,",200,0,20,64,-1.57,4.71);
859   fOutputList->Add(fDphiULSMassLowNoPartner4);
860
861   fDphiLSMassLowNoPartner = new TH2F("fDphiLSMassLowNoPartner", "e-h Dphi LS with no partner, mass<mass cut",200,0,20,64,-1.57,4.71);
862   fOutputList->Add(fDphiLSMassLowNoPartner);
863
864   fDphiLSMassLowNoPartner1 = new TH2F("fDphiLSMassLowNoPartner1", "e-h Dphi LS with no partner, mass<mass cut for 1<pt^{asso}<3,",200,0,20,64,-1.57,4.71);
865   fOutputList->Add(fDphiLSMassLowNoPartner1);                                            
866
867   fDphiLSMassLowNoPartner2 = new TH2F("fDphiLSMassLowNoPartner2", "e-h Dphi LS with no partner, mass<mass cut for 3<pt^{asso}<5,",200,0,20,64,-1.57,4.71);
868   fOutputList->Add(fDphiLSMassLowNoPartner2);
869
870   fDphiLSMassLowNoPartner3 = new TH2F("fDphiLSMassLowNoPartner3", "e-h Dphi LS with no partner, mass<mass cut for 5<pt^{asso}<7,",200,0,20,64,-1.57,4.71);
871   fOutputList->Add(fDphiLSMassLowNoPartner3);
872
873   fDphiLSMassLowNoPartner4 = new TH2F("fDphiLSMassLowNoPartner4", "e-h Dphi LS with no partner, mass<mass cut for 7<pt^{asso}<9,",200,0,20,64,-1.57,4.71);
874   fOutputList->Add(fDphiLSMassLowNoPartner4);
875
876   fPhotoElecPt = new TH1F("fPhotoElecPt", "photonic electron pt",1000,0,100);
877   fOutputList->Add(fPhotoElecPt);
878
879   fSemiInclElecPt = new TH1F("fSemiInclElecPt", "Semi-inclusive electron pt",1000,0,100);
880   fOutputList->Add(fSemiInclElecPt);
881
882   fInclusiveElecPt = new TH1F("fInclElecPt", "Inclusive electron pt",1000,0,100);
883   fOutputList->Add(fInclusiveElecPt);
884
885   fULSElecPt = new TH1F("fULSElecPt", "ULS electron pt",1000,0,100);
886   fOutputList->Add(fULSElecPt);
887
888   fLSElecPt = new TH1F("fLSElecPt", "LS electron pt",1000,0,100);
889   fOutputList->Add(fLSElecPt);
890
891   fNCellv1 = new TH1F("fNCellv1","Ncell in clus (v1); NCell; count",100,0,100) ;
892   fOutputList->Add(fNCellv1);
893
894   fClsEv1 = new TH1F("fClsEv1", "Clus E(v1); Cls E; count",1000,0,100); 
895   fOutputList->Add(fClsEv1); 
896
897   fNClusv1 = new TH1F("fNClusv1","Nclus in event (v1); NClus; count",500,0,500) ; 
898   fOutputList->Add(fNClusv1);
899
900   fInvmassLS1 = new TH1F("fInvmassLS1", "Inv mass of LS (e,e); mass(GeV/c^2); counts;", 1000,0,1.0);
901   fOutputList->Add(fInvmassLS1);
902
903   fInvmassULS1 = new TH1F("fInvmassULS1", "Inv mass of ULS (e,e); mass(GeV/c^2); counts;", 1000,0,1.0);
904   fOutputList->Add(fInvmassULS1);
905
906   fInvmassLS2 = new TH1F("fInvmassLS2", "Inv mass of LS (e,e) for pt^{e}>1; mass(GeV/c^2); counts;", 1000,0,1.0);
907   fOutputList->Add(fInvmassLS2);
908
909   fInvmassULS2 = new TH1F("fInvmassULS2", "Inv mass of ULS (e,e) for pt^{e}>1; mass(GeV/c^2); counts;", 1000,0,1.0);
910   fOutputList->Add(fInvmassULS2);
911
912   fInvmassLS3 = new TH1F("fInvmassLS3", "Inv mass of LS (e,e) for pt^{e}>2; mass(GeV/c^2); counts;", 1000,0,1.0);
913   fOutputList->Add(fInvmassLS3);                                                          
914
915   fInvmassULS3 = new TH1F("fInvmassULS3", "Inv mass of ULS (e,e) for pt^{e}>2; mass(GeV/c^2); counts;", 1000,0,1.0);
916   fOutputList->Add(fInvmassULS3);
917
918   fInvmassLS4 = new TH1F("fInvmassLS4", "Inv mass of LS (e,e) for pt^{e}>3; mass(GeV/c^2); counts;", 1000,0,1.0);
919   fOutputList->Add(fInvmassLS4);  
920
921   fInvmassULS4 = new TH1F("fInvmassULS4", "Inv mass of ULS (e,e) for pt^{e}>3; mass(GeV/c^2); counts;", 1000,0,1.0);
922   fOutputList->Add(fInvmassULS4);
923
924   fInvmassLS5 = new TH1F("fInvmassLS5", "Inv mass of LS (e,e) for pt^{e}>4; mass(GeV/c^2); counts;", 1000,0,1.0);
925   fOutputList->Add(fInvmassLS5);  
926
927   fInvmassULS5 = new TH1F("fInvmassULS5", "Inv mass of ULS (e,e) for pt^{e}>4; mass(GeV/c^2); counts;", 1000,0,1.0);
928   fOutputList->Add(fInvmassULS5);
929
930 /*  fNoMixedEvents = new TH1F("fNoMixedEvents","",1,0,1) ;
931   fOutputList->Add(fNoMixedEvents);
932
933   fMixStat = new TH2F("fMixStat","no of events in pool  vs Centrality;Nevent in pool;Centrality",200,0,200,5,0,10);
934   fOutputList->Add(fMixStat);                                                             
935
936   fMixStat1 = new TH2F("fMixStat1","no of events in pool  vs zvtx;Nevents in pool;zvtx",200,0,200,4,-10,10);
937   fOutputList->Add(fMixStat1);
938
939   fMixedIncElecDphi = new TH2F("fMixedIncElecDphi", "Mixed event - Inclusive elec-had Dphi correlation",200,0,20,100,-1.57,4.71);
940   fOutputList->Add(fMixedIncElecDphi);
941
942   fMixedIncElecDphi1 = new TH2F("fMixedIncElecDphi1", "Mixed event - Inclusive elec-had Dphi correlation 1<pt<3",200,0,20,100,-1.57,4.71);
943   fOutputList->Add(fMixedIncElecDphi1);
944
945   fMixedIncElecDphi2 = new TH2F("fMixedIncElecDphi2", "Mixed event - Inclusive elec-had Dphi correlation 3<pt<5",200,0,20,100,-1.57,4.71);
946   fOutputList->Add(fMixedIncElecDphi2);
947
948   fMixedSemiIncElecDphi = new TH2F("fMixedSemiIncElecDphi", "Mixed event - Semi Inclusive elec-had Dphi correlation",200,0,20,100,-1.57,4.71);
949   fOutputList->Add(fMixedSemiIncElecDphi);
950
951   fMixedSemiIncElecDphi1 = new TH2F("fMixedSemiIncElecDphi1", "Mixed event - Semi Inclusive elec-had Dphi correlation 1<pt<3",200,0,20,100,-1.57,4.71);
952   fOutputList->Add(fMixedSemiIncElecDphi1);
953
954   fMixedSemiIncElecDphi2 = new TH2F("fMixedSemiIncElecDphi2", "Mixed event - Semi Inclusive elec-had Dphi correlation 3<pt<5",200,0,20,100,-1.57,4.71);
955   fOutputList->Add(fMixedSemiIncElecDphi2);
956
957   fMixedPhotElecDphi = new TH2F("fMixedPhotElecDphi", "Mixed event - Photo elec-had Dphi correlation",200,0,20,100,-1.57,4.71);
958   fOutputList->Add(fMixedPhotElecDphi);
959
960   fMixedPhotElecDphi1 = new TH2F("fMixedPhotElecDphi1", "Mixed event - Photo elec-had Dphi correlation 1<pt<3",200,0,20,100,-1.57,4.71);
961   fOutputList->Add(fMixedPhotElecDphi1);
962
963   fMixedPhotElecDphi2 = new TH2F("fMixedPhotElecDphi2", "Mixed event - Photo elec-had Dphi correlation 3<pt<5",200,0,20,100,-1.57,4.71);
964   fOutputList->Add(fMixedPhotElecDphi2);
965
966   fMixedDphiULSMassLow = new TH2F("fMixedDphiULSMassLow", "Mixed event - ULS mass < cut elec-had Dphi correlation",200,0,20,100,-1.57,4.71);
967   fOutputList->Add(fMixedDphiULSMassLow);
968
969   fMixedDphiULSMassLow1 = new TH2F("fMixedDphiULSMassLow1", "Mixed event - ULS mass < cut elec-had Dphi correlation 1<pt<3",200,0,20,100,-1.57,4.71);
970   fOutputList->Add(fMixedDphiULSMassLow1);
971
972   fMixedDphiULSMassLow2 = new TH2F("fMixedDphiULSMassLow2", "Mixed event - ULS mass < cut elec-had Dphi correlation 3<pt<5",200,0,20,100,-1.57,4.71);
973   fOutputList->Add(fMixedDphiULSMassLow2);
974
975   fMixedDphiLSMassLow = new TH2F("fMixedDphiLSMassLow", "Mixed event - LS mass < cut elec-had Dphi correlation",200,0,20,100,-1.57,4.71);
976   fOutputList->Add(fMixedDphiLSMassLow);
977
978   fMixedDphiLSMassLow1 = new TH2F("fMixedDphiLSMassLow1", "Mixed event - LS mass < cut elec-had Dphi correlation 1<pt<3",200,0,20,100,-1.57,4.71);
979   fOutputList->Add(fMixedDphiLSMassLow1);
980
981   fMixedDphiLSMassLow2 = new TH2F("fMixedDphiLSMassLow2", "Mixed event - LS mass < cut elec-had Dphi correlation 3<pt<5",200,0,20,100,-1.57,4.71);
982   fOutputList->Add(fMixedDphiLSMassLow2);
983 */
984   fHadronPt = new TH1F("fHadronPt","hadron pt distribution",1000,0,100);
985   fOutputList->Add(fHadronPt);
986
987   fCentralityPass = new TH1F("fCentralityPass", "Centrality Pass", 101, -1, 100);
988   fOutputList->Add(fCentralityPass);
989
990   fCentralityNoPass = new TH1F("fCentralityNoPass", "Centrality No Pass", 101, -1, 100);
991   fOutputList->Add(fCentralityNoPass);
992
993   /*
994      Int_t binsv1[8]={1000,1000,200,150,100,100,100,100}; //pt, p, TPCnsig, dEdx, E/p, M20, M02, dispersion 
995      Double_t xminv1[8]={0,0,-10,0,0,0,0,0};
996      Double_t xmaxv1[8]={50,50,10,150,2,2,2,2};
997      fSparseElectron = new THnSparseD ("Electron","Electron",8,binsv1,xminv1,xmaxv1);
998      fOutputList->Add(fSparseElectron);
999    */
1000   PostData(1,fOutputList);
1001 }
1002
1003 //________________________________________________________________________
1004 void AliAnalysisTaskElecHadronCorrel::Terminate(Option_t *)
1005 {
1006   // Info("Terminate");
1007   AliAnalysisTaskSE::Terminate();
1008 }
1009
1010 //________________________________________________________________________
1011 Bool_t AliAnalysisTaskElecHadronCorrel::ProcessCutStep(Int_t cutStep, AliVParticle *track)
1012 {
1013   // Check single track cuts for a given cut step
1014   const Int_t kMCOffset = AliHFEcuts::kNcutStepsMCTrack;
1015   if(!fCFM->CheckParticleCuts(cutStep + kMCOffset, track)) return kFALSE;
1016   return kTRUE;
1017 }
1018
1019 //_________________________________________
1020 void AliAnalysisTaskElecHadronCorrel::SelectPhotonicElectron(Int_t itrack, AliVTrack *track, Bool_t &fFlagPhotonicElec)
1021 {
1022   //Identify non-heavy flavour electrons using Invariant mass method
1023
1024   fTrackCuts1->SetAcceptKinkDaughters(kFALSE);
1025   fTrackCuts1->SetRequireTPCRefit(kTRUE);
1026   fTrackCuts1->SetRequireITSRefit(kTRUE);
1027   fTrackCuts1->SetEtaRange(-0.9,0.9);
1028   fTrackCuts1->SetRequireSigmaToVertex(kTRUE);
1029   fTrackCuts1->SetMaxChi2PerClusterTPC(4);
1030   fTrackCuts1->SetMinNClustersTPC(80);
1031   fTrackCuts1->SetMaxDCAToVertexZ(3.2);
1032   fTrackCuts1->SetMaxDCAToVertexXY(2.4);
1033   fTrackCuts1->SetDCAToVertex2D(kTRUE);
1034
1035   Bool_t flagPhotonicElec = kFALSE;
1036
1037   for(Int_t jTracks = 0; jTracks<fVevent->GetNumberOfTracks(); jTracks++){
1038     AliVParticle* VtrackAsso = fVevent->GetTrack(jTracks);
1039     if (!VtrackAsso) {
1040       printf("ERROR: Could not receive track %d\n", jTracks);
1041       continue;
1042     }
1043
1044     AliVTrack *trackAsso = dynamic_cast<AliVTrack*>(VtrackAsso);
1045
1046     //track cuts applied
1047     if(IsAODanalysis()) { 
1048       AliAODTrack *atrackAsso = dynamic_cast<AliAODTrack*>(VtrackAsso);
1049       if(!atrackAsso->TestFilterMask(AliAODTrack::kTrkTPCOnly)) continue;
1050       if(atrackAsso->GetTPCNcls() < 80) continue;
1051       if((!(atrackAsso->GetStatus()&AliESDtrack::kITSrefit)|| (!(atrackAsso->GetStatus()&AliESDtrack::kTPCrefit)))) continue;
1052     }
1053     else{
1054       AliESDtrack *etrackAsso = dynamic_cast<AliESDtrack*>(VtrackAsso);
1055       if(!fTrackCuts1->AcceptTrack(etrackAsso)) continue;
1056     }
1057
1058     if(jTracks==itrack) continue;
1059
1060     Double_t dEdxAsso = -999., ptAsso=-999., nsigma=-999.0;
1061     Double_t mass=-999., width = -999;
1062     Bool_t fFlagLS=kFALSE, fFlagULS=kFALSE;
1063
1064     dEdxAsso = trackAsso->GetTPCsignal();
1065     nsigma = fPID->GetPIDResponse() ? fPID->GetPIDResponse()->NumberOfSigmasTPC(trackAsso, AliPID::kElectron) : 1000;
1066     ptAsso = trackAsso->Pt();
1067     Int_t chargeAsso = trackAsso->Charge();
1068     Int_t charge = track->Charge();
1069
1070     if(ptAsso <0.3) continue;
1071     if(trackAsso->Eta()<-0.9 || trackAsso->Eta()>0.9) continue;
1072     if(nsigma < -3 || nsigma > 3) continue;
1073
1074     Int_t fPDGe1 = 11; Int_t fPDGe2 = 11;
1075     if(charge>0) fPDGe1 = -11;
1076     if(chargeAsso>0) fPDGe2 = -11;
1077
1078     if(charge == chargeAsso) fFlagLS = kTRUE;
1079     if(charge != chargeAsso) fFlagULS = kTRUE;
1080
1081     AliKFParticle ge1 = AliKFParticle(*track, fPDGe1);
1082     AliKFParticle ge2 = AliKFParticle(*trackAsso, fPDGe2);
1083     AliKFParticle recg(ge1, ge2);
1084
1085     if(recg.GetNDF()<1) continue;
1086     Double_t chi2recg = recg.GetChi2()/recg.GetNDF();
1087     if(TMath::Sqrt(TMath::Abs(chi2recg))>3.) continue;
1088
1089     Int_t MassCorrect;
1090     MassCorrect = recg.GetMass(mass,width);
1091
1092     if(fFlagLS) {
1093       fInvmassLS1->Fill(mass);
1094       if(track->Pt()> 1) fInvmassLS2->Fill(mass);
1095       if(track->Pt()>2) fInvmassLS3->Fill(mass);
1096       if(track->Pt()>3) fInvmassLS4->Fill(mass);
1097       if(track->Pt()>4) fInvmassLS5->Fill(mass);
1098     }
1099     if(fFlagULS) {
1100       fInvmassULS1->Fill(mass);
1101       if(track->Pt() >1) fInvmassULS2->Fill(mass);
1102       if(track->Pt() >2) fInvmassULS3->Fill(mass);
1103       if(track->Pt() >3) fInvmassULS4->Fill(mass);
1104       if(track->Pt() >4) fInvmassULS5->Fill(mass);
1105     }
1106
1107     if(mass<fInvmassCut){
1108       if(fFlagULS)
1109       {
1110         ElectronHadCorrel(itrack,track,fDphiULSMassLow, fDphiULSMassLow1,fDphiULSMassLow2,fDphiULSMassLow3,fDphiULSMassLow4);
1111         fULSElecPt->Fill(track->Pt());
1112         //      MixedEvent(track,fMixedDphiULSMassLow,fMixedDphiULSMassLow1,fMixedDphiULSMassLow2);
1113       }
1114       if(fFlagLS)
1115       {
1116         ElectronHadCorrel(itrack,track,fDphiLSMassLow,fDphiLSMassLow1,fDphiLSMassLow2,fDphiLSMassLow3,fDphiLSMassLow4);
1117         fLSElecPt->Fill(track->Pt());
1118         //     MixedEvent(track,fMixedDphiLSMassLow,fMixedDphiLSMassLow1,fMixedDphiLSMassLow2);
1119       }
1120       if(fFlagLS) ElectronHadCorrelNoPartner(itrack,jTracks,track,fDphiLSMassLowNoPartner, fDphiLSMassLowNoPartner1,fDphiLSMassLowNoPartner2,fDphiLSMassLowNoPartner3,fDphiLSMassLowNoPartner4);
1121       if(fFlagULS) ElectronHadCorrelNoPartner(itrack,jTracks,track,fDphiULSMassLowNoPartner, fDphiULSMassLowNoPartner1,fDphiULSMassLowNoPartner2,fDphiULSMassLowNoPartner3,fDphiULSMassLowNoPartner4);
1122     }
1123
1124     if(mass<fInvmassCut && fFlagULS && !flagPhotonicElec){
1125       flagPhotonicElec = kTRUE;
1126     }
1127     //   }
1128
1129 }
1130 fFlagPhotonicElec = flagPhotonicElec;
1131 }
1132 //_________________________________________
1133 void AliAnalysisTaskElecHadronCorrel::ElectronHadCorrel(Int_t itrack, AliVTrack *track, TH2F *DphiPt, TH2F *DphiPt1,TH2F *DphiPt2,TH2F *DphiPt3,TH2F *DphiPt4)
1134 {
1135   //Construct Delta Phi between electrons and hadrons
1136
1137   fTrackCuts2->SetAcceptKinkDaughters(kFALSE);
1138   fTrackCuts2->SetRequireTPCRefit(kTRUE);
1139   fTrackCuts2->SetRequireITSRefit(kTRUE);
1140   fTrackCuts2->SetEtaRange(-0.9,0.9);
1141   fTrackCuts2->SetRequireSigmaToVertex(kTRUE);
1142   fTrackCuts2->SetMaxChi2PerClusterTPC(4);
1143   fTrackCuts2->SetMinNClustersTPC(80);
1144   fTrackCuts2->SetMaxDCAToVertexZ(3.2);
1145   fTrackCuts2->SetMaxDCAToVertexXY(2.4);
1146   fTrackCuts2->SetDCAToVertex2D(kTRUE);
1147
1148   for(Int_t ktracks = 0; ktracks<fVevent->GetNumberOfTracks(); ktracks++){
1149     AliVParticle* VtrackHad = fVevent->GetTrack(ktracks);
1150     if (!VtrackHad) {
1151       printf("ERROR: Could not receive track %d\n", ktracks);
1152       continue;
1153     }
1154
1155     AliVTrack *trackHad = dynamic_cast<AliVTrack*>(VtrackHad);
1156
1157     if(IsAODanalysis()) {
1158       AliAODTrack *atrackHad = dynamic_cast<AliAODTrack*>(VtrackHad);
1159       if(!atrackHad->TestFilterMask(AliAODTrack::kTrkTPCOnly)) continue;
1160       if((!(atrackHad->GetStatus()&AliESDtrack::kITSrefit)|| (!(atrackHad->GetStatus()&AliESDtrack::kTPCrefit)))) continue;
1161       if(atrackHad->GetTPCNcls() < 80) continue; 
1162     }
1163     else{   
1164       AliESDtrack *etrackHad = dynamic_cast<AliESDtrack*>(VtrackHad); 
1165       if(!fTrackCuts2->AcceptTrack(etrackHad)) continue; 
1166     }
1167     
1168     if(ktracks == itrack) continue; //do not select the same electron
1169
1170     Double_t ptHad= -999, pHad=-999., dEdxHad = -999;
1171     Double_t ptEle = -999;
1172     Double_t phiEle = -999, phiHad = -999, Dphi = -999;
1173     Double_t pi = 3.14;
1174
1175     dEdxHad = trackHad->GetTPCsignal();
1176     ptHad = trackHad->Pt();
1177     pHad = trackHad->P();
1178     ptEle = track->Pt();
1179
1180     //    if(ptHad <2) continue;
1181     if(ptHad > ptEle) continue;
1182     if(trackHad->Eta()<-0.9 || trackHad->Eta()>0.9) continue;
1183
1184     phiEle = track->Phi();
1185     phiHad = trackHad->Phi();
1186     Dphi = phiEle - phiHad;
1187     if (Dphi > 3*pi/2)
1188       Dphi = Dphi - 2*pi;
1189     if (Dphi < -pi/2)
1190       Dphi = Dphi + 2*pi;
1191
1192     if(ptHad>2) DphiPt->Fill(ptEle,Dphi);
1193     if(ptHad>2 && ptHad<4) DphiPt1->Fill(ptEle,Dphi);
1194     if(ptHad>4 && ptHad<6) DphiPt2->Fill(ptEle,Dphi);
1195     if(ptHad>6 && ptHad<8) DphiPt3->Fill(ptEle,Dphi);
1196     if(ptHad>8 && ptHad<10) DphiPt4->Fill(ptEle,Dphi);
1197
1198   }
1199 }
1200 //_________________________________________
1201 void AliAnalysisTaskElecHadronCorrel::ElectronHadCorrelNoPartner(Int_t itrack,Int_t jtrack, AliVTrack *track, TH2F *DphiPtNew, TH2F *DphiPtNew1,TH2F *DphiPtNew2,TH2F *DphiPtNew3,TH2F *DphiPtNew4)
1202 {
1203   //Construct Delta Phi between electrons and hadrons for electrons from invariant mass calculation excluding associated track
1204
1205   fTrackCuts2->SetAcceptKinkDaughters(kFALSE);
1206   fTrackCuts2->SetRequireTPCRefit(kTRUE);
1207   fTrackCuts2->SetRequireITSRefit(kTRUE);
1208   fTrackCuts2->SetEtaRange(-0.9,0.9);
1209   fTrackCuts2->SetRequireSigmaToVertex(kTRUE);
1210   fTrackCuts2->SetMaxChi2PerClusterTPC(4);
1211   fTrackCuts2->SetMinNClustersTPC(80);
1212   fTrackCuts2->SetMaxDCAToVertexZ(3.2);
1213   fTrackCuts2->SetMaxDCAToVertexXY(2.4);
1214   fTrackCuts2->SetDCAToVertex2D(kTRUE);
1215
1216   for(Int_t ktracks = 0; ktracks<fVevent->GetNumberOfTracks(); ktracks++){
1217     AliVParticle* VtrackHad = fVevent->GetTrack(ktracks);
1218     if (!VtrackHad) {
1219       printf("ERROR: Could not receive track %d\n", ktracks);
1220       continue;
1221     }
1222     
1223     AliVTrack *trackHad = dynamic_cast<AliVTrack*>(VtrackHad);
1224
1225     if(IsAODanalysis()) {
1226       AliAODTrack *atrackHad = dynamic_cast<AliAODTrack*>(VtrackHad);
1227       if(!atrackHad->TestFilterMask(AliAODTrack::kTrkTPCOnly)) continue;
1228       if((!(atrackHad->GetStatus()&AliESDtrack::kITSrefit)|| (!(atrackHad->GetStatus()&AliESDtrack::kTPCrefit)))) continue;
1229       if(atrackHad->GetTPCNcls() < 80) continue; 
1230     }
1231     else{   
1232       AliESDtrack *etrackHad = dynamic_cast<AliESDtrack*>(VtrackHad); 
1233       if(!fTrackCuts2->AcceptTrack(etrackHad)) continue; 
1234     }
1235
1236     if(ktracks == itrack || ktracks == jtrack) continue; //do not select the same electron and associated track from inv mass cal
1237
1238     Double_t ptHad= -999, pHad=-999., dEdxHad = -999;
1239     Double_t ptEle = -999;
1240     Double_t phiEle = -999, phiHad = -999, Dphi = -999;
1241     Double_t pi = 3.14;
1242
1243     dEdxHad = trackHad->GetTPCsignal();
1244     ptHad = trackHad->Pt();
1245     pHad = trackHad->P();
1246     ptEle = track->Pt();
1247
1248 //    if(ptHad <2) continue;
1249     if(ptHad > ptEle) continue;
1250     if(trackHad->Eta()<-0.9 || trackHad->Eta()>0.9) continue;
1251
1252     phiEle = track->Phi();
1253     phiHad = trackHad->Phi();
1254     Dphi = phiEle - phiHad;
1255     if (Dphi > 3*pi/2)
1256       Dphi = Dphi - 2*pi;
1257     if (Dphi < -pi/2)
1258       Dphi = Dphi + 2*pi;
1259
1260     if(ptHad>2) DphiPtNew->Fill(ptEle,Dphi);
1261     if(ptHad>2 && ptHad<4) DphiPtNew1->Fill(ptEle,Dphi);
1262     if(ptHad>4 && ptHad<6) DphiPtNew2->Fill(ptEle,Dphi);
1263     if(ptHad>6 && ptHad<8) DphiPtNew3->Fill(ptEle,Dphi);
1264     if(ptHad>8 && ptHad<10) DphiPtNew4->Fill(ptEle,Dphi);
1265   }
1266 }
1267
1268 /*
1269 //_________________________________________
1270 void AliAnalysisTaskElecHadronCorrel::MixedEvent(AliAODTrack *track, TH2F *DphiPt, TH2F *DphiPt1,TH2F *DphiPt2)
1271 {
1272
1273   const AliAODVertex *pVtx = fAOD->GetPrimaryVertex();
1274   Double_t zVtx;
1275   zVtx = pVtx->GetZ();
1276
1277
1278   AliCentrality *fCentrality = (AliCentrality*)fAOD->GetCentrality();
1279   Double_t centvalue = fCentrality->GetCentralityPercentile("V0M");
1280
1281   AliEventPool* pool = fPoolMgr->GetEventPool(centvalue, zVtx); // Get the buffer associated with the current centrality and z-vtx
1282   if (!pool)
1283     AliFatal(Form("No pool found for centrality = %f, zVtx = %f", centvalue, zVtx));
1284
1285   //  pool->PrintInfo();
1286   if (pool->GetCurrentNEvents() >= 5) // start mixing when 5 events are in the buffer
1287   {
1288     Int_t nMix = pool->GetCurrentNEvents();
1289     fNoMixedEvents->Fill(0);
1290     fMixStat->Fill(pool->GetCurrentNEvents(),centvalue);
1291     fMixStat1->Fill(pool->GetCurrentNEvents(),zVtx);
1292
1293    // cout << "nMix = " << nMix << " tracks in pool = " << pool->NTracksInPool() << endl;
1294     for (Int_t jMix=0; jMix<nMix; jMix++)  // mix with each event in the buffer
1295     {
1296       TObjArray* bgTracks = pool->GetEvent(jMix);
1297       for (Int_t i=0;i<bgTracks->GetEntriesFast(); i++)
1298       {
1299         AliVParticle* mixtrk = (AliVParticle*) bgTracks->At(i);
1300
1301         Double_t mixtrkPhi = -999;
1302         Double_t ptEle = -999;
1303         Double_t phiEle = -999, Dphi = -999;
1304         Double_t pi = 3.14;
1305         Double_t ptmixtrk = -999;
1306
1307         ptEle = track->Pt();
1308         ptmixtrk = mixtrk->Pt();
1309         if(ptmixtrk > ptEle) continue;
1310
1311         mixtrkPhi = mixtrk->Phi();
1312         phiEle = track->Phi();
1313         Dphi = phiEle - mixtrkPhi;
1314
1315         if (Dphi > 3*pi/2)
1316           Dphi = Dphi - 2*pi;
1317         if (Dphi < -pi/2)
1318           Dphi = Dphi + 2*pi;
1319         if(ptmixtrk>2) DphiPt->Fill(ptEle,Dphi);
1320         if(ptmixtrk>2 && ptmixtrk<4) DphiPt1->Fill(ptEle,Dphi);
1321         if(ptmixtrk>4 && ptmixtrk<6) DphiPt2->Fill(ptEle,Dphi);
1322       }
1323     }
1324
1325   }
1326
1327 }
1328 //___________________________________________
1329 TObjArray*  AliAnalysisTaskElecHadronCorrel::CloneAndReduceTrackList()
1330 {
1331   // clones a track list by using AliehDPhiBasicParticle which uses much less memory (used for event mixing)
1332
1333   fTrackCuts2->SetAcceptKinkDaughters(kFALSE);
1334   fTrackCuts2->SetRequireTPCRefit(kTRUE);
1335   fTrackCuts2->SetRequireITSRefit(kTRUE);
1336   fTrackCuts2->SetEtaRange(-0.9,0.9);
1337   fTrackCuts2->SetRequireSigmaToVertex(kTRUE);
1338   fTrackCuts2->SetMaxChi2PerClusterTPC(3.5);
1339   fTrackCuts2->SetMinNClustersTPC(80);
1340
1341   TObjArray* tracksClone = new TObjArray;
1342   tracksClone->SetOwner(kTRUE);
1343
1344   for(Int_t ktracks = 0; ktracks<fAOD->GetNumberOfTracks(); ktracks++){
1345     AliAODTrack* track = fAOD->GetTrack(ktracks);
1346     if (!track) {
1347       printf("ERROR: Could not receive track %d\n", ktracks);
1348       continue;
1349     }
1350     if(!track->TestFilterMask(AliAODTrack::kTrkGlobalNoDCA)) continue;
1351
1352     //   if(ktracks == iTrack) continue;
1353     Double_t eta=-999,ptHad= -999, pHad=-999., phi=-999.0;
1354     Int_t label=-9999, id=-999;
1355     eta = track->Eta();
1356     ptHad = track->Pt();
1357     pHad = track->P();
1358     phi= track->Phi();
1359     label= track->GetLabel();
1360     id=track->GetID();
1361     
1362     if(track->Eta()<-0.9 || track->Eta()>0.9) continue; 
1363     if(!ProcessCutStep(AliHFEcuts::kStepRecKineITSTPC, track)) continue; 
1364     if(!ProcessCutStep(AliHFEcuts::kStepHFEcutsTPC, track)) continue; 
1365     if(ptHad <2) continue;
1366 //    if(!fTrackCuts2->AcceptTrack(track)) continue;
1367
1368     AliVParticle* particle = (AliVParticle*) fAOD->GetTrack(ktracks);
1369     tracksClone->Add(new AliehDPhiBasicParticle(particle->Eta(), particle->Phi(), particle->Pt(), particle->Charge()));
1370
1371   }
1372
1373   return tracksClone;
1374 }
1375 */
1376 //___________________________________________
1377 void AliAnalysisTaskElecHadronCorrel::HadronInfo(Int_t itrack)
1378 {
1379   //Hadron information
1380
1381   fTrackCuts2->SetAcceptKinkDaughters(kFALSE);                                           
1382   fTrackCuts2->SetRequireTPCRefit(kTRUE);                                                
1383   fTrackCuts2->SetRequireITSRefit(kTRUE);                                                
1384   fTrackCuts2->SetEtaRange(-0.9,0.9);
1385   fTrackCuts2->SetRequireSigmaToVertex(kTRUE);                                           
1386   fTrackCuts2->SetMaxChi2PerClusterTPC(4);                                             
1387   fTrackCuts2->SetMinNClustersTPC(80);                                                   
1388   fTrackCuts2->SetMaxDCAToVertexZ(3.2);
1389   fTrackCuts2->SetMaxDCAToVertexXY(2.4);
1390   fTrackCuts2->SetDCAToVertex2D(kTRUE);
1391
1392   for(Int_t ktracks = 0; ktracks<fVevent->GetNumberOfTracks(); ktracks++){                  
1393     AliVParticle* VtrackHad = fVevent->GetTrack(ktracks);                                     
1394     if (!VtrackHad) {
1395       printf("ERROR: Could not receive track %d\n", ktracks);                            
1396       continue;                                                                          
1397     }
1398
1399     AliVTrack *trackHad = dynamic_cast<AliVTrack*>(VtrackHad);
1400
1401     if(IsAODanalysis()) {
1402       AliAODTrack *atrackHad = dynamic_cast<AliAODTrack*>(VtrackHad);
1403       if(!atrackHad->TestFilterMask(AliAODTrack::kTrkTPCOnly)) continue;
1404       if((!(atrackHad->GetStatus()&AliESDtrack::kITSrefit)|| (!(atrackHad->GetStatus()&AliESDtrack::kTPCrefit)))) continue;
1405       if(atrackHad->GetTPCNcls() < 80) continue; 
1406     }
1407     else{   
1408       AliESDtrack *etrackHad = dynamic_cast<AliESDtrack*>(VtrackHad); 
1409       if(!fTrackCuts2->AcceptTrack(etrackHad)) continue; 
1410     }
1411
1412     if(ktracks == itrack) continue; //do not select the same electron
1413     
1414     Double_t ptHad= -999;
1415     ptHad = trackHad->Pt();
1416     
1417     if(trackHad->Eta()<-0.9 || trackHad->Eta()>0.9) continue;
1418    // cout << "pt had = " << ptHad <<endl;
1419
1420     if(ptHad<2) continue;
1421
1422     fHadronPhi->Fill(trackHad->Phi());
1423     fHadronPhiPt->Fill(trackHad->Phi(),ptHad);
1424     if (trackHad->Eta() >0 && trackHad->Eta() <0.9) fHadronPhiTPChalf->Fill(trackHad->Phi());
1425
1426     fHadronPt->Fill(ptHad);
1427   }
1428 }
1429 //_________________________________________
1430 void AliAnalysisTaskElecHadronCorrel::CheckCentrality(AliVEvent* event, Bool_t &centralitypass)
1431 {
1432   // Check if event is within the set centrality range. Falls back to V0 centrality determination if no method is set
1433   if (!fkCentralityMethod) AliFatal("No centrality method set! FATAL ERROR!");
1434   fCentrality = event->GetCentrality()->GetCentralityPercentile(fkCentralityMethod);
1435  // cout << "Centrality evaluated-------------------------: " << fCentrality <<endl;
1436
1437   if ((fCentrality <= fCentralityMin) || (fCentrality > fCentralityMax))
1438   {
1439     fCentralityNoPass->Fill(fCentrality);
1440   //  cout << "--------------Fill no pass-------------------------"<<endl;
1441     centralitypass = kFALSE;
1442   }else
1443   {
1444     fCentralityPass->Fill(fCentrality);
1445   //  cout << "--------------Fill pass-------------------------"<<endl;
1446     centralitypass = kTRUE;
1447   }
1448
1449 }
1450 //_____________________________________________________________________________
1451 void AliAnalysisTaskElecHadronCorrel::SetCentralityParameters(Double_t CentralityMin, Double_t CentralityMax, const char* CentralityMethod)
1452 {
1453   // Set a centrality range ]min, max] and define the method to use for centrality selection
1454   fCentralityMin = CentralityMin;
1455   fCentralityMax = CentralityMax;
1456   fkCentralityMethod = CentralityMethod;
1457 }