26std::map<RooFit::Detail::DataKey, RooSpan<const double>>
27getSingleDataSpans(
RooAbsData const &
data, std::string_view rangeName, std::string
const &prefix,
28 std::stack<std::vector<double>> &buffers,
bool skipZeroWeights)
30 std::map<RooFit::Detail::DataKey, RooSpan<const double>> dataSpans;
35 const TNamed *namePtr = nameReg.constPtr((prefix + key).c_str());
36 dataSpans[namePtr] = span;
39 auto retrieve = [&](
const char *key) {
40 const TNamed *namePtr = nameReg.constPtr((prefix + key).c_str());
41 return dataSpans.at(namePtr);
44 std::size_t nEvents =
static_cast<size_t>(
data.numEntries());
52 auto weight =
data.getWeightBatch(0, nEvents,
false);
53 auto weightSumW2 =
data.getWeightBatch(0, nEvents,
true);
55 std::vector<bool> hasZeroWeight;
56 hasZeroWeight.resize(nEvents);
57 std::size_t nNonZeroWeight = 0;
64 auto &buffer = buffers.top();
66 auto &bufferSumW2 = buffers.top();
71 buffer.push_back(1.0);
72 bufferSumW2.push_back(1.0);
75 nNonZeroWeight = nEvents;
77 buffer.reserve(nEvents);
78 bufferSumW2.reserve(nEvents);
79 for (std::size_t i = 0; i < nEvents; ++i) {
80 if (!skipZeroWeights || weight[i] != 0) {
81 buffer.push_back(weight[i]);
82 bufferSumW2.push_back(weightSumW2[i]);
85 hasZeroWeight[i] =
true;
92 insert(RooNLLVarNew::weightVarName, weight);
93 insert(RooNLLVarNew::weightVarNameSumW2, weightSumW2);
99 auto &buffer = buffers.top();
100 buffer.reserve(nNonZeroWeight);
102 for (std::size_t i = 0; i < nEvents; ++i) {
103 if (!hasZeroWeight[i]) {
104 buffer.push_back(dataHist->binVolume(i));
108 insert(
"_bin_volume", {buffer.data(), buffer.size()});
113 for (
auto const &item :
data.getBatches(0, nEvents)) {
118 auto &buffer = buffers.top();
119 buffer.reserve(nNonZeroWeight);
121 for (std::size_t i = 0; i < nEvents; ++i) {
122 if (!hasZeroWeight[i]) {
123 buffer.push_back(span[i]);
126 insert(item.first->GetName(), {buffer.data(), buffer.size()});
131 for (
auto const &item :
data.getCategoryBatches(0, nEvents)) {
136 auto &buffer = buffers.top();
137 buffer.reserve(nNonZeroWeight);
139 for (std::size_t i = 0; i < nEvents; ++i) {
140 if (!hasZeroWeight[i]) {
141 buffer.push_back(
static_cast<double>(intSpan[i]));
144 insert(item.first->GetName(), {buffer.data(), buffer.size()});
147 nEvents = nNonZeroWeight;
150 if (!rangeName.empty()) {
152 std::vector<bool> isInRange(nEvents,
false);
153 for (
auto const &range :
ROOT::
Split(rangeName,
",")) {
154 std::vector<bool> isInSubRange(nEvents,
true);
158 observable->inRange({
retrieve(observable->GetName()).data(), nEvents}, range, isInSubRange);
161 for (std::size_t i = 0; i < isInSubRange.size(); ++i) {
162 isInRange[i] = isInRange[i] || isInSubRange[i];
167 nEvents = std::accumulate(isInRange.begin(), isInRange.end(), 0);
170 for (
auto const &item : dataSpans) {
171 auto const &allValues = item.second;
172 if (allValues.size() == 1) {
175 buffers.emplace(nEvents);
176 double *buffer = buffers.top().data();
178 for (std::size_t i = 0; i < isInRange.size(); ++i) {
180 buffer[j] = allValues[i];
219std::map<RooFit::Detail::DataKey, RooSpan<const double>>
222 bool takeGlobalObservablesFromData, std::stack<std::vector<double>> &buffers)
224 std::vector<std::pair<std::string, RooAbsData const *>> datas;
225 std::vector<bool> isBinnedL;
226 bool splitRange =
false;
227 std::vector<std::unique_ptr<RooAbsData>> splittedDataSets;
230 std::unique_ptr<TList> splits{
data.split(*simPdf,
true)};
231 for (
auto *
d : static_range_cast<RooAbsData *>(*splits)) {
237 datas.emplace_back(std::string(
"_") +
d->GetName() +
"_",
d);
238 isBinnedL.emplace_back(simComponent->
getAttribute(
"BinnedLikelihoodActive"));
240 splittedDataSets.emplace_back(
d);
244 datas.emplace_back(
"", &
data);
245 isBinnedL.emplace_back(
false);
248 std::map<RooFit::Detail::DataKey, RooSpan<const double>> dataSpans;
250 for (std::size_t iData = 0; iData < datas.size(); ++iData) {
251 auto const &toAdd = datas[iData];
252 auto spans = getSingleDataSpans(
254 toAdd.first, buffers, skipZeroWeights && !isBinnedL[iData]);
255 for (
auto const &item : spans) {
256 dataSpans.insert(item);
260 if (takeGlobalObservablesFromData &&
data.getGlobalObservables()) {
262 auto &buffer = buffers.top();
263 buffer.reserve(
data.getGlobalObservables()->size());
264 for (
auto *arg : static_range_cast<RooRealVar const *>(*
data.getGlobalObservables())) {
265 buffer.push_back(arg->getVal());
ROOT::RRangeCast< T, true, Range_t > dynamic_range_cast(Range_t &&coll)
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
bool getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
RooAbsData is the common abstract base class for binned and unbinned datasets.
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
The RooDataHist is a container class to hold N-dimensional binned data.
static RooNameReg & instance()
Return reference to singleton instance.
RooSimultaneous 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.
A simple container to hold a batch of data values.
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::map< RooFit::Detail::DataKey, RooSpan< const double > > getDataSpans(RooAbsData const &data, std::string const &rangeName, RooSimultaneous const *simPdf, bool skipZeroWeights, bool takeGlobalObservablesFromData, std::stack< std::vector< double > > &buffers)
Extract all content from a RooFit datasets as a map of spans.
std::string getRangeNameForSimComponent(std::string const &rangeName, bool splitRange, std::string const &catName)
#define Split(a, ahi, alo)