]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWGJE/AliPWG4HighPtSpectra.cxx
- update list of libraries with those for the EMCAL jet framework
[u/mrichter/AliRoot.git] / PWGJE / AliPWG4HighPtSpectra.cxx
index 403842b2ae8c2923cbb8685e0bfbbbf021b993b2..ec6a5c8fd563b779395aebaa1473ab1c1af9eb06 100644 (file)
 
 #include "AliAnalysisManager.h"
 #include "AliESDInputHandler.h"
+#include "AliAODInputHandler.h"
 #include "AliESDtrack.h"
+#include "AliAODTrack.h"
+#include "AliAODMCParticle.h"
 #include "AliESDtrackCuts.h"
 #include "AliExternalTrackParam.h"
 #include "AliCentrality.h"
@@ -56,6 +59,8 @@
 #include "AliGenPythiaEventHeader.h"
 #include "AliGenHijingEventHeader.h"
 #include "AliGenCocktailEventHeader.h"
+#include "AliAODMCHeader.h"
+#include "AliESDVertex.h"
 //#include "$ALICE_ROOT/PWG4/JetTasks/AliAnalysisHelperJetTasks.h"
 
 //#include <iostream>
@@ -66,11 +71,14 @@ ClassImp(AliPWG4HighPtSpectra)
 //__________________________________________________________________________
 AliPWG4HighPtSpectra::AliPWG4HighPtSpectra() : AliAnalysisTask("AliPWG4HighPtSpectra", ""), 
   fReadAODData(0),
+  fNoPythiaInfo(0),
   fCFManagerPos(0x0),
   fCFManagerNeg(0x0),
   fESD(0x0),
+  fAOD(0x0),
   fMC(0x0),
   fStack(0x0),
+  fArrayMCAOD(0x0),
   fVtx(0x0),
   fTriggerMask(AliVEvent::kMB),
   fIsPbPb(0),
@@ -78,6 +86,7 @@ AliPWG4HighPtSpectra::AliPWG4HighPtSpectra() : AliAnalysisTask("AliPWG4HighPtSpe
   fTrackType(0),
   fTrackCuts(0x0),
   fTrackCutsReject(0x0),
+  fFilterMask(0),
   fbSelectHIJING(kFALSE),
   fSigmaConstrainedMax(100.),
   fAvgTrials(1),
@@ -97,15 +106,19 @@ AliPWG4HighPtSpectra::AliPWG4HighPtSpectra() : AliAnalysisTask("AliPWG4HighPtSpe
   //Default ctor
   //
 }
+
 //___________________________________________________________________________
 AliPWG4HighPtSpectra::AliPWG4HighPtSpectra(const Char_t* name) :
   AliAnalysisTask(name,""),
   fReadAODData(0),
+  fNoPythiaInfo(0),
   fCFManagerPos(0x0),
   fCFManagerNeg(0x0),
   fESD(0x0),
+  fAOD(0x0),
   fMC(0x0),
   fStack(0x0),
+  fArrayMCAOD(0x0),
   fVtx(0x0),
   fTriggerMask(AliVEvent::kMB),
   fIsPbPb(0),
@@ -113,6 +126,7 @@ AliPWG4HighPtSpectra::AliPWG4HighPtSpectra(const Char_t* name) :
   fTrackType(0),
   fTrackCuts(0x0),
   fTrackCutsReject(0x0),
+  fFilterMask(0),
   fbSelectHIJING(kFALSE),
   fSigmaConstrainedMax(100.),
   fAvgTrials(1),
@@ -166,14 +180,24 @@ void AliPWG4HighPtSpectra::ConnectInputData(Option_t *)
     return;
   }
 
-  AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
-
-  if (!esdH) {
-    AliDebug(2,Form("ERROR: Could not get ESDInputHandler"));
-    return;
-  } else
-    fESD = esdH->GetEvent();
+  if(fReadAODData) {
+    AliAODInputHandler *aodH = dynamic_cast<AliAODInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
+  
+    if (!aodH) {
+      AliDebug(2,Form("ERROR: Could not get AODInputHandler"));
+      return;
+    } else
+      fAOD = aodH->GetEvent();
+  } else {
+    AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
   
+    if (!esdH) {
+      AliDebug(2,Form("ERROR: Could not get ESDInputHandler"));
+      return;
+    } else
+      fESD = esdH->GetEvent();
+  }
+
   AliMCEventHandler *eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
   if (!eventHandler) {
     AliDebug(2,Form( "ERROR: Could not retrieve MC event handler \n"));
@@ -184,7 +208,8 @@ void AliPWG4HighPtSpectra::ConnectInputData(Option_t *)
 }
 
 //________________________________________________________________________
