Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 "TMath.h"
26#include "Riostream.h"
27#include "RooGaussModel.h"
28#include "RooMath.h"
29#include "RooRealConstant.h"
30#include "RooRandom.h"
31#include "RooBatchCompute.h"
32
33#include "TError.h"
34
36
37using namespace std;
38
41
43
44////////////////////////////////////////////////////////////////////////////////
45
46RooGaussModel::RooGaussModel(const char *name, const char *title, RooAbsRealLValue& xIn,
47 RooAbsReal& _mean, RooAbsReal& _sigma) :
48 RooResolutionModel(name,title,xIn),
49 _flatSFInt(false),
50 _asympInt(false),
51 mean("mean","Mean",this,_mean),
52 sigma("sigma","Width",this,_sigma),
53 msf("msf","Mean Scale Factor",this,(RooRealVar&)RooRealConstant::value(1)),
54 ssf("ssf","Sigma Scale Factor",this,(RooRealVar&)RooRealConstant::value(1))
55{
56}
57
58////////////////////////////////////////////////////////////////////////////////
59
60RooGaussModel::RooGaussModel(const char *name, const char *title, RooAbsRealLValue& xIn,
61 RooAbsReal& _mean, RooAbsReal& _sigma,
62 RooAbsReal& _msSF) :
63 RooResolutionModel(name,title,xIn),
64 _flatSFInt(false),
65 _asympInt(false),
66 mean("mean","Mean",this,_mean),
67 sigma("sigma","Width",this,_sigma),
68 msf("msf","Mean Scale Factor",this,_msSF),
69 ssf("ssf","Sigma Scale Factor",this,_msSF)
70{
71}
72
73////////////////////////////////////////////////////////////////////////////////
74
75RooGaussModel::RooGaussModel(const char *name, const char *title, RooAbsRealLValue& xIn,
76 RooAbsReal& _mean, RooAbsReal& _sigma,
77 RooAbsReal& _meanSF, RooAbsReal& _sigmaSF) :
78 RooResolutionModel(name,title,xIn),
79 _flatSFInt(false),
80 _asympInt(false),
81 mean("mean","Mean",this,_mean),
82 sigma("sigma","Width",this,_sigma),
83 msf("msf","Mean Scale Factor",this,_meanSF),
84 ssf("ssf","Sigma Scale Factor",this,_sigmaSF)
85{
86}
87
88////////////////////////////////////////////////////////////////////////////////
89
92 _flatSFInt(other._flatSFInt),
93 _asympInt(other._asympInt),
94 mean("mean",this,other.mean),
95 sigma("sigma",this,other.sigma),
96 msf("msf",this,other.msf),
97 ssf("ssf",this,other.ssf)
98{
99}
100
101////////////////////////////////////////////////////////////////////////////////
102/// Destructor
103
105{
106}
107
108////////////////////////////////////////////////////////////////////////////////
109
111{
112 if (!TString("exp(-@0/@1)").CompareTo(name)) return expBasisPlus ;
113 if (!TString("exp(@0/@1)").CompareTo(name)) return expBasisMinus ;
114 if (!TString("exp(-abs(@0)/@1)").CompareTo(name)) return expBasisSum ;
115 if (!TString("exp(-@0/@1)*sin(@0*@2)").CompareTo(name)) return sinBasisPlus ;
116 if (!TString("exp(@0/@1)*sin(@0*@2)").CompareTo(name)) return sinBasisMinus ;
117 if (!TString("exp(-abs(@0)/@1)*sin(@0*@2)").CompareTo(name)) return sinBasisSum ;
118 if (!TString("exp(-@0/@1)*cos(@0*@2)").CompareTo(name)) return cosBasisPlus ;
119 if (!TString("exp(@0/@1)*cos(@0*@2)").CompareTo(name)) return cosBasisMinus ;
120 if (!TString("exp(-abs(@0)/@1)*cos(@0*@2)").CompareTo(name)) return cosBasisSum ;
121 if (!TString("(@0/@1)*exp(-@0/@1)").CompareTo(name)) return linBasisPlus ;
122 if (!TString("(@0/@1)*(@0/@1)*exp(-@0/@1)").CompareTo(name)) return quadBasisPlus ;
123 if (!TString("exp(-@0/@1)*cosh(@0*@2/2)").CompareTo(name)) return coshBasisPlus;
124 if (!TString("exp(@0/@1)*cosh(@0*@2/2)").CompareTo(name)) return coshBasisMinus;
125 if (!TString("exp(-abs(@0)/@1)*cosh(@0*@2/2)").CompareTo(name)) return coshBasisSum;
126 if (!TString("exp(-@0/@1)*sinh(@0*@2/2)").CompareTo(name)) return sinhBasisPlus;
127 if (!TString("exp(@0/@1)*sinh(@0*@2/2)").CompareTo(name)) return sinhBasisMinus;
128 if (!TString("exp(-abs(@0)/@1)*sinh(@0*@2/2)").CompareTo(name)) return sinhBasisSum;
129 return 0 ;
130}
131
132////////////////////////////////////////////////////////////////////////////////
133
135{
136 auto arg1 = static_cast<RooAbsReal*>(basis().getParameter(1));
137 auto arg2 = static_cast<RooAbsReal*>(basis().getParameter(2));
138 double param1 = arg1 ? arg1->getVal() : 0.0;
139 double param2 = arg2 ? arg2->getVal() : 0.0;
140 return evaluate(x, mean * msf, sigma * ssf, param1, param2, _basisCode);
141}
142
143void RooGaussModel::computeBatch(cudaStream_t *stream, double *output, size_t size,
144 RooFit::Detail::DataMap const &dataMap) const
145{
146 auto xVals = dataMap.at(x);
147 auto meanVals = dataMap.at(mean);
148 auto meanSfVals = dataMap.at(msf);
149 auto sigmaVals = dataMap.at(sigma);
150 auto sigmaSfVals = dataMap.at(ssf);
151
152 auto param1 = static_cast<RooAbsReal *>(basis().getParameter(1));
153 auto param2 = static_cast<RooAbsReal *>(basis().getParameter(2));
154 const double zeroVal = 0.0;
155 auto param1Vals = param1 ? dataMap.at(param1) : RooSpan<const double>{&zeroVal, 1};
156 auto param2Vals = param2 ? dataMap.at(param2) : RooSpan<const double>{&zeroVal, 1};
157
158 BasisType basisType = getBasisType(_basisCode);
159 double basisSign = _basisCode - 10 * (basisType - 1) - 2;
160
162
163 // We have an implementation also for CUDA right now only for the most used
164 // basis type, which is expBasis. If the need to support other basis types
165 // arises, they can be implemented following this example. Remember to also
166 // adapt RooGaussModel::canComputeBatchWithCuda().
167 if (basisType == expBasis) {
168 RooBatchCompute::ArgVector extraArgs{basisSign};
169 dispatch->compute(stream, RooBatchCompute::GaussModelExpBasis, output, size,
170 {xVals, meanVals, meanSfVals, sigmaVals, sigmaSfVals, param1Vals}, extraArgs);
171 return;
172 }
173
174 // For now, if the arrays don't have the expected input shape, fall back to the scalar mode
175 if (xVals.size() != size || meanVals.size() != 1 || meanSfVals.size() != 1 || sigmaVals.size() != 1 ||
176 sigmaSfVals.size() != 1 || param1Vals.size() != 1 || param2Vals.size() != 1) {
177 return RooAbsPdf::computeBatch(stream, output, size, dataMap);
178 }
179
180 for (unsigned int i = 0; i < size; ++i) {
181 output[i] = evaluate(xVals[i], meanVals[0] * meanSfVals[0], sigmaVals[0] * sigmaSfVals[0], param1Vals[0],
182 param2Vals[0], _basisCode);
183 }
184}
185
186double RooGaussModel::evaluate(double x, double mean, double sigma, double param1, double param2, int basisCode)
187{
188 // *** 1st form: Straight Gaussian, used for unconvoluted PDF or expBasis with 0 lifetime ***
189 static double root2(std::sqrt(2.)) ;
190 static double root2pi(std::sqrt(2.*std::atan2(0.,-1.))) ;
191 static double rootpi(std::sqrt(std::atan2(0.,-1.))) ;
192
193 BasisType basisType = getBasisType(basisCode);
194 BasisSign basisSign = (BasisSign)( basisCode - 10*(basisType-1) - 2 ) ;
195
196 double tau = (basisCode!=noBasis) ? param1 : 0.0;
197 if (basisType == coshBasis && basisCode!=noBasis ) {
198 double dGamma = param2;
199 if (dGamma==0) basisType = expBasis;
200 }
201
202 if (basisType==none || ((basisType==expBasis || basisType==cosBasis) && tau==0.)) {
203 double xprime = (x-mean)/sigma ;
204 double result = std::exp(-0.5*xprime*xprime)/(sigma*root2pi) ;
205 if (basisCode!=0 && basisSign==Both) result *= 2 ;
206 return result ;
207 }
208
209 // *** 2nd form: 0, used for sinBasis, linBasis, and quadBasis with tau=0 ***
210 if (tau==0) {
211 return 0. ;
212 }
213
214 // *** 3nd form: Convolution with exp(-t/tau), used for expBasis and cosBasis(omega=0) ***
215 double omega = (basisType==sinBasis || basisType==cosBasis) ? param2 : 0 ;
216 double dgamma = (basisType==sinhBasis || basisType==coshBasis) ? param2 : 0 ;
217 double _x = omega *tau ;
218 double _y = tau*dgamma/2;
219 double xprime = (x-mean)/tau ;
220 double c = sigma/(root2*tau) ;
221 double u = xprime/(2*c) ;
222
223 if (basisType==expBasis || (basisType==cosBasis && _x==0.)) {
224 double result(0) ;
225 if (basisSign!=Minus) result += evalCerf(0,-u,c).real();
226 if (basisSign!=Plus) result += evalCerf(0, u,c).real();
227 return result ;
228 }
229
230 // *** 4th form: Convolution with exp(-t/tau)*sin(omega*t), used for sinBasis(omega<>0,tau<>0) ***
231 if (basisType==sinBasis) {
232 double result(0) ;
233 if (_x==0.) return result ;
234 if (basisSign!=Minus) result += -evalCerf(-_x,-u,c).imag();
235 if (basisSign!=Plus) result += -evalCerf( _x, u,c).imag();
236 return result ;
237 }
238
239 // *** 5th form: Convolution with exp(-t/tau)*cos(omega*t), used for cosBasis(omega<>0) ***
240 if (basisType==cosBasis) {
241 double result(0) ;
242 if (basisSign!=Minus) result += evalCerf(-_x,-u,c).real();
243 if (basisSign!=Plus) result += evalCerf( _x, u,c).real();
244 return result ;
245 }
246
247 // ***8th form: Convolution with exp(-|t|/tau)*cosh(dgamma*t/2), used for coshBasisSum ***
248 if (basisType==coshBasis || basisType ==sinhBasis) {
249 double result(0);
250 int sgn = ( basisType == coshBasis ? +1 : -1 );
251 if (basisSign!=Minus) result += 0.5*( evalCerf(0,-u,c*(1-_y)).real()+sgn*evalCerf(0,-u,c*(1+_y)).real()) ;
252 if (basisSign!=Plus) result += 0.5*(sgn*evalCerf(0, u,c*(1-_y)).real()+ evalCerf(0, u,c*(1+_y)).real()) ;
253 return result ;
254 }
255
256 // *** 6th form: Convolution with (t/tau)*exp(-t/tau), used for linBasis ***
257 if (basisType==linBasis) {
258 R__ASSERT(basisSign==Plus); // This should only be for positive times
259
260 double f0 = std::exp(-xprime+c*c) * RooMath::erfc(-u+c);
261 double f1 = std::exp(-u*u);
262 return (xprime - 2*c*c)*f0 + (2*c/rootpi)*f1 ;
263 }
264
265 // *** 7th form: Convolution with (t/tau)^2*exp(-t/tau), used for quadBasis ***
266 if (basisType==quadBasis) {
267 R__ASSERT(basisSign==Plus); // This should only be for positive times
268
269 double f0 = std::exp(-xprime+c*c) * RooMath::erfc(-u+c);
270 double f1 = std::exp(-u*u);
271 double x2c2 = xprime - 2*c*c;
272 return ( x2c2*x2c2*f0 + (2*c/rootpi)*x2c2*f1 + 2*c*c*f0 );
273 }
274
275 R__ASSERT(0) ;
276 return 0 ;
277}
278
279////////////////////////////////////////////////////////////////////////////////
280
281Int_t RooGaussModel::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* /*rangeName*/) const
282{
283 switch(_basisCode) {
284
285 // Analytical integration capability of raw PDF
286 case noBasis:
287
288 // Optionally advertise flat integral over sigma scale factor
289 if (_flatSFInt) {
290 if (matchArgs(allVars,analVars,RooArgSet(convVar(),ssf.arg()))) return 2 ;
291 }
292
293 if (matchArgs(allVars,analVars,convVar())) return 1 ;
294 break ;
295
296 // Analytical integration capability of convoluted PDF
297 case expBasisPlus:
298 case expBasisMinus:
299 case expBasisSum:
300 case sinBasisPlus:
301 case sinBasisMinus:
302 case sinBasisSum:
303 case cosBasisPlus:
304 case cosBasisMinus:
305 case cosBasisSum:
306 case linBasisPlus:
307 case quadBasisPlus:
308 case coshBasisMinus:
309 case coshBasisPlus:
310 case coshBasisSum:
311 case sinhBasisMinus:
312 case sinhBasisPlus:
313 case sinhBasisSum:
314
315 // Optionally advertise flat integral over sigma scale factor
316 if (_flatSFInt) {
317
318 if (matchArgs(allVars,analVars,RooArgSet(convVar(),ssf.arg()))) {
319 return 2 ;
320 }
321 }
322
323 if (matchArgs(allVars,analVars,convVar())) return 1 ;
324 break ;
325 }
326
327 return 0 ;
328}
329
330////////////////////////////////////////////////////////////////////////////////
331
332double RooGaussModel::analyticalIntegral(Int_t code, const char* rangeName) const
333{
334 static const double root2 = std::sqrt(2.) ;
335 //static double rootPiBy2 = std::sqrt(std::atan2(0.0,-1.0)/2.0);
336 static const double rootpi = std::sqrt(std::atan2(0.0,-1.0));
337 double ssfInt(1.0) ;
338
339 // Code must be 1 or 2
340 R__ASSERT(code==1||code==2) ;
341 if (code==2) ssfInt = (ssf.max(rangeName)-ssf.min(rangeName)) ;
342
343 BasisType basisType = (BasisType)( (_basisCode == 0) ? 0 : (_basisCode/10) + 1 );
344 BasisSign basisSign = (BasisSign)( _basisCode - 10*(basisType-1) - 2 ) ;
345
346 // *** 1st form: Straight Gaussian, used for unconvoluted PDF or expBasis with 0 lifetime ***
347 double tau = (_basisCode!=noBasis)?((RooAbsReal*)basis().getParameter(1))->getVal():0 ;
348 if (basisType == coshBasis && _basisCode!=noBasis ) {
349 double dGamma = ((RooAbsReal*)basis().getParameter(2))->getVal();
350 if (dGamma==0) basisType = expBasis;
351 }
352 if (basisType==none || ((basisType==expBasis || basisType==cosBasis) && tau==0.)) {
353 double xscale = root2*(sigma*ssf);
354 if (verboseEval()>0) cout << "RooGaussModel::analyticalIntegral(" << GetName() << ") 1st form" << endl ;
355
356 double xpmin = (x.min(rangeName)-(mean*msf))/xscale ;
357 double xpmax = (x.max(rangeName)-(mean*msf))/xscale ;
358
359 double result ;
360 if (_asympInt) { // modified FMV, 07/24/03
361 result = 1.0 ;
362 } else {
363 result = 0.5*(RooMath::erf(xpmax)-RooMath::erf(xpmin)) ;
364 }
365
366 if (_basisCode!=0 && basisSign==Both) result *= 2 ;
367 //cout << "Integral 1st form " << " result= " << result*ssfInt << endl;
368 if (TMath::IsNaN(result)) { cxcoutE(Tracing) << "RooGaussModel::analyticalIntegral(" << GetName() << ") got nan during case 1 " << endl; }
369 return result*ssfInt ;
370 }
371
372
373 double omega = ((basisType==sinBasis)||(basisType==cosBasis)) ? ((RooAbsReal*)basis().getParameter(2))->getVal() : 0 ;
374 double dgamma =((basisType==sinhBasis)||(basisType==coshBasis)) ? ((RooAbsReal*)basis().getParameter(2))->getVal() : 0 ;
375
376 // *** 2nd form: unity, used for sinBasis and linBasis with tau=0 (PDF is zero) ***
377 if (tau==0) {
378 if (verboseEval()>0) cout << "RooGaussModel::analyticalIntegral(" << GetName() << ") 2nd form" << endl ;
379 return 0. ;
380 }
381
382 // *** 3rd form: Convolution with exp(-t/tau), used for expBasis and cosBasis(omega=0) ***
383 double c = (sigma*ssf)/(root2*tau) ;
384 double xpmin = (x.min(rangeName)-(mean*msf))/tau ;
385 double xpmax = (x.max(rangeName)-(mean*msf))/tau ;
386 double umin = xpmin/(2*c) ;
387 double umax = xpmax/(2*c) ;
388
389 if (basisType==expBasis || (basisType==cosBasis && omega==0.)) {
390 if (verboseEval()>0) cout << "RooGaussModel::analyticalIntegral(" << GetName() << ") 3d form tau=" << tau << endl ;
391 double result(0) ;
392 if (basisSign!=Minus) result += evalCerfInt(+1,0,tau,-umin,-umax,c).real();
393 if (basisSign!=Plus) result += evalCerfInt(-1,0,tau, umin, umax,c).real();
394 if (TMath::IsNaN(result)) { cxcoutE(Tracing) << "RooGaussModel::analyticalIntegral(" << GetName() << ") got nan during case 3 " << endl; }
395 return result*ssfInt ;
396 }
397
398 // *** 4th form: Convolution with exp(-t/tau)*sin(omega*t), used for sinBasis(omega<>0,tau<>0) ***
399 double _x = omega * tau ;
400 double _y = tau*dgamma/2;
401
402 if (basisType==sinBasis) {
403 if (verboseEval()>0) cout << "RooGaussModel::analyticalIntegral(" << GetName() << ") 4th form omega = " << omega << ", tau = " << tau << endl ;
404 double result(0) ;
405 if (_x==0) return result*ssfInt ;
406 if (basisSign!=Minus) result += -1*evalCerfInt(+1,-_x,tau,-umin,-umax,c).imag();
407 if (basisSign!=Plus) result += -1*evalCerfInt(-1, _x,tau, umin, umax,c).imag();
408 if (TMath::IsNaN(result)) { cxcoutE(Tracing) << "RooGaussModel::analyticalIntegral(" << GetName() << ") got nan during case 4 " << endl; }
409 return result*ssfInt ;
410 }
411
412 // *** 5th form: Convolution with exp(-t/tau)*cos(omega*t), used for cosBasis(omega<>0) ***
413 if (basisType==cosBasis) {
414 if (verboseEval()>0) cout << "RooGaussModel::analyticalIntegral(" << GetName() << ") 5th form omega = " << omega << ", tau = " << tau << endl ;
415 double result(0) ;
416 if (basisSign!=Minus) result += evalCerfInt(+1,-_x,tau,-umin,-umax,c).real();
417 if (basisSign!=Plus) result += evalCerfInt(-1, _x,tau, umin, umax,c).real();
418 if (TMath::IsNaN(result)) { cxcoutE(Tracing) << "RooGaussModel::analyticalIntegral(" << GetName() << ") got nan during case 5 " << endl; }
419 return result*ssfInt ;
420 }
421
422 // *** 8th form: Convolution with exp(-|t|/tau)*cosh(dgamma*t/2), used for coshBasis ***
423 // *** 9th form: Convolution with exp(-|t|/tau)*sinh(dgamma*t/2), used for sinhBasis ***
424 if (basisType==coshBasis || basisType == sinhBasis) {
425 if (verboseEval()>0) {cout << "RooGaussModel::analyticalIntegral(" << GetName() << ") 8th form tau=" << tau << endl ; }
426 double result(0) ;
427 int sgn = ( basisType == coshBasis ? +1 : -1 );
428 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());
429 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());
430 if (TMath::IsNaN(result)) { cxcoutE(Tracing) << "RooGaussModel::analyticalIntegral(" << GetName() << ") got nan during case 6 " << endl; }
431 return result*ssfInt ;
432 }
433
434 // *** 6th form: Convolution with (t/tau)*exp(-t/tau), used for linBasis ***
435 if (basisType==linBasis) {
436 if (verboseEval()>0) cout << "RooGaussModel::analyticalIntegral(" << GetName() << ") 6th form tau=" << tau << endl ;
437
438 double f0 = RooMath::erf(-umax) - RooMath::erf(-umin);
439 double f1 = std::exp(-umax*umax) - std::exp(-umin*umin);
440
441 double tmp1 = std::exp(-xpmax)*RooMath::erfc(-umax + c);
442 double tmp2 = std::exp(-xpmin)*RooMath::erfc(-umin + c);
443
444 double f2 = tmp1 - tmp2;
445 double f3 = xpmax*tmp1 - xpmin*tmp2;
446
447 double expc2 = std::exp(c*c);
448
449 return -tau*( f0 +
450 (2*c/rootpi)*f1 +
451 (1 - 2*c*c)*expc2*f2 +
452 expc2*f3
453 )*ssfInt;
454 }
455
456 // *** 7th form: Convolution with (t/tau)*(t/tau)*exp(-t/tau), used for quadBasis ***
457 if (basisType==quadBasis) {
458 if (verboseEval()>0) cout << "RooGaussModel::analyticalIntegral(" << GetName() << ") 7th form tau=" << tau << endl ;
459
460 double f0 = RooMath::erf(-umax) - RooMath::erf(-umin);
461
462 double tmpA1 = std::exp(-umax*umax);
463 double tmpA2 = std::exp(-umin*umin);
464
465 double f1 = tmpA1 - tmpA2;
466 double f2 = umax*tmpA1 - umin*tmpA2;
467
468 double tmpB1 = std::exp(-xpmax)*RooMath::erfc(-umax + c);
469 double tmpB2 = std::exp(-xpmin)*RooMath::erfc(-umin + c);
470
471 double f3 = tmpB1 - tmpB2;
472 double f4 = xpmax*tmpB1 - xpmin*tmpB2;
473 double f5 = xpmax*xpmax*tmpB1 - xpmin*xpmin*tmpB2;
474
475 double expc2 = std::exp(c*c);
476
477 return -tau*( 2*f0 +
478 (4*c/rootpi)*((1-c*c)*f1 + c*f2) +
479 (2*c*c*(2*c*c-1) + 2)*expc2*f3 - (4*c*c-2)*expc2*f4 + expc2*f5
480 )*ssfInt;
481 }
482 R__ASSERT(0) ;
483 return 0 ;
484}
485
486
487////////////////////////////////////////////////////////////////////////////////
488
489std::complex<double> RooGaussModel::evalCerfInt(double sign, double _x, double tau, double umin, double umax, double c) const
490{
491 std::complex<double> diff(2., 0.);
492 if (!_asympInt) {
493 diff = evalCerf(_x,umin,c);
494 diff -= evalCerf(_x,umax,c);
495 diff += RooMath::erf(umin) - RooMath::erf(umax);
496 diff *= sign;
497 }
498 diff *= std::complex<double>(1., _x);
499 diff *= tau / (1.+_x*_x);
500 return diff;
501}
502
503////////////////////////////////////////////////////////////////////////////////
504
505Int_t RooGaussModel::getGenerator(const RooArgSet& directVars, RooArgSet &generateVars, bool /*staticInitOK*/) const
506{
507 if (matchArgs(directVars,generateVars,x)) return 1 ;
508 return 0 ;
509}
510
511////////////////////////////////////////////////////////////////////////////////
512
514{
515 R__ASSERT(code==1) ;
516 double xmin = x.min();
517 double xmax = x.max();
518 TRandom *generator = RooRandom::randomGenerator();
519 while(true) {
520 double xgen = generator->Gaus(mean*msf,sigma*ssf);
521 if (xgen<xmax && xgen>xmin) {
522 x = xgen ;
523 return ;
524 }
525 }
526}
#define c(i)
Definition RSha256.hxx:101
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
#define cxcoutE(a)
#define ClassImp(name)
Definition Rtypes.h:377
#define R__ASSERT(e)
Definition TError.h:117
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
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
char name[80]
Definition TGX11.cxx:110
float xmin
float xmax
static int verboseEval()
Return global level of verbosity for p.d.f. evaluations.
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition RooAbsReal.h:62
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:91
bool matchArgs(const RooArgSet &allDeps, RooArgSet &numDeps, const RooArgProxy &a) const
Utility function for use in getAnalyticalIntegral().
virtual void computeBatch(cudaStream_t *, double *output, size_t size, RooFit::Detail::DataMap const &) const
Base function for computing multiple values of a RooAbsReal.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
RooSpan< const double > at(RooAbsArg const *arg, RooAbsArg const *caller=nullptr)
Definition DataMap.cxx:21
RooAbsArg * getParameter(const char *name) const
Return pointer to parameter with given name.
Class RooGaussModel implements a RooResolutionModel that models a Gaussian distribution.
RooRealProxy sigma
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
std::complex< double > evalCerfInt(double sign, double wt, double tau, double umin, double umax, double c) const
RooRealProxy msf
Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName=nullptr) const override
Interface function getAnalyticalIntergral advertises the analytical integrals that are supported.
void computeBatch(cudaStream_t *, double *output, size_t size, RooFit::Detail::DataMap const &) const override
Base function for computing multiple values of a RooAbsReal.
~RooGaussModel() override
Destructor.
void generateEvent(Int_t code) override
Interface for generation of an event using the algorithm corresponding to the specified code.
Int_t basisCode(const char *name) const override
Int_t getGenerator(const RooArgSet &directVars, RooArgSet &generateVars, bool staticInitOK=true) const override
Load generatedVars with the subset of directVars that we can generate events for, and return a code t...
RooRealProxy mean
double analyticalIntegral(Int_t code, const char *rangeName) const override
Implements the actual analytical integral(s) advertised by getAnalyticalIntegral.
RooRealProxy ssf
static BasisType getBasisType(int basisCode)
static std::complex< double > erfc(const std::complex< double > z)
complex erfc function
Definition RooMath.cxx:40
static std::complex< double > erf(const std::complex< double > z)
complex erf function
Definition RooMath.cxx:59
static TRandom * randomGenerator()
Return a pointer to a singleton random-number generator implementation.
Definition RooRandom.cxx:51
RooRealConstant provides static functions to create and keep track of RooRealVar constants.
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:40
RooResolutionModel is the base class for PDFs that represent a resolution model that can be convolute...
Int_t _basisCode
Identifier code for selected basis function.
RooAbsRealLValue & convVar() const
Return the convolution variable of the resolution model.
const RooFormulaVar & basis() const
RooTemplateProxy< RooAbsRealLValue > x
Dependent/convolution variable.
A simple container to hold a batch of data values.
Definition RooSpan.h:34
double max(const char *rname=nullptr) const
Query upper limit of range. This requires the payload to be RooAbsRealLValue or derived.
const T & arg() const
Return reference to object held in proxy.
double min(const char *rname=nullptr) const
Query lower limit of range. This requires the payload to be RooAbsRealLValue or derived.
const char * GetName() const override
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:274
Basic string class.
Definition TString.h:139
const Double_t sigma
Double_t x[n]
Definition legend1.C:17
TF1 * f1
Definition legend1.C:11
R__EXTERN RooBatchComputeInterface * dispatchCUDA
R__EXTERN RooBatchComputeInterface * dispatchCPU
This dispatch pointer points to an implementation of the compute library, provided one has been loade...
std::vector< double > ArgVector
__roohost__ __roodevice__ STD::complex< double > evalCerfApprox(double _x, double u, double c)
use the approximation: erf(z) = exp(-z*z)/(STD::sqrt(pi)*z) to explicitly cancel the divergent exp(y*...
__roohost__ __roodevice__ STD::complex< double > evalCerf(double swt, double u, double c)
Bool_t IsNaN(Double_t x)
Definition TMath.h:890
static void output()