9#include <framework/gearbox/Unit.h>
10#include <analysis/dbobjects/PIDDetectorWeights.h>
18 auto dummyBinEdges = std::set<double>();
25 auto cut_pdgId = [&](
double pdg) {
return (pdg == hypo.getPDGCode()); };
28 if (*filteredRDF.Count()) {
31 auto pMinEdges = filteredRDF.Take<
double>(
"p_min").GetValue();
32 auto pMaxEdges = filteredRDF.Take<
double>(
"p_max").GetValue();
34 auto pBinIdxs = filteredRDF.Take<
double>(
"p_bin_idx").GetValue();
36 std::set<double> pMinEdges_set(std::begin(pMinEdges), std::end(pMinEdges));
37 std::set<double> pMaxEdges_set(std::begin(pMaxEdges), std::end(pMaxEdges));
38 std::set<double> pBinEdges;
39 std::set_union(std::begin(pMinEdges_set), std::end(pMinEdges_set),
40 std::begin(pMaxEdges_set), std::end(pMaxEdges_set),
41 std::inserter(pBinEdges, std::begin(pBinEdges)));
45 weightsTable.
m_nPBins = pBinEdges.size() - 1;
48 std::vector<double> pMinEdgesVec(std::begin(pMinEdges_set), std::end(pMinEdges_set));
49 std::vector<double> pMaxEdgesVec(std::begin(pMaxEdges_set), std::end(pMaxEdges_set));
50 for (
unsigned int iEdgeIdx(0); iEdgeIdx < pMaxEdgesVec.size() - 1; ++iEdgeIdx) {
51 if (pMaxEdgesVec[iEdgeIdx] != pMinEdgesVec[iEdgeIdx + 1]) {
52 B2FATAL(
"The p bins in the weights table are not contiguous. Please check the input CSV file.");
56 auto thetaMinEdges = filteredRDF.Take<
double>(
"theta_min").GetValue();
57 auto thetaMaxEdges = filteredRDF.Take<
double>(
"theta_max").GetValue();
58 auto thetaBinIdxs = filteredRDF.Take<
double>(
"theta_bin_idx").GetValue();
59 std::set<double> thetaMinEdges_set(std::begin(thetaMinEdges), std::end(thetaMinEdges));
60 std::set<double> thetaMaxEdges_set(std::begin(thetaMaxEdges), std::end(thetaMaxEdges));
61 std::set<double> thetaBinEdges;
62 std::set_union(std::begin(thetaMinEdges_set), std::end(thetaMinEdges_set),
63 std::begin(thetaMaxEdges_set), std::end(thetaMaxEdges_set),
64 std::inserter(thetaBinEdges, std::begin(thetaBinEdges)));
67 std::vector<double> thetaMinEdgesVec(std::begin(thetaMinEdges_set), std::end(thetaMinEdges_set));
68 std::vector<double> thetaMaxEdgesVec(std::begin(thetaMaxEdges_set), std::end(thetaMaxEdges_set));
69 for (
unsigned int iEdge(0); iEdge < thetaMaxEdgesVec.size() - 1; ++iEdge) {
70 if (thetaMaxEdgesVec[iEdge] != thetaMinEdgesVec[iEdge + 1]) {
71 B2FATAL(
"The theta bins in the weights table are not contiguous. Please check the input CSV file.");
76 std::vector<std::tuple<double, double>> pAndThetaIdxs;
77 std::transform(std::begin(pBinIdxs), std::end(pBinIdxs),
78 std::begin(thetaBinIdxs),
79 std::back_inserter(pAndThetaIdxs), [](
const auto & pIdx,
const auto & thetaIdx) {
return std::make_tuple(pIdx, thetaIdx); });
84 for (
const auto& tup : pAndThetaIdxs) {
85 double linBinIdx = (std::get<0>(tup) - 1.0) + (std::get<1>(tup) - 1.0) * weightsTable.
m_nPBins;
93 auto colName =
"ablat_s_" + detName;
94 auto weights = filteredRDF.Take<
double>(colName.c_str()).GetValue();
100 B2WARNING(
"Couldn't find detector weights in input ROOT::RDataFrame for std charged particle hypothesis: " << hypo.getPDGCode());
117 if (weightsTable->m_isEmpty) {
119 return std::numeric_limits<float>::quiet_NaN();
123 auto pBinUpperEdge_it = std::lower_bound(std::begin(weightsTable->m_pBinEdges),
124 std::end(weightsTable->m_pBinEdges),
126 auto pBinIdx = std::distance(std::begin(weightsTable->m_pBinEdges), pBinUpperEdge_it);
128 auto thetaBinUpperEdge_it = std::lower_bound(std::begin(weightsTable->m_thetaBinEdges),
129 std::end(weightsTable->m_thetaBinEdges),
131 auto thetaBinIdx = std::distance(std::begin(weightsTable->m_thetaBinEdges), thetaBinUpperEdge_it);
134 double linBinIdx = (pBinIdx - 1.0) + (thetaBinIdx - 1.0) * weightsTable->m_nPBins;
136 if (!weightsTable->m_linBinIdxsToRowIdxs.count(linBinIdx)) {
139 <<
"p = " << p <<
" [GeV/c], theta = " << theta <<
" [rad].\n"
140 <<
"Bin indexes: (" << pBinIdx <<
", " << thetaBinIdx <<
").\n"
141 <<
"Either input value is outside of bin range for PID detector weights:\n"
142 <<
"p : [" << *weightsTable->m_pBinEdges.begin() <<
", " << *weightsTable->m_pBinEdges.rbegin() <<
"],\n"
143 <<
"theta: [" << *weightsTable->m_thetaBinEdges.begin() <<
", " << *weightsTable->m_thetaBinEdges.rbegin() <<
"]");
144 return std::numeric_limits<float>::quiet_NaN();
147 auto rowIdx = weightsTable->m_linBinIdxsToRowIdxs.at(linBinIdx);
Provides a type-safe way to pass members of the chargedStableSet set.
int getPDGCode() const
PDG code.
static DetectorSet set()
Accessor for the set of valid detector IDs.
static const ParticleSet chargedStableSet
set of charged stable particles
EDetector
Enum for identifying the detector components (detector and subdetector).
static std::string parseDetectors(EDetector det)
Converts Const::EDetector object to string.
Nested class acting as a container the per-detector weights.
int m_nPBins
Number of p bins.
int m_nThetaBins
Number of theta bins.
std::unordered_map< double, unsigned int > m_linBinIdxsToRowIdxs
Map the linearised index of the (p, theta) bin indexes to the row index in the (filtered) table.
std::map< std::string, std::vector< double > > m_weightsPerDet
Map each detector to its vector of weights.
bool m_isEmpty
Default constructor.
std::set< double > m_pBinEdges
Set of p bins edges.
std::set< double > m_thetaBinEdges
Set of theta bins edges.
void fillWeightsTablePerHypoFromRDF()
Fill the internal weights container class per particle hypo, based on the content of the RDataFrame.
ROOT::RDataFrame m_weightsRDataFrame
The RDataFrame containing the detector weights per particle hypo, per phase space bin.
double getWeight(Const::ChargedStable hypo, Const::EDetector det, double p, double theta) const
Lookup the weight from the internal map structures.
std::map< int, WeightsTable > m_weightsTablePerHypo
Map containing a WeightsTable object per particle hypo.
Abstract base class for different kinds of events.