CMS 3D CMS Logo

MuonDxyCut.cc
Go to the documentation of this file.
5 
7 {
8 public:
10 
11  result_type operator()(const reco::MuonPtr&) const override final;
12  CandidateType candidateType() const override final { return MUON; }
13  double value(const reco::CandidatePtr&) const override final;
14 
15  void setConsumes(edm::ConsumesCollector&) override final;
16  void getEventContent(const edm::EventBase&) override final;
17 
18 private:
20  const double maxDxy_;
22 };
24  MuonDxyCut, "MuonDxyCut");
25 
26 // Define constructors and initialization routines
29  maxDxy_(c.getParameter<double>("maxDxy"))
30 {
31  const std::string trackTypeName = c.getParameter<std::string>("trackType");
32  trackType_ = NONE;
33  if ( trackTypeName == "muonBestTrack" ) trackType_ = MUONBESTTRACK;
34  else if ( trackTypeName == "innerTrack" ) trackType_ = INNERTRACK;
35  else
36  {
37  edm::LogError("MuonDxyCut") << "Wrong cut id name, " << trackTypeName
38  << "Choose among \"muonBestTrack\", \"innerTrack\"";
39  trackType_ = NONE;
40  }
41 
42  contentTags_.emplace("vertices", c.getParameter<edm::InputTag>("vertexSrc"));
43  contentTags_.emplace("verticesMiniAOD", c.getParameter<edm::InputTag>("vertexSrcMiniAOD"));
44 }
45 
47 {
48  contentTokens_.emplace("vertices", cc.consumes<reco::VertexCollection>(contentTags_["vertices"]));
49  contentTokens_.emplace("verticesMiniAOD", cc.consumes<reco::VertexCollection>(contentTags_["verticesMiniAOD"]));
50 }
51 
53 {
54  ev.getByLabel(contentTags_["vertices"], vtxs_);
55  if ( !vtxs_.isValid() ) ev.getByLabel(contentTags_["verticesMiniAOD"], vtxs_);
56 }
57 
58 // Functors for evaluation
59 CutApplicatorBase::result_type MuonDxyCut::operator()(const reco::MuonPtr& cand) const
60 {
61  const auto& vtxPos = vtxs_->at(0).position();
62 
63  reco::TrackRef trackRef;
64  if ( trackType_ == INNERTRACK ) trackRef = cand->innerTrack();
65  else if ( trackType_ == MUONBESTTRACK ) trackRef = cand->muonBestTrack();
66 
67  return trackRef.isNonnull() and std::abs(trackRef->dxy(vtxPos)) <= maxDxy_;
68 }
69 
71 {
72  const reco::MuonPtr muon(cand);
73  reco::TrackRef trackRef;
74  if ( trackType_ == INNERTRACK ) trackRef = muon->innerTrack();
75  else if ( trackType_ == MUONBESTTRACK ) trackRef = muon->muonBestTrack();
76  if ( trackRef.isNull() ) return -1;
77 
78  const auto& vtxPos = vtxs_->at(0).position();
79  return std::abs(trackRef->dxy(vtxPos));
80 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:252
virtual TrackRef innerTrack() const
Definition: Muon.h:48
std::unordered_map< std::string, edm::EDGetToken > contentTokens_
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
bool ev
void getEventContent(const edm::EventBase &) override final
Definition: MuonDxyCut.cc:52
MuonDxyCut(const edm::ParameterSet &c)
Definition: MuonDxyCut.cc:27
std::unordered_map< std::string, edm::InputTag > contentTags_
enum MuonDxyCut::BestTrackType trackType_
edm::Handle< reco::VertexCollection > vtxs_
Definition: MuonDxyCut.cc:19
virtual TrackRef muonBestTrack() const
Definition: Muon.h:63
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool isValid() const
Definition: HandleBase.h:74
bool isNull() const
Checks for null.
Definition: Ref.h:249
CandidateType candidateType() const override final
Definition: MuonDxyCut.cc:12
result_type operator()(const reco::MuonPtr &) const override final
Definition: MuonDxyCut.cc:59
const double maxDxy_
Definition: MuonDxyCut.cc:20
void setConsumes(edm::ConsumesCollector &) override final
Definition: MuonDxyCut.cc:46
bool getByLabel(InputTag const &, Handle< T > &) const
Definition: EventBase.h:94
#define DEFINE_EDM_PLUGIN(factory, type, name)
double value(const reco::CandidatePtr &) const override final
Definition: MuonDxyCut.cc:70