1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: Satyajit Jena. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 //=========================================================================//
19 // Analysis Task for Net-Charge Higher Moment Analysis //
20 // Author: Satyajit Jena || Nirbhay K. Behera //
21 // sjena@cern.ch || nbehera@cern.ch //
23 //=========================================================================//
31 #include "THnSparse.h"
34 #include "AliAnalysisTaskSE.h"
35 #include "AliAnalysisManager.h"
36 #include "AliAODEvent.h"
37 #include "AliVTrack.h"
38 #include "AliAODTrack.h"
39 #include "AliAODInputHandler.h"
40 #include "AliAODEvent.h"
42 #include "AliAODMCHeader.h"
43 #include "AliAODMCParticle.h"
44 #include "AliMCEventHandler.h"
45 #include "AliMCEvent.h"
47 #include "AliGenHijingEventHeader.h"
48 #include "AliGenEventHeader.h"
50 #include "AliAODPid.h"
51 #include "AliPIDResponse.h"
52 #include "AliAODpidUtil.h"
53 #include "AliPIDCombined.h"
54 #include "AliHelperPID.h"
56 #include "AliEbyEHigherMomentsTaskPID.h"
61 ClassImp(AliEbyEHigherMomentsTaskPID)
64 //-----------------------------------------------------------------------
65 AliEbyEHigherMomentsTaskPID::AliEbyEHigherMomentsTaskPID( const char *name )
66 : AliAnalysisTaskSE( name ),
70 fParticleSpecies(AliPID::kProton),
72 fCentralityEstimator("V0M"),
89 fTHnCentNplusNminusPid(0),
90 fTHnCentNplusNminusPidTruth(0),
91 fPtBinNplusNminusPid(0),
92 fPtBinNplusNminusPidTruth(0)
95 for ( Int_t i = 0; i < 4; i++) {
99 DefineOutput(1, TList::Class()); // Outpput...
102 AliEbyEHigherMomentsTaskPID::~AliEbyEHigherMomentsTaskPID(){
104 if(fListOfHistos) delete fListOfHistos;
105 if(fHelperPID) delete fHelperPID;
108 //---------------------------------------------------------------------------------
109 void AliEbyEHigherMomentsTaskPID::UserCreateOutputObjects() {
111 fListOfHistos = new TList();
112 fListOfHistos->SetOwner(kTRUE);
114 fEventCounter = new TH1D("fEventCounter","EventCounter", 10, 0.5,10.5);
115 fEventCounter->GetXaxis()->SetBinLabel(1,"Event Accesed");
116 fEventCounter->GetXaxis()->SetBinLabel(2,"Within 0-80% centrality");
117 fEventCounter->GetXaxis()->SetBinLabel(5,"Have a vertex");
118 fEventCounter->GetXaxis()->SetBinLabel(6,"After vertex Cut");
119 fEventCounter->GetXaxis()->SetBinLabel(7,"Event Analyzed");
120 fListOfHistos->Add(fEventCounter);
123 fHistQA[0] = new TH1D("fHistQAvz", "Histo Vz After Cut", 500, -25., 25.);
124 fHistQA[1] = new TH1D("fHistQAPt","p_{T} distribution",600,0,6);
125 fHistQA[2] = new TH1D("fHistQAEta","#eta distribution",240,-1.2,1.2);
126 fHistQA[3] = new TH1D("fHistQAPhi","#phi distribution",340,0,6.8);
128 for(Int_t i = 0; i < 4; i++)
130 fListOfHistos->Add(fHistQA[i]);
133 fHistVxVy = new TH2D("fHistVxVy","Vertex-x Vs Vertex-y", 200, -1., 1., 200, -1., 1.);
134 fListOfHistos->Add(fHistVxVy);
137 const Int_t nDim = 3;
138 const Int_t nPid = 5;
139 TString Species[nPid] = {"Electron","Muon","Pion","Kaon","Proton"};
141 Int_t fBins[nPid][nDim];
142 Double_t fMin[nPid][nDim];
143 Double_t fMax[nPid][nDim];
145 for( Int_t i = 0; i < nPid; i++ ){
146 for( Int_t j = 0; j < nDim; j++ ){
154 const Int_t dim = fNptBins*2 + 1;
155 Int_t bin[nPid][dim];
156 Double_t min[nPid][dim];
157 Double_t max[nPid][dim];
159 bin[2][0] = 100; min[2][0] = -0.5; max[2][0] = 99.5;
160 bin[3][0] = 100; min[3][0] = -0.5; max[3][0] = 99.5;
161 bin[4][0] = 100; min[4][0] = -0.5; max[4][0] = 99.5;
163 for(Int_t i = 1; i < dim; i++){
184 TString hname1, hname11;
185 TString htitle1, axisTitle1, axisTitle2;
187 Int_t gPid = (Int_t)fParticleSpecies;
190 fBins[2][0] = 100; fBins[2][1] = 1000; fBins[2][2] = 1000;
191 fMin[2][0] = -0.5; fMin[2][1] = -0.5; fMin[2][2] = -0.5;
192 fMax[2][0] = 99.5; fMax[2][1] = 999.5; fMax[2][2] = 999.5;
194 fBins[3][0] = 100; fBins[3][1] = 700; fBins[3][2] = 700;
195 fMin[3][0] = -0.5; fMin[3][1] = -0.5; fMin[3][2] = -0.5;
196 fMax[3][0] = 99.5; fMax[3][1] = 699.5; fMax[3][2] = 699.5;
198 fBins[4][0] = 100; fBins[4][1] = 400; fBins[4][2] = 400;
199 fMin[4][0] = -0.5; fMin[4][1] = -0.5; fMin[4][2] = -0.5;
200 fMax[4][0] = 99.5; fMax[4][1] = 399.5; fMax[4][2] = 399.5;
202 hname1 = "fCentNplusNminusPid"; hname1 +=gPid;
203 htitle1 = Species[gPid]; htitle1 +=" And Neg-"; htitle1 +=Species[gPid];
204 axisTitle1 ="Pos-"; axisTitle1 += Species[gPid];
205 axisTitle2 ="Neg-"; axisTitle2 += Species[gPid];
207 fTHnCentNplusNminusPid = new THnSparseD(hname1.Data(),htitle1.Data(), nDim, fBins[gPid], fMin[gPid],fMax[gPid]);
209 fTHnCentNplusNminusPid->GetAxis(0)->SetTitle("Centrality");
210 fTHnCentNplusNminusPid->GetAxis(1)->SetTitle(axisTitle1.Data());
211 fTHnCentNplusNminusPid->GetAxis(2)->SetTitle(axisTitle2.Data());
212 fListOfHistos->Add(fTHnCentNplusNminusPid);
214 TString hname2 = "fPtBinNplusNminusPid";
215 TString htitle2 = "cent-nplus-nminus-ptbinwise";
218 fPtBinNplusNminusPid = new THnSparseI(hname2.Data(),htitle2.Data(), dim, bin[gPid], min[gPid], max[gPid]);
219 fListOfHistos->Add(fPtBinNplusNminusPid);
224 if( fAnalysisType == "MCAOD" ){
226 hname11 = "fCentNplusNminusPidTruth"; hname11 +=gPid;
227 fTHnCentNplusNminusPidTruth = new THnSparseD(hname11.Data(),htitle1.Data(), nDim, fBins[gPid], fMin[gPid],fMax[gPid]);
229 fTHnCentNplusNminusPidTruth->GetAxis(0)->SetTitle("Centrality");
230 fTHnCentNplusNminusPidTruth->GetAxis(1)->SetTitle(axisTitle1.Data());
231 fTHnCentNplusNminusPidTruth->GetAxis(2)->SetTitle(axisTitle2.Data());
232 fListOfHistos->Add(fTHnCentNplusNminusPidTruth);
234 TString hname22 = "fPtBinNplusNminusPidTruth";
235 TString htitle22 = "cent-nplus-nminus-ptbinwise";
239 fPtBinNplusNminusPidTruth = new THnSparseI(hname22.Data(),htitle22.Data(), dim, bin[gPid], min[gPid], max[gPid]);
240 fListOfHistos->Add(fPtBinNplusNminusPidTruth);
244 PostData(1, fListOfHistos);
250 //----------------------------------------------------------------------------------
251 void AliEbyEHigherMomentsTaskPID::UserExec( Option_t * ){
253 fEventCounter->Fill(1);
255 if(fAnalysisType == "AOD") {
259 }//AOD--analysis-----
261 else if(fAnalysisType == "MCAOD") {
273 //--------------------------------------------------------------------------------------
274 void AliEbyEHigherMomentsTaskPID::doAODEvent(){
276 Double_t posPidSum = 0.;
277 Double_t negPidSum = 0.;
279 const Int_t dim = fNptBins*2;
282 for(Int_t idx = 0; idx < dim; idx++){
287 Int_t gPid = (Int_t)fParticleSpecies;
289 AliAnalysisManager* manager = AliAnalysisManager::GetAnalysisManager();
291 cout<<"ERROR: Analysis manager not found."<<endl;
294 //coneect to the inputHandler------------
295 AliAODInputHandler* inputHandler = dynamic_cast<AliAODInputHandler*> (manager->GetInputEventHandler());
297 cout<<"ERROR: Input handler not found."<<endl;
301 AliAODEvent *fAOD = dynamic_cast<AliAODEvent*>(InputEvent());
305 cout<< "ERROR: AOD not found " <<endl;
309 fPIDResponse = inputHandler->GetPIDResponse();
313 AliFatal("This Task needs the PID response attached to the inputHandler");
317 if(!ProperVertex(fAOD)) return;
319 AliAODHeader *aodHeader = dynamic_cast<AliAODHeader*>(fAOD->GetHeader());
320 if(!aodHeader) AliFatal("Not a standard AOD");
322 fCentrality = (Int_t)aodHeader->GetCentralityP()->GetCentralityPercentile(fCentralityEstimator.Data());
324 if(fCentrality < 0 || fCentrality >= 81) return;
326 fEventCounter->Fill(2);
328 Int_t nTracks = fAOD->GetNumberOfTracks();
330 for(Int_t i = 0; i < nTracks; i++) {
332 AliAODTrack* aodTrack = dynamic_cast<AliAODTrack *>(fAOD->GetTrack(i));
335 AliError(Form("ERROR: Could not retrieve AODtrack %d",i));
339 if(!AcceptTrack(aodTrack) ) continue;
342 fBin = GetPtBin(aodTrack->Pt());
344 Short_t gCharge = aodTrack->Charge();
347 Double_t rap = aodTrack->Y(AliPID::ParticleMass(fParticleSpecies));
348 if( fabs(rap ) > fRapidityCut ) continue;//Rapidity cut
350 Int_t PID = fHelperPID->GetParticleSpecies((AliVTrack*)aodTrack, kFALSE);
352 if( (PID+2) == gPid ){
360 PtCh[fNptBins+fBin] += 1;
366 }//--------- Track Loop to select with filterbit
369 Double_t fContainerPid[3] = { static_cast<Double_t>(fCentrality), posPidSum, negPidSum};
370 fTHnCentNplusNminusPid->Fill(fContainerPid);
372 //cout << fCentrality <<" "<< posPidSum <<" " << negPidSum << endl;
374 Double_t ptContainer[dim+1];
376 ptContainer[0] = fCentrality;
378 for(Int_t i = 1; i <= dim; i++){
379 ptContainer[i] = PtCh[i-1];
380 //cout << PtCh[i-1] <<" ,";
384 fPtBinNplusNminusPid->Fill(ptContainer);
387 fEventCounter->Fill(7);
388 PostData(1, fListOfHistos);
392 //--------------------------------------------------------------------------------------
393 //--------------------------------------------------------------------------------------
394 void AliEbyEHigherMomentsTaskPID::doMCAODEvent(){
398 Double_t posPidSumMCRec = 0.;
399 Double_t negPidSumMCRec = 0.;
401 Double_t posPidSumMCTruth = 0.;
402 Double_t negPidSumMCTruth = 0.;
404 const Int_t dim = fNptBins*2;
406 Double_t ptChMC[dim];
408 for(Int_t idx = 0; idx < dim; idx++){
414 Int_t gPid = (Int_t)fParticleSpecies;
416 Int_t gPdgCode = AliPID::ParticleCode(fParticleSpecies);
418 //Connect to Anlaysis manager------
419 AliAnalysisManager* manager = AliAnalysisManager::GetAnalysisManager();
421 cout<<"ERROR: Analysis manager not found."<<endl;
425 AliAODInputHandler* inputHandler = dynamic_cast<AliAODInputHandler*> (manager->GetInputEventHandler());
427 cout<<"ERROR: Input handler not found."<<endl;
432 AliAODEvent *fAOD = dynamic_cast<AliAODEvent*>(InputEvent());
436 cout<< "ERROR: AOD not found " <<endl;
440 fPIDResponse =inputHandler->GetPIDResponse();
444 AliFatal("This Task needs the PID response attached to the inputHandler");
449 // ------------------------------------------------------------------
451 fArrayMC = dynamic_cast<TClonesArray*>(fAOD->FindListObject(AliAODMCParticle::StdBranchName()));
453 AliFatal("Error: MC particles branch not found!\n");
457 AliAODMCHeader *mcHdr=NULL;
458 mcHdr=(AliAODMCHeader*)fAOD->GetList()->FindObject(AliAODMCHeader::StdBranchName());
460 printf("MC header branch not found!\n");
464 if(!ProperVertex(fAOD)) return;
466 AliAODHeader *aodHeader = dynamic_cast<AliAODHeader*>(fAOD->GetHeader());
467 if(!aodHeader) AliFatal("Not a standard AOD");
469 fCentrality = (Int_t)aodHeader->GetCentralityP()->GetCentralityPercentile(fCentralityEstimator.Data());
471 if( fCentrality < 0 || fCentrality >= 81) return;
473 fEventCounter->Fill(2);
475 Int_t nTracks = fAOD->GetNumberOfTracks();
477 for(Int_t i = 0; i < nTracks; i++) {
479 AliAODTrack* aodTrack = dynamic_cast<AliAODTrack *>(fAOD->GetTrack(i));
482 AliError(Form("ERROR: Could not retrieve AODtrack %d",i));
486 if(!AcceptTrack(aodTrack) ) continue;
488 fBin = GetPtBin(aodTrack->Pt());
490 //cout << "Pt Bin " << fBin << endl;
492 Short_t gCharge = aodTrack->Charge();
494 Double_t rap = aodTrack->Y(AliPID::ParticleMass(fParticleSpecies));
495 if( fabs(rap ) > fRapidityCut ) continue;//Rapidity cut
497 Int_t PID = fHelperPID->GetParticleSpecies((AliVTrack*)aodTrack, kFALSE);
499 if( (PID+2) == gPid ){
505 negPidSumMCRec += 1.;
506 PtCh[fNptBins+fBin] += 1;
510 }//--------- Track Loop to select with filterbit
512 //===============================================================================
513 //---------------------MC Truth--------------------------------------------------
514 //===============================================================================
516 Int_t nMCTrack = fArrayMC->GetEntriesFast();
518 for (Int_t iMC = 0; iMC < nMCTrack; iMC++) {
520 AliAODMCParticle *partMC = (AliAODMCParticle*) fArrayMC->At(iMC);
523 AliError(Form("ERROR: Could not retrieve AODMCtrack %d",iMC));
527 if(partMC->Charge() == 0) continue;
528 if(!partMC->IsPhysicalPrimary()) continue;
530 if (partMC->Eta() < fEtaLowerLimit || partMC->Eta() > fEtaHigherLimit) continue;
531 if (partMC->Pt() < fPtLowerLimit || partMC->Pt() > fPtHigherLimit) continue;
533 Short_t gCharge = partMC->Charge();
534 Int_t mcbin = GetPtBin(partMC->Pt());
536 Double_t rap = partMC->Y();
537 if( fabs(rap ) > fRapidityCut ) continue;//Rapidity cut
538 if(TMath::Abs(partMC->GetPdgCode()) != gPdgCode) continue;
541 posPidSumMCTruth += 1.;
545 negPidSumMCTruth += 1.;
546 ptChMC[fNptBins+mcbin] += 1;
550 }//MC-Truth Track loop--
553 //cout << fCentrality << " " << positiveSumMCRec << " " << negativeSumMCRec <<endl;
554 //cout <<" " << positiveSumMCTruth << " " << negativeSumMCTruth << endl;
555 //cout <<fCentrality<<" " << posPidSumMCRec << " " << negPidSumMCRec << endl;
556 //cout <<fCentrality<<" " << posPidSumMCTruth << " " << negPidSumMCTruth << endl;
557 //cout <<"---------------------------------" << endl;
559 Double_t fContainerPid[3] = { static_cast<Double_t>(fCentrality), posPidSumMCRec, negPidSumMCRec};//Reco.
560 Double_t fContainerPidTruth[3] = { static_cast<Double_t>(fCentrality), posPidSumMCTruth, negPidSumMCTruth};
562 fTHnCentNplusNminusPid->Fill(fContainerPid);//Fill the rec. pid tracks
563 fTHnCentNplusNminusPidTruth->Fill(fContainerPidTruth);//MC-Truth pid
565 Double_t ptContainer[dim+1];
566 Double_t ptContainerMC[dim+1];
567 ptContainer[0] = fCentrality;
568 ptContainerMC[0] = fCentrality;
570 for(Int_t i = 1; i <= dim; i++){
571 ptContainer[i] = PtCh[i-1];
572 ptContainerMC[i] = ptChMC[i-1];
573 //cout <<" "<< PtCh[i-1]<<endl;
574 //cout<< " Rec=" << PtCh[i-1];
579 fPtBinNplusNminusPid->Fill(ptContainer);
580 fPtBinNplusNminusPidTruth->Fill(ptContainerMC);
582 fEventCounter->Fill(7);
583 PostData(1, fListOfHistos);
588 //---------------------------------------------------------------------------------------
589 Bool_t AliEbyEHigherMomentsTaskPID::ProperVertex(AliAODEvent *fAOD) const{
591 Bool_t IsVtx = kFALSE;
593 const AliAODVertex *vertex = fAOD->GetPrimaryVertex();
597 vertex->GetCovarianceMatrix(fCov);
598 if(vertex->GetNContributors() > 0) {
601 Double_t lvx = vertex->GetX();
602 Double_t lvy = vertex->GetY();
603 Double_t lvz = vertex->GetZ();
605 fEventCounter->Fill(5);
607 if(TMath::Abs(lvx) < fVxMax) {
608 if(TMath::Abs(lvy) < fVyMax) {
609 if(TMath::Abs(lvz) < fVzMax) {
611 fEventCounter->Fill(6);
612 fHistQA[0]->Fill(lvz);
613 fHistVxVy->Fill(lvx,lvy);
620 }//Contributors check---
621 }//If vertex-----------
623 AliCentrality *centrality = fAOD->GetCentrality();
624 if (centrality->GetQuality() != 0) IsVtx = kFALSE;
628 //---------------------------------------------------------------------------------------
630 //---------------------------------------------------------------------------------------
631 Bool_t AliEbyEHigherMomentsTaskPID::AcceptTrack(AliAODTrack* track) const{
633 if(!track) return kFALSE;
634 if( track->Charge() == 0 ) return kFALSE;
636 Double_t pt = track->Pt();
637 Double_t eta = track->Eta();
638 if(!track->TestFilterBit(fAODtrackCutBit)) return kFALSE;
639 if( pt < fPtLowerLimit || pt > fPtHigherLimit ) return kFALSE;
640 if( eta < fEtaLowerLimit || eta > fEtaHigherLimit ) return kFALSE;
642 fHistQA[1]->Fill(pt);
643 fHistQA[2]->Fill(eta);
644 fHistQA[3]->Fill(track->Phi());
648 //------------------------------------------------------------------------
650 //------------------------------------------------------------------------
651 Int_t AliEbyEHigherMomentsTaskPID::GetPtBin(Double_t pt){
655 Double_t BinSize = (fPtHigherLimit - fPtLowerLimit)/fNptBins;
657 for(Int_t iBin = 0; iBin < fNptBins; iBin++){
659 Double_t xLow = fPtLowerLimit + iBin*BinSize;
660 Double_t xHigh = fPtLowerLimit + (iBin+1)*BinSize;
662 if( pt >= xLow && pt < xHigh){
664 //cout << "Pt Bin #" << bin <<"pt=" << pt << endl;
673 //------------------------------------------------------------------------
674 //------------------------------------------------------------------------
675 void AliEbyEHigherMomentsTaskPID::Terminate( Option_t * ){
677 Info("AliEbyEHigherMomentTask"," Task Successfully finished");
681 //------------------------------------------------------------------------