45std::map<RooFit::Detail::DataKey, RooSpan<const double>>
47 std::string
const &prefix, std::stack<std::vector<double>> &buffers,
50 std::map<RooFit::Detail::DataKey, RooSpan<const double>> dataSpans;
55 const TNamed *namePtr = nameReg.constPtr((prefix + key).c_str());
56 dataSpans[namePtr] = span;
59 auto retrieve = [&](
const char *key) {
60 const TNamed *namePtr = nameReg.constPtr((prefix + key).c_str());
61 return dataSpans.at(namePtr);
64 std::size_t nEvents =
static_cast<size_t>(
data.numEntries());
72 auto weight =
data.getWeightBatch(0, nEvents,
false);
73 auto weightSumW2 =
data.getWeightBatch(0, nEvents,
true);
75 std::vector<bool> hasZeroWeight;
76 hasZeroWeight.resize(nEvents);
77 std::size_t nNonZeroWeight = 0;
84 auto &buffer = buffers.top();
86 auto &bufferSumW2 = buffers.top();
91 buffer.push_back(1.0);
92 bufferSumW2.push_back(1.0);
95 nNonZeroWeight = nEvents;
97 buffer.reserve(nEvents);
98 bufferSumW2.reserve(nEvents);
99 for (std::size_t i = 0; i < nEvents; ++i) {
100 if (!skipZeroWeights || weight[i] != 0) {
101 buffer.push_back(weight[i]);
102 bufferSumW2.push_back(weightSumW2[i]);
105 hasZeroWeight[i] =
true;
112 insert(RooNLLVarNew::weightVarName, weight);
113 insert(RooNLLVarNew::weightVarNameSumW2, weightSumW2);
119 auto &buffer = buffers.top();
120 buffer.reserve(nNonZeroWeight);
122 for (std::size_t i = 0; i < nEvents; ++i) {
123 if (!hasZeroWeight[i]) {
124 buffer.push_back(dataHist->binVolume(i));
128 insert(
"_bin_volume", {buffer.data(), buffer.size()});
133 for (
auto const &item :
data.getBatches(0, nEvents)) {
138 auto &buffer = buffers.top();
139 buffer.reserve(nNonZeroWeight);
141 for (std::size_t i = 0; i < nEvents; ++i) {
142 if (!hasZeroWeight[i]) {
143 buffer.push_back(span[i]);
146 insert(item.first->GetName(), {buffer.data(), buffer.size()});
151 for (
auto const &item :
data.getCategoryBatches(0, nEvents)) {
156 auto &buffer = buffers.top();
157 buffer.reserve(nNonZeroWeight);
159 for (std::size_t i = 0; i < nEvents; ++i) {
160 if (!hasZeroWeight[i]) {
161 buffer.push_back(
static_cast<double>(intSpan[i]));
164 insert(item.first->GetName(), {buffer.data(), buffer.size()});
167 nEvents = nNonZeroWeight;
170 if (!rangeName.empty()) {
172 std::vector<bool> isInRange(nEvents,
false);
173 for (
auto const &range :
ROOT::Split(rangeName,
",")) {
174 std::vector<bool> isInSubRange(nEvents,
true);
175 for (
auto *observable : dynamic_range_cast<RooAbsRealLValue *>(*
data.get())) {
178 observable->inRange({
retrieve(observable->GetName()).data(), nEvents}, range, isInSubRange);
181 for (std::size_t i = 0; i < isInSubRange.size(); ++i) {
182 isInRange[i] = isInRange[i] || isInSubRange[i];
187 nEvents = std::accumulate(isInRange.begin(), isInRange.end(), 0);
190 for (
auto const &item : dataSpans) {
191 auto const &allValues = item.second;
192 if (allValues.size() == 1) {
195 buffers.emplace(nEvents);
196 double *buffer = buffers.top().data();
198 for (std::size_t i = 0; i < isInRange.size(); ++i) {
200 buffer[j] = allValues[i];
static void retrieve(const gsl_integration_workspace *workspace, double *a, double *b, double *r, double *e)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
RooAbsData is the common abstract base class for binned and unbinned datasets.
The RooDataHist is a container class to hold N-dimensional binned data.
static RooNameReg & instance()
Return reference to singleton instance.
A simple container to hold a batch of data values.
The TNamed class is the base class for all named ROOT classes.
basic_string_view< char > string_view
std::vector< std::string > Split(std::string_view str, std::string_view delims, bool skipEmpty=false)
Splits a string at each character in delims.
std::map< RooFit::Detail::DataKey, RooSpan< const double > > getDataSpans(RooAbsData const &data, std::string_view rangeName, std::string const &prefix, std::stack< std::vector< double > > &buffers, bool skipZeroWeights)
Extract all content from a RooFit datasets as a map of spans.