61 const int ConstArrayLength,
const int Blength,
64 std::cout <<
"CgemDigitizerSvc::ConvolveWithConst::init(): trying to initialize a instance that claimed itself initialized. may cause problem!!!!" << std::endl;
72 len=ConstArrayLength+Blength-1;
83 m_length=ConstArrayLength+Blength-1;
86 std::vector<double> A_tmp;
89 if (0==m_map[pars].fft){
90 m_map[pars].fft =TVirtualFFT::FFT(1, &m_length,options1[opt]);
91 m_map[pars].ifft=TVirtualFFT::FFT(1, &m_length,options2[opt]);
95 m_fft = m_map[pars].fft;
96 m_ifft = m_map[pars].ifft;
97 m_ref = m_map.find(pars);
98 m_map[pars].refcount++;
107 zeros.resize(m_length*2);
108 A_fft.resize(m_length*2);
112 A_tmp.resize(m_length);
115 double *p_A_fft=&(A_fft.front());
116 double *p_A_tmp=&(A_tmp.front());
118 std::memcpy(p_A_tmp,ConstArray,ConstArrayLength*
sizeof(
double));
119 m_fft->SetPoints(p_A_tmp);
121 m_fft->GetPoints(p_A_fft);
168 int leftIndex,
int sizeofOut,
double factor)
const{
169 if (not m_initialized){
throw "ConvolveWithConst::convolve: object not initialized";}
170 if (leftIndex > m_length)
throw "ConvolveWithConst::convolve: leftIndex"
171 "should not be more than NA+NB-1, as there should be only 0";
172 if (leftIndex <0 )
throw "ConvolveWithConst::convolve: leftIndex should not be negative.";
175 B_tmp.resize(m_length);
176 B_fft.resize(m_length*2);
177 AB_fft.resize(m_length*2);
179 double *p_A_fft=&(A_fft.front());
180 double *p_B_fft=&(B_fft.front());
181 double *p_AB_fft=&(AB_fft.front());
183 double *p_B_tmp=&(B_tmp.front());
184 const double *p_zeros=&(zeros.front());
187 std::memcpy(p_B_tmp,B,m_BLength*
sizeof(
double));
189 m_fft->SetPoints(p_B_tmp);
191 m_fft->GetPoints(p_B_fft);
196 for (
int i = 0; i < (m_length / 2 + 1); i++) {
197 ((
Complex *)p_AB_fft)[i] = ((
Complex *)p_A_fft)[i] * ((
Complex *)p_B_fft)[i] / (double)m_length * factor;
199 for (
int i = m_length - 1; i >= (m_length / 2 + 1); i--) {
200 AB_fft[2 * i] = AB_fft[2 * (m_length - i)];
201 AB_fft[2 * i + 1] = -AB_fft[2 * (m_length - i) + 1];
203 m_ifft->SetPoints(p_AB_fft);
205 m_ifft->GetPoints(p_B_tmp);
206 if (leftIndex+sizeofOut <=m_length){
207 std::memcpy(
output,(p_B_tmp+leftIndex),sizeofOut*
sizeof(
double));
210 std::memcpy(
output,(p_B_tmp+leftIndex),(m_length-leftIndex)*
sizeof(
double));
211 while (leftIndex+sizeofOut -m_length > zeros.size()){
212 std::memcpy(
output+m_length-leftIndex,(p_zeros),(zeros.size())*
sizeof(
double));
214 sizeofOut-=zeros.size();
217 std::memcpy(
output+m_length-leftIndex,(p_zeros),(leftIndex+sizeofOut -m_length)*
sizeof(
double));
252 if (not m_initialized){cerr<<
"ConvolveWithConst::FFT: object not initialized"<<endl;
throw "ConvolveWithConst::FFT: object not initialized";}
253 if (LengthOutAsDouble/2 < m_length / 2 +1) {cerr<<
"ConvolveWithConst::FFT:LengthOutAsDouble too small" <<endl;
throw "LengthOutAsDouble too small";}
255 B_tmp.resize(m_length);
256 double *p_B_tmp=&(B_tmp.front());
257 std::memcpy(p_B_tmp,inNormalLength,LengthIn*
sizeof(
double));
259 m_fft->SetPoints(p_B_tmp);
261 m_fft->GetPoints((
double*)outHalfPlus1);
272 if (not m_initialized){cerr<<
"ConvolveWithConst::IFFT: object not initialized"<<endl;
throw "ConvolveWithConst::IFFT: object not initialized";}
273 if (lengthInAsDouble/2 < m_length/2+1){ cerr<<
"ConvolveWithConst::IFFT:LengthInAsDouble too small"<<endl;
throw "LengthInAsDouble too small";}
274 AB_fft.resize(m_length*2);
275 double *p_AB_fft=&(AB_fft.front());
277 B_tmp.resize(m_length);
278 double *p_B_tmp=&(B_tmp.front());
283 std::memcpy(p_AB_fft,inHalfPlus1,lengthInAsDouble*
sizeof(
double));
284 for (
int i = m_length - 1; i >= (m_length / 2 + 1); i--) {
285 AB_fft[2 * i] = AB_fft[2 * (m_length - i)];
286 AB_fft[2 * i + 1] = -AB_fft[2 * (m_length - i) + 1];
292 m_ifft->SetPoints(p_AB_fft);
294 m_ifft->GetPoints(p_B_tmp);
295 if (lengthOut> m_length)lengthOut = m_length;
296 std::memcpy(outNormalLength,p_B_tmp,lengthOut*
sizeof(
double));
void MultiplyAndAdd(Complex *outHalfPlus1, const Complex *inHalfPlus1, double factor=1) const
multiply with ffted saved results and add them to output with factor; out += in* SavedConst*factor/L
void FFT(Complex *outHalfPlus1, const double *inNormalLength, int LengthOutAsDouble, int LengthIn) const
Do fft with respect of getLength();.
void convolve(double *output, const double *B, const int leftIndex, const int sizeofOut, double factor=1) const
do a convolve of stored const A and B, and put results to output.
void IFFT(double *outNormalLength, const Complex *inHalfPlus1, int lengthOut, int lengthInAsDouble) const
Do ifft with respect of getLength();.