Logo ROOT  
Reference Guide
RooAbsL.h
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#ifndef ROOT_ROOFIT_TESTSTATISTICS_RooAbsL
14#define ROOT_ROOFIT_TESTSTATISTICS_RooAbsL
15
16#include "RooArgSet.h"
17#include "RooAbsArg.h" // enum ConstOpCode
18#include "RooAbsPdf.h"
19
20#include "Math/Util.h" // KahanSum
21
22#include <cstddef> // std::size_t
23#include <string>
24#include <memory>
25
26// forward declarations
27class RooAbsPdf;
28class RooAbsData;
29
30namespace RooFit {
31namespace TestStatistics {
32
33class RooAbsL {
34public:
35 enum class Extended { Auto, Yes, No };
36 static bool isExtendedHelper(RooAbsPdf *pdf, Extended extended);
37
38 /// Convenience wrapper class used to distinguish between pdf/data owning and non-owning constructors.
39 struct ClonePdfData {
42 };
43
44private:
45 RooAbsL(std::shared_ptr<RooAbsPdf> pdf, std::shared_ptr<RooAbsData> data, std::size_t N_events,
46 std::size_t N_components, Extended extended);
47
48public:
49 RooAbsL(RooAbsPdf *pdf, RooAbsData *data, std::size_t N_events, std::size_t N_components,
50 Extended extended = Extended::Auto);
51 RooAbsL(ClonePdfData in, std::size_t N_events, std::size_t N_components, Extended extended = Extended::Auto);
52 RooAbsL(const RooAbsL &other);
53 virtual ~RooAbsL() = default;
54
55 void initClones(RooAbsPdf &inpdf, RooAbsData &indata);
56
57 /// A part of some range delimited by two fractional points between 0 and 1 (inclusive).
58 struct Section {
60 {
61 if ((begin > end) || (begin < 0) || (end > 1)) {
62 throw std::domain_error("Invalid input values for section; begin must be >= 0, end <= 1 and begin < end.");
63 }
64 }
65
66 Section(const Section &section) = default;
67
68 std::size_t begin(std::size_t N_total) const { return static_cast<std::size_t>(N_total * begin_fraction); }
69
70 std::size_t end(std::size_t N_total) const
71 {
72 if (end_fraction == 1) {
73 return N_total;
74 } else {
75 return static_cast<std::size_t>(N_total * end_fraction);
76 }
77 }
78
81 };
82
83 /*
84 * \brief Evaluate (part of) the likelihood over a given range of events and components
85 *
86 * A fractional event range is used because components may have different numbers of events. For a
87 * multi-component RooSumL, for instance, this means the caller need not indicate for each component which event
88 * ranges they want to evaluate, but can just pass one overall fractional range.
89 *
90 * \param[in] events The fractional event range.
91 * \param[in] components_begin The first component to be calculated.
92 * \param[in] components_end The *exclusive* upper limit to the range of components to be calculated, i.e. the
93 * component *before this one* is the last to be included. \return The value of part of the negative log likelihood,
94 * returned as a KahanSum object which also includes a carry term.
95 */
97 evaluatePartition(Section events, std::size_t components_begin, std::size_t components_end) = 0;
98
99 // necessary from MinuitFcnGrad to reach likelihood properties:
100 virtual RooArgSet *getParameters();
101
102 /// \brief Interface function signaling a request to perform constant term optimization.
103 ///
104 /// The default implementation takes no action other than to forward the calls to all servers. May be overridden in
105 /// likelihood classes without a cached dataset, like RooSubsidiaryL.
106 virtual void constOptimizeTestStatistic(RooAbsArg::ConstOpCode opcode, bool doAlsoTrackingOpt);
107
108 virtual std::string GetName() const;
109 virtual std::string GetTitle() const;
110 virtual std::string GetInfo() const { return GetClassName() + "::" + pdf_->GetName(); }
111 virtual std::string GetClassName() const = 0;
112
113 // necessary in RooMinimizer (via LikelihoodWrapper)
114 inline virtual double defaultErrorLevel() const { return 0.5; }
115
116 // necessary in LikelihoodJob
117 /// Number of dataset entries. Typically equal to the number of dataset events, except in RooSubsidiaryL, which has
118 /// no events.
119 virtual std::size_t numDataEntries() const;
120 inline std::size_t getNEvents() const { return N_events_; }
121 inline std::size_t getNComponents() const { return N_components_; }
122 inline bool isExtended() const { return extended_; }
123 inline void setSimCount(std::size_t value) { sim_count_ = value; }
124
125protected:
126 // Note: pdf_ and data_ can be constructed in two ways, one of which implies ownership and the other does not.
127 // Inspired by this: https://stackoverflow.com/a/61227865/1199693.
128 // The owning variant is used for classes that need a pdf/data clone (RooBinnedL and RooUnbinnedL), whereas the
129 // non-owning version is used for when a reference to the external pdf/dataset is good enough (RooSumL).
130 // This means that pdf_ and data_ are not meant to actually be shared! If there were a unique_ptr with optional
131 // ownership, we would have used that instead.
132 std::shared_ptr<RooAbsPdf> pdf_;
133 std::shared_ptr<RooAbsData> data_;
134 std::unique_ptr<RooArgSet> normSet_; ///< Pointer to set with observables used for normalization
135
136 std::size_t N_events_ = 1;
137 std::size_t N_components_ = 1;
138
139 bool extended_ = false;
140
141 std::size_t sim_count_ = 1; // Total number of component p.d.f.s in RooSimultaneous (if any)
142};
143
144} // namespace TestStatistics
145} // namespace RooFit
146
147#endif // ROOT_ROOFIT_TESTSTATISTICS_RooAbsL
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:62
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:57
virtual double defaultErrorLevel() const
Definition: RooAbsL.h:114
std::shared_ptr< RooAbsData > data_
Definition: RooAbsL.h:133
std::size_t getNComponents() const
Definition: RooAbsL.h:121
virtual std::string GetClassName() const =0
virtual ROOT::Math::KahanSum< double > evaluatePartition(Section events, std::size_t components_begin, std::size_t components_end)=0
static bool isExtendedHelper(RooAbsPdf *pdf, Extended extended)
Definition: RooAbsL.cxx:34
virtual std::string GetInfo() const
Definition: RooAbsL.h:110
virtual std::string GetName() const
Definition: RooAbsL.cxx:235
virtual std::string GetTitle() const
Definition: RooAbsL.cxx:242
std::unique_ptr< RooArgSet > normSet_
Pointer to set with observables used for normalization.
Definition: RooAbsL.h:134
void initClones(RooAbsPdf &inpdf, RooAbsData &indata)
Definition: RooAbsL.cxx:109
virtual void constOptimizeTestStatistic(RooAbsArg::ConstOpCode opcode, bool doAlsoTrackingOpt)
Interface function signaling a request to perform constant term optimization.
Definition: RooAbsL.cxx:227
void setSimCount(std::size_t value)
Definition: RooAbsL.h:123
RooAbsL(std::shared_ptr< RooAbsPdf > pdf, std::shared_ptr< RooAbsData > data, std::size_t N_events, std::size_t N_components, Extended extended)
After handling cloning (or not) of the pdf and dataset, the public constructors call this private con...
Definition: RooAbsL.cxx:53
virtual RooArgSet * getParameters()
Definition: RooAbsL.cxx:221
virtual std::size_t numDataEntries() const
Number of dataset entries.
Definition: RooAbsL.cxx:249
std::size_t getNEvents() const
Definition: RooAbsL.h:120
std::shared_ptr< RooAbsPdf > pdf_
Definition: RooAbsL.h:132
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition: Common.h:18
Convenience wrapper class used to distinguish between pdf/data owning and non-owning constructors.
Definition: RooAbsL.h:39
A part of some range delimited by two fractional points between 0 and 1 (inclusive).
Definition: RooAbsL.h:58
std::size_t begin(std::size_t N_total) const
Definition: RooAbsL.h:68
Section(const Section &section)=default
std::size_t end(std::size_t N_total) const
Definition: RooAbsL.h:70
Section(double begin, double end)
Definition: RooAbsL.h:59