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
13#include "RooNormalizedPdf.h"
14#include "RooBatchCompute.h"
15
16/**
17 * \class RooNormalizedPdf
18 *
19 * A RooNormalizedPdf wraps a pdf divided by its integral for a given
20 * normalization set into a new self-normalized pdf.
21 */
22
23void RooNormalizedPdf::computeBatch(double *output, size_t nEvents, RooFit::Detail::DataMap const &dataMap) const
24{
25 auto nums = dataMap.at(_pdf);
26 auto integralSpan = dataMap.at(_normIntegral);
27
28 // We use the extraArgs as output parameter to count evaluation errors.
29 RooBatchCompute::ArgVector extraArgs{0.0, 0.0, 0.0};
30
31 RooBatchCompute::compute(dataMap.config(this), RooBatchCompute::NormalizedPdf, output, nEvents, {nums, integralSpan},
32 extraArgs);
33
34 std::size_t nEvalErrorsType0 = extraArgs[0];
35 std::size_t nEvalErrorsType1 = extraArgs[1];
36 std::size_t nEvalErrorsType2 = extraArgs[2];
37
38 for (std::size_t i = 0; i < nEvalErrorsType0; ++i) {
39 logEvalError("p.d.f normalization integral is zero or negative");
40 }
41 for (std::size_t i = 0; i < nEvalErrorsType1; ++i) {
42 logEvalError("p.d.f value is less than zero, trying to recover");
43 }
44 for (std::size_t i = 0; i < nEvalErrorsType2; ++i) {
45 logEvalError("p.d.f value is Not-a-Number");
46 }
47}
48
50{
51 // For now just return function/normalization integral.
52 ctx.addResult(this, ctx.getResult(_pdf) + "/" + ctx.getResult(_normIntegral));
53}
void logEvalError(const char *message, const char *serverValueString=nullptr) const
Log evaluation error message.
A class to maintain the context for squashing of RooFit models into code.
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.
std::string const & getResult(RooAbsArg const &arg)
Gets the result for the given node using the node name.
RooBatchCompute::Config config(RooAbsArg const *arg) const
Definition DataMap.cxx:40
std::span< const double > at(RooAbsArg const *arg, RooAbsArg const *caller=nullptr)
Definition DataMap.cxx:22
void translate(RooFit::Detail::CodeSquashContext &ctx) const override
This function defines a translation for each RooAbsReal based object that can be used to express the ...
RooRealProxy _normIntegral
void computeBatch(double *output, size_t size, RooFit::Detail::DataMap const &) const override
Base function for computing multiple values of a RooAbsReal.
RooTemplateProxy< RooAbsPdf > _pdf
std::vector< double > ArgVector
void compute(Config cfg, Computer comp, RestrictArr output, size_t size, const VarVector &vars, ArgVector &extraArgs)
static void output()