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>;
281 std::array<tsOut, 9>
ts;
293 if (
int(b2line.
offset + foundtime) >= 0 &&
298 if (
int(slv_to_bin_string(bitsn->
signal()[iTracker]).size()) >= (NN_WIDTH - b2line.
start)) {
299 data = slv_to_bin_string(bitsn->
signal()[iTracker]).substr(NN_WIDTH - 1 - b2line.
end, b2line.
end - b2line.
start + 1);
314 std::vector<bool> decodedriftthreshold(std::string p_driftthreshold)
316 std::vector<bool> res;
317 for (
unsigned i = 0; i < p_driftthreshold.size(); ++i) {
318 if (p_driftthreshold.substr(i, 1) ==
"1") {
320 }
else if (p_driftthreshold.substr(i, 1) ==
"0") {
321 res.push_back(
false);
323 B2WARNING(
"Invalid input in NNBitstream appending 'false'!");
324 res.push_back(
false);
329 std::vector<bool> decodefoundoldtrack(std::string p_foundoldtrack)
331 std::vector<bool> res;
332 for (
unsigned i = 0; i < p_foundoldtrack.size(); ++i) {
333 if (p_foundoldtrack.substr(i, 1) ==
"1") {
335 }
else if (p_foundoldtrack.substr(i, 1) ==
"0") {
336 res.push_back(
false);
338 B2WARNING(
"Invalid input in NNBitstream appending 'false'!");
339 res.push_back(
false);
344 bool decodevalstereobit(
const std::string& p_valstereobit)
347 if (p_valstereobit ==
"1") {
349 }
else if (p_valstereobit ==
"0") {
352 B2WARNING(
"Invalid input in NNBitstream appending 'false'!");
368 unsigned TSIDInSL(
unsigned tsIDInTracker,
unsigned iSL,
unsigned iTracker)
370 const unsigned nCellsInSL = nMergers[iSL] * nCellsInLayer;
372 unsigned iTS = tsIDInTracker + nCellsInSL * iTracker / nTrackers;
374 if (iTS >= nCellsInSL) {
389 int mlp_bin_to_signed_int(std::string signal)
391 constexpr
unsigned len = 13;
392 std::bitset<len> signal_bit(signal);
393 const unsigned shift = 16 - len;
396 int signal_out = (int16_t (signal_bit.to_ulong() << shift)) >> shift;
403 int recalcETF(std::string driftinput, std::vector<unsigned> tsvector, CDCTriggerTrack* track)
406 float scale = 1. / (1 << (driftinput.size() - 1) / 9);
412 std::vector<std::vector<int>> table;
413 for (
unsigned iSL = 0; iSL < 9; ++iSL) {
415 int reldt =
static_cast<int>(fabs((mlp_bin_to_signed_int(driftinput.substr((8 - iSL) * driftinput.size() / 9,
416 driftinput.size() / 9)) * scale * 256)));
417 int tstime =
static_cast<int>(tsvector[iSL]);
419 if (reldt != 0 && reldt < 255) {
420 for (std::vector<int>& x : table) {
422 if (x[0] == tstime - reldt) {
427 if (!stor) {table.push_back({tstime - reldt, 1});}
433 for (std::vector<int>& x : table) {
440 if (table.size() > 1) {track->setQualityVector(128);}
452 tsOut decodeTSHit(std::string tsIn)
454 constexpr
unsigned lenID = 8;
455 constexpr
unsigned lenPriorityTime = 9;
456 constexpr
unsigned lenLR = 2;
457 constexpr
unsigned lenPriorityPosition = 2;
458 constexpr std::array<unsigned, 4> tsLens = {
459 lenID, lenPriorityTime, lenLR, lenPriorityPosition
461 std::array<unsigned, 5> tsPos = { 0 };
462 std::partial_sum(tsLens.begin(), tsLens.end(), tsPos.begin() + 1);
464 tsOutput[0] = std::bitset<tsLens[0]>(tsIn.substr(tsPos[0], tsLens[0])).to_ulong();
465 tsOutput[1] = std::bitset<tsLens[1]>(tsIn.substr(tsPos[1], tsLens[1])).to_ulong();
466 tsOutput[2] = std::bitset<tsLens[2]>(tsIn.substr(tsPos[2], tsLens[2])).to_ulong();
467 tsOutput[3] = std::bitset<tsLens[3]>(tsIn.substr(tsPos[3], tsLens[3])).to_ulong();
470 tsOut decodeTSHit_sim(std::string tsIn, std::string twodcc)
472 constexpr
unsigned lenID = 8;
473 constexpr
unsigned lenPriorityTime = 9;
474 constexpr
unsigned lenLR = 2;
475 constexpr
unsigned lenPriorityPosition = 2;
476 constexpr std::array<unsigned, 4> tsLens = {
477 lenID, lenPriorityTime, lenLR, lenPriorityPosition
479 std::string C = tsIn.substr(lenID + 5, 4);
480 std::string B = tsIn.substr(lenID, 5);
481 std::string Bp = twodcc.substr(4, 5);
482 std::string Ap = twodcc.substr(0, 4);
485 if (std::stoul(B, 0, 2) <= std::stoul(Bp, 0, 2)) {
488 B2DEBUG(14,
"2DCC overflow detected!");
489 pts = std::bitset<4>(std::stoul(Ap, 0, 2) - 1).to_string() + B + C;
491 pt = std::stoul(pts, 0, 2);
492 std::array<unsigned, 5> tsPos = { 0 };
493 std::partial_sum(tsLens.begin(), tsLens.end(), tsPos.begin() + 1);
495 tsOutput[0] = std::bitset<tsLens[0]>(tsIn.substr(tsPos[0], tsLens[0])).to_ulong();
497 tsOutput[2] = std::bitset<tsLens[2]>(tsIn.substr(tsPos[2], tsLens[2])).to_ulong();
498 tsOutput[3] = std::bitset<tsLens[3]>(tsIn.substr(tsPos[3], tsLens[3])).to_ulong();
501 tsOut decodeTSHit_ext(std::string tsIn, std::string expt)
503 constexpr
unsigned lenID = 8;
504 constexpr
unsigned lenPriorityTime = 9;
505 constexpr
unsigned lenLR = 2;
506 constexpr
unsigned lenPriorityPosition = 2;
507 constexpr std::array<unsigned, 4> tsLens = {
508 lenID, lenPriorityTime, lenLR, lenPriorityPosition
510 unsigned pt = std::stoul(expt, 0, 2);
511 std::array<unsigned, 5> tsPos = { 0 };
512 std::partial_sum(tsLens.begin(), tsLens.end(), tsPos.begin() + 1);
514 tsOutput[0] = std::bitset<tsLens[0]>(tsIn.substr(tsPos[0], tsLens[0])).to_ulong();
516 tsOutput[2] = std::bitset<tsLens[2]>(tsIn.substr(tsPos[2], tsLens[2])).to_ulong();
517 tsOutput[3] = std::bitset<tsLens[3]>(tsIn.substr(tsPos[3], tsLens[3])).to_ulong();
530 TRG2DFinderTrack decode2DTrack(
const std::string& p_charge __attribute__((unused)),
533 const std::string& p_ts0,
534 const std::string& p_ts2,
535 const std::string& p_ts4,
536 const std::string& p_ts6,
537 const std::string& p_ts8,
539 const std::string& p_2dcc,
543 unsigned shift = 16 - p_omega.size();
544 TRG2DFinderTrack trackout;
545 int omega = std::stoi(p_omega, 0, 2);
548 int omegafirm = (int16_t (omega << shift)) >> shift;
549 trackout.hwOmega = omegafirm;
552 const double BField = 1.5e-4;
560 int phi = std::stoi(p_phi, 0, 2);
561 trackout.hwPhi0 = phi;
563 double globalPhi0 = pi() / 4 + pi() / 2 / 80 * (phi + 1) + pi() / 2 * iTracker;
566 trackout.ts[0] = (sim13dt) ? decodeTSHit_sim(p_ts0, p_2dcc) : decodeTSHit(p_ts0);
567 trackout.ts[1] = (sim13dt) ? decodeTSHit_sim(p_ts2, p_2dcc) : decodeTSHit(p_ts2);
568 trackout.ts[2] = (sim13dt) ? decodeTSHit_sim(p_ts4, p_2dcc) : decodeTSHit(p_ts4);
569 trackout.ts[3] = (sim13dt) ? decodeTSHit_sim(p_ts6, p_2dcc) : decodeTSHit(p_ts6);
570 trackout.ts[4] = (sim13dt) ? decodeTSHit_sim(p_ts8, p_2dcc) : decodeTSHit(p_ts8);
572 if (globalPhi0 > pi() * 2) {
573 globalPhi0 -= pi() * 2;
575 trackout.phi0 = globalPhi0;
576 B2DEBUG(20,
"Unpacking 2DTrack in Tracker: " << iTracker);
577 B2DEBUG(20,
" Omega: " << std::to_string(omega) <<
", Omegafirm: " << std::to_string(omegafirm) <<
", converted to: " <<
578 std::to_string(trackout.omega));
579 B2DEBUG(20,
" Phi: " << std::to_string(phi) <<
", converted to: " << std::to_string(trackout.phi0));
583 TRG2DFinderTrack decode2DTrack(std::string trackIn,
unsigned iTracker)
585 constexpr
unsigned lenCharge = 2;
586 constexpr
unsigned lenOmega = 7;
587 constexpr
unsigned lenPhi0 = 7;
588 constexpr std::array<unsigned, 3> trackLens = {lenCharge, lenOmega, lenPhi0};
589 std::array<unsigned, 4> trackPos{ 0 };
590 std::partial_sum(trackLens.begin(), trackLens.end(), trackPos.begin() + 1);
591 const unsigned shift = 16 - lenOmega;
592 TRG2DFinderTrack trackOut;
593 std::bitset<trackLens[1]> omega(trackIn.substr(trackPos[1], trackLens[1]));
596 int omegaFirm = (int16_t (omega.to_ulong() << shift)) >> shift;
597 trackOut.hwOmega = omegaFirm;
599 const double BField = 1.5e-4;
604 int phi0 = std::bitset<trackLens[2]>(trackIn.substr(trackPos[2], trackLens[2])).to_ulong();
605 trackOut.hwPhi0 = phi0;
606 trackOut.phi0 = pi() / 4 + pi() / 2 / 80 * (phi0 + 1);
607 for (
unsigned i = 0; i < 5; ++i) {
608 trackOut.ts[i] = decodeTSHit(trackIn.substr(trackPos.back() + i * lenTS, lenTS));
612 double globalPhi0 = trackOut.phi0 + pi() / 2 * iTracker;
613 if (globalPhi0 > pi() * 2) {
614 globalPhi0 -= pi() * 2;
616 trackOut.phi0 = globalPhi0;
628 TRGNeuroTrack decodeNNTrack(std::string p_mlpout_z,
629 std::string p_mlpout_theta,
630 std::string p_tsfsel,
631 std::string p_mlpin_alpha,
632 std::string p_mlpin_drifttime,
633 std::string p_mlpin_id,
634 std::string p_netsel,
635 const DBObjPtr<CDCTriggerNeuroConfig>& neurodb,
636 const std::string& p_2dcc,
638 B2LDataField p_extendedpts)
641 float scale_z = 1. / (1 << (p_mlpout_z.size() - 1));
642 float scale_theta = 1. / (1 << (p_mlpout_theta.size() - 1));
643 float scale_alpha = 1. / (1 << (p_mlpin_alpha.size() - 1) / 9);
644 float scale_drifttime = 1. / (1 << (p_mlpin_drifttime.size() - 1) / 9);
645 float scale_id = 1. / (1 << (p_mlpin_id.size() - 1) / 9);
646 TRGNeuroTrack foundTrack;
647 int theta_raw = mlp_bin_to_signed_int(p_mlpout_theta);
648 int z_raw = mlp_bin_to_signed_int(p_mlpout_z);
649 foundTrack.hwZ = z_raw;
650 foundTrack.hwTheta = theta_raw;
651 std::vector<float> unscaledT = neurodb->getMLPs()[0].unscaleTarget({(z_raw * scale_z), (theta_raw * scale_theta)});
652 foundTrack.z = unscaledT[0];
653 foundTrack.theta = unscaledT[1];
654 foundTrack.sector = std::stoi(p_netsel, 0, 2);
655 for (
unsigned iSL = 0; iSL < 9; ++iSL) {
656 foundTrack.inputAlpha[iSL] =
657 mlp_bin_to_signed_int(p_mlpin_alpha.substr((8 - iSL) * p_mlpin_alpha.size() / 9, p_mlpin_alpha.size() / 9)) * scale_alpha;
658 foundTrack.inputT[iSL] =
659 mlp_bin_to_signed_int(p_mlpin_drifttime.substr((8 - iSL) * p_mlpin_drifttime.size() / 9,
660 p_mlpin_drifttime.size() / 9)) * scale_drifttime;
661 foundTrack.inputID[iSL] =
662 mlp_bin_to_signed_int(p_mlpin_id.substr((8 - iSL) * p_mlpin_drifttime.size() / 9, p_mlpin_drifttime.size() / 9)) * scale_id;
664 foundTrack.ts[iSL] = decodeTSHit_sim(p_tsfsel.substr((8 - iSL) * lenTS, lenTS), p_2dcc);
666 if (p_extendedpts.name !=
"None") {
667 foundTrack.ts[iSL] = decodeTSHit_ext(p_tsfsel.substr((8 - iSL) * lenTS, lenTS), p_extendedpts.data.substr((8 - iSL) * 13, 13));
669 foundTrack.ts[iSL] = decodeTSHit(p_tsfsel.substr((8 - iSL) * lenTS, lenTS));
675 TRGNeuroTrack decodeNNTrack_old(std::string trackIn, std::string selectIn)
677 constexpr
unsigned lenMLP = 13;
678 float scale = 1. / (1 << (lenMLP - 1));
679 TRGNeuroTrack foundTrack;
680 int theta_raw = mlp_bin_to_signed_int(trackIn.substr(1, lenMLP));
681 foundTrack.theta = theta_raw * scale * M_PI_2 + M_PI_2;
682 int z_raw = mlp_bin_to_signed_int(trackIn.substr(lenMLP + 1, lenMLP));
683 foundTrack.z = z_raw * scale * 50.;
684 foundTrack.sector = std::bitset<3>(trackIn.substr(2 * lenMLP + 1, 3)).to_ulong();
685 for (
unsigned iSL = 0; iSL < 9; ++iSL) {
686 foundTrack.inputAlpha[iSL] =
687 mlp_bin_to_signed_int(selectIn.substr((2 + (8 - iSL)) * lenMLP + 4, lenMLP)) * scale;
688 foundTrack.inputT[iSL] =
689 mlp_bin_to_signed_int(selectIn.substr((11 + (8 - iSL)) * lenMLP + 4, lenMLP)) * scale;
690 foundTrack.inputID[iSL] =
691 mlp_bin_to_signed_int(selectIn.substr((20 + (8 - iSL)) * lenMLP + 4, lenMLP)) * scale;
693 decodeTSHit(selectIn.substr(29 * lenMLP + 4 + (8 - iSL) * lenTS, lenTS));
702 CDCTriggerSegmentHit* addTSHit(tsOut ts,
unsigned iSL,
unsigned iTracker,
703 StoreArray<CDCTriggerSegmentHit>* tsHits,
706 unsigned iTS = TSIDInSL(ts[0], iSL, iTracker);
708 CDCTriggerSegmentHit* hit =
nullptr;
722 hit = tsHits->appendNew(iSL, iTS, ts[3], ts[2], ts[1], 0, foundTime, iTracker);
723 B2DEBUG(15,
"make hit at SL " << iSL <<
" ID " << iTS <<
" clock " << foundTime <<
" iTracker " << iTracker);
742 void decode2DOutput(
short foundTime,
743 T2DOutputBitStream* bits,
744 StoreArray<CDCTriggerTrack>* storeTracks,
745 StoreArray<CDCTriggerFinderClone>* storeClones,
746 StoreArray<CDCTriggerSegmentHit>* tsHits)
748 const unsigned lenTrack = 121;
749 const unsigned oldTrackWidth = 6;
750 const unsigned foundWidth = 6;
751 std::array<int, 4> posTrack;
752 for (
unsigned i = 0; i < posTrack.size(); ++i) {
753 posTrack[i] = oldTrackWidth + foundWidth + lenTrack * i;
755 for (
unsigned iTracker = 0; iTracker < nTrackers; ++iTracker) {
756 const auto slv = bits->signal()[iTracker];
758 substr(clockCounterWidth, T2DOutputWidth - clockCounterWidth);
759 for (
unsigned i = 0; i < nMax2DTracksPerClock; ++i) {
761 if (slv[clockCounterWidth + oldTrackWidth + i] == one_val) {
762 TRG2DFinderTrack trk = decode2DTrack(strOutput.substr(posTrack[i], lenTrack), iTracker);
763 B2DEBUG(15,
"2DOut phi0:" << trk.phi0 <<
", omega:" << trk.omega
764 <<
", at clock " << foundTime <<
", tracker " << iTracker);
765 CDCTriggerTrack* track =
766 storeTracks->appendNew(trk.phi0, trk.omega, 0., foundTime, iTracker);
767 CDCTriggerFinderClone* clone =
768 storeClones->appendNew(slv[clockCounterWidth + i] == one_val, iTracker);
769 clone->addRelationTo(track);
776 for (
unsigned iAx = 0; iAx < nAxialTSF; ++iAx) {
777 const auto& ts = trk.ts[iAx];
779 unsigned iTS = TSIDInSL(ts[0], 2 * iAx, iTracker);
780 CDCTriggerSegmentHit* hit =
781 tsHits->appendNew(2 * iAx,
792 2000 + iTracker * 100 + foundTime,
794 track->addRelationTo(hit);
814 void decode2DInput(
short foundTime,
815 std::array<int, 4> timeOffset,
816 TSFOutputBitStream* bits,
817 StoreArray<CDCTriggerSegmentHit>* tsHits)
820 for (
unsigned iAx = 0; iAx < nAxialTSF; ++iAx) {
821 for (
unsigned iTracker = 0; iTracker < nTrackers; ++iTracker) {
822 const auto& tracker = bits->signal()[iAx][iTracker];
824 bool noMoreHit =
false;
825 for (
unsigned pos = clockCounterWidth; pos < TSFOutputWidth; pos += lenTS) {
826 std::string tsHitStr = strInput.substr(pos, lenTS);
827 B2DEBUG(50, tsHitStr);
828 tsOut ts = decodeTSHit(tsHitStr);
833 }
else if (noMoreHit) {
834 B2DEBUG(20,
"Discontinuous TS hit detected!");
836 unsigned iTS = TSIDInSL(ts[0], 2 * iAx, iTracker);
838 CDCTriggerSegmentHit hit(2 * iAx,
844 foundTime + timeOffset[iTracker],
857 if (std::none_of(tsHits->begin(), tsHits->end(),
858 [hit](CDCTriggerSegmentHit storeHit) {
859 return (storeHit.getSegmentID() == hit.getSegmentID() &&
860 storeHit.foundTime() == hit.foundTime());
862 B2DEBUG(40,
"found TS hit ID " << hit.getSegmentID() <<
863 ", SL" << 2 * iAx <<
", local ID " << iTS <<
865 tsHits->appendNew(hit);
867 B2DEBUG(45,
"skipping redundant hit ID " << hit.getSegmentID() <<
" in 2D" << iTracker);
890 CDCTriggerTrack* decodeNNInput(
short iclock,
893 StoreArray<CDCTriggerTrack>* store2DTracks,
894 StoreArray<CDCTriggerSegmentHit>* tsHits)
896 CDCTriggerTrack* track2D =
nullptr;
897 constexpr
unsigned lenTrack = 135;
899 const auto slvIn = bitsIn->signal()[iTracker];
901 strIn = strIn.substr(NN_WIDTH - 570 - 496, 982);
903 for (
unsigned iSt = 0; iSt < nStereoTSF; ++iSt) {
904 for (
unsigned iHit = 0; iHit < 10; ++iHit) {
906 unsigned pos = ((nStereoTSF - iSt - 1) * 10 + iHit) * lenTS;
907 tsOut ts = decodeTSHit(strIn.substr(pos, lenTS));
909 addTSHit(ts, iSt * 2 + 1, iTracker, tsHits, iclock);
913 std::string strTrack = strIn.substr(nStereoTSF * 10 * lenTS, lenTrack);
914 if (!std::all_of(strTrack.begin(), strTrack.end(), [](
char i) {return i ==
'0';})) {
915 std::string infobits = strTrack.substr(5 * lenTS + 14, 16);
916 strTrack =
"00" + strTrack.substr(5 * lenTS, 14) + strTrack.substr(0,
918 TRG2DFinderTrack trk2D = decode2DTrack(strTrack, iTracker);
919 B2DEBUG(15,
"NNIn phi0:" << trk2D.phi0 <<
", omega:" << trk2D.omega
920 <<
", at clock " << iclock <<
", tracker " << iTracker);
921 B2DEBUG(300,
"Content of new infobits: " << infobits);
922 std::vector<bool> foundoldtrack;
923 std::vector<bool> driftthreshold;
926 for (i = 0; i < 6; i++) {
927 if (infobits.substr(i, 1) ==
"1") {
928 foundoldtrack.push_back(
true);
929 }
else if (infobits.substr(i, 1) ==
"0") {
930 foundoldtrack.push_back(
false);
932 B2WARNING(
"Invalid input in NNBitstream appending 'false'!");
933 foundoldtrack.push_back(
false);
937 if (infobits.substr(i, 1) ==
"1") {
939 }
else if (infobits.substr(i, 1) ==
"0") {
940 valstereobit =
false;
942 B2WARNING(
"Invalid input in NNBitstream appending 'false'!");
943 valstereobit =
false;
945 for (i = 7; i < 16; i++) {
946 if (infobits.substr(i, 1) ==
"1") {
947 driftthreshold.push_back(
true);
948 }
else if (infobits.substr(i, 1) ==
"0") {
949 driftthreshold.push_back(
false);
951 B2WARNING(
"Invalid input in NNBitstream appending 'false'!");
952 driftthreshold.push_back(
false);
955 B2DEBUG(15,
"bits for foundoldtrack: " << foundoldtrack[0]
960 << foundoldtrack[5]);
961 B2DEBUG(15,
"bits for driftthreshold: " << driftthreshold[0]
969 << driftthreshold[8]);
970 B2DEBUG(15,
"bits for valstereobit: " << valstereobit);
981 B2DEBUG(15,
"make new 2D track with phi " << trk2D.phi0 <<
" omega " << trk2D.omega <<
" clock " << iclock);
982 track2D = store2DTracks->appendNew(trk2D.phi0, trk2D.omega, 0., foundoldtrack, driftthreshold, valstereobit, iclock, iTracker);
984 for (
unsigned iAx = 0; iAx < nAxialTSF; ++iAx) {
985 const auto& ts = trk2D.ts[iAx];
987 CDCTriggerSegmentHit* hit =
988 addTSHit(ts, 2 * iAx, iTracker, tsHits, iclock);
989 track2D->addRelationTo(hit);
1017 void decodeNNOutput_old(
short foundTime,
1019 NNBitStream* bitsOut,
1020 NNBitStream* bitsSelectTS,
1021 StoreArray<CDCTriggerTrack>* storeNNTracks,
1022 StoreArray<CDCTriggerSegmentHit>* tsHits,
1023 StoreArray<CDCTriggerMLPInput>* storeNNInputs,
1024 CDCTriggerTrack* track2D)
1026 const auto slvOut = bitsOut->signal()[iTracker];
1028 strTrack = strTrack.substr(496, 570);
1029 const auto slvSelect = bitsSelectTS->signal()[iTracker];
1031 strSelect = strSelect.substr(496, 570);
1032 TRGNeuroTrack trkNN = decodeNNTrack_old(strTrack, strSelect);
1033 B2DEBUG(15,
"make new NN track with , z:" << trkNN.z <<
", theta:" << trkNN.theta <<
1034 ", sector:" << trkNN.sector <<
", clock " << foundTime);
1038 phi0 = track2D->getPhi0();
1039 omega = track2D->getOmega();
1041 std::vector<unsigned> tsvector(9, 0);
1042 for (
unsigned iSL = 0; iSL < 9; ++iSL) {
1043 tsvector[iSL] = trkNN.ts[iSL][2];
1045 CDCTriggerTrack* trackNN = storeNNTracks->appendNew(phi0, omega, 0.,
1046 trkNN.z, cos(trkNN.theta) / sin(trkNN.theta), 0., track2D->getFoundOldTrack(), track2D->getDriftThreshold(),
1047 track2D->getValidStereoBit(), trkNN.sector, tsvector, foundTime, iTracker);
1048 std::vector<float> inputVector(27, 0.);
1049 for (
unsigned iSL = 0; iSL < 9; ++iSL) {
1050 inputVector[3 * iSL] = trkNN.inputID[iSL];
1051 inputVector[3 * iSL + 1] = trkNN.inputT[iSL];
1052 inputVector[3 * iSL + 2] = trkNN.inputAlpha[iSL];
1054 CDCTriggerMLPInput* storeInput =
1055 storeNNInputs->appendNew(inputVector, trkNN.sector);
1056 trackNN->addRelationTo(storeInput);
1057 track2D->addRelationTo(trackNN);
1059 for (
unsigned iSL = 0; iSL < 9; ++iSL) {
1060 if (trkNN.ts[iSL][3] > 0) {
1061 CDCTriggerSegmentHit* hit = addTSHit(trkNN.ts[iSL] , iSL, iTracker, tsHits, foundTime);
1062 trackNN->addRelationTo(hit);
1085 StoreArray<CDCTriggerUnpacker::NNBitStream>* bitsNN,
1086 StoreArray<CDCTriggerTrack>* store2DTracks,
1087 StoreArray<CDCTriggerTrack>* storeNNTracks,
1088 StoreArray<CDCTriggerSegmentHit>* tsHits,
1089 StoreArray<CDCTriggerSegmentHit>* tsHitsAll,
1090 StoreArray<CDCTriggerMLPInput>* storeNNInputs,
1091 StoreObjPtr<BinnedEventT0> storeETFTime,
1092 const DBObjPtr<CDCTriggerNeuroConfig> neurodb,
1095 for (
unsigned iTracker = 0; iTracker < nTrackers; ++iTracker) {
1096 B2DEBUG(21,
"----------------------------------------------------------------------------------------------------");
1097 B2DEBUG(21, padright(
" Unpacking Tracker: " + std::to_string(iTracker), 100));
1100 for (
short iclock = 0; iclock < bitsNN->getEntries(); ++iclock) {
1102 B2LDataField p_nnenable(bitsNN, iclock, iTracker, neurodb->getB2FormatLine(
"NNEnable"));
1103 if (p_nnenable.name ==
"None") {
1104 B2DEBUG(5,
"Neurotrigger: NNENable position unknown, skipping ... ");
1106 }
else if (p_nnenable.data ==
"1") {
1107 B2DEBUG(10, padright(
"Tracker: " + std::to_string(iTracker) +
", Clock: " + std::to_string(iclock) +
" : NNEnable set!", 100));
1109 B2DEBUG(21, padright(
" UnpackerClock: " + std::to_string(iclock), 100));
1113 CDCTriggerNeuroConfig::B2FormatLine nnall;
1117 nnall.name =
"nnall";
1118 B2LDataField p_nnall(bitsNN, iclock, iTracker, nnall);
1119 B2DEBUG(22, padright(
" all bits: ", 100));
1120 B2DEBUG(22, padright(
" " + p_nnall.data, 100));
1122 B2LDataField p_driftthreshold(bitsNN, iclock, iTracker, neurodb->getB2FormatLine(
"DriftThreshold"));
1123 if ((p_driftthreshold.name !=
"None") && (p_driftthreshold.data.size() == 0)) {
1124 B2DEBUG(10,
"Could not load Datafield: " << p_driftthreshold.name <<
" from bitstream. Maybe offset was out of bounds? clock: " <<
1129 B2LDataField p_valstereobit(bitsNN, iclock, iTracker, neurodb->getB2FormatLine(
"ValStereoBit"));
1130 if ((p_valstereobit.name !=
"None") && (p_valstereobit.data.size() == 0)) {
1131 B2DEBUG(10,
"Could not load Datafield: " << p_valstereobit.name <<
" from bitstream. Maybe offset was out of bounds? clock: " <<
1136 B2LDataField p_foundoldtrack(bitsNN, iclock, iTracker, neurodb->getB2FormatLine(
"FoundOldTrack"));
1137 if ((p_foundoldtrack.name !=
"None") && (p_foundoldtrack.data.size() == 0)) {
1138 B2DEBUG(10,
"Could not load Datafield: " << p_foundoldtrack.name <<
" from bitstream. Maybe offset was out of bounds? clock: " <<
1143 B2LDataField p_phi(bitsNN, iclock, iTracker, neurodb->getB2FormatLine(
"Phi"));
1144 if ((p_phi.name !=
"None") && (p_phi.data.size() == 0)) {
1145 B2DEBUG(10,
"Could not load Datafield: " << p_phi.name <<
" from bitstream. Maybe offset was out of bounds? clock: " << iclock);
1149 B2LDataField p_omega(bitsNN, iclock, iTracker, neurodb->getB2FormatLine(
"Omega"));
1150 if ((p_omega.name !=
"None") && (p_omega.data.size() == 0)) {
1151 B2DEBUG(10,
"Could not load Datafield: " << p_omega.name <<
" from bitstream. Maybe offset was out of bounds? clock: " << iclock);
1155 B2LDataField p_ts8(bitsNN, iclock, iTracker, neurodb->getB2FormatLine(
"TS8"));
1156 if ((p_ts8.name !=
"None") && (p_ts8.data.size() == 0)) {
1157 B2DEBUG(10,
"Could not load Datafield: " << p_ts8.name <<
" from bitstream. Maybe offset was out of bounds? clock: " << iclock);
1161 B2LDataField p_ts6(bitsNN, iclock, iTracker, neurodb->getB2FormatLine(
"TS6"));
1162 if ((p_ts6.name !=
"None") && (p_ts6.data.size() == 0)) {
1163 B2DEBUG(10,
"Could not load Datafield: " << p_ts6.name <<
" from bitstream. Maybe offset was out of bounds? clock: " << iclock);
1167 B2LDataField p_ts4(bitsNN, iclock, iTracker, neurodb->getB2FormatLine(
"TS4"));
1168 if ((p_ts4.name !=
"None") && (p_ts4.data.size() == 0)) {
1169 B2DEBUG(10,
"Could not load Datafield: " << p_ts4.name <<
" from bitstream. Maybe offset was out of bounds? clock: " << iclock);
1173 B2LDataField p_ts2(bitsNN, iclock, iTracker, neurodb->getB2FormatLine(
"TS2"));
1174 if ((p_ts2.name !=
"None") && (p_ts2.data.size() == 0)) {
1175 B2DEBUG(10,
"Could not load Datafield: " << p_ts2.name <<
" from bitstream. Maybe offset was out of bounds? clock: " << iclock);
1179 B2LDataField p_ts0(bitsNN, iclock, iTracker, neurodb->getB2FormatLine(
"TS0"));
1180 if ((p_ts0.name !=
"None") && (p_ts0.data.size() == 0)) {
1181 B2DEBUG(10,
"Could not load Datafield: " << p_ts0.name <<
" from bitstream. Maybe offset was out of bounds? clock: " << iclock);
1185 B2LDataField p_tsf1(bitsNN, iclock, iTracker, neurodb->getB2FormatLine(
"TSF1"));
1186 if ((p_tsf1.name !=
"None") && (p_tsf1.data.size() == 0)) {
1187 B2DEBUG(10,
"Could not load Datafield: " << p_tsf1.name <<
" from bitstream. Maybe offset was out of bounds? clock: " << iclock);
1191 B2LDataField p_tsf3(bitsNN, iclock, iTracker, neurodb->getB2FormatLine(
"TSF3"));
1192 if ((p_tsf3.name !=
"None") && (p_tsf3.data.size() == 0)) {
1193 B2DEBUG(10,
"Could not load Datafield: " << p_tsf3.name <<
" from bitstream. Maybe offset was out of bounds? clock: " << iclock);
1197 B2LDataField p_tsf5(bitsNN, iclock, iTracker, neurodb->getB2FormatLine(
"TSF5"));
1198 if ((p_tsf5.name !=
"None") && (p_tsf5.data.size() == 0)) {
1199 B2DEBUG(10,
"Could not load Datafield: " << p_tsf5.name <<
" from bitstream. Maybe offset was out of bounds? clock: " << iclock);
1203 B2LDataField p_tsf7(bitsNN, iclock, iTracker, neurodb->getB2FormatLine(
"TSF7"));
1204 if ((p_tsf7.name !=
"None") && (p_tsf7.data.size() == 0)) {
1205 B2DEBUG(10,
"Could not load Datafield: " << p_tsf7.name <<
" from bitstream. Maybe offset was out of bounds? clock: " << iclock);
1209 B2LDataField p_tsfsel(bitsNN, iclock, iTracker, neurodb->getB2FormatLine(
"TSFsel"));
1210 if ((p_tsfsel.name !=
"None") && (p_tsfsel.data.size() == 0)) {
1211 B2DEBUG(10,
"Could not load Datafield: " << p_tsfsel.name <<
" from bitstream. Maybe offset was out of bounds? clock: " << iclock);
1215 B2LDataField p_mlpin_alpha(bitsNN, iclock, iTracker, neurodb->getB2FormatLine(
"MLPIn_alpha"));
1216 if ((p_mlpin_alpha.name !=
"None") && (p_mlpin_alpha.data.size() == 0)) {
1217 B2DEBUG(10,
"Could not load Datafield: " << p_mlpin_alpha.name <<
" from bitstream. Maybe offset was out of bounds? clock: " <<
1222 B2LDataField p_mlpin_drifttime(bitsNN, iclock, iTracker, neurodb->getB2FormatLine(
"MLPIn_driftt"));
1223 if ((p_mlpin_drifttime.name !=
"None") && (p_mlpin_drifttime.data.size() == 0)) {
1224 B2DEBUG(10,
"Could not load Datafield: " << p_mlpin_drifttime.name <<
" from bitstream. Maybe offset was out of bounds? clock: " <<
1229 B2LDataField p_mlpin_id(bitsNN, iclock, iTracker, neurodb->getB2FormatLine(
"MLPIn_id"));
1230 if ((p_mlpin_id.name !=
"None") && (p_mlpin_id.data.size() == 0)) {
1231 B2DEBUG(10,
"Could not load Datafield: " << p_mlpin_id.name <<
" from bitstream. Maybe offset was out of bounds? clock: " <<
1236 B2LDataField p_netsel(bitsNN, iclock, iTracker, neurodb->getB2FormatLine(
"Netsel"));
1237 if ((p_netsel.name !=
"None") && (p_netsel.data.size() == 0)) {
1238 B2DEBUG(10,
"Could not load Datafield: " << p_netsel.name <<
" from bitstream. Maybe offset was out of bounds? clock: " << iclock);
1242 B2LDataField p_mlpout_z(bitsNN, iclock, iTracker, neurodb->getB2FormatLine(
"MLPOut_z"));
1243 if ((p_mlpout_z.name !=
"None") && (p_mlpout_z.data.size() == 0)) {
1244 B2DEBUG(10,
"Could not load Datafield: " << p_mlpout_z.name <<
" from bitstream. Maybe offset was out of bounds? clock: " <<
1249 B2LDataField p_mlpout_theta(bitsNN, iclock, iTracker, neurodb->getB2FormatLine(
"MLPOut_theta"));
1250 if ((p_mlpout_theta.name !=
"None") && (p_mlpout_theta.data.size() == 0)) {
1251 B2DEBUG(10,
"Could not load Datafield: " << p_mlpout_theta.name <<
" from bitstream. Maybe offset was out of bounds? clock: " <<
1256 B2LDataField p_2dcc(bitsNN, iclock, iTracker, neurodb->getB2FormatLine(
"2dcc"));
1257 if ((p_2dcc.name !=
"None") && (p_2dcc.data.size() == 0)) {
1258 B2DEBUG(10,
"Could not load Datafield: " << p_2dcc.name <<
" from bitstream. Maybe offset was out of bounds? clock: " << iclock);
1262 B2LDataField p_extendedpts(bitsNN, iclock, iTracker, neurodb->getB2FormatLine(
"extendedPriorityTimes"));
1263 if ((p_extendedpts.name !=
"None") && (p_extendedpts.data.size() == 0)) {
1264 B2DEBUG(10,
"Could not load Datafield: " << p_extendedpts.name <<
" from bitstream. Maybe offset was out of bounds? clock: " <<
1268 B2LDataField p_etftime(bitsNN, iclock, iTracker, neurodb->getB2FormatLine(
"etftime"));
1269 if ((p_etftime.name !=
"None") && (p_etftime.data.size() == 0)) {
1270 B2DEBUG(10,
"Could not load Datafield: " << p_etftime.name <<
" from bitstream. Maybe offset was out of bounds? clock: " <<
1274 B2LDataField p_etfcc(bitsNN, iclock, iTracker, neurodb->getB2FormatLine(
"etfcc"));
1275 if ((p_etfcc.name !=
"None") && (p_etfcc.data.size() == 0)) {
1276 B2DEBUG(10,
"Could not load Datafield: " << p_etfcc.name <<
" from bitstream. Maybe offset was out of bounds? clock: " <<
1280 B2LDataField p_etfqual(bitsNN, iclock, iTracker, neurodb->getB2FormatLine(
"etfquality"));
1281 if ((p_etfqual.name !=
"None") && (p_etfqual.data.size() == 0)) {
1282 B2DEBUG(10,
"Could not load Datafield: " << p_etfqual.name <<
" from bitstream. Maybe offset was out of bounds? clock: " <<
1286 B2LDataField p_etfval(bitsNN, iclock, iTracker, neurodb->getB2FormatLine(
"etfvalid"));
1287 if ((p_etfval.name !=
"None") && (p_etfval.data.size() == 0)) {
1288 B2DEBUG(10,
"Could not load Datafield: " << p_etfval.name <<
" from bitstream. Maybe offset was out of bounds? clock: " <<
1295 CDCTriggerTrack* track2D =
nullptr;
1299 B2DEBUG(21, padright(
" Stereos: ", 100));
1300 for (
auto stereolayer : {p_tsf1, p_tsf3, p_tsf5, p_tsf7}) {
1301 if (stereolayer.name ==
"None") {
1302 B2ERROR(
"Error in CDCTriggerNeuroConfig Payload, position of stereo tsf could not be found!");
1305 std::string tsstr =
" | ";
1306 for (
unsigned iHit = 0; iHit < 10; ++iHit) {
1307 tsOut ts = (sim13dt) ? decodeTSHit_sim(stereolayer.data.substr(iHit * lenTS, lenTS),
1308 p_2dcc.data) : decodeTSHit(stereolayer.data.substr(iHit * lenTS, lenTS));
1310 unsigned iTS = TSIDInSL(ts[0], sln * 2 + 1, iTracker);
1311 tsstr += std::to_string(iTS) +
", " + std::to_string(ts[1]) +
", " + std::to_string(ts[2]) +
", " + std::to_string(ts[3]) +
" | ";
1312 addTSHit(ts, sln * 2 + 1, iTracker, tsHitsAll, iclock);
1315 B2DEBUG(21, padright(
" SL" + std::to_string(sln * 2 + 1) + tsstr, 100));
1319 B2DEBUG(21, padright(
" 2DCC: " + std::to_string(std::stoi(p_2dcc.data, 0, 2)) +
", (" + p_2dcc.data +
")", 100));
1320 B2DEBUG(21, padright(
" ETFCC: " + std::to_string(std::stoi(p_etfcc.data, 0, 2)) +
", (" + p_etfcc.data +
")", 100));
1321 B2DEBUG(21, padright(
" ETFVAL: " + std::to_string(std::stoi(p_etfval.data, 0, 2)) +
", (" + p_etfval.data +
")", 100));
1322 B2DEBUG(21, padright(
" ETFT0: " + std::to_string(std::stoi(p_etftime.data, 0, 2)) +
", (" + p_etftime.data +
")", 100));
1323 B2DEBUG(21, padright(
" ETFQuality: " + std::to_string(std::stoi(p_etfqual.data, 0, 2)) +
", (" + p_etfqual.data +
")", 100));
1324 bool hasETFTime =
false;
1325 if (p_nnenable.data ==
"1") {
1326 if (p_etfval.data ==
"1") {
1327 storeETFTime->addBinnedEventT0(std::stoi(p_etftime.data, 0, 2), Const::CDC);
1330 std::vector<bool> foundoldtrack{
false};
1331 std::vector<bool> driftthreshold{
false};
1333 if (p_foundoldtrack.name !=
"None") {
1334 foundoldtrack = decodefoundoldtrack(p_foundoldtrack.data);
1336 if (p_driftthreshold.name !=
"None") {
1337 driftthreshold = decodedriftthreshold(p_driftthreshold.data);
1339 if (p_valstereobit.name !=
"None") {
1340 valstereobit = decodevalstereobit(p_valstereobit.data);
1343 if (std::all_of(p_phi.data.begin(), p_phi.data.end(), [](
char i) {return i == 0;})) {
1344 B2ERROR(
"Empty Phi Value found for 2DTrack, should not happen!");
1347 TRG2DFinderTrack trk2D = decode2DTrack(
1359 track2D = store2DTracks->appendNew(trk2D.phi0, trk2D.omega, 0., foundoldtrack, driftthreshold, valstereobit, iclock, iTracker);
1360 track2D->setRawOmega(trk2D.hwOmega);
1361 track2D->setRawPhi0(trk2D.hwPhi0);
1362 B2DEBUG(12, padright(
" 2DTrack: (phi=" + std::to_string(trk2D.phi0) +
", omega=" + std::to_string(
1363 trk2D.omega) +
", update=" + std::to_string(foundoldtrack[1]) +
")", 100));
1367 for (
unsigned iAx = 0; iAx < nAxialTSF; ++iAx) {
1368 const auto& ts = trk2D.ts[iAx];
1370 CDCTriggerSegmentHit* hit =
1371 addTSHit(ts, 2 * iAx, iTracker, tsHitsAll, iclock);
1372 unsigned iTS = TSIDInSL(ts[0], iAx * 2, iTracker);
1373 tsstr +=
"(SL" + std::to_string(iAx * 2) +
", " + std::to_string(iTS) +
", " + std::to_string(ts[1]) +
", " + std::to_string(
1374 ts[2]) +
", " + std::to_string(ts[3]) +
"),";
1375 track2D->addRelationTo(hit);
1378 B2DEBUG(16, padright(
" 2DTrack TS: " + tsstr, 100));
1382 TRGNeuroTrack trkNN;
1383 trkNN = decodeNNTrack(p_mlpout_z.data,
1384 p_mlpout_theta.data,
1387 p_mlpin_drifttime.data,
1396 B2DEBUG(11, padright(
" NNTrack: (z=" + std::to_string(trkNN.z) +
", theta=" + std::to_string(trkNN.theta) +
")", 100));
1398 double phi0 = track2D->getPhi0();
1399 double omega = track2D->getOmega();
1401 std::vector<unsigned> tsvector(9, 0);
1402 std::vector<unsigned> tstimevector(9, 0);
1406 for (
unsigned iSL = 0; iSL < 9; ++iSL) {
1407 tsvector[iSL] = trkNN.ts[iSL][3];
1408 tstimevector[iSL] = trkNN.ts[iSL][1];
1409 if (trkNN.ts[iSL][3] > 0) {
1410 unsigned iTS = TSIDInSL(trkNN.ts[iSL][0], iSL, iTracker);
1411 tsstr +=
"(SL" + std::to_string(iSL) +
", " + std::to_string(iTS) +
", " + std::to_string(trkNN.ts[iSL][1]) +
", " + std::to_string(
1412 trkNN.ts[iSL][2]) +
", " + std::to_string(trkNN.ts[iSL][3]) +
"),\n";
1415 if (!(trk2D.ts[iSL / 2][0] == trkNN.ts[iSL][0] &&
1417 trk2D.ts[iSL / 2][2] == trkNN.ts[iSL][2] &&
1418 trk2D.ts[iSL / 2][3] == trkNN.ts[iSL][3])) {
1424 tsstr +=
"( - ),\n";
1428 B2DEBUG(15, padright(
" NNTrack TS: " + tsstr, 100));
1430 CDCTriggerTrack* trackNN = storeNNTracks->appendNew(phi0, omega, 0.,
1431 trkNN.z, cos(trkNN.theta) / sin(trkNN.theta), 0., track2D->getFoundOldTrack(), track2D->getDriftThreshold(),
1432 track2D->getValidStereoBit(), trkNN.sector, tsvector, iclock, iTracker);
1433 trackNN->setHasETFTime(hasETFTime);
1434 track2D->setHasETFTime(hasETFTime);
1435 trackNN->setRawOmega(track2D->getRawOmega());
1436 trackNN->setRawPhi0(track2D->getRawPhi0());
1437 trackNN->setRawTheta(trkNN.hwTheta);
1438 trackNN->setRawZ(trkNN.hwZ);
1440 trackNN->setETF_unpacked(std::stoi(p_etftime.data, 0, 2));
1441 track2D->setETF_unpacked(std::stoi(p_etftime.data, 0, 2));
1443 trackNN->setETF_recalced(recalcETF(p_mlpin_drifttime.data, tstimevector, trackNN));
1444 track2D->setETF_recalced(recalcETF(p_mlpin_drifttime.data, tstimevector, trackNN));
1446 if (isin2d ==
false) {
1447 trackNN->setQualityVector(1);
1449 std::vector<float> inputVector(27, 0.);
1450 for (
unsigned iSL = 0; iSL < 9; ++iSL) {
1451 inputVector[3 * iSL] = trkNN.inputID[iSL];
1452 inputVector[3 * iSL + 1] = trkNN.inputT[iSL];
1453 inputVector[3 * iSL + 2] = trkNN.inputAlpha[iSL];
1455 CDCTriggerMLPInput* storeInput =
1456 storeNNInputs->appendNew(inputVector, trkNN.sector);
1457 trackNN->addRelationTo(storeInput);
1458 track2D->addRelationTo(trackNN);
1460 for (
unsigned iSL = 0; iSL < 9; ++iSL) {
1461 if (trkNN.ts[iSL][3] > 0) {
1462 CDCTriggerSegmentHit* hit =
nullptr;
1492 hit = addTSHit(trkNN.ts[iSL] , iSL, iTracker, tsHits, iclock);
1496 trackNN->addRelationTo(hit);
1498 track2D->addRelationTo(hit);
1522 void decodeNNIO_old(
1523 StoreArray<CDCTriggerUnpacker::NNBitStream>* bitsNN,
1524 StoreArray<CDCTriggerTrack>* store2DTracks,
1525 StoreArray<CDCTriggerTrack>* storeNNTracks,
1526 StoreArray<CDCTriggerSegmentHit>* tsHits,
1527 StoreArray<CDCTriggerMLPInput>* storeNNInputs)
1529 for (
short iclock = 0; iclock < bitsNN->getEntries(); ++iclock) {
1530 NNBitStream* bitsIn = (*bitsNN)[iclock];
1531 NNBitStream* bitsOutEnable = (*bitsNN)[iclock];
1532 for (
unsigned iTracker = 0; iTracker < nTrackers; ++iTracker) {
1533 const auto slvOutEnable = bitsOutEnable->signal()[iTracker];
1534 const auto slvIn = bitsIn->signal()[iTracker];
1537 if (stringOutEnable.c_str()[0] ==
'1') {
1538 CDCTriggerTrack* nntrack2D = decodeNNInput(iclock, iTracker, bitsIn, store2DTracks, tsHits);
1540 int foundTime = iclock;
1541 if (foundTime < bitsNN->getEntries()) {
1542 NNBitStream* bitsOut = (*bitsNN)[foundTime];
1543 NNBitStream* bitsSelectTS = (*bitsNN)[iclock];
1544 decodeNNOutput_old(iclock, iTracker, bitsOut, bitsSelectTS,
1545 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
shortcut for NaN of double type
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