Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooNormalizedPdf.cxx
Go to the documentation of this file.
1/*
2 * Project: RooFit
3 * Authors:
4 * Jonas Rembser, CERN 2022
5 *
6 * Copyright (c) 2022, CERN
7 *
8 * Redistribution and use in source and binary forms,
9 * with or without modification, are permitted according to the terms
10 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)
11 */
12
14
15#include "RooBatchCompute.h"
16#include "RooFitImplHelpers.h"
17
18#include <array>
19
20/**
21 * \class RooNormalizedPdf
22 *
23 * A RooNormalizedPdf wraps a pdf divided by its integral for a given
24 * normalization set into a new self-normalized pdf.
25 */
26
27namespace RooFit::Detail {
28
30{
31 auto nums = ctx.at(_pdf);
32 auto integralSpan = ctx.at(_normIntegral);
33 auto config = ctx.config(this);
34
35 // The first three extra args are output parameters to count evaluation
36 // errors. The last one tells the LogNormalizedPdf computer whether the pdf
37 // values are logarithms already.
38 _extraArgs = {0., 0., 0., static_cast<double>(ctx.outputsLogarithm(&*_pdf))};
39 const auto computer =
41 RooBatchCompute::compute(config, computer, ctx.output(), {nums, integralSpan}, _extraArgs);
42
43 if (config.useCuda()) {
44 // In CUDA mode, the counters are read back from the GPU without
45 // synchronizing the stream: they only arrive in _extraArgs with the
46 // synchronization at the end of the evaluation of the full computation
47 // graph, so the logging has to be deferred until then.
48 ctx.deferAction([this] { logEvalErrorCounts(); });
49 } else {
51 }
52}
53
55{
56 const std::size_t nEvalErrorsType0 = _extraArgs[0];
57 const std::size_t nEvalErrorsType1 = _extraArgs[1];
58 const std::size_t nEvalErrorsType2 = _extraArgs[2];
59
60 for (std::size_t i = 0; i < nEvalErrorsType0; ++i) {
61 logEvalError("p.d.f normalization integral is zero or negative");
62 }
63 for (std::size_t i = 0; i < nEvalErrorsType1; ++i) {
64 logEvalError("p.d.f value is less than zero, trying to recover");
65 }
66 for (std::size_t i = 0; i < nEvalErrorsType2; ++i) {
67 logEvalError("p.d.f value is Not-a-Number");
68 }
69}
70
71double RooNormalizedPdf::getValV(const RooArgSet * /*normSet*/) const
72{
74}
75
76} // namespace RooFit::Detail
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:107
void logEvalError(const char *message, const char *serverValueString=nullptr) const
Log evaluation error message.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
RooTemplateProxy< RooAbsPdf > _pdf
double getValV(const RooArgSet *normSet) const override
Return current value, normalized by integrating over the observables in nset.
std::array< double, 4 > _extraArgs
Extra args of the compute functions: three evaluation error counters, filled by the compute function,...
void doEval(RooFit::EvalContext &) const override
Base function for computing multiple values of a RooAbsReal.
std::span< const double > at(RooAbsArg const *arg, RooAbsArg const *caller=nullptr)
std::span< double > output()
bool outputsLogarithm(RooAbsArg const *arg) const
Whether the output of the given node is the logarithm of its value.
void deferAction(std::function< void()> action)
Register an action to be run after the evaluation of the full computation graph, when all potentially...
RooBatchCompute::Config config(RooAbsArg const *arg) const
void compute(Config cfg, Computer comp, std::span< double > output, VarSpan vars, ArgSpan extraArgs={})
double normalizeWithNaNPacking(RooAbsPdf const &pdf, double rawVal, double normVal)