55 #include "CLHEP/Vector/TwoVector.h"
71 std::vector<double> dataX;
72 std::vector<double> dataY;
80 VectorTest(
int n1,
int n2) :
89 int pr = std::cout.precision(8);
90 std::cout << s <<
"\t" <<
" time = " << time.
RealTime() <<
"\t(sec)\t"
93 std::cout.precision(pr);
97 int check(std::string name,
double s1,
double s2,
double s3,
double scale=1) {
100 int pr = std::cout.precision(16);
101 std::cout << s1 <<
"\t" << s2 <<
"\t" << s3 <<
"\n";
102 std::cout <<
"Rel Diff 1-2:\t" << (s1-s2)/
std::fabs(s1) <<
" Diff 1-3:\t" << (s1-s3)/
std::fabs(s1) << std::endl;
103 std::cout <<
"Test " << name <<
" failed !!\n\n";
104 std::cout.precision(pr);
114 for (
int i = 0; i <
n ; ++ i) {
116 double phi = rdm.
Rndm()*3.1415926535897931;
117 double r = rdm.
Exp(10.);
121 dataX.push_back(
q.x() );
122 dataY.push_back(
q.y() );
130 void testCreate( std::vector<V *> & dataV,
TStopwatch & tim,
double& t, std::string s) {
132 int n = dataX.size();
135 for (
int i = 0; i <
n; ++i) {
136 dataV[i] =
new V( dataX[i], dataY[i] );
145 void testCreate2( std::vector<V *> & dataV,
TStopwatch & tim,
double& t, std::string s) {
147 int n = dataX.size();
150 for (
int i = 0; i <
n; ++i) {
152 dataV[i]->SetXY(dataX[i], dataY[i] );
158 void testCreate2( std::vector<TVector2 *> & dataV,
TStopwatch & tim,
double& t, std::string s) {
160 int n = dataX.size();
163 for (
int i = 0; i <
n; ++i) {
165 dataV[i]->Set(dataX[i], dataY[i] );
172 void testCreate2( std::vector<Hep2Vector *> & dataV,
TStopwatch & tim,
double& t, std::string s) {
174 int n = dataX.size();
177 for (
int i = 0; i <
n; ++i) {
178 dataV[i] =
new Hep2Vector();
179 dataV[i]->set(dataX[i], dataY[i] );
189 void clear( std::vector<V *> & dataV ) {
190 for (
unsigned int i = 0; i < dataV.size(); ++i) {
199 inline double addXY(
const V & v) {
200 return v.X() + v.Y();
206 inline double getSum(
const V & v1,
const V & v2) {
207 return v1.X()+v1.Y() + v2.X() + v2.Y();
211 return v1(0)+
v1(1) + v2(0)+v2(1);
215 inline double dotProd(
const V & v1,
const V & v2) {
229 inline double addXY(
const Hep2Vector & v) {
230 return v.x() + v.y();
232 inline double getSum(
const Hep2Vector & v1,
const Hep2Vector & v2 ) {
233 return v1.x() + v1.y() + v2.x() + v2.y();
238 double testAddition(
const std::vector<V *> & dataV,
TStopwatch & tim,
double& t, std::string s) {
239 unsigned int n = dataV.size();
243 for (
unsigned int i = 0; i <
n; ++i) {
244 V & v1 = *(dataV[i]);
255 double testAddition2(
const std::vector<V *> & dataV,
TStopwatch & tim,
double& t, std::string s) {
256 unsigned int n = dataV.size();
260 for (
unsigned int i = 0; i <
n; ++i) {
261 const V & v1 = *(dataV[i]);
272 double testAddition3(
const std::vector<V *> & dataV,
TStopwatch & tim,
double& t, std::string s) {
274 unsigned int n = dataV.size();
278 for (
unsigned int i = 0; i <
n; ++i) {
279 V & v1 = *(dataV[i]);
294 double testDotProduct(
const std::vector<V *> & dataV,
TStopwatch & tim,
double& t, std::string s) {
297 unsigned int n = dataV.size();
300 for (
unsigned int i = 0; i <
n; ++i) {
301 V & v1 = *(dataV[i]);
306 tot += dotProd(v1,v0);
316 double testScale(
const std::vector<V *> & dataV,
TStopwatch & tim,
double& t, std::string s) {
317 unsigned int n = dataV.size();
320 for (
unsigned int i = 0; i <
n; ++i) {
321 V & v1 = *(dataV[i]);
333 double testScale2(
const std::vector<V *> & dataV,
TStopwatch & tim,
double& t, std::string s) {
335 unsigned int n = dataV.size();
338 for (
unsigned int i = 0; i <
n; ++i) {
339 V & v1 = *(dataV[i]);
354 unsigned int n = dataV.size();
357 V v0b = *(dataV[n-1]);
359 for (
unsigned int i = 0; i <
n; ++i) {
360 V & v1 = *(dataV[i]);
362 double a = dotProd(v1,v0a);
374 inline double dPhi(V & v1, V& v2) {
375 return std::abs(v1.Phi() - v2.Phi() );
379 inline double dPhi(Hep2Vector & v1, Hep2Vector & v2) {
380 return std::abs(v1.phi() - v2.phi() );
386 double testDeltaPhi(
const std::vector<V *> & dataV,
TStopwatch & tim,
double& t, std::string s) {
387 unsigned int n =
std::min(n2Loop, dataV.size() );
390 for (
unsigned int i = 0; i <
n; ++i) {
391 V & v1 = *(dataV[i]);
392 for (
unsigned int j = i +1; j <
n; ++j) {
393 V & v2 = *(dataV[j]);
394 double delta = dPhi(v1,v2);
465 template <
class V1,
class V2>
466 void testConversion( std::vector<V1 *> & dataV1, std::vector<V2 *> & dataV2,
TStopwatch & tim,
double& t, std::string s) {
468 int n = dataX.size();
471 for (
int i = 0; i <
n; ++i) {
472 dataV2[i] =
new V2( *dataV1[i] );
482 template <
class V,
class R>
483 double testRotation( std::vector<V *> & dataV,
double rotAngle,
TStopwatch & tim,
double& t, std::string s) {
485 unsigned int n =
std::min(n2Loop, dataV.size() );
488 for (
unsigned int i = 0; i <
n; ++i) {
489 V & v1 = *(dataV[i]);
506 int main(
int argc,
const char *argv[]) {
509 if (argc > 1) ngen = atoi(argv[1]);
510 int nloop2 = int(
std::sqrt(2.0*ngen)+0.5);
511 if (argc > 2) nloop2 = atoi(argv[2]);
513 std::cout <<
"Test with Ngen = " << ngen <<
" n2loop = " << nloop2 << std::endl;
518 VectorTest
a(ngen,nloop2);
523 for (
int i = 0; i < niter; ++i) {
526 std::cout <<
"iteration " << i << std::endl;
536 std::vector<TVector2 *>
v1;
537 std::vector<XYVector *> v2;
538 std::vector<Polar2DVector *> v3;
539 std::vector<XYPoint *> v4;
540 std::vector<Polar2DPoint *> v5;
541 std::vector<SVector<double,2> *> v6;
543 a.testCreate (v1, t, t1,
"creation TVector2 " );
544 a.testCreate (v2, t, t2,
"creation XYVector " );
545 a.testCreate (v3, t, t3,
"creation Polar2DVector " );
546 a.testCreate (v4, t, t4,
"creation XYPoint " );
547 a.testCreate (v5, t, t5,
"creation Polar2DPoint " );
548 a.testCreate (v6, t, t6,
"creation SVector<2> " );
551 std::vector<Hep2Vector *> v7;
552 a.testCreate (v7, t, t7,
"creation Hep2Vector " );
565 a.testConversion (v2, v3, t, t3,
"Conversion XY->Polar " );
566 a.testConversion (v2, v4, t, t4,
"Conversion XYVec->XYPoint " );
567 a.testConversion (v2, v5, t, t5,
"Conversion XYVec->PolarP " );
576 a.testCreate2 (v1, t, t1,
"creationSet TVector2 " );
577 a.testCreate2 (v2, t, t2,
"creationSet XYVector " );
578 a.testCreate2 (v3, t, t3,
"creationSet Polar2DVector " );
579 a.testCreate2 (v4, t, t4,
"creationSet XYPoint " );
580 a.testCreate2 (v5, t, t5,
"creationSet Polar2DPoint " );
583 a.testCreate2 (v7, t, t7,
"creationSet Hep2Vector " );
588 double s1,s2,s3,s4,s5,s6;
589 s1=a.testAddition (v1, t, t1,
"Addition TVector2 " );
590 s2=a.testAddition (v2, t, t2,
"Addition XYVector " );
591 s3=a.testAddition (v3, t, t3,
"Addition Polar2DVector " );
592 s6=a.testAddition (v6, t, t6,
"Addition SVector<2> " );
593 a.check(
"Addition test1",s1,s2,s3);
594 a.check(
"Addition test2",s1,s2,s6);
597 s7=a.testAddition (v7, t, t7,
"Addition Hep2Vector " );
598 a.check(
"Addition",s7,s1,s2);
604 s1=a.testAddition2 (v1, t, t1,
"Addition2 TVector2 " );
605 s2=a.testAddition2 (v2, t, t2,
"Addition2 XYVector " );
606 s3=a.testAddition2 (v3, t, t3,
"Addition2 Polar2DVector " );
607 s6=a.testAddition2 (v6, t, t6,
"Addition2 SVector<2> " );
608 a.check(
"Addition2 test1",s1,s2,s3,100);
609 a.check(
"Addition2 test2",s1,s2,s6);
611 s7=a.testAddition2 (v7, t, t7,
"Addition2 Hep2Vector " );
612 a.check(
"Addition2 CLHEP",s7,s1,s2);
617 s1=a.testAddition3 (v1, t, t1,
"Addition3 TVector2 " );
618 s2=a.testAddition3 (v2, t, t2,
"Addition3 XYVector " );
619 s3=a.testAddition3 (v3, t, t3,
"Addition3 Polar2DVector " );
620 s6=a.testAddition3 (v6, t, t6,
"Addition3 SVector<2> " );
621 a.check(
"Addition3 test1",s1,s2,s3);
622 a.check(
"Addition3 test2",s6,s0,s2);
624 s7=a.testAddition3 (v7, t, t7,
"Addition3 Hep2Vector " );
625 a.check(
"Addition3 CLHEP",s7,s1,s2);
630 s1=a.testDotProduct (v1, t, t1,
"DotProduct TVector2 " );
631 s2=a.testDotProduct (v2, t, t2,
"DotProduct XYVector " );
633 s6=a.testDotProduct (v6, t, t6,
"DotProduct SVector<2> " );
634 a.check(
"DotProduct test1",s1,s2,s6);
637 s7=a.testDotProduct (v7, t, t7,
"DotProduct Hep2Vector " );
638 a.check(
"DotProduct CLHEP",s7,s1,s2);
644 s1=a.testDeltaPhi (v1, t, t1,
"DeltaPhi TVector2 " );
645 s2=a.testDeltaPhi (v2, t, t2,
"DeltaPhi XYVector " );
646 s3=a.testDeltaPhi (v3, t, t3,
"DeltaPhi Polar2DVector " );
647 s4=a.testDeltaPhi (v4, t, t4,
"DeltaPhi XYPoint " );
648 s5=a.testDeltaPhi (v5, t, t5,
"DeltaPhi Polar2DPoint " );
651 a.check(
"DeltaPhi",s1,s2,s3,10);
652 a.check(
"DeltaPhi",s2,s4,s5,10);
654 a.check(
"DeltaPhi",s1,s2,s3);
655 a.check(
"DeltaPhi",s2,s4,s5);
658 s7=a.testDeltaPhi (v7, t, t7,
"DeltaPhi HEP2Vector " );
659 a.check(
"DeltaPhi",s7,s1,s2);
663 s1=a.testScale (v1, t, t1,
"Scale of TVector2 " );
664 s2=a.testScale (v2, t, t2,
"Scale of XYVector " );
665 s3=a.testScale (v3, t, t3,
"Scale of Polar2DVector " );
666 s4=a.testScale (v4, t, t4,
"Scale of XYPoint " );
667 s5=a.testScale (v5, t, t5,
"Scale of Polar2DPoint " );
668 a.check(
"Scaling",s1,s2,s3);
669 a.check(
"Scaling",s2,s4,s5, 10);
670 s6=a.testScale (v6, t, t6,
"Scale of SVector<2> " );
671 a.check(
"Scaling SV",s6,s1,s2);
674 s7=a.testScale (v7, t, t7,
"Scale of HEP2Vector " );
675 a.check(
"Scaling CLHEP",s7,s2,s3);
679 s1=a.testScale2 (v1, t, t1,
"Scale2 of TVector2 " );
680 s2=a.testScale2 (v2, t, t2,
"Scale2 of XYVector " );
681 s3=a.testScale2 (v3, t, t3,
"Scale2 of Polar2DVector " );
682 s4=a.testScale2 (v4, t, t4,
"Scale2 of XYPoint " );
683 s5=a.testScale2 (v5, t, t5,
"Scale2 of Polar2DPoint " );
684 a.check(
"Scaling2",s1,s2,s3);
685 a.check(
"Scaling2",s2,s4,s5, 10);
686 s6=a.testScale2 (v6, t, t6,
"Scale2 of SVector<2> " );
687 a.check(
"Scaling2 SV",s6,s1,s2);
690 s7=a.testScale2 (v7, t, t7,
"Scale2 of HEP2Vector " );
691 a.check(
"Scaling CLHEP",s7,s2,s3);
696 s1=a.testOperations (v1, t, t1,
"Operations of TVector2 " );
697 s2=a.testOperations (v2, t, t2,
"Operations of XYVector " );
698 s6=a.testOperations (v6, t, t6,
"Operations of SVector<2> " );
699 a.check(
"Operations testSV",s6,s1,s2);
701 s7=a.testOperations (v7, t, t7,
"Operations of HEP2Vector " );
702 a.check(
"Operations CLHEP",s7,s1,s2);
709 int n1, n2, n3,n4,n5;
710 n1 = a.testAnalysis (v1, t, t1,
"Analysis1 TVector2 " );
711 n2 = a.testAnalysis (v2, t, t2,
"Analysis1 XYVector " );
712 n3 = a.testAnalysis (v3, t, t3,
"Analysis1 Polar2DVector " );
713 n4 = a.testAnalysis (v4, t, t4,
"Analysis1 XYPoint " );
714 n5 = a.testAnalysis (v5, t, t5,
"Analysis1 Polar2DPoint " );
715 a.check(
"Analysis1",n1,n2,n3);
716 a.check(
"Analysis1",n2,n4,n5);
719 n6 = a.testAnalysis (v7, t, t7,
"Analysis1 HEP2Vector " );
720 a.check(
"Analysis2 CLHEP",n6,n1,n2);
724 n1 = a.testAnalysis2 (v1, t, t1,
"Analysis2 TVector2 " );
725 n2 = a.testAnalysis2 (v2, t, t2,
"Analysis2 XYVector " );
726 n3 = a.testAnalysis2 (v3, t, t3,
"Analysis2 Polar2DVector " );
727 n4 = a.testAnalysis2 (v4, t, t4,
"Analysis2 XYPoint " );
728 n5 = a.testAnalysis2 (v5, t, t5,
"Analysis2 Polar2DPoint " );
729 a.check(
"Analysis2",n1,n2,n3);
730 a.check(
"Analysis2",n2,n4,n5);
732 n6 = a.testAnalysis2 (v7, t, t7,
"Analysis2 HEP2Vector " );
733 a.check(
"Analysis2 CLHEP",n6,n1,n2);
737 n1 = a.testAnalysis3 (v1, t, t1,
"Analysis3 TVector2 " );
738 n2 = a.testAnalysis3 (v2, t, t2,
"Analysis3 XYVector " );
739 n3 = a.testAnalysis3 (v3, t, t3,
"Analysis3 Polar2DVector " );
740 n4 = a.testAnalysis3 (v4, t, t4,
"Analysis3 XYPoint " );
741 n5 = a.testAnalysis3 (v5, t, t5,
"Analysis3 Polar2DPoint " );
742 a.check(
"Analysis3",n1,n2,n3);
743 a.check(
"Analysis3",n2,n4,n5);
745 n6 = a.testAnalysis3 (v7, t, t7,
"Analysis3 HEP2Vector " );
746 a.check(
"Analysis3 CLHEP",n6,n1,n2);
757 std::cout << std::endl;
758 std::cout <<
"Total Time for TVector2 = " << t1 <<
"\t(sec)" << std::endl;
759 std::cout <<
"Total Time for XYVector = " << t2 <<
"\t(sec)" << std::endl;
760 std::cout <<
"Total Time for Polar2DVector = " << t3 <<
"\t(sec)" << std::endl;
762 std::cout <<
"Total Time for Hep2Vector = " << t7 <<
"\t(sec)" << std::endl;
T Dot(const SVector< T, D > &lhs, const SVector< T, D > &rhs)
Vector dot product.
Random number generator class based on M.
static Vc_ALWAYS_INLINE int_v min(const int_v &x, const int_v &y)
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.
void Stop()
Stop the stopwatch.
static Vc_ALWAYS_INLINE Vector< T > abs(const Vector< T > &x)
virtual Double_t Rndm(Int_t i=0)
Machine independent random number generator.
int getSum(const int *x, int n)
Scalar Dot(const DisplacementVector2D< OtherCoords, Tag > &v) const
Return the scalar (dot) product of two displacement vectors.
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
int main(int argc, const char *argv[])
Class describing a generic displacement vector in 2 dimensions.
virtual Double_t Exp(Double_t tau)
Returns an exponential deviate.
SVector: a generic fixed size Vector class.