musrfit 1.10.0
PRunAsymmetry Class Reference

Class for handling standard μSR asymmetry fits. More...

#include <PRunAsymmetry.h>

Inheritance diagram for PRunAsymmetry:
Collaboration diagram for PRunAsymmetry:

Public Member Functions

 PRunAsymmetry ()
 Default constructor.
 
 PRunAsymmetry (PMsrHandler *msrInfo, PRunDataHandler *rawData, UInt_t runNo, EPMusrHandleTag tag, Bool_t theoAsData)
 Main constructor for μSR asymmetry fitting.
 
virtual ~PRunAsymmetry ()
 Destructor.
 
virtual Double_t CalcChiSquare (const std::vector< Double_t > &par)
 Calculates chi-square for the current parameter set.
 
virtual Double_t CalcChiSquareExpected (const std::vector< Double_t > &par)
 Calculates expected chi-square (for statistical analysis).
 
virtual Double_t CalcMaxLikelihood (const std::vector< Double_t > &par)
 Calculates maximum likelihood estimator.
 
virtual void CalcTheory ()
 Calculates theoretical asymmetry function.
 
virtual UInt_t GetNoOfFitBins ()
 Returns the number of bins used in the fit.
 
virtual void SetFitRangeBin (const TString fitRange)
 Sets the fit range in bins.
 
virtual Int_t GetStartTimeBin ()
 Returns the first bin used in the fit.
 
virtual Int_t GetEndTimeBin ()
 Returns the last bin used in the fit.
 
virtual Int_t GetPacking ()
 Returns the packing factor.
 
virtual void CalcNoOfFitBins ()
 Calculates the number of bins to be fitted.
 
- 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 PRunDataGetData ()
 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 ()
 Prepares all data for fitting or viewing.
 
virtual Bool_t PrepareFitData ()
 Prepares data specifically for fitting.
 
virtual Bool_t PrepareViewData (PRawRunData *runData, UInt_t histoNo[2])
 Prepares data for viewing/plotting.
 
virtual Bool_t PrepareRRFViewData (PRawRunData *runData, UInt_t histoNo[2])
 Prepares rotating reference frame (RRF) data for viewing.
 
- 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 Member Functions

Bool_t SubtractFixBkg ()
 Subtracts fixed background from histograms.
 
Bool_t SubtractEstimatedBkg ()
 Estimates and subtracts background from histograms.
 
virtual Bool_t GetProperT0 (PRawRunData *runData, PMsrGlobalBlock *globalBlock, PUIntVector &forwardHisto, PUIntVector &backwardHistoNo)
 Retrieves proper t0 values for all histograms.
 
virtual Bool_t GetProperDataRange (PRawRunData *runData, UInt_t histoNo[2])
 Retrieves proper data range for histograms.
 
virtual void GetProperFitRange (PMsrGlobalBlock *globalBlock)
 Determines the proper fit range from global block.
 

Private Attributes

UInt_t fAlphaBetaTag
 Tag indicating α/β configuration: 1=both unity, 2=α free/β unity, 3=α unity/β free, 4=both free.
 
UInt_t fNoOfFitBins
 Number of bins included in the fit.
 
Int_t fPacking
 Bin packing factor from RUN or GLOBAL block.
 
Bool_t fTheoAsData
 If true, theory calculated only at data points; if false, extra points for nicer Fourier transforms.
 
PDoubleVector fForward
 Forward detector histogram data.
 
PDoubleVector fForwardErr
 Forward detector histogram errors.
 
PDoubleVector fBackward
 Backward detector histogram data.
 
PDoubleVector fBackwardErr
 Backward detector histogram errors.
 
Int_t fGoodBins [4]
 Good bin boundaries: [0]=forward first, [1]=forward last, [2]=backward first, [3]=backward last.
 
Int_t fStartTimeBin
 First bin index for fitting.
 
Int_t fEndTimeBin
 Last bin index for fitting.
 

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)
 
PMsrHandlerfMsrInfo
 Pointer to MSR file handler (owned externally, not deleted here)
 
PMsrRunBlockfRunInfo
 Pointer to this run's RUN block settings within fMsrInfo.
 
PRunDataHandlerfRawData
 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< PDoubleVectorfAddT0s
 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< PTheoryfTheory
 Theory function evaluator (smart pointer, automatically deleted)
 
PDoubleVector fKaiserFilter
 Kaiser window FIR filter coefficients for smoothing RRF theory curves.
 

Detailed Description

Class for handling standard μSR asymmetry fits.

PRunAsymmetry implements asymmetry fitting for conventional μSR experiments, where the asymmetry is calculated from forward and backward detector histograms:

\[ A(t) = \frac{F(t) - \alpha B(t)}{F(t) + \alpha B(t)} \]

The class supports various configurations:

  • α and β parameters (detector efficiency corrections)
  • Background subtraction (fixed or estimated)
  • Bin packing for improved statistics
  • Rotating reference frame (RRF) data handling
  • Multiple histogram grouping and run adding

