HepMC Reference Documentation

HepMC

testSimpleVector.cc

Go to the documentation of this file.
00001 //
00002 // First pass - simply exercise all the vector methods
00003 //
00004 #include <iostream>
00005 
00006 #include "HepMC/SimpleVector.h"
00007 
00008 int main() 
00009 {
00010   // ThreeVector
00011   HepMC::ThreeVector vector3;
00012   HepMC::ThreeVector v3(1.1,2.2,3.3);
00013   HepMC::ThreeVector vx(1.34);
00014   
00015   HepMC::ThreeVector v3copy( v3 );
00016    
00017   double eps = 1.e-15; // allowed differnce between doubles
00018   int numbad = 0;
00019  
00020   double x = v3.x();
00021   double y = v3.y();
00022   double z = v3.z();
00023   double p2 = v3.perp2();
00024   double pt = v3.perp();
00025   double r = v3.r();
00026   double th = v3.theta();
00027   double ph = v3.phi();
00028   double mag = std::sqrt(x*x + y*y + z*z);
00029   double pperp = std::sqrt(x*x + y*y);
00030 
00031   vx.set(1., 2., 3.);
00032   vx.setX(1.1);
00033   vx.setY(2.3);
00034   vx.setZ(4.4);
00035   vx.setPhi(0.12);
00036   vx.setTheta(0.54);
00037   
00038   vector3 = v3;
00039 
00040   if( fabs( mag - r ) > eps ) { 
00041      std::cout << "different ThreeVector magnitude: " << mag << " " << r << std::endl;
00042      std::cout << "difference is : " << ( mag - r ) << std::endl;
00043      ++numbad;
00044   }
00045   if( fabs( pperp - pt ) > eps ) { 
00046      std::cout << "different ThreeVector Pt: " << pperp << " " << pt << std::endl;
00047      std::cout << "difference is : " << ( pperp - pt ) << std::endl;
00048      ++numbad;
00049   }
00050 
00051   if( v3 == vector3 ) {
00052   } else {
00053      ++numbad;
00054      std::cout << "vectors v3 and vector3 are different" << std::endl;
00055   }
00056   if( v3 != v3copy ) {
00057      ++numbad;
00058      std::cout << "vectors v3 and v3copy are different" << std::endl;
00059   }
00060  
00061   // FourVector
00062   HepMC::FourVector vector;
00063   HepMC::FourVector v4(1.1,2.2,3.3,4.4);
00064   HepMC::FourVector vt(1.34);
00065   
00066   HepMC::FourVector vectorcopy( v4 );
00067   vector = v4;
00068   
00069   double px = v4.px();
00070   double py = v4.py();
00071   double pz = v4.pz();
00072   double e  = v4.e();
00073    x = vectorcopy.x();
00074    y = vectorcopy.y();
00075    z = vectorcopy.z();
00076   double t = vectorcopy.t();
00077   
00078    p2 = v4.perp2();
00079    pt = v4.perp();
00080    th = v4.theta();
00081    ph = v4.phi();
00082    r = v4.rho();
00083   double masssq1 = v4.m2();
00084   double mass1 = v4.m();
00085   double pr1 = v4.pseudoRapidity();
00086   double eta1 = v4.eta();
00087   double masssq2 = vector.m2();
00088   double mass2 = vector.m();
00089   double pr2 = vector.pseudoRapidity();
00090   double eta2 = vector.eta();
00091 
00092   vt.set(1., 2., 3., 5.5);
00093   vt.setX(1.1);
00094   vt.setY(2.3);
00095   vt.setZ(4.4);
00096   vt.setT(6.5);
00097   vt.setPx(3.1);
00098   vt.setPy(2.2);
00099   vt.setPz(-1.1);
00100   vt.setE(5.4);
00101 
00102   mag = std::sqrt(x*x + y*y + z*z);
00103   pperp = std::sqrt(x*x + y*y);
00104   if( fabs( mag - r ) > eps ) { 
00105      std::cout << "different FourVector magnitude: " << mag << " " << r << std::endl;
00106      std::cout << "difference is : " << ( mag - r ) << std::endl;
00107      ++numbad;
00108   }
00109   if( fabs( pperp - pt ) > eps ) { 
00110      std::cout << "different FourVector Pt: " << pperp << " " << pt << std::endl;
00111      std::cout << "difference is : " << ( pperp - pt ) << std::endl;
00112      ++numbad;
00113   }
00114 
00115   if( px != x ) { 
00116      std::cout << "different X values: " << px << " " << x << std::endl;
00117      ++numbad;
00118   }
00119   if( py != y ) { 
00120      std::cout << "different Y values: " << py << " " << y << std::endl;
00121      ++numbad;
00122   }
00123   if( pz != z ) { 
00124      std::cout << "different Z values: " << pz << " " << z << std::endl;
00125      ++numbad;
00126   }
00127   if( e != t ) { 
00128      std::cout << "different E values: " << e << " " << t << std::endl;
00129      ++numbad;
00130   }
00131   if( fabs( masssq1 - masssq2 ) > eps ) { 
00132      std::cout << "different mass sq values: " << masssq1 << " " << masssq2 << std::endl;
00133      std::cout << "difference is : " << ( masssq1 - masssq2 ) << std::endl;
00134      ++numbad;
00135   }
00136   if( fabs( mass1 - mass2 ) > eps ) { 
00137      std::cout << "different mass values: " << mass1 << " " << mass2 << std::endl;
00138      std::cout << "difference is : " << ( mass1 - mass2 ) << std::endl;
00139      ++numbad;
00140   }
00141   if( fabs( pr1 - pr2 ) > eps ) { 
00142      std::cout << "different pseudorapidity values: " << pr1 << " " << pr2 << std::endl;
00143      std::cout << "difference is : " << ( pr1 - pr2 ) << std::endl;
00144      ++numbad;
00145   }
00146   if( fabs( eta1 - eta2 ) > eps ) { 
00147      std::cout << "different eta values: " << eta1 << " " << eta2 << std::endl;
00148      std::cout << "difference is : " << ( eta1 - eta2 ) << std::endl;
00149      ++numbad;
00150   }
00151   if( v4 == vector ) {
00152   } else {
00153      std::cout << "vectors v and vector are different" << std::endl;
00154      ++numbad;
00155   }
00156   if( v4 != vectorcopy ) {
00157      std::cout << "vectors v and vectorcopy are different" << std::endl;
00158      ++numbad;
00159   }
00160 
00161   return numbad;
00162 }

Generated on Thu Jan 7 13:10:16 2010 for HepMC by  doxygen 1.4.7