test_ThresholdNoiseRemovalService.cxx
Go to the documentation of this file.
1 // test_ThresholdNoiseRemovalService.cxx
2 //
3 // David Adams
4 // May 2016
5 //
6 // Test ThresholdNoiseRemovalService.
7 //
8 
9 #include <string>
10 #include <iostream>
11 #include <fstream>
12 #include <iomanip>
16 
17 #undef NDEBUG
18 #include <cassert>
19 
20 using std::string;
21 using std::vector;
22 using std::cout;
23 using std::endl;
24 using std::istringstream;
25 using std::ofstream;
26 using std::setw;
27 using std::setprecision;
28 using std::fixed;
29 using art::ServiceHandle;
30 
31 //**********************************************************************
32 
33 int test_ThresholdNoiseRemovalService(int a_LogLevel =1) {
34  const string myname = "test_ThresholdNoiseRemovalService: ";
35 #ifdef NDEBUG
36  cout << myname << "NDEBUG must be off." << endl;
37  abort();
38 #endif
39  string line = "-----------------------------";
40 
41  cout << myname << line << endl;
42  cout << myname << "Create top-level FCL." << endl;
43  AdcSignal threshold = 4.0;
44  std::ostringstream oss;
45  oss << "services.AdcChannelNoiseRemovalService: {" << endl;
46  oss << " service_provider: ThresholdNoiseRemovalService" << endl;
47  oss << " Threshold: " << threshold << endl;
48  oss << " LogLevel: " << a_LogLevel << endl;
49  oss << "}" << endl;
51 
52  const unsigned int nsig = 100;
53  AdcChannelData acd;
54  acd.setChannelInfo(100);
55  for ( unsigned int isig=0; isig<nsig; ++isig ) {
56  acd.samples.push_back(20*sin(0.47*isig));
57  acd.flags.push_back(AdcGood);
58  }
59  AdcSignalVector& sigs = acd.samples;
60  AdcSignalVector sigsin = sigs;
61  AdcSignalVector sigsexp = sigs;
62  for ( AdcSignal& sig : sigsexp ) if ( fabs(sig) < threshold ) sig = 0.0;
63 
64  cout << myname << line << endl;
65  cout << myname << "Fetch the noise removal." << endl;
67  hanr->print(cout, myname);
68 
69  cout << myname << line << endl;
70  cout << myname << "Remove noise." << endl;
71  assert( hanr->update(acd) == 0 );
72  for ( unsigned int isig=0; isig<nsig; ++isig ) {
73  cout << myname << setw(4) << isig << ": "
74  << fixed << setprecision(1) << setw(10) << sigsin[isig]
75  << fixed << setprecision(1) << setw(10) << sigs[isig]
76  << endl;
77  assert( sigs[isig] == sigsexp[isig] );
78  }
79 
80  cout << myname << line << endl;
81  cout << myname << "Done." << endl;
82  return 0;
83 }
84 
85 //**********************************************************************
86 
87 int main(int argc, char* argv[]) {
88  int a_LogLevel = -1;
89  if ( argc > 1 ) {
90  istringstream ssarg(argv[1]);
91  ssarg >> a_LogLevel;
92  }
93  return test_ThresholdNoiseRemovalService(a_LogLevel);
94 }
95 
96 //**********************************************************************
std::string string
Definition: nybbler.cc:12
float AdcSignal
Definition: AdcTypes.h:21
struct vector vector
static void load_services(std::string const &config)
Q_EXPORT QTSManip setprecision(int p)
Definition: qtextstream.h:343
const AdcFlag AdcGood
Definition: AdcTypes.h:32
void setChannelInfo(ChannelInfoPtr pchi)
virtual std::ostream & print(std::ostream &out=std::cout, std::string prefix="") const =0
int main(int argc, char *argv[])
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
int test_ThresholdNoiseRemovalService(int a_LogLevel=1)
void line(double t, double *p, double &x, double &y, double &z)
virtual int update(AdcChannelData &data) const =0
std::vector< AdcSignal > AdcSignalVector
Definition: AdcTypes.h:22
AdcSignalVector samples
QTextStream & endl(QTextStream &s)
AdcFlagVector flags