File indexing completed on 2026-04-19 07:48:53
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/Utilities/Histogram.hpp"
0012 #include "Acts/Utilities/ProtoAxis.hpp"
0013
0014 using namespace Acts;
0015 using namespace Acts::Experimental;
0016
0017 BOOST_AUTO_TEST_SUITE(ProfileEfficiencySuite)
0018
0019 BOOST_AUTO_TEST_CASE(ProfileHistogram_BasicFill) {
0020 ProtoAxis protoAxis(AxisBoundaryType::Bound, 0.0, 10.0, 10);
0021 auto xAxis = BoostVariableAxis(protoAxis.getAxis().getBinEdges(), "x");
0022 ProfileHistogram1 profile("test_prof", "Test Profile", {xAxis}, "y value");
0023
0024 BOOST_CHECK_EQUAL(profile.name(), "test_prof");
0025 BOOST_CHECK_EQUAL(profile.title(), "Test Profile");
0026 BOOST_CHECK_EQUAL(profile.sampleAxisTitle(), "y value");
0027
0028
0029 profile.fill({2.5}, 10.0);
0030 profile.fill({2.5}, 20.0);
0031 profile.fill({2.5}, 30.0);
0032
0033 const auto& bh = profile.histogram();
0034 auto xIdx = bh.axis(0).index(2.5);
0035
0036
0037 double mean = bh.at(xIdx).value();
0038 BOOST_CHECK_CLOSE(mean, 20.0, 1e-6);
0039
0040
0041 double count = bh.at(xIdx).count();
0042 BOOST_CHECK_CLOSE(count, 3.0, 1e-10);
0043 }
0044
0045 BOOST_AUTO_TEST_CASE(ProfileHistogram_MultipleBins) {
0046 ProtoAxis protoAxis(AxisBoundaryType::Bound, -2.5, 2.5, 5);
0047 auto xAxis = BoostVariableAxis(protoAxis.getAxis().getBinEdges(), "eta");
0048 ProfileHistogram1 profile("res_vs_eta", "Residual vs Eta", {xAxis},
0049 "residual");
0050
0051
0052 profile.fill({-2.0}, 1.0);
0053 profile.fill({-2.0}, 3.0);
0054 profile.fill({0.0}, 5.0);
0055 profile.fill({0.0}, 7.0);
0056 profile.fill({2.0}, 9.0);
0057 profile.fill({2.0}, 11.0);
0058
0059 const auto& bh = profile.histogram();
0060
0061
0062 auto idx0 = bh.axis(0).index(-2.0);
0063 BOOST_CHECK_CLOSE(bh.at(idx0).value(), 2.0, 1e-6);
0064
0065
0066 auto idx2 = bh.axis(0).index(0.0);
0067 BOOST_CHECK_CLOSE(bh.at(idx2).value(), 6.0, 1e-6);
0068
0069
0070 auto idx4 = bh.axis(0).index(2.0);
0071 BOOST_CHECK_CLOSE(bh.at(idx4).value(), 10.0, 1e-6);
0072 }
0073
0074 BOOST_AUTO_TEST_CASE(Efficiency1D_BasicFill) {
0075 ProtoAxis protoAxis(AxisBoundaryType::Bound, -3.0, 3.0, 10);
0076 auto axis =
0077 AxisVariant(BoostVariableAxis(protoAxis.getAxis().getBinEdges(), "eta"));
0078 Efficiency1 eff("eff_vs_eta", "Efficiency vs Eta", {axis});
0079
0080 BOOST_CHECK_EQUAL(eff.name(), "eff_vs_eta");
0081 BOOST_CHECK_EQUAL(eff.title(), "Efficiency vs Eta");
0082
0083
0084 for (int i = 0; i < 7; ++i) {
0085 eff.fill({0.5}, true);
0086 }
0087 for (int i = 0; i < 3; ++i) {
0088 eff.fill({0.5}, false);
0089 }
0090
0091
0092 auto binIdx = eff.acceptedHistogram().axis(0).index(0.5);
0093 double accepted = static_cast<double>(eff.acceptedHistogram().at(binIdx));
0094 double total = static_cast<double>(eff.totalHistogram().at(binIdx));
0095
0096 BOOST_CHECK_CLOSE(accepted, 7.0, 1e-10);
0097 BOOST_CHECK_CLOSE(total, 10.0, 1e-10);
0098 BOOST_CHECK_CLOSE(accepted / total, 0.7, 1e-6);
0099 }
0100
0101 BOOST_AUTO_TEST_CASE(Efficiency1D_MultipleBins) {
0102 ProtoAxis protoAxis(AxisBoundaryType::Bound, 0.0, 5.0, 5);
0103 auto axis =
0104 AxisVariant(BoostVariableAxis(protoAxis.getAxis().getBinEdges(), "pt"));
0105 Efficiency1 eff("eff_vs_pt", "Efficiency vs pT", {axis});
0106
0107
0108 eff.fill({0.5}, true);
0109 eff.fill({0.5}, false);
0110
0111
0112 for (int i = 0; i < 8; ++i) {
0113 eff.fill({2.5}, true);
0114 }
0115 for (int i = 0; i < 2; ++i) {
0116 eff.fill({2.5}, false);
0117 }
0118
0119
0120 for (int i = 0; i < 5; ++i) {
0121 eff.fill({4.5}, true);
0122 }
0123
0124 const auto& accepted = eff.acceptedHistogram();
0125 const auto& total = eff.totalHistogram();
0126
0127 auto idx0 = accepted.axis(0).index(0.5);
0128 BOOST_CHECK_CLOSE(static_cast<double>(accepted.at(idx0)) /
0129 static_cast<double>(total.at(idx0)),
0130 0.5, 1e-6);
0131
0132 auto idx2 = accepted.axis(0).index(2.5);
0133 BOOST_CHECK_CLOSE(static_cast<double>(accepted.at(idx2)) /
0134 static_cast<double>(total.at(idx2)),
0135 0.8, 1e-6);
0136
0137 auto idx4 = accepted.axis(0).index(4.5);
0138 BOOST_CHECK_CLOSE(static_cast<double>(accepted.at(idx4)) /
0139 static_cast<double>(total.at(idx4)),
0140 1.0, 1e-6);
0141 }
0142
0143 BOOST_AUTO_TEST_CASE(Efficiency2D_BasicFill) {
0144 ProtoAxis protoX(AxisBoundaryType::Bound, -2.5, 2.5, 5);
0145 ProtoAxis protoY(AxisBoundaryType::Bound, 0.0, 5.0, 5);
0146 auto xAxis =
0147 AxisVariant(BoostVariableAxis(protoX.getAxis().getBinEdges(), "eta"));
0148 auto yAxis =
0149 AxisVariant(BoostVariableAxis(protoY.getAxis().getBinEdges(), "pt"));
0150 Efficiency2 eff("eff_vs_eta_pt", "Efficiency vs Eta and pT", {xAxis, yAxis});
0151
0152 BOOST_CHECK_EQUAL(eff.name(), "eff_vs_eta_pt");
0153 BOOST_CHECK_EQUAL(eff.title(), "Efficiency vs Eta and pT");
0154
0155
0156 eff.fill({0.0, 2.5}, true);
0157 eff.fill({0.0, 2.5}, true);
0158 eff.fill({0.0, 2.5}, true);
0159 eff.fill({0.0, 2.5}, false);
0160
0161 const auto& accepted = eff.acceptedHistogram();
0162 const auto& total = eff.totalHistogram();
0163
0164 auto xIdx = accepted.axis(0).index(0.0);
0165 auto yIdx = accepted.axis(1).index(2.5);
0166
0167 double acceptedCount = static_cast<double>(accepted.at(xIdx, yIdx));
0168 double totalCount = static_cast<double>(total.at(xIdx, yIdx));
0169
0170 BOOST_CHECK_CLOSE(acceptedCount, 3.0, 1e-10);
0171 BOOST_CHECK_CLOSE(totalCount, 4.0, 1e-10);
0172 BOOST_CHECK_CLOSE(acceptedCount / totalCount, 0.75, 1e-6);
0173 }
0174
0175 BOOST_AUTO_TEST_SUITE_END()