3 #ifndef __s2_corr_inline_hpp
4 #define __s2_corr_inline_hpp
9 #include <s2proc/s2_corr.hpp>
16 template <
template <
class>
class Functor>
19 Functor<Trace::AmplT> functor;
22 if (bases.size() < 1 || tr.
size() < 1 || bases.size() > tr.
size())
24 printf (
"S2Corr->traceBaseOp: error: %zu bases provided for %zu samplse in trace.\n",
25 bases.size(), tr.
size());
34 for (
size_t i=0; i<bases.size(); i++)
37 for (
size_t j=0; j<bn; j++)
39 res = functor(trb[j], bases[i]);
41 printf (
"S2Corr->traceBaseOp: base %d, sample %d : %g op %g = %g\n",
42 i, j, trb[j], bases[i], res);
54 template <
typename FFT_T>
63 printf(
"S2Corr::tracesCCF: error: incorrect size of traces tr1.size() = %zu tr2.size = %zu\n",
70 for(
size_t n=0; n<tr1.
size(); ++n)
79 if(En1 > E && En2 > E)
80 norm_coef = 1/sqrt(En1*En2);
82 fft.setRotateFlag(
false);
87 fft.calc(sp1_re, sp1_im);
91 fft.calc(sp2_re, sp2_im);
94 Trace resultRe(sp1_re.header(), sp1_re.size(), 0.);
95 Trace resultIm(sp1_im.header(), sp1_im.size(), 0.);
97 for(
unsigned int i=0; i<sp1_re.size(); ++i)
105 resultRe[i] = sp1_re[i]*sp2_re[i] + sp1_im[i]*sp2_im[i];
106 resultIm[i] = sp1_im[i]*sp2_re[i] - sp1_re[i]*sp2_im[i];
109 fft.setDirection(-1);
111 if(!fft.calc(resultRe, resultIm))
114 size_t half = resultRe.
size()/2;
115 size_t add = resultRe.
size()%2;
120 for (
size_t i=half+add; i<ccf.
size(); i++)
121 ccf[i-half-add] = resultRe[i];
123 for (
size_t i=0; i<half+add; i++)
124 ccf[i+half] = resultRe[i];
127 for (
size_t i=0; i<ccf.
size(); i++)
137 template <
typename FFT_T>
145 {printf(
"traceACF::ERROR: Empty traces tr.size() = %zu\n", tr.
size());
return false;}
147 fft.setRotateFlag(
false);
152 std::fill (sp_im.
begin(), sp_im.end(), 0);
153 fft.calc(sp_re, sp_im);
156 Trace resultRe = sp_re, resultIm = sp_im;
158 std::fill (resultRe.
begin(), resultRe.end(), 0);
159 std::fill (resultIm.begin(), resultIm.end(), 0);
161 for(
unsigned int i=0; i<sp_re.
size(); ++i)
167 resultRe[i] = sp_re[i]*sp_re[i] + sp_im[i]*sp_im[i];
168 resultIm[i] = sp_im[i]*sp_re[i] - sp_re[i]*sp_im[i];
171 fft.setDirection(-1);
173 if(!fft.calc(resultRe, resultIm))
178 size_t half = resultRe.
size()/2;
179 size_t add = resultRe.
size()%2;
188 for (
size_t i=half+add; i<acf.
size(); i++)
189 acf[i-half-add] = resultRe[i];
191 for (
size_t i=0; i<half+add; i++)
192 acf[i+half] = resultRe[i];
197 if(acf[half+add] > 1e-7)
198 norm_coef = 1./acf[half+add];
201 for (
size_t i=0; i<acf.
size(); i++)
213 template <
typename FFT_T>
214 bool S2Corr::SpectrWidth(FFT_T &fft,
219 {printf(
"SpectrWidth::ERROR: Empty traces tr.size() = %zu\n", tr.
size());
return false;}
223 fft.setRotateFlag(
false);
228 std::fill (sp_im.
begin(), sp_im.end(), 0);
229 fft.calc(sp_re, sp_im);
232 Trace resultRe = sp_re, resultIm = sp_im;
237 std::fill (resultRe.
begin(), resultRe.end(), 0);
238 std::fill (resultIm.begin(), resultIm.end(), 0);
240 for(
unsigned int i=0; i<sp_re.
size(); ++i)
245 resultRe[i] = sp_re[i]*sp_re[i] + sp_im[i]*sp_im[i];
247 width_val += (i+1)*(i+1)*resultRe[i];
248 norm_val += resultRe[i];
256 sw_val = width_val/norm_val;
float AmplT
Definition: trace.hpp:21
bool traceACF(FFT_T &fft, const Trace &tr, Trace &acf, bool norma)
Definition: s2_corr_inline.hpp:138
Definition: base_separator.hpp:10
const Header & header() const
Definition: trace.hpp:196
bool tracesCCF(FFT_T &fft, const Trace &tr1, const Trace &tr2, Trace &ccf, bool norma)
Definition: s2_corr_inline.hpp:55
std::vector< Trace::AmplT > DVector
Definition: s2_corr.hpp:20
bool traceBaseOp(Trace &tr, const DVector &bases)
Definition: s2_corr_inline.hpp:17
const_iterator begin() const
Definition: cdft2d.hpp:15