15 using std::ostringstream;
31 float tht = 180/acos(-1.0)*std::arg(val);
34 ssout.setf(std::ios::fixed);
37 ssout <<
"(" << mag <<
"@" <<
setw(4) <<
int(tht) <<
")";
48 : m_LogLevel(ps.
get<
int>(
"LogLevel")),
50 m_ResponseCenter(ps.
get<
int>(
"ResponseCenter")),
52 m_InPath(ps.
get<
Name>(
"InPath")),
53 m_OutPath(ps.
get<
Name>(
"OutPath")),
54 m_SampleSigma(ps.
get<
float>(
"SampleSigma")),
55 m_ChannelSigma(ps.
get<
float>(
"ChannelSigma")),
56 m_LowFilterWidth(ps.
get<
float>(
"LowFilterWidth")),
57 m_LowFilterPower(ps.
get<
float>(
"LowFilterPower")),
58 m_pfft(new
Fw2dFFT(m_FftSize, 1)) {
59 const string myname =
"Tpc2dDeconvolute::ctor: ";
61 std::ios cout_state(
nullptr);
62 cout_state.copyfmt(std::cout);
63 cout << myname <<
"Parameters:" <<
endl;
65 cout << myname <<
" ResponseVectors: [";
69 if ( first ) first =
false;
71 for (
Index isam=0; isam<vec.size(); ++isam ) {
72 float val = vec[isam];
73 if ( isam != 0 ) cout <<
", ";
74 if ( isam == 0 ) cout <<
"\n" << myname <<
setw(indent) <<
"[";
75 else if ( 10*(isam/10) == isam ) cout <<
"\n" << myname <<
setw(indent) <<
" ";
81 cout << myname <<
setw(indent-2) <<
"]" <<
endl;
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 ) {
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);
285 const string myname =
"Tpc2dDeconvolute::updateTpcData: ";
286 cout << myname <<
"ERROR: View of TPC data is not supported here." <<
endl;
const std::vector< F > & data() const
int fftForward(const Data &dat, DFT &dft, Index logLevel=0)
DFT::IndexArray IndexArray
DataMap & setStatus(int stat)
IndexArrayVector indexArrays(Index idat) const
ChannelGroupService::Name Name
TpcData * addTpcData(Name nam, bool copyAdcData=true)
DftData::IndexArray IndexArray
Q_EXPORT QTSManip setprecision(int p)
static RealDftNormalization convolutionNormalization()
std::vector< Index > IndexVector
int fftBackward(const DFT &dft, Data &dat, Index logLevel=0)
std::vector< ResponseVector > ResponseVectorVector
DataMap viewTpcData(const TpcData &) const override
Index size(Index idim) const
ResponseVectorVector m_ResponseVectors
void setInt(Name name, int val)
std::vector< double > DoubleVector
static constexpr double ps
Tpc2dDeconvolute(fhicl::ParameterSet const &ps)
Q_EXPORT QTSManip setw(int w)
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
std::vector< AdcSignal > AdcSignalVector
Dft::FloatVector FloatVector
virtual F power(const IndexArray &ifrqs) const
std::unique_ptr< Fw2dFFT > m_pfft
auto const & get(AssnsNode< L, R, D > const &r)
Index setValue(const IndexArray &isams, Float val, Index *pchk=nullptr)
Tpc2dRoiVector & get2dRois()
DataMap updateTpcData(TpcData &) const override
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
QTextStream & endl(QTextStream &s)
Real2dData< float > DataArray