Typedefs | Functions
test_AdcRoiViewer.cxx File Reference
#include <string>
#include <iostream>
#include <fstream>
#include "dunecore/DuneInterface/Tool/TpcDataTool.h"
#include "dunecore/ArtSupport/DuneToolManager.h"
#include "TRandom.h"
#include <cassert>

Go to the source code of this file.

Typedefs

using Index = unsigned int
 

Functions

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

Typedef Documentation

using Index = unsigned int

Definition at line 25 of file test_AdcRoiViewer.cxx.

Function Documentation

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

Definition at line 189 of file test_AdcRoiViewer.cxx.

189  {
190  bool useExistingFcl = false;
191  if ( argc > 1 ) {
192  string sarg(argv[1]);
193  if ( sarg == "-h" ) {
194  cout << "Usage: " << argv[0] << " [ARG]" << endl;
195  cout << " If ARG = true, existing FCL file is used." << endl;
196  return 0;
197  }
198  useExistingFcl = sarg == "true" || sarg == "1";
199  }
200  return test_AdcRoiViewer(useExistingFcl);
201 }
int test_AdcRoiViewer(bool useExistingFcl=false)
QTextStream & endl(QTextStream &s)
int test_AdcRoiViewer ( bool  useExistingFcl = false)

Definition at line 29 of file test_AdcRoiViewer.cxx.

29  {
30  const string myname = "test_AdcRoiViewer: ";
31 #ifdef NDEBUG
32  cout << myname << "NDEBUG must be off." << endl;
33  abort();
34 #endif
35  string line = "-----------------------------";
36 
37  cout << myname << line << endl;
38  string fclfile = "test_AdcRoiViewer.fcl";
39  if ( ! useExistingFcl ) {
40  cout << myname << "Creating top-level FCL." << endl;
41  ofstream fout(fclfile.c_str());
42  fout << "#include \"dataprep_tools.fcl\"" << endl;
43  fout << "tools.mytool1: {" << endl;
44  fout << " tool_type: AdcRoiViewer" << endl;
45  fout << " LogLevel: 3" << endl;
46  fout << " SigThresh: 0.0" << endl;
47  fout << " TickBorder: 0" << endl;
48  fout << " RoiHistOpt: 1" << endl;
49  fout << " FitOpt: 1" << endl;
50  fout << " StartTime: 0" << endl;
51  fout << " PulserStepCharge: 0.0" << endl;
52  fout << " PulserDacOffset: 0.0" << endl;
53  fout << " PulserChargeUnit: \"\"" << endl;
54  fout << " RoiPlotOpt: 1" << endl;
55  fout << " MaxRoiPlots: 100" << endl;
56  fout << " RoiPlotPadX: 2" << endl;
57  fout << " RoiPlotPadY: 2" << endl;
58  fout << " SumNegate: false" << endl;
59  fout << " SumPlotPadX: 2" << endl;
60  fout << " SumPlotPadY: 2" << endl;
61  fout << " RunDataTool: \"\"" << endl;
62  fout << " TickOffsetTool: \"\"" << endl;
63  fout << " SumHists: []" << endl;
64  fout << " ChannelRanges: []" << endl;
65  fout << " ChanSumHists: []" << endl;
66  fout << " ChannelLineModulus: 0" << endl;
67  fout << " ChannelLinePattern: []" << endl;
68  fout << " RoiRootFileName: \"roi.root\"" << endl;
69  fout << " SumRootFileName: \"\"" << endl;
70  fout << " ChanSumRootFileName: \"\"" << endl;
71  fout << " PlotLabels: [\"very\", \"nice\"]" << endl;
72  fout << "}" << endl;
73  fout << "tools.mytool2: @local::tools.mytool1" << endl;
74  fout << "tools.mytool2.SumHists: [" << endl;
75  fout << " {var:\"fitHeight\" name:\"hfh_%0RUN%\""
76  << " title:\"Combined fit height run %RUN%\""
77  << " nbin:60 xmin:-300 xmax:300 plot:\"\"}, " << endl;
78  fout << " {var:\"fitHeight\" name:\"hfh_%0RUN%_chan%0CHAN%\""
79  << " title:\"Fit height run %RUN% channel %CHAN%\""
80  << " nbin:40 xmin:0 xmax:0 fit:gaus plot:\"\"}," << endl;
81  fout << " {var:\"fitWidth\" name:\"hfw_%0RUN%_chan%0CHAN%\""
82  << " title:\"Fit width run %RUN% channel %CHAN%\""
83  << " nbin:40 xmin:0 xmax:4.0 fit:gaus plot:\"\"}" << endl;
84  fout << "]" << endl;
85  fout << "tools.mytool2.ChanSumHists: [" << endl;
86  fout << " {name:\"hcsHeight_%CRNAME%\" title:\"Pulse heights for %LAB0% %LAB1% run %RUN% %CRLABEL%\" "
87  << "valHist:\"hfh_%0RUN%_chan%0CHAN%\" valType:fitMean errType:fitSigma nbins:0 cr:apa1x plot:\"\" pran:\"\"}," << endl;
88  fout << " {name:\"hcsWidth_%CRNAME%\" title:\"Shaping times for run %RUN% %CRLABEL%\" "
89  << "valHist:\"hfw_%0RUN%_chan%0CHAN%\" valType:fitMean errType:fitSigma nbins:0 cr:apa1x plot:\"\" pran:\"\"}" << endl;
90  fout << "]" << endl;
91  //fout << " {val:\"hfw_%0RUN%_chan%0CHAN%:FitMean\" hist:\"hcsWidth_%0RUN%\"
92  fout << "tools.mytool2.RoiRootFileName: \"\"" << endl;
93  fout << "tools.mytool2.SumRootFileName: \"roisum.root\"" << endl;
94  fout << "tools.mytool2.ChanSumRootFileName: \"roichan.root\"" << endl;
95  fout << "tools.channelRanges: {" << endl;
96  fout << " tool_type: FclIndexRangeTool" << endl;
97  fout << " LogLevel: 0" << endl;
98  fout << " Ranges: [" << endl;
99  fout << " {name:apa1x label:APA1x begin:250 end:270}" << endl;
100  fout << " ]" << endl;
101  fout << "}" << endl;
102  fout.close();
103  } else {
104  cout << myname << "Using existing top-level FCL." << endl;
105  }
106 
107  cout << myname << line << endl;
108  cout << myname << "Fetching tool manager." << endl;
110  assert ( ptm != nullptr );
111  DuneToolManager& tm = *ptm;
112  tm.print();
113  assert( tm.toolNames().size() >= 2 );
114 
115  cout << myname << line << endl;
116  cout << myname << "Fetching tool." << endl;
117  auto ptoo1 = tm.getPrivate<TpcDataTool>("mytool1");
118  assert( ptoo1 != nullptr );
119  auto ptoo2 = tm.getPrivate<TpcDataTool>("mytool2");
120  assert( ptoo2 != nullptr );
121 
122  cout << myname << line << endl;
123  cout << myname << "Create test data." << endl;
124  AdcChannelDataMap acds;
125  vector<float> pulse = { 2.0, -3.0, 0.0, 5.0, 24.0, 56.0, 123.0, 71.0, 52.1, 26.3,
126  12.5, 8.1, 4.5, 2.0, -1.0, 3.2, 1.1, -2.2, 0.1, -0.1};
127  Index npul = 100;
128  for ( Index icha=250; icha<270; ++icha ) {
129  AdcChannelData& acd = acds[icha];
130  acd.setEventInfo(111, icha);
131  acd.setChannelInfo(icha);
132  acd.samples.resize(npul*pulse.size());
133  acd.sampleUnit = "ADC count";
134  double sigma = 5.0;
135  Index itck = 0;
136  for ( Index ipul=0; ipul<npul; ++ipul ) {
137  Index itck0 = itck;
138  for ( Index ismp=0; ismp<pulse.size(); ++ismp, ++itck ) {
139  acd.samples[itck] = pulse[ismp] + gRandom->Gaus(0.0, sigma);
140  }
141  acd.rois.emplace_back( itck0+2, itck-2);
142  }
143  assert( acd.rois.size() == npul );
144  }
145  const AdcChannelData& acd = acds[250];
146 
147  cout << myname << line << endl;
148  cout << myname << "Call tool for one channel." << endl;
149  DataMap res = ptoo1->view(acd);
150  res.print();
151  cout << myname << "roiCount: " << res.getInt("roiCount") << endl;
152  cout << myname << "roiHists:" << endl;
153  for ( TH1* ph : res.getHistVector("roiHists") ) {
154  cout << myname << " " << ph->GetName() << endl;
155  }
156  assert( res == 0 );
157  Index nroi = res.getInt("roiCount");
158  assert( nroi == npul );
159  assert( res.getIntVector("roiTick0s").size() == nroi );
160  assert( res.getIntVector("roiNTicks").size() == nroi );
161  assert( res.getIntVector("roiNUnderflows").size() == nroi );
162  assert( res.getIntVector("roiNOverflows").size() == nroi );
163  assert( res.getIntVector("roiTickMins").size() == nroi );
164  assert( res.getIntVector("roiTickMaxs").size() == nroi );
165  assert( res.getFloatVector("roiSigMins").size() == nroi );
166  assert( res.getFloatVector("roiSigMaxs").size() == nroi );
167  assert( res.getFloatVector("roiSigAreas").size() == nroi );
168  assert( res.getHistVector("roiHists").size() == nroi );
169  assert( res.getFloatVector("roiFitHeights").size() == nroi );
170  assert( res.getFloatVector("roiFitWidths").size() == nroi );
171  assert( res.getFloatVector("roiFitPositions").size() == nroi );
172 
173  cout << myname << line << endl;
174  cout << myname << "Call tool for channel map." << endl;
175  res = ptoo2->viewMap(acds);
176  res.print();
177  cout << myname << "roiCount: " << res.getInt("roiCount") << endl;
178  cout << myname << "roiHists:" << endl;
179  assert( res == 0 );
180  assert( res.getInt("roiCount") == int(npul*acds.size()) );
181 
182  cout << myname << line << endl;
183  cout << myname << "Done." << endl;
184  return 0;
185 }
const std::vector< std::string > & toolNames() const
const IntVector & getIntVector(Name name) const
Definition: DataMap.h:219
const FloatVector & getFloatVector(Name name) const
Definition: DataMap.h:221
void print() const
unsigned int Index
void print(std::ostream *pout) const
Definition: DataMap.h:245
tm
Definition: demo.py:21
const HistVector & getHistVector(Name name) const
Definition: DataMap.h:224
void setChannelInfo(ChannelInfoPtr pchi)
AdcRoiVector rois
size_t size
Definition: lodepng.cpp:55
void setEventInfo(EventInfoPtr pevi)
std::unique_ptr< T > getPrivate(std::string name)
int getInt(Name name, int def=0) const
Definition: DataMap.h:218
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)