Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions HLTrigger/Configuration/python/customizeHLTforCMSSW.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,53 @@ def customizeHLTfor44576(process):
break
return process

def customizeHLTfor45063(process):
"""Assigns value of MuonHLTSeedMVAClassifier mva input file, scales and mean values according to the value of isFromL1"""
for prod in producers_by_type(process, 'MuonHLTSeedMVAClassifier'):
if hasattr(prod, "isFromL1"):
if (prod.isFromL1 == True):
if hasattr(prod, "mvaFileBL1"):
prod.mvaFileB = prod.mvaFileBL1
if hasattr(prod, "mvaFileEL1"):
prod.mvaFileE = prod.mvaFileEL1
if hasattr(prod, "mvaScaleMeanBL1"):
prod.mvaScaleMeanB = prod.mvaScaleMeanBL1
if hasattr(prod, "mvaScaleStdBL1"):
prod.mvaScaleStdB = prod.mvaScaleStdBL1
if hasattr(prod, "mvaScaleMeanEL1"):
prod.mvaScaleMeanE = prod.mvaScaleMeanEL1
if hasattr(prod, "mvaScaleStdEL1"):
prod.mvaScaleStdE = prod.mvaScaleStdEL1
else:
if hasattr(prod, "mvaFileBL2"):
prod.mvaFileB = prod.mvaFileBL2
if hasattr(prod, "mvaFileEL2"):
prod.mvaFileE = prod.mvaFileEL2
if hasattr(prod, "mvaScaleMeanBL2"):
prod.mvaScaleMeanB = prod.mvaScaleMeanBL2
if hasattr(prod, "mvaScaleStdBL2"):
prod.mvaScaleStdB = prod.mvaScaleStdBL2
if hasattr(prod, "mvaScaleMeanEL2"):
prod.mvaScaleMeanE = prod.mvaScaleMeanEL2
if hasattr(prod, "mvaScaleStdEL2"):
prod.mvaScaleStdE = prod.mvaScaleStdEL2

for prod in producers_by_type(process, 'MuonHLTSeedMVAClassifier'):
delattr(prod,"mvaFileBL1")
delattr(prod,"mvaFileEL1")
delattr(prod,"mvaScaleMeanBL1")
delattr(prod,"mvaScaleStdBL1")
delattr(prod,"mvaScaleMeanEL1")
delattr(prod,"mvaScaleStdEL1")
delattr(prod,"mvaFileBL2")
delattr(prod,"mvaFileEL2")
delattr(prod,"mvaScaleMeanBL2")
delattr(prod,"mvaScaleStdBL2")
delattr(prod,"mvaScaleMeanEL2")
delattr(prod,"mvaScaleStdEL2")

return process

# CMSSW version specific customizations
def customizeHLTforCMSSW(process, menuType="GRun"):

Expand All @@ -278,5 +325,6 @@ def customizeHLTforCMSSW(process, menuType="GRun"):

process = checkHLTfor43774(process)
process = customizeHLTfor44576(process)
process = customizeHLTfor45063(process)

return process
18 changes: 18 additions & 0 deletions RecoMuon/TrackerSeedGenerator/interface/SeedMvaEstimator.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ namespace edm {
class FileInPath;
}

namespace {
enum inputIndexes {
kTsosErr0, // 0
kTsosErr2, // 1
kTsosErr5, // 2
kTsosDxdz, // 3
kTsosDydz, // 4
kTsosQbp, // 5
kDRdRL1SeedP, // 6
kDPhidRL1SeedP, // 7
kLastL1, // 8

kDRdRL2SeedP = 8, // 8
kDPhidRL2SeedP, // 9
kLastL2, // 10
};
} // namespace

