9 #include <boost/format.hpp>
10 #include <boost/test/data/test_case.hpp>
11 #include <boost/test/unit_test.hpp>
31 namespace tt = boost::test_tools;
40 #define CHECK_ROTATION_ANGLE(t, a, tolerance) \
42 Vector3D v = (*t) * Vector3D(1, 0, 0); \
43 CHECK_CLOSE_ABS(VectorHelpers::phi(v), (a), tolerance); \
46 using SrfVec = std::vector<std::shared_ptr<const Surface>>;
52 os << std::fixed << std::setprecision(4);
55 for (
const auto& srfx : surfaces) {
56 std::shared_ptr<const PlaneSurface> srf =
61 for (
const auto& vtxloc : bounds->vertices()) {
64 os <<
"v " << vtx.x() <<
" " << vtx.y() <<
" " << vtx.z() <<
"\n";
69 for (
size_t i = 1; i <= bounds->vertices().size(); ++i) {
70 os <<
" " << nVtx + i;
74 nVtx += bounds->vertices().size();
81 std::shared_ptr<const SurfaceArrayCreator>
p_SAC;
82 std::shared_ptr<LayerCreator>
p_LC;
86 p_SAC = std::make_shared<const SurfaceArrayCreator>(
91 p_LC = std::make_shared<LayerCreator>(
95 template <
typename... Args>
97 return p_LC->checkBinning(std::forward<Args>(args)...);
101 size_t nBins = sArray->
size();
103 for (
size_t i = 0; i < nBins; ++i) {
107 std::vector<const Surface*> binContent = sArray->
at(i);
108 BOOST_TEST_INFO(
"Bin: " << i);
109 BOOST_CHECK_EQUAL(binContent.size(),
n);
110 result = result && binContent.size() ==
n;
117 double zbase = 0,
double r = 10) {
120 double phiStep = 2 *
M_PI /
n;
121 for (
size_t i = 0; i <
n; ++i) {
122 double z = zbase + ((i % 2 == 0) ? 1 : -1) * 0.2;
126 trans.rotate(Eigen::AngleAxisd(i * phiStep + shift,
Vector3D(0, 0, 1)));
129 auto bounds = std::make_shared<const RectangleBounds>(2, 1);
131 auto transptr = std::make_shared<const Transform3D>(trans);
132 std::shared_ptr<PlaneSurface> srf =
133 Surface::makeShared<PlaneSurface>(transptr, bounds);
144 double incl =
M_PI / 9.,
double w = 2,
148 double phiStep = 2 *
M_PI /
n;
149 for (
int i = 0; i <
n; ++i) {
154 trans.rotate(Eigen::AngleAxisd(i * phiStep + shift,
Vector3D(0, 0, 1)));
155 trans.translate(
Vector3D(10, 0, z));
156 trans.rotate(Eigen::AngleAxisd(incl,
Vector3D(0, 0, 1)));
157 trans.rotate(Eigen::AngleAxisd(
M_PI / 2.,
Vector3D(0, 1, 0)));
159 auto bounds = std::make_shared<const RectangleBounds>(
w,
h);
161 auto transptr = std::make_shared<const Transform3D>(trans);
162 std::shared_ptr<PlaneSurface> srf =
163 Surface::makeShared<PlaneSurface>(transptr, bounds);
174 double z0 = -(nZ - 1) * w;
177 for (
int i = 0; i < nZ; i++) {
178 double z = i * w * 2 +
z0;
179 std::cout <<
"z=" << z << std::endl;
181 res.insert(res.end(), ring.begin(), ring.end());
187 std::pair<SrfVec, std::vector<std::pair<const Surface*, const Surface*>>>
189 double w = 2,
double h = 1.5) {
190 double z0 = -(nZ - 1) *
w;
193 std::vector<std::pair<const Surface*, const Surface*>> pairs;
195 for (
int i = 0; i < nZ; i++) {
196 double z = i *
w * 2 +
z0;
198 double phiStep = 2 *
M_PI / nPhi;
199 for (
int j = 0; j < nPhi; ++j) {
202 trans.rotate(Eigen::AngleAxisd(j * phiStep + shift,
Vector3D(0, 0, 1)));
203 trans.translate(
Vector3D(10, 0, z));
204 trans.rotate(Eigen::AngleAxisd(incl,
Vector3D(0, 0, 1)));
205 trans.rotate(Eigen::AngleAxisd(
M_PI / 2.,
Vector3D(0, 1, 0)));
207 auto bounds = std::make_shared<const RectangleBounds>(
w,
h);
209 auto transAptr = std::make_shared<const Transform3D>(trans);
211 std::shared_ptr<PlaneSurface> srfA =
212 Surface::makeShared<PlaneSurface>(transAptr, bounds);
216 transB.pretranslate(nrm * 0.1);
217 auto transBptr = std::make_shared<const Transform3D>(transB);
218 std::shared_ptr<PlaneSurface> srfB =
219 Surface::makeShared<PlaneSurface>(transBptr, bounds);
221 pairs.push_back(std::make_pair(srfA.get(), srfB.get()));
230 return std::make_pair(res, pairs);
234 BOOST_AUTO_TEST_SUITE(Tools)
237 std::vector<std::shared_ptr<const Surface>> srf;
239 srf = makeBarrel(30, 7, 2, 1.5);
240 draw_surfaces(srf,
"LayerCreator_createCylinderLayer_BRL_1.obj");
243 double envR = 0.1, envZ = 0.5;
245 pl.
envR = {envR, envR};
246 pl.
envZ = {envZ, envZ};
247 std::shared_ptr<CylinderLayer>
layer =
251 double rMax = 10.6071, rMin = 9.59111;
257 BOOST_CHECK(checkBinning(
tgContext, *layer->surfaceArray()));
258 auto axes = layer->surfaceArray()->getAxes();
259 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(), 30
u);
260 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), 7
u);
269 pl2.envR = {envR, envR};
270 pl2.envZ = {envZ, envZ};
272 p_LC->cylinderLayer(
tgContext, srf, 30, 7, pl2));
274 bounds = &layer->bounds();
277 BOOST_CHECK(checkBinning(
tgContext, *layer->surfaceArray()));
278 axes = layer->surfaceArray()->getAxes();
279 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(), 30
u);
280 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), 7
u);
287 p_LC->cylinderLayer(
tgContext, srf, 13, 3, pl2));
289 bounds = &layer->bounds();
294 BOOST_CHECK(checkBinning(
tgContext, *layer->surfaceArray()));
295 axes = layer->surfaceArray()->getAxes();
296 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(), 13
u);
297 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), 3
u);
312 bounds = &layer->bounds();
319 BOOST_CHECK(checkBinning(
tgContext, *layer->surfaceArray()));
321 axes = layer->surfaceArray()->getAxes();
322 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(), 30
u);
323 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), 7
u);
331 std::vector<std::shared_ptr<const Surface>> surfaces;
332 auto ringa = fullPhiTestSurfacesEC(30, 0, 0, 10);
333 surfaces.insert(surfaces.end(), ringa.begin(), ringa.end());
334 auto ringb = fullPhiTestSurfacesEC(30, 0, 0, 15);
335 surfaces.insert(surfaces.end(), ringb.begin(), ringb.end());
336 auto ringc = fullPhiTestSurfacesEC(30, 0, 0, 20);
337 surfaces.insert(surfaces.end(), ringc.begin(), ringc.end());
338 draw_surfaces(surfaces,
"LayerCreator_createDiscLayer_EC_1.obj");
352 BOOST_CHECK(checkBinning(
tgContext, *layer->surfaceArray()));
353 auto axes = layer->surfaceArray()->getAxes();
354 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(), 3
u);
355 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), 30
u);
360 checkBinContentSize(layer->surfaceArray(), 1);
368 double envMinR = 1, envMaxR = 1, envZ = 5;
369 size_t nBinsR = 3, nBinsPhi = 30;
371 pl2.
envR = {envMinR, envMaxR};
372 pl2.
envZ = {envZ, envZ};
374 p_LC->discLayer(
tgContext, surfaces, nBinsR, nBinsPhi, pl2));
376 double rMin = 8, rMax = 22.0227;
378 bounds =
dynamic_cast<const RadialBounds*
>(&layer->bounds());
381 BOOST_CHECK(checkBinning(
tgContext, *layer->surfaceArray()));
382 axes = layer->surfaceArray()->getAxes();
383 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(),
nBinsR);
384 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), nBinsPhi);
389 checkBinContentSize(layer->surfaceArray(), 1);
400 bounds =
dynamic_cast<const RadialBounds*
>(&layer->bounds());
403 BOOST_CHECK(checkBinning(
tgContext, *layer->surfaceArray()));
404 axes = layer->surfaceArray()->getAxes();
405 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(),
nBinsR);
406 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), nBinsPhi);
411 checkBinContentSize(layer->surfaceArray(), 1);
421 auto barrel = makeBarrelStagger(30, 7, 0,
M_PI / 9.);
422 auto brl = barrel.first;
425 double envR = 0, envZ = 0;
427 pl.
envR = {envR, envR};
428 pl.
envZ = {envZ, envZ};
429 std::shared_ptr<CylinderLayer>
layer =
434 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(), 30
u);
435 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), 7
u);
438 for (
const auto&
pr : barrel.second) {
448 auto binContent = layer->surfaceArray()->at(ctr);
449 BOOST_CHECK_EQUAL(binContent.size(), 2
u);
450 std::set<const Surface*> act;
451 act.insert(binContent[0]);
452 act.insert(binContent[1]);
454 std::set<const Surface*> exp;
457 BOOST_CHECK(exp == act);
461 checkBinning(
tgContext, *layer->surfaceArray());
464 BOOST_AUTO_TEST_SUITE_END()