52constexpr const char *RooNLLVarNew::weightVarName;
53constexpr const char *RooNLLVarNew::weightVarNameSumW2;
54constexpr const char *RooNLLVarNew::binVolumeVarName;
55constexpr const char *RooNLLVarNew::weightErrorLoVarName;
56constexpr const char *RooNLLVarNew::weightErrorHiVarName;
63 return std::make_unique<RooConstVar>(
name,
name, 1.0);
71 _observables(
"!observables",
"List of observables",
this),
75 _observables.add(*obs);
80 _observables(
"!servers",
this,
other._observables),
88 std::span<double> output = ctx.
output();
89 std::size_t nEvents = output.size();
99 for (std::size_t i = 0; i < nEvents; ++i) {
101 var->setVal(ctx.
at(var)[i]);
103 dataHist.
add(_observables, weights[weights.size() == 1 ? 0 : i]);
107 RooHistPdf pdf{
"offsetPdf",
"offsetPdf", _observables, dataHist};
108 for (std::size_t i = 0; i < nEvents; ++i) {
110 var->setVal(ctx.
at(var)[i]);
112 output[i] = pdf.getVal(_observables);
117 double evaluate()
const override {
return 0.0; }
131 _func{
"func",
"func",
this, func},
137 auto *pdf =
dynamic_cast<RooAbsPdf *
>(&func);
143 setAttribute(
"Chi2EvaluationActive");
144 _funcMode = !pdf ? FuncMode::Function : (cfg.extended ? FuncMode::ExtendedPdf : FuncMode::Pdf);
146 _binnedL = pdf && pdf->getAttribute(
"BinnedLikelihoodActive");
160 std::unique_ptr<RooAbsReal> expectedEvents = pdf->createExpectedEventsFunc(&obs);
161 if (expectedEvents) {
163 std::make_unique<RooTemplateProxy<RooAbsReal>>(
"expectedEvents",
"expectedEvents",
this, *expectedEvents);
164 addOwnedComponents(std::move(expectedEvents));
173 if (
_binnedL && !pdf->getAttribute(
"BinnedLikelihoodActiveYields")) {
183 auto offsetPdf = std::make_unique<RooOffsetPdf>(
"_offset_func",
"_offset_func", obs, *
_weightVar);
184 _offsetPdf = std::make_unique<RooTemplateProxy<RooAbsPdf>>(
"offsetPdf",
"offsetPdf",
this, *
offsetPdf);
185 addOwnedComponents(std::move(
offsetPdf));
223 _prefix{
other._prefix},
226 if (
other._expectedEvents) {
227 _expectedEvents = std::make_unique<RooTemplateProxy<RooAbsReal>>(
"expectedEvents",
this, *
other._expectedEvents);
229 if (
other._binVolumes) {
232 if (
other._weightErrLo) {
235 if (
other._weightErrHi) {
240void RooNLLVarNew::fillBinWidthsFromPdfBoundaries(
RooAbsReal const &pdf,
RooArgSet const &observables)
243 if (!_binw.empty()) {
247 if (observables.
size() != 1) {
248 throw std::runtime_error(
"BinnedPdf optimization only works with a 1D pdf.");
251 std::list<double> *boundaries = pdf.
binBoundaries(*var, var->getMin(), var->getMax());
252 std::list<double>::iterator
biter = boundaries->begin();
253 _binw.resize(boundaries->size() - 1);
257 while (
biter != boundaries->end()) {
267 std::span<const double> weights)
const
274 for (std::size_t i = 0; i <
preds.size(); ++i) {
277 double N = weights[i];
278 double mu =
preds[i];
285 logEvalError(
Form(
"Observed %f events in bin %lu with zero event yield",
N, (
unsigned long)i));
295void RooNLLVarNew::doEvalChi2(
RooFit::EvalContext &ctx, std::span<const double>
preds, std::span<const double> weights,
305 auto config = ctx.
config(
this);
315 case FuncMode::ExtendedPdf:
normFactor = ctx.
at(*_expectedEvents)[0];
break;
316 case FuncMode::Function:
normFactor = 1.0;
break;
322 for (std::size_t i = 0; i <
preds.size(); ++i) {
323 const double N = weights[i];
325 const double diff = mu -
N;
336 default:
sigma2 = mu;
break;
340 if (
sigma2 == 0.0 &&
N == 0.0 && mu == 0.0) {
344 logEvalError(
Form(
"chi2 bin %lu has non-positive error; term replaced with NaN", (
unsigned long)i));
345 result += std::numeric_limits<double>::quiet_NaN();
369 auto config = ctx.
config(
this);
382 if (
nllOut.nInfiniteValues > 0) {
383 oocoutW(&*_func, Eval) <<
"RooAbsPdf::getLogVal(" << _func->GetName()
384 <<
") WARNING: top-level pdf has some infinite values" << std::endl;
386 for (std::size_t i = 0; i <
nllOut.nNonPositiveValues; ++i) {
387 _func->logEvalError(
"getLogVal() top-level p.d.f not greater than zero");
389 for (std::size_t i = 0; i <
nllOut.nNaNValues; ++i) {
390 _func->logEvalError(
"getLogVal() top-level p.d.f evaluates to NaN");
393 if (_expectedEvents) {
396 std::span<const double>
expected = ctx.
at(*_expectedEvents);
407void RooNLLVarNew::setPrefix(std::string
const &prefix)
414void RooNLLVarNew::resetWeightVarNames()
416 _weightVar->SetName((_prefix + weightVarName).c_str());
419 (*_offsetPdf)->SetName((_prefix +
"_offset_func").c_str());
434void RooNLLVarNew::applyWeightSquared(
bool flag)
438 coutW(Fitting) <<
"RooNLLVarNew::applyWeightSquared(" << GetName()
439 <<
") has no effect on a chi-squared evaluator; ignoring." << std::endl;
446void RooNLLVarNew::enableOffsetting(
bool flag)
466 if (_offset.Sum() == 0 && _offset.Carry() == 0 && (
result.Sum() != 0 ||
result.Carry() != 0)) {
ROOT::RRangeCast< T, false, Range_t > static_range_cast(Range_t &&coll)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
The Kahan summation is a compensated summation algorithm, which significantly reduces numerical error...
Common abstract base class for objects that represent a value and a "shape" in RooFit.
RooFit::OwningPtr< RooArgSet > getObservables(const RooArgSet &set, bool valueOnly=true) const
Given a set of possible observables, return the observables that this PDF depends on.
Storage_t::size_type size() const
RooAbsArg * first() const
Abstract interface for all probability density functions.
Abstract base class for objects that represent a real value and implements functionality common to al...
virtual std::list< double > * binBoundaries(RooAbsRealLValue &obs, double xlo, double xhi) const
Retrieve bin boundaries if this distribution is binned in obs.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Container class to hold N-dimensional binned data.
void add(const RooArgSet &row, double wgt=1.0) override
Add wgt to the bin content enclosed by the coordinates passed in row.
std::span< const double > at(RooAbsArg const *arg, RooAbsArg const *caller=nullptr)
std::span< double > output()
RooBatchCompute::Config config(RooAbsArg const *arg) const
void setOutputWithOffset(RooAbsArg const *arg, ROOT::Math::KahanSum< double > val, ROOT::Math::KahanSum< double > const &offset)
Sets the output value with an offset.
A probability density function sampled from a multidimensional histogram.
Variable that can be changed from the outside.
Mother of all ROOT objects.
double reduceSum(Config cfg, InputArr input, size_t n)
ReduceNLLOutput reduceNLL(Config cfg, std::span< const double > probas, std::span< const double > weights, std::span< const double > offsetProbas)
double nll(double pdf, double weight, int binnedL, int doBinOffset)
void evaluate(typename Architecture_t::Tensor_t &A, EActivationFunction f)
Apply the given activation function to each value in the given tensor A.
void probas(TString dataset, TString fin="TMVA.root", Bool_t useTMVAStyle=kTRUE)