49ClassImp(RooFit::Detail::RooNLLVarNew);
 
   55constexpr const char *RooNLLVarNew::weightVarName;
 
   56constexpr const char *RooNLLVarNew::weightVarNameSumW2;
 
   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),
 
   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; } 
 
  132RooNLLVarNew::RooNLLVarNew(
const char *
name, 
const char *title, 
RooAbsPdf &pdf, 
RooArgSet const &observables,
 
  135     _pdf{
"pdf", 
"pdf", 
this, pdf},
 
  138     _binnedL{pdf.getAttribute(
"BinnedLikelihoodActive")}
 
  152      if (expectedEvents) {
 
  154            std::make_unique<RooTemplateProxy<RooAbsReal>>(
"expectedEvents", 
"expectedEvents", 
this, *expectedEvents);
 
  155         addOwnedComponents(std::move(expectedEvents));
 
  166      auto offsetPdf = std::make_unique<RooOffsetPdf>(
"_offset_pdf", 
"_offset_pdf", obs, *
_weightVar);
 
  167      _offsetPdf = std::make_unique<RooTemplateProxy<RooAbsPdf>>(
"offsetPdf", 
"offsetPdf", 
this, *
offsetPdf);
 
  168      addOwnedComponents(std::move(
offsetPdf));
 
  179     _doOffset{
other._doOffset},
 
  180     _simCount{
other._simCount},
 
  181     _prefix{
other._prefix},
 
  184   if (
other._expectedEvents) {
 
  185      _expectedEvents = std::make_unique<RooTemplateProxy<RooAbsReal>>(
"expectedEvents", 
this, *
other._expectedEvents);
 
  189void RooNLLVarNew::fillBinWidthsFromPdfBoundaries(
RooAbsReal const &pdf, 
RooArgSet const &observables)
 
  192   if (!_binw.empty()) {
 
  196   if (observables.
size() != 1) {
 
  197      throw std::runtime_error(
"BinnedPdf optimization only works with a 1D pdf.");
 
  200      std::list<double> *boundaries = pdf.
binBoundaries(*var, var->getMin(), var->getMax());
 
  201      std::list<double>::iterator 
biter = boundaries->begin();
 
  202      _binw.resize(boundaries->size() - 1);
 
  206      while (
biter != boundaries->end()) {
 
  216                                 std::span<const double> weights)
 const 
  223   for (std::size_t i = 0; i < 
preds.size(); ++i) {
 
  226      double N = weights[i];
 
  227      double mu = 
preds[i];
 
  234         logEvalError(
Form(
"Observed %f events in bin %lu with zero event yield", 
N, (
unsigned long)i));
 
  253   auto config = ctx.
config(
this);
 
  257   _sumWeight = weights.size() == 1 ? weights[0] * 
probas.size()
 
  265                                            _doBinOffset ? ctx.at(*_offsetPdf) : std::span<const 
double>{});
 
  267   if (
nllOut.nInfiniteValues > 0) {
 
  268      oocoutW(&*_pdf, Eval) << 
"RooAbsPdf::getLogVal(" << _pdf->GetName()
 
  269                            << 
") WARNING: top-level pdf has some infinite values" << std::endl;
 
  271   for (std::size_t i = 0; i < 
nllOut.nNonPositiveValues; ++i) {
 
  272      _pdf->logEvalError(
"getLogVal() top-level p.d.f not greater than zero");
 
  274   for (std::size_t i = 0; i < 
nllOut.nNaNValues; ++i) {
 
  275      _pdf->logEvalError(
"getLogVal() top-level p.d.f evaluates to NaN");
 
  278   if (_expectedEvents) {
 
  279      std::span<const double> 
expected = ctx.
at(*_expectedEvents);
 
  290void RooNLLVarNew::setPrefix(std::string 
const &prefix)
 
  297void RooNLLVarNew::resetWeightVarNames()
 
  299   _weightVar->SetName((_prefix + weightVarName).c_str());
 
  302      (*_offsetPdf)->SetName((_prefix + 
"_offset_pdf").c_str());
 
  308void RooNLLVarNew::applyWeightSquared(
bool flag)
 
  313void RooNLLVarNew::enableOffsetting(
bool flag)
 
  324   if (!_doBinOffset && _simCount > 1) {
 
  332      if (_offset.Sum() == 0 && _offset.Carry() == 0 && (
result.Sum() != 0 || 
result.Carry() != 0)) {
 
  341   if (
_binnedL && !_pdf->getAttribute(
"BinnedLikelihoodActiveYields")) {
 
  343      errorMsg << 
"RooNLLVarNew::translate(): binned likelihood optimization is only supported when raw pdf " 
  344                  "values can be interpreted as yields." 
  345               << 
" This is not the case for HistFactory models written with ROOT versions before 6.26.00";
 
  347      throw std::runtime_error(
errorMsg.str());
 
  363      std::string 
simCountStr = std::to_string(
static_cast<double>(_simCount));
 
  375   if (_expectedEvents) {
 
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.
A class to maintain the context for squashing of RooFit models into code.
std::string buildCall(std::string const &funcname, Args_t const &...args)
Build the code to call the function with name funcname, passing some arguments.
void addResult(RooAbsArg const *key, std::string const &value)
A function to save an expression that includes/depends on the result of the input node.
void addToCodeBody(RooAbsArg const *klass, std::string const &in)
Adds the input string to the squashed code body.
std::string const & getResult(RooAbsArg const &arg)
Gets the result for the given node using the node name.
void addToGlobalScope(std::string const &str)
Adds the given string to the string block that will be emitted at the top of the squashed function.
std::unique_ptr< LoopScope > beginLoop(RooAbsArg const *in)
Create a RAII scope for iterating over vector observables.
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 propability 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)
std::string makeValidVarName(std::string const &in)
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)