ATLAS Offline Software
NJetBtagSelector.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3  */
4 
7 
9 using namespace TopEventSelectionTools;
10 
11 namespace top {
12  NJetBtagSelector::NJetBtagSelector(const std::string& params, std::shared_ptr<top::TopConfig> config,
13  bool doTrackJets) :
14  SignValueSelector((doTrackJets ? "TJET_N_BTAG" : "JET_N_BTAG"), params, true, true, ":", "_", "DL1r"),
15  m_doTrackJets(doTrackJets) {
17 
18  // check if the provided btag WP is really available - need to replace : with _ to match the naming of variables
19  bool bTagWP_exists = false;
20  if (m_doTrackJets) bTagWP_exists =
21  (std::find(config->bTagWP_trkJet().begin(), config->bTagWP_trkJet().end(), valueStringDelimReplace()) != config->bTagWP_trkJet().end());
22  else bTagWP_exists =
23  (std::find(config->bTagWP().begin(), config->bTagWP().end(), valueStringDelimReplace()) != config->bTagWP().end());
24 
25  if (!bTagWP_exists) {
26  ATH_MSG_ERROR("NJetBtagSelector is confused\n"
27  << "B-tagging working point " << valueString() << " doesn't seem to be configured.\n"
28  << "Did you provide the argument as bTagAlgorithm:bTagWP ? \n "
29  << "Did you specified it in the \"BTaggingCaloWP\" or \"BTaggingTrackJetWP\" field of your cutfile?\n");
30  throw std::runtime_error("NJetBtagSelector: Invalid btagging selector WP: " + name());
31  }
32  }
33 
35  auto func = [&](const xAOD::Jet* jetPtr) {
36  if (!jetPtr->isAvailable<char>("isbtagged_" + valueStringDelimReplace())) {
37  throw std::runtime_error("NJetBtagSelector: Jet doesn't have decoration \"isbtagged_" +
38  valueStringDelimReplace() + "\"");
39  }
40  return jetPtr->auxdataConst<char>("isbtagged_" + valueStringDelimReplace());
41  };
42  int count = 0;
43 
44  if (m_doTrackJets) {
45  count = std::count_if(event.m_trackJets.begin(), event.m_trackJets.end(), func);
46  } else {
47  count = std::count_if(event.m_jets.begin(), event.m_jets.end(), func);
48  }
49  return checkInt(count, multiplicity());
50  }
51 }
top::SignValueSelector::checkInt
bool checkInt(int value, int cut) const
Compare a cut supplied by the user with the value calculated in the event.
Definition: SignValueSelector.cxx:159
top
TopConfig A simple configuration that is NOT a singleton.
Definition: AnalysisTrackingHelper.cxx:58
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
top::SignValueSelector::multiplicity
double multiplicity() const
Get the cut multiplicity assigned in the constructor.
Definition: SignValueSelector.cxx:106
MsgCategory.h
top::SignValueSelector
Many of the tools need a sign (>=) and a value (2).
Definition: SignValueSelector.h:16
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
top::SignValueSelector::valueString
std::string valueString() const
Get the cut value assigned in the constructor.
Definition: SignValueSelector.cxx:98
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
NJetBtagSelector.h
top::NJetBtagSelector::apply
bool apply(const top::Event &event) const override
This does stuff based on the information in an event.
Definition: NJetBtagSelector.cxx:34
top::SignValueSelector::checkMultiplicityIsInteger
void checkMultiplicityIsInteger()
Integers are annoying in C++.
Definition: SignValueSelector.cxx:82
TopConfig.h
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
top::NJetBtagSelector::m_doTrackJets
bool m_doTrackJets
Definition: NJetBtagSelector.h:22
top::Event
Very simple class to hold event data after reading from a file.
Definition: Event.h:49
PowhegControl_ttFCNC_NLO.params
params
Definition: PowhegControl_ttFCNC_NLO.py:226
top::SignValueSelector::valueStringDelimReplace
std::string valueStringDelimReplace() const
valueString which is manipulated to replace delimiter with new string
Definition: SignValueSelector.cxx:102
top::SignValueSelector::name
virtual std::string name() const override
The name is generated in the constructor for this kind of tool.
Definition: SignValueSelector.cxx:70