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