9#include <framework/logging/Logger.h>
10#include <framework/gearbox/Const.h>
12#include <analysis/dbobjects/ChargedPidMVAWeights.h>
14#include <gtest/gtest.h>
41 std::vector<double>
m_thetabins = {0.2164208, 0.5480334, 0.561996, 2.2462387, 2.2811453, 2.7070057};
46 std::vector<double>
m_pbins = {0.2, 0.6, 0.75, 1.0, 3.0, 7.0};
51 std::vector<double>
m_chbins = { -1.5, -0.5, 0.5, 1.5};
77 std::vector<std::tuple<double, double, double>> gridBinCentres;
79 for (
unsigned int kch(0); kch <
m_chbins.size() - 1; kch++) {
81 for (
unsigned int ip(0); ip <
m_pbins.size() - 1; ip++) {
83 for (
unsigned int jth(0); jth <
m_thetabins.size() - 1; jth++) {
87 +
"__p__" + std::to_string(
m_pbins.at(ip)) +
"_" + std::to_string(
m_pbins.at(ip + 1))
88 +
"__charge__" + std::to_string(ch_bin_centre);
90 std::replace(fname.begin(), fname.end(),
'.',
'_');
92 std::ofstream dummyfile(fname);
96 auto centre = std::make_tuple(th_bin_centre, p_bin_centre, ch_bin_centre);
97 gridBinCentres.push_back(centre);
113 if (remove(fname.c_str())) {
114 B2ERROR(
"Couldn't remove file: " << fname);
131 std::random_device rd;
132 std::uniform_int_distribution<int> binx_idx_distr(1, m_thetabins.size() - 1);
133 std::uniform_int_distribution<int> biny_idx_distr(1, m_pbins.size() - 1);
134 std::uniform_int_distribution<int> binz_idx_distr(1, m_chbins.size() - 1);
135 int binx = binx_idx_distr(rd);
136 int biny = biny_idx_distr(rd);
137 int binz = binz_idx_distr(rd);
140 auto theta = m_dbrep.getWeightCategories()->GetXaxis()->GetBinCenter(binx);
141 auto p = m_dbrep.getWeightCategories()->GetYaxis()->GetBinCenter(biny);
142 auto charge = m_dbrep.getWeightCategories()->GetZaxis()->GetBinCenter(binz);
145 auto jik = m_dbrep.getMVAWeightIdx(theta, p, charge, jth, ip, kch);
147 EXPECT_EQ(jth, binx);
149 EXPECT_EQ(kch, binz);
151 auto thisfname = m_basename
152 +
"__clusterTheta__" + std::to_string(m_thetabins.at(jth - 1)) +
"_" + std::to_string(m_thetabins.at(jth))
153 +
"__p__" + std::to_string(m_pbins.at(ip - 1)) +
"_" + std::to_string(m_pbins.at(ip))
154 +
"__charge__" + std::to_string(charge);
155 std::replace(thisfname.begin(), thisfname.end(),
'.',
'_');
158 EXPECT_EQ(thisfname, m_dummyfiles.at(jik));
160 auto matchitr = std::find(m_dummyfiles.begin(), m_dummyfiles.end(), thisfname);
161 auto thisidx = std::distance(m_dummyfiles.begin(), matchitr);
163 EXPECT_EQ(thisidx, jik);
Test the MVA-based charged PID.
Const::ChargedStable m_testHypo
The signal charged particle hypothesis to test.
std::vector< double > m_chbins
The charge bin edges.
void SetUp() override
Prepare resources for the tests.
std::vector< double > m_pbins
The p bin edges in [GeV/c].
std::string m_basename
Base common name for all dummy weight files.
ChargedPidMVAWeights m_dbrep
Database representation of MVA weightfiles.
void TearDown() override
Release all resources.
std::vector< double > m_thetabins
The clusterTheta bin edges in [rad].
std::vector< std::string > m_dummyfiles
List of dummy xml file names.
Class to contain the payload of MVA weightfiles needed for charged particle identification.
void setWeightCategories(const double *clusterThetaBins, const int nClusterThetaBins, const double *pBins, const int nPBins, const double *chargeBins, const int nChargeBins)
Set the 3D (clusterTheta, p, charge) grid representing the categories for which weightfiles are defin...
void storeMVAWeights(const int pdg, const std::vector< std::string > &filepaths, const std::vector< std::tuple< double, double, double > > &categoryBinCentres)
Given a particle mass hypothesis' pdgId, store the list of MVA weight files (one for each category) i...
Provides a type-safe way to pass members of the chargedStableSet set.
int getPDGCode() const
PDG code.
static const ChargedStable electron
electron particle
Abstract base class for different kinds of events.