Conversion Task able to run on AOD's, added different trigger selection, implemented...
authorfbock <fbock@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 13 Jun 2013 11:38:41 +0000 (11:38 +0000)
committerfbock <fbock@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 13 Jun 2013 11:38:41 +0000 (11:38 +0000)
18 files changed:
PWGGA/GammaConv/AliAODConversionPhoton.cxx
PWGGA/GammaConv/AliAnalysisTaskConversionQA.cxx
PWGGA/GammaConv/AliAnalysisTaskConversionQA.h
PWGGA/GammaConv/AliAnalysisTaskGammaConvDalitzV1.cxx
PWGGA/GammaConv/AliAnalysisTaskGammaConvDalitzV1.h
PWGGA/GammaConv/AliAnalysisTaskGammaConvV1.cxx
PWGGA/GammaConv/AliAnalysisTaskGammaConvV1.h
PWGGA/GammaConv/AliAnalysisTaskMaterial.cxx
PWGGA/GammaConv/AliAnalysisTaskMaterial.h
PWGGA/GammaConv/AliConversionCuts.cxx
PWGGA/GammaConv/AliConversionCuts.h
PWGGA/GammaConv/AliConversionMesonCuts.cxx
PWGGA/GammaConv/AliConversionMesonCuts.h
PWGGA/GammaConv/AliDalitzElectronCuts.cxx
PWGGA/GammaConv/AliDalitzElectronCuts.h
PWGGA/GammaConv/AliV0ReaderV1.cxx
PWGGA/GammaConv/AliV0ReaderV1.h
PWGGA/GammaConv/macros/AddTask_ConversionAODProduction.C

index 7305bbe..aaac331 100644 (file)
@@ -19,8 +19,8 @@ AliConversionPhotonBase(*((AliConversionPhotonBase*)kfphoton))
     //Constructor from kfphoton
 
     // puts the mass to zero and store dilepton mass
-    SetMass(kfphoton->M());
-    SetE(P());
+           SetMass(kfphoton->M());
+                       //SetE(P());
 }
 
 AliAODConversionPhoton::AliAODConversionPhoton(TLorentzVector *vec) :
index b9bc235..c7c2b58 100644 (file)
@@ -27,6 +27,9 @@
 #include "AliPIDResponse.h"
 #include "TFile.h"
 #include "AliESDtrackCuts.h"
+#include "AliAODMCParticle.h"
+#include "AliAODMCHeader.h"
+
 
 class iostream;
 
@@ -35,6 +38,65 @@ using namespace std;
 ClassImp(AliAnalysisTaskConversionQA)
 
 //________________________________________________________________________
+AliAnalysisTaskConversionQA::AliAnalysisTaskConversionQA() : AliAnalysisTaskSE(),
+   fV0Reader(NULL),
+   fConversionGammas(NULL),
+   fConversionCuts(NULL),
+   fInputEvent(NULL),
+   fNumberOfESDTracks(0),
+   fMCEvent(NULL),
+   fMCStack(NULL),
+   fStreamQA(NULL),
+   fIsHeavyIon(kFALSE),
+   ffillTree(kFALSE),
+   ffillHistograms(kFALSE),
+   fOutputList(NULL),
+   fESDList(NULL),
+   hVertexZ(NULL),
+   hNGoodESDTracks(NULL),
+   hNV0Tracks(NULL),
+   hNContributorsVertex(NULL),
+   hITSClusterPhi(NULL),
+   hGammaPt(NULL),
+   hGammaPhi(NULL),
+   hGammaEta(NULL),
+   hGammaChi2perNDF(NULL),
+   hGammaPsiPair(NULL),
+   hGammaQt(NULL),
+   hGammaCosinePointingAngle(NULL),
+   hGammaXY(NULL),
+   hGammaZR(NULL),
+   hElecPt(NULL),
+   hElecEta(NULL),
+   hElecPhi(NULL),
+   hElecNfindableClsTPC(NULL),
+   hPosiNfindableClsTPC(NULL),
+   fTrueList(NULL),
+   hTrueResolutionR(NULL),
+   hTrueResolutionZ(NULL),
+   hTrueResolutionPhi(NULL),
+   hTrueGammaPt(NULL),
+   hTrueGammaPhi(NULL),
+   hTrueGammaEta(NULL),
+   hTrueGammaMass(NULL),
+   hTrueGammaChi2perNDF(NULL),
+   hTrueGammaPsiPair(NULL),
+   hTrueGammaQt(NULL),
+   hTrueGammaCosinePointingAngle(NULL),
+   hTrueGammaXY(NULL),
+   hTrueGammaZR(NULL),
+   hTrueElecPt(NULL),
+   hTrueElecEta(NULL),
+   hTrueElecPhi(NULL),
+   hTrueElecNfindableClsTPC(NULL),
+   hTruePosiNfindableClsTPC(NULL),
+   fIsMC(kFALSE),
+   fnGammaCandidates(1),
+   fMCStackPos(NULL),
+   fMCStackNeg(NULL)
+{
+
+}
 AliAnalysisTaskConversionQA::AliAnalysisTaskConversionQA(const char *name) : AliAnalysisTaskSE(name),
    fV0Reader(NULL),
    fConversionGammas(NULL),
@@ -69,9 +131,9 @@ AliAnalysisTaskConversionQA::AliAnalysisTaskConversionQA(const char *name) : Ali
    hElecNfindableClsTPC(NULL),
    hPosiNfindableClsTPC(NULL),
    fTrueList(NULL),
-   hTrueResoulutionR(NULL),
-   hTrueResoulutionZ(NULL),
-   hTrueResoulutionPhi(NULL),
+   hTrueResolutionR(NULL),
+   hTrueResolutionZ(NULL),
+   hTrueResolutionPhi(NULL),
    hTrueGammaPt(NULL),
    hTrueGammaPhi(NULL),
    hTrueGammaEta(NULL),
@@ -86,7 +148,11 @@ AliAnalysisTaskConversionQA::AliAnalysisTaskConversionQA(const char *name) : Ali
    hTrueElecEta(NULL),
    hTrueElecPhi(NULL),
    hTrueElecNfindableClsTPC(NULL),
