Logo ROOT  
Reference Guide
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
118//_____________________________________________________________________________
120{
122}
123
124//_____________________________________________________________________________
126 const char *rangeName) const
127{
128 return RooRealSumPdf::getAnalyticalIntegralWN(*this, _normIntMgr, _funcList, _coefList, allVars, analVars, normSet2, rangeName);
129}
130
131//_____________________________________________________________________________
132double RooRealSumFunc::analyticalIntegralWN(Int_t code, const RooArgSet *normSet2, const char *rangeName) const
133{
134 return RooRealSumPdf::analyticalIntegralWN(*this, _normIntMgr, _funcList, _coefList, code, normSet2, rangeName, _haveWarned);
135}
136
137//_____________________________________________________________________________
138std::list<double> *RooRealSumFunc::binBoundaries(RooAbsRealLValue &obs, double xlo, double xhi) const
139{
140 return RooRealSumPdf::binBoundaries(_funcList, obs, xlo, xhi);
141}
142
143//_____________________________________________________________________________B
145{
147}
148
149//_____________________________________________________________________________
150std::list<double> *RooRealSumFunc::plotSamplingHint(RooAbsRealLValue &obs, double xlo, double xhi) const
151{
152 return RooRealSumPdf::plotSamplingHint(_funcList, obs, xlo, xhi);
153}
154
155//_____________________________________________________________________________
157{
159}
160
161/// Customized printing of arguments of a RooRealSumFunc to more intuitively
162/// reflect the contents of the product operator construction.
163
164void RooRealSumFunc::printMetaArgs(std::ostream &os) const
165{
167}
#define TRACE_DESTROY
Definition: RooTrace.h:24
#define TRACE_CREATE
Definition: RooTrace.h:23
#define ClassImp(name)
Definition: Rtypes.h:375
char name[80]
Definition: TGX11.cxx:110
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:62
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:56
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...
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.
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.