Analysis-Utilities 26.9.9
C++/ROOT utilities for nuclear measurement data analysis
Loading...
Searching...
No Matches
RooHighExpTail.cu
Go to the documentation of this file.
2
3#include <cuda_runtime.h>
4
5#ifndef M_PI
6#define M_PI 3.14159265358979323846
7#endif
8
9namespace {
10
11// exp(a)*erfc(b) without intermediate overflow; see ExpErfc in
12// src/RooFitPhotopeakPdfs.cpp for the derivation. In the tail a and b share the
13// sign of z and b >= a/sqrt(2), so when exp(a) would overflow erfc(b)
14// underflows and the product tends to 0.
15__device__ double ExpErfc(double a, double b) {
16 if (a <= 700.0)
17 return exp(a) * erfc(b);
18 double t = 1.0 / (b * b);
19 double erfcx = (1.0 / (b * sqrt(M_PI))) *
20 (1.0 - 0.5 * t + 0.75 * t * t - 1.875 * t * t * t);
21 return exp(a - b * b) * erfcx;
22}
23
24__global__ void RooHighExpTailKernel(double *output, const double *x_vals,
25 double mu, double inv_tau,
26 double inv_sqrt2_sigma, size_t n) {
27 size_t i = blockIdx.x * blockDim.x + threadIdx.x;
28 if (i < n) {
29 double z = mu - x_vals[i];
30 double v = ExpErfc(z * inv_tau, z * inv_sqrt2_sigma);
31 output[i] = v > 1e-300 ? v : 1e-300;
32 }
33}
34
35} // namespace
36
37void RooHighExpTail_launchKernel(double *output, const double *x_vals,
38 double mu, double inv_tau,
39 double inv_sqrt2_sigma, size_t n) {
40 const int threads = 256;
41 const int blocks = (n + threads - 1) / threads;
42 RooHighExpTailKernel<<<blocks, threads>>>(output, x_vals, mu, inv_tau,
43 inv_sqrt2_sigma, n);
44}
Host-callable launch wrappers for the photopeak PDF CUDA kernels.
void RooHighExpTail_launchKernel(double *output, const double *x_vals, double mu, double inv_tau, double inv_sqrt2_sigma, size_t n)
Launch the high-energy exponential tail kernel.
#define M_PI