The α/β parameter configurations are:

  • Tag 1: α = β = 1 (no corrections)
  • Tag 2: α ≠ 1, β = 1 (forward/backward asymmetry correction)
  • Tag 3: α = 1, β ≠ 1 (alternative correction)
  • Tag 4: α ≠ 1, β ≠ 1 (both corrections active)
See also
PRunBase for the base class providing common functionality
PRunAsymmetryBNMR for β-NMR asymmetry (helicity-dependent)
PRunSingleHisto for single histogram fits

Definition at line 61 of file PRunAsymmetry.h.

Constructor & Destructor Documentation

◆ PRunAsymmetry() [1/2]

PRunAsymmetry::PRunAsymmetry ( )

Default constructor.

Default constructor that initializes all member variables.

Sets all counters and indices to default/invalid values. This constructor creates an invalid instance that requires proper initialization via the main constructor.

Definition at line 60 of file PRunAsymmetry.cpp.

References fEndTimeBin, fGoodBins, fNoOfFitBins, fPacking, fStartTimeBin, fTheoAsData, and PRunBase::PRunBase().

◆ PRunAsymmetry() [2/2]

PRunAsymmetry::PRunAsymmetry ( PMsrHandler * msrInfo,
PRunDataHandler * rawData,
UInt_t runNo,
EPMusrHandleTag tag,
Bool_t theoAsData )

Main constructor for μSR asymmetry fitting.

Main constructor that initializes μSR asymmetry fitting.

Parameters
msrInfoPointer to MSR file handler
rawDataPointer to raw run data handler
runNoRun number within the MSR file
tagOperation mode (kFit for fitting, kView for viewing)
theoAsDataIf true, calculate theory only at data points; if false, calculate additional points for Fourier

Performs comprehensive initialization:

  1. Validates packing parameter from RUN or GLOBAL block
  2. Validates α parameter (required for asymmetry)
  3. Validates β parameter (optional, defaults to 1)
  4. Determines α/β configuration tag (1-4)
  5. Calls PrepareData() to load and process histogram data

The α/β tag determines the asymmetry calculation method:

  • Tag 1: α=1, β=1 (no corrections)
  • Tag 2: α≠1, β=1 (forward/backward correction)
  • Tag 3: α=1, β≠1 (alternative correction)
  • Tag 4: α≠1, β≠1 (both corrections)
Parameters
msrInfoPointer to MSR file handler
rawDataPointer to raw run data handler
runNoRun number within the MSR file
tagOperation mode (kFit or kView)
theoAsDataIf true, calculate theory only at data points

Definition at line 100 of file PRunAsymmetry.cpp.

References fEndTimeBin, fGoodBins, PRunBase::fMsrInfo, fPacking, PRunBase::fRunInfo, fStartTimeBin, fTheoAsData, PRunBase::fValid, PMsrHandler::GetMsrParamList(), if(), MSR_PARAM_FUN_OFFSET, and PRunBase::PRunBase().

◆ ~PRunAsymmetry()

PRunAsymmetry::~PRunAsymmetry ( )
virtual

Destructor.

Destructor that cleans up histogram data.

Clears all four histogram vectors (forward/backward × data/errors) to free memory.

Definition at line 200 of file PRunAsymmetry.cpp.

References fBackward, fBackwardErr, fForward, and fForwardErr.

Member Function Documentation

◆ CalcChiSquare()

Double_t PRunAsymmetry::CalcChiSquare ( const std::vector< Double_t > & par)
virtual

Calculates chi-square for the current parameter set.

Calculates chi-square for μSR asymmetry fit.

Parameters
parParameter vector from MINUIT
Returns
Chi-square value

Computes χ² by comparing the measured asymmetry with theory: χ² = Σ[(A_data - A_theory)²/σ²]

The asymmetry calculation depends on fAlphaBetaTag:

  • Tag 1 (α=β=1): A = (F - B)/(F + B)
  • Tag 2 (α≠1, β=1): A = (F - αB)/(F + αB)
  • Tag 3 (α=1, β≠1): Uses β correction
  • Tag 4 (α≠1, β≠1): Uses both α and β corrections

Supports OpenMP parallelization for faster calculation.

Parameters
parParameter vector from MINUIT minimizer
Returns
Chi-square value

Implements PRunBase.

Definition at line 228 of file PRunAsymmetry.cpp.

References fAlphaBetaTag, PRunBase::fData, fEndTimeBin, PRunBase::fFuncValues, PRunBase::fMetaData, PRunBase::fMsrInfo, PRunBase::fRunInfo, fStartTimeBin, PRunBase::fTheory, and MSR_PARAM_FUN_OFFSET.

◆ CalcChiSquareExpected()

Double_t PRunAsymmetry::CalcChiSquareExpected ( const std::vector< Double_t > & par)
virtual

