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 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{
48 parameter_set_.add(parameter_set);
49}
50
51/// \note The subsidiary term is only calculated together with the last event.
52/// While this is meaningless for the subsidiary term itself (it has no
53/// events), it is useful when calculating RooSumLs by parts. The Section
54/// from each part is forwarded here if the component is a RooSubsidiaryL.
56 std::size_t /*components_begin*/,
57 std::size_t /*components_end*/)
58{
60
61 if (events.end_fraction == 1) {
62 for (const auto comp : subsidiary_pdfs_) {
63 sum += -static_cast<RooAbsPdf*>(comp)->getLogVal(&parameter_set_);
64 }
65 }
66
67 return sum;
68}
69
70void RooSubsidiaryL::constOptimizeTestStatistic(RooAbsArg::ConstOpCode /*opcode*/, bool /*doAlsoTrackingOpt*/) {}
71
72} // namespace TestStatistics
73} // namespace RooFit
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.
bool addTyped(const RooAbsCollection &list, bool silent=false)
Adds elements of a given RooAbsCollection to the container if they match the specified type.
Abstract interface for all probability density functions.
Definition RooAbsPdf.h:40
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
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
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 CodegenImpl.h:64
A part of some range delimited by two fractional points between 0 and 1 (inclusive).
Definition RooAbsL.h:65