ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Ringer::onnx::RingerSelector Class Reference

#include <RingerSelector.h>

Inheritance diagram for Ringer::onnx::RingerSelector:
Collaboration diagram for Ringer::onnx::RingerSelector:

Public Member Functions

 RingerSelector (const std::string &name)
 Standard constructor. More...
 
 ~RingerSelector ()=default
 Standard destructor. More...
 
StatusCode read_from (const std::string &, AthOnnx::IOnnxRuntimeSvc *)
 read tunings from configuration file More...
 
std::vector< std::vector< float > > prepare_inputs (unsigned barcode, const xAOD::TrigRingerRings *, const xAOD::TrigElectron *) const
 prepare all inputs More...
 
float predict (const xAOD::TrigRingerRings *, const xAOD::TrigElectron *) const
 Calculation of model output. More...
 
bool accept (const xAOD::TrigRingerRings *, float discr, float mu) const
 Accept method. More...
 
void setLevel (MSG::Level lvl)
 Change the current logging level. More...
 

Private Member Functions

template<typename T >
bool strtof (const std::string &input, T &f)
 parse tenv string into list with type T More...
 
template<typename T >
std::vector< T > GetValues (const std::string &input, TEnv &env)
 Get the list of values inside of tenv. More...
 
std::vector< std::string > GetPaths (const std::string &input, TEnv &env)
 Get the list of paths inside of tenv. More...
 
std::string GetBasePath (const std::string &path) const
 Get basepath from calib path. More...
 
void initMessaging () const
 Initialize our message level and MessageSvc. More...
 

Private Attributes

std::vector< Ringer::onnx::Modelm_models
 hold all onnx sessions More...
 
std::vector< Ringer::onnx::Thresholdm_thresholds
 hold all thresholds definitions More...
 
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 27 of file RingerSelector.h.

Constructor & Destructor Documentation

◆ RingerSelector()

Ringer::onnx::RingerSelector::RingerSelector ( const std::string &  name)

Standard constructor.

Definition at line 20 of file RingerSelector.cxx.

20  :
22  {;}

◆ ~RingerSelector()

Ringer::onnx::RingerSelector::~RingerSelector ( )
default

Standard destructor.

Member Function Documentation

◆ accept()

bool Ringer::onnx::RingerSelector::accept ( const xAOD::TrigRingerRings ringsCluster,
float  discr,
float  mu 
) const

Accept method.

Definition at line 109 of file RingerSelector.cxx.

110  {
111  float et = ringsCluster->emCluster()->et();
112  float eta = std::abs(ringsCluster->emCluster()->eta());
113 
114  ATH_MSG_DEBUG( "Event et = "<< et << ", eta = " << eta );
115  for( auto& cutDef : m_thresholds ){
116  if ( et < cutDef.etMin()*Gaudi::Units::GeV || et >= cutDef.etMax()*Gaudi::Units::GeV ) continue;
117  if ( eta < cutDef.etaMin() || eta >= cutDef.etaMax() ) continue;
118  return cutDef.accept( discr, avgmu );
119  }// loop over all thresholds
120 
121  return false;
122  }

◆ GetBasePath()

std::string Ringer::onnx::RingerSelector::GetBasePath ( const std::string &  path) const
private

Get basepath from calib path.

Definition at line 286 of file RingerSelector.cxx.

286  {
287  // Get the normalized parent path
288  std::string ret = std::filesystem::path(path).parent_path().lexically_normal().string();
289  if (!ret.empty() && ret.front()=='/') ret.erase(0, 1);
290  return ret;
291  }

◆ GetPaths()

std::vector< std::string > Ringer::onnx::RingerSelector::GetPaths ( const std::string &  input,
TEnv &  env 
)
private

Get the list of paths inside of tenv.

Definition at line 269 of file RingerSelector.cxx.

270  {
271  std::vector<std::string> CutVector;
272  std::string env_input(env.GetValue(input.c_str(), ""));
273  if (!env_input.empty()) {
274  std::string::size_type end;
275  do {
276  end = env_input.find(';');
277  CutVector.push_back( env_input.substr(0,end) );
278  if (end != std::string::npos) {
279  env_input= env_input.substr(end+2);
280  }
281  } while (end != std::string::npos);
282  }
283  return CutVector;
284  }

◆ GetValues()

template<typename T >
std::vector< T > Ringer::onnx::RingerSelector::GetValues ( const std::string &  input,
TEnv &  env 
)
private

