Logo ROOT   6.08/07
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  if (iret == 0) std::cout << "OK\n";
676  else std::cout << "\t\t\tFAILED\n";
677 
678  return iret;
679 }
680 
681 
683 
684  std::cout << "testing VectorUtil \t:\t";
685  int iret = 0;
686 
687  // test new perp functions
688  XYZVector v(1.,2.,3.);
689 
690  XYZVector vx = ProjVector(v,XYZVector(3,0,0) );
691  iret |= compare(vx.X(), v.X(),"x",1 );
692  iret |= compare(vx.Y(), 0,"y",1 );
693  iret |= compare(vx.Z(), 0,"z",1 );
694 
695  XYZVector vpx = PerpVector(v,XYZVector(2,0,0) );
696  iret |= compare(vpx.X(), 0,"x",1 );
697  iret |= compare(vpx.Y(), v.Y(),"y",1 );
698  iret |= compare(vpx.Z(), v.Z(), "z",1 );
699 
700  double perpy = Perp(v, XYZVector(0,2,0) );
701  iret |= compare(perpy, std::sqrt( v.Mag2() - v.y()*v.y()),"perpy" );
702 
703  XYZPoint u(1,1,1);
704  XYZPoint un = u/u.R();
705 
706 
707  XYZVector vl = ProjVector(v,u);
708  XYZVector vl2 = XYZVector(un) * ( v.Dot(un ) );
709 
710  iret |= compare(vl.X(), vl2.X(),"x",1 );
711  iret |= compare(vl.Y(), vl2.Y(),"y",1 );
712  iret |= compare(vl.Z(), vl2.Z(),"z",1 );
713 
714  XYZVector vp = PerpVector(v,u);
715  XYZVector vp2 = v - XYZVector ( un * ( v.Dot(un ) ) );
716  iret |= compare(vp.X(), vp2.X(),"x",10 );
717  iret |= compare(vp.Y(), vp2.Y(),"y",10 );
718  iret |= compare(vp.Z(), vp2.Z(),"z",10 );
719 
720  double perp = Perp(v,u);
721  iret |= compare(perp, vp.R(),"perp",1 );
722  double perp2 = Perp2(v,u);
723  iret |= compare(perp2, vp.Mag2(),"perp2",1 );
724 
725  // test rotations
726  double angle = 1;
727  XYZVector vr1 = RotateX(v,angle);
728  XYZVector vr2 = RotationX(angle) * v;
729  iret |= compare(vr1.Y(), vr2.Y(),"y",1 );
730  iret |= compare(vr1.Z(), vr2.Z(),"z",1 );
731 
732  vr1 = RotateY(v,angle);
733  vr2 = RotationY(angle) * v;
734  iret |= compare(vr1.X(), vr2.X(),"x",1 );
735  iret |= compare(vr1.Z(), vr2.Z(),"z",1 );
736 
737  vr1 = RotateZ(v,angle);
738  vr2 = RotationZ(angle) * v;
739  iret |= compare(vr1.X(), vr2.X(),"x",1 );
740  iret |= compare(vr1.Y(), vr2.Y(),"y",1 );
741 
742 
743  if (iret == 0) std::cout << "\t\t\tOK\n";
744  else std::cout << "\t\t\t\t\t\tFAILED\n";
745  return iret;
746 
747 }
748 
750 
751  int iret = 0;
752  iret |= testVector3D();
753  iret |= testPoint3D();
754 
755  iret |= testVector2D();
756  iret |= testPoint2D();
757 
758  iret |= testRotations3D();
759 
760  iret |= testTransform3D();
761 
762  iret |= testVectorUtil();
763 
764 
765  if (iret !=0) std::cout << "\nTest GenVector FAILED!!!!!!!!!\n";
766  return iret;
767 
768 }
769 
770 int main() {
771  int ret = testGenVector();
772  if (ret) std::cerr << "test FAILED !!! " << std::endl;
773  else std::cout << "test OK " << std::endl;
774  return ret;
775 }
Scalar R() const
Polar R, converting if necessary from internal coordinate system.
DisplacementVector3D< Cartesian3D< double >, LocalCoordinateSystemTag > LocalXYZVector
int testVector3D()
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:215
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:153
EulerAngles Inverse() const
Return inverse of a rotation.
Definition: EulerAngles.h:306
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)
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.
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: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
Rotation3D Inverse() const
Return inverse of a rotation.
Definition: Rotation3D.h:420
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:255
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
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...
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:182
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)
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:289
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.
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< Cartesian2D< double >, GlobalCoordinateSystemTag > GlobalXYPoint
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.
const Vector & Vect() const
return a const reference to the underline vector representing the translation
Global Helper functions for generic Vector classes.
Definition: VectorUtil.h:47
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
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
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
Rotation3D Rotation() const
Get the 3D rotation representing the 3D transformation.
Definition: Transform3D.h:425
Class describing a 3 dimensional translation.
Definition: Translation3D.h:57
static const double x1[5]
int testRotations3D()
int testTransform3D()
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()
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:205
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
DisplacementVector3D< Cartesian3D< double >, DefaultCoordinateSystemTag > XYZVector
3D Vector based on the cartesian coordinates x,y,z in double precision
Definition: Vector3Dfwd.h:34
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:169
Scalar Y() const
Cartesian Y, converting if necessary from internal coordinate system.
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 testVectorUtil()
void Invert()
Invert a rotation in place.
Definition: Rotation3D.cxx:109
Scalar Phi() const
Return Phi angle (Z rotation angle)
Definition: RotationZYX.h:195
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:198
Tag for identifying vectors based on a global coordinate system.
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
char name[80]
Definition: TGX11.cxx:109
Class describing a generic displacement vector in 2 dimensions.
Scalar Dot(const DisplacementVector3D< OtherCoords, Tag > &v) const
Return the scalar (dot) product of two displacement vectors.
Translation3D Inverse() const
Return the inverse of the transformation.