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