Functions
test_waveform.cxx File Reference
#include "WireCellUtil/Waveform.h"
#include "WireCellUtil/Testing.h"
#include <iostream>
#include <algorithm>
#include <complex>

Go to the source code of this file.

Functions

void test_transform ()
 
void test_mean_rms ()
 
void test_fft ()
 
void test_complex ()
 
void test_arithmetic ()
 
int main (int argc, char *argv[])
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 100 of file test_waveform.cxx.

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 }
void test_arithmetic()
void test_mean_rms()
void test_complex()
void test_fft()
QTextStream & endl(QTextStream &s)
void test_transform()
void test_arithmetic ( )

Definition at line 72 of file test_waveform.cxx.

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 }
Sequence< real_t > realseq_t
Definition: Waveform.h:31
#define Assert
Definition: Testing.h:7
void increase(Sequence< Val > &seq, Val scalar)
Increase (shift) sequence values by scalar.
Definition: Waveform.h:129
void scale(Sequence< Val > &seq, Val scalar)
Scale (multiply) sequence values by scalar.
Definition: Waveform.h:146
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
void test_complex ( )

Definition at line 66 of file test_waveform.cxx.

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 }
array_xxf idft(const array_xxc &arr)
Definition: Array.cxx:96
Sequence< complex_t > compseq_t
A complex-valued sequence, eg for discrete spectrum powers.
Definition: Waveform.h:34
void test_fft ( )

Definition at line 47 of file test_waveform.cxx.

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 }
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
float real_t
The type for the signal in each bin.
Definition: Waveform.h:18
T abs(T value)
array_xxc dft(const array_xxf &arr)
Definition: Array.cxx:15
static QCString * s
Definition: config.cpp:1042
QTextStream & endl(QTextStream &s)
void test_mean_rms ( )

Definition at line 36 of file test_waveform.cxx.

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 }
static const double m
Definition: Units.h:79
Sequence< real_t > realseq_t
Definition: Waveform.h:31
static const double us
Definition: Units.h:101
std::pair< double, double > mean_rms(const realseq_t &wave)
Definition: Waveform.cxx:24
double median(sqlite3 *db, std::string const &table_name, std::string const &column_name)
Definition: statistics.cc:25
QTextStream & endl(QTextStream &s)
void test_transform ( )

Definition at line 16 of file test_waveform.cxx.

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 }
Sequence< real_t > realseq_t
Definition: Waveform.h:31
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
list x
Definition: train.py:276