Skip to content

Commit

Permalink
Merge pull request #104 from blinkseb/sf_nan_fix
Browse files Browse the repository at this point in the history
Protect against NaN b-tag discriminant. Fixes #99
  • Loading branch information
OlivierBondu committed Jan 4, 2016
2 parents 71f34be + c35adfc commit 22d44c6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
11 changes: 10 additions & 1 deletion interface/ScaleFactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,16 @@ struct ScaleFactor {
std::vector<_Value> get(Histogram<_Value, float>& h, const std::vector<float>& bins, bool& outOfRange) const {
std::size_t bin = h.findClosestBin(bins, &outOfRange);
if (bin == 0) {
throw std::runtime_error("Failed to found the right bin for a scale-factor. This should not happend");
std::stringstream msg;
msg << "Failed to found the right bin for a scale-factor. This should not happend. Bins: [";
for (float b: bins) {
msg << b << ", ";
}

msg.seekp(msg.tellp() - 2l);
msg << "]";

throw std::runtime_error(msg.str());
}

return {h.getBinContent(bin), h.getBinErrorLow(bin), h.getBinErrorHigh(bin)};
Expand Down
6 changes: 5 additions & 1 deletion src/FatJetsProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,15 @@ void FatJetsProducer::produce(edm::Event& event, const edm::EventSetup& eventSet
for (auto& it: m_btag_discriminators) {

float btag_discriminator = jet.bDiscriminator(it.first);
// Protect against NaN discriminant
if (std::isnan(btag_discriminator))
btag_discriminator = -10;

it.second->push_back(btag_discriminator);

Algorithm algo = string_to_algorithm(it.first);
if (algo != Algorithm::UNKNOWN && BTaggingScaleFactors::has_scale_factors(algo)) {
BTaggingScaleFactors::store_scale_factors(algo, get_flavor(jet.hadronFlavour()), {static_cast<float>(fabs(jet.eta())), static_cast<float>(jet.pt()), btag_discriminator},event.isRealData());
BTaggingScaleFactors::store_scale_factors(algo, get_flavor(jet.hadronFlavour()), {static_cast<float>(std::abs(jet.eta())), static_cast<float>(jet.pt()), btag_discriminator}, event.isRealData());
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/JetsProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@ void JetsProducer::produce(edm::Event& event, const edm::EventSetup& eventSetup)
for (auto& it: m_btag_discriminators) {

float btag_discriminator = jet.bDiscriminator(it.first);
// Protect against NaN discriminant
if (std::isnan(btag_discriminator))
btag_discriminator = -10;

it.second->push_back(btag_discriminator);

Algorithm algo = string_to_algorithm(it.first);
if (algo != Algorithm::UNKNOWN && BTaggingScaleFactors::has_scale_factors(algo)) {
BTaggingScaleFactors::store_scale_factors(algo, get_flavor(jet.hadronFlavour()), {static_cast<float>(fabs(jet.eta())), static_cast<float>(jet.pt()), btag_discriminator},event.isRealData());
BTaggingScaleFactors::store_scale_factors(algo, get_flavor(jet.hadronFlavour()), {static_cast<float>(std::abs(jet.eta())), static_cast<float>(jet.pt()), btag_discriminator}, event.isRealData());
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions test/TestConfigurationMC.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,12 @@
'/store/mc/RunIISpring15MiniAODv2/TTJets_TuneCUETP8M1_13TeV-amcatnloFXFX-pythia8/MINIAODSIM/74X_mcRun2_asymptotic_v2-v1/00000/0014DC94-DC5C-E511-82FB-7845C4FC39F5.root'
)

# Only run on a specific event. Useful for debugging

# NaN b-tagging discriminant for a jet
# input file: /store/mc/RunIISpring15MiniAODv2/TTTo2L2Nu_13TeV-powheg/MINIAODSIM/74X_mcRun2_asymptotic_v2-v1/60000/88E6468A-C56D-E511-B6C8-001E67248142.root
#process.source.eventsToProcess = cms.untracked.VEventRange(
#'1:25002:4987798',
#)

process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(1000))

0 comments on commit 22d44c6

Please sign in to comment.