Calculates expected chi-square (for statistical analysis).

Calculates expected chi-square value.

Parameters
parParameter vector from MINUIT
Returns
Expected chi-square value

This function is currently not implemented for asymmetry fits because the expected chi-square calculation for asymmetry data requires a more complex statistical treatment than for single histogram fits. The asymmetry is a ratio of count rates, and the proper expected value calculation is non-trivial.

Parameters
parParameter vector from MINUIT minimizer
Returns
Always returns 0.0 (placeholder value)
Todo
Implement proper expected chi-square calculation for asymmetry fits

Implements PRunBase.

Definition at line 335 of file PRunAsymmetry.cpp.

◆ CalcMaxLikelihood()

Double_t PRunAsymmetry::CalcMaxLikelihood ( const std::vector< Double_t > & par)
virtual

Calculates maximum likelihood estimator.

Calculates maximum likelihood estimator for asymmetry fit.

Parameters
parParameter vector from MINUIT
Returns
Maximum likelihood value

Maximum likelihood estimation provides an alternative to χ² minimization and can be more appropriate for low-count data where Gaussian statistics do not apply. However, the proper likelihood function for μSR asymmetry data is complex and not yet implemented.

Parameters
parParameter vector from MINUIT minimizer
Returns
Placeholder value of 1.0
Todo
Implement proper Poisson-based maximum likelihood for asymmetry fits

Implements PRunBase.

Definition at line 355 of file PRunAsymmetry.cpp.

◆ CalcNoOfFitBins()

void PRunAsymmetry::CalcNoOfFitBins ( )
virtual

Calculates the number of bins to be fitted.

Calculates the number of bins included in the current fit range.

Determines fNoOfFitBins based on the fit range and data availability.

Determines fStartTimeBin and fEndTimeBin from the fit time range (fFitStartTime, fFitEndTime) and data time grid. Ensures that bin indices remain within valid histogram bounds. The result is stored in fNoOfFitBins.

This calculation accounts for:

  • Data time step and start time
  • Rounding effects (ceiling for start, floor for end)
  • Boundary conditions (clips to [0, histogram size])

Definition at line 486 of file PRunAsymmetry.cpp.

References PRunBase::fData, fEndTimeBin, PRunBase::fFitEndTime, PRunBase::fFitStartTime, fNoOfFitBins, and fStartTimeBin.

Referenced by GetNoOfFitBins(), PrepareFitData(), and PrepareViewData().

◆ CalcTheory()

void PRunAsymmetry::CalcTheory ( )
virtual

Calculates theoretical asymmetry function.

Calculates theoretical asymmetry values for the current parameters.

Computes the theory values for the μSR asymmetry based on the current parameters and fit function.

Computes the expected asymmetry A(t) for all data points based on the current parameter values and the user-defined theory function. The calculation depends on the α/β correction mode:

  • Tag 1 (α=1, β=1): A(t) = f(t)
  • Tag 2 (α≠1, β=1): A(t) = [f(t)(α+1) - (α-1)] / [(α+1) - f(t)(α-1)]
  • Tag 3 (α=1, β≠1): A(t) = f(t)(β+1) / [2 - f(t)(β-1)]
  • Tag 4 (α≠1, β≠1): Combined α and β corrections

where f(t) is the raw theory function from the THEORY block.

The calculated values are stored in fData for plotting and comparison with measured data.

Implements PRunBase.

Definition at line 521 of file PRunAsymmetry.cpp.

References fAlphaBetaTag, PRunBase::fData, PRunBase::fFuncValues, PRunBase::fMetaData, PRunBase::fMsrInfo, PRunBase::fRunInfo, PRunBase::fTheory, and MSR_PARAM_FUN_OFFSET.

◆ GetEndTimeBin()

virtual Int_t PRunAsymmetry::GetEndTimeBin ( )
inlinevirtual

Returns the last bin used in the fit.

Returns
End time bin index

Definition at line 131 of file PRunAsymmetry.h.

References fEndTimeBin.

◆ GetNoOfFitBins()

UInt_t PRunAsymmetry::GetNoOfFitBins ( )
virtual

Returns the number of bins used in the fit.

Returns the number of bins included in the fit.

Returns
Number of fit bins

Calculates and returns the number of data bins that fall within the current fit range. This value is used for determining degrees of freedom and is recalculated when the fit range changes (e.g., via COMMAND block).

Returns
Number of data bins included in the fit

Definition at line 374 of file PRunAsymmetry.cpp.

References CalcNoOfFitBins(), and fNoOfFitBins.

◆ GetPacking()

virtual Int_t PRunAsymmetry::GetPacking ( )
inlinevirtual

Returns the packing factor.

Returns
Number of bins combined (1 = no packing)

Definition at line 137 of file PRunAsymmetry.h.

References fPacking.

◆ GetProperDataRange()

