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
 
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
 
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 20 of file BDTHelper.cxx.

20  {
21 }

Member Function Documentation

◆ getBDT()

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

Definition at line 27 of file BDTHelper.h.

27 { return m_BDT.get(); }

◆ getGradBoostMVA()

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

Definition at line 113 of file BDTHelper.cxx.

113  {
114  std::vector<float> values = getInputVariables(availableVariables);
115 
116  if (values.size() < m_inputVariableNames.size()) {
117  ATH_MSG_ERROR("There are missing variables when calculating the BDT score, will return -999");
118  return -999;
119  }
120  else {
121  return m_BDT->GetGradBoostMVA(values);
122  }
123 }

◆ getInputVariables() [1/2]

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

Definition at line 96 of file BDTHelper.cxx.

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

◆ getInputVariables() [2/2]

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

Definition at line 79 of file BDTHelper.cxx.

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

◆ getResponse()

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

Definition at line 126 of file BDTHelper.cxx.

126  {
127  std::vector<float> values = getInputVariables(availableVariables);
128 
129  if (values.size() < m_inputVariableNames.size()) {
130  ATH_MSG_ERROR("There are missing variables when calculating the BDT score, will return -999");
131  return -999;
132  }
133  else {
134  return m_BDT->GetResponse(values);
135  }
136 }

◆ initialize()

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

Definition at line 23 of file BDTHelper.cxx.

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

◆ 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 55 of file BDTHelper.cxx.

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

◆ 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 36 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 37 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:1393
tauRecTools::BDTHelper::m_BDT
std::unique_ptr< MVAUtils::BDT > m_BDT
Definition: BDTHelper.h:36
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
tree
TChain * tree
Definition: tile_monitor.h:30
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:808
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:240
asg::AsgMessaging
Class mimicking the AthMessaging class from the offline software.
Definition: AsgMessaging.h:40
python.Constants.INFO
int INFO
Definition: Control/AthenaCommon/python/Constants.py:15
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:55
beamspotnt.varList
list varList
Definition: bin/beamspotnt.py:1107
str
Definition: BTagTrackIpAccessor.cxx:11
tauRecTools::BDTHelper::getInputVariables
std::vector< float > getInputVariables(const std::map< TString, float > &availableVariables) const
Definition: BDTHelper.cxx:79
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
tauRecTools::BDTHelper::m_inputVariableNames
std::vector< TString > m_inputVariableNames
Definition: BDTHelper.h:37