HiggsAnalysis-KITHiggsToTauTau
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
TriggerTagAndProbeConsumers.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <TTree.h>
4 
5 #include "Artus/Core/interface/ConsumerBase.h"
6 #include "Artus/Utility/interface/RootFileHelper.h"
7 #include "Artus/Utility/interface/SafeMap.h"
8 
9 #include "HiggsAnalysis/KITHiggsToTauTau/interface/HttTypes.h"
10 #include "Artus/KappaAnalysis/interface/Consumers/KappaLambdaNtupleConsumer.h"
11 
12 template<class TTag, class TProbe>
13 class TriggerTagAndProbeConsumerBase: public ConsumerBase<HttTypes>
14 {
15 
16 public:
17 
19  std::string treeName,
20  std::vector<std::pair<TTag*, TProbe*> > product_type::*triggerTagProbeObjectPairsMember,
21  std::vector<std::pair<bool, bool> > product_type::*triggerTagProbeObjectMatchedPairsMember
22  ) :
23  ConsumerBase<HttTypes>(),
24  m_treeName(treeName),
25  m_triggerTagProbeObjectPairsMember(triggerTagProbeObjectPairsMember),
26  m_triggerTagProbeObjectMatchedPairsMember(triggerTagProbeObjectMatchedPairsMember)
27  {
28  }
29 
30  virtual void Init(setting_type const& settings, metadata_type& metadata) override
31  {
32  ConsumerBase<HttTypes>::Init(settings, metadata);
33 
34  RootFileHelper::SafeCd(settings.GetRootOutFile(),
35  settings.GetRootFileFolder());
36  m_tree = new TTree(m_treeName.c_str(), m_treeName.c_str());
37 
38  m_tree->Branch("tag", &m_currentTagObject);
39  m_tree->Branch("tagMatched", &m_currentTagObjectMatched, "tagMatched/O");
40  m_tree->Branch("probe", &m_currentProbeObject);
41  m_tree->Branch("probeMatched", &m_currentProbeObjectMatched, "probeMatched/O");
42  m_tree->Branch("tagProbeSystem", &m_tagProbeSystem);
43 
44 
45  LambdaNtupleConsumer<HttTypes>::AddVFloatQuantity(metadata, "tagPt", [this](event_type const& event, product_type const& product)
46  {
47  std::vector<float> tagPt;
48  for (typename std::vector<std::pair<TTag*, TProbe*> >::const_iterator tagProbePair = (product.*(this->m_triggerTagProbeObjectPairsMember)).begin();
49  tagProbePair != (product.*(this->m_triggerTagProbeObjectPairsMember)).end(); ++tagProbePair)
50  {
51  tagPt.push_back(tagProbePair->first->p4.Pt());
52  }
53  return tagPt;
54  });
55  LambdaNtupleConsumer<HttTypes>::AddVFloatQuantity(metadata, "probePt", [this](event_type const& event, product_type const& product)
56  {
57  std::vector<float> probePt;
58  for (typename std::vector<std::pair<TTag*, TProbe*> >::const_iterator tagProbePair = (product.*(this->m_triggerTagProbeObjectPairsMember)).begin();
59  tagProbePair != (product.*(this->m_triggerTagProbeObjectPairsMember)).end(); ++tagProbePair)
60  {
61  probePt.push_back(tagProbePair->second->p4.Pt());
62  }
63  return probePt;
64  });
65  LambdaNtupleConsumer<HttTypes>::AddVFloatQuantity(metadata, "probeEta", [this](event_type const& event, product_type const& product)
66  {
67  std::vector<float> probeEta;
68  for (typename std::vector<std::pair<TTag*, TProbe*> >::const_iterator tagProbePair = (product.*(this->m_triggerTagProbeObjectPairsMember)).begin();
69  tagProbePair != (product.*(this->m_triggerTagProbeObjectPairsMember)).end(); ++tagProbePair)
70  {
71  probeEta.push_back(tagProbePair->second->p4.Eta());
72  }
73  return probeEta;
74  });
75  LambdaNtupleConsumer<HttTypes>::AddVFloatQuantity(metadata, "tagProbeDeltaR", [this](event_type const& event, product_type const& product)
76  {
77  std::vector<float> tagProbeDeltaR;
78  for (typename std::vector<std::pair<TTag*, TProbe*> >::const_iterator tagProbePair = (product.*(this->m_triggerTagProbeObjectPairsMember)).begin();
79  tagProbePair != (product.*(this->m_triggerTagProbeObjectPairsMember)).end(); ++tagProbePair)
80  {
81  tagProbeDeltaR.push_back(ROOT::Math::VectorUtil::DeltaR(tagProbePair->first->p4, tagProbePair->second->p4));
82  }
83  return tagProbeDeltaR;
84  });
85  LambdaNtupleConsumer<HttTypes>::AddVFloatQuantity(metadata, "tagProbeMass", [this](event_type const& event, product_type const& product)
86  {
87  std::vector<float> tagProbeMass;
88  for (typename std::vector<std::pair<TTag*, TProbe*> >::const_iterator tagProbePair = (product.*(this->m_triggerTagProbeObjectPairsMember)).begin();
89  tagProbePair != (product.*(this->m_triggerTagProbeObjectPairsMember)).end(); ++tagProbePair)
90  {
91  tagProbeMass.push_back((tagProbePair->first->p4 + tagProbePair->second->p4).M());
92  }
93  return tagProbeMass;
94  });
95  LambdaNtupleConsumer<HttTypes>::AddVIntQuantity(metadata, "probeMatched", [this](event_type const& event, product_type const& product)
96  {
97  std::vector<int> probeMatched;
98  for (typename std::vector<std::pair<bool, bool> >::const_iterator tagProbePair = (product.*(this->m_triggerTagProbeObjectMatchedPairsMember)).begin();
99  tagProbePair != (product.*(this->m_triggerTagProbeObjectMatchedPairsMember)).end(); ++tagProbePair)
100  {
101  probeMatched.push_back(tagProbePair->second);
102  }
103  return probeMatched;
104  });
105  LambdaNtupleConsumer<HttTypes>::AddVIntQuantity(metadata, "tagMatched", [this](event_type const& event, product_type const& product)
106  {
107  std::vector<int> tagMatched;
108  for (typename std::vector<std::pair<bool, bool> >::const_iterator tagProbePair = (product.*(this->m_triggerTagProbeObjectMatchedPairsMember)).begin();
109  tagProbePair != (product.*(this->m_triggerTagProbeObjectMatchedPairsMember)).end(); ++tagProbePair)
110  {
111  tagMatched.push_back(tagProbePair->first);
112  }
113  return tagMatched;
114  });
115  LambdaNtupleConsumer<HttTypes>::AddVIntQuantity(metadata, "tagCharge", [this](event_type const& event, product_type const& product)
116  {
117  std::vector<int> tagCharge;
118  for (typename std::vector<std::pair<TTag*, TProbe*> >::const_iterator tagProbePair = (product.*(this->m_triggerTagProbeObjectPairsMember)).begin();
119  tagProbePair != (product.*(this->m_triggerTagProbeObjectPairsMember)).end(); ++tagProbePair)
120  {
121  tagCharge.push_back(tagProbePair->first->charge());
122  }
123  return tagCharge;
124  });
125  LambdaNtupleConsumer<HttTypes>::AddVIntQuantity(metadata, "probeCharge", [this](event_type const& event, product_type const& product)
126  {
127  std::vector<int> probeCharge;
128  for (typename std::vector<std::pair<TTag*, TProbe*> >::const_iterator tagProbePair = (product.*(this->m_triggerTagProbeObjectPairsMember)).begin();
129  tagProbePair != (product.*(this->m_triggerTagProbeObjectPairsMember)).end(); ++tagProbePair)
130  {
131  probeCharge.push_back(tagProbePair->second->charge());
132  }
133  return probeCharge;
134  });
135  LambdaNtupleConsumer<HttTypes>::AddVIntQuantity(metadata, "isOS", [this](event_type const& event, product_type const& product)
136  {
137  std::vector<int> isOS;
138  for (typename std::vector<std::pair<TTag*, TProbe*> >::const_iterator tagProbePair = (product.*(this->m_triggerTagProbeObjectPairsMember)).begin();
139  tagProbePair != (product.*(this->m_triggerTagProbeObjectPairsMember)).end(); ++tagProbePair)
140  {
141  isOS.push_back(int((tagProbePair->first->charge()*tagProbePair->second->charge())<0));
142  }
143  return isOS;
144  });
145  LambdaNtupleConsumer<HttTypes>::AddVFloatQuantity(metadata, "tagIsoOverPt", [this](event_type const& event, product_type const& product)
146  {
147  std::vector<float> tagIsoOverPt;
148  for (typename std::vector<std::pair<TTag*, TProbe*> >::const_iterator tagProbePair = (product.*(this->m_triggerTagProbeObjectPairsMember)).begin();
149  tagProbePair != (product.*(this->m_triggerTagProbeObjectPairsMember)).end(); ++tagProbePair)
150  {
151  tagIsoOverPt.push_back(tagProbePair->first->pfIso() / tagProbePair->first->p4.Pt());
152  }
153  return tagIsoOverPt;
154  });
155  LambdaNtupleConsumer<HttTypes>::AddVFloatQuantity(metadata, "tagIso", [this](event_type const& event, product_type const& product)
156  {
157  std::vector<float> tagIso;
158  for (typename std::vector<std::pair<TTag*, TProbe*> >::const_iterator tagProbePair = (product.*(this->m_triggerTagProbeObjectPairsMember)).begin();
159  tagProbePair != (product.*(this->m_triggerTagProbeObjectPairsMember)).end(); ++tagProbePair)
160  {
161  tagIso.push_back(tagProbePair->first->pfIso() / tagProbePair->first->p4.Pt());
162  }
163  return tagIso;
164  });
165  }
166 
167  virtual void ProcessFilteredEvent(event_type const& event, product_type const& product,
168  setting_type const& settings, metadata_type const& metadata) override
169  {
170  size_t index = 0;
171  for (typename std::vector<std::pair<TTag*, TProbe*> >::const_iterator tagProbePair = (product.*m_triggerTagProbeObjectPairsMember).begin();
172  tagProbePair != (product.*m_triggerTagProbeObjectPairsMember).end(); ++tagProbePair)
173  {
174  m_currentTagObject = *(tagProbePair->first);
175  m_currentProbeObject = *(tagProbePair->second);
176 
177  m_currentTagObjectMatched = (product.*m_triggerTagProbeObjectMatchedPairsMember).at(index).first;
178  m_currentProbeObjectMatched = (product.*m_triggerTagProbeObjectMatchedPairsMember).at(index).second;
179 
180  m_tagProbeSystem = tagProbePair->first->p4 + tagProbePair->second->p4;
181 
182  m_tree->Fill();
183  ++index;
184  }
185  }
186 
187  virtual void Finish(setting_type const& settings, metadata_type const& metadata) override
188  {
189  RootFileHelper::SafeCd(settings.GetRootOutFile(),
190  settings.GetRootFileFolder());
191 
192  m_tree->Write(m_tree->GetName());
193  }
194 
195 
196 private:
197  std::string m_treeName;
198  std::vector<std::pair<TTag*, TProbe*> > product_type::*m_triggerTagProbeObjectPairsMember;
199  std::vector<std::pair<bool, bool> > product_type::*m_triggerTagProbeObjectMatchedPairsMember;
200 
201  TTree* m_tree = nullptr;
202 
203  TTag m_currentTagObject;
204  bool m_currentTagObjectMatched;
205  TProbe m_currentProbeObject;
206  bool m_currentProbeObjectMatched;
207  RMFLV m_tagProbeSystem;
208 };
209 
210 
211 
213 {
214 public:
216  virtual std::string GetConsumerId() const override;
217 };
218 
219 
221 {
222 public:
224  virtual std::string GetConsumerId() const override;
225 };
226 
227 
229 {
230 public:
232  virtual std::string GetConsumerId() const override;
233 };
234 
235 
237 {
238 public:
240  virtual std::string GetConsumerId() const override;
241 };
242 
TriggerTagAndProbeConsumerBase(std::string treeName, std::vector< std::pair< TTag *, TProbe * > > product_type::*triggerTagProbeObjectPairsMember, std::vector< std::pair< bool, bool > > product_type::*triggerTagProbeObjectMatchedPairsMember)
Definition: TriggerTagAndProbeConsumers.h:18
MTTriggerTagAndProbeConsumer()
Definition: TriggerTagAndProbeConsumers.cc:35
Definition: TriggerTagAndProbeConsumers.h:220
virtual std::string GetConsumerId() const override
Definition: TriggerTagAndProbeConsumers.cc:29
MMTriggerTagAndProbeConsumer()
Definition: TriggerTagAndProbeConsumers.cc:5
Definition: TriggerTagAndProbeConsumers.h:236
virtual std::string GetConsumerId() const override
Definition: TriggerTagAndProbeConsumers.cc:44
index
Definition: makePlots_shapeUncertainties.py:54
Definition: TriggerTagAndProbeConsumers.h:13
EETriggerTagAndProbeConsumer()
Definition: TriggerTagAndProbeConsumers.cc:20
virtual void ProcessFilteredEvent(event_type const &event, product_type const &product, setting_type const &settings, metadata_type const &metadata) override
Definition: TriggerTagAndProbeConsumers.h:167
Definition: TriggerTagAndProbeConsumers.h:228
Definition: TriggerTagAndProbeConsumers.h:212
ETTriggerTagAndProbeConsumer()
Definition: TriggerTagAndProbeConsumers.cc:50
virtual std::string GetConsumerId() const override
Definition: TriggerTagAndProbeConsumers.cc:59
virtual void Init(setting_type const &settings, metadata_type &metadata) override
Definition: TriggerTagAndProbeConsumers.h:30
all data types which are used for Htt analyses
Definition: HttTypes.h:27
virtual std::string GetConsumerId() const override
Definition: TriggerTagAndProbeConsumers.cc:14
virtual void Finish(setting_type const &settings, metadata_type const &metadata) override
Definition: TriggerTagAndProbeConsumers.h:187