Functions
test_AcdWireReader.cxx File Reference
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include "art/Framework/Services/Registry/ServiceHandle.h"
#include "dunecore/DuneInterface/Service/RawDigitPrepService.h"
#include "dunecore/DuneInterface/Tool/TpcDataTool.h"
#include "dunecore/ArtSupport/ArtServiceHelper.h"
#include "dunecore/ArtSupport/DuneToolManager.h"
#include "lardataobj/RawData/RawDigit.h"
#include "lardata/DetectorInfoServices/DetectorClocksService.h"
#include <cassert>
#include "TestDigit.h"

Go to the source code of this file.

Functions

bool sigequal (AdcSignal sig1, AdcSignal sig2)
 
int test_AcdWireReader (bool useExistingFcl=false)
 
int main (int argc, char *argv[])
 

Function Documentation

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

Definition at line 157 of file test_AcdWireReader.cxx.

157  {
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 }
int test_AcdWireReader(bool useExistingFcl=false)
QTextStream & endl(QTextStream &s)
bool sigequal ( AdcSignal  sig1,
AdcSignal  sig2 
)

Definition at line 39 of file test_AcdWireReader.cxx.

39  {
40  AdcSignal sigdiff = sig2 - sig1;
41  if ( sigdiff < -0.5 ) return false;
42  if ( sigdiff > 0.5 ) return false;
43  return true;
44 }
float AdcSignal
Definition: AdcTypes.h:21
int test_AcdWireReader ( bool  useExistingFcl = false)

Definition at line 48 of file test_AcdWireReader.cxx.

48  {
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 }
Collection of charge vs time digitized from a single readout channel.
Definition: RawDigit.h:69
bool dbg
const std::vector< std::string > & toolNames() const
static constexpr FileOnPath_t FileOnPath
void print() const
const recob::Wire * wire
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
AdcRoiVector rois
static Config * config
Definition: config.cpp:1054
AdcCountVector raw
unsigned int AdcIndex
Definition: AdcTypes.h:15
bool sigequal(AdcSignal sig1, AdcSignal sig2)
std::unique_ptr< T > getPrivate(std::string name)
AdcFilterVector signal
void line(double t, double *p, double &x, double &y, double &z)
std::map< AdcChannel, AdcChannelData > AdcChannelDataMap
static DuneToolManager * instance(std::string fclname="", int dbg=1)
AdcSignalVector samples
QTextStream & endl(QTextStream &s)