File indexing completed on 2025-01-18 09:12:56
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0013 #include "Acts/Utilities/BinningData.hpp"
0014 #include "Acts/Utilities/BinningType.hpp"
0015
0016 #include <cmath>
0017 #include <cstddef>
0018 #include <memory>
0019 #include <numbers>
0020 #include <utility>
0021 #include <vector>
0022
0023 namespace Acts::Test {
0024
0025
0026 Vector3 xyzPosition(0.5, 1.5, 2.5);
0027 Vector3 xyzPositionOutside(30., -30., 200.);
0028 Vector3 phi0Position(0.5, 0., 2.5);
0029 Vector3 phiPihPosition(0., 1.5, 2.5);
0030 Vector3 eta0Position(0.5, 1.5, 0.);
0031
0032 Vector2 xyPosition(0.5, 1.5);
0033 Vector2 rphizPosition(0.1, 2.5);
0034 Vector2 rphiPosition(3.5, std::numbers::pi / 8.);
0035
0036
0037
0038
0039
0040 BinningData xData_eq(open, AxisDirection::AxisX, 10, 0., 10.);
0041 BinningData yData_eq(open, AxisDirection::AxisY, 10, 0., 10.);
0042 BinningData zData_eq(open, AxisDirection::AxisZ, 10, 0., 10.);
0043
0044
0045
0046 BinningData rData_eq(open, AxisDirection::AxisR, 10, 0., 10.);
0047
0048
0049 BinningData phiData_eq(closed, AxisDirection::AxisPhi, 5, -std::numbers::pi,
0050 std::numbers::pi);
0051
0052
0053
0054
0055 BinningData etaData_eq(open, AxisDirection::AxisEta, 5, -2.5, 2.5);
0056
0057
0058 BinningData xData_eq_copy(open, AxisDirection::AxisX, 10, 0., 10.);
0059
0060
0061 std::vector<float> values = {0., 1., 2., 3., 4., 10.};
0062
0063
0064 BinningData xData_arb(open, AxisDirection::AxisX, values);
0065 BinningData yData_arb(open, AxisDirection::AxisY, values);
0066
0067 std::vector<float> phiValues = {-std::numbers::pi, -2., -1., 1., 2.,
0068 std::numbers::pi};
0069 BinningData phiData_arb(closed, AxisDirection::AxisPhi, phiValues);
0070
0071
0072
0073 std::size_t nBins_binary = 59;
0074 double valueMin = 0.;
0075 double phiMin = -std::numbers::pi;
0076 double delta = 0.5;
0077 double phiDelta = 0.1064;
0078
0079
0080 std::vector<float> sstr = {0., 1., 1.5, 2., 3.};
0081
0082 auto xData_sstr_mult =
0083 std::make_unique<const BinningData>(open, AxisDirection::AxisX, sstr);
0084
0085 BinningData xData_mult(open, AxisDirection::AxisX, 3, 0., 9.,
0086 std::move(xData_sstr_mult));
0087
0088
0089 std::vector<float> main_sstr = {0., 3., 4., 5.};
0090 auto xData_sstr_add =
0091 std::make_unique<const BinningData>(open, AxisDirection::AxisX, sstr);
0092 BinningData xData_add(open, AxisDirection::AxisX, main_sstr,
0093 std::move(xData_sstr_add));
0094
0095
0096
0097
0098
0099
0100 BOOST_AUTO_TEST_CASE(BinningData_AxisDirection) {
0101
0102
0103 std::vector<float> values_binary;
0104 std::vector<float> phiValues_binary;
0105 for (std::size_t i = 0; i <= nBins_binary; i++) {
0106 values_binary.push_back(valueMin + i * delta);
0107 phiValues_binary.push_back(phiMin + i * phiDelta);
0108 }
0109
0110 BinningData xData_arb_binary(open, AxisDirection::AxisX, values_binary);
0111 BinningData phiData_arb_binary(closed, AxisDirection::AxisPhi,
0112 phiValues_binary);
0113
0114
0115
0116 BOOST_CHECK_EQUAL(xData_eq.bins(), std::size_t{10});
0117
0118 BOOST_CHECK_EQUAL(xData_arb.bins(), std::size_t{5});
0119
0120 BOOST_CHECK_EQUAL(xData_mult.bins(), std::size_t{12});
0121
0122 BOOST_CHECK_EQUAL(xData_add.bins(), std::size_t{6});
0123 BOOST_CHECK_EQUAL(xData_arb_binary.bins(), nBins_binary);
0124
0125 BOOST_CHECK(xData_eq_copy == xData_eq_copy);
0126 BOOST_CHECK(!(xData_eq == yData_eq));
0127
0128
0129 BOOST_CHECK_EQUAL(xData_eq.value(xyzPosition), 0.5);
0130 BOOST_CHECK_EQUAL(yData_eq.value(xyzPosition), 1.5);
0131 BOOST_CHECK_EQUAL(zData_eq.value(xyzPosition), 2.5);
0132 BOOST_CHECK_EQUAL(xData_arb.value(xyzPosition), 0.5);
0133 BOOST_CHECK_EQUAL(xData_mult.value(xyzPosition), 0.5);
0134 BOOST_CHECK_EQUAL(xData_add.value(xyzPosition), 0.5);
0135 BOOST_CHECK_EQUAL(xData_arb_binary.value(xyzPosition), 0.5);
0136
0137
0138 BOOST_CHECK_EQUAL(xData_eq.value(xyPosition), 0.5);
0139 BOOST_CHECK_EQUAL(yData_eq.value(xyPosition), 1.5);
0140 BOOST_CHECK_EQUAL(zData_eq.value(rphizPosition), 2.5);
0141 BOOST_CHECK_EQUAL(xData_arb.value(xyPosition), 0.5);
0142 BOOST_CHECK_EQUAL(xData_mult.value(xyPosition), 0.5);
0143 BOOST_CHECK_EQUAL(xData_add.value(xyPosition), 0.5);
0144 BOOST_CHECK_EQUAL(xData_arb_binary.value(xyPosition), 0.5);
0145
0146
0147 CHECK_CLOSE_REL(rData_eq.value(xyzPosition), std::hypot(0.5, 1.5), 1e-5);
0148 BOOST_CHECK_EQUAL(rData_eq.value(rphiPosition), 3.5);
0149
0150 CHECK_SMALL(phiData_eq.value(phi0Position), 1e-6 * std::numbers::pi);
0151 CHECK_CLOSE_REL(phiData_eq.value(phiPihPosition), std::numbers::pi / 2.,
0152 1e-5);
0153
0154 BOOST_CHECK_EQUAL(phiData_eq.bins(), std::size_t{5});
0155 BOOST_CHECK_EQUAL(phiData_arb.bins(), std::size_t{5});
0156 BOOST_CHECK_EQUAL(phiData_arb_binary.bins(), nBins_binary);
0157
0158
0159 CHECK_SMALL(etaData_eq.value(eta0Position), 1e-5);
0160 }
0161
0162
0163 BOOST_AUTO_TEST_CASE(BinningData_bins) {
0164
0165
0166 std::vector<float> values_binary;
0167 std::vector<float> phiValues_binary;
0168 for (std::size_t i = 0; i <= nBins_binary; i++) {
0169 values_binary.push_back(valueMin + i * delta);
0170 phiValues_binary.push_back(phiMin + i * phiDelta);
0171 }
0172
0173 BinningData xData_arb_binary(open, AxisDirection::AxisX, values_binary);
0174 BinningData phiData_arb_binary(closed, AxisDirection::AxisPhi,
0175 phiValues_binary);
0176
0177
0178
0179 BOOST_CHECK_EQUAL(xData_eq.searchGlobal(xyzPosition), std::size_t{0});
0180 BOOST_CHECK_EQUAL(yData_eq.searchGlobal(xyzPosition), std::size_t{1});
0181 BOOST_CHECK_EQUAL(zData_eq.searchGlobal(xyzPosition), std::size_t{2});
0182
0183 BOOST_CHECK_EQUAL(xData_arb.searchGlobal(xyzPosition), std::size_t{0});
0184 BOOST_CHECK_EQUAL(xData_arb.search(6.), std::size_t{4});
0185 BOOST_CHECK_EQUAL(xData_arb_binary.searchGlobal(xyzPosition), std::size_t{0});
0186 BOOST_CHECK_EQUAL(xData_arb_binary.search(50.), (nBins_binary - 1));
0187
0188 BOOST_CHECK_EQUAL(xData_add.searchGlobal(xyzPosition), std::size_t{0});
0189 BOOST_CHECK_EQUAL(xData_add.searchGlobal(xyzPosition), std::size_t{0});
0190 BOOST_CHECK_EQUAL(xData_add.search(0.2), std::size_t{0});
0191 BOOST_CHECK_EQUAL(xData_add.search(1.2), std::size_t{1});
0192 BOOST_CHECK_EQUAL(xData_add.search(1.7), std::size_t{2});
0193 BOOST_CHECK_EQUAL(xData_add.search(2.5), std::size_t{3});
0194 BOOST_CHECK_EQUAL(xData_add.search(3.5), std::size_t{4});
0195 BOOST_CHECK_EQUAL(xData_add.search(4.2), std::size_t{5});
0196 BOOST_CHECK_EQUAL(xData_add.search(7.), std::size_t{5});
0197
0198 BOOST_CHECK_EQUAL(xData_mult.searchGlobal(xyzPosition), std::size_t{0});
0199 BOOST_CHECK_EQUAL(xData_mult.search(0.2), std::size_t{0});
0200 BOOST_CHECK_EQUAL(xData_mult.search(1.2), std::size_t{1});
0201 BOOST_CHECK_EQUAL(xData_mult.search(1.7), std::size_t{2});
0202 BOOST_CHECK_EQUAL(xData_mult.search(2.5), std::size_t{3});
0203 BOOST_CHECK_EQUAL(xData_mult.search(3.5), std::size_t{4});
0204 BOOST_CHECK_EQUAL(xData_mult.search(4.2), std::size_t{5});
0205 BOOST_CHECK_EQUAL(xData_mult.search(4.7), std::size_t{6});
0206 BOOST_CHECK_EQUAL(xData_mult.search(5.7), std::size_t{7});
0207 BOOST_CHECK_EQUAL(xData_mult.search(6.5), std::size_t{8});
0208 BOOST_CHECK_EQUAL(xData_mult.search(7.2), std::size_t{9});
0209 BOOST_CHECK_EQUAL(xData_mult.search(7.7), std::size_t{10});
0210 BOOST_CHECK_EQUAL(xData_mult.search(8.1), std::size_t{11});
0211
0212
0213 BOOST_CHECK_EQUAL(xData_eq.searchLocal(xyPosition), std::size_t{0});
0214 BOOST_CHECK_EQUAL(yData_eq.searchLocal(xyPosition), std::size_t{1});
0215 BOOST_CHECK_EQUAL(zData_eq.searchLocal(rphizPosition), std::size_t{2});
0216 BOOST_CHECK_EQUAL(xData_arb.searchLocal(xyPosition), std::size_t{0});
0217 BOOST_CHECK_EQUAL(xData_arb_binary.searchLocal(xyPosition), std::size_t{0});
0218
0219
0220 BOOST_CHECK_EQUAL(rData_eq.searchGlobal(xyzPosition), std::size_t{1});
0221 BOOST_CHECK_EQUAL(rData_eq.searchLocal(rphiPosition), std::size_t{3});
0222 BOOST_CHECK_EQUAL(phiData_eq.searchGlobal(phi0Position), std::size_t{2});
0223 BOOST_CHECK_EQUAL(phiData_eq.searchGlobal(phiPihPosition), std::size_t{3});
0224 BOOST_CHECK_EQUAL(phiData_arb_binary.search(std::numbers::pi),
0225 std::size_t{0});
0226
0227
0228 BOOST_CHECK_EQUAL(etaData_eq.searchGlobal(eta0Position), std::size_t{2});
0229 }
0230
0231
0232 BOOST_AUTO_TEST_CASE(BinningData_inside_outside) {
0233
0234
0235 std::vector<float> values_binary;
0236 std::vector<float> phiValues_binary;
0237 for (std::size_t i = 0; i <= nBins_binary; i++) {
0238 values_binary.push_back(valueMin + i * delta);
0239 phiValues_binary.push_back(phiMin + i * phiDelta);
0240 }
0241
0242 BinningData xData_arb_binary(open, AxisDirection::AxisX, values_binary);
0243 BinningData phiData_arb_binary(closed, AxisDirection::AxisPhi,
0244 phiValues_binary);
0245
0246 BOOST_CHECK_EQUAL(xData_eq.inside(xyzPosition), true);
0247 BOOST_CHECK_EQUAL(yData_eq.inside(xyzPosition), true);
0248 BOOST_CHECK_EQUAL(zData_eq.inside(xyzPosition), true);
0249 BOOST_CHECK_EQUAL(xData_arb.inside(xyzPosition), true);
0250 BOOST_CHECK_EQUAL(xData_add.inside(xyzPosition), true);
0251 BOOST_CHECK_EQUAL(xData_mult.inside(xyzPosition), true);
0252 BOOST_CHECK_EQUAL(xData_arb_binary.inside(xyzPosition), true);
0253
0254
0255 BOOST_CHECK_EQUAL(xData_eq.inside(xyzPositionOutside), false);
0256 BOOST_CHECK_EQUAL(yData_eq.inside(xyzPositionOutside), false);
0257 BOOST_CHECK_EQUAL(zData_eq.inside(xyzPositionOutside), false);
0258 BOOST_CHECK_EQUAL(xData_arb.inside(xyzPositionOutside), false);
0259 BOOST_CHECK_EQUAL(xData_add.inside(xyzPositionOutside), false);
0260 BOOST_CHECK_EQUAL(xData_mult.inside(xyzPositionOutside), false);
0261 BOOST_CHECK_EQUAL(xData_arb_binary.inside(xyzPositionOutside), false);
0262
0263
0264 BOOST_CHECK_EQUAL(xData_eq.inside(xyPosition), true);
0265 BOOST_CHECK_EQUAL(yData_eq.inside(xyPosition), true);
0266 BOOST_CHECK_EQUAL(zData_eq.inside(rphizPosition), true);
0267
0268
0269 BOOST_CHECK_EQUAL(phiData_eq.inside(phi0Position), true);
0270 BOOST_CHECK_EQUAL(phiData_eq.inside(phiPihPosition), true);
0271
0272 BOOST_CHECK_EQUAL(etaData_eq.inside(eta0Position), true);
0273 }
0274
0275
0276 BOOST_AUTO_TEST_CASE(BinningData_open_close) {
0277
0278
0279 std::vector<float> values_binary;
0280 std::vector<float> phiValues_binary;
0281 for (std::size_t i = 0; i <= nBins_binary; i++) {
0282 values_binary.push_back(valueMin + i * delta);
0283 phiValues_binary.push_back(phiMin + i * phiDelta);
0284 }
0285
0286 BinningData xData_arb_binary(open, AxisDirection::AxisX, values_binary);
0287 BinningData phiData_arb_binary(closed, AxisDirection::AxisPhi,
0288 phiValues_binary);
0289
0290 BOOST_CHECK_EQUAL(xData_eq.searchGlobal(xyzPositionOutside), std::size_t{9});
0291 BOOST_CHECK_EQUAL(yData_eq.searchGlobal(xyzPositionOutside), std::size_t{0});
0292 BOOST_CHECK_EQUAL(zData_eq.searchGlobal(xyzPositionOutside), std::size_t{9});
0293 BOOST_CHECK_EQUAL(xData_arb.searchGlobal(xyzPositionOutside) + 1,
0294 xData_arb.bins());
0295 BOOST_CHECK_EQUAL(xData_arb_binary.searchGlobal(xyzPositionOutside) + 1,
0296 xData_arb_binary.bins());
0297 BOOST_CHECK_EQUAL(yData_arb.searchGlobal(xyzPositionOutside), std::size_t{0});
0298
0299
0300 BOOST_CHECK_EQUAL(phiData_eq.search(-4.), std::size_t{4});
0301 BOOST_CHECK_EQUAL(phiData_eq.search(4.), std::size_t{0});
0302 BOOST_CHECK_EQUAL(phiData_arb.search(-4.), std::size_t{4});
0303 BOOST_CHECK_EQUAL(phiData_arb.search(4.), std::size_t{0});
0304 BOOST_CHECK_EQUAL(phiData_arb_binary.search(-4.), (nBins_binary - 1));
0305 BOOST_CHECK_EQUAL(phiData_arb_binary.search(4.), std::size_t{0});
0306 }
0307
0308
0309 BOOST_AUTO_TEST_CASE(BinningData_boundaries) {
0310
0311 std::vector<float> boundaries = {0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.};
0312 BOOST_CHECK_EQUAL_COLLECTIONS(xData_eq.boundaries().begin(),
0313 xData_eq.boundaries().end(), boundaries.begin(),
0314 boundaries.end());
0315
0316 const float phiStep = std::numbers::pi * 2. / 5.;
0317 std::vector<float> phiBoundaries_eq;
0318
0319 for (int i = 0; i <= 5; ++i) {
0320 phiBoundaries_eq.push_back(
0321 static_cast<float>(-std::numbers::pi + i * phiStep));
0322 }
0323
0324 CHECK_CLOSE_REL(phiData_eq.boundaries(), phiBoundaries_eq, 1e-5);
0325 }
0326
0327
0328
0329 BOOST_AUTO_TEST_CASE(BinningData_bincenter) {
0330
0331
0332 std::vector<float> values_binary;
0333 std::vector<float> phiValues_binary;
0334 for (std::size_t i = 0; i <= nBins_binary; i++) {
0335 values_binary.push_back(valueMin + i * delta);
0336 phiValues_binary.push_back(phiMin + i * phiDelta);
0337 }
0338
0339 BinningData xData_arb_binary(open, AxisDirection::AxisX, values_binary);
0340 BinningData phiData_arb_binary(closed, AxisDirection::AxisPhi,
0341 phiValues_binary);
0342
0343
0344 BOOST_CHECK_EQUAL(xData_eq.center(3), 3.5);
0345
0346 BOOST_CHECK_EQUAL(xData_arb.center(4), 7.);
0347
0348 BOOST_CHECK_EQUAL(xData_add.center(0), 0.5);
0349 BOOST_CHECK_EQUAL(xData_add.center(1), 1.25);
0350 BOOST_CHECK_EQUAL(xData_add.center(4), 3.5);
0351
0352 BOOST_CHECK_EQUAL(xData_mult.center(0), 0.5);
0353 BOOST_CHECK_EQUAL(xData_mult.center(1), 1.25);
0354 BOOST_CHECK_EQUAL(xData_mult.center(4), 3.5);
0355 BOOST_CHECK_EQUAL(xData_mult.center(10), 7.75);
0356 BOOST_CHECK_EQUAL(xData_mult.center(11), 8.5);
0357
0358 BOOST_CHECK_EQUAL(xData_arb_binary.center(0), 0.5 * delta);
0359
0360
0361 std::vector<float> center = {0.5, 1.5, 2.5, 3.5, 4.5,
0362 5.5, 6.5, 7.5, 8.5, 9.5};
0363 for (std::size_t ib = 0; ib < center.size(); ++ib) {
0364 BOOST_CHECK_EQUAL(xData_eq.center(ib), center[ib]);
0365 }
0366
0367
0368 const float phiStep = std::numbers::pi * 2. / 5.;
0369 std::vector<float> phiCenters_eq;
0370
0371 for (int i = 0; i < 5; ++i) {
0372 phiCenters_eq.push_back(
0373 static_cast<float>(-std::numbers::pi + (i + 0.5) * phiStep));
0374 }
0375
0376 for (std::size_t ib = 0; ib < phiCenters_eq.size(); ++ib) {
0377 CHECK_CLOSE_ABS(phiData_eq.center(ib), phiCenters_eq[ib], 1e-3);
0378 }
0379 }
0380
0381
0382 BOOST_AUTO_TEST_CASE(BinningData_phi_modules) {
0383
0384
0385 const float deltaPhi = 0.1;
0386 BinningData phiData_mod(closed, AxisDirection::AxisPhi, 5,
0387 -std::numbers::pi + deltaPhi,
0388 std::numbers::pi + deltaPhi);
0389
0390 const float phiStep = std::numbers::pi * 2. / 5.;
0391 std::vector<float> phiBoundaries_mod;
0392
0393 for (int i = 0; i <= 5; ++i) {
0394 phiBoundaries_mod.push_back(
0395 static_cast<float>(-std::numbers::pi + i * phiStep) + deltaPhi);
0396 }
0397
0398
0399 CHECK_CLOSE_REL(phiData_mod.boundaries(), phiBoundaries_mod, 1e-5);
0400
0401
0402
0403 float firstAngle = (-std::numbers::pi + 1.5 * deltaPhi);
0404 Vector3 firstBin(cos(firstAngle), sin(firstAngle), 0.);
0405 BOOST_CHECK_EQUAL(phiData_mod.search(firstAngle), std::size_t{0});
0406 BOOST_CHECK_EQUAL(phiData_mod.searchGlobal(firstBin), std::size_t{0});
0407
0408 float firstAngleNeg = (-std::numbers::pi + 0.5 * deltaPhi);
0409 Vector3 lastBinNeg(cos(firstAngleNeg), sin(firstAngleNeg), 0.);
0410 BOOST_CHECK_EQUAL(phiData_mod.search(firstAngleNeg), std::size_t{4});
0411 BOOST_CHECK_EQUAL(phiData_mod.searchGlobal(lastBinNeg), std::size_t{4});
0412
0413 float lastAnglePos = (std::numbers::pi + 0.5 * deltaPhi);
0414 Vector3 lastBinPos(cos(lastAnglePos), sin(lastAnglePos), 0.);
0415 BOOST_CHECK_EQUAL(phiData_mod.search(lastAnglePos), std::size_t{4});
0416 BOOST_CHECK_EQUAL(phiData_mod.searchGlobal(lastBinPos), std::size_t{4});
0417
0418
0419 float underscaledAngle = -std::numbers::pi - 0.5 * deltaPhi;
0420 Vector3 underscaledPos(cos(underscaledAngle), sin(underscaledAngle), 0.);
0421 BOOST_CHECK_EQUAL(phiData_mod.search(underscaledAngle), std::size_t{4});
0422 BOOST_CHECK_EQUAL(phiData_mod.searchGlobal(underscaledPos), std::size_t{4});
0423 }
0424
0425 }