]> 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 33079d02aafc9a3671f0610ff76186abefc1612c..fcaa66bb132038a75a7951ed5f3bdda65289029f 100644 (file)
@@ -45,6 +45,7 @@
 #include "AliGenHijingEventHeader.h"
 #include "AliTriggerAnalysis.h"
 #include "AliV0ReaderV1.h"
+#include "AliVCaloCells.h"
 #include "AliAODMCParticle.h"
 #include "AliAODMCHeader.h"
 
@@ -131,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());
@@ -209,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];}
@@ -665,14 +667,18 @@ void AliConvEventCuts::PrintCutsWithValues() {
        if (fIsHeavyIon == 0) {
                printf("Running in pp mode \n");
                if (fSpecialTrigger == 0){
-                       printf("\t only events triggered by V0OR will be analysed \n");
+                       if (fSpecialSubTrigger == 0){
+                               printf("\t only events triggered by V0OR will be analysed \n");
+                       } else if (fSpecialSubTrigger == 1){
+                               printf("\t only events where SDD was present will be analysed \n");
+                       }
                } else if (fSpecialTrigger == 1){
-                       printf("\t only events triggered by V0AND will be analysed \n");
-               } else if (fSpecialTrigger == 2){
-                       printf("\t only events where SDD was present will be analysed \n");
-               } else if (fSpecialTrigger == 3){
-                       printf("\t only events where SDD was present will be analysed and triggered by VOAND\n");
-               } else if (fSpecialTrigger > 3){ 
+                       if (fSpecialSubTrigger == 0){
+                               printf("\t only events triggered by V0AND will be analysed \n");
+                       } else if(fSpecialSubTrigger == 1){
+                               printf("\t only events where SDD was present will be analysed and triggered by VOAND\n");
+                       }    
+               } else if (fSpecialTrigger > 1){ 
                        printf("\t only events triggered by %s %s\n", fSpecialTriggerName.Data(), fSpecialSubTriggerName.Data());
                }
        } else if (fIsHeavyIon == 1){ 
@@ -697,8 +703,10 @@ void AliConvEventCuts::PrintCutsWithValues() {
                }
                if (fSpecialTrigger == 0){
                        printf("\t only events triggered by kMB, kCentral, kSemiCentral will be analysed \n");
-               } else if (fSpecialTrigger > 4){   
+               } else if (fSpecialTrigger > 1){
                        printf("\t only events triggered by %s %s\n", fSpecialTriggerName.Data(), fSpecialSubTriggerName.Data());
+                       printf("\n\t        SpecialTrigger is:  %s\n", fSpecialTriggerName.Data());
+                       printf("\t        SpecialSubTrigger is: %s\n\n", fSpecialSubTriggerName.Data());
                }
        } else if (fIsHeavyIon == 2){
                printf("Running in pPb mode \n");
@@ -712,7 +720,7 @@ void AliConvEventCuts::PrintCutsWithValues() {
                }
                if (fSpecialTrigger == 0){
                        printf("\t only events triggered by kINT7 will be analysed \n");
-               } else if (fSpecialTrigger > 4){   
+               } else if (fSpecialTrigger > 1){ 
                        printf("\t only events triggered by %s %s\n", fSpecialTriggerName.Data(), fSpecialSubTriggerName.Data());
                }
        }
@@ -810,18 +818,18 @@ Bool_t AliConvEventCuts::SetSelectSpecialTrigger(Int_t selectSpecialTrigger)
 
        switch(selectSpecialTrigger){
        case 0:
-               fSpecialTrigger=0; // dont care
+               fSpecialTrigger=0; // V0OR
                break;
        case 1:
                fSpecialTrigger=1; // V0AND
                break;
-       case 2:
-               fSpecialTrigger=2; // with SDD requested
-               break;
-       case 3:
-               fSpecialTrigger=3; // V0AND plus with SDD requested
+//     case 2:
+//             fSpecialTrigger=2; // 
+//             break;
+       case 3:       
+               fSpecialTrigger=3; //specific centrality trigger selection
+               fSpecialTriggerName="AliVEvent::kCentral/kSemiCentral/kMB";
                break;
-       // allows to run MB & 6 other different trigger classes in parallel with the same photon cut
        case 4:
                fSpecialTrigger=4; // trigger alias kTRD 
                fOfflineTriggerMask=AliVEvent::kTRD;
@@ -875,13 +883,30 @@ Bool_t AliConvEventCuts::SetSelectSpecialTrigger(Int_t selectSpecialTrigger)
 Bool_t AliConvEventCuts::SetSelectSubTriggerClass(Int_t selectSpecialSubTriggerClass)
 {// Set Cut
 
-       if (fSpecialTrigger == 1){ //V0AND with different detectors
+       if (fSpecialTrigger == 0){ //OR 
                switch(selectSpecialSubTriggerClass){
-               case 0: //with VZERO
-                       fSpecialTrigger=1;
+               case 0://with VZERO
+                       fSpecialTrigger=0;
                        fSpecialSubTrigger=0; 
 //                     AliInfo("Info: Nothing to be done");
+                       break;  
+               case 3: //V0OR with SDD requested (will only work with LHC11a dataset)
+                       fSpecialSubTrigger=1; 
+                       cout << "V0OR with SDD requested" << endl;          
                        break;
+               default:
+                       AliError("Warning: Special Subtrigger Class Not known");
+                       return 0;
+               }       
+       } else if (fSpecialTrigger == 1){ //AND with different detectors
+               switch(selectSpecialSubTriggerClass){
+               case 0: //with VZERO general implementation of V0AND (periods LHC11c onwards)
+                       fSpecialTrigger=0;
+                       fSpecialSubTrigger=0; 
+                       fOfflineTriggerMask=AliVEvent::kINT7;
+                       fTriggerSelectedManually = kTRUE;
+                       fSpecialTriggerName="AliVEvent::kINT7";
+               break;
                case 1: //with TZERO
                        fSpecialTrigger=0;
                        fSpecialSubTrigger=0; 
@@ -889,11 +914,78 @@ Bool_t AliConvEventCuts::SetSelectSubTriggerClass(Int_t selectSpecialSubTriggerC
                        fTriggerSelectedManually = kTRUE;
                        fSpecialTriggerName="AliVEvent::kINT8";
                        break;
+               case 2: //with VZERO (will only work with LHC11a dataset)
+                       fSpecialTrigger=1;
+                       fSpecialSubTrigger=0; 
+//                     AliInfo("Info: Nothing to be done");
+                       break;  
+               case 3: //V0AND with SDD requested (will only work with LHC11a dataset)
+                       fSpecialTrigger=1;
+                       fSpecialSubTrigger=1; 
+                       break;
                default:
                        AliError("Warning: Special Subtrigger Class Not known");
                        return 0;
-               }       
-                       
+               }               
+       } else if (fSpecialTrigger == 3){ // Selecting kCentral and kSemiCentral from trigger classes, not aliases
+               switch(selectSpecialSubTriggerClass){
+               case 0: // all together
+                       fSpecialSubTrigger=0; 
+                       fSpecialSubTriggerName="";
+//                     AliInfo("Info: Nothing to be done");
+                       break;
+               case 1: // kCentral - no vertex restriction
+                       fSpecialSubTrigger=1; 
+                       fNSpecialSubTriggerOptions=1;
+                       fSpecialSubTriggerName="CVHN";
+                       cout << "kCentralOpen" << endl;
+                       break;
+               case 2: // kCentral - T00 +- 10 cm
+                       fSpecialSubTrigger=1; 
+                       fNSpecialSubTriggerOptions=1;
+                       fSpecialSubTriggerName="CCENT";
+                       cout << "kCentralVertex" << endl;
+                       break;
+               case 3: // kCentral - both
+                       fSpecialSubTrigger=1; 
+                       fNSpecialSubTriggerOptions=1;
+                       fSpecialSubTriggerName="CVHN|CCENT";
+                       cout << "kCentral both" << endl;
+                       break;
+               case 4: // kSemiCentral - no vertex restriction
+                       fSpecialSubTrigger=1; 
+                       fNSpecialSubTriggerOptions=1;
+                       fSpecialSubTriggerName="CVLN";
+                       cout << "kSemiCentralOpen" << endl;
+                       break;
+               case 5: // kSemiCentral - T00 +- 10 cm
+                       fSpecialSubTrigger=1; 
+                       fNSpecialSubTriggerOptions=1;
+                       fSpecialSubTriggerName="CSEMI";
+                       cout << "kSemiCentralVertex" << endl;
+                       break;
+               case 6: // kSemiCentral - both
+                       fSpecialSubTrigger=1; 
+                       fNSpecialSubTriggerOptions=1;
+                       fSpecialSubTriggerName="CSEMI%CVLN";
+                       cout << "kSemiCentral both" << endl;
+                       break;
+               case 7: // kMB
+                       fSpecialSubTrigger=1; 
+                       fNSpecialSubTriggerOptions=1;
+                       fSpecialSubTriggerName="CPBI1_|CPBI1-";
+                       cout << "kMB 1" << endl;
+                       break;                  
+               case 8: // kMB
+                       fSpecialSubTrigger=1; 
+                       fNSpecialSubTriggerOptions=1;
+                       fSpecialSubTriggerName="CPBI2_|CPBI2-";
+                       cout << "kMB 2" << endl;
+                       break;                  
+               default:
+                       AliError("Warning: Special Subtrigger Class Not known");
+                       return 0;
+               }               
        } else if (fSpecialTrigger == 4){ // Subdivision of TRD trigger classes
                switch(selectSpecialSubTriggerClass){
                case 0: // all together
@@ -1220,7 +1312,7 @@ Double_t AliConvEventCuts::GetCentrality(AliVEvent *event)
 
        AliAODEvent *aodEvent=dynamic_cast<AliAODEvent*>(event);
        if(aodEvent){
-               if(aodEvent->GetHeader()){return aodEvent->GetHeader()->GetCentrality();}
+          if(aodEvent->GetHeader()){return ((AliVAODHeader*)aodEvent->GetHeader())->GetCentrality();}
        }
 
        return -1;
@@ -1232,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;
 
@@ -1258,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
@@ -1269,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
@@ -1282,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
@@ -1295,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;
@@ -1425,6 +1519,7 @@ Bool_t AliConvEventCuts::IsTriggerSelected(AliVEvent *fInputEvent, Bool_t isMC)
 {
 
        AliInputEventHandler *fInputHandler=(AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
+
        
        UInt_t isSelected = AliVEvent::kAny;
        TString periodName = ((AliV0ReaderV1*)AliAnalysisManager::GetAnalysisManager()->GetTask(fV0ReaderName.Data()))->GetPeriodName();
@@ -1451,6 +1546,8 @@ Bool_t AliConvEventCuts::IsTriggerSelected(AliVEvent *fInputEvent, Bool_t isMC)
        //       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 (isMC) fOfflineTriggerMask = AliVEvent::kAny;
+       
                if (fOfflineTriggerMask){
                        isSelected = fOfflineTriggerMask & fInputHandler->IsEventSelected();             
                        
@@ -1462,16 +1559,45 @@ Bool_t AliConvEventCuts::IsTriggerSelected(AliVEvent *fInputEvent, Bool_t isMC)
                                }
                                if (fSpecialSubTrigger>0 && !isMC){
                                        if (!firedTrigClass.Contains(fSpecialSubTriggerName.Data())) isSelected = 0;
-                               } else if (fSpecialSubTrigger>0 && isMC){
+                               } else if (isMC){
                                        if (fSpecialTrigger == 5 || fSpecialTrigger == 8 || fSpecialTrigger == 9){ // EMCAL triggers
                                                isSelected = 0;
-//                                             cout << "triggers: " << fTriggersEMCAL << "    selected triggers: " << fTriggersEMCALSelected << endl;
+//                                             if (fTriggersEMCAL > 0)cout << "Special Trigger " << fSpecialTrigger << " triggers: " << fTriggersEMCAL << "    selected triggers: " << fTriggersEMCALSelected << " run number: " <<fInputEvent->GetRunNumber()<<endl;
                                                if (fTriggersEMCAL&fTriggersEMCALSelected){
 //                                                     cout << "accepted ++++++++++++++++++++" << endl;
                                                        isSelected = 1;
                                                }       
                                        }       
-                               }       
+                               }
+                               //if for specif centrality trigger selection 
+                               if(fSpecialSubTrigger == 1){
+                                       if(fSpecialSubTriggerName.Contains("|")){
+                                               TObjArray *ClassesList = fSpecialSubTriggerName.Tokenize("|");
+                                               for (Int_t i=0; i<ClassesList->GetEntriesFast();++i){
+                                                       TObjString *NameClass = (TObjString*)ClassesList->At(i);
+                                                       if (firedTrigClass.Contains(NameClass->GetString())) isSelected = 1;
+//                                                     cout << "|||||||| \t" << NameClass->GetString() << "\t ||||||||" << endl;
+                                               }
+                                       } else if(fSpecialSubTriggerName.Contains("%")){
+                                               TObjArray *ClassesList = fSpecialSubTriggerName.Tokenize("%");
+                                               for (Int_t i=0; i<ClassesList->GetEntriesFast();++i){
+                                                       TObjString *NameClass = (TObjString*)ClassesList->At(i);
+                                                       if (firedTrigClass.Contains(NameClass->GetString())) isSelected = 1;
+//                                                     cout << "|||||||| \t" << NameClass->GetString() << "\t ||||||||" << endl;
+                                               }       
+                                       } else if(fSpecialSubTriggerName.Contains("&")){
+                                               TObjArray *ClassesList = fSpecialSubTriggerName.Tokenize("&");
+                                               TString CheckClass = "";
+                                               for (Int_t i=0; i<ClassesList->GetEntriesFast(); i++){
+                                                       TObjString *NameClass = (TObjString*)ClassesList->At(i);
+                                                       if (firedTrigClass.Contains(NameClass->GetString())) CheckClass+="1";
+                                                       else CheckClass+="0";
+                                               }
+                                               if(CheckClass.Contains("0")) isSelected = 0;
+//                                             cout << "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&" << endl;
+                                       }       
+                                       else if(firedTrigClass.Contains(fSpecialSubTriggerName.Data())) isSelected = 1;
+                               }
                        }                               
                }        
        }
@@ -1587,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;
@@ -1609,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();
@@ -1649,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 ){
@@ -1677,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;
@@ -1721,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;
@@ -1733,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 ){
@@ -1753,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;
@@ -1792,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);
        }
        
@@ -1808,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
@@ -1855,7 +1965,7 @@ Int_t AliConvEventCuts::IsParticleFromBGEvent(Int_t index, AliStack *MCStack, Al
 }
 
 //_________________________________________________________________________
-Int_t AliConvEventCuts::IsEventAcceptedByCut(AliConvEventCuts *ReaderCuts, AliVEvent *InputEvent, AliMCEvent *MCEvent, Int_t isHeavyIon){
+Int_t AliConvEventCuts::IsEventAcceptedByCut(AliConvEventCuts *ReaderCuts, AliVEvent *InputEvent, AliMCEvent *MCEvent, Int_t isHeavyIon, Bool_t isEMCALAnalysis){
 
        Bool_t isMC = kFALSE;
        if (MCEvent){isMC = kTRUE;}
@@ -1874,12 +1984,61 @@ Int_t AliConvEventCuts::IsEventAcceptedByCut(AliConvEventCuts *ReaderCuts, AliVE
 
        Bool_t hasV0And = ReaderCuts->HasV0AND();
        Bool_t isSDDFired = ReaderCuts->IsSDDFired();
+       
+       if( ( (IsSpecialTrigger() == 0 && IsSpecialSubTrigger() == 1) || (IsSpecialTrigger() == 1 && IsSpecialSubTrigger() == 1) ) && !isSDDFired && !MCEvent) 
+       //if V0OR with SDD requested or V0AND with SDD request but the SDD has not fired
+       return 7; // V0 with SDD requested but no fired
+
+       if( ( (IsSpecialTrigger() == 1 && IsSpecialSubTrigger() == 0) || (IsSpecialTrigger() == 1 && IsSpecialSubTrigger() == 1) ) && !hasV0And) 
+       //if V0AND (only) or V0AND with SDD requested but V0AND requested but no fired
+       return 8; // V0AND requested but no fired
+
+       
        if( (IsSpecialTrigger() == 2 || IsSpecialTrigger() == 3) && !isSDDFired && !MCEvent)
                return 7; // With SDD requested but no fired
 
        if( (IsSpecialTrigger() == 1 || IsSpecialTrigger() == 3) && !hasV0And)
                return 8; // V0AND requested but no fired
 
+       // Special EMCAL checks due to hardware issues in LHC11a        
+       if (isEMCALAnalysis || IsSpecialTrigger() == 5 || IsSpecialTrigger() == 8 || IsSpecialTrigger() == 9 ){
+               Int_t runnumber = InputEvent->GetRunNumber();
+               if ((runnumber>=144871) && (runnumber<=146860)) { 
+
+                       AliVCaloCells *cells   = InputEvent->GetEMCALCells();
+                       const Short_t nCells   = cells->GetNumberOfCells();
+                       
+                       if (InputEvent->IsA()==AliESDEvent::Class()) AliAnalysisManager::GetAnalysisManager()->LoadBranch("EMCALCells.");
+
+                       AliInputEventHandler *fInputHandler=(AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
+                       if (!fInputHandler) return 3;
+                       
+                       // count cells above threshold
+                       Int_t nCellCount[12] = {0,0,0,0,0,0,0,0,0,0,0,0};
+                       for(Int_t iCell=0; iCell<nCells; ++iCell) {
+                               Short_t cellId = cells->GetCellNumber(iCell);
+                               Double_t cellE = cells->GetCellAmplitude(cellId);
+                               Int_t sm       = cellId / (24*48);
+                               if (cellE>0.1) ++nCellCount[sm];
+                       }
+
+                       Bool_t fIsLedEvent = kFALSE;
+                       if (nCellCount[4] > 100) {
+                               fIsLedEvent = kTRUE;
+                       } else {
+                               if ((runnumber>=146858) && (runnumber<=146860)) {
+                                       if ((fInputHandler->IsEventSelected() & AliVEvent::kMB) && (nCellCount[3]>=21))
+                                               fIsLedEvent = kTRUE;
+                                       else if ((fInputHandler->IsEventSelected() & AliVEvent::kEMC1) && (nCellCount[3]>=35))
+                                               fIsLedEvent = kTRUE;
+                               }
+                       }
+                       if (fIsLedEvent) {
+                               return 9;
+                       }
+               }
+       }       
+               
        if(hCentrality)hCentrality->Fill(GetCentrality(InputEvent));
        if(hCentralityVsNumberOfPrimaryTracks)
                hCentralityVsNumberOfPrimaryTracks->Fill(GetCentrality(InputEvent),
@@ -1891,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){
-                               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){
+                       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("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;
@@ -1933,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));
@@ -1947,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;
@@ -2058,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;
 }
 
@@ -2202,21 +2266,46 @@ ULong_t AliConvEventCuts::GetTriggerList(){
        Int_t nJ2 = 0;
        Int_t nL0 = 0;
        AliEmcalTriggerPatchInfo *patch;
+//     if (nPatch> 0) {cout << "NEW Triggers in this event*********************************" << endl;}
        for (Int_t iPatch = 0; iPatch < nPatch; iPatch++) {
                patch = (AliEmcalTriggerPatchInfo*)fTriggerPatchInfo->At( iPatch );
-               if (patch->IsGammaHigh()) nG1++;
-               if (patch->IsGammaLow())  nG2++;
-               if (patch->IsJetHigh()) nJ1++;
-               if (patch->IsJetLow())  nJ2++;
-               if (patch->IsLevel0())  nL0++;
+//             cout << "Patch energy: "<<patch->GetPatchE() << "\t ADC counts: " << patch->GetADCAmp() << endl;
+//             cout << "Phi: " << patch->GetPhiMin() << " - " << patch->GetPhiMax() << " delta phi: " <<abs(patch->GetPhiMin()-patch->GetPhiMax())<< endl;
+//             cout << "Eta: " << patch->GetEtaMin() << " - " << patch->GetEtaMax() << " delta eta: " <<abs(patch->GetEtaMin()-patch->GetEtaMax())<< endl;
+               if (patch->IsGammaHigh()){
+//                     cout << "fired L1GA high" << endl;
+                       nG1++;
+               }       
+               if (patch->IsGammaLow()){
+//                     cout << "fired L1GA low" << endl;
+                       nG2++;
+               }       
+               if (patch->IsJetHigh()){
+//                     cout << "fired L1JE high" << endl;
+                       nJ1++;
+               }
+               if (patch->IsJetLow()){
+//                     cout << "fired L1JE low" << endl;
+                       nJ2++;
+               }       
+               if (patch->IsLevel0()){
+//                     cout << "fired L0" << endl;
+                       nL0++;
+               }       
+//             cout << patch->GetPatchE()      << "\t" << patch->GetADCAmp()   << "\t" << patch->IsGammaHigh() << "\t" << patch->IsGammaLow()  
+//                  << "\t" << patch->IsJetHigh()      << "\t" << patch->IsJetLow()    << "\t" << patch->IsLevel0() 
+//                      << "\t" << patch->GetPhiMin()  << "\t" << patch->GetPhiMax()   << "\t" << abs(patch->GetPhiMin()-patch->GetPhiMax())
+//                      << "\t" << patch->GetEtaMin()  << "\t" << patch->GetEtaMax()   << "\t" << abs(patch->GetEtaMin()-patch->GetEtaMax()) << endl;
        }
 
-//       AliDebug(2, "Patch summary: ");
-//       AliDebug(2, Form("Number of patches: %d", nPatch));
-//       AliDebug(2, Form("Level0: [%d]" ,nL0));
-//       AliDebug(2, Form("Jet:    low[%d], high[%d]" ,nJ2, nJ1));
-//       AliDebug(2, Form("Gamma:  low[%d], high[%d]" ,nG2, nG1));
-
+       if (nPatch > 0){
+               AliDebug(2, "Patch summary: ");
+               AliDebug(2, Form("Number of patches: %d", nPatch));
+               AliDebug(2, Form("Level0: [%d]" ,nL0));
+               AliDebug(2, Form("Jet:    low[%d], high[%d]" ,nJ2, nJ1));
+               AliDebug(2, Form("Gamma:  low[%d], high[%d]" ,nG2, nG1));
+       }
+               
 //     if (nPatch > 0){
 //             cout <<           Form("Number of patches: %d", nPatch) << endl;
 //             cout <<           Form("Level0: [%d]" ,nL0) << endl;
@@ -2226,15 +2315,15 @@ ULong_t AliConvEventCuts::GetTriggerList(){
          
        ULong_t triggers(0);
        if (nG1>0)
-       SETBIT(triggers, kG1);
+               SETBIT(triggers, kG1);
        if (nG2>0)
-       SETBIT(triggers, kG2);
+               SETBIT(triggers, kG2);
        if (nJ1>0)
-       SETBIT(triggers, kJ1);
+               SETBIT(triggers, kJ1);
        if (nJ2>0)
-       SETBIT(triggers, kJ2);
+               SETBIT(triggers, kJ2);
        if (nL0>0)
-       SETBIT(triggers, kL0);
+               SETBIT(triggers, kL0);
        return triggers;
 }
 
@@ -2277,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;
+}      
+