9#include <framework/logging/Logger.h>
10#include <framework/gearbox/Const.h>
11#include <framework/gearbox/Unit.h>
13#include <analysis/dbobjects/ChargedPidMVAWeights.h>
15#include <gtest/gtest.h>
44 std::vector<double>
m_thetabins = {0.2164208, 0.5480334, 0.561996, 2.2462387, 2.2811453, 2.7070057};
49 std::vector<double>
m_pbins = {0.2, 0.6, 0.75, 1.0, 3.0, 7.0};
54 std::vector<double>
m_chbins = { -1.5, -0.5, 0.5, 1.5};
80 std::vector<std::tuple<double, double, double>> gridBinCentres;
82 for (
unsigned int kch(0); kch <
m_chbins.size() - 1; kch++) {
84 for (
unsigned int ip(0); ip <
m_pbins.size() - 1; ip++) {
86 for (
unsigned int jth(0); jth <
m_thetabins.size() - 1; jth++) {
90 +
"__p__" + std::to_string(
m_pbins.at(ip)) +
"_" + std::to_string(
m_pbins.at(ip + 1))
91 +
"__charge__" + std::to_string(ch_bin_centre);
93 std::replace(fname.begin(), fname.end(),
'.',
'_');
95 std::ofstream dummyfile(fname);
99 auto centre = std::make_tuple(th_bin_centre, p_bin_centre, ch_bin_centre);
100 gridBinCentres.push_back(centre);
116 if (remove(fname.c_str())) {
117 B2ERROR(
"Couldn't remove file: " << fname);
134 std::random_device rd;
135 std::uniform_int_distribution<int> binx_idx_distr(1, m_thetabins.size() - 1);
136 std::uniform_int_distribution<int> biny_idx_distr(1, m_pbins.size() - 1);
137 std::uniform_int_distribution<int> binz_idx_distr(1, m_chbins.size() - 1);
138 int binx = binx_idx_distr(rd);
139 int biny = biny_idx_distr(rd);
140 int binz = binz_idx_distr(rd);
143 auto theta = m_dbrep.getWeightCategories()->GetXaxis()->GetBinCenter(binx);
144 auto p = m_dbrep.getWeightCategories()->GetYaxis()->GetBinCenter(biny);
145 auto charge = m_dbrep.getWeightCategories()->GetZaxis()->GetBinCenter(binz);
148 auto jik = m_dbrep.getMVAWeightIdx(theta, p, charge, jth, ip, kch);
150 EXPECT_EQ(jth, binx);
152 EXPECT_EQ(kch, binz);
154 auto thisfname = m_basename
155 +
"__clusterTheta__" + std::to_string(m_thetabins.at(jth - 1)) +
"_" + std::to_string(m_thetabins.at(jth))
156 +
"__p__" + std::to_string(m_pbins.at(ip - 1)) +
"_" + std::to_string(m_pbins.at(ip))
157 +
"__charge__" + std::to_string(charge);
158 std::replace(thisfname.begin(), thisfname.end(),
'.',
'_');
161 EXPECT_EQ(thisfname, m_dummyfiles.at(jik));
163 auto matchitr = std::find(m_dummyfiles.begin(), m_dummyfiles.end(), thisfname);
164 auto thisidx = std::distance(m_dummyfiles.begin(), matchitr);
166 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.