17 auto dummyBinEdges = std::set<double>();
24 auto cut_pdgId = [&](
double pdg) {
return (pdg == hypo.getPDGCode()); };
27 if (*filteredRDF.Count()) {
30 auto pMinEdges = filteredRDF.Take<
double>(
"p_min").GetValue();
31 auto pMaxEdges = filteredRDF.Take<
double>(
"p_max").GetValue();
33 auto pBinIdxs = filteredRDF.Take<
double>(
"p_bin_idx").GetValue();
35 std::set<double> pMinEdges_set(pMinEdges.begin(), pMinEdges.end());
36 std::set<double> pMaxEdges_set(pMaxEdges.begin(), pMaxEdges.end());
37 std::set<double> pBinEdges;
38 std::set_union(pMinEdges_set.begin(), pMinEdges_set.end(),
39 pMaxEdges_set.begin(), pMaxEdges_set.end(),
40 std::inserter(pBinEdges, pBinEdges.begin()));
44 weightsTable.
m_nPBins = pBinEdges.size() - 1;
47 std::vector<double> pMinEdgesVec(pMinEdges_set.begin(), pMinEdges_set.end());
48 std::vector<double> pMaxEdgesVec(pMaxEdges_set.begin(), pMaxEdges_set.end());
49 for (
unsigned int iEdgeIdx(0); iEdgeIdx < pMaxEdgesVec.size() - 1; ++iEdgeIdx) {
50 if (pMaxEdgesVec[iEdgeIdx] != pMinEdgesVec[iEdgeIdx + 1]) {
51 B2FATAL(
"The p bins in the weights table are not contiguous. Please check the input CSV file.");
55 auto thetaMinEdges = filteredRDF.Take<
double>(
"theta_min").GetValue();
56 auto thetaMaxEdges = filteredRDF.Take<
double>(
"theta_max").GetValue();
57 auto thetaBinIdxs = filteredRDF.Take<
double>(
"theta_bin_idx").GetValue();
58 std::set<double> thetaMinEdges_set(thetaMinEdges.begin(), thetaMinEdges.end());
59 std::set<double> thetaMaxEdges_set(thetaMaxEdges.begin(), thetaMaxEdges.end());
60 std::set<double> thetaBinEdges;
61 std::set_union(thetaMinEdges_set.begin(), thetaMinEdges_set.end(),
62 thetaMaxEdges_set.begin(), thetaMaxEdges_set.end(),
63 std::inserter(thetaBinEdges, thetaBinEdges.begin()));
66 std::vector<double> thetaMinEdgesVec(thetaMinEdges_set.begin(), thetaMinEdges_set.end());
67 std::vector<double> thetaMaxEdgesVec(thetaMaxEdges_set.begin(), thetaMaxEdges_set.end());
68 for (
unsigned int iEdge(0); iEdge < thetaMaxEdgesVec.size() - 1; ++iEdge) {
69 if (thetaMaxEdgesVec[iEdge] != thetaMinEdgesVec[iEdge + 1]) {
70 B2FATAL(
"The theta bins in the weights table are not contiguous. Please check the input CSV file.");
75 std::vector<std::tuple<double, double>> pAndThetaIdxs;
76 std::transform(pBinIdxs.begin(), pBinIdxs.end(),
78 std::back_inserter(pAndThetaIdxs), [](
const auto & pIdx,
const auto & thetaIdx) { return std::make_tuple(pIdx, thetaIdx); });
83 for (
const auto& tup : pAndThetaIdxs) {
84 double linBinIdx = (std::get<0>(tup) - 1.0) + (std::get<1>(tup) - 1.0) * weightsTable.
m_nPBins;
92 auto colName =
"ablat_s_" + detName;
93 auto weights = filteredRDF.Take<
double>(colName.c_str()).GetValue();
99 B2WARNING(
"Couldn't find detector weights in input ROOT::RDataFrame for std charged particle hypothesis: " << hypo.getPDGCode());
116 if (weightsTable->m_isEmpty) {
118 return std::numeric_limits<float>::quiet_NaN();
122 auto pBinUpperEdge_it = std::lower_bound(weightsTable->m_pBinEdges.begin(),
123 weightsTable->m_pBinEdges.end(),
125 auto pBinIdx = std::distance(weightsTable->m_pBinEdges.begin(), pBinUpperEdge_it);
127 auto thetaBinUpperEdge_it = std::lower_bound(weightsTable->m_thetaBinEdges.begin(),
128 weightsTable->m_thetaBinEdges.end(),
130 auto thetaBinIdx = std::distance(weightsTable->m_thetaBinEdges.begin(), thetaBinUpperEdge_it);
133 double linBinIdx = (pBinIdx - 1.0) + (thetaBinIdx - 1.0) * weightsTable->m_nPBins;
135 if (!weightsTable->m_linBinIdxsToRowIdxs.count(linBinIdx)) {
138 <<
"p = " << p <<
" [GeV/c], theta = " << theta <<
" [rad].\n"
139 <<
"Bin indexes: (" << pBinIdx <<
", " << thetaBinIdx <<
").\n"
140 <<
"Either input value is outside of bin range for PID detector weights:\n"
141 <<
"p : [" << *weightsTable->m_pBinEdges.begin() <<
", " << *weightsTable->m_pBinEdges.rbegin() <<
"],\n"
142 <<
"theta: [" << *weightsTable->m_thetaBinEdges.begin() <<
", " << *weightsTable->m_thetaBinEdges.rbegin() <<
"]");
143 return std::numeric_limits<float>::quiet_NaN();
146 auto rowIdx = weightsTable->m_linBinIdxsToRowIdxs.at(linBinIdx);