HiggsAnalysis-KITHiggsToTauTau
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
MetSelectors.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "Kappa/DataFormats/interface/Kappa.h"
5 
6 #include "Artus/Core/interface/ProducerBase.h"
7 #include "Artus/Consumer/interface/LambdaNtupleConsumer.h"
8 #include "Artus/Utility/interface/SafeMap.h"
9 #include "boost/functional/hash.hpp"
10 
11 #include "HiggsAnalysis/KITHiggsToTauTau/interface/HttTypes.h"
12 
18 template<class TMet>
19 class MetSelectorBase: public ProducerBase<HttTypes>
20 {
21 public:
22 
23  MetSelectorBase(TMet* event_type::*met, std::vector<TMet>* event_type::*mets) :
24  ProducerBase<HttTypes>(),
25  m_metMember(met),
26  m_metsMember(mets)
27  {
28  }
29 
30  virtual void Init(setting_type const& settings, metadata_type& metadata) override
31  {
32  ProducerBase<HttTypes>::Init(settings, metadata);
33 
34  // add possible quantities for the lambda ntuples consumers
35  LambdaNtupleConsumer<HttTypes>::AddFloatQuantity(metadata, "metSumEt", [](event_type const& event, product_type const& product)
36  {
37  return product.m_met.sumEt;
38  });
39  LambdaNtupleConsumer<HttTypes>::AddFloatQuantity(metadata, "metPt", [](event_type const& event, product_type const& product)
40  {
41  return product.m_met.p4.Pt();
42  });
43  LambdaNtupleConsumer<HttTypes>::AddFloatQuantity(metadata, "metPhi", [](event_type const& event, product_type const& product)
44  {
45  return product.m_met.p4.Phi();
46  });
47  LambdaNtupleConsumer<HttTypes>::AddFloatQuantity(metadata, "metCov00", [](event_type const& event, product_type const& product)
48  {
49  return product.m_met.significance.At(0, 0);
50  });
51  LambdaNtupleConsumer<HttTypes>::AddFloatQuantity(metadata, "metCov01", [](event_type const& event, product_type const& product)
52  {
53  return product.m_met.significance.At(0, 1);
54  });
55  LambdaNtupleConsumer<HttTypes>::AddFloatQuantity(metadata, "metCov10", [](event_type const& event, product_type const& product)
56  {
57  return product.m_met.significance.At(1, 0);
58  });
59  LambdaNtupleConsumer<HttTypes>::AddFloatQuantity(metadata, "metCov11", [](event_type const& event, product_type const& product)
60  {
61  return product.m_met.significance.At(1, 1);
62  });
63 
64  LambdaNtupleConsumer<HttTypes>::AddFloatQuantity(metadata, "pfMetSumEt", [](event_type const& event, product_type const& product)
65  {
66  return product.m_pfmet.sumEt;
67  });
68  LambdaNtupleConsumer<HttTypes>::AddFloatQuantity(metadata, "pfMetPt", [](event_type const& event, product_type const& product)
69  {
70  return product.m_pfmet.p4.Pt();
71  });
72  LambdaNtupleConsumer<HttTypes>::AddFloatQuantity(metadata, "pfMetPhi", [](event_type const& event, product_type const& product)
73  {
74  return product.m_pfmet.p4.Phi();
75  });
76  LambdaNtupleConsumer<HttTypes>::AddFloatQuantity(metadata, "pfMetCov00", [](event_type const& event, product_type const& product)
77  {
78  return product.m_pfmet.significance.At(0, 0);
79  });
80  LambdaNtupleConsumer<HttTypes>::AddFloatQuantity(metadata, "pfMetCov01", [](event_type const& event, product_type const& product)
81  {
82  return product.m_pfmet.significance.At(0, 1);
83  });
84  LambdaNtupleConsumer<HttTypes>::AddFloatQuantity(metadata, "pfMetCov10", [](event_type const& event, product_type const& product)
85  {
86  return product.m_pfmet.significance.At(1, 0);
87  });
88  LambdaNtupleConsumer<HttTypes>::AddFloatQuantity(metadata, "pfMetCov11", [](event_type const& event, product_type const& product)
89  {
90  return product.m_pfmet.significance.At(1, 1);
91  });
92 
93  LambdaNtupleConsumer<HttTypes>::AddFloatQuantity(metadata, "mvaMetSumEt", [](event_type const& event, product_type const& product)
94  {
95  return product.m_mvamet.sumEt;
96  });
97  LambdaNtupleConsumer<HttTypes>::AddFloatQuantity(metadata, "mvaMetPt", [](event_type const& event, product_type const& product)
98  {
99  return product.m_mvamet.p4.Pt();
100  });
101  LambdaNtupleConsumer<HttTypes>::AddFloatQuantity(metadata, "mvaMetPhi", [](event_type const& event, product_type const& product)
102  {
103  return product.m_mvamet.p4.Phi();
104  });
105  LambdaNtupleConsumer<HttTypes>::AddFloatQuantity(metadata, "mvaMetCov00", [](event_type const& event, product_type const& product)
106  {
107  return product.m_mvamet.significance.At(0, 0);
108  });
109  LambdaNtupleConsumer<HttTypes>::AddFloatQuantity(metadata, "mvaMetCov01", [](event_type const& event, product_type const& product)
110  {
111  return product.m_mvamet.significance.At(0, 1);
112  });
113  LambdaNtupleConsumer<HttTypes>::AddFloatQuantity(metadata, "mvaMetCov10", [](event_type const& event, product_type const& product)
114  {
115  return product.m_mvamet.significance.At(1, 0);
116  });
117  LambdaNtupleConsumer<HttTypes>::AddFloatQuantity(metadata, "mvaMetCov11", [](event_type const& event, product_type const& product)
118  {
119  return product.m_mvamet.significance.At(1, 1);
120  });
121  }
122 
123  virtual void Produce(event_type const& event, product_type & product,
124  setting_type const& settings, metadata_type const& metadata) const override
125  {
126  if ((m_metsMember != nullptr) && ((event.*m_metsMember) != nullptr))
127  {
128  assert(product.m_ptOrderedLeptons.size() > 0);
129 
130  // create hashes from lepton selection. Any number of leptons is possible
131  std::vector<KLepton*> leptons = product.m_ptOrderedLeptons;
132  std::vector<size_t> hashes;
133  if (leptons.size() == 2 && (leptons[0]->p4.Pt() < leptons[1]->p4.Pt()))
134  {
135  do
136  {
137  size_t hash = 0;
138  for (std::vector<KLepton*>::iterator lepton = leptons.begin(); lepton != leptons.end(); ++lepton)
139  {
140  boost::hash_combine(hash,(*lepton)->internalId);
141  }
142  hashes.push_back(hash);
143  }
144  while (std::prev_permutation(leptons.begin(), leptons.end(), [](KLepton const* lepton1, KLepton const* lepton2) -> bool { return lepton1->p4.Pt() < lepton2->p4.Pt(); }));
145  }
146  else
147  {
148  // in case both pt's are equal the results of before does not include both permutations.
149  // Comupte the hashes for both permutations.
150  size_t hash = 0;
151  for (std::vector<KLepton*>::iterator lepton = leptons.begin(); lepton != leptons.end(); ++lepton)
152  {
153  boost::hash_combine(hash,(*lepton)->internalId);
154  }
155  hashes.push_back(hash);
156  // permutate both leptons and calculate the second one
157  std::swap(leptons[0],leptons[1]);
158  hash = 0;
159  for (std::vector<KLepton*>::iterator lepton = leptons.begin(); lepton != leptons.end(); ++lepton)
160  {
161  boost::hash_combine(hash,(*lepton)->internalId);
162  }
163  hashes.push_back(hash);
164  }
165 
166 
167  bool foundMvaMet = false;
168  for (typename std::vector<TMet>::iterator met = (event.*m_metsMember)->begin(); met != (event.*m_metsMember)->end(); ++met)
169  {
170  if (std::find(hashes.begin(), hashes.end(), met->leptonSelectionHash)!= hashes.end())
171  {
172  product.m_mvametUncorr = &(*met);
173  foundMvaMet = true;
174  break;
175  }
176  }
177 
178  // Make sure we found a corresponding MVAMET, this is to ensure we do not fall back to the PFMet
179  assert(foundMvaMet && (product.m_mvametUncorr != nullptr));
180  // If this assertion fails, one might have to consider running the MetSelector before this producer
181  // in order to have the (PF) MET as a fallback solution
182 
183  // Copy the MET object, for possible future corrections
184  product.m_mvamet = *(product.m_mvametUncorr);
185  if (settings.GetChooseMvaMet())
186  {
187  product.m_metUncorr = product.m_mvametUncorr;
188  product.m_met = product.m_mvamet;
189  }
190  }
191  else if ((m_metMember != nullptr) && ((event.*m_metMember) != nullptr))
192  {
193  product.m_pfmetUncorr = (event.*m_metMember);
194 
195  // Copy the MET object, for possible future corrections
196  product.m_pfmet = *(product.m_pfmetUncorr);
197  if (!settings.GetChooseMvaMet())
198  {
199  product.m_metUncorr = product.m_pfmetUncorr;
200  product.m_met = product.m_pfmet;
201  }
202  }
203  else
204  {
205  assert(((m_metsMember != nullptr) && ((event.*m_metsMember) != nullptr)) ||
206  ((m_metMember != nullptr) && ((event.*m_metMember) != nullptr)));
207  }
208  }
209 
210 
211 protected:
212  TMet* event_type::*m_metMember;
213  std::vector<TMet>* event_type::*m_metsMember;
214 };
215 
216 
217 
221 class MetSelector: public MetSelectorBase<KMET>
222 {
223 public:
224  MetSelector();
225  virtual std::string GetProducerId() const override;
226 };
227 
228 
233 {
234 public:
235  virtual void Produce(event_type const& event, product_type & product,
236  setting_type const& settings, metadata_type const& metadata) const override;
238  virtual std::string GetProducerId() const override;
239 };
240 
245 {
246 public:
248  virtual std::string GetProducerId() const override;
249 };
250 
251 
252 
257 {
258 public:
260  virtual std::string GetProducerId() const override;
261 };
262 
263 
264 
269 {
270 public:
272  virtual std::string GetProducerId() const override;
273 };
274 
275 
276 
281 {
282 public:
284  virtual std::string GetProducerId() const override;
285 };
286 
290 class MvaMetSelector: public MetSelectorBase<KMET>
291 {
292 public:
293  MvaMetSelector();
294  virtual std::string GetProducerId() const override;
295 };
MvaMetEMSelector()
Definition: MetSelectors.cc:68
virtual std::string GetProducerId() const override
Definition: MetSelectors.cc:11
virtual void Produce(event_type const &event, product_type &product, setting_type const &settings, metadata_type const &metadata) const override
Definition: MetSelectors.cc:22
Producer for Puppi MET.
Definition: MetSelectors.h:232
virtual std::string GetProducerId() const override
Definition: MetSelectors.cc:62
Producer for MVAMET (TT channel)
Definition: MetSelectors.h:244
virtual std::string GetProducerId() const override
Definition: MetSelectors.cc:51
virtual void Init(setting_type const &settings, metadata_type &metadata) override
Definition: MetSelectors.h:30
virtual std::string GetProducerId() const override
Definition: MetSelectors.cc:40
Producer for (PF) MET.
Definition: MetSelectors.h:221
virtual void Produce(event_type const &event, product_type &product, setting_type const &settings, metadata_type const &metadata) const override
Definition: MetSelectors.h:123
virtual std::string GetProducerId() const override
Definition: MetSelectors.cc:30
MetSelector()
Definition: MetSelectors.cc:5
MvaMetTTSelector()
Definition: MetSelectors.cc:35
Producer for MVAMET (EM channel)
Definition: MetSelectors.h:290
Producer for the MET.
Definition: MetSelectors.h:19
virtual std::string GetProducerId() const override
Definition: MetSelectors.cc:73
MvaMetETSelector()
Definition: MetSelectors.cc:57
Producer for MVAMET (ET channel)
Definition: MetSelectors.h:268
all data types which are used for Htt analyses
Definition: HttTypes.h:27
virtual std::string GetProducerId() const override
Definition: MetSelectors.cc:83
Producer for MVAMET (EM channel)
Definition: MetSelectors.h:280
std::vector< TMet > *event_type::* m_metsMember
Definition: MetSelectors.h:213
TMet *event_type::* m_metMember
Definition: MetSelectors.h:212
MetSelectorPuppi()
Definition: MetSelectors.cc:17
MvaMetSelector()
Definition: MetSelectors.cc:78
Producer for MVAMET (MT channel)
Definition: MetSelectors.h:256
MetSelectorBase(TMet *event_type::*met, std::vector< TMet > *event_type::*mets)
Definition: MetSelectors.h:23
MvaMetMTSelector()
Definition: MetSelectors.cc:46