9#include <analysis/dbobjects/ParticleWeightingLookUpTable.h>
10#include <analysis/dbobjects/ParticleWeightingBinLimits.h>
11#include <analysis/dbobjects/ParticleWeightingAxis.h>
13#include <framework/utilities/TestHelpers.h>
15#include <gtest/gtest.h>
22 TEST(ParticleWeighting, BinLimits)
25#ifndef __clang_analyzer__
27 EXPECT_TRUE(a->first() == 0);
28 EXPECT_TRUE(a->second() == 1);
30 EXPECT_TRUE(b->first() == 0);
31 EXPECT_TRUE(b->second() == 1);
35 TEST(ParticleWeighting, Axis)
38 EXPECT_TRUE(a->getName() ==
"");
39 a->setName(
"Test axis name");
40 EXPECT_TRUE(a->getName() ==
"Test axis name");
46 int added_bin_id_1 = a->addBin(bin1);
47 EXPECT_EQ(added_bin_id_1, 1);
48 int added_bin_id_2 = a->addBin(bin2);
49 EXPECT_EQ(added_bin_id_2, 2);
50#ifndef __clang_analyzer__
54 EXPECT_B2FATAL(a->addBin(bin3));
55 EXPECT_B2FATAL(a->addBin(bin4));
56 EXPECT_B2FATAL(a->addBin(bin5));
58 EXPECT_TRUE(a->findBin(0.5) == 1);
59 EXPECT_TRUE(a->findBin(1.5) == -1);
60 EXPECT_TRUE(a->findBin(bin1) == 1);
61 EXPECT_TRUE(a->addBin(bin1b) == 3);
64 TEST(ParticleWeighting, KeyMap)
73 bin1.insert(make_pair(a1, bl1));
74 bin1.insert(make_pair(a2, bl1));
76 bin2.insert(make_pair(a1, bl2));
77 bin2.insert(make_pair(a2, bl2));
79 bin3.insert(make_pair(a1, bl3));
80 bin3.insert(make_pair(a2, bl3));
82 bin1a.insert(make_pair(a1, bl2));
83 bin1a.insert(make_pair(a2, bl2));
84 bin1a.insert(make_pair(a3, bl3));
86 bin1b.insert(make_pair(a1, bl1));
87 bin1b.insert(make_pair(a1, bl2));
89 bin1c.insert(make_pair(a3, bl3));
90 bin1c.insert(make_pair(a2, bl2));
91 map<string, double> entry1;
92 entry1.insert(make_pair(a1, 0.1));
93 entry1.insert(make_pair(a2, 0.2));
94 map<string, double> entry2;
95 entry2.insert(make_pair(a1, 1.1));
96 entry2.insert(make_pair(a2, 1.2));
97 map<string, double> entry3;
98 entry3.insert(make_pair(a1, 10));
99 entry3.insert(make_pair(a2, 10));
102 int added_bin_id_1 = kmp->addKey(bin1);
103 EXPECT_EQ(added_bin_id_1, 0);
104 int added_bin_id_2 = kmp->addKey(bin2);
105 EXPECT_EQ(added_bin_id_2, 1);
106 EXPECT_B2FATAL(kmp->addKey(bin1, 42));
107 EXPECT_B2FATAL(kmp->addKey(bin1a));
108 EXPECT_B2FATAL(kmp->addKey(bin1b));
109 EXPECT_B2FATAL(kmp->addKey(bin1c));
110 EXPECT_EQ(kmp->getKey(entry1), 0);
111 EXPECT_EQ(kmp->getKey(entry2), 1);
112 EXPECT_EQ(kmp->getKey(entry3), -1);
115 TEST(ParticleWeighting, LookUpTable)
125 bin1.insert(make_pair(a1, bl1));
126 bin1.insert(make_pair(a2, bl1));
128 bin2.insert(make_pair(a1, bl2));
129 bin2.insert(make_pair(a2, bl2));
131 bin3.insert(make_pair(a1, bl3));
132 bin3.insert(make_pair(a2, bl3));
134 info1.insert(make_pair(v1, 41));
135 info1.insert(make_pair(v2, 42));
137 info2.insert(make_pair(v1, 31));
138 info2.insert(make_pair(v2, 32));
140 info3.insert(make_pair(v1, 21));
141 info3.insert(make_pair(v2, 22));
142 map<string, double> entry1;
143 entry1.insert(make_pair(a1, 0.1));
144 entry1.insert(make_pair(a2, 0.2));
145 map<string, double> entry1a;
146 entry1a.insert(make_pair(a1, 100));
147 entry1a.insert(make_pair(a2, 200));
150 ltb->addEntry(info1, bin1);
151 ltb->addEntry(info2, bin2);
152 vector<string> axes = ltb->getAxesNames();
153 vector<string> known_axes;
154 known_axes.push_back(a1);
155 known_axes.push_back(a2);
156 EXPECT_TRUE(equal(axes.begin(), axes.end(), known_axes.begin()));
157 WeightInfo obtained_info = ltb->getInfo(entry1);
158 double info_at_1 = obtained_info.at(v1);
159 EXPECT_EQ(info_at_1, 41);
160 double info_at_2 = obtained_info.at(v2);
161 EXPECT_EQ(info_at_2, 42);
163 EXPECT_B2FATAL(ltb->getInfo(entry1a));
165 ltb->defineOutOfRangeWeight(info3);
166 obtained_info = ltb->getInfo(entry1a);
167 info_at_2 = obtained_info.at(v2);
168 EXPECT_EQ(info_at_2, 22);
Class for handling LookUp tables.
Just pair of numbers - min and max values of bin border.
Class for handling KeyMap.
Class for handling LookUp tables.
std::map< std::string, ParticleWeightingBinLimits * > NDBin
N-dim bin: pairs of bin limits with name of the axis variable.
std::map< std::string, double > WeightInfo
Weight information: a line from the weight lookup table.
Abstract base class for different kinds of events.
const std::vector< double > v2
MATLAB generated random vector.
const std::vector< double > v1
MATLAB generated random vector.