CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PFMuonSelector.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_PatUtils_interface_PFMuonSelector_h
2 #define PhysicsTools_PatUtils_interface_PFMuonSelector_h
3 
7 
10 
11 #include <iostream>
12 
13 class PFMuonSelector : public Selector<pat::Muon> {
14 
15  public: // interface
16 
17  bool verbose_;
18 
20 
22 
24 
25  verbose_ = false;
26 
27  std::string versionStr = parameters.getParameter<std::string>("version");
28 
30 
31  if ( versionStr == "TOPPAG12_LJETS" ) {
32  version = TOPPAG12_LJETS;
33  }
34  else {
35  throw cms::Exception("InvalidInput") << "Expect version to be one of SPRING11" << std::endl;
36  }
37 
38  initialize( version,
39  parameters.getParameter<double>("Chi2"),
40  parameters.getParameter<int> ("minTrackerLayers"),
41  parameters.getParameter<int> ("minValidMuHits"),
42  parameters.getParameter<double>("maxIp"),
43  parameters.getParameter<int> ("minPixelHits"),
44  parameters.getParameter<int> ("minMatchedStations"),
45  parameters.getParameter<double>("maxPfRelIso")
46  );
47  if ( parameters.exists("cutsToIgnore") )
48  setIgnoredCuts( parameters.getParameter<std::vector<std::string> >("cutsToIgnore") );
49 
51 
52  }
53 
55  double chi2 = 10.0,
56  int minTrackerLayers = 6,
57  int minValidMuonHits = 1,
58  double maxIp = 0.2,
59  int minPixelHits = 1,
60  int minNMatches = 2,
61  double pfiso = 0.12
62  )
63  {
64  version_ = version;
65 
66  push_back("GlobalMuon", true);
67  push_back("TrackerMuon", true);
68  push_back("Chi2", chi2 );
69  push_back("minTrackerLayers", minTrackerLayers);
70  push_back("minValidMuHits", minValidMuonHits );
71  push_back("maxIp", maxIp );
72  push_back("minPixelHits", minPixelHits);
73  push_back("minMatchedStations", minNMatches);
74  push_back("maxPfRelIso", pfiso );
75 
76  set("GlobalMuon");
77  set("TrackerMuon");
78  set("Chi2");
79  set("minTrackerLayers");
80  set("minValidMuHits");
81  set("maxIp");
82  set("minPixelHits");
83  set("minMatchedStations");
84  set("maxPfRelIso");
85 
86  indexChi2_ = index_type(&bits_, "Chi2" );
87  indexMinTrackerLayers_ = index_type(&bits_, "minTrackerLayers" );
88  indexminValidMuHits_ = index_type(&bits_, "minValidMuHits" );
89  indexMaxIp_ = index_type(&bits_, "maxIp" );
90  indexPixHits_ = index_type(&bits_, "minPixelHits" );
91  indexStations_ = index_type(&bits_, "minMatchedStations");
92  indexmaxPfRelIso_ = index_type(&bits_, "maxPfRelIso" );
93 
94 
95  if (version_ == TOPPAG12_LJETS ){
96  set("TrackerMuon", false);
97  }
98 
99  }
100 
101  // Allow for multiple definitions of the cuts.
103  {
104  if (version_ == TOPPAG12_LJETS ) return TopPag12LjetsCuts(muon, ret);
105  else {
106  return false;
107  }
108  }
109 
111 
113 
114  ret.set(false);
115 
116  bool isGlobal = muon.isGlobalMuon();
117  bool isTracker = muon.isTrackerMuon();
118 
119  double norm_chi2 = 9999999.0;
120  int minTrackerLayers = 0;
121  int minValidMuonHits = 0;
122  int _ip = 0.0;
123  int minPixelHits = 0;
124  if ( muon.globalTrack().isNonnull() && muon.globalTrack().isAvailable() ){
125  norm_chi2 = muon.normChi2();
126  minTrackerLayers = static_cast<int> (muon.track()->hitPattern().trackerLayersWithMeasurement());
127  minValidMuonHits = static_cast<int> (muon.globalTrack()->hitPattern().numberOfValidMuonHits());
128  _ip = muon.dB();
129  minPixelHits = muon.innerTrack()->hitPattern().numberOfValidPixelHits();
130  }
131 
132  int minMatchedStations = muon.numberOfMatches();
133 
134  double chIso = muon.userIsolation(pat::PfChargedHadronIso);
135  double nhIso = muon.userIsolation(pat::PfNeutralHadronIso);
136  double gIso = muon.userIsolation(pat::PfGammaIso);
137  double pt = muon.pt() ;
138 
139  double pfIso = (chIso + nhIso + gIso) / pt;
140 
141  if ( isGlobal || ignoreCut("GlobalMuon") ) passCut(ret, "GlobalMuon" );
142  if ( isTracker || ignoreCut("TrackerMuon") ) passCut(ret, "TrackerMuon" );
143  if ( norm_chi2 < cut(indexChi2_, double()) || ignoreCut(indexChi2_) ) passCut(ret, indexChi2_ );
144  if ( minTrackerLayers >= cut(indexMinTrackerLayers_,int()) || ignoreCut(indexMinTrackerLayers_)) passCut(ret, indexMinTrackerLayers_ );
145  if ( minValidMuonHits >= cut(indexminValidMuHits_,int()) || ignoreCut(indexminValidMuHits_)) passCut(ret, indexminValidMuHits_ );
146  if ( _ip < cut(indexMaxIp_,double()) || ignoreCut(indexMaxIp_)) passCut(ret, indexMaxIp_ );
147  if ( minPixelHits >= cut(indexPixHits_,int()) || ignoreCut(indexPixHits_)) passCut(ret, indexPixHits_);
148  if ( minMatchedStations >= cut(indexStations_,int()) || ignoreCut(indexStations_)) passCut(ret, indexStations_);
149  if ( pfIso < cut(indexmaxPfRelIso_, double()) || ignoreCut(indexmaxPfRelIso_) ) passCut(ret, indexmaxPfRelIso_ );
150 
151  setIgnored(ret);
152 
153  return (bool)ret;
154  }
155 
156 
157 
158  private: // member variables
159 
161 
169 
170 
171 };
172 
173 #endif
double normChi2() const
Norm chi2 gives the normalized chi2 of the global track.
Definition: Muon.cc:317
T getParameter(std::string const &) const
void set(std::string const &s, bool val=true)
Set a given selection cut, on or off.
Definition: Selector.h:105
dictionary parameters
Definition: Parameters.py:2
reco::TrackRef innerTrack() const
reference to Track reconstructed in the tracker only (reimplemented from reco::Muon) ...
Definition: Muon.h:72
bool operator()(const pat::Muon &muon, pat::strbitset &ret)
This provides the interface for base classes to select objects.
bool isTrackerMuon() const
Definition: Muon.h:219
bool exists(std::string const &parameterName) const
checks if a parameter exists
bool isGlobalMuon() const
Definition: Muon.h:218
index_type indexPixHits_
Version_t version_
pat::strbitset::index_type index_type
Definition: Selector.h:29
void setIgnored(pat::strbitset &ret)
set ignored bits
Definition: Selector.h:224
pat::strbitset retInternal_
internal ret if users don&#39;t care about return bits
Definition: Selector.h:287
bool TopPag12LjetsCuts(const pat::Muon &muon, pat::strbitset &ret)
bool isAvailable() const
Definition: Ref.h:276
index_type indexStations_
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
index_type indexminValidMuHits_
pat::strbitset bits_
the bitset indexed by strings
Definition: Selector.h:286
void passCut(pat::strbitset &ret, std::string const &s)
Passing cuts.
Definition: Selector.h:176
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)
bool ignoreCut(std::string const &s) const
ignore the cut at index &quot;s&quot;
Definition: Selector.h:159
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:46
index_type indexMinTrackerLayers_
Functor that operates on &lt;T&gt;
Definition: Selector.h:24
double dB(IpType type=None) const
Definition: Muon.cc:343
reco::TrackRef globalTrack() const
reference to Track reconstructed in both tracked and muon detector (reimplemented from reco::Muon) ...
Definition: Muon.h:80
index_type indexMaxIp_
int numberOfMatches(ArbitrationType type=SegmentAndTrackArbitration) const
get number of chambers with matched segments
Definition: Muon.cc:60
float userIsolation(IsolationKeys key) const
Definition: Lepton.h:49
strbitset & set(bool val=true)
set method of all bits
Definition: strbitset.h:144
pat::strbitset getBitTemplate() const
Get an empty bitset with the proper names.
Definition: Selector.h:212
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:167
virtual float pt() const GCC11_FINAL
transverse momentum
Analysis-level muon class.
Definition: Muon.h:49
reco::TrackRef track() const
reference to Track reconstructed in the tracker only (reimplemented from reco::Muon) ...
Definition: Muon.cc:141
int cut(index_type const &i, int val) const
Access the int cut values at index &quot;s&quot;.
Definition: Selector.h:194