Bool_t PRunAsymmetry::GetProperDataRange ( PRawRunData * runData,
UInt_t histoNo[2] )
privatevirtual

Retrieves proper data range for histograms.

Determines the valid data range (first/last good bins) for analysis.

Determines the "good bins" range for data analysis from:

  1. Individual RUN block data range settings
  2. GLOBAL block data range (fallback)
  3. Full histogram range (final fallback)

The good bins define which portion of the histograms contains valid data, excluding noisy or problematic regions at the start/end.

Parameters
runDataPointer to raw run data
histoNoArray of histogram numbers [0]=forward, [1]=backward
Returns
True on success, false on error

The data range defines which portion of the histograms contains usable data, excluding initial and final bins that may be noisy or affected by detector artifacts.

Determination hierarchy:

  1. RUN block data range settings (highest priority, run-specific)
  2. GLOBAL block data range (shared defaults)
  3. Estimated range (last resort: start = t0 + 10ns, end = histogram length)

Performs validation checks:

  • Ensures start < end (swaps if needed)
  • Verifies bins are within histogram bounds [0, histogram size]
  • Validates t0 is within valid range
  • Clips end bin if it exceeds histogram length

The good bins are stored in fGoodBins as [forward_start, forward_end, backward_start, backward_end].

Parameters
runDataPointer to raw run data for histogram size validation
histoNoArray of histogram indices: [0]=forward, [1]=backward
Returns
True on success, false if data range is invalid or out of bounds
Warning
Estimated data ranges may not be appropriate for all experiments

Definition at line 2018 of file PRunAsymmetry.cpp.

References fBackward, fForward, fGoodBins, PRunBase::fMsrInfo, PRunBase::fRunInfo, PRunBase::fT0s, PRunBase::fTimeResolution, and PRawRunData::GetDataBin().

Referenced by PrepareData().

◆ GetProperFitRange()

void PRunAsymmetry::GetProperFitRange ( PMsrGlobalBlock * globalBlock)
privatevirtual

Determines the proper fit range from global block.

Determines the fit range for χ² minimization.

Extracts fit range settings from the GLOBAL block if not specified in the RUN block. The fit range defines the time window used for χ² minimization, specified either in time units (μs) or bin numbers.

Parameters
globalBlockPointer to global MSR block containing default fit range

The fit range defines the time window used for parameter fitting. It can be specified in two formats:

  • Time-based: "fit start end" in microseconds (e.g., "fit 0.1 10.0")
  • Bin-based: "fit fgb+offset lgb-offset" using good bin boundaries (e.g., "fit fgb+5 lgb-10")

Determination sequence:

  1. Checks RUN block for time-based fit range
  2. If RUN block specifies bin-based range, converts to time using fgb/lgb offsets
  3. Falls back to GLOBAL block fit range (time or bin-based) if RUN block is empty
  4. Uses full data range (fgb to lgb) if no fit range is specified

Bin-based format allows fine-tuning relative to good bin boundaries:

  • fgb+n: Start n bins after first good bin
  • lgb-n: End n bins before last good bin

The resulting fit range is stored as time values in fFitStartTime and fFitEndTime.

Parameters
globalBlockPointer to GLOBAL block containing default fit range settings

Definition at line 2172 of file PRunAsymmetry.cpp.

References PRunBase::fFitEndTime, PRunBase::fFitStartTime, fGoodBins, PRunBase::fRunInfo, PRunBase::fT0s, PRunBase::fTimeResolution, PMsrGlobalBlock::GetFitRange(), PMsrGlobalBlock::GetFitRangeOffset(), PMsrGlobalBlock::IsFitRangeInBin(), PMUSR_UNDEFINED, and PMsrGlobalBlock::SetFitRange().

Referenced by PrepareData().

◆ GetProperT0()

Bool_t PRunAsymmetry::GetProperT0 ( PRawRunData * runData,
PMsrGlobalBlock * globalBlock,
PUIntVector & forwardHistoNo,
PUIntVector & backwardHistoNo )
privatevirtual

Retrieves proper t0 values for all histograms.

Determines and validates t0 values for all forward and backward histograms.

Determines t0 (time zero) values for forward and backward histograms from:

  1. Individual RUN block t0 entries
  2. GLOBAL block t0 values (fallback)
  3. Data file t0 values (final fallback)

Also handles addT0 corrections for runs to be added together. The t0 values are critical for proper alignment of histograms in time.

Parameters
runDataPointer to raw run data containing histogram information
globalBlockPointer to global MSR block with default t0 values
forwardHistoVector of forward histogram indices
backwardHistoNoVector of backward histogram indices
Returns
True on success, false if t0 values cannot be determined

Time zero (t0) marks the arrival time of muons in the sample and is critical for proper time alignment. This method attempts to find t0 values from multiple sources with a well-defined fallback hierarchy:

