9 #include <boost/test/data/test_case.hpp>
10 #include <boost/test/unit_test.hpp>
28 double theta()
const {
return m_theta; }
29 double phi()
const {
return m_phi; }
31 double loc0()
const {
return m_loc0; }
32 double loc1()
const {
return m_loc1; }
33 double time()
const {
return m_time; }
38 return 2 * std::atan(std::exp(-eta));
41 BOOST_AUTO_TEST_SUITE(TrackSelectorTests)
43 std::vector<
double>
etaValues{-5.0, -4.5, -4.0, -3.5, -3.0, -2.5, -2.0, -1.5,
44 -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0, 2.5,
45 3.0, 3.5, 4.0, 4.5, 5.0, 1.0};
52 baseTrack.m_phi = 0.5;
54 baseTrack.m_loc0 = 0.5;
55 baseTrack.m_loc1 = 0.5;
56 baseTrack.m_time = 0.5;
57 baseTrack.m_nMeasurements = 0.5;
62 BOOST_CHECK(selector.isValidTrack(baseTrack));
65 auto check = [&](
const auto& var,
const auto& minPtr,
const auto& maxPtr,
66 const auto& propPtr) {
67 BOOST_TEST_INFO_SCOPE(
"Testing " << var);
70 auto cfgMinOnly = cfgBase;
71 auto cfgMaxOnly = cfgBase;
72 auto cfgMinMax = cfgBase;
74 cfgMinOnly.
cutSets.at(0).*minPtr = -1;
75 cfgMinMax.cutSets.at(0).*minPtr = -1;
76 cfgMaxOnly.cutSets.at(0).*maxPtr = 1;
77 cfgMinMax.cutSets.at(0).*maxPtr = 1;
83 BOOST_CHECK(minOnly.isValidTrack(track));
84 BOOST_CHECK(maxOnly.isValidTrack(track));
85 BOOST_CHECK(minMax.isValidTrack(track));
88 track.*propPtr = -1.1;
90 BOOST_CHECK(!minOnly.isValidTrack(track));
91 BOOST_CHECK(maxOnly.isValidTrack(track));
92 BOOST_CHECK(!minMax.isValidTrack(track));
97 BOOST_CHECK(minOnly.isValidTrack(track));
98 BOOST_CHECK(!maxOnly.isValidTrack(track));
99 BOOST_CHECK(!minMax.isValidTrack(track));
115 BOOST_TEST_INFO_SCOPE(
"pt min");
117 cfg.cutSets.at(0).ptMin = {0.2};
120 BOOST_CHECK(selector.isValidTrack(track));
122 BOOST_CHECK(!selector.isValidTrack(track));
126 BOOST_TEST_INFO_SCOPE(
"pt max");
128 cfg.cutSets.at(0).ptMax = {1.0};
131 BOOST_CHECK(selector.isValidTrack(track));
133 BOOST_CHECK(!selector.isValidTrack(track));
137 BOOST_TEST_INFO_SCOPE(
"pt min max");
139 cfg.cutSets.at(0).ptMin = {0.2};
140 cfg.cutSets.at(0).ptMax = {1.0};
143 BOOST_CHECK(selector.isValidTrack(track));
145 BOOST_CHECK(!selector.isValidTrack(track));
147 BOOST_CHECK(!selector.isValidTrack(track));
151 BOOST_TEST_INFO_SCOPE(
"eta min");
153 cfg.cutSets.at(0).etaMin = {-1.0};
157 BOOST_CHECK(selector.isValidTrack(track));
159 BOOST_CHECK(!selector.isValidTrack(track));
163 BOOST_TEST_INFO_SCOPE(
"eta max");
165 cfg.cutSets.at(0).etaMax = {1.0};
169 BOOST_CHECK(selector.isValidTrack(track));
171 BOOST_CHECK(!selector.isValidTrack(track));
175 BOOST_TEST_INFO_SCOPE(
"eta min max");
177 cfg.cutSets.at(0).etaMin = {-1.0};
178 cfg.cutSets.at(0).etaMax = {1.0};
182 BOOST_CHECK(selector.isValidTrack(track));
184 BOOST_CHECK(!selector.isValidTrack(track));
186 BOOST_CHECK(!selector.isValidTrack(track));
190 BOOST_TEST_INFO_SCOPE(
"abs eta min");
192 cfg.cutSets.at(0).absEtaMin = {0.2};
196 BOOST_CHECK(selector.isValidTrack(track));
198 BOOST_CHECK(selector.isValidTrack(track));
201 BOOST_CHECK(!selector.isValidTrack(track));
203 BOOST_CHECK(!selector.isValidTrack(track));
207 BOOST_TEST_INFO_SCOPE(
"abs eta max");
209 cfg.cutSets.at(0).absEtaMax = {1.0};
213 BOOST_CHECK(selector.isValidTrack(track));
215 BOOST_CHECK(selector.isValidTrack(track));
218 BOOST_CHECK(!selector.isValidTrack(track));
220 BOOST_CHECK(!selector.isValidTrack(track));
224 BOOST_TEST_INFO_SCOPE(
"abs eta min max");
226 cfg.cutSets.at(0).absEtaMin = {0.2};
227 cfg.cutSets.at(0).absEtaMax = {1.0};
231 BOOST_CHECK(selector.isValidTrack(track));
233 BOOST_CHECK(selector.isValidTrack(track));
236 BOOST_CHECK(!selector.isValidTrack(track));
238 BOOST_CHECK(!selector.isValidTrack(track));
241 BOOST_CHECK(!selector.isValidTrack(track));
243 BOOST_CHECK(!selector.isValidTrack(track));
247 BOOST_TEST_INFO_SCOPE(
"nMeas min");
249 cfg.cutSets.at(0).minMeasurements = {1};
252 track.m_nMeasurements = {2};
253 BOOST_CHECK(selector.isValidTrack(track));
254 track.m_nMeasurements = {1};
255 BOOST_CHECK(selector.isValidTrack(track));
256 track.m_nMeasurements = {0};
257 BOOST_CHECK(!selector.isValidTrack(track));
264 BOOST_TEST_INFO_SCOPE(selector.config());
268 BOOST_CHECK(!selector.isValidTrack(track));
271 BOOST_CHECK(!selector.isValidTrack(track));
276 BOOST_CHECK(selector.isValidTrack(track));
279 BOOST_CHECK(selector.isValidTrack(track));
282 BOOST_CHECK(!selector.isValidTrack(track));
288 baseTrack.m_phi = 0.5;
289 baseTrack.m_pt = 0.5;
290 baseTrack.m_loc0 = 0.5;
291 baseTrack.m_loc1 = 0.5;
292 baseTrack.m_time = 0.5;
293 baseTrack.m_nMeasurements = 0.5;
297 using factory_ptr_t =
Config& (
Config::*)(
double,
double);
300 auto check = [&](
const char*
name,
const factory_ptr_t& factory,
301 const prop_ptr_t& prop) {
302 BOOST_TEST_CONTEXT(name) {
305 cfg.addCuts(2.0, [&](
auto&
c) { (
c.*factory)(-1.0, 1.0); })
306 .addCuts([&](
auto&
c) { (
c.*factory)(-2.0, 2.0); });
310 BOOST_TEST_INFO_SCOPE(
cfg);
317 BOOST_CHECK(selector.isValidTrack(track));
320 BOOST_CHECK(!selector.isValidTrack(track));
323 BOOST_CHECK(!selector.isValidTrack(track));
331 BOOST_CHECK(selector.isValidTrack(track));
334 BOOST_CHECK(!selector.isValidTrack(track));
337 BOOST_CHECK(!selector.isValidTrack(track));
344 thetaFromEta(2.0 - std::numeric_limits<double>::epsilon());
346 BOOST_CHECK(selector.isValidTrack(track));
349 BOOST_CHECK(!selector.isValidTrack(track));
352 BOOST_CHECK(!selector.isValidTrack(track));
360 BOOST_CHECK(selector.isValidTrack(track));
363 BOOST_CHECK(selector.isValidTrack(track));
366 BOOST_CHECK(selector.isValidTrack(track));
369 BOOST_CHECK(!selector.isValidTrack(track));
372 BOOST_CHECK(!selector.isValidTrack(track));
381 BOOST_CHECK(selector.isValidTrack(track));
384 BOOST_CHECK(selector.isValidTrack(track));
387 BOOST_CHECK(!selector.isValidTrack(track));
390 BOOST_CHECK(!selector.isValidTrack(track));
404 constexpr
double inf = std::numeric_limits<double>::infinity();
407 EtaBinnedConfig
cfg{std::vector<double>{0, inf}};
408 for (
int i = -1;
i <= 1;
i =
i + 2) {
409 BOOST_CHECK_EQUAL(
cfg.binIndex(
i * 0.0), 0);
410 BOOST_CHECK_EQUAL(
cfg.binIndex(
i * 1.0), 0);
411 BOOST_CHECK_EQUAL(
cfg.binIndex(
i * 2.0), 0);
412 BOOST_CHECK_EQUAL(
cfg.binIndex(
i * 3.0), 0);
413 BOOST_CHECK_EQUAL(
cfg.binIndex(
i * 10.0), 0);
414 BOOST_CHECK_EQUAL(
cfg.binIndex(
i * 1000.0), 0);
419 EtaBinnedConfig
cfg{std::vector<double>{0, 0.5, 1.5, 2.5, 3.0, inf}};
420 for (
int i = -1;
i <= 1;
i =
i + 2) {
421 BOOST_CHECK_EQUAL(
cfg.binIndex(
i * 0.0), 0);
422 BOOST_CHECK_EQUAL(
cfg.binIndex(
i * 1.0), 1);
423 BOOST_CHECK_EQUAL(
cfg.binIndex(
i * 2.0), 2);
424 BOOST_CHECK_EQUAL(
cfg.binIndex(
i * 3.0), 4);
425 BOOST_CHECK_EQUAL(
cfg.binIndex(
i * 10.0), 4);
426 BOOST_CHECK_EQUAL(
cfg.binIndex(
i * 1000.0), 4);
431 EtaBinnedConfig
cfg{std::vector<double>{0, 1, 2}};
432 for (
int i = -1;
i <= 1;
i =
i + 2) {
433 BOOST_CHECK_EQUAL(
cfg.binIndex(
i * 0.0), 0);
434 BOOST_CHECK_EQUAL(
cfg.binIndex(
i * 1.0), 1);
436 cfg.binIndex(
i * (2.0 - std::numeric_limits<double>::epsilon())), 1);
437 BOOST_CHECK_THROW(
cfg.binIndex(
i * 2.0), std::invalid_argument);
446 cfg.cutSets.at(0).ptMin = 0.9;
447 cfg.cutSets.at(1).ptMin = 0.4;
459 cfg.cutSets.resize(1);
463 cfg.cutSets.resize(3);
470 BOOST_CHECK_EQUAL(selector.config().absEtaEdges.size(), 2);
475 cfg.addCuts(2.0, [](
auto&
c) {
c.loc0(-1.0, 1.0); });
476 BOOST_CHECK_THROW(
cfg.addCuts(1.0), std::invalid_argument);
478 std::invalid_argument);
484 cfg.addCuts(2.0, [](
auto&
c) {
c.loc0(-1.0, 1.0); });
485 BOOST_CHECK_EQUAL(
cfg.nEtaBins(), 1);
486 BOOST_CHECK_EQUAL(
cfg.getCuts(1.5).loc0Min, -1.0);
487 BOOST_CHECK_EQUAL(
cfg.getCuts(1.5).loc0Max, 1.0);
489 cfg.addCuts(3.0, [](
auto&
c) {
c.loc0(-2.0, 2.0); });
490 BOOST_CHECK_EQUAL(
cfg.nEtaBins(), 2);
491 BOOST_CHECK_EQUAL(
cfg.getCuts(2.5).loc0Min, -2.0);
492 BOOST_CHECK_EQUAL(
cfg.getCuts(2.5).loc0Max, 2.0);
494 cfg.addCuts(4.0, [](
auto&
c) {
c.loc0(-3.0, 3.0); });
495 BOOST_CHECK_EQUAL(
cfg.nEtaBins(), 3);
496 BOOST_CHECK_EQUAL(
cfg.getCuts(3.5).loc0Min, -3.0);
497 BOOST_CHECK_EQUAL(
cfg.getCuts(3.5).loc0Max, 3.0);
501 BOOST_AUTO_TEST_SUITE_END()