Belle II Software  release-05-02-19
GRLNeuro.h
1 #ifndef GRLNEURO_H
2 #define GRLNEURO_H
3 
4 #include <trg/grl/dataobjects/GRLMLP.h>
5 #include <framework/datastore/StoreArray.h>
6 #include <framework/datastore/StoreObjPtr.h>
7 #include <framework/database/DBObjPtr.h>
8 //#include <trg/cdc/dbobjects/CDCTriggerNeuroConfig.h>
9 //#include <framework/dataobjects/BinnedEventT0.h>
10 
11 namespace Belle2 {
27  class GRLNeuro {
28  public:
33  struct Parameters {
39  unsigned nMLP;
44  std::vector<std::vector<float>> nHidden;
46  bool targetresult = true;
48  bool multiplyHidden = false;
50  std::vector<std::vector<float>> outputScale = {{ -1., 1.}};
51 
53  unsigned n_cdc_sector;
54  std::vector<float> i_cdc_sector;
56  unsigned n_ecl_sector;
57  std::vector<float> i_ecl_sector;
58  };
59 
61  GRLNeuro() {}
62 
64  virtual ~GRLNeuro() {}
65 
67  void initialize(const Parameters& p);
68 
73  void save(const std::string& filename, const std::string& arrayname = "MLPs");
79  bool load(const std::string& filename, const std::string& arrayname = "MLPs");
80 
83  //void setConstants();
84 
86  void setPrecision(const std::vector<unsigned>& precision) { m_precision = precision; }
87 
90  //void initializeCollections(std::string hitCollectionName, std::string eventTimeName, std::string et_option);
91 
93  GRLMLP& operator[](unsigned index) { return m_MLPs[index]; }
95  const GRLMLP& operator[](unsigned index) const { return m_MLPs[index]; }
96 
98  unsigned nSectors() const { return m_MLPs.size(); }
99 
101  void addMLP(const GRLMLP& newMLP) { m_MLPs.push_back(newMLP); }
102 
107  std::vector<float> runMLP(unsigned isector, const std::vector<float>& input);
108 
110  std::vector<float> runMLPFix(unsigned isector, const std::vector<float>& input);
111 
112  private:
114  std::vector<GRLMLP> m_MLPs = {};
122  std::vector<unsigned> m_precision;
123 
124  };
126 }
127 #endif
Belle2::GRLNeuro::Parameters::n_cdc_sector
unsigned n_cdc_sector
Number of CDC sectors.
Definition: GRLNeuro.h:53
Belle2::GRLNeuro::m_MLPs
std::vector< GRLMLP > m_MLPs
List of networks.
Definition: GRLNeuro.h:114
Belle2::GRLNeuro::Parameters::targetresult
bool targetresult
train result as output
Definition: GRLNeuro.h:46
Belle2::GRLNeuro::runMLP
std::vector< float > runMLP(unsigned isector, const std::vector< float > &input)
Run an expert MLP.
Definition: GRLNeuro.cc:106
Belle2::GRLNeuro::Parameters::multiplyHidden
bool multiplyHidden
If true, multiply nHidden with number of input nodes.
Definition: GRLNeuro.h:48
Belle2::GRLMLP
Class to keep all parameters of an expert MLP for the neuro trigger.
Definition: GRLMLP.h:13
Belle2::GRLNeuro
Class to represent the GRL Neuro.
Definition: GRLNeuro.h:27
Belle2::GRLNeuro::nSectors
unsigned nSectors() const
return number of neural networks
Definition: GRLNeuro.h:98
Belle2::GRLNeuro::Parameters::n_ecl_sector
unsigned n_ecl_sector
Number of ECL sectors.
Definition: GRLNeuro.h:56
Belle2::GRLNeuro::runMLPFix
std::vector< float > runMLPFix(unsigned isector, const std::vector< float > &input)
Run an expert MLP with fixed point arithmetic.
Definition: GRLNeuro.cc:135
Belle2::GRLNeuro::Parameters
Struct to keep neurotrigger parameters.
Definition: GRLNeuro.h:33
Belle2::GRLNeuro::operator[]
const GRLMLP & operator[](unsigned index) const
return const reference to a neural network
Definition: GRLNeuro.h:95
Belle2::GRLNeuro::Parameters::nMLP
unsigned nMLP
Number of networks.
Definition: GRLNeuro.h:39
Belle2::GRLNeuro::save
void save(const std::string &filename, const std::string &arrayname="MLPs")
Save MLPs to file.
Definition: GRLNeuro.cc:195
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::GRLNeuro::~GRLNeuro
virtual ~GRLNeuro()
Default destructor.
Definition: GRLNeuro.h:64
Belle2::GRLNeuro::Parameters::outputScale
std::vector< std::vector< float > > outputScale
Output scale for all networks.
Definition: GRLNeuro.h:50
Belle2::GRLNeuro::operator[]
GRLMLP & operator[](unsigned index)
set the hit collection and event time to required and store the hit collection name
Definition: GRLNeuro.h:93
Belle2::GRLNeuro::setPrecision
void setPrecision(const std::vector< unsigned > &precision)
Loads parameters from the geometry and precalculates some constants that will be needed.
Definition: GRLNeuro.h:86
Belle2::GRLNeuro::load
bool load(const std::string &filename, const std::string &arrayname="MLPs")
Load MLPs from file.
Belle2::GRLNeuro::GRLNeuro
GRLNeuro()
Default constructor.
Definition: GRLNeuro.h:61
Belle2::GRLNeuro::initialize
void initialize(const Parameters &p)
Set parameters and get some network independent parameters.
Definition: GRLNeuro.cc:21
Belle2::GRLNeuro::addMLP
void addMLP(const GRLMLP &newMLP)
add an MLP to the list of networks
Definition: GRLNeuro.h:101
Belle2::GRLNeuro::m_precision
std::vector< unsigned > m_precision
Fixed point precision in bit after radix point.
Definition: GRLNeuro.h:122
Belle2::GRLNeuro::Parameters::nHidden
std::vector< std::vector< float > > nHidden
Number of nodes in each hidden layer for all networks or factor to multiply with number of inputs.
Definition: GRLNeuro.h:44