Belle II Software  release-06-02-00
TRGCDC.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 //-----------------------------------------------------------------------------
10 // Description : A class to represent CDC.
11 //-----------------------------------------------------------------------------
12 
13 #define TRG_SHORT_NAMES
14 #define TRGCDC_SHORT_NAMES
15 
16 #include <math.h>
17 #include <iostream>
18 #include <fstream>
19 #include "framework/datastore/StoreArray.h"
20 #include "framework/datastore/RelationArray.h"
21 #include "rawdata/dataobjects/RawDataBlock.h"
22 #include "rawdata/dataobjects/RawCOPPER.h"
23 #include <rawdata/dataobjects/RawTRG.h>
24 #include "cdc/geometry/CDCGeometryPar.h"
25 #include "cdc/dataobjects/CDCHit.h"
26 #include "cdc/dataobjects/CDCSimHit.h"
27 #include "mdst/dataobjects/MCParticle.h"
28 #include "trg/trg/Debug.h"
29 #include "trg/trg/Time.h"
30 #include "trg/trg/State.h"
31 #include "trg/trg/Signal.h"
32 #include "trg/trg/Channel.h"
33 #include "trg/trg/Utilities.h"
34 #include "trg/cdc/dataobjects/CDCTriggerSegmentHit.h"
35 #include "trg/cdc/dataobjects/CDCTriggerTrack.h"
36 #include "trg/trg/dataobjects/TRGTiming.h"
37 #include "trg/cdc/TRGCDC.h"
38 #include "trg/cdc/Wire.h"
39 #include "trg/cdc/Layer.h"
40 #include "trg/cdc/WireHit.h"
41 #include "trg/cdc/WireHitMC.h"
42 #include "trg/cdc/TrackMC.h"
43 #include "trg/cdc/Relation.h"
44 #include "trg/cdc/TRGCDCTrack.h"
45 #include "trg/cdc/Segment.h"
46 #include "trg/cdc/SegmentHit.h"
47 #include "trg/cdc/LUT.h"
48 #include "trg/cdc/FrontEnd.h"
49 #include "trg/cdc/Merger.h"
50 #include "trg/cdc/TrackSegmentFinder.h"
51 #include "trg/cdc/Tracker2D.h"
52 #include "trg/cdc/PerfectFinder.h"
53 #include "trg/cdc/HoughFinder.h"
54 #include "trg/cdc/Hough3DFinder.h"
55 #include "trg/cdc/Fitter3D.h"
56 #include "trg/cdc/Fitter3DUtility.h"
57 #include "trg/cdc/Link.h"
58 #include "trg/cdc/EventTime.h"
59 #include <framework/gearbox/Const.h>
60 #include <TObjString.h>
61 
62 #define NOT_USE_SOCKETLIB
63 //#define NOT_SEND
64 //#define DUMMY_DATA
65 #define TIME_MONITOR
66 //#define MULTIPLE_SEND
67 //#define MEMCPY_TO_ONE_BUFFER
68 #define SEND_BY_WRITEV
69 
70 #ifdef TRGCDC_DISPLAY
71 #include "trg/cdc/DisplayRphi.h"
72 #include "trg/cdc/DisplayHough.h"
73 namespace Belle2_TRGCDC {
74  Belle2::TRGCDCDisplayRphi* D = 0;
75 }
76 using namespace Belle2_TRGCDC;
77 #endif
78 
79 #define P3D HepGeom::Point3D<double>
80 
81 using namespace std;
82 
83 namespace Belle2 {
89  string
90  TRGCDC::name(void) const
91  {
92  return "TRGCDC";
93  }
94 
95  string
96  TRGCDC::version(void) const
97  {
98  return string("TRGCDC 5.39");
99  }
100 
101  TRGCDC*
102  TRGCDC::_cdc = 0;
103 
104  TRGCDC*
105  TRGCDC::getTRGCDC(const string& configFile,
106  unsigned simulationMode,
107  unsigned fastSimulationMode,
108  unsigned firmwareSimulationMode,
109  int firmwareSimulationStart,
110  int firmwareSimulationStop,
111  bool makeRootFile,
112  bool perfect2DFinder,
113  bool perfect3DFinder,
114  const string& innerTSLUTFile,
115  const string& outerTSLUTFile,
116  const string& rootTRGCDCFile,
117  const string& rootFitter3DFile,
118  unsigned houghFinderPeakMin,
119  const string& houghMappingFilePlus,
120  const string& houghMappingFileMinus,
121  unsigned houghDoit,
122  bool fLogicLUTTSF,
123  bool fLRLUT,
124  bool fFitter3Dsmclr,
125  bool fFitter3Ds2DFit,
126  bool fFitter3Ds2DFitDrift,
127  double inefficiency,
128  bool fileTSF,
129  bool fileETF,
130  int fverETF,
131  bool fprintFirmETF,
132  bool fileHough3D,
133  int finder3DMode,
134  bool fileFitter3D,
135  bool fXtSimpleFitter3D,
136  double TdcBinWidth,
137  int trgCDCDataInputMode,
138  const string& cdchitCollectionName)
139  {
140  if (_cdc) {
141  //delete _cdc;
142  _cdc = 0;
143  }
144 
145  if (configFile != "good-bye") {
146  _cdc = new TRGCDC(configFile,
147  simulationMode,
148  fastSimulationMode,
149  firmwareSimulationMode,
150  firmwareSimulationStart,
151  firmwareSimulationStop,
152  makeRootFile,
153  perfect2DFinder,
154  perfect3DFinder,
155  innerTSLUTFile,
156  outerTSLUTFile,
157  rootTRGCDCFile,
158  rootFitter3DFile,
159  houghFinderPeakMin,
160  houghMappingFilePlus,
161  houghMappingFileMinus,
162  houghDoit,
163  fLogicLUTTSF,
164  fLRLUT,
165  fFitter3Dsmclr,
166  fFitter3Ds2DFit,
167  fFitter3Ds2DFitDrift,
168  inefficiency,
169  fileTSF,
170  fileETF,
171  fverETF,
172  fprintFirmETF,
173  fileHough3D,
174  finder3DMode,
175  fileFitter3D,
176  fXtSimpleFitter3D,
177  TdcBinWidth,
178  trgCDCDataInputMode,
179  cdchitCollectionName);
180  } else {
181  cout << "TRGCDC::getTRGCDC ... good-bye" << endl;
182  // delete _cdc;
183  _cdc = 0;
184  }
185 
186  return _cdc;
187  }
188 
189  TRGCDC*
190  TRGCDC::getTRGCDC(void)
191  {
192  if (! _cdc)
193  cout << "TRGCDC::getTRGCDC !!! TRGCDC is not created yet" << endl;
194  return _cdc;
195  }
196 
197  vector<TCTrack*>
198  TRGCDC::getTrackList2D(void)
199  {
200  return _trackList2D;
201  }
202 
203  vector<TCTrack*>
204  TRGCDC::getTrackList2DFitted(void)
205  {
206  return _trackList2DFitted;
207  }
208 
209  vector<TCTrack*>
210  TRGCDC::getTrackList3D(void)
211  {
212  return _trackList3D;
213  }
214 
215  TRGCDC::TRGCDC(const string& configFile,
216  unsigned simulationMode,
217  unsigned fastSimulationMode,
218  unsigned firmwareSimulationMode,
219  int firmwareSimulationStart,
220  int firmwareSimulationStop,
221  bool makeRootFile,
222  bool perfect2DFinder,
223  bool perfect3DFinder,
224  const string& innerTSLUTFile,
225  const string& outerTSLUTFile,
226  const string& rootTRGCDCFile,
227  const string& rootFitter3DFile,
228  unsigned houghFinderPeakMin,
229  const string& houghMappingFilePlus,
230  const string& houghMappingFileMinus,
231  unsigned houghDoit,
232  bool fLogicLUTTSF,
233  bool fLRLUT,
234  bool fFitter3Dsmclr,
235  bool fFitter3Ds2DFit,
236  bool fFitter3Ds2DFitDrift,
237  double inefficiency,
238  bool fileTSF,
239  bool fileETF,
240  int fverETF,
241  bool fprintFirmETF,
242  bool fileHough3D,
243  int finder3DMode,
244  bool fileFitter3D,
245  bool fXtSimpleFitter3D,
246  double TdcBinWidth,
247  int trgCDCDataInputMode,
248  const string& cdchitCollectionName):
249  _debugLevel(0),
250  _configFilename(configFile),
251  _simulationMode(simulationMode),
252  _fastSimulationMode(fastSimulationMode),
253  _firmwareSimulationMode(firmwareSimulationMode),
254  _firmwareSimulationStart(firmwareSimulationStart),
255  _firmwareSimulationStop(firmwareSimulationStop),
256  _returnValue(0),
257  _makeRootFile(makeRootFile),
258  _perfect2DFinder(perfect2DFinder),
259  _perfect3DFinder(perfect3DFinder),
260  _innerTSLUTFilename(innerTSLUTFile),
261  _outerTSLUTFilename(outerTSLUTFile),
262  _rootTRGCDCFilename(rootTRGCDCFile),
263  _rootFitter3DFilename(rootFitter3DFile),
264  _fLogicLUTTSF(fLogicLUTTSF),
265  _fLRLUT(fLRLUT),
266  _fFitter3Dsmclr(fFitter3Dsmclr),
267  _fFitter3Ds2DFit(fFitter3Ds2DFit),
268  _fFitter3Ds2DFitDrift(fFitter3Ds2DFitDrift),
269  _inefficiency(inefficiency),
270  _fileTSF(fileTSF),
271  _fileETF(fileETF),
272  _fverETF(fverETF),
273  _fprintFirmETF(fprintFirmETF),
274  _fileHough3D(fileHough3D),
275  _finder3DMode(finder3DMode),
276  _fileFitter3D(fileFitter3D),
277  _fXtSimpleFitter3D(fXtSimpleFitter3D),
278  _fudgeFactor(1.),
279  _width(0),
280  _r(0),
281  _r2(0),
282  _clock("CDCTrigger system clock", 0, 125. / TdcBinWidth),
283  _clockFE("CDCFE TDC clock", _clock, 8),
284  _clockTDC("CDCTrigger TDC clock (after mergers)", _clock, 4),
285  _clockD("CDCTrigger data clock", _clock, 1, 4),
286  _clockUser3125("CDCTrigger Aurora user clock (3.125Gbps)",
287  _clock, 25, 20),
288  _clockUser6250("CDCTrigger Aurora user clock (6.250Gbps)",
289  _clock, 50, 20),
290  _offset(5.3),
291  _pFinder(0),
292  _hFinder(0),
293  _h3DFinder(0),
294  _fitter3D(0),
295  _eventTime(0),
296  _trgCDCDataInputMode(trgCDCDataInputMode),
297  _cdchitCollectionName(cdchitCollectionName)
298  {
299 
300  TRGDebug::enterStage("TRGCDC constructor");
301 
302 #ifdef TRGCDC_DISPLAY
303  int argc = 0;
304  char** argv = 0;
305  Gtk::Main main_instance(argc, argv);
306  if (! D)
307  D = new TCDisplayRphi();
308  D->clear();
309  D->show();
310  cout << "TRGCDC ... GTK initialized" << endl;
311 #endif
312 
313  //...Clock summary...
314  _clock.dump();
315  _clockFE.dump();
316  _clockTDC.dump();
317  _clockD.dump();
318 
319  //...Firmware simulation time window...
321  TRGTime fall = rise;
323  _firmwareSimulationWindow = TRGSignal(rise & fall);
324  _firmwareSimulationWindow.name("Firmware simulation window in FE clock");
326 
327  //...Time window in other clocks...
332 
333  cout << "In " << _clock.name() << endl;
334  cout << " Start : "
336  << endl;
337  cout << " Stop : "
339  << endl;
340  cout << "In " << _clockTDC.name() << endl;
341  cout << " Start : "
343  << endl;
344  cout << " Stop : "
346  << endl;
347  cout << "In " << _clockD.name() << endl;
348  cout << " Start : " << _firmwareSimulationStartDataClock << endl;
349  cout << " Stop : " << _firmwareSimulationStopDataClock << endl;
350 
351  if (TRGDebug::level()) {
352  cout << "TRGCDC ... TRGCDC initializing with " << _configFilename
353  << endl
354  << "mode=0x" << hex << _simulationMode << dec << endl;
355  }
356 
357  initialize(houghFinderPeakMin,
358  houghMappingFilePlus,
359  houghMappingFileMinus,
360  houghDoit);
361 
362  if (TRGDebug::level()) {
363  cout << "TRGCDC ... TRGCDC created with " << _configFilename << endl;
364  }
365 
366  TRGDebug::leaveStage("TRGCDC constructor");
367  }
368 
369  void
370  TRGCDC::initialize(unsigned houghFinderPeakMin,
371  const string& houghMappingFilePlus,
372  const string& houghMappingFileMinus,
373  unsigned houghDoit)
374  {
375 
376  TRGDebug::enterStage("TRGCDC initialize");
377 
378  //...CDC...
380  const unsigned nLayers = m_cdcp->nWireLayers();
381 
382  //...Loop over layers...
383  int superLayerId = -1;
384  vector<TRGCDCLayer*>* superLayer;
385  unsigned lastNWires = 0;
386  int lastShifts = -1000;
387  int ia = -1;
388  int is = -1;
389  int ias = -1;
390  int iss = -1;
391  unsigned nWires = 0;
392  float fwr = 0;
393  unsigned axialStereoSuperLayerId = 0;
394  for (unsigned i = 0; i < nLayers; i++) {
395  const unsigned nWiresInLayer = m_cdcp->nWiresInLayer(i);
396 
397  //...Axial or stereo?...
398  int nShifts = m_cdcp->nShifts(i);
399  bool axial = true;
400  if (nShifts != 0)
401  axial = false;
402 
403  unsigned axialStereoLayerId = 0;
404  if (axial) {
405  ++ia;
406  axialStereoLayerId = ia;
407  } else {
408  ++is;
409  axialStereoLayerId = is;
410  }
411 
412  if (TRGDebug::level() > 1) {
413  cout << TRGDebug::tab() << "No " << i << " nWiresInLayer: "
414  << nWiresInLayer << " axial: " << axial << " nShifts: "
415  << nShifts << endl;
416  }
417 
418  //...Is this in a new super layer?...
419  if ((lastNWires != nWiresInLayer) || (lastShifts != nShifts)) {
420  ++superLayerId;
421  superLayer = new vector<TRGCDCLayer*>;
422  _superLayers.push_back(superLayer);
423  if (axial) {
424  ++ias;
426  _axialSuperLayers.push_back(superLayer);
427  } else {
428  ++iss;
430  _stereoSuperLayers.push_back(superLayer);
431  }
432  lastNWires = nWiresInLayer;
433  lastShifts = nShifts;
434  }
435 
436  if (TRGDebug::level() > 1) {
437  cout << TRGDebug::tab() << "(lastNWires,nWiresInLayer) "
438  << lastNWires << " " << nWiresInLayer << endl;
439  cout << TRGDebug::tab() << "(lastShifts,nShifts) " << lastShifts
440  << " " << nShifts << endl;
441  cout << "superLayerId: " << superLayerId << endl;
442  cout << "ia: " << ia << " is: " << is << " ias: " << ias
443  << " iss: " << iss << endl;
444  }
445 
446  //...Calculate radius...
447  const float swr = m_cdcp->senseWireR(i);
448  if (i < nLayers - 1)
449  fwr = m_cdcp->fieldWireR(i);
450  else
451  fwr = swr + (swr - m_cdcp->fieldWireR(i - 1));
452  const float innerRadius = swr - (fwr - swr);
453  const float outerRadius = swr + (fwr - swr);
454 
455  if (TRGDebug::level() > 1)
456  cout << TRGDebug::tab() << "lyr " << i << ", in=" << innerRadius
457  << ", out=" << outerRadius << ", swr=" << swr << ", fwr"
458  << fwr << endl;
459 
460  //...New layer...
461  TRGCDCLayer* layer = new TRGCDCLayer(i,
462  superLayerId,
463  _superLayers[superLayerId]->size(),
464  axialStereoLayerId,
467  nShifts,
468  M_PI * m_cdcp->senseWireR(i)
469  * m_cdcp->senseWireR(i)
470  / double(nWiresInLayer),
471  nWiresInLayer,
472  innerRadius,
473  outerRadius);
474  _layers.push_back(layer);
475  superLayer->push_back(layer);
476  if (axial)
477  _axialLayers.push_back(layer);
478  else
479  _stereoLayers.push_back(layer);
480 
481  //...Loop over all wires in a layer...
482  for (unsigned j = 0; j < nWiresInLayer; j++) {
483  const P3D fp = P3D(m_cdcp->wireForwardPosition(i, j).x(),
484  m_cdcp->wireForwardPosition(i, j).y(),
485  m_cdcp->wireForwardPosition(i, j).z());
486  const P3D bp = P3D(m_cdcp->wireBackwardPosition(i, j).x(),
487  m_cdcp->wireBackwardPosition(i, j).y(),
488  m_cdcp->wireBackwardPosition(i, j).z());
489  TCWire* tw = new TCWire(nWires++, j, *layer, fp, bp, _clockFE);
490  if (_simulationMode & 1)
491  tw->_signal.clock(_clockTDC);
492  _wires.push_back(tw);
493  layer->push_back(tw);
494  }
495  }
496 
497  //...event Time...
498  _eventTime.push_back(new TCEventTime(*this, _fileETF));
499  _eventTime.back()->initialize();
500 
501  //...Make TSF's...
502  const unsigned nWiresInTS[2] = {15, 11};
503  const int shape[2][30] = {
504  {
505  -2, 0, // relative layer id, relative wire id
506  -1, -1, // assuming layer offset 0.0, not 0.5
507  -1, 0,
508  0, -1,
509  0, 0,
510  0, 1,
511  1, -2,
512  1, -1,
513  1, 0,
514  1, 1,
515  2, -2,
516  2, -1,
517  2, 0,
518  2, 1,
519  2, 2
520  //-2, 0, // relative layer id, relative wire id
521  //-1, 0, // assuming layer offset 0.5, not 0.0
522  //-1, 1,
523  //0, -1,
524  //0, 0,
525  //0, 1,
526  //1, -1,
527  //1, -0,
528  //1, 1,
529  //1, 2,
530  //2, -2,
531  //2, -1,
532  //2, 0,
533  //2, 1,
534  //2, 2
535  },
536  {
537  -2, -1,
538  -2, 0,
539  -2, 1,
540  -1, -1,
541  -1, 0,
542  0, 0,
543  1, -1,
544  1, 0,
545  2, -1,
546  2, 0,
547  2, 1,
548  0, 0,
549  0, 0,
550  0, 0,
551  0, 0
552  }
553  };
554  const int layerOffset[2] = {5, 2};
555  unsigned id = 0;
556  unsigned idTS = 0;
557  for (unsigned i = 0; i < nSuperLayers(); i++) {
558  unsigned tsType = 0;
559  if (i)
560  tsType = 1;
561 
562 // const unsigned nLayers = _superLayers[i]->size(); //'nLayers' shadows a previous local
563 // if (nLayers < 5) {
564  if (_superLayers[i]->size() < 5) {
565  cout << "TRGCDC !!! can not create TS because "
566  << "#layers is less than 5 in super layer " << i
567  << endl;
568  continue;
569  }
570 
571  //...TS layer... w is a central wire
572  const TCCell& ww = *(*_superLayers[i])[layerOffset[tsType]]->front();
573  TRGCDCLayer* layer = new TRGCDCLayer(id++, ww);
574  _tsLayers.push_back(layer);
575 
576  //...Loop over all wires in a central wire layer...
577  const unsigned nWiresInLayer = ww.layer().nCells();
578  for (unsigned j = 0; j < nWiresInLayer; j++) {
579  const TCWire& w =
580  *(TCWire*)(*(*_superLayers[i])[layerOffset[tsType]])[j];
581 
582  const unsigned localId = w.localId();
583  const unsigned layerId = w.layerId();
584  vector<const TCWire*> cells;
585 
586  for (unsigned k = 0; k < nWiresInTS[tsType]; k++) {
587  const unsigned laid = layerId + shape[tsType][k * 2];
588  const unsigned loid = localId + shape[tsType][k * 2 + 1];
589 
590  const TCWire* c = wire(laid, loid);
591  if (! c)
592  cout << "TRGCDC !!! no such a wire for TS : "
593  << "layer id=" << laid << ", local id=" << loid
594  << endl;
595 
596  cells.push_back(c);
597  }
598 
599  TRGCDCSegment* ts;
600  if (w.superLayerId()) {
601  ts = new TRGCDCSegment(idTS++,
602  *layer,
603  w,
604  _clockD,
606  cells);
607  } else {
608  ts = new TRGCDCSegment(idTS++,
609  *layer,
610  w,
611  _clockD,
613  cells);
614  }
615  ts->initialize();
616 
617  //...Store it...
618  _tss.push_back(ts);
619  _tsSL[i].push_back(ts);
620  layer->push_back(ts);
621  }
622  }
623 
624  //...Fill caches...
625  if (_width) delete [] _width;
626  if (_r) delete [] _r;
627  if (_r2) delete [] _r2;
628  _width = new float[nSuperLayers()];
629  _r = new float[nSuperLayers() + 1];
630  _r2 = new float[nSuperLayers() + 1];
631  for (unsigned i = 0; i < nSuperLayers(); i++) {
632  const vector<TRGCDCLayer*>& slayer = *_superLayers[i];
633  _width[i] = M_PI * 2 / float(slayer.back()->nCells());
634  _r[i] = slayer[0]->innerRadius();
635  _r2[i] = _r[i] * _r[i];
636  if (i == (nSuperLayers() - 1)) {
637  _r[i + 1] = slayer.back()->outerRadius();
638  _r2[i + 1] = _r[i + 1] * _r[i + 1];
639  }
640 
641  if (TRGDebug::level() > 9) {
642  const TCCell& wi = *slayer[0]->front();
643  const unsigned layerId = wi.layerId();
644  cout << layerId << "," << m_cdcp->senseWireR(layerId) << ","
645  << m_cdcp->fieldWireR(layerId) << endl;
646  cout << " super layer " << i << " radius=" << _r[i]
647  << "(r^2=" << _r2[i] << ")" << endl;
648  }
649  }
650 
651  //...Track Segment Finder...
652  _tsFinder = new TSFinder(*this, _fileTSF, _fLogicLUTTSF);
653 
654  //...Perfect 2D Finder...
655  _pFinder = new TCPFinder("Perfect2DFinder", *this);
656 
657  //...Perfect 3D Finder...
658  _p3DFinder = 0;
659 
660  //...Hough 2D Finder...
661  _hFinder = new TCHFinder("HoughFinder",
662  *this,
663  houghFinderPeakMin,
664  houghMappingFilePlus,
665  houghMappingFileMinus,
666  houghDoit);
667 
668  //...Hough 3D Finder...
669  _h3DFinder = new TCH3DFinder(*this, _fileHough3D, _finder3DMode);
670 
671  //...3D fitter...
672  map<string, bool> flags = {
673  {"fLRLUT", _fLRLUT},
674  {"fmcLR", _fFitter3Dsmclr},
675  {"f2DFit", _fFitter3Ds2DFit},
676  {"f2DFitDrift", _fFitter3Ds2DFitDrift},
677  {"fRootFile", _fileFitter3D},
678  {"fXtSimple", _fXtSimpleFitter3D}
679  };
680  _fitter3D = new TCFitter3D("Fitter3D",
682  *this,
683  flags);
685 
686  //...For module simulation (Front-end)...
687  configure();
688 
689  //...Initialize root file...
690  if (_makeRootFile) {
691  m_file = new TFile((char*)_rootTRGCDCFilename.c_str(), "RECREATE");
692  //m_file = new TFile("TRGCDC.root", "RECREATE");
693  m_tree = new TTree("m_tree", "tree");
694  m_treeAllTracks = new TTree("m_treeAllTracks", "treeAllTracks");
695 
696  m_fitParameters = new TClonesArray("TVectorD");
697  m_mcParameters = new TClonesArray("TVectorD");
698  m_mcTrack4Vector = new TClonesArray("TLorentzVector");
699  m_mcTrackVertexVector = new TClonesArray("TVector3");
700  m_mcTrackStatus = new TClonesArray("TVectorD");
701  // m_parameters2D = new TClonesArray("TVectorD");
702 
703  m_tree->Branch("fitParameters", &m_fitParameters, 32000, 0);
704  m_tree->Branch("mcParameters", &m_mcParameters, 32000, 0);
705  m_treeAllTracks->Branch("mcTrack4Vector", &m_mcTrack4Vector, 32000, 0);
706  m_treeAllTracks->Branch("mcTrackVertexVector", &m_mcTrackVertexVector, 32000, 0);
707  m_treeAllTracks->Branch("mcTrackStatus", &m_mcTrackStatus, 32000, 0);
708 
709  m_evtTime = new TClonesArray("TVectorD");
710  m_treeAllTracks->Branch("evtTime", &m_evtTime, 32000, 0);
711 
712  _tree2D = new TTree("tree2D", "2D Tracks");
713  _tracks2D = new TClonesArray("TVectorD");
714  _tree2D->Branch("track parameters", & _tracks2D, 32000, 0);
715 
716  //...Initialize firmware ROOT input
717  //m_minCDCTdc = 9999;
718  //m_maxCDCTdc = 0;
719  //m_minTRGTdc = 9999;
720  //m_maxTRGTdc = 0;
721 
722  m_treeROOTInput = new TTree("m_treeROOTInput", "treeRootInput");
723  //m_CDCTRGTimeMatch = new TClonesArray("TVectorD");
724  m_rootCDCHitInformation = new TClonesArray("TVectorD");
725  m_rootTRGHitInformation = new TClonesArray("TVectorD");
726  m_rootTRGRawInformation = new TClonesArray("TObjString");
727  //m_treeROOTInput->Branch("CDCTRGTimeMatch", &m_CDCTRGTimeMatch,32000,0);
728  m_treeROOTInput->Branch("rootCDCHitInformation", &m_rootCDCHitInformation, 32000, 0);
729  m_treeROOTInput->Branch("rootTRGHitInformation", &m_rootTRGHitInformation, 32000, 0);
730  m_treeROOTInput->Branch("rootTRGRawInformation", &m_rootTRGRawInformation, 32000, 0);
731  }
732 
733  TRGDebug::leaveStage("TRGCDC initialize");
734  }
735 
736  void
738  {
739  TRGDebug::enterStage("TRGCDC terminate");
740 
741  if (_tsFinder) {
742  _tsFinder->terminate();
743  }
744  if (_eventTime.back()) {
745  _eventTime.back()->terminate();
746  }
747  if (_fitter3D) {
748  _fitter3D->terminate();
749  }
750  if (_hFinder) {
751  _hFinder->terminate();
752  }
753  if (_h3DFinder) {
755  }
756  if (_makeRootFile) {
757  m_file->Write();
758  m_file->Close();
759  }
760 
761  TRGDebug::leaveStage("TRGCDC terminate");
762  }
763 
764  void
765  TRGCDC::dump(const string& msg) const
766  {
767  TRGDebug::enterStage("TRGCDC dump");
768 
769  if (msg.find("name") != string::npos ||
770  msg.find("version") != string::npos ||
771  msg.find("detail") != string::npos ||
772  msg == "") {
773  cout << name() << "(CDC version=" << versionCDC() << ", "
774  << version() << ") ";
775  }
776  if (msg.find("detail") != string::npos ||
777  msg.find("state") != string::npos) {
778  cout << "Debug Level=" << _debugLevel;
779  }
780  cout << endl;
781 
782  string tab(" ");
783 
784  if (msg == "" || msg.find("geometry") != string::npos) {
785  //...Get information..."
786  unsigned nLayer = _layers.size();
787  cout << " version : " << version() << endl;
788  cout << " cdc version: " << versionCDC() << endl;
789  cout << " # of wires : " << _wires.size() << endl;
790  cout << " # of layers: " << nLayer << endl;
791  cout << " super layer information" << endl;
792  cout << " # of super layers() = "
793  << nSuperLayers() << endl;
794  cout << " # of Axial super layers = "
795  << nAxialSuperLayers() << endl;
796  cout << " # of Stereo super layers = "
797  << nStereoSuperLayers() << endl;
798 
799  if (msg.find("superLayers") != string::npos) {
800  cout << " super layer detail" << endl;
801  cout << " id #layers (stereo type)" << endl;
802  for (unsigned i = 0; i < nSuperLayers(); ++i) {
803  const unsigned n = _superLayers[i]->size();
804  cout << " " << i << " " << n << " (";
805  for (unsigned j = 0; j < n; j++) {
806  cout << (* _superLayers[i])[0]->stereoType();
807  }
808  cout << ")" << endl;
809  }
810  }
811 
812  cout << " layer information" << endl;
813  cout << " # of Axial layers = "
814  << nAxialLayers() << endl;
815  cout << " # of Stereo layers = "
816  << nStereoLayers() << endl;
817 
818  if (msg.find("layers") != string::npos) {
819  cout << " layer detail" << endl;
820  cout << " id type sId #wires lId asId assId"
821  << endl;
822  for (unsigned int i = 0; i < nLayers(); ++i) {
823  const TRGCDCLayer& l = *_layers[i];
824  cout << " " << i
825  << " " << l.stereoType()
826  << " " << l.superLayerId()
827  << " " << l.nCells()
828  << " " << l.localLayerId()
829  << " " << l.axialStereoLayerId()
830  << " " << l.axialStereoSuperLayerId()
831  << endl;
832  }
833  }
834 
835  if (msg.find("wires") != string::npos) {
836  cout << " wire information" << endl;
837  for (unsigned i = 0; i < nWires(); i++)
838  (_wires[i])->dump("neighbor", tab);
839  }
840 
841  return;
842  }
843  if (msg.find("hits") != string::npos) {
844  cout << " hits : " << _hits.size() << endl;
845  for (unsigned i = 0; i < (unsigned) _hits.size(); i++)
846  _hits[i]->dump("mc drift", tab);
847  }
848  if (msg.find("axialHits") != string::npos) {
849  cout << " hits : " << _axialHits.size() << endl;
850  for (unsigned i = 0; i < (unsigned) _axialHits.size(); i++)
851  _axialHits[i]->dump("mc drift", tab);
852  }
853  if (msg.find("stereoHits") != string::npos) {
854  cout << " hits : " << _stereoHits.size() << endl;
855  for (unsigned i = 0; i < (unsigned) _stereoHits.size(); i++)
856  _stereoHits[i]->dump("mc drift", tab);
857  }
858  if (msg.find("trgWireHits") != string::npos) {
859  const string dumpOption = "trigger detail";
860  cout << " wire hits" << endl;
861  for (unsigned i = 0; i < nWires(); i++) {
862  const TCWire& w = *wire(i);
863  if (w.signal().active())
864  w.dump(dumpOption, TRGDebug::tab(4));
865  }
866  }
867  if (msg.find("trgWireCentralHits") != string::npos) {
868  const string dumpOption = "trigger detail";
869  cout << " wire hits" << endl;
870  for (unsigned i = 0; i < nSegments(); i++) {
871  const TCSegment& s = segment(i);
872  if (s.wires()[5]->signal().active())
873  s.wires()[5]->dump(dumpOption, TRGDebug::tab(4));
874  }
875  }
876  if (msg.find("trgTSHits") != string::npos) {
877  const string dumpOption = "trigger detail";
878  cout << " TS hits" << endl;
879  for (unsigned i = 0; i < nSegments(); i++) {
880  const TCSegment& s = segment(i);
881  if (s.signal().active())
882  s.dump(dumpOption, TRGDebug::tab(4));
883  }
884  }
885 
886  TRGDebug::leaveStage("TRGCDC dump");
887  }
888 
889  const TCWire*
890  TRGCDC::wire(unsigned id) const
891  {
892  if (id < nWires())
893  return _wires[id];
894  return 0;
895  }
896 
897  const TCWire*
898  TRGCDC::wire(unsigned layerId, int localId) const
899  {
900  if (layerId < nLayers())
901  return (TCWire*) & _layers[layerId]->cell(localId);
902  return 0;
903  }
904 
905 // const TCWire *
906 // TRGCDC::wire(const HepGeom::Point3D<double> & p) const {
907 // float r = p.mag();
908 // float phi = p.phi();
909 // return wire(r, phi);
910 // }
911 
912  const TCWire*
913  TRGCDC::wire(float , float) const
914  {
915  //...Not implemented yet...
916  return _wires[0];
917 
918  // // cout << "r,phi = " << r << "," << p << endl;
919 
920  // // unsigned id = 25;
921  // // bool ok = false;
922  // // const TRGCDCLayer * l;
923  // // while (! ok) {
924  // // l = layer(id);
925  // // if (! l) return 0;
926 
927  // // const geocdc_layer * geo = l->geocdc();
928  // // if (geo->m_r + geo->m_rcsiz2 < r) ++id;
929  // // else if (geo->m_r - geo->m_rcsiz1 > r) --id;
930  // // else ok = true;
931  // // }
932  // // float dPhi = 2. * M_PI / float(l->nCells());
933  // // if (l->geocdc()->m_offset > 0.) p -= dPhi / 2.;
934  // // unsigned localId = unsigned(phi(p) / dPhi);
935  // // return l->wire(localId);
936  // }
937  }
938 
939  void
941  {
942  TRGDebug::enterStage("TRGCDC clear");
943 
944  TCWHit::removeAll();
945  TCSHit::removeAll();
946  TCLink::removeAll();
947 
948  // for (unsigned i = 0; i < _hits.size(); i++)
949  // delete _hits[i];
950  for (unsigned i = 0; i < _hitsMC.size(); i++)
951  delete _hitsMC[i];
952  // for (unsigned i = 0; i < _badHits.size(); i++)
953  // delete _badHits[i];
954  // for (unsigned i = 0; i < _segmentHits.size(); i++)
955  // delete _segmentHits[i];
956 
957  for (unsigned i = 0; i < _wires.size(); i++) {
958  TCWire* w = _wires[i];
959  w->clear();
960  }
961  for (unsigned i = 0; i < _tss.size(); i++) {
962  TCSegment* s = _tss[i];
963  s->clear();
964  }
965  _hitWires.clear();
966  _hits.clear();
967  _axialHits.clear();
968  _stereoHits.clear();
969  _badHits.clear();
970  _hitsMC.clear();
971  _segmentHits.clear();
972  for (unsigned i = 0; i < 9; i++)
973  _segmentHitsSL[i].clear();
974 
975  TRGDebug::leaveStage("TRGCDC clear");
976  }
977 
978  void
980 
981  void
983  {
984  _trackList2D.clear();
985  _trackList2DFitted.clear();
986  _trackList3D.clear();
987 
988  TRGDebug::enterStage("TRGCDC update");
989 
990  if (_trgCDCDataInputMode != 0) {
992  } else {
993 
994  //...Clear old information...
995  // fastClear();
996  clear();
997 
998  //...CDCSimHit...
999  StoreArray<CDCSimHit> SimHits;
1000  if (! SimHits) {
1001  if (TRGDebug::level())
1002  cout << "TRGCDC !!! can not access to CDCSimHits" << endl;
1003  TRGDebug::leaveStage("TRGCDC update");
1004  return;
1005  }
1006  const unsigned n = SimHits.getEntries();
1007 
1008  //...CDCHit...
1010  if (! CDCHits) {
1011  if (TRGDebug::level())
1012  cout << "TRGCDC !!! can not access to CDCHits" << endl;
1013  TRGDebug::leaveStage("TRGCDC update");
1014  return;
1015  }
1016  const unsigned nHits = CDCHits.getEntries();
1017 
1018  //...MCParticle...
1019  StoreArray<MCParticle> mcParticles;
1020  if (! mcParticles) {
1021  if (TRGDebug::level())
1022  cout << "TRGCDC !!! can not access to MCParticles" << endl;
1023  TRGDebug::leaveStage("TRGCDC update");
1024  return;
1025  }
1026 
1027  //...Relations...
1028  RelationArray rels(SimHits, CDCHits);
1029  const unsigned nRels = rels.getEntries();
1030  RelationArray relsMC(mcParticles, CDCHits);
1031  const unsigned nRelsMC = relsMC.getEntries();
1032 
1033  //...Loop over CDCHits...
1034  for (unsigned i = 0; i < nHits; i++) {
1035  const CDCHit& h = *CDCHits[i];
1036  double tmp = rand() / (double(RAND_MAX));
1037  if (tmp < _inefficiency)
1038  continue;
1039 
1040  // //...Check validity (skip broken channel)...
1041  // if (! (h->m_stat & CellHitFindingValid)) continue;
1042 
1043  //...Get CDCSimHit... This is expensive. Should be moved outside.
1044  unsigned iSimHit = 0;
1045  for (unsigned j = 0; j < nRels; j++) {
1046  const unsigned k = rels[j].getToIndices().size();
1047  for (unsigned l = 0; l < k; l++) {
1048  if (rels[j].getToIndex(l) == i)
1049  iSimHit = rels[j].getFromIndex();
1050  }
1051 
1052  if (TRGDebug::level())
1053  if (k > 1)
1054  cout << "TRGCDC::update !!! CDCSimHit[" << iSimHit
1055  << "] has multiple CDCHit(" << k << " hits)" << endl;
1056  }
1057 
1058  //...Get MCParticle... This is expensive, again.
1059  // (Getting the first MCParticle only)
1060  unsigned iMCPart = 0;
1061  for (unsigned j = 0; j < nRelsMC; j++) {
1062  const unsigned k = relsMC[j].getToIndices().size();
1063  for (unsigned l = 0; l < k; l++) {
1064  if (relsMC[j].getToIndex(l) == i) {
1065  iMCPart = relsMC[j].getFromIndex();
1066  break;
1067  }
1068  }
1069 
1070  if (TRGDebug::level())
1071  if (k > 1)
1072  cout << "TRGCDC::update !!! MCParticle[" << iMCPart
1073  << "] has multiple CDCHit(" << k << " hits)" << endl;
1074  }
1075 
1076  //...Wire...
1077  int t_layerId;
1078  if (h.getISuperLayer() == 0) t_layerId = h.getILayer();
1079  else t_layerId = h.getILayer() + 6 * h.getISuperLayer() + 2;
1080  const unsigned layerId = t_layerId;
1081  const unsigned wireId = h.getIWire();
1082  const TCWire& w = * static_cast<const TCWire*>(wire(layerId, wireId));
1083 
1084  //...TDC count...
1085  B2INFO("t0:" << m_cdcp->getT0(WireID(h.getID())) <<
1086  "binwidth:" << m_cdcp->getTdcBinWidth() <<
1087  "tdc count:" << h.getTDCCount());
1088  const int tdcCount = floor(m_cdcp->getT0(WireID(h.getID())) / m_cdcp->getTdcBinWidth()
1089  - h.getTDCCount() + 0.5);
1090 
1091  //...Drift length from TDC...
1092  const float driftLength = tdcCount * m_cdcp->getTdcBinWidth() * m_cdcp->getNominalDriftV();
1093  const float driftLengthError = 0.013;
1094 
1095  //...Trigger timing...
1096  TRGTime rise = TRGTime(tdcCount, true, _clockFE, w.name());
1097  if (_simulationMode & 1)
1098  rise.clock(_clockTDC);
1099  TRGTime fall = rise;
1100  fall.shift(1).reverse();
1101  if (_simulationMode & 1)
1102  w._signal |= TRGSignal(rise & fall);
1103  else
1104  w._signal |= (TRGSignal(rise & fall) & _firmwareSimulationWindow);
1105  w._signal.name(w.name());
1106 
1107  //...Left/right...
1108  const int LRflag = SimHits[iSimHit]->getPosFlag();
1109 
1110  //...TCWireHit...
1111  TCWHit* hit = new TCWHit(w,
1112  i,
1113  iSimHit,
1114  iMCPart,
1115  driftLength,
1116  driftLengthError,
1117  driftLength,
1118  driftLengthError,
1119  LRflag,
1120  1);
1121  hit->state(CellHitFindingValid | CellHitFittingValid);
1122 
1123  //...Store a hit...
1124  if (!(*_layers[layerId])[wireId]->hit())
1125  ((TCWire*)(*_layers[layerId])[wireId])->hit(hit);
1126  _hits.push_back(hit);
1127  if (w.axial()) _axialHits.push_back(hit);
1128  else _stereoHits.push_back(hit);
1129 
1130  //...Debug...
1131  if (TRGDebug::level() > 2) {
1132  w._signal.dump("", TRGDebug::tab());
1133  cout << TRGDebug::tab(4) << "CDCHit TDC count="
1134  << h.getTDCCount() << std::endl;
1135  }
1136  }
1137 
1138  //...Track segment... This part is moved to ::simulate().
1139 
1140  //...Hit classification...
1141  // _hits.sort(TCWHit::sortByWireId);
1142  classification();
1143 
1144  if (TRGDebug::level()) {
1145  cout << TRGDebug::tab() << "#CDCSimHit=" << n << ",#CDCHit="
1146  << nHits << endl;
1147  }
1148 
1149  if (TRGDebug::level() > 2) {
1150  // StoreArray<CDCSimHit> simHits("CDCSimHits"); //TODO variable is not used, is it ok?
1151  _clock.dump("detail", TRGDebug::tab());
1152  _clockFE.dump("detail", TRGDebug::tab());
1153  if (TRGDebug::level() > 10) {
1154  for (unsigned i = 0; i < _hits.size(); i++) {
1155  const TCWHit& h = *_hits[i];
1156  h.dump("detail", TRGDebug::tab(4));
1157  }
1158  } else {
1159  //unsigned nh = 10; //TODO these two lines have no impact
1160  //if (nh > _hits.size()) nh = _hits.size();
1161  cout << TRGDebug::tab() << "Dump of the first " << n
1162  << " hits of a wire" << endl;
1163  for (unsigned i = 0; i < n; i++) {
1164  const TCWHit& h = *_hits[i];
1165  h.dump("detail", TRGDebug::tab(4));
1166  }
1167  }
1168  }
1169 
1170  }
1171 
1172  TRGDebug::leaveStage("TRGCDC update");
1173  }
1174 
1175 
1176  void
1177  TRGCDC::updateByData(int inputMode)
1178  {
1179  TRGDebug::enterStage("TRGCDC updateByData");
1180 
1181  //...Clear old information...
1182  clear();
1183 
1184  // There is a 1 window difference between slow control parameter and actual data.
1185  // For SPrint-8 data
1186  int cdcDelay = 101;
1187  int nCDCWindows = 28 + 1;
1188  // For Fuji hall data
1189  //int cdcDelay = 87;
1190  //int nCDCWindows = 32+1;
1191  // For Fuji hall matching data
1192  //int cdcDelay = 79;
1193  //int nCDCWindows = 47+1;
1194 
1195  // For TRG parameters
1196  unsigned nTRGWindows = 48;
1197  int nTrgBitsInWindow = 352;
1198 
1199  vector<string> trgInformations;
1200 
1201  // ##### Store data into a common binary format #####
1202  // inBinaryData[iBoard][iWord]
1203  vector<vector<unsigned> > inBinaryData;
1204  // Get data using Belle2Link
1205  if (inputMode == 1) {
1206 
1207  int nCdcBitsInWindow = 1536;
1208  //[FIXME] Getting data from ROOT file is fixed to 2 CDC FE, 1 TRG board.
1209  // Data should be in CDCFE0, CDCFE1, TRG sequence.
1210 
1211  // For Fuji data
1212  // Get data from root file.
1213  StoreArray<RawDataBlock> raw_datablkarray;
1214  // One block is one event. Take only first block = event.
1215  // Copper board 0 is for two CDC FE and one TRG.
1216  int iBlock = 0;
1217  int iCopper = 0;
1218  //cout<<"Number of blocks: "<<raw_cdcarray.getEntries()<<endl;
1219  //cout<<"Number of Copper: "<<raw_cdcarray[iBlock]->GetNumEntries()<<endl;
1220  int* temp_buf = raw_datablkarray[ iBlock ]->GetBuffer(iCopper);
1221  int nwords = raw_datablkarray[ iBlock ]->GetBlockNwords(iCopper);
1222  int malloc_flag = 0;
1223  int num_nodes = 1;
1224  int num_events = 1;
1225  RawCOPPER* raw_copper;
1226  RawCOPPER raw_copper_buf;
1227  raw_copper_buf.SetBuffer(temp_buf, nwords, malloc_flag, num_nodes, num_events);
1228  raw_copper = &raw_copper_buf;
1229 
1231  //StoreArray<RawCDC> raw_cdcarray;
1232  //int iBlock = 0;
1233  //int iCopper = 0;
1234  //RawCOPPER* raw_copper = raw_cdcarray[iBlock];
1235 
1237  //printf("*******Start of BODY**********\n");
1238  //printf("\n%.8d : ", 0);
1239  //for (int j = 0; j < raw_copper->GetBlockNwords(iCopper); j++) {
1240  // printf("0x%.8x ", (raw_copper->GetBuffer(iCopper))[ j ]);
1241  // if ((j + 1) % 10 == 0) {
1242  // printf("\n%.8d : ", j + 1);
1243  // }
1244  //}
1245  //printf("*******End of BODY**********\n");
1246 
1247  // Number of words for data
1248  int daqHeader = 32;
1249  int cdcHeader = 5;
1250  int cdcTrailer = 2;
1251  int trgHeader = 1;
1252  //int trgTrailer = 1;
1253  // 3 for event data. -1 for lost word in DAQ. Each window is 48 words.
1254  int widthCDCFEData = 3 - 1 + nCdcBitsInWindow / 32 * nCDCWindows;
1255  int widthTRGData = nTrgBitsInWindow / 32 * nTRGWindows;
1256 
1257  // Remove headers and trailer from data.
1258  // rawBinaryData[iBoard][iWord]
1259  // CDCFE0, CDCFE1, TSF sequence.
1260  vector<vector<unsigned> > rawBinaryData;
1261  for (int iFe = 0; iFe < 2; iFe++) {
1262  int startCDCData = daqHeader + cdcHeader + (iFe * (widthCDCFEData + cdcTrailer + cdcHeader)) + 1;
1263  // 1 is due to missing data.
1264  vector<unsigned> t_feData(widthCDCFEData + 1);
1265  // Loop over all the words for CDC FE data
1266  for (int iWord = 0; iWord < widthCDCFEData; iWord++) {
1267  t_feData[iWord] = (raw_copper->GetBuffer(iCopper))[iWord + startCDCData];
1268  }
1269  // Fill with 0 for last missing data
1270  t_feData[widthCDCFEData] = 0;
1271  rawBinaryData.push_back(t_feData);
1272  }
1273  vector<unsigned> t_trgData(widthTRGData);
1274  // Loop over all the words for TRG data
1275  int startTRGData = daqHeader + 2 * (cdcHeader + widthCDCFEData + cdcTrailer) + trgHeader + 1;
1276  for (int iWord = 0; iWord < widthTRGData; iWord++) {
1277  t_trgData[iWord] = (raw_copper->GetBuffer(iCopper))[iWord + startTRGData];
1278  }
1279  rawBinaryData.push_back(t_trgData);
1281  //for(unsigned iBoard=0; iBoard<rawBinaryData.size(); iBoard++){
1282  // cout<<"Board"<<iBoard<<endl;
1283  // for(unsigned iWord=0; iWord<rawBinaryData[iBoard].size(); iWord++){
1284  // cout<<setfill('0')<<setw(8)<<hex<<rawBinaryData[iBoard][iWord];
1285  // }
1286  // cout<<dec<<endl;
1287  //}
1288 
1289  // Shift all binary data by 8 bits to the right for two CDC FE data
1290  for (unsigned iBoard = 0; iBoard < 2; iBoard++) {
1291  unsigned t_buf = 0;
1292  // 1 is due to missing data
1293  vector<unsigned> t_feData(widthCDCFEData + 1);
1294  for (unsigned iWord = 0; iWord < rawBinaryData[iBoard].size(); iWord++) {
1295  unsigned t_value = t_buf + (rawBinaryData[iBoard][iWord] >> 8);
1296  t_buf = rawBinaryData[iBoard][iWord] << 24;
1297  t_feData[iWord] = t_value;
1298  }
1299  inBinaryData.push_back(t_feData);
1300  }
1301  inBinaryData.push_back(rawBinaryData[2]);
1303  //for(unsigned iBoard=0; iBoard<inBinaryData.size(); iBoard++){
1304  // cout<<"Board"<<iBoard<<endl;
1305  // for(unsigned iWord=0; iWord<inBinaryData[iBoard].size(); iWord++){
1306  // cout<<setfill('0')<<setw(8)<<hex<<inBinaryData[iBoard][iWord];
1307  // }
1308  // cout<<dec<<endl;
1309  //}
1310  } else if (inputMode == 2) {
1311  // get data from Belle2Link
1312  StoreArray<RawTRG> raw_trgarray;
1313  for (int i = 0; i < raw_trgarray.getEntries(); i++) {
1314  cout << "\n===== DataBlock(RawTRG) : Block # " << i << endl;
1315  for (int j = 0; j < raw_trgarray[ i ]->GetNumEntries(); j++) {
1316  RawCOPPER* raw_copper = raw_trgarray[ i ];
1317  vector<vector<unsigned> > rawBinaryData;
1318  // Loop over 4 FINESSEs
1319  for (int iFinesse = 0; iFinesse < 4; iFinesse++) {
1320  int bufferNwords = raw_copper->GetDetectorNwords(j, iFinesse);
1321  if (bufferNwords > 0) {
1322  printf("===== Detector Buffer(FINESSE # %i) 0x%x words \n", iFinesse, bufferNwords);
1323  vector<unsigned> t_copperData(raw_copper->GetDetectorNwords(j, iFinesse));
1324  // Loop over all the words for board data
1325  for (int iWord = 0; iWord < bufferNwords; iWord++) {
1326  t_copperData[iWord] = (raw_copper->GetDetectorBuffer(j, iFinesse))[iWord];
1327  }
1328  rawBinaryData.push_back(t_copperData);
1329  inBinaryData.push_back(t_copperData);
1330 
1331  }
1332  }
1333  }
1334  }
1335 
1337  //for(unsigned iBoard=0; iBoard<inBinaryData.size(); iBoard++){
1338  // cout<<"Board"<<iBoard<<endl;
1339  // for(unsigned iWord=0; iWord<inBinaryData[iBoard].size(); iWord++){
1340  // cout<<setfill('0')<<setw(8)<<hex<<inBinaryData[iBoard][iWord];
1341  // }
1342  // cout<<dec<<endl;
1343  //}
1344  } else {
1345  cout << "[ERROR} TRGCDCDataInputMode is incorrect! No simulation will be done." << endl;
1346  return;
1347  }
1348 
1349  // #####Separate binary into meaningful data#####
1350  // CDC
1351  // cdcTrgTiming[iFE]
1352  vector<unsigned> cdcTrgTiming(2);
1353  for (unsigned iFe = 0; iFe < 2; iFe++) {
1354  cdcTrgTiming[iFe] = (inBinaryData[iFe][1]) >> 16;
1355  if (cdcTrgTiming[iFe] >= 32768) cout << "CDC trigger timing error. TDC is larger than 0x8000" << endl;
1356  }
1358  //for(unsigned iFe=0; ieE<2; iFe++){
1359  // cout<<"FE"<<iFe<<" TRG Timing: "<<setfill('0')<<setw(8)<<hex<<cdcTrgTiming[0]<<dec<<endl;
1360  //}
1361  // [iHit] [0]: layerId, [1]: wireId, [2]: adc, [3]: tdc, [4]: FE trg timing
1362  vector<vector<unsigned>> hitCdcData;
1363  // Store information according to window,FE,Wire
1364  for (int iWindow = 0; iWindow < nCDCWindows; iWindow++) {
1365  for (int iFE = 0; iFE < 2; iFE++) {
1366  for (int iWire = 0; iWire < 48; iWire++) {
1367  unsigned t_adc;
1368  unsigned t_tdc;
1369  unsigned t_layerId = 3 * iFE + ((iWire / 8) % 3);
1370  unsigned t_wireId = 8 * (iWire / 24) + iWire % 8;
1371  // Take 16 bits according to wire.
1372  t_adc = ((inBinaryData[iFE][iWire / 2 + iWindow * 48 + 3] << (16 * (iWire % 2))) >> 16);
1373  t_tdc = ((inBinaryData[iFE][iWire / 2 + iWindow * 48 + 24 + 3] << (16 * (iWire % 2))) >> 16);
1374  if (t_tdc != 0) {
1375  if (t_tdc >= 32768) {
1376  // Calculate TDC.
1377  t_tdc -= 32768;
1378  // Round down and go back cdcDelay+nCDCWindows windows
1379  unsigned startTiming;
1380  if (unsigned(cdcTrgTiming[iFE] / 32) * 32 > (unsigned)(cdcDelay + nCDCWindows) * 32) {
1381  startTiming = unsigned(cdcTrgTiming[iFE] / 32) * 32 - (cdcDelay + nCDCWindows) * 32;
1382  } else {
1383  startTiming = unsigned(cdcTrgTiming[iFE] / 32) * 32 + 32768 - (cdcDelay + nCDCWindows) * 32;
1384  }
1385  if (t_tdc > startTiming) t_tdc -= startTiming;
1386  else t_tdc += 32768 - startTiming;
1387  // Fill data
1388  vector<unsigned> t_hitCdcData(5);
1389  t_hitCdcData[0] = t_layerId;
1390  t_hitCdcData[1] = t_wireId;
1391  t_hitCdcData[2] = t_adc;
1392  t_hitCdcData[3] = t_tdc;
1393  t_hitCdcData[4] = cdcTrgTiming[iFE];
1394  hitCdcData.push_back(t_hitCdcData);
1395  } else {
1396  cout << "CDC TDC data error. TDC is smaller than 0x8000. " << hex << t_tdc << dec << endl;
1397  continue;
1398  }
1399  } // end tdc hit
1400  } // wire loop
1401  } // fe loop
1402  } // window loop
1404  //for(unsigned iHit=0; iHit<hitCdcData.size(); iHit++){
1405  // cout<<"["<<hitCdcData[iHit][0]<<"]["<<hitCdcData[iHit][1]<<"]: "<<hitCdcData[iHit][2]<<", "<<hitCdcData[iHit][3]<<endl;
1406  //}
1407  // TRG
1408  // Save data into string
1409  stringstream t_trgWindow;
1410  for (unsigned iWord = 0; iWord < inBinaryData[2].size(); iWord++) {
1411  t_trgWindow << setw(8) << setfill('0') << hex << inBinaryData[2][iWord];
1412  if (iWord % 11 == 10) {
1413  trgInformations.push_back(t_trgWindow.str());
1414  t_trgWindow.str("");
1415  }
1416  }
1417  // Save data into hits
1418  // [iHit] [0]: layerId, [1]: wireId, [2]: window timing, [3]: priority timing
1419  // priority timing = -1 : No timing
1420  vector<vector<int> > hitTrgData;
1421  for (unsigned iWindow = 0; iWindow < nTRGWindows; iWindow++) {
1422  // Change binary into TRGState
1423  vector<unsigned> t_trgData(inBinaryData[2].begin() + 11 * iWindow, inBinaryData[2].begin() + 11 * iWindow + 11);
1424  TRGState t_trgState(t_trgData, 1);
1425  TRGState t_mergerState = t_trgState.subset(96, 256);
1426  TRGState t_hitMap = t_mergerState.subset(0, 80);
1427  TRGState t_priorityMap = t_mergerState.subset(32, 16);
1428  TRGState t_secondPriorityMap = t_mergerState.subset(48, 16);
1429  TRGState t_secondHitFlag = t_mergerState.subset(208, 16);
1430  TRGState t_priorityTiming = t_mergerState.subset(80, 64);
1431  TRGState t_fastestTiming = t_mergerState.subset(144, 64);
1432  //cout<<"["<<iWindow<<"] HM: "<<t_hitMap<<endl;
1433  //cout<<"["<<iWindow<<"] PHM: "<<t_priorityMap<<endl;
1434  //cout<<"["<<iWindow<<"] SHM: "<<t_secondPriorityMap<<endl;
1435  //cout<<"["<<iWindow<<"] SPF: "<<t_secondHitFlag<<endl;
1436  //cout<<"["<<iWindow<<"] PT: "<<setfill('0')<<setw(16)<<hex<<(unsigned long long) (t_priorityTiming)<<dec<<endl;
1437  //cout<<"["<<iWindow<<"] FT: "<<setfill('0')<<setw(16)<<hex<<(unsigned long long) (t_fastestTiming)<<dec<<endl;
1438  for (unsigned iWire = 0; iWire < t_hitMap.size(); iWire++) {
1439  unsigned t_layerId = iWire / 16;
1440  unsigned t_wireId = iWire % 16;
1441  if (t_hitMap[iWire] == 1) {
1442  vector<int> t_hitTrgData(4);
1443  t_hitTrgData[0] = t_layerId;
1444  t_hitTrgData[1] = t_wireId;
1445  t_hitTrgData[2] = iWindow;
1446  // Calculate priority timing
1447  if (t_layerId == 2) {
1448  t_hitTrgData[3] = (unsigned)t_priorityTiming.subset(4 * t_wireId, 4);
1449  //cout<<"["<<t_layerId<<"]["<<t_wireId<<"]: "<<iWindow<<", "<<t_hitTrgData[3]<<endl;
1450  } else if (t_layerId == 3) {
1451  // [1] Priority hit, [0] secondaryLR
1452  TRGState t_leftInformation(2);
1453  TRGState t_rightInformation(2);
1454  TRGState t_priorityHits(2);
1455  TRGState t_secondaryLR(2);
1456  if (t_wireId != 15) {
1457  t_priorityHits = t_priorityMap.subset(t_wireId, 2);
1458  t_secondaryLR = t_secondHitFlag.subset(t_wireId, 2);
1459  t_leftInformation.set(1, t_priorityMap.subset(t_wireId + 1, 1));
1460  t_leftInformation.set(0, t_secondHitFlag.subset(t_wireId + 1, 1));
1461  t_rightInformation.set(1, t_priorityMap.subset(t_wireId, 1));
1462  t_rightInformation.set(0, t_secondHitFlag.subset(t_wireId, 1));
1463  } else {
1464  t_priorityHits.set(0, t_priorityMap.subset(t_wireId, 1));
1465  t_priorityHits.set(1, 0);
1466  t_secondaryLR.set(0, t_secondHitFlag.subset(t_wireId, 1));
1467  t_secondaryLR.set(1, 0);
1468  t_leftInformation.set(1, 1);
1469  t_leftInformation.set(0, 0);
1470  t_rightInformation.set(1, t_priorityMap.subset(t_wireId, 1));
1471  t_rightInformation.set(0, t_secondHitFlag.subset(t_wireId, 1));
1472  }
1473  //cout<<"["<<iWindow<<"]["<<t_layerId<<"]["<<t_wireId<<"] PriorityHits: "<<t_priorityHits<<endl;
1474  //cout<<"["<<iWindow<<"]["<<t_layerId<<"]["<<t_wireId<<"] SecondaryLR: "<<t_secondaryLR<<endl;
1475  //cout<<"["<<iWindow<<"]["<<t_layerId<<"]["<<t_wireId<<"] Combine0: "<<t_leftInformation<<endl;
1476  //cout<<"["<<iWindow<<"]["<<t_layerId<<"]["<<t_wireId<<"] Combine1: "<<t_rightInformation<<endl;
1477  int secondaryFlag = -1;
1478  if ((unsigned)t_leftInformation == (unsigned)TRGState("00", 0)) secondaryFlag = 0;
1479  if ((unsigned)t_leftInformation == (unsigned)TRGState("01", 0)) secondaryFlag = 1;
1480  //cout<<"["<<iWindow<<"]["<<t_layerId<<"]["<<t_wireId<<"] SecondaryFlag: "<<secondaryFlag<<" timing: ";
1481  if (secondaryFlag != -1) {
1482  if (t_wireId + (1 - secondaryFlag) < 16) {
1483  //int t_priorityTiming = strtol(priorityTiming.substr(15-t_wireId-(1-secondaryFlag),1).c_str(),0,16);
1484  unsigned t_secondaryTiming = (unsigned)t_priorityTiming.subset(4 * (t_wireId + (1 - secondaryFlag)), 4);
1485  t_hitTrgData[3] = t_secondaryTiming;
1486  //cout<<t_secondaryTiming<<endl;
1487  } else {
1488  cout << "Error in TRGDATA for secondary priority hits" << endl;
1489  }
1490  //cout<<"Layer3end"<<endl;
1491  } else {
1492  t_hitTrgData[3] = -1;
1493  //cout<<"-1"<<endl;
1494  }
1495  } else {
1496  t_hitTrgData[3] = -1;
1497  }
1498  hitTrgData.push_back(t_hitTrgData);
1499  } // wire is hit
1500  } // wire loop
1501  } // window loop
1503  //if(hitTrgData.size()) cout<<"TRG: "<<endl;
1504  //for(unsigned iHit=0; iHit<hitTrgData.size(); iHit++){
1505  // cout<<"["<<hitTrgData[iHit][0]<<"]["<<hitTrgData[iHit][1]<<"]: "<<hitTrgData[iHit][2]*32+hitTrgData[iHit][3]*2<<"("<<hitTrgData[iHit][2]<<","<<hitTrgData[iHit][3]<<")"<<endl;;
1506  //}
1507  //if(hitTrgData.size()) {
1508  // for(unsigned iWindow=0; iWindow<nTRGWindows; iWindow++){
1509  // vector<unsigned> t_trgData(inBinaryData[2].begin()+11*iWindow, inBinaryData[2].begin()+11*iWindow+11);
1510  // TRGState t_trgState(t_trgData,1);
1511  // TRGState t_mergerState = t_trgState.subset(96, 256);
1512  // TRGState t_hitMap = t_mergerState.subset(0,80);
1513  // TRGState t_priorityMap = t_mergerState.subset(32,16);
1514  // TRGState t_secondPriorityMap = t_mergerState.subset(48,16);
1515  // TRGState t_secondHitFlag= t_mergerState.subset(208,16);
1516  // TRGState t_priorityTiming = t_mergerState.subset(80,64);
1517  // TRGState t_fastestTiming = t_mergerState.subset(144,64);
1518  // cout<<"["<<iWindow<<"] HM: "<<t_hitMap<<endl;
1519  // cout<<"["<<iWindow<<"] PHM: "<<t_priorityMap<<endl;
1520  // cout<<"["<<iWindow<<"] SHM: "<<t_secondPriorityMap<<endl;
1521  // cout<<"["<<iWindow<<"] SPF: "<<t_secondHitFlag<<endl;
1522  // cout<<"["<<iWindow<<"] PT: "<<setfill('0')<<setw(16)<<hex<<(unsigned long long) (t_priorityTiming)<<dec<<endl;
1523  // cout<<"["<<iWindow<<"] FT: "<<setfill('0')<<setw(16)<<hex<<(unsigned long long) (t_fastestTiming)<<dec<<endl;
1524  // }
1525  //}
1526 
1527  const int trgOutput = 2;
1528  // Store TRG data to TRGSignalBundle.
1529  // 1 is FE output. 2 is Merger output. 3 is TRG output.
1530  //...Clock...
1531  const TRGClock& dClock = TRGCDC::getTRGCDC()->dataClock();
1532  // Create signal bundle
1533  TRGSignalBundle* allTrgData;
1534  allTrgData = new TRGSignalBundle(string("TRGData"), dClock);
1535  // Create signal vector. Need to create signals for of signal vector.
1536  TRGSignalVector* trgData;
1537  trgData = new TRGSignalVector(string("TRGData"), dClock, nTrgBitsInWindow);
1538  // Loop over data and fill TRGSignalVector
1539  for (unsigned iWindow = 0; iWindow < nTRGWindows; iWindow++) {
1540  vector<unsigned> t_trgData(inBinaryData[2].begin() + 11 * iWindow, inBinaryData[2].begin() + 11 * iWindow + 11);
1541  TRGState t_trgState(t_trgData, 1);
1542  trgData->set(t_trgState, iWindow);
1543  }
1544  if (allTrgData) {
1545  allTrgData->push_back(trgData);
1546  // Clean up memory
1547  for (unsigned i = 0; i < allTrgData->size(); i++) delete(*allTrgData)[i];
1548  delete allTrgData;
1549  }
1550 
1551 
1552  // Save CDC hit data and TRG hit data to ROOT file.
1553  if (_makeRootFile) {
1554  saveTRGRawInformation(trgInformations);
1555  saveCDCHitInformation(hitCdcData);
1556  // cppcheck-suppress knownConditionTrueFalse
1557  if (trgOutput == 2) {
1558  saveTRGHitInformation(hitTrgData);
1559  }
1560  m_treeROOTInput->Fill();
1561  }
1562 
1563  // Update CDC wires using data. Start from layer 50.
1564  for (unsigned iHit = 0; iHit < hitCdcData.size(); iHit++) {
1565  unsigned t_layerId = hitCdcData[iHit][0] + 50;
1566  unsigned t_wireId = hitCdcData[iHit][1];
1567  int t_rawTdc = hitCdcData[iHit][2];
1568  const TCWire& currentWire = *static_cast<const TCWire*>(wire(t_layerId, t_wireId));
1569 
1570  // Update currentWire._signal
1571  TRGTime rise = TRGTime(t_rawTdc, true, _clockFE, currentWire.name());
1572  TRGTime fall = rise;
1573  fall.shift(1).reverse();
1574  if (currentWire._signal.active()) {
1575  currentWire._signal = currentWire.signal() | TRGSignal(rise & fall);
1576  currentWire._signal.name(currentWire.name());
1577  } else {
1578  currentWire._signal = TRGSignal(rise & fall);
1579  currentWire._signal.name(currentWire.name());
1580 
1581  // Make TCWireHit and store in _layers.
1582  // [FIXME] TCWireHit can not accept wire being hit two times.
1583  TCWHit* hit = new TCWHit(currentWire, 0, 0, 0, t_rawTdc, 0, t_rawTdc, 0, 0, 1);
1584  hit->state(CellHitFindingValid | CellHitFittingValid);
1585  ((TCWire*)(*_layers[t_layerId])[t_wireId])->hit(hit);
1586  _hits.push_back(hit);
1587  if (currentWire.axial()) _axialHits.push_back(hit);
1588  else _stereoHits.push_back(hit);
1589  }
1590  //cout<<"iLayer, iWire, iHit: "<<t_layerId<<" "<<t_wireId<<" "<<iHit<<endl;
1591  //currentWire.signal().dump();
1592 
1593  } // End updating CDC wires
1594 
1595  //...Hit classification...
1596  classification();
1597 
1598  TRGDebug::leaveStage("TRGCDC updateByData");
1599  }
1600 
1601  void
1603  {
1604  TRGDebug::enterStage("TRGCDC classification");
1605 
1606  unsigned n = _hits.size();
1607 
1608  for (unsigned i = 0; i < n; i++) {
1609  TCWHit* h = _hits[i];
1610  const TCWire& w = h->wire();
1611  unsigned state = h->state();
1612 
1613  //...Cache pointers to a neighbor...
1614  const TCWire* neighbor[7];
1615  for (unsigned j = 0; j < 7; j++) neighbor[j] = w.neighbor(j);
1616 
1617  //...Decide hit pattern...
1618  unsigned pattern = 0;
1619  for (unsigned j = 0; j < 7; j++) {
1620  if (neighbor[j])
1621  if (neighbor[j]->hit())
1622  pattern += (1 << j);
1623  }
1624  state |= (pattern << CellHitNeighborHit);
1625 
1626  //...Check isolation...
1627  const TCWHit* hr1 = neighbor[2]->hit();
1628  const TCWHit* hl1 = neighbor[3]->hit();
1629  if ((hr1 == 0) && (hl1 == 0)) {
1630  state |= CellHitIsolated;
1631  } else {
1632  const TCWHit* hr2 = neighbor[2]->neighbor(2)->hit();
1633  const TCWHit* hl2 = neighbor[3]->neighbor(3)->hit();
1634  if (((hr2 == 0) && (hr1 != 0) && (hl1 == 0)) ||
1635  ((hl2 == 0) && (hl1 != 0) && (hr1 == 0)))
1636  state |= CellHitIsolated;
1637  }
1638 
1639  //...Check continuation...
1640  // unsigned superLayer = w.superLayerId();
1641  bool previous = false;
1642  bool next = false;
1643  if (neighbor[0] == 0) previous = true;
1644  else {
1645  if ((neighbor[0]->hit()) || neighbor[1]->hit())
1646  previous = true;
1647  // if (m_smallcell && w.layerId() == 3)
1648  // if (neighbor[6]->hit())
1649  // previous = true;
1650  }
1651  if (neighbor[5] == 0) next = true;
1652  else {
1653  if ((neighbor[4]->hit()) || neighbor[5]->hit())
1654  next = true;
1655  }
1656  // if (previous && next) state |= CellHitContinuous;
1657  if (previous || next) state |= CellHitContinuous;
1658 
1659  //...Solve LR locally...
1660  if ((pattern == 34) || (pattern == 42) ||
1661  (pattern == 40) || (pattern == 10) ||
1662  (pattern == 35) || (pattern == 50))
1663  state |= CellHitPatternRight;
1664  else if ((pattern == 17) || (pattern == 21) ||
1665  (pattern == 20) || (pattern == 5) ||
1666  (pattern == 19) || (pattern == 49))
1667  state |= CellHitPatternLeft;
1668 
1669  //...Store it...
1670  h->state(state);
1671  }
1672 
1673  TRGDebug::leaveStage("TRGCDC classification");
1674  }
1675 
1676  vector<const TCWHit*>
1677  TRGCDC::axialHits(void) const
1678  {
1679  vector<const TCWHit*> t;
1680  t.assign(_axialHits.begin(), _axialHits.end());
1681  return t;
1682 
1683  // if (! mask) return _axialHits;
1684  // else if (mask == CellHitFindingValid) return _axialHits;
1685  // cout << "TRGCDC::axialHits !!! unsupported mask given" << endl;
1686  // return _axialHits;
1687  }
1688 
1689  vector<const TCWHit*>
1691  {
1692  vector<const TCWHit*> t;
1693  t.assign(_stereoHits.begin(), _stereoHits.end());
1694  return t;
1695 
1696  // if (! mask) return _stereoHits;
1697  // else if (mask == CellHitFindingValid) return _stereoHits;
1698  // cout << "TRGCDC::stereoHits !!! unsupported mask given" << endl;
1699  // return _stereoHits;
1700  }
1701 
1702  vector<const TCWHit*>
1703  TRGCDC::hits(void) const
1704  {
1705  vector<const TCWHit*> t;
1706  t.assign(_hits.begin(), _hits.end());
1707  return t;
1708 
1709  // if (! mask) return _hits;
1710  // else if (mask == CellHitFindingValid) return _hits;
1711  // cout << "TRGCDC::hits !!! unsupported mask given" << endl;
1712  // return _hits;
1713  }
1714 
1715 // vector<const TCWHit *>
1716 // TRGCDC::badHits(void) const {
1717 // vector<const TCWHit *> t;
1718 // t.assign(_badHits.begin(), _badHits.end());
1719 // return t;
1720 
1721 // //cnv if (! updated()) update();
1722 // // if (_badHits.length()) return _badHits;
1723 
1724 // // //...Loop over RECCDC_WIRHIT bank...
1725 // // x unsigned nReccdc = BsCouTab(RECCDC_WIRHIT);
1726 // // for (unsigned i = 0; i < nReccdc; i++) {
1727 // // x struct reccdc_wirhit * h =
1728 // // (struct reccdc_wirhit *)
1729 // // BsGetEnt(RECCDC_WIRHIT, i + 1, BBS_No_Index);
1730 
1731 // // //...Check validity...
1732 // // if (h->m_stat & CellHitFindingValid) continue;
1733 
1734 // // //...Obtain a pointer to GEOCDC...
1735 // // x geocdc_wire * g =
1736 // // (geocdc_wire *) BsGetEnt(GEOCDC_WIRE, h->m_geo, BBS_No_Index);
1737 
1738 // // //...Get a pointer to a TRGCDCWire...
1739 // // TCWire * w = _wires[g->m_ID - 1];
1740 
1741 // // //...Create TCWHit...
1742 // // _badHits.append(new TCWHit(w, h, _fudgeFactor));
1743 // // }
1744 
1745 // // return _badHits;
1746 // }
1747 
1748  vector<const TCWHitMC*>
1749  TRGCDC::hitsMC(void) const
1750  {
1751  vector<const TCWHitMC*> t;
1752  t.assign(_hitsMC.begin(), _hitsMC.end());
1753  return t;
1754  }
1755 
1756  string
1757  TRGCDC::wireName(unsigned wireId) const
1758  {
1759  string as = "-";
1760  const TCWire* const w = wire(wireId);
1761  if (w) {
1762  if (w->stereo())
1763  as = "=";
1764  } else {
1765  return "invalid_wire(" + TRGUtil::itostring(wireId) + ")";
1766  }
1767  return TRGUtil::itostring(layerId(wireId)) + as + TRGUtil::itostring(localId(wireId));
1768  }
1769 
1770  unsigned
1771  TRGCDC::localId(unsigned id) const
1772  {
1773  cout << "TRGCDC::localId !!! this function is not tested yet"
1774  << endl;
1775  unsigned iLayer = 0;
1776  unsigned nW = 0;
1777  bool nextLayer = true;
1778  while (nextLayer) {
1779  unsigned nWLast = nW;
1780  nW += layer(iLayer++)->nCells();
1781  if (id < (nW - 1))
1782  return id - nWLast;
1783  if (nW >= nWires())
1784  nextLayer = false;
1785  }
1786  cout << "TRGCDC::localId !!! no such a wire (id=" << id << endl;
1787  return TRGCDC_UNDEFINED;
1788  }
1789 
1790  unsigned
1791  TRGCDC::layerId(unsigned id) const
1792  {
1793  cout << "TRGCDC::layerId !!! this function is not tested yet"
1794  << endl;
1795  unsigned iLayer = 0;
1796  unsigned nW = 0;
1797  bool nextLayer = true;
1798  while (nextLayer) {
1799  nW += layer(iLayer++)->nCells();
1800  if (id < (nW - 1))
1801  return iLayer - 1;
1802  if (nW >= nWires())
1803  nextLayer = false;
1804  }
1805  cout << "TRGCDC::layerId !!! no such a wire (id=" << id << endl;
1806  return TRGCDC_UNDEFINED;
1807  }
1808 
1809  unsigned
1810  TRGCDC::layerId(unsigned, unsigned) const
1811  {
1812  cout << "TRGCDC::layerId !!! this function is not implemented yet"
1813  << endl;
1814  return TRGCDC_UNDEFINED;
1815  }
1816 
1817  unsigned
1818  TRGCDC::superLayerId(unsigned id) const
1819  {
1820  unsigned iLayer = 0;
1821  unsigned nW = 0;
1822  bool nextLayer = true;
1823  while (nextLayer) {
1824  const vector<TRGCDCLayer*>& sl = *superLayer(iLayer);
1825  const unsigned nLayers = sl.size();
1826  for (unsigned i = 0; i < nLayers; i++)
1827  nW += sl[i]->nCells();
1828 
1829  if (id < (nW - 1))
1830  return iLayer;
1831  if (nW >= nWires())
1832  nextLayer = false;
1833  }
1834  cout << "TRGCDC::superLayerId !!! no such a wire (id=" << id
1835  << endl;
1836  return TRGCDC_UNDEFINED;
1837  }
1838 
1839  unsigned
1840  TRGCDC::localLayerId(unsigned id) const
1841  {
1842  unsigned iLayer = 0;
1843  unsigned nW = 0;
1844  bool nextLayer = true;
1845  while (nextLayer) {
1846  const vector<TRGCDCLayer*>& sl = *superLayer(iLayer);
1847  const unsigned nLayers = sl.size();
1848  for (unsigned i = 0; i < nLayers; i++) {
1849  nW += sl[i]->nCells();
1850  if (id < (nW - 1))
1851  return i;
1852  }
1853 
1854  if (nW >= nWires())
1855  nextLayer = false;
1856  }
1857  cout << "TRGCDC::localLayerId !!! no such a wire (id=" << id
1858  << endl;
1859  return TRGCDC_UNDEFINED;
1860  }
1861 
1862  unsigned
1863  TRGCDC::axialStereoSuperLayerId(unsigned aors, unsigned i) const
1864  {
1865  unsigned is = 99;
1866  // cout << "aors,i= " << aors <<" "<< i << std::endl;
1867  if (aors == 0) { //axial
1868  if (i <= 7) {
1869  is = 0;
1870  } else if (i <= 13) {
1871  is = 1;
1872  } else if (i <= 19) {
1873  is = 2;
1874  } else if (i <= 25) {
1875  is = 3;
1876  } else if (i <= 31) {
1877  is = 4;
1878  }
1879  } else if (aors == 1) { //stereo
1880  if (i <= 5) {
1881  is = 0;
1882  } else if (i <= 11) {
1883  is = 1;
1884  } else if (i <= 17) {
1885  is = 2;
1886  } else if (i <= 23) {
1887  is = 3;
1888  }
1889  }
1890 
1891  assert(is != 99);
1892  return is;
1893  }
1894 
1895 // void
1896 // TRGCDC::driftDistance(TLink & l,
1897 // const TTrack & t,
1898 // unsigned flag,
1899 // float t0Offset) {
1900 
1901 // //...No correction...
1902 // if (flag == 0) {
1903 // if (l.hit()) {
1904 // // l.drift(0, l.hit()->drift(0));
1905 // // l.drift(1, l.hit()->drift(1));
1906 // // l.dDrift(0, l.hit()->dDrift(0));
1907 // // l.dDrift(1, l.hit()->dDrift(1));
1908 // l.drift(l.hit()->drift(0), 0);
1909 // l.drift(l.hit()->drift(1), 1);
1910 // l.dDrift(l.hit()->dDrift(0), 0);
1911 // l.dDrift(l.hit()->dDrift(1), 1);
1912 // }
1913 // else {
1914 // // l.drift(0, 0.);
1915 // // l.drift(1, 0.);
1916 // // l.dDrift(0, 0.);
1917 // // l.dDrift(1, 0.);
1918 // l.drift(0., 0);
1919 // l.drift(0., 1);
1920 // l.dDrift(0., 0);
1921 // l.dDrift(0., 1);
1922 // }
1923 
1924 // return;
1925 // }
1926 
1927 // //...TOF correction...
1928 // float tof = 0.;
1929 // if (flag && 1) {
1930 // int imass = 3;
1931 // float tl = t.helix().a()[4];
1932 // float f = sqrt(1. + tl * tl);
1933 // float s = fabs(t.helix().curv()) * fabs(l.dPhi()) * f;
1934 // float p = f / fabs(t.helix().a()[2]);
1935 // calcdc_tof2_(& imass, & p, & s, & tof);
1936 // }
1937 
1938 // //...T0 correction....
1939 // if (! (flag && 2)) t0Offset = 0.;
1940 
1941 // //...Propagation corrections...
1942 // const TCWHit & h = * l.hit();
1943 // int wire = h.wire()->id();
1944 // HepGeom::Vector3D<double> tp = t.helix().momentum(l.dPhi());
1945 // float p[3] = {tp.x(), tp.y(), tp.z()};
1946 // const HepGeom::Point3D<double> & onWire = l.positionOnWire();
1947 // float x[3] = {onWire.x(), onWire.y(), onWire.z()};
1948 // //cnv float time = h.reccdc()->m_tdc + t0Offset - tof;
1949 // float time = 0;
1950 // float dist;
1951 // float edist;
1952 // int prop = (flag & 4);
1953 
1954 // //...Calculation with left side...
1955 // int side = -1;
1956 // if (side == 0) side = -1;
1957 // calcdc_driftdist_(& prop,
1958 // & wire,
1959 // & side,
1960 // p,
1961 // x,
1962 // & time,
1963 // & dist,
1964 // & edist);
1965 // // l.drift(0, dist);
1966 // // l.dDrift(0, edist);
1967 // l.drift(dist, 0);
1968 // l.dDrift(edist, 0);
1969 
1970 // //...Calculation with left side...
1971 // side = 1;
1972 // calcdc_driftdist_(& prop,
1973 // & wire,
1974 // & side,
1975 // p,
1976 // x,
1977 // & time,
1978 // & dist,
1979 // & edist);
1980 // // l.drift(1, dist);
1981 // // l.dDrift(1, edist);
1982 // l.drift(dist, 1);
1983 // l.dDrift(edist, 1);
1984 
1985 // //...tan(lambda) correction...
1986 // if (flag && 8) {
1987 // float tanl = abs(p[2]) / tp.perp();
1988 // float c;
1989 // if ((tanl >= 0.0) && (tanl < 0.5)) c = -0.48 * tanl + 1.3;
1990 // else if ((tanl >= 0.5) && (tanl < 1.0)) c = -0.28 * tanl + 1.2;
1991 // else if ((tanl >= 1.0) && (tanl < 1.5)) c = -0.16 * tanl + 1.08;
1992 // else c = 0.84;
1993 
1994 // // l.dDrift(0, l.dDrift(0) * c);
1995 // // l.dDrift(1, l.dDrift(1) * c);
1996 // l.dDrift(l.dDrift(0) * c, 0);
1997 // l.dDrift(l.dDrift(1) * c, 1);
1998 // }
1999 // }
2000 
2002  {
2003  TRGDebug::enterStage("TRGCDC destructor");
2004  clear();
2005 
2006  delete [] _width;
2007  delete [] _r;
2008  delete [] _r2;
2009 
2010  if (_tsFinder) delete _tsFinder;
2011  if (_hFinder)
2012  delete _hFinder;
2013  if (_h3DFinder)
2014  delete _h3DFinder;
2015  if (_fitter3D)
2016  delete _fitter3D;
2017 
2018 #ifdef TRGCDC_DISPLAY
2019  if (D)
2020  delete D;
2021  cout << "TRGCDC ... rphi displays deleted" << endl;
2022 #endif
2023 
2024  TRGDebug::leaveStage("TRGCDC destructor");
2025  }
2026 
2027  bool
2028  TRGCDC::neighbor(const TCWire& w0, const TCWire& w1) const
2029  {
2030  const int lyr0 = w0.layerId();
2031  const int lyr1 = w1.layerId();
2032  const int lyr = lyr0 - lyr1;
2033 
2034  if (abs(lyr) > 1) return false;
2035  if (w0.superLayerId() != w1.superLayerId()) return false;
2036 
2037  for (unsigned i = 0; i < 7; i++) {
2038  if (w0.neighbor(i)) {
2039  if (w0.neighbor(i)->id() == w1.id())
2040  return true;
2041  }
2042  }
2043  return false;
2044  }
2045 
2046  void
2048  {
2049  TRGDebug::enterStage("TRGCDC simulate");
2050 
2051  const bool fast = (_simulationMode & 1);
2052  const bool firm = (_simulationMode & 2);
2053  if (fast)
2054  fastSimulation();
2055  if (firm)
2057 
2058  TRGDebug::leaveStage("TRGCDC simulate");
2059  }
2060 
2061  void
2063  {
2064  TRGDebug::enterStage("TRGCDC fastSimulation");
2065 
2066 #ifdef TRGCDC_DISPLAY
2067  D->beginningOfEvent();
2068 #endif
2069 
2070  //...Options...
2071  const bool trackSegmentSimulationOnly = _fastSimulationMode & 1;
2072  const bool trackSegmentClockSimulation = _fastSimulationMode & 2;
2073 
2074  //...TSF simulation...
2075  _tsFinder->doit(_tss,
2076  trackSegmentClockSimulation,
2077  _segmentHits,
2078  _segmentHitsSL);
2079  _eventTime.back()->doit(_fverETF, _fprintFirmETF);
2080 
2081  if (_segmentHits.size() == 0) setReturnValue(TSF, 1);
2082 
2083  if (trackSegmentSimulationOnly) {
2084  TRGDebug::leaveStage("TRGCDC fastSimulation");
2085  return;
2086  }
2087 
2088 #ifdef TRGCDC_DISPLAY
2089  // dump("hits");
2090  string stg = "fast simulation results";
2091  string inf = "#segments=" + TRGUtilities::itostring(segmentHits().size());
2092  D->clear();
2093  D->stage(stg);
2094  D->information(inf);
2095  D->area().append(hits());
2096  D->area().append(segmentHits());
2097  D->show();
2098  D->run();
2099 #endif
2100 
2101  //...2D finder and fitter...
2102  if (_perfect2DFinder)
2104  else
2106  if (_trackList2D.size() == 0) setReturnValue(find2D, 1);
2107  if (_trackList2DFitted.size() == 0) setReturnValue(fit2D, 1);
2108 
2109  //cout<<"s3D"<<endl;
2110  //...Stereo finder...
2112 
2113  //...Check tracks...
2114  if (TRGDebug::level()) {
2115  for (unsigned i = 0; i < _trackList3D.size(); i++) {
2116  const TCTrack& t = *_trackList3D[i];
2117  cout << "> links=" << t.links().size() << endl;
2118  t.dump();
2119  }
2120  }
2121 
2122  //...Check relations...
2123  if (TRGDebug::level()) {
2124  for (unsigned i = 0; i < _trackList3D.size(); i++) {
2125  // trackList[i]->relation().dump();
2126  _trackList3D[i]->dump();
2127  }
2128  }
2129 
2130  //...Event Time... In ns scale.
2131  // [FIXME] This does nothing.
2132  _eventTime.back()->getT0();
2133 
2134  //...3D tracker...
2136  //_fitter3D->doitComplex(_trackList3D);
2137  //cout<<"e3D"<<endl;
2138 
2139  // Notify if track's debugValue is not 0
2140  {
2141  // For any track
2142  int t_debugValue = 0;
2143  for (unsigned iTrack = 0; iTrack < _trackList3D.size(); iTrack++) {
2144  t_debugValue |= _trackList3D[iTrack]->getDebugValue(TRGCDCTrack::EDebugValueType::any);
2145  }
2147  //int t_debugValue = TRGCDCTrack::EDebugValueType::any;
2148  //for(unsigned iTrack = 0; iTrack<_trackList3D.size(); iTrack++) {
2149  // t_debugValue &= _trackList3D[iTrack]->getDebugValue(TRGCDCTrack::EDebugValueType::any);
2150  //}
2151  setReturnValue(t_debugValue | getReturnValue());
2152  }
2153 
2154  if (TRGDebug::level() > 1) {
2155  for (unsigned iTrack = 0; iTrack < _trackList3D.size(); iTrack++) {
2156  const TCTrack& aTrack = *_trackList3D[iTrack];
2157  if (aTrack.fitted()) {
2158  double fitPt = aTrack.pt();
2159  double fitPhi0 = aTrack.helix().phi0();
2160  int fitCharge = aTrack.charge();
2161  if (fitCharge < 0) {
2162  fitPhi0 -= M_PI;
2163  if (fitPhi0 < 0) fitPhi0 += 2 * M_PI;
2164  }
2165  double fitZ0 = aTrack.helix().dz();
2166  double fitCot = aTrack.helix().tanl();
2167  cout << TRGDebug::tab() << "Track[" << iTrack << "]: charge=" << fitCharge
2168  << " pt=" << fitPt << " phi_c=" << fitPhi0
2169  << " z0=" << fitZ0 << " cot=" << fitCot << endl;
2170  const TCRelation& trackRelation = aTrack.relation();
2171  const MCParticle& trackMCParticle = trackRelation.mcParticle(0);
2172  int mcCharge = trackMCParticle.getCharge();
2173  double mcPt = trackMCParticle.getMomentum().Pt();
2174  double mcPhi0 = 0.0;
2175  if (mcCharge > 0) mcPhi0 = trackMCParticle.getMomentum().Phi() - M_PI / 2;
2176  if (mcCharge < 0) mcPhi0 = trackMCParticle.getMomentum().Phi() + M_PI / 2;
2177  // Change range to [0,2pi]
2178  if (mcPhi0 < 0) mcPhi0 += 2 * M_PI;
2179  // Calculated impact position
2180  TVector3 vertex = trackMCParticle.getVertex();
2181  TLorentzVector vector4 = trackMCParticle.get4Vector();
2182  TVector2 helixCenter;
2183  TVector3 impactPosition;
2184  Fitter3DUtility::findImpactPosition(&vertex, &vector4, mcCharge, helixCenter, impactPosition);
2185  double mcZ0 = impactPosition.Z();
2186  double mcCot = trackMCParticle.getMomentum().Pz() / trackMCParticle.getMomentum().Pt();
2187  cout << TRGDebug::tab() << "Track[" << iTrack << "]: mcCharge=" << mcCharge
2188  << " mcPt=" << mcPt << " mcPhi_c=" << mcPhi0
2189  << " mcZ0=" << mcZ0 << " mcCot=" << mcCot << endl;
2190  }
2191  }
2192  }
2193 
2194  if (TRGDebug::level()) {
2195  cout << TRGDebug::tab() << "Number of 2D tracks : "
2196  << _trackList2D.size() << endl;
2197  cout << TRGDebug::tab() << "Number of 2D fitted tracks : "
2198  << _trackList2DFitted.size() << endl;
2199  cout << TRGDebug::tab() << "Number of 3D tracks : "
2200  << _trackList3D.size() << endl;
2201  }
2202 
2203 #ifdef TRGCDC_DISPLAY
2204  // dump("hits");
2205  vector<const TCTrack*> t2;
2206  t2.assign(_trackList2D.begin(), _trackList2D.end());
2207  vector<const TCTrack*> t2f;
2208  t2f.assign(_trackList2DFitted.begin(), _trackList2DFitted.end());
2209  vector<const TCTrack*> t3;
2210  t3.assign(_trackList3D.begin(), _trackList3D.end());
2211  D->endOfEvent();
2212  stg = "fast simulation results";
2213  inf = "red:2D, blue:2DF, green:3D";
2214  D->clear();
2215  D->stage(stg);
2216  D->information(inf);
2217  D->area().append(hits());
2218  D->area().append(segmentHits());
2219  D->area().append(t2, Gdk::Color("red"));
2220  D->area().append(t2f, Gdk::Color("blue"));
2221  D->area().append(t3, Gdk::Color("green"));
2222  D->show();
2223  D->run();
2224 
2225  // unsigned iFront = 0;
2226  // while (const TCFrontEnd * f = _cdc.frontEnd(iFront++)) {
2227  // D->clear();
2228  // D->beginEvent();
2229  // D->area().append(* f);
2230  // D->run();
2231  // }
2232  // unsigned iMerger = 0;
2233  // while (const TCMerger * f = _cdc.merger(iMerger++)) {
2234  // D->clear();
2235  // D->beginEvent();
2236  // D->area().append(* f);
2237  // D->run();
2238  // }
2239 #endif
2240 
2241  TRGDebug::leaveStage("TRGCDC fastSimulation");
2242  return;
2243  }
2244 
2245  void
2246  TRGCDC::storeSimulationResults(string collection2Dfinder,
2247  string collection2Dfitter,
2248  string collection3Dfitter)
2249  {
2250  TRGDebug::enterStage("TRGCDC storeSimulationResults");
2251 
2252  // hits
2253  if (!(_fastSimulationMode & 2)) {
2254  StoreArray<CDCTriggerSegmentHit> storeSegmentHits;
2256  for (unsigned its = 0; its < _segmentHits.size(); ++its) {
2257  const TCSHit* segmentHit = _segmentHits[its];
2258  const CDCHit* priorityHit = cdcHits[segmentHit->iCDCHit()];
2259  const TCSegment* segment = static_cast<const TCSegment*>(&segmentHit->cell());
2260  const CDCTriggerSegmentHit* storeHit =
2261  storeSegmentHits.appendNew(*priorityHit,
2262  segment->id(),
2265  segment->priorityTime(),
2266  segment->fastestTime(),
2267  segment->foundTime());
2268  _tss[segment->id()]->addStoreHit(storeHit);
2269  // relation to all CDCHits in segment
2270  for (unsigned iw = 0; iw < segment->wires().size(); ++iw) {
2271  const TRGCDCWire* wire = (TRGCDCWire*)(*segment)[iw];
2272  if (wire->signal().active()) {
2273  // priority wire has relation weight 2
2274  double weight = (wire == &(segment->priority())) ? 2. : 1.;
2275  storeHit->addRelationTo(cdcHits[wire->hit()->iCDCHit()], weight);
2276  }
2277  }
2278  // relation to MCParticles (same as priority hit)
2279  RelationVector<MCParticle> mcrel = priorityHit->getRelationsFrom<MCParticle>();
2280  for (unsigned imc = 0; imc < mcrel.size(); ++imc) {
2281  mcrel[imc]->addRelationTo(storeHit, mcrel.weight(imc));
2282  }
2283  }
2284  }
2285  // event time
2286  StoreObjPtr<TRGTiming> eventTime("CDCTriggerEventTime");
2287  eventTime.construct(Const::CDC, getEventTime());
2288  // 2D finder tracks
2289  StoreArray<CDCTriggerTrack> storeTracks2Dfinder(collection2Dfinder);
2290  for (unsigned itr = 0; itr < _trackList2D.size(); ++itr) {
2291  const TCTrack* track2D = _trackList2D[itr];
2292  double phi0 = remainder(track2D->helix().phi0() + M_PI_2, 2. * M_PI);
2293  double omega = track2D->charge() / track2D->helix().radius();
2294  const CDCTriggerTrack* track =
2295  storeTracks2Dfinder.appendNew(phi0, omega, 0.);
2296  // relation to SegmentHits
2297  vector<TRGCDCLink*> links = track2D->links();
2298  for (unsigned its = 0; its < links.size(); ++its) {
2299  const TRGCDCSegment* segment = static_cast<const TRGCDCSegment*>(links[its]->cell());
2300  const vector<const CDCTriggerSegmentHit*> storeHits = segment->storeHits();
2301  for (unsigned ihit = 0; ihit < storeHits.size(); ++ihit) {
2302  track->addRelationTo(storeHits[ihit]);
2303  }
2304  }
2305  }
2306  // 2D fitter tracks
2307  StoreArray<CDCTriggerTrack> storeTracks2Dfitter(collection2Dfitter);
2308  for (unsigned itr = 0; itr < _trackList2DFitted.size(); ++itr) {
2309  const TCTrack* track2D = _trackList2DFitted[itr];
2310  if (!track2D->fitted()) continue;
2311  double phi0 = remainder(track2D->helix().phi0() + M_PI_2, 2. * M_PI);
2312  double omega = track2D->charge() / track2D->helix().radius();
2313  double chi2 = track2D->get2DFitChi2();
2314  const CDCTriggerTrack* track =
2315  storeTracks2Dfitter.appendNew(phi0, omega, chi2);
2316  // relation to SegmentHits
2317  vector<TRGCDCLink*> links = track2D->links();
2318  for (unsigned its = 0; its < links.size(); ++its) {
2319  const TRGCDCSegment* segment = static_cast<const TRGCDCSegment*>(links[its]->cell());
2320  const vector<const CDCTriggerSegmentHit*> storeHits = segment->storeHits();
2321  for (unsigned ihit = 0; ihit < storeHits.size(); ++ihit) {
2322  track->addRelationTo(storeHits[ihit]);
2323  }
2324  }
2325  // relation to 2D finder, assuming same order in tracklist
2326  if (storeTracks2Dfinder.getEntries() > 0)
2327  storeTracks2Dfinder[itr]->addRelationTo(track);
2328  }
2329  // 3D tracks
2330  StoreArray<CDCTriggerTrack> storeTracks3Dfitter(collection3Dfitter);
2331  for (unsigned itr = 0; itr < _trackList3D.size(); ++itr) {
2332  const TCTrack* track3D = _trackList3D[itr];
2333  if (!track3D->fitted()) continue;
2334  double phi0 = remainder(track3D->helix().phi0() + M_PI_2, 2. * M_PI);
2335  double omega = 1. / track3D->helix().radius();
2336  double chi2 = track3D->get2DFitChi2();
2337  double z = track3D->helix().dz();
2338  double cot = track3D->helix().tanl();
2339  double chi3 = track3D->get3DFitChi2();
2340  const CDCTriggerTrack* track =
2341  storeTracks3Dfitter.appendNew(phi0, omega, chi2, z, cot, chi3);
2342  // relation to SegmentHits
2343  vector<TRGCDCLink*> links = track3D->links();
2344  for (unsigned its = 0; its < links.size(); ++its) {
2345  const TRGCDCSegment* segment = static_cast<const TRGCDCSegment*>(links[its]->cell());
2346  const vector<const CDCTriggerSegmentHit*> storeHits = segment->storeHits();
2347  for (unsigned ihit = 0; ihit < storeHits.size(); ++ihit) {
2348  track->addRelationTo(storeHits[ihit]);
2349  }
2350  }
2351  // relation to 2D finder, assuming same order in tracklist
2352  if (storeTracks2Dfinder.getEntries() > 0)
2353  storeTracks2Dfinder[itr]->addRelationTo(track);
2354  }
2355 
2356  TRGDebug::leaveStage("TRGCDC storeSimulationResults");
2357  return;
2358  }
2359 
2360  void
2362  {
2363 #ifdef TRGCDC_DISPLAY
2364  D->beginningOfEvent();
2365 #endif
2366 
2367  TRGDebug::enterStage("TRGCDC firmwareSimulation");
2368 
2369  //...Wire level simulation is in update().
2370 
2371  //...Front ends...
2372  const unsigned nFronts = _fronts.size();
2373  for (unsigned i = 0; i < nFronts; i++) {
2374  //...Skip inner-most FE because they have no contribution to TRG
2375  if (i < 10)
2376  continue;
2377 
2378  //...FE simulation...
2379  _fronts[i]->simulate();
2380  }
2381 
2382  //...Mergers...
2383  const unsigned nMergers = _mergers.size();
2384  for (unsigned i = 0; i < nMergers; i++) {
2385  _mergers[i]->simulate();
2386  }
2387 
2388  //...TSFs...
2389  const unsigned nTSFBoards = _tsfboards.size();
2390  for (unsigned i = 0; i < nTSFBoards; i++) {
2391  //iw _tsfboards[i]->simulateBoard();
2392  // _tsfboards[i]->simulate();
2393  _tsfboards[i]->simulate2();
2394  }
2395 
2396  //...Event Time... In ns scale.
2397  // [FIXME] Not really firmware mode. Just for display.
2398  int t_eventTime = _eventTime.back()->getT0();
2399  // Update WireHit driftTime using eventTime
2400  // [FIXME] This method is a temorary method. Next time change everything inside EventTime class.
2401  //cout<<"Hit timing ";
2402  for (unsigned iHits = 0; iHits < _hits.size(); iHits++) {
2403  //cout<<"["<<_hits[iHits]->wire().layerId()<<"]["<<_hits[iHits]->wire().localId()<<"]: "<<(_hits[iHits]->drift(0))<<" ";
2404  _hits[iHits]->setDriftTime((_hits[iHits]->drift(0) - t_eventTime) / 250, 0);
2405  _hits[iHits]->setDriftTime((_hits[iHits]->drift(1) - t_eventTime) / 250, 1);
2406  }
2407  //cout<< endl;
2408  //cout<<"Event timing: "<<t_eventTime<<endl;
2409 
2410  //...Tracker2D...
2411  const unsigned nTracker2Ds = _tracker2Ds.size();
2412  for (unsigned i = 0; i < nTracker2Ds; i++) {
2413  _tracker2Ds[i]->simulate();
2414  }
2415 
2416 #ifdef TRGCDC_DISPLAY
2417  dump("hits");
2418  D->endOfEvent();
2419  string stg = "Firmware simulation";
2420  string inf = " ";
2421  D->clear();
2422  D->stage(stg);
2423  D->information(inf);
2424  D->area().append(hits());
2425  D->area().append(segmentHits());
2426  D->show();
2427  D->run();
2428  // unsigned iFront = 0;
2429  // while (const TCFrontEnd * f = _cdc.frontEnd(iFront++)) {
2430  // D->clear();
2431  // D->beginEvent();
2432  // D->area().append(* f);
2433  // D->run();
2434  // }
2435  // unsigned iMerger = 0;
2436  // while (const TCMerger * f = _cdc.merger(iMerger++)) {
2437  // D->clear();
2438  // D->beginEvent();
2439  // D->area().append(* f);
2440  // D->run();
2441  // }
2442 #endif
2443 
2444  TRGDebug::leaveStage("TRGCDC firmwareSimulation");
2445  }
2446 
2447  void
2449  {
2450  TRGDebug::enterStage("TRGCDC configure");
2451 
2452  //...Open configuration file...
2453  ifstream infile(_configFilename.c_str(), ios::in);
2454  if (infile.fail()) {
2455  cout << "TRGCDC !!! can not open file" << endl
2456  << " " << _configFilename << endl;
2457  return;
2458  }
2459 
2460  //...Read configuration data...
2461  char b[800];
2462  unsigned lines = 0;
2463  unsigned lastSl = 0;
2464  unsigned lastMergerLocalId = 0;
2465  while (! infile.eof()) {
2466  infile.getline(b, 800);
2467  const string l(b);
2468  string cdr = l;
2469 
2470  bool skip = false;
2471  unsigned wid = 0;
2472  unsigned lid = 0;
2473  unsigned fid = 0;
2474  unsigned mid = 0;
2475  unsigned tid = 0;
2476  // cppcheck-suppress knownConditionTrueFalse
2477  if (lid != 0) mid = lid + tid; //jb
2478  for (unsigned i = 0; i < 5; i++) {
2479  const string car = TRGUtil::carstring(cdr);
2480  cdr = TRGUtil::cdrstring(cdr);
2481 
2482  if (car == "#") {
2483  skip = true;
2484  break;
2485  } else if (car == "CDC") {
2486  skip = true;
2487  break;
2488  }
2489 
2490  if (i == 0) {
2491  wid = atoi(car.c_str());
2492  } else if (i == 1) {
2493  lid = atoi(car.c_str());
2494  } else if (i == 2) {
2495  fid = atoi(car.c_str());
2496  } else if (i == 3) {
2497  mid = atoi(car.c_str());
2498  } else if (i == 4) {
2499  tid = atoi(car.c_str());
2500  }
2501  }
2502 
2503  if (skip)
2504  continue;
2505  if (lines != wid)
2506  continue;
2507 
2508  //...Super layer ID...
2509  const unsigned sl = _wires[wid]->superLayerId();
2510  if (sl != lastSl)
2511  lastMergerLocalId = 0;
2512 
2513  //...Make a front-end board if necessary...
2514  bool newFrontEnd = false;
2515  TCFrontEnd* f = 0;
2516  if (fid < _fronts.size())
2517  f = _fronts[fid];
2518  if (! f) {
2519  newFrontEnd = true;
2520  const string name = "CDCFrontEnd" + TRGUtil::itostring(fid);
2521  TCFrontEnd::boardType t = TCFrontEnd::unknown;
2522  if (sl == 0) {
2523  if (_wires[wid]->localLayerId() < 5)
2524  t = TCFrontEnd::innerInside;
2525  else
2526  t = TCFrontEnd::innerOutside;
2527  } else {
2528  if (_wires[wid]->localLayerId() < 3)
2529  t = TCFrontEnd::outerInside;
2530  else
2531  t = TCFrontEnd::outerOutside;
2532  }
2533  f = new TCFrontEnd(name, t, _clock, _clockD, _clockUser3125);
2534 
2535  _fronts.push_back(f);
2536  }
2537  f->push_back(_wires[wid]);
2538 
2539  //...Make a merger board if necessary... 2013,0908: physjg: I
2540  // think this should be done only when a new frontboard is
2541  // created. i.e., inlcuded in the if(!f) { .... } block.
2542  // Or I can put this part inside the new FrontEnd creation
2543  // part, well, seems not good in coding
2544  //
2545  bool newMerger = false;
2546  TCMerger* m = 0;
2547  if (newFrontEnd) {
2548  if (mid != 99999) {
2549  if (mid < _mergers.size())
2550  m = _mergers[mid];
2551  if (! m) {
2552  newMerger = true;
2553  const string name = "CDCMerger" + TRGUtil::itostring(sl) +
2554  "-" + TRGUtil::itostring(lastMergerLocalId);
2555  TCMerger::unitType mt = TCMerger::unknown;
2556  if (sl == 0)
2557  mt = TCMerger::innerType;
2558  else
2559  mt = TCMerger::outerType;
2560  m = new TCMerger(name,
2561  mt,
2562  _clock,
2563  _clockD,
2565  _clockUser6250);
2566  _mergers.push_back(m);
2567  ++lastMergerLocalId;
2568  lastSl = sl;
2569  //cout << "new merger : " << name << endl;
2570  }
2571  m->push_back(f);
2572  }
2573 
2574  //...Make Aurora channel...
2575  if (f && m) {
2576  const string n = f->name() + string("-") + m->name();
2577  TRGChannel* ch = new TRGChannel(n, *f, *m);
2578  f->appendOutput(ch);
2579  m->appendInput(ch);
2580  }
2581  }
2582 
2583  //...Make a TSF board if necessary...
2584  if (newMerger) {
2585  TSFinder* t = 0;
2586  if (tid != 99999) {
2587  if (tid < _tsfboards.size())
2588  t = _tsfboards[tid];
2589  if (!t) {
2590  const string name = "CDCTSFBoard" + TRGUtil::itostring(tid);
2591  TSFinder::boardType tt = TSFinder::unknown;
2592  if (_wires[wid]->superLayerId() == 0)
2593  tt = TSFinder::innerType;
2594  else
2595  tt = TSFinder::outerType;
2596  t = new TSFinder(*this,
2597  name,
2598  tt,
2599  _clock,
2600  _clockD,
2603  _tsSL[tid]);
2604  _tsfboards.push_back(t);
2605  }
2606  t->push_back(m);
2607  }
2608 
2609  if (m && t) {
2610  const string n = m->name() + string("-") + t->name();
2611  TRGChannel* chmt = new TRGChannel(n, *m, *t);
2612  m->appendOutput(chmt);
2613  t->appendInput(chmt);
2614  }
2615  }
2616 
2617  ++lines;
2618  }
2619  infile.close();
2620 
2621  //...Make a 2D finder...
2622  for (unsigned i = 0; i < 4; i++) {
2623  const string name = "CDC2DBoard" + TRGUtil::itostring(i);
2624  TCTracker2D* t = new TCTracker2D(name,
2625  _clock,
2626  _clockD,
2628  _clockUser6250);
2629  _tracker2Ds.push_back(t);
2630  for (unsigned j = 0; j < 9; j++) {
2631  TCTSFinder* tsf = _tsfboards[j];
2632  const string n = tsf->name() + string("-") + t->name();
2633  TRGChannel* ch = new TRGChannel(n, *tsf, *t);
2634  tsf->appendOutput(ch);
2635  t->appendInput(ch);
2636  }
2637  const string n = t->name() + string("-") + "CDC3DBoard" + TRGUtil::itostring(i);
2638  TRGChannel* ch = new TRGChannel(n, *t, *t);
2639  // last (* t) should be 3D tracker in future
2640  t->appendOutput(ch);
2641  }
2642 
2643  //...For debug...
2644  if (TRGDebug::level()) {
2645  cout << TRGDebug::tab() << "TSF configuration" << endl;
2646  for (unsigned i = 0; i < _tsfboards.size(); i++) {
2647  const TSFinder& t = *_tsfboards[i];
2648  t.dump("detail", TRGDebug::tab() + " ");
2649  }
2650  cout << TRGDebug::tab() << "Tracker2D configuration" << endl;
2651  for (unsigned i = 0; i < _tracker2Ds.size(); i++) {
2652  const TCTracker2D& t = *_tracker2Ds[i];
2653  t.dump("detail", TRGDebug::tab() + " ");
2654  }
2655  }
2656 
2657  TRGDebug::leaveStage("TRGCDC configure");
2658  }
2659 
2660  const TRGCDCSegment&
2661  TRGCDC::segment(unsigned lid, unsigned id) const
2662  {
2663  return *(const TRGCDCSegment*)(* _tsLayers[lid])[id];
2664  }
2665 
2666 //jb void
2667 //jb TRGCDC::perfect3DFinder(vector<TCTrack*> trackList) const {
2668 //jb
2669 //jb TRGDebug::enterStage("Perfect 3D Finder");
2670 //jb if (TRGDebug::level())
2671 //jb cout << TRGDebug::tab() << "givenTrk#=" << trackList.size() << endl;
2672 //jb
2673 //jb //...Track loop....
2674 //jb for (unsigned j = 0; j < trackList.size(); j++) {
2675 //jb
2676 //jb //...G4 trackID...
2677 //jb TCTrack * trk = trackList[j];
2678 //jb unsigned id = trackList[j]->relation().contributor(0);
2679 //jb vector<const TCSHit*> tsList[9];
2680 //jb
2681 //jb //...Segment loop...
2682 //jb const vector<const TCSHit*> hits = segmentHits();
2683 //jb for (unsigned i = 0; i < hits.size(); i++) {
2684 //jb const TCSHit & ts = * hits[i];
2685 //jb if (ts.segment().axial()) continue;
2686 //jb if (! ts.signal().active()) continue;
2687 //jb const TCWHit * wh = ts.segment().center().hit();
2688 //jb if (! wh) continue;
2689 //jb const unsigned trackId = wh->iMCParticle();
2690 //jb
2691 //jb if (id == trackId)
2692 //jb tsList[wh->wire().superLayerId()].push_back(& ts);
2693 //jb }
2694 //jb
2695 //jb if (TRGDebug::level()) {
2696 //jb cout << TRGDebug::tab() << "trk#" << j << endl;
2697 //jb for (unsigned k = 0; k < 9; k++) {
2698 //jb if (k % 2) {
2699 //jb cout << TRGDebug::tab(4) << "superlayer " << k << ":";
2700 //jb for (unsigned l = 0; l < tsList[k].size(); l++) {
2701 //jb if (l)
2702 //jb cout << ",";
2703 //jb cout << tsList[k][l]->cell().name();
2704 //jb }
2705 //jb cout << endl;
2706 //jb }
2707 //jb }
2708 //jb }
2709 //jb
2710 //jb //...Select best one in each super layer...
2711 //jb for (unsigned i = 0; i < 9; i++) {
2712 //jb const TCSHit * best = 0;
2713 //jb if (tsList[i].size() == 0) {
2714 //jb continue;
2715 //jb } else if (tsList[i].size() == 1) {
2716 //jb best = tsList[i][0];
2717 //jb } else {
2718 //jb int timeMin = 99999;
2719 //jb for (unsigned k = 0; k < tsList[i].size(); k++) {
2720 //jb const TRGSignal & signal = tsList[i][k]->signal();
2721 //jb const TRGTime & t = * signal[0];
2722 //jb if (t.time() < timeMin) {
2723 //jb timeMin = t.time();
2724 //jb best = tsList[i][k];
2725 //jb }
2726 //jb }
2727 //jb }
2728 //jb //trk->append(new TCLink(0,
2729 //jb // best,
2730 //jb // best->cell().xyPosition()));
2731 //jb }
2732 //jb
2733 //jb if (TRGDebug::level())
2734 //jb trk->dump("", "> ");
2735 //jb
2736 //jb }
2737 //jb
2738 //jb TRGDebug::leaveStage("Perfect 3D Finder");
2739 //jb }
2740 
2741  int TRGCDC::getEventTime(void) const
2742  {
2743  return _eventTime.back()->getT0();
2744  }
2745 
2746  void TRGCDC::setReturnValue(EReturnValueType const& moduleName, bool flag)
2747  {
2748  if (flag) _returnValue |= moduleName;
2749  else _returnValue &= ~moduleName;
2750  }
2751 
2752  int TRGCDC::getReturnValue(EReturnValueType const& moduleName) const
2753  {
2754  return _returnValue & moduleName;
2755  }
2756 
2757 
2758  void TRGCDC::saveCDCHitInformation(vector<vector<unsigned>>& hitWiresFromCDC)
2759  {
2760  TClonesArray& rootCDCHitInformation = *m_rootCDCHitInformation;
2761  rootCDCHitInformation.Clear();
2762  for (unsigned iHit = 0; iHit < hitWiresFromCDC.size(); iHit++) {
2763  TVectorD t_rootCDCHitInformation(5);
2764  t_rootCDCHitInformation[0] = hitWiresFromCDC[iHit][0];
2765  t_rootCDCHitInformation[1] = hitWiresFromCDC[iHit][1];
2766  t_rootCDCHitInformation[2] = hitWiresFromCDC[iHit][2];
2767  t_rootCDCHitInformation[3] = hitWiresFromCDC[iHit][3];
2768  t_rootCDCHitInformation[4] = hitWiresFromCDC[iHit][4];
2769  new(rootCDCHitInformation[iHit]) TVectorD(t_rootCDCHitInformation);
2770  } // End of hit loop
2771  }
2772 
2773  void TRGCDC::saveTRGHitInformation(vector<vector<int>>& hitWiresFromTRG)
2774  {
2775  TClonesArray& rootTRGHitInformation = *m_rootTRGHitInformation;
2776  rootTRGHitInformation.Clear();
2777  for (unsigned iHit = 0; iHit < hitWiresFromTRG.size(); iHit++) {
2778  TVectorD t_rootTRGHitInformation(4);
2779  t_rootTRGHitInformation[0] = hitWiresFromTRG[iHit][0];
2780  t_rootTRGHitInformation[1] = hitWiresFromTRG[iHit][1];
2781  t_rootTRGHitInformation[2] = hitWiresFromTRG[iHit][2];
2782  t_rootTRGHitInformation[3] = hitWiresFromTRG[iHit][3];
2783  new(rootTRGHitInformation[iHit]) TVectorD(t_rootTRGHitInformation);
2784  } // End of hit loop
2785  }
2786 
2787  void TRGCDC::saveTRGRawInformation(vector<string >& trgInformations)
2788  {
2789  TClonesArray& rootTRGRawInformation = *m_rootTRGRawInformation;
2790  rootTRGRawInformation.Clear();
2791  for (unsigned iWindow = 0; iWindow < trgInformations.size(); iWindow++) {
2792  TObjString t_rootTRGRawInformation;
2793  t_rootTRGRawInformation.SetString(trgInformations[iWindow].c_str());
2794  new(rootTRGRawInformation[iWindow]) TObjString(t_rootTRGRawInformation);
2795  } // End of hit loop
2796  }
2797 
2798 //void TRGCDC::saveCDCTRGTimeMatchInformation(vector<vector<map<int, int> > >& hitTimingComp) {
2799 //
2800 // TClonesArray& CDCTRGTimeMatch = *m_CDCTRGTimeMatch;
2801 // CDCTRGTimeMatch.Clear();
2802 // int nTotalHits = 0;
2803 // for(unsigned iLayer=0; iLayer<5; iLayer++){
2804 // for(unsigned iWire=0; iWire<16; iWire++){
2805 // for(map<int, int>::iterator it = hitTimingComp[iLayer][iWire].begin(); it != hitTimingComp[iLayer][iWire].end(); it++){
2806 // TVectorD t_CDCTRGTimeMatch(4);
2807 // t_CDCTRGTimeMatch[0] = iLayer;
2808 // t_CDCTRGTimeMatch[1] = iWire;
2809 // t_CDCTRGTimeMatch[2] = (*it).first;
2810 // t_CDCTRGTimeMatch[3] = (*it).second;
2811 // new(CDCTRGTimeMatch[nTotalHits++]) TVectorD(t_CDCTRGTimeMatch);
2812 // }
2813 // } // End of wire loop
2814 // } // End of layer loop
2815 //
2816 //}
2817 
2818  unsigned
2819  TRGCDC::nSegments(unsigned id) const
2820  {
2821  if (id < _tsLayers.size())
2822  return _tsLayers[id]->size();
2823  return 0;
2824  }
2825 
2827 } // namespace Belle2
Class containing the result of the unpacker in raw data and the result of the digitizer in simulation...
Definition: CDCHit.h:40
Combination of several CDCHits to a track segment hit for the trigger.
This class is the interface between TSim/basf2 TSF module and the firmware simulation core of XSim/IS...
Track created by the CDC trigger.
const TVector3 wireBackwardPosition(int layerId, int cellId, EWirePosition set=c_Base) const
Returns the backward position of the input sense wire.
int nShifts(int layerId) const
Returns number shift.
const TVector3 wireForwardPosition(int layerId, int cellId, EWirePosition set=c_Base) const
Returns the forward position of the input sense wire.
double fieldWireR(int layerId) const
Returns radius of field wire in each layer.
double getTdcBinWidth() const
Return TDC bin width (nsec).
float getT0(const WireID &wireID) const
Returns t0 parameter of the specified sense wire.
unsigned nWiresInLayer(int layerId) const
Returns wire numbers in a layer.
double getNominalDriftV() const
Return the nominal drift velocity of He-ethane gas (default: 4.0x10^-3 cm/nsec).
static CDCGeometryPar & Instance(const CDCGeometry *=nullptr)
Static method to get a reference to the CDCGeometryPar instance.
unsigned nWireLayers() const
Returns a number of wire layers.
double senseWireR(int layerId) const
Returns radius of sense wire in each layer.
double zOffsetWireLayer(unsigned i) const
Returns the offset of z of the wire layer i.
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32
TVector3 getVertex() const
Return production vertex position, shorthand for getProductionVertex().
Definition: MCParticle.h:183
TVector3 getMomentum() const
Return momentum.
Definition: MCParticle.h:198
float getCharge() const
Return the particle charge defined in TDatabasePDG.
Definition: MCParticle.cc:34
TLorentzVector get4Vector() const
Return 4Vector of particle.
Definition: MCParticle.h:207
The Raw COPPER class This class stores data received by COPPER via belle2linkt Data from all detector...
Definition: RawCOPPER.h:52
void SetBuffer(int *bufin, int nwords, int delete_flag, int num_events, int num_nodes) OVERRIDE_CPP17
set buffer ( delete_flag : m_buffer is freeed( = 0 )/ not freeed( = 1 ) in Destructer )
Definition: RawCOPPER.cc:141
virtual int * GetBuffer(int n)
get nth buffer pointer
Definition: RawDataBlock.h:53
Low-level class to create/modify relations between StoreArrays.
Definition: RelationArray.h:62
int getEntries() const
Get the number of elements.
Class for type safe access to objects that are referred to in relations.
size_t size() const
Get number of relations.
float weight(int index) const
Get weight with index.
void addRelationTo(const RelationsInterface< BASE > *object, float weight=1.0, const std::string &namedRelation="") const
Add a relation from this object to another object (with caching).
RelationVector< FROM > getRelationsFrom(const std::string &name="", const std::string &namedRelation="") const
Get the relations that point from another store array to this object.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:246
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:95
bool construct(Args &&... params)
Construct an object of type T in this StoreObjPtr, using the provided constructor arguments.
Definition: StoreObjPtr.h:118
void doit(std::vector< TRGCDCTrack * > const &trackList2D, std::vector< TRGCDCTrack * > &trackList3D)
Member functions.
A class to represent a cell layer.
Definition: Layer.h:33
A class to represent a wire in CDC.
Definition: Segment.h:39
int priorityPosition(void) const
return priority cell position in TSHit. 0: no hit, 3: 1st priority, 1: 2nd right, 2: 2nd left
float fastestTime(void) const
return fastest time in TSHit.
float priorityTime(void) const
return priority time in TSHit.
float foundTime(void) const
return found time in TSHit.
const TRGCDCWire & priority(void) const
returns priority wire.
A class to represent a wire in CDC.
Definition: Wire.h:56
The instance of TRGCDC is a singleton.
Definition: TRGCDC.h:69
TClonesArray * m_fitParameters
3D fit
Definition: TRGCDC.h:747
bool _fileFitter3D
Switch for Fitter3D.root file.
Definition: TRGCDC.h:602
std::vector< TRGCDCTrack * > _trackList3D
Track list for 3D fitted tracks.
Definition: TRGCDC.h:542
float * _r
R of cell.
Definition: TRGCDC.h:668
std::vector< TRGCDCTracker2D * > _tracker2Ds
CDC 2D finder boards.
Definition: TRGCDC.h:708
bool _fFitter3Ds2DFitDrift
Switch to us wire 2D fit or drift 2D fit.
Definition: TRGCDC.h:578
int _firmwareSimulationStopDataClock
Firmware simulation stop clock in CDCTRG data clock.
Definition: TRGCDC.h:530
std::vector< TRGCDCWireHit * > _axialHits
CDC hits on axial wires.
Definition: TRGCDC.h:635
bool _fFitter3Ds2DFit
Switch to us 2D fit or Hough finder results.
Definition: TRGCDC.h:575
unsigned _simulationMode
Simulation mode.
Definition: TRGCDC.h:502
TClonesArray * m_rootTRGRawInformation
[0]: iLayer, [1]: iWire, [2]: Timing(CDC), [3]: MatchNumber MatchNumber: 1: Only CDC,...
Definition: TRGCDC.h:788
std::string _configFilename
CDC trigger configuration filename.
Definition: TRGCDC.h:499
TTree * m_tree
root tree for reconstructed 3D tracks
Definition: TRGCDC.h:738
std::vector< std::vector< TRGCDCLayer * > * > _superLayers
Super layers.
Definition: TRGCDC.h:608
unsigned _fastSimulationMode
Fast simulation mode.
Definition: TRGCDC.h:505
TTree * m_treeAllTracks
root tree for MC tracks
Definition: TRGCDC.h:741
std::vector< TRGCDCWire * > _hitWires
Wires with a hit.
Definition: TRGCDC.h:629
std::vector< TRGCDCSegment * > _tsSL[9]
Track Segments.
Definition: TRGCDC.h:650
int _trgCDCDataInputMode
Switch for TRG CDC input mode.
Definition: TRGCDC.h:768
std::string _cdchitCollectionName
name of the CDCHit DataStore array used as input
Definition: TRGCDC.h:771
int _debugLevel
Debug level.
Definition: TRGCDC.h:493
std::vector< TRGCDCTrack * > _trackList2DFitted
Track list for 2D fitted tracks.
Definition: TRGCDC.h:539
int _finder3DMode
Sets mode of 3DFinder.
Definition: TRGCDC.h:599
std::vector< TRGCDCTrackSegmentFinder * > _tsfboards
CDC trigger tsf boards.
Definition: TRGCDC.h:705
bool _fXtSimpleFitter3D
Switch for using simple x-t curve or non-linear x-t curve. 0: non-linear 1: simple.
Definition: TRGCDC.h:605
TClonesArray * m_mcParameters
MC.
Definition: TRGCDC.h:750
float * _width
Cell width in radian.
Definition: TRGCDC.h:665
std::string _outerTSLUTFilename
The filename of LUT for outer track segments.
Definition: TRGCDC.h:557
std::string _innerTSLUTFilename
The filename of LUT for the inner-most track segments.
Definition: TRGCDC.h:554
bool _fLogicLUTTSF
Switch for logic or LUT TSF.
Definition: TRGCDC.h:566
int _fverETF
Switch for selecting ETF version.
Definition: TRGCDC.h:590
std::vector< TRGCDCWireHitMC * > _hitsMC
MC info. of CDC hits.
Definition: TRGCDC.h:644
TClonesArray * m_mcTrackVertexVector
MC vertex.
Definition: TRGCDC.h:756
std::vector< TRGCDCSegment * > _tss
Track Segments.
Definition: TRGCDC.h:647
const bool _perfect2DFinder
Switch to activate perfect 2D finder.
Definition: TRGCDC.h:548
bool _fileHough3D
Switch for Hough3D.root file.
Definition: TRGCDC.h:596
std::vector< TRGCDCLayer * > _stereoLayers
Stereo layers.
Definition: TRGCDC.h:623
const TRGClock _clockD
CDC trigger data clock.
Definition: TRGCDC.h:684
bool _fileTSF
Switch for TSF.root file.
Definition: TRGCDC.h:584
bool _fileETF
Switch for ETF.root file.
Definition: TRGCDC.h:587
std::vector< std::vector< TRGCDCLayer * > * > _stereoSuperLayers
Stereo super layers.
Definition: TRGCDC.h:614
std::string _rootTRGCDCFilename
The filename of root file for TRGCDC.
Definition: TRGCDC.h:560
std::vector< TRGCDCSegmentHit * > _segmentHits
Track Segments with hits.
Definition: TRGCDC.h:656
std::vector< TRGCDCLayer * > _tsLayers
Track Segment layers.
Definition: TRGCDC.h:653
TTree * m_treeROOTInput
Debugging members for firmware ROOT input.
Definition: TRGCDC.h:779
std::vector< TRGCDCWireHit * > _badHits
Bad CDC hits.(not used now)
Definition: TRGCDC.h:641
bool _makeRootFile
Switch for TRGCDC.root file.
Definition: TRGCDC.h:545
EReturnValueType
Enum for returnValue types.
Definition: TRGCDC.h:74
int _returnValue
Return value for trg cdc module;.
Definition: TRGCDC.h:533
std::vector< TRGCDCTrack * > _trackList2D
Track list by 2D finding.
Definition: TRGCDC.h:536
bool _fprintFirmETF
Switch for printing Firmware inputs for ETF.
Definition: TRGCDC.h:593
TRGCDCHoughFinder * _hFinder
Hough finder.
Definition: TRGCDC.h:720
TRGCDCTrackSegmentFinder * _tsFinder
Track Segement Finder.
Definition: TRGCDC.h:711
std::vector< TRGCDCEventTime * > _eventTime
EventTime.
Definition: TRGCDC.h:729
TClonesArray * m_mcTrack4Vector
MC track.
Definition: TRGCDC.h:753
TRGSignal _firmwareSimulationWindow
Firmware simulation time window in FE.
Definition: TRGCDC.h:524
std::vector< TRGCDCWire * > _wires
All wires.
Definition: TRGCDC.h:626
TClonesArray * m_rootTRGHitInformation
[0]: iLayer, [1]: iWire, [2]: window number, [3]: priority timing
Definition: TRGCDC.h:783
std::vector< TRGCDCLayer * > _layers
All layers.
Definition: TRGCDC.h:617
const TRGClock _clock
CDC trigger system clock.
Definition: TRGCDC.h:674
TClonesArray * m_mcTrackStatus
MC track status.
Definition: TRGCDC.h:759
double _inefficiency
Hit inefficiency parameter.
Definition: TRGCDC.h:581
TClonesArray * m_evtTime
Event time.
Definition: TRGCDC.h:762
TFile * m_file
root file
Definition: TRGCDC.h:735
TRGCDCFitter3D * _fitter3D
3D fitter.
Definition: TRGCDC.h:726
std::vector< TRGCDCFrontEnd * > _fronts
CDC front-end boards.
Definition: TRGCDC.h:699
float * _r2
R^2 of cell.
Definition: TRGCDC.h:671
std::vector< TRGCDCSegmentHit * > _segmentHitsSL[9]
Track Segments with hits in each super layer.
Definition: TRGCDC.h:659
std::vector< TRGCDCWireHit * > _stereoHits
CDC hits on stereo wires.
Definition: TRGCDC.h:638
int _firmwareSimulationStop
Fimrware simulation stop clock in FE.
Definition: TRGCDC.h:521
int _firmwareSimulationStart
Fimrware simulation start clock in FE.
Definition: TRGCDC.h:518
TRGCDCPerfectFinder * _pFinder
Perfect 2D finder.
Definition: TRGCDC.h:714
std::vector< std::vector< TRGCDCLayer * > * > _axialSuperLayers
Axial super layers.
Definition: TRGCDC.h:611
TClonesArray * _tracks2D
2D track information
Definition: TRGCDC.h:765
std::vector< TRGCDCLayer * > _axialLayers
Axial layers.
Definition: TRGCDC.h:620
TRGCDCPerfectFinder * _p3DFinder
Perfect 3D finder.
Definition: TRGCDC.h:717
CDC::CDCGeometryPar * m_cdcp
returns a pointer to CDCGeometryPar
Definition: TRGCDC.h:252
TRGCDCHough3DFinder * _h3DFinder
Hough 3D finder.
Definition: TRGCDC.h:723
const TRGClock _clockUser3125
CDC trigger user clock for Aurora 3.125 Gbps.
Definition: TRGCDC.h:687
std::vector< TRGCDCWireHit * > _hits
CDC hits.
Definition: TRGCDC.h:632
const TRGClock _clockFE
CDC front end clock. Resolution is CDC TdcBinWidth.
Definition: TRGCDC.h:677
std::string _rootFitter3DFilename
The filename of root file for Fitter3D.
Definition: TRGCDC.h:563
bool _fFitter3Dsmclr
Switch for MC L/R information in Fitter3D.
Definition: TRGCDC.h:572
std::vector< TRGCDCMerger * > _mergers
CDC trigger merger boards.
Definition: TRGCDC.h:702
bool _fLRLUT
Switch for the LR LUT in Fitter3D.
Definition: TRGCDC.h:569
const TRGClock _clockUser6250
CDC trigger user clock for Aurora 6.250 Gbps.
Definition: TRGCDC.h:690
TTree * _tree2D
root tree for 2D tracks
Definition: TRGCDC.h:744
const TRGClock _clockTDC
CDC trigger TDC clock.
Definition: TRGCDC.h:681
int _firmwareSimulationStartDataClock
Firmware simulation start clock in CDCTRG data clock.
Definition: TRGCDC.h:527
TClonesArray * m_rootCDCHitInformation
[0]: iLayer, [1]: iWire, [2]: CDCADC, [3]: CDCTDC, [4]: CDC FE TRG timing
Definition: TRGCDC.h:781
A class to represent a serial link between trigger hardware modules.
Definition: Channel.h:24
A class to represent a digitized signal. Unit is nano second.
Definition: Clock.h:38
A class to represent a bundle of SignalVectors.
Definition: SignalBundle.h:26
A class to represent a bundle of digitized signals.
Definition: SignalVector.h:26
A class to represent a digitized signal. Unit is nano second.
Definition: Signal.h:23
A class to represent a state of multi bits.
Definition: State.h:24
A class to represent a signal timing in the trigger system.
Definition: Time.h:25
static std::string itostring(int i)
converts int to string. (Use boost::lexical_cast)
Class to identify a wire inside the CDC.
Definition: WireID.h:34
static void findImpactPosition(TVector3 *mcPosition, TLorentzVector *mcMomentum, int charge, TVector2 &helixCenter, TVector3 &impactPosition)
MC calculation functions Calculates the impact position of track.
int GetDetectorNwords(int n, int finesse_num)
get Detector buffer length
Definition: RawCOPPER.h:654
int * GetDetectorBuffer(int n, int finesse_num)
get Detector buffer
Definition: RawCOPPER.h:678
std::vector< const TRGCDCSegmentHit * > segmentHits(void) const
returns a list of TRGCDCSegmentHit.
Definition: TRGCDC.h:996
unsigned nAxialLayers(void) const
return # of axial layers.
Definition: TRGCDC.h:884
unsigned size(void) const
returns bit size.
Definition: State.h:149
unsigned localId(unsigned wireId) const
returns local ID in a layer. This function is expensive.
Definition: TRGCDC.cc:1771
void configure(void)
configures trigger modules for firmware simulation.
Definition: TRGCDC.cc:2448
static std::string tab(void)
returns tab spaces.
Definition: Debug.cc:47
const TRGSignalVector & set(const TRGState &, int clockPosition)
sets state at given clock.
static TRGCDC * getTRGCDC(void)
returns TRGCDC object.
Definition: TRGCDC.cc:190
void setReturnValue(EReturnValueType const &moduleName, bool flag)
sets return value for trg cdc module.
Definition: TRGCDC.cc:2746
unsigned layerId(unsigned wireId) const
returns layer ID. This function is expensive.
Definition: TRGCDC.cc:1791
std::string name(void) const
simulates track segment decisions.
Definition: TRGCDC.cc:90
void initialize()
Initialization.
Definition: Fitter3D.cc:75
unsigned localLayerId(unsigned wireId) const
returns local layer ID in a super layer. This function is expensive.
Definition: TRGCDC.cc:1840
void fastClear(void)
clears TRGCDC information.
Definition: TRGCDC.cc:979
double absoluteTime(int clockPosition) const
returns absolute time of clock position
Definition: Clock.cc:128
std::string wireName(unsigned wireId) const
returns wire name.
Definition: TRGCDC.cc:1757
int FindAndFit(std::vector< TRGCDCTrack * > &trackList2D, std::vector< TRGCDCTrack * > &trackList2DFitted)
do track finding and fitting (wrapper that can choose between different versions).
Definition: HoughFinder.cc:755
TRGState subset(unsigned i, unsigned n) const
returns subset from i with n bits.
Definition: State.cc:356
unsigned id(void) const
returns id.
Definition: Cell.h:197
int doit(std::vector< TRGCDCTrack * > &trackList)
Does track fitting.
Definition: Fitter3D.cc:210
const TRGClock & clock(void) const
returns clock.
Definition: Time.h:149
int doit(std::vector< TRGCDCTrack * > &trackListClone, std::vector< TRGCDCTrack * > &trackList)
do track finding.
unsigned localLayerId(void) const
returns local layer id in a super layer.
Definition: Layer.h:170
void terminate(void)
terminates when run is finished
Definition: TRGCDC.cc:737
TRGTime & reverse(void)
reverse edge.
Definition: Time.h:141
int getValue(unsigned) const
get LUT Values
Definition: LUT.cc:47
const std::string & name(void) const
returns name.
Definition: Signal.h:188
static void enterStage(const std::string &stageName)
Declare that you enter new stage.
Definition: Debug.cc:24
bool neighbor(const TRGCDCWire &w0, const TRGCDCWire &w1) const
returns true if w0 and w1 are neighbor.
Definition: TRGCDC.cc:2028
unsigned superLayerId(void) const
returns super layer id.
Definition: Layer.h:163
virtual ~TRGCDC()
Destructor.
Definition: TRGCDC.cc:2001
void saveTRGHitInformation(std::vector< std::vector< int > > &)
Save functions for ROOT.
Definition: TRGCDC.cc:2773
void terminate()
Termination.
Definition: Fitter3D.cc:1527
const std::string stereoType(void) const
returns "A" or "U" or "V" depending on stereo type.
Definition: Layer.h:235
const TRGSignal & signal(void) const override
returns an input to the trigger. This is sync'ed to 1GHz clock.
Definition: Wire.h:226
unsigned nAxialSuperLayers(void) const
return # of axial super layers.
Definition: TRGCDC.h:891
unsigned axialStereoSuperLayerId(void) const
returns id of axial or stereo super layer id.
Definition: Layer.h:221
const TRGState & set(unsigned position, bool state=true)
sets state at bit i.
Definition: State.h:305
std::vector< const TRGCDCWireHitMC * > hitsMC(void) const
returns a list of TRGCDCWireHitMC.
Definition: TRGCDC.cc:1749
const TRGClock & dataClock(void) const
returns the data clock.
Definition: TRGCDC.h:982
unsigned nSegments(void) const
returns # of track segments.
Definition: TRGCDC.h:954
TRGTime & shift(int unit)
delays by clock unit.
Definition: Time.h:163
const TRGCDCWireHit * hit(void) const
returns a pointer to a TRGCDCWireHit.
Definition: Wire.h:144
unsigned axialStereoSuperLayerId(unsigned axialStereo, unsigned axialStereoLayerId) const
returns axialStereo super layer ID. This function is expensive.
Definition: TRGCDC.cc:1863
unsigned nSuperLayers(void) const
returns # of super layers.
Definition: TRGCDC.h:870
unsigned nStereoLayers(void) const
returns # of stereo layers.
Definition: TRGCDC.h:877
void initialize(void)
initilize variables.
Definition: Segment.cc:65
unsigned lutPattern(void) const
hit pattern containing bit for priority position
Definition: Segment.cc:559
std::string versionCDC(void) const
returns CDC version.
Definition: TRGCDC.h:856
void initialize(unsigned houghFinderPeakMin, const std::string &houghMappingFilePlus, const std::string &houghMappingFileMinus, unsigned houghDoit)
initializes CDC geometry.
Definition: TRGCDC.cc:370
const TRGCDCSegment & segment(unsigned id) const
returns a track segment.
Definition: TRGCDC.h:933
void saveTRGRawInformation(std::vector< std::string > &)
Save functions for ROOT.
Definition: TRGCDC.cc:2787
const TRGCDCLUT * LUT(void) const
returns LUT
Definition: Segment.h:243
unsigned nLayers(void) const
return # of layers.
Definition: TRGCDC.h:905
int getEventTime(void) const
returns bad hits(finding invalid hits).
Definition: TRGCDC.cc:2741
const std::vector< TRGCDCLayer * > * superLayer(unsigned id) const
returns a pointer to a super-layer.
Definition: TRGCDC.h:835
void dump(const std::string &message) const
dumps debug information.
Definition: TRGCDC.cc:765
std::vector< const TRGCDCWireHit * > stereoHits(void) const
returns a list of stereo hits.
Definition: TRGCDC.cc:1690
const std::vector< const CDCTriggerSegmentHit * > storeHits(void) const
returns a pointer to a CDCTriggerSegmentHit.
Definition: Segment.h:236
unsigned iCDCHit(void) const
returns an index to CDCHit.
Definition: CellHit.h:360
std::vector< const TRGCDCWireHit * > axialHits(void) const
returns a list of axial hits.
Definition: TRGCDC.cc:1677
unsigned superLayerId(unsigned wireId) const
returns super layer ID. This function is expensive.
Definition: TRGCDC.cc:1818
void doit(std::vector< TRGCDCSegment * > &tss, const bool trackSegmentClockSimulation, std::vector< TRGCDCSegmentHit * > &segmentHits, std::vector< TRGCDCSegmentHit * > *segmentHitsSL)
Member functions of doing TSF.
static int level(void)
returns the debug level.
Definition: Debug.cc:67
unsigned axialStereoLayerId(void) const
returns id of axial or stereo id.
Definition: Layer.h:214
std::vector< const TRGCDCWireHit * > hits(void) const
returns a list of TRGCDCWireHit.
Definition: TRGCDC.cc:1703
int getReturnValue(void) const
gets return value for trg cdc module.
Definition: TRGCDC.h:1098
bool active(void) const
returns true if there is a signal.
Definition: Signal.h:277
const std::vector< const TRGCDCWire * > & wires(void) const
returns a vector containing pointers to a wire.
Definition: Segment.h:190
const TRGCDCLayer * layer(unsigned id) const
returns a pointer to a layer. 0 will be returned if 'id' is invalid.
Definition: TRGCDC.h:828
void update()
updates TRGCDC wire information. clear() is called in this function.
Definition: TRGCDC.cc:982
int position(double timing) const
returns clock position.
Definition: Clock.cc:114
static void leaveStage(const std::string &stageName)
Declare that you leave a stage.
Definition: Debug.cc:34
unsigned nCells(void) const
returns # of cells.
Definition: Layer.h:191
unsigned nStereoSuperLayers(void) const
returns # of stereo super layers.
Definition: TRGCDC.h:898
void fastSimulation(void)
Fast simulation.
Definition: TRGCDC.cc:2062
std::string version(void) const
returns version.
Definition: TRGCDC.cc:96
unsigned nWires(void) const
return # of wires.
Definition: TRGCDC.h:863
void simulate(void)
fast trigger simulation.
Definition: TRGCDC.cc:2047
void clear(void)
clears all TRGCDC hit information.
Definition: TRGCDC.cc:940
void saveCDCHitInformation(std::vector< std::vector< unsigned > > &)
Save functions for ROOT.
Definition: TRGCDC.cc:2758
void firmwareSimulation(void)
Firmware simulation.
Definition: TRGCDC.cc:2361
void classification(void)
classify hits.
Definition: TRGCDC.cc:1602
void updateByData(int inputMode)
updates TRGCDC wire information by Hardware data 0: From CDC FE ASCII file (Implementing) 1: From CDC...
Definition: TRGCDC.cc:1177
void storeSimulationResults(std::string collection2Dfinder, std::string collection2Dfitter, std::string collection3Dfitter)
Save results of fast simulation to data store (segment hits & tracks).
Definition: TRGCDC.cc:2246
void dump(const std::string &message="", const std::string &pre="") const
dumps contents.
Definition: Clock.cc:88
const TRGCDCWire * wire(unsigned wireId) const
returns a pointer to a wire.
Definition: TRGCDC.cc:890
Abstract base class for different kinds of events.