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 == "SPRING11" ) {
32  version = SPRING11;
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<double>("D0") ,
41  parameters.getParameter<int> ("NHits") ,
42  parameters.getParameter<int> ("NValMuHits"),
43  parameters.getParameter<double>("PFIso"),
44  parameters.getParameter<int> ("nPixelHits"),
45  parameters.getParameter<int> ("nMatchedStations")
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  double d0 = 0.02,
57  int nhits = 11,
58  int nValidMuonHits = 0,
59  double pfiso = 0.15,
60  int minPixelHits = 1,
61  int minNMatches = 1 )
62  {
63  version_ = version;
64 
65  push_back("Chi2", chi2 );
66  push_back("D0", d0 );
67  push_back("NHits", nhits );
68  push_back("NValMuHits",nValidMuonHits );
69  push_back("PFIso", pfiso );
70  push_back("nPixelHits",minPixelHits);
71  push_back("nMatchedStations", minNMatches);
72 
73  set("Chi2");
74  set("D0");
75  set("NHits");
76  set("NValMuHits");
77  set("PFIso");
78  set("nPixelHits");
79  set("nMatchedStations");
80 
81  indexChi2_ = index_type(&bits_, "Chi2" );
82  indexD0_ = index_type(&bits_, "D0" );
83  indexNHits_ = index_type(&bits_, "NHits" );
84  indexNValMuHits_ = index_type(&bits_, "NValMuHits" );
85  indexPFIso_ = index_type(&bits_, "PFIso" );
86  indexPixHits_ = index_type(&bits_, "nPixelHits");
87  indexStations_ = index_type(&bits_, "nMatchedStations");
88 
89  }
90 
91  // Allow for multiple definitions of the cuts.
93  {
94  if (version_ == SPRING11 ) return spring11Cuts(muon, ret);
95  else {
96  return false;
97  }
98  }
99 
101 
102  // cuts based on top group L+J synchronization exercise
104  {
105  ret.set(false);
106 
107  double norm_chi2 = 9999999.0;
108  if ( muon.globalTrack().isNonnull() && muon.globalTrack().isAvailable() )
109  norm_chi2 = muon.normChi2();
110  double corr_d0 = 999999.0;
111  if ( muon.globalTrack().isNonnull() && muon.globalTrack().isAvailable() )
112  corr_d0 = muon.dB();
113 
114  int nhits = static_cast<int>( muon.numberOfValidHits() );
115  int nValidMuonHits = 0;
116  if ( muon.globalTrack().isNonnull() && muon.globalTrack().isAvailable() )
117  nValidMuonHits = static_cast<int> (muon.globalTrack()->hitPattern().numberOfValidMuonHits());
118 
119  double chIso = muon.userIsolation(pat::PfChargedHadronIso);
120  double nhIso = muon.userIsolation(pat::PfNeutralHadronIso);
121  double gIso = muon.userIsolation(pat::PfGammaIso);
122  double pt = muon.pt() ;
123 
124  double pfIso = (chIso + nhIso + gIso) / pt;
125 
126  int nPixelHits = 0;
127  if ( muon.innerTrack().isNonnull() && muon.innerTrack().isAvailable() )
128  nPixelHits = muon.innerTrack()->hitPattern().pixelLayersWithMeasurement();
129 
130  int nMatchedStations = muon.numberOfMatches();
131 
132  if ( norm_chi2 < cut(indexChi2_, double()) || ignoreCut(indexChi2_) ) passCut(ret, indexChi2_ );
133  if ( fabs(corr_d0) < cut(indexD0_, double()) || ignoreCut(indexD0_) ) passCut(ret, indexD0_ );
134  if ( nhits >= cut(indexNHits_, int() ) || ignoreCut(indexNHits_) ) passCut(ret, indexNHits_ );
135  if ( nValidMuonHits> cut(indexNValMuHits_,int()) || ignoreCut(indexNValMuHits_)) passCut(ret, indexNValMuHits_ );
136  if ( pfIso < cut(indexPFIso_, double()) || ignoreCut(indexPFIso_) ) passCut(ret, indexPFIso_ );
137  if ( nPixelHits > cut(indexPixHits_,int()) || ignoreCut(indexPixHits_)) passCut(ret, indexPixHits_);
138  if ( nMatchedStations> cut(indexStations_,int()) || ignoreCut(indexStations_)) passCut(ret, indexStations_);
139 
140  setIgnored(ret);
141 
142  return (bool)ret;
143  }
144 
145 
146 
147  private: // member variables
148 
150 
158 
159 
160 };
161 
162 #endif
double normChi2() const
Norm chi2 gives the normalized chi2 of the global track.
Definition: Muon.cc:318
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
unsigned int numberOfValidHits() const
numberOfValidHits returns the number of valid hits on the global track.
Definition: Muon.cc:331
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 exists(std::string const &parameterName) const
checks if a parameter exists
index_type indexPixHits_
Version_t version_
pat::strbitset::index_type index_type
Definition: Selector.h:30
void initialize(Version_t version, double chi2=10.0, double d0=0.02, int nhits=11, int nValidMuonHits=0, double pfiso=0.15, int minPixelHits=1, int minNMatches=1)
void setIgnored(pat::strbitset &ret)
set ignored bits
Definition: Selector.h:225
index_type indexNHits_
pat::strbitset retInternal_
internal ret if users don&#39;t care about return bits
Definition: Selector.h:288
bool isAvailable() const
Definition: Ref.h:276
index_type indexStations_
index_type indexNValMuHits_
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
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
index_type indexPFIso_
bool ignoreCut(std::string const &s) const
ignore the cut at index &quot;s&quot;
Definition: Selector.h:160
index_type indexD0_
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
Functor that operates on &lt;T&gt;
Definition: Selector.h:25
double dB(IpType type=None) const
Definition: Muon.cc:344
reco::TrackRef globalTrack() const
reference to Track reconstructed in both tracked and muon detector (reimplemented from reco::Muon) ...
Definition: Muon.h:82
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:51
strbitset & set(bool val=true)
set method of all bits
Definition: strbitset.h:144
bool spring11Cuts(const pat::Muon &muon, pat::strbitset &ret)
pat::strbitset getBitTemplate() const
Get an empty bitset with the proper names.
Definition: Selector.h:213
index_type indexChi2_
void setIgnoredCuts(std::vector< std::string > const &bitsToIgnore)
set the bits to ignore from a vector
Definition: Selector.h:168
virtual float pt() const GCC11_FINAL
transverse momentum
Analysis-level muon class.
Definition: Muon.h:51
int cut(index_type const &i, int val) const
Access the int cut values at index &quot;s&quot;.
Definition: Selector.h:195