32void assignSpan(std::span<T> &to, std::span<T>
const &from)
37std::map<RooFit::Detail::DataKey, std::span<const double>>
38getSingleDataSpans(
RooAbsData const &
data, std::string_view rangeName, std::string
const &prefix,
39 std::stack<std::vector<double>> &buffers,
bool skipZeroWeights)
41 std::map<RooFit::Detail::DataKey, std::span<const double>> dataSpans;
45 auto insert = [&](
const char *key, std::span<const double> span) {
46 const TNamed *namePtr = nameReg.constPtr((prefix + key).c_str());
47 dataSpans[namePtr] = span;
50 auto retrieve = [&](
const char *key) {
51 const TNamed *namePtr = nameReg.constPtr((prefix + key).c_str());
52 return dataSpans.at(namePtr);
55 std::size_t nEvents =
static_cast<size_t>(
data.numEntries());
63 auto weight =
data.getWeightBatch(0, nEvents,
false);
64 auto weightSumW2 =
data.getWeightBatch(0, nEvents,
true);
66 std::vector<bool> hasZeroWeight;
67 hasZeroWeight.resize(nEvents);
68 std::size_t nNonZeroWeight = 0;
75 auto &buffer = buffers.top();
77 auto &bufferSumW2 = buffers.top();
82 buffer.push_back(1.0);
83 bufferSumW2.push_back(1.0);
84 assignSpan(weight, {buffer.data(), 1});
85 assignSpan(weightSumW2, {bufferSumW2.data(), 1});
86 nNonZeroWeight = nEvents;
88 buffer.reserve(nEvents);
89 bufferSumW2.reserve(nEvents);
90 for (std::size_t i = 0; i < nEvents; ++i) {
91 if (!skipZeroWeights || weight[i] != 0) {
92 buffer.push_back(weight[i]);
93 bufferSumW2.push_back(weightSumW2[i]);
96 hasZeroWeight[i] =
true;
99 assignSpan(weight, {buffer.data(), nNonZeroWeight});
100 assignSpan(weightSumW2, {bufferSumW2.data(), nNonZeroWeight});
108 for (
auto const &item :
data.getBatches(0, nEvents)) {
110 std::span<const double> span{item.second};
113 auto &buffer = buffers.top();
114 buffer.reserve(nNonZeroWeight);
116 for (std::size_t i = 0; i < nEvents; ++i) {
117 if (!hasZeroWeight[i]) {
118 buffer.push_back(span[i]);
121 insert(item.first->GetName(), {buffer.data(), buffer.size()});
126 for (
auto const &item :
data.getCategoryBatches(0, nEvents)) {
128 std::span<const RooAbsCategory::value_type> intSpan{item.second};
131 auto &buffer = buffers.top();
132 buffer.reserve(nNonZeroWeight);
134 for (std::size_t i = 0; i < nEvents; ++i) {
135 if (!hasZeroWeight[i]) {
136 buffer.push_back(
static_cast<double>(intSpan[i]));
139 insert(item.first->GetName(), {buffer.data(), buffer.size()});
142 nEvents = nNonZeroWeight;
145 if (!rangeName.empty()) {
147 std::vector<bool> isInRange(nEvents,
false);
148 for (
auto const &range :
ROOT::
Split(rangeName,
",")) {
149 std::vector<bool> isInSubRange(nEvents,
true);
153 observable->inRange({
retrieve(observable->GetName()).data(), nEvents}, range, isInSubRange);
156 for (std::size_t i = 0; i < isInSubRange.size(); ++i) {
157 isInRange[i] = isInRange[i] || isInSubRange[i];
162 nEvents = std::accumulate(isInRange.begin(), isInRange.end(), 0);
165 for (
auto const &item : dataSpans) {
166 auto const &allValues = item.second;
167 if (allValues.size() == 1) {
170 buffers.emplace(nEvents);
171 double *buffer = buffers.top().data();
173 for (std::size_t i = 0; i < isInRange.size(); ++i) {
175 buffer[j] = allValues[i];
179 assignSpan(dataSpans[item.first], {buffer, nEvents});
212std::map<RooFit::Detail::DataKey, std::span<const double>>
213RooFit::BatchModeDataHelpers::getDataSpans(
RooAbsData const &
data, std::string
const &rangeName,
215 bool takeGlobalObservablesFromData, std::stack<std::vector<double>> &buffers)
217 std::vector<std::pair<std::string, RooAbsData const *>> datasets;
218 std::vector<bool> isBinnedL;
219 bool splitRange =
false;
220 std::vector<std::unique_ptr<RooAbsData>> splitDataSets;
223 std::unique_ptr<TList> splits{
data.split(*simPdf,
true)};
230 datasets.emplace_back(std::string(
"_") +
d->GetName() +
"_",
d);
231 isBinnedL.emplace_back(simComponent->
getAttribute(
"BinnedLikelihoodActive"));
233 splitDataSets.emplace_back(
d);
237 datasets.emplace_back(
"", &
data);
238 isBinnedL.emplace_back(
false);
241 std::map<RooFit::Detail::DataKey, std::span<const double>> dataSpans;
243 for (std::size_t iData = 0; iData < datasets.size(); ++iData) {
244 auto const &toAdd = datasets[iData];
245 auto spans = getSingleDataSpans(
247 toAdd.first, buffers, skipZeroWeights && !isBinnedL[iData]);
248 for (
auto const &item : spans) {
249 dataSpans.insert(item);
253 if (takeGlobalObservablesFromData &&
data.getGlobalObservables()) {
255 auto &buffer = buffers.top();
256 buffer.reserve(
data.getGlobalObservables()->size());
258 buffer.push_back(arg->getVal());
259 assignSpan(dataSpans[arg], {&buffer.back(), 1});
275std::map<RooFit::Detail::DataKey, std::size_t> RooFit::BatchModeDataHelpers::determineOutputSizes(
278 std::map<RooFit::Detail::DataKey, std::size_t>
output;
284 std::size_t inputSize = inputSizeFunc(arg);
291 std::size_t
size = 1;
295 if (!arg->isReducerNode()) {
296 for (
RooAbsArg *server : arg->servers()) {
297 if (server->isValueServer(*arg)) {
ROOT::RRangeCast< T, true, Range_t > dynamic_range_cast(Range_t &&coll)
ROOT::RRangeCast< T, false, Range_t > static_range_cast(Range_t &&coll)
static void retrieve(const gsl_integration_workspace *workspace, double *a, double *b, double *r, double *e)
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Common abstract base class for objects that represent a value and a "shape" in RooFit.
bool getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
Abstract base class for binned and unbinned datasets.
Abstract interface for all probability density functions.
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
RooArgSet is a container object that can hold multiple RooAbsArg objects.
static constexpr const char * weightVarName
static constexpr const char * weightVarNameSumW2
static RooNameReg & instance()
Return reference to singleton instance.
RooRealVar represents a variable that can be changed from the outside.
Facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
RooAbsPdf * getPdf(RooStringView catName) const
Return the p.d.f associated with the given index category name.
The TNamed class is the base class for all named ROOT classes.
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
std::string getRangeNameForSimComponent(std::string const &rangeName, bool splitRange, std::string const &catName)
void getSortedComputationGraph(RooAbsArg const &func, RooArgSet &out)
#define Split(a, ahi, aLo)