From 6f1b16e81db40102ad2c425d8c12d1139c0287bc Mon Sep 17 00:00:00 2001 From: Lauren Hay Date: Tue, 20 Sep 2022 23:06:25 +0200 Subject: [PATCH] Protect against zero-sized jet correction param array --- .../JetMETObjects/src/SimpleJetCorrector.cc | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/CondFormats/JetMETObjects/src/SimpleJetCorrector.cc b/CondFormats/JetMETObjects/src/SimpleJetCorrector.cc index 7ca9f82e9b255..a645ac7dc9191 100644 --- a/CondFormats/JetMETObjects/src/SimpleJetCorrector.cc +++ b/CondFormats/JetMETObjects/src/SimpleJetCorrector.cc @@ -4,6 +4,7 @@ #include #include #include +#include //------------------------------------------------------------------------ //--- SimpleJetCorrector constructor ------------------------------------- @@ -78,25 +79,30 @@ float SimpleJetCorrector::correctionBin(unsigned fBin, const std::vector& handleError("SimpleJetCorrector", sserr.str()); } unsigned N = fY.size(); - if (N > 4) { - std::stringstream sserr; - sserr << "two many variables: " << N << " maximum is 4"; - handleError("SimpleJetCorrector", sserr.str()); - } - const std::vector& par = mParameters.record(fBin).parameters(); - - double params[par.size() - 2 * N]; - for (unsigned int i = 2 * N; i < par.size(); i++) { - params[i - 2 * N] = par[i]; - } - double x[4] = {}; - for (unsigned i = 0; i < N; i++) { - x[i] = (fY[i] < par[2 * i]) ? par[2 * i] : (fY[i] > par[2 * i + 1]) ? par[2 * i + 1] : fY[i]; - } - if (mParameters.definitions().isResponse()) { - return invert(x, params); + if (!fY.empty() && N <= 4) { + const std::vector& par = mParameters.record(fBin).parameters(); + auto nParams = static_cast(par.size() - 2 * N); + if (nParams > 0) { + double params[nParams]; + for (unsigned int i = 2 * N; i < par.size(); i++) { + params[i - 2 * N] = par[i]; + } + double x[4] = {}; + for (unsigned i = 0; i < N; i++) { + x[i] = (fY[i] < par[2 * i]) ? par[2 * i] : (fY[i] > par[2 * i + 1]) ? par[2 * i + 1] : fY[i]; + } + if (mParameters.definitions().isResponse()) { + return invert(x, params); + } + return mFunc.evaluate(reco::formula::ArrayAdaptor(x, N), reco::formula::ArrayAdaptor(params, par.size() - 2 * N)); + } else { + return 1.0; + } + } else { + edm::LogWarning("SimpleJetCorrector") << "Expect number of variables to be 0