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(nullptr, 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
58/// \note The subsidiary term is only calculated together with the last event.
59/// While this is meaningless for the subsidiary term itself (it has no
60/// events), it is useful when calculating RooSumLs by parts. The Section
61/// from each part is forwarded here if the component is a RooSubsidiaryL.
63 std::size_t /*components_begin*/,
64 std::size_t /*components_end*/)
65{
67
68 if (events.end_fraction == 1) {
69 for (const auto comp : subsidiary_pdfs_) {
70 sum += -static_cast<RooAbsPdf*>(comp)->getLogVal(&parameter_set_);
71 }
72 }
73
74 return sum;
75}
76
77void RooSubsidiaryL::constOptimizeTestStatistic(RooAbsArg::ConstOpCode /*opcode*/, bool /*doAlsoTrackingOpt*/) {}
78
79} // namespace TestStatistics
80} // namespace RooFit
#define oocoutE(o, a)
The Kahan summation is a compensated summation algorithm, which significantly reduces numerical error...
Definition Util.h:122
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
static void softAbort()
Soft abort function that interrupts macro execution but doesn't kill ROOT.
virtual std::string GetName() const
Definition RooAbsL.cxx:247
void constOptimizeTestStatistic(RooAbsArg::ConstOpCode opcode, bool doAlsoTrackingOpt) override
Interface function signaling a request to perform constant term optimization.
RooArgSet parameter_set_
Set of parameters to which constraints apply.
ROOT::Math::KahanSum< double > evaluatePartition(Section events, std::size_t components_begin, std::size_t components_end) override
std::string GetName() const override
RooArgList subsidiary_pdfs_
Set of subsidiary PDF or "constraint" terms.
RooSubsidiaryL(const std::string &parent_pdf_name, const RooArgSet &pdfs, const RooArgSet &parameter_set)
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:65