Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooSubsidiaryL.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
13/**
14\file RooSubsidiaryL.cxx
15\class RooSubsidiaryL
16\ingroup Roofitcore
17
18\brief RooSubsidiaryL calculates the sum of the -(log) likelihoods of a set of RooAbsPdf objects that represent
19subsidiary or constraint functions.
20
21This class is used to gather all subsidiary PDF terms from the component PDFs of RooSumL likelihoods and calculate the
22composite -log(L). Such subsidiary terms can be marked using RooFit::Constrain arguments to RooAbsPdf::fitTo() or
23RooAbsPdf::createNLL().
24
25Subsidiary terms are summed separately for increased numerical stability, since these terms are often small and cause
26numerical variances in their original PDFs, whereas by summing as one separate subsidiary collective term, it is
27numerically very stable.
28
29\note When a subsidiary PDF is part of multiple component PDFs, it will only be summed once in this class! This doesn't
30change the derivative of the log likelihood (which is what matters in fitting the likelihood), but does change the
31value of the (log-)likelihood itself.
32**/
33
35#include <RooAbsPdf.h> // for dynamic cast
36#include <RooErrorHandler.h>
37
38#include "Math/Util.h" // KahanSum
39
40namespace RooFit {
41namespace TestStatistics {
42
43RooSubsidiaryL::RooSubsidiaryL(const std::string &parent_pdf_name, const RooArgSet &pdfs,
44 const RooArgSet &parameter_set)
45 : RooAbsL(nullptr, nullptr, 0, 0, RooAbsL::Extended::No), parent_pdf_name_(parent_pdf_name)
46{
47 for (const auto comp : pdfs) {
48 if (!dynamic_cast<RooAbsPdf *>(comp)) {
49 oocoutE((TObject *)0, InputArguments) << "RooSubsidiaryL::ctor(" << GetName() << ") ERROR: component "
50 << comp->GetName() << " is not of type RooAbsPdf" << std::endl;
52 }
53 subsidiary_pdfs_.add(*comp);
54 }
55 parameter_set_.add(parameter_set);
56}
57
59 std::size_t /*components_begin*/,
60 std::size_t /*components_end*/)
61{
62 if (events.begin_fraction != 0 || events.end_fraction != 1) {
63 oocoutW((TObject *)0, InputArguments) << "RooSubsidiaryL::evaluatePartition can only calculate everything, so "
64 "section should be {0,1}, but it's not!"
65 << std::endl;
66 }
67
69
70 for (const auto comp : subsidiary_pdfs_) {
71 sum += -((RooAbsPdf *)comp)->getLogVal(&parameter_set_);
72 }
73
74 return sum;
75}
76
77void RooSubsidiaryL::constOptimizeTestStatistic(RooAbsArg::ConstOpCode /*opcode*/, bool /*doAlsoTrackingOpt*/) {}
78
79} // namespace TestStatistics
80} // namespace RooFit
#define oocoutW(o, a)
#define oocoutE(o, a)
The Kahan summation is a compensated summation algorithm, which significantly reduces numerical error...
Definition Util.h:122
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:35
static void softAbort()
virtual std::string GetName() const
Definition RooAbsL.cxx:230
void constOptimizeTestStatistic(RooAbsArg::ConstOpCode opcode, bool doAlsoTrackingOpt) override
Interface function signaling a request to perform constant term optimization.
ROOT::Math::KahanSum< double > evaluatePartition(Section events, std::size_t components_begin, std::size_t components_end) override
std::string GetName() const override
RooSubsidiaryL(const std::string &parent_pdf_name, const RooArgSet &pdfs, const RooArgSet &parameter_set)
Mother of all ROOT objects.
Definition TObject.h:41
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition Common.h:18
@ InputArguments
A part of some range delimited by two fractional points between 0 and 1 (inclusive).
Definition RooAbsL.h:57