test_DuneRoiBuildingService.cxx
Go to the documentation of this file.
1 // test_DuneRoiBuildingService.cxx
2 //
3 // David Adams
4 // May 2016
5 //
6 // Test DuneRoiBuildingService.
7 //
8 
9 #include <string>
10 #include <iostream>
11 #include <sstream>
12 #include <fstream>
13 #include <iomanip>
18 
19 #undef NDEBUG
20 #include <cassert>
21 
22 using std::string;
23 using std::vector;
24 using std::cout;
25 using std::endl;
26 using std::istringstream;
27 using std::ofstream;
28 using std::setw;
29 using std::setprecision;
30 using std::fixed;
31 using art::ServiceHandle;
32 
33 typedef vector<unsigned int> IndexVector;
34 
35 //**********************************************************************
36 
37 int test_DuneRoiBuildingService(int a_LogLevel =1) {
38  const string myname = "test_DuneRoiBuildingService: ";
39 #ifdef NDEBUG
40  cout << myname << "NDEBUG must be off." << endl;
41  abort();
42 #endif
43  string line = "-----------------------------";
44 
45  cout << myname << line << endl;
46  cout << myname << "Create top-level FCL." << endl;
47 
48  std::ostringstream oss;
49  oss << "#include \"services_dune.fcl\"" << endl;
50  oss << "services: @local::dune35t_services_legacy" << endl;
51  oss << "services.AdcRoiBuildingService: {" << endl;
52  oss << " service_provider: DuneRoiBuildingService" << endl;
53  oss << " NSigmaStart: 4.0" << endl;
54  oss << " NSigmaEnd: 1.0" << endl;
55  oss << " PadLow: 5" << endl;
56  oss << " PadHigh: 10" << endl;
57  oss << " LogLevel: " << a_LogLevel << endl;
58  oss << "}" << endl;
60 
61  const unsigned int nsig = 100;
62  AdcChannelData acd;
63  acd.setChannelInfo(100);
64  for ( unsigned int isig=0; isig<nsig; ++isig ) {
65  acd.samples.push_back(0);
66  acd.flags.push_back(AdcGood);
67  }
68  acd.samples[10] = 3.0;
69  acd.samples[29] = 2.0;
70  acd.samples[30] = 8.0;
71  acd.samples[31] = 10.0;
72  acd.samples[32] = 8.0;
73  acd.samples[33] = 4.0;
74  acd.samples[34] = 2.0;
75  acd.samples[35] = 0.5;
76  acd.samples[60] = 20.0;
77  acd.samples[70] = 20.0;
78  acd.samples[90] = 20.0;
79  AdcSignalVector& sigs = acd.samples;
80  AdcSignalVector sigsin = sigs;
81 
82  //cout << myname << "Fetch FFT service." << endl;
83  //art::ServiceHandle<util::LArFFT> hfft;
84  //unsigned int fftsize = hfft->FFTSize();
85  //cout << myname << "Resizing signal vector to FFT size " << fftsize
86  //<< " as required for convolution." << endl;
87  //sigs.resize(fftsize, 0.0);
88  //cout << myname << "Samples size: " << acd.samples.size() << endl;
89 
90  cout << myname << "Fetch shaping service." << endl;
92  cout << myname << "Decon noise: " << hsss->GetDeconNoise(acd.channel()) << endl;
93 
94  cout << myname << "Fetch ROI building service." << endl;
96  hroi->print(cout, myname);
97 
98  cout << myname << "Build ROIs." << endl;
99  hroi->build(acd);
100  cout << myname << "Samples size: " << acd.samples.size() << endl;
101  cout << myname << "Output ROIS size: " << acd.rois.size() << endl;
102  assert( sigs.size() == nsig );
103  for ( unsigned int isig=0; isig<nsig; ++isig ) {
104  cout << myname << setw(4) << isig << ": "
105  << fixed << setprecision(1) << setw(10) << sigsin[isig]
106  << fixed << setprecision(1) << setw(10) << sigs[isig]
107  << endl;
108  assert( sigs[isig] == sigsin[isig] );
109  }
110  cout << myname << line << endl;
111  cout << myname << "ROIS:" << endl;
112  for ( AdcRoi roi : acd.rois ) {
113  cout << setw(6) << roi.first << setw(6) << roi.second << endl;
114  }
115 
116  cout << myname << line << endl;
117  cout << myname << "Check ROIs." << endl;
118  assert( acd.rois.size() == 3 );
119  assert( acd.rois[0].first == 25 );
120  assert( acd.rois[0].second == 44 );
121  assert( acd.rois[1].first == 55 );
122  assert( acd.rois[1].second == 80 );
123  assert( acd.rois[2].first == 85 );
124  assert( acd.rois[2].second == 99 );
125 
126  cout << myname << line << endl;
127  cout << myname << "Done." << endl;
128  return 0;
129 }
130 
131 //**********************************************************************
132 
133 int main(int argc, char* argv[]) {
134  int a_LogLevel = -1;
135  if ( argc > 1 ) {
136  istringstream ssarg(argv[1]);
137  ssarg >> a_LogLevel;
138  }
139  return test_DuneRoiBuildingService(a_LogLevel);
140 }
141 
142 //**********************************************************************
std::string string
Definition: nybbler.cc:12
virtual int build(AdcChannelData &data) const =0
virtual std::ostream & print(std::ostream &out=std::cout, std::string prefix="") const =0
struct vector vector
std::pair< AdcIndex, AdcIndex > AdcRoi
Definition: AdcTypes.h:54
double GetDeconNoise(Channel channel) const override
Service to provide microboone-specific signal shaping for simulation (convolution) and reconstruction...
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)
AdcRoiVector rois
vector< unsigned int > IndexVector
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
Channel channel() const
void line(double t, double *p, double &x, double &y, double &z)
std::vector< AdcSignal > AdcSignalVector
Definition: AdcTypes.h:22
int test_DuneRoiBuildingService(int a_LogLevel=1)
AdcSignalVector samples
int main(int argc, char *argv[])
QTextStream & endl(QTextStream &s)
AdcFlagVector flags