File indexing completed on 2024-04-06 12:27:00
0001 #include "PhysicsTools/SelectorUtils/interface/CutApplicatorBase.h"
0002 #include "DataFormats/MuonReco/interface/Muon.h"
0003 #include "DataFormats/MuonReco/interface/MuonSelectors.h"
0004
0005 class MuonTrackCut : public CutApplicatorBase {
0006 public:
0007 MuonTrackCut(const edm::ParameterSet& c);
0008
0009 result_type operator()(const reco::MuonPtr&) const final;
0010 CandidateType candidateType() const final { return MUON; }
0011 double value(const reco::CandidatePtr&) const final;
0012
0013 private:
0014
0015 int minTrackerLayersWithMeasurement_, minPixelLayersWithMeasurement_, minNumberOfValidPixelHits_;
0016 double minValidFraction_;
0017 reco::Track::TrackQuality trackQuality_;
0018 int minNumberOfValidMuonHits_;
0019
0020 bool doInnerTrack_, doGlobalTrack_;
0021 };
0022 DEFINE_EDM_PLUGIN(CutApplicatorFactory, MuonTrackCut, "MuonTrackCut");
0023
0024
0025 MuonTrackCut::MuonTrackCut(const edm::ParameterSet& c)
0026 : CutApplicatorBase(c),
0027 minTrackerLayersWithMeasurement_(-1),
0028 minPixelLayersWithMeasurement_(-1),
0029 minNumberOfValidPixelHits_(-1),
0030 minValidFraction_(-1),
0031 trackQuality_(reco::Track::undefQuality),
0032 minNumberOfValidMuonHits_(-1),
0033 doInnerTrack_(false),
0034 doGlobalTrack_(false) {
0035 if (c.existsAs<edm::ParameterSet>("innerTrack")) {
0036 doInnerTrack_ = true;
0037
0038 const edm::ParameterSet cc = c.getParameter<edm::ParameterSet>("innerTrack");
0039 if (cc.exists("minTrackerLayersWithMeasurement"))
0040 minTrackerLayersWithMeasurement_ = cc.getParameter<int>("minTrackerLayersWithMeasurement");
0041 if (cc.exists("minPixelLayersWithMeasurement"))
0042 minPixelLayersWithMeasurement_ = cc.getParameter<int>("minPixelLayersWithMeasurement");
0043 if (cc.exists("minNumberOfValidPixelHits"))
0044 minNumberOfValidPixelHits_ = cc.getParameter<int>("minNumberOfValidPixelHits");
0045 if (cc.exists("minValidFraction"))
0046 minValidFraction_ = cc.getParameter<double>("minValidFraction");
0047 const std::string trackQualityStr = cc.exists("trackQuality") ? cc.getParameter<std::string>("trackQuality") : "";
0048 trackQuality_ = reco::Track::qualityByName(trackQualityStr);
0049 }
0050 if (c.existsAs<edm::ParameterSet>("globalTrack")) {
0051 doGlobalTrack_ = true;
0052
0053 const edm::ParameterSet cc = c.getParameter<edm::ParameterSet>("globalTrack");
0054
0055 if (cc.exists("minNumberOfValidMuonHits"))
0056 minNumberOfValidMuonHits_ = cc.getParameter<int>("minNumberOfValidMuonHits");
0057 }
0058 }
0059
0060
0061 CutApplicatorBase::result_type MuonTrackCut::operator()(const reco::MuonPtr& muon) const {
0062 if (doInnerTrack_) {
0063 const reco::TrackRef t = muon->innerTrack();
0064 if (t.isNull())
0065 return false;
0066 const auto& h = t->hitPattern();
0067 if (trackQuality_ != reco::Track::undefQuality and !t->quality(trackQuality_))
0068 return false;
0069 if (h.trackerLayersWithMeasurement() < minTrackerLayersWithMeasurement_)
0070 return false;
0071 if (h.pixelLayersWithMeasurement() < minPixelLayersWithMeasurement_)
0072 return false;
0073 if (h.numberOfValidPixelHits() < minNumberOfValidPixelHits_)
0074 return false;
0075 if (t->validFraction() <= minValidFraction_)
0076 return false;
0077 }
0078 if (doGlobalTrack_) {
0079 const reco::TrackRef t = muon->globalTrack();
0080 if (t.isNull())
0081 return false;
0082 const auto& h = t->hitPattern();
0083 if (h.numberOfValidMuonHits() < minNumberOfValidMuonHits_)
0084 return false;
0085
0086 }
0087
0088 return true;
0089 }
0090
0091 double MuonTrackCut::value(const reco::CandidatePtr& cand) const {
0092 const reco::MuonPtr muon(cand);
0093 if (doInnerTrack_) {
0094 const reco::TrackRef t = muon->innerTrack();
0095 if (t.isNull())
0096 return 0;
0097 const auto& h = t->hitPattern();
0098 if (trackQuality_ != reco::Track::undefQuality and !t->quality(trackQuality_))
0099 return t->quality(trackQuality_);
0100 if (h.trackerLayersWithMeasurement() < minTrackerLayersWithMeasurement_)
0101 return h.trackerLayersWithMeasurement();
0102 if (h.pixelLayersWithMeasurement() < minPixelLayersWithMeasurement_)
0103 return h.pixelLayersWithMeasurement();
0104 if (h.numberOfValidPixelHits() < minNumberOfValidPixelHits_)
0105 return h.numberOfValidPixelHits();
0106 if (t->validFraction() <= minValidFraction_)
0107 return t->validFraction();
0108
0109 return t->validFraction();
0110 }
0111 if (doGlobalTrack_) {
0112 const reco::TrackRef t = muon->globalTrack();
0113 if (t.isNull())
0114 return 0;
0115 const auto& h = t->hitPattern();
0116 if (h.numberOfValidMuonHits() < minNumberOfValidMuonHits_)
0117 return h.numberOfValidMuonHits();
0118
0119
0120 return h.numberOfValidMuonHits();
0121 }
0122
0123 return 0;
0124 }