4 #include <boost/regex.hpp>
6 #include "Kappa/DataFormats/interface/Kappa.h"
8 #include "Artus/Core/interface/ProducerBase.h"
9 #include "Artus/Consumer/interface/LambdaNtupleConsumer.h"
10 #include "Artus/Utility/interface/Utility.h"
12 #include "HiggsAnalysis/KITHiggsToTauTau/interface/HttTypes.h"
19 template<
class TLepton1,
class TLepton2>
25 std::vector<TLepton2*> product_type::*validLeptonsMember2) :
27 m_validLeptonsMember1(validLeptonsMember1),
28 m_validLeptonsMember2(validLeptonsMember2)
32 virtual void Init(setting_type
const& settings, metadata_type& metadata)
override
34 ProducerBase<HttTypes>::Init(settings, metadata);
40 m_lepton1LowerPtCutsByIndex = Utility::ParseMapTypes<size_t, float>(
41 Utility::ParseVectorToMap(settings.GetDiTauPairLepton1LowerPtCuts()), m_lepton1LowerPtCutsByHltName
43 m_lepton2LowerPtCutsByIndex = Utility::ParseMapTypes<size_t, float>(
44 Utility::ParseVectorToMap(settings.GetDiTauPairLepton2LowerPtCuts()), m_lepton2LowerPtCutsByHltName
46 m_hltFiredBranchNames = Utility::ParseVectorToMap(settings.GetHLTBranchNames());
49 LambdaNtupleConsumer<HttTypes>::AddIntQuantity(metadata,
"nDiTauPairCandidates", [](event_type
const& event, product_type
const& product)
51 return static_cast<int>(product.m_validDiTauPairCandidates.size());
53 LambdaNtupleConsumer<HttTypes>::AddIntQuantity(metadata,
"nAllDiTauPairCandidates", [](event_type
const& event, product_type
const& product)
55 return static_cast<int>(product.m_validDiTauPairCandidates.size()+product.m_invalidDiTauPairCandidates.size());
57 std::vector<std::string> hltPathsWithoutCommonMatch = settings.GetDiTauPairHltPathsWithoutCommonMatchRequired();
76 for(
auto hltNames: m_hltFiredBranchNames)
78 std::map<std::string, std::vector<float>> lepton1LowerPtCutsByHltName = m_lepton1LowerPtCutsByHltName;
79 std::map<std::string, std::vector<float>> lepton2LowerPtCutsByHltName = m_lepton2LowerPtCutsByHltName;
80 LambdaNtupleConsumer<HttTypes>::AddBoolQuantity(metadata, hltNames.first, [hltNames, hltPathsWithoutCommonMatch, lepton1LowerPtCutsByHltName, lepton2LowerPtCutsByHltName](event_type
const& event, product_type
const& product)
82 bool diTauPairFiredTrigger =
false;
84 for (
auto hltName: hltNames.second)
86 if(std::find(hltPathsWithoutCommonMatch.begin(), hltPathsWithoutCommonMatch.end(), hltName) == hltPathsWithoutCommonMatch.end())
90 if (product.m_detailedTriggerMatchedLeptons.find(static_cast<KLepton*>(product.m_validDiTauPairCandidates.at(0).first)) != product.m_detailedTriggerMatchedLeptons.end() &&
91 product.m_detailedTriggerMatchedLeptons.find(static_cast<KLepton*>(product.m_validDiTauPairCandidates.at(0).second)) != product.m_detailedTriggerMatchedLeptons.end())
93 auto trigger1 = product.m_detailedTriggerMatchedLeptons.at(static_cast<KLepton*>(product.m_validDiTauPairCandidates.at(0).first));
94 auto trigger2 = product.m_detailedTriggerMatchedLeptons.at(static_cast<KLepton*>(product.m_validDiTauPairCandidates.at(0).second));
95 bool hltFired1 =
false;
96 bool hltFired2 =
false;
97 for (
auto hlts: (*trigger1))
99 if (boost::regex_search(hlts.first,
boost::regex(hltName, boost::regex::icase | boost::regex::extended)))
101 for (
auto matchedObjects: hlts.second)
103 if (matchedObjects.second.size() > 0) hltFired1 =
true;
108 for (
auto hlts: (*trigger2))
110 if (boost::regex_search(hlts.first,
boost::regex(hltName, boost::regex::icase | boost::regex::extended)))
112 for (
auto matchedObjects: hlts.second)
114 if (matchedObjects.second.size() > 0) hltFired2 =
true;
119 bool hltFired = hltFired1 && hltFired2;
121 if (lepton1LowerPtCutsByHltName.find(hltName) != lepton1LowerPtCutsByHltName.end())
123 hltFired = hltFired &&
124 (product.m_validDiTauPairCandidates.at(0).first->p4.Pt() > *std::max_element(lepton1LowerPtCutsByHltName.at(hltName).begin(), lepton1LowerPtCutsByHltName.at(hltName).end()));
127 if (lepton2LowerPtCutsByHltName.find(hltName) != lepton2LowerPtCutsByHltName.end())
129 hltFired = hltFired &&
130 (product.m_validDiTauPairCandidates.at(0).second->p4.Pt() > *std::max_element(lepton2LowerPtCutsByHltName.at(hltName).begin(), lepton2LowerPtCutsByHltName.at(hltName).end()));
134 diTauPairFiredTrigger = diTauPairFiredTrigger || hltFired;
141 if (product.m_detailedTriggerMatchedLeptons.find(static_cast<KLepton*>(product.m_validDiTauPairCandidates.at(0).first)) != product.m_detailedTriggerMatchedLeptons.end())
143 auto trigger = product.m_detailedTriggerMatchedLeptons.at(static_cast<KLepton*>(product.m_validDiTauPairCandidates.at(0).first));
144 bool hltFired =
false;
145 for (
auto hlts: (*trigger))
147 if (boost::regex_search(hlts.first,
boost::regex(hltName, boost::regex::icase | boost::regex::extended)))
149 for (
auto matchedObjects: hlts.second)
151 if (matchedObjects.second.size() > 0) hltFired =
true;
157 if (lepton1LowerPtCutsByHltName.find(hltName) != lepton1LowerPtCutsByHltName.end())
159 hltFired = hltFired &&
160 (product.m_validDiTauPairCandidates.at(0).first->p4.Pt() > *std::max_element(lepton1LowerPtCutsByHltName.at(hltName).begin(), lepton1LowerPtCutsByHltName.at(hltName).end()));
163 if (lepton2LowerPtCutsByHltName.find(hltName) != lepton2LowerPtCutsByHltName.end())
165 hltFired = hltFired &&
166 (product.m_validDiTauPairCandidates.at(0).second->p4.Pt() > *std::max_element(lepton2LowerPtCutsByHltName.at(hltName).begin(), lepton2LowerPtCutsByHltName.at(hltName).end()));
170 diTauPairFiredTrigger = diTauPairFiredTrigger || hltFired;
175 return diTauPairFiredTrigger;
180 virtual void Produce(event_type
const& event, product_type & product,
181 setting_type
const& settings, metadata_type
const& metadata)
const override
183 product.m_validDiTauPairCandidates.clear();
186 for (
typename std::vector<TLepton1*>::iterator lepton1 = (product.*m_validLeptonsMember1).begin();
187 lepton1 != (product.*m_validLeptonsMember1).end(); ++lepton1)
189 for (
typename std::vector<TLepton2*>::iterator lepton2 = (product.*m_validLeptonsMember2).begin();
190 lepton2 != (product.*m_validLeptonsMember2).end(); ++lepton2)
195 bool validDiTauPair =
true;
201 validDiTauPair = validDiTauPair && ((settings.GetDiTauPairMinDeltaRCut() < 0.0) || (diTauPair.
GetDeltaR() >
static_cast<double>(settings.GetDiTauPairMinDeltaRCut())));
204 if ((! settings.GetDiTauPairNoHLT()) && (! settings.GetDiTauPairHLTLast()))
206 std::vector<std::string> commonHltPaths = diTauPair.
GetCommonHltPaths(product.m_detailedTriggerMatchedLeptons, settings.GetDiTauPairHltPathsWithoutCommonMatchRequired());
207 validDiTauPair = validDiTauPair && (commonHltPaths.size() > 0);
213 std::vector<bool> hltValidDiTauPair(commonHltPaths.size(),
true);
214 for (std::vector<std::string>::size_type hltPathNumber = 0; hltPathNumber != commonHltPaths.size(); ++hltPathNumber)
217 for (std::map<
size_t, std::vector<float> >::const_iterator lowerPtCutByIndex = m_lepton1LowerPtCutsByIndex.begin();
218 lowerPtCutByIndex != m_lepton1LowerPtCutsByIndex.end() && hltValidDiTauPair.at(hltPathNumber); ++lowerPtCutByIndex)
220 if ((diTauPair.first->p4.Pt() <= *std::max_element(lowerPtCutByIndex->second.begin(), lowerPtCutByIndex->second.end())) &&
221 boost::regex_search(commonHltPaths.at(hltPathNumber),
boost::regex(settings.GetHltPaths().at(lowerPtCutByIndex->first), boost::regex::icase | boost::regex::extended)))
223 hltValidDiTauPair.at(hltPathNumber) =
false;
228 for (std::map<std::string, std::vector<float> >::const_iterator lowerPtCutByHltName = m_lepton1LowerPtCutsByHltName.begin();
229 lowerPtCutByHltName != m_lepton1LowerPtCutsByHltName.end() && hltValidDiTauPair.at(hltPathNumber); ++lowerPtCutByHltName)
231 if ((diTauPair.first->p4.Pt() <= *std::max_element(lowerPtCutByHltName->second.begin(), lowerPtCutByHltName->second.end())) &&
232 boost::regex_search(commonHltPaths.at(hltPathNumber),
boost::regex(lowerPtCutByHltName->first, boost::regex::icase | boost::regex::extended)))
234 hltValidDiTauPair.at(hltPathNumber) =
false;
239 for (std::map<
size_t, std::vector<float> >::const_iterator lowerPtCutByIndex = m_lepton2LowerPtCutsByIndex.begin();
240 lowerPtCutByIndex != m_lepton2LowerPtCutsByIndex.end() && hltValidDiTauPair.at(hltPathNumber); ++lowerPtCutByIndex)
242 if ((diTauPair.second->p4.Pt() <= *std::max_element(lowerPtCutByIndex->second.begin(), lowerPtCutByIndex->second.end())) &&
243 boost::regex_search(commonHltPaths.at(hltPathNumber),
boost::regex(settings.GetHltPaths().at(lowerPtCutByIndex->first), boost::regex::icase | boost::regex::extended)))
245 hltValidDiTauPair.at(hltPathNumber) =
false;
250 for (std::map<std::string, std::vector<float> >::const_iterator lowerPtCutByHltName = m_lepton2LowerPtCutsByHltName.begin();
251 lowerPtCutByHltName != m_lepton2LowerPtCutsByHltName.end() && hltValidDiTauPair.at(hltPathNumber); ++lowerPtCutByHltName)
253 if ((diTauPair.second->p4.Pt() <= *std::max_element(lowerPtCutByHltName->second.begin(), lowerPtCutByHltName->second.end())) &&
254 boost::regex_search(commonHltPaths.at(hltPathNumber),
boost::regex(lowerPtCutByHltName->first, boost::regex::icase | boost::regex::extended)))
256 hltValidDiTauPair.at(hltPathNumber) =
false;
261 validDiTauPair =
false;
262 for (std::vector<bool>::const_iterator hltPathResult = hltValidDiTauPair.begin(); hltPathResult != hltValidDiTauPair.end(); ++hltPathResult)
266 validDiTauPair =
true;
270 if (settings.GetRequireFirstTriggering())
272 bool hltFired =
false;
273 auto trigger = product.m_detailedTriggerMatchedLeptons[
static_cast<KLepton*
>(diTauPair.first)];
274 for (
auto hltName : settings.GetHltPaths())
276 for (
auto hlts: (*trigger))
278 if (boost::regex_search(hlts.first,
boost::regex(hltName, boost::regex::icase | boost::regex::extended)))
280 for (
auto matchedObjects: hlts.second)
282 if (matchedObjects.second.size() > 0) hltFired =
true;
287 validDiTauPair = validDiTauPair && hltFired;
288 validDiTauPair = validDiTauPair && (diTauPair.first->p4.Pt() >= diTauPair.second->p4.Pt());
292 else if(!settings.GetDiTauPairHLTLast())
297 for (std::map<
size_t, std::vector<float> >::const_iterator lowerPtCutByIndex = m_lepton1LowerPtCutsByIndex.begin();
298 lowerPtCutByIndex != m_lepton1LowerPtCutsByIndex.end(); ++lowerPtCutByIndex)
300 if (diTauPair.first->p4.Pt() <= *std::max_element(lowerPtCutByIndex->second.begin(), lowerPtCutByIndex->second.end()))
302 validDiTauPair =
false;
307 for (std::map<std::string, std::vector<float> >::const_iterator lowerPtCutByHltName = m_lepton1LowerPtCutsByHltName.begin();
308 lowerPtCutByHltName != m_lepton1LowerPtCutsByHltName.end(); ++lowerPtCutByHltName)
310 if (diTauPair.first->p4.Pt() <= *std::max_element(lowerPtCutByHltName->second.begin(), lowerPtCutByHltName->second.end()))
312 validDiTauPair =
false;
317 for (std::map<
size_t, std::vector<float> >::const_iterator lowerPtCutByIndex = m_lepton2LowerPtCutsByIndex.begin();
318 lowerPtCutByIndex != m_lepton2LowerPtCutsByIndex.end(); ++lowerPtCutByIndex)
320 if (diTauPair.second->p4.Pt() <= *std::max_element(lowerPtCutByIndex->second.begin(), lowerPtCutByIndex->second.end()))
322 validDiTauPair =
false;
327 for (std::map<std::string, std::vector<float> >::const_iterator lowerPtCutByHltName = m_lepton2LowerPtCutsByHltName.begin();
328 lowerPtCutByHltName != m_lepton2LowerPtCutsByHltName.end(); ++lowerPtCutByHltName)
330 if (diTauPair.second->p4.Pt() <= *std::max_element(lowerPtCutByHltName->second.begin(), lowerPtCutByHltName->second.end()))
332 validDiTauPair =
false;
337 validDiTauPair = validDiTauPair && (diTauPair.first->p4.Pt() > settings.GetLowerCutHardLepPt() || diTauPair.second->p4.Pt() > settings.GetLowerCutHardLepPt());
340 validDiTauPair = validDiTauPair && AdditionalCriteria(diTauPair, event, product, settings, metadata);
343 product.m_validDiTauPairCandidates.push_back(diTauPair);
347 product.m_invalidDiTauPairCandidates.push_back(diTauPair);
352 std::sort(product.m_validDiTauPairCandidates.begin(), product.m_validDiTauPairCandidates.end(),
354 std::sort(product.m_invalidDiTauPairCandidates.begin(), product.m_invalidDiTauPairCandidates.end(),
362 product_type& product, setting_type
const& settings, metadata_type
const& metadata)
const
364 bool validDiTauPair =
true;
365 return validDiTauPair;
370 std::vector<TLepton1*> product_type::*m_validLeptonsMember1;
371 std::vector<TLepton2*> product_type::*m_validLeptonsMember2;
373 std::map<size_t, std::vector<float> > m_lepton1LowerPtCutsByIndex;
374 std::map<std::string, std::vector<float> > m_lepton1LowerPtCutsByHltName;
375 std::map<size_t, std::vector<float> > m_lepton2LowerPtCutsByIndex;
376 std::map<std::string, std::vector<float> > m_lepton2LowerPtCutsByHltName;
377 std::map<std::string, std::vector<std::string> > m_hltFiredBranchNames;
virtual void Init(setting_type const &settings, metadata_type &metadata) override
Definition: ValidDiTauPairCandidatesProducers.h:32
virtual std::string GetProducerId() const override
Definition: ValidDiTauPairCandidatesProducers.cc:13
ValidDiTauPairCandidatesProducerBase(std::vector< TLepton1 * > product_type::*validLeptonsMember1, std::vector< TLepton2 * > product_type::*validLeptonsMember2)
Definition: ValidDiTauPairCandidatesProducers.h:24
ValidMMPairCandidatesProducer()
Definition: ValidDiTauPairCandidatesProducers.cc:61
virtual std::string GetProducerId() const override
Definition: ValidDiTauPairCandidatesProducers.cc:41
ValidMTPairCandidatesProducer()
Definition: ValidDiTauPairCandidatesProducers.cc:19
ValidEEPairCandidatesProducer()
Definition: ValidDiTauPairCandidatesProducers.cc:75
Definition: DiTauPair.h:23
virtual bool AdditionalCriteria(DiTauPair const &diTauPair, event_type const &event, product_type &product, setting_type const &settings, metadata_type const &metadata) const
Definition: ValidDiTauPairCandidatesProducers.h:361
Producers for candidates of di-tau pairs.
Definition: ValidDiTauPairCandidatesProducers.h:20
Definition: ValidDiTauPairCandidatesProducers.h:403
ValidTTPairCandidatesProducer()
Definition: ValidDiTauPairCandidatesProducers.cc:5
Definition: ValidDiTauPairCandidatesProducers.h:410
Definition: ValidDiTauPairCandidatesProducers.h:396
virtual std::string GetProducerId() const override
Definition: ValidDiTauPairCandidatesProducers.cc:83
virtual void Produce(event_type const &event, product_type &product, setting_type const &settings, metadata_type const &metadata) const override
Definition: ValidDiTauPairCandidatesProducers.h:180
virtual std::string GetProducerId() const override
Definition: ValidDiTauPairCandidatesProducers.cc:55
Definition: ValidDiTauPairCandidatesProducers.h:382
virtual std::string GetProducerId() const override
Definition: ValidDiTauPairCandidatesProducers.cc:69
Definition: ValidDiTauPairCandidatesProducers.h:389
all data types which are used for Htt analyses
Definition: HttTypes.h:27
tuple regex
Definition: plot_overtraining.py:51
ValidETPairCandidatesProducer()
Definition: ValidDiTauPairCandidatesProducers.cc:33
std::vector< std::string > GetCommonHltPaths(std::map< KLepton *, std::map< std::string, std::map< std::string, std::vector< KLV * > > > * > const &detailedTriggerMatchedLeptons, std::vector< std::string > const &hltPathsWithoutCommonMatchRequired)
Definition: DiTauPair.cc:22
Definition: ValidDiTauPairCandidatesProducers.h:417
double GetDeltaR()
Definition: DiGenTauPair.cc:14
ValidEMPairCandidatesProducer()
Definition: ValidDiTauPairCandidatesProducers.cc:47
Definition: DiTauPair.h:9
virtual std::string GetProducerId() const override
Definition: ValidDiTauPairCandidatesProducers.cc:27