Diffuser.h
Go to the documentation of this file.
1 #ifndef WIRECELL_DIFFUSER
2 #define WIRECELL_DIFFUSER
3 
7 #include "WireCellIface/IDepo.h"
8 
9 #include <vector>
10 #include <deque>
11 
12 namespace WireCell {
13 
14 
15  /** Model longitudinal and transverse diffusion of drifted charge.
16  *
17  * WireCell::IDepo objects are inserted and WireCell::IDiffusion
18  * objects are extracted. An internal buffer is kept in order to
19  * assure the output is time ordered by the leading edge of the
20  * diffusion "patch". Depositions are diffused in place so are
21  * assumed to be drifted to whatever location they are wanted.
22  * The IDepo::prior() method is used to find the total drift
23  * distance.
24  *
25  * FIXME: this action is really a compound as it does three things:
26  *
27  * 1) Projects a deposition position onto wire pitch.
28  * 2) Applies arbitrary time offset.
29  * 3) Diffuses the deposition.
30  */
31  class Diffuser : public IDiffuser, public IConfigurable {
32  public:
33 
34  typedef std::pair<double,double> bounds_type;
35 
36 
37  /** Create a diffuser.
38  *
39  * \param pitch gives the wire coordinate system.
40  * \param lbinsize defines the grid spacing in the longitudinal direction.
41  * \param tbinsize defines the grid spacing in the transverse direction.
42  * \param lorigin defines a grid line in the longitudinal direction.
43  * \param torigin defines a grid line in the transverse direction.
44  * \param DL is the longitudinal diffusion coefficient.
45  * \param DT is the transverse diffusion coefficient.
46  * \param drift_velocity is what it sounds like.
47  * \param max_sigma_l is the largest possible longitudinal diffusion.
48  * \param nsigma defines the number of sigma at which to truncate the Gaussian.
49  */
50  Diffuser(const Ray& pitch = Ray(Point(0.0,0.0,0.0),Point(0.0,0.0,5*units::millimeter)),
51  double binsize_l = 2.0*units::millimeter,
52  double time_offset = 0.0*units::microsecond,
53  double origin_l = 0.0*units::microsecond,
54  double DL=5.3*units::centimeter2/units::second,
55  double DT=12.8*units::centimeter2/units::second,
56  double drift_velocity = 1.6*units::millimeter/units::microsecond,
57  double max_sigma_l = 5*units::microsecond,
58  double nsigma=3.0);
59 
60  virtual ~Diffuser();
61 
62  virtual void configure(const WireCell::Configuration& config);
64 
65 
66  virtual void reset();
67 
68  // IQueuedoutNode.
69  virtual bool operator()(const input_pointer& depo, output_queue& outq);
70 
71  /** Diffuse a point charge.
72  *
73  * \param mean_l is the position in the longitudinal direction.
74  * \param mean_t is the position in the transverse direction.
75  * \param sigma_l is the Gaussian sigma in the longitudinal direction.
76  * \param sigma_t is the Gaussian sigma in the transverse direction.
77  * \param weight is the normalization (eg, amount of charge)
78  *
79  * This is a mostly internal method. It does not directly
80  * fill or drain any internal buffers so can be used to test
81  * diffusion directly.
82  */
83  IDiffusion::pointer diffuse(double mean_l, double mean_t,
84  double sigma_l, double sigma_t,
85  double weight = 1.0,
86  IDepo::pointer depo = nullptr);
87 
88  /* Internal function, return the +/- nsigma*sigma bounds
89  * around mean enlarged to fall on bin edges.
90  */
91  bounds_type bounds(double mean, double sigma, double binsize, double origin=0.0);
92 
93 
94  /* Internal function, return a 1D distribution of mean/sigma
95  * binned with zeroth bin at origin and given binsize.
96  */
97  std::vector<double> oned(double mean, double sigma,
98  double binsize,
100 
101 
102  private:
103 
107  double m_origin_l;
108  double m_origin_t;
109  double m_binsize_l;
110  double m_binsize_t;
111  double m_DL, m_DT;
114  double m_nsigma;
115 
116  IDiffusionSet m_input; // to allow for proper output ordering
117 
118  bool m_eos;
119 
120  void dump(const std::string& msg);
121  };
122 
123 }
124 
125 #endif
126 
virtual bool operator()(const input_pointer &depo, output_queue &outq)
The calling signature:
Definition: Diffuser.cxx:117
std::pair< Point, Point > Ray
A line segment running from a first (tail) to a second (head) point.
Definition: Point.h:21
std::shared_ptr< const IDiffusion > pointer
Definition: IData.h:19
void msg(const char *fmt,...)
Definition: message.cpp:107
D3Vector< double > Point
A 3D Cartesian point in double precision.
Definition: Point.h:15
void dump(const std::string &msg)
Definition: Diffuser.cxx:98
virtual void configure(const WireCell::Configuration &config)
Accept a configuration.
Definition: Diffuser.cxx:70
std::string string
Definition: nybbler.cc:12
IDiffusion::pointer diffuse(double mean_l, double mean_t, double sigma_l, double sigma_t, double weight=1.0, IDepo::pointer depo=nullptr)
Definition: Diffuser.cxx:204
Point m_pitch_origin
Definition: Diffuser.h:104
static const double microsecond
Definition: Units.h:94
IDiffusionSet m_input
Definition: Diffuser.h:116
virtual WireCell::Configuration default_configuration() const
Optional, override to return a hard-coded default configuration.
Definition: Diffuser.cxx:50
Vector m_pitch_direction
Definition: Diffuser.h:105
std::deque< output_pointer > output_queue
virtual ~Diffuser()
Definition: Diffuser.cxx:46
std::vector< double > oned(double mean, double sigma, double binsize, const Diffuser::bounds_type &bounds)
Definition: Diffuser.cxx:173
static Config * config
Definition: config.cpp:1054
double m_time_offset
Definition: Diffuser.h:106
double m_binsize_t
Definition: Diffuser.h:110
static const double centimeter2
Definition: Units.h:27
double m_max_sigma_l
Definition: Diffuser.h:113
Diffuser(const Ray &pitch=Ray(Point(0.0, 0.0, 0.0), Point(0.0, 0.0, 5 *units::millimeter)), double binsize_l=2.0 *units::millimeter, double time_offset=0.0 *units::microsecond, double origin_l=0.0 *units::microsecond, double DL=5.3 *units::centimeter2/units::second, double DT=12.8 *units::centimeter2/units::second, double drift_velocity=1.6 *units::millimeter/units::microsecond, double max_sigma_l=5 *units::microsecond, double nsigma=3.0)
Definition: Diffuser.cxx:20
double m_drift_velocity
Definition: Diffuser.h:112
std::pair< double, double > bounds_type
Definition: Diffuser.h:34
Definition: Main.h:22
static const double second
Definition: Units.h:92
static const double millimeter
Definition: Units.h:22
bounds_type bounds(double mean, double sigma, double binsize, double origin=0.0)
Definition: Diffuser.cxx:195
Json::Value Configuration
Definition: Configuration.h:50
std::shared_ptr< const IDepo > input_pointer
std::set< IDiffusion::pointer, IDiffusionCompareLbegin > IDiffusionSet
Definition: IDiffusion.h:66
weight
Definition: test.py:257
double m_binsize_l
Definition: Diffuser.h:109
virtual void reset()
Definition: Diffuser.cxx:93
double mean(sqlite3 *db, std::string const &table_name, std::string const &column_name)
Definition: statistics.cc:15
constexpr Point origin()
Returns a origin position with a point of the specified type.
Definition: geo_vectors.h:227