diff --git a/Trigger/TrigHypothesis/TrigHLTJetHypoUnitTests/CMakeLists.txt b/Trigger/TrigHypothesis/TrigHLTJetHypoUnitTests/CMakeLists.txt index 95aefaf50a23945c3a8bc7e2211534d869ccd662..f3ca08ee39b6099f9f44325a613357dee464311b 100644 --- a/Trigger/TrigHypothesis/TrigHLTJetHypoUnitTests/CMakeLists.txt +++ b/Trigger/TrigHypothesis/TrigHLTJetHypoUnitTests/CMakeLists.txt @@ -29,7 +29,8 @@ atlas_add_test( TrigHLTJetHypoUnitTests src/FlowNetworkTest.cxx src/LlpCleanerTest.cxx src/LooseCleanerTest.cxx - src/MaximumBipartiteMatcherTest.cxx + src/MaximumBipartiteGroupsMatcherTest.cxx + src/MaximumBipartiteGroupsMatcherMTTest.cxx src/MultiJetMatcherTest.cxx src/OrderedCollectionsMatcherTest.cxx src/SelectedJetsMatcherTest.cxx diff --git a/Trigger/TrigHypothesis/TrigHLTJetHypoUnitTests/src/MaximumBipartiteGroupsMatcherMTTest.cxx b/Trigger/TrigHypothesis/TrigHLTJetHypoUnitTests/src/MaximumBipartiteGroupsMatcherMTTest.cxx new file mode 100644 index 0000000000000000000000000000000000000000..6f217f14b3f2588465824b2d1dd57691c26da1de --- /dev/null +++ b/Trigger/TrigHypothesis/TrigHLTJetHypoUnitTests/src/MaximumBipartiteGroupsMatcherMTTest.cxx @@ -0,0 +1,359 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "TrigHLTJetHypo/../src//MaximumBipartiteGroupsMatcherMT.h" +#include "TrigHLTJetHypo/TrigHLTJetHypoUtils/HypoJetDefs.h" +#include "TrigHLTJetHypo/../src/ConditionsDefsMT.h" +#include "TrigHLTJetHypo/../src/conditionsFactoryMT.h" +#include "TrigHLTJetHypo/../src/ConditionDebugVisitor.h" +#include "TrigHLTJetHypo/TrigHLTJetHypoUtils/CombinationsGrouper.h" + +#include "./MockJetWithLorentzVector.h" +#include "./TLorentzVectorFactory.h" +#include "gtest/gtest.h" +#include "gmock/gmock.h" + +#include <TLorentzVector.h> +#include <memory> +#include <iostream> + + +/* + * MaximumBipartiteMatcher functionality tested: + * 0 fail if no jet vector indices + * 1 fail if no if there are fewer passing jets than conditions + * 2 pass if there are at least as many passing jets as conditions + * 3 conditions are ordered by threshold + * 4 jets are ordered by Et + * + * Mocked objects: + * - jet: will be ordered on ET, need TLorentzVector, hence + * MockJetWithLorentzVector + * - ICondition + */ + +using ::testing::Return; +using ::testing::_; +using ::testing::SetArgReferee; + + +class MaximumBipartiteGroupsMatcherMTTest: public ::testing::Test { +public: + MaximumBipartiteGroupsMatcherMTTest() { + + + std::vector<double> etaMins{-1., -1., -1.}; + std::vector<double> etaMaxs{1., 1, 1.}; + std::vector<double> thresholds{100., 120, 140.}; + std::vector<int> asymmetricEtas{0, 0, 0, 0}; + + m_conditions = conditionsFactoryEtaEtMT(etaMins, etaMaxs, + thresholds, asymmetricEtas); + m_nconditions = m_conditions.size(); + } + + ConditionsMT m_conditions; + int m_nconditions; +}; + +HypoJetGroupVector makeJetGroupsMT(HypoJetIter b, HypoJetIter e){ + CombinationsGrouper g(1); // single jet groups + return g.group(b, e); +} + +TEST_F(MaximumBipartiteGroupsMatcherMTTest, zeroInputJets){ + /* test with 0 jets - fails, no passed for failed jets */ + + MaximumBipartiteGroupsMatcherMT matcher(m_conditions); + + HypoJetVector jets; + auto groups = makeJetGroupsMT(jets.begin(), jets.end()); + auto visitor = std::unique_ptr<IConditionVisitor>(nullptr); + + bool pass = matcher.match(groups.begin(), groups.end(), visitor); + + EXPECT_FALSE(pass); +} + + +TEST_F(MaximumBipartiteGroupsMatcherMTTest, tooFewSelectedJets){ + /* pass fewer jets than indicies. Fails, all jets are bad */ + + double eta{5}; + double et{100.}; + + auto factory = TLorentzVectorFactory(); + auto tl = factory.make(eta, et); + + MockJetWithLorentzVector jet0(tl); + MockJetWithLorentzVector jet1{tl}; + + HypoJetVector jets{&jet0, &jet1}; + auto groups = makeJetGroupsMT(jets.begin(), jets.end()); + auto visitor = std::unique_ptr<IConditionVisitor>(nullptr); + + MaximumBipartiteGroupsMatcherMT matcher(m_conditions); + bool pass = matcher.match(groups.begin(), groups.end(), visitor); + + EXPECT_FALSE(pass); +} + + +TEST_F(MaximumBipartiteGroupsMatcherMTTest, oneSelectedJet){ + /* 1 jet1 over highest threshold - check good/bad jet list, fail. */ + + double eta{5}; + double et{100.}; + + auto factory = TLorentzVectorFactory(); + auto tl = factory.make(eta, et); + + MockJetWithLorentzVector jet0(tl); + MockJetWithLorentzVector jet1{tl}; + MockJetWithLorentzVector jet2{tl}; + + eta = 0; + et = 150; + auto tl0 = factory.make(eta, et); + MockJetWithLorentzVector jet3{tl0}; + + HypoJetVector jets{&jet0, &jet1, &jet2, &jet3}; + + EXPECT_CALL(jet0, eta()).Times(m_nconditions); + EXPECT_CALL(jet1, eta()).Times(m_nconditions); + EXPECT_CALL(jet2, eta()).Times(m_nconditions); + EXPECT_CALL(jet3, eta()).Times(m_nconditions); + + EXPECT_CALL(jet0, et()).Times(m_nconditions); + EXPECT_CALL(jet1, et()).Times(m_nconditions); + EXPECT_CALL(jet2, et()).Times(m_nconditions); + EXPECT_CALL(jet3, et()).Times(m_nconditions); + + auto groups = makeJetGroupsMT(jets.begin(), jets.end()); + auto visitor = std::unique_ptr<IConditionVisitor>(nullptr); + + MaximumBipartiteGroupsMatcherMT matcher(m_conditions); + bool pass = matcher.match(groups.begin(), groups.end(), visitor); + + EXPECT_FALSE(pass); +} + + +TEST_F(MaximumBipartiteGroupsMatcherMTTest, twoSelectedJets){ + /* 2 jets over repsective thresholds - check good/bad jet list, fail. */ + + + double eta{5}; + double et{100.}; + + auto factory = TLorentzVectorFactory(); + auto tl0 = factory.make(eta, et); + + MockJetWithLorentzVector jet0(tl0); + + eta = 0.1; + et = 139; + auto tl1 = factory.make(eta, et); + + MockJetWithLorentzVector jet1{tl1}; + + + eta = 5.; + et = 100.; + auto tl2 = factory.make(eta, et); + MockJetWithLorentzVector jet2{tl2}; + + eta = 0; + et = 150; + auto tl3 = factory.make(eta, et); + MockJetWithLorentzVector jet3{tl3}; + + HypoJetVector jets{&jet0, &jet1, &jet2, &jet3}; + + + EXPECT_CALL(jet0, eta()).Times(m_nconditions); + EXPECT_CALL(jet1, eta()).Times(m_nconditions); + EXPECT_CALL(jet2, eta()).Times(m_nconditions); + EXPECT_CALL(jet3, eta()).Times(m_nconditions); + + EXPECT_CALL(jet0, et()).Times(m_nconditions); + EXPECT_CALL(jet1, et()).Times(m_nconditions); + EXPECT_CALL(jet2, et()).Times(m_nconditions); + EXPECT_CALL(jet3, et()).Times(m_nconditions); + + MaximumBipartiteGroupsMatcherMT matcher(m_conditions); + auto groups = makeJetGroupsMT(jets.begin(), jets.end()); + auto visitor = std::unique_ptr<IConditionVisitor>(nullptr); + + bool pass = matcher.match(groups.begin(), groups.end(), visitor); + + EXPECT_FALSE(pass); +} + + +TEST_F(MaximumBipartiteGroupsMatcherMTTest, threeSelectedJets){ + /* 3 jets over repsective thresholds - check good/bad jet list, pass. + Expect no failed jets (alg stops on success) and no checks on the + unused jet*/ + + double eta{5}; + double et{100.}; + + auto factory = TLorentzVectorFactory(); + auto tl0 = factory.make(eta, et); + + MockJetWithLorentzVector jet0(tl0); + + eta = 0.1; + et = 139; + auto tl1 = factory.make(eta, et); + + MockJetWithLorentzVector jet1{tl1}; + + + eta = 0.5; + et = 141.; + auto tl2 = factory.make(eta, et); + MockJetWithLorentzVector jet2{tl2}; + + eta = -0.2; + et = 101.; + auto tl3 = factory.make(eta, et); + MockJetWithLorentzVector jet3{tl3}; + + HypoJetVector jets{&jet0, &jet1, &jet2, &jet3}; + + + EXPECT_CALL(jet1, eta()).Times(m_nconditions); + EXPECT_CALL(jet2, eta()).Times(m_nconditions); + EXPECT_CALL(jet3, eta()).Times(m_nconditions); + EXPECT_CALL(jet0, eta()).Times(m_nconditions); + + EXPECT_CALL(jet1, et()).Times(m_nconditions); + EXPECT_CALL(jet2, et()).Times(m_nconditions); + EXPECT_CALL(jet3, et()).Times(m_nconditions); + EXPECT_CALL(jet0, et()).Times(m_nconditions); + + MaximumBipartiteGroupsMatcherMT matcher(m_conditions); + auto groups = makeJetGroupsMT(jets.begin(), jets.end()); + auto visitor = std::unique_ptr<IConditionVisitor>(nullptr); + + bool pass = matcher.match(groups.begin(), groups.end(), visitor); + + EXPECT_TRUE(pass); +} + + +TEST_F(MaximumBipartiteGroupsMatcherMTTest, fourSelectedJets){ + /* 4 jets over repsective thresholds - check good/bad jet list, pass. + Expect no failed jets (alg stops on success) and no checks on the + unused jet*/ + + double eta{-0.6}; + double et{180.}; + + auto factory = TLorentzVectorFactory(); + auto tl0 = factory.make(eta, et); + + MockJetWithLorentzVector jet0(tl0); + + eta = 0.1; + et = 139; + auto tl1 = factory.make(eta, et); + + MockJetWithLorentzVector jet1{tl1}; + + + eta = 0.5; + et = 175.; + auto tl2 = factory.make(eta, et); + MockJetWithLorentzVector jet2{tl2}; + + eta = -0.2; + et = 101.; + auto tl3 = factory.make(eta, et); + MockJetWithLorentzVector jet3{tl3}; + + HypoJetVector jets{&jet0, &jet1, &jet2, &jet3}; + + EXPECT_CALL(jet0, eta()).Times(m_nconditions); + EXPECT_CALL(jet1, eta()).Times(m_nconditions); + EXPECT_CALL(jet2, eta()).Times(m_nconditions); + EXPECT_CALL(jet3, eta()).Times(m_nconditions); + + EXPECT_CALL(jet0, et()).Times(m_nconditions); + EXPECT_CALL(jet1, et()).Times(m_nconditions); + EXPECT_CALL(jet2, et()).Times(m_nconditions); + EXPECT_CALL(jet3, et()).Times(m_nconditions); + + MaximumBipartiteGroupsMatcherMT matcher(m_conditions); + auto groups = makeJetGroupsMT(jets.begin(), jets.end()); + auto visitor = std::unique_ptr<IConditionVisitor>(nullptr); + + bool pass = matcher.match(groups.begin(), groups.end(), visitor); + + EXPECT_TRUE(pass); +} + + + +TEST_F(MaximumBipartiteGroupsMatcherMTTest, overlappingEtaRegions){ + /* 4 jets over repsective thresholds - check good/bad jet list, pass. + Expect no failed jets (alg stops on success) and no checks on the + unused jet*/ + + std::vector<double> etaMins{-1.00, -1.00, -0.25, -0.25}; + std::vector<double> etaMaxs{ 0.25, 0.25, 1.00, 1.00}; + std::vector<double> thresholds{100., 80, 140., 90.}; + std::vector<int> asymmetricEtas{0, 0, 0, 0}; + + auto conditions = conditionsFactoryEtaEtMT(etaMins, etaMaxs, + thresholds, asymmetricEtas); + int nconditions = conditions.size(); + + double eta{0.1}; + double et{180.}; + + auto factory = TLorentzVectorFactory(); + auto tl0 = factory.make(eta, et); + + MockJetWithLorentzVector jet0(tl0); + + eta = 0.1; + et = 101; + auto tl1 = factory.make(eta, et); + + MockJetWithLorentzVector jet1{tl1}; + + + eta = 0.1; + et = 91.; + auto tl2 = factory.make(eta, et); + MockJetWithLorentzVector jet2{tl2}; + + eta = 0.1; + et = 81.; + auto tl3 = factory.make(eta, et); + MockJetWithLorentzVector jet3{tl3}; + + HypoJetVector jets{&jet0, &jet1, &jet2, &jet3}; + + EXPECT_CALL(jet0, eta()).Times(nconditions); + EXPECT_CALL(jet1, eta()).Times(nconditions); + EXPECT_CALL(jet2, eta()).Times(nconditions); + EXPECT_CALL(jet3, eta()).Times(nconditions); + + EXPECT_CALL(jet0, et()).Times(nconditions); + EXPECT_CALL(jet1, et()).Times(nconditions); + EXPECT_CALL(jet2, et()).Times(nconditions); + EXPECT_CALL(jet3, et()).Times(nconditions); + + MaximumBipartiteGroupsMatcherMT matcher(conditions); + auto groups = makeJetGroupsMT(jets.begin(), jets.end()); + auto visitor = std::unique_ptr<IConditionVisitor>(nullptr); + + bool pass = matcher.match(groups.begin(), groups.end(), visitor); + + EXPECT_TRUE(pass); +} diff --git a/Trigger/TrigHypothesis/TrigHLTJetHypoUnitTests/src/MaximumBipartiteGroupsMatcherTest.cxx b/Trigger/TrigHypothesis/TrigHLTJetHypoUnitTests/src/MaximumBipartiteGroupsMatcherTest.cxx index 9007660739a87ccb3f60ada0af45767cdd811c80..baaebf52e9ea9be7e20e8f2031259ea5c460612f 100644 --- a/Trigger/TrigHypothesis/TrigHLTJetHypoUnitTests/src/MaximumBipartiteGroupsMatcherTest.cxx +++ b/Trigger/TrigHypothesis/TrigHLTJetHypoUnitTests/src/MaximumBipartiteGroupsMatcherTest.cxx @@ -5,7 +5,9 @@ #include "TrigHLTJetHypo/TrigHLTJetHypoUtils/MaximumBipartiteGroupsMatcher.h" #include "TrigHLTJetHypo/TrigHLTJetHypoUtils/HypoJetDefs.h" #include "TrigHLTJetHypo/TrigHLTJetHypoUtils/ConditionsDefs.h" -#include "TrigHLTJetHypo/TrigHLTJetHypoUtils/conditionsFactory.h" +#include "TrigHLTJetHypo/TrigHLTJetHypoUtils/conditionsFactory2.h" +#include "TrigHLTJetHypo/TrigHLTJetHypoUtils/CombinationsGrouper.h" + #include "./MockJetWithLorentzVector.h" #include "./TLorentzVectorFactory.h" #include "gtest/gtest.h" @@ -43,24 +45,30 @@ public: std::vector<double> etaMins{-1., -1., -1.}; std::vector<double> etaMaxs{1., 1, 1.}; std::vector<double> thresholds{100., 120, 140.}; + std::vector<int> asymmetricEtas{0, 0, 0, 0}; - m_conditions = conditionsFactory(etaMins, etaMaxs, thresholds); - m_name = "testOrderedConditionsMatcher"; + m_conditions = conditionsFactoryEtaEt(etaMins, etaMaxs, + thresholds, asymmetricEtas); m_nconditions = m_conditions.size(); } Conditions m_conditions; int m_nconditions; - std::string m_name; }; - +HypoJetGroupVector makeJetGroups(HypoJetIter b, HypoJetIter e){ + CombinationsGrouper g(1); // single jet groups + return g.group(b, e); +} + TEST_F(MaximumBipartiteGroupsMatcherTest, zeroInputJets){ /* test with 0 jets - fails, no passed for failed jets */ + MaximumBipartiteGroupsMatcher matcher(m_conditions); + HypoJetVector jets; - MaximumBipartiteGroupsMatcher matcher(m_conditions, m_name); - matcher.match(jets.begin(), jets.end()); + auto groups = makeJetGroups(jets.begin(), jets.end()); + matcher.match(groups.begin(), groups.end()); EXPECT_FALSE(matcher.pass()); EXPECT_EQ(matcher.passedJets().size(), static_cast<unsigned int>(0)); @@ -81,9 +89,10 @@ TEST_F(MaximumBipartiteGroupsMatcherTest, tooFewSelectedJets){ MockJetWithLorentzVector jet1{tl}; HypoJetVector jets{&jet0, &jet1}; + auto groups = makeJetGroups(jets.begin(), jets.end()); - MaximumBipartiteGroupsMatcher matcher(m_conditions, m_name); - matcher.match(jets.begin(), jets.end()); + MaximumBipartiteGroupsMatcher matcher(m_conditions); + matcher.match(groups.begin(), groups.end()); EXPECT_FALSE(matcher.pass()); EXPECT_EQ(matcher.passedJets().size(), static_cast<unsigned int>(0)); @@ -121,8 +130,10 @@ TEST_F(MaximumBipartiteGroupsMatcherTest, oneSelectedJet){ EXPECT_CALL(jet2, et()).Times(m_nconditions); EXPECT_CALL(jet3, et()).Times(m_nconditions); - MaximumBipartiteGroupsMatcher matcher(m_conditions, m_name); - matcher.match(jets.begin(), jets.end()); + auto groups = makeJetGroups(jets.begin(), jets.end()); + + MaximumBipartiteGroupsMatcher matcher(m_conditions); + matcher.match(groups.begin(), groups.end()); EXPECT_FALSE(matcher.pass()); EXPECT_EQ(matcher.passedJets().size(), static_cast<unsigned int>(1)); @@ -172,8 +183,10 @@ TEST_F(MaximumBipartiteGroupsMatcherTest, twoSelectedJets){ EXPECT_CALL(jet2, et()).Times(m_nconditions); EXPECT_CALL(jet3, et()).Times(m_nconditions); - MaximumBipartiteGroupsMatcher matcher(m_conditions, m_name); - matcher.match(jets.begin(), jets.end()); + MaximumBipartiteGroupsMatcher matcher(m_conditions); + auto groups = makeJetGroups(jets.begin(), jets.end()); + + matcher.match(groups.begin(), groups.end()); EXPECT_FALSE(matcher.pass()); EXPECT_EQ(matcher.passedJets().size(), static_cast<unsigned int>(2)); @@ -224,8 +237,10 @@ TEST_F(MaximumBipartiteGroupsMatcherTest, threeSelectedJets){ EXPECT_CALL(jet3, et()).Times(m_nconditions); EXPECT_CALL(jet0, et()).Times(m_nconditions); - MaximumBipartiteGroupsMatcher matcher(m_conditions, m_name); - matcher.match(jets.begin(), jets.end()); + MaximumBipartiteGroupsMatcher matcher(m_conditions); + auto groups = makeJetGroups(jets.begin(), jets.end()); + + matcher.match(groups.begin(), groups.end()); EXPECT_TRUE(matcher.pass()); EXPECT_EQ(matcher.passedJets().size(), static_cast<unsigned int>(3)); @@ -275,8 +290,9 @@ TEST_F(MaximumBipartiteGroupsMatcherTest, fourSelectedJets){ EXPECT_CALL(jet2, et()).Times(m_nconditions); EXPECT_CALL(jet3, et()).Times(m_nconditions); - MaximumBipartiteGroupsMatcher matcher(m_conditions, m_name); - matcher.match(jets.begin(), jets.end()); + MaximumBipartiteGroupsMatcher matcher(m_conditions); + auto groups = makeJetGroups(jets.begin(), jets.end()); + matcher.match(groups.begin(), groups.end()); EXPECT_TRUE(matcher.pass()); EXPECT_EQ(matcher.passedJets().size(), static_cast<unsigned int>(3)); @@ -293,9 +309,10 @@ TEST_F(MaximumBipartiteGroupsMatcherTest, overlappingEtaRegions){ std::vector<double> etaMins{-1.00, -1.00, -0.25, -0.25}; std::vector<double> etaMaxs{ 0.25, 0.25, 1.00, 1.00}; std::vector<double> thresholds{100., 80, 140., 90.}; + std::vector<int> asymmetricEtas{0, 0, 0, 0}; - auto conditions = conditionsFactory(etaMins, etaMaxs, thresholds); - std::string name = "overlappingRegionsMatcher"; + auto conditions = conditionsFactoryEtaEt(etaMins, etaMaxs, + thresholds, asymmetricEtas); int nconditions = conditions.size(); double eta{0.1}; @@ -335,8 +352,9 @@ TEST_F(MaximumBipartiteGroupsMatcherTest, overlappingEtaRegions){ EXPECT_CALL(jet2, et()).Times(nconditions); EXPECT_CALL(jet3, et()).Times(nconditions); - MaximumBipartiteGroupsMatcher matcher(conditions, name); - matcher.match(jets.begin(), jets.end()); + MaximumBipartiteGroupsMatcher matcher(conditions); + auto groups = makeJetGroups(jets.begin(), jets.end()); + matcher.match(groups.begin(), groups.end()); EXPECT_TRUE(matcher.pass()); EXPECT_EQ(matcher.passedJets().size(), static_cast<unsigned int>(4));