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