Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooCBShape.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 RooCBShape
18 \ingroup Roofit
19
20PDF implementing the Crystal Ball line shape.
21**/
22
23#include "RooCBShape.h"
24
25#include "RooRealVar.h"
26#include "RooMath.h"
27#include "RooBatchCompute.h"
28
29#include "TMath.h"
30
31#include <cmath>
32
33using namespace std;
34
36
37////////////////////////////////////////////////////////////////////////////////
38
39double RooCBShape::ApproxErf(double arg) const
40{
41 static const double erflim = 5.0;
42 if( arg > erflim )
43 return 1.0;
44 if( arg < -erflim )
45 return -1.0;
46
47 return RooMath::erf(arg);
48}
49
50////////////////////////////////////////////////////////////////////////////////
51
52RooCBShape::RooCBShape(const char *name, const char *title,
53 RooAbsReal& _m, RooAbsReal& _m0, RooAbsReal& _sigma,
54 RooAbsReal& _alpha, RooAbsReal& _n) :
55 RooAbsPdf(name, title),
56 m("m", "Dependent", this, _m),
57 m0("m0", "M0", this, _m0),
58 sigma("sigma", "Sigma", this, _sigma),
59 alpha("alpha", "Alpha", this, _alpha),
60 n("n", "Order", this, _n)
61{
62}
63
64////////////////////////////////////////////////////////////////////////////////
65
66RooCBShape::RooCBShape(const RooCBShape& other, const char* name) :
67 RooAbsPdf(other, name), m("m", this, other.m), m0("m0", this, other.m0),
68 sigma("sigma", this, other.sigma), alpha("alpha", this, other.alpha),
69 n("n", this, other.n)
70{
71}
72
73////////////////////////////////////////////////////////////////////////////////
74
75double RooCBShape::evaluate() const {
76 double t = (m-m0)/sigma;
77 if (alpha < 0) t = -t;
78
79 double absAlpha = std::abs((double)alpha);
80
81 if (t >= -absAlpha) {
82 return exp(-0.5*t*t);
83 }
84 else {
85 double a = TMath::Power(n/absAlpha,n)*exp(-0.5*absAlpha*absAlpha);
86 double b= n/absAlpha - absAlpha;
87
88 return a/TMath::Power(b - t, n);
89 }
90}
91
92////////////////////////////////////////////////////////////////////////////////
93/// Compute multiple values of Crystal ball Shape distribution.
94void RooCBShape::computeBatch(double *output, size_t nEvents, RooFit::Detail::DataMap const &dataMap) const
95{
97 {dataMap.at(m), dataMap.at(m0), dataMap.at(sigma), dataMap.at(alpha), dataMap.at(n)});
98}
99
100////////////////////////////////////////////////////////////////////////////////
101
102Int_t RooCBShape::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* /*rangeName*/) const
103{
104 if( matchArgs(allVars,analVars,m) )
105 return 1 ;
106
107 return 0;
108}
109
110////////////////////////////////////////////////////////////////////////////////
111
112double RooCBShape::analyticalIntegral(Int_t code, const char* rangeName) const
113{
114 static const double sqrtPiOver2 = 1.2533141373;
115 static const double sqrt2 = 1.4142135624;
116
117 R__ASSERT(code==1);
118 double result = 0.0;
119 bool useLog = false;
120
121 if( std::abs(n-1.0) < 1.0e-05 )
122 useLog = true;
123
124 double sig = std::abs((double)sigma);
125
126 double tmin = (m.min(rangeName)-m0)/sig;
127 double tmax = (m.max(rangeName)-m0)/sig;
128
129 if(alpha < 0) {
130 double tmp = tmin;
131 tmin = -tmax;
132 tmax = -tmp;
133 }
134
135 double absAlpha = std::abs((double)alpha);
136
137 if( tmin >= -absAlpha ) {
138 result += sig*sqrtPiOver2*( ApproxErf(tmax/sqrt2)
139 - ApproxErf(tmin/sqrt2) );
140 }
141 else if( tmax <= -absAlpha ) {
142 double a = TMath::Power(n/absAlpha,n)*exp(-0.5*absAlpha*absAlpha);
143 double b = n/absAlpha - absAlpha;
144
145 if(useLog) {
146 result += a*sig*( log(b-tmin) - log(b-tmax) );
147 }
148 else {
149 result += a*sig/(1.0-n)*( 1.0/(TMath::Power(b-tmin,n-1.0))
150 - 1.0/(TMath::Power(b-tmax,n-1.0)) );
151 }
152 }
153 else {
154 double a = TMath::Power(n/absAlpha,n)*exp(-0.5*absAlpha*absAlpha);
155 double b = n/absAlpha - absAlpha;
156
157 double term1 = 0.0;
158 if(useLog) {
159 term1 = a*sig*( log(b-tmin) - log(n/absAlpha));
160 }
161 else {
162 term1 = a*sig/(1.0-n)*( 1.0/(TMath::Power(b-tmin,n-1.0))
163 - 1.0/(TMath::Power(n/absAlpha,n-1.0)) );
164 }
165
166 double term2 = sig*sqrtPiOver2*( ApproxErf(tmax/sqrt2)
167 - ApproxErf(-absAlpha/sqrt2) );
168
169
170 result += term1 + term2;
171 }
172
173 return result != 0. ? result : 1.E-300;
174}
175
176////////////////////////////////////////////////////////////////////////////////
177/// Advertise that we know the maximum of self for given (m0,alpha,n,sigma)
178
180{
181 RooArgSet dummy ;
182
183 if (matchArgs(vars,dummy,m)) {
184 return 1 ;
185 }
186 return 0 ;
187}
188
189////////////////////////////////////////////////////////////////////////////////
190
191double RooCBShape::maxVal(Int_t code) const
192{
193 R__ASSERT(code==1) ;
194
195 // The maximum value for given (m0,alpha,n,sigma)
196 // is 1./ Integral in the variable range
197 return 1.0/analyticalIntegral(1) ;
198}
#define b(i)
Definition RSha256.hxx:100
#define a(i)
Definition RSha256.hxx:99
#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 result
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
PDF implementing the Crystal Ball line shape.
Definition RooCBShape.h:24
double ApproxErf(double arg) const
void computeBatch(double *output, size_t nEvents, RooFit::Detail::DataMap const &) const override
Compute multiple values of Crystal ball Shape distribution.
Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName=nullptr) const override
Interface function getAnalyticalIntergral advertises the analytical integrals that are supported.
RooRealProxy n
Definition RooCBShape.h:49
RooRealProxy m0
Definition RooCBShape.h:46
RooRealProxy m
Definition RooCBShape.h:45
double analyticalIntegral(Int_t code, const char *rangeName=nullptr) const override
Implements the actual analytical integral(s) advertised by getAnalyticalIntegral.
RooRealProxy sigma
Definition RooCBShape.h:47
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
RooRealProxy alpha
Definition RooCBShape.h:48
Int_t getMaxVal(const RooArgSet &vars) const override
Advertise that we know the maximum of self for given (m0,alpha,n,sigma)
double maxVal(Int_t code) const override
Return maximum value for set of observables identified by code assigned in getMaxVal.
RooBatchCompute::Config config(RooAbsArg const *arg) const
Definition DataMap.cxx:40
static std::complex< double > erf(const std::complex< double > z)
complex erf function
Definition RooMath.cxx:59
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.
const Double_t sigma
const Int_t n
Definition legend1.C:16
void compute(Config cfg, Computer comp, RestrictArr output, size_t size, const VarVector &vars, ArgVector &extraArgs)
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Returns x raised to the power y.
Definition TMath.h:721
TMarker m
Definition textangle.C:8
static void output()