Skip to content

Commit

Permalink
Merge pull request #46273 from hqucms/xpog/PNetMuonID
Browse files Browse the repository at this point in the history
[NanoAOD] Add ParticleNet-based Muon ID (Rework of #46153)
  • Loading branch information
cmsbuild authored Oct 31, 2024
2 parents 515a950 + 8a13edd commit 55d7248
Show file tree
Hide file tree
Showing 8 changed files with 581 additions and 3 deletions.
3 changes: 3 additions & 0 deletions DataFormats/BTauReco/interface/DeepBoostedJetFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <vector>
#include <unordered_map>
#include "FWCore/Utilities/interface/Exception.h"
#include "DataFormats/BTauReco/interface/RefMacros.h"

namespace btagbtvdeep {

Expand Down Expand Up @@ -57,6 +58,8 @@ namespace btagbtvdeep {
std::unordered_map<std::string, std::vector<float>> feature_map_;
};

DECLARE_EDM_REFS(DeepBoostedJetFeatures)

} // namespace btagbtvdeep

#endif // DataFormats_BTauReco_DeepBoostedJetFeatures_h
8 changes: 8 additions & 0 deletions DataFormats/BTauReco/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,15 @@
<class name="edm::Wrapper<reco::DeepDoubleXTagInfoCollection>"/>

<class name="btagbtvdeep::DeepBoostedJetFeatures"/>
<class name="btagbtvdeep::DeepBoostedJetFeaturesCollection"/>
<class name="btagbtvdeep::DeepBoostedJetFeaturesRef"/>
<class name="btagbtvdeep::DeepBoostedJetFeaturesFwdRef"/>
<class name="btagbtvdeep::DeepBoostedJetFeaturesRefProd"/>
<class name="btagbtvdeep::DeepBoostedJetFeaturesRefVector"/>
<class name="edm::Wrapper<btagbtvdeep::DeepBoostedJetFeaturesCollection>" persistent="false"/>

<class name="btagbtvdeep::LostTracksFeatures"/>

<class name="reco::DeepBoostedJetTagInfo"/>
<class name="reco::DeepBoostedJetTagInfoCollection"/>
<class name="reco::DeepBoostedJetTagInfoRef"/>
Expand Down
76 changes: 73 additions & 3 deletions PhysicsTools/NanoAOD/python/muons_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,73 @@
variables = _legacy_muon_BDT_variable
)

