CbmRoot
CbmLitMatrixMath.cxx
Go to the documentation of this file.
2 
3 #include <iostream>
4 
5 /*
6  * Matrix operations
7  */
8 
9 // SMij are indices for a 5x5 matrix.
10 
11 #define SM00 0
12 #define SM01 1
13 #define SM02 2
14 #define SM03 3
15 #define SM04 4
16 
17 #define SM10 1
18 #define SM11 5
19 #define SM12 6
20 #define SM13 7
21 #define SM14 8
22 
23 #define SM20 2
24 #define SM21 6
25 #define SM22 9
26 #define SM23 10
27 #define SM24 11
28 
29 #define SM30 3
30 #define SM31 7
31 #define SM32 10
32 #define SM33 12
33 #define SM34 13
34 
35 #define SM40 4
36 #define SM41 8
37 #define SM42 11
38 #define SM43 13
39 #define SM44 14
40 
41 bool InvSym15(std::vector<litfloat>& a) {
42  if (a.size() != 15) {
43  std::cout << "-E- InvSym15: size is not correct" << std::endl;
44  return false;
45  }
46 
47  litfloat* pM = &a[0];
48 
49  // Find all NECESSARY 2x2 dets: (25 of them)
50 
51  const litfloat mDet2_23_01 = pM[SM20] * pM[SM31] - pM[SM21] * pM[SM30];
52  const litfloat mDet2_23_02 = pM[SM20] * pM[SM32] - pM[SM22] * pM[SM30];
53  const litfloat mDet2_23_03 = pM[SM20] * pM[SM33] - pM[SM23] * pM[SM30];
54  const litfloat mDet2_23_12 = pM[SM21] * pM[SM32] - pM[SM22] * pM[SM31];
55  const litfloat mDet2_23_13 = pM[SM21] * pM[SM33] - pM[SM23] * pM[SM31];
56  const litfloat mDet2_23_23 = pM[SM22] * pM[SM33] - pM[SM23] * pM[SM32];
57  const litfloat mDet2_24_01 = pM[SM20] * pM[SM41] - pM[SM21] * pM[SM40];
58  const litfloat mDet2_24_02 = pM[SM20] * pM[SM42] - pM[SM22] * pM[SM40];
59  const litfloat mDet2_24_03 = pM[SM20] * pM[SM43] - pM[SM23] * pM[SM40];
60  const litfloat mDet2_24_04 = pM[SM20] * pM[SM44] - pM[SM24] * pM[SM40];
61  const litfloat mDet2_24_12 = pM[SM21] * pM[SM42] - pM[SM22] * pM[SM41];
62  const litfloat mDet2_24_13 = pM[SM21] * pM[SM43] - pM[SM23] * pM[SM41];
63  const litfloat mDet2_24_14 = pM[SM21] * pM[SM44] - pM[SM24] * pM[SM41];
64  const litfloat mDet2_24_23 = pM[SM22] * pM[SM43] - pM[SM23] * pM[SM42];
65  const litfloat mDet2_24_24 = pM[SM22] * pM[SM44] - pM[SM24] * pM[SM42];
66  const litfloat mDet2_34_01 = pM[SM30] * pM[SM41] - pM[SM31] * pM[SM40];
67  const litfloat mDet2_34_02 = pM[SM30] * pM[SM42] - pM[SM32] * pM[SM40];
68  const litfloat mDet2_34_03 = pM[SM30] * pM[SM43] - pM[SM33] * pM[SM40];
69  const litfloat mDet2_34_04 = pM[SM30] * pM[SM44] - pM[SM34] * pM[SM40];
70  const litfloat mDet2_34_12 = pM[SM31] * pM[SM42] - pM[SM32] * pM[SM41];
71  const litfloat mDet2_34_13 = pM[SM31] * pM[SM43] - pM[SM33] * pM[SM41];
72  const litfloat mDet2_34_14 = pM[SM31] * pM[SM44] - pM[SM34] * pM[SM41];
73  const litfloat mDet2_34_23 = pM[SM32] * pM[SM43] - pM[SM33] * pM[SM42];
74  const litfloat mDet2_34_24 = pM[SM32] * pM[SM44] - pM[SM34] * pM[SM42];
75  const litfloat mDet2_34_34 = pM[SM33] * pM[SM44] - pM[SM34] * pM[SM43];
76 
77  // Find all NECESSARY 3x3 dets: (30 of them)
78 
79  const litfloat mDet3_123_012 =
80  pM[SM10] * mDet2_23_12 - pM[SM11] * mDet2_23_02 + pM[SM12] * mDet2_23_01;
81  const litfloat mDet3_123_013 =
82  pM[SM10] * mDet2_23_13 - pM[SM11] * mDet2_23_03 + pM[SM13] * mDet2_23_01;
83  const litfloat mDet3_123_023 =
84  pM[SM10] * mDet2_23_23 - pM[SM12] * mDet2_23_03 + pM[SM13] * mDet2_23_02;
85  const litfloat mDet3_123_123 =
86  pM[SM11] * mDet2_23_23 - pM[SM12] * mDet2_23_13 + pM[SM13] * mDet2_23_12;
87  const litfloat mDet3_124_012 =
88  pM[SM10] * mDet2_24_12 - pM[SM11] * mDet2_24_02 + pM[SM12] * mDet2_24_01;
89  const litfloat mDet3_124_013 =
90  pM[SM10] * mDet2_24_13 - pM[SM11] * mDet2_24_03 + pM[SM13] * mDet2_24_01;
91  const litfloat mDet3_124_014 =
92  pM[SM10] * mDet2_24_14 - pM[SM11] * mDet2_24_04 + pM[SM14] * mDet2_24_01;
93  const litfloat mDet3_124_023 =
94  pM[SM10] * mDet2_24_23 - pM[SM12] * mDet2_24_03 + pM[SM13] * mDet2_24_02;
95  const litfloat mDet3_124_024 =
96  pM[SM10] * mDet2_24_24 - pM[SM12] * mDet2_24_04 + pM[SM14] * mDet2_24_02;
97  const litfloat mDet3_124_123 =
98  pM[SM11] * mDet2_24_23 - pM[SM12] * mDet2_24_13 + pM[SM13] * mDet2_24_12;
99  const litfloat mDet3_124_124 =
100  pM[SM11] * mDet2_24_24 - pM[SM12] * mDet2_24_14 + pM[SM14] * mDet2_24_12;
101  const litfloat mDet3_134_012 =
102  pM[SM10] * mDet2_34_12 - pM[SM11] * mDet2_34_02 + pM[SM12] * mDet2_34_01;
103  const litfloat mDet3_134_013 =
104  pM[SM10] * mDet2_34_13 - pM[SM11] * mDet2_34_03 + pM[SM13] * mDet2_34_01;
105  const litfloat mDet3_134_014 =
106  pM[SM10] * mDet2_34_14 - pM[SM11] * mDet2_34_04 + pM[SM14] * mDet2_34_01;
107  const litfloat mDet3_134_023 =
108  pM[SM10] * mDet2_34_23 - pM[SM12] * mDet2_34_03 + pM[SM13] * mDet2_34_02;
109  const litfloat mDet3_134_024 =
110  pM[SM10] * mDet2_34_24 - pM[SM12] * mDet2_34_04 + pM[SM14] * mDet2_34_02;
111  const litfloat mDet3_134_034 =
112  pM[SM10] * mDet2_34_34 - pM[SM13] * mDet2_34_04 + pM[SM14] * mDet2_34_03;
113  const litfloat mDet3_134_123 =
114  pM[SM11] * mDet2_34_23 - pM[SM12] * mDet2_34_13 + pM[SM13] * mDet2_34_12;
115  const litfloat mDet3_134_124 =
116  pM[SM11] * mDet2_34_24 - pM[SM12] * mDet2_34_14 + pM[SM14] * mDet2_34_12;
117  const litfloat mDet3_134_134 =
118  pM[SM11] * mDet2_34_34 - pM[SM13] * mDet2_34_14 + pM[SM14] * mDet2_34_13;
119  const litfloat mDet3_234_012 =
120  pM[SM20] * mDet2_34_12 - pM[SM21] * mDet2_34_02 + pM[SM22] * mDet2_34_01;
121  const litfloat mDet3_234_013 =
122  pM[SM20] * mDet2_34_13 - pM[SM21] * mDet2_34_03 + pM[SM23] * mDet2_34_01;
123  const litfloat mDet3_234_014 =
124  pM[SM20] * mDet2_34_14 - pM[SM21] * mDet2_34_04 + pM[SM24] * mDet2_34_01;
125  const litfloat mDet3_234_023 =
126  pM[SM20] * mDet2_34_23 - pM[SM22] * mDet2_34_03 + pM[SM23] * mDet2_34_02;
127  const litfloat mDet3_234_024 =
128  pM[SM20] * mDet2_34_24 - pM[SM22] * mDet2_34_04 + pM[SM24] * mDet2_34_02;
129  const litfloat mDet3_234_034 =
130  pM[SM20] * mDet2_34_34 - pM[SM23] * mDet2_34_04 + pM[SM24] * mDet2_34_03;
131  const litfloat mDet3_234_123 =
132  pM[SM21] * mDet2_34_23 - pM[SM22] * mDet2_34_13 + pM[SM23] * mDet2_34_12;
133  const litfloat mDet3_234_124 =
134  pM[SM21] * mDet2_34_24 - pM[SM22] * mDet2_34_14 + pM[SM24] * mDet2_34_12;
135  const litfloat mDet3_234_134 =
136  pM[SM21] * mDet2_34_34 - pM[SM23] * mDet2_34_14 + pM[SM24] * mDet2_34_13;
137  const litfloat mDet3_234_234 =
138  pM[SM22] * mDet2_34_34 - pM[SM23] * mDet2_34_24 + pM[SM24] * mDet2_34_23;
139 
140  // Find all NECESSARY 4x4 dets: (15 of them)
141 
142  const litfloat mDet4_0123_0123 =
143  pM[SM00] * mDet3_123_123 - pM[SM01] * mDet3_123_023
144  + pM[SM02] * mDet3_123_013 - pM[SM03] * mDet3_123_012;
145  const litfloat mDet4_0124_0123 =
146  pM[SM00] * mDet3_124_123 - pM[SM01] * mDet3_124_023
147  + pM[SM02] * mDet3_124_013 - pM[SM03] * mDet3_124_012;
148  const litfloat mDet4_0124_0124 =
149  pM[SM00] * mDet3_124_124 - pM[SM01] * mDet3_124_024
150  + pM[SM02] * mDet3_124_014 - pM[SM04] * mDet3_124_012;
151  const litfloat mDet4_0134_0123 =
152  pM[SM00] * mDet3_134_123 - pM[SM01] * mDet3_134_023
153  + pM[SM02] * mDet3_134_013 - pM[SM03] * mDet3_134_012;
154  const litfloat mDet4_0134_0124 =
155  pM[SM00] * mDet3_134_124 - pM[SM01] * mDet3_134_024
156  + pM[SM02] * mDet3_134_014 - pM[SM04] * mDet3_134_012;
157  const litfloat mDet4_0134_0134 =
158  pM[SM00] * mDet3_134_134 - pM[SM01] * mDet3_134_034
159  + pM[SM03] * mDet3_134_014 - pM[SM04] * mDet3_134_013;
160  const litfloat mDet4_0234_0123 =
161  pM[SM00] * mDet3_234_123 - pM[SM01] * mDet3_234_023
162  + pM[SM02] * mDet3_234_013 - pM[SM03] * mDet3_234_012;
163  const litfloat mDet4_0234_0124 =
164  pM[SM00] * mDet3_234_124 - pM[SM01] * mDet3_234_024
165  + pM[SM02] * mDet3_234_014 - pM[SM04] * mDet3_234_012;
166  const litfloat mDet4_0234_0134 =
167  pM[SM00] * mDet3_234_134 - pM[SM01] * mDet3_234_034
168  + pM[SM03] * mDet3_234_014 - pM[SM04] * mDet3_234_013;
169  const litfloat mDet4_0234_0234 =
170  pM[SM00] * mDet3_234_234 - pM[SM02] * mDet3_234_034
171  + pM[SM03] * mDet3_234_024 - pM[SM04] * mDet3_234_023;
172  const litfloat mDet4_1234_0123 =
173  pM[SM10] * mDet3_234_123 - pM[SM11] * mDet3_234_023
174  + pM[SM12] * mDet3_234_013 - pM[SM13] * mDet3_234_012;
175  const litfloat mDet4_1234_0124 =
176  pM[SM10] * mDet3_234_124 - pM[SM11] * mDet3_234_024
177  + pM[SM12] * mDet3_234_014 - pM[SM14] * mDet3_234_012;
178  const litfloat mDet4_1234_0134 =
179  pM[SM10] * mDet3_234_134 - pM[SM11] * mDet3_234_034
180  + pM[SM13] * mDet3_234_014 - pM[SM14] * mDet3_234_013;
181  const litfloat mDet4_1234_0234 =
182  pM[SM10] * mDet3_234_234 - pM[SM12] * mDet3_234_034
183  + pM[SM13] * mDet3_234_024 - pM[SM14] * mDet3_234_023;
184  const litfloat mDet4_1234_1234 =
185  pM[SM11] * mDet3_234_234 - pM[SM12] * mDet3_234_134
186  + pM[SM13] * mDet3_234_124 - pM[SM14] * mDet3_234_123;
187 
188  // Find the 5x5 det:
189 
190  const litfloat det = pM[SM00] * mDet4_1234_1234 - pM[SM01] * mDet4_1234_0234
191  + pM[SM02] * mDet4_1234_0134 - pM[SM03] * mDet4_1234_0124
192  + pM[SM04] * mDet4_1234_0123;
193 
194  if (det == 0) {
195  std::cout << "-E- InvSym15: zero determinant" << std::endl;
196  return false;
197  }
198 
199  const litfloat oneOverDet = 1.0 / det;
200  const litfloat mn1OverDet = -oneOverDet;
201 
202  pM[SM00] = mDet4_1234_1234 * oneOverDet;
203  pM[SM01] = mDet4_1234_0234 * mn1OverDet;
204  pM[SM02] = mDet4_1234_0134 * oneOverDet;
205  pM[SM03] = mDet4_1234_0124 * mn1OverDet;
206  pM[SM04] = mDet4_1234_0123 * oneOverDet;
207 
208  pM[SM11] = mDet4_0234_0234 * oneOverDet;
209  pM[SM12] = mDet4_0234_0134 * mn1OverDet;
210  pM[SM13] = mDet4_0234_0124 * oneOverDet;
211  pM[SM14] = mDet4_0234_0123 * mn1OverDet;
212 
213  pM[SM22] = mDet4_0134_0134 * oneOverDet;
214  pM[SM23] = mDet4_0134_0124 * mn1OverDet;
215  pM[SM24] = mDet4_0134_0123 * oneOverDet;
216 
217  pM[SM33] = mDet4_0124_0124 * oneOverDet;
218  pM[SM34] = mDet4_0124_0123 * mn1OverDet;
219 
220  pM[SM44] = mDet4_0123_0123 * oneOverDet;
221 
222  return true;
223 }
224 
225 
226 bool Mult25(const std::vector<litfloat>& a,
227  const std::vector<litfloat>& b,
228  std::vector<litfloat>& c) {
229  if (a.size() != 25 || b.size() != 25 || c.size() != 25) {
230  std::cout << "-E- Mult25: size is not correct" << std::endl;
231  return false;
232  }
233 
234  c[0] = a[0] * b[0] + a[1] * b[5] + a[2] * b[10] + a[3] * b[15] + a[4] * b[20];
235  c[1] = a[0] * b[1] + a[1] * b[6] + a[2] * b[11] + a[3] * b[16] + a[4] * b[21];
236  c[2] = a[0] * b[2] + a[1] * b[7] + a[2] * b[12] + a[3] * b[17] + a[4] * b[22];
237  c[3] = a[0] * b[3] + a[1] * b[8] + a[2] * b[13] + a[3] * b[18] + a[4] * b[23];
238  c[4] = a[0] * b[4] + a[1] * b[9] + a[2] * b[14] + a[3] * b[19] + a[4] * b[24];
239  c[5] = a[5] * b[0] + a[6] * b[5] + a[7] * b[10] + a[8] * b[15] + a[9] * b[20];
240  c[6] = a[5] * b[1] + a[6] * b[6] + a[7] * b[11] + a[8] * b[16] + a[9] * b[21];
241  c[7] = a[5] * b[2] + a[6] * b[7] + a[7] * b[12] + a[8] * b[17] + a[9] * b[22];
242  c[8] = a[5] * b[3] + a[6] * b[8] + a[7] * b[13] + a[8] * b[18] + a[9] * b[23];
243  c[9] = a[5] * b[4] + a[6] * b[9] + a[7] * b[14] + a[8] * b[19] + a[9] * b[24];
244  c[10] =
245  a[10] * b[0] + a[11] * b[5] + a[12] * b[10] + a[13] * b[15] + a[14] * b[20];
246  c[11] =
247  a[10] * b[1] + a[11] * b[6] + a[12] * b[11] + a[13] * b[16] + a[14] * b[21];
248  c[12] =
249  a[10] * b[2] + a[11] * b[7] + a[12] * b[12] + a[13] * b[17] + a[14] * b[22];
250  c[13] =
251  a[10] * b[3] + a[11] * b[8] + a[12] * b[13] + a[13] * b[18] + a[14] * b[23];
252  c[14] =
253  a[10] * b[4] + a[11] * b[9] + a[12] * b[14] + a[13] * b[19] + a[14] * b[24];
254  c[15] =
255  a[15] * b[0] + a[16] * b[5] + a[17] * b[10] + a[18] * b[15] + a[19] * b[20];
256  c[16] =
257  a[15] * b[1] + a[16] * b[6] + a[17] * b[11] + a[18] * b[16] + a[19] * b[21];
258  c[17] =
259  a[15] * b[2] + a[16] * b[7] + a[17] * b[12] + a[18] * b[17] + a[19] * b[22];
260  c[18] =
261  a[15] * b[3] + a[16] * b[8] + a[17] * b[13] + a[18] * b[18] + a[19] * b[23];
262  c[19] =
263  a[15] * b[4] + a[16] * b[9] + a[17] * b[14] + a[18] * b[19] + a[19] * b[24];
264  c[20] =
265  a[20] * b[0] + a[21] * b[5] + a[22] * b[10] + a[23] * b[15] + a[24] * b[20];
266  c[21] =
267  a[20] * b[1] + a[21] * b[6] + a[22] * b[11] + a[23] * b[16] + a[24] * b[21];
268  c[22] =
269  a[20] * b[2] + a[21] * b[7] + a[22] * b[12] + a[23] * b[17] + a[24] * b[22];
270  c[23] =
271  a[20] * b[3] + a[21] * b[8] + a[22] * b[13] + a[23] * b[18] + a[24] * b[23];
272  c[24] =
273  a[20] * b[4] + a[21] * b[9] + a[22] * b[14] + a[23] * b[19] + a[24] * b[24];
274 
275  return true;
276 }
277 
278 bool Mult36(const std::vector<litfloat>& a,
279  const std::vector<litfloat>& b,
280  std::vector<litfloat>& c) {
281  if (a.size() != 36 || b.size() != 36 || c.size() != 36) {
282  std::cout << "-E- Mult36: size is not correct" << std::endl;
283  return false;
284  }
285 
286  for (int i = 0; i < 6; ++i) {
287  for (int j = 0; j < 6; ++j) {
288  c[6 * i + j] = 0;
289 
290  for (int k = 0; k < 6; ++k)
291  c[6 * i + j] += a[6 * i + k] * b[j + 6 * k];
292  }
293  }
294 
295  return true;
296 }
297 
298 bool Transpose25(std::vector<litfloat>& a) {
299  if (a.size() != 25) {
300  std::cout << "-E- Transpose25: size is not correct" << std::endl;
301  return true;
302  }
303  std::vector<litfloat> b(a);
304  a[0] = b[0];
305  a[1] = b[5];
306  a[2] = b[10];
307  a[3] = b[15];
308  a[4] = b[20];
309  a[5] = b[1];
310  a[6] = b[6];
311  a[7] = b[11];
312  a[8] = b[16];
313  a[9] = b[21];
314  a[10] = b[2];
315  a[11] = b[7];
316  a[12] = b[12];
317  a[13] = b[17];
318  a[14] = b[22];
319  a[15] = b[3];
320  a[16] = b[8];
321  a[17] = b[13];
322  a[18] = b[18];
323  a[19] = b[23];
324  a[20] = b[4];
325  a[21] = b[9];
326  a[22] = b[14];
327  a[23] = b[19];
328  a[24] = b[24];
329  return true;
330 }
331 
332 
333 bool Mult25On5(const std::vector<litfloat>& a,
334  const std::vector<litfloat>& b,
335  std::vector<litfloat>& c) {
336  if (a.size() != 25 || b.size() != 7 || c.size() != 7) {
337  std::cout << "-E- Mult25On5: size is not correct" << std::endl;
338  return false;
339  }
340  c[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3] + a[4] * b[4];
341  c[1] = a[5] * b[0] + a[6] * b[1] + a[7] * b[2] + a[8] * b[3] + a[9] * b[4];
342  c[2] =
343  a[10] * b[0] + a[11] * b[1] + a[12] * b[2] + a[13] * b[3] + a[14] * b[4];
344  c[3] =
345  a[15] * b[0] + a[16] * b[1] + a[17] * b[2] + a[18] * b[3] + a[19] * b[4];
346  c[4] =
347  a[20] * b[0] + a[21] * b[1] + a[22] * b[2] + a[23] * b[3] + a[24] * b[4];
348  return true;
349 }
350 
351 bool Mult15On5(const std::vector<litfloat>& a,
352  const std::vector<litfloat>& b,
353  std::vector<litfloat>& c) {
354  if (a.size() != 15 || b.size() != 7 || c.size() != 7) {
355  std::cout << "-E- Mult15On5: size is not correct" << std::endl;
356  return false;
357  }
358  c[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3] + a[4] * b[4];
359  c[1] = a[1] * b[0] + a[5] * b[1] + a[6] * b[2] + a[7] * b[3] + a[8] * b[4];
360  c[2] = a[2] * b[0] + a[6] * b[1] + a[9] * b[2] + a[10] * b[3] + a[11] * b[4];
361  c[3] = a[3] * b[0] + a[7] * b[1] + a[10] * b[2] + a[12] * b[3] + a[13] * b[4];
362  c[4] = a[4] * b[0] + a[8] * b[1] + a[11] * b[2] + a[13] * b[3] + a[14] * b[4];
363  return true;
364 }
365 
366 bool Subtract(const std::vector<litfloat>& a,
367  const std::vector<litfloat>& b,
368  std::vector<litfloat>& c) {
369  if (a.size() != b.size() || a.size() != c.size()) {
370  std::cout << "-E- Subtract: size is not correct" << std::endl;
371  return false;
372  }
373  for (unsigned int i = 0; i < a.size(); ++i) {
374  c[i] = a[i] - b[i];
375  }
376  return true;
377 }
378 
379 
380 bool Add(const std::vector<litfloat>& a,
381  const std::vector<litfloat>& b,
382  std::vector<litfloat>& c) {
383  if (a.size() != b.size() || a.size() != c.size()) {
384  std::cout << "-E- Add: size is not correct" << std::endl;
385  return false;
386  }
387  for (unsigned int i = 0; i < a.size(); ++i) {
388  c[i] = a[i] + b[i];
389  }
390  return true;
391 }
392 
393 
394 /* a*b*a^T */
395 bool Similarity(const std::vector<litfloat>& a,
396  const std::vector<litfloat>& b,
397  std::vector<litfloat>& c) {
398  if (a.size() != 25 || b.size() != 15 || c.size() != 15) {
399  std::cout << "-E- Similarity: size is not correct" << std::endl;
400  return false;
401  }
402 
403  litfloat A =
404  a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3] + a[4] * b[4];
405  litfloat B =
406  a[0] * b[1] + a[1] * b[5] + a[2] * b[6] + a[3] * b[7] + a[4] * b[8];
407  litfloat C =
408  a[0] * b[2] + a[1] * b[6] + a[2] * b[9] + a[3] * b[10] + a[4] * b[11];
409  litfloat D =
410  a[0] * b[3] + a[1] * b[7] + a[2] * b[10] + a[3] * b[12] + a[4] * b[13];
411  litfloat E =
412  a[0] * b[4] + a[1] * b[8] + a[2] * b[11] + a[3] * b[13] + a[4] * b[14];
413 
414  litfloat F =
415  a[5] * b[0] + a[6] * b[1] + a[7] * b[2] + a[8] * b[3] + a[9] * b[4];
416  litfloat G =
417  a[5] * b[1] + a[6] * b[5] + a[7] * b[6] + a[8] * b[7] + a[9] * b[8];
418  litfloat H =
419  a[5] * b[2] + a[6] * b[6] + a[7] * b[9] + a[8] * b[10] + a[9] * b[11];
420  litfloat I =
421  a[5] * b[3] + a[6] * b[7] + a[7] * b[10] + a[8] * b[12] + a[9] * b[13];
422  litfloat J =
423  a[5] * b[4] + a[6] * b[8] + a[7] * b[11] + a[8] * b[13] + a[9] * b[14];
424 
425  litfloat K =
426  a[10] * b[0] + a[11] * b[1] + a[12] * b[2] + a[13] * b[3] + a[14] * b[4];
427  litfloat L =
428  a[10] * b[1] + a[11] * b[5] + a[12] * b[6] + a[13] * b[7] + a[14] * b[8];
429  litfloat M =
430  a[10] * b[2] + a[11] * b[6] + a[12] * b[9] + a[13] * b[10] + a[14] * b[11];
431  litfloat N =
432  a[10] * b[3] + a[11] * b[7] + a[12] * b[10] + a[13] * b[12] + a[14] * b[13];
433  litfloat O =
434  a[10] * b[4] + a[11] * b[8] + a[12] * b[11] + a[13] * b[13] + a[14] * b[14];
435 
436  litfloat P =
437  a[15] * b[0] + a[16] * b[1] + a[17] * b[2] + a[18] * b[3] + a[19] * b[4];
438  litfloat Q =
439  a[15] * b[1] + a[16] * b[5] + a[17] * b[6] + a[18] * b[7] + a[19] * b[8];
440  litfloat R =
441  a[15] * b[2] + a[16] * b[6] + a[17] * b[9] + a[18] * b[10] + a[19] * b[11];
442  litfloat S =
443  a[15] * b[3] + a[16] * b[7] + a[17] * b[10] + a[18] * b[12] + a[19] * b[13];
444  litfloat T =
445  a[15] * b[4] + a[16] * b[8] + a[17] * b[11] + a[18] * b[13] + a[19] * b[14];
446 
447  c[0] = A * a[0] + B * a[1] + C * a[2] + D * a[3] + E * a[4];
448  c[1] = A * a[5] + B * a[6] + C * a[7] + D * a[8] + E * a[9];
449  c[2] = A * a[10] + B * a[11] + C * a[12] + D * a[13] + E * a[14];
450  c[3] = A * a[15] + B * a[16] + C * a[17] + D * a[18] + E * a[19];
451  c[4] = A * a[20] + B * a[21] + C * a[22] + D * a[23] + E * a[24];
452 
453  c[5] = F * a[5] + G * a[6] + H * a[7] + I * a[8] + J * a[9];
454  c[6] = F * a[10] + G * a[11] + H * a[12] + I * a[13] + J * a[14];
455  c[7] = F * a[15] + G * a[16] + H * a[17] + I * a[18] + J * a[19];
456  c[8] = F * a[20] + G * a[21] + H * a[22] + I * a[23] + J * a[24];
457 
458  c[9] = K * a[10] + L * a[11] + M * a[12] + N * a[13] + O * a[14];
459  c[10] = K * a[15] + L * a[16] + M * a[17] + N * a[18] + O * a[19];
460  c[11] = K * a[20] + L * a[21] + M * a[22] + N * a[23] + O * a[24];
461 
462  c[12] = P * a[15] + Q * a[16] + R * a[17] + S * a[18] + T * a[19];
463  c[13] = P * a[20] + Q * a[21] + R * a[22] + S * a[23] + T * a[24];
464 
465  c[14] =
466  (a[20] * b[0] + a[21] * b[1] + a[22] * b[2] + a[23] * b[3] + a[24] * b[4])
467  * a[20]
468  + (a[20] * b[1] + a[21] * b[5] + a[22] * b[6] + a[23] * b[7] + a[24] * b[8])
469  * a[21]
470  + (a[20] * b[2] + a[21] * b[6] + a[22] * b[9] + a[23] * b[10]
471  + a[24] * b[11])
472  * a[22]
473  + (a[20] * b[3] + a[21] * b[7] + a[22] * b[10] + a[23] * b[12]
474  + a[24] * b[13])
475  * a[23]
476  + (a[20] * b[4] + a[21] * b[8] + a[22] * b[11] + a[23] * b[13]
477  + a[24] * b[14])
478  * a[24];
479  return true;
480 }
481 
482 
483 bool Mult15On25(const std::vector<litfloat>& a,
484  const std::vector<litfloat>& b,
485  std::vector<litfloat>& c) {
486  if (a.size() != 15 || b.size() != 25 || c.size() != 25) {
487  std::cout << "-E- Mult15On25: size is not correct" << std::endl;
488  return false;
489  }
490  c[0] = a[0] * b[0] + a[1] * b[5] + a[2] * b[10] + a[3] * b[15] + a[4] * b[20];
491  c[1] = a[0] * b[1] + a[1] * b[6] + a[2] * b[11] + a[3] * b[16] + a[4] * b[21];
492  c[2] = a[0] * b[2] + a[1] * b[7] + a[2] * b[12] + a[3] * b[17] + a[4] * b[22];
493  c[3] = a[0] * b[3] + a[1] * b[8] + a[2] * b[13] + a[3] * b[18] + a[4] * b[23];
494  c[4] = a[0] * b[4] + a[1] * b[9] + a[2] * b[14] + a[3] * b[19] + a[4] * b[24];
495  c[5] = a[1] * b[0] + a[5] * b[5] + a[6] * b[10] + a[7] * b[15] + a[8] * b[20];
496  c[6] = a[1] * b[1] + a[5] * b[6] + a[6] * b[11] + a[7] * b[16] + a[8] * b[21];
497  c[7] = a[1] * b[2] + a[5] * b[7] + a[6] * b[12] + a[7] * b[17] + a[8] * b[22];
498  c[8] = a[1] * b[3] + a[5] * b[8] + a[6] * b[13] + a[7] * b[18] + a[8] * b[23];
499  c[9] = a[1] * b[4] + a[5] * b[9] + a[6] * b[14] + a[7] * b[19] + a[8] * b[24];
500  c[10] =
501  a[2] * b[0] + a[6] * b[5] + a[9] * b[10] + a[10] * b[15] + a[11] * b[20];
502  c[11] =
503  a[2] * b[1] + a[6] * b[6] + a[9] * b[11] + a[10] * b[16] + a[11] * b[21];
504  c[12] =
505  a[2] * b[2] + a[6] * b[7] + a[9] * b[12] + a[10] * b[17] + a[11] * b[22];
506  c[13] =
507  a[2] * b[3] + a[6] * b[8] + a[9] * b[13] + a[10] * b[18] + a[11] * b[23];
508  c[14] =
509  a[2] * b[4] + a[6] * b[9] + a[9] * b[14] + a[10] * b[19] + a[11] * b[24];
510  c[15] =
511  a[3] * b[0] + a[7] * b[5] + a[10] * b[10] + a[12] * b[15] + a[13] * b[20];
512  c[16] =
513  a[3] * b[1] + a[7] * b[6] + a[10] * b[11] + a[12] * b[16] + a[13] * b[21];
514  c[17] =
515  a[3] * b[2] + a[7] * b[7] + a[10] * b[12] + a[12] * b[17] + a[13] * b[22];
516  c[18] =
517  a[3] * b[3] + a[7] * b[8] + a[10] * b[13] + a[12] * b[18] + a[13] * b[23];
518  c[19] =
519  a[3] * b[4] + a[7] * b[9] + a[10] * b[14] + a[12] * b[19] + a[13] * b[24];
520  c[20] =
521  a[4] * b[0] + a[8] * b[5] + a[11] * b[10] + a[13] * b[15] + a[14] * b[20];
522  c[21] =
523  a[4] * b[1] + a[8] * b[6] + a[11] * b[11] + a[13] * b[16] + a[14] * b[21];
524  c[22] =
525  a[4] * b[2] + a[8] * b[7] + a[11] * b[12] + a[13] * b[17] + a[14] * b[22];
526  c[23] =
527  a[4] * b[3] + a[8] * b[8] + a[11] * b[13] + a[13] * b[18] + a[14] * b[23];
528  c[24] =
529  a[4] * b[4] + a[8] * b[9] + a[11] * b[14] + a[13] * b[19] + a[14] * b[24];
530 
531  return true;
532 }
533 
534 bool Mult25On15(const std::vector<litfloat>& a,
535  const std::vector<litfloat>& b,
536  std::vector<litfloat>& c) {
537  if (a.size() != 25 || b.size() != 15 || c.size() != 25) {
538  std::cout << "-E- Mult15On25: size is not correct" << std::endl;
539  return false;
540  }
541  c[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3] + a[4] * b[4];
542  c[1] = a[0] * b[1] + a[1] * b[5] + a[2] * b[6] + a[3] * b[7] + a[4] * b[8];
543  c[2] = a[0] * b[2] + a[1] * b[6] + a[2] * b[9] + a[3] * b[10] + a[4] * b[11];
544  c[3] = a[0] * b[3] + a[1] * b[7] + a[2] * b[10] + a[3] * b[12] + a[4] * b[13];
545  c[4] = a[0] * b[4] + a[1] * b[8] + a[2] * b[11] + a[3] * b[13] + a[4] * b[14];
546  c[5] = a[5] * b[0] + a[6] * b[1] + a[7] * b[2] + a[8] * b[3] + a[9] * b[4];
547  c[6] = a[5] * b[1] + a[6] * b[5] + a[7] * b[6] + a[8] * b[7] + a[9] * b[8];
548  c[7] = a[5] * b[2] + a[6] * b[6] + a[7] * b[9] + a[8] * b[10] + a[9] * b[11];
549  c[8] = a[5] * b[3] + a[6] * b[7] + a[7] * b[10] + a[8] * b[12] + a[9] * b[13];
550  c[9] = a[5] * b[4] + a[6] * b[8] + a[7] * b[11] + a[8] * b[13] + a[9] * b[14];
551  c[10] =
552  a[10] * b[0] + a[11] * b[1] + a[12] * b[2] + a[13] * b[3] + a[14] * b[4];
553  c[11] =
554  a[10] * b[1] + a[11] * b[5] + a[12] * b[6] + a[13] * b[7] + a[14] * b[8];
555  c[12] =
556  a[10] * b[2] + a[11] * b[6] + a[12] * b[9] + a[13] * b[10] + a[14] * b[11];
557  c[13] =
558  a[10] * b[3] + a[11] * b[7] + a[12] * b[10] + a[13] * b[12] + a[14] * b[13];
559  c[14] =
560  a[10] * b[4] + a[11] * b[8] + a[12] * b[11] + a[13] * b[13] + a[14] * b[14];
561  c[15] =
562  a[15] * b[0] + a[16] * b[1] + a[17] * b[2] + a[18] * b[3] + a[19] * b[4];
563  c[16] =
564  a[15] * b[1] + a[16] * b[5] + a[17] * b[6] + a[18] * b[7] + a[19] * b[8];
565  c[17] =
566  a[15] * b[2] + a[16] * b[6] + a[17] * b[9] + a[18] * b[10] + a[19] * b[11];
567  c[18] =
568  a[15] * b[3] + a[16] * b[7] + a[17] * b[10] + a[18] * b[12] + a[19] * b[13];
569  c[19] =
570  a[15] * b[4] + a[16] * b[8] + a[17] * b[11] + a[18] * b[13] + a[19] * b[14];
571  c[20] =
572  a[20] * b[0] + a[21] * b[1] + a[22] * b[2] + a[23] * b[3] + a[24] * b[4];
573  c[21] =
574  a[20] * b[1] + a[21] * b[5] + a[22] * b[6] + a[23] * b[7] + a[24] * b[8];
575  c[22] =
576  a[20] * b[2] + a[21] * b[6] + a[22] * b[9] + a[23] * b[10] + a[24] * b[11];
577  c[23] =
578  a[20] * b[3] + a[21] * b[7] + a[22] * b[10] + a[23] * b[12] + a[24] * b[13];
579  c[24] =
580  a[20] * b[4] + a[21] * b[8] + a[22] * b[11] + a[23] * b[13] + a[24] * b[14];
581 
582  return true;
583 }
SM04
#define SM04
Definition: CbmLitMatrixMath.cxx:15
litfloat
double litfloat
Definition: CbmLitFloat.h:15
SM22
#define SM22
Definition: CbmLitMatrixMath.cxx:25
SM03
#define SM03
Definition: CbmLitMatrixMath.cxx:14
Add
bool Add(const std::vector< litfloat > &a, const std::vector< litfloat > &b, std::vector< litfloat > &c)
Definition: CbmLitMatrixMath.cxx:380
SM00
#define SM00
Definition: CbmLitMatrixMath.cxx:11
SM23
#define SM23
Definition: CbmLitMatrixMath.cxx:26
SM44
#define SM44
Definition: CbmLitMatrixMath.cxx:39
SM40
#define SM40
Definition: CbmLitMatrixMath.cxx:35
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
Mult25On15
bool Mult25On15(const std::vector< litfloat > &a, const std::vector< litfloat > &b, std::vector< litfloat > &c)
Definition: CbmLitMatrixMath.cxx:534
SM24
#define SM24
Definition: CbmLitMatrixMath.cxx:27
Mult25
bool Mult25(const std::vector< litfloat > &a, const std::vector< litfloat > &b, std::vector< litfloat > &c)
Definition: CbmLitMatrixMath.cxx:226
SM14
#define SM14
Definition: CbmLitMatrixMath.cxx:21
SM42
#define SM42
Definition: CbmLitMatrixMath.cxx:37
SM10
#define SM10
Definition: CbmLitMatrixMath.cxx:17
Similarity
bool Similarity(const std::vector< litfloat > &a, const std::vector< litfloat > &b, std::vector< litfloat > &c)
Definition: CbmLitMatrixMath.cxx:395
Transpose25
bool Transpose25(std::vector< litfloat > &a)
Definition: CbmLitMatrixMath.cxx:298
SM41
#define SM41
Definition: CbmLitMatrixMath.cxx:36
SM21
#define SM21
Definition: CbmLitMatrixMath.cxx:24
SM34
#define SM34
Definition: CbmLitMatrixMath.cxx:33
SM01
#define SM01
Definition: CbmLitMatrixMath.cxx:12
InvSym15
bool InvSym15(std::vector< litfloat > &a)
Definition: CbmLitMatrixMath.cxx:41
SM11
#define SM11
Definition: CbmLitMatrixMath.cxx:18
SM20
#define SM20
Definition: CbmLitMatrixMath.cxx:23
SM12
#define SM12
Definition: CbmLitMatrixMath.cxx:19
Mult15On5
bool Mult15On5(const std::vector< litfloat > &a, const std::vector< litfloat > &b, std::vector< litfloat > &c)
Definition: CbmLitMatrixMath.cxx:351
SM33
#define SM33
Definition: CbmLitMatrixMath.cxx:32
SM31
#define SM31
Definition: CbmLitMatrixMath.cxx:30
CbmLitMatrixMath.h
Mult15On25
bool Mult15On25(const std::vector< litfloat > &a, const std::vector< litfloat > &b, std::vector< litfloat > &c)
Definition: CbmLitMatrixMath.cxx:483
Mult36
bool Mult36(const std::vector< litfloat > &a, const std::vector< litfloat > &b, std::vector< litfloat > &c)
Definition: CbmLitMatrixMath.cxx:278
Mult25On5
bool Mult25On5(const std::vector< litfloat > &a, const std::vector< litfloat > &b, std::vector< litfloat > &c)
Definition: CbmLitMatrixMath.cxx:333
SM02
#define SM02
Definition: CbmLitMatrixMath.cxx:13
Subtract
bool Subtract(const std::vector< litfloat > &a, const std::vector< litfloat > &b, std::vector< litfloat > &c)
Definition: CbmLitMatrixMath.cxx:366
SM13
#define SM13
Definition: CbmLitMatrixMath.cxx:20
SM43
#define SM43
Definition: CbmLitMatrixMath.cxx:38
SM32
#define SM32
Definition: CbmLitMatrixMath.cxx:31
SM30
#define SM30
Definition: CbmLitMatrixMath.cxx:29