CMS 3D CMS Logo

JetIDSelectionFunctor.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_PatUtils_interface_JetIDSelectionFunctor_h
2 #define PhysicsTools_PatUtils_interface_JetIDSelectionFunctor_h
3 
18 #ifndef __GCCXML__
20 #endif
23 
26 
27 #include <TMath.h>
28 class JetIDSelectionFunctor : public Selector<pat::Jet> {
29 public: // interface
32 
34 
35 #ifndef __GCCXML__
38 #endif
39 
41  std::string versionStr = parameters.getParameter<std::string>("version");
42  std::string qualityStr = parameters.getParameter<std::string>("quality");
44 
45  if (qualityStr == "MINIMAL")
46  quality = MINIMAL;
47  else if (qualityStr == "LOOSE_AOD")
49  else if (qualityStr == "LOOSE")
50  quality = LOOSE;
51  else if (qualityStr == "TIGHT")
52  quality = TIGHT;
53  else
54  throw cms::Exception("InvalidInput")
55  << "Expect quality to be one of MINIMAL, LOOSE_AOD, LOOSE,TIGHT" << std::endl;
56 
57  if (versionStr == "CRAFT08") {
59  } else if (versionStr == "PURE09") {
61  } else if (versionStr == "DQM09") {
63  } else {
64  throw cms::Exception("InvalidInput") << "Expect version to be one of CRAFT08, PURE09, DQM09" << std::endl;
65  }
66  }
67 
69 
71  version_ = version;
72  quality_ = quality;
73 
74  push_back("MINIMAL_EMF");
75 
76  push_back("LOOSE_AOD_fHPD");
77  push_back("LOOSE_AOD_N90Hits");
78  push_back("LOOSE_AOD_EMF");
79 
80  push_back("LOOSE_fHPD");
81  push_back("LOOSE_N90Hits");
82  push_back("LOOSE_EMF");
83 
84  push_back("TIGHT_fHPD");
85  push_back("TIGHT_EMF");
86 
87  push_back("LOOSE_nHit");
88  push_back("LOOSE_als");
89  push_back("LOOSE_fls");
90  push_back("LOOSE_foot");
91 
92  push_back("TIGHT_nHit");
93  push_back("TIGHT_als");
94  push_back("TIGHT_fls");
95  push_back("TIGHT_foot");
96  push_back("widths");
97  push_back("EF_N90Hits");
98  push_back("EF_EMF");
99 
100  bool use_09_fwd_id = version_ != CRAFT08; // CRAFT08 predates the 09 forward ID cuts
101  bool use_dqm_09 = version_ == DQM09 && quality_ != LOOSE_AOD;
102 
103  // all appropriate for version and format (AOD complications) are on by default
104  set("MINIMAL_EMF");
105  set("LOOSE_AOD_fHPD");
106  set("LOOSE_AOD_N90Hits");
107  set("LOOSE_AOD_EMF", !use_09_fwd_id); // except in CRAFT08, this devolves into MINIMAL_EMF
108  set("LOOSE_fHPD");
109  set("LOOSE_N90Hits");
110  set("LOOSE_EMF", !use_09_fwd_id); // except in CRAFT08, this devolves into MINIMAL_EMF
111  set("TIGHT_fHPD");
112  set("TIGHT_EMF");
113 
114  set("LOOSE_nHit", use_09_fwd_id);
115  set("LOOSE_als", use_09_fwd_id);
116  set("TIGHT_nHit", use_09_fwd_id);
117  set("TIGHT_als", use_09_fwd_id);
118  set("widths", use_09_fwd_id);
119  set("EF_N90Hits", use_09_fwd_id);
120  set("EF_EMF", use_09_fwd_id);
121 
122  set("LOOSE_fls", use_dqm_09);
123  set("LOOSE_foot", use_dqm_09);
124  set("TIGHT_fls", use_dqm_09);
125  set("TIGHT_foot", use_dqm_09);
126 
127  index_MINIMAL_EMF_ = index_type(&bits_, "MINIMAL_EMF");
128 
129  index_LOOSE_AOD_fHPD_ = index_type(&bits_, "LOOSE_AOD_fHPD");
130  index_LOOSE_AOD_N90Hits_ = index_type(&bits_, "LOOSE_AOD_N90Hits");
131  index_LOOSE_AOD_EMF_ = index_type(&bits_, "LOOSE_AOD_EMF");
132 
133  index_LOOSE_fHPD_ = index_type(&bits_, "LOOSE_fHPD");
134  index_LOOSE_N90Hits_ = index_type(&bits_, "LOOSE_N90Hits");
135  index_LOOSE_EMF_ = index_type(&bits_, "LOOSE_EMF");
136 
137  index_TIGHT_fHPD_ = index_type(&bits_, "TIGHT_fHPD");
138  index_TIGHT_EMF_ = index_type(&bits_, "TIGHT_EMF");
139 
140  index_LOOSE_nHit_ = index_type(&bits_, "LOOSE_nHit");
141  index_LOOSE_als_ = index_type(&bits_, "LOOSE_als");
142  index_LOOSE_fls_ = index_type(&bits_, "LOOSE_fls");
143  index_LOOSE_foot_ = index_type(&bits_, "LOOSE_foot");
144 
145  index_TIGHT_nHit_ = index_type(&bits_, "TIGHT_nHit");
146  index_TIGHT_als_ = index_type(&bits_, "TIGHT_als");
147  index_TIGHT_fls_ = index_type(&bits_, "TIGHT_fls");
148  index_TIGHT_foot_ = index_type(&bits_, "TIGHT_foot");
149  index_widths_ = index_type(&bits_, "widths");
150  index_EF_N90Hits_ = index_type(&bits_, "EF_N90Hits");
151  index_EF_EMF_ = index_type(&bits_, "EF_EMF");
152 
153  // now set the return values for the ignored parts
154  bool use_loose_aod = false;
155  bool use_loose = false;
156  bool use_tight = false;
157  bool use_tight_09_fwd_id = false;
158  bool use_loose_09_fwd_id = false;
159  // if ( quality_ == MINIMAL ) nothing to do...
160  if (quality_ == LOOSE) {
161  use_loose = true;
162  if (use_09_fwd_id)
163  use_loose_09_fwd_id = true;
164  }
165  if (quality_ == LOOSE_AOD) {
166  use_loose_aod = true;
167  if (use_09_fwd_id)
168  use_loose_09_fwd_id = true;
169  }
170  if (quality_ == TIGHT) {
171  use_tight = true;
172  if (use_09_fwd_id)
173  use_tight_09_fwd_id = true;
174  }
175 
176  if (!use_loose_aod) {
177  set("LOOSE_AOD_fHPD", false);
178  set("LOOSE_AOD_N90Hits", false);
179  set("LOOSE_AOD_EMF", false);
180  }
181 
182  if (!(use_loose || use_tight)) { // the CRAFT08 cuts are cumulative
183  set("LOOSE_N90Hits", false);
184  set("LOOSE_fHPD", false);
185  set("LOOSE_EMF", false);
186  }
187 
188  if (!use_tight) {
189  set("TIGHT_fHPD", false);
190  set("TIGHT_EMF", false);
191  }
192 
193  if (!use_loose_09_fwd_id) { // the FWD09 cuts are not
194  set("LOOSE_nHit", false);
195  set("LOOSE_als", false);
196  if (use_dqm_09) {
197  set("LOOSE_fls", false);
198  set("LOOSE_foot", false);
199  }
200  } // not using loose 09 fwd ID
201 
202  if (!use_tight_09_fwd_id) {
203  set("TIGHT_nHit", false);
204  set("TIGHT_als", false);
205  set("widths", false);
206  set("EF_N90Hits", false);
207  set("EF_EMF", false);
208  if (use_dqm_09) {
209  set("TIGHT_fls", false);
210  set("TIGHT_foot", false);
211  }
212  } // not using tight 09 fwd ID
213 
215  }
216 
217  // this functionality should be migrated into JetIDHelper in future releases
218  unsigned int count_hits(const std::vector<CaloTowerPtr>& towers) {
219  unsigned int nHit = 0;
220  for (unsigned int iTower = 0; iTower < towers.size(); ++iTower) {
221  const std::vector<DetId>& cellIDs = towers[iTower]->constituents(); // cell == recHit
222  nHit += cellIDs.size();
223  }
224  return nHit;
225  }
226 
227  //
228  // Accessor from PAT jets
229  //
230  bool operator()(const pat::Jet& jet, pat::strbitset& ret) override {
231  if (!jet.isCaloJet() && !jet.isJPTJet()) {
232  edm::LogWarning("NYI") << "Criteria for pat::Jet-s other than CaloJets and JPTJets are not yet implemented";
233  return false;
234  }
235  if (version_ == CRAFT08)
236  return craft08Cuts(jet.p4(), jet.emEnergyFraction(), jet.jetID(), ret);
237  if (version_ == PURE09 || version_ == DQM09) {
238  unsigned int nHit = count_hits(jet.getCaloConstituents());
239  if (jet.currentJECLevel() == "Uncorrected") {
240  return fwd09Cuts(
241  jet.p4(), jet.emEnergyFraction(), jet.etaetaMoment(), jet.phiphiMoment(), nHit, jet.jetID(), ret);
242  } else {
243  return fwd09Cuts(jet.correctedP4("Uncorrected"),
244  jet.emEnergyFraction(),
245  jet.etaetaMoment(),
246  jet.phiphiMoment(),
247  nHit,
248  jet.jetID(),
249  ret);
250  }
251  }
252  edm::LogWarning("BadInput | NYI") << "Requested version (" << version_ << ") is unknown";
253  return false;
254  }
255 
256  // accessor from PAT jets without the ret
258 
259  //
260  // Accessor from *CORRECTED* 4-vector, EMF, and Jet ID.
261  // This can be used with reco quantities.
262  //
264  double emEnergyFraction,
265  reco::JetID const& jetID,
266  pat::strbitset& ret) {
267  if (version_ == CRAFT08)
268  return craft08Cuts(correctedP4, emEnergyFraction, jetID, ret);
269  edm::LogWarning("BadInput | NYI") << "Requested version (" << version_
270  << ") is unknown or doesn't match the depreceated interface used";
271  return false;
272  }
274  virtual bool operator()(reco::Candidate::LorentzVector const& correctedP4,
275  double emEnergyFraction,
276  reco::JetID const& jetID) {
277  retInternal_.set(false);
278  operator()(correctedP4, emEnergyFraction, jetID, retInternal_);
280  return (bool)retInternal_;
281  }
282 
283  //
284  // Accessor from CaloJet and Jet ID. Jets MUST BE corrected for craft08, but uncorrected for later cuts...
285  // This can be used with reco quantities.
286  //
287  bool operator()(reco::CaloJet const& jet, reco::JetID const& jetID, pat::strbitset& ret) {
288  if (version_ == CRAFT08)
289  return craft08Cuts(jet.p4(), jet.emEnergyFraction(), jetID, ret);
290  if (version_ == PURE09 || version_ == DQM09) {
291  unsigned int nHit = count_hits(jet.getCaloConstituents());
292  return fwd09Cuts(jet.p4(), jet.emEnergyFraction(), jet.etaetaMoment(), jet.phiphiMoment(), nHit, jetID, ret);
293  }
294  edm::LogWarning("BadInput | NYI") << "Requested version (" << version_ << ") is unknown";
295  return false;
296  }
297 
299  virtual bool operator()(reco::CaloJet const& jet, reco::JetID const& jetID) {
300  retInternal_.set(false);
301  operator()(jet, jetID, retInternal_);
303  return (bool)retInternal_;
304  }
305 
306  //
307  // cuts based on craft 08 analysis.
308  //
310  double emEnergyFraction,
311  reco::JetID const& jetID,
312  pat::strbitset& ret) {
313  ret.set(false);
314 
315  // cache some variables
316  double abs_eta = TMath::Abs(correctedP4.eta());
317  double corrPt = correctedP4.pt();
318  double emf = emEnergyFraction;
319 
320  if (ignoreCut(index_MINIMAL_EMF_) || abs_eta > 2.6 || emf > 0.01)
322 
323  if (quality_ == LOOSE_AOD) {
324  // loose fhpd cut from aod
325  if (ignoreCut(index_LOOSE_AOD_fHPD_) || jetID.approximatefHPD < 0.98)
327  // loose n90 hits cut
328  if (ignoreCut(index_LOOSE_AOD_N90Hits_) || jetID.hitsInN90 > 1)
330 
331  // loose EMF Cut from aod
332  bool emf_loose = true;
333  if (abs_eta <= 2.6) { // HBHE
334  if (emEnergyFraction <= 0.01)
335  emf_loose = false;
336  } else { // HF
337  if (emEnergyFraction <= -0.9)
338  emf_loose = false;
339  if (corrPt > 80 && emEnergyFraction >= 1)
340  emf_loose = false;
341  }
342  if (ignoreCut(index_LOOSE_AOD_EMF_) || emf_loose)
344 
345  } else if (quality_ == LOOSE || quality_ == TIGHT) {
346  // loose fhpd cut
347  if (ignoreCut(index_LOOSE_fHPD_) || jetID.fHPD < 0.98)
349  // loose n90 hits cut
350  if (ignoreCut(index_LOOSE_N90Hits_) || jetID.n90Hits > 1)
352 
353  // loose EMF Cut
354  bool emf_loose = true;
355  if (abs_eta <= 2.6) { // HBHE
356  if (emEnergyFraction <= 0.01)
357  emf_loose = false;
358  } else { // HF
359  if (emEnergyFraction <= -0.9)
360  emf_loose = false;
361  if (corrPt > 80 && emEnergyFraction >= 1)
362  emf_loose = false;
363  }
364  if (ignoreCut(index_LOOSE_EMF_) || emf_loose)
366 
367  if (quality_ == TIGHT) {
368  // tight fhpd cut
369  bool tight_fhpd = true;
370  if (corrPt >= 25 && jetID.fHPD >= 0.95)
371  tight_fhpd = false; // this was supposed to use raw pT, see AN2009/087 :-(
372  if (ignoreCut(index_TIGHT_fHPD_) || tight_fhpd)
374 
375  // tight emf cut
376  bool tight_emf = true;
377  if (abs_eta >= 1 && corrPt >= 80 && emEnergyFraction >= 1)
378  tight_emf = false; // outside HB
379  if (abs_eta >= 2.6) { // outside HBHE
380  if (emEnergyFraction <= -0.3)
381  tight_emf = false;
382  if (abs_eta < 3.25) { // HE-HF transition region
383  if (corrPt >= 50 && emEnergyFraction <= -0.2)
384  tight_emf = false;
385  if (corrPt >= 80 && emEnergyFraction <= -0.1)
386  tight_emf = false;
387  if (corrPt >= 340 && emEnergyFraction >= 0.95)
388  tight_emf = false;
389  } else { // HF
390  if (emEnergyFraction >= 0.9)
391  tight_emf = false;
392  if (corrPt >= 50 && emEnergyFraction <= -0.2)
393  tight_emf = false;
394  if (corrPt >= 50 && emEnergyFraction >= 0.8)
395  tight_emf = false;
396  if (corrPt >= 130 && emEnergyFraction <= -0.1)
397  tight_emf = false;
398  if (corrPt >= 130 && emEnergyFraction >= 0.7)
399  tight_emf = false;
400 
401  } // end if HF
402  } // end if outside HBHE
403  if (ignoreCut(index_TIGHT_EMF_) || tight_emf)
405  } // end if tight
406  } // end if loose or tight
407 
408  setIgnored(ret);
409 
410  return (bool)ret;
411  }
412 
413  //
414  // cuts based on craft 08 analysis + forward jet ID based on 09 data
415  //
417  double emEnergyFraction,
418  double etaWidth,
419  double phiWidth,
420  unsigned int nHit,
421  reco::JetID const& jetID,
422  pat::strbitset& ret) {
423  ret.set(false);
424 
425  // cache some variables
426  double abs_eta = TMath::Abs(rawP4.eta());
427  double rawPt = rawP4.pt();
428  double emf = emEnergyFraction;
429  double fhf = jetID.fLong + jetID.fShort;
430  double lnpt = (rawPt > 0) ? TMath::Log(rawPt) : -10;
431  double lnE = (rawP4.energy() > 0) ? TMath::Log(rawP4.energy()) : -10;
432 
433  bool HB = abs_eta < 1.0;
434  bool EF = 2.6 <= abs_eta && abs_eta < 3.4 && 0.1 <= fhf && fhf < 0.9;
435  bool HBHE = abs_eta < 2.6 || (abs_eta < 3.4 && fhf < 0.1);
436  bool HF = 3.4 <= abs_eta || (2.6 <= abs_eta && 0.9 <= fhf);
437  bool HFa = HF && abs_eta < 3.8;
438  bool HFb = HF && !HFa;
439 
440  // HBHE cuts as in CRAFT08
441  // - but using raw pTs
442  // ========================
443 
444  if ((!HBHE) || ignoreCut(index_MINIMAL_EMF_) || emf > 0.01)
446 
447  // loose fhpd cut from AOD
448  if ((!HBHE) || ignoreCut(index_LOOSE_AOD_fHPD_) || jetID.approximatefHPD < 0.98)
450  // loose n90 hits cut from AOD
451  if ((!HBHE) || ignoreCut(index_LOOSE_AOD_N90Hits_) || jetID.hitsInN90 > 1)
453 
454  // loose fhpd cut
455  if ((!HBHE) || ignoreCut(index_LOOSE_fHPD_) || jetID.fHPD < 0.98)
457  // loose n90 hits cut
458  if ((!HBHE) || ignoreCut(index_LOOSE_N90Hits_) || jetID.n90Hits > 1)
460 
461  // tight fhpd cut
462  if ((!HBHE) || ignoreCut(index_TIGHT_fHPD_) || rawPt < 25 || jetID.fHPD < 0.95)
464 
465  // tight emf cut
466  if ((!HBHE) || ignoreCut(index_TIGHT_EMF_) || HB || rawPt < 55 || emf < 1)
468 
469  // EF - these cuts are only used in "tight", but there's no need for this test here.
470 
471  if ((!EF) || ignoreCut(index_EF_N90Hits_) || jetID.n90Hits > 1 + 1.5 * TMath::Max(0., lnpt - 1.5))
473 
474  if ((!EF) || ignoreCut(index_EF_EMF_) ||
475  emf > TMath::Max(-0.9, -0.1 - 0.05 * TMath::Power(TMath::Max(0., 5 - lnpt), 2.)))
477 
478  // both EF and HF
479 
480  if ((!(EF || HF)) || ignoreCut(index_TIGHT_fls_) ||
481  (EF && jetID.fLS < TMath::Min(0.8, 0.1 + 0.016 * TMath::Power(TMath::Max(0., 6 - lnpt), 2.5))) ||
482  (HFa && jetID.fLS < TMath::Min(0.6, 0.05 + 0.045 * TMath::Power(TMath::Max(0., 7.5 - lnE), 2.2))) ||
483  (HFb && jetID.fLS < TMath::Min(0.1, 0.05 + 0.07 * TMath::Power(TMath::Max(0., 7.8 - lnE), 2.))))
485 
486  if ((!(EF || HF)) || ignoreCut(index_widths_) ||
487  (1E-10 < etaWidth && etaWidth < 0.12 && 1E-10 < phiWidth && phiWidth < 0.12))
489 
490  // HF cuts
491 
492  if ((!HF) || ignoreCut(index_LOOSE_nHit_) || (HFa && nHit > 1 + 2.4 * (lnpt - 1.)) ||
493  (HFb && nHit > 1 + 3. * (lnpt - 1.)))
495 
496  if ((!HF) || ignoreCut(index_LOOSE_als_) ||
497  (emf < 0.6 + 0.05 * TMath::Power(TMath::Max(0., 9 - lnE), 1.5) &&
498  emf > -0.2 - 0.041 * TMath::Power(TMath::Max(0., 7.5 - lnE), 2.2)))
500 
501  if ((!HF) || ignoreCut(index_LOOSE_fls_) ||
502  (HFa && jetID.fLS < TMath::Min(0.9, 0.1 + 0.05 * TMath::Power(TMath::Max(0., 7.5 - lnE), 2.2))) ||
503  (HFb && jetID.fLS < TMath::Min(0.6, 0.1 + 0.065 * TMath::Power(TMath::Max(0., 7.5 - lnE), 2.2))))
505 
506  if ((!HF) || ignoreCut(index_LOOSE_foot_) || jetID.fHFOOT < 0.9)
508 
509  if ((!HF) || ignoreCut(index_TIGHT_nHit_) || (HFa && nHit > 1 + 2.7 * (lnpt - 0.8)) ||
510  (HFb && nHit > 1 + 3.5 * (lnpt - 0.8)))
512 
513  if ((!HF) || ignoreCut(index_TIGHT_als_) ||
514  (emf < 0.5 + 0.057 * TMath::Power(TMath::Max(0., 9 - lnE), 1.5) &&
515  emf > TMath::Max(-0.6, -0.1 - 0.026 * TMath::Power(TMath::Max(0., 8 - lnE), 2.2))))
517 
518  if ((!HF) || ignoreCut(index_TIGHT_foot_) || jetID.fLS < 0.5)
520 
521  setIgnored(ret);
522 
523  return (bool)ret;
524  }
525 
526 private: // member variables
529 
531 
535 
539 
542 
547 
555 };
556 
557 #endif
bool ignoreCut(std::string const &s) const
ignore the cut at index "s"
Definition: Selector.h:127
short hitsInN90
Definition: JetID.h:53
void initialize(Version_t version, Quality_t quality)
JetIDSelectionFunctor(Version_t version, Quality_t quality)
Jets made from CaloTowers.
Definition: CaloJet.h:27
float approximatefHPD
Definition: JetID.h:51
unsigned int count_hits(const std::vector< CaloTowerPtr > &towers)
float fHPD
Definition: JetID.h:41
virtual bool operator()(reco::Candidate::LorentzVector const &correctedP4, double emEnergyFraction, reco::JetID const &jetID)
accessor like previous, without the ret
ret
prodAgent to be discontinued
float fLS
Definition: JetID.h:60
pat::strbitset::index_type index_type
Definition: Selector.h:25
float fLong
Definition: JetID.h:59
void setIgnored(pat::strbitset &ret)
set ignored bits
Definition: Selector.h:181
pat::strbitset retInternal_
internal ret if users don&#39;t care about return bits
Definition: Selector.h:242
JetIDSelectionFunctor(edm::ParameterSet const &parameters)
Jet ID object.
Definition: JetID.h:16
bool operator()(reco::Candidate::LorentzVector const &correctedP4, double emEnergyFraction, reco::JetID const &jetID, pat::strbitset &ret)
bool craft08Cuts(reco::Candidate::LorentzVector const &correctedP4, double emEnergyFraction, reco::JetID const &jetID, pat::strbitset &ret)
string quality
pat::strbitset bits_
the bitset indexed by strings
Definition: Selector.h:241
void passCut(pat::strbitset &ret, std::string const &s)
Passing cuts.
Definition: Selector.h:142
JetIDSelectionFunctor(edm::ParameterSet const &parameters, edm::ConsumesCollector &iC)
float fShort
Definition: JetID.h:59
bool operator()(reco::CaloJet const &jet, reco::JetID const &jetID, pat::strbitset &ret)
virtual void push_back(std::string const &s)
This is the registration of an individual cut string.
Definition: Selector.h:42
Functor that operates on <T>
Definition: Selector.h:22
bool fwd09Cuts(reco::Candidate::LorentzVector const &rawP4, double emEnergyFraction, double etaWidth, double phiWidth, unsigned int nHit, reco::JetID const &jetID, pat::strbitset &ret)
bool operator()(const pat::Jet &jet, pat::strbitset &ret) override
This provides the interface for base classes to select objects.
Jet selector for pat::Jets and for CaloJets.
pat::strbitset getBitTemplate() const
Get an empty bitset with the proper names.
Definition: Selector.h:168
strbitset & set(bool val=true)
set method of all bits
Definition: strbitset.h:126
Analysis-level calorimeter jet class.
Definition: Jet.h:77
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:36
virtual bool operator()(reco::CaloJet const &jet, reco::JetID const &jetID)
accessor like previous, without the ret
Log< level::Warning, false > LogWarning
float fHFOOT
Definition: JetID.h:60
short n90Hits
Definition: JetID.h:43