37 #include "CLHEP/Vector/TwoVector.h"
48 #define VSUM(v) v.x() + v.y()
50 #define VSUM(v) v.X() + v.Y()
54 #elif DIM_3 // 3 Dimensions
60 #include "CLHEP/Vector/ThreeVector.h"
71 #define VSUM(v) v.x() + v.y() + v.z()
73 #define VSUM(v) v.X() + v.Y() + v.Z()
76 #else // default is 4D
80 #include "CLHEP/Vector/LorentzVector.h"
81 typedef HepLorentzVector
VecType;
91 #define VSUM(v) v.x() + v.y() + v.z() + v.t()
93 #define VSUM(v) v.X() + v.Y() + v.Z() + v.T()
99 const int N = 1000000;
101 template<
class Vector>
119 std::vector<Vector> vlist;
120 std::vector<double> scale;
127 template<
class Vector>
128 TestVector<Vector>::TestVector() :
129 vlist(
std::vector<Vector>(N) ),
137 for (
int i = 0; i<
N; ++i) {
139 vlist[i] = Vector(
r.Uniform(-1,1),
r.Uniform(-1,1) );
141 vlist[i] = Vector(
r.Uniform(-1,1),
r.Uniform(-1,1),
r.Uniform(-1,1) );
143 vlist[i] = Vector(
r.Uniform(-1,1),
r.Uniform(-1,1),
r.Uniform(-1,1),
r.Uniform(2,10) );
145 scale[i] =
r.Uniform(0,1);
148 std::cout <<
"test using " <<
typeid(vlist[0]).
name() << std::endl;
151 template<
class Vector>
158 for (
int l = 0;
l<100; ++
l) {
159 for (
int i = 1; i<
N; ++i) {
160 Vector v3 = vlist[i-1] + vlist[i];
165 std::cout <<
"Time for v3 = v1 + v2 :\t" << w.
RealTime() <<
"\t" << w.
CpuTime() << std::endl;
166 std::cout <<
"value " << s << std::endl << std::endl;
170 template<
class Vector>
171 void TestVector<Vector>::Add2()
178 for (
int l = 0;
l<100; ++
l) {
179 for (
int i = 0; i<
N; ++i) {
185 std::cout <<
"Time for v2 += v1 :\t" << w.
RealTime() <<
"\t" << w.
CpuTime() << std::endl;
186 std::cout <<
"value " << s << std::endl << std::endl;
190 template<
class Vector>
191 void TestVector<Vector>::Sub()
197 for (
int l = 0;
l<100; ++
l) {
198 for (
int i = 1; i<
N; ++i) {
199 Vector v3 = vlist[i-1] - vlist[i];
204 std::cout <<
"Time for v3 = v1 - v2 :\t" << w.
RealTime() <<
"\t" << w.
CpuTime() << std::endl;
205 std::cout <<
"value " << s << std::endl << std::endl;
209 template<
class Vector>
210 void TestVector<Vector>::Sub2()
217 for (
int l = 0;
l<100; ++
l) {
218 for (
int i = 0; i<
N; ++i) {
224 std::cout <<
"Time for v2 -= v1 :\t" << w.
RealTime() <<
"\t" << w.
CpuTime() << std::endl;
225 std::cout <<
"value " << s << std::endl << std::endl;
230 template<
class Vector>
231 void TestVector<Vector>::Scale()
237 for (
int l = 0;
l<100; ++
l) {
238 for (
int i = 1; i<
N; ++i) {
239 Vector v3 = scale[i]*vlist[i];
244 std::cout <<
"Time for v2 = A * v1 :\t" << w.
RealTime() <<
"\t" << w.
CpuTime() << std::endl;
245 std::cout <<
"value " << s << std::endl << std::endl;
249 template<
class Vector>
250 void TestVector<Vector>::Scale2()
257 for (
int l = 0;
l<100; ++
l) {
258 for (
int i = 0; i<
N; ++i) {
265 std::cout <<
"Time for v *= a :\t" << w.
RealTime() <<
"\t" << w.
CpuTime() << std::endl;
266 std::cout <<
"value " << s << std::endl << std::endl;
270 template<
class Vector>
271 void TestVector<Vector>::Divide()
277 for (
int l = 0;
l<100; ++
l) {
278 for (
int i = 1; i<
N; ++i) {
279 Vector v3 = vlist[i]/scale[i];
284 std::cout <<
"Time for v2 = v1 / a :\t" << w.
RealTime() <<
"\t" << w.
CpuTime() << std::endl;
285 std::cout <<
"value " << s << std::endl << std::endl;
289 template<
class Vector>
290 void TestVector<Vector>::Divide2()
297 for (
int l = 0;
l<100; ++
l) {
298 for (
int i = 0; i<
N; ++i) {
305 std::cout <<
"Time for v /= a :\t" << w.
RealTime() <<
"\t" << w.
CpuTime() << std::endl;
306 std::cout <<
"value " << s << std::endl << std::endl;
311 template<
class Vector>
312 void TestVector<Vector>::PrintSummary()
314 std::cout <<
"\nResults for " <<
typeid(vlist[0]).
name() << std::endl;
315 std::cout <<
" v3 = v1+v2"
322 <<
" v1 /= a " << std::endl;
324 for (
int i = 0; i < fTest; ++i) {
325 std::cout << std::setw(8) << fTime[i] <<
" ";
327 std::cout << std::endl << std::endl;
331 TestVector<VecType> t;
Class describing a generic LorentzVector in the 4D space-time, using the specified coordinate system ...
Double_t RealTime()
Stop the stopwatch (if it is running) and return the realtime (in seconds) passed between the start a...
void Add(THist< DIMENSION, PRECISIONA > &to, THist< DIMENSION, PRECISIONB > &from)
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
Random number generator class based on the maximally quidistributed combined Tausworthe generator by ...
Class describing a generic position vector (point) in 3 dimensions.
Double_t CpuTime()
Stop the stopwatch (if it is running) and return the cputime (in seconds) passed between the start an...
Class describing a generic position vector (point) in 2 dimensions.
ROOT::Math::XYZTVector VecType
Class describing a generic displacement vector in 2 dimensions.