coverity fixes (Saehanseul Oh <saehanseul.oh@cern.ch>)
[u/mrichter/AliRoot.git] / PWGCF / Correlations / DPhi / FourierDecomposition / AliMuonEffMC.cxx
index f5b04a6145501509effc494ab1893326f5d62f33..af664180f06ec7084e9e2390ffaab16d6af783c5 100644 (file)
 #include <TChain.h>
 #include <TFile.h>
 
+#include "TParticle.h"
+#include "AliStack.h"
 #include "AliAnalysisManager.h"
 #include "AliAnalysisTask.h"
 #include "AliESDVertex.h"
 #include "AliESDEvent.h"
 #include "AliAODEvent.h"
 #include "AliESDMuonTrack.h"
+#include "AliAODTrack.h"
 #include "AliESDVertex.h"
 #include "AliAODVertex.h"
 #include "AliCentrality.h"
@@ -24,6 +27,7 @@
 #include "AliMCParticle.h"
 #include "AliAnalysisHelperJetTasks.h"
 #include "AliMCEvent.h"
+#include "AliAODMCParticle.h"
 
 using std::cout;
 using std::endl;
@@ -32,54 +36,66 @@ ClassImp(AliMuonEffMC)
 
 //________________________________________________________________________
 AliMuonEffMC::AliMuonEffMC() :
-  AliAnalysisTaskSE(), fESD(0), fAOD(0), fMC(0), fCentrality(99), fZVertex(99), fOutputList(0x0),      
-  fHEventStat(0), fHEvt(0x0), fIsMc(kTRUE), fMDProcess(kTRUE), fCentralityEstimator("V0M"),
-  fNEtaBins(15), fNpTBins(100), fNCentBins(5), fNZvtxBins(10), fNPhiBins(24),
-  fHMuonParGen(0x0), fHMuonDetGen(0x0), fHMuonDetRec(0x0), fHEtcDetRec(0x0)
+  AliAnalysisTaskSE(), fESD(0), fAOD(0), fMC(0), fStack(0), fCentrality(99), fZVertex(99), fOutputList(0x0),      
+  fHEventStat(0), fHEvt(0x0), fIsMc(kFALSE), fMDProcess(kFALSE), fCentralityEstimator("V0M"),
+  fNEtaBins(15), fNpTBins(100), fNCentBins(5), fNZvtxBins(10), fNPhiBins(36),
+  fHMuonParGen(0x0), fHMuonDetGen(0x0), fHMuonDetRec(0x0), fHEtcDetRec(0x0), fHFXu(0), fHFXantiu(0), fHFXd(0), fHFXantid(0), fHFXg(0), fHFXetc(0), fHFXmuonP(0), fHFXmuonM(0)
 {
   // Constructor
-  DefineInput(0, TChain::Class());
-  DefineOutput(1, TList::Class());
-
-  for(Int_t i=0; i<4; i++)
+   for(Int_t i=0; i<4; i++)
   {
-    fHMuMotherGenPt[i] = 0x0;
-    fHMuMotherRecPt[i] = 0x0;
-    fHMuMotherGenPhi[i] = 0x0;
-    fHMuMotherRecPhi[i] = 0x0;
-    fHMuMotherGenEta[i] = 0x0;
-    fHMuMotherRecEta[i] = 0x0;
+    fHMuMotherGenPt[i] = NULL;
+    fHMuMotherRecPt[i] = NULL;
+    fHMuMotherGenPhi[i] = NULL;
+    fHMuMotherRecPhi[i] = NULL;
+    fHMuMotherGenEta[i] = NULL;
+    fHMuMotherRecEta[i] = NULL;
     fHMuDCA[i] = 0x0;
+    for(Int_t j=0; j<3; j++)
+    {
+      fHMuMohterPhiDifGen[i][j] = NULL;
+      fHMuMohterPhiDifRec[i][j] = NULL;
+      fHMuMohterEtaDifGen[i][j] = NULL;
+      fHMuMohterEtaDifRec[i][j] = NULL;
+    }
   }
 }
 
 //________________________________________________________________________
 AliMuonEffMC::AliMuonEffMC(const char *name) :
