19 auto dummyBinEdges = std::set<double>();
26 auto cut_pdgId = [&](
double pdg) {
return (pdg == hypo.getPDGCode()); };
29 if (*filteredRDF.Count()) {
32 auto pMinEdges = filteredRDF.Take<
double>(
"p_min").GetValue();
33 auto pMaxEdges = filteredRDF.Take<
double>(
"p_max").GetValue();
35 auto pBinIdxs = filteredRDF.Take<
double>(
"p_bin_idx").GetValue();
37 std::set<double> pMinEdges_set(pMinEdges.begin(), pMinEdges.end());
38 std::set<double> pMaxEdges_set(pMaxEdges.begin(), pMaxEdges.end());
39 std::set<double> pBinEdges;
40 std::set_union(pMinEdges_set.begin(), pMinEdges_set.end(),
41 pMaxEdges_set.begin(), pMaxEdges_set.end(),
42 std::inserter(pBinEdges, pBinEdges.begin()));
46 weightsTable.
m_nPBins = pBinEdges.size() - 1;
49 std::vector<double> pMinEdgesVec(pMinEdges_set.begin(), pMinEdges_set.end());
50 std::vector<double> pMaxEdgesVec(pMaxEdges_set.begin(), pMaxEdges_set.end());
51 for (
unsigned int iEdgeIdx(0); iEdgeIdx < pMaxEdgesVec.size() - 1; ++iEdgeIdx) {
52 if (pMaxEdgesVec[iEdgeIdx] != pMinEdgesVec[iEdgeIdx + 1]) {
53 B2FATAL(
"The p bins in the weights table are not contiguous. Please check the input CSV file.");
57 auto thetaMinEdges = filteredRDF.Take<
double>(
"theta_min").GetValue();
58 auto thetaMaxEdges = filteredRDF.Take<
double>(
"theta_max").GetValue();
59 auto thetaBinIdxs = filteredRDF.Take<
double>(
"theta_bin_idx").GetValue();
60 std::set<double> thetaMinEdges_set(thetaMinEdges.begin(), thetaMinEdges.end());
61 std::set<double> thetaMaxEdges_set(thetaMaxEdges.begin(), thetaMaxEdges.end());
62 std::set<double> thetaBinEdges;
63 std::set_union(thetaMinEdges_set.begin(), thetaMinEdges_set.end(),
64 thetaMaxEdges_set.begin(), thetaMaxEdges_set.end(),
65 std::inserter(thetaBinEdges, thetaBinEdges.begin()));
68 std::vector<double> thetaMinEdgesVec(thetaMinEdges_set.begin(), thetaMinEdges_set.end());
69 std::vector<double> thetaMaxEdgesVec(thetaMaxEdges_set.begin(), thetaMaxEdges_set.end());
70 for (
unsigned int iEdge(0); iEdge < thetaMaxEdgesVec.size() - 1; ++iEdge) {
71 if (thetaMaxEdgesVec[iEdge] != thetaMinEdgesVec[iEdge + 1]) {
72 B2FATAL(
"The theta bins in the weights table are not contiguous. Please check the input CSV file.");
77 std::vector<std::tuple<double, double>> pAndThetaIdxs;
78 std::transform(pBinIdxs.begin(), pBinIdxs.end(),
80 std::back_inserter(pAndThetaIdxs), [](
const auto & pIdx,
const auto & thetaIdx) { return std::make_tuple(pIdx, thetaIdx); });
85 for (
const auto& tup : pAndThetaIdxs) {
86 double linBinIdx = (std::get<0>(tup) - 1.0) + (std::get<1>(tup) - 1.0) * weightsTable.
m_nPBins;
94 auto colName =
"ablat_s_" + detName;
95 auto weights = filteredRDF.Take<
double>(colName.c_str()).GetValue();
101 B2WARNING(
"Couldn't find detector weights in input ROOT::RDataFrame for std charged particle hypothesis: " << hypo.getPDGCode());
118 if (weightsTable->m_isEmpty) {
120 return std::numeric_limits<float>::quiet_NaN();
124 auto pBinUpperEdge_it = std::lower_bound(weightsTable->m_pBinEdges.begin(),
125 weightsTable->m_pBinEdges.end(),
127 auto pBinIdx = std::distance(weightsTable->m_pBinEdges.begin(), pBinUpperEdge_it);
129 auto thetaBinUpperEdge_it = std::lower_bound(weightsTable->m_thetaBinEdges.begin(),
130 weightsTable->m_thetaBinEdges.end(),
132 auto thetaBinIdx = std::distance(weightsTable->m_thetaBinEdges.begin(), thetaBinUpperEdge_it);
135 double linBinIdx = (pBinIdx - 1.0) + (thetaBinIdx - 1.0) * weightsTable->m_nPBins;
137 if (!weightsTable->m_linBinIdxsToRowIdxs.count(linBinIdx)) {
140 <<
"p = " << p <<
" [GeV/c], theta = " << theta <<
" [rad].\n"
141 <<
"Bin indexes: (" << pBinIdx <<
", " << thetaBinIdx <<
").\n"
142 <<
"Either input value is outside of bin range for PID detector weights:\n"
143 <<
"p : [" << *weightsTable->m_pBinEdges.begin() <<
", " << *weightsTable->m_pBinEdges.rbegin() <<
"],\n"
144 <<
"theta: [" << *weightsTable->m_thetaBinEdges.begin() <<
", " << *weightsTable->m_thetaBinEdges.rbegin() <<
"]");
145 return std::numeric_limits<float>::quiet_NaN();
148 auto rowIdx = weightsTable->m_linBinIdxsToRowIdxs.at(linBinIdx);