from PhysicsTools.PatAlgos.muonTagInfos_cfi import muonTagInfos as _muonTagInfos
muonPNetVariables = _muonTagInfos.clone(
src = cms.InputTag("linkedObjects","muons"),
leptonVars = cms.PSet(
MuonSelected_LepGood_pt = cms.string("pt"),
MuonSelected_LepGood_eta = cms.string("eta"),
MuonSelected_LepGood_jetNDauChargedMVASel = cms.string("?userCand('jetForLepJetVar').isNonnull()?userFloat('jetNDauChargedMVASel'):0"),
MuonSelected_LepGood_miniRelIsoCharged = cms.string("userFloat('miniIsoChg')/pt"),
MuonSelected_LepGood_miniRelIsoNeutral = cms.string("(userFloat('miniIsoAll')-userFloat('miniIsoChg'))/pt"),
MuonSelected_LepGood_jetPtRelv2 = cms.string("?userCand('jetForLepJetVar').isNonnull()?userFloat('ptRel'):0"),
MuonSelected_LepGood_jetDF = cms.string("?userCand('jetForLepJetVar').isNonnull()?max(userCand('jetForLepJetVar').bDiscriminator('pfDeepFlavourJetTags:probbb')+userCand('jetForLepJetVar').bDiscriminator('pfDeepFlavourJetTags:probb')+userCand('jetForLepJetVar').bDiscriminator('pfDeepFlavourJetTags:problepb'),0.0):0.0"),
MuonSelected_LepGood_jetPtRatio = cms.string("?userCand('jetForLepJetVar').isNonnull()?min(userFloat('ptRatio'),1.5):1.0/(1.0+(pfIsolationR04().sumChargedHadronPt + max(pfIsolationR04().sumNeutralHadronEt + pfIsolationR04().sumPhotonEt - pfIsolationR04().sumPUPt/2,0.0))/pt)"),
MuonSelected_dxy = cms.string("log(abs(dB('PV2D')))"),
MuonSelected_sip3d = cms.string("abs(dB('PV3D')/edB('PV3D'))"),
MuonSelected_dz = cms.string("log(abs(dB('PVDZ')))"),
MuonSelected_LepGood_dz = cms.string("log(abs(dB('PVDZ')))"),
MuonSelected_segmentComp = cms.string("segmentCompatibility"),
MuonSelected_global_muon = cms.string("isGlobalMuon"),
MuonSelected_validFraction = cms.string("?innerTrack.isNonnull?innerTrack().validFraction:-99"),
MuonSelected_local_chi2 = cms.string("combinedQuality().chi2LocalPosition"),
MuonSelected_kink = cms.string("combinedQuality().trkKink"),
MuonSelected_n_MatchedStations = cms.string("numberOfMatchedStations()"),
MuonSelected_Valid_pixel = cms.string("?innerTrack.isNonnull()?innerTrack().hitPattern().numberOfValidPixelHits():-99"),
MuonSelected_tracker_layers = cms.string("?innerTrack.isNonnull()?innerTrack().hitPattern().trackerLayersWithMeasurement():-99"),
MuonSelected_mvaId=cms.string("userFloat('mvaIDMuon')"),
),
leptonVarsExt = cms.PSet(
MuonSelected_mvaTTH=cms.InputTag("muonPROMPTMVA"),
),
pfVars = cms.PSet(
PF_pt=cms.string("pt"),
PF_charge=cms.string("charge"),
PF_isElectron=cms.string("?abs(pdgId)==11?1:0"),
PF_isMuon=cms.string("?abs(pdgId)==13?1:0"),
PF_isNeutralHadron=cms.string("?abs(pdgId)==130?1:0"),
PF_isPhoton=cms.string("?abs(pdgId)==22?1:0"),
PF_isChargedHadron=cms.string("?abs(pdgId)==211?1:0"),
PF_puppiWeightNoLep=cms.string("puppiWeightNoLep"),
PF_fromPV=cms.string("fromPV"),
PF_numberOfPixelHits=cms.string("numberOfPixelHits"),
PF_dzSig=cms.string("?hasTrackDetails?dz/max(dzError,1.e-6):0"),
PF_dxySig=cms.string("?hasTrackDetails?dxy/max(dxyError,1.e-6):0"),
PF_hcalFraction=cms.string("hcalFraction"),
PF_trackerLayersWithMeasurement=cms.string("?hasTrackDetails?bestTrack().hitPattern().trackerLayersWithMeasurement:0"),
PF_mask=cms.string("1"),
),
svVars = cms.PSet(
SV_eta=cms.string("eta"),
SV_phi=cms.string("phi"),
SV_pt=cms.string("pt"),
SV_ndof=cms.string("vertexNdof"),
SV_chi2=cms.string("vertexChi2"),
SV_nTracks=cms.string("numberOfDaughters"),
SV_mass=cms.string("mass"),
SV_mask=cms.string("1"),
),
)

from PhysicsTools.PatAlgos.muonPNetTags_cfi import muonPNetTags as _muonPNetTags
muonPNetScores = _muonPNetTags.clone(
src = cms.InputTag("muonPNetVariables"),
srcLeps = cms.InputTag("linkedObjects", "muons"),
model_path = 'PhysicsTools/NanoAOD/data/PNetMuonId/model.onnx',
preprocess_json = 'PhysicsTools/NanoAOD/data/PNetMuonId/preprocess.json',
flav_names = cms.vstring(["light", "prompt", "tau", "heavy"]),
)

