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