HiggsAnalysis-KITHiggsToTauTau
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
TagAndProbePairProducer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "HiggsAnalysis/KITHiggsToTauTau/interface/HttTypes.h"
4 
5 #include <boost/algorithm/string.hpp>
6 #include <boost/algorithm/string/trim.hpp>
7 
8 class TagAndProbeMuonPairProducer: public ProducerBase<HttTypes> {
9 public:
10 
11  virtual std::string GetProducerId() const override {
12  return "TagAndProbeMuonPairProducer";
13  }
14 
15  enum class ValidMuonsInput : int
16  {
17  AUTO = 0,
18  UNCORRECTED = 1,
19  CORRECTED = 2,
20  };
21  static ValidMuonsInput ToValidMuonsInput(std::string const& validMuonsInput)
22  {
23  if (validMuonsInput == "uncorrected") return ValidMuonsInput::UNCORRECTED;
24  else if (validMuonsInput == "corrected") return ValidMuonsInput::CORRECTED;
25  else return ValidMuonsInput::AUTO;
26  }
27 
28  enum class MuonID : int
29  {
30  NONE = -1,
31  TIGHT = 0,
32  MEDIUM = 1,
33  LOOSE = 2,
34  VETO = 3,
35  FAKEABLE = 4,
36  EMBEDDING = 5
37  };
38  static MuonID ToMuonID(std::string const& muonID)
39  {
40  if (muonID == "tight") return MuonID::TIGHT;
41  else if (muonID == "medium") return MuonID::MEDIUM;
42  else if (muonID == "loose") return MuonID::LOOSE;
43  else if (muonID == "veto") return MuonID::VETO;
44  else if (muonID == "fakeable") return MuonID::FAKEABLE;
45  else if (muonID == "embedding") return MuonID::EMBEDDING;
46  else return MuonID::NONE;
47  }
48 
49  virtual void Init(setting_type const& settings, metadata_type& metadata) override;
50 
51  virtual void Produce(event_type const& event, product_type& product,
52  setting_type const& settings, metadata_type const& metadata) const override;
53 protected:
55 private:
56  ValidMuonsInput validMuonsInput;
57  float (setting_type::*GetMuonDeltaBetaCorrectionFactor)(void) const;
58  bool MuonIDshortTerm = false;
59  bool IsMediumMuon2016ShortTerm(KMuon* muon, event_type const& event, product_type& product) const;
60  bool IsMediumMuon2016(KMuon* muon, event_type const& event, product_type& product) const;
61 };
62 
63 class TagAndProbeElectronPairProducer: public ProducerBase<HttTypes> {
64 public:
65 
66  virtual std::string GetProducerId() const override {
67  return "TagAndProbeElectronPairProducer";
68  }
69 
70  enum class ValidElectronsInput : int
71  {
72  AUTO = 0,
73  UNCORRECTED = 1,
74  CORRECTED = 2,
75  };
76  static ValidElectronsInput ToValidElectronsInput(std::string const& validElectronsInput)
77  {
78  if (validElectronsInput == "uncorrected") return ValidElectronsInput::UNCORRECTED;
79  else if (validElectronsInput == "corrected") return ValidElectronsInput::CORRECTED;
80  else return ValidElectronsInput::AUTO;
81  }
82 
83  enum class ElectronID : int
84  {
85  INVALID = -2,
86  NONE = -1,
87  MVANONTRIG = 0,
88  MVATRIG = 1,
89  VBTF95_VETO = 2,
90  VBTF95_LOOSE = 3,
91  VBTF95_MEDIUM = 4,
92  VBTF95_TIGHT = 5,
93  FAKEABLE = 6,
94  USER = 7,
95  VETO = 8,
96  LOOSE = 9,
97  MEDIUM = 10,
98  TIGHT = 11,
100  };
101  static ElectronID ToElectronID(std::string const& electronID)
102  {
103  if (electronID == "mvanontrig") return ElectronID::MVANONTRIG;
104  else if (electronID == "mvatrig") return ElectronID::MVATRIG;
105  else if (electronID == "vbft95_veto") return ElectronID::VBTF95_VETO;
106  else if (electronID == "vbft95_loose") return ElectronID::VBTF95_LOOSE;
107  else if (electronID == "vbft95_loose_relaxedvtxcriteria") return ElectronID::VBTF95_LOOSE_RELAXEDVTXCRITERIA;
108  else if (electronID == "vbft95_medium") return ElectronID::VBTF95_MEDIUM;
109  else if (electronID == "vbft95_tight") return ElectronID::VBTF95_TIGHT;
110  else if (electronID == "fakeable") return ElectronID::FAKEABLE;
111  else if (electronID == "user") return ElectronID::USER;
112  else if (electronID == "none") return ElectronID::NONE;
113  else if (electronID == "veto") return ElectronID::VETO;
114  else if (electronID == "loose") return ElectronID::LOOSE;
115  else if (electronID == "medium") return ElectronID::MEDIUM;
116  else if (electronID == "tight") return ElectronID::TIGHT;
117  else
118  LOG(FATAL) << "Could not find ElectronID " << electronID << "! If you want the ValidElectronsProducer to use no special ID, use \"none\" as argument."<< std::endl;
119  return ElectronID::INVALID;
120  }
121 
122  virtual void Init(setting_type const& settings, metadata_type& metadata) override;
123 
124  virtual void Produce(event_type const& event, product_type& product,
125  setting_type const& settings, metadata_type const& metadata) const override;
126 protected:
128 private:
129  ValidElectronsInput validElectronsInput;
130  std::string electronIDName;
131  double electronMvaIDCutEB1;
132  double electronMvaIDCutEB2;
133  double electronMvaIDCutEE;
134  bool IsMVABased(KElectron* electron, event_type const& event, const std::string &idName) const;
135 };
136 /*
137 template<class TLepton>
138 class TagAndProbeGenLeptonProducer: public ProducerBase<HttTypes> {
139 public:
140 
141  typedef typename HttTypes::event_type event_type;
142  typedef typename HttTypes::product_type product_type;
143  typedef typename HttTypes::setting_type setting_type;
144 
145  TagAndProbeGenLeptonProducer(std::vector<TLepton>* event_type::*leptons,
146  std::vector<std::shared_ptr<TLepton>> product_type::*leptons_corrected,
147  std::vector<TLepton*> product_type::*validleptons,
148  std::vector<TLepton*> product_type::*genleptons) :
149  ProducerBase<HttTypes>(),
150  m_leptons(leptons),
151  m_leptons_corrected(leptons_corrected),
152  m_validleptons(validleptons),
153  m_genleptons(genleptons)
154  {
155  }
156 
157  virtual std::string GetProducerId() const override {
158  return "TagAndProbeGenLeptonProducer";
159  }
160 
161  enum class ValidLeptonsInput : int
162  {
163  AUTO = 0,
164  UNCORRECTED = 1,
165  CORRECTED = 2,
166  };
167 
168  ValidLeptonsInput ToValidLeptzonsInput(std::string const& validLeptonsInput)
169  {
170  if (validLeptonsInput == "uncorrected") return ValidLeptonsInput::UNCORRECTED;
171  else if (validLeptonsInput == "corrected") return ValidLeptonsInput::CORRECTED;
172  else return ValidLeptonsInput::AUTO;
173  }
174 
175  virtual void Init(setting_type const& settings, metadata_type& metadata) override
176  {
177  ProducerBase<HttTypes>::Init(settings, metadata);
178  }
179 
180  virtual void Produce(event_type const& event, product_type& product,
181  setting_type const& settings, metadata_type const& metadata) const override
182  {
183  assert(*m_leptons);
184  bool IsData = settings.GetInputIsData();
185  if(IsData) return;
186  // select input source
187  std::vector<TLepton*> leptons;
188  if ((validLeptonsInput == ValidLeptonsInput::AUTO && (m_leptons_corrected->size() > 0)) || (validLeptonsInput == ValidLeptonsInput::CORRECTED))
189  {
190  leptons.resize(m_leptons_corrected->size());
191  size_t leptonIndex = 0;
192  for (typename std::vector<std::shared_ptr<TLepton> >::iterator lepton = m_leptons_corrected->begin();
193  lepton != m_leptons_corrected->end(); ++lepton)
194  {
195  leptons[leptonIndex] = lepton->get();
196  ++leptonIndex;
197  }
198  }
199  else
200  {
201  leptons.resize((*m_leptons)->size());
202  size_t leptonIndex = 0;
203  for (typename std::vector<TLepton>::iterator lepton = (*m_leptons)->begin(); lepton != (*m_leptons)->end(); ++lepton)
204  {
205  leptons[leptonIndex] = &(*lepton);
206  ++leptonIndex;
207  }
208  }
209  //loop over leptons
210  for (typename std::vector<TLepton*>::iterator lepton = leptons.begin(); lepton != leptons.end(); ++lepton)
211  {
212  m_validleptons->push_back(*lepton); //needed for ValidLEptonsFilter
213 
214  //filter
215  if (
216  (*lepton)->p4.Pt() > 10.0 &&
217  std::abs((*lepton)->p4.Eta()) < 2.5
218  ){
219  m_genleptons->push_back(*lepton);
220  }
221  }
222  }
223  ValidLeptonsInput validLeptonsInput;
224 private:
225  std::vector<TLepton>* event_type::*m_leptons;
226  std::vector<std::shared_ptr<TLepton>> product_type::*m_leptons_corrected;
227  std::vector<TLepton*> product_type::*m_validleptons;
228  std::vector<TLepton*> product_type::*m_genleptons;
229 };
230 
231 class TagAndProbeGenElectronProducer: public TagAndProbeGenLeptonProducer<KElectron> {
232 public:
233  typedef typename HttTypes::event_type event_type;
234  typedef typename HttTypes::product_type product_type;
235  typedef typename HttTypes::setting_type setting_type;
236 
237  enum class ValidLeptonsInput : int
238  {
239  AUTO = 0,
240  UNCORRECTED = 1,
241  CORRECTED = 2,
242  };
243 
244  virtual std::string GetProducerId() const override;
245  TagAndProbeGenElectronProducer();
246  virtual void Init(setting_type const& settings, metadata_type& metadata) override;
247 };
248 
249 class TagAndProbeGenMuonProducer: public TagAndProbeGenLeptonProducer<KMuon> {
250 public:
251  typedef typename HttTypes::event_type event_type;
252  typedef typename HttTypes::product_type product_type;
253  typedef typename HttTypes::setting_type setting_type;
254 
255  enum class ValidLeptonsInput : int
256  {
257  AUTO = 0,
258  UNCORRECTED = 1,
259  CORRECTED = 2,
260  };
261 
262  virtual std::string GetProducerId() const override;
263  TagAndProbeGenMuonProducer();
264  virtual void Init(setting_type const& settings, metadata_type& metadata) override;
265 };
266 
267 class TagAndProbeGenTauProducer: public TagAndProbeGenLeptonProducer<KTau> {
268 public:
269  typedef typename HttTypes::event_type event_type;
270  typedef typename HttTypes::product_type product_type;
271  typedef typename HttTypes::setting_type setting_type;
272 
273  enum class ValidLeptonsInput : int
274  {
275  AUTO = 0,
276  UNCORRECTED = 1,
277  CORRECTED = 2,
278  };
279 
280  virtual std::string GetProducerId() const override;
281  TagAndProbeGenTauProducer();
282  virtual void Init(setting_type const& settings, metadata_type& metadata) override;
283 };
284 */
285 class TagAndProbeGenElectronProducer: public ProducerBase<HttTypes> {
286 public:
287 
288  virtual std::string GetProducerId() const override {
289  return "TagAndProbeGenElectronProducer";
290  }
291 
292  enum class ValidElectronsInput : int
293  {
294  AUTO = 0,
295  UNCORRECTED = 1,
296  CORRECTED = 2,
297  };
298 
299  ValidElectronsInput ToValidElectronsInput(std::string const& validElectronsInput)
300  {
301  if (validElectronsInput == "uncorrected") return ValidElectronsInput::UNCORRECTED;
302  else if (validElectronsInput == "corrected") return ValidElectronsInput::CORRECTED;
303  else return ValidElectronsInput::AUTO;
304  }
305 
306  virtual void Init(setting_type const& settings, metadata_type& metadata) override
307  {
308  ProducerBase<HttTypes>::Init(settings, metadata);
309  validElectronsInput = ToValidElectronsInput(boost::algorithm::to_lower_copy(boost::algorithm::trim_copy(settings.GetValidElectronsInput())));
310  }
311 
312  virtual void Produce(event_type const& event, product_type& product,
313  setting_type const& settings, metadata_type const& metadata) const override
314  {
315  assert(event.m_electrons);
316  bool IsData = settings.GetInputIsData();
317  if(IsData) return;
318  // select input source
319  std::vector<KElectron*> electrons;
320  if ((validElectronsInput == ValidElectronsInput::AUTO && (product.m_correctedElectrons.size() > 0)) || (validElectronsInput == ValidElectronsInput::CORRECTED))
321  {
322  electrons.resize(product.m_correctedElectrons.size());
323  size_t electronIndex = 0;
324  for (std::vector<std::shared_ptr<KElectron> >::iterator electron = product.m_correctedElectrons.begin();
325  electron != product.m_correctedElectrons.end(); ++electron)
326  {
327  electrons[electronIndex] = electron->get();
328  ++electronIndex;
329  }
330  }
331  else
332  {
333  electrons.resize(event.m_electrons->size());
334  size_t electronIndex = 0;
335  for (KElectrons::iterator electron = event.m_electrons->begin(); electron != event.m_electrons->end(); ++electron)
336  {
337  electrons[electronIndex] = &(*electron);
338  ++electronIndex;
339  }
340  }
341  //loop over electrons
342  for (typename std::vector<KElectron*>::iterator electron = electrons.begin(); electron != electrons.end(); ++electron)
343  {
344  product.m_validElectrons.push_back(*electron); //needed for ValidLEptonsFilter
345 
346  //filter
347  if (
348  (*electron)->p4.Pt() > 10.0 &&
349  std::abs((*electron)->p4.Eta()) < 2.5
350  ){
351  product.m_TagAndProbeGenElectrons.push_back(*electron);
352  }
353  }
354  }
355 
356 private:
357  ValidElectronsInput validElectronsInput;
358 };
359 
360 class TagAndProbeGenMuonProducer: public ProducerBase<HttTypes> {
361 public:
362 
363  virtual std::string GetProducerId() const override {
364  return "TagAndProbeGenMuonProducer";
365  }
366 
367  enum class ValidMuonsInput : int
368  {
369  AUTO = 0,
370  UNCORRECTED = 1,
371  CORRECTED = 2,
372  };
373 
374  ValidMuonsInput ToValidMuonsInput(std::string const& validMuonsInput)
375  {
376  if (validMuonsInput == "uncorrected") return ValidMuonsInput::UNCORRECTED;
377  else if (validMuonsInput == "corrected") return ValidMuonsInput::CORRECTED;
378  else return ValidMuonsInput::AUTO;
379  }
380 
381  virtual void Init(setting_type const& settings, metadata_type& metadata) override
382  {
383  ProducerBase<HttTypes>::Init(settings, metadata);
384  validMuonsInput = ToValidMuonsInput(boost::algorithm::to_lower_copy(boost::algorithm::trim_copy(settings.GetValidMuonsInput())));
385  }
386 
387  virtual void Produce(event_type const& event, product_type& product,
388  setting_type const& settings, metadata_type const& metadata) const override
389  {
390  assert(event.m_muons);
391  bool IsData = settings.GetInputIsData();
392  if(IsData) return;
393  // select input source
394  std::vector<KMuon*> muons;
395  if ((validMuonsInput == ValidMuonsInput::AUTO && (product.m_correctedMuons.size() > 0)) || (validMuonsInput == ValidMuonsInput::CORRECTED))
396  {
397  muons.resize(product.m_correctedMuons.size());
398  size_t muonIndex = 0;
399  for (std::vector<std::shared_ptr<KMuon> >::iterator muon = product.m_correctedMuons.begin();
400  muon != product.m_correctedMuons.end(); ++muon)
401  {
402  muons[muonIndex] = muon->get();
403  ++muonIndex;
404  }
405  }
406  else
407  {
408  muons.resize(event.m_muons->size());
409  size_t muonIndex = 0;
410  for (KMuons::iterator muon = event.m_muons->begin(); muon != event.m_muons->end(); ++muon)
411  {
412  muons[muonIndex] = &(*muon);
413  ++muonIndex;
414  }
415  }
416  //loop over muons
417  for (typename std::vector<KMuon*>::iterator muon = muons.begin(); muon != muons.end(); ++muon)
418  {
419  product.m_validMuons.push_back(*muon); //needed for ValidLEptonsFilter
420 
421  //filter
422  if (
423  (*muon)->p4.Pt() > 10.0 &&
424  std::abs((*muon)->p4.Eta()) < 2.5
425  ){
426  product.m_TagAndProbeGenMuons.push_back(*muon);
427  }
428  }
429  }
430 
431 private:
432  ValidMuonsInput validMuonsInput;
433 };
434 
435 class TagAndProbeGenTauProducer: public ProducerBase<HttTypes> {
436 public:
437 
438  virtual std::string GetProducerId() const override {
439  return "TagAndProbeGenTauProducer";
440  }
441 
442  enum class ValidTausInput : int
443  {
444  AUTO = 0,
445  UNCORRECTED = 1,
446  CORRECTED = 2,
447  };
448 
449  ValidTausInput ToValidTausInput(std::string const& validTausInput)
450  {
451  if (validTausInput == "uncorrected") return ValidTausInput::UNCORRECTED;
452  else if (validTausInput == "corrected") return ValidTausInput::CORRECTED;
453  else return ValidTausInput::AUTO;
454  }
455 
456  virtual void Init(setting_type const& settings, metadata_type& metadata) override
457  {
458  ProducerBase<HttTypes>::Init(settings, metadata);
459  validTausInput = ToValidTausInput(boost::algorithm::to_lower_copy(boost::algorithm::trim_copy(settings.GetValidTausInput())));
460  }
461 
462  virtual void Produce(event_type const& event, product_type& product,
463  setting_type const& settings, metadata_type const& metadata) const override
464  {
465  assert(event.m_taus);
466  bool IsData = settings.GetInputIsData();
467  if(IsData) return;
468  // select input source
469  std::vector<KTau*> taus;
470  if ((validTausInput == ValidTausInput::AUTO && (product.m_correctedTaus.size() > 0)) || (validTausInput == ValidTausInput::CORRECTED))
471  {
472  taus.resize(product.m_correctedTaus.size());
473  size_t tauIndex = 0;
474  for (std::vector<std::shared_ptr<KTau> >::iterator tau = product.m_correctedTaus.begin();
475  tau != product.m_correctedTaus.end(); ++tau)
476  {
477  taus[tauIndex] = tau->get();
478  ++tauIndex;
479  }
480  }
481  else
482  {
483  taus.resize(event.m_taus->size());
484  size_t tauIndex = 0;
485  for (KTaus::iterator tau = event.m_taus->begin(); tau != event.m_taus->end(); ++tau)
486  {
487  taus[tauIndex] = &(*tau);
488  ++tauIndex;
489  }
490  }
491  //loop over taus
492  for (typename std::vector<KTau*>::iterator tau = taus.begin(); tau != taus.end(); ++tau)
493  {
494  product.m_validTaus.push_back(*tau); //needed for ValidLEptonsFilter
495 
496  //filter
497  if (
498  (*tau)->p4.Pt() > 10.0 &&
499  std::abs((*tau)->p4.Eta()) < 2.5
500  ){
501  product.m_TagAndProbeGenTaus.push_back(*tau);
502  }
503  }
504  }
505 
506 private:
507  ValidTausInput validTausInput;
508 };
Definition: TagAndProbePairProducer.h:435
Definition: TagAndProbePairProducer.h:285
virtual void Produce(event_type const &event, product_type &product, setting_type const &settings, metadata_type const &metadata) const override
Definition: TagAndProbePairProducer.h:312
ValidMuonsInput
Definition: TagAndProbePairProducer.h:15
Definition: TagAndProbePairProducer.h:63
virtual std::string GetProducerId() const override
Definition: TagAndProbePairProducer.h:363
static MuonID ToMuonID(std::string const &muonID)
Definition: TagAndProbePairProducer.h:38
ValidElectronsInput ToValidElectronsInput(std::string const &validElectronsInput)
Definition: TagAndProbePairProducer.h:299
virtual std::string GetProducerId() const override
Definition: TagAndProbePairProducer.h:438
virtual void Init(setting_type const &settings, metadata_type &metadata) override
Definition: TagAndProbePairProducer.h:306
virtual void Produce(event_type const &event, product_type &product, setting_type const &settings, metadata_type const &metadata) const override
Definition: TagAndProbePairProducer.h:462
virtual std::string GetProducerId() const override
Definition: TagAndProbePairProducer.h:11
static ValidMuonsInput ToValidMuonsInput(std::string const &validMuonsInput)
Definition: TagAndProbePairProducer.h:21
ValidTausInput
Definition: TagAndProbePairProducer.h:442
Definition: TagAndProbePairProducer.h:360
ValidElectronsInput
Definition: TagAndProbePairProducer.h:70
virtual void Produce(event_type const &event, product_type &product, setting_type const &settings, metadata_type const &metadata) const override
Definition: TagAndProbePairProducer.cc:502
static ElectronID ToElectronID(std::string const &electronID)
Definition: TagAndProbePairProducer.h:101
virtual void Init(setting_type const &settings, metadata_type &metadata) override
Definition: TagAndProbePairProducer.cc:492
Definition: TagAndProbePairProducer.h:8
virtual void Init(setting_type const &settings, metadata_type &metadata) override
Definition: TagAndProbePairProducer.h:381
MuonID
Definition: TagAndProbePairProducer.h:28
virtual std::string GetProducerId() const override
Definition: TagAndProbePairProducer.h:288
virtual void Init(setting_type const &settings, metadata_type &metadata) override
Definition: TagAndProbePairProducer.cc:11
virtual void Init(setting_type const &settings, metadata_type &metadata) override
Definition: TagAndProbePairProducer.h:456
static ValidElectronsInput ToValidElectronsInput(std::string const &validElectronsInput)
Definition: TagAndProbePairProducer.h:76
ValidMuonsInput
Definition: TagAndProbePairProducer.h:367
MuonID muonID
Definition: TagAndProbePairProducer.h:54
ValidTausInput ToValidTausInput(std::string const &validTausInput)
Definition: TagAndProbePairProducer.h:449
virtual void Produce(event_type const &event, product_type &product, setting_type const &settings, metadata_type const &metadata) const override
Definition: TagAndProbePairProducer.cc:390
virtual std::string GetProducerId() const override
Definition: TagAndProbePairProducer.h:66
ValidMuonsInput ToValidMuonsInput(std::string const &validMuonsInput)
Definition: TagAndProbePairProducer.h:374
virtual void Produce(event_type const &event, product_type &product, setting_type const &settings, metadata_type const &metadata) const override
Definition: TagAndProbePairProducer.h:387
ValidElectronsInput
Definition: TagAndProbePairProducer.h:292
ElectronID
Definition: TagAndProbePairProducer.h:83
ElectronID electronID
Definition: TagAndProbePairProducer.h:127