Functions
test_AdcNoiseSignalFinder.cxx File Reference
#include <string>
#include <iostream>
#include <fstream>
#include "dunecore/DuneInterface/Tool/TpcDataTool.h"
#include "dunecore/ArtSupport/DuneToolManager.h"
#include <cassert>

Go to the source code of this file.

Functions

int test_AdcNoiseSignalFinder (bool useExistingFcl=false)
 
int main (int argc, char *argv[])
 

Function Documentation

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

Definition at line 120 of file test_AdcNoiseSignalFinder.cxx.

120  {
121  bool useExistingFcl = false;
122  if ( argc > 1 ) {
123  string sarg(argv[1]);
124  if ( sarg == "-h" ) {
125  cout << "Usage: " << argv[0] << " [ARG]" << endl;
126  cout << " If ARG = true, existing FCL file is used." << endl;
127  return 0;
128  }
129  useExistingFcl = sarg == "true" || sarg == "1";
130  }
131  return test_AdcNoiseSignalFinder(useExistingFcl);
132 }
int test_AdcNoiseSignalFinder(bool useExistingFcl=false)
QTextStream & endl(QTextStream &s)
int test_AdcNoiseSignalFinder ( bool  useExistingFcl = false)

Definition at line 25 of file test_AdcNoiseSignalFinder.cxx.

25  {
26  const string myname = "test_AdcNoiseSignalFinder: ";
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_AdcNoiseSignalFinder.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: AdcNoiseSignalFinder" << endl;
41  fout << " LogLevel: 1" << endl;
42  fout << " SigFracMax: 0.2" << endl;
43  fout << " ThresholdMin: 20" << endl;
44  fout << " ThresholdRatio: 5" << endl;
45  fout << " ThresholdRatioTol: 0.1" << endl;
46  fout << " MaxLoop: 10" << endl;
47  fout << " BinsAfter: 10" << endl;
48  fout << " BinsBefore: 5" << endl;
49  fout << " FlagPositive: true" << endl;
50  fout << " FlagNegative: true" << endl;
51  fout << " }" << endl;
52  fout << "}" << endl;
53  fout.close();
54  } else {
55  cout << myname << "Using existing top-level FCL." << endl;
56  }
57 
58  cout << myname << line << endl;
59  cout << myname << "Fetching tool manager." << endl;
61  assert ( ptm != nullptr );
62  DuneToolManager& tm = *ptm;
63  tm.print();
64  assert( tm.toolNames().size() == 1 );
65 
66  cout << myname << line << endl;
67  cout << myname << "Fetching tool." << endl;
68  auto psgf = tm.getPrivate<TpcDataTool>("mytool");
69  assert( psgf != nullptr );
70  auto psgfmod = tm.getPrivate<TpcDataTool>("mytool");
71  assert( psgfmod != nullptr );
72 
73  cout << myname << line << endl;
74  cout << myname << "Create data and call tool." << endl;
76  int wnoi = 20;
77  float signoi = wnoi/sqrt(12.0);
78  srand(12345);
79  for ( AdcIndex itic=0; itic<100; ++itic ) {
80  float xadc = rand()%wnoi - 0.5*wnoi;
81  data.samples.push_back(xadc);
82  }
83  data.samples[30] = 150.0;
84  assert( data.signal.size() == 0 );
85  assert( data.rois.size() == 0 );
86  assert( data.samples[30] = 150 );
87 
88  cout << myname << line << endl;
89  cout << myname << "Running tool." << endl;
90  DataMap resmod = psgfmod->update(data);
91  resmod.print();
92 
93  cout << myname << line << endl;
94  cout << myname << "Checking results." << endl;
95  assert( resmod == 0 );
96  assert( resmod.getInt("nsfLoopCount") > 1 );
97  assert( resmod.getInt("nsfRoiCount") == 1 );
98  assert( data.signal.size() == 100 );
99  assert( data.rois.size() == 1 );
100  assert( data.rois[0].first == 25 );
101  assert( data.rois[0].second == 40 );
102  float mdNoise = data.getMetadata("nsfNoise");
103  assert( mdNoise > 0.9*signoi );
104  assert( mdNoise < 1.1*signoi );
105  float mdSigFrac = data.getMetadata("nsfSigFrac");
106  int mdNsig = int(100*mdSigFrac + 0.1);
107  assert( mdNsig == 16 );
108  float mdThresh = data.getMetadata("nsfThreshold");
109  float expThresh = 5.0*signoi;
110  assert( mdThresh > 0.9*expThresh );
111  assert( mdThresh < 1.1*expThresh );
112 
113  cout << myname << line << endl;
114  cout << myname << "Done." << endl;
115  return 0;
116 }
const std::vector< std::string > & toolNames() const
void print() const
void print(std::ostream *pout) const
Definition: DataMap.h:245
tm
Definition: demo.py:21
AdcRoiVector rois
float getMetadata(Name mname, float def=0.0) const
unsigned int AdcIndex
Definition: AdcTypes.h:15
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)