Logo ROOT   6.18/05
Reference Guide
RooGaussModel.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 RooGaussModel
18 \ingroup Roofit
19
20Class RooGaussModel implements a RooResolutionModel that models a Gaussian
21distribution. Object of class RooGaussModel can be used
22for analytical convolutions with classes inheriting from RooAbsAnaConvPdf
23**/
24
25#include "RooFit.h"
26
27#include "TMath.h"
28#include "Riostream.h"
29#include "Riostream.h"
30#include "RooGaussModel.h"
31#include "RooRealConstant.h"
32#include "RooRandom.h"
33
34#include "TError.h"
35
36using namespace std;
37
39
40////////////////////////////////////////////////////////////////////////////////
41
42RooGaussModel::RooGaussModel(const char *name, const char *title, RooRealVar& xIn,
43 RooAbsReal& _mean, RooAbsReal& _sigma) :
44 RooResolutionModel(name,title,xIn),
45 _flatSFInt(kFALSE),
46 _asympInt(kFALSE),
47 mean("mean","Mean",this,_mean),
48 sigma("sigma","Width",this,_sigma),
49 msf("msf","Mean Scale Factor",this,(RooRealVar&)RooRealConstant::value(1)),
50 ssf("ssf","Sigma Scale Factor",this,(RooRealVar&)RooRealConstant::value(1))
51{
52}
53
54////////////////////////////////////////////////////////////////////////////////
55
56RooGaussModel::RooGaussModel(const char *name, const char *title, RooRealVar& xIn,
57 RooAbsReal& _mean, RooAbsReal& _sigma,
58 RooAbsReal& _msSF) :
59 RooResolutionModel(name,title,xIn),
60 _flatSFInt(kFALSE),
61 _asympInt(kFALSE),
62 mean("mean","Mean",this,_mean),
63 sigma("sigma","Width",this,_sigma),
64 msf("msf","Mean Scale Factor",this,_msSF),
65 ssf("ssf","Sigma Scale Factor",this,_msSF)
66{
67}
68
69////////////////////////////////////////////////////////////////////////////////
70
71RooGaussModel::RooGaussModel(const char *name, const char *title, RooRealVar& xIn,
72 RooAbsReal& _mean, RooAbsReal& _sigma,
73 RooAbsReal& _meanSF, RooAbsReal& _sigmaSF) :
74 RooResolutionModel(name,title,xIn),
75 _flatSFInt(kFALSE),
76 _asympInt(kFALSE),
77 mean("mean","Mean",this,_mean),
78 sigma("sigma","Width",this,_sigma),
79 msf("msf","Mean Scale Factor",this,_meanSF),
80 ssf("ssf","Sigma Scale Factor",this,_sigmaSF)
81{
82}
83
84////////////////////////////////////////////////////////////////////////////////
85
88 _flatSFInt(other._flatSFInt),
89 _asympInt(other._asympInt),
90 mean("mean",this,other.mean),
91 sigma("sigma",this,other.sigma),
92 msf("msf",this,other.msf),
93 ssf("ssf",this,other.ssf)
94{
95}
96
97////////////////////////////////////////////////////////////////////////////////
98/// Destructor
99
101{
102}
103
104////////////////////////////////////////////////////////////////////////////////
105
107{
108 if (!TString("exp(-@0/@1)").CompareTo(name)) return expBasisPlus ;
109 if (!TString("exp(@0/@1)").CompareTo(name)) return expBasisMinus ;
110 if (!TString("exp(-abs(@0)/@1)").CompareTo(name)) return expBasisSum ;
111 if (!TString("exp(-@0/@1)*sin(@0*@2)").CompareTo(name)) return sinBasisPlus ;
112 if (!TString("exp(@0/@1)*sin(@0*@2)").CompareTo(name)) return sinBasisMinus ;
113 if (!TString("exp(-abs(@0)/@1)*sin(@0*@2)").CompareTo(name)) return sinBasisSum ;
114 if (!TString("exp(-@0/@1)*cos(@0*@2)").CompareTo(name)) return cosBasisPlus ;
115 if (!TString("exp(@0/@1)*cos(@0*@2)").CompareTo(name)) return cosBasisMinus ;
116 if (!TString("exp(-abs(@0)/@1)*cos(@0*@2)").CompareTo(name)) return cosBasisSum ;
117 if (!TString("(@0/@1)*exp(-@0/@1)").CompareTo(name)) return linBasisPlus ;
118 if (!TString("(@0/@1)*(@0/@1)*exp(-@0/@1)").CompareTo(name)) return quadBasisPlus ;
119 if (!TString("exp(-@0/@1)*cosh(@0*@2/2)").CompareTo(name)) return coshBasisPlus;
120 if (!TString("exp(@0/@1)*cosh(@0*@2/2)").CompareTo(name)) return coshBasisMinus;
121 if (!TString("exp(-abs(@0)/@1)*cosh(@0*@2/2)").CompareTo(name)) return coshBasisSum;
122 if (!TString("exp(-@0/@1)*sinh(@0*@2/2)").CompareTo(name)) return sinhBasisPlus;
123 if (!TString("exp(@0/@1)*sinh(@0*@2/2)").CompareTo(name)) return sinhBasisMinus;
124 if (!TString("exp(-abs(@0)/@1)*sinh(@0*@2/2)").CompareTo(name)) return sinhBasisSum;
125 return 0 ;
126}
127
128////////////////////////////////////////////////////////////////////////////////
129
131{
132 // *** 1st form: Straight Gaussian, used for unconvoluted PDF or expBasis with 0 lifetime ***
133 static Double_t root2(std::sqrt(2.)) ;
134 static Double_t root2pi(std::sqrt(2.*std::atan2(0.,-1.))) ;
135 static Double_t rootpi(std::sqrt(std::atan2(0.,-1.))) ;
136
137 BasisType basisType = (BasisType)( (_basisCode == 0) ? 0 : (_basisCode/10) + 1 );
138 BasisSign basisSign = (BasisSign)( _basisCode - 10*(basisType-1) - 2 ) ;
139
141 if (basisType == coshBasis && _basisCode!=noBasis ) {
142 Double_t dGamma = ((RooAbsReal*)basis().getParameter(2))->getVal();
143 if (dGamma==0) basisType = expBasis;
144 }
145
146 if (basisType==none || ((basisType==expBasis || basisType==cosBasis) && tau==0.)) {
147 Double_t xprime = (x-(mean*msf))/(sigma*ssf) ;
148 if (verboseEval()>2) cout << "RooGaussModel::evaluate(" << GetName() << ") 1st form" << endl ;
149
150 Double_t result = std::exp(-0.5*xprime*xprime)/(sigma*ssf*root2pi) ;
151 if (_basisCode!=0 && basisSign==Both) result *= 2 ;
152 return result ;
153 }
154
155 // *** 2nd form: 0, used for sinBasis, linBasis, and quadBasis with tau=0 ***
156 if (tau==0) {
157 if (verboseEval()>2) cout << "RooGaussModel::evaluate(" << GetName() << ") 2nd form" << endl ;
158 return 0. ;
159 }
160
161 // *** 3nd form: Convolution with exp(-t/tau), used for expBasis and cosBasis(omega=0) ***
162 Double_t omega = (basisType==sinBasis || basisType==cosBasis) ? ((RooAbsReal*)basis().getParameter(2))->getVal() : 0 ;
163 Double_t dgamma = (basisType==sinhBasis || basisType==coshBasis) ? ((RooAbsReal*)basis().getParameter(2))->getVal() : 0 ;
164 Double_t _x = omega *tau ;
165 Double_t _y = tau*dgamma/2;
166 Double_t xprime = (x-(mean*msf))/tau ;
167 Double_t c = (sigma*ssf)/(root2*tau) ;
168 Double_t u = xprime/(2*c) ;
169
170 if (basisType==expBasis || (basisType==cosBasis && _x==0.)) {
171 if (verboseEval()>2) cout << "RooGaussModel::evaluate(" << GetName() << ") 3d form tau=" << tau << endl ;
172 Double_t result(0) ;
173 if (basisSign!=Minus) result += evalCerf(0,-u,c).real();
174 if (basisSign!=Plus) result += evalCerf(0, u,c).real();
175 if (TMath::IsNaN(result)) { cxcoutE(Tracing) << "RooGaussModel::getVal(" << GetName() << ") got nan during case 1 " << endl; }
176 return result ;
177 }
178
179 // *** 4th form: Convolution with exp(-t/tau)*sin(omega*t), used for sinBasis(omega<>0,tau<>0) ***
180 if (basisType==sinBasis) {
181 if (verboseEval()>2) cout << "RooGaussModel::evaluate(" << GetName() << ") 4th form omega = " << omega << ", tau = " << tau << endl ;
182 Double_t result(0) ;
183 if (_x==0.) return result ;
184 if (basisSign!=Minus) result += -evalCerf(-_x,-u,c).imag();
185 if (basisSign!=Plus) result += -evalCerf( _x, u,c).imag();
186 if (TMath::IsNaN(result)) cxcoutE(Tracing) << "RooGaussModel::getVal(" << GetName() << ") got nan during case 3 " << endl;
187 return result ;
188 }
189
190 // *** 5th form: Convolution with exp(-t/tau)*cos(omega*t), used for cosBasis(omega<>0) ***
191 if (basisType==cosBasis) {
192 if (verboseEval()>2) cout << "RooGaussModel::evaluate(" << GetName() << ") 5th form omega = " << omega << ", tau = " << tau << endl ;
193 Double_t result(0) ;
194 if (basisSign!=Minus) result += evalCerf(-_x,-u,c).real();
195 if (basisSign!=Plus) result += evalCerf( _x, u,c).real();
196 if (TMath::IsNaN(result)) cxcoutE(Tracing) << "RooGaussModel::getVal(" << GetName() << ") got nan during case 4 " << endl;
197 return result ;
198 }
199
200 // ***8th form: Convolution with exp(-|t|/tau)*cosh(dgamma*t/2), used for coshBasisSum ***
201 if (basisType==coshBasis || basisType ==sinhBasis) {
202 if (verboseEval()>2) cout << "RooGaussModel::evaluate(" << GetName() << ") 8th form tau = " << tau << endl ;
203 Double_t result(0);
204 int sgn = ( basisType == coshBasis ? +1 : -1 );
205 if (basisSign!=Minus) result += 0.5*( evalCerf(0,-u,c*(1-_y)).real()+sgn*evalCerf(0,-u,c*(1+_y)).real()) ;
206 if (basisSign!=Plus) result += 0.5*(sgn*evalCerf(0, u,c*(1-_y)).real()+ evalCerf(0, u,c*(1+_y)).real()) ;
207 if (TMath::IsNaN(result)) cxcoutE(Tracing) << "RooGaussModel::getVal(" << GetName() << ") got nan during case 8 " << endl;
208 return result ;
209 }
210
211 // *** 6th form: Convolution with (t/tau)*exp(-t/tau), used for linBasis ***
212 if (basisType==linBasis) {
213 if (verboseEval()>2) cout << "RooGaussModel::evaluate(" << GetName() << ") 6th form tau = " << tau << endl ;
214 R__ASSERT(basisSign==Plus); // This should only be for positive times
215
216 Double_t f0 = std::exp(-xprime+c*c) * RooMath::erfc(-u+c);
217 Double_t f1 = std::exp(-u*u);
218 return (xprime - 2*c*c)*f0 + (2*c/rootpi)*f1 ;
219 }
220
221 // *** 7th form: Convolution with (t/tau)^2*exp(-t/tau), used for quadBasis ***
222 if (basisType==quadBasis) {
223 if (verboseEval()>2) cout << "RooGaussModel::evaluate(" << GetName() << ") 7th form tau = " << tau << endl ;
224 R__ASSERT(basisSign==Plus); // This should only be for positive times
225
226 Double_t f0 = std::exp(-xprime+c*c) * RooMath::erfc(-u+c);
227 Double_t f1 = std::exp(-u*u);
228 Double_t x2c2 = xprime - 2*c*c;
229 return ( x2c2*x2c2*f0 + (2*c/rootpi)*x2c2*f1 + 2*c*c*f0 );
230 }
231
232 R__ASSERT(0) ;
233 return 0 ;
234}
235
236////////////////////////////////////////////////////////////////////////////////
237
238Int_t RooGaussModel::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* /*rangeName*/) const
239{
240 switch(_basisCode) {
241
242 // Analytical integration capability of raw PDF
243 case noBasis:
244
245 // Optionally advertise flat integral over sigma scale factor
246 if (_flatSFInt) {
247 if (matchArgs(allVars,analVars,RooArgSet(convVar(),ssf.arg()))) return 2 ;
248 }
249
250 if (matchArgs(allVars,analVars,convVar())) return 1 ;
251 break ;
252
253 // Analytical integration capability of convoluted PDF
254 case expBasisPlus:
255 case expBasisMinus:
256 case expBasisSum:
257 case sinBasisPlus:
258 case sinBasisMinus:
259 case sinBasisSum:
260 case cosBasisPlus:
261 case cosBasisMinus:
262 case cosBasisSum:
263 case linBasisPlus:
264 case quadBasisPlus:
265 case coshBasisMinus:
266 case coshBasisPlus:
267 case coshBasisSum:
268 case sinhBasisMinus:
269 case sinhBasisPlus:
270 case sinhBasisSum:
271
272 // Optionally advertise flat integral over sigma scale factor
273 if (_flatSFInt) {
274
275 if (matchArgs(allVars,analVars,RooArgSet(convVar(),ssf.arg()))) {
276 return 2 ;
277 }
278 }
279
280 if (matchArgs(allVars,analVars,convVar())) return 1 ;
281 break ;
282 }
283
284 return 0 ;
285}
286
287////////////////////////////////////////////////////////////////////////////////
288
289Double_t RooGaussModel::analyticalIntegral(Int_t code, const char* rangeName) const
290{
291 static const Double_t root2 = std::sqrt(2.) ;
292 //static Double_t rootPiBy2 = std::sqrt(std::atan2(0.0,-1.0)/2.0);
293 static const Double_t rootpi = std::sqrt(std::atan2(0.0,-1.0));
294 Double_t ssfInt(1.0) ;
295
296 // Code must be 1 or 2
297 R__ASSERT(code==1||code==2) ;
298 if (code==2) ssfInt = (ssf.max(rangeName)-ssf.min(rangeName)) ;
299
300 BasisType basisType = (BasisType)( (_basisCode == 0) ? 0 : (_basisCode/10) + 1 );
301 BasisSign basisSign = (BasisSign)( _basisCode - 10*(basisType-1) - 2 ) ;
302
303 // *** 1st form: Straight Gaussian, used for unconvoluted PDF or expBasis with 0 lifetime ***
305 if (basisType == coshBasis && _basisCode!=noBasis ) {
306 Double_t dGamma = ((RooAbsReal*)basis().getParameter(2))->getVal();
307 if (dGamma==0) basisType = expBasis;
308 }
309 if (basisType==none || ((basisType==expBasis || basisType==cosBasis) && tau==0.)) {
310 Double_t xscale = root2*(sigma*ssf);
311 if (verboseEval()>0) cout << "RooGaussModel::analyticalIntegral(" << GetName() << ") 1st form" << endl ;
312
313 Double_t xpmin = (x.min(rangeName)-(mean*msf))/xscale ;
314 Double_t xpmax = (x.max(rangeName)-(mean*msf))/xscale ;
315
316 Double_t result ;
317 if (_asympInt) { // modified FMV, 07/24/03
318 result = 1.0 ;
319 } else {
320 result = 0.5*(RooMath::erf(xpmax)-RooMath::erf(xpmin)) ;
321 }
322
323 if (_basisCode!=0 && basisSign==Both) result *= 2 ;
324 //cout << "Integral 1st form " << " result= " << result*ssfInt << endl;
325 if (TMath::IsNaN(result)) { cxcoutE(Tracing) << "RooGaussModel::analyticalIntegral(" << GetName() << ") got nan during case 1 " << endl; }
326 return result*ssfInt ;
327 }
328
329
330 Double_t omega = ((basisType==sinBasis)||(basisType==cosBasis)) ? ((RooAbsReal*)basis().getParameter(2))->getVal() : 0 ;
331 Double_t dgamma =((basisType==sinhBasis)||(basisType==coshBasis)) ? ((RooAbsReal*)basis().getParameter(2))->getVal() : 0 ;
332
333 // *** 2nd form: unity, used for sinBasis and linBasis with tau=0 (PDF is zero) ***
334 if (tau==0) {
335 if (verboseEval()>0) cout << "RooGaussModel::analyticalIntegral(" << GetName() << ") 2nd form" << endl ;
336 return 0. ;
337 }
338
339 // *** 3rd form: Convolution with exp(-t/tau), used for expBasis and cosBasis(omega=0) ***
340 Double_t c = (sigma*ssf)/(root2*tau) ;
341 Double_t xpmin = (x.min(rangeName)-(mean*msf))/tau ;
342 Double_t xpmax = (x.max(rangeName)-(mean*msf))/tau ;
343 Double_t umin = xpmin/(2*c) ;
344 Double_t umax = xpmax/(2*c) ;
345
346 if (basisType==expBasis || (basisType==cosBasis && omega==0.)) {
347 if (verboseEval()>0) cout << "RooGaussModel::analyticalIntegral(" << GetName() << ") 3d form tau=" << tau << endl ;
348 Double_t result(0) ;
349 if (basisSign!=Minus) result += evalCerfInt(+1,0,tau,-umin,-umax,c).real();
350 if (basisSign!=Plus) result += evalCerfInt(-1,0,tau, umin, umax,c).real();
351 if (TMath::IsNaN(result)) { cxcoutE(Tracing) << "RooGaussModel::analyticalIntegral(" << GetName() << ") got nan during case 3 " << endl; }
352 return result*ssfInt ;
353 }
354
355 // *** 4th form: Convolution with exp(-t/tau)*sin(omega*t), used for sinBasis(omega<>0,tau<>0) ***
356 Double_t _x = omega * tau ;
357 Double_t _y = tau*dgamma/2;
358
359 if (basisType==sinBasis) {
360 if (verboseEval()>0) cout << "RooGaussModel::analyticalIntegral(" << GetName() << ") 4th form omega = " << omega << ", tau = " << tau << endl ;
361 Double_t result(0) ;
362 if (_x==0) return result*ssfInt ;
363 if (basisSign!=Minus) result += -1*evalCerfInt(+1,-_x,tau,-umin,-umax,c).imag();
364 if (basisSign!=Plus) result += -1*evalCerfInt(-1, _x,tau, umin, umax,c).imag();
365 if (TMath::IsNaN(result)) { cxcoutE(Tracing) << "RooGaussModel::analyticalIntegral(" << GetName() << ") got nan during case 4 " << endl; }
366 return result*ssfInt ;
367 }
368
369 // *** 5th form: Convolution with exp(-t/tau)*cos(omega*t), used for cosBasis(omega<>0) ***
370 if (basisType==cosBasis) {
371 if (verboseEval()>0) cout << "RooGaussModel::analyticalIntegral(" << GetName() << ") 5th form omega = " << omega << ", tau = " << tau << endl ;
372 Double_t result(0) ;
373 if (basisSign!=Minus) result += evalCerfInt(+1,-_x,tau,-umin,-umax,c).real();
374 if (basisSign!=Plus) result += evalCerfInt(-1, _x,tau, umin, umax,c).real();
375 if (TMath::IsNaN(result)) { cxcoutE(Tracing) << "RooGaussModel::analyticalIntegral(" << GetName() << ") got nan during case 5 " << endl; }
376 return result*ssfInt ;
377 }
378
379 // *** 8th form: Convolution with exp(-|t|/tau)*cosh(dgamma*t/2), used for coshBasis ***
380 // *** 9th form: Convolution with exp(-|t|/tau)*sinh(dgamma*t/2), used for sinhBasis ***
381 if (basisType==coshBasis || basisType == sinhBasis) {
382 if (verboseEval()>0) {cout << "RooGaussModel::analyticalIntegral(" << GetName() << ") 8th form tau=" << tau << endl ; }
383 Double_t result(0) ;
384 int sgn = ( basisType == coshBasis ? +1 : -1 );
385 if (basisSign!=Minus) result += 0.5*( evalCerfInt(+1,0,tau/(1-_y),-umin,-umax,c*(1-_y)).real()+ sgn*evalCerfInt(+1,0,tau/(1+_y),-umin,-umax,c*(1+_y)).real());
386 if (basisSign!=Plus) result += 0.5*(sgn*evalCerfInt(-1,0,tau/(1-_y), umin, umax,c*(1-_y)).real()+ evalCerfInt(-1,0,tau/(1+_y), umin, umax,c*(1+_y)).real());
387 if (TMath::IsNaN(result)) { cxcoutE(Tracing) << "RooGaussModel::analyticalIntegral(" << GetName() << ") got nan during case 6 " << endl; }
388 return result*ssfInt ;
389 }
390
391 // *** 6th form: Convolution with (t/tau)*exp(-t/tau), used for linBasis ***
392 if (basisType==linBasis) {
393 if (verboseEval()>0) cout << "RooGaussModel::analyticalIntegral(" << GetName() << ") 6th form tau=" << tau << endl ;
394
395 Double_t f0 = RooMath::erf(-umax) - RooMath::erf(-umin);
396 Double_t f1 = std::exp(-umax*umax) - std::exp(-umin*umin);
397
398 Double_t tmp1 = std::exp(-xpmax)*RooMath::erfc(-umax + c);
399 Double_t tmp2 = std::exp(-xpmin)*RooMath::erfc(-umin + c);
400
401 Double_t f2 = tmp1 - tmp2;
402 Double_t f3 = xpmax*tmp1 - xpmin*tmp2;
403
404 Double_t expc2 = std::exp(c*c);
405
406 return -tau*( f0 +
407 (2*c/rootpi)*f1 +
408 (1 - 2*c*c)*expc2*f2 +
409 expc2*f3
410 )*ssfInt;
411 }
412
413 // *** 7th form: Convolution with (t/tau)*(t/tau)*exp(-t/tau), used for quadBasis ***
414 if (basisType==quadBasis) {
415 if (verboseEval()>0) cout << "RooGaussModel::analyticalIntegral(" << GetName() << ") 7th form tau=" << tau << endl ;
416
417 Double_t f0 = RooMath::erf(-umax) - RooMath::erf(-umin);
418
419 Double_t tmpA1 = std::exp(-umax*umax);
420 Double_t tmpA2 = std::exp(-umin*umin);
421
422 Double_t f1 = tmpA1 - tmpA2;
423 Double_t f2 = umax*tmpA1 - umin*tmpA2;
424
425 Double_t tmpB1 = std::exp(-xpmax)*RooMath::erfc(-umax + c);
426 Double_t tmpB2 = std::exp(-xpmin)*RooMath::erfc(-umin + c);
427
428 Double_t f3 = tmpB1 - tmpB2;
429 Double_t f4 = xpmax*tmpB1 - xpmin*tmpB2;
430 Double_t f5 = xpmax*xpmax*tmpB1 - xpmin*xpmin*tmpB2;
431
432 Double_t expc2 = std::exp(c*c);
433
434 return -tau*( 2*f0 +
435 (4*c/rootpi)*((1-c*c)*f1 + c*f2) +
436 (2*c*c*(2*c*c-1) + 2)*expc2*f3 - (4*c*c-2)*expc2*f4 + expc2*f5
437 )*ssfInt;
438 }
439 R__ASSERT(0) ;
440 return 0 ;
441}
442
443////////////////////////////////////////////////////////////////////////////////
444/// use the approximation: erf(z) = exp(-z*z)/(std::sqrt(pi)*z)
445/// to explicitly cancel the divergent exp(y*y) behaviour of
446/// CWERF for z = x + i y with large negative y
447
449{
450 static const Double_t rootpi= std::sqrt(std::atan2(0.,-1.));
451 const std::complex<Double_t> z(_x * c, u + c);
452 const std::complex<Double_t> zc(u + c, - _x * c);
453 const std::complex<Double_t> zsq((z.real() + z.imag()) * (z.real() - z.imag()),
454 2. * z.real() * z.imag());
455 const std::complex<Double_t> v(-zsq.real() - u*u, -zsq.imag());
456 const std::complex<Double_t> ev = std::exp(v);
457 const std::complex<Double_t> mez2zcrootpi = -std::exp(zsq)/(zc*rootpi);
458
459 return 2. * (ev * (mez2zcrootpi + 1.));
460}
461
462////////////////////////////////////////////////////////////////////////////////
463
464std::complex<Double_t> RooGaussModel::evalCerfInt(Double_t sign, Double_t _x, Double_t tau, Double_t umin, Double_t umax, Double_t c) const
465{
466 std::complex<Double_t> diff(2., 0.);
467 if (!_asympInt) {
468 diff = evalCerf(_x,umin,c);
469 diff -= evalCerf(_x,umax,c);
470 diff += RooMath::erf(umin) - RooMath::erf(umax);
471 diff *= sign;
472 }
473 diff *= std::complex<Double_t>(1., _x);
474 diff *= tau / (1.+_x*_x);
475 return diff;
476}
477
478////////////////////////////////////////////////////////////////////////////////
479
480Int_t RooGaussModel::getGenerator(const RooArgSet& directVars, RooArgSet &generateVars, Bool_t /*staticInitOK*/) const
481{
482 if (matchArgs(directVars,generateVars,x)) return 1 ;
483 return 0 ;
484}
485
486////////////////////////////////////////////////////////////////////////////////
487
489{
490 R__ASSERT(code==1) ;
491 Double_t xmin = x.min();
492 Double_t xmax = x.max();
493 TRandom *generator = RooRandom::randomGenerator();
494 while(true) {
495 Double_t xgen = generator->Gaus(mean*msf,sigma*ssf);
496 if (xgen<xmax && xgen>xmin) {
497 x = xgen ;
498 return ;
499 }
500 }
501}
SVector< double, 2 > v
Definition: Dict.h:5
#define c(i)
Definition: RSha256.hxx:101
#define cxcoutE(a)
Definition: RooMsgService.h:95
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
double Double_t
Definition: RtypesCore.h:55
#define ClassImp(name)
Definition: Rtypes.h:365
#define R__ASSERT(e)
Definition: TError.h:96
char name[80]
Definition: TGX11.cxx:109
float xmin
Definition: THbookFile.cxx:93
float xmax
Definition: THbookFile.cxx:93
double atan2(double, double)
double sqrt(double)
double exp(double)
friend class RooArgSet
Definition: RooAbsArg.h:516
static int verboseEval()
Return global level of verbosity for p.d.f. evaluations.
Definition: RooAbsPdf.cxx:2940
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
Bool_t matchArgs(const RooArgSet &allDeps, RooArgSet &numDeps, const RooArgProxy &a) const
Utility function for use in getAnalyticalIntegral().
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:81
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
RooAbsArg * getParameter(const char *name) const
Definition: RooFormulaVar.h:39
Class RooGaussModel implements a RooResolutionModel that models a Gaussian distribution.
Definition: RooGaussModel.h:26
RooRealProxy sigma
Definition: RooGaussModel.h:83
Bool_t _asympInt
Definition: RooGaussModel.h:80
Bool_t _flatSFInt
Definition: RooGaussModel.h:78
RooRealProxy msf
Definition: RooGaussModel.h:84
virtual ~RooGaussModel()
Destructor.
std::complex< Double_t > evalCerfInt(Double_t sign, Double_t wt, Double_t tau, Double_t umin, Double_t umax, Double_t c) const
static std::complex< Double_t > evalCerf(Double_t swt, Double_t u, Double_t c)
Definition: RooGaussModel.h:69
static std::complex< Double_t > evalCerfApprox(Double_t swt, Double_t u, Double_t c)
use the approximation: erf(z) = exp(-z*z)/(std::sqrt(pi)*z) to explicitly cancel the divergent exp(y*...
virtual Double_t analyticalIntegral(Int_t code, const char *rangeName) const
Implements the actual analytical integral(s) advertised by getAnalyticalIntegral.
Int_t getGenerator(const RooArgSet &directVars, RooArgSet &generateVars, Bool_t staticInitOK=kTRUE) const
Load generatedVars with the subset of directVars that we can generate events for, and return a code t...
virtual Double_t evaluate() const
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
void generateEvent(Int_t code)
Interface for generation of an event using the algorithm corresponding to the specified code.
virtual Int_t basisCode(const char *name) const
virtual Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName=0) const
Interface function getAnalyticalIntergral advertises the analytical integrals that are supported.
RooRealProxy mean
Definition: RooGaussModel.h:82
RooRealProxy ssf
Definition: RooGaussModel.h:85
static std::complex< double > erfc(const std::complex< double > z)
complex erfc function
Definition: RooMath.cxx:556
static std::complex< double > erf(const std::complex< double > z)
complex erf function
Definition: RooMath.cxx:580
static TRandom * randomGenerator()
Return a pointer to a singleton random-number generator implementation.
Definition: RooRandom.cxx:54
RooRealConstant provides static functions to create and keep track of RooRealVar constants.
Double_t min(const char *rname=0) const
Definition: RooRealProxy.h:56
const RooAbsReal & arg() const
Definition: RooRealProxy.h:43
Double_t max(const char *rname=0) const
Definition: RooRealProxy.h:57
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
RooRealVar & convVar() const
Return the convolution variable of the resolution model.
const RooFormulaVar & basis() const
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:27
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
Definition: TRandom.cxx:263
Basic string class.
Definition: TString.h:131
const Double_t sigma
TF1 * f1
Definition: legend1.C:11
Bool_t IsNaN(Double_t x)
Definition: TMath.h:880