Get the list of values inside of tenv.

Definition at line 247 of file RingerSelector.cxx.

248  {
249  std::vector<T> CutVector;
250  std::string env_input(env.GetValue(input.c_str(), ""));
251  if (!env_input.empty()) {
252  std::string::size_type end;
253  do {
254  end = env_input.find(';');
255  T myValue(0);
256  if(strtof(env_input.substr(0,end),myValue)){
257  CutVector.push_back(myValue);
258  }
259  if (end != std::string::npos) {
260  env_input= env_input.substr(end+1);
261  }
262  } while (end != std::string::npos);
263  }
264  return CutVector;
265  }

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

◆ predict()

float Ringer::onnx::RingerSelector::predict ( const xAOD::TrigRingerRings ringsCluster,
const xAOD::TrigElectron el 
) const

Calculation of model output.

Definition at line 126 of file RingerSelector.cxx.

127  {
128  float et = ringsCluster->emCluster()->et();
129  float eta = std::abs(ringsCluster->emCluster()->eta());
130 
131  // Find the correct model and predict
132  for( auto& model : m_models ){
133 
134  if(et<model.etMin()*Gaudi::Units::GeV || et >= model.etMax()*Gaudi::Units::GeV ) continue;
135  if(eta<model.etaMin() || eta >= model.etaMax()) continue;
136  auto inputs = prepare_inputs( model.barcode(), ringsCluster, el );
137  auto output = model.predict( inputs ); // propagate the input throut the model
138  ATH_MSG_DEBUG( "The current model predict with output: " << output );
139  return output;
140  }
141 
142  ATH_MSG_DEBUG("There is no model available for this cluster.");
143  return -999;
144  }

◆ prepare_inputs()

std::vector< std::vector< float > > Ringer::onnx::RingerSelector::prepare_inputs ( unsigned  barcode,
const xAOD::TrigRingerRings ringsCluster,
const xAOD::TrigElectron  
) const

prepare all inputs

Definition at line 151 of file RingerSelector.cxx.

154  {
155  std::vector< std::vector< float > > inputs;
156 
157  // Barcode 0 for all rings normalized by the total energy
158  if ( PreprocessingMode == 0 ){
159  const std::vector<float> rings = ringsCluster->rings();
160  std::vector<float> refRings(rings.size());
161  refRings.assign(rings.begin(), rings.end());
162  float energy=0.0;
163  for(auto &ring : refRings ) energy+=ring;
164 
165  if (energy > 0){
166  for(auto &ring : refRings ) ring/=energy;
167  }
168 
169  inputs.push_back( refRings );
170 
171  // Barcode 1 for half rings normalized by the total energy
172  }else if ( PreprocessingMode == 1){
173 
174  const std::vector<float> rings = ringsCluster->rings();
175  std::vector<float> refRings(rings.size());
176  refRings.assign(rings.begin(), rings.end());
177 
178  std::vector<float> halfRings;
179 
180  constexpr int PS = 8;
181  constexpr int EM1 = 64;
182  constexpr int EM2 = 8;
183  constexpr int EM3 = 8;
184  constexpr int HAD1 = 4;
185  constexpr int HAD2 = 4;
186  constexpr int HAD3 = 4;
187 
188  halfRings.insert(halfRings.end(), refRings.begin(), refRings.begin() + PS/2);
189  halfRings.insert(halfRings.end(), refRings.begin() + PS, refRings.begin() + PS + (EM1/2));
190  halfRings.insert(halfRings.end(), refRings.begin() + PS + EM1, refRings.begin() + PS + EM1 + (EM2/2));
191  halfRings.insert(halfRings.end(), refRings.begin() + PS + EM1 + EM2, refRings.begin() + PS + EM1 + EM2 + (EM3/2));
192  halfRings.insert(halfRings.end(), refRings.begin() + PS + EM1 + EM2 + EM3, refRings.begin() + PS + EM1 + EM2 + EM3 + (HAD1/2));
193  halfRings.insert(halfRings.end(), refRings.begin() + PS + EM1 + EM2 + EM3 + HAD1, refRings.begin() + PS + EM1 + EM2 + EM3 + HAD1 + (HAD2/2));
194  halfRings.insert(halfRings.end(), refRings.begin() + PS + EM1 + EM2 + EM3 + HAD1 + HAD2, refRings.begin() + PS + EM1 + EM2 + EM3 + HAD1 + HAD2 + (HAD3/2));
195 
196  // concatenate
197  float energy=0.0;
198  for(auto &ring : halfRings ) energy+=ring;
199 
200  if (energy > 0){
201  for(auto &ring : halfRings ) ring/=energy;
202  }
203 
204  inputs.push_back( halfRings );
205  }
206 
207  return inputs;
208  }

