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>
32 namespace CDCTriggerUnpacker {
34 constexpr
double pi() {
return std::atan(1) * 4; }
37 static constexpr std::array<int, 9> nMergers = {10, 10, 12, 14, 16, 18, 20, 22, 24};
42 static constexpr
int TSFOutputWidth = TSF_TO_2D_WIDTH;
43 static constexpr
int nTrackers = NUM_2D;
44 static constexpr
int nAxialTSF = NUM_TSF;
45 static constexpr
int nStereoTSF = 4;
46 static constexpr
int T2DOutputWidth = T2D_TO_3D_WIDTH;
47 static constexpr
unsigned lenTS = 21;
49 static constexpr
int nMax2DTracksPerClock = 4;
52 static constexpr
int clockCounterWidth = 9;
55 static constexpr std::array<int, nAxialTSF> nAxialMergers = {10, 12, 16, 20, 24};
57 static constexpr std::array<int, 9> nWiresInSuperLayer = {
58 160, 160, 192, 224, 256, 288, 320, 352, 384
61 static constexpr
int nCellsInLayer = 16;
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>;
69 using T2DOutputVector = std::array<char, T2DOutputWidth>;
70 using T2DOutputBus = std::array<T2DOutputVector, nTrackers>;
71 using T2DOutputBitStream = Bitstream<T2DOutputBus>;
73 using NNVector = std::array<char, NN_WIDTH>;
74 using NNBus = std::array<NNVector, nTrackers>;
75 using NNBitStream = Bitstream<NNBus>;
85 std::string padto(std::string s,
unsigned l)
88 s.insert(s.begin(), l - s.size(),
' ');
92 std::string padright(std::string s,
unsigned l)
95 s.insert(s.end(), l - s.size(),
' ');
100 void printBuffer(
int* buf,
int nwords)
102 for (
int j = 0; j < nwords; ++j) {
103 printf(
" %.8x", buf[j]);
104 if ((j + 1) % 8 == 0) {
112 std::string rawIntToAscii(
int buf)
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));
121 firmwareTypeIStream >> std::hex >> character;
122 firmwareType[i] = character;
127 std::string rawIntToString(
int buf)
129 std::ostringstream firmwareVersionStream;
130 firmwareVersionStream << std::hex << buf;
131 return firmwareVersionStream.str();
157 char std_logic(
bool inBit)
169 for (
int i = 0; i < size; i++) {
170 if (count[i] >= 0 && count[i] < 9) {
173 B2DEBUG(20,
"invalid signal detected: " <<
static_cast<int>(count[i]));
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) {
189 B2DEBUG(20,
"invalid signal detected: " <<
static_cast<int>(bit));
197 void display_hex(
const std::array<char, N>& signal)
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.");
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();
215 std::cout.copyfmt(oldState);
225 template<
size_t nbits,
size_t min,
size_t max>
226 std::bitset < max - min + 1 >
subset(std::bitset<nbits> set)
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));
241 unsigned short globalSegmentID(
unsigned short localID,
unsigned short iSL)
243 auto itr = nWiresInSuperLayer.begin();
244 unsigned short globalID = std::accumulate(itr, itr + iSL, 0);
249 static const double realNaN = std::numeric_limits<double>::quiet_NaN();
251 using tsOut = std::array<unsigned, 4>;
252 using tsOutArray = std::array<tsOut, 5>;
276 std::array<int, 9> rawinputID;
279 std::array<int, 9> rawinputT;
282 std::array<int, 9> rawinputAlpha;
284 std::array<tsOut, 9>
ts;
296 if (
int(b2line.
offset + foundtime) >= 0 &&
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);
317 std::vector<bool> decodedriftthreshold(std::string p_driftthreshold)
319 std::vector<bool> res;
320 for (
unsigned i = 0; i < p_driftthreshold.size(); ++i) {
321 if (p_driftthreshold.substr(i, 1) ==
"1") {
323 }
else if (p_driftthreshold.substr(i, 1) ==
"0") {
324 res.push_back(
false);
326 B2WARNING(
"Invalid input in NNBitstream appending 'false'!");
327 res.push_back(
false);
332 std::vector<bool> decodefoundoldtrack(std::string p_foundoldtrack)
334 std::vector<bool> res;
335 for (
unsigned i = 0; i < p_foundoldtrack.size(); ++i) {
336 if (p_foundoldtrack.substr(i, 1) ==
"1") {
338 }
else if (p_foundoldtrack.substr(i, 1) ==
"0") {
339 res.push_back(
false);
341 B2WARNING(
"Invalid input in NNBitstream appending 'false'!");
342 res.push_back(
false);
347 bool decodevalstereobit(
const std::string& p_valstereobit)
350 if (p_valstereobit ==
"1") {
352 }
else if (p_valstereobit ==
"0") {
355 B2WARNING(
"Invalid input in NNBitstream appending 'false'!");
371 unsigned TSIDInSL(
unsigned tsIDInTracker,
unsigned iSL,
unsigned iTracker)
373 const unsigned nCellsInSL = nMergers[iSL] * nCellsInLayer;
375 unsigned iTS = tsIDInTracker + nCellsInSL * iTracker / nTrackers;
377 if (iTS >= nCellsInSL) {
392 int mlp_bin_to_signed_int(std::string signal)
394 constexpr
unsigned len = 13;
395 std::bitset<len> signal_bit(signal);
396 const unsigned shift = 16 - len;
399 int signal_out = (int16_t (signal_bit.to_ulong() << shift)) >> shift;
406 int recalcETF(std::string driftinput, std::vector<unsigned> tsvector, CDCTriggerTrack* track)
409 float scale = 1. / (1 << (driftinput.size() - 1) / 9);
415 std::vector<std::vector<int>> table;
416 for (
unsigned iSL = 0; iSL < 9; ++iSL) {
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]);
422 if (reldt != 0 && reldt < 255) {
423 for (std::vector<int>& x : table) {
425 if (x[0] == tstime - reldt) {
430 if (!stor) {table.push_back({tstime - reldt, 1});}
436 for (std::vector<int>& x : table) {
443 if (table.size() > 1) {track->setQualityVector(128);}
455 tsOut decodeTSHit(std::string tsIn)
457 constexpr
unsigned lenID = 8;
458 constexpr
unsigned lenPriorityTime = 9;
459 constexpr
unsigned lenLR = 2;
460 constexpr
unsigned lenPriorityPosition = 2;
461 constexpr std::array<unsigned, 4> tsLens = {
462 lenID, lenPriorityTime, lenLR, lenPriorityPosition
464 std::array<unsigned, 5> tsPos = { 0 };
465 std::partial_sum(tsLens.begin(), tsLens.end(), tsPos.begin() + 1);
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();
473 tsOut decodeTSHit_sim(std::string tsIn, std::string twodcc)
475 constexpr
unsigned lenID = 8;
476 constexpr
unsigned lenPriorityTime = 9;
477 constexpr
unsigned lenLR = 2;
478 constexpr
unsigned lenPriorityPosition = 2;
479 constexpr std::array<unsigned, 4> tsLens = {
480 lenID, lenPriorityTime, lenLR, lenPriorityPosition
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);
488 if (std::stoul(B, 0, 2) <= std::stoul(Bp, 0, 2)) {
491 B2DEBUG(14,
"2DCC overflow detected!");
492 pts = std::bitset<4>(std::stoul(Ap, 0, 2) - 1).to_string() + B + C;
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);
498 tsOutput[0] = std::bitset<tsLens[0]>(tsIn.substr(tsPos[0], tsLens[0])).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();
504 tsOut decodeTSHit_ext(std::string tsIn, std::string expt)
506 constexpr
unsigned lenID = 8;
507 constexpr
unsigned lenPriorityTime = 9;
508 constexpr
unsigned lenLR = 2;
509 constexpr
unsigned lenPriorityPosition = 2;
510 constexpr std::array<unsigned, 4> tsLens = {
511 lenID, lenPriorityTime, lenLR, lenPriorityPosition
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);
517 tsOutput[0] = std::bitset<tsLens[0]>(tsIn.substr(tsPos[0], tsLens[0])).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();
533 TRG2DFinderTrack decode2DTrack(
const std::string& p_charge __attribute__((unused)),
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,
542 const std::string& p_2dcc,
546 unsigned shift = 16 - p_omega.size();
547 TRG2DFinderTrack trackout;
548 int omega = std::stoi(p_omega, 0, 2);
551 int omegafirm = (int16_t (omega << shift)) >> shift;
552 trackout.hwOmega = omegafirm;
555 const double BField = 1.5e-4;
563 int phi = std::stoi(p_phi, 0, 2);
564 trackout.hwPhi0 = phi;
566 double globalPhi0 = pi() / 4 + pi() / 2 / 80 * (phi + 1) + pi() / 2 * iTracker;
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);
575 if (globalPhi0 > pi() * 2) {
576 globalPhi0 -= pi() * 2;
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));
586 TRG2DFinderTrack decode2DTrack(std::string trackIn,
unsigned iTracker)
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]));
599 int omegaFirm = (int16_t (omega.to_ulong() << shift)) >> shift;
600 trackOut.hwOmega = omegaFirm;
602 const double BField = 1.5e-4;
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));
615 double globalPhi0 = trackOut.phi0 + pi() / 2 * iTracker;
616 if (globalPhi0 > pi() * 2) {
617 globalPhi0 -= pi() * 2;
619 trackOut.phi0 = globalPhi0;
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,
641 B2LDataField p_extendedpts)
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));
673 foundTrack.ts[iSL] = decodeTSHit_sim(p_tsfsel.substr((8 - iSL) * lenTS, lenTS), p_2dcc);
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));
678 foundTrack.ts[iSL] = decodeTSHit(p_tsfsel.substr((8 - iSL) * lenTS, lenTS));
684 TRGNeuroTrack decodeNNTrack_old(std::string trackIn, std::string selectIn)
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;
702 decodeTSHit(selectIn.substr(29 * lenMLP + 4 + (8 - iSL) * lenTS, lenTS));
711 CDCTriggerSegmentHit* addTSHit(tsOut ts,
unsigned iSL,
unsigned iTracker,
712 StoreArray<CDCTriggerSegmentHit>* tsHits,
715 unsigned iTS = TSIDInSL(ts[0], iSL, iTracker);
717 CDCTriggerSegmentHit* hit =
nullptr;
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);
751 void decode2DOutput(
short foundTime,
752 T2DOutputBitStream* bits,
753 StoreArray<CDCTriggerTrack>* storeTracks,
754 StoreArray<CDCTriggerFinderClone>* storeClones,
755 StoreArray<CDCTriggerSegmentHit>* tsHits)
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;
764 for (
unsigned iTracker = 0; iTracker < nTrackers; ++iTracker) {
765 const auto slv = bits->signal()[iTracker];
767 substr(clockCounterWidth, T2DOutputWidth - clockCounterWidth);
768 for (
unsigned i = 0; i < nMax2DTracksPerClock; ++i) {
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);
785 for (
unsigned iAx = 0; iAx < nAxialTSF; ++iAx) {
786 const auto& ts = trk.ts[iAx];
788 unsigned iTS = TSIDInSL(ts[0], 2 * iAx, iTracker);
789 CDCTriggerSegmentHit* hit =
790 tsHits->appendNew(2 * iAx,
801 2000 + iTracker * 100 + foundTime,
803 track->addRelationTo(hit);
823 void decode2DInput(
short foundTime,
824 std::array<int, 4> timeOffset,
825 TSFOutputBitStream* bits,
826 StoreArray<CDCTriggerSegmentHit>* tsHits)
829 for (
unsigned iAx = 0; iAx < nAxialTSF; ++iAx) {
830 for (
unsigned iTracker = 0; iTracker < nTrackers; ++iTracker) {
831 const auto& tracker = bits->signal()[iAx][iTracker];
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);
842 }
else if (noMoreHit) {
843 B2DEBUG(20,
"Discontinuous TS hit detected!");
845 unsigned iTS = TSIDInSL(ts[0], 2 * iAx, iTracker);
847 CDCTriggerSegmentHit hit(2 * iAx,
853 foundTime + timeOffset[iTracker],
866 if (std::none_of(tsHits->begin(), tsHits->end(),
867 [hit](CDCTriggerSegmentHit storeHit) {
868 return (storeHit.getSegmentID() == hit.getSegmentID() &&
869 storeHit.foundTime() == hit.foundTime());
871 B2DEBUG(40,
"found TS hit ID " << hit.getSegmentID() <<
872 ", SL" << 2 * iAx <<
", local ID " << iTS <<
874 tsHits->appendNew(hit);
876 B2DEBUG(45,
"skipping redundant hit ID " << hit.getSegmentID() <<
" in 2D" << iTracker);
899 CDCTriggerTrack* decodeNNInput(
short iclock,
902 StoreArray<CDCTriggerTrack>* store2DTracks,
903 StoreArray<CDCTriggerSegmentHit>* tsHits)
905 CDCTriggerTrack* track2D =
nullptr;
906 constexpr
unsigned lenTrack = 135;
908 const auto slvIn = bitsIn->signal()[iTracker];
910 strIn = strIn.substr(NN_WIDTH - 570 - 496, 982);
912 for (
unsigned iSt = 0; iSt < nStereoTSF; ++iSt) {
913 for (
unsigned iHit = 0; iHit < 10; ++iHit) {
915 unsigned pos = ((nStereoTSF - iSt - 1) * 10 + iHit) * lenTS;
916 tsOut ts = decodeTSHit(strIn.substr(pos, lenTS));
918 addTSHit(ts, iSt * 2 + 1, iTracker, tsHits, iclock);
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,
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;
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);
941 B2WARNING(
"Invalid input in NNBitstream appending 'false'!");
942 foundoldtrack.push_back(
false);
946 if (infobits.substr(i, 1) ==
"1") {
948 }
else if (infobits.substr(i, 1) ==
"0") {
949 valstereobit =
false;
951 B2WARNING(
"Invalid input in NNBitstream appending 'false'!");
952 valstereobit =
false;
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);
960 B2WARNING(
"Invalid input in NNBitstream appending 'false'!");
961 driftthreshold.push_back(
false);
964 B2DEBUG(15,
"bits for foundoldtrack: " << foundoldtrack[0]
969 << foundoldtrack[5]);
970 B2DEBUG(15,
"bits for driftthreshold: " << driftthreshold[0]
978 << driftthreshold[8]);
979 B2DEBUG(15,
"bits for valstereobit: " << valstereobit);
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);
993 for (
unsigned iAx = 0; iAx < nAxialTSF; ++iAx) {
994 const auto& ts = trk2D.ts[iAx];
996 CDCTriggerSegmentHit* hit =
997 addTSHit(ts, 2 * iAx, iTracker, tsHits, iclock);
998 track2D->addRelationTo(hit);
1026 void decodeNNOutput_old(
short foundTime,
1028 NNBitStream* bitsOut,
1029 NNBitStream* bitsSelectTS,
1030 StoreArray<CDCTriggerTrack>* storeNNTracks,
1031 StoreArray<CDCTriggerSegmentHit>* tsHits,
1032 StoreArray<CDCTriggerMLPInput>* storeNNInputs,
1033 CDCTriggerTrack* track2D)
1035 const auto slvOut = bitsOut->signal()[iTracker];
1037 strTrack = strTrack.substr(496, 570);
1038 const auto slvSelect = bitsSelectTS->signal()[iTracker];
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);
1047 phi0 = track2D->getPhi0();
1048 omega = track2D->getOmega();
1050 std::vector<unsigned> tsvector(9, 0);
1051 for (
unsigned iSL = 0; iSL < 9; ++iSL) {
1052 tsvector[iSL] = trkNN.ts[iSL][2];
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];
1063 CDCTriggerMLPInput* storeInput =
1064 storeNNInputs->appendNew(inputVector, trkNN.sector);
1065 trackNN->addRelationTo(storeInput);
1066 track2D->addRelationTo(trackNN);
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);
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,
1104 for (
unsigned iTracker = 0; iTracker < nTrackers; ++iTracker) {
1105 B2DEBUG(21,
"----------------------------------------------------------------------------------------------------");
1106 B2DEBUG(21, padright(
" Unpacking Tracker: " + std::to_string(iTracker), 100));
1109 for (
short iclock = 0; iclock < bitsNN->getEntries(); ++iclock) {
1111 B2LDataField p_nnenable(bitsNN, iclock, iTracker, neurodb->getB2FormatLine(
"NNEnable"));
1112 if (p_nnenable.name ==
"None") {
1113 B2DEBUG(5,
"Neurotrigger: NNENable position unknown, skipping ... ");
1115 }
else if (p_nnenable.data ==
"1") {
1116 B2DEBUG(10, padright(
"Tracker: " + std::to_string(iTracker) +
", Clock: " + std::to_string(iclock) +
" : NNEnable set!", 100));
1118 B2DEBUG(21, padright(
" UnpackerClock: " + std::to_string(iclock), 100));
1122 CDCTriggerNeuroConfig::B2FormatLine nnall;
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));
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: " <<
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: " <<
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: " <<
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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: " <<
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: " <<
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: " <<
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);
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: " <<
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: " <<
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);
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: " <<
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: " <<
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: " <<
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: " <<
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: " <<
1304 CDCTriggerTrack* track2D =
nullptr;
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!");
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));
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);
1324 B2DEBUG(21, padright(
" SL" + std::to_string(sln * 2 + 1) + tsstr, 100));
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);
1339 std::vector<bool> foundoldtrack{
false};
1340 std::vector<bool> driftthreshold{
false};
1342 if (p_foundoldtrack.name !=
"None") {
1343 foundoldtrack = decodefoundoldtrack(p_foundoldtrack.data);
1345 if (p_driftthreshold.name !=
"None") {
1346 driftthreshold = decodedriftthreshold(p_driftthreshold.data);
1348 if (p_valstereobit.name !=
"None") {
1349 valstereobit = decodevalstereobit(p_valstereobit.data);
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!");
1356 TRG2DFinderTrack trk2D = decode2DTrack(
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));
1376 for (
unsigned iAx = 0; iAx < nAxialTSF; ++iAx) {
1377 const auto& ts = trk2D.ts[iAx];
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);
1387 B2DEBUG(16, padright(
" 2DTrack TS: " + tsstr, 100));
1391 TRGNeuroTrack trkNN;
1392 trkNN = decodeNNTrack(p_mlpout_z.data,
1393 p_mlpout_theta.data,
1396 p_mlpin_drifttime.data,
1405 B2DEBUG(11, padright(
" NNTrack: (z=" + std::to_string(trkNN.z) +
", theta=" + std::to_string(trkNN.theta) +
")", 100));
1407 double phi0 = track2D->getPhi0();
1408 double omega = track2D->getOmega();
1410 std::vector<unsigned> tsvector(9, 0);
1411 std::vector<unsigned> tstimevector(9, 0);
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";
1424 if (!(trk2D.ts[iSL / 2][0] == trkNN.ts[iSL][0] &&
1426 trk2D.ts[iSL / 2][2] == trkNN.ts[iSL][2] &&
1427 trk2D.ts[iSL / 2][3] == trkNN.ts[iSL][3])) {
1433 tsstr +=
"( - ),\n";
1437 B2DEBUG(15, padright(
" NNTrack TS: " + tsstr, 100));
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);
1449 trackNN->setETF_unpacked(std::stoi(p_etftime.data, 0, 2));
1450 track2D->setETF_unpacked(std::stoi(p_etftime.data, 0, 2));
1452 trackNN->setETF_recalced(recalcETF(p_mlpin_drifttime.data, tstimevector, trackNN));
1453 track2D->setETF_recalced(recalcETF(p_mlpin_drifttime.data, tstimevector, trackNN));
1455 if (isin2d ==
false) {
1456 trackNN->setQualityVector(1);
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];
1468 trackNN->setRawInput(rawinputVector);
1470 CDCTriggerMLPInput* storeInput =
1471 storeNNInputs->appendNew(inputVector, trkNN.sector);
1472 trackNN->addRelationTo(storeInput);
1473 track2D->addRelationTo(trackNN);
1475 for (
unsigned iSL = 0; iSL < 9; ++iSL) {
1476 if (trkNN.ts[iSL][3] > 0) {
1477 CDCTriggerSegmentHit* hit =
nullptr;
1507 hit = addTSHit(trkNN.ts[iSL], iSL, iTracker, tsHits, iclock);
1511 trackNN->addRelationTo(hit);
1513 track2D->addRelationTo(hit);
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)
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];
1552 if (stringOutEnable.c_str()[0] ==
'1') {
1553 CDCTriggerTrack* nntrack2D = decodeNNInput(iclock, iTracker, bitsIn, store2DTracks, tsHits);
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,
Class to hold one clock cycle of raw bit content.
const SignalBus & signal()
accessors
static const double speedOfLight
[cm/ns]
Accessor to arrays stored in the data store.
int getEntries() const
Get the number of objects in the array.
static const double realNaN
constant for double NaN
double atan(double a)
atan for double
Abstract base class for different kinds of events.
const char one_val
'1' in XSI VHDL simulation
const char * std_logic_literal[]
In case you are not familiar with VHDL simulation, there are 9 possible values defined for the standa...
std::bitset< max - min+1 > subset(std::bitset< nbits > set)
extract a subset of bitstring, like substring.
const char zero_val
'0' in XSI VHDL simulation
std::string slv_to_bin_string(std::array< char, N > signal, bool padding=false)
Transform into string.
void display_hex(const std::array< char, N > &signal)
Display signal in hex.
std::string display_value(const char *count, int size)
Display value of the signal.
tsOutArray ts
all TS of a 2D track
double omega
omega of a 2D track
double phi0
phi0 of a 2D track
int hwZ
raw output values of hw network
std::array< float, 9 > inputT
input T list of a NN track
std::array< float, 9 > inputAlpha
input Alpha list of a NN track
unsigned sector
sector of a NN track
std::array< float, 9 > inputID
input ID list of a NN track
std::array< tsOut, 9 > ts
input TS list of a NN track
double theta
theta of a NN track