musrfit 1.10.0
PUserFcn Class Reference

Example user function implementing a third-order polynomial. More...

#include <PUserFcn.h>

Inheritance diagram for PUserFcn:
Collaboration diagram for PUserFcn:

Public Member Functions

 PUserFcn ()
 Default constructor.
 
 ~PUserFcn ()
 Destructor.
 
Double_t operator() (Double_t t, const std::vector< Double_t > &param) const
 Evaluates the third-order polynomial at time t.
 
- Public Member Functions inherited from PUserFcnBase
 PUserFcnBase ()
 Default constructor.
 
virtual ~PUserFcnBase ()
 Virtual destructor.
 
virtual Bool_t NeedGlobalPart () const
 
virtual void SetGlobalPart (std::vector< void * > &globalPart, UInt_t idx)
 
virtual Bool_t GlobalPartIsValid () const
 

Detailed Description

Example user function implementing a third-order polynomial.

PUserFcn demonstrates how to create custom theory functions by deriving from PUserFcnBase. This example implements a cubic polynomial:

\[ P(t) = a_0 + a_1 t + a_2 t^2 + a_3 t^3 \]

where $a_0, a_1, a_2, a_3$ are the polynomial coefficients passed as fit parameters.

Usage in MSR File

To use this function in your analysis:

FITPARAMETER
# No Name Value Step Pos_Error Boundaries
1 a0 1.0 0.1 none
2 a1 0.01 0.001 none
3 a2 0.001 0.0001 none
4 a3 0.0001 0.00001 none
THEORY
userFcn libPUserFcn.so PUserFcn 1 2 3 4 (a0, a1, a2, a3)
PUserFcn()
Default constructor.

Applications

Polynomial backgrounds are useful for:

  • Modeling baseline drifts in long-time measurements
  • Phenomenological fits to slowly varying relaxation
  • Testing the user function infrastructure

As a Template

This class serves as a minimal working example for creating custom user functions. To create your own:

  1. Copy PUserFcn.h and PUserFcn.cpp
  2. Rename the class and update the ClassDef/ClassImp macros
  3. Implement your physics in the operator() method
  4. Create a LinkDef.h and build as a shared library
See also
PUserFcnBase for the abstract interface and detailed implementation guide
PTheory for how user functions are loaded and evaluated

Definition at line 85 of file PUserFcn.h.

Constructor & Destructor Documentation

◆ PUserFcn()

PUserFcn::PUserFcn ( )

Default constructor.

References PUserFcn().

Referenced by PUserFcn().

◆ ~PUserFcn()

PUserFcn::~PUserFcn ( )

Destructor.

Destructor for PUserFcn.

Cleans up any resources allocated by the polynomial function. Since this implementation has no dynamically allocated resources, the destructor is empty.

Note
User functions with allocated resources (lookup tables, buffers, external library handles) must clean them up here to prevent memory leaks. If using the global part interface, ensure proper coordination with gGlobalUserFcn cleanup.

Definition at line 65 of file PUserFcn.cpp.

Member Function Documentation

◆ operator()()

Double_t PUserFcn::operator() ( Double_t t,
const std::vector< Double_t > & param ) const
virtual

Evaluates the third-order polynomial at time t.

Evaluates the third-order polynomial at the given time.

Computes:

\[ P(t) = \texttt{param[0]} + \texttt{param[1]} \cdot t
         + \texttt{param[2]} \cdot t^2 + \texttt{param[3]} \cdot t^3 \]

Parameters
tTime value (typically in microseconds)
paramVector of polynomial coefficients:
  • param[0]: constant term $a_0$
  • param[1]: linear coefficient $a_1$ (per μs)
  • param[2]: quadratic coefficient $a_2$ (per μs²)
  • param[3]: cubic coefficient $a_3$ (per μs³)
Returns
The polynomial value at time t

Computes a cubic polynomial of the form:

\[ P(t) = c_0 + c_1 t + c_2 t^2 + c_3 t^3 = \sum_{k=0}^{3} c_k t^k \]

where the coefficients $c_k$ are provided in the parameter vector.

Example MSR Configuration

FITPARAMETER
# No Name Value Step Pos_Error Boundaries
1 c0 0.95 0.01 none
2 c1 -0.001 0.0001 none
3 c2 0.00001 0.000001 none
4 c3 0.0 0.0000001 none 0 none (fixed to zero for quadratic)
THEORY
userFcn libPUserFcn.so PUserFcn 1 2 3 4

Implementation Notes

  • Uses direct polynomial evaluation (Horner's method could improve numerical stability for high-precision applications)
  • Asserts exactly 4 parameters to catch MSR file configuration errors
  • No special handling for negative time values
Parameters
tIndependent variable (time in μs for μSR, or general x-axis value for non-μSR fits)
paramVector containing exactly 4 polynomial coefficients:
  • param[0]: $c_0$ - constant term (dimensionless)
  • param[1]: $c_1$ - linear coefficient (μs⁻¹)
  • param[2]: $c_2$ - quadratic coefficient (μs⁻²)
  • param[3]: $c_3$ - cubic coefficient (μs⁻³)
Returns
The polynomial value $P(t)$ at the specified time
Precondition
param.size() == 4 (enforced by assertion)
See also
PUserFcnBase::operator() for the virtual interface specification

Implements PUserFcnBase.

Definition at line 114 of file PUserFcn.cpp.


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