|
musrfit 1.10.0
|
#include <PFourier.h>
Public Member Functions | |
| PFourier (TH1F *data, Int_t unitTag, Double_t startTime=0.0, Double_t endTime=0.0, Bool_t dcCorrected=false, UInt_t zeroPaddingPower=0) | |
| virtual | ~PFourier () |
| virtual void | Transform (UInt_t apodizationTag=0) |
| virtual const char * | GetDataTitle () |
| virtual const Int_t | GetUnitTag () |
| virtual Double_t | GetResolution () |
| virtual Double_t | GetMaxFreq () |
| virtual TH1F * | GetRealFourier (const Double_t scale=1.0) |
| virtual TH1F * | GetImaginaryFourier (const Double_t scale=1.0) |
| virtual TH1F * | GetPowerFourier (const Double_t scale=1.0) |
| virtual TH1F * | GetPhaseFourier (const Double_t scale=1.0) |
| virtual Bool_t | IsValid () |
Static Public Member Functions | |
| static TH1F * | GetPhaseOptRealFourier (const TH1F *re, const TH1F *im, std::vector< Double_t > &phase, const Double_t scale=1.0, const Double_t min=-1.0, const Double_t max=-1.0) |
Private Member Functions | |
| virtual void | PrepareFFTwInputData (UInt_t apodizationTag) |
| virtual void | ApodizeData (Int_t apodizationTag) |
Private Attributes | |
| TH1F * | fData |
| data histogram to be Fourier transformed. | |
| Bool_t | fValid |
| true = all boundary conditions fullfilled and hence a Fourier transform can be performed. | |
| Int_t | fUnitTag |
| 1=Field Units (G), 2=Field Units (T), 3=Frequency Units (MHz), 4=Angular Frequency Units (Mc/s) | |
| Int_t | fApodization |
| 0=none, 1=weak, 2=medium, 3=strong | |
| Double_t | fTimeResolution |
| time resolution of the data histogram in (us) | |
| Double_t | fStartTime |
| start time of the data histogram | |
| Double_t | fEndTime |
| end time of the data histogram | |
| Bool_t | fDCCorrected |
| if true, removed DC offset from signal before Fourier transformation, otherwise not | |
| UInt_t | fZeroPaddingPower |
| power for zero padding, if set < 0 no zero padding will be done | |
| Double_t | fResolution |
| Fourier resolution (field, frequency, or angular frequency) | |
| UInt_t | fNoOfData |
| number of bins in the time interval between fStartTime and fStopTime | |
| UInt_t | fNoOfBins |
| number of bins to be Fourier transformed. Might be different to fNoOfData due to zero padding | |
| fftw_plan | fFFTwPlan |
| fftw plan (see FFTW3 User Manual) | |
| fftw_complex * | fIn |
| real part of the Fourier transform | |
| fftw_complex * | fOut |
| imaginary part of the Fourier transform | |
Fourier transform engine for μSR time-domain data.
PFourier converts time-domain μSR signals to frequency domain, revealing:
Key features:
Workflow:
Unit conversions:
Example: TF-μSR measurement at 100 G produces a peak at ~1.36 MHz in the Fourier spectrum.
Definition at line 201 of file PFourier.h.
| PFourier::PFourier | ( | TH1F * | data, |
| Int_t | unitTag, | ||
| Double_t | startTime = 0.0, | ||
| Double_t | endTime = 0.0, | ||
| Bool_t | dcCorrected = false, | ||
| UInt_t | zeroPaddingPower = 0 ) |
Constructor for Fourier transformation.
| data | Time histogram to transform |
| unitTag | Output units (1=Gauss, 2=Tesla, 3=MHz, 4=Mc/s) |
| startTime | Start time for transform in microseconds (0=from t0) |
| endTime | End time for transform in microseconds (0=to end) |
| dcCorrected | If true, remove DC offset before FFT |
| zeroPaddingPower | Zero-pad to 2^N points (0=no padding) |
Constructor for Fourier transform engine.
Creates a PFourier object configured to transform μSR time-domain data to frequency/field domain. The constructor validates inputs, allocates FFTW resources, and prepares for FFT computation.
| data | TH1F histogram containing time-domain μSR signal. X-axis: time in microseconds, Y-axis: asymmetry or counts. |
| unitTag | Output units for frequency axis:
|
| startTime | Start of transform window in μs (0.0 = from t₀). Default: 0.0 |
| endTime | End of transform window in μs (0.0 = to end). Default: 0.0 |
| dcCorrected | If true, remove DC offset before FFT to eliminate zero-frequency artifact. Default: false |
| zeroPaddingPower | Zero-pad to 2^N points where N=zeroPaddingPower. Value 0 disables padding. Padding improves frequency interpolation but doesn't add information. Default: 0 |
Unit conversions (using γ_μ/2π = 0.01355 MHz/G):
Example usage:
After construction, check IsValid() before calling Transform().
Definition at line 482 of file PFourier.cpp.
References F_APODIZATION_NONE, fApodization, fData, fDCCorrected, fEndTime, fFFTwPlan, fIn, fNoOfBins, fNoOfData, FOURIER_UNIT_CYCLES, FOURIER_UNIT_FREQ, FOURIER_UNIT_GAUSS, FOURIER_UNIT_TESLA, fOut, fResolution, fStartTime, fTimeResolution, fUnitTag, fValid, fZeroPaddingPower, GAMMA_BAR_MUON, and PI.
|
virtual |
Destructor - cleans up FFTW resources.
Releases all FFTW-allocated memory and destroys the FFT plan. Proper cleanup is essential to avoid memory leaks, as FFTW uses special aligned memory allocation.
Resources freed:
Definition at line 584 of file PFourier.cpp.
|
privatevirtual |
Applies apodization (windowing) to time-domain data before FFT.
Purpose: Apodization multiplies the time signal by a smooth window function that tapers to zero at the edges, reducing the Gibbs phenomenon (spectral leakage) caused by finite observation windows.
Trade-off:
Window functions: Polynomial windows of the form: w(t) = Σ c_j·(t/T)^(2j) where t ∈ [0,T]
Three predefined window strengths with optimized coefficients:
| apodizationTag | Window function type:
|
Window is applied in-place to fIn[] array.
Definition at line 1226 of file PFourier.cpp.
References F_APODIZATION_MEDIUM, F_APODIZATION_NONE, F_APODIZATION_STRONG, F_APODIZATION_WEAK, fIn, and fNoOfData.
Referenced by PrepareFFTwInputData().
|
inlinevirtual |
Returns the original data histogram title
Definition at line 232 of file PFourier.h.
References fData.
|
virtual |
Gets imaginary part of Fourier transform as histogram.
| scale | Scaling factor for amplitudes (default=1.0) |
Returns imaginary part of Fourier transform as ROOT histogram.
The imaginary component represents the out-of-phase (sine) projection of the signal. Ideally zero for perfect phase correction, but contains signal information when phase is uncorrected.
Uses:
Histogram covers [0, f_Nyquist] with N/2 bins where N is the FFT size (including zero padding if applied).
| scale | Multiplication factor applied to all amplitudes. Use for normalization or unit conversion. Default: 1.0 |
Definition at line 931 of file PFourier.cpp.
References fData, fNoOfBins, fOut, fResolution, and fValid.
Referenced by PMusrCanvas::HandleDifferenceFourier(), and PMusrCanvas::HandleFourier().
|
virtual |
Returns the maximum frequency (Nyquist frequency).
Returns the maximum frequency (Nyquist frequency) of the spectrum.
The Nyquist frequency is the highest frequency that can be unambiguously represented given the time resolution: f_Nyquist = 1 / (2·Δt)
Higher frequencies are aliased back into the [0, f_Nyquist] range, so the useful spectrum extends from 0 to f_Nyquist.
Example: For time resolution Δt = 0.01 μs: f_Nyquist = 1/(2×0.01) = 50 MHz ≈ 3690 Gauss
Definition at line 685 of file PFourier.cpp.
References fNoOfBins, and fResolution.
|
virtual |
Gets phase spectrum arg(F(ω)) as histogram.
| scale | Scaling factor (default=1.0) |
Returns phase spectrum φ(ω) = arg(F) as ROOT histogram.
The phase spectrum shows the phase angle of the complex Fourier transform at each frequency: φ(ω) = atan2(Im, Re)
Range: Phase values are in [-π, +π] radians, with proper quadrant handling using the two-argument arctangent.
Interpretation:
Applications:
Histogram covers [0, f_Nyquist] with N/2 bins where N is the FFT size (including zero padding if applied).
| scale | Multiplication factor applied to phase values. Typically 1.0 (radians) or 180/π (degrees). Default: 1.0 |
Note: Phase is undefined where amplitude is zero. In practice, phase values in noise regions are meaningless.
Definition at line 1073 of file PFourier.cpp.
References fData, fNoOfBins, fOut, fResolution, fValid, PI, and PI_HALF.
Referenced by PMusrCanvas::HandleDifferenceFourier(), and PMusrCanvas::HandleFourier().
|
static |
Static method for phase-optimized real Fourier spectrum.
Applies phase correction to maximize real component using provided phase parameters.
| re | Real part of Fourier transform |
| im | Imaginary part of Fourier transform |
| phase | Phase correction parameters [c₀, c₁] |
| scale | Scaling factor (default=1.0) |
| min | Minimum frequency for correction (-1=all) |
| max | Maximum frequency for correction (-1=all) |
Returns phase-optimized real Fourier spectrum (static method).
This static method performs automatic phase correction on a complex Fourier spectrum to maximize the real component (absorption mode) while minimizing the imaginary component. The algorithm finds optimal phase parameters φ(ω) = c₀ + c₁·ω that produce the cleanest real spectrum.
Why phase correction? Raw FFT produces mixed-phase spectra with arbitrary phase offsets due to:
Algorithm:
Optimization range [min, max]: Restrict to signal-containing regions for best results. Including noisy baseline degrades optimization.
| re | Real part of Fourier transform (TH1F histogram) |
| im | Imaginary part of Fourier transform (TH1F histogram) |
| phase | Output parameter: phase[0]=c₀, phase[1]=c₁ (vector resized to 2) |
| scale | Amplitude scaling factor. Default: 1.0 |
| min | Minimum frequency/field for optimization window. Use -1.0 to include all frequencies. Default: -1.0 |
| max | Maximum frequency/field for optimization window. Use -1.0 to include all frequencies. Default: -1.0 |
Example:
Definition at line 817 of file PFourier.cpp.
References PFTPhaseCorrection::GetPhaseCorrectionParam(), PFTPhaseCorrection::IsValid(), and PFTPhaseCorrection::Minimize().
Referenced by PMusrCanvas::CalcPhaseOptReFT().
|
virtual |
Gets power spectrum |F(ω)|² as histogram.
Power spectrum is always positive and shows signal strength at each frequency, useful for identifying dominant frequencies.
| scale | Scaling factor for power (default=1.0) |
Returns power spectrum |F(ω)| as ROOT histogram.
The power spectrum shows signal magnitude at each frequency, computed as: |F(ω)| = √(Re² + Im²)
Advantages:
Applications:
Histogram covers [0, f_Nyquist] with N/2 bins where N is the FFT size (including zero padding if applied).
| scale | Multiplication factor applied to all amplitudes. Use for normalization or unit conversion. Default: 1.0 |
Note: This returns the amplitude |F|, not the power |F|². For power values, square the histogram contents.
Definition at line 1001 of file PFourier.cpp.
References fData, fNoOfBins, fOut, fResolution, and fValid.
Referenced by PMusrCanvas::HandleDifferenceFourier(), and PMusrCanvas::HandleFourier().
|
virtual |
Gets real part of Fourier transform as histogram.
| scale | Scaling factor for amplitudes (default=1.0) |
Returns real part of Fourier transform as ROOT histogram.
The real component represents the in-phase (cosine) projection of the signal. Without phase correction, both positive and negative values typically appear due to arbitrary phase offsets.
Interpretation:
Histogram covers [0, f_Nyquist] with N/2 bins where N is the FFT size (including zero padding if applied).
| scale | Multiplication factor applied to all amplitudes. Use for normalization or unit conversion. Default: 1.0 |
Example:
Definition at line 731 of file PFourier.cpp.
References fData, fNoOfBins, fOut, fResolution, and fValid.
Referenced by PMusrCanvas::HandleDifferenceFourier(), and PMusrCanvas::HandleFourier().
|
inlinevirtual |
Returns the frequency resolution (bin width in output units)
Definition at line 240 of file PFourier.h.
References fResolution.
|
inlinevirtual |
Returns the output unit tag (1=G, 2=T, 3=MHz, 4=Mc/s)
Definition at line 236 of file PFourier.h.
References fUnitTag.
|
inlinevirtual |
Returns true if Fourier transform is ready
Definition at line 303 of file PFourier.h.
References fValid.
Referenced by PMusrCanvas::HandleDifferenceFourier(), and PMusrCanvas::HandleFourier().
|
privatevirtual |
Prepares time-domain data for FFT with optional DC correction and apodization.
This method performs essential preprocessing steps:
DC Correction: Subtracts mean value from time signal to remove constant offset, which would otherwise create a large artifact at zero frequency.
Zero Padding: Increases frequency resolution by interpolation without adding information content. Often used for smoother spectra.
| apodizationTag | Window function strength:
|
Result is stored in fIn[] array ready for FFTW execution.
Definition at line 1155 of file PFourier.cpp.
References ApodizeData(), fData, fDCCorrected, fIn, fNoOfBins, fNoOfData, fStartTime, and fTimeResolution.
Referenced by Transform().
|
virtual |
Performs the Fourier transformation.
Applies optional apodization, computes FFT using FFTW3, and prepares output histograms in requested units.
| apodizationTag | Apodization strength (0/1=none, 2=weak, 3=medium, 4=strong) |
Executes the Fourier transform with optional apodization.
This is the main workhorse method that performs the complete FFT pipeline:
Phase correction: If fStartTime ≠ 0, applies phase shift e^(i·ω·t₀) to account for the time-zero offset. This ensures proper phase relationships in the frequency spectrum.
Apodization: Window functions reduce spectral leakage (Gibbs phenomenon) at the cost of slight peak broadening:
| apodizationTag | Window function strength:
|
After calling Transform(), retrieve results using: GetRealFourier(), GetImaginaryFourier(), GetPowerFourier(), GetPhaseFourier()
Definition at line 632 of file PFourier.cpp.
References fData, fFFTwPlan, fNoOfBins, fOut, fStartTime, fTimeResolution, fValid, PI, and PrepareFFTwInputData().
Referenced by PMusrCanvas::HandleDifferenceFourier(), and PMusrCanvas::HandleFourier().
|
private |
0=none, 1=weak, 2=medium, 3=strong
Definition at line 311 of file PFourier.h.
Referenced by PFourier().
|
private |
data histogram to be Fourier transformed.
Definition at line 306 of file PFourier.h.
Referenced by GetDataTitle(), GetImaginaryFourier(), GetPhaseFourier(), GetPowerFourier(), GetRealFourier(), PFourier(), PrepareFFTwInputData(), and Transform().
|
private |
if true, removed DC offset from signal before Fourier transformation, otherwise not
Definition at line 316 of file PFourier.h.
Referenced by PFourier(), and PrepareFFTwInputData().
|
private |
|
private |
fftw plan (see FFTW3 User Manual)
Definition at line 322 of file PFourier.h.
Referenced by PFourier(), Transform(), and ~PFourier().
|
private |
real part of the Fourier transform
Definition at line 323 of file PFourier.h.
Referenced by ApodizeData(), PFourier(), PrepareFFTwInputData(), and ~PFourier().
|
private |
number of bins to be Fourier transformed. Might be different to fNoOfData due to zero padding
Definition at line 321 of file PFourier.h.
Referenced by GetImaginaryFourier(), GetMaxFreq(), GetPhaseFourier(), GetPowerFourier(), GetRealFourier(), PFourier(), PrepareFFTwInputData(), and Transform().
|
private |
number of bins in the time interval between fStartTime and fStopTime
Definition at line 320 of file PFourier.h.
Referenced by ApodizeData(), PFourier(), and PrepareFFTwInputData().
|
private |
imaginary part of the Fourier transform
Definition at line 324 of file PFourier.h.
Referenced by GetImaginaryFourier(), GetPhaseFourier(), GetPowerFourier(), GetRealFourier(), PFourier(), Transform(), and ~PFourier().
|
private |
Fourier resolution (field, frequency, or angular frequency)
Definition at line 318 of file PFourier.h.
Referenced by GetImaginaryFourier(), GetMaxFreq(), GetPhaseFourier(), GetPowerFourier(), GetRealFourier(), GetResolution(), and PFourier().
|
private |
start time of the data histogram
Definition at line 314 of file PFourier.h.
Referenced by PFourier(), PrepareFFTwInputData(), and Transform().
|
private |
time resolution of the data histogram in (us)
Definition at line 313 of file PFourier.h.
Referenced by PFourier(), PrepareFFTwInputData(), and Transform().
|
private |
1=Field Units (G), 2=Field Units (T), 3=Frequency Units (MHz), 4=Angular Frequency Units (Mc/s)
Definition at line 309 of file PFourier.h.
Referenced by GetUnitTag(), and PFourier().
|
private |
true = all boundary conditions fullfilled and hence a Fourier transform can be performed.
Definition at line 308 of file PFourier.h.
Referenced by GetImaginaryFourier(), GetPhaseFourier(), GetPowerFourier(), GetRealFourier(), IsValid(), PFourier(), and Transform().
|
private |
power for zero padding, if set < 0 no zero padding will be done
Definition at line 317 of file PFourier.h.
Referenced by PFourier().