Priority order:

  1. Individual RUN block t0 values (highest priority, user-specified)
  2. GLOBAL block t0 values (shared defaults for all runs)
  3. Data file t0 values (from detector electronics or auto-detection)
  4. Estimated t0 values (last resort, may be unreliable for some facilities)

The t0 vector is organized as [forward_0, backward_0, forward_1, backward_1, ...], accommodating different numbers of forward/backward histograms in grouped data.

Also handles addT0 values for runs being added together, ensuring proper time alignment when combining multiple datasets.

Parameters
runDataPointer to raw run data containing file-based t0 information
globalBlockPointer to GLOBAL block with default t0 settings
forwardHistoNoVector of forward histogram indices (after red/green offset adjustment)
backwardHistoNoVector of backward histogram indices (after red/green offset adjustment)
Returns
True on success, false if critical t0 values cannot be determined
Warning
Estimated t0 values may be unreliable for certain facilities (e.g., LEM)

Definition at line 1830 of file PRunAsymmetry.cpp.

References PRunBase::fAddT0s, PRunBase::fRawData, PRunBase::fRunInfo, PRunBase::fT0s, PRawRunData::GetDataBin(), PMsrGlobalBlock::GetT0Bin(), PRawRunData::GetT0Bin(), PRawRunData::GetT0BinEstimated(), and PMsrGlobalBlock::GetT0BinSize().

Referenced by PrepareData().

◆ GetStartTimeBin()

virtual Int_t PRunAsymmetry::GetStartTimeBin ( )
inlinevirtual

Returns the first bin used in the fit.

Returns
Start time bin index

Definition at line 125 of file PRunAsymmetry.h.

References fStartTimeBin.

◆ PrepareData()

Bool_t PRunAsymmetry::PrepareData ( )
protectedvirtual

Prepares all data for fitting or viewing.

Main data preparation routine for asymmetry fitting and viewing.

Returns
True on success, false on error

Main data preparation routine that handles background subtraction, packing, and asymmetry calculation from forward/backward histograms.

Performs comprehensive data preparation including:

  • Loading forward/backward histograms from data files
  • Extracting metadata (field, energy, temperature)
  • Determining time resolution from data file
  • Validating and retrieving t0 values for all histograms
  • Adding multiple runs together (if addruns are specified)
  • Grouping multiple histograms (if grouping is specified)
  • Subtracting background (fixed or estimated)
  • Calculating asymmetry and error bars
  • Applying bin packing (if specified)

The asymmetry is calculated as:

\[ A_i = \frac{f_i^{\rm c} - b_i^{\rm c}}{f_i^{\rm c} + b_i^{\rm c}} \]

Error propagation (assuming Poisson statistics):

\[ \Delta A_i = \pm\frac{2}{(f_i^{\rm c}+b_i^{\rm c})^2}\sqrt{
    (b_i^{\rm c})^2 (\Delta f_i^{\rm c})^2 +
    (f_i^{\rm c})^2 (\Delta b_i^{\rm c})^2} \]

where $ f_i^{\rm c} $ and $ b_i^{\rm c} $ are background-corrected forward and backward histograms, respectively.

Returns
True if data preparation succeeds, false on any error

Implements PRunBase.

Definition at line 629 of file PRunAsymmetry.cpp.

References PRunBase::DeadTimeCorrection(), PRunBase::fAddT0s, fBackward, fForward, PRunBase::fHandleTag, PRunBase::fMetaData, PRunBase::fMsrInfo, PRunBase::fRawData, PRunBase::fRunInfo, PRunBase::fT0s, PRunBase::fTimeResolution, PRunBase::fValid, PRawRunData::GetDataBin(), PRawRunData::GetEnergy(), PRawRunData::GetField(), PRawRunData::GetNoOfTemperatures(), GetProperDataRange(), GetProperFitRange(), GetProperT0(), PRawRunData::GetTemperature(), PRawRunData::GetTimeResolution(), PRawRunData::IsPresent(), kFit, kView, PMUSR_UNDEFINED, PrepareFitData(), PrepareRRFViewData(), PrepareViewData(), status, SubtractEstimatedBkg(), and SubtractFixBkg().

◆ PrepareFitData()

Bool_t PRunAsymmetry::PrepareFitData ( )
protectedvirtual

Prepares data specifically for fitting.

Processes pre-grouped data and calculates asymmetry for fitting.

Returns
True on success, false on error

Sets up data structures for the fitting process, including determining fit ranges and calculating the number of fit bins.

Takes forward/backward histograms (after grouping and addrun operations) and performs final processing steps for fitting:

  1. Validates data range, estimates if not specified
  2. Checks data range consistency and validity
  3. Aligns forward/backward histograms (ensures 'first good bin - t0' is identical)
  4. Applies bin packing (rebinning) if requested
  5. Truncates longer histogram if packed sizes differ
  6. Calculates asymmetry: $ A_i = (f_i^{\rm c}-b_i^{\rm c})/(f_i^{\rm c}+b_i^{\rm c}) $
  7. Propagates errors: $ \delta A_i = \frac{2}{(f_i^{\rm c}+b_i^{\rm c})^2}\sqrt{(b_i^{\rm c})^2 (\delta f_i^{\rm c})^2 + (f_i^{\rm c})^2 (\delta b_i^{\rm c})^2} $

