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"
1820namespace 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
133159template <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