ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
tauRecTools::BDTHelper Class Reference

#include <BDTHelper.h>

Inheritance diagram for tauRecTools::BDTHelper:
Collaboration diagram for tauRecTools::BDTHelper:

Public Member Functions

 BDTHelper ()
 
 ~BDTHelper ()
 
StatusCode initialize (const TString &weightFileName)
 
float getGradBoostMVA (const std::map< TString, float > &availableVariables) const
 
float getResponse (const std::map< TString, float * > &availableVariables) const
 
float getClassification (const std::map< TString, float * > &availableVariables) const
 
float getGradBoostMVA (const xAOD::TauJet &tau) const
 
MVAUtils::BDTgetBDT () const
 
void setLevel (MSG::Level lvl)
 Change the current logging level. More...
 

Private Member Functions

std::vector< TString > parseString (const TString &str, const TString &delim=",") const
 
std::vector< float > getInputVariables (const std::map< TString, float > &availableVariables) const
 
std::vector< float > getInputVariables (const std::map< TString, float * > &availableVariables) const
 
std::vector< float > getInputVariables (const xAOD::TauJet &tau) const
 
void initMessaging () const
 Initialize our message level and MessageSvc. More...
 

Private Attributes

std::unique_ptr< MVAUtils::BDTm_BDT
 
std::vector< TString > m_inputVariableNames
 
std::string m_nm
 Message source name. More...
 
boost::thread_specific_ptr< MsgStream > m_msg_tls
 MsgStream instance (a std::cout like with print-out levels) More...
 
std::atomic< IMessageSvc * > m_imsg { nullptr }
 MessageSvc pointer. More...
 
std::atomic< MSG::Level > m_lvl { MSG::NIL }
 Current logging level. More...
 
std::atomic_flag m_initialized ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
 Messaging initialized (initMessaging) More...
 

Detailed Description

Definition at line 16 of file BDTHelper.h.

Constructor & Destructor Documentation

◆ BDTHelper()

tauRecTools::BDTHelper::BDTHelper ( )

Definition at line 14 of file BDTHelper.cxx.

14  :
15  asg::AsgMessaging("BDTHelper"),
16  m_BDT(nullptr) {
17 }

◆ ~BDTHelper()

tauRecTools::BDTHelper::~BDTHelper ( )

Definition at line 21 of file BDTHelper.cxx.

21  {
22 }

Member Function Documentation

◆ getBDT()

MVAUtils::BDT* tauRecTools::BDTHelper::getBDT ( ) const
inline

Definition at line 31 of file BDTHelper.h.

31 { return m_BDT.get(); }

◆ getClassification()

float tauRecTools::BDTHelper::getClassification ( const std::map< TString, float * > &  availableVariables) const

Definition at line 162 of file BDTHelper.cxx.

162  {
163  std::vector<float> values = getInputVariables(availableVariables);
164 
165  if (values.size() < m_inputVariableNames.size()) {
166  ATH_MSG_ERROR("There are missing variables when calculating the BDT score, will return -999");
167  return -999;
168  }
169  else {
170  return m_BDT->GetClassification(values);
171  }
172 }

◆ getGradBoostMVA() [1/2]

float tauRecTools::BDTHelper::getGradBoostMVA ( const std::map< TString, float > &  availableVariables) const

Definition at line 136 of file BDTHelper.cxx.

136  {
137  std::vector<float> values = getInputVariables(availableVariables);
138 
139  if (values.size() < m_inputVariableNames.size()) {
140  ATH_MSG_ERROR("There are missing variables when calculating the BDT score, will return -999");
141  return -999;
142  }
143  else {
144  return m_BDT->GetGradBoostMVA(values);
145  }
146 }

◆ getGradBoostMVA() [2/2]

float tauRecTools::BDTHelper::getGradBoostMVA ( const xAOD::TauJet tau) const

Definition at line 175 of file BDTHelper.cxx.

175  {
176  std::vector<float> values = getInputVariables(tau);
177 
178  if (values.size() < m_inputVariableNames.size()) {
179  ATH_MSG_ERROR("There are missing variables when calculating the BDT score, will return -999");
180  return -999;
181  }
182  else {
183  return m_BDT->GetGradBoostMVA(values);
184  }
185 }

◆ getInputVariables() [1/3]

std::vector< float > tauRecTools::BDTHelper::getInputVariables ( const std::map< TString, float * > &  availableVariables) const
private

Definition at line 99 of file BDTHelper.cxx.

99  {
100  std::vector<float> values;
101 
102  // sort the input variables by the order in varList (from BDT)
103  for (const TString& name : m_inputVariableNames) {
104  std::map<TString, float*>::const_iterator itr = availableVariables.find(name);
105  if(itr==availableVariables.end()) {
106  ATH_MSG_ERROR(name << " not available");
107  }
108  else {
109  values.push_back(*itr->second);
110  }
111  }
112 
113  return values;
114 }

