Typedefs | Functions
test_AdcDetectorPlotter.cxx File Reference
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include "dunecore/DuneInterface/Tool/TpcDataTool.h"
#include "dunecore/ArtSupport/DuneToolManager.h"
#include "dunecore/ArtSupport/ArtServiceHelper.h"
#include "dunecore/Geometry/AdcChannelDataTester.h"
#include "larcore/Geometry/Geometry.h"
#include "art/Framework/Services/Registry/ServiceHandle.h"
#include "TRandom.h"
#include <cassert>

Go to the source code of this file.

Typedefs

using Index = unsigned int
 

Functions

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

Typedef Documentation

using Index = unsigned int

Definition at line 31 of file test_AdcDetectorPlotter.cxx.

Function Documentation

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

Definition at line 171 of file test_AdcDetectorPlotter.cxx.

171  {
172  bool useExistingFcl = false;
173  if ( argc > 1 ) {
174  string sarg(argv[1]);
175  if ( sarg == "-h" ) {
176  cout << "Usage: " << argv[0] << " [ARG]" << endl;
177  cout << " If ARG = true, existing FCL file is used." << endl;
178  return 0;
179  }
180  useExistingFcl = sarg == "true" || sarg == "1";
181  }
182  return test_AdcDetectorPlotter(useExistingFcl);
183 }
int test_AdcDetectorPlotter(bool useExistingFcl=false)
QTextStream & endl(QTextStream &s)
int test_AdcDetectorPlotter ( bool  useExistingFcl = false)

Definition at line 35 of file test_AdcDetectorPlotter.cxx.

35  {
36  const string myname = "test_AdcDetectorPlotter: ";
37 #ifdef NDEBUG
38  cout << myname << "NDEBUG must be off." << endl;
39  abort();
40 #endif
41  string line = "-----------------------------";
42 
43  cout << myname << line << endl;
44  string fclfile = "test_AdcDetectorPlotter.fcl";
45  string gname = "protodune_geo";
46  if (useExistingFcl) {
47  cout << myname << "Using existing top-level FCL." << endl;
48  } else {
49  cout << myname << "Creating top-level FCL." << endl;
50  std::ofstream config{fclfile};
51  config << "#include \"geometry_dune.fcl\"" << endl;
52  config << "services.Geometry: @local::" + gname << endl;
53  config << "services.ExptGeoHelperInterface: @local::dune_geometry_helper" << endl;
54  config << "#include \"dataprep_tools.fcl\"" << endl; // Need adcStringBuilder
55  config << "tools.mytool: {" << endl;
56  config << " tool_type: AdcDetectorPlotter" << endl;
57  config << " LogLevel: 2" << endl;
58  config << " WireAngle: 0.0" << endl;
59  //config << " WireAngle: 0.623" << endl;
60  config << " DataType: 0" << endl;
61  config << " Tick0: 0" << endl;
62  config << " DriftSpeed: 0.01" << endl;
63  config << " XMin: 600.0" << endl;
64  config << " XMax: -600.0" << endl;
65  config << " ZMin: -20.0" << endl;
66  config << " ZMax: 720.0" << endl;
67  config << " SignalThreshold: 10" << endl;
68  config << " SkipBadChannels: false" << endl;
69  config << " ShowAllTicks: false" << endl;
70  config << " FirstTick: 0" << endl;
71  config << " LastTick: 0" << endl;
72  config << " ShowWires: true" << endl;
73  config << " ShowCathode: true" << endl;
74  config << " ShowTpcSets: []" << endl;
75  config << " ShowGrid: true" << endl;
76  config << " Title: \"Prepared ADC run %RUN% event %EVENT%\"" << endl;
77  config << " PlotTitle: \"%UTCTIME2\"" << endl;
78  config << " FileName: \"test_AdcDetectorPlotter-run%0RUN%-evt%0EVENT%.png\"" << endl;
79  config << "}" << endl;
80  }
82 
83  cout << myname << line << endl;
84  cout << myname << "Get Geometry service." << endl;
86  cout << myname << "Geometry name: " << pgeo->DetectorName() << endl;
87 
88  cout << myname << line << endl;
89  cout << myname << "Fetching tool manager." << endl;
91  assert ( ptm != nullptr );
92  DuneToolManager& tm = *ptm;
93  tm.print();
94  assert( tm.toolNames().size() >= 1 );
95 
96  cout << myname << line << endl;
97  cout << myname << "Fetching tool." << endl;
98  auto padv = tm.getPrivate<TpcDataTool>("mytool");
99  assert( padv != nullptr );
100 
101  cout << myname << line << endl;
102  cout << myname << "Create data." << endl;
103  Index nevt = 2;
104  vector<vector<AdcChannelDataMap>> evtdatamaps(nevt);
105  Index icry = 0;
106  const geo::CryostatGeo& gcry = pgeo->Cryostat(icry);
107  Index ntpc = gcry.NTPC();
108  Index ncha = pgeo->Nchannels();
109  // Loop over events.
110  AdcChannelDataTester tester;
111  tester.run = 123;
112  tester.event = 0;
113  tester.subrun = 2;
114  tester.nsam = 20000;
115  bool strumWires = false;
116  // Loop over events.
117  for ( vector<AdcChannelDataMap>& datamaps : evtdatamaps ) {
118  if ( strumWires ) {
119  datamaps.resize(ntpc);
120  // Loop over TPCs. No, no, no...
121  for ( Index itpc=0; itpc<ntpc; ++itpc ) {
122  tester.strumTpcWires(datamaps[itpc], itpc, icry);
123  }
124  } else {
125  datamaps.resize(1);
126  AdcChannelDataMap& datamap = datamaps[0];
127  for ( Index icha=0; icha<ncha; ++ icha ) datamap[icha];
128  tester.strumChannels(datamap);
129  }
130  Index ngrp = datamaps.size();
131  cout << myname << " Event " << tester.event << endl;
132  cout << myname << " Group count is " << ngrp << endl;
133  for ( Index igrp=0; igrp<ngrp; ++ igrp ) {
134  cout << myname << " Group " << igrp << " channel count: " << datamaps[igrp].size() << endl;
135  }
136  ++tester.event;
137  }
138 
139  cout << myname << line << endl;
140  cout << myname << "Call tool." << endl;
141  assert( nevt == 2 );
142  // Loop over events.
143  for ( AdcIndex ievt=0; ievt<nevt; ++ievt ) {
144  cout << myname << "Event " << ievt << endl;
145  DuneEventInfo dev;
146  dev.event = ievt;
147  dev.run = tester.run;
148  dev.subRun = tester.subrun;
149  const vector<AdcChannelDataMap>& datamaps = evtdatamaps[ievt];
150  Index ngrp = datamaps.size();
151  // Loop over ADC channel groups (1 group per TPC).
152  for ( Index igrp=0; igrp<ngrp; ++igrp ) {
153  const AdcChannelDataMap& datamap = datamaps[igrp];
154  assert( datamap.size() > 0 );
155  assert( datamap.begin()->second.event() == ievt );
156  assert( datamap.begin()->second.run() == tester.run );
157  cout << myname << "Calling tool for event " << ievt << ", group " << igrp
158  << ", Nchan = " << datamap.size() << endl;
159  assert( padv->viewMap(datamap) == 0 );
160  }
161  padv->endEvent(dev);
162  }
163 
164  cout << myname << line << endl;
165  cout << myname << "Done." << endl;
166  return 0;
167 }
const std::vector< std::string > & toolNames() const
static constexpr FileOnPath_t FileOnPath
void print() const
unsigned int Index
Geometry information for a single cryostat.
Definition: CryostatGeo.h:43
static void load_services(std::string const &config)
tm
Definition: demo.py:21
unsigned int Nchannels() const
Returns the number of TPC readout channels in the detector.
std::string DetectorName() const
Returns a string with the name of the detector, as configured.
static Config * config
Definition: config.cpp:1054
int strumChannels(AdcChannelDataMap &acds, Index ncha=0)
unsigned int NTPC() const
Number of TPCs in this cryostat.
Definition: CryostatGeo.h:181
CryostatGeo const & Cryostat(geo::CryostatID const &cryoid) const
Returns the specified cryostat.
unsigned int AdcIndex
Definition: AdcTypes.h:15
std::unique_ptr< T > getPrivate(std::string name)
void line(double t, double *p, double &x, double &y, double &z)
int strumTpcWires(AdcChannelDataMap &acds, Index itpc, Index icry=0)
std::map< AdcChannel, AdcChannelData > AdcChannelDataMap
static DuneToolManager * instance(std::string fclname="", int dbg=1)
QTextStream & endl(QTextStream &s)