test_AcdWireReader.cxx
Go to the documentation of this file.
1 // test_AcdWireReader.cxx
2 //
3 // David Adams
4 // April 2017
5 //
6 // Test AcdWireReader.
7 
8 #include <string>
9 #include <iostream>
10 #include <fstream>
11 #include <sstream>
12 #include <iomanip>
20 
21 #undef NDEBUG
22 #include <cassert>
23 
24 using std::string;
25 using std::cout;
26 using std::endl;
27 using std::ostringstream;
28 using std::ofstream;
29 using std::setw;
30 using std::setprecision;
31 using std::fixed;
33 using art::ServiceHandle;
34 
35 #include "TestDigit.h"
36 
37 //**********************************************************************
38 
39 bool sigequal(AdcSignal sig1, AdcSignal sig2) {
40  AdcSignal sigdiff = sig2 - sig1;
41  if ( sigdiff < -0.5 ) return false;
42  if ( sigdiff > 0.5 ) return false;
43  return true;
44 }
45 
46 //**********************************************************************
47 
48 int test_AcdWireReader(bool useExistingFcl =false) {
49  const string myname = "test_AcdWireReader: ";
50 #ifdef NDEBUG
51  cout << myname << "NDEBUG must be off." << endl;
52  abort();
53 #endif
54  string line = "-----------------------------";
55 
56  cout << myname << line << endl;
57  string fclfile = "test_AcdWireReader.fcl";
58  if (useExistingFcl) {
59  cout << myname << "Using existing top-level FCL." << endl;
61  } else {
62  cout << myname << "Creating top-level FCL." << endl;
63  // To convert digit to wire, use the DUNE fcl for 35-ton reco.
64  // Disable noise removal and deconvolution because these make it difficult
65  // to predict the result.
66  std::ofstream config{fclfile};
67  config << "#include \"services_dune.fcl\"" << endl;
68  config << "services: @local::dune35tdata_reco_services" << endl;
69  config << "services.RawDigitPrepService.DoNoiseRemoval: false" << endl;
70  config << "services.RawDigitPrepService.DoDeconvolution: false" << endl;
71  config << "services.RawDigitPrepService.DoIntermediateStates: true" << endl;
72  config << "services.AdcChannelDataCopyService.CopyFlags: true" << endl;
73  // Need the standard tool to read channel data from a digit.
74  config << "#include \"dataprep_tools.fcl\"" << endl;
75  // Build local wire reader.
76  config << "tools.mytool: {" << endl;
77  config << " tool_type: AcdWireReader" << endl;
78  config << " LogLevel: 2" << endl;
79  config << "}" << endl;
80  }
81 
82  // We explicitly initialize the DuneToolManager first so that the
83  // above configuration wins. If we load the services first, then a
84  // default services configuration is loaded, and the one for this
85  // test is ignored.
86  cout << myname << line << endl;
87  cout << myname << "Fetching tool manager." << endl;
90 
91  assert ( ptm != nullptr );
92  DuneToolManager& tm = *ptm;
93  tm.print();
94  assert( tm.toolNames().size() );
95 
96  cout << myname << line << endl;
97  cout << myname << "Fetch services." << endl;
99 
100  cout << myname << line << endl;
101  cout << myname << "Construct test digit." << endl;
102  TestDigit tdig(2);
103  AdcIndex nsig = tdig.nsig;
104  const raw::RawDigit* pdig = tdig.pdig;
105 
106  cout << myname << line << endl;
107  cout << myname << "Create channel dat map and set digits." << endl;
108  AdcChannelDataMap acds;
109  AdcChannelData& acd = acds[tdig.channel];
110  acd.digit = pdig;
111  assert( acd.raw.size() == 0 );
112 
113  cout << myname << line << endl;
114  cout << myname << "Construct test wire." << endl;
115  std::vector<recob::Wire> wires;
116  wires.reserve(acds.size());
117  assert( acd.samples.size() == 0 );
118  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataForJob();
119  assert( hrdp->prepare(clockData, acds, &wires) == 0 );
120  assert( acd.raw.size() == nsig );
121  assert( acd.samples.size() == nsig );
122 
123  cout << myname << line << endl;
124  cout << myname << "Fetch wire read tool." << endl;
125  auto prdr = tm.getPrivate<TpcDataTool>("mytool");
126  assert( prdr != nullptr );
127 
128  cout << myname << line << endl;
129  cout << myname << "Read wire into channel data." << endl;
130  AdcChannelData newacd;
131  newacd.wire = &wires[0];
132  assert( newacd.samples.size() == 0 );
133  assert( prdr->update(newacd) == 0 );
134  assert( newacd.samples.size() == nsig );
135 
136  cout << myname << line << endl;
137  cout << myname << "Check samples." << endl;
138  int dbg = 1;
139  for ( unsigned int isig=0; isig<nsig; ++isig ) {
140  if ( dbg ) cout << myname << isig << ": " << acd.samples[isig]
141  << " ?= " << newacd.samples[isig]
142  << " (" << acd.signal[isig] << " "
143  << newacd.signal[isig] << ")" << endl;
144  assert(sigequal(acd.samples[isig], newacd.samples[isig]));
145  }
146  cout << myname << "NROI: " << wires[0].SignalROI().size() << " "
147  << acd.rois.size() << " " << newacd.rois.size() << endl;
148  assert( newacd.rois.size() == acd.rois.size() );
149 
150  cout << myname << line << endl;
151  cout << myname << "Done." << endl;
152  return 0;
153 }
154 
155 //**********************************************************************
156 
157 int main(int argc, char* argv[]) {
158  bool useExistingFcl = false;
159  if ( argc > 1 ) {
160  string sarg(argv[1]);
161  if ( sarg == "-h" ) {
162  cout << "Usage: " << argv[0] << " [ARG]" << endl;
163  cout << " If ARG = true, existing FCL file is used." << endl;
164  return 0;
165  }
166  useExistingFcl = sarg == "true" || sarg == "1";
167  }
168  return test_AcdWireReader(useExistingFcl);
169 }
170 
171 //**********************************************************************
Collection of charge vs time digitized from a single readout channel.
Definition: RawDigit.h:69
bool dbg
const std::vector< std::string > & toolNames() const
std::string string
Definition: nybbler.cc:12
float AdcSignal
Definition: AdcTypes.h:21
static constexpr FileOnPath_t FileOnPath
void print() const
int main(int argc, char *argv[])
AdcIndex channel
Definition: TestDigit.h:21
const recob::Wire * wire
const raw::RawDigit * pdig
Definition: TestDigit.h:23
const raw::RawDigit * digit
virtual int prepare(detinfo::DetectorClocksData const &clockData, AdcChannelDataMap &prepdigs, std::vector< recob::Wire > *pwires=nullptr, WiredAdcChannelDataMap *pwiredData=nullptr) const =0
static void load_services(std::string const &config)
tm
Definition: demo.py:21
Q_EXPORT QTSManip setprecision(int p)
Definition: qtextstream.h:343
AdcIndex nsig
Definition: TestDigit.h:24
AdcRoiVector rois
static Config * config
Definition: config.cpp:1054
AdcCountVector raw
unsigned int AdcIndex
Definition: AdcTypes.h:15
bool sigequal(AdcSignal sig1, AdcSignal sig2)
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
std::unique_ptr< T > getPrivate(std::string name)
AdcFilterVector signal
void line(double t, double *p, double &x, double &y, double &z)
int test_AcdWireReader(bool useExistingFcl=false)
std::map< AdcChannel, AdcChannelData > AdcChannelDataMap
static DuneToolManager * instance(std::string fclname="", int dbg=1)
AdcSignalVector samples
QTextStream & endl(QTextStream &s)