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"
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
4852private:
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+
90126MuonHLTSeedMVAClassifier::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_) {
0 commit comments