testGenVector.cxx

Go to the documentation of this file.
00001 
00002 #include "Math/Vector3D.h"
00003 #include "Math/Point3D.h"
00004 
00005 #include "Math/Vector2D.h"
00006 #include "Math/Point2D.h"
00007 
00008 #include "Math/EulerAngles.h"
00009 
00010 #include "Math/Transform3D.h"
00011 #include "Math/Translation3D.h"
00012 
00013 #include "Math/Rotation3D.h"
00014 #include "Math/RotationX.h"
00015 #include "Math/RotationY.h"
00016 #include "Math/RotationZ.h"
00017 #include "Math/Quaternion.h"
00018 #include "Math/AxisAngle.h"
00019 #include "Math/EulerAngles.h"
00020 #include "Math/RotationZYX.h"
00021 
00022 #include "Math/LorentzRotation.h"
00023 
00024 #include "Math/VectorUtil.h"
00025 #ifndef NO_SMATRIX
00026 #include "Math/SMatrix.h"
00027 #endif
00028 
00029 #include <vector>
00030 
00031 using namespace ROOT::Math;
00032 using namespace ROOT::Math::VectorUtil;
00033 
00034 
00035 
00036 typedef  DisplacementVector3D<Cartesian3D<double>, GlobalCoordinateSystemTag>  GlobalXYZVector; 
00037 typedef  DisplacementVector3D<Cartesian3D<double>, LocalCoordinateSystemTag>   LocalXYZVector; 
00038 typedef  DisplacementVector3D<Polar3D<double>, GlobalCoordinateSystemTag>      GlobalPolar3DVector; 
00039 
00040 
00041 
00042 typedef  PositionVector3D<Cartesian3D<double>, GlobalCoordinateSystemTag>   GlobalXYZPoint; 
00043 typedef  PositionVector3D<Cartesian3D<double>, LocalCoordinateSystemTag>    LocalXYZPoint; 
00044 typedef  PositionVector3D<Polar3D<double>, GlobalCoordinateSystemTag>       GlobalPolar3DPoint; 
00045 typedef  PositionVector3D<Polar3D<double>, LocalCoordinateSystemTag>       LocalPolar3DPoint; 
00046 
00047 
00048 //#define TEST_COMPILE_ERROR
00049 
00050 
00051 int compare( double v1, double v2, const std::string & name = "", double scale = 1.0) {
00052   //  ntest = ntest + 1; 
00053 
00054   // numerical double limit for epsilon 
00055   double eps = scale* std::numeric_limits<double>::epsilon();
00056   int iret = 0; 
00057   double delta = v2 - v1;
00058   double d = 0;
00059   if (delta < 0 ) delta = - delta; 
00060   if (v1 == 0 || v2 == 0) { 
00061     if  (delta > eps ) { 
00062       iret = 1; 
00063     }
00064   }
00065   // skip case v1 or v2 is infinity
00066   else { 
00067      d = v1; 
00068 
00069     if ( v1 < 0) d = -d; 
00070     // add also case when delta is small by default
00071     if ( delta/d  > eps && delta > eps ) 
00072       iret =  1; 
00073   }
00074 
00075   if (iret == 0) 
00076     std::cout << ".";
00077   else { 
00078     int pr = std::cout.precision (18);
00079     std::cout << "\nDiscrepancy in " << name << "() : " << v1 << " != " << v2 << " discr = " << int(delta/d/eps) 
00080               << "   (Allowed discrepancy is " << eps  << ")\n";
00081     std::cout.precision (pr);
00082     //nfail = nfail + 1;
00083   }
00084   return iret; 
00085 }
00086 
00087 template<class Transform>
00088 bool IsEqual(const Transform & t1, const Transform & t2, unsigned int size)  {
00089 // size should be an enum of the Transform class 
00090    std::vector<double> x1(size); 
00091    std::vector<double> x2(size); 
00092    t1.GetComponents(x1.begin(), x1.end() );
00093    t2.GetComponents(x2.begin(), x2.end() );
00094    bool ret = true; 
00095    unsigned int i = 0; 
00096    while (ret && i < size) {
00097       // from TMath::AreEqualRel(x1,x2,2*eps)
00098       bool areEqual = std::abs(x1[i]-x2[i]) < std::numeric_limits<double>::epsilon() * 
00099          ( std::abs(x1[i]) + std::abs(x2[i] ) ); 
00100       ret &= areEqual; 
00101       i++;
00102    }
00103    return ret; 
00104 }
00105 
00106 int testVector3D() { 
00107 
00108   int iret = 0;
00109 
00110   std::cout << "testing Vector3D   \t:\t"; 
00111 
00112   // test the vector tags 
00113 
00114   GlobalXYZVector vg(1.,2.,3.); 
00115   GlobalXYZVector vg2(vg); 
00116 
00117   GlobalPolar3DVector vpg(vg);
00118 
00119   iret |= compare(vpg.R(), vg2.R() );
00120  
00121 //   std::cout << vg2 << std::endl;
00122 
00123   double r = vg.Dot(vpg); 
00124   iret |= compare(r, vg.Mag2() );
00125 
00126   GlobalXYZVector vcross = vg.Cross(vpg); 
00127   iret |= compare(vcross.R(), 0.0,"cross",10 );
00128 
00129 //   std::cout << vg.Dot(vpg) << std::endl;
00130 //   std::cout << vg.Cross(vpg) << std::endl;
00131 
00132 
00133   
00134  
00135 
00136   GlobalXYZVector vg3 = vg + vpg;  
00137   iret |= compare(vg3.R(), 2*vg.R() );
00138 
00139   GlobalXYZVector vg4 = vg - vpg;  
00140   iret |= compare(vg4.R(), 0.0,"diff",10 );
00141 
00142 
00143 
00144 
00145 #ifdef TEST_COMPILE_ERROR
00146    LocalXYZVector vl; vl = vg; 
00147   LocalXYZVector vl2(vg2);
00148   LocalXYZVector vl3(vpg);
00149   vg.Dot(vl);
00150   vg.Cross(vl);
00151   vg3 = vg + vl;
00152   vg4 = vg - vl;
00153 #endif
00154 
00155 
00156   if (iret == 0) std::cout << "\t\t\t\t\tOK\n"; 
00157   else std::cout << "\t\t\t\tFAILED\n";
00158 
00159 
00160   return iret;
00161 }
00162 
00163 
00164 
00165 int testPoint3D() { 
00166 
00167   int iret = 0;
00168 
00169   std::cout << "testing Point3D    \t:\t"; 
00170 
00171   // test the vector tags 
00172 
00173   GlobalXYZPoint pg(1.,2.,3.); 
00174   GlobalXYZPoint pg2(pg); 
00175 
00176   GlobalPolar3DPoint ppg(pg);
00177 
00178   iret |= compare(ppg.R(), pg2.R() );
00179   //std::cout << pg2 << std::endl;
00180   
00181 
00182 
00183 
00184   GlobalXYZVector vg(pg);
00185 
00186   double r = pg.Dot(vg); 
00187   iret |= compare(r, pg.Mag2() );
00188 
00189   GlobalPolar3DVector vpg(pg);
00190   GlobalXYZPoint pcross = pg.Cross(vpg);
00191   iret |= compare(pcross.R(), 0.0,"cross",10 );
00192 
00193   GlobalPolar3DPoint pg3 = ppg + vg; 
00194   iret |= compare(pg3.R(), 2*pg.R() );
00195 
00196   GlobalXYZVector vg4 = pg - ppg; 
00197   iret |= compare(vg4.R(), 0.0,"diff",10 );
00198 
00199 
00200 #ifdef TEST_COMPILE_ERROR
00201   LocalXYZPoint pl; pl = pg; 
00202   LocalXYZVector pl2(pg2);
00203   LocalXYZVector pl3(ppg);
00204   pl.Dot(vg);
00205   pl.Cross(vg);
00206   pg3 = ppg + pg;
00207   pg3 = ppg + pl;
00208   vg4 = pg - pl;
00209 #endif
00210 
00211   // operator - 
00212   XYZPoint q1(1.,2.,3.);
00213   XYZPoint q2 = -1.* q1; 
00214   XYZVector v2 = -XYZVector(q1);
00215   iret |= compare(XYZVector(q2) == v2,true,"reflection");
00216 
00217 
00218   if (iret == 0) std::cout << "\t\t\t\t\tOK\n"; 
00219   else std::cout << "\t\t\t\tFAILED\n"; 
00220 
00221   return iret;
00222 }
00223 
00224 
00225 
00226 typedef  DisplacementVector2D<Cartesian2D<double>, GlobalCoordinateSystemTag>  GlobalXYVector; 
00227 typedef  DisplacementVector2D<Cartesian2D<double>, LocalCoordinateSystemTag>   LocalXYVector; 
00228 typedef  DisplacementVector2D<Polar2D<double>, GlobalCoordinateSystemTag>      GlobalPolar2DVector; 
00229 
00230 
00231 
00232 
00233 int testVector2D() { 
00234 
00235   int iret = 0;
00236 
00237   std::cout << "testing Vector2D   \t:\t"; 
00238 
00239   // test the vector tags 
00240 
00241   GlobalXYVector vg(1.,2.); 
00242   GlobalXYVector vg2(vg); 
00243 
00244   GlobalPolar2DVector vpg(vg);
00245 
00246   iret |= compare(vpg.R(), vg2.R() );
00247  
00248 //   std::cout << vg2 << std::endl;
00249 
00250   double r = vg.Dot(vpg); 
00251   iret |= compare(r, vg.Mag2() );
00252 
00253 //   std::cout << vg.Dot(vpg) << std::endl;
00254  
00255 
00256   GlobalXYVector vg3 = vg + vpg;  
00257   iret |= compare(vg3.R(), 2*vg.R() );
00258 
00259   GlobalXYVector vg4 = vg - vpg;  
00260   iret |= compare(vg4.R(), 0.0,"diff",10 );
00261 
00262 
00263   double angle = 1.;
00264   vg.Rotate(angle); 
00265   iret |= compare(vg.Phi(), vpg.Phi() + angle );
00266   iret |= compare(vg.R(), vpg.R()  );
00267 
00268   GlobalXYZVector v3d(1,2,0);
00269   GlobalXYZVector vr3d = RotationZ(angle) * v3d; 
00270   iret |= compare(vg.X(), vr3d.X() );
00271   iret |= compare(vg.Y(), vr3d.Y()  );
00272   
00273   GlobalXYVector vu = vg3.Unit();
00274   iret |= compare(vu.R(), 1. );
00275   
00276 
00277 #ifdef TEST_COMPILE_ERROR
00278    LocalXYVector vl; vl = vg; 
00279   LocalXYVector vl2(vg2);
00280   LocalXYVector vl3(vpg);
00281   vg.Dot(vl);
00282   vg3 = vg + vl;
00283   vg4 = vg - vl;
00284 #endif
00285 
00286 
00287   if (iret == 0) std::cout << "\t\t\t\tOK\n"; 
00288   else std::cout << "\t\t\tFAILED\n";
00289 
00290 
00291   return iret;
00292 }
00293 
00294 
00295 typedef  PositionVector2D<Cartesian2D<double>, GlobalCoordinateSystemTag>   GlobalXYPoint; 
00296 typedef  PositionVector2D<Cartesian2D<double>, LocalCoordinateSystemTag>    LocalXYPoint; 
00297 typedef  PositionVector2D<Polar2D<double>, GlobalCoordinateSystemTag>       GlobalPolar2DPoint; 
00298 typedef  PositionVector2D<Polar2D<double>, LocalCoordinateSystemTag>       LocalPolar2DPoint; 
00299 
00300 
00301 
00302 int testPoint2D() { 
00303 
00304   int iret = 0;
00305 
00306   std::cout << "testing Point2D    \t:\t"; 
00307 
00308   // test the vector tags 
00309 
00310   GlobalXYPoint pg(1.,2.); 
00311   GlobalXYPoint pg2(pg); 
00312 
00313   GlobalPolar2DPoint ppg(pg);
00314 
00315   iret |= compare(ppg.R(), pg2.R() );
00316   //std::cout << pg2 << std::endl;
00317   
00318 
00319 
00320 
00321   GlobalXYVector vg(pg);
00322 
00323   double r = pg.Dot(vg); 
00324   iret |= compare(r, pg.Mag2() );
00325 
00326   GlobalPolar2DVector vpg(pg);
00327 
00328   GlobalPolar2DPoint pg3 = ppg + vg; 
00329   iret |= compare(pg3.R(), 2*pg.R() );
00330 
00331   GlobalXYVector vg4 = pg - ppg; 
00332   iret |= compare(vg4.R(), 0.0,"diff",10 );
00333 
00334 
00335 #ifdef TEST_COMPILE_ERROR
00336   LocalXYPoint pl; pl = pg; 
00337   LocalXYVector pl2(pg2);
00338   LocalXYVector pl3(ppg);
00339   pl.Dot(vg);
00340   pl.Cross(vg);
00341   pg3 = ppg + pg;
00342   pg3 = ppg + pl;
00343   vg4 = pg - pl;
00344 #endif
00345 
00346   // operator - 
00347   XYPoint q1(1.,2.);
00348   XYPoint q2 = -1.* q1; 
00349   XYVector v2 = -XYVector(q1);
00350   iret |= compare(XYVector(q2) == v2,true,"reflection");
00351 
00352 
00353 
00354   double angle = 1.;
00355   pg.Rotate(angle); 
00356   iret |= compare(pg.Phi(), ppg.Phi() + angle );
00357   iret |= compare(pg.R(), ppg.R()  );
00358 
00359   GlobalXYZVector v3d(1,2,0);
00360   GlobalXYZVector vr3d = RotationZ(angle) * v3d; 
00361   iret |= compare(pg.X(), vr3d.X() );
00362   iret |= compare(pg.Y(), vr3d.Y()  );
00363   
00364 
00365 
00366   if (iret == 0) std::cout << "\t\t\t\tOK\n"; 
00367   else std::cout << "\t\t\tFAILED\n"; 
00368 
00369   return iret;
00370 }
00371 
00372 
00373 // missing LV test
00374 
00375 int testRotations3D() {  
00376 
00377   int iret=0; 
00378   std::cout << "testing 3D Rotations\t:\t"; 
00379 
00380 
00381   Rotation3D rot = RotationZ(1.) * RotationY(2) * RotationX(3); 
00382   GlobalXYZVector vg(1.,2.,3); 
00383   GlobalXYZPoint  pg(1.,2.,3); 
00384   GlobalPolar3DVector vpg(vg);  
00385 
00386   //  GlobalXYZVector vg2 = rot.operator()<Cartesian3D,GlobalCoordinateSystemTag, GlobalCoordinateSystemTag> (vg); 
00387   GlobalXYZVector vg2 = rot(vg); 
00388   iret |= compare(vg2.R(), vg.R(),"rot3D" );
00389 
00390   GlobalXYZPoint pg2 = rot(pg); 
00391   iret |= compare(pg2.X(), vg2.X(),"x diff");
00392   iret |= compare(pg2.Y(), vg2.Y(),"y diff");
00393   iret |= compare(pg2.Z(), vg2.Z(),"z diff");
00394 
00395 
00396   Quaternion qrot(rot); 
00397 
00398   pg2 = qrot(pg); 
00399   iret |= compare(pg2.X(), vg2.X(),"x diff",10);
00400   iret |= compare(pg2.Y(), vg2.Y(),"y diff",10);
00401   iret |= compare(pg2.Z(), vg2.Z(),"z diff",10);
00402 
00403   GlobalPolar3DVector vpg2 = qrot * vpg; 
00404 
00405   iret |= compare(vpg2.X(), vg2.X(),"x diff",10 );
00406   iret |= compare(vpg2.Y(), vg2.Y(),"y diff",10 );
00407   iret |= compare(vpg2.Z(), vg2.Z(),"z diff",10 );
00408 
00409   AxisAngle arot(rot); 
00410   pg2 = arot(pg); 
00411   iret |= compare(pg2.X(), vg2.X(),"x diff",10 );
00412   iret |= compare(pg2.Y(), vg2.Y(),"y diff",10 );
00413   iret |= compare(pg2.Z(), vg2.Z(),"z diff",10 );
00414 
00415   vpg2 = arot (vpg);
00416   iret |= compare(vpg2.X(), vg2.X(),"x diff",10 );
00417   iret |= compare(vpg2.Y(), vg2.Y(),"y diff",10 );
00418   iret |= compare(vpg2.Z(), vg2.Z(),"z diff",10 );
00419   
00420   EulerAngles erot(rot); 
00421 
00422   vpg2 = erot (vpg); 
00423   iret |= compare(vpg2.X(), vg2.X(),"x diff",10 );
00424   iret |= compare(vpg2.Y(), vg2.Y(),"y diff",10 );
00425   iret |= compare(vpg2.Z(), vg2.Z(),"z diff",10 );
00426 
00427   GlobalXYZVector vrx = RotationX(3) * vg; 
00428   GlobalXYZVector vry = RotationY(2) * vrx; 
00429   vpg2 = RotationZ(1) * GlobalPolar3DVector (vry); 
00430   iret |= compare(vpg2.X(), vg2.X(),"x diff",10 );
00431   iret |= compare(vpg2.Y(), vg2.Y(),"y diff",10 );
00432   iret |= compare(vpg2.Z(), vg2.Z(),"z diff",10 );
00433 
00434   // test Get/SetComponents
00435   XYZVector v1,v2,v3; 
00436   rot.GetComponents(v1,v2,v3);
00437   const Rotation3D rot2(v1,v2,v3); 
00438   //rot2.SetComponents(v1,v2,v3);
00439   double r1[9],r2[9]; 
00440   rot.GetComponents(r1,r1+9);
00441   rot2.GetComponents(r2,r2+9);
00442   for (int i = 0; i < 9; ++i) {
00443      iret |= compare(r1[i],r2[i],"Get/SetComponents"); 
00444   }
00445   // operator == fails for numerical precision
00446   //iret |= compare( (rot2==rot),true,"Get/SetComponens");
00447 
00448   // test get/set with a matrix
00449 #ifndef NO_SMATRIX
00450   SMatrix<double,3> mat; 
00451   rot2.GetRotationMatrix(mat);
00452   rot.SetRotationMatrix(mat); 
00453   iret |= compare( (rot2==rot),true,"Get/SetRotMatrix");
00454 #endif
00455 
00456   //test inversion
00457   Rotation3D rotInv = rot.Inverse();
00458   rot.Invert(); // invert in place
00459   bool comp = (rotInv == rot ); 
00460   iret |= compare(comp,true,"inversion");
00461 
00462   // rotation and scaling of points
00463   XYZPoint q1(1.,2,3); double a = 3;
00464   XYZPoint qr1 =  rot( a * q1);
00465   XYZPoint qr2 =  a * rot( q1);
00466   iret |= compare(qr1.X(), qr2.X(),"x diff",10 );
00467   iret |= compare(qr1.Y(), qr2.Y(),"y diff",10 );
00468   iret |= compare(qr1.Z(), qr2.Z(),"z diff",10 );
00469 
00470 
00471   if (iret == 0) std::cout << "\tOK\n"; 
00472   else std::cout << "\t FAILED\n";
00473 
00474   return iret; 
00475 }
00476 
00477 
00478 int testTransform3D() { 
00479 
00480 
00481   std::cout << "testing 3D Transform\t:\t"; 
00482   int iret = 0; 
00483 
00484   EulerAngles r(1.,2.,3.);
00485 
00486   GlobalPolar3DVector v(1.,2.,3.);
00487   GlobalXYZVector w(v);
00488 
00489   Transform3D t1( v );
00490   GlobalXYZPoint pg; 
00491   t1.Transform( LocalXYZPoint(), pg ); 
00492   iret |= compare(pg.X(), v.X(),"x diff",10 );
00493   iret |= compare(pg.Y(), v.Y(),"y diff",10 );
00494   iret |= compare(pg.Z(), v.Z(),"z diff",10 );
00495 
00496 
00497   Transform3D t2( r, v );
00498 
00499   GlobalPolar3DVector vr = r.Inverse()*v; 
00500 
00501 //   std::cout << GlobalXYZVector(v) << std::endl; 
00502 //   std::cout << GlobalXYZVector(vr) << std::endl; 
00503 //   std::cout << GlobalXYZVector (r(v)) << std::endl; 
00504 //   std::cout << GlobalXYZVector (r(vr)) << std::endl; 
00505 //   std::cout << vr << std::endl; 
00506 //   std::cout << r(vr) << std::endl; 
00507 
00508   
00509 
00510 //   std::cout << r << std::endl; 
00511 //   std::cout << r.Inverse() << std::endl; 
00512 //   std::cout << r * r.Inverse() << std::endl; 
00513 //   std::cout << Rotation3D(r) * Rotation3D(r.Inverse()) << std::endl; 
00514 //   std::cout << Rotation3D(r) * Rotation3D(r).Inverse() << std::endl; 
00515 
00516 
00517   // test Translation3D
00518 
00519   Translation3D tr1(v);
00520   Translation3D tr2(v.X(),v.Y(),v.Z());
00521   iret |= compare(tr1 ==tr2, 1,"eq transl",1 );
00522 
00523   Translation3D tr3 = tr1 * tr1.Inverse(); 
00524   GlobalPolar3DVector vp2 = tr3 * v;
00525   iret |= compare(vp2.X(), v.X(),"x diff",10 );
00526   iret |= compare(vp2.Y(), v.Y(),"y diff",10 );
00527   iret |= compare(vp2.Z(), v.Z(),"z diff",10 );
00528 
00529 
00530   Transform3D t2b = tr1 * Rotation3D(r);
00531   // this above fails on Windows - use a comparison with tolerance
00532   // 12 is size of Transform3D internal vector
00533   iret |= compare( IsEqual(t2,t2b,12), true,"eq1 transf",1 );
00534   //iret |= compare(t2 ==t2b, 1,"eq1 transf",1 );
00535   Transform3D t2c( r, tr1); 
00536   iret |= compare( IsEqual(t2,t2c,12), true,"eq2 transf",1 );
00537   //iret |= compare(t2 ==t2c, 1,"eq2 transf",1 );
00538 
00539 
00540   Transform3D t3 =  Rotation3D(r) * Translation3D(vr); 
00541 
00542   Rotation3D rrr;
00543   XYZVector vvv;
00544   t2b.GetDecomposition(rrr,vvv);
00545   iret |= compare(Rotation3D(r) ==rrr, 1,"eq transf rot",1 );
00546   iret |= compare( tr1.Vect() == vvv, 1,"eq transf vec",1 );
00547 //   if (iret) std::cout << vvv << std::endl;
00548 //   if (iret) std::cout << Translation3D(vr) << std::endl;
00549 
00550   Translation3D ttt;
00551   t2b.GetDecomposition(rrr,ttt);
00552   iret |= compare( tr1 == ttt, 1,"eq transf trans",1 );
00553 //   if (iret) std::cout << ttt << std::endl;
00554 
00555   EulerAngles err2; 
00556   GlobalPolar3DVector vvv2;
00557   t2b.GetDecomposition(err2,vvv2);
00558   iret |= compare( r.Phi(), err2.Phi(),"transf rot phi",4 );
00559   iret |= compare( r.Theta(), err2.Theta(),"transf rot theta",1 );
00560   iret |= compare( r.Psi(), err2.Psi(),"transf rot psi",1 );
00561 
00562   iret |= compare( v == vvv2, 1,"eq transf g vec",1 );
00563 
00564   // create from other rotations
00565   RotationZYX rzyx(r); 
00566   Transform3D t4( rzyx);
00567   iret |= compare( t4.Rotation() == Rotation3D(rzyx), 1,"eq trans rzyx",1 );
00568 
00569   Transform3D trf2 = tr1 * r; 
00570   iret |= compare( trf2 == t2b, 1,"trasl * e rot",1 );
00571   Transform3D trf3 = r * Translation3D(vr); 
00572   //iret |= compare( trf3 == t3, 1,"e rot * transl",1 );
00573   // this above fails on i686-slc5-gcc43-opt - use a comparison with tolerance
00574   iret |= compare( IsEqual(trf3,t3,12), true,"e rot * transl",1 );
00575 
00576   Transform3D t5(rzyx, v);
00577   Transform3D trf5 = Translation3D(v) * rzyx; 
00578   //iret |= compare( trf5 == t5, 1,"trasl * rzyx",1 );
00579   iret |= compare( IsEqual(trf5,t5,12), true,"trasl * rzyx",1 );
00580 
00581   Transform3D t6(rzyx, rzyx * Translation3D(v).Vect() );
00582   Transform3D trf6 = rzyx * Translation3D(v); 
00583   iret |= compare( trf6 == t6, 1,"rzyx * transl",1 );
00584   if (iret) std::cout << t6 << "\n---\n" << trf6 << std::endl;
00585 
00586 
00587 
00588   Transform3D trf7 = t4 * Translation3D(v);
00589   //iret |= compare( trf7 == trf6, 1,"tranf * transl",1 );
00590   iret |= compare( IsEqual(trf7,trf6,12), true,"tranf * transl",1 );
00591   Transform3D trf8 = Translation3D(v) * t4;
00592   iret |= compare( trf8 == trf5, 1,"trans * transf",1 );
00593 
00594   Transform3D trf9 = Transform3D(v) * rzyx;
00595   iret |= compare( trf9 == trf5, 1,"tranf * rzyx",1 );
00596   Transform3D trf10 = rzyx * Transform3D(v);
00597   iret |= compare( trf10 == trf6, 1,"rzyx * transf",1 );
00598   Transform3D trf11 = Rotation3D(rzyx) * Transform3D(v);
00599   iret |= compare( trf11 == trf10, 1,"r3d * transf",1 );
00600 
00601   RotationZYX rrr2 = trf10.Rotation<RotationZYX>(); 
00602   //iret |= compare( rzyx == rrr2, 1,"gen Rotation()",1 );
00603   iret |= compare( rzyx.Phi() , rrr2.Phi(),"gen Rotation() Phi",1 );
00604   iret |= compare( rzyx.Theta(), rrr2.Theta(),"gen Rotation() Theta",10 );
00605   iret |= compare( rzyx.Psi(), rrr2.Psi(),"gen Rotation() Psi",1 );
00606   if (iret) std::cout << rzyx << "\n---\n" << rrr2 << std::endl;
00607 
00608 
00609   //std::cout << t2 << std::endl; 
00610   //std::cout << t3 << std::endl; 
00611 
00612   XYZPoint p1(-1.,2.,-3);
00613   
00614   XYZPoint p2 = t2 (p1); 
00615   Polar3DPoint p3 = t3 ( Polar3DPoint(p1) ); 
00616   iret |= compare(p3.X(), p2.X(),"x diff",10 );
00617   iret |= compare(p3.Y(), p2.Y(),"y diff",10 );
00618   iret |= compare(p3.Z(), p2.Z(),"z diff",10 );
00619 
00620   GlobalXYZVector v1(1.,2.,3.);
00621   LocalXYZVector v2;  t2.Transform (v1, v2); 
00622   GlobalPolar3DVector v3;  t3.Transform ( GlobalPolar3DVector(v1), v3 ); 
00623 
00624   iret |= compare(v3.X(), v2.X(),"x diff",10 );
00625   iret |= compare(v3.Y(), v2.Y(),"y diff",10 );
00626   iret |= compare(v3.Z(), v2.Z(),"z diff",10 );
00627 
00628   XYZPoint q1(1,2,3);
00629   XYZPoint q2(-1,-2,-3);
00630   XYZPoint q3 = q1 +  XYZVector(q2);
00631   //std::cout << q3 << std::endl; 
00632   XYZPoint qt3 = t3(q3); 
00633   //std::cout << qt3 << std::endl; 
00634   XYZPoint qt1 = t3(q1);
00635   XYZVector vt2 = t3( XYZVector(q2) );
00636   XYZPoint qt4 = qt1 + vt2; 
00637   iret |= compare(qt3.X(), qt4.X(),"x diff",10 );
00638   iret |= compare(qt3.Y(), qt4.Y(),"y diff",10 );
00639   iret |= compare(qt3.Z(),  qt4.Z(),"z diff",10 );
00640      //std::cout << qt4 << std::endl; 
00641 
00642   // this fails
00643 //  double a = 3;
00644   //XYZPoint q4 = a*q1;
00645 //   std::cout << t3( a * q1) << std::endl;
00646 //   std::cout << a * t3(q1) << std::endl;
00647 
00648   // test get/set with a matrix
00649 #ifndef NO_SMATRIX
00650   SMatrix<double,3,4> mat; 
00651   t3.GetTransformMatrix(mat);
00652   Transform3D t3b;  t3b.SetTransformMatrix(mat); 
00653   iret |= compare( (t3==t3b),true,"Get/SetTransformMatrix");
00654 
00655   // test LR 
00656   Boost b(0.2,0.4,0.8); 
00657   LorentzRotation lr(b); 
00658   SMatrix<double,4> mat4; 
00659   lr.GetRotationMatrix(mat4);
00660   LorentzRotation lr2;  lr2.SetRotationMatrix(mat4); 
00661   iret |= compare( (lr==lr2),true,"Get/SetLRotMatrix");
00662 #endif
00663 
00664 
00665   if (iret == 0) std::cout << "OK\n"; 
00666   else std::cout << "\t\t\tFAILED\n"; 
00667 
00668   return iret; 
00669 }
00670 
00671 
00672 int testVectorUtil() { 
00673 
00674   std::cout << "testing VectorUtil  \t:\t"; 
00675    int iret = 0;
00676 
00677    // test new perp functions
00678    XYZVector v(1.,2.,3.); 
00679 
00680    XYZVector vx = ProjVector(v,XYZVector(3,0,0) );
00681    iret |= compare(vx.X(), v.X(),"x",1 );
00682    iret |= compare(vx.Y(), 0,"y",1 );
00683    iret |= compare(vx.Z(), 0,"z",1 );
00684 
00685    XYZVector vpx = PerpVector(v,XYZVector(2,0,0) );
00686    iret |= compare(vpx.X(), 0,"x",1 );
00687    iret |= compare(vpx.Y(), v.Y(),"y",1 );
00688    iret |= compare(vpx.Z(), v.Z(), "z",1 );
00689 
00690    double perpy = Perp(v, XYZVector(0,2,0) );  
00691    iret |= compare(perpy, std::sqrt( v.Mag2() - v.y()*v.y()),"perpy" );
00692 
00693    XYZPoint  u(1,1,1); 
00694    XYZPoint  un = u/u.R(); 
00695    
00696 
00697    XYZVector vl = ProjVector(v,u);
00698    XYZVector vl2 = XYZVector(un) * ( v.Dot(un ) ); 
00699 
00700    iret |= compare(vl.X(), vl2.X(),"x",1 );
00701    iret |= compare(vl.Y(), vl2.Y(),"y",1 );
00702    iret |= compare(vl.Z(), vl2.Z(),"z",1 );
00703 
00704    XYZVector vp = PerpVector(v,u);
00705    XYZVector vp2 = v - XYZVector ( un * ( v.Dot(un ) ) ); 
00706    iret |= compare(vp.X(), vp2.X(),"x",10 );
00707    iret |= compare(vp.Y(), vp2.Y(),"y",10 );
00708    iret |= compare(vp.Z(), vp2.Z(),"z",10 );
00709 
00710    double perp = Perp(v,u);
00711    iret |= compare(perp, vp.R(),"perp",1 );
00712    double perp2 = Perp2(v,u);
00713    iret |= compare(perp2, vp.Mag2(),"perp2",1 );
00714 
00715   if (iret == 0) std::cout << "\t\t\t\tOK\n"; 
00716   else std::cout << "\t\t\t\t\t\tFAILED\n"; 
00717   return iret; 
00718 
00719 }
00720 
00721 int testGenVector() { 
00722 
00723   int iret = 0; 
00724   iret |= testVector3D(); 
00725   iret |= testPoint3D(); 
00726 
00727   iret |= testVector2D(); 
00728   iret |= testPoint2D(); 
00729 
00730   iret |= testRotations3D(); 
00731 
00732   iret |= testTransform3D();
00733 
00734   iret |= testVectorUtil();
00735 
00736 
00737   if (iret !=0) std::cout << "\nTest GenVector FAILED!!!!!!!!!\n";
00738   return iret; 
00739 
00740 }
00741 
00742 int main() { 
00743    int ret = testGenVector();
00744    if (ret)  std::cerr << "test FAILED !!! " << std::endl; 
00745    else   std::cout << "test OK " << std::endl;
00746    return ret;
00747 }

Generated on Tue Jul 5 14:33:12 2011 for ROOT_528-00b_version by  doxygen 1.5.1