-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[RF] New PDF: gaussian with double sided exponential tails #17976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4a36987
[RF] New PDF: gaussian with double sided exponential tails
ferdymercury 35182af
Apply suggestions from code review
ferdymercury cc32ecf
Apply suggestions from code review
ferdymercury 0e733ff
Update RooGaussExpTails.cxx
ferdymercury 7518a0b
Apply suggestions from code review
ferdymercury 71723e7
Apply suggestions from code review
ferdymercury 7e05af7
Update RooGaussExpTails.cxx
ferdymercury ad1001b
Update RooGaussExpTails.h
ferdymercury 02d3e8a
Apply suggestions from code review
ferdymercury 69b6d9f
Update RooGaussExpTails.h
ferdymercury File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#ifndef RooFit_RooFit_RooGaussExpTails_h | ||
#define RooFit_RooFit_RooGaussExpTails_h | ||
|
||
#include "RooAbsPdf.h" | ||
#include "RooRealProxy.h" | ||
|
||
class RooAbsReal; | ||
|
||
class RooGaussExpTails : public RooAbsPdf { | ||
public: | ||
RooGaussExpTails() {} | ||
RooGaussExpTails(const char *name, const char *title, RooAbsReal::Ref x, RooAbsReal::Ref x0, RooAbsReal::Ref sigma, | ||
RooAbsReal::Ref kL, RooAbsReal::Ref kH); | ||
RooGaussExpTails(const RooGaussExpTails &other, const char *name = nullptr); | ||
TObject *clone(const char *newname) const override { return new RooGaussExpTails(*this, newname); } | ||
|
||
Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName = nullptr) const override; | ||
double analyticalIntegral(Int_t code, const char *rangeName = nullptr) const override; | ||
|
||
RooAbsReal const &x() const { return *_x; } | ||
RooAbsReal const &x0() const { return *_x0; } | ||
RooAbsReal const &sigma() const { return *_sigma; } | ||
RooAbsReal const &kL() const { return *_kL; } | ||
RooAbsReal const &kH() const { return *_kH; } | ||
|
||
protected: | ||
double evaluate() const override; | ||
|
||
private: | ||
RooRealProxy _x; | ||
RooRealProxy _x0; | ||
RooRealProxy _sigma; | ||
RooRealProxy _kL; | ||
RooRealProxy _kH; | ||
|
||
private: | ||
ClassDefOverride(RooGaussExpTails, 1) // Gaussian with double-sided exponential tails PDF, see https://arxiv.org/abs/1603.08591v1 | ||
}; | ||
|
||
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/** \class RooGaussExpTails | ||
\ingroup Roofit | ||
|
||
PDF implementing a Gaussian core + double-sided exponential tail distribution | ||
\author Souvik Das (8/1/2013) Initial implementation and | ||
Giovanni Marchiori (30/3/2016) Implemented analytic integral | ||
\see http://arxiv.org/pdf/1603.08591v1.pdf, https://github.com/mpuccio/RooCustomPdfs/blob/master/RooGausDExp.cxx, https://doi.org/10.1142/S0217751X14300440 | ||
\note To use the one-sided version, just set the opposite parameter k to a very large value | ||
*/ | ||
|
||
|
||
#include "RooGaussExpTails.h" | ||
#include "RooAbsReal.h" | ||
#include <cmath> | ||
#include "Math/ProbFuncMathCore.h" | ||
|
||
//_____________________________________________________________________________ | ||
RooGaussExpTails::RooGaussExpTails(const char *name, const char *title, RooAbsReal::Ref x, RooAbsReal::Ref x0, | ||
RooAbsReal::Ref sigma, RooAbsReal::Ref kL, RooAbsReal::Ref kH) | ||
: RooAbsPdf(name, title), | ||
_x("x", "x", this, x), | ||
_x0("x0", "x0", this, x0), | ||
_sigma("sigma", "sigma", this, sigma), | ||
_kL("kL", "kL", this, kL), | ||
_kH("kH", "kH", this, kH) | ||
{ | ||
} | ||
|
||
//_____________________________________________________________________________ | ||
RooGaussExpTails::RooGaussExpTails(const RooGaussExpTails &other, const char* name) | ||
: RooAbsPdf(other, name), | ||
_x("x", this, other._x), | ||
_x0("x0", this, other._x0), | ||
_sigma("sigma", this, other._sigma), | ||
_kL("kL", this, other._kL), | ||
_kH("kH", this, other._kH) | ||
{ | ||
} | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
namespace { | ||
|
||
inline double gaussianIntegral(double tmin, double tmax) | ||
{ | ||
constexpr double m_sqrt_2_pi = 2.50662827463; // std::sqrt(TMath::TwoPi()) | ||
return m_sqrt_2_pi * (ROOT::Math::gaussian_cdf(tmax) - ROOT::Math::gaussian_cdf(tmin)); | ||
} | ||
|
||
inline double tailIntegral(double tmin, double tmax, double k) | ||
{ | ||
double a = std::exp(0.5 * k * k) / k; | ||
return a * (std::exp(k * tmax) - std::exp(k * tmin)); | ||
} | ||
|
||
} // namespace | ||
|
||
//_____________________________________________________________________________ | ||
Double_t RooGaussExpTails::evaluate() const | ||
{ | ||
Double_t t = (_x - _x0) / _sigma; | ||
|
||
if (t <= -_kL) | ||
return std::exp(0.5 * _kL * _kL + _kL * t); | ||
else if (t > _kH) | ||
return std::exp(0.5 * _kH * _kH - _kH * t); | ||
else | ||
return std::exp(-0.5 * t * t); | ||
} | ||
|
||
ferdymercury marked this conversation as resolved.
Show resolved
Hide resolved
|
||
//_____________________________________________________________________________ | ||
Int_t RooGaussExpTails::getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char * /*rangeName*/) const | ||
{ | ||
if (matchArgs(allVars, analVars, _x)) | ||
return 1; | ||
|
||
return 0; | ||
} | ||
|
||
ferdymercury marked this conversation as resolved.
Show resolved
Hide resolved
|
||
//_____________________________________________________________________________ | ||
Double_t RooGaussExpTails::analyticalIntegral(Int_t code, const char *rangeName) const | ||
{ | ||
R__ASSERT(code == 1); | ||
double result = 0; | ||
|
||
double sig = std::abs((Double_t)_sigma); | ||
double tmin = (_x.min(rangeName) - _x0) / sig; | ||
double tmax = (_x.max(rangeName) - _x0) / sig; | ||
|
||
if (tmin <= -_kL) | ||
result += tailIntegral(tmin, std::min(tmax, -_kL), _kL); | ||
if (tmin <= _kH && tmax > -_kL) | ||
result += gaussianIntegral(std::max(tmin, -_kL), std::min(tmax, +_kH)); | ||
if (tmax > _kH) | ||
result += tailIntegral(std::max(tmin, +_kH), tmax, -_kH); | ||
|
||
return sig * result; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.