Skip to content

Commit

Permalink
Merge pull request #46679 from mbluj/CMSSW_14_2_X_TauSpinnerTableFix
Browse files Browse the repository at this point in the history
Protect TauSpinnerTable producer against crash with samples with HTT mixed with other processes
  • Loading branch information
cmsbuild authored Nov 13, 2024
2 parents a869f22 + 76197db commit 9755d19
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions PhysicsTools/NanoAOD/plugins/TauSpinnerTableProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "TauSpinner/SimpleParticle.h"
#include "TauSpinner/tau_reweight_lib.h"

#include <atomic>

class TauSpinnerTableProducer : public edm::one::EDProducer<edm::one::SharedResources> {
public:
explicit TauSpinnerTableProducer(const edm::ParameterSet &);
Expand Down Expand Up @@ -92,6 +94,9 @@ class TauSpinnerTableProducer : public edm::one::EDProducer<edm::one::SharedReso
const int nonSMN_;
const double cmsE_;
const double default_weight_;

std::atomic<unsigned int> nWarnings{0};
static const unsigned int nMaxWarnings = 10;
};

TauSpinnerTableProducer::TauSpinnerTableProducer(const edm::ParameterSet &config)
Expand Down Expand Up @@ -189,15 +194,42 @@ void TauSpinnerTableProducer::produce(edm::Event &event, const edm::EventSetup &
edm::RefVector<edm::View<reco::GenParticle>> 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<double>(
"weight_cp_" + theta.first, default_weight_, "TauSpinner weight for theta_CP = " + theta.first);
wtTable->addColumnValue<double>(
"weight_cp_" + theta.first + "_alt",
default_weight_,
"TauSpinner weight for theta_CP = " + theta.first + " (alternative hadronic currents)");
}
event.put(std::move(wtTable));
return;
}

// 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<double>(
"weight_cp_" + theta.first, default_weight_, "TauSpinner weight for theta_CP = " + theta.first);
wtTable->addColumnValue<double>(
"weight_cp_" + theta.first + "_alt",
default_weight_,
"TauSpinner weight for theta_CP = " + theta.first + " (alternative hadronic currents)");
}
event.put(std::move(wtTable));
return;
}
Expand Down

0 comments on commit 9755d19

Please sign in to comment.