test_waveform.cxx
Go to the documentation of this file.
2 #include "WireCellUtil/Testing.h"
3 
4 #include <iostream>
5 #include <algorithm>
6 #include <complex>
7 
8 
9 
10 using std::cout;
11 using std::cerr;
12 using std::endl;
13 using std::vector;
14 using namespace WireCell;
15 
17 {
18  const int baseline = 1000;
19  const int nticks = 100;
20  const int period = 10;
21 
22  Waveform::realseq_t wf1(nticks), wf2(nticks);
23 
24  for (int ind=0; ind<nticks; ++ind) {
25  wf1[ind] = baseline + ind%period;
26  }
27 
28  transform(wf1.begin(), wf1.end(), wf2.begin(),
29  [](int x)->int{return x - baseline;});
30 
31  for (int ind=0; ind<nticks; ++ind) {
32  Assert(wf1[ind]-baseline == wf2[ind]);
33  }
34 }
35 
37 {
38  Waveform::realseq_t v{1.0,1.0,2.0,3.0,4.0,4.0,4.0,3.0};
39 
40  auto us = Waveform::mean_rms(v);
41  auto m = Waveform::median(v);
42 
43  cerr << us.first << " +/- " << us.second << " med=" << m << endl;
44 }
45 
46 
47 void test_fft()
48 {
50  const int nbins = 360;
51  for (int ind=0; ind<nbins; ++ind) {
52  double phi = ind*3.1415/180.0;
53  Waveform::real_t val = sin(phi) + sin(11.0/7.0*phi);
54  s.push_back(val);
55  }
56 
57  auto spec = Waveform::dft(s);
58  for (int ind=0; ind<nbins; ++ind) {
59  auto c = spec[ind];
60  cerr << ind << "\ts=" << s[ind] <<"\tc="<< c << "\tmag=" << std::abs(c) << "\tphi=" << std::arg(c) << endl;
61  }
62  cerr << s.size() << " " << spec.size() << endl;
63 }
64 
65 
67 {
68  Waveform::compseq_t cv{{1.1,2.2},{-3.3,4.4},{0,0},{1,0},{0,1},{-1,0},{0,-1}};
69  auto bogus = Waveform::idft(cv);
70 }
71 
73 {
74  using namespace WireCell::Waveform;
75  realseq_t v{0.0,1.0,2.0};
76  auto v2 = v;
77 
78  increase(v, 2.0);
79  Assert(v[0] == 2.0);
80  Assert(v[1] == 3.0);
81  Assert(v[2] == 4.0);
82  increase(v2, v);
83  Assert(v2[0] = 2.0);
84  Assert(v2[0] = 4.0);
85  Assert(v2[0] = 6.0);
86 
87  scale(v, 2.0);
88  scale(v2, v);
89 
90 
91  compseq_t cv{{1.1,2.2},{-3.3,4.4},{0,0},{1,0},{0,1},{-1,0},{0,-1}};
92  auto cv2 = cv;
93 
94  increase(cv, complex_t(1.0,0.0));
95  increase(cv2, cv);
96  scale(cv, complex_t(1.0,0.0));
97  scale(cv2, cv);
98 }
99 
100 int main(int argc, char* argv[])
101 {
102  test_transform();
103  test_fft();
104  test_complex();
105  test_mean_rms();
106  test_arithmetic();
107 
108  cerr << "bye." << endl;
109  return 0;
110 }
static const double m
Definition: Units.h:79
void test_arithmetic()
Sequence< real_t > realseq_t
Definition: Waveform.h:31
internal::named_arg< T, char > arg(string_view name, const T &arg)
Definition: core.h:1391
struct vector vector
float real_t
The type for the signal in each bin.
Definition: Waveform.h:18
const int nticks
tagset_t transform(const tagset_t &ts, const ruleset_t &rs, bool all_rules=true)
Definition: TagRules.cxx:43
#define Assert
Definition: Testing.h:7
real_t median(realseq_t &wave)
Definition: Waveform.cxx:76
T abs(T value)
compseq_t dft(realseq_t seq)
Definition: Waveform.cxx:141
void increase(Sequence< Val > &seq, Val scalar)
Increase (shift) sequence values by scalar.
Definition: Waveform.h:129
void test_mean_rms()
Definition: Main.h:22
void test_complex()
void scale(Sequence< Val > &seq, Val scalar)
Scale (multiply) sequence values by scalar.
Definition: Waveform.h:146
static const double us
Definition: Units.h:101
realseq_t idft(compseq_t spec)
Definition: Waveform.cxx:149
void test_fft()
int main(int argc, char *argv[])
std::pair< double, double > mean_rms(const realseq_t &wave)
Definition: Waveform.cxx:24
list x
Definition: train.py:276
std::complex< float > complex_t
The type for the spectrum in each bin.
Definition: Waveform.h:21
Sequence< complex_t > compseq_t
A complex-valued sequence, eg for discrete spectrum powers.
Definition: Waveform.h:34
static QCString * s
Definition: config.cpp:1042
QTextStream & endl(QTextStream &s)
void test_transform()