8#include <framework/gearbox/Const.h>
9#include <framework/gearbox/Unit.h>
10#include <framework/datastore/StoreArray.h>
12#include <ecl/dataobjects/ECLPidLikelihood.h>
13#include <ecl/dbobjects/ECLChargedPidPDFs.h>
16#include <gtest/gtest.h>
70 EXPECT_FLOAT_EQ(lk->getLogLikelihood(
Const::muon), 0.58);
71 EXPECT_FLOAT_EQ(lk->getLogLikelihood(
Const::pion), 0.28);
72 EXPECT_FLOAT_EQ(lk->getLogLikelihood(
Const::kaon), 0.38);
83 float pmin_vals[] = {0.2, 0.6, 1.0, 100.0};
84 float thetamin_vals[] = {0.21, 0.56, 2.24, 2.70};
86 TH2F histgrid(
"binsgrid",
88 sizeof(thetamin_vals) /
sizeof(
float) - 1,
90 sizeof(pmin_vals) /
sizeof(
float) - 1,
101 typedef std::pair<int, TF1> pdfSet;
103 pdfSet pdf_el = std::make_pair(-1, TF1(
"pdf_el",
"TMath::Gaus(x, 1.0, 0.2, true)", 0.0, 1.3));
104 pdfSet pdf_elanti = std::make_pair(1, TF1(
"pdf_elanti",
"TMath::Gaus(x, 0.9, 0.2, true)", 0.0, 1.2));
106 pdfSet pdf_mu = std::make_pair(-1, TF1(
"pdf_mu",
"TMath::Gaus(x, 0.3, 0.2, true)", 0.0, 1.0));
107 pdfSet pdf_muanti = std::make_pair(1, TF1(
"pdf_muanti",
"TMath::Gaus(x, 0.35, 0.22, true)", 0.0, 1.0));
109 pdfSet pdf_pi = std::make_pair(1, TF1(
"pdf_pi",
"TMath::Gaus(x, 0.4, 0.1, true)", 0.0, 1.0));
110 pdfSet pdf_pianti = std::make_pair(-1, TF1(
"pdf_pianti",
"TMath::Gaus(x, 0.38, 0.15, true)", 0.0, 1.0));
112 pdfSet pdf_k = std::make_pair(1, TF1(
"pdf_k",
"TMath::Gaus(x, 0.38, 0.2, true)", 0.0, 1.0));
113 pdfSet pdf_kanti = std::make_pair(-1, TF1(
"pdf_kanti",
"TMath::Gaus(x, 0.5, 0.22, true)", 0.0, 1.0));
115 pdfSet pdf_p = std::make_pair(1, TF1(
"pdf_p",
"TMath::Gaus(x, 1.0, 0.4, true)", 0.0, 1.6));
116 pdfSet pdf_panti = std::make_pair(-1, TF1(
"pdf_panti",
"TMath::Gaus(x, 1.3, 0.5, true)", 0.0, 2.0));
118 pdfSet pdf_d = std::make_pair(1, TF1(
"pdf_d",
"TMath::Gaus(x, 1.1, 0.45, true)", 0.0, 1.6));
119 pdfSet pdf_danti = std::make_pair(-1, TF1(
"pdf_danti",
"TMath::Gaus(x, 1.2, 0.6, true)", 0.0, 2.0));
121 std::map<unsigned int, std::vector<pdfSet>> pdfs = {
135 for (
auto& [pdg, pdf_setlist] : pdfs) {
136 for (
auto& pdf_set : pdf_setlist) {
137 for (
int ip(1); ip <= histgrid.GetNbinsY(); ++ip) {
138 for (
int jth(1); jth <= histgrid.GetNbinsX(); ++jth) {
139 for (
const auto& varid : varids) {
140 eclPdfs.
add(pdg, pdf_set.first, ip, jth, varid, &pdf_set.second);
152 double clusterTheta = 1.047;
157 for (
const auto& [pdg, pdf_setlist] : pdfs) {
158 for (
const auto& pdf_set : pdf_setlist) {
159 float pdfval = eclPdfs.
getPdf(pdg, pdf_set.first, p, clusterTheta, varids.at(0))->Eval(eop);
160 EXPECT_NEAR(pdf_set.second.Eval(eop), pdfval, 0.001);
161 if (pdf_set.first < 0) {
171 const auto* lk_minus = ecl_likelihoods_minus.
appendNew(likelihoods_minus);
173 const auto* lk_plus = ecl_likelihoods_plus.
appendNew(likelihoods_plus);
175 for (
const auto& [pdg, pdf_setlist] : pdfs) {
176 for (
const auto& pdf_set : pdf_setlist) {
178 float logl_expect = log(pdf_set.second.Eval(eop));
179 if (pdf_set.first < 0) {
184 EXPECT_NEAR(logl_expect, logl, 0.01);
static const unsigned int c_SetSize
Number of elements (for use in array bounds etc.)
const ParticleType & find(int pdg) const
Returns particle in set with given PDG code, or invalidParticle if not found.
int getPDGCode() const
PDG code.
int getIndex() const
This particle's index in the associated set.
static const ChargedStable muon
muon particle
static const ParticleSet chargedStableSet
set of charged stable particles
static const ChargedStable pion
charged pion particle
static const ChargedStable proton
proton particle
static const ChargedStable kaon
charged kaon particle
static const ChargedStable electron
electron particle
static const ChargedStable deuteron
deuteron particle
static DataStore & Instance()
Instance of singleton Store.
void setInitializeActive(bool active)
Setter for m_initializeActive.
void reset(EDurability durability)
Frees memory occupied by data store items and removes all objects from the map.
Test the ECL charged PID.
virtual void TearDown()
Clear datastore.
virtual void SetUp()
Set up a few arrays and objects in the datastore.
Class representing the DB payload w/ information about ECL PDF parameters for a set of particle hypot...
void add(const unsigned int pdg, const int true_charge, const unsigned int i, const unsigned int j, const InputVar varid, TF1 *pdf)
Fills the internal maps for a given hypothesis and category (clusterTheta, p).
void setPdfCategories(TH2F *h)
Set the 2D (clusterTheta, p) grid representing the categories for which PDFs are defined.
const TF1 * getPdf(const unsigned int pdg, const int charge, const double &p, const double &theta, const InputVar varid) const
Return the PDF of this observable for this candidate's reconstructed (p, clusterTheta),...
void setAngularUnit(const double &unit)
Set the angular unit to be consistent w/ the one used in the fit.
void setEnergyUnit(const double &unit)
Set the energy unit to be consistent w/ the one used in the fit.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
Accessor to arrays stored in the data store.
T * appendNew()
Construct a new T object at the end of the array.
static const double rad
Standard of [angle].
static const double GeV
Standard of [energy, momentum, mass].
Abstract base class for different kinds of events.