12#include <analysis/dbobjects/PIDPriorsTable.h>
13#include <analysis/dbobjects/PIDPriors.h>
15#include <framework/gearbox/Const.h>
16#include <framework/utilities/TestHelpers.h>
20#include <gtest/gtest.h>
38 std::vector<float> edgesX = {0., 0.2, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1., 1.1, 1.2, 1.3, 1.4, 1.5, 1.7, 1.9, 2.2, 2.5, 3., 3.5, 4., 5., 6., 7., 10.};
39 std::vector<float> edgesY = { -1., -0.95, -0.9, -0.8, -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, 0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.95, 1.};
49 std::cout <<
"after setting (1.1, 0.54) amd (9.5, -0.67)" << std::endl;
55 std::cout <<
" ----- Setting the priors from outside ------ " << std::endl;
57 std::vector<float> prior;
59 for (
int j = 0; j < (int)edgesY.size() - 1; j++) {
60 for (
int i = 0; i < (int)edgesX.size() - 1; i++) {
61 prior.push_back(0.001 * (i + j * (edgesX.size() - 1)));
70 EXPECT_FLOAT_EQ(PIDTable.
getPriorValue(0.1, -0.98), 0.001 * (0 + 0 * (edgesX.size() - 1)));
71 EXPECT_FLOAT_EQ(PIDTable.
getPriorValue(0.71, -0.65), 0.001 * (5 + 4 * (edgesX.size() - 1)));
81 std::vector<float> badEdges1 = {0.};
82 std::vector<float> badEdges2 = {};
87 EXPECT_B2WARNING(PIDTable2.
setBinEdges(edgesX, badEdges1));
88 EXPECT_B2WARNING(PIDTable2.
setBinEdges(edgesX, badEdges2));
98 std::cout <<
"after setting (1.1, 0.54) and (9.5, -0.67)" << std::endl;
101 EXPECT_B2WARNING(PIDTable2.
setPriorValue(11.0, -10.01, 0.3));
113 std::vector<float> edgesX = {0., 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.};
114 std::vector<float> edgesY = { -1., -0.9, -0.8, -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, 0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.};
116 std::vector<float> prior1;
117 std::vector<float> prior2;
118 std::vector<float> prior3;
119 std::vector<float> prior4;
120 std::vector<float> prior5;
121 std::vector<float> prior6;
123 TH2F* counts1 =
new TH2F(
"counts1",
"counts1", 10, 0, 10., 20, -1, 1);
124 TH2F* counts2 =
new TH2F(
"counts2",
"counts2", 10, 0, 10., 20, -1, 1);
125 TH2F* counts3 =
new TH2F(
"counts3",
"counts3", 10, 0, 10., 20, -1, 1);
126 TH2F* counts4 =
new TH2F(
"counts4",
"counts4", 10, 0, 10., 20, -1, 1);
127 TH2F* counts5 =
new TH2F(
"counts5",
"counts5", 10, 0, 10., 20, -1, 1);
128 TH2F* counts6 =
new TH2F(
"counts6",
"counts6", 10, 0, 10., 20, -1, 1);
130 TH2F* norms =
new TH2F(
"norms",
"norms", 10, 0, 10., 20, -1, 1);
132 TRandom3*
rn =
new TRandom3();
136 for (
int i = 0; i < (int)edgesX.size() - 1; i++) {
137 for (
int j = 0; j < (int)edgesY.size() - 1; j++) {
139 float n1 = (float)
rn->Poisson(100);
140 float n2 = (float)
rn->Poisson(100);
141 float n3 = (float)
rn->Poisson(700);
142 float n4 = (float)
rn->Poisson(200);
143 float n5 = (float)
rn->Poisson(100);
144 float n6 = (float)
rn->Poisson(10);
146 float n = n1 + n2 + n3 + n4 + n5 + n6;
148 prior1.push_back(n1 / n);
149 prior2.push_back(n2 / n);
150 prior3.push_back(n3 / n);
151 prior4.push_back(n4 / n);
152 prior5.push_back(n5 / n);
153 prior6.push_back(n6 / n);
155 counts1->SetBinContent(i + 1, j + 1, n1);
156 counts2->SetBinContent(i + 1, j + 1, n2);
157 counts3->SetBinContent(i + 1, j + 1, n3);
158 counts4->SetBinContent(i + 1, j + 1, n4);
159 counts5->SetBinContent(i + 1, j + 1, n5);
160 counts6->SetBinContent(i + 1, j + 1, n6);
161 norms->SetBinContent(i + 1, j + 1, n);
199 std::cout <<
"setting the tables " << std::endl;
202 priors.setPriors(part_e, PIDTable1);
203 priors.setPriors(part_mu, PIDTable2);
204 priors.setPriors(part_pi, PIDTable3);
205 priors.setPriors(part_K, PIDTable4);
206 priors.setPriors(part_p, PIDTable5);
207 priors.setPriors(part_d, PIDTable6);
211 priors2.
setPriors(part_e, counts1, norms);
212 priors2.
setPriors(part_mu, counts2, norms);
213 priors2.
setPriors(part_pi, counts3, norms);
214 priors2.
setPriors(part_K, counts4, norms);
215 priors2.
setPriors(part_p, counts5, norms);
216 priors2.
setPriors(part_d, counts6, norms);
218 counts1->Divide(norms);
219 counts2->Divide(norms);
220 counts3->Divide(norms);
221 counts4->Divide(norms);
222 counts5->Divide(norms);
223 counts6->Divide(norms);
225 std::cout <<
"division done" << std::endl;
227 std::cout <<
"setting the TH2 " << std::endl;
237 std::vector<Const::ChargedStable> codes = {part_e, part_mu, part_pi, part_K, part_p, part_d};
238 for (
auto code : codes) {
239 for (
int i = 0; i < 3; i++) {
240 double p =
rn->Uniform(0., 10);
241 double c =
rn->Uniform(-1., 1);
242 EXPECT_FLOAT_EQ(priors.getPriorValue(code, p, c), priors2.
getPriorValue(code, p, c));
243 EXPECT_FLOAT_EQ(priors.getPriorValue(code, p, c), priors3.
getPriorValue(code, p, c));
247 EXPECT_FLOAT_EQ(0., priors.getPriorValue(part_pi, 11.1, 0.));
248 EXPECT_FLOAT_EQ(0., priors.getPriorValue(part_pi, -1, 0.5));
249 EXPECT_FLOAT_EQ(0., priors.getPriorValue(part_pi, 0.98, -1.001));
251 EXPECT_FLOAT_EQ(0., priors2.
getPriorValue(part_pi, 11.1, 0.));
252 EXPECT_FLOAT_EQ(0., priors2.
getPriorValue(part_pi, -1, 0.5));
253 EXPECT_FLOAT_EQ(0., priors2.
getPriorValue(part_pi, 0.98, -1.001));
255 EXPECT_FLOAT_EQ(0., priors3.
getPriorValue(part_pi, 11.1, 0.));
256 EXPECT_FLOAT_EQ(0., priors3.
getPriorValue(part_pi, -1, 0.5));
257 EXPECT_FLOAT_EQ(0., priors3.
getPriorValue(part_pi, 0.98, -1.001));
Provides a type-safe way to pass members of the chargedStableSet set.
This class holds the prior distribution for a single particle species.
void printPrior() const
Prints the content of the table and the axes.
void setBinEdges(const std::vector< float > &binEdgesX, const std::vector< float > &binEdgesY)
Sets the bin edges arrays.
float getPriorValue(float x, float y) const
Returns the prior probability for a given value of (x,y).
void setPriorValue(float x, float y, float value)
Sets the prior value for a single bin.
void setPriorsTable(const std::vector< float > &priors)
Sets the priors table from a 2D std::vector.
A database class to hold the prior probability for the particle identification.
void setPriors(const Const::ChargedStable &particle, const PIDPriorsTable &table)
Sets the prior table for a particle species from a PIDPriorsTable object.
float getPriorValue(const Const::ChargedStable &particle, float x, float y) const
Returns the prior probability associated to a particle with defined species and parameters.
TString rn()
Get random string.
Abstract base class for different kinds of events.