Skip to content

Commit 98b7093

Browse files
committed
[genvectorx] Add Invariant Masses test
1 parent fe5460d commit 98b7093

File tree

2 files changed

+184
-3
lines changed

2 files changed

+184
-3
lines changed

math/experimental/genvectorx/test/CMakeLists.txt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,22 @@
88

99

1010
ROOT_EXECUTABLE(testGenvectorSYCL testGenVectorSYCL.cxx) # LIBRARIES GenVectorSYCL)
11-
if (oneapi)
12-
target_link_options(testGenvectorSYCL PUBLIC -E)
13-
endif()
1411
target_link_libraries(testGenvectorSYCL PUBLIC GenVectorSYCL )
1512
add_sycl_to_root_target(TARGET testGenvectorSYCL
1613
SOURCES testGenVectorSYCL.cxx
1714
COMPILE_DEFINITIONS ROOT_MATH_SYCL
1815
DEPENDENCIES GenVectorSYCL
1916
)
17+
18+
19+
ROOT_EXECUTABLE(testGenvectorSYCLInvMasses testGenVectorSYCLInvMasses.cxx) # LIBRARIES GenVectorSYCL)
20+
target_link_libraries(testGenvectorSYCLInvMasses PUBLIC GenVectorSYCL )
21+
add_sycl_to_root_target(TARGET testGenvectorSYCLInvMasses
22+
SOURCES testGenvectorSYCLInvMasses.cxx
23+
COMPILE_DEFINITIONS ROOT_MATH_SYCL
24+
DEPENDENCIES GenVectorSYCL
25+
)
26+
2027
ROOT_ADD_TEST(test-genvector-genvectorsycl COMMAND testGenvectorSYCL)
28+
ROOT_ADD_TEST(test-genvector-genvectorsyclinvmasses COMMAND testGenvectorSYCLInvMasses)
2129

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
#include "MathX/Vector3D.h"
2+
#include "MathX/Point3D.h"
3+
4+
#include "MathX/Vector2D.h"
5+
#include "MathX/Point2D.h"
6+
7+
#include "MathX/EulerAngles.h"
8+
9+
#include "MathX/Transform3D.h"
10+
#include "MathX/Translation3D.h"
11+
12+
#include "MathX/Rotation3D.h"
13+
#include "MathX/RotationX.h"
14+
#include "MathX/RotationY.h"
15+
#include "MathX/RotationZ.h"
16+
#include "MathX/Quaternion.h"
17+
#include "MathX/AxisAngle.h"
18+
#include "MathX/RotationZYX.h"
19+
20+
#include "MathX/LorentzRotation.h"
21+
#include "MathX/PtEtaPhiM4D.h"
22+
#include "MathX/LorentzVector.h"
23+
24+
#include "MathX/VectorUtil.h"
25+
26+
#include "MathX/GenVectorX/AccHeaders.h"
27+
28+
#include <sycl/sycl.hpp>
29+
30+
#include <vector>
31+
32+
using namespace ROOT::ROOT_MATH_ARCH;
33+
using namespace ROOT::ROOT_MATH_ARCH::VectorUtil;
34+
35+
typedef LorentzVector<PtEtaPhiM4D<double>> vec4d;
36+
37+
int compare(double v1, double v2, double scale = 1.0)
38+
{
39+
// ntest = ntest + 1;
40+
41+
// numerical double limit for epsilon
42+
double eps = scale * std::numeric_limits<double>::epsilon();
43+
int iret = 0;
44+
double delta = v2 - v1;
45+
double d = 0;
46+
if (delta < 0)
47+
delta = -delta;
48+
if (v1 == 0 || v2 == 0) {
49+
if (delta > eps) {
50+
iret = 1;
51+
}
52+
}
53+
// skip case v1 or v2 is infinity
54+
else {
55+
d = v1;
56+
57+
if (v1 < 0)
58+
d = -d;
59+
// add also case when delta is small by default
60+
if (delta / d > eps && delta > eps)
61+
iret = 1;
62+
}
63+
64+
// if (iret == 0)
65+
// std::cout << ".";
66+
// else {
67+
// int pr = std::cout.precision(18);
68+
// std::cout << "\nDiscrepancy in " << name << "() : " << v1 << " != " << v2 << " discr = " << int(delta / d /
69+
// eps)
70+
// << " (Allowed discrepancy is " << eps << ")\n";
71+
// std::cout.precision(pr);
72+
// // nfail = nfail + 1;
73+
// }
74+
return iret;
75+
}
76+
77+
template <class Transform>
78+
bool IsEqual(const Transform &t1, const Transform &t2, unsigned int size)
79+
{
80+
// size should be an enum of the Transform class
81+
std::vector<double> x1(size);
82+
std::vector<double> x2(size);
83+
t1.GetComponents(x1.begin(), x1.end());
84+
t2.GetComponents(x2.begin(), x2.end());
85+
bool ret = true;
86+
unsigned int i = 0;
87+
while (ret && i < size) {
88+
// from TMath::AreEqualRel(x1,x2,2*eps)
89+
bool areEqual =
90+
std::abs(x1[i] - x2[i]) < std::numeric_limits<double>::epsilon() * (std::abs(x1[i]) + std::abs(x2[i]));
91+
ret &= areEqual;
92+
i++;
93+
}
94+
return ret;
95+
}
96+
97+
vec4d *GenVectors(int n)
98+
{
99+
vec4d *vectors = new vec4d[n];
100+
101+
// generate n -4 momentum quantities
102+
for (int i = 0; i < n; ++i)
103+
{
104+
// fill vectors
105+
vectors[i] = {1., 1., 1., 1.};
106+
}
107+
108+
return vectors;
109+
}
110+
111+
int testInvariantMasses(int N)
112+
{
113+
int iret_host = 0;
114+
std::cout << "testing Invariant Masses Computation \t:\n";
115+
116+
sycl::default_selector device_selector;
117+
sycl::queue queue(device_selector);
118+
119+
auto v1 = GenVectors(N);
120+
auto v2 = GenVectors(N);
121+
double* invMasses = new double[N];
122+
123+
std::cout << "sycl::queue check - selected device:\n"
124+
<< queue.get_device().get_info<sycl::info::device::name>()
125+
<< std::endl;
126+
127+
{
128+
129+
vec4d* d_v1 = sycl::malloc_device<vec4d>(N, queue);
130+
vec4d* d_v2 = sycl::malloc_device<vec4d>(N, queue);
131+
double* d_invMasses = sycl::malloc_device<double>(N, queue);
132+
133+
queue.memcpy(d_v1, v1, N * sizeof(vec4d));
134+
queue.memcpy(d_v2, v2, N * sizeof(vec4d));
135+
queue.wait();
136+
137+
queue.submit([&](sycl::handler &cgh) {
138+
cgh.parallel_for(sycl::range<1>(N), [=](sycl::id<1> indx) {
139+
vec4d v = d_v2[indx]+d_v2[indx];
140+
d_invMasses[indx] = v.M();
141+
142+
});
143+
});
144+
145+
queue.wait();
146+
queue.memcpy(invMasses, d_invMasses, N * sizeof(double));
147+
queue.wait();
148+
}
149+
150+
for (int i = 0; i < N; i++){
151+
iret_host += (std::abs(invMasses[i] - 2.) > 1e-5);
152+
}
153+
154+
if (iret_host == 0)
155+
std::cout << "\tOK\n";
156+
else
157+
std::cout << "\t FAILED\n";
158+
159+
return iret_host;
160+
161+
}
162+
163+
164+
int main()
165+
{
166+
int n = 128;
167+
int ret = testInvariantMasses(n);
168+
if (ret)
169+
std::cerr << "test FAILED !!! " << std::endl;
170+
else
171+
std::cout << "test OK " << std::endl;
172+
return ret;
173+
}

0 commit comments

Comments
 (0)