9 #include <boost/test/data/test_case.hpp>
10 #include <boost/test/unit_test.hpp>
46 #include <boost/format.hpp>
49 namespace tt = boost::test_tools;
58 #define CHECK_ROTATION_ANGLE(t, a, tolerance) \
60 Vector3 v = (*t) * Vector3(1, 0, 0); \
61 CHECK_CLOSE_ABS(VectorHelpers::phi(v), (a), tolerance); \
64 using SrfVec = std::vector<std::shared_ptr<const Surface>>;
70 os << std::fixed << std::setprecision(4);
73 for (
const auto& srfx : surfaces) {
74 std::shared_ptr<const PlaneSurface> srf =
79 for (
const auto& vtxloc : bounds->vertices()) {
82 os <<
"v " << vtx.x() <<
" " << vtx.y() <<
" " << vtx.z() <<
"\n";
87 for (
size_t i = 1;
i <= bounds->vertices().size(); ++
i) {
88 os <<
" " << nVtx +
i;
92 nVtx += bounds->vertices().size();
99 std::shared_ptr<const SurfaceArrayCreator>
p_SAC;
100 std::shared_ptr<LayerCreator>
p_LC;
105 p_SAC = std::make_shared<const SurfaceArrayCreator>(
109 cfg.surfaceArrayCreator =
p_SAC;
110 p_LC = std::make_shared<LayerCreator>(
114 template <
typename...
Args>
116 return p_LC->checkBinning(std::forward<Args>(
args)...);
120 size_t nBins = sArray->
size();
122 for (
size_t i = 0;
i < nBins; ++
i) {
126 std::vector<const Surface*> binContent = sArray->
at(
i);
127 BOOST_TEST_INFO(
"Bin: " <<
i);
128 BOOST_CHECK_EQUAL(binContent.size(),
n);
129 result = result && binContent.size() ==
n;
136 double zbase = 0,
double r = 10) {
139 double phiStep = 2 * M_PI /
n;
140 for (
size_t i = 0;
i <
n; ++
i) {
141 double z = zbase + ((
i % 2 == 0) ? 1 : -1) * 0.2;
145 trans.rotate(Eigen::AngleAxisd(
i * phiStep + shift,
Vector3(0, 0, 1)));
148 auto bounds = std::make_shared<const RectangleBounds>(2, 1);
149 std::shared_ptr<PlaneSurface> srf =
150 Surface::makeShared<PlaneSurface>(trans,
bounds);
161 double incl = M_PI / 9.,
double w = 2,
165 double phiStep = 2 * M_PI /
n;
166 for (
int i = 0;
i <
n; ++
i) {
171 trans.rotate(Eigen::AngleAxisd(
i * phiStep + shift,
Vector3(0, 0, 1)));
172 trans.translate(
Vector3(10, 0, z));
173 trans.rotate(Eigen::AngleAxisd(incl,
Vector3(0, 0, 1)));
174 trans.rotate(Eigen::AngleAxisd(M_PI / 2.,
Vector3(0, 1, 0)));
176 auto bounds = std::make_shared<const RectangleBounds>(w,
h);
177 std::shared_ptr<PlaneSurface> srf =
178 Surface::makeShared<PlaneSurface>(trans,
bounds);
189 double z0 = -(nZ - 1) * w;
192 for (
int i = 0;
i < nZ;
i++) {
193 double z =
i * w * 2 + z0;
194 std::cout <<
"z=" << z << std::endl;
196 res.insert(res.end(), ring.begin(), ring.end());
202 std::pair<SrfVec, std::vector<std::pair<const Surface*, const Surface*>>>
204 double w = 2,
double h = 1.5) {
205 double z0 = -(nZ - 1) * w;
208 std::vector<std::pair<const Surface*, const Surface*>> pairs;
210 for (
int i = 0;
i < nZ;
i++) {
211 double z =
i * w * 2 + z0;
213 double phiStep = 2 * M_PI / nPhi;
214 for (
int j = 0;
j < nPhi; ++
j) {
217 trans.rotate(Eigen::AngleAxisd(
j * phiStep + shift,
Vector3(0, 0, 1)));
218 trans.translate(
Vector3(10, 0, z));
219 trans.rotate(Eigen::AngleAxisd(incl,
Vector3(0, 0, 1)));
220 trans.rotate(Eigen::AngleAxisd(M_PI / 2.,
Vector3(0, 1, 0)));
222 auto bounds = std::make_shared<const RectangleBounds>(w,
h);
223 std::shared_ptr<PlaneSurface> srfA =
224 Surface::makeShared<PlaneSurface>(trans,
bounds);
228 transB.pretranslate(nrm * 0.1);
229 std::shared_ptr<PlaneSurface> srfB =
230 Surface::makeShared<PlaneSurface>(transB,
bounds);
232 pairs.push_back(std::make_pair(srfA.get(), srfB.get()));
241 return std::make_pair(res, pairs);
245 BOOST_AUTO_TEST_SUITE(Tools)
248 std::vector<std::shared_ptr<const Surface>> srf;
250 srf = makeBarrel(30, 7, 2, 1.5);
251 draw_surfaces(srf,
"LayerCreator_createCylinderLayer_BRL_1.obj");
254 double envR = 0.1, envZ = 0.5;
258 std::shared_ptr<CylinderLayer>
layer =
263 double rMax = 10.6071, rMin = 9.59111;
269 BOOST_CHECK(checkBinning(
tgContext, *layer->surfaceArray()));
270 auto axes = layer->surfaceArray()->getAxes();
271 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(), 30
u);
272 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), 7
u);
284 p_LC->cylinderLayer(
tgContext, srf, 30, 7, pl2));
286 bounds = &layer->bounds();
289 BOOST_CHECK(checkBinning(
tgContext, *layer->surfaceArray()));
290 axes = layer->surfaceArray()->getAxes();
291 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(), 30
u);
292 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), 7
u);
299 p_LC->cylinderLayer(
tgContext, srf, 13, 3, pl2));
301 bounds = &layer->bounds();
306 BOOST_CHECK(checkBinning(
tgContext, *layer->surfaceArray()));
307 axes = layer->surfaceArray()->getAxes();
308 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(), 13
u);
309 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), 3
u);
322 bounds = &layer->bounds();
329 BOOST_CHECK(checkBinning(
tgContext, *layer->surfaceArray()));
331 axes = layer->surfaceArray()->getAxes();
332 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(), 30
u);
333 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), 7
u);
341 std::vector<std::shared_ptr<const Surface>> surfaces;
342 auto ringa = fullPhiTestSurfacesEC(30, 0, 0, 10);
343 surfaces.insert(surfaces.end(), ringa.begin(), ringa.end());
344 auto ringb = fullPhiTestSurfacesEC(30, 0, 0, 15);
345 surfaces.insert(surfaces.end(), ringb.begin(), ringb.end());
346 auto ringc = fullPhiTestSurfacesEC(30, 0, 0, 20);
347 surfaces.insert(surfaces.end(), ringc.begin(), ringc.end());
348 draw_surfaces(surfaces,
"LayerCreator_createDiscLayer_EC_1.obj");
360 BOOST_CHECK(checkBinning(
tgContext, *layer->surfaceArray()));
361 auto axes = layer->surfaceArray()->getAxes();
362 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(), 3
u);
363 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), 30
u);
368 checkBinContentSize(layer->surfaceArray(), 1);
376 double envMinR = 1, envMaxR = 1, envZ = 5;
377 size_t nBinsR = 3, nBinsPhi = 30;
382 p_LC->discLayer(
tgContext, surfaces, nBinsR, nBinsPhi, pl2));
384 double rMin = 8, rMax = 22.0227;
386 bounds =
dynamic_cast<const RadialBounds*
>(&layer->bounds());
389 BOOST_CHECK(checkBinning(
tgContext, *layer->surfaceArray()));
390 axes = layer->surfaceArray()->getAxes();
391 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(),
nBinsR);
392 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), nBinsPhi);
397 checkBinContentSize(layer->surfaceArray(), 1);
408 bounds =
dynamic_cast<const RadialBounds*
>(&layer->bounds());
411 BOOST_CHECK(checkBinning(
tgContext, *layer->surfaceArray()));
412 axes = layer->surfaceArray()->getAxes();
413 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(),
nBinsR);
414 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), nBinsPhi);
419 checkBinContentSize(layer->surfaceArray(), 1);
429 auto barrel = makeBarrelStagger(30, 7, 0, M_PI / 9.);
430 auto brl = barrel.first;
433 double envR = 0, envZ = 0;
437 std::shared_ptr<CylinderLayer>
layer =
442 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(), 30
u);
443 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), 7
u);
446 for (
const auto& pr : barrel.second) {
456 auto binContent = layer->surfaceArray()->at(ctr);
457 BOOST_CHECK_EQUAL(binContent.size(), 2
u);
458 std::set<const Surface*> act;
459 act.insert(binContent[0]);
460 act.insert(binContent[1]);
462 std::set<const Surface*> exp;
465 BOOST_CHECK(exp == act);
469 checkBinning(
tgContext, *layer->surfaceArray());
472 BOOST_AUTO_TEST_SUITE_END()