12 #include "cetlib_except/coded_exception.h" 25 LArFFTW(
int transformSize,
const void* fplan,
const void* rplan,
int fitbins);
29 void DoFFT(std::vector<T>& input);
33 void DoInvFFT(std::vector<T>& output);
41 void Convolute(std::vector<T>& func, std::vector<T>& resp);
47 void Deconvolute(std::vector<T>& func, std::vector<T>& resp);
53 void Correlate(std::vector<T>& func, std::vector<T>& resp);
57 void ShiftData(std::vector<T>& input,
double shift);
60 void AlignedSum(std::vector<T>& input, std::vector<T>& output,
bool add =
true);
90 for (
size_t p = 0; p < input.size(); ++p) {
91 ((
double*)
fIn)[p] = input[p];
95 fftw_execute_dft_r2c((fftw_plan)
fPlan, (
double*)
fIn, (fftw_complex*)
fOut);
107 for (
size_t p = 0; p < input.size(); ++p) {
108 ((
double*)
fIn)[p] = input[p];
112 fftw_execute_dft_r2c((fftw_plan)
fPlan, (
double*)
fIn, (fftw_complex*)
fOut);
115 output[i].real(((fftw_complex*)
fOut)[i][0]);
116 output[i].imag(((fftw_complex*)
fOut)[i][1]);
129 fftw_execute_dft_c2r((fftw_plan)
rPlan, (fftw_complex*)
rIn, (
double*)
rOut);
132 double factor = 1.0 / (double)
fSize;
133 const double*
array = (
const double*)(
rOut);
134 for (
int i = 0; i <
fSize; ++i) {
135 output[i] = factor * array[i];
149 ((fftw_complex*)
rIn)[i][0] = input[i].real();
150 ((fftw_complex*)
rIn)[i][1] = input[i].imag();
154 fftw_execute_dft_c2r((fftw_plan)
rPlan, (fftw_complex*)
rIn, (
double*)
rOut);
157 double factor = 1.0 / (double)
fSize;
158 const double*
array = (
const double*)(
rOut);
159 for (
int i = 0; i <
fSize; ++i) {
160 output[i] = factor * array[i];
175 if (n !=
fSize) {
throw cet::exception(
"LArFFTW") <<
"Bad time series size = " << n <<
"\n"; }
183 double re = ((fftw_complex*)
fOut)[i][0];
184 double im = ((fftw_complex*)
fOut)[i][1];
185 ((fftw_complex*)
rIn)[i][0] = re * kern[i].real() - im * kern[i].imag();
186 ((fftw_complex*)
rIn)[i][1] = re * kern[i].imag() + im * kern[i].real();
200 int n = func1.size();
201 if (n !=
fSize) {
throw cet::exception(
"LArFFTW") <<
"Bad 1st time series size = " << n <<
"\n"; }
203 if (n !=
fSize) {
throw cet::exception(
"LArFFTW") <<
"Bad 2nd time series size = " << n <<
"\n"; }
207 fKern[i].real(((fftw_complex*)
fOut)[i][0]);
208 fKern[i].imag(((fftw_complex*)
fOut)[i][1]);
214 double re = ((fftw_complex*)
fOut)[i][0];
215 double im = ((fftw_complex*)
fOut)[i][1];
216 ((fftw_complex*)
rIn)[i][0] = re *
fKern[i].real() - im *
fKern[i].imag();
217 ((fftw_complex*)
rIn)[i][1] = re *
fKern[i].imag() + im *
fKern[i].real();
232 if (n !=
fSize) {
throw cet::exception(
"LArFFTW") <<
"Bad time series size = " << n <<
"\n"; }
239 double a, b, c,
d,
e;
241 a = ((fftw_complex*)
fOut)[i][0];
242 b = ((fftw_complex*)
fOut)[i][1];
245 e = 1. / (c * c + d *
d);
246 ((fftw_complex*)
rIn)[i][0] = (a * c + b *
d) * e;
247 ((fftw_complex*)
rIn)[i][1] = (b * c - a *
d) * e;
262 if (n !=
fSize) {
throw cet::exception(
"LArFFTW") <<
"Bad 1st time series size = " << n <<
"\n"; }
264 if (n !=
fSize) {
throw cet::exception(
"LArFFTW") <<
"Bad 2nd time series size = " << n <<
"\n"; }
268 fKern[i].real(((fftw_complex*)
fOut)[i][0]);
269 fKern[i].imag(((fftw_complex*)
fOut)[i][1]);
274 double a, b, c,
d,
e;
276 a = ((fftw_complex*)
fOut)[i][0];
277 b = ((fftw_complex*)
fOut)[i][1];
280 e = 1. / (c * c + d *
d);
281 ((fftw_complex*)
rIn)[i][0] = (a * c + b *
d) * e;
282 ((fftw_complex*)
rIn)[i][1] = (b * c - a *
d) * e;
297 if (n !=
fSize) {
throw cet::exception(
"LArFFTW") <<
"Bad time series size = " << n <<
"\n"; }
305 double re = ((fftw_complex*)
fOut)[i][0];
306 double im = ((fftw_complex*)
fOut)[i][1];
307 ((fftw_complex*)
rIn)[i][0] = re * kern[i].real() + im * kern[i].imag();
308 ((fftw_complex*)
rIn)[i][1] = -re * kern[i].imag() + im * kern[i].real();
322 int n = func1.size();
323 if (n !=
fSize) {
throw cet::exception(
"LArFFTW") <<
"Bad 1st time series size = " << n <<
"\n"; }
325 if (n !=
fSize) {
throw cet::exception(
"LArFFTW") <<
"Bad 2nd time series size = " << n <<
"\n"; }
329 fKern[i].real(((fftw_complex*)
fOut)[i][0]);
330 fKern[i].imag(((fftw_complex*)
fOut)[i][1]);
336 double re = ((fftw_complex*)
fOut)[i][0];
337 double im = ((fftw_complex*)
fOut)[i][1];
338 ((fftw_complex*)
rIn)[i][0] = re *
fKern[i].real() + im *
fKern[i].imag();
339 ((fftw_complex*)
rIn)[i][1] = -re *
fKern[i].imag() + im *
fKern[i].real();
371 for (
int i = 0; i <
fSize; i++)
372 shape1[i] += shape2[i];
384 float chiSqr = std::numeric_limits<float>::max();
385 float dchiSqr = std::numeric_limits<float>::max();
386 const float chiCut = 1
e-3;
387 float lambda = 0.001;
388 std::vector<float> p;
390 std::vector<T> holder = shape1;
393 int maxT = max_element(holder.begin(), holder.end()) - holder.begin();
397 for (
int i = 0; i <
fFitBins; i++) {
400 else if (startT + i >
fSize)
404 if (holder[i + startT + offset] <= 0.) {
fConvHist[i] = 0.; }
406 fConvHist[i] = holder[i + startT + offset];
425 else if (trial > 100) {
428 }
while (fabs(dchiSqr) >= chiCut);
429 if (!fitResult) p1 = p[1];
431 return p1 + 0.5 + startT;
std::vector< double > DoubleVector
Namespace for general, non-LArSoft-specific utilities.
std::vector< std::complex< double >> ComplexVector
LArFFTW(int transformSize, const void *fplan, const void *rplan, int fitbins)
T PeakCorrelation(std::vector< T > &shape1, std::vector< T > &shape2)
int mrqdtfit(float &lambda, float p[], float y[], const int nParam, const int nData, float &chiSqr, float &dchiSqr)
void AlignedSum(std::vector< T > &input, std::vector< T > &output, bool add=true)
std::vector< float > fConvHist
void Deconvolute(std::vector< T > &func, const ComplexVector &kern)
auto array(Array const &a)
Returns a manipulator which will print the specified array.
void ShiftData(ComplexVector &input, double shift)
void Convolute(std::vector< T > &func, const ComplexVector &kern)
void Correlate(std::vector< T > &func, const ComplexVector &kern)
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
gshf::MarqFitAlg * fMarqFitAlg
std::vector< float > FloatVector
void DoInvFFT(std::vector< T > &output)
void DoFFT(std::vector< T > &input)
cet::coded_exception< error, detail::translate > exception