-  AliAnalysisTaskSE(name), fESD(0), fAOD(0), fMC(0), fCentrality(99), fZVertex(99), fOutputList(0x0),      
-  fHEventStat(0), fHEvt(0x0),  fIsMc(kTRUE), fMDProcess(kTRUE), fCentralityEstimator("V0M"),
-  fNEtaBins(15), fNpTBins(100), fNCentBins(5), fNZvtxBins(10), fNPhiBins(24),
-  fHMuonParGen(0x0), fHMuonDetGen(0x0), fHMuonDetRec(0x0), fHEtcDetRec(0x0)
+  AliAnalysisTaskSE(name), fESD(0), fAOD(0), fMC(0), fStack(0), fCentrality(99), fZVertex(99), fOutputList(0x0),      
+  fHEventStat(0), fHEvt(0x0),  fIsMc(kFALSE), fMDProcess(kFALSE), fCentralityEstimator("V0M"),
+  fNEtaBins(15), fNpTBins(100), fNCentBins(5), fNZvtxBins(10), fNPhiBins(36),
+  fHMuonParGen(0x0), fHMuonDetGen(0x0), fHMuonDetRec(0x0), fHEtcDetRec(0x0), fHFXu(0), fHFXantiu(0), fHFXd(0), fHFXantid(0), fHFXg(0), fHFXetc(0), fHFXmuonP(0), fHFXmuonM(0)
 {
   // Constructor
-  DefineInput(0, TChain::Class());
-  DefineOutput(1, TList::Class());
-
-  for(Int_t i=0; i<4; i++)
+   for(Int_t i=0; i<4; i++)
   {
-    fHMuMotherGenPt[i] = 0x0;
-    fHMuMotherRecPt[i] = 0x0;
-    fHMuMotherGenPhi[i] = 0x0;
-    fHMuMotherRecPhi[i] = 0x0;
-    fHMuMotherGenEta[i] = 0x0;
-    fHMuMotherRecEta[i] = 0x0;
+    fHMuMotherGenPt[i] = NULL;
+    fHMuMotherRecPt[i] = NULL;
+    fHMuMotherGenPhi[i] = NULL;
+    fHMuMotherRecPhi[i] = NULL;
+    fHMuMotherGenEta[i] = NULL;
+    fHMuMotherRecEta[i] = NULL;
     fHMuDCA[i] = 0x0;
+    for(Int_t j=0; j<3; j++)
+    {
+      fHMuMohterPhiDifGen[i][j] = NULL;
+      fHMuMohterPhiDifRec[i][j] = NULL;
+      fHMuMohterEtaDifGen[i][j] = NULL;
+      fHMuMohterEtaDifRec[i][j] = NULL;
+    }
   }
+  DefineInput(0, TChain::Class());
+  DefineOutput(1, TList::Class());
+
 }
 
 //________________________________________________________________________
 AliMuonEffMC::~AliMuonEffMC()
 {
   //Destructor
+  if(fOutputList) delete fOutputList;
 }
 
 //________________________________________________________________________
@@ -90,7 +106,7 @@ void AliMuonEffMC::UserCreateOutputObjects()
 
   fOutputList = new TList();
   fOutputList->SetOwner(1);
+
   fHEventStat = new TH1D("fHEventStat","Event statistics for analysis",18,0,18);
   fHEventStat->GetXaxis()->SetBinLabel(1,"Event");
   fHEventStat->GetXaxis()->SetBinLabel(2,"SelectedEvent");
@@ -177,33 +193,66 @@ void AliMuonEffMC::UserCreateOutputObjects()
   fHEtcDetRec->Sumw2();
   fOutputList->Add(fHEtcDetRec);
 
