Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooPoisson.cxx
Go to the documentation of this file.
1 /*****************************************************************************
2 * Project: RooFit *
3 * *
4 * Simple Poisson PDF
5 * author: Kyle Cranmer <cranmer@cern.ch>
6 * *
7 *****************************************************************************/
8
9/** \class RooPoisson
10 \ingroup Roofit
11
12Poisson pdf
13**/
14
15#include "RooPoisson.h"
16#include "RooRandom.h"
17#include "RooMath.h"
18#include "RooNaNPacker.h"
19#include "RooBatchCompute.h"
20
24
25#include <array>
26
28
29////////////////////////////////////////////////////////////////////////////////
30/// Constructor
31
32RooPoisson::RooPoisson(const char *name, const char *title,
34 RooAbsReal::Ref _mean,
35 bool noRounding) :
36 RooAbsPdf(name,title),
37 x("x","x",this,_x),
38 mean("mean","mean",this,_mean),
39 _noRounding(noRounding)
40{
41}
42
43////////////////////////////////////////////////////////////////////////////////
44/// Copy constructor
45
46 RooPoisson::RooPoisson(const RooPoisson& other, const char* name) :
47 RooAbsPdf(other,name),
48 x("x",this,other.x),
49 mean("mean",this,other.mean),
50 _noRounding(other._noRounding),
51 _protectNegative(other._protectNegative)
52{
53}
54
55////////////////////////////////////////////////////////////////////////////////
56/// Implementation in terms of the TMath::Poisson() function.
57
59{
60 double k = _noRounding ? x : floor(x);
61 if(_protectNegative && mean<0) {
63 np.setPayload(-mean);
64 return np._payload;
65 }
67}
68
70{
71 std::string xName = ctx.getResult(x);
72 if (!_noRounding)
73 xName = "std::floor(" + xName + ")";
74
75 ctx.addResult(this, ctx.buildCall("RooFit::Detail::EvaluateFuncs::poissonEvaluate", xName, mean));
76}
77
78////////////////////////////////////////////////////////////////////////////////
79/// Compute multiple values of the Poisson distribution.
81{
82 std::array<double, 2> extraArgs{static_cast<double>(_protectNegative), static_cast<double>(_noRounding)};
83 RooBatchCompute::compute(ctx.config(this), RooBatchCompute::Poisson, ctx.output(), {ctx.at(x), ctx.at(mean)},
84 extraArgs);
85}
86
87////////////////////////////////////////////////////////////////////////////////
88
89Int_t RooPoisson::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* /*rangeName*/) const
90{
91 if (matchArgs(allVars,analVars,x)) return 1 ;
92 if (matchArgs(allVars, analVars, mean)) return 2;
93 return 0 ;
94}
95
96////////////////////////////////////////////////////////////////////////////////
97
98double RooPoisson::analyticalIntegral(Int_t code, const char* rangeName) const
99{
100 R__ASSERT(code == 1 || code == 2) ;
101
102 RooRealProxy const &integrand = code == 1 ? x : mean;
104 code, mean, _noRounding ? x : std::floor(x), integrand.min(rangeName), integrand.max(rangeName), _protectNegative);
105}
106
107std::string
109{
110 R__ASSERT(code == 1 || code == 2);
111 std::string xName = ctx.getResult(x);
112 if (!_noRounding)
113 xName = "std::floor(" + xName + ")";
114
115 RooRealProxy const &integrand = code == 1 ? x : mean;
116 // Since the integral function is the same for both codes, we need to make sure the indexed observables do not appear
117 // in the function if they are not required.
118 xName = code == 1 ? "0" : xName;
119 return ctx.buildCall("RooFit::Detail::AnalyticalIntegrals::poissonIntegral", code, mean, xName,
120 integrand.min(rangeName), integrand.max(rangeName), _protectNegative);
121}
122
123////////////////////////////////////////////////////////////////////////////////
124/// Advertise internal generator in x
125
126Int_t RooPoisson::getGenerator(const RooArgSet& directVars, RooArgSet &generateVars, bool /*staticInitOK*/) const
127{
128 if (matchArgs(directVars,generateVars,x)) return 1 ;
129 return 0 ;
130}
131
132////////////////////////////////////////////////////////////////////////////////
133/// Implement internal generator using TRandom::Poisson
134
136{
137 R__ASSERT(code==1) ;
138 double xgen ;
139 while(true) {
141 if (xgen<=x.max() && xgen>=x.min()) {
142 x = xgen ;
143 break;
144 }
145 }
146 return;
147}
#define ClassImp(name)
Definition Rtypes.h:377
#define R__ASSERT(e)
Definition TError.h:118
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t np
char name[80]
Definition TGX11.cxx:110
Abstract interface for all probability density functions.
Definition RooAbsPdf.h:40
A RooAbsReal::Ref can be constructed from a RooAbsReal& or a double that will be implicitly converted...
Definition RooAbsReal.h:68
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
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
Poisson pdf.
Definition RooPoisson.h:19
RooRealProxy x
Definition RooPoisson.h:54
bool _noRounding
Definition RooPoisson.h:56
double analyticalIntegral(Int_t code, const char *rangeName=nullptr) const override
Implements the actual analytical integral(s) advertised by getAnalyticalIntegral.
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 ...
bool _protectNegative
Definition RooPoisson.h:57
void generateEvent(Int_t code) override
Implement internal generator using TRandom::Poisson.
void doEval(RooFit::EvalContext &) const override
Compute multiple values of the Poisson distribution.
Int_t getGenerator(const RooArgSet &directVars, RooArgSet &generateVars, bool staticInitOK=true) const override
Advertise internal generator in x.
double evaluate() const override
Implementation in terms of the TMath::Poisson() function.
RooRealProxy mean
Definition RooPoisson.h:55
std::string buildCallToAnalyticIntegral(int code, const char *rangeName, RooFit::Detail::CodeSquashContext &ctx) const override
This function defines the analytical integral translation for the class.
Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName=nullptr) const override
Interface function getAnalyticalIntergral advertises the analytical integrals that are supported.
static TRandom * randomGenerator()
Return a pointer to a singleton random-number generator implementation.
Definition RooRandom.cxx:48
double max(const char *rname=nullptr) const
Query upper limit of range. This requires the payload to be RooAbsRealLValue or derived.
double min(const char *rname=nullptr) const
Query lower limit of range. This requires the payload to be RooAbsRealLValue or derived.
virtual ULong64_t Poisson(Double_t mean)
Generates a random integer N according to a Poisson law.
Definition TRandom.cxx:404
Double_t x[n]
Definition legend1.C:17
void compute(Config cfg, Computer comp, std::span< double > output, VarSpan vars, ArgSpan extraArgs={})
double poissonIntegral(int code, double mu, double x, double integrandMin, double integrandMax, unsigned int protectNegative)
double poissonEvaluate(double x, double par)
Little struct that can pack a float into the unused bits of the mantissa of a NaN double.