From 135b60d8b521f00585e2d766c83aaabaad164af3 Mon Sep 17 00:00:00 2001 From: Simone Pagan Griso <simone.pagan.griso@cern.ch> Date: Mon, 10 Aug 2020 11:56:56 -0700 Subject: [PATCH] add additional early protection against failure to balance energy --- Generators/Pythia8_i/src/UserHooks/DecayToSUEP.cxx | 13 ++++++++++--- Generators/Pythia8_i/src/UserHooks/suep_shower.cxx | 7 +++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Generators/Pythia8_i/src/UserHooks/DecayToSUEP.cxx b/Generators/Pythia8_i/src/UserHooks/DecayToSUEP.cxx index d52df4bba1d..9f526e847d4 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 08c9ea67ad5..f6404d3d71b 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; -- GitLab