Belle II Software  release-05-01-25
TrackSegmentFinder.cc
1 //-----------------------------------------------------------------------------
2 // $Id$
3 //-----------------------------------------------------------------------------
4 // Filename : TrackSegmentFinder.cc
5 // Section : TRG CDC
6 // Owner : Jaebak Kim
7 // Email : jbkim@hep.korea.ac.kr
8 //-----------------------------------------------------------------------------
9 // Description : A class to find Track Segments
10 //-----------------------------------------------------------------------------
11 // $Log$
12 //-----------------------------------------------------------------------------
13 
14 #define TRG_SHORT_NAMES
15 #define TRGCDC_SHORT_NAMES
16 
17 #include <bitset>
18 #include "TVectorD.h"
19 #include "trg/trg/Debug.h"
20 #include "trg/trg/State.h"
21 #include "trg/trg/Channel.h"
22 #include "trg/trg/Utilities.h"
23 #include "trg/cdc/TRGCDC.h"
24 #include "trg/cdc/Cell.h"
25 #include "trg/cdc/Wire.h"
26 #include "trg/cdc/WireHit.h"
27 #include "trg/cdc/Segment.h"
28 #include "trg/cdc/SegmentHit.h"
29 #include "trg/cdc/TrackSegmentFinder.h"
30 #include "framework/datastore/StoreArray.h"
31 #include "framework/datastore/RelationArray.h"
32 #include "cdc/dataobjects/CDCSimHit.h"
33 #include "mdst/dataobjects/MCParticle.h"
34 #include "trg/cdc/FrontEnd.h"
35 #include "trg/cdc/Merger.h"
36 
37 using namespace std;
38 
39 namespace Belle2 {
45 //...For debug : yi...
46 // vector<TRGSignalVector * > dbgIn;
47 // vector<TRGSignalVector * > dbgOut;
48 
49  TRGCDCTrackSegmentFinder::TRGCDCTrackSegmentFinder(const TRGCDC& TRGCDC,
50  bool makeRootFile,
51  bool logicLUTFlag)
52  :
53  TRGBoard("", TRGClock("", 0, 0), TRGClock("", 0, 0), TRGClock("", 0, 0),
54  TRGClock("", 0, 0)),
55  _cdc(TRGCDC),
56  m_logicLUTFlag(logicLUTFlag),
57  m_makeRootFile(makeRootFile),
58  _type(), _tosbE(), _tosbT() // 2019/07/31 by ytlai
59  {
60 
61  m_Trg_PI = 3.141592653589793;
62 
63  m_hitPatternInformation = new TClonesArray("TVectorD");
64  m_particleEfficiency = new TClonesArray("TVectorD");
65  m_tsInformation = new TClonesArray("TVectorD");
66  m_nnPatternInformation = new TClonesArray("TVectorD");
67 
68  // For ROOT file
69  TDirectory* currentDir = gDirectory;
70  if (m_makeRootFile) {
71  m_fileTSF = new TFile("TSF.root", "RECREATE");
72 
73  m_treeInputTSF = new TTree("m_treeInputTSF", "InputTSF");
74  m_treeInputTSF->Branch("hitPatternInformation", &m_hitPatternInformation,
75  32000, 0);
76 
77  m_treeOutputTSF = new TTree("m_treeOutputTSF", "OutputTSF");
78  m_treeOutputTSF->Branch("particleEfficiency", &m_particleEfficiency, 32000, 0);
79  m_treeOutputTSF->Branch("tsInformation", &m_tsInformation, 32000, 0);
80 
81  // For neural network TSF. Filled only when TSF and priority is hit.
82  m_treeNNTSF = new TTree("m_treeNNTSF", "NNTSF");
83  m_treeNNTSF->Branch("nnPatternInformation", &m_nnPatternInformation, 32000, 0);
84  }
85  currentDir->cd();
86  }
87 
88 
90  const std::string& name,
91  boardType type,
92  const TRGClock& systemClock,
93  const TRGClock& dataClock,
94  const TRGClock& userClockInput,
95  const TRGClock& userClockOutput,
96  std::vector<TCSegment*>& tsSL)
97  : TRGBoard(name, systemClock, dataClock, userClockInput, userClockOutput),
98  _cdc(TRGCDC),
99  m_Trg_PI(), // 2019/07/31 by ytlai
100  m_logicLUTFlag(),
101  m_rootTSFFilename(),
102  m_fileTSF(),
103  _type(type),
104  // _tisb(0),
105  _tosbE(0),
106  _tosbT(0),
107  _tsSL(tsSL)
108  {
109 
110  }
112  {
113 
114  delete m_nnPatternInformation;
115  delete m_tsInformation;
116  delete m_particleEfficiency;
118  delete m_treeInputTSF;
119  if (m_makeRootFile) delete m_fileTSF;
120 
121  }
122 
125  {
126  return _type;
127  }
129  {
130  if (m_makeRootFile) {
131  m_fileTSF->Write();
132  m_fileTSF->Close();
133  }
134  }
135 
136  void TRGCDCTrackSegmentFinder::doit(std::vector<TRGCDCSegment*>& tss,
137  const bool trackSegmentClockSimulation,
138  std::vector<TRGCDCSegmentHit*>& segmentHits,
139  std::vector<TRGCDCSegmentHit*>* segmentHitsSL)
140  {
141  TRGDebug::enterStage("Track Segment Finder");
142 
143  // Saves TS information
144  //saveTSInformation(tss);
145 
146  //...Store TS hits...
147  const unsigned n = tss.size();
148  for (unsigned i = 0; i < n; i++) {
149  TCSegment& s = * tss[i];
150  s.simulate(trackSegmentClockSimulation, m_logicLUTFlag,
151  TRGCDC::getTRGCDC()->getCDCHitCollectionName());
152  if (s.signal().active()) {
153  TCSHit* th = new TCSHit(s);
154  s.hit(th);
155  segmentHits.push_back(th);
156  segmentHitsSL[s.layerId()].push_back(th);
157  }
158  }
159 
160  // Save TSF results
161  saveTSFResults(segmentHitsSL);
162 
163  // Saves NNTS information. Only when ts is hit.
164  //saveNNTSInformation(tss);
165 
166  if (TRGDebug::level() > 1) {
167  cout << TRGDebug::tab() << "TS hit list" << endl;
168  string dumpOption = "trigger";
169  if (TRGDebug::level() > 2)
170  dumpOption = "detail";
171  for (unsigned i = 0; i < _cdc.nSegments(); i++) {
172  const TCSegment& s = _cdc.segment(i);
173  if (s.signal().active())
174  s.dump(dumpOption, TRGDebug::tab(4));
175  }
176 
177  cout << TRGDebug::tab() << "TS hit list (2)" << endl;
178  if (TRGDebug::level() > 2)
179  dumpOption = "detail";
180  for (unsigned i = 0; i < segmentHits.size(); i++) {
181  const TCSHit& s = * segmentHits[i];
182  s.dump(dumpOption, TRGDebug::tab(4));
183  }
184 
185  cout << TRGDebug::tab() << "TS hit list (3)" << endl;
186  if (TRGDebug::level() > 2)
187  dumpOption = "detail";
188  for (unsigned j = 0; j < _cdc.nSuperLayers(); j++) {
189  for (unsigned i = 0; i < segmentHitsSL[j].size(); i++) {
190  const vector<TCSHit*>& s = segmentHitsSL[j];
191  for (unsigned k = 0; k < s.size(); k++)
192  s[k]->dump(dumpOption, TRGDebug::tab(4));
193  }
194  }
195  }
196 
197  TRGDebug::leaveStage("Track Segment Finder");
198  }
199 
200 
202  {
203 
204  //... Clear signal bundle...
205  // if(_tisb){
206  // for(unsigned i=0;i<_tisb->size();i++)
207  // delete (* _tisb)[i];
208  // delete _tisb;
209  // }
210  if (_tosbE) {
211  for (unsigned i = 0; i < _tosbE->size(); i++)
212  delete(* _tosbE)[i];
213  delete _tosbE;
214  }
215  if (_tosbT) {
216  for (unsigned i = 0; i < _tosbT->size(); i++)
217  delete(* _tosbT)[i];
218  delete _tosbT;
219  }
220 
221  //... Clock..
222  const TRGClock& dClock = TRGCDC::getTRGCDC()->dataClock();
223 
224  //... Make input signal bundle
225  TRGSignalVector inputv(name() + "inputMerger", dClock);
226  // const string ni= name()+"InputSignalBundle";
227  // _tisb = new TRGSignalBundle(ni, dClock);
228 
229  //TRGSignalVector *inputM= new TRGSignalVector(*( (*(*this)[0]->output())[0]));
230  vector <TRGSignalVector*> inputM;
231  vector <TRGSignalVector*> findOUTTrack;
232  vector <TRGSignalVector*> findOUTEvt;
233  vector <int> tmpCTimeListE;
234  vector <int> changeTimeListE;
235  vector <int> tmpCTimeListT;
236  vector <int> changeTimeListT;
237  inputM.resize((*this).size());
238  //yi for(unsigned i=0;i<(*this).size();i++){
239  for (unsigned i = 0; i < nInput(); i++) {
240  //yi inputM[i] = new TRGSignalVector(*( (*(*this)[i]->output())[0]));
241  inputM[i] = new TRGSignalVector(* (* input(i)->signal())[0]);
242  }
243 
244  // TRGSignalVector *inputM= new TRGSignalVector(*( (*(*this)[0]->output())[0]));
245 
246  for (unsigned i = 0; i < inputM[0]->size(); i++) {
247 
248  TRGSignal msig = (*(inputM[0]))[i];
249  inputv += msig;
250  }
251 
252  vector<TRGSignalVector*> separateTS;
253  TRGSignalVector* clockCounter = new TRGSignalVector(inputv[236]);
254  for (int i = 0; i < 8; i++)
255  clockCounter->push_back(inputv[236 + i]);
256  separateTS.resize(16);
257  //separateTS.resize((*this).size()*16);
258  int nTS = separateTS.size();
259  findOUTTrack.resize(nTS);
260  findOUTEvt.resize(nTS);
261  if (type() == outerType) {
262  for (int i = 0; i < nTS; i++) {
263  separateTS[i] = new TRGSignalVector(inputv[i + 208]);
265  if (i == 0)
266  separateTS[i]->push_back(inputv[255]);
267  else
268  separateTS[i]->push_back(inputv[i - 1]);
269  separateTS[i]->push_back(inputv[i]);
270  if (i == nTS)
271  separateTS[i]->push_back(inputv[255]);
272  else
273  separateTS[i]->push_back(inputv[i + 1]);
274  if (i == 0)
275  separateTS[i]->push_back(inputv[255]);
276  else
277  separateTS[i]->push_back(inputv[i + 15]);
278  separateTS[i]->push_back(inputv[i + 16]);
279  separateTS[i]->push_back(inputv[i + 32]);
280  if (i == 0)
281  separateTS[i]->push_back(inputv[255]);
282  else
283  separateTS[i]->push_back(inputv[i + 47]);
284  separateTS[i]->push_back(inputv[i + 48]);
285  if (i == 0)
286  separateTS[i]->push_back(inputv[255]);
287  else
288  separateTS[i]->push_back(inputv[i + 63]);
289  separateTS[i]->push_back(inputv[i + 64]);
290  if (i == nTS)
291  separateTS[i]->push_back(inputv[255]);
292  else
293  separateTS[i]->push_back(inputv[i + 65]);
294 
296  separateTS[i]->push_back(inputv[4 * i + 80]);
297  separateTS[i]->push_back(inputv[4 * i + 81]);
298  separateTS[i]->push_back(inputv[4 * i + 82]);
299  separateTS[i]->push_back(inputv[4 * i + 83]);
301  separateTS[i]->push_back(inputv[4 * i + 144]);
302  separateTS[i]->push_back(inputv[4 * i + 145]);
303  separateTS[i]->push_back(inputv[4 * i + 146]);
304  separateTS[i]->push_back(inputv[4 * i + 147]);
306  const TRGSignalVector& cc = dClock.clockCounter();
307  // cc.dump();
308  separateTS[i]->push_back(cc[0]);
309  separateTS[i]->push_back(cc[1]);
310  separateTS[i]->push_back(cc[2]);
311  separateTS[i]->push_back(cc[3]);
312  separateTS[i]->push_back(cc[4]);
313 
314  }
315  // Board Type Check Start.(for future)
316  for (int i = 0; i < nTS; i++) {
317  findOUTTrack[i] = findTSHit(separateTS[i], i)[0];
318  vector<int> tt = findOUTTrack[i]->stateChanges();
319  if (tt.size())
320  tmpCTimeListT.insert(tmpCTimeListT.end(), tt.begin(), tt.end());
321 
322  findOUTEvt[i] = findTSHit(separateTS[i], i)[1];
323  vector<int> ee = findOUTEvt[i]->stateChanges();
324  if (ee.size())
325  tmpCTimeListE.insert(tmpCTimeListE.end(), ee.begin(), ee.end());
326 
327  //...iw for debug...
328  // dbgIn.push_back(separateTS[i]);
329  // dbgOut.push_back(findOUTTrack[i]);
330  }
331 
332  for (unsigned i = 0; i < tmpCTimeListT.size(); i++) {
333  bool nomatch = true;
334  for (unsigned j = 0; j < changeTimeListT.size(); j++) {
335  if (tmpCTimeListT[i] == changeTimeListT[j]) {
336  nomatch = false;
337  break;
338  }
339  }
340  if (nomatch) changeTimeListT.push_back(tmpCTimeListT[i]);
341  }
342 
343  TRGSignalVector* trackerOut = packerOuterTracker(findOUTTrack,
344  changeTimeListT, 6);
345  (*trackerOut).insert((*trackerOut).end(), (*clockCounter).begin(),
346  (*clockCounter).end());
347  trackerOut->name("TSF TrackerOut");
348 
349  const string noT = name() + "OutputSignalBundleTracker";
350  _tosbT = new TRGSignalBundle(noT, dClock);
351  _tosbT->push_back(trackerOut);
352  if (_tosbT) {
353  (*_tosbT)[0]->name(noT);
354  for (unsigned i = 0; i < (*(*_tosbT)[0]).size(); i++)
355  (*(*_tosbT)[0])[i].name(noT + ":bit" + TRGUtilities::itostring(i));
356  // _tosbT->dump("","");
357  }
358 
359  for (unsigned i = 0; i < tmpCTimeListE.size(); i++) {
360  bool nomatch = true;
361  for (unsigned j = 0; j < changeTimeListE.size(); j++) {
362  if (tmpCTimeListE[i] == changeTimeListE[j]) {
363  nomatch = false;
364  break;
365  }
366  }
367  if (nomatch) changeTimeListE.push_back(tmpCTimeListE[i]);
368  }
369 
370  TRGSignalVector* evtOut = packerOuterEvt(findOUTEvt, changeTimeListE, 6);
371  (*evtOut).insert((*evtOut).end(), (*clockCounter).begin(),
372  (*clockCounter).end());
373 
374  const string noE = name() + "OutputSignalBundleEvt";
375  _tosbE = new TRGSignalBundle(noE, dClock);
376  _tosbE->push_back(evtOut);
377  if (_tosbE) {
378  (*_tosbE)[0]->name(noE);
379  for (unsigned i = 0; i < (*(*_tosbE)[0]).size(); i++)
380  (*(*_tosbE)[0])[i].name(noE + ":bit" + TRGUtilities::itostring(i));
381  // _tosbE->dump("","");
382  }
383  // Board Type Check End.
384  }
385 
386  }
387 
388  vector <TRGSignalVector*>
389  TSFinder::findTSHit(TRGSignalVector* eachInput, int tsid)
390  {
391 
392  //variables for common
393  const string na = "TSCandidate" + TRGUtilities::itostring(
394  tsid) + " in " + name();
395  TCSegment* tsi = _tsSL[tsid];
396  vector <TRGSignalVector*> result;
397 
398  //variables for EvtTime & Low pT
399  vector<bool> fTimeVect;
400  // int tmpFTime = 0 ;
401 
402  //variables for Tracker & N.N
403  vector <bool> tmpOutBool;
404 
405  TRGSignalVector* resultT = new TRGSignalVector(na, eachInput->clock(), 22);
406  TRGSignalVector* resultE = new TRGSignalVector(na, eachInput->clock(), 10);
407  TRGSignalVector* Hitmap = new TRGSignalVector(na + "HitMap",
408  eachInput->clock(), 0);
409  TRGSignalVector pTime(na + "PriorityTime", eachInput->clock(), 0);
410  TRGSignalVector fTime(na + "FastestTime", eachInput->clock(), 0);
411  for (unsigned i = 0; i < 12; i++) {
412  Hitmap->push_back((*eachInput)[i]);
413  (*Hitmap)[i].widen(16);
414  }
415  for (unsigned i = 0; i < 4; i++) {
416  pTime.push_back((*eachInput)[i + 12]);
417  fTime.push_back((*eachInput)[i + 16]);
418  }
419  for (unsigned i = 0; i < 5; i++) {
420  pTime.push_back((*eachInput)[i + 20]);
421  fTime.push_back((*eachInput)[i + 20]);
422  }
423 
424  vector <int> changeTime = Hitmap->stateChanges();
425 
426  int* LUTValue = new int[changeTime.size()];
427  if (changeTime.size()) {
428  int hitPosition = 0;
429  bool fTimeBool[10];
430  int tmpPTime = 0 ;
431  int tmpCTime = 0 ;
432  int tmpOutInt;
433  fTime.state(changeTime[0]).copy2bool(fTimeBool);
434  fTimeBool[9] = true;
435  fTimeVect.insert(fTimeVect.begin(), fTimeBool, fTimeBool + 10);
436  //tmpFTime = mkint(fTime.state(changeTime[0]));
437  bool eOUT = true;
438  for (unsigned i = 0; i < changeTime.size(); i++) {
439  LUTValue[i] = tsi->LUT()->getValue(mkint(Hitmap->state(changeTime[i])));
440 
442  if ((LUTValue[i]) && (eOUT)) {
443  resultE->set(fTimeVect, changeTime[i]);
444  eOUT = false;
445  }
446 
447  bool priority1rise = (*Hitmap)[6].riseEdge(changeTime[i]);
448  bool priority2rise = ((*Hitmap)[7].riseEdge(changeTime[i]) |
449  (*Hitmap)[8].riseEdge(changeTime[i]));
450 
452  //ready for output
453  if (priority1rise) {
454  hitPosition = 3;
455  tmpPTime = mkint(pTime.state(changeTime[i]));
456  tmpCTime = changeTime[i];
457  } else if (priority2rise) {
458  if (!hitPosition) {
459  tmpPTime = mkint(pTime.state(changeTime[i]));
460  tmpCTime = changeTime[i];
461  if ((*Hitmap)[0].state(changeTime[i])) hitPosition = 2;
462  else hitPosition = 1;
463  }
464  }
465 
466  // output selection
467  if ((hitPosition) && (LUTValue[i]) && ((changeTime[i] - tmpCTime) < 16)) {
468  tmpOutInt = tsid * pow(2, 13) + tmpPTime * pow(2, 4) + LUTValue[i] * pow(2,
469  2) + hitPosition;
470  tmpOutBool = mkbool(tmpOutInt, 22);
471  if (hitPosition == 3) {
472  if (priority1rise) resultT->set(tmpOutBool, changeTime[i]);
473  else {
474  if ((LUTValue[i] == 1) | (LUTValue[i] == 2)) {
475  if (!((LUTValue[i - 1] == 1) |
476  (LUTValue[i - 1] == 2)))
477  resultT->set(tmpOutBool, changeTime[i]);
478  } else {
479  if (!(LUTValue[i - 1])) resultT->set(tmpOutBool, changeTime[i]);
480  }
481  }
482  } else {
483  if (priority2rise) resultT->set(tmpOutBool, changeTime[i]);
484  else {
485  if ((LUTValue[i] == 1) | (LUTValue[i] == 2)) {
486  if (!((LUTValue[i - 1] == 1) |
487  (LUTValue[i - 1] == 2)))
488  resultT->set(tmpOutBool, changeTime[i]);
489  } else {
490  if (!(LUTValue[i])) resultT->set(tmpOutBool, changeTime[i]);
491  }
492  }
493  }
494  }
495 
496  }
497 
498  }
499  result.push_back(resultT);
500  result.push_back(resultE);
501 
502  delete [] LUTValue;
503  delete Hitmap;
504 
505  return result;
506  }
507 
508  TRGSignalVector*
509  TSFinder::packerOuterTracker(vector<TRGSignalVector*>& hitList,
510  vector<int>& cList,
511  const unsigned maxHit)
512  {
513  TRGSignalVector* result =
514  new TRGSignalVector("", (* hitList[0]).clock() , 21 * maxHit);
515 
516  for (unsigned ci = 0; ci < cList.size(); ci++) {
517  unsigned cntHit = 0;
518  for (unsigned hi = 0; hi < hitList.size(); hi++) {
519  TRGState s = (* hitList[hi]).state(cList[ci]);
520  if (s.active()) {
521  if (cntHit >= maxHit) continue;
522  for (unsigned j = 0; j < 21; j++) {
523  if ((* hitList[hi])[j].state(cList[ci])) {
524  (* result)[21 * (maxHit - 1) - (cntHit * 21) + j]
525  .set(cList[ci], cList[ci] + 1);
526  }
527  }
528  if (TRGDebug::level()) {
529  TRGState t = hitList[hi]->state(cList[ci]).subset(13, 9);
530  cout << TRGDebug::tab() << " hit found : TSF out local ID="
531  << unsigned(t) << "(" << t << ")" << endl;
532  }
533 
534  ++cntHit;
535  // result->dump("", "??? ");
536  }
537  }
538  }
539 
540  return result;
541  }
542 
543  TRGSignalVector*
544  TSFinder::packerOuterEvt(vector<TRGSignalVector*> hitList, vector<int> cList,
545  int maxHit)
546  {
547 
548  //TRGSignalVector * result = new TRGSignalVector("",(*hitList[0]).clock() ,N+9*maxHit);
549  TRGSignalVector* result = new TRGSignalVector("", (*hitList[0]).clock() ,
550  hitList.size() + 9 * maxHit);
551 
552  for (unsigned ci = 0; ci < cList.size(); ci++) {
553  int cntHit = 0;
554  for (unsigned hi = 0; hi < hitList.size(); hi++) {
555  if ((*hitList[hi]).state(cList[ci]).active()) {
556  (*result)[9 * maxHit + hi].set(cList[ci], cList[ci] + 1);
557  if (cntHit >= maxHit) continue;
558  for (unsigned j = 0; j < (((*hitList[hi])).size() - 1); j++) {
559  if ((*hitList[hi])[j].state(cList[ci]))
560  (*result)[9 * (maxHit - 1) - (cntHit * 9) + j].set(cList[ci], cList[ci] + 1);
561  }
562  cntHit++;
563  }
564  }
565  }
566  return result;
567  }
568 
569  double
570  TSFinder::mkint(TRGState bitInput)
571  {
572  double r = 0;
573  bool* binput = new bool[bitInput.size()];
574  bitInput.copy2bool(binput);
575  for (unsigned i = 0; i < bitInput.size(); i++) {
576  if (binput[i])
577  r += pow(2, i);
578  }
579  delete[] binput;
580  return r;
581  }
582 
583  vector<bool>
584  TSFinder::mkbool(int N, int bitSize)
585  {
586  vector<bool> boutput;
587  boutput.resize(bitSize);
588  int tmpint = N;
589  for (unsigned i = 0; tmpint; i++) {
590  if (tmpint % 2) boutput[i] = true;
591  else boutput[i] = false;
592  tmpint = tmpint / 2;
593  }
594 
595  return boutput;
596  }
597 
598 //
599 
600  void TRGCDCTrackSegmentFinder::saveTSInformation(std::vector<TRGCDCSegment*>&
601  tss)
602  {
603 
604  TClonesArray& hitPatternInformation = *m_hitPatternInformation;
605  hitPatternInformation.Clear();
606 
607  StoreArray<CDCSimHit> SimHits;
608  if (! SimHits.getEntries()) {
609  //cout << "CDCTRGTSF !!! can not access to CDCSimHits" << endl;
610  return;
611  }
612  StoreArray<MCParticle> mcParticles;
613  if (! mcParticles.getEntries()) {
614  //cout << "CDCTRGTSF !!! can not access to MCParticles" << endl;
615  return;
616  }
617 
618  //cout<<"Save TS information"<<endl;
619  // Loop over all TSs. wireHit has only one wireSimHit. Meaning there is a particle overlap hit bug.
620  const unsigned nTSs = tss.size();
621  unsigned nHitTSs = 0;
622  for (unsigned iTS = 0; iTS < nTSs; iTS++) {
623  const TCSegment& ts = * tss[iTS];
624  const TRGCDCWire* priority;
625  const TRGCDCWire* secondPriorityL;
626  const TRGCDCWire* secondPriorityR;
627  // Find priority wires
628  if (ts.wires().size() == 15) {
629  priority = ts.wires()[0];
630  secondPriorityR = ts.wires()[1];
631  secondPriorityL = ts.wires()[2];
632  } else {
633  priority = ts.wires()[5];
634  secondPriorityR = ts.wires()[6];
635  secondPriorityL = ts.wires()[7];
636  }
637  // Find L/R, phi of priority wires
638  vector<int> priorityLRs(3);
639  vector<float> priorityPhis(3);
640  TVector3 posOnTrack;
641  TVector3 posOnWire;
642  if (priority->hit() != 0) {
643  int iSimHit = priority->hit()->iCDCSimHit();
644  priorityLRs[0] = SimHits[iSimHit]->getPosFlag();
645  posOnTrack = SimHits[iSimHit]->getPosTrack();
646  posOnWire = SimHits[iSimHit]->getPosWire();
647  priorityPhis[0] = (posOnTrack - posOnWire).Phi() + m_Trg_PI / 2 -
648  posOnWire.Phi();
649  //cout<<ts.name()<<endl;
650  //cout<<"Track: "<<posOnTrack.x()<<" "<<posOnTrack.y()<<" "<<posOnTrack.z()<<endl;
651  //cout<<"Wire: "<<posOnWire.x()<<" "<<posOnWire.y()<<" "<<posOnWire.z()<<endl;
652  //cout<<"Before Phi: "<<(posOnTrack - posOnWire).Phi()<<" PosOnWirePhi: "<<posOnWire.Phi()<<" After Phi: "<<priorityPhis[0]<<endl;
653  //cout<<"LR: "<<priorityLRs[0]<<endl;
654  } else {
655  priorityLRs[0] = -1;
656  priorityPhis[0] = 9999;
657  }
658  if (secondPriorityR->hit() != 0) {
659  int iSimHit = secondPriorityR->hit()->iCDCSimHit();
660  priorityLRs[1] = SimHits[iSimHit]->getPosFlag();
661  posOnTrack = SimHits[iSimHit]->getPosTrack();
662  posOnWire = SimHits[iSimHit]->getPosWire();
663  priorityPhis[1] = (posOnTrack - posOnWire).Phi() + m_Trg_PI / 2 -
664  posOnWire.Phi();
665  } else {
666  priorityLRs[1] = -1;
667  priorityPhis[1] = 9999;
668  }
669  if (secondPriorityL->hit() != 0) {
670  int iSimHit = secondPriorityL->hit()->iCDCSimHit();
671  priorityLRs[2] = SimHits[iSimHit]->getPosFlag();
672  posOnTrack = SimHits[iSimHit]->getPosTrack();
673  posOnWire = SimHits[iSimHit]->getPosWire();
674  priorityPhis[2] = (posOnTrack - posOnWire).Phi() + m_Trg_PI / 2 -
675  posOnWire.Phi();
676  } else {
677  priorityLRs[2] = -1;
678  priorityPhis[2] = 9999;
679  }
680 
681  const unsigned nWires = ts.wires().size();
682  unsigned nHitWires = 0;
683  // Find TSPatternInformation for each particle
684  map<int, unsigned> particleTSPattern;
685  // Loop over wires in TS
686  for (unsigned iWire = 0; iWire < nWires; iWire++) {
687  //...Copy signal from a wire...
688  const TRGSignal& wireSignal = ts.wires()[iWire]->signal();
689  if (wireSignal.active()) ++nHitWires;
690  // Find MC particle of hit wire
691  const TRGCDCWireHit* wireHit = ts.wires()[iWire]->hit();
692  if (wireHit != 0) {
693  MCParticle* particle = SimHits[wireHit->iCDCSimHit()]->getRelatedFrom<MCParticle>();
694  int iMCParticle = (particle) ? particle->getArrayIndex() : mcParticles.getEntries();
695  // If new particle
696  if (particleTSPattern[iMCParticle] == 0) {
697  particleTSPattern[iMCParticle] = 1 << iWire;
698  } else {
699  particleTSPattern[iMCParticle] |= 1 << iWire;
700  }
701  }
702  } // Loop over wires in TS
703 
704  // Print pattern for each particle
705  //for(map<int, unsigned >::const_iterator it = particleTSPattern.begin(); it != particleTSPattern.end(); it++ ) {
706  // bitset<15> printPattern((*it).second);
707  // cout<<ts.name()<<" MC Particle: "<< (*it).first <<" pattern: "<<printPattern<<endl;
708  //}
709 
710  if (nHitWires != 0) {
711  // Ignore TSPatterns that have 2 particles passing TS.
712  if (particleTSPattern.size() == 1) {
713  map<int, unsigned>::const_iterator it = particleTSPattern.begin();
714  bitset<15> printPattern((*it).second);
715  //cout<<ts.name()<<" MC Particle: "<< (*it).first <<" pattern: "<<printPattern<<endl;
716  //cout<<(*it).first<<" "<<ts.superLayerId()<<" "<<printPattern<<endl;
717  // Save TS Pattern information
718  TVectorD tsPatternInformation(9);
719  tsPatternInformation[0] = (*it).first;
720  tsPatternInformation[1] = ts.superLayerId();
721  tsPatternInformation[2] = double((*it).second);
722  tsPatternInformation[3] = priorityLRs[0];
723  tsPatternInformation[4] = priorityPhis[0];
724  tsPatternInformation[5] = priorityLRs[1];
725  tsPatternInformation[6] = priorityPhis[1];
726  tsPatternInformation[7] = priorityLRs[2];
727  tsPatternInformation[8] = priorityPhis[2];
728  new(hitPatternInformation[nHitTSs++]) TVectorD(tsPatternInformation);
729  }
730  //cout<<ts.name()<<" has "<<nHitWires<<" hit wires."<<endl;
731  }
732  } // End of loop over all TSs
733  if (m_makeRootFile) m_treeInputTSF->Fill();
734  //cout<<"End saving TS information"<<endl;
735  } // End of save function
736 
737 
738 
739  void TRGCDCTrackSegmentFinder::saveTSFResults(std::vector<TRGCDCSegmentHit*>*
740  segmentHitsSL)
741  {
742 
743  TClonesArray& particleEfficiency = *m_particleEfficiency;
744  TClonesArray& tsInformation = *m_tsInformation;
745  particleEfficiency.Clear();
746  tsInformation.Clear();
747 
748  int mcInformation = 1;
750  StoreArray<CDCSimHit> SimHits;
751  if (! SimHits) {
752  //cout << "CDCTRGTSF !!! can not access to CDCSimHits" << endl;
753  mcInformation = 0;
754  }
755  StoreArray<MCParticle> mcParticles;
756  if (! mcParticles) {
757  //cout << "CDCTRGTSF !!! can not access to MCParticles" << endl;
758  mcInformation = 0;
759  }
760  if (mcInformation) {
761  RelationArray cdcSimHitRel(mcParticles, SimHits);
762  // Make map for hit to mcParticle
763  map<int, int> simHitsMCParticlesMap;
764  // Loop over all particles
765  for (int iPart = 0; iPart < cdcSimHitRel.getEntries(); iPart++) {
766  // Loop over all hits for particle
767  for (unsigned iHit = 0; iHit < cdcSimHitRel[iPart].getToIndices().size();
768  iHit++) {
769  //cout<<"From: "<<cdcSimHitRel[iPart].getFromIndex()<<" To: "<<cdcSimHitRel[iPart].getToIndex(iHit)<<endl;
770  simHitsMCParticlesMap[cdcSimHitRel[iPart].getToIndex(iHit)] =
771  cdcSimHitRel[iPart].getFromIndex();
772  }
773  }
775  //for(map<int, int >::iterator it = simHitsMCParticlesMap.begin(); it != simHitsMCParticlesMap.end(); it++) {
776  // cout<<"SimHit Index: "<<(*it).first<<" MCParticle Index: "<<(*it).second<<endl;
777  //}
778  // Find efficiency for each particle
779  // Find hit TS SuperLayer for particles
780  // particleNHiTS[iMCParticle] = hitTSSL
781  map<int, unsigned> particleNHitTS;
782  // Loop over all hit TSs
783  for (int iSuperLayer = 0; iSuperLayer < 9; iSuperLayer++) {
784  // map<int, bool> particleHitTS;
785  for (unsigned iTS = 0; iTS < segmentHitsSL[iSuperLayer].size(); iTS++) {
786  const TCSegment& ts = segmentHitsSL[iSuperLayer][iTS]->segment();
787  unsigned nWires = ts.wires().size();
788  for (unsigned iWire = 0; iWire < nWires; iWire++) {
789  const TRGCDCWireHit* wireHit = ts.wires()[iWire]->hit();
790  if (wireHit != 0) {
791  int iMCParticle = simHitsMCParticlesMap[wireHit->iCDCSimHit()];
792  if (particleNHitTS[iMCParticle] == 0) {
793  unsigned hitTSSL;
794  hitTSSL = 1 << iSuperLayer;
795  particleNHitTS[iMCParticle] = hitTSSL;
796  } else
797  particleNHitTS[iMCParticle] |= 1 << iSuperLayer;
798  //cout<<ts.name()<<" "<<ts.wires()[iWire]->name()<<" was hit.";
799  //cout<<" Particle was "<<simHitsMCParticlesMap[wireHit->iCDCSimHit()]<<endl;
800  } // If wire is hit
801  } // End of loop over all wires in TS
802  } // End of loop over all TS in super layer
803  } // End of loop over all hit TSs
805  //for( map<int, unsigned>::const_iterator it = particleNHitTS.begin(); it != particleNHitTS.end(); it++) {
806  // bitset<9> printSuperLayers((*it).second);
807  // cout<<"MC particle: "<<(*it).first<<" HitSuperLayers: "<<printSuperLayers<<" nCount: "<<printSuperLayers.count()<<endl;
808  //}
809 
810  // Find last CDC hit for each MC particle
811  // tsEfficiency[i][tsEfficiency,particle pT,#MCTS]
812  vector<vector<float>> tsEfficiency;
813  // Loop over all particles
814  for (int iPart = 0; iPart < cdcSimHitRel.getEntries(); iPart++) {
815  int lastWireHit = -1;
816  // Loop over all hits for particle
817  for (unsigned iHit = 0; iHit < cdcSimHitRel[iPart].getToIndices().size();
818  iHit++) {
819  int iSimHit = cdcSimHitRel[iPart].getToIndex(iHit);
820  if (SimHits[iSimHit]->getWireID().getICLayer() > lastWireHit) lastWireHit =
821  SimHits[iSimHit]->getWireID().getICLayer();
822  //cout<<"Particle: "<<cdcSimHitRel[iPart].getFromIndex()<<" CDCSimHit: "<<iSimHit<<endl;
823  //cout<<"SuperLayer: "<<SimHits[iSimHit]->getWireID().getISuperLayer()<<" wireLayer: "<<SimHits[iSimHit]->getWireID().getICLayer()<<endl;
824  }
825  //cout<<"iMCParticle: "<<cdcSimHitRel[iPart].getFromIndex()<<" Last wire Hit: "<<lastWireHit<<endl;
826  // Calculate last superlayer
827  int lastSLHit = 0;
828  if (lastWireHit >= 53) lastSLHit = 9;
829  else if (lastWireHit >= 47) lastSLHit = 8;
830  else if (lastWireHit >= 41) lastSLHit = 7;
831  else if (lastWireHit >= 35) lastSLHit = 6;
832  else if (lastWireHit >= 29) lastSLHit = 5;
833  else if (lastWireHit >= 23) lastSLHit = 4;
834  else if (lastWireHit >= 17) lastSLHit = 3;
835  else if (lastWireHit >= 11) lastSLHit = 2;
836  else if (lastWireHit >= 5) lastSLHit = 1;
837  // Get number of hit TS for particle
838  int iMCParticle = cdcSimHitRel[iPart].getFromIndex();
839  bitset<9> hitSuperLayers(particleNHitTS[iMCParticle]);
840  int numberHitSuperLayers = hitSuperLayers.count();
841  //cout<<"iMCParticle: "<< iMCParticle << " # hit TS: "<<numberHitSuperLayers<<" MC # TS: "<<lastSLHit<<endl;
842  float mcPt = mcParticles[iMCParticle]->getMomentum().Perp();
843  float efficiency;
844  if (lastSLHit == 0) efficiency = -1;
845  else efficiency = float(numberHitSuperLayers) / lastSLHit;
846  //cout<<"Efficiency: "<<float(numberHitSuperLayers)/lastSLHit<<" MC pT: "<<mcPt<<endl;
847  vector<float> tempEfficiency;
848  tempEfficiency.resize(3);
849  tempEfficiency[0] = efficiency;
850  tempEfficiency[1] = mcPt;
851  tempEfficiency[2] = lastSLHit;
852  tsEfficiency.push_back(tempEfficiency);
853  } // End of looping over all particles
855  //for(unsigned iEfficiency=0; iEfficiency<tsEfficiency.size(); iEfficiency++) {
856  // cout<<"Efficiency: "<<tsEfficiency[iEfficiency][0]<<" Pt: "<<tsEfficiency[iEfficiency][1]<<" #MCTS: "<<tsEfficiency[iEfficiency][2]<<endl;
857  //}
858 
859  // Save TS efficiency for each particle
860  for (unsigned iEfficiency = 0; iEfficiency < tsEfficiency.size();
861  iEfficiency++) {
862  TVectorD t_particleEfficiency(3);
863  t_particleEfficiency[0] = tsEfficiency[iEfficiency][0];
864  t_particleEfficiency[1] = tsEfficiency[iEfficiency][1];
865  t_particleEfficiency[2] = tsEfficiency[iEfficiency][2];
866  new(particleEfficiency[iEfficiency]) TVectorD(t_particleEfficiency);
867  }
868 
869  } // End of no MC information
870 
871  // Save TS information
872  // [FIXME] Doesn't work when second only priority is hit.
873  // Loop over all hit TSs
874  int iHitTS = 0;
875  for (int iSuperLayer = 0; iSuperLayer < 9; iSuperLayer++) {
876  for (unsigned iTS = 0; iTS < segmentHitsSL[iSuperLayer].size(); iTS++) {
877  const TCSegment& ts = segmentHitsSL[iSuperLayer][iTS]->segment();
878  //unsigned nWires = ts.wires().size();
879  unsigned iWire = 5;
880  if (iSuperLayer == 0) iWire = 0;
881  const TRGCDCWireHit* wireHit = ts.wires()[iWire]->hit();
882  if (wireHit != 0) {
883  //cout<<"[TSF]: "<<ts.name()<<" was hit at ";
884  unsigned nHits = ts.wires()[iWire]->signal().nSignals();
885  for (unsigned iHit = 0; iHit < nHits; iHit++) {
886  if (iHit % 2 == 1) continue;
887  TVectorD tempTSInformation(3);
888  tempTSInformation[0] = iSuperLayer;
889  tempTSInformation[1] = ts.localId();
890  tempTSInformation[2] = ts.wires()[iWire]->signal().stateChanges()[iHit];
891  new(tsInformation[iHitTS++]) TVectorD(tempTSInformation);
892  //cout<<ts.wires()[iWire]->signal().stateChanges()[iHit]<<", ";
893  //iHit++;
894  }
895  //cout<<endl;
896  } // If wire is hit
897  } // End of loop over all TS in super layer
898  } // End of loop over all hit TSs
899 
900  if (m_makeRootFile) m_treeOutputTSF->Fill();
901 
902  } // End of saving TSF results
903 
904 
905 
907  std::vector<TRGCDCSegment*>& tss)
908  {
909 
910  StoreArray<CDCSimHit> SimHits;
911  if (! SimHits) {
912  //cout << "CDCTRGTSF !!! can not access to CDCSimHits" << endl;
913  return;
914  }
915 
916  TClonesArray& nnPatternInformation = *m_nnPatternInformation;
917  nnPatternInformation.Clear();
918 
919  // Save Timing information in ROOT file. Fill for each TS.
920  // Loop over all TSs. wireHit has only one wireSimHit. Meaning there is a particle overlap hit bug.
921  const unsigned nTSs = tss.size();
922  unsigned indexSaving = 0;
923  for (unsigned iTS = 0; iTS < nTSs; iTS++) {
924  // If TS is hit
925  const TCSegment& ts = * tss[iTS];
926  const TCSHit* tsHit = ts.hit();
927  if (tsHit) {
928  const TRGCDCWire* priority;
929  if (ts.wires().size() == 15) priority = ts.wires()[0];
930  else priority = ts.wires()[5];
931  // If priority wire is hit
932  if (priority->hit()) {
933 
934  // Calculate timeWires
935  // Fill wire timing. Not hit = 9999. Unit is ns.
936  vector<float> wireTime;
937  if (ts.superLayerId() == 0)
938  wireTime.resize(15);
939  else
940  wireTime.resize(11);
941  // Loop over all wires
942  //cout<<ts.name();
943  const unsigned nWires = ts.wires().size();
944  for (unsigned iWire = 0; iWire < nWires; iWire++) {
945  const TRGCDCWire* wire = ts.wires()[iWire];
946  const TRGCDCWireHit* wireHit = ts.wires()[iWire]->hit();
947  // If wire is hit
948  if (wireHit) {
949  // Only check first change. This could become a bug.
950  wireTime[iWire] = wire->signal().stateChanges()[0];
951  //cout<<ts.wires()[iWire]->name()<<" Clock: "<< ts.wires()[iWire]->signal().clock().frequency()<<" Drift lenght: "<<wireHit->drift()<<" Drift time: "<<ts.wires()[iWire]->signal().stateChanges()[0]<<endl;
952  } else
953  wireTime[iWire] = 9999;
954  //cout<<" "<<wire->name();
955  } // End loop over all wires
956  //cout<<endl;
958  //for(unsigned iWire = 0; iWire < wireTime.size(); iWire++) {
959  // cout<<"Wire: "<<iWire<<" Time: "<<wireTime[iWire]<<endl;
960  //}
961  // Get additional wire information for 6th layer
962  //cout<<" JB: "<<ts.wires().back()->layerId()<<" "<<ts.wires().back()->localId()<<endl;
963  int lastLayer = ts.wires().back()->layerId();
964  int lastWire = ts.wires().back()->localId();
965  int nWiresLayer = _cdc.layer(lastLayer + 1)->nCells();
966  if (nWires == 15) {
967  for (unsigned iWire = 0; iWire < 6; iWire++) {
968  int wireIndex = lastWire - 4 + iWire;
969  if (wireIndex < 0) wireIndex += nWiresLayer;
970  if (wireIndex >= nWiresLayer) wireIndex -= nWiresLayer;
971  //cout<<"Call: "<<(*_cdc.layer(lastLayer+1))[wireIndex]->localId()<<endl;
972  const TRGCDCCell* wire = (*_cdc.layer(lastLayer + 1))[wireIndex];
973  const TRGCDCCellHit* wireHit = wire->hit();
974  // If wire is hit
975  if (wireHit) {
976  // Only check first change. This could become a bug.
977  wireTime.push_back(wire->signal().stateChanges()[0]);
978  //cout<<ts.wires()[iWire]->name()<<" Clock: "<< ts.wires()[iWire]->signal().clock().frequency()<<" Drift lenght: "<<wireHit->drift()<<" Drift time: "<<ts.wires()[iWire]->signal().stateChanges()[0]<<endl;
979  } else
980  wireTime.push_back(9999);
981  } // Loop over all extra wires
982  } else {
983  for (unsigned iWire = 0; iWire < 5; iWire++) {
984  int wireIndex = lastWire - 3 + iWire;
985  if (wireIndex < 0) wireIndex += nWiresLayer;
986  if (wireIndex >= nWiresLayer) wireIndex -= nWiresLayer;
987  //cout<<"Call: "<<(*_cdc.layer(lastLayer+1))[wireIndex]->localId()<<endl;
988  const TRGCDCCell* wire = (*_cdc.layer(lastLayer + 1))[wireIndex];
989  const TRGCDCCellHit* wireHit = wire->hit();
990  // If wire is hit
991  if (wireHit) {
992  // Only check first change. This could become a bug.
993  wireTime.push_back(wire->signal().stateChanges()[0]);
994  //cout<<ts.wires()[iWire]->name()<<" Clock: "<< ts.wires()[iWire]->signal().clock().frequency()<<" Drift lenght: "<<wireHit->drift()<<" Drift time: "<<ts.wires()[iWire]->signal().stateChanges()[0]<<endl;
995  } else
996  wireTime.push_back(9999);
997  } // Loop over all extra wires
998  }
999  //ts.wires()[14]->layerId(), localId()
1000  //_cdc._layers[0][localId]->signal().stateChanges()[0]
1001 
1002 
1004  //float fastestTime = 9999;
1005  //for(unsigned iWire=0; iWire<wireTime.size();iWire++) {
1006  // if (fastestTime > wireTime[iWire]) fastestTime = wireTime[iWire];
1007  //}
1009  //for(unsigned iWire=0; iWire<wireTime.size();iWire++) {
1010  // if(wireTime[iWire] != 9999) wireTime[iWire] -= fastestTime;
1011  //}
1012 
1014  //for(unsigned iWire = 0; iWire < wireTime.size(); iWire++) {
1015  // cout<<"Wire: "<<iWire<<" Time: "<<wireTime[iWire]<<endl;
1016  //}
1017  //cout<<ts.name()<<" is found and priority wire is hit"<<endl;
1018  // Calculate mc result
1019  float mcLRDriftTime = priority->signal().stateChanges()[0];
1020  if (priority->hit()->mcLR()) mcLRDriftTime *= -1;
1021  //cout<<ts.name()<<" LRDriftTime: "<<mcLRDriftTime<<endl;
1022 
1023  // Save timing information in Root
1024  TVectorD t_nnPatternInformation;
1025  if (ts.superLayerId() == 0) {
1026  //t_nnPatternInformation.ResizeTo(17);
1027  t_nnPatternInformation.ResizeTo(23);
1028  t_nnPatternInformation[0] = ts.superLayerId();
1029  t_nnPatternInformation[1] = mcLRDriftTime;
1030  //for(unsigned iWire=0; iWire<15; iWire++){
1031  for (unsigned iWire = 0; iWire < 21; iWire++)
1032  t_nnPatternInformation[iWire + 2] = wireTime[iWire];
1033  new(nnPatternInformation[indexSaving++]) TVectorD(t_nnPatternInformation);
1034  } else {
1035  //t_nnPatternInformation.ResizeTo(13);
1036  t_nnPatternInformation.ResizeTo(17);
1037  t_nnPatternInformation[0] = ts.superLayerId();
1038  t_nnPatternInformation[1] = mcLRDriftTime;
1039  //for(unsigned iWire=0; iWire<11; iWire++){
1040  for (unsigned iWire = 0; iWire < 15; iWire++)
1041  t_nnPatternInformation[iWire + 2] = wireTime[iWire];
1042  new(nnPatternInformation[indexSaving++]) TVectorD(t_nnPatternInformation);
1043  }
1044 
1045  } // End of if priority cell is hit
1046  } // End of if TS is hit
1047  } // End loop of all TSs
1048 
1049  if (m_makeRootFile) m_treeNNTSF->Fill();
1050 
1051  } // End of save function
1052 
1053  void
1055  {
1056  std::vector<const TRGCDCMerger*>::push_back(a);
1057  }
1058 
1059 
1060  void
1062  {
1063 
1064  const string sn = "TSF::simulateOuter : " + name();
1066 
1067  //...Loop over mergers to create a super layer hit map...
1068  for (unsigned m = 0; m < nInput(); m++) {
1069  TRGSignalBundle* b = input(m)->signal();
1070 
1071  for (unsigned i = 0; i < 16; i++) {
1072  _secMap.push_back(& ((* b)[0][0][208 + i]));
1073  for (unsigned j = 0; j < 5; j++)
1074  _hitMap[j].push_back(& ((* b)[0][0][j * 16 + i]));
1075  for (unsigned j = 0; j < 4; j++)
1076  _priMap.push_back(& ((* b)[0][0][80 + i * 4 + j]));
1077  for (unsigned j = 0; j < 4; j++)
1078  _fasMap.push_back(& ((* b)[0][0][144 + i * 4 + j]));
1079  }
1080 
1081  for (unsigned i = 0; i < 4; i++)
1082  _edg0Map.push_back(& ((* b)[0][0][224 + i]));
1083  for (unsigned i = 0; i < 4; i++)
1084  _edg1Map.push_back(& ((* b)[0][0][224 + 4 + i]));
1085  for (unsigned i = 0; i < 4; i++)
1086  _edg2Map.push_back(& ((* b)[0][0][224 + 8 + i]));
1087  }
1088 
1089  //...Storage preparation...
1090  const unsigned nTSF = nInput() * 16;
1091  vector<TRGSignalVector*> trker[4];
1092  vector<int> tsfStateChanges;
1093 
1094  //...Form a TSF...
1095  for (unsigned t = 0; t < nTSF; t++) {
1096 
1097  const string n = name() + "-" + TRGUtilities::itostring(t);
1098  TRGSignalVector* s = new TRGSignalVector(n, clockData());
1099  _tsfIn.push_back(s);
1100 
1101  s->push_back(* _secMap[t]);
1102 
1103  if (t == 0) {
1104  s->push_back(* (_hitMap[0][nTSF - 1]));
1105  s->push_back(* (_hitMap[0][0]));
1106  s->push_back(* (_hitMap[0][1]));
1107  s->push_back(* (_hitMap[1][nTSF - 1]));
1108  s->push_back(* (_hitMap[1][0]));
1109  s->push_back(* (_hitMap[2][0]));
1110  s->push_back(* (_hitMap[3][nTSF - 1]));
1111  s->push_back(* (_hitMap[3][0]));
1112  s->push_back(* (_hitMap[4][nTSF - 1]));
1113  s->push_back(* (_hitMap[4][0]));
1114  s->push_back(* (_hitMap[4][1]));
1115  } else if (t == (nTSF - 1)) {
1116  s->push_back(* (_hitMap[0][nTSF - 2]));
1117  s->push_back(* (_hitMap[0][nTSF - 1]));
1118  s->push_back(* (_hitMap[0][0]));
1119  s->push_back(* (_hitMap[1][nTSF - 2]));
1120  s->push_back(* (_hitMap[1][nTSF - 1]));
1121  s->push_back(* (_hitMap[2][nTSF - 1]));
1122  s->push_back(* (_hitMap[3][nTSF - 2]));
1123  s->push_back(* (_hitMap[3][nTSF - 1]));
1124 
1125  s->push_back(* (_hitMap[4][nTSF - 2]));
1126  s->push_back(* (_hitMap[4][nTSF - 1]));
1127  s->push_back(* (_hitMap[4][0]));
1128  } else {
1129  s->push_back(* (_hitMap[0][t - 1]));
1130  s->push_back(* (_hitMap[0][t]));
1131  s->push_back(* (_hitMap[0][t + 1]));
1132  s->push_back(* (_hitMap[1][t - 1]));
1133  s->push_back(* (_hitMap[1][t]));
1134  s->push_back(* (_hitMap[2][t]));
1135  s->push_back(* (_hitMap[3][t - 1]));
1136  s->push_back(* (_hitMap[3][t]));
1137  s->push_back(* (_hitMap[4][t - 1]));
1138  s->push_back(* (_hitMap[4][t]));
1139  s->push_back(* (_hitMap[4][t + 1]));
1140  }
1141 
1142  //...Priority timing...
1143  s->push_back(* _priMap[t * 4 + 0]);
1144  s->push_back(* _priMap[t * 4 + 1]);
1145  s->push_back(* _priMap[t * 4 + 2]);
1146  s->push_back(* _priMap[t * 4 + 3]);
1147 
1148  //...Priority timing...
1149  priorityTiming(t, nTSF, * s, (* s)[6], (* s)[7], (* s)[8]);
1150 
1151  //...Fastest timing...
1152  fastestTimingOuter(t, nTSF, * s);
1153 
1154  //...Clock counter is omitted...
1155 
1156  //...Simulate TSF...
1157  vector<TRGSignalVector*> result = simulateOuter(s, t);
1158  _toBeDeleted.push_back(result[1]); // Event timing omitted now
1159 
1160  TRGSignalVector* forTracker0 = result[0];
1161  TRGSignalVector* forTracker1 = new TRGSignalVector(* forTracker0);
1162 
1163  _tsfOut.push_back(forTracker0);
1164  _tsfOut.push_back(forTracker1);
1165 
1166 
1167  //...State change list...
1168  vector<int> sc = forTracker0->stateChanges();
1169  for (unsigned i = 0; i < sc.size(); i++) {
1170  bool skip = false;
1171  for (unsigned j = 0; j < tsfStateChanges.size(); j++) {
1172  if (tsfStateChanges[j] == sc[i]) {
1173  skip = true;
1174  break;
1175  }
1176  }
1177  if (! skip) tsfStateChanges.push_back(sc[i]);
1178  }
1179 
1180  //...Store it for each tracker division...
1181  const unsigned pos = t / (nTSF / 4);
1182  if (pos == 0) {
1183  addID(* forTracker0, t + (nTSF / 4));
1184  addID(* forTracker1, t);
1185  trker[3].push_back(forTracker0);
1186  trker[0].push_back(forTracker1);
1187  } else if (pos == 1) {
1188  addID(* forTracker0, t);
1189  addID(* forTracker1, t - 1 * (nTSF / 4));
1190  trker[0].push_back(forTracker0);
1191  trker[1].push_back(forTracker1);
1192  } else if (pos == 2) {
1193  addID(* forTracker0, t - 1 * (nTSF / 4));
1194  addID(* forTracker1, t - 2 * (nTSF / 4));
1195  trker[1].push_back(forTracker0);
1196  trker[2].push_back(forTracker1);
1197  } else {
1198  addID(* forTracker0, t - 2 * (nTSF / 4));
1199  addID(* forTracker1, t - 3 * (nTSF / 4));
1200  trker[2].push_back(forTracker0);
1201  trker[3].push_back(forTracker1);
1202  }
1203 
1204  if (TRGDebug::level())
1205  if (forTracker0->active())
1206  cout << TRGDebug::tab() << "hit found : TSF out="
1207  << t << endl;
1208  }
1209 
1210  //...Sort state changes...
1211  std::sort(tsfStateChanges.begin(), tsfStateChanges.end());
1212 
1213  //...Output for 2D...
1214  for (unsigned i = 0; i < 4; i++) {
1215  string n = name() + "-trker" + TRGUtilities::itostring(i);
1216  TRGSignalVector* tOut = packerOuterTracker(trker[i],
1217  tsfStateChanges,
1218  20);
1219  tOut->name(n);
1220  TRGSignalBundle* b = new TRGSignalBundle(n, clockData());
1221  b->push_back(tOut);
1222  output(i)->signal(b);
1223  _toBeDeleted.push_back(tOut);
1224 
1225  if (TRGCDC::getTRGCDC()->firmwareSimulationMode() & 0x4)
1226  b->dumpCOE("",
1227  TRGCDC::getTRGCDC()->firmwareSimulationStartDataClock(),
1228  TRGCDC::getTRGCDC()->firmwareSimulationStopDataClock());
1229 
1230  // b->dump();
1231  }
1232 
1234  }
1235 
1236  vector <TRGSignalVector*>
1237  TSFinder::simulateOuter(TRGSignalVector* in, unsigned tsid)
1238  {
1239 
1240  //variables for common
1241  const string na = "TSCandidate" + TRGUtilities::itostring(tsid) + " in " +
1242  name();
1243  TCSegment* tsi = _tsSL[tsid];
1244  vector <TRGSignalVector*> result;
1245 
1246  //variables for EvtTime & Low pT
1247  vector<bool> fTimeVect;
1248  // int tmpFTime = 0 ;
1249 
1250  //variables for Tracker & N.N
1251  vector <bool> tmpOutBool;
1252 
1253  //iwTRGSignalVector* resultT = new TRGSignalVector(na, in->clock(),22);
1254  TRGSignalVector* resultT = new TRGSignalVector(na, in->clock(), 13);
1255  TRGSignalVector* resultE = new TRGSignalVector(na, in->clock(), 10);
1256  TRGSignalVector* Hitmap = new TRGSignalVector(na + "HitMap", in->clock(), 0);
1257  TRGSignalVector pTime(na + "PriorityTime", in->clock(), 0);
1258  TRGSignalVector fTime(na + "FastestTime", in->clock(), 0);
1259  for (unsigned i = 0; i < 12; i++) {
1260  Hitmap->push_back((*in)[i]);
1261  (*Hitmap)[i].widen(16);
1262  }
1263  for (unsigned i = 0; i < 4; i++) {
1264  pTime.push_back((*in)[i + 12]);
1265  fTime.push_back((*in)[i + 16]);
1266  }
1267 
1268  //...Clock counter...
1269  const TRGSignalVector& cc = in->clock().clockCounter();
1270  for (unsigned i = 0; i < 5; i++) {
1271  pTime.push_back(cc[i]);
1272  fTime.push_back(cc[i]);
1273  }
1274 
1275  vector <int> changeTime = Hitmap->stateChanges();
1276 
1277  int* LUTValue = new int[changeTime.size()];
1278  if (changeTime.size()) {
1279  int hitPosition = 0;
1280  bool fTimeBool[10];
1281  int tmpPTime = 0 ;
1282  int tmpCTime = 0 ;
1283  int tmpOutInt;
1284  fTime.state(changeTime[0]).copy2bool(fTimeBool);
1285  fTimeBool[9] = true;
1286  fTimeVect.insert(fTimeVect.begin(), fTimeBool, fTimeBool + 10);
1287  //tmpFTime = mkint(fTime.state(changeTime[0]));
1288  bool eOUT = true;
1289  for (unsigned i = 0; i < changeTime.size(); i++) {
1290  LUTValue[i] = tsi->LUT()->getValue(mkint(Hitmap->state(changeTime[i])));
1291 
1293  if ((LUTValue[i]) && (eOUT)) {
1294  resultE->set(fTimeVect, changeTime[i]);
1295  eOUT = false;
1296  }
1297 
1298  bool priority1rise = (*Hitmap)[6].riseEdge(changeTime[i]);
1299  bool priority2rise = ((*Hitmap)[7].riseEdge(changeTime[i]) |
1300  (*Hitmap)[8].riseEdge(changeTime[i]));
1301 
1303  //ready for output
1304  if (priority1rise) {
1305  hitPosition = 3;
1306  tmpPTime = mkint(pTime.state(changeTime[i]));
1307  tmpCTime = changeTime[i];
1308  } else if (priority2rise) {
1309  if (!hitPosition) {
1310  tmpPTime = mkint(pTime.state(changeTime[i]));
1311  tmpCTime = changeTime[i];
1312  if ((*Hitmap)[0].state(changeTime[i])) hitPosition = 2;
1313  else hitPosition = 1;
1314  }
1315  }
1316 
1317  // output selection
1318  if ((hitPosition) && (LUTValue[i]) && ((changeTime[i] - tmpCTime) < 16)) {
1319  //iw tmpOutInt = tsid * pow(2, 13) + tmpPTime * pow(2, 4) +
1320  //iw LUTValue[i] * pow(2,2) + hitPosition;
1321  tmpOutInt = tmpPTime * pow(2, 4) +
1322  LUTValue[i] * pow(2, 2) + hitPosition;
1323  tmpOutBool = mkbool(tmpOutInt, 13); // ID removed : iw
1324  if (hitPosition == 3) {
1325  if (priority1rise) resultT->set(tmpOutBool, changeTime[i]);
1326  else {
1327  if ((LUTValue[i] == 1) | (LUTValue[i] == 2)) {
1328  if (!((LUTValue[i - 1] == 1) |
1329  (LUTValue[i - 1] == 2)))
1330  resultT->set(tmpOutBool, changeTime[i]);
1331  } else {
1332  if (!(LUTValue[i - 1])) resultT->set(tmpOutBool, changeTime[i]);
1333  }
1334  }
1335  } else {
1336  if (priority2rise) resultT->set(tmpOutBool, changeTime[i]);
1337  else {
1338  if ((LUTValue[i] == 1) | (LUTValue[i] == 2)) {
1339  if (!((LUTValue[i - 1] == 1) |
1340  (LUTValue[i - 1] == 2)))
1341  resultT->set(tmpOutBool, changeTime[i]);
1342  } else {
1343  if (!(LUTValue[i])) resultT->set(tmpOutBool, changeTime[i]);
1344  }
1345  }
1346  }
1347  }
1348 
1349  }
1350 
1351  }
1352  result.push_back(resultT);
1353  result.push_back(resultE);
1354 
1355  delete [] LUTValue;
1356  delete Hitmap;
1357 
1358  return result;
1359  }
1360 
1361  void
1363  const unsigned nTSF,
1364  TRGSignalVector& s,
1365  const TRGSignal& center,
1366  const TRGSignal& right,
1367  const TRGSignal& left) const
1368  {
1369 
1370  unsigned rem = t % 16;
1371 
1372  if (rem != 0) {
1373  s.push_back(* _priMap[t * 4 + 0]);
1374  s.push_back(* _priMap[t * 4 + 1]);
1375  s.push_back(* _priMap[t * 4 + 2]);
1376  s.push_back(* _priMap[t * 4 + 3]);
1377  return;
1378  }
1379 
1380  //...Prepare signal vector for timing cells...
1381  TRGSignalVector tc("timing cell hit", clockData());
1382  tc.push_back(center);
1383  tc.push_back(right);
1384  tc.push_back(left);
1385 
1386  //...No timing hit case...
1387  if (! tc.active()) {
1388  s.push_back(* _priMap[t * 4 + 0]);
1389  s.push_back(* _priMap[t * 4 + 1]);
1390  s.push_back(* _priMap[t * 4 + 2]);
1391  s.push_back(* _priMap[t * 4 + 3]);
1392  return;
1393  }
1394 
1395  const string sn = "TSF priority timing outer";
1397 
1398  //...Prepare signal vector for each timing cells...
1399  TRGSignalVector t0("t0", clockData()); // center
1400  t0.push_back(* _priMap[t * 4 + 0]);
1401  t0.push_back(* _priMap[t * 4 + 1]);
1402  t0.push_back(* _priMap[t * 4 + 2]);
1403  t0.push_back(* _priMap[t * 4 + 3]);
1404 
1405  TRGSignalVector t1("t1", clockData()); // left
1406  unsigned p = t / 16;
1407  if (t == 0)
1408  p = nTSF / 16 - 1;
1409  else p = p - 1;
1410  t1.push_back(* _edg0Map[p * 4 + 0]);
1411  t1.push_back(* _edg0Map[p * 4 + 1]);
1412  t1.push_back(* _edg0Map[p * 4 + 2]);
1413  t1.push_back(* _edg0Map[p * 4 + 3]);
1414 
1415  //...Loop over state changes...
1416  vector<TRGState*> outputTimingStates;
1417  vector<int> clkStates;
1418  vector<int> sc = tc.stateChanges();
1419  vector<bool> sb;
1420  for (unsigned i = 0; i < sc.size(); i++) {
1421  int clk = sc[i];
1422  TRGState stt = tc.state(clk);
1423 
1424  //...Priority cell hit case...
1425  bool sel = true; // true=t0, false=t1
1426  if (stt[0])
1427  sel = true;
1428  else if (stt[1] && (! stt[2]))
1429  sel = false;
1430  else if ((! stt[1]) && stt[2])
1431  sel = true;
1432  else { // (stt[1] && stt[2])
1433  if (unsigned(t0.state(clk)) < unsigned(t1.state(clk)))
1434  sel = true;
1435  else
1436  sel = false;
1437  }
1438 
1439  if (sel) {
1440  outputTimingStates.push_back(new TRGState(t0.state(clk)));
1441  sb.push_back(false);
1442  } else {
1443  outputTimingStates.push_back(new TRGState(t1.state(clk)));
1444  sb.push_back(true);
1445  }
1446  clkStates.push_back(clk);
1447  }
1448 
1449  //...Create signals...
1450  const unsigned n = outputTimingStates.size();
1451  TRGSignalVector st("pri.timing", clockData(), 4);
1452  for (unsigned i = 0; i < n; i++) {
1453  if (sb[i])
1454  s[0].unset(clkStates[i], clkStates[i] + 1);
1455  st.set(* outputTimingStates[i], clkStates[i]);
1456  delete outputTimingStates[i];
1457  }
1458 
1459  //...Store signals...
1460  s.push_back(st[0]);
1461  s.push_back(st[1]);
1462  s.push_back(st[2]);
1463  s.push_back(st[3]);
1464 
1465  if (TRGDebug::level()) {
1466  tc.dump("", TRGDebug::tab() + " ");
1467  t0.dump("", TRGDebug::tab() + " ");
1468  t1.dump("", TRGDebug::tab() + " ");
1469  st.dump("", TRGDebug::tab() + " ");
1470  s.dump("", TRGDebug::tab() + " ");
1471  }
1472 
1474  }
1475 
1476  void
1478  const unsigned nTSF,
1479  TRGSignalVector& s) const
1480  {
1481 
1482  const unsigned rem = t % 16;
1483 
1484  if ((rem != 0) && (rem != 15)) {
1485  s.push_back(* _fasMap[t * 4 + 0]);
1486  s.push_back(* _fasMap[t * 4 + 1]);
1487  s.push_back(* _fasMap[t * 4 + 2]);
1488  s.push_back(* _fasMap[t * 4 + 3]);
1489  return;
1490  }
1491 
1492  //...Check hit map if there is a hit...
1493  bool hit = false;
1494  for (unsigned i = 0; i < 11; i++) {
1495  if (s[i + 1].active()) {
1496  hit = true;
1497  break;
1498  }
1499  }
1500 
1501  //...No hit case...
1502  if (! hit) {
1503  s.push_back(* _fasMap[t * 4 + 0]);
1504  s.push_back(* _fasMap[t * 4 + 1]);
1505  s.push_back(* _fasMap[t * 4 + 2]);
1506  s.push_back(* _fasMap[t * 4 + 3]);
1507  return;
1508  }
1509 
1510  const string sn = "TSF fastest timing outer";
1512 
1513  //...Prepare timing signal vectors
1514  TRGSignalVector t0("t0", clockData()); // main
1515  t0.push_back(* _fasMap[t * 4 + 0]);
1516  t0.push_back(* _fasMap[t * 4 + 1]);
1517  t0.push_back(* _fasMap[t * 4 + 2]);
1518  t0.push_back(* _fasMap[t * 4 + 3]);
1519 
1520  TRGSignalVector t1("t1", clockData()); // edge
1521  TRGSignal ht0("t0 hit", clockData());
1522  TRGSignal ht1("t1 hit", clockData());
1523  if (rem == 0) {
1524  unsigned n = t / 16;
1525  if (n == 0)
1526  n = nTSF / 16 - 1;
1527  else
1528  --n;
1529 
1530  t1.push_back(* _edg2Map[n * 4 + 0]);
1531  t1.push_back(* _edg2Map[n * 4 + 1]);
1532  t1.push_back(* _edg2Map[n * 4 + 2]);
1533  t1.push_back(* _edg2Map[n * 4 + 3]);
1534 
1535  ht0 = s[2];
1536  ht0 |= s[3];
1537  ht0 |= s[5];
1538  ht0 |= s[6];
1539  ht0 |= s[8];
1540  ht0 |= s[10];
1541  ht0 |= s[11];
1542 
1543  ht1 = s[1];
1544  ht1 |= s[4];
1545  ht1 |= s[7];
1546  ht1 |= s[9];
1547  } else {
1548  unsigned n = t / 16 + 1;
1549  if (n >= nTSF / 16)
1550  n = 0;
1551 
1552  t1.push_back(* _edg1Map[n * 4 + 0]);
1553  t1.push_back(* _edg1Map[n * 4 + 1]);
1554  t1.push_back(* _edg1Map[n * 4 + 2]);
1555  t1.push_back(* _edg1Map[n * 4 + 3]);
1556 
1557  ht0 = s[1];
1558  ht0 |= s[2];
1559  ht0 |= s[4];
1560  ht0 |= s[5];
1561  ht0 |= s[6];
1562  ht0 |= s[7];
1563  ht0 |= s[8];
1564  ht0 |= s[9];
1565  ht0 |= s[10];
1566 
1567  ht1 = s[3];
1568  ht1 |= s[11];
1569  }
1570 
1571  //...State changes...
1572  vector<int> sc = t0.stateChanges();
1573  vector<int> tmp = t1.stateChanges();
1574  sc.insert(sc.end(), tmp.begin(), tmp.end());
1575  std::sort(sc.begin(), sc.end());
1576 
1577  //...Loop over state changes...
1578  TRGSignalVector tm("fastest", clockData(), 4);
1579  int last = clockData().max();
1580  for (unsigned i = 0; i < sc.size(); i++) {
1581  if (sc[i] == last)
1582  continue;
1583 
1584  int clk = sc[i];
1585 
1586  TRGState ts0 = t0.state(clk);
1587  TRGState ts1 = t1.state(clk);
1588  unsigned tm0 = unsigned(ts0);
1589  unsigned tm1 = unsigned(ts1);
1590  bool th0 = ht0.state(clk);
1591  bool th1 = ht1.state(clk);
1592 
1593  if ((! th0) && (! th1))
1594  continue;
1595  else if (th0 && th1) {
1596  if (tm1 < tm0)
1597  tm.set(ts1, clk);
1598  else
1599  tm.set(ts0, clk);
1600  } else if (th0)
1601  tm.set(ts0, clk);
1602  else if (th1)
1603  tm.set(ts1, clk);
1604 
1605  last = clk;
1606  }
1607 
1608  //...Store signals...
1609  s.push_back(tm[0]);
1610  s.push_back(tm[1]);
1611  s.push_back(tm[2]);
1612  s.push_back(tm[3]);
1613 
1614  if (TRGDebug::level()) {
1615  ht0.name("t0 hit:" + ht0.name());
1616  ht0.dump("", TRGDebug::tab() + " ");
1617  t0.dump("", TRGDebug::tab() + " ");
1618  ht1.name("t1 hit:" + ht1.name());
1619  ht1.dump("", TRGDebug::tab() + " ");
1620  t1.dump("", TRGDebug::tab() + " ");
1621  tm.dump("", TRGDebug::tab() + " ");
1622  s.dump("", TRGDebug::tab() + " ");
1623  }
1624 
1626  }
1627 
1628  void
1630  {
1631 
1632  const string sn = "TSF::simulateInner : " + name();
1634 
1635  //...Output for 2D : empty bundle temporary...
1636  for (unsigned i = 0; i < 4; i++) {
1637  string n = name() + "-trker" + TRGUtilities::itostring(i);
1638  TRGSignalVector* dummy = new TRGSignalVector(n, clockData(), 420);
1639  TRGSignalBundle* b = new TRGSignalBundle(n, clockData());
1640  b->push_back(dummy);
1641  output(i)->signal(b);
1642  _toBeDeleted.push_back(dummy);
1643 
1644  if (TRGCDC::getTRGCDC()->firmwareSimulationMode() & 0x4)
1645  b->dumpCOE("",
1646  TRGCDC::getTRGCDC()->firmwareSimulationStartDataClock(),
1647  TRGCDC::getTRGCDC()->firmwareSimulationStopDataClock());
1648  }
1649 
1651  return;
1652 
1653 
1654  //...Loop over mergers to create a super layer hit map...
1655  for (unsigned m = 0; m < nInput(); m++) {
1656  TRGSignalBundle* b = input(m)->signal();
1657 
1658  for (unsigned i = 0; i < 16; i++) {
1659  _secMap.push_back(& ((* b)[0][0][208 + i]));
1660  for (unsigned j = 0; j < 5; j++)
1661  _hitMap[j].push_back(& ((* b)[0][0][j * 16 + i]));
1662  for (unsigned j = 0; j < 4; j++)
1663  _priMap.push_back(& ((* b)[0][0][80 + i * 4 + j]));
1664  for (unsigned j = 0; j < 4; j++)
1665  _fasMap.push_back(& ((* b)[0][0][144 + i * 4 + j]));
1666  }
1667 
1668  for (unsigned i = 0; i < 4; i++)
1669  _edg0Map.push_back(& ((* b)[0][0][224 + i]));
1670  for (unsigned i = 0; i < 4; i++)
1671  _edg1Map.push_back(& ((* b)[0][0][224 + 4 + i]));
1672  for (unsigned i = 0; i < 4; i++)
1673  _edg2Map.push_back(& ((* b)[0][0][224 + 8 + i]));
1674  for (unsigned i = 0; i < 4; i++)
1675  _edg3Map.push_back(& ((* b)[0][0][224 + 12 + i]));
1676  for (unsigned i = 0; i < 4; i++)
1677  _edg4Map.push_back(& ((* b)[0][0][224 + 16 + i]));
1678  }
1679 
1680  //...Storage preparation...
1681  const unsigned nTSF = nInput() * 16;
1682  vector<TRGSignalVector*> trker[4];
1683  vector<int> tsfStateChanges;
1684 
1685  //...Form a TSF...
1686  for (unsigned t = 0; t < nTSF; t++) {
1687 
1688  const string n = name() + "-" + TRGUtilities::itostring(t);
1689  TRGSignalVector* s = new TRGSignalVector(n, clockData());
1690  _tsfIn.push_back(s);
1691 
1692  s->push_back(* _secMap[t]);
1693 
1694  if (t == 0) {
1695  s->push_back(* (_hitMap[0][0]));
1696  s->push_back(* (_hitMap[1][nTSF - 1]));
1697  s->push_back(* (_hitMap[1][0]));
1698  s->push_back(* (_hitMap[2][nTSF - 1]));
1699  s->push_back(* (_hitMap[2][0]));
1700  s->push_back(* (_hitMap[2][1]));
1701  s->push_back(* (_hitMap[3][nTSF - 2]));
1702  s->push_back(* (_hitMap[3][nTSF - 1]));
1703  s->push_back(* (_hitMap[3][0]));
1704  s->push_back(* (_hitMap[3][1]));
1705  s->push_back(* (_hitMap[4][nTSF - 2]));
1706  s->push_back(* (_hitMap[4][nTSF - 1]));
1707  s->push_back(* (_hitMap[4][0]));
1708  s->push_back(* (_hitMap[4][1]));
1709  s->push_back(* (_hitMap[4][2]));
1710  } else if (t == 1) {
1711  s->push_back(* (_hitMap[0][1]));
1712  s->push_back(* (_hitMap[1][0]));
1713  s->push_back(* (_hitMap[1][1]));
1714  s->push_back(* (_hitMap[2][0]));
1715  s->push_back(* (_hitMap[2][1]));
1716  s->push_back(* (_hitMap[2][2]));
1717  s->push_back(* (_hitMap[3][nTSF - 1]));
1718  s->push_back(* (_hitMap[3][0]));
1719  s->push_back(* (_hitMap[3][1]));
1720  s->push_back(* (_hitMap[3][2]));
1721  s->push_back(* (_hitMap[4][nTSF - 1]));
1722  s->push_back(* (_hitMap[4][0]));
1723  s->push_back(* (_hitMap[4][1]));
1724  s->push_back(* (_hitMap[4][2]));
1725  s->push_back(* (_hitMap[4][3]));
1726  } else if (t == (nTSF - 2)) {
1727  s->push_back(* (_hitMap[0][t]));
1728  s->push_back(* (_hitMap[1][t - 11]));
1729  s->push_back(* (_hitMap[1][t]));
1730  s->push_back(* (_hitMap[2][t - 1]));
1731  s->push_back(* (_hitMap[2][t]));
1732  s->push_back(* (_hitMap[2][0]));
1733  s->push_back(* (_hitMap[3][t - 2]));
1734  s->push_back(* (_hitMap[3][t - 1]));
1735  s->push_back(* (_hitMap[3][t]));
1736  s->push_back(* (_hitMap[3][0]));
1737  s->push_back(* (_hitMap[4][t - 2]));
1738  s->push_back(* (_hitMap[4][t - 1]));
1739  s->push_back(* (_hitMap[4][t]));
1740  s->push_back(* (_hitMap[4][t + 1]));
1741  s->push_back(* (_hitMap[4][0]));
1742  } else if (t == (nTSF - 1)) {
1743  s->push_back(* (_hitMap[0][t]));
1744  s->push_back(* (_hitMap[1][t - 11]));
1745  s->push_back(* (_hitMap[1][t]));
1746  s->push_back(* (_hitMap[2][t - 1]));
1747  s->push_back(* (_hitMap[2][t]));
1748  s->push_back(* (_hitMap[2][0]));
1749  s->push_back(* (_hitMap[3][t - 2]));
1750  s->push_back(* (_hitMap[3][t - 1]));
1751  s->push_back(* (_hitMap[3][t]));
1752  s->push_back(* (_hitMap[3][0]));
1753  s->push_back(* (_hitMap[4][t - 2]));
1754  s->push_back(* (_hitMap[4][t - 1]));
1755  s->push_back(* (_hitMap[4][t]));
1756  s->push_back(* (_hitMap[4][0]));
1757  s->push_back(* (_hitMap[4][1]));
1758  } else {
1759  s->push_back(* (_hitMap[0][t]));
1760  s->push_back(* (_hitMap[1][t - 11]));
1761  s->push_back(* (_hitMap[1][t]));
1762  s->push_back(* (_hitMap[2][t - 1]));
1763  s->push_back(* (_hitMap[2][t]));
1764  s->push_back(* (_hitMap[2][0]));
1765  s->push_back(* (_hitMap[3][t - 2]));
1766  s->push_back(* (_hitMap[3][t - 1]));
1767  s->push_back(* (_hitMap[3][t]));
1768  s->push_back(* (_hitMap[3][0]));
1769  s->push_back(* (_hitMap[4][t - 2]));
1770  s->push_back(* (_hitMap[4][t - 1]));
1771  s->push_back(* (_hitMap[4][t]));
1772  s->push_back(* (_hitMap[4][t + 1]));
1773  s->push_back(* (_hitMap[4][t + 2]));
1774  }
1775 
1776  //...Priority timing...
1777  s->push_back(* _priMap[t * 4 + 0]);
1778  s->push_back(* _priMap[t * 4 + 1]);
1779  s->push_back(* _priMap[t * 4 + 2]);
1780  s->push_back(* _priMap[t * 4 + 3]);
1781 
1782  //...Priority timing...
1783  priorityTiming(t, nTSF, * s, (* s)[1], (* s)[2], (* s)[3]);
1784 
1785  //...Fastest timing...
1786  fastestTimingInner(t, nTSF, * s);
1787 
1788  //...Clock counter is omitted...
1789 
1790  //...Simulate TSF...
1791  vector<TRGSignalVector*> result = simulateInner(* s, t);
1792 
1793  TRGSignalVector* forTracker = result[0];
1794  _tsfOut.push_back(forTracker);
1795  _toBeDeleted.push_back(result[1]);
1796 
1797  //...State change list...
1798  vector<int> sc = forTracker->stateChanges();
1799  for (unsigned i = 0; i < sc.size(); i++) {
1800  bool skip = false;
1801  for (unsigned j = 0; j < tsfStateChanges.size(); j++) {
1802  if (tsfStateChanges[j] == sc[i]) {
1803  skip = true;
1804  break;
1805  }
1806  }
1807  if (! skip) tsfStateChanges.push_back(sc[i]);
1808  }
1809 
1810  //...Store it for each tracker division...
1811  const unsigned pos = t / (nTSF / 4);
1812  if (pos == 0) {
1813  trker[0].push_back(forTracker);
1814  trker[1].push_back(forTracker);
1815  } else if (pos == 1) {
1816  trker[1].push_back(forTracker);
1817  trker[2].push_back(forTracker);
1818  } else if (pos == 2) {
1819  trker[2].push_back(forTracker);
1820  trker[3].push_back(forTracker);
1821  } else {
1822  trker[3].push_back(forTracker);
1823  trker[0].push_back(forTracker);
1824  }
1825 
1826  //...Test...
1827  // if (TRGDebug::level() && t < 16) {
1828  // bool ok = ((* result[0]) == (* dbgOut[t])); // track part only
1829 
1830  // if (ok) {
1831  // cout << TRGDebug::tab() << name() << "...Comparison OK"
1832  // << endl;
1833  // }
1834  // else {
1835  // cout << TRGDebug::tab() << name()
1836  // << "...Comparison is not OK" << endl;
1837  // dbgOut[t]->dump("", "kt :");
1838  // result[0]->dump("", "2d :");
1839  // dbgIn[t]->dump("", "kt i:");
1840  // s->dump("", "2d i:");
1841  // }
1842  // }
1843  }
1844 
1845  //...Sort state changes...
1846  std::sort(tsfStateChanges.begin(), tsfStateChanges.end());
1847 
1848  //...Output for 2D...
1849  for (unsigned i = 0; i < 4; i++) {
1850  TRGSignalVector* tOut = packerOuterTracker(trker[i],
1851  tsfStateChanges,
1852  20);
1853  string n = name() + "trker" + TRGUtilities::itostring(i);
1854  TRGSignalBundle* b = new TRGSignalBundle(n, clockData());
1855  b->push_back(tOut);
1856  output(i)->signal(b);
1857  }
1858 
1860  }
1861 
1862  void
1864  const unsigned nTSF,
1865  TRGSignalVector& s) const
1866  {
1867 
1868  const unsigned rem = t % 16;
1869 
1870  if ((rem > 1) && (rem < 14)) {
1871  s.push_back(* _fasMap[t * 4 + 0]);
1872  s.push_back(* _fasMap[t * 4 + 1]);
1873  s.push_back(* _fasMap[t * 4 + 2]);
1874  s.push_back(* _fasMap[t * 4 + 3]);
1875  return;
1876  }
1877 
1878  //...Check hit map if there is a hit...
1879  bool hit = false;
1880  for (unsigned i = 0; i < 11; i++) {
1881  if (s[i + 1].active()) {
1882  hit = true;
1883  break;
1884  }
1885  }
1886 
1887  //...No hit case...
1888  if (! hit) {
1889  s.push_back(* _fasMap[t * 4 + 0]);
1890  s.push_back(* _fasMap[t * 4 + 1]);
1891  s.push_back(* _fasMap[t * 4 + 2]);
1892  s.push_back(* _fasMap[t * 4 + 3]);
1893  return;
1894  }
1895 
1896  const string sn = "TSF fastest timing inner";
1898 
1899  //...Prepare timing signal vectors
1900  TRGSignalVector t0("t0", clockData()); // main
1901  t0.push_back(* _fasMap[t * 4 + 0]);
1902  t0.push_back(* _fasMap[t * 4 + 1]);
1903  t0.push_back(* _fasMap[t * 4 + 2]);
1904  t0.push_back(* _fasMap[t * 4 + 3]);
1905 
1906  TRGSignalVector t1("t1", clockData()); // edge
1907  TRGSignal ht0("t0 hit", clockData());
1908  TRGSignal ht1("t1 hit", clockData());
1909  if (rem == 0) {
1910  unsigned n = t / 16;
1911  if (n == 0)
1912  n = nTSF / 16 - 1;
1913  else
1914  --n;
1915 
1916  t1.push_back(* _edg3Map[n * 4 + 0]);
1917  t1.push_back(* _edg3Map[n * 4 + 1]);
1918  t1.push_back(* _edg3Map[n * 4 + 2]);
1919  t1.push_back(* _edg3Map[n * 4 + 3]);
1920 
1921  ht0 = s[0 + 1];
1922  ht0 |= s[2 + 1];
1923  ht0 |= s[4 + 1];
1924  ht0 |= s[5 + 1];
1925  ht0 |= s[8 + 1];
1926  ht0 |= s[9 + 1];
1927  ht0 |= s[12 + 1];
1928  ht0 |= s[13 + 1];
1929 
1930  ht1 = s[1 + 1];
1931  ht1 |= s[3 + 1];
1932  ht1 |= s[6 + 1];
1933  ht1 |= s[7 + 1];
1934  ht1 |= s[10 + 1];
1935  ht1 |= s[11 + 1];
1936  } else if (rem == 1) {
1937  unsigned n = t / 16;
1938  if (n == 0)
1939  n = nTSF / 16 - 1;
1940  else
1941  --n;
1942 
1943  t1.push_back(* _edg4Map[n * 4 + 0]);
1944  t1.push_back(* _edg4Map[n * 4 + 1]);
1945  t1.push_back(* _edg4Map[n * 4 + 2]);
1946  t1.push_back(* _edg4Map[n * 4 + 3]);
1947 
1948  // ht0 = s[0 + 1];
1949  ht0 = s[1 + 1];
1950  ht0 |= s[2 + 1];
1951  ht0 |= s[3 + 1];
1952  ht0 |= s[4 + 1];
1953  ht0 |= s[5 + 1];
1954  ht0 |= s[7 + 1];
1955  ht0 |= s[8 + 1];
1956  ht0 |= s[9 + 1];
1957  ht0 |= s[10 + 1];
1958  ht0 |= s[12 + 1];
1959  ht0 |= s[13 + 1];
1960 
1961  ht1 |= s[6 + 1];
1962  ht1 |= s[11 + 1];
1963  } else if (rem == 14) {
1964  unsigned n = t / 16 + 1;
1965  if (n >= nTSF / 16)
1966  n = 0;
1967 
1968  t1.push_back(* _edg1Map[n * 4 + 0]);
1969  t1.push_back(* _edg1Map[n * 4 + 1]);
1970  t1.push_back(* _edg1Map[n * 4 + 2]);
1971  t1.push_back(* _edg1Map[n * 4 + 3]);
1972 
1973  ht0 = s[0 + 1];
1974  ht0 |= s[1 + 1];
1975  ht0 |= s[2 + 1];
1976  ht0 |= s[3 + 1];
1977  ht0 |= s[4 + 1];
1978  ht0 |= s[5 + 1];
1979  ht0 |= s[6 + 1];
1980  ht0 |= s[7 + 1];
1981  ht0 |= s[8 + 1];
1982  ht0 |= s[9 + 1];
1983  ht0 |= s[10 + 1];
1984  ht0 |= s[11 + 1];
1985  ht0 |= s[12 + 1];
1986 
1987  ht1 = s[13 + 1];
1988  } else {
1989  unsigned n = t / 16 + 1;
1990  if (n >= nTSF / 16)
1991  n = 0;
1992 
1993  t1.push_back(* _edg2Map[n * 4 + 0]);
1994  t1.push_back(* _edg2Map[n * 4 + 1]);
1995  t1.push_back(* _edg2Map[n * 4 + 2]);
1996  t1.push_back(* _edg2Map[n * 4 + 3]);
1997 
1998  ht0 = s[0 + 1];
1999  ht0 |= s[1 + 1];
2000  ht0 |= s[2 + 1];
2001  ht0 |= s[3 + 1];
2002  ht0 |= s[4 + 1];
2003  ht0 |= s[6 + 1];
2004  ht0 |= s[7 + 1];
2005  ht0 |= s[8 + 1];
2006  ht0 |= s[10 + 1];
2007  ht0 |= s[11 + 1];
2008 
2009  ht1 = s[5 + 1];
2010  ht1 |= s[9 + 1];
2011  ht1 |= s[12 + 1];
2012  ht1 |= s[13 + 1];
2013  }
2014 
2015  //...State changes...
2016  vector<int> sc = t0.stateChanges();
2017  vector<int> tmp = t1.stateChanges();
2018  sc.insert(sc.end(), tmp.begin(), tmp.end());
2019  std::sort(sc.begin(), sc.end());
2020 
2021  //...Loop over state changes...
2022  TRGSignalVector tm("fastest", clockData(), 4);
2023  int last = clockData().max();
2024  for (unsigned i = 0; i < sc.size(); i++) {
2025  if (sc[i] == last)
2026  continue;
2027 
2028  int clk = sc[i];
2029 
2030  TRGState ts0 = t0.state(clk);
2031  TRGState ts1 = t1.state(clk);
2032  unsigned tm0 = unsigned(ts0);
2033  unsigned tm1 = unsigned(ts1);
2034  bool th0 = ht0.state(clk);
2035  bool th1 = ht1.state(clk);
2036 
2037  if ((! th0) && (! th1))
2038  continue;
2039  else if (th0 && th1) {
2040  if (tm1 < tm0)
2041  tm.set(ts1, clk);
2042  else
2043  tm.set(ts0, clk);
2044  } else if (th0)
2045  tm.set(ts0, clk);
2046  else if (th1)
2047  tm.set(ts1, clk);
2048 
2049  last = clk;
2050  }
2051 
2052  //...Store signals...
2053  s.push_back(tm[0]);
2054  s.push_back(tm[1]);
2055  s.push_back(tm[2]);
2056  s.push_back(tm[3]);
2057 
2058  if (TRGDebug::level()) {
2059  ht0.name("t0 hit:" + ht0.name());
2060  ht0.dump("", TRGDebug::tab() + " ");
2061  t0.dump("", TRGDebug::tab() + " ");
2062  ht1.name("t1 hit:" + ht1.name());
2063  ht1.dump("", TRGDebug::tab() + " ");
2064  t1.dump("", TRGDebug::tab() + " ");
2065  tm.dump("", TRGDebug::tab() + " ");
2066  s.dump("", TRGDebug::tab() + " ");
2067  }
2068 
2070  }
2071 
2072  vector<TRGSignalVector*>
2074  {
2075 
2076  // This is just a simple coincidence logic. Should be replaced by
2077  // real logic.
2078 
2079  const int width = 10;
2080 
2081  //...Layer hit...
2082  TRGSignal l0 = s[0 + 1].widen(width);
2083  TRGSignal l1 = s[1 + 1].widen(width) | s[2 + 1].widen(width);
2084  TRGSignal l2 = s[3 + 1].widen(width) | s[4 + 1].widen(width) |
2085  s[5 + 1].widen(width);
2086  TRGSignal l3 = s[6 + 1].widen(width) | s[7 + 1].widen(width) |
2087  s[8 + 1].widen(width) | s[9 + 1].widen(width);
2088  TRGSignal l4 = s[10 + 1].widen(width) | s[11 + 1].widen(width) |
2089  s[12 + 1].widen(width) | s[13 + 1].widen(width);
2090 
2091  //...Layer coincidence...
2092  TRGSignal a0 = l1 & l2 & l3 & l4;
2093  TRGSignal a1 = l0 & l2 & l3 & l4;
2094  TRGSignal a2 = l0 & l1 & l3 & l4;
2095  TRGSignal a3 = l0 & l1 & l2 & l4;
2096  TRGSignal a4 = l0 & l1 & l2 & l3;
2097 
2098  //...Final hit... (detail hit pattern changes are ignored here)
2099  TRGSignal a = a0 | a1 | a2 | a3 | a4;
2100 
2101  //...Check timing cells...
2102  vector<int> sc = s.stateChanges();
2103  for (unsigned i = 0; i < sc.size(); i++) {
2104  int clk = sc[i];
2105  TRGState st = s.state(clk).subset(1, 3);
2106 
2107  if (st[0]) {
2108  } else {
2109  if (st[1] && st[2]) {
2110  } else if (st[1]) {
2111  } else if (st[2]) {
2112  }
2113  }
2114  }
2115 
2116  TRGSignalVector* r0 = new TRGSignalVector("tmp0", clockData(), 21);
2117  TRGSignalVector* r1 = new TRGSignalVector("tmp0", clockData(), 21);
2118  vector<TRGSignalVector*> v;
2119  v.push_back(r0);
2120  v.push_back(r1);
2121  return v;
2122  }
2123 
2124  void
2126  {
2127  const TRGState sid(8, id);
2128  TRGSignalVector idv("TSFid", s.clock(), 8);
2129 
2130  //...Encode ID only when s is active...
2131  vector<int> sc = s.stateChanges();
2132  for (unsigned i = 0; i < sc.size(); i++) {
2133  if (s.active(sc[i]))
2134  idv.set(sid, sc[i]);
2135  }
2136 
2137  //...Merge ID vectors...
2138  s += idv;
2139  }
2140 
2141  void
2143  {
2144 
2145  //...Delete old objects...
2146  for (unsigned i = 0; i < nOutput(); i++) {
2147  if (output(i))
2148  if (output(i)->signal())
2149  delete output(i)->signal();
2150  }
2151  for (unsigned i = 0; i < _tsfIn.size(); i++)
2152  delete _tsfIn[i];
2153  _tsfIn.clear();
2154  for (unsigned i = 0; i < _tsfOut.size(); i++)
2155  delete _tsfOut[i];
2156  _tsfOut.clear();
2157  for (unsigned i = 0; i < _toBeDeleted.size(); i++)
2158  delete _toBeDeleted[i];
2159  _toBeDeleted.clear();
2160 
2161  //...Clear old pointers...
2162  for (unsigned i = 0; i < 5; i++)
2163  _hitMap[i].clear();
2164  _priMap.clear();
2165  _fasMap.clear();
2166  _secMap.clear();
2167  _edg0Map.clear();
2168  _edg1Map.clear();
2169  _edg2Map.clear();
2170  _edg3Map.clear();
2171  _edg4Map.clear();
2172 
2173  if (_type == innerType)
2174  simulateInner();
2175  else
2176  simulateOuter();
2177  }
2178 
2179  void
2181  {
2182 
2183  const string sn = "TSF::simulate2 : " + name();
2185 
2186  // if (_type == innerType) {
2187  // cout << "??? tmp skip" << endl;
2188  // TRGDebug::leaveStage(sn);
2189  // return;
2190  // }
2191 
2192  //...Delete old objects...
2193  for (unsigned i = 0; i < nOutput(); i++) {
2194  if (output(i))
2195  if (output(i)->signal())
2196  delete output(i)->signal();
2197  }
2198  for (unsigned i = 0; i < _tsfIn.size(); i++)
2199  delete _tsfIn[i];
2200  _tsfIn.clear();
2201  for (unsigned i = 0; i < _tsfOut.size(); i++)
2202  delete _tsfOut[i];
2203  _tsfOut.clear();
2204  for (unsigned i = 0; i < _toBeDeleted.size(); i++)
2205  delete _toBeDeleted[i];
2206  _toBeDeleted.clear();
2207 
2208  //...Clear old pointers...
2209  for (unsigned i = 0; i < 5; i++)
2210  _hitMap[i].clear();
2211  _priMap.clear();
2212  _fasMap.clear();
2213  _secMap.clear();
2214  _edg0Map.clear();
2215  _edg1Map.clear();
2216  _edg2Map.clear();
2217  _edg3Map.clear();
2218  _edg4Map.clear();
2219 
2220  //...Storage preparation...
2221  const unsigned nTSF = nInput() * 16;
2222  vector<TRGSignalVector*> trker[4];
2223  vector<int> tsfStateChanges;
2224 
2225  //...Creates hit maps...
2226  if (_type == innerType)
2227  hitMapInner();
2228  else
2229  hitMapOuter();
2230 
2231  //...Form a TSF...
2232  for (unsigned t = 0; t < nTSF; t++) {
2233 
2234  const string n = name() + "-" + TRGUtilities::itostring(t);
2235  TRGSignalVector* s = new TRGSignalVector(n, clockData());
2236  _tsfIn.push_back(s);
2237 
2238  //...Make input signals...
2239  if (_type == innerType)
2240  inputInner(t, nTSF, s);
2241  else
2242  inputOuter(t, nTSF, s);
2243 
2244  //...Simulate TSF...
2245  vector<TRGSignalVector*> result = simulateTSF(s, t);
2246  vector<TRGSignalVector*> result2 = simulateTSF2(s, t);
2247  _toBeDeleted.push_back(result[1]); // Event timing omitted now
2248 
2249  if (TRGDebug::level()) {
2250  if (result.size() != result2.size()) {
2251  cout << "TSF::simulateTSF2 has different response(size)"
2252  << endl;
2253  } else {
2254  for (unsigned i = 0; i < result.size(); i++) {
2255  if ((* result[i]) != (* result2[i]))
2256  cout << "TSF::simulateTSF2 has different response"
2257  << "(contents)" << endl;
2258  }
2259  }
2260  }
2261 
2262  TRGSignalVector* forTracker0 = result[0];
2263  TRGSignalVector* forTracker1 = new TRGSignalVector(* forTracker0);
2264 
2265  _tsfOut.push_back(forTracker0);
2266  _tsfOut.push_back(forTracker1);
2267 
2268  //...State change list...
2269  vector<int> sc = forTracker0->stateChanges();
2270  for (unsigned i = 0; i < sc.size(); i++) {
2271  bool skip = false;
2272  for (unsigned j = 0; j < tsfStateChanges.size(); j++) {
2273  if (tsfStateChanges[j] == sc[i]) {
2274  skip = true;
2275  break;
2276  }
2277  }
2278  if (! skip) tsfStateChanges.push_back(sc[i]);
2279  }
2280 
2281  //...Store it for each tracker division...
2282  const unsigned pos = t / (nTSF / 4);
2283  if (pos == 0) {
2284  addID(* forTracker0, t - 3 * (nTSF / 4));
2285  addID(* forTracker1, t);
2286  trker[3].push_back(forTracker0);
2287  trker[0].push_back(forTracker1);
2288  } else if (pos == 1) {
2289  addID(* forTracker0, t);
2290  addID(* forTracker1, t - 1 * (nTSF / 4));
2291  trker[0].push_back(forTracker0);
2292  trker[1].push_back(forTracker1);
2293  } else if (pos == 2) {
2294  addID(* forTracker0, t - 1 * (nTSF / 4));
2295  addID(* forTracker1, t - 2 * (nTSF / 4));
2296  trker[1].push_back(forTracker0);
2297  trker[2].push_back(forTracker1);
2298  } else {
2299  addID(* forTracker0, t - 2 * (nTSF / 4));
2300  addID(* forTracker1, t - 3 * (nTSF / 4));
2301  trker[2].push_back(forTracker0);
2302  trker[3].push_back(forTracker1);
2303  }
2304 
2305  if (TRGDebug::level())
2306  if (forTracker0->active())
2307  cout << TRGDebug::tab() << name() << " : TSF out="
2308  << t << endl;
2309  }
2310 
2311  //...Sort state changes...
2312  std::sort(tsfStateChanges.begin(), tsfStateChanges.end());
2313 
2314  //...Output for 2D...
2315  for (unsigned i = 0; i < 4; i++) {
2316  string n = name() + "-trker" + TRGUtilities::itostring(i);
2317  TRGSignalVector* tOut = packerForTracker(trker[i],
2318  tsfStateChanges,
2319  20);
2320  tOut->name(n);
2321  TRGSignalBundle* b = new TRGSignalBundle(n, clockData());
2322  b->push_back(tOut);
2323  output(i)->signal(b);
2324  _toBeDeleted.push_back(tOut);
2325 
2326  if (TRGCDC::getTRGCDC()->firmwareSimulationMode() & 0x4)
2327  b->dumpCOE("",
2328  TRGCDC::getTRGCDC()->firmwareSimulationStartDataClock(),
2329  TRGCDC::getTRGCDC()->firmwareSimulationStopDataClock());
2330  // b->dump();
2331  }
2332 
2334  }
2335 
2336  void
2338  {
2339 
2340  // dump("detail","??? ");
2341 
2342  //...Loop over mergers to create a super layer hit map...
2343  for (unsigned m = 0; m < nInput(); m++) {
2344  TRGSignalBundle* b = input(m)->signal();
2345 
2346  // b->dump("", "??? ");
2347 
2348  for (unsigned i = 0; i < 16; i++) {
2349  _secMap.push_back(& ((* b)[0][0][208 + i]));
2350  for (unsigned j = 0; j < 5; j++) {
2351  _hitMap[j].push_back(& ((* b)[0][0][j * 16 + i]));
2352 
2353  // _hitMap[j][i]->dump("", "??? " + TRGUtilities::itostring(i) + "-" + TRGUtilities::itostring(j));
2354 
2355  }
2356  for (unsigned j = 0; j < 4; j++)
2357  _priMap.push_back(& ((* b)[0][0][80 + i * 4 + j]));
2358  for (unsigned j = 0; j < 4; j++)
2359  _fasMap.push_back(& ((* b)[0][0][144 + i * 4 + j]));
2360  }
2361 
2362  for (unsigned i = 0; i < 4; i++)
2363  _edg0Map.push_back(& ((* b)[0][0][224 + i]));
2364  for (unsigned i = 0; i < 4; i++)
2365  _edg1Map.push_back(& ((* b)[0][0][224 + 4 + i]));
2366  for (unsigned i = 0; i < 4; i++)
2367  _edg2Map.push_back(& ((* b)[0][0][224 + 8 + i]));
2368  for (unsigned i = 0; i < 4; i++)
2369  _edg3Map.push_back(& ((* b)[0][0][224 + 12 + i]));
2370  for (unsigned i = 0; i < 4; i++)
2371  _edg4Map.push_back(& ((* b)[0][0][224 + 16 + i]));
2372  }
2373  }
2374 
2375  void
2377  {
2378 
2379  //...Loop over mergers to create a super layer hit map...
2380  for (unsigned m = 0; m < nInput(); m++) {
2381  TRGSignalBundle* b = input(m)->signal();
2382 
2383  for (unsigned i = 0; i < 16; i++) {
2384  _secMap.push_back(& ((* b)[0][0][208 + i]));
2385  for (unsigned j = 0; j < 5; j++)
2386  _hitMap[j].push_back(& ((* b)[0][0][j * 16 + i]));
2387  for (unsigned j = 0; j < 4; j++)
2388  _priMap.push_back(& ((* b)[0][0][80 + i * 4 + j]));
2389  for (unsigned j = 0; j < 4; j++)
2390  _fasMap.push_back(& ((* b)[0][0][144 + i * 4 + j]));
2391  }
2392 
2393  for (unsigned i = 0; i < 4; i++)
2394  _edg0Map.push_back(& ((* b)[0][0][224 + i]));
2395  for (unsigned i = 0; i < 4; i++)
2396  _edg1Map.push_back(& ((* b)[0][0][224 + 4 + i]));
2397  for (unsigned i = 0; i < 4; i++)
2398  _edg2Map.push_back(& ((* b)[0][0][224 + 8 + i]));
2399  }
2400  }
2401 
2402  void
2404  const unsigned nTSF,
2405  TRGSignalVector* s)
2406  {
2407  s->push_back(* _secMap[t]);
2408 
2409  if (t == 0) {
2410  s->push_back(* (_hitMap[0][0]));
2411  s->push_back(* (_hitMap[1][nTSF - 1]));
2412  s->push_back(* (_hitMap[1][0]));
2413  s->push_back(* (_hitMap[2][nTSF - 1]));
2414  s->push_back(* (_hitMap[2][0]));
2415  s->push_back(* (_hitMap[2][1]));
2416  s->push_back(* (_hitMap[3][nTSF - 2]));
2417  s->push_back(* (_hitMap[3][nTSF - 1]));
2418  s->push_back(* (_hitMap[3][0]));
2419  s->push_back(* (_hitMap[3][1]));
2420  s->push_back(* (_hitMap[4][nTSF - 2]));
2421  s->push_back(* (_hitMap[4][nTSF - 1]));
2422  s->push_back(* (_hitMap[4][0]));
2423  s->push_back(* (_hitMap[4][1]));
2424  s->push_back(* (_hitMap[4][2]));
2425  } else if (t == 1) {
2426  s->push_back(* (_hitMap[0][1]));
2427  s->push_back(* (_hitMap[1][0]));
2428  s->push_back(* (_hitMap[1][1]));
2429  s->push_back(* (_hitMap[2][0]));
2430  s->push_back(* (_hitMap[2][1]));
2431  s->push_back(* (_hitMap[2][2]));
2432  s->push_back(* (_hitMap[3][nTSF - 1]));
2433  s->push_back(* (_hitMap[3][0]));
2434  s->push_back(* (_hitMap[3][1]));
2435  s->push_back(* (_hitMap[3][2]));
2436  s->push_back(* (_hitMap[4][nTSF - 1]));
2437  s->push_back(* (_hitMap[4][0]));
2438  s->push_back(* (_hitMap[4][1]));
2439  s->push_back(* (_hitMap[4][2]));
2440  s->push_back(* (_hitMap[4][3]));
2441  } else if (t == (nTSF - 2)) {
2442  s->push_back(* (_hitMap[0][t]));
2443  s->push_back(* (_hitMap[1][t - 11]));
2444  s->push_back(* (_hitMap[1][t]));
2445  s->push_back(* (_hitMap[2][t - 1]));
2446  s->push_back(* (_hitMap[2][t]));
2447  s->push_back(* (_hitMap[2][0]));
2448  s->push_back(* (_hitMap[3][t - 2]));
2449  s->push_back(* (_hitMap[3][t - 1]));
2450  s->push_back(* (_hitMap[3][t]));
2451  s->push_back(* (_hitMap[3][0]));
2452  s->push_back(* (_hitMap[4][t - 2]));
2453  s->push_back(* (_hitMap[4][t - 1]));
2454  s->push_back(* (_hitMap[4][t]));
2455  s->push_back(* (_hitMap[4][t + 1]));
2456  s->push_back(* (_hitMap[4][0]));
2457  } else if (t == (nTSF - 1)) {
2458  s->push_back(* (_hitMap[0][t]));
2459  s->push_back(* (_hitMap[1][t - 11]));
2460  s->push_back(* (_hitMap[1][t]));
2461  s->push_back(* (_hitMap[2][t - 1]));
2462  s->push_back(* (_hitMap[2][t]));
2463  s->push_back(* (_hitMap[2][0]));
2464  s->push_back(* (_hitMap[3][t - 2]));
2465  s->push_back(* (_hitMap[3][t - 1]));
2466  s->push_back(* (_hitMap[3][t]));
2467  s->push_back(* (_hitMap[3][0]));
2468  s->push_back(* (_hitMap[4][t - 2]));
2469  s->push_back(* (_hitMap[4][t - 1]));
2470  s->push_back(* (_hitMap[4][t]));
2471  s->push_back(* (_hitMap[4][0]));
2472  s->push_back(* (_hitMap[4][1]));
2473  } else {
2474  // _hitMap[1][t - 1]->dump("", "??? " + TRGUtilities::itostring(1) + "-" + TRGUtilities::itostring(t - 1));
2475 
2476  TRGSignal& ts = * _hitMap[1][t - 1];
2477 
2478  s->push_back(* (_hitMap[0][t]));
2479  // s->push_back(* (_hitMap[1][t - 11])); // Why this makes SegV?
2480  s->push_back(ts);
2481  s->push_back(* (_hitMap[1][t]));
2482  s->push_back(* (_hitMap[2][t - 1]));
2483  s->push_back(* (_hitMap[2][t]));
2484  s->push_back(* (_hitMap[2][0]));
2485  s->push_back(* (_hitMap[3][t - 2]));
2486  s->push_back(* (_hitMap[3][t - 1]));
2487  s->push_back(* (_hitMap[3][t]));
2488  s->push_back(* (_hitMap[3][0]));
2489  s->push_back(* (_hitMap[4][t - 2]));
2490  s->push_back(* (_hitMap[4][t - 1]));
2491  s->push_back(* (_hitMap[4][t]));
2492  s->push_back(* (_hitMap[4][t + 1]));
2493  s->push_back(* (_hitMap[4][t + 2]));
2494  }
2495 
2496  //...Priority timing...
2497 // s->push_back(* _priMap[t * 4 + 0]);
2498 // s->push_back(* _priMap[t * 4 + 1]);
2499 // s->push_back(* _priMap[t * 4 + 2]);
2500 // s->push_back(* _priMap[t * 4 + 3]);
2501 
2502  //...Priority timing...
2503  priorityTiming(t, nTSF, * s, (* s)[1], (* s)[2], (* s)[3]);
2504 
2505  //...Fastest timing...
2506  fastestTimingInner(t, nTSF, * s);
2507 
2508  //...Clock counter is omitted...
2509  }
2510 
2511  void
2513  const unsigned nTSF,
2514  TRGSignalVector* s)
2515  {
2516  s->push_back(* _secMap[t]);
2517 
2518  if (t == 0) {
2519  s->push_back(* (_hitMap[0][nTSF - 1]));
2520  s->push_back(* (_hitMap[0][0]));
2521  s->push_back(* (_hitMap[0][1]));
2522  s->push_back(* (_hitMap[1][nTSF - 1]));
2523  s->push_back(* (_hitMap[1][0]));
2524  s->push_back(* (_hitMap[2][0]));
2525  s->push_back(* (_hitMap[3][nTSF - 1]));
2526  s->push_back(* (_hitMap[3][0]));
2527  s->push_back(* (_hitMap[4][nTSF - 1]));
2528  s->push_back(* (_hitMap[4][0]));
2529  s->push_back(* (_hitMap[4][1]));
2530  } else if (t == (nTSF - 1)) {
2531  s->push_back(* (_hitMap[0][nTSF - 2]));
2532  s->push_back(* (_hitMap[0][nTSF - 1]));
2533  s->push_back(* (_hitMap[0][0]));
2534  s->push_back(* (_hitMap[1][nTSF - 2]));
2535  s->push_back(* (_hitMap[1][nTSF - 1]));
2536  s->push_back(* (_hitMap[2][nTSF - 1]));
2537  s->push_back(* (_hitMap[3][nTSF - 2]));
2538  s->push_back(* (_hitMap[3][nTSF - 1]));
2539 
2540  s->push_back(* (_hitMap[4][nTSF - 2]));
2541  s->push_back(* (_hitMap[4][nTSF - 1]));
2542  s->push_back(* (_hitMap[4][0]));
2543  } else {
2544  s->push_back(* (_hitMap[0][t - 1]));
2545  s->push_back(* (_hitMap[0][t]));
2546  s->push_back(* (_hitMap[0][t + 1]));
2547  s->push_back(* (_hitMap[1][t - 1]));
2548  s->push_back(* (_hitMap[1][t]));
2549  s->push_back(* (_hitMap[2][t]));
2550  s->push_back(* (_hitMap[3][t - 1]));
2551  s->push_back(* (_hitMap[3][t]));
2552  s->push_back(* (_hitMap[4][t - 1]));
2553  s->push_back(* (_hitMap[4][t]));
2554  s->push_back(* (_hitMap[4][t + 1]));
2555  }
2556 
2557  //...Priority timing...
2558 // s->push_back(* _priMap[t * 4 + 0]);
2559 // s->push_back(* _priMap[t * 4 + 1]);
2560 // s->push_back(* _priMap[t * 4 + 2]);
2561 // s->push_back(* _priMap[t * 4 + 3]);
2562 
2563  //...Priority timing...
2564  priorityTiming(t, nTSF, * s, (* s)[6], (* s)[7], (* s)[8]);
2565 
2566  //...Fastest timing...
2567  fastestTimingOuter(t, nTSF, * s);
2568 
2569  //...Clock counter is omitted...
2570  }
2571 
2573  TSFinder::packerForTracker(vector<TRGSignalVector*>& hitList,
2574  vector<int>& cList,
2575  const unsigned maxHit)
2576  {
2577 
2578  TRGSignalVector* result =
2579  new TRGSignalVector("", (* hitList[0]).clock() , 21 * maxHit);
2580 
2581  for (unsigned ci = 0; ci < cList.size(); ci++) {
2582  unsigned cntHit = 0;
2583  for (unsigned hi = 0; hi < hitList.size(); hi++) {
2584  TRGState s = (* hitList[hi]).state(cList[ci]);
2585  if (s.active()) {
2586  if (cntHit >= maxHit) continue;
2587  for (unsigned j = 0; j < 21; j++) {
2588  if ((* hitList[hi])[j].state(cList[ci])) {
2589  (* result)[21 * (maxHit - 1) - (cntHit * 21) + j]
2590  .set(cList[ci], cList[ci] + 1);
2591  }
2592  }
2593  if (TRGDebug::level()) {
2594  TRGState t = hitList[hi]->state(cList[ci]).subset(13, 8);
2595  cout << TRGDebug::tab() << " hit found : TSF out local ID="
2596  << unsigned(t) << "(" << t << ")" << endl;
2597  }
2598 
2599  ++cntHit;
2600  // result->dump("", "??? ");
2601  }
2602  }
2603  }
2604 
2605  return result;
2606  }
2607 
2608  vector <TRGSignalVector*>
2609  TSFinder::simulateTSFOld(TRGSignalVector* in, unsigned tsid)
2610  {
2611 
2612  //variables for common
2613  const string na = "TSF" + TRGUtilities::itostring(tsid) + " in " +
2614  name();
2615  TCSegment* tsi = _tsSL[tsid];
2616  vector <TRGSignalVector*> result;
2617 
2618  //variables for EvtTime & Low pT
2619  vector<bool> fTimeVect;
2620  // int tmpFTime = 0 ;
2621 
2622  //variables for Tracker & N.N
2623  vector <bool> tmpOutBool;
2624 
2625  //iwTRGSignalVector* resultT = new TRGSignalVector(na, in->clock(),22);
2626  TRGSignalVector* resultT = new TRGSignalVector(na, in->clock(), 13);
2627  TRGSignalVector* resultE = new TRGSignalVector(na, in->clock(), 10);
2628  TRGSignalVector* Hitmap = new TRGSignalVector(na + "HitMap", in->clock(), 0);
2629  TRGSignalVector pTime(na + "PriorityTime", in->clock(), 0);
2630  TRGSignalVector fTime(na + "FastestTime", in->clock(), 0);
2631  TRGSignal* pri0 = 0;
2632  TRGSignal* pri1 = 0;
2633  TRGSignal* pri2 = 0;
2634  if (_type == innerType) {
2635  for (unsigned i = 0; i < 16; i++) {
2636  Hitmap->push_back((* in)[i]);
2637  (* Hitmap)[i].widen(16);
2638  }
2639  for (unsigned i = 0; i < 4; i++) {
2640  pTime.push_back((* in)[i + 16]);
2641  fTime.push_back((* in)[i + 20]);
2642  }
2643  pri0 = & (*Hitmap)[1];
2644  pri1 = & (*Hitmap)[2];
2645  pri2 = & (*Hitmap)[3];
2646  } else {
2647  for (unsigned i = 0; i < 12; i++) {
2648  Hitmap->push_back((* in)[i]);
2649  (* Hitmap)[i].widen(16);
2650  }
2651  for (unsigned i = 0; i < 4; i++) {
2652  pTime.push_back((* in)[i + 12]);
2653  fTime.push_back((* in)[i + 16]);
2654  }
2655  pri0 = & (*Hitmap)[6];
2656  pri1 = & (*Hitmap)[7];
2657  pri2 = & (*Hitmap)[8];
2658  }
2659 
2660  //...Clock counter...
2661  const TRGSignalVector& cc = in->clock().clockCounter();
2662  for (unsigned i = 0; i < 5; i++) {
2663  pTime.push_back(cc[i]);
2664  fTime.push_back(cc[i]);
2665  }
2666 
2667  vector <int> changeTime = Hitmap->stateChanges();
2668 
2669  int* LUTValue = new int[changeTime.size()];
2670  if (changeTime.size()) {
2671 
2672  const string fn = "TSF::simulateTSF:tsid=" + to_string(tsid);
2674 
2675  int hitPosition = 0;
2676  bool fTimeBool[10];
2677  int tmpPTime = 0 ;
2678  int tmpCTime = 0 ;
2679  int tmpOutInt;
2680  fTime.state(changeTime[0]).copy2bool(fTimeBool);
2681  fTimeBool[9] = true;
2682  fTimeVect.insert(fTimeVect.begin(), fTimeBool, fTimeBool + 10);
2683  //tmpFTime = mkint(fTime.state(changeTime[0]));
2684  bool eOUT = true;
2685  for (unsigned i = 0; i < changeTime.size(); i++) {
2686  int ct = changeTime[i];
2687 
2688 // LUTValue[i] = tsi->LUT()->getValue(mkint(Hitmap->state(ct)));
2689  LUTValue[i] = tsi->LUT()->getValue(unsigned(Hitmap->state(ct)));
2690 
2692  if ((LUTValue[i]) && (eOUT)) {
2693  resultE->set(fTimeVect, ct);
2694  eOUT = false;
2695  }
2696 
2697  bool priority1rise = pri0->riseEdge(ct);
2698  bool priority2rise = pri1->riseEdge(ct) | pri2->riseEdge(ct);
2699 
2701  //ready for output
2702  if (priority1rise) {
2703  hitPosition = 3;
2704 // tmpPTime = mkint(pTime.state(ct));
2705  tmpPTime = unsigned(pTime.state(ct));
2706  tmpCTime = ct;
2707  } else if (priority2rise) {
2708  if (!hitPosition) {
2709 // tmpPTime = mkint(pTime.state(ct));
2710  tmpPTime = unsigned(pTime.state(ct));
2711  tmpCTime = ct;
2712  if ((*Hitmap)[0].state(ct)) hitPosition = 2;
2713  else hitPosition = 1;
2714  }
2715  }
2716 
2717  // output selection
2718  if ((hitPosition) && (LUTValue[i]) && ((ct - tmpCTime) < 16)) {
2719  tmpOutInt = tmpPTime * pow(2, 4) +
2720  LUTValue[i] * pow(2, 2) + hitPosition;
2721  tmpOutBool = mkbool(tmpOutInt, 13); // ID removed : iw
2722 
2723  if (hitPosition == 3) {
2724  if (priority1rise) {
2725  resultT->set(tmpOutBool, ct);
2726  } else {
2727  if ((LUTValue[i] == 1) | (LUTValue[i] == 2)) {
2728  if (!((LUTValue[i - 1] == 1) |
2729  (LUTValue[i - 1] == 2)))
2730  resultT->set(tmpOutBool, ct);
2731  } else {
2732  if (!(LUTValue[i - 1])) resultT->set(tmpOutBool, ct);
2733  }
2734  }
2735  } else {
2736  if (priority2rise) resultT->set(tmpOutBool, ct);
2737  else {
2738  if ((LUTValue[i] == 1) | (LUTValue[i] == 2)) {
2739  if (!((LUTValue[i - 1] == 1) |
2740  (LUTValue[i - 1] == 2)))
2741  resultT->set(tmpOutBool, ct);
2742  } else {
2743  if (!(LUTValue[i])) resultT->set(tmpOutBool, ct);
2744  }
2745  }
2746  }
2747  }
2748 
2749  if (TRGDebug::level() > 1) {
2750  cout << TRGDebug::tab() << "clk=" << ct
2751  << ", pattern=" << Hitmap->state(ct)
2752  << ", LUT=" << LUTValue[i]
2753  << ", pri=" << priority1rise
2754  << ", sec=" << priority2rise
2755  << ", hitPos=" << hitPosition
2756  << ", (clk-tmpCTime)=" << (ct - tmpCTime)
2757  << endl;
2758  }
2759  }
2760 
2762  }
2763 
2764  result.push_back(resultT);
2765  result.push_back(resultE);
2766 
2767  delete [] LUTValue;
2768  delete Hitmap;
2769 
2770  return result;
2771  }
2772 
2773  vector <TRGSignalVector*>
2774  TSFinder::simulateTSF(TRGSignalVector* in, unsigned tsid)
2775  {
2776 
2777  //variables for common
2778  const string na = "TSF" + TRGUtilities::itostring(tsid) + " in " +
2779  name();
2780  TCSegment* tsi = _tsSL[tsid];
2781  vector <TRGSignalVector*> result;
2782 
2783  //variables for EvtTime & Low pT
2784  vector<bool> fTimeVect;
2785  // int tmpFTime = 0 ;
2786 
2787  //variables for Tracker & N.N
2788  vector <bool> tmpOutBool;
2789 
2790  TRGSignalVector* resultT = new TRGSignalVector(na, in->clock(), 13);
2791  TRGSignalVector* resultE = new TRGSignalVector(na, in->clock(), 10);
2792  TRGSignalVector* Hitmap = new TRGSignalVector(na + "HitMap",
2793  in->clock(),
2794  0);
2795  TRGSignalVector pTime(na + "PriorityTime", in->clock(), 0);
2796  TRGSignalVector fTime(na + "FastestTime", in->clock(), 0);
2797  TRGSignal* pri0 = 0;
2798  TRGSignal* pri1 = 0;
2799  TRGSignal* pri2 = 0;
2800  if (_type == innerType) {
2801  for (unsigned i = 0; i < 16; i++) {
2802  Hitmap->push_back((* in)[i]);
2803  (* Hitmap)[i].widen(16);
2804  }
2805  for (unsigned i = 0; i < 4; i++) {
2806  pTime.push_back((* in)[i + 16]);
2807  fTime.push_back((* in)[i + 20]);
2808  }
2809  pri0 = & (*Hitmap)[1];
2810  pri1 = & (*Hitmap)[2];
2811  pri2 = & (*Hitmap)[3];
2812  } else {
2813  for (unsigned i = 0; i < 12; i++) {
2814  Hitmap->push_back((* in)[i]);
2815  (* Hitmap)[i].widen(16);
2816  }
2817  for (unsigned i = 0; i < 4; i++) {
2818  pTime.push_back((* in)[i + 12]);
2819  fTime.push_back((* in)[i + 16]);
2820  }
2821  pri0 = & (*Hitmap)[6];
2822  pri1 = & (*Hitmap)[7];
2823  pri2 = & (*Hitmap)[8];
2824  }
2825 
2826  //...Clock counter...
2827  const TRGSignalVector& cc = in->clock().clockCounter();
2828  for (unsigned i = 0; i < 5; i++) {
2829  pTime.push_back(cc[i]);
2830  fTime.push_back(cc[i]);
2831  }
2832 
2833  vector<int> changeTime = Hitmap->stateChanges();
2834 
2835  int* LUTValue = new int[changeTime.size()];
2836  //int oldLUT = 0;
2837  int lastFastHit = in->clock().min();
2838  if (changeTime.size()) {
2839 
2840  int oldLUT = 0; // 2019/07/31 by ytlai, moved to here to reduce scope
2841  const string fn = "TSF::simulateTSF:tsid=" + to_string(tsid);
2843 
2844  int hitPosition = 0;
2845  int tmpPTime = 0 ;
2846  int tmpCTime = 0 ;
2847  int tmpOutInt;
2848  TRGState ft(10);
2849  bool eOut = false;
2850  for (unsigned i = 0; i < changeTime.size(); i++) {
2851 
2852  int ct = changeTime[i];
2853  TRGState st = Hitmap->state(ct);
2854 
2855  //...LUT...
2856  // 0:no hit, 1:right, 2:left, 3:LR unknown hit
2857  LUTValue[i] = tsi->LUT()->getValue(unsigned(st));
2858 
2859  //...Any wire hit (for the fastest timing)...
2860  bool active = st.active();
2861  if (active) {
2862  const int timeCounter = ct - lastFastHit;
2863 
2864  //...Record as the fastest timing hit...
2865  if (timeCounter > 15) {
2866  lastFastHit = ct;
2867  TRGState ftnow = fTime.state(ct);
2868  ftnow += TRGState(1, 1);
2869  ft = ftnow;
2870  eOut = true;
2871  }
2872  }
2873 
2875  if ((LUTValue[i])) {
2876  if (eOut) {
2877  resultE->set(fTimeVect, ct);
2878  eOut = false;
2879  }
2880  }
2881 
2882  bool priority1rise = pri0->riseEdge(ct);
2883  bool priority2rise = pri1->riseEdge(ct) | pri2->riseEdge(ct);
2884 
2886  //ready for output
2887  if (priority1rise) {
2888  hitPosition = 3;
2889  tmpPTime = unsigned(pTime.state(ct));
2890  tmpCTime = ct;
2891  } else if (priority2rise) {
2892  if (!hitPosition) {
2893  tmpPTime = unsigned(pTime.state(ct));
2894  tmpCTime = ct;
2895  if ((*Hitmap)[0].state(ct)) hitPosition = 2;
2896  else hitPosition = 1;
2897  }
2898  }
2899 
2900  // output selection
2901  if ((ct - tmpCTime) < 16) {
2902  if ((hitPosition) && (LUTValue[i])) {
2903  //iw tmpOutInt = tsid * pow(2, 13) + tmpPTime * pow(2, 4) +
2904  //iw LUTValue[i] * pow(2,2) + hitPosition;
2905  tmpOutInt = tmpPTime * pow(2, 4) +
2906  LUTValue[i] * pow(2, 2) + hitPosition;
2907  tmpOutBool = mkbool(tmpOutInt, 13); // ID removed : iw
2908 
2909  if (hitPosition == 3) {
2910  if (priority1rise) {
2911  resultT->set(tmpOutBool, ct);
2912  oldLUT = LUTValue[i];
2913  } else {
2914  if ((LUTValue[i] == 1) | (LUTValue[i] == 2)) {
2915  if (!((oldLUT == 1) |
2916  (oldLUT == 2))) {
2917  resultT->set(tmpOutBool, ct);
2918  oldLUT = LUTValue[i];
2919  }
2920  } else {
2921  if (!(LUTValue[i - 1])) {
2922  resultT->set(tmpOutBool, ct);
2923  oldLUT = LUTValue[i];
2924  }
2925  }
2926  }
2927  } else {
2928  if ((priority2rise) && (!oldLUT)) resultT->set(tmpOutBool, ct);
2929  else {
2930  if ((LUTValue[i] == 1) | (LUTValue[i] == 2)) {
2931  if (!((oldLUT == 1) |
2932  (oldLUT == 2))) {
2933  resultT->set(tmpOutBool, ct);
2934  oldLUT = LUTValue[i];
2935  }
2936  } else {
2937  if (!(oldLUT)) {
2938  resultT->set(tmpOutBool, ct);
2939  oldLUT = LUTValue[i];
2940  }
2941  }
2942  }
2943  }
2944  }
2945  } else {
2946  oldLUT = 0;
2947  hitPosition = 0;
2948  }
2949 
2950  if (TRGDebug::level() > 1) {
2951  cout << TRGDebug::tab() << "clk=" << ct
2952  << ", pattern=" << st
2953  << ", LUT=" << LUTValue[i]
2954  << ", pri=" << priority1rise
2955  << ", sec=" << priority2rise
2956  << ", hitPos=" << hitPosition
2957  << ", (clk-tmpCTime)=" << (ct - tmpCTime)
2958  << endl;
2959  }
2960  }
2962  }
2963 
2964  if (TRGDebug::level()) {
2965  vector<int> sc = resultT->stateChanges();
2966  vector<unsigned> lv;
2967  for (unsigned i = 0; i < sc.size(); i++) {
2968  //...LUT value...
2969  unsigned l = unsigned(resultT->state(sc[i]).subset(2, 2));
2970  lv.push_back(l);
2971  cout << "clk=" << sc[i] << " LUT output[" << i << "]=" << l << endl;
2972  }
2973  bool found1or2 = false;
2974  bool found3 = false;
2975  for (unsigned i = 0; i < lv.size(); i++) {
2976  if (found1or2 && (lv[i] > 0))
2977  cout << "!!! simulateTSF something wrong(found1or2)" << endl;
2978  if (found3 && (lv[i] == 3))
2979  cout << "!!! simulateTSF something wrong(found3)" << endl;
2980 
2981  if ((lv[i] == 1) & (lv[i] == 2))
2982  found1or2 = true;
2983  else if (lv[i] == 3)
2984  found3 = true;
2985  }
2986  }
2987 
2988  result.push_back(resultT);
2989  result.push_back(resultE);
2990 
2991  delete [] LUTValue;
2992  delete Hitmap;
2993 
2994  return result;
2995  }
2996  vector <TRGSignalVector*>
2997  TSFinder::simulateTSF2(TRGSignalVector* in, unsigned tsid)
2998  {
2999 
3000  //variables for common
3001  const string na = "TSF" + TRGUtilities::itostring(tsid) + " in " +
3002  name();
3003  TCSegment* tsi = _tsSL[tsid];
3004  vector <TRGSignalVector*> result;
3005 
3006  //variables for EvtTime & Low pT
3007  vector<bool> fTimeVect;
3008  // int tmpFTime = 0 ;
3009 
3010  //variables for Tracker & N.N
3011  TRGSignalVector* resultT = new TRGSignalVector(na, in->clock(), 13);
3012  TRGSignalVector* resultE = new TRGSignalVector(na, in->clock(), 10);
3013  TRGSignalVector* Hitmap = new TRGSignalVector(na + "HitMap",
3014  in->clock(),
3015  0);
3016  TRGSignalVector pTime(na + "PriorityTime", in->clock(), 0);
3017  TRGSignalVector fTime(na + "FastestTime", in->clock(), 0);
3018  TRGSignal* pri0 = 0;
3019  TRGSignal* pri1 = 0;
3020  TRGSignal* pri2 = 0;
3021 
3022  if (_type == innerType) {
3023  for (unsigned i = 0; i < 16; i++) {
3024  Hitmap->push_back((* in)[i]);
3025  (* Hitmap)[i].widen(16);
3026  }
3027  for (unsigned i = 0; i < 4; i++) {
3028  pTime.push_back((* in)[i + 16]);
3029  fTime.push_back((* in)[i + 20]);
3030  }
3031  pri0 = & (*Hitmap)[1];
3032  pri1 = & (*Hitmap)[2];
3033  pri2 = & (*Hitmap)[3];
3034  } else {
3035  for (unsigned i = 0; i < 12; i++) {
3036  Hitmap->push_back((* in)[i]);
3037  (* Hitmap)[i].widen(16);
3038  }
3039  for (unsigned i = 0; i < 4; i++) {
3040  pTime.push_back((* in)[i + 12]);
3041  fTime.push_back((* in)[i + 16]);
3042  }
3043  pri0 = & (*Hitmap)[6];
3044  pri1 = & (*Hitmap)[7];
3045  pri2 = & (*Hitmap)[8];
3046  }
3047 
3048  //...Clock counter...
3049  const TRGSignalVector& cc = in->clock().clockCounter();
3050  for (unsigned i = 0; i < 5; i++) {
3051  pTime.push_back(cc[i]);
3052  fTime.push_back(cc[i]);
3053  }
3054 
3055  vector<int> changeTime = Hitmap->stateChanges();
3056 
3057  vector<unsigned> luts;
3058  int lastFastHit = in->clock().min();
3059 
3060  if (changeTime.size()) {
3061 
3062  const string fn = "TSF::simulateTSF2:tsid=" + to_string(tsid);
3064 
3065  TRGState ft(10);
3066  bool eOut = false;
3067 
3068  unsigned stateHitPos = 0; // 0:wait, 1:active1st, 2:active2nd
3069  unsigned hitPos = 0;
3070  unsigned timing = 0;
3071  int timePosFound = 0;
3072  int counterPos = 0;
3073 
3074  unsigned stateLR = 0; // 0:wait, 1:LUT12, 2:LUT3
3075 // int timeLRFound = 0;
3076 // int counterLR = 0;
3077 
3078  for (unsigned i = 0; i < changeTime.size(); i++) {
3079 
3080  const int ct = changeTime[i];
3081  const TRGState st = Hitmap->state(ct);
3082 
3083  //...LUT...
3084  // 0:no hit, 1:right, 2:left, 3:LR unknown hit
3085  const unsigned lut = tsi->LUT()->getValue(unsigned(st));
3086  luts.push_back(lut);
3087 
3088  //...Any wire hit (for the fastest timing)...
3089  const bool active = st.active();
3090  if (active) {
3091  const int timeCounter = ct - lastFastHit;
3092 
3093  //...Record as the fastest timing hit...
3094  if (timeCounter > 15) {
3095  lastFastHit = ct;
3096  TRGState ftnow = fTime.state(ct);
3097  ftnow += TRGState(1, 1);
3098  ft = ftnow;
3099  eOut = true;
3100  }
3101  }
3102 
3103  // output for EvtTime & Low pT tracker module
3104  if (lut) {
3105  if (eOut) {
3106  resultE->set(fTimeVect, ct);
3107  eOut = false;
3108  }
3109  }
3110 
3111  //...Hit position...
3112  const bool hit1st = pri0->riseEdge(ct);
3113  const bool hit2nd0 = pri1->riseEdge(ct);
3114  const bool hit2nd1 = pri2->riseEdge(ct);
3115  const bool hit2nd = hit2nd0 || hit2nd1;
3116 
3117  //...Hit position state machine...
3118 
3119  //...State : wait...
3120  if (stateHitPos == 0) {
3121  hitPos = 0;
3122  timing = 0;
3123  timePosFound = 0;
3124  if (hit1st) {
3125  hitPos = 3;
3126  timing = unsigned(pTime.state(ct));
3127  timePosFound = ct;
3128  stateHitPos = 1;
3129  } else if (hit2nd) {
3130  if ((* Hitmap)[0].state(ct))
3131  hitPos = 2;
3132  else
3133  hitPos = 1;
3134  timing = unsigned(pTime.state(ct));
3135  timePosFound = ct;
3136  stateHitPos = 2;
3137  }
3138  }
3139 
3140  //...State : active1st...
3141  else if (stateHitPos == 1) {
3142  counterPos = ct - timePosFound;
3143  if (counterPos > 15)
3144  stateHitPos = 0;
3145  }
3146 
3147  //...State : active2nd...
3148  else if (stateHitPos == 2) {
3149  if (hit1st) {
3150  hitPos = 3;
3151  timing = unsigned(pTime.state(ct));
3152  timePosFound = ct;
3153  stateHitPos = 1;
3154  } else {
3155  counterPos = ct - timePosFound;
3156  if (counterPos > 15)
3157  stateHitPos = 0;
3158  }
3159  }
3160 
3161  //...State unknown...
3162  else {
3163  cout << "TSF::simulateTSF2 !!! strange state in hit position"
3164  << endl;
3165  }
3166 
3167  //...L/R decision state machine...
3168 
3169  //...State : wait...
3170  if (stateLR == 0) {
3171  if (lut != 0) {
3172  const unsigned val = (timing << 4) | (lut << 2) | hitPos;
3173  const TRGState output(13, val);
3174  resultT->set(output, ct);
3175 // timeLRFound = ct;
3176  if ((lut == 1) || (lut == 2))
3177  stateLR = 1;
3178  else
3179  stateLR = 2;
3180 
3181  if (TRGDebug::level()) {
3182  if (((lut == 1) || (lut == 2)) && (stateHitPos == 0))
3183  cout << TRGDebug::tab()
3184  << "!!! state machines incosistent" << endl;
3185  }
3186  }
3187  }
3188 
3189  //...State : LUT12...
3190  else if (stateLR == 1) {
3191 // counterLR = ct - timeLRFound;
3192  if (counterPos > 15)
3193  stateLR = 0;
3194  }
3195 
3196  //...State : LUT3...
3197  else if (stateLR == 2) {
3198  if (lut) {
3199  if ((lut == 1) || (lut == 2)) {
3200  const unsigned val = (timing << 4) | (lut << 2) |
3201  hitPos;
3202  const TRGState output(13, val);
3203  resultT->set(output, ct);
3204 // timeLRFound = ct;
3205  stateLR = 1;
3206  } else {
3207 // counterLR = ct - timeLRFound;
3208  if (counterPos > 15)
3209  stateLR = 0;
3210  }
3211  }
3212  }
3213 
3214  //...State unknown...
3215  else {
3216  cout << "TSF::simulateTSF2 !!! strange state in L/R decision"
3217  << endl;
3218  }
3219 
3220  if (TRGDebug::level() > 1) {
3221  cout << TRGDebug::tab() << "clk=" << ct
3222  << ", ptn=" << st
3223  << ", LUT=" << lut
3224  << ", pri=" << hit1st
3225  << ", sec=" << hit2nd
3226  << ", hPos=" << hitPos
3227  << ", ctr=" << counterPos // << "," << counterLR
3228  << ", states=" << stateHitPos << "," << stateLR
3229  << endl;
3230  }
3231  }
3233  }
3234 
3235  if (TRGDebug::level()) {
3236  vector<int> sc = resultT->stateChanges();
3237  vector<unsigned> lv;
3238  for (unsigned i = 0; i < sc.size(); i++) {
3239  //...LUT value...
3240  unsigned l = unsigned(resultT->state(sc[i]).subset(2, 2));
3241  lv.push_back(l);
3242  cout << "clk=" << sc[i] << " LUT output[" << i << "]=" << l << endl;
3243  }
3244  }
3245 
3246  result.push_back(resultT);
3247  result.push_back(resultE);
3248 
3249  delete Hitmap;
3250 
3251  return result;
3252  }
3253 
3255 } // namespace Belle2
Belle2::TRGSignal
A class to represent a digitized signal. Unit is nano second.
Definition: Signal.h:28
Belle2::RelationArray
Low-level class to create/modify relations between StoreArrays.
Definition: RelationArray.h:72
Belle2::TRGCDCTrackSegmentFinder::TRGCDCTrackSegmentFinder
TRGCDCTrackSegmentFinder(const TRGCDC &, bool makeRootFile, bool logicLUTFlag)
Constructor.
Definition: TrackSegmentFinder.cc:49
Belle2::TRGSignalVector::stateChanges
std::vector< int > stateChanges(void) const
returns a list of clock position of state change.
Definition: SignalVector.cc:135
Belle2::TRGCDCTrackSegmentFinder::_type
boardType _type
Unit type.
Definition: TrackSegmentFinder.h:252
Belle2::TRGCDCTrackSegmentFinder::inputOuter
void inputOuter(const unsigned id, const unsigned nTSF, TRGSignalVector *s)
Creates input signals to TSF for the outer.
Definition: TrackSegmentFinder.cc:2512
Belle2::TRGCDCLayer::nCells
unsigned nCells(void) const
returns # of cells.
Definition: Layer.h:192
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::TRGCDCCell::hit
const TRGCDCCellHit * hit(void) const
returns a pointer to a TRGCDCCellHit.
Definition: Cell.h:363
Belle2::TRGCDCTrackSegmentFinder::fastestTimingOuter
void fastestTimingOuter(unsigned tsfID, const unsigned nTSF, TRGSignalVector &s) const
Make TRGSignals for the fastest timing bits.
Definition: TrackSegmentFinder.cc:1477
Belle2::TRGCDCTrackSegmentFinder::m_tsInformation
TClonesArray * m_tsInformation
[SuperLayer Id, Wire Id, Priority Timing]
Definition: TrackSegmentFinder.h:112
Belle2::TRGCDCTrackSegmentFinder::simulate
void simulate(void)
Firmware simulation. yi.
Definition: TrackSegmentFinder.cc:2142
Belle2::TRGCDCTrackSegmentFinder::_edg1Map
std::vector< TRGSignal * > _edg1Map
Internal data of the edge timing information.
Definition: TrackSegmentFinder.h:289
Belle2::TRGClock::clockCounter
const TRGSignalVector & clockCounter(void) const
returns the clock counter.
Definition: Clock.cc:171
Belle2::TRGCDCTrackSegmentFinder::packerForTracker
TRGSignalVector * packerForTracker(vector< TRGSignalVector * > &, vector< int > &, const unsigned)
Output packer for tracker.
Belle2::TRGState
A class to represent a state of multi bits.
Definition: State.h:29
Belle2::TRGCDCCell::signal
virtual const TRGSignal & signal(void) const =0
returns trigger output. Null will returned if no signal.
Belle2::TRGCDCTrackSegmentFinder::packerOuterTracker
TRGSignalVector * packerOuterTracker(vector< TRGSignalVector * > &, vector< int > &, const unsigned)
Packing output for tracker.
Belle2::TRGCDCWire
A class to represent a wire in CDC.
Definition: Wire.h:57
Belle2::TRGCDCTrackSegmentFinder::saveTSFResults
void saveTSFResults(std::vector< TRGCDCSegmentHit * > *segmentHitsSL)
save result of TSF
Definition: TrackSegmentFinder.cc:739
Belle2::TRGCDCTrackSegmentFinder::findTSHit
vector< TRGSignalVector * > findTSHit(TRGSignalVector *eachInput, int)
Use LUT for find TSHit.
Belle2::TRGCDCTrackSegmentFinder::saveTSInformation
void saveTSInformation(std::vector< TRGCDCSegment * > &tss)
save the TS info
Definition: TrackSegmentFinder.cc:600
Belle2::TRGCDCTrackSegmentFinder::_edg2Map
std::vector< TRGSignal * > _edg2Map
Internal data of the edge timing information.
Definition: TrackSegmentFinder.h:292
Belle2::TRGCDCTrackSegmentFinder::priorityTiming
void priorityTiming(unsigned tsfID, const unsigned nTSF, TRGSignalVector &s, const TRGSignal &center, const TRGSignal &right, const TRGSignal &left) const
Make TRGSignals for the priority timing bits.
Definition: TrackSegmentFinder.cc:1362
Belle2::TRGCDCTrackSegmentFinder::packerOuterEvt
TRGSignalVector * packerOuterEvt(vector< TRGSignalVector * >, vector< int >, int)
Packing output for evtTime & Low pT.
Belle2::TRGSignal::state
bool state(int clockPosition) const
returns true if signal is active in given clock position.
Definition: Signal.h:288
Belle2::TRGCDCTrackSegmentFinder::boardType
boardType
enum of boardType of TrackSegmentFinder
Definition: TrackSegmentFinder.h:47
Belle2::TRGCDCMerger
A class to represent a CDC merger board.
Definition: Merger.h:35
Belle2::TRGCDC::dataClock
const TRGClock & dataClock(void) const
returns the data clock.
Definition: TRGCDC.h:983
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::TRGCDC::layer
const TRGCDCLayer * layer(unsigned id) const
returns a pointer to a layer. 0 will be returned if 'id' is invalid.
Definition: TRGCDC.h:829
Belle2::TRGCDCTrackSegmentFinder::hitMapOuter
void hitMapOuter(void)
Creates the hit maps for the outer.
Definition: TrackSegmentFinder.cc:2376
Belle2::TRGCDCTrackSegmentFinder::m_logicLUTFlag
bool m_logicLUTFlag
0 is Logic. 1 is LUT.
Definition: TrackSegmentFinder.h:90
Belle2::TRGCDCTrackSegmentFinder::type
boardType type(void) const
board type of TSF
Definition: TrackSegmentFinder.cc:124
Belle2::TRGCDCTrackSegmentFinder::_fasMap
std::vector< TRGSignal * > _fasMap
Internal data of the fastest hit timing.
Definition: TrackSegmentFinder.h:280
Belle2::TRGCDCTrackSegmentFinder::_secMap
std::vector< TRGSignal * > _secMap
Internal data of the priority cell hit position flag.
Definition: TrackSegmentFinder.h:283
Belle2::TRGCDCTrackSegmentFinder::m_makeRootFile
bool m_makeRootFile
make ROOT file or not
Definition: TrackSegmentFinder.h:120
Belle2::TRGSignal::active
bool active(void) const
returns true if there is a signal.
Definition: Signal.h:279
Belle2::TRGBoard::dump
void dump(const std::string &message="", const std::string &pre="") const
dumps contents.
Definition: Board.cc:47
Belle2::TRGChannel::signal
TRGSignalBundle * signal(void) const
returns signal.
Definition: Channel.h:99
Belle2::TRGCDCCell
A class to represent a wire in CDC.
Definition: Cell.h:41
Belle2::TRGCDCTrackSegmentFinder::_cdc
const TRGCDC & _cdc
Members.
Definition: TrackSegmentFinder.h:86
Belle2::TRGCDCCellHit
A class to represent a wire hit in CDC.
Definition: CellHit.h:75
Belle2::TRGCDCTrackSegmentFinder::m_treeInputTSF
TTree * m_treeInputTSF
ROOT TTree for input.
Definition: TrackSegmentFinder.h:98
Belle2::TRGCDC::nSuperLayers
unsigned nSuperLayers(void) const
returns # of super layers.
Definition: TRGCDC.h:871
Belle2::TRGBoard::output
TRGChannel * output(unsigned i) const
returns output channel i.
Definition: Board.h:170
Belle2::TRGCDCTrackSegmentFinder::_tsfIn
std::vector< TRGSignalVector * > _tsfIn
TSF input storage.
Definition: TrackSegmentFinder.h:265
Belle2::TRGSignalVector::clock
const TRGClock & clock(void) const
returns clock.
Definition: SignalVector.h:130
Belle2::TRGCDCTrackSegmentFinder::_toBeDeleted
std::vector< TRGSignalVector * > _toBeDeleted
One time info. to be deleted in next event;.
Definition: TrackSegmentFinder.h:271
Belle2::TRGCDCTrackSegmentFinder::m_hitPatternInformation
TClonesArray * m_hitPatternInformation
Stores hitpattern information.
Definition: TrackSegmentFinder.h:104
Belle2::TRGCDCTrackSegmentFinder::m_treeOutputTSF
TTree * m_treeOutputTSF
ROOT TTree for output.
Definition: TrackSegmentFinder.h:107
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::TRGCDCTrackSegmentFinder::addID
static void addID(TRGSignalVector &s, unsigned id)
Add TSF ID to timing signal vector for the output.
Definition: TrackSegmentFinder.cc:2125
Belle2::TRGCDCTrackSegmentFinder::_edg4Map
std::vector< TRGSignal * > _edg4Map
Internal data of the edge timing information.
Definition: TrackSegmentFinder.h:298
Belle2::TRGCDCTrackSegmentFinder::m_Trg_PI
double m_Trg_PI
PI.
Definition: TrackSegmentFinder.h:88
Belle2::TRGCDCTrackSegmentFinder::m_nnPatternInformation
TClonesArray * m_nnPatternInformation
[superlayer id, lrDriftTime, timeWire0, timeWire1, ..., ...]
Definition: TrackSegmentFinder.h:117
Belle2::TRGCDC::getTRGCDC
static TRGCDC * getTRGCDC(void)
returns TRGCDC object.
Definition: TRGCDC.cc:190
Belle2::TRGCDCTrackSegmentFinder::fastestTimingInner
void fastestTimingInner(unsigned tsfID, const unsigned nTSF, TRGSignalVector &s) const
Make TRGSignals for the fastest timing bits.
Definition: TrackSegmentFinder.cc:1863
Belle2::TRGCDCTrackSegmentFinder::inputInner
void inputInner(const unsigned id, const unsigned nTSF, TRGSignalVector *s)
Creates input signals to TSF for the inner.
Definition: TrackSegmentFinder.cc:2403
Belle2::TRGCDCWireHit
A class to represent a wire hit in CDC.
Definition: WireHit.h:34
Belle2::TRGCDCTrackSegmentFinder::saveNNTSInformation
void saveNNTSInformation(std::vector< TRGCDCSegment * > &tss)
Saves NNTS information. Only when ts is hit.
Definition: TrackSegmentFinder.cc:906
Belle2::TRGCDC::segment
const TRGCDCSegment & segment(unsigned id) const
returns a track segment.
Definition: TRGCDC.h:934
Belle2::TRGCDCTrackSegmentFinder::simulateTSF2
vector< TRGSignalVector * > simulateTSF2(TRGSignalVector *in, unsigned id)
Simulate TSF response (unified version, state machine)
Belle2::TRGCDCTrackSegmentFinder::_tsfOut
std::vector< TRGSignalVector * > _tsfOut
TSF response storeage.
Definition: TrackSegmentFinder.h:268
Belle2::TRGCDCTrackSegmentFinder::m_particleEfficiency
TClonesArray * m_particleEfficiency
[Efficiency, Pt, # MC TS] Efficiency = -1 means that # MC TS is 0.
Definition: TrackSegmentFinder.h:110
Belle2::TRGCDCTrackSegmentFinder::_edg0Map
std::vector< TRGSignal * > _edg0Map
Internal data of the edge timing information.
Definition: TrackSegmentFinder.h:286
Belle2::TRGCDCWire::hit
const TRGCDCWireHit * hit(void) const
returns a pointer to a TRGCDCWireHit.
Definition: Wire.h:144
Belle2::TRGCDC
The instance of TRGCDC is a singleton.
Definition: TRGCDC.h:70
Belle2::TRGCDCTrackSegmentFinder::simulateBoard
void simulateBoard(void)
firmware simulation.
Definition: TrackSegmentFinder.cc:201
Belle2::TRGCDCTrackSegmentFinder::_priMap
std::vector< TRGSignal * > _priMap
Internal data of the priority hit timing.
Definition: TrackSegmentFinder.h:277
Belle2::RelationArray::getEntries
int getEntries() const
Get the number of elements.
Definition: RelationArray.h:252
Belle2::TRGCDCTrackSegmentFinder::simulateInner
void simulateInner(void)
Firmware simulation for the outers. yi.
Definition: TrackSegmentFinder.cc:1629
Belle2::TRGCDCTrackSegmentFinder::simulate2
void simulate2(void)
Firmware simulation. Unified version of inner and outer : yi.
Definition: TrackSegmentFinder.cc:2180
Belle2::TRGBoard::nInput
unsigned nInput(void) const
returns input channels.
Definition: Board.h:177
Belle2::TRGCDCTrackSegmentFinder::_hitMap
std::vector< TRGSignal * > _hitMap[5]
Internal data of wire hit map.
Definition: TrackSegmentFinder.h:274
Belle2::TRGUtilities::itostring
static std::string itostring(int i)
converts int to string. (Use boost::lexical_cast)
Belle2::TRGCDCTrackSegmentFinder::simulateOuter
void simulateOuter(void)
Firmware simulation for the outers. yi.
Definition: TrackSegmentFinder.cc:1061
Belle2::TRGDebug::tab
static std::string tab(void)
returns tab spaces.
Definition: Debug.cc:52
Belle2::TRGCDCTrackSegmentFinder::push_back
void push_back(const TRGCDCMerger *)
push back the Mergers of this TSF
Definition: TrackSegmentFinder.cc:1054
Belle2::TRGCDCTrackSegmentFinder::_tosbT
TRGSignalBundle * _tosbT
Output signal bundle.
Definition: TrackSegmentFinder.h:260
Belle2::TRGClock::max
int max(void) const
returns max. clock point.
Definition: Clock.h:206
Belle2::TRGSignalVector::state
TRGState state(int clockPosition) const
returns state at given clock position.
Definition: SignalVector.cc:163
Belle2::MCParticle
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:43
Belle2::StoreArray
Accessor to arrays stored in the data store.
Definition: ECLMatchingPerformanceExpertModule.h:33
Belle2::TRGCDCTrackSegmentFinder::terminate
void terminate(void)
terminate
Definition: TrackSegmentFinder.cc:128
Belle2::TRGCDCWire::signal
const TRGSignal & signal(void) const override
returns an input to the trigger. This is sync'ed to 1GHz clock.
Definition: Wire.h:225
Belle2::TRGCDCTrackSegmentFinder::simulateTSF
vector< TRGSignalVector * > simulateTSF(TRGSignalVector *in, unsigned id)
Simulate TSF response (unified version, 2016/07/12)
Belle2::TRGCDCTrackSegmentFinder::m_treeNNTSF
TTree * m_treeNNTSF
ROOT Tree for NNTSF.
Definition: TrackSegmentFinder.h:115
Belle2::TRGDebug::leaveStage
static void leaveStage(const std::string &stageName)
Declare that you leave a stage.
Definition: Debug.cc:39
Belle2::TRGCDC::nSegments
unsigned nSegments(void) const
returns # of track segments.
Definition: TRGCDC.h:955
Belle2::TRGCDCTrackSegmentFinder::_tosbE
TRGSignalBundle * _tosbE
Input signal bundle.
Definition: TrackSegmentFinder.h:258
Belle2::TRGDebug::enterStage
static void enterStage(const std::string &stageName)
Declare that you enter new stage.
Definition: Debug.cc:29
Belle2::TRGCDCTrackSegmentFinder::hitMapInner
void hitMapInner(void)
Creates the hit maps for the inner.
Definition: TrackSegmentFinder.cc:2337
Belle2::TRGCDCTrackSegmentFinder::doit
void doit(std::vector< TRGCDCSegment * > &tss, const bool trackSegmentClockSimulation, std::vector< TRGCDCSegmentHit * > &segmentHits, std::vector< TRGCDCSegmentHit * > *segmentHitsSL)
Member functions of doing TSF.
Definition: TrackSegmentFinder.cc:136
Belle2::TRGClock
A class to represent a digitized signal. Unit is nano second.
Definition: Clock.h:43
Belle2::TRGSignalVector
A class to represent a bundle of digitized signals.
Definition: SignalVector.h:31
Belle2::StoreArray::getEntries
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:226
Belle2::TRGCDCCellHit::mcLR
int mcLR(void) const
returns mc left/right information
Definition: CellHit.h:246
Belle2::TRGBoard::input
const TRGChannel * input(unsigned i) const
returns input channel i.
Definition: Board.h:163
Belle2::TRGSignalVector::set
const TRGSignalVector & set(const TRGState &, int clockPosition)
sets state at given clock.
Definition: SignalVector.cc:186
Belle2::TRGCDCTrackSegmentFinder::~TRGCDCTrackSegmentFinder
~TRGCDCTrackSegmentFinder()
Destructor.
Definition: TrackSegmentFinder.cc:111
Belle2::TRGCDCTrackSegmentFinder::m_fileTSF
TFile * m_fileTSF
ROOT file.
Definition: TrackSegmentFinder.h:95
Belle2::TRGCDCWireHit::iCDCSimHit
unsigned iCDCSimHit(void) const
return index of CDCSimHit
Definition: WireHit.h:112
Belle2::TRGCDCTrackSegmentFinder::_edg3Map
std::vector< TRGSignal * > _edg3Map
Internal data of the edge timing information.
Definition: TrackSegmentFinder.h:295