CMS 3D CMS Logo

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