Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:32: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    \class WSelector WSelector.h "PhysicsTools/FWLite/interface/WSelector.h"
0009    \brief Example class of an EventSelector to apply a simple W Boson selection
0010 
0011    Example class for of an EventSelector as defined in the SelectorUtils package. 
0012    EventSelectors may be used to facilitate cutflows and to implement selections
0013    independent from the event loop in FWLite or full framework.
0014 */
0015 
0016 class WSelector : public EventSelector {
0017 public:
0018   /// constructor
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   /// destructor
0035   ~WSelector() override {}
0036   /// return muon candidate of W boson
0037   pat::Muon const& wMuon() const { return *wMuon_; }
0038   /// return MET of W boson
0039   pat::MET const& met() const { return *met_; }
0040 
0041   /// here is where the selection occurs
0042   bool operator()(edm::EventBase const& event, pat::strbitset& ret) override {
0043     ret.set(false);
0044     // Handle to the muon collection
0045     edm::Handle<std::vector<pat::Muon> > muons;
0046     // Handle to the MET collection
0047     edm::Handle<std::vector<pat::MET> > met;
0048     // get the objects from the event
0049     bool gotMuons = event.getByLabel(muonSrc_, muons);
0050     bool gotMET = event.getByLabel(metSrc_, met);
0051     // get the MET, require to be > minimum
0052     if (gotMET) {
0053       met_ = &met->at(0);
0054       if (met_->pt() > cut("MET", double()) || ignoreCut("MET"))
0055         passCut(ret, "MET");
0056     }
0057     // get the highest pt muon, require to have pt > minimum
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   /// muon input
0075   edm::InputTag muonSrc_;
0076   /// met input
0077   edm::InputTag metSrc_;
0078   /// muon candidate from W boson
0079   pat::Muon const* wMuon_;
0080   /// MET from W boson
0081   pat::MET const* met_;
0082 };
0083 #endif  // PhysicsTools_FWLite_WSelector_h