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 
54 
55 
57  double chi2 = 10.0,
58  int minTrackerLayers = 6,
59  int minValidMuonHits = 1,
60  double maxIp = 0.2,
61  int minPixelHits = 1,
62  int minNMatches = 2,
63  double pfiso = 0.12
64  )
65  {
66  version_ = version;
67 
68  push_back("GlobalMuon", true);
69  push_back("TrackerMuon", true);
70  push_back("Chi2", chi2 );
71  push_back("minTrackerLayers", minTrackerLayers);
72  push_back("minValidMuHits", minValidMuonHits );
73  push_back("maxIp", maxIp );
74  push_back("minPixelHits", minPixelHits);
75  push_back("minMatchedStations", minNMatches);
76  push_back("maxPfRelIso", pfiso );
77 
78  set("GlobalMuon");
79  set("TrackerMuon");
80  set("Chi2");
81  set("minTrackerLayers");
82  set("minValidMuHits");
83  set("maxIp");
84  set("minPixelHits");
85  set("minMatchedStations");
86  set("maxPfRelIso");
87 
88  indexChi2_ = index_type(&bits_, "Chi2" );
89  indexMinTrackerLayers_ = index_type(&bits_, "minTrackerLayers" );
90  indexminValidMuHits_ = index_type(&bits_, "minValidMuHits" );
91  indexMaxIp_ = index_type(&bits_, "maxIp" );
92  indexPixHits_ = index_type(&bits_, "minPixelHits" );
93  indexStations_ = index_type(&bits_, "minMatchedStations");
94  indexmaxPfRelIso_ = index_type(&bits_, "maxPfRelIso" );
95 
96 
97  if (version_ == TOPPAG12_LJETS ){
98  set("TrackerMuon", false);
99  }
100 
101  }
102 
103  // Allow for multiple definitions of the cuts.
105  {
106  if (version_ == TOPPAG12_LJETS ) return TopPag12LjetsCuts(muon, ret);
107  else {
108  return false;
109  }
110  }
111 
112 
113 
115 
116 
117 
119 
120  ret.set(false);
121 
122 
123  bool isGlobal = muon.isGlobalMuon();
124  bool isTracker = muon.isTrackerMuon();
125 
126 
127  double norm_chi2 = 9999999.0;
128  int minTrackerLayers = 0;
129  int minValidMuonHits = 0;
130  int _ip = 0.0;
131  int minPixelHits = 0;
132  if ( muon.globalTrack().isNonnull() && muon.globalTrack().isAvailable() ){
133  norm_chi2 = muon.normChi2();
134  minTrackerLayers = static_cast<int> (muon.track()->hitPattern().trackerLayersWithMeasurement());
135  minValidMuonHits = static_cast<int> (muon.globalTrack()->hitPattern().numberOfValidMuonHits());
136  _ip = muon.dB();
137  minPixelHits = muon.innerTrack()->hitPattern().numberOfValidPixelHits();
138  }
139 
140 
141  int minMatchedStations = muon.numberOfMatches();
142 
143 
144  double chIso = muon.userIsolation(pat::PfChargedHadronIso);
145  double nhIso = muon.userIsolation(pat::PfNeutralHadronIso);
146  double gIso = muon.userIsolation(pat::PfGammaIso);
147  double puIso = muon.userIsolation(pat::PfPUChargedHadronIso);
148  double pt = muon.pt() ;
149 
150  double pfIso = ( chIso + std::max( 0.0, nhIso + gIso - 0.5 * puIso) ) / pt;
151 
152 
153  if ( isGlobal || ignoreCut("GlobalMuon") ) passCut(ret, "GlobalMuon" );
154  if ( isTracker || ignoreCut("TrackerMuon") ) passCut(ret, "TrackerMuon" );
155  if ( norm_chi2 < cut(indexChi2_, double()) || ignoreCut(indexChi2_) ) passCut(ret, indexChi2_ );
156  if ( minTrackerLayers >= cut(indexMinTrackerLayers_,int()) || ignoreCut(indexMinTrackerLayers_)) passCut(ret, indexMinTrackerLayers_ );
157  if ( minValidMuonHits >= cut(indexminValidMuHits_,int()) || ignoreCut(indexminValidMuHits_)) passCut(ret, indexminValidMuHits_ );
158  if ( _ip < cut(indexMaxIp_,double()) || ignoreCut(indexMaxIp_)) passCut(ret, indexMaxIp_ );
159  if ( minPixelHits >= cut(indexPixHits_,int()) || ignoreCut(indexPixHits_)) passCut(ret, indexPixHits_);
160  if ( minMatchedStations >= cut(indexStations_,int()) || ignoreCut(indexStations_)) passCut(ret, indexStations_);
161  if ( pfIso < cut(indexmaxPfRelIso_, double()) || ignoreCut(indexmaxPfRelIso_) ) passCut(ret, indexmaxPfRelIso_ );
162 
163  setIgnored(ret);
164 
165  return (bool)ret;
166  }
167 
168 
169 
170  private: // member variables
171 
173 
181 
182 
183 };
184 
185 #endif
double normChi2() const
Norm chi2 gives the normalized chi2 of the global track.
Definition: Muon.cc:363
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:106
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:74
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:212
bool exists(std::string const &parameterName) const
checks if a parameter exists
bool isGlobalMuon() const
Definition: Muon.h:211
index_type indexPixHits_
Version_t version_
pat::strbitset::index_type index_type
Definition: Selector.h:30
void setIgnored(pat::strbitset &ret)
set ignored bits
Definition: Selector.h:225
pat::strbitset retInternal_
internal ret if users don&#39;t care about return bits
Definition: Selector.h:288
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:287
void passCut(pat::strbitset &ret, std::string const &s)
Passing cuts.
Definition: Selector.h:177
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)
const T & max(const T &a, const T &b)
bool ignoreCut(std::string const &s) const
ignore the cut at index &quot;s&quot;
Definition: Selector.h:160
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:47
index_type indexMinTrackerLayers_
Functor that operates on &lt;T&gt;
Definition: Selector.h:25
double dB(IpType type=None) const
Definition: Muon.cc:389
reco::TrackRef globalTrack() const
reference to Track reconstructed in both tracked and muon detector (reimplemented from reco::Muon) ...
Definition: Muon.h:82
index_type indexMaxIp_
int numberOfMatches(ArbitrationType type=SegmentAndTrackArbitration) const
get number of chambers with matched segments
Definition: Muon.cc:56
float userIsolation(IsolationKeys key) const
Definition: Lepton.h:51
virtual double pt() const
transverse momentum
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:213
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:168
Analysis-level muon class.
Definition: Muon.h:51
reco::TrackRef track() const
reference to Track reconstructed in the tracker only (reimplemented from reco::Muon) ...
Definition: Muon.cc:156
int cut(index_type const &i, int val) const
Access the int cut values at index &quot;s&quot;.
Definition: Selector.h:195