-   hTruePosiNfindableClsTPC(NULL)
+   hTruePosiNfindableClsTPC(NULL),
+   fIsMC(kFALSE),
+   fnGammaCandidates(1),
+   fMCStackPos(NULL),
+   fMCStackNeg(NULL)
 {
    // Default constructor
 
@@ -167,18 +233,18 @@ void AliAnalysisTaskConversionQA::UserCreateOutputObjects()
       hPosiNfindableClsTPC = new TH1F("Positron_findableClusterTPC","Positron_findableClusterTPC",100,0,1);
       fESDList->Add(hPosiNfindableClsTPC);
 
-      if(MCEvent()){
+      if(fIsMC){
          fTrueList = new TList();
          fTrueList->SetOwner(kTRUE);
          fTrueList->SetName("True QA");
          fOutputList->Add(fTrueList);
 
-         hTrueResoulutionR = new TH2F("True_ConversionPointResolution_R","True_ConversionPointResolution_R",240,0,120,200,-20,20);
-         fTrueList->Add(hTrueResoulutionR);
-         hTrueResoulutionZ = new TH2F("True_ConversionPointResolution_Z","True_ConversionPointResolution_Z",480,-120,120,200,-20,20);
-         fTrueList->Add(hTrueResoulutionZ);
-         hTrueResoulutionPhi = new TH2F("True_ConversionPointResolution_Phi","True_ConversionPointResolution_Phi",360,0,2*TMath::Pi(),200,-20,20);
-         fTrueList->Add(hTrueResoulutionPhi);
+         hTrueResolutionR = new TH2F("True_ConversionPointResolution_R","True_ConversionPointResolution_R",240,0,120,200,-20,20);
+         fTrueList->Add(hTrueResolutionR);
+         hTrueResolutionZ = new TH2F("True_ConversionPointResolution_Z","True_ConversionPointResolution_Z",480,-120,120,200,-20,20);
+         fTrueList->Add(hTrueResolutionZ);
+         hTrueResolutionPhi = new TH2F("True_ConversionPointResolution_Phi","True_ConversionPointResolution_Phi",360,0,2*TMath::Pi(),200,-TMath::Pi()/30., TMath::Pi()/30.);
+         fTrueList->Add(hTrueResolutionPhi);
 
          hTrueGammaPt = new TH1F("True_Gamma_Pt","True_Gamma_Pt",250,0,25);
          fTrueList->Add(hTrueGammaPt);
@@ -254,8 +320,8 @@ void AliAnalysisTaskConversionQA::UserExec(Option_t *){
       return;
    }
    fInputEvent = InputEvent();
-   fMCEvent = MCEvent();
-   if(fMCEvent) fMCStack = fMCEvent->Stack();
+   if(fIsMC) fMCEvent = MCEvent();
+   if(fMCEvent && fInputEvent->IsA()==AliESDEvent::Class()){ fMCStack = fMCEvent->Stack(); }
 
    Int_t eventNotAccepted =
       fConversionCuts->IsEventAcceptedByConversionCut(fV0Reader->GetConversionCuts(),fInputEvent,fMCEvent,fIsHeavyIon);
@@ -265,27 +331,37 @@ void AliAnalysisTaskConversionQA::UserExec(Option_t *){
 
    if(fMCEvent){
       if(fConversionCuts->GetSignalRejection() != 0){
-         fConversionCuts->GetNotRejectedParticles(fConversionCuts->GetSignalRejection(),
-                                                  fConversionCuts->GetAcceptedHeader(),
-                                                  fMCEvent);
+         if(fInputEvent->IsA()==AliESDEvent::Class()){
+               fConversionCuts->GetNotRejectedParticles(fConversionCuts->GetSignalRejection(),
+                                                        fConversionCuts->GetAcceptedHeader(),
+                                                        fMCEvent);
+         }
+         else if(fInputEvent->IsA()==AliAODEvent::Class()){
+            fConversionCuts->GetNotRejectedParticles(fConversionCuts->GetSignalRejection(),
+                                                      fConversionCuts->GetAcceptedHeader(),
+                                                      fInputEvent);
+         }
       }
    }
 
    if(ffillHistograms){
-      CountESDTracks();
+      CountTracks();
       hVertexZ->Fill(fInputEvent->GetPrimaryVertex()->GetZ());
       hNContributorsVertex->Fill(fConversionCuts->GetNumberOfContributorsVtx(fInputEvent));
       hNGoodESDTracks->Fill(fNumberOfESDTracks);
       hNV0Tracks->Fill(fInputEvent->GetVZEROData()->GetMTotV0A()+fInputEvent->GetVZEROData()->GetMTotV0C());
    }
 
+    if(fMCEvent && fInputEvent->IsA()==AliAODEvent::Class())
+      RelabelAODPhotonCandidates(kTRUE);    // In case of AODMC relabeling MC
+   
    for(Int_t firstGammaIndex=0;firstGammaIndex<fConversionGammas->GetEntriesFast();firstGammaIndex++){
       AliAODConversionPhoton *gamma=dynamic_cast<AliAODConversionPhoton*>(fConversionGammas->At(firstGammaIndex));
       if (gamma==NULL) continue;
       if(fMCEvent && fConversionCuts->GetSignalRejection() != 0){
-         if(!fConversionCuts->IsParticleFromBGEvent(gamma->GetMCLabelPositive(), fMCStack))
+         if(!fConversionCuts->IsParticleFromBGEvent(gamma->GetMCLabelPositive(), fMCStack, fInputEvent))
             continue;
-         if(!fConversionCuts->IsParticleFromBGEvent(gamma->GetMCLabelNegative(), fMCStack))
+         if(!fConversionCuts->IsParticleFromBGEvent(gamma->GetMCLabelNegative(), fMCStack, fInputEvent))
             continue;
       }
       if(!fConversionCuts->PhotonIsSelected(gamma,fInputEvent)){
@@ -295,7 +371,9 @@ void AliAnalysisTaskConversionQA::UserExec(Option_t *){
       if(ffillTree) ProcessQATree(gamma);
       if(ffillHistograms) ProcessQA(gamma);
    }
-
+   if(fMCEvent && fInputEvent->IsA()==AliAODEvent::Class())
+      RelabelAODPhotonCandidates(kFALSE);    // In case of AODMC relabeling MC
+      
    PostData(1, fOutputList);
 }
 
@@ -304,7 +382,7 @@ void AliAnalysisTaskConversionQA::UserExec(Option_t *){
 void AliAnalysisTaskConversionQA::ProcessQATree(AliAODConversionPhoton *gamma){
 
    // Fill Histograms for QA and MC
-   AliESDEvent* event = (AliESDEvent*) InputEvent();
+   AliVEvent* event = (AliVEvent*) InputEvent();
    AliPIDResponse* pidResonse = ((AliConversionCuts*)fV0Reader->GetConversionCuts())->GetPIDResponse();
 
    Float_t gammaPt = gamma->GetPhotonPt();
@@ -320,14 +398,16 @@ void AliAnalysisTaskConversionQA::ProcessQATree(AliAODConversionPhoton *gamma){
    conversionPoint(1) = gamma->GetConversionY();
    conversionPoint(2) = gamma->GetConversionZ();
    TVectorF daughterProp(20);
-   AliESDtrack * negTrack = fConversionCuts->GetESDTrack(event, gamma->GetTrackLabelNegative());
-   AliESDtrack * posTrack = fConversionCuts->GetESDTrack(event, gamma->GetTrackLabelPositive());
+   AliVTrack * negTrack = fConversionCuts->GetTrack(event, gamma->GetTrackLabelNegative());
+   AliVTrack * posTrack = fConversionCuts->GetTrack(event, gamma->GetTrackLabelPositive());
 
    if(!negTrack||!posTrack)return;
 
    Bool_t isTruePhoton = kFALSE;
-   if(fMCEvent){
-      if(IsTruePhoton(gamma)) isTruePhoton = kTRUE;
+   if(fMCEvent && fInputEvent->IsA()==AliVEvent::Class()){
+      isTruePhoton = IsTruePhotonESD(gamma);
+   } else if (fMCEvent && fInputEvent->IsA()==AliAODEvent::Class()){
+      isTruePhoton = IsTruePhotonAOD(gamma);   
    }
 
    daughterProp(0) = posTrack->Pt();
@@ -391,7 +471,7 @@ void AliAnalysisTaskConversionQA::ProcessQATree(AliAODConversionPhoton *gamma){
    daughterProp(18) = posTrack->GetNcls(1);
    daughterProp(13) = (Float_t)negTrack->GetTPCClusterInfo(2,0,fConversionCuts->GetFirstTPCRow(gamma->GetConversionRadius()));
    daughterProp(19) = negTrack->GetNcls(1);
-
+   
    if (fStreamQA){
       if(fMCEvent){
          (*fStreamQA)<<"PhotonQA"
@@ -440,8 +520,8 @@ void AliAnalysisTaskConversionQA::ProcessQA(AliAODConversionPhoton *gamma){
    hGammaXY->Fill(gamma->GetConversionX(),gamma->GetConversionY());
    hGammaZR->Fill(gamma->GetConversionZ(),gamma->GetConversionRadius());
 
-   AliESDtrack * negTrack = fConversionCuts->GetESDTrack((AliESDEvent*)fInputEvent, gamma->GetTrackLabelNegative());
-   AliESDtrack * posTrack = fConversionCuts->GetESDTrack((AliESDEvent*)fInputEvent, gamma->GetTrackLabelPositive());
+   AliVTrack * negTrack = fConversionCuts->GetTrack(fInputEvent, gamma->GetTrackLabelNegative());
+   AliVTrack * posTrack = fConversionCuts->GetTrack(fInputEvent, gamma->GetTrackLabelPositive());
    if(!negTrack||!posTrack)return;
 
    Double_t negtrackPhi = negTrack->Phi();
@@ -466,25 +546,25 @@ void AliAnalysisTaskConversionQA::ProcessQA(AliAODConversionPhoton *gamma){
 
    // hElecNfindableClsTPC->Fill((Float_t)negTrack->GetNcls(1)/(Float_t)negTrack->GetTPCNclsF());
    // hPosiNfindableClsTPC->Fill((Float_t)posTrack->GetNcls(1)/(Float_t)posTrack->GetTPCNclsF());
-
-   if(fMCEvent) ProcessTrueQA(gamma,negTrack,posTrack);
+   if(fMCEvent && fInputEvent->IsA()==AliESDEvent::Class()){
+      ProcessTrueQAESD(gamma,(AliESDtrack*)negTrack,(AliESDtrack*)posTrack);
+   } else if(fMCEvent && fInputEvent->IsA()==AliAODEvent::Class()){
+        ProcessTrueQAAOD(gamma,(AliAODTrack*)negTrack,(AliAODTrack*)posTrack);
+   }
 }
 
 //________________________________________________________________________
-void AliAnalysisTaskConversionQA::ProcessTrueQA(AliAODConversionPhoton *TruePhotonCandidate, AliESDtrack *elec, AliESDtrack *posi)
+void AliAnalysisTaskConversionQA::ProcessTrueQAESD(AliAODConversionPhoton *TruePhotonCandidate, AliESDtrack *elec, AliESDtrack *posi)
 {
-
-   if(!IsTruePhoton(TruePhotonCandidate)) return;
-
+   if(!IsTruePhotonESD(TruePhotonCandidate)) return;
    TParticle *negDaughter = TruePhotonCandidate->GetNegativeMCDaughter(fMCStack);
    TParticle *mcPhoton = TruePhotonCandidate->GetMCParticle(fMCStack);
-
    // True Photon
-   hTrueResoulutionR->Fill(TruePhotonCandidate->GetConversionRadius(),
+   hTrueResolutionR->Fill(TruePhotonCandidate->GetConversionRadius(),
                            TruePhotonCandidate->GetConversionRadius()-negDaughter->R());
-   hTrueResoulutionZ->Fill(TruePhotonCandidate->GetConversionZ(),
+   hTrueResolutionZ->Fill(TruePhotonCandidate->GetConversionZ(),
                            TruePhotonCandidate->GetConversionZ()-negDaughter->Vz());
-   hTrueResoulutionPhi->Fill(TruePhotonCandidate->Phi(),
+   hTrueResolutionPhi->Fill(TruePhotonCandidate->Phi(),
                              TruePhotonCandidate->Phi()-mcPhoton->Phi());
    hTrueGammaPt->Fill(TruePhotonCandidate->Pt());
    hTrueGammaPhi->Fill(TruePhotonCandidate->Phi());
@@ -496,7 +576,6 @@ void AliAnalysisTaskConversionQA::ProcessTrueQA(AliAODConversionPhoton *TruePhot
    hTrueGammaCosinePointingAngle->Fill(fConversionCuts->GetCosineOfPointingAngle(TruePhotonCandidate,fInputEvent));
    hTrueGammaXY->Fill(TruePhotonCandidate->GetConversionX(),TruePhotonCandidate->GetConversionY());
    hTrueGammaZR->Fill(TruePhotonCandidate->GetConversionZ(),TruePhotonCandidate->GetConversionRadius());
-
    hTrueElecPt->Fill(elec->Pt(),posi->Pt());
    hTrueElecEta->Fill(elec->Eta(),posi->Eta());
    hTrueElecPhi->Fill(elec->Phi(),posi->Phi());
@@ -506,34 +585,82 @@ void AliAnalysisTaskConversionQA::ProcessTrueQA(AliAODConversionPhoton *TruePhot
       ->Fill((Float_t)posi->GetTPCClusterInfo(2,0,fConversionCuts->GetFirstTPCRow(TruePhotonCandidate->GetConversionRadius())));
    // hTrueElecNfindableClsTPC->Fill((Float_t)elec->GetNcls(1)/(Float_t)elec->GetTPCNclsF());
    // hTruePosiNfindableClsTPC->Fill((Float_t)posi->GetNcls(1)/(Float_t)posi->GetTPCNclsF());
+}
+
+//________________________________________________________________________
+void AliAnalysisTaskConversionQA::ProcessTrueQAAOD(AliAODConversionPhoton *TruePhotonCandidate, AliAODTrack *elec, AliAODTrack *posi)
+{
+   if(!IsTruePhotonAOD(TruePhotonCandidate)) return;
 
+   TClonesArray *AODMCTrackArray = dynamic_cast<TClonesArray*>(fInputEvent->FindListObject(AliAODMCParticle::StdBranchName()));
+   AliAODMCParticle *negDaughter = (AliAODMCParticle*) AODMCTrackArray->At(TruePhotonCandidate->GetMCLabelNegative());
+   AliAODMCParticle *mcPhoton = (AliAODMCParticle*) AODMCTrackArray->At(negDaughter->GetMother());
+   // True Photon
+   hTrueResolutionR->Fill(TruePhotonCandidate->GetConversionRadius(),
+                           TruePhotonCandidate->GetConversionRadius()-(TMath::Sqrt(negDaughter->Xv()*negDaughter->Xv()+negDaughter->Yv()*negDaughter->Yv())));
+   hTrueResolutionZ->Fill(TruePhotonCandidate->GetConversionZ(),
+                           TruePhotonCandidate->GetConversionZ()-negDaughter->Zv());
+   hTrueResolutionPhi->Fill(TruePhotonCandidate->Phi(),
+                             TruePhotonCandidate->Phi()-mcPhoton->Phi());
+   hTrueGammaPt->Fill(TruePhotonCandidate->Pt());
+   hTrueGammaPhi->Fill(TruePhotonCandidate->Phi());
+   hTrueGammaEta->Fill(TruePhotonCandidate->Eta());
+   hTrueGammaMass->Fill(TruePhotonCandidate->GetMass());
+   hTrueGammaChi2perNDF->Fill(TruePhotonCandidate->GetChi2perNDF());
+   hTrueGammaPsiPair->Fill(TruePhotonCandidate->GetPsiPair());
+   hTrueGammaQt->Fill(TruePhotonCandidate->GetArmenterosQt());
+   hTrueGammaCosinePointingAngle->Fill(fConversionCuts->GetCosineOfPointingAngle(TruePhotonCandidate,fInputEvent));
+   hTrueGammaXY->Fill(TruePhotonCandidate->GetConversionX(),TruePhotonCandidate->GetConversionY());
+   hTrueGammaZR->Fill(TruePhotonCandidate->GetConversionZ(),TruePhotonCandidate->GetConversionRadius());
+   hTrueElecPt->Fill(elec->Pt(),posi->Pt());
+   hTrueElecEta->Fill(elec->Eta(),posi->Eta());
+   hTrueElecPhi->Fill(elec->Phi(),posi->Phi());
+   hTrueElecNfindableClsTPC
+      ->Fill((Float_t)elec->GetTPCClusterInfo(2,0,fConversionCuts->GetFirstTPCRow(TruePhotonCandidate->GetConversionRadius())));
+   hTruePosiNfindableClsTPC
+      ->Fill((Float_t)posi->GetTPCClusterInfo(2,0,fConversionCuts->GetFirstTPCRow(TruePhotonCandidate->GetConversionRadius())));
+   // hTrueElecNfindableClsTPC->Fill((Float_t)elec->GetNcls(1)/(Float_t)elec->GetTPCNclsF());
+   // hTruePosiNfindableClsTPC->Fill((Float_t)posi->GetNcls(1)/(Float_t)posi->GetTPCNclsF());
 }
+
 //________________________________________________________________________
-void AliAnalysisTaskConversionQA::CountESDTracks(){
+void AliAnalysisTaskConversionQA::CountTracks(){
 
+   if(fInputEvent->IsA()==AliESDEvent::Class()){
    // Using standard function for setting Cuts
    Bool_t selectPrimaries=kTRUE;
    AliESDtrackCuts *EsdTrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010(selectPrimaries);
    EsdTrackCuts->SetMaxDCAToVertexZ(2);
    EsdTrackCuts->SetEtaRange(-0.8, 0.8);
    EsdTrackCuts->SetPtRange(0.15);
-
-   fNumberOfESDTracks = 0;
-   for(Int_t iTracks = 0; iTracks < fInputEvent->GetNumberOfTracks(); iTracks++){
-      AliESDtrack* curTrack = (AliESDtrack*)fInputEvent->GetTrack(iTracks);
-      if(!curTrack) continue;
-      // if(fMCEvent && fConversionCuts->GetSignalRejection() != 0){
-      //    if(!fConversionCuts->IsParticleFromBGEvent(abs(curTrack->GetLabel()), fMCStack)) continue;
-      // }
-      if(EsdTrackCuts->AcceptTrack(curTrack) ) fNumberOfESDTracks++;
+      fNumberOfESDTracks = 0;
+      for(Int_t iTracks = 0; iTracks < fInputEvent->GetNumberOfTracks(); iTracks++){
+         AliESDtrack* curTrack = (AliESDtrack*) fInputEvent->GetTrack(iTracks);
+         if(!curTrack) continue;
+         // if(fMCEvent && ((AliConversionCuts*)fCutArray->At(fiCut))->GetSignalRejection() != 0){
+         //    if(!((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(abs(curTrack->GetLabel()), fMCStack)) continue;
+         // }
+         if(EsdTrackCuts->AcceptTrack(curTrack) ) fNumberOfESDTracks++;
+      }
+      delete EsdTrackCuts;
+      EsdTrackCuts=0x0;
    }
-   delete EsdTrackCuts;
-   EsdTrackCuts=0x0;
-
+   else if(fInputEvent->IsA()==AliAODEvent::Class()){
+      fNumberOfESDTracks = 0;
+      for(Int_t iTracks = 0; iTracks<fInputEvent->GetNumberOfTracks(); iTracks++){
+         AliAODTrack* curTrack = (AliAODTrack*) fInputEvent->GetTrack(iTracks);
+         if(!curTrack->IsPrimaryCandidate()) continue;
+         if(abs(curTrack->Eta())>0.8) continue;
+         if(curTrack->Pt()<0.15) continue;
+         if(abs(curTrack->ZAtDCA())>2) continue;
+         fNumberOfESDTracks++;
+      }
+   }
+   
    return;
 }
 //________________________________________________________________________
-Bool_t AliAnalysisTaskConversionQA::IsTruePhoton(AliAODConversionPhoton *TruePhotonCandidate)
+Bool_t AliAnalysisTaskConversionQA::IsTruePhotonESD(AliAODConversionPhoton *TruePhotonCandidate)
 {
    TParticle *posDaughter = TruePhotonCandidate->GetPositiveMCDaughter(fMCStack);
    TParticle *negDaughter = TruePhotonCandidate->GetNegativeMCDaughter(fMCStack);
@@ -554,6 +681,109 @@ Bool_t AliAnalysisTaskConversionQA::IsTruePhoton(AliAODConversionPhoton *TruePho
 }
 
 //________________________________________________________________________
+Bool_t AliAnalysisTaskConversionQA::IsTruePhotonAOD(AliAODConversionPhoton *TruePhotonCandidate)
+{   
+   TClonesArray *AODMCTrackArray = dynamic_cast<TClonesArray*>(fInputEvent->FindListObject(AliAODMCParticle::StdBranchName()));
+   AliAODMCParticle *posDaughter = (AliAODMCParticle*) AODMCTrackArray->At(TruePhotonCandidate->GetMCLabelPositive());
+   AliAODMCParticle *negDaughter = (AliAODMCParticle*) AODMCTrackArray->At(TruePhotonCandidate->GetMCLabelNegative());
+   
+   if(posDaughter == NULL || negDaughter == NULL) return kFALSE; // One particle does not exist
+   Int_t pdgCode[2] = {abs(posDaughter->GetPdgCode()),abs(negDaughter->GetPdgCode())};
+   if(posDaughter->GetMother() != negDaughter->GetMother()) return kFALSE;
+   else if(posDaughter->GetMother() == -1) return kFALSE;
+      
+   if(pdgCode[0]!=11 || pdgCode[1]!=11) return kFALSE; //One Particle is not a electron
+
+   if(posDaughter->GetPdgCode()==negDaughter->GetPdgCode()) return kFALSE; // Same Charge
+
+   if(((posDaughter->GetMCProcessCode())) != 5 || ((negDaughter->GetMCProcessCode())) != 5) return kFALSE;// check if the daughters come from a conversion 
+   // STILL A BUG IN ALIROOT >>8 HAS TPO BE REMOVED AFTER FIX
+   
+   AliAODMCParticle *Photon = (AliAODMCParticle*) AODMCTrackArray->At(posDaughter->GetMother());
+   if(Photon->GetPdgCode() != 22) return kFALSE; // Mother is no Photon
+
+   return kTRUE;
+}
+
+//________________________________________________________________________
+void AliAnalysisTaskConversionQA::RelabelAODPhotonCandidates(Bool_t mode){
+
+   // Relabeling For AOD Event
+   // ESDiD -> AODiD
+   // MCLabel -> AODMCLabel
+   
+   if(mode){
+      fMCStackPos = new Int_t[fConversionGammas->GetEntries()];
+      fMCStackNeg = new Int_t[fConversionGammas->GetEntries()];
+   }
+   
+   for(Int_t iGamma = 0;iGamma<fConversionGammas->GetEntries();iGamma++){
+      AliAODConversionPhoton* PhotonCandidate = (AliAODConversionPhoton*) fConversionGammas->At(iGamma);
+      if(!PhotonCandidate) continue;
+      if(!mode){// Back to ESD Labels
+         PhotonCandidate->SetMCLabelPositive(fMCStackPos[iGamma]);
+         PhotonCandidate->SetMCLabelNegative(fMCStackNeg[iGamma]);
+         //PhotonCandidate->IsAODMCLabel(kFALSE);
+         continue;
+      }
+      fMCStackPos[iGamma] =  PhotonCandidate->GetMCLabelPositive();
+      fMCStackNeg[iGamma] =  PhotonCandidate->GetMCLabelNegative();
+
+      Bool_t AODLabelPos = kFALSE;
+      Bool_t AODLabelNeg = kFALSE;
+
+      for(Int_t i = 0; i<fInputEvent->GetNumberOfTracks();i++){
+         AliAODTrack *tempDaughter = static_cast<AliAODTrack*>(fInputEvent->GetTrack(i));
+         if(!AODLabelPos){
+            if( tempDaughter->GetID() == PhotonCandidate->GetTrackLabelPositive() ){
+               PhotonCandidate->SetMCLabelPositive(abs(tempDaughter->GetLabel()));
+               AODLabelPos = kTRUE;
+            }
+         }
+         if(!AODLabelNeg){
+            if( tempDaughter->GetID() == PhotonCandidate->GetTrackLabelNegative()){
+               PhotonCandidate->SetMCLabelNegative(abs(tempDaughter->GetLabel()));
+               AODLabelNeg = kTRUE;
+            }
+         }
+         if(AODLabelNeg && AODLabelPos){
+            break;
+         }
+      } // Both ESD Tracks have AOD Tracks with Positive IDs
+      if(!AODLabelPos || !AODLabelNeg){
+         for(Int_t i = 0; i<fInputEvent->GetNumberOfTracks();i++){
+            AliAODTrack *tempDaughter = static_cast<AliAODTrack*>(fInputEvent->GetTrack(i));
+            if(tempDaughter->GetID()<0){
+               if(!AODLabelPos){
+                  if( (abs(tempDaughter->GetID())-1) == PhotonCandidate->GetTrackLabelPositive()){
+                     PhotonCandidate->SetMCLabelPositive(abs(tempDaughter->GetLabel()));
+                     AODLabelPos = kTRUE;
+                  }
+               }
+               if(!AODLabelNeg){
+                  if( (abs(tempDaughter->GetID())-1) == PhotonCandidate->GetTrackLabelNegative()){
+                     PhotonCandidate->SetMCLabelNegative(abs(tempDaughter->GetLabel()));
+                     AODLabelNeg = kTRUE;
+                  }
+               }
+            }
+            if(AODLabelNeg && AODLabelPos){
+               break;
+            }
+         }
+         if(!AODLabelPos || !AODLabelNeg){
+            cout<<"WARNING!!! AOD TRACKS NOT FOUND FOR"<<endl;
+         }
+      }
+   }
+   
+   if(!mode){
+      delete[] fMCStackPos;
+      delete[] fMCStackNeg;
+   }
+}
+
+//________________________________________________________________________
 void AliAnalysisTaskConversionQA::Terminate(Option_t *)
 {
 
index a945c20..eb171ba 100644 (file)
@@ -21,7 +21,8 @@ using namespace std;
 class AliAnalysisTaskConversionQA : public AliAnalysisTaskSE{
 
  public:
-
+   
+   AliAnalysisTaskConversionQA();
    AliAnalysisTaskConversionQA(const char *name);
    virtual ~AliAnalysisTaskConversionQA();
 
@@ -39,7 +40,8 @@ class AliAnalysisTaskConversionQA : public AliAnalysisTaskSE{
       ffillTree = fillTree;
       ffillHistograms = fillHistorams;
    }
-    
+   void SetIsMC(Bool_t isMC){fIsMC = isMC;}
+   
  private:
     
    AliAnalysisTaskConversionQA(const AliAnalysisTaskConversionQA&); // Prevent copy-construction
@@ -47,9 +49,13 @@ class AliAnalysisTaskConversionQA : public AliAnalysisTaskSE{
 
    void ProcessQATree(AliAODConversionPhoton *gamma);
    void ProcessQA(AliAODConversionPhoton *gamma);
-   void ProcessTrueQA(AliAODConversionPhoton *TruePhotonCandidate, AliESDtrack *elec, AliESDtrack *posi);
-   Bool_t IsTruePhoton(AliAODConversionPhoton *TruePhotonCandidate);
-   void CountESDTracks();
+   void RelabelAODPhotonCandidates(Bool_t mode);
+   void ProcessTrueQAESD(AliAODConversionPhoton *TruePhotonCandidate, AliESDtrack *elec, AliESDtrack *posi);
+   void ProcessTrueQAAOD(AliAODConversionPhoton *TruePhotonCandidate, AliAODTrack *elec, AliAODTrack *posi);
+   Bool_t IsTruePhotonESD(AliAODConversionPhoton *TruePhotonCandidate);
+   Bool_t IsTruePhotonAOD(AliAODConversionPhoton *TruePhotonCandidate);
+   void CountTracks();
+   
        
    AliV0ReaderV1 *fV0Reader;    
    TClonesArray *fConversionGammas;
@@ -84,9 +90,9 @@ class AliAnalysisTaskConversionQA : public AliAnalysisTaskSE{
    TH1F *hElecNfindableClsTPC;
    TH1F *hPosiNfindableClsTPC;
    TList *fTrueList;
-   TH2F *hTrueResoulutionR;
-   TH2F *hTrueResoulutionZ;
-   TH2F *hTrueResoulutionPhi;
+   TH2F *hTrueResolutionR;
+   TH2F *hTrueResolutionZ;
+   TH2F *hTrueResolutionPhi;
    TH1F *hTrueGammaPt;
    TH1F *hTrueGammaPhi;
    TH1F *hTrueGammaEta;
@@ -102,8 +108,11 @@ class AliAnalysisTaskConversionQA : public AliAnalysisTaskSE{
    TH2F *hTrueElecPhi;
    TH1F *hTrueElecNfindableClsTPC;
    TH1F *hTruePosiNfindableClsTPC;
-    
-   ClassDef(AliAnalysisTaskConversionQA, 1);
+   Bool_t fIsMC;
+   Int_t fnGammaCandidates;
+   Int_t *fMCStackPos;     //[fnGammaCandidates]
+   Int_t *fMCStackNeg;     //[fnGammaCandidates]
+   ClassDef(AliAnalysisTaskConversionQA, 2);
 };
 
 #endif
index f18e7f4..4a81162 100644 (file)
@@ -92,10 +92,13 @@ fV0Reader(NULL),
    hESDMotherInvMassPt(NULL),
    hESDPi0MotherInvMassPt(NULL),
    hESDPi0MotherDiffInvMassPt(NULL),
+   hESDPi0MotherDiffLimInvMassPt(NULL),
    sESDMotherInvMassPtZM(NULL),
    hESDMotherBackInvMassPt(NULL),
    sESDMotherBackInvMassPtZM(NULL),
    hMCAllGammaPt(NULL),
+   hMCConvGammaPt(NULL),
+   hMCConvGammaRSPt(NULL),
    hMCAllPositronsPt(NULL),
    hMCAllElectronsPt(NULL),
    hMCPi0DalitzGammaPt(NULL),
@@ -114,6 +117,7 @@ fV0Reader(NULL),
    hESDEposEnegTruePhotonInvMassPt(NULL),
    hESDEposEnegTrueJPsiInvMassPt(NULL),
    hESDTrueMotherChiCInvMassPt(NULL),
+   hESDTrueMotherChiCDiffInvMassPt(NULL),
    hESDTrueMotherInvMassPt(NULL),
    hESDTrueMotherPi0GGInvMassPt(NULL),
    hESDTruePrimaryMotherInvMassMCPt(NULL),
@@ -126,9 +130,15 @@ fV0Reader(NULL),
    hESDTrueConvGammaPt(NULL),
    hESDTruePositronPt(NULL),
    hESDTrueElectronPt(NULL),
+   hESDTrueSecConvGammaPt(NULL),
+   hESDTrueSecPositronPt(NULL),
+   hESDTrueSecElectronPt(NULL),
    hESDTruePi0DalitzConvGammaPt(NULL),
    hESDTruePi0DalitzPositronPt(NULL),
    hESDTruePi0DalitzElectronPt(NULL),
+   hESDTruePi0DalitzSecConvGammaPt(NULL),
+   hESDTruePi0DalitzSecPositronPt(NULL),
+   hESDTruePi0DalitzSecElectronPt(NULL),
    hNEvents(NULL),
    hNGoodESDTracks(NULL),
    fRandom(0),
@@ -141,7 +151,9 @@ fV0Reader(NULL),
    fNumberOfESDTracks(0),
    fMoveParticleAccordingToVertex(kFALSE),
    fIsHeavyIon(kFALSE),
-   fDoMesonAnalysis(kTRUE)
+   fDoMesonAnalysis(kTRUE),
+   fIsFromMBHeader(kTRUE),
+   fIsMC(kFALSE)
 {
 
 }
@@ -182,10 +194,13 @@ AliAnalysisTaskGammaConvDalitzV1::AliAnalysisTaskGammaConvDalitzV1( const char*
    hESDMotherInvMassPt(NULL),
    hESDPi0MotherInvMassPt(NULL),
    hESDPi0MotherDiffInvMassPt(NULL),
+   hESDPi0MotherDiffLimInvMassPt(NULL),
    sESDMotherInvMassPtZM(NULL),
    hESDMotherBackInvMassPt(NULL),
    sESDMotherBackInvMassPtZM(NULL),
    hMCAllGammaPt(NULL),
+   hMCConvGammaPt(NULL),
+   hMCConvGammaRSPt(NULL),
    hMCAllPositronsPt(NULL),
    hMCAllElectronsPt(NULL),
    hMCPi0DalitzGammaPt(NULL),
@@ -204,6 +219,7 @@ AliAnalysisTaskGammaConvDalitzV1::AliAnalysisTaskGammaConvDalitzV1( const char*
    hESDEposEnegTruePhotonInvMassPt(NULL),
    hESDEposEnegTrueJPsiInvMassPt(NULL),
    hESDTrueMotherChiCInvMassPt(NULL),
+   hESDTrueMotherChiCDiffInvMassPt(NULL),
    hESDTrueMotherInvMassPt(NULL),
    hESDTrueMotherPi0GGInvMassPt(NULL),
    hESDTruePrimaryMotherInvMassMCPt(NULL),
@@ -216,9 +232,15 @@ AliAnalysisTaskGammaConvDalitzV1::AliAnalysisTaskGammaConvDalitzV1( const char*
    hESDTrueConvGammaPt(NULL),
    hESDTruePositronPt(NULL),
    hESDTrueElectronPt(NULL),
+   hESDTrueSecConvGammaPt(NULL),
+   hESDTrueSecPositronPt(NULL),
+   hESDTrueSecElectronPt(NULL),
    hESDTruePi0DalitzConvGammaPt(NULL),
    hESDTruePi0DalitzPositronPt(NULL),
    hESDTruePi0DalitzElectronPt(NULL),
+   hESDTruePi0DalitzSecConvGammaPt(NULL),
+   hESDTruePi0DalitzSecPositronPt(NULL),
+   hESDTruePi0DalitzSecElectronPt(NULL),
    hNEvents(NULL),
    hNGoodESDTracks(NULL),
    fRandom(0),
@@ -231,7 +253,9 @@ AliAnalysisTaskGammaConvDalitzV1::AliAnalysisTaskGammaConvDalitzV1( const char*
    fNumberOfESDTracks(0),
    fMoveParticleAccordingToVertex(kFALSE),
    fIsHeavyIon(kFALSE),
-   fDoMesonAnalysis(kTRUE)
+   fDoMesonAnalysis(kTRUE),
+   fIsFromMBHeader(kTRUE),
+   fIsMC(kFALSE)
 {
    DefineOutput(1, TList::Class());
 }
@@ -404,6 +428,7 @@ void AliAnalysisTaskGammaConvDalitzV1::UserCreateOutputObjects()
    hESDMotherInvMassPt             = new TH2F*[fnCuts];
    hESDPi0MotherInvMassPt          = new TH2F*[fnCuts];
    hESDPi0MotherDiffInvMassPt      = new TH2F*[fnCuts];
+   hESDPi0MotherDiffLimInvMassPt      = new TH2F*[fnCuts];
    hESDMotherBackInvMassPt         = new TH2F*[fnCuts];
 
 
@@ -446,10 +471,10 @@ void AliAnalysisTaskGammaConvDalitzV1::UserCreateOutputObjects()
       hESDConvGammaPt[iCut] = new TH1F("ESD_ConvGamma_Pt","ESD_ConvGamma_Pt",250,0,25);
       fESDList[iCut]->Add(hESDConvGammaPt[iCut]);
 
-      hESDDalitzElectronPt[iCut] = new TH1F("ESD_DalitzElectron_Pt","ESD_DalitzElectron_Pt",250,0,25);
+      hESDDalitzElectronPt[iCut] = new TH1F("ESD_DalitzElectron_Pt","ESD_DalitzElectron_Pt",1000,0,25);
       fESDList[iCut]->Add(hESDDalitzElectronPt[iCut]);
 
-      hESDDalitzPositronPt[iCut] = new TH1F("ESD_DalitzPositron_Pt","ESD_DalitzPositron_Pt",250,0,25);
+      hESDDalitzPositronPt[iCut] = new TH1F("ESD_DalitzPositron_Pt","ESD_DalitzPositron_Pt",1000,0,25);
       fESDList[iCut]->Add(hESDDalitzPositronPt[iCut]);
 
 
@@ -472,9 +497,12 @@ void AliAnalysisTaskGammaConvDalitzV1::UserCreateOutputObjects()
       hESDPi0MotherDiffInvMassPt[iCut] = new TH2F("ESD_Pi0Mother_DiffInvMass_Pt","ESD_Pi0Mother_DiffInvMass_Pt",2000,0,2,250,0,25);
       fESDList[iCut]->Add(hESDPi0MotherDiffInvMassPt[iCut]);
 
+      hESDPi0MotherDiffLimInvMassPt[iCut] = new TH2F("ESD_Pi0Mother_DiffLimInvMass_Pt","ESD_Pi0Mother_DiffLimInvMass_Pt",2000,0,2,250,0,25);
+      fESDList[iCut]->Add(hESDPi0MotherDiffLimInvMassPt[iCut]);
 
       hESDMotherBackInvMassPt[iCut] = new TH2F("ESD_DalitzBackground_InvMass_Pt","ESD_DalitzBackground_InvMass_Pt",1000,0,1,250,0,25);
       fESDList[iCut]->Add(hESDMotherBackInvMassPt[iCut]);
+      
 
       fCutFolder[iCut]->Add(fESDList[iCut]);
 
@@ -486,7 +514,8 @@ void AliAnalysisTaskGammaConvDalitzV1::UserCreateOutputObjects()
    InitBack(); // Init Background Handler
 
 
-   if(MCEvent()){
+   //if(MCEvent()){
+    if( fIsMC ){
       // MC Histogramms
       fMCList = new TList*[fnCuts];
       // True Histogramms
@@ -494,11 +523,19 @@ void AliAnalysisTaskGammaConvDalitzV1::UserCreateOutputObjects()
       hESDTrueConvGammaPt = new TH1F*[fnCuts];
       hESDTruePositronPt  = new TH1F*[fnCuts];
       hESDTrueElectronPt  = new TH1F*[fnCuts];
+      hESDTrueSecConvGammaPt = new TH1F*[fnCuts];
+      hESDTrueSecPositronPt  = new TH1F*[fnCuts];
+      hESDTrueSecElectronPt  = new TH1F*[fnCuts];
       hESDTruePi0DalitzConvGammaPt = new TH1F*[fnCuts];
       hESDTruePi0DalitzPositronPt  = new TH1F*[fnCuts];
       hESDTruePi0DalitzElectronPt  = new TH1F*[fnCuts];
+      hESDTruePi0DalitzSecConvGammaPt = new TH1F*[fnCuts];
+      hESDTruePi0DalitzSecPositronPt  = new TH1F*[fnCuts];
+      hESDTruePi0DalitzSecElectronPt  = new TH1F*[fnCuts];
       //if(fDoMesonAnalysis){
-      hMCAllGammaPt = new TH1F*[fnCuts];
+      hMCAllGammaPt  = new TH1F*[fnCuts];
+      hMCConvGammaPt = new TH1F*[fnCuts];
+      hMCConvGammaRSPt = new TH1F*[fnCuts];
       hMCAllPositronsPt = new TH1F*[fnCuts];
       hMCAllElectronsPt = new TH1F*[fnCuts];
       hMCPi0DalitzGammaPt    = new TH1F*[fnCuts];
@@ -520,6 +557,7 @@ void AliAnalysisTaskGammaConvDalitzV1::UserCreateOutputObjects()
       hESDEposEnegTrueJPsiInvMassPt                = new TH2F*[fnCuts];
       
       hESDTrueMotherChiCInvMassPt = new TH2F*[fnCuts];
+      hESDTrueMotherChiCDiffInvMassPt = new TH2F*[fnCuts];
       hESDTrueMotherInvMassPt = new TH2F*[fnCuts];
       hESDTrueMotherPi0GGInvMassPt = new TH2F*[fnCuts];
       hESDTruePrimaryPi0DalitzESDPtMCPt = new TH2F*[fnCuts];
@@ -542,22 +580,29 @@ void AliAnalysisTaskGammaConvDalitzV1::UserCreateOutputObjects()
          fCutFolder[iCut]->Add(fMCList[iCut]);
 
 
-                                hMCAllGammaPt[iCut] = new TH1F("MC_AllGamma_Pt","MC_AllGamma_Pt",250,0,25);
-                                fMCList[iCut]->Add(hMCAllGammaPt[iCut]);
+       hMCAllGammaPt[iCut] = new TH1F("MC_AllGamma_Pt","MC_AllGamma_Pt",250,0,25);
+       fMCList[iCut]->Add(hMCAllGammaPt[iCut]);
+       
+       hMCConvGammaPt[iCut] = new TH1F("MC_ConvGamma_Pt","MC_ConvGamma_Pt",250,0,25);
+       fMCList[iCut]->Add(hMCConvGammaPt[iCut]);
+       
+       hMCConvGammaRSPt[iCut] = new TH1F("MC_ConvGamma_RS_Pt","MC_ConvGamma_RS_Pt",250,0,25);
+        fMCList[iCut]->Add(hMCConvGammaRSPt[iCut]);
+       
                                 
-                                hMCAllPositronsPt[iCut] = new TH1F("MC_AllPositrons_Pt","MC_AllPositrons_Pt",250,0,25);
-                                fMCList[iCut]->Add(hMCAllPositronsPt[iCut]);
+       hMCAllPositronsPt[iCut] = new TH1F("MC_AllPositrons_Pt","MC_AllPositrons_Pt",1000,0,25);
+       fMCList[iCut]->Add(hMCAllPositronsPt[iCut]);
                                 
-                                hMCAllElectronsPt[iCut] = new TH1F("MC_AllElectrons_Pt","MC_AllElectrons_Pt",250,0,25);
+                                hMCAllElectronsPt[iCut] = new TH1F("MC_AllElectrons_Pt","MC_AllElectrons_Pt",1000,0,25);
                                 fMCList[iCut]->Add(hMCAllElectronsPt[iCut]);
                                 
                                 hMCPi0DalitzGammaPt[iCut] = new TH1F("MC_Pi0DalitzGamma_Pt","MC_Pi0DalitzGamma_Pt",250,0,25);
                                 fMCList[iCut]->Add(hMCPi0DalitzGammaPt[iCut]);
                                 
-                                hMCPi0DalitzPositronPt[iCut] = new TH1F("MC_Pi0DalitzPositron_Pt","MC_Pi0DalitzPositron_Pt",250,0,25);
+                                hMCPi0DalitzPositronPt[iCut] = new TH1F("MC_Pi0DalitzPositron_Pt","MC_Pi0DalitzPositron_Pt",1000,0,25);
                                 fMCList[iCut]->Add(hMCPi0DalitzPositronPt[iCut]);
                                 
-                                hMCPi0DalitzElectronPt[iCut] = new TH1F("MC_Pi0DalitzElectron_Pt","MC_Pi0DalitzElectron_Pt",250,0,25);
+                                hMCPi0DalitzElectronPt[iCut] = new TH1F("MC_Pi0DalitzElectron_Pt","MC_Pi0DalitzElectron_Pt",1000,0,25);
                                 fMCList[iCut]->Add(hMCPi0DalitzElectronPt[iCut]);
                                 
                                 
@@ -591,42 +636,60 @@ void AliAnalysisTaskGammaConvDalitzV1::UserCreateOutputObjects()
          fCutFolder[iCut]->Add(fTrueList[iCut]);
 
         
-                                hESDEposEnegTruePi0DalitzInvMassPt[iCut] = new TH2F("ESD_EposEneg_TruePi0Dalitz_InvMassPt","ESD_EposEneg_TruePi0Dalitz_InvMassPt",5000,0.,5.,100,0.,10.);
-                                fTrueList[iCut]->Add(hESDEposEnegTruePi0DalitzInvMassPt[iCut]);
+        hESDEposEnegTruePi0DalitzInvMassPt[iCut] = new TH2F("ESD_EposEneg_TruePi0Dalitz_InvMassPt","ESD_EposEneg_TruePi0Dalitz_InvMassPt",5000,0.,5.,100,0.,10.);
+        fTrueList[iCut]->Add(hESDEposEnegTruePi0DalitzInvMassPt[iCut]);
         
-                                hESDEposEnegTrueEtaDalitzInvMassPt[iCut] = new TH2F("ESD_EposEneg_TrueEtaDalitz_InvMassPt","ESD_EposEneg_TrueEtaDalitz_InvMassPt",5000,0.,5.,100,0.,10.);
-                                fTrueList[iCut]->Add(hESDEposEnegTrueEtaDalitzInvMassPt[iCut]);
+        hESDEposEnegTrueEtaDalitzInvMassPt[iCut] = new TH2F("ESD_EposEneg_TrueEtaDalitz_InvMassPt","ESD_EposEneg_TrueEtaDalitz_InvMassPt",5000,0.,5.,100,0.,10.);
+        fTrueList[iCut]->Add(hESDEposEnegTrueEtaDalitzInvMassPt[iCut]);
         
-                                hESDEposEnegTruePhotonInvMassPt[iCut] = new TH2F("ESD_EposEneg_TruePhoton_InvMassPt","ESD_EposEneg_TruePhoton_InvMassPt",5000,0.,5.,100,0.,10.);
-                                fTrueList[iCut]->Add(hESDEposEnegTruePhotonInvMassPt[iCut]);
+        hESDEposEnegTruePhotonInvMassPt[iCut] = new TH2F("ESD_EposEneg_TruePhoton_InvMassPt","ESD_EposEneg_TruePhoton_InvMassPt",5000,0.,5.,100,0.,10.);
+        fTrueList[iCut]->Add(hESDEposEnegTruePhotonInvMassPt[iCut]);
         
-                                hESDEposEnegTrueJPsiInvMassPt[iCut] = new TH2F("ESD_EposEneg_TrueJPsi_InvMassPt","ESD_EposEneg_TrueJPsi_InvMassPt",5000,0.,5.,100,0.,10.);
-                                fTrueList[iCut]->Add(hESDEposEnegTrueJPsiInvMassPt[iCut]);
+        hESDEposEnegTrueJPsiInvMassPt[iCut] = new TH2F("ESD_EposEneg_TrueJPsi_InvMassPt","ESD_EposEneg_TrueJPsi_InvMassPt",5000,0.,5.,100,0.,10.);
+        fTrueList[iCut]->Add(hESDEposEnegTrueJPsiInvMassPt[iCut]);
 
 
-         hESDTruePositronPt[iCut] = new TH1F("ESD_TruePositron_Pt","ESD_TruePositron_Pt",250,0,25);
+         hESDTruePositronPt[iCut] = new TH1F("ESD_TruePositron_Pt","ESD_TruePositron_Pt",1000,0,25);
          fTrueList[iCut]->Add(hESDTruePositronPt[iCut]);
 
-         hESDTrueElectronPt[iCut] = new TH1F("ESD_TrueElectron_Pt","ESD_TrueElectron_Pt",250,0,25);
+         hESDTrueElectronPt[iCut] = new TH1F("ESD_TrueElectron_Pt","ESD_TrueElectron_Pt",1000,0,25);
          fTrueList[iCut]->Add(hESDTrueElectronPt[iCut]);
+        
+        hESDTrueSecPositronPt[iCut] = new TH1F("ESD_TrueSecPositron_Pt","ESD_TrueSecPositron_Pt",1000,0,25);
+         fTrueList[iCut]->Add(hESDTrueSecPositronPt[iCut]);
+
+         hESDTrueSecElectronPt[iCut] = new TH1F("ESD_TrueSecElectron_Pt","ESD_TrueSecElectron_Pt",1000,0,25);
+         fTrueList[iCut]->Add(hESDTrueSecElectronPt[iCut]); 
 
          hESDTrueConvGammaPt[iCut] = new TH1F("ESD_TrueConvGamma_Pt","ESD_TrueConvGamma_Pt",250,0,25);
          fTrueList[iCut]->Add(hESDTrueConvGammaPt[iCut]);
+        
+        hESDTrueSecConvGammaPt[iCut] = new TH1F("ESD_TrueSecConvGamma_Pt","ESD_TrueSecConvGamma_Pt",250,0,25);
+         fTrueList[iCut]->Add(hESDTrueSecConvGammaPt[iCut]);
 
          hESDTruePi0DalitzConvGammaPt[iCut] = new TH1F("ESD_TruePi0DalitzConvGamma_Pt","ESD_TruePi0DalitzConvGamma_Pt",250,0,25);
          fTrueList[iCut]->Add(hESDTruePi0DalitzConvGammaPt[iCut]);
 
-         hESDTruePi0DalitzElectronPt[iCut] = new TH1F("ESD_TruePi0DalitzElectron_Pt","ESD_TruePi0DalitzElectron_Pt",250,0,25);
+         hESDTruePi0DalitzElectronPt[iCut] = new TH1F("ESD_TruePi0DalitzElectron_Pt","ESD_TruePi0DalitzElectron_Pt",1000,0,25);
          fTrueList[iCut]->Add(hESDTruePi0DalitzElectronPt[iCut]);
 
-         hESDTruePi0DalitzPositronPt[iCut] = new TH1F("ESD_TruePi0DalitzPositron_Pt","ESD_TruePi0DalitzPositron_Pt",250,0,25);
+         hESDTruePi0DalitzPositronPt[iCut] = new TH1F("ESD_TruePi0DalitzPositron_Pt","ESD_TruePi0DalitzPositron_Pt",1000,0,25);
          fTrueList[iCut]->Add(hESDTruePi0DalitzPositronPt[iCut]);
+        
+        hESDTruePi0DalitzSecConvGammaPt[iCut] = new TH1F("ESD_TruePi0DalitzSecConvGamma_Pt","ESD_TruePi0DalitzSecConvGamma_Pt",250,0,25);
+         fTrueList[iCut]->Add(hESDTruePi0DalitzSecConvGammaPt[iCut]);
+        
+        hESDTruePi0DalitzSecElectronPt[iCut] = new TH1F("ESD_TruePi0DalitzSecElectron_Pt","ESD_TruePi0DalitzSecElectron_Pt",1000,0,25);
+         fTrueList[iCut]->Add(hESDTruePi0DalitzSecElectronPt[iCut]);
 
+         hESDTruePi0DalitzSecPositronPt[iCut] = new TH1F("ESD_TruePi0DalitzSecPositron_Pt","ESD_TruePi0DalitzSecPositron_Pt",1000,0,25);
+         fTrueList[iCut]->Add(hESDTruePi0DalitzSecPositronPt[iCut]);
 
-
-                                hESDTrueMotherChiCInvMassPt[iCut] = new TH2F("ESD_TrueMotherChiC_InvMass_Pt","ESD_TrueMotherChiC_InvMass_Pt",1000,0,1,250,0,25);
+        hESDTrueMotherChiCInvMassPt[iCut] = new TH2F("ESD_TrueMotherChiC_InvMass_Pt","ESD_TrueMotherChiC_InvMass_Pt",1000,0,4,250,0,25);
          fTrueList[iCut]->Add(hESDTrueMotherChiCInvMassPt[iCut]);
 
+        hESDTrueMotherChiCDiffInvMassPt[iCut] = new TH2F("ESD_TrueMotherChiCDiff_InvMass_Pt","ESD_TrueMotherChiCDiff_InvMass_Pt",1000,0,1,250,0,25);
+         fTrueList[iCut]->Add(hESDTrueMotherChiCDiffInvMassPt[iCut]);
 
          hESDTrueMotherInvMassPt[iCut] = new TH2F("ESD_TrueMother_InvMass_Pt","ESD_TrueMother_InvMass_Pt",1000,0,1,250,0,25);
          fTrueList[iCut]->Add(hESDTrueMotherInvMassPt[iCut]);
@@ -663,7 +726,6 @@ void AliAnalysisTaskGammaConvDalitzV1::UserExec(Option_t *)
    // Execute analysis for current event
    //
 
-
    fV0Reader=(AliV0ReaderV1*)AliAnalysisManager::GetAnalysisManager()->GetTask("V0ReaderV1");
    if(!fV0Reader){printf("Error: No V0 Reader");return;} // GetV0Reader
 
@@ -671,20 +733,18 @@ void AliAnalysisTaskGammaConvDalitzV1::UserExec(Option_t *)
    Int_t eventQuality = ((AliConversionCuts*)fV0Reader->GetConversionCuts())->GetEventQuality();
 
    if(eventQuality == 2 || eventQuality == 3){// Event Not Accepted due to MC event missing or wrong trigger for V0ReaderV1
-      for(Int_t iCut = 0; iCut<fnCuts; iCut++){
-         hNEvents[iCut]->Fill(eventQuality);
-      }
+        for(Int_t iCut = 0; iCut<fnCuts; iCut++){
+          hNEvents[iCut]->Fill(eventQuality);
+        }
       return;
    }
 
 
-
-
    fElecSelector=(AliDalitzElectronSelector*)AliAnalysisManager::GetAnalysisManager()->GetTask("ElectronSelector");
    if(!fElecSelector){printf("Error: No ElectronSelector");return;} // GetV0Reader
 
 
-   fMCEvent         =  MCEvent();
+   if(fIsMC)         fMCEvent        =  MCEvent();
    fESDEvent        = (AliESDEvent*)InputEvent();
    fReaderGammas    = fV0Reader->GetReconstructedGammas(); // Gammas from default Cut
    fSelectorElectronIndex = fElecSelector->GetReconstructedElectronsIndex(); // Electrons from default Cut
@@ -699,6 +759,7 @@ void AliAnalysisTaskGammaConvDalitzV1::UserExec(Option_t *)
       Int_t eventNotAccepted =
          ((AliConversionCuts*)fCutGammaArray->At(iCut))
          ->IsEventAcceptedByConversionCut(fV0Reader->GetConversionCuts(),fInputEvent,fMCEvent,fIsHeavyIon);
+        
       if(eventNotAccepted){
          //                    cout << "event rejected due to wrong trigger: " <<eventNotAccepted << endl;
          hNEvents[iCut]->Fill(eventNotAccepted); // Check Centrality, PileUp, SDD and V0AND --> Not Accepted => eventQuality = 1
@@ -716,18 +777,61 @@ void AliAnalysisTaskGammaConvDalitzV1::UserExec(Option_t *)
       hNGoodESDTracks[iCut]->Fill(fNumberOfESDTracks);
 
       if(fMCEvent){ // Process MC Particle
-         fMCStack = fMCEvent->Stack();
+         
+       
+       
+       fMCStack = fMCEvent->Stack();
+        
+         if(((AliConversionCuts*)fCutGammaArray->At(iCut))->GetSignalRejection() != 0){
+             ((AliConversionCuts*)fCutGammaArray->At(iCut))->GetNotRejectedParticles(((AliConversionCuts*)fCutGammaArray->At(iCut))->GetSignalRejection(),
+                                                                                    ((AliConversionCuts*)fCutGammaArray->At(iCut))->GetAcceptedHeader(),
+                                                                                      fMCEvent);
+         } 
+        
          ProcessMCParticles();
       }
 
-
-
       ProcessPhotonCandidates(); // Process this cuts gammas
       ProcessElectronCandidates(); // Process this cuts gammas
+      
+      if(((AliConversionMesonCuts*)fCutMesonArray->At(iCut))->UseMCPSmearing() && fMCEvent){
+       
+            fUnsmearedPx = new Double_t[fGoodGammas->GetEntries()]; // Store unsmeared Momenta
+            fUnsmearedPy = new Double_t[fGoodGammas->GetEntries()];
+            fUnsmearedPz = new Double_t[fGoodGammas->GetEntries()];
+            fUnsmearedE =  new Double_t[fGoodGammas->GetEntries()];
+
+            for(Int_t gamma=0;gamma<fGoodGammas->GetEntries();gamma++){ // Smear the AODPhotons in MC
+             
+               fUnsmearedPx[gamma] = ((AliAODConversionPhoton*)fGoodGammas->At(gamma))->Px();
+               fUnsmearedPy[gamma] = ((AliAODConversionPhoton*)fGoodGammas->At(gamma))->Py();
+               fUnsmearedPz[gamma] = ((AliAODConversionPhoton*)fGoodGammas->At(gamma))->Pz();
+               fUnsmearedE[gamma] =  ((AliAODConversionPhoton*)fGoodGammas->At(gamma))->E();
+               ((AliConversionMesonCuts*)fCutMesonArray->At(iCut))->SmearParticle(dynamic_cast<AliAODConversionPhoton*>(fGoodGammas->At(gamma)));
+              
+            }           
+        }
+  
+
       CalculatePi0DalitzCandidates();
       CalculateBackground();
       UpdateEventByEventData();
-
+      
+      
+      if(((AliConversionMesonCuts*)fCutMesonArray->At(iCut))->UseMCPSmearing() && fMCEvent){
+       
+          for(Int_t gamma=0;gamma<fGoodGammas->GetEntries();gamma++){ // Smear the AODPhotons in MC
+               ((AliAODConversionPhoton*)fGoodGammas->At(gamma))->SetPx(fUnsmearedPx[gamma]); // Reset Unsmeared Momenta
+               ((AliAODConversionPhoton*)fGoodGammas->At(gamma))->SetPy(fUnsmearedPy[gamma]);
+               ((AliAODConversionPhoton*)fGoodGammas->At(gamma))->SetPz(fUnsmearedPz[gamma]);
+               ((AliAODConversionPhoton*)fGoodGammas->At(gamma))->SetE(fUnsmearedE[gamma]);
+            }
+            delete[] fUnsmearedPx; fUnsmearedPx = 0x0;
+            delete[] fUnsmearedPy; fUnsmearedPy = 0x0;
+            delete[] fUnsmearedPz; fUnsmearedPz = 0x0;
+            delete[] fUnsmearedE;  fUnsmearedE  = 0x0;
+           
+       }
 
 
       fGoodGammas->Clear(); // delete this cuts good gammas
@@ -740,6 +844,29 @@ void AliAnalysisTaskGammaConvDalitzV1::UserExec(Option_t *)
    PostData( 1, fOutputContainer );
 }
 
+Bool_t AliAnalysisTaskGammaConvDalitzV1::Notify()
+{
+   for(Int_t iCut = 0; iCut<fnCuts;iCut++){
+      if(!((AliConversionCuts*)fCutGammaArray->At(iCut))->GetDoEtaShift()) continue; // No Eta Shift requested, continue
+      
+      if( ((AliConversionCuts*)fCutGammaArray->At(iCut))->GetEtaShift() == 0.0){ // Eta Shift requested but not set, get shift automatically
+         ((AliConversionCuts*)fCutGammaArray->At(iCut))->GetCorrectEtaShiftFromPeriod(fV0Reader->GetPeriodName());
+         ((AliConversionCuts*)fCutGammaArray->At(iCut))->DoEtaShift(kFALSE); // Eta Shift Set, make sure that it is called only once   
+        ((AliDalitzElectronCuts*)fCutElectronArray->At(iCut))->SetEtaShift( ((AliConversionCuts*)fCutGammaArray->At(iCut))->GetEtaShift() );
+         continue;
+      }
+      else{
+         printf(" Gamma Conversion Task %s :: Eta Shift Manually Set to %f \n\n",
+         (((AliConversionCuts*)fCutGammaArray->At(iCut))->GetCutNumber()).Data(),((AliConversionCuts*)fCutGammaArray->At(iCut))->GetEtaShift());
+         ((AliConversionCuts*)fCutGammaArray->At(iCut))->DoEtaShift(kFALSE); // Eta Shift Set, make sure that it is called only once   
+        ((AliDalitzElectronCuts*)fCutElectronArray->At(iCut))->SetEtaShift( ((AliConversionCuts*)fCutGammaArray->At(iCut))->GetEtaShift() );
+      }
+   }
+   
+   return kTRUE;
+}
+
+
 void AliAnalysisTaskGammaConvDalitzV1::Terminate(const Option_t *)
 {
 
@@ -750,8 +877,7 @@ void AliAnalysisTaskGammaConvDalitzV1::Terminate(const Option_t *)
       }
    }
 
-
-   if ( fV0Reader ) {
+  if ( fV0Reader ) {
 
       if ( ((AliConversionCuts*)fV0Reader->GetConversionCuts())->GetCutHistograms() ){
          fOutputContainer->Add(  ((AliConversionCuts*)fV0Reader->GetConversionCuts())->GetCutHistograms() );
@@ -787,15 +913,37 @@ void AliAnalysisTaskGammaConvDalitzV1::ProcessPhotonCandidates()
    TList *GoodGammasStepOne = new TList();
    TList *GoodGammasStepTwo = new TList();
    // Loop over Photon Candidates allocated by ReaderV1
+   
    for(Int_t i = 0; i < fReaderGammas->GetEntriesFast(); i++){
       AliAODConversionPhoton* PhotonCandidate = (AliAODConversionPhoton*) fReaderGammas->At(i);
       if(!PhotonCandidate) continue;
+      
+      
+      fIsFromMBHeader = kTRUE;
+      
+      if( fMCEvent && ((AliConversionCuts*)fCutGammaArray->At(fiCut))->GetSignalRejection() != 0 ){
+       
+         Int_t isPosFromMBHeader
+            = ((AliConversionCuts*)fCutGammaArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelPositive(), fMCStack, fInputEvent);
+         if(isPosFromMBHeader == 0 && ((AliConversionCuts*)fCutGammaArray->At(fiCut))->GetSignalRejection() != 3) continue;
+         
+         Int_t isNegFromMBHeader
+            = ((AliConversionCuts*)fCutGammaArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelNegative(), fMCStack,fInputEvent);
+         if(isNegFromMBHeader == 0 && ((AliConversionCuts*)fCutGammaArray->At(fiCut))->GetSignalRejection() != 3) continue;
+         
+
+         if( (isNegFromMBHeader+isPosFromMBHeader) != 4) fIsFromMBHeader = kFALSE;
+      }
+      
       if(!((AliConversionCuts*)fCutGammaArray->At(fiCut))->PhotonIsSelected(PhotonCandidate,fESDEvent)) continue;
 
       if(!((AliConversionCuts*)fCutGammaArray->At(fiCut))->UseElecSharingCut() &&
          !((AliConversionCuts*)fCutGammaArray->At(fiCut))->UseToCloseV0sCut()){ // if no post reader loop is required add to events good gammas
+         
          fGoodGammas->Add(PhotonCandidate);
-         hESDConvGammaPt[fiCut]->Fill(PhotonCandidate->Pt());
+        if(fIsFromMBHeader){
+             hESDConvGammaPt[fiCut]->Fill(PhotonCandidate->Pt());
+        }
          if(fMCEvent){
             ProcessTruePhotonCandidates(PhotonCandidate);
          }
@@ -806,7 +954,7 @@ void AliAnalysisTaskGammaConvDalitzV1::ProcessPhotonCandidates()
          GoodGammasStepOne->Add(PhotonCandidate);
       }
       else if(!((AliConversionCuts*)fCutGammaArray->At(fiCut))->UseElecSharingCut() &&
-              ((AliConversionCuts*)fCutGammaArray->At(fiCut))->UseToCloseV0sCut()){ // shared electron is disabled, step one not needed -> step two
+               ((AliConversionCuts*)fCutGammaArray->At(fiCut))->UseToCloseV0sCut()){ // shared electron is disabled, step one not needed -> step two
          GoodGammasStepTwo->Add(PhotonCandidate);
       }
    }
@@ -814,10 +962,26 @@ void AliAnalysisTaskGammaConvDalitzV1::ProcessPhotonCandidates()
       for(Int_t i = 0;i<GoodGammasStepOne->GetEntries();i++){
          AliAODConversionPhoton *PhotonCandidate= (AliAODConversionPhoton*) GoodGammasStepOne->At(i);
          if(!PhotonCandidate) continue;
+         
+         
+         fIsFromMBHeader = kTRUE;
+         if(fMCEvent && ((AliConversionCuts*)fCutGammaArray->At(fiCut))->GetSignalRejection() != 0){
+            Int_t isPosFromMBHeader
+               = ((AliConversionCuts*)fCutGammaArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelPositive(), fMCStack,fInputEvent);
+            Int_t isNegFromMBHeader
+               = ((AliConversionCuts*)fCutGammaArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelNegative(), fMCStack,fInputEvent);
+            if( (isNegFromMBHeader+isPosFromMBHeader) != 4) fIsFromMBHeader = kFALSE;
+         }
+         
+         
          if(!((AliConversionCuts*)fCutGammaArray->At(fiCut))->RejectSharedElectronV0s(PhotonCandidate,i,GoodGammasStepOne->GetEntries())) continue;
          if(!((AliConversionCuts*)fCutGammaArray->At(fiCut))->UseToCloseV0sCut()){ // To Colse v0s cut diabled, step two not needed
             fGoodGammas->Add(PhotonCandidate);
-            hESDConvGammaPt[fiCut]->Fill(PhotonCandidate->Pt());
+           
+            if(fIsFromMBHeader){
+               hESDConvGammaPt[fiCut]->Fill(PhotonCandidate->Pt());
+            }
+            
             if(fMCEvent){
                ProcessTruePhotonCandidates(PhotonCandidate);
             }
@@ -829,9 +993,22 @@ void AliAnalysisTaskGammaConvDalitzV1::ProcessPhotonCandidates()
       for(Int_t i = 0;i<GoodGammasStepTwo->GetEntries();i++){
          AliAODConversionPhoton* PhotonCandidate = (AliAODConversionPhoton*) GoodGammasStepTwo->At(i);
          if(!PhotonCandidate) continue;
+         
+         if(fMCEvent && ((AliConversionCuts*)fCutGammaArray->At(fiCut))->GetSignalRejection() != 0){
+            Int_t isPosFromMBHeader
+               = ((AliConversionCuts*)fCutGammaArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelPositive(), fMCStack,fInputEvent);
+            Int_t isNegFromMBHeader
+               = ((AliConversionCuts*)fCutGammaArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelNegative(), fMCStack,fInputEvent);
+            if( (isNegFromMBHeader+isPosFromMBHeader) != 4) fIsFromMBHeader = kFALSE;
+         }
+         
          if(!((AliConversionCuts*)fCutGammaArray->At(fiCut))->RejectToCloseV0s(PhotonCandidate,GoodGammasStepTwo,i)) continue;
          fGoodGammas->Add(PhotonCandidate); // Add gamma to current cut TList
-         hESDConvGammaPt[fiCut]->Fill(PhotonCandidate->Pt()); // Differences to old V0Reader in p_t due to conversion KF->TLorentzVector
+        
+         if(fIsFromMBHeader){
+             hESDConvGammaPt[fiCut]->Fill(PhotonCandidate->Pt()); // Differences to old V0Reader in p_t due to conversion KF->TLorentzVector
+         }
+        
          if(fMCEvent){
             ProcessTruePhotonCandidates(PhotonCandidate);
          }
@@ -856,6 +1033,11 @@ void AliAnalysisTaskGammaConvDalitzV1::ProcessTruePhotonCandidates(AliAODConvers
    if(posDaughter->GetMother(0) != negDaughter->GetMother(0)){  // Not Same Mother == Combinatorial Bck
       return;
    }
+   
+   else if (posDaughter->GetMother(0) == -1){
+      return;
+   }
+   
    if(TMath::Abs(posDaughter->GetPdgCode())!=11 || TMath::Abs(negDaughter->GetPdgCode())!=11) return; //One Particle is not electron
    if(posDaughter->GetPdgCode()==negDaughter->GetPdgCode()) return; // Same Charge
    if(posDaughter->GetUniqueID() != 5 || negDaughter->GetUniqueID() !=5) return;// check if the daughters come from a conversion
@@ -864,20 +1046,36 @@ void AliAnalysisTaskGammaConvDalitzV1::ProcessTruePhotonCandidates(AliAODConvers
    if(Photon->GetPdgCode() != 22) return; // Mother is no Photon
 
    // True Photon
-   hESDTrueConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
   
-   Int_t labelGamma = TruePhotonCandidate->GetMCParticleLabel(MCStack);
-
-    if( IsPi0DalitzDaughter(labelGamma) == kTRUE ) {
-        hESDTruePi0DalitzConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
-     }
+  Int_t labelGamma = TruePhotonCandidate->GetMCParticleLabel(MCStack);
+  
+  if( labelGamma < MCStack->GetNprimary() ){
+    if( fIsFromMBHeader ){
+      hESDTrueConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
+    }
+  }
+  else {
+    if( fIsFromMBHeader){
+      hESDTrueSecConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
+    }
+  }
+  if( IsPi0DalitzDaughter(labelGamma) == kTRUE ) {
+        if( labelGamma < MCStack->GetNprimary() ) {
+         if( fIsFromMBHeader ){
+           hESDTruePi0DalitzConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
+         }
+       }
+       else {
+         if( fIsFromMBHeader ) {
+           hESDTruePi0DalitzSecConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
+         }
+       }
+  }
    
  
-
-
 }
 
-
 //________________________________________________________________________
 void AliAnalysisTaskGammaConvDalitzV1::ProcessElectronCandidates(){
 
@@ -892,53 +1090,68 @@ void AliAnalysisTaskGammaConvDalitzV1::ProcessElectronCandidates(){
    }
 
 
-
-
    vector<Int_t> lGoodElectronIndex(0);
    vector<Int_t> lGoodPositronIndex(0);
 
 
-
    for(UInt_t i = 0; i < fSelectorElectronIndex.size(); i++){
-
-      AliESDtrack* electronCandidate = fESDEvent->GetTrack(fSelectorElectronIndex[i]);
-      if(! ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->ElectronIsSelected(electronCandidate) ) continue;
-         lGoodElectronIndex.push_back(   fSelectorElectronIndex[i] );
-         hESDDalitzElectronPt[fiCut]->Fill(electronCandidate->Pt());
-                                if( fMCEvent ) {
-                                        Int_t labelelectron = TMath::Abs( electronCandidate->GetLabel() );
-                                        if( labelelectron < fMCStack->GetNtrack() ){
-                                                TParticle* electron = fMCStack->Particle(labelelectron);
-                                                if( electron->GetPdgCode() ==  11 ){
-                                                        hESDTrueElectronPt[fiCut]->Fill(electron->Pt());
-                                                        if( IsPi0DalitzDaughter(labelelectron) == kTRUE ) {
-                                                                hESDTruePi0DalitzElectronPt[fiCut]->Fill(electron->Pt());
-                                                        }
-                                                }
-                                        }
-                                }
+    AliESDtrack* electronCandidate = fESDEvent->GetTrack(fSelectorElectronIndex[i]);
+    if(! ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->ElectronIsSelected(electronCandidate) ) continue;
+       lGoodElectronIndex.push_back(   fSelectorElectronIndex[i] );
+       hESDDalitzElectronPt[fiCut]->Fill(electronCandidate->Pt());
+         if( fMCEvent ) {
+         Int_t labelelectron = TMath::Abs( electronCandidate->GetLabel() );
+           if( labelelectron < fMCStack->GetNtrack() ){
+             TParticle* electron = fMCStack->Particle(labelelectron);
+               if( electron->GetPdgCode() ==  11 ){
+                   if( labelelectron < fMCStack->GetNprimary() ){
+                     hESDTrueElectronPt[fiCut]->Fill(electronCandidate->Pt());    //primary electron
+                   }
+                   else{
+                     hESDTrueSecElectronPt[fiCut]->Fill(electronCandidate->Pt()); //secondary electron
+                   }
+                   if( IsPi0DalitzDaughter(labelelectron) == kTRUE ) {
+                       if( labelelectron < fMCStack->GetNprimary() ) {
+                         hESDTruePi0DalitzElectronPt[fiCut]->Fill(electronCandidate->Pt());
+                       }
+                       else{
+                         hESDTruePi0DalitzSecElectronPt[fiCut]->Fill(electronCandidate->Pt());
+                       }
+                   }
+               }
+           }
+       }
    }
 
    for(UInt_t i = 0; i < fSelectorPositronIndex.size(); i++){
 
       AliESDtrack* positronCandidate = fESDEvent->GetTrack( fSelectorPositronIndex[i] );
       if(! ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->ElectronIsSelected(positronCandidate) ) continue;
-        lGoodPositronIndex.push_back(   fSelectorPositronIndex[i] );
-        hESDDalitzPositronPt[fiCut]->Fill(positronCandidate->Pt());
+       lGoodPositronIndex.push_back(   fSelectorPositronIndex[i]  );
+        hESDDalitzPositronPt[fiCut]->Fill( positronCandidate->Pt() );
         if( fMCEvent ) {
-                                       Int_t labelpositron = TMath::Abs( positronCandidate->GetLabel() );
-                                       if( labelpositron < fMCStack->GetNtrack() ) {
-                    TParticle* positron = fMCStack->Particle(labelpositron);
-                      if( positron->GetPdgCode() ==  -11 ){
-                            hESDTruePositronPt[fiCut]->Fill(positron->Pt());
-                        if( IsPi0DalitzDaughter(labelpositron) == kTRUE ) {
-                            hESDTruePi0DalitzPositronPt[fiCut]->Fill(positron->Pt());
-                       }
-                     }
-               }
+         Int_t labelpositron = TMath::Abs( positronCandidate->GetLabel() );
+         if( labelpositron < fMCStack->GetNtrack() ) {
+           TParticle* positron = fMCStack->Particle(labelpositron);
+            if( positron->GetPdgCode() ==  -11 ){
+             if( labelpositron < fMCStack->GetNprimary() ){
+               hESDTruePositronPt[fiCut]->Fill(positronCandidate->Pt());
+             }
+             else{
+               hESDTrueSecPositronPt[fiCut]->Fill(positronCandidate->Pt());
+             }
+             if( IsPi0DalitzDaughter(labelpositron) == kTRUE ) {
+               if( labelpositron < fMCStack->GetNprimary() ){
+                 hESDTruePi0DalitzPositronPt[fiCut]->Fill(positronCandidate->Pt());
+               }
+               else{
+                 hESDTruePi0DalitzSecPositronPt[fiCut]->Fill(positronCandidate->Pt());
+               }
+              }
+            }
+          }
         }
-
-   }
+    }
 
 
    vector<Bool_t> lElectronPsiIndex(lGoodElectronIndex.size(), kTRUE);
@@ -967,8 +1180,6 @@ void AliAnalysisTaskGammaConvDalitzV1::ProcessElectronCandidates(){
 
 
 
-
-
    for(UInt_t i = 0; i < lGoodElectronIndex.size(); i++){
 
       if( lElectronPsiIndex[i] == kFALSE ) continue;
@@ -1017,9 +1228,7 @@ void AliAnalysisTaskGammaConvDalitzV1::ProcessElectronCandidates(){
                                                }
             
             TParticle *mcVgamma=virtualPhoton->GetMCParticle(fMCStack);
-                                               Int_t labelgamma    = -1;
-                                               Int_t labelelectron = -1;
-                                               Int_t labelpositron = -1;
+                                               
                                                
                                                if(mcVgamma){
                                                        // Check if it is a true photon
@@ -1028,7 +1237,7 @@ void AliAnalysisTaskGammaConvDalitzV1::ProcessElectronCandidates(){
                                                        }else if(mcVgamma->GetPdgCode() == 443){
                                                                isJPsi = kTRUE;
                                                        }
-                                                       else if( IsDalitz( mcVgamma,labelgamma,labelelectron,labelpositron ) ){
+                                                       else if( IsDalitz( mcVgamma ) ){
                                                                if     ( mcVgamma->GetPdgCode() == 111 ) isPi0Dalitz = kTRUE;
                                                                else if( mcVgamma->GetPdgCode() == 221 ) isEtaDalitz = kTRUE;
                                                        }
@@ -1041,11 +1250,11 @@ void AliAnalysisTaskGammaConvDalitzV1::ProcessElectronCandidates(){
          hESDEposEnegPsiPairDPhi[fiCut]->Fill(deltaPhi,psiPair);   
          hESDEposEnegInvMassPt[fiCut]->Fill(vphoton->GetMass(),vphoton->Pt());
                                 
-                                if( fMCEvent ) {
-                                        if(isPhoton)   hESDEposEnegTruePhotonInvMassPt[fiCut]->Fill(vphoton->GetMass(),vphoton->Pt());
-                else if(isJPsi) hESDEposEnegTrueJPsiInvMassPt[fiCut]->Fill(vphoton->GetMass(),vphoton->Pt());
-                                else if(isPi0Dalitz)hESDEposEnegTruePi0DalitzInvMassPt[fiCut]->Fill(vphoton->GetMass(),vphoton->Pt());
-                                        else if(isEtaDalitz)hESDEposEnegTrueEtaDalitzInvMassPt[fiCut]->Fill(vphoton->GetMass(),vphoton->Pt());
+                               if( fMCEvent ) {
+                               if(isPhoton)    hESDEposEnegTruePhotonInvMassPt[fiCut]->Fill(vphoton->GetMass(),vphoton->Pt());
+                               else if(isJPsi) hESDEposEnegTrueJPsiInvMassPt[fiCut]->Fill(vphoton->GetMass(),vphoton->Pt());
+                               else if(isPi0Dalitz)hESDEposEnegTruePi0DalitzInvMassPt[fiCut]->Fill(vphoton->GetMass(),vphoton->Pt());
+                               else if(isEtaDalitz)hESDEposEnegTrueEtaDalitzInvMassPt[fiCut]->Fill(vphoton->GetMass(),vphoton->Pt());
                                         
                                 }
                                 
@@ -1156,27 +1365,45 @@ void AliAnalysisTaskGammaConvDalitzV1::CalculatePi0DalitzCandidates(){
             pi0cand->SetLabels(GammaIndex,virtualGammaIndex);
 
             if( ( ((AliConversionMesonCuts*)fCutMesonArray->At(fiCut))->MesonIsSelected(pi0cand,kTRUE)) ){
-               hESDMotherInvMassPt[fiCut]->Fill(pi0cand->M(),pi0cand->Pt());
-               hESDPi0MotherInvMassPt[fiCut]->Fill(pi0cand->M(),pi0cand->Pt());
-                
-               Double_t diffMass = pi0cand->M() - Vgamma->GetMass();
-    
-               hESDPi0MotherDiffInvMassPt[fiCut]->Fill( diffMass , pi0cand->Pt() );
-               // if(pi0cand->GetAlpha()<0.1){
-               //    hESDMotherInvMassEalpha[fiCut]->Fill(pi0cand->M(),pi0cand->E());
-               // }
-               Int_t zbin= fBGHandler[fiCut]->GetZBinIndex(fESDEvent->GetPrimaryVertex()->GetZ());
+             
+              Int_t zbin= fBGHandler[fiCut]->GetZBinIndex(fESDEvent->GetPrimaryVertex()->GetZ());
                Int_t mbin = 0;
                if( ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->UseTrackMultiplicity() ){
                   mbin = fBGHandler[fiCut]->GetMultiplicityBinIndex(fNumberOfESDTracks);
                } else {
                   mbin = fBGHandler[fiCut]->GetMultiplicityBinIndex(fGoodGammas->GetEntries());
                }
-               Double_t sparesFill[4] = {pi0cand->M(),pi0cand->Pt(),(Double_t)zbin,(Double_t)mbin};
-               sESDMotherInvMassPtZM[fiCut]->Fill(sparesFill,1);
-               if(fMCEvent){
+             
+             
+             
+              if(  ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->DoMassCut() == kTRUE ) {
+                if( Vgamma->GetMass()  <  ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->GetMassCut() ){
+                hESDMotherInvMassPt[fiCut]->Fill(pi0cand->M(),pi0cand->Pt());
+                Double_t sparesFill[4] = {pi0cand->M(),pi0cand->Pt(),(Double_t)zbin,(Double_t)mbin};
+                 sESDMotherInvMassPtZM[fiCut]->Fill(sparesFill,1);
+               }
+             }
+             else {
+                hESDMotherInvMassPt[fiCut]->Fill(pi0cand->M(),pi0cand->Pt());
+                Double_t sparesFill[4] = {pi0cand->M(),pi0cand->Pt(),(Double_t)zbin,(Double_t)mbin};
+                 sESDMotherInvMassPtZM[fiCut]->Fill(sparesFill,1);
+             }
+              
+              
+              
+               hESDPi0MotherInvMassPt[fiCut]->Fill(pi0cand->M(),pi0cand->Pt());
+                
+               Double_t diffMass = pi0cand->M() - Vgamma->GetMass();
+    
+               hESDPi0MotherDiffInvMassPt[fiCut]->Fill( diffMass , pi0cand->Pt() );
+       
+             if(Vgamma->GetMass() > 2.5 && Vgamma->GetMass()<3.4       ){
+               hESDPi0MotherDiffLimInvMassPt[fiCut]->Fill( diffMass , pi0cand->Pt() );
+             }
+               
+              if(fMCEvent){
                   ProcessTrueMesonCandidates(pi0cand,gamma,Vgamma);
-               }
+              }
             }
             delete pi0cand;
             pi0cand=0x0;
@@ -1228,9 +1455,19 @@ void AliAnalysisTaskGammaConvDalitzV1::CalculateBackground(){
 
                   AliAODConversionMother *backgroundCandidate = new AliAODConversionMother(&currentEventGoodV0,&previousGoodV0);
                   if( ( ((AliConversionMesonCuts*)fCutMesonArray->At(fiCut))->MesonIsSelected(backgroundCandidate,kFALSE) ) ){
-                     hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt());
-                     Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),(Double_t)zbin,(Double_t)mbin};
-                     sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);
+                     if(  ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->DoMassCut() == kTRUE ) {
+                       if( currentEventGoodV0.GetMass()  <  ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->GetMassCut() ){
+                         
+                         hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt());
+                         Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),(Double_t)zbin,(Double_t)mbin};
+                         sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);
+                        }
+                     }
+                     else {
+                       hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt());
+                       Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),(Double_t)zbin,(Double_t)mbin};
+                       sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);
+                     }       
                   }
                   delete backgroundCandidate;
                   backgroundCandidate = 0x0;
@@ -1259,9 +1496,20 @@ void AliAnalysisTaskGammaConvDalitzV1::CalculateBackground(){
 
                      AliAODConversionMother *backgroundCandidate = new AliAODConversionMother(&currentEventGoodV0,&previousGoodV0);
                      if((((AliConversionMesonCuts*)fCutMesonArray->At(fiCut))->MesonIsSelected(backgroundCandidate,kFALSE))){
-                        hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt());
-                        Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),(Double_t)zbin,(Double_t)mbin};
-                        sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);
+                      
+                      if(  ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->DoMassCut() == kTRUE ) {
+                       if( currentEventGoodV0.GetMass()  <  ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->GetMassCut() ){
+                      
+                         hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt());
+                         Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),(Double_t)zbin,(Double_t)mbin};
+                         sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);
+                       }
+                      }
+                      else {
+                         hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt());
+                         Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),(Double_t)zbin,(Double_t)mbin};
+                         sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);
+                      }
                      }
                      delete backgroundCandidate;
                      backgroundCandidate = 0x0;
@@ -1286,10 +1534,23 @@ void AliAnalysisTaskGammaConvDalitzV1::CalculateBackground(){
             AliAODConversionMother *backgroundCandidate = new AliAODConversionMother(&currentEventGoodV0,&previousGoodV0);
 
             if((((AliConversionMesonCuts*)fCutMesonArray->At(fiCut))->MesonIsSelected(backgroundCandidate,kFALSE))){
-
-               hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt());
-               Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),(Double_t)zbin,(Double_t)mbin};
-               sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);
+             
+              if(  ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->DoMassCut() == kTRUE ) {
+                 if( currentEventGoodV0.GetMass()  <  ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->GetMassCut() ){
+                     
+                 hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt());
+                 Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),(Double_t)zbin,(Double_t)mbin};
+                 sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);
+                 
+                 }
+              }
+              else{
+                
+                hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt());
+                Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),(Double_t)zbin,(Double_t)mbin};
+                sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1); 
+                
+              }
             }
             delete backgroundCandidate;
             backgroundCandidate = 0x0;
@@ -1354,17 +1615,29 @@ void AliAnalysisTaskGammaConvDalitzV1::ProcessTrueMesonCandidates(AliAODConversi
 
    AliStack *MCStack = fMCEvent->Stack();
 
-
-   if(TrueGammaCandidate->GetV0Index()<fESDEvent->GetNumberOfV0s()){
+   if( TrueGammaCandidate->GetV0Index()<fESDEvent->GetNumberOfV0s()    ){
 
 
       Bool_t isTruePi0 = kFALSE;
       Bool_t isTrueEta = kFALSE;
+      Bool_t massCutAccept = kFALSE;
       Bool_t isTrueChiC = kFALSE;
       Int_t gammaMCLabel = TrueGammaCandidate->GetMCParticleLabel(MCStack);
       Int_t gammaMotherLabel = -1;
 
 
+      if(  ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->DoMassCut() == kTRUE ) {
+          
+           if( TrueVirtualGammaCandidate->GetMass()  <  ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->GetMassCut() ){      
+              massCutAccept = kTRUE;
+           }
+      }
+      else {
+             massCutAccept  = kTRUE;
+      }
+      
+      
+      
 
 
       if(gammaMCLabel != -1){ // Gamma is Combinatorial; MC Particles don't belong to the same Mother
@@ -1391,6 +1664,8 @@ void AliAnalysisTaskGammaConvDalitzV1::ProcessTrueMesonCandidates(AliAODConversi
       Int_t virtualGammaMCLabel = TrueVirtualGammaCandidate->GetMCParticleLabel(MCStack);
       Int_t virtualGammaMotherLabel = -1;
       Int_t virtualGamma = 1;
+      Int_t virtualGammaGrandMotherLabel =-1;
+
 
       if(virtualGammaMCLabel != -1){ // Gamma is Combinatorial; MC Particles don't belong to the same Mother
          // Daughters Gamma 1
@@ -1402,19 +1677,20 @@ void AliAnalysisTaskGammaConvDalitzV1::ProcessTrueMesonCandidates(AliAODConversi
 
             if( virtualGammaMotherMC->GetPdgCode() != 22 ){
                virtualGammaMotherLabel=virtualGammaMCLabel;
-            }
+           if(virtualGammaMotherMC->GetPdgCode() == 443){
+              virtualGammaGrandMotherLabel=virtualGammaMotherMC->GetFirstMother();
+           }
+           }
 
             else if(negativeMC->GetUniqueID() == 5 && positiveMC->GetUniqueID() ==5){ // ... From Conversion ...
-
                virtualGammaMotherLabel=virtualGammaMotherMC->GetFirstMother();
                virtualGamma = 0; //no virtual gamma
-
             }
          }
       }
 
 
-      if(gammaMotherLabel>=0 && ( gammaMotherLabel == virtualGammaMotherLabel) ){
+      if(gammaMotherLabel >= 0 && ( gammaMotherLabel == virtualGammaMotherLabel) ){
 
          if(((TParticle*)MCStack->Particle(virtualGammaMotherLabel))->GetPdgCode() == 111){
             isTruePi0=kTRUE;
@@ -1423,26 +1699,38 @@ void AliAnalysisTaskGammaConvDalitzV1::ProcessTrueMesonCandidates(AliAODConversi
          if(((TParticle*)MCStack->Particle(virtualGammaMotherLabel))->GetPdgCode() == 221){
             isTrueEta=kTRUE;
          }
-                                
-                                if(((TParticle*)MCStack->Particle(virtualGammaMotherLabel))->GetPdgCode() == 445 ||
-                                               ((TParticle*)MCStack->Particle(virtualGammaMotherLabel))->GetPdgCode() == 10443 ||
-                                               ((TParticle*)MCStack->Particle(virtualGammaMotherLabel))->GetPdgCode() == 20443 ){
-            isTrueChiC=kTRUE;
-                                               hESDTrueMotherChiCInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
-         }
+         
+        
+       }
 
-      }
+                       if(gammaMotherLabel>=0 && ( gammaMotherLabel == virtualGammaGrandMotherLabel) ){
+                               if(((TParticle*)MCStack->Particle(virtualGammaGrandMotherLabel))->GetPdgCode() == 445 ||
+                                        ((TParticle*)MCStack->Particle(virtualGammaGrandMotherLabel))->GetPdgCode() == 10443 ||
+                                        ((TParticle*)MCStack->Particle(virtualGammaGrandMotherLabel))->GetPdgCode() == 20443 ){
+                                       isTrueChiC=kTRUE;
+                                       hESDTrueMotherChiCInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
+                                       hESDTrueMotherChiCDiffInvMassPt[fiCut]->Fill(Pi0Candidate->M()-TrueVirtualGammaCandidate->GetMass(),Pi0Candidate->Pt());
+                               }
+                       }
 
-      if(isTruePi0 || isTrueEta ){ // True Pion or Eta
+      if( ( isTruePi0 || isTrueEta) && massCutAccept ){ // True Pion or Eta
+       
          if ( virtualGamma == 1 ) { //True Dalitz
             hESDTrueMotherInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
-            if(gammaMotherLabel <= MCStack->GetNprimary()){ // Only primary pi0 for efficiency calculation
-               hESDTruePrimaryMotherInvMassMCPt[fiCut]->Fill(Pi0Candidate->M(),((TParticle*)MCStack->Particle(virtualGammaMotherLabel))->Pt());
+            if(gammaMotherLabel < MCStack->GetNprimary()){ // Only primary pi0 for efficiency calculation
+             
+              Float_t weighted= 1;
+               if(((AliConversionCuts*)fCutGammaArray->At(fiCut))->IsParticleFromBGEvent(gammaMotherLabel, fMCStack,fInputEvent)){
+                  if (((TParticle*)MCStack->Particle(gammaMotherLabel))->Pt()>0.005){
+                     weighted= ((AliConversionCuts*)fCutGammaArray->At(fiCut))->GetWeightForMeson(fV0Reader->GetPeriodName(),gammaMotherLabel,fMCStack,fInputEvent);
+                  }
+               }
+               hESDTruePrimaryMotherInvMassMCPt[fiCut]->Fill(Pi0Candidate->M(),((TParticle*)MCStack->Particle(virtualGammaMotherLabel))->Pt(),weighted);
                if(isTruePi0){ // Only primaries for unfolding
-                  hESDTruePrimaryPi0DalitzESDPtMCPt[fiCut]->Fill(Pi0Candidate->Pt(),((TParticle*)MCStack->Particle(virtualGammaMotherLabel))->Pt());
+                  hESDTruePrimaryPi0DalitzESDPtMCPt[fiCut]->Fill(Pi0Candidate->Pt(),((TParticle*)MCStack->Particle(virtualGammaMotherLabel))->Pt(),weighted);
                }
             }
-            if(gammaMotherLabel > MCStack->GetNprimary()){ // Secondary Meson
+            else { // Secondary Meson
                hESDTrueSecondaryMotherInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
                //if (((TParticle*)MCStack->Particle(virtualGammaMotherLabel))->GetMother(0) >-1){
                //   if(MCStack->Particle(((TParticle*)MCStack->Particle(virtualGammaMotherLabel))->GetMother(0))->GetPdgCode()==kK0Short){
@@ -1455,7 +1743,7 @@ void AliAnalysisTaskGammaConvDalitzV1::ProcessTrueMesonCandidates(AliAODConversi
          }
       }
 
-      if(!isTruePi0 && !isTrueEta){ // Background
+      if(!isTruePi0 && !isTrueEta && massCutAccept ){ // Background
          if(gammaMotherLabel>-1 && virtualGammaMotherLabel>-1 && virtualGamma == 0){ // Both Tracks are Photons and have a mother but not Pi0 or Eta
             hESDTrueBckGGInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
          } else { // No photon or without mother
@@ -1507,37 +1795,76 @@ void AliAnalysisTaskGammaConvDalitzV1::ProcessMCParticles()
 
    // Loop over all primary MC particle
 
-       for(Int_t i = 0; i < fMCStack->GetNprimary(); i++) {
-               TParticle* particle = (TParticle *)fMCStack->Particle(i);
-               if (!particle) continue;
-               
-               
-    if(((AliConversionCuts*)fCutGammaArray->At(fiCut))->PhotonIsSelectedMC(particle,fMCStack,kFALSE)){
-                       hMCAllGammaPt[fiCut]->Fill(particle->Pt()); // All MC Gamma
-    }
-               
-    if(((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->ElectronIsSelectedMC(i,fMCStack)){
+   for(Int_t i = 0; i < fMCStack->GetNprimary(); i++) {
+     
+     
+      TParticle* particle = (TParticle *)fMCStack->Particle(i);
+      if (!particle) continue;
+      
+      
+      Bool_t mcIsFromMB = kTRUE;
+      Int_t isMCFromMBHeader = -1;
+           
+      if(((AliConversionCuts*)fCutGammaArray->At(fiCut))->GetSignalRejection() != 0) {
+         isMCFromMBHeader
+            = ((AliConversionCuts*)fCutGammaArray->At(fiCut))->IsParticleFromBGEvent(i,fMCStack,fInputEvent);
+         if(isMCFromMBHeader == 0 && ((AliConversionCuts*)fCutGammaArray->At(fiCut))->GetSignalRejection() != 3) continue;
+         if(isMCFromMBHeader != 2) mcIsFromMB = kFALSE;
+      }    
+    
+      if(((AliConversionCuts*)fCutGammaArray->At(fiCut))->PhotonIsSelectedMC(particle,fMCStack,kFALSE)){
+         hMCAllGammaPt[fiCut]->Fill(particle->Pt()); // All MC Gamma
+      }
+      
+      if(((AliConversionCuts*)fCutGammaArray->At(fiCut))->PhotonIsSelectedMC(particle,fMCStack,kTRUE)){
+         hMCConvGammaPt[fiCut]->Fill(particle->Pt());
+         if(mcIsFromMB){
+            hMCConvGammaRSPt[fiCut]->Fill(particle->Pt());
+         }
+      } // Converted MC Gamma
+       
+      if(((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->ElectronIsSelectedMC(i,fMCStack)){
                        if( particle->GetPdgCode() == -11)hMCAllPositronsPt[fiCut]->Fill(particle->Pt()); // All positrons
                        if( particle->GetPdgCode() ==  11)hMCAllElectronsPt[fiCut]->Fill(particle->Pt()); // All electrons
-    }
-               
-    if(((AliConversionMesonCuts*)fCutMesonArray->At(fiCut))->MesonIsSelectedMC(particle,fMCStack)){
-                       if(particle->GetPdgCode() == 111)hMCPi0GGPt[fiCut]->Fill( particle->Pt() ); // All MC Pi0 GG decay
-                       if(particle->GetPdgCode() == 221)hMCEtaGGPt[fiCut]->Fill( particle->Pt() ); // All MC Eta GG decay
-    }
+      }
+       
+      if(((AliConversionMesonCuts*)fCutMesonArray->At(fiCut))->MesonIsSelectedMC(particle,fMCStack,((AliConversionCuts*)fCutGammaArray->At(fiCut))->GetEtaShift()) ){
+       
+                       Float_t weighted= 1;
+       
+                       if(((AliConversionCuts*)fCutGammaArray->At(fiCut))->IsParticleFromBGEvent(i, fMCStack, fInputEvent)){
+                         if (particle->Pt()>0.005){
+                           weighted= ((AliConversionCuts*)fCutGammaArray->At(fiCut))->GetWeightForMeson(fV0Reader->GetPeriodName(),i, fMCStack,fInputEvent);
+                         }
+                       }
+       
+                       if(particle->GetPdgCode() == 111)hMCPi0GGPt[fiCut]->Fill( particle->Pt() , weighted); // All MC Pi0 GG decay
+                       if(particle->GetPdgCode() == 221)hMCEtaGGPt[fiCut]->Fill( particle->Pt() , weighted); // All MC Eta GG decay
+      }
+      
+      
+      Int_t labelgamma           = -1;
+      Int_t labelelectron = -1;
+      Int_t labelpositron = -1;
+
 
-    if(((AliConversionMesonCuts*)fCutMesonArray->At(fiCut))->MesonIsSelectedMCDalitz(particle,fMCStack)){
-                       if(particle->GetPdgCode() == 111)hMCPi0Pt[fiCut]->Fill(particle->Pt()); // All MC Pi0
-                       if(particle->GetPdgCode() == 221)hMCEtaPt[fiCut]->Fill(particle->Pt()); // All MC Eta
+      if( ((AliConversionMesonCuts*)fCutMesonArray->At(fiCut))->MesonIsSelectedMCDalitz(particle,fMCStack,labelelectron,labelpositron,labelgamma,((AliConversionCuts*)fCutGammaArray->At(fiCut))->GetEtaShift())  )
+      {
+       
+       
+                       Float_t weighted= 1;
+       
+                       if(((AliConversionCuts*)fCutGammaArray->At(fiCut))->IsParticleFromBGEvent(i, fMCStack,fInputEvent)){
+                         if (particle->Pt()>0.005){
+                           weighted= ((AliConversionCuts*)fCutGammaArray->At(fiCut))->GetWeightForMeson(fV0Reader->GetPeriodName(),i, fMCStack,fInputEvent);
+                         }
+                       }
+       
+                       if(particle->GetPdgCode() == 111)hMCPi0Pt[fiCut]->Fill(particle->Pt(), weighted); // All MC Pi0
+                       if(particle->GetPdgCode() == 221)hMCEtaPt[fiCut]->Fill(particle->Pt(), weighted); // All MC Eta
                        
                        // Check the acceptance for gamma and electrons
                        
-                       Int_t labelgamma =    -1;
-                       Int_t labelelectron = -1;
-                       Int_t labelpositron = -1;
-                       
-                       if( IsDalitz( particle,labelgamma,labelelectron,labelpositron) == kTRUE ) {
-                                        
                                         
                                TParticle *gamma    = fMCStack->Particle(labelgamma);
                                TParticle *electron = fMCStack->Particle(labelelectron);
@@ -1545,46 +1872,50 @@ void AliAnalysisTaskGammaConvDalitzV1::ProcessMCParticles()
                                
            
                                if(((AliConversionCuts*)fCutGammaArray->At(fiCut))->PhotonIsSelectedMC(gamma,fMCStack,kFALSE) &&
-                                        TMath::Abs( electron->Eta() ) < ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->GetEtaCut()  &&
-                                        TMath::Abs( positron->Eta() ) < ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->GetEtaCut() ){
+                                  ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->ElectronIsSelectedMC(labelelectron,fMCStack) &&
+                                  ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->ElectronIsSelectedMC(labelpositron,fMCStack) ) {
+                                  
                                        if(particle->GetPdgCode() == 111){ 
-                                               hMCPi0InAccPt[fiCut]->Fill(particle->Pt()); // MC Pi0Dalitz with gamma and e+e- in acc
-                                               hMCPi0DalitzGammaPt[fiCut]->Fill( gamma->Pt());
-                                               hMCPi0DalitzPositronPt[fiCut]->Fill( positron->Pt());
-                                               hMCPi0DalitzElectronPt[fiCut]->Fill( electron->Pt());
+                                         
+                                               hMCPi0InAccPt[fiCut]->Fill(particle->Pt() , weighted); // MC Pi0Dalitz with gamma and e+e- in acc
+                                               hMCPi0DalitzGammaPt[fiCut]->Fill( gamma->Pt() ,weighted );
+                                               hMCPi0DalitzPositronPt[fiCut]->Fill( positron->Pt(),weighted );
+                                               hMCPi0DalitzElectronPt[fiCut]->Fill( electron->Pt(),weighted );
+                                               
                                        }
-                                       if(particle->GetPdgCode() == 221)hMCEtaInAccPt[fiCut]->Fill(particle->Pt()); // MC EtaDalitz with gamma and e+e- in acc
+                                       if(particle->GetPdgCode() == 221)hMCEtaInAccPt[fiCut]->Fill(particle->Pt(), weighted ); // MC EtaDalitz with gamma and e+e- in acc
                                }
-                       }
-               }
+               
+                       
+       }
                Int_t labelgammaChiC=-1;
                Int_t labelpositronChiC=-1;
                Int_t labelelectronChiC=-1;
 
-
-
-               if(((AliConversionMesonCuts*)fCutMesonArray->At(fiCut))->MesonIsSelectedMCChiC(particle,fMCStack,labelelectronChiC,labelpositronChiC,labelgammaChiC)){
+               if(((AliConversionMesonCuts*)fCutMesonArray->At(fiCut))->MesonIsSelectedMCChiC(particle,fMCStack,labelelectronChiC,labelpositronChiC,labelgammaChiC,((AliConversionCuts*)fCutGammaArray->At(fiCut))->GetEtaShift())){
+                 
                        hMCChiCPt[fiCut]->Fill(particle->Pt()); // All MC ChiC
                        TParticle * gammaChiC  =fMCStack->Particle(labelgammaChiC);
 
                        if( ((AliConversionCuts*)fCutGammaArray->At(fiCut))->PhotonIsSelectedMC( gammaChiC,fMCStack,kFALSE) &&
-                                       ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->ElectronIsSelectedMC(labelelectronChiC,fMCStack) && 
-                                       ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->ElectronIsSelectedMC(labelpositronChiC,fMCStack) ){
+                           ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->ElectronIsSelectedMC(labelelectronChiC,fMCStack) && 
+                           ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->ElectronIsSelectedMC(labelpositronChiC,fMCStack) ){
                                hMCChiCInAccPt[fiCut]->Fill(particle->Pt()); // All MC ChiC
                        } 
                }
        }
 }
 //_____________________________________________________________________________
-Bool_t AliAnalysisTaskGammaConvDalitzV1::IsDalitz(TParticle *fMCMother,Int_t &labelgamma, Int_t &labelelectron,Int_t &labelpositron)
+Bool_t AliAnalysisTaskGammaConvDalitzV1::IsDalitz(TParticle *fMCMother) const
 {
 
        if( fMCMother->GetNDaughters() != 3 ) return kFALSE;
        if( fMCMother->GetPdgCode() != 111 && fMCMother->GetPdgCode() != 221 ) return kFALSE;
        
+       
        TParticle *positron = 0x0;
        TParticle *electron = 0x0;
-       TParticle *gamma        = 0x0;
+       TParticle *gamma    = 0x0;
        
        for(Int_t index= fMCMother->GetFirstDaughter();index<= fMCMother->GetLastDaughter();index++){                           
 
@@ -1593,15 +1924,12 @@ Bool_t AliAnalysisTaskGammaConvDalitzV1::IsDalitz(TParticle *fMCMother,Int_t &la
                switch( temp->GetPdgCode() ) {
                case ::kPositron:
                        positron =  temp;
-                       labelpositron = index;
                        break;
                case ::kElectron:
                        electron =  temp;
-                       labelelectron = index;
                        break;
                case ::kGamma:
                        gamma    =  temp;
-                       labelgamma = index;
                        break;
                }
        }
@@ -1616,34 +1944,21 @@ Bool_t AliAnalysisTaskGammaConvDalitzV1::IsPi0DalitzDaughter( Int_t label ) cons
 //
 // Returns true if the particle comes from Pi0 -> e+ e- gamma
 //
-        Bool_t ePlusFlag  = kFALSE;
-        Bool_t eMinusFlag = kFALSE;
-        Bool_t gammaFlag  = kFALSE;
         
         Int_t motherLabel = fMCStack->Particle( label )->GetMother(0);
         
-        if( motherLabel < 0 ) return kFALSE;
+        if( motherLabel < 0 || motherLabel >= fMCStack->GetNtrack() ) return kFALSE;
         
         TParticle* mother = fMCStack->Particle( motherLabel );
+       
+       if( mother->GetPdgCode() != 111 ) return kFALSE;
+       
+       if( IsDalitz( mother ) ) return kTRUE;
+       
+       
+       return kFALSE;
         
-        if ( mother->GetPdgCode() != ::kPi0 ) return kFALSE;
-        
-        if ( mother->GetNDaughters() != 3 ) return kFALSE;
-        
-        for( Int_t idx = mother->GetFirstDaughter(); idx <= mother->GetLastDaughter(); ++idx ) {
-                switch( fMCStack->Particle(idx)->GetPdgCode()) {
-                        case ::kPositron:
-                                ePlusFlag  = kTRUE;
-                                break;
-                        case ::kElectron:
-                                eMinusFlag = kTRUE;
-                                break;
-                        case ::kGamma:
-                                gammaFlag  = kTRUE;
-                                break;
-                }
-        }
-        return ( ePlusFlag && eMinusFlag && gammaFlag );
+       
 }
 
 
@@ -1652,7 +1967,7 @@ Double_t AliAnalysisTaskGammaConvDalitzV1::GetPsiPair( const AliESDtrack *trackP
 {
    //
    // This angle is a measure for the contribution of the opening in polar
-   // direction Δ0 to the opening angle ξ Pair
+   // direction ?0 to the opening angle ? Pair
    //
    // Ref. Measurement of photons via conversion pairs with the PHENIX experiment at RHIC
    //      Master Thesis. Thorsten Dahms. 2005
@@ -1677,4 +1992,4 @@ Double_t AliAnalysisTaskGammaConvDalitzV1::GetPsiPair( const AliESDtrack *trackP
    Double_t psiAngle = TMath::ASin( deltaTheta/openingAngle );
 
    return psiAngle;
-}
+}
\ No newline at end of file
index 9c5c885..1bd65ea 100644 (file)
@@ -33,24 +33,34 @@ class AliAnalysisTaskGammaConvDalitzV1: public AliAnalysisTaskSE
 
        virtual void UserExec(Option_t *);
        virtual void UserCreateOutputObjects();
+       virtual Bool_t Notify();
        virtual void Terminate(const Option_t *);
 
 
 
          
-         void SetMoveParticleAccordingToVertex(Bool_t flag){fMoveParticleAccordingToVertex = flag;}
-         void SetIsHeavyIon(Bool_t flag){fIsHeavyIon = flag;}
-         void SetConversionCutList(Int_t nCuts, TList *CutArray){
-                        fnCuts= nCuts;
-                        fCutGammaArray = CutArray;
-                }
-         void SetElectronCutList(TList *CutArray){
-                        fCutElectronArray = CutArray;
-                }
-         void SetMesonCutList(TList *CutArray){
-                        fCutMesonArray = CutArray;
-                }
-               
+       void SetMoveParticleAccordingToVertex(Bool_t flag){fMoveParticleAccordingToVertex = flag;}
+         
+       void SetIsHeavyIon(Int_t flag){
+               if (flag == 1 || flag ==2 ){
+                       fIsHeavyIon = 1;    
+               } else {
+                       fIsHeavyIon = 0;    
+               }
+       }
+       
+       void SetIsMC(Bool_t isMC){fIsMC=isMC;}
+       void SetConversionCutList(Int_t nCuts, TList *CutArray){
+               fnCuts= nCuts;
+               fCutGammaArray = CutArray;
+       }
+       void SetElectronCutList(TList *CutArray){
+               fCutElectronArray = CutArray;
+       }
+       void SetMesonCutList(TList *CutArray){
+               fCutMesonArray = CutArray;
+       }
+  
 
        private:
 
@@ -66,7 +76,7 @@ class AliAnalysisTaskGammaConvDalitzV1: public AliAnalysisTaskSE
                 void CalculateBackground();
                 void UpdateEventByEventData();
                 Double_t GetPsiPair( const AliESDtrack *trackPos, const AliESDtrack *trackNeg ) const;
-               Bool_t IsDalitz(TParticle *fMCMother,Int_t &labelgamma, Int_t &labelelectron,Int_t &labelpositron);
+               Bool_t IsDalitz(TParticle *fMCMother) const;
                 Bool_t IsPi0DalitzDaughter( Int_t label ) const;
                
                
@@ -104,10 +114,13 @@ class AliAnalysisTaskGammaConvDalitzV1: public AliAnalysisTaskSE
     TH2F **hESDMotherInvMassPt;
     TH2F **hESDPi0MotherInvMassPt;
     TH2F **hESDPi0MotherDiffInvMassPt;
+    TH2F **hESDPi0MotherDiffLimInvMassPt;
     THnSparseF **sESDMotherInvMassPtZM;
     TH2F **hESDMotherBackInvMassPt;
     THnSparseF **sESDMotherBackInvMassPtZM;
     TH1F **hMCAllGammaPt;
+    TH1F **hMCConvGammaPt;
+    TH1F **hMCConvGammaRSPt;
     TH1F **hMCAllPositronsPt;
     TH1F **hMCAllElectronsPt;
     TH1F **hMCPi0DalitzGammaPt;
@@ -126,6 +139,7 @@ class AliAnalysisTaskGammaConvDalitzV1: public AliAnalysisTaskSE
     TH2F **hESDEposEnegTruePhotonInvMassPt;
     TH2F **hESDEposEnegTrueJPsiInvMassPt;
     TH2F **hESDTrueMotherChiCInvMassPt;
+    TH2F **hESDTrueMotherChiCDiffInvMassPt;
     TH2F **hESDTrueMotherInvMassPt;
     TH2F **hESDTrueMotherPi0GGInvMassPt;
     TH2F **hESDTruePrimaryMotherInvMassMCPt;
@@ -138,9 +152,15 @@ class AliAnalysisTaskGammaConvDalitzV1: public AliAnalysisTaskSE
     TH1F **hESDTrueConvGammaPt;
     TH1F **hESDTruePositronPt;
     TH1F **hESDTrueElectronPt;
+    TH1F **hESDTrueSecConvGammaPt;
+    TH1F **hESDTrueSecPositronPt;
+    TH1F **hESDTrueSecElectronPt;
     TH1F **hESDTruePi0DalitzConvGammaPt;
     TH1F **hESDTruePi0DalitzPositronPt;
     TH1F **hESDTruePi0DalitzElectronPt;
+    TH1F **hESDTruePi0DalitzSecConvGammaPt;
+    TH1F **hESDTruePi0DalitzSecPositronPt;
+    TH1F **hESDTruePi0DalitzSecElectronPt;
       //if(fDoMesonAnalysis){
 
 
@@ -158,12 +178,14 @@ class AliAnalysisTaskGammaConvDalitzV1: public AliAnalysisTaskSE
     Bool_t fMoveParticleAccordingToVertex;
     Bool_t fIsHeavyIon;
     Bool_t fDoMesonAnalysis;
-   
+    Bool_t fIsFromMBHeader;
+               Bool_t fIsMC;
+
        private:
                AliAnalysisTaskGammaConvDalitzV1( const AliAnalysisTaskGammaConvDalitzV1& ); // Not implemented
                AliAnalysisTaskGammaConvDalitzV1& operator=( const AliAnalysisTaskGammaConvDalitzV1& ); // Not implemented
 
-               ClassDef( AliAnalysisTaskGammaConvDalitzV1, 2 );
+               ClassDef( AliAnalysisTaskGammaConvDalitzV1, 3 );
 };
 
 #endif // ALIANALYSISTASKGAMMACONVDALITZV1_H
index aa94ae9..5e7c8ee 100644 (file)
@@ -19,6 +19,7 @@
 
 ////////////////////////////////////////////////
 //---------------------------------------------
+
 // Class used to do analysis on conversion pairs
 //---------------------------------------------
 ///////////////////////////////////////////////
@@ -47,6 +48,8 @@
 #include "AliV0ReaderV1.h"
 #include "AliGenCocktailEventHeader.h"
 #include "AliConversionAODBGHandlerRP.h"
+#include "AliAODMCParticle.h"
+#include "AliAODMCHeader.h"
 
 ClassImp(AliAnalysisTaskGammaConvV1)
 
@@ -67,6 +70,7 @@ AliAnalysisTaskGammaConvV1::AliAnalysisTaskGammaConvV1(): AliAnalysisTaskSE(),
    fTrueMotherRapList(NULL),
    fMCList(NULL),
    fHeaderNameList(NULL),
+   fTriggerNameList(NULL),
    fOutputContainer(0),
    fReaderGammas(NULL),
    fGammaCandidates(NULL),
@@ -97,11 +101,15 @@ AliAnalysisTaskGammaConvV1::AliAnalysisTaskGammaConvV1(): AliAnalysisTaskSE(),
    hMCConvGammaRSR(NULL),
    hMCConvGammaRSEta(NULL),
    hMCPi0Pt(NULL),
+   hMCPi0WOWeightPt(NULL),
    hMCEtaPt(NULL),
    hMCPi0InAccPt(NULL),
    hMCEtaInAccPt(NULL),
    hMCPi0PtY(NULL),
    hMCEtaPtY(NULL),
+   hMCK0sPt(NULL),
+   hMCK0sWOWeightPt(NULL),
+   hMCK0sPtY(NULL),
    hESDTrueMotherInvMassPt(NULL),
    hESDTruePrimaryMotherInvMassPt(NULL),
    hESDTruePrimaryPi0MCPtResolPt(NULL),
@@ -129,12 +137,15 @@ AliAnalysisTaskGammaConvV1::AliAnalysisTaskGammaConvV1(): AliAnalysisTaskSE(),
    hNGoodESDTracks(NULL),
    hNGammaCandidates(NULL),
    hNV0Tracks(NULL),
+   hEtaShift(NULL),
    fRandom(0),
    fnGammaCandidates(0),
    fUnsmearedPx(NULL),
    fUnsmearedPy(NULL),
    fUnsmearedPz(NULL),
    fUnsmearedE(NULL),
+   fMCStackPos(NULL),
+   fMCStackNeg(NULL),
    fnCuts(0),
    fiCut(0),
    fNumberOfESDTracks(0),
@@ -143,7 +154,8 @@ AliAnalysisTaskGammaConvV1::AliAnalysisTaskGammaConvV1(): AliAnalysisTaskSE(),
    fDoMesonAnalysis(kTRUE),
    fDoMesonQA(kFALSE),
    fDoPhotonQA(kFALSE),
-   fIsFromMBHeader(kTRUE)
+   fIsFromMBHeader(kTRUE),
+   fIsMC(kFALSE)
 {
 
 }
@@ -166,6 +178,7 @@ AliAnalysisTaskGammaConvV1::AliAnalysisTaskGammaConvV1(const char *name):
    fTrueMotherRapList(NULL),
    fMCList(NULL),
    fHeaderNameList(NULL),
+   fTriggerNameList(NULL),
    fOutputContainer(0),
    fReaderGammas(NULL),
    fGammaCandidates(NULL),
@@ -196,11 +209,15 @@ AliAnalysisTaskGammaConvV1::AliAnalysisTaskGammaConvV1(const char *name):
    hMCConvGammaRSR(NULL),
    hMCConvGammaRSEta(NULL),
    hMCPi0Pt(NULL),
+   hMCPi0WOWeightPt(NULL),
    hMCEtaPt(NULL),
    hMCPi0InAccPt(NULL),
    hMCEtaInAccPt(NULL),
    hMCPi0PtY(NULL),
    hMCEtaPtY(NULL),
+   hMCK0sPt(NULL),
+   hMCK0sWOWeightPt(NULL),
+   hMCK0sPtY(NULL),
    hESDTrueMotherInvMassPt(NULL),
    hESDTruePrimaryMotherInvMassPt(NULL),
    hESDTruePrimaryPi0MCPtResolPt(NULL),
@@ -228,12 +245,15 @@ AliAnalysisTaskGammaConvV1::AliAnalysisTaskGammaConvV1(const char *name):
    hNGoodESDTracks(NULL),
    hNGammaCandidates(NULL),
    hNV0Tracks(NULL),
+   hEtaShift(NULL),
    fRandom(0),
    fnGammaCandidates(0),
    fUnsmearedPx(NULL),
    fUnsmearedPy(NULL),
    fUnsmearedPz(NULL),
    fUnsmearedE(NULL),
+   fMCStackPos(NULL),
+   fMCStackNeg(NULL),
    fnCuts(0),
    fiCut(0),
    fNumberOfESDTracks(0),
@@ -242,7 +262,8 @@ AliAnalysisTaskGammaConvV1::AliAnalysisTaskGammaConvV1(const char *name):
    fDoMesonAnalysis(kTRUE),
    fDoMesonQA(kFALSE),
    fDoPhotonQA(kFALSE),
-   fIsFromMBHeader(kTRUE)
+   fIsFromMBHeader(kTRUE),
+   fIsMC(kFALSE)
 {
    // Define output slots here
    DefineOutput(1, TList::Class());
@@ -354,11 +375,14 @@ void AliAnalysisTaskGammaConvV1::UserCreateOutputObjects()
    fESDList = new TList*[fnCuts];
    fBackList = new TList*[fnCuts];
    fMotherList = new TList*[fnCuts];
+   fTriggerNameList = new TList*[fnCuts];
    hNEvents = new TH1I*[fnCuts];
    hNGoodESDTracks = new TH1I*[fnCuts];
    hNGammaCandidates = new TH1I*[fnCuts];
    hNV0Tracks = new TH1I*[fnCuts];
+   hEtaShift = new TH1F*[fnCuts];
    hESDConvGammaPt = new TH1F*[fnCuts];
+
    if (fDoPhotonQA){
       hESDConvGammaR = new TH1F*[fnCuts];
    }
@@ -411,6 +435,8 @@ void AliAnalysisTaskGammaConvV1::UserCreateOutputObjects()
       if(fIsHeavyIon) hNV0Tracks[iCut] = new TH1I("V0 Multiplicity","V0 Multiplicity",30000,0,30000);
       else hNV0Tracks[iCut] = new TH1I("V0 Multiplicity","V0 Multiplicity",2000,0,2000);
       fESDList[iCut]->Add(hNV0Tracks[iCut]);
+      hEtaShift[iCut] = new TH1F("Eta Shift","Eta Shift",1, -0.5,0.5);
+      fESDList[iCut]->Add(hEtaShift[iCut]);
       hESDConvGammaPt[iCut] = new TH1F("ESD_ConvGamma_Pt","ESD_ConvGamma_Pt",250,0,25);
       fESDList[iCut]->Add(hESDConvGammaPt[iCut]);
 
@@ -442,14 +468,14 @@ void AliAnalysisTaskGammaConvV1::UserCreateOutputObjects()
       InitBack(); // Init Background Handler
    }
 
-   if(MCEvent()){
+   if(fIsMC){
       // MC Histogramms
       fMCList = new TList*[fnCuts];
       // True Histogramms
       fTrueList = new TList*[fnCuts];
       // Selected Header List
       fHeaderNameList = new TList*[fnCuts];
-
+      
       hMCAllGammaPt = new TH1F*[fnCuts];
       hMCDecayGammaPi0Pt = new TH1F*[fnCuts];
       hMCDecayGammaRhoPt = new TH1F*[fnCuts];
@@ -482,6 +508,7 @@ void AliAnalysisTaskGammaConvV1::UserCreateOutputObjects()
 
       if(fDoMesonAnalysis){
          hMCPi0Pt = new TH1F*[fnCuts];
+         hMCPi0WOWeightPt = new TH1F*[fnCuts];
          hMCEtaPt = new TH1F*[fnCuts];
          hMCPi0InAccPt = new TH1F*[fnCuts];
          hMCEtaInAccPt = new TH1F*[fnCuts];
@@ -494,6 +521,9 @@ void AliAnalysisTaskGammaConvV1::UserCreateOutputObjects()
          if (fDoMesonQA){
             hMCPi0PtY = new TH2F*[fnCuts];
             hMCEtaPtY = new TH2F*[fnCuts];
+            hMCK0sPt = new TH1F*[fnCuts];
+            hMCK0sWOWeightPt = new TH1F*[fnCuts];
+            hMCK0sPtY = new TH2F*[fnCuts];
             hESDTruePrimaryPi0MCPtResolPt = new TH2F*[fnCuts];
             hESDTruePrimaryEtaMCPtResolPt = new TH2F*[fnCuts];
             hESDTrueK0sWithPi0DaughterMCPt = new TH1F*[fnCuts];
@@ -551,6 +581,10 @@ void AliAnalysisTaskGammaConvV1::UserCreateOutputObjects()
             hMCPi0Pt[iCut] = new TH1F("MC_Pi0_Pt","MC_Pi0_Pt",250,0,25);
             hMCPi0Pt[iCut]->Sumw2();
             fMCList[iCut]->Add(hMCPi0Pt[iCut]);
+            hMCPi0WOWeightPt[iCut] = new TH1F("MC_Pi0_WOWeights_Pt","MC_Pi0_WOWeights_Pt",250,0,25);
+            hMCPi0WOWeightPt[iCut]->Sumw2();
+            fMCList[iCut]->Add(hMCPi0WOWeightPt[iCut]);
+            
             hMCEtaPt[iCut] = new TH1F("MC_Eta_Pt","MC_Eta_Pt",250,0,25);
             hMCEtaPt[iCut]->Sumw2();
             fMCList[iCut]->Add(hMCEtaPt[iCut]);
@@ -567,6 +601,16 @@ void AliAnalysisTaskGammaConvV1::UserCreateOutputObjects()
                hMCEtaPtY[iCut] = new TH2F("MC_Eta_Pt_Y","MC_Eta_Pt_Y",250,0,25,20,-1,1);
                hMCEtaPtY[iCut]->Sumw2();
                fMCList[iCut]->Add(hMCEtaPtY[iCut]);
+               hMCK0sPt[iCut] = new TH1F("MC_K0s_Pt","MC_K0s_Pt",250,0,25);
+               hMCK0sPt[iCut]->Sumw2();
+               fMCList[iCut]->Add(hMCK0sPt[iCut]);
+               hMCK0sWOWeightPt[iCut] = new TH1F("MC_K0s_WOWeights_Pt","MC_K0s_WOWeights_Pt",250,0,25);
+               hMCK0sWOWeightPt[iCut]->Sumw2();
+               fMCList[iCut]->Add(hMCK0sWOWeightPt[iCut]);
+               hMCK0sPtY[iCut] = new TH2F("MC_K0s_Pt_Y","MC_K0s_Pt_Y",250,0,25,20,-1,1);
+               hMCK0sPtY[iCut]->Sumw2();
+               fMCList[iCut]->Add(hMCK0sPtY[iCut]);
+               
             }
 
          }
@@ -628,9 +672,11 @@ void AliAnalysisTaskGammaConvV1::UserCreateOutputObjects()
             fTrueList[iCut]->Add(hESDTruePrimaryMotherInvMassPt[iCut]);
             hESDTrueSecondaryMotherInvMassPt[iCut]
                = new TH2F("ESD_TrueSecondaryMother_InvMass_Pt", "ESD_TrueSecondaryMother_InvMass_Pt", 800,0,0.8,250,0,25);
+            hESDTrueSecondaryMotherInvMassPt[iCut]->Sumw2();
             fTrueList[iCut]->Add(hESDTrueSecondaryMotherInvMassPt[iCut]);
             hESDTrueSecondaryMotherFromK0sInvMassPt[iCut]
                = new TH2F("ESD_TrueSecondaryMotherFromK0s_InvMass_Pt","ESD_TrueSecondaryMotherFromK0s_InvMass_Pt",800,0,0.8,250,0,25);
+            hESDTrueSecondaryMotherFromK0sInvMassPt[iCut]->Sumw2();
             fTrueList[iCut]->Add(hESDTrueSecondaryMotherFromK0sInvMassPt[iCut]);
             hESDTrueSecondaryMotherFromEtaInvMassPt[iCut]
                = new TH2F("ESD_TrueSecondaryMotherFromEta_InvMass_Pt","ESD_TrueSecondaryMotherFromEta_InvMass_Pt",800,0,0.8,250,0,25);
@@ -691,16 +737,29 @@ void AliAnalysisTaskGammaConvV1::UserCreateOutputObjects()
 Bool_t AliAnalysisTaskGammaConvV1::Notify()
 {
    for(Int_t iCut = 0; iCut<fnCuts;iCut++){
-      if(!((AliConversionCuts*)fCutArray->At(iCut))->GetDoEtaShift()) continue; // No Eta Shift requested, continue
-      
+     if(!((AliConversionCuts*)fCutArray->At(iCut))->GetDoEtaShift()){ 
+       if (((AliConversionCuts*)fCutArray->At(iCut))->GetEtaShift() != 0.){
+          ((AliConversionCuts*)fCutArray->At(iCut))->SetEtaShift(0.);
+          printf("Error: Gamma Conversion Task %s :: Eta Shift not requested but set to %f, reset to 0. \n\n",
+                (((AliConversionCuts*)fCutArray->At(iCut))->GetCutNumber()).Data(),((AliConversionCuts*)fCutArray->At(iCut))->GetEtaShift());
+       }   
+       
+       hEtaShift[iCut]->Fill(0.,0.);
+       continue; // No Eta Shift requested, continue
+     }
+
       if(((AliConversionCuts*)fCutArray->At(iCut))->GetEtaShift() == 0.0){ // Eta Shift requested but not set, get shift automatically
-         ((AliConversionCuts*)fCutArray->At(iCut))->GetCorrectEtaShiftFromPeriod(fV0Reader->GetPeriodName());
+       ((AliConversionCuts*)fCutArray->At(iCut))->GetCorrectEtaShiftFromPeriod(fV0Reader->GetPeriodName());
+       hEtaShift[iCut]->Fill(0.,(((AliConversionCuts*)fCutArray->At(iCut))->GetEtaShift()));
+               //      hEtaShift[iCut]->Fill(0);
          ((AliConversionCuts*)fCutArray->At(iCut))->DoEtaShift(kFALSE); // Eta Shift Set, make sure that it is called only once   
          continue;
       }
       else{
          printf(" Gamma Conversion Task %s :: Eta Shift Manually Set to %f \n\n",
                 (((AliConversionCuts*)fCutArray->At(iCut))->GetCutNumber()).Data(),((AliConversionCuts*)fCutArray->At(iCut))->GetEtaShift());
+        hEtaShift[iCut]->Fill(0.,(((AliConversionCuts*)fCutArray->At(iCut))->GetEtaShift()));
+               //      hEtaShift[iCut]->Fill(-0.5);
          ((AliConversionCuts*)fCutArray->At(iCut))->DoEtaShift(kFALSE); // Eta Shift Set, make sure that it is called only once   
       }
    }
@@ -721,17 +780,21 @@ void AliAnalysisTaskGammaConvV1::UserExec(Option_t *)
       return;
    }
 
-   fMCEvent = MCEvent();
-   if(fMCEvent){
+   if(fIsMC) fMCEvent = MCEvent();
+   fInputEvent = InputEvent();
+
+   if(fMCEvent && fInputEvent->IsA()==AliESDEvent::Class()){
       fMCStack = fMCEvent->Stack();
    }
-   fInputEvent = InputEvent();
 
    fReaderGammas = fV0Reader->GetReconstructedGammas(); // Gammas from default Cut
-   CountESDTracks(); // Estimate Event Multiplicity
+   CountTracks(); // Estimate Event Multiplicity
 
    // ------------------- BeginEvent ----------------------------
 
+   if(fMCEvent && fInputEvent->IsA()==AliAODEvent::Class())
+      RelabelAODPhotonCandidates(kTRUE);    // In case of AODMC relabeling MC
+
    for(Int_t iCut = 0; iCut<fnCuts; iCut++){
       fiCut = iCut;
 
@@ -755,13 +818,26 @@ void AliAnalysisTaskGammaConvV1::UserExec(Option_t *)
       if(((AliConversionCuts*)fCutArray->At(iCut))->IsHeavyIon() == 2) hNV0Tracks[iCut]->Fill(fInputEvent->GetVZEROData()->GetMTotV0A());
       else hNV0Tracks[iCut]->Fill(fInputEvent->GetVZEROData()->GetMTotV0A()+fInputEvent->GetVZEROData()->GetMTotV0C());
 
-      if(fMCEvent){ // Process MC Particle
+      if(fMCEvent){
+         // Process MC Particle
          if(((AliConversionCuts*)fCutArray->At(iCut))->GetSignalRejection() != 0){
-            ((AliConversionCuts*)fCutArray->At(iCut))->GetNotRejectedParticles(((AliConversionCuts*)fCutArray->At(iCut))->GetSignalRejection(),
-                                                                               ((AliConversionCuts*)fCutArray->At(iCut))->GetAcceptedHeader(),
-                                                                               fMCEvent);
+            if(fInputEvent->IsA()==AliESDEvent::Class()){
+               ((AliConversionCuts*)fCutArray->At(iCut))->GetNotRejectedParticles(((AliConversionCuts*)fCutArray->At(iCut))->GetSignalRejection(),
+                                                                                  ((AliConversionCuts*)fCutArray->At(iCut))->GetAcceptedHeader(),
+                                                                                  fMCEvent);
+            }
+            else if(fInputEvent->IsA()==AliAODEvent::Class()){
+               ((AliConversionCuts*)fCutArray->At(iCut))->GetNotRejectedParticles(((AliConversionCuts*)fCutArray->At(iCut))->GetSignalRejection(),
+                                                                                  ((AliConversionCuts*)fCutArray->At(iCut))->GetAcceptedHeader(),
+                                                                                  fInputEvent);
+            }
          }
-         ProcessMCParticles();
+      }
+      if(fMCEvent){
+         if(fInputEvent->IsA()==AliESDEvent::Class())
+            ProcessMCParticles();
+         if(fInputEvent->IsA()==AliAODEvent::Class())
+            ProcessAODMCParticles();
       }
 
       ProcessPhotonCandidates(); // Process this cuts gammas
@@ -808,9 +884,11 @@ void AliAnalysisTaskGammaConvV1::UserExec(Option_t *)
          }
       }
       fGammaCandidates->Clear(); // delete this cuts good gammas
-
    }
 
+   if(fMCEvent && fInputEvent->IsA()==AliAODEvent::Class())
+      RelabelAODPhotonCandidates(kFALSE); // Back to ESDMC Label
+   
    PostData(1, fOutputContainer);
 }
 //________________________________________________________________________
@@ -826,10 +904,10 @@ void AliAnalysisTaskGammaConvV1::ProcessPhotonCandidates()
       fIsFromMBHeader = kTRUE;
       if(fMCEvent && ((AliConversionCuts*)fCutArray->At(fiCut))->GetSignalRejection() != 0){
          Int_t isPosFromMBHeader
-            = ((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelPositive(), fMCStack);
+            = ((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelPositive(), fMCStack, fInputEvent);
          if(isPosFromMBHeader == 0 && ((AliConversionCuts*)fCutArray->At(fiCut))->GetSignalRejection() != 3) continue;
          Int_t isNegFromMBHeader
-            = ((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelNegative(), fMCStack);
+            = ((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelNegative(), fMCStack, fInputEvent);
          if(isNegFromMBHeader == 0 && ((AliConversionCuts*)fCutArray->At(fiCut))->GetSignalRejection() != 3) continue;
 
          if( (isNegFromMBHeader+isPosFromMBHeader) != 4) fIsFromMBHeader = kFALSE;
@@ -845,7 +923,10 @@ void AliAnalysisTaskGammaConvV1::ProcessPhotonCandidates()
             if (fDoPhotonQA)hESDConvGammaR[fiCut]->Fill(PhotonCandidate->GetConversionRadius());
          }
          if(fMCEvent){
-            ProcessTruePhotonCandidates(PhotonCandidate);
+            if(fInputEvent->IsA()==AliESDEvent::Class())
+               ProcessTruePhotonCandidates(PhotonCandidate);
+            if(fInputEvent->IsA()==AliAODEvent::Class())
+               ProcessTruePhotonCandidatesAOD(PhotonCandidate);
          }
       }
       else if(((AliConversionCuts*)fCutArray->At(fiCut))->UseElecSharingCut()){ // if Shared Electron cut is enabled, Fill array, add to step one
@@ -863,11 +944,11 @@ void AliAnalysisTaskGammaConvV1::ProcessPhotonCandidates()
          AliAODConversionPhoton *PhotonCandidate= (AliAODConversionPhoton*) GammaCandidatesStepOne->At(i);
          if(!PhotonCandidate) continue;
          fIsFromMBHeader = kTRUE;
-         if(fMCEvent && ((AliConversionCuts*)fCutArray->At(fiCut))->GetSignalRejection() != 0){
+         if(fMCStack && ((AliConversionCuts*)fCutArray->At(fiCut))->GetSignalRejection() != 0){
             Int_t isPosFromMBHeader
-               = ((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelPositive(), fMCStack);
+               = ((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelPositive(), fMCStack, fInputEvent);
             Int_t isNegFromMBHeader
-               = ((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelNegative(), fMCStack);
+               = ((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelNegative(), fMCStack, fInputEvent);
             if( (isNegFromMBHeader+isPosFromMBHeader) != 4) fIsFromMBHeader = kFALSE;
          }
          if(!((AliConversionCuts*)fCutArray->At(fiCut))->RejectSharedElectronV0s(PhotonCandidate,i,GammaCandidatesStepOne->GetEntries())) continue;
@@ -877,9 +958,12 @@ void AliAnalysisTaskGammaConvV1::ProcessPhotonCandidates()
                hESDConvGammaPt[fiCut]->Fill(PhotonCandidate->Pt());
                if (fDoPhotonQA)hESDConvGammaR[fiCut]->Fill(PhotonCandidate->GetConversionRadius());
             }
-            if(fMCEvent){
+         }
+         if(fMCEvent){
+            if(fInputEvent->IsA()==AliESDEvent::Class())
                ProcessTruePhotonCandidates(PhotonCandidate);
-            }
+            if(fInputEvent->IsA()==AliAODEvent::Class())
+               ProcessTruePhotonCandidatesAOD(PhotonCandidate);
          }
          else GammaCandidatesStepTwo->Add(PhotonCandidate); // Close v0s cut enabled -> add to list two
       }
@@ -889,11 +973,11 @@ void AliAnalysisTaskGammaConvV1::ProcessPhotonCandidates()
          AliAODConversionPhoton* PhotonCandidate = (AliAODConversionPhoton*) GammaCandidatesStepTwo->At(i);
          if(!PhotonCandidate) continue;
          fIsFromMBHeader = kTRUE;
-         if(fMCEvent && ((AliConversionCuts*)fCutArray->At(fiCut))->GetSignalRejection() != 0){
+         if(fMCStack && ((AliConversionCuts*)fCutArray->At(fiCut))->GetSignalRejection() != 0){
             Int_t isPosFromMBHeader
-               = ((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelPositive(), fMCStack);
+               = ((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelPositive(), fMCStack, fInputEvent);
             Int_t isNegFromMBHeader
-               = ((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelNegative(), fMCStack);
+               = ((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelNegative(), fMCStack, fInputEvent);
             if( (isNegFromMBHeader+isPosFromMBHeader) != 4) fIsFromMBHeader = kFALSE;
          }
          if(!((AliConversionCuts*)fCutArray->At(fiCut))->RejectToCloseV0s(PhotonCandidate,GammaCandidatesStepTwo,i)) continue;
@@ -903,7 +987,10 @@ void AliAnalysisTaskGammaConvV1::ProcessPhotonCandidates()
             if (fDoPhotonQA)hESDConvGammaR[fiCut]->Fill(PhotonCandidate->GetConversionRadius());
          }
          if(fMCEvent){
-            ProcessTruePhotonCandidates(PhotonCandidate);
+            if(fInputEvent->IsA()==AliESDEvent::Class())
+               ProcessTruePhotonCandidates(PhotonCandidate);
+            if(fInputEvent->IsA()==AliAODEvent::Class())
+               ProcessTruePhotonCandidatesAOD(PhotonCandidate);
          }
       }
    }
@@ -915,74 +1002,80 @@ void AliAnalysisTaskGammaConvV1::ProcessPhotonCandidates()
 
 }
 //________________________________________________________________________
+void AliAnalysisTaskGammaConvV1::ProcessTruePhotonCandidatesAOD(AliAODConversionPhoton *TruePhotonCandidate)
+{
+
+   TClonesArray *AODMCTrackArray = dynamic_cast<TClonesArray*>(fInputEvent->FindListObject(AliAODMCParticle::StdBranchName()));
+   AliAODMCParticle *posDaughter = (AliAODMCParticle*) AODMCTrackArray->At(TruePhotonCandidate->GetMCLabelPositive());
+   AliAODMCParticle *negDaughter = (AliAODMCParticle*) AODMCTrackArray->At(TruePhotonCandidate->GetMCLabelNegative());
+   
+   if(posDaughter == NULL || negDaughter == NULL) return; // One particle does not exist
+   Int_t pdgCode[2] = {abs(posDaughter->GetPdgCode()),abs(negDaughter->GetPdgCode())};
+
+   if(posDaughter->GetMother() != negDaughter->GetMother()){
+      FillPhotonCombinatorialBackgroundHist(TruePhotonCandidate, pdgCode);
+      return;
+   }
+   else if(posDaughter->GetMother() == -1){
+      FillPhotonCombinatorialBackgroundHist(TruePhotonCandidate, pdgCode);
+      return;
+   }
+
+   if(pdgCode[0]!=11 || pdgCode[1]!=11) return; //One Particle is not a electron
+
+   if(posDaughter->GetPdgCode()==negDaughter->GetPdgCode()) return; // Same Charge
+
+   if(((posDaughter->GetMCProcessCode())) != 5 || ((negDaughter->GetMCProcessCode())) != 5) return;// check if the daughters come from a conversion 
+   // STILL A BUG IN ALIROOT >>8 HAS TPO BE REMOVED AFTER FIX
+   
+   AliAODMCParticle *Photon = (AliAODMCParticle*) AODMCTrackArray->At(posDaughter->GetMother());
+   if(Photon->GetPdgCode() != 22) return; // Mother is no Photon
+
+   // True Photon
+   if(fIsFromMBHeader)hESDTrueConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
+
+   if(Photon->IsPrimary()){ // OR ISPHYSICALPRIMARY() ???????
+      // Count just primary MC Gammas as true --> For Ratio esdtruegamma / mcconvgamma
+      if(fIsFromMBHeader){
+         hESDTruePrimaryConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
+         if (fDoPhotonQA){
+            hESDTruePrimaryConvGammaR[fiCut]->Fill(TruePhotonCandidate->GetConversionRadius());
+            hESDTruePrimaryConvGammaEta[fiCut]->Fill(TruePhotonCandidate->Eta());
+         }
+         hESDTruePrimaryConvGammaRSESDPtMCPt[fiCut]->Fill(TruePhotonCandidate->Pt(),Photon->Pt()); // Allways Filled
+      }
+      hESDTruePrimaryConvGammaESDPtMCPt[fiCut]->Fill(TruePhotonCandidate->Pt(),Photon->Pt()); // Allways Filled
+      // (Not Filled for i6, Extra Signal Gamma (parambox) are secondary)
+   }
+   else{
+      if(fIsFromMBHeader){
+         hESDTrueSecondaryConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
+         if (fDoPhotonQA) hESDTrueSecondaryConvGammaR[fiCut]->Fill(TruePhotonCandidate->GetConversionRadius());
+         if(((AliAODMCParticle*)AODMCTrackArray->At(Photon->GetMother()))->GetMother() > -1 &&
+            ((AliAODMCParticle*)AODMCTrackArray->At(((AliAODMCParticle*)AODMCTrackArray->At(Photon->GetMother()))->GetMother()))->GetPdgCode() == 310){
+            hESDTrueSecondaryConvGammaFromXFromK0sPt[fiCut]->Fill(TruePhotonCandidate->Pt());
+         }
+      }
+   }
+
+}
+//________________________________________________________________________
 void AliAnalysisTaskGammaConvV1::ProcessTruePhotonCandidates(AliAODConversionPhoton *TruePhotonCandidate)
 {
    // Process True Photons
-   AliStack *MCStack = fMCEvent->Stack();
-   TParticle *posDaughter = TruePhotonCandidate->GetPositiveMCDaughter(MCStack);
-   TParticle *negDaughter = TruePhotonCandidate->GetNegativeMCDaughter(MCStack);
+   TParticle *posDaughter = TruePhotonCandidate->GetPositiveMCDaughter(fMCStack);
+   TParticle *negDaughter = TruePhotonCandidate->GetNegativeMCDaughter(fMCStack);
 
    if(posDaughter == NULL || negDaughter == NULL) return; // One particle does not exist
 
    Int_t pdgCode[2] = {abs(posDaughter->GetPdgCode()),abs(negDaughter->GetPdgCode())};
 
    if(posDaughter->GetMother(0) != negDaughter->GetMother(0)){
-      // Combinatorial Bck = 0 ee, 1 ep,i 2 ek, 3 ep, 4 emu, 5 pipi, 6 pik, 7 pip, 8 pimu, 9 kk, 10 kp, 11 kmu, 12 pp, 13 pmu, 14 mumu, 15 Rest
-      if(pdgCode[0]==11   && pdgCode[1]==11){if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),0);}
-      else if( (pdgCode[0]==11   && pdgCode[1]==211) || (pdgCode[0]==211  && pdgCode[1]==11) )
-         {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),1);}
-      else if( (pdgCode[0]==11   && pdgCode[1]==321) || (pdgCode[0]==321  && pdgCode[1]==11) )
-         {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),2);}
-      else if( (pdgCode[0]==11   && pdgCode[1]==2212) || (pdgCode[0]==2212 && pdgCode[1]==11) )
-         {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),3);}
-      else if( (pdgCode[0]==11   && pdgCode[1]==13) || (pdgCode[0]==13   && pdgCode[1]==11) )
-         {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),4);}
-      else if(  pdgCode[0]==211  && pdgCode[1]==211 ){if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),5);}
-      else if( (pdgCode[0]==211  && pdgCode[1]==321) || (pdgCode[0]==321  && pdgCode[1]==211) )
-         {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),6);}
-      else if( (pdgCode[0]==211  && pdgCode[1]==2212) || (pdgCode[0]==2212 && pdgCode[1]==211) )
-         {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),7);}
-      else if( (pdgCode[0]==211  && pdgCode[1]==13) || (pdgCode[0]==13   && pdgCode[1]==211) )
-         {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),8);}
-      else if(  pdgCode[0]==321  && pdgCode[1]==321 ){if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),9);}
-      else if( (pdgCode[0]==321  && pdgCode[1]==2212) || (pdgCode[0]==2212 && pdgCode[1]==321) )
-         {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),10);}
-      else if( (pdgCode[0]==321  && pdgCode[1]==13) || (pdgCode[0]==13   && pdgCode[1]==321) )
-         {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),11);}
-      else if(  pdgCode[0]==2212   && pdgCode[1]==2212  ){if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),12);}
-      else if( (pdgCode[0]==2212  && pdgCode[1]==13) || (pdgCode[0]==13   && pdgCode[1]==2212) )
-         {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),13);}
-      else if(  pdgCode[0]==13   && pdgCode[1]==13  ){if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),14);}
-      else {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),15);}
+      FillPhotonCombinatorialBackgroundHist(TruePhotonCandidate, pdgCode);
       return;
    }
    else if(posDaughter->GetMother(0) == -1){
-      if(pdgCode[0]==11   && pdgCode[1]==11){if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),0);}
-      else if( (pdgCode[0]==11   && pdgCode[1]==211) || (pdgCode[0]==211  && pdgCode[1]==11) )
-         {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),1);}
-      else if( (pdgCode[0]==11   && pdgCode[1]==321) || (pdgCode[0]==321  && pdgCode[1]==11) )
-         {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),2);}
-      else if( (pdgCode[0]==11   && pdgCode[1]==2212) || (pdgCode[0]==2212 && pdgCode[1]==11) )
-         {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),3);}
-      else if( (pdgCode[0]==11   && pdgCode[1]==13) || (pdgCode[0]==13   && pdgCode[1]==11) )
-         {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),4);}
-      else if(  pdgCode[0]==211  && pdgCode[1]==211 ){if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),5);}
-      else if( (pdgCode[0]==211  && pdgCode[1]==321) || (pdgCode[0]==321  && pdgCode[1]==211) )
-         {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),6);}
-      else if( (pdgCode[0]==211  && pdgCode[1]==2212) || (pdgCode[0]==2212 && pdgCode[1]==211) )
-         {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),7);}
-      else if( (pdgCode[0]==211  && pdgCode[1]==13) || (pdgCode[0]==13   && pdgCode[1]==211) )
-         {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),8);}
-      else if(  pdgCode[0]==321  && pdgCode[1]==321 ){if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),9);}
-      else if( (pdgCode[0]==321  && pdgCode[1]==2212) || (pdgCode[0]==2212 && pdgCode[1]==321) )
-         {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),10);}
-      else if( (pdgCode[0]==321  && pdgCode[1]==13) || (pdgCode[0]==13   && pdgCode[1]==321) )
-         {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),11);}
-      else if(  pdgCode[0]==2212   && pdgCode[1]==2212  ){if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),12);}
-      else if( (pdgCode[0]==2212  && pdgCode[1]==13) || (pdgCode[0]==13   && pdgCode[1]==2212) )
-         {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),13);}
-      else if(  pdgCode[0]==13   && pdgCode[1]==13  ){if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),14);}
-      else {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),15);}
+      FillPhotonCombinatorialBackgroundHist(TruePhotonCandidate, pdgCode);
       return;
    }
 
