Belle II Software development
Hough3DUtility.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#ifndef __CINT__
9#include "trg/cdc/Fitter3DUtility.h"
10#include "trg/cdc/Hough3DUtility.h"
11#include "trg/cdc/JSignal.h"
12#include "trg/cdc/JLUT.h"
13#include "trg/cdc/JSignalData.h"
14#include "trg/cdc/FpgaUtility.h"
15#include <cmath>
16#include <iostream>
17#include <tuple>
18#endif
19
20
21
22using namespace std;
23
25 m_mode(0), m_nWires(), m_rr(), m_ztostraw(), m_anglest(),
26 m_cotStart(0), m_cotEnd(0), m_z0Start(0), m_z0End(0),
27 m_nCotSteps(0), m_nZ0Steps(0), m_cotStepSize(0), m_z0StepSize(0),
28 m_houghMeshLayerDiff(0), m_houghMeshLayer(0), m_houghMesh(0), m_houghMeshDiff(0),
29 m_hitMap(0), m_driftMap(0), m_geoCandidatesIndex(0), m_geoCandidatesPhi(0),
30 m_geoCandidatesDiffStWires(0), m_stAxPhi(), m_bestCot(0), m_bestZ0(0),
31 m_houghMax(0), m_minDiffHough(0), m_foundZ(), m_foundPhiSt(), m_bestTSIndex(),
32 m_bestTS(), m_inputFileName("GeoFinder.input"), m_findRhoMax(0), m_findRhoMin(0),
33 m_findRhoIntMax(0), m_findRhoIntMin(0),
34 m_findPhi0Max(0), m_findPhi0Min(0), m_findPhi0IntMax(0), m_findPhi0IntMin(0),
35 m_findArcCosMax(0), m_findArcCosMin(0), m_findArcCosIntMax(0), m_findArcCosIntMin(0),
36 m_findPhiZMax(0), m_findPhiZMin(0), m_findPhiZIntMax(0), m_findPhiZIntMin(0),
37 m_rhoMax(0), m_rhoMin(0), m_rhoBit(0), m_phi0Max(0), m_phi0Min(0), m_phi0Bit(0),
38 m_stAxWireFactor(0), m_LUT(0),
39 m_arcCosLUT(0), m_wireConvertLUT(0),
40 m_commonData(0), m_outputVhdlDirname("./VHDL/finder3D")
41{
42 m_mode = 2;
43 m_outputLutDirname = m_outputVhdlDirname + "/" + "LutData";
44 // Make driftMap
45 m_driftMap = new int* [4];
46 for (int iSt = 0; iSt < 4; iSt++) {
47 m_driftMap[iSt] = new int[m_nWires[iSt] / 2];
48 for (int iTS = 0; iTS < m_nWires[iSt] / 2; iTS++) {
49 m_driftMap[iSt][iTS] = 0;
50 }
51 }
52}
53
55{
56 //destruct();
57}
58
60{
61 m_mode = mode;
62}
63
65{
66 return m_mode;
67}
68
69void Hough3DFinder::initialize(const TVectorD& geometryVariables, vector<float >& initVariables)
70{
71
72 m_findRhoMax = -9999;
73 m_findRhoIntMax = -9999;
74 m_findPhi0Max = -9999;
75 m_findPhi0IntMax = -9999;
76 m_findArcCosMax = -9999;
77 m_findArcCosIntMax = -9999;
78 m_findPhiZMax = -9999;
79 m_findPhiZIntMax = -9999;
80 m_findRhoMin = 9999;
81 m_findRhoIntMin = 9999;
82 m_findPhi0Min = 9999;
83 m_findPhi0IntMin = 9999;
84 m_findArcCosMin = 9999;
85 m_findArcCosIntMin = 9999;
86 m_findPhiZMin = 9999;
87 m_findPhiZIntMin = 9999;
88
89 for (int iLayer = 0; iLayer < 4; iLayer++) {
90 m_bestTS[iLayer] = 999;
91 m_bestTSIndex[iLayer] = 999;
92 }
93 for (int i = 0; i < 4; i++) {
94 m_rr[i] = geometryVariables[i];
95 m_anglest[i] = geometryVariables[i + 4];
96 m_ztostraw[i] = geometryVariables[i + 8];
97 m_nWires[i] = (int)geometryVariables[i + 12];
98 }
99 switch (m_mode) {
100 case 0:
101 break;
102 case 1:
103 initVersion1(initVariables);
104 break;
105 case 2:
106 initVersion2(initVariables);
107 break;
108 case 3:
109 initVersion3(initVariables);
110 break;
111 default:
112 cout << "[Error] 3DFinder mode is not correct. Current mode is " << m_mode << "." << endl;
113 break;
114 }
115}
116
118{
119 switch (m_mode) {
120 case 1:
121 destVersion1();
122 break;
123 case 2:
124 destVersion2();
125 break;
126 case 3:
127 destVersion3();
128 break;
129 default:
130 break;
131 }
132}
133
134void Hough3DFinder::runFinder(const std::vector<double>& trackVariables, vector<vector<double> >& stTSs,
135 const vector<vector<int> >& stTSDrift)
136{
137
138 // Clear best TS
139 for (int iLayer = 0; iLayer < 4; iLayer++) {
140 m_bestTS[iLayer] = 999;
141 m_bestTSIndex[iLayer] = 999;
142 }
143
144 // Set 2D parameters
145 int charge = (int)trackVariables[0];
146 double rho = trackVariables[1];
147 double fitPhi0 = trackVariables[2];
148
149 // Change TS candidates to arcS and z plane.
150 vector<double > tsArcS;
151 vector<vector<double> > tsZ;
152 for (unsigned i = 0; i < 4; i++) {
153 tsArcS.push_back(Fitter3DUtility::calS(rho, m_rr[i]));
154 tsZ.push_back(vector<double>());
155 for (unsigned j = 0; j < stTSs[i].size(); j++) {
156 //fitPhi0 = mcPhi0;
157 tsZ[i].push_back(Fitter3DUtility::calZ(charge, m_anglest[i], m_ztostraw[i], m_rr[i], stTSs[i][j], rho, fitPhi0));
158 }
159 }
160
161 switch (m_mode) {
162 // Hough 3D finder
163 case 1:
164 runFinderVersion1(trackVariables, stTSs, tsArcS, tsZ);
165 break;
166 // Geo Finder
167 case 2:
168 runFinderVersion2(trackVariables, stTSs, stTSDrift);
169 break;
170 // FPGA Geo Finder (For LUT generator. Doesn't use LUTs)
171 case 3:
172 runFinderVersion3(trackVariables, stTSs, stTSDrift);
173 break;
174 default:
175 break;
176 }
177
178}
179
180void Hough3DFinder::initVersion1(const vector<float >& initVariables)
181{
182 // Hough Variables.
183 m_cotStart = (int)initVariables[0];
184 m_cotEnd = (int)initVariables[1];
185 m_z0Start = (int)initVariables[2];
186 m_z0End = (int)initVariables[3];
187 // Must be odd
188 //m_nCotSteps = 101;
189 //m_nZ0Steps = 501;
190 m_nCotSteps = (int)initVariables[4];
191 m_nZ0Steps = (int)initVariables[5];
192 m_cotStepSize = m_cotEnd / ((m_nCotSteps - 1) / 2);
193 m_z0StepSize = m_z0End / ((m_nZ0Steps - 1) / 2);
194 // HoughMesh
195 m_houghMeshLayerDiff = new float** [m_nCotSteps];
196 m_houghMeshLayer = new bool** [m_nCotSteps];
197 m_houghMesh = new int* [m_nCotSteps];
198 m_houghMeshDiff = new float*[m_nCotSteps];
199 for (int i = 0; i < m_nCotSteps; i++) {
200 m_houghMeshLayerDiff[i] = new float*[m_nZ0Steps];
201 m_houghMeshLayer[i] = new bool*[m_nZ0Steps];
202 m_houghMesh[i] = new int[m_nZ0Steps];
203 m_houghMeshDiff[i] = new float[m_nZ0Steps];
204 for (int j = 0; j < m_nZ0Steps; j++) {
205 m_houghMeshLayerDiff[i][j] = new float[4];
206 m_houghMeshLayer[i][j] = new bool[4];
207 }
208 }
209}
210
211void Hough3DFinder::initVersion2(vector<float >& initVariables)
212{
213 if (false) cout << initVariables.size() << endl; // Removes warning when compiling
214
215 // index values of candidates.
216 m_geoCandidatesIndex = new vector<vector<int > >;
217 for (int iLayer = 0; iLayer < 4; iLayer++) m_geoCandidatesIndex->push_back(vector<int> ());
218 // phi values of candidates.
219 m_geoCandidatesPhi = new vector<vector<double > >;
220 for (int iLayer = 0; iLayer < 4; iLayer++) m_geoCandidatesPhi->push_back(vector<double> ());
221 // diffStWire values of candidates.
222 m_geoCandidatesDiffStWires = new vector<vector<double > >;
223 for (int iLayer = 0; iLayer < 4; iLayer++) m_geoCandidatesDiffStWires->push_back(vector<double> ());
224}
225
226void Hough3DFinder::initVersion3(vector<float >& initVariables)
227{
228 if (false) cout << initVariables.size() << endl; // Removes warning when compiling
229
230 // Make hitMap
231 m_hitMap = new bool*[4];
232 for (int i = 0; i < 4; i++) {
233 m_hitMap[i] = new bool[m_nWires[i] / 2];
234 for (int j = 0; j < m_nWires[i] / 2; j++) {
235 m_hitMap[i][j] = 0;
236 }
237 }
238 // Make driftMap
239 m_driftMap = new int* [4];
240 for (int iSt = 0; iSt < 4; iSt++) {
241 m_driftMap[iSt] = new int[m_nWires[iSt] / 2];
242 for (int iTS = 0; iTS < m_nWires[iSt] / 2; iTS++) {
243 m_driftMap[iSt][iTS] = 0;
244 }
245 }
246
247 // index values of candidates.
248 m_geoCandidatesIndex = new vector<vector<int > >;
249 for (int iLayer = 0; iLayer < 4; iLayer++) m_geoCandidatesIndex->push_back(vector<int> ());
250 // phi values of candidates.
251 m_geoCandidatesPhi = new vector<vector<double > >;
252 for (int iLayer = 0; iLayer < 4; iLayer++) m_geoCandidatesPhi->push_back(vector<double> ());
253 // diffStWire values of candidates.
254 m_geoCandidatesDiffStWires = new vector<vector<double > >;
255 for (int iLayer = 0; iLayer < 4; iLayer++) m_geoCandidatesDiffStWires->push_back(vector<double> ());
256
257 // [TODO] Add to class. Add getters and setters.
258 m_mBool["fVHDLFile"] = 0;
259 m_mBool["fVerbose"] = 0;
260}
261
262void Hough3DFinder::setInputFileName(const string& inputFileName)
263{
264 m_inputFileName = inputFileName;
265}
266
268{
269 // Deallocate HoughMesh
270 for (int i = 0; i < m_nCotSteps; i++) {
271 for (int j = 0; j < m_nZ0Steps; j++) {
272 delete [] m_houghMeshLayerDiff[i][j];
273 delete [] m_houghMeshLayer[i][j];
274 }
275 delete [] m_houghMeshLayerDiff[i];
276 delete [] m_houghMeshLayer[i];
277 delete [] m_houghMesh[i];
278 delete [] m_houghMeshDiff[i];
279 }
280 delete [] m_houghMeshLayerDiff;
281 delete [] m_houghMeshLayer;
282 delete [] m_houghMesh;
283 delete [] m_houghMeshDiff;
284
285}
286
288{
289
291 delete m_geoCandidatesPhi;
293 //for(int iLayer=0; iLayer<4; iLayer++) {
294 // delete m_geoCandidatesIndex;
295 // delete m_geoCandidatesPhi;
296 // delete m_geoCandidatesDiffStWires;
297 //}
298}
299
301{
302
303 for (int i = 0; i < 4; i++) {
304 delete [] m_hitMap[i];
305 }
306 delete [] m_hitMap;
307 for (int iSt = 0; iSt < 4; iSt++) {
308 delete [] m_driftMap[iSt];
309 }
310 delete [] m_driftMap;
311
312 if (m_mBool["fVHDLFile"]) {
313 if (m_mSavedIoSignals.size() != 0) {
315 }
316 if (m_mSavedSignals.size() != 0) {
318 }
319 //if(m_mSavedIoSignals.size()!=0) FpgaUtility::multipleWriteCoe(10, m_mSavedIoSignals, "./");
320 //if(m_mSavedSignals.size()!=0) FpgaUtility::writeSignals("signalValues",m_mSavedSignals);
321 }
322
323 if (m_commonData) delete m_commonData;
324
325}
326
327// Hough 3D finder
328void Hough3DFinder::runFinderVersion1(const vector<double>& trackVariables, const vector<vector<double> >& stTSs,
329 const vector<double>& tsArcS,
330 const vector<vector<double> >& tsZ)
331{
332
333 int charge = (int)trackVariables[0];
334 double rho = trackVariables[1];
335 double fitPhi0 = trackVariables[2];
336
337 // Clear Hough Meshes.
338 for (int i = 0; i < m_nCotSteps; i++) {
339 for (int j = 0; j < m_nZ0Steps; j++) {
340 for (int k = 0; k < 4; k++) {
341 m_houghMeshLayerDiff[i][j][k] = 999;
342 m_houghMeshLayer[i][j][k] = 0;
343 }
344 m_houghMesh[i][j] = 0;
345 m_houghMeshDiff[i][j] = 0.;
346 }
347 }
348
349 // Fill Hough mesh.
350 double tempZ0Start, tempZ0End;
351 double tempZ01, tempZ02;
352 int tempHoughZ0;
353 double actualCot, actualZ0;
354 // Find best vote.
355 //double minZ0;
356
357 // Vote in Hough Mesh Layers.
358 for (int cotStep = 0; cotStep < m_nCotSteps; cotStep++) {
359 // Find cotStep range for mesh.
360 double tempCotStart = (cotStep - 0.5) * m_cotStepSize + m_cotStart;
361 double tempCotEnd = (cotStep + 0.5) * m_cotStepSize + m_cotStart;
362 //cout<<"tempCotStart: "<<tempCotStart<<" tempCotEnd: "<<tempCotEnd<<endl;
363
364 // Find z0 range for mesh per layer.
365 for (unsigned iLayer = 0; iLayer < 4; iLayer++) {
366 for (unsigned iTS = 0; iTS < stTSs[iLayer].size(); iTS++) {
367 // Find z0 for cot.
368 tempZ01 = -tsArcS[iLayer] * tempCotStart + tsZ[iLayer][iTS];
369 tempZ02 = -tsArcS[iLayer] * tempCotEnd + tsZ[iLayer][iTS];
370
371 // Find start and end of range z0.
372 if (tempZ01 < tempZ02) {
373 tempZ0Start = tempZ01;
374 tempZ0End = tempZ02;
375 } else {
376 tempZ0Start = tempZ02;
377 tempZ0End = tempZ01;
378 }
379 //cout<<"z0Start: "<<tempZ0Start<<endl;
380 //cout<<"z0End: "<<tempZ0End<<endl;
381
382 // Do proper rounding for plus and minus values.
383 if (tempZ0Start > 0) {
384 tempZ0Start = int(tempZ0Start / m_z0StepSize + 0.5);
385 } else {
386 tempZ0Start = int(tempZ0Start / m_z0StepSize - 0.5);
387 }
388 if (tempZ0End > 0) {
389 tempZ0End = int(tempZ0End / m_z0StepSize + 0.5);
390 } else {
391 tempZ0End = int(tempZ0End / m_z0StepSize - 0.5);
392 }
393
394 // To save time do z0 cut off here
395 if (tempZ0Start < -(m_nZ0Steps - 1) / 2) {
396 tempZ0Start = -(m_nZ0Steps - 1) / 2;
397 }
398 if (tempZ0End > (m_nZ0Steps - 1) / 2) {
399 tempZ0End = (m_nZ0Steps - 1) / 2;
400 }
401
402 // Fill Hough Mesh.
403 for (int z0Step = int(tempZ0Start); z0Step <= int(tempZ0End); z0Step++) {
404 // Cut off if z0Step is bigger or smaller than z0 limit.
405 // Not needed anymore.
406 if (z0Step > (m_nZ0Steps - 1) / 2 || z0Step < -(m_nZ0Steps - 1) / 2) {
407 cout << "cutoff because z0step is bigger or smaller than z0 limit ";
408 continue;
409 }
410
411 // Change temHoughZ0 if minus.
412 if (z0Step < 0) {
413 tempHoughZ0 = (m_nZ0Steps - 1) / 2 - z0Step;
414 } else { tempHoughZ0 = z0Step; }
415
416 //Change to actual value.
417 actualCot = cotStep * m_cotStepSize + m_cotStart;
418 actualZ0 = z0Step * m_z0StepSize;
419 //cout<<"actualCot: "<<actualCot<<" actualZ0: "<<actualZ0<<endl;
420
421
422 m_houghMeshLayer[cotStep][tempHoughZ0][iLayer] = 1;
423 // Find minimum z difference for the vote.
424 m_minDiffHough = abs(actualCot * tsArcS[iLayer] + actualZ0 - tsZ[iLayer][iTS]);
425 if (m_houghMeshLayerDiff[cotStep][tempHoughZ0][iLayer] > m_minDiffHough) {
426 m_houghMeshLayerDiff[cotStep][tempHoughZ0][iLayer] = m_minDiffHough;
427 }
428
429 } // End of z0 vote loop.
430 } // End of TS loop.
431 } // End of layer loop.
432 } // End of cot vote loop.
433
434 // Filling HoughMesh. Combines the separate HoughMeshLayers.
435 for (int houghCot = 0; houghCot < m_nCotSteps; houghCot++) {
436 for (int houghZ0 = 0; houghZ0 < m_nZ0Steps; houghZ0++) {
437 //Change back tempHoughZ0 if minus, currently unused so commented out
438 // if (houghZ0 > (m_nZ0Steps - 1) / 2) {
439 // tempHoughZ0 = (m_nZ0Steps - 1) / 2 - houghZ0;
440 // } else {
441 // tempHoughZ0 = houghZ0;
442 // }
443 //Change to actual value, currently unused so commented out
444 // actualCot = houghCot * m_cotStepSize + m_cotStart;
445 // actualZ0 = tempHoughZ0 * m_z0StepSize;
446
447 for (int layer = 0; layer < 4; layer++) {
448 m_houghMesh[houghCot][houghZ0] += m_houghMeshLayer[houghCot][houghZ0][layer];
449 if (m_houghMeshLayerDiff[houghCot][houghZ0][layer] != 999) m_houghMeshDiff[houghCot][houghZ0] +=
450 m_houghMeshLayerDiff[houghCot][houghZ0][layer];
451 //if(houghMeshLayer[houghCot][houghZ0][layer]==1) hhough00->Fill(actualCot,actualZ0);
452 } // End of combining votes
453 } // End loop for houghZ0
454 } // End loop for houghCot
455
456 // Find best vote. By finding highest votes and comparing all votes and pick minimum diff z.
457 m_houghMax = 0;
458 for (int houghCot = 0; houghCot < m_nCotSteps; houghCot++) {
459 for (int houghZ0 = 0; houghZ0 < m_nZ0Steps; houghZ0++) {
460 // Changes back values for minus
461 if (houghZ0 > (m_nZ0Steps - 1) / 2) {
462 tempHoughZ0 = (m_nZ0Steps - 1) / 2 - houghZ0;
463 } else { tempHoughZ0 = houghZ0;}
464 // Find highest vote
465 if (m_houghMax < m_houghMesh[houghCot][houghZ0]) {
466 m_houghMax = m_houghMesh[houghCot][houghZ0];
467 // If highest vote changes, need to initialize minZ0, minDiffHough
468 //minZ0 = 9999;
469 m_minDiffHough = 9999;
470 }
471 // When highest vote
472 if (m_houghMax == m_houghMesh[houghCot][houghZ0]) {
473 // For second finder version
474 // When z0 is minimum
475 //if(minZ0>abs(tempHoughZ0)) {
476 // cout<<"minZ0: "<<minZ0<<" tempHoughZ0: "<<tempHoughZ0<<endl;
477 // minZ0 = tempHoughZ0;
478 // bestCot = houghCot;
479 // bestZ0 = tempHoughZ0;
480 //}
481 // For third finder version
482 // When minDiffHough is minimum
483 if (m_minDiffHough > m_houghMeshDiff[houghCot][houghZ0]) {
484 m_minDiffHough = m_houghMeshDiff[houghCot][houghZ0];
485 m_bestCot = houghCot;
486 m_bestZ0 = tempHoughZ0;
487 }
488 }
489 } // End of houghZ0 loop
490 } // End of houghCot loop
491 //cout<<"JB bestCot: "<<m_bestCot<<" bestZ0: "<<m_bestZ0<<" "<<"#Votes: "<<m_houghMax<<endl;
492 //cout<<"JB foundCot: "<<m_bestCot*m_cotStepSize+m_cotStart<<" foundZ0: "<<m_bestZ0*m_z0StepSize<<endl;
493 //cout<<"mcCot: "<<mcCot<<" mcZ0: "<<mcZ0<<endl;
494
495 // Finds the related TS from bestCot and bestZ0
496
497 // Find z and phiSt from bestCot and bestZ0 (arcS is dependent to pT)
498 for (int i = 0; i < 4; i++) {
499 m_foundZ[i] = (m_bestCot * m_cotStepSize + m_cotStart) * tsArcS[i] + (m_bestZ0 * m_z0StepSize);
500 m_foundPhiSt[i] = fitPhi0 + charge * acos(m_rr[i] / 2 / rho) + 2 * asin((m_ztostraw[i] - m_foundZ[i]) * tan(
501 m_anglest[i]) / 2 / m_rr[i]);
502 if (m_foundPhiSt[i] > 2 * M_PI) m_foundPhiSt[i] -= 2 * M_PI;
503 if (m_foundPhiSt[i] < 0) m_foundPhiSt[i] += 2 * M_PI;
504 }
505 //cout<<"JB FoundPhiSt[0]: "<<m_foundPhiSt[0]<<" FoundPhiSt[1]: "<<m_foundPhiSt[1]<<" FoundPhiSt[2]: "<<m_foundPhiSt[2]<<" FoundPhiSt[3]: "<<m_foundPhiSt[3]<<endl;
506
507 // Find closest phi out of candidates
508 double minDiff[4] = {999, 999, 999, 999};
509 for (unsigned iLayer = 0; iLayer < 4; iLayer++) {
510 for (unsigned iTS = 0; iTS < stTSs[iLayer].size(); iTS++) {
511 if (minDiff[iLayer] > abs(m_foundPhiSt[iLayer] - stTSs[iLayer][iTS])) {
512 minDiff[iLayer] = abs(m_foundPhiSt[iLayer] - stTSs[iLayer][iTS]);
513 m_bestTS[iLayer] = stTSs[iLayer][iTS];
514 m_bestTSIndex[iLayer] = (int)iTS;
515 }
516 }
517 }
518 //cout<<"JB BestPhiSt[0]: "<<m_bestTS[0]<<" BestPhiSt[1]: "<<m_bestTS[1]<<" BestPhiSt[2]: "<<m_bestTS[2]<<" BestPhiSt[3]: "<<m_bestTS[3]<<endl;
519
520}
521
522void Hough3DFinder::runFinderVersion2(const vector<double>& trackVariables, vector<vector<double> >& stTSs,
523 const std::vector<std::vector<int> >& stTSDrift)
524{
525
526 // Clear m_geoCandidatesIndex
527 for (int iLayer = 0; iLayer < 4; iLayer++) {
528 (*m_geoCandidatesIndex)[iLayer].clear();
529 (*m_geoCandidatesPhi)[iLayer].clear();
530 (*m_geoCandidatesDiffStWires)[iLayer].clear();
531 }
532
533 int charge = (int)trackVariables[0];
534 double rho = trackVariables[1];
535 double fitPhi0 = trackVariables[2];
536 double tsDiffSt;
537
538 //cout<<"charge:"<<charge<<" rho:"<<rho<<" fitPhi0:"<<fitPhi0<<endl;
539 for (int iLayer = 0; iLayer < 4; iLayer++) {
540 m_stAxPhi[iLayer] = Fitter3DUtility::calStAxPhi(charge, m_anglest[iLayer], m_ztostraw[iLayer], m_rr[iLayer], rho, fitPhi0);
541 //cout<<"iSt:"<<iLayer<<" ztostraw:"<<m_ztostraw[iLayer]<<" m_rr:"<<m_rr[iLayer]<<" stAxPhi:"<<m_stAxPhi[iLayer]<<endl;
542 //if(stTSs[iLayer].size()==0) cout<<"stTSs["<<iLayer<<"] is zero"<<endl;
543 for (unsigned iTS = 0; iTS < stTSs[iLayer].size(); iTS++) {
544 //int t_tdc = (stTSDrift[iLayer][iTS] >> 4);
545 //int t_lr = ((stTSDrift[iLayer][iTS] >> 2) & 3);
546 int t_priorityPosition = (stTSDrift[iLayer][iTS] & 3);
547 //int t_tsId = int(stTSs[iLayer][iTS]*m_nWires[iLayer]/2/2/M_PI+0.5);
548 //cout<<"iSt:"<<iLayer<<" tsId:"<<t_tsId<<" pp:"<<t_priorityPosition<<endl;
549 // Reject second priority TSs.
550 if (t_priorityPosition != 3) continue;
551 // Find number of wire difference
552 tsDiffSt = m_stAxPhi[iLayer] - stTSs[iLayer][iTS];
553 if (tsDiffSt > M_PI) tsDiffSt -= 2 * M_PI;
554 if (tsDiffSt < -M_PI) tsDiffSt += 2 * M_PI;
555 tsDiffSt = tsDiffSt / 2 / M_PI * m_nWires[iLayer] / 2;
556 //cout<<"JB ["<<iLayer<<"]["<<iTS<<"] tsDiffSt: "<<tsDiffSt<<" stTSs:"<<stTSs[iLayer][iTS]<<" rho: "<<rho<<" phi0: "<<fitPhi0<<" m_stAxPhi:"<<m_stAxPhi[iLayer]<<endl;
557 // Save index if condition is in 10 wires
558 if (iLayer % 2 == 0) {
559 if (tsDiffSt > 0 && tsDiffSt <= 10) {
560 (*m_geoCandidatesIndex)[iLayer].push_back(iTS);
561 (*m_geoCandidatesPhi)[iLayer].push_back(stTSs[iLayer][iTS]);
562 (*m_geoCandidatesDiffStWires)[iLayer].push_back(tsDiffSt);
563 }
564 } else {
565 if (tsDiffSt < 0 && tsDiffSt >= -10) {
566 (*m_geoCandidatesIndex)[iLayer].push_back(iTS);
567 (*m_geoCandidatesPhi)[iLayer].push_back(stTSs[iLayer][iTS]);
568 (*m_geoCandidatesDiffStWires)[iLayer].push_back(tsDiffSt);
569 }
570 } // End of saving index
571
572 } // Candidate loop
573 } // Layer loop
574
576 //for( int iLayer=0; iLayer<4; iLayer++){
577 // cout<<"[geoFinder] iSt:"<<iLayer<<" nSegments:"<<(*m_geoCandidatesIndex)[iLayer].size()<<endl;
578 // for(unsigned iTS=0; iTS<(*m_geoCandidatesIndex)[iLayer].size(); iTS++){
579 // //cout<<"cand ["<<iLayer<<"]["<<iTS<<"]: "<<(*m_geoCandidatesIndex)[iLayer][iTS]<<endl;
580 // cout<<"cand ["<<iLayer<<"]["<<iTS<<"]: "<<(*m_geoCandidatesPhi)[iLayer][iTS]<<endl;
581 // }
582 //}
583
584 // Pick middle candidate if multiple candidates
585 //double meanWireDiff[4] = { 5, 5, 5, 5 };
586 // z=0 wireDiff
587 //double meanWireDiff[4] = { 3.08452, 2.61314, 2.84096, 3.06938 };
588 // mean wire diff
589 const double meanWireDiff[4] = { 3.68186, 3.3542, 3.9099, 4.48263 };
590 for (int iLayer = 0; iLayer < 4; iLayer++) {
591 if ((*m_geoCandidatesIndex)[iLayer].size() == 0) {
592 //cout<<"No St Candidate in GeoFinder"<<endl;
593 m_bestTS[iLayer] = 999;
594 m_bestTSIndex[iLayer] = 999;
595 } else {
596 double bestDiff = 999;
597 for (int iTS = 0; iTS < int((*m_geoCandidatesIndex)[iLayer].size()); iTS++) {
598 tsDiffSt = m_stAxPhi[iLayer] - stTSs[iLayer][(*m_geoCandidatesIndex)[iLayer][iTS]];
599 if (tsDiffSt > M_PI) tsDiffSt -= 2 * M_PI;
600 if (tsDiffSt < -M_PI) tsDiffSt += 2 * M_PI;
601 tsDiffSt = tsDiffSt / 2 / M_PI * m_nWires[iLayer] / 2;
602 // Pick the better TS
603 //if(abs(abs(tsDiffSt)-5) < bestDiff){
604 if (abs(abs(tsDiffSt) - meanWireDiff[iLayer]) < bestDiff) {
605 //bestDiff = abs(abs(tsDiffSt)-5);
606 bestDiff = abs(abs(tsDiffSt) - meanWireDiff[iLayer]);
607 m_bestTS[iLayer] = stTSs[iLayer][(*m_geoCandidatesIndex)[iLayer][iTS]];
608 m_bestTSIndex[iLayer] = (*m_geoCandidatesIndex)[iLayer][iTS];
609 }
610 } // TS loop
611 } // If there is a TS candidate
612 } // Layer loop
613
614
615
617 //for( int iLayer=0; iLayer<4; iLayer++){
618 // cout<<"best ["<<iLayer<<"]: "<<m_bestTSIndex[iLayer]<<" "<<m_bestTS[iLayer]<<endl;
619 //}
620
621}
622
623void Hough3DFinder::runFinderVersion3(const vector<double>& trackVariables, vector<vector<double> >& stTSs,
624 const vector<vector<int> >& stTSDrift)
625{
626
627 int m_verboseFlag = m_mBool["fVerbose"];
628
629 if (m_verboseFlag) cout << "####geoFinder start####" << endl;
630
631 // Clear m_geoCandidatesIndex
632 for (int iLayer = 0; iLayer < 4; iLayer++) {
633 (*m_geoCandidatesPhi)[iLayer].clear();
634 (*m_geoCandidatesIndex)[iLayer].clear();
635 (*m_geoCandidatesDiffStWires)[iLayer].clear();
636 }
637 // Clear hit map for track
638 for (int iLayer = 0; iLayer < 4; iLayer++) {
639 for (int iTS = 0; iTS < m_nWires[iLayer] / 2; iTS++) {
640 m_hitMap[iLayer][iTS] = 0;
641 }
642 }
643 // Clear drift map for track
644 for (int iSt = 0; iSt < 4; iSt++) {
645 for (int iTS = 0; iTS < m_nWires[iSt] / 2; iTS++) {
646 m_driftMap[iSt][iTS] = 0;
647 }
648 }
649
650 // 2D Track Variables
651 int charge = (int)trackVariables[0];
652 double rho = trackVariables[1];
653 double fitPhi0 = trackVariables[2];
654
655 // Fill hitMap and driftMap
656 int iHitTS;
657 int driftInfo;
658 for (unsigned iLayer = 0; iLayer < 4; iLayer++) {
659 //cout<<"["<<iLayer<<"] size:"<<stTSs[iLayer].size()<<endl;
660 for (unsigned iTS = 0; iTS < stTSs[iLayer].size(); iTS++) {
661 iHitTS = int(stTSs[iLayer][iTS] * m_nWires[iLayer] / 2 / 2 / M_PI + 0.5);
662 driftInfo = stTSDrift[iLayer][iTS];
663 if (m_verboseFlag) cout << "[" << iLayer << "] TSId: " << iHitTS << " stTSs: " << stTSs[iLayer][iTS] << " driftInfo:" << driftInfo
664 << " priorityPosition:" << (driftInfo & 3) << endl;
665 //cout<<iHitTS*2*M_PI/m_nWires[iLayer]*2<<endl;
666 m_hitMap[iLayer][iHitTS] = 1;
667 m_driftMap[iLayer][iHitTS] = driftInfo;
668 } // End iTS
669 } // End layer
670
672 //for(int iLayer=0; iLayer<4; iLayer++) {
673 // cout<<"["<<iLayer<<"]["<<m_nWires[iLayer]/2<<"]";
674 // for(int iTS=m_nWires[iLayer]/2-1; iTS>=0; iTS--) {
675 // cout<<m_hitMap[iLayer][iTS];
676 // }
677 // cout<<endl;
678 //} // End layer
680 //for(int iLayer=0; iLayer<4; iLayer++) {
681 // cout<<"["<<iLayer<<"]["<<m_nWires[iLayer]/2<<"]"<<endl;;
682 // for(int iTS=m_nWires[iLayer]/2-1; iTS>=0; iTS--) {
683 // cout<<" ["<<iTS<<"]: "<<m_driftMap[iLayer][iTS]<<endl;;
684 // }
685 // cout<<endl;
686 //} // End layer
687
689 //for( int iLayer=0; iLayer<4; iLayer++) {
690 // double t_phiAx = acos(m_rr[iLayer]/(2*rho));
691 // double t_dPhiAx = 0;
692 // double t_dPhiAx_c = 0;
693 // if(charge==1) t_dPhiAx = t_phiAx+fitPhi0;
694 // else t_dPhiAx = -t_phiAx+fitPhi0;
695 // if(t_dPhiAx < 0) t_dPhiAx_c = t_dPhiAx + 2* M_PI;
696 // else if (t_dPhiAx > 2*M_PI) t_dPhiAx_c = t_dPhiAx - 2*M_PI;
697 // else t_dPhiAx_c = t_dPhiAx;
698 // double t_dPhiAxWire = 0;
699 // if( iLayer%2 == 0 ) t_dPhiAxWire = int(t_dPhiAx_c/2/M_PI*m_nWires[iLayer]/2);
700 // else t_dPhiAxWire = int(t_dPhiAx_c/2/M_PI*m_nWires[iLayer]/2 + 1);
701 // cout<<"iSt:"<<iLayer<<" phiAx:"<<t_phiAx<<" phi0:"<<fitPhi0<<" dPhiAx:"<<t_dPhiAx<<" charge:"<<charge<<endl;
702 // cout<<" dPhiAx_c:"<<t_dPhiAx_c<<" dPhiAxWire:"<<t_dPhiAxWire<<endl;
703 //}
704
705 // Will use cm unit.
706 std::map<std::string, std::vector<double> > mConstV;
707 std::map<std::string, double > mConstD;
708 std::map<std::string, double > mDouble;
709
710 if (m_commonData == 0) {
712 }
713 // Setup firmware parameters
714 /* cppcheck-suppress variableScope */
715 double phiMax = M_PI;
716 /* cppcheck-suppress variableScope */
717 double phiMin = -M_PI;
718 int phiBitSize = 13;
719 // pt = 0.3*1.5*rho*0.01;
720 /* cppcheck-suppress variableScope */
721 double rhoMin = 20;
722 double rhoMax = 2500;
723 int rhoBitSize = 11;
724
725 // Constraints used in below code.
726 mConstV["rr"] = vector<double> (9);
727 mConstV["rr3D"] = vector<double> (4);
728 mConstV["nTSs"] = vector<double> (9);
729 for (unsigned iSt = 0; iSt < 4; iSt++) {
730 // Convert unit to cm.
731 mConstV["rr"][2 * iSt + 1] = m_rr[iSt] * 100;
732 mConstV["rr3D"][iSt] = m_rr[iSt] * 100;
733 mConstV["nTSs"][2 * iSt + 1] = m_nWires[iSt] / 2;
734 }
735 mConstD["acosLUTInBitSize"] = rhoBitSize;
736 mConstD["acosLUTOutBitSize"] = phiBitSize - 1;
737 mConstD["Trg_PI"] = M_PI;
738
739 // Constrain rho to rhoMax. For removing warnings when changing to signals.
740 {
741 mDouble["rho"] = rho * 100;
742 if (mDouble["rho"] > rhoMax) {
743 mDouble["rho"] = rhoMax;
744 mDouble["pt"] = rhoMax * 0.3 * 1.5 * 0.01;
745 }
746 }
747 // Constrain phi0 to [-pi, pi]
748 {
749 mDouble["phi0"] = fitPhi0;
750 bool rangeFail = 1;
751 while (rangeFail) {
752 if (mDouble["phi0"] > mConstD["Trg_PI"]) mDouble["phi0"] -= 2 * mConstD["Trg_PI"];
753 else if (mDouble["phi0"] < -mConstD["Trg_PI"]) mDouble["phi0"] += 2 * mConstD["Trg_PI"];
754 else rangeFail = 0;
755 }
756 }
757
758 // Change to Signals. Convert rho to cm unit.
759 {
760 vector<tuple<string, double, int, double, double, int> > t_values = {
761 make_tuple("phi0", mDouble["phi0"], phiBitSize, phiMin, phiMax, 0),
762 make_tuple("rho", mDouble["rho"], rhoBitSize, rhoMin, rhoMax, 0),
763 make_tuple("charge", (int)(charge == 1 ? 1 : 0), 1, 0, 1.5, 0),
764 };
766 }
767 //cout<<"<<<phi0>>>"<<endl; m_mSignalStorage["phi0"].dump();
768 //cout<<"<<<rho>>>"<<endl; m_mSignalStorage["rho"].dump();
769 //cout<<"<<<charge>>>"<<endl; m_mSignalStorage["charge"].dump();
770
771 // Constrain rho
773 // phiAx = arcos(r/2R).
774 // Make min max constants for lut.
775 if (m_mSignalStorage.find("invPhiAxMin_0") == m_mSignalStorage.end()) {
776 for (unsigned iSt = 0; iSt < 4; iSt++) {
777 string t_invMinName = "invPhiAxMin_" + to_string(iSt);
778 double t_actual = m_mSignalStorage["rho_c_" + to_string(iSt)].getMinActual();
779 double t_toReal = m_mSignalStorage["rho_c_" + to_string(iSt)].getToReal();
780 m_mSignalStorage[t_invMinName] = Belle2::TRGCDCJSignal(t_actual, t_toReal, m_commonData);
781 string t_invMaxName = "invPhiAxMax_" + to_string(iSt);
782 t_actual = m_mSignalStorage["rho_c_" + to_string(iSt)].getMaxActual();
783 m_mSignalStorage[t_invMaxName] = Belle2::TRGCDCJSignal(t_actual, t_toReal, m_commonData);
784 }
785 }
786 //for(int iSt=0; iSt<4; iSt++) {cout<<"<<<invPhiAxMin_"<<iSt<<">>>"<<endl; m_mSignalStorage["invPhiAxMin_"+to_string(iSt)].dump();}
787 //for(int iSt=0; iSt<4; iSt++) {cout<<"<<<invPhiAxMax_"<<iSt<<">>>"<<endl; m_mSignalStorage["invPhiAxMax_"+to_string(iSt)].dump();}
788 // Generate LUT(phiAx[i]=acos(rr[i]/2/rho)).
789 for (unsigned iSt = 0; iSt < 4; iSt++) {
790 string t_valueName = "phiAx_" + to_string(iSt);
791 string t_minName = "phiAxMin_" + to_string(iSt);
792 string t_maxName = "phiAxMax_" + to_string(iSt);
793 string t_invMinName = "invPhiAxMin_" + to_string(iSt);
794 string t_invMaxName = "invPhiAxMax_" + to_string(iSt);
795 if (!m_mLutStorage.count(t_valueName)) {
796 m_mLutStorage[t_valueName] = new Belle2::TRGCDCJLUT(t_valueName);
797 // Lambda can not copy maps.
798 double t_parameter = mConstV.at("rr3D")[iSt];
799 m_mLutStorage[t_valueName]->setFloatFunction(
800 [ = ](double aValue) -> double{return acos(t_parameter / 2 / aValue);},
801 m_mSignalStorage["rho_c_" + to_string(iSt)],
802 m_mSignalStorage[t_invMinName], m_mSignalStorage[t_invMaxName], m_mSignalStorage["phi0"].getToReal(),
803 (int)mConstD.at("acosLUTInBitSize"), (int)mConstD.at("acosLUTOutBitSize"));
804 //m_mLutStorage[t_valueName]->makeCOE("./LutData/geoFinder_"+t_valueName+".coe");
805 }
806 }
807 // phiAx[i] = acos(rr[i]/2/rho).
808 // Operate using LUT(phiAx[i]).
809 for (unsigned iSt = 0; iSt < 4; iSt++) {
810 // Set output name
811 string t_valueName = "phiAx_" + to_string(iSt);
812 m_mLutStorage[t_valueName]->operate(m_mSignalStorage["rho_c_" + to_string(iSt)], m_mSignalStorage[t_valueName]);
813 }
814 //for(int iSt=0; iSt<4; iSt++) {cout<<"<<<phiAx_"<<iSt<<">>>"<<endl; m_mSignalStorage["phiAx_"+to_string(iSt)].dump();}
815 // dPhiAx[i] = +-phiAx[i] + phi0
816 {
817 // Create data for ifElse
818 vector<pair<Belle2::TRGCDCJSignal, vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > > > t_data;
819 // Compare
821 m_commonData), "=", m_mSignalStorage["charge"]);
822 // Assignments
823 vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > t_assigns = {
824 make_pair(&m_mSignalStorage["dPhiAx_0"], m_mSignalStorage["phiAx_0"] + m_mSignalStorage["phi0"]),
825 make_pair(&m_mSignalStorage["dPhiAx_1"], m_mSignalStorage["phiAx_1"] + m_mSignalStorage["phi0"]),
826 make_pair(&m_mSignalStorage["dPhiAx_2"], m_mSignalStorage["phiAx_2"] + m_mSignalStorage["phi0"]),
827 make_pair(&m_mSignalStorage["dPhiAx_3"], m_mSignalStorage["phiAx_3"] + m_mSignalStorage["phi0"])
828 };
829 // Push to data.
830 t_data.push_back(make_pair(t_compare, t_assigns));
831 // Compare
832 t_compare = Belle2::TRGCDCJSignal();
833 // Assignments
834 t_assigns = {
835 make_pair(&m_mSignalStorage["dPhiAx_0"], -m_mSignalStorage["phiAx_0"] + m_mSignalStorage["phi0"]),
836 make_pair(&m_mSignalStorage["dPhiAx_1"], -m_mSignalStorage["phiAx_1"] + m_mSignalStorage["phi0"]),
837 make_pair(&m_mSignalStorage["dPhiAx_2"], -m_mSignalStorage["phiAx_2"] + m_mSignalStorage["phi0"]),
838 make_pair(&m_mSignalStorage["dPhiAx_3"], -m_mSignalStorage["phiAx_3"] + m_mSignalStorage["phi0"])
839 };
840 // Push to data.
841 t_data.push_back(make_pair(t_compare, t_assigns));
842 // Process ifElse data.
844 }
845 //cout<<"<<<phi0>>>"<<endl; m_mSignalStorage["phi0"].dump();
846 //cout<<"<<<charge>>>"<<endl; m_mSignalStorage["charge"].dump();
847 //for(int iSt=0; iSt<4; iSt++) {cout<<"<<<dPhiAx_"<<iSt<<">>>"<<endl; m_mSignalStorage["dPhiAx_"+to_string(iSt)].dump();}
848
849 // This could be needed in the future if efficiency is low.
850 // To use this code, change dPhiAx to dPhiAx_m when constraining dPhiAx below.
852 //for(unsigned iSt=0; iSt<4; iSt++) {
853 // double wirePhiUnit = 2 * mConstD["Trg_PI"] / mConstV["nTSs"][2*iSt+1];
854 // if (iSt%2 == 0) {
855 // m_mSignalStorage["dPhiAx_m_"+to_string(iSt)] <= m_mSignalStorage["dPhiAx_"+to_string(iSt)] + Belle2::TRGCDCJSignal(wirePhiUnit,m_mSignalStorage["dPhiAx_"+to_string(iSt)].getToReal(), m_commonData);
856 // } else {
857 // m_mSignalStorage["dPhiAx_m_"+to_string(iSt)] <= m_mSignalStorage["dPhiAx_"+to_string(iSt)] - Belle2::TRGCDCJSignal(wirePhiUnit, m_mSignalStorage["dPhiAx_"+to_string(iSt)].getToReal(), m_commonData);
858 // }
859 //}
860
861 //for(int iSt=0; iSt<4; iSt++) {cout<<"<<<dPhiAx_m_"<<iSt<<">>>"<<endl; m_mSignalStorage["dPhiAx_m_"+to_string(iSt)].dump();}
862 // Constrain dPhiAx[i] to [0, 2pi)
863 if (m_mSignalStorage.find("dPhiAxMax_0") == m_mSignalStorage.end()) {
864 for (unsigned iSt = 0; iSt < 4; iSt++) {
865 string t_valueName = "dPhiAx_" + to_string(iSt);
866 //string t_valueName = "dPhiAx_m_" + to_string(iSt);
867 string t_maxName = "dPhiAxMax_" + to_string(iSt);
868 string t_minName = "dPhiAxMin_" + to_string(iSt);
869 string t_2PiName = "dPhiAx2Pi_" + to_string(iSt);
870 m_mSignalStorage[t_maxName] = Belle2::TRGCDCJSignal(2 * mConstD.at("Trg_PI"), m_mSignalStorage[t_valueName].getToReal(),
872 m_mSignalStorage[t_minName] = Belle2::TRGCDCJSignal(0, m_mSignalStorage[t_valueName].getToReal(), m_commonData);
873 m_mSignalStorage[t_2PiName] = Belle2::TRGCDCJSignal(2 * mConstD.at("Trg_PI"), m_mSignalStorage[t_valueName].getToReal(),
875 }
876 }
877 for (unsigned iSt = 0; iSt < 4; iSt++) {
878 string t_in1Name = "dPhiAx_" + to_string(iSt);
879 //string t_in1Name = "dPhiAx_m_" + to_string(iSt);
880 string t_valueName = "dPhiAx_c_" + to_string(iSt);
881 string t_maxName = "dPhiAxMax_" + to_string(iSt);
882 string t_minName = "dPhiAxMin_" + to_string(iSt);
883 string t_2PiName = "dPhiAx2Pi_" + to_string(iSt);
884 // Create data for ifElse
885 vector<pair<Belle2::TRGCDCJSignal, vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > > > t_data;
886 // Compare (dPhiAx_m >= 2*pi)
888 // Assignments (dPhiAx_c <= dPhiAx_m - 2*pi)
889 vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > t_assigns = {
890 make_pair(&m_mSignalStorage[t_valueName], (m_mSignalStorage[t_in1Name] - m_mSignalStorage[t_2PiName]).limit(m_mSignalStorage[t_minName], m_mSignalStorage[t_maxName])),
891 };
892 // Push to data.
893 t_data.push_back(make_pair(t_compare, t_assigns));
894 // Compare (dPhiAx_m >= 0)
895 t_compare = Belle2::TRGCDCJSignal::comp(m_mSignalStorage[t_in1Name], ">=", m_mSignalStorage[t_minName]);
896 // Assignments (dPhiAx_c <= dPhiAx_m)
897 t_assigns = {
898 make_pair(&m_mSignalStorage[t_valueName], m_mSignalStorage[t_in1Name].limit(m_mSignalStorage[t_minName], m_mSignalStorage[t_maxName])),
899 };
900 // Push to data.
901 t_data.push_back(make_pair(t_compare, t_assigns));
902 // Compare (dPhiAx_m < 0)
903 t_compare = Belle2::TRGCDCJSignal();
904 // Assignments (dPhiAx_c <= dPhiAx_m + 2*pi)
905 t_assigns = {
906 make_pair(&m_mSignalStorage[t_valueName], (m_mSignalStorage[t_in1Name] + m_mSignalStorage[t_2PiName]).limit(m_mSignalStorage[t_minName], m_mSignalStorage[t_maxName])),
907 };
908 // Push to data.
909 t_data.push_back(make_pair(t_compare, t_assigns));
910 // Process ifElse data.
912 }
913 //for(int iSt=0; iSt<4; iSt++) {cout<<"<<<dPhiAxMax_"<<iSt<<">>>"<<endl; m_mSignalStorage["dPhiAxMax_"+to_string(iSt)].dump();}
914 //for(int iSt=0; iSt<4; iSt++) {cout<<"<<<dPhiAxMin_"<<iSt<<">>>"<<endl; m_mSignalStorage["dPhiAxMin_"+to_string(iSt)].dump();}
915 //for(int iSt=0; iSt<4; iSt++) {cout<<"<<<dPhiAx2Pi_"<<iSt<<">>>"<<endl; m_mSignalStorage["dPhiAx2Pi_"+to_string(iSt)].dump();}
916 //for(int iSt=0; iSt<4; iSt++) {cout<<"<<<dPhiAx_c_"<<iSt<<">>>"<<endl; m_mSignalStorage["dPhiAx_c_"+to_string(iSt)].dump();}
917 // Change to wire space
918 // Make wireFactor constants
919 if (m_mSignalStorage.find("wireFactor_0") == m_mSignalStorage.end()) {
920 for (unsigned iSt = 0; iSt < 4; iSt++) {
921 int nShiftBits = int(log(pow(2, 24) * 2 * mConstD.at("Trg_PI") / mConstV.at("nTSs")[2 * iSt + 1] /
922 m_mSignalStorage["phi0"].getToReal()) / log(2));
923 string t_name;
924 t_name = "wireFactor_" + to_string(iSt);
925 m_mSignalStorage[t_name] = Belle2::TRGCDCJSignal(mConstV.at("nTSs")[2 * iSt + 1] / 2 / mConstD.at("Trg_PI"),
926 1 / m_mSignalStorage["phi0"].getToReal() / pow(2, nShiftBits), m_commonData);
927 }
928 }
929 //for(int iSt=0; iSt<4; iSt++) {cout<<"<<<wireFactor_"<<iSt<<">>>"<<endl; m_mSignalStorage["wireFactor_"+to_string(iSt)].dump();}
930 // wireDPhiAx[i] <= dPhiAx_c[i] * wireFactor[i]
931 // Shift to find actual wire.
932 for (unsigned iSt = 0; iSt < 4; iSt++) {
933 int nShiftBits = log(1 / m_mSignalStorage["dPhiAx_c_" + to_string(iSt)].getToReal() / m_mSignalStorage["wireFactor_" + to_string(
934 iSt)].getToReal()) / log(2);
935 m_mSignalStorage["wireDPhiAx_" + to_string(iSt)] <= (m_mSignalStorage["dPhiAx_c_" + to_string(
936 iSt)] * m_mSignalStorage["wireFactor_" + to_string(iSt)]).shift(nShiftBits, 0);
937 }
938 //for(int iSt=0; iSt<4; iSt++) {cout<<"<<<wireDPhiAx_"<<iSt<<">>>"<<endl; m_mSignalStorage["wireDPhiAx_"+to_string(iSt)].dump();}
939 // Select TS window from wireDPhiAx
940 vector< int > nCandidates = { 10, 10, 10, 13 };
941 // stCandHitmap[iSt][iTS]
942 vector<vector<bool> > t_stCandHitmap(4);
943 for (unsigned iSt = 0; iSt < 4; iSt++) t_stCandHitmap[iSt] = vector<bool> (nCandidates[iSt]);
944 // Last driftInfo is for showing no hit.
945 vector<vector<int> > t_stCandDriftmap(4);
946 for (unsigned iSt = 0; iSt < 4; iSt++) t_stCandDriftmap[iSt] = vector<int> (nCandidates[iSt] + 1);
947 // resultValues = [name, value, bitwidth, min, max, clock]
948 vector<tuple<string, double, int, double, double, int> > resultValues;
949 {
950 vector<pair<string, int> > t_chooseSignals = {
951 make_pair("wireDPhiAx_0", 1), make_pair("wireDPhiAx_1", 1), make_pair("wireDPhiAx_2", 1), make_pair("wireDPhiAx_3", 1)
952 };
953 Belle2::TRGCDCJSignal::mapSignalsToValues(m_mSignalStorage, t_chooseSignals, resultValues);
954 }
955 vector<double> t_wireDPhiAx = {std::get<1>(resultValues[0]), std::get<1>(resultValues[1]), std::get<1>(resultValues[2]), std::get<1>(resultValues[3])};
956 // Print wireDPhiAx
957 //for(unsigned iSt=0; iSt<4; iSt++) cout<<"iSt:"<<iSt<<" t_wireDPhiAx:"<<t_wireDPhiAx[iSt]<<endl;
958 for (int iSt = 0; iSt < 4; iSt++) {
959 int indexTS = t_wireDPhiAx[iSt];
960 for (int iTS = 0; iTS < nCandidates[iSt]; iTS++) {
961 // Copy 10 TSs from hitmap and driftmap
962 t_stCandHitmap[iSt][iTS] = m_hitMap[iSt][indexTS];
963 t_stCandDriftmap[iSt][iTS] = m_driftMap[iSt][indexTS];
964 // Move indexTS
965 if (iSt % 2 == 0) {
966 indexTS--;
967 // If index is below 0 deg goto 360-delta deg
968 if (indexTS < 0) indexTS = m_nWires[iSt] / 2 - 1;
969 } else {
970 indexTS++;
971 // If index is 360 deg goto 0 deg
972 if (indexTS >= m_nWires[iSt] / 2) indexTS = 0;
973 }
974 }
975 }
976 // Print stCandHitMap
977 if (m_verboseFlag) {
978 for (unsigned iLayer = 0; iLayer < 4; iLayer++) {
979 cout << "iSt:" << iLayer << " t_wireDPhiAx:" << t_wireDPhiAx[iLayer];
980 int t_endTSId = 0;
981 if (iLayer % 2 == 0) t_endTSId = t_wireDPhiAx[iLayer] - (nCandidates[iLayer] - 1);
982 else t_endTSId = t_wireDPhiAx[iLayer] + (nCandidates[iLayer] - 1);
983 if (t_endTSId < 0) t_endTSId += mConstV["nTSs"][2 * iLayer + 1];
984 else if (t_endTSId >= mConstV["nTSs"][2 * iLayer + 1]) t_endTSId -= mConstV["nTSs"][2 * iLayer + 1];
985 //cout<<" endWindow:"<<t_endTSId<<endl;
986 cout << " t_stCandHitmap[" << iLayer << "]: " << t_endTSId << "=> ";
987 for (int iTS = nCandidates[iLayer] - 1; iTS >= 0; iTS--) {
988 cout << t_stCandHitmap[iLayer][iTS];
989 }
990 cout << " <= " << t_wireDPhiAx[iLayer] << endl;
991 }
993 //for(unsigned iSt=0; iSt<4; iSt++){
994 // for(int iTS=0; iTS<nCandidates[iSt]; iTS++){
995 // cout<<"iSt:"<<iSt<<" iTS:"<<iTS<<" stCandDriftMap:"<<t_stCandDriftmap[iSt][iTS]<<endl;
996 // }
997 //}
998 }
999 vector<double> t_targetWirePosition = { 3, 2, 3, 3};
1000 // When bestRelTsId is nCandidates, it means no hit.
1001 vector<int> t_bestRelTSId(4);
1002 for (unsigned iSt = 0; iSt < 4; iSt++) t_bestRelTSId[iSt] = nCandidates[iSt];
1003 vector<int> t_bestDiff = {16, 16, 16, 16};
1004 // Select best TS between 10 wires.
1005 for (unsigned iSt = 0; iSt < 4; iSt++) {
1006 for (int iTS = 0; iTS < nCandidates[iSt]; iTS++) {
1007 int t_priorityPosition = (t_stCandDriftmap[iSt][iTS] & 3);
1008 //cout<<"iSt:"<<iSt<<" iTS:"<<iTS<<" t_priorityPosition:"<<t_priorityPosition<<endl;
1009 if (t_stCandHitmap[iSt][iTS] == 0) continue;
1010 if (t_priorityPosition != 3) continue;
1011 double tsDiffTarget = fabs(t_targetWirePosition[iSt] - iTS);
1012 if (t_bestDiff[iSt] > tsDiffTarget) {
1013 t_bestDiff[iSt] = tsDiffTarget;
1014 t_bestRelTSId[iSt] = iTS;
1015 }
1016 }
1017 }
1018 // Print best relative output
1019 if (m_verboseFlag) {
1020 for (unsigned iSt = 0; iSt < 4;
1021 iSt++) cout << "iSt:" << iSt << " bestRelTS:" << t_bestRelTSId[iSt] << " diff:" << t_bestDiff[iSt] << endl;
1022 }
1023 // Convert best relative TS id to best TS id
1024 vector<double> t_bestTSId(4);
1025 for (unsigned iSt = 0; iSt < 4; iSt++) {
1026 if (iSt % 2 == 0) t_bestTSId[iSt] = t_wireDPhiAx[iSt] - t_bestRelTSId[iSt];
1027 else t_bestTSId[iSt] = t_wireDPhiAx[iSt] + t_bestRelTSId[iSt];
1028 }
1029 // Get bestDriftInfo
1030 vector<double> t_bestDriftInfo(4);
1031 for (unsigned iSt = 0; iSt < 4; iSt++) t_bestDriftInfo[iSt] = t_stCandDriftmap[iSt][t_bestRelTSId[iSt]];
1033 //for(unsigned iSt=0; iSt<4; iSt++) cout<<"iSt:"<<iSt<<" bestTS:"<<t_bestTSId[iSt]<<endl;
1034 // Print best drift info
1035 if (m_verboseFlag) {
1036 for (unsigned iSt = 0; iSt < 4; iSt++)cout << "iSt:" << iSt << " bestDriftInfo:" << t_bestDriftInfo[iSt] << endl;
1037 }
1038
1039 // Constrain bestTS to [0, nTS-1]
1040 vector<double> t_bestTSId_c(4);
1041 for (unsigned iSt = 0; iSt < 4; iSt++) {
1042 if (t_bestTSId[iSt] >= mConstV["nTSs"][2 * iSt + 1]) t_bestTSId_c[iSt] = t_bestTSId[iSt] - mConstV["nTSs"][2 * iSt + 1];
1043 else if (t_bestTSId[iSt] < 0) t_bestTSId_c[iSt] = t_bestTSId[iSt] + mConstV["nTSs"][2 * iSt + 1];
1044 else t_bestTSId_c[iSt] = t_bestTSId[iSt];
1045 }
1046 // Print best constrained output
1047 if (m_verboseFlag) {
1048 for (unsigned iSt = 0; iSt < 4; iSt++)cout << "iSt:" << iSt << " bestTS_c:" << t_bestTSId_c[iSt] << endl;
1049 }
1050
1051 // Save to m_bestTS
1052 for (unsigned iSt = 0; iSt < 4; iSt++) {
1053 if (t_bestDriftInfo[iSt] != 0) m_bestTS[iSt] = t_bestTSId_c[iSt] * 2 * mConstD["Trg_PI"] / mConstV["nTSs"][2 * iSt + 1] ;
1054 else m_bestTS[iSt] = 999;
1055 }
1056 //if(m_verboseFlag) {
1057 // for(unsigned iSt=0; iSt<4; iSt++)cout<<"iSt:"<<iSt<<" m_bestTS:"<<m_bestTS[iSt]<<endl;
1058 //}
1059 // Search and save to m_bestTSIndex
1060 for (unsigned iSt = 0; iSt < 4; iSt++) {
1061 if (t_bestDriftInfo[iSt] == 0) {
1062 m_bestTSIndex[iSt] = 999;
1063 } else {
1064 for (unsigned iTS = 0; iTS < stTSs[iSt].size(); iTS++) {
1065 if (fabs(m_bestTS[iSt] - stTSs[iSt][iTS]) < 0.0001) {
1066 m_bestTSIndex[iSt] = iTS;
1067 break;
1068 }
1069 }
1070 }
1071 }
1072 //if(m_verboseFlag) {
1073 // for(unsigned iSt=0; iSt<4; iSt++)cout<<"iSt:"<<iSt<<" m_bestTSIndex:"<<m_bestTSIndex[iSt]<<endl;
1074 //}
1075
1076 // Post handling of signals.
1077 // Name all signals.
1078 if ((*m_mSignalStorage.begin()).second.getName() == "") {
1079 for (auto it = m_mSignalStorage.begin(); it != m_mSignalStorage.end(); ++it) {
1080 (*it).second.setName((*it).first);
1081 }
1082 }
1091
1092 if (m_mBool["fVHDLFile"]) {
1093 // Check if there is a name.
1094 if ((*m_mSignalStorage.begin()).second.getName() != "") {
1095 // Saves to file only one time.
1096 // Print Vhdl and Coe
1097 if (m_commonData->getPrintedToFile() == 0) {
1098 if (m_commonData->getPrintVhdl() == 0) {
1101 } else {
1107 // Print LUTs.
1108 for (map<string, Belle2::TRGCDCJLUT*>::iterator it = m_mLutStorage.begin(); it != m_mLutStorage.end(); ++it) {
1109 it->second->makeCOE(m_outputLutDirname + "/" + it->first + ".coe");
1110 //it->second->makeCOE(it->first+".coe");
1111 }
1112 }
1113 }
1114
1115 // Saves values to memory. Wrote to file at terminate().
1116 // Save all signals to m_mSavedSignals. Limit to 10 times.
1117 if ((*m_mSavedSignals.begin()).second.size() < 10 || m_mSavedSignals.empty()) {
1118 for (auto it = m_mSignalStorage.begin(); it != m_mSignalStorage.end(); ++it) {
1119 m_mSavedSignals[(*it).first].push_back((*it).second.getInt());
1120 }
1121 }
1122
1123 // Saves values to memory. Wrote to file at terminate().
1124 // Save input output signals. Limit to 1024.
1125 if ((*m_mSavedIoSignals.begin()).second.size() < 1025 || m_mSavedIoSignals.empty()) {
1126 m_mSavedIoSignals["in_phi0"].push_back(m_mSignalStorage["phi0"].getInt());
1127 m_mSavedIoSignals["in_rho"].push_back(m_mSignalStorage["rho"].getInt());
1128 m_mSavedIoSignals["in_charge"].push_back(m_mSignalStorage["charge"].getInt());
1129 for (unsigned iSt = 0; iSt < 4;
1130 iSt++) m_mSavedIoSignals["out_wireDPhiAx_" + to_string(iSt)].push_back(m_mSignalStorage["wireDPhiAx_" + to_string(iSt)].getInt());
1131 }
1132
1133 }
1134 }
1135
1136 if (m_verboseFlag) cout << "####geoFinder end####" << endl;
1137
1138}
1139
1140void Hough3DFinder::getValues(const string& input, vector<double>& result)
1141{
1142 //Clear result vector
1143 result.clear();
1144
1145 if (input == "bestCot") {
1146 result.push_back(m_bestCot);
1147 }
1148 if (input == "bestZ0") {
1149 result.push_back(m_bestZ0);
1150 }
1151 if (input == "houghMax") {
1152 result.push_back(m_houghMax);
1153 }
1154 if (input == "minDiffHough") {
1155 result.push_back(m_minDiffHough);
1156 }
1157 if (input == "foundZ") {
1158 result.push_back(m_foundZ[0]);
1159 result.push_back(m_foundZ[1]);
1160 result.push_back(m_foundZ[2]);
1161 result.push_back(m_foundZ[3]);
1162 }
1163 if (input == "foundPhiSt") {
1164 result.push_back(m_foundPhiSt[0]);
1165 result.push_back(m_foundPhiSt[1]);
1166 result.push_back(m_foundPhiSt[2]);
1167 result.push_back(m_foundPhiSt[3]);
1168 }
1169 if (input == "bestTS") {
1170 result.push_back(m_bestTS[0]);
1171 result.push_back(m_bestTS[1]);
1172 result.push_back(m_bestTS[2]);
1173 result.push_back(m_bestTS[3]);
1174 }
1175 if (input == "bestTSIndex") {
1176 result.push_back(m_bestTSIndex[0]);
1177 result.push_back(m_bestTSIndex[1]);
1178 result.push_back(m_bestTSIndex[2]);
1179 result.push_back(m_bestTSIndex[3]);
1180 }
1181 if (input == "st0GeoCandidatesPhi") {
1182 for (int iTS = 0; iTS < int((*m_geoCandidatesPhi)[0].size()); iTS++)
1183 result.push_back((*m_geoCandidatesPhi)[0][iTS]);
1184 }
1185 if (input == "st1GeoCandidatesPhi") {
1186 for (int iTS = 0; iTS < int((*m_geoCandidatesPhi)[1].size()); iTS++)
1187 result.push_back((*m_geoCandidatesPhi)[1][iTS]);
1188 }
1189 if (input == "st2GeoCandidatesPhi") {
1190 for (int iTS = 0; iTS < int((*m_geoCandidatesPhi)[2].size()); iTS++)
1191 result.push_back((*m_geoCandidatesPhi)[2][iTS]);
1192 }
1193 if (input == "st3GeoCandidatesPhi") {
1194 for (int iTS = 0; iTS < int((*m_geoCandidatesPhi)[3].size()); iTS++)
1195 result.push_back((*m_geoCandidatesPhi)[3][iTS]);
1196 }
1197
1198 if (input == "st0GeoCandidatesDiffStWires") {
1199 for (int iTS = 0; iTS < int((*m_geoCandidatesDiffStWires)[0].size()); iTS++)
1200 result.push_back((*m_geoCandidatesDiffStWires)[0][iTS]);
1201 }
1202 if (input == "st1GeoCandidatesDiffStWires") {
1203 for (int iTS = 0; iTS < int((*m_geoCandidatesDiffStWires)[1].size()); iTS++)
1204 result.push_back((*m_geoCandidatesDiffStWires)[1][iTS]);
1205 }
1206 if (input == "st2GeoCandidatesDiffStWires") {
1207 for (int iTS = 0; iTS < int((*m_geoCandidatesDiffStWires)[2].size()); iTS++)
1208 result.push_back((*m_geoCandidatesDiffStWires)[2][iTS]);
1209 }
1210 if (input == "st3GeoCandidatesDiffStWires") {
1211 for (int iTS = 0; iTS < int((*m_geoCandidatesDiffStWires)[3].size()); iTS++)
1212 result.push_back((*m_geoCandidatesDiffStWires)[3][iTS]);
1213 }
1214
1215 if (input == "st0GeoCandidatesIndex") {
1216 for (int iTS = 0; iTS < int((*m_geoCandidatesIndex)[0].size()); iTS++)
1217 result.push_back((*m_geoCandidatesIndex)[0][iTS]);
1218 }
1219 if (input == "st1GeoCandidatesIndex") {
1220 for (int iTS = 0; iTS < int((*m_geoCandidatesIndex)[1].size()); iTS++)
1221 result.push_back((*m_geoCandidatesIndex)[1][iTS]);
1222 }
1223 if (input == "st2GeoCandidatesIndex") {
1224 for (int iTS = 0; iTS < int((*m_geoCandidatesIndex)[2].size()); iTS++)
1225 result.push_back((*m_geoCandidatesIndex)[2][iTS]);
1226 }
1227 if (input == "st3GeoCandidatesIndex") {
1228 for (int iTS = 0; iTS < int((*m_geoCandidatesIndex)[3].size()); iTS++)
1229 result.push_back((*m_geoCandidatesIndex)[3][iTS]);
1230 }
1231
1232 if (input == "stAxPhi") {
1233 result.push_back(m_stAxPhi[0]);
1234 result.push_back(m_stAxPhi[1]);
1235 result.push_back(m_stAxPhi[2]);
1236 result.push_back(m_stAxPhi[3]);
1237 }
1238
1239 if (input == "extreme") {
1240 result.push_back(m_findRhoMax);
1241 result.push_back(m_findRhoMin);
1242 result.push_back(m_findPhi0Max);
1243 result.push_back(m_findPhi0Min);
1244 result.push_back(m_findArcCosMax);
1245 result.push_back(m_findArcCosMin);
1246 result.push_back(m_findPhiZMax);
1247 result.push_back(m_findPhiZMin);
1248 result.push_back(m_findRhoIntMax);
1249 result.push_back(m_findRhoIntMin);
1250 result.push_back(m_findPhi0IntMax);
1251 result.push_back(m_findPhi0IntMin);
1252 result.push_back(m_findArcCosIntMax);
1253 result.push_back(m_findArcCosIntMin);
1254 result.push_back(m_findPhiZIntMax);
1255 result.push_back(m_findPhiZIntMin);
1257 //for(unsigned i=0; i<result.size(); i++) {
1258 // cout<<result[i]<<endl;
1259 //}
1260 }
1261
1262 if (input == "hitmapLayer1") {
1263 for (unsigned iOutput = 0; iOutput < unsigned(m_nWires[0] / 2); iOutput++) {
1264 result.push_back(m_hitMap[0][iOutput]);
1265 }
1266 }
1267
1268 if (input == "hitmapLayer2") {
1269 for (unsigned iOutput = 0; iOutput < unsigned(m_nWires[1] / 2); iOutput++) {
1270 result.push_back(m_hitMap[1][iOutput]);
1271 }
1272 }
1273
1274 if (input == "hitmapLayer3") {
1275 for (unsigned iOutput = 0; iOutput < unsigned(m_nWires[2] / 2); iOutput++) {
1276 result.push_back(m_hitMap[2][iOutput]);
1277 }
1278 }
1279
1280 if (input == "hitmapLayer4") {
1281 for (unsigned iOutput = 0; iOutput < unsigned(m_nWires[3] / 2); iOutput++) {
1282 result.push_back(m_hitMap[3][iOutput]);
1283 }
1284 }
1285
1286}
1287
1288void Hough3DFinder::getHoughMeshLayer(bool***& houghMeshLayer)
1289{
1290 houghMeshLayer = m_houghMeshLayer;
1291}
A class to use LUTs for TRGCDC.
Definition: JLUT.h:35
A class to hold common data for JSignals.
Definition: JSignalData.h:33
A class to use Signals for TRGCDC 3D tracker.
Definition: JSignal.h:35
static double calStAxPhi(int charge, double anglest, double ztostraw, double rr, double rho, double phi0)
Calculates the fitted axial phi for the stereo super layer.
static double calZ(int charge, double anglest, double ztostraw, double rr, double phi, double rho, double phi0)
Calculates z.
static double calS(double rho, double rr)
Calculates arc length.
static void constrainRPerStSl(std::map< std::string, std::vector< double > > const &mConstV, std::map< std::string, Belle2::TRGCDCJSignal > &mSignalStorage)
Constrains R for each SL differently using JSignal and multiple constants.
static void writeSignals(std::string outFilePath, std::map< std::string, std::vector< signed long long > > &data)
COE file functions.
Definition: FpgaUtility.cc:202
static void multipleWriteCoe(int lutInBitsize, std::map< std::string, std::vector< signed long long > > &data, const std::string &fileDirectory)
Writes multiple signal values to a file in coe format.
Definition: FpgaUtility.cc:220
void initialize(const TVectorD &geometryVariables, std::vector< float > &initVariables)
Geometry variables.
double m_findPhi0Max
Holds the maximum value for phi0.
int m_nWires[4]
Holds the number of wires for stereo superlayer.
double m_findRhoMin
Holds the minimum value for rho.
bool *** m_houghMeshLayer
Map to check if there is a Hough vote in a stereo superlayer.
double m_houghMax
The maximum vote number for track.
std::vector< std::vector< double > > * m_geoCandidatesDiffStWires
The number of wires difference from fitted axial phi location.
void runFinderVersion3(const std::vector< double > &trackVariables, std::vector< std::vector< double > > &stTSs, const std::vector< std::vector< int > > &stTSDrift)
Uses the 3D finder for mode 3.
std::vector< std::vector< double > > * m_geoCandidatesPhi
The phi for stereo superlayer hits.
std::map< std::string, bool > m_mBool
Map to hold input options.
Belle2::TRGCDCJSignalData * m_commonData
For VHDL code.
double m_findPhiZMin
Holds the minimum value for fitted axial phi location between superlayers.
double m_cotEnd
Hough mesh cot end range.
double m_z0StepSize
Holds the size of Hough mesh for z0.
std::map< std::string, std::vector< signed long long > > m_mSavedSignals
Array of saved signals.
std::string m_outputVhdlDirname
Output directory for vhdl.
double m_findArcCosMax
Holds the maximum value for arc cos(radius/2/rho).
void destVersion3(void)
Destructs the 3D finder for mode 3.
double m_rr[4]
Holds the radius for stereo super layer in cm.
double m_cotStart
Hough finder variables.
bool ** m_hitMap
Hit map for all streo superlayers.
double m_bestCot
Finder results.
void initVersion1(const std::vector< float > &initVariables)
Init variables.
double m_stAxPhi[4]
The fitted axial phi for stereo superlayers.
double m_findRhoIntMin
Holds the minimum value for integer rho.
double m_findPhiZMax
Holds the maximum for fitted axial phi location between superlayers.
double m_findArcCosIntMax
Holds the maximum value for integer arc cos(radius/2/rho).
double m_anglest[4]
Holds the tan theta of streo super layer in radian.
int m_mode
Members.
double m_findPhi0Min
Holds the minimum value for phi0.
Hough3DFinder(void)
3D finder constructor.
double m_findPhi0IntMin
Holds the minimum value for integer phi0.
std::string m_inputFileName
Version3 (GeoFinder Integer space) GeoFinder input file for parameters.
int ** m_driftMap
Drift map for all streo superlayers.
void runFinderVersion2(const std::vector< double > &trackVariables, std::vector< std::vector< double > > &stTSs, const std::vector< std::vector< int > > &stTSDrift)
Uses the 3D finder for mode 2.
void setInputFileName(const std::string &inputFileName)
Sets the config file for the GeoFinder.
std::map< std::string, Belle2::TRGCDCJSignal > m_mSignalStorage
Map to hold JSignals.
std::string m_outputLutDirname
Output directory for luts.
float ** m_houghMeshDiff
Map that combines the z differences for all stereo superlayers.
void destVersion2(void)
Destructs the 3D finder for mode 2.
int m_nCotSteps
Number of Hough meshes for cot.
int m_nZ0Steps
Number of Hough meshes for z0.
double m_ztostraw[4]
Holds the length of for stereo super layer from center in cm.
~Hough3DFinder(void)
3D finder destructor.
double m_z0Start
Hough mesh z0 start range.
double m_findPhiZIntMax
Holds the maximum value for fitted integer axial phi location between superlayers.
int getMode(void)
Gets which 3D finder is used.
double m_bestTS[4]
The phi location of the found TSs.
double m_findRhoIntMax
Holds the maximum value for integer rho.
void initVersion2(std::vector< float > &initVariables)
Initializes the 3D finder for mode 2.
void setMode(int mode)
Sets which 3D finder to use.
double m_findArcCosIntMin
Holds the minimum value for integer arc cos(radius/2/rho).
float *** m_houghMeshLayerDiff
Hold the minimum z differences for the Hough vote in a stereo superlayer.
double m_minDiffHough
The minimum z diff between all Hough votes that have maximum vote number.
std::vector< std::vector< int > > * m_geoCandidatesIndex
GeoFinder Variables.
double m_foundPhiSt[4]
The phi location for streo superlayer using found z0 and cot values for track.
void runFinder(const std::vector< double > &trackVariables, std::vector< std::vector< double > > &stTSs, const std::vector< std::vector< int > > &stTSDrift)
Track variables.
double m_bestZ0
The found z0 value for track.
double m_cotStepSize
Holds the size of Hough mesh for cot.
void initVersion3(std::vector< float > &initVariables)
Initializes the 3D finder for mode 3.
double m_z0End
Hough mesh z0 end range.
void getValues(const std::string &input, std::vector< double > &result)
Gets results from the 3D finder.
void getHoughMeshLayer(bool ***&houghMeshLayer)
Gets the Hough plane for the 3D finder.
double m_findPhiZIntMin
Holds the minimum value for fitted integer axial phi location between superlayers.
double m_findArcCosMin
Holds the minimum value for arc cos(radius/2/rho).
double m_foundZ[4]
The z location for stereo superlayer using found z0 and cot values for track.
void destVersion1(void)
Destructs the 3D finder for mode 1.
std::map< std::string, std::vector< signed long long > > m_mSavedIoSignals
Array of I/O signals.
std::map< std::string, Belle2::TRGCDCJLUT * > m_mLutStorage
Map to hold JLuts.
double m_findPhi0IntMax
Holds the maximum value for integer phi0.
void destruct(void)
Destructs the 3D finder.
void runFinderVersion1(const std::vector< double > &trackVariables, const std::vector< std::vector< double > > &stTSs, const std::vector< double > &tsArcS, const std::vector< std::vector< double > > &tsZ)
Uses the 3D finder for mode 1.
double m_findRhoMax
Find min and max values Holds the maximum value for rho.
int ** m_houghMesh
Map that combines the number of Hough votes for all stereo superlayers.
int m_bestTSIndex[4]
The hit index of the found TSs.
void printToFile()
Utilities Function to print VHDL code.
Definition: JSignalData.cc:106
static void valuesToMapSignals(std::vector< std::tuple< std::string, double, int, double, double, int > > const &inValues, Belle2::TRGCDCJSignalData *inCommonData, std::map< std::string, Belle2::TRGCDCJSignal > &outMap)
Values => [name, value, bitwidth, min, max, clock] Changes values to signals.
Definition: JSignal.cc:2208
bool getPrintVhdl() const
Gets the status of m_printVhdl.
Definition: JSignalData.cc:75
static void ifElse(std::vector< std::pair< TRGCDCJSignal, std::vector< std::pair< TRGCDCJSignal *, TRGCDCJSignal > > > > &data, int targetClock)
If else implementation with target clock.
Definition: JSignal.cc:800
bool getPrintedToFile() const
Gets the status of m_printedToFile.
Definition: JSignalData.cc:80
void entryVhdlCode()
Function to print entry VHDL code.
Definition: JSignalData.cc:195
void signalsVhdlCode()
Function to print definition of signal VHDL code.
Definition: JSignalData.cc:178
void setVhdlOutputFile(const std::string &)
Sets the filename for VHDL output.
Definition: JSignalData.cc:45
void buffersVhdlCode()
Function to print buffer VHDL code.
Definition: JSignalData.cc:150
void setPrintVhdl(bool)
Sets if to print VHDL output.
Definition: JSignalData.cc:50
static void mapSignalsToValues(std::map< std::string, Belle2::TRGCDCJSignal >const &inMap, std::vector< std::pair< std::string, int > > const &inChoose, std::vector< std::tuple< std::string, double, int, double, double, int > > &outValues)
Choose => [signalName, FpgaEffects(=1)/NoFpgaEffects(=0)] Values => [name, value, bitwidth,...
Definition: JSignal.cc:2225
static TRGCDCJSignal comp(TRGCDCJSignal const &lhs, const std::string &operate, TRGCDCJSignal const &rhs)
Compare two signals.
Definition: JSignal.cc:1169
STL namespace.