◆ read_from()

StatusCode Ringer::onnx::RingerSelector::read_from ( const std::string &  path,
AthOnnx::IOnnxRuntimeSvc svc 
)

read tunings from configuration file

Definition at line 26 of file RingerSelector.cxx.

27  {
28 
29  std::string configFile = PathResolverFindCalibFile( path );
30  std::string basepath = GetBasePath( path );
31 
32  ATH_MSG_INFO( "Loading all tunings configs from " << configFile );
33  ATH_MSG_INFO( "Basepath is "<< basepath);
34 
35  if (configFile.empty()){
36  ATH_MSG_ERROR( "Could not locate the config file: " << configFile);
37  return StatusCode::FAILURE;
38  }
39 
40  // Read configuration file
41  TEnv env(configFile.c_str());
42 
43 
44  // Retrieve all models
45  {
46  // Retrieve the size
47  unsigned size = env.GetValue( "Model__size" , 0 );
48  auto PreprocessingMode = GetValues<int>( "Model__barcode", env); // select the input preprocessing mode
49 
50  // Retrieve Et bins
51  auto etmin = GetValues<float>( "Model__etmin", env );
52  auto etmax = GetValues<float>( "Model__etmax", env );
53 
54  // Retrieve Eta bins
55  auto etamin = GetValues<float>( "Model__etamin", env );
56  auto etamax = GetValues<float>( "Model__etamax", env );
57 
58  // Retreive all ONNX model file paths
59  auto model_paths = GetPaths( "Model__path", env );
60 
61  // Loop over all models
62  for ( unsigned idx = 0; idx < size; ++idx )
63  {
64  std::string modelPath = PathResolverFindCalibFile( basepath+"/"+model_paths[idx] );
65  ATH_MSG_DEBUG( "Reading Onnx model from: " << modelPath );
66  auto model = Ringer::onnx::Model( modelPath, svc, etmin[idx], etmax[idx], etamin[idx], etamax[idx], PreprocessingMode[idx]) ;
67  // Compile the model
68  model.compile();
69  m_models.push_back(model);
70  }
71  }
72 
73  // Retrieve all thresholds
74  {
75  // Retrieve the size
76  unsigned size = env.GetValue( "Threshold__size" , 0);
77  auto max_avgmu = GetValues<float>( "Threshold__MaxAverageMu", env );
78 
79  // Retrieve Et bins
80  auto etmin = GetValues<float>( "Threshold__etmin", env );
81  auto etmax = GetValues<float>( "Threshold__etmax", env );
82  // Retrieve Eta bins
83  auto etamin = GetValues<float>( "Threshold__etamin", env );
84  auto etamax = GetValues<float>( "Threshold__etamax", env );
85  // Retrieve slopes
86  auto slopes = GetValues<float>( "Threshold__slope", env );
87  // Retrieve offsets
88  auto offsets = GetValues<float>("Threshold__offset", env );
89 
90  for ( unsigned idx = 0; idx <size; ++idx ){
92  etmin[idx],
93  etmax[idx],
94  etamin[idx],
95  etamax[idx],
96  slopes[idx],
97  offsets[idx],
98  max_avgmu[idx])
99  );
100  }
101  }
102 
103  return StatusCode::SUCCESS;
104  }

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

◆ strtof()

template<typename T >
bool Ringer::onnx::RingerSelector::strtof ( const std::string &  input,
T &  f 
)
private

parse tenv string into list with type T

Definition at line 216 of file RingerSelector.cxx.

217  {
218  int diff = 0 ;
219  std::string tmp = input;
220  std::string::size_type first(0);
221  std::string::size_type last(0);
222  first = ( input.find('#') ) ;
223 
224  //if we do not find a comment character "#" we are fine
225  if (first == std::string::npos) {
226  std::istringstream buffer (tmp);
227  buffer>>f;
228  return true;
229  }
230 
231  //if we have found comment character check if it is inlined between two "#"
232  last = (input.find('#',first+1) );
233  //if nor error
234  if (last == std::string::npos) {
235  return false;
236  }
237  //else if between two "#" remove this part
238  diff = last - first ;
239  tmp= tmp.erase(first,diff+1);
240  std::istringstream buffer (tmp);
241  buffer>>f;
242  return true;
243  }

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_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_models

