CMS 3D CMS Logo

PFMuonSelector.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_PatUtils_interface_PFMuonSelector_h
2 #define PhysicsTools_PatUtils_interface_PFMuonSelector_h
3 
4 #ifndef __GCCXML__
6 #endif
10 
13 
14 #include <iostream>
15 
16 class PFMuonSelector : public Selector<pat::Muon> {
17 public: // interface
18  bool verbose_;
19 
21 
23 
24 #ifndef __GCCXML__
26 #endif
27 
29  verbose_ = false;
30 
31  std::string versionStr = parameters.getParameter<std::string>("version");
32 
34 
35  if (versionStr == "TOPPAG12_LJETS") {
37  } else {
38  throw cms::Exception("InvalidInput") << "Expect version to be one of SPRING11" << std::endl;
39  }
40 
42  parameters.getParameter<double>("Chi2"),
43  parameters.getParameter<int>("minTrackerLayers"),
44  parameters.getParameter<int>("minValidMuHits"),
45  parameters.getParameter<double>("maxIp"),
46  parameters.getParameter<int>("minPixelHits"),
47  parameters.getParameter<int>("minMatchedStations"),
48  parameters.getParameter<double>("maxPfRelIso"));
49  if (parameters.exists("cutsToIgnore"))
50  setIgnoredCuts(parameters.getParameter<std::vector<std::string> >("cutsToIgnore"));
51 
53  }
54 
56  double chi2 = 10.0,
57  int minTrackerLayers = 6,
58  int minValidMuonHits = 1,
59  double maxIp = 0.2,
60  int minPixelHits = 1,
61  int minNMatches = 2,
62  double pfiso = 0.12) {
63  version_ = version;
64 
65  push_back("GlobalMuon", true);
66  push_back("TrackerMuon", true);
67  push_back("Chi2", chi2);
68  push_back("minTrackerLayers", minTrackerLayers);
69  push_back("minValidMuHits", minValidMuonHits);
70  push_back("maxIp", maxIp);
71  push_back("minPixelHits", minPixelHits);
72  push_back("minMatchedStations", minNMatches);
73  push_back("maxPfRelIso", pfiso);
74 
75  set("GlobalMuon");
76  set("TrackerMuon");
77  set("Chi2");
78  set("minTrackerLayers");
79  set("minValidMuHits");
80  set("maxIp");
81  set("minPixelHits");
82  set("minMatchedStations");
83  set("maxPfRelIso");
84 
85  indexChi2_ = index_type(&bits_, "Chi2");
86  indexMinTrackerLayers_ = index_type(&bits_, "minTrackerLayers");
87  indexminValidMuHits_ = index_type(&bits_, "minValidMuHits");
88  indexMaxIp_ = index_type(&bits_, "maxIp");
89  indexPixHits_ = index_type(&bits_, "minPixelHits");
90  indexStations_ = index_type(&bits_, "minMatchedStations");
91  indexmaxPfRelIso_ = index_type(&bits_, "maxPfRelIso");
92 
93  if (version_ == TOPPAG12_LJETS) {
94  set("TrackerMuon", false);
95  }
96  }
97 
98  // Allow for multiple definitions of the cuts.
99  bool operator()(const pat::Muon& muon, pat::strbitset& ret) override {
100  if (version_ == TOPPAG12_LJETS)
101  return TopPag12LjetsCuts(muon, ret);
102  else {
103  return false;
104  }
105  }
106 
108 
110  ret.set(false);
111 
112  bool isGlobal = muon.isGlobalMuon();
113  bool isTracker = muon.isTrackerMuon();
114 
115  double norm_chi2 = 9999999.0;
116  int minTrackerLayers = 0;
117  int minValidMuonHits = 0;
118  int _ip = 0.0;
119  int minPixelHits = 0;
120  if (muon.globalTrack().isNonnull() && muon.globalTrack().isAvailable()) {
121  norm_chi2 = muon.normChi2();
122  minTrackerLayers = static_cast<int>(muon.track()->hitPattern().trackerLayersWithMeasurement());
123  minValidMuonHits = static_cast<int>(muon.globalTrack()->hitPattern().numberOfValidMuonHits());
124  _ip = muon.dB();
125  minPixelHits = muon.innerTrack()->hitPattern().numberOfValidPixelHits();
126  }
127 
128  int minMatchedStations = muon.numberOfMatches();
129 
130  double chIso = muon.userIsolation(pat::PfChargedHadronIso);
131  double nhIso = muon.userIsolation(pat::PfNeutralHadronIso);
132  double gIso = muon.userIsolation(pat::PfGammaIso);
133  double pt = muon.pt();
134 
135  double pfIso = (chIso + nhIso + gIso) / pt;
136 
137  if (isGlobal || ignoreCut("GlobalMuon"))
138  passCut(ret, "GlobalMuon");
139  if (isTracker || ignoreCut("TrackerMuon"))
140  passCut(ret, "TrackerMuon");
141  if (norm_chi2 < cut(indexChi2_, double()) || ignoreCut(indexChi2_))
145  if (minValidMuonHits >= cut(indexminValidMuHits_, int()) || ignoreCut(indexminValidMuHits_))
147  if (_ip < cut(indexMaxIp_, double()) || ignoreCut(indexMaxIp_))
153  if (pfIso < cut(indexmaxPfRelIso_, double()) || ignoreCut(indexmaxPfRelIso_))
155 
156  setIgnored(ret);
157 
158  return (bool)ret;
159  }
160 
161 private: // member variables
163 
171 };
172 
173 #endif
bool ignoreCut(std::string const &s) const
ignore the cut at index "s"
Definition: Selector.h:127
bool operator()(const pat::Muon &muon, pat::strbitset &ret) override
This provides the interface for base classes to select objects.
PFMuonSelector(edm::ParameterSet const &parameters, edm::ConsumesCollector &&iC)
ret
prodAgent to be discontinued
index_type indexPixHits_
Version_t version_
pat::strbitset::index_type index_type
Definition: Selector.h:25
void setIgnored(pat::strbitset &ret)
set ignored bits
Definition: Selector.h:181
pat::strbitset retInternal_
internal ret if users don&#39;t care about return bits
Definition: Selector.h:242
bool TopPag12LjetsCuts(const pat::Muon &muon, pat::strbitset &ret)
index_type indexStations_
index_type indexminValidMuHits_
pat::strbitset bits_
the bitset indexed by strings
Definition: Selector.h:241
void passCut(pat::strbitset &ret, std::string const &s)
Passing cuts.
Definition: Selector.h:142
void initialize(Version_t version, double chi2=10.0, int minTrackerLayers=6, int minValidMuonHits=1, double maxIp=0.2, int minPixelHits=1, int minNMatches=2, double pfiso=0.12)
PFMuonSelector(edm::ParameterSet const &parameters)
virtual void push_back(std::string const &s)
This is the registration of an individual cut string.
Definition: Selector.h:42
index_type indexMinTrackerLayers_
Functor that operates on <T>
Definition: Selector.h:22
index_type indexMaxIp_
pat::strbitset getBitTemplate() const
Get an empty bitset with the proper names.
Definition: Selector.h:168
int cut(index_type const &i, int val) const
Access the int cut values at index "s".
Definition: Selector.h:158
index_type indexmaxPfRelIso_
index_type indexChi2_
void setIgnoredCuts(std::vector< std::string > const &bitsToIgnore)
set the bits to ignore from a vector
Definition: Selector.h:131
Analysis-level muon class.
Definition: Muon.h:51