Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:26:59

0001 #include "PhysicsTools/SelectorUtils/interface/CutApplicatorBase.h"
0002 #include "PhysicsTools/SelectorUtils/interface/CutApplicatorWithEventContentBase.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 #include "DataFormats/MuonReco/interface/Muon.h"
0005 #include "DataFormats/MuonReco/interface/MuonSelectors.h"
0006 
0007 class MuonPOGStandardCut : public CutApplicatorWithEventContentBase {
0008 public:
0009   MuonPOGStandardCut(const edm::ParameterSet& c);
0010 
0011   result_type operator()(const reco::MuonPtr&) const final;
0012   CandidateType candidateType() const final { return MUON; }
0013 
0014   void setConsumes(edm::ConsumesCollector&) final;
0015   void getEventContent(const edm::EventBase&) final;
0016 
0017   double value(const reco::CandidatePtr& cand) const final;
0018 
0019 private:
0020   enum CutType { LOOSE, MEDIUM, TIGHT, SOFT, HIGHPT, NONE } cutType_;
0021   edm::Handle<reco::VertexCollection> vtxs_;
0022 };
0023 DEFINE_EDM_PLUGIN(CutApplicatorFactory, MuonPOGStandardCut, "MuonPOGStandardCut");
0024 
0025 // Define constructors and initialization routines
0026 MuonPOGStandardCut::MuonPOGStandardCut(const edm::ParameterSet& c) : CutApplicatorWithEventContentBase(c) {
0027   const auto cutTypeName = c.getParameter<std::string>("idName");
0028   if (cutTypeName == "loose")
0029     cutType_ = LOOSE;
0030   else if (cutTypeName == "tight")
0031     cutType_ = TIGHT;
0032   else if (cutTypeName == "medium")
0033     cutType_ = MEDIUM;
0034   else if (cutTypeName == "soft")
0035     cutType_ = SOFT;
0036   else if (cutTypeName == "highpt")
0037     cutType_ = HIGHPT;
0038   else {
0039     edm::LogError("MuonPOGStandardCut") << "Wrong cut id name, " << cutTypeName;
0040     cutType_ = NONE;
0041   }
0042 
0043   contentTags_.emplace("vertices", c.getParameter<edm::InputTag>("vertexSrc"));
0044 }
0045 
0046 void MuonPOGStandardCut::setConsumes(edm::ConsumesCollector& cc) {
0047   auto vtcs = cc.consumes<reco::VertexCollection>(contentTags_["vertices"]);
0048   contentTokens_.emplace("vertices", vtcs);
0049 }
0050 
0051 void MuonPOGStandardCut::getEventContent(const edm::EventBase& ev) { ev.getByLabel(contentTags_["vertices"], vtxs_); }
0052 
0053 // Functors for evaluation
0054 CutApplicatorBase::result_type MuonPOGStandardCut::operator()(const reco::MuonPtr& cand) const {
0055   switch (cutType_) {
0056     case LOOSE:
0057       return muon::isLooseMuon(*cand);
0058       break;
0059     case TIGHT:
0060       return muon::isTightMuon(*cand, vtxs_->at(0));
0061       break;
0062     case MEDIUM:
0063       return muon::isMediumMuon(*cand);
0064       break;
0065     case SOFT:
0066       return muon::isSoftMuon(*cand, vtxs_->at(0));
0067       break;
0068     case HIGHPT:
0069       return muon::isHighPtMuon(*cand, vtxs_->at(0));
0070       break;
0071     case NONE:
0072       return false;
0073       break;
0074   }
0075 
0076   return true;
0077 }
0078 
0079 double MuonPOGStandardCut::value(const reco::CandidatePtr& cand) const {
0080   edm::Ptr<reco::Muon> mu(cand);
0081   switch (cutType_) {
0082     case LOOSE:
0083       return muon::isLooseMuon(*mu);
0084       break;
0085     case TIGHT:
0086       return muon::isTightMuon(*mu, vtxs_->at(0));
0087       break;
0088     case MEDIUM:
0089       return muon::isMediumMuon(*mu);
0090       break;
0091     case SOFT:
0092       return muon::isSoftMuon(*mu, vtxs_->at(0));
0093       break;
0094     case HIGHPT:
0095       return muon::isHighPtMuon(*mu, vtxs_->at(0));
0096       break;
0097     case NONE:
0098       return 0.0;
0099       break;
0100   }
0101   return 1.0;
0102 }