29 class NeuroTrigger3DH {
33 NeuroTrigger3DH() =
default;
36 virtual ~NeuroTrigger3DH() =
default;
41 void initializeCollections(std::string hitCollectionName);
43 void createIntWeights();
53 std::vector<float> getInputVector(
const std::vector<size_t>& hitIds)
const;
55 std::vector<float> runMLP(
const std::vector<float>& input)
const;
57 std::vector<float> runMLPFixedPrecision(
const std::vector<float>& input)
const;
59 std::vector<float> unscaleTarget(
const std::vector<float>& target)
const;
61 std::vector<float> scaleTarget(
const std::vector<float>& target)
const;
64 int getWeightBits()
const {
return m_precisionWeights; }
66 int getFractionalWeightBits()
const {
return m_fractionalWeightBits; }
68 const std::vector<int32_t>& getIntWeights()
const {
return m_intWeights; }
70 int getEventTime()
const {
return m_T0; };
72 void setNeuroParameters(
const NeuroParametersHough& neuroParameters3DH) { m_neuroParameters3DH = neuroParameters3DH; };
82 float getScaledDriftTime(
const CDCTriggerSegmentHit& trackSegmentHit,
const unsigned short maxTime)
const;
86 float scaleRelativeID(
const double relativeID,
const unsigned superLayerIdx)
const;
91 std::vector<int32_t> m_intWeights;
93 int m_fractionalWeightBits;
99 std::string m_hitCollectionName;
102 static constexpr unsigned int m_nSL = 9;
104 std::array<std::array<double, 2>, m_nSL> m_radiusWireLayer{};
106 std::array < unsigned short, m_nSL + 1 > m_cumulativeWires{};
108 std::array<unsigned short, m_nSL> m_nWires{};
110 double m_referenceID[m_nSL][2] = {};
112 double m_alpha[m_nSL][2] = {};
116 bool m_hasT0 =
false;
119 static constexpr unsigned int m_nStandardInputNodes = 27;
120 static constexpr unsigned int m_nExtendedInputNodes = 126;
123 static constexpr int m_precisionPhi = 12;
124 static constexpr int m_precisionAlpha = 12;
125 static constexpr int m_precisionScaleFactor = 8;
126 static constexpr int m_precisionReferenceID = 8;
129 static constexpr int m_precisionInputs = 13;
130 static constexpr int m_precisionWeights = 17;
135 static constexpr int LUT_INDEX_BITS = 12;
136 static constexpr std::size_t LUT_SIZE = 1 << LUT_INDEX_BITS;
139 static constexpr int LUT_FRAC_BITS = 12;
140 static constexpr int LUT_SCALE = 1 << LUT_FRAC_BITS;
143 static constexpr int MAX_FLOAT_SHIFT = 2;
144 static constexpr int MAX_FLOAT = 1 << MAX_FLOAT_SHIFT;
145 static constexpr int LUT_SATURATION = 1 << (LUT_FRAC_BITS + MAX_FLOAT_SHIFT);
150 static constexpr int HEADROOM_BITS = 3;
152 inline static const std::array<int32_t, LUT_SIZE> table = []()
154 std::array<int32_t, LUT_SIZE> lut{};
155 for (std::size_t i = 0; i < LUT_SIZE; ++i) {
156 double input = MAX_FLOAT *
static_cast<double>(i) / LUT_SIZE;
157 double val = std::tanh(input) * LUT_SCALE;
158 int32_t qval =
static_cast<int32_t
>(std::round(val));
160 qval = std::min<int32_t>(qval, (LUT_SCALE - 1));
166 static int32_t get(std::size_t idx) {
return table[idx]; }
170 static constexpr int32_t extractBits(int64_t value,
int high,
int low)
172 int width = high - low + 1;
173 int64_t shifted = value >> low;
174 int32_t mask = (1 << width) - 1;
175 int32_t result =
static_cast<int32_t
>(shifted & mask);
176 if (result & (1 << (width - 1))) {