Logo ROOT   6.10/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)
98  bool areEqual = std::abs(x1[i]-x2[i]) < std::numeric_limits<double>::epsilon() *
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  iret |= compare( v.X(), vvv2.X(),"eq transf g vec",4 );
571  iret |= compare( v.Y(), vvv2.Y(),"eq transf g vec",1 );
572  iret |= compare( v.Z(), vvv2.Z(),"eq transf g vec",1 );
573 
574  // create from other rotations
575  RotationZYX rzyx(r);
576  Transform3D t4( rzyx);
577  iret |= compare( t4.Rotation() == Rotation3D(rzyx), 1,"eq trans rzyx",1 );
578 
579  Transform3D trf2 = tr1 * r;
580  iret |= compare( trf2 == t2b, 1,"trasl * e rot",1 );
581  Transform3D trf3 = r * Translation3D(vr);
582  //iret |= compare( trf3 == t3, 1,"e rot * transl",1 );
583  // this above fails on i686-slc5-gcc43-opt - use a comparison with tolerance
584  iret |= compare( IsEqual(trf3,t3,12), true,"e rot * transl",1 );
585 
586  Transform3D t5(rzyx, v);
587  Transform3D trf5 = Translation3D(v) * rzyx;
588  //iret |= compare( trf5 == t5, 1,"trasl * rzyx",1 );
589  iret |= compare( IsEqual(trf5,t5,12), true,"trasl * rzyx",1 );
590 
591  Transform3D t6(rzyx, rzyx * Translation3D(v).Vect() );
592  Transform3D trf6 = rzyx * Translation3D(v);
593  iret |= compare( trf6 == t6, 1,"rzyx * transl",1 );
594  if (iret) std::cout << t6 << "\n---\n" << trf6 << std::endl;
595 
596 
597 
598  Transform3D trf7 = t4 * Translation3D(v);
599  //iret |= compare( trf7 == trf6, 1,"tranf * transl",1 );
600  iret |= compare( IsEqual(trf7,trf6,12), true,"tranf * transl",1 );
601  Transform3D trf8 = Translation3D(v) * t4;
602  iret |= compare( trf8 == trf5, 1,"trans * transf",1 );
603 
604  Transform3D trf9 = Transform3D(v) * rzyx;
605  iret |= compare( trf9 == trf5, 1,"tranf * rzyx",1 );
606  Transform3D trf10 = rzyx * Transform3D(v);
607  iret |= compare( trf10 == trf6, 1,"rzyx * transf",1 );
608  Transform3D trf11 = Rotation3D(rzyx) * Transform3D(v);
609  iret |= compare( trf11 == trf10, 1,"r3d * transf",1 );
610 
611  RotationZYX rrr2 = trf10.Rotation<RotationZYX>();
612  //iret |= compare( rzyx == rrr2, 1,"gen Rotation()",1 );
613  iret |= compare( rzyx.Phi() , rrr2.Phi(),"gen Rotation() Phi",1 );
614  iret |= compare( rzyx.Theta(), rrr2.Theta(),"gen Rotation() Theta",10 );
615  iret |= compare( rzyx.Psi(), rrr2.Psi(),"gen Rotation() Psi",1 );
616  if (iret) std::cout << rzyx << "\n---\n" << rrr2 << std::endl;
617 
618 
619  //std::cout << t2 << std::endl;
620  //std::cout << t3 << std::endl;
621 
622  XYZPoint p1(-1.,2.,-3);
623 
624  XYZPoint p2 = t2 (p1);
625  Polar3DPoint p3 = t3 ( Polar3DPoint(p1) );
626  iret |= compare(p3.X(), p2.X(),"x diff",10 );
627  iret |= compare(p3.Y(), p2.Y(),"y diff",10 );
628  iret |= compare(p3.Z(), p2.Z(),"z diff",10 );
629 
630  GlobalXYZVector v1(1.,2.,3.);
631  LocalXYZVector v2; t2.Transform (v1, v2);
632  GlobalPolar3DVector v3; t3.Transform ( GlobalPolar3DVector(v1), v3 );
633 
634  iret |= compare(v3.X(), v2.X(),"x diff",10 );
635  iret |= compare(v3.Y(), v2.Y(),"y diff",10 );
636  iret |= compare(v3.Z(), v2.Z(),"z diff",10 );
637 
638  XYZPoint q1(1,2,3);
639  XYZPoint q2(-1,-2,-3);
640  XYZPoint q3 = q1 + XYZVector(q2);
641  //std::cout << q3 << std::endl;
642  XYZPoint qt3 = t3(q3);
643  //std::cout << qt3 << std::endl;
644  XYZPoint qt1 = t3(q1);
645  XYZVector vt2 = t3( XYZVector(q2) );
646  XYZPoint qt4 = qt1 + vt2;
647  iret |= compare(qt3.X(), qt4.X(),"x diff",10 );
648  iret |= compare(qt3.Y(), qt4.Y(),"y diff",10 );
649  iret |= compare(qt3.Z(), qt4.Z(),"z diff",10 );
650  //std::cout << qt4 << std::endl;
651 
652  // this fails
653 // double a = 3;
654  //XYZPoint q4 = a*q1;
655 // std::cout << t3( a * q1) << std::endl;
656 // std::cout << a * t3(q1) << std::endl;
657 
658  // test get/set with a matrix
659 #ifndef NO_SMATRIX
661  t3.GetTransformMatrix(mat);
662  Transform3D t3b; t3b.SetTransformMatrix(mat);
663  iret |= compare( (t3==t3b),true,"Get/SetTransformMatrix");
664 
665  // test LR
666  Boost b(0.2,0.4,0.8);
667  LorentzRotation lr(b);
668  SMatrix<double,4> mat4;
669  lr.GetRotationMatrix(mat4);
670  LorentzRotation lr2; lr2.SetRotationMatrix(mat4);
671  iret |= compare( (lr==lr2),true,"Get/SetLRotMatrix");
672 #endif
673 
674  {
675  // testing ApplyInverse on Point
676  XYZPoint point(1., -2., 3.);
677  Transform3D tr(EulerAngles(10, -10, 10), XYZVector(10, -10, 0));
678 
679  // test that applying transformation + Inverse is identity
680  auto r0 = tr.ApplyInverse(tr(point));
681  auto r0_2 = tr.Inverse()(tr(point));
682 
683  iret |= compare(r0.X(), point.X(), "ApplyInverse/PointX", 100);
684  iret |= compare(r0_2.X(), point.X(), "ApplyInverse/PointX", 100);
685  iret |= compare(r0.Y(), point.Y(), "ApplyInverse/PointY", 10);
686  iret |= compare(r0_2.Y(), point.Y(), "ApplyInverse/PointY", 10);
687  iret |= compare(r0.Z(), point.Z(), "ApplyInverse/PointZ", 10);
688  iret |= compare(r0_2.Z(), point.Z(), "ApplyInverse/PointZ", 10);
689 
690  // compare ApplyInverse with Inverse()
691  auto r1 = tr.ApplyInverse(point);
692  auto r2 = tr.Inverse()(point);
693  iret |= compare(r1.X(), r2.X(), "ApplyInverse/Point", 10);
694  iret |= compare(r1.Y(), r2.Y(), "ApplyInverse/Point", 10);
695  iret |= compare(r1.Z(), r2.Z(), "ApplyInverse/Point", 10);
696  }
697 
698  {
699  // testing ApplyInverse on Vector
700  XYZVector vector(1, -2., 3);
701  Transform3D tr(EulerAngles(10, -10, 10), XYZVector(10, -10, 0));
702  auto r1 = tr.ApplyInverse(vector);
703  auto r2 = tr.Inverse()(vector);
704  iret |= compare(r1.X(), r2.X(), "ApplyInverse/Vector", 10);
705  iret |= compare(r1.Y(), r2.Y(), "ApplyInverse/Vector", 10);
706  iret |= compare(r1.Z(), r2.Z(), "ApplyInverse/Vector", 10);
707  }
708 
709  if (iret == 0) std::cout << "OK\n";
710  else std::cout << "\t\t\tFAILED\n";
711 
712  return iret;
713 }
714 
715 
717 
718  std::cout << "testing VectorUtil \t:\t";
719  int iret = 0;
720 
721  // test new perp functions
722  XYZVector v(1.,2.,3.);
723 
724  XYZVector vx = ProjVector(v,XYZVector(3,0,0) );
725  iret |= compare(vx.X(), v.X(),"x",1 );
726  iret |= compare(vx.Y(), 0,"y",1 );
727  iret |= compare(vx.Z(), 0,"z",1 );
728 
729  XYZVector vpx = PerpVector(v,XYZVector(2,0,0) );
730  iret |= compare(vpx.X(), 0,"x",1 );
731  iret |= compare(vpx.Y(), v.Y(),"y",1 );
732  iret |= compare(vpx.Z(), v.Z(), "z",1 );
733 
734  double perpy = Perp(v, XYZVector(0,2,0) );
735  iret |= compare(perpy, std::sqrt( v.Mag2() - v.y()*v.y()),"perpy" );
736 
737  XYZPoint u(1,1,1);
738  XYZPoint un = u/u.R();
739 
740 
741  XYZVector vl = ProjVector(v,u);
742  XYZVector vl2 = XYZVector(un) * ( v.Dot(un ) );
743 
744  iret |= compare(vl.X(), vl2.X(),"x",1 );
745  iret |= compare(vl.Y(), vl2.Y(),"y",1 );
746  iret |= compare(vl.Z(), vl2.Z(),"z",1 );
747 
748  XYZVector vp = PerpVector(v,u);
749  XYZVector vp2 = v - XYZVector ( un * ( v.Dot(un ) ) );
750  iret |= compare(vp.X(), vp2.X(),"x",10 );
751  iret |= compare(vp.Y(), vp2.Y(),"y",10 );
752  iret |= compare(vp.Z(), vp2.Z(),"z",10 );
753 
754  double perp = Perp(v,u);
755  iret |= compare(perp, vp.R(),"perp",1 );
756  double perp2 = Perp2(v,u);
757  iret |= compare(perp2, vp.Mag2(),"perp2",1 );
758 
759  // test rotations
760  double angle = 1;
761  XYZVector vr1 = RotateX(v,angle);
762  XYZVector vr2 = RotationX(angle) * v;
763  iret |= compare(vr1.Y(), vr2.Y(),"y",1 );
764  iret |= compare(vr1.Z(), vr2.Z(),"z",1 );
765 
766  vr1 = RotateY(v,angle);
767  vr2 = RotationY(angle) * v;
768  iret |= compare(vr1.X(), vr2.X(),"x",1 );
769  iret |= compare(vr1.Z(), vr2.Z(),"z",1 );
770 
771  vr1 = RotateZ(v,angle);
772  vr2 = RotationZ(angle) * v;
773  iret |= compare(vr1.X(), vr2.X(),"x",1 );
774  iret |= compare(vr1.Y(), vr2.Y(),"y",1 );
775 
776 
777  if (iret == 0) std::cout << "\t\t\tOK\n";
778  else std::cout << "\t\t\t\t\t\tFAILED\n";
779  return iret;
780 
781 }
782 
784 
785  int iret = 0;
786  iret |= testVector3D();
787  iret |= testPoint3D();
788 
789  iret |= testVector2D();
790  iret |= testPoint2D();
791 
792  iret |= testRotations3D();
793 
794  iret |= testTransform3D();
795 
796  iret |= testVectorUtil();
797 
798 
799  if (iret !=0) std::cout << "\nTest GenVector FAILED!!!!!!!!!\n";
800  return iret;
801 
802 }
803 
804 int main() {
805  int ret = testGenVector();
806  if (ret) std::cerr << "test FAILED !!! " << std::endl;
807  else std::cout << "test OK " << std::endl;
808  return ret;
809 }
Scalar R() const
Polar R, converting if necessary from internal coordinate system.
DisplacementVector3D< Cartesian3D< double >, LocalCoordinateSystemTag > LocalXYZVector
int testVector3D()
Translation3D< T > Inverse() const
Return the inverse of the transformation.
Scalar R() const
Polar R, converting if necessary from internal coordinate system.
Scalar Psi() const
Return Psi angle (X&#39;&#39; rotation angle)
Definition: RotationZYX.h:203
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
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
Rotation class representing a 3D rotation about the Z axis by the angle of rotation.
Definition: RotationZ.h:43
PositionVector3D< Polar3D< double >, GlobalCoordinateSystemTag > GlobalPolar3DPoint
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
Scalar Mag2() const
Magnitute squared ( r^2 in spherical coordinate)
Vector1 ProjVector(const Vector1 &v, const Vector2 &u)
Find the projection of v along the given direction u.
Definition: VectorUtil.h:151
EulerAngles Inverse() const
Return inverse of a rotation.
Definition: EulerAngles.h:306
DisplacementVector3D< Cartesian3D< double >, DefaultCoordinateSystemTag > XYZVector
3D Vector based on the cartesian coordinates x,y,z in double precision
Definition: Vector3Dfwd.h:34
Scalar Phi() const
Polar phi, converting if necessary from internal coordinate system.
Scalar Mag2() const
Magnitute squared ( r^2 in spherical coordinate)
int compare(double v1, double v2, const std::string &name="", double scale=1.0)
Class describing a generic position vector (point) in 3 dimensions.
Scalar Dot(const DisplacementVector2D< OtherCoords, Tag > &v) const
Return the scalar (dot) product of two displacement vectors.
int testPoint3D()
Rotation class with the (3D) rotation represented by angles describing first a rotation of an angle p...
Definition: RotationZYX.h:59
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
Rotation3D Inverse() const
Return inverse of a rotation.
Definition: Rotation3D.h:420
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:516
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
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:253
int testGenVector()
PositionVector3D< Cartesian3D< double >, GlobalCoordinateSystemTag > GlobalXYZPoint
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
void Transform(const PositionVector3D< CoordSystem, Tag1 > &p1, PositionVector3D< CoordSystem, Tag2 > &p2) const
Transformation operation for points between different coordinate system tags.
Definition: Transform3D.h:726
Float_t delta
Scalar Phi() const
Return Phi Euler angle.
Definition: EulerAngles.h:212
AxisAngle class describing rotation represented with direction axis (3D Vector) and an angle of rotat...
Definition: AxisAngle.h:41
Scalar X() const
Cartesian X, converting if necessary from internal coordinate system.
Scalar Psi() const
Return Psi Euler angle.
Definition: EulerAngles.h:232
Rotation3D rrr(TestRotation const &t)
double sqrt(double)
static const double x2[5]
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...
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:529
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 Z() const
Cartesian Z, converting if necessary from internal coordinate system.
Scalar Y() const
Cartesian Y, converting if necessary from internal coordinate system.
Scalar R() const
Polar R, 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:180
Lorentz boost class with the (4D) transformation represented internally by a 4x4 orthosymplectic matr...
Definition: Boost.h:46
Scalar Theta() const
Return Theta Euler angle.
Definition: EulerAngles.h:222
static double p2(double t, double a, double b, double c)
Vector ApplyInverse(const Vector &v) const
Directly apply the inverse affine transformation on vectors.
Definition: Transform3D.h:679
Scalar X() const
Cartesian X, 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:287
int testPoint2D()
void GetRotationMatrix(ForeignMatrix &m) const
Get components into a linear algebra matrix of size at least 4x4, which must support operator()(i...
void Rotate(Scalar angle)
Rotate by an angle.
Scalar Y() const
Cartesian Y, converting if necessary from internal coordinate system.
PositionVector2D< Cartesian2D< double >, GlobalCoordinateSystemTag > GlobalXYPoint
Class describing a 3 dimensional translation.
Definition: Translation3D.h:51
Lorentz transformation class with the (4D) transformation represented by a 4x4 orthosymplectic matrix...
Scalar Z() const
Cartesian Z, converting if necessary from internal coordinate system.
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:45
TRandom2 r(17)
Scalar R() const
Polar R, converting if necessary from internal coordinate system.
SVector< double, 2 > v
Definition: Dict.h:5
Scalar X() const
Cartesian X, converting if necessary from internal coordinate system.
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
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...
Rotation class with the (3D) rotation represented by a 3x3 orthogonal matrix.
Definition: Rotation3D.h:65
const Vector & Vect() const
return a const reference to the underline vector representing the translation
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:270
static double p1(double t, double a, double b)
DisplacementVector3D< Cartesian3D< double >, GlobalCoordinateSystemTag > GlobalXYZVector
Class describing a generic position vector (point) in 2 dimensions.
Scalar Mag2() const
Magnitute squared ( r^2 in spherical coordinate)
REAL epsilon
Definition: triangle.c:617
Impl::Transform3D< double > Transform3D
Definition: Transform3D.h:1318
static const double x1[5]
int testRotations3D()
int testTransform3D()
EulerAngles class describing rotation as three angles (Euler Angles).
Definition: EulerAngles.h:43
int main()
DisplacementVector2D Unit() const
return unit vector parallel to this
bool IsEqual(const Transform &t1, const Transform &t2, unsigned int size)
Scalar Theta() const
Return Theta angle (Y&#39; rotation angle)
Definition: RotationZYX.h:193
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
PositionVector3D< Cartesian3D< double >, LocalCoordinateSystemTag > LocalXYZPoint
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:167
Scalar Y() const
Cartesian Y, converting if necessary from internal coordinate system.
int testVectorUtil()
Transform3D< T > Inverse() const
Return the inverse of the transformation.
Definition: Transform3D.h:881
void Invert()
Invert a rotation in place.
Definition: Rotation3D.cxx:109
Scalar Phi() const
Return Phi angle (Z rotation angle)
Definition: RotationZYX.h:183
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
Scalar Dot(const DisplacementVector2D< OtherCoords, Tag > &v) const
Return the scalar (Dot) product of this with a displacement vector in any coordinate system...
DisplacementVector2D< Cartesian2D< double >, GlobalCoordinateSystemTag > GlobalXYVector
Tag for identifying vectors based on a local coordinate system.
Scalar Mag2() const
Magnitute squared ( r^2 in spherical coordinate)
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:196
Basic 3D Transformation class describing a rotation and then a translation The internal data are a 3D...
Definition: Transform3D.h:78
Tag for identifying vectors based on a global coordinate system.
Impl::Translation3D< double > Translation3D
Scalar Dot(const DisplacementVector3D< OtherCoords, Tag > &v) const
Return the scalar (Dot) product of this with a displacement vector in any 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:579
Scalar Dot(const DisplacementVector3D< OtherCoords, Tag > &v) const
Return the scalar (dot) product of two displacement vectors.