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>
49 std::vector<float>
m_thetabins = {0.2164208, 0.5480334, 0.561996, 2.2462387, 2.2811453, 2.7070057};
54 std::vector<float>
m_pbins = {0.2, 0.6, 0.75, 1.0, 3.0, 7.0};
59 std::vector<float>
m_chbins = { -1.5, -0.5, 0.5, 1.5};
81 m_grid = std::make_unique<TH3F>(
"theta_p_charge_binsgrid",
82 ";ECL cluster #theta;p_{lab}; Q",
92 std::vector<std::tuple<double, double, double>> gridBinCentres;
94 for (
unsigned int kch(0); kch <
m_chbins.size() - 1; kch++) {
96 for (
unsigned int ip(0); ip <
m_pbins.size() - 1; ip++) {
98 for (
unsigned int jth(0); jth <
m_thetabins.size() - 1; jth++) {
101 +
"__clusterTheta__" + std::to_string(
m_thetabins.at(jth)) +
"_" + std::to_string(
m_thetabins.at(jth + 1))
102 +
"__p__" + std::to_string(
m_pbins.at(ip)) +
"_" + std::to_string(
m_pbins.at(ip + 1))
103 +
"__charge__" + std::to_string(ch_bin_centre);
105 std::replace(fname.begin(), fname.end(),
'.',
'_');
107 std::ofstream dummyfile(fname);
111 auto centre = std::make_tuple(th_bin_centre, p_bin_centre, ch_bin_centre);
112 gridBinCentres.push_back(centre);
128 if (remove(fname.c_str())) {
129 B2ERROR(
"Couldn't remove file: " << fname);
146 std::random_device rd;
147 std::uniform_int_distribution<int> binx_idx_distr(1, m_thetabins.size() - 1);
148 std::uniform_int_distribution<int> biny_idx_distr(1, m_pbins.size() - 1);
149 std::uniform_int_distribution<int> binz_idx_distr(1, m_chbins.size() - 1);
150 int binx = binx_idx_distr(rd);
151 int biny = biny_idx_distr(rd);
152 int binz = binz_idx_distr(rd);
155 auto theta = m_grid->GetXaxis()->GetBinCenter(binx);
156 auto p = m_grid->GetYaxis()->GetBinCenter(biny);
157 auto charge = m_grid->GetZaxis()->GetBinCenter(binz);
160 auto jik = m_dbrep.getMVAWeightIdx(theta, p, charge, jth, ip, kch);
162 EXPECT_EQ(jth, binx);
164 EXPECT_EQ(kch, binz);
166 auto thisfname = m_basename
167 +
"__clusterTheta__" + std::to_string(m_thetabins.at(jth - 1)) +
"_" + std::to_string(m_thetabins.at(jth))
168 +
"__p__" + std::to_string(m_pbins.at(ip - 1)) +
"_" + std::to_string(m_pbins.at(ip))
169 +
"__charge__" + std::to_string(charge);
170 std::replace(thisfname.begin(), thisfname.end(),
'.',
'_');
173 EXPECT_EQ(thisfname, m_dummyfiles.at(jik));
175 auto matchitr = std::find(m_dummyfiles.begin(), m_dummyfiles.end(), thisfname);
176 auto thisidx = std::distance(m_dummyfiles.begin(), matchitr);
178 EXPECT_EQ(thisidx, jik);
Test the MVA-based charged PID.
Const::ChargedStable m_testHypo
The signal charged particle hypothesis to test.
void SetUp() override
Prepare resources for the tests.
std::vector< float > m_thetabins
The clusterTheta bin edges in [rad].
std::vector< float > m_pbins
The p bin edges in [GeV/c].
std::string m_basename
Base common name for all dummy weight files.
std::unique_ptr< TH3F > m_grid
The (clusterTheta, p, charge) grid for which xml files are stored in the payload.
ChargedPidMVAWeights m_dbrep
Database representation of MVA weightfiles.
void TearDown() override
Release all resources.
std::vector< float > m_chbins
The charge bin edges.
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(TH3F *h)
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
TEST_F(GlobalLabelTest, LargeNumberOfTimeDependentParameters)
Test large number of time-dep params for registration and retrieval.
Abstract base class for different kinds of events.