class SeedMvaEstimator {
public:
SeedMvaEstimator(const edm::FileInPath& weightsfile,
Expand Down
82 changes: 56 additions & 26 deletions RecoMuon/TrackerSeedGenerator/plugins/MuonHLTSeedMVAClassifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// system include files
#include <memory>
#include <cmath>
#include <tinyxml2.h>

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
Expand All @@ -23,6 +24,8 @@
#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"

#include "CommonTools/MVAUtils/interface/TMVAZipReader.h"

// TrajectorySeed
#include "DataFormats/TrajectorySeed/interface/TrajectorySeed.h"
#include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
Expand All @@ -44,6 +47,7 @@ class MuonHLTSeedMVAClassifier : public edm::stream::EDProducer<> {
~MuonHLTSeedMVAClassifier() override = default;

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

private:
void produce(edm::Event&, const edm::EventSetup&) override;
Expand Down Expand Up @@ -87,33 +91,67 @@ class MuonHLTSeedMVAClassifier : public edm::stream::EDProducer<> {
const reco::RecoChargedCandidateCollection& l2Muons);
};

bool MuonHLTSeedMVAClassifier::checkMVAFileConsistency(const std::string& weightsFileFullPath,
const bool isFromL1) const {
tinyxml2::XMLDocument xmlDoc;
if (reco::details::hasEnding(weightsFileFullPath, ".xml")) {
xmlDoc.LoadFile(weightsFileFullPath.c_str());
} else {
edm::LogError("MuonHLTSeedMVAClassifier") << "unsupported file extension, it should be a .xml file!";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe return false after LogError ? (or convert to an exception ?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed in the last push: fb54b44

return false;
}
tinyxml2::XMLElement* root = xmlDoc.FirstChildElement("MethodSetup");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe return false if root == nullptr ? (not sure if it's possible that the pointer is null)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed in the last push: fb54b44

if (root == nullptr) {
edm::LogError("MuonHLTSeedMVAClassifier") << "could not retrieve the MethodSetup node from XML file!";
return false;
}

const auto& vars = root->FirstChildElement("Variables");
size_t n = 0;
if (vars != nullptr) {
for (tinyxml2::XMLElement* e = vars->FirstChildElement("Variable"); e != nullptr;
e = e->NextSiblingElement("Variable")) {
++n;
}
} else {
edm::LogError("MuonHLTSeedMVAClassifier") << "could not retrieve the Variables node from XML file!";
return false;
}

LogTrace("MuonHLTSeedMVAClassifier") << "MVA file:" << weightsFileFullPath.c_str() << " n Var:" << n;
bool condition = (isFromL1 && (n == inputIndexes::kLastL1)) || (!isFromL1 && (n == inputIndexes::kLastL2));
return condition;
}

MuonHLTSeedMVAClassifier::MuonHLTSeedMVAClassifier(const edm::ParameterSet& iConfig)
: seedToken_(consumes<TrajectorySeedCollection>(iConfig.getParameter<edm::InputTag>("src"))),
l1MuonToken_(consumes<l1t::MuonBxCollection>(iConfig.getParameter<edm::InputTag>("L1Muon"))),
l2MuonToken_(consumes<reco::RecoChargedCandidateCollection>(iConfig.getParameter<edm::InputTag>("L2Muon"))),
trackerGeometryToken_(esConsumes<TrackerGeometry, TrackerDigiGeometryRecord>()),

rejectAll_(iConfig.getParameter<bool>("rejectAll")),
isFromL1_(iConfig.getParameter<bool>("isFromL1")),

mvaFileB_(iConfig.getParameter<edm::FileInPath>(isFromL1_ ? "mvaFileBL1" : "mvaFileBL2")),
mvaFileE_(iConfig.getParameter<edm::FileInPath>(isFromL1_ ? "mvaFileEL1" : "mvaFileEL2")),

mvaScaleMeanB_(iConfig.getParameter<std::vector<double>>(isFromL1_ ? "mvaScaleMeanBL1" : "mvaScaleMeanBL2")),
mvaScaleStdB_(iConfig.getParameter<std::vector<double>>(isFromL1_ ? "mvaScaleStdBL1" : "mvaScaleStdBL2")),
mvaScaleMeanE_(iConfig.getParameter<std::vector<double>>(isFromL1_ ? "mvaScaleMeanEL1" : "mvaScaleMeanEL2")),
mvaScaleStdE_(iConfig.getParameter<std::vector<double>>(isFromL1_ ? "mvaScaleStdEL1" : "mvaScaleStdEL2")),

mvaFileB_(iConfig.getParameter<edm::FileInPath>("mvaFileB")),
mvaFileE_(iConfig.getParameter<edm::FileInPath>("mvaFileE")),
mvaScaleMeanB_(iConfig.getParameter<std::vector<double>>("mvaScaleMeanB")),
mvaScaleStdB_(iConfig.getParameter<std::vector<double>>("mvaScaleStdB")),
mvaScaleMeanE_(iConfig.getParameter<std::vector<double>>("mvaScaleMeanE")),
mvaScaleStdE_(iConfig.getParameter<std::vector<double>>("mvaScaleStdE")),
doSort_(iConfig.getParameter<bool>("doSort")),
nSeedsMaxB_(iConfig.getParameter<int>("nSeedsMaxB")),
nSeedsMaxE_(iConfig.getParameter<int>("nSeedsMaxE")),

etaEdge_(iConfig.getParameter<double>("etaEdge")),
mvaCutB_(iConfig.getParameter<double>("mvaCutB")),
mvaCutE_(iConfig.getParameter<double>("mvaCutE")),

minL1Qual_(iConfig.getParameter<int>("minL1Qual")),
baseScore_(iConfig.getParameter<double>("baseScore")) {
const auto& mvaFileBPath = mvaFileB_.fullPath();
const auto& mvaFileEPath = mvaFileE_.fullPath();

if (!checkMVAFileConsistency(mvaFileBPath, isFromL1_) || !checkMVAFileConsistency(mvaFileEPath, isFromL1_)) {
throw cms::Exception("ConfigurationError") << " MVA files appear to be not consistent with the value of isFromL1 "
"parameter.\n Please check your configuration.";
}

if (!rejectAll_) {
mvaEstimator_ = std::make_pair(
std::make_unique<SeedMvaEstimator>(mvaFileB_, mvaScaleMeanB_, mvaScaleStdB_, isFromL1_, minL1Qual_),
Expand Down Expand Up @@ -247,22 +285,14 @@ void MuonHLTSeedMVAClassifier::fillDescriptions(edm::ConfigurationDescriptions&
desc.add<bool>("rejectAll", false);
desc.add<bool>("isFromL1", false);

desc.add<edm::FileInPath>("mvaFileBL1",
desc.add<edm::FileInPath>("mvaFileB",
edm::FileInPath("RecoMuon/TrackerSeedGenerator/data/xgb_Run3_Iter2FromL1Seeds_barrel.xml"));
desc.add<edm::FileInPath>("mvaFileEL1",
desc.add<edm::FileInPath>("mvaFileE",
edm::FileInPath("RecoMuon/TrackerSeedGenerator/data/xgb_Run3_Iter2FromL1Seeds_endcap.xml"));
desc.add<edm::FileInPath>("mvaFileBL2",
edm::FileInPath("RecoMuon/TrackerSeedGenerator/data/xgb_Run3_Iter2Seeds_barrel.xml"));
desc.add<edm::FileInPath>("mvaFileEL2",
edm::FileInPath("RecoMuon/TrackerSeedGenerator/data/xgb_Run3_Iter2Seeds_endcap.xml"));
desc.add<std::vector<double>>("mvaScaleMeanBL1", {0., 0., 0., 0., 0., 0., 0., 0.});
desc.add<std::vector<double>>("mvaScaleStdBL1", {1., 1., 1., 1., 1., 1., 1., 1.});
desc.add<std::vector<double>>("mvaScaleMeanEL1", {0., 0., 0., 0., 0., 0., 0., 0.});
desc.add<std::vector<double>>("mvaScaleStdEL1", {1., 1., 1., 1., 1., 1., 1., 1.});
desc.add<std::vector<double>>("mvaScaleMeanBL2", {0., 0., 0., 0., 0., 0., 0., 0., 0., 0.});
desc.add<std::vector<double>>("mvaScaleStdBL2", {1., 1., 1., 1., 1., 1., 1., 1., 1., 1.});
desc.add<std::vector<double>>("mvaScaleMeanEL2", {0., 0., 0., 0., 0., 0., 0., 0., 0., 0.});
desc.add<std::vector<double>>("mvaScaleStdEL2", {1., 1., 1., 1., 1., 1., 1., 1., 1., 1.});
desc.add<std::vector<double>>("mvaScaleMeanB", {0., 0., 0., 0., 0., 0., 0., 0.});
desc.add<std::vector<double>>("mvaScaleStdB", {1., 1., 1., 1., 1., 1., 1., 1.});
desc.add<std::vector<double>>("mvaScaleMeanE", {0., 0., 0., 0., 0., 0., 0., 0.});
desc.add<std::vector<double>>("mvaScaleStdE", {1., 1., 1., 1., 1., 1., 1., 1.});

desc.add<bool>("doSort", false);
desc.add<int>("nSeedsMaxB", 1e6);
Expand Down
18 changes: 0 additions & 18 deletions RecoMuon/TrackerSeedGenerator/src/SeedMvaEstimator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,6 @@ SeedMvaEstimator::SeedMvaEstimator(const edm::FileInPath& weightsfile,

SeedMvaEstimator::~SeedMvaEstimator() {}

namespace {
enum inputIndexes {
kTsosErr0, // 0
kTsosErr2, // 1
kTsosErr5, // 2
kTsosDxdz, // 3
kTsosDydz, // 4
kTsosQbp, // 5
kDRdRL1SeedP, // 6
kDPhidRL1SeedP, // 7
kLastL1, // 8

kDRdRL2SeedP = 8, // 8
kDPhidRL2SeedP, // 9
kLastL2, // 10
};
} // namespace

void SeedMvaEstimator::getL1MuonVariables(const GlobalVector& global_p,
const l1t::MuonBxCollection& l1Muons,
float& dR2dRL1SeedP,
Expand Down