Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooRealSumFunc.cxx
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * @(#)root/roofitcore:$Id$
5 * Authors: *
6 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8 * *
9 * Copyright (c) 2000-2005, Regents of the University of California *
10 * and Stanford University. All rights reserved. *
11 * *
12 * Redistribution and use in source and binary forms, *
13 * with or without modification, are permitted according to the terms *
14 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15 *****************************************************************************/
16
17//////////////////////////////////////////////////////////////////////////////
18///
19/// Class RooRealSumFunc implements a PDF constructed from a sum of
20/// functions:
21/// ```
22/// Sum(i=1,n-1) coef_i * func_i(x) + [ 1 - (Sum(i=1,n-1) coef_i ] * func_n(x)
23/// pdf(x) = ------------------------------------------------------------------------------
24/// Sum(i=1,n-1) coef_i * Int(func_i)dx + [ 1 - (Sum(i=1,n-1) coef_i ] * Int(func_n)dx
25///
26/// ```
27/// where coef_i and func_i are RooAbsReal objects, and x is the collection of dependents.
28/// In the present version coef_i may not depend on x, but this limitation may be removed in the future
29///
30/// ### Difference between RooAddPdf / RooRealSum{Func|Pdf}
31/// - RooAddPdf is a PDF of PDFs, *i.e.* its components need to be normalised and non-negative.
32/// - RooRealSumPdf is a PDF of functions, *i.e.*, its components can be negative, but their sum cannot be. The normalisation
33/// is computed automatically, unless the PDF is extended (see above).
34/// - RooRealSumFunc is a sum of functions. It is neither normalised, nor need it be positive.
35
36#include "RooRealSumFunc.h"
37#include "RooRealSumPdf.h"
38#include "RooTrace.h"
39
41
43
44//_____________________________________________________________________________
45RooRealSumFunc::RooRealSumFunc() : _normIntMgr(this, 10)
46{
47 // Default constructor
48 // coverity[UNINIT_CTOR]
50}
51
52//_____________________________________________________________________________
53RooRealSumFunc::RooRealSumFunc(const char *name, const char *title)
54 : RooAbsReal(name, title), _normIntMgr(this, 10), _haveLastCoef(false),
55 _funcList("!funcList", "List of functions", this), _coefList("!coefList", "List of coefficients", this)
56{
57 // Constructor with name and title
59}
60
61//_____________________________________________________________________________
62RooRealSumFunc::RooRealSumFunc(const char *name, const char *title, RooAbsReal &func1, RooAbsReal &func2,
63 RooAbsReal &coef1)
64 : RooRealSumFunc{name, title}
65{
66 // Construct p.d.f consisting of coef1*func1 + (1-coef1)*func2
67 // The input coefficients and functions are allowed to be negative
68 // but the resulting sum is not, which is enforced at runtime
69
70 // Special constructor with two functions and one coefficient
71
72 _funcList.add(func1);
73 _funcList.add(func2);
74 _coefList.add(coef1);
76}
77
78//_____________________________________________________________________________
79RooRealSumFunc::RooRealSumFunc(const char *name, const char *title, const RooArgList &inFuncList,
80 const RooArgList &inCoefList)
81 : RooRealSumFunc{name, title}
82{
83 // Constructor p.d.f implementing sum_i [ coef_i * func_i ], if N_coef==N_func
84 // or sum_i [ coef_i * func_i ] + (1 - sum_i [ coef_i ] )* func_N if Ncoef==N_func-1
85 //
86 // All coefficients and functions are allowed to be negative
87 // but the sum is not, which is enforced at runtime.
88
89 RooRealSumPdf::initializeFuncsAndCoefs(*this, inFuncList, inCoefList, _funcList, _coefList);
90
92}
93
94//_____________________________________________________________________________
96 : RooAbsReal(other, name), _normIntMgr(other._normIntMgr, this), _haveLastCoef(other._haveLastCoef),
97 _funcList("!funcList", this, other._funcList), _coefList("!coefList", this, other._coefList),
98 _doFloor(other._doFloor)
99{
100 // Copy constructor
101
103}
104
105//_____________________________________________________________________________
107{
109}
110
111//_____________________________________________________________________________
113{
115}
116
117//_____________________________________________________________________________
119{
121}
122
123//_____________________________________________________________________________
125 const char *rangeName) const
126{
127 return RooRealSumPdf::getAnalyticalIntegralWN(*this, _normIntMgr, _funcList, _coefList, allVars, analVars, normSet2, rangeName);
128}
129
130//_____________________________________________________________________________
131double RooRealSumFunc::analyticalIntegralWN(Int_t code, const RooArgSet *normSet2, const char *rangeName) const
132{
133 return RooRealSumPdf::analyticalIntegralWN(*this, _normIntMgr, _funcList, _coefList, code, normSet2, rangeName, _haveWarned);
134}
135
136//_____________________________________________________________________________
137std::list<double> *RooRealSumFunc::binBoundaries(RooAbsRealLValue &obs, double xlo, double xhi) const
138{
139 return RooRealSumPdf::binBoundaries(_funcList, obs, xlo, xhi);
140}
141
142//_____________________________________________________________________________B
144{
146}
147
148//_____________________________________________________________________________
149std::list<double> *RooRealSumFunc::plotSamplingHint(RooAbsRealLValue &obs, double xlo, double xhi) const
150{
151 return RooRealSumPdf::plotSamplingHint(_funcList, obs, xlo, xhi);
152}
153
154//_____________________________________________________________________________
156{
158}
159
160/// Customized printing of arguments of a RooRealSumFunc to more intuitively
161/// reflect the contents of the product operator construction.
162
163void RooRealSumFunc::printMetaArgs(std::ostream &os) const
164{
166}
167
168std::unique_ptr<RooAbsArg> RooRealSumFunc::compileForNormSet(RooArgSet const &/*normSet*/, RooFit::Detail::CompileContext & ctx) const
169{
170 auto newArg = std::unique_ptr<RooAbsArg>{static_cast<RooAbsArg *>(Clone())};
171 ctx.markAsCompiled(*newArg);
172 ctx.compileServers(*newArg, {});
173 return newArg;
174}
#define TRACE_DESTROY
Definition RooTrace.h:24
#define TRACE_CREATE
Definition RooTrace.h:23
#define ClassImp(name)
Definition Rtypes.h:382
char name[80]
Definition TGX11.cxx:110
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:77
TObject * Clone(const char *newname=nullptr) const override
Make a clone of an object using the Streamer facility.
Definition RooAbsArg.h:89
Abstract base class for objects that represent a real value that may appear on the left hand side of ...
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:59
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
bool add(const RooAbsArg &var, bool valueServer, bool shapeServer, bool silent)
Overloaded RooCollection_t::add() method insert object into set and registers object as server to own...
void markAsCompiled(RooAbsArg &arg) const
void compileServers(RooAbsArg &arg, RooArgSet const &normSet)
std::list< double > * binBoundaries(RooAbsRealLValue &, double, double) const override
Retrieve bin boundaries if this distribution is binned in obs.
void printMetaArgs(std::ostream &os) const override
Customized printing of arguments of a RooRealSumFunc to more intuitively reflect the contents of the ...
Int_t getAnalyticalIntegralWN(RooArgSet &allVars, RooArgSet &numVars, const RooArgSet *normSet, const char *rangeName=nullptr) const override
Variant of getAnalyticalIntegral that is also passed the normalization set that should be applied to ...
double analyticalIntegralWN(Int_t code, const RooArgSet *normSet, const char *rangeName=nullptr) const override
Implements the actual analytical integral(s) advertised by getAnalyticalIntegral.
bool _doFloor
Introduce floor at zero in pdf.
~RooRealSumFunc() override
RooListProxy _funcList
List of component FUNCs.
RooObjCacheManager _normIntMgr
static bool _doFloorGlobal
Global flag for introducing floor at zero in pdf.
std::unique_ptr< RooAbsArg > compileForNormSet(RooArgSet const &normSet, RooFit::Detail::CompileContext &ctx) const override
RooListProxy _coefList
List of coefficients.
bool isBinnedDistribution(const RooArgSet &obs) const override
Tests if the distribution is binned. Unless overridden by derived classes, this always returns false.
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
bool checkObservables(const RooArgSet *nset) const override
Overloadable function in which derived classes can implement consistency checks of the variables.
void setCacheAndTrackHints(RooArgSet &) override
std::list< double > * plotSamplingHint(RooAbsRealLValue &, double, double) const override
Interface for returning an optional hint for initial sampling points when constructing a curve projec...
void setCacheAndTrackHints(RooArgSet &) override
Label OK'ed components of a RooRealSumPdf with cache-and-track.
bool checkObservables(const RooArgSet *nset) const override
Check if FUNC is valid for given normalization set.
std::list< double > * plotSamplingHint(RooAbsRealLValue &, double, double) const override
Interface for returning an optional hint for initial sampling points when constructing a curve projec...
double evaluate() const override
Calculate the current value.
std::list< double > * binBoundaries(RooAbsRealLValue &, double, double) const override
Retrieve bin boundaries if this distribution is binned in obs.
void printMetaArgs(std::ostream &os) const override
Customized printing of arguments of a RooRealSumPdf to more intuitively reflect the contents of the p...
Int_t getAnalyticalIntegralWN(RooArgSet &allVars, RooArgSet &numVars, const RooArgSet *normSet, const char *rangeName=nullptr) const override
Advertise that all integrals can be handled internally.
double analyticalIntegralWN(Int_t code, const RooArgSet *normSet, const char *rangeName=nullptr) const override
Implement analytical integrations by deferring integration of component functions to integrators of c...
static void initializeFuncsAndCoefs(RooAbsReal const &caller, const RooArgList &inFuncList, const RooArgList &inCoefList, RooArgList &funcList, RooArgList &coefList)
bool isBinnedDistribution(const RooArgSet &obs) const override
Check if all components that depend on obs are binned.