Skip to content

Commit 54e1534

Browse files
authored
Merge pull request #49082 from cms-ngt-hlt/hotfix/division_by_zero
[Hotfix] MET Validation: Division by zero
2 parents 8ec7a4b + 02e10ba commit 54e1534

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

Validation/RecoMET/plugins/METTester.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ class METTester : public DQMEDAnalyzer {
4141
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;
4242
static void fillDescriptions(edm::ConfigurationDescriptions &);
4343

44-
static const int mNMETBins = 11;
44+
static constexpr int mNMETBins = 11;
4545
static constexpr std::array<float, mNMETBins + 1> mMETBins = {
4646
{0., 20., 40., 60., 80., 100., 150., 200., 300., 400., 500., 1000.}};
47-
static const int mNPhiBins = 6;
47+
static constexpr int mNPhiBins = 6;
4848
static constexpr std::array<float, mNPhiBins + 1> mPhiBins = {{-3.15, -2., -1., 0., 1., 2., 3.15}};
4949

5050
static std::string binStr(float left, float right, bool roundInt = true);

Validation/RecoMET/plugins/METTesterPostProcessor.cc

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ void METTesterPostProcessor::dqmEndJob(DQMStore::IBooker &ibook_, DQMStore::IGet
3737
}
3838
}
3939

40+
bool METTesterPostProcessor::mCheckHisto(MElem *h) { return h && h->getRootObject(); }
41+
4042
void METTesterPostProcessor::mFillAggrHistograms(std::string metdir, DQMStore::IGetter &iget) {
4143
for (std::string bt : {"MET", "Phi"}) { // loop over bin types
4244
for (unsigned idx = 0; idx < mNBins[bt]; ++idx) {
@@ -46,12 +48,27 @@ void METTesterPostProcessor::mFillAggrHistograms(std::string metdir, DQMStore::I
4648
mArrayIdx<MElem *>(mMETDiff_GenMETTrue[bt], idx) = iget.get(metdir + "/METDiff_GenMETTrue_" + bt + edges);
4749
mArrayIdx<MElem *>(mMETRatio_GenMETTrue[bt], idx) = iget.get(metdir + "/METRatio_GenMETTrue_" + bt + edges);
4850
mArrayIdx<MElem *>(mMETDeltaPhi_GenMETTrue[bt], idx) = iget.get(metdir + "/METDeltaPhi_GenMETTrue_" + bt + edges);
51+
52+
// check one object, if it exists, then the remaining ME's exists too
53+
// for genmet none of these ME's are filled
54+
if (mCheckHisto(mArrayIdx<MElem *>(mMETDiff_GenMETTrue[bt], 0))) {
55+
// log histograms with zero entries
56+
if (mArrayIdx<MElem *>(mMET[bt], idx)->getEntries() < mEpsilonDouble ||
57+
mArrayIdx<MElem *>(mMETDiff_GenMETTrue[bt], idx)->getEntries() < mEpsilonDouble ||
58+
mArrayIdx<MElem *>(mMETRatio_GenMETTrue[bt], idx)->getEntries() < mEpsilonDouble ||
59+
mArrayIdx<MElem *>(mMETDeltaPhi_GenMETTrue[bt], idx)->getEntries() < mEpsilonDouble) {
60+
LogDebug("METTesterPostProcessor")
61+
<< "At least one of the " << bt + edges << " histograms has zero entries:\n"
62+
<< " MET: " << mArrayIdx<MElem *>(mMET[bt], idx)->getEntries() << "\n"
63+
<< " METDiff: " << mArrayIdx<MElem *>(mMETDiff_GenMETTrue[bt], idx)->getEntries() << "\n"
64+
<< " METRatio: " << mArrayIdx<MElem *>(mMETRatio_GenMETTrue[bt], idx)->getEntries() << "\n"
65+
<< " METDeltaPhi: " << mArrayIdx<MElem *>(mMETDeltaPhi_GenMETTrue[bt], idx)->getEntries();
66+
}
67+
}
4968
}
5069

51-
// check one object, if it exists, then the remaining ME's exists too
52-
// for genmet none of these ME's are filled
53-
if (mArrayIdx<MElem *>(mMETDiff_GenMETTrue[bt], 0) &&
54-
mArrayIdx<MElem *>(mMETDiff_GenMETTrue[bt], 0)->getRootObject()) {
70+
if (mCheckHisto(mArrayIdx<MElem *>(mMETDiff_GenMETTrue[bt], 0))) {
71+
// compute and store MET quantities
5572
for (unsigned idx = 0; idx < mNBins[bt]; ++idx) {
5673
mMETDiffAggr[bt]->setBinContent(idx + 1, mArrayIdx<MElem *>(mMETDiff_GenMETTrue[bt], idx)->getMean());
5774
mMETDiffAggr[bt]->setBinError(idx + 1, mArrayIdx<MElem *>(mMETDiff_GenMETTrue[bt], idx)->getRMS());
@@ -67,11 +84,13 @@ void METTesterPostProcessor::mFillAggrHistograms(std::string metdir, DQMStore::I
6784
mMETResolAggr[bt]->setBinContent(idx + 1, metRMS);
6885
mMETResolAggr[bt]->setBinError(idx + 1, resolError);
6986

70-
float significance = metMean / metRMS;
87+
float significance = metRMS < mEpsilonFloat ? 0.f : metMean / metRMS;
88+
float significance_error = metRMS < mEpsilonFloat || metMean < mEpsilonFloat
89+
? 0.f
90+
: significance * std::sqrt((metRMS * metRMS / (metMean * metMean)) +
91+
(resolError * resolError / (metRMS * metRMS)));
7192
mMETSignAggr[bt]->setBinContent(idx + 1, significance);
72-
mMETSignAggr[bt]->setBinError(idx + 1,
73-
significance * std::sqrt((metRMS * metRMS / (metMean * metMean)) +
74-
(resolError * resolError / (metRMS * metRMS))));
93+
mMETSignAggr[bt]->setBinError(idx + 1, significance_error);
7594
}
7695
}
7796
}

Validation/RecoMET/plugins/METTesterPostProcessor.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ class METTesterPostProcessor : public DQMEDHarvester {
2222
void dqmEndJob(DQMStore::IBooker&, DQMStore::IGetter&) override;
2323
std::vector<std::string> met_dirs;
2424

25+
using MElem = MonitorElement;
26+
2527
void mFillAggrHistograms(std::string, DQMStore::IGetter&);
28+
bool mCheckHisto(MElem* h);
2629

27-
using MElem = MonitorElement;
2830
template <typename T>
2931
using ArrayVariant = std::variant<std::array<T, METTester::mNMETBins + 1>, std::array<T, METTester::mNPhiBins + 1>>;
3032

@@ -59,6 +61,9 @@ class METTesterPostProcessor : public DQMEDHarvester {
5961
ElemMap mMETSignAggr;
6062

6163
std::string runDir;
64+
65+
float mEpsilonFloat = std::numeric_limits<float>::epsilon();
66+
double mEpsilonDouble = std::numeric_limits<double>::epsilon();
6267
};
6368

6469
#endif

0 commit comments

Comments
 (0)