ROOT  6.06/09
Reference Guide
testGenVector.cxx
Go to the documentation of this file.
1 
2 #include "Math/Vector3D.h"
3 #include "Math/Point3D.h"
4 
5 #include "Math/Vector2D.h"
6 #include "Math/Point2D.h"
7 
8 #include "Math/EulerAngles.h"
9 
10 #include "Math/Transform3D.h"
11 #include "Math/Translation3D.h"
12 
13 #include "Math/Rotation3D.h"
14 #include "Math/RotationX.h"
15 #include "Math/RotationY.h"
16 #include "Math/RotationZ.h"
17 #include "Math/Quaternion.h"
18 #include "Math/AxisAngle.h"
19 #include "Math/EulerAngles.h"
20 #include "Math/RotationZYX.h"
21 
22 #include "Math/LorentzRotation.h"
23 
24 #include "Math/VectorUtil.h"
25 #ifndef NO_SMATRIX
26 #include "Math/SMatrix.h"
27 #endif
28 
29 #include <vector>
30 
31 using namespace ROOT::Math;
32 using namespace ROOT::Math::VectorUtil;
33 
34 
35 
39 
40 
41 
46 
47 
48 //#define TEST_COMPILE_ERROR
49 
50 
51 int compare( double v1, double v2, const std::string & name = "", double scale = 1.0) {
52  // ntest = ntest + 1;
53 
54  // numerical double limit for epsilon
55  double eps = scale* std::numeric_limits<double>::epsilon();
56  int iret = 0;
57  double delta = v2 - v1;
58  double d = 0;
59  if (delta < 0 ) delta = - delta;
60  if (v1 == 0 || v2 == 0) {
61  if (delta > eps ) {
62  iret = 1;
63  }
64  }
65  // skip case v1 or v2 is infinity
66  else {
67  d = v1;
68 
69  if ( v1 < 0) d = -d;
70  // add also case when delta is small by default
71  if ( delta/d > eps && delta > eps )
72  iret = 1;
73  }
74 
75  if (iret == 0)
76  std::cout << ".";
77  else {
78  int pr = std::cout.precision (18);
79  std::cout << "\nDiscrepancy in " << name << "() : " << v1 << " != " << v2 << " discr = " << int(delta/d/eps)
80  << " (Allowed discrepancy is " << eps << ")\n";
81  std::cout.precision (pr);
82  //nfail = nfail + 1;
83  }
84  return iret;
85 }
86 
87 template<class Transform>
88 bool IsEqual(const Transform & t1, const Transform & t2, unsigned int size) {
89 // size should be an enum of the Transform class
90  std::vector<double> x1(size);
91  std::vector<double> x2(size);
92  t1.GetComponents(x1.begin(), x1.end() );
93  t2.GetComponents(x2.begin(), x2.end() );
94  bool ret = true;
95  unsigned int i = 0;
96  while (ret && i < size) {
97  // from TMath::AreEqualRel(x1,x2,2*eps)
99  ( std::abs(x1[i]) + std::abs(x2[i] ) );
100  ret &= areEqual;
101  i++;
102  }
103  return ret;
104 }
105 
107 
108  int iret = 0;
109 
110  std::cout << "testing Vector3D \t:\t";
111 
112  // test the vector tags
113 
114  GlobalXYZVector vg(1.,2.,3.);
115  GlobalXYZVector vg2(vg);
116 
117  GlobalPolar3DVector vpg(vg);
118 
119  iret |= compare(vpg.R(), vg2.R() );
120 
121 // std::cout << vg2 << std::endl;
122 
123  double r = vg.Dot(vpg);
124  iret |= compare(r, vg.Mag2() );
125 
126  GlobalXYZVector vcross = vg.Cross(vpg);
127  iret |= compare(vcross.R(), 0.0,"cross",10 );
128 
129 // std::cout << vg.Dot(vpg) << std::endl;
130 // std::cout << vg.Cross(vpg) << std::endl;
131 
132 
133 
134 
135 
136  GlobalXYZVector vg3 = vg + vpg;
137  iret |= compare(vg3.R(), 2*vg.R() );
138 
139  GlobalXYZVector vg4 = vg - vpg;
140  iret |= compare(vg4.R(), 0.0,"diff",10 );
141 
142 
143 
144 
145 #ifdef TEST_COMPILE_ERROR
146  LocalXYZVector vl; vl = vg;
147  LocalXYZVector vl2(vg2);
148  LocalXYZVector vl3(vpg);
149  vg.Dot(vl);
150  vg.Cross(vl);
151  vg3 = vg + vl;
152  vg4 = vg - vl;
153 #endif
154 
155 
156  if (iret == 0) std::cout << "\t\t\t\t\tOK\n";
157  else std::cout << "\t\t\t\tFAILED\n";
158 
159 
160  return iret;
161 }
162 
163 
164 
165 int testPoint3D() {
166 
167  int iret = 0;
168 
169  std::cout << "testing Point3D \t:\t";
170 
171  // test the vector tags
172 
173  GlobalXYZPoint pg(1.,2.,3.);
174  GlobalXYZPoint pg2(pg);
175 
176  GlobalPolar3DPoint ppg(pg);
177 
178  iret |= compare(ppg.R(), pg2.R() );
179  //std::cout << pg2 << std::endl;
180 
181 
182 
183 
184  GlobalXYZVector vg(pg);
185 
186  double r = pg.Dot(vg);
187  iret |= compare(r, pg.Mag2() );
188 
189  GlobalPolar3DVector vpg(pg);
190  GlobalXYZPoint pcross = pg.Cross(vpg);
191  iret |= compare(pcross.R(), 0.0,"cross",10 );
192 
193  GlobalPolar3DPoint pg3 = ppg + vg;
194  iret |= compare(pg3.R(), 2*pg.R() );
195 
196  GlobalXYZVector vg4 = pg - ppg;
197  iret |= compare(vg4.R(), 0.0,"diff",10 );
198 
199 
200 #ifdef TEST_COMPILE_ERROR
201  LocalXYZPoint pl; pl = pg;
202  LocalXYZVector pl2(pg2);
203  LocalXYZVector pl3(ppg);
204  pl.Dot(vg);
205  pl.Cross(vg);
206  pg3 = ppg + pg;
207  pg3 = ppg + pl;
208  vg4 = pg - pl;
209 #endif
210 
211  // operator -
212  XYZPoint q1(1.,2.,3.);
213  XYZPoint q2 = -1.* q1;
214  XYZVector v2 = -XYZVector(q1);
215  iret |= compare(XYZVector(q2) == v2,true,"reflection");
216 
217 
218  if (iret == 0) std::cout << "\t\t\t\t\tOK\n";
219  else std::cout << "\t\t\t\tFAILED\n";
220 
221  return iret;
222 }
223 
224 
225 
229 
230 
231 
232 
234 
235  int iret = 0;
236 
237  std::cout << "testing Vector2D \t:\t";
238 
239  // test the vector tags
240 
241  GlobalXYVector vg(1.,2.);
242  GlobalXYVector vg2(vg);
243 
244  GlobalPolar2DVector vpg(vg);
245 
246  iret |= compare(vpg.R(), vg2.R() );
247 
248 // std::cout << vg2 << std::endl;
249 
250  double r = vg.Dot(vpg);
251  iret |= compare(r, vg.Mag2() );
252 
253 // std::cout << vg.Dot(vpg) << std::endl;
254 
255 
256  GlobalXYVector vg3 = vg + vpg;
257  iret |= compare(vg3.R(), 2*vg.R() );
258 
259  GlobalXYVector vg4 = vg - vpg;
260  iret |= compare(vg4.R(), 0.0,"diff",10 );
261 
262 
263  double angle = 1.;
264  vg.Rotate(angle);
265  iret |= compare(vg.Phi(), vpg.Phi() + angle );
266  iret |= compare(vg.R(), vpg.R() );
267 
268  GlobalXYZVector v3d(1,2,0);
269  GlobalXYZVector vr3d = RotationZ(angle) * v3d;
270  iret |= compare(vg.X(), vr3d.X() );
271  iret |= compare(vg.Y(), vr3d.Y() );
272 
273  GlobalXYVector vu = vg3.Unit();
274  iret |= compare(vu.R(), 1. );
275 
276 
277 #ifdef TEST_COMPILE_ERROR
278  LocalXYVector vl; vl = vg;
279  LocalXYVector vl2(vg2);
280  LocalXYVector vl3(vpg);
281  vg.Dot(vl);
282  vg3 = vg + vl;
283  vg4 = vg - vl;
284 #endif
285 
286 
287  if (iret == 0) std::cout << "\t\t\t\tOK\n";
288  else std::cout << "\t\t\tFAILED\n";
289 
290 
291  return iret;
292 }
293 
294 
299 
300 
301 
302 int testPoint2D() {
303 
304  int iret = 0;
305 
306  std::cout << "testing Point2D \t:\t";
307 
308  // test the vector tags
309 
310  GlobalXYPoint pg(1.,2.);
311  GlobalXYPoint pg2(pg);
312 
313  GlobalPolar2DPoint ppg(pg);
314 
315  iret |= compare(ppg.R(), pg2.R() );
316  //std::cout << pg2 << std::endl;
317 
318 
319 
320 
321  GlobalXYVector vg(pg);
322 
323  double r = pg.Dot(vg);
324  iret |= compare(r, pg.Mag2() );
325 
326  GlobalPolar2DVector vpg(pg);
327 
328  GlobalPolar2DPoint pg3 = ppg + vg;
329  iret |= compare(pg3.R(), 2*pg.R() );
330 
331  GlobalXYVector vg4 = pg - ppg;
332  iret |= compare(vg4.R(), 0.0,"diff",10 );
333 
334 
335 #ifdef TEST_COMPILE_ERROR
336  LocalXYPoint pl; pl = pg;
337  LocalXYVector pl2(pg2);
338  LocalXYVector pl3(ppg);
339  pl.Dot(vg);
340  pl.Cross(vg);
341  pg3 = ppg + pg;
342  pg3 = ppg + pl;
343  vg4 = pg - pl;
344 #endif
345 
346  // operator -
347  XYPoint q1(1.,2.);
348  XYPoint q2 = -1.* q1;
349  XYVector v2 = -XYVector(q1);
350  iret |= compare(XYVector(q2) == v2,true,"reflection");
351 
352 
353 
354  double angle = 1.;
355  pg.Rotate(angle);
356  iret |= compare(pg.Phi(), ppg.Phi() + angle );
357  iret |= compare(pg.R(), ppg.R() );
358 
359  GlobalXYZVector v3d(1,2,0);
360  GlobalXYZVector vr3d = RotationZ(angle) * v3d;
361  iret |= compare(pg.X(), vr3d.X() );
362  iret |= compare(pg.Y(), vr3d.Y() );
363 
364 
365 
366  if (iret == 0) std::cout << "\t\t\t\tOK\n";
367  else std::cout << "\t\t\tFAILED\n";
368 
369  return iret;
370 }
371 
372 
373 // missing LV test
374 
376 
377  int iret=0;
378  std::cout << "testing 3D Rotations\t:\t";
379 
380 
381  Rotation3D rot = RotationZ(1.) * RotationY(2) * RotationX(3);
382  GlobalXYZVector vg(1.,2.,3);
383  GlobalXYZPoint pg(1.,2.,3);
384  GlobalPolar3DVector vpg(vg);
385 
386  // GlobalXYZVector vg2 = rot.operator()<Cartesian3D,GlobalCoordinateSystemTag, GlobalCoordinateSystemTag> (vg);
387  GlobalXYZVector vg2 = rot(vg);
388  iret |= compare(vg2.R(), vg.R(),"rot3D" );
389 
390  GlobalXYZPoint pg2 = rot(pg);
391  iret |= compare(pg2.X(), vg2.X(),"x diff");
392  iret |= compare(pg2.Y(), vg2.Y(),"y diff");
393  iret |= compare(pg2.Z(), vg2.Z(),"z diff");
394 
395 
396  Quaternion qrot(rot);
397 
398  pg2 = qrot(pg);
399  iret |= compare(pg2.X(), vg2.X(),"x diff",10);
400  iret |= compare(pg2.Y(), vg2.Y(),"y diff",10);
401  iret |= compare(pg2.Z(), vg2.Z(),"z diff",10);
402 
403  GlobalPolar3DVector vpg2 = qrot * vpg;
404 
405  iret |= compare(vpg2.X(), vg2.X(),"x diff",10 );
406  iret |= compare(vpg2.Y(), vg2.Y(),"y diff",10 );
407  iret |= compare(vpg2.Z(), vg2.Z(),"z diff",10 );
408 
409  AxisAngle arot(rot);
410  pg2 = arot(pg);
411  iret |= compare(pg2.X(), vg2.X(),"x diff",10 );
412  iret |= compare(pg2.Y(), vg2.Y(),"y diff",10 );
413  iret |= compare(pg2.Z(), vg2.Z(),"z diff",10 );
414 
415  vpg2 = arot (vpg);
416  iret |= compare(vpg2.X(), vg2.X(),"x diff",10 );
417  iret |= compare(vpg2.Y(), vg2.Y(),"y diff",10 );
418  iret |= compare(vpg2.Z(), vg2.Z(),"z diff",10 );
419 
420  EulerAngles erot(rot);
421 
422  vpg2 = erot (vpg);
423  iret |= compare(vpg2.X(), vg2.X(),"x diff",10 );
424  iret |= compare(vpg2.Y(), vg2.Y(),"y diff",10 );
425  iret |= compare(vpg2.Z(), vg2.Z(),"z diff",10 );
426 
427  GlobalXYZVector vrx = RotationX(3) * vg;
428  GlobalXYZVector vry = RotationY(2) * vrx;
429  vpg2 = RotationZ(1) * GlobalPolar3DVector (vry);
430  iret |= compare(vpg2.X(), vg2.X(),"x diff",10 );
431  iret |= compare(vpg2.Y(), vg2.Y(),"y diff",10 );
432  iret |= compare(vpg2.Z(), vg2.Z(),"z diff",10 );
433 
434  // test Get/SetComponents
435  XYZVector v1,v2,v3;
436  rot.GetComponents(v1,v2,v3);
437  const Rotation3D rot2(v1,v2,v3);
438  //rot2.SetComponents(v1,v2,v3);
439  double r1[9],r2[9];
440  rot.GetComponents(r1,r1+9);
441  rot2.GetComponents(r2,r2+9);
442  for (int i = 0; i < 9; ++i) {
443  iret |= compare(r1[i],r2[i],"Get/SetComponents");
444  }
445  // operator == fails for numerical precision
446  //iret |= compare( (rot2==rot),true,"Get/SetComponens");
447 
448  // test get/set with a matrix
449 #ifndef NO_SMATRIX
450  SMatrix<double,3> mat;
451  rot2.GetRotationMatrix(mat);
452  rot.SetRotationMatrix(mat);
453  iret |= compare( (rot2==rot),true,"Get/SetRotMatrix");
454 #endif
455 
456  //test inversion
457  Rotation3D rotInv = rot.Inverse();
458  rot.Invert(); // invert in place
459  bool comp = (rotInv == rot );
460  iret |= compare(comp,true,"inversion");
461 
462  // rotation and scaling of points
463  XYZPoint q1(1.,2,3); double a = 3;
464  XYZPoint qr1 = rot( a * q1);
465  XYZPoint qr2 = a * rot( q1);
466  iret |= compare(qr1.X(), qr2.X(),"x diff",10 );
467  iret |= compare(qr1.Y(), qr2.Y(),"y diff",10 );
468  iret |= compare(qr1.Z(), qr2.Z(),"z diff",10 );
469 
470 
471  if (iret == 0) std::cout << "\tOK\n";
472  else std::cout << "\t FAILED\n";
473 
474  return iret;
475 }
476 
477 
479 
480 
481  std::cout << "testing 3D Transform\t:\t";
482  int iret = 0;
483 
484  EulerAngles r(1.,2.,3.);
485 
486  GlobalPolar3DVector v(1.,2.,3.);
487  GlobalXYZVector w(v);
488 
489  Transform3D t1( v );
490  GlobalXYZPoint pg;
491  t1.Transform( LocalXYZPoint(), pg );
492  iret |= compare(pg.X(), v.X(),"x diff",10 );
493  iret |= compare(pg.Y(), v.Y(),"y diff",10 );
494  iret |= compare(pg.Z(), v.Z(),"z diff",10 );
495 
496 
497  Transform3D t2( r, v );
498 
499  GlobalPolar3DVector vr = r.Inverse()*v;
500 
501 // std::cout << GlobalXYZVector(v) << std::endl;
502 // std::cout << GlobalXYZVector(vr) << std::endl;
503 // std::cout << GlobalXYZVector (r(v)) << std::endl;
504 // std::cout << GlobalXYZVector (r(vr)) << std::endl;
505 // std::cout << vr << std::endl;
506 // std::cout << r(vr) << std::endl;
507 
508 
509 
510 // std::cout << r << std::endl;
511 // std::cout << r.Inverse() << std::endl;
512 // std::cout << r * r.Inverse() << std::endl;
513 // std::cout << Rotation3D(r) * Rotation3D(r.Inverse()) << std::endl;
514 // std::cout << Rotation3D(r) * Rotation3D(r).Inverse() << std::endl;
515 
516 
517  // test Translation3D
518 
519  Translation3D tr1(v);
520  Translation3D tr2(v.X(),v.Y(),v.Z());
521 // skip this test on 32 bits architecture. It might fail due to extended precision
522 #if !defined(__i386__)
523  iret |= compare(tr1 ==tr2, 1,"eq transl",1 );
524 #else
525  // add a dummy test to have the same outputfile for roottest
526  // otherwise it will complain that the output is different !
527  iret |= compare(0, 0,"dummy test",1 );
528 #endif
529 
530  Translation3D tr3 = tr1 * tr1.Inverse();
531  GlobalPolar3DVector vp2 = tr3 * v;
532  iret |= compare(vp2.X(), v.X(),"x diff",10 );
533  iret |= compare(vp2.Y(), v.Y(),"y diff",10 );
534  iret |= compare(vp2.Z(), v.Z(),"z diff",10 );
535 
536 
537  Transform3D t2b = tr1 * Rotation3D(r);
538  // this above fails on Windows - use a comparison with tolerance
539  // 12 is size of Transform3D internal vector
540  iret |= compare( IsEqual(t2,t2b,12), true,"eq1 transf",1 );
541  //iret |= compare(t2 ==t2b, 1,"eq1 transf",1 );
542  Transform3D t2c( r, tr1);
543  iret |= compare( IsEqual(t2,t2c,12), true,"eq2 transf",1 );
544  //iret |= compare(t2 ==t2c, 1,"eq2 transf",1 );
545 
546 
547  Transform3D t3 = Rotation3D(r) * Translation3D(vr);
548 
549  Rotation3D rrr;
550  XYZVector vvv;
551  t2b.GetDecomposition(rrr,vvv);
552  iret |= compare(Rotation3D(r) ==rrr, 1,"eq transf rot",1 );
553  iret |= compare( tr1.Vect() == vvv, 1,"eq transf vec",1 );
554 // if (iret) std::cout << vvv << std::endl;
555 // if (iret) std::cout << Translation3D(vr) << std::endl;
556 
557  Translation3D ttt;
558  t2b.GetDecomposition(rrr,ttt);
559  iret |= compare( tr1 == ttt, 1,"eq transf trans",1 );
560 // if (iret) std::cout << ttt << std::endl;
561 
562  EulerAngles err2;
563  GlobalPolar3DVector vvv2;
564  t2b.GetDecomposition(err2,vvv2);
565  iret |= compare( r.Phi(), err2.Phi(),"transf rot phi",4 );
566  iret |= compare( r.Theta(), err2.Theta(),"transf rot theta",1 );
567  iret |= compare( r.Psi(), err2.Psi(),"transf rot psi",1 );
568 
569  iret |= compare( v == vvv2, 1,"eq transf g vec",1 );
570 
571  // create from other rotations
572  RotationZYX rzyx(r);
573  Transform3D t4( rzyx);
574  iret |= compare( t4.Rotation() == Rotation3D(rzyx), 1,"eq trans rzyx",1 );
575 
576  Transform3D trf2 = tr1 * r;
577  iret |= compare( trf2 == t2b, 1,"trasl * e rot",1 );
578  Transform3D trf3 = r * Translation3D(vr);
579  //iret |= compare( trf3 == t3, 1,"e rot * transl",1 );
580  // this above fails on i686-slc5-gcc43-opt - use a comparison with tolerance
581  iret |= compare( IsEqual(trf3,t3,12), true,"e rot * transl",1 );
582 
583  Transform3D t5(rzyx, v);
584  Transform3D trf5 = Translation3D(v) * rzyx;
585  //iret |= compare( trf5 == t5, 1,"trasl * rzyx",1 );
586  iret |= compare( IsEqual(trf5,t5,12), true,"trasl * rzyx",1 );
587 
588  Transform3D t6(rzyx, rzyx * Translation3D(v).Vect() );
589  Transform3D trf6 = rzyx * Translation3D(v);
590  iret |= compare( trf6 == t6, 1,"rzyx * transl",1 );
591  if (iret) std::cout << t6 << "\n---\n" << trf6 << std::endl;
592 
593 
594 
595  Transform3D trf7 = t4 * Translation3D(v);
596  //iret |= compare( trf7 == trf6, 1,"tranf * transl",1 );
597  iret |= compare( IsEqual(trf7,trf6,12), true,"tranf * transl",1 );
598  Transform3D trf8 = Translation3D(v) * t4;
599  iret |= compare( trf8 == trf5, 1,"trans * transf",1 );
600 
601  Transform3D trf9 = Transform3D(v) * rzyx;
602  iret |= compare( trf9 == trf5, 1,"tranf * rzyx",1 );
603  Transform3D trf10 = rzyx * Transform3D(v);
604  iret |= compare( trf10 == trf6, 1,"rzyx * transf",1 );
605  Transform3D trf11 = Rotation3D(rzyx) * Transform3D(v);
606  iret |= compare( trf11 == trf10, 1,"r3d * transf",1 );
607 
608  RotationZYX rrr2 = trf10.Rotation<RotationZYX>();
609  //iret |= compare( rzyx == rrr2, 1,"gen Rotation()",1 );
610  iret |= compare( rzyx.Phi() , rrr2.Phi(),"gen Rotation() Phi",1 );
611  iret |= compare( rzyx.Theta(), rrr2.Theta(),"gen Rotation() Theta",10 );
612  iret |= compare( rzyx.Psi(), rrr2.Psi(),"gen Rotation() Psi",1 );
613  if (iret) std::cout << rzyx << "\n---\n" << rrr2 << std::endl;
614 
615 
616  //std::cout << t2 << std::endl;
617  //std::cout << t3 << std::endl;
618 
619  XYZPoint p1(-1.,2.,-3);
620 
621  XYZPoint p2 = t2 (p1);
622  Polar3DPoint p3 = t3 ( Polar3DPoint(p1) );
623  iret |= compare(p3.X(), p2.X(),"x diff",10 );
624  iret |= compare(p3.Y(), p2.Y(),"y diff",10 );
625  iret |= compare(p3.Z(), p2.Z(),"z diff",10 );
626 
627  GlobalXYZVector v1(1.,2.,3.);
628  LocalXYZVector v2; t2.Transform (v1, v2);
629  GlobalPolar3DVector v3; t3.Transform ( GlobalPolar3DVector(v1), v3 );
630 
631  iret |= compare(v3.X(), v2.X(),"x diff",10 );
632  iret |= compare(v3.Y(), v2.Y(),"y diff",10 );
633  iret |= compare(v3.Z(), v2.Z(),"z diff",10 );
634 
635  XYZPoint q1(1,2,3);
636  XYZPoint q2(-1,-2,-3);
637  XYZPoint q3 = q1 + XYZVector(q2);
638  //std::cout << q3 << std::endl;
639  XYZPoint qt3 = t3(q3);
640  //std::cout << qt3 << std::endl;
641  XYZPoint qt1 = t3(q1);
642  XYZVector vt2 = t3( XYZVector(q2) );
643  XYZPoint qt4 = qt1 + vt2;
644  iret |= compare(qt3.X(), qt4.X(),"x diff",10 );
645  iret |= compare(qt3.Y(), qt4.Y(),"y diff",10 );
646  iret |= compare(qt3.Z(), qt4.Z(),"z diff",10 );
647  //std::cout << qt4 << std::endl;
648 
649  // this fails
650 // double a = 3;
651  //XYZPoint q4 = a*q1;
652 // std::cout << t3( a * q1) << std::endl;
653 // std::cout << a * t3(q1) << std::endl;
654 
655  // test get/set with a matrix
656 #ifndef NO_SMATRIX
658  t3.GetTransformMatrix(mat);
659  Transform3D t3b; t3b.SetTransformMatrix(mat);
660  iret |= compare( (t3==t3b),true,"Get/SetTransformMatrix");
661 
662  // test LR
663  Boost b(0.2,0.4,0.8);
664  LorentzRotation lr(b);
665  SMatrix<double,4> mat4;
666  lr.GetRotationMatrix(mat4);
667  LorentzRotation lr2; lr2.SetRotationMatrix(mat4);
668  iret |= compare( (lr==lr2),true,"Get/SetLRotMatrix");
669 #endif
670 
671 
672  if (iret == 0) std::cout << "OK\n";
673  else std::cout << "\t\t\tFAILED\n";
674 
675  return iret;
676 }
677 
678 
680 
681  std::cout << "testing VectorUtil \t:\t";
682  int iret = 0;
683 
684  // test new perp functions
685  XYZVector v(1.,2.,3.);
686 
687  XYZVector vx = ProjVector(v,XYZVector(3,0,0) );
688  iret |= compare(vx.X(), v.X(),"x",1 );
689  iret |= compare(vx.Y(), 0,"y",1 );
690  iret |= compare(vx.Z(), 0,"z",1 );
691 
692  XYZVector vpx = PerpVector(v,XYZVector(2,0,0) );
693  iret |= compare(vpx.X(), 0,"x",1 );
694  iret |= compare(vpx.Y(), v.Y(),"y",1 );
695  iret |= compare(vpx.Z(), v.Z(), "z",1 );
696 
697  double perpy = Perp(v, XYZVector(0,2,0) );
698  iret |= compare(perpy, std::sqrt( v.Mag2() - v.y()*v.y()),"perpy" );
699 
700  XYZPoint u(1,1,1);
701  XYZPoint un = u/u.R();
702 
703 
704  XYZVector vl = ProjVector(v,u);
705  XYZVector vl2 = XYZVector(un) * ( v.Dot(un ) );
706 
707  iret |= compare(vl.X(), vl2.X(),"x",1 );
708  iret |= compare(vl.Y(), vl2.Y(),"y",1 );
709  iret |= compare(vl.Z(), vl2.Z(),"z",1 );
710 
711  XYZVector vp = PerpVector(v,u);
712  XYZVector vp2 = v - XYZVector ( un * ( v.Dot(un ) ) );
713  iret |= compare(vp.X(), vp2.X(),"x",10 );
714  iret |= compare(vp.Y(), vp2.Y(),"y",10 );
715  iret |= compare(vp.Z(), vp2.Z(),"z",10 );
716 
717  double perp = Perp(v,u);
718  iret |= compare(perp, vp.R(),"perp",1 );
719  double perp2 = Perp2(v,u);
720  iret |= compare(perp2, vp.Mag2(),"perp2",1 );
721 
722  // test rotations
723  double angle = 1;
724  XYZVector vr1 = RotateX(v,angle);
725  XYZVector vr2 = RotationX(angle) * v;
726  iret |= compare(vr1.Y(), vr2.Y(),"y",1 );
727  iret |= compare(vr1.Z(), vr2.Z(),"z",1 );
728 
729  vr1 = RotateY(v,angle);
730  vr2 = RotationY(angle) * v;
731  iret |= compare(vr1.X(), vr2.X(),"x",1 );
732  iret |= compare(vr1.Z(), vr2.Z(),"z",1 );
733 
734  vr1 = RotateZ(v,angle);
735  vr2 = RotationZ(angle) * v;
736  iret |= compare(vr1.X(), vr2.X(),"x",1 );
737  iret |= compare(vr1.Y(), vr2.Y(),"y",1 );
738 
739 
740  if (iret == 0) std::cout << "\t\t\tOK\n";
741  else std::cout << "\t\t\t\t\t\tFAILED\n";
742  return iret;
743 
744 }
745 
747 
748  int iret = 0;
749  iret |= testVector3D();
750  iret |= testPoint3D();
751 
752  iret |= testVector2D();
753  iret |= testPoint2D();
754 
755  iret |= testRotations3D();
756 
757  iret |= testTransform3D();
758 
759  iret |= testVectorUtil();
760 
761 
762  if (iret !=0) std::cout << "\nTest GenVector FAILED!!!!!!!!!\n";
763  return iret;
764 
765 }
766 
767 int main() {
768  int ret = testGenVector();
769  if (ret) std::cerr << "test FAILED !!! " << std::endl;
770  else std::cout << "test OK " << std::endl;
771  return ret;
772 }
DisplacementVector3D< Cartesian3D< double >, LocalCoordinateSystemTag > LocalXYZVector
int testVector3D()
Scalar Psi() const
Return Psi angle (X'' rotation angle)
Definition: RotationZYX.h:215
Scalar Phi() const
Return Phi Euler angle.
Definition: EulerAngles.h:212
const Double_t * v1
Definition: TArcBall.cxx:33
static double p3(double t, double a, double b, double c, double d)
PositionVector3D< Polar3D< double >, DefaultCoordinateSystemTag > Polar3DPoint
3D Point based on the polar coordinates rho, theta, phi in double precision.
Definition: Point3Dfwd.h:59
Scalar Mag2() const
Magnitute squared ( r^2 in spherical coordinate)
Translation3D Inverse() const
Return the inverse of the transformation.
Rotation class representing a 3D rotation about the Z axis by the angle of rotation.
Definition: RotationZ.h:43
PositionVector3D< Polar3D< double >, GlobalCoordinateSystemTag > GlobalPolar3DPoint
Scalar Y() const
Cartesian Y, converting if necessary from internal coordinate system.
void SetRotationMatrix(const ForeignMatrix &m)
Set components from a linear algebra matrix of size at least 3x3, which must support operator()(i...
Definition: Rotation3D.h:307
Vector1 ProjVector(const Vector1 &v, const Vector2 &u)
Find the projection of v along the given direction u.
Definition: VectorUtil.h:153
Scalar R() const
Polar R, converting if necessary from internal coordinate system.
Scalar Phi() const
Polar phi, converting if necessary from internal coordinate system.
int compare(double v1, double v2, const std::string &name="", double scale=1.0)
void SetTransformMatrix(const ForeignMatrix &m)
Set components from a linear algebra matrix of size at least 3x4, which must support operator()(i...
Definition: Transform3D.h:358
Class describing a generic position vector (point) in 3 dimensions.
int testPoint3D()
Rotation class with the (3D) rotation represented by angles describing first a rotation of an angle p...
Definition: RotationZYX.h:71
TArc * a
Definition: textangle.C:12
DisplacementVector2D< Cartesian2D< double >, DefaultCoordinateSystemTag > XYVector
2D Vector based on the cartesian coordinates x,y in double precision
Definition: Vector2Dfwd.h:31
DisplacementVector2D< Cartesian2D< double >, LocalCoordinateSystemTag > LocalXYVector
Vector RotateX(const Vector &v, double alpha)
rotation along X axis for a generic vector by an Angle alpha returning a new vector.
Definition: VectorUtil.h:255
int testGenVector()
DisplacementVector2D Unit() const
return unit vector parallel to this
PositionVector3D< Cartesian3D< double >, GlobalCoordinateSystemTag > GlobalXYZPoint
Scalar Phi() const
Return Phi angle (Z rotation angle)
Definition: RotationZYX.h:195
Rotation class with the (3D) rotation represented by a unit quaternion (u, i, j, k).
Definition: Quaternion.h:47
TLatex * t1
Definition: textangle.C:20
Scalar Z() const
Cartesian Z, converting if necessary from internal coordinate system.
Scalar Dot(const DisplacementVector3D< OtherCoords, Tag > &v) const
Return the scalar (dot) product of two displacement vectors.
Scalar Y() const
Cartesian Y, converting if necessary from internal coordinate system.
AxisAngle class describing rotation represented with direction axis (3D Vector) and an angle of rotat...
Definition: AxisAngle.h:41
Rotation3D rrr(TestRotation const &t)
double sqrt(double)
static const double x2[5]
Rotation3D Inverse() const
Return inverse of a rotation.
Definition: Rotation3D.h:420
SMatrix: a generic fixed size D1 x D2 Matrix class.
Rotation class representing a 3D rotation about the Y axis by the angle of rotation.
Definition: RotationY.h:43
Scalar Mag2() const
Magnitute squared ( r^2 in spherical coordinate)
Scalar X() const
Cartesian X, converting if necessary from internal coordinate system.
double Perp2(const Vector1 &v, const Vector2 &u)
Find the magnitude square of the vector component of v perpendicular to the given direction of u...
Definition: VectorUtil.h:182
Lorentz boost class with the (4D) transformation represented internally by a 4x4 orthosymplectic matr...
Definition: Boost.h:46
Scalar Dot(const DisplacementVector2D< OtherCoords, Tag > &v) const
Return the scalar (Dot) product of this with a displacement vector in any coordinate system...
static double p2(double t, double a, double b, double c)
static Vc_ALWAYS_INLINE Vector< T > abs(const Vector< T > &x)
Definition: vector.h:450
Scalar Y() const
Cartesian Y, converting if necessary from internal coordinate system.
Vector RotateZ(const Vector &v, double alpha)
rotation along Z axis for a generic vector by an Angle alpha returning a new vector.
Definition: VectorUtil.h:289
int testPoint2D()
Scalar Mag2() const
Magnitute squared ( r^2 in spherical coordinate)
void Rotate(Scalar angle)
Rotate by an angle.
Scalar R() const
Polar R, converting if necessary from internal coordinate system.
PositionVector2D< Cartesian2D< double >, GlobalCoordinateSystemTag > GlobalXYPoint
Lorentz transformation class with the (4D) transformation represented by a 4x4 orthosymplectic matrix...
Scalar Dot(const DisplacementVector2D< OtherCoords, Tag > &v) const
Return the scalar (dot) product of two displacement vectors.
int testVector2D()
PositionVector2D< Cartesian2D< double >, LocalCoordinateSystemTag > LocalXYPoint
Class describing a generic displacement vector in 3 dimensions.
Global Helper functions for generic Vector classes.
Definition: VectorUtil.h:47
ROOT::R::TRInterface & r
Definition: Object.C:4
SVector< double, 2 > v
Definition: Dict.h:5
EulerAngles Inverse() const
Return inverse of a rotation.
Definition: EulerAngles.h:306
unsigned int r1[N_CITIES]
Definition: simanTSP.cxx:321
Rotation class representing a 3D rotation about the X axis by the angle of rotation.
Definition: RotationX.h:43
void GetRotationMatrix(ForeignMatrix &m) const
Get components into a linear algebra matrix of size at least 4x4, which must support operator()(i...
Rotation class with the (3D) rotation represented by a 3x3 orthogonal matrix.
Definition: Rotation3D.h:65
Scalar R() const
Polar R, converting if necessary from internal coordinate system.
Basic 3D Transformation class describing a rotation and then a translation The internal data are a 3D...
Definition: Transform3D.h:85
Vector RotateY(const Vector &v, double alpha)
rotation along Y axis for a generic vector by an Angle alpha returning a new vector.
Definition: VectorUtil.h:272
Scalar R() const
Polar R, converting if necessary from internal coordinate system.
void GetComponents(ForeignVector &v1, ForeignVector &v2, ForeignVector &v3) const
Get components into three vectors which will be the (orthonormal) columns of the rotation matrix...
Definition: Rotation3D.h:249
static double p1(double t, double a, double b)
DisplacementVector3D< Cartesian3D< double >, GlobalCoordinateSystemTag > GlobalXYZVector
Class describing a generic position vector (point) in 2 dimensions.
REAL epsilon
Definition: triangle.c:617
void GetRotationMatrix(ForeignMatrix &m) const
Get components into a linear algebra matrix of size at least 3x3, which must support operator()(i...
Definition: Rotation3D.h:320
Scalar Theta() const
Return Theta Euler angle.
Definition: EulerAngles.h:222
PositionVector3D Cross(const DisplacementVector3D< OtherCoords, Tag > &v) const
Return vector (Cross) product of this point with a displacement, as a point vector in this coordinate...
Class describing a 3 dimensional translation.
Definition: Translation3D.h:57
static const double x1[5]
void GetTransformMatrix(ForeignMatrix &m) const
Get components into a linear algebra matrix of size at least 3x4, which must support operator()(i...
Definition: Transform3D.h:371
int testRotations3D()
int testTransform3D()
Scalar Z() const
Cartesian Z, converting if necessary from internal coordinate system.
bool areEqual(const RULE *r1, const RULE *r2, bool moduloNameOrPattern=false)
EulerAngles class describing rotation as three angles (Euler Angles).
Definition: EulerAngles.h:43
int main()
Scalar Mag2() const
Magnitute squared ( r^2 in spherical coordinate)
bool IsEqual(const Transform &t1, const Transform &t2, unsigned int size)
void SetRotationMatrix(const ForeignMatrix &m)
Set components from a linear algebra matrix of size at least 4x4, which must support operator()(i...
PositionVector3D< Polar3D< double >, LocalCoordinateSystemTag > LocalPolar3DPoint
const Vector & Vect() const
return a const reference to the underline vector representing the translation
Scalar Dot(const DisplacementVector3D< OtherCoords, Tag > &v) const
Return the scalar (Dot) product of this with a displacement vector in any coordinate system...
DisplacementVector3D< Cartesian3D< double >, DefaultCoordinateSystemTag > XYZVector
3D Vector based on the cartesian coordinates x,y,z in double precision
Definition: Vector3Dfwd.h:34
#define name(a, b)
Definition: linkTestLib0.cpp:5
DisplacementVector3D Cross(const DisplacementVector3D< OtherCoords, Tag > &v) const
Return vector (cross) product of two displacement vectors, as a vector in the coordinate system of th...
PositionVector3D< Cartesian3D< double >, LocalCoordinateSystemTag > LocalXYZPoint
void Transform(const PositionVector3D< CoordSystem, Tag1 > &p1, PositionVector3D< CoordSystem, Tag2 > &p2) const
Transformation operation for points between different coordinate system tags.
Definition: Transform3D.h:513
PositionVector2D< Polar2D< double >, LocalCoordinateSystemTag > LocalPolar2DPoint
DisplacementVector3D< Polar3D< double >, GlobalCoordinateSystemTag > GlobalPolar3DVector
Vector1 PerpVector(const Vector1 &v, const Vector2 &u)
Find the vector component of v perpendicular to the given direction of u.
Definition: VectorUtil.h:169
int testVectorUtil()
Scalar X() const
Cartesian X, converting if necessary from internal coordinate system.
void Invert()
Invert a rotation in place.
Definition: Rotation3D.cxx:109
Scalar X() const
Cartesian X, converting if necessary from internal coordinate system.
DisplacementVector2D< Cartesian2D< double >, GlobalCoordinateSystemTag > GlobalXYVector
Tag for identifying vectors based on a local coordinate system.
double Perp(const Vector1 &v, const Vector2 &u)
Find the magnitude of the vector component of v perpendicular to the given direction of u...
Definition: VectorUtil.h:198
Scalar Theta() const
Return Theta angle (Y' rotation angle)
Definition: RotationZYX.h:205
Tag for identifying vectors based on a global coordinate system.
PositionVector2D< Polar2D< double >, GlobalCoordinateSystemTag > GlobalPolar2DPoint
DisplacementVector2D< Polar2D< double >, GlobalCoordinateSystemTag > GlobalPolar2DVector
unsigned int r2[N_CITIES]
Definition: simanTSP.cxx:322
Class describing a generic displacement vector in 2 dimensions.
Rotation3D Rotation() const
Get the 3D rotation representing the 3D transformation.
Definition: Transform3D.h:425
Scalar Psi() const
Return Psi Euler angle.
Definition: EulerAngles.h:232