Belle II Software development
NeuroTriggerParameters.h
1
2/**************************************************************************
3 * basf2 (Belle II Analysis Software Framework) *
4 * Author: The Belle II Collaboration *
5 * *
6 * See git log for contributors and copyright holders. *
7 * This file is licensed under LGPL-3.0, see LICENSE.md. *
8 **************************************************************************/
9#pragma once
10#include <iostream>
11#include <TObject.h>
12
13
14namespace Belle2 {
23 template <class T>
24 class NNTParam {
27 public:
30 NNTParam(const T& xvalue)
31 {
32 m_value = xvalue;
33 m_set = true;
34 }
36 operator T() const { return m_value;}
37
39 T operator= (const T t)
40 {
41 if (!m_locked) {
42 m_value = t;
43 m_set = true;
44 } else {
45 throw std::invalid_argument("parameter is read only! (locked)");
46 }
47 return *this;
48 }
49
51 NNTParam operator()() const {return m_value;}
52
53
55 bool isSet() const {return m_set;}
57 void lock() {m_locked = true;}
59 bool isLocked() const {return m_locked;}
60
61 private:
64 /* saves the "set" state */
65 bool m_set = false;
67 bool m_locked = false;
68 };
69
70 class NeuroTriggerParameters : public TObject {
71 public:
73 NeuroTriggerParameters(std::string& filename);
74 virtual ~NeuroTriggerParameters() {};
75 // unfortunately i am too dumb to make the typewrapper class work for strings,
76 // so the workaround are those translate functions
77 int to_intTiming(const std::string& text) const
78 {
79 if (text == "fastestpriority") {return 0;}
80 else if (text == "fastest2d") {return 1;}
81 else if (text == "etf") {return 2;}
82 else if (text == "etf_or_fastestpriority") {return 3;}
83 else if (text == "etf_or_fastest2d") {return 4;}
84 else if (text == "etf_only") {return 5;}
85 else if (text == "etfcc") {return 6;}
86 else if (text == "etfhwin") {return 7;}
87 else if (text == "etfcc_or_fastestpriority") {return 8;}
88 else if (text == "min_etf_fastestpriority") {return 9;}
89 else if (text == "min_etfcc_fastestpriority") {return 10;}
90 else {return -1;}
91 }
92 const std::string to_strTiming(const unsigned& i) const
93 {
94 if (i == 0) {return "fastestpriority";}
95 else if (i == 1) {return "fastest2d";}
96 else if (i == 2) {return "etf";}
97 else if (i == 3) {return "etf_or_fastestpriority";}
98 else if (i == 4) {return "etf_or_fastest2d";}
99 else if (i == 5) {return "etf_only";}
100 else if (i == 6) {return "etfcc";}
101 else if (i == 7) {return "etfhwin";}
102 else if (i == 8) {return "etfcc_or_fastestpriority";}
103 else if (i == 9) {return "min_etf_fastestpriority";}
104 else if (i == 10) {return "min_etfcc_fastestpriority";}
105 else {return "invalid";}
106 }
107
108
110 const std::string et_option() const {return to_strTiming(ETOption);}
112 void loadconfigtxt(const std::string& filename);
114 void saveconfigtxt(const std::string& filename);
116 template<typename X>
117 std::string print2dArray(const std::string& name, std::vector<std::vector<NNTParam<X>>> vecvec);
119 template<typename X>
120 std::string print1dArray(const std::string& name, std::vector<NNTParam<X>> vecvec);
125 template<typename X>
126 std::vector<std::vector<X>> tcastvector(const std::vector<std::vector<NNTParam<X>>> vec) const
127 {
128 std::vector<std::vector<X>> ret;
129 for (auto x : vec) {
130 std::vector<X> line;
131 for (auto y : x) {
132 line.push_back((X) y);
133 }
134 ret.push_back(line);
135 }
136 return ret;
137 }
138
139 template<typename X>
140 std::vector<X> tcastvector(const std::vector<NNTParam<X>> vec) const
141 {
142 std::vector<std::vector<X>> ret;
143 for (auto x : vec) {
144 ret.push_back((X) x);
145 }
146 return ret;
147 }
148
149
190
192 std::vector<std::vector<NNTParam<float>>> phiRangeUse;
194 std::vector<std::vector<NNTParam<float>>> thetaRangeUse;
196 std::vector<std::vector<NNTParam<float>>> invptRangeUse;
199 std::vector<std::vector<NNTParam<float>>> phiRangeTrain;
202 std::vector<std::vector<NNTParam<float>>> thetaRangeTrain;
205 std::vector<std::vector<NNTParam<float>>> invptRangeTrain;
210 std::vector<std::vector<NNTParam<float>>> nHidden;
212 std::vector<std::vector<NNTParam<float>>> outputScale;
214 std::vector<NNTParam<unsigned short>> maxHitsPerSL;
220 std::vector<NNTParam<unsigned long>> SLpattern;
227 std::vector<NNTParam<unsigned long>> SLpatternMask;
229 std::vector<NNTParam<unsigned>> precision;
231 std::vector<std::vector<NNTParam<float>>> IDRanges;
232 private:
234 template<typename X>
235 bool checkarr(std::vector<std::vector<NNTParam<X>>> vec);
237 template<typename X>
238 bool checkarr(std::vector<NNTParam<X>> vec);
240 template<typename X>
241 std::vector<std::vector<NNTParam<X>>> read2dArray(std::string keyx, bool locked);
243 template<typename X>
244 std::vector<NNTParam<X>> read1dArray(std::string keyx, bool locked);
245
246 };
248}
249
Class to represent a complete set to describe a Neurotrigger.
NNTParam(const T &xvalue)
copy constructor
bool isLocked() const
check, if variable was already locked and is read only now
bool isSet() const
check, if variable was already initialized
bool m_locked
saves the "locked" state
void lock()
lock the variable, to make it read only
NNTParam operator()() const
return the value of the data type this wrapper class is holding
T operator=(const T t)
assignment operator, but checks first if the variable is already locked
NNTParam()
this is a typewrapper class for the parameters for the neurotrigger.
T m_value
holding the value
std::vector< NNTParam< unsigned short > > maxHitsPerSL
Maximum number of hits in a single super layer for all networks.
std::vector< std::vector< NNTParam< float > > > invptRangeUse
Charge / Pt region for which MLP is used in 1/GeV for all networks.
std::vector< std::vector< NNTParam< float > > > thetaRangeUse
Theta region for which MLP is used in degree for all networks.
NNTParam< unsigned > nMLP
Number of networks.
std::vector< NNTParam< unsigned long > > SLpatternMask
Super layer pattern mask for which MLP is trained for all networks.
std::vector< std::vector< NNTParam< float > > > nHidden
Number of nodes in each hidden layer for all networks or factor to multiply with number of inputs.
std::vector< std::vector< NNTParam< float > > > thetaRangeTrain
Theta region for which MLP is trained in degree for all networks.
bool checkarr(std::vector< std::vector< NNTParam< X > > > vec)
check, if a vector is already set.
NNTParam< unsigned > tMax
Maximal drift time, identical for all networks.
std::vector< NNTParam< X > > read1dArray(std::string keyx, bool locked)
fill the array from a given string that looks like: [1,2,3]
std::vector< NNTParam< unsigned long > > SLpattern
Super layer pattern for which MLP is trained for all networks.
std::string print2dArray(const std::string &name, std::vector< std::vector< NNTParam< X > > > vecvec)
this is a class for piping the output of a 2d array to a string with brackets
NNTParam< bool > rescaleTarget
flag to allow for target tracks lying out of the output range to be rescaled during training.
std::vector< std::vector< NNTParam< float > > > IDRanges
relative ID range of the relevant wire IDs of the track segments that are taken into consideration wh...
NNTParam< bool > multiplyHidden
If true, multiply nHidden with number of input nodes.
NNTParam< bool > targetTheta
train theta as output
NNTParam< unsigned > nOutput
number of output nodes
std::vector< std::vector< NNTParam< float > > > phiRangeUse
Phi region for which MLP is used in degree for all networks.
NNTParam< unsigned > ETOption
Determine, how the event time should be obtained.
NNTParam< bool > targetZ
train z as output
const std::string et_option() const
return the string variant ov the et option
NNTParam< bool > cutSum
only used in the idhist module.
std::vector< std::vector< NNTParam< X > > > read2dArray(std::string keyx, bool locked)
fill the array from a given string that looks like: [[1,2],[3, 4]]
std::vector< std::vector< NNTParam< float > > > invptRangeTrain
Charge / Pt region for which MLP is trained in 1/GeV for all networks.
std::vector< std::vector< NNTParam< float > > > phiRangeTrain
Phi region for which MLP is trained in degree for all networks.
void loadconfigtxt(const std::string &filename)
load the configuration from a file
std::vector< std::vector< X > > tcastvector(const std::vector< std::vector< NNTParam< X > > > vec) const
the parameters stored in the parameterset are not advanced enough to be vectors, they can only be sin...
void saveconfigtxt(const std::string &filename)
save the configuration to a file
std::string print1dArray(const std::string &name, std::vector< NNTParam< X > > vecvec)
this is a class for piping the output of a 1d array to a string with brackets
NNTParam< double > relevantCut
only used in the idhist module.
NNTParam< unsigned > nInput
Network parameters.
std::vector< NNTParam< unsigned > > precision
precision used for the hardware simulation
std::vector< std::vector< NNTParam< float > > > outputScale
Output scale for all networks.
Abstract base class for different kinds of events.