corrected size for noOfFourierBins, and made switching between FFTW and DKS more coherent
This commit is contained in:
@ -99,6 +99,7 @@ PFourier::PFourier(TH1F *data, Int_t unitTag, Double_t startTime, Double_t endTi
|
||||
|
||||
// calculate start and end bin
|
||||
fNoOfData = (UInt_t)((fEndTime-fStartTime)/fTimeResolution);
|
||||
cout << "debug> fNoOfData=" << fNoOfData << endl;
|
||||
|
||||
// check if zero padding is whished
|
||||
if (fZeroPaddingPower > 0) {
|
||||
@ -184,7 +185,15 @@ PFourier::PFourier(TH1F *data, Int_t unitTag, Double_t startTime, Double_t endTi
|
||||
fReal_ptr = 0;
|
||||
fComp_ptr = 0;
|
||||
fReal_ptr = fDks.allocateMemory<double>(fNoOfBins, ierr);
|
||||
if (ierr > 0) {
|
||||
cerr << ">> PFourier: **ERROR** Couldn't allocate memory for fReal_ptr." << endl;
|
||||
fValid = false;
|
||||
}
|
||||
fComp_ptr = fDks.allocateMemory< complex<double> >(size, ierr);
|
||||
if (ierr > 0) {
|
||||
cerr << ">> PFourier: **ERROR** Couldn't allocate memory for fComp_ptr." << endl;
|
||||
fValid = false;
|
||||
}
|
||||
if ((fReal_ptr==0) || (fComp_ptr==0))
|
||||
fValid = false;
|
||||
#else
|
||||
@ -245,7 +254,7 @@ void PFourier::Transform(UInt_t apodizationTag)
|
||||
int dimsize[3] = {fNoOfBins, 1, 1};
|
||||
int status=0, size=fNoOfBins/2+1;
|
||||
// write data to the accelerator
|
||||
status=fDks.writeData<double>(fReal_ptr, fInDKS, fNoOfBins);
|
||||
status = fDks.writeData<double>(fReal_ptr, fInDKS, fNoOfBins);
|
||||
// execute the FFT
|
||||
status = fDks.callR2CFFT(fReal_ptr, fComp_ptr, 1, dimsize);
|
||||
// read data from accelerator
|
||||
@ -276,7 +285,8 @@ void PFourier::Transform(UInt_t apodizationTag)
|
||||
fOut[i][1] = im;
|
||||
}
|
||||
} else { // try DKS
|
||||
for (UInt_t i=0; i<fNoOfBins; i++) {
|
||||
UInt_t size=fNoOfBins/2+1;
|
||||
for (UInt_t i=0; i<size; i++) {
|
||||
phase = 2.0*PI/(fTimeResolution*fNoOfBins) * i * shiftTime;
|
||||
#ifdef HAVE_DKS
|
||||
re = fOutDKS[i].real() * cos(phase) + fOutDKS[i].imag() * sin(phase);
|
||||
@ -314,11 +324,7 @@ void PFourier::SetUseFFTW(const Bool_t flag)
|
||||
*/
|
||||
Double_t PFourier::GetMaxFreq()
|
||||
{
|
||||
UInt_t noOfFourierBins = 0;
|
||||
if (fNoOfBins % 2 == 0)
|
||||
noOfFourierBins = fNoOfBins/2;
|
||||
else
|
||||
noOfFourierBins = (fNoOfBins+1)/2;
|
||||
UInt_t noOfFourierBins = fNoOfBins/2+1;
|
||||
|
||||
return fResolution*noOfFourierBins;
|
||||
}
|
||||
@ -343,11 +349,7 @@ TH1F* PFourier::GetRealFourier(const Double_t scale)
|
||||
snprintf(name, sizeof(name), "%s_Fourier_Re", fData->GetName());
|
||||
snprintf(title, sizeof(title), "%s_Fourier_Re", fData->GetTitle());
|
||||
|
||||
UInt_t noOfFourierBins = 0;
|
||||
if (fNoOfBins % 2 == 0)
|
||||
noOfFourierBins = fNoOfBins/2;
|
||||
else
|
||||
noOfFourierBins = (fNoOfBins+1)/2;
|
||||
UInt_t noOfFourierBins = fNoOfBins/2+1;
|
||||
|
||||
TH1F *realFourier = new TH1F(name, title, noOfFourierBins, -fResolution/2.0, (Double_t)(noOfFourierBins-1)*fResolution+fResolution/2.0);
|
||||
if (realFourier == 0) {
|
||||
@ -395,11 +397,7 @@ TH1F* PFourier::GetImaginaryFourier(const Double_t scale)
|
||||
snprintf(name, sizeof(name), "%s_Fourier_Im", fData->GetName());
|
||||
snprintf(title, sizeof(title), "%s_Fourier_Im", fData->GetTitle());
|
||||
|
||||
UInt_t noOfFourierBins = 0;
|
||||
if (fNoOfBins % 2 == 0)
|
||||
noOfFourierBins = fNoOfBins/2;
|
||||
else
|
||||
noOfFourierBins = (fNoOfBins+1)/2;
|
||||
UInt_t noOfFourierBins = fNoOfBins/2+1;
|
||||
|
||||
TH1F* imaginaryFourier = new TH1F(name, title, noOfFourierBins, -fResolution/2.0, (Double_t)(noOfFourierBins-1)*fResolution+fResolution/2.0);
|
||||
if (imaginaryFourier == 0) {
|
||||
@ -447,11 +445,7 @@ TH1F* PFourier::GetPowerFourier(const Double_t scale)
|
||||
snprintf(name, sizeof(name), "%s_Fourier_Pwr", fData->GetName());
|
||||
snprintf(title, sizeof(title), "%s_Fourier_Pwr", fData->GetTitle());
|
||||
|
||||
UInt_t noOfFourierBins = 0;
|
||||
if (fNoOfBins % 2 == 0)
|
||||
noOfFourierBins = fNoOfBins/2;
|
||||
else
|
||||
noOfFourierBins = (fNoOfBins+1)/2;
|
||||
UInt_t noOfFourierBins = fNoOfBins/2+1;
|
||||
|
||||
TH1F* pwrFourier = new TH1F(name, title, noOfFourierBins, -fResolution/2.0, (Double_t)(noOfFourierBins-1)*fResolution+fResolution/2.0);
|
||||
if (pwrFourier == 0) {
|
||||
@ -499,11 +493,7 @@ TH1F* PFourier::GetPhaseFourier(const Double_t scale)
|
||||
snprintf(name, sizeof(name), "%s_Fourier_Phase", fData->GetName());
|
||||
snprintf(title, sizeof(title), "%s_Fourier_Phase", fData->GetTitle());
|
||||
|
||||
UInt_t noOfFourierBins = 0;
|
||||
if (fNoOfBins % 2 == 0)
|
||||
noOfFourierBins = fNoOfBins/2;
|
||||
else
|
||||
noOfFourierBins = (fNoOfBins+1)/2;
|
||||
UInt_t noOfFourierBins = fNoOfBins/2+1;
|
||||
|
||||
TH1F* phaseFourier = new TH1F(name, title, noOfFourierBins, -fResolution/2.0, (Double_t)(noOfFourierBins-1)*fResolution+fResolution/2.0);
|
||||
if (phaseFourier == 0) {
|
||||
@ -564,45 +554,41 @@ TH1F* PFourier::GetPhaseFourier(const Double_t scale)
|
||||
void PFourier::PrepareFFTwInputData(UInt_t apodizationTag)
|
||||
{
|
||||
// 1st find t==0. fData start at times t<0!!
|
||||
Int_t t0bin = -1;
|
||||
UInt_t t0bin = -1;
|
||||
for (Int_t i=1; i<fData->GetNbinsX(); i++) {
|
||||
if (fData->GetBinCenter(i) >= 0.0) {
|
||||
t0bin = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Int_t ival = static_cast<Int_t>(fStartTime/fTimeResolution) + t0bin;
|
||||
UInt_t start = 0;
|
||||
if (ival >= 0) {
|
||||
start = static_cast<UInt_t>(ival);
|
||||
}
|
||||
cout << "debug> t0bin=" << t0bin << ", fNoOfData=" << fNoOfData << ", fNoOfBins=" << fNoOfBins << endl;
|
||||
|
||||
Double_t mean = 0.0;
|
||||
if (fDCCorrected) {
|
||||
for (UInt_t i=0; i<fNoOfData; i++) {
|
||||
mean += fData->GetBinContent(i+start);
|
||||
for (UInt_t i=t0bin; i<fNoOfData; i++) {
|
||||
mean += fData->GetBinContent(i);
|
||||
}
|
||||
mean /= (Double_t)fNoOfData;
|
||||
}
|
||||
mean /= (Double_t)(fNoOfData-t0bin);
|
||||
cout << "debug> mean=" << mean << endl;
|
||||
}
|
||||
|
||||
// 2nd fill fIn
|
||||
if (fUseFFTW) {
|
||||
for (UInt_t i=0; i<fNoOfData; i++) {
|
||||
fIn[i][0] = fData->GetBinContent(i+start) - mean;
|
||||
for (UInt_t i=0; i<fNoOfData-t0bin; i++) {
|
||||
fIn[i][0] = fData->GetBinContent(i+t0bin) - mean;
|
||||
fIn[i][1] = 0.0;
|
||||
}
|
||||
for (UInt_t i=fNoOfData; i<fNoOfBins; i++) {
|
||||
for (UInt_t i=fNoOfData-t0bin; i<fNoOfBins; i++) {
|
||||
fIn[i][0] = 0.0;
|
||||
fIn[i][1] = 0.0;
|
||||
}
|
||||
} else {
|
||||
for (UInt_t i=0; i<fNoOfData; i++) {
|
||||
for (UInt_t i=0; i<fNoOfData-t0bin; i++) {
|
||||
#ifdef HAVE_DKS
|
||||
fInDKS[i] = fData->GetBinContent(i+start) - mean;
|
||||
fInDKS[i] = fData->GetBinContent(i+t0bin) - mean;
|
||||
#endif
|
||||
}
|
||||
for (UInt_t i=fNoOfData; i<fNoOfBins; i++) {
|
||||
for (UInt_t i=fNoOfData-t0bin; i<fNoOfBins; i++) {
|
||||
#ifdef HAVE_DKS
|
||||
fInDKS[i] = 0.0;
|
||||
#endif
|
||||
@ -625,6 +611,9 @@ void PFourier::PrepareFFTwInputData(UInt_t apodizationTag)
|
||||
*/
|
||||
void PFourier::ApodizeData(Int_t apodizationTag) {
|
||||
|
||||
if (apodizationTag == F_APODIZATION_NONE)
|
||||
return;
|
||||
|
||||
const Double_t cweak[3] = { 0.384093, -0.087577, 0.703484 };
|
||||
const Double_t cmedium[3] = { 0.152442, -0.136176, 0.983734 };
|
||||
const Double_t cstrong[3] = { 0.045335, 0.554883, 0.399782 };
|
||||
@ -635,9 +624,6 @@ void PFourier::ApodizeData(Int_t apodizationTag) {
|
||||
}
|
||||
|
||||
switch (apodizationTag) {
|
||||
case F_APODIZATION_NONE:
|
||||
return;
|
||||
break;
|
||||
case F_APODIZATION_WEAK:
|
||||
c[0] = cweak[0]+cweak[1]+cweak[2];
|
||||
c[1] = -(cweak[1]+2.0*cweak[2]);
|
||||
|
Reference in New Issue
Block a user