From 76197dbbfb0948eae3bab52b4fa2916fd6db432a Mon Sep 17 00:00:00 2001 From: Michal Bluj Date: Tue, 12 Nov 2024 14:28:58 +0100 Subject: [PATCH] Protect TauSpinnerTable producer against crash with samples with HtoTauTau being only a fraction of differnt event types --- .../plugins/TauSpinnerTableProducer.cc | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/PhysicsTools/NanoAOD/plugins/TauSpinnerTableProducer.cc b/PhysicsTools/NanoAOD/plugins/TauSpinnerTableProducer.cc index bcf8b426abfb9..bdca5918478fc 100644 --- a/PhysicsTools/NanoAOD/plugins/TauSpinnerTableProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/TauSpinnerTableProducer.cc @@ -24,6 +24,8 @@ #include "TauSpinner/SimpleParticle.h" #include "TauSpinner/tau_reweight_lib.h" +#include + class TauSpinnerTableProducer : public edm::one::EDProducer { public: explicit TauSpinnerTableProducer(const edm::ParameterSet &); @@ -92,6 +94,9 @@ class TauSpinnerTableProducer : public edm::one::EDProducer nWarnings{0}; + static const unsigned int nMaxWarnings = 10; }; TauSpinnerTableProducer::TauSpinnerTableProducer(const edm::ParameterSet &config) @@ -189,7 +194,20 @@ void TauSpinnerTableProducer::produce(edm::Event &event, const edm::EventSetup & edm::RefVector> bosons; getBosons(bosons, genParts); if (bosons.size() != - 1) { // no boson found or more than one found, produce empty table (expected for non HTT samples) + 1) { // no boson found or more than one found, produce table with default weights (expected for non HTT samples) + if (++nWarnings < nMaxWarnings) + edm::LogWarning("TauSpinnerTableProducer::produce") + << "Current event has " << bosons.size() + << " Higgs bosons while there must be exactly one; table with default weights is produced.\n"; + // Fill table with default values + for (const auto &theta : theta_vec_) { + wtTable->addColumnValue( + "weight_cp_" + theta.first, default_weight_, "TauSpinner weight for theta_CP = " + theta.first); + wtTable->addColumnValue( + "weight_cp_" + theta.first + "_alt", + default_weight_, + "TauSpinner weight for theta_CP = " + theta.first + " (alternative hadronic currents)"); + } event.put(std::move(wtTable)); return; } @@ -197,7 +215,21 @@ void TauSpinnerTableProducer::produce(edm::Event &event, const edm::EventSetup & // Search for taus from boson decay reco::GenParticleRefVector taus; getTaus(taus, *bosons[0]); - if (taus.size() != 2) { // boson does not decay to tau pair, produce empty table (expected for non HTT samples) + if (taus.size() != + 2) { // boson does not decay to tau pair, produce table with default weights (expected for non HTT samples) + if (++nWarnings < nMaxWarnings) + edm::LogWarning("TauSpinnerTableProducer::produce") + << "Current event has " << taus.size() + << " taus from boson decay while there must be exactly one pair; table with default weights is produced.\n"; + // Fill table with default values + for (const auto &theta : theta_vec_) { + wtTable->addColumnValue( + "weight_cp_" + theta.first, default_weight_, "TauSpinner weight for theta_CP = " + theta.first); + wtTable->addColumnValue( + "weight_cp_" + theta.first + "_alt", + default_weight_, + "TauSpinner weight for theta_CP = " + theta.first + " (alternative hadronic currents)"); + } event.put(std::move(wtTable)); return; }