ATLAS Offline Software
Public Types | Public Member Functions | Protected Member Functions | Private Attributes | List of all members
top::SignValueSelector Class Referenceabstract

Many of the tools need a sign (>=) and a value (2). More...

#include <SignValueSelector.h>

Inherits top::EventSelectorBase.

Inherited by top::HTSelector, top::JetNGhostSelector, top::KLFitterSelector, top::METMWTSelector, top::METSelector, top::MLLSelector, top::MWTSelector, top::NElectronNMuonSelector, top::NElectronNMuonTightSelector, top::NElectronSelector, top::NElectronTightSelector, top::NFwdElectronSelector, top::NFwdElectronTightSelector, top::NJetBtagSelector, top::NJetSelector, top::NLargeJetSelector, top::NMuonSelector, top::NMuonTightSelector, top::NPhotonSelector, top::NRCJetSelector, top::NSoftMuonSelector, top::NTauSelector, top::NTauTightSelector, top::NVarRCJetSelector, and top::RunNumberSelector.

Collaboration diagram for top::SignValueSelector:

Public Types

enum  Sign {
  signNOIDEA, signEQ, signLT, signGT,
  signLTEQ, signGTEQ
}
 Many of the tools will be supplied with an equality (or inequality) by the user. More...
 

Public Member Functions

 SignValueSelector (const std::string &name, std::string params, bool multiplicityMode=false, bool cutValueMode=false)
 Constructor for tools that need a sign and a value. More...
 
 SignValueSelector (const std::string &name, std::string params, bool multiplicityMode, bool cutValueMode, std::string delim, std::string replace, std::string default_prefix)
 Overloaded constructor with additional options to do string splitting on delimiter and concatantion with a new string. More...
 
virtual std::string name () const override
 The name is generated in the constructor for this kind of tool. More...
 
virtual bool apply (const top::Event &) const =0
 This does stuff based on the information in an event. More...
 
virtual bool applyParticleLevel (const top::ParticleLevelEvent &) const
 This does stuff based on the information in a particle level event. More...
 

Protected Member Functions

void checkValueIsInteger ()
 Integers are annoying in C++. More...
 
void checkMultiplicityIsInteger ()
 Integers are annoying in C++. More...
 
Sign sign () const
 Get the sign setup in the constructor. More...
 
double value () const
 Get the cut value assigned in the constructor. More...
 
std::string valueString () const
 Get the cut value assigned in the constructor. More...
 
std::string valueStringDelimReplace () const
 valueString which is manipulated to replace delimiter with new string More...
 
double multiplicity () const
 Get the cut multiplicity assigned in the constructor. More...
 
Sign decodesign (std::string &params)
 Take the string params, look for one of the allowed inequalities (or equality) and return that. More...
 
bool checkFloat (double value, double cut) const
 Compare a cut supplied by the user with the value calculated in the event. More...
 
bool checkInt (int value, int cut) const
 Compare a cut supplied by the user with the value calculated in the event. More...
 
const std::string signstring () const
 Convert the sign enum back to a string for use in the name and print outs. More...
 

Private Attributes

std::string m_name
 Hold the name of the tool, filled by the constructor. More...
 
Sign m_sign
 The sign of the cut, filled by the constructor. More...
 
double m_cutvalue
 The value of the cut, filled by the constructor. More...
 
std::string m_cutvalueString
 The value of the cut in the case it's a string, filled by the constructor. More...
 
double m_multiplicity
 The multiplicity for cuts that take both a value and a multiplicity e.g. EL_N 25000 >= 2. More...
 
std::string m_cutvalueStringDelimReplace
 The value of the cut when it is a string, with replacement of delimiter with a replacement substring. More...
 

Detailed Description

Many of the tools need a sign (>=) and a value (2).

For example, if we want at least two leptons. This is an intermediate 'base' class that implements all the functionality these tools need in one place.

Definition at line 16 of file SignValueSelector.h.

Member Enumeration Documentation

◆ Sign

Many of the tools will be supplied with an equality (or inequality) by the user.

They're decoded from the text input and saved in this 'sign' format.

Enumerator
signNOIDEA 
signEQ 
signLT 
signGT 
signLTEQ 
signGTEQ 

Definition at line 23 of file SignValueSelector.h.

23  {
24  signNOIDEA, //the user clearly did something wrong, expect to exit / crash
25  signEQ, // ==
26  signLT, // <
27  signGT, // >
28  signLTEQ, // <=
29  signGTEQ // >=
30  };

Constructor & Destructor Documentation

◆ SignValueSelector() [1/2]

top::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.

For example selectors based on multiplicity and cuts.

Parameters
nameThe name of the tool to be used in print outs
paramsThe parameters to setup the tool with. Note that it's not constant because it's edited by the decodesign function (to remove stuff).
multiplicityModeWill this take both a cut value and a multiplicity. For example b-tagging. MV1 0.5 >= 2. Two mv1 tags of atleast 0.5. The default is the "normal" cut mode for cuts like MET, HT etc.
cutValueModeThe cut value can also be a string, e.g. FixedCutBEff_77 The default behaviour is false (the cut value is not a string). Note that cutValueMode = true only makes sense if multiplicityMode = true

