Belle II Software development
CDCTriggerMLP Class Reference

Class to keep all parameters of an expert MLP for the neuro trigger. More...

#include <CDCTriggerMLP.h>

Inheritance diagram for CDCTriggerMLP:

Public Member Functions

 CDCTriggerMLP ()
 default constructor.
 
 CDCTriggerMLP (std::vector< unsigned short > &nodes, unsigned short targets, std::vector< float > &outputscale, std::vector< float > &phirangeUse, std::vector< float > &invptrangeUse, std::vector< float > &thetarangeUse, std::vector< float > &phirangeTrain, std::vector< float > &invptrangeTrain, std::vector< float > &thetarangeTrain, unsigned short maxHits, unsigned long pattern, unsigned long patternMask, unsigned short tmax, const std::string &etoption)
 constructor to set all parameters (not weights and relevantID ranges).
 
 ~CDCTriggerMLP ()
 destructor, empty because we don't allocate memory anywhere.
 
bool isTrained () const
 check if weights are default values or set by some trainer
 
unsigned nLayers () const
 get number of layers
 
unsigned nNodesLayer (unsigned iLayer) const
 get number of nodes in a layer
 
unsigned nWeights () const
 get number of weights from length of weights vector
 
unsigned nWeightsCal () const
 calculate number of weights from number of nodes
 
std::vector< float > getWeights () const
 get weights vector
 
void setWeights (std::vector< float > xweights)
 set weights vector
 
unsigned short getMaxHitsPerSL () const
 get maximum hit number for a single super layer
 
unsigned long getSLpattern () const
 get super layer pattern
 
unsigned long getSLpatternMask () const
 get bitmask for super layer pattern
 
unsigned long getSLpatternUnmasked () const
 get raw super layer pattern
 
unsigned short getTMax () const
 get maximal drift time
 
std::vector< float > getIDRange (unsigned iSL) const
 get relevant ID range for given super layer
 
void setRelID (std::vector< float > relid)
 set and get total relevant ID range
 
std::vector< float > getRelID () const
 
std::string get_et_option () const
 Returns way of obtaining the event time.
 
bool inPhiRangeUse (float phi) const
 check whether given phi value is in sector
 
bool inPtRangeUse (float pt) const
 check whether given pt value is in sector
 
bool inInvptRangeUse (float invpt) const
 check whether given 1/pt value is in sector
 
bool inThetaRangeUse (float theta) const
 check whether given theta value is in sector
 
bool inPhiRangeTrain (float phi) const
 check whether given phi value is in training sector
 
bool inPtRangeTrain (float pt) const
 check whether given pt value is in training sector
 
bool inInvptRangeTrain (float invpt) const
 check whether given 1/pt value is in training sector
 
bool inThetaRangeTrain (float theta) const
 check whether given theta value is in training sector
 
bool isRelevant (float relId, unsigned iSL) const
 check whether given relative TS ID is in relevant range
 
float scaleId (double relId, unsigned iSL) const
 scale relative TS ID from relevant range to approximately [-1, 1] (to facilitate the FPGA implementation, the scale factor is rounded to a power of 2)
 
std::vector< float > scaleTarget (std::vector< float > target) const
 scale target value from outputScale to [-1, 1]
 
std::vector< float > unscaleTarget (std::vector< float > target) const
 scale target value from [-1, 1] to outputScale
 
int zIndex () const
 get target index for z (-1 if no output is trained for z)
 
int thetaIndex () const
 get target index for theta (-1 if no output is trained for theta)
 

Private Member Functions

 ClassDef (CDCTriggerMLP, 11)
 Needed to make the ROOT object storable.
 

Private Attributes

std::vector< unsigned short > nNodes
 Number of nodes in each layer, not including bias nodes.
 
std::vector< float > weights
 Weights of the network.
 
bool trained
 Indicator whether the weights are just default values or have been set by some trainer (set to true when setWeights() is first called).
 
unsigned short targetVars
 output variables: 1: z, 2: theta, 3: (z, theta)
 
std::vector< float > outputScale
 Output[i] of the MLP is scaled from [-1, 1] to [outputScale[2i], outputScale[2i+1]].
 
std::vector< float > phiRangeUse
 Phi region in radian for which this expert is used.
 
std::vector< float > invptRangeUse
 Charge / Pt region in 1/GeV for which this expert is used.
 
std::vector< float > thetaRangeUse
 Theta region in radian for which this expert is trained.
 
std::vector< float > phiRangeTrain
 Phi region in radian for which this expert is used.
 
