Functions
test_AdcChannelPlotter.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_AdcChannelPlotter (bool useExistingFcl=false)
 
int main (int argc, char *argv[])
 

Function Documentation

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

Definition at line 126 of file test_AdcChannelPlotter.cxx.

126  {
127  bool useExistingFcl = false;
128  if ( argc > 1 ) {
129  string sarg(argv[1]);
130  if ( sarg == "-h" ) {
131  cout << "Usage: " << argv[0] << " [ARG]" << endl;
132  cout << " If ARG = true, existing FCL file is used." << endl;
133  return 0;
134  }
135  useExistingFcl = sarg == "true" || sarg == "1";
136  }
137  return test_AdcChannelPlotter(useExistingFcl);
138 }
int test_AdcChannelPlotter(bool useExistingFcl=false)
QTextStream & endl(QTextStream &s)
int test_AdcChannelPlotter ( bool  useExistingFcl = false)

Definition at line 25 of file test_AdcChannelPlotter.cxx.

25  {
26  const string myname = "test_AdcChannelPlotter: ";
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_AdcChannelPlotter.fcl";
35  if ( ! useExistingFcl ) {
36  cout << myname << "Creating top-level FCL." << endl;
37  ofstream fout(fclfile.c_str());
38  fout << "#include \"dataprep_tools.fcl\"" << endl; // Need adcStringBuilder
39  fout << "tools.mytool: {" << endl;
40  fout << " tool_type: AdcChannelPlotter" << endl;
41  fout << " LogLevel: 1" << endl;
42  fout << " HistTypes: [\"raw\", \"rawdist\", \"prepared\"]" << endl;
43  fout << " HistName: \"adc%TYPE%_%EVENT%_%CHAN%\"" << endl;
44  fout << " HistTitle: \"ADC %TYPE% event %EVENT% channel %CHAN%\"" << endl;
45  fout << " RootFileName: \"adcplot.root\"" << endl;
46  fout << " PlotFileName: \"adcsigs.png\"" << endl;
47  fout << " PlotSamMin: 0" << endl;
48  fout << " PlotSamMax: 100" << endl;
49  fout << " PlotSigOpt: full" << endl;
50  fout << " PlotDistMin: 0" << endl;
51  fout << " PlotDistMax: 0" << endl;
52  fout << " PlotSigMin: 0" << endl;
53  fout << " PlotSigMax: 0" << endl;
54  fout << " ColorBad: 0" << endl;
55  fout << " ColorNoisy: 0" << endl;
56  fout << " HistManager: \"\"" << endl;
57  fout << " MaxSample: 80" << endl;
58  fout << " SkipFlags: []" << endl;
59  fout << " LabelSize: 0" << endl;
60  fout << "}" << endl;
61  fout.close();
62  } else {
63  cout << myname << "Using existing top-level FCL." << endl;
64  }
65 
66  cout << myname << line << endl;
67  cout << myname << "Fetching tool manager." << endl;
69  assert ( ptm != nullptr );
70  DuneToolManager& tm = *ptm;
71  tm.print();
72  assert( tm.toolNames().size() >= 1 );
73 
74  cout << myname << line << endl;
75  cout << myname << "Fetching tool." << endl;
76  auto padv = tm.getPrivate<TpcDataTool>("mytool");
77  assert( padv != nullptr );
78 
79  cout << myname << line << endl;
80  cout << myname << "Create data and call too." << endl;
81  AdcIndex nevt = 2;
82  string lab = "plane 3u";
83  float peds[10] = {701.1, 711.2, 733.3, 690.4, 688.5, 703.6, 720.7, 720.8, 695.9, 702.0};
84  for ( AdcIndex ievt=0; ievt<nevt; ++ievt ) {
85  cout << myname << "Event " << ievt << endl;
86  AdcChannelDataMap datamap;
87  AdcIndex ncha = 10;
88  for ( AdcIndex icha=0; icha<ncha; ++icha ) {
89  std::pair<AdcChannelDataMap::iterator, bool> kdat = datamap.emplace(icha, AdcChannelData());
90  assert(kdat.second);
91  AdcChannelDataMap::iterator idat = kdat.first;
92  AdcChannelData& data = idat->second;
93  float ped = peds[icha];
94  data.setEventInfo(101, ievt, 23);
95  data.setChannelInfo(icha);
96  data.pedestal = ped;
97  for ( AdcIndex itic=0; itic<100; ++itic ) {
98  float xadc = ped + rand()%20 - 10.0;
99  AdcIndex iticeff = itic - 3*icha;
100  if ( iticeff > 20 && iticeff < 40 ) xadc +=600;
101  AdcCount iadc = xadc;
102  data.raw.push_back(iadc);
103  data.flags.push_back(0);
104  data.samples.push_back(iadc - ped);
105  data.signal.push_back(xadc - ped > 300.0 );
106  }
107  AdcIndex tp = 10*ievt + 60 - 2.3*icha;
108  AdcIndex tm = tp - 8;
109  data.raw[tp] += 100;
110  data.samples[tp] += 100;
111  data.raw[tm] -= 100;
112  data.samples[tm] -= 100;
113  data.flags[tm] = 4;
114  data.roisFromSignal();
115  assert( padv->view(datamap[icha]) == 0 );
116  }
117  }
118 
119  cout << myname << line << endl;
120  cout << myname << "Done." << endl;
121  return 0;
122 }
intermediate_table::iterator iterator
const std::vector< std::string > & toolNames() const
void print() const
tm
Definition: demo.py:21
void setChannelInfo(ChannelInfoPtr pchi)
void setEventInfo(EventInfoPtr pevi)
AdcCountVector raw
unsigned int AdcIndex
Definition: AdcTypes.h:15
std::unique_ptr< T > getPrivate(std::string name)
AdcSignal pedestal
AdcFilterVector signal
void line(double t, double *p, double &x, double &y, double &z)
std::map< AdcChannel, AdcChannelData > AdcChannelDataMap
short AdcCount
Definition: AdcTypes.h:18
static DuneToolManager * instance(std::string fclname="", int dbg=1)
AdcSignalVector samples
QTextStream & endl(QTextStream &s)
AdcFlagVector flags