Belle II Software  release-06-02-00
Tracker2D.cc
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 
9 //-----------------------------------------------------------------------------
10 // Description : A class to represent a CDC Tracker2D board
11 //-----------------------------------------------------------------------------
12 
13 #define TRGCDC_SHORT_NAMES
14 
15 #include <algorithm>
16 #include <iostream>
17 #include "trg/trg/Debug.h"
18 #include "trg/trg/State.h"
19 #include "trg/trg/Channel.h"
20 #include "trg/cdc/TRGCDC.h"
21 #include "trg/cdc/Wire.h"
22 #include "trg/cdc/Segment.h"
23 #include "trg/cdc/Tracker2D.h"
24 #include "trg/cdc/TrackSegmentFinder.h"
25 
26 using namespace std;
27 
28 namespace Belle2 {
34  unsigned TRGCDCTracker2D::_nTSF = 0;
35  vector<unsigned> TRGCDCTracker2D::_n;
36  TRGState TRGCDCTracker2D::_ts(160 + 192 + 256 + 320 + 384);
37 
38  TRGCDCTracker2D::TRGCDCTracker2D(const std::string& name,
39  const TRGClock& systemClock,
40  const TRGClock& dataClock,
41  const TRGClock& userClockInput,
42  const TRGClock& userClockOutput)
43  : TRGBoard(name, systemClock, dataClock, userClockInput, userClockOutput)
44  {
45  }
46 
48  {
49  }
50 
51  string
53  {
54  return ("TRGCDCTracker2D version 0.00");
55  }
56 
57  void
59  {
60  std::vector<const TRGCDCTrackSegmentFinder*>::push_back(a);
61  }
62 
63  void
64  TRGCDCTracker2D::dump(const string& message, const string& pre) const
65  {
66  TRGBoard::dump(message, pre);
67  }
68 
69  void
71  {
72 
73  const string sn = "TRGCDC 2D simulate : " + name();
75 
76  static bool first = true;
77  if (first) {
78  setConstants();
79  first = false;
80  }
81 
82  //...Delete old objects...
83  if (nOutput())
84  for (unsigned i = 0; i < nOutput(); i++)
85  if (output(i)->signal())
86  delete output(i)->signal();
87 
88  //...Create a combined input signal bundle from 5 TSF boards...
90  "-InputSignalBundle",
91  clockData());
92  for (unsigned i = 0; i < 5; i++) {
93  TRGSignalBundle* b = input(i)->signal();
94  if (! b)
95  continue;
96  for (unsigned j = 0; j < b->size(); j++) {
97  isb.push_back((* b)[j]);
98  }
99  }
100 
101  if (TRGDebug::level())
102  isb.dump("", TRGDebug::tab());
103 
104  //...Output signal bundle...
105  const string no = name() + "OutputSignalBundle";
106  TRGSignalBundle* osb = new TRGSignalBundle(no,
107  clockData(),
108  isb,
109  256,
110  _nTSF / 2 * 16,
111  TCTracker2D::packer);
112  output(0)->signal(osb);
113 
115  }
116 
117  TRGState
118  TCTracker2D::packer(const TRGState& input,
119  TRGState& registers,
120  bool& logicStillActive)
121  {
122 
123  //...Registers...
124  // Storing TSF hit history upto 16 clocks. #TSF is half of all TSF.
125  // reg[15 downto 0] : TSF-0 history (SL0)
126  // reg[31 downto 16] : TSF-1 history (SL0)
127  // ...
128  // reg[1279 downto 1264] : TSF-59 history (SL0)
129  // reg[1295 downto 1280] : TSF-? history (SL1)
130  // ...
131 
132  //...Shift registers (TSF hit history pipe)...
133  for (unsigned i = 0; i < nTSF() / 2; i++) {
134  TRGState s = registers.subset(i * 16, 16);
135  s.shift(1);
136  registers.set(i * 16, s);
137  }
138 
139  //...Unpack input state...
140  // Get TSF hit information. The drift time information is ignored.
141  unpacker(input, registers);
142 
143  //...Make TSF hit...
144  hitInformation(registers);
145 
146  //...Do core logic...
147 // HoughMappingPlus();
148 // HoughMappingMinus();
149 
150  //...Make output...
151  logicStillActive = registers.active();
152 
153  return TRGState(256);
154  }
155 
156  void
157  TCTracker2D:: unpacker(const TRGState& input,
158  TRGState& output)
159  {
160 
161  const string sn = "TRGCDC 2D unpacker";
163 
164  //...Constants...
165 // const unsigned noHit = 0b11111111;
166  const unsigned sizeSB = 420; // bits
167  const unsigned sizeTS = 21; // bits
168  const unsigned sizeID = 8; // bits
169  const unsigned posID = 13; // bit position
170 
171  //...Store hit TSF id...
172  unsigned tsfId[5][20]; // Max. 20 TSF ID is sent
173  bool hitFound = false;
174  for (unsigned i = 0; i < 5; i++) {
175  for (unsigned j = 0; j < 20; j++) {
176  unsigned jr = 20 - j - 1;
177  tsfId[i][jr] = input.subset(i * sizeSB + sizeTS * jr + posID,
178  sizeID);
179  if (tsfId[i][jr] != 0) {
180  output.set(tsfId[i][jr] * 16, true);
181  hitFound = true;
182  }
183  }
184  }
185 
186  if (TRGDebug::level() && hitFound) {
187  input.dump("", TRGDebug::tab() + "input bits:");
188  cout << TRGDebug::tab() << "TSF hit ID" << endl;
189  for (unsigned i = 0; i < 5; i++) {
190  cout << TRGDebug::tab() << " ASL" << i
191  << " < " << nTSF(i) / 2 << endl;
192  cout << TRGDebug::tab() << " ";
193  for (unsigned j = 0; j < 20; j++) {
194  cout << tsfId[i][j] << ",";
195  }
196  cout << endl;
197  }
198  }
199 
201  }
202 
203  void
204  TCTracker2D::hitInformation(const TRGState& registers)
205  {
206 
207  //...Clear info...
208  _ts.clear();
209 
210  //...Set TSF hit information...
211  for (unsigned i = 0; i < nTSF() / 2; i++) {
212  bool active = registers.subset(i * 16, 16).active();
213  if (active)
214  _ts.set(i, true);
215  }
216  }
217 
218  void
219  TCTracker2D::setConstants(void)
220  {
221 
222  //...# of TSFs...
223  const TRGCDC& cdc = * TRGCDC::getTRGCDC();
224  _nTSF = 0;
225  for (unsigned i = 0; i < 5; i++) { // Ax only
226  const unsigned n = cdc.nSegments(i * 2);
227  _n.push_back(n);
228  _nTSF += n;
229  }
230 
231  //...Consistency check...
232  if (_nTSF != nTSF()) {
233  cout << "TRGCDCTracker2D !!! # of TSF is inconsistent internally"
234  << endl;
235  cout << " _nTSF,nTSF()=" << _nTSF << "," << nTSF()
236  << endl;
237  }
238  for (unsigned i = 0; i < 5; i++) {
239  if (_n[i] != nTSF(i)) {
240  cout << "TRGCDCTracker2D !!! # of TSF is inconsistent internally"
241  << endl;
242  cout << " i,_n[i],nTSF(i)=" << i << ","
243  << _n[i] << "," << nTSF(i) << endl;
244  }
245 
246  }
247  if (_nTSF != _ts.size()) {
248  cout << "TRGCDCTracker2D !!! # of TSF is inconsistent internally"
249  << endl;
250  cout << " _nTSF,_ts.size()=" << _nTSF << ","
251  << _ts.size() << endl;
252  }
253  }
254 
256 } // namespace Belle2
A class to represent a trigger board.
Definition: Board.h:25
a class of TrackSegmentFinder in TRGCDC
void setConstants(void)
Sets constants.
A class to represent a digitized signal. Unit is nano second.
Definition: Clock.h:38
A class to represent a bundle of SignalVectors.
Definition: SignalBundle.h:26
A class to represent a state of multi bits.
Definition: State.h:24
static std::string tab(void)
returns tab spaces.
Definition: Debug.cc:47
static TRGCDC * getTRGCDC(void)
returns TRGCDC object.
Definition: TRGCDC.cc:190
void push_back(const TRGCDCTrackSegmentFinder *)
Appends a TSF board.
Definition: Tracker2D.cc:58
const TRGChannel * input(unsigned i) const
returns input channel i.
Definition: Board.h:158
TRGState subset(unsigned i, unsigned n) const
returns subset from i with n bits.
Definition: State.cc:356
virtual ~TRGCDCTracker2D()
Destructor.
Definition: Tracker2D.cc:47
const TRGClock & clockData(void) const
returns data clock.
Definition: Board.h:123
const std::string & name(void) const
returns name.
Definition: Board.h:109
static void enterStage(const std::string &stageName)
Declare that you enter new stage.
Definition: Debug.cc:24
const TRGState & set(unsigned position, bool state=true)
sets state at bit i.
Definition: State.h:305
static unsigned _nTSF
# of TSFs.
Definition: Tracker2D.h:102
TRGSignalBundle * signal(void) const
returns signal.
Definition: Channel.h:93
static int level(void)
returns the debug level.
Definition: Debug.cc:67
bool active(void) const
returns true if there are active bits.
Definition: State.h:156
static void leaveStage(const std::string &stageName)
Declare that you leave a stage.
Definition: Debug.cc:34
static std::string version(void)
returns version.
Definition: Tracker2D.cc:52
void simulate(void)
simulates firmware.
Definition: Tracker2D.cc:70
unsigned nOutput(void) const
returns output channels.
Definition: Board.h:180
TRGChannel * output(unsigned i) const
returns output channel i.
Definition: Board.h:165
void dump(const std::string &message="", const std::string &pre="") const
dumps contents.
Definition: Tracker2D.cc:64
Abstract base class for different kinds of events.