13 #include "cetlib_except/coded_exception.h" 14 #include "larvecutils/MarqFitAlg/MarqFitAlg.h" 26 LArFFTW(
int transformSize,
const void* fplan,
const void* rplan,
int fitbins);
29 template <
class T>
void DoFFT(std::vector<T>&
input);
36 template <
class T>
void Convolute(std::vector<T>&
func, std::vector<T>& resp);
40 template <
class T>
void Deconvolute(std::vector<T>&
func, std::vector<T>& resp);
44 template <
class T>
void Correlate(std::vector<T>&
func, std::vector<T>& resp);
47 template <
class T>
void ShiftData(std::vector<T> &
input,
double shift);
51 template <
class T>
T PeakCorrelation(std::vector<T> &shape1,std::vector<T> &shape2);
79 for(
size_t p = 0;
p < input.size(); ++
p){
80 ((
double *)
fIn)[
p] = input[
p];
84 fftw_execute_dft_r2c((fftw_plan)
fPlan,(
double*)
fIn,(fftw_complex*)
fOut);
95 for(
size_t p = 0;
p < input.size(); ++
p){
96 ((
double *)
fIn)[
p] = input[
p];
100 fftw_execute_dft_r2c((fftw_plan)
fPlan,(
double*)
fIn,(fftw_complex*)
fOut);
103 output[i].real(((fftw_complex*)
fOut)[i][0]);
104 output[i].imag(((fftw_complex*)
fOut)[i][1]);
116 fftw_execute_dft_c2r((fftw_plan)
rPlan,(fftw_complex*)
rIn,(
double*)
rOut);
119 double factor = 1.0/(double)
fSize;
120 const double *
array = (
const double*)(
rOut);
121 for(
int i = 0; i <
fSize; ++i){
122 output[i] = factor*array[i];
135 ((fftw_complex*)
rIn)[i][0] = input[i].real();
136 ((fftw_complex*)
rIn)[i][1] = input[i].imag();
140 fftw_execute_dft_c2r((fftw_plan)
rPlan,(fftw_complex*)
rIn,(
double*)
rOut);
143 double factor = 1.0/(double)
fSize;
144 const double *
array = (
const double*)(
rOut);
145 for(
int i = 0; i <
fSize; ++i){
146 output[i] = factor*array[i];
162 throw cet::exception(
"LArFFTW") <<
"Bad time series size = " << n <<
"\n";
166 throw cet::exception(
"LArFFTW") <<
"Bad kernel size = " << n <<
"\n";
173 double re = ((fftw_complex*)
fOut)[i][0];
174 double im = ((fftw_complex*)
fOut)[i][1];
175 ((fftw_complex*)
rIn)[i][0] = re*kern[i].real()-im*kern[i].imag();
176 ((fftw_complex*)
rIn)[i][1] = re*kern[i].imag()+im*kern[i].real();
187 std::vector<T>&
func2){
190 int n = func1.size();
192 throw cet::exception(
"LArFFTW") <<
"Bad 1st time series size = " << n <<
"\n";
196 throw cet::exception(
"LArFFTW") <<
"Bad 2nd time series size = " << n <<
"\n";
201 fKern[i].real(((fftw_complex*)
fOut)[i][0]);
202 fKern[i].imag(((fftw_complex*)
fOut)[i][1]);
208 double re = ((fftw_complex*)
fOut)[i][0];
209 double im = ((fftw_complex*)
fOut)[i][1];
210 ((fftw_complex*)
rIn)[i][0] = re*
fKern[i].real()-im*
fKern[i].imag();
211 ((fftw_complex*)
rIn)[i][1] = re*
fKern[i].imag()+im*
fKern[i].real();
227 throw cet::exception(
"LArFFTW") <<
"Bad time series size = " << n <<
"\n";
231 throw cet::exception(
"LArFFTW") <<
"Bad kernel size = " << n <<
"\n";
239 a = ((fftw_complex*)
fOut)[i][0];
240 b = ((fftw_complex*)
fOut)[i][1];
244 ((fftw_complex*)
rIn)[i][0] = (a*c+b*
d)*e;
245 ((fftw_complex*)
rIn)[i][1] = (b*c-a*
d)*e;
256 std::vector<T>& resp){
261 throw cet::exception(
"LArFFTW") <<
"Bad 1st time series size = " << n <<
"\n";
265 throw cet::exception(
"LArFFTW") <<
"Bad 2nd time series size = " << n <<
"\n";
270 fKern[i].real(((fftw_complex*)
fOut)[i][0]);
271 fKern[i].imag(((fftw_complex*)
fOut)[i][1]);
278 a = ((fftw_complex*)
fOut)[i][0];
279 b = ((fftw_complex*)
fOut)[i][1];
283 ((fftw_complex*)
rIn)[i][0] = (a*c+b*
d)*e;
284 ((fftw_complex*)
rIn)[i][1] = (b*c-a*
d)*e;
301 throw cet::exception(
"LArFFTW") <<
"Bad time series size = " << n <<
"\n";
305 throw cet::exception(
"LArFFTW") <<
"Bad kernel size = " << n <<
"\n";
312 double re = ((fftw_complex*)
fOut)[i][0];
313 double im = ((fftw_complex*)
fOut)[i][1];
314 ((fftw_complex*)
rIn)[i][0] = re*kern[i].real()+im*kern[i].imag();
315 ((fftw_complex*)
rIn)[i][1] = -re*kern[i].imag()+im*kern[i].real();
327 std::vector<T>&
func2){
330 int n = func1.size();
332 throw cet::exception(
"LArFFTW") <<
"Bad 1st time series size = " << n <<
"\n";
336 throw cet::exception(
"LArFFTW") <<
"Bad 2nd time series size = " << n <<
"\n";
341 fKern[i].real(((fftw_complex*)
fOut)[i][0]);
342 fKern[i].imag(((fftw_complex*)
fOut)[i][1]);
348 double re = ((fftw_complex*)
fOut)[i][0];
349 double im = ((fftw_complex*)
fOut)[i][1];
350 ((fftw_complex*)
rIn)[i][0] = re*
fKern[i].real()+im*
fKern[i].imag();
351 ((fftw_complex*)
rIn)[i][1] = -re*
fKern[i].imag()+im*
fKern[i].real();
377 std::vector<T> & shape2,
384 if(add)
for(
int i = 0; i <
fSize; i++) shape1[i]+=shape2[i];
394 std::vector<T> & shape2)
398 const float chiCut = 1
e-3;
399 float lambda = 0.001;
400 std::vector<float>
p;
402 std::vector<T> holder = shape1;
405 int maxT = max_element(holder.begin(), holder.end())-holder.begin();
410 if(startT+i < 0) offset=
fSize;
413 if(holder[i+startT+offset]<=0.) {
434 }
else if (trial>100){
438 while (fabs(dchiSqr) >= chiCut);
439 if (!fitResult)p1=p[1];
441 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)
Coord add(Coord c1, Coord c2)
T PeakCorrelation(std::vector< T > &shape1, std::vector< T > &shape2)
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)
void ShiftData(ComplexVector &input, double shift)
void Convolute(std::vector< T > &func, const ComplexVector &kern)
static int max(int a, int b)
void Correlate(std::vector< T > &func, const ComplexVector &kern)
auto array(Array const &a)
Returns a manipulator which will print the specified array.
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