23 using std::ostringstream;
31 const string myname =
"test_AdcDataPlotter: ";
33 cout << myname <<
"NDEBUG must be off." <<
endl;
36 string line =
"-----------------------------";
38 cout << myname << line <<
endl;
39 string fclfile =
"test_AdcDataPlotter.fcl";
40 if ( ! useExistingFcl ) {
41 cout << myname <<
"Creating top-level FCL." <<
endl;
42 ofstream
fout(fclfile.c_str());
43 fout <<
"#include \"dataprep_tools.fcl\"" <<
endl;
44 fout <<
"#include \"dunecommon_tools.fcl\"" <<
endl;
45 fout <<
"tools.tickRanges.myTicks: { begin:10 end:90 labels:[\"My ticks\"] }" <<
endl;
47 fout <<
" tool_type: AdcDataPlotter" <<
endl;
51 fout <<
" TickRange: \"myTicks\"" <<
endl;
53 fout <<
" ChannelRanges: []" <<
endl;
56 fout <<
" FembTickOffsets: []" <<
endl;
57 fout <<
" MaxSignal: \"10*[gain]/14.0\"" <<
endl;
58 fout <<
" SkipChannelStatus: []" <<
endl;
60 fout <<
" ChannelLineModulus: 4" <<
endl;
61 fout <<
" ChannelLinePattern: [1]" <<
endl;
63 fout <<
" HistName: \"hadc\"" <<
endl;
64 fout <<
" HistTitle: \"Prepared ADC run %RUN% event %EVENT%\"" <<
endl;
65 fout <<
" PlotTitle: \"Run %RUN% event %EVENT% xyx UTC\"" <<
endl;
66 fout <<
" PlotFileName: \"myplotall-run%0RUN%-evt%0EVENT%.png\"" <<
endl;
69 fout <<
" RootFileName: \"adc.root\"" <<
endl;
71 fout <<
"tools.mytool2: @local::tools.mytool" <<
endl;
72 fout <<
"tools.mytool2.DataView: rois" <<
endl;
73 fout <<
"tools.mytool2.HistTitle: \"Prepared ROI ADC run %RUN% event %EVENT%\"" <<
endl;
74 fout <<
"tools.mytool2.PlotFileName: \"myplotroi-run%0RUN%-evt%0EVENT%.png\"" <<
endl;
75 fout <<
"tools.mytool3: @local::tools.mytool" <<
endl;
76 fout <<
"tools.mytool3.DataView: rnis" <<
endl;
77 fout <<
"tools.mytool3.HistTitle: \"Prepared not ROI ADC run %RUN% event %EVENT%\"" <<
endl;
78 fout <<
"tools.mytool3.PlotFileName: \"myplotrni-run%0RUN%-evt%0EVENT%.png\"" <<
endl;
79 fout <<
"tools.runDataTool: {" <<
endl;
80 fout <<
" tool_type: FclRunDataTool" <<
endl;
82 fout <<
" FileNames: [\"rundata.fcl\"]" <<
endl;
85 ofstream fout2(
"rundata.fcl");
86 fout2 <<
"run: 123" <<
endl;
87 fout2 <<
"gain: 14.0" <<
endl;
88 fout2 <<
"shaping: 2.0" <<
endl;
91 cout << myname <<
"Using existing top-level FCL." <<
endl;
94 cout << myname << line <<
endl;
95 cout << myname <<
"Fetching tool manager." <<
endl;
97 assert ( ptm !=
nullptr );
102 cout << myname << line <<
endl;
103 cout << myname <<
"Fetching tool." <<
endl;
105 assert( padv !=
nullptr );
107 assert( padv2 !=
nullptr );
109 assert( padv3 !=
nullptr );
111 cout << myname << line <<
endl;
112 cout << myname <<
"Create data and call tool." <<
endl;
114 float peds[20] = {701, 711, 733, 690, 688, 703, 720, 720, 695, 702,
115 410, 404, 388, 389, 400, 401, 410, 404, 395, 396};
116 vector<double> wf = {5.0, 20.1, 53.2, 80.6, 130.2, 160.1, 150.4, 125.7, 72.5, 41.3, 18.4,
117 -6.5, -34.9, -56.6, -88.9, -132.6, -170.8, -172.9, -144.6, -112.6,
118 -79.4, -44.9, -22.1, -12.6, -4.7};
119 for (
AdcIndex ievt=0; ievt<nevt; ++ievt ) {
120 cout << myname <<
"Event " << ievt <<
endl;
125 for (
AdcIndex icha=icha1; icha<icha2; ++icha ) {
126 std::pair<AdcChannelDataMap::iterator, bool> kdat = datamap.emplace(icha,
AdcChannelData());
131 float ped = peds[icha-icha1];
134 for (
AdcIndex itic=0; itic<100; ++itic ) {
135 float xadc = ped + gRandom->Gaus(0.0, 10.0);
137 data.
raw.push_back(iadc);
138 data.
samples.push_back(iadc - ped);
140 AdcIndex tp = 10*ievt + 60 - 2.3*(icha-icha1);
141 for (
unsigned int iwf=0; iwf<wf.
size(); ++iwf ) {
142 unsigned int isam = tp+iwf;
143 if ( isam < data.
samples.size() ) {
144 data.
raw[isam] += wf[iwf];
148 for (
unsigned int isam=0; isam<data.
samples.size(); ++isam ) {
153 assert( padv->viewMap(datamap) == 0 );
155 for (
AdcIndex icha=icha1; icha<icha2; ++icha ) {
157 assert( dain.
channel() == icha );
159 AdcIndex tp = 10*ievt + 60 - 2.3*(icha-icha1);
161 vroi.push_back(dain);
164 for (
unsigned int iwf=0; iwf<wf.
size(); ++iwf ) {
166 if ( isam >= nsam )
break;
170 assert( padv2->viewMap(datamap) == 0 );
172 for (
AdcIndex icha=icha1; icha<icha2; ++icha ) {
174 assert( dain.
channel() == icha );
176 AdcIndex tp = 10*ievt + 60 - 2.3*(icha-icha1);
178 vrni.push_back(dain);
180 for (
unsigned int isam=0; isam<tp; ++isam) {
183 vrni.push_back(dain);
185 unsigned int isam0 = tp + wf.
size();
187 for (
unsigned int isam=isam0; isam<nsam; ++isam) {
191 assert( padv3->viewMap(datamap) == 0 );
194 cout << myname << line <<
endl;
195 cout << myname <<
"Done." <<
endl;
202 bool useExistingFcl =
false;
204 string sarg(argv[1]);
205 if ( sarg ==
"-h" ) {
206 cout <<
"Usage: " << argv[0] <<
" [ARG]" <<
endl;
207 cout <<
" If ARG = true, existing FCL file is used." <<
endl;
210 useExistingFcl = sarg ==
"true" || sarg ==
"1";
std::vector< AdcChannelData > View
int main(int argc, char *argv[])
void setChannelInfo(ChannelInfoPtr pchi)
void setEventInfo(EventInfoPtr pevi)
void line(double t, double *p, double &x, double &y, double &z)
View & updateView(Name vnam)
std::map< AdcChannel, AdcChannelData > AdcChannelDataMap
int test_AdcDataPlotter(bool useExistingFcl=false)
QTextStream & endl(QTextStream &s)