Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooExponential.cxx
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitModels *
4 * @(#)root/roofit:$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/** \class RooExponential
18 \ingroup Roofit
19
20Exponential PDF. It computes
21\f[
22 \mathrm{RooExponential}(x, c) = \mathcal{N} \cdot \exp(c\cdot x),
23\f]
24where \f$ \mathcal{N} \f$ is a normalisation constant that depends on the
25range and values of the arguments.
26**/
27
28#include "RooExponential.h"
29
30#include "RooRealVar.h"
31#include "RooBatchCompute.h"
32
34
35#include <algorithm>
36#include <cmath>
37
39
40////////////////////////////////////////////////////////////////////////////////
41
42RooExponential::RooExponential(const char *name, const char *title, RooAbsReal &variable, RooAbsReal &coefficient,
43 bool negateCoefficient)
44 : RooAbsPdf{name, title},
45 x{"x", "Dependent", this, variable},
46 c{"c", "Exponent", this, coefficient},
47 _negateCoefficient{negateCoefficient}
48{
49}
50
51////////////////////////////////////////////////////////////////////////////////
52
54 : RooAbsPdf{other, name}, x{"x", this, other.x}, c{"c", this, other.c}, _negateCoefficient{other._negateCoefficient}
55{
56}
57
58////////////////////////////////////////////////////////////////////////////////
59
61{
62 double coef = c;
64 coef = -coef;
65 }
66 return std::exp(coef * x);
67}
68
69////////////////////////////////////////////////////////////////////////////////
70/// Compute multiple values of Exponential distribution.
72{
74 RooBatchCompute::compute(ctx.config(this), computer, ctx.output(), {ctx.at(x), ctx.at(c)});
75}
76
77Int_t RooExponential::getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char * /*rangeName*/) const
78{
79 if (matchArgs(allVars, analVars, x))
80 return 1;
81 if (matchArgs(allVars, analVars, c))
82 return 2;
83 return 0;
84}
85
86////////////////////////////////////////////////////////////////////////////////
87
88double RooExponential::analyticalIntegral(Int_t code, const char *rangeName) const
89{
90 assert(code == 1 || code == 2);
91
92 bool isOverX = code == 1;
93
94 double coef = c;
96 coef = -coef;
97 }
98
99 double constant = isOverX ? coef : x;
100 auto &integrand = isOverX ? x : c;
101
102 double min = integrand.min(rangeName);
103 double max = integrand.max(rangeName);
104
105 if (!isOverX && _negateCoefficient) {
106 std::swap(min, max);
107 min = -min;
108 max = -max;
109 }
110
112}
113
114////////////////////////////////////////////////////////////////////////////////
115
117{
118 // Build a call to the stateless exponential defined later.
119 std::string coef;
120 if (_negateCoefficient) {
121 coef += "-";
122 }
123 coef += ctx.getResult(c);
124 ctx.addResult(this, "std::exp(" + coef + " * " + ctx.getResult(x) + ")");
125}
126
127////////////////////////////////////////////////////////////////////////////////
128
129std::string RooExponential::buildCallToAnalyticIntegral(Int_t code, const char *rangeName,
131{
132 bool isOverX = code == 1;
133
134 std::string constant;
135 if (_negateCoefficient && isOverX) {
136 constant += "-";
137 }
138 constant += ctx.getResult(isOverX ? c : x);
139
140 auto &integrand = isOverX ? x : c;
141
142 double min = integrand.min(rangeName);
143 double max = integrand.max(rangeName);
144
145 if (!isOverX && _negateCoefficient) {
146 std::swap(min, max);
147 min = -min;
148 max = -max;
149 }
150
151 return ctx.buildCall("RooFit::Detail::AnalyticalIntegrals::exponentialIntegral", min, max, constant);
152}
#define c(i)
Definition RSha256.hxx:101
#define ClassImp(name)
Definition Rtypes.h:377
char name[80]
Definition TGX11.cxx:110
Abstract interface for all probability density functions.
Definition RooAbsPdf.h:40
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:59
bool matchArgs(const RooArgSet &allDeps, RooArgSet &numDeps, const RooArgProxy &a) const
Utility function for use in getAnalyticalIntegral().
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
Exponential PDF.
void doEval(RooFit::EvalContext &) const override
Compute multiple values of Exponential distribution.
RooRealProxy c
void translate(RooFit::Detail::CodeSquashContext &ctx) const override
This function defines a translation for each RooAbsReal based object that can be used to express the ...
double analyticalIntegral(Int_t code, const char *rangeName=nullptr) const override
Implements the actual analytical integral(s) advertised by getAnalyticalIntegral.
std::string buildCallToAnalyticIntegral(Int_t code, const char *rangeName, RooFit::Detail::CodeSquashContext &ctx) const override
This function defines the analytical integral translation for the class.
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
RooRealProxy x
Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName=nullptr) const override
Interface function getAnalyticalIntergral advertises the analytical integrals that are supported.
A class to maintain the context for squashing of RooFit models into code.
std::string buildCall(std::string const &funcname, Args_t const &...args)
Build the code to call the function with name funcname, passing some arguments.
void addResult(RooAbsArg const *key, std::string const &value)
A function to save an expression that includes/depends on the result of the input node.
std::string const & getResult(RooAbsArg const &arg)
Gets the result for the given node using the node name.
std::span< double > output()
RooBatchCompute::Config config(RooAbsArg const *arg) const
Double_t x[n]
Definition legend1.C:17
void compute(Config cfg, Computer comp, std::span< double > output, VarSpan vars, ArgSpan extraArgs={})
double exponentialIntegral(double xMin, double xMax, double constant)