ATLAS Offline Software
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
TauGNNUtils::GNNVarCalc Class Reference

Tool to calculate input variables for the GNN-based tau identification. More...

#include <TauGNNUtils.h>

Inheritance diagram for TauGNNUtils::GNNVarCalc:
Collaboration diagram for TauGNNUtils::GNNVarCalc:

Public Types

using ScalarCalc = bool(*)(const xAOD::TauJet &, double &)
 
using TrackCalc = bool(*)(const xAOD::TauJet &, const xAOD::TauTrack &, double &)
 
using ClusterCalc = bool(*)(const xAOD::TauJet &, const xAOD::CaloVertexedTopoCluster &, double &)
 

Public Member Functions

 GNNVarCalc ()
 
 ~GNNVarCalc ()=default
 
bool compute (const std::string &name, const xAOD::TauJet &tau, double &out) const
 
bool compute (const std::string &name, const xAOD::TauJet &tau, const std::vector< const xAOD::TauTrack * > &tracks, std::vector< double > &out) const
 
bool compute (const std::string &name, const xAOD::TauJet &tau, const std::vector< xAOD::CaloVertexedTopoCluster > &clusters, std::vector< double > &out) const
 
void insert (const std::string &name, ScalarCalc func, const std::vector< std::string > &scalar_vars)
 
void insert (const std::string &name, TrackCalc func, const std::vector< std::string > &track_vars)
 
void insert (const std::string &name, ClusterCalc func, const std::vector< std::string > &cluster_vars)
 
void setLevel (MSG::Level lvl)
 Change the current logging level. More...
 

Private Member Functions

void initMessaging () const
 Initialize our message level and MessageSvc. More...
 

Private Attributes

std::unordered_map< std::string, ScalarCalcm_scalar_map
 
std::unordered_map< std::string, TrackCalcm_track_map
 
std::unordered_map< std::string, ClusterCalcm_cluster_map
 
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

Tool to calculate input variables for the GNN-based tau identification.

Used to calculate input variables for (onnx)GNN-based tau identification on the fly by providing a mapping between variable names (strings) and functions to calculate these variables.

Author
C. Deutsch
W. Davey
N.M. Tamir

Definition at line 31 of file TauGNNUtils.h.

Member Typedef Documentation

◆ ClusterCalc

Definition at line 39 of file TauGNNUtils.h.

◆ ScalarCalc

Definition at line 34 of file TauGNNUtils.h.

◆ TrackCalc

Definition at line 36 of file TauGNNUtils.h.

Constructor & Destructor Documentation

◆ GNNVarCalc()

TauGNNUtils::GNNVarCalc::GNNVarCalc ( )

Definition at line 13 of file TauGNNUtils.cxx.

13  : asg::AsgMessaging("TauGNNUtils::GNNVarCalc") {
14 }

◆ ~GNNVarCalc()

TauGNNUtils::GNNVarCalc::~GNNVarCalc ( )
default

Member Function Documentation

◆ compute() [1/3]

bool TauGNNUtils::GNNVarCalc::compute ( const std::string &  name,
const xAOD::TauJet tau,
const std::vector< const xAOD::TauTrack * > &  tracks,
std::vector< double > &  out 
) const

Definition at line 31 of file TauGNNUtils.cxx.

33  {
34  out.clear();
35  out.reserve(tracks.size());
36 
37  // Retrieve calculator function
38  TrackCalc func = nullptr;
39  try {
40  func = m_track_map.at(name);
41  } catch (const std::out_of_range &e) {
42  ATH_MSG_ERROR("Variable '" << name << "' not defined");
43  throw;
44  }
45 
46  // Calculate variables for selected tracks
47  bool success = true;
48  double value;
49  for (const auto *const trk : tracks) {
50  success = success && func(tau, *trk, value);
51  out.push_back(value);
52  }
53 
54  return success;
55 }

◆ compute() [2/3]

bool TauGNNUtils::GNNVarCalc::compute ( const std::string &  name,
const xAOD::TauJet tau,
const std::vector< xAOD::CaloVertexedTopoCluster > &  clusters,
std::vector< double > &  out 
) const

Definition at line 57 of file TauGNNUtils.cxx.

59  {
60  out.clear();
61  out.reserve(clusters.size());
62 
63  // Retrieve calculator function
64  ClusterCalc func = nullptr;
65  try {
66  func = m_cluster_map.at(name);
67  } catch (const std::out_of_range &e) {
68  ATH_MSG_ERROR("Variable '" << name << "' not defined");
69  throw;
70  }
71 
72  // Calculate variables for selected clusters
73  bool success = true;
74  double value;
75  for (const xAOD::CaloVertexedTopoCluster& cluster : clusters) {
76  success = success && func(tau, cluster, value);
77  out.push_back(value);
78  }
79 
80  return success;
81 }

◆ compute() [3/3]

bool TauGNNUtils::GNNVarCalc::compute ( const std::string &  name,
const xAOD::TauJet tau,
double &  out 
) const