Bin packing averages multiple bins to improve statistics:

  • Packed value normalized to per-bin counts (value/packing)
  • Error propagation: $ \sigma_{\rm packed} = \sqrt{\sum \sigma_i^2}/N_{\rm pack} $
Returns
True on success, false if data preparation fails

Definition at line 1067 of file PRunAsymmetry.cpp.

References PRunData::AppendErrorValue(), PRunData::AppendValue(), CalcNoOfFitBins(), fBackward, fBackwardErr, PRunBase::fData, fForward, fForwardErr, fGoodBins, fPacking, PRunBase::fT0s, PRunBase::fTimeResolution, PRunData::GetError(), and PRunData::GetValue().

Referenced by PrepareData().

◆ PrepareRRFViewData()

Bool_t PRunAsymmetry::PrepareRRFViewData ( PRawRunData * runData,
UInt_t histoNo[2] )
protectedvirtual

Prepares rotating reference frame (RRF) data for viewing.

Prepares rotating reference frame (RRF) data for visualization.

Parameters
runDataPointer to raw run data
histoNoArray of histogram numbers [0]=forward, [1]=backward
Returns
True on success, false on error

Special handling for RRF data where asymmetry is calculated in a rotating coordinate frame.

Transforms asymmetry data into a rotating reference frame for analyzing high-frequency oscillations. The RRF technique mixes the data with a reference frequency to shift oscillations down to lower frequencies, making them easier to visualize and analyze.

Processing sequence:

  1. Validates data ranges and histogram alignment
  2. Builds asymmetry $ A(t) $ without packing
  3. Applies RRF transformation: $ A_R(t) = A(t) \cdot 2\cos(\omega_R t + \phi_R) $
  4. Packs the RRF asymmetry data
  5. Calculates theory $ T(t) $ at high time resolution
  6. Transforms theory to RRF: $ T_R(t) = T(t) \cdot 2\cos(\omega_R t + \phi_R) $
  7. Packs the RRF theory curve
  8. Applies Kaiser FIR filter to smooth the theory curve

The RRF frequency ( $ \omega_R $) and phase ( $ \phi_R $) are specified in the PLOT block.

Parameters
runDataPointer to raw run data for validation
histoNoArray of histogram indices: [0]=forward, [1]=backward
Returns
True on success, false on error

Definition at line 1483 of file PRunAsymmetry.cpp.

References PRunBase::CalculateKaiserFilterCoeff(), fAlphaBetaTag, fBackward, fBackwardErr, PRunBase::fData, fForward, fForwardErr, PRunBase::fFuncValues, fGoodBins, PRunBase::FilterTheo(), PRunBase::fMetaData, PRunBase::fMsrInfo, PRunBase::fRunInfo, PRunBase::fT0s, PRunBase::fTheory, PRunBase::fTimeResolution, GAMMA_BAR_MUON, PRawRunData::GetDataBin(), MSR_PARAM_FUN_OFFSET, RRF_UNIT_G, RRF_UNIT_kHz, RRF_UNIT_Mcs, RRF_UNIT_MHz, and RRF_UNIT_T.

Referenced by PrepareData().

◆ PrepareViewData()

Bool_t PRunAsymmetry::PrepareViewData ( PRawRunData * runData,
UInt_t histoNo[2] )
protectedvirtual

Prepares data for viewing/plotting.

Prepares asymmetry data for plotting and visualization.

Parameters
runDataPointer to raw run data
histoNoArray of histogram numbers [0]=forward, [1]=backward
Returns
True on success, false on error

Processes pre-grouped data for display in plots, with special handling for view packing and α/β corrections. Similar to PrepareFitData but includes theory calculation and supports separate view packing settings.

Processing steps:

  1. Checks for view-specific packing (overrides fit packing for display)
  2. Validates and estimates data range if needed
  3. Aligns forward/backward histogram start bins relative to t0
  4. Applies bin packing for improved visualization
  5. Ensures equal bin counts between forward/backward after packing
  6. Calculates asymmetry with α/β corrections: $ A_i = (\alpha f_i^{\rm c} - b_i^{\rm c})/(\alpha \beta f_i^{\rm c} + b_i^{\rm c}) $
  7. Propagates errors: $ \delta A_i = \frac{2}{(f_i^{\rm c}+b_i^{\rm c})^2}\sqrt{(b_i^{\rm c})^2 (\delta f_i^{\rm c})^2 + (f_i^{\rm c})^2 (\delta b_i^{\rm c})^2} $
  8. Calculates theory curve for overlay
