{ "cells": [ { "cell_type": "markdown", "id": "5704fdb5", "metadata": {}, "source": [ "# mathcoreGenVectorSYCL\n", "Example macro testing available methods and operation of the GenVectorX classes.\n", "\n", "Configure CMake with:\n", " `-Dexperimental_adaptivecpp=ON -Dexperimental_genvectorx=ON`\n", "\n", "The results are compared and checked\n", "The macro is divided in 3 parts:\n", " - testVector3D : tests of the 3D Vector classes\n", " - testPoint3D : tests of the 3D Point classes\n", " - testLorentzVector : tests of the 4D LorentzVector classes\n", "\n", "\n", "\n", "\n", "**Author:** Devajith Valaparambil Sreeramaswamy (CERN) \n", "This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Tuesday, May 19, 2026 at 08:25 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "b6e11941", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:49.499970Z", "iopub.status.busy": "2026-05-19T20:25:49.499854Z", "iopub.status.idle": "2026-05-19T20:25:49.824593Z", "shell.execute_reply": "2026-05-19T20:25:49.824041Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_44:4:10: fatal error: 'MathX/Vector3D.h' file not found\n", "#include \"MathX/Vector3D.h\"\n", " ^~~~~~~~~~~~~~~~~~\n" ] } ], "source": [ "#define ROOT_MATH_ARCH MathSYCL\n", "#define ROOT_MATH_SYCL\n", "\n", "#include \"MathX/Vector3D.h\"\n", "#include \"MathX/Point3D.h\"\n", "\n", "#include \"MathX/Vector2D.h\"\n", "#include \"MathX/Point2D.h\"\n", "\n", "#include \"MathX/EulerAngles.h\"\n", "\n", "#include \"MathX/Transform3D.h\"\n", "#include \"MathX/Translation3D.h\"\n", "\n", "#include \"MathX/Rotation3D.h\"\n", "#include \"MathX/RotationX.h\"\n", "#include \"MathX/RotationY.h\"\n", "#include \"MathX/RotationZ.h\"\n", "#include \"MathX/Quaternion.h\"\n", "#include \"MathX/AxisAngle.h\"\n", "#include \"MathX/RotationZYX.h\"\n", "\n", "#include \"MathX/LorentzRotation.h\"\n", "#include \"MathX/PtEtaPhiM4D.h\"\n", "#include \"MathX/LorentzVector.h\"\n", "\n", "#include \"MathX/VectorUtil.h\"\n", "\n", "#include \n", "\n", "#include \n", "\n", "using namespace ROOT::ROOT_MATH_ARCH;\n", "using namespace ROOT::ROOT_MATH_ARCH::VectorUtil;\n", "\n", "typedef DisplacementVector3D, GlobalCoordinateSystemTag> GlobalXYZVector;\n", "typedef DisplacementVector3D, LocalCoordinateSystemTag> LocalXYZVector;\n", "typedef DisplacementVector3D, GlobalCoordinateSystemTag> GlobalPolar3DVector;\n", "\n", "typedef PositionVector3D, GlobalCoordinateSystemTag> GlobalXYZPoint;\n", "typedef PositionVector3D, LocalCoordinateSystemTag> LocalXYZPoint;\n", "typedef PositionVector3D, GlobalCoordinateSystemTag> GlobalPolar3DPoint;\n", "typedef PositionVector3D, LocalCoordinateSystemTag> LocalPolar3DPoint;\n", "\n", "int ntest = 0;\n", "int nfail = 0;\n", "int ok = 0;" ] }, { "cell_type": "markdown", "id": "e3fdd5dc", "metadata": {}, "source": [ " Definition of a helper function: " ] }, { "cell_type": "code", "execution_count": 2, "id": "df8d6b5b", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:49.826412Z", "iopub.status.busy": "2026-05-19T20:25:49.826286Z", "iopub.status.idle": "2026-05-19T20:25:49.831564Z", "shell.execute_reply": "2026-05-19T20:25:49.830813Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_53:3:4: error: use of undeclared identifier 'ntest'\n", " ntest = ntest + 1;\n", " ^\n", "input_line_53:3:12: error: use of undeclared identifier 'ntest'\n", " ntest = ntest + 1;\n", " ^\n" ] } ], "source": [ "%%cpp -d\n", "int compare(double v1, double v2, double scale = 1.0)\n", "{\n", " ntest = ntest + 1;\n", "\n", " // numerical double limit for epsilon\n", " double eps = scale * std::numeric_limits::epsilon();\n", " int iret = 0;\n", " double delta = v2 - v1;\n", " double d = 0;\n", " if (delta < 0)\n", " delta = -delta;\n", " if (v1 == 0 || v2 == 0) {\n", " if (delta > eps) {\n", " iret = 1;\n", " }\n", " }\n", " // skip case v1 or v2 is infinity\n", " else {\n", " d = v1;\n", "\n", " if (v1 < 0)\n", " d = -d;\n", " // add also case when delta is small by default\n", " if (delta / d > eps && delta > eps)\n", " iret = 1;\n", " }\n", "\n", " return iret;\n", "}" ] }, { "cell_type": "markdown", "id": "91581323", "metadata": {}, "source": [ " Definition of a helper function: " ] }, { "cell_type": "code", "execution_count": 3, "id": "9fad83eb", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:49.832951Z", "iopub.status.busy": "2026-05-19T20:25:49.832830Z", "iopub.status.idle": "2026-05-19T20:25:49.837784Z", "shell.execute_reply": "2026-05-19T20:25:49.837062Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "template \n", "bool IsEqual(const Transform &t1, const Transform &t2, unsigned int size)\n", "{\n", " // size should be an enum of the Transform class\n", " std::vector x1(size);\n", " std::vector x2(size);\n", " t1.GetComponents(x1.begin(), x1.end());\n", " t2.GetComponents(x2.begin(), x2.end());\n", " bool ret = true;\n", " unsigned int i = 0;\n", " while (ret && i < size) {\n", " // from TMath::AreEqualRel(x1,x2,2*eps)\n", " bool areEqual =\n", " std::abs(x1[i] - x2[i]) < std::numeric_limits::epsilon() * (std::abs(x1[i]) + std::abs(x2[i]));\n", " ret &= areEqual;\n", " i++;\n", " }\n", " return ret;\n", "}" ] }, { "cell_type": "markdown", "id": "8d28e1a6", "metadata": {}, "source": [ " Definition of a helper function: " ] }, { "cell_type": "code", "execution_count": 4, "id": "904b2b47", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:49.839214Z", "iopub.status.busy": "2026-05-19T20:25:49.839066Z", "iopub.status.idle": "2026-05-19T20:25:49.846563Z", "shell.execute_reply": "2026-05-19T20:25:49.845740Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_55:6:4: error: use of undeclared identifier 'sycl'\n", " sycl::buffer ok_buf(&ok, sycl::range<1>(1));\n", " ^\n", "input_line_55:6:20: error: expected '(' for function-style cast or type construction\n", " sycl::buffer ok_buf(&ok, sycl::range<1>(1));\n", " ~~~^\n", "input_line_55:6:33: error: use of undeclared identifier 'ok'\n", " sycl::buffer ok_buf(&ok, sycl::range<1>(1));\n", " ^\n", "input_line_55:6:37: error: use of undeclared identifier 'sycl'\n", " sycl::buffer ok_buf(&ok, sycl::range<1>(1));\n", " ^\n", "input_line_55:7:4: error: use of undeclared identifier 'sycl'\n", " sycl::default_selector device_selector;\n", " ^\n", "input_line_55:8:4: error: use of undeclared identifier 'sycl'\n", " sycl::queue queue(device_selector);\n", " ^\n", "input_line_55:11:12: error: cannot use dot operator on a type\n", " queue.submit([&](sycl::handler &cgh) {\n", " ^\n", "input_line_55:42:8: error: use of undeclared identifier 'ok'\n", " if (ok == 0)\n", " ^\n", "input_line_55:45:11: error: use of undeclared identifier 'ok'\n", " return ok;\n", " ^\n" ] } ], "source": [ "%%cpp -d\n", "int testVector3D()\n", "{\n", " std::cout << \"\\n************************************************************************\\n \" << \" Vector 3D Test\"\n", " << \"\\n************************************************************************\\n\";\n", "\n", " sycl::buffer ok_buf(&ok, sycl::range<1>(1));\n", " sycl::default_selector device_selector;\n", " sycl::queue queue(device_selector);\n", "\n", " {\n", " queue.submit([&](sycl::handler &cgh) {\n", " auto ok_device = ok_buf.get_access(cgh);\n", " cgh.single_task([=]() {\n", " // test the vector tags\n", "\n", " GlobalXYZVector vg(1., 2., 3.);\n", " GlobalXYZVector vg2(vg);\n", " GlobalPolar3DVector vpg(vg);\n", "\n", " ok_device[0] += compare(vpg.R(), vg2.R());\n", "\n", " // std::cout << vg2 << std::endl;\n", "\n", " double r = vg.Dot(vpg);\n", " ok_device[0] += compare(r, vg.Mag2());\n", "\n", " GlobalXYZVector vcross = vg.Cross(vpg);\n", " ok_device[0] += compare(vcross.R(), 0.0, 10);\n", "\n", " // std::cout << vg.Dot(vpg) << std::endl;\n", " // std::cout << vg.Cross(vpg) << std::endl;\n", "\n", " GlobalXYZVector vg3 = vg + vpg;\n", " ok_device[0] += compare(vg3.R(), 2 * vg.R());\n", "\n", " GlobalXYZVector vg4 = vg - vpg;\n", " ok_device[0] += compare(vg4.R(), 0.0, 10);\n", " });\n", " });\n", " }\n", "\n", " if (ok == 0)\n", " std::cout << \"\\t\\t OK \" << std::endl;\n", "\n", " return ok;\n", "}" ] }, { "cell_type": "markdown", "id": "155c8cae", "metadata": {}, "source": [ " Definition of a helper function: " ] }, { "cell_type": "code", "execution_count": 5, "id": "88d410ad", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:49.847969Z", "iopub.status.busy": "2026-05-19T20:25:49.847850Z", "iopub.status.idle": "2026-05-19T20:25:49.853151Z", "shell.execute_reply": "2026-05-19T20:25:49.852405Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_56:6:4: error: use of undeclared identifier 'sycl'\n", " sycl::buffer ok_buf(&ok, sycl::range<1>(1));\n", " ^\n", "input_line_56:6:20: error: expected '(' for function-style cast or type construction\n", " sycl::buffer ok_buf(&ok, sycl::range<1>(1));\n", " ~~~^\n", "input_line_56:6:33: error: use of undeclared identifier 'ok'\n", " sycl::buffer ok_buf(&ok, sycl::range<1>(1));\n", " ^\n", "input_line_56:6:37: error: use of undeclared identifier 'sycl'\n", " sycl::buffer ok_buf(&ok, sycl::range<1>(1));\n", " ^\n", "input_line_56:7:4: error: use of undeclared identifier 'sycl'\n", " sycl::default_selector device_selector;\n", " ^\n", "input_line_56:8:4: error: use of undeclared identifier 'sycl'\n", " sycl::queue queue(device_selector);\n", " ^\n", "input_line_56:11:12: error: cannot use dot operator on a type\n", " queue.submit([&](sycl::handler &cgh) {\n", " ^\n", "input_line_56:48:8: error: use of undeclared identifier 'ok'\n", " if (ok == 0)\n", " ^\n", "input_line_56:51:11: error: use of undeclared identifier 'ok'\n", " return ok;\n", " ^\n" ] } ], "source": [ "%%cpp -d\n", "int testPoint3D()\n", "{\n", " std::cout << \"\\n************************************************************************\\n \" << \" Point 3D Tests\"\n", " << \"\\n************************************************************************\\n\";\n", "\n", " sycl::buffer ok_buf(&ok, sycl::range<1>(1));\n", " sycl::default_selector device_selector;\n", " sycl::queue queue(device_selector);\n", "\n", " {\n", " queue.submit([&](sycl::handler &cgh) {\n", " auto ok_device = ok_buf.get_access(cgh);\n", " cgh.single_task([=]() {\n", " // test the vector tags\n", "\n", " GlobalXYZPoint pg(1., 2., 3.);\n", " GlobalXYZPoint pg2(pg);\n", "\n", " GlobalPolar3DPoint ppg(pg);\n", "\n", " ok_device[0] += compare(ppg.R(), pg2.R());\n", " // std::cout << pg2 << std::endl;\n", "\n", " GlobalXYZVector vg(pg);\n", "\n", " double r = pg.Dot(vg);\n", " ok_device[0] += compare(r, pg.Mag2());\n", "\n", " GlobalPolar3DVector vpg(pg);\n", " GlobalXYZPoint pcross = pg.Cross(vpg);\n", " ok_device[0] += compare(pcross.R(), 0.0, 10);\n", "\n", " GlobalPolar3DPoint pg3 = ppg + vg;\n", " ok_device[0] += compare(pg3.R(), 2 * pg.R());\n", "\n", " GlobalXYZVector vg4 = pg - ppg;\n", " ok_device[0] += compare(vg4.R(), 0.0, 10);\n", "\n", " // operator -\n", " XYZPoint q1(1., 2., 3.);\n", " XYZPoint q2 = -1. * q1;\n", " XYZVector v2 = -XYZVector(q1);\n", " ok_device[0] += compare(XYZVector(q2) == v2, true);\n", " });\n", " });\n", " }\n", "\n", " if (ok == 0)\n", " std::cout << \"\\t OK \" << std::endl;\n", "\n", " return ok;\n", "}" ] }, { "cell_type": "markdown", "id": "7f01da42", "metadata": {}, "source": [ " Definition of a helper function: " ] }, { "cell_type": "code", "execution_count": 6, "id": "573b72fd", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:49.854475Z", "iopub.status.busy": "2026-05-19T20:25:49.854360Z", "iopub.status.idle": "2026-05-19T20:25:49.860441Z", "shell.execute_reply": "2026-05-19T20:25:49.859626Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_57:7:4: error: use of undeclared identifier 'sycl'\n", " sycl::buffer ok_buf(&ok, sycl::range<1>(1));\n", " ^\n", "input_line_57:7:20: error: expected '(' for function-style cast or type construction\n", " sycl::buffer ok_buf(&ok, sycl::range<1>(1));\n", " ~~~^\n", "input_line_57:7:33: error: use of undeclared identifier 'ok'\n", " sycl::buffer ok_buf(&ok, sycl::range<1>(1));\n", " ^\n", "input_line_57:7:37: error: use of undeclared identifier 'sycl'\n", " sycl::buffer ok_buf(&ok, sycl::range<1>(1));\n", " ^\n", "input_line_57:8:4: error: use of undeclared identifier 'sycl'\n", " sycl::default_selector device_selector;\n", " ^\n", "input_line_57:9:4: error: use of undeclared identifier 'sycl'\n", " sycl::queue queue(device_selector);\n", " ^\n", "input_line_57:12:17: error: use of class template 'queue' requires template arguments\n", " << queue.get_device().get_info() << std::endl;\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/stl_queue.h:96:11: note: template is declared here\n", " class queue\n", " ^\n", "input_line_57:12:45: error: use of undeclared identifier 'sycl'\n", " << queue.get_device().get_info() << std::endl;\n", " ^\n", "input_line_57:15:12: error: cannot use dot operator on a type\n", " queue.submit([&](sycl::handler &cgh) {\n", " ^\n", "input_line_57:28:8: error: use of undeclared identifier 'ok'\n", " if (ok == 0)\n", " ^\n", "input_line_57:33:11: error: use of undeclared identifier 'ok'\n", " return ok;\n", " ^\n" ] } ], "source": [ "%%cpp -d\n", "int testLorentzVector()\n", "{\n", " std::cout << \"\\n************************************************************************\\n \"\n", " << \" Lorentz Vector Tests\"\n", " << \"\\n************************************************************************\\n\";\n", "\n", " sycl::buffer ok_buf(&ok, sycl::range<1>(1));\n", " sycl::default_selector device_selector;\n", " sycl::queue queue(device_selector);\n", "\n", " std::cout << \"sycl::queue check - selected device:\\n\"\n", " << queue.get_device().get_info() << std::endl;\n", "\n", " {\n", " queue.submit([&](sycl::handler &cgh) {\n", " auto ok_device = ok_buf.get_access(cgh);\n", " cgh.single_task([=]() {\n", " LorentzVector> v1(1, 2, 3, 4);\n", " LorentzVector> v2(5, 6, 7, 8);\n", " ok_device[0] += compare(v1.DeltaR(v2), 4.60575f);\n", "\n", " LorentzVector> v = v1 + v2;\n", " ok_device[0] += compare(v.M(), 62.03058f);\n", " });\n", " });\n", " }\n", "\n", " if (ok == 0)\n", " std::cout << \"\\tOK\\n\";\n", " else\n", " std::cout << \"\\t FAILED\\n\";\n", "\n", " return ok;\n", "}" ] }, { "cell_type": "code", "execution_count": 7, "id": "de3f868e", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:49.861826Z", "iopub.status.busy": "2026-05-19T20:25:49.861714Z", "iopub.status.idle": "2026-05-19T20:25:50.069871Z", "shell.execute_reply": "2026-05-19T20:25:50.069261Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_59:2:3: error: use of undeclared identifier 'testVector3D'\n", " (testVector3D())\n", " ^\n", "Error in : Error evaluating expression (testVector3D())\n", "Execution of your code was aborted.\n" ] } ], "source": [ "testVector3D();\n", "testPoint3D();\n", "testLorentzVector();\n", "\n", "std::cout << \"\\n\\nNumber of tests \" << ntest << \" failed = \" << nfail << std::endl;" ] } ], "metadata": { "kernelspec": { "display_name": "ROOT C++", "language": "c++", "name": "root" }, "language_info": { "codemirror_mode": "text/x-c++src", "file_extension": ".C", "mimetype": " text/x-c++src", "name": "c++" } }, "nbformat": 4, "nbformat_minor": 5 }