File indexing completed on 2024-04-06 12:23:23
0001 #ifndef PhysicsTools_FWLite_WSelector_h
0002 #define PhysicsTools_FWLite_WSelector_h
0003 #include "DataFormats/PatCandidates/interface/MET.h"
0004 #include "DataFormats/PatCandidates/interface/Muon.h"
0005 #include "PhysicsTools/SelectorUtils/interface/EventSelector.h"
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 class WSelector : public EventSelector {
0017 public:
0018
0019 WSelector(edm::ParameterSet const& params)
0020 : muonSrc_(params.getParameter<edm::InputTag>("muonSrc")), metSrc_(params.getParameter<edm::InputTag>("metSrc")) {
0021 double muonPtMin = params.getParameter<double>("muonPtMin");
0022 double metMin = params.getParameter<double>("metMin");
0023 push_back("Muon Pt", muonPtMin);
0024 push_back("MET", metMin);
0025 set("Muon Pt");
0026 set("MET");
0027 wMuon_ = nullptr;
0028 met_ = nullptr;
0029 if (params.exists("cutsToIgnore")) {
0030 setIgnoredCuts(params.getParameter<std::vector<std::string> >("cutsToIgnore"));
0031 }
0032 retInternal_ = getBitTemplate();
0033 }
0034
0035 ~WSelector() override {}
0036
0037 pat::Muon const& wMuon() const { return *wMuon_; }
0038
0039 pat::MET const& met() const { return *met_; }
0040
0041
0042 bool operator()(edm::EventBase const& event, pat::strbitset& ret) override {
0043 ret.set(false);
0044
0045 edm::Handle<std::vector<pat::Muon> > muons;
0046
0047 edm::Handle<std::vector<pat::MET> > met;
0048
0049 bool gotMuons = event.getByLabel(muonSrc_, muons);
0050 bool gotMET = event.getByLabel(metSrc_, met);
0051
0052 if (gotMET) {
0053 met_ = &met->at(0);
0054 if (met_->pt() > cut("MET", double()) || ignoreCut("MET"))
0055 passCut(ret, "MET");
0056 }
0057
0058 if (gotMuons) {
0059 if (!ignoreCut("Muon Pt")) {
0060 if (!muons->empty()) {
0061 wMuon_ = &muons->at(0);
0062 if (wMuon_->pt() > cut("Muon Pt", double()) || ignoreCut("Muon Pt"))
0063 passCut(ret, "Muon Pt");
0064 }
0065 } else {
0066 passCut(ret, "Muon Pt");
0067 }
0068 }
0069 setIgnored(ret);
0070 return (bool)ret;
0071 }
0072
0073 protected:
0074
0075 edm::InputTag muonSrc_;
0076
0077 edm::InputTag metSrc_;
0078
0079 pat::Muon const* wMuon_;
0080
0081 pat::MET const* met_;
0082 };
0083 #endif