Skip to content

Commit fb54b44

Browse files
committed
MuonHLTSeedMVAClassifier: improved identification of the MVA files
1 parent e2e21e7 commit fb54b44

File tree

3 files changed

+57
-26
lines changed

3 files changed

+57
-26
lines changed

RecoMuon/TrackerSeedGenerator/interface/SeedMvaEstimator.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,24 @@ namespace edm {
2020
class FileInPath;
2121
}
2222

23+
namespace {
24+
enum inputIndexes {
25+
kTsosErr0, // 0
26+
kTsosErr2, // 1
27+
kTsosErr5, // 2
28+
kTsosDxdz, // 3
29+
kTsosDydz, // 4
30+
kTsosQbp, // 5
31+
kDRdRL1SeedP, // 6
32+
kDPhidRL1SeedP, // 7
33+
kLastL1, // 8
34+
35+
kDRdRL2SeedP = 8, // 8
36+
kDPhidRL2SeedP, // 9
37+
kLastL2, // 10
38+
};
39+
} // namespace
40+
2341
class SeedMvaEstimator {
2442
public:
2543
SeedMvaEstimator(const edm::FileInPath& weightsfile,

RecoMuon/TrackerSeedGenerator/plugins/MuonHLTSeedMVAClassifier.cc

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// system include files
99
#include <memory>
1010
#include <cmath>
11+
#include <tinyxml2.h>
1112

1213
// user include files
1314
#include "FWCore/Framework/interface/Frameworkfwd.h"
@@ -23,6 +24,8 @@
2324
#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
2425
#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
2526

27+
#include "CommonTools/MVAUtils/interface/TMVAZipReader.h"
28+
2629
// TrajectorySeed
2730
#include "DataFormats/TrajectorySeed/interface/TrajectorySeed.h"
2831
#include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
@@ -44,6 +47,7 @@ class MuonHLTSeedMVAClassifier : public edm::stream::EDProducer<> {
4447
~MuonHLTSeedMVAClassifier() override = default;
4548

4649
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
50+
bool checkMVAFileConsistency(const std::string& weightsFileFullPath, bool isFromL1) const;
4751

4852
private:
4953
void produce(edm::Event&, const edm::EventSetup&) override;
@@ -87,6 +91,38 @@ class MuonHLTSeedMVAClassifier : public edm::stream::EDProducer<> {
8791
const reco::RecoChargedCandidateCollection& l2Muons);
8892
};
8993

94+
bool MuonHLTSeedMVAClassifier::checkMVAFileConsistency(const std::string& weightsFileFullPath,
95+
const bool isFromL1) const {
96+
tinyxml2::XMLDocument xmlDoc;
97+
if (reco::details::hasEnding(weightsFileFullPath, ".xml")) {
98+
xmlDoc.LoadFile(weightsFileFullPath.c_str());
99+
} else {
100+
edm::LogError("MuonHLTSeedMVAClassifier") << "unsupported file extension, it should be a .xml file!";
101+
return false;
102+
}
103+
tinyxml2::XMLElement* root = xmlDoc.FirstChildElement("MethodSetup");
104+
if (root == nullptr) {
105+
edm::LogError("MuonHLTSeedMVAClassifier") << "could not retrieve the MethodSetup node from XML file!";
106+
return false;
107+
}
108+
109+
const auto& vars = root->FirstChildElement("Variables");
110+
size_t n = 0;
111+
if (vars != nullptr) {
112+
for (tinyxml2::XMLElement* e = vars->FirstChildElement("Variable"); e != nullptr;
113+
e = e->NextSiblingElement("Variable")) {
114+
++n;
115+
}
116+
} else {
117+
edm::LogError("MuonHLTSeedMVAClassifier") << "could not retrieve the Variables node from XML file!";
118+
return false;
119+
}
120+
121+
LogTrace("MuonHLTSeedMVAClassifier") << "MVA file:" << weightsFileFullPath.c_str() << " n Var:" << n;
122+
bool condition = (isFromL1 && (n == inputIndexes::kLastL1)) || (!isFromL1 && (n == inputIndexes::kLastL2));
123+
return condition;
124+
}
125+
90126
MuonHLTSeedMVAClassifier::MuonHLTSeedMVAClassifier(const edm::ParameterSet& iConfig)
91127
: seedToken_(consumes<TrajectorySeedCollection>(iConfig.getParameter<edm::InputTag>("src"))),
92128
l1MuonToken_(consumes<l1t::MuonBxCollection>(iConfig.getParameter<edm::InputTag>("L1Muon"))),
@@ -111,14 +147,9 @@ MuonHLTSeedMVAClassifier::MuonHLTSeedMVAClassifier(const edm::ParameterSet& iCon
111147
const auto& mvaFileBPath = mvaFileB_.fullPath();
112148
const auto& mvaFileEPath = mvaFileE_.fullPath();
113149

114-
if (!isFromL1_ and
115-
((mvaFileBPath.find("FromL1") != std::string::npos) or (mvaFileEPath.find("FromL1") != std::string::npos))) {
116-
throw cms::Exception("ConfigurationError")
117-
<< " isFromL1 parameter is False, but using FromL1 MVA files.\n Please check your configuration";
118-
} else if (isFromL1_ and ((mvaFileBPath.find("FromL1") == std::string::npos) or
119-
(mvaFileEPath.find("FromL1") == std::string::npos))) {
120-
throw cms::Exception("ConfigurationError")
121-
<< " isFromL1 parameter is True, but not using FromL1 MVA files.\n Please check your configuration";
150+
if (!checkMVAFileConsistency(mvaFileBPath, isFromL1_) || !checkMVAFileConsistency(mvaFileEPath, isFromL1_)) {
151+
throw cms::Exception("ConfigurationError") << " MVA files appear to be not consistent with the value of isFromL1 "
152+
"parameter.\n Please check your configuration.";
122153
}
123154

124155
if (!rejectAll_) {

RecoMuon/TrackerSeedGenerator/src/SeedMvaEstimator.cc

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,6 @@ SeedMvaEstimator::SeedMvaEstimator(const edm::FileInPath& weightsfile,
2020

2121
SeedMvaEstimator::~SeedMvaEstimator() {}
2222

23-
namespace {
24-
enum inputIndexes {
25-
kTsosErr0, // 0
26-
kTsosErr2, // 1
27-
kTsosErr5, // 2
28-
kTsosDxdz, // 3
29-
kTsosDydz, // 4
30-
kTsosQbp, // 5
31-
kDRdRL1SeedP, // 6
32-
kDPhidRL1SeedP, // 7
33-
kLastL1, // 8
34-
35-
kDRdRL2SeedP = 8, // 8
36-
kDPhidRL2SeedP, // 9
37-
kLastL2, // 10
38-
};
39-
} // namespace
40-
4123
void SeedMvaEstimator::getL1MuonVariables(const GlobalVector& global_p,
4224
const l1t::MuonBxCollection& l1Muons,
4325
float& dR2dRL1SeedP,

0 commit comments

Comments
 (0)