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