Skip to content

Commit 6be423c

Browse files
committed
Fix discrepancies in e/mu objects.
1 parent 4873a9f commit 6be423c

File tree

7 files changed

+55
-8
lines changed

7 files changed

+55
-8
lines changed

PhysicsTools/NanoAOD/python/electrons_cff.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,5 +540,5 @@ def _get_bitmapVIDForEle_docstring(modules,WorkingPoints):
540540
run2_egamma.toReplaceWith(electronTask, _electronTask_Run2)
541541

542542
# Revert back to AK4 CHS jets for Run2 inputs
543-
run2_nanoAOD_ANY.toModify(
543+
run2_egamma.toModify(
544544
ptRatioRelForEle,srcJet="updatedJets")

PhysicsTools/NanoAOD/python/jetsAK4_CHS_cff.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ def nanoAOD_refineFastSim_bTagDeepFlav(process):
498498
jetUserDataTask = cms.Task(bJetVars,qgtagger,jercVars,pileupJetIdNano)
499499

500500
#before cross linking
501+
chsJetUpdateTask = cms.Task(jetCorrFactorsNano,updatedJets)
501502
jetTask = cms.Task(jetCorrFactorsNano,updatedJets,jetUserDataTask,updatedJetsWithUserData,finalJets)
502503

503504
#after cross linkining

PhysicsTools/NanoAOD/python/muons_cff.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
pfCandsForMiniIso = cms.InputTag("packedPFCandidates"),
1616
miniIsoParams = PhysicsTools.PatAlgos.producersLayer1.muonProducer_cfi.patMuons.miniIsoParams, # so they're in sync
1717
recomputeMuonBasicSelectors = cms.bool(False),
18+
recomputeSoftMuonMvaRun3 = cms.bool(False),
19+
softMvaRun3Model = PhysicsTools.PatAlgos.producersLayer1.muonProducer_cfi.patMuons.softMvaRun3Model,
20+
)
21+
22+
(run2_nanoAOD_106Xv2 | run3_nanoAOD_pre142X).toModify(
23+
slimmedMuonsUpdated, recomputeMuonBasicSelectors=True, recomputeSoftMuonMvaRun3=True,
1824
)
1925

2026
isoForMu = cms.EDProducer("MuonIsoValueMapProducer",
@@ -305,7 +311,7 @@
305311

306312

307313
# Revert back to AK4 CHS jets for Run 2
308-
run2_nanoAOD_ANY.toModify(
314+
run2_muon.toModify(
309315
ptRatioRelForMu,srcJet="updatedJets"
310316
)
311317

PhysicsTools/NanoAOD/python/nano_cff.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@
6767
isoTrackTablesTask,softActivityTablesTask
6868
)
6969

70+
(run2_muon | run2_egamma).toReplaceWith(
71+
nanoTableTaskCommon,
72+
nanoTableTaskCommon.copyAndAdd(chsJetUpdateTask)
73+
)
74+
7075
nanoSequenceCommon = cms.Sequence(nanoTableTaskCommon)
7176

7277
nanoSequenceOnlyFullSim = cms.Sequence(triggerObjectTablesTask)
@@ -132,7 +137,7 @@ def nanoAOD_addTauIds(process, idsToRun=[], addPNetCHS=False, addUParTPuppi=Fals
132137
addGenJetMatch=False,
133138
genJetMatch=""
134139
))
135-
process.tauTask.add(process.jetTask, getattr(process, updatedTauName))
140+
process.tauTask.add(process.chsJetUpdateTask, getattr(process, updatedTauName))
136141
originalTauName = updatedTauName
137142

138143
if addUParTPuppi:

PhysicsTools/NanoAOD/python/nano_eras_cff.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,13 @@
2424

2525
from Configuration.ProcessModifiers.nanoAOD_rePuppi_cff import nanoAOD_rePuppi
2626

27+
# [General Note]
28+
# use `runX_nanoAOD_YYY` only for input-dataset-specific changes
29+
# (e.g., run2_nanoAOD_106Xv2 for 106X MiniAODv2, run3_nanoAOD_pre142X for pre-142X Run3 MiniAODs)
2730
run2_nanoAOD_ANY = (
2831
run2_nanoAOD_106Xv2
2932
)
3033

34+
# use other modifiers for intrinsic era-dependent changes
3135
run2_egamma = (run2_egamma_2016 | run2_egamma_2017 | run2_egamma_2018)
36+
run2_muon = (run2_muon_2016 | run2_muon_2017 | run2_muon_2018)

PhysicsTools/PatAlgos/plugins/BuildFile.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<use name="DataFormats/HeavyIonEvent"/>
1919
<use name="DataFormats/HepMCCandidate"/>
2020
<use name="PhysicsTools/PatUtils"/>
21+
<use name="PhysicsTools/XGBoost"/>
2122
<use name="CondFormats/JetMETObjects"/>
2223
<use name="CondFormats/HcalObjects"/>
2324
<use name="CondFormats/DataRecord"/>

PhysicsTools/PatAlgos/plugins/LeptonUpdater.cc

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
#include "FWCore/Framework/interface/global/EDProducer.h"
1+
#include "FWCore/Framework/interface/stream/EDProducer.h"
22
#include "FWCore/Framework/interface/Event.h"
33
#include "FWCore/ParameterSet/interface/ParameterSet.h"
44
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
55
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
66
#include "FWCore/Utilities/interface/InputTag.h"
77
#include "FWCore/MessageLogger/interface/MessageLogger.h"
88
#include "PhysicsTools/PatUtils/interface/MiniIsolation.h"
9+
#include "PhysicsTools/PatAlgos/interface/SoftMuonMvaRun3Estimator.h"
10+
#include "PhysicsTools/XGBoost/interface/XGBooster.h"
911
#include "DataFormats/Common/interface/View.h"
1012

