Response.h
Go to the documentation of this file.
1 #ifndef WIRECELLSIGPROC_RESPONSE
2 #define WIRECELLSIGPROC_RESPONSE
3 
5 #include "WireCellUtil/Binning.h"
6 #include "WireCellUtil/Units.h"
7 #include "WireCellUtil/Array.h"
8 
9 #include "WireCellUtil/Point.h"
10 
11 namespace WireCell {
12 
13 
14  namespace Response {
15 
16  //// Units notice: all quantities are expressed in the WCT
17  //// system of unis. In particular, time is not seconds.
18 
19  // These objects correspond to those defined in the Wire Cell
20  // field response transfer file format schema.
21  namespace Schema {
22 
23  // FIXME: this schema is very specific to Garfield 2D
24  // results. The namespace should reflect that and a more
25  // generic interface should hide it.
26 
27 
28  /// Hold information about the induced current response
29  /// due to passage of a charge along one drift path.
30  struct PathResponse {
31 
32  /// An array holding the induced current for the path on the wire-of-interest.
34 
35  /// The position in the pitch direction to the starting point of the path.
36  double pitchpos;
37 
38  /// The position along the wire direction to the starting point of the path.
39  double wirepos;
40 
41  PathResponse() : pitchpos(0.0), wirepos(-99999.0) {}
43  : current(c), pitchpos(p), wirepos(w) {}
44 
45  ~PathResponse();
46  };
47 
48 
49  /// Hold information about the collection of induced
50  /// current responses on one wire plane.
51  struct PlaneResponse {
52 
53  /// List of PathResponse objects.
54  std::vector<PathResponse> paths;
55 
56  /// A numerical identifier for the plane.
57  int planeid;
58 
59  /// location, in direction of drift, of this plane (in
60  /// same coordinate system as used by
61  /// FieldResponse::origin).
62  double location;
63 
64  /// The pitch distance between neighboring wires.
65  double pitch;
66 
67  PlaneResponse() : planeid(-1), location(0.0), pitch(0.0) {}
68  PlaneResponse(const std::vector<PathResponse>& paths, int pid, double l, double p)
69  : paths(paths), planeid(pid), location(l), pitch(p) {}
70 
71  ~PlaneResponse();
72  };
73 
74  /// Hold info about multiple plane responses in the detector.
75  struct FieldResponse {
76 
77  /// List of PlaneResponse objects.
78  std::vector<PlaneResponse> planes;
79 
80  /// A normalized 3-vector giving direction of axis
81  /// (anti)parallel to nominal drift direction.
83 
84  /// The location on the X-axis where drift paths
85  /// begin. See PlaneResponse::location.
86  double origin;
87 
88  /// Time at which drift paths begin.
89  double tstart;
90 
91  /// The sampling period of the response function.
92  double period;
93 
94  /// The nominal drift speed.
95  double speed;
96 
97  PlaneResponse* plane(int ident) {
98  for (auto& pr : planes) {
99  if (pr.planeid == ident) {
100  return &pr;
101  }
102  }
103  return nullptr;
104  }
105  const PlaneResponse* plane(int ident) const {
106  for (auto& pr : planes) {
107  if (pr.planeid == ident) {
108  return &pr;
109  }
110  }
111  return nullptr;
112  }
113 
114  FieldResponse() : origin(-999.0), tstart(-999.0), period(0.0), speed(0.0) {}
115  FieldResponse(const std::vector<PlaneResponse>& planes, const WireCell::Vector& adir,
116  double o, double t, double p, double s)
117  : planes(planes), axis(adir), origin(o), tstart(t), period(p), speed(s) {}
118  ~FieldResponse();
119  };
120 
121  FieldResponse load(const char* filename);
122  void dump(const char* filename, const FieldResponse& fr);
123 
124  }
125 
126 
127  /// Return a reduced FieldResponse structure where the
128  /// Path::Response::current arrays are reduced by averaging
129  /// over each wire region.
131 
133 
134 
135  /// Return the plane's response as a 2D array. This is a
136  /// straight copy of the plane's current vectors into rows of
137  /// the returned array. The first "path" will be in row 0.
138  /// Each column thus contains the same sample (aka tick)
139  /// across all current waveforms. Column 0 is first sample.
140  /// The plane response input data is taken at face value an
141  /// not attempt to resolve any implicit symmetries is made.
143  Array::array_xxf as_array(const Schema::PlaneResponse& pr, int set_nrows, int set_ncols);
144 
145  /// The cold electronics response function.
146  double coldelec(double time, double gain=7.8, double shaping=1.0*units::us);
147  // HF filter format
148  double hf_filter(double freq, double sigma = 1, double power = 2, bool zero_freq_removal = true);
149 
150  // LF filter format
151  double lf_filter(double freq, double tau = 0.02);
152 
153  class Generator {
154  public:
155  virtual ~Generator();
156  virtual double operator()(double time) const = 0;
157 
158  /// FIXME: eradicate Domain in favor of Binning.
159  WireCell::Waveform::realseq_t generate(const WireCell::Waveform::Domain& domain, int nsamples);
160  /// Lay down the function into a binned waveform.
162  };
163 
164  /// A functional object caching gain and shape.
165  class ColdElec : public Generator {
166  const double _g, _s;
167  public:
168  // Create cold electronics response function. Gain is an
169  // arbitrary scale, typically in [voltage/charge], and
170  // shaping time in WCT system of units.
171  ColdElec(double gain=14*units::mV/units::fC, double shaping=1.0*units::us);
172  virtual ~ColdElec();
173 
174  // Return the response at given time. Time is in WCT
175  // system of units.
176  virtual double operator()(double time) const;
177 
178  };
179 
180  /// A functional object giving the response as a function of
181  /// time to a simple RC circuit.
182  class SimpleRC : public Generator {
183  const double _width, _offset, _tick;
184  public:
185  // Create (current) response function for a simple RC
186  // circuit where a unit of charge is placed on the cap at
187  // time offset and circuit has RC time constant of given
188  // width. Time is in WCT system of units.
189  SimpleRC(double width=1.0*units::ms, double tick=0.5*units::us, double offset=0.0);
190  virtual ~SimpleRC();
191 
192  // Return the response at a given time. Time in WCT
193  // system of units. Warning: to get the delta function,
194  // one must call *exactly* at the offset time.
195  virtual double operator()(double time) const;
196 
197  };
198 
199  class SysResp : public Generator{
200  const double _tick, _mag, _smear, _offset;
201  public:
202  SysResp(double tick=0.5*units::us, double magnitude=1.0, double smear=0.0*units::us, double offset=0.0*units::us);
203  virtual ~SysResp();
204  virtual double operator()(double time) const;
205  };
206 
207  class LfFilter : public Generator{
208  const double _tau;
209  public:
210  LfFilter(double tau);
211  virtual ~LfFilter();
212  virtual double operator()(double freq) const;
213  };
214 
215  class HfFilter : public Generator{
216  const double _sigma, _power;
217  const bool _flag;
218  public:
219  HfFilter(double sigma, double power, bool flag);
220  virtual ~HfFilter();
221  virtual double operator()(double freq) const;
222  };
223 
224 
225 
226  }
227 }
228 
229 #endif
double pitch
The pitch distance between neighboring wires.
Definition: Response.h:65
double tstart
Time at which drift paths begin.
Definition: Response.h:89
Sequence< real_t > realseq_t
Definition: Waveform.h:31
Schema::FieldResponse wire_region_average(const Schema::FieldResponse &fr)
Definition: Response.cxx:99
PlaneResponse * plane(int ident)
Definition: Response.h:97
static const double mV
Definition: Units.h:180
double period
The sampling period of the response function.
Definition: Response.h:92
PlaneResponse(const std::vector< PathResponse > &paths, int pid, double l, double p)
Definition: Response.h:68
A functional object caching gain and shape.
Definition: Response.h:165
string filename
Definition: train.py:213
static QStrList * l
Definition: config.cpp:1044
const double tick
static const double ms
Definition: Units.h:104
void dump(const char *filename, const FieldResponse &fr)
Definition: Response.cxx:90
Binning tbins(nticks, t0, t0+readout_time)
const double width
Array::array_xxf as_array(const Schema::PlaneResponse &pr)
Definition: Response.cxx:279
PathResponse(const WireCell::Waveform::realseq_t &c, double p, double w)
Definition: Response.h:42
Schema::FieldResponse average_1D(const Schema::FieldResponse &fr)
Definition: Response.cxx:224
std::pair< double, double > Domain
Definition: Waveform.h:75
double coldelec(double time, double gain=7.8, double shaping=1.0 *units::us)
The cold electronics response function.
Definition: Response.cxx:350
double pitchpos
The position in the pitch direction to the starting point of the path.
Definition: Response.h:36
std::vector< PlaneResponse > planes
List of PlaneResponse objects.
Definition: Response.h:78
static const double fC
Definition: Units.h:113
FieldResponse(const std::vector< PlaneResponse > &planes, const WireCell::Vector &adir, double o, double t, double p, double s)
Definition: Response.h:115
FieldResponse load(const char *filename)
Definition: Response.cxx:39
double wirepos
The position along the wire direction to the starting point of the path.
Definition: Response.h:39
Definition: Main.h:22
WireCell::Waveform::realseq_t current
An array holding the induced current for the path on the wire-of-interest.
Definition: Response.h:33
p
Definition: test.py:223
double hf_filter(double freq, double sigma=1, double power=2, bool zero_freq_removal=true)
Definition: Response.cxx:377
realseq_t magnitude(const compseq_t &seq)
Return the magnitude or absolute value of the sequence.
Definition: Waveform.cxx:65
const PlaneResponse * plane(int ident) const
Definition: Response.h:105
static const double us
Definition: Units.h:105
std::vector< PathResponse > paths
List of PathResponse objects.
Definition: Response.h:54
Hold info about multiple plane responses in the detector.
Definition: Response.h:75
static QCString * s
Definition: config.cpp:1042
int planeid
A numerical identifier for the plane.
Definition: Response.h:57
Eigen::ArrayXXf array_xxf
A real, 2D array.
Definition: Array.h:54
double lf_filter(double freq, double tau=0.02)
Definition: Response.cxx:386
double speed
The nominal drift speed.
Definition: Response.h:95