diff --git a/Generators/Pythia8_i/src/UserHooks/DecayToSUEP.cxx b/Generators/Pythia8_i/src/UserHooks/DecayToSUEP.cxx index d52df4bba1d978bfcc95caa218c985b8949cd1a7..9f526e847d41e5a54bd62fbd9b56c9e0e8a946b7 100644 --- a/Generators/Pythia8_i/src/UserHooks/DecayToSUEP.cxx +++ b/Generators/Pythia8_i/src/UserHooks/DecayToSUEP.cxx @@ -133,15 +133,22 @@ namespace Pythia8{ try { nShowerAttempts++; suep_shower4momenta=suep_shower.generate_shower(); - nShowerAttempts = -1; //exit condition + if( suep_shower4momenta.size()<3){ + //Failed to balance energy or less than 3 particles in the shower + //Try again until nShowerAttempts >= 3 + } else { + //All ok! + nShowerAttempts = -1; //exit condition + } } catch (std::exception &e) { //Failed to generate the shower! - //Can happen in some rare circumstances, try again + //Can happen in some rare circumstances, + //Try again until nShowerAttempts >= 3 } } while ((nShowerAttempts > 0) && (nShowerAttempts < 3)); if (nShowerAttempts >= 3) { //Something is seriously wrong then, print warning and skip to next event - std::cout << "[SUEP] ERROR: Something went terribly wrong in generating the shower. Skipping the event." << std::endl; + std::cout << "[SUEP] WARNING: Something went wrong in generating the shower. Skipping the event." << std::endl; return true; //veto the event! } diff --git a/Generators/Pythia8_i/src/UserHooks/suep_shower.cxx b/Generators/Pythia8_i/src/UserHooks/suep_shower.cxx index 08c9ea67ad58d97abf6b53e4599c1746f1f4260f..f6404d3d71b70b64852576b66cb3008e9bcf0c99 100644 --- a/Generators/Pythia8_i/src/UserHooks/suep_shower.cxx +++ b/Generators/Pythia8_i/src/UserHooks/suep_shower.cxx @@ -146,6 +146,13 @@ vector< Vec4 > Suep_shower::generate_shower(){ event[n][i] += correction; } } + + //Shield against an exception in the calculation of "p_scale" further down. If it fails, abort the event. + if(Suep_shower::reballance_func(2.0,event)<0.0){ + // failed to balance energy. + event.clear(); + return event; + } // finally, ballance the total energy, without destroying momentum conservation tolerance tol = 0.00001;