CLHEP 2.0.4.7 Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
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/Vector/defs.h" 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 xx, double xy, double xz, 00025 double yx, double yy, double yz, 00026 double zx, double zy, double zz) { 00027 rxx = xx; rxy = xy; rxz = xz; 00028 ryx = yx; ryy = yy; ryz = yz; 00029 rzx = zx; rzy = zy; rzz = zz; 00030 } 00031 }; 00032 00033 class Rot4 : public HepLorentzRotation { 00034 public: 00035 void setMatrix(double xx, double xy, double xz, double xt, 00036 double yx, double yy, double yz, double yt, 00037 double zx, double zy, double zz, double zt, 00038 double tx, double ty, double tz, double tt) { 00039 mxx = xx; mxy = xy; mxz = xz; mxt = xt; 00040 myx = yx; myy = yy; myz = yz; myt = yt; 00041 mzx = zx; mzy = zy; mzz = zz; mzt = zt; 00042 mtx = tx; mty = ty; mtz = tz; mtt = tt; 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 }