Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooNovosibirsk.cxx
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitModels *
4 * @(#)root/roofit:$Id$
5 * Authors: *
6 * DB, Dieter Best, UC Irvine, best@slac.stanford.edu *
7 * HT, Hirohisa Tanaka SLAC tanaka@slac.stanford.edu *
8 * *
9 * Updated version with analytical integral *
10 * MP, Marko Petric, J. Stefan Institute, marko.petric@ijs.si *
11 * *
12 * Copyright (c) 2000-2013, Regents of the University of California *
13 * and Stanford University. All rights reserved. *
14 * *
15 * Redistribution and use in source and binary forms, *
16 * with or without modification, are permitted according to the terms *
17 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
18 *****************************************************************************/
19
20/** \class RooNovosibirsk
21 \ingroup Roofit
22
23RooNovosibirsk implements the Novosibirsk function
24
25Function taken from H. Ikeda et al. NIM A441 (2000), p. 401 (Belle Collaboration)
26
27**/
28#include "RooNovosibirsk.h"
29#include "RooFit.h"
30#include "RooRealVar.h"
31#include "RooBatchCompute.h"
32
33#include "TMath.h"
34
35#include <cmath>
36using namespace std;
37
39
40////////////////////////////////////////////////////////////////////////////////
41
42RooNovosibirsk::RooNovosibirsk(const char *name, const char *title,
43 RooAbsReal& _x, RooAbsReal& _peak,
44 RooAbsReal& _width, RooAbsReal& _tail) :
45 // The two addresses refer to our first dependent variable and
46 // parameter, respectively, as declared in the rdl file
47 RooAbsPdf(name, title),
48 x("x","x",this,_x),
49 width("width","width",this,_width),
50 peak("peak","peak",this,_peak),
51 tail("tail","tail",this,_tail)
52{
53}
54
55////////////////////////////////////////////////////////////////////////////////
56
58 RooAbsPdf(other,name),
59 x("x",this,other.x),
60 width("width",this,other.width),
61 peak("peak",this,other.peak),
62 tail("tail",this,other.tail)
63{
64}
65
66////////////////////////////////////////////////////////////////////////////////
67///If tail=eta=0 the Belle distribution becomes gaussian
68
70{
71 if (TMath::Abs(tail) < 1.e-7) {
72 return TMath::Exp( -0.5 * TMath::Power( ( (x - peak) / width ), 2 ));
73 }
74
75 Double_t arg = 1.0 - ( x - peak ) * tail / width;
76
77 if (arg < 1.e-7) {
78 //Argument of logarithm negative. Real continuation -> function equals zero
79 return 0.0;
80 }
81
82 Double_t log = TMath::Log(arg);
83 static const Double_t xi = 2.3548200450309494; // 2 Sqrt( Ln(4) )
84
85 Double_t width_zero = ( 2.0 / xi ) * TMath::ASinH( tail * xi * 0.5 );
86 Double_t width_zero2 = width_zero * width_zero;
87 Double_t exponent = ( -0.5 / (width_zero2) * log * log ) - ( width_zero2 * 0.5 );
88
89 return TMath::Exp(exponent) ;
90}
91////////////////////////////////////////////////////////////////////////////////
92/// Compute multiple values of Novosibirsk distribution.
93void RooNovosibirsk::computeBatch(cudaStream_t* stream, double* output, size_t nEvents, RooFit::Detail::DataMap const& dataMap) const
94{
96 dispatch->compute(stream, RooBatchCompute::Novosibirsk, output, nEvents,
97 {dataMap.at(x), dataMap.at(peak), dataMap.at(width), dataMap.at(tail)});
98}
99
100////////////////////////////////////////////////////////////////////////////////
101
102Int_t RooNovosibirsk::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* ) const
103{
104 if (matchArgs(allVars,analVars,x)) return 1 ;
105 if (matchArgs(allVars,analVars,peak)) return 2 ;
106
107 //The other two integrals over tali and width are not integrable
108
109 return 0 ;
110}
111
112////////////////////////////////////////////////////////////////////////////////
113
114Double_t RooNovosibirsk::analyticalIntegral(Int_t code, const char* rangeName) const
115{
116 assert(code==1 || code==2) ;
117
118 //The range is defined as [A,B]
119
120 //Numerical values need for the evaluation of the integral
121 static const Double_t sqrt2 = 1.4142135623730950; // Sqrt(2)
122 static const Double_t sqlog2 = 0.832554611157697756; //Sqrt( Log(2) )
123 static const Double_t sqlog4 = 1.17741002251547469; //Sqrt( Log(4) )
124 static const Double_t log4 = 1.38629436111989062; //Log(2)
125 static const Double_t rootpiby2 = 1.2533141373155003; // Sqrt(pi/2)
126 static const Double_t sqpibylog2 = 2.12893403886245236; //Sqrt( pi/Log(2) )
127
128 if (code==1) {
129 Double_t A = x.min(rangeName);
130 Double_t B = x.max(rangeName);
131
132 Double_t result = 0;
133
134
135 //If tail==0 the function becomes gaussian, thus we return a Gaussian integral
136 if (TMath::Abs(tail) < 1.e-7) {
137
138 Double_t xscale = sqrt2*width;
139
140 result = rootpiby2*width*(TMath::Erf((B-peak)/xscale)-TMath::Erf((A-peak)/xscale));
141
142 return result;
143
144 }
145
146 // If the range is not defined correctly the function becomes complex
147 Double_t log_argument_A = ( (peak - A)*tail + width ) / width ;
148 Double_t log_argument_B = ( (peak - B)*tail + width ) / width ;
149
150 //lower limit
151 if ( log_argument_A < 1.e-7) {
152 log_argument_A = 1.e-7;
153 }
154
155 //upper limit
156 if ( log_argument_B < 1.e-7) {
157 log_argument_B = 1.e-7;
158 }
159
160 Double_t term1 = TMath::ASinH( tail * sqlog4 );
161 Double_t term1_2 = term1 * term1;
162
163 //Calculate the error function arguments
164 Double_t erf_termA = ( term1_2 - log4 * TMath::Log( log_argument_A ) ) / ( 2 * term1 * sqlog2 );
165 Double_t erf_termB = ( term1_2 - log4 * TMath::Log( log_argument_B ) ) / ( 2 * term1 * sqlog2 );
166
167 result = 0.5 / tail * width * term1 * ( TMath::Erf(erf_termB) - TMath::Erf(erf_termA)) * sqpibylog2;
168
169 return result;
170
171 } else if (code==2) {
172 Double_t A = x.min(rangeName);
173 Double_t B = x.max(rangeName);
174
175 Double_t result = 0;
176
177
178 //If tail==0 the function becomes gaussian, thus we return a Gaussian integral
179 if (TMath::Abs(tail) < 1.e-7) {
180
181 Double_t xscale = sqrt2*width;
182
183 result = rootpiby2*width*(TMath::Erf((B-x)/xscale)-TMath::Erf((A-x)/xscale));
184
185 return result;
186
187 }
188
189 // If the range is not defined correctly the function becomes complex
190 Double_t log_argument_A = ( (A - x)*tail + width ) / width;
191 Double_t log_argument_B = ( (B - x)*tail + width ) / width;
192
193 //lower limit
194 if ( log_argument_A < 1.e-7) {
195 log_argument_A = 1.e-7;
196 }
197
198 //upper limit
199 if ( log_argument_B < 1.e-7) {
200 log_argument_B = 1.e-7;
201 }
202
203 Double_t term1 = TMath::ASinH( tail * sqlog4 );
204 Double_t term1_2 = term1 * term1;
205
206 //Calculate the error function arguments
207 Double_t erf_termA = ( term1_2 - log4 * TMath::Log( log_argument_A ) ) / ( 2 * term1 * sqlog2 );
208 Double_t erf_termB = ( term1_2 - log4 * TMath::Log( log_argument_B ) ) / ( 2 * term1 * sqlog2 );
209
210 result = 0.5 / tail * width * term1 * ( TMath::Erf(erf_termB) - TMath::Erf(erf_termA)) * sqpibylog2;
211
212 return result;
213
214 }
215
216 // Emit fatal error
217 coutF(Eval) << "Error in RooNovosibirsk::analyticalIntegral" << std::endl;
218
219 // Put dummy return here to avoid compiler warnings
220 return 1.0 ;
221}
#define coutF(a)
#define ClassImp(name)
Definition Rtypes.h:364
include TDocParser_001 C image html pict1_TDocParser_001 png width
char name[80]
Definition TGX11.cxx:110
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition RooAbsReal.h:64
Bool_t 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:35
virtual void compute(cudaStream_t *, Computer, RestrictArr, size_t, const VarVector &, const ArgVector &={})=0
auto & at(RooAbsArg const *arg, RooAbsArg const *=nullptr)
Definition DataMap.h:88
RooNovosibirsk implements the Novosibirsk function.
RooRealProxy width
Double_t analyticalIntegral(Int_t code, const char *rangeName=0) const
Implements the actual analytical integral(s) advertised by getAnalyticalIntegral.
Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName=0) const
Interface function getAnalyticalIntergral advertises the analytical integrals that are supported.
double evaluate() const
If tail=eta=0 the Belle distribution becomes gaussian.
RooRealProxy peak
RooRealProxy tail
void computeBatch(cudaStream_t *, double *output, size_t nEvents, RooFit::Detail::DataMap const &) const
Compute multiple values of Novosibirsk distribution.
RooRealProxy x
double min(const char *rname=0) const
Query lower limit of range. This requires the payload to be RooAbsRealLValue or derived.
double max(const char *rname=0) const
Query upper limit of range. This requires the payload to be RooAbsRealLValue or derived.
Double_t x[n]
Definition legend1.C:17
R__EXTERN RooBatchComputeInterface * dispatchCUDA
R__EXTERN RooBatchComputeInterface * dispatchCPU
This dispatch pointer points to an implementation of the compute library, provided one has been loade...
Double_t Exp(Double_t x)
Definition TMath.h:677
Double_t Erf(Double_t x)
Computation of the error function erf(x).
Definition TMath.cxx:184
Double_t ASinH(Double_t)
Definition TMath.cxx:64
Double_t Log(Double_t x)
Definition TMath.h:710
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Definition TMath.h:685
Short_t Abs(Short_t d)
Definition TMathBase.h:120
static void output(int code)
Definition gifencode.c:226