-  if(fMDProcess)
+  if(fIsMc)
   {
     const char* MotherSpecies[4] = {"Pion","Kaon","D", "Etc"};
-    
-    for(Int_t i=0; i<4; i++)
+    const char *MuPt[3] = {"0510","1020","2040"};
+    if(fMDProcess)
     {
-      fHMuMotherGenPt[i] = new TH2F(Form("fHMuMotherGenPt_%s",MotherSpecies[i]),";p_{T,muon}^{gen} (GeV/c);p_{T,mother}^{Truth} (GeV/c);",500, 0, 50, 500, 0, 50);
-      fOutputList->Add(fHMuMotherGenPt[i]);
-      
-      fHMuMotherRecPt[i] = new TH2F(Form("fHMuMotherRecPt_%s",MotherSpecies[i]),";p_{T,muon}^{rec} (GeV/c);p_{T,mother}^{Truth} (GeV/c);",500, 0, 50, 500, 0, 50);
-      fOutputList->Add(fHMuMotherRecPt[i]);
-      
-      fHMuMotherGenPhi[i] = new TH2F(Form("fHMuMotherGenPhi_%s",MotherSpecies[i]),";#phi_{gen};mother #phi;",100, 0, TMath::TwoPi(), 100, 0, TMath::TwoPi());
-      fOutputList->Add(fHMuMotherGenPhi[i]);
-      
-      fHMuMotherRecPhi[i] = new TH2F(Form("fHMuMotherRecPhi_%s",MotherSpecies[i]),";#phi_{rec};mother #phi;",100, 0, TMath::TwoPi(), 100, 0, TMath::TwoPi());
-      fOutputList->Add(fHMuMotherRecPhi[i]);
-      
-      fHMuMotherGenEta[i] = new TH2F(Form("fHMuMotherGenEta_%s",MotherSpecies[i]),";#eta_{gen};mother #eta;",100, -5., -1., 100, -5., -1.);
-      fOutputList->Add(fHMuMotherGenEta[i]);
-      
-      fHMuMotherRecEta[i] = new TH2F(Form("fHMuMotherRecEta_%s",MotherSpecies[i]),";#eta_{rec};mother #eta;",100, -5., -1., 100, -5., -1.);
-      fOutputList->Add(fHMuMotherRecEta[i]);
-      
-      fHMuDCA[i] =  new TH1F(Form("fHMuDCA_%s",MotherSpecies[i]), ";DCA", 100, 0, 50);
-      fOutputList->Add(fHMuDCA[i]);
+      for(Int_t i=0; i<4; i++)
+      {
+       fHMuMotherGenPt[i] = new TH2F(Form("fHMuMotherGenPt_%s",MotherSpecies[i]),";p_{T,muon}^{gen} (GeV/c);p_{T,mother}^{Truth} (GeV/c);",500, 0, 50, 500, 0, 50);
+       fOutputList->Add(fHMuMotherGenPt[i]);
+       fHMuMotherRecPt[i] = new TH2F(Form("fHMuMotherRecPt_%s",MotherSpecies[i]),";p_{T,muon}^{rec} (GeV/c);p_{T,mother}^{Truth} (GeV/c);",500, 0, 50, 500, 0, 50);
+       fOutputList->Add(fHMuMotherRecPt[i]);
+       fHMuMotherGenPhi[i] = new TH2F(Form("fHMuMotherGenPhi_%s",MotherSpecies[i]),";#phi_{gen};mother #phi;",100, 0, TMath::TwoPi(), 100, 0, TMath::TwoPi());
+       fOutputList->Add(fHMuMotherGenPhi[i]);
+       fHMuMotherRecPhi[i] = new TH2F(Form("fHMuMotherRecPhi_%s",MotherSpecies[i]),";#phi_{rec};mother #phi;",100, 0, TMath::TwoPi(), 100, 0, TMath::TwoPi());
+       fOutputList->Add(fHMuMotherRecPhi[i]);
+       fHMuMotherGenEta[i] = new TH2F(Form("fHMuMotherGenEta_%s",MotherSpecies[i]),";#eta_{gen};mother #eta;",100, -5., -1., 100, -5., -1.);
+       fOutputList->Add(fHMuMotherGenEta[i]);
+       fHMuMotherRecEta[i] = new TH2F(Form("fHMuMotherRecEta_%s",MotherSpecies[i]),";#eta_{rec};mother #eta;",100, -5., -1., 100, -5., -1.);
+       fOutputList->Add(fHMuMotherRecEta[i]);
+       fHMuDCA[i] =  new TH1F(Form("fHMuDCA_%s",MotherSpecies[i]), ";DCA", 100, 0, 50);
+       fOutputList->Add(fHMuDCA[i]);
+       
+       for(Int_t j=0; j<3; j++)
+       {
+         fHMuMohterPhiDifGen[i][j] = new TH1F(Form("fHMuMohterPhiDifGen_%s_%s",MotherSpecies[i], MuPt[j]),";#Delta#phi",100, -1.0*TMath::Pi(), TMath::Pi());
+         fOutputList->Add(fHMuMohterPhiDifGen[i][j]);
+         fHMuMohterPhiDifRec[i][j] = new TH1F(Form("fHMuMohterPhiDifRec_%s_%s",MotherSpecies[i], MuPt[j]),";#Delta#phi",100, -1.0*TMath::Pi(), TMath::Pi());
+         fOutputList->Add(fHMuMohterPhiDifRec[i][j]);
+         fHMuMohterEtaDifGen[i][j] = new TH1F(Form("fHMuMohterEtaDifGen_%s_%s",MotherSpecies[i], MuPt[j]),";#Delta#eta",100, -5.0, 5.0);
+         fOutputList->Add(fHMuMohterEtaDifGen[i][j]);
+         fHMuMohterEtaDifRec[i][j] = new TH1F(Form("fHMuMohterEtaDifRec_%s_%s",MotherSpecies[i], MuPt[j]),";#Delta#eta",100, -5.0, 5.0);
+         fOutputList->Add(fHMuMohterEtaDifRec[i][j]);
+       }
+      }
     }
+    
+    fHFXu = new TH1F("fHFXu",";x_{F}",1000, 0.0, 1.0);
+    fOutputList->Add(fHFXu);
+    
+    fHFXantiu = new TH1F("fHFXantiu",";x_{F}",1000, 0.0, 1.0);
+    fOutputList->Add(fHFXantiu);
+    
+    fHFXd = new TH1F("fHFXd",";x_{F}",1000, 0.0, 1.0);
+    fOutputList->Add(fHFXd);
+    
+    fHFXantid = new TH1F("fHFXantid",";x_{F}",1000, 0.0, 1.0);
+    fOutputList->Add(fHFXantid);
+    
+    fHFXg = new TH1F("fHFXg",";x_{F}",1000, 0.0, 1.0);
+    fOutputList->Add(fHFXg);
+    
+    fHFXetc = new TH1F("fHFXetc",";x_{F}",1000, 0.0, 1.0);
+    fOutputList->Add(fHFXetc);
+    
+    fHFXmuonP = new TH1F("fHFXmuonP",";x_{F}",1000, 0.0, 1.0);
+    fOutputList->Add(fHFXmuonP);
+    
+    fHFXmuonM = new TH1F("fHFXmuonM",";x_{F}",1000, 0.0, 1.0);
+    fOutputList->Add(fHFXmuonM);
   }
   PostData(1, fOutputList);
 }
