Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooLandau.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 RooLandau
18 \ingroup Roofit
19
20Landau distribution p.d.f
21\image html RF_Landau.png "PDF of the Landau distribution."
22**/
23
24#include "RooLandau.h"
25#include "RooHelpers.h"
26#include "RooRandom.h"
27#include "RooBatchCompute.h"
28
30
31#include "TMath.h"
32#include "Math/ProbFunc.h"
33
35
36////////////////////////////////////////////////////////////////////////////////
37
38RooLandau::RooLandau(const char *name, const char *title, RooAbsReal::Ref _x, RooAbsReal::Ref _mean, RooAbsReal::Ref _sigma) :
39 RooAbsPdf(name,title),
40 x("x","Dependent",this,_x),
41 mean("mean","Mean",this,_mean),
42 sigma("sigma","Width",this,_sigma)
43{
44 RooHelpers::checkRangeOfParameters(this, {&static_cast<RooAbsReal&>(_sigma)}, 0.0);
45}
46
47////////////////////////////////////////////////////////////////////////////////
48
49RooLandau::RooLandau(const RooLandau& other, const char* name) :
50 RooAbsPdf(other,name),
51 x("x",this,other.x),
52 mean("mean",this,other.mean),
53 sigma("sigma",this,other.sigma)
54{
55}
56
57////////////////////////////////////////////////////////////////////////////////
58
59double RooLandau::evaluate() const
60{
62}
63
64////////////////////////////////////////////////////////////////////////////////
65
67{
68 ctx.addResult(this, ctx.buildCall("RooFit::Detail::MathFuncs::landau", x, mean, sigma));
69}
70
71////////////////////////////////////////////////////////////////////////////////
72/// Compute multiple values of Landau distribution.
74{
76 {ctx.at(x), ctx.at(mean), ctx.at(sigma)});
77}
78
79////////////////////////////////////////////////////////////////////////////////
80
81Int_t RooLandau::getGenerator(const RooArgSet& directVars, RooArgSet &generateVars, bool /*staticInitOK*/) const
82{
83 return matchArgs(directVars,generateVars,x) ? 1 : 0;
84}
85
86Int_t RooLandau::getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char * /*rangeName*/) const
87{
88 return matchArgs(allVars, analVars, x) ? 1 : 0;
89}
90
91Double_t RooLandau::analyticalIntegral(Int_t /*code*/, const char *rangeName) const
92{
93 // Don't do anything with "code". It can only be "1" anyway (see
94 // implementation of getAnalyticalIntegral).
95
96 const double meanVal = mean;
97 const double sigmaVal = sigma;
98
99 const double a = ROOT::Math::landau_cdf(x.max(rangeName), sigmaVal, meanVal);
100 const double b = ROOT::Math::landau_cdf(x.min(rangeName), sigmaVal, meanVal);
101 return sigmaVal * (a - b);
102}
103
104////////////////////////////////////////////////////////////////////////////////
105
106std::string RooLandau::buildCallToAnalyticIntegral(Int_t /*code*/, const char *rangeName,
108{
109 // Don't do anything with "code". It can only be "1" anyway (see
110 // implementation of getAnalyticalIntegral).
111 const std::string a = ctx.buildCall("ROOT::Math::landau_cdf", x.max(rangeName), sigma, mean);
112 const std::string b = ctx.buildCall("ROOT::Math::landau_cdf", x.min(rangeName), sigma, mean);
113 return ctx.getResult(sigma) + " * " + "(" + a + " - " + b + ")";
114}
115
116////////////////////////////////////////////////////////////////////////////////
117
119{
120 assert(1 == code); (void)code;
121 double xgen ;
122 while(true) {
124 if (xgen<x.max() && xgen>x.min()) {
125 x = xgen ;
126 break;
127 }
128 }
129 return;
130}
#define b(i)
Definition RSha256.hxx:100
#define a(i)
Definition RSha256.hxx:99
#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
A RooAbsReal::Ref can be constructed from a RooAbsReal& or a double that will be implicitly converted...
Definition RooAbsReal.h:68
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:24
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
Landau distribution p.d.f.
Definition RooLandau.h:24
Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName=nullptr) const override
Interface function getAnalyticalIntergral advertises the analytical integrals that are supported.
Definition RooLandau.cxx:86
void generateEvent(Int_t code) override
Interface for generation of an event using the algorithm corresponding to the specified code.
RooRealProxy x
Definition RooLandau.h:46
RooRealProxy sigma
Definition RooLandau.h:48
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 ...
Definition RooLandau.cxx:66
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
Definition RooLandau.cxx:59
void doEval(RooFit::EvalContext &) const override
Compute multiple values of Landau distribution.
Definition RooLandau.cxx:73
Int_t getGenerator(const RooArgSet &directVars, RooArgSet &generateVars, bool staticInitOK=true) const override
Load generatedVars with the subset of directVars that we can generate events for, and return a code t...
Definition RooLandau.cxx:81
RooRealProxy mean
Definition RooLandau.h:47
double analyticalIntegral(Int_t code, const char *rangeName) const override
Implements the actual analytical integral(s) advertised by getAnalyticalIntegral.
Definition RooLandau.cxx:91
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.
static TRandom * randomGenerator()
Return a pointer to a singleton random-number generator implementation.
Definition RooRandom.cxx:48
virtual Double_t Landau(Double_t mean=0, Double_t sigma=1)
Generate a random number following a Landau distribution with location parameter mu and scale paramet...
Definition TRandom.cxx:381
double landau_cdf(double x, double xi=1, double x0=0)
Cumulative distribution function of the Landau distribution (lower tail).
const Double_t sigma
Double_t x[n]
Definition legend1.C:17
void compute(Config cfg, Computer comp, std::span< double > output, VarSpan vars, ArgSpan extraArgs={})
double landau(double x, double mu, double sigma)
Definition MathFuncs.h:331
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.