Belle II Software  release-05-02-19
GRLNeuro Class Reference

Class to represent the GRL Neuro. More...

#include <GRLNeuro.h>

Collaboration diagram for GRLNeuro:

Classes

struct  Parameters
 Struct to keep neurotrigger parameters. More...
 

Public Member Functions

 GRLNeuro ()
 Default constructor.
 
virtual ~GRLNeuro ()
 Default destructor.
 
void initialize (const Parameters &p)
 Set parameters and get some network independent parameters.
 
void save (const std::string &filename, const std::string &arrayname="MLPs")
 Save MLPs to file. More...
 
bool load (const std::string &filename, const std::string &arrayname="MLPs")
 Load MLPs from file. More...
 
void setPrecision (const std::vector< unsigned > &precision)
 Loads parameters from the geometry and precalculates some constants that will be needed. More...
 
GRLMLPoperator[] (unsigned index)
 set the hit collection and event time to required and store the hit collection name More...
 
const GRLMLPoperator[] (unsigned index) const
 return const reference to a neural network
 
unsigned nSectors () const
 return number of neural networks
 
void addMLP (const GRLMLP &newMLP)
 add an MLP to the list of networks
 
std::vector< float > runMLP (unsigned isector, const std::vector< float > &input)
 Run an expert MLP. More...
 
std::vector< float > runMLPFix (unsigned isector, const std::vector< float > &input)
 Run an expert MLP with fixed point arithmetic.
 

Private Attributes

std::vector< GRLMLPm_MLPs = {}
 List of networks.
 
std::vector< unsigned > m_precision
 Fixed point precision in bit after radix point. More...
 

Detailed Description

Class to represent the GRL Neuro.

The Neurotrigger consists of one or several Multi Layer Perceptrons. The input values are calculated from ECLTRG cluster and a 2D track estimate. The output is a scaled estimate of the judgement.

See also
GRLNeuro Modules:
GRLTrainerModule for preparing training data and training,
GRLNeuro for loading trained networks and using them.

Definition at line 27 of file GRLNeuro.h.

Member Function Documentation

◆ load()

bool load ( const std::string &  filename,
const std::string &  arrayname = "MLPs" 
)

Load MLPs from file.

Parameters
filenamename of the TFile to read from
arraynamename of the TObjArray holding the MLPs in the file
Returns
true if the MLPs were loaded correctly

◆ operator[]()

GRLMLP& operator[] ( unsigned  index)
inline

set the hit collection and event time to required and store the hit collection name

return reference to a neural network

Definition at line 93 of file GRLNeuro.h.

93 { return m_MLPs[index]; }

◆ runMLP()

vector< float > runMLP ( unsigned  isector,
const std::vector< float > &  input 
)

Run an expert MLP.

Parameters
isectorindex of the MLP
inputvector of input values
Returns
unscaled output values (z vertex in cm and/or theta in radian)

Definition at line 106 of file GRLNeuro.cc.

107 {
108  const GRLMLP& expert = m_MLPs[isector];
109  vector<float> weights = expert.getWeights();
110  vector<float> layerinput = input;
111  vector<float> layeroutput = {};
112  unsigned iw = 0;
113  for (unsigned il = 1; il < expert.nLayers(); ++il) {
114  //add bias input
115  layerinput.push_back(1.);
116  //prepare output
117  layeroutput.clear();
118  layeroutput.assign(expert.nNodesLayer(il), 0.);
119  //loop over outputs
120  for (unsigned io = 0; io < layeroutput.size(); ++io) {
121  //loop over inputs
122  for (unsigned ii = 0; ii < layerinput.size(); ++ii) {
123  layeroutput[io] += layerinput[ii] * weights[iw++];
124  }
125  //apply activation function
126  layeroutput[io] = tanh(layeroutput[io] / 2.);
127  }
128  //output is new input
129  layerinput = layeroutput;
130  }
131  return layeroutput;
132 }

◆ save()

void save ( const std::string &  filename,
const std::string &  arrayname = "MLPs" 
)

Save MLPs to file.

Parameters
filenamename of the TFile to write to
arraynamename of the TObjArray holding the MLPs in the file

Definition at line 195 of file GRLNeuro.cc.

◆ setPrecision()

void setPrecision ( const std::vector< unsigned > &  precision)
inline

Loads parameters from the geometry and precalculates some constants that will be needed.

set fixed point precision

Definition at line 86 of file GRLNeuro.h.

Member Data Documentation

◆ m_precision

std::vector<unsigned> m_precision
private

Fixed point precision in bit after radix point.

8 values:

  • 2D track parameters: omega, phi
  • geometrical values derived from track: crossing angle, reference wire ID
  • scale factor: radian to wire ID
  • MLP values: nodes, weights, activation function LUT input (LUT output = nodes)

Definition at line 122 of file GRLNeuro.h.


The documentation for this class was generated from the following files:
Belle2::GRLNeuro::m_MLPs
std::vector< GRLMLP > m_MLPs
List of networks.
Definition: GRLNeuro.h:114
Belle2::GRLMLP
Class to keep all parameters of an expert MLP for the neuro trigger.
Definition: GRLMLP.h:13