From 339958ea75660b5fe50bb8e54dc90c2618ef2924 Mon Sep 17 00:00:00 2001 From: Steven Doran <78985334+S81D@users.noreply.github.com> Date: Wed, 14 Jan 2026 10:29:15 -0600 Subject: [PATCH] Update LoadReweightGenieEvent.cpp Some events have parameter throws that make the xsec_total < 0. Add error handling to account for events where re-weighting failed. An example of what sometimes happens: Executing tool LoadWCSim with MC entry 20, trigger 0 Analyse: GReWeightXSecMEC.cxx:500: double genie::rew::GReWeightXSecMEC::CalcWeightPNDelta(const genie::EventRecord&): Assertion `xsec_tot > 0.' failed. Aborted (core dumped) This causes the toolchain to crash at entry N, leading to a large loss in statistics. To remedy this we can use a recovery point where the weight will automatically be assigned as 1.0 if such a problematic value is sampled in multisim. --- .../LoadReweightGenieEvent.cpp | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/UserTools/LoadReweightGenieEvent/LoadReweightGenieEvent.cpp b/UserTools/LoadReweightGenieEvent/LoadReweightGenieEvent.cpp index 85768367a..5af826f50 100644 --- a/UserTools/LoadReweightGenieEvent/LoadReweightGenieEvent.cpp +++ b/UserTools/LoadReweightGenieEvent/LoadReweightGenieEvent.cpp @@ -11,6 +11,21 @@ //using namespace genie::constants; //using namespace genie::flux; +// *********************** +// GENIE ERROR HANDLING +#include +#include +// global jump buffer for signal recovery +static jmp_buf genie_jump_buffer; + +// signal handler function +void handle_genie_abort(int sig) { + if (sig == SIGABRT) { + longjmp(genie_jump_buffer, 1); + } +} +// *********************** + /* GENIE INPUTS ============ @@ -644,7 +659,27 @@ bool LoadReweightGenieEvent::Execute(){ // objects to compute the weights. weights[i].resize( num_knobs ); for (unsigned int k = 0; k < num_knobs; ++k ) { - weights[i][k] = reweightVector[i].at(k).CalcWeight( *gevtRec ); + + // ERROR HANDLING FROM GENIE + // ************************************ + // register the signal handler + void (*prev_handler)(int) = std::signal(SIGABRT, handle_genie_abort); + + // set the jump point + if (setjmp(genie_jump_buffer) == 0) { + // default (if no error is present) + weights[i][k] = reweightVector[i].at(k).CalcWeight( *gevtRec ); + } else { + // recovery path: if GENIE calls abort(), we land here + std::cerr << "!!! GENIE Aborted on event " << tchainentrynum + << " (Knob: " << k << "). Skipping and using weight 1.0." << std::endl; + weights[i][k] = 1.0; + } + + // restore the original handler + std::signal(SIGABRT, prev_handler); + // ************************************ + } reweights.insert(std::pair>(weight_names[i],weights[i]));