CMS 3D CMS Logo

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