Definition at line 16 of file TauGNNUtils.cxx.

17  {
18  // Retrieve calculator function
19  ScalarCalc func = nullptr;
20  try {
21  func = m_scalar_map.at(name);
22  } catch (const std::out_of_range &e) {
23  ATH_MSG_ERROR("Variable '" << name << "' not defined");
24  throw;
25  }
26 
27  // Calculate variable
28  return func(tau, out);
29 }

◆ 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 }

◆ insert() [1/3]

void TauGNNUtils::GNNVarCalc::insert ( const std::string &  name,
ClusterCalc  func,
const std::vector< std::string > &  cluster_vars 
)

Definition at line 103 of file TauGNNUtils.cxx.

103  {
104  if (std::find(cluster_vars.begin(), cluster_vars.end(), name) == cluster_vars.end()) {
105  return;
106  }
107  if (!func) {
108  throw std::invalid_argument("Nullptr passed to GNNVarCalc::insert");
109  }
110  m_cluster_map[name] = func;
111 }

◆ insert() [2/3]

void TauGNNUtils::GNNVarCalc::insert ( const std::string &  name,
ScalarCalc  func,
const std::vector< std::string > &  scalar_vars 
)

Definition at line 83 of file TauGNNUtils.cxx.

83  {
84  if (std::find(scalar_vars.begin(), scalar_vars.end(), name) == scalar_vars.end()) {
85  return;
86  }
87  if (!func) {
88  throw std::invalid_argument("Nullptr passed to GNNVarCalc::insert");
89  }
90  m_scalar_map[name] = func;
91 }

◆ insert() [3/3]

void TauGNNUtils::GNNVarCalc::insert ( const std::string &  name,
TrackCalc  func,
const std::vector< std::string > &  track_vars 
)

Definition at line 93 of file TauGNNUtils.cxx.

93  {
94  if (std::find(track_vars.begin(), track_vars.end(), name) == track_vars.end()) {
95  return;
96  }
97  if (!func) {
98  throw std::invalid_argument("Nullptr passed to GNNVarCalc::insert");
99  }
100  m_track_map[name] = func;
101 }

◆ 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  }

◆ 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_cluster_map

std::unordered_map<std::string, ClusterCalc> TauGNNUtils::GNNVarCalc::m_cluster_map
private

Definition at line 70 of file TauGNNUtils.h.

◆ m_imsg

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

MessageSvc pointer.

Definition at line 135 of file AthMessaging.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.

◆ m_scalar_map

std::unordered_map<std::string, ScalarCalc> TauGNNUtils::GNNVarCalc::m_scalar_map
private

Definition at line 68 of file TauGNNUtils.h.

◆ m_track_map

std::unordered_map<std::string, TrackCalc> TauGNNUtils::GNNVarCalc::m_track_map
private

Definition at line 69 of file TauGNNUtils.h.


The documentation for this class was generated from the following files:
TauGNNUtils::GNNVarCalc::ScalarCalc
bool(*)(const xAOD::TauJet &, double &) ScalarCalc
Definition: TauGNNUtils.h:34
AthMessaging::m_lvl
std::atomic< MSG::Level > m_lvl
Current logging level.
Definition: AthMessaging.h:138
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
athena.value
value
Definition: athena.py:124
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
TauGNNUtils::GNNVarCalc::ClusterCalc
bool(*)(const xAOD::TauJet &, const xAOD::CaloVertexedTopoCluster &, double &) ClusterCalc
Definition: TauGNNUtils.h:40
TauGNNUtils::GNNVarCalc::TrackCalc
bool(*)(const xAOD::TauJet &, const xAOD::TauTrack &, double &) TrackCalc
Definition: TauGNNUtils.h:37
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TauGNNUtils::GNNVarCalc::m_track_map
std::unordered_map< std::string, TrackCalc > m_track_map
Definition: TauGNNUtils.h:69
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
asg::AsgMessaging
Class mimicking the AthMessaging class from the offline software.
Definition: AsgMessaging.h:40
TauGNNUtils::GNNVarCalc::m_cluster_map
std::unordered_map< std::string, ClusterCalc > m_cluster_map
Definition: TauGNNUtils.h:70
TauGNNUtils::Variables::Cluster::e
bool e(const xAOD::TauJet &, const xAOD::CaloVertexedTopoCluster &cluster, double &out)
Definition: TauGNNUtils.cxx:892
AthMessaging::m_nm
std::string m_nm
Message source name.
Definition: AthMessaging.h:129
RunTileMonitoring.clusters
clusters
Definition: RunTileMonitoring.py:133
xAOD::CaloVertexedTopoCluster
Evaluate cluster kinematics with a different vertex / signal state.
Definition: Event/xAOD/xAODCaloEvent/xAODCaloEvent/CaloVertexedTopoCluster.h:38
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
TauGNNUtils::GNNVarCalc::m_scalar_map
std::unordered_map< std::string, ScalarCalc > m_scalar_map
Definition: TauGNNUtils.h:68