]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWGGA/GammaConv/AliConvEventCuts.cxx
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / PWGGA / GammaConv / AliConvEventCuts.cxx
index f5f8a61344334e638c839fea8bde4509733d4594..fcaa66bb132038a75a7951ed5f3bdda65289029f 100644 (file)
@@ -132,8 +132,8 @@ AliConvEventCuts::AliConvEventCuts(const char *name,const char *title) :
        fCaloTriggerPatchInfoName(""),
        fTriggersEMCAL(0),
        fTriggersEMCALSelected(-1),
-       fEMCALTrigInitialized(kFALSE)
-       
+       fEMCALTrigInitialized(kFALSE),
+       fSecProdBoundary(1.0)
 {
    for(Int_t jj=0;jj<kNCuts;jj++){fCuts[jj]=0;}
    fCutString=new TObjString((GetCutNumber()).Data());
@@ -210,7 +210,8 @@ AliConvEventCuts::AliConvEventCuts(const AliConvEventCuts &ref) :
        fCaloTriggerPatchInfoName(ref.fCaloTriggerPatchInfoName),
        fTriggersEMCAL(ref.fTriggersEMCAL),
        fTriggersEMCALSelected(ref.fTriggersEMCALSelected),
-       fEMCALTrigInitialized(kFALSE)
+       fEMCALTrigInitialized(kFALSE),
+       fSecProdBoundary(ref.fSecProdBoundary)
 {
    // Copy Constructor
    for(Int_t jj=0;jj<kNCuts;jj++){fCuts[jj]=ref.fCuts[jj];}
@@ -1323,8 +1324,7 @@ Bool_t AliConvEventCuts::IsCentralitySelected(AliVEvent *event, AliVEvent *fMCEv
        if(!fIsHeavyIon)return kTRUE;
 
        if(fCentralityMin == fCentralityMax ) return kTRUE;//0-100%
-       else if(fCentralityMax==0) fCentralityMax=10; //CentralityRange = fCentralityMin-100%
-
+       else if ( fCentralityMax==0) fCentralityMax=10; //CentralityRange = fCentralityMin-10*multfactor
        Double_t centrality=GetCentrality(event);
        if(centrality<0)return kFALSE;
 
@@ -1349,7 +1349,7 @@ Bool_t AliConvEventCuts::IsCentralitySelected(AliVEvent *event, AliVEvent *fMCEv
        }
 
        Int_t nprimaryTracks = ((AliV0ReaderV1*)AliAnalysisManager::GetAnalysisManager()->GetTask(fV0ReaderName.Data()))->GetNumberOfPrimaryTracks();
-       Int_t PrimaryTracks10[10][2] =
+       Int_t PrimaryTracks10[11][2] =
                {
                        {9999,9999}, //  0
                        {1210, 928}, // 10
@@ -1360,9 +1360,10 @@ Bool_t AliConvEventCuts::IsCentralitySelected(AliVEvent *event, AliVEvent *fMCEv
                        { 106, 100}, // 60
                        {  51,  44}, // 70
                        {  21,  18}, // 80
-                       {   0,   0}  // 90
+                       {   0,   0},  // 90
+                       {   0,   0}  // 100 // only max accessible
                };
-       Int_t PrimaryTracks5a[10][2] =
+       Int_t PrimaryTracks5a[11][2] =
                {
                        {9999,9999}, // 0
                        {1485,1168}, // 5
@@ -1373,9 +1374,10 @@ Bool_t AliConvEventCuts::IsCentralitySelected(AliVEvent *event, AliVEvent *fMCEv
                        { 536, 435}, // 30
                        { 428, 350}, // 35
                        { 337, 276}, // 40
-                       { 260, 214}  // 45
+                       { 260, 214},  // 45
+                       { 0, 162}  // 50 only max accessible
                };
-       Int_t PrimaryTracks5b[10][2] =
+       Int_t PrimaryTracks5b[11][2] =
                {
                        { 260, 214}, // 45
                        { 197, 162}, // 50
@@ -1386,7 +1388,8 @@ Bool_t AliConvEventCuts::IsCentralitySelected(AliVEvent *event, AliVEvent *fMCEv
                        {  34,  29}, // 75
                        {  21,  18}, // 80
                        {  13,  11}, // 85
-                       {   0,   0}  // 90
+                       {   0,   0},  // 90
+                       {   0,   0}  // 100 only max accessible
                };
        Int_t column = 0;
        if(event->IsA()==AliESDEvent::Class()) column = 0;
@@ -1710,7 +1713,6 @@ void AliConvEventCuts::GetNotRejectedParticles(Int_t rejection, TList *HeaderLis
 
        TString periodName = ((AliV0ReaderV1*)AliAnalysisManager::GetAnalysisManager()->GetTask(fV0ReaderName.Data()))->GetPeriodName();
 
-
        if(fNotRejectedStart){
                delete[] fNotRejectedStart;
                fNotRejectedStart = NULL;
@@ -1732,18 +1734,19 @@ void AliConvEventCuts::GetNotRejectedParticles(Int_t rejection, TList *HeaderLis
        AliStack *fMCStack = 0x0;
        TClonesArray *fMCStackAOD = 0x0;
        if(MCEvent->IsA()==AliMCEvent::Class()){
-               cHeader = dynamic_cast<AliGenCocktailEventHeader*>(dynamic_cast<AliMCEvent*>(MCEvent)->GenEventHeader());
-               if(cHeader) headerFound = kTRUE;
-               if(dynamic_cast<AliMCEvent*>(MCEvent))fMCStack = dynamic_cast<AliStack*>(dynamic_cast<AliMCEvent*>(MCEvent)->Stack());
+               if(dynamic_cast<AliMCEvent*>(MCEvent)){
+                       cHeader = dynamic_cast<AliGenCocktailEventHeader*>(dynamic_cast<AliMCEvent*>(MCEvent)->GenEventHeader());
+                       if(cHeader) headerFound = kTRUE;
+                       fMCStack = dynamic_cast<AliStack*>(dynamic_cast<AliMCEvent*>(MCEvent)->Stack());
+               }       
        }
        if(MCEvent->IsA()==AliAODEvent::Class()){ // MCEvent is a AODEvent in case of AOD
                cHeaderAOD = dynamic_cast<AliAODMCHeader*>(MCEvent->FindListObject(AliAODMCHeader::StdBranchName()));
                fMCStackAOD = dynamic_cast<TClonesArray*>(MCEvent->FindListObject(AliAODMCParticle::StdBranchName()));
-               
-               
                if(cHeaderAOD) headerFound = kTRUE;
        }
 
+//     cout << "event starts here" << endl;
        if(headerFound){
                TList *genHeaders = 0x0;
                if(cHeader) genHeaders = cHeader->GetHeaders();
@@ -1772,25 +1775,26 @@ void AliConvEventCuts::GetNotRejectedParticles(Int_t rejection, TList *HeaderLis
 //                                             cout << "accepted" << endl;
                                                if (GeneratorInList.CompareTo("PARAM") == 0 || GeneratorInList.CompareTo("BOX") == 0 ){
                                                        if(fMCStack){
-                                                               if (fMCStack->Particle(firstindexA)->GetPdgCode() == fAddedSignalPDGCode ) {
-                                                                       if (periodName.CompareTo("LHC14a1b")==0 || periodName.CompareTo("LHC14a1c")==0 ){
+                                                               if (periodName.CompareTo("LHC14a1b")==0 || periodName.CompareTo("LHC14a1c")==0 ){
+                                                                       if (fMCStack->Particle(firstindexA)->GetPdgCode() == fAddedSignalPDGCode ) {    
                                                                                if (gh->NProduced() > 10 && fMCStack->Particle(firstindexA+10)->GetPdgCode() == fAddedSignalPDGCode ){
 //                                                                                     cout << "cond 1: "<< fnHeaders << endl;
                                                                                        fnHeaders++;
                                                                                        continue;
                                                                                }       
                                                                                continue;
-                                                                       } else {
-//                                                                             cout << "cond 2: " << fnHeaders << endl;
-                                                                               fnHeaders++;
-                                                                               continue;
                                                                        }       
+                                                               } else {
+//                                                                     cout << "cond 2: " << fnHeaders << endl;
+                                                                       fnHeaders++;
+                                                                       continue;
+                                                                       
                                                                }
                                                        }   
                                                        if ( fMCStackAOD){
                                                                AliAODMCParticle *aodMCParticle = static_cast<AliAODMCParticle*>(fMCStackAOD->At(firstindexA));
-                                                               if (  aodMCParticle->GetPdgCode() == fAddedSignalPDGCode ){
-                                                                       if (periodName.CompareTo("LHC14a1b")==0 || periodName.CompareTo("LHC14a1c")==0 ){
+                                                               if (periodName.CompareTo("LHC14a1b")==0 || periodName.CompareTo("LHC14a1c")==0 ){
+                                                                       if (  aodMCParticle->GetPdgCode() == fAddedSignalPDGCode ){
                                                                                if (gh->NProduced() > 10){
                                                                                        AliAODMCParticle *aodMCParticle2 = static_cast<AliAODMCParticle*>(fMCStackAOD->At(firstindexA+10));
                                                                                        if (  aodMCParticle2->GetPdgCode() == fAddedSignalPDGCode ){
@@ -1800,11 +1804,11 @@ void AliConvEventCuts::GetNotRejectedParticles(Int_t rejection, TList *HeaderLis
                                                                                        } 
                                                                                }       
                                                                                continue;
-                                                                       } else {
-//                                                                             cout << "cond 2: " << fnHeaders << endl;
-                                                                               fnHeaders++;
-                                                                               continue;
-                                                                       }       
+                                                                       }
+                                                               } else {
+//                                                                     cout << "cond 2: " << fnHeaders << endl;
+                                                                       fnHeaders++;
+                                                                       continue;
                                                                }   
                                                        }
                                                        continue;
@@ -1844,9 +1848,9 @@ void AliConvEventCuts::GetNotRejectedParticles(Int_t rejection, TList *HeaderLis
                                if(GeneratorName.CompareTo(GeneratorInList) == 0){
                                        if (GeneratorInList.CompareTo("PARAM") == 0 || GeneratorInList.CompareTo("BOX") == 0 ){
                                                if(fMCStack){
-                                                       if (fMCStack->Particle(firstindex)->GetPdgCode() == fAddedSignalPDGCode ) {
-                                                               if (periodName.CompareTo("LHC14a1b")==0 || periodName.CompareTo("LHC14a1c")==0 ){
-//                                                                     cout << "produced " << gh->NProduced() << " with box generator" << endl;
+                                                       if (periodName.CompareTo("LHC14a1b")==0 || periodName.CompareTo("LHC14a1c")==0 ){
+                                                               if (fMCStack->Particle(firstindex)->GetPdgCode() == fAddedSignalPDGCode ) {
+                                                                       cout << "produced " << gh->NProduced() << " with box generator" << endl;
                                                                        if (gh->NProduced() > 10 && fMCStack->Particle(firstindex+10)->GetPdgCode() == fAddedSignalPDGCode){
 //                                                                             cout << "one of them was a pi0 or eta" <<  endl;
                                                                                fNotRejectedStart[number] = firstindex;
@@ -1856,19 +1860,19 @@ void AliConvEventCuts::GetNotRejectedParticles(Int_t rejection, TList *HeaderLis
 //                                                                             cout << "Number of particles produced for: " << i << "\t" << GeneratorName.Data() << "\t" << lastindex-firstindex+1 << endl;
                                                                                continue;
                                                                        }       
-                                                               } else {
-                                                                       fNotRejectedStart[number] = firstindex;
-                                                                       fNotRejectedEnd[number] = lastindex;
-                                                                       fGeneratorNames[number] = GeneratorName;
-                                                                       number++;
-                                                                       continue;
                                                                }       
+                                                       } else {
+                                                               fNotRejectedStart[number] = firstindex;
+                                                               fNotRejectedEnd[number] = lastindex;
+                                                               fGeneratorNames[number] = GeneratorName;
+                                                               number++;
+                                                               continue;       
                                                        }
                                                }   
                                                if ( fMCStackAOD){
                                                        AliAODMCParticle *aodMCParticle = static_cast<AliAODMCParticle*>(fMCStackAOD->At(firstindex));
-                                                       if (  aodMCParticle->GetPdgCode() == fAddedSignalPDGCode ){
-                                                               if (periodName.CompareTo("LHC14a1b")==0 || periodName.CompareTo("LHC14a1c")==0 ){
+                                                       if (periodName.CompareTo("LHC14a1b")==0 || periodName.CompareTo("LHC14a1c")==0 ){
+                                                               if (  aodMCParticle->GetPdgCode() == fAddedSignalPDGCode ){
                                                                        if (gh->NProduced() > 10) {
                                                                                AliAODMCParticle *aodMCParticle2 = static_cast<AliAODMCParticle*>(fMCStackAOD->At(firstindex+10));
                                                                                if ( aodMCParticle2->GetPdgCode() == fAddedSignalPDGCode ){
@@ -1876,16 +1880,16 @@ void AliConvEventCuts::GetNotRejectedParticles(Int_t rejection, TList *HeaderLis
                                                                                        fNotRejectedStart[number] = firstindex;
                                                                                        fGeneratorNames[number] = GeneratorName;
                                                                                        number++;
-                                                                       } 
-                                                                                       continue;
-                                                                               }
-                                                               } else {
-                                                                       fNotRejectedStart[number] = firstindex;
-                                                                       fNotRejectedEnd[number] = lastindex;
-                                                                       fGeneratorNames[number] = GeneratorName;
-                                                                       number++;
-                                                                       continue;       
-                                                               }       
+                                                                               
+                                                                               continue;
+                                                                       }
+                                                               } 
+                                                       } else {
+                                                               fNotRejectedStart[number] = firstindex;
+                                                               fNotRejectedEnd[number] = lastindex;
+                                                               fGeneratorNames[number] = GeneratorName;
+                                                               number++;
+                                                               continue;       
                                                        }   
                                                }
                                                continue;
@@ -1915,14 +1919,6 @@ void AliConvEventCuts::GetNotRejectedParticles(Int_t rejection, TList *HeaderLis
                fNotRejectedEnd[0] = static_cast<AliMCEvent*>(MCEvent)->Stack()->GetNprimary()-1;
                fGeneratorNames = new TString[1];
                fGeneratorNames[0] = "NoCocktailGeneratorFound";
-
-               AliGenPythiaEventHeader *mcHeaderPythia = dynamic_cast<AliGenPythiaEventHeader*>(static_cast<AliMCEvent*>(MCEvent)->GenEventHeader());
-               if (mcHeaderPythia) fGeneratorNames[0] = "NoCocktailGeneratorFound_Pythia";
-               AliGenDPMjetEventHeader *mcHeaderPhojet = dynamic_cast<AliGenDPMjetEventHeader*>(static_cast<AliMCEvent*>(MCEvent)->GenEventHeader());
-               if (mcHeaderPhojet) fGeneratorNames[0] = "NoCocktailGeneratorFound_Phojet";
-               AliGenHijingEventHeader *mcHeaderHijing = dynamic_cast<AliGenHijingEventHeader*>(static_cast<AliMCEvent*>(MCEvent)->GenEventHeader());
-               if (mcHeaderHijing) fGeneratorNames[0] = "NoCocktailGeneratorFound_Hijing";
-
                SetRejectExtraSignalsCut(0);
        }
        
@@ -1931,17 +1927,8 @@ void AliConvEventCuts::GetNotRejectedParticles(Int_t rejection, TList *HeaderLis
 //_________________________________________________________________________
 Int_t AliConvEventCuts::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
 
-//     if (index == 100){
-//             cout << "possible headers" << endl;
-//             for(Int_t i = 0;i<fnHeaders;i++){
-//                     cout << i << "\t" <<fGeneratorNames[i] << "\t" << fNotRejectedStart[i] << "\t" <<fNotRejectedEnd[i] << endl;
-//             }
-//     }       
        Int_t accepted = 0;
        if(!InputEvent || InputEvent->IsA()==AliESDEvent::Class()){
                if( index >= MCStack->GetNprimary()){ // Secondary Particle
@@ -2063,41 +2050,21 @@ Int_t AliConvEventCuts::IsEventAcceptedByCut(AliConvEventCuts *ReaderCuts, AliVE
 
 //_________________________________________________________________________
 Float_t AliConvEventCuts::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.Contains("LHC13d2")|| period.Contains("LHC14a1") || 
-       period.CompareTo("LHC13e7") == 0 || period.Contains("LHC13b2_efix") || period.CompareTo("LHC14b2") == 0 )) return 1.;
-
+       if (!( period.Contains("LHC13d2")                       || period.Contains("LHC14a1")                                   || period.CompareTo("LHC13e7") == 0             || period.Contains("LHC13b2_efix")              ||
+                  period.CompareTo("LHC14b2") == 0     || period.Contains("LHC14e2")                                   || period.CompareTo("LHC12f1a") == 0            || period.CompareTo("LHC12f1b") == 0    || 
+                  period.CompareTo("LHC12i3") == 0)) return 1.;
        Int_t kCaseGen = 0;
        for (Int_t i = 0; i < fnHeaders; i++){
                if (index >= fNotRejectedStart[i] && index < fNotRejectedEnd[i]+1){
-                       if (fGeneratorNames[i].CompareTo("Pythia") == 0){
+                       if (period.Contains("LHC13d2")          || period.CompareTo("LHC13e7") == 0                     || period.Contains("LHC13b2_efix")              || period.Contains("LHC14a1")                   ||
+                               period.CompareTo("LHC14b2") == 0 || period.Contains("LHC14e2")                                  || period.CompareTo("LHC12f1a") == 0            || period.CompareTo("LHC12f1b") == 0    || 
+                               period.CompareTo("LHC12i3") == 0){
                                kCaseGen = 1;
-                       } else if (fGeneratorNames[i].CompareTo("DPMJET") == 0){
-                               kCaseGen = 2;
-                       } 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;
-                       } else if (fGeneratorNames[i].CompareTo("PARAM") == 0){
-                               kCaseGen = 5;
-                       } else if (fGeneratorNames[i].CompareTo("NoCocktailGeneratorFound") == 0){
-                               kCaseGen = 6;
-                       } else if (fGeneratorNames[i].CompareTo("NoCocktailGeneratorFound_Pythia") == 0){
-                               kCaseGen = 1;
-                       } else if (fGeneratorNames[i].CompareTo("NoCocktailGeneratorFound_Phojet") == 0){
-                               kCaseGen = 2;
-                       } else if (fGeneratorNames[i].CompareTo("NoCocktailGeneratorFound_Hijing") == 0){
-                               kCaseGen = 3;
-                       }
-                       if (period.Contains("LHC13d2") || period.CompareTo("LHC13e7") == 0 || period.Contains("LHC13b2_efix")  || period.Contains("LHC14a1") || period.CompareTo("LHC14b2") == 0 ){
-                               kCaseGen = 3;
                        }
                }
        }
        if (kCaseGen == 0) return 1;
 
-
        Double_t mesonPt = 0;
        Double_t mesonMass = 0;
        Int_t PDGCode = 0;
@@ -2105,8 +2072,7 @@ Float_t AliConvEventCuts::GetWeightForMeson(TString period, Int_t index, AliStac
                mesonPt = ((TParticle*)MCStack->Particle(index))->Pt();
                mesonMass = ((TParticle*)MCStack->Particle(index))->GetCalcMass();
                PDGCode = ((TParticle*)MCStack->Particle(index))->GetPdgCode();
-       }
-       else if(InputEvent->IsA()==AliAODEvent::Class()){
+       } else if(InputEvent->IsA()==AliAODEvent::Class()){
                TClonesArray *AODMCTrackArray = dynamic_cast<TClonesArray*>(InputEvent->FindListObject(AliAODMCParticle::StdBranchName()));
                if (AODMCTrackArray){
                        AliAODMCParticle *aodMCParticle = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(index));
@@ -2119,95 +2085,25 @@ Float_t AliConvEventCuts::GetWeightForMeson(TString period, Int_t index, AliStac
        }
 
        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 ( PDGCode ==  111){
-                       dNdyMC = 2.1462;
-                       nMC = 7.06055;
-                       tMC = 0.12533;
-               } else if ( PDGCode ==  221){
-                       dNdyMC = 0.2357;
-                       nMC = 5.9105;
-                       tMC = 0.1525;
-               }
-               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 ( PDGCode ==  111){
-                       dNdyMC = 2.35978;
-                       nMC = 6.81795;
-                       tMC = 0.11492;
-               } else if ( PDGCode ==  221){
-                       dNdyMC = 0.3690;
-                       nMC = 5.55809;
-                       tMC = 0.13387;
-               }
-               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 ( PDGCode ==  111){
-                       a = 0.23437;
-                       b = 5.6661;
-                       c = -1430.5863;
-                       d = -0.6966624;
-                       e = 252.3742;
-               } else if ( PDGCode ==  221){
-                       a = 0.10399;
-                       b = 4.35311;
-                       c = -12.17723;
-                       d = -0.01172;
-                       e =1.85140;
-               }
-               functionResultMC = a*TMath::Power(mesonPt,-1.*(b+c/(TMath::Power(mesonPt,d)+e)))*1./mesonPt *1./1.6 *1./(2.* TMath::Pi());
-       //       cout << functionResultMC << endl;
-       } else if (kCaseGen == 3 ){ // HIJING
-               if ( PDGCode ==  111 && fDoReweightHistoMCPi0 && hReweightMCHistPi0!= 0x0){
-                       functionResultMC = hReweightMCHistPi0->Interpolate(mesonPt);
-               }
-               if ( PDGCode ==  221 && fDoReweightHistoMCEta && hReweightMCHistEta!= 0x0){
-                       functionResultMC = hReweightMCHistEta->Interpolate(mesonPt);
-               }
-               if ( PDGCode ==  310 && fDoReweightHistoMCK0s && hReweightMCHistK0s!= 0x0){
-                       functionResultMC = hReweightMCHistK0s->Interpolate(mesonPt);
-               }
+       if ( PDGCode ==  111 && fDoReweightHistoMCPi0 && hReweightMCHistPi0!= 0x0){
+               functionResultMC = hReweightMCHistPi0->Interpolate(mesonPt);
+       }
+       if ( PDGCode ==  221 && fDoReweightHistoMCEta && hReweightMCHistEta!= 0x0){
+               functionResultMC = hReweightMCHistEta->Interpolate(mesonPt);
+       }
+       if ( PDGCode ==  310 && fDoReweightHistoMCK0s && hReweightMCHistK0s!= 0x0){
+               functionResultMC = hReweightMCHistK0s->Interpolate(mesonPt);
        }
 
        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 ( PDGCode ==  221){
-                       dNdyData = 0.38992; //be careful this fit is not optimal, eta in data still has problems
-                       nData = 5.72778;
-                       tData = 0.13835;
-               }
-               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);
-       //       cout << functionResultData << endl;
-       } else {
-               if ( PDGCode ==  111 && fDoReweightHistoMCPi0 && fFitDataPi0!= 0x0){
-                       functionResultData = fFitDataPi0->Eval(mesonPt);
-               }
-               if ( PDGCode ==  221 && fDoReweightHistoMCEta && fFitDataEta!= 0x0){
-                       functionResultData = fFitDataEta->Eval(mesonPt);
-               }
-               if ( PDGCode ==  310 && fDoReweightHistoMCK0s && fFitDataK0s!= 0x0){
-                       functionResultData = fFitDataK0s->Eval(mesonPt);
-               }
-
+       if ( PDGCode ==  111 && fDoReweightHistoMCPi0 && fFitDataPi0!= 0x0){
+               functionResultData = fFitDataPi0->Eval(mesonPt);
+       }
+       if ( PDGCode ==  221 && fDoReweightHistoMCEta && fFitDataEta!= 0x0){
+               functionResultData = fFitDataEta->Eval(mesonPt);
+       }
+       if ( PDGCode ==  310 && fDoReweightHistoMCK0s && fFitDataK0s!= 0x0){
+               functionResultData = fFitDataK0s->Eval(mesonPt);
        }
 
        Double_t weight = 1;
@@ -2230,12 +2126,8 @@ Float_t AliConvEventCuts::GetWeightForMeson(TString period, Int_t index, AliStac
                        if (!isfinite(weight)) weight = 1.;
                }
        } else if (PDGCode ==  310 && functionResultMC != 0 && isfinite(functionResultMC)){
-                       weight = 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;
 }
 
@@ -2474,3 +2366,97 @@ TClonesArray *AliConvEventCuts::GetArrayFromEvent(AliVEvent* fInputEvent, const
        }
        return arr;
 }
+
+//_________________________________________________________________________
+Bool_t AliConvEventCuts::IsConversionPrimaryESD( AliStack *MCStack, Int_t stackpos, Double_t prodVtxX, Double_t prodVtxY, Double_t prodVtxZ){
+       
+       TParticle* particle = (TParticle *)MCStack->Particle(stackpos);
+       if (!particle) return kFALSE; 
+       if (particle->GetMother(0) != -1){
+               Double_t deltaX = particle->Vx() - prodVtxX;
+               Double_t deltaY = particle->Vy() - prodVtxY;
+               Double_t deltaZ = particle->Vz() - prodVtxZ;
+
+               Double_t realRadius2D = TMath::Sqrt(deltaX*deltaX+deltaY*deltaY);
+               Double_t realRadius3D = TMath::Sqrt(deltaX*deltaX+deltaY*deltaY+deltaZ*deltaZ);
+               
+
+               Bool_t dalitzCand = kFALSE;
+               
+               TParticle* firstmother = (TParticle *)MCStack->Particle(particle->GetMother(0));
+               Int_t pdgCodeFirstMother                = firstmother->GetPdgCode();                    
+               Bool_t intDecay = kFALSE;
+               if ( pdgCodeFirstMother == 111 || pdgCodeFirstMother == 221 ) intDecay = kTRUE;
+               if ( intDecay && abs(particle->GetPdgCode()) == 11 ){
+                       dalitzCand = kTRUE;
+//                     cout << "dalitz candidate found" << endl;
+               }
+       
+               Int_t source = particle->GetMother(0);
+               Bool_t foundExcludedPart = kFALSE;
+               Bool_t foundShower = kFALSE;            
+               Int_t pdgCodeMotherPrev = 0;
+               Int_t pdgCodeMotherPPrevMother = 0;
+               Int_t depth = 0;
+               if (dalitzCand || realRadius3D < fSecProdBoundary ){
+//                     if (particle->GetPdgCode() == 22){
+//                             cout << endl << endl << "new particle: " << stackpos <<endl;
+//                             cout << particle->GetPdgCode() << "\t" << particle->R() << "\t" << realRadius2D << "\t" << realRadius3D << endl;
+//                     }
+                       while (depth < 20){
+                               TParticle* mother       = (TParticle *)MCStack->Particle(source);
+                               source                          = mother->GetMother(0); 
+//                             if (particle->GetPdgCode() == 22)cout << "Stackposition: "<< source << endl;
+                               Int_t pdgCodeMother             = mother->GetPdgCode();                 
+//                             if (particle->GetPdgCode() == 22)cout << "Previous mothers: " << pdgCodeMother << "\t"<< pdgCodeMotherPrev<< "\t" << pdgCodeMotherPPrevMother << endl;
+                               if (pdgCodeMother == pdgCodeMotherPrev && pdgCodeMother == pdgCodeMotherPPrevMother) depth = 20;
+                               if (abs(pdgCodeMother) == 11 && abs(pdgCodeMotherPrev) == 22 && abs(pdgCodeMotherPPrevMother) == 11 ){
+                                       foundShower = kTRUE;
+                                       depth =20;
+                               }       
+                               if (abs(pdgCodeMother) == 22 && abs(pdgCodeMotherPrev) == 11 && abs(pdgCodeMotherPPrevMother) == 22 ){
+                                       foundShower = kTRUE;
+                                       depth =20;
+                               }
+                               
+                               // particles to be excluded:
+                               // K0s          - 310  
+                               // K0l          - 130
+                               // K+/-         - 321
+                               // Lambda       - 3122
+                               // Sigma0       - 3212
+                               // Sigma+/-     - 3222, 3112
+                               // Cascades     - 3322, 3312    
+                               if (abs(pdgCodeMother) == 310   || abs(pdgCodeMother) == 130    || abs(pdgCodeMother) == 321  ||
+                                       abs(pdgCodeMother) == 3122      || abs(pdgCodeMother) == 3212   || abs(pdgCodeMother) == 3222 ||
+                                       abs(pdgCodeMother) == 3112      || abs(pdgCodeMother) == 3322   || abs(pdgCodeMother) == 3312 
+                               ) {
+                                       foundExcludedPart = kTRUE;
+                               }       
+//                             if (particle->GetPdgCode() == 22)cout << mother->GetPdgCode() << "\t" <<  source << "\t" << foundExcludedPart<< endl;
+                               pdgCodeMotherPPrevMother = pdgCodeMotherPrev;
+                               pdgCodeMotherPrev = pdgCodeMother;                      
+                               if (source == -1) depth = 20;
+                               
+//                             if (particle->GetPdgCode() == 22)cout << depth << endl;
+                               depth++;
+                       }       
+               }       
+               if (foundExcludedPart){
+//                     if (particle->GetPdgCode() == 22)cout << "This is definitely a secondary, manually excluded" << endl;
+                       return kFALSE;
+               } else if (dalitzCand){
+//                     if (particle->GetPdgCode() == 22)cout << "This was a decay via a virtual photon" << endl;
+                       return kTRUE;
+               } else if (foundShower){
+//                     if (particle->GetPdgCode() == 22)cout << "This is a shower" << endl;
+                       return kFALSE;                  
+               } else if (realRadius3D > fSecProdBoundary){
+//                     cout << "This is a secondary, to large production radius" << endl;
+                       return kFALSE;                  
+               }
+       }
+
+       return kTRUE;
+}      
+