Index: readers/DelphesPythia8.cpp
===================================================================
--- readers/DelphesPythia8.cpp	(revision e576ef604d84790b0d1775120514a8a161d0af38)
+++ readers/DelphesPythia8.cpp	(revision d2cf547025b9c4f13a77649c78caf8ae9d2c04f2)
@@ -146,12 +146,15 @@
 }
 
-
-// Single-particle gun. The particle must be a colour singlet.
-// Input: flavour, energy, direction (theta, phi).
-// If theta < 0 then random choice over solid angle.
-// Optional final argument to put particle at rest => E = m.
-// from pythia8 example 21
-
-void fillParticle(int id, double p_max, double eta_max,
+//---------------------------------------------------------------------------
+
+/*
+Single-particle gun. The particle must be a colour singlet.
+Input: flavour, energy, direction (theta, phi).
+If theta < 0 then random choice over solid angle.
+Optional final argument to put particle at rest => E = m.
+from pythia8 example 21
+*/
+
+void fillParticle(int id, double pMax, double etaMax,
   Pythia8::Event &event, Pythia8::ParticleData &pdt, Pythia8::Rndm &rndm)
 {
@@ -161,8 +164,8 @@
   // Generate uniform pt and eta.
   double pt, eta, phi, pp, ee, mm;
-  
-  //pmin = 0.1 GeV for single particles
-  pp = pow(10, - 1.0 + (log10(p_max) + 1.0) * rndm.flat()); 
-  eta = (2.0 * rndm.flat() - 1.0) * eta_max;
+
+  // pMin = 0.1 GeV for single particles
+  pp = pow(10, - 1.0 + (log10(pMax) + 1.0) * rndm.flat());
+  eta = (2.0 * rndm.flat() - 1.0) * etaMax;
   phi = 2.0 * M_PI * rndm.flat();
   mm = pdt.mSel(id);
@@ -174,8 +177,9 @@
 }
 
-void fillPartons(int id, double p_max, double eta_max,
+//---------------------------------------------------------------------------
+
+void fillPartons(int id, double pMax, double etaMax,
   Pythia8::Event &event, Pythia8::ParticleData &pdt, Pythia8::Rndm &rndm)
 {
-
   // Reset event record to allow for new event.
   event.reset();
@@ -184,7 +188,7 @@
   double pt, eta, phi, pp, ee, mm;
 
-  //pmin = 1 GeV for jets
-  pp = pow(10, log10(p_max) * rndm.flat());  
-  eta = (2.0 * rndm.flat() - 1.0) * eta_max;
+  // pMin = 1 GeV for jets
+  pp = pow(10, log10(pMax) * rndm.flat());
+  eta = (2.0 * rndm.flat() - 1.0) * etaMax;
   phi = 2.0 * M_PI * rndm.flat();
   mm = pdt.mSel(id);
@@ -193,5 +197,5 @@
 
   if( (id == 4 || id == 5) && pt < 10.0) return;
- 
+
   if(id == 21)
   {
@@ -205,5 +209,4 @@
   }
 }
-
 
 //---------------------------------------------------------------------------
@@ -227,7 +230,10 @@
   Long64_t eventCounter, errorCounter;
   Long64_t numberOfEvents, timesAllowErrors;
+  Bool_t spareFlag1;
+  Int_t spareMode1;
+  Double_t spareParm1, spareParm2;
 
   Pythia8::Pythia *pythia = 0;
- 
+
   // for matching
   Pythia8::CombineMatchingInput *combined = 0;
@@ -279,13 +285,13 @@
     // Initialize Pythia
     pythia = new Pythia8::Pythia;
-  
+
     // jet matching
     matching = combined->getHook(*pythia);
-    if (!matching)
+    if(!matching)
     {
       throw runtime_error("can't do matching");
     }
     pythia->setUserHooksPtr(matching);
- 
+
 
     if(pythia == NULL)
@@ -305,6 +311,11 @@
     timesAllowErrors = pythia->mode("Main:timesAllowErrors");
 
+    spareFlag1 = pythia->flag("Main:spareFlag1");
+    spareMode1 = pythia->mode("Main:spareMode1");
+    spareParm1 = pythia->parm("Main:spareParm1");
+    spareParm2 = pythia->parm("Main:spareParm2");
+
     // Check if particle gun
-    if (!pythia->flag("Main:spareFlag1"))
+    if(!spareFlag1)
     {
       inputFile = fopen(pythia->word("Beams:LHEF").c_str(), "r");
@@ -340,13 +351,13 @@
         stableParticleOutputArrayLHEF, partonOutputArrayLHEF) && !reader->EventReady());
 
-      if (pythia->flag("Main:spareFlag1"))
+      if(spareFlag1)
       {
-        if (pythia->mode("Main:spareMode1") == 11 || pythia->mode("Main:spareMode1") == 13 || pythia->mode("Main:spareMode1") == 15 || pythia->mode("Main:spareMode1") == 22 || pythia->mode("Main:spareMode1") == 211 || pythia->mode("Main:spareMode1") == 2112) 
-        { 
-          fillParticle(pythia->mode("Main:spareMode1"), pythia->parm("Main:spareParm1"), pythia->parm("Main:spareParm2"), pythia->event, pythia->particleData, pythia->rndm);
+        if((spareMode1 >= 1 && spareMode1 <= 5) || spareMode1 == 21)
+        {
+          fillPartons(spareMode1, spareParm1, spareParm2, pythia->event, pythia->particleData, pythia->rndm);
         }
         else
         {
-          fillPartons(pythia->mode("Main:spareMode1"), pythia->parm("Main:spareParm1"), pythia->parm("Main:spareParm2"), pythia->event, pythia->particleData, pythia->rndm);
+          fillParticle(spareMode1, spareParm1, spareParm2, pythia->event, pythia->particleData, pythia->rndm);
         }
       }
