StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
testSimpleVector.cc
1 //
2 // First pass - simply exercise all the vector methods
3 //
4 #include <iostream>
5 
6 #include "HepMC/SimpleVector.h"
7 
8 int main()
9 {
10  // ThreeVector
12  HepMC::ThreeVector v3(1.1,2.2,3.3);
13  HepMC::ThreeVector vx(1.34);
14 
15  HepMC::ThreeVector v3copy( v3 );
16 
17  double eps = 1.e-15; // allowed differnce between doubles
18  int numbad = 0;
19 
20  double x = v3.x();
21  double y = v3.y();
22  double z = v3.z();
23  double p2 = v3.perp2();
24  double pt = v3.perp();
25  double r = v3.r();
26  double th = v3.theta();
27  double ph = v3.phi();
28  double mag = std::sqrt(x*x + y*y + z*z);
29  double pperp = std::sqrt(x*x + y*y);
30 
31  vx.set(1., 2., 3.);
32  vx.setX(1.1);
33  vx.setY(2.3);
34  vx.setZ(4.4);
35  vx.setPhi(0.12);
36  vx.setTheta(0.54);
37 
38  vector3 = v3;
39 
40  if( fabs( mag - r ) > eps ) {
41  std::cout << "different ThreeVector magnitude: " << mag << " " << r << std::endl;
42  std::cout << "difference is : " << ( mag - r ) << std::endl;
43  ++numbad;
44  }
45  if( fabs( pperp - pt ) > eps ) {
46  std::cout << "different ThreeVector Pt: " << pperp << " " << pt << std::endl;
47  std::cout << "difference is : " << ( pperp - pt ) << std::endl;
48  ++numbad;
49  }
50 
51  if( v3 == vector3 ) {
52  } else {
53  ++numbad;
54  std::cout << "vectors v3 and vector3 are different" << std::endl;
55  }
56  if( v3 != v3copy ) {
57  ++numbad;
58  std::cout << "vectors v3 and v3copy are different" << std::endl;
59  }
60 
61  // FourVector
62  HepMC::FourVector vector;
63  HepMC::FourVector v4(1.1,2.2,3.3,4.4);
64  HepMC::FourVector vt(1.34);
65 
66  HepMC::FourVector vectorcopy( v4 );
67  vector = v4;
68 
69  double px = v4.px();
70  double py = v4.py();
71  double pz = v4.pz();
72  double e = v4.e();
73  x = vectorcopy.x();
74  y = vectorcopy.y();
75  z = vectorcopy.z();
76  double t = vectorcopy.t();
77 
78  p2 = v4.perp2();
79  pt = v4.perp();
80  th = v4.theta();
81  ph = v4.phi();
82  r = v4.rho();
83  double masssq1 = v4.m2();
84  double mass1 = v4.m();
85  double pr1 = v4.pseudoRapidity();
86  double eta1 = v4.eta();
87  double masssq2 = vector.m2();
88  double mass2 = vector.m();
89  double pr2 = vector.pseudoRapidity();
90  double eta2 = vector.eta();
91 
92  vt.set(1., 2., 3., 5.5);
93  vt.setX(1.1);
94  vt.setY(2.3);
95  vt.setZ(4.4);
96  vt.setT(6.5);
97  vt.setPx(3.1);
98  vt.setPy(2.2);
99  vt.setPz(-1.1);
100  vt.setE(5.4);
101 
102  mag = std::sqrt(x*x + y*y + z*z);
103  pperp = std::sqrt(x*x + y*y);
104  if( fabs( mag - r ) > eps ) {
105  std::cout << "different FourVector magnitude: " << mag << " " << r << std::endl;
106  std::cout << "difference is : " << ( mag - r ) << std::endl;
107  ++numbad;
108  }
109  if( fabs( pperp - pt ) > eps ) {
110  std::cout << "different FourVector Pt: " << pperp << " " << pt << std::endl;
111  std::cout << "difference is : " << ( pperp - pt ) << std::endl;
112  ++numbad;
113  }
114 
115  if( px != x ) {
116  std::cout << "different X values: " << px << " " << x << std::endl;
117  ++numbad;
118  }
119  if( py != y ) {
120  std::cout << "different Y values: " << py << " " << y << std::endl;
121  ++numbad;
122  }
123  if( pz != z ) {
124  std::cout << "different Z values: " << pz << " " << z << std::endl;
125  ++numbad;
126  }
127  if( e != t ) {
128  std::cout << "different E values: " << e << " " << t << std::endl;
129  ++numbad;
130  }
131  if( fabs( masssq1 - masssq2 ) > eps ) {
132  std::cout << "different mass sq values: " << masssq1 << " " << masssq2 << std::endl;
133  std::cout << "difference is : " << ( masssq1 - masssq2 ) << std::endl;
134  ++numbad;
135  }
136  if( fabs( mass1 - mass2 ) > eps ) {
137  std::cout << "different mass values: " << mass1 << " " << mass2 << std::endl;
138  std::cout << "difference is : " << ( mass1 - mass2 ) << std::endl;
139  ++numbad;
140  }
141  if( fabs( pr1 - pr2 ) > eps ) {
142  std::cout << "different pseudorapidity values: " << pr1 << " " << pr2 << std::endl;
143  std::cout << "difference is : " << ( pr1 - pr2 ) << std::endl;
144  ++numbad;
145  }
146  if( fabs( eta1 - eta2 ) > eps ) {
147  std::cout << "different eta values: " << eta1 << " " << eta2 << std::endl;
148  std::cout << "difference is : " << ( eta1 - eta2 ) << std::endl;
149  ++numbad;
150  }
151  if( v4 == vector ) {
152  } else {
153  std::cout << "vectors v and vector are different" << std::endl;
154  ++numbad;
155  }
156  if( v4 != vectorcopy ) {
157  std::cout << "vectors v and vectorcopy are different" << std::endl;
158  ++numbad;
159  }
160 
161  return numbad;
162 }
double m() const
Invariant mass. If m2() is negative then -sqrt(-m2()) is returned.
double px() const
return px
Definition: SimpleVector.h:70
ThreeVector is a simple representation of a position or displacement 3 vector.
Definition: SimpleVector.h:131
double eta() const
Pseudorapidity (of the space part)
FourVector is a simple representation of a physics 4 vector.
Definition: SimpleVector.h:42
double m2() const
Invariant mass squared.
double pseudoRapidity() const
Returns the pseudo-rapidity, i.e. -ln(tan(theta/2))