musrfit 1.10.0
PFTPhaseCorrection Class Reference

#include <PFourier.h>

Inheritance diagram for PFTPhaseCorrection:
Collaboration diagram for PFTPhaseCorrection:

Public Member Functions

 PFTPhaseCorrection (const Int_t minBin=-1, const Int_t maxBin=-1)
 
 PFTPhaseCorrection (std::vector< Double_t > &reFT, std::vector< Double_t > &imFT, const Int_t minBin=-1, const Int_t maxBin=-1)
 
virtual ~PFTPhaseCorrection ()
 
virtual Bool_t IsValid ()
 
virtual void Minimize ()
 
virtual void SetGamma (const Double_t gamma)
 
virtual void SetPh (const Double_t c0, const Double_t c1)
 
virtual Double_t GetGamma ()
 
virtual Double_t GetPhaseCorrectionParam (UInt_t idx)
 
virtual Double_t GetMinimum ()
 

Private Member Functions

virtual void Init ()
 keeps the minimum of the entropy/penalty minimization
 
virtual void CalcPhasedFT () const
 
virtual void CalcRealPhFTDerivative () const
 
virtual Double_t Penalty () const
 
virtual Double_t Entropy () const
 
virtual Double_t Up () const
 
virtual Double_t operator() (const std::vector< Double_t > &) const
 

Private Attributes

Bool_t fValid
 
std::vector< Double_t > fReal
 
std::vector< Double_t > fImag
 original real Fourier data set
 
std::vector< Double_t > fRealPh
 original imag Fourier data set
 
std::vector< Double_t > fImagPh
 phased real Fourier data set
 
std::vector< Double_t > fRealPhD
 phased imag Fourier data set
 
Int_t fMinBin
 1st derivative of fRealPh
 
Int_t fMaxBin
 minimum bin from Fourier range to be used for the phase correction estimate
 
Double_t fPh_c0
 maximum bin from Fourier range to be used for the phase correction estimate
 
Double_t fPh_c1
 constant part of the phase dispersion used for the phase correction
 
Double_t fGamma
 linear part of the phase dispersion used for the phase correction
 
Double_t fMin
 gamma parameter to balance between entropy and penalty
 

Detailed Description

Phase correction optimizer for Fourier transforms.

This class performs automatic phase correction on complex Fourier spectra to maximize the real component and minimize the imaginary component. Phase errors arise from:

  • Uncertain time-zero determination
  • Detector time offsets
  • Signal dispersion

Algorithm: Minimizes a combined entropy-penalty functional using Minuit2, finding optimal phase parameters (constant + linear dispersion): φ(ω) = c₀ + c₁·ω

Applications:

  • Improving signal clarity in real Fourier spectra
  • Identifying field distributions in vortex lattices
  • Resolving closely-spaced frequency components

Usage: Specify frequency range for optimization to focus on signal peaks while avoiding noise regions.

Definition at line 84 of file PFourier.h.

Constructor & Destructor Documentation

◆ PFTPhaseCorrection() [1/2]

PFTPhaseCorrection::PFTPhaseCorrection ( const Int_t minBin = -1,
const Int_t maxBin = -1 )

Constructor for phase correction with default Fourier data.

Parameters
minBinMinimum frequency bin for optimization (-1 = use all)
maxBinMaximum frequency bin for optimization (-1 = use all)

Default constructor for phase correction optimizer.

Initializes a phase correction object with default Fourier data. The actual Fourier data must be set externally before minimization.

Parameters
minBinMinimum frequency bin index for optimization region. Use -1 to optimize over all bins. Default: -1.
maxBinMaximum frequency bin index for optimization region. Use -1 to optimize over all bins. Default: -1.

Note: Restricting the optimization range to signal-containing regions improves results by excluding noisy baseline regions.

Definition at line 67 of file PFourier.cpp.

References fMaxBin, fMinBin, and Init().

◆ PFTPhaseCorrection() [2/2]

PFTPhaseCorrection::PFTPhaseCorrection ( std::vector< Double_t > & reFT,
std::vector< Double_t > & imFT,
const Int_t minBin = -1,
const Int_t maxBin = -1 )

Constructor with explicit Fourier data.

Parameters
reFTReal part of Fourier transform
imFTImaginary part of Fourier transform
minBinMinimum frequency bin for optimization
maxBinMaximum frequency bin for optimization

Constructor with explicit Fourier transform data.

Creates a phase correction optimizer with pre-computed Fourier data. The optimizer will find phase parameters φ(ω) = c₀ + c₁·ω that maximize the real component while minimizing the imaginary component.

Parameters
reFTReal part of the Fourier transform (vector of amplitudes).
imFTImaginary part of the Fourier transform (vector of amplitudes).
minBinMinimum frequency bin index for optimization region. Use -1 to optimize over all bins. Default: -1.
maxBinMaximum frequency bin index for optimization region. Use -1 to optimize over all bins. Default: -1.

Usage example:

std::vector<Double_t> real, imag;
// ... fill real and imag with FFT results ...
PFTPhaseCorrection phCorr(real, imag, 10, 500);
phCorr.Minimize();
Double_t c0 = phCorr.GetPhaseCorrectionParam(0);
Double_t c1 = phCorr.GetPhaseCorrectionParam(1);
PFTPhaseCorrection(const Int_t minBin=-1, const Int_t maxBin=-1)
Definition PFourier.cpp:67

Definition at line 100 of file PFourier.cpp.

References fImag, fImagPh, fMaxBin, fMinBin, fReal, fRealPh, and Init().

◆ ~PFTPhaseCorrection()

virtual PFTPhaseCorrection::~PFTPhaseCorrection ( )
inlinevirtual

Definition at line 105 of file PFourier.h.

Member Function Documentation

◆ CalcPhasedFT()

void PFTPhaseCorrection::CalcPhasedFT ( ) const
privatevirtual

Calculates phase-corrected Fourier transform.

Applies the phase correction φ(ω) = c₀ + c₁·(i/N) to the complex Fourier spectrum using rotation in the complex plane:

  • F'_re(ω) = F_re(ω)·cos(φ) - F_im(ω)·sin(φ)
  • F'_im(ω) = F_re(ω)·sin(φ) + F_im(ω)·cos(φ)

The corrected spectra are stored in fRealPh and fImagPh.

Physics: This rotation compensates for:

  • Time-zero offset (constant phase c₀)
  • Timing dispersion (linear phase c₁)
See also
CalcRealPhFTDerivative()

Definition at line 276 of file PFourier.cpp.

References fImag, fImagPh, fPh_c0, fPh_c1, fReal, and fRealPh.

Referenced by operator()(), and SetPh().

◆ CalcRealPhFTDerivative()

void PFTPhaseCorrection::CalcRealPhFTDerivative ( ) const
privatevirtual

Calculates first derivative of phase-corrected real Fourier spectrum.

Computes the finite difference derivative: dF/dω ≈ F(i+1) - F(i) for all interior points. Boundary points are set to 1.0.

The derivative is used in the entropy calculation, where smooth spectra (small derivatives) have lower entropy and are preferred by the optimization algorithm.

Purpose: Entropy minimization favors phase corrections that produce smooth, well-resolved real spectra with minimal oscillations.

See also
Entropy()

Definition at line 307 of file PFourier.cpp.

References fRealPh, and fRealPhD.

Referenced by operator()(), and SetPh().

◆ Entropy()

Double_t PFTPhaseCorrection::Entropy ( ) const
privatevirtual

Calculates Shannon entropy of the real spectrum derivative.

Computes: S = -Σ[p_i·ln(p_i)] where p_i = |dF/dω|_i / Σ|dF/dω|

This entropy measure quantifies the "smoothness" of the real Fourier spectrum:

  • Low entropy: Concentrated, smooth spectrum (desired)
  • High entropy: Dispersed, noisy spectrum (undesired)

Physical interpretation: Correct phase alignment produces sharp, well-defined peaks with smooth baselines, resulting in concentrated derivatives and low entropy.

Returns
Shannon entropy of normalized derivative distribution

Note: Small values (< 10⁻¹⁵) are skipped to avoid numerical issues with log(0).

See also
CalcRealPhFTDerivative()
Penalty()

Definition at line 376 of file PFourier.cpp.

References fMaxBin, fMinBin, and fRealPhD.

Referenced by operator()().

◆ GetGamma()

virtual Double_t PFTPhaseCorrection::GetGamma ( )
inlinevirtual

Returns the gamma parameter

Returns
Balancing factor between entropy and penalty

Definition at line 130 of file PFourier.h.

References fGamma.

◆ GetMinimum()

Double_t PFTPhaseCorrection::GetMinimum ( )
virtual

Returns the minimum value of the optimization functional

Returns
Minimum value achieved

Returns the minimum value of the optimization functional.

This value represents the combined entropy-penalty functional at the optimal phase parameters. Lower values indicate better phase correction. A value of -1.0 indicates failed minimization.

Returns
Minimum functional value, or -1.0 if minimization failed.

Note: Always check IsValid() before using this value.

Definition at line 223 of file PFourier.cpp.

References fMin, and fValid.

◆ GetPhaseCorrectionParam()

Double_t PFTPhaseCorrection::GetPhaseCorrectionParam ( UInt_t idx)
virtual

Gets phase correction parameter.

Parameters
idxParameter index (0=c₀, 1=c₁)
Returns
Phase parameter value

Retrieves optimized phase correction parameter by index.

Returns the phase parameter determined by Minimize(). The phase correction formula is: φ(ω) = c₀ + c₁·(ω/ω_max)

Parameters
idxParameter index:
  • 0: Returns c₀ (constant phase offset in radians)
  • 1: Returns c₁ (linear phase dispersion coefficient)
Returns
Phase correction parameter value, or 0.0 if idx is invalid.

Example:

phCorr.Minimize();
if (phCorr.IsValid()) {
Double_t c0 = phCorr.GetPhaseCorrectionParam(0);
Double_t c1 = phCorr.GetPhaseCorrectionParam(1);
std::cout << "Phase: " << c0 << " + " << c1 << "*w" << std::endl;
}

Definition at line 195 of file PFourier.cpp.

References fPh_c0, and fPh_c1.

Referenced by PFourier::GetPhaseOptRealFourier().

◆ Init()

void PFTPhaseCorrection::Init ( )
privatevirtual

keeps the minimum of the entropy/penalty minimization

Initializes phase correction object with default values.

Sets initial state:

  • fValid = true (object ready for use)
  • fPh_c0 = 0.0 (no constant phase offset)
  • fPh_c1 = 0.0 (no linear phase dispersion)
  • fGamma = 1.0 (equal weighting of entropy and penalty)
  • fMin = -1.0 (no minimization performed yet)

Called by constructors to establish consistent initial state.

Definition at line 248 of file PFourier.cpp.

References fGamma, fMin, fPh_c0, fPh_c1, and fValid.

Referenced by PFTPhaseCorrection(), and PFTPhaseCorrection().

◆ IsValid()

virtual Bool_t PFTPhaseCorrection::IsValid ( )
inlinevirtual

Returns true if phase correction initialized successfully

Returns
Validity status

Definition at line 109 of file PFourier.h.

References fValid.

Referenced by PFourier::GetPhaseOptRealFourier().

◆ Minimize()

void PFTPhaseCorrection::Minimize ( )
virtual

Performs phase correction minimization.

Uses Minuit2 to find optimal phase parameters that maximize the real spectrum while minimizing imaginary components.

Performs phase correction minimization using Minuit2.

This method finds optimal phase parameters (c₀, c₁) by minimizing a combined entropy-penalty functional:

  • Entropy term: Promotes smooth, concentrated real spectra
  • Penalty term: Penalizes negative values in real spectrum

The phase correction is: φ(ω) = c₀ + c₁·ω where:

  • c₀ corrects constant phase offset (time-zero uncertainty)
  • c₁ corrects linear phase dispersion (detector timing effects)

Algorithm:

  1. Initialize Minuit2 parameters with starting values (c₀=0, c₁=0)
  2. Minimize entropy + γ×penalty using MnMinimize
  3. Store optimal parameters in fPh_c0, fPh_c1

After calling this method, use GetPhaseCorrectionParam() to retrieve the optimal phase parameters and IsValid() to check success.

See also
GetPhaseCorrectionParam()
SetGamma()
IsValid()

Definition at line 144 of file PFourier.cpp.

References fMin, fPh_c0, fPh_c1, and fValid.

Referenced by PFourier::GetPhaseOptRealFourier().

◆ operator()()

double PFTPhaseCorrection::operator() ( const std::vector< Double_t > & ) const
privatevirtual

Objective function for Minuit2 minimization (FCNBase interface).

Evaluates the combined entropy-penalty functional: f(c₀, c₁) = S + γ·P where:

  • S = entropy of phase-corrected real spectrum derivative
  • P = penalty for negative values in real spectrum
  • γ = balancing parameter (fGamma)
Parameters
parParameter vector: [0]=c₀ (constant phase), [1]=c₁ (linear phase)
Returns
Combined functional value to be minimized

Algorithm flow:

  1. Apply phase correction with parameters par
  2. Calculate phase-corrected Fourier transform
  3. Compute spectrum derivative
  4. Return entropy + penalty

Called repeatedly by Minuit2 during optimization.

See also
Entropy()
Penalty()
Minimize()

Definition at line 425 of file PFourier.cpp.

References CalcPhasedFT(), CalcRealPhFTDerivative(), Entropy(), fPh_c0, fPh_c1, and Penalty().

◆ Penalty()

Double_t PFTPhaseCorrection::Penalty ( ) const
privatevirtual

Calculates penalty term for negative real spectrum values.

Computes: P = γ·Σ[F_re(ω)² for all F_re(ω) < 0]

The penalty term penalizes negative values in the real Fourier spectrum, since physically meaningful absorption-mode spectra should be predominantly positive. The γ parameter controls the relative importance of this constraint.

Returns
Weighted penalty value (γ×sum of squared negative amplitudes)

Note: Only bins in range [fMinBin, fMaxBin) are considered, allowing focus on signal-containing regions.

See also
SetGamma()
Entropy()

Definition at line 339 of file PFourier.cpp.

References fGamma, fMaxBin, fMinBin, and fRealPh.

Referenced by operator()().

◆ SetGamma()

virtual void PFTPhaseCorrection::SetGamma ( const Double_t gamma)
inlinevirtual

Sets the gamma balancing parameter between entropy and penalty

Parameters
gammaBalancing factor (typical range: 0.1 to 10)

Definition at line 121 of file PFourier.h.

References fGamma.

◆ SetPh()

virtual void PFTPhaseCorrection::SetPh ( const Double_t c0,
const Double_t c1 )
inlinevirtual

Sets phase correction parameters manually

Parameters
c0Constant phase offset in degrees
c1Linear phase dispersion coefficient

Definition at line 126 of file PFourier.h.

References CalcPhasedFT(), CalcRealPhFTDerivative(), fPh_c0, and fPh_c1.

◆ Up()

virtual Double_t PFTPhaseCorrection::Up ( ) const
inlineprivatevirtual

Definition at line 166 of file PFourier.h.

Member Data Documentation

◆ fGamma

Double_t PFTPhaseCorrection::fGamma
private

linear part of the phase dispersion used for the phase correction

Definition at line 157 of file PFourier.h.

Referenced by GetGamma(), Init(), Penalty(), and SetGamma().

◆ fImag

std::vector<Double_t> PFTPhaseCorrection::fImag
private

original real Fourier data set

Definition at line 148 of file PFourier.h.

Referenced by CalcPhasedFT(), and PFTPhaseCorrection().

◆ fImagPh

std::vector<Double_t> PFTPhaseCorrection::fImagPh
mutableprivate

phased real Fourier data set

Definition at line 150 of file PFourier.h.

Referenced by CalcPhasedFT(), and PFTPhaseCorrection().

◆ fMaxBin

Int_t PFTPhaseCorrection::fMaxBin
private

minimum bin from Fourier range to be used for the phase correction estimate

Definition at line 154 of file PFourier.h.

Referenced by Entropy(), Penalty(), PFTPhaseCorrection(), and PFTPhaseCorrection().

◆ fMin

Double_t PFTPhaseCorrection::fMin
private

gamma parameter to balance between entropy and penalty

Definition at line 158 of file PFourier.h.

Referenced by GetMinimum(), Init(), and Minimize().

◆ fMinBin

Int_t PFTPhaseCorrection::fMinBin
private

1st derivative of fRealPh

Definition at line 153 of file PFourier.h.

Referenced by Entropy(), Penalty(), PFTPhaseCorrection(), and PFTPhaseCorrection().

◆ fPh_c0

Double_t PFTPhaseCorrection::fPh_c0
mutableprivate

maximum bin from Fourier range to be used for the phase correction estimate

Definition at line 155 of file PFourier.h.

Referenced by CalcPhasedFT(), GetPhaseCorrectionParam(), Init(), Minimize(), operator()(), and SetPh().

◆ fPh_c1

Double_t PFTPhaseCorrection::fPh_c1
mutableprivate

constant part of the phase dispersion used for the phase correction

Definition at line 156 of file PFourier.h.

Referenced by CalcPhasedFT(), GetPhaseCorrectionParam(), Init(), Minimize(), operator()(), and SetPh().

◆ fReal

std::vector<Double_t> PFTPhaseCorrection::fReal
private

Definition at line 147 of file PFourier.h.

Referenced by CalcPhasedFT(), and PFTPhaseCorrection().

◆ fRealPh

std::vector<Double_t> PFTPhaseCorrection::fRealPh
mutableprivate

original imag Fourier data set

Definition at line 149 of file PFourier.h.

Referenced by CalcPhasedFT(), CalcRealPhFTDerivative(), Penalty(), and PFTPhaseCorrection().

◆ fRealPhD

std::vector<Double_t> PFTPhaseCorrection::fRealPhD
mutableprivate

phased imag Fourier data set

Definition at line 151 of file PFourier.h.

Referenced by CalcRealPhFTDerivative(), and Entropy().

◆ fValid

Bool_t PFTPhaseCorrection::fValid
private

Definition at line 145 of file PFourier.h.

Referenced by GetMinimum(), Init(), IsValid(), and Minimize().


The documentation for this class was generated from the following files: