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

Removing not used muon MVAs from miniAOD (backport) #41043

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
10 changes: 0 additions & 10 deletions DataFormats/PatCandidates/interface/Muon.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,6 @@ namespace pat {
void setJetPtRatio(float jetPtRatio) { jetPtRatio_ = jetPtRatio; }
void setJetPtRel(float jetPtRel) { jetPtRel_ = jetPtRel; }

/// Muon MVA
float mvaValue() const { return mvaValue_; }
void setMvaValue(float mva) { mvaValue_ = mva; }

// Low pt Muon MVA
float lowptMvaValue() const { return lowptMvaValue_; }
void setLowPtMvaValue(float lowptmva) { lowptMvaValue_ = lowptmva; }

/// Soft Muon MVA
float softMvaValue() const { return softMvaValue_; }
void setSoftMvaValue(float softmva) { softMvaValue_ = softmva; }
Expand Down Expand Up @@ -420,8 +412,6 @@ namespace pat {
float jetPtRel_;

/// Muon MVA
float mvaValue_;
float lowptMvaValue_;
float mvaIDValue_;
float softMvaValue_;

Expand Down
8 changes: 0 additions & 8 deletions DataFormats/PatCandidates/src/Muon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ Muon::Muon()
pfEcalEnergy_(0),
jetPtRatio_(0),
jetPtRel_(0),
mvaValue_(0),
lowptMvaValue_(0),
mvaIDValue_(0),
softMvaValue_(0),
inverseBeta_(0),
Expand Down Expand Up @@ -63,8 +61,6 @@ Muon::Muon(const reco::Muon& aMuon)
pfEcalEnergy_(0),
jetPtRatio_(0),
jetPtRel_(0),
mvaValue_(0),
lowptMvaValue_(0),
mvaIDValue_(0),
softMvaValue_(0),
inverseBeta_(0),
Expand Down Expand Up @@ -95,8 +91,6 @@ Muon::Muon(const edm::RefToBase<reco::Muon>& aMuonRef)
pfEcalEnergy_(0),
jetPtRatio_(0),
jetPtRel_(0),
mvaValue_(0),
lowptMvaValue_(0),
mvaIDValue_(0),
softMvaValue_(0),
inverseBeta_(0),
Expand Down Expand Up @@ -127,8 +121,6 @@ Muon::Muon(const edm::Ptr<reco::Muon>& aMuonRef)
pfEcalEnergy_(0),
jetPtRatio_(0),
jetPtRel_(0),
mvaValue_(0),
lowptMvaValue_(0),
mvaIDValue_(0),
softMvaValue_(0),
inverseBeta_(0),
Expand Down
3 changes: 2 additions & 1 deletion DataFormats/PatCandidates/src/classes_def_objects.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
</ioread>


<class name="pat::Muon" ClassVersion="29">
<class name="pat::Muon" ClassVersion="30">
<version ClassVersion="30" checksum="3276039509"/>
<version ClassVersion="29" checksum="4221614933"/>
<version ClassVersion="28" checksum="282262684"/>
<version ClassVersion="27" checksum="3473399161"/>
Expand Down
2 changes: 0 additions & 2 deletions PhysicsTools/NanoAOD/python/muons_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@
highPtId = Var("?passed('CutBasedIdGlobalHighPt')?2:passed('CutBasedIdTrkHighPt')","uint8",doc="high-pT cut-based ID (1 = tracker high pT, 2 = global high pT, which includes tracker high pT)"),
pfIsoId = Var("passed('PFIsoVeryLoose')+passed('PFIsoLoose')+passed('PFIsoMedium')+passed('PFIsoTight')+passed('PFIsoVeryTight')+passed('PFIsoVeryVeryTight')","uint8",doc="PFIso ID from miniAOD selector (1=PFIsoVeryLoose, 2=PFIsoLoose, 3=PFIsoMedium, 4=PFIsoTight, 5=PFIsoVeryTight, 6=PFIsoVeryVeryTight)"),
tkIsoId = Var("?passed('TkIsoTight')?2:passed('TkIsoLoose')","uint8",doc="TkIso ID (1=TkIsoLoose, 2=TkIsoTight)"),
mvaId = Var("passed('MvaLoose')+passed('MvaMedium')+passed('MvaTight')+passed('MvaVTight')+passed('MvaVVTight')","uint8",doc="Mva for ID of prompt leptons from miniAOD selector (1=MvaLoose, 2=MvaMedium, 3=MvaTight, 4=MvaVTight, 5=MvaVVTight)"),
mvaLowPtId = Var("passed('LowPtMvaLoose')+passed('LowPtMvaMedium')","uint8", doc="Low Pt Mva ID from miniAOD selector (1=LowPtMvaLoose, 2=LowPtMvaMedium)"),
miniIsoId = Var("passed('MiniIsoLoose')+passed('MiniIsoMedium')+passed('MiniIsoTight')+passed('MiniIsoVeryTight')","uint8",doc="MiniIso ID from miniAOD selector (1=MiniIsoLoose, 2=MiniIsoMedium, 3=MiniIsoTight, 4=MiniIsoVeryTight)"),
mvaMuID = Var("mvaIDValue()",float,doc="MVA-based ID score ",precision=6),
mvaMuID_WP = Var("userFloat('mvaIDMuon_wpMedium') + userFloat('mvaIDMuon_wpTight')","uint8",doc="MVA-based ID selector WPs (1=MVAIDwpMedium,2=MVAIDwpTight)"),
Expand Down
2 changes: 0 additions & 2 deletions PhysicsTools/NanoAOD/python/nanoDQM_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,9 +523,7 @@
Plot1D('miniPFRelIso_all', 'miniPFRelIso_all', 20, 0, 1, 'mini PF relative isolation, total (with scaled rho*EA PU corrections)'),
Plot1D('miniPFRelIso_chg', 'miniPFRelIso_chg', 20, 0, 1, 'mini PF relative isolation, charged component'),
Plot1D('multiIsoId', 'multiIsoId', 3, -0.5, 2.5, 'MultiIsoId from miniAOD selector (1=MultiIsoLoose, 2=MultiIsoMedium)'),
Plot1D('mvaId', 'mvaId', 6, -0.5, 5.5, 'Mva ID from miniAOD selector (1=MvaLoose, 2=MvaMedium, 3=MvaTight, 4=MvaVTight, 5=MvaVVTight)'),
Plot1D('mvaLowPt', 'mvaLowPt', 20, -1, 1, 'Low pt muon ID score'),
Plot1D('mvaLowPtId', 'mvaLowPtId', 3, -0.5, 2.5, 'Low Pt Mva ID from miniAOD selector (1=LowPtMvaLoose, 2=LowPtMvaMedium)'),
Plot1D('mvaTTH', 'mvaTTH', 20, -1, 1, 'TTH MVA lepton ID score'),
Plot1D('mvaMuID', 'mvaMuID', 20, 0, 1, 'Score of MVA-based muon ID'),
Plot1D('mvaMuID_WP', 'mvaMuID_WP', 3, -0.5, 2.5, 'MVA-based ID selector WPs (1=MVAIDwpMedium,2=MVAIDwpTight)'),
Expand Down
33 changes: 33 additions & 0 deletions PhysicsTools/PatAlgos/interface/CalculatePtRatioRel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef __PhysicsTools_PatAlgos_CalculatePtRatioRel__
#define __PhysicsTools_PatAlgos_CalculatePtRatioRel__

#include "DataFormats/BTauReco/interface/JetTag.h"

#include <memory>
#include <string>

namespace pat {
class Muon;
}

namespace reco {
class JetCorrector;
} // namespace reco

namespace pat {
class CalculatePtRatioRel {
public:
CalculatePtRatioRel(float dR2max);

~CalculatePtRatioRel();

std::array<float, 2> computePtRatioRel(const pat::Muon& imuon,
const reco::JetTagCollection& bTags,
const reco::JetCorrector* correctorL1 = nullptr,
const reco::JetCorrector* correctorL1L2L3Res = nullptr) const;

private:
float dR2max_;
};
} // namespace pat
#endif
45 changes: 0 additions & 45 deletions PhysicsTools/PatAlgos/interface/MuonMvaEstimator.h

This file was deleted.

93 changes: 19 additions & 74 deletions PhysicsTools/PatAlgos/plugins/PATMuonProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#include "PhysicsTools/PatAlgos/interface/EfficiencyLoader.h"
#include "PhysicsTools/PatAlgos/interface/KinResolutionsLoader.h"
#include "PhysicsTools/PatAlgos/interface/MultiIsolator.h"
#include "PhysicsTools/PatAlgos/interface/MuonMvaEstimator.h"
#include "PhysicsTools/PatAlgos/interface/CalculatePtRatioRel.h"
#include "PhysicsTools/PatAlgos/interface/MuonMvaIDEstimator.h"
#include "PhysicsTools/PatAlgos/interface/PATUserDataHelper.h"
#include "PhysicsTools/PatAlgos/interface/SoftMuonMvaEstimator.h"
Expand All @@ -58,14 +58,12 @@ namespace pat {
public:
PATMuonHeavyObjectCache(const edm::ParameterSet&);

pat::MuonMvaEstimator const& muonMvaEstimator() const { return *muonMvaEstimator_; }
pat::MuonMvaEstimator const& muonLowPtMvaEstimator() const { return *muonLowPtMvaEstimator_; }
pat::CalculatePtRatioRel const& calculatePtRatioRel() const { return *calculatePtRatioRel_; }
pat::MuonMvaIDEstimator const& muonMvaIDEstimator() const { return *muonMvaIDEstimator_; }
pat::SoftMuonMvaEstimator const& softMuonMvaEstimator() const { return *softMuonMvaEstimator_; }

private:
std::unique_ptr<const pat::MuonMvaEstimator> muonLowPtMvaEstimator_;
std::unique_ptr<const pat::MuonMvaEstimator> muonMvaEstimator_;
std::unique_ptr<const pat::CalculatePtRatioRel> calculatePtRatioRel_;
std::unique_ptr<const pat::MuonMvaIDEstimator> muonMvaIDEstimator_;
std::unique_ptr<const pat::SoftMuonMvaEstimator> softMuonMvaEstimator_;
};
Expand Down Expand Up @@ -234,11 +232,10 @@ namespace pat {
edm::EDGetTokenT<edm::ValueMap<float>> PUPPINoLeptonsIsolation_neutral_hadrons_;
edm::EDGetTokenT<edm::ValueMap<float>> PUPPINoLeptonsIsolation_photons_;
/// standard muon selectors
bool computeMuonMVA_;
bool computeMuonIDMVA_;
bool computeSoftMuonMVA_;
bool recomputeBasicSelectors_;
bool mvaUseJec_;
bool useJec_;
edm::EDGetTokenT<reco::JetTagCollection> mvaBTagCollectionTag_;
edm::EDGetTokenT<reco::JetCorrector> mvaL1Corrector_;
edm::EDGetTokenT<reco::JetCorrector> mvaL1L2L3ResCorrector_;
Expand Down Expand Up @@ -325,12 +322,9 @@ using namespace pat;
using namespace std;

PATMuonHeavyObjectCache::PATMuonHeavyObjectCache(const edm::ParameterSet& iConfig) {
if (iConfig.getParameter<bool>("computeMuonMVA")) {
edm::FileInPath mvaTrainingFile = iConfig.getParameter<edm::FileInPath>("mvaTrainingFile");
edm::FileInPath mvaLowPtTrainingFile = iConfig.getParameter<edm::FileInPath>("lowPtmvaTrainingFile");
if (iConfig.getParameter<bool>("computeMiniIso")) {
float mvaDrMax = iConfig.getParameter<double>("mvaDrMax");
muonMvaEstimator_ = std::make_unique<MuonMvaEstimator>(mvaTrainingFile, mvaDrMax);
muonLowPtMvaEstimator_ = std::make_unique<MuonMvaEstimator>(mvaLowPtTrainingFile, mvaDrMax);
calculatePtRatioRel_ = std::make_unique<CalculatePtRatioRel>(mvaDrMax * mvaDrMax);
}

if (iConfig.getParameter<bool>("computeMuonIDMVA")) {
Expand All @@ -347,11 +341,10 @@ PATMuonHeavyObjectCache::PATMuonHeavyObjectCache(const edm::ParameterSet& iConfi
PATMuonProducer::PATMuonProducer(const edm::ParameterSet& iConfig, PATMuonHeavyObjectCache const*)
: relMiniIsoPUCorrected_(0),
useUserData_(iConfig.exists("userData")),
computeMuonMVA_(false),
computeMuonIDMVA_(false),
computeSoftMuonMVA_(false),
recomputeBasicSelectors_(false),
mvaUseJec_(false),
useJec_(false),
isolator_(iConfig.getParameter<edm::ParameterSet>("userIsolation"), consumesCollector(), false),
geometryToken_{esConsumes()},
transientTrackBuilderToken_{esConsumes(edm::ESInputTag("", "TransientTrackBuilder"))},
Expand Down Expand Up @@ -460,18 +453,15 @@ PATMuonProducer::PATMuonProducer(const edm::ParameterSet& iConfig, PATMuonHeavyO

// standard selectors
recomputeBasicSelectors_ = iConfig.getParameter<bool>("recomputeBasicSelectors");
computeMuonMVA_ = iConfig.getParameter<bool>("computeMuonMVA");
computeMuonIDMVA_ = iConfig.getParameter<bool>("computeMuonIDMVA");
if (computeMuonMVA_ and not computeMiniIso_)
throw cms::Exception("ConfigurationError") << "MiniIso is needed for Muon MVA calculation.\n";

if (computeMuonMVA_) {
if (computeMiniIso_) {
// pfCombinedInclusiveSecondaryVertexV2BJetTags
mvaBTagCollectionTag_ = consumes<reco::JetTagCollection>(iConfig.getParameter<edm::InputTag>("mvaJetTag"));
mvaL1Corrector_ = consumes<reco::JetCorrector>(iConfig.getParameter<edm::InputTag>("mvaL1Corrector"));
mvaL1L2L3ResCorrector_ = consumes<reco::JetCorrector>(iConfig.getParameter<edm::InputTag>("mvaL1L2L3ResCorrector"));
rho_ = consumes<double>(iConfig.getParameter<edm::InputTag>("rho"));
mvaUseJec_ = iConfig.getParameter<bool>("mvaUseJec");
useJec_ = iConfig.getParameter<bool>("useJec");
}

computeSoftMuonMVA_ = iConfig.getParameter<bool>("computeSoftMuonMVA");
Expand Down Expand Up @@ -642,7 +632,7 @@ void PATMuonProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
edm::Handle<reco::JetTagCollection> mvaBTagCollectionTag;
edm::Handle<reco::JetCorrector> mvaL1Corrector;
edm::Handle<reco::JetCorrector> mvaL1L2L3ResCorrector;
if (computeMuonMVA_) {
if (computeMiniIso_) {
iEvent.getByToken(mvaBTagCollectionTag_, mvaBTagCollectionTag);
iEvent.getByToken(mvaL1Corrector_, mvaL1Corrector);
iEvent.getByToken(mvaL1L2L3ResCorrector_, mvaL1L2L3ResCorrector);
Expand Down Expand Up @@ -932,7 +922,7 @@ void PATMuonProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
// Need a separate loop over muons to have all inputs properly
// computed and stored in the object.
edm::Handle<double> rho;
if (computeMuonMVA_)
if (computeMiniIso_)
iEvent.getByToken(rho_, rho);
const reco::Vertex* pv(nullptr);
if (primaryVertexIsValid)
Expand Down Expand Up @@ -980,68 +970,23 @@ void PATMuonProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
muon.setSelector(reco::Muon::PuppiIsoTight, puppiCombinedIsolationPAT < 0.12);
}

float jetPtRatio = 0.0;
float jetPtRel = 0.0;
float mva = 0.0;
float mva_lowpt = 0.0;
if (computeMuonMVA_ && primaryVertexIsValid && computeMiniIso_) {
if (mvaUseJec_) {
mva = globalCache()->muonMvaEstimator().computeMva(muon,
primaryVertex,
*(mvaBTagCollectionTag.product()),
jetPtRatio,
jetPtRel,
miniIsoValue,
mvaL1Corrector.product(),
mvaL1L2L3ResCorrector.product());
mva_lowpt = globalCache()->muonLowPtMvaEstimator().computeMva(muon,
primaryVertex,
*(mvaBTagCollectionTag.product()),
jetPtRatio,
jetPtRel,
miniIsoValue,
mvaL1Corrector.product(),
mvaL1L2L3ResCorrector.product());

std::array<float, 2> jetPtRatioRel = {{0.0, 0.0}};
if (primaryVertexIsValid && computeMiniIso_) {
if (useJec_) {
jetPtRatioRel = globalCache()->calculatePtRatioRel().computePtRatioRel(
muon, *(mvaBTagCollectionTag.product()), mvaL1Corrector.product(), mvaL1L2L3ResCorrector.product());
} else {
mva = globalCache()->muonMvaEstimator().computeMva(
muon, primaryVertex, *mvaBTagCollectionTag, jetPtRatio, jetPtRel, miniIsoValue);
mva_lowpt = globalCache()->muonLowPtMvaEstimator().computeMva(
muon, primaryVertex, *mvaBTagCollectionTag, jetPtRatio, jetPtRel, miniIsoValue);
jetPtRatioRel = globalCache()->calculatePtRatioRel().computePtRatioRel(muon, *mvaBTagCollectionTag);
}

muon.setMvaValue(mva);
muon.setLowPtMvaValue(mva_lowpt);
muon.setJetPtRatio(jetPtRatio);
muon.setJetPtRel(jetPtRel);
muon.setJetPtRatio(jetPtRatioRel[0]);
muon.setJetPtRel(jetPtRatioRel[1]);

// multi-isolation
if (computeMiniIso_) {
muon.setSelector(reco::Muon::MultiIsoMedium,
miniIsoValue < 0.11 && (muon.jetPtRatio() > 0.74 || muon.jetPtRel() > 6.8));
}

// MVA working points
// https://twiki.cern.ch/twiki/bin/viewauth/CMS/LeptonMVA
const double dB2D = std::abs(muon.dB(pat::Muon::PV2D));
const double dB3D = std::abs(muon.dB(pat::Muon::PV3D));
const double edB3D = std::abs(muon.edB(pat::Muon::PV3D));
const double sip3D = edB3D > 0 ? dB3D / edB3D : 0.0;
const double dz = std::abs(muon.muonBestTrack()->dz(primaryVertex.position()));

// muon preselection
if (muon.pt() > 5 and muon.isLooseMuon() and muon.passed(reco::Muon::MiniIsoLoose) and sip3D < 8.0 and
dB2D < 0.05 and dz < 0.1) {
muon.setSelector(reco::Muon::MvaLoose, muon.mvaValue() > -0.60);
muon.setSelector(reco::Muon::MvaMedium, muon.mvaValue() > -0.20);
muon.setSelector(reco::Muon::MvaTight, muon.mvaValue() > 0.15);
muon.setSelector(reco::Muon::MvaVTight, muon.mvaValue() > 0.45);
muon.setSelector(reco::Muon::MvaVVTight, muon.mvaValue() > 0.9);
}
if (muon.pt() > 5 and muon.isLooseMuon() and sip3D < 4 and dB2D < 0.5 and dz < 1) {
muon.setSelector(reco::Muon::LowPtMvaLoose, muon.lowptMvaValue() > -0.60);
muon.setSelector(reco::Muon::LowPtMvaMedium, muon.lowptMvaValue() > -0.20);
}
}

// MVA ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,8 @@
# Standard Muon Selectors and Jet-related observables
# Depends on MiniIsolation, so only works in miniaod
# Don't forget to set flags properly in miniAOD_tools.py
computeMuonMVA = False,
mvaTrainingFile = "RecoMuon/MuonIdentification/data/mu_2017_BDTG.weights.xml",
lowPtmvaTrainingFile = "RecoMuon/MuonIdentification/data/mu_lowpt_BDTG.weights.xml",
recomputeBasicSelectors = False,
mvaUseJec = False,
useJec = False,
mvaDrMax = 0.4,
mvaJetTag = "pfCombinedInclusiveSecondaryVertexV2BJetTags",
mvaL1Corrector = "ak4PFCHSL1FastjetCorrector",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,10 @@
# Standard Muon Selectors and Jet-related observables
# Depends on MiniIsolation, so only works in miniaod
# Don't forget to set flags properly in miniAOD_tools.py
computeMuonMVA = cms.bool(False),
computeMuonIDMVA = cms.bool(False),
mvaTrainingFile = cms.FileInPath("RecoMuon/MuonIdentification/data/mu_2017_BDTG.weights.xml"),
mvaIDTrainingFile = cms.FileInPath("RecoMuon/MuonIdentification/data/mvaID.onnx"),
lowPtmvaTrainingFile = cms.FileInPath("RecoMuon/MuonIdentification/data/mu_lowpt_BDTG.weights.xml"),
recomputeBasicSelectors = cms.bool(True),
mvaUseJec = cms.bool(True),
useJec = cms.bool(True),
mvaDrMax = cms.double(0.4),
mvaJetTag = cms.InputTag("pfCombinedInclusiveSecondaryVertexV2BJetTags"),
mvaL1Corrector = cms.InputTag("ak4PFCHSL1FastjetCorrector"),
Expand Down
4 changes: 1 addition & 3 deletions PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def miniAOD_customizeCommon(process):
process.patMuons.puppiNoLeptonsIsolationPhotons = cms.InputTag("muonPUPPINoLeptonsIsolation","gamma-DR040-ThresholdVeto000-ConeVeto001")

process.patMuons.computeMiniIso = True
process.patMuons.computeMuonMVA = True
process.patMuons.computeMuonIDMVA = True
process.patMuons.computeSoftMuonMVA = True

Expand All @@ -41,8 +40,7 @@ def miniAOD_customizeCommon(process):
run2_muon_2016.toModify( process.patMuons, effectiveAreaVec = [0.0735,0.0619,0.0465,0.0433,0.0577])
run2_muon_2017.toModify( process.patMuons, effectiveAreaVec = [0.0566, 0.0562, 0.0363, 0.0119, 0.0064])
run2_muon_2018.toModify( process.patMuons, effectiveAreaVec = [0.0566, 0.0562, 0.0363, 0.0119, 0.0064])
run2_muon_2016.toModify( process.patMuons, mvaTrainingFile = "RecoMuon/MuonIdentification/data/mu_2016_BDTG.weights.xml")


process.patMuons.computePuppiCombinedIso = True
#
# disable embedding of electron and photon associated objects already stored by the ReducedEGProducer
Expand Down
Loading