83 const string mypre =
"test_AdcDeconvoluteFFT";
84 const string myname = mypre +
": ";
86 cout << myname <<
"NDEBUG must be off." <<
endl;
89 string line =
"-----------------------------";
91 cout << myname << line <<
endl;
92 string fclfile =
"test_AdcDeconvoluteFFT.fcl";
93 AdcSignalVector res = {0.03, 0.31, 0.77, 0.97, 1.00, 0.96, 0.92, 0.84, 0.77, 0.66,
94 0.53, 0.39, 0.31, 0.26, 0.21, 0.17, 0.14, 0.115, 0.08, 0.06,
95 0.043, 0.029, 0.022, 0.015, 0.009, 0.005, 0.003, 0.001};
97 for (
float val : res ) sum +=
val;
98 for (
float&
val : res )
val /= sum;
99 if ( ! useExistingFcl ) {
100 cout << myname <<
"Creating top-level FCL." <<
endl;
101 ofstream
fout(fclfile.c_str());
104 fout <<
" tool_type: AdcDeconvoluteFFT" <<
endl;
106 fout <<
" ResponseVectors: [[";
107 for (
Index ival=0; ival<res.size(); ++ival ) {
108 if ( ival )
fout <<
", ";
113 fout <<
" ResponseCenters: [5]" <<
endl;
114 fout <<
" SmoothVectors: [[-0.5, 0.5]]" <<
endl;
115 fout <<
" SmoothScales: [1.0]" <<
endl;
116 fout <<
" GausFilterSigmas: [" << sigmaFilter <<
"]" <<
endl;
117 fout <<
" LowFilterWidths: [-1.0]" <<
endl;
118 fout <<
" LowFilterPowers: [ 2.0]" <<
endl;
119 fout <<
" IndexMapTool: \"\"" <<
endl;
122 fout <<
"tools.mycondir: @local::tools.mydco" <<
endl;
123 fout <<
"tools.mycondir.Action: 4" <<
endl;
124 fout <<
"tools.myconfft: @local::tools.mydco" <<
endl;
125 fout <<
"tools.myconfft.Action: 2" <<
endl;
128 cout << myname <<
"Using existing top-level FCL." <<
endl;
131 cout << myname << line <<
endl;
132 cout << myname <<
"Fetching tool manager." <<
endl;
134 assert ( ptm !=
nullptr );
139 cout << myname << line <<
endl;
140 cout << myname <<
"Fetching tool." <<
endl;
142 assert( pcondir !=
nullptr );
144 assert( pconfft !=
nullptr );
146 assert( pdco !=
nullptr );
148 cout << myname << line <<
endl;
149 cout << myname <<
"Create true samples." <<
endl;
151 samsTru[20] = 1000.0;
153 cout << myname << line <<
endl;
154 cout << myname <<
"Create data by direct convolution with response." <<
endl;
159 assert( acd.
samples.size() == nsam );
160 DataMap ret = pcondir->update(acd);
162 cout <<
" # samples: " << acd.
samples.size() <<
endl;
163 cout <<
" # DFT amps: " << acd.
dftmags.size() <<
endl;
165 assert( acd.
samples.size() == nsam );
168 cout << myname << line <<
endl;
169 cout << myname <<
"Create data by FFT convolution with response." <<
endl;
174 DataMap retchk = pconfft->update(acdchk);
175 assert( retchk == 0 );
176 cout <<
" # samples: " << acdchk.
samples.size() <<
endl;
177 cout <<
" # DFT amps: " << acdchk.
dftmags.size() <<
endl;
178 cout <<
" # DFT phases: " << acdchk.
dftphases.size() <<
endl;
179 assert( acdchk.
samples.size() == nsam );
182 cout << myname << line <<
endl;
183 cout << myname <<
"Compare convolutions." <<
endl;
186 eout <<
" Direct FFT" <<
endl;
187 for (
Index isam=0; isam<nsam; ++isam ) {
188 float qdir = samsDatNoNoise[isam];
189 float qfft = samsDatCheck[isam];
190 eout <<
setw(5) << isam <<
": " << fixed <<
setw(10) << qdir << fixed <<
setw(10) << qfft;
191 if ( fabs(qfft - qdir) > 1.
e-5 ) {
198 cout << myname <<
"Convolutions disagree:" <<
endl;
199 cout << eout.str() <<
endl;
204 cout << myname << line <<
endl;
205 cout << myname <<
"Add noise." <<
endl;
206 if ( noiseLev > 0.0 ) {
207 for (
float&
val : acd.
samples ) val += gRandom->Gaus(0.0, noiseLev);
211 cout << myname << line <<
endl;
212 cout << myname <<
"Deconvolute." <<
endl;
213 ret = pdco->update(acd);
217 cout << myname << line <<
endl;
218 cout << myname <<
"Check integrals." <<
endl;
220 for (
float sig : res ) ares += sig;
222 for (
float sig : samsTru ) aTru += sig;
223 float aDatNoNoise = 0.0;
224 for (
float sig : samsDatNoNoise ) aDatNoNoise += sig;
226 for (
float sig : samsDat ) aDat += sig;
228 for (
float sig : samsDco ) aDco += sig;
229 cout << myname <<
" Response function: " << ares <<
endl;
230 cout << myname <<
" Input signal: " << aTru <<
endl;
231 cout << myname <<
" Data without noise: " << aDatNoNoise <<
endl;
232 cout << myname <<
" Data with noise: " << aDat <<
endl;
233 cout << myname <<
" Deconvolution: " << aDco <<
endl;
235 cout << myname << line <<
endl;
236 cout << myname <<
"Plot spectra." <<
endl;
238 timPlot.addHist(samsTru,
"True", 3, 2, 1);
240 timPlot.addHist(samsDatNoNoise,
"DataNoNoise", 38, 4, 1);
241 timPlot.addHist(samsDat,
"Data", 1, 2, 1);
242 timPlot.addHist(samsDco,
"Deconvoluted", 2, 2, 1);
243 timPlot.print(mypre +
"_time.png", -50, 200);
245 cout << myname << line <<
endl;
246 cout << myname <<
"Done." <<
endl;
void setChannelInfo(ChannelInfoPtr pchi)
void setEventInfo(EventInfoPtr pevi)
AdcSignalVector dftphases
Q_EXPORT QTSManip setw(int w)
void line(double t, double *p, double &x, double &y, double &z)
std::vector< AdcSignal > AdcSignalVector
QTextStream & endl(QTextStream &s)