54constexpr const char *RooNLLVarNew::weightVarName;
55constexpr const char *RooNLLVarNew::weightVarNameSumW2;
62 return std::make_unique<RooConstVar>(
name,
name, 1.0);
70 _observables(
"!observables",
"List of observables",
this),
74 _observables.add(*obs);
79 _observables(
"!servers",
this,
other._observables),
88 std::size_t nEvents =
output.size();
98 for (std::size_t i = 0; i < nEvents; ++i) {
100 var->setVal(ctx.
at(var)[i]);
102 dataHist.
add(_observables, weights[weights.size() == 1 ? 0 : i]);
106 RooHistPdf pdf{
"offsetPdf",
"offsetPdf", _observables, dataHist};
107 for (std::size_t i = 0; i < nEvents; ++i) {
109 var->setVal(ctx.
at(var)[i]);
111 output[i] = pdf.getVal(_observables);
116 double evaluate()
const override {
return 0.0; }
131RooNLLVarNew::RooNLLVarNew(
const char *
name,
const char *title,
RooAbsPdf &pdf,
RooArgSet const &observables,
134 _pdf{
"pdf",
"pdf",
this, pdf},
137 _binnedL{pdf.getAttribute(
"BinnedLikelihoodActive")}
151 if (expectedEvents) {
153 std::make_unique<RooTemplateProxy<RooAbsReal>>(
"expectedEvents",
"expectedEvents",
this, *expectedEvents);
154 addOwnedComponents(std::move(expectedEvents));
165 auto offsetPdf = std::make_unique<RooOffsetPdf>(
"_offset_pdf",
"_offset_pdf", obs, *
_weightVar);
166 _offsetPdf = std::make_unique<RooTemplateProxy<RooAbsPdf>>(
"offsetPdf",
"offsetPdf",
this, *
offsetPdf);
167 addOwnedComponents(std::move(
offsetPdf));
180 _prefix{
other._prefix},
183 if (
other._expectedEvents) {
184 _expectedEvents = std::make_unique<RooTemplateProxy<RooAbsReal>>(
"expectedEvents",
this, *
other._expectedEvents);
188void RooNLLVarNew::fillBinWidthsFromPdfBoundaries(
RooAbsReal const &pdf,
RooArgSet const &observables)
191 if (!_binw.empty()) {
195 if (observables.
size() != 1) {
196 throw std::runtime_error(
"BinnedPdf optimization only works with a 1D pdf.");
199 std::list<double> *boundaries = pdf.
binBoundaries(*var, var->getMin(), var->getMax());
200 std::list<double>::iterator
biter = boundaries->begin();
201 _binw.resize(boundaries->size() - 1);
205 while (
biter != boundaries->end()) {
215 std::span<const double> weights)
const
222 for (std::size_t i = 0; i <
preds.size(); ++i) {
225 double N = weights[i];
226 double mu =
preds[i];
233 logEvalError(
Form(
"Observed %f events in bin %lu with zero event yield",
N, (
unsigned long)i));
252 auto config = ctx.
config(
this);
256 _sumWeight = weights.size() == 1 ? weights[0] *
probas.size()
266 if (
nllOut.nInfiniteValues > 0) {
267 oocoutW(&*_pdf, Eval) <<
"RooAbsPdf::getLogVal(" << _pdf->GetName()
268 <<
") WARNING: top-level pdf has some infinite values" << std::endl;
270 for (std::size_t i = 0; i <
nllOut.nNonPositiveValues; ++i) {
271 _pdf->logEvalError(
"getLogVal() top-level p.d.f not greater than zero");
273 for (std::size_t i = 0; i <
nllOut.nNaNValues; ++i) {
274 _pdf->logEvalError(
"getLogVal() top-level p.d.f evaluates to NaN");
277 if (_expectedEvents) {
278 std::span<const double>
expected = ctx.
at(*_expectedEvents);
289void RooNLLVarNew::setPrefix(std::string
const &prefix)
296void RooNLLVarNew::resetWeightVarNames()
298 _weightVar->SetName((_prefix + weightVarName).c_str());
301 (*_offsetPdf)->SetName((_prefix +
"_offset_pdf").c_str());
307void RooNLLVarNew::applyWeightSquared(
bool flag)
312void RooNLLVarNew::enableOffsetting(
bool flag)
331 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.
bool getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
Storage_t::size_type size() const
RooAbsArg * first() const
Abstract interface for all probability density functions.
virtual std::unique_ptr< RooAbsReal > createExpectedEventsFunc(const RooArgSet *nset) const
Returns an object that represents the expected number of events for a given normalization set,...
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)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
OffsetMode
For setting the offset mode with the Offset() command argument to RooAbsPdf::fitTo()
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)