Belle II Software development
TRGCDCTrackSegmentSimulator.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 program to display TRGCDC components
11//-----------------------------------------------------------------------------
12
13#define TRG_SHORT_NAMES
14#define TRGCDC_SHORT_NAMES
15
16#define DEBUG_LEVEL 1
17#define PROGRAM_NAME "TRGCDCTrackSegmentSimulator"
18#define PROGRAM_VERSION "version 0.00"
19#define ENV_PATH "BELLE2_LOCAL_DIR"
20//#define CONFIG "TRGCDCWireConfig_0_20101110_0836.dat"
21#define CONFIG "TRGCDCConfig_0_20101111_1051_2013beamtest.dat"
22
23#include <iostream>
24#include <fstream>
25#include <string>
26#include "trg/trg/Debug.h"
27#include "trg/trg/Utilities.h"
28#include "trg/trg/State.h"
29#include "trg/trg/Channel.h"
30#include "trg/cdc/TRGCDC.h"
31#include "trg/cdc/Wire.h"
32#include "trg/cdc/Segment.h"
33#include "trg/cdc/TrackSegmentFinder.h"
34#include "framework/gearbox/Gearbox.h"
35
36#ifdef TRGCDC_DISPLAY
37#include "trg/cdc/DisplayRphi.h"
38#include "trg/cdc/DisplayHough.h"
39namespace Belle2_TRGCDC {
40 Belle2::TRGCDCDisplayRphi* D = 0;
41}
42#endif
43
44using namespace std;
45using namespace Belle2;
46#ifdef TRGCDC_DISPLAY
47using namespace Belle2_TRGCDC;
48#endif
49
50void readFile(const string& filename,
51 TRGSignalBundle& isb,
52 TRGSignalBundle& osbe,
53 TRGSignalBundle& osbt);
54
55int
56main(int argc, char* argv[])
57{
58
59 cout << PROGRAM_NAME << " ... " << PROGRAM_VERSION << endl;
60 // const string tab = " ";
61
62 //...Arguments...
63 if (argc < 3) {
64 cout << PROGRAM_NAME << " needs 3 arguments" << endl;
65 return -1;
66 }
67 const unsigned dl = stoi(string(argv[1]));
68 const unsigned sl = stoi(string(argv[2]));
69 const string fn = string(argv[3]);
70
72
73 //...Gearbox...
74 const string path = getenv(ENV_PATH);
75 const string patht = path + "/data/trg/cdc/";
76 vector<std::string> backends;
77 backends.push_back("file:");
78 string filename = "geometry/Belle2.xml";
79 Gearbox& gearbox = Gearbox::getInstance();
80 gearbox.setBackends(backends);
81 gearbox.open(filename);
82
83 //...TRGCDC parameters...
84 const string configFile = patht + CONFIG;
85 const unsigned simulationMode = 3; // fast and firm
86 const unsigned fastSimulationMode = 0;
87 const unsigned firmwareSimulationMode = 0;
88 const int firmwareSimulationStart = 0;
89 const int firmwareSimulationStop = 32 * 32 - 1;
90 const unsigned makeRootFile = 0;
91 const bool perfect2DFinder = false;
92 const bool perfect3DFinder = false;
93 const string innerTSLUTFile = patht + "innerLUT_v2.2.coe";
94 const string outerTSLUTFile = patht + "outerLUT_v2.2.coe";
95 const string rootTRGCDCFile = "TRGCDC.root";
96 const string rootFitter3DFile = "Fitter3D.root";
97 const unsigned houghFinderPeakMin = 5;
98 const string houghMappingFilePlus = patht + "HoughMappingPlus20140807.dat";
99 const string houghMappingFileMinus = patht +
100 "HoughMappingMinus20140808.dat";
101 const unsigned houghDoit = 2;
102 const unsigned fLogicLUTTSF = 0;
103 const unsigned fLRLUT = 1;
104 const unsigned fevtTime = 1;
105 const unsigned fmclr = 0;
106 const double inefficiency = 0;
107 const unsigned fileTSF = 0;
108 const unsigned fileETF = 0;
109 const unsigned fverETF = 0;
110 const unsigned fprintFirmETF = 0;
111 const unsigned fileHough3D = 0;
112 const unsigned finder3DMode = 2;
113 const unsigned fileFitter3D = 0;
114 const unsigned trgCDCDataInputMode = 0;
115
116 //...TRGCDC...
117 TRGCDC* cdc = TRGCDC::getTRGCDC(configFile,
118 simulationMode,
119 fastSimulationMode,
120 firmwareSimulationMode,
121 firmwareSimulationStart,
122 firmwareSimulationStop,
123 makeRootFile,
124 perfect2DFinder,
125 perfect3DFinder,
126 innerTSLUTFile,
127 outerTSLUTFile,
128 rootTRGCDCFile,
129 rootFitter3DFile,
130 houghFinderPeakMin,
131 houghMappingFilePlus,
132 houghMappingFileMinus,
133 houghDoit,
134 fLogicLUTTSF,
135 fLRLUT,
136 fevtTime,
137 fmclr,
138 inefficiency,
139 fileTSF,
140 fileETF,
141 fverETF,
142 fprintFirmETF,
143 fileHough3D,
144 finder3DMode,
145 fileFitter3D,
146 trgCDCDataInputMode);
147
148 //...TSF board...
149 TRGCDCTrackSegmentFinder& tsfb = * cdc->tsfboard(sl);
150
151 //...Read input signal bundle...
152 const TRGClock& dc = TRGCDC::getTRGCDC()->dataClock();
153 TRGSignalBundle isb("mgr data from chipscope", dc);;
154 TRGSignalBundle osbt("output for trk form chipscope", dc);;
155 TRGSignalBundle osbe("output for evt from chipscope", dc);;
156 readFile(fn, isb, osbe, osbt);
157
158 //...Set input signal bundle...
159 const_cast<TRGChannel*>(tsfb.input(0))->signal(& isb);
160 TRGSignalVector dummy("mgr dummy data", dc, isb[0]->size());
161 TRGSignalBundle isbd("mgr dummy data", dc);;
162 isbd.push_back(& dummy);
163 for (unsigned i = 1; i < tsfb.nInput(); i++)
164 const_cast<TRGChannel*>(tsfb.input(i))->signal(& isbd);
165
166 //...Get output signal bundle...
167 tsfb.simulate2();
168 const TRGSignalBundle& osb = * tsfb.output(0)->signal();
169
170 //...Compare output...
171 osb.dump();
172 osbt.dump();
173
174#ifdef TRGCDC_DISPLAY
175 //...Display...
176 D->clear();
177 D->show();
178#endif
179
180 //...Termination...
181 cout << PROGRAM_NAME << " ... terminated" << endl;
182}
183
184void
185readFile(const string& fn,
186 TRGSignalBundle& isb,
187 TRGSignalBundle& osbe,
188 TRGSignalBundle& osbt)
189{
190
191 //...Open input file...
192 ifstream ifile(fn.c_str(), ios::in);
193 if (ifile.fail()) {
194 cout << PROGRAM_NAME << " !!! can not open file" << endl
195 << " " << fn << endl;
196 exit(-1);
197 }
198
199 //...Preparations...
200 const TRGClock& dc = TRGCDC::getTRGCDC()->dataClock();
201 const unsigned eSize = 625;
202 const unsigned tSize = 1054 - 625;
203 const unsigned mSize = 1309 - 1053 - 9;
204 TRGSignalVector* eOut = new TRGSignalVector("output for evt", dc, eSize);
205 TRGSignalVector* tOut = new TRGSignalVector("output for trk", dc, tSize);
206 TRGSignalVector* mIn = new TRGSignalVector("input from mgr", dc, mSize);
207
208 //...Read data...
209 char b[10000];
210 while (! ifile.eof()) {
211 ifile.getline(b, 10000);
212 string l(b);
213
214 if (l.size() == 0) continue;
215 if (b[0] == '#') continue;
216 if (b[0] == 'S') continue;
217
218 // string clock = TRGUtil::carstring(l);
219 l = TRGUtil::cdrstring(l);
220 // const string g = TRGUtil::carstring(l);
221 l = TRGUtil::cdrstring(l);
222 const string dat = TRGUtil::carstring(l);
223 l = TRGUtil::cdrstring(l);
224
225 //...Divide data...
226 TRGState a(dat.c_str(), 0);
227 TRGState e = a.subset(0, eSize);
228 TRGState t = a.subset(eSize, tSize);
229 TRGState m = a.subset(1054, mSize);
230 TRGState c = a.subset(1054 + mSize, 9);
231 unsigned cMgr = unsigned(c);
232
233 eOut->set(e, cMgr);
234 tOut->set(t, cMgr);
235 mIn->set(m, cMgr);
236
237 // cout << "clock=" << clock << ",dat:size=" << a.size() << ",e:size="
238 // << e.size() << ",t:size=" << t.size() << ",m:size=" << m.size()
239 // << endl;
240 }
241
242 isb.push_back(mIn);
243 osbe.push_back(eOut);
244 osbt.push_back(tOut);
245}
Singleton class responsible for loading detector parameters from an XML file.
Definition: Gearbox.h:34
a class of TrackSegmentFinder in TRGCDC
The instance of TRGCDC is a singleton.
Definition: TRGCDC.h:69
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 state of multi bits.
Definition: State.h:24
static Gearbox & getInstance()
Return reference to the Gearbox instance.
Definition: Gearbox.cc:81
const TRGSignalVector & set(const TRGState &, int clockPosition)
sets state at given clock.
static TRGCDC * getTRGCDC(void)
returns TRGCDC object.
Definition: TRGCDC.cc:192
const TRGChannel * input(unsigned i) const
returns input channel i.
Definition: Board.h:158
unsigned nInput(void) const
returns input channels.
Definition: Board.h:172
const TRGClock & dataClock(void) const
returns the data clock.
Definition: TRGCDC.h:982
TRGSignalBundle * signal(void) const
returns signal.
Definition: Channel.h:93
void simulate2(void)
Firmware simulation. Unified version of inner and outer : yi.
static int level(void)
returns the debug level.
Definition: Debug.cc:67
TRGChannel * output(unsigned i) const
returns output channel i.
Definition: Board.h:165
void dump(const std::string &message="", const std::string &pre="") const
dumps contents.
Abstract base class for different kinds of events.
STL namespace.