test_AdcThresholdSignalFinder.cxx
Go to the documentation of this file.
1 // test_AdcThresholdSignalFinder.cxx
2 //
3 // David Adams
4 // April 2017
5 //
6 // Test AdcThresholdSignalFinder.
7 
8 #include <string>
9 #include <iostream>
10 #include <fstream>
13 
14 #undef NDEBUG
15 #include <cassert>
16 
17 using std::string;
18 using std::cout;
19 using std::endl;
20 using std::ofstream;
22 
23 //**********************************************************************
24 
25 int test_AdcThresholdSignalFinder(bool useExistingFcl =false) {
26  const string myname = "test_AdcThresholdSignalFinder: ";
27 #ifdef NDEBUG
28  cout << myname << "NDEBUG must be off." << endl;
29  abort();
30 #endif
31  string line = "-----------------------------";
32 
33  cout << myname << line << endl;
34  string fclfile = "test_AdcThresholdSignalFinder.fcl";
35  if ( ! useExistingFcl ) {
36  cout << myname << "Creating top-level FCL." << endl;
37  ofstream fout(fclfile.c_str());
38  fout << "tools: {" << endl;
39  fout << " mytool: {" << endl;
40  fout << " tool_type: AdcThresholdSignalFinder" << endl;
41  fout << " LogLevel: 1" << endl;
42  fout << " Threshold: \"100*[gain]/14.0\"" << endl;
43  fout << " BinsAfter: 10" << endl;
44  fout << " BinsBefore: 5" << endl;
45  fout << " FlagPositive: true" << endl;
46  fout << " FlagNegative: true" << endl;
47  fout << " }" << endl;
48  fout << " runDataTool: {" << endl;
49  fout << " tool_type: FclRunDataTool" << endl;
50  fout << " LogLevel: 1" << endl;
51  fout << " FileNames: [\"rundata.fcl\"]" << endl;
52  fout << " }" << endl;
53  fout << "}" << endl;
54  fout.close();
55  ofstream fout2("rundata.fcl");
56  fout2 << "run: 123" << endl;
57  fout2 << "gain: 14.0" << endl;
58  fout2 << "shaping: 2.0" << endl;
59  fout2.close();
60  fout.close();
61  } else {
62  cout << myname << "Using existing top-level FCL." << endl;
63  }
64 
65  cout << myname << line << endl;
66  cout << myname << "Fetching tool manager." << endl;
68  assert ( ptm != nullptr );
69  DuneToolManager& tm = *ptm;
70  tm.print();
71  assert( tm.toolNames().size() == 2 );
72 
73  cout << myname << line << endl;
74  cout << myname << "Fetching tool." << endl;
75  auto psgf = tm.getPrivate<TpcDataTool>("mytool");
76  assert( psgf != nullptr );
77  auto psgfmod = tm.getPrivate<TpcDataTool>("mytool");
78  assert( psgfmod != nullptr );
79 
80  cout << myname << line << endl;
81  cout << myname << "Create data and call tool." << endl;
83  for ( AdcIndex itic=0; itic<100; ++itic ) {
84  float xadc = rand()%20 - 10.0;
85  data.samples.push_back(xadc);
86  }
87  data.samples[30] = 150.0;
88  assert( data.signal.size() == 0 );
89  assert( data.rois.size() == 0 );
90  assert( data.samples[30] = 150 );
91 
92  cout << myname << line << endl;
93  cout << myname << "Running tool." << endl;
94  DataMap resmod = psgfmod->update(data);
95  resmod.print();
96 
97  cout << myname << line << endl;
98  cout << myname << "Checking results." << endl;
99  assert( resmod == 0 );
100  assert( fabs(resmod.getFloat("threshold") - 100) < 0.1 );
101  assert( resmod.getInt("nThresholdBins") == 1 );
102  assert( resmod.getInt("nroi") == 1 );
103  assert( data.signal.size() == 100 );
104  assert( data.rois.size() == 1 );
105  assert( data.rois[0].first == 25 );
106  assert( data.rois[0].second == 40 );
107 
108  cout << myname << line << endl;
109  cout << myname << "Done." << endl;
110  return 0;
111 }
112 
113 //**********************************************************************
114 
115 int main(int argc, char* argv[]) {
116  bool useExistingFcl = false;
117  if ( argc > 1 ) {
118  string sarg(argv[1]);
119  if ( sarg == "-h" ) {
120  cout << "Usage: " << argv[0] << " [ARG]" << endl;
121  cout << " If ARG = true, existing FCL file is used." << endl;
122  return 0;
123  }
124  useExistingFcl = sarg == "true" || sarg == "1";
125  }
126  return test_AdcThresholdSignalFinder(useExistingFcl);
127 }
128 
129 //**********************************************************************
const std::vector< std::string > & toolNames() const
std::string string
Definition: nybbler.cc:12
void print() const
void print(std::ostream *pout) const
Definition: DataMap.h:245
tm
Definition: demo.py:21
int test_AdcThresholdSignalFinder(bool useExistingFcl=false)
AdcRoiVector rois
unsigned int AdcIndex
Definition: AdcTypes.h:15
Float getFloat(Name name, Float def=0.0) const
Definition: DataMap.h:220
std::unique_ptr< T > getPrivate(std::string name)
AdcFilterVector signal
int getInt(Name name, int def=0) const
Definition: DataMap.h:218
void line(double t, double *p, double &x, double &y, double &z)
static DuneToolManager * instance(std::string fclname="", int dbg=1)
AdcSignalVector samples
QTextStream & endl(QTextStream &s)
int main(int argc, char *argv[])