96 const string myname =
"Tpc2dDeconvolute::updateTpcData: ";
100 if ( ptpdIn ==
nullptr ) {
101 cout << myname <<
"WARNING: Input TPC data not found at " <<
m_InPath <<
"." <<
endl;
109 if ( ptpdOut ==
nullptr ) {
111 cout << myname <<
"Adding data path " <<
m_OutPath <<
"." <<
endl;
114 if ( ptpdOut ==
nullptr ) {
115 cout << myname <<
"ERROR: Unable to create output TPC data at " <<
m_OutPath <<
"." <<
endl;
120 if ( poutrois->size() ) {
122 cout << myname <<
"WARNING: Output 2D ROI container is not empty." <<
endl;
132 Index ncha = roi.channelSize();
133 Index nsam = roi.sampleSize();
135 if (
fft().checkDataSize(ndxs) ) {
136 cout << myname <<
"ERROR: Skipping too-large 2D ROI: " << ncha <<
" x " << nsam <<
endl;
140 if ( roi.dft() == nullptr ) {
146 if ( roi.dft() == nullptr ) {
147 cout << myname <<
"ERROR: Forward FFT of ROI failed." <<
endl;
158 while ( samoffInt < 0 ) samoffInt += nsamInt;
159 while ( samoffInt >= nsamInt ) samoffInt -= nsamInt;
160 Index samoff = samoffInt;
161 for (
Index dcha1=0; dcha1<(ncha+1)/2; ++dcha1 ) {
166 Index dcha2 = ncha - dcha1;
167 if ( dcha2 != dcha1 ) dchas.push_back(dcha2);
169 for (
Index dsam=0; dsam<nsam; ++dsam ) {
170 Index isam = dsam + samoff;
171 if ( isam >= nsam ) isam -= nsam;
172 float rval = isam < res1d.size() ? res1d[isam] : 0.0;
173 for (
Index dcha : dchas ) {
175 Index idat = resDat.setValue(idxs, rval);
177 cout << myname <<
" res[" << dcha <<
", " << dsam <<
"]: " << rval <<
endl;
180 if ( idat >= resDat.size() ) {
181 cout << myname <<
"ERROR: Unexpected invalid response indices." <<
endl;
188 DftData resDft(respNorm, ndxs);
193 std::vector<double> samFilt(nsam, 1.0);
196 for (
Index ifrq=0; ifrq<nsam; ++ifrq ) {
197 float xf = ifrq/freqSigma;
198 float fac = exp(-xf*xf/2.0);
200 if (
m_LogLevel >= 3 ) cout << myname <<
" samfil[" << ifrq <<
"]: " << fac <<
endl;
206 std::vector<double> chaFilt(ncha, 1.0);
209 for (
Index ifrq=0; ifrq<ncha; ++ifrq ) {
210 float xf = ifrq/freqSigma;
211 float fac = exp(-xf*xf/2.0);
213 if (
m_LogLevel >= 3 ) cout << myname <<
" chafil[" << ifrq <<
"]: " << fac <<
endl;
216 std::vector<double> samFiltLow(nsam, 1.0);
223 for (
Index ifrq=1; ifrq<nsam; ++ifrq ) {
225 samFiltLow[ifrq] = 1.0/(1.0 + arg);
233 for (
Index idat=0; idat<poutDft->
size(); ++idat ) {
235 Index dcha = idxs[0][0];
236 Index dsam = idxs[0][1];
242 cout << myname <<
"Decon[" << dcha <<
"," << dsam <<
"]";
243 cout <<
"[" << dchaFilt <<
"," << dsamFilt <<
"]";
244 cout <<
": " << comstr(val);
246 val *= chaFilt[dchaFilt];
247 val *= samFilt[dsamFilt];
248 val *= samFiltLow[dsamFilt];
250 if ( resp != 0.0 ) val /= resp;
252 cout <<
" * " << chaFilt[dchaFilt];
253 cout <<
" * " << samFilt[dsamFilt];
254 cout <<
" / " << comstr(resp) <<
" = " << comstr(val) <<
endl;
258 cout << myname <<
" Input power: " << roiDft.
power() <<
endl;
259 cout << myname <<
"Response power: " << resDft.power() <<
endl;
260 cout << myname <<
" Output power: " << poutDft->
power() <<
endl;
264 if ( poutrois !=
nullptr ) {
265 poutrois->emplace_back(ncha, nsam, roi.channelOffset(), roi.sampleOffset());
266 poutroi = &poutrois->back();
272 cout << myname <<
"ERROR: Reverse xform failed with error " << dstat <<
endl;
277 ret.
setInt(
"dcoNroiIn", inrois.size());
278 ret.
setInt(
"dcoNroiOut", nroi);
const std::vector< F > & data() const
int fftForward(const Data &dat, DFT &dft, Index logLevel=0)
DataMap & setStatus(int stat)
IndexArrayVector indexArrays(Index idat) const
TpcData * addTpcData(Name nam, bool copyAdcData=true)
DftData::IndexArray IndexArray
static RealDftNormalization convolutionNormalization()
int fftBackward(const DFT &dft, Data &dat, Index logLevel=0)
ResponseVectorVector m_ResponseVectors
void setInt(Name name, int val)
std::complex< Float > Complex
TpcData * getTpcData(Name nam)
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
std::vector< Tpc2dRoi > Tpc2dRoiVector
AdcSignalVector ResponseVector
const DataArray & data() const
virtual F power(const IndexArray &ifrqs) const
Tpc2dRoiVector & get2dRois()
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
QTextStream & endl(QTextStream &s)