CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

testSubscripts.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // $Id: testSubscripts.cc,v 1.2 2003/08/13 20:00:14 garren Exp $
00003 // ---------------------------------------------------------------------------
00004 //
00005 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
00006 //
00007 // This is a small program for testing of subscriping in the Vector module.
00008 //
00009 
00010 #include <assert.h>
00011 #include "CLHEP/Units/GlobalSystemOfUnits.h"    // to see shadowing problems
00012 #include "CLHEP/Vector/ThreeVector.h"
00013 #include "CLHEP/Vector/Rotation.h"
00014 #include "CLHEP/Vector/LorentzVector.h"
00015 #include "CLHEP/Vector/LorentzRotation.h"
00016 
00017 using namespace CLHEP;
00018 
00019 typedef Hep3Vector       Vec3;
00020 typedef HepLorentzVector Vec4;
00021 
00022 class Rot3 : public HepRotation {
00023 public:  
00024   void setMatrix(double xx1, double xy1, double xz1,
00025                  double yx1, double yy1, double yz1,
00026                  double zx1, double zy1, double zz1) {
00027     rxx = xx1; rxy = xy1; rxz = xz1;
00028     ryx = yx1; ryy = yy1; ryz = yz1;
00029     rzx = zx1; rzy = zy1; rzz = zz1;
00030   }
00031 };
00032 
00033 class Rot4 : public HepLorentzRotation {
00034 public:  
00035   void setMatrix(double xx1, double xy1, double xz1, double xt1,
00036                  double yx1, double yy1, double yz1, double yt1,
00037                  double zx1, double zy1, double zz1, double zt1,
00038                  double tx1, double ty1, double tz1, double tt1) {
00039     mxx = xx1; mxy = xy1; mxz = xz1; mxt = xt1;
00040     myx = yx1; myy = yy1; myz = yz1; myt = yt1;
00041     mzx = zx1; mzy = zy1; mzz = zz1; mzt = zt1;
00042     mtx = tx1; mty = ty1; mtz = tz1; mtt = tt1;
00043   }
00044 };
00045 
00046 int main() {
00047 
00048   // Test ThreeVector subscripting
00049 
00050   Vec3  V3;
00051   const Vec3 ConstV3(1.,2.,3.);
00052 
00053   V3[0] = ConstV3[0];
00054   V3[1] = ConstV3[1];
00055   V3[2] = ConstV3[2];
00056   assert(V3 == ConstV3);
00057 
00058   V3(0) = ConstV3(2);
00059   V3(1) = ConstV3(1);
00060   V3(2) = ConstV3(0);
00061   assert(V3 == Hep3Vector(3.,2.,1.));
00062 
00063   // Test LorentzVector subscripting
00064 
00065   Vec4  V4;
00066   const Vec4 ConstV4(1.,2.,3.,4); 
00067 
00068   V4[0] = ConstV4[0];
00069   V4[1] = ConstV4[1];
00070   V4[2] = ConstV4[2];
00071   V4[3] = ConstV4[3];
00072   assert(V4 == ConstV4);
00073 
00074   V4(0) = ConstV4(3);
00075   V4(1) = ConstV4(2);
00076   V4(2) = ConstV4(1);
00077   V4(3) = ConstV4(0);
00078   assert(V4 == HepLorentzVector(4.,3.,2.,1.));
00079 
00080   // Test Rotation subscripting
00081 
00082   int  i, j, k;
00083   Rot3 R3;
00084 
00085   R3.setMatrix(1.,2.,3.,4.,5.,6.,7.,8.,9.);
00086 
00087   k = 1;
00088   for(i=0; i<3; i++) {
00089     for(j=0; j<3; j++) {
00090       assert(R3(i,j)  == double(k));
00091       assert(R3[i][j] == double(k));
00092       k++;
00093     }
00094   }
00095 
00096   // Test LorentzRotation subscripting
00097 
00098   Rot4 R4;
00099   R4.setMatrix(1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.);
00100 
00101   k = 1;
00102   for(i=0; i<4; i++) {
00103     for(j=0; j<4; j++) {
00104       assert(R4(i,j)  == double(k));
00105       assert(R4[i][j] == double(k));
00106       k++;
00107     }
00108   }
00109 
00110   return 0;
00111 }

Generated on 15 Nov 2012 for CLHEP by  doxygen 1.4.7