CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuonDzCut.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 maxDz_;
22 };
24  MuonDzCut, "MuonDzCut");
25 
26 // Define constructors and initialization routines
29  maxDz_(c.getParameter<double>("maxDz"))
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("MuonDzCut") << "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 MuonDzCut::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->dz(vtxPos)) <= maxDz_;
68 }
69 
70 double MuonDzCut::value(const reco::CandidatePtr& cand) const
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->dz(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
enum MuonDzCut::BestTrackType trackType_
edm::Handle< reco::VertexCollection > vtxs_
Definition: MuonDzCut.cc:19
std::unordered_map< std::string, edm::EDGetToken > contentTokens_
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
bool ev
MuonDzCut(const edm::ParameterSet &c)
Definition: MuonDzCut.cc:27
std::unordered_map< std::string, edm::InputTag > contentTags_
CandidateType candidateType() const overridefinal
Definition: MuonDzCut.cc:12
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define private
Definition: FWEveView.cc:22
bool isValid() const
Definition: HandleBase.h:75
bool isNull() const
Checks for null.
Definition: Ref.h:249
void setConsumes(edm::ConsumesCollector &) overridefinal
Definition: MuonDzCut.cc:46
string const
Definition: compareJSON.py:14
result_type operator()(const reco::MuonPtr &) const overridefinal
Definition: MuonDzCut.cc:59
bool getByLabel(InputTag const &, Handle< T > &) const
Definition: EventBase.h:92
#define DEFINE_EDM_PLUGIN(factory, type, name)
const double maxDz_
Definition: MuonDzCut.cc:20
double value(const reco::CandidatePtr &) const overridefinal
Definition: MuonDzCut.cc:70
void getEventContent(const edm::EventBase &) overridefinal
Definition: MuonDzCut.cc:52