]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGCF/EBYE/Fluctuations/AliEbyEHigherMomentsEffContTask.cxx
AliAODEvent::GetHeader() returns AliVHeader
[u/mrichter/AliRoot.git] / PWGCF / EBYE / Fluctuations / AliEbyEHigherMomentsEffContTask.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: Satyajit Jena.                                                 *
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 //           Analysis Task for Net-Charge Higher Moment Analysis           //
20 //              Author: Satyajit Jena || Nirbhay K. Behera                 //
21 //                      sjena@cern.ch || nbehera@cern.ch                   //
22 //                                                                         //
23 //=========================================================================//
24
25 #include "TChain.h"
26 #include "TList.h"
27 #include "TFile.h"
28 #include "TTree.h"
29 #include "TH1D.h"
30 #include "TH2F.h"
31 #include "THnSparse.h"
32 #include "TCanvas.h"
33 #include "TParticle.h"
34 #include <TDatabasePDG.h>
35 #include <TParticlePDG.h>
36
37 #include "AliAnalysisTaskSE.h"
38 #include "AliAnalysisManager.h"
39
40 #include "AliESDVertex.h"
41 #include "AliESDEvent.h"
42 #include "AliESDInputHandler.h"
43 #include "AliAODEvent.h"
44 #include "AliAODTrack.h"
45 #include "AliAODInputHandler.h"
46 #include "AliESD.h"
47 #include "AliESDEvent.h"
48 #include "AliAODEvent.h"
49 #include "AliStack.h"
50 #include "AliESDtrackCuts.h"
51 #include "AliAODMCHeader.h"
52 #include "AliAODMCParticle.h"
53 #include "AliMCEventHandler.h"
54 #include "AliMCEvent.h"
55 #include "AliMCParticle.h"
56 #include "AliStack.h"
57 #include "AliGenHijingEventHeader.h"
58 #include "AliGenEventHeader.h"
59 #include "AliPID.h"
60 #include "AliAODPid.h"                
61 #include "AliPIDResponse.h"
62 #include "AliAODpidUtil.h"        
63 #include "AliPIDCombined.h"
64
65 #include "AliEbyEHigherMomentsEffContTask.h"
66
67 using std::cout;
68 using std::endl;
69
70
71 ClassImp(AliEbyEHigherMomentsEffContTask)
72
73
74 //-----------------------------------------------------------------------
75 AliEbyEHigherMomentsEffContTask::AliEbyEHigherMomentsEffContTask( const char *name )
76 : AliAnalysisTaskSE( name ),
77   fListOfHistosQA(0),
78   fListOfHistos(0),
79   fAOD(0),
80   fArrayMC(0),
81   fPIDResponse(0),
82   fParticleSpecies(AliPID::kProton),
83   fAnalysisType("AOD"),
84   fCentralityEstimator("V0M"),
85   fCentrality(0),
86   fVxMax(3.),
87   fVyMax(3.),
88   fVzMax(10.),
89   fDCAxy(2.4),
90   fDCAz(3.),
91   fPtLowerLimit(0.3),
92   fPtHigherLimit(1.5),
93   fEtaLowerLimit(-0.8),
94   fEtaHigherLimit(0.8),
95   fRapidityCut(0.5),
96   fNSigmaCut(3.),
97   fTPCNClus(80),
98   fChi2perNDF(4.),
99   fAODtrackCutBit(1024),
100   fLabel(NULL),
101   fUsePid(kFALSE),
102   fCheckCont(kFALSE),
103   fEff(kFALSE),
104   fEventCounter(0),
105   fHistDCA(0),
106   fTPCSig(0),
107   fTPCSigA(0),
108   fTHnCentNplusNminusCh(0),
109   fTHnCentNplusNminus(0),
110   fTHnEff(0),
111   fTHnCont(0)
112
113  
114   for ( Int_t i = 0; i < 13; i++) { 
115     fHistQA[i] = NULL;
116   }
117   
118   for ( Int_t i = 0; i < 5; i++ ){
119     fTHnCentNplusNminusPid[i] = NULL;
120   }
121
122   DefineOutput(1, TList::Class()); // Outpput....
123   DefineOutput(2, TList::Class()); 
124
125 }
126
127 AliEbyEHigherMomentsEffContTask::~AliEbyEHigherMomentsEffContTask() {
128   
129   if(fListOfHistosQA) delete fListOfHistosQA;
130   if(fListOfHistos) delete fListOfHistos;
131   if(fLabel[0] ) delete [] (fLabel[0]);
132   if(fLabel[1] ) delete [] (fLabel[1]);
133
134 }
135
136 //---------------------------------------------------------------------------------
137 void AliEbyEHigherMomentsEffContTask::UserCreateOutputObjects() {
138   //For QA-Histograms
139   fListOfHistosQA = new TList();
140   fListOfHistosQA->SetOwner(kTRUE);
141   
142   fListOfHistos = new TList();
143   fListOfHistos->SetOwner(kTRUE);
144   
145   fEventCounter = new TH1D("fEventCounter","EventCounter", 10, 0.5,10.5);
146   fEventCounter->GetXaxis()->SetBinLabel(1,"Event Accesed");
147   fEventCounter->GetXaxis()->SetBinLabel(2,"Within 0-90% centrality");
148   fEventCounter->GetXaxis()->SetBinLabel(5,"Have a vertex");
149   fEventCounter->GetXaxis()->SetBinLabel(6,"After vertex Cut");
150   fEventCounter->GetXaxis()->SetBinLabel(7,"Event Analyzed");
151   fEventCounter->GetXaxis()->SetBinLabel(8,"Event Analysis finished");
152   fListOfHistosQA->Add(fEventCounter);
153   
154   fHistQA[0] = new TH1D("fHistQAvx", "Histo Vx After Cut", 400, -4., 4.);
155   fHistQA[1] = new TH1D("fHistQAvy", "Histo Vy After Cut", 400, -4., 4.);
156   fHistQA[2] = new TH1D("fHistQAvz", "Histo Vz After Cut", 500, -25., 25.);  
157   fHistQA[3] = new TH1D("fHistQAvxA", "Histo Vx All", 500, -5., 5.);
158   fHistQA[4] = new TH1D("fHistQAvyA", "Histo Vy All", 500, -5., 5.);
159   fHistQA[5] = new TH1D("fHistQAvzA", "Histo Vz All", 500, -25., 25.);
160   fHistQA[6] = new TH1D("fHistQADcaXyC", "Histo DCAxy after cut", 500, -5., 5.);
161   fHistQA[7] = new TH1D("fHistQADcaZC", "Histo DCAz after cut", 500, -5., 5.);   
162   fHistQA[8] = new TH1D("fHistQAPt","p_{T} distribution",600,0,6);
163   fHistQA[9] = new TH1D("fHistQAEta","#eta distribution",240,-1.2,1.2);
164   fHistQA[10] = new TH1D("fHistQAPhi","#phi distribution",340,0,6.8);
165   fHistQA[11] = new TH1D("fHistQANCls","Number of TPC cluster",200,0,200);
166   fHistQA[12] = new TH1D("fHistQAChi2","Chi2 per NDF",100,0,10);
167   
168   for(Int_t i = 0; i < 13; i++)
169     {
170       fListOfHistosQA->Add(fHistQA[i]);
171     }
172   
173   fHistDCA = new TH2D("fHistDCA","DCAxy Vs DCAz", 500, -5., 5., 500, -5., 5.);
174   fTPCSig = new TH2D("fTPCSig","TPC signal",200, 0.0, 10. ,1000,0.,1000);
175   fTPCSig->SetMarkerColor(kRed);
176   fTPCSigA = new TH2D("fTPCSigA","TPC signal all ",200, 0.0, 10. ,1000,0.,1000);
177   fListOfHistosQA->Add(fHistDCA);
178   fListOfHistosQA->Add(fTPCSig);
179   fListOfHistosQA->Add(fTPCSigA);
180   
181   const Int_t nDim = 3;
182   const Int_t nPid = 5;
183
184   TString Species[nPid] = {"Electron","Muon","Pion","Kaon","Proton"};
185   
186   Int_t fBins[nPid][nDim];
187   Double_t fMin[nPid][nDim];
188   Double_t fMax[nPid][nDim];
189   
190   for( Int_t i = 0; i < nPid; i++ ){
191     for( Int_t j = 0; j < nDim; j++ ){
192       fBins[i][j] = 0;
193       fMin[i][j] = 0.;
194       fMax[i][j] = 0.;
195     }
196   }
197   
198   
199   // if(fAnalysisType == "AOD" || fAnalysisType == "MCAOD")
200     
201   //{
202       TString hname1;
203       TString htitle1, axisTitle1, axisTitle2;
204       
205       
206       
207       if( fUsePid ){
208         
209         Int_t gPid = (Int_t)fParticleSpecies;
210         
211         if( gPid > 1 && gPid < 5 ){ 
212           //Pion----
213           fBins[2][0] = 100; fBins[2][1] = 1000; fBins[2][2] = 1000;
214           fMin[2][0] = -0.5; fMin[2][1] = -0.5; fMin[2][2] = -0.5;
215           fMax[2][0] = 99.5; fMax[2][1] = 999.5; fMax[2][2] = 999.5;
216           //Kaon------
217           fBins[3][0] = 100; fBins[3][1] = 600; fBins[3][2] = 600;
218           fMin[3][0] = -0.5; fMin[3][1] = -0.5; fMin[3][2] = -0.5;
219           fMax[3][0] = 99.5; fMax[3][1] = 599.5; fMax[3][2] = 599.5;
220           //Proton-----
221           fBins[4][0] = 100; fBins[4][1] = 400; fBins[4][2] = 400;
222           fMin[4][0] = -0.5; fMin[4][1] = -0.5; fMin[4][2] = -0.5;
223           fMax[4][0] = 99.5; fMax[4][1] = 399.5; fMax[4][2] = 399.5;
224           
225           hname1 = "fCentNplusNminusPid"; hname1 +=gPid;
226           htitle1 = Species[gPid]; htitle1 +=" And Neg-"; htitle1 +=Species[gPid];
227           axisTitle1 = Species[gPid];
228           axisTitle2 ="Neg-"; axisTitle2 += Species[gPid];
229           
230           fTHnCentNplusNminusPid[gPid] = new THnSparseD(hname1.Data(),htitle1.Data(), nDim, fBins[gPid], fMin[gPid],fMax[gPid]);
231           
232           fTHnCentNplusNminusPid[gPid]->GetAxis(0)->SetTitle("Centrality");
233           fTHnCentNplusNminusPid[gPid]->GetAxis(1)->SetTitle(axisTitle1.Data());
234           fTHnCentNplusNminusPid[gPid]->GetAxis(1)->SetTitle(axisTitle2.Data());
235           
236           fListOfHistos->Add(fTHnCentNplusNminusPid[gPid]);
237           
238         }//Pion, Koan and Proton-------
239         
240         else{
241           
242           Int_t fBinsX[nDim] = {100, 1500, 1500};
243           Double_t fMinX[nDim] = { -0.5, -0.5, -0.5 };
244           Double_t fMaxX[nDim] = { 99.5, 1499.5, 1499.5};
245           
246           fTHnCentNplusNminus = new THnSparseD("fTHnCentNplusNminus","Cent-NplusChrg-NminusChrg", nDim, fBinsX, fMinX, fMaxX); 
247           fTHnCentNplusNminus->GetAxis(0)->SetTitle("Centrality");
248           fTHnCentNplusNminus->GetAxis(1)->SetTitle("UnwantedPlus");
249           fTHnCentNplusNminus->GetAxis(2)->SetTitle("UnwantedMinus");
250           fListOfHistos->Add(fTHnCentNplusNminus);
251           
252         }//Unwanted particle -------
253         
254       }//fUsePid-------
255       
256       else{    
257         
258         Int_t fBinsCh[nDim] = {100, 1500, 1500};
259         Double_t fMinCh[nDim] = { -0.5, -0.5, -0.5 };
260         Double_t fMaxCh[nDim] = { 99.5, 1499.5, 1499.5};
261         
262         fTHnCentNplusNminusCh = new THnSparseD("fTHnCentNplusNminusCh","Cent-NplusChrg-NminusChrg", nDim, fBinsCh, fMinCh, fMaxCh); 
263         fTHnCentNplusNminusCh->GetAxis(0)->SetTitle("Centrality");
264         fTHnCentNplusNminusCh->GetAxis(1)->SetTitle("Nplus");
265         fTHnCentNplusNminusCh->GetAxis(2)->SetTitle("Nminus");
266         fListOfHistos->Add(fTHnCentNplusNminusCh);
267       }//All charge hadrons---------
268       
269
270
271   if( fAnalysisType == "MCAOD" ){
272     
273     Double_t dCent[2] = {-0.5, 9.5};
274     Int_t iCent       = 10;
275     
276     Double_t dEta[2]  = {-0.9, 0.9}; 
277     Int_t iEta        = Int_t((dEta[1]-dEta[0]) / 0.075) +1 ; 
278     
279     Double_t dRap[2]  = {-0.5, 0.5}; 
280     Int_t iRap        = Int_t((dRap[1]-dRap[0]) / 0.075) +1 ; 
281     
282     Double_t dPhi[2]  = {0.0, TMath::TwoPi()};
283     Int_t iPhi        = 42;
284     
285     Double_t dPt[2]   = {0.1, 3.0};
286     Int_t iPt         = Int_t((dPt[1]-dPt[0]) / 0.075);
287     
288     Double_t dSign[2] = {-1.5, 1.5};
289     Int_t iSign       = 3;
290     
291     if(fEff){    
292       
293       Int_t nBinEff[15] = { iCent, iEta, iRap, iPhi, iPt, iSign, 2, 2, 2, iEta, iPhi, iPt, iEta, 2*iPhi+1, 2*iPt+1};
294       Double_t nMinEff[15] = { dCent[0], dEta[0], dRap[0], dPhi[0], dPt[0], dSign[0], -0.5, -0.5, -0.5, dEta[0], dPhi[0], dPt[0], dEta[0], -dPhi[1], -dPt[1] };
295       Double_t nMaxEff[15] = { dCent[1], dEta[1], dRap[1], dPhi[1], dPt[1], dSign[1], 1.5, 1.5, 1.5, dEta[1], dPhi[1], dPt[1], dEta[1], dPhi[1], dPt[1] };
296       
297       fTHnEff = new THnSparseF("fHnEff", "cent:etaMC:yMC:phiMC:ptMC:sign:findable:recStatus:pidStatus:etaRec:phiRec:ptRec:deltaEta:deltaPhi:deltaPt", 15, nBinEff, nMinEff, nMaxEff);
298       
299       fTHnEff->Sumw2();
300       
301       fTHnEff->GetAxis(0)->SetTitle("centrality");
302       fTHnEff->GetAxis(1)->SetTitle("#eta_{MC}");
303       fTHnEff->GetAxis(2)->SetTitle("#it{y}_{MC}");
304       fTHnEff->GetAxis(3)->SetTitle("#varphi_{MC} (rad)"); 
305       fTHnEff->GetAxis(4)->SetTitle("p_{T,MC} (GeV/#it{c})");
306       fTHnEff->GetAxis(5)->SetTitle("sign");
307       fTHnEff->GetAxis(6)->SetTitle("findable");
308       fTHnEff->GetAxis(7)->SetTitle("recStatus");
309       fTHnEff->GetAxis(8)->SetTitle("recPid");
310       fTHnEff->GetAxis(9)->SetTitle("#eta_{Rec}");
311       fTHnEff->GetAxis(10)->SetTitle("#varphi_{Rec} (rad)");
312       fTHnEff->GetAxis(11)->SetTitle("p_{T,Rec} (GeV/#it{c})");
313       fTHnEff->GetAxis(12)->SetTitle("#eta_{MC}-#eta_{Rec}");
314       fTHnEff->GetAxis(13)->SetTitle("#varphi_{MC}-#varphi_{Rec} (rad)");
315       fTHnEff->GetAxis(14)->SetTitle("p_{T,MC}-p_{T,Rec} (GeV/#it{c})");
316       
317       fListOfHistos->Add(fTHnEff);
318     }
319     
320     if(fCheckCont){  
321       
322       Int_t nBinCont[14] = { iCent,    iEta,    iRap,    iPhi,    iPt,    iSign,       8,    iSign,    iEta,    iPhi,    iPt,    iEta, 2*iPhi+1, 2*iPt+1 };
323       Double_t nMinCont[14] = {dCent[0], dEta[0], dRap[0], dPhi[0], dPt[0], dSign[0],     0.5, dSign[0], dEta[0], dPhi[0], dPt[0], dEta[0], -dPhi[1], -dPt[1]};
324       Double_t nMaxCont[14] = { dCent[1], dEta[1], dRap[1], dPhi[1], dPt[1], dSign[1],     8.5, dSign[1], dEta[1], dPhi[1], dPt[1], dEta[1],  dPhi[1],  dPt[1] };
325       
326       fTHnCont = new THnSparseF("fHnCont", "cent:etaMC:yMC:phiMC:ptMC:sign:contPart:contSign:etaRec:phiRec:ptRec:deltaEta:deltaPhi:deltaPt",14, nBinCont, nMinCont, nMaxCont);
327       fTHnCont->Sumw2();
328       
329       fTHnCont->GetAxis(0)->SetTitle("centrality");      
330       fTHnCont->GetAxis(1)->SetTitle("#eta_{MC}"); 
331       fTHnCont->GetAxis(2)->SetTitle("#it{y}_{MC}");
332       fTHnCont->GetAxis(3)->SetTitle("#varphi_{MC} (rad)"); 
333       fTHnCont->GetAxis(4)->SetTitle("p_{T,MC} (GeV/#it{c})");
334       fTHnCont->GetAxis(5)->SetTitle("sign");
335       fTHnCont->GetAxis(6)->SetTitle("contPart");
336       fTHnCont->GetAxis(7)->SetTitle("contSign");
337       fTHnCont->GetAxis(8)->SetTitle("#eta_{Rec}");
338       fTHnCont->GetAxis(9)->SetTitle("#varphi_{Rec} (rad)");
339       fTHnCont->GetAxis(10)->SetTitle("p_{T,Rec} (GeV/#it{c})");
340       fTHnCont->GetAxis(11)->SetTitle("#eta_{MC}-#eta_{Rec}"); 
341       fTHnCont->GetAxis(12)->SetTitle("#varphi_{MC}-#varphi_{Rec} (rad)");
342       fTHnCont->GetAxis(13)->SetTitle("p_{T,MC}-p_{T,Rec} (GeV/#it{c})");
343       
344       fListOfHistos->Add(fTHnCont);
345     }
346     
347   }//MCAOD------
348   
349   PostData(1, fListOfHistosQA);
350   PostData(2, fListOfHistos);
351   
352 }
353
354
355 //----------------------------------------------------------------------------------
356 void AliEbyEHigherMomentsEffContTask::UserExec( Option_t * ){
357   
358   fEventCounter->Fill(1);
359
360   
361   if(fAnalysisType == "AOD") {
362     
363     doAODEvent();
364     
365   }//AOD--analysis-----
366
367   else if(fAnalysisType == "MCAOD") {
368   
369     doMCAODEvent();
370     
371   }
372   
373   else return;
374   
375   
376   
377   
378   fEventCounter->Fill(8);
379   
380   PostData(1, fListOfHistosQA);
381   PostData(2, fListOfHistos);
382   
383 }
384
385 //--------------------------------------------------------------------------------------
386 void AliEbyEHigherMomentsEffContTask::doAODEvent(){
387  
388   //-------------------
389   Double_t nPlusCharge = 0.;
390   Double_t nMinusCharge = 0.;
391   Double_t nPartile = 0.;
392   Double_t nAntiParticle = 0.;
393   Int_t gPid = 0.;
394
395
396   //connect to the analysis mannager-----
397  
398   AliAnalysisManager* manager = AliAnalysisManager::GetAnalysisManager();
399   if (!manager) {
400     cout<<"ERROR: Analysis manager not found."<<endl;
401     return;
402   }
403   //coneect to the inputHandler------------
404   AliAODInputHandler* inputHandler = dynamic_cast<AliAODInputHandler*> (manager->GetInputEventHandler());
405   if (!inputHandler) {
406     cout<<"ERROR: Input handler not found."<<endl;
407     return;
408   }
409   
410   fAOD = dynamic_cast<AliAODEvent*>(InputEvent());
411   if (!fAOD)
412     {
413       cout<< "ERROR 01: AOD not found " <<endl;
414       return;
415     }
416   
417   fPIDResponse =inputHandler->GetPIDResponse();
418   
419   
420   if (!fPIDResponse){
421     AliFatal("This Task needs the PID response attached to the inputHandler");
422     return;
423   }  
424   
425   
426   AliAODHeader *aodHeader = dynamic_cast<AliAODHeader*>(fAOD->GetHeader());
427   if(!aodHeader) AliFatal("Not a standard AOD");
428   
429   Int_t cent = -1;
430   cent =  aodHeader->GetCentralityP()->GetCentralityClass10(fCentralityEstimator.Data());
431   
432   if (cent == 0)
433     fCentrality = aodHeader->GetCentralityP()->GetCentralityClass5(fCentralityEstimator.Data());
434   else if (cent == 10 || cent == -1.)
435     fCentrality = -1;
436   else if (cent > 0 && cent < 9)
437     fCentrality = cent + 1;
438   
439   if(fCentrality < 0 || fCentrality >= 10) return;
440   
441   fEventCounter->Fill(2);
442   
443   if(!ProperVertex()) return;   
444   
445   Int_t nTracks = fAOD->GetNumberOfTracks();
446   
447   TExMap *trackMap = new TExMap();//Mapping matrix----
448   
449   for(Int_t i = 0; i < nTracks; i++) {
450     
451     AliAODTrack* aodTrack = dynamic_cast<AliAODTrack *>(fAOD->GetTrack(i)); 
452     
453     if(!aodTrack) {
454       AliError(Form("ERROR: Could not retrieve AODtrack %d",i));
455       continue;
456     }
457     
458     Double_t tpcSignalAll = aodTrack->GetTPCsignal();
459     fTPCSigA->Fill(aodTrack->GetTPCmomentum(),tpcSignalAll);
460     
461     Int_t gID = aodTrack->GetID();
462     
463     if (aodTrack->TestFilterBit(1)) trackMap->Add(gID, i);//Global tracks-----
464   }//1st track loop----
465  
466  AliAODTrack* newAodTrack; 
467   
468   for( Int_t j = 0; j < nTracks; j++ )
469     {
470       
471       AliAODTrack* aodTrack1 = dynamic_cast<AliAODTrack *>(fAOD->GetTrack(j));
472       
473       if(!aodTrack1) {
474         AliError(Form("ERROR: Could not retrieve AODtrack %d",j));
475         continue;
476       }
477       
478       
479       if(!aodTrack1->TestFilterBit(fAODtrackCutBit)) continue;
480       
481       Int_t gID = aodTrack1->GetID();
482       
483       //if( aodTrack->GetID() != (-aodTrack1->GetID() -1) ) continue;
484       newAodTrack = gID >= 0 ? aodTrack1 : fAOD->GetTrack(trackMap->GetValue(-1-gID)); //Take those global track who corresponds to TPC only track
485       
486       Float_t dxy = 0., dz = 0.;
487       
488       dxy = aodTrack1->DCA();
489       dz  = aodTrack1->ZAtDCA();
490       
491       Double_t pt = aodTrack1->Pt();
492       Double_t eta = aodTrack1->Eta();
493       Double_t nclus = aodTrack1->GetTPCClusterInfo(2,1);
494       Double_t chi2ndf = aodTrack1->Chi2perNDF();
495       
496       /* 
497       if( fabs(dxy) > fDCAxy ) continue; 
498       if( fabs(dz) > fDCAz ) continue;
499       //Extra cut on DCA---( Similar to BF Task.. )           
500       if( fDCAxy !=0 && fDCAz !=0 ){
501         if( TMath::Sqrt((dxy*dxy)/(fDCAxy*fDCAxy)+(dz*dz)/(fDCAz*fDCAz)) > 1. ) continue;
502       }
503       */
504       if( pt < fPtLowerLimit || pt > fPtHigherLimit ) continue;
505       if( eta < fEtaLowerLimit || eta > fEtaHigherLimit ) continue;
506       if( nclus < fTPCNClus ) continue;
507       if( chi2ndf > fChi2perNDF ) continue;
508       
509       
510       fHistQA[6]->Fill(dxy);
511       fHistQA[7]->Fill(dz);
512       fHistQA[8]->Fill(pt);
513       fHistQA[9]->Fill(eta);
514       fHistQA[10]->Fill(aodTrack1->Phi());
515       fHistQA[11]->Fill(nclus);
516       fHistQA[12]->Fill(chi2ndf);
517       fHistDCA->Fill(dxy,dz);
518       
519       Short_t gCharge = aodTrack1->Charge();
520       
521       if(gCharge > 0) nPlusCharge += 1.;
522       if(gCharge < 0) nMinusCharge += 1.;
523       
524       if( fUsePid ) {
525         
526         gPid = (Int_t)fParticleSpecies;
527
528         Double_t rap =  newAodTrack->Y(AliPID::ParticleMass(fParticleSpecies));
529         Double_t tpcSignal = newAodTrack->GetTPCsignal();
530         //Double_t rap =  aodTrack1->Y(AliPID::ParticleMass(fParticleSpecies));
531         //Double_t tpcSignal = aodTrack1->GetTPCsignal();
532         
533         if( fabs(rap ) > fRapidityCut ) continue;//Rapidity cut
534         
535         fTPCSig->Fill(newAodTrack->GetTPCmomentum(),tpcSignal);
536         
537         Float_t nsigmaTPCPID = -999.;
538         //Float_t nsigmaTOFPID = -999.;
539         //Float_t nsigmaTPCTOFPID = -999.;
540         
541         nsigmaTPCPID = TMath::Abs(fPIDResponse->NumberOfSigmasTPC(newAodTrack,fParticleSpecies));
542         //nsigmaTOFPID = TMath::Abs(fPIDResponse->NumberOfSigmasTOF(newAodTrack,fParticleSpecies));
543         
544         if ( nsigmaTPCPID < fNSigmaCut  ){
545           
546           if (gCharge > 0) nPartile +=1.;
547           if( gCharge < 0 ) nAntiParticle +=1.;
548           
549         }
550       }//fUsepid-----
551       
552     }//--------- Track Loop to select with filterbit
553   
554   
555   
556   Double_t fContainerCh[3] = { static_cast<Double_t>(fCentrality), nPlusCharge, nMinusCharge};
557   Double_t fContainerPid[3] = { static_cast<Double_t>(fCentrality), nPartile, nAntiParticle};
558   
559   if( fUsePid ){
560     
561     fTHnCentNplusNminusPid[gPid]->Fill(fContainerPid);
562     
563     // cout << "nCentrality "<< fCentrality <<", nParticle="<< nPartile << ", nMinusParticle=" << nAntiParticle << endl;
564   }
565   else{
566     
567     fTHnCentNplusNminusCh->Fill(fContainerCh);
568   }               
569   
570   //cout << "nCentrality "<< fCentrality <<", nPlusCharge="<< nPlusCharge << ", nMinusCharge=" << nMinusCharge << endl;
571   
572   fEventCounter->Fill(7);
573   
574   return;
575   
576 }
577 //--------------------------------------------------------------------------------------
578
579
580 //--------------------------------------------------------------------------------------
581 void AliEbyEHigherMomentsEffContTask::doMCAODEvent(){
582   
583   
584   //---------
585   Double_t nPlusCharge = 0.;
586   Double_t nMinusCharge = 0.;
587   Double_t nPartile = 0.;
588   Double_t nAntiParticle = 0.;
589   Int_t gPid = 0;
590   
591   //Connect to Anlaysis manager------
592   AliAnalysisManager* manager = AliAnalysisManager::GetAnalysisManager();
593   if (!manager) {
594     cout<<"ERROR: Analysis manager not found."<<endl;
595     return;
596   }
597   
598   AliAODInputHandler* inputHandler = dynamic_cast<AliAODInputHandler*> (manager->GetInputEventHandler());
599   if (!inputHandler) {
600     cout<<"ERROR: Input handler not found."<<endl;
601     return;
602   }
603   
604   //AOD event------
605   fAOD = dynamic_cast<AliAODEvent*>(InputEvent());
606   if (!fAOD)
607     {
608       cout<< "ERROR 01: AOD not found " <<endl;
609       return;
610     }
611   
612   fPIDResponse =inputHandler->GetPIDResponse();
613   
614   
615   if (!fPIDResponse){
616     AliFatal("This Task needs the PID response attached to the inputHandler");
617     return;
618   }  
619   // -- Get MC header
620   // ------------------------------------------------------------------
621   
622   fArrayMC = (TClonesArray*) fAOD->GetList()->FindObject(AliAODMCParticle::StdBranchName());
623   if (!fArrayMC) {
624     AliFatal("Error: MC particles branch not found!\n");
625   }
626   
627   AliAODMCHeader *mcHdr=NULL;
628   mcHdr=(AliAODMCHeader*)fAOD->GetList()->FindObject(AliAODMCHeader::StdBranchName());  
629   if(!mcHdr) {
630     printf("MC header branch not found!\n");
631     return;
632   }
633   
634   AliAODHeader *aodHeader = dynamic_cast<AliAODHeader*>(fAOD->GetHeader());
635   if(!aodHeader) AliFatal("Not a standard AOD");
636   
637   Int_t cent = -1;
638   cent =  aodHeader->GetCentralityP()->GetCentralityClass10(fCentralityEstimator.Data());
639   
640   if (cent == 0)
641     fCentrality = aodHeader->GetCentralityP()->GetCentralityClass5(fCentralityEstimator.Data());
642   else if (cent == 10 || cent == -1.)
643     fCentrality = -1;
644   else if (cent > 0 && cent < 9)
645     fCentrality = cent + 1;
646   
647   if( fCentrality < 0 || fCentrality >= 10) return;
648   
649   fEventCounter->Fill(2);
650   
651   
652   
653   if(!ProperVertex()) return;   
654   
655   Int_t nTracks = fAOD->GetNumberOfTracks();
656   
657   //Creat Lables ---
658   fLabel = new Int_t*[2];
659   fLabel[0] = new Int_t[nTracks]; //All charged hadrons----
660   fLabel[1] = new Int_t[nTracks]; //For Pid-----------
661   //Initialize labels----
662   
663   if(!fLabel[0]){
664     AliError("Can't Get fLabel[0] ");
665     return;
666   }
667   if(!fLabel[1]){
668     AliError("Can't Get fLabel[1] "); 
669     return; 
670   }
671   
672   for(Int_t i=0; i < 2; i++){
673     for(Int_t j=0; j < nTracks; j++){
674       fLabel[i][j] = 0;
675     }
676   }   
677   
678   
679   TExMap *trackMap = new TExMap();//Mapping matrix----
680   
681   for(Int_t i = 0; i < nTracks; i++) {
682     
683     AliAODTrack* aodTrack = dynamic_cast<AliAODTrack *>(fAOD->GetTrack(i)); 
684     
685     if(!aodTrack) {
686       AliError(Form("ERROR: Could not retrieve AODtrack %d",i));
687       continue;
688     }
689     
690     Double_t tpcSignalAll = aodTrack->GetTPCsignal();
691     fTPCSigA->Fill(aodTrack->GetTPCmomentum(),tpcSignalAll);
692     
693     Int_t gID = aodTrack->GetID();
694     
695     if (aodTrack->TestFilterBit(1)) trackMap->Add(gID, i);//Global tracks-----
696     
697   }//1st track loop----
698   
699   AliAODTrack* newAodTrack; 
700   
701   for( Int_t j = 0; j < nTracks; j++ ){
702     
703     AliAODTrack* aodTrack1 = dynamic_cast<AliAODTrack *>(fAOD->GetTrack(j));
704     
705     if(!aodTrack1) {
706       AliError(Form("ERROR: Could not retrieve AODtrack %d",j));
707       continue;
708     }
709     
710    
711     if(!aodTrack1->TestFilterBit(fAODtrackCutBit)) continue;
712     
713     
714     Int_t gID = aodTrack1->GetID();
715     
716     //if( aodTrack->GetID() != (-aodTrack1->GetID() -1) ) continue;
717     
718     newAodTrack = gID >= 0 ? aodTrack1 : fAOD->GetTrack(trackMap->GetValue(-1-gID)); //Take those global track who corresponds to TPC only track
719     
720     Float_t dxy = 0., dz = 0.;
721     
722     dxy = aodTrack1->DCA();
723     dz  = aodTrack1->ZAtDCA();
724  
725     //cout << dxy << endl;
726     Double_t pt = aodTrack1->Pt();
727     Double_t eta = aodTrack1->Eta();
728     Double_t nclus = aodTrack1->GetTPCClusterInfo(2,1);
729     Double_t chi2ndf = aodTrack1->Chi2perNDF();
730   
731     /*  
732     if( fabs(dxy) > fDCAxy ) continue; 
733     if( fabs(dz) > fDCAz ) continue;
734     //Extra cut on DCA---( Similar to BF Task.. )             
735     if( fDCAxy !=0 && fDCAz !=0 ){
736       if( TMath::Sqrt((dxy*dxy)/(fDCAxy*fDCAxy)+(dz*dz)/(fDCAz*fDCAz)) > 1. ) continue;
737     }
738     */
739     
740
741     if( pt < fPtLowerLimit || pt > fPtHigherLimit ) continue;
742     if( eta < fEtaLowerLimit || eta > fEtaHigherLimit ) continue;
743     // if( nclus < fTPCNClus ) continue;
744     //if( chi2ndf > fChi2perNDF ) continue;
745     
746     
747     fHistQA[6]->Fill(dxy);
748     fHistQA[7]->Fill(dz);
749     fHistQA[8]->Fill(pt);
750     fHistQA[9]->Fill(eta);
751     fHistQA[10]->Fill(aodTrack1->Phi());
752     fHistQA[11]->Fill(nclus);
753     fHistQA[12]->Fill(chi2ndf);
754     fHistDCA->Fill(dxy,dz);
755     
756     Short_t gCharge = aodTrack1->Charge();
757     
758     if( gCharge == 0 ) continue;
759     
760     Int_t label  = TMath::Abs(aodTrack1->GetLabel()); 
761     //fill the labels--------
762     fLabel[0][j] = label;
763     
764     if(gCharge > 0) nPlusCharge += 1.;
765     if(gCharge < 0) nMinusCharge += 1.;
766     
767     if( fUsePid ) {
768       
769       gPid = (Int_t)fParticleSpecies;;
770       Double_t rap =  newAodTrack->Y(AliPID::ParticleMass(fParticleSpecies));
771       Double_t tpcSignal = newAodTrack->GetTPCsignal();
772    
773       if( fabs(rap ) > fRapidityCut ) continue;//Rapidity cut
774       
775       fTPCSig->Fill(newAodTrack->GetTPCmomentum(),tpcSignal);
776       
777       Float_t nsigmaTPCPID = -999.;
778       //Float_t nsigmaTOFPID = -999.;
779       //Float_t nsigmaTPCTOFPID = -999.;
780       
781       nsigmaTPCPID = TMath::Abs(fPIDResponse->NumberOfSigmasTPC(newAodTrack,fParticleSpecies));
782       //nsigmaTOFPID = TMath::Abs(fPIDResponse->NumberOfSigmasTOF(newAodTrack,fParticleSpecies));
783       
784       if ( nsigmaTPCPID < fNSigmaCut  ){
785         
786         //Fill the labels----
787         fLabel[1][j] = label;
788         
789         if (gCharge > 0) nPartile +=1.;
790         if( gCharge < 0 ) nAntiParticle +=1.;
791         
792       }
793     }//fUsepid-----
794     //Check Contamination-------------------
795     
796     if( fCheckCont ){
797       CheckContTrackAOD(label, gCharge, j);
798     }
799     
800   }//--------- Track Loop to select with filterbit
801   
802   if(fEff) FillEffSparse();
803   
804   //cout << "Cent=" << fCentrality << " MC-PlusChrg=" << nPlusCharge << " MC-MinusChrg=" << nMinusCharge << endl;
805   
806   //cout << "nCentrality "<< fCentrality <<", nParticle="<< nPartile << ", nMinusParticle=" << nAntiParticle << endl; 
807   
808   Double_t fContainerCh[3] = { static_cast<Double_t>(fCentrality), nPlusCharge, nMinusCharge};
809   Double_t fContainerPid[3] = { static_cast<Double_t>(fCentrality), nPartile, nAntiParticle};
810   
811   if( fUsePid ){
812     
813     fTHnCentNplusNminusPid[gPid]->Fill(fContainerPid);
814     
815   }
816   else{
817     
818     fTHnCentNplusNminusCh->Fill(fContainerCh);
819   }               
820   
821   fEventCounter->Fill(7);
822
823   return;
824   
825 }
826 //---------------------------------------------------------------------------------------
827
828 //---------------------------------------------------------------------------------------
829 Bool_t AliEbyEHigherMomentsEffContTask::ProperVertex(){
830   
831   Bool_t IsVtx = kFALSE;
832   
833   const AliAODVertex *vertex = fAOD->GetPrimaryVertex();
834   
835   if(vertex) {
836     Double32_t fCov[6];
837     vertex->GetCovarianceMatrix(fCov);
838     if(vertex->GetNContributors() > 0) {
839       if(fCov[5] != 0) {
840         
841         Double_t lvx = vertex->GetX();
842         Double_t lvy = vertex->GetY();
843         Double_t lvz = vertex->GetZ();
844         
845         fEventCounter->Fill(5);
846         
847         fHistQA[3]->Fill(lvx);fHistQA[4]->Fill(lvy);fHistQA[5]->Fill(lvz);
848         
849         if(TMath::Abs(lvx) < fVxMax) {
850           if(TMath::Abs(lvy) < fVyMax) {
851             if(TMath::Abs(lvz) < fVzMax) {
852               
853               fEventCounter->Fill(6);
854               fHistQA[0]->Fill(lvx);fHistQA[1]->Fill(lvy);fHistQA[2]->Fill(lvz);
855               
856               IsVtx = kTRUE; 
857               
858             }//Z-Vertex cut---
859           }//Y-vertex cut--
860         }//X-vertex cut---
861       }//Covariance------
862     }//Contributors check---
863   }//If vertex-----------
864   
865   return IsVtx;
866 }
867 //---------------------------------------------------------------------------------------
868
869 //---------------------------------------------------------------------------------------
870 void AliEbyEHigherMomentsEffContTask::FillEffSparse(){
871
872   //For Efficiency-------------------------------------
873  
874   Int_t nTracks = fAOD->GetNumberOfTracks();
875   Int_t gPdgCode = AliPID::ParticleCode(fParticleSpecies);
876   
877   Int_t nMCTrack = fArrayMC->GetEntriesFast();
878   
879   
880   for (Int_t iMC = 0; iMC < nMCTrack; iMC++) {
881     
882     AliAODMCParticle *partMC = (AliAODMCParticle*) fArrayMC->At(iMC);
883
884     if(!partMC){
885       AliError(Form("ERROR: Could not retrieve AODMCtrack %d",iMC));
886       continue;
887     }
888     
889     /* TDatabasePDG *db = TDatabasePDG::Instance();
890     TParticlePDG *part = 0x0;
891     
892     if (!(part = db->GetParticle(partMC->PdgCode()))) continue;
893     if ((part = db->GetParticle(partMC->PdgCode()))->Charge() == 0.0) continue;
894     */
895     if(!(partMC->PdgCode())) continue;
896     if(partMC->Charge() == 0) continue;
897     //-(1) Check for primary----
898     if(!partMC->IsPhysicalPrimary()) continue;
899
900     //-(2) Basic track cuts--------
901     
902     if (partMC->Eta() < fEtaLowerLimit || partMC->Eta() > fEtaHigherLimit) continue;
903     if (partMC->Pt() < fPtLowerLimit ||  partMC->Pt() > fPtHigherLimit) continue;
904     
905     Double_t rap =  partMC->Y();
906     
907     if( fabs(rap ) > fRapidityCut ) continue;//Rapidity cut
908     
909     if(TMath::Abs(partMC->GetPdgCode()) != gPdgCode) continue;
910     
911     Short_t gCharge = partMC->Charge();
912
913     Float_t sign      = (gCharge < 0 ) ? -1. : 1.;
914     
915     Float_t findable  = 1.;// Float_t(fHelper->IsParticleFindable(idxMC)); XXX
916     
917     // (3) Initialize rec. variables-----
918     Float_t recStatus = 0.;
919     Float_t recPid    = 0.;
920     // (4) Initialize track parameters------
921     Float_t etaRec = 0.;
922     Float_t phiRec = 0.;
923     Float_t ptRec  = 0.;
924     
925     
926     
927     // (5) Loop over all Labels--------
928     
929     
930     for( Int_t iRec = 0; iRec < nTracks; iRec++ ){
931       
932       if( iMC != fLabel[0][iRec] ) continue;
933       else{
934         recStatus = 1.;
935         if( iMC == fLabel[1][iRec] )
936           recPid = 1.;
937          
938           AliAODTrack* aodTrack = NULL;
939           
940           if(fAOD)
941             
942             aodTrack = fAOD->GetTrack(iRec);
943           
944           if(aodTrack){
945             
946             etaRec = aodTrack->Eta();
947             phiRec = aodTrack->Phi();     
948             ptRec  = aodTrack->Pt();
949             
950           }//aodTrack
951           
952           break;
953       }
954       
955       
956       
957     }//all charged track rec. check---
958     
959     
960     //Fill ThnSparse----
961     
962     Double_t EffContainer[15] = {static_cast<Double_t>(fCentrality), partMC->Eta(), partMC->Y(), partMC->Phi(), partMC->Pt(), static_cast<Double_t>(sign),static_cast<Double_t>(findable), static_cast<Double_t>(recStatus), static_cast<Double_t>(recPid), static_cast<Double_t>(etaRec), static_cast<Double_t>(phiRec), static_cast<Double_t>(ptRec), partMC->Eta()-etaRec, partMC->Phi()-phiRec, partMC->Pt()-ptRec};
963     
964     fTHnEff->Fill(EffContainer);   
965     
966   }//iMC Track loop-----
967   
968   return;
969 }
970 //---------------------------------------------------------------------------------------
971
972 //---------------------------------------------------------------------------------------
973 void AliEbyEHigherMomentsEffContTask::CheckContTrackAOD(Int_t label, Float_t sign, Int_t idxTrack){
974
975   AliAODMCParticle* particle = (AliAODMCParticle*)fArrayMC->At(label);
976   
977   if (!particle)
978     return;
979   
980   Int_t gPdgCode = AliPID::ParticleCode(fParticleSpecies);
981   Bool_t isSecondaryFromWeakDecay = kFALSE;
982   Bool_t isSecondaryFromMaterial  = kFALSE;
983   
984   // -- Check if correctly identified 
985   if (particle->GetPdgCode() == (sign*gPdgCode)) {
986     
987     // Check if is physical primary -> all ok 
988     if(particle->IsPhysicalPrimary())
989       return;
990     
991     // -- Check if secondaries from material or weak decay
992     isSecondaryFromWeakDecay = particle->IsSecondaryFromWeakDecay();
993     isSecondaryFromMaterial  = particle->IsSecondaryFromMaterial();
994     
995   } 
996   
997   // -- Get MC pdg 
998   Float_t contSign = 0.;
999   
1000   // TDatabasePDG *db = TDatabasePDG::Instance();
1001   //TParticlePDG *part = 0x0;
1002   /* 
1003      if(( part = db->GetParticle(particle->PdgCode()))->Charge() == 0.) contSign =  0.;
1004      else if((part = db->GetParticle(particle->PdgCode()))->Charge() <  0.) contSign = -1.;     
1005      else if((part = db->GetParticle(particle->PdgCode()))->Charge() >  0.) contSign =  1.;     
1006   */  
1007   
1008   if(particle->Charge() == 0.) contSign =  0.;
1009   if(particle->Charge() < 0. ) contSign = -1;
1010   if(particle->Charge() > 0. ) contSign = 1.;
1011   
1012   // -- Get contaminating particle
1013   Float_t contPart = 0;
1014   if        (isSecondaryFromWeakDecay)                   contPart = 7; // probeParticle from WeakDecay
1015   else if   (isSecondaryFromMaterial)                    contPart = 8; // probeParticle from Material
1016   else {
1017     if      (TMath::Abs(particle->GetPdgCode()) ==  211) contPart = 1; // pion
1018     else if (TMath::Abs(particle->GetPdgCode()) ==  321) contPart = 2; // kaon
1019     else if (TMath::Abs(particle->GetPdgCode()) == 2212) contPart = 3; // proton
1020     else if (TMath::Abs(particle->GetPdgCode()) ==   11) contPart = 4; // electron
1021     else if (TMath::Abs(particle->GetPdgCode()) ==   13) contPart = 5; // muon
1022     else                                                 contPart = 6; // other
1023   }
1024   
1025   // -- Get Reconstructed values 
1026   Float_t etaRec = 0.;
1027   Float_t phiRec = 0.;
1028   Float_t ptRec  = 0.;
1029
1030   AliAODTrack* aodTrack = dynamic_cast<AliAODTrack *>(fAOD->GetTrack(idxTrack));
1031   
1032   if (aodTrack) {
1033     // if no track present (which should not happen)
1034     // -> pt = 0. , which is not in the looked at range
1035     
1036     // -- Get Reconstructed eta/phi/pt
1037     etaRec = aodTrack->Eta();
1038     phiRec = aodTrack->Phi();     
1039     ptRec  = aodTrack->Pt();
1040   }     
1041   
1042   // -- Fill THnSparse
1043   Double_t ContContainer[14] = { static_cast<Double_t>(fCentrality), particle->Eta(), particle->Y(), particle->Phi(), particle->Pt(), static_cast<Double_t>(sign), static_cast<Double_t>(contPart), static_cast<Double_t>(contSign), static_cast<Double_t>(etaRec), static_cast<Double_t>(phiRec), static_cast<Double_t>(ptRec), particle->Eta()-etaRec, particle->Phi()-phiRec, particle->Pt()-ptRec };
1044   
1045   fTHnCont->Fill(ContContainer);
1046   
1047   return;
1048   
1049 }
1050 //------------------------------------------------------------------------
1051 void AliEbyEHigherMomentsEffContTask::Terminate( Option_t * ){
1052   
1053   Info("AliEbyEHigherMomentsEffContTask"," Task Successfully finished");
1054   
1055 }
1056
1057 //------------------------------------------------------------------------