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#include "RooHelpers.h"
21
23
24#include <array>
25
26 ////////////////////////////////////////////////////////////////////////////////
27 /// Constructor
28
29 RooPoisson::RooPoisson(const char *name, const char *title, RooAbsReal::Ref _x, RooAbsReal::Ref _mean, bool noRounding)
30 : RooAbsPdf(name, title), x("x", "x", this, _x), mean("mean", "mean", this, _mean), _noRounding(noRounding)
31 {
32 RooHelpers::checkRangeOfParameters(this, {&static_cast<RooAbsReal &>(_x), &static_cast<RooAbsReal &>(_mean)}, 0.);
33}
34
35////////////////////////////////////////////////////////////////////////////////
36/// Copy constructor
37
40 x("x",this,other.x),
41 mean("mean",this,other.mean),
42 _noRounding(other._noRounding),
43 _protectNegative(other._protectNegative)
44{
45}
46
47////////////////////////////////////////////////////////////////////////////////
48/// Implementation in terms of the TMath::Poisson() function.
49
51{
52 double k = _noRounding ? x : floor(x);
53 if(_protectNegative && mean<0) {
55 np.setPayload(-mean);
56 return np._payload;
57 }
59}
60
61////////////////////////////////////////////////////////////////////////////////
62/// Compute multiple values of the Poisson distribution.
64{
65 std::array<double, 2> extraArgs{static_cast<double>(_protectNegative), static_cast<double>(_noRounding)};
66 RooBatchCompute::compute(ctx.config(this), RooBatchCompute::Poisson, ctx.output(), {ctx.at(x), ctx.at(mean)},
67 extraArgs);
68}
69
70////////////////////////////////////////////////////////////////////////////////
71
72Int_t RooPoisson::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* /*rangeName*/) const
73{
74 if (matchArgs(allVars,analVars,x)) return 1 ;
75 if (matchArgs(allVars, analVars, mean)) return 2;
76 return 0 ;
77}
78
79////////////////////////////////////////////////////////////////////////////////
80
81double RooPoisson::analyticalIntegral(Int_t code, const char* rangeName) const
82{
83 R__ASSERT(code == 1 || code == 2) ;
84
85 RooRealProxy const &integrand = code == 1 ? x : mean;
87 code, mean, _noRounding ? x : std::floor(x), integrand.min(rangeName), integrand.max(rangeName), _protectNegative);
88}
89
90////////////////////////////////////////////////////////////////////////////////
91/// Advertise internal generator in x
92
94{
95 if (matchArgs(directVars,generateVars,x)) return 1 ;
96 return 0 ;
97}
98
99////////////////////////////////////////////////////////////////////////////////
100/// Implement internal generator using TRandom::Poisson
101
103{
104 R__ASSERT(code==1) ;
105 double xgen ;
106 while(true) {
108 if (xgen<=x.max() && xgen>=x.min()) {
109 x = xgen ;
110 break;
111 }
112 }
113 return;
114}
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Definition TError.h:125
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:32
A RooAbsReal::Ref can be constructed from a RooAbsReal& or a double that will be implicitly converted...
Definition RooAbsReal.h:72
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:63
bool matchArgs(const RooArgSet &allDeps, RooArgSet &analDeps, const RooArgProxy &a, const Proxies &... proxies) const
Definition RooAbsReal.h:428
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
std::span< double > output()
RooBatchCompute::Config config(RooAbsArg const *arg) const
Poisson pdf.
Definition RooPoisson.h:19
RooRealProxy x
Definition RooPoisson.h:52
bool _noRounding
Definition RooPoisson.h:54
double analyticalIntegral(Int_t code, const char *rangeName=nullptr) const override
Implements the actual analytical integral(s) advertised by getAnalyticalIntegral.
bool _protectNegative
Definition RooPoisson.h:55
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:53
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:47
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.
Double_t x[n]
Definition legend1.C:17
void compute(Config cfg, Computer comp, std::span< double > output, VarSpan vars, ArgSpan extraArgs={})
double poisson(double x, double par)
Definition MathFuncs.h:226
double poissonIntegral(int code, double mu, double x, double integrandMin, double integrandMax, unsigned int protectNegative)
Definition MathFuncs.h:615
void checkRangeOfParameters(const RooAbsReal *callingClass, std::initializer_list< const RooAbsReal * > pars, double min=-std::numeric_limits< double >::max(), double max=std::numeric_limits< double >::max(), bool limitsInAllowedRange=false, std::string const &extraMessage="")
Check if the parameters have a range, and warn if the range extends below / above the set limits.
Little struct that can pack a float into the unused bits of the mantissa of a NaN double.