1113
#include "DataFormats/PatCandidates/interface/Muon.h"
@@ -18,7 +20,7 @@
1820
namespace pat {
1921

2022
template <typename T>
21-
class LeptonUpdater : public edm::global::EDProducer<> {
23+
class LeptonUpdater : public edm::stream::EDProducer<> {
2224
public:
2325
explicit LeptonUpdater(const edm::ParameterSet &iConfig)
2426
: src_(consumes<std::vector<T>>(iConfig.getParameter<edm::InputTag>("src"))),
@@ -32,14 +34,23 @@ namespace pat {
3234
pcToken_ = consumes<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("pfCandsForMiniIso"));
3335
}
3436
recomputeMuonBasicSelectors_ = false;
35-
if (typeid(T) == typeid(pat::Muon))
37+
recomputeSoftMuonMvaRun3_ = false;
38+
if (typeid(T) == typeid(pat::Muon)) {
3639
recomputeMuonBasicSelectors_ = iConfig.getParameter<bool>("recomputeMuonBasicSelectors");
40+
recomputeSoftMuonMvaRun3_ = iConfig.getParameter<bool>("recomputeSoftMuonMvaRun3");
41+
if (recomputeSoftMuonMvaRun3_) {
42+
std::string softMvaRun3Model = iConfig.getParameter<std::string>("softMvaRun3Model");
43+
softMuonMvaRun3Booster_ =
44+
std::make_unique<pat::XGBooster>(edm::FileInPath(softMvaRun3Model + ".model").fullPath(),
45+
edm::FileInPath(softMvaRun3Model + ".features").fullPath());
46+
}
47+
}
3748
produces<std::vector<T>>();
3849
}
3950

4051
~LeptonUpdater() override {}
4152

42-
void produce(edm::StreamID, edm::Event &, edm::EventSetup const &) const override;
53+
void produce(edm::Event &, const edm::EventSetup &) override;
4354

4455
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
4556
edm::ParameterSetDescription desc;
@@ -53,6 +64,9 @@ namespace pat {
5364
if (typeid(T) == typeid(pat::Muon)) {
5465
desc.add<bool>("recomputeMuonBasicSelectors", false)
5566
->setComment("Recompute basic cut-based muon selector flags");
67+
desc.add<bool>("recomputeSoftMuonMvaRun3", false)->setComment("Recompute Run3 soft muon MVA value");
68+
desc.add<std::string>("softMvaRun3Model", "RecoMuon/MuonIdentification/data/Run2022-20231030-1731-Event0")
69+
->setComment("Run3 soft muon MVA model path");
5670
desc.addOptional<std::vector<double>>("miniIsoParams")
5771
->setComment("Parameters used for miniIso (as in PATMuonProducer)");
5872
descriptions.add("muonsUpdated", desc);
@@ -76,6 +90,8 @@ namespace pat {
7690

7791
void recomputeMuonBasicSelectors(T &, const reco::Vertex &, const bool) const;
7892

93+
void recomputeSoftMuonMvaRun3(T &);
94+
7995
private:
8096
// configurables
8197
edm::EDGetTokenT<std::vector<T>> src_;
@@ -84,8 +100,10 @@ namespace pat {
84100
bool computeMiniIso_;
85101
bool fixDxySign_;
86102
bool recomputeMuonBasicSelectors_;
103+
bool recomputeSoftMuonMvaRun3_;
87104
std::vector<double> miniIsoParams_[2];
88105
edm::EDGetTokenT<pat::PackedCandidateCollection> pcToken_;
106+
std::unique_ptr<pat::XGBooster> softMuonMvaRun3Booster_;
89107
};
90108

91109
// must do the specialization within the namespace otherwise gcc complains
@@ -128,10 +146,18 @@ namespace pat {
128146
lep.setSelectors(muon::makeSelectorBitset(lep, &pv, do_hip_mitigation_2016));
129147
}
130148

149+
template <typename T>
150+
void LeptonUpdater<T>::recomputeSoftMuonMvaRun3(T &lep) {}
151+
152+
template <>
153+
void LeptonUpdater<pat::Muon>::recomputeSoftMuonMvaRun3(pat::Muon &muon) {
154+
muon.setSoftMvaRun3Value(computeSoftMvaRun3(*softMuonMvaRun3Booster_, muon));
155+
}
156+
131157
} // namespace pat
132158

133159
template <typename T>
134-
void pat::LeptonUpdater<T>::produce(edm::StreamID, edm::Event &iEvent, edm::EventSetup const &) const {
160+
void pat::LeptonUpdater<T>::produce(edm::Event &iEvent, edm::EventSetup const &) {
135161
edm::Handle<std::vector<T>> src;
136162
iEvent.getByToken(src_, src);
137163

@@ -179,6 +205,9 @@ void pat::LeptonUpdater<T>::produce(edm::StreamID, edm::Event &iEvent, edm::Even
179205
}
180206
if (recomputeMuonBasicSelectors_)
181207
recomputeMuonBasicSelectors(lep, pv, do_hip_mitigation_2016);
208+
if (recomputeSoftMuonMvaRun3_) {
209+
recomputeSoftMuonMvaRun3(lep);
210+
}
182211
//Fixing the sign of impact parameters
183212
if (fixDxySign_) {
184213
float signPV = 1.;

0 commit comments

Comments
 (0)