Functions
test_MultiChannelNoiseRemovalService.cxx File Reference
#include <string>
#include <iostream>
#include <fstream>
#include <iomanip>
#include "art/Framework/Services/Registry/ServiceHandle.h"
#include "dunecore/ArtSupport/ArtServiceHelper.h"
#include "dunecore/DuneInterface/Service/AdcNoiseRemovalService.h"
#include <cassert>

Go to the source code of this file.

Functions

int test_MultiChannelNoiseRemovalService (int a_LogLevel=1)
 
int main (int argc, char *argv[])
 

Function Documentation

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

Definition at line 112 of file test_MultiChannelNoiseRemovalService.cxx.

112  {
113  int a_LogLevel = -1;
114  if ( argc > 1 ) {
115  istringstream ssarg(argv[1]);
116  ssarg >> a_LogLevel;
117  }
118  return test_MultiChannelNoiseRemovalService(a_LogLevel);
119 }
int test_MultiChannelNoiseRemovalService(int a_LogLevel=1)
int test_MultiChannelNoiseRemovalService ( int  a_LogLevel = 1)

Definition at line 33 of file test_MultiChannelNoiseRemovalService.cxx.

33  {
34  const string myname = "test_MultiChannelNoiseRemovalService: ";
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;
50  oss << "services.AdcNoiseRemovalService: {" << endl;
51  oss << " service_provider: MultiChannelNoiseRemovalService" << endl;
52  oss << " LogLevel: " << a_LogLevel << endl;
53  oss << "}" << endl;
55 
56  cout << myname << line << endl;
57  cout << myname << "Create samples." << endl;
58  const unsigned int nchan = 5;
59  double f[nchan] = {0.11, 0.22, 0.33, 0.44, 0.55};
60  const unsigned int nsig = 100;
61  AdcChannelDataMap acdmap;
62  vector<AdcSignalVector> sigsin(nchan); // Record the stae before noise removal.
63  vector<AdcSignalVector> sigsexp(nchan); // Record the expected state.
64  for ( unsigned int icha=0; icha<nchan; ++icha ) {
65  AdcChannel chan = 100 + icha;
66  acdmap[chan] = AdcChannelData();
67  AdcChannelData& acd = acdmap[chan];
68  AdcSignalVector& exp = sigsexp[icha];
69  AdcSignalVector& in = sigsin[icha];
70  acd.setChannelInfo(chan);
71  for ( unsigned int isig=0; isig<nsig; ++isig ) {
72  acd.samples.push_back(20*sin(f[icha]*isig));
73  acd.flags.push_back(AdcGood);
74  }
75  AdcSignalVector& sigs = acd.samples;
76  AdcSignalVector sigsin = sigs;
77  in = sigs;
78  exp = sigs;
79  for ( AdcSignal& sig : exp ) if ( fabs(sig) < threshold ) sig = 0.0;
80  }
81 
82  cout << myname << line << endl;
83  cout << myname << "Fetch the noise removal." << endl;
85  hanr->print(cout, myname);
86 
87  cout << myname << line << endl;
88  cout << myname << "Remove noise." << endl;
89  assert( hanr->update(acdmap) == 0 );
90  for ( unsigned int icha=0; icha<nchan; ++icha ) {
91  AdcChannel chan = 100 + icha;
92  AdcChannelData& acd = acdmap[chan];
93  AdcSignalVector& sigs = acd.samples;
94  cout << myname << "-------" << endl;
95  cout << myname << "Channel " << chan << endl;
96  for ( unsigned int isig=0; isig<nsig; ++isig ) {
97  cout << myname << setw(4) << isig << ": "
98  << fixed << setprecision(1) << setw(10) << sigsin[icha][isig]
99  << fixed << setprecision(1) << setw(10) << sigs[isig]
100  << endl;
101  assert( sigs[isig] == sigsexp[icha][isig] );
102  }
103  }
104 
105  cout << myname << line << endl;
106  cout << myname << "Done." << endl;
107  return 0;
108 }
float AdcSignal
Definition: AdcTypes.h:21
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 int update(AdcChannelDataMap &datamap) const =0
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
virtual std::ostream & print(std::ostream &out=std::cout, std::string prefix="") const =0
unsigned int AdcChannel
Definition: AdcTypes.h:50
void line(double t, double *p, double &x, double &y, double &z)
std::vector< AdcSignal > AdcSignalVector
Definition: AdcTypes.h:22
std::map< AdcChannel, AdcChannelData > AdcChannelDataMap
AdcSignalVector samples
QTextStream & endl(QTextStream &s)
AdcFlagVector flags