Belle II Software  release-08-00-10
Unpacker.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 #include <string>
9 #include <sstream>
10 #include <iostream>
11 #include <iomanip>
12 #include <bitset>
13 #include <numeric>
14 #include <cmath>
15 #include <algorithm>
16 
17 #include <trg/cdc/dataobjects/Bitstream.h>
18 #include <trg/cdc/dataobjects/CDCTriggerTrack.h>
19 #include <trg/cdc/dataobjects/CDCTriggerSegmentHit.h>
20 #include <trg/cdc/dataobjects/CDCTriggerFinderClone.h>
21 #include <trg/cdc/dataobjects/CDCTriggerMLPInput.h>
22 #include <framework/gearbox/Const.h>
23 #include <trg/cdc/dbobjects/CDCTriggerNeuroConfig.h>
24 #include <framework/dataobjects/BinnedEventT0.h>
25 
26 namespace Belle2 {
32  namespace CDCTriggerUnpacker {
33 
34  constexpr double pi() { return std::atan(1) * 4; }
35 
36  // constants
37  static constexpr std::array<int, 9> nMergers = {10, 10, 12, 14, 16, 18, 20, 22, 24};
38 
39  // The data width are the specs under full speed.
40  // When using one of the half-speed version,
41  // TS/track are filled from MSB, leaving LSB blank.
42  static constexpr int TSFOutputWidth = TSF_TO_2D_WIDTH; // 429 (#defined in Bitstream.h)
43  static constexpr int nTrackers = NUM_2D; // 4
44  static constexpr int nAxialTSF = NUM_TSF; // 5
45  static constexpr int nStereoTSF = 4;
46  static constexpr int T2DOutputWidth = T2D_TO_3D_WIDTH; // 747
47  static constexpr unsigned lenTS = 21; // ID (8 bit) + t (9 bit) + LR (2 bit) + priority (2 bit)
48 
49  static constexpr int nMax2DTracksPerClock = 4;
50 
51  // bit width of the clock counter
52  static constexpr int clockCounterWidth = 9;
53 
54  /* number of mergers in axial super layers */
55  static constexpr std::array<int, nAxialTSF> nAxialMergers = {10, 12, 16, 20, 24};
56  /* number of wires in a super layer*/
57  static constexpr std::array<int, 9> nWiresInSuperLayer = {
58  160, 160, 192, 224, 256, 288, 320, 352, 384
59  };
60  /* Number of wire/cells in a single layer per merger unit */
61  static constexpr int nCellsInLayer = 16;
62 
63  // dataobjects
64  using TSFOutputVector = std::array<char, TSFOutputWidth>;
65  using TSFOutputArray = std::array<TSFOutputVector, nTrackers>;
66  using TSFOutputBus = std::array<TSFOutputArray, nAxialTSF>;
67  using TSFOutputBitStream = Bitstream<TSFOutputBus>;
68 
69  using T2DOutputVector = std::array<char, T2DOutputWidth>;
70  using T2DOutputBus = std::array<T2DOutputVector, nTrackers>;
71  using T2DOutputBitStream = Bitstream<T2DOutputBus>;
72 
73  using NNVector = std::array<char, NN_WIDTH>;
74  using NNBus = std::array<NNVector, nTrackers>;
75  using NNBitStream = Bitstream<NNBus>;
76  // using NNInputVector = std::array<char, NNInputWidth>;
77  // using NNInputBus = std::array<NNInputVector, nTrackers>;
78  // using NNInputBitStream = Bitstream<NNInputBus>;
79 
80  // using NNOutputVector = std::array<char, NNOutputWidth>;
81  // using NNOutputBus = std::array<NNOutputVector, nTrackers>;
82  // using NNOutputBitStream = Bitstream<NNOutputBus>;
83 
84  // functions
85  std::string padto(std::string s, unsigned l)
86  {
87  if (s.size() < l) {
88  s.insert(s.begin(), l - s.size(), ' ');
89  }
90  return s;
91  }
92  std::string padright(std::string s, unsigned l)
93  {
94  if (s.size() < l) {
95  s.insert(s.end(), l - s.size(), ' ');
96  }
97  return s;
98  }
99 
100  void printBuffer(int* buf, int nwords)
101  {
102  for (int j = 0; j < nwords; ++j) {
103  printf(" %.8x", buf[j]);
104  if ((j + 1) % 8 == 0) {
105  printf("\n");
106  }
107  }
108  printf("\n");
109  return;
110  };
111 
112  std::string rawIntToAscii(int buf)
113  {
114  std::ostringstream firmwareTypeStream;
115  firmwareTypeStream << std::hex << buf;
116  std::string firmwareTypeHex(firmwareTypeStream.str());
117  std::string firmwareType(4, '0');
118  for (int i = 0; i < 4; i++) {
119  std::istringstream firmwareTypeIStream(firmwareTypeHex.substr(i * 2, 2));
120  int character;
121  firmwareTypeIStream >> std::hex >> character;
122  firmwareType[i] = character;
123  }
124  return firmwareType;
125  };
126 
127  std::string rawIntToString(int buf)
128  {
129  std::ostringstream firmwareVersionStream;
130  firmwareVersionStream << std::hex << buf;
131  return firmwareVersionStream.str();
132  };
133 
134  /* Note: VHDL std_logic value is stored in a byte (char). The
135  * 9 values are mapped as 'U':0, 'X':1, '0':2, '1':3
136  * 'Z':4, 'W':5, 'L':6, 'H':7, '-':8 . The std_logic_vector
137  * is stored as a contiguous array of bytes. For example
138  * "0101Z" is stored in five bytes as char s[5] = {2,3,2,3,4}
139  * An HDL integer type is stored as C int, a HDL real type is
140  * stored as a C double and a VHDL string type is stored as char*.
141  * An array of HDL integer or double is stored as an array of C
142  * integer or double respectively
143  */
144 
145  /* In case you are not familiar with VHDL simulation, there are 9 possible
146  * values defined for the standard logic type, instead of just 0 and 1. The
147  * simulator needs to compute all these possible outcomes. Therefore, XSI uses
148  * a byte, instead of a bit, to represent a std_logic. This is represented
149  * with a char with possible values ranging from 0 to 8.
150  */
151  const char* std_logic_literal[] = {"U", "X", "0", "1", "Z", "W", "L", "H", "-"};
153  const char one_val = 3;
155  const char zero_val = 2;
156 
157  char std_logic(bool inBit)
158  {
159  char outBit = zero_val;
160  if (inBit) {
161  outBit = one_val;
162  }
163  return outBit;
164  }
165 
166  std::string display_value(const char* count, int size)
167  {
168  std::string res;
169  for (int i = 0; i < size; i++) {
170  if (count[i] >= 0 && count[i] < 9) {
171  res += std_logic_literal[(int) count[i]];
172  } else {
173  B2DEBUG(20, "invalid signal detected: " << static_cast<int>(count[i]));
174  res += "?";
175  }
176  }
177  return res;
178  }
179 
180  template<size_t N>
181  std::string slv_to_bin_string(std::array<char, N> signal, bool padding = false)
182  {
183  int ini = padding ? 4 - signal.size() % 4 : 0;
184  std::string res(ini, '0');
185  for (auto const& bit : signal) {
186  if (bit >= 0 && bit < 9) {
187  res += std_logic_literal[(int) bit];
188  } else {
189  B2DEBUG(20, "invalid signal detected: " << static_cast<int>(bit));
190  res += "0";
191  }
192  }
193  return res;
194  }
195 
196  template<size_t N>
197  void display_hex(const std::array<char, N>& signal)
198  {
199  std::ios oldState(nullptr);
200  oldState.copyfmt(std::cout);
201  if (std::any_of(signal.begin(), signal.end(), [](char i)
202  {return i != zero_val && i != one_val;})) {
203  B2DEBUG(20, "Some bit in the signal vector is neither 0 nor 1. \n" <<
204  "Displaying binary values instead.");
205  std::cout << slv_to_bin_string(signal) << std::endl;
206  } else {
207  std::string binString = slv_to_bin_string(signal, true);
208  std::cout << std::setfill('0');
209  for (unsigned i = 0; i < signal.size(); i += 4) {
210  std::bitset<4> set(binString.substr(i, 4));
211  std::cout << std::setw(1) << std::hex << set.to_ulong();
212  }
213  }
214  std::cout << "\n";
215  std::cout.copyfmt(oldState);
216  }
217 
218  /* extract a subset of bitstring, like substring.
219  *
220  * In principle this can be done using only integer manipulations, but for the
221  * sake of simplicity, let's just cast them to string. Beware the endianness.
222  * 0 refer to the rightmost bit in std::bitset, but the leftmost bit in
223  * std::string
224  */
225  template<size_t nbits, size_t min, size_t max>
226  std::bitset < max - min + 1 > subset(std::bitset<nbits> set)
227  {
228  const size_t outWidth = max - min + 1;
229  std::string str = set.to_string();
230  return std::bitset<outWidth>(str.substr(nbits - max - 1, outWidth));
231  }
232 
233 
241  unsigned short globalSegmentID(unsigned short localID, unsigned short iSL)
242  {
243  auto itr = nWiresInSuperLayer.begin();
244  unsigned short globalID = std::accumulate(itr, itr + iSL, 0);
245  globalID += localID;
246  return globalID;
247  }
248 
249  static const double realNaN = std::numeric_limits<double>::quiet_NaN();
250 
251  using tsOut = std::array<unsigned, 4>;
252  using tsOutArray = std::array<tsOut, 5>;
257  double omega;
259  double phi0;
261  tsOutArray ts;
262  // hw values of 2dtrack
263  int hwOmega{0};
264  int hwPhi0{0};
265  };
267  struct TRGNeuroTrack {
269  double z;
271  double theta;
273  unsigned sector;
275  std::array<float, 9> inputID;
276  std::array<int, 9> rawinputID;
278  std::array<float, 9> inputT;
279  std::array<int, 9> rawinputT;
281  std::array<float, 9> inputAlpha;
282  std::array<int, 9> rawinputAlpha;
284  std::array<tsOut, 9> ts;
286  int hwZ{0};
287  int hwTheta{0};
288  };
289  struct B2LDataField {
290  B2LDataField(
292  unsigned foundtime,
293  unsigned iTracker,
295  {
296  if (int(b2line.offset + foundtime) >= 0 &&
297  int(b2line.offset + foundtime) <= bitsNN->getEntries()) {
298 
299  NNBitStream* bitsn = (*bitsNN)[foundtime + b2line.offset];
300 
301  if (int(slv_to_bin_string(bitsn->signal()[iTracker]).size()) >= (NN_WIDTH - b2line.start)) {
302  data = slv_to_bin_string(bitsn->signal()[iTracker]).substr(NN_WIDTH - 1 - b2line.end, b2line.end - b2line.start + 1);
303  } else {
304  data = "";
305  }
306  } else {
307  data = "";
308  }
309 
310 
311  name = b2line.name;
312  }
313  std::string data;
314  std::string name;
315  };
316 
317  std::vector<bool> decodedriftthreshold(std::string p_driftthreshold)
318  {
319  std::vector<bool> res;
320  for (unsigned i = 0; i < p_driftthreshold.size(); ++i) {
321  if (p_driftthreshold.substr(i, 1) == "1") {
322  res.push_back(true);
323  } else if (p_driftthreshold.substr(i, 1) == "0") {
324  res.push_back(false);
325  } else {
326  B2WARNING("Invalid input in NNBitstream appending 'false'!");
327  res.push_back(false);
328  }
329  }
330  return res;
331  }
332  std::vector<bool> decodefoundoldtrack(std::string p_foundoldtrack)
333  {
334  std::vector<bool> res;
335  for (unsigned i = 0; i < p_foundoldtrack.size(); ++i) {
336  if (p_foundoldtrack.substr(i, 1) == "1") {
337  res.push_back(true);
338  } else if (p_foundoldtrack.substr(i, 1) == "0") {
339  res.push_back(false);
340  } else {
341  B2WARNING("Invalid input in NNBitstream appending 'false'!");
342  res.push_back(false);
343  }
344  }
345  return res;
346  }
347  bool decodevalstereobit(const std::string& p_valstereobit)
348  {
349  bool res;
350  if (p_valstereobit == "1") {
351  res = true;
352  } else if (p_valstereobit == "0") {
353  res = false;
354  } else {
355  B2WARNING("Invalid input in NNBitstream appending 'false'!");
356  res = false;
357  }
358  return res;
359  }
371  unsigned TSIDInSL(unsigned tsIDInTracker, unsigned iSL, unsigned iTracker)
372  {
373  const unsigned nCellsInSL = nMergers[iSL] * nCellsInLayer;
374  // get global TS ID
375  unsigned iTS = tsIDInTracker + nCellsInSL * iTracker / nTrackers;
376  // periodic ID overflow when phi0 > 0 for the 4th tracker
377  if (iTS >= nCellsInSL) {
378  iTS -= nCellsInSL;
379  }
380  // ID in SL8 is shifted by 16
381  if (iSL == 8) {
382  if (iTS < 16) {
383  iTS += nCellsInSL;
384  }
385  iTS -= 16;
386  }
387  return iTS;
388  }
389 
392  int mlp_bin_to_signed_int(std::string signal)
393  {
394  constexpr unsigned len = 13;
395  std::bitset<len> signal_bit(signal);
396  const unsigned shift = 16 - len;
397  // shift to 16 bits, cast it to signed 16-bit int, and shift it back
398  // thus the signed bit is preserved (when right-shifting)
399  int signal_out = (int16_t (signal_bit.to_ulong() << shift)) >> shift;
400  return signal_out;
401  }
406  int recalcETF(std::string driftinput, std::vector<unsigned> tsvector, CDCTriggerTrack* track)
407  {
408  //scale factor to get a value between -1 and 1
409  float scale = 1. / (1 << (driftinput.size() - 1) / 9);
410  int ret = 0;
411  bool stor = false;
412  // make a table, with <possible etf, how often it was calculated
413  // it is possible there are different event t0 used, if some value
414  // in the hw is kept longer than it should be
415  std::vector<std::vector<int>> table;
416  for (unsigned iSL = 0; iSL < 9; ++iSL) {
417  // getting the relative drift time in clock cycles (1cc ~ 2ns)
418  int reldt = static_cast<int>(fabs((mlp_bin_to_signed_int(driftinput.substr((8 - iSL) * driftinput.size() / 9,
419  driftinput.size() / 9)) * scale * 256)));
420  int tstime = static_cast<int>(tsvector[iSL]);
421  // we do not want SLs with no LR info or pts outside of the time window
422  if (reldt != 0 && reldt < 255) {
423  for (std::vector<int>& x : table) {
424  stor = false;
425  if (x[0] == tstime - reldt) {
426  x[1]++;
427  stor = true;
428  }
429  }
430  if (!stor) {table.push_back({tstime - reldt, 1});}
431  }
432 
433  }
434  // now get the event t0 recalculated most often and return it in the end
435  int maxi = 0;
436  for (std::vector<int>& x : table) {
437  if (x[1] > maxi) {
438  ret = x[0];
439  maxi = x[1];
440  }
441  }
442  // if there is a "wrong" input in the hardware values, the corresponding error bit is set
443  if (table.size() > 1) {track->setQualityVector(128);}
444  return ret;
445 
446  }
447 
455  tsOut decodeTSHit(std::string tsIn)
456  {
457  constexpr unsigned lenID = 8;
458  constexpr unsigned lenPriorityTime = 9; //(twodcc.size() > 0) ? 13 : 9;
459  constexpr unsigned lenLR = 2;
460  constexpr unsigned lenPriorityPosition = 2;
461  constexpr std::array<unsigned, 4> tsLens = {
462  lenID, lenPriorityTime, lenLR, lenPriorityPosition
463  };
464  std::array<unsigned, 5> tsPos = { 0 };
465  std::partial_sum(tsLens.begin(), tsLens.end(), tsPos.begin() + 1);
466  tsOut tsOutput;
467  tsOutput[0] = std::bitset<tsLens[0]>(tsIn.substr(tsPos[0], tsLens[0])).to_ulong();
468  tsOutput[1] = std::bitset<tsLens[1]>(tsIn.substr(tsPos[1], tsLens[1])).to_ulong();
469  tsOutput[2] = std::bitset<tsLens[2]>(tsIn.substr(tsPos[2], tsLens[2])).to_ulong();
470  tsOutput[3] = std::bitset<tsLens[3]>(tsIn.substr(tsPos[3], tsLens[3])).to_ulong();
471  return tsOutput;
472  }
473  tsOut decodeTSHit_sim(std::string tsIn, std::string twodcc)
474  {
475  constexpr unsigned lenID = 8;
476  constexpr unsigned lenPriorityTime = 9; //(twodcc.size() > 0) ? 13 : 9;
477  constexpr unsigned lenLR = 2;
478  constexpr unsigned lenPriorityPosition = 2;
479  constexpr std::array<unsigned, 4> tsLens = {
480  lenID, lenPriorityTime, lenLR, lenPriorityPosition
481  };
482  std::string C = tsIn.substr(lenID + 5, 4);
483  std::string B = tsIn.substr(lenID, 5);
484  std::string Bp = twodcc.substr(4, 5);
485  std::string Ap = twodcc.substr(0, 4);
486  int pt;
487  std::string pts;
488  if (std::stoul(B, 0, 2) <= std::stoul(Bp, 0, 2)) {
489  pts = Ap + B + C;
490  } else {
491  B2DEBUG(14, "2DCC overflow detected!");
492  pts = std::bitset<4>(std::stoul(Ap, 0, 2) - 1).to_string() + B + C;
493  }
494  pt = std::stoul(pts, 0, 2);
495  std::array<unsigned, 5> tsPos = { 0 };
496  std::partial_sum(tsLens.begin(), tsLens.end(), tsPos.begin() + 1);
497  tsOut tsOutput;
498  tsOutput[0] = std::bitset<tsLens[0]>(tsIn.substr(tsPos[0], tsLens[0])).to_ulong();
499  tsOutput[1] = pt; // std::bitset<tsLens[1]>(tsIn.substr(tsPos[1], tsLens[1])).to_ulong();
500  tsOutput[2] = std::bitset<tsLens[2]>(tsIn.substr(tsPos[2], tsLens[2])).to_ulong();
501  tsOutput[3] = std::bitset<tsLens[3]>(tsIn.substr(tsPos[3], tsLens[3])).to_ulong();
502  return tsOutput;
503  }
504  tsOut decodeTSHit_ext(std::string tsIn, std::string expt)
505  {
506  constexpr unsigned lenID = 8;
507  constexpr unsigned lenPriorityTime = 9; //(twodcc.size() > 0) ? 13 : 9;
508  constexpr unsigned lenLR = 2;
509  constexpr unsigned lenPriorityPosition = 2;
510  constexpr std::array<unsigned, 4> tsLens = {
511  lenID, lenPriorityTime, lenLR, lenPriorityPosition
512  };
513  unsigned pt = std::stoul(expt, 0, 2);
514  std::array<unsigned, 5> tsPos = { 0 };
515  std::partial_sum(tsLens.begin(), tsLens.end(), tsPos.begin() + 1);
516  tsOut tsOutput;
517  tsOutput[0] = std::bitset<tsLens[0]>(tsIn.substr(tsPos[0], tsLens[0])).to_ulong();
518  tsOutput[1] = pt; //std::bitset<13>(expt).to_ulong();
519  tsOutput[2] = std::bitset<tsLens[2]>(tsIn.substr(tsPos[2], tsLens[2])).to_ulong();
520  tsOutput[3] = std::bitset<tsLens[3]>(tsIn.substr(tsPos[3], tsLens[3])).to_ulong();
521  return tsOutput;
522  }
523 
533  TRG2DFinderTrack decode2DTrack(const std::string& p_charge __attribute__((unused)),
534  std::string p_omega,
535  std::string p_phi,
536  const std::string& p_ts0,
537  const std::string& p_ts2,
538  const std::string& p_ts4,
539  const std::string& p_ts6,
540  const std::string& p_ts8,
541  unsigned iTracker,
542  const std::string& p_2dcc,
543  bool sim13dt)
544  {
545 //constexpr unsigned lenomega = p_omega.size();
546  unsigned shift = 16 - p_omega.size();
547  TRG2DFinderTrack trackout;
548  int omega = std::stoi(p_omega, 0, 2);
549  // shift omega to 16 bits, cast it to signed 16-bit int, and shift it back to 7 bits
550  // thus the signed bit is preserved (when right-shifting)
551  int omegafirm = (int16_t (omega << shift)) >> shift;
552  trackout.hwOmega = omegafirm;
553  //int omegafirm = (int16_t (omega.to_ulong() << shift)) >> shift;
554  // B field is 1.5T
555  const double BField = 1.5e-4; // why is it so small?
556  // omega in 1/cm
557  // omega = 1/R = c * B / pt
558  trackout.omega = Const::speedOfLight * BField / 0.3 / 34 * omegafirm;
559 
560 
561 
562 
563  int phi = std::stoi(p_phi, 0, 2);
564  trackout.hwPhi0 = phi;
565  // c.f. https://confluence.desy.de/download/attachments/34033650/output-def.pdf
566  double globalPhi0 = pi() / 4 + pi() / 2 / 80 * (phi + 1) + pi() / 2 * iTracker; // see document above
567 
568 
569  trackout.ts[0] = (sim13dt) ? decodeTSHit_sim(p_ts0, p_2dcc) : decodeTSHit(p_ts0);
570  trackout.ts[1] = (sim13dt) ? decodeTSHit_sim(p_ts2, p_2dcc) : decodeTSHit(p_ts2);
571  trackout.ts[2] = (sim13dt) ? decodeTSHit_sim(p_ts4, p_2dcc) : decodeTSHit(p_ts4);
572  trackout.ts[3] = (sim13dt) ? decodeTSHit_sim(p_ts6, p_2dcc) : decodeTSHit(p_ts6);
573  trackout.ts[4] = (sim13dt) ? decodeTSHit_sim(p_ts8, p_2dcc) : decodeTSHit(p_ts8);
574  // rotate the tracks to the correct quadrant (iTracker)
575  if (globalPhi0 > pi() * 2) {
576  globalPhi0 -= pi() * 2;
577  }
578  trackout.phi0 = globalPhi0;
579  B2DEBUG(20, "Unpacking 2DTrack in Tracker: " << iTracker);
580  B2DEBUG(20, " Omega: " << std::to_string(omega) << ", Omegafirm: " << std::to_string(omegafirm) << ", converted to: " <<
581  std::to_string(trackout.omega));
582  B2DEBUG(20, " Phi: " << std::to_string(phi) << ", converted to: " << std::to_string(trackout.phi0));
583  return trackout;
584 
585  }
586  TRG2DFinderTrack decode2DTrack(std::string trackIn, unsigned iTracker)
587  {
588  constexpr unsigned lenCharge = 2;
589  constexpr unsigned lenOmega = 7;
590  constexpr unsigned lenPhi0 = 7;
591  constexpr std::array<unsigned, 3> trackLens = {lenCharge, lenOmega, lenPhi0};
592  std::array<unsigned, 4> trackPos{ 0 };
593  std::partial_sum(trackLens.begin(), trackLens.end(), trackPos.begin() + 1);
594  const unsigned shift = 16 - lenOmega;
595  TRG2DFinderTrack trackOut;
596  std::bitset<trackLens[1]> omega(trackIn.substr(trackPos[1], trackLens[1]));
597  // shift omega to 16 bits, cast it to signed 16-bit int, and shift it back to 7 bits
598  // thus the signed bit is preserved (when right-shifting)
599  int omegaFirm = (int16_t (omega.to_ulong() << shift)) >> shift;
600  trackOut.hwOmega = omegaFirm;
601  // B field is 1.5T
602  const double BField = 1.5e-4;
603  // omega in 1/cm
604  // omega = 1/R = c * B / pt
605  // c.f. https://confluence.desy.de/download/attachments/34033650/output-def.pdf
606  trackOut.omega = Const::speedOfLight * BField / 0.3 / 34 * omegaFirm;
607  int phi0 = std::bitset<trackLens[2]>(trackIn.substr(trackPos[2], trackLens[2])).to_ulong();
608  trackOut.hwPhi0 = phi0;
609  trackOut.phi0 = pi() / 4 + pi() / 2 / 80 * (phi0 + 1);
610  for (unsigned i = 0; i < 5; ++i) {
611  trackOut.ts[i] = decodeTSHit(trackIn.substr(trackPos.back() + i * lenTS, lenTS));
612  }
613 
614  // rotate the tracks to the correct quadrant (iTracker)
615  double globalPhi0 = trackOut.phi0 + pi() / 2 * iTracker;
616  if (globalPhi0 > pi() * 2) {
617  globalPhi0 -= pi() * 2;
618  }
619  trackOut.phi0 = globalPhi0;
620  return trackOut;
621  }
622 
631  TRGNeuroTrack decodeNNTrack(std::string p_mlpout_z,
632  std::string p_mlpout_theta,
633  std::string p_tsfsel,
634  std::string p_mlpin_alpha,
635  std::string p_mlpin_drifttime,
636  std::string p_mlpin_id,
637  std::string p_netsel,
638  const DBObjPtr<CDCTriggerNeuroConfig>& neurodb,
639  const std::string& p_2dcc,
640  bool sim13dt,
641  B2LDataField p_extendedpts)
642  {
643  // constexpr unsigned lenMLP = 13;
644  float scale_z = 1. / (1 << (p_mlpout_z.size() - 1));
645  float scale_theta = 1. / (1 << (p_mlpout_theta.size() - 1));
646  float scale_alpha = 1. / (1 << (p_mlpin_alpha.size() - 1) / 9);
647  float scale_drifttime = 1. / (1 << (p_mlpin_drifttime.size() - 1) / 9);
648  float scale_id = 1. / (1 << (p_mlpin_id.size() - 1) / 9);
649  TRGNeuroTrack foundTrack;
650  int theta_raw = mlp_bin_to_signed_int(p_mlpout_theta);
651  int z_raw = mlp_bin_to_signed_int(p_mlpout_z);
652  foundTrack.hwZ = z_raw;
653  foundTrack.hwTheta = theta_raw;
654  std::vector<float> unscaledT = neurodb->getMLPs()[0].unscaleTarget({(z_raw * scale_z), (theta_raw * scale_theta)});
655  foundTrack.z = unscaledT[0];
656  foundTrack.theta = unscaledT[1];
657  foundTrack.sector = std::stoi(p_netsel, 0, 2);
658  for (unsigned iSL = 0; iSL < 9; ++iSL) {
659  foundTrack.inputAlpha[iSL] =
660  mlp_bin_to_signed_int(p_mlpin_alpha.substr((8 - iSL) * p_mlpin_alpha.size() / 9, p_mlpin_alpha.size() / 9)) * scale_alpha;
661  foundTrack.inputT[iSL] =
662  mlp_bin_to_signed_int(p_mlpin_drifttime.substr((8 - iSL) * p_mlpin_drifttime.size() / 9,
663  p_mlpin_drifttime.size() / 9)) * scale_drifttime;
664  foundTrack.inputID[iSL] =
665  mlp_bin_to_signed_int(p_mlpin_id.substr((8 - iSL) * p_mlpin_drifttime.size() / 9, p_mlpin_drifttime.size() / 9)) * scale_id;
666  foundTrack.rawinputAlpha[iSL] = mlp_bin_to_signed_int(p_mlpin_alpha.substr((8 - iSL) * p_mlpin_alpha.size() / 9,
667  p_mlpin_alpha.size() / 9));
668  foundTrack.rawinputT[iSL] = mlp_bin_to_signed_int(p_mlpin_drifttime.substr((8 - iSL) * p_mlpin_drifttime.size() / 9,
669  p_mlpin_drifttime.size() / 9));
670  foundTrack.rawinputID[iSL] = mlp_bin_to_signed_int(p_mlpin_id.substr((8 - iSL) * p_mlpin_drifttime.size() / 9,
671  p_mlpin_drifttime.size() / 9));
672  if (sim13dt) {
673  foundTrack.ts[iSL] = decodeTSHit_sim(p_tsfsel.substr((8 - iSL) * lenTS, lenTS), p_2dcc);
674  } else {
675  if (p_extendedpts.name != "None") {
676  foundTrack.ts[iSL] = decodeTSHit_ext(p_tsfsel.substr((8 - iSL) * lenTS, lenTS), p_extendedpts.data.substr((8 - iSL) * 13, 13));
677  } else {
678  foundTrack.ts[iSL] = decodeTSHit(p_tsfsel.substr((8 - iSL) * lenTS, lenTS));
679  }
680  }
681  }
682  return foundTrack;
683  }
684  TRGNeuroTrack decodeNNTrack_old(std::string trackIn, std::string selectIn)
685  {
686  constexpr unsigned lenMLP = 13;
687  float scale = 1. / (1 << (lenMLP - 1));
688  TRGNeuroTrack foundTrack;
689  int theta_raw = mlp_bin_to_signed_int(trackIn.substr(1, lenMLP));
690  foundTrack.theta = theta_raw * scale * M_PI_2 + M_PI_2;
691  int z_raw = mlp_bin_to_signed_int(trackIn.substr(lenMLP + 1, lenMLP));
692  foundTrack.z = z_raw * scale * 50.;
693  foundTrack.sector = std::bitset<3>(trackIn.substr(2 * lenMLP + 1, 3)).to_ulong();
694  for (unsigned iSL = 0; iSL < 9; ++iSL) {
695  foundTrack.inputAlpha[iSL] =
696  mlp_bin_to_signed_int(selectIn.substr((2 + (8 - iSL)) * lenMLP + 4, lenMLP)) * scale;
697  foundTrack.inputT[iSL] =
698  mlp_bin_to_signed_int(selectIn.substr((11 + (8 - iSL)) * lenMLP + 4, lenMLP)) * scale;
699  foundTrack.inputID[iSL] =
700  mlp_bin_to_signed_int(selectIn.substr((20 + (8 - iSL)) * lenMLP + 4, lenMLP)) * scale;
701  foundTrack.ts[iSL] = // order: SL8, ..., SL0
702  decodeTSHit(selectIn.substr(29 * lenMLP + 4 + (8 - iSL) * lenTS, lenTS));
703  }
704  return foundTrack;
705  }
706 
711  CDCTriggerSegmentHit* addTSHit(tsOut ts, unsigned iSL, unsigned iTracker,
712  StoreArray<CDCTriggerSegmentHit>* tsHits,
713  int foundTime = 0)
714  {
715  unsigned iTS = TSIDInSL(ts[0], iSL, iTracker);
716  // check if hit is already existing in datastore
717  CDCTriggerSegmentHit* hit = nullptr;
718  //for (int ihit = 0; ihit < tsHits->getEntries(); ++ihit) {
719  // CDCTriggerSegmentHit* compare = (*tsHits)[ihit];
720  // if (compare->getISuperLayer() == iSL &&
721  // compare->getIWireCenter() == iTS &&
722  // compare->getPriorityPosition() == ts[3] &&
723  // compare->getLeftRight() == ts[2] &&
724  // compare->priorityTime() == int(ts[1])) {
725  // hit = compare;
726  // break;
727  // }
728  //}
729 // !hit is always true.
730 // if (!hit) {
731  hit = tsHits->appendNew(iSL, iTS, ts[3], ts[2], ts[1], 0, foundTime, iTracker);
732  B2DEBUG(15, "make hit at SL " << iSL << " ID " << iTS << " clock " << foundTime << " iTracker " << iTracker);
733 // }
734  return hit;
735  }
736 
751  void decode2DOutput(short foundTime,
752  T2DOutputBitStream* bits,
753  StoreArray<CDCTriggerTrack>* storeTracks,
754  StoreArray<CDCTriggerFinderClone>* storeClones,
755  StoreArray<CDCTriggerSegmentHit>* tsHits)
756  {
757  const unsigned lenTrack = 121;
758  const unsigned oldTrackWidth = 6;
759  const unsigned foundWidth = 6;
760  std::array<int, 4> posTrack;
761  for (unsigned i = 0; i < posTrack.size(); ++i) {
762  posTrack[i] = oldTrackWidth + foundWidth + lenTrack * i;
763  }
764  for (unsigned iTracker = 0; iTracker < nTrackers; ++iTracker) {
765  const auto slv = bits->signal()[iTracker];
766  std::string strOutput = slv_to_bin_string(slv).
767  substr(clockCounterWidth, T2DOutputWidth - clockCounterWidth);
768  for (unsigned i = 0; i < nMax2DTracksPerClock; ++i) {
769  // The first 6 bits indicate whether a track is found or not
770  if (slv[clockCounterWidth + oldTrackWidth + i] == one_val) {
771  TRG2DFinderTrack trk = decode2DTrack(strOutput.substr(posTrack[i], lenTrack), iTracker);
772  B2DEBUG(15, "2DOut phi0:" << trk.phi0 << ", omega:" << trk.omega
773  << ", at clock " << foundTime << ", tracker " << iTracker);
774  CDCTriggerTrack* track =
775  storeTracks->appendNew(trk.phi0, trk.omega, 0., foundTime, iTracker);
776  CDCTriggerFinderClone* clone =
777  storeClones->appendNew(slv[clockCounterWidth + i] == one_val, iTracker);
778  clone->addRelationTo(track);
779  // TODO: dig out the TS hits in DataStore, and
780  // add relations to them.
781  // Otherwise, create a new TS hit object and add the relation.
782  // However, the fastest time would be lost in this case.
783  // Problem: there might be multiple TS hits with the same ID,
784  // so the foundTime needs to be aligned first in order to compare.
785  for (unsigned iAx = 0; iAx < nAxialTSF; ++iAx) {
786  const auto& ts = trk.ts[iAx];
787  if (ts[3] > 0) {
788  unsigned iTS = TSIDInSL(ts[0], 2 * iAx, iTracker);
789  CDCTriggerSegmentHit* hit =
790  tsHits->appendNew(2 * iAx, // super layer
791  iTS, // TS number in super layer
792  ts[3], // priority position
793  ts[2], // L/R
794  ts[1], // priority time
795  0, // fastest time (unknown)
796  // set to a clock definitely outside the time window to receive the TS from TSF,
797  // so it won't cause any confusion of the TS origin.
798  // what I want to is to set it to (200 + 2DmoduleID[0,1,2,3]),
799  // so one can distinguish in which 2D this track is found.
800  // foundTime); // found time (using the unpacked clock cycle)
801  2000 + iTracker * 100 + foundTime,
802  iTracker); // quadrant
803  track->addRelationTo(hit);
804  }
805  }
806  }
807  }
808  }
809  }
810 
823  void decode2DInput(short foundTime,
824  std::array<int, 4> timeOffset,
825  TSFOutputBitStream* bits,
826  StoreArray<CDCTriggerSegmentHit>* tsHits)
827  {
828  // Get the input TS to 2D from the Bitstream
829  for (unsigned iAx = 0; iAx < nAxialTSF; ++iAx) {
830  for (unsigned iTracker = 0; iTracker < nTrackers; ++iTracker) {
831  const auto& tracker = bits->signal()[iAx][iTracker];
832  std::string strInput = slv_to_bin_string(tracker);
833  bool noMoreHit = false;
834  for (unsigned pos = clockCounterWidth; pos < TSFOutputWidth; pos += lenTS) {
835  std::string tsHitStr = strInput.substr(pos, lenTS);
836  B2DEBUG(50, tsHitStr);
837  tsOut ts = decodeTSHit(tsHitStr);
838  // check if all the hits are on the MSB side
839  if (ts[2] == 0) {
840  noMoreHit = true;
841  continue;
842  } else if (noMoreHit) {
843  B2DEBUG(20, "Discontinuous TS hit detected!");
844  }
845  unsigned iTS = TSIDInSL(ts[0], 2 * iAx, iTracker);
846  // Make TS hit object
847  CDCTriggerSegmentHit hit(2 * iAx, // super layer
848  iTS, // TS number in super layer
849  ts[3], // priority position
850  ts[2], // L/R
851  ts[1], // priority time
852  0, // fastest time (unknown)
853  foundTime + timeOffset[iTracker], // found time
854  iTracker); // quadrant
855 
856  // add if the TS hit of identical ID and foundTime is not already in the StoreArray
857  // (from the 2D input of another quarter or the 2D track output)
858 
859  /* TODO: Currently, it is very likely that a TS hit will appear
860  * multiple times in the StoreArray. To avoid adding the input from
861  * another quarter again, we need to look at the clock counter,
862  * because the data from different 2D's are not always synchronized
863  * due to Belle2Link instability. To avoid adding again from the 2D
864  * output, we need to consider the 2D latency.
865  */
866  if (std::none_of(tsHits->begin(), tsHits->end(),
867  [hit](CDCTriggerSegmentHit storeHit) {
868  return (storeHit.getSegmentID() == hit.getSegmentID() &&
869  storeHit.foundTime() == hit.foundTime());
870  })) {
871  B2DEBUG(40, "found TS hit ID " << hit.getSegmentID() <<
872  ", SL" << 2 * iAx << ", local ID " << iTS <<
873  ", 2D" << iTracker);
874  tsHits->appendNew(hit);
875  } else {
876  B2DEBUG(45, "skipping redundant hit ID " << hit.getSegmentID() << " in 2D" << iTracker);
877  }
878  }
879  }
880  }
881  }
882 
899  CDCTriggerTrack* decodeNNInput(short iclock,
900  unsigned iTracker,
901  NNBitStream* bitsIn,
902  StoreArray<CDCTriggerTrack>* store2DTracks,
903  StoreArray<CDCTriggerSegmentHit>* tsHits)
904  {
905  CDCTriggerTrack* track2D = nullptr;
906  constexpr unsigned lenTrack = 135; //119;
907  // omega (7 bit) + phi (7 bit) + 5 * TS (21 bit) + old track found(6bit) + valid stereo bit (1bit) + drift threshold (9bit)
908  const auto slvIn = bitsIn->signal()[iTracker];
909  std::string strIn = slv_to_bin_string(slvIn);
910  strIn = strIn.substr(NN_WIDTH - 570 - 496, 982);
911  // decode stereo hits
912  for (unsigned iSt = 0; iSt < nStereoTSF; ++iSt) {
913  for (unsigned iHit = 0; iHit < 10; ++iHit) {
914  // order: 10 * SL7, 10 * SL5, 10 * SL3, 10 * SL1
915  unsigned pos = ((nStereoTSF - iSt - 1) * 10 + iHit) * lenTS;
916  tsOut ts = decodeTSHit(strIn.substr(pos, lenTS));
917  if (ts[3] > 0) {
918  addTSHit(ts, iSt * 2 + 1, iTracker, tsHits, iclock);
919  }
920  }
921  }
922  std::string strTrack = strIn.substr(nStereoTSF * 10 * lenTS, lenTrack);
923  if (!std::all_of(strTrack.begin(), strTrack.end(), [](char i) {return i == '0';})) {
924  std::string infobits = strTrack.substr(5 * lenTS + 14, 16);
925  strTrack = "00" + strTrack.substr(5 * lenTS, 14) + strTrack.substr(0,
926  5 * lenTS); // add 2 dummy bits for the charge (not stored in NN)
927  TRG2DFinderTrack trk2D = decode2DTrack(strTrack, iTracker);
928  B2DEBUG(15, "NNIn phi0:" << trk2D.phi0 << ", omega:" << trk2D.omega
929  << ", at clock " << iclock << ", tracker " << iTracker);
930  B2DEBUG(300, "Content of new infobits: " << infobits);
931  std::vector<bool> foundoldtrack;
932  std::vector<bool> driftthreshold;
933  bool valstereobit;
934  unsigned i = 0;
935  for (i = 0; i < 6; i++) {
936  if (infobits.substr(i, 1) == "1") {
937  foundoldtrack.push_back(true);
938  } else if (infobits.substr(i, 1) == "0") {
939  foundoldtrack.push_back(false);
940  } else {
941  B2WARNING("Invalid input in NNBitstream appending 'false'!");
942  foundoldtrack.push_back(false);
943  }
944  }
945  i = 6;
946  if (infobits.substr(i, 1) == "1") {
947  valstereobit = true;
948  } else if (infobits.substr(i, 1) == "0") {
949  valstereobit = false;
950  } else {
951  B2WARNING("Invalid input in NNBitstream appending 'false'!");
952  valstereobit = false;
953  }
954  for (i = 7; i < 16; i++) {
955  if (infobits.substr(i, 1) == "1") {
956  driftthreshold.push_back(true);
957  } else if (infobits.substr(i, 1) == "0") {
958  driftthreshold.push_back(false);
959  } else {
960  B2WARNING("Invalid input in NNBitstream appending 'false'!");
961  driftthreshold.push_back(false);
962  }
963  }
964  B2DEBUG(15, "bits for foundoldtrack: " << foundoldtrack[0]
965  << foundoldtrack[1]
966  << foundoldtrack[2]
967  << foundoldtrack[3]
968  << foundoldtrack[4]
969  << foundoldtrack[5]);
970  B2DEBUG(15, "bits for driftthreshold: " << driftthreshold[0]
971  << driftthreshold[1]
972  << driftthreshold[2]
973  << driftthreshold[3]
974  << driftthreshold[4]
975  << driftthreshold[5]
976  << driftthreshold[6]
977  << driftthreshold[7]
978  << driftthreshold[8]);
979  B2DEBUG(15, "bits for valstereobit: " << valstereobit);
980 
981  // check if 2D track is already in list, otherwise add it
982  //for (int itrack = 0; itrack < store2DTracks->getEntries(); ++itrack) {
983  // if ((*store2DTracks)[itrack]->getPhi0() == trk2D->phi0 &&
984  // (*store2DTracks)[itrack]->getOmega() == trk2D->omega) {
985  // track2D = (*store2DTracks)[itrack];
986  // B2DEBUG(15, "found 2D track in store with phi " << trk2D->phi0 << " omega " << trk2D->omega);
987  // break;
988  // }
989  //}
990  B2DEBUG(15, "make new 2D track with phi " << trk2D.phi0 << " omega " << trk2D.omega << " clock " << iclock);
991  track2D = store2DTracks->appendNew(trk2D.phi0, trk2D.omega, 0., foundoldtrack, driftthreshold, valstereobit, iclock, iTracker);
992  // add axial hits and create relations
993  for (unsigned iAx = 0; iAx < nAxialTSF; ++iAx) {
994  const auto& ts = trk2D.ts[iAx];
995  if (ts[3] > 0) {
996  CDCTriggerSegmentHit* hit =
997  addTSHit(ts, 2 * iAx, iTracker, tsHits, iclock);
998  track2D->addRelationTo(hit);
999  }
1000  }
1001  // TODO: decode event time
1002  }
1003  return track2D;
1004  }
1005 
1026  void decodeNNOutput_old(short foundTime,
1027  unsigned iTracker,
1028  NNBitStream* bitsOut,
1029  NNBitStream* bitsSelectTS,
1030  StoreArray<CDCTriggerTrack>* storeNNTracks,
1031  StoreArray<CDCTriggerSegmentHit>* tsHits,
1032  StoreArray<CDCTriggerMLPInput>* storeNNInputs,
1033  CDCTriggerTrack* track2D)
1034  {
1035  const auto slvOut = bitsOut->signal()[iTracker];
1036  std::string strTrack = slv_to_bin_string(slvOut);
1037  strTrack = strTrack.substr(496, 570);
1038  const auto slvSelect = bitsSelectTS->signal()[iTracker];
1039  std::string strSelect = slv_to_bin_string(slvSelect);
1040  strSelect = strSelect.substr(496, 570);
1041  TRGNeuroTrack trkNN = decodeNNTrack_old(strTrack, strSelect);
1042  B2DEBUG(15, "make new NN track with , z:" << trkNN.z << ", theta:" << trkNN.theta <<
1043  ", sector:" << trkNN.sector << ", clock " << foundTime);
1044  double phi0 = 0;
1045  double omega = 0;
1046  if (track2D) {
1047  phi0 = track2D->getPhi0();
1048  omega = track2D->getOmega();
1049  }
1050  std::vector<unsigned> tsvector(9, 0);
1051  for (unsigned iSL = 0; iSL < 9; ++iSL) {
1052  tsvector[iSL] = trkNN.ts[iSL][2]; // save lr info in tsvector array
1053  }
1054  CDCTriggerTrack* trackNN = storeNNTracks->appendNew(phi0, omega, 0.,
1055  trkNN.z, cos(trkNN.theta) / sin(trkNN.theta), 0., track2D->getFoundOldTrack(), track2D->getDriftThreshold(),
1056  track2D->getValidStereoBit(), trkNN.sector, tsvector, foundTime, iTracker);
1057  std::vector<float> inputVector(27, 0.);
1058  for (unsigned iSL = 0; iSL < 9; ++iSL) {
1059  inputVector[3 * iSL] = trkNN.inputID[iSL];
1060  inputVector[3 * iSL + 1] = trkNN.inputT[iSL];
1061  inputVector[3 * iSL + 2] = trkNN.inputAlpha[iSL];
1062  }
1063  CDCTriggerMLPInput* storeInput =
1064  storeNNInputs->appendNew(inputVector, trkNN.sector);
1065  trackNN->addRelationTo(storeInput);
1066  track2D->addRelationTo(trackNN);
1067 
1068  for (unsigned iSL = 0; iSL < 9; ++iSL) {
1069  if (trkNN.ts[iSL][3] > 0) {
1070  CDCTriggerSegmentHit* hit = addTSHit(trkNN.ts[iSL], iSL, iTracker, tsHits, foundTime);
1071  trackNN->addRelationTo(hit);
1072  }
1073  }
1074  }
1075 
1093  void decodeNNIO(
1094  StoreArray<CDCTriggerUnpacker::NNBitStream>* bitsNN,
1095  StoreArray<CDCTriggerTrack>* store2DTracks,
1096  StoreArray<CDCTriggerTrack>* storeNNTracks,
1097  StoreArray<CDCTriggerSegmentHit>* tsHits,
1098  StoreArray<CDCTriggerSegmentHit>* tsHitsAll,
1099  StoreArray<CDCTriggerMLPInput>* storeNNInputs,
1100  StoreObjPtr<BinnedEventT0> storeETFTime,
1101  const DBObjPtr<CDCTriggerNeuroConfig> neurodb,
1102  bool sim13dt)
1103  {
1104  for (unsigned iTracker = 0; iTracker < nTrackers; ++iTracker) {
1105  B2DEBUG(21, "----------------------------------------------------------------------------------------------------");
1106  B2DEBUG(21, padright(" Unpacking Tracker: " + std::to_string(iTracker), 100));
1107  // loop over boards belonging to geometrical sectors
1108 
1109  for (short iclock = 0; iclock < bitsNN->getEntries(); ++iclock) {
1110  // check for NNEnable bit:
1111  B2LDataField p_nnenable(bitsNN, iclock, iTracker, neurodb->getB2FormatLine("NNEnable"));
1112  if (p_nnenable.name == "None") {
1113  B2DEBUG(5, "Neurotrigger: NNENable position unknown, skipping ... ");
1114  continue;
1115  } else if (p_nnenable.data == "1") {
1116  B2DEBUG(10, padright("Tracker: " + std::to_string(iTracker) + ", Clock: " + std::to_string(iclock) + " : NNEnable set!", 100));
1117  } else {
1118  B2DEBUG(21, padright(" UnpackerClock: " + std::to_string(iclock), 100));
1119  }
1120 
1121 
1122  CDCTriggerNeuroConfig::B2FormatLine nnall;
1123  nnall.start = 0;
1124  nnall.end = 2047;
1125  nnall.offset = 0;
1126  nnall.name = "nnall";
1127  B2LDataField p_nnall(bitsNN, iclock, iTracker, nnall);
1128  B2DEBUG(22, padright(" all bits: ", 100));
1129  B2DEBUG(22, padright(" " + p_nnall.data, 100));
1130  // define variables to fill from the bitstream, B2LDataField holds just the string, not the unpacked data yet
1131  B2LDataField p_driftthreshold(bitsNN, iclock, iTracker, neurodb->getB2FormatLine("DriftThreshold"));
1132  if ((p_driftthreshold.name != "None") && (p_driftthreshold.data.size() == 0)) {
1133  B2DEBUG(10, "Could not load Datafield: " << p_driftthreshold.name << " from bitstream. Maybe offset was out of bounds? clock: " <<
1134  iclock);
1135  continue;
1136  }
1137 
1138  B2LDataField p_valstereobit(bitsNN, iclock, iTracker, neurodb->getB2FormatLine("ValStereoBit"));
1139  if ((p_valstereobit.name != "None") && (p_valstereobit.data.size() == 0)) {
1140  B2DEBUG(10, "Could not load Datafield: " << p_valstereobit.name << " from bitstream. Maybe offset was out of bounds? clock: " <<
1141  iclock);
1142  continue;
1143  }
1144 
1145  B2LDataField p_foundoldtrack(bitsNN, iclock, iTracker, neurodb->getB2FormatLine("FoundOldTrack"));
1146  if ((p_foundoldtrack.name != "None") && (p_foundoldtrack.data.size() == 0)) {
1147  B2DEBUG(10, "Could not load Datafield: " << p_foundoldtrack.name << " from bitstream. Maybe offset was out of bounds? clock: " <<
1148  iclock);
1149  continue;
1150  }
1151 
1152  B2LDataField p_phi(bitsNN, iclock, iTracker, neurodb->getB2FormatLine("Phi"));
1153  if ((p_phi.name != "None") && (p_phi.data.size() == 0)) {
1154  B2DEBUG(10, "Could not load Datafield: " << p_phi.name << " from bitstream. Maybe offset was out of bounds? clock: " << iclock);
1155  continue;
1156  }
1157 
1158  B2LDataField p_omega(bitsNN, iclock, iTracker, neurodb->getB2FormatLine("Omega"));
1159  if ((p_omega.name != "None") && (p_omega.data.size() == 0)) {
1160  B2DEBUG(10, "Could not load Datafield: " << p_omega.name << " from bitstream. Maybe offset was out of bounds? clock: " << iclock);
1161  continue;
1162  }
1163 
1164  B2LDataField p_ts8(bitsNN, iclock, iTracker, neurodb->getB2FormatLine("TS8"));
1165  if ((p_ts8.name != "None") && (p_ts8.data.size() == 0)) {
1166  B2DEBUG(10, "Could not load Datafield: " << p_ts8.name << " from bitstream. Maybe offset was out of bounds? clock: " << iclock);
1167  continue;
1168  }
1169 
1170  B2LDataField p_ts6(bitsNN, iclock, iTracker, neurodb->getB2FormatLine("TS6"));
1171  if ((p_ts6.name != "None") && (p_ts6.data.size() == 0)) {
1172  B2DEBUG(10, "Could not load Datafield: " << p_ts6.name << " from bitstream. Maybe offset was out of bounds? clock: " << iclock);
1173  continue;
1174  }
1175 
1176  B2LDataField p_ts4(bitsNN, iclock, iTracker, neurodb->getB2FormatLine("TS4"));
1177  if ((p_ts4.name != "None") && (p_ts4.data.size() == 0)) {
1178  B2DEBUG(10, "Could not load Datafield: " << p_ts4.name << " from bitstream. Maybe offset was out of bounds? clock: " << iclock);
1179  continue;
1180  }
1181 
1182  B2LDataField p_ts2(bitsNN, iclock, iTracker, neurodb->getB2FormatLine("TS2"));
1183  if ((p_ts2.name != "None") && (p_ts2.data.size() == 0)) {
1184  B2DEBUG(10, "Could not load Datafield: " << p_ts2.name << " from bitstream. Maybe offset was out of bounds? clock: " << iclock);
1185  continue;
1186  }
1187 
1188  B2LDataField p_ts0(bitsNN, iclock, iTracker, neurodb->getB2FormatLine("TS0"));
1189  if ((p_ts0.name != "None") && (p_ts0.data.size() == 0)) {
1190  B2DEBUG(10, "Could not load Datafield: " << p_ts0.name << " from bitstream. Maybe offset was out of bounds? clock: " << iclock);
1191  continue;
1192  }
1193 
1194  B2LDataField p_tsf1(bitsNN, iclock, iTracker, neurodb->getB2FormatLine("TSF1"));
1195  if ((p_tsf1.name != "None") && (p_tsf1.data.size() == 0)) {
1196  B2DEBUG(10, "Could not load Datafield: " << p_tsf1.name << " from bitstream. Maybe offset was out of bounds? clock: " << iclock);
1197  continue;
1198  }
1199 
1200  B2LDataField p_tsf3(bitsNN, iclock, iTracker, neurodb->getB2FormatLine("TSF3"));
1201  if ((p_tsf3.name != "None") && (p_tsf3.data.size() == 0)) {
1202  B2DEBUG(10, "Could not load Datafield: " << p_tsf3.name << " from bitstream. Maybe offset was out of bounds? clock: " << iclock);
1203  continue;
1204  }
1205 
1206  B2LDataField p_tsf5(bitsNN, iclock, iTracker, neurodb->getB2FormatLine("TSF5"));
1207  if ((p_tsf5.name != "None") && (p_tsf5.data.size() == 0)) {
1208  B2DEBUG(10, "Could not load Datafield: " << p_tsf5.name << " from bitstream. Maybe offset was out of bounds? clock: " << iclock);
1209  continue;
1210  }
1211 
1212  B2LDataField p_tsf7(bitsNN, iclock, iTracker, neurodb->getB2FormatLine("TSF7"));
1213  if ((p_tsf7.name != "None") && (p_tsf7.data.size() == 0)) {
1214  B2DEBUG(10, "Could not load Datafield: " << p_tsf7.name << " from bitstream. Maybe offset was out of bounds? clock: " << iclock);
1215  continue;
1216  }
1217 
1218  B2LDataField p_tsfsel(bitsNN, iclock, iTracker, neurodb->getB2FormatLine("TSFsel"));
1219  if ((p_tsfsel.name != "None") && (p_tsfsel.data.size() == 0)) {
1220  B2DEBUG(10, "Could not load Datafield: " << p_tsfsel.name << " from bitstream. Maybe offset was out of bounds? clock: " << iclock);
1221  continue;
1222  }
1223 
1224  B2LDataField p_mlpin_alpha(bitsNN, iclock, iTracker, neurodb->getB2FormatLine("MLPIn_alpha"));
1225  if ((p_mlpin_alpha.name != "None") && (p_mlpin_alpha.data.size() == 0)) {
1226  B2DEBUG(10, "Could not load Datafield: " << p_mlpin_alpha.name << " from bitstream. Maybe offset was out of bounds? clock: " <<
1227  iclock);
1228  continue;
1229  }
1230 
1231  B2LDataField p_mlpin_drifttime(bitsNN, iclock, iTracker, neurodb->getB2FormatLine("MLPIn_driftt"));
1232  if ((p_mlpin_drifttime.name != "None") && (p_mlpin_drifttime.data.size() == 0)) {
1233  B2DEBUG(10, "Could not load Datafield: " << p_mlpin_drifttime.name << " from bitstream. Maybe offset was out of bounds? clock: " <<
1234  iclock);
1235  continue;
1236  }
1237 
1238  B2LDataField p_mlpin_id(bitsNN, iclock, iTracker, neurodb->getB2FormatLine("MLPIn_id"));
1239  if ((p_mlpin_id.name != "None") && (p_mlpin_id.data.size() == 0)) {
1240  B2DEBUG(10, "Could not load Datafield: " << p_mlpin_id.name << " from bitstream. Maybe offset was out of bounds? clock: " <<
1241  iclock);
1242  continue;
1243  }
1244 
1245  B2LDataField p_netsel(bitsNN, iclock, iTracker, neurodb->getB2FormatLine("Netsel"));
1246  if ((p_netsel.name != "None") && (p_netsel.data.size() == 0)) {
1247  B2DEBUG(10, "Could not load Datafield: " << p_netsel.name << " from bitstream. Maybe offset was out of bounds? clock: " << iclock);
1248  continue;
1249  }
1250 
1251  B2LDataField p_mlpout_z(bitsNN, iclock, iTracker, neurodb->getB2FormatLine("MLPOut_z"));
1252  if ((p_mlpout_z.name != "None") && (p_mlpout_z.data.size() == 0)) {
1253  B2DEBUG(10, "Could not load Datafield: " << p_mlpout_z.name << " from bitstream. Maybe offset was out of bounds? clock: " <<
1254  iclock);
1255  continue;
1256  }
1257 
1258  B2LDataField p_mlpout_theta(bitsNN, iclock, iTracker, neurodb->getB2FormatLine("MLPOut_theta"));
1259  if ((p_mlpout_theta.name != "None") && (p_mlpout_theta.data.size() == 0)) {
1260  B2DEBUG(10, "Could not load Datafield: " << p_mlpout_theta.name << " from bitstream. Maybe offset was out of bounds? clock: " <<
1261  iclock);
1262  continue;
1263  }
1264 
1265  B2LDataField p_2dcc(bitsNN, iclock, iTracker, neurodb->getB2FormatLine("2dcc"));
1266  if ((p_2dcc.name != "None") && (p_2dcc.data.size() == 0)) {
1267  B2DEBUG(10, "Could not load Datafield: " << p_2dcc.name << " from bitstream. Maybe offset was out of bounds? clock: " << iclock);
1268  continue;
1269  }
1270 
1271  B2LDataField p_extendedpts(bitsNN, iclock, iTracker, neurodb->getB2FormatLine("extendedPriorityTimes"));
1272  if ((p_extendedpts.name != "None") && (p_extendedpts.data.size() == 0)) {
1273  B2DEBUG(10, "Could not load Datafield: " << p_extendedpts.name << " from bitstream. Maybe offset was out of bounds? clock: " <<
1274  iclock);
1275  continue;
1276  }
1277  B2LDataField p_etftime(bitsNN, iclock, iTracker, neurodb->getB2FormatLine("etftime"));
1278  if ((p_etftime.name != "None") && (p_etftime.data.size() == 0)) {
1279  B2DEBUG(10, "Could not load Datafield: " << p_etftime.name << " from bitstream. Maybe offset was out of bounds? clock: " <<
1280  iclock);
1281  continue;
1282  }
1283  B2LDataField p_etfcc(bitsNN, iclock, iTracker, neurodb->getB2FormatLine("etfcc"));
1284  if ((p_etfcc.name != "None") && (p_etfcc.data.size() == 0)) {
1285  B2DEBUG(10, "Could not load Datafield: " << p_etfcc.name << " from bitstream. Maybe offset was out of bounds? clock: " <<
1286  iclock);
1287  continue;
1288  }
1289  B2LDataField p_etfqual(bitsNN, iclock, iTracker, neurodb->getB2FormatLine("etfquality"));
1290  if ((p_etfqual.name != "None") && (p_etfqual.data.size() == 0)) {
1291  B2DEBUG(10, "Could not load Datafield: " << p_etfqual.name << " from bitstream. Maybe offset was out of bounds? clock: " <<
1292  iclock);
1293  continue;
1294  }
1295  B2LDataField p_etfval(bitsNN, iclock, iTracker, neurodb->getB2FormatLine("etfvalid"));
1296  if ((p_etfval.name != "None") && (p_etfval.data.size() == 0)) {
1297  B2DEBUG(10, "Could not load Datafield: " << p_etfval.name << " from bitstream. Maybe offset was out of bounds? clock: " <<
1298  iclock);
1299  continue;
1300  }
1301 
1302  // B2LDataField (bitsNN, iclock, iTracker, neurodb->getB2FormatLine(""));
1303 
1304  CDCTriggerTrack* track2D = nullptr;
1305  // decode stereo hits
1306  if (true) { // (p_nnenable.data == "1") {
1307  unsigned sln = 0;
1308  B2DEBUG(21, padright(" Stereos: ", 100));
1309  for (auto stereolayer : {p_tsf1, p_tsf3, p_tsf5, p_tsf7}) {
1310  if (stereolayer.name == "None") {
1311  B2ERROR("Error in CDCTriggerNeuroConfig Payload, position of stereo tsf could not be found!");
1312  continue;
1313  }
1314  std::string tsstr = " | ";
1315  for (unsigned iHit = 0; iHit < 10; ++iHit) {
1316  tsOut ts = (sim13dt) ? decodeTSHit_sim(stereolayer.data.substr(iHit * lenTS, lenTS),
1317  p_2dcc.data) : decodeTSHit(stereolayer.data.substr(iHit * lenTS, lenTS));
1318  if (ts[3] > 0) { // if it is 0, it means 'no hit'
1319  unsigned iTS = TSIDInSL(ts[0], sln * 2 + 1, iTracker);
1320  tsstr += std::to_string(iTS) + ", " + std::to_string(ts[1]) + ", " + std::to_string(ts[2]) + ", " + std::to_string(ts[3]) + " | ";
1321  addTSHit(ts, sln * 2 + 1, iTracker, tsHitsAll, iclock);
1322  }
1323  }
1324  B2DEBUG(21, padright(" SL" + std::to_string(sln * 2 + 1) + tsstr, 100));
1325  ++sln;
1326  }
1327  }
1328  B2DEBUG(21, padright(" 2DCC: " + std::to_string(std::stoi(p_2dcc.data, 0, 2)) + ", (" + p_2dcc.data + ")", 100));
1329  B2DEBUG(21, padright(" ETFCC: " + std::to_string(std::stoi(p_etfcc.data, 0, 2)) + ", (" + p_etfcc.data + ")", 100));
1330  B2DEBUG(21, padright(" ETFVAL: " + std::to_string(std::stoi(p_etfval.data, 0, 2)) + ", (" + p_etfval.data + ")", 100));
1331  B2DEBUG(21, padright(" ETFT0: " + std::to_string(std::stoi(p_etftime.data, 0, 2)) + ", (" + p_etftime.data + ")", 100));
1332  B2DEBUG(21, padright(" ETFQuality: " + std::to_string(std::stoi(p_etfqual.data, 0, 2)) + ", (" + p_etfqual.data + ")", 100));
1333  if (p_nnenable.data == "1") {
1334  bool hasETFTime = false;
1335  if (p_etfval.data == "1") {
1336  storeETFTime->addBinnedEventT0(std::stoi(p_etftime.data, 0, 2), Const::CDC);
1337  hasETFTime = true;
1338  }
1339  std::vector<bool> foundoldtrack{false};
1340  std::vector<bool> driftthreshold{false};
1341  bool valstereobit;
1342  if (p_foundoldtrack.name != "None") {
1343  foundoldtrack = decodefoundoldtrack(p_foundoldtrack.data);
1344  }
1345  if (p_driftthreshold.name != "None") {
1346  driftthreshold = decodedriftthreshold(p_driftthreshold.data);
1347  }
1348  if (p_valstereobit.name != "None") {
1349  valstereobit = decodevalstereobit(p_valstereobit.data);
1350  }
1351 
1352  if (std::all_of(p_phi.data.begin(), p_phi.data.end(), [](char i) {return i == 0;})) {
1353  B2ERROR("Empty Phi Value found for 2DTrack, should not happen!");
1354  continue;
1355  }
1356  TRG2DFinderTrack trk2D = decode2DTrack(
1357  "00", //charge
1358  p_omega.data,
1359  p_phi.data,
1360  p_ts0.data,
1361  p_ts2.data,
1362  p_ts4.data,
1363  p_ts6.data,
1364  p_ts8.data,
1365  iTracker,
1366  p_2dcc.data,
1367  sim13dt);
1368  track2D = store2DTracks->appendNew(trk2D.phi0, trk2D.omega, 0., foundoldtrack, driftthreshold, valstereobit, iclock, iTracker);
1369  track2D->setRawOmega(trk2D.hwOmega);
1370  track2D->setRawPhi0(trk2D.hwPhi0);
1371  B2DEBUG(12, padright(" 2DTrack: (phi=" + std::to_string(trk2D.phi0) + ", omega=" + std::to_string(
1372  trk2D.omega) + ", update=" + std::to_string(foundoldtrack[1]) + ")", 100));
1373 
1374  // add axial hits and create relations
1375  std::string tsstr;
1376  for (unsigned iAx = 0; iAx < nAxialTSF; ++iAx) {
1377  const auto& ts = trk2D.ts[iAx];
1378  if (ts[3] > 0) {
1379  CDCTriggerSegmentHit* hit =
1380  addTSHit(ts, 2 * iAx, iTracker, tsHitsAll, iclock);
1381  unsigned iTS = TSIDInSL(ts[0], iAx * 2, iTracker);
1382  tsstr += "(SL" + std::to_string(iAx * 2) + ", " + std::to_string(iTS) + ", " + std::to_string(ts[1]) + ", " + std::to_string(
1383  ts[2]) + ", " + std::to_string(ts[3]) + "),";
1384  track2D->addRelationTo(hit);
1385  }
1386  }
1387  B2DEBUG(16, padright(" 2DTrack TS: " + tsstr, 100));
1388 
1389 
1390  if (track2D) {
1391  TRGNeuroTrack trkNN;
1392  trkNN = decodeNNTrack(p_mlpout_z.data,
1393  p_mlpout_theta.data,
1394  p_tsfsel.data,
1395  p_mlpin_alpha.data,
1396  p_mlpin_drifttime.data,
1397  p_mlpin_id.data,
1398  p_netsel.data,
1399  neurodb,
1400  p_2dcc.data,
1401  sim13dt,
1402  p_extendedpts);
1403 
1404 
1405  B2DEBUG(11, padright(" NNTrack: (z=" + std::to_string(trkNN.z) + ", theta=" + std::to_string(trkNN.theta) + ")", 100));
1406 
1407  double phi0 = track2D->getPhi0();
1408  double omega = track2D->getOmega();
1409 
1410  std::vector<unsigned> tsvector(9, 0);
1411  std::vector<unsigned> tstimevector(9, 0);
1412  tsstr = "";
1413  // turns false, as soon as there is a ts, which is not contained in the 2dfindertrack
1414  bool isin2d = true;
1415  for (unsigned iSL = 0; iSL < 9; ++iSL) {
1416  tsvector[iSL] = trkNN.ts[iSL][3];
1417  tstimevector[iSL] = trkNN.ts[iSL][1];
1418  if (trkNN.ts[iSL][3] > 0) {
1419  unsigned iTS = TSIDInSL(trkNN.ts[iSL][0], iSL, iTracker);
1420  tsstr += "(SL" + std::to_string(iSL) + ", " + std::to_string(iTS) + ", " + std::to_string(trkNN.ts[iSL][1]) + ", " + std::to_string(
1421  trkNN.ts[iSL][2]) + ", " + std::to_string(trkNN.ts[iSL][3]) + "),\n";
1422  // check, wether axials are a subset of 2dfinderTS:
1423  if (iSL % 2 == 0) {
1424  if (!(trk2D.ts[iSL / 2][0] == trkNN.ts[iSL][0] &&
1425  //trk2D.ts[iSL / 2][1] == trkNN.ts[iSL][1] &&
1426  trk2D.ts[iSL / 2][2] == trkNN.ts[iSL][2] &&
1427  trk2D.ts[iSL / 2][3] == trkNN.ts[iSL][3])) {
1428  isin2d = false;
1429  }
1430  }
1431 
1432  } else {
1433  tsstr += "( - ),\n";
1434  }
1435  }
1436 
1437  B2DEBUG(15, padright(" NNTrack TS: " + tsstr, 100));
1438 
1439  CDCTriggerTrack* trackNN = storeNNTracks->appendNew(phi0, omega, 0.,
1440  trkNN.z, cos(trkNN.theta) / sin(trkNN.theta), 0., track2D->getFoundOldTrack(), track2D->getDriftThreshold(),
1441  track2D->getValidStereoBit(), trkNN.sector, tsvector, iclock, iTracker);
1442  trackNN->setHasETFTime(hasETFTime);
1443  track2D->setHasETFTime(hasETFTime);
1444  trackNN->setRawOmega(track2D->getRawOmega());
1445  trackNN->setRawPhi0(track2D->getRawPhi0());
1446  trackNN->setRawTheta(trkNN.hwTheta);
1447  trackNN->setRawZ(trkNN.hwZ);
1448  if (hasETFTime) {
1449  trackNN->setETF_unpacked(std::stoi(p_etftime.data, 0, 2));
1450  track2D->setETF_unpacked(std::stoi(p_etftime.data, 0, 2));
1451  }
1452  trackNN->setETF_recalced(recalcETF(p_mlpin_drifttime.data, tstimevector, trackNN));
1453  track2D->setETF_recalced(recalcETF(p_mlpin_drifttime.data, tstimevector, trackNN));
1454 
1455  if (isin2d == false) {
1456  trackNN->setQualityVector(1);
1457  }
1458  std::vector<float> inputVector(27, 0.);
1459  std::vector<int> rawinputVector(27, 0.);
1460  for (unsigned iSL = 0; iSL < 9; ++iSL) {
1461  inputVector[3 * iSL] = trkNN.inputID[iSL];
1462  inputVector[3 * iSL + 1] = trkNN.inputT[iSL];
1463  inputVector[3 * iSL + 2] = trkNN.inputAlpha[iSL];
1464  rawinputVector[3 * iSL] = trkNN.rawinputID[iSL];
1465  rawinputVector[3 * iSL + 1] = trkNN.rawinputT[iSL];
1466  rawinputVector[3 * iSL + 2] = trkNN.rawinputAlpha[iSL];
1467  }
1468  trackNN->setRawInput(rawinputVector);
1469 
1470  CDCTriggerMLPInput* storeInput =
1471  storeNNInputs->appendNew(inputVector, trkNN.sector);
1472  trackNN->addRelationTo(storeInput);
1473  track2D->addRelationTo(trackNN);
1474 
1475  for (unsigned iSL = 0; iSL < 9; ++iSL) {
1476  if (trkNN.ts[iSL][3] > 0) {
1477  CDCTriggerSegmentHit* hit = nullptr;
1478  // if (sim13dt) {
1479  // // get extended priority time for stereos from the allstereots storearray
1480  // for (int ihit = 0; ihit<tsHitsAll->getEntries(); ++ihit) {
1481  // CDCTriggerSegmentHit* compare = (*tsHitsAll)[ihit];
1482  // if (compare->getISuperLayer() == iSL &&
1483  // compare->getIWireCenter() == TSIDInSL(trkNN.ts[iSL][0], iSL, iTracker) &&
1484  // compare->getPriorityPosition() == trkNN.ts[iSL][3] &&
1485  // compare->getLeftRight() == trkNN.ts[iSL][2] ) {
1486  // hit = compare;
1487  // }
1488  // }
1489  // if (!(!hit)) {
1490  // tsHits->appendNew(hit->getISuperLayer(), hit->getIWireCenter(), hit->getPriorityPosition(), hit->getLeftRight(), hit->priorityTime(), 0, hit->foundTime(), iTracker);
1491  // }
1492  // // get the extended pt for axials from the already existing 2d TS
1493  // for (int ihit = 0; ihit<tsHits->getEntries(); ++ihit) {
1494  // CDCTriggerSegmentHit* compare = (*tsHits)[ihit];
1495  // if (compare->getISuperLayer() == iSL &&
1496  // compare->getIWireCenter() == TSIDInSL(trkNN.ts[iSL][0], iSL, iTracker) &&
1497  // compare->getPriorityPosition() == trkNN.ts[iSL][3] &&
1498  // compare->getLeftRight() == trkNN.ts[iSL][2] ) {
1499  // hit = compare;
1500  // }
1501  // }
1502 
1503  // }
1504 
1505  // cppcheck-suppress knownConditionTrueFalse
1506  if (!hit) {
1507  hit = addTSHit(trkNN.ts[iSL], iSL, iTracker, tsHits, iclock);
1508  // B2DEBUG(1, "Hit with short drift time added, should not happen!");
1509  // }
1510  }
1511  trackNN->addRelationTo(hit);
1512  if (iSL % 2 == 0) {
1513  track2D->addRelationTo(hit);
1514  }
1515  }
1516  }
1517  }
1518 
1519 
1520  //
1521  // B2DEBUG(15, "bits for foundoldtrack: ");
1522  // for (auto x : foundoldtrack) {
1523  // B2DEBUG(15, x);
1524  // }
1525  // B2DEBUG(15, "bits for driftthreshold: ");
1526  // for (auto x : driftthreshold) {
1527  // B2DEBUG(15, x);
1528  // }
1529  // B2DEBUG(15, "bits for valstereobit: " << valstereobit);
1530  // B2DEBUG(15, "make new 2D track with phi " << trk2D.phi0 << " omega " << trk2D.omega << " clock " << iclock);
1531 
1532  }
1533  }
1534  }
1535  }
1536 
1537  void decodeNNIO_old(
1538  StoreArray<CDCTriggerUnpacker::NNBitStream>* bitsNN,
1539  StoreArray<CDCTriggerTrack>* store2DTracks,
1540  StoreArray<CDCTriggerTrack>* storeNNTracks,
1541  StoreArray<CDCTriggerSegmentHit>* tsHits,
1542  StoreArray<CDCTriggerMLPInput>* storeNNInputs)
1543  {
1544  for (short iclock = 0; iclock < bitsNN->getEntries(); ++iclock) {
1545  NNBitStream* bitsIn = (*bitsNN)[iclock];
1546  NNBitStream* bitsOutEnable = (*bitsNN)[iclock];
1547  for (unsigned iTracker = 0; iTracker < nTrackers; ++iTracker) {
1548  const auto slvOutEnable = bitsOutEnable->signal()[iTracker];
1549  const auto slvIn = bitsIn->signal()[iTracker];
1550  std::string stringOutEnable = slv_to_bin_string(slvOutEnable); //.substr(NN_OUT_WIDTH - 570, NN_OUT_WIDTH);
1551  std::string stringIn = slv_to_bin_string(slvIn); //.substr(NN_OUT_WIDTH - 570, NN_OUT_WIDTH);
1552  if (stringOutEnable.c_str()[0] == '1') {
1553  CDCTriggerTrack* nntrack2D = decodeNNInput(iclock, iTracker, bitsIn, store2DTracks, tsHits);
1554  if (nntrack2D) {
1555  int foundTime = iclock;
1556  if (foundTime < bitsNN->getEntries()) {
1557  NNBitStream* bitsOut = (*bitsNN)[foundTime];
1558  NNBitStream* bitsSelectTS = (*bitsNN)[iclock];
1559  decodeNNOutput_old(iclock, iTracker, bitsOut, bitsSelectTS,
1560  storeNNTracks, tsHits, storeNNInputs,
1561  nntrack2D);
1562  }
1563  }
1564  }
1565  }
1566  }
1567  }
1568  }
1570 }
Class to hold one clock cycle of raw bit content.
Definition: Bitstream.h:54
const SignalBus & signal()
accessors
Definition: Bitstream.h:70
static const double speedOfLight
[cm/ns]
Definition: Const.h:686
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
static const double realNaN
constant for double NaN
double atan(double a)
atan for double
Definition: beamHelpers.h:34
Abstract base class for different kinds of events.
const char one_val
'1' in XSI VHDL simulation
Definition: Cosim.h:43
const char * std_logic_literal[]
In case you are not familiar with VHDL simulation, there are 9 possible values defined for the standa...
Definition: Cosim.h:40
std::bitset< max - min+1 > subset(std::bitset< nbits > set)
extract a subset of bitstring, like substring.
Definition: Cosim.h:120
const char zero_val
'0' in XSI VHDL simulation
Definition: Cosim.h:45
std::string slv_to_bin_string(std::array< char, N > signal, bool padding=false)
Transform into string.
Definition: Cosim.h:64
void display_hex(const std::array< char, N > &signal)
Display signal in hex.
Definition: Cosim.h:81
std::string display_value(const char *count, int size)
Display value of the signal.
Definition: Cosim.h:48
std::string name
name of information in B2link
int offset
offset of information in B2Link
tsOutArray ts
all TS of a 2D track
Definition: Unpacker.h:261
int hwZ
raw output values of hw network
Definition: Unpacker.h:286
std::array< float, 9 > inputT
input T list of a NN track
Definition: Unpacker.h:278
std::array< float, 9 > inputAlpha
input Alpha list of a NN track
Definition: Unpacker.h:281
unsigned sector
sector of a NN track
Definition: Unpacker.h:273
std::array< float, 9 > inputID
input ID list of a NN track
Definition: Unpacker.h:275
std::array< tsOut, 9 > ts
input TS list of a NN track
Definition: Unpacker.h:284
double theta
theta of a NN track
Definition: Unpacker.h:271