◆ getInputVariables() [2/3]

std::vector< float > tauRecTools::BDTHelper::getInputVariables ( const std::map< TString, float > &  availableVariables) const
private

Definition at line 82 of file BDTHelper.cxx.

82  {
83  std::vector<float> values;
84 
85  // sort the input variables by the order in varList (from BDT)
86  for (const TString& name : m_inputVariableNames) {
87  std::map<TString, float>::const_iterator itr = availableVariables.find(name);
88  if(itr==availableVariables.end()) {
89  ATH_MSG_ERROR(name << " not available");
90  }
91  else {
92  values.push_back(itr->second);
93  }
94  }
95 
96  return values;
97 }

◆ getInputVariables() [3/3]

std::vector< float > tauRecTools::BDTHelper::getInputVariables ( const xAOD::TauJet tau) const
private

Definition at line 116 of file BDTHelper.cxx.

116  {
117  std::vector<float> values;
118 
119  // obtain the values of input variables by the name
120  // all the variables should be decorated to tau already
121  for (TString name : m_inputVariableNames) {
122  // remove prefix (::TauJets.centFrac -> cenFrac)
123  if(name.Index(".")>=0){
124  name = name(name.Last('.')+1, name.Length()-name.Last('.')-1);
125  }
126 
128  float value = accessor(tau);
129  values.push_back(value);
130  }
131 
132  return values;
133 }

◆ getResponse()

float tauRecTools::BDTHelper::getResponse ( const std::map< TString, float * > &  availableVariables) const

Definition at line 149 of file BDTHelper.cxx.

149  {
150  std::vector<float> values = getInputVariables(availableVariables);
151 
152  if (values.size() < m_inputVariableNames.size()) {
153  ATH_MSG_ERROR("There are missing variables when calculating the BDT score, will return -999");
154  return -999;
155  }
156  else {
157  return m_BDT->GetResponse(values);
158  }
159 }

◆ initialize()

StatusCode tauRecTools::BDTHelper::initialize ( const TString &  weightFileName)

Definition at line 26 of file BDTHelper.cxx.

26  {
27 
28  std::unique_ptr<TFile> file(TFile::Open(weightFileName));
29  if (!file) {
30  ATH_MSG_ERROR("Cannot find input BDT file: " << weightFileName);
31  return StatusCode::FAILURE;
32  }
33  ATH_MSG_INFO( "Open file: " << weightFileName);
34 
35  TTree* tree = dynamic_cast<TTree*> (file->Get("BDT"));
36  if (!tree) {
37  ATH_MSG_ERROR("Cannot find input BDT tree");
38  return StatusCode::FAILURE;
39  }
40  m_BDT = std::make_unique<MVAUtils::BDT>(tree);
41 
42  TNamed* varList = dynamic_cast<TNamed*> (file->Get("varList"));
43  if (!varList) {
44  ATH_MSG_ERROR("No variable list in file: " << weightFileName);
45  return StatusCode::FAILURE;
46  }
47  TString names = varList->GetTitle();
48  delete varList;
49 
50  // abtain the list of input variables
52 
53  file->Close();
54 
55  return StatusCode::SUCCESS;
56 }

◆ initMessaging()

void AthMessaging::initMessaging ( ) const
privateinherited

Initialize our message level and MessageSvc.

This method should only be called once.

Definition at line 39 of file AthMessaging.cxx.

40 {
42  m_lvl = m_imsg ?
43  static_cast<MSG::Level>( m_imsg.load()->outputLevel(m_nm) ) :
44  MSG::INFO;
45 }

◆ msg() [1/2]

MsgStream & asg::AsgMessaging::msg ( ) const
inherited

The standard message stream.

Returns
A reference to the default message stream of this object.

Definition at line 49 of file AsgMessaging.cxx.

49  {
50 #ifndef XAOD_STANDALONE
52 #else // not XAOD_STANDALONE
53  return m_msg;
54 #endif // not XAOD_STANDALONE
55  }

◆ msg() [2/2]

MsgStream & asg::AsgMessaging::msg ( const MSG::Level  lvl) const
inherited

The standard message stream.

Parameters
lvlThe message level to set the stream to
Returns
A reference to the default message stream, set to level "lvl"

Definition at line 57 of file AsgMessaging.cxx.

57  {
58 #ifndef XAOD_STANDALONE
60 #else // not XAOD_STANDALONE
61  m_msg << lvl;
62  return m_msg;
63 #endif // not XAOD_STANDALONE
64  }

◆ msgLvl()

bool asg::AsgMessaging::msgLvl ( const MSG::Level  lvl) const
inherited

Test the output level of the object.

Parameters
lvlThe message level to test against
Returns
boolean Indicting if messages at given level will be printed
true If messages at level "lvl" will be printed

Definition at line 41 of file AsgMessaging.cxx.

