Skip to content

Commit 712af69

Browse files
authored
Merge pull request #48352 from llunerti/from-CMSSW_15_1_0_pre3
Protect SoftMuonMvaRun3Estimator from returning nan
2 parents 249907a + 2e49fcd commit 712af69

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

PhysicsTools/PatAlgos/src/SoftMuonMvaRun3Estimator.cc

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "PhysicsTools/PatAlgos/interface/SoftMuonMvaRun3Estimator.h"
22
#include "DataFormats/PatCandidates/interface/Muon.h"
33
#include "PhysicsTools/XGBoost/interface/XGBooster.h"
4+
#include "FWCore/Utilities/interface/isFinite.h"
45

56
typedef std::pair<const reco::MuonChamberMatch*, const reco::MuonSegmentMatch*> MatchPair;
67

@@ -20,6 +21,17 @@ const MatchPair& getBetterMatch(const MatchPair& match1, const MatchPair& match2
2021
return match1;
2122
}
2223

24+
const bool isValidMatchPair(const MatchPair& match) {
25+
if (!match.first || !match.second)
26+
return false;
27+
28+
// Check that all required error components are finite
29+
return edm::isFinite(match.first->xErr) && edm::isFinite(match.first->yErr) && edm::isFinite(match.first->dXdZErr) &&
30+
edm::isFinite(match.first->dYdZErr) && edm::isFinite(match.second->xErr) &&
31+
edm::isFinite(match.second->yErr) && edm::isFinite(match.second->dXdZErr) &&
32+
edm::isFinite(match.second->dYdZErr);
33+
}
34+
2335
float dX(const MatchPair& match) {
2436
if (match.first and match.second->hasPhi())
2537
return (match.first->x - match.second->x);
@@ -28,14 +40,14 @@ float dX(const MatchPair& match) {
2840
}
2941

3042
float pullX(const MatchPair& match) {
31-
if (match.first and match.second->hasPhi())
43+
if (match.first and match.second->hasPhi() and isValidMatchPair(match))
3244
return dX(match) / sqrt(pow(match.first->xErr, 2) + pow(match.second->xErr, 2));
3345
else
3446
return 9999.;
3547
}
3648

3749
float pullDxDz(const MatchPair& match) {
38-
if (match.first and match.second->hasPhi())
50+
if (match.first and match.second->hasPhi() and isValidMatchPair(match))
3951
return (match.first->dXdZ - match.second->dXdZ) /
4052
sqrt(pow(match.first->dXdZErr, 2) + pow(match.second->dXdZErr, 2));
4153
else
@@ -50,14 +62,14 @@ float dY(const MatchPair& match) {
5062
}
5163

5264
float pullY(const MatchPair& match) {
53-
if (match.first and match.second->hasZed())
65+
if (match.first and match.second->hasZed() and isValidMatchPair(match))
5466
return dY(match) / sqrt(pow(match.first->yErr, 2) + pow(match.second->yErr, 2));
5567
else
5668
return 9999.;
5769
}
5870

5971
float pullDyDz(const MatchPair& match) {
60-
if (match.first and match.second->hasZed())
72+
if (match.first and match.second->hasZed() and isValidMatchPair(match))
6173
return (match.first->dYdZ - match.second->dYdZ) /
6274
sqrt(pow(match.first->dYdZErr, 2) + pow(match.second->dYdZErr, 2));
6375
else

0 commit comments

Comments
 (0)