Public Member Functions | Public Attributes | List of all members
WireCell::Gen::GausDesc Struct Reference

#include <GaussianDiffusion.h>

Public Member Functions

 GausDesc (double center, double sigma)
 
double distance (double x)
 Return the distance in number of sigma that x is from the center. More...
 
std::pair< double, double > sigma_range (double nsigma=3.0)
 
std::vector< double > sample (double start, double step, int nsamples) const
 
std::vector< double > binint (double start, double step, int nbins) const
 
std::vector< double > weight (double start, double step, int nbins, std::vector< double > pvec) const
 

Public Attributes

double center
 
double sigma
 The Gaussian sigma (half) width. More...
 

Detailed Description

A GausDesc describes a Gaussian distribution.

Two are used by GaussianDiffusion. One describes the transverse dimension along the direction of wire pitch (and for a given wire plane) and one the longitudinal dimension is along the drift direction as measured in time.

Definition at line 21 of file GaussianDiffusion.h.

Constructor & Destructor Documentation

WireCell::Gen::GausDesc::GausDesc ( double  center,
double  sigma 
)
inline

Definition at line 29 of file GaussianDiffusion.h.

30  : center(center)
31  , sigma(sigma)
32  { }
double sigma
The Gaussian sigma (half) width.

Member Function Documentation

std::vector< double > Gen::GausDesc::binint ( double  start,
double  step,
int  nbins 
) const

Integrate Gaussian across uniform bins. Result is normalized assuming integral of Gaussian over entire domain is 1.0.

Definition at line 31 of file GaussianDiffusion.cxx.

32 {
33  std::vector<double> bins;
34 
35  if(!sigma){
36  bins.resize(1, 0);
37  bins[0] = 1;
38  if(nbins != 1){
39  cerr<<"NOT one bin for true point source: "<<nbins<<"\n";
40  }
41  }
42  else{
43  bins.resize(nbins, 0.0);
44  std::vector<double> erfs(nbins+1, 0.0);
45  const double sqrt2 = sqrt(2.0);
46  for (int ind=0; ind <= nbins; ++ind) {
47  double x = (start + step * ind - center)/(sqrt2*sigma);
48  erfs[ind] = 0.5*std::erf(x);
49  }
50 
51  double tot = 0.0;
52  for (int ibin=0; ibin < nbins; ++ibin) {
53  const double val = erfs[ibin+1] - erfs[ibin];
54  tot += val;
55  bins[ibin] = val;
56  }
57  }
58  return bins;
59 }
double sigma
The Gaussian sigma (half) width.
list x
Definition: train.py:276
double WireCell::Gen::GausDesc::distance ( double  x)
inline

Return the distance in number of sigma that x is from the center.

Definition at line 35 of file GaussianDiffusion.h.

35  {
36  double ret = 0.0;
37  if(!sigma){
38  ret = x-center;
39  }
40  else{
41  ret = (x-center)/sigma;
42  }
43  return ret;
44  }
double sigma
The Gaussian sigma (half) width.
list x
Definition: train.py:276
std::vector< double > Gen::GausDesc::sample ( double  start,
double  step,
int  nsamples 
) const

Sample the Gaussian at points on a uniform linear grid.

Definition at line 8 of file GaussianDiffusion.cxx.

9 {
10  std::vector<double> ret;
11 
12  if(!sigma){
13  ret.resize(1, 0);
14  ret[0] = 1;
15  if(nsamples != 1){
16  cerr<<"NOT one sample for true point source: "<<nsamples<<"\n";
17  }
18 
19  }
20  else{
21  ret.resize(nsamples, 0.0);
22  for (int ind=0; ind<nsamples; ++ind) {
23  const double rel = (start + ind*step - center)/sigma;
24  ret[ind] = exp(-0.5*rel*rel);
25  }
26  }
27 
28  return ret;
29 }
double sigma
The Gaussian sigma (half) width.
std::pair<double,double> WireCell::Gen::GausDesc::sigma_range ( double  nsigma = 3.0)
inline

Definition at line 46 of file GaussianDiffusion.h.

46  {
47  return std::make_pair(center-sigma*nsigma, center+sigma*nsigma);
48 
49  }
double sigma
The Gaussian sigma (half) width.
std::vector< double > Gen::GausDesc::weight ( double  start,
double  step,
int  nbins,
std::vector< double >  pvec 
) const

Integrate Gaussian diffusion with linear weighting to redistribute the charge to the two neartest impact positions for linear interpolation of the field response

Definition at line 64 of file GaussianDiffusion.cxx.

65 {
66  std::vector<double> wt;
67  if(!sigma){
68  wt.resize(1, 0);
69  wt[0] = (start+step - center)/step;
70  }
71  else{
72  wt.resize(nbins, 0.0);
73  const double pi = 4.0*atan(1);
74  double x2 = start;
75  double x1 = 0;
76  double gaus2 = exp(-0.5*(start-center)/sigma*(start-center)/sigma);
77  double gaus1 = 0;
78  for (int ind=0; ind<nbins; ind++)
79  {
80  x1 = x2;
81  x2 = x1 + step;
82  double rel = (x2-center)/sigma;
83  gaus1 = gaus2;
84  gaus2 = exp(-0.5*rel*rel);
85 
86  // weighting
87  wt[ind] = -1.0*sigma/(x1-x2)*(gaus2-gaus1)/sqrt(2.0*pi)/pvec[ind] + (center-x2)/(x1-x2);
88  /* std::cerr<<"Gaus: "<<"1 and 2 "<<gaus1<<", "<<gaus2<<std::endl; */
89  /* std::cerr<<"center, x1, x2: "<<center<<", "<<x1<<", "<<x2<<std::endl; */
90  /* std::cerr<<"Total charge: "<<pvec[ind]<<std::endl; */
91  /* std::cerr<<"weight: "<<ind<<" "<<wt[ind]<<std::endl; */
92  }
93  }
94  return wt;
95 }
double sigma
The Gaussian sigma (half) width.
float pi
Definition: units.py:11

Member Data Documentation

double WireCell::Gen::GausDesc::center

The absolute location of the mean of the Gaussian as measured relative to some externally defined origin.

Definition at line 25 of file GaussianDiffusion.h.

double WireCell::Gen::GausDesc::sigma

The Gaussian sigma (half) width.

Definition at line 27 of file GaussianDiffusion.h.


The documentation for this struct was generated from the following files: