ATLAS Offline Software
Loading...
Searching...
No Matches
Trigo.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4/*********************************
5 * Trigo.cxx
6 * author : Ignacio Aracena <ignacio.aracena@cern.ch>
7 * Created June 2015
8 *
9 * @brief Lookup table for trigonometric functions.
10 * Resolution is in PI/32. Values is in Qm.n format
11 * with the MSB reserved for sign, and m=1, n = 7
12 *
13 **********************************/
14
17#include <cmath>
18
19//helper to convert entire vectors
20std::vector<int> convertVector(const std::vector<std::string>& stringVector) {
21 std::vector<int> values;
22 for (const std::string& binStr: stringVector) {
23 values.push_back( TSU::toSigned(binStr) );
24 }
25 return values;
26}
27
28const std::vector<std::string> TSU::Trigo::Cosleg=
29 {
30 //legacy
31 "010000000", // 1.0
32 "001111111", // 0.9951847266721969
33 "001111110", // 0.9807852804032304
34 "001111010", // 0.9569403357322088
35 "001110110", // 0.9238795325112867
36 "001110001", // 0.881921264348355 // 5
37 "001101010", // 0.8314696123025452
38 "001100011", // 0.773010453362737
39 "001011011", // 0.7071067811865476
40 "001010001", // 0.6343932841636455
41 "001000111", // 0.5555702330196023 // 10
42 "000111100", // 0.4713967368259978
43 "000110001", // 0.38268343236508984
44 "000100101", // 0.29028467725446233
45 "000011001", // 0.19509032201612833
46 "000001101", // 0.09801714032956077 // 15
47 "000000000", // 6.123233995736766e-17
48 "111110011", // -0.09801714032956065
49 "111100111", // -0.1950903220161282
50 "111011011", // -0.29028467725446216
51 "111001111", // -0.3826834323650897 // 20
52 "111000100", // -0.4713967368259977
53 "110111001", // -0.555570233019602
54 "110101111", // -0.6343932841636454
55 "110100101", // -0.7071067811865475
56 "110011101", // -0.773010453362737 // 25
57 "110010110", // -0.8314696123025453
58 "110001111", // -0.8819212643483549
59 "110001010", // -0.9238795325112867
60 "110000110", // -0.9569403357322088
61 "110000010", // -0.9807852804032304 // 30
62 "110000001", // -0.9951847266721968
63 "110000000", // -1.0
64 "110000001", // -0.9951847266721969
65 "110000010", // -0.9807852804032304
66 "110000110", // -0.9569403357322089 // 35
67 "110001010", // -0.9238795325112868
68 "110001111", // -0.881921264348355
69 "110010110", // -0.8314696123025455
70 "110011101", // -0.7730104533627371
71 "110100101", // -0.7071067811865477 // 40
72 "110101111", // -0.6343932841636459
73 "110111001", // -0.5555702330196022
74 "111000100", // -0.47139673682599786
75 "111001111", // -0.38268343236509034
76 "111011011", // -0.29028467725446244 // 45
77 "111100111", // -0.19509032201612866
78 "111110011", // -0.09801714032956045
79 "000000000", // -1.8369701987210297e-16
80 "000001101", // 0.09801714032956009
81 "000011001", // 0.1950903220161283
82 "000100101", // 0.29028467725446205
83 "000110001", // 0.38268343236509
84 "000111100", // 0.4713967368259976
85 "001000111", // 0.5555702330196018
86 "001010001", // 0.6343932841636456
87 "001011011", // 0.7071067811865474
88 "001100011", // 0.7730104533627367
89 "001101010", // 0.8314696123025452
90 "001110001", // 0.8819212643483548
91 "001110110", // 0.9238795325112865
92 "001111010", // 0.9569403357322088
93 "001111110", // 0.9807852804032303
94 "001111111" // 0.9951847266721969
95 };
96
98
99//phase1
100const std::vector<std::string> TSU::Trigo::Cos=
101 {
102 "010000000000", // value = 1.0(1.0) argument value = 0.0
103 "001111111111", // value = 0.9987954562051724(0.9990234375) argument value = 0.04908738521234052
104 "001111111011", // value = 0.9951847266721969(0.9951171875) argument value = 0.09817477042468103
105 "001111110101", // value = 0.989176509964781(0.9892578125) argument value = 0.14726215563702155
106 "001111101100", // value = 0.9807852804032304(0.98046875) argument value = 0.19634954084936207
107 "001111100001", // value = 0.970031253194544(0.9697265625) argument value = 0.2454369260617026
108 "001111010100", // value = 0.9569403357322088(0.95703125) argument value = 0.2945243112740431
109 "001111000100", // value = 0.9415440651830208(0.94140625) argument value = 0.3436116964863836
110 "001110110010", // value = 0.9238795325112867(0.923828125) argument value = 0.39269908169872414
111 "001110011110", // value = 0.9039892931234433(0.904296875) argument value = 0.44178646691106466
112 "001110000111", // value = 0.881921264348355(0.8818359375) argument value = 0.4908738521234052
113 "001101101110", // value = 0.8577286100002721(0.857421875) argument value = 0.5399612373357456
114 "001101010011", // value = 0.8314696123025452(0.8310546875) argument value = 0.5890486225480862
115 "001100110110", // value = 0.8032075314806449(0.802734375) argument value = 0.6381360077604268
116 "001100011000", // value = 0.773010453362737(0.7734375) argument value = 0.6872233929727672
117 "001011110111", // value = 0.7409511253549591(0.7412109375) argument value = 0.7363107781851077
118 "001011010100", // value = 0.7071067811865476(0.70703125) argument value = 0.7853981633974483
119 "001010110000", // value = 0.6715589548470183(0.671875) argument value = 0.8344855486097889
120 "001010001010", // value = 0.6343932841636455(0.634765625) argument value = 0.8835729338221293
121 "001001100010", // value = 0.5956993044924335(0.595703125) argument value = 0.9326603190344698
122 "001000111001", // value = 0.5555702330196023(0.5556640625) argument value = 0.9817477042468103
123 "001000001110", // value = 0.5141027441932217(0.513671875) argument value = 1.030835089459151
124 "000111100011", // value = 0.4713967368259978(0.4716796875) argument value = 1.0799224746714913
125 "000110110110", // value = 0.4275550934302822(0.427734375) argument value = 1.1290098598838318
126 "000110001000", // value = 0.38268343236508984(0.3828125) argument value = 1.1780972450961724
127 "000101011001", // value = 0.33688985339222005(0.3369140625) argument value = 1.227184630308513
128 "000100101001", // value = 0.29028467725446233(0.2900390625) argument value = 1.2762720155208536
129 "000011111001", // value = 0.24298017990326398(0.2431640625) argument value = 1.325359400733194
130 "000011001000", // value = 0.19509032201612833(0.1953125) argument value = 1.3744467859455345
131 "000010010110", // value = 0.14673047445536175(0.146484375) argument value = 1.423534171157875
132 "000001100100", // value = 0.09801714032956077(0.09765625) argument value = 1.4726215563702154
133 "000000110010", // value = 0.049067674327418126(0.048828125) argument value = 1.521708941582556
134 "000000000000", // value = 6.123233995736766e-17(0.0) argument value = 1.5707963267948966
135 "111111001110", // value = -0.04906767432741801(-0.048828125) argument value = 1.6198837120072371
136 "111110011100", // value = -0.09801714032956065(-0.09765625) argument value = 1.6689710972195777
137 "111101101010", // value = -0.14673047445536164(-0.146484375) argument value = 1.718058482431918
138 "111100111000", // value = -0.1950903220161282(-0.1953125) argument value = 1.7671458676442586
139 "111100000111", // value = -0.24298017990326387(-0.2431640625) argument value = 1.8162332528565992
140 "111011010111", // value = -0.29028467725446216(-0.2900390625) argument value = 1.8653206380689396
141 "111010100111", // value = -0.33688985339221994(-0.3369140625) argument value = 1.9144080232812801
142 "111001111000", // value = -0.3826834323650897(-0.3828125) argument value = 1.9634954084936207
143 "111001001010", // value = -0.42755509343028186(-0.427734375) argument value = 2.012582793705961
144 "111000011101", // value = -0.4713967368259977(-0.4716796875) argument value = 2.061670178918302
145 "110111110010", // value = -0.5141027441932217(-0.513671875) argument value = 2.110757564130642
146 "110111000111", // value = -0.555570233019602(-0.5556640625) argument value = 2.1598449493429825
147 "110110011110", // value = -0.5956993044924334(-0.595703125) argument value = 2.2089323345553233
148 "110101110110", // value = -0.6343932841636454(-0.634765625) argument value = 2.2580197197676637
149 "110101010000", // value = -0.6715589548470184(-0.671875) argument value = 2.3071071049800045
150 "110100101100", // value = -0.7071067811865475(-0.70703125) argument value = 2.356194490192345
151 "110100001001", // value = -0.7409511253549589(-0.7412109375) argument value = 2.405281875404685
152 "110011101000", // value = -0.773010453362737(-0.7734375) argument value = 2.454369260617026
153 "110011001010", // value = -0.8032075314806448(-0.802734375) argument value = 2.5034566458293663
154 "110010101101", // value = -0.8314696123025453(-0.8310546875) argument value = 2.552544031041707
155 "110010010010", // value = -0.857728610000272(-0.857421875) argument value = 2.6016314162540475
156 "110001111001", // value = -0.8819212643483549(-0.8818359375) argument value = 2.650718801466388
157 "110001100010", // value = -0.9039892931234433(-0.904296875) argument value = 2.6998061866787286
158 "110001001110", // value = -0.9238795325112867(-0.923828125) argument value = 2.748893571891069
159 "110000111100", // value = -0.9415440651830207(-0.94140625) argument value = 2.7979809571034093
160 "110000101100", // value = -0.9569403357322088(-0.95703125) argument value = 2.84706834231575
161 "110000011111", // value = -0.970031253194544(-0.9697265625) argument value = 2.8961557275280905
162 "110000010100", // value = -0.9807852804032304(-0.98046875) argument value = 2.945243112740431
163 "110000001011", // value = -0.989176509964781(-0.9892578125) argument value = 2.9943304979527716
164 "110000000101", // value = -0.9951847266721968(-0.9951171875) argument value = 3.043417883165112
165 "110000000001", // value = -0.9987954562051724(-0.9990234375) argument value = 3.0925052683774528
166 "110000000000", // value = -1.0(-1.0) argument value = 3.141592653589793
167 "110000000001", // value = -0.9987954562051724(-0.9990234375) argument value = 3.1906800388021335
168 "110000000101", // value = -0.9951847266721969(-0.9951171875) argument value = 3.2397674240144743
169 "110000001011", // value = -0.989176509964781(-0.9892578125) argument value = 3.2888548092268146
170 "110000010100", // value = -0.9807852804032304(-0.98046875) argument value = 3.3379421944391554
171 "110000011111", // value = -0.970031253194544(-0.9697265625) argument value = 3.3870295796514958
172 "110000101100", // value = -0.9569403357322089(-0.95703125) argument value = 3.436116964863836
173 "110000111100", // value = -0.9415440651830208(-0.94140625) argument value = 3.485204350076177
174 "110001001110", // value = -0.9238795325112868(-0.923828125) argument value = 3.5342917352885173
175 "110001100010", // value = -0.9039892931234434(-0.904296875) argument value = 3.5833791205008576
176 "110001111001", // value = -0.881921264348355(-0.8818359375) argument value = 3.6324665057131984
177 "110010010010", // value = -0.8577286100002721(-0.857421875) argument value = 3.6815538909255388
178 "110010101101", // value = -0.8314696123025455(-0.8310546875) argument value = 3.730641276137879
179 "110011001010", // value = -0.8032075314806449(-0.802734375) argument value = 3.77972866135022
180 "110011101000", // value = -0.7730104533627371(-0.7734375) argument value = 3.8288160465625602
181 "110100001001", // value = -0.7409511253549591(-0.7412109375) argument value = 3.877903431774901
182 "110100101100", // value = -0.7071067811865477(-0.70703125) argument value = 3.9269908169872414
183 "110101010000", // value = -0.6715589548470187(-0.671875) argument value = 3.9760782021995817
184 "110101110110", // value = -0.6343932841636459(-0.634765625) argument value = 4.025165587411922
185 "110110011110", // value = -0.5956993044924331(-0.595703125) argument value = 4.074252972624263
186 "110111000111", // value = -0.5555702330196022(-0.5556640625) argument value = 4.123340357836604
187 "110111110010", // value = -0.5141027441932218(-0.513671875) argument value = 4.172427743048944
188 "111000011101", // value = -0.47139673682599786(-0.4716796875) argument value = 4.221515128261284
189 "111001001010", // value = -0.4275550934302825(-0.427734375) argument value = 4.270602513473625
190 "111001111000", // value = -0.38268343236509034(-0.3828125) argument value = 4.319689898685965
191 "111010100111", // value = -0.33688985339221994(-0.3369140625) argument value = 4.368777283898306
192 "111011010111", // value = -0.29028467725446244(-0.2900390625) argument value = 4.417864669110647
193 "111100000111", // value = -0.24298017990326412(-0.2431640625) argument value = 4.466952054322987
194 "111100111000", // value = -0.19509032201612866(-0.1953125) argument value = 4.516039439535327
195 "111101101010", // value = -0.1467304744553623(-0.146484375) argument value = 4.565126824747668
196 "111110011100", // value = -0.09801714032956045(-0.09765625) argument value = 4.614214209960009
197 "111111001110", // value = -0.04906767432741803(-0.048828125) argument value = 4.663301595172349
198 "000000000000", // value = -1.8369701987210297e-16(0.0) argument value = 4.71238898038469
199 "000000110010", // value = 0.04906767432741766(0.048828125) argument value = 4.76147636559703
200 "000001100100", // value = 0.09801714032956009(0.09765625) argument value = 4.81056375080937
201 "000010010110", // value = 0.14673047445536194(0.146484375) argument value = 4.859651136021712
202 "000011001000", // value = 0.1950903220161283(0.1953125) argument value = 4.908738521234052
203 "000011111001", // value = 0.24298017990326376(0.2431640625) argument value = 4.957825906446392
204 "000100101001", // value = 0.29028467725446205(0.2900390625) argument value = 5.006913291658733
205 "000101011001", // value = 0.3368898533922196(0.3369140625) argument value = 5.056000676871073
206 "000110001000", // value = 0.38268343236509(0.3828125) argument value = 5.105088062083414
207 "000110110110", // value = 0.42755509343028214(0.427734375) argument value = 5.154175447295755
208 "000111100011", // value = 0.4713967368259976(0.4716796875) argument value = 5.203262832508095
209 "001000001110", // value = 0.5141027441932216(0.513671875) argument value = 5.252350217720435
210 "001000111001", // value = 0.5555702330196018(0.5556640625) argument value = 5.301437602932776
211 "001001100010", // value = 0.5956993044924329(0.595703125) argument value = 5.350524988145116
212 "001010001010", // value = 0.6343932841636456(0.634765625) argument value = 5.399612373357457
213 "001010110000", // value = 0.6715589548470183(0.671875) argument value = 5.448699758569798
214 "001011010100", // value = 0.7071067811865474(0.70703125) argument value = 5.497787143782138
215 "001011110111", // value = 0.7409511253549589(0.7412109375) argument value = 5.546874528994478
216 "001100011000", // value = 0.7730104533627367(0.7734375) argument value = 5.595961914206819
217 "001100110110", // value = 0.803207531480645(0.802734375) argument value = 5.64504929941916
218 "001101010011", // value = 0.8314696123025452(0.8310546875) argument value = 5.6941366846315
219 "001101101110", // value = 0.857728610000272(0.857421875) argument value = 5.743224069843841
220 "001110000111", // value = 0.8819212643483548(0.8818359375) argument value = 5.792311455056181
221 "001110011110", // value = 0.9039892931234431(0.904296875) argument value = 5.841398840268521
222 "001110110010", // value = 0.9238795325112865(0.923828125) argument value = 5.890486225480862
223 "001111000100", // value = 0.9415440651830208(0.94140625) argument value = 5.939573610693203
224 "001111010100", // value = 0.9569403357322088(0.95703125) argument value = 5.988660995905543
225 "001111100001", // value = 0.970031253194544(0.9697265625) argument value = 6.037748381117884
226 "001111101100", // value = 0.9807852804032303(0.98046875) argument value = 6.086835766330224
227 "001111110101", // value = 0.9891765099647809(0.9892578125) argument value = 6.135923151542564
228 "001111111011", // value = 0.9951847266721969(0.9951171875) argument value = 6.1850105367549055
229 "001111111111" // value = 0.9987954562051724(0.9990234375) argument value = 6.234097921967246
230 };
231
232const std::vector<int> TSU::Trigo::CosInt = convertVector(TSU::Trigo::Cos);
233
234const std::vector<std::string> TSU::Trigo::Sinleg =
235 {
236 "000000000", // 0.0 // 0
237 "000001101", // 0.0980171403295606
238 "000011001", // 0.19509032201612825
239 "000100101", // 0.29028467725446233
240 "000110001", // 0.3826834323650898
241 "000111100", // 0.47139673682599764 // 5
242 "001000111", // 0.5555702330196022
243 "001010001", // 0.6343932841636455
244 "001011011", // 0.7071067811865475
245 "001100011", // 0.773010453362737
246 "001101010", // 0.8314696123025452 // 10
247 "001110001", // 0.8819212643483549
248 "001110110", // 0.9238795325112867
249 "001111010", // 0.9569403357322089
250 "001111110", // 0.9807852804032304
251 "001111111", // 0.9951847266721968 // 15
252 "010000000", // 1.0
253 "001111111", // 0.9951847266721969
254 "001111110", // 0.9807852804032304
255 "001111010", // 0.9569403357322089
256 "001110110", // 0.9238795325112867 // 20
257 "001110001", // 0.881921264348355
258 "001101010", // 0.8314696123025455
259 "001100011", // 0.7730104533627371
260 "001011011", // 0.7071067811865476
261 "001010001", // 0.6343932841636455 // 25
262 "001000111", // 0.5555702330196022
263 "000111100", // 0.47139673682599786
264 "000110001", // 0.3826834323650899
265 "000100101", // 0.2902846772544624
266 "000011001", // 0.1950903220161286 // 30
267 "000001101", // 0.09801714032956083
268 "000000000", // 1.2246467991473532e-16
269 "111110011", // -0.09801714032956059
270 "111100111", // -0.19509032201612836
271 "111011011", // -0.2902846772544621 // 35
272 "111001111", // -0.38268343236508967
273 "111000100", // -0.47139673682599764
274 "110111001", // -0.555570233019602
275 "110101111", // -0.6343932841636453
276 "110100101", // -0.7071067811865475 // 40
277 "110011101", // -0.7730104533627367
278 "110010110", // -0.8314696123025452
279 "110001111", // -0.8819212643483549
280 "110001010", // -0.9238795325112865
281 "110000110", // -0.9569403357322088 // 45
282 "110000010", // -0.9807852804032303
283 "110000001", // -0.9951847266721969
284 "110000000", // -1.0
285 "110000001", // -0.9951847266721969
286 "110000010", // -0.9807852804032304 // 50
287 "110000110", // -0.9569403357322089
288 "110001010", // -0.9238795325112866
289 "110001111", // -0.881921264348355
290 "110010110", // -0.8314696123025455
291 "110011101", // -0.7730104533627369 // 55
292 "110100101", // -0.7071067811865477
293 "110101111", // -0.6343932841636459
294 "110111001", // -0.5555702330196022
295 "111000100", // -0.4713967368259979
296 "111001111", // -0.3826834323650904 // 60
297 "111011011", // -0.2902846772544625
298 "111100111", // -0.19509032201612872
299 "111110011" // -0.0980171403295605 // 63
300 };
301
303
304//phase1
305const std::vector<std::string> TSU::Trigo::Sin=
306 {
307 "000000000000", // 0.0
308 "000000110010", // 0.049067674327418015
309 "000001100100", // 0.0980171403295606
310 "000010010110", // 0.14673047445536175
311 "000011001000", // 0.19509032201612825
312 "000011111001", // 0.24298017990326387
313 "000100101001", // 0.29028467725446233
314 "000101011001", // 0.33688985339222005
315 "000110001000", // 0.3826834323650898
316 "000110110110", // 0.4275550934302821
317 "000111100011", // 0.47139673682599764
318 "001000001110", // 0.5141027441932217
319 "001000111001", // 0.5555702330196022
320 "001001100010", // 0.5956993044924334
321 "001010001010", // 0.6343932841636455
322 "001010110000", // 0.6715589548470183
323 "001011010100", // 0.7071067811865475
324 "001011110111", // 0.7409511253549591
325 "001100011000", // 0.773010453362737
326 "001100110110", // 0.8032075314806448
327 "001101010011", // 0.8314696123025452
328 "001101101110", // 0.8577286100002721
329 "001110000111", // 0.8819212643483549
330 "001110011110", // 0.9039892931234433
331 "001110110010", // 0.9238795325112867
332 "001111000100", // 0.9415440651830208
333 "001111010100", // 0.9569403357322089
334 "001111100001", // 0.970031253194544
335 "001111101100", // 0.9807852804032304
336 "001111110101", // 0.989176509964781
337 "001111111011", // 0.9951847266721968
338 "001111111111", // 0.9987954562051724
339 "010000000000", // 1.0
340 "001111111111", // 0.9987954562051724
341 "001111111011", // 0.9951847266721969
342 "001111110101", // 0.989176509964781
343 "001111101100", // 0.9807852804032304
344 "001111100001", // 0.970031253194544
345 "001111010100", // 0.9569403357322089
346 "001111000100", // 0.9415440651830208
347 "001110110010", // 0.9238795325112867
348 "001110011110", // 0.9039892931234434
349 "001110000111", // 0.881921264348355
350 "001101101110", // 0.8577286100002721
351 "001101010011", // 0.8314696123025455
352 "001100110110", // 0.8032075314806449
353 "001100011000", // 0.7730104533627371
354 "001011110111", // 0.740951125354959
355 "001011010100", // 0.7071067811865476
356 "001010110000", // 0.6715589548470186
357 "001010001010", // 0.6343932841636455
358 "001001100010", // 0.5956993044924335
359 "001000111001", // 0.5555702330196022
360 "001000001110", // 0.5141027441932218
361 "000111100011", // 0.47139673682599786
362 "000110110110", // 0.42755509343028203
363 "000110001000", // 0.3826834323650899
364 "000101011001", // 0.33688985339222033
365 "000100101001", // 0.2902846772544624
366 "000011111001", // 0.24298017990326407
367 "000011001000", // 0.1950903220161286
368 "000010010110", // 0.1467304744553618
369 "000001100100", // 0.09801714032956083
370 "000000110010", // 0.049067674327417966
371 "000000000000", // 1.2246467991473532e-16
372 "111111001110", // -0.049067674327417724
373 "111110011100", // -0.09801714032956059
374 "111101101010", // -0.14673047445536158
375 "111100111000", // -0.19509032201612836
376 "111100000111", // -0.24298017990326382
377 "111011010111", // -0.2902846772544621
378 "111010100111", // -0.3368898533922201
379 "111001111000", // -0.38268343236508967
380 "111001001010", // -0.4275550934302818
381 "111000011101", // -0.47139673682599764
382 "110111110010", // -0.5141027441932216
383 "110111000111", // -0.555570233019602
384 "110110011110", // -0.5956993044924332
385 "110101110110", // -0.6343932841636453
386 "110101010000", // -0.6715589548470184
387 "110100101100", // -0.7071067811865475
388 "110100001001", // -0.7409511253549589
389 "110011101000", // -0.7730104533627367
390 "110011001010", // -0.803207531480645
391 "110010101101", // -0.8314696123025452
392 "110010010010", // -0.857728610000272
393 "110001111001", // -0.8819212643483549
394 "110001100010", // -0.9039892931234431
395 "110001001110", // -0.9238795325112865
396 "110000111100", // -0.9415440651830208
397 "110000101100", // -0.9569403357322088
398 "110000011111", // -0.970031253194544
399 "110000010100", // -0.9807852804032303
400 "110000001011", // -0.9891765099647809
401 "110000000101", // -0.9951847266721969
402 "110000000001", // -0.9987954562051724
403 "110000000000", // -1.0
404 "110000000001", // -0.9987954562051724
405 "110000000101", // -0.9951847266721969
406 "110000001011", // -0.9891765099647809
407 "110000010100", // -0.9807852804032304
408 "110000011111", // -0.970031253194544
409 "110000101100", // -0.9569403357322089
410 "110000111100", // -0.9415440651830209
411 "110001001110", // -0.9238795325112866
412 "110001100010", // -0.9039892931234433
413 "110001111001", // -0.881921264348355
414 "110010010010", // -0.8577286100002722
415 "110010101101", // -0.8314696123025455
416 "110011001010", // -0.8032075314806453
417 "110011101000", // -0.7730104533627369
418 "110100001001", // -0.7409511253549591
419 "110100101100", // -0.7071067811865477
420 "110101010000", // -0.6715589548470187
421 "110101110110", // -0.6343932841636459
422 "110110011110", // -0.5956993044924332
423 "110111000111", // -0.5555702330196022
424 "110111110010", // -0.5141027441932219
425 "111000011101", // -0.4713967368259979
426 "111001001010", // -0.42755509343028253
427 "111001111000", // -0.3826834323650904
428 "111010100111", // -0.33688985339222
429 "111011010111", // -0.2902846772544625
430 "111100000111", // -0.24298017990326418
431 "111100111000", // -0.19509032201612872
432 "111101101010", // -0.1467304744553624
433 "111110011100", // -0.0980171403295605
434 "111111001110" // -0.04906767432741809
435 };
436
437const std::vector<int> TSU::Trigo::SinInt = convertVector(TSU::Trigo::Sin);
438
439
441 short int octant=0;
442 if((x.value()&(1<<16))&&(y.value()&(1<<16))){ // Ex and Ey negative
443 if(std::abs(y.to_float()) < std::abs(x.to_float())) octant = 4; //100
444 else octant = 5; // 101
445 } else if(x.value()&(1<<16)){
446 if(std::abs(y.to_float()) < std::abs(x.to_float())) octant = 3; //011
447 else octant = 2; // 010
448 } else if(y.value()&(1<<16)){
449 if(std::abs(y.to_float()) < std::abs(x.to_float())) octant = 7; //111
450 else octant = 6; // 110
451 } else { // Ex and Ey both positive
452 if(std::abs(y.to_float()) < std::abs(x.to_float())) octant = 0; //000
453 else octant = 1; // 001
454 }
455
456 auto signed_x_f = x;
457 auto signed_y_f = y;
458 if(octant==0||octant==3||octant==4||octant==7){
459 //signed_x_f = (abs(int(x)));
460 signed_x_f = x.abs();
461 signed_y_f = y.abs();
462 } else {
463 //signed_x_f = (abs(int(y)));
464 signed_x_f = y.abs();
465 signed_y_f = x.abs();
466 }
467
468 const std::vector<std::string> atan2_thresholds = {
469 "000010011101100", // 1.260 (0.9)
470 "000011000010101", // 1.557 (1.0)
471 "000011110101100", // 1.964 (1.1)
472 "000101000001100", // 2.572 (1.2)
473 "000111000010010", // 3.602 (1.3)
474 "001011010100101", // 5.797 (1.4)
475 "011011100010101"}; // 14.101 (1.5)
476 unsigned int flag = 0;
477 for(size_t j=0;j<atan2_thresholds.size(); ++j){
478 auto thresh = TSU::L1TopoDataTypes<15,10>(atan2_thresholds.at(j));
479 auto yy = signed_y_f*thresh;
480 if(signed_x_f.to_float() > yy.to_float()) flag = (flag | (1<<j));
481 }
482 unsigned int octant_fine = 0;
483 if(flag==0) octant_fine = 7;
484 else if(flag==1) octant_fine = 6;
485 else if(flag==3) octant_fine = 5;
486 else if(flag==7) octant_fine = 4;
487 else if(flag==15) octant_fine = 3;
488 else if(flag==31) octant_fine = 2;
489 else if(flag==63) octant_fine = 1;
490 else if(flag==127) octant_fine = 0;
491
492 unsigned int octant_fine2 = 0;
493 if(flag==0) octant_fine2 = 0;
494 else if(flag==1) octant_fine2 = 1;
495 else if(flag==3) octant_fine2 = 2;
496 else if(flag==7) octant_fine2 = 3;
497 else if(flag==15) octant_fine2 = 4;
498 else if(flag==31) octant_fine2 = 5;
499 else if(flag==63) octant_fine2 = 6;
500 else if(flag==127) octant_fine2 = 7;
501
502 int intphi = octant << 3;
503 if(octant==0||octant==2||octant==4||octant==6){
504 intphi |= octant_fine;
505 } else {
506 intphi |= octant_fine2;
507 }
508
509 return intphi;
510}
511
513 short int octant=0;
514 if((x.value()&(1<<16))&&(y.value()&(1<<16))){ // Ex and Ey negative
515 if(std::abs(y.to_float()) < std::abs(x.to_float())) octant = 4; //100
516 else octant = 5; // 101
517 } else if(x.value()&(1<<16)){
518 if(std::abs(y.to_float()) < std::abs(x.to_float())) octant = 3; //011
519 else octant = 2; // 010
520 } else if(y.value()&(1<<16)){
521 if(std::abs(y.to_float()) < std::abs(x.to_float())) octant = 7; //111
522 else octant = 6; // 110
523 } else { // Ex and Ey both positive
524 if(std::abs(y.to_float()) < std::abs(x.to_float())) octant = 0; //000
525 else octant = 1; // 001
526 }
527
528 auto signed_x_f = x;
529 auto signed_y_f = y;
530 if(octant==0||octant==3||octant==4||octant==7){
531 //signed_x_f = (abs(int(x)));
532 signed_x_f = x.abs();
533 signed_y_f = y.abs();
534 } else {
535 //signed_x_f = (abs(int(y)));
536 signed_x_f = y.abs();
537 signed_y_f = x.abs();
538 }
539
540 // For phi in the first sector (0.8 < phi < 1.6) store the possible values of the tan
541 const std::vector<std::string> atan2_thresholds =
542 {
543 "00000010010001101", // tan(0.85)=1.1383327132284393 rounded to 1.1376953125
544 "00000010100001010", // tan(0.9)=1.2601582175503392 rounded to 1.259765625
545 "00000010110010111", // tan(0.95)=1.398382589287699 rounded to 1.3974609375
546 "00000011000111010", // tan(1.0)=1.5574077246549023 rounded to 1.556640625
547 "00000011011111001", // tan(1.05)=1.7433153099831704 rounded to 1.7431640625
548 "00000011111011011", // tan(1.1)=1.9647596572486523 rounded to 1.9638671875
549 "00000100011110000", // tan(1.15)=2.2344969487553255 rounded to 2.234375
550 "00000101001001001", // tan(1.2)=2.5721516221263188 rounded to 2.5712890625
551 "00000110000001001", // tan(1.25)=3.0095696738628313 rounded to 3.0087890625
552 "00000111001101000", // tan(1.3)=3.6021024479679786 rounded to 3.6015625
553 "00001000111010010", // tan(1.35)=4.455221759562705 rounded to 4.455078125
554 "00001011100110001", // tan(1.4)=5.797883715482887 rounded to 5.7978515625
555 "00010000011110011", // tan(1.4500000000000002)=8.238092752965619 rounded to 8.2373046875
556 "00011100001100111", // tan(1.5)=14.101419947171719 rounded to 14.1005859375
557 "01100000001010000" // tan(1.55)=48.07848247921907 rounded to 48.078125
558 };
559
560 unsigned int thresholdsPassed = atan2_thresholds.size();
561 for(size_t j=0;j<atan2_thresholds.size(); ++j){
562 auto thresh = TSU::L1TopoDataTypes<17,10>(atan2_thresholds.at(j));
563 auto yy = signed_y_f*thresh;
564 if(! (signed_x_f.to_float() > yy.to_float()) ) {
565 //if the current threshold is not passed, then the previous one must have been the last one passed
566 //(no) off-by-one consideration: j starts at 0, so if the first threshold is already failed, that's just the number we're looking for
567 thresholdsPassed = j;
568 break;
569 }
570 }
571
572 //for first half of a quadrant fine steps are counted in downward
573 // (range: 15 downto 0)
574 unsigned int octant_fine = 16 - (thresholdsPassed + 1);
575
576 //for second half of a quadrant count fine steps upwards
577 // (range: 0 to 15)
578 unsigned int octant_fine2 = thresholdsPassed;
579
580 int intphi = octant << 4;
581 if(octant==0||octant==2||octant==4||octant==6){
582 intphi |= octant_fine;
583 } else {
584 intphi |= octant_fine2;
585 }
586
587 return intphi;
588}
std::vector< int > convertVector(const std::vector< std::string > &stringVector)
Definition Trigo.cxx:20
#define y
#define x
int toSigned(unsigned bits, unsigned length)
static int atan2leg(TSU::L1TopoDataTypes< 16, 0 > x, TSU::L1TopoDataTypes< 16, 0 > y)
Definition Trigo.cxx:440
static const std::vector< std::string > Sin
Definition Trigo.h:305
static const std::vector< std::string > Cos
Definition Trigo.h:100
static const std::vector< int > CosInt
Definition Trigo.h:28
static const std::vector< int > SinInt
Definition Trigo.h:29
static const std::vector< std::string > Sinleg
Definition Trigo.h:234
static const std::vector< int > CoslegInt
Definition Trigo.h:26
static const std::vector< int > SinlegInt
Definition Trigo.h:27
static const std::vector< std::string > Cosleg
Definition Trigo.h:28
static int atan2(TSU::L1TopoDataTypes< 16, 0 > x, TSU::L1TopoDataTypes< 16, 0 > y)
Definition Trigo.cxx:512