Belle II Software  release-05-01-25
TreeTraversal.test.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2017 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Oliver Frost <oliver.frost@desy.de> *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <gtest/gtest.h>
12 #include <tracking/trackFindingCDC/findlets/generic/TreeTraversal.h>
13 #include <tracking/trackFindingCDC/findlets/generic/WeightedTreeTraversal.h>
14 
15 #include <tracking/trackFindingCDC/findlets/base/Findlet.h>
16 
17 #include <tracking/trackFindingCDC/numerics/Weight.h>
18 #include <tracking/trackFindingCDC/numerics/WithWeight.h>
19 
20 #include <tracking/trackFindingCDC/utilities/Functional.h>
21 #include <tracking/trackFindingCDC/utilities/Algorithms.h>
22 
23 #include <vector>
24 
25 using namespace Belle2;
26 using namespace TrackFindingCDC;
27 
28 namespace {
29  using State = int;
30  using Result = std::vector<const int*>;
31 
32  class AcceptAll : public Findlet<const int* const, int*> {
33  public:
34  void apply(const std::vector<const int*>& currentPath __attribute__((unused)),
35  std::vector<int*>& nextStates __attribute__((unused))) override
36  {
37  // Do not filter states at all.
38  }
39  };
40 
41  class AcceptHighWeight : public Findlet<const int* const, WithWeight<int*> > {
42  public:
43  void apply(const std::vector<const int*>& currentPath __attribute__((unused)),
44  std::vector<WithWeight<int*>>& nextStates __attribute__((unused)))
45  {
46  // Remove states with low weight
47  erase_remove_if(nextStates, GetWeight() < 0.5);
48  }
49  };
50 }
51 
52 
53 TEST(TrackFindingCDCTest, Findlet_generic_TreeTraversal)
54 {
55  TreeTraversal<AcceptAll, State, Result> testTreeTraversal;
56 
57  // Prepare states
58  std::vector<int> states({1, 2, 3});
59 
60  // Prepare relations
61  std::vector<Relation<int> > stateRelations;
62  stateRelations.push_back({&states[1], &states[2]});
63  stateRelations.push_back({&states[0], &states[2]});
64  stateRelations.push_back({&states[0], &states[1]});
65  std::sort(stateRelations.begin(), stateRelations.end());
66 
67  // Select some seeds
68  std::vector<const int*> seedStates;
69  seedStates.push_back(&states[0]);
70 
71  // Find the paths
72  std::vector<std::vector<const int*>> results;
73  testTreeTraversal.apply(seedStates, stateRelations, results);
74 
75  ASSERT_EQ(2, results.size());
76 
77  ASSERT_EQ(3, results[0].size());
78  EXPECT_EQ(1, *results[0][0]);
79  EXPECT_EQ(2, *results[0][1]);
80  EXPECT_EQ(3, *results[0][2]);
81 
82  ASSERT_EQ(2, results[1].size());
83  EXPECT_EQ(1, *results[1][0]);
84  EXPECT_EQ(3, *results[1][1]);
85 }
86 
87 TEST(TrackFindingCDCTest, Findlet_generic_WeightedTreeTraversal)
88 {
89  WeightedTreeTraversal<AcceptHighWeight, State> testWeightedTreeTraversal;
90 
91  // Prepare states
92  std::vector<int> states({1, 2, 3});
93 
94  // Prepare relations
95  std::vector<WeightedRelation<int> > stateRelations;
96  stateRelations.push_back({&states[1], 0.1, &states[2]});
97  stateRelations.push_back({&states[0], 1, &states[2]});
98  stateRelations.push_back({&states[0], 1, &states[1]});
99  std::sort(stateRelations.begin(), stateRelations.end());
100 
101  // Select some seeds
102  std::vector<const int*> seedStates;
103  seedStates.push_back(&states[0]);
104 
105  // Find the paths
106  std::vector<std::vector<const int*>> results;
107  testWeightedTreeTraversal.apply(seedStates, stateRelations, results);
108 
109  ASSERT_EQ(2, results.size());
110 
111  ASSERT_EQ(2, results[0].size());
112  EXPECT_EQ(1, *results[0][0]);
113  EXPECT_EQ(2, *results[0][1]);
114 
115  ASSERT_EQ(2, results[1].size());
116  EXPECT_EQ(1, *results[1][0]);
117  EXPECT_EQ(3, *results[1][1]);
118 }
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TEST
TEST(TestgetDetectorRegion, TestgetDetectorRegion)
Test Constructors.
Definition: utilityFunctions.cc:18