@@ -212,50 +261,54 @@ void AliMuonEffMC::UserCreateOutputObjects()
 void AliMuonEffMC::UserExec(Option_t *) 
 {
   // Main loop, Called for each event
-  fESD = dynamic_cast<AliESDEvent*>(InputEvent());
-  if (!fESD) 
+  Int_t ntrks = 0; // number of tracks in an event
+
+  if(((TString)InputEvent()->IsA()->GetName())=="AliAODEvent")
   {
     fAOD = dynamic_cast<AliAODEvent*>(InputEvent());
-  }
-
-  if (!fESD && !fAOD) 
+    if (!fAOD) { AliError("AOD event not found. Nothing done!"); return; }
+    ntrks = fAOD->GetNTracks();
+  } 
+  else
   {
-    AliError("Neither fESD nor fAOD available");
-    return;
+    fESD = dynamic_cast<AliESDEvent*>(InputEvent());
+    if (!fESD) { AliError("ESD event not found. Nothing done!"); return; }
+    ntrks = fESD->GetNumberOfMuonTracks();
   }
        
   fHEventStat->Fill(0.5);
   if(fIsMc) 
   {
     fMC = MCEvent();
-    if (!fMC) {
-      printf("ERROR: fMC not available\n");
-      return;
-    }
-  }
-
-  const AliESDVertex* vertex = fESD->GetPrimaryVertex();
-  fZVertex = vertex->GetZ();
-  if(fESD->GetCentrality()) fCentrality = fESD->GetCentrality()->GetCentralityPercentile("fCentralityEstimator");
-
-  // Fill Event histogram
-  fHEvt->Fill(fZVertex, fCentrality);
-
-   // Centrality, vertex, other event variables...
-  if (!VertexOk(fESD)) { 
-    AliInfo(Form("Event REJECTED. z = %.1f", fZVertex));  
-    return; 
   }
 
