142 const string mypre =
"test_Tpc2dDeconvolute";
143 const string myname = mypre +
": ";
145 cout << myname <<
"NDEBUG must be off." <<
endl;
148 string line =
"-----------------------------";
150 cout << myname << line <<
endl;
151 string fclfile =
"test_Tpc2dDeconvolute.fcl";
156 if ( ! useExistingFcl ) {
157 cout << myname <<
"Creating top-level FCL." <<
endl;
158 ofstream
fout(fclfile.c_str());
160 fout <<
" [0.2, 0.4, 0.3, 0.1]," <<
endl;
161 fout <<
" [-0.04, -0.08, -0.06, -0.02]," <<
endl;
162 fout <<
" [0.04, 0.08, 0.06, 0.02]" <<
endl;
166 fout <<
" tool_type: Adc2dConvolute" <<
endl;
168 fout <<
" ResponseVectors: @local::data.response" <<
endl;
169 fout <<
" ResponseCenter: 1" <<
endl;;
172 fout <<
" MinChannel: 100" <<
endl;;
173 fout <<
" MaxChannel: 104" <<
endl;;
176 fout <<
" tool_type: AdcToRoi2d" <<
endl;
181 fout <<
" tool_type: Tpc2dDeconvolute" <<
endl;
184 fout <<
" ResponseVectors: @local::data.response" <<
endl;
185 fout <<
" ResponseCenter: 1" <<
endl;
186 fout <<
" InPath: \"conv\"" <<
endl;
187 fout <<
" OutPath: \"dcon\"" <<
endl;
188 fout <<
" SampleSigma: 2.0" <<
endl;
189 fout <<
" ChannelSigma: 0.0" <<
endl;
190 fout <<
" LowFilterPower: 0.0" <<
endl;
191 fout <<
" LowFilterWidth: 0.0" <<
endl;
196 cout << myname <<
"Using existing top-level FCL." <<
endl;
199 cout << myname << line <<
endl;
200 cout << myname <<
"Fetching tool manager." <<
endl;
202 assert ( ptm !=
nullptr );
207 cout << myname << line <<
endl;
208 cout << myname <<
"Fetching tools." <<
endl;
210 assert( pcon !=
nullptr );
212 assert( pdco !=
nullptr );
214 cout << myname << line <<
endl;
215 cout << myname <<
"Create empty input data." <<
endl;
221 for (
Index icha=100; icha<105; ++icha ) {
227 std::map<Index,float> expAreas;
228 for (
Index icha=100; icha<106; ++icha ) expAreas[icha] = 0.0;
234 cout << myname <<
"Add signal " << ++isig <<
endl;
236 data[102].samples[20] = 100.0*sfac;
237 expAreas[100] += +20.0*sfac;
238 expAreas[101] += -20.0*sfac;
239 expAreas[102] += 100.0*sfac;
240 expAreas[103] += -20.0*sfac;
241 expAreas[104] += +20.0*sfac;
245 cout << myname <<
"Add signal " << ++isig <<
endl;
246 data[103].samples[10] = 100.0;
247 expAreas[101] += 20.0;
248 expAreas[102] += -20.0;
249 expAreas[103] += 100.0;
250 expAreas[104] += -20.0;
253 cout << myname << line <<
endl;
254 cout << myname <<
"Check signals." <<
endl;
256 cout << myname <<
"Add signal " << ++isig <<
endl;
257 data[101].samples[30] = 100.0;
258 expAreas[100] += -20.0;
259 expAreas[101] += 100.0;
260 expAreas[102] += -20.0;
261 expAreas[103] += 20.0;
264 cout << myname <<
"Check signals." <<
endl;
265 cout << myname <<
"Signal count: " << nsig <<
endl;
266 assert( isig == nsig );
268 cout << myname << line <<
endl;
269 string fnam =
"noconvhist.png";
270 cout << myname <<
"Create plot " << fnam <<
endl;
271 Plot plt1(data.size());
273 plt1.addData(tpd,
"", lc.green(), 2, 1);
274 plt1.setRange(0, 105);
277 cout << myname << line <<
endl;
278 cout << myname <<
"Call convolution tool." <<
endl;
279 DataMap ret = pcon->updateMap(data);
282 assert( ret.
getInt(
"responseVectorCount") == 3 );
283 assert( ret.
getInt(
"channelMin") == 100 );
284 assert( ret.
getInt(
"channelMax") == 104 );
286 cout << myname << line <<
endl;
287 cout << myname <<
"Copy samples to ROI." <<
endl;
288 tpd.addTpcData(
"conv");
289 assert( tpd.getTpcData(
"conv") != nullptr );
290 assert( tpd.getTpcData(
"dcon") == nullptr );
291 assert( tpd.getTpcData(
"conv")->get2dRois().size() == 0 );
292 tpd.getTpcData(
"conv")->get2dRois().emplace_back(5, nsam, 100, 0);
293 assert( tpd.getTpcData(
"conv")->get2dRois().size() == 1 );
294 Tpc2dRoi& roi = tpd.getTpcData(
"conv")->get2dRois().back();
296 Index& kcha = idxs[0];
297 Index& ksam = idxs[1];
298 for ( kcha=0; kcha<ncha; ++kcha ) {
299 for ( ksam=0; ksam<nsam; ++ksam ) {
300 roi.
data().
setValue(idxs, data[chan0+kcha].samples[ksam]);
303 assert( tpd.getTpcData(
"conv")->get2dRois().size() == 1 );
305 cout << myname << line <<
endl;
306 fnam =
"convhist.png";
307 cout << myname <<
"Create plot " << fnam <<
endl;
308 Plot plt2(data.size());
309 plt2.setRange(-10, 45);
310 plt2.addData(tpd,
"", lc.blue(), 2, 1);
311 plt2.addData(tpd,
"conv", lc.red(), 2, 2);
314 cout << myname << line <<
endl;
315 cout << myname <<
"Check convoluted areas" <<
endl;
316 cout << myname <<
"Chan Nsam Area" <<
endl;
317 cout << myname <<
"---- ---- -----------" <<
endl;
318 for (
const auto& kdat : data ) {
319 Index icha = kdat.first;
323 for (
float sam : sams ) area +=
sam;
324 cout << myname <<
setw(4) << icha <<
setw(6) << nsam <<
setw(13) << area
325 <<
" (" << expAreas[icha] <<
")" <<
endl;
329 cout << myname << line <<
endl;
330 cout << myname <<
"Call deconvolution tool." <<
endl;
331 ret = pdco->updateTpcData(tpd);
334 assert( ret.
getInt(
"dcoNroiIn") == 1 );
335 assert( ret.
getInt(
"dcoNroiOut") == 1 );
336 assert( tpd.getTpcData(
"conv")->get2dRois().size() == 1 );
337 assert( tpd.getTpcData(
"dcon")->get2dRois().size() == 1 );
338 cout << myname <<
"Input normalization: " 339 << tpd.getTpcData(
"conv")->get2dRois()[0].dft()->normalization().globalName() <<
", " 340 << tpd.getTpcData(
"conv")->get2dRois()[0].dft()->normalization().termName() <<
endl;
341 cout << myname <<
"Output normaization: " 342 << tpd.getTpcData(
"dcon")->get2dRois()[0].dft()->normalization().globalName() <<
", " 343 << tpd.getTpcData(
"dcon")->get2dRois()[0].dft()->normalization().termName() <<
endl;
344 assert( tpd.getTpcData(
"conv")->get2dRois()[0].dft()->normalization() ==
345 tpd.getTpcData(
"dcon")->get2dRois()[0].dft()->normalization() );
347 cout << myname << line <<
endl;
348 fnam =
"dcovhist.png";
349 cout << myname <<
"Create plot " << fnam <<
endl;
350 Plot plt3(data.size());
351 plt3.setRange(-10, 45);
352 plt3.addData(tpd,
"", lc.blue(), 2, 1);
353 plt2.addData(tpd,
"conv", lc.red(), 2, 2);
354 plt3.addData(tpd,
"dcon", lc.orange(), 2, 3);
357 cout << myname << line <<
endl;
358 cout << myname <<
"Done." <<
endl;
void print(std::ostream *pout) const
bool checkEqual(string s1, string s2)
void setChannelInfo(ChannelInfoPtr pchi)
DataArray::IndexArray IndexArray
void setEventInfo(EventInfoPtr pevi)
Q_EXPORT QTSManip setw(int w)
int getInt(Name name, int def=0) const
void line(double t, double *p, double &x, double &y, double &z)
const DataArray & data() const
std::vector< AdcSignal > AdcSignalVector
std::map< AdcChannel, AdcChannelData > AdcChannelDataMap
Index setValue(const IndexArray &isams, Float val, Index *pchk=nullptr)
QTextStream & endl(QTextStream &s)