@@ -992,13 +1085,13 @@ void AliAnalysisTaskGammaConvV1::ProcessTruePhotonCandidates(AliAODConversionPho
 
    if(posDaughter->GetUniqueID() != 5 || negDaughter->GetUniqueID() !=5) return;// check if the daughters come from a conversion
 
-   TParticle *Photon = TruePhotonCandidate->GetMCParticle(MCStack);
+   TParticle *Photon = TruePhotonCandidate->GetMCParticle(fMCStack);
    if(Photon->GetPdgCode() != 22) return; // Mother is no Photon
 
    // True Photon
    if(fIsFromMBHeader)hESDTrueConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
 
-   if(posDaughter->GetMother(0) <= MCStack->GetNprimary()){
+   if(posDaughter->GetMother(0) <= fMCStack->GetNprimary()){
       // Count just primary MC Gammas as true --> For Ratio esdtruegamma / mcconvgamma
       if(fIsFromMBHeader){
          hESDTruePrimaryConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
@@ -1015,14 +1108,146 @@ void AliAnalysisTaskGammaConvV1::ProcessTruePhotonCandidates(AliAODConversionPho
       if(fIsFromMBHeader){
          hESDTrueSecondaryConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
          if (fDoPhotonQA) hESDTrueSecondaryConvGammaR[fiCut]->Fill(TruePhotonCandidate->GetConversionRadius());
-         if(MCStack->Particle(Photon->GetMother(0))->GetMother(0) > -1 &&
-            MCStack->Particle(MCStack->Particle(Photon->GetMother(0))->GetMother(0))->GetPdgCode() == 310){
+         if(fMCStack->Particle(Photon->GetMother(0))->GetMother(0) > -1 &&
+            fMCStack->Particle(fMCStack->Particle(Photon->GetMother(0))->GetMother(0))->GetPdgCode() == 310){
             hESDTrueSecondaryConvGammaFromXFromK0sPt[fiCut]->Fill(TruePhotonCandidate->Pt());
          }
       }
    }
 }
 //________________________________________________________________________
+void AliAnalysisTaskGammaConvV1::ProcessAODMCParticles()
+{
+
+   TClonesArray *AODMCTrackArray = dynamic_cast<TClonesArray*>(fInputEvent->FindListObject(AliAODMCParticle::StdBranchName()));
+
+   // Loop over all primary MC particle
+   for(Int_t i = 0; i < AODMCTrackArray->GetEntriesFast(); i++) {
+
+      AliAODMCParticle* particle = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(i));
+      if (!particle) continue;
+      if (!particle->IsPrimary()) continue;
+
+      Bool_t mcIsFromMB = kTRUE;
+      Int_t isMCFromMBHeader = -1;
+      if(((AliConversionCuts*)fCutArray->At(fiCut))->GetSignalRejection() != 0){
+         isMCFromMBHeader
+            = ((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(i, fMCStack, fInputEvent);
+         if(isMCFromMBHeader == 0 && ((AliConversionCuts*)fCutArray->At(fiCut))->GetSignalRejection() != 3) continue;
+         if(isMCFromMBHeader != 2) mcIsFromMB = kFALSE;
+      }
+
+      if(((AliConversionCuts*)fCutArray->At(fiCut))->PhotonIsSelectedAODMC(particle,AODMCTrackArray,kFALSE)){
+         hMCAllGammaPt[fiCut]->Fill(particle->Pt()); // All MC Gamma
+         if(particle->GetMother() >-1){ // Meson Decay Gamma
+            switch((static_cast<AliAODMCParticle*>(AODMCTrackArray->At(particle->GetMother())))->GetPdgCode()){
+            case 111: // Pi0
+               hMCDecayGammaPi0Pt[fiCut]->Fill(particle->Pt());
+               break;
+            case 113: // Rho0
+               hMCDecayGammaRhoPt[fiCut]->Fill(particle->Pt());
+               break;
+            case 221: // Eta
+               hMCDecayGammaEtaPt[fiCut]->Fill(particle->Pt());
+               break;
+            case 223: // Omega
+               hMCDecayGammaOmegaPt[fiCut]->Fill(particle->Pt());
+               break;
+            case 331: // Eta'
+               hMCDecayGammaEtapPt[fiCut]->Fill(particle->Pt());
+               break;
+            case 333: // Phi
+               hMCDecayGammaPhiPt[fiCut]->Fill(particle->Pt());
+               break;
+            case 3212: // Sigma
+               hMCDecayGammaSigmaPt[fiCut]->Fill(particle->Pt());
+               break;
+            }
+         }
+      }
+      if(((AliConversionCuts*)fCutArray->At(fiCut))->PhotonIsSelectedAODMC(particle,AODMCTrackArray,kTRUE)){
+         Double_t rConv = 0;
+         for(Int_t daughterIndex=particle->GetDaughter(0);daughterIndex<=particle->GetDaughter(1);daughterIndex++){
+            AliAODMCParticle *tmpDaughter = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(daughterIndex));
+            if(!tmpDaughter) continue;
+            if(abs(tmpDaughter->GetPdgCode()) == 11){
+               rConv = sqrt( (tmpDaughter->Xv()*tmpDaughter->Xv()) + (tmpDaughter->Yv()*tmpDaughter->Yv()) );
+            }
+         }
+         hMCConvGammaPt[fiCut]->Fill(particle->Pt());
+         if (fDoPhotonQA){
+            hMCConvGammaR[fiCut]->Fill(rConv);
+            hMCConvGammaEta[fiCut]->Fill(particle->Eta());
+         }
+         if(mcIsFromMB){
+            hMCConvGammaRSPt[fiCut]->Fill(particle->Pt());
+            if (fDoPhotonQA){
+               hMCConvGammaRSR[fiCut]->Fill(rConv);
+               hMCConvGammaRSEta[fiCut]->Fill(particle->Eta());
+            }
+         }
+      }
+      // Converted MC Gamma
+      if(fDoMesonAnalysis){
+         if(particle->GetPdgCode() == 310 && fDoMesonQA){
+            Double_t mesonY = 10.;
+            if(particle->E() - particle->Pz() == 0 || particle->E() + particle->Pz() == 0){
+               mesonY=10.-((AliConversionCuts*)fCutArray->At(fiCut))->GetEtaShift();
+            } else{
+               mesonY = 0.5*(TMath::Log((particle->E()+particle->Pz()) / (particle->E()-particle->Pz())))-((AliConversionCuts*)fCutArray->At(fiCut))->GetEtaShift();
+            }
+            Float_t weightedK0s= 1;
+            if(((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(i, fMCStack, fInputEvent)){
+               if (particle->Pt()>0.005){
+                  weightedK0s= ((AliConversionCuts*)fCutArray->At(fiCut))->GetWeightForMeson(fV0Reader->GetPeriodName(),i, 0x0, fInputEvent);
+                  //cout << "MC input \t"<<i << "\t" <<  particle->Pt()<<"\t"<<weighted << endl;
+               }
+            }
+            hMCK0sPt[fiCut]->Fill(particle->Pt(),weightedK0s);
+            hMCK0sWOWeightPt[fiCut]->Fill(particle->Pt());
+            hMCK0sPtY[fiCut]->Fill(particle->Pt(),mesonY,weightedK0s);
+         }         
+         if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->MesonIsSelectedAODMC(particle,AODMCTrackArray,((AliConversionCuts*)fCutArray->At(fiCut))->GetEtaShift())){
+            AliAODMCParticle* daughter0 = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(particle->GetDaughter(0)));
+            AliAODMCParticle* daughter1 = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(particle->GetDaughter(1)));
+            Float_t weighted= 1;
+            if(((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(i, fMCStack, fInputEvent)){
+               if (particle->Pt()>0.005){
+                  weighted= ((AliConversionCuts*)fCutArray->At(fiCut))->GetWeightForMeson(fV0Reader->GetPeriodName(),i, 0x0, fInputEvent);
+                  //cout << "MC input \t"<<i << "\t" <<  particle->Pt()<<"\t"<<weighted << endl;
+               }
+            }
+            Double_t mesonY = 10.;
+            if(particle->E() - particle->Pz() == 0 || particle->E() + particle->Pz() == 0){
+               mesonY=10.-((AliConversionCuts*)fCutArray->At(fiCut))->GetEtaShift();
+            } else{
+               mesonY = 0.5*(TMath::Log((particle->E()+particle->Pz()) / (particle->E()-particle->Pz())))-((AliConversionCuts*)fCutArray->At(fiCut))->GetEtaShift();
+            }
+
+            if(particle->GetPdgCode() == 111){
+               hMCPi0Pt[fiCut]->Fill(particle->Pt(),weighted); // All MC Pi0
+               hMCPi0WOWeightPt[fiCut]->Fill(particle->Pt());
+               if (fDoMesonQA) hMCPi0PtY[fiCut]->Fill(particle->Pt(),mesonY,weighted); // All MC Pi0
+            } else if(particle->GetPdgCode() == 221){
+               hMCEtaPt[fiCut]->Fill(particle->Pt(),weighted); // All MC Eta
+               if (fDoMesonQA) hMCEtaPtY[fiCut]->Fill(particle->Pt(),mesonY,weighted); // All MC Pi0
+            }
+            
+            // Check the acceptance for both gammas
+            if(((AliConversionCuts*)fCutArray->At(fiCut))->PhotonIsSelectedAODMC(daughter0,AODMCTrackArray,kFALSE) &&
+               ((AliConversionCuts*)fCutArray->At(fiCut))->PhotonIsSelectedAODMC(daughter1,AODMCTrackArray,kFALSE) ){
+
+               if(particle->GetPdgCode() == 111){
+                  hMCPi0InAccPt[fiCut]->Fill(particle->Pt(),weighted); // MC Pi0 with gamma in acc
+               } else if(particle->GetPdgCode() == 221){
+                  hMCEtaInAccPt[fiCut]->Fill(particle->Pt(),weighted); // MC Eta with gamma in acc
+               }
+            }
+         }
+      }
+   }
+}
+//________________________________________________________________________
 void AliAnalysisTaskGammaConvV1::ProcessMCParticles()
 {
    // Loop over all primary MC particle
@@ -1034,7 +1259,7 @@ void AliAnalysisTaskGammaConvV1::ProcessMCParticles()
       Int_t isMCFromMBHeader = -1;
       if(((AliConversionCuts*)fCutArray->At(fiCut))->GetSignalRejection() != 0){
          isMCFromMBHeader
-            = ((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(i, fMCStack);
+            = ((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(i, fMCStack, fInputEvent);
          if(isMCFromMBHeader == 0 && ((AliConversionCuts*)fCutArray->At(fiCut))->GetSignalRejection() != 3) continue;
          if(isMCFromMBHeader != 2) mcIsFromMB = kFALSE;
       }
@@ -1082,14 +1307,33 @@ void AliAnalysisTaskGammaConvV1::ProcessMCParticles()
          }
       } // Converted MC Gamma
       if(fDoMesonAnalysis){
+         if(particle->GetPdgCode() == 310 && fDoMesonQA){
+            Double_t mesonY = 10.;
+            if(particle->Energy() - particle->Pz() == 0 || particle->Energy() + particle->Pz() == 0){
+               mesonY=10.-((AliConversionCuts*)fCutArray->At(fiCut))->GetEtaShift();
+            } else{
+               mesonY = 0.5*(TMath::Log((particle->Energy()+particle->Pz()) / (particle->Energy()-particle->Pz())))-((AliConversionCuts*)fCutArray->At(fiCut))->GetEtaShift();
+            }
+            Float_t weightedK0s= 1;
+            if(((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(i, fMCStack, fInputEvent)){
+               if (particle->Pt()>0.005){
+                  weightedK0s= ((AliConversionCuts*)fCutArray->At(fiCut))->GetWeightForMeson(fV0Reader->GetPeriodName(),i, fMCStack, fInputEvent);
+                  //cout << "MC input \t"<<i << "\t" <<  particle->Pt()<<"\t"<<weighted << endl;
+               }
+            }
+            hMCK0sPt[fiCut]->Fill(particle->Pt(),weightedK0s);
+            hMCK0sWOWeightPt[fiCut]->Fill(particle->Pt());
+            hMCK0sPtY[fiCut]->Fill(particle->Pt(),mesonY,weightedK0s);
+         }
          if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->MesonIsSelectedMC(particle,fMCStack,((AliConversionCuts*)fCutArray->At(fiCut))->GetEtaShift())){
             TParticle* daughter0 = (TParticle*)fMCStack->Particle(particle->GetFirstDaughter());
             TParticle* daughter1 = (TParticle*)fMCStack->Particle(particle->GetLastDaughter());
 
             Float_t weighted= 1;
-            if(((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(i, fMCStack)){
+            if(((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(i, fMCStack, fInputEvent)){
                if (particle->Pt()>0.005){
-                  weighted= ((AliConversionCuts*)fCutArray->At(fiCut))->GetWeightForMeson(fV0Reader->GetPeriodName(),i, fMCStack);
+                  weighted= ((AliConversionCuts*)fCutArray->At(fiCut))->GetWeightForMeson(fV0Reader->GetPeriodName(),i, fMCStack, fInputEvent);
+                  //cout << "MC input \t"<<i << "\t" <<  particle->Pt()<<"\t"<<weighted << endl;
                }
             }
             Double_t mesonY = 10.;
@@ -1101,11 +1345,12 @@ void AliAnalysisTaskGammaConvV1::ProcessMCParticles()
 
             if(particle->GetPdgCode() == 111){
                hMCPi0Pt[fiCut]->Fill(particle->Pt(),weighted); // All MC Pi0
+               hMCPi0WOWeightPt[fiCut]->Fill(particle->Pt());
                if (fDoMesonQA) hMCPi0PtY[fiCut]->Fill(particle->Pt(),mesonY,weighted); // All MC Pi0
             } else if(particle->GetPdgCode() == 221){
                hMCEtaPt[fiCut]->Fill(particle->Pt(),weighted); // All MC Eta
                if (fDoMesonQA) hMCEtaPtY[fiCut]->Fill(particle->Pt(),mesonY,weighted); // All MC Pi0
-            }
+            } 
 
             // Check the acceptance for both gammas
             if(((AliConversionCuts*)fCutArray->At(fiCut))->PhotonIsSelectedMC(daughter0,fMCStack,kFALSE) &&
@@ -1172,8 +1417,13 @@ void AliAnalysisTaskGammaConvV1::CalculatePi0Candidates(){
                   Double_t sparesFill[4] = {pi0cand->M(),pi0cand->Pt(),(Double_t)zbin,(Double_t)mbin};
                   sESDMotherInvMassPtZM[fiCut]->Fill(sparesFill,1);
                }
+               
+
                if(fMCEvent){
-                  ProcessTrueMesonCandidates(pi0cand,gamma0,gamma1);
+                  if(fInputEvent->IsA()==AliESDEvent::Class())
+                     ProcessTrueMesonCandidates(pi0cand,gamma0,gamma1);
+                  if(fInputEvent->IsA()==AliAODEvent::Class())
+                     ProcessTrueMesonCandidatesAOD(pi0cand,gamma0,gamma1);
                }
             }
             delete pi0cand;
@@ -1246,24 +1496,32 @@ void AliAnalysisTaskGammaConvV1::ProcessTrueMesonCandidates(AliAODConversionMoth
             hESDTrueMotherInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
 
             if(gamma0MotherLabel >= MCStack->GetNprimary()){ // Secondary Meson
-               hESDTrueSecondaryMotherInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
-               if (((TParticle*)MCStack->Particle(gamma1MotherLabel))->GetMother(0) >-1){
-                  if(MCStack->Particle(((TParticle*)MCStack->Particle(gamma1MotherLabel))->GetMother(0))->GetPdgCode()==kK0Short){
-                     hESDTrueSecondaryMotherFromK0sInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
+               Int_t secMotherLabel = ((TParticle*)MCStack->Particle(gamma1MotherLabel))->GetMother(0);
+               Float_t weightedSec= 1;
+               if(((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(secMotherLabel, fMCStack, fInputEvent) && MCStack->Particle(secMotherLabel)->GetPdgCode()==310){
+                  weightedSec= ((AliConversionCuts*)fCutArray->At(fiCut))->GetWeightForMeson(fV0Reader->GetPeriodName(),secMotherLabel, fMCStack, fInputEvent)/2.; //invariant mass is additive thus the weight for the daughters has to be devide by two for the K0s at a certain pt
+                  //cout << "MC input \t"<<i << "\t" <<  particle->Pt()<<"\t"<<weighted << endl;
+               }
+               hESDTrueSecondaryMotherInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weightedSec);
+               
+               if (secMotherLabel >-1){
+                  if(MCStack->Particle(secMotherLabel)->GetPdgCode()==310){
+                     hESDTrueSecondaryMotherFromK0sInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weightedSec);
                      if (fDoMesonQA)hESDTrueK0sWithPi0DaughterMCPt[fiCut]
-                                       ->Fill(MCStack->Particle(((TParticle*)MCStack->Particle(gamma1MotherLabel))->GetMother(0))->Pt());
+                                       ->Fill(MCStack->Particle(secMotherLabel)->Pt());
                   }
-                  if(MCStack->Particle(((TParticle*)MCStack->Particle(gamma1MotherLabel))->GetMother(0))->GetPdgCode()==221){
-                     hESDTrueSecondaryMotherFromEtaInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
+                  if(MCStack->Particle(secMotherLabel)->GetPdgCode()==221){
+                     hESDTrueSecondaryMotherFromEtaInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weightedSec);
                      if (fDoMesonQA)hESDTrueEtaWithPi0DaughterMCPt[fiCut]
-                                       ->Fill(MCStack->Particle(((TParticle*)MCStack->Particle(gamma1MotherLabel))->GetMother(0))->Pt());
+                                       ->Fill(MCStack->Particle(secMotherLabel)->Pt());
                   }
                }
             }else{ // Only primary pi0 for efficiency calculation
                Float_t weighted= 1;
-               if(((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(gamma1MotherLabel, fMCStack)){
+               if(((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(gamma1MotherLabel, fMCStack, fInputEvent)){
                   if (((TParticle*)MCStack->Particle(gamma1MotherLabel))->Pt()>0.005){
-                     weighted= ((AliConversionCuts*)fCutArray->At(fiCut))->GetWeightForMeson(fV0Reader->GetPeriodName(),gamma1MotherLabel, fMCStack);
+                     weighted= ((AliConversionCuts*)fCutArray->At(fiCut))->GetWeightForMeson(fV0Reader->GetPeriodName(),gamma1MotherLabel, fMCStack, fInputEvent);
+//                      cout << "rec \t " <<gamma1MotherLabel << "\t" <<  weighted << endl;
                   }
                }
                hESDTruePrimaryMotherInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weighted);
@@ -1294,7 +1552,140 @@ void AliAnalysisTaskGammaConvV1::ProcessTrueMesonCandidates(AliAODConversionMoth
       }
    }
 }
+//______________________________________________________________________
+void AliAnalysisTaskGammaConvV1::ProcessTrueMesonCandidatesAOD(AliAODConversionMother *Pi0Candidate, AliAODConversionPhoton *TrueGammaCandidate0, AliAODConversionPhoton *TrueGammaCandidate1)
+{
+
+   // Process True Mesons
+   TClonesArray *AODMCTrackArray = dynamic_cast<TClonesArray*>(fInputEvent->FindListObject(AliAODMCParticle::StdBranchName()));
+   Bool_t isTruePi0 = kFALSE;
+   Bool_t isTrueEta = kFALSE;
+   
+   AliAODMCParticle *positiveMC = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(TrueGammaCandidate0->GetMCLabelPositive()));
+   AliAODMCParticle *negativeMC = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(TrueGammaCandidate0->GetMCLabelNegative()));
 
+   Int_t gamma0MCLabel = -1;
+   Int_t gamma0MotherLabel = -1;
+   if(!positiveMC||!negativeMC)
+      return;
+   
+   if(positiveMC->GetMother()>-1&&(negativeMC->GetMother() == positiveMC->GetMother())){
+      gamma0MCLabel = positiveMC->GetMother();
+   }
+
+   if(gamma0MCLabel != -1){ // Gamma is Combinatorial; MC Particles don't belong to the same Mother
+      // Daughters Gamma 0
+      AliAODMCParticle * gammaMC0 = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma0MCLabel));
+      if(abs(negativeMC->GetPdgCode())==11 && abs(positiveMC->GetPdgCode())==11){  // Electrons ...
+         if(((positiveMC->GetMCProcessCode())) == 5 && ((negativeMC->GetMCProcessCode())) == 5){ // ... From Conversion ...     // STILL A BUG IN ALIROOT >>8 HAS TPO BE REMOVED AFTER FIX
+            if(gammaMC0->GetPdgCode() == 22){ // ... with Gamma Mother
+               gamma0MotherLabel=gammaMC0->GetMother();
+            }
+         }
+         if(gammaMC0->GetPdgCode() ==111){ // Conversion but Pi0 Mother
+            gamma0MotherLabel=-111;
+         }
+         if(gammaMC0->GetPdgCode() ==221){ // Conversion but Eta Mother
+            gamma0MotherLabel=-221;
+         }
+      }
+   }
+   positiveMC = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(TrueGammaCandidate1->GetMCLabelPositive()));
+   negativeMC = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(TrueGammaCandidate1->GetMCLabelNegative()));
+   
+   Int_t gamma1MCLabel = -1;
+   Int_t gamma1MotherLabel = -1;
+   if(!positiveMC||!negativeMC)
+      return;
+   
+   if(positiveMC->GetMother()>-1&&(negativeMC->GetMother() == positiveMC->GetMother())){
+      gamma1MCLabel = positiveMC->GetMother();
+   }
+   if(gamma1MCLabel != -1){ // Gamma is Combinatorial; MC Particles don't belong to the same Mother
+      // Daughters Gamma 1
+      AliAODMCParticle * gammaMC1 = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma1MCLabel));
+      if(abs(negativeMC->GetPdgCode())==11 && abs(positiveMC->GetPdgCode())==11){  // Electrons ...
+         if(((positiveMC->GetMCProcessCode())) == 5 && ((negativeMC->GetMCProcessCode())) == 5){ // ... From Conversion ...     // STILL A BUG IN ALIROOT >>8 HAS TPO BE REMOVED AFTER FIX
+            if(gammaMC1->GetPdgCode() == 22){ // ... with Gamma Mother
+               gamma1MotherLabel=gammaMC1->GetMother();
+            }
+         }
+         if(gammaMC1->GetPdgCode() ==111){ // Conversion but Pi0 Mother
+            gamma1MotherLabel=-111;
+         }
+         if(gammaMC1->GetPdgCode() ==221){ // Conversion but Eta Mother
+            gamma1MotherLabel=-221;
+         }
+      }
+   }
+   if(gamma0MotherLabel>=0 && gamma0MotherLabel==gamma1MotherLabel){
+      if(static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma1MotherLabel))->GetPdgCode() == 111){
+         isTruePi0=kTRUE;
+      }
+      if(static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma1MotherLabel))->GetPdgCode() == 221){
+         isTrueEta=kTRUE;
+      }
+   }
+   if(isTruePi0 || isTrueEta){// True Pion or Eta
+      hESDTrueMotherInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
+      
+      if(!(static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma0MotherLabel))->IsPrimary())){ // Secondary Meson
+         Int_t secMotherLabel = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma1MotherLabel))->GetMother();
+         Float_t weightedSec= 1;
+         if(((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(secMotherLabel, 0x0, fInputEvent) && static_cast<AliAODMCParticle*>(AODMCTrackArray->At(secMotherLabel))->GetPdgCode()==310){
+            weightedSec= ((AliConversionCuts*)fCutArray->At(fiCut))->GetWeightForMeson(fV0Reader->GetPeriodName(),secMotherLabel, 0x0, fInputEvent)/2.; //invariant mass is additive thus the weight for the daughters has to be devide by two for the K0s at a certain pt
+            //cout << "MC input \t"<<i << "\t" <<  particle->Pt()<<"\t"<<weighted << endl;
+         }
+         hESDTrueSecondaryMotherInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weightedSec);
+      
+         if (secMotherLabel >-1){
+            if(static_cast<AliAODMCParticle*>(AODMCTrackArray->At(secMotherLabel))->GetPdgCode()==310){
+               hESDTrueSecondaryMotherFromK0sInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weightedSec);
+               if (fDoMesonQA)hESDTrueK0sWithPi0DaughterMCPt[fiCut]
+                                 ->Fill(static_cast<AliAODMCParticle*>(AODMCTrackArray->At(secMotherLabel))->Pt());
+            }
+            if(static_cast<AliAODMCParticle*>(AODMCTrackArray->At(secMotherLabel))->GetPdgCode()==221){
+               hESDTrueSecondaryMotherFromEtaInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weightedSec);
+               if (fDoMesonQA)hESDTrueEtaWithPi0DaughterMCPt[fiCut]
+                                 ->Fill(static_cast<AliAODMCParticle*>(AODMCTrackArray->At(secMotherLabel))->Pt());
+            }
+         }
+      }else{ // Only primary pi0 for efficiency calculation
+         Float_t weighted= 1;
+         if(((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(gamma1MotherLabel, 0x0, fInputEvent)){
+            if (static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma1MotherLabel))->Pt()>0.005){
+               weighted= ((AliConversionCuts*)fCutArray->At(fiCut))->GetWeightForMeson(fV0Reader->GetPeriodName(),gamma1MotherLabel, 0x0, fInputEvent);
+               //                      cout << "rec \t " <<gamma1MotherLabel << "\t" <<  weighted << endl;
+            }
+         }
+         hESDTruePrimaryMotherInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt(),weighted);
+   
+         if (fDoMesonQA){
+            Double_t sparesFill[3] = {Pi0Candidate->M(),Pi0Candidate->Pt(),Pi0Candidate->Rapidity()-((AliConversionCuts*)fCutArray->At(fiCut))->GetEtaShift()};
+            sESDTruePrimaryMotherInvMassPtY[fiCut]->Fill(sparesFill,1);
+            if(isTruePi0){ // Only primary pi0 for resolution
+               hESDTruePrimaryPi0MCPtResolPt[fiCut]->Fill(static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma1MotherLabel))->Pt(),
+                                                          (Pi0Candidate->Pt()-static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma1MotherLabel))->Pt())/static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma1MotherLabel))->Pt(),weighted);
+            }
+            if (isTrueEta){ // Only primary eta for resolution
+               hESDTruePrimaryEtaMCPtResolPt[fiCut]->Fill(static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma1MotherLabel))->Pt(),
+                                                          (Pi0Candidate->Pt()-static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma1MotherLabel))->Pt())/static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma1MotherLabel))->Pt(),weighted);
+            }
+         }
+      }
+   }
+   else if(!isTruePi0 && !isTrueEta && fDoMesonQA){ // Background
+      if(gamma0MotherLabel>-1 && gamma1MotherLabel>-1){ // Both Tracks are Photons and have a mother but not Pi0 or Eta
+         hESDTrueBckGGInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
+      } else { // No photon or without mother
+         hESDTrueBckContInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
+      }
+      if((gamma0MotherLabel==-111 || gamma1MotherLabel==-111 || gamma0MotherLabel==-221 || gamma1MotherLabel==-221) ){
+         // Dalitz
+         hESDTrueMotherDalitzInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
+      }
+   }
+}
 //________________________________________________________________________
 void AliAnalysisTaskGammaConvV1::CalculateBackground(){
 
@@ -1512,31 +1903,150 @@ void AliAnalysisTaskGammaConvV1::UpdateEventByEventData(){
 }
 
 //________________________________________________________________________
-void AliAnalysisTaskGammaConvV1::CountESDTracks(){
+void AliAnalysisTaskGammaConvV1::CountTracks(){
 
+   if(fInputEvent->IsA()==AliESDEvent::Class()){
    // Using standard function for setting Cuts
    Bool_t selectPrimaries=kTRUE;
    AliESDtrackCuts *EsdTrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010(selectPrimaries);
    EsdTrackCuts->SetMaxDCAToVertexZ(2);
    EsdTrackCuts->SetEtaRange(-0.8, 0.8);
    EsdTrackCuts->SetPtRange(0.15);
-
-   fNumberOfESDTracks = 0;
-
-   for(Int_t iTracks = 0; iTracks < fInputEvent->GetNumberOfTracks(); iTracks++){
-      AliESDtrack* curTrack = (AliESDtrack*) fInputEvent->GetTrack(iTracks);
-      if(!curTrack) continue;
-      // if(fMCEvent && ((AliConversionCuts*)fCutArray->At(fiCut))->GetSignalRejection() != 0){
-      //    if(!((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(abs(curTrack->GetLabel()), fMCStack)) continue;
-      // }
-      if(EsdTrackCuts->AcceptTrack(curTrack) ) fNumberOfESDTracks++;
+      fNumberOfESDTracks = 0;
+      for(Int_t iTracks = 0; iTracks < fInputEvent->GetNumberOfTracks(); iTracks++){
+         AliESDtrack* curTrack = (AliESDtrack*) fInputEvent->GetTrack(iTracks);
+         if(!curTrack) continue;
+         // if(fMCEvent && ((AliConversionCuts*)fCutArray->At(fiCut))->GetSignalRejection() != 0){
+         //    if(!((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(abs(curTrack->GetLabel()), fMCStack)) continue;
+         // }
+         if(EsdTrackCuts->AcceptTrack(curTrack) ) fNumberOfESDTracks++;
+      }
+      delete EsdTrackCuts;
+      EsdTrackCuts=0x0;
+   }
+   else if(fInputEvent->IsA()==AliAODEvent::Class()){
+      fNumberOfESDTracks = 0;
+      for(Int_t iTracks = 0; iTracks<fInputEvent->GetNumberOfTracks(); iTracks++){
+         AliAODTrack* curTrack = (AliAODTrack*) fInputEvent->GetTrack(iTracks);
+         if(!curTrack->IsPrimaryCandidate()) continue;
+         if(abs(curTrack->Eta())>0.8) continue;
+         if(curTrack->Pt()<0.15) continue;
+         if(abs(curTrack->ZAtDCA())>2) continue;
+         fNumberOfESDTracks++;
+      }
    }
-   delete EsdTrackCuts;
-   EsdTrackCuts=0x0;
 
    return;
 }
 //________________________________________________________________________
+void AliAnalysisTaskGammaConvV1::FillPhotonCombinatorialBackgroundHist(AliAODConversionPhoton *TruePhotonCandidate, Int_t pdgCode[])
+{
+   // Combinatorial Bck = 0 ee, 1 ep,i 2 ek, 3 ep, 4 emu, 5 pipi, 6 pik, 7 pip, 8 pimu, 9 kk, 10 kp, 11 kmu, 12 pp, 13 pmu, 14 mumu, 15 Rest
+   if(pdgCode[0]==11   && pdgCode[1]==11){if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),0);}
+   else if( (pdgCode[0]==11   && pdgCode[1]==211) || (pdgCode[0]==211  && pdgCode[1]==11) )
+      {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),1);}
+   else if( (pdgCode[0]==11   && pdgCode[1]==321) || (pdgCode[0]==321  && pdgCode[1]==11) )
+      {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),2);}
+   else if( (pdgCode[0]==11   && pdgCode[1]==2212) || (pdgCode[0]==2212 && pdgCode[1]==11) )
+      {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),3);}
+   else if( (pdgCode[0]==11   && pdgCode[1]==13) || (pdgCode[0]==13   && pdgCode[1]==11) )
+      {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),4);}
+   else if(  pdgCode[0]==211  && pdgCode[1]==211 ){if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),5);}
+   else if( (pdgCode[0]==211  && pdgCode[1]==321) || (pdgCode[0]==321  && pdgCode[1]==211) )
+      {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),6);}
+   else if( (pdgCode[0]==211  && pdgCode[1]==2212) || (pdgCode[0]==2212 && pdgCode[1]==211) )
+      {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),7);}
+   else if( (pdgCode[0]==211  && pdgCode[1]==13) || (pdgCode[0]==13   && pdgCode[1]==211) )
+      {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),8);}
+   else if(  pdgCode[0]==321  && pdgCode[1]==321 ){if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),9);}
+   else if( (pdgCode[0]==321  && pdgCode[1]==2212) || (pdgCode[0]==2212 && pdgCode[1]==321) )
+      {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),10);}
+   else if( (pdgCode[0]==321  && pdgCode[1]==13) || (pdgCode[0]==13   && pdgCode[1]==321) )
+      {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),11);}
+   else if(  pdgCode[0]==2212   && pdgCode[1]==2212  ){if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),12);}
+   else if( (pdgCode[0]==2212  && pdgCode[1]==13) || (pdgCode[0]==13   && pdgCode[1]==2212) )
+      {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),13);}
+   else if(  pdgCode[0]==13   && pdgCode[1]==13  ){if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),14);}
+   else {if(fIsFromMBHeader)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),15);}
+}
+//________________________________________________________________________
+void AliAnalysisTaskGammaConvV1::RelabelAODPhotonCandidates(Bool_t mode){
+
+   // Relabeling For AOD Event
+   // ESDiD -> AODiD
+   // MCLabel -> AODMCLabel
+   
+   if(mode){
+      fMCStackPos = new Int_t[fReaderGammas->GetEntries()];
+      fMCStackNeg = new Int_t[fReaderGammas->GetEntries()];
+   }
+   
+   for(Int_t iGamma = 0;iGamma<fReaderGammas->GetEntries();iGamma++){
+      AliAODConversionPhoton* PhotonCandidate = (AliAODConversionPhoton*) fReaderGammas->At(iGamma);
+      if(!PhotonCandidate) continue;
+      if(!mode){// Back to ESD Labels
+         PhotonCandidate->SetMCLabelPositive(fMCStackPos[iGamma]);
+         PhotonCandidate->SetMCLabelNegative(fMCStackNeg[iGamma]);
+         //PhotonCandidate->IsAODMCLabel(kFALSE);
+         continue;
+      }
+      fMCStackPos[iGamma] =  PhotonCandidate->GetMCLabelPositive();
+      fMCStackNeg[iGamma] =  PhotonCandidate->GetMCLabelNegative();
+
+      Bool_t AODLabelPos = kFALSE;
+      Bool_t AODLabelNeg = kFALSE;
+
+      for(Int_t i = 0; i<fInputEvent->GetNumberOfTracks();i++){
+         AliAODTrack *tempDaughter = static_cast<AliAODTrack*>(fInputEvent->GetTrack(i));
+         if(!AODLabelPos){
+            if( tempDaughter->GetID() == PhotonCandidate->GetTrackLabelPositive() ){
+               PhotonCandidate->SetMCLabelPositive(abs(tempDaughter->GetLabel()));
+               AODLabelPos = kTRUE;
+            }
+         }
+         if(!AODLabelNeg){
+            if( tempDaughter->GetID() == PhotonCandidate->GetTrackLabelNegative()){
+               PhotonCandidate->SetMCLabelNegative(abs(tempDaughter->GetLabel()));
+               AODLabelNeg = kTRUE;
+            }
+         }
+         if(AODLabelNeg && AODLabelPos){
+            break;
+         }
+      } // Both ESD Tracks have AOD Tracks with Positive IDs
+      if(!AODLabelPos || !AODLabelNeg){
+         for(Int_t i = 0; i<fInputEvent->GetNumberOfTracks();i++){
+            AliAODTrack *tempDaughter = static_cast<AliAODTrack*>(fInputEvent->GetTrack(i));
+            if(tempDaughter->GetID()<0){
+               if(!AODLabelPos){
+                  if( (abs(tempDaughter->GetID())-1) == PhotonCandidate->GetTrackLabelPositive()){
+                     PhotonCandidate->SetMCLabelPositive(abs(tempDaughter->GetLabel()));
+                     AODLabelPos = kTRUE;
+                  }
+               }
+               if(!AODLabelNeg){
+                  if( (abs(tempDaughter->GetID())-1) == PhotonCandidate->GetTrackLabelNegative()){
+                     PhotonCandidate->SetMCLabelNegative(abs(tempDaughter->GetLabel()));
+                     AODLabelNeg = kTRUE;
+                  }
+               }
+            }
+            if(AODLabelNeg && AODLabelPos){
+               break;
+            }
+         }
+         if(!AODLabelPos || !AODLabelNeg){
+            cout<<"WARNING!!! AOD TRACKS NOT FOUND FOR"<<endl;
+         }
+      }
+   }
+   
+   if(!mode){
+      delete[] fMCStackPos;
+      delete[] fMCStackNeg;
+   }
+}
+//________________________________________________________________________
 void AliAnalysisTaskGammaConvV1::Terminate(const Option_t *)
 {
 
@@ -1562,6 +2072,14 @@ void AliAnalysisTaskGammaConvV1::Terminate(const Option_t *)
          fHeaderNameList[iCut]->SetOwner(kTRUE);
          fCutFolder[iCut]->Add(fHeaderNameList[iCut]);
       }