-  if (fCentrality > 100. || fCentrality < -1.5) { 
-    AliInfo(Form("Event REJECTED. fCentrality = %.1f", fCentrality)); 
-    return; 
+  // Centrality, vertex, other event variables...
+  if(fAOD)
+  { 
+    const AliAODVertex* vertex = fAOD->GetPrimaryVertex();
+    fZVertex = vertex->GetZ();
+    if(fAOD->GetCentrality())  fCentrality = fAOD->GetCentrality()->GetCentralityPercentile(fCentralityEstimator);
   }
+  else if(fESD) 
+  {
+    const AliESDVertex* vertex = fESD->GetPrimaryVertex();
+    fZVertex = vertex->GetZ();
+    if(fESD->GetCentrality()) fCentrality = fESD->GetCentrality()->GetCentralityPercentile(fCentralityEstimator);
+  }   
+
+  if ((fESD && !VertexOk(fESD)) || (fAOD && !VertexOk(fAOD))) { //AliInfo(Form("Event REJECTED. z = %.1f", fZVertex)); 
+    return; }
+  if (fCentrality > 100. || fCentrality < -1.5) { //AliInfo(Form("Event REJECTED. fCentrality = %.1f", fCentrality)); 
+    return; }
  
-  if(fCentrality < 0) fCentrality = 1.0;
+  if(fCentrality < 0) fCentrality = 0.0; //ad hoc centrality for pp
+  // Fill Event histogram
+  fHEvt->Fill(fZVertex, fCentrality);
   fHEventStat->Fill(1.5);
  
-  ULong64_t trigword=fESD->GetTriggerMask();
+  ULong64_t trigword = 0;
+  if(fAOD) trigword=fAOD->GetTriggerMask();
+  else if(fESD) trigword=fESD->GetTriggerMask();
  
   if (trigword & 0x01) fHEventStat->Fill(17.5);
   if (trigword & 0x02) fHEventStat->Fill(3.5);
@@ -272,90 +325,130 @@ void AliMuonEffMC::UserExec(Option_t *)
   if (trigword & 0x1000) fHEventStat->Fill(14.5);
   if (trigword & 0x2000) fHEventStat->Fill(15.5);
   if (trigword & 0x4000) fHEventStat->Fill(16.5);
-
+  
+  // generated level loop
   if(fIsMc)
   {
-    for (Int_t iTrack = 0; iTrack<fESD->GetNumberOfMuonTracks(); iTrack++) 
-    { 
-      // loop on muon tracks
+    for (Int_t ipart=0; ipart<fMC->GetNumberOfTracks(); ipart++)
+    {
+      if(fAOD)
+      {
+       AliAODMCParticle *AodMcParticle  = (AliAODMCParticle*)fMC->GetTrack(ipart);
+       if(TMath::Abs(AodMcParticle->PdgCode())==13) 
+       {
+         Double_t fillArrayParGen[5] = { AodMcParticle->Eta(), AodMcParticle->Pt(), fCentrality, fZVertex, AodMcParticle->Phi() };
+         fHMuonParGen->Fill(fillArrayParGen);
+       }
+      } 
+      else if(fESD)
+      {
+       AliMCParticle *McParticle  = (AliMCParticle*)fMC->GetTrack(ipart);
+       if(TMath::Abs(McParticle->PdgCode())==13) 
+       {
+         Double_t fillArrayParGen[5] = { McParticle->Eta(), McParticle->Pt(), fCentrality, fZVertex, McParticle->Phi() };
+         fHMuonParGen->Fill(fillArrayParGen);
+       }
+      }
+    }
+  }
+  
+  // reconstructed level loop
+  for (Int_t iTrack = 0; iTrack<ntrks; iTrack++) 
+  { 
+    Int_t label = 0;
+    Double_t trackpt = 0;
+    Double_t tracketa = 0;
+    Double_t trackphi = 0;
+    Double_t dcavalue = 0;
+    
+    Double_t mcpt = 0;
+    Double_t mceta = 0;
+    Double_t mcphi = 0;
+    
+    Int_t motherlabel =0;
+    Int_t motherpdg = 0;
+    Double_t motherpt = 0;
+    Double_t mothereta = 0;
+    Double_t motherphi = 0;
+    
+    if(fAOD)
+    {
+      AliAODTrack* muonTrack = (AliAODTrack*)fAOD->GetTrack(iTrack);
+      if(muonTrack)
+      {
+       if(!(IsGoodMUONtrack(*muonTrack)) || !(muonTrack->IsMuonTrack())) continue;
+       trackpt = muonTrack->Pt();
+       tracketa = muonTrack->Eta();
+       trackphi = muonTrack->Phi();
+       label =  TMath::Abs(muonTrack->GetLabel());
+      }
+    }
+    else if(fESD)
+    {
       AliESDMuonTrack* muonTrack = fESD->GetMuonTrack(iTrack);
       if(muonTrack)
       {
        if(!IsGoodMUONtrack(*muonTrack)) continue;
-       Double_t fillArrayDetRec[5] = { muonTrack->Eta(), muonTrack->Pt(), fCentrality, fZVertex, muonTrack->Phi() };
-       fHMuonDetRec->Fill(fillArrayDetRec); 
-       
-       Int_t label = TMath::Abs(muonTrack->GetLabel());
+       trackpt = muonTrack->Pt();
+       tracketa = muonTrack->Eta();
+       trackphi = muonTrack->Phi();
+       label =  TMath::Abs(muonTrack->GetLabel());
+       dcavalue = muonTrack->GetDCA();
+      }
+    }
+    Double_t fillArrayDetRec[5] = { tracketa, trackpt, fCentrality, fZVertex, trackphi };
+    fHMuonDetRec->Fill(fillArrayDetRec); 
+    
+    if(fIsMc)
+    {
+      if(fAOD)
+      {
+       AliAODMCParticle *aodMcParticle  = (AliAODMCParticle*)fMC->GetTrack(label);
+       if(TMath::Abs(aodMcParticle->PdgCode()) != 13) 
+       {
+         fHEtcDetRec->Fill(fillArrayDetRec); 
+         continue;
+       }
+       mcpt = aodMcParticle->Pt();
+       mceta = aodMcParticle->Eta();
+       mcphi = aodMcParticle->Phi();
+       motherlabel = aodMcParticle->GetMother();
+       if(motherlabel > 0) 
+       { 
+         AliAODMCParticle *aodMotherParticle  = (AliAODMCParticle*)fMC->GetTrack(motherlabel);
+         motherpdg = TMath::Abs(aodMotherParticle->PdgCode());
+         motherpt = aodMotherParticle->Pt();
+         mothereta = aodMotherParticle->Eta();
+         motherphi = aodMotherParticle->Phi();
+       }      
+      }
+      else if(fESD)
+      {
        AliMCParticle *McParticle  = (AliMCParticle*)fMC->GetTrack(label);
        if(TMath::Abs(McParticle->PdgCode()) != 13) 
        {
          fHEtcDetRec->Fill(fillArrayDetRec); 
          continue;
        }
-       Double_t fillArrayDetGen[5] = { McParticle->Eta(), McParticle->Pt(), fCentrality, fZVertex, McParticle->Phi() };
-       fHMuonDetGen->Fill(fillArrayDetGen);
-       
-       if(fMDProcess)
-       {
-         if(McParticle->GetMother() > 0)
-         {
-           AliMCParticle *MotherParticle  = (AliMCParticle*)fMC->GetTrack(McParticle->GetMother());
-           Int_t motherlabel = TMath::Abs(MotherParticle->PdgCode());
-           
-           if(motherlabel==411 || motherlabel==413 || motherlabel==421 || motherlabel==423 || motherlabel==431 || motherlabel==433 || motherlabel==10413 || motherlabel==10411 || motherlabel==10423 || motherlabel==10421 || motherlabel==10433 || motherlabel==10431 || motherlabel==20413 || motherlabel==415 || motherlabel==20423 || motherlabel==425 || motherlabel==20433 || motherlabel==435)
-           {  
-             fHMuMotherGenPt[2]->Fill(McParticle->Pt(), MotherParticle->Pt());
-             fHMuMotherRecPt[2]->Fill(muonTrack->Pt(), MotherParticle->Pt());
-             fHMuMotherGenPhi[2]->Fill(McParticle->Phi(), MotherParticle->Phi());
-             fHMuMotherRecPhi[2]->Fill(muonTrack->Phi(), MotherParticle->Phi());
-             fHMuMotherGenEta[2]->Fill(McParticle->Eta(), MotherParticle->Eta());
-             fHMuMotherRecEta[2]->Fill(muonTrack->Eta(), MotherParticle->Eta());
-             fHMuDCA[2]->Fill(muonTrack->GetDCA());
-           }
-           else if(motherlabel==211) 
-           {
-             fHMuMotherGenPt[0]->Fill(McParticle->Pt(), MotherParticle->Pt());
-             fHMuMotherRecPt[0]->Fill(muonTrack->Pt(), MotherParticle->Pt());
-             fHMuMotherGenPhi[0]->Fill(McParticle->Phi(), MotherParticle->Phi());
-             fHMuMotherRecPhi[0]->Fill(muonTrack->Phi(), MotherParticle->Phi());
-             fHMuMotherGenEta[0]->Fill(McParticle->Eta(), MotherParticle->Eta());
-             fHMuMotherRecEta[0]->Fill(muonTrack->Eta(), MotherParticle->Eta());
-             fHMuDCA[0]->Fill(muonTrack->GetDCA());
-           }
-           else if(motherlabel==321)
-           {
-             fHMuMotherGenPt[1]->Fill(McParticle->Pt(), MotherParticle->Pt());
-             fHMuMotherRecPt[1]->Fill(muonTrack->Pt(), MotherParticle->Pt());
-             fHMuMotherGenPhi[1]->Fill(McParticle->Phi(), MotherParticle->Phi());
-             fHMuMotherRecPhi[1]->Fill(muonTrack->Phi(), MotherParticle->Phi());
-             fHMuMotherGenEta[1]->Fill(McParticle->Eta(), MotherParticle->Eta());
-             fHMuMotherRecEta[1]->Fill(muonTrack->Eta(), MotherParticle->Eta());
-             fHMuDCA[1]->Fill(muonTrack->GetDCA());
-           }   
-           else 
-           {
-             fHMuMotherGenPt[3]->Fill(McParticle->Pt(), MotherParticle->Pt());
-             fHMuMotherRecPt[3]->Fill(muonTrack->Pt(), MotherParticle->Pt());
-             fHMuMotherGenPhi[3]->Fill(McParticle->Phi(), MotherParticle->Phi());
-             fHMuMotherRecPhi[3]->Fill(muonTrack->Phi(), MotherParticle->Phi());
-             fHMuMotherGenEta[3]->Fill(McParticle->Eta(), MotherParticle->Eta());
-             fHMuMotherRecEta[3]->Fill(muonTrack->Eta(), MotherParticle->Eta());
-             fHMuDCA[3]->Fill(muonTrack->GetDCA());
-           }
-         }    
-       } // (mother hadron) : (daughter muon) QA 
-      } 
-    }
-    
-    for (Int_t ipart=0; ipart<fMC->GetNumberOfTracks(); ipart++)
-    {
-      AliMCParticle *McParticle  = (AliMCParticle*)fMC->GetTrack(ipart);
-      if(TMath::Abs(McParticle->PdgCode())==13) 
-      {
-       Double_t fillArrayParGen[5] = { McParticle->Eta(), McParticle->Pt(), fCentrality, fZVertex, McParticle->Phi() };
-       fHMuonParGen->Fill(fillArrayParGen);
+       mcpt = McParticle->Pt();
+       mceta = McParticle->Eta();
+       mcphi = McParticle->Phi();
+       motherlabel = McParticle->GetMother();
+       if(motherlabel > 0) 
+       { 
+         AliMCParticle *MotherParticle  = (AliMCParticle*)fMC->GetTrack(motherlabel);
+         motherpdg = TMath::Abs(MotherParticle->PdgCode());
+         motherpt = MotherParticle->Pt();
+         mothereta = MotherParticle->Eta();
+         motherphi = MotherParticle->Phi();
+       }
       }
-    }  
+      Double_t fillArrayDetGen[5] = { mceta, mcpt, fCentrality, fZVertex, mcphi };
+      fHMuonDetGen->Fill(fillArrayDetGen);
+    
+      // mother-daughter kinematic relation
+      if(fMDProcess && motherlabel>0) MDProcess(motherpdg, mcpt, mcphi, mceta, trackpt, trackphi, tracketa, motherpt, motherphi, mothereta, dcavalue);
+    }
   }
   PostData(1, fOutputList);
   return;
@@ -366,14 +459,7 @@ void AliMuonEffMC::Terminate(Option_t *)
 {
   // Draw result to the screen
   // Called once at the end of the query
-
-  fOutputList = dynamic_cast<TList*> (GetOutputData(1));
-  if (!fOutputList) {
-    AliError("Output list not available");
-    return;
-  }
 }
-
 //________________________________________________________________________
 Bool_t AliMuonEffMC::VertexOk(TObject* obj) const
 {
@@ -420,7 +506,6 @@ Bool_t AliMuonEffMC::IsGoodMUONtrack(AliESDMuonTrack &track)
 {
   // Applying track cuts for MUON tracks
   if(!track.ContainTrackerData()) return kFALSE;
-  if(!track.ContainTriggerData()) return kFALSE;
 
   Double_t thetaTrackAbsEnd = TMath::ATan(track.GetRAtAbsorberEnd()/505.) * TMath::RadToDeg();
   Double_t eta = track.Eta();
@@ -433,3 +518,204 @@ Bool_t AliMuonEffMC::IsGoodMUONtrack(AliESDMuonTrack &track)
 
   return kTRUE;
 }
+
+//________________________________________________________________________
+Bool_t AliMuonEffMC::IsGoodMUONtrack(AliAODTrack &track)
+{
+  if (!track.IsMuonTrack()) return kFALSE;
+
+  Double_t dThetaAbs = TMath::ATan(track.GetRAtAbsorberEnd()/505.)
+                     * TMath::RadToDeg();
+  if ((dThetaAbs<2.) || (dThetaAbs>10.)) return kFALSE;
+
+  Double_t dEta = track.Eta();
+  if ((dEta<-4.) || (dEta>2.5)) return kFALSE;
+
+  if (track.GetMatchTrigger()<0.5) return kFALSE;
+
+  return kTRUE;
+}
+
+//________________________________________________________________________
+void AliMuonEffMC::MDProcess(Int_t motherpdg, Double_t mcpt, Double_t mcphi, Double_t mceta, Double_t trackpt, Double_t trackphi, Double_t tracketa, Double_t motherpt, Double_t motherphi, Double_t mothereta, Double_t dcavalue)
+{
+  if(motherpdg==411 || motherpdg==413 || motherpdg==421 || motherpdg==423 || motherpdg==431 || motherpdg==433 || motherpdg==10413 || motherpdg==10411 || motherpdg==10423 || motherpdg==10421 || motherpdg==10433 || motherpdg==10431 || motherpdg==20413 || motherpdg==415 || motherpdg==20423 || motherpdg==425 || motherpdg==20433 || motherpdg==435)
+  {  
+    fHMuMotherGenPt[2]->Fill(mcpt, motherpt);
+    fHMuMotherRecPt[2]->Fill(trackpt, motherpt);
+    fHMuMotherGenPhi[2]->Fill(mcphi, motherphi);
+    fHMuMotherRecPhi[2]->Fill(trackphi, motherphi);
+    fHMuMotherGenEta[2]->Fill(mceta, mothereta);
+    fHMuMotherRecEta[2]->Fill(tracketa, mothereta);
+    
+    // generated 
+    if((0.5 <= mcpt) && (mcpt < 1.0))
+    {
+      fHMuMohterPhiDifGen[2][0]->Fill(deltaphi(motherphi-mcphi));
+      fHMuMohterEtaDifGen[2][0]->Fill(mothereta-mceta);
+    }
+    else if((1.0 <= mcpt) && (mcpt < 2.0))
+    {
+      fHMuMohterPhiDifGen[2][1]->Fill(deltaphi(motherphi-mcphi));
+      fHMuMohterEtaDifGen[2][1]->Fill(mothereta-mceta);
+    }
+    else if((2.0 <= mcpt) && (mcpt < 4.0))
+    {
+      fHMuMohterPhiDifGen[2][2]->Fill(deltaphi(motherphi-mcphi));
+      fHMuMohterEtaDifGen[2][2]->Fill(mothereta-mceta);
+    }
+    // reconstructed
+    if((0.5 <= trackpt) && (trackpt < 1.0))
+    {
+      fHMuMohterPhiDifRec[2][0]->Fill(deltaphi(motherphi-trackphi));
+      fHMuMohterEtaDifRec[2][0]->Fill(mothereta-tracketa);
+    }
+    else if((1.0 <= trackpt) && (trackpt < 2.0))
+    {
+      fHMuMohterPhiDifRec[2][1]->Fill(deltaphi(motherphi-trackphi));
+      fHMuMohterEtaDifRec[2][1]->Fill(mothereta-tracketa);
+    }
+    else if((2.0 <= trackpt) && (trackpt < 4.0))
+    {
+      fHMuMohterPhiDifRec[2][2]->Fill(deltaphi(motherphi-trackphi));
+      fHMuMohterEtaDifRec[2][2]->Fill(mothereta-tracketa);
+    }
+    
+    // DCA
+    if(fESD) fHMuDCA[2]->Fill(dcavalue);
+  }
+  
+  else if(motherpdg==211) 
+  {
+    fHMuMotherGenPt[0]->Fill(mcpt, motherpt);
+    fHMuMotherRecPt[0]->Fill(trackpt, motherpt);
+    fHMuMotherGenPhi[0]->Fill(mcphi, motherphi);
+    fHMuMotherRecPhi[0]->Fill(trackphi, motherphi);
+    fHMuMotherGenEta[0]->Fill(mceta, mothereta);
+    fHMuMotherRecEta[0]->Fill(tracketa, mothereta);
+    // generated 
+    if((0.5 <= mcpt) && (mcpt < 1.0))
+    {
+      fHMuMohterPhiDifGen[0][0]->Fill(deltaphi(motherphi-mcphi));
+      fHMuMohterEtaDifGen[0][0]->Fill(mothereta-mceta);
+    }
+    else if((1.0 <= mcpt) && (mcpt < 2.0))
+    {
+      fHMuMohterPhiDifGen[0][1]->Fill(deltaphi(motherphi-mcphi));
+      fHMuMohterEtaDifGen[0][1]->Fill(mothereta-mceta);
+    }
+    else if((2.0 <= mcpt) && (mcpt < 4.0))
+    {
+      fHMuMohterPhiDifGen[0][2]->Fill(deltaphi(motherphi-mcphi));
+      fHMuMohterEtaDifGen[0][2]->Fill(mothereta-mceta);
+    }
+    // reconstructed
+    if((0.5 <= trackpt) && (trackpt < 1.0))
+    {
+      fHMuMohterPhiDifRec[0][0]->Fill(deltaphi(motherphi-trackphi));
+      fHMuMohterEtaDifRec[0][0]->Fill(mothereta-tracketa);
+    }
+    else if((1.0 <= trackpt) && (trackpt < 2.0))
+    {
+      fHMuMohterPhiDifRec[0][1]->Fill(deltaphi(motherphi-trackphi));
+      fHMuMohterEtaDifRec[0][1]->Fill(mothereta-tracketa);
+    }
+    else if((2.0 <= trackpt) && (trackpt < 4.0))
+    {
+      fHMuMohterPhiDifRec[0][2]->Fill(deltaphi(motherphi-trackphi));
+      fHMuMohterEtaDifRec[0][2]->Fill(mothereta-tracketa);
+    }
+    if(fESD) fHMuDCA[0]->Fill(dcavalue);
+  }
+  else if(motherpdg==321)
+  {
+    fHMuMotherGenPt[1]->Fill(mcpt, motherpt);
+    fHMuMotherRecPt[1]->Fill(trackpt, motherpt);
+    fHMuMotherGenPhi[1]->Fill(mcphi, motherphi);
+    fHMuMotherRecPhi[1]->Fill(trackphi, motherphi);
+    fHMuMotherGenEta[1]->Fill(mceta, mothereta);
+    fHMuMotherRecEta[1]->Fill(tracketa, mothereta);
+    // generated 
+    if((0.5 <= mcpt) && (mcpt < 1.0))
+    {
+      fHMuMohterPhiDifGen[1][0]->Fill(deltaphi(motherphi-mcphi));
+      fHMuMohterEtaDifGen[1][0]->Fill(mothereta-mceta);
+    }
+    else if((1.0 <= mcpt) && (mcpt < 2.0))
+    {
+      fHMuMohterPhiDifGen[1][1]->Fill(deltaphi(motherphi-mcphi));
+      fHMuMohterEtaDifGen[1][1]->Fill(mothereta-mceta);
+    }
+    else if((2.0 <= mcpt) && (mcpt < 4.0))
+    {
+      fHMuMohterPhiDifGen[1][2]->Fill(deltaphi(motherphi-mcphi));
+      fHMuMohterEtaDifGen[1][2]->Fill(mothereta-mceta);
+    }
+    // reconstructed
+    if((0.5 <= trackpt) && (trackpt < 1.0))
+    {
+      fHMuMohterPhiDifRec[1][0]->Fill(deltaphi(motherphi-trackphi));
+      fHMuMohterEtaDifRec[1][0]->Fill(mothereta-tracketa);
+    }
+    else if((1.0 <= trackpt) && (trackpt < 2.0))
+    {
+      fHMuMohterPhiDifRec[1][1]->Fill(deltaphi(motherphi-trackphi));
+      fHMuMohterEtaDifRec[1][1]->Fill(mothereta-tracketa);
+    }
+    else if((2.0 <= trackpt) && (trackpt < 4.0))
+    {
+      fHMuMohterPhiDifRec[1][2]->Fill(deltaphi(motherphi-trackphi));
+      fHMuMohterEtaDifRec[1][2]->Fill(mothereta-tracketa);
+    }
+    if(fESD) fHMuDCA[1]->Fill(dcavalue);
+  }    
+  else 
+  {
+    fHMuMotherGenPt[3]->Fill(mcpt, motherpt);
+    fHMuMotherRecPt[3]->Fill(trackpt, motherpt);
+    fHMuMotherGenPhi[3]->Fill(mcphi, motherphi);
+    fHMuMotherRecPhi[3]->Fill(trackphi, motherphi);
+    fHMuMotherGenEta[3]->Fill(mceta, mothereta);
+    fHMuMotherRecEta[3]->Fill(tracketa, mothereta);
+    // generated 
+    if((0.5 <= mcpt) && (mcpt < 1.0))
+    {
+      fHMuMohterPhiDifGen[3][0]->Fill(deltaphi(motherphi-mcphi));
+      fHMuMohterEtaDifGen[3][0]->Fill(mothereta-mceta);
+    }
+    else if((1.0 <= mcpt) && (mcpt < 2.0))
+    {
+      fHMuMohterPhiDifGen[3][1]->Fill(deltaphi(motherphi-mcphi));
+      fHMuMohterEtaDifGen[3][1]->Fill(mothereta-mceta);
+    }
+    else if((2.0 <= mcpt) && (mcpt < 4.0))
+    {
+      fHMuMohterPhiDifGen[3][2]->Fill(deltaphi(motherphi-mcphi));
+      fHMuMohterEtaDifGen[3][2]->Fill(mothereta-mceta);
+    }
+    // reconstructed
+    if((0.5 <= trackpt) && (trackpt < 1.0))
+    {
+      fHMuMohterPhiDifRec[3][0]->Fill(deltaphi(motherphi-trackphi));
+      fHMuMohterEtaDifRec[3][0]->Fill(mothereta-tracketa);
+    }
+    else if((1.0 <= trackpt) && (trackpt < 2.0))
+    {
+      fHMuMohterPhiDifRec[3][1]->Fill(deltaphi(motherphi-trackphi));
+      fHMuMohterEtaDifRec[3][1]->Fill(mothereta-tracketa);
+    }
+    else if((2.0 <= trackpt) && (trackpt < 4.0))
+    {
+      fHMuMohterPhiDifRec[3][2]->Fill(deltaphi(motherphi-trackphi));
+      fHMuMohterEtaDifRec[3][2]->Fill(mothereta-tracketa);
+    }
+    if(fESD) fHMuDCA[3]->Fill(dcavalue);
+  }  
+}
+//________________________________________________________________________
+Double_t AliMuonEffMC::deltaphi(Double_t phi)
+{
+  if(phi < -1.0*TMath::Pi()) { return (phi + TMath::TwoPi()); }
+  else if(phi > TMath::Pi()) { return (phi - TMath::TwoPi()); }
+  else { return phi; }
+}