Parameters
runDataPointer to raw run data for validation and cross-checks
histoNoArray of histogram indices: [0]=forward, [1]=backward
Returns
True on success, false on error

Definition at line 1191 of file PRunAsymmetry.cpp.

References PRunData::AppendErrorValue(), PRunData::AppendValue(), CalcNoOfFitBins(), fAlphaBetaTag, fBackward, fBackwardErr, PRunBase::fData, fForward, fForwardErr, PRunBase::fFuncValues, fGoodBins, PRunBase::fMetaData, PRunBase::fMsrInfo, fPacking, PRunBase::fRunInfo, PRunBase::fT0s, fTheoAsData, PRunBase::fTheory, PRunBase::fTimeResolution, PRawRunData::GetDataBin(), PRunData::GetError(), PRunData::GetValue(), and MSR_PARAM_FUN_OFFSET.

Referenced by PrepareData().

◆ SetFitRangeBin()

void PRunAsymmetry::SetFitRangeBin ( const TString fitRange)
virtual

Sets the fit range in bins.

Dynamically changes the fit range in bin units.

Parameters
fitRangeFit range string (format depends on configuration)

Allows modification of the fit range at runtime, typically called from the COMMAND block. Supports bin-based fit ranges with optional offsets for fine-tuning.

Syntax formats:

  • Single range: FIT_RANGE fgb[+n0] lgb[-n1]
    • Applied to all RUN blocks
  • Multiple ranges: FIT_RANGE fgb[+n00] lgb[-n01] fgb[+n10] lgb[-n11] ... fgb[+nN0] lgb[-nN1]
    • One pair per RUN block (N must equal number of RUN blocks)

Parameters:

  • fgb: First good bin (start of fit range)
  • lgb: Last good bin (end of fit range)
  • +n: Positive offset to shift start forward
  • -n: Negative offset to shift end backward

Example: "FIT_RANGE 10+5 200-10" uses bins [15, 190] for fitting

Parameters
fitRangeString containing fit range specification

Definition at line 406 of file PRunAsymmetry.cpp.

References PRunBase::fFitEndTime, PRunBase::fFitStartTime, fGoodBins, PRunBase::fRunNo, PRunBase::fT0s, and PRunBase::fTimeResolution.

◆ SubtractEstimatedBkg()

Bool_t PRunAsymmetry::SubtractEstimatedBkg ( )
private

Estimates and subtracts background from histograms.

Calculates background from a specified bin range (typically before t0) and subtracts it from forward and backward histograms. The background range is adjusted to align with accelerator beam cycles when applicable (PSI, RAL, TRIUMF).

Background calculation:

\[ \mathrm{bkg} = \frac{1}{N}\sum_{i=0}^N f_i \]

Error propagation:

\[ \Delta f_i^{\rm c} = \pm\sqrt{(\Delta f_i)^2 + (\Delta \mathrm{bkg})^2} = \pm\sqrt{f_i + (\Delta \mathrm{bkg})^2} \]

where $ N $ is the number of background bins and

\[ \Delta \mathrm{bkg} = \pm\frac{1}{N}\sqrt{\sum_{i=0}^N f_i} \]

Returns
True on success, false if background range is out of bounds

Subtracts the background which is estimated from a given interval (typically before t0).

The background corrected histogramms are: $ f_i^{\rm c} = f_i - \mathrm{bkg} $, where $ f_i $ is the raw data histogram, $ \mathrm{bkg} $ the background estimate, and $ f_i^{\rm c} $ background corrected histogram. The error on $ f_i^{\rm c} $ is

\[ \Delta f_i^{\rm c} = \pm \sqrt{ (\Delta f_i)^2 + (\Delta \mathrm{bkg})^2 } =
   \pm \sqrt{f_i + (\Delta \mathrm{bkg})^2} \]

The background error $ \Delta \mathrm{bkg} $ is

\[ \Delta \mathrm{bkg} = \pm\frac{1}{N}\left[\sum_{i=0}^N (\Delta f_i)^2\right]^{1/2} =
\pm\frac{1}{N}\left[\sum_{i=0}^N f_i \right]^{1/2},\]

where $N$ is the number of bins over which the background is formed.

return:

  • true

Definition at line 942 of file PRunAsymmetry.cpp.

References ACCEL_PERIOD_PSI, ACCEL_PERIOD_RAL, ACCEL_PERIOD_TRIUMF, fBackward, fBackwardErr, fForward, fForwardErr, fPacking, PRunBase::fRunInfo, and PRunBase::fTimeResolution.

Referenced by PrepareData().

◆ SubtractFixBkg()

Bool_t PRunAsymmetry::SubtractFixBkg ( )
private

Subtracts fixed background from histograms.

Subtracts user-specified fixed background values from forward and backward histograms. Background values are read from the MSR file (e.g., "backgr.fix 2 3" for forward/backward).

