1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
#include "VecGeom/volumes/LogicalVolume.h"
#include "VecGeom/volumes/Box.h"
#include "VecGeom/volumes/Trapezoid.h"
#include "VecGeomTest/Benchmarker.h"
#include "VecGeom/management/GeoManager.h"
#include "ArgParser.h"
#include <fstream>
using namespace vecgeom;
int main(int argc, char *argv[])
{
OPTION_INT(npoints, 32768);
OPTION_INT(nrep, 4);
OPTION_INT(nstats, 1);
OPTION_INT(type, 2);
#if 0
// temporary alert to deprecated use of npoints
OPTION_INT(npoints, 0);
if(npoints) {
printf("\n***** ERROR: -npoints is now deprecated. Please use -npoints instead.\n");
std::exit(-1);
}
#endif
//===== Build a geometry with trapezoid(s)
// world volume: either a box, or a box-like trapezoid
// UnplacedBox worldUnplaced = UnplacedBox(20., 20., 20.);
// UnplacedTrapezoid worldUnplaced = UnplacedTrapezoid(20., 0., 0., 20., 20., 20., 0., 20., 20., 20., 0.);
auto worldUnplaced = GeoManager::MakeInstance<UnplacedTrapezoid>(20., 0., 0., 20., 20., 20., 0., 20., 20., 20., 0.);
//-- and here for a few alternative internal trapezoids
// UnplacedTrapezoid *trapPtr = nullptr;
VUnplacedVolume *trapPtr = nullptr;
switch (type) {
case 0:
std::cout << "==================================================\n"
<< " Testing box-like trapezoid for npoints = " << npoints << "\n"
<< "==================================================\n";
// trapPtr = new UnplacedTrapezoid(10, 0, 0, 10, 10, 10, 0, 10, 10, 10, 0);
trapPtr = GeoManager::MakeInstance<UnplacedTrapezoid>(10, 0, 0, 10, 10, 10, 0, 10, 10, 10, 0);
break;
case 1:
std::cout << "======================================================\n"
<< " Testing corner-based trapezoid for npoints = " << npoints << "\n"
<< "======================================================\n";
{
// validate construtor for input corner points -- add an xy-offset for non-zero theta,phi
TrapCorners xyz;
Precision xoffset = 9;
Precision yoffset = -6;
// define corner points
// convention: p0(---); p1(+--); p2(-+-); p3(++-); p4(--+); p5(+-+); p6(-++); p7(+++)
xyz[0] = Vector3D<Precision>(-2 + xoffset, -5 + yoffset, -15);
xyz[1] = Vector3D<Precision>(2 + xoffset, -5 + yoffset, -15);
xyz[2] = Vector3D<Precision>(-3 + xoffset, 5 + yoffset, -15);
xyz[3] = Vector3D<Precision>(3 + xoffset, 5 + yoffset, -15);
xyz[4] = Vector3D<Precision>(-4 - xoffset, -10 - yoffset, 15);
xyz[5] = Vector3D<Precision>(4 - xoffset, -10 - yoffset, 15);
xyz[6] = Vector3D<Precision>(-6 - xoffset, 10 - yoffset, 15);
xyz[7] = Vector3D<Precision>(6 - xoffset, 10 - yoffset, 15);
// create trapezoid
trapPtr = new UnplacedTrapezoid(xyz);
}
break;
case 2:
std::cout << "=====================================================================\n"
<< " Testing trapezoid with non-zero Alpha1,Alpha2 for npoints = " << npoints << "\n"
<< "=====================================================================\n";
{
// check geometry derived from JIRA-393 (dividing by 4 in order to fit on world box)
const double ° = kDegToRad;
double theta = 20. * deg;
double phi = 5. * deg;
double alpha = 10. * deg;
// trapPtr = new UnplacedTrapezoid(15, theta, phi, 10, 7.5, 10, alpha, 4, 2.5, 3.5, alpha);
trapPtr = GeoManager::MakeInstance<UnplacedTrapezoid>(15, theta, phi, 10, 7.5, 10, alpha, 4, 2.5, 3.5, alpha);
}
break;
case 3:
std::cout << "=====================================================================\n"
<< " Testing Trd1 like Trapezoid for npoints = " << npoints << "\n"
<< "=====================================================================\n";
{
trapPtr = GeoManager::MakeInstance<UnplacedTrapezoid>(15, 0., 0., 10., 7.5, 7.5, 0., 10., 3.5, 3.5, 0.);
}
break;
case 4:
std::cout << "=====================================================================\n"
<< " Testing Trd2 like Trapezoid for npoints = " << npoints << "\n"
<< "=====================================================================\n";
{
trapPtr = GeoManager::MakeInstance<UnplacedTrapezoid>(15, 0., 0., 10., 7.5, 7.5, 0., 8., 3.5, 3.5, 0.);
}
break;
case 5:
std::cout << "=====================================================================\n"
<< " Testing Parallelepiped like Trapezoid for npoints = " << npoints << "\n"
<< "=====================================================================\n";
{
const double ° = kDegToRad;
double theta = 20. * deg;
double phi = 5. * deg;
double alpha = 10. * deg;
trapPtr = GeoManager::MakeInstance<UnplacedTrapezoid>(15, theta, phi, 10., 7.5, 7.5, alpha, 10., 7.5, 7.5, alpha);
}
break;
default:
std::cout << "\n***** Unknown trapezoid type: " << type << "\n"
<< "\n Valid types:\n"
<< "\t0: box-like trapezoid\n"
<< "\t1: corner-defined trapezoid\n"
<< "\t2: non-zero Alpha1=Alpha2 trapezoid [default]\n";
return 1;
}
trapPtr->Print();
// LogicalVolume world("world", &worldUnplaced);
LogicalVolume world("world", worldUnplaced);
LogicalVolume trap("trap", trapPtr);
// define transformation
Transformation3D *transf = NULL;
transf = new Transformation3D(5, 2, 3, 15, 30, 45);
world.PlaceDaughter(&trap, transf);
// world.PlaceDaughter(&trap, &Transformation3D::kIdentity);
VPlacedVolume *worldPlaced = world.Place();
GeoManager::Instance().SetWorldAndClose(worldPlaced);
Benchmarker tester(GeoManager::Instance().GetWorld());
tester.SetPointCount(npoints);
tester.SetRepetitions(nrep);
tester.SetTolerance(1.e-9);
tester.SetPoolMultiplier(1);
//=== Here is for the validation + one perf data point displayed on screen
tester.SetVerbosity(3);
tester.SetMeasurementCount(1);
auto errcode = tester.RunBenchmark();
// clear benchmark results, so previous measurements won't be written out into the output .csv file
tester.ClearResults();
// Now run to collect statistics for performance plots - written to the .csv output file only
if (nstats > 1) {
// Idea is to start at npoints=2, and then increase it by x2 at a time until maxNpoints is reached
tester.SetVerbosity(0);
tester.SetMeasurementCount(nstats);
npoints = 2;
int maxNpoints = 2048;
#ifdef VECGEOM_ENABLE_CUDA
maxNpoints = 1048576;
#endif
while (npoints <= maxNpoints) {
tester.SetPointCount(npoints);
tester.RunBenchmark();
npoints *= 2;
}
// Save statistics data to a text file
std::list<BenchmarkResult> results = tester.PopResults();
std::ofstream outStream;
outStream.open("trapBenchmarkData.csv", std::fstream::app);
BenchmarkResult::WriteCsvHeader(outStream);
for (auto i = results.begin(), iEnd = results.end(); i != iEnd; ++i) {
i->WriteToCsv(outStream);
}
outStream.close();
}
// cleanup
if (transf) delete transf;
if (trapPtr) delete trapPtr;
return errcode;
}
|