Belle II Software  release-06-00-14
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 
14 namespace Belle2 {
20  class CDCTriggerMLP : public TObject {
21 
22  // weights etc. are set only by the trainer
23  friend class CDCTriggerNeuroTrainerModule;
24 
25  public:
27  CDCTriggerMLP();
28 
30  CDCTriggerMLP(std::vector<unsigned short>& nodes,
31  unsigned short targets,
32  std::vector<float>& outputscale,
33  std::vector<float>& phirange,
34  std::vector<float>& invptrange,
35  std::vector<float>& thetarange,
36  unsigned short maxHits,
37  unsigned long pattern,
38  unsigned long patternMask,
39  unsigned short tmax,
40  bool calcT0,
41  const std::string& etoption);
42 
45 
47  bool isTrained() const { return trained; }
49  unsigned nLayers() const { return nNodes.size(); }
51  unsigned nNodesLayer(unsigned iLayer) const { return nNodes[iLayer]; }
53  unsigned nWeights() const { return weights.size(); }
55  unsigned nWeightsCal() const;
57  std::vector<float> getWeights() const { return weights; }
59  unsigned short getMaxHitsPerSL() const { return maxHitsPerSL; }
61  unsigned long getSLpattern() const { return SLpattern & SLpatternMask; }
63  unsigned long getSLpatternMask() const { return SLpatternMask; }
65  unsigned long getSLpatternUnmasked() const { return SLpattern; }
67  unsigned short getTMax() const { return tMax; }
69  std::vector<float> getIDRange(unsigned iSL) const
70  {
71  return {relevantID[2 * iSL], relevantID[2 * iSL + 1]};
72  }
74  bool getT0fromHits() const
75  {
76  B2WARNING("Use of this flag is deprecated! Use get_et_option() instead!");
77  return T0fromHits;
78  }
80  std::string get_et_option() const { return et_option; }
81 
83  bool inPhiRange(float phi) const;
85  bool inPtRange(float pt) const;
87  bool inInvptRange(float invpt) const;
89  bool inThetaRange(float theta) const;
91  bool isRelevant(float relId, unsigned iSL) const;
92 
95  float scaleId(double relId, unsigned iSL) const;
97  std::vector<float> scaleTarget(std::vector<float> target) const;
99  std::vector<float> unscaleTarget(std::vector<float> target) const;
100 
102  int zIndex() const;
104  int thetaIndex() const;
105 
106  private:
108  std::vector<unsigned short> nNodes;
110  std::vector<float> weights;
113  bool trained;
114 
116  unsigned short targetVars;
119  std::vector<float> outputScale;
120 
123  std::vector<float> phiRange;
127  std::vector<float> invptRange;
129  std::vector<float> thetaRange;
130 
132  unsigned short maxHitsPerSL;
136  unsigned long SLpattern;
140  unsigned long SLpatternMask;
141 
143  unsigned short tMax;
147  std::vector<float> relevantID;
148 
163  std::string et_option;
164 
171 
174  };
176 }
177 #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
std::vector< float > thetaRange
Theta region in radian for which this expert is trained.
~CDCTriggerMLP()
destructor, empty because we don't allocate memory anywhere.
Definition: CDCTriggerMLP.h:44
unsigned short tMax
Maximal drift time (for scaling), hits with larger values are ignored.
bool inPhiRange(float phi) const
check whether given phi value is in sector
bool inThetaRange(float theta) const
check whether given theta value is in sector
std::vector< unsigned short > nNodes
Number of nodes in each layer, not including bias nodes.
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:47
std::string get_et_option() const
Returns way of obtaining the event time.
Definition: CDCTriggerMLP.h:80
unsigned long getSLpatternMask() const
get bitmask for super layer pattern
Definition: CDCTriggerMLP.h:63
unsigned long getSLpatternUnmasked() const
get raw super layer pattern
Definition: CDCTriggerMLP.h:65
std::vector< float > scaleTarget(std::vector< float > target) const
scale target value from outputScale to [-1, 1]
bool getT0fromHits() const
get flag for event time definition
Definition: CDCTriggerMLP.h:74
std::vector< float > outputScale
Output[i] of the MLP is scaled from [-1, 1] to [outputScale[2i], outputScale[2i+1]].
bool inPtRange(float pt) const
check whether given pt value is in sector
unsigned short getTMax() const
get maximal drift time
Definition: CDCTriggerMLP.h:67
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.
float scaleId(double relId, unsigned iSL) const
scale relative TS ID from relevant range to approximately [-1, 1] (to facilitate the FPGA implementat...
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.
unsigned nLayers() const
get number of layers
Definition: CDCTriggerMLP.h:49
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 > phiRange
Phi region in radian for which this expert is trained.
std::vector< float > getIDRange(unsigned iSL) const
get relevant ID range for given super layer
Definition: CDCTriggerMLP.h:69
bool inInvptRange(float invpt) const
check whether given 1/pt value is in sector
unsigned long getSLpattern() const
get super layer pattern
Definition: CDCTriggerMLP.h:61
bool T0fromHits
DEPRECATED!! If true, the event time will be determined from hits within relevantID region,...
unsigned nWeights() const
get number of weights from length of weights vector
Definition: CDCTriggerMLP.h:53
ClassDef(CDCTriggerMLP, 7)
Needed to make the ROOT object storable.
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:59
int thetaIndex() const
get target index for theta (-1 if no output is trained for theta)
std::vector< float > invptRange
Charge / Pt region in 1/GeV for which this expert is trained.
int zIndex() const
get target index for z (-1 if no output is trained for z)
std::vector< float > getWeights() const
get weights vector
Definition: CDCTriggerMLP.h:57
unsigned long SLpattern
Super layer pattern for which this expert is trained.
unsigned nNodesLayer(unsigned iLayer) const
get number of nodes in a layer
Definition: CDCTriggerMLP.h:51
The trainer module for the neural networks of the CDC trigger.
Abstract base class for different kinds of events.