1 #define TRG_SHORT_NAMES
8 #include "trg/trg/Utilities.h"
13 #define NAME "HoughMapping"
14 #define VERSION "version 0.01"
31 void printHeader(ofstream& out,
const string&
function);
32 void superLayer(
const unsigned id);
33 void printMapping(ofstream& out, vector<vector<vector<int>>>& HPcell);
37 const double PI2 = 2 * M_PI;
39 const double minY = 1.823908740944321;
40 const double maxY = 3.204119982655926;
42 const unsigned nX = 160;
43 const unsigned nY = 16;
45 vector<vector<vector<int>>> HPcellM(nY, vector<vector<int>>(nX, vector<int>()));
46 ofstream outputM(
"minus_total.dat");
48 vector<vector<vector<int>>> HPcellP(nY, vector<vector<int>>(nX, vector<int>()));
49 ofstream outputP(
"plus_total.dat");
53 const string fncM =
"HoughMappingMinus.cc";
54 const string fncP =
"HoughMappingPlus.cc";
61 cout << NAME <<
" ... " << VERSION << endl;
63 printHeader(outcM,
"HoughMappingMinus");
64 printHeader(outcP,
"HoughMappingPlus");
66 for (
unsigned isl = 0; isl < 5 ; isl++)
69 printMapping(outputM, HPcellM);
70 printMapping(outputP, HPcellP);
72 outcM << endl <<
"}" << endl;
73 outcP << endl <<
"}" << endl;
79 cout <<
"Files generated" << endl;
80 cout <<
" c++ for tsim firmware : " << fncM << endl;
81 cout <<
" c++ for tsim firmware : " << fncP << endl;
85 printHeader(ofstream& out,
const string&
function)
88 string ts = TRGUtil::dateString();
90 out <<
"// This file is generated by " << NAME <<
"(" << VERSION <<
")" << endl;
91 out <<
"// " << ts << endl << endl;
92 out <<
"#define TRGCDC_SHORT_NAMES" << endl;
93 out <<
"#include \"trg/trg/State.h\"" << endl;
94 out <<
"#include \"trg/cdc/Tracker2D.h\"" << endl;
95 out <<
"using namespace std;" << endl;
96 out <<
"using namespace Belle2;" << endl;
97 out <<
"void" << endl;
98 out <<
"TCTracker2D::" <<
function <<
"(void) {" << endl;
100 out <<
" //...TS hit map..." << endl;
101 out <<
" TRGState SL0_TS = _ts.subset(0, 160);" << endl;
102 out <<
" TRGState SL2_TS = _ts.subset(160, 192);" << endl;
103 out <<
" TRGState SL4_TS = _ts.subset(160 + 192, 256);" << endl;
104 out <<
" TRGState SL6_TS = _ts.subset(160 + 192 + 256, 320);" << endl;
105 out <<
" TRGState SL8_TS = _ts.subset(160 + 192 + 256 + 320, 384);" << endl;
107 out <<
" //...Hough cells..." << endl;
109 for (
unsigned isl = 0; isl < 5; isl++) {
110 for (
unsigned iy = 1; iy < nY + 1; iy++) {
111 out <<
" TRGState SL" << to_string(isl * 2) <<
"_row"
112 << to_string(iy) <<
"(" << to_string(nX) <<
");" << endl;
118 superLayer(
const unsigned id)
129 }
else if (
id == 1) {
132 }
else if (
id == 2) {
135 }
else if (
id == 3) {
138 }
else if (
id == 4) {
142 cout << NAME <<
" !!! bad super layer ID" << endl;
152 for (
int i = 0; i < N_TS_SL; ++i) {
153 xy.
x = r_SL * cos((PI2 / N_TS_SL) * i);
154 xy.
y = r_SL * sin((PI2 / N_TS_SL) * i);
155 xymatrix.push_back(xy);
159 const double r0 = minY;
160 const double phi0 = 0;
161 const double dr = (maxY - minY) / nY;
162 const double dphi = PI2 / nX;
172 const string vhM =
"UT3_0_SL" + to_string(
id * 2) +
".vhd";
173 const string vhP =
"UT3_0_SL" + to_string(
id * 2) +
"_p.vhd";
174 ofstream outputfM(vhM);
175 ofstream outputfP(vhP);
178 outputfM <<
"library IEEE;" << endl;
179 outputfM <<
"use IEEE.STD_LOGIC_1164.ALL;" << endl;
180 outputfM <<
" " << endl;
181 outputfM <<
" " << endl;
182 outputfM <<
"entity UT3_0_SL" << SL <<
" is" << endl;
183 outputfM <<
" " << endl;
184 outputfM <<
"Port (" << endl;
185 for (
unsigned irow = 1; irow < nY + 1; ++irow) {
186 outputfM <<
" SL" << SL <<
"_row" << left << setw(2) << to_string(irow)
187 <<
" : out STD_LOGIC_VECTOR (79 downto 40);" << endl;
189 outputfM <<
" SL" << SL <<
"_TS : in STD_LOGIC_VECTOR ("
190 << N_TS_SL / 2 <<
" downto 0));" << endl;
191 outputfM <<
"end UT3_0_SL" << SL <<
";" << endl;
192 outputfM <<
" " << endl;
193 outputfM <<
" " << endl;
194 outputfM <<
"architecture Behavioral of UT3_0_SL" << SL <<
" is" << endl;
195 outputfM <<
" " << endl;
196 outputfM <<
"begin" << endl;
197 outputfM <<
" " << endl;
200 outputfP <<
"library IEEE;" << endl;
201 outputfP <<
"use IEEE.STD_LOGIC_1164.ALL;" << endl;
202 outputfP <<
" " << endl;
203 outputfP <<
" " << endl;
204 outputfP <<
"entity UT3_0_SL" << SL <<
"_P is" << endl;
205 outputfP <<
" " << endl;
206 outputfP <<
"Port (" << endl;
207 for (
unsigned irow = 1; irow < nY + 1; ++irow) {
208 outputfP <<
" SL" << SL <<
"_row" << left << setw(2) << to_string(irow)
209 <<
" : out STD_LOGIC_VECTOR (39 downto 0);" << endl;
211 outputfP <<
" SL" << SL <<
"_TS : in STD_LOGIC_VECTOR ("
212 << N_TS_SL / 2 <<
" downto 0));" << endl;
213 outputfP <<
"end UT3_0_SL" << SL <<
"_P;" << endl;
214 outputfP <<
" " << endl;
215 outputfP <<
" " << endl;
216 outputfP <<
"architecture Behavioral of UT3_0_SL" << SL <<
"_P is" << endl;
217 outputfP <<
" " << endl;
218 outputfP <<
"begin" << endl;
219 outputfP <<
" " << endl;
222 for (
unsigned k = 0 ; k < nY ; ++k) {
224 for (
unsigned j = 0 ; j < nX ; ++j) {
228 if (j > 39 && j < 80)
229 outputfM <<
"SL" << SL <<
"_row" << k + 1 <<
"(" << j <<
")<=";
231 outputfP <<
"SL" << SL <<
"_row" << k + 1 <<
"(" << j <<
")<=";
232 outcM <<
" SL" << SL <<
"_row" << k + 1 <<
".set(" << j <<
", ";
233 outcP <<
" SL" << SL <<
"_row" << k + 1 <<
".set(" << j <<
", ";
237 phi1 = phi0 + j * dphi;
238 phi2 = phi0 + (j + 1) * dphi;
241 for (
int i = 0 ; i < N_TS_SL ; i++) {
243 r1 = ((xymatrix[i].x * xymatrix[i].x) + (xymatrix[i].y * xymatrix[i].y)) /
244 ((2 * xymatrix[i].x * cos(phi1)) + (2 * xymatrix[i].y * sin(phi1)));
245 r2 = ((xymatrix[i].x * xymatrix[i].x) + (xymatrix[i].y * xymatrix[i].y)) /
246 ((2 * xymatrix[i].x * cos(phi2)) + (2 * xymatrix[i].y * sin(phi2)));
263 if (r1 >= 0 && r2 >= 0 && r1 < r2) {
267 minus1 = r0 + (k + 1) * dr - log10(r1);
268 minus2 = r0 + k * dr - log10(r2);
269 if (minus1 * minus2 <= 0.0) {
270 HPcellM[k][j].push_back(SL);
271 HPcellM[k][j].push_back(i);
277 if (j > 39 && j < 80)
282 if (j > 39 && j < 80)
283 outputfM <<
"SL" << SL <<
"_TS(" << i <<
") ";
285 outcM <<
"SL" << SL <<
"_TS[" << i <<
"]";
288 }
else if (r2 < 0 && r1 >= 0) {
292 minus1 = r0 + (k + 1) * dr - log10(r1);
294 HPcellM[k][j].push_back(SL);
295 HPcellM[k][j].push_back(i);
301 if (j > 39 && j < 80)
305 if (j > 39 && j < 80)
306 outputfM <<
"SL" << SL <<
"_TS(" << i <<
") ";
308 outcM <<
"SL" << SL <<
"_TS[" << i <<
"]";
314 if (r1 >= 0 && r2 >= 0 && r2 < r1) {
318 plus1 = r0 + (k + 1) * dr - log10(r2);
319 plus2 = r0 + k * dr - log10(r1);
320 if (plus1 * plus2 <= 0.0) {
321 HPcellP[k][j].push_back(SL);
322 HPcellP[k][j].push_back(i);
332 outputfP <<
"SL" << SL <<
"_TS(" << i <<
") ";
334 outcP <<
"SL" << SL <<
"_TS[" << i <<
"]";
337 }
else if (r1 < 0 && r2 >= 0) {
341 plus1 = r0 + (k + 1) * dr - log10(r2);
343 HPcellP[k][j].push_back(SL);
344 HPcellP[k][j].push_back(i);
354 outputfP <<
"SL" << SL <<
"_TS(" << i <<
") ";
356 outcP <<
"SL" << SL <<
"_TS[" << i <<
"]";
362 if (j > 39 && j < 80)
363 outputfM <<
";" << endl;
365 outputfP <<
";" << endl;
366 outcM <<
");" << endl;
367 outcP <<
");" << endl;
370 outputfM <<
" " << endl;
371 outputfM <<
"end Behavioral;" << endl;
372 outputfP <<
" " << endl;
373 outputfP <<
"end Behavioral;" << endl;
378 printMapping(ofstream& out, vector<vector<vector<int>>>& HPcell)
381 string ts = TRGUtil::dateString();
382 out <<
"// This file is generated by " << NAME <<
"(" << VERSION <<
")" << endl;
383 out <<
"// " << ts << endl << endl;
385 out << nX <<
" " << nY <<
" " << minY <<
" " << maxY << endl;
387 for (
unsigned iy = 0; iy < nY; iy++) {
388 for (
unsigned ix = 0; ix < nX; ix++) {
389 out << ix <<
" " << iy + 1 <<
" ";
390 for (
unsigned its = 0; its < HPcell[iy][ix].size(); its++) {
391 out << HPcell[iy][ix][its] <<
" ";