from TrackingTools.TransientTrack.TransientTrackBuilder_cfi import *
muonBSConstrain = cms.EDProducer("MuonBeamspotConstraintValueMapProducer",
src = cms.InputTag("linkedObjects","muons"),
Expand Down Expand Up @@ -213,6 +280,10 @@
externalVariables = cms.PSet(
promptMVA = ExtVar(cms.InputTag("muonPROMPTMVA"),float, doc="Prompt MVA lepton ID score. Corresponds to the previous mvaTTH",precision=14),
mvaLowPt = ExtVar(cms.InputTag("muonMVALowPt"),float, doc="Low pt muon ID score",precision=14),
pnScore_prompt = ExtVar(cms.InputTag("muonPNetScores:prompt"),float, doc="PNet muon ID score for lepton from W/Z/H bosons", precision=14),
pnScore_heavy = ExtVar(cms.InputTag("muonPNetScores:heavy"),float, doc="PNet muon ID score for lepton from B or D hadrons", precision=14),
pnScore_light = ExtVar(cms.InputTag("muonPNetScores:light"),float, doc="PNet muon ID score for lepton from hadrons w/o b or c quarks OR w/o generator matching", precision=14),
pnScore_tau = ExtVar(cms.InputTag("muonPNetScores:tau"),float, doc="PNet muon ID score for decay of tau to light leptons (mu)", precision=14),
fsrPhotonIdx = ExtVar(cms.InputTag("leptonFSRphotons:muFsrIndex"), "int16", doc="Index of the lowest-dR/ET2 among associated FSR photons"),
bsConstrainedPt = ExtVar(cms.InputTag("muonBSConstrain:muonBSConstrainedPt"),float, doc="pT with beamspot constraint",precision=-1),
bsConstrainedPtErr = ExtVar(cms.InputTag("muonBSConstrain:muonBSConstrainedPtErr"),float, doc="pT error with beamspot constraint ",precision=6),
Expand Down Expand Up @@ -252,7 +323,6 @@
docString = cms.string("MC matching to status==1 muons"),
)

muonTask = cms.Task(slimmedMuonsUpdated,isoForMu,ptRatioRelForMu,slimmedMuonsWithUserData,finalMuons,finalLooseMuons )
muonTask = cms.Task(slimmedMuonsUpdated,isoForMu,ptRatioRelForMu,slimmedMuonsWithUserData,finalMuons,finalLooseMuons)
muonMCTask = cms.Task(muonsMCMatchForTable,muonMCTable)
muonTablesTask = cms.Task(muonPROMPTMVA,muonMVALowPt,muonBSConstrain,muonTable,muonMVAID)

muonTablesTask = cms.Task(muonPROMPTMVA,muonMVALowPt,muonBSConstrain,muonTable,muonMVAID,muonPNetVariables,muonPNetScores)
5 changes: 5 additions & 0 deletions PhysicsTools/NanoAOD/python/nanoDQM_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,10 @@
Plot1D('pfRelIso03_chg', 'pfRelIso03_chg', 20, 0, 2, 'PF relative isolation dR=0.3, charged component'),
Plot1D('pfRelIso04_all', 'pfRelIso04_all', 20, 0, 2, 'PF relative isolation dR=0.4, total (deltaBeta corrections)'),
Plot1D('phi', 'phi', 20, -3.14159, 3.14159, 'phi'),
Plot1D('pnScore_heavy', 'pnScore_heavy', 40, -1, 1, 'PNet muon ID score for lepton from B or D hadrons'),
Plot1D('pnScore_light', 'pnScore_light', 40, -1, 1, 'PNet muon ID score for lepton from hadrons w/o b or c quarks OR w/o generator matching'),
Plot1D('pnScore_prompt', 'pnScore_prompt', 40, -1, 1, 'PNet muon ID score for lepton from W/Z/H bosons'),
Plot1D('pnScore_tau', 'pnScore_tau', 40, -1, 1, 'PNet muon ID score for decay of tau to light leptons (mu)'),
Plot1D('pt', 'pt', 20, 0, 200, 'pt'),
Plot1D('ptErr', 'ptErr', 20, 0, 20, 'ptError of the muon track'),
Plot1D('segmentComp', 'segmentComp', 20, 0, 1, 'muon segment compatibility'),
Expand All @@ -607,6 +611,7 @@
Plot1D('tkRelIso', 'tkRelIso', 100, 0, 1, 'Tracker-based relative isolation dR=0.3 for highPt, trkIso/tunePpt'),
Plot1D('triggerIdLoose', 'triggerIdLoose', 2, -0.5, 1.5, 'TriggerIdLoose ID'),
Plot1D('tunepRelPt', 'tunepRelPt', 200, 0, 200, 'TuneP relative pt, tunePpt/pt'),
Plot1D('tuneP_pterr', 'tuneP_pterr', 200, 0, 20, 'pTerr from tunePMuonBestTrack'),
Plot1D('VXBS_Cov00', 'VXBS_Cov00', 200, -10, 10, '0, 0 element of the VXBS Covariance matrix'),
Plot1D('VXBS_Cov03', 'VXBS_Cov03', 200, -10, 10, '0, 3 element of the VXBS Covariance matrix'),
Plot1D('VXBS_Cov33', 'VXBS_Cov33', 200, -10, 10, '3, 3 element of the VXBS Covariance matrix'),
Expand Down
1 change: 1 addition & 0 deletions PhysicsTools/PatAlgos/plugins/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@
<use name="TrackingTools/IPTools"/>
<use name="TrackingTools/Records"/>
<use name="RecoTauTag/RecoTau"/>
<use name="RecoBTag/FeatureTools"/>
<use name="root"/>
</library>
Loading

0 comments on commit 55d7248

Please sign in to comment.