Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplifying LL1TkMuonFilter, CMSSW_12_5_X #39281

Merged
merged 2 commits into from
Sep 5, 2022
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
71 changes: 19 additions & 52 deletions HLTrigger/HLTfilters/plugins/L1TTkMuonFilter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/EventSetupRecord.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Utilities/interface/Exception.h"

#include <algorithm>
//
// constructors and destructor
//
Expand All @@ -45,18 +47,25 @@ namespace {
L1TTkMuonFilter::L1TTkMuonFilter(const edm::ParameterSet& iConfig)
: HLTFilter(iConfig),
l1TkMuonTag_(iConfig.getParameter<edm::InputTag>("inputTag")),
tkMuonToken_(consumes<l1t::TrackerMuonCollection>(l1TkMuonTag_)),
qualityCut_(iConfig.getParameter<edm::ParameterSet>("qualities")) {
tkMuonToken_(consumes(l1TkMuonTag_)) {
min_Pt_ = iConfig.getParameter<double>("MinPt");
min_N_ = iConfig.getParameter<int>("MinN");
min_Eta_ = iConfig.getParameter<double>("MinEta");
max_Eta_ = iConfig.getParameter<double>("MaxEta");
applyQuality_ = iConfig.getParameter<bool>("applyQuality");
applyDuplicateRemoval_ = iConfig.getParameter<bool>("applyDuplicateRemoval");
qualities_ = iConfig.getParameter<std::vector<int>>("qualities");
scalings_ = iConfig.getParameter<edm::ParameterSet>("Scalings");
barrelScalings_ = scalings_.getParameter<std::vector<double>>("barrel");
overlapScalings_ = scalings_.getParameter<std::vector<double>>("overlap");
endcapScalings_ = scalings_.getParameter<std::vector<double>>("endcap");

std::sort(qualities_.begin(), qualities_.end());

if (applyQuality_ && qualities_.empty()) {
throw cms::Exception("InvalidConfiguration")
<< "If you want to applyQuality the qualities vector should not be empty!";
}
}

L1TTkMuonFilter::~L1TTkMuonFilter() = default;
Expand All @@ -75,8 +84,7 @@ void L1TTkMuonFilter::fillDescriptions(edm::ConfigurationDescriptions& descripti
desc.add<edm::InputTag>("inputTag", edm::InputTag("L1TkMuons"));
desc.add<bool>("applyQuality", false);
desc.add<bool>("applyDuplicateRemoval", true);
desc.add<edm::ParameterSetDescription>("qualities", MuonQualityCut::makePSetDescription());

desc.add<std::vector<int>>("qualities", {});
edm::ParameterSetDescription descScalings;
descScalings.add<std::vector<double>>("barrel", {0.0, 1.0, 0.0});
descScalings.add<std::vector<double>>("overlap", {0.0, 1.0, 0.0});
Expand Down Expand Up @@ -118,7 +126,13 @@ bool L1TTkMuonFilter::hltFilter(edm::Event& iEvent,
l1t::TrackerMuonCollection::const_iterator itkMuon;
for (itkMuon = atrkmuons; itkMuon != otrkmuons; itkMuon++) {
double offlinePt = this->TkMuonOfflineEt(itkMuon->phPt(), itkMuon->phEta());
bool passesQual = !applyQuality_ || qualityCut_(*itkMuon);

// The muonDetector() and quality() methods are not available for TrackerMuon
// as they were for TkMuon (TkMuon being the old implementation, at the times
// of the HLT-TDR). So we fall back to the hwQual() method inherited from
// L1Candidate, and compare it with a vector of allowed qualities.
bool passesQual = !applyQuality_ || std::binary_search(qualities_.begin(), qualities_.end(), itkMuon->hwQual());

if (passesQual && offlinePt >= min_Pt_ && itkMuon->phEta() <= max_Eta_ && itkMuon->phEta() >= min_Eta_) {
l1t::TrackerMuonRef ref(tkMuons, distance(atrkmuons, itkMuon));
if (!applyDuplicateRemoval_ || !isDupMuon(ref, passingMuons)) {
Expand All @@ -135,53 +149,6 @@ bool L1TTkMuonFilter::hltFilter(edm::Event& iEvent,
return accept;
}

L1TTkMuonFilter::MuonQualityCut::MuonQualityCut(const edm::ParameterSet& iConfig) {
auto detQualities = iConfig.getParameter<std::vector<edm::ParameterSet>>("values");
for (const auto& detQuality : detQualities) {
auto dets = detQuality.getParameter<std::vector<int>>("detectors");
auto qualities = detQuality.getParameter<std::vector<int>>("qualities");
std::sort(qualities.begin(), qualities.end());
for (const auto& det : dets) {
allowedQualities_.insert({det, std::move(qualities)});
}
}
}

bool L1TTkMuonFilter::MuonQualityCut::operator()(const l1t::TrackerMuon& muon) const {
// If we didn't load any qualities from the config file, that means we don't care.
// So we set passesQuality to true.
if (allowedQualities_.empty()) {
return true;
}

bool passesQuality(false);
// The muonDetector() method is not available for TrackerMuon (it was available in TkMuon),
// so for the time being we just take the union of all quality vectors for all muon detectors.
for (const auto& detQuality : allowedQualities_) {
passesQuality |= std::binary_search(detQuality.second.begin(), detQuality.second.end(), muon.hwQual());
}

return passesQuality;
}

void L1TTkMuonFilter::MuonQualityCut::fillPSetDescription(edm::ParameterSetDescription& desc) {
edm::ParameterSetDescription detQualDesc;
detQualDesc.add<std::vector<int>>("detectors", {-99});
detQualDesc.add<std::vector<int>>("qualities", {-99, -99, -99});
std::vector<edm::ParameterSet> detQualDefaults;
edm::ParameterSet detQualDefault;
detQualDefault.addParameter<std::vector<int>>("detectors", {-99});
detQualDefault.addParameter<std::vector<int>>("qualities", {-99, -99, -99});
detQualDefaults.push_back(detQualDefault);
desc.addVPSet("values", detQualDesc, detQualDefaults);
}

edm::ParameterSetDescription L1TTkMuonFilter::MuonQualityCut::makePSetDescription() {
edm::ParameterSetDescription desc;
fillPSetDescription(desc);
return desc;
}

double L1TTkMuonFilter::TkMuonOfflineEt(double Et, double Eta) const {
if (std::abs(Eta) < 0.9)
return (barrelScalings_.at(0) + Et * barrelScalings_.at(1) + Et * Et * barrelScalings_.at(2));
Expand Down
16 changes: 2 additions & 14 deletions HLTrigger/HLTfilters/plugins/L1TTkMuonFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,21 @@ class L1TTkMuonFilter : public HLTFilter {
trigger::TriggerFilterObjectWithRefs& filterproduct) const override;

private:
class MuonQualityCut {
public:
MuonQualityCut(const edm::ParameterSet&);
bool operator()(const l1t::TrackerMuon&) const;
static void fillPSetDescription(edm::ParameterSetDescription& desc);
static edm::ParameterSetDescription makePSetDescription();

private:
std::unordered_map<int, std::vector<int>> allowedQualities_;
};

edm::InputTag l1TkMuonTag_; //input tag for L1 TrackerMuon product
edm::EDGetTokenT<l1t::TrackerMuonCollection> tkMuonToken_; // token identifying product containing L1 TrackerMuons

double min_Pt_; // min pt cut
int min_N_; // min number of candidates above pT cut
double min_Eta_; // min eta cut
double max_Eta_; // max eta cut
bool applyQuality_; // apply quaility cuts
bool applyQuality_; // apply quality cuts
bool applyDuplicateRemoval_; // apply duplicate removal
std::vector<int> qualities_; // allowed qualities
edm::ParameterSet scalings_; // all scalings. An indirection level allows extra flexibility
std::vector<double> barrelScalings_; // barrel scalings
std::vector<double> overlapScalings_; // overlap scalings
std::vector<double> endcapScalings_; // endcap scalings

MuonQualityCut qualityCut_;

double TkMuonOfflineEt(double Et, double Eta) const;
};

Expand Down