Belle II Software  release-08-01-10
PIDNeuralNetwork.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #pragma once
10 
11 #include <analysis/dbobjects/PIDNeuralNetworkParameters.h>
12 #include <framework/database/DBObjPtr.h>
13 #include <framework/logging/Logger.h>
14 
15 #include <framework/gearbox/Const.h>
16 
17 #define FDEEP_FLOAT_TYPE float
18 #include <fdeep/fdeep.hpp>
19 
20 
21 
22 namespace Belle2 {
32 
33  public:
34 
40  m_model(nullptr)
41  {
43  };
44 
45 
49  PIDNeuralNetwork(const std::string& parameterName):
50  m_pidNeuralNetworkParametersName(parameterName),
52  m_model(nullptr)
53  {
55  }
56 
63  m_model(std::move(other.m_model))
64  {
65  }
66 
73  std::map<int, double> predict(std::vector<float> inputs) const;
74 
79  size_t getInputSize() const { return (*m_pidNeuralNetworkParametersDB)->getInputSize(); }
80 
85  size_t getInputIndex(const std::string& name) const { return (*m_pidNeuralNetworkParametersDB)->getInputIndex(name); }
86 
91  const std::vector<std::string>& getInputNames() const { return (*m_pidNeuralNetworkParametersDB)->getInputNames(); }
92 
98  const std::vector<int>& getOutputSpeciesPdg() const {return (*m_pidNeuralNetworkParametersDB)->getOutputSpeciesPdg();}
99 
105 
112  bool hasPdgCode(const int pdg, const bool throwException = false) const {return (*m_pidNeuralNetworkParametersDB)->hasPdgCode(pdg, throwException);}
113 
114  private:
115 
119  void loadParametersFromDB();
120 
121  std::string m_pidNeuralNetworkParametersName = "PIDNeuralNetworkParameters";
122  std::unique_ptr<DBObjPtr<PIDNeuralNetworkParameters>>
125  std::unique_ptr<const fdeep::model> m_model;
127  };
128 
130 } // Belle2 namespace
131 
132 
133 
134 
Class to call PID neural network.
PIDNeuralNetwork(const std::string &parameterName)
Constructor with given paramenter-set name.
size_t getInputSize() const
Get number of inputs.
PIDNeuralNetwork()
Constructor with default paramenter-set name.
size_t getInputIndex(const std::string &name) const
Get input names.
std::string m_pidNeuralNetworkParametersName
name of the parameter set
void loadParametersFromDB()
Load neural-network parameters with name m_pidNeuralNetworkParametersName from the conditions data ba...
std::map< int, double > predict(std::vector< float > inputs) const
Predict neural-network output for all implemented hypotheses using the given inputs.
const std::vector< int > & getOutputSpeciesPdg() const
Get the list of pdg codes of species hypotheses, for which the network predicts the probability in th...
bool hasPdgCode(const int pdg, const bool throwException=false) const
const std::string & getPIDNeuralNetworkParametersName() const
Get the name of the used neural network.
std::unique_ptr< const fdeep::model > m_model
frugally-deep neural network
const std::vector< std::string > & getInputNames() const
Get input names.
PIDNeuralNetwork(PIDNeuralNetwork &&other)
Move constructor.
std::unique_ptr< DBObjPtr< PIDNeuralNetworkParameters > > m_pidNeuralNetworkParametersDB
db object for the parameter set
Abstract base class for different kinds of events.