ATLAS Offline Software
SignValueSelector.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3  */
4 
7 
9 using namespace TopEventSelectionTools;
10 
11 namespace top {
12  SignValueSelector::SignValueSelector(const std::string& name, std::string params, bool multiplicityMode,
13  bool cutValueMode) :
14  m_sign(signNOIDEA),
15  m_cutvalue(0),
16  m_cutvalueString(""),
17  m_multiplicity(-1) {
19  //cutValueMode always set to false if multiplicityMode is false
20  if (!multiplicityMode) cutValueMode = false;
21  //get the sign and remove it from the params text
23  if (!cutValueMode) std::istringstream(params) >> m_cutvalue >> m_multiplicity;
24  else std::istringstream(params) >> m_cutvalueString >> m_multiplicity;
25 
26  //form the name string for the tool
27  std::stringstream ss;
28  if (!multiplicityMode) ss << name << " " << signstring() << " " << m_cutvalue;
29  else {
30  if (m_multiplicity < 0) {
31  throw std::runtime_error("Cut value and multiplicity must be set for " + name);
32  }
33 
34  if (!cutValueMode) ss << name << " " << m_cutvalue << " " << signstring() << " " << m_multiplicity;
35  else ss << name << " " << m_cutvalueString << " " << signstring() << " " << m_multiplicity;
36  }
37 
38  m_name = ss.str();
39  }
40 
41  SignValueSelector::SignValueSelector(const std::string& name, std::string params, bool multiplicityMode,
42  bool cutValueMode, std::string delim, std::string replace,
43  std::string default_prefix) :
44  SignValueSelector(name, params, multiplicityMode, cutValueMode) {
45  // This function is only if we need a bit of additional string manipulation
46  // Required for the btagging selector when we start doing "alg:wp"
47  // If string is empty, do the split, otherwise just return the stored value
48 
49  std::vector<std::string> tokens;
51  if (tokens.size() > 1) {
52  for (const auto& cutString : tokens) {
55  }
56  // Tidy up the end of the string
59  replace.length());
60  }
61  // We are kind, and keep some backwards compatablity, so incase you did not know the syntax changed, hopefully we
62  // provided the most likely default
63  else {
64  ATH_MSG_INFO("SignValueSelector :: We are using a default_prefix as we could not split on a delimiter.");
66  ATH_MSG_INFO("SignValueSelector :: The final result is " << m_cutvalueStringDelimReplace);
67  }
68  }
69 
70  std::string SignValueSelector::name() const {
71  return m_name;
72  }
73 
75  if (value() != floor(value())) {
76  ATH_MSG_ERROR("The number " << value() << " is not an integer\n"
77  << "As defined in " << name() << "\n");
78  throw std::runtime_error("Failed parsing value for SignValueSelector");
79  }
80  }
81 
83  if (multiplicity() != floor(multiplicity())) {
84  ATH_MSG_ERROR("The number " << multiplicity() << " is not an integer\n"
85  << "As defined in " << name() << "\n");
86  throw std::runtime_error("Failed parsing multiplicity cut for SignValueSelector");
87  }
88  }
89 
91  return m_sign;
92  }
93 
94  double SignValueSelector::value() const {
95  return m_cutvalue;
96  }
97 
98  std::string SignValueSelector::valueString() const {
99  return m_cutvalueString;
100  }
101 
104  }
105 
107  return m_multiplicity;
108  }
109 
111  Sign tempsign(signNOIDEA);
112 
113  if (params.find("==") != std::string::npos) {
114  tempsign = signEQ;
115  params.erase(params.find("=="), 2);
116  } else if (params.find("<=") != std::string::npos) {
117  tempsign = signLTEQ;
118  params.erase(params.find("<="), 2);
119  } else if (params.find(">=") != std::string::npos) {
120  tempsign = signGTEQ;
121  params.erase(params.find(">="), 2);
122  } else if (params.find("<") != std::string::npos) {
123  tempsign = signLT;
124  params.erase(params.find("<"), 1);
125  } else if (params.find(">") != std::string::npos) {
126  tempsign = signGT;
127  params.erase(params.find(">"), 1);
128  }
129 
130  return tempsign;
131  }
132 
133  bool SignValueSelector::checkFloat(double value, double cut) const {
134  switch (m_sign) {
135  case signNOIDEA: {
136  throw std::runtime_error("SignValueSelector::checkFloat: Can't recognise the sign");
137  }
138 
139  case signEQ: {
140  throw std::runtime_error("SignValueSelector::checkFloat: Can't compare floats with ==");
141  }
142 
143  case signLT:
144  return value < cut;
145 
146  case signGT:
147  return value > cut;
148 
149  case signLTEQ:
150  return value <= cut;
151 
152  case signGTEQ:
153  return value >= cut;
154  }
155 
156  return false;
157  }
158 
159  bool SignValueSelector::checkInt(int value, int cut) const {
160  switch (m_sign) {
161  case signNOIDEA: {
162  throw std::runtime_error("SignValueSelector::checkInt: Can't recognise the sign");
163  }
164 
165  case signEQ:
166  return value == cut;
167 
168  case signLT:
169  return value < cut;
170 
171  case signGT:
172  return value > cut;
173 
174  case signLTEQ:
175  return value <= cut;
176 
177  case signGTEQ:
178  return value >= cut;
179  }
180 
181  return false;
182  }
183 
184  const std::string SignValueSelector::signstring() const {
185  switch (m_sign) {
186  case signNOIDEA: {
187  ATH_MSG_ERROR("SignValueSelector is confused\n"
188  << "Check that your cuts have one of: "
189  << "==, >, >=, <, <=\n");
190  throw std::runtime_error("SignValueSelector::signstring: Can't recognise the comparison operator");
191  }
192 
193  case signEQ:
194  return "==";
195 
196  case signLT:
197  return "<";
198 
199  case signGT:
200  return ">";
201 
202  case signLTEQ:
203  return "<=";
204 
205  case signGTEQ:
206  return ">=";
207  }
208 
209  return "";
210  }
211 }
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
top::SignValueSelector::SignValueSelector
SignValueSelector(const std::string &name, std::string params, bool multiplicityMode=false, bool cutValueMode=false)
Constructor for tools that need a sign and a value.
Definition: SignValueSelector.cxx:12
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::SignValueSelector::sign
Sign sign() const
Get the sign setup in the constructor.
Definition: SignValueSelector.cxx:90
top
TopConfig A simple configuration that is NOT a singleton.
Definition: AnalysisTrackingHelper.cxx:58
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
top::SignValueSelector::multiplicity
double multiplicity() const
Get the cut multiplicity assigned in the constructor.
Definition: SignValueSelector.cxx:106
top::tokenize
void tokenize(const std::string &input, Container &output, const std::string &delimiters=" ", bool trim_empty=false)
Tokenize an input string using a set of delimiters.
Definition: Tokenize.h:24
top::SignValueSelector::signLT
@ signLT
Definition: SignValueSelector.h:26
athena.value
value
Definition: athena.py:122
top::SignValueSelector::signGT
@ signGT
Definition: SignValueSelector.h:27
top::SignValueSelector::m_name
std::string m_name
Hold the name of the tool, filled by the constructor.
Definition: SignValueSelector.h:168
MsgCategory.h
beamspotman.tokens
tokens
Definition: beamspotman.py:1284
top::SignValueSelector::m_sign
Sign m_sign
The sign of the cut, filled by the constructor.
Definition: SignValueSelector.h:171
top::SignValueSelector
Many of the tools need a sign (>=) and a value (2).
Definition: SignValueSelector.h:16
top::SignValueSelector::checkValueIsInteger
void checkValueIsInteger()
Integers are annoying in C++.
Definition: SignValueSelector.cxx:74
top::SignValueSelector::checkFloat
bool checkFloat(double value, double cut) const
Compare a cut supplied by the user with the value calculated in the event.
Definition: SignValueSelector.cxx:133
SignValueSelector.h
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
top::SignValueSelector::m_multiplicity
double m_multiplicity
The multiplicity for cuts that take both a value and a multiplicity e.g. EL_N 25000 >= 2.
Definition: SignValueSelector.h:180
top::SignValueSelector::signstring
const std::string signstring() const
Convert the sign enum back to a string for use in the name and print outs.
Definition: SignValueSelector.cxx:184
BindingsTest.cut
cut
This script demonstrates how to call a C++ class from Python Also how to use PyROOT is shown.
Definition: BindingsTest.py:13
top::SignValueSelector::checkMultiplicityIsInteger
void checkMultiplicityIsInteger()
Integers are annoying in C++.
Definition: SignValueSelector.cxx:82
top::SignValueSelector::signNOIDEA
@ signNOIDEA
Definition: SignValueSelector.h:24
top::SignValueSelector::m_cutvalue
double m_cutvalue
The value of the cut, filled by the constructor.
Definition: SignValueSelector.h:174
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
top::SignValueSelector::decodesign
Sign decodesign(std::string &params)
Take the string params, look for one of the allowed inequalities (or equality) and return that.
Definition: SignValueSelector.cxx:110
top::SignValueSelector::value
double value() const
Get the cut value assigned in the constructor.
Definition: SignValueSelector.cxx:94
top::SignValueSelector::signGTEQ
@ signGTEQ
Definition: SignValueSelector.h:29
top::SignValueSelector::Sign
Sign
Many of the tools will be supplied with an equality (or inequality) by the user.
Definition: SignValueSelector.h:23
top::SignValueSelector::signLTEQ
@ signLTEQ
Definition: SignValueSelector.h:28
Tokenize.h
PhysDESDM_SmpMs.cutString
string cutString
Definition: PhysDESDM_SmpMs.py:51
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::signEQ
@ signEQ
Definition: SignValueSelector.h:25
top::SignValueSelector::m_cutvalueString
std::string m_cutvalueString
The value of the cut in the case it's a string, filled by the constructor.
Definition: SignValueSelector.h:177
top::SignValueSelector::m_cutvalueStringDelimReplace
std::string m_cutvalueStringDelimReplace
The value of the cut when it is a string, with replacement of delimiter with a replacement substring.
Definition: SignValueSelector.h:183
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