CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PFJetIDSelectionFunctor.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_PatUtils_interface_PFJetIDSelectionFunctor_h
2 #define PhysicsTools_PatUtils_interface_PFJetIDSelectionFunctor_h
3 
4 
24 
26 
27 #include <TMath.h>
28 class PFJetIDSelectionFunctor : public Selector<pat::Jet> {
29 
30  public: // interface
31 
34 
36 
38  {
39  std::string versionStr = params.getParameter<std::string>("version");
40  std::string qualityStr = params.getParameter<std::string>("quality");
41 
42  if ( versionStr == "FIRSTDATA" )
44  else
46 
47  if ( qualityStr == "LOOSE") quality_ = LOOSE;
48  else if ( qualityStr == "TIGHT") quality_ = TIGHT;
49  else quality_ = LOOSE;
50 
51  push_back("CHF" );
52  push_back("NHF" );
53  push_back("CEF" );
54  push_back("NEF" );
55  push_back("NCH" );
56  push_back("nConstituents");
57 
58 
59  // Set some default cuts for LOOSE, TIGHT
60  if ( quality_ == LOOSE ) {
61  set("CHF", 0.0);
62  set("NHF", 0.99);
63  set("CEF", 0.99);
64  set("NEF", 0.99);
65  set("NCH", 0);
66  set("nConstituents", 1);
67  } else if ( quality_ == TIGHT ) {
68  set("CHF", 0.0);
69  set("NHF", 0.9);
70  set("CEF", 0.99);
71  set("NEF", 0.9);
72  set("NCH", 0);
73  set("nConstituents", 1);
74  }
75 
76 
77  // Now check the configuration to see if the user changed anything
78  if ( params.exists("CHF") ) set("CHF", params.getParameter<double>("CHF") );
79  if ( params.exists("NHF") ) set("NHF", params.getParameter<double>("NHF") );
80  if ( params.exists("CEF") ) set("CEF", params.getParameter<double>("CEF") );
81  if ( params.exists("NEF") ) set("NEF", params.getParameter<double>("NEF") );
82  if ( params.exists("NCH") ) set("NCH", params.getParameter<int> ("NCH") );
83  if ( params.exists("nConstuents") ) set("nConstituents", params.getParameter<int> ("nConstituents") );
84 
85  if ( params.exists("cutsToIgnore") )
86  setIgnoredCuts( params.getParameter<std::vector<std::string> >("cutsToIgnore") );
87 
88 
89  indexNConstituents_ = index_type (&bits_, "nConstituents");
90  indexNEF_ = index_type (&bits_, "NEF");
91  indexNHF_ = index_type (&bits_, "NHF");
92  indexCEF_ = index_type (&bits_, "CEF");
93  indexCHF_ = index_type (&bits_, "CHF");
94  indexNCH_ = index_type (&bits_, "NCH");
95 
97 
98  }
99 
100 
102  Quality_t quality ) :
103  version_(version), quality_(quality)
104  {
105 
106  push_back("CHF" );
107  push_back("NHF" );
108  push_back("CEF" );
109  push_back("NEF" );
110  push_back("NCH" );
111  push_back("nConstituents");
112 
113 
114  // Set some default cuts for LOOSE, TIGHT
115  if ( quality_ == LOOSE ) {
116  set("CHF", 0.0);
117  set("NHF", 0.99);
118  set("CEF", 0.99);
119  set("NEF", 0.99);
120  set("NCH", 0);
121  set("nConstituents", 1);
122  } else if ( quality_ == TIGHT ) {
123  set("CHF", 0.0);
124  set("NHF", 0.9);
125  set("CEF", 0.99);
126  set("NEF", 0.9);
127  set("NCH", 0);
128  set("nConstituents", 1);
129  }
130 
131 
132  indexNConstituents_ = index_type (&bits_, "nConstituents");
133  indexNEF_ = index_type (&bits_, "NEF");
134  indexNHF_ = index_type (&bits_, "NHF");
135  indexCEF_ = index_type (&bits_, "CEF");
136  indexCHF_ = index_type (&bits_, "CHF");
137  indexNCH_ = index_type (&bits_, "NCH");
138 
140  }
141 
142 
143  //
144  // Accessor from PAT jets
145  //
147  {
148  if ( version_ == FIRSTDATA ) {
149  if ( jet.currentJECLevel() == "Uncorrected" )
150  return firstDataCuts( jet, ret );
151  else
152  return firstDataCuts( jet.correctedJet("Uncorrected"), ret );
153  }
154  else {
155  return false;
156  }
157  }
159 
160  //
161  // Accessor from *CORRECTED* 4-vector, EMF, and Jet ID.
162  // This can be used with reco quantities.
163  //
164  bool operator()( reco::PFJet const & jet,
165  pat::strbitset & ret )
166  {
167  if ( version_ == FIRSTDATA ) return firstDataCuts( jet, ret );
168  else {
169  return false;
170  }
171  }
172 
173  //
174  // cuts based on craft 08 analysis.
175  //
176  bool firstDataCuts( reco::Jet const & jet,
177  pat::strbitset & ret)
178  {
179 
180  ret.set(false);
181 
182  // cache some variables
183  double chf = 0.0;
184  double nhf = 0.0;
185  double cef = 0.0;
186  double nef = 0.0;
187  int nch = 0;
188  int nconstituents = 0;
189 
190  // Have to do this because pat::Jet inherits from reco::Jet but not reco::PFJet
191  reco::PFJet const * pfJet = dynamic_cast<reco::PFJet const *>(&jet);
192  pat::Jet const * patJet = dynamic_cast<pat::Jet const *>(&jet);
193  reco::BasicJet const * basicJet = dynamic_cast<reco::BasicJet const *>(&jet);
194 
195  if ( patJet != 0 ) {
196 
197  if ( patJet->isPFJet() ) {
198  chf = patJet->chargedHadronEnergyFraction();
199  nhf = ( patJet->neutralHadronEnergy() + patJet->HFHadronEnergy() ) / patJet->energy();
200  cef = patJet->chargedEmEnergyFraction();
201  nef = patJet->neutralEmEnergyFraction();
202  nch = patJet->chargedMultiplicity();
203  nconstituents = patJet->numberOfDaughters();
204  }
205  // Handle the special case where this is a composed jet for
206  // subjet analyses
207  else if ( patJet->isBasicJet() ) {
208  double e_chf = 0.0;
209  double e_nhf = 0.0;
210  double e_cef = 0.0;
211  double e_nef = 0.0;
212  nch = 0;
213  nconstituents = 0;
214 
215  for ( reco::Jet::const_iterator ibegin = patJet->begin(),
216  iend = patJet->end(), isub = ibegin;
217  isub != iend; ++isub ) {
218  reco::PFJet const * pfsub = dynamic_cast<reco::PFJet const *>( &*isub );
219  e_chf += pfsub->chargedHadronEnergy();
220  e_nhf += (pfsub->neutralHadronEnergy() + pfsub->HFHadronEnergy());
221  e_cef += pfsub->chargedEmEnergy();
222  e_nef += pfsub->neutralEmEnergy();
223  nch += pfsub->chargedMultiplicity();
224  nconstituents += pfsub->numberOfDaughters();
225  }
226  double e = patJet->energy();
227  if ( e > 0.000001 ) {
228  chf = e_chf / e;
229  nhf = e_nhf / e;
230  cef = e_cef / e;
231  nef = e_nef / e;
232  } else {
233  chf = nhf = cef = nef = 0.0;
234  }
235  }
236  } // end if pat jet
237  else if ( pfJet != 0 ) {
238  chf = pfJet->chargedHadronEnergyFraction();
239  nhf = ( pfJet->neutralHadronEnergy() + pfJet->HFHadronEnergy() ) / pfJet->energy();
240  cef = pfJet->chargedEmEnergyFraction();
241  nef = pfJet->neutralEmEnergyFraction();
242  nch = pfJet->chargedMultiplicity();
243  nconstituents = pfJet->numberOfDaughters();
244  } // end if PF jet
245  // Handle the special case where this is a composed jet for
246  // subjet analyses
247  else if ( basicJet != 0 ) {
248  double e_chf = 0.0;
249  double e_nhf = 0.0;
250  double e_cef = 0.0;
251  double e_nef = 0.0;
252  nch = 0;
253  nconstituents = 0;
254 
255  for ( reco::Jet::const_iterator ibegin = basicJet->begin(),
256  iend = patJet->end(), isub = ibegin;
257  isub != iend; ++isub ) {
258  reco::PFJet const * pfsub = dynamic_cast<reco::PFJet const *>( &*isub );
259  e_chf += pfsub->chargedHadronEnergy();
260  e_nhf += (pfsub->neutralHadronEnergy() + pfsub->HFHadronEnergy());
261  e_cef += pfsub->chargedEmEnergy();
262  e_nef += pfsub->neutralEmEnergy();
263  nch += pfsub->chargedMultiplicity();
264  nconstituents += pfsub->numberOfDaughters();
265  }
266  double e = basicJet->energy();
267  if ( e > 0.000001 ) {
268  chf = e_chf / e;
269  nhf = e_nhf / e;
270  cef = e_cef / e;
271  nef = e_nef / e;
272  }
273  } // end if basic jet
274 
275 
276  // Cuts for all |eta|:
277  if ( ignoreCut(indexNConstituents_) || nconstituents > cut(indexNConstituents_, int() ) ) passCut( ret, indexNConstituents_);
278  if ( ignoreCut(indexNEF_) || ( nef < cut(indexNEF_, double()) ) ) passCut( ret, indexNEF_);
279  if ( ignoreCut(indexNHF_) || ( nhf < cut(indexNHF_, double()) ) ) passCut( ret, indexNHF_);
280  // Cuts for |eta| < 2.4:
281  if ( ignoreCut(indexCEF_) || ( cef < cut(indexCEF_, double()) || std::abs(jet.eta()) > 2.4 ) ) passCut( ret, indexCEF_);
282  if ( ignoreCut(indexCHF_) || ( chf > cut(indexCHF_, double()) || std::abs(jet.eta()) > 2.4 ) ) passCut( ret, indexCHF_);
283  if ( ignoreCut(indexNCH_) || ( nch > cut(indexNCH_, int()) || std::abs(jet.eta()) > 2.4 ) ) passCut( ret, indexNCH_);
284 
285  setIgnored( ret );
286  return (bool)ret;
287  }
288 
289  private: // member variables
290 
293 
300 
301 };
302 
303 #endif
virtual double energy() const GCC11_FINAL
energy
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
float chargedEmEnergy() const
chargedEmEnergy
Definition: PFJet.h:139
float chargedHadronEnergyFraction() const
chargedHadronEnergyFraction (relative to uncorrected jet energy)
Definition: Jet.h:341
float chargedHadronEnergyFraction() const
chargedHadronEnergyFraction
Definition: PFJet.h:97
Base class for all types of Jets.
Definition: Jet.h:21
Jet correctedJet(const std::string &level, const std::string &flavor="none", const std::string &set="") const
Definition: Jet.cc:271
float neutralHadronEnergy() const
neutralHadronEnergy
Definition: Jet.h:581
float chargedEmEnergyFraction() const
chargedEmEnergyFraction (relative to uncorrected jet energy)
Definition: Jet.h:345
bool exists(std::string const &parameterName) const
checks if a parameter exists
#define abs(x)
Definition: mlp_lapack.h:159
pat::strbitset::index_type index_type
Definition: Selector.h:30
void setIgnored(pat::strbitset &ret)
set ignored bits
Definition: Selector.h:225
bool firstDataCuts(reco::Jet const &jet, pat::strbitset &ret)
pat::strbitset retInternal_
internal ret if users don&#39;t care about return bits
Definition: Selector.h:288
float HFHadronEnergy() const
HFHadronEnergy.
Definition: PFJet.h:115
Jets made from CaloTowers.
Definition: BasicJet.h:21
int chargedMultiplicity() const
chargedMultiplicity
Definition: PFJet.h:152
Jets made from PFObjects.
Definition: PFJet.h:22
PFJetIDSelectionFunctor(Version_t version, Quality_t quality)
float neutralEmEnergy() const
neutralEmEnergy
Definition: PFJet.h:147
PFJetIDSelectionFunctor(edm::ParameterSet const &params)
float neutralEmEnergyFraction() const
neutralEmEnergyFraction
Definition: PFJet.h:149
pat::strbitset bits_
the bitset indexed by strings
Definition: Selector.h:287
virtual size_t numberOfDaughters() const
number of daughters
void passCut(pat::strbitset &ret, std::string const &s)
Passing cuts.
Definition: Selector.h:177
float HFHadronEnergy() const
HFHadronEnergy.
Definition: Jet.h:363
bool ignoreCut(std::string const &s) const
ignore the cut at index &quot;s&quot;
Definition: Selector.h:160
bool operator()(const pat::Jet &jet, pat::strbitset &ret)
This provides the interface for base classes to select objects.
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
PF Jet selector for pat::Jets.
bool isPFJet() const
check to see if the jet is a reco::PFJet
Definition: Jet.h:226
virtual float eta() const GCC11_FINAL
momentum pseudorapidity
float chargedEmEnergyFraction() const
chargedEmEnergyFraction
Definition: PFJet.h:141
virtual size_t numberOfDaughters() const
Definition: Jet.h:430
bool operator()(reco::PFJet const &jet, pat::strbitset &ret)
virtual const_iterator begin() const
first daughter const_iterator
strbitset & set(bool val=true)
set method of all bits
Definition: strbitset.h:144
std::string currentJECLevel() const
return the name of the current step of jet energy corrections
Definition: Jet.h:122
Analysis-level calorimeter jet class.
Definition: Jet.h:71
pat::strbitset getBitTemplate() const
Get an empty bitset with the proper names.
Definition: Selector.h:213
virtual const_iterator end() const
last daughter const_iterator
bool isBasicJet() const
check to see if the jet is no more than a reco::BasicJet
Definition: Jet.h:228
float neutralHadronEnergy() const
neutralHadronEnergy
Definition: PFJet.h:99
void setIgnoredCuts(std::vector< std::string > const &bitsToIgnore)
set the bits to ignore from a vector
Definition: Selector.h:168
float neutralEmEnergyFraction() const
neutralEmEnergyFraction (relative to uncorrected jet energy)
Definition: Jet.h:347
int chargedMultiplicity() const
chargedMultiplicity
Definition: Jet.h:609
float chargedHadronEnergy() const
chargedHadronEnergy
Definition: PFJet.h:95
int cut(index_type const &i, int val) const
Access the int cut values at index &quot;s&quot;.
Definition: Selector.h:195