-Bool_t AliPWG4HighPtSpectra::SelectEvent() {
+Bool_t AliPWG4HighPtSpectra::SelectEvent()
+{
   //
   // Decide if event should be selected for analysis
   //
@@ -198,10 +223,10 @@ Bool_t AliPWG4HighPtSpectra::SelectEvent() {
 
   Bool_t selectEvent = kTRUE;
 
-  //fESD object available?
-  if (!fESD) {
+  //fESD or fAOD object available?
+  if (!fESD && !fAOD) {
     AliDebug(2,Form("ERROR: fInputEvent not available\n"));
-    fNEventReject->Fill("noESD",1);
+    fNEventReject->Fill("noESD/AOD",1);
     selectEvent = kFALSE;
     return selectEvent;
   }
@@ -216,14 +241,19 @@ Bool_t AliPWG4HighPtSpectra::SelectEvent() {
   }
 
   //Check if number of reconstructed tracks is larger than 1
-  if(!fESD->GetNumberOfTracks() || fESD->GetNumberOfTracks()<2)  {
-    fNEventReject->Fill("NTracks<2",1);
-    selectEvent = kFALSE;
-    return selectEvent;
+  if(!fReadAODData) {
+    if(!fESD->GetNumberOfTracks() || fESD->GetNumberOfTracks()<2)  {
+      fNEventReject->Fill("NTracks<2",1);
+      selectEvent = kFALSE;
+      return selectEvent;
+    }
   }
 
   //Check if vertex is reconstructed
-  fVtx = fESD->GetPrimaryVertexSPD();
+  if(fESD)
+    fVtx = fESD->GetPrimaryVertexSPD();
+  if(fAOD)
+    fVtx = fAOD->GetPrimaryVertex();
 
   if(!fVtx) {
     fNEventReject->Fill("noVTX",1);
@@ -231,10 +261,13 @@ Bool_t AliPWG4HighPtSpectra::SelectEvent() {
     return selectEvent;
   }
 
-  if(!fVtx->GetStatus()) {
-    fNEventReject->Fill("VtxStatus",1);
-    selectEvent = kFALSE;
-    return selectEvent;
+  if(!fReadAODData){
+    const AliESDVertex* esdVtx = fESD->GetPrimaryVertexSPD();
+    if(!esdVtx->GetStatus()) {
+      fNEventReject->Fill("VtxStatus",1);
+      selectEvent = kFALSE;
+      return selectEvent;
+    }
   }
 
   // Need vertex cut
@@ -257,19 +290,32 @@ Bool_t AliPWG4HighPtSpectra::SelectEvent() {
   //Centrality selection should only be done in case of PbPb
   if(IsPbPb()) {
     Float_t cent = 0.;
-    if(fCentClass!=CalculateCentrality(fESD) && fCentClass!=10) {
+    Int_t calccent = 0;
+    if(fReadAODData)
+      calccent = CalculateCentrality(fAOD);
+    else
+      calccent = CalculateCentrality(fESD);
+    if(fCentClass!=calccent && fCentClass!=10) {
       fNEventReject->Fill("cent",1);
       selectEvent = kFALSE;
       return selectEvent;
     }
     else {
-      if(dynamic_cast<AliESDEvent*>(fESD)->GetCentrality()) {
-       cent = dynamic_cast<AliESDEvent*>(fESD)->GetCentrality()->GetCentralityPercentile("V0M");
+      if(fReadAODData) {
+        if(dynamic_cast<AliAODEvent*>(fAOD)->GetCentrality()) {
+          cent = dynamic_cast<AliAODEvent*>(fAOD)->GetCentrality()->GetCentralityPercentile("V0M");
+        }
+      }
+      else {
+        if(dynamic_cast<AliESDEvent*>(fESD)->GetCentrality()) {
+          cent = dynamic_cast<AliESDEvent*>(fESD)->GetCentrality()->GetCentralityPercentile("V0M");
+        }
       }
+
       if(cent>90.) {
        fNEventReject->Fill("cent>90",1);
        selectEvent = kFALSE;
-       return selectEvent;     
+       return selectEvent;
       }
       fh1Centrality->Fill(cent);
     }
@@ -280,24 +326,22 @@ Bool_t AliPWG4HighPtSpectra::SelectEvent() {
 }
 
 //________________________________________________________________________
-Int_t AliPWG4HighPtSpectra::CalculateCentrality(AliESDEvent *esd){
-
-
+Int_t AliPWG4HighPtSpectra::CalculateCentrality(AliVEvent *event)
+{
   Float_t cent = 999;
 
-  if(esd){
-    if(esd->GetCentrality()){
-      cent = esd->GetCentrality()->GetCentralityPercentile("V0M");
+  if(event){
+    if(event->GetCentrality()){
+      cent = event->GetCentrality()->GetCentralityPercentile("V0M");
     }
   }
 
-  if(cent<0)  return 5;
+  if(cent<0) return 5;
   if(cent>80)return 4;
   if(cent>50)return 3;
   if(cent>30)return 2;
   if(cent>10)return 1;
   return 0;
-
 }
 
 //_________________________________________________
@@ -308,13 +352,19 @@ void AliPWG4HighPtSpectra::Exec(Option_t *)
   //
   AliDebug(2,Form(">> AliPWG4HighPtSpectra::Exec \n"));  
 
-  if(!fMC) {
-    AliMCEventHandler *eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
-    if (!eventHandler) {
-      AliDebug(2,Form( "ERROR: Could not retrieve MC event handler \n"));
+  AliVEvent* event;
+  if(fReadAODData)
+    event = fAOD;
+  else {
+    event = fESD;
+    if(!fMC) {
+      AliMCEventHandler *eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
+      if (!eventHandler) {
+        AliDebug(2,Form( "ERROR: Could not retrieve MC event handler \n"));
+      }
+      else
+        fMC = eventHandler->MCEvent();
     }
-    else
-      fMC = eventHandler->MCEvent();
   }
 
   // All events without selection
@@ -328,18 +378,23 @@ void AliPWG4HighPtSpectra::Exec(Option_t *)
     return;
   }
 
-  //MCEvent available? 
-  //if yes: get stack
-  if(fMC) {
-    AliDebug(2,Form("MC particles: %d", fMC->GetNumberOfTracks()));
-    fStack = fMC->Stack();                //Particles Stack
-    AliDebug(2,Form("MC particles stack: %d", fStack->GetNtrack()));
+  if(fReadAODData){
+    //Open the MC particles in the case of AODanalysis
+    fArrayMCAOD = (TClonesArray*) fAOD->GetList()->FindObject(AliAODMCParticle::StdBranchName());
+  }
+  else {
+    //In case of ESD event: MCEvent available? if yes: get MC particles stack
+    if(fMC) {
+      AliDebug(2,Form("MC particles: %d", fMC->GetNumberOfTracks()));
+      fStack = fMC->Stack();                //Particles Stack
+      AliDebug(2,Form("MC particles stack: %d", fStack->GetNtrack()));
+    }
   }
 
-  Int_t nTracks = fESD->GetNumberOfTracks();
+  Int_t nTracks = event->GetNumberOfTracks();
   AliDebug(2,Form("nTracks %d", nTracks));
 
-  if(!fTrackCuts) { 
+  if((!fTrackCuts && !fReadAODData) || (fFilterMask==0 && fReadAODData)) { //if the TrackCuts are missing in ESD analysis or the FilterBit is missing in AOD analysis
     fNEventReject->Fill("noTrackCuts",1);
     // Post output data
     PostData(0,fHistList);
@@ -358,8 +413,108 @@ void AliPWG4HighPtSpectra::Exec(Option_t *)
   Double_t containerInputRecMC[nvar]     = {0.,0.,0.,0.}; //reconstructed yield as function of MC variable
 
   //Now go to rec level
-  for (Int_t iTrack = 0; iTrack<nTracks; iTrack++) 
-    {   
+  if(fReadAODData) {//AOD analysis
+    for (Int_t iTrack = 0; iTrack<nTracks; iTrack++) 
+    {
+      //Get track for analysis
+      AliVTrack *track = 0x0;
+
+      AliAODTrack *aodtrack = fAOD->GetTrack(iTrack);
+      if(!aodtrack)
+        continue;
+      if((!aodtrack->TestFilterBit(fFilterMask)) || 
+         ((!fCFManagerPos->CheckParticleCuts(kStepReconstructed,aodtrack)) && (aodtrack->Charge()>0.)) ||
+         ((!fCFManagerNeg->CheckParticleCuts(kStepReconstructed,aodtrack)) && (aodtrack->Charge()<0))    )
+        continue;
+      else {
+        track = static_cast<AliVTrack*>(aodtrack);
+      }
+      //fill the container
+      containerInputRec[0] = track->Pt();
+      containerInputRec[1] = track->Phi();
+      containerInputRec[2] = track->Eta();
+      containerInputRec[3] = track->GetTPCNcls();
+
+      if(track->Charge()>0.) fCFManagerPos->GetParticleContainer()->Fill(containerInputRec,kStepReconstructed);
+      if(track->Charge()<0.) fCFManagerNeg->GetParticleContainer()->Fill(containerInputRec,kStepReconstructed);
+
+      if(fArrayMCAOD) {
+        Int_t label = TMath::Abs(track->GetLabel());
+       if(label>fArrayMCAOD->GetEntries()) {
+         continue;
+       }
+       AliAODMCParticle *particle = (AliAODMCParticle*) fArrayMCAOD->At(label);
+       if(!particle) {
+         continue;
+       }
+       //Only select particles generated by HIJING if requested
+       if(fbSelectHIJING) {
+         if(!IsHIJINGParticle(label)) {
+           continue;
+         }
+       }
+       containerInputRecMC[0] = particle->Pt();      
+       containerInputRecMC[1] = particle->Phi();      
+       containerInputRecMC[2] = particle->Eta();  
+       containerInputRecMC[3] = track->GetTPCNcls();
+
+       //Container with primaries
+       if(particle->IsPhysicalPrimary()) {
+         if(particle->Charge()>0.) fCFManagerPos->GetParticleContainer()->Fill(containerInputRecMC,kStepReconstructedMC);
+         if(particle->Charge()<0.) fCFManagerNeg->GetParticleContainer()->Fill(containerInputRecMC,kStepReconstructedMC);
+         //Fill pT resolution plots for primaries
+         //fPtRelUncertainty1PtPrim->Fill(containerInputRec[0],containerInputRec[0]*TMath::Sqrt(track->GetSigma1Pt2())); //This has not been implemented in AOD analysis, since they are also produced by the AddTaskPWG4HighPtTrackQA.C macro
+       }
+
+       //Container with secondaries
+       if (!particle->IsPhysicalPrimary() ) {
+         if(particle->Charge()>0.) fCFManagerPos->GetParticleContainer()->Fill(containerInputRecMC,kStepSecondaries);
+         if(particle->Charge()<0.) fCFManagerNeg->GetParticleContainer()->Fill(containerInputRecMC,kStepSecondaries);
+         //Fill pT resolution plots for primaries
+         //fPtRelUncertainty1PtSec->Fill(containerInputRec[0],containerInputRec[0]*TMath::Sqrt(track->GetSigma1Pt2())); //This has not been implemented in AOD analysis, since they are also produced by the AddTaskPWG4HighPtTrackQA.C macro
+       }
+      }
+    }//track loop
+
+    //Fill MC containers if particles are findable
+    if(fArrayMCAOD) {
+      int noPart = fArrayMCAOD->GetEntriesFast();
+
+      for(int iPart = 1; iPart<noPart; iPart++) {
+       AliAODMCParticle *mcPart = (AliAODMCParticle*) fArrayMCAOD->At(iPart);
+        if(!mcPart) continue;
+
+        //Only select particles generated by HIJING if requested
+        if(fbSelectHIJING) {
+         if(!IsHIJINGParticle(iPart))
+           continue;
+        }
+
+        Int_t pdg = mcPart->PdgCode();
+
+        // select charged pions, protons, kaons , electrons, muons
+        if(TMath::Abs(pdg) == 211 || TMath::Abs(pdg) == 2212 || TMath::Abs(pdg) ==
+          321 || TMath::Abs(pdg) == 11 || TMath::Abs(pdg) == 13){
+  
+         //fill the container
+         containerInputMC[0] = mcPart->Pt();
+         containerInputMC[1] = mcPart->Phi();      
+         containerInputMC[2] = mcPart->Eta();  
+         //      AliESDtrack *esdtrack = fESD->GetTrack(mcPart->GetLabel());
+         containerInputMC[3] = 159.;
+         
+         if(mcPart->IsPhysicalPrimary()) {
+           if(mcPart->Charge()>0. && fCFManagerPos->CheckParticleCuts(kStepMCAcceptance,mcPart)) fCFManagerPos->GetParticleContainer()->Fill(containerInputMC,kStepMCAcceptance);
+           if(mcPart->Charge()<0. && fCFManagerNeg->CheckParticleCuts(kStepMCAcceptance,mcPart)) fCFManagerNeg->GetParticleContainer()->Fill(containerInputMC,kStepMCAcceptance);
+         }
+        }
+      }
+    }
+
+  }//end of AOD analysis
+  else {//ESD analysis
+    for (Int_t iTrack = 0; iTrack<nTracks; iTrack++) 
+    {
       //Get track for analysis
       AliESDtrack *track = 0x0;
       AliESDtrack *esdtrack = fESD->GetTrack(iTrack);
@@ -380,7 +535,7 @@ void AliPWG4HighPtSpectra::Exec(Option_t *)
          continue;
        
        AliExternalTrackParam exParam;
-       Bool_t relate = track->RelateToVertexTPC(fVtx,fESD->GetMagneticField(),kVeryBig,&exParam);
+       Bool_t relate = track->RelateToVertexTPC(fESD->GetPrimaryVertexSPD(),fESD->GetMagneticField(),kVeryBig,&exParam);
        if( !relate ) {
          if(track) delete track;
          continue;
@@ -401,7 +556,7 @@ void AliPWG4HighPtSpectra::Exec(Option_t *)
                continue;
              
              AliExternalTrackParam exParam;
-             Bool_t relate = track->RelateToVertexTPC(fVtx,fESD->GetMagneticField(),kVeryBig,&exParam);
+             Bool_t relate = track->RelateToVertexTPC(fESD->GetPrimaryVertexSPD(),fESD->GetMagneticField(),kVeryBig,&exParam);
              if( !relate ) {
                if(track) delete track;
                continue;
@@ -412,7 +567,6 @@ void AliPWG4HighPtSpectra::Exec(Option_t *)
              //use global constrained track
              track = new AliESDtrack(*esdtrack);
              track->Set(esdtrack->GetConstrainedParam()->GetX(),esdtrack->GetConstrainedParam()->GetAlpha(),esdtrack->GetConstrainedParam()->GetParameter(),esdtrack->GetConstrainedParam()->GetCovariance());
-
            }
          }
        }
@@ -449,7 +603,6 @@ void AliPWG4HighPtSpectra::Exec(Option_t *)
            continue;
          }
        }
-      
        if(esdtrack->GetConstrainedParam()) 
          track->Set(esdtrack->GetConstrainedParam()->GetX(),esdtrack->GetConstrainedParam()->GetAlpha(),esdtrack->GetConstrainedParam()->GetParameter(),esdtrack->GetConstrainedParam()->GetCovariance());
       }
@@ -500,26 +653,16 @@ void AliPWG4HighPtSpectra::Exec(Option_t *)
 
        //Container with primaries
        if(fStack->IsPhysicalPrimary(label)) {
-         if(particle->GetPDG()->Charge()>0.) {
-           fCFManagerPos->GetParticleContainer()->Fill(containerInputRecMC,kStepReconstructedMC);
-         }
-         if(particle->GetPDG()->Charge()<0.) {
-           fCFManagerNeg->GetParticleContainer()->Fill(containerInputRecMC,kStepReconstructedMC);
-         }
-
+         if(particle->GetPDG()->Charge()>0.) fCFManagerPos->GetParticleContainer()->Fill(containerInputRecMC,kStepReconstructedMC);
+         if(particle->GetPDG()->Charge()<0.) fCFManagerNeg->GetParticleContainer()->Fill(containerInputRecMC,kStepReconstructedMC);
          //Fill pT resolution plots for primaries
          fPtRelUncertainty1PtPrim->Fill(containerInputRec[0],containerInputRec[0]*TMath::Sqrt(track->GetSigma1Pt2()));
-
        }
 
        //Container with secondaries
        if (!fStack->IsPhysicalPrimary(label) ) {
-         if(particle->GetPDG()->Charge()>0.) {
-           fCFManagerPos->GetParticleContainer()->Fill(containerInputMC,kStepSecondaries);
-         }
-         if(particle->GetPDG()->Charge()<0.) {
-           fCFManagerNeg->GetParticleContainer()->Fill(containerInputMC,kStepSecondaries);
-         }
+         if(particle->GetPDG()->Charge()>0.) fCFManagerPos->GetParticleContainer()->Fill(containerInputMC,kStepSecondaries);
+         if(particle->GetPDG()->Charge()<0.) fCFManagerNeg->GetParticleContainer()->Fill(containerInputMC,kStepSecondaries);
          //Fill pT resolution plots for primaries
          fPtRelUncertainty1PtSec->Fill(containerInputRec[0],containerInputRec[0]*TMath::Sqrt(track->GetSigma1Pt2()));
        }
@@ -528,51 +671,51 @@ void AliPWG4HighPtSpectra::Exec(Option_t *)
       if(fTrackType==1  || fTrackType==2 || fTrackType==4 || fTrackType==5 || fTrackType==6 || fTrackType==7) {
        if(track) delete track;
       }
-
-
     }//track loop
-  
-
-  //Fill MC containers if particles are findable
-  if(fMC) {
-    for(int iPart = 1; iPart<(fMC->GetNumberOfPrimaries()); iPart++) {
-      AliMCParticle *mcPart  = (AliMCParticle*)fMC->GetTrack(iPart);
-      if(!mcPart) continue;
-
-      //Only select particles generated by HIJING if requested
-      if(fbSelectHIJING) {
-       if(!IsHIJINGParticle(iPart))
-         continue;
-      }
 
-      Int_t pdg = mcPart->PdgCode();
-      
-      // select charged pions, protons, kaons , electrons, muons
-      if(TMath::Abs(pdg) == 211 || TMath::Abs(pdg) == 2212 || TMath::Abs(pdg) ==
-        321 || TMath::Abs(pdg) == 11 || TMath::Abs(pdg) == 13){
-
-       //fill the container
-       containerInputMC[0] = mcPart->Pt();
-       containerInputMC[1] = mcPart->Phi();      
-       containerInputMC[2] = mcPart->Eta();  
-       //      AliESDtrack *esdtrack = fESD->GetTrack(mcPart->GetLabel());
-       containerInputMC[3] = 159.;
-       
-       if(fStack->IsPhysicalPrimary(iPart)) {
-         if(mcPart->Charge()>0. && fCFManagerPos->CheckParticleCuts(kStepMCAcceptance,mcPart)) fCFManagerPos->GetParticleContainer()->Fill(containerInputMC,kStepMCAcceptance);
-         if(mcPart->Charge()<0. && fCFManagerNeg->CheckParticleCuts(kStepMCAcceptance,mcPart)) fCFManagerNeg->GetParticleContainer()->Fill(containerInputMC,kStepMCAcceptance);
-       }
+    //Fill MC containers if particles are findable
+    if(fMC) {
+      for(int iPart = 1; iPart<(fMC->GetNumberOfPrimaries()); iPart++) {
+        AliMCParticle *mcPart  = (AliMCParticle*)fMC->GetTrack(iPart);
+        if(!mcPart) continue;
+  
+        //Only select particles generated by HIJING if requested
+        if(fbSelectHIJING) {
+         if(!IsHIJINGParticle(iPart))
+           continue;
+        }
+  
+        Int_t pdg = mcPart->PdgCode();
+        
+        // select charged pions, protons, kaons , electrons, muons
+        if(TMath::Abs(pdg) == 211 || TMath::Abs(pdg) == 2212 || TMath::Abs(pdg) ==
+          321 || TMath::Abs(pdg) == 11 || TMath::Abs(pdg) == 13){
+  
+         //fill the container
+         containerInputMC[0] = mcPart->Pt();
+         containerInputMC[1] = mcPart->Phi();      
+         containerInputMC[2] = mcPart->Eta();  
+         //      AliESDtrack *esdtrack = fESD->GetTrack(mcPart->GetLabel());
+         containerInputMC[3] = 159.;
+         
+         if(fStack->IsPhysicalPrimary(iPart)) {
+           if(mcPart->Charge()>0. && fCFManagerPos->CheckParticleCuts(kStepMCAcceptance,mcPart)) fCFManagerPos->GetParticleContainer()->Fill(containerInputMC,kStepMCAcceptance);
+           if(mcPart->Charge()<0. && fCFManagerNeg->CheckParticleCuts(kStepMCAcceptance,mcPart)) fCFManagerNeg->GetParticleContainer()->Fill(containerInputMC,kStepMCAcceptance);
+         }
+        }
       }
     }
-  }
-  
+  }//end of ESD analysis
+
   PostData(0,fHistList);
   PostData(1,fCFManagerPos->GetParticleContainer());
   PostData(2,fCFManagerNeg->GetParticleContainer());
   
 }
+
 //________________________________________________________________________
-Bool_t AliPWG4HighPtSpectra::PythiaInfoFromFile(const char* currFile,Float_t &fXsec,Float_t &fTrials){
+Bool_t AliPWG4HighPtSpectra::PythiaInfoFromFile(const char* currFile,Float_t &fXsec,Float_t &fTrials)
+{
   //
   // get the cross section and the trails either from pyxsec.root or from pysec_hists.root
   // This is to called in Notify and should provide the path to the AOD/ESD file
@@ -636,6 +779,7 @@ Bool_t AliPWG4HighPtSpectra::PythiaInfoFromFile(const char* currFile,Float_t &fX
   }
   return kTRUE;
 }
+
 //________________________________________________________________________
 Bool_t AliPWG4HighPtSpectra::Notify()
 {
@@ -645,6 +789,9 @@ Bool_t AliPWG4HighPtSpectra::Notify()
   // Copied from AliAnalysisTaskJetSpectrum2
   // 
 
+  if(fNoPythiaInfo)
+    return kTRUE;
+
   TTree *tree = AliAnalysisManager::GetAnalysisManager()->GetTree();
   Float_t xsection = 0;
   Float_t ftrials  = 1;
@@ -667,7 +814,8 @@ Bool_t AliPWG4HighPtSpectra::Notify()
 }
 
 //________________________________________________________________________
-AliGenPythiaEventHeader*  AliPWG4HighPtSpectra::GetPythiaEventHeader(AliMCEvent *mcEvent){
+AliGenPythiaEventHeader*  AliPWG4HighPtSpectra::GetPythiaEventHeader(AliMCEvent *mcEvent)
+{
   
   if(!mcEvent)return 0;
   AliGenEventHeader* genHeader = mcEvent->GenEventHeader();
@@ -697,7 +845,8 @@ AliGenPythiaEventHeader*  AliPWG4HighPtSpectra::GetPythiaEventHeader(AliMCEvent
 }
 
 //________________________________________________________________________
-AliGenHijingEventHeader*  AliPWG4HighPtSpectra::GetHijingEventHeader(AliMCEvent *mcEvent){
+AliGenHijingEventHeader*  AliPWG4HighPtSpectra::GetHijingEventHeader(AliMCEvent *mcEvent)
+{
   
   if(!mcEvent)return 0;
   AliGenEventHeader* genHeader = mcEvent->GenEventHeader();
@@ -707,7 +856,7 @@ AliGenHijingEventHeader*  AliPWG4HighPtSpectra::GetHijingEventHeader(AliMCEvent
     AliGenCocktailEventHeader* genCocktailHeader = dynamic_cast<AliGenCocktailEventHeader*>(genHeader);
     
     if (!genCocktailHeader) {
-      //      AliWarningGeneral(Form(" %s:%d",(char*)__FILE__,__LINE__),"Unknown header type (not Pythia or Cocktail)");
+      AliWarningGeneral(Form(" %s:%d",(char*)__FILE__,__LINE__),"Unknown header type (not Pythia or Cocktail)");
       //      AliWarning(Form("%s %d: Unknown header type (not Pythia or Cocktail)",(char*)__FILE__,__LINE__));
       return 0;
     }
@@ -726,6 +875,21 @@ AliGenHijingEventHeader*  AliPWG4HighPtSpectra::GetHijingEventHeader(AliMCEvent
 
 }
 
+//________________________________________________________________________
+AliGenHijingEventHeader*  AliPWG4HighPtSpectra::GetHijingEventHeaderAOD(AliAODEvent *aodEvent)
+{
+  AliGenHijingEventHeader* hijingGenHeader = 0x0;
+  if(aodEvent) {
+    AliAODMCHeader* mcHeader = (AliAODMCHeader*) aodEvent->GetList()->FindObject(AliAODMCHeader::StdBranchName());
+    TList* headerList = mcHeader->GetCocktailHeaders();
+    for (Int_t i=0; i<headerList->GetEntries(); i++) {
+      hijingGenHeader = dynamic_cast<AliGenHijingEventHeader*>(headerList->At(i));
+      if (hijingGenHeader)
+        break;
+    }
+  }
+  return hijingGenHeader;
+}
 
 //___________________________________________________________________________
 void AliPWG4HighPtSpectra::Terminate(Option_t*)
@@ -737,7 +901,8 @@ void AliPWG4HighPtSpectra::Terminate(Option_t*)
 }
 
 //___________________________________________________________________________
-void AliPWG4HighPtSpectra::CreateOutputObjects() {
+void AliPWG4HighPtSpectra::CreateOutputObjects() 
+{
   //HERE ONE CAN CREATE OUTPUT OBJECTS, IN PARTICULAR IF THE OBJECT PARAMETERS DON'T NEED
   //TO BE SET BEFORE THE EXECUTION OF THE TASK
   //
@@ -757,7 +922,7 @@ void AliPWG4HighPtSpectra::CreateOutputObjects() {
 
   fNEventReject = new TH1F("fNEventReject","Reason events are rejectected for analysis",20,0,20);
   //Set labels
-  fNEventReject->Fill("noESD",0);
+  fNEventReject->Fill("noESD/AOD",0);
   fNEventReject->Fill("Trigger",0);
   fNEventReject->Fill("NTracks<2",0);
   fNEventReject->Fill("noVTX",0);
@@ -805,6 +970,9 @@ void AliPWG4HighPtSpectra::CreateOutputObjects() {
 
   TH1::AddDirectory(oldStatus);   
 
+  OpenFile(1);
+  OpenFile(2);
+
   PostData(0,fHistList);
   PostData(1,fCFManagerPos->GetParticleContainer());
   PostData(2,fCFManagerNeg->GetParticleContainer());
@@ -815,30 +983,52 @@ void AliPWG4HighPtSpectra::CreateOutputObjects() {
 }
 
 //________________________________________________________________________
-Bool_t AliPWG4HighPtSpectra::IsHIJINGParticle(Int_t label) {
+Bool_t AliPWG4HighPtSpectra::IsHIJINGParticle(Int_t label)
+{
   //
   // Return kTRUE in case particle is from HIJING event
   //
 
-  AliGenHijingEventHeader*  hijingHeader = GetHijingEventHeader(fMC);
+  AliGenHijingEventHeader* hijingHeader;
+  if(fReadAODData)
+    hijingHeader = GetHijingEventHeaderAOD(fAOD);
+  else
+    hijingHeader = GetHijingEventHeader(fMC);
 
   Int_t nproduced = hijingHeader->NProduced();
 
-  TParticle * mom = fStack->Particle(label);
-  Int_t iMom = label;
-  Int_t iParent = mom->GetFirstMother();
-  while(iParent!=-1){
-    iMom = iParent;
-    mom = fStack->Particle(iMom);
-    iParent = mom->GetFirstMother();
-  }
+  if(fReadAODData) {
+    AliAODMCParticle* mom = (AliAODMCParticle*) fArrayMCAOD->At(label);
+    Int_t iMom = label;
+    Int_t iParent = mom->GetMother();
+    while(iParent!=-1){
+      iMom = iParent;
+      mom = (AliAODMCParticle*) fArrayMCAOD->At(iMom);
+      iParent = mom->GetMother();
+    }
 
-  if(iMom<nproduced) {
-    return kTRUE;
-  } else {
-    return kFALSE;
+    if(iMom<nproduced) {
+      return kTRUE;
+    } else {
+      return kFALSE;
+    }
+  }
+  else { //ESD analysis
+    TParticle * mom = fStack->Particle(label);
+    Int_t iMom = label;
+    Int_t iParent = mom->GetFirstMother();
+    while(iParent!=-1){
+      iMom = iParent;
+      mom = fStack->Particle(iMom);
+      iParent = mom->GetFirstMother();
+    }
+  
+    if(iMom<nproduced) {
+      return kTRUE;
+    } else {
+      return kFALSE;
+    }
   }
-
 }
 
 #endif