Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooRealL.cxx
Go to the documentation of this file.
1/*
2 * Project: RooFit
3 * Authors:
4 * PB, Patrick Bos, Netherlands eScience Center, p.bos@esciencecenter.nl
5 *
6 * Copyright (c) 2021, 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
15#include <RooRealVar.h>
16
17#include "TMath.h" // IsNaN
18
19namespace RooFit {
20namespace TestStatistics {
21
22/** \class RooRealL
23 * \ingroup Roofitcore
24 *
25 * \brief RooAbsReal that wraps RooAbsL likelihoods for use in RooFit outside of the RooMinimizer context
26 *
27 * This class provides a simple wrapper to evaluate RooAbsL derived likelihood objects like a regular RooFit real value.
28 * Whereas the RooAbsL objects are meant to be used within the context of minimization, RooRealL can be used in any
29 * RooFit context, like plotting. The value can be accessed through getVal(), like with other RooFit real variables.
30 **/
31
32RooRealL::RooRealL(const char *name, const char *title, std::shared_ptr<RooAbsL> likelihood)
33 : RooAbsReal(name, title),
34 likelihood_(std::move(likelihood)),
35 vars_proxy_("varsProxy", "proxy set of parameters", this)
36{
37 std::unique_ptr<RooArgSet> params{likelihood_->getParameters()};
38 vars_obs_.add(*params);
39 vars_proxy_.add(*params);
40}
41
42RooRealL::RooRealL(const RooRealL &other, const char *name)
43 : RooAbsReal(other, name), likelihood_(other.likelihood_), vars_proxy_("varsProxy", this, other.vars_proxy_)
44{
45 vars_obs_.add(other.vars_obs_);
46}
47
48double RooRealL::evaluate() const
49{
50 // Transfer values from proxy variables to internal variables of likelihood
51 if (!vars_proxy_.empty()) {
52 for (auto i = 0u; i < vars_obs_.size(); ++i) {
53 auto harg = vars_obs_[i];
54 const auto parg = vars_proxy_[i];
55
56 if (harg != parg) {
57 (static_cast<RooAbsRealLValue *>(harg))->setVal((static_cast<RooAbsReal *>(parg))->getVal());
58 }
59 }
60 }
61 // Evaluate as straight FUNC
62 std::size_t last_component = likelihood_->getNComponents();
63
64 auto ret_kahan = likelihood_->evaluatePartition({0, 1}, 0, last_component);
65
66 const double norm = globalNormalization();
67 double ret = ret_kahan.Sum() / norm;
68 eval_carry = ret_kahan.Carry() / norm;
69
70 if (TMath::IsNaN(ret)) {
71 RooAbsReal::logEvalError("function value is NAN");
72 }
73
74 return ret;
75}
76
77} // namespace TestStatistics
78} // namespace RooFit
char name[80]
Definition TGX11.cxx:110
RooFit::OwningPtr< RooArgSet > getParameters(const RooAbsData *data, bool stripDisconnected=true) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Storage_t::size_type size() const
Abstract base class for objects that represent a real value that may appear on the left hand side of ...
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:59
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:103
void logEvalError(const char *message, const char *serverValueString=nullptr) const
Log evaluation error message.
bool add(const RooAbsArg &var, bool valueServer, bool shapeServer, bool silent)
Overloaded RooCollection_t::add() method insert object into set and registers object as server to own...
RooAbsReal that wraps RooAbsL likelihoods for use in RooFit outside of the RooMinimizer context.
Definition RooRealL.h:28
std::shared_ptr< RooAbsL > likelihood_
Definition RooRealL.h:50
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
Definition RooRealL.cxx:48
RooSetProxy vars_proxy_
sets up client-server connections
Definition RooRealL.h:52
double globalNormalization() const
Definition RooRealL.h:35
RooArgSet vars_obs_
list of observables
Definition RooRealL.h:53
RooRealL(const char *name, const char *title, std::shared_ptr< RooAbsL > likelihood)
Definition RooRealL.cxx:32
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition JSONIO.h:26
Bool_t IsNaN(Double_t x)
Definition TMath.h:892