9 #include <boost/test/data/test_case.hpp>
10 #include <boost/test/unit_test.hpp>
29 #include <boost/format.hpp>
32 namespace tt = boost::test_tools;
41 #define CHECK_ROTATION_ANGLE(t, a, tolerance) \
43 Vector3D v = (*t) * Vector3D(1, 0, 0); \
44 CHECK_CLOSE_ABS(VectorHelpers::phi(v), (a), tolerance); \
47 using SrfVec = std::vector<std::shared_ptr<const Surface>>;
53 os << std::fixed << std::setprecision(4);
56 for (
const auto& srfx : surfaces) {
57 std::shared_ptr<const PlaneSurface> srf =
62 for (
const auto& vtxloc : bounds->vertices()) {
65 os <<
"v " << vtx.x() <<
" " << vtx.y() <<
" " << vtx.z() <<
"\n";
70 for (
size_t i = 1; i <= bounds->vertices().size(); ++i) {
71 os <<
" " << nVtx + i;
75 nVtx += bounds->vertices().size();
82 std::shared_ptr<const SurfaceArrayCreator>
p_SAC;
83 std::shared_ptr<LayerCreator>
p_LC;
88 p_SAC = std::make_shared<const SurfaceArrayCreator>(
93 p_LC = std::make_shared<LayerCreator>(
97 template <
typename... Args>
99 return p_LC->checkBinning(std::forward<Args>(
args)...);
103 size_t nBins = sArray->
size();
105 for (
size_t i = 0; i < nBins; ++i) {
109 std::vector<const Surface*> binContent = sArray->
at(i);
110 BOOST_TEST_INFO(
"Bin: " << i);
111 BOOST_CHECK_EQUAL(binContent.size(),
n);
112 result = result && binContent.size() ==
n;
119 double zbase = 0,
double r = 10) {
122 double phiStep = 2 *
M_PI /
n;
123 for (
size_t i = 0; i <
n; ++i) {
124 double z = zbase + ((i % 2 == 0) ? 1 : -1) * 0.2;
128 trans.rotate(Eigen::AngleAxisd(i * phiStep + shift,
Vector3D(0, 0, 1)));
131 auto bounds = std::make_shared<const RectangleBounds>(2, 1);
132 std::shared_ptr<PlaneSurface> srf =
133 Surface::makeShared<PlaneSurface>(trans, 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);
160 std::shared_ptr<PlaneSurface> srf =
161 Surface::makeShared<PlaneSurface>(trans, bounds);
172 double z0 = -(nZ - 1) * w;
175 for (
int i = 0; i < nZ; i++) {
176 double z = i * w * 2 + z0;
177 std::cout <<
"z=" << z << std::endl;
179 res.insert(res.end(), ring.begin(), ring.end());
185 std::pair<SrfVec, std::vector<std::pair<const Surface*, const Surface*>>>
187 double w = 2,
double h = 1.5) {
188 double z0 = -(nZ - 1) * w;
191 std::vector<std::pair<const Surface*, const Surface*>> pairs;
193 for (
int i = 0; i < nZ; i++) {
194 double z = i * w * 2 + z0;
196 double phiStep = 2 *
M_PI / nPhi;
197 for (
int j = 0; j < nPhi; ++j) {
200 trans.rotate(Eigen::AngleAxisd(j * phiStep + shift,
Vector3D(0, 0, 1)));
201 trans.translate(
Vector3D(10, 0, z));
202 trans.rotate(Eigen::AngleAxisd(incl,
Vector3D(0, 0, 1)));
203 trans.rotate(Eigen::AngleAxisd(
M_PI / 2.,
Vector3D(0, 1, 0)));
205 auto bounds = std::make_shared<const RectangleBounds>(w,
h);
206 std::shared_ptr<PlaneSurface> srfA =
207 Surface::makeShared<PlaneSurface>(trans, bounds);
211 transB.pretranslate(nrm * 0.1);
212 std::shared_ptr<PlaneSurface> srfB =
213 Surface::makeShared<PlaneSurface>(transB, bounds);
215 pairs.push_back(std::make_pair(srfA.get(), srfB.get()));
224 return std::make_pair(res, pairs);
228 BOOST_AUTO_TEST_SUITE(Tools)
231 std::vector<std::shared_ptr<const Surface>> srf;
233 srf = makeBarrel(30, 7, 2, 1.5);
234 draw_surfaces(srf,
"LayerCreator_createCylinderLayer_BRL_1.obj");
237 double envR = 0.1, envZ = 0.5;
241 std::shared_ptr<CylinderLayer>
layer =
246 double rMax = 10.6071, rMin = 9.59111;
252 BOOST_CHECK(checkBinning(
tgContext, *layer->surfaceArray()));
253 auto axes = layer->surfaceArray()->getAxes();
254 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(), 30
u);
255 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), 7
u);
267 p_LC->cylinderLayer(
tgContext, srf, 30, 7, pl2));
269 bounds = &layer->bounds();
272 BOOST_CHECK(checkBinning(
tgContext, *layer->surfaceArray()));
273 axes = layer->surfaceArray()->getAxes();
274 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(), 30
u);
275 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), 7
u);
282 p_LC->cylinderLayer(
tgContext, srf, 13, 3, pl2));
284 bounds = &layer->bounds();
289 BOOST_CHECK(checkBinning(
tgContext, *layer->surfaceArray()));
290 axes = layer->surfaceArray()->getAxes();
291 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(), 13
u);
292 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), 3
u);
305 bounds = &layer->bounds();
312 BOOST_CHECK(checkBinning(
tgContext, *layer->surfaceArray()));
314 axes = layer->surfaceArray()->getAxes();
315 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(), 30
u);
316 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), 7
u);
324 std::vector<std::shared_ptr<const Surface>> surfaces;
325 auto ringa = fullPhiTestSurfacesEC(30, 0, 0, 10);
326 surfaces.insert(surfaces.end(), ringa.begin(), ringa.end());
327 auto ringb = fullPhiTestSurfacesEC(30, 0, 0, 15);
328 surfaces.insert(surfaces.end(), ringb.begin(), ringb.end());
329 auto ringc = fullPhiTestSurfacesEC(30, 0, 0, 20);
330 surfaces.insert(surfaces.end(), ringc.begin(), ringc.end());
331 draw_surfaces(surfaces,
"LayerCreator_createDiscLayer_EC_1.obj");
343 BOOST_CHECK(checkBinning(
tgContext, *layer->surfaceArray()));
344 auto axes = layer->surfaceArray()->getAxes();
345 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(), 3
u);
346 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), 30
u);
351 checkBinContentSize(layer->surfaceArray(), 1);
359 double envMinR = 1, envMaxR = 1, envZ = 5;
360 size_t nBinsR = 3, nBinsPhi = 30;
365 p_LC->discLayer(
tgContext, surfaces, nBinsR, nBinsPhi, pl2));
367 double rMin = 8, rMax = 22.0227;
369 bounds =
dynamic_cast<const RadialBounds*
>(&layer->bounds());
372 BOOST_CHECK(checkBinning(
tgContext, *layer->surfaceArray()));
373 axes = layer->surfaceArray()->getAxes();
374 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(),
nBinsR);
375 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), nBinsPhi);
380 checkBinContentSize(layer->surfaceArray(), 1);
391 bounds =
dynamic_cast<const RadialBounds*
>(&layer->bounds());
394 BOOST_CHECK(checkBinning(
tgContext, *layer->surfaceArray()));
395 axes = layer->surfaceArray()->getAxes();
396 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(),
nBinsR);
397 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), nBinsPhi);
402 checkBinContentSize(layer->surfaceArray(), 1);
412 auto barrel = makeBarrelStagger(30, 7, 0,
M_PI / 9.);
413 auto brl = barrel.first;
416 double envR = 0, envZ = 0;
420 std::shared_ptr<CylinderLayer>
layer =
425 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(), 30
u);
426 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), 7
u);
429 for (
const auto& pr : barrel.second) {
439 auto binContent = layer->surfaceArray()->at(ctr);
440 BOOST_CHECK_EQUAL(binContent.size(), 2
u);
441 std::set<const Surface*> act;
442 act.insert(binContent[0]);
443 act.insert(binContent[1]);
445 std::set<const Surface*> exp;
448 BOOST_CHECK(exp == act);
452 checkBinning(
tgContext, *layer->surfaceArray());
455 BOOST_AUTO_TEST_SUITE_END()