test_DuneDeconvolutionService.cxx
Go to the documentation of this file.
1 // test_DuneDeconvolutionService.cxx
2 //
3 // David Adams
4 // May 2016
5 //
6 // Test DuneDeconvolutionService.
7 //
8 // This test crashes in cleanup until this problem is resolved:
9 // https://cdcvs.fnal.gov/redmine/issues/10618
10 
11 #include <string>
12 #include <iostream>
13 #include <sstream>
14 #include <fstream>
15 #include <iomanip>
21 
22 #undef NDEBUG
23 #include <cassert>
24 
25 using std::string;
26 using std::vector;
27 using std::cout;
28 using std::endl;
29 using std::istringstream;
30 using std::ofstream;
31 using std::setw;
32 using std::setprecision;
33 using std::fixed;
34 using art::ServiceHandle;
35 
36 typedef vector<unsigned int> IndexVector;
37 
38 //**********************************************************************
39 
40 int test_DuneDeconvolutionService(int a_LogLevel =-1) {
41  const string myname = "test_DuneDeconvolutionService: ";
42 #ifdef NDEBUG
43  cout << myname << "NDEBUG must be off." << endl;
44  abort();
45 #endif
46  string line = "-----------------------------";
47 
48  if ( a_LogLevel < 0 ) {
49  cout << myname << "Skipping test while we wat for resolution of larsoft issue 10618" << endl;
50  return 0;
51  }
52 
53  cout << myname << line << endl;
54  cout << myname << "Create top-level FCL." << endl;
55 
56  std::ostringstream oss;
57  oss << "#include \"services_dune.fcl\"" << endl;
58  oss << "services: @local::dune35t_services_legacy" << endl;
59  oss << "services.AdcDeconvolutionService: {" << endl;
60  oss << " service_provider: DuneDeconvolutionService" << endl;
61  oss << " LogLevel: " << a_LogLevel << endl;
62  oss << "}" << endl;
64 
65  const unsigned int nsig = 100;
66  AdcChannelData acd;
67  acd.setChannelInfo(100);
68  for ( unsigned int isig=0; isig<nsig; ++isig ) {
69  acd.samples.push_back(0);
70  acd.flags.push_back(AdcGood);
71  }
72  acd.samples[50] = 100000.0;
73  AdcSignalVector& sigs = acd.samples;
74  AdcSignalVector sigsin = sigs;
75 
76  cout << myname << "Fetch FFT service." << endl;
78  unsigned int fftsize = hfft->FFTSize();
79  cout << myname << "Resizing signal vector to FFT size " << fftsize
80  << " as required for convolution." << endl;
81  sigs.resize(fftsize, 0.0);
82 
83  cout << myname << "Fetch shaping service." << endl;
85 
86  cout << myname << "Convolute." << endl;
87  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataForJob();
88  hsss->Convolute(clockData, acd.channel(), sigs);
89  AdcSignalVector sigsco = sigs;
90 
91  cout << myname << "Fetch deconvolution service." << endl;
93  hdco->print();
94 
95  cout << myname << line << endl;
96  cout << myname << "Deconvolute." << endl;
97  assert( hdco->update(clockData, acd) == 0 );
98  cout << myname << "Output vector size: " << sigs.size() << endl;
99  assert( sigs.size() == sigsco.size() );
100  for ( unsigned int isig=0; isig<nsig; ++isig ) {
101  cout << setw(4) << isig << ": "
102  << fixed << setprecision(1) << setw(8) << sigsin[isig]
103  << fixed << setprecision(1) << setw(10) << sigsco[isig]
104  << fixed << setprecision(1) << setw(10) << sigs[isig]
105  << endl;
106  //assert( sigs[isig] == sigsexp[isig] );
107  }
108 
109  cout << myname << "Done." << endl;
110  return 0;
111 }
112 
113 //**********************************************************************
114 
115 int main(int argc, char* argv[]) {
116  const string myname = "main: ";
117  int a_LogLevel = 1;
118  if ( argc > 1 ) {
119  istringstream ssarg(argv[1]);
120  ssarg >> a_LogLevel;
121  }
122  int rstat = test_DuneDeconvolutionService(a_LogLevel);
123  cout << myname << "Exiting." << endl;
124  return rstat;
125 }
126 
127 //**********************************************************************
std::string string
Definition: nybbler.cc:12
struct vector vector
Service to provide microboone-specific signal shaping for simulation (convolution) and reconstruction...
int test_DuneDeconvolutionService(int a_LogLevel=-1)
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)
int FFTSize() const
Definition: LArFFT.h:69
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
Channel channel() const
void Convolute(detinfo::DetectorClocksData const &clockData, Channel channel, std::vector< T > &func) const
vector< unsigned int > IndexVector
virtual std::ostream & print(std::ostream &out=std::cout, std::string prefix="") const =0
void line(double t, double *p, double &x, double &y, double &z)
std::vector< AdcSignal > AdcSignalVector
Definition: AdcTypes.h:22
virtual int update(detinfo::DetectorClocksData const &clockData, AdcChannelData &data) const =0
AdcSignalVector samples
QTextStream & endl(QTextStream &s)
int main(int argc, char *argv[])
AdcFlagVector flags