Error propagation:

\[ \Delta f_i^{\rm c} = \pm\sqrt{(\Delta f_i)^2 + (\Delta \mathrm{bkg})^2} = \pm\sqrt{f_i + \mathrm{bkg}} \]

where $ f_i^{\rm c} $ is the background-corrected histogram, $ f_i $ is the raw histogram, and $ \mathrm{bkg} $ is the fixed background value.

Returns
True on success, false if background values are missing

Subtracts a fixed background from the raw data. The background is given in units of (1/bin); for the Asymmetry representation (1/ns) doesn't make too much sense. The error propagation is done the following way: it is assumed that the error of the background is Poisson like, i.e. $\Delta\mathrm{bkg} = \sqrt{\mathrm{bkg}}$.

Error propagation:

\[ \Delta f_i^{\rm c} = \pm\left[ (\Delta f_i)^2 + (\Delta \mathrm{bkg})^2 \right]^{1/2} =
     \pm\left[ f_i + \mathrm{bkg} \right]^{1/2}, \]

where $ f_i^{\rm c} $ is the background corrected histogram, $ f_i $ the raw histogram and $ \mathrm{bkg} $ the fix given background.

return:

  • true

Definition at line 884 of file PRunAsymmetry.cpp.

References fBackward, fBackwardErr, fForward, fForwardErr, PRunBase::fRunInfo, and PMUSR_UNDEFINED.

Referenced by PrepareData().

Member Data Documentation

◆ fAlphaBetaTag

UInt_t PRunAsymmetry::fAlphaBetaTag
private

Tag indicating α/β configuration: 1=both unity, 2=α free/β unity, 3=α unity/β free, 4=both free.

Definition at line 185 of file PRunAsymmetry.h.

Referenced by CalcChiSquare(), CalcTheory(), PrepareRRFViewData(), and PrepareViewData().

◆ fBackward

PDoubleVector PRunAsymmetry::fBackward
private

◆ fBackwardErr

PDoubleVector PRunAsymmetry::fBackwardErr
private

Backward detector histogram errors.

Definition at line 193 of file PRunAsymmetry.h.

Referenced by PrepareFitData(), PrepareRRFViewData(), PrepareViewData(), SubtractEstimatedBkg(), SubtractFixBkg(), and ~PRunAsymmetry().

◆ fEndTimeBin

Int_t PRunAsymmetry::fEndTimeBin
private

Last bin index for fitting.

Definition at line 198 of file PRunAsymmetry.h.

Referenced by CalcChiSquare(), CalcNoOfFitBins(), GetEndTimeBin(), PRunAsymmetry(), and PRunAsymmetry().

◆ fForward

PDoubleVector PRunAsymmetry::fForward
private

◆ fForwardErr

PDoubleVector PRunAsymmetry::fForwardErr
private

Forward detector histogram errors.

Definition at line 191 of file PRunAsymmetry.h.

Referenced by PrepareFitData(), PrepareRRFViewData(), PrepareViewData(), SubtractEstimatedBkg(), SubtractFixBkg(), and ~PRunAsymmetry().

◆ fGoodBins

Int_t PRunAsymmetry::fGoodBins[4]
private

Good bin boundaries: [0]=forward first, [1]=forward last, [2]=backward first, [3]=backward last.

Definition at line 195 of file PRunAsymmetry.h.

Referenced by GetProperDataRange(), GetProperFitRange(), PrepareFitData(), PrepareRRFViewData(), PrepareViewData(), PRunAsymmetry(), PRunAsymmetry(), and SetFitRangeBin().

◆ fNoOfFitBins

UInt_t PRunAsymmetry::fNoOfFitBins
private

Number of bins included in the fit.

Definition at line 186 of file PRunAsymmetry.h.

Referenced by CalcNoOfFitBins(), GetNoOfFitBins(), and PRunAsymmetry().

◆ fPacking

Int_t PRunAsymmetry::fPacking
private

Bin packing factor from RUN or GLOBAL block.

Definition at line 187 of file PRunAsymmetry.h.

Referenced by GetPacking(), PrepareFitData(), PrepareViewData(), PRunAsymmetry(), PRunAsymmetry(), and SubtractEstimatedBkg().

◆ fStartTimeBin

Int_t PRunAsymmetry::fStartTimeBin
private

First bin index for fitting.

Definition at line 197 of file PRunAsymmetry.h.

Referenced by CalcChiSquare(), CalcNoOfFitBins(), GetStartTimeBin(), PRunAsymmetry(), and PRunAsymmetry().

◆ fTheoAsData

Bool_t PRunAsymmetry::fTheoAsData
private

If true, theory calculated only at data points; if false, extra points for nicer Fourier transforms.

Definition at line 188 of file PRunAsymmetry.h.

Referenced by PrepareViewData(), PRunAsymmetry(), and PRunAsymmetry().


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