Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:13:06

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/unit_test.hpp>
0010 
0011 #include "ActsFatras/Selectors/KinematicCasts.hpp"
0012 #include "ActsFatras/Selectors/SelectorHelpers.hpp"
0013 
0014 #include <string>
0015 
0016 #include "Dataset.hpp"
0017 
0018 namespace {
0019 const auto& backward = Dataset::backwardPion;
0020 const auto& central = Dataset::centralPion;
0021 const auto& forward = Dataset::forwardPion;
0022 
0023 // mock-ups for input objects (particles)
0024 
0025 struct Object {
0026   int feature = 0;
0027   std::string name = "";
0028 };
0029 
0030 /// Selector that selects on the feature. Only acts on the object.
0031 struct FeatureSelector {
0032   int select_on = 0;
0033 
0034   bool operator()(const Object& object) const {
0035     return object.feature == select_on;
0036   }
0037 };
0038 
0039 /// Selector that selects on the name. Only acts on the object.
0040 struct NameSelector {
0041   std::string select_on = "";
0042 
0043   bool operator()(const Object& object) const {
0044     return object.name == select_on;
0045   }
0046 };
0047 
0048 struct CombineFixture {
0049   FeatureSelector selectObjectFeature = {1};
0050   NameSelector selectObjectName = {"same_name"};
0051   Object obj = {1, "same_name"};
0052   Object objWrongFeature = {2, "same_name"};
0053   Object objWrongName = {1, "another_name"};
0054 };
0055 
0056 }  // namespace
0057 
0058 BOOST_AUTO_TEST_SUITE(FatrasSelectorHelpers)
0059 
0060 BOOST_AUTO_TEST_CASE(Min) {
0061   // require a minimum eta value of 0.5
0062   ActsFatras::Min<ActsFatras::Casts::Eta> minEta{0.5};
0063   BOOST_CHECK(!minEta(backward));
0064   BOOST_CHECK(!minEta(central));
0065   BOOST_CHECK(minEta(forward));
0066 
0067   // require a minimum absolute eta value of 0.5
0068   ActsFatras::Min<ActsFatras::Casts::AbsEta> minAbsEta{0.5};
0069   BOOST_CHECK(minAbsEta(backward));
0070   BOOST_CHECK(!minAbsEta(central));
0071   BOOST_CHECK(minAbsEta(forward));
0072 }
0073 
0074 BOOST_AUTO_TEST_CASE(Max) {
0075   // require a maximum eta value of 0.5
0076   ActsFatras::Max<ActsFatras::Casts::Eta> maxEta{0.5};
0077   BOOST_CHECK(maxEta(backward));
0078   BOOST_CHECK(maxEta(central));
0079   BOOST_CHECK(!maxEta(forward));
0080 
0081   // require a maximum absolute eta value of 0.5
0082   ActsFatras::Max<ActsFatras::Casts::AbsEta> maxAbsEta{0.5};
0083   BOOST_CHECK(!maxAbsEta(backward));
0084   BOOST_CHECK(maxAbsEta(central));
0085   BOOST_CHECK(!maxAbsEta(forward));
0086 }
0087 
0088 BOOST_AUTO_TEST_CASE(Range) {
0089   ActsFatras::Range<ActsFatras::Casts::Eta> rangeEta{-6.0, -0.5};
0090   BOOST_CHECK(rangeEta(backward));
0091   BOOST_CHECK(!rangeEta(central));
0092   BOOST_CHECK(!rangeEta(forward));
0093 
0094   ActsFatras::Range<ActsFatras::Casts::AbsEta> rangeAbsEta{0.5, 6.0};
0095   BOOST_CHECK(rangeAbsEta(backward));
0096   BOOST_CHECK(!rangeAbsEta(central));
0097   BOOST_CHECK(rangeAbsEta(forward));
0098 }
0099 
0100 BOOST_AUTO_TEST_CASE(And1) {
0101   CombineFixture f;
0102   ActsFatras::CombineAnd<FeatureSelector> select;
0103   select.get<FeatureSelector>() = f.selectObjectFeature;
0104   BOOST_CHECK(select(f.obj));
0105   BOOST_CHECK(!select(f.objWrongFeature));
0106   BOOST_CHECK(select(f.objWrongName));
0107 }
0108 
0109 BOOST_AUTO_TEST_CASE(And2) {
0110   CombineFixture f;
0111   ActsFatras::CombineAnd<FeatureSelector, NameSelector> select;
0112   select.get<FeatureSelector>() = f.selectObjectFeature;
0113   select.get<NameSelector>() = f.selectObjectName;
0114   BOOST_CHECK(select(f.obj));
0115   BOOST_CHECK(!select(f.objWrongFeature));
0116   BOOST_CHECK(!select(f.objWrongName));
0117 }
0118 
0119 BOOST_AUTO_TEST_CASE(Or1) {
0120   CombineFixture f;
0121   ActsFatras::CombineOr<FeatureSelector> select;
0122   select.get<FeatureSelector>() = f.selectObjectFeature;
0123   BOOST_CHECK(select(f.obj));
0124   BOOST_CHECK(!select(f.objWrongFeature));
0125   BOOST_CHECK(select(f.objWrongName));
0126 }
0127 
0128 BOOST_AUTO_TEST_CASE(Or2) {
0129   CombineFixture f;
0130   ActsFatras::CombineOr<FeatureSelector, NameSelector> select;
0131   select.get<FeatureSelector>() = f.selectObjectFeature;
0132   select.get<NameSelector>() = f.selectObjectName;
0133   BOOST_CHECK(select(f.obj));
0134   BOOST_CHECK(select(f.objWrongFeature));
0135   BOOST_CHECK(select(f.objWrongName));
0136 }
0137 
0138 BOOST_AUTO_TEST_SUITE_END()