Belle II Software development
CDCTriggerMLP.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#ifndef CDCTRIGGERMLP_H
9#define CDCTRIGGERMLP_H
10
11#include <TObject.h>
12#include <framework/logging/Logger.h>
13
14namespace Belle2 {
20 class CDCTriggerMLP : public TObject {
21
22 // weights etc. are set only by the trainer
23 friend class CDCTriggerNeuroTrainerModule;
24 friend class NeuroTrigger;
25
26 public:
29
31 CDCTriggerMLP(std::vector<unsigned short>& nodes,
32 unsigned short targets,
33 std::vector<float>& outputscale,
34 std::vector<float>& phirangeUse,
35 std::vector<float>& invptrangeUse,
36 std::vector<float>& thetarangeUse,
37 std::vector<float>& phirangeTrain,
38 std::vector<float>& invptrangeTrain,
39 std::vector<float>& thetarangeTrain,
40 unsigned short maxHits,
41 unsigned long pattern,
42 unsigned long patternMask,
43 unsigned short tmax,
44 const std::string& etoption);
45
48
50 bool isTrained() const { return trained; }
52 unsigned nLayers() const { return nNodes.size(); }
54 unsigned nNodesLayer(unsigned iLayer) const { return nNodes[iLayer]; }
56 unsigned nWeights() const { return weights.size(); }
58 unsigned nWeightsCal() const;
60 std::vector<float> getWeights() const { return weights; }
62 void setWeights(std::vector<float> xweights) {weights = xweights; }
64 unsigned short getMaxHitsPerSL() const { return maxHitsPerSL; }
66 unsigned long getSLpattern() const { return SLpattern & SLpatternMask; }
68 unsigned long getSLpatternMask() const { return SLpatternMask; }
70 unsigned long getSLpatternUnmasked() const { return SLpattern; }
72 unsigned short getTMax() const { return tMax; }
74 std::vector<float> getIDRange(unsigned iSL) const
75 {
76 return {relevantID[2 * iSL], relevantID[2 * iSL + 1]};
77 }
79 void setRelID(std::vector<float> relid) {relevantID = relid;}
80 std::vector<float> getRelID() const {return relevantID;}
82 std::string get_et_option() const { return et_option; }
83
85 bool inPhiRangeUse(float phi) const;
87 bool inPtRangeUse(float pt) const;
89 bool inInvptRangeUse(float invpt) const;
91 bool inThetaRangeUse(float theta) const;
93 bool inPhiRangeTrain(float phi) const;
95 bool inPtRangeTrain(float pt) const;
97 bool inInvptRangeTrain(float invpt) const;
99 bool inThetaRangeTrain(float theta) const;
101 bool isRelevant(float relId, unsigned iSL) const;
102
105 float scaleId(double relId, unsigned iSL) const;
107 std::vector<float> scaleTarget(std::vector<float> target) const;
109 std::vector<float> unscaleTarget(std::vector<float> target) const;
110
112 int zIndex() const;
114 int thetaIndex() const;
115
116 private:
118 std::vector<unsigned short> nNodes;
120 std::vector<float> weights;
124
126 unsigned short targetVars;
129 std::vector<float> outputScale;
130
133 std::vector<float> phiRangeUse;
137 std::vector<float> invptRangeUse;
139 std::vector<float> thetaRangeUse;
142 std::vector<float> phiRangeTrain;
146 std::vector<float> invptRangeTrain;
148 std::vector<float> thetaRangeTrain;
149
151 unsigned short maxHitsPerSL;
155 unsigned long SLpattern;
159 unsigned long SLpatternMask;
160
162 unsigned short tMax;
166 std::vector<float> relevantID;
167
182 std::string et_option;
183
186 };
188}
189#endif
Class to keep all parameters of an expert MLP for the neuro trigger.
Definition: CDCTriggerMLP.h:20
unsigned nWeightsCal() const
calculate number of weights from number of nodes
~CDCTriggerMLP()
destructor, empty because we don't allocate memory anywhere.
Definition: CDCTriggerMLP.h:47
unsigned short tMax
Maximal drift time (for scaling), hits with larger values are ignored.
std::vector< unsigned short > nNodes
Number of nodes in each layer, not including bias nodes.
void setRelID(std::vector< float > relid)
set and get total relevant ID range
Definition: CDCTriggerMLP.h:79
std::vector< float > phiRangeUse
Phi region in radian for which this expert is used.
std::vector< float > unscaleTarget(std::vector< float > target) const
scale target value from [-1, 1] to outputScale
CDCTriggerMLP()
default constructor.
bool isTrained() const
check if weights are default values or set by some trainer
Definition: CDCTriggerMLP.h:50
std::string get_et_option() const
Returns way of obtaining the event time.
Definition: CDCTriggerMLP.h:82
std::vector< float > invptRangeTrain
Charge / Pt region in 1/GeV for which this expert is trained.
unsigned long getSLpatternMask() const
get bitmask for super layer pattern
Definition: CDCTriggerMLP.h:68
unsigned long getSLpatternUnmasked() const
get raw super layer pattern
Definition: CDCTriggerMLP.h:70
ClassDef(CDCTriggerMLP, 11)
Needed to make the ROOT object storable.
std::vector< float > scaleTarget(std::vector< float > target) const
scale target value from outputScale to [-1, 1]
std::vector< float > outputScale
Output[i] of the MLP is scaled from [-1, 1] to [outputScale[2i], outputScale[2i+1]].
unsigned short getTMax() const
get maximal drift time
Definition: CDCTriggerMLP.h:72
bool inThetaRangeTrain(float theta) const
check whether given theta value is in training sector
std::vector< float > relevantID
Hits must be within ID region around 2D track to be used as input.
unsigned long SLpatternMask
Bitmask for comparing the super layer pattern.
std::vector< float > thetaRangeUse
Theta region in radian for which this expert is trained.
bool inPtRangeTrain(float pt) const
check whether given pt value is in training sector
float scaleId(double relId, unsigned iSL) const
scale relative TS ID from relevant range to approximately [-1, 1] (to facilitate the FPGA implementat...
bool inInvptRangeUse(float invpt) const
check whether given 1/pt value is in sector
bool isRelevant(float relId, unsigned iSL) const
check whether given relative TS ID is in relevant range
unsigned short targetVars
output variables: 1: z, 2: theta, 3: (z, theta)
std::vector< float > weights
Weights of the network.
bool inPhiRangeUse(float phi) const
check whether given phi value is in sector
void setWeights(std::vector< float > xweights)
set weights vector
Definition: CDCTriggerMLP.h:62
unsigned nLayers() const
get number of layers
Definition: CDCTriggerMLP.h:52
std::vector< float > phiRangeTrain
Phi region in radian for which this expert is used.
unsigned short maxHitsPerSL
Maximum number of inputs for a single super layer.
std::string et_option
Returns way of obtaining the event time.
std::vector< float > thetaRangeTrain
Theta region in radian for which this expert is trained.
std::vector< float > invptRangeUse
Charge / Pt region in 1/GeV for which this expert is used.
bool inInvptRangeTrain(float invpt) const
check whether given 1/pt value is in training sector
std::vector< float > getIDRange(unsigned iSL) const
get relevant ID range for given super layer
Definition: CDCTriggerMLP.h:74
bool inThetaRangeUse(float theta) const
check whether given theta value is in sector
bool inPtRangeUse(float pt) const
check whether given pt value is in sector
unsigned long getSLpattern() const
get super layer pattern
Definition: CDCTriggerMLP.h:66
unsigned nWeights() const
get number of weights from length of weights vector
Definition: CDCTriggerMLP.h:56
bool trained
Indicator whether the weights are just default values or have been set by some trainer (set to true w...
unsigned short getMaxHitsPerSL() const
get maximum hit number for a single super layer
Definition: CDCTriggerMLP.h:64
std::vector< float > getWeights() const
get weights vector
Definition: CDCTriggerMLP.h:60
int thetaIndex() const
get target index for theta (-1 if no output is trained for theta)
int zIndex() const
get target index for z (-1 if no output is trained for z)
unsigned long SLpattern
Super layer pattern for which this expert is trained.
bool inPhiRangeTrain(float phi) const
check whether given phi value is in training sector
unsigned nNodesLayer(unsigned iLayer) const
get number of nodes in a layer
Definition: CDCTriggerMLP.h:54
Class to represent the CDC Neurotrigger.
Definition: NeuroTrigger.h:40
Abstract base class for different kinds of events.