Definition at line 12 of file SignValueSelector.cxx.

13  :
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  }

◆ SignValueSelector() [2/2]

top::SignValueSelector::SignValueSelector ( const std::string &  name,
std::string  params,
bool  multiplicityMode,
bool  cutValueMode,
std::string  delim,
std::string  replace,
std::string  default_prefix 
)

Overloaded constructor with additional options to do string splitting on delimiter and concatantion with a new string.

Parameters
delim- delimiter to split with
replace- string to replace the delimiter when concatanating
default_prefix- if it was not possible to split, the code was probably expecting something to be prepended to the string so cover this

Definition at line 41 of file SignValueSelector.cxx.

43  :
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  }

Member Function Documentation

◆ apply()

virtual bool top::EventSelectorBase::apply ( const top::Event ) const
pure virtualinherited

This does stuff based on the information in an event.

The idea is that you implement this to return either true or false based on the information held within top::Event. If this returns true then the event is kept. If it returns false then the event is removed.

Parameters
top::EventThe current event.
Returns
true if the event should be kept, false otherwise.

Implemented in top::GlobalTrigDecisionSelector, top::GlobalTrigMatchSelector, top::JetResponsePlots, top::TrigDecisionLooseSelector, top::TrigDecisionTightSelector, top::JetFlavorPlots, top::TrigDecisionSelector, top::ExamplePlots, top::JetCleaningSelector, top::JetFtagEffPlots, top::NoBadMuonSelector, top::FakesMMConfigs, top::PrimaryVertexSelector, top::GRLSelector, top::NElectronNMuonTightSelector, top::GoodCaloSelector, top::NElectronNMuonSelector, top::TrigMatchSelector, top::PrintEventSelector, top::NFwdElectronSelector, top::TrackJetCleaningSelector, top::RunNumberSelector, top::HTSelector, top::NJetBtagSelector, top::OSLeptonTightSelector, top::MLLSelector, top::MWTSelector, top::NElectronTightSelector, top::NFwdElectronTightSelector, top::NMuonTightSelector, top::OSLeptonSelector, top::METMWTSelector, top::METSelector, top::MLLWindow, top::NElectronSelector, top::NJetSelector, top::NMuonSelector, top::NPhotonSelector, top::NSoftMuonSelector, top::NTauSelector, top::NTauTightSelector, top::SSLeptonTightSelector, top::NVarRCJetSelector, top::SSLeptonSelector, top::NLargeJetSelector, top::NRCJetSelector, top::NeutrinoWeighting, top::Chi2LJets, top::ParticleLevelSelector, top::RecoLevelSelector, top::Sonnenschein, top::JetNGhostSelector, top::SaveEventSelector, top::PTMaxReco, top::InitialSelector, top::KLFitterRun, top::KLFitterSelector, and top::PseudoTopRecoRun.

◆ applyParticleLevel()

virtual bool top::EventSelectorBase::applyParticleLevel ( const top::ParticleLevelEvent ) const
inlinevirtualinherited

This does stuff based on the information in a particle level event.

The idea is that you implement this to return either true or false, based on the information held within the top::ParticleLevelEvent. If this function returns true, then the event is kept, otherwise it is removed. The function has a default implementation (which returns true) because it is expected that many EventSelector objects do not operate on ParticleLevelEvent objects.

Parameters
top::ParticleLevelEventthe current particle level event.
trueif the event should be kept (i.e. it passed the selector criteria), false otherwise.

Reimplemented in top::JetNGhostSelector, top::PrintEventSelector, top::PseudoTopRecoRun, top::NElectronNMuonTightSelector, top::NElectronNMuonSelector, top::NFwdElectronSelector, top::HTSelector, top::OSLeptonTightSelector, top::MLLSelector, top::MWTSelector, top::NElectronTightSelector, top::NFwdElectronTightSelector, top::NMuonTightSelector, top::OSLeptonSelector, top::METMWTSelector, top::METSelector, top::MLLWindow, top::NElectronSelector, top::NJetSelector, top::NMuonSelector, top::NPhotonSelector, top::NSoftMuonSelector, top::NTauSelector, top::SSLeptonTightSelector, top::SSLeptonSelector, top::ParticleLevelSelector, top::RecoLevelSelector, top::NVarRCJetSelector, top::NLargeJetSelector, and top::NRCJetSelector.

Definition at line 73 of file EventSelectorBase.h.

73 {return true;}

◆ checkFloat()

bool top::SignValueSelector::checkFloat ( double  value,
double  cut 
) const
protected

Compare a cut supplied by the user with the value calculated in the event.

For floating point numbers.

Parameters
valueThe value from the event.
cutThe cut the user wants to apply.
Returns
True if the cut is passed.

Definition at line 133 of file SignValueSelector.cxx.

133  {
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  }

◆ checkInt()

bool top::SignValueSelector::checkInt ( int  value,
int  cut 
) const
protected

Compare a cut supplied by the user with the value calculated in the event.

For integer numbers.

Parameters
valueThe value from the event.
cutThe cut the user wants to apply.
Returns
True if the cut is passed.

