9 #include <boost/test/data/test_case.hpp>
10 #include <boost/test/unit_test.hpp>
25 #include <boost/format.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(phi(v), (a), tolerance); \
46 using SrfVec = std::vector<std::shared_ptr<const Surface>>;
56 BOOST_TEST_MESSAGE(
"setup fixture");
60 template <
typename... Args>
65 template <
typename... Args>
75 std::forward<Args>(
args)...);
79 double zbase = 0,
double r = 10,
double w = 2,
84 double phiStep = 2 *
M_PI /
n;
85 for (
size_t i = 0; i <
n; ++i) {
86 double z = zbase + ((i % 2 == 0) ? 1 : -1) * 0.2;
87 double phi = std::fma(i, phiStep, shift);
91 trans.rotate(Eigen::AngleAxisd(phi,
Vector3D(0, 0, 1)));
94 auto bounds = std::make_shared<const RectangleBounds>(w,
h);
96 std::shared_ptr<Surface> srf =
97 Surface::makeShared<PlaneSurface>(trans, bounds);
108 double zbase = 0,
double incl =
M_PI / 9.,
109 double w = 2,
double h = 1.5) {
113 double phiStep = 2 *
M_PI /
n;
114 for (
size_t i = 0; i <
n; ++i) {
116 double phi = std::fma(i, phiStep, shift);
120 trans.rotate(Eigen::AngleAxisd(phi,
Vector3D(0, 0, 1)));
121 trans.translate(
Vector3D(10, 0, z));
122 trans.rotate(Eigen::AngleAxisd(incl,
Vector3D(0, 0, 1)));
123 trans.rotate(Eigen::AngleAxisd(
M_PI / 2.,
Vector3D(0, 1, 0)));
125 auto bounds = std::make_shared<const RectangleBounds>(w,
h);
126 std::shared_ptr<Surface> srf =
127 Surface::makeShared<PlaneSurface>(trans, bounds);
139 const Transform3D& pretrans = Transform3D::Identity(),
142 for (
size_t i = 0; i <
n; ++i) {
148 trans = trans * pretrans;
150 auto bounds = std::make_shared<const RectangleBounds>(2, 1.5);
152 std::shared_ptr<Surface> srf =
153 Surface::makeShared<PlaneSurface>(trans, bounds);
164 double z0 = -(nZ - 1) * w;
167 for (
int i = 0; i < nZ; i++) {
168 double z = i * w * 2 + z0;
171 res.insert(res.end(), ring.begin(), ring.end());
177 std::pair<SrfVec, std::vector<std::pair<const Surface*, const Surface*>>>
179 double w = 2,
double h = 1.5) {
180 double z0 = -(nZ - 1) * w;
182 std::vector<std::pair<const Surface*, const Surface*>> pairs;
185 double phiStep = 2 *
M_PI / nPhi;
186 for (
int i = 0; i < nZ; i++) {
187 double z = i * w * 2 + z0;
188 for (
int j = 0; j < nPhi; ++j) {
189 double phi = std::fma(j, phiStep, shift);
192 trans.rotate(Eigen::AngleAxisd(phi,
Vector3D(0, 0, 1)));
193 trans.translate(
Vector3D(10, 0, z));
194 trans.rotate(Eigen::AngleAxisd(incl,
Vector3D(0, 0, 1)));
195 trans.rotate(Eigen::AngleAxisd(
M_PI / 2.,
Vector3D(0, 1, 0)));
197 auto bounds = std::make_shared<const RectangleBounds>(w,
h);
198 std::shared_ptr<Surface> srfA =
199 Surface::makeShared<PlaneSurface>(trans, bounds);
203 transB.pretranslate(nrm * 0.1);
204 std::shared_ptr<Surface> srfB =
205 Surface::makeShared<PlaneSurface>(transB, bounds);
207 pairs.push_back(std::make_pair(srfA.get(), srfB.get()));
216 return std::make_pair(res, pairs);
224 os << std::fixed << std::setprecision(4);
227 for (
const auto& srfx : surfaces) {
228 std::shared_ptr<const PlaneSurface> srf =
233 for (
const auto& vtxloc : bounds->vertices()) {
236 os <<
"v " << vtx.x() <<
" " << vtx.y() <<
" " << vtx.z() <<
"\n";
241 for (
size_t i = 1; i <= bounds->vertices().size(); ++i) {
242 os <<
" " << nVtx + i;
246 nVtx += bounds->vertices().size();
252 BOOST_AUTO_TEST_SUITE(Tools)
257 std::vector<const Surface*> emptyRaw;
259 auto tr = Transform3D::Identity();
264 std::vector<float> bdExp = {
265 -3.14159, -2.93215, -2.72271, -2.51327, -2.30383, -2.0944, -1.88496,
266 -1.67552, -1.46608, -1.25664, -1.0472, -0.837758, -0.628319, -0.418879,
267 -0.20944, 0, 0.20944, 0.418879, 0.628319, 0.837758, 1.0472,
268 1.25664, 1.46608, 1.67552, 1.88496, 2.09439, 2.30383, 2.51327,
269 2.72271, 2.93215, 3.14159};
275 for (
int i = -1; i <= 2; i += 2) {
278 double angleShift = step / 2.;
279 auto surfaces = fullPhiTestSurfacesEC(30, angleShift, z);
282 tr = Transform3D::Identity();
283 auto axis = createEquidistantAxis(
tgContext, surfacesRaw,
286 BOOST_CHECK_EQUAL(axis.nBins, 30
u);
294 surfaces = fullPhiTestSurfacesEC(30, angleShift, z);
297 tr = Transform3D::Identity();
301 "SurfaceArrayCreator_createEquidistantAxis_EC_2.obj");
302 BOOST_CHECK_EQUAL(axis.nBins, 30
u);
309 angleShift = step / -4.;
310 surfaces = fullPhiTestSurfacesEC(30, angleShift, z);
313 tr = Transform3D::Identity();
317 "SurfaceArrayCreator_createEquidistantAxis_EC_3.obj");
318 BOOST_CHECK_EQUAL(axis.nBins, 30
u);
325 angleShift = step / 4.;
326 surfaces = fullPhiTestSurfacesEC(30, angleShift, z);
330 tr = Transform3D::Identity();
335 "SurfaceArrayCreator_createEquidistantAxis_EC_4.obj");
336 BOOST_CHECK_EQUAL(axis.nBins, 30
u);
343 for (
int i = -1; i <= 2; i += 2) {
346 double angleShift = step / 2.;
347 auto surfaces = fullPhiTestSurfacesBRL(30, angleShift, z);
350 tr = Transform3D::Identity();
351 auto axis = createEquidistantAxis(
tgContext, surfacesRaw,
354 "SurfaceArrayCreator_createEquidistantAxis_BRL_1.obj");
355 BOOST_CHECK_EQUAL(axis.nBins, 30
u);
363 surfaces = fullPhiTestSurfacesBRL(30, angleShift, z);
366 tr = Transform3D::Identity();
370 "SurfaceArrayCreator_createEquidistantAxis_BRL_2.obj");
371 BOOST_CHECK_EQUAL(axis.nBins, 30
u);
379 angleShift = step / -4.;
380 surfaces = fullPhiTestSurfacesBRL(30, angleShift, z);
383 tr = Transform3D::Identity();
387 "SurfaceArrayCreator_createEquidistantAxis_BRL_3.obj");
388 BOOST_CHECK_EQUAL(axis.nBins, 30
u);
396 angleShift = step / 4.;
397 surfaces = fullPhiTestSurfacesBRL(30, angleShift, z);
400 tr = Transform3D::Identity();
404 "SurfaceArrayCreator_createEquidistantAxis_BRL_4.obj");
405 BOOST_CHECK_EQUAL(axis.nBins, 30
u);
416 surfaces = fullPhiTestSurfacesEC(1);
419 "SurfaceArrayCreator_createEquidistantAxis_EC_Single.obj");
422 tr = Transform3D::Identity();
423 auto axis = createEquidistantAxis(
tgContext, surfacesRaw,
425 BOOST_CHECK_EQUAL(axis.nBins, 1
u);
435 auto surfaces = straightLineSurfaces(1);
438 auto trf = Transform3D::Identity();
441 draw_surfaces(surfaces,
"SurfaceArrayCreator_createEquidistantAxis_Z_1.obj");
442 BOOST_CHECK_EQUAL(axis.nBins, 1
u);
448 for (
size_t i = 0; i <= 20; i++) {
449 double z0 = -10 + 1. * i;
450 surfaces = straightLineSurfaces(10, 3,
Vector3D(0, 0, z0 + 1.5));
453 trf = Transform3D::Identity();
459 "SurfaceArrayCreator_createEquidistantAxis_Z_2_%1%.obj") %
462 BOOST_CHECK_EQUAL(axis.nBins, 10
u);
471 surfaces = straightLineSurfaces(10, 3,
Vector3D(0, 0, 0 + 1.5), tr);
474 trf = Transform3D::Identity();
477 draw_surfaces(surfaces,
"SurfaceArrayCreator_createEquidistantAxis_Z_3.obj");
478 BOOST_CHECK_EQUAL(axis.nBins, 10
u);
487 auto surfaces = fullPhiTestSurfacesEC(1, 0, 0, 15);
489 draw_surfaces(surfaces,
"SurfaceArrayCreator_createEquidistantAxis_R_1.obj");
490 auto trf = Transform3D::Identity();
494 BOOST_CHECK_EQUAL(axis.nBins, 1
u);
501 auto ringa = fullPhiTestSurfacesEC(30, 0, 0, 10);
502 surfaces.insert(surfaces.end(), ringa.begin(), ringa.end());
503 auto ringb = fullPhiTestSurfacesEC(30, 0, 0, 15);
504 surfaces.insert(surfaces.end(), ringb.begin(), ringb.end());
505 auto ringc = fullPhiTestSurfacesEC(30, 0, 0, 20);
506 surfaces.insert(surfaces.end(), ringc.begin(), ringc.end());
507 draw_surfaces(surfaces,
"SurfaceArrayCreator_createEquidistantAxis_R_2.obj");
511 trf = Transform3D::Identity();
515 BOOST_CHECK_EQUAL(axis.nBins, 3
u);
528 auto ringA = fullPhiTestSurfacesEC(10, 0, 0, 10, 2, 3);
529 auto ringB = fullPhiTestSurfacesEC(15, 0, 0, 15, 2, 3.5);
530 auto ringC = fullPhiTestSurfacesEC(20, 0, 0, 20, 2, 3.8);
532 std::vector<std::shared_ptr<const Surface>> surfaces;
533 std::copy(ringA.begin(), ringA.end(), std::back_inserter(surfaces));
534 std::copy(ringB.begin(), ringB.end(), std::back_inserter(surfaces));
535 std::copy(ringC.begin(), ringC.end(), std::back_inserter(surfaces));
536 draw_surfaces(surfaces,
"SurfaceArrayCreator_dependentBinCounts.obj");
538 std::unique_ptr<SurfaceArray> sArray =
540 auto axes = sArray->getAxes();
541 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(), 3
u);
542 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), 10
u);
547 objVis.write(
"SurfaceArrayCreator_EndcapGrid");
552 SrfVec brl = makeBarrel(30, 7, 2, 1);
554 draw_surfaces(brl,
"SurfaceArrayCreator_completeBinning_BRL.obj");
556 detail::Axis<detail::AxisType::Equidistant, detail::AxisBoundaryType::Closed>
558 detail::Axis<detail::AxisType::Equidistant, detail::AxisBoundaryType::Bound>
565 auto localToGlobal = [
R](
const Vector2D& loc) {
566 double phi = loc[0] - 2 *
M_PI / 30 / 2;
570 auto sl = std::make_unique<
572 globalToLocal, localToGlobal,
573 std::make_tuple(std::move(phiAxis), std::move(zAxis)));
580 objVis.
write(
"SurfaceArrayCreator_BarrelGrid");
583 for (
const auto& srf : brl) {
585 auto binContent = sa.
at(ctr);
587 BOOST_CHECK_EQUAL(binContent.size(), 1
u);
588 BOOST_CHECK_EQUAL(srf.get(), binContent.at(0));
594 auto barrel = makeBarrelStagger(30, 7, 0,
M_PI / 9.);
595 auto brl = barrel.first;
616 auto localToGlobal = [
R, itr](
const Vector2D& loc) {
620 auto sl = makeSurfaceGridLookup2D<detail::AxisBoundaryType::Closed,
621 detail::AxisBoundaryType::Bound>(
622 globalToLocal, localToGlobal, pAxisPhi, pAxisZ);
627 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(), 30
u);
628 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), 7
u);
630 for (
const auto& pr : barrel.second) {
635 auto binContent = sa.
at(ctr);
636 BOOST_CHECK_EQUAL(binContent.size(), 2
u);
637 std::set<const Surface*> act;
638 act.insert(binContent[0]);
639 act.insert(binContent[1]);
641 std::set<const Surface*> exp;
645 BOOST_CHECK(act == exp);
649 BOOST_TEST_CONTEXT(
"Barrel Stagger Variable binning") {
650 tr = Transform3D::Identity();
659 auto globalToLocalVar = [tr](
const Vector3D&
pos) {
663 auto localToGlobalVar = [
R, itr](
const Vector2D& loc) {
667 auto sl2 = makeSurfaceGridLookup2D<detail::AxisBoundaryType::Closed,
668 detail::AxisBoundaryType::Bound>(
669 globalToLocalVar, localToGlobalVar, pAxisPhiVar, pAxisZVar);
674 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(), 30
u);
675 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), 7
u);
678 std::vector<double> phiEdgesExp = {
679 -3.14159, -2.93215, -2.72271, -2.51327, -2.30383, -2.0944,
680 -1.88496, -1.67552, -1.46608, -1.25664, -1.0472, -0.837758,
681 -0.628319, -0.418879, -0.20944, 4.44089e-16, 0.20944, 0.418879,
682 0.628319, 0.837758, 1.0472, 1.25664, 1.46608, 1.67552,
683 1.88496, 2.0944, 2.30383, 2.51327, 2.72271, 3.00831,
685 std::vector<double> zEdgesExp = {-14, -10, -6, -2, 2, 6, 10, 14};
687 for (
const auto& edge : axes.at(0)->getBinEdges()) {
688 BOOST_TEST_INFO(
"phi edge index " << i);
689 auto phiEdge = phiEdgesExp.at(i);
694 for (
const auto& edge : axes.at(1)->getBinEdges()) {
695 BOOST_TEST_INFO(
"z edge index " << i);
700 for (
const auto& pr : barrel.second) {
705 auto binContent = sa2.
at(ctr);
706 BOOST_CHECK_EQUAL(binContent.size(), 2
u);
707 std::set<const Surface*> act;
708 act.insert(binContent[0]);
709 act.insert(binContent[1]);
711 std::set<const Surface*> exp;
715 BOOST_CHECK(act == exp);
720 BOOST_AUTO_TEST_SUITE_END()