+      if (((AliConversionCuts*)fCutArray->At(iCut))->IsSpecialTrigger() == 4 ){
+         fTriggerNameList[iCut] = new TList();
+         TString TriggerNames = "Trigger: ";
+         TriggerNames = TriggerNames+ ( (AliConversionCuts*)fCutArray->At(iCut))->GetSpecialTriggerName();
+         fTriggerNameList[iCut]->SetName(TriggerNames);
+         fTriggerNameList[iCut]->SetOwner(kTRUE);
+         fCutFolder[iCut]->Add(fTriggerNameList[iCut]);
+      }   
    }
 
    //fOutputContainer->Print(); // Will crash on GRID
index abfcc4e..4ab96f6 100644 (file)
@@ -32,6 +32,8 @@ class AliAnalysisTaskGammaConvV1 : public AliAnalysisTaskSE {
          fIsHeavyIon = 0;    
       }
    }
+
+   void SetIsMC(Bool_t isMC){fIsMC=isMC;}
    void SetDoMesonAnalysis(Bool_t flag){fDoMesonAnalysis = flag;}
    void SetDoMesonQA(Bool_t flag){fDoMesonQA = flag;}
    void SetDoPhotonQA(Bool_t flag){fDoPhotonQA = flag;}
@@ -40,8 +42,12 @@ class AliAnalysisTaskGammaConvV1 : public AliAnalysisTaskSE {
    void CalculateBackground();
    void CalculateBackgroundRP();
    void ProcessMCParticles();
+   void ProcessAODMCParticles();
+   void RelabelAODPhotonCandidates(Bool_t mode);
    void ProcessTruePhotonCandidates( AliAODConversionPhoton* TruePhotonCandidate);
+   void ProcessTruePhotonCandidatesAOD( AliAODConversionPhoton* TruePhotonCandidate);
    void ProcessTrueMesonCandidates( AliAODConversionMother *Pi0Candidate, AliAODConversionPhoton *TrueGammaCandidate0, AliAODConversionPhoton *TrueGammaCandidate1);
+   void ProcessTrueMesonCandidatesAOD(AliAODConversionMother *Pi0Candidate, AliAODConversionPhoton *TrueGammaCandidate0, AliAODConversionPhoton *TrueGammaCandidate1);
    void RotateParticle(AliAODConversionPhoton *gamma);
    void SetConversionCutList(Int_t nCuts, TList *CutArray){
       fnCuts = nCuts;
@@ -54,7 +60,8 @@ class AliAnalysisTaskGammaConvV1 : public AliAnalysisTaskSE {
 
    // BG HandlerSettings
    void SetMoveParticleAccordingToVertex(Bool_t flag){fMoveParticleAccordingToVertex = flag;}
-   void CountESDTracks();
+   void CountTracks();
+   void FillPhotonCombinatorialBackgroundHist(AliAODConversionPhoton *TruePhotonCandidate, Int_t pdgCode[]);
    void MoveParticleAccordingToVertex(AliAODConversionPhoton* particle,const AliGammaConversionAODBGHandler::GammaConversionVertex *vertex);
    void UpdateEventByEventData();
 
@@ -74,6 +81,7 @@ class AliAnalysisTaskGammaConvV1 : public AliAnalysisTaskSE {
    TList **fTrueMotherRapList;
    TList **fMCList;
    TList **fHeaderNameList;
+   TList **fTriggerNameList;
    TList *fOutputContainer;
    TClonesArray *fReaderGammas;
    TList *fGammaCandidates;
@@ -104,11 +112,15 @@ class AliAnalysisTaskGammaConvV1 : public AliAnalysisTaskSE {
    TH1F **hMCConvGammaRSR;
    TH1F **hMCConvGammaRSEta;
    TH1F **hMCPi0Pt;
+   TH1F **hMCPi0WOWeightPt;
    TH1F **hMCEtaPt;
    TH1F **hMCPi0InAccPt;
    TH1F **hMCEtaInAccPt;
    TH2F **hMCPi0PtY;
    TH2F **hMCEtaPtY;
+   TH1F **hMCK0sPt;
+   TH1F **hMCK0sWOWeightPt;
+   TH2F **hMCK0sPtY;
    TH2F **hESDTrueMotherInvMassPt;
    TH2F **hESDTruePrimaryMotherInvMassPt;
    TH2F **hESDTruePrimaryPi0MCPtResolPt;
@@ -136,6 +148,7 @@ class AliAnalysisTaskGammaConvV1 : public AliAnalysisTaskSE {
    TH1I **hNGoodESDTracks;
    TH1I **hNGammaCandidates;
    TH1I **hNV0Tracks;
+   TH1F **hEtaShift;
    
    TRandom3 fRandom;
    Int_t fnGammaCandidates;
@@ -143,6 +156,8 @@ class AliAnalysisTaskGammaConvV1 : public AliAnalysisTaskSE {
    Double_t *fUnsmearedPy; //[fnGammaCandidates]
    Double_t *fUnsmearedPz; //[fnGammaCandidates]
    Double_t *fUnsmearedE;  //[fnGammaCandidates]
+   Int_t *fMCStackPos;     //[fnGammaCandidates]
+   Int_t *fMCStackNeg;     //[fnGammaCandidates]
    Int_t fnCuts;
    Int_t fiCut;
    Int_t fNumberOfESDTracks;
@@ -152,6 +167,7 @@ class AliAnalysisTaskGammaConvV1 : public AliAnalysisTaskSE {
    Bool_t fDoMesonQA;
    Bool_t fDoPhotonQA;
    Bool_t fIsFromMBHeader;
+   Bool_t fIsMC;
 
 private:
 
@@ -159,7 +175,7 @@ private:
    AliAnalysisTaskGammaConvV1 &operator=(const AliAnalysisTaskGammaConvV1&); // Prevent assignment
 
 
-   ClassDef(AliAnalysisTaskGammaConvV1, 4);
+   ClassDef(AliAnalysisTaskGammaConvV1, 7);
 };
 
 #endif
index 22ca7b4..cc80770 100644 (file)
@@ -99,9 +99,8 @@ void AliAnalysisTaskMaterial::UserExec(Option_t *){
    fESDEvent = (AliESDEvent*) InputEvent();
    if (fESDEvent==NULL) return;
    if(fIsHeavyIon && !fConversionCuts->IsCentralitySelected(fESDEvent)) return;
-       Int_t nESDtracksEta09 = CountESDTracks09(); // Estimate Event Multiplicity
-       Int_t nESDtracksEta0914 = CountESDTracks0914(); // Estimate Event Multiplicity
-       //      Int_t nESDtracksEta14 = CountESDTracks14(); // Estimate Event Multiplicity
+       Int_t nESDtracksEta09 = CountTracks09(); // Estimate Event Multiplicity
+       Int_t nESDtracksEta0914 = CountTracks0914(); // Estimate Event Multiplicity
        Int_t nESDtracksEta14; // Estimate Event Multiplicity
   nESDtracksEta14= nESDtracksEta09 + nESDtracksEta0914;
        Int_t nContrVtx;
@@ -356,78 +355,85 @@ void AliAnalysisTaskMaterial::ProcessPhotons(){
 }
 
 //________________________________________________________________________
-Int_t AliAnalysisTaskMaterial::CountESDTracks09(){
-   
-   // Using standard function for setting Cuts
-   Bool_t selectPrimaries=kTRUE;
-   AliESDtrackCuts *EsdTrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010(selectPrimaries);
-   EsdTrackCuts->SetMaxDCAToVertexZ(2);
-   EsdTrackCuts->SetEtaRange(-0.9, 0.9);
-   EsdTrackCuts->SetPtRange(0.15);
-
+Int_t AliAnalysisTaskMaterial::CountTracks09(){
    Int_t fNumberOfESDTracks = 0;
-   for(Int_t iTracks = 0; iTracks < fESDEvent->GetNumberOfTracks(); iTracks++){
-      AliESDtrack* curTrack = fESDEvent->GetTrack(iTracks);
-      if(!curTrack) continue;
-      if(EsdTrackCuts->AcceptTrack(curTrack) ) fNumberOfESDTracks++;
+   if(fInputEvent->IsA()==AliESDEvent::Class()){
+   // Using standard function for setting Cuts
+      Bool_t selectPrimaries=kTRUE;
+      AliESDtrackCuts *EsdTrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010(selectPrimaries);
+      EsdTrackCuts->SetMaxDCAToVertexZ(2);
+      EsdTrackCuts->SetEtaRange(-0.9, 0.9);
+      EsdTrackCuts->SetPtRange(0.15);
+      
+      for(Int_t iTracks = 0; iTracks < fInputEvent->GetNumberOfTracks(); iTracks++){
+         AliESDtrack* curTrack = (AliESDtrack*) fInputEvent->GetTrack(iTracks);
+         if(!curTrack) continue;
+         // if(fMCEvent && ((AliConversionCuts*)fCutArray->At(fiCut))->GetSignalRejection() != 0){
+         //    if(!((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(abs(curTrack->GetLabel()), fMCStack)) continue;
+         // }
+         if(EsdTrackCuts->AcceptTrack(curTrack) ) fNumberOfESDTracks++;
+      }
+      delete EsdTrackCuts;
+      EsdTrackCuts=0x0;
+   }
+   else if(fInputEvent->IsA()==AliAODEvent::Class()){
+      for(Int_t iTracks = 0; iTracks<fInputEvent->GetNumberOfTracks(); iTracks++){
+         AliAODTrack* curTrack = (AliAODTrack*) fInputEvent->GetTrack(iTracks);
+         if(!curTrack->IsPrimaryCandidate()) continue;
+         if(abs(curTrack->Eta())>0.9) continue;
+         if(curTrack->Pt()<0.15) continue;
+         if(abs(curTrack->ZAtDCA())>2) continue;
+         fNumberOfESDTracks++;
+      }
    }
-   delete EsdTrackCuts;
-   EsdTrackCuts=0x0;
 
    return fNumberOfESDTracks;
 }
 
-Int_t AliAnalysisTaskMaterial::CountESDTracks0914(){
+Int_t AliAnalysisTaskMaterial::CountTracks0914(){
 
    // Using standard function for setting Cuts ; We use TPCOnlyTracks for outer eta region
    //Bool_t selectPrimaries=kTRUE;
         //   EsdTrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010(selectPrimaries);
-   AliESDtrackCuts *EsdTrackCuts = AliESDtrackCuts::GetStandardTPCOnlyTrackCuts();
-        EsdTrackCuts->SetMaxDCAToVertexXY(5);
-        //      EsdTrackCuts->SetMaxDCAToVertexXYPtDep("sqrt(0.15^2+(0.4/pt)^2");
-   EsdTrackCuts->SetEtaRange(0.9, 1.4);
-   EsdTrackCuts->SetPtRange(0.15);
-
-   Int_t fNumberOfESDTracks = 0;
-   for(Int_t iTracks = 0; iTracks < fESDEvent->GetNumberOfTracks(); iTracks++){
-      AliESDtrack* curTrack = fESDEvent->GetTrack(iTracks);
-      if(!curTrack) continue;
-      if(EsdTrackCuts->AcceptTrack(curTrack) ) fNumberOfESDTracks++;
+    Int_t fNumberOfESDTracks = 0;
+    if(fInputEvent->IsA()==AliESDEvent::Class()){
+      // Using standard function for setting Cuts
+      AliESDtrackCuts *EsdTrackCuts = AliESDtrackCuts::GetStandardTPCOnlyTrackCuts();
+      EsdTrackCuts->SetMaxDCAToVertexZ(5);
+      EsdTrackCuts->SetEtaRange(0.9, 1.4);
+      EsdTrackCuts->SetPtRange(0.15);
+      
+      for(Int_t iTracks = 0; iTracks < fInputEvent->GetNumberOfTracks(); iTracks++){
+         AliESDtrack* curTrack = (AliESDtrack*) fInputEvent->GetTrack(iTracks);
+         if(!curTrack) continue;
+         // if(fMCEvent && ((AliConversionCuts*)fCutArray->At(fiCut))->GetSignalRejection() != 0){
+         //    if(!((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(abs(curTrack->GetLabel()), fMCStack)) continue;
+         // }
+         if(EsdTrackCuts->AcceptTrack(curTrack) ) fNumberOfESDTracks++;
+      }
+      EsdTrackCuts->SetEtaRange(-1.4, -0.9);
+      for(Int_t iTracks = 0; iTracks < fESDEvent->GetNumberOfTracks(); iTracks++){
+         AliESDtrack* curTrack = fESDEvent->GetTrack(iTracks);
+         if(!curTrack) continue;
+         if(EsdTrackCuts->AcceptTrack(curTrack) ) fNumberOfESDTracks++;
+      }
+      delete EsdTrackCuts;
+      EsdTrackCuts=0x0;
    }
-   EsdTrackCuts->SetEtaRange(-1.4, -0.9);
-   for(Int_t iTracks = 0; iTracks < fESDEvent->GetNumberOfTracks(); iTracks++){
-      AliESDtrack* curTrack = fESDEvent->GetTrack(iTracks);
-      if(!curTrack) continue;
-      if(EsdTrackCuts->AcceptTrack(curTrack) ) fNumberOfESDTracks++;
+   else if(fInputEvent->IsA()==AliAODEvent::Class()){
+      for(Int_t iTracks = 0; iTracks<fInputEvent->GetNumberOfTracks(); iTracks++){
+         AliAODTrack* curTrack = (AliAODTrack*) fInputEvent->GetTrack(iTracks);
+//          if(!curTrack->IsPrimaryCandidate()) continue;
+         if(abs(curTrack->Eta())<0.9 || abs(curTrack->Eta())>1.4 ) continue;
+         if(curTrack->Pt()<0.15) continue;
+         if(abs(curTrack->ZAtDCA())>5) continue;
+         fNumberOfESDTracks++;
+      }
    }
-   delete EsdTrackCuts;
-   EsdTrackCuts=0x0;
-
-   return fNumberOfESDTracks;
-}
-
-Int_t AliAnalysisTaskMaterial::CountESDTracks14(){
-
-   // Using standard function for setting Cuts
-   Bool_t selectPrimaries=kTRUE;
-   AliESDtrackCuts *EsdTrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010(selectPrimaries);
-   EsdTrackCuts->SetMaxDCAToVertexZ(2);
-   EsdTrackCuts->SetEtaRange(-1.4, 1.4);
-   EsdTrackCuts->SetPtRange(0.15);
-
-   Int_t fNumberOfESDTracks = 0;
-   for(Int_t iTracks = 0; iTracks < fESDEvent->GetNumberOfTracks(); iTracks++){
-      AliESDtrack* curTrack = fESDEvent->GetTrack(iTracks);
-      if(!curTrack) continue;
-      if(EsdTrackCuts->AcceptTrack(curTrack) ) fNumberOfESDTracks++;
-   }
-   delete EsdTrackCuts;
-   EsdTrackCuts=0x0;
-
+   
    return fNumberOfESDTracks;
 }
 
-
 //________________________________________________________________________
 void AliAnalysisTaskMaterial::Terminate(Option_t *)
 {
index 2b307ec..34ea86d 100644 (file)
@@ -40,9 +40,8 @@ class AliAnalysisTaskMaterial : public AliAnalysisTaskSE{
    void ProcessPhotons();
    void ProcessMCPhotons();
    void FillMCTree(Int_t stackPos);
-   Int_t CountESDTracks14();
-   Int_t CountESDTracks0914();
-   Int_t CountESDTracks09();
+   Int_t CountTracks0914();
+   Int_t CountTracks09();
 
    AliV0ReaderV1 *fV0Reader;
    TClonesArray *fConversionGammas; //Reconstructed Photons;
index 2d89158..0d4931f 100644 (file)
@@ -39,6 +39,7 @@
 #include "AliESDEvent.h"
 #include "AliCentrality.h"
 #include "TList.h"
+#include "TFile.h"
 #include "AliLog.h"
 #include "AliGenCocktailEventHeader.h"
 #include "AliGenDPMjetEventHeader.h"
@@ -46,6 +47,8 @@
 #include "AliGenHijingEventHeader.h"
 #include "AliTriggerAnalysis.h"
 #include "AliV0ReaderV1.h"
+#include "AliAODMCParticle.h"
+#include "AliAODMCHeader.h"
 
 class iostream;
 
@@ -176,6 +179,13 @@ AliConversionCuts::AliConversionCuts(const char *name,const char *title) :
    fUtils(NULL),
    fEtaShift(0.0),
    fDoEtaShift(kFALSE),
+   fDoReweightHistoMCPi0(kFALSE),
+   fDoReweightHistoMCEta(kFALSE),
+   fDoReweightHistoMCK0s(kFALSE),
+   fPathTrFReweighting(""),
+   fNameHistoReweightingPi0(""),
+   fNameHistoReweightingEta(""),
+   fNameHistoReweightingK0s(""),
    hdEdxCuts(NULL),
    hTPCdEdxbefore(NULL),
    hTPCdEdxafter(NULL),
@@ -196,8 +206,14 @@ AliConversionCuts::AliConversionCuts(const char *name,const char *title) :
    hCentrality(NULL),
    hVertexZ(NULL),
    hTriggerClass(NULL),
-   hTriggerClassSelected(NULL)
-
+   hTriggerClassSelected(NULL),
+   hReweightMCHistPi0(NULL),
+   hReweightMCHistEta(NULL),
+   hReweightMCHistK0s(NULL),
+   fPreSelCut(kFALSE),
+   fTriggerSelectedManually(kFALSE),
+   fSpecialTriggerName("")
+   
 {
    InitPIDResponse();
    for(Int_t jj=0;jj<kNCuts;jj++){fCuts[jj]=0;}
@@ -304,6 +320,13 @@ AliConversionCuts::AliConversionCuts(const AliConversionCuts &ref) :
    fUtils(NULL),
    fEtaShift(ref.fEtaShift),
    fDoEtaShift(ref.fDoEtaShift),
+   fDoReweightHistoMCPi0(ref.fDoReweightHistoMCPi0),
+   fDoReweightHistoMCEta(ref.fDoReweightHistoMCEta),
+   fDoReweightHistoMCK0s(ref.fDoReweightHistoMCK0s),
+   fPathTrFReweighting(ref.fPathTrFReweighting),
+   fNameHistoReweightingPi0(ref.fNameHistoReweightingPi0),
+   fNameHistoReweightingEta(ref.fNameHistoReweightingEta),
+   fNameHistoReweightingK0s(ref.fNameHistoReweightingK0s),
    hdEdxCuts(NULL),
    hTPCdEdxbefore(NULL),
    hTPCdEdxafter(NULL),
@@ -324,7 +347,13 @@ AliConversionCuts::AliConversionCuts(const AliConversionCuts &ref) :
    hCentrality(NULL),
    hVertexZ(NULL),
    hTriggerClass(NULL),
-   hTriggerClassSelected(NULL)
+   hTriggerClassSelected(NULL),
+   hReweightMCHistPi0(NULL),
+   hReweightMCHistEta(NULL),
+   hReweightMCHistK0s(NULL),
+   fPreSelCut(ref.fPreSelCut),
+   fTriggerSelectedManually(ref.fTriggerSelectedManually),
+   fSpecialTriggerName(ref.fSpecialTriggerName)
 {
    // Copy Constructor
    for(Int_t jj=0;jj<kNCuts;jj++){fCuts[jj]=ref.fCuts[jj];}
@@ -387,6 +416,10 @@ void AliConversionCuts::InitCutHistograms(TString name, Bool_t preCut){
       else fHistograms->SetName(Form("%s_%s",name.Data(),GetCutNumber().Data()));
    }
 
+   if (hReweightMCHistPi0) fHistograms->Add(hReweightMCHistPi0);
+   if (hReweightMCHistEta) fHistograms->Add(hReweightMCHistEta);
+   if (hReweightMCHistK0s) fHistograms->Add(hReweightMCHistK0s);
+   
    // IsPhotonSelected
    hCutIndex=new TH1F(Form("IsPhotonSelected %s",GetCutNumber().Data()),"IsPhotonSelected",10,-0.5,9.5);
    hCutIndex->GetXaxis()->SetBinLabel(kPhotonIn+1,"in");
@@ -565,7 +598,8 @@ void AliConversionCuts::InitCutHistograms(TString name, Bool_t preCut){
       hTriggerClass->GetXaxis()->SetBinLabel(34,"NOT kFastOnly");
       hTriggerClass->GetXaxis()->SetBinLabel(35,"failed Physics Selection");
       fHistograms->Add(hTriggerClass);
-
+   }
+   if(!preCut){
       hTriggerClassSelected= new TH1F(Form("OfflineTriggerSelected %s",GetCutNumber().Data()),"OfflineTriggerSelected",34,-0.5,33.5);
       hTriggerClassSelected->GetXaxis()->SetBinLabel( 1,"kMB");
       hTriggerClassSelected->GetXaxis()->SetBinLabel( 2,"kINT7");
@@ -630,7 +664,7 @@ Bool_t AliConversionCuts::EventIsSelected(AliVEvent *fInputEvent, AliVEvent *fMC
    cutindex++;
 
    // Check for MC event
-   if(fMCEvent){
+   if(fMCEvent && fInputEvent->IsA()==AliESDEvent::Class()){
       // Check if MC event is correctly loaded
       AliMCEventHandler* mcHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
       if (!mcHandler){
@@ -800,8 +834,97 @@ Bool_t AliConversionCuts::PhotonIsSelectedMC(TParticle *particle,AliStack *fMCSt
    }
    return kFALSE;
 }
+///________________________________________________________________________
+Bool_t AliConversionCuts::PhotonIsSelectedAODMC(AliAODMCParticle *particle,TClonesArray *aodmcArray,Bool_t checkForConvertedGamma){
+   // MonteCarlo Photon Selection
+
+   if(!aodmcArray)return kFALSE;
+   
+   if (particle->GetPdgCode() == 22){
+      if( particle->Eta() > (fEtaCut + fEtaShift) || particle->Eta() < (-fEtaCut + fEtaShift) )
+         return kFALSE;
+      if(fEtaCutMin>-0.1){
+         if( particle->Eta() < (fEtaCutMin + fEtaShift) && particle->Eta() > (-fEtaCutMin + fEtaShift) )
+            return kFALSE;
+      }
+
+      if(particle->GetMother() > -1){
+         if((static_cast<AliAODMCParticle*>(aodmcArray->At(particle->GetMother())))->GetPdgCode() == 22){
+            return kFALSE; // no photon as mothers!
+         }
+         if(!(static_cast<AliAODMCParticle*>(aodmcArray->At(particle->GetMother()))->IsPrimary())){
+            return kFALSE; // the gamma has a mother, and it is not a primary particle
+         }
+      }
+      
+      if(!checkForConvertedGamma) return kTRUE; // return in case of accepted gamma
+
+      // looking for conversion gammas (electron + positron from pairbuilding (= 5) )
+      AliAODMCParticle* ePos = NULL;
+      AliAODMCParticle* eNeg = NULL;
+
+      if(particle->GetNDaughters() >= 2){
+         for(Int_t daughterIndex=particle->GetDaughter(0);daughterIndex<=particle->GetDaughter(1);daughterIndex++){
+            AliAODMCParticle *tmpDaughter = static_cast<AliAODMCParticle*>(aodmcArray->At(daughterIndex));
+            if(!tmpDaughter) continue;
+            if(((tmpDaughter->GetMCProcessCode())) == 5){    // STILL A BUG IN ALIROOT >>8 HAS TPO BE REMOVED AFTER FIX
+               if(tmpDaughter->GetPdgCode() == 11){
+                  eNeg = tmpDaughter;
+               } else if(tmpDaughter->GetPdgCode() == -11){
+                  ePos = tmpDaughter;
+               }
+            }
+         }
+      }
+      
+      if(ePos == NULL || eNeg == NULL){ // means we do not have two daughters from pair production
+         return kFALSE;
+      }
+
+      if(ePos->Pt()<fSinglePtCut || eNeg->Pt()<fSinglePtCut){
+         return kFALSE; // no reconstruction below the Pt cut
+      }
+
+      if( ePos->Eta() > (fEtaCut + fEtaShift) || ePos->Eta() < (-fEtaCut + fEtaShift) ||
+          eNeg->Eta() > (fEtaCut + fEtaShift) || eNeg->Eta() < (-fEtaCut + fEtaShift) )
+         return kFALSE;
+
+      if(fEtaCutMin > -0.1){
+         if( (ePos->Eta() < (fEtaCutMin + fEtaShift) && ePos->Eta() > (-fEtaCutMin + fEtaShift)) ||
+             (eNeg->Eta() < (fEtaCutMin + fEtaShift) && eNeg->Eta() > (-fEtaCutMin + fEtaShift)) )
+            return kFALSE;
+      }
+
+      Double_t rPos = sqrt( (ePos->Xv()*ePos->Xv()) + (ePos->Yv()*ePos->Yv()) );
+      Double_t rNeg = sqrt( (eNeg->Xv()*eNeg->Xv()) + (eNeg->Yv()*eNeg->Yv()) );
+     
+      if(rPos>fMaxR){
+         return kFALSE; // cuts on distance from collision point
+      }
+      if(abs(ePos->Zv()) > fMaxZ){
+         return kFALSE;         // outside material
+      }
+      if(abs(eNeg->Zv()) > fMaxZ){
+         return kFALSE;         // outside material
+      }
 
+      if( rPos <= ((abs(ePos->Zv()) * fLineCutZRSlope) - fLineCutZValue)){
+         return kFALSE;  // line cut to exclude regions where we do not reconstruct
+      } else if ( fEtaCutMin != -0.1 &&   rPos >= ((abs(ePos->Zv()) * fLineCutZRSlopeMin) - fLineCutZValueMin)){
+         return kFALSE;
+      }
+
+      if( rNeg <= ((abs(eNeg->Zv()) * fLineCutZRSlope) - fLineCutZValue)){
+         return kFALSE; // line cut to exclude regions where we do not reconstruct
+      } else if ( fEtaCutMin != -0.1 &&   rNeg >= ((abs(eNeg->Zv()) * fLineCutZRSlopeMin) - fLineCutZValueMin)){
+         return kFALSE;
+      }
 
+      return kTRUE;
+      //if(AcceptanceCut(particle,ePos,eNeg))return kTRUE;
+   }
+   return kFALSE;
+}
 ///________________________________________________________________________
 Bool_t AliConversionCuts::PhotonCuts(AliConversionPhotonBase *photon,AliVEvent *event)
 {   // Specific Photon Cuts
@@ -1332,15 +1455,25 @@ AliVTrack *AliConversionCuts::GetTrack(AliVEvent * event, Int_t label){
       return track;
 
    } else {
+      AliVTrack * track = 0x0;
       for(Int_t ii=0; ii<event->GetNumberOfTracks(); ii++) {
-         AliVTrack * track = dynamic_cast<AliVTrack*>(event->GetTrack(ii));
-
-         if(track) {
+         track = dynamic_cast<AliVTrack*>(event->GetTrack(ii));
+         if(track){
             if(track->GetID() == label) {
                return track;
             }
          }
       }
+      for(Int_t ii=0; ii<event->GetNumberOfTracks(); ii++) {
+         track = dynamic_cast<AliVTrack*>(event->GetTrack(ii));
+         if(track){
+            if(track->GetID()<0){
+               if( (abs(track->GetID())-1)  == label) {
+                  return track;
+               }
+            }
+         }
+      }
    }
 
    //AliDebug(5,(Form("track not found %d %d",label,event->GetNumberOfTracks()));
@@ -1484,10 +1617,40 @@ Bool_t AliConversionCuts::UpdateCutString() {
    return kTRUE;
 }
 
+void AliConversionCuts::LoadReweightingHistosMCFromFile() {
+
+  AliInfo("Entering loading of histograms for weighting");
+  TFile *f = TFile::Open(fPathTrFReweighting.Data());
+  if(!f){
+     AliError(Form("file for weighting %s not found",fPathTrFReweighting.Data()));
+     return;
+  } 
+  if (fNameHistoReweightingPi0.CompareTo("") != 0 && fDoReweightHistoMCPi0 ){
+     hReweightMCHistPi0 = (TH1D*)f->Get(fNameHistoReweightingPi0.Data());
+     if (hReweightMCHistPi0) AliInfo(Form("%s has been loaded from %s", fNameHistoReweightingPi0.Data(),fPathTrFReweighting.Data() ));
+       else AliWarning(Form("%s not found in %s",fPathTrFReweighting.Data(), fNameHistoReweightingPi0.Data() ));
+  }
+  if (fNameHistoReweightingEta.CompareTo("") != 0 && fDoReweightHistoMCEta){
+     hReweightMCHistEta = (TH1D*)f->Get(fNameHistoReweightingEta.Data());
+     if (hReweightMCHistEta) AliInfo(Form("%s has been loaded from %s", fNameHistoReweightingEta.Data(),fPathTrFReweighting.Data() ));
+       else AliWarning(Form("%s not found in %s",fPathTrFReweighting.Data(), fNameHistoReweightingEta.Data() ));
+
+  }
+  if (fNameHistoReweightingK0s.CompareTo("") != 0 && fDoReweightHistoMCK0s){
+     hReweightMCHistK0s = (TH1D*)f->Get(fNameHistoReweightingK0s.Data());
+     if (hReweightMCHistK0s) AliInfo(Form("%s has been loaded from %s", fNameHistoReweightingK0s.Data(),fPathTrFReweighting.Data() ));
+       else AliWarning(Form("%s not found in %s",fPathTrFReweighting.Data(), fNameHistoReweightingK0s.Data() ));
+
+  }
+
+}
+
+
 ///________________________________________________________________________
 Bool_t AliConversionCuts::InitializeCutsFromCutString(const TString analysisCutSelection ) {
    // Initialize Cuts from a given Cut string
-
+   if(fDoReweightHistoMCPi0 || fDoReweightHistoMCEta || fDoReweightHistoMCK0s)   LoadReweightingHistosMCFromFile();
+   
    AliInfo(Form("Set Photoncut Number: %s",analysisCutSelection.Data()));
    if(analysisCutSelection.Length()!=kNCuts) {
       AliError(Form("Cut selection has the wrong length! size is %d, number of cuts is %d", analysisCutSelection.Length(), kNCuts));
@@ -1511,11 +1674,6 @@ Bool_t AliConversionCuts::InitializeCutsFromCutString(const TString analysisCutS
 
    //PrintCuts();
 
-   // Set StandardTriggers
-
-   if(fIsHeavyIon)SelectCollisionCandidates(AliVEvent::kMB | AliVEvent::kCentral | AliVEvent::kSemiCentral);
-   else SelectCollisionCandidates(AliVEvent::kMB);
-
    return kTRUE;
 }
 ///________________________________________________________________________
@@ -1814,7 +1972,31 @@ Int_t AliConversionCuts::SetSelectSpecialTrigger(Int_t selectSpecialTrigger)
    case 3:
       fSpecialTrigger=3; // V0AND plus with SDD requested
       break;
-
+   // allows to run MB & 6 other different trigger classes in parallel with the same photon cut   
+   case 4: 
+      fSpecialTrigger=4; // different trigger class as MB
+      fTriggerSelectedManually = kTRUE;
+      break;
+   case 5: 
+      fSpecialTrigger=4; // different trigger class as MB
+      fTriggerSelectedManually = kTRUE;
+      break;
+   case 6: 
+      fSpecialTrigger=4; // different trigger class as MB
+      fTriggerSelectedManually = kTRUE;
+      break;
+   case 7: 
+      fSpecialTrigger=4; // different trigger class as MB
+      fTriggerSelectedManually = kTRUE;
+      break;
+    case 8: 
+      fSpecialTrigger=4; // different trigger class as MB
+      fTriggerSelectedManually = kTRUE;
+      break;  
+    case 9: 
+      fSpecialTrigger=4; // different trigger class as MB
+      fTriggerSelectedManually = kTRUE;
+      break;    
    default:
       AliError("Warning: Special Trigger Not known");
       return kFALSE;
@@ -1905,8 +2087,8 @@ Bool_t AliConversionCuts::SetEtaCut(Int_t etaCut)
       fEtaCutMin               = -0.1;
       fLineCutZRSlopeMin = 0.;
       break;
-   case 1:     // 1.2
-      fEtaCut          = 1.2;
+   case 1:     // 1.2  // changed from 1.2 to 0.6 on 2013.06.10
+      fEtaCut          = 0.6;
       fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
       fEtaCutMin               = -0.1;
       fLineCutZRSlopeMin = 0.;
@@ -2664,12 +2846,11 @@ Double_t AliConversionCuts::GetCentrality(AliVEvent *event)
       AliCentrality *fESDCentrality=(AliCentrality*)esdEvent->GetCentrality();
 
       if(fDetectorCentrality==0){
-       if (fIsHeavyIon==2){
-         return fESDCentrality->GetCentralityPercentile("V0A"); // default for pPb
-       }
-       else{
-         return fESDCentrality->GetCentralityPercentile("V0M"); // default
-       }
+         if (fIsHeavyIon==2){
+            return fESDCentrality->GetCentralityPercentile("V0A"); // default for pPb
+         } else{
+            return fESDCentrality->GetCentralityPercentile("V0M"); // default
+         }
       }
       if(fDetectorCentrality==1){
          return fESDCentrality->GetCentralityPercentile("CL1");
@@ -2838,8 +3019,19 @@ Bool_t AliConversionCuts::IsTriggerSelected()
    UInt_t isSelected = AliVEvent::kAny;
    if (fInputHandler==NULL) return kFALSE;
    if( fInputHandler->GetEventSelection()) {
+      if (!fTriggerSelectedManually){
+         if (fPreSelCut) fOfflineTriggerMask = AliVEvent::kAny;
+         else {
+            if (fIsHeavyIon == 1) fOfflineTriggerMask = AliVEvent::kMB | AliVEvent::kCentral | AliVEvent::kSemiCentral;
+               else if (fIsHeavyIon == 2) fOfflineTriggerMask = AliVEvent::kINT7;
+               else fOfflineTriggerMask = AliVEvent::kMB;
+         } 
+      }
       // Get the actual offline trigger mask for the event and AND it with the
       // requested mask. If no mask requested select by default the event.
+//       if (fPreSelCut) cout << "Trigger selected from outside: "<< fTriggerSelectedManually <<"\t Offline Trigger mask for Precut: " << fOfflineTriggerMask << endl;
+//       else cout << "Trigger selected from outside: "<< fTriggerSelectedManually <<"\t Offline Trigger mask: " << fOfflineTriggerMask << endl;
+      
       if (fOfflineTriggerMask)
          isSelected = fOfflineTriggerMask & fInputHandler->IsEventSelected();
    }
@@ -3084,7 +3276,7 @@ Bool_t AliConversionCuts::RejectToCloseV0s(AliAODConversionPhoton* photon, TList
    return kTRUE;
 }
 ///________________________________________________________________________
-void AliConversionCuts::GetNotRejectedParticles(Int_t rejection, TList *HeaderList, AliMCEvent *MCEvent){
+void AliConversionCuts::GetNotRejectedParticles(Int_t rejection, TList *HeaderList, AliVEvent *MCEvent){
 
    if(fNotRejectedStart){
       delete[] fNotRejectedStart;
@@ -3100,9 +3292,30 @@ void AliConversionCuts::GetNotRejectedParticles(Int_t rejection, TList *HeaderLi
    }
 
    if(rejection == 0) return; // No Rejection
-   AliGenCocktailEventHeader *cHeader = dynamic_cast<AliGenCocktailEventHeader*>(MCEvent->GenEventHeader());
-   if(cHeader){
-      TList *genHeaders = cHeader->GetHeaders();
+
+   AliGenCocktailEventHeader *cHeader = 0x0;
+   AliAODMCHeader *cHeaderAOD = 0x0;
+   Bool_t headerFound = kFALSE;
+
+   if(MCEvent->IsA()==AliMCEvent::Class()){
+      cHeader = dynamic_cast<AliGenCocktailEventHeader*>(dynamic_cast<AliMCEvent*>(MCEvent)->GenEventHeader());
+      if(cHeader) headerFound = kTRUE;
+   }
+   if(MCEvent->IsA()==AliAODEvent::Class()){
+      cHeaderAOD = dynamic_cast<AliAODMCHeader*>(MCEvent->FindListObject(AliAODMCHeader::StdBranchName()));
+      if(cHeaderAOD) headerFound = kTRUE;
+   }
+      
+   if(headerFound){
+      TList *genHeaders = 0x0;
+      if(cHeader) genHeaders = cHeader->GetHeaders();
+      if(cHeaderAOD){
+         genHeaders = cHeaderAOD->GetCocktailHeaders();
+         if(genHeaders->GetEntries()==1){
+            SetRejectExtraSignalsCut(0);
+            return;
+         }
+      }
       AliGenEventHeader* gh = 0;
       fnHeaders = 0;
       if(rejection == 1 || rejection == 3) fnHeaders = 1; // MinBiasHeader
@@ -3157,17 +3370,17 @@ void AliConversionCuts::GetNotRejectedParticles(Int_t rejection, TList *HeaderLi
 
       fnHeaders = 1;
       fNotRejectedStart[0] = 0;
-      fNotRejectedEnd[0] = MCEvent->Stack()->GetNprimary()-1;
+      fNotRejectedEnd[0] = static_cast<AliMCEvent*>(MCEvent)->Stack()->GetNprimary()-1;
       //       if(rejection == 2){
       fGeneratorNames = new TString[1];
       fGeneratorNames[0] = "NoCocktailGeneratorFound";
 //       }
 
-      AliGenPythiaEventHeader *mcHeaderPythia = dynamic_cast<AliGenPythiaEventHeader*>(MCEvent->GenEventHeader());
+      AliGenPythiaEventHeader *mcHeaderPythia = dynamic_cast<AliGenPythiaEventHeader*>(static_cast<AliMCEvent*>(MCEvent)->GenEventHeader());
       if (mcHeaderPythia) fGeneratorNames[0] = "NoCocktailGeneratorFound_Pythia";
-      AliGenDPMjetEventHeader *mcHeaderPhojet = dynamic_cast<AliGenDPMjetEventHeader*>(MCEvent->GenEventHeader());
+      AliGenDPMjetEventHeader *mcHeaderPhojet = dynamic_cast<AliGenDPMjetEventHeader*>(static_cast<AliMCEvent*>(MCEvent)->GenEventHeader());
       if (mcHeaderPhojet) fGeneratorNames[0] = "NoCocktailGeneratorFound_Phojet";
-      AliGenHijingEventHeader *mcHeaderHijing = dynamic_cast<AliGenHijingEventHeader*>(MCEvent->GenEventHeader());
+      AliGenHijingEventHeader *mcHeaderHijing = dynamic_cast<AliGenHijingEventHeader*>(static_cast<AliMCEvent*>(MCEvent)->GenEventHeader());
       if (mcHeaderHijing) fGeneratorNames[0] = "NoCocktailGeneratorFound_Hijing";
 
       SetRejectExtraSignalsCut(0);
@@ -3175,23 +3388,39 @@ void AliConversionCuts::GetNotRejectedParticles(Int_t rejection, TList *HeaderLi
 
 }
 //_________________________________________________________________________
-Int_t AliConversionCuts::IsParticleFromBGEvent(Int_t index, AliStack *MCStack){
+Int_t AliConversionCuts::IsParticleFromBGEvent(Int_t index, AliStack *MCStack, AliVEvent *InputEvent){
 
    // Not Accepted == kFALSE == 0
    //     Accepted ==  kTRUE == 1
    //  FirstHeader ==  kTRUE == 3
-
    if(index < 0) return 0; // No Particle
 
    Int_t accepted = 0;
-   if( index >= MCStack->GetNprimary()){ // Secondary Particle
-      if( ((TParticle*)MCStack->Particle(index))->GetMother(0) < 0) return 1; // Secondary Particle without Mother??
-      return IsParticleFromBGEvent(((TParticle*)MCStack->Particle(index))->GetMother(0),MCStack);
+   if(!InputEvent || InputEvent->IsA()==AliESDEvent::Class()){
+      if( index >= MCStack->GetNprimary()){ // Secondary Particle
+         if( ((TParticle*)MCStack->Particle(index))->GetMother(0) < 0) return 1; // Secondary Particle without Mother??
+         return IsParticleFromBGEvent(((TParticle*)MCStack->Particle(index))->GetMother(0),MCStack,InputEvent);
+      }
+      for(Int_t i = 0;i<fnHeaders;i++){
+         if(index >= fNotRejectedStart[i] && index <= fNotRejectedEnd[i]){
+            accepted = 1;
+            if(i == 0) accepted = 2; // MB Header
+         }
+      }
    }
-   for(Int_t i = 0;i<fnHeaders;i++){
-      if(index >= fNotRejectedStart[i] && index <= fNotRejectedEnd[i]){
-         accepted = 1;
-         if(i == 0) accepted = 2; // MB Header
+   else if(InputEvent->IsA()==AliAODEvent::Class()){
+      TClonesArray *AODMCTrackArray = dynamic_cast<TClonesArray*>(InputEvent->FindListObject(AliAODMCParticle::StdBranchName()));
+      AliAODMCParticle *aodMCParticle = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(index));
+      if(!aodMCParticle->IsPrimary()){
+         if( aodMCParticle->GetMother() < 0) return 1;// Secondary Particle without Mother??
+         return IsParticleFromBGEvent(aodMCParticle->GetMother(),MCStack,InputEvent);
+      }
+      index = abs(static_cast<AliAODMCParticle*>(AODMCTrackArray->At(index))->GetLabel());
+      for(Int_t i = 0;i<fnHeaders;i++){
+         if(index >= fNotRejectedStart[i] && index <= fNotRejectedEnd[i]){
+            accepted = 1;
+            if(i == 0) accepted = 2; // MB Header
+         }
       }
    }
 
@@ -3200,6 +3429,9 @@ Int_t AliConversionCuts::IsParticleFromBGEvent(Int_t index, AliStack *MCStack){
 //_________________________________________________________________________
 Int_t AliConversionCuts::IsEventAcceptedByConversionCut(AliConversionCuts *ReaderCuts, AliVEvent *InputEvent, AliMCEvent *MCEvent, Bool_t isHeavyIon){
 
+   if ( !IsTriggerSelected() )
+      return 3;
+   
    if(isHeavyIon && !(IsCentralitySelected(InputEvent,MCEvent)))
       return 1; // Check Centrality --> Not Accepted => eventQuality = 1
 
@@ -3209,7 +3441,7 @@ Int_t AliConversionCuts::IsEventAcceptedByConversionCut(AliConversionCuts *Reade
          return 6; // Check Pileup --> Not Accepted => eventQuality = 6
       }
    }
-
+   
    Bool_t hasV0And = ReaderCuts->HasV0AND();
    Bool_t isSDDFired = ReaderCuts->IsSDDFired();
    if( (IsSpecialTrigger() == 2 || IsSpecialTrigger() == 3) && !isSDDFired && !MCEvent)
@@ -3217,22 +3449,24 @@ Int_t AliConversionCuts::IsEventAcceptedByConversionCut(AliConversionCuts *Reade
 
    if( (IsSpecialTrigger() == 1 || IsSpecialTrigger() == 3) && !hasV0And)
       return 8; // V0AND requested but no fired
-
+   
 
    return 0;
 }
 //_________________________________________________________________________
-Float_t AliConversionCuts::GetWeightForMeson(TString period, Int_t index, AliStack *MCStack){
-   if (!(period.CompareTo("LHC12f1a") == 0 || period.CompareTo("LHC12f1b") == 0  || period.CompareTo("LHC12i3") == 0 )) return 1.;
+Float_t AliConversionCuts::GetWeightForMeson(TString period, Int_t index, AliStack *MCStack, AliVEvent *InputEvent){
+   if (!(period.CompareTo("LHC12f1a") == 0 || period.CompareTo("LHC12f1b") == 0  || period.CompareTo("LHC12i3") == 0 || period.CompareTo("LHC11a10a") == 0 || period.CompareTo("LHC11a10b") == 0 || period.CompareTo("LHC11a10b_bis") == 0 || period.CompareTo("LHC11a10a_bis") == 0 || period.CompareTo("LHC11a10b_plus") == 0 || period.CompareTo("LHC13d2") == 0)) return 1.;
+   
    Int_t kCaseGen = 0;
    for (Int_t i = 0; i < fnHeaders; i++){
       if (index >= fNotRejectedStart[i] && index < fNotRejectedEnd[i]+1){
-//          cout << fGeneratorNames[i].Data() << endl;
          if (fGeneratorNames[i].CompareTo("Pythia") == 0){
             kCaseGen = 1;
          } else if (fGeneratorNames[i].CompareTo("DPMJET") == 0){
             kCaseGen = 2;
-         } else if (fGeneratorNames[i].CompareTo("HIJING") == 0){
+         } else if (fGeneratorNames[i].CompareTo("HIJING") == 0 || 
+                    fGeneratorNames[i].CompareTo("Hijing") == 0 || 
+                    fGeneratorNames[i].Contains("hijing")){
             kCaseGen = 3;
          } else if (fGeneratorNames[i].CompareTo("BOX") == 0){
             kCaseGen = 4;
@@ -3247,81 +3481,199 @@ Float_t AliConversionCuts::GetWeightForMeson(TString period, Int_t index, AliSta
          } else if (fGeneratorNames[i].CompareTo("NoCocktailGeneratorFound_Hijing") == 0){
             kCaseGen = 3;
          }
-//          cout << "resulting kCaseGen :" << kCaseGen << endl;
       }
    }
+   if (kCaseGen == 0) return 1;
+   
 
-   Double_t mesonPt = ((TParticle*)MCStack->Particle(index))->Pt();
-
-   Double_t mesonMass = ((TParticle*)MCStack->Particle(index))->GetCalcMass();
-   Float_t functionResult = 1.;
-   if (kCaseGen == 1){
+   Double_t mesonPt = 0;
+   Double_t mesonMass = 0;
+   Int_t PDGCode = 0;
+   if(!InputEvent || InputEvent->IsA()==AliESDEvent::Class()){
+      mesonPt = ((TParticle*)MCStack->Particle(index))->Pt();
+      mesonMass = ((TParticle*)MCStack->Particle(index))->GetCalcMass();
+      PDGCode = ((TParticle*)MCStack->Particle(index))->GetPdgCode();
+   }
+   else if(InputEvent->IsA()==AliAODEvent::Class()){
+      TClonesArray *AODMCTrackArray = dynamic_cast<TClonesArray*>(InputEvent->FindListObject(AliAODMCParticle::StdBranchName()));
+      AliAODMCParticle *aodMCParticle = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(index));
+      mesonPt = aodMCParticle->Pt();
+      mesonMass = aodMCParticle->GetCalcMass();
+      PDGCode = aodMCParticle->GetPdgCode();
+   }   
+
+   Float_t functionResultMC = 1.;
+   if (kCaseGen == 1){ // Pythia 6
       Float_t dNdyMC = 2.1462;
       Float_t nMC = 7.06055;
       Float_t tMC = 0.12533;
-      if ( ((TParticle*)MCStack->Particle(index))->GetPdgCode() ==  111){
+      if ( PDGCode ==  111){
          dNdyMC = 2.1462;
          nMC = 7.06055;
          tMC = 0.12533;
-      } else if ( ((TParticle*)MCStack->Particle(index))->GetPdgCode() ==  221){
+      } else if ( PDGCode ==  221){
          dNdyMC = 0.2357;
          nMC = 5.9105;
          tMC = 0.1525;
       }
-      functionResult = dNdyMC / ( 2 * TMath::Pi())*(nMC-1.)*(nMC-2.) / (nMC*tMC*(nMC*tMC+mesonMass*(nMC-2.)))  * TMath::Power(1.+(TMath::Sqrt(mesonPt*mesonPt+mesonMass*mesonMass)-mesonMass)/(nMC*tMC), -nMC);
-   } else if (kCaseGen == 2){
+      functionResultMC = dNdyMC / ( 2 * TMath::Pi())*(nMC-1.)*(nMC-2.) / (nMC*tMC*(nMC*tMC+mesonMass*(nMC-2.)))  * TMath::Power(1.+(TMath::Sqrt(mesonPt*mesonPt+mesonMass*mesonMass)-mesonMass)/(nMC*tMC), -nMC);
+   } else if (kCaseGen == 2){ // Phojet
       Float_t dNdyMC = 2.35978;
       Float_t nMC = 6.81795;
       Float_t tMC = 0.11492;
-      if ( ((TParticle*)MCStack->Particle(index))->GetPdgCode() ==  111){
+      if ( PDGCode ==  111){
          dNdyMC = 2.35978;
          nMC = 6.81795;
          tMC = 0.11492;
-      } else if ( ((TParticle*)MCStack->Particle(index))->GetPdgCode() ==  221){
+      } else if ( PDGCode ==  221){
          dNdyMC = 0.3690;
          nMC = 5.55809;
          tMC = 0.13387;
       }
-      functionResult = dNdyMC / ( 2 * TMath::Pi())*(nMC-1.)*(nMC-2.) / (nMC*tMC*(nMC*tMC+mesonMass*(nMC-2.)))  * TMath::Power(1.+(TMath::Sqrt(mesonPt*mesonPt+mesonMass*mesonMass)-mesonMass)/(nMC*tMC), -nMC);
-   } else if (kCaseGen == 4){
-//       functionResult = 1./sqrt(1.-mesonMass*mesonMass/((mesonMass*mesonMass+mesonPt*mesonPt)*cosh(mesonY)*cosh(mesonY)));
+      functionResultMC = dNdyMC / ( 2 * TMath::Pi())*(nMC-1.)*(nMC-2.) / (nMC*tMC*(nMC*tMC+mesonMass*(nMC-2.)))  * TMath::Power(1.+(TMath::Sqrt(mesonPt*mesonPt+mesonMass*mesonMass)-mesonMass)/(nMC*tMC), -nMC);
+   } else if (kCaseGen == 4){ // BOX generators pp
+//       functionResultMC = 1./sqrt(1.-mesonMass*mesonMass/((mesonMass*mesonMass+mesonPt*mesonPt)*cosh(mesonY)*cosh(mesonY)));
       Float_t a = 0.23437;
       Float_t b = 5.6661;
       Float_t c = -1430.5863;
       Float_t d = -0.6966624;
       Float_t e = 252.3742;
-      if ( ((TParticle*)MCStack->Particle(index))->GetPdgCode() ==  111){
+      if ( PDGCode ==  111){
          a = 0.23437;
          b = 5.6661;
          c = -1430.5863;
          d = -0.6966624;
          e = 252.3742;
-      } else if ( ((TParticle*)MCStack->Particle(index))->GetPdgCode() ==  221){
+      } else if ( PDGCode ==  221){
          a = 0.10399;
          b = 4.35311;
          c = -12.17723;
          d = -0.01172;
          e =1.85140;
       }
-      functionResult = a*TMath::Power(mesonPt,-1.*(b+c/(TMath::Power(mesonPt,d)+e)))*1./mesonPt *1./1.6 *1./(2.* TMath::Pi());
+      functionResultMC = a*TMath::Power(mesonPt,-1.*(b+c/(TMath::Power(mesonPt,d)+e)))*1./mesonPt *1./1.6 *1./(2.* TMath::Pi());
+   } else if (kCaseGen == 3 ){ // HIJING
+      if ( PDGCode ==  111 && fDoReweightHistoMCPi0 && hReweightMCHistPi0!= 0x0){
+         functionResultMC = hReweightMCHistPi0->Interpolate(mesonPt);
+      } 
+      if ( PDGCode ==  310 && fDoReweightHistoMCK0s && hReweightMCHistK0s!= 0x0){
+         functionResultMC = hReweightMCHistK0s->Interpolate(mesonPt);
+      }
    }
 
-   Float_t dNdyData = 2.2328;
-   Float_t nData = 7.1473;
-   Float_t tData = 0.1346;
-   if ( ((TParticle*)MCStack->Particle(index))->GetPdgCode() ==  111){
+   Float_t functionResultData = 1;
+   if (kCaseGen == 1 || kCaseGen == 2 || kCaseGen == 4 ){
+      Float_t dNdyData = 2.2328;
+      Float_t nData = 7.1473;
+      Float_t tData = 0.1346;
+      if ( PDGCode ==  111){
          dNdyData = 2.2328;
          nData = 7.1473;
          tData = 0.1346;
-      } else if ( ((TParticle*)MCStack->Particle(index))->GetPdgCode() ==  221){
+      } else if ( PDGCode ==  221){
          dNdyData = 0.38992; //be careful this fit is not optimal, eta in data still has problems
          nData = 5.72778;
          tData = 0.13835;
       }
-   Float_t tsallisData = dNdyData / ( 2 * TMath::Pi())*(nData-1.)*(nData-2.) / (nData*tData*(nData*tData+mesonMass*(nData-2.)))  * TMath::Power(1.+(TMath::Sqrt(mesonPt*mesonPt+mesonMass*mesonMass)-mesonMass)/(nData*tData), -nData);
-//    cout << "tsallisData/functionResult: " << tsallisData/functionResult << endl;
-   return tsallisData/functionResult;
-//       return
+      functionResultData = dNdyData / ( 2 * TMath::Pi())*(nData-1.)*(nData-2.) / (nData*tData*(nData*tData+mesonMass*(nData-2.)))  * TMath::Power(1.+(TMath::Sqrt(mesonPt*mesonPt+mesonMass*mesonMass)-mesonMass)/(nData*tData), -nData);
+   } else {
+      Float_t a = 0.;
+      Float_t b = 0.;
+      Float_t c = 0.;
+      Float_t d = 0.;
+      Float_t e = 0.;
+      if ( PDGCode ==  111 ){
+         if (fModCentralityClass == 1 && fCentralityMin == 0 && fCentralityMax == 1 ){ // 0-5 % PbPb
+            a = 25.8747458223;
+            b = 5.8761820045;
+            c = -33.9928191673;
+            d = 3.0731850142;
+            e = 13.2500447620;
+         } else if (fModCentralityClass == 1 && fCentralityMin == 1 && fCentralityMax == 2){ // 5-10% PbPb
+            a = 21.7518148922;
+            b = 5.8441200081;
+            c = -17.1497051691;
+            d = 2.3799090842;
+            e = 5.4346404718;
+         } else if (fModCentralityClass == 0 && fCentralityMin == 0 && fCentralityMax == 1){ // 0-10% PbPb
+            a = 22.9852133622;
+            b = 5.8602063916;
+            c = -17.0992478654;
+            d = 2.4426218039;
+            e = 5.1194526345;
+         } else if (fModCentralityClass == 0 && fCentralityMin == 1 && fCentralityMax == 2){ // 10-20% PbPb
+            a = 19.3237333776;
+            b = 5.8145906958;
+            c = -13.8316665424;
+            d = 2.3737630637;
+            e = 4.7690300693;
+         } else if (fModCentralityClass == 0 && fCentralityMin == 2 && fCentralityMax == 4){ // 20-40% PbPb
+            a = 11.2656032751;
+            b = 5.8003194354;
+            c = -13.3936105929;
+            d = 2.3371452334;
+            e = 4.4726244958;
+         } else if (fModCentralityClass == 0 && fCentralityMin == 4 && fCentralityMax == 6){ // 40-60% PbPb   
+            a = 4.1578154081;
+            b = 5.6450005163;
+            c = -8.4309375240;
+            d = 1.8918308704;
+            e = 2.9429194709;
+         } else if (fModCentralityClass == 0 && fCentralityMin == 6 && fCentralityMax == 8){ // 60-80% PbPb      
+            a = 1.0635443810;
+            b = 5.1337469970;
+            c = -8.5906997238;
+            d = 2.9794995997;
+            e = 3.9294980048;
+         }  else if (fModCentralityClass == 0 && fCentralityMin == 0 && fCentralityMax == 2){ // 0-20% PbPb      
+            a = 21.7018745556;
+            b = 5.9019352094;
+            c = -14.2295510326;
+            d = 2.2104490688;
+            e = 4.2969671500;
+         }  else if (fModCentralityClass == 0 && fCentralityMin == 0 && fCentralityMax == 4){ // 0-40% PbPb      
+            a = 16.8227412106;
+            b = 5.8660502207;
+            c = -12.0978551215;
+            d = 2.1695068981;
+            e = 3.5349621182;
+         }   else if (fModCentralityClass == 0 && fCentralityMin == 0 && fCentralityMax == 8){ // 0-80% PbPb      
+            a = 9.4675681080;
+            b = 5.8114944205;
+            c = -10.4901523616;
+            d = 2.0607982712;
+            e = 2.9262259130;
+         }   else if (fModCentralityClass == 0 && fCentralityMin == 4 && fCentralityMax == 8){ // 60-80% PbPb      
+            a = 2.5985551785;
+            b = 5.4118895738;
+            c = -8.2510958428;
+            d = 2.2551249190;
+            e = 3.0700919491;
+         }
+         
+         functionResultData = a*TMath::Power(mesonPt,-1*(b+c/(TMath::Power(mesonPt,d)+e)));
+      } 
+      
+   }
+   
+   Double_t weight = 1;
+   if (PDGCode ==  111 || PDGCode ==  221){
+      if (functionResultData != 0. && functionResultMC != 0. && isfinite(functionResultData) && isfinite(functionResultMC)){
+         weight = functionResultData/functionResultMC;
+         if ( !(kCaseGen == 3 && fDoReweightHistoMCPi0 && hReweightMCHistPi0!= 0x0 && PDGCode ==  111)){
+         weight = 1.;  
+         }
+         if (!isfinite(functionResultData)) weight = 1.;  
+         if (!isfinite(weight)) weight = 1.;  
+      }
+   } else if (PDGCode ==  310 && functionResultMC != 0 && isfinite(functionResultMC)){
+        weight = functionResultMC;
+   }
+      
+//    if (fModCentralityClass == 0 && fCentralityMin == 4 && fCentralityMax == 6 && PDGCode ==  111){
+//       cout << period.Data() << "\t" << kCaseGen << "\t" <<fModCentralityClass<< "\t" <<fCentralityMin<< "\t" <<fCentralityMax << "\t" << mesonPt << "\t" <<mesonMass<< "\t"<<functionResultData << "\t"<< functionResultMC << "\t" << weight <<endl;
+//    }
+   return weight;
 }
 ///________________________________________________________________________
 AliConversionCuts* AliConversionCuts::GetStandardCuts2010PbPb(){
index 712b0ba..c6cb632 100644 (file)
@@ -28,6 +28,7 @@ class AliAnalysisCuts;
 class iostream;
 class TList;
 class AliAnalysisManager;
+class AliAODMCParticle;
 
 using namespace std;
 
@@ -89,9 +90,19 @@ class AliConversionCuts : public AliAnalysisCuts {
 
 
   Bool_t InitializeCutsFromCutString(const TString analysisCutSelection);
-  void SelectCollisionCandidates(UInt_t offlineTriggerMask = AliVEvent::kMB) {fOfflineTriggerMask = offlineTriggerMask;}
+  void SelectCollisionCandidates(UInt_t offlineTriggerMask = AliVEvent::kAny) {
+     fOfflineTriggerMask = offlineTriggerMask;
+     fTriggerSelectedManually = kTRUE;
+  }
+  void SelectSpecialTrigger(UInt_t offlineTriggerMask = AliVEvent::kAny, TString TriggerClassName = "AliVEvent::kAny" ) {
+     fOfflineTriggerMask = offlineTriggerMask;
+     fSpecialTriggerName = TriggerClassName;
+     cout << fSpecialTriggerName.Data() << endl;
+     
+  }   
   void FillElectonLabelArray(AliAODConversionPhoton* photon, Int_t nV0);
   void SetAcceptedHeader(TList *HeaderList){fHeaderList = HeaderList;}   
+  void SetPreSelectionCutFlag(Bool_t preSelFlag){fPreSelCut = preSelFlag;}   
   TString *GetFoundHeader(){return fGeneratorNames;}
 
   Int_t GetEventQuality(){return fEventQuality;}
@@ -118,6 +129,7 @@ class AliConversionCuts : public AliAnalysisCuts {
   Int_t IsEventAcceptedByConversionCut(AliConversionCuts *ReaderCuts, AliVEvent *InputEvent, AliMCEvent *MCEvent, Bool_t isHeavyIon);
   Bool_t PhotonIsSelected(AliConversionPhotonBase * photon, AliVEvent  * event);
   Bool_t PhotonIsSelectedMC(TParticle *particle,AliStack *fMCStack,Bool_t checkForConvertedGamma=kTRUE);
+  Bool_t PhotonIsSelectedAODMC(AliAODMCParticle *particle,TClonesArray *aodmcArray,Bool_t checkForConvertedGamma=kTRUE);
   Bool_t ElectronIsSelectedMC(TParticle *particle,AliStack *fMCStack);
   Bool_t TracksAreSelected(AliVTrack * negTrack, AliVTrack * posTrack);
   Bool_t MesonIsSelected(AliAODConversionMother *pi0,Bool_t IsSignal=kTRUE);
@@ -178,9 +190,19 @@ class AliConversionCuts : public AliAnalysisCuts {
   Bool_t CosinePAngleCut(const AliConversionPhotonBase * photon, AliVEvent * event) const;
   Bool_t RejectSharedElectronV0s(AliAODConversionPhoton* photon, Int_t nV0, Int_t nV0s);
   Bool_t RejectToCloseV0s(AliAODConversionPhoton* photon, TList *photons, Int_t nV0);
-  Int_t IsParticleFromBGEvent(Int_t index, AliStack *MCStack);
-  void GetNotRejectedParticles(Int_t rejection, TList *HeaderList, AliMCEvent *MCEvent);
-
+  Int_t IsParticleFromBGEvent(Int_t index, AliStack *MCStack, AliVEvent *InputEvent = 0x0);
+  void GetNotRejectedParticles(Int_t rejection, TList *HeaderList, AliVEvent *MCEvent);
+  void SetUseReweightingWithHistogramFromFile( Bool_t pi0reweight=kTRUE, Bool_t etareweight=kFALSE, Bool_t k0sreweight=kFALSE,TString path="$ALICE_ROOT/PWGGA/GammaConv/MCSpectraInput.root", 
+                                               TString histoNamePi0 = "Hijing_PbPb_2760GeV_0005", TString histoNameEta = "", TString histoNameK0s = "") {
+     fDoReweightHistoMCPi0 = pi0reweight; 
+     fDoReweightHistoMCEta = etareweight; 
+     fDoReweightHistoMCK0s = k0sreweight; 
+     fPathTrFReweighting=path;
+     fNameHistoReweightingPi0 =histoNamePi0;
+     fNameHistoReweightingEta =histoNameEta;
+     fNameHistoReweightingK0s =histoNameK0s; 
+  }
+  void  LoadReweightingHistosMCFromFile ();
   // Event Cuts
   Bool_t IsCentralitySelected(AliVEvent *fInputEvent, AliVEvent *fMCEvent = NULL);
   Double_t GetCentrality(AliVEvent *event);
@@ -190,6 +212,7 @@ class AliConversionCuts : public AliAnalysisCuts {
   Bool_t HasV0AND(){return fHasV0AND;}
   Bool_t IsSDDFired(){return fIsSDDFired;}
   Int_t IsSpecialTrigger(){return fSpecialTrigger;}
+  TString GetSpecialTriggerName(){return fSpecialTriggerName;}
 
   // Set Individual Cuts
   Bool_t SetRCut(Int_t RCut);
@@ -224,7 +247,7 @@ class AliConversionCuts : public AliAnalysisCuts {
 
   Int_t IsHeavyIon(){return fIsHeavyIon;}
   Int_t GetFirstTPCRow(Double_t radius);
-  Float_t GetWeightForMeson(TString period, Int_t index, AliStack *MCStack);
+  Float_t GetWeightForMeson(TString period, Int_t index, AliStack *MCStack, AliVEvent *InputEvent = 0x0);
 
   Bool_t UseElecSharingCut(){return fDoSharedElecCut;}
   Bool_t UseToCloseV0sCut(){return fDoToCloseV0sCut;}
@@ -331,8 +354,14 @@ class AliConversionCuts : public AliAnalysisCuts {
   TObjString *fCutString; // cut number used for analysis
   AliAnalysisUtils *fUtils;
   Double_t fEtaShift;
-  Bool_t fDoEtaShift;
-
+  Bool_t fDoEtaShift;            // Flag for Etashift
+  Bool_t fDoReweightHistoMCPi0; // Flag for reweighting Pi0 input with histogram
+  Bool_t fDoReweightHistoMCEta; // Flag for reweighting Eta input with histogram
+  Bool_t fDoReweightHistoMCK0s; // Flag for reweighting K0s input with histogram
+  TString fPathTrFReweighting; // Path for file used in reweighting
+  TString fNameHistoReweightingPi0; //Histogram name for reweighting Pi0
+  TString fNameHistoReweightingEta; //Histogram name for reweighting Eta
+  TString fNameHistoReweightingK0s; //Histogram name for reweighting K0s
   // Histograms
   TH1F *hdEdxCuts;  // bookkeeping for dEdx cuts
   TH2F *hTPCdEdxbefore; // TPC dEdx before cuts
@@ -355,9 +384,15 @@ class AliConversionCuts : public AliAnalysisCuts {
   TH1F *hVertexZ; // vertex z distribution for selected events
   TH1F *hTriggerClass; //fired offline trigger class
   TH1F *hTriggerClassSelected; //selected fired offline trigger class
+  TH1D *hReweightMCHistPi0; //histogram input for reweighting Pi0
+  TH1D *hReweightMCHistEta; //histogram input for reweighting Eta
+  TH1D *hReweightMCHistK0s; //histogram input for reweighting K0s
+  Bool_t fPreSelCut; // Flag for preselection cut used in V0Reader
+  Bool_t fTriggerSelectedManually; // Flag for manual trigger selection
+  TString fSpecialTriggerName; // Name of the Special Triggers
 private:
 
-  ClassDef(AliConversionCuts,3)
+  ClassDef(AliConversionCuts,4)
 };
 
 
index 69f47e7..b081698 100644 (file)
 #include "AliESDEvent.h"
 #include "AliCentrality.h"
 #include "TList.h"
+#include "TPDGCode.h"
+#include "TDatabasePDG.h"
+#include "AliAODMCParticle.h"
+
 class iostream;
 
 using namespace std;
@@ -245,58 +249,100 @@ Bool_t AliConversionMesonCuts::MesonIsSelectedMC(TParticle *fMCMother,AliStack *
    }
    return kFALSE;
 }
-
 //________________________________________________________________________
-Bool_t AliConversionMesonCuts::MesonIsSelectedMCDalitz(TParticle *fMCMother,AliStack *fMCStack, Double_t fRapidityShift){
+Bool_t AliConversionMesonCuts::MesonIsSelectedAODMC(AliAODMCParticle *MCMother,TClonesArray *AODMCArray, Double_t fRapidityShift){
    // Returns true for all pions within acceptance cuts for decay into 2 photons
    // If bMCDaughtersInAcceptance is selected, it requires in addition that both daughter photons are within acceptance cuts
 
-   if(!fMCStack)return kFALSE;
-       
-   if(fMCMother->GetPdgCode()==111 || fMCMother->GetPdgCode()==221){
-               
-      if(fMCMother->R()>fMaxR) return kFALSE; // cuts on distance from collision point
+   if(!AODMCArray)return kFALSE;
+
+   if(MCMother->GetPdgCode()==111 || MCMother->GetPdgCode()==221){
+      Double_t rMeson = sqrt( (MCMother->Xv()*MCMother->Xv()) + (MCMother->Yv()*MCMother->Yv()) ) ;
+      if(rMeson>fMaxR) return kFALSE; // cuts on distance from collision point
 
       Double_t rapidity = 10.;
-      if(fMCMother->Energy() - fMCMother->Pz() == 0 || fMCMother->Energy() + fMCMother->Pz() == 0){
+      if(MCMother->E() - MCMother->Pz() == 0 || MCMother->E() + MCMother->Pz() == 0){
          rapidity=8.-fRapidityShift;
+      } else{
+         rapidity = 0.5*(TMath::Log((MCMother->E()+MCMother->Pz()) / (MCMother->E()-MCMother->Pz())))-fRapidityShift;
       }
-      else{
-         rapidity = 0.5*(TMath::Log((fMCMother->Energy()+fMCMother->Pz()) / (fMCMother->Energy()-fMCMother->Pz())))-fRapidityShift;
-      }        
-               
+
       // Rapidity Cut
       if(abs(rapidity)>fRapidityCutMeson)return kFALSE;
 
-      // Select only -> Dalitz decay channel
-      if(fMCMother->GetNDaughters()!=3)return kFALSE;
-
-      Int_t daughterPDGs[3] = {0,0,0};
-      Int_t index = 0;
-
-      //                iParticle->GetFirstDaughter(); idxPi0 <= iParticle->GetLastDaughter()
+      // Select only -> 2y decay channel
+      if(MCMother->GetNDaughters()!=2)return kFALSE;
 
-      for(Int_t i=fMCMother->GetFirstDaughter(); i<= fMCMother->GetLastDaughter();i++){
-         TParticle *MDaughter=fMCStack->Particle(i);
-         // Is Daughter a Photon or an electron?
-         daughterPDGs[index]=MDaughter->GetPdgCode();
-         index++;
-      }
-      for (Int_t j=0;j<2;j++){
-
-         for (Int_t i=0;i<2;i++){
-            if (daughterPDGs[i] > daughterPDGs[i+1]){
-               Int_t interMed = daughterPDGs[i] ; 
-               daughterPDGs[i] = daughterPDGs[i+1];
-               daughterPDGs[i+1] = interMed;
-            }
-         }
+      for(Int_t i=0;i<2;i++){
+         AliAODMCParticle *MDaughter=static_cast<AliAODMCParticle*>(AODMCArray->At(MCMother->GetDaughter(i)));
+         // Is Daughter a Photon?
+         if(MDaughter->GetPdgCode()!=22)return kFALSE;
+         // Is Photon in Acceptance?
+         //   if(bMCDaughtersInAcceptance){
+         //    if(!PhotonIsSelectedMC(MDaughter,fMCStack)){return kFALSE;}
+         //   }
       }
-      if (daughterPDGs[0] == -11 && daughterPDGs[1] == 11 && daughterPDGs[2] == 22) return kTRUE;
+      return kTRUE;
    }
    return kFALSE;
 }
 //________________________________________________________________________
+Bool_t AliConversionMesonCuts::MesonIsSelectedMCDalitz(TParticle *fMCMother,AliStack *fMCStack, Int_t &labelelectron, Int_t &labelpositron, Int_t &labelgamma, Double_t fRapidityShift){
+  
+   // Returns true for all pions within acceptance cuts for decay into 2 photons
+   // If bMCDaughtersInAcceptance is selected, it requires in addition that both daughter photons are within acceptance cuts
+
+   if( !fMCStack )return kFALSE;
+       
+   if( fMCMother->GetPdgCode() != 111 && fMCMother->GetPdgCode() != 221 ) return kFALSE;
+               
+   if(  fMCMother->R()>fMaxR ) return kFALSE; // cuts on distance from collision point
+
+   Double_t rapidity = 10.;
+   
+   if( fMCMother->Energy() - fMCMother->Pz() == 0 || fMCMother->Energy() + fMCMother->Pz() == 0 ){
+         rapidity=8.-fRapidityShift;
+   }
+   else{
+         rapidity = 0.5*(TMath::Log((fMCMother->Energy()+fMCMother->Pz()) / (fMCMother->Energy()-fMCMother->Pz())))-fRapidityShift;
+   }   
+               
+      // Rapidity Cut
+   if( abs(rapidity) > fRapidityCutMeson )return kFALSE;
+
+      // Select only -> Dalitz decay channel
+   if( fMCMother->GetNDaughters() != 3 )return kFALSE;
+
+   TParticle *positron = 0x0;
+   TParticle *electron = 0x0;
+   TParticle    *gamma = 0x0;
+       
+   for(Int_t index= fMCMother->GetFirstDaughter();index<= fMCMother->GetLastDaughter();index++){
+    
+     TParticle* temp = (TParticle*)fMCStack->Particle( index );
+               
+               switch( temp->GetPdgCode() ) {
+               case ::kPositron:
+                       positron      =  temp;
+                       labelpositron = index;
+                       break;
+               case ::kElectron:
+                       electron      =  temp;
+                       labelelectron = index;
+                       break;
+               case ::kGamma:
+                       gamma         =  temp;
+                       labelgamma    = index;
+                       break;
+               }
+  }
+  
+  if( positron && electron && gamma) return kTRUE;  
+  return kFALSE;
+  
+  
+}
+//________________________________________________________________________
 Bool_t AliConversionMesonCuts::MesonIsSelectedMCChiC(TParticle *fMCMother,AliStack *fMCStack,Int_t & labelelectronChiC, Int_t & labelpositronChiC, Int_t & labelgammaChiC, Double_t fRapidityShift){
    // Returns true for all ChiC within acceptance cuts for decay into JPsi + gamma -> e+ + e- + gamma
    // If bMCDaughtersInAcceptance is selected, it requires in addition that both daughter photons are within acceptance cuts
index 6233ce8..aea4b99 100644 (file)
@@ -14,6 +14,7 @@
 #include "AliStack.h"
 #include "AliAnalysisCuts.h"
 #include "TH1F.h"
+#include "AliAODMCParticle.h"
 
 class AliESDEvent;
 class AliAODEvent;
@@ -74,7 +75,8 @@ class AliConversionMesonCuts : public AliAnalysisCuts {
   // Cut Selection
   Bool_t MesonIsSelected(AliAODConversionMother *pi0,Bool_t IsSignal=kTRUE, Double_t fRapidityShift=0.);
   Bool_t MesonIsSelectedMC(TParticle *fMCMother,AliStack *fMCStack, Double_t fRapidityShift=0.);
-  Bool_t MesonIsSelectedMCDalitz(TParticle *fMCMother,AliStack *fMCStack, Double_t fRapidityShift=0.);
+  Bool_t MesonIsSelectedAODMC(AliAODMCParticle *MCMother,TClonesArray *AODMCArray, Double_t fRapidityShift=0.);
+  Bool_t MesonIsSelectedMCDalitz(TParticle *fMCMother,AliStack *fMCStack, Int_t &labelelectron, Int_t &labelpositron, Int_t &labelgamma,Double_t fRapidityShift=0.);
   Bool_t MesonIsSelectedMCChiC(TParticle *fMCMother,AliStack *fMCStack, Int_t &, Int_t &, Int_t &, Double_t fRapidityShift=0. );
   void PrintCuts();
 
@@ -82,7 +84,6 @@ class AliConversionMesonCuts : public AliAnalysisCuts {
   void SetFillCutHistograms(TString name=""){if(!fHistograms){InitCutHistograms(name);};}
   TList *GetCutHistograms(){return fHistograms;}
   void SmearParticle(AliAODConversionPhoton * photon);
-  
   ///Cut functions
   Bool_t RejectSharedElectronV0s(AliAODConversionPhoton* photon, Int_t nV0, Int_t nV0s);
   Bool_t RejectToCloseV0s(AliAODConversionPhoton* photon, TList *photons, Int_t nV0);
@@ -146,11 +147,10 @@ class AliConversionMesonCuts : public AliAnalysisCuts {
   TH1F *hMesonCuts; // bookkeeping for meson cuts
   TH1F *hMesonBGCuts; // bookkeeping for meson bg cuts
 
-
 private:
 
 
-  ClassDef(AliConversionMesonCuts,3)
+  ClassDef(AliConversionMesonCuts,4)
 };
 
 
index 6ea8e0b..c6f6dc8 100644 (file)
@@ -62,6 +62,9 @@ const char* AliDalitzElectronCuts::fgkCutNames[AliDalitzElectronCuts::kNCuts] =
 "RejectSharedElecGamma",\r
 "BackgroundScheme",\r
 "NumberOfRotations",\r
+"PtCut",\r
+"DCAcut",\r
+"MassCut",\r
 };\r
 \r
 //________________________________________________________________________\r
@@ -70,6 +73,9 @@ AliDalitzElectronCuts::AliDalitzElectronCuts(const char *name,const char *title)
     fPIDResponse(NULL),\r
     fesdTrackCuts(NULL),\r
     fEtaCut(0.9),\r
+    fEtaShift(0.0),\r
+    fDoEtaCut(kFALSE),\r
+    fPtCut(0.0),\r
     fRadiusCut(1000.0),\r
     fPsiPairCut(0.45),\r
     fDeltaPhiCutMin(0.),\r
@@ -106,6 +112,8 @@ AliDalitzElectronCuts::AliDalitzElectronCuts(const char *name,const char *title)
     fUseTrackMultiplicityForBG(kFALSE),\r
     fBKGMethod(0),\r
     fnumberOfRotationEventsForBG(0),\r
+    fDoMassCut(kFALSE),\r
+    fMassCut(999.),\r
     fCutString(NULL),\r
     hCutIndex(NULL),\r
     hdEdxCuts(NULL),\r
@@ -116,7 +124,11 @@ AliDalitzElectronCuts::AliDalitzElectronCuts(const char *name,const char *title)
     hTPCdEdxSignalbefore(NULL),\r
     hTPCdEdxSignalafter(NULL),\r
     hTOFbefore(NULL),\r
-    hTOFafter(NULL)\r
+    hTOFafter(NULL),\r
+    hTrackDCAxybefore(NULL),\r
+    hTrackDCAxyafter(NULL),\r
+    hTrackDCAzbefore(NULL),\r
+    hTrackDCAzafter(NULL)\r
    {\r
     InitPIDResponse();\r
     for(Int_t jj=0;jj<kNCuts;jj++){fCuts[jj]=0;}\r
@@ -124,7 +136,7 @@ AliDalitzElectronCuts::AliDalitzElectronCuts(const char *name,const char *title)
 \r
    //fesdTrackCuts = new AliESDtrackCuts("AliESDtrackCuts");\r
    // Using standard function for setting Cuts\r
-    Bool_t selectPrimaries=kTRUE;\r
+    Bool_t selectPrimaries=kFALSE;\r
     fesdTrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010(selectPrimaries);\r
 }\r
 \r
@@ -215,10 +227,15 @@ void AliDalitzElectronCuts::InitCutHistograms(TString name, Bool_t preCut,TStrin
        fHistograms->Add(hTPCdEdxSignalbefore);\r
        AxisBeforedEdxSignal = hTPCdEdxSignalbefore->GetXaxis();\r
 \r
-\r
        hTOFbefore=new TH2F(Form("Electron_TOF_before %s",cutName.Data()),"TOF electron before" ,150,0.05,20,400,-6,10);\r
        fHistograms->Add(hTOFbefore);\r
        AxisBeforeTOF = hTOFbefore->GetXaxis();\r
+       \r
+       hTrackDCAxybefore = new TH1F(Form("hTrackDCAxy_before %s",cutName.Data()),"DCAxy of tracks before",2000,-10.0,10.0);\r
+       fHistograms->Add(hTrackDCAxybefore);    \r
+       \r
+       hTrackDCAzbefore  = new TH1F(Form("hTrackDCAz_before %s",cutName.Data()), "DCAz of tracks before",2000,-10.0,10.0);\r
+       fHistograms->Add(hTrackDCAzbefore); \r
 \r
     }\r
 \r
@@ -234,6 +251,14 @@ void AliDalitzElectronCuts::InitCutHistograms(TString name, Bool_t preCut,TStrin
 \r
     hTOFafter=new TH2F(Form("Electron_TOF_after %s",cutName.Data()),"TOF electron after" ,150,0.05,20,400,-6,10);\r
     fHistograms->Add(hTOFafter);\r
+      \r
+    hTrackDCAxyafter  = new TH1F(Form("hTrackDCAxy_after %s",cutName.Data()),"DCAxy of tracks after",2000,-10.0,10.0);\r
+    fHistograms->Add(hTrackDCAxyafter); \r
+    \r
+    hTrackDCAzafter  = new TH1F(Form("hTrackDCAz_after %s",cutName.Data()), "DCAz of tracks  after",2000,-10.0,10.0);\r
+    fHistograms->Add(hTrackDCAzafter); \r
+    \r
+    \r
 \r
     TAxis *AxisAfter = hTPCdEdxafter->GetXaxis(); \r
     Int_t bins = AxisAfter->GetNbins();\r
@@ -285,13 +310,18 @@ Bool_t AliDalitzElectronCuts::InitPIDResponse(){
 ///________________________________________________________________________\r
 Bool_t AliDalitzElectronCuts::ElectronIsSelectedMC(Int_t labelParticle,AliStack *fMCStack)\r
 {   \r
-        if( labelParticle < 0 ) return kFALSE;\r
-        if( fMCStack->IsPhysicalPrimary(labelParticle) == kFALSE ) return kFALSE;\r
+        if( labelParticle < 0 || labelParticle >= fMCStack->GetNtrack() ) return kFALSE;\r
+        if( fMCStack->IsPhysicalPrimary(labelParticle) == kFALSE ) return kFALSE; //Ask Ana\r
 \r
         TParticle* particle = fMCStack->Particle(labelParticle);\r
 \r
-        if( TMath::Abs( particle->GetPdgCode() ) != 11)  return kFALSE;\r
-        if( TMath::Abs( particle->Eta() ) > fEtaCut   )  return kFALSE;\r
+        if( TMath::Abs( particle->GetPdgCode() ) != 11 )  return kFALSE;\r
+        \r
+        if( fDoEtaCut ){\r
+         if( particle->Eta() > (fEtaCut + fEtaShift) || particle->Eta() < (-fEtaCut + fEtaShift) )\r
+         return kFALSE;\r
+       }\r
+        \r
 \r
 return kTRUE;\r
 }\r
@@ -339,18 +369,44 @@ Bool_t AliDalitzElectronCuts::ElectronIsSelected(AliESDtrack* lTrack)
 ///________________________________________________________________________\r
 Bool_t AliDalitzElectronCuts::TrackIsSelected(AliESDtrack* lTrack) {\r
     // Track Selection for Photon Reconstruction\r
+    \r
+    \r
+   Float_t b[2];\r
+   Float_t bCov[3];\r
+   lTrack->GetImpactParameters(b,bCov);\r
+   if (bCov[0]<=0 || bCov[2]<=0) {\r
+     AliDebug(1, "Estimated b resolution lower or equal zero!");\r
+     bCov[0]=0; bCov[2]=0;\r
+    }\r
 \r
 \r
+  Float_t dcaToVertexXY = b[0];\r
+  Float_t dcaToVertexZ  = b[1];\r
+   \r
+    \r
 \r
-    if( ! fesdTrackCuts->AcceptTrack(lTrack) ){\r
+   if( hTrackDCAxybefore) hTrackDCAxybefore->Fill(dcaToVertexXY);\r
+   if( hTrackDCAzbefore ) hTrackDCAzbefore->Fill(dcaToVertexZ);\r
+   \r
 \r
-        return kFALSE;\r
-    }\r
 \r
-   if(  TMath::Abs( lTrack->Eta()) > fEtaCut ) {\r
+    if( ! fesdTrackCuts->AcceptTrack(lTrack) ){\r
 \r
         return kFALSE;\r
     }\r
+    \r
+    if( fDoEtaCut ) {\r
+      if(  lTrack->Eta() > (fEtaCut + fEtaShift) || lTrack->Eta() < (-fEtaCut + fEtaShift) ) {\r
+        return kFALSE;\r
+      }\r
+   }\r
+   \r
+   \r
+   if( lTrack->Pt() < fPtCut ) {\r
+     \r
+       return kFALSE;\r
+       \r
+   }\r
 \r
     if( lTrack->GetNcls(1) < fMinClsTPC ) {\r
 \r
@@ -380,6 +436,8 @@ Bool_t AliDalitzElectronCuts::TrackIsSelected(AliESDtrack* lTrack) {
     return kFALSE;\r
     }\r
 \r
+    if( hTrackDCAxyafter) hTrackDCAxyafter->Fill(dcaToVertexXY);\r
+    if( hTrackDCAzafter ) hTrackDCAzafter->Fill(dcaToVertexZ);\r
 \r
 \r
    return kTRUE;\r
@@ -638,6 +696,8 @@ Bool_t AliDalitzElectronCuts::InitializeCutsFromCutString(const TString analysis
    // Initialize Cuts from a given Cut string\r
 \r
 //   out<<"Set Cut Number: "<<analysisCutSelection.Data()<<endl;\r
+  AliInfo(Form("Set ElectronCuts Number: %s",analysisCutSelection.Data()));\r
+  \r
   if(analysisCutSelection.Length()!=kNCuts) {\r
        AliError(Form("Cut selection has the wrong length! size is %d, number of cuts is %d", analysisCutSelection.Length(), kNCuts));\r
        return kFALSE;\r
@@ -753,6 +813,21 @@ Bool_t AliDalitzElectronCuts::SetCut(cutIds cutID, const Int_t value) {
                        UpdateCutString(cutID, value);\r
                        return kTRUE;\r
                } else return kFALSE;\r
+  case kptCut:         \r
+               if( SetPtCut(value)) {\r
+                       fCuts[kptCut] = value;\r
+                       UpdateCutString(cutID, value);\r
+                       return kTRUE;\r
+               } else return kFALSE;\r
+    \r
+  case kDCACut:\r
+               if( SetDCACut(value)) {\r
+                       fCuts[kDCACut] = value;\r
+                       UpdateCutString(cutID, value);\r
+                       return kTRUE;\r
+               } else return kFALSE;\r
+             \r
+             \r
        case kPsiPair:\r
                if( SetPsiPairCut(value)) {\r
                        fCuts[kPsiPair] = value;\r
@@ -781,6 +856,13 @@ Bool_t AliDalitzElectronCuts::SetCut(cutIds cutID, const Int_t value) {
                        return kTRUE;\r
                } else return kFALSE;\r
                \r
+  case kmassCut:\r
+               if( SetMassCut(value)) {\r
+                       fCuts[kmassCut] = value;\r
+                       UpdateCutString(cutID, value);\r
+                       return kTRUE;\r
+               } else return kFALSE;\r
+               \r
   case kNCuts:\r
                cout << "Error:: Cut id out of range"<< endl;\r
                return kFALSE;\r
@@ -953,12 +1035,12 @@ Bool_t AliDalitzElectronCuts::SetTPCdEdxCutPionLine(Int_t pidedxSigmaCut)
                fPIDnSigmaAbovePionLineTPCHighPt=-10;\r
                break;\r
        case 7:\r
-               fPIDnSigmaAbovePionLineTPC=3.0; // We need a bit less tight cut on dE/dx\r
-               fPIDnSigmaAbovePionLineTPCHighPt=-10;\r
+               fPIDnSigmaAbovePionLineTPC = 2.0; // We need a bit less tight cut on dE/dx //Updated from 3.0 and -10 to +2.0 , +2.0 \r
+               fPIDnSigmaAbovePionLineTPCHighPt = 2.0;\r
                break;\r
        case 8:  // 1\r
-               fPIDnSigmaAbovePionLineTPC=3.5;\r
-               fPIDnSigmaAbovePionLineTPCHighPt=-10;\r
+               fPIDnSigmaAbovePionLineTPC = 1.5;   // Updated May-16-2013 from 3.5 and -10 to +1.5, +1\r
+               fPIDnSigmaAbovePionLineTPCHighPt = 1.0;\r
                break;\r
        case 9:  // 1\r
                fPIDnSigmaAbovePionLineTPC=1.5;\r
@@ -1088,21 +1170,35 @@ Bool_t AliDalitzElectronCuts::SetEtaCut(Int_t etaCut)
        switch(etaCut){\r
        case 0: \r
                fEtaCut = 100.;\r
+               fDoEtaCut = kFALSE;\r
                break;\r
        case 1: // 1.4\r
                fEtaCut = 1.4;\r
+               fDoEtaCut = kTRUE;\r
                break;\r
        case 2: // 1.2\r
                fEtaCut = 1.2;\r
+               fDoEtaCut = kTRUE;\r
                break;\r
        case 3: // 0.9\r
                fEtaCut = 0.9;\r
+               fDoEtaCut = kTRUE;\r
                break;\r
        case 4: // 0.8\r
                fEtaCut = 0.8;\r
+               fDoEtaCut = kTRUE;\r
                break;\r
        case 5: // 0.75\r
                fEtaCut = 0.75;\r
+               fDoEtaCut = kTRUE;\r
+               break;\r
+       case 6: //0.6\r
+               fEtaCut = 0.6; //changed from 0.4 to 0.6 2013.06.10\r
+               fDoEtaCut = kTRUE;\r
+               break;\r
+       case 7: //0.5\r
+               fEtaCut = 0.5; //changed from 0.3 to 0.5 2013.06.10\r
+               fDoEtaCut = kTRUE;\r
                break;\r
        default:\r
                cout<<"Warning: EtaCut not defined "<<etaCut<<endl;\r
@@ -1112,6 +1208,73 @@ Bool_t AliDalitzElectronCuts::SetEtaCut(Int_t etaCut)
 }\r
 \r
 ///________________________________________________________________________\r
+Bool_t AliDalitzElectronCuts::SetPtCut(Int_t ptCut)\r
+{ \r
+       // Set Pt Cut\r
+        //0.1GeV, 0.125 GeV, 0.15 GeV\r
+  \r
+       switch(ptCut){\r
+         \r
+       case 0: fPtCut = 0.075;         \r
+               break;\r
+       case 1:  // 0.1\r
+               fPtCut  = 0.1;  \r
+               break;\r
+       case 2:  // 0.125 GeV\r
+               fPtCut  = 0.125;                \r
+               break;\r
+       case 3: // 0.15 GeV\r
+               fPtCut  = 0.15;\r
+               break;\r
+       default:\r
+               cout<<"Warning: PtCut not defined "<<ptCut<<endl;\r
+               return kFALSE;\r
+       }\r
+       return kTRUE;\r
+}\r
+\r
+\r
+///________________________________________________________________________\r
+Bool_t AliDalitzElectronCuts::SetDCACut(Int_t dcaCut)\r
+{ \r
+  // Set DCA Cut\r
+  \r
+       if( !fesdTrackCuts ) {\r
+\r
+               cout<<"Warning: AliESDtrackCut is not initialized "<<endl;\r
+               return kFALSE;\r
+       }\r
+  \r
+       switch(dcaCut){\r
+         \r
+       case 0: \r
+               //Open cuts//\r
+               fesdTrackCuts->SetMaxDCAToVertexZ(1000);\r
+               fesdTrackCuts->SetMaxDCAToVertexXY(1000);\r
+               fesdTrackCuts->SetMaxChi2TPCConstrainedGlobal(36);\r
+               break;\r
+              \r
+       case 1: \r
+               fesdTrackCuts->SetMaxDCAToVertexXYPtDep("0.0182+0.0350/pt^1.01");\r
+               fesdTrackCuts->SetMaxChi2TPCConstrainedGlobal(36);\r
+               \r
+               break;\r
+       case 2: fesdTrackCuts->SetMaxDCAToVertexZ(2);\r
+               fesdTrackCuts->SetMaxDCAToVertexXY(1);\r
+               fesdTrackCuts->SetMaxChi2TPCConstrainedGlobal(36);\r
+               break; \r
+               \r
+       default:\r
+               cout<<"Warning: dcaCut not defined "<<dcaCut<<endl;\r
+               return kFALSE;\r
+       }\r
+       return kTRUE;\r
+}\r
+\r
+\r
+\r
+\r
+///________________________________________________________________________\r
 Bool_t AliDalitzElectronCuts::SetMaxMomPiondEdxTPCCut(Int_t piMaxMomdedxSigmaCut)\r
 {   // Set Cut\r
    switch(piMaxMomdedxSigmaCut){\r
@@ -1152,6 +1315,7 @@ Bool_t AliDalitzElectronCuts::SetLowPRejectionCuts(Int_t LowPRejectionSigmaCut)
                fPIDnSigmaAtLowPAroundKaonLine=0;\r
                fPIDnSigmaAtLowPAroundProtonLine=0;\r
                fPIDnSigmaAtLowPAroundPionLine=0;\r
+               fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLineTPC;\r
                break;\r
        case 1:  //\r
                fDoKaonRejectionLowP=kTRUE;\r
@@ -1160,14 +1324,16 @@ Bool_t AliDalitzElectronCuts::SetLowPRejectionCuts(Int_t LowPRejectionSigmaCut)
                fPIDnSigmaAtLowPAroundKaonLine=0.5;\r
                fPIDnSigmaAtLowPAroundProtonLine=0.5;\r
                fPIDnSigmaAtLowPAroundPionLine=0.5;\r
+               fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLineTPC;\r
                break;\r
        case 2:  //\r
                fDoKaonRejectionLowP=kTRUE;\r
                fDoProtonRejectionLowP=kTRUE;\r
                fDoPionRejectionLowP=kTRUE;\r
-               fPIDnSigmaAtLowPAroundKaonLine=1;\r
-               fPIDnSigmaAtLowPAroundProtonLine=1;\r
-               fPIDnSigmaAtLowPAroundPionLine=1;\r
+               fPIDnSigmaAtLowPAroundKaonLine=1.0;\r
+               fPIDnSigmaAtLowPAroundProtonLine=1.0;\r
+               fPIDnSigmaAtLowPAroundPionLine=1.0;\r
+               fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLineTPC;\r
                break;\r
        case 3:  //\r
                fDoKaonRejectionLowP=kTRUE;\r
@@ -1176,6 +1342,7 @@ Bool_t AliDalitzElectronCuts::SetLowPRejectionCuts(Int_t LowPRejectionSigmaCut)
                fPIDnSigmaAtLowPAroundKaonLine=1.5;\r
                fPIDnSigmaAtLowPAroundProtonLine=1.5;\r
                fPIDnSigmaAtLowPAroundPionLine=1.5;\r
+               fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLineTPC;\r
                break;\r
        case 4:  //\r
                fDoKaonRejectionLowP=kTRUE;\r
@@ -1184,6 +1351,7 @@ Bool_t AliDalitzElectronCuts::SetLowPRejectionCuts(Int_t LowPRejectionSigmaCut)
                fPIDnSigmaAtLowPAroundKaonLine=2.0;\r
                fPIDnSigmaAtLowPAroundProtonLine=2.0;\r
                fPIDnSigmaAtLowPAroundPionLine=2.0;\r
+               fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLineTPC;\r
                break;\r
        case 5:  //\r
                fDoKaonRejectionLowP=kTRUE;\r
@@ -1192,6 +1360,7 @@ Bool_t AliDalitzElectronCuts::SetLowPRejectionCuts(Int_t LowPRejectionSigmaCut)
                fPIDnSigmaAtLowPAroundKaonLine=2.0;\r
                fPIDnSigmaAtLowPAroundProtonLine=2.0;\r
                fPIDnSigmaAtLowPAroundPionLine=2.5;\r
+               fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLineTPC;\r
                break;\r
        case 6:  //\r
                fDoKaonRejectionLowP=kTRUE;\r
@@ -1200,6 +1369,7 @@ Bool_t AliDalitzElectronCuts::SetLowPRejectionCuts(Int_t LowPRejectionSigmaCut)
                fPIDnSigmaAtLowPAroundKaonLine=0.;\r
                fPIDnSigmaAtLowPAroundProtonLine=0.;\r
                fPIDnSigmaAtLowPAroundPionLine=2.;\r
+               fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLineTPC;\r
                break;\r
        case 7: //\r
                fDoKaonRejectionLowP=kFALSE;\r
@@ -1208,6 +1378,7 @@ Bool_t AliDalitzElectronCuts::SetLowPRejectionCuts(Int_t LowPRejectionSigmaCut)
                fPIDnSigmaAtLowPAroundKaonLine=0.0;\r
                fPIDnSigmaAtLowPAroundProtonLine=0.0;\r
                fPIDnSigmaAtLowPAroundPionLine=1.0;\r
+               fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLineTPC;\r
                break;\r
        case 8:\r
                fDoKaonRejectionLowP=kFALSE;\r
@@ -1216,6 +1387,7 @@ Bool_t AliDalitzElectronCuts::SetLowPRejectionCuts(Int_t LowPRejectionSigmaCut)
                fPIDnSigmaAtLowPAroundKaonLine=0.;\r
                fPIDnSigmaAtLowPAroundProtonLine=0.;\r
                fPIDnSigmaAtLowPAroundPionLine=0.5; \r
+               fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLineTPC;\r
                break;  \r
        default:\r
                cout<<"Warning: LowPRejectionSigmaCut not defined "<<LowPRejectionSigmaCut<<endl;\r
@@ -1408,6 +1580,37 @@ Bool_t AliDalitzElectronCuts::SetNumberOfRotations(Int_t NumberOfRotations)
     }\r
     return kTRUE;\r
 }\r
+\r
+\r
+\r
+///________________________________________________________________________\r
+Bool_t AliDalitzElectronCuts::SetMassCut(Int_t massCut)\r
+{   // Set Cut\r
+    switch(massCut){\r
+      \r
+    case 0:\r
+         fMassCut = 999.;\r
+         fDoMassCut = kFALSE;   \r
+        break;\r
+    case 1:\r
+         fMassCut = 0.135;      //GeV/c^2\r
+         fDoMassCut = kTRUE;\r
+        break; \r
+    case 2:\r
+         fMassCut = 0.100;    //GeV/c^2\r
+         fDoMassCut = kTRUE;\r
+         break;\r
+    case 3:\r
+         fMassCut = 0.075;    //GeV/c^2\r
+         fDoMassCut = kTRUE;\r
+         break;\r
+    default:\r
+        cout<<"Warning: MassCut not defined "<<massCut<<endl;\r
+        return kFALSE;\r
+    }\r
+    return kTRUE;\r
+}\r
+\r
 ///________________________________________________________________________\r
 TString AliDalitzElectronCuts::GetCutNumber(){\r
     // returns TString with current cut number\r
index 9806f7b..8bd98e2 100644 (file)
@@ -55,6 +55,9 @@ class AliDalitzElectronCuts : public AliAnalysisCuts {
         kRejectSharedElecGamma,
         kBackgroundScheme,
         kNumberOfRotations,
+        kptCut,
+        kDCACut,
+        kmassCut,
        kNCuts
   };
 
@@ -126,6 +129,9 @@ class AliDalitzElectronCuts : public AliAnalysisCuts {
   Bool_t SetITSClusterCut(Int_t clsITSCut);
   Bool_t SetTPCClusterCut(Int_t clsTPCCut);
   Bool_t SetEtaCut(Int_t etaCut);
+  Bool_t SetPtCut(Int_t ptCut);
+  Bool_t SetDCACut(Int_t dcaCut);
+  void SetEtaShift(Double_t etaShift){fEtaShift = etaShift;}
   Bool_t SetMinMomPiondEdxCut(Int_t piMinMomdedxSigmaCut);
   Bool_t SetMaxMomPiondEdxCut(Int_t piMaxMomdedxSigmaCut);
   Bool_t SetLowPRejectionCuts(Int_t LowPRejectionSigmaCut);
@@ -134,6 +140,7 @@ class AliDalitzElectronCuts : public AliAnalysisCuts {
   Bool_t SetRejectSharedElecGamma(Int_t RCut);
   Bool_t SetBackgroundScheme(Int_t BackgroundScheme);
   Bool_t SetNumberOfRotations(Int_t NumberOfRotations);
+  Bool_t SetMassCut(Int_t massCut);
   
   // Request Flags
 
@@ -144,6 +151,8 @@ class AliDalitzElectronCuts : public AliAnalysisCuts {
   Bool_t   UseTrackMultiplicity(){ return fUseTrackMultiplicityForBG;}
   Int_t    GetBKGMethod(){ return fBKGMethod; }
   Int_t    NumberOfRotationEvents(){return fnumberOfRotationEventsForBG;}
+  Bool_t   DoMassCut(){return  fDoMassCut;}
+  Double_t GetMassCut(){return fMassCut;}
   
 
   
@@ -154,6 +163,9 @@ class AliDalitzElectronCuts : public AliAnalysisCuts {
   AliESDtrackCuts *fesdTrackCuts;
 
   Double_t fEtaCut; //eta cutç
+  Double_t fEtaShift;
+  Bool_t   fDoEtaCut;
+  Double_t fPtCut;
   Double_t fRadiusCut; // radius cut
   Double_t fPsiPairCut;
   Double_t fDeltaPhiCutMin;
@@ -191,6 +203,8 @@ class AliDalitzElectronCuts : public AliAnalysisCuts {
   Bool_t   fUseTrackMultiplicityForBG; // use multiplicity
   Int_t    fBKGMethod;
   Int_t    fnumberOfRotationEventsForBG;
+  Bool_t   fDoMassCut;
+  Double_t fMassCut;
 
 
   // Histograms
@@ -205,6 +219,11 @@ class AliDalitzElectronCuts : public AliAnalysisCuts {
   TH2F *hTPCdEdxSignalafter; //TPC dEdx signal  after
   TH2F *hTOFbefore; // TOF after cuts
   TH2F *hTOFafter; // TOF after cuts
+  TH1F *hTrackDCAxybefore;
+  TH1F *hTrackDCAxyafter;
+  TH1F *hTrackDCAzbefore;
+  TH1F *hTrackDCAzafter;
+  
   
 
 private:
index cfda9e6..a1c123c 100644 (file)
@@ -73,6 +73,7 @@ AliV0ReaderV1::AliV0ReaderV1(const char *name) : AliAnalysisTaskSE(name),
     fCreateAOD(kFALSE),
     fDeltaAODBranchName("GammaConv"),
     fDeltaAODFilename("AliAODGammaConversion.root"),
+    fCheckAODConsistenty(kFALSE),
     fEventIsSelected(kFALSE),
     fPeriodName("")
 {
@@ -138,7 +139,6 @@ void AliV0ReaderV1::Init()
     if(fConversionCuts==NULL){
        if(fConversionCuts==NULL)AliError("No Cut Selection initialized");
     }
-
     if(fCreateAOD){kUseAODConversionPhoton=kTRUE;}
 
     if(fConversionGammas != NULL){
@@ -314,10 +314,36 @@ Bool_t AliV0ReaderV1::ProcessESDV0s()
 
            if(fCurrentMotherKFCandidate){
 
+               //Bool_t aodV0Found = kFALSE;
+               if(AODEvent() && fCheckAODConsistenty){
+                  // for(Int_t i = 0; i<AODEvent()->GetNumberOfV0s();i++){
+                  //    AliAODv0 *currebtAODV0 = AODEvent()->GetV0(i);
+                  //    cout<<currebtAODV0->GetID()<<endl;
+                  //    if(currebtAODV0->GetID() == currentV0Index)
+                  //       aodV0Found = kTRUE;
+                  // }
+                  // if(!aodV0Found)
+                  //    AliError(Form("AODV0 not Found belonging to ESDV0 %i",currentV0Index));
+                  
+                  
+                  if(!(fConversionCuts->GetTrack(AODEvent(),fCurrentMotherKFCandidate->GetTrackLabelPositive())) || !(fConversionCuts->GetTrack(AODEvent(),fCurrentMotherKFCandidate->GetTrackLabelNegative()))){
+                     fConversionGammas->Delete(); // Reset Gamma Array
+                     AliError(Form("AOD Tracks not found for current ESD V0!!! V0 index %i, posESDtrack %i negESDtrack %i, Run Number: %i, Period Number: %i, NTracks: ESD %i AOD %i",
+                                   currentV0Index,
+                                   fCurrentMotherKFCandidate->GetTrackLabelPositive(),fCurrentMotherKFCandidate->GetTrackLabelNegative(),
+                                   fInputEvent->GetRunNumber(),fInputEvent->GetPeriodNumber(),
+                                   fInputEvent->GetNumberOfTracks(),AODEvent()->GetNumberOfTracks()));
+                     return kTRUE;
+                  }
+               }
                // Add Gamma to the TClonesArray
 
                if(kUseAODConversionPhoton){
                    new((*fConversionGammas)[fConversionGammas->GetEntriesFast()]) AliAODConversionPhoton(fCurrentMotherKFCandidate);
+                               AliAODConversionPhoton * currentConversionPhoton = (AliAODConversionPhoton*)(fConversionGammas->At(fConversionGammas->GetEntriesFast()-1));
+                               currentConversionPhoton->SetMass(fCurrentMotherKFCandidate->M());
+                               currentConversionPhoton->SetMassToZero();
+                               
                }
                else{
                    new((*fConversionGammas)[fConversionGammas->GetEntriesFast()]) AliKFConversionPhoton(*fCurrentMotherKFCandidate);
@@ -385,11 +411,11 @@ AliKFConversionPhoton *AliV0ReaderV1::ReconstructV0(AliESDv0 *fCurrentV0,Int_t c
     // Reconstruct Gamma
 
     if(fUseConstructGamma){
-       fCurrentMotherKF = new AliKFConversionPhoton();
-       fCurrentMotherKF->ConstructGamma(fCurrentNegativeKFParticle,fCurrentPositiveKFParticle);
+                       fCurrentMotherKF = new AliKFConversionPhoton();
+                       fCurrentMotherKF->ConstructGamma(fCurrentNegativeKFParticle,fCurrentPositiveKFParticle);
     }else{
-       fCurrentMotherKF = new AliKFConversionPhoton(fCurrentNegativeKFParticle,fCurrentPositiveKFParticle);
-       fCurrentMotherKF->SetMassConstraint(0,0);
+                       fCurrentMotherKF = new AliKFConversionPhoton(fCurrentNegativeKFParticle,fCurrentPositiveKFParticle);
+                       fCurrentMotherKF->SetMassConstraint(0,0.0001);
     }
 
     // Set Track Labels
index 061e45b..4e8daeb 100644 (file)
@@ -60,6 +60,7 @@ class AliV0ReaderV1 : public AliAnalysisTaskSE {
   void SetCreateAODs(Bool_t k=kTRUE){fCreateAOD=k;}
   void SetDeltaAODFilename(TString s){fDeltaAODFilename=s;}
   void SetDeltaAODBranchName(TString string) { fDeltaAODBranchName = string;AliInfo(Form("Set DeltaAOD BranchName to: %s",fDeltaAODBranchName.Data()));}
+  void CheckAODConsistency(){fCheckAODConsistenty=kTRUE;}
   TString GetPeriodName(){return fPeriodName;}
   
 protected:
@@ -93,6 +94,7 @@ protected:
     Bool_t fCreateAOD; // set flag for AOD creation
     TString     fDeltaAODBranchName;// File where Gamma Conv AOD is located, if not in default AOD
     TString fDeltaAODFilename; // set filename for delta/satellite aod
+    Bool_t fCheckAODConsistenty;
     Bool_t fEventIsSelected;
     TString fPeriodName;
     
index b7dd698..c9e1097 100644 (file)
@@ -1,11 +1,10 @@
-AliAnalysisTask *AddTask_ConversionAODProduction(Int_t dataset=1){
+AliAnalysisTask *AddTask_ConversionAODProduction(Int_t dataset=0, Bool_t isMC = kFALSE){
 
    // Before doing anything, we load the needed library
     gSystem->Load("libPWGGAGammaConv.so");
     // dataset 0: pp
     // dataset 1: PbPb
-
-    Bool_t IsHeavyIon=(dataset==1);
+    // dataset 2: pPb
 
     //get the current analysis manager
     AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
@@ -14,18 +13,28 @@ AliAnalysisTask *AddTask_ConversionAODProduction(Int_t dataset=1){
       return 0;
     }
 
-  
+   //========= Add PID Reponse to ANALYSIS manager ====
+    if(!(AliPIDResponse*)mgr->GetTask("PIDResponseTask")){
+       gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPIDResponse.C");
+       AddTaskPIDResponse(isMC);
+    }
+    
     TString analysiscut;
+    TString analysiscutB;
 
-    if(IsHeavyIon){
+    if(dataset == 1){
      // Old cut string, no longer compatible with AliConversionCuts
      // analysiscut="900177009350113211200001000000000";
      // New cut string as of April 2013
-      analysiscut="1000000032091071001000000";
-    }
-    else{
-      // analysiscut="900397209450304221200000002000000";
-      analysiscut="0000000002084000002200000";
+       analysiscut= "1000000060084000001500000";
+       analysiscutB="1000000160084000001500000";
+    } else if (dataset == 2){
+       analysiscut= "8000000060084000001500000";
+       analysiscutB="8000000160084000001500000";
+    } else{
+      // analysiscut="
+       analysiscut ="0000000060084001001500000";
+       analysiscutB="0000000160084001001500000";
     }
 
     //========= Add V0 Reader to  ANALYSIS manager =====
@@ -33,14 +42,29 @@ AliAnalysisTask *AddTask_ConversionAODProduction(Int_t dataset=1){
     AliV0ReaderV1 *fV0Reader=new AliV0ReaderV1("ConvGammaAODProduction");
     fV0Reader->SetCreateAODs(kTRUE);
     fV0Reader->SetUseOwnXYZCalculation(kTRUE);
+    fV0Reader->SetUseAODConversionPhoton(kTRUE);
+    fV0Reader->CheckAODConsistency();
+
+    AliV0ReaderV1 *fV0ReaderB=new AliV0ReaderV1("ConvGammaAODProductionB");
+    fV0ReaderB->SetCreateAODs(kTRUE);
+    fV0ReaderB->SetUseOwnXYZCalculation(kTRUE);
+    fV0ReaderB->SetUseAODConversionPhoton(kTRUE);
+    fV0ReaderB->CheckAODConsistency();
+
     // Set AnalysisCut Number
     AliConversionCuts *fCuts= new AliConversionCuts(analysiscut.Data(),analysiscut.Data());
+    AliConversionCuts *fCutsB= new AliConversionCuts(analysiscutB.Data(),analysiscutB.Data());
     if(fCuts->InitializeCutsFromCutString(analysiscut.Data())){
       fV0Reader->SetConversionCuts(fCuts);
     }
     fV0Reader->Init();
-    mgr->AddTask(fV0Reader);
 
+    if(fCutsB->InitializeCutsFromCutString(analysiscutB.Data())){
+      fV0ReaderB->SetConversionCuts(fCutsB);
+    }
+    fV0ReaderB->Init();
+
+    
     AliLog::SetGlobalLogLevel(AliLog::kInfo);
 
     //================================================
@@ -52,7 +76,12 @@ AliAnalysisTask *AddTask_ConversionAODProduction(Int_t dataset=1){
 
     // connect input V0Reader
     fV0Reader->SelectCollisionCandidates(AliVEvent::kAny);
+    mgr->AddTask(fV0Reader);
     mgr->ConnectInput (fV0Reader,0,cinput);
 
+    fV0ReaderB->SelectCollisionCandidates(AliVEvent::kAny);
+    mgr->AddTask(fV0ReaderB);
+    mgr->ConnectInput (fV0ReaderB,0,cinput);
+
     return fV0Reader;
 }