ATLAS Offline Software
Classes | Public Member Functions | Public Attributes | Private Types | Private Member Functions | Private Attributes | List of all members
TauGNN Class Reference

Wrapper around SaltModel to compute the output score of a model. More...

#include <TauGNN.h>

Inheritance diagram for TauGNN:
Collaboration diagram for TauGNN:

Classes

struct  Config
 

Public Member Functions

 TauGNN (const std::string &nnFile, const Config &config, bool useTRT)
 
 ~TauGNN ()
 
std::tuple< std::map< std::string, float >, std::map< std::string, std::vector< char > >, std::map< std::string, std::vector< float > > > compute (const xAOD::TauJet &tau, const std::vector< const xAOD::TauTrack * > &tracks, const std::vector< xAOD::CaloVertexedTopoCluster > &clusters) const
 
std::tuple< std::vector< float >, std::vector< float >, std::vector< float > > calculateInputVariables (const xAOD::TauJet &tau, const std::vector< const xAOD::TauTrack * > &tracks, const std::vector< xAOD::CaloVertexedTopoCluster > &clusters) const
 
const TauGNNUtils::GNNVarCalcvariable_calculator () const
 
void setLevel (MSG::Level lvl)
 Change the current logging level. More...
 

Public Attributes

FlavorTagInference::SaltModel::OutputConfig gnn_output_config
 

Private Types

using Inputs = FlavorTagInference::Inputs
 
using VariableMap = std::map< std::string, double >
 
using VectorMap = std::map< std::string, std::vector< double > >
 
using InputMap = std::map< std::string, VariableMap >
 
using InputSequenceMap = std::map< std::string, VectorMap >
 

Private Member Functions

std::vector< float > flatten (const std::vector< std::vector< float >> &mat) const
 
void initMessaging () const
 Initialize our message level and MessageSvc. More...
 

Private Attributes

std::shared_ptr< const FlavorTagInference::SaltModel > m_saltModel
 
const Config m_config
 
std::vector< std::string > m_scalar_inputs
 
std::vector< std::string > m_track_inputs
 
std::vector< std::string > m_cluster_inputs
 
std::vector< std::string > m_scalarCalc_inputs
 
std::vector< std::string > m_trackCalc_inputs
 
std::vector< std::string > m_clusterCalc_inputs
 
std::unique_ptr< TauGNNUtils::GNNVarCalcm_var_calc
 
bool m_useTRT = true
 
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

Wrapper around SaltModel to compute the output score of a model.

Configures the network and computes the network outputs given the input objects. Retrieval of input variables is handled internally.

Author
N.M. Tamir

Definition at line 36 of file TauGNN.h.

Member Typedef Documentation

◆ InputMap

using TauGNN::InputMap = std::map<std::string, VariableMap>
private

Definition at line 80 of file TauGNN.h.

◆ Inputs

Definition at line 75 of file TauGNN.h.

◆ InputSequenceMap

using TauGNN::InputSequenceMap = std::map<std::string, VectorMap>
private

Definition at line 81 of file TauGNN.h.

◆ VariableMap

using TauGNN::VariableMap = std::map<std::string, double>
private

Definition at line 77 of file TauGNN.h.

◆ VectorMap

using TauGNN::VectorMap = std::map<std::string, std::vector<double> >
private

Definition at line 78 of file TauGNN.h.

Constructor & Destructor Documentation

◆ TauGNN()

TauGNN::TauGNN ( const std::string &  nnFile,
const Config config,
bool  useTRT 
)

Definition at line 15 of file TauGNN.cxx.

