26 std::vector<double> dataX;
27 std::vector<double> dataY;
28 std::vector<double> dataZ;
34 VectorTest(
int n1,
int n2) :
37 dataX(
std::vector<double>(n2)),
38 dataY(
std::vector<double>(n2)),
39 dataZ(
std::vector<double>(n2))
46 int pr = std::cout.precision(8);
47 std::cout << s <<
"\t" <<
" time = " << time.
RealTime() <<
"\t(sec)\t" 50 std::cout.precision(pr);
54 int check(std::string
name,
double s1,
double s2,
double s3,
double scale=1) {
57 std::cout.precision(16);
58 std::cout << s1 <<
"\t" << s2 <<
"\t" << s3 <<
"\n";
59 std::cout <<
"Test " << name <<
" failed !!\n\n";
69 for (
int i = 0; i <
n ; ++ i) {
71 double phi = r.
Rndm()*3.1415926535897931;
73 double pt = r.
Exp(10.);
88 void testCreate( std::vector<V *> & dataV,
TStopwatch & tim,
double& t, std::string s) {
93 for (
int i = 0; i <
n; ++i) {
94 dataV[i] =
new V( dataX[i], dataY[i], dataZ[i] );
103 double testVectorAddition(
const std::vector<V *> & dataV,
TStopwatch & tim,
double& t, std::string s) {
104 unsigned int n = std::min(n2Loop, dataV.size() );
106 V vSum = *(dataV[0]);
107 for (
unsigned int i = 1; i <
n; ++i) {
117 double testPointAddition(
const std::vector<P *> & dataP,
TStopwatch & tim,
double& t, std::string s) {
118 unsigned int n = std::min(n2Loop, dataP.size() );
120 P pSum = *(dataP[0]);
121 for (
unsigned int i = 1; i <
n; ++i) {
122 P &
p2 = *(dataP[i]);
123 #ifndef HEAP_CREATION 138 return v.x() + v.y() + v.z();
144 double testTranslation( std::vector<V *> & dataV,
const Translation3D & tr,
TStopwatch & tim,
double& t, std::string s) {
146 unsigned int n = dataV.size();
152 for (
unsigned int i = 0; i <
n; ++i) {
153 V & v1 = *(dataV[i]);
164 template <
class V,
class T>
165 double testTransform( std::vector<V *> & dataV,
const T & trans,
TStopwatch & tim,
double& t, std::string s) {
167 unsigned int n = dataV.size();
170 for (
unsigned int i = 0; i <
n; ++i) {
171 V & v1 = *(dataV[i]);
182 template <
class V,
class T1,
class T2>
183 double testTransformProd( std::vector<V *> & dataV,
const T1 & trans,
const T2 &,
TStopwatch & tim,
double& t, std::string s) {
185 unsigned int n = dataV.size();
188 for (
unsigned int i = 0; i <
n; ++i) {
189 V & v1 = *(dataV[i]);
200 template <
class V,
class T1,
class T2>
201 double testTransformProd2( std::vector<V *> & dataV,
const T1 & trans,
const T2 &,
TStopwatch & tim,
double& t, std::string s) {
203 unsigned int n = dataV.size();
206 for (
unsigned int i = 0; i <
n; ++i) {
207 V & v1 = *(dataV[i]);
218 template <
class V,
class T1,
class T2>
219 double testTransformProd3( std::vector<V *> & dataV,
const T1 & trans1,
const T2 & trans2,
TStopwatch & tim,
double& t, std::string s) {
221 unsigned int n = dataV.size();
224 for (
unsigned int i = 0; i <
n; ++i) {
225 V & v1 = *(dataV[i]);
226 V v2 = trans2 * trans1 * v1;
238 int main(
int argc,
const char *argv[]) {
241 if (argc > 1) ngen = atoi(argv[1]);
243 if (argc > 2) nloop2 = atoi(argv[1]);
245 std::cout <<
"Test with Ngen = " << ngen <<
" n2loop = " << nloop2 << std::endl;
249 VectorTest
a(ngen,nloop2);
258 std::vector<TVector3 *> v1;
259 std::vector<ROOT::Math::XYZVector *> v2;
260 std::vector<ROOT::Math::XYZPoint *> v3;
265 a.testCreate (v2, t, t2,
"creation XYZVector " );
268 a.testCreate (v3, t, t3,
"creation XYZPoint " );
271 a.testCreate (v1, t, t1,
"creation TVector3 " );
276 s1=a.testVectorAddition (v1, t, t1,
"Addition TVector3 " );
277 s2=a.testVectorAddition (v2, t, t2,
"Addition XYZVector " );
278 s3=a.testPointAddition (v3, t, t3,
"Addition XYZPoint " );
280 a.check(
"Addition",s1,s2,s3);
284 s2=a.testVectorAddition (v2, t, t2,
"Addition XYZVector " );
285 s1=a.testVectorAddition (v1, t, t1,
"Addition TVector3 " );
286 s3=a.testPointAddition (v3, t, t3,
"Addition XYZPoint " );
288 s2=a.testVectorAddition (v2, t, t2,
"Addition XYZVector " );
289 s3=a.testPointAddition (v3, t, t3,
"Addition XYZPoint " );
290 s1=a.testVectorAddition (v1, t, t1,
"Addition TVector3 " );
292 s1=a.testVectorAddition (v1, t, t1,
"Addition TVector3 " );
293 s3=a.testPointAddition (v3, t, t3,
"Addition XYZPoint " );
294 s2=a.testVectorAddition (v2, t, t2,
"Addition XYZVector " );
296 s3=a.testPointAddition (v3, t, t3,
"Addition XYZPoint " );
297 s2=a.testVectorAddition (v2, t, t2,
"Addition XYZVector " );
298 s1=a.testVectorAddition (v1, t, t1,
"Addition TVector3 " );
300 s3=a.testPointAddition (v3, t, t3,
"Addition XYZPoint " );
301 s1=a.testVectorAddition (v1, t, t1,
"Addition TVector3 " );
302 s2=a.testVectorAddition (v2, t, t2,
"Addition XYZVector " );
311 s1=a.testTransform (v1, r1, t, t1,
"TRotation TVector3 " );
312 s2=a.testTransform (v2, r2, t, t2,
"Rotation3D XYZVector " );
313 s3=a.testTransform (v3, r2, t, t3,
"Rotation3D XYZPoint " );
315 a.check(
"Rotation3D",s1,s2,s3);
322 s1=a.testTranslation (v1, tr, t, t1,
"Shift TVector3 " );
323 s2=a.testTranslation (v2, tr, t, t2,
"Shift XYZVector " );
324 s3=a.testTransform (v3, tr, t, t3,
"Translation3D XYZPoint " );
325 s4=a.testTransform (v2, tr, t, t0,
"Translation3D XYZVector " );
327 a.check(
"Translation3D",s1,s2,s3);
333 s2=a.testTransform (v2, tf, t, t0,
"Transform3D XYZVector " );
334 s3=a.testTransform (v3, tf, t, t0,
"Transform3D XYZPoint " );
345 s2=a.testTransformProd (v2, r2, tr, t, t0,
"Delta * Rot XYZVector " );
346 s3=a.testTransformProd (v3, r2, tr, t, t0,
"Delta * Rot XYZPoint " );
349 s4=a.testTransformProd (v2, tfr, tf, t, t0,
"Delta * Rot(T) XYZVector " );
350 s5=a.testTransformProd (v3, tfr, tf, t, t0,
"Delta * Rot(T) XYZPoint " );
351 a.check(
"Delta * Rot",s3,s5,s5);
353 a.check(
"Trans Vec",s2a,s2b,s2);
354 a.check(
"Trans Vec",s2a,s2,s4);
361 s2=a.testTransformProd2 (v2, r2, tr, t, t0,
"Rot * Delta XYZVector " );
362 s3=a.testTransformProd2 (v3, r2, tr, t, t0,
"Rot * Delta XYZPoint " );
364 s4=a.testTransformProd2 (v2, tfr, tf, t, t0,
"Rot * Delta(T) XYZVector " );
365 s5=a.testTransformProd2 (v3, tfr, tf, t, t0,
"Rot * Delta(T) XYZPoint " );
367 a.check(
"Rot * Delta",s3,s5,s5);
369 a.check(
"Trans Vec",s2a,s2,s4);
373 s2=a.testTransformProd (v2, tf,
Translation3D(), t, t0,
"Delta * Trans XYZVector " );
374 s3=a.testTransformProd (v3, tf,
Translation3D(), t, t0,
"Delta * Trans XYZPoint " );
375 s4=a.testTransformProd (v2, tf,
Transform3D(), t, t0,
"TDelta * Trans XYZVector " );
376 s5=a.testTransformProd (v3, tf,
Transform3D(), t, t0,
"TDelta * Trans XYZPoint " );
377 a.check(
"Delta * Trans",s3,s5,s5);
378 a.check(
"Delta * Trans Vec",s2a,s2,s4);
381 s2=a.testTransformProd2 (v2, tf,
Translation3D(), t, t0,
"Trans * Delta XYZVector " );
382 s3=a.testTransformProd2 (v3, tf,
Translation3D(), t, t0,
"Trans * Delta XYZPoint " );
383 s4=a.testTransformProd2 (v2, tf,
Transform3D(), t, t0,
"Trans * TDelta XYZVector " );
384 s5=a.testTransformProd2 (v3, tf,
Transform3D(), t, t0,
"Trans * TDelta XYZPoint " );
385 a.check(
"Delta * Trans",s3,s5,s5);
386 a.check(
"Delta * Trans Vec",s2a,s2,s4);
389 s2=a.testTransformProd (v2, tf,
Translation3D(), t, t0,
"Delta * Trans XYZVector " );
390 s3=a.testTransformProd (v3, tf,
Translation3D(), t, t0,
"Delta * Trans XYZPoint " );
391 s4=a.testTransformProd (v2, tf,
Transform3D(), t, t0,
"TDelta * Trans XYZVector " );
392 s5=a.testTransformProd (v3, tf,
Transform3D(), t, t0,
"TDelta * Trans XYZPoint " );
393 a.check(
"Delta * Trans",s3,s5,s5);
394 a.check(
"Delta * Trans Vec",s2a,s2,s4);
397 s2=a.testTransformProd2 (v2, tf,
Translation3D(), t, t0,
"Trans * Delta XYZVector " );
398 s3=a.testTransformProd2 (v3, tf,
Translation3D(), t, t0,
"Trans * Delta XYZPoint " );
399 s4=a.testTransformProd2 (v2, tf,
Transform3D(), t, t0,
"Trans * TDelta XYZVector " );
400 s5=a.testTransformProd2 (v3, tf,
Transform3D(), t, t0,
"Trans * TDelta XYZPoint " );
401 a.check(
"Delta * Trans",s3,s5,s5);
402 a.check(
"Delta * Trans Vec",s2a,s2,s4);
405 s1=a.testTransformProd3 (v1, r2, r2, t, t0,
"Rot * Rot TVector3 " );
406 s2=a.testTransformProd3 (v2, r2, r2, t, t0,
"Rot * Rot XYZVector " );
407 s3=a.testTransformProd3 (v3, r2, r2, t, t0,
"Rot * Rot XYZPoint " );
408 a.check(
"Rot * Rot",s1,s2,s3);
413 s2=a.testTransformProd3 (v2, tf, r2, t, t0,
"Rot * Trans XYZVector " );
414 s3=a.testTransformProd3 (v3, tf, r2, t, t0,
"Rot * Trans XYZPoint " );
415 s4=a.testTransformProd3 (v2, tf,
Transform3D(r2), t, t0,
"TRot * Trans XYZVector " );
416 s5=a.testTransformProd3 (v3, tf,
Transform3D(r2), t, t0,
"TRot * Trans XYZPoint " );
417 a.check(
"Rot * Trans Pnt",s3,s5,s5);
418 a.check(
"Rot * Trans Vec",s2a,s2,s4);
422 s2=a.testTransformProd3 (v2, r2, tf, t, t0,
"Trans * Rot XYZVector " );
423 s3=a.testTransformProd3 (v3, r2, tf, t, t0,
"Trans * Rot XYZPoint " );
424 s4=a.testTransformProd3 (v2,
Transform3D(r2), tf, t, t0,
"Trans * TRot XYZVector " );
425 s5=a.testTransformProd3 (v3,
Transform3D(r2), tf, t, t0,
"Trans * TRot XYZPoint " );
427 a.check(
"Rot * Trans Pnt",s3,s5,s5);
428 a.check(
"Rot * Trans Vec",s2a,s2,s4);
432 std::cout <<
"Total Time for TVector3 = " << t1 <<
"\t(sec)" << std::endl;
433 std::cout <<
"Total Time for XYZVector = " << t2 <<
"\t(sec)" << std::endl;
434 std::cout <<
"Total Time for XYZPoint = " << t3 <<
"\t(sec)" << std::endl;
static long int sum(long int i)
Random number generator class based on M.
Double_t RealTime()
Stop the stopwatch (if it is running) and return the realtime (in seconds) passed between the start a...
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
virtual Double_t Rndm()
Machine independent random number generator.
TRotation & RotateZ(Double_t)
Rotate around z.
void GetComponents(IT begin, IT end) const
Get the 3 components into data specified by an iterator begin and another to the end of the desired d...
TRotation & RotateX(Double_t)
Rotate around x.
Rotation class with the (3D) rotation represented by angles describing first a rotation of an angle p...
void Stop()
Stop the stopwatch.
int main(int argc, const char *argv[])
static double p2(double t, double a, double b, double c)
int getSum(const int *x, int n)
The TRotation class describes a rotation of objects of the TVector3 class.
Class describing a generic displacement vector in 3 dimensions.
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
unsigned int r1[N_CITIES]
Rotation class with the (3D) rotation represented by a 3x3 orthogonal matrix.
Class describing a 3 dimensional translation.
TRotation & RotateY(Double_t)
Rotate around y.
virtual Double_t Uniform(Double_t x1=1)
Returns a uniform deviate on the interval (0, x1).
DisplacementVector3D< Cartesian3D< double >, DefaultCoordinateSystemTag > XYZVector
3D Vector based on the cartesian coordinates x,y,z in double precision
unsigned int r2[N_CITIES]
virtual Double_t Exp(Double_t tau)
Returns an exponential deviate.