41  {
42 #ifndef XAOD_STANDALONE
43  return ::AthMessaging::msgLvl( lvl );
44 #else // not XAOD_STANDALONE
45  return m_msg.msgLevel( lvl );
46 #endif // not XAOD_STANDALONE
47  }

◆ parseString()

std::vector< TString > tauRecTools::BDTHelper::parseString ( const TString &  str,
const TString &  delim = "," 
) const
private

Definition at line 58 of file BDTHelper.cxx.

58  {
59  std::vector<TString> parsedString;
60 
61  TObjArray* objList = str.Tokenize(delim);
62  size_t arraySize = objList->GetEntries();
63 
64  // split the string with ",", and put them into a vector
65  for(size_t i = 0; i < arraySize; ++i) {
66  if (auto *str = dynamic_cast<TObjString*> (objList->At(i))) {
67  TString var = str->String();
68  var.ReplaceAll(" ", "");
69  if(var.Contains(":=")) {
70  var=var(var.Index(":=")+2, var.Length()-var.Index(":=")-2);
71  }
72  if(0==var.Length()) continue;
73  parsedString.push_back(var);
74  }
75  }
76 
77  delete objList;
78 
79  return parsedString;
80 }

◆ setLevel()

void AthMessaging::setLevel ( MSG::Level  lvl)
inherited

Change the current logging level.

Use this rather than msg().setLevel() for proper operation with MT.

Definition at line 28 of file AthMessaging.cxx.

29 {
30  m_lvl = lvl;
31 }

Member Data Documentation

◆ ATLAS_THREAD_SAFE

std::atomic_flag m_initialized AthMessaging::ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
mutableprivateinherited

Messaging initialized (initMessaging)

Definition at line 141 of file AthMessaging.h.

◆ m_BDT

std::unique_ptr<MVAUtils::BDT> tauRecTools::BDTHelper::m_BDT
private

Definition at line 42 of file BDTHelper.h.

◆ m_imsg

std::atomic<IMessageSvc*> AthMessaging::m_imsg { nullptr }
mutableprivateinherited

MessageSvc pointer.

Definition at line 135 of file AthMessaging.h.

◆ m_inputVariableNames

std::vector<TString> tauRecTools::BDTHelper::m_inputVariableNames
private

Definition at line 43 of file BDTHelper.h.

◆ m_lvl

std::atomic<MSG::Level> AthMessaging::m_lvl { MSG::NIL }
mutableprivateinherited

Current logging level.

Definition at line 138 of file AthMessaging.h.

◆ m_msg_tls

boost::thread_specific_ptr<MsgStream> AthMessaging::m_msg_tls
mutableprivateinherited

MsgStream instance (a std::cout like with print-out levels)

Definition at line 132 of file AthMessaging.h.

◆ m_nm

std::string AthMessaging::m_nm
privateinherited

Message source name.

Definition at line 129 of file AthMessaging.h.


The documentation for this class was generated from the following files:
AthMessaging::m_lvl
std::atomic< MSG::Level > m_lvl
Current logging level.
Definition: AthMessaging.h:138
beamspotnt.var
var
Definition: bin/beamspotnt.py:1394
tauRecTools::BDTHelper::m_BDT
std::unique_ptr< MVAUtils::BDT > m_BDT
Definition: BDTHelper.h:42
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
tree
TChain * tree
Definition: tile_monitor.h:30
athena.value
value
Definition: athena.py:124
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
AthMessaging::m_imsg
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
Definition: AthMessaging.h:135
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:805
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
python.subdetectors.mmg.names
names
Definition: mmg.py:8
file
TFile * file
Definition: tile_monitor.h:29
PyPoolBrowser.objList
dictionary objList
Definition: PyPoolBrowser.py:103
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
asg::AsgMessaging
Class mimicking the AthMessaging class from the offline software.
Definition: AsgMessaging.h:40
xAOD::JetAttributeAccessor::accessor
const AccessorWrapper< T > * accessor(xAOD::JetAttribute::AttributeID id)
Returns an attribute accessor corresponding to an AttributeID.
Definition: JetAccessorMap.h:26
AthMessaging::m_nm
std::string m_nm
Message source name.
Definition: AthMessaging.h:129
tauRecTools::BDTHelper::parseString
std::vector< TString > parseString(const TString &str, const TString &delim=",") const
Definition: BDTHelper.cxx:58
beamspotnt.varList
list varList
Definition: bin/beamspotnt.py:1108
str
Definition: BTagTrackIpAccessor.cxx:11
tauRecTools::BDTHelper::getInputVariables
std::vector< float > getInputVariables(const std::map< TString, float > &availableVariables) const
Definition: BDTHelper.cxx:82
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
tauRecTools::BDTHelper::m_inputVariableNames
std::vector< TString > m_inputVariableNames
Definition: BDTHelper.h:43