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 std::size_t begin(std::size_t N_total) const { return static_cast<std::size_t>(N_total * begin_fraction); }
67
68 std::size_t end(std::size_t N_total) const
69 {
70 if (end_fraction == 1) {
71 return N_total;
72 } else {
73 return static_cast<std::size_t>(N_total * end_fraction);
74 }
75 }
76
77 bool operator==(const Section& rhs) {
79 }
80
83 };
84
85 /*
86 * \brief Evaluate (part of) the likelihood over a given range of events and components
87 *
88 * A fractional event range is used because components may have different numbers of events. For a
89 * multi-component RooSumL, for instance, this means the caller need not indicate for each component which event
90 * ranges they want to evaluate, but can just pass one overall fractional range.
91 *
92 * \param[in] events The fractional event range.
93 * \param[in] components_begin The first component to be calculated.
94 * \param[in] components_end The *exclusive* upper limit to the range of components to be calculated, i.e. the
95 * component *before this one* is the last to be included. \return The value of part of the negative log likelihood,
96 * returned as a KahanSum object which also includes a carry term.
97 */
99 evaluatePartition(Section events, std::size_t components_begin, std::size_t components_end) = 0;
100
101 // necessary from MinuitFcnGrad to reach likelihood properties:
102 virtual RooArgSet *getParameters();
103
104 /// \brief Interface function signaling a request to perform constant term optimization.
105 ///
106 /// The default implementation takes no action other than to forward the calls to all servers. May be overridden in
107 /// likelihood classes without a cached dataset, like RooSubsidiaryL.
108 virtual void constOptimizeTestStatistic(RooAbsArg::ConstOpCode opcode, bool doAlsoTrackingOpt);
109
110 virtual std::string GetName() const;
111 virtual std::string GetTitle() const;
112 virtual std::string GetInfo() const { return GetClassName() + "::" + pdf_->GetName(); }
113 virtual std::string GetClassName() const = 0;
114
115 // necessary in RooMinimizer (via LikelihoodWrapper)
116 inline virtual double defaultErrorLevel() const { return 0.5; }
117
118 // necessary in LikelihoodJob
119 /// Number of dataset entries. Typically equal to the number of dataset events, except in RooSubsidiaryL, which has
120 /// no events.
121 virtual std::size_t numDataEntries() const;
122 inline std::size_t getNEvents() const { return N_events_; }
123 inline std::size_t getNComponents() const { return N_components_; }
124 inline bool isExtended() const { return extended_; }
125 inline void setSimCount(std::size_t value) { sim_count_ = value; }
126
127protected:
128 // Note: pdf_ and data_ can be constructed in two ways, one of which implies ownership and the other does not.
129 // Inspired by this: https://stackoverflow.com/a/61227865/1199693.
130 // The owning variant is used for classes that need a pdf/data clone (RooBinnedL and RooUnbinnedL), whereas the
131 // non-owning version is used for when a reference to the external pdf/dataset is good enough (RooSumL).
132 // This means that pdf_ and data_ are not meant to actually be shared! If there were a unique_ptr with optional
133 // ownership, we would have used that instead.
134 std::shared_ptr<RooAbsPdf> pdf_;
135 std::shared_ptr<RooAbsData> data_;
136 std::unique_ptr<RooArgSet> normSet_; ///< Pointer to set with observables used for normalization
137
138 std::size_t N_events_ = 1;
139 std::size_t N_components_ = 1;
140
141 bool extended_ = false;
142
143 std::size_t sim_count_ = 1; // Total number of component p.d.f.s in RooSimultaneous (if any)
144};
145
146} // namespace TestStatistics
147} // namespace RooFit
148
149#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:61
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:56
virtual double defaultErrorLevel() const
Definition: RooAbsL.h:116
std::shared_ptr< RooAbsData > data_
Definition: RooAbsL.h:135
std::size_t getNComponents() const
Definition: RooAbsL.h:123
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:112
virtual std::string GetName() const
Definition: RooAbsL.cxx:236
virtual std::string GetTitle() const
Definition: RooAbsL.cxx:243
std::unique_ptr< RooArgSet > normSet_
Pointer to set with observables used for normalization.
Definition: RooAbsL.h:136
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:228
void setSimCount(std::size_t value)
Definition: RooAbsL.h:125
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:222
virtual std::size_t numDataEntries() const
Number of dataset entries.
Definition: RooAbsL.cxx:250
std::size_t getNEvents() const
Definition: RooAbsL.h:122
std::shared_ptr< RooAbsPdf > pdf_
Definition: RooAbsL.h:134
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:66
std::size_t end(std::size_t N_total) const
Definition: RooAbsL.h:68
Section(double begin, double end)
Definition: RooAbsL.h:59
bool operator==(const Section &rhs)
Definition: RooAbsL.h:77