std::vector< Ringer::onnx::Model > Ringer::onnx::RingerSelector::m_models
private

hold all onnx sessions

Definition at line 66 of file RingerSelector.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_thresholds

std::vector< Ringer::onnx::Threshold > Ringer::onnx::RingerSelector::m_thresholds
private

hold all thresholds definitions

Definition at line 68 of file RingerSelector.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
test_pyathena.eta
eta
Definition: test_pyathena.py:10
et
Extra patterns decribing particle interation process.
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:17
Ringer::HAD2
@ HAD2
Definition: CaloRingsDefs.h:51
xAOD::TrigEMCluster_v1::eta
float eta() const
get Eta (calibrated)
taskman.configFile
configFile
Definition: taskman.py:311
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:128
Ringer::EM3
@ EM3
Definition: CaloRingsDefs.h:49
Ringer::onnx::RingerSelector::m_thresholds
std::vector< Ringer::onnx::Threshold > m_thresholds
hold all thresholds definitions
Definition: RingerSelector.h:68
Ringer::HAD3
@ HAD3
Definition: CaloRingsDefs.h:52
Ringer::HAD1
@ HAD1
Definition: CaloRingsDefs.h:50
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
xAOD::TrigRingerRings_v2::emCluster
const TrigEMCluster * emCluster() const
The associated EM cluster, as a simple pointer.
Definition: TrigRingerRings_v2.cxx:41
Ringer::EM2
@ EM2
Definition: CaloRingsDefs.h:48
xAOD::TrigRingerRings_v2::rings
const std::vector< float > & rings() const
Acessor methods.
mc.diff
diff
Definition: mc.SFGenPy8_MuMu_DD.py:14
Ringer::onnx::RingerSelector::GetBasePath
std::string GetBasePath(const std::string &path) const
Get basepath from calib path.
Definition: RingerSelector.cxx:286
Ringer::onnx::RingerSelector::strtof
bool strtof(const std::string &input, T &f)
parse tenv string into list with type T
Definition: RingerSelector.cxx:216
AthMessaging::m_imsg
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
Definition: AthMessaging.h:135
postInclude.inputs
inputs
Definition: postInclude.SortInput.py:15
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
Ringer::PS
@ PS
Definition: CaloRingsDefs.h:46
createCoolChannelIdFile.buffer
buffer
Definition: createCoolChannelIdFile.py:12
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ParticleGun_FastCalo_ChargeFlip_Config.energy
energy
Definition: ParticleGun_FastCalo_ChargeFlip_Config.py:78
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Epos_Base_Fragment.Model
Model
Definition: Epos_Base_Fragment.py:10
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
hist_file_dump.f
f
Definition: hist_file_dump.py:135
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
Ringer::onnx::Threshold
Definition: Threshold.h:14
beamspotman.basepath
string basepath
Definition: beamspotman.py:1018
merge.output
output
Definition: merge.py:17
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
Ringer::onnx::RingerSelector::GetPaths
std::vector< std::string > GetPaths(const std::string &input, TEnv &env)
Get the list of paths inside of tenv.
Definition: RingerSelector.cxx:269
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:431
Ringer::onnx::RingerSelector::m_models
std::vector< Ringer::onnx::Model > m_models
hold all onnx sessions
Definition: RingerSelector.h:66
correlationModel::model
model
Definition: AsgElectronEfficiencyCorrectionTool.cxx:46
AthMessaging::m_nm
std::string m_nm
Message source name.
Definition: AthMessaging.h:129
DeMoScan.first
bool first
Definition: DeMoScan.py:536
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
xAOD::TrigEMCluster_v1::et
float et() const
get Et (calibrated)
Ringer::onnx::RingerSelector::prepare_inputs
std::vector< std::vector< float > > prepare_inputs(unsigned barcode, const xAOD::TrigRingerRings *, const xAOD::TrigElectron *) const
prepare all inputs
Definition: RingerSelector.cxx:151
python.DataFormatRates.env
env
Definition: DataFormatRates.py:32
LArCellBinning.etamin
etamin
Definition: LArCellBinning.py:137
Ringer::EM1
@ EM1
Definition: CaloRingsDefs.h:47
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35