Drifter.h
Go to the documentation of this file.
1 #ifndef WIRECELL_GEN_DRIFTER
2 #define WIRECELL_GEN_DRIFTER
3 
7 #include "WireCellUtil/Units.h"
8 #include "WireCellUtil/Logging.h"
9 
10 
11 #include <set>
12 
13 namespace WireCell {
14 
15  // The xregions are a list of objects specifying locations on the
16  // X (drift) axis of the coordinate system in which depo
17  // positions are defined. Three locations may be defined.
18  //
19  //
20 
21  namespace Gen {
22 
23  /** This component drifts depos bounded by planes
24  * perpendicular to the X-axis. The boundary planes are
25  * specified with the "xregions" list. Each list is an object
26  * fully specified with a "cathode" an "anode" and a
27  * "response" attribute giving X locations in the same
28  * coordinate system as depos of three planes.
29  *
30  * - cathode :: a plane which bounds the maximum possible drift.
31  * - anode :: a plane which bounds the minimum possible drift.
32  * - response :: a plane to which all depositions are drifted.
33  *
34  * If "anode" is not given then its value is take to be that of
35  * "response" and vice versa and at least one must be specified.
36  * A "cathode" value must be specified.
37  *
38  * Any depo not falling between "anode" and "cathode" will be
39  * dropped.
40  *
41  * Any depo falling between "response" and "cathode" will be
42  * drifted to the "response" plane.
43  *
44  * Any depo falling between "anode" and "response" will be
45  * ANTI-DRIFTED to the "response" plane. Ie, it will be
46  * "BACKED UP" in space an time as if it had be produced
47  * earlier and at the response plane.
48  *
49  * Input depositions must be ordered in absolute time (their
50  * current time) and output depositions are produced ordered
51  * by their time after being drifted to the response plane.
52  *
53  * Diffusion and absorption effects and also, optionally,
54  * fluctuations are applied. Fano factor and Recombination
55  * are not applied in this component (see IRecombinationModel
56  * implementations).
57  *
58  * Typically a drifter is used just prior to a ductor and in
59  * such cases the "response" plane should be made coincident
60  * with the non-physical "response plane" which defines the
61  * starting point for the field response functions. The
62  * location of the response plane *realtive* to the wire
63  * planes can be found using:
64  *
65  * $ wriecell-sigproc response-info garfield-1d-3planes-21wires-6impacts-dune-v1.json.bz2
66  * origin:10.00 cm, period:0.10 us, tstart:0.00 us, speed:1.60 mm/us, axis:(1.00,0.00,0.00)
67  * plane:0, location:9.4200mm, pitch:4.7100mm
68  * plane:1, location:4.7100mm, pitch:4.7100mm
69  * plane:2, location:0.0000mm, pitch:4.7100mm
70  *
71  * Here, "origin" gives the location of the response plane.
72  * The location of the wire planes according to wire geometry
73  * can be similarly dumped.
74  *
75  * $ wirecell-util wires-info protodune-wires-larsoft-v3.json.bz2
76  * anode:0 face:0 X=[-3584.63,-3584.63]mm Y=[6066.70,6066.70]mm Z=[7.92,7.92]mm
77  * 0: x=-3584.63mm dx=9.5250mm
78  * 1: x=-3589.39mm dx=4.7620mm
79  * 2: x=-3594.16mm dx=0.0000mm
80  * ....
81  * anode:5 face:1 X=[3584.63,3584.63]mm Y=[6066.70,6066.70]mm Z=[6940.01,6940.01]mm
82  * 0: x=3584.63mm dx=-9.5250mm
83  * 1: x=3589.39mm dx=-4.7620mm
84  * 2: x=3594.16mm dx=0.0000mm
85  *
86  * Note, as can see, these two sources of information may not
87  * be consistent w.r.t. the inter-plane separation distance
88  * (4.71mm and 4.76mm, respectively). This mismatch will
89  * result in a relative shift in time between the planes for
90  * various waveform features (eg induction zero crossings and
91  * collection peak).
92  *
93  * For the example above, likely candidates for "anode" X
94  * locations are:
95  *
96  * x = -3594.16mm + 10cm
97  *
98  * and
99  *
100  * x = +3594.16mm - 10cm
101  */
102  class Drifter : public IDrifter, public IConfigurable {
103  public:
104  Drifter();
105  virtual ~Drifter();
106 
107  virtual void reset();
108  virtual bool operator()(const input_pointer& depo, output_queue& outq);
109 
110  /// WireCell::IConfigurable interface.
111  virtual void configure(const WireCell::Configuration& config);
113 
114 
115  // Implementation methods.
116 
117  // Do actual transport, producing a new depo
119 
120  // Return the "proper time" for a deposition
121  double proper_time(IDepo::pointer depo);
122 
123  bool insert(const input_pointer& depo);
124  void flush(output_queue& outq);
125  void flush_ripe(output_queue& outq, double now);
126 
127  // Reset lifetime e.g. based on a larsoft database.
128  // Detailed implementation in a subclass.
129  virtual void set_lifetime(double lifetime_to_set){
130  m_lifetime = lifetime_to_set;
131  };
132 
133  private:
134 
137 
138  // Longitudinal and Transverse coefficients of diffusion
139  // in units of [length^2]/[time].
140  double m_DL, m_DT;
141 
142  // Electron absorption lifetime.
143  double m_lifetime;
144 
145  // If true, fluctuate by number of absorbed electrons.
147 
148  double m_speed; // drift speeds
149  double m_toffset; // time offset
150 
152 
153 
154  // keep the depos sorted by time
156  bool operator()(const IDepo::pointer& lhs, const IDepo::pointer& rhs) const;
157  };
158 
159  // A little helper to carry the region extent and depo buffers.
160  struct Xregion {
162  double anode, response, cathode;
163  typedef std::set<IDepo::pointer, DepoTimeCompare> ordered_depos_t;
164  ordered_depos_t depos; // buffer depos
165 
166  bool inside_bulk(double x) const;
167  bool inside_response(double x) const;
168 
169  };
170  std::vector<Xregion> m_xregions;
171 
172  struct IsInsideBulk {
174  IsInsideBulk(const input_pointer& depo) : depo(depo) {}
175  bool operator()(const Xregion& xr) const { return xr.inside_bulk(depo->pos().x()); }
176  };
177  struct IsInsideResp {
179  IsInsideResp(const input_pointer& depo) : depo(depo) {}
180  bool operator()(const Xregion& xr) const { return xr.inside_response(depo->pos().x()); }
181  };
182 
184  }; // Drifter
185 
186  }
187 
188 }
189 
190 #endif
std::shared_ptr< const IDepo > pointer
Definition: IData.h:19
IsInsideResp(const input_pointer &depo)
Definition: Drifter.h:179
bool inside_bulk(double x) const
Definition: Drifter.cxx:53
virtual void reset()
Definition: Drifter.cxx:119
std::string string
Definition: nybbler.cc:12
bool operator()(const Xregion &xr) const
Definition: Drifter.h:175
std::vector< Xregion > m_xregions
Definition: Drifter.h:170
virtual void set_lifetime(double lifetime_to_set)
Definition: Drifter.h:129
cfg
Definition: dbjson.py:29
IRandom::pointer m_rng
Definition: Drifter.h:131
std::deque< output_pointer > output_queue
void flush_ripe(output_queue &outq, double now)
Definition: Drifter.cxx:219
static Config * config
Definition: config.cpp:1054
std::string m_rng_tn
Definition: Drifter.h:136
bool insert(const input_pointer &depo)
Definition: Drifter.cxx:125
Log::logptr_t l
Definition: Drifter.h:183
bool operator()(const Xregion &xr) const
Definition: Drifter.h:180
std::shared_ptr< Interface > pointer
Definition: Interface.h:16
double proper_time(IDepo::pointer depo)
bool inside_response(double x) const
Definition: Drifter.cxx:49
const input_pointer & depo
Definition: Drifter.h:173
void flush(output_queue &outq)
Definition: Drifter.cxx:206
std::set< IDepo::pointer, DepoTimeCompare > ordered_depos_t
Definition: Drifter.h:163
std::shared_ptr< spdlog::logger > logptr_t
Definition: Logging.h:24
IsInsideBulk(const input_pointer &depo)
Definition: Drifter.h:174
Definition: Main.h:22
virtual bool operator()(const input_pointer &depo, output_queue &outq)
The calling signature:
Definition: Drifter.cxx:252
const input_pointer & depo
Definition: Drifter.h:178
bool operator()(const IDepo::pointer &lhs, const IDepo::pointer &rhs) const
Definition: Drifter.cxx:21
Json::Value Configuration
Definition: Configuration.h:50
std::shared_ptr< const IDepo > input_pointer
list x
Definition: train.py:276
virtual WireCell::Configuration default_configuration() const
Optional, override to return a hard-coded default configuration.
Definition: Drifter.cxx:78
virtual void configure(const WireCell::Configuration &config)
WireCell::IConfigurable interface.
Definition: Drifter.cxx:93
IDepo::pointer transport(IDepo::pointer depo)