std::vector< float > invptRangeTrain
 Charge / Pt region in 1/GeV for which this expert is trained.
 
std::vector< float > thetaRangeTrain
 Theta region in radian for which this expert is trained.
 
unsigned short maxHitsPerSL
 Maximum number of inputs for a single super layer.
 
unsigned long SLpattern
 Super layer pattern for which this expert is trained.
 
unsigned long SLpatternMask
 Bitmask for comparing the super layer pattern.
 
unsigned short tMax
 Maximal drift time (for scaling), hits with larger values are ignored.
 
std::vector< float > relevantID
 Hits must be within ID region around 2D track to be used as input.
 
std::string et_option
 Returns way of obtaining the event time.
 

Friends

class CDCTriggerNeuroTrainerModule
 
class NeuroTrigger
 

Detailed Description

Class to keep all parameters of an expert MLP for the neuro trigger.

Definition at line 20 of file CDCTriggerMLP.h.

Constructor & Destructor Documentation

◆ CDCTriggerMLP() [1/2]

default constructor.

Definition at line 13 of file CDCTriggerMLP.cc.

13 :
14 nNodes{27, 27, 2}, trained(false), targetVars(3), outputScale{ -1., 1., -1., 1.},
15 phiRangeUse{0., 2. * M_PI}, invptRangeUse{ -5., 5.}, thetaRangeUse{0., M_PI},
16 phiRangeTrain{0., 2. * M_PI}, invptRangeTrain{ -5., 5.}, thetaRangeTrain{0., M_PI},
18 relevantID{ -1., 1.,
19 -10., 1.,
20 -1., 1.,
21 -1., 10.,
22 -1., 1.,
23 -10.5, 1.,
24 -1., 1.,
25 -1., 11.,
26 -1., 1.},
27 et_option("etf_or_fastestpriority")
28{
29 weights.assign(nWeightsCal(), 0.);
30}
unsigned nWeightsCal() const
calculate number of weights from number of nodes
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.
std::vector< float > phiRangeUse
Phi region in radian for which this expert is used.
std::vector< float > invptRangeTrain
Charge / Pt region in 1/GeV for which this expert is trained.
std::vector< float > outputScale
Output[i] of the MLP is scaled from [-1, 1] to [outputScale[2i], outputScale[2i+1]].
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.
unsigned short targetVars
output variables: 1: z, 2: theta, 3: (z, theta)
std::vector< float > weights
Weights of the network.
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 trained
Indicator whether the weights are just default values or have been set by some trainer (set to true w...
unsigned long SLpattern
Super layer pattern for which this expert is trained.

◆ CDCTriggerMLP() [2/2]

CDCTriggerMLP ( std::vector< unsigned short > &  nodes,
unsigned short  targets,
std::vector< float > &  outputscale,
std::vector< float > &  phirangeUse,
std::vector< float > &  invptrangeUse,
std::vector< float > &  thetarangeUse,
std::vector< float > &  phirangeTrain,
std::vector< float > &  invptrangeTrain,
std::vector< float > &  thetarangeTrain,
unsigned short  maxHits,
unsigned long  pattern,
unsigned long  patternMask,
unsigned short  tmax,
const std::string &  etoption 
)

constructor to set all parameters (not weights and relevantID ranges).

Definition at line 32 of file CDCTriggerMLP.cc.

45 :
46 nNodes(nodes), trained(false), targetVars(targets), outputScale(outputscale),
47 phiRangeUse(phirangeUse), invptRangeUse(invptrangeUse), thetaRangeUse(thetarangeUse),
48 phiRangeTrain(phirangeTrain), invptRangeTrain(invptrangeTrain), thetaRangeTrain(thetarangeTrain),
49 maxHitsPerSL(maxHits), SLpattern(pattern), SLpatternMask(patternMask),
50 tMax(tmax),
51 relevantID{ -1., 1.,
52 -10., 1.,
53 -1., 1.,
54 -1., 10.,
55 -1., 1.,
56 -10.5, 1.,
57 -1., 1.,
58 -1., 11.,
59 -1., 1.},
60 et_option(etoption)
61{
62 weights.assign(nWeightsCal(), 0.);
63}

◆ ~CDCTriggerMLP()

~CDCTriggerMLP ( )
inline

destructor, empty because we don't allocate memory anywhere.

Definition at line 47 of file CDCTriggerMLP.h.

47{ }

Member Function Documentation

◆ get_et_option()

std::string get_et_option ( ) const
inline

Returns way of obtaining the event time.

Definition at line 82 of file CDCTriggerMLP.h.

82{ return et_option; }

◆ getIDRange()

std::vector< float > getIDRange ( unsigned  iSL) const
inline

get relevant ID range for given super layer

Definition at line 74 of file CDCTriggerMLP.h.

75 {
76 return {relevantID[2 * iSL], relevantID[2 * iSL + 1]};
77 }

◆ getMaxHitsPerSL()

unsigned short getMaxHitsPerSL ( ) const
inline

get maximum hit number for a single super layer

Definition at line 64 of file CDCTriggerMLP.h.

64{ return maxHitsPerSL; }

◆ getRelID()

std::vector< float > getRelID ( ) const
inline

Definition at line 80 of file CDCTriggerMLP.h.

80{return relevantID;}

◆ getSLpattern()

unsigned long getSLpattern ( ) const
inline

get super layer pattern

Definition at line 66 of file CDCTriggerMLP.h.

66{ return SLpattern & SLpatternMask; }

◆ getSLpatternMask()

unsigned long getSLpatternMask ( ) const
inline

get bitmask for super layer pattern

Definition at line 68 of file CDCTriggerMLP.h.

68{ return SLpatternMask; }

◆ getSLpatternUnmasked()

unsigned long getSLpatternUnmasked ( ) const
inline

get raw super layer pattern

Definition at line 70 of file CDCTriggerMLP.h.

70{ return SLpattern; }

◆ getTMax()

unsigned short getTMax ( ) const
inline

get maximal drift time

Definition at line 72 of file CDCTriggerMLP.h.

72{ return tMax; }

◆ getWeights()

std::vector< float > getWeights ( ) const
inline

get weights vector

Definition at line 60 of file CDCTriggerMLP.h.

60{ return weights; }

◆ inInvptRangeTrain()

bool inInvptRangeTrain ( float  invpt) const

check whether given 1/pt value is in training sector

Definition at line 119 of file CDCTriggerMLP.cc.

120{
121 return (invptRangeTrain[0] <= invpt && invpt <= invptRangeTrain[1]);
122}

◆ inInvptRangeUse()

bool inInvptRangeUse ( float  invpt) const

check whether given 1/pt value is in sector

Definition at line 93 of file CDCTriggerMLP.cc.

94{
95 return (invptRangeUse[0] <= invpt && invpt <= invptRangeUse[1]);
96}

◆ inPhiRangeTrain()

bool inPhiRangeTrain ( float  phi) const

check whether given phi value is in training sector

Definition at line 105 of file CDCTriggerMLP.cc.

106{
107 return ((phiRangeTrain[0] <= (phi - 2. * M_PI) && (phi - 2. * M_PI) <= phiRangeTrain[1]) ||
108 (phiRangeTrain[0] <= phi && phi <= phiRangeTrain[1]) ||
109 (phiRangeTrain[0] <= (phi + 2. * M_PI) && (phi + 2. * M_PI) <= phiRangeTrain[1]));
110}

◆ inPhiRangeUse()

bool inPhiRangeUse ( float  phi) const

check whether given phi value is in sector

Definition at line 79 of file CDCTriggerMLP.cc.

80{
81 return ((phiRangeUse[0] <= (phi - 2. * M_PI) && (phi - 2. * M_PI) <= phiRangeUse[1]) ||
82 (phiRangeUse[0] <= phi && phi <= phiRangeUse[1]) ||
83 (phiRangeUse[0] <= (phi + 2. * M_PI) && (phi + 2. * M_PI) <= phiRangeUse[1]));
84}

◆ inPtRangeTrain()

bool inPtRangeTrain ( float  pt) const

check whether given pt value is in training sector

Definition at line 113 of file CDCTriggerMLP.cc.

114{
115 return (invptRangeTrain[0] <= 1. / pt && 1. / pt <= invptRangeTrain[1]);
116}

◆ inPtRangeUse()

bool inPtRangeUse ( float  pt) const

check whether given pt value is in sector

Definition at line 87 of file CDCTriggerMLP.cc.

88{
89 return (invptRangeUse[0] <= 1. / pt && 1. / pt <= invptRangeUse[1]);
90}

◆ inThetaRangeTrain()

bool inThetaRangeTrain ( float  theta) const

check whether given theta value is in training sector

Definition at line 125 of file CDCTriggerMLP.cc.

126{
127 return (thetaRangeTrain[0] <= theta && theta <= thetaRangeTrain[1]);
128}

◆ inThetaRangeUse()

bool inThetaRangeUse ( float  theta) const

check whether given theta value is in sector

Definition at line 99 of file CDCTriggerMLP.cc.

100{
101 return (thetaRangeUse[0] <= theta && theta <= thetaRangeUse[1]);
102}

◆ isRelevant()

bool isRelevant ( float  relId,
unsigned  iSL 
) const

check whether given relative TS ID is in relevant range

Definition at line 131 of file CDCTriggerMLP.cc.

132{
133 return (relevantID[2 * iSL] <= relId && relId <= relevantID[2 * iSL + 1]);
134}

◆ isTrained()

bool isTrained ( ) const
inline

check if weights are default values or set by some trainer

Definition at line 50 of file CDCTriggerMLP.h.

50{ return trained; }

◆ nLayers()

unsigned nLayers ( ) const
inline

get number of layers

Definition at line 52 of file CDCTriggerMLP.h.

52{ return nNodes.size(); }

◆ nNodesLayer()

unsigned nNodesLayer ( unsigned  iLayer) const
inline

get number of nodes in a layer

Definition at line 54 of file CDCTriggerMLP.h.

54{ return nNodes[iLayer]; }

◆ nWeights()

unsigned nWeights ( ) const
inline

get number of weights from length of weights vector

Definition at line 56 of file CDCTriggerMLP.h.

56{ return weights.size(); }

◆ nWeightsCal()

unsigned nWeightsCal ( ) const

calculate number of weights from number of nodes

Definition at line 66 of file CDCTriggerMLP.cc.

67{
68 unsigned nWeights = 0;
69 if (nLayers() > 1) {
70 nWeights = (nNodes[0] + 1) * nNodes[1];
71 for (unsigned il = 1; il < nLayers() - 1; ++il) {
72 nWeights += (nNodes[il] + 1) * nNodes[il + 1];
73 }
74 }
75 return nWeights;
76}
unsigned nLayers() const
get number of layers
Definition: CDCTriggerMLP.h:52
unsigned nWeights() const
get number of weights from length of weights vector
Definition: CDCTriggerMLP.h:56

◆ scaleId()

float scaleId ( double  relId,
unsigned  iSL 
) const

scale relative TS ID from relevant range to approximately [-1, 1] (to facilitate the FPGA implementation, the scale factor is rounded to a power of 2)

Definition at line 137 of file CDCTriggerMLP.cc.

138{
139 float scale = 2. / (relevantID[2 * iSL + 1] - relevantID[2 * iSL]);
140 // round down to nearest power of 2
141 scale = pow(2, floor(log2(scale)));
142 float offset = (relevantID[2 * iSL] + relevantID[2 * iSL + 1]) / 2.;
143 return scale * (relId - offset);
144}

◆ scaleTarget()

std::vector< float > scaleTarget ( std::vector< float >  target) const

scale target value from outputScale to [-1, 1]

Definition at line 147 of file CDCTriggerMLP.cc.

148{
149 std::vector<float> scaled;
150 scaled.assign(target.size(), 0.);
151 for (unsigned i = 0; i < target.size(); ++i) {
152 scaled[i] = 2. * (target[i] - outputScale[2 * i]) / (outputScale[2 * i + 1] - outputScale[2 * i]) - 1.;
153 }
154 return scaled;
155}

◆ setRelID()

void setRelID ( std::vector< float >  relid)
inline

set and get total relevant ID range

Definition at line 79 of file CDCTriggerMLP.h.

79{relevantID = relid;}

◆ setWeights()

void setWeights ( std::vector< float >  xweights)
inline

set weights vector

Definition at line 62 of file CDCTriggerMLP.h.

62{weights = xweights; }

◆ thetaIndex()

int thetaIndex ( ) const

get target index for theta (-1 if no output is trained for theta)

Definition at line 175 of file CDCTriggerMLP.cc.

176{
177 return (targetVars & 2) ? (targetVars & 1) : -1;
178}

◆ unscaleTarget()

std::vector< float > unscaleTarget ( std::vector< float >  target) const

scale target value from [-1, 1] to outputScale

Definition at line 158 of file CDCTriggerMLP.cc.

159{
160 std::vector<float> unscaled;
161 unscaled.assign(target.size(), 0.);
162 for (unsigned i = 0; i < target.size(); ++i) {
163 unscaled[i] = (target[i] + 1.) * (outputScale[2 * i + 1] - outputScale[2 * i]) / 2. + outputScale[2 * i];
164 }
165 return unscaled;
166}

◆ zIndex()

int zIndex ( ) const

get target index for z (-1 if no output is trained for z)

Definition at line 169 of file CDCTriggerMLP.cc.

170{
171 return (targetVars & 1) ? 0 : -1;
172}

Friends And Related Function Documentation

◆ CDCTriggerNeuroTrainerModule

friend class CDCTriggerNeuroTrainerModule
friend

Definition at line 23 of file CDCTriggerMLP.h.

◆ NeuroTrigger

friend class NeuroTrigger
friend

Definition at line 24 of file CDCTriggerMLP.h.

Member Data Documentation

◆ et_option

std::string et_option
private

Returns way of obtaining the event time.

The different options are: "etf_only" : only ETF info is used, otherwise an error is thrown. "fastestpriority" : event time is estimated by fastest priority time in selected track segments. if something fails, it is set to 0. "zero" : the event time is set to 0. "etf_or_fastestpriority" : the event time is obtained by the ETF, if not possible, the flag "fastestppriority" is used. "etf_or_zero" : the event time is obtained by the ETF, if

Definition at line 182 of file CDCTriggerMLP.h.

◆ invptRangeTrain

std::vector<float> invptRangeTrain
private

Charge / Pt region in 1/GeV for which this expert is trained.

Taking 1 / Pt instead of Pt means that straight tracks are at 0, i.e. there is a smooth transition from positive to negative charge.

Definition at line 146 of file CDCTriggerMLP.h.

◆ invptRangeUse

std::vector<float> invptRangeUse
private

Charge / Pt region in 1/GeV for which this expert is used.

Taking 1 / Pt instead of Pt means that straight tracks are at 0, i.e. there is a smooth transition from positive to negative charge.

Definition at line 137 of file CDCTriggerMLP.h.

◆ maxHitsPerSL

unsigned short maxHitsPerSL
private

Maximum number of inputs for a single super layer.

Definition at line 151 of file CDCTriggerMLP.h.

◆ nNodes

std::vector<unsigned short> nNodes
private

Number of nodes in each layer, not including bias nodes.

Definition at line 118 of file CDCTriggerMLP.h.

◆ outputScale

std::vector<float> outputScale
private

Output[i] of the MLP is scaled from [-1, 1] to [outputScale[2i], outputScale[2i+1]].

Definition at line 129 of file CDCTriggerMLP.h.

◆ phiRangeTrain

std::vector<float> phiRangeTrain
private

Phi region in radian for which this expert is used.

Valid ranges go from -2pi to 2pi.

Definition at line 142 of file CDCTriggerMLP.h.

◆ phiRangeUse

std::vector<float> phiRangeUse
private

Phi region in radian for which this expert is used.

Valid ranges go from -2pi to 2pi.

Definition at line 133 of file CDCTriggerMLP.h.

◆ relevantID

std::vector<float> relevantID
private

Hits must be within ID region around 2D track to be used as input.

Default for axial layers is +- 1 wire, default for stereo layers is region spanned by stereos +- 1 wire.

Definition at line 166 of file CDCTriggerMLP.h.

◆ SLpattern

unsigned long SLpattern
private

Super layer pattern for which this expert is trained.

Binary pattern of 9 * maxHitsPerSL bits (on/off for each hit). 0 means no restriction rather than no inputs.

Definition at line 155 of file CDCTriggerMLP.h.

◆ SLpatternMask

unsigned long SLpatternMask
private

Bitmask for comparing the super layer pattern.

A track matches a sector, if SLpattern & SLpatternMask == hitPattern(track) & SLpatternMask.

Definition at line 159 of file CDCTriggerMLP.h.

◆ targetVars

unsigned short targetVars
private

output variables: 1: z, 2: theta, 3: (z, theta)

Definition at line 126 of file CDCTriggerMLP.h.

◆ thetaRangeTrain

std::vector<float> thetaRangeTrain
private

Theta region in radian for which this expert is trained.

Definition at line 148 of file CDCTriggerMLP.h.

◆ thetaRangeUse

std::vector<float> thetaRangeUse
private

Theta region in radian for which this expert is trained.

Definition at line 139 of file CDCTriggerMLP.h.

◆ tMax

unsigned short tMax
private

Maximal drift time (for scaling), hits with larger values are ignored.

Definition at line 162 of file CDCTriggerMLP.h.

◆ trained

bool trained
private

Indicator whether the weights are just default values or have been set by some trainer (set to true when setWeights() is first called).

Definition at line 123 of file CDCTriggerMLP.h.

◆ weights

std::vector<float> weights
private

Weights of the network.

Definition at line 120 of file CDCTriggerMLP.h.


The documentation for this class was generated from the following files: