FEDRA emulsion software from the OPERA Collaboration
main.C File Reference
#include <iostream>
#include <cmath>
#include "SVector.hh"
#include "SMatrix.hh"
#include "MatrixFunctions.hh"
#include "Dfact.hh"
#include "Dinv.hh"
Include dependency graph for main.C:

Functions

int main (void)
 

Function Documentation

◆ main()

int main ( void  )
13  {
14 
15 #ifdef XXX
16  SVector<float,3> x(4,5,6);
17  SVector<float,2> y(2,3);
18  cout << "x: " << x << endl;
19  cout << "y: " << y << endl;
20 
23 
24  A.place_in_row(y, 1, 1);
25  A.place_in_col(x + 2, 1, 0);
26  A.place_at(B * -4, 2, 1);
27  cout << "A: " << endl << A << endl;
28 
29  return 0;
30 #endif
31 
32 #ifdef XXX
34  A(0,0) = A(1,0) = 1;
35  A(0,1) = 3;
36  A(1,1) = A(2,2) = 2;
37  cout << "A: " << endl << A << endl;
38 
39  SVector<double,3> x = A.row(0);
40  cout << "x: " << x << endl;
41 
42  SVector<double,3> y = A.col(1);
43  cout << "y: " << y << endl;
44 
45  return 0;
46 #endif
47 
48 #ifdef XXX1
50  A(0,0) = A(0,1) = A(1,0) = 1;
51  A(1,1) = A(2,2) = 2;
52 
53  SMatrix<double,3> B = A; // save A in B
54  cout << "A: " << endl << A << endl;
55 
56 // double det = 0.;
57 // A.sdet(det);
58 // cout << "Determinant: " << det << endl;
59  // WARNING: A has changed!!
60 // cout << "A again: " << endl << A << endl;
61 
62  A.sinvert();
63  cout << "A^-1: " << endl << A << endl;
64 
65  // check if this is really the inverse:
66  cout << "A^-1 * B: " << endl << A * B << endl;
67 
68  return 0;
69 #endif
70 
71 #ifdef XXX
73  A(0,0) = A(0,1) = A(1,0) = 1;
74  A(1,1) = A(2,2) = 2;
75  cout << " A: " << endl << A << endl;
76 
77  SVector<double,3> x(1,2,3);
78  cout << "x: " << x << endl;
79 
80  // we add 1 to each component of x and A
81  cout << " (x+1)^T * (A+1) * (x+1): " << product(x+1,A+1) << endl;
82 
83  return 0;
84 #endif
85 
86 #ifdef XXX
88  A(0,0) = A(0,1) = A(1,1) = A(2,2) = 4.;
89  A(2,3) = 1.;
90  cout << "A: " << endl << A << endl;
91  SVector<float,4> x(1,2,3,4);
92  cout << " x: " << x << endl;
93  SVector<float,3> a(1,2,3);
94  cout << " a: " << a << endl;
95  SVector<float,4> y = x + A * a;
96  // SVector<float,4> y = A * a;
97  cout << " y: " << y << endl;
98 
99  SVector<float,3> b = (x+1) * (A+1);
100  cout << " b: " << b << endl;
101 
102  return 0;
103 #endif
104 
105 #ifdef XXX
107  A(0,0) = A(0,1) = A(1,1) = A(2,0) = A(3,1) = 4.;
108  cout << "A: " << endl << A << endl;
109 
111  S(0,0) = S(0,1) = S(1,1) = S(0,2) = 1.;
112  cout << " S: " << endl << S << endl;
113 
114  SMatrix<float,4,3> C = A * S;
115  cout << " C: " << endl << C << endl;
116 
117  return 0;
118 #endif
119 
120 #ifdef XXX
121  SMatrix<float,2,3> x = 4.;
122  SMatrix<float,2,3> y = 5.;
123  SMatrix<float,2,3> z = 64.;
124 
125  // element wise multiplication
126  cout << "x * y: " << endl << times(x, -y) << endl;
127 
128  x += z - y;
129  cout << "x += z - y: " << endl << x << endl;
130 
131  // element wise square root
132  cout << "sqrt(z): " << endl << sqrt(z) << endl;
133 
134  // element wise multiplication with constant
135  cout << "2 * y: " << endl << 2 * y << endl;
136 
137  // a more complex expression
138  cout << "fabs(-z + 3*x): " << endl << fabs(-z + 3*x) << endl;
139 
140  return 0;
141 #endif
142 
143 #ifdef XXX
144  SMatrix<float,2,3> A = 15.;
145  A(0,0) = A(1,1) = A(0,2) = 5.;
146 
147  cout << "A: " << endl << A << endl;
148 
149  SVector<float,3> x(1,2,3);
150  SVector<float,3> y(4,5,6);
151 
152  cout << "dot(x,y): " << dot(x,y) << endl;
153 
154  cout << "mag(x): " << mag(x) << endl;
155 
156  cout << "cross(x,y): " << cross(x,y) << endl;
157 
158  cout << "unit(x): " << unit(x) << endl;
159 
160  SVector<float,3> z(4,16,64);
161  cout << "x + y: " << x+y << endl;
162 
163  cout << "x * y: " << x * -y << endl;
164  x += z - y;
165  cout << "x += z - y: " << x << endl;
166 
167  // element wise square root
168  cout << "sqrt(z): " << sqrt(z) << endl;
169 
170  // element wise multiplication with constant
171  cout << "2 * y: " << 2 * y << endl;
172 
173  // a more complex expression
174  cout << "fabs(-z + 3*x): " << fabs(-z + 3*x) << endl;
175 
177  SVector<float,2> b(1,2);
178  a.place_at(b,2);
179  cout << "a: " << a << endl;
180 #endif
181 
182  for(unsigned int i=0; i<1000000; ++i) {
183 #ifdef XXX
184  VtVector a(1.,2.,3.);
185  VtVector b(4.,5.,6.);
186  VtVector c(8.,9.,10.);
187 
188  VtVector d = a*(-1) + b;
189  VtVector d = a + b + c;
190 #endif
191 #ifdef XXX
192  VtMatrix A(4,3);
193  A(0,0) = A(1,1) = A(2,2) = 4.;
194  A(2,3) = 1.;
195  VtVector a(1,2,3);
196  // cout << " a: " << a << endl;
197  // cout << " A: " << A << endl;
198  // VtVector x(1,2,3,4);
199  // cout << " x: " << x << endl;
200  // VtVector y = x + A * a;
201  VtVector y = A * a;
202  cout << " y: " << y << endl;
203  exit(0);
204 #endif
205 #ifdef XXX
206  // ==========================================
207  VtMatrix A(3,3);
208  A(0,0) = A(1,1) = A(2,2) = 4.;
209  // A(2,3) = 1.;
210  // cout << " A: " << -A << endl;
211  VtMatrix B(3,3);
212  B(0,1) = B(1,0) = B(1,1) = B(0,2) = 1.;
213  // cout << " B: " << B << endl;
214  // cout << " B: " << B << endl;
215  VtMatrix C(3,3);
216  C(0,2) = C(1,2) = C(2,2) = 2.;
217  // cout << " C: " << C << endl;
218  // VtMatrix D = B + C + (-A);
219  VtMatrix D = A + B + C + A + B + C;
220  cout << " D: " << D << endl;
221  exit(0);
222 #endif
223 #ifdef XXX
224  VtSymMatrix VA(3,2.);
225  VA(0,0) = VA(0,1) = VA(1,0) = 1;
226  // cout << " A: " << VA << endl;
227  // cout << " det A: " << VA.det() << endl;
228  VA.det();
229  VA.VtDsinv();
230  cout << " A^-1: " << VA << endl;
231 #endif
232 #ifdef XXX
233  //===================================
234  VtSymMatrix A(3,3.);
235  A(0,0) = A(0,1) = A(1,0) = 1;
236  // cout << " A: " << VA << endl;
237  VtSymMatrix B(3,3);
238  B(0,1) = B(1,0) = B(1,1) = B(2,2) = 1.;
239  // cout << " B: " << B << endl;
240  VtSymMatrix C(3,3);
241  C(0,1) = C(1,0) = C(2,1) = C(0,2) = 2.;
242  cout << " C: " << C << endl;
243  VtVector x(1,2,3);
244  // cout << " x: " << x << endl;
245  VtVector y(4,5,6);
246  // cout << " y: " << y << endl;
247  (A+B+C).product(x+y);
248  cout << " (x+y)^T * (A+B+C) * (x+y): " << (A+B+C).product(x+y) << endl;
249  exit(0);
250 #endif
251 #ifdef XXX
252  // cout << " c: " << c << endl;
254  a[0] = 1.; a[1] = 2.; a[2] = 3.;
256  b[0] = 4.; b[1] = 5.; b[2] = 6.;
258  c[0] = 8.; c[1] = 9.; c[2] = 10.;
259 
260  SVector<float,3> d = a + b + c;
261  cout << "d: " << d << endl;
262  exit(0);
263 
264  cout << "d: " << d << endl;
265  d -= b + c;
266  cout << "d -= b + c: " << d << endl;
267  cout << "dot(a,b): " << dot(a,b) << endl;
268  cout << "dot(a+b,c+d): " << dot(a+b,c+d) << endl;
269  cout << "dot(a*b,c+d): " << dot(a*b,c+d) << endl;
270  cout << "dot(a*b+c,c+d): " << dot(a*b+c,c+d) << endl;
271 
272  cout << "mag2(a) " << mag2(a) << endl;
273  cout << "mag(a) " << mag(a) << endl;
274  cout << "mag2(a+b+c)" << mag2(a+b+c) << endl;
275  cout << "mag(a+b+c) " << mag(a+b+c) << endl;
276  // mag2(a);
277  // mag2(a+b+c);
278 
279  // SVector<float,3> d = a + static_cast<float>(3.);
280  // SVector<float,3> d = sqr(a + b + -20);
281  // SVector<float,3> d = (-a+b) * 3;
282  SVector<float,3> d = a * (b + c);
283  d = unit(a + b + c);
284  // d.unit();
285  // cout << "d unit: " << d << endl;
286  // cout << "d = -a + b: " << d << endl;
287  // cout << "a: " << a << " b: " << b << endl;
288  // cout << "mag2(3*a): " << mag2(3*a) << endl;
289  // cout << "cross(3*a,b+c): " << cross(3*a,b+c) << endl;
290  // cout << "dot(-a,c+d+3): " << dot(-a,c+d+3) << endl;
291  // cout << "mag2(-a+d): " << mag2(-a+d) << " mag(d): " << mag(-a+d) << endl;
292 
293  SMatrix<float,3,3> A = 15.;
294  SMatrix<float,3,3> B = A;
295  A(0,0) = A(1,1) = A(2,0) = A(2,2) = 5.;
296  SMatrix<float,3,3> C = fabs(A + -B + 2);
297 // cout << "A: " << endl << A << endl;
298  cout << "C: " << endl << C << endl;
299 #endif
300 
301 #ifdef XXX
303  A(0,0) = A(1,1) = A(2,2) = 4.;
304  A(2,3) = 1.;
305  // cout << "A: " << endl << A << endl;
306  SVector<float,4> x(1,2,3,4);
307  // cout << " x: " << x << endl;
308  SVector<float,3> a(1,2,3);
309  // cout << " a: " << a << endl;
310  SVector<float,4> y = x + A * a;
311  // SVector<float,4> y = A * a;
312  cout << " y: " << y << endl;
313  exit(0);
314 #endif
315 #ifdef XXX
316  // =======================================
318  A(0,0) = A(1,1) = A(2,2) = 4.;
319  // cout << "A: " << endl << A << endl;
320  // cout << "B: " << endl << B << endl;
322  B(0,1) = B(1,0) = B(1,1) = B(0,2) = 1.;
323  // cout << "B: " << endl << B << endl;
324  // SMatrix<float,3,3> C = times(A,B); // component wise multiplication
326  C(0,2) = C(1,2) = C(2,2) = 2.;
327  // cout << "C: " << endl << C << endl;
328  // SMatrix<float,3,3> D = -A + B + C;
329  SMatrix<float,3,3> D = A + B + C + A + B + C;
330  cout << "D: " << endl << D << endl;
331  exit(0);
332  SMatrix<float,3,2> E = 4.;
333  cout << "E: " << endl << E << endl;
334  // D = A + E;
335 #endif
336 
337 #ifdef XXX
338  SVector<float,3> b(4,5,6);
339  cout << " x: " << x << endl;
340 
341  // SVector<float,4> y = x + (A * 2) * (a + 1);
342  SVector<float,3> y = (x+1) * (A+1);
343  cout << " y: " << y << endl;
344 
346  S(0,0) = S(1,0) = S(2,0) = 1.;
347  cout << " S: " << endl << S << endl;
348  SMatrix<float,4,3> C = A * S;
349  cout << " C: " << endl << C << endl;
350 #endif
351 #ifdef XXX
353  A(0,0) = A(0,1) = A(1,0) = 1;
354  A(1,1) = A(2,2) = 2;
355  // cout << "A: " << endl << A << endl;
356  double det = 0.;
357  A.sdet(det);
358  cout << "Determinant: " << det << endl;
359  cout << "A again: " << endl << A << endl;
360  exit(0);
361  A.sinvert();
362  cout << "A^-1: " << endl << A << endl;
363  exit(0);
364 #endif
365 #ifdef XXX
366  SVector<double,3> x(1,2,3);
367  cout << "x: " << x << endl;
368  cout << " x^T * A * x: " << product(x+1,A+1) << endl;
369  // product(A,x);
370 
371  SMatrix<double,3> B = 1;
372  cout << "B: " << endl << B << endl;
373  A /= B + 1;
374  cout << "A/=B: " << endl << A << endl;
375 
376  SVector<double,3> y(4,5,6);
377  cout << "y: " << y << endl;
378  y /= x;
379  cout << "y/=x: " << y << endl;
380  exit(0);
381 #endif
382 #ifdef XXX
383  //===================================
385  A(0,0) = A(0,1) = A(1,0) = 1;
386  A(1,1) = A(2,2) = 3.;
387  // cout << " A: " << endl << VA << endl;
389  B(0,1) = B(1,0) = B(1,1) = B(2,2) = 1.;
390  B(0,0) = 3;
391  // cout << " B: " << endl << B << endl;
393  C(0,1) = C(1,0) = C(2,1) = C(0,2) = 2.;
394  C(0,0) = C(1,1) = C(2,2) = 3;
395  // cout << " C: " << endl << C << endl;
396  SVector<float,3> x(1,2,3);
397  // cout << " x: " << x << endl;
398  SVector<float,3> y(4,5,6);
399  // cout << " y: " << y << endl;
400  product(A+B+C,x+y);
401  cout << " (x+y)^T * (A+B+C) * (x+y): " << product(A+B+C,x+y) << endl;
402  exit(0);
403 #endif
404 #ifdef XXX
406  SVector<float,2> y(1,2);
407  // cout << "y: " << y << endl;
408  x.place_at(y,2);
409  cout << "x: " << x << endl;
411  SMatrix<float,2,2> B = 1;
412  // SVector<float,2> x(1,2);
413  // A.place_in_row(x+2,1,1);
414  // A.place_in_col(x,1,1);
415  A.place_at(B,0,1);
416  cout << "A: " << endl << A << endl;
417  exit(0);
418 #endif
419 #ifdef XXX
420  VtVector x(4);
421  VtVector y(1,2);
422  // cout << "y: " << y << endl;
423  x.place_at(y,2);
424  cout << "x: " << x << endl;
425  exit(0);
426 #endif
427 #ifdef XXX
429  SMatrix<float,2,2> B = 1;
430  // SVector<float,2> x(1,2);
431  // A.place_in_row(x+2,1,1);
432  // A.place_in_col(x,1,1);
433  A.place_at(B,0,1);
434  cout << "A: " << endl << A << endl;
435  exit(0);
436 #endif
437 #ifdef XXX
438  VtMatrix A(4,3);
439  VtMatrix B(2,2);
440  B(0,0) = B(1,1) = 2.;
441  A.place_at(B,0,1);
442  cout << "A: " << A << endl;
443  exit(0);
444 #endif
445 #ifdef XXX
447  C(0,1) = C(1,0) = C(2,1) = C(0,2) = 2.;
448  C(0,0) = C(1,1) = C(2,2) = 3;
449  // cout << " C: " << endl << C << endl;
450  float det = 0.;
451  // Dfact<SMatrix<float,3>,3,3>(C,det);
452  C.det(det);
453  cout << "Dfact(C): " << det << endl;
454  cout << "C after: " << endl << C << endl;
455  exit(0);
456 #endif
457 #ifdef XXX
459  C(0,1) = C(1,0) = C(2,1) = C(0,2) = C(3,1) = C(2,3) = 2.;
460  C(0,0) = C(1,1) = C(2,2) = C(3,3) = 3;
461 // SMatrix<float,4> B(C);
462 // cout << " C: " << endl << C << endl;
463  Dinv<SMatrix<float,4>,4,4>(C);
464  cout << "C after: " << endl << C << endl;
465  SMatrix<float,4> D = B * C;
466  // cout.setf(ios::fixed);
467  cout << "D = B * C: " << endl << D << endl;
468  exit(0);
469 #endif
470 #ifdef XXX
472  C(0,0) = C(1,1) = C(0,1) = 5.;
473  C(1,0) = 1;
474  SMatrix<float,2> B(C);
475  cout << " C: " << endl << C << endl;
476  if(Invert<0>::Dinv(C) ) {
477  cout << "C after: " << endl << C << endl;
478  SMatrix<float,2> D = C * B;
479  cout << " D: " << endl << D << endl;
480  } else { cerr << " inversion failed! " << endl; }
481  exit(0);
482 #endif
483 #ifdef XXX
485  C(0,1) = C(1,1) = C(0,2) = C(2,2) = 5.;
486  C(0,0) = 10;
487  SMatrix<float,3> B(C);
488  cout << " C: " << endl << C << endl;
489  if(Invert<3>::Dinv(C)) {
490  cout << "C after: " << endl << C << endl;
491  SMatrix<float,3> D = B * C;
492  cout << "D: " << endl << D << endl;
493  } else { cerr << " inversion failed! " << endl; }
494  exit(0);
495 #endif
496 #ifdef XXX
498  C(0,1) = C(1,0) = C(2,1) = C(0,2) = 2;
499  C(3,1) = 2;
500  C(2,3) = 2.;
501  C(0,0) = C(1,1) = C(2,2) = C(3,3) = 3;
502  // Invert<4>::Dinv<SMatrix<float,4>, 4>(C);
503  // C.invert();
504  SMatrix<float,4> B(C);
505  cout << " C: " << endl << C << endl;
506  // if(Invert<4>::Dinv(C)) {
507  if(C.invert()) {
508  cout << "C after: " << endl << C << endl;
509  SMatrix<float,4> D = B * C;
510  cout.setf(ios::fixed);
511  cout << "D: " << endl << D << endl;
512  } else { cerr << " inversion failed! " << endl; }
513 
514  cout << "C+B: " << endl << C+B << endl;
515  exit(0);
516 #endif
517  }
518 
519  return 0;
520 }
Expr< BinaryOp< MulOp< T >, SMatrix< T, D, D2 >, SMatrix< T, D, D2 >, T >, T, D, D2 > times(const SMatrix< T, D, D2 > &lhs, const SMatrix< T, D, D2 > &rhs)
Definition: BinaryOperators.hh:533
T mag(const SVector< T, D > &rhs)
Definition: Functions.hh:216
SVector< T, 3 > cross(const SVector< T, 3 > &lhs, const SVector< T, 3 > &rhs)
Definition: Functions.hh:283
T dot(const SVector< T, D > &lhs, const SVector< T, D > &rhs)
Definition: Functions.hh:132
SVector< T, D > unit(const SVector< T, D > &rhs)
Definition: Functions.hh:341
T mag2(const SVector< T, D > &rhs)
Definition: Functions.hh:195
T product(const SMatrix< T, D > &lhs, const SVector< T, D > &rhs)
Definition: MatrixFunctions.hh:451
void d()
Definition: RecDispEX.C:381
Expr< UnaryOp< Fabs< T >, Expr< A, T, D >, T >, T, D > fabs(const Expr< A, T, D > &rhs)
Definition: UnaryOperators.hh:96
void a()
Definition: check_aligned.C:59
Definition: Dinv.hh:46
Definition: SMatrix.hh:53
SMatrix< T, D1, D2 > & place_in_col(const SVector< T, D > &rhs, const unsigned int row, const unsigned int col)
place a vector in a Matrix column
SVector< T, D1 > col(const unsigned int thecol) const
return a Matrix column as a vector
bool invert()
invert square Matrix via Dinv
bool det(T &det)
bool sdet(T &det)
bool sinvert()
invert symmetric, pos. def. Matrix via Dsinv
SMatrix< T, D1, D2 > & place_in_row(const SVector< T, D > &rhs, const unsigned int row, const unsigned int col)
place a vector in a Matrix row
SVector< T, D2 > row(const unsigned int therow) const
return a Matrix row as a vector
SMatrix< T, D1, D2 > & place_at(const SMatrix< T, D3, D4 > &rhs, const unsigned int row, const unsigned int col)
place a matrix in this matrix
Definition: SVector.hh:51
SVector< T, D > & place_at(const SVector< T, D2 > &rhs, const unsigned int row)
place a sub-vector starting at <row>
struct @6 B