9#include <mva/utility/Binning.h>
10#include <framework/utilities/FileSystem.h>
11#include <framework/utilities/TestHelpers.h>
13#include <gtest/gtest.h>
23 EXPECT_EQ(binning.m_signal_pdf.size(), 3);
24 EXPECT_EQ(binning.m_signal_cdf.size(), 3);
25 EXPECT_EQ(binning.m_bckgrd_pdf.size(), 3);
26 EXPECT_EQ(binning.m_bckgrd_cdf.size(), 3);
27 EXPECT_EQ(binning.m_boundaries.size(), 4);
29 EXPECT_FLOAT_EQ(binning.m_signal_yield, 0.0);
30 EXPECT_FLOAT_EQ(binning.m_bckgrd_yield, 0.0);
32 binning.m_signal_pdf[0] = 1.0;
33 binning.m_signal_pdf[1] = 2.0;
34 binning.m_signal_pdf[2] = 3.0;
36 binning.m_bckgrd_pdf[0] = 3.0;
37 binning.m_bckgrd_pdf[1] = 2.0;
38 binning.m_bckgrd_pdf[2] = 1.0;
40 binning.m_boundaries = {1.0, 2.0, 3.0, 4.0};
42 binning.normalizePDFs();
44 EXPECT_FLOAT_EQ(binning.m_signal_pdf[0], 1.0 / 6.0 * 3.0);
45 EXPECT_FLOAT_EQ(binning.m_signal_pdf[1], 2.0 / 6.0 * 3.0);
46 EXPECT_FLOAT_EQ(binning.m_signal_pdf[2], 3.0 / 6.0 * 3.0);
48 EXPECT_FLOAT_EQ(binning.m_bckgrd_pdf[0], 3.0 / 6.0 * 3.0);
49 EXPECT_FLOAT_EQ(binning.m_bckgrd_pdf[1], 2.0 / 6.0 * 3.0);
50 EXPECT_FLOAT_EQ(binning.m_bckgrd_pdf[2], 1.0 / 6.0 * 3.0);
52 EXPECT_FLOAT_EQ(binning.m_signal_yield, 6.0);
53 EXPECT_FLOAT_EQ(binning.m_bckgrd_yield, 6.0);
55 binning.calculateCDFsFromPDFs();
57 EXPECT_FLOAT_EQ(binning.m_signal_pdf[0], 1.0 / 6.0 * 3.0);
58 EXPECT_FLOAT_EQ(binning.m_signal_pdf[1], 2.0 / 6.0 * 3.0);
59 EXPECT_FLOAT_EQ(binning.m_signal_pdf[2], 3.0 / 6.0 * 3.0);
61 EXPECT_FLOAT_EQ(binning.m_bckgrd_pdf[0], 3.0 / 6.0 * 3.0);
62 EXPECT_FLOAT_EQ(binning.m_bckgrd_pdf[1], 2.0 / 6.0 * 3.0);
63 EXPECT_FLOAT_EQ(binning.m_bckgrd_pdf[2], 1.0 / 6.0 * 3.0);
65 EXPECT_FLOAT_EQ(binning.m_signal_yield, 6.0);
66 EXPECT_FLOAT_EQ(binning.m_bckgrd_yield, 6.0);
68 EXPECT_FLOAT_EQ(binning.m_signal_cdf[0], 1.0 / 6.0);
69 EXPECT_FLOAT_EQ(binning.m_signal_cdf[1], 3.0 / 6.0);
71 EXPECT_FLOAT_EQ(binning.m_signal_cdf[2], 6.0 / 6.0);
73 EXPECT_FLOAT_EQ(binning.m_bckgrd_cdf[0], 3.0 / 6.0);
74 EXPECT_FLOAT_EQ(binning.m_bckgrd_cdf[1], 5.0 / 6.0);
76 EXPECT_FLOAT_EQ(binning.m_bckgrd_cdf[2], 6.0 / 6.0);
78 binning.m_boundaries[0] = 1.0;
79 binning.m_boundaries[1] = 2.0;
80 binning.m_boundaries[2] = 3.0;
81 binning.m_boundaries[3] = 4.0;
83 EXPECT_EQ(binning.getBin(0.0), 0);
84 EXPECT_EQ(binning.getBin(1.0), 0);
85 EXPECT_EQ(binning.getBin(1.5), 0);
86 EXPECT_EQ(binning.getBin(2.0), 1);
87 EXPECT_EQ(binning.getBin(2.5), 1);
88 EXPECT_EQ(binning.getBin(3.0), 2);
89 EXPECT_EQ(binning.getBin(3.5), 2);
90 EXPECT_EQ(binning.getBin(4.5), 2);
94 TEST(BinningTest, EqualFrequencyBinning)
96 std::vector<float> data(100);
97 std::vector<float> weights(100);
98 std::vector<bool> isSignal(100);
100 for (
unsigned int i = 0; i < 100; ++i) {
102 weights[i] =
static_cast<int>(i / 10) + 1;
103 isSignal[i] = (i % 2) == 1;
106 MVA::Binning binning = MVA::Binning::CreateEqualFrequency(data, weights, isSignal, 3);
136 TEST(BinningTest, EquidistantBinning)
138 std::vector<float> data(100);
139 std::vector<float> weights(100);
140 std::vector<bool> isSignal(100);
142 for (
unsigned int i = 0; i < 100; ++i) {
144 weights[i] =
static_cast<int>(i / 10) + 1;
145 isSignal[i] = (i % 2) == 1;
148 MVA::Binning binning = MVA::Binning::CreateEquidistant(data, weights, isSignal, 3);
Binning of a data distribution Provides PDF and CDF values of the distribution per bin.
std::vector< float > m_bckgrd_pdf
Background pdf of data distribution per bin.
std::vector< float > m_signal_pdf
Signal pdf of data distribution per bin.
std::vector< float > m_boundaries
Boundaries of data distribution, including minimum and maximum value as first and last boundary.
std::vector< float > m_bckgrd_cdf
Background cdf of data distribution per bin.
double m_bckgrd_yield
Background yield in data distribution.
double m_signal_yield
Signal yield in data distribution.
std::vector< float > m_signal_cdf
Signal cdf of data distribution per bin.
std::vector< std::pair< double, double > > Binning
Bin holder as vector for bin limit pairs: [energy limits, theta limits, phi limits].
Abstract base class for different kinds of events.