Definition at line 159 of file SignValueSelector.cxx.

159  {
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  }

◆ checkMultiplicityIsInteger()

void top::SignValueSelector::checkMultiplicityIsInteger ( )
protected

Integers are annoying in C++.

Your first thought when reading in an integer is probably just to read it in with cin to an integer variable. This seems to not work, as it'll just read the integer component and ignore the rest of the string. The approach here then is to read it in as a floating point number and ask that number if it is equal to itself rounded down (integers are, fractional numbers are not)

Since the user probably didn't mean to cut on njets >= 2.3 we should interrupt the job and print a useful error message if it doesn't work.

Definition at line 82 of file SignValueSelector.cxx.

82  {
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  }

◆ checkValueIsInteger()

void top::SignValueSelector::checkValueIsInteger ( )
protected

Integers are annoying in C++.

Mostly used by the NLargeJet selectors.

Definition at line 74 of file SignValueSelector.cxx.

74  {
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  }

◆ decodesign()

SignValueSelector::Sign top::SignValueSelector::decodesign ( std::string &  params)
protected

Take the string params, look for one of the allowed inequalities (or equality) and return that.

It also removes the text from the string so the string can then be passed on to some code to extract the numerical value.

Parameters
paramsThe string that contains something like ">= 2". It will return the " 2" via the params parameter.
Returns
For the above example, the sign ">=" will be configured.

Definition at line 110 of file SignValueSelector.cxx.

110  {
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  }

◆ multiplicity()

double top::SignValueSelector::multiplicity ( ) const
protected

Get the cut multiplicity assigned in the constructor.

This is used for cuts that take a value and a multiplicity, for example EL_N 25000 >= 2 means at least two electrons with pT > 25 GeV. You can chain these together to make non-symmetric cuts. For example EL_N 25000 >= 2 EL_N 40000 >= 1

Returns
The multiplicity is actually integer, but it's stored in a double so that we can check it's an integer when we read it in.

Definition at line 106 of file SignValueSelector.cxx.

106  {
107  return m_multiplicity;
108  }

◆ name()

std::string top::SignValueSelector::name ( ) const
overridevirtual

The name is generated in the constructor for this kind of tool.

Implements top::EventSelectorBase.

Reimplemented in top::JetNGhostSelector.

Definition at line 70 of file SignValueSelector.cxx.

70  {
71  return m_name;
72  }

◆ sign()

SignValueSelector::Sign top::SignValueSelector::sign ( ) const
protected

Get the sign setup in the constructor.

Definition at line 90 of file SignValueSelector.cxx.

90  {
91  return m_sign;
92  }

◆ signstring()

const std::string top::SignValueSelector::signstring ( ) const
protected

Convert the sign enum back to a string for use in the name and print outs.

Returns
A short string version of the name

Definition at line 184 of file SignValueSelector.cxx.

184  {
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  }

◆ value()

double top::SignValueSelector::value ( ) const
protected

Get the cut value assigned in the constructor.

Definition at line 94 of file SignValueSelector.cxx.

94  {
95  return m_cutvalue;
96  }

◆ valueString()

std::string top::SignValueSelector::valueString ( ) const
protected

Get the cut value assigned in the constructor.

This is for when the cut is a string

Definition at line 98 of file SignValueSelector.cxx.

98  {
99  return m_cutvalueString;
100  }

◆ valueStringDelimReplace()

std::string top::SignValueSelector::valueStringDelimReplace ( ) const
protected

valueString which is manipulated to replace delimiter with new string

Definition at line 102 of file SignValueSelector.cxx.

102  {
104  }

Member Data Documentation

◆ m_cutvalue

double top::SignValueSelector::m_cutvalue
private

The value of the cut, filled by the constructor.

Definition at line 174 of file SignValueSelector.h.

◆ m_cutvalueString

std::string top::SignValueSelector::m_cutvalueString
private

The value of the cut in the case it's a string, filled by the constructor.

Definition at line 177 of file SignValueSelector.h.

◆ m_cutvalueStringDelimReplace

std::string top::SignValueSelector::m_cutvalueStringDelimReplace
private

The value of the cut when it is a string, with replacement of delimiter with a replacement substring.

Definition at line 183 of file SignValueSelector.h.

◆ m_multiplicity

double top::SignValueSelector::m_multiplicity
private

The multiplicity for cuts that take both a value and a multiplicity e.g. EL_N 25000 >= 2.

Definition at line 180 of file SignValueSelector.h.

◆ m_name

std::string top::SignValueSelector::m_name
private

Hold the name of the tool, filled by the constructor.

Definition at line 168 of file SignValueSelector.h.

◆ m_sign

Sign top::SignValueSelector::m_sign
private

The sign of the cut, filled by the constructor.

Definition at line 171 of file SignValueSelector.h.


The documentation for this class was generated from the following files:
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
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
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
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
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
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::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
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
PhysDESDM_SmpMs.cutString
string cutString
Definition: PhysDESDM_SmpMs.py:51
PowhegControl_ttFCNC_NLO.params
params
Definition: PowhegControl_ttFCNC_NLO.py:226
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