Belle II Software  release-05-01-25
SingleMatchSelector.test.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2016 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Nils Braun *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <tracking/trackFindingCDC/collectors/selectors/SingleMatchSelector.h>
12 
13 #include <tracking/trackFindingCDC/numerics/WeightComperator.h>
14 
15 #include <gtest/gtest.h>
16 
17 using namespace Belle2;
18 using namespace TrackFindingCDC;
19 
20 namespace {
22  TEST(TrackFindingCDCTest, single_match_selector)
23  {
24  SingleMatchSelector<int, double> selector;
25 
26  int a = 1, b = 2;
27  double c = 3, d = 4, e = 5;
28 
29  std::vector<WeightedRelation<int, const double>> relations = {
30  WeightedRelation<int, const double>(&a, 1.1, &c),
31  WeightedRelation<int, const double>(&a, 1.0, &d),
32  WeightedRelation<int, const double>(&b, 0.8, &c),
33  WeightedRelation<int, const double>(&b, 0.6, &e)
34  };
35 
36  std::sort(relations.begin(), relations.end());
37  selector.apply(relations);
38 
39  std::sort(relations.begin(), relations.end(), GreaterWeight());
40 
41  ASSERT_EQ(relations.size(), 2);
42  ASSERT_EQ(relations[0].getWeight(), 1.0);
43  ASSERT_EQ(relations[0].getFrom(), &a);
44  ASSERT_EQ(relations[0].getTo(), &d);
45  ASSERT_EQ(relations[1].getWeight(), 0.6);
46  ASSERT_EQ(relations[1].getFrom(), &b);
47  ASSERT_EQ(relations[1].getTo(), &e);
48 
49  }
50 
52  TEST(TrackFindingCDCTest, single_best_match_selector)
53  {
54  SingleMatchSelector<int, double> selector;
55  selector.setUseOnlySingleBestCandidate(false);
56 
57  int a = 1, b = 2, c = 3;
58  double d = 4, e = 5, f = 6;
59 
60  std::vector<WeightedRelation<int, const double>> relations = {
61  WeightedRelation<int, const double>(&a, 1.1, &d),
62  WeightedRelation<int, const double>(&a, 1.0, &e),
63  WeightedRelation<int, const double>(&b, 0.8, &d),
64  WeightedRelation<int, const double>(&b, 0.6, &f),
65  WeightedRelation<int, const double>(&c, 0.6, &d),
66  };
67 
68  std::sort(relations.begin(), relations.end());
69  selector.apply(relations);
70 
71  std::sort(relations.begin(), relations.end(), GreaterWeight());
72 
73  ASSERT_EQ(relations.size(), 3);
74  ASSERT_EQ(relations[0].getWeight(), 1.1);
75  ASSERT_EQ(relations[0].getFrom(), &a);
76  ASSERT_EQ(relations[0].getTo(), &d);
77  ASSERT_EQ(relations[1].getWeight(), 1.0);
78  ASSERT_EQ(relations[1].getFrom(), &a);
79  ASSERT_EQ(relations[1].getTo(), &e);
80  ASSERT_EQ(relations[2].getWeight(), 0.6);
81  ASSERT_EQ(relations[2].getFrom(), &b);
82  ASSERT_EQ(relations[2].getTo(), &f);
83  }
84 
86  struct CustomComparer {
87  bool operator()(const double* lhs, const double* rhs) const
88  {
89  return (static_cast<int>(*lhs) % 2) < (static_cast<int>(*rhs) % 2);
90  }
91  };
92 
94  TEST(TrackFindingCDCTest, single_match_selector_with_comparer)
95  {
96  SingleMatchSelector<int, double, CustomComparer> selector;
97 
98  int a = 1, b = 2;
99  double c = 3, d = 4, e = 5;
100 
101  std::vector<WeightedRelation<int, const double>> relations = {
102  WeightedRelation<int, const double>(&a, 1.1, &c),
103  WeightedRelation<int, const double>(&a, 1.0, &d),
104  WeightedRelation<int, const double>(&b, 0.8, &c),
105  WeightedRelation<int, const double>(&b, 0.6, &e)
106  };
107 
108  std::sort(relations.begin(), relations.end());
109  selector.apply(relations);
110 
111  std::sort(relations.begin(), relations.end(), GreaterWeight());
112 
113  ASSERT_EQ(relations.size(), 1);
114  ASSERT_EQ(relations[0].getWeight(), 1.0);
115  ASSERT_EQ(relations[0].getFrom(), &a);
116  ASSERT_EQ(relations[0].getTo(), &d);
117  }
118 }
prepareAsicCrosstalkSimDB.e
e
aux.
Definition: prepareAsicCrosstalkSimDB.py:53
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TEST
TEST(TestgetDetectorRegion, TestgetDetectorRegion)
Test Constructors.
Definition: utilityFunctions.cc:18