Array.h
Go to the documentation of this file.
1 /**
2  Wire Cell uses Eigen3 arrays for holding large block data like the
3  waveforms from one plane of one readout frame. This header
4  provides a shim between Eigen3 and the rest of Wire Cell.
5 
6  There are a few important rules:
7 
8  - Eigen3 Arrays have element-wise arithmetic and Matrices have
9  matrix-like arithmetic otherwise are similar.
10 
11  - They have .array() and .matrix() methods to produce one from the other.
12 
13  - Arrays are indexed by (row,col) order.
14 
15  - An Eigen3 Vector is a 1D Matrix of shape (N,1), again, (row,col).
16 
17  - A row, column or block from an array references the original
18  array so can not live beyond it.
19 
20  - In Wire Cell large arrays are accessed via const shared pointer.
21 
22  Usage examples are given below.
23  */
24 
25 
26 #ifndef WIRECELL_ARRAY
27 #define WIRECELL_ARRAY
28 
29 #include "WireCellUtil/Waveform.h"
30 
31 #include <Eigen/Core>
32 
33 #include <memory>
34 #include <vector>
35 
36 
37 namespace WireCell {
38 
39  namespace Array {
40 
41  typedef Eigen::ArrayXf array_xf;
42  typedef Eigen::ArrayXcf array_xc;
43 
44  /// A 16 bit short integer 2D array.
45  typedef Eigen::Array<short, Eigen::Dynamic, Eigen::Dynamic> array_xxs;
46 
47  /// Integer
48  typedef Eigen::Array<int, Eigen::Dynamic, Eigen::Dynamic> array_xxi;
49 
50  /// Integer
51  typedef Eigen::Array<long, Eigen::Dynamic, Eigen::Dynamic> array_xxl;
52 
53  /// A real, 2D array
54  typedef Eigen::ArrayXXf array_xxf;
55 
56  /// A complex, 2D array
57  typedef Eigen::ArrayXXcf array_xxc;
58 
59 
60  /** Perform full, 2D discrete Fourier transform on a real 2D
61  array.
62 
63  The full 2D DFT first performs a 1D DFT (real->complex) on
64  each individual row and then a 1D DFT (complex->complex)
65  on each resulting column.
66 
67  const_shared_array_xxf arr = ...;
68  const_shared_array_xxc spec = dft(*arr);
69 
70  // ...
71 
72  const_shared_array_xxf arr2 = idft(*spec);
73  */
74  array_xxc dft(const array_xxf& arr);
75  array_xxf idft(const array_xxc& arr);
76 
77  /** Partial, 1D DFT and inverse DFT along one dimension of an
78  * array. Each row is transformed if dim=0, each column if
79  * dim=1. The transfer is either real->complex (rc),
80  * complex->complex(cc) or complex->real(cr).
81  *
82  * The full 2D DFT should be used unless an intermediate
83  * filter is required as it will avoid producing some
84  * temporaries.
85  *
86  * Conceptually:
87  *
88  * auto xxc = dft(xxf);
89  *
90  * is equivalent to
91  *
92  * auto tmp = dft_rc(xxf, 0);
93  * auto xxc = dft_cc(tmp, 1);
94  *
95  * and:
96  *
97  * auto xxf = idft(xxc)
98  *
99  * is equivalent to:
100  *
101  * auto tmp = idft_cc(xxc, 1);
102  * auto xxf = idft_rc(tmp, 0);
103  */
104  array_xxc dft_rc(const array_xxf& arr, int dim=0);
105  array_xxc dft_cc(const array_xxc& arr, int dim=1);
106  array_xxc idft_cc(const array_xxc& arr, int dim=1);
107  array_xxf idft_cr(const array_xxc& arr, int dim=0);
108 
109  /** Perform 2D deconvolution.
110 
111  This will perform a 2D forward DFT, do an
112  element-by-element multiplication of that
113  periodicity/frequency space matrix by the filter and then
114  perform an 2D inverse DFT.
115 
116  */
117  array_xxf deconv(const array_xxf& arr, const array_xxc& filter);
118 
119  }
120 }
121 
122 #endif
Eigen::Array< long, Eigen::Dynamic, Eigen::Dynamic > array_xxl
Integer.
Definition: Array.h:51
array_xxc dft_cc(const array_xxc &arr, int dim=1)
Definition: Array.cxx:67
array_xxf idft_cr(const array_xxc &arr, int dim=0)
Definition: Array.cxx:153
Eigen::ArrayXf array_xf
Definition: Array.h:41
Eigen::ArrayXXcf array_xxc
A complex, 2D array.
Definition: Array.h:57
array_xxc dft_rc(const array_xxf &arr, int dim=0)
Definition: Array.cxx:40
Eigen::ArrayXcf array_xc
Definition: Array.h:42
#define Array
Definition: scanner.cpp:11549
array_xxc idft_cc(const array_xxc &arr, int dim=1)
Definition: Array.cxx:125
array_xxf deconv(const array_xxf &arr, const array_xxc &filter)
Definition: Array.cxx:187
Eigen::Array< short, Eigen::Dynamic, Eigen::Dynamic > array_xxs
A 16 bit short integer 2D array.
Definition: Array.h:45
Definition: Main.h:22
array_xxf idft(const array_xxc &arr)
Definition: Array.cxx:96
array_xxc dft(const array_xxf &arr)
Definition: Array.cxx:15
Eigen::Array< int, Eigen::Dynamic, Eigen::Dynamic > array_xxi
Integer.
Definition: Array.h:48
Eigen::ArrayXXf array_xxf
A real, 2D array.
Definition: Array.h:54