Index: trunk/modules/MadGraphShowerPartonSelector.cc
===================================================================
--- trunk/modules/MadGraphShowerPartonSelector.cc	(revision 2)
+++ trunk/modules/MadGraphShowerPartonSelector.cc	(revision 11)
@@ -35,5 +35,6 @@
   void SetEtaMax(Double_t eta);
   void InsertParticleID(Int_t pid);
-  void InsertAncestorID(Int_t pid);
+  void InsertExclAncestorID(Int_t pid);
+  void InsertInclAncestorID(Int_t pid);
   void SetHadronizationInfo(Bool_t info);
 
@@ -41,4 +42,5 @@
 
   Bool_t hasBadAncestor(ExRootGenParticle *object);
+  Bool_t hasGoodAncestor(ExRootGenParticle *object);
 
   Double_t fEtaMax;
@@ -47,5 +49,6 @@
 
   set< Int_t > fParticleIDSet;
-  set< Int_t > fAncestorIDSet;
+  set< Int_t > fExclAncestorIDSet;
+  set< Int_t > fInclAncestorIDSet;
 };
 
@@ -73,7 +76,14 @@
 //------------------------------------------------------------------------------
 
-void MadGraphShowerPartonClassifier::InsertAncestorID(Int_t pid)
-{
-  fAncestorIDSet.insert(pid);
+void MadGraphShowerPartonClassifier::InsertExclAncestorID(Int_t pid)
+{
+  fExclAncestorIDSet.insert(pid);
+}
+
+//------------------------------------------------------------------------------
+
+void MadGraphShowerPartonClassifier::InsertInclAncestorID(Int_t pid)
+{
+  fInclAncestorIDSet.insert(pid);
 }
 
@@ -96,10 +106,16 @@
   if(particle->PID == 21) return kFALSE;
 
+  // keep all particles if there is no pid in the list
+  if(fExclAncestorIDSet.empty())
+  {
+    return kFALSE;
+  }
+
   pidAbs = TMath::Abs(particle->PID);
 
   // skip particles with pid included in list
-  itAncestorIDSet = fAncestorIDSet.find(pidAbs);
-
-  if(itAncestorIDSet != fAncestorIDSet.end()) return kTRUE;
+  itAncestorIDSet = fExclAncestorIDSet.find(pidAbs);
+
+  if(itAncestorIDSet != fExclAncestorIDSet.end()) return kTRUE;
   if(particle->M2 > -1) return kFALSE;
 
@@ -115,7 +131,59 @@
 
     // skip particles with pid included in list
-    itAncestorIDSet = fAncestorIDSet.find(pidAbs);
-
-    if(itAncestorIDSet != fAncestorIDSet.end()) return kTRUE;
+    itAncestorIDSet = fExclAncestorIDSet.find(pidAbs);
+
+    if(itAncestorIDSet != fExclAncestorIDSet.end()) return kTRUE;
+    if(particle->M2 > -1) return kFALSE;
+  }
+
+  return kFALSE;
+}
+
+//------------------------------------------------------------------------------
+
+Bool_t MadGraphShowerPartonClassifier::hasGoodAncestor(ExRootGenParticle *object)
+{
+  const int kMaxAncestors = 10;
+  Int_t i, pidAbs;
+  ExRootGenParticle *particle = object;
+  set< Int_t >::const_iterator itAncestorIDSet;
+
+  for(i = 0; i < kMaxAncestors && particle->Status != 3; ++i)
+  {
+    if(particle->M1 < 0) return kFALSE;
+
+    particle = static_cast<ExRootGenParticle*>(fBranchParticle->At(particle->M1));
+  }
+
+  if(particle->PID == 21) return kFALSE;
+
+  // keep all particles if there is no pid in the list
+  if(fInclAncestorIDSet.empty())
+  {
+    return kTRUE;
+  }
+
+  pidAbs = TMath::Abs(particle->PID);
+
+  // keep particles with pid included in list
+  itAncestorIDSet = fInclAncestorIDSet.find(pidAbs);
+
+  if(itAncestorIDSet != fInclAncestorIDSet.end()) return kTRUE;
+  if(particle->M2 > -1) return kFALSE;
+
+  for(i = 0; i < kMaxAncestors; ++i)
+  {
+    if(particle->M1 < 0) return kFALSE;
+
+    if(particle->PID == 21) return kFALSE;
+
+    particle = static_cast<ExRootGenParticle*>(fBranchParticle->At(particle->M1));
+
+    pidAbs = TMath::Abs(particle->PID);
+
+    // keep particles with pid included in list
+    itAncestorIDSet = fInclAncestorIDSet.find(pidAbs);
+
+    if(itAncestorIDSet != fInclAncestorIDSet.end()) return kTRUE;
     if(particle->M2 > -1) return kFALSE;
   }
@@ -159,4 +227,6 @@
   if(hasBadAncestor(particle)) return -1;
 
+  if(!hasGoodAncestor(particle)) return -1;
+
   return 0;
 }
@@ -214,5 +284,16 @@
   {
     pid = param[i].GetInt();
-    fClassifier->InsertAncestorID(pid);
+    fClassifier->InsertExclAncestorID(pid);
+  }
+
+  // read ancestor IDs from configuration file and setup classifier
+
+  param = GetParam("IncludedAncestorIDs");
+  sizeParam = param.GetSize();
+
+  for(i = 0; i < sizeParam; ++i)
+  {
+    pid = param[i].GetInt();
+    fClassifier->InsertInclAncestorID(pid);
   }
 
