Belle II Software  release-08-01-10
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_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 
59 void Hough3DFinder::setMode(int mode)
60 {
61  m_mode = mode;
62 }
63 
65 {
66  return m_mode;
67 }
68 
69 void 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 
134 void 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 
180 void 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 
211 void 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 
226 void 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 
262 void 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 
290  delete m_geoCandidatesIndex;
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
328 void 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 seperate 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
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
444  actualCot = houghCot * m_cotStepSize + m_cotStart;
445  actualZ0 = tempHoughZ0 * m_z0StepSize;
446  // To remove warning of actualCot and actualZ0.
447  if (false) cout << actualCot << actualZ0 << endl;
448 
449  for (int layer = 0; layer < 4; layer++) {
450  m_houghMesh[houghCot][houghZ0] += m_houghMeshLayer[houghCot][houghZ0][layer];
451  if (m_houghMeshLayerDiff[houghCot][houghZ0][layer] != 999) m_houghMeshDiff[houghCot][houghZ0] +=
452  m_houghMeshLayerDiff[houghCot][houghZ0][layer];
453  //if(houghMeshLayer[houghCot][houghZ0][layer]==1) hhough00->Fill(actualCot,actualZ0);
454  } // End of combining votes
455  } // End loop for houghZ0
456  } // End loop for houghCot
457 
458  // Find best vote. By finding highest votes and comparing all votes and pick minimum diff z.
459  m_houghMax = 0;
460  for (int houghCot = 0; houghCot < m_nCotSteps; houghCot++) {
461  for (int houghZ0 = 0; houghZ0 < m_nZ0Steps; houghZ0++) {
462  // Changes back values for minus
463  if (houghZ0 > (m_nZ0Steps - 1) / 2) {
464  tempHoughZ0 = (m_nZ0Steps - 1) / 2 - houghZ0;
465  } else { tempHoughZ0 = houghZ0;}
466  // Find highest vote
467  if (m_houghMax < m_houghMesh[houghCot][houghZ0]) {
468  m_houghMax = m_houghMesh[houghCot][houghZ0];
469  // If highest vote changes, need to initialize minZ0, minDiffHough
470  //minZ0 = 9999;
471  m_minDiffHough = 9999;
472  }
473  // When highest vote
474  if (m_houghMax == m_houghMesh[houghCot][houghZ0]) {
475  // For second finder version
476  // When z0 is minimum
477  //if(minZ0>abs(tempHoughZ0)) {
478  // cout<<"minZ0: "<<minZ0<<" tempHoughZ0: "<<tempHoughZ0<<endl;
479  // minZ0 = tempHoughZ0;
480  // bestCot = houghCot;
481  // bestZ0 = tempHoughZ0;
482  //}
483  // For third finder version
484  // When minDiffHough is minimum
485  if (m_minDiffHough > m_houghMeshDiff[houghCot][houghZ0]) {
486  m_minDiffHough = m_houghMeshDiff[houghCot][houghZ0];
487  m_bestCot = houghCot;
488  m_bestZ0 = tempHoughZ0;
489  }
490  }
491  } // End of houghZ0 loop
492  } // End of houghCot loop
493  //cout<<"JB bestCot: "<<m_bestCot<<" bestZ0: "<<m_bestZ0<<" "<<"#Votes: "<<m_houghMax<<endl;
494  //cout<<"JB foundCot: "<<m_bestCot*m_cotStepSize+m_cotStart<<" foundZ0: "<<m_bestZ0*m_z0StepSize<<endl;
495  //cout<<"mcCot: "<<mcCot<<" mcZ0: "<<mcZ0<<endl;
496 
497  // Finds the related TS from bestCot and bestZ0
498 
499  // Find z and phiSt from bestCot and bestZ0 (arcS is dependent to pT)
500  for (int i = 0; i < 4; i++) {
501  m_foundZ[i] = (m_bestCot * m_cotStepSize + m_cotStart) * tsArcS[i] + (m_bestZ0 * m_z0StepSize);
502  m_foundPhiSt[i] = fitPhi0 + charge * acos(m_rr[i] / 2 / rho) + 2 * asin((m_ztostraw[i] - m_foundZ[i]) * tan(
503  m_anglest[i]) / 2 / m_rr[i]);
504  if (m_foundPhiSt[i] > 2 * M_PI) m_foundPhiSt[i] -= 2 * M_PI;
505  if (m_foundPhiSt[i] < 0) m_foundPhiSt[i] += 2 * M_PI;
506  }
507  //cout<<"JB FoundPhiSt[0]: "<<m_foundPhiSt[0]<<" FoundPhiSt[1]: "<<m_foundPhiSt[1]<<" FoundPhiSt[2]: "<<m_foundPhiSt[2]<<" FoundPhiSt[3]: "<<m_foundPhiSt[3]<<endl;
508 
509  // Find closest phi out of canidates
510  double minDiff[4] = {999, 999, 999, 999};
511  for (unsigned iLayer = 0; iLayer < 4; iLayer++) {
512  for (unsigned iTS = 0; iTS < stTSs[iLayer].size(); iTS++) {
513  if (minDiff[iLayer] > abs(m_foundPhiSt[iLayer] - stTSs[iLayer][iTS])) {
514  minDiff[iLayer] = abs(m_foundPhiSt[iLayer] - stTSs[iLayer][iTS]);
515  m_bestTS[iLayer] = stTSs[iLayer][iTS];
516  m_bestTSIndex[iLayer] = (int)iTS;
517  }
518  }
519  }
520  //cout<<"JB BestPhiSt[0]: "<<m_bestTS[0]<<" BestPhiSt[1]: "<<m_bestTS[1]<<" BestPhiSt[2]: "<<m_bestTS[2]<<" BestPhiSt[3]: "<<m_bestTS[3]<<endl;
521 
522 }
523 
524 void Hough3DFinder::runFinderVersion2(const vector<double>& trackVariables, vector<vector<double> >& stTSs,
525  const std::vector<std::vector<int> >& stTSDrift)
526 {
527 
528  // Clear m_geoCandidatesIndex
529  for (int iLayer = 0; iLayer < 4; iLayer++) {
530  (*m_geoCandidatesIndex)[iLayer].clear();
531  (*m_geoCandidatesPhi)[iLayer].clear();
532  (*m_geoCandidatesDiffStWires)[iLayer].clear();
533  }
534 
535  int charge = (int)trackVariables[0];
536  double rho = trackVariables[1];
537  double fitPhi0 = trackVariables[2];
538  double tsDiffSt;
539 
540  //cout<<"charge:"<<charge<<" rho:"<<rho<<" fitPhi0:"<<fitPhi0<<endl;
541  for (int iLayer = 0; iLayer < 4; iLayer++) {
542  m_stAxPhi[iLayer] = Fitter3DUtility::calStAxPhi(charge, m_anglest[iLayer], m_ztostraw[iLayer], m_rr[iLayer], rho, fitPhi0);
543  //cout<<"iSt:"<<iLayer<<" ztostraw:"<<m_ztostraw[iLayer]<<" m_rr:"<<m_rr[iLayer]<<" stAxPhi:"<<m_stAxPhi[iLayer]<<endl;
544  //if(stTSs[iLayer].size()==0) cout<<"stTSs["<<iLayer<<"] is zero"<<endl;
545  for (unsigned iTS = 0; iTS < stTSs[iLayer].size(); iTS++) {
546  //int t_tdc = (stTSDrift[iLayer][iTS] >> 4);
547  //int t_lr = ((stTSDrift[iLayer][iTS] >> 2) & 3);
548  int t_priorityPosition = (stTSDrift[iLayer][iTS] & 3);
549  //int t_tsId = int(stTSs[iLayer][iTS]*m_nWires[iLayer]/2/2/M_PI+0.5);
550  //cout<<"iSt:"<<iLayer<<" tsId:"<<t_tsId<<" pp:"<<t_priorityPosition<<endl;
551  // Reject second priority TSs.
552  if (t_priorityPosition != 3) continue;
553  // Find number of wire difference
554  tsDiffSt = m_stAxPhi[iLayer] - stTSs[iLayer][iTS];
555  if (tsDiffSt > M_PI) tsDiffSt -= 2 * M_PI;
556  if (tsDiffSt < -M_PI) tsDiffSt += 2 * M_PI;
557  tsDiffSt = tsDiffSt / 2 / M_PI * m_nWires[iLayer] / 2;
558  //cout<<"JB ["<<iLayer<<"]["<<iTS<<"] tsDiffSt: "<<tsDiffSt<<" stTSs:"<<stTSs[iLayer][iTS]<<" rho: "<<rho<<" phi0: "<<fitPhi0<<" m_stAxPhi:"<<m_stAxPhi[iLayer]<<endl;
559  // Save index if condition is in 10 wires
560  if (iLayer % 2 == 0) {
561  if (tsDiffSt > 0 && tsDiffSt <= 10) {
562  (*m_geoCandidatesIndex)[iLayer].push_back(iTS);
563  (*m_geoCandidatesPhi)[iLayer].push_back(stTSs[iLayer][iTS]);
564  (*m_geoCandidatesDiffStWires)[iLayer].push_back(tsDiffSt);
565  }
566  } else {
567  if (tsDiffSt < 0 && tsDiffSt >= -10) {
568  (*m_geoCandidatesIndex)[iLayer].push_back(iTS);
569  (*m_geoCandidatesPhi)[iLayer].push_back(stTSs[iLayer][iTS]);
570  (*m_geoCandidatesDiffStWires)[iLayer].push_back(tsDiffSt);
571  }
572  } // End of saving index
573 
574  } // Candidate loop
575  } // Layer loop
576 
578  //for( int iLayer=0; iLayer<4; iLayer++){
579  // cout<<"[geoFinder] iSt:"<<iLayer<<" nSegments:"<<(*m_geoCandidatesIndex)[iLayer].size()<<endl;
580  // for(unsigned iTS=0; iTS<(*m_geoCandidatesIndex)[iLayer].size(); iTS++){
581  // //cout<<"cand ["<<iLayer<<"]["<<iTS<<"]: "<<(*m_geoCandidatesIndex)[iLayer][iTS]<<endl;
582  // cout<<"cand ["<<iLayer<<"]["<<iTS<<"]: "<<(*m_geoCandidatesPhi)[iLayer][iTS]<<endl;
583  // }
584  //}
585 
586  // Pick middle candidate if multiple candidates
587  //double meanWireDiff[4] = { 5, 5, 5, 5 };
588  // z=0 wireDiff
589  //double meanWireDiff[4] = { 3.08452, 2.61314, 2.84096, 3.06938 };
590  // mean wire diff
591  const double meanWireDiff[4] = { 3.68186, 3.3542, 3.9099, 4.48263 };
592  for (int iLayer = 0; iLayer < 4; iLayer++) {
593  if ((*m_geoCandidatesIndex)[iLayer].size() == 0) {
594  //cout<<"No St Candidate in GeoFinder"<<endl;
595  m_bestTS[iLayer] = 999;
596  m_bestTSIndex[iLayer] = 999;
597  } else {
598  double bestDiff = 999;
599  for (int iTS = 0; iTS < int((*m_geoCandidatesIndex)[iLayer].size()); iTS++) {
600  tsDiffSt = m_stAxPhi[iLayer] - stTSs[iLayer][(*m_geoCandidatesIndex)[iLayer][iTS]];
601  if (tsDiffSt > M_PI) tsDiffSt -= 2 * M_PI;
602  if (tsDiffSt < -M_PI) tsDiffSt += 2 * M_PI;
603  tsDiffSt = tsDiffSt / 2 / M_PI * m_nWires[iLayer] / 2;
604  // Pick the better TS
605  //if(abs(abs(tsDiffSt)-5) < bestDiff){
606  if (abs(abs(tsDiffSt) - meanWireDiff[iLayer]) < bestDiff) {
607  //bestDiff = abs(abs(tsDiffSt)-5);
608  bestDiff = abs(abs(tsDiffSt) - meanWireDiff[iLayer]);
609  m_bestTS[iLayer] = stTSs[iLayer][(*m_geoCandidatesIndex)[iLayer][iTS]];
610  m_bestTSIndex[iLayer] = (*m_geoCandidatesIndex)[iLayer][iTS];
611  }
612  } // TS loop
613  } // If there is a TS candidate
614  } // Layer loop
615 
616 
617 
619  //for( int iLayer=0; iLayer<4; iLayer++){
620  // cout<<"best ["<<iLayer<<"]: "<<m_bestTSIndex[iLayer]<<" "<<m_bestTS[iLayer]<<endl;
621  //}
622 
623 }
624 
625 void Hough3DFinder::runFinderVersion3(const vector<double>& trackVariables, vector<vector<double> >& stTSs,
626  const vector<vector<int> >& stTSDrift)
627 {
628 
629  int m_verboseFlag = m_mBool["fVerbose"];
630 
631  if (m_verboseFlag) cout << "####geoFinder start####" << endl;
632 
633  // Clear m_geoCandidatesIndex
634  for (int iLayer = 0; iLayer < 4; iLayer++) {
635  (*m_geoCandidatesPhi)[iLayer].clear();
636  (*m_geoCandidatesIndex)[iLayer].clear();
637  (*m_geoCandidatesDiffStWires)[iLayer].clear();
638  }
639  // Clear hit map for track
640  for (int iLayer = 0; iLayer < 4; iLayer++) {
641  for (int iTS = 0; iTS < m_nWires[iLayer] / 2; iTS++) {
642  m_hitMap[iLayer][iTS] = 0;
643  }
644  }
645  // Clear drift map for track
646  for (int iSt = 0; iSt < 4; iSt++) {
647  for (int iTS = 0; iTS < m_nWires[iSt] / 2; iTS++) {
648  m_driftMap[iSt][iTS] = 0;
649  }
650  }
651 
652  // 2D Track Variables
653  int charge = (int)trackVariables[0];
654  double rho = trackVariables[1];
655  double fitPhi0 = trackVariables[2];
656 
657  // Fill hitMap and driftMap
658  int iHitTS;
659  int driftInfo;
660  for (unsigned iLayer = 0; iLayer < 4; iLayer++) {
661  //cout<<"["<<iLayer<<"] size:"<<stTSs[iLayer].size()<<endl;
662  for (unsigned iTS = 0; iTS < stTSs[iLayer].size(); iTS++) {
663  iHitTS = int(stTSs[iLayer][iTS] * m_nWires[iLayer] / 2 / 2 / M_PI + 0.5);
664  driftInfo = stTSDrift[iLayer][iTS];
665  if (m_verboseFlag) cout << "[" << iLayer << "] TSId: " << iHitTS << " stTSs: " << stTSs[iLayer][iTS] << " driftInfo:" << driftInfo
666  << " priorityPosition:" << (driftInfo & 3) << endl;
667  //cout<<iHitTS*2*M_PI/m_nWires[iLayer]*2<<endl;
668  m_hitMap[iLayer][iHitTS] = 1;
669  m_driftMap[iLayer][iHitTS] = driftInfo;
670  } // End iTS
671  } // End layer
672 
674  //for(int iLayer=0; iLayer<4; iLayer++) {
675  // cout<<"["<<iLayer<<"]["<<m_nWires[iLayer]/2<<"]";
676  // for(int iTS=m_nWires[iLayer]/2-1; iTS>=0; iTS--) {
677  // cout<<m_hitMap[iLayer][iTS];
678  // }
679  // cout<<endl;
680  //} // End layer
682  //for(int iLayer=0; iLayer<4; iLayer++) {
683  // cout<<"["<<iLayer<<"]["<<m_nWires[iLayer]/2<<"]"<<endl;;
684  // for(int iTS=m_nWires[iLayer]/2-1; iTS>=0; iTS--) {
685  // cout<<" ["<<iTS<<"]: "<<m_driftMap[iLayer][iTS]<<endl;;
686  // }
687  // cout<<endl;
688  //} // End layer
689 
691  //for( int iLayer=0; iLayer<4; iLayer++) {
692  // double t_phiAx = acos(m_rr[iLayer]/(2*rho));
693  // double t_dPhiAx = 0;
694  // double t_dPhiAx_c = 0;
695  // if(charge==1) t_dPhiAx = t_phiAx+fitPhi0;
696  // else t_dPhiAx = -t_phiAx+fitPhi0;
697  // if(t_dPhiAx < 0) t_dPhiAx_c = t_dPhiAx + 2* M_PI;
698  // else if (t_dPhiAx > 2*M_PI) t_dPhiAx_c = t_dPhiAx - 2*M_PI;
699  // else t_dPhiAx_c = t_dPhiAx;
700  // double t_dPhiAxWire = 0;
701  // if( iLayer%2 == 0 ) t_dPhiAxWire = int(t_dPhiAx_c/2/M_PI*m_nWires[iLayer]/2);
702  // else t_dPhiAxWire = int(t_dPhiAx_c/2/M_PI*m_nWires[iLayer]/2 + 1);
703  // cout<<"iSt:"<<iLayer<<" phiAx:"<<t_phiAx<<" phi0:"<<fitPhi0<<" dPhiAx:"<<t_dPhiAx<<" charge:"<<charge<<endl;
704  // cout<<" dPhiAx_c:"<<t_dPhiAx_c<<" dPhiAxWire:"<<t_dPhiAxWire<<endl;
705  //}
706 
707  // Will use cm unit.
708  std::map<std::string, std::vector<double> > mConstV;
709  std::map<std::string, double > mConstD;
710  std::map<std::string, double > mDouble;
711 
712  if (m_commonData == 0) {
714  }
715  // Setup firmware parameters
716  /* cppcheck-suppress variableScope */
717  double phiMax = M_PI;
718  /* cppcheck-suppress variableScope */
719  double phiMin = -M_PI;
720  int phiBitSize = 13;
721  // pt = 0.3*1.5*rho*0.01;
722  /* cppcheck-suppress variableScope */
723  double rhoMin = 20;
724  double rhoMax = 2500;
725  int rhoBitSize = 11;
726 
727  // Constraints used in below code.
728  mConstV["rr"] = vector<double> (9);
729  mConstV["rr3D"] = vector<double> (4);
730  mConstV["nTSs"] = vector<double> (9);
731  for (unsigned iSt = 0; iSt < 4; iSt++) {
732  // Convert unit to cm.
733  mConstV["rr"][2 * iSt + 1] = m_rr[iSt] * 100;
734  mConstV["rr3D"][iSt] = m_rr[iSt] * 100;
735  mConstV["nTSs"][2 * iSt + 1] = m_nWires[iSt] / 2;
736  }
737  mConstD["acosLUTInBitSize"] = rhoBitSize;
738  mConstD["acosLUTOutBitSize"] = phiBitSize - 1;
739  mConstD["Trg_PI"] = M_PI;
740 
741  // Constrain rho to rhoMax. For removing warnings when changing to signals.
742  {
743  mDouble["rho"] = rho * 100;
744  if (mDouble["rho"] > rhoMax) {
745  mDouble["rho"] = rhoMax;
746  mDouble["pt"] = rhoMax * 0.3 * 1.5 * 0.01;
747  }
748  }
749  // Constrain phi0 to [-pi, pi]
750  {
751  mDouble["phi0"] = fitPhi0;
752  bool rangeFail = 1;
753  while (rangeFail) {
754  if (mDouble["phi0"] > mConstD["Trg_PI"]) mDouble["phi0"] -= 2 * mConstD["Trg_PI"];
755  else if (mDouble["phi0"] < -mConstD["Trg_PI"]) mDouble["phi0"] += 2 * mConstD["Trg_PI"];
756  else rangeFail = 0;
757  }
758  }
759 
760  // Change to Signals. Convert rho to cm unit.
761  {
762  vector<tuple<string, double, int, double, double, int> > t_values = {
763  make_tuple("phi0", mDouble["phi0"], phiBitSize, phiMin, phiMax, 0),
764  make_tuple("rho", mDouble["rho"], rhoBitSize, rhoMin, rhoMax, 0),
765  make_tuple("charge", (int)(charge == 1 ? 1 : 0), 1, 0, 1.5, 0),
766  };
768  }
769  //cout<<"<<<phi0>>>"<<endl; m_mSignalStorage["phi0"].dump();
770  //cout<<"<<<rho>>>"<<endl; m_mSignalStorage["rho"].dump();
771  //cout<<"<<<charge>>>"<<endl; m_mSignalStorage["charge"].dump();
772 
773  // Constrain rho
775  // phiAx = arcos(r/2R).
776  // Make min max constants for lut.
777  if (m_mSignalStorage.find("invPhiAxMin_0") == m_mSignalStorage.end()) {
778  for (unsigned iSt = 0; iSt < 4; iSt++) {
779  string t_invMinName = "invPhiAxMin_" + to_string(iSt);
780  double t_actual = m_mSignalStorage["rho_c_" + to_string(iSt)].getMinActual();
781  double t_toReal = m_mSignalStorage["rho_c_" + to_string(iSt)].getToReal();
782  m_mSignalStorage[t_invMinName] = Belle2::TRGCDCJSignal(t_actual, t_toReal, m_commonData);
783  string t_invMaxName = "invPhiAxMax_" + to_string(iSt);
784  t_actual = m_mSignalStorage["rho_c_" + to_string(iSt)].getMaxActual();
785  m_mSignalStorage[t_invMaxName] = Belle2::TRGCDCJSignal(t_actual, t_toReal, m_commonData);
786  }
787  }
788  //for(int iSt=0; iSt<4; iSt++) {cout<<"<<<invPhiAxMin_"<<iSt<<">>>"<<endl; m_mSignalStorage["invPhiAxMin_"+to_string(iSt)].dump();}
789  //for(int iSt=0; iSt<4; iSt++) {cout<<"<<<invPhiAxMax_"<<iSt<<">>>"<<endl; m_mSignalStorage["invPhiAxMax_"+to_string(iSt)].dump();}
790  // Generate LUT(phiAx[i]=acos(rr[i]/2/rho)).
791  for (unsigned iSt = 0; iSt < 4; iSt++) {
792  string t_valueName = "phiAx_" + to_string(iSt);
793  string t_minName = "phiAxMin_" + to_string(iSt);
794  string t_maxName = "phiAxMax_" + to_string(iSt);
795  string t_invMinName = "invPhiAxMin_" + to_string(iSt);
796  string t_invMaxName = "invPhiAxMax_" + to_string(iSt);
797  if (!m_mLutStorage.count(t_valueName)) {
798  m_mLutStorage[t_valueName] = new Belle2::TRGCDCJLUT(t_valueName);
799  // Lambda can not copy maps.
800  double t_parameter = mConstV.at("rr3D")[iSt];
801  m_mLutStorage[t_valueName]->setFloatFunction(
802  [ = ](double aValue) -> double{return acos(t_parameter / 2 / aValue);},
803  m_mSignalStorage["rho_c_" + to_string(iSt)],
804  m_mSignalStorage[t_invMinName], m_mSignalStorage[t_invMaxName], m_mSignalStorage["phi0"].getToReal(),
805  (int)mConstD.at("acosLUTInBitSize"), (int)mConstD.at("acosLUTOutBitSize"));
806  //m_mLutStorage[t_valueName]->makeCOE("./LutData/geoFinder_"+t_valueName+".coe");
807  }
808  }
809  // phiAx[i] = acos(rr[i]/2/rho).
810  // Operate using LUT(phiAx[i]).
811  for (unsigned iSt = 0; iSt < 4; iSt++) {
812  // Set output name
813  string t_valueName = "phiAx_" + to_string(iSt);
814  m_mLutStorage[t_valueName]->operate(m_mSignalStorage["rho_c_" + to_string(iSt)], m_mSignalStorage[t_valueName]);
815  }
816  //for(int iSt=0; iSt<4; iSt++) {cout<<"<<<phiAx_"<<iSt<<">>>"<<endl; m_mSignalStorage["phiAx_"+to_string(iSt)].dump();}
817  // dPhiAx[i] = +-phiAx[i] + phi0
818  {
819  // Create data for ifElse
820  vector<pair<Belle2::TRGCDCJSignal, vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > > > t_data;
821  // Compare
823  m_commonData), "=", m_mSignalStorage["charge"]);
824  // Assignments
825  vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > t_assigns = {
826  make_pair(&m_mSignalStorage["dPhiAx_0"], m_mSignalStorage["phiAx_0"] + m_mSignalStorage["phi0"]),
827  make_pair(&m_mSignalStorage["dPhiAx_1"], m_mSignalStorage["phiAx_1"] + m_mSignalStorage["phi0"]),
828  make_pair(&m_mSignalStorage["dPhiAx_2"], m_mSignalStorage["phiAx_2"] + m_mSignalStorage["phi0"]),
829  make_pair(&m_mSignalStorage["dPhiAx_3"], m_mSignalStorage["phiAx_3"] + m_mSignalStorage["phi0"])
830  };
831  // Push to data.
832  t_data.push_back(make_pair(t_compare, t_assigns));
833  // Compare
834  t_compare = Belle2::TRGCDCJSignal();
835  // Assignments
836  t_assigns = {
837  make_pair(&m_mSignalStorage["dPhiAx_0"], -m_mSignalStorage["phiAx_0"] + m_mSignalStorage["phi0"]),
838  make_pair(&m_mSignalStorage["dPhiAx_1"], -m_mSignalStorage["phiAx_1"] + m_mSignalStorage["phi0"]),
839  make_pair(&m_mSignalStorage["dPhiAx_2"], -m_mSignalStorage["phiAx_2"] + m_mSignalStorage["phi0"]),
840  make_pair(&m_mSignalStorage["dPhiAx_3"], -m_mSignalStorage["phiAx_3"] + m_mSignalStorage["phi0"])
841  };
842  // Push to data.
843  t_data.push_back(make_pair(t_compare, t_assigns));
844  // Process ifElse data.
846  }
847  //cout<<"<<<phi0>>>"<<endl; m_mSignalStorage["phi0"].dump();
848  //cout<<"<<<charge>>>"<<endl; m_mSignalStorage["charge"].dump();
849  //for(int iSt=0; iSt<4; iSt++) {cout<<"<<<dPhiAx_"<<iSt<<">>>"<<endl; m_mSignalStorage["dPhiAx_"+to_string(iSt)].dump();}
850 
851  // This could be needed in the future if efficiency is low.
852  // To use this code, change dPhiAx to dPhiAx_m when constraining dPhiAx below.
854  //for(unsigned iSt=0; iSt<4; iSt++) {
855  // double wirePhiUnit = 2 * mConstD["Trg_PI"] / mConstV["nTSs"][2*iSt+1];
856  // if (iSt%2 == 0) {
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  // } else {
859  // 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);
860  // }
861  //}
862 
863  //for(int iSt=0; iSt<4; iSt++) {cout<<"<<<dPhiAx_m_"<<iSt<<">>>"<<endl; m_mSignalStorage["dPhiAx_m_"+to_string(iSt)].dump();}
864  // Constrain dPhiAx[i] to [0, 2pi)
865  if (m_mSignalStorage.find("dPhiAxMax_0") == m_mSignalStorage.end()) {
866  for (unsigned iSt = 0; iSt < 4; iSt++) {
867  string t_valueName = "dPhiAx_" + to_string(iSt);
868  //string t_valueName = "dPhiAx_m_" + to_string(iSt);
869  string t_maxName = "dPhiAxMax_" + to_string(iSt);
870  string t_minName = "dPhiAxMin_" + to_string(iSt);
871  string t_2PiName = "dPhiAx2Pi_" + to_string(iSt);
872  m_mSignalStorage[t_maxName] = Belle2::TRGCDCJSignal(2 * mConstD.at("Trg_PI"), m_mSignalStorage[t_valueName].getToReal(),
873  m_commonData);
874  m_mSignalStorage[t_minName] = Belle2::TRGCDCJSignal(0, m_mSignalStorage[t_valueName].getToReal(), m_commonData);
875  m_mSignalStorage[t_2PiName] = Belle2::TRGCDCJSignal(2 * mConstD.at("Trg_PI"), m_mSignalStorage[t_valueName].getToReal(),
876  m_commonData);
877  }
878  }
879  for (unsigned iSt = 0; iSt < 4; iSt++) {
880  string t_in1Name = "dPhiAx_" + to_string(iSt);
881  //string t_in1Name = "dPhiAx_m_" + to_string(iSt);
882  string t_valueName = "dPhiAx_c_" + to_string(iSt);
883  string t_maxName = "dPhiAxMax_" + to_string(iSt);
884  string t_minName = "dPhiAxMin_" + to_string(iSt);
885  string t_2PiName = "dPhiAx2Pi_" + to_string(iSt);
886  // Create data for ifElse
887  vector<pair<Belle2::TRGCDCJSignal, vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > > > t_data;
888  // Compare (dPhiAx_m >= 2*pi)
890  // Assignments (dPhiAx_c <= dPhiAx_m - 2*pi)
891  vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > t_assigns = {
892  make_pair(&m_mSignalStorage[t_valueName], (m_mSignalStorage[t_in1Name] - m_mSignalStorage[t_2PiName]).limit(m_mSignalStorage[t_minName], m_mSignalStorage[t_maxName])),
893  };
894  // Push to data.
895  t_data.push_back(make_pair(t_compare, t_assigns));
896  // Compare (dPhiAx_m >= 0)
897  t_compare = Belle2::TRGCDCJSignal::comp(m_mSignalStorage[t_in1Name], ">=", m_mSignalStorage[t_minName]);
898  // Assignments (dPhiAx_c <= dPhiAx_m)
899  t_assigns = {
900  make_pair(&m_mSignalStorage[t_valueName], m_mSignalStorage[t_in1Name].limit(m_mSignalStorage[t_minName], m_mSignalStorage[t_maxName])),
901  };
902  // Push to data.
903  t_data.push_back(make_pair(t_compare, t_assigns));
904  // Compare (dPhiAx_m < 0)
905  t_compare = Belle2::TRGCDCJSignal();
906  // Assignments (dPhiAx_c <= dPhiAx_m + 2*pi)
907  t_assigns = {
908  make_pair(&m_mSignalStorage[t_valueName], (m_mSignalStorage[t_in1Name] + m_mSignalStorage[t_2PiName]).limit(m_mSignalStorage[t_minName], m_mSignalStorage[t_maxName])),
909  };
910  // Push to data.
911  t_data.push_back(make_pair(t_compare, t_assigns));
912  // Process ifElse data.
914  }
915  //for(int iSt=0; iSt<4; iSt++) {cout<<"<<<dPhiAxMax_"<<iSt<<">>>"<<endl; m_mSignalStorage["dPhiAxMax_"+to_string(iSt)].dump();}
916  //for(int iSt=0; iSt<4; iSt++) {cout<<"<<<dPhiAxMin_"<<iSt<<">>>"<<endl; m_mSignalStorage["dPhiAxMin_"+to_string(iSt)].dump();}
917  //for(int iSt=0; iSt<4; iSt++) {cout<<"<<<dPhiAx2Pi_"<<iSt<<">>>"<<endl; m_mSignalStorage["dPhiAx2Pi_"+to_string(iSt)].dump();}
918  //for(int iSt=0; iSt<4; iSt++) {cout<<"<<<dPhiAx_c_"<<iSt<<">>>"<<endl; m_mSignalStorage["dPhiAx_c_"+to_string(iSt)].dump();}
919  // Change to wire space
920  // Make wireFactor constants
921  if (m_mSignalStorage.find("wireFactor_0") == m_mSignalStorage.end()) {
922  for (unsigned iSt = 0; iSt < 4; iSt++) {
923  int nShiftBits = int(log(pow(2, 24) * 2 * mConstD.at("Trg_PI") / mConstV.at("nTSs")[2 * iSt + 1] /
924  m_mSignalStorage["phi0"].getToReal()) / log(2));
925  string t_name;
926  t_name = "wireFactor_" + to_string(iSt);
927  m_mSignalStorage[t_name] = Belle2::TRGCDCJSignal(mConstV.at("nTSs")[2 * iSt + 1] / 2 / mConstD.at("Trg_PI"),
928  1 / m_mSignalStorage["phi0"].getToReal() / pow(2, nShiftBits), m_commonData);
929  }
930  }
931  //for(int iSt=0; iSt<4; iSt++) {cout<<"<<<wireFactor_"<<iSt<<">>>"<<endl; m_mSignalStorage["wireFactor_"+to_string(iSt)].dump();}
932  // wireDPhiAx[i] <= dPhiAx_c[i] * wireFactor[i]
933  // Shift to find actual wire.
934  for (unsigned iSt = 0; iSt < 4; iSt++) {
935  int nShiftBits = log(1 / m_mSignalStorage["dPhiAx_c_" + to_string(iSt)].getToReal() / m_mSignalStorage["wireFactor_" + to_string(
936  iSt)].getToReal()) / log(2);
937  m_mSignalStorage["wireDPhiAx_" + to_string(iSt)] <= (m_mSignalStorage["dPhiAx_c_" + to_string(
938  iSt)] * m_mSignalStorage["wireFactor_" + to_string(iSt)]).shift(nShiftBits, 0);
939  }
940  //for(int iSt=0; iSt<4; iSt++) {cout<<"<<<wireDPhiAx_"<<iSt<<">>>"<<endl; m_mSignalStorage["wireDPhiAx_"+to_string(iSt)].dump();}
941  // Select TS window from wireDPhiAx
942  vector< int > nCandidates = { 10, 10, 10, 13 };
943  // stCandHitmap[iSt][iTS]
944  vector<vector<bool> > t_stCandHitmap(4);
945  for (unsigned iSt = 0; iSt < 4; iSt++) t_stCandHitmap[iSt] = vector<bool> (nCandidates[iSt]);
946  // Last driftInfo is for showing no hit.
947  vector<vector<int> > t_stCandDriftmap(4);
948  for (unsigned iSt = 0; iSt < 4; iSt++) t_stCandDriftmap[iSt] = vector<int> (nCandidates[iSt] + 1);
949  // resultValues = [name, value, bitwidth, min, max, clock]
950  vector<tuple<string, double, int, double, double, int> > resultValues;
951  {
952  vector<pair<string, int> > t_chooseSignals = {
953  make_pair("wireDPhiAx_0", 1), make_pair("wireDPhiAx_1", 1), make_pair("wireDPhiAx_2", 1), make_pair("wireDPhiAx_3", 1)
954  };
955  Belle2::TRGCDCJSignal::mapSignalsToValues(m_mSignalStorage, t_chooseSignals, resultValues);
956  }
957  vector<double> t_wireDPhiAx = {std::get<1>(resultValues[0]), std::get<1>(resultValues[1]), std::get<1>(resultValues[2]), std::get<1>(resultValues[3])};
958  // Print wireDPhiAx
959  //for(unsigned iSt=0; iSt<4; iSt++) cout<<"iSt:"<<iSt<<" t_wireDPhiAx:"<<t_wireDPhiAx[iSt]<<endl;
960  for (int iSt = 0; iSt < 4; iSt++) {
961  int indexTS = t_wireDPhiAx[iSt];
962  for (int iTS = 0; iTS < nCandidates[iSt]; iTS++) {
963  // Copy 10 TSs from hitmap and driftmap
964  t_stCandHitmap[iSt][iTS] = m_hitMap[iSt][indexTS];
965  t_stCandDriftmap[iSt][iTS] = m_driftMap[iSt][indexTS];
966  // Move indexTS
967  if (iSt % 2 == 0) {
968  indexTS--;
969  // If index is below 0 deg goto 360-delta deg
970  if (indexTS < 0) indexTS = m_nWires[iSt] / 2 - 1;
971  } else {
972  indexTS++;
973  // If index is 360 deg goto 0 deg
974  if (indexTS >= m_nWires[iSt] / 2) indexTS = 0;
975  }
976  }
977  }
978  // Print stCandHitMap
979  if (m_verboseFlag) {
980  for (unsigned iLayer = 0; iLayer < 4; iLayer++) {
981  cout << "iSt:" << iLayer << " t_wireDPhiAx:" << t_wireDPhiAx[iLayer];
982  int t_endTSId = 0;
983  if (iLayer % 2 == 0) t_endTSId = t_wireDPhiAx[iLayer] - (nCandidates[iLayer] - 1);
984  else t_endTSId = t_wireDPhiAx[iLayer] + (nCandidates[iLayer] - 1);
985  if (t_endTSId < 0) t_endTSId += mConstV["nTSs"][2 * iLayer + 1];
986  else if (t_endTSId >= mConstV["nTSs"][2 * iLayer + 1]) t_endTSId -= mConstV["nTSs"][2 * iLayer + 1];
987  //cout<<" endWindow:"<<t_endTSId<<endl;
988  cout << " t_stCandHitmap[" << iLayer << "]: " << t_endTSId << "=> ";
989  for (int iTS = nCandidates[iLayer] - 1; iTS >= 0; iTS--) {
990  cout << t_stCandHitmap[iLayer][iTS];
991  }
992  cout << " <= " << t_wireDPhiAx[iLayer] << endl;
993  }
995  //for(unsigned iSt=0; iSt<4; iSt++){
996  // for(int iTS=0; iTS<nCandidates[iSt]; iTS++){
997  // cout<<"iSt:"<<iSt<<" iTS:"<<iTS<<" stCandDriftMap:"<<t_stCandDriftmap[iSt][iTS]<<endl;
998  // }
999  //}
1000  }
1001  vector<double> t_targetWirePosition = { 3, 2, 3, 3};
1002  // When bestRelTsId is nCandidates, it means no hit.
1003  vector<int> t_bestRelTSId(4);
1004  for (unsigned iSt = 0; iSt < 4; iSt++) t_bestRelTSId[iSt] = nCandidates[iSt];
1005  vector<int> t_bestDiff = {16, 16, 16, 16};
1006  // Select best TS between 10 wires.
1007  for (unsigned iSt = 0; iSt < 4; iSt++) {
1008  for (int iTS = 0; iTS < nCandidates[iSt]; iTS++) {
1009  int t_priorityPosition = (t_stCandDriftmap[iSt][iTS] & 3);
1010  //cout<<"iSt:"<<iSt<<" iTS:"<<iTS<<" t_priorityPosition:"<<t_priorityPosition<<endl;
1011  if (t_stCandHitmap[iSt][iTS] == 0) continue;
1012  if (t_priorityPosition != 3) continue;
1013  double tsDiffTarget = fabs(t_targetWirePosition[iSt] - iTS);
1014  if (t_bestDiff[iSt] > tsDiffTarget) {
1015  t_bestDiff[iSt] = tsDiffTarget;
1016  t_bestRelTSId[iSt] = iTS;
1017  }
1018  }
1019  }
1020  // Print best relative output
1021  if (m_verboseFlag) {
1022  for (unsigned iSt = 0; iSt < 4;
1023  iSt++) cout << "iSt:" << iSt << " bestRelTS:" << t_bestRelTSId[iSt] << " diff:" << t_bestDiff[iSt] << endl;
1024  }
1025  // Convert best relative TS id to best TS id
1026  vector<double> t_bestTSId(4);
1027  for (unsigned iSt = 0; iSt < 4; iSt++) {
1028  if (iSt % 2 == 0) t_bestTSId[iSt] = t_wireDPhiAx[iSt] - t_bestRelTSId[iSt];
1029  else t_bestTSId[iSt] = t_wireDPhiAx[iSt] + t_bestRelTSId[iSt];
1030  }
1031  // Get bestDriftInfo
1032  vector<double> t_bestDriftInfo(4);
1033  for (unsigned iSt = 0; iSt < 4; iSt++) t_bestDriftInfo[iSt] = t_stCandDriftmap[iSt][t_bestRelTSId[iSt]];
1035  //for(unsigned iSt=0; iSt<4; iSt++) cout<<"iSt:"<<iSt<<" bestTS:"<<t_bestTSId[iSt]<<endl;
1036  // Print best drift info
1037  if (m_verboseFlag) {
1038  for (unsigned iSt = 0; iSt < 4; iSt++)cout << "iSt:" << iSt << " bestDriftInfo:" << t_bestDriftInfo[iSt] << endl;
1039  }
1040 
1041  // Constrain bestTS to [0, nTS-1]
1042  vector<double> t_bestTSId_c(4);
1043  for (unsigned iSt = 0; iSt < 4; iSt++) {
1044  if (t_bestTSId[iSt] >= mConstV["nTSs"][2 * iSt + 1]) t_bestTSId_c[iSt] = t_bestTSId[iSt] - mConstV["nTSs"][2 * iSt + 1];
1045  else if (t_bestTSId[iSt] < 0) t_bestTSId_c[iSt] = t_bestTSId[iSt] + mConstV["nTSs"][2 * iSt + 1];
1046  else t_bestTSId_c[iSt] = t_bestTSId[iSt];
1047  }
1048  // Print best constrained output
1049  if (m_verboseFlag) {
1050  for (unsigned iSt = 0; iSt < 4; iSt++)cout << "iSt:" << iSt << " bestTS_c:" << t_bestTSId_c[iSt] << endl;
1051  }
1052 
1053  // Save to m_bestTS
1054  for (unsigned iSt = 0; iSt < 4; iSt++) {
1055  if (t_bestDriftInfo[iSt] != 0) m_bestTS[iSt] = t_bestTSId_c[iSt] * 2 * mConstD["Trg_PI"] / mConstV["nTSs"][2 * iSt + 1] ;
1056  else m_bestTS[iSt] = 999;
1057  }
1058  //if(m_verboseFlag) {
1059  // for(unsigned iSt=0; iSt<4; iSt++)cout<<"iSt:"<<iSt<<" m_bestTS:"<<m_bestTS[iSt]<<endl;
1060  //}
1061  // Search and save to m_bestTSIndex
1062  for (unsigned iSt = 0; iSt < 4; iSt++) {
1063  if (t_bestDriftInfo[iSt] == 0) {
1064  m_bestTSIndex[iSt] = 999;
1065  } else {
1066  for (unsigned iTS = 0; iTS < stTSs[iSt].size(); iTS++) {
1067  if (fabs(m_bestTS[iSt] - stTSs[iSt][iTS]) < 0.0001) {
1068  m_bestTSIndex[iSt] = iTS;
1069  break;
1070  }
1071  }
1072  }
1073  }
1074  //if(m_verboseFlag) {
1075  // for(unsigned iSt=0; iSt<4; iSt++)cout<<"iSt:"<<iSt<<" m_bestTSIndex:"<<m_bestTSIndex[iSt]<<endl;
1076  //}
1077 
1078  // Post handling of signals.
1079  // Name all signals.
1080  if ((*m_mSignalStorage.begin()).second.getName() == "") {
1081  for (auto it = m_mSignalStorage.begin(); it != m_mSignalStorage.end(); ++it) {
1082  (*it).second.setName((*it).first);
1083  }
1084  }
1093 
1094  if (m_mBool["fVHDLFile"]) {
1095  // Check if there is a name.
1096  if ((*m_mSignalStorage.begin()).second.getName() != "") {
1097  // Saves to file only one time.
1098  // Print Vhdl and Coe
1099  if (m_commonData->getPrintedToFile() == 0) {
1100  if (m_commonData->getPrintVhdl() == 0) {
1103  } else {
1109  // Print LUTs.
1110  for (map<string, Belle2::TRGCDCJLUT*>::iterator it = m_mLutStorage.begin(); it != m_mLutStorage.end(); ++it) {
1111  it->second->makeCOE(m_outputLutDirname + "/" + it->first + ".coe");
1112  //it->second->makeCOE(it->first+".coe");
1113  }
1114  }
1115  }
1116 
1117  // Saves values to memory. Wrote to file at terminate().
1118  // Save all signals to m_mSavedSignals. Limit to 10 times.
1119  if ((*m_mSavedSignals.begin()).second.size() < 10 || m_mSavedSignals.empty()) {
1120  for (auto it = m_mSignalStorage.begin(); it != m_mSignalStorage.end(); ++it) {
1121  m_mSavedSignals[(*it).first].push_back((*it).second.getInt());
1122  }
1123  }
1124 
1125  // Saves values to memory. Wrote to file at terminate().
1126  // Save input output signals. Limit to 1024.
1127  if ((*m_mSavedIoSignals.begin()).second.size() < 1025 || m_mSavedIoSignals.empty()) {
1128  m_mSavedIoSignals["in_phi0"].push_back(m_mSignalStorage["phi0"].getInt());
1129  m_mSavedIoSignals["in_rho"].push_back(m_mSignalStorage["rho"].getInt());
1130  m_mSavedIoSignals["in_charge"].push_back(m_mSignalStorage["charge"].getInt());
1131  for (unsigned iSt = 0; iSt < 4;
1132  iSt++) m_mSavedIoSignals["out_wireDPhiAx_" + to_string(iSt)].push_back(m_mSignalStorage["wireDPhiAx_" + to_string(iSt)].getInt());
1133  }
1134 
1135  }
1136  }
1137 
1138  if (m_verboseFlag) cout << "####geoFinder end####" << endl;
1139 
1140 }
1141 
1142 void Hough3DFinder::getValues(const string& input, vector<double>& result)
1143 {
1144  //Clear result vector
1145  result.clear();
1146 
1147  if (input == "bestCot") {
1148  result.push_back(m_bestCot);
1149  }
1150  if (input == "bestZ0") {
1151  result.push_back(m_bestZ0);
1152  }
1153  if (input == "houghMax") {
1154  result.push_back(m_houghMax);
1155  }
1156  if (input == "minDiffHough") {
1157  result.push_back(m_minDiffHough);
1158  }
1159  if (input == "foundZ") {
1160  result.push_back(m_foundZ[0]);
1161  result.push_back(m_foundZ[1]);
1162  result.push_back(m_foundZ[2]);
1163  result.push_back(m_foundZ[3]);
1164  }
1165  if (input == "foundPhiSt") {
1166  result.push_back(m_foundPhiSt[0]);
1167  result.push_back(m_foundPhiSt[1]);
1168  result.push_back(m_foundPhiSt[2]);
1169  result.push_back(m_foundPhiSt[3]);
1170  }
1171  if (input == "bestTS") {
1172  result.push_back(m_bestTS[0]);
1173  result.push_back(m_bestTS[1]);
1174  result.push_back(m_bestTS[2]);
1175  result.push_back(m_bestTS[3]);
1176  }
1177  if (input == "bestTSIndex") {
1178  result.push_back(m_bestTSIndex[0]);
1179  result.push_back(m_bestTSIndex[1]);
1180  result.push_back(m_bestTSIndex[2]);
1181  result.push_back(m_bestTSIndex[3]);
1182  }
1183  if (input == "st0GeoCandidatesPhi") {
1184  for (int iTS = 0; iTS < int((*m_geoCandidatesPhi)[0].size()); iTS++)
1185  result.push_back((*m_geoCandidatesPhi)[0][iTS]);
1186  }
1187  if (input == "st1GeoCandidatesPhi") {
1188  for (int iTS = 0; iTS < int((*m_geoCandidatesPhi)[1].size()); iTS++)
1189  result.push_back((*m_geoCandidatesPhi)[1][iTS]);
1190  }
1191  if (input == "st2GeoCandidatesPhi") {
1192  for (int iTS = 0; iTS < int((*m_geoCandidatesPhi)[2].size()); iTS++)
1193  result.push_back((*m_geoCandidatesPhi)[2][iTS]);
1194  }
1195  if (input == "st3GeoCandidatesPhi") {
1196  for (int iTS = 0; iTS < int((*m_geoCandidatesPhi)[3].size()); iTS++)
1197  result.push_back((*m_geoCandidatesPhi)[3][iTS]);
1198  }
1199 
1200  if (input == "st0GeoCandidatesDiffStWires") {
1201  for (int iTS = 0; iTS < int((*m_geoCandidatesDiffStWires)[0].size()); iTS++)
1202  result.push_back((*m_geoCandidatesDiffStWires)[0][iTS]);
1203  }
1204  if (input == "st1GeoCandidatesDiffStWires") {
1205  for (int iTS = 0; iTS < int((*m_geoCandidatesDiffStWires)[1].size()); iTS++)
1206  result.push_back((*m_geoCandidatesDiffStWires)[1][iTS]);
1207  }
1208  if (input == "st2GeoCandidatesDiffStWires") {
1209  for (int iTS = 0; iTS < int((*m_geoCandidatesDiffStWires)[2].size()); iTS++)
1210  result.push_back((*m_geoCandidatesDiffStWires)[2][iTS]);
1211  }
1212  if (input == "st3GeoCandidatesDiffStWires") {
1213  for (int iTS = 0; iTS < int((*m_geoCandidatesDiffStWires)[3].size()); iTS++)
1214  result.push_back((*m_geoCandidatesDiffStWires)[3][iTS]);
1215  }
1216 
1217  if (input == "st0GeoCandidatesIndex") {
1218  for (int iTS = 0; iTS < int((*m_geoCandidatesIndex)[0].size()); iTS++)
1219  result.push_back((*m_geoCandidatesIndex)[0][iTS]);
1220  }
1221  if (input == "st1GeoCandidatesIndex") {
1222  for (int iTS = 0; iTS < int((*m_geoCandidatesIndex)[1].size()); iTS++)
1223  result.push_back((*m_geoCandidatesIndex)[1][iTS]);
1224  }
1225  if (input == "st2GeoCandidatesIndex") {
1226  for (int iTS = 0; iTS < int((*m_geoCandidatesIndex)[2].size()); iTS++)
1227  result.push_back((*m_geoCandidatesIndex)[2][iTS]);
1228  }
1229  if (input == "st3GeoCandidatesIndex") {
1230  for (int iTS = 0; iTS < int((*m_geoCandidatesIndex)[3].size()); iTS++)
1231  result.push_back((*m_geoCandidatesIndex)[3][iTS]);
1232  }
1233 
1234  if (input == "stAxPhi") {
1235  result.push_back(m_stAxPhi[0]);
1236  result.push_back(m_stAxPhi[1]);
1237  result.push_back(m_stAxPhi[2]);
1238  result.push_back(m_stAxPhi[3]);
1239  }
1240 
1241  if (input == "extreme") {
1242  result.push_back(m_findRhoMax);
1243  result.push_back(m_findRhoMin);
1244  result.push_back(m_findPhi0Max);
1245  result.push_back(m_findPhi0Min);
1246  result.push_back(m_findArcCosMax);
1247  result.push_back(m_findArcCosMin);
1248  result.push_back(m_findPhiZMax);
1249  result.push_back(m_findPhiZMin);
1250  result.push_back(m_findRhoIntMax);
1251  result.push_back(m_findRhoIntMin);
1252  result.push_back(m_findPhi0IntMax);
1253  result.push_back(m_findPhi0IntMin);
1254  result.push_back(m_findArcCosIntMax);
1255  result.push_back(m_findArcCosIntMin);
1256  result.push_back(m_findPhiZIntMax);
1257  result.push_back(m_findPhiZIntMin);
1259  //for(unsigned i=0; i<result.size(); i++) {
1260  // cout<<result[i]<<endl;
1261  //}
1262  }
1263 
1264  if (input == "hitmapLayer1") {
1265  for (unsigned iOutput = 0; iOutput < unsigned(m_nWires[0] / 2); iOutput++) {
1266  result.push_back(m_hitMap[0][iOutput]);
1267  }
1268  }
1269 
1270  if (input == "hitmapLayer2") {
1271  for (unsigned iOutput = 0; iOutput < unsigned(m_nWires[1] / 2); iOutput++) {
1272  result.push_back(m_hitMap[1][iOutput]);
1273  }
1274  }
1275 
1276  if (input == "hitmapLayer3") {
1277  for (unsigned iOutput = 0; iOutput < unsigned(m_nWires[2] / 2); iOutput++) {
1278  result.push_back(m_hitMap[2][iOutput]);
1279  }
1280  }
1281 
1282  if (input == "hitmapLayer4") {
1283  for (unsigned iOutput = 0; iOutput < unsigned(m_nWires[3] / 2); iOutput++) {
1284  result.push_back(m_hitMap[3][iOutput]);
1285  }
1286  }
1287 
1288 }
1289 
1290 void Hough3DFinder::getHoughMeshLayer(bool***& houghMeshLayer)
1291 {
1292  houghMeshLayer = m_houghMeshLayer;
1293 }
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 tan(double a)
tan for double
Definition: beamHelpers.h:31
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