15  :
16  asg::AsgMessaging("TauGNN"),
17  m_saltModel(std::make_shared<FlavorTagInference::SaltModel>(nnFile)),
18  m_config{config}, m_useTRT(useTRT)
19  {
20  //==================================================//
21  // This part is ported from FTagDiscriminant GNN.cxx//
22  //==================================================//
23 
24  // get the configuration of the model outputs
25  FlavorTagInference::SaltModel::OutputConfig gnn_output_config = m_saltModel->getOutputConfig();
26 
27  //Let's see the output!
28  for (const auto& out_node: gnn_output_config) {
29  if(out_node.type==FlavorTagInference::SaltModelOutput::OutputType::FLOAT) ATH_MSG_INFO("Found output FLOAT node named:" << out_node.name);
30  if(out_node.type==FlavorTagInference::SaltModelOutput::OutputType::VECCHAR) ATH_MSG_INFO("Found output VECCHAR node named:" << out_node.name);
31  if(out_node.type==FlavorTagInference::SaltModelOutput::OutputType::VECFLOAT) ATH_MSG_INFO("Found output VECFLOAT node named:" << out_node.name);
32  }
33 
34  //Get model config (for inputs)
35  auto graph_config = m_saltModel->getGraphConfig();
36 
37  //===================================================//
38  // This part is ported from tauRecTools TauJetRNN.cxx//
39  //===================================================//
40 
41  // Search for input layer names specified in 'config'
42  auto node_is_scalar = [&config](const FlavorTagInference::SaltModelGraphConfig::InputNodeConfig &in_node) {
43  return in_node.name == config.input_layer_scalar;
44  };
45  auto node_is_track = [&config](const FlavorTagInference::SaltModelGraphConfig::InputNodeConfig &in_node) {
46  return in_node.name == config.input_layer_tracks;
47  };
48  auto node_is_cluster = [&config](const FlavorTagInference::SaltModelGraphConfig::InputNodeConfig &in_node) {
49  return in_node.name == config.input_layer_clusters;
50  };
51 
52  auto scalar_node = std::find_if(graph_config.inputs.cbegin(),
53  graph_config.inputs.cend(),
54  node_is_scalar);
55 
56  auto track_node = std::find_if(graph_config.input_sequences.cbegin(),
57  graph_config.input_sequences.cend(),
58  node_is_track);
59 
60  auto cluster_node = std::find_if(graph_config.input_sequences.cbegin(),
61  graph_config.input_sequences.cend(),
62  node_is_cluster);
63 
64  // Check which input layers were found
65  auto has_scalar_node = scalar_node != graph_config.inputs.cend();
66  auto has_track_node = track_node != graph_config.input_sequences.cend();
67  auto has_cluster_node = cluster_node != graph_config.input_sequences.cend();
68  if(!has_scalar_node) ATH_MSG_WARNING("No scalar node with name "<<config.input_layer_scalar<<" found!");
69  if(!has_track_node) ATH_MSG_WARNING("No track node with name "<<config.input_layer_tracks<<" found!");
70  if(!has_cluster_node) ATH_MSG_WARNING("No cluster node with name "<<config.input_layer_clusters<<" found!");
71 
72  // Fill the variable names of each input layer into the corresponding vector
73  if (has_scalar_node) {
74  for (const auto &in : scalar_node->variables) {
75  std::string name = in.name;
76  m_scalarCalc_inputs.push_back(name);
77  }
78  }
79 
80  if (has_track_node) {
81  for (const auto &in : track_node->variables) {
82  std::string name = in.name;
83  m_trackCalc_inputs.push_back(name);
84  }
85  }
86 
87  if (has_cluster_node) {
88  for (const auto &in : cluster_node->variables) {
89  std::string name = in.name;
90  m_clusterCalc_inputs.push_back(name);
91  }
92  }
93  // Load the variable calculator
94  m_var_calc = std::make_unique<TauGNNUtils::GNNVarCalc>(m_useTRT);
95  ATH_MSG_INFO("TauGNN object initialized successfully!");
96 }

◆ ~TauGNN()

TauGNN::~TauGNN ( )

Definition at line 98 of file TauGNN.cxx.

98 {}

Member Function Documentation

◆ calculateInputVariables()

std::tuple< std::vector< float >, std::vector< float >, std::vector< float > > TauGNN::calculateInputVariables ( const xAOD::TauJet tau,
const std::vector< const xAOD::TauTrack * > &  tracks,
const std::vector< xAOD::CaloVertexedTopoCluster > &  clusters 
) const

Definition at line 132 of file TauGNN.cxx.

136  {
137  // Populate input (sequence) map with input variables
138  std::vector<float> tau_feats;
139  std::vector<std::vector<float>> track_feats_2d, cluster_feats_2d;
140  for (const auto &varname : m_scalarCalc_inputs) {
141  tau_feats.push_back(m_var_calc->compute(varname, tau));
142  }
143  for (const auto &varname : m_trackCalc_inputs) {
144  track_feats_2d.push_back(m_var_calc->compute(varname, tau, tracks));
145  }
146  for (const auto &varname : m_clusterCalc_inputs) {
147  cluster_feats_2d.push_back(m_var_calc->compute(varname, tau, clusters));
148  }
149  //transposing the 2d feature arrays
150  std::vector<float> track_feats = flatten(track_feats_2d);
151  std::vector<float> cluster_feats = flatten(cluster_feats_2d);
152  return std::make_tuple(tau_feats, track_feats, cluster_feats);
153 }

◆ compute()

std::tuple< std::map< std::string, float >, std::map< std::string, std::vector< char > >, std::map< std::string, std::vector< float > > > TauGNN::compute ( const xAOD::TauJet tau,
const std::vector< const xAOD::TauTrack * > &  tracks,
const std::vector< xAOD::CaloVertexedTopoCluster > &  clusters 
) const

Definition at line 104 of file TauGNN.cxx.

106  {
107  std::map<std::string, Inputs> gnn_input;
108  ATH_MSG_DEBUG("Starting compute...");
109  //Prepare input variables
110  auto [tau_feats, trk_feats, cls_feats] = calculateInputVariables(tau, tracks, clusters);
111 
112  std::vector<int64_t> tau_feats_dim = {static_cast<int64_t>(1), static_cast<int64_t>(tau_feats.size())};
113  std::vector<int64_t> trk_feats_dim = {static_cast<int64_t>(tracks.size()), static_cast<int64_t>(m_trackCalc_inputs.size())};
114  std::vector<int64_t> cls_feats_dim = {static_cast<int64_t>(clusters.size()), static_cast<int64_t>(m_clusterCalc_inputs.size())};
115 
116  Inputs tau_info (tau_feats, tau_feats_dim);
117  Inputs trk_info (trk_feats, trk_feats_dim);
118  Inputs cls_info (cls_feats, cls_feats_dim);
119 
120  gnn_input.insert({"tau_vars", tau_info});
121  gnn_input.insert({"track_vars", trk_info});
122  gnn_input.insert({"cluster_vars", cls_info});
123 
124  //RUN THE INFERENCE!!!
125  ATH_MSG_DEBUG("Prepared inputs, running inference...");
126  auto [out_f, out_vc, out_vf] = m_saltModel->runInference(gnn_input);
127  ATH_MSG_DEBUG("Finished compute!");
128  return std::make_tuple(out_f, out_vc, out_vf);
129 }

◆ flatten()

std::vector<float> TauGNN::flatten ( const std::vector< std::vector< float >> &  mat) const
inlineprivate

Definition at line 100 of file TauGNN.h.

100  {
101  std::vector<float> flat;
102  for (size_t col = 0; col < mat[0].size(); col++){
103  for (size_t row = 0; row < mat.size(); row++){
104  flat.push_back(mat[row][col]);
105  }
106  }
107  return flat;
108  };

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

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

◆ variable_calculator()

const TauGNNUtils::GNNVarCalc* TauGNN::variable_calculator ( ) const
inline

Definition at line 67 of file TauGNN.h.

67  {
68  return m_var_calc.get();
69  }

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.

◆ gnn_output_config

FlavorTagInference::SaltModel::OutputConfig TauGNN::gnn_output_config

Definition at line 72 of file TauGNN.h.

◆ m_cluster_inputs

std::vector<std::string> TauGNN::m_cluster_inputs
private

Definition at line 90 of file TauGNN.h.

◆ m_clusterCalc_inputs

std::vector<std::string> TauGNN::m_clusterCalc_inputs
private

Definition at line 94 of file TauGNN.h.

◆ m_config

const Config TauGNN::m_config
private

Definition at line 85 of file TauGNN.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_saltModel

std::shared_ptr<const FlavorTagInference::SaltModel> TauGNN::m_saltModel
private

Definition at line 84 of file TauGNN.h.

◆ m_scalar_inputs

std::vector<std::string> TauGNN::m_scalar_inputs
private

Definition at line 88 of file TauGNN.h.

◆ m_scalarCalc_inputs

std::vector<std::string> TauGNN::m_scalarCalc_inputs
private

Definition at line 92 of file TauGNN.h.

◆ m_track_inputs

std::vector<std::string> TauGNN::m_track_inputs
private

Definition at line 89 of file TauGNN.h.

◆ m_trackCalc_inputs

std::vector<std::string> TauGNN::m_trackCalc_inputs
private

Definition at line 93 of file TauGNN.h.

◆ m_useTRT

bool TauGNN::m_useTRT = true
private

Definition at line 98 of file TauGNN.h.

◆ m_var_calc

std::unique_ptr<TauGNNUtils::GNNVarCalc> TauGNN::m_var_calc
private

Definition at line 97 of file TauGNN.h.


The documentation for this class was generated from the following files:
FlavorTagInference::SaltModelOutput::OutputType::VECCHAR
@ VECCHAR
AthMessaging::m_lvl
std::atomic< MSG::Level > m_lvl
Current logging level.
Definition: AthMessaging.h:138
TauGNN::m_config
const Config m_config
Definition: TauGNN.h:85
TauGNN::m_scalarCalc_inputs
std::vector< std::string > m_scalarCalc_inputs
Definition: TauGNN.h:92
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TauGNN::m_clusterCalc_inputs
std::vector< std::string > m_clusterCalc_inputs
Definition: TauGNN.h:94
mat
GeoMaterial * mat
Definition: LArDetectorConstructionTBEC.cxx:55
python.base_data.config
config
Definition: base_data.py:20
keylayer_zslicemap.row
row
Definition: keylayer_zslicemap.py:155
TauGNN::m_useTRT
bool m_useTRT
Definition: TauGNN.h:98
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
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
FlavorTagInference::SaltModelGraphConfig::InputNodeConfig
Definition: SaltModelGraphConfig.h:22
TauGNN::gnn_output_config
FlavorTagInference::SaltModel::OutputConfig gnn_output_config
Definition: TauGNN.h:72
TauGNN::calculateInputVariables
std::tuple< std::vector< float >, std::vector< float >, std::vector< float > > calculateInputVariables(const xAOD::TauJet &tau, const std::vector< const xAOD::TauTrack * > &tracks, const std::vector< xAOD::CaloVertexedTopoCluster > &clusters) const
Definition: TauGNN.cxx:132
TauGNN::m_var_calc
std::unique_ptr< TauGNNUtils::GNNVarCalc > m_var_calc
Definition: TauGNN.h:97
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
TauGNN::m_trackCalc_inputs
std::vector< std::string > m_trackCalc_inputs
Definition: TauGNN.h:93
TauGNN::m_saltModel
std::shared_ptr< const FlavorTagInference::SaltModel > m_saltModel
Definition: TauGNN.h:84
LArG4AODNtuplePlotter.varname
def varname(hname)
Definition: LArG4AODNtuplePlotter.py:37
FlavorTagInference::SaltModelOutput::OutputType::FLOAT
@ FLOAT
TauGNN::flatten
std::vector< float > flatten(const std::vector< std::vector< float >> &mat) const
Definition: TauGNN.h:100
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
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
RunTileMonitoring.clusters
clusters
Definition: RunTileMonitoring.py:133
TauGNN::Inputs
FlavorTagInference::Inputs Inputs
Definition: TauGNN.h:75
FlavorTagInference::SaltModelOutput::OutputType::VECFLOAT
@ VECFLOAT
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7