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(std::begin(pMinEdges), std::end(pMinEdges));
36 std::set<double> pMaxEdges_set(std::begin(pMaxEdges), std::end(pMaxEdges));
37 std::set<double> pBinEdges;
38 std::set_union(std::begin(pMinEdges_set), std::end(pMinEdges_set),
39 std::begin(pMaxEdges_set), std::end(pMaxEdges_set),
40 std::inserter(pBinEdges, std::begin(pBinEdges)));
44 weightsTable.
m_nPBins = pBinEdges.size() - 1;
47 std::vector<double> pMinEdgesVec(std::begin(pMinEdges_set), std::end(pMinEdges_set));
48 std::vector<double> pMaxEdgesVec(std::begin(pMaxEdges_set), std::end(pMaxEdges_set));
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(std::begin(thetaMinEdges), std::end(thetaMinEdges));
59 std::set<double> thetaMaxEdges_set(std::begin(thetaMaxEdges), std::end(thetaMaxEdges));
60 std::set<double> thetaBinEdges;
61 std::set_union(std::begin(thetaMinEdges_set), std::end(thetaMinEdges_set),
62 std::begin(thetaMaxEdges_set), std::end(thetaMaxEdges_set),
63 std::inserter(thetaBinEdges, std::begin(thetaBinEdges)));
66 std::vector<double> thetaMinEdgesVec(std::begin(thetaMinEdges_set), std::end(thetaMinEdges_set));
67 std::vector<double> thetaMaxEdgesVec(std::begin(thetaMaxEdges_set), std::end(thetaMaxEdges_set));
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(std::begin(pBinIdxs), std::end(pBinIdxs),
77 std::begin(thetaBinIdxs),
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(std::begin(weightsTable->m_pBinEdges),
123 std::end(weightsTable->m_pBinEdges),
125 auto pBinIdx = std::distance(std::begin(weightsTable->m_pBinEdges), pBinUpperEdge_it);
127 auto thetaBinUpperEdge_it = std::lower_bound(std::begin(weightsTable->m_thetaBinEdges),
128 std::end(weightsTable->m_thetaBinEdges),
130 auto thetaBinIdx = std::distance(std::begin(weightsTable->m_thetaBinEdges), 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);