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 
18  public: // interface
19 
20  bool verbose_;
21 
23 
25 
26 #ifndef __GCCXML__
28  PFMuonSelector( parameters )
29  {}
30 #endif
31 
33 
34  verbose_ = false;
35 
36  std::string versionStr = parameters.getParameter<std::string>("version");
37 
39 
40  if ( versionStr == "TOPPAG12_LJETS" ) {
41  version = TOPPAG12_LJETS;
42  }
43  else {
44  throw cms::Exception("InvalidInput") << "Expect version to be one of SPRING11" << std::endl;
45  }
46 
47  initialize( version,
48  parameters.getParameter<double>("Chi2"),
49  parameters.getParameter<int> ("minTrackerLayers"),
50  parameters.getParameter<int> ("minValidMuHits"),
51  parameters.getParameter<double>("maxIp"),
52  parameters.getParameter<int> ("minPixelHits"),
53  parameters.getParameter<int> ("minMatchedStations"),
54  parameters.getParameter<double>("maxPfRelIso")
55  );
56  if ( parameters.exists("cutsToIgnore") )
57  setIgnoredCuts( parameters.getParameter<std::vector<std::string> >("cutsToIgnore") );
58 
60 
61  }
62 
64  double chi2 = 10.0,
65  int minTrackerLayers = 6,
66  int minValidMuonHits = 1,
67  double maxIp = 0.2,
68  int minPixelHits = 1,
69  int minNMatches = 2,
70  double pfiso = 0.12
71  )
72  {
73  version_ = version;
74 
75  push_back("GlobalMuon", true);
76  push_back("TrackerMuon", true);
77  push_back("Chi2", chi2 );
78  push_back("minTrackerLayers", minTrackerLayers);
79  push_back("minValidMuHits", minValidMuonHits );
80  push_back("maxIp", maxIp );
81  push_back("minPixelHits", minPixelHits);
82  push_back("minMatchedStations", minNMatches);
83  push_back("maxPfRelIso", pfiso );
84 
85  set("GlobalMuon");
86  set("TrackerMuon");
87  set("Chi2");
88  set("minTrackerLayers");
89  set("minValidMuHits");
90  set("maxIp");
91  set("minPixelHits");
92  set("minMatchedStations");
93  set("maxPfRelIso");
94 
95  indexChi2_ = index_type(&bits_, "Chi2" );
96  indexMinTrackerLayers_ = index_type(&bits_, "minTrackerLayers" );
97  indexminValidMuHits_ = index_type(&bits_, "minValidMuHits" );
98  indexMaxIp_ = index_type(&bits_, "maxIp" );
99  indexPixHits_ = index_type(&bits_, "minPixelHits" );
100  indexStations_ = index_type(&bits_, "minMatchedStations");
101  indexmaxPfRelIso_ = index_type(&bits_, "maxPfRelIso" );
102 
103 
104  if (version_ == TOPPAG12_LJETS ){
105  set("TrackerMuon", false);
106  }
107 
108  }
109 
110  // Allow for multiple definitions of the cuts.
111  bool operator()( const pat::Muon & muon, pat::strbitset & ret ) override
112  {
113  if (version_ == TOPPAG12_LJETS ) return TopPag12LjetsCuts(muon, ret);
114  else {
115  return false;
116  }
117  }
118 
120 
122 
123  ret.set(false);
124 
125  bool isGlobal = muon.isGlobalMuon();
126  bool isTracker = muon.isTrackerMuon();
127 
128  double norm_chi2 = 9999999.0;
129  int minTrackerLayers = 0;
130  int minValidMuonHits = 0;
131  int _ip = 0.0;
132  int minPixelHits = 0;
133  if ( muon.globalTrack().isNonnull() && muon.globalTrack().isAvailable() ){
134  norm_chi2 = muon.normChi2();
135  minTrackerLayers = static_cast<int> (muon.track()->hitPattern().trackerLayersWithMeasurement());
136  minValidMuonHits = static_cast<int> (muon.globalTrack()->hitPattern().numberOfValidMuonHits());
137  _ip = muon.dB();
138  minPixelHits = muon.innerTrack()->hitPattern().numberOfValidPixelHits();
139  }
140 
141  int minMatchedStations = muon.numberOfMatches();
142 
143  double chIso = muon.userIsolation(pat::PfChargedHadronIso);
144  double nhIso = muon.userIsolation(pat::PfNeutralHadronIso);
145  double gIso = muon.userIsolation(pat::PfGammaIso);
146  double pt = muon.pt() ;
147 
148  double pfIso = (chIso + nhIso + gIso) / pt;
149 
150  if ( isGlobal || ignoreCut("GlobalMuon") ) passCut(ret, "GlobalMuon" );
151  if ( isTracker || ignoreCut("TrackerMuon") ) passCut(ret, "TrackerMuon" );
152  if ( norm_chi2 < cut(indexChi2_, double()) || ignoreCut(indexChi2_) ) passCut(ret, indexChi2_ );
153  if ( minTrackerLayers >= cut(indexMinTrackerLayers_,int()) || ignoreCut(indexMinTrackerLayers_)) passCut(ret, indexMinTrackerLayers_ );
154  if ( minValidMuonHits >= cut(indexminValidMuHits_,int()) || ignoreCut(indexminValidMuHits_)) passCut(ret, indexminValidMuHits_ );
155  if ( _ip < cut(indexMaxIp_,double()) || ignoreCut(indexMaxIp_)) passCut(ret, indexMaxIp_ );
156  if ( minPixelHits >= cut(indexPixHits_,int()) || ignoreCut(indexPixHits_)) passCut(ret, indexPixHits_);
157  if ( minMatchedStations >= cut(indexStations_,int()) || ignoreCut(indexStations_)) passCut(ret, indexStations_);
158  if ( pfIso < cut(indexmaxPfRelIso_, double()) || ignoreCut(indexmaxPfRelIso_) ) passCut(ret, indexmaxPfRelIso_ );
159 
160  setIgnored(ret);
161 
162  return (bool)ret;
163  }
164 
165 
166 
167  private: // member variables
168 
170 
178 
179 
180 };
181 
182 #endif
bool isAvailable() const
Definition: Ref.h:577
T getParameter(std::string const &) const
bool operator()(const pat::Muon &muon, pat::strbitset &ret) override
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:253
PFMuonSelector(edm::ParameterSet const &parameters, edm::ConsumesCollector &&iC)
bool exists(std::string const &parameterName) const
checks if a parameter exists
double dB(IPTYPE type) const
index_type indexPixHits_
double pt() const final
transverse momentum
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)
reco::TrackRef track() const override
reference to Track reconstructed in the tracker only (reimplemented from reco::Muon) ...
index_type indexStations_
bool isTrackerMuon() const override
Definition: Muon.h:273
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
reco::TrackRef innerTrack() const override
reference to Track reconstructed in the tracker only (reimplemented from reco::Muon) ...
Definition: Muon.h:73
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 isGlobalMuon() const override
Definition: Muon.h:272
bool ignoreCut(std::string const &s) const
ignore the cut at index "s"
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 <T>
Definition: Selector.h:24
index_type indexMaxIp_
float userIsolation(IsolationKeys key) const
Definition: Lepton.h:50
reco::TrackRef globalTrack() const override
reference to Track reconstructed in both tracked and muon detector (reimplemented from reco::Muon) ...
Definition: Muon.h:81
strbitset & set(bool val=true)
set method of all bits
Definition: strbitset.h:144
int numberOfMatches(ArbitrationType type=SegmentAndTrackArbitration) const
get number of chambers with matched segments
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
double normChi2() const
Norm chi2 gives the normalized chi2 of the global track.
bool isTracker(GeomDetEnumerators::SubDetector m)
Analysis-level muon class.
Definition: Muon.h:50
int cut(index_type const &i, int val) const
Access the int cut values at index "s".
Definition: Selector.h:194