test_VintageDeconvoluter.cxx
Go to the documentation of this file.
1 // test_VintageDeconvoluter.cxx
2 //
3 // David Adams
4 // May 2018
5 //
6 // Test VintageDeconvoluter.
7 
8 #include <string>
9 #include <iostream>
10 #include <fstream>
15 
16 #undef NDEBUG
17 #include <cassert>
18 
19 using std::string;
20 using std::cout;
21 using std::endl;
22 using std::ofstream;
24 using Index = unsigned int;
25 
26 //**********************************************************************
27 
28 int test_VintageDeconvoluter(bool useExistingFcl =false) {
29  const string myname = "test_VintageDeconvoluter: ";
30 #ifdef NDEBUG
31  cout << myname << "NDEBUG must be off." << endl;
32  abort();
33 #endif
34  string line = "-----------------------------";
35 
36  cout << myname << line << endl;
37  string fclfile = "test_VintageDeconvoluter.fcl";
38  if (useExistingFcl) {
39  cout << myname << "Using existing top-level FCL." << endl;
40  } else {
41  cout << myname << "Creating top-level FCL." << endl;
42  std::ofstream config{fclfile};
43  config << "#include \"services_dune.fcl\"" << endl;
44  //config << "services: @local::protodune_reco_services" << endl;
45  config << "services: @local::dune35t_services_legacy" << endl;
46  config << "tools: {" << endl;
47  config << " mytool: {" << endl;
48  config << " tool_type: VintageDeconvoluter" << endl;
49  config << " LogLevel: 1" << endl;
50  config << " }" << endl;
51  config << "}" << endl;
52  }
54 
55  cout << myname << line << endl;
56  cout << myname << "Fetching tool manager." << endl;
58  assert ( ptm != nullptr );
59  DuneToolManager& tm = *ptm;
60  tm.print();
61  assert( tm.toolNames().size() == 1 );
62 
63  cout << myname << line << endl;
64  cout << myname << "Fetching tool." << endl;
65  auto psgf = tm.getPrivate<TpcDataTool>("mytool");
66  assert( psgf != nullptr );
67  auto psgfmod = tm.getPrivate<TpcDataTool>("mytool");
68  assert( psgfmod != nullptr );
69 
70  cout << myname << line << endl;
71  cout << myname << "Create data and call tool." << endl;
73  data.setChannelInfo(123);
74  for ( AdcIndex itic=0; itic<100; ++itic ) {
75  float xadc = rand()%20 - 10.0;
76  data.samples.push_back(xadc);
77  }
78  data.samples[30] = 150.0;
79  assert( data.signal.size() == 0 );
80  assert( data.rois.size() == 0 );
81  assert( data.samples[30] = 150 );
82  AdcChannelData data0 = data;
83  data0.signal = data.signal;
84  data0.rois = data.rois;
85  data0.samples = data.samples;
86 
87  cout << myname << line << endl;
88  cout << myname << "Running tool." << endl;
89  DataMap resmod = psgfmod->update(data);
90  resmod.print();
91 
92  cout << myname << line << endl;
93  cout << myname << "Checking results." << endl;
94  assert( data.samples.size() == data0.samples.size() );
95  for ( Index isam=0; isam<data0.samples.size(); ++isam ) {
96  cout << isam << ": " << data0.samples[isam] << " " << data.samples[isam] << endl;
97  }
98 
99  cout << myname << line << endl;
100  cout << myname << "Done." << endl;
101  return 0;
102 }
103 
104 //**********************************************************************
105 
106 int main(int argc, char* argv[]) {
107  bool useExistingFcl = false;
108  if ( argc > 1 ) {
109  string sarg(argv[1]);
110  if ( sarg == "-h" ) {
111  cout << "Usage: " << argv[0] << " [ARG]" << endl;
112  cout << " If ARG = true, existing FCL file is used." << endl;
113  return 0;
114  }
115  useExistingFcl = sarg == "true" || sarg == "1";
116  }
117  return test_VintageDeconvoluter(useExistingFcl);
118 }
119 
120 //**********************************************************************
const std::vector< std::string > & toolNames() const
std::string string
Definition: nybbler.cc:12
static constexpr FileOnPath_t FileOnPath
void print() const
unsigned int Index
void print(std::ostream *pout) const
Definition: DataMap.h:245
static void load_services(std::string const &config)
tm
Definition: demo.py:21
void setChannelInfo(ChannelInfoPtr pchi)
AdcRoiVector rois
static Config * config
Definition: config.cpp:1054
int main(int argc, char *argv[])
unsigned int AdcIndex
Definition: AdcTypes.h:15
std::unique_ptr< T > getPrivate(std::string name)
AdcFilterVector signal
int test_VintageDeconvoluter(bool useExistingFcl=false)
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)