9 #include <boost/test/data/test_case.hpp>
10 #include <boost/test/unit_test.hpp>
48 #include <boost/format.hpp>
54 namespace tt = boost::test_tools;
63 #define CHECK_ROTATION_ANGLE(t, a, tolerance) \
65 Vector3 v = (*t) * Vector3(1, 0, 0); \
66 CHECK_CLOSE_ABS(phi(v), (a), tolerance); \
69 using SrfVec = std::vector<std::shared_ptr<const Surface>>;
79 BOOST_TEST_MESSAGE(
"setup fixture");
83 template <
typename...
Args>
88 template <
typename...
Args>
98 std::forward<Args>(
args)...);
102 double zbase = 0,
double r = 10,
double w = 2,
107 double phiStep = 2 * M_PI /
n;
108 for (
size_t i = 0;
i <
n; ++
i) {
109 double z = zbase + ((
i % 2 == 0) ? 1 : -1) * 0.2;
110 double phi = std::fma(
i, phiStep, shift);
114 trans.rotate(Eigen::AngleAxisd(phi,
Vector3(0, 0, 1)));
117 auto bounds = std::make_shared<const RectangleBounds>(w,
h);
119 std::shared_ptr<Surface> srf =
120 Surface::makeShared<PlaneSurface>(trans,
bounds);
131 double zbase = 0,
double incl = M_PI / 9.,
132 double w = 2,
double h = 1.5) {
136 double phiStep = 2 * M_PI /
n;
137 for (
size_t i = 0;
i <
n; ++
i) {
139 double phi = std::fma(
i, phiStep, shift);
143 trans.rotate(Eigen::AngleAxisd(phi,
Vector3(0, 0, 1)));
144 trans.translate(
Vector3(10, 0, z));
145 trans.rotate(Eigen::AngleAxisd(incl,
Vector3(0, 0, 1)));
146 trans.rotate(Eigen::AngleAxisd(M_PI / 2.,
Vector3(0, 1, 0)));
148 auto bounds = std::make_shared<const RectangleBounds>(w,
h);
149 std::shared_ptr<Surface> srf =
150 Surface::makeShared<PlaneSurface>(trans,
bounds);
162 const Transform3& pretrans = Transform3::Identity(),
163 const Vector3& dir = {0, 0, 1}) {
165 for (
size_t i = 0;
i <
n; ++
i) {
171 trans = trans * pretrans;
173 auto bounds = std::make_shared<const RectangleBounds>(2, 1.5);
175 std::shared_ptr<Surface> srf =
176 Surface::makeShared<PlaneSurface>(trans,
bounds);
187 double z0 = -(nZ - 1) * w;
190 for (
int i = 0; i < nZ; i++) {
191 double z = i * w * 2 + z0;
194 res.insert(res.end(), ring.begin(), ring.end());
200 std::pair<SrfVec, std::vector<std::pair<const Surface*, const Surface*>>>
202 double w = 2,
double h = 1.5) {
203 double z0 = -(nZ - 1) * w;
205 std::vector<std::pair<const Surface*, const Surface*>> pairs;
208 double phiStep = 2 * M_PI / nPhi;
209 for (
int i = 0; i < nZ; i++) {
210 double z = i * w * 2 + z0;
211 for (
int j = 0;
j < nPhi; ++
j) {
212 double phi = std::fma(
j, phiStep, shift);
215 trans.rotate(Eigen::AngleAxisd(phi,
Vector3(0, 0, 1)));
216 trans.translate(
Vector3(10, 0, z));
217 trans.rotate(Eigen::AngleAxisd(incl,
Vector3(0, 0, 1)));
218 trans.rotate(Eigen::AngleAxisd(M_PI / 2.,
Vector3(0, 1, 0)));
220 auto bounds = std::make_shared<const RectangleBounds>(w,
h);
221 std::shared_ptr<Surface> srfA =
222 Surface::makeShared<PlaneSurface>(trans,
bounds);
226 transB.pretranslate(nrm * 0.1);
227 std::shared_ptr<Surface> srfB =
228 Surface::makeShared<PlaneSurface>(transB,
bounds);
230 pairs.push_back(std::make_pair(srfA.get(), srfB.get()));
239 return std::make_pair(res, pairs);
247 os << std::fixed << std::setprecision(4);
250 for (
const auto& srfx : surfaces) {
251 std::shared_ptr<const PlaneSurface> srf =
256 for (
const auto& vtxloc : bounds->vertices()) {
259 os <<
"v " << vtx.x() <<
" " << vtx.y() <<
" " << vtx.z() <<
"\n";
264 for (
size_t i = 1; i <= bounds->vertices().size(); ++
i) {
265 os <<
" " << nVtx +
i;
269 nVtx += bounds->vertices().size();
275 BOOST_AUTO_TEST_SUITE(Tools)
280 std::vector<const Surface*> emptyRaw;
282 auto tr = Transform3::Identity();
287 std::vector<float> bdExp = {
288 -3.14159, -2.93215, -2.72271, -2.51327, -2.30383, -2.0944, -1.88496,
289 -1.67552, -1.46608, -1.25664, -1.0472, -0.837758, -0.628319, -0.418879,
290 -0.20944, 0, 0.20944, 0.418879, 0.628319, 0.837758, 1.0472,
291 1.25664, 1.46608, 1.67552, 1.88496, 2.09439, 2.30383, 2.51327,
292 2.72271, 2.93215, 3.14159};
294 double step = 2 * M_PI / 30.;
298 for (
int i = -1; i <= 2; i += 2) {
301 double angleShift = step / 2.;
302 auto surfaces = fullPhiTestSurfacesEC(30, angleShift, z);
305 tr = Transform3::Identity();
306 auto axis = createEquidistantAxis(
tgContext, surfacesRaw,
309 BOOST_CHECK_EQUAL(axis.nBins, 30
u);
317 surfaces = fullPhiTestSurfacesEC(30, angleShift, z);
320 tr = Transform3::Identity();
324 "SurfaceArrayCreator_createEquidistantAxis_EC_2.obj");
325 BOOST_CHECK_EQUAL(axis.nBins, 30
u);
332 angleShift = step / -4.;
333 surfaces = fullPhiTestSurfacesEC(30, angleShift, z);
336 tr = Transform3::Identity();
340 "SurfaceArrayCreator_createEquidistantAxis_EC_3.obj");
341 BOOST_CHECK_EQUAL(axis.nBins, 30
u);
348 angleShift = step / 4.;
349 surfaces = fullPhiTestSurfacesEC(30, angleShift, z);
353 tr = Transform3::Identity();
358 "SurfaceArrayCreator_createEquidistantAxis_EC_4.obj");
359 BOOST_CHECK_EQUAL(axis.nBins, 30
u);
366 for (
int i = -1; i <= 2; i += 2) {
369 double angleShift = step / 2.;
370 auto surfaces = fullPhiTestSurfacesBRL(30, angleShift, z);
373 tr = Transform3::Identity();
374 auto axis = createEquidistantAxis(
tgContext, surfacesRaw,
377 "SurfaceArrayCreator_createEquidistantAxis_BRL_1.obj");
378 BOOST_CHECK_EQUAL(axis.nBins, 30
u);
386 surfaces = fullPhiTestSurfacesBRL(30, angleShift, z);
389 tr = Transform3::Identity();
393 "SurfaceArrayCreator_createEquidistantAxis_BRL_2.obj");
394 BOOST_CHECK_EQUAL(axis.nBins, 30
u);
402 angleShift = step / -4.;
403 surfaces = fullPhiTestSurfacesBRL(30, angleShift, z);
406 tr = Transform3::Identity();
410 "SurfaceArrayCreator_createEquidistantAxis_BRL_3.obj");
411 BOOST_CHECK_EQUAL(axis.nBins, 30
u);
419 angleShift = step / 4.;
420 surfaces = fullPhiTestSurfacesBRL(30, angleShift, z);
423 tr = Transform3::Identity();
427 "SurfaceArrayCreator_createEquidistantAxis_BRL_4.obj");
428 BOOST_CHECK_EQUAL(axis.nBins, 30
u);
439 surfaces = fullPhiTestSurfacesEC(1);
442 "SurfaceArrayCreator_createEquidistantAxis_EC_Single.obj");
445 tr = Transform3::Identity();
446 auto axis = createEquidistantAxis(
tgContext, surfacesRaw,
448 BOOST_CHECK_EQUAL(axis.nBins, 1
u);
458 auto surfaces = straightLineSurfaces(1);
461 auto trf = Transform3::Identity();
464 draw_surfaces(surfaces,
"SurfaceArrayCreator_createEquidistantAxis_Z_1.obj");
465 BOOST_CHECK_EQUAL(axis.nBins, 1
u);
471 for (
size_t i = 0; i <= 20; i++) {
472 double z0 = -10 + 1. *
i;
473 surfaces = straightLineSurfaces(10, 3,
Vector3(0, 0, z0 + 1.5));
476 trf = Transform3::Identity();
482 "SurfaceArrayCreator_createEquidistantAxis_Z_2_%1%.obj") %
485 BOOST_CHECK_EQUAL(axis.nBins, 10
u);
494 surfaces = straightLineSurfaces(10, 3,
Vector3(0, 0, 0 + 1.5), tr);
497 trf = Transform3::Identity();
500 draw_surfaces(surfaces,
"SurfaceArrayCreator_createEquidistantAxis_Z_3.obj");
501 BOOST_CHECK_EQUAL(axis.nBins, 10
u);
510 auto surfaces = fullPhiTestSurfacesEC(1, 0, 0, 15);
512 draw_surfaces(surfaces,
"SurfaceArrayCreator_createEquidistantAxis_R_1.obj");
513 auto trf = Transform3::Identity();
517 BOOST_CHECK_EQUAL(axis.nBins, 1
u);
524 auto ringa = fullPhiTestSurfacesEC(30, 0, 0, 10);
525 surfaces.insert(surfaces.end(), ringa.begin(), ringa.end());
526 auto ringb = fullPhiTestSurfacesEC(30, 0, 0, 15);
527 surfaces.insert(surfaces.end(), ringb.begin(), ringb.end());
528 auto ringc = fullPhiTestSurfacesEC(30, 0, 0, 20);
529 surfaces.insert(surfaces.end(), ringc.begin(), ringc.end());
530 draw_surfaces(surfaces,
"SurfaceArrayCreator_createEquidistantAxis_R_2.obj");
534 trf = Transform3::Identity();
538 BOOST_CHECK_EQUAL(axis.nBins, 3
u);
551 auto ringA = fullPhiTestSurfacesEC(10, 0, 0, 10, 2, 3);
552 auto ringB = fullPhiTestSurfacesEC(15, 0, 0, 15, 2, 3.5);
553 auto ringC = fullPhiTestSurfacesEC(20, 0, 0, 20, 2, 3.8);
555 std::vector<std::shared_ptr<const Surface>> surfaces;
556 std::copy(ringA.begin(), ringA.end(), std::back_inserter(surfaces));
557 std::copy(ringB.begin(), ringB.end(), std::back_inserter(surfaces));
558 std::copy(ringC.begin(), ringC.end(), std::back_inserter(surfaces));
559 draw_surfaces(surfaces,
"SurfaceArrayCreator_dependentBinCounts.obj");
561 std::unique_ptr<SurfaceArray> sArray =
563 auto axes = sArray->getAxes();
564 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(), 3
u);
565 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), 10
u);
570 objVis.write(
"SurfaceArrayCreator_EndcapGrid");
575 SrfVec brl = makeBarrel(30, 7, 2, 1);
577 draw_surfaces(brl,
"SurfaceArrayCreator_completeBinning_BRL.obj");
579 detail::Axis<detail::AxisType::Equidistant, detail::AxisBoundaryType::Closed>
580 phiAxis(-M_PI, M_PI, 30
u);
581 detail::Axis<detail::AxisType::Equidistant, detail::AxisBoundaryType::Bound>
589 double phi =
loc[0] - 2 * M_PI / 30 / 2;
590 return Vector3(R * std::cos(phi), R * std::sin(phi),
loc[1]);
593 auto sl = std::make_unique<
595 globalToLocal, localToGlobal,
603 objVis.
write(
"SurfaceArrayCreator_BarrelGrid");
606 for (
const auto& srf : brl) {
608 auto binContent = sa.
at(ctr);
610 BOOST_CHECK_EQUAL(binContent.size(), 1
u);
611 BOOST_CHECK_EQUAL(srf.get(), binContent.at(0));
617 auto barrel = makeBarrelStagger(30, 7, 0, M_PI / 9.);
618 auto brl = barrel.first;
635 auto globalToLocal = [tr](
const Vector3&
pos) {
639 auto localToGlobal = [
R, itr](
const Vector2&
loc) {
643 auto sl = makeSurfaceGridLookup2D<detail::AxisBoundaryType::Closed,
644 detail::AxisBoundaryType::Bound>(
645 globalToLocal, localToGlobal, pAxisPhi, pAxisZ);
650 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(), 30
u);
651 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), 7
u);
653 for (
const auto& pr : barrel.second) {
658 auto binContent = sa.
at(ctr);
659 BOOST_CHECK_EQUAL(binContent.size(), 2
u);
660 std::set<const Surface*> act;
661 act.insert(binContent[0]);
662 act.insert(binContent[1]);
664 std::set<const Surface*> exp;
668 BOOST_CHECK(act == exp);
672 BOOST_TEST_CONTEXT(
"Barrel Stagger Variable binning") {
673 tr = Transform3::Identity();
682 auto globalToLocalVar = [tr](
const Vector3&
pos) {
686 auto localToGlobalVar = [
R, itr](
const Vector2&
loc) {
690 auto sl2 = makeSurfaceGridLookup2D<detail::AxisBoundaryType::Closed,
691 detail::AxisBoundaryType::Bound>(
692 globalToLocalVar, localToGlobalVar, pAxisPhiVar, pAxisZVar);
697 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(), 30
u);
698 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), 7
u);
701 std::vector<double> phiEdgesExp = {
702 -3.14159, -2.93215, -2.72271, -2.51327, -2.30383, -2.0944,
703 -1.88496, -1.67552, -1.46608, -1.25664, -1.0472, -0.837758,
704 -0.628319, -0.418879, -0.20944, 4.44089e-16, 0.20944, 0.418879,
705 0.628319, 0.837758, 1.0472, 1.25664, 1.46608, 1.67552,
706 1.88496, 2.0944, 2.30383, 2.51327, 2.72271, 3.00831,
708 std::vector<double> zEdgesExp = {-14, -10, -6, -2, 2, 6, 10, 14};
710 for (
const auto&
edge : axes.at(0)->getBinEdges()) {
711 BOOST_TEST_INFO(
"phi edge index " << i);
712 auto phiEdge = phiEdgesExp.at(i);
717 for (
const auto&
edge : axes.at(1)->getBinEdges()) {
718 BOOST_TEST_INFO(
"z edge index " << i);
723 for (
const auto& pr : barrel.second) {
728 auto binContent = sa2.
at(ctr);
729 BOOST_CHECK_EQUAL(binContent.size(), 2
u);
730 std::set<const Surface*> act;
731 act.insert(binContent[0]);
732 act.insert(binContent[1]);
734 std::set<const Surface*> exp;
738 BOOST_CHECK(act == exp);
743 BOOST_AUTO_TEST_SUITE_END()