Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
mathcoreGenVectorSYCL.C File Reference

Detailed Description

View in nbviewer Open in SWAN
Example macro testing available methods and operation of the GenVectorX classes.

Note
This tutorial requires ROOT to be built with SYCL support and GenVectorX enabled. Configure CMake with: -Dexperimental_adaptivecpp=ON -Dexperimental_genvectorx=ON

The results are compared and checked The macro is divided in 3 parts:

  • testVector3D : tests of the 3D Vector classes
  • testPoint3D : tests of the 3D Point classes
  • testLorentzVector : tests of the 4D LorentzVector classes
#define ROOT_MATH_ARCH MathSYCL
#include "MathX/Vector3D.h"
#include "MathX/Point3D.h"
#include "MathX/Vector2D.h"
#include "MathX/Point2D.h"
#include <sycl/sycl.hpp>
#include <vector>
using namespace ROOT::ROOT_MATH_ARCH;
int ntest = 0;
int nfail = 0;
int ok = 0;
int compare(double v1, double v2, double scale = 1.0)
{
ntest = ntest + 1;
// numerical double limit for epsilon
double eps = scale * std::numeric_limits<double>::epsilon();
int iret = 0;
double delta = v2 - v1;
double d = 0;
if (delta < 0)
delta = -delta;
if (v1 == 0 || v2 == 0) {
if (delta > eps) {
iret = 1;
}
}
// skip case v1 or v2 is infinity
else {
d = v1;
if (v1 < 0)
d = -d;
// add also case when delta is small by default
if (delta / d > eps && delta > eps)
iret = 1;
}
return iret;
}
template <class Transform>
bool IsEqual(const Transform &t1, const Transform &t2, unsigned int size)
{
// size should be an enum of the Transform class
std::vector<double> x1(size);
std::vector<double> x2(size);
t1.GetComponents(x1.begin(), x1.end());
t2.GetComponents(x2.begin(), x2.end());
bool ret = true;
unsigned int i = 0;
while (ret && i < size) {
// from TMath::AreEqualRel(x1,x2,2*eps)
bool areEqual =
std::abs(x1[i] - x2[i]) < std::numeric_limits<double>::epsilon() * (std::abs(x1[i]) + std::abs(x2[i]));
i++;
}
return ret;
}
{
std::cout << "\n************************************************************************\n " << " Vector 3D Test"
<< "\n************************************************************************\n";
sycl::buffer<int, 1> ok_buf(&ok, sycl::range<1>(1));
sycl::default_selector device_selector;
sycl::queue queue(device_selector);
{
queue.submit([&](sycl::handler &cgh) {
auto ok_device = ok_buf.get_access<sycl::access::mode::read_write>(cgh);
cgh.single_task<class testVector3D>([=]() {
// test the vector tags
GlobalXYZVector vg(1., 2., 3.);
ok_device[0] += compare(vpg.R(), vg2.R());
// std::cout << vg2 << std::endl;
double r = vg.Dot(vpg);
ok_device[0] += compare(r, vg.Mag2());
ok_device[0] += compare(vcross.R(), 0.0, 10);
// std::cout << vg.Dot(vpg) << std::endl;
// std::cout << vg.Cross(vpg) << std::endl;
ok_device[0] += compare(vg3.R(), 2 * vg.R());
ok_device[0] += compare(vg4.R(), 0.0, 10);
});
});
}
if (ok == 0)
std::cout << "\t\t OK " << std::endl;
return ok;
}
{
std::cout << "\n************************************************************************\n " << " Point 3D Tests"
<< "\n************************************************************************\n";
sycl::buffer<int, 1> ok_buf(&ok, sycl::range<1>(1));
sycl::default_selector device_selector;
sycl::queue queue(device_selector);
{
queue.submit([&](sycl::handler &cgh) {
auto ok_device = ok_buf.get_access<sycl::access::mode::read_write>(cgh);
cgh.single_task<class testPoint3D>([=]() {
// test the vector tags
GlobalXYZPoint pg(1., 2., 3.);
ok_device[0] += compare(ppg.R(), pg2.R());
// std::cout << pg2 << std::endl;
double r = pg.Dot(vg);
ok_device[0] += compare(r, pg.Mag2());
ok_device[0] += compare(pcross.R(), 0.0, 10);
ok_device[0] += compare(pg3.R(), 2 * pg.R());
ok_device[0] += compare(vg4.R(), 0.0, 10);
// operator -
XYZPoint q1(1., 2., 3.);
XYZPoint q2 = -1. * q1;
ok_device[0] += compare(XYZVector(q2) == v2, true);
});
});
}
if (ok == 0)
std::cout << "\t OK " << std::endl;
return ok;
}
{
std::cout << "\n************************************************************************\n "
<< " Lorentz Vector Tests"
<< "\n************************************************************************\n";
ok += compare(v1.DeltaR(v2), 4.60575f);
// Result cross-validated using:
// TLorentzVector t1, t2;
// t1.SetPtEtaPhiE(1,2,3,4); t2.SetPtEtaPhiE(5,6,7,8);
// t1.DeltaR(t2)
if (ok == 0)
std::cout << "\t OK " << std::endl;
return ok;
}
{
std::cout << "\n\nNumber of tests " << ntest << " failed = " << nfail << std::endl;
}
#define d(i)
Definition RSha256.hxx:102
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Tag for identifying vectors based on a global coordinate system.
Tag for identifying vectors based on a local coordinate system.
Global Helper functions for generic Vector classes.
Definition VectorUtil.h:45
DisplacementVector3D< Cartesian3D< double >, DefaultCoordinateSystemTag > XYZVector
3D Vector based on the cartesian coordinates x,y,z in double precision
Definition Vector3Dfwd.h:49
bool areEqual(const RULE *r1, const RULE *r2, bool moduloNameOrPattern=false)
auto * t1
Definition textangle.C:20
Author
Devajith Valaparambil Sreeramaswamy (CERN)

Definition in file mathcoreGenVectorSYCL.C.