Typedefs | Functions
test_AdcChannelDftPlotter.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 <TRandom.h>
#include <cassert>

Go to the source code of this file.

Typedefs

using Index = unsigned int
 
using Name = string
 

Functions

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

Typedef Documentation

using Index = unsigned int

Definition at line 28 of file test_AdcChannelDftPlotter.cxx.

using Name = string

Definition at line 29 of file test_AdcChannelDftPlotter.cxx.

Function Documentation

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

Definition at line 220 of file test_AdcChannelDftPlotter.cxx.

220  {
221  bool useExistingFcl = false;
222  if ( argc > 1 ) {
223  string sarg(argv[1]);
224  if ( sarg == "-h" ) {
225  cout << "Usage: " << argv[0] << " [ARG]" << endl;
226  cout << " If ARG = true, existing FCL file is used." << endl;
227  return 0;
228  }
229  useExistingFcl = sarg == "true" || sarg == "1";
230  }
231  return test_AdcChannelDftPlotter(useExistingFcl);
232 }
int test_AdcChannelDftPlotter(bool useExistingFcl=false)
QTextStream & endl(QTextStream &s)
int test_AdcChannelDftPlotter ( bool  useExistingFcl = false)

Definition at line 33 of file test_AdcChannelDftPlotter.cxx.

33  {
34  const string myname = "test_AdcChannelDftPlotter: ";
35 #ifdef NDEBUG
36  cout << myname << "NDEBUG must be off." << endl;
37  abort();
38 #endif
39  string line = "-----------------------------";
40 
41  cout << myname << line << endl;
42  string fclfile = "test_AdcChannelDftPlotter.fcl";
43  Name vnam = "myview";
44  if ( ! useExistingFcl ) {
45  cout << myname << "Creating top-level FCL." << endl;
46  ofstream fout(fclfile.c_str());
47  fout << "#include \"dataprep_tools.fcl\"" << endl;
48  fout << "tools.mytemplate: {" << endl;
49  fout << " tool_type: AdcChannelDftPlotter" << endl;
50  fout << " LogLevel: 2" << endl;
51  fout << " ChannelStatusFlag: 0" << endl;
52  fout << " ChannelSelection: \"\"" << endl;
53  fout << " SampleFreq: 2000" << endl;
54  fout << " XMin: 0.0" << endl;
55  fout << " XMax: 0.0" << endl;
56  fout << " YMinLog: 0.0" << endl;
57  fout << " HistName: \"\"" << endl;
58  fout << " HistTitle: \"\"" << endl;
59  fout << " HistSummaryTitles: []" << endl;
60  fout << " PlotDataView: \"\"" << endl;
61  fout << " PlotName: \"\"" << endl;
62  fout << " PlotSummaryNames: []" << endl;
63  fout << " PlotChannelRanges: []" << endl;
64  fout << " PlotChannelGroups: []" << endl;
65  fout << " PlotOverlayGroups: 1" << endl;
66  fout << " PlotSizeX: 1000" << endl;
67  fout << " PlotSizeY: 700" << endl;
68  fout << " PlotSplitX: 2" << endl;
69  fout << " PlotSplitY: 0" << endl;
70  fout << "}" << endl;
71  fout << "" << endl;
72  fout << "tools.myphases: @local::tools.mytemplate" << endl;
73  fout << "tools.myphases.Variable: phase" << endl;
74  fout << "tools.myphases.HistName: \"hdftphase_run%0RUN%_evt%0EVENT%\"" << endl;
75  fout << "tools.myphases.HistTitle: \"DFT phases for run %RUN% event %EVENT% channel %CHAN%\"" << endl;
76  fout << "tools.myphases.PlotName: \"dftphase_run%0RUN%_evt%0EVENT%.png\"" << endl;
77  fout << "" << endl;
78  fout << "tools.mymags: @local::tools.mytemplate" << endl;
79  fout << "tools.mymags.Variable: magnitude" << endl;
80  fout << "tools.mymags.YMax: 0.0" << endl;
81  fout << "tools.mymags.HistName: \"hdftmags_run%0RUN%_evt%0EVENT%\"" << endl;
82  fout << "tools.mymags.HistTitle: \"DFT amplitudes for run %RUN% event %EVENT% channel %CHAN%\"" << endl;
83  fout << "tools.mymags.PlotName: \"dftmag_run%0RUN%_evt%0EVENT%.png\"" << endl;
84  fout << "" << endl;
85  fout << "tools.mypwr: @local::tools.mytemplate" << endl;
86  fout << "tools.mypwr.Variable: power" << endl;
87  fout << "tools.mypwr.YMax: 65.0" << endl;
88  fout << "tools.mypwr.NBinX: 5" << endl;
89  fout << "tools.mypwr.HistName: \"hdftpower_run%0RUN%_evt%0EVENT%\"" << endl;
90  fout << "tools.mypwr.HistTitle: \"DFT power for run %RUN% event %EVENT% channel %CHAN%\"" << endl;
91  fout << "tools.mypwr.PlotName: \"dftpower_run%0RUN%_evt%0EVENT%_ch%0CHAN%.png\"" << endl;
92  fout << "" << endl;
93  fout << "tools.mypwt: @local::tools.mytemplate" << endl;
94  fout << "tools.mypwt.Variable: \"power/tick\"" << endl;
95  fout << "tools.mypwt.YMax: 6.0" << endl;
96  fout << "tools.mypwt.NBinX: 5" << endl;
97  fout << "tools.mypwt.HistName: \"hdftpowt_run%0RUN%_evt%0EVENT%\"" << endl;
98  fout << "tools.mypwt.HistTitle: \"DFT power for run %RUN% event %EVENT% channel %CHAN%\"" << endl;
99  fout << "tools.mypwt.PlotName: \"dftpowt_run%0RUN%_evt%0EVENT%_ch%0CHAN%.png\"" << endl;
100  fout << "tools.mvpwr: @local::tools.mypwr" << endl;
101  fout << "tools.mvpwr.PlotDataView: " << vnam << endl;
102  fout << "tools.mvpwr.HistTitle: \"DFT power for run %RUN% event %EVENT% channel %CHAN% view %VIEW%\"" << endl;
103  fout << "tools.mvpwr.PlotName: \"dftpower_run%0RUN%_evt%0EVENT%_ch%0CHAN%_view%VIEW%.png\"" << endl;
104  fout.close();
105  } else {
106  cout << myname << "Using existing top-level FCL." << endl;
107  }
108 
109  cout << myname << line << endl;
110  cout << myname << "Fetching tool manager." << endl;
112  assert ( ptm != nullptr );
113  DuneToolManager& tm = *ptm;
114  tm.print();
115  assert( tm.toolNames().size() >= 1 );
116 
117  cout << myname << line << endl;
118  cout << myname << "Fetching tools." << endl;
119  auto ppha = tm.getPrivate<TpcDataTool>("myphases");
120  auto pmag = tm.getPrivate<TpcDataTool>("mymags");
121  auto ppwr = tm.getPrivate<TpcDataTool>("mypwr");
122  auto ppwt = tm.getPrivate<TpcDataTool>("mypwt");
123  auto ppwrv = tm.getPrivate<TpcDataTool>("mvpwr");
124  assert( ppha != nullptr );
125  assert( pmag != nullptr );
126  assert( ppwr != nullptr );
127  assert( ppwt != nullptr );
128  assert( ppwrv != nullptr );
129 
130  cout << myname << line << endl;
131  cout << myname << "Create data." << endl;
132  AdcChannelData acd;
133  acd.setChannelInfo(123456);
134  acd.setEventInfo(123, 2468, 45);
135  acd.sampleUnit = "fC";
136  float pi = acos(-1.0);
137  vector<float> mags = { 1.0, 2.0, 3.0, 4.0, 5.0, 4.0, 2.0, 1.0, 1.0, 1.0, 1.0 };
138  vector<float> phas = { 0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, -2.0, -1.5, -1.0 };
139  acd.dftmags = mags;
140  acd.dftphases = phas;
141  cout << myname << " Mag size: " << mags.size() << endl;
142  cout << myname << "Phase size: " << phas.size() << endl;
143 
144  cout << myname << line << endl;
145  cout << myname << "Create data map." << endl;
146  AdcChannelDataMap acds;
147  for ( Index icha=10000; icha<10010; ++icha ) {
148  acds[icha].setEventInfo(acd.run(), acd.event(), acd.subRun());;
149  acds[icha].setChannelInfo(icha);
150  acds[icha].dftmags = mags;
151  acds[icha].dftphases = phas;
152  for ( float& mag : mags ) mag *= 1.02;
153  for ( float& pha : phas ) { pha += 0.2; if ( pha > pi ) pha -= 2.0*pi; }
154  // Build the view vnam.
155  vector<float> vmags = mags;
156  for ( float& mag : vmags ) mag *= sqrt(0.70);
157  vector<float> vphas = phas;
158  for ( float& pha : vphas ) { pha += 0.4; if ( pha > pi ) pha -= 2.0*pi; }
159  acds[icha].updateView(vnam).push_back(acds[icha]);
160  acds[icha].updateView(vnam).back().dftmags = vmags;
161  acds[icha].updateView(vnam).back().dftphases = vphas;
162  vmags = mags;
163  for ( float& mag : vmags ) mag *= sqrt(0.30);
164  vphas = phas;
165  for ( float& pha : vphas ) { pha += 0.4; if ( pha > pi ) pha -= 2.0*pi; }
166  acds[icha].updateView(vnam).push_back(acds[icha]);
167  acds[icha].updateView(vnam).back().dftmags = vmags;
168  acds[icha].updateView(vnam).back().dftphases = vphas;
169  }
170 
171  cout << myname << line << endl;
172  cout << myname << "Call phase tool." << endl;
173  DataMap dm = ppha->view(acd);
174  dm.print();
175  assert( dm == 0 );
176 
177  cout << myname << line << endl;
178  cout << myname << "Call mag tool." << endl;
179  dm = pmag->view(acd);
180  dm.print();
181  assert( dm == 0 );
182 
183  cout << myname << line << endl;
184  cout << myname << "Call power tool." << endl;
185  dm = ppwr->view(acd);
186  dm.print();
187  assert( dm == 0 );
188 
189  cout << myname << line << endl;
190  cout << myname << "Call tick power tool." << endl;
191  dm = ppwt->view(acd);
192  dm.print();
193  assert( dm == 0 );
194 
195  cout << myname << line << endl;
196  cout << myname << "Call power tool with map." << endl;
197  dm = ppwr->viewMap(acds);
198  dm.print();
199  assert( dm == 0 );
200 
201  cout << myname << line << endl;
202  cout << myname << "Call tick power tool with map." << endl;
203  dm = ppwt->viewMap(acds);
204  dm.print();
205  assert( dm == 0 );
206 
207  cout << myname << line << endl;
208  cout << myname << "Call tick power view tool with map." << endl;
209  dm = ppwrv->viewMap(acds);
210  dm.print();
211  assert( dm == 0 );
212 
213  cout << myname << line << endl;
214  cout << myname << "Done." << endl;
215  return 0;
216 }
AdcIndex subRun() const
const std::vector< std::string > & toolNames() const
virtual DataMap viewMap(const AdcChannelDataMap &acds) const
ChannelGroupService::Name Name
void print() const
unsigned int Index
void print(std::ostream *pout) const
Definition: DataMap.h:245
tm
Definition: demo.py:21
virtual DataMap view(const AdcChannelData &acd) const
void setChannelInfo(ChannelInfoPtr pchi)
AdcIndex run() const
size_t size
Definition: lodepng.cpp:55
void setEventInfo(EventInfoPtr pevi)
AdcIndex event() const
AdcSignalVector dftphases
std::unique_ptr< T > getPrivate(std::string name)
void line(double t, double *p, double &x, double &y, double &z)
std::map< AdcChannel, AdcChannelData > AdcChannelDataMap
float pi
Definition: units.py:11
static DuneToolManager * instance(std::string fclname="", int dbg=1)
AdcSignalVector dftmags
QTextStream & endl(QTextStream &s)