Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 "RooAbsPdf.h"
18
19#include "Math/Util.h" // KahanSum
20
21#include <cstddef> // std::size_t
22#include <string>
23#include <memory>
24
25// forward declarations
26class RooAbsPdf;
27class RooAbsData;
28
29namespace RooFit {
30namespace TestStatistics {
31
32class RooAbsL {
33public:
34 enum class Extended { Auto, Yes, No };
35 static bool isExtendedHelper(RooAbsPdf *pdf, Extended extended);
36
37 /// Convenience wrapper class used to distinguish between pdf/data owning and non-owning constructors.
39 public:
41 ClonePdfData(std::unique_ptr<RooAbsPdf> inPdf, RooAbsData *inData)
42 : pdf{inPdf.get()}, data{inData}, ownedPdf{std::move(inPdf)}
43 {
44 }
45 RooAbsPdf *pdf = nullptr;
46 RooAbsData *data = nullptr;
47 std::shared_ptr<RooAbsPdf> ownedPdf;
48 };
49
50private:
51 RooAbsL(std::shared_ptr<RooAbsPdf> pdf, std::shared_ptr<RooAbsData> data, std::size_t N_events,
52 std::size_t N_components, Extended extended);
53
54public:
55 RooAbsL(RooAbsPdf *pdf, RooAbsData *data, std::size_t N_events, std::size_t N_components,
58 RooAbsL(const RooAbsL &other);
59 virtual ~RooAbsL() = default;
60
62
63 /// A part of some range delimited by two fractional points between 0 and 1 (inclusive).
64 struct Section {
66 {
67 if ((begin > end) || (begin < 0) || (end > 1)) {
68 throw std::domain_error("Invalid input values for section; begin must be >= 0, end <= 1 and begin < end.");
69 }
70 }
71
72 std::size_t begin(std::size_t N_total) const { return static_cast<std::size_t>(N_total * begin_fraction); }
73
74 std::size_t end(std::size_t N_total) const
75 {
76 if (end_fraction == 1) {
77 return N_total;
78 } else {
79 return static_cast<std::size_t>(N_total * end_fraction);
80 }
81 }
82
83 friend bool operator==(const Section &lhs, const Section &rhs)
84 {
85 return lhs.begin_fraction == rhs.begin_fraction && lhs.end_fraction == rhs.end_fraction;
86 }
87
90 };
91
92 /*
93 * \brief Evaluate (part of) the likelihood over a given range of events and components
94 *
95 * A fractional event range is used because components may have different numbers of events. For a
96 * multi-component RooSumL, for instance, this means the caller need not indicate for each component which event
97 * ranges they want to evaluate, but can just pass one overall fractional range.
98 *
99 * \param[in] events The fractional event range.
100 * \param[in] components_begin The first component to be calculated.
101 * \param[in] components_end The *exclusive* upper limit to the range of components to be calculated, i.e. the
102 * component *before this one* is the last to be included. \return The value of part of the negative log likelihood,
103 * returned as a KahanSum object which also includes a carry term.
104 */
106 evaluatePartition(Section events, std::size_t components_begin, std::size_t components_end) = 0;
107
108 // necessary from MinuitFcnGrad to reach likelihood properties:
109 virtual std::unique_ptr<RooArgSet> getParameters();
110
111 virtual std::string GetName() const;
112 virtual std::string GetTitle() const;
113 virtual std::string GetInfo() const { return GetClassName() + "::" + pdf_->GetName(); }
114 virtual std::string GetClassName() const = 0;
115
116 // necessary in RooMinimizer (via LikelihoodWrapper)
117 inline virtual double defaultErrorLevel() const { return 0.5; }
118
119 // necessary in LikelihoodJob
120 /// Number of dataset entries. Typically equal to the number of dataset events, except in RooSubsidiaryL, which has
121 /// no events.
122 virtual std::size_t numDataEntries() const;
123 inline std::size_t getNEvents() const { return N_events_; }
124 inline std::size_t getNComponents() const { return N_components_; }
125 inline bool isExtended() const { return extended_; }
126 inline void setSimCount(std::size_t value) { sim_count_ = value; }
127
128protected:
129 // Note: pdf_ and data_ can be constructed in two ways, one of which implies ownership and the other does not.
130 // Inspired by this: https://stackoverflow.com/a/61227865/1199693.
131 // The owning variant is used for classes that need a pdf/data clone (RooBinnedL and RooUnbinnedL), whereas the
132 // non-owning version is used for when a reference to the external pdf/dataset is good enough (RooSumL).
133 // This means that pdf_ and data_ are not meant to actually be shared! If there were a unique_ptr with optional
134 // ownership, we would have used that instead.
135 std::shared_ptr<RooAbsPdf> pdf_;
136 std::shared_ptr<RooAbsData> data_;
137 std::unique_ptr<RooArgSet> normSet_; ///< Pointer to set with observables used for normalization
138
139 std::size_t N_events_ = 1;
140 std::size_t N_components_ = 1;
141
142 bool extended_ = false;
143
144 std::size_t sim_count_ = 1; // Total number of component p.d.f.s in RooSimultaneous (if any)
145};
146
147} // namespace TestStatistics
148} // namespace RooFit
149
150#endif // ROOT_ROOFIT_TESTSTATISTICS_RooAbsL
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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
The Kahan summation is a compensated summation algorithm, which significantly reduces numerical error...
Definition Util.h:141
Abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:55
Abstract interface for all probability density functions.
Definition RooAbsPdf.h:32
Convenience wrapper class used to distinguish between pdf/data owning and non-owning constructors.
Definition RooAbsL.h:38
ClonePdfData(RooAbsPdf *inPdf, RooAbsData *inData)
Definition RooAbsL.h:40
std::shared_ptr< RooAbsPdf > ownedPdf
Definition RooAbsL.h:47
ClonePdfData(std::unique_ptr< RooAbsPdf > inPdf, RooAbsData *inData)
Definition RooAbsL.h:41
virtual double defaultErrorLevel() const
Definition RooAbsL.h:117
std::shared_ptr< RooAbsData > data_
Definition RooAbsL.h:136
std::size_t getNComponents() const
Definition RooAbsL.h:124
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:33
virtual std::string GetInfo() const
Definition RooAbsL.h:113
virtual std::string GetName() const
Definition RooAbsL.cxx:238
virtual std::string GetTitle() const
Definition RooAbsL.cxx:245
std::unique_ptr< RooArgSet > normSet_
Pointer to set with observables used for normalization.
Definition RooAbsL.h:137
void initClones(RooAbsPdf &inpdf, RooAbsData &indata)
Definition RooAbsL.cxx:123
virtual std::unique_ptr< RooArgSet > getParameters()
Definition RooAbsL.cxx:233
void setSimCount(std::size_t value)
Definition RooAbsL.h:126
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 std::size_t numDataEntries() const
Number of dataset entries.
Definition RooAbsL.cxx:252
std::size_t getNEvents() const
Definition RooAbsL.h:123
std::shared_ptr< RooAbsPdf > pdf_
Definition RooAbsL.h:135
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition CodegenImpl.h:73
A part of some range delimited by two fractional points between 0 and 1 (inclusive).
Definition RooAbsL.h:64
std::size_t begin(std::size_t N_total) const
Definition RooAbsL.h:72
std::size_t end(std::size_t N_total) const
Definition RooAbsL.h:74
friend bool operator==(const Section &lhs, const Section &rhs)
Definition RooAbsL.h:83
Section(double begin, double end)
Definition RooAbsL.h:65