|
musrfit 1.10.0
|
Class for fitting general x-y data sets (non-μSR time series). More...
#include <PRunNonMusr.h>


Public Member Functions | |
| PRunNonMusr () | |
| Default constructor creating an empty, invalid non-μSR run object. | |
| PRunNonMusr (PMsrHandler *msrInfo, PRunDataHandler *rawData, UInt_t runNo, EPMusrHandleTag tag, Bool_t theoAsData) | |
| Main constructor initializing a non-μSR run from MSR file and data. | |
| virtual | ~PRunNonMusr () |
| Virtual destructor (no cleanup needed for this class). | |
| virtual Double_t | CalcChiSquare (const std::vector< Double_t > &par) |
| Calculates χ² between non-μSR data and theory. | |
| virtual Double_t | CalcChiSquareExpected (const std::vector< Double_t > &par) |
| Calculates expected χ² (NOT IMPLEMENTED for non-μSR). | |
| virtual Double_t | CalcMaxLikelihood (const std::vector< Double_t > &par) |
| Calculates maximum likelihood (NOT IMPLEMENTED for non-μSR). | |
| virtual void | CalcTheory () |
| Evaluates theory function (empty implementation for non-μSR). | |
| virtual UInt_t | GetNoOfFitBins () |
| Returns the number of x-y points within the fit range. | |
| virtual void | SetFitRangeBin (const TString fitRange) |
| Sets fit range in bin units (NOT SUPPORTED for non-μSR). | |
| virtual UInt_t | GetXIndex () |
| Returns the x-axis column index from MSR file specification. | |
| virtual UInt_t | GetYIndex () |
| Returns the y-axis column index from MSR file specification. | |
Public Member Functions inherited from PRunBase | |
| PRunBase () | |
| Default constructor. | |
| PRunBase (PMsrHandler *msrInfo, PRunDataHandler *rawData, UInt_t runNo, EPMusrHandleTag tag) | |
| Constructor initializing run from MSR file and raw data. | |
| virtual | ~PRunBase () |
| Virtual destructor. | |
| virtual void | SetFitRange (PDoublePairVector fitRange) |
| Sets the fit time range for this run. | |
| virtual UInt_t | GetRunNo () |
| Returns the run number (0-based index in MSR file). | |
| virtual PRunData * | GetData () |
| Returns pointer to processed data container. | |
| virtual void | CleanUp () |
| Cleans up internal data structures. | |
| virtual Bool_t | IsValid () |
| Returns validity status of this run object. | |
Protected Member Functions | |
| virtual Bool_t | PrepareData () |
| Main data preparation orchestrator for non-μSR data. | |
| virtual Bool_t | PrepareFitData () |
| Prepares x-y data for fitting. | |
| virtual Bool_t | PrepareViewData () |
| Prepares x-y data for viewing/plotting. | |
Protected Member Functions inherited from PRunBase | |
| virtual void | DeadTimeCorrection (std::vector< PDoubleVector > &histos, PUIntVector &histoNo) |
| carry out dead time correction | |
| virtual void | CalculateKaiserFilterCoeff (Double_t wc, Double_t A, Double_t dw) |
| Calculates Kaiser window FIR filter coefficients for RRF smoothing. | |
| virtual void | FilterTheo () |
| Applies Kaiser FIR filter to theory values for RRF fits. | |
Private Attributes | |
| PRawRunData * | fRawRunData |
| Pointer to raw run data handler (not owned). | |
| UInt_t | fNoOfFitBins |
| Number of x-y points within fit range (fFitStartTime ≤ x ≤ fFitEndTime) | |
| Int_t | fPacking |
| Data point averaging/grouping factor. | |
| Bool_t | fTheoAsData |
| Theory calculation mode flag. | |
| Int_t | fStartTimeBin |
| Index of first data point in fit range. | |
| Int_t | fEndTimeBin |
| Index of last data point in fit range (inclusive). | |
Additional Inherited Members | |
Protected Attributes inherited from PRunBase | |
| Bool_t | fValid |
| Flag indicating if run object initialized successfully; false if any error occurred. | |
| EPMusrHandleTag | fHandleTag |
| Operation mode: kFit (fitting), kView (display only), kEmpty (uninitialized) | |
| Int_t | fRunNo |
| Run number (0-based index in MSR file RUN blocks) | |
| PMsrHandler * | fMsrInfo |
| Pointer to MSR file handler (owned externally, not deleted here) | |
| PMsrRunBlock * | fRunInfo |
| Pointer to this run's RUN block settings within fMsrInfo. | |
| PRunDataHandler * | fRawData |
| Pointer to raw data handler (owned externally, not deleted here) | |
| PRunData | fData |
| Processed data container: background-corrected, packed, with theory values. | |
| Double_t | fTimeResolution |
| Time resolution of raw histogram data in microseconds (μs), e.g., 0.01953125 μs for PSI GPS. | |
| PMetaData | fMetaData |
| Experimental metadata extracted from data file header (magnetic field, temperature, beam energy) | |
| PDoubleVector | fT0s |
| Time-zero bin values for all histograms in this run (forward, backward, etc.) | |
| std::vector< PDoubleVector > | fAddT0s |
| Time-zero bin values for additional runs to be added to main run. | |
| Double_t | fFitStartTime |
| Fit range start time in microseconds (μs) relative to t0. | |
| Double_t | fFitEndTime |
| Fit range end time in microseconds (μs) relative to t0. | |
| PDoubleVector | fFuncValues |
| Cached values of user-defined functions from FUNCTIONS block, evaluated at current parameters. | |
| std::unique_ptr< PTheory > | fTheory |
| Theory function evaluator (smart pointer, automatically deleted) | |
| PDoubleVector | fKaiserFilter |
| Kaiser window FIR filter coefficients for smoothing RRF theory curves. | |
Class for fitting general x-y data sets (non-μSR time series).
PRunNonMusr extends the musrfit framework to handle arbitrary x-y data that doesn't originate from μSR experiments. This allows users to leverage musrfit's powerful fitting engine, theory functions, and MINUIT interface for general curve fitting tasks.
This fit type is designed for:
Unlike μSR fits, non-μSR data is provided as simple x-y pairs:
Non-μSR data can be loaded from:
ASCII format example:
Example MSR file RUN block for non-μSR data:
All standard musrfit theory functions can be used:
Theory is evaluated at the x-values from the data file.
| Feature | μSR Fits | Non-μSR Fits |
|---|---|---|
| Data type | Raw histograms | Processed x-y pairs |
| Time zero (t0) | Required | Not applicable |
| Background | Estimated/subtracted | Included in y-data |
| Asymmetry | Calculated | Not applicable |
| Packing | Rebin histograms | Average x-y points |
| Fit range | Time (μs) | x-axis units (arbitrary) |
| ADDRUN | Supported | NOT supported |
Definition at line 132 of file PRunNonMusr.h.
| PRunNonMusr::PRunNonMusr | ( | ) |
Default constructor creating an empty, invalid non-μSR run object.
Initializes all member variables to default values:
This constructor is needed for creating vectors of PRunNonMusr objects. The resulting object cannot be used until properly initialized via the main constructor.
Initializes all member variables to default/safe values:
This constructor is needed for creating vectors of PRunNonMusr objects. The resulting object cannot be used until properly initialized via the main constructor.
Definition at line 54 of file PRunNonMusr.cpp.
References fEndTimeBin, PRunBase::fHandleTag, fNoOfFitBins, fPacking, fRawRunData, fStartTimeBin, kEmpty, and PRunBase::PRunBase().
| PRunNonMusr::PRunNonMusr | ( | PMsrHandler * | msrInfo, |
| PRunDataHandler * | rawData, | ||
| UInt_t | runNo, | ||
| EPMusrHandleTag | tag, | ||
| Bool_t | theoAsData ) |
Main constructor initializing a non-μSR run from MSR file and data.
Main constructor initializing a non-μSR run from MSR file and x-y data.
Performs initialization for general x-y data fitting:
The object is marked as invalid (fValid=false) if:
| msrInfo | Pointer to MSR file handler (must remain valid) |
| rawData | Pointer to raw data handler for loading data files |
| runNo | Run number (0-based index in MSR file RUN blocks) |
| tag | Operation mode: kFit (fitting), kView (display/plotting) |
| theoAsData | Theory mode: true = at data points, false = high-resolution |
Performs comprehensive initialization for general curve fitting:
The object is marked as invalid (fValid=false) if:
Key features for non-μSR:
| msrInfo | Pointer to MSR file handler (must remain valid for object lifetime) |
| rawData | Pointer to raw data handler for loading data files |
| runNo | Run number (0-based index in MSR file RUN blocks) |
| tag | Operation mode: kFit (fitting), kView (display/plotting) |
| theoAsData | Theory mode: true = at data x-values, false = high-resolution (minimal effect for non-μSR) |
Definition at line 113 of file PRunNonMusr.cpp.
References PRunBase::fRawData, fRawRunData, PRunBase::fRunInfo, fTheoAsData, PRunBase::fValid, if(), PrepareData(), and PRunBase::PRunBase().
|
virtual |
Virtual destructor (no cleanup needed for this class).
Destructor (no cleanup needed for non-μSR).
Raw data pointer (fRawRunData) is not owned by this class and is not deleted. Base class destructor handles cleanup of theory objects and other shared resources.
The fRawRunData pointer is not owned by this class and is not deleted here. It is managed by the PRunDataHandler and will be cleaned up externally.
Base class destructor (PRunBase) handles cleanup of:
Definition at line 143 of file PRunNonMusr.cpp.
|
virtual |
Calculates χ² between non-μSR data and theory.
Calculates χ² between non-μSR x-y data and theory.
Computes the chi-squared statistic for x-y data:
![\[ \chi^2 = \sum_{i={\rm start}}^{\rm end} \frac{(y_i^{\rm data} - y_i^{\rm theory})^2}{\sigma_i^2} \]](form_32.png)
where:
Algorithm:
Unlike μSR fits, this operates on x-y data directly (not histograms). The x-axis can represent any independent variable (time, temperature, field, etc.), not just time in microseconds.
| par | Parameter vector from MINUIT with current parameter values |
Computes the chi-squared statistic for general x-y data:
![\[ \chi^2 = \sum_{i={\rm start}}^{\rm end} \frac{(y_i - f(x_i))^2}{\sigma_i^2} \]](form_83.png)
where:
Algorithm:
Key differences from μSR fits:
| par | Parameter vector from MINUIT with current parameter values |
Implements PRunBase.
Definition at line 189 of file PRunNonMusr.cpp.
References PRunBase::fData, fEndTimeBin, PRunBase::fFuncValues, PRunBase::fMetaData, PRunBase::fMsrInfo, PRunBase::fRunInfo, fStartTimeBin, and PRunBase::fTheory.
|
virtual |
Calculates expected χ² (NOT IMPLEMENTED for non-μSR).
This method is not implemented for general x-y data because the concept of "expected χ²" depends on the underlying statistical distribution, which is not well-defined for arbitrary non-μSR data (unlike Poisson-distributed histogram counts in μSR).
Calling this method prints a warning message and returns 0.0.
| par | Parameter vector from MINUIT |
This method is not implemented because the concept of "expected χ²" requires knowledge of the underlying statistical distribution of the data, which is not well-defined for general x-y data.
For μSR histogram data, the expected χ² can be calculated based on Poisson statistics. For arbitrary non-μSR data, the appropriate statistical model depends on the data source:
Without knowing the data's statistical nature, a meaningful implementation cannot be provided.
| par | Parameter vector from MINUIT (unused) |
Implements PRunBase.
Definition at line 235 of file PRunNonMusr.cpp.
|
virtual |
Calculates maximum likelihood (NOT IMPLEMENTED for non-μSR).
Maximum likelihood fitting is not implemented for general x-y data because:
Calling this method prints a warning message and returns 1.0.
| par | Parameter vector from MINUIT |
Maximum likelihood fitting is not implemented for general x-y data because:
For general x-y data with Gaussian errors, use χ² fitting via CalcChiSquare(). For non-Gaussian statistics, users should implement custom fitting outside musrfit.
| par | Parameter vector from MINUIT (unused) |
Implements PRunBase.
Definition at line 273 of file PRunNonMusr.cpp.
|
virtual |
Evaluates theory function (empty implementation for non-μSR).
For non-μSR data, theory calculation is performed directly in CalcChiSquare() rather than pre-calculating and storing theory values. This is because:
This method exists to satisfy the PRunBase interface but does nothing.
For non-μSR data, theory calculation is performed on-demand within CalcChiSquare() rather than pre-calculating and storing theory values.
This design choice is made because:
This empty method exists solely to satisfy the PRunBase interface requirement.
Implements PRunBase.
Definition at line 299 of file PRunNonMusr.cpp.
|
virtual |
Returns the number of x-y points within the fit range.
Calculates and returns the number of x-y points within the fit range.
Counts data points where fFitStartTime ≤ x ≤ fFitEndTime. This count is used for:
The method loops through all x-values in fData.GetX() and counts those within the specified fit range.
Counts data points where fFitStartTime ≤ x ≤ fFitEndTime (both inclusive). This count is essential for:
Algorithm:
The fit range (fFitStartTime, fFitEndTime) is specified in the MSR file RUN or GLOBAL block "fit" entry, in the same units as the x-axis data.
Definition at line 330 of file PRunNonMusr.cpp.
References PRunBase::fData, PRunBase::fFitEndTime, PRunBase::fFitStartTime, and fNoOfFitBins.
|
virtual |
Returns the x-axis column index from MSR file specification.
Extracts the x-data column index from:
The index specifies which column in the data file contains the independent variable (x-axis values).
Returns the x-axis data index.
return:
Definition at line 640 of file PRunNonMusr.cpp.
References fRawRunData, and PRunBase::fRunInfo.
Referenced by PrepareFitData(), and PrepareViewData().
|
virtual |
Returns the y-axis column index from MSR file specification.
Extracts the y-data column index from:
The index specifies which column in the data file contains the dependent variable (y-axis values to be fitted).
Returns the y-axis data index.
return:
Definition at line 681 of file PRunNonMusr.cpp.
References fRawRunData, and PRunBase::fRunInfo.
Referenced by PrepareFitData(), and PrepareViewData().
|
protectedvirtual |
Main data preparation orchestrator for non-μSR data.
Coordinates the data loading and preprocessing pipeline:
Key validation:
Prepare data for fitting or viewing.
return:
Implements PRunBase.
Definition at line 353 of file PRunNonMusr.cpp.
References PRunBase::fFitEndTime, PRunBase::fFitStartTime, PRunBase::fHandleTag, PRunBase::fMsrInfo, fPacking, PRunBase::fRunInfo, PRunBase::fValid, kFit, kView, PMUSR_UNDEFINED, PrepareFitData(), and PrepareViewData().
Referenced by PRunNonMusr().
|
protectedvirtual |
Prepares x-y data for fitting.
Performs data processing for curve fitting:
Packing example (packing=3):
Prepare data for fitting.
return:
Definition at line 402 of file PRunNonMusr.cpp.
References PRunBase::fData, fEndTimeBin, PRunBase::fFitEndTime, PRunBase::fFitStartTime, fNoOfFitBins, fPacking, fRawRunData, fStartTimeBin, GetXIndex(), and GetYIndex().
Referenced by PrepareData().
|
protectedvirtual |
Prepares x-y data for viewing/plotting.
Similar to PrepareFitData() but optimized for visualization:
The exact implementation mirrors PrepareFitData() for non-μSR, but the separation allows future customization for viewing.
Prepare data for viewing.
return:
Definition at line 465 of file PRunNonMusr.cpp.
References PRunBase::fData, PRunBase::fFuncValues, PRunBase::fMetaData, PRunBase::fMsrInfo, fNoOfFitBins, fPacking, fRawRunData, PRunBase::fRunInfo, fTheoAsData, PRunBase::fTheory, PMsrPlotStructure::fTmax, PMsrPlotStructure::fTmin, PMsrPlotStructure::fUseFitRanges, GetXIndex(), and GetYIndex().
Referenced by PrepareData().
|
inlinevirtual |
Sets fit range in bin units (NOT SUPPORTED for non-μSR).
This method is not meaningful for non-μSR data because:
This empty implementation exists to satisfy the PRunBase interface. Use SetFitRange(PDoublePairVector) in the base class instead.
| fitRange | Fit range string (ignored) |
Definition at line 310 of file PRunNonMusr.h.
|
private |
Index of last data point in fit range (inclusive).
Points to the last x-y pair where x ≤ fFitEndTime. Used as loop end in CalcChiSquare() (inclusive: i <= fEndTimeBin).
Definition at line 476 of file PRunNonMusr.h.
Referenced by CalcChiSquare(), PrepareFitData(), and PRunNonMusr().
|
private |
Number of x-y points within fit range (fFitStartTime ≤ x ≤ fFitEndTime)
Definition at line 425 of file PRunNonMusr.h.
Referenced by GetNoOfFitBins(), PrepareFitData(), PrepareViewData(), and PRunNonMusr().
|
private |
Data point averaging/grouping factor.
Number of consecutive raw data points to average together:
Packing reduces the number of data points, improving:
But decreases:
Source priority:
Definition at line 446 of file PRunNonMusr.h.
Referenced by PrepareData(), PrepareFitData(), PrepareViewData(), and PRunNonMusr().
|
private |
Pointer to raw run data handler (not owned).
Provides access to loaded x-y data from file. Retrieved via fRawData->GetRunData(*runName) during construction.
Contains the fDataNonMusr structure with:
Definition at line 423 of file PRunNonMusr.h.
Referenced by GetXIndex(), GetYIndex(), PrepareFitData(), PrepareViewData(), PRunNonMusr(), and PRunNonMusr().
|
private |
Index of first data point in fit range.
Points to the first x-y pair where x ≥ fFitStartTime. Used as loop start in CalcChiSquare().
Definition at line 466 of file PRunNonMusr.h.
Referenced by CalcChiSquare(), PrepareFitData(), and PRunNonMusr().
|
private |
Theory calculation mode flag.
Controls theory grid resolution (currently not used for non-μSR):
For non-μSR, theory is always evaluated at data x-values during CalcChiSquare(), so this flag has minimal effect.
Definition at line 458 of file PRunNonMusr.h.
Referenced by PrepareViewData(), and PRunNonMusr().