GaussianDiffusion.h
Go to the documentation of this file.
1 #ifndef WIRECELLGEN_GaussianDiffusion
2 #define WIRECELLGEN_GaussianDiffusion
3 
4 #include "WireCellUtil/Array.h"
5 #include "WireCellUtil/Binning.h"
6 #include "WireCellIface/IDepo.h"
8 
9 #include <memory>
10 #include <iostream>
11 
12 namespace WireCell {
13  namespace Gen {
14 
15  /** A GausDesc describes a Gaussian distribution.
16  *
17  * Two are used by GaussianDiffusion. One describes the
18  * transverse dimension along the direction of wire pitch (and
19  * for a given wire plane) and one the longitudinal dimension
20  * is along the drift direction as measured in time. */
21  struct GausDesc {
22 
23  /// The absolute location of the mean of the Gaussian as
24  /// measured relative to some externally defined origin.
25  double center;
26  /// The Gaussian sigma (half) width.
27  double sigma;
28 
29  GausDesc(double center, double sigma)
30  : center(center)
31  , sigma(sigma)
32  { }
33 
34  /// Return the distance in number of sigma that x is from the center
35  double distance(double x) {
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  }
45 
46  std::pair<double,double> sigma_range(double nsigma=3.0) {
47  return std::make_pair(center-sigma*nsigma, center+sigma*nsigma);
48 
49  }
50 
51  /** Sample the Gaussian at points on a uniform linear grid. */
52  std::vector<double> sample(double start, double step, int nsamples) const;
53 
54  /** Integrate Gaussian across uniform bins. Result is
55  * normalized assuming integral of Gaussian over entire
56  * domain is 1.0. */
57  std::vector<double> binint(double start, double step, int nbins) const;
58 
59  /** Integrate Gaussian diffusion with linear weighting
60  * to redistribute the charge to the two neartest impact positions
61  * for linear interpolation of the field response */
62  std::vector<double> weight(double start, double step, int nbins, std::vector<double> pvec) const;
63 
64  };
65 
66 
67 
69  public:
70 
71  typedef std::shared_ptr<GaussianDiffusion> pointer;
72 
73 
74  /// A patch is a 2D array of diffuse charge in (nimpacts X
75  /// nticks) bins. patch[0] is drifted/diffused charge
76  /// waveform at impact position 0 (relative to min pitch
77  /// for the patch). patch[0][0] is charge at this impact
78  /// position at time = 0 (relative to min time for the
79  /// patch). See `bin()`.
81 
82  /** Create a diffused deposition.
83  */
84 
86  const GausDesc& time_desc,
87  const GausDesc& pitch_desc);
88 
89 
90  /// This fills the patch once matching the given time and
91  /// pitch binning. The patch is limited to the 2D sample
92  /// points that cover the subdomain determined by the
93  /// number of sigma. If there should be Poisson
94  /// fluctuations applied pass in an IRandom. Total charge
95  /// is charge is preserved. Each cell of the patch
96  /// represents the 2D bin-centered sampling of the
97  /// Gaussian.
98 
99  void set_sampling(const Binning& tbin, const Binning& pbin,
100  double nsigma = 3.0,
101  IRandom::pointer fluctuate=nullptr,
102  unsigned int weightstrat = 1/*see BinnedDiffusion ImpactDataCalculationStrategy*/);
103  void clear_sampling();
104 
105  /// Get the diffusion patch as an array of N_pitch rows X
106  /// N_time columns. Index as patch(i_pitch, i_time).
107  /// Call set_sampling() first.
108  const patch_t& patch() const;
109 
110  const std::vector<double> weights() const;
111 
112  /// Return the absolute time bin in the binning corresponding to column 0 of the patch.
113  int toffset_bin() const { return m_toffset_bin; }
114 
115  /// Return the absolute impact bin in the binning corresponding to column 0 of the patch.
116  int poffset_bin() const { return m_poffset_bin; }
117 
118  /// Access deposition.
119  IDepo::pointer depo() const { return m_deposition; }
120 
121  double depo_time() const { return m_deposition->time();}
122  double depo_x() const { return m_deposition->pos().x();}
123 
124  const GausDesc pitch_desc() { return m_pitch_desc; }
125  const GausDesc time_desc() { return m_time_desc; }
126 
127  private:
128 
129  IDepo::pointer m_deposition; // just for provenance
130 
131  GausDesc m_time_desc, m_pitch_desc;
132 
133  patch_t m_patch;
134  std::vector<double> m_qweights;
135 
138  };
139  }
140 }
141 
142 #endif
std::shared_ptr< const IDepo > pointer
Definition: IData.h:19
double distance(double x)
Return the distance in number of sigma that x is from the center.
GausDesc(double center, double sigma)
int toffset_bin() const
Return the absolute time bin in the binning corresponding to column 0 of the patch.
std::vector< double > binint(double start, double step, int nbins) const
double sigma
The Gaussian sigma (half) width.
std::vector< double > weight(double start, double step, int nbins, std::vector< double > pvec) const
int poffset_bin() const
Return the absolute impact bin in the binning corresponding to column 0 of the patch.
std::pair< double, double > sigma_range(double nsigma=3.0)
std::shared_ptr< Interface > pointer
Definition: Interface.h:16
std::vector< double > sample(double start, double step, int nsamples) const
Definition: Main.h:22
IDepo::pointer depo() const
Access deposition.
list x
Definition: train.py:276
std::shared_ptr< GaussianDiffusion > pointer
Eigen::ArrayXXf array_xxf
A real, 2D array.
Definition: Array.h:54