|
musrfit 1.10.0
|
Class for fitting single detector histograms (basic time-differential μSR). More...
#include <PRunSingleHisto.h>


Public Member Functions | |
| PRunSingleHisto () | |
| Default constructor creating an empty, invalid single histogram run object. | |
| PRunSingleHisto (PMsrHandler *msrInfo, PRunDataHandler *rawData, UInt_t runNo, EPMusrHandleTag tag, Bool_t theoAsData) | |
| Main constructor initializing a single histogram run from MSR file and data. | |
| virtual | ~PRunSingleHisto () |
| Virtual destructor cleaning up allocated resources. | |
| virtual Double_t | CalcChiSquare (const std::vector< Double_t > &par) |
| Calculates χ² between histogram data and theory. | |
| virtual Double_t | CalcChiSquareExpected (const std::vector< Double_t > &par) |
| Calculates expected χ² based on theory predictions. | |
| virtual Double_t | CalcMaxLikelihood (const std::vector< Double_t > &par) |
| Calculates maximum likelihood for Poisson-distributed histogram counts. | |
| virtual Double_t | CalcMaxLikelihoodExpected (const std::vector< Double_t > &par) |
| Calculates expected maximum likelihood. | |
| virtual void | CalcTheory () |
| Evaluates theory function at all data points or high-resolution grid. | |
| virtual UInt_t | GetNoOfFitBins () |
| Returns the number of bins included in the fit range. | |
| virtual void | SetFitRangeBin (const TString fitRange) |
| Sets fit range using bin-offset specification (COMMANDS block syntax). | |
| virtual Double_t | GetBackground () |
| Returns the estimated background level. | |
| virtual Int_t | GetStartTimeBin () |
| Returns the first bin index in the fit range. | |
| virtual Int_t | GetEndTimeBin () |
| Returns the last bin index in the fit range (exclusive). | |
| virtual Int_t | GetPacking () |
| Returns the bin packing factor. | |
| virtual Bool_t | GetScaleN0AndBkg () |
| Returns the N₀/background scaling mode. | |
| virtual void | CalcNoOfFitBins () |
| Calculates start/end bin indices from fit time range. | |
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. | |
| virtual Bool_t | PrepareFitData (PRawRunData *runData, const UInt_t histoNo) |
| Prepares histogram data for fitting. | |
| virtual Bool_t | PrepareRawViewData (PRawRunData *runData, const UInt_t histoNo) |
| Prepares raw histogram data for viewing (minimal processing). | |
| virtual Bool_t | PrepareViewData (PRawRunData *runData, const UInt_t histoNo) |
| Prepares processed histogram 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 Member Functions | |
| virtual Bool_t | GetProperT0 (PRawRunData *runData, PMsrGlobalBlock *globalBlock, PUIntVector &histoNo) |
| Determines and validates t0 values for histogram. | |
| virtual Bool_t | GetProperDataRange () |
| Determines data range (region of valid histogram data). | |
| virtual void | GetProperFitRange (PMsrGlobalBlock *globalBlock) |
| Determines fit range from MSR file settings. | |
| virtual void | EstimateN0 () |
| Estimates initial normalization N₀ from histogram data. | |
| virtual Bool_t | EstimateBkg (UInt_t histoNo) |
| Estimates background from pre-t0 bins. | |
| virtual Bool_t | IsScaleN0AndBkg () |
| Determines if N₀ and background should be scaled to 1/ns. | |
Private Attributes | |
| Bool_t | fScaleN0AndBkg |
| Scaling mode: true = scale N₀ and B to 1/ns, false = leave as 1/bin (determined by IsScaleN0AndBkg()) | |
| UInt_t | fNoOfFitBins |
| Number of bins within fit range (fStartTimeBin to fEndTimeBin) | |
| Double_t | fBackground |
| Background level in counts/bin (estimated from pre-t0 bins or fixed value from RUN block) | |
| Int_t | fPacking |
| Bin packing factor (REQUIRED: from RUN or GLOBAL block) | |
| Bool_t | fTheoAsData |
| Theory mode: true = at data points, false = high-resolution grid for smooth Fourier transforms. | |
| Int_t | fGoodBins [2] |
| Good bin markers for COMMANDS block: [0]=fgb (first good bin/t0), [1]=lgb (last good bin) | |
| PDoubleVector | fForward |
| Forward detector histogram (background-corrected, packed) | |
| Int_t | fStartTimeBin |
| First bin index in fit range (inclusive, 0-based after packing) | |
| Int_t | fEndTimeBin |
| Last bin index in fit range (exclusive: loop as i < fEndTimeBin) | |
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 single detector histograms (basic time-differential μSR).
PRunSingleHisto implements the most fundamental μSR analysis: fitting a single positron detector histogram to extract relaxation parameters. This is the basis for all μSR measurements and is used when asymmetry analysis is not appropriate or desired.
Single histogram measurements are used for:
Histogram content:
where:
The fitted function is typically:
![\[ N(t) = N_0 e^{-t/\tau_\mu} P(t) + B \]](form_33.png)
Common polarization functions P(t):
Normalization (N₀):
Background (B):
Packing:
| Feature | Single Histogram | Asymmetry |
|---|---|---|
| Detectors | One (forward) | Two (forward + backward) |
| Quantity fitted | N(t) counts | A(t) = (F-αB)/(F+αB) |
| Statistics | All positrons | F and B separately |
| Background | Additive B | Cancels in asymmetry |
| α parameter | N/A | Required (F/B asymmetry) |
| Use cases | TF, calibration | LF, ZF, weak TF |
Definition at line 143 of file PRunSingleHisto.h.
| PRunSingleHisto::PRunSingleHisto | ( | ) |
Default constructor creating an empty, invalid single histogram run object.
Default constructor for single histogram fitting class.
Initializes all member variables to default/invalid states:
This constructor is needed for creating vectors of PRunSingleHisto objects. The resulting object cannot be used until properly initialized via the main constructor.
Initializes all member variables to safe default values:
Definition at line 65 of file PRunSingleHisto.cpp.
References fBackground, fEndTimeBin, fGoodBins, fNoOfFitBins, fPacking, fScaleN0AndBkg, fStartTimeBin, fTheoAsData, and PRunBase::PRunBase().
| PRunSingleHisto::PRunSingleHisto | ( | PMsrHandler * | msrInfo, |
| PRunDataHandler * | rawData, | ||
| UInt_t | runNo, | ||
| EPMusrHandleTag | tag, | ||
| Bool_t | theoAsData ) |
Main constructor initializing a single histogram run from MSR file and data.
Main constructor for single histogram fitting and viewing.
Performs comprehensive initialization:
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 histogram loading |
| 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 |
Constructs a fully initialized single histogram run object by:
| msrInfo | Pointer to MSR file handler (NOT owned, must outlive this object) |
| rawData | Pointer to raw run data handler (NOT owned, must outlive this object) |
| runNo | Zero-based index of the RUN block in the MSR file |
| tag | Operation mode: kFit (fitting) or kView (viewing/plotting) |
| theoAsData | If true, theory is calculated only at data points (for viewing); if false, theory uses finer time grid (8× data resolution) |
Definition at line 108 of file PRunSingleHisto.cpp.
References fBackground, fEndTimeBin, fGoodBins, PRunBase::fMsrInfo, fNoOfFitBins, fPacking, PRunBase::fRunInfo, fScaleN0AndBkg, fStartTimeBin, fTheoAsData, PRunBase::fValid, IsScaleN0AndBkg(), PrepareData(), and PRunBase::PRunBase().
|
virtual |
Virtual destructor cleaning up allocated resources.
Destructor for single histogram fitting class.
Releases memory used by the forward histogram vector (fForward). Base class destructor handles cleanup of theory objects and other shared resources.
Cleans up dynamically allocated memory:
Definition at line 153 of file PRunSingleHisto.cpp.
References fForward.
|
virtual |
Calculates χ² between histogram data and theory.
Calculates χ² between data and theory (least-squares fit metric).
Computes chi-squared for single histogram fitting:
![\[ \chi^2 = \sum_{i} \frac{(N_i^{\rm data} - N_i^{\rm theory})^2}{\sigma_i^2} \]](form_34.png)
where N_theory(t) = N₀·exp(-t/τ_μ)·P(t) + B
Uses OpenMP parallelization when available. N₀ can be a fit parameter or derived from FUNCTIONS block.
| par | Parameter vector from MINUIT |
Computes the standard chi-square goodness-of-fit statistic:
![\[\chi^2 = \sum_{i=t_{\rm start}}^{t_{\rm end}} \frac{[N_i - N_{\rm theo}(t_i)]^2}{\sigma_i^2}
\]](form_84.png)
where the theory function is:
![\[N_{\rm theo}(t) = N_0 e^{-t/\tau_\mu} [1 + P(t)] + B
\]](form_85.png)
Algorithm:
N₀ Parameter vs. Function Handling:
OpenMP Parallelization:
Scaling Correction: If fScaleN0AndBkg is true, χ² is multiplied by:
![\[\text{correction} = \text{packing} \times (t_{\rm res} \times 1000)
\]](form_86.png)
This accounts for the fact that data scales like pack×t_res, but errors scale like √(pack×t_res), ensuring correct χ² when normalizing to 1/ns.
| par | Parameter vector from MINUIT2 optimizer (1-based indexing in MSR file, but 0-based in this vector) |
Implements PRunBase.
Definition at line 208 of file PRunSingleHisto.cpp.
References fBackground, PRunBase::fData, fEndTimeBin, PRunBase::fFuncValues, PRunBase::fMetaData, PRunBase::fMsrInfo, fPacking, PRunBase::fRunInfo, fScaleN0AndBkg, fStartTimeBin, PRunBase::fTheory, PRunBase::fTimeResolution, MSR_PARAM_FUN_OFFSET, PMUON_LIFETIME, and PMUSR_UNDEFINED.
|
virtual |
Calculates expected χ² based on theory predictions.
Calculates expected χ² using theory as variance (alternative fit metric).
| par | Parameter vector from MINUIT |
Computes chi-square using the expected variance (theory value) instead of observed variance. This is sometimes called the "Neyman χ²" or "expected χ²":
![\[\chi^2_{\rm exp} = \sum_{i=t_{\rm start}}^{t_{\rm end}} \frac{[N_i - N_{\rm theo}(t_i)]^2}{N_{\rm theo}(t_i)}
\]](form_87.png)
Difference from Standard χ²:
This metric can be useful when:
Algorithm:
OpenMP Parallelization:
| par | Parameter vector from MINUIT2 optimizer |
Implements PRunBase.
Definition at line 323 of file PRunSingleHisto.cpp.
References fBackground, PRunBase::fData, fEndTimeBin, PRunBase::fFuncValues, PRunBase::fMetaData, PRunBase::fMsrInfo, fPacking, PRunBase::fRunInfo, fScaleN0AndBkg, fStartTimeBin, PRunBase::fTheory, PRunBase::fTimeResolution, MSR_PARAM_FUN_OFFSET, PMUON_LIFETIME, and PMUSR_UNDEFINED.
|
virtual |
Calculates maximum likelihood for Poisson-distributed histogram counts.
Calculates -2 log(maximum likelihood) for Poisson-distributed histogram data.
Computes -2ln(L) for low-count data (< 10-20 counts/bin). Superior to χ² when Gaussian approximation invalid.
| par | Parameter vector from MINUIT |
Computes the negative log-likelihood assuming Poisson statistics for each bin. This is the preferred fit metric for low-count data where Gaussian approximations break down. The likelihood function is:
![\[-2\ln\mathcal{L} = 2 \sum_{i} \left[ N_{\rm theo}(t_i) - N_i + N_i \ln\frac{N_i}{N_{\rm theo}(t_i)} \right]
\]](form_88.png)
This is derived from the Poisson probability:
![\[P(N_i | N_{\rm theo}) = \frac{N_{\rm theo}^{N_i} e^{-N_{\rm theo}}}{N_i!}
\]](form_89.png)
The factor of 2 makes -2ln(L) asymptotically distributed as χ² for large N, allowing use of standard error estimation from MINUIT.
Algorithm:
Edge Cases:
OpenMP Parallelization:
When to Use Maximum Likelihood vs. χ²:
| par | Parameter vector from MINUIT2 optimizer |
Implements PRunBase.
Definition at line 455 of file PRunSingleHisto.cpp.
References fBackground, PRunBase::fData, fEndTimeBin, PRunBase::fFuncValues, PRunBase::fMetaData, PRunBase::fMsrInfo, fPacking, PRunBase::fRunInfo, fScaleN0AndBkg, fStartTimeBin, PRunBase::fTheory, PRunBase::fTimeResolution, MSR_PARAM_FUN_OFFSET, PMUON_LIFETIME, and PMUSR_UNDEFINED.
|
virtual |
Calculates expected maximum likelihood.
Calculates expected -2 log(maximum likelihood) using G-test formulation.
| par | Parameter vector from MINUIT |
Computes an alternative form of the Poisson likelihood using only the data×ln(data/theo) term. This is related to the G-test (likelihood ratio test) and represents the "expected" contribution to the likelihood:
![\[-2\ln\mathcal{L}_{\rm exp} = 2 \sum_{i} N_i \ln\frac{N_i}{N_{\rm theo}(t_i)}
\]](form_90.png)
Difference from CalcMaxLikelihood():
The omitted (theo - data) term represents the "prior" expectation and is constant for a given theory. This formulation is sometimes used in:
Algorithm:
OpenMP Parallelization:
| par | Parameter vector from MINUIT2 optimizer |
Definition at line 590 of file PRunSingleHisto.cpp.
References fBackground, PRunBase::fData, fEndTimeBin, PRunBase::fFuncValues, PRunBase::fMetaData, PRunBase::fMsrInfo, fPacking, PRunBase::fRunInfo, fScaleN0AndBkg, fStartTimeBin, PRunBase::fTheory, PRunBase::fTimeResolution, MSR_PARAM_FUN_OFFSET, PMUON_LIFETIME, and PMUSR_UNDEFINED.
|
virtual |
Calculates start/end bin indices from fit time range.
Calculates the number of bins in the fit range and caches bin indices.
Converts fit range (μs) to bin indices, accounting for t0, time resolution, and packing. Updates fStartTimeBin, fEndTimeBin, fNoOfFitBins.
Converts the fit time range [fFitStartTime, fFitEndTime] to bin indices [fStartTimeBin, fEndTimeBin) and computes the total number of fit bins.
Algorithm:


where:
Edge Cases:
Definition at line 951 of file PRunSingleHisto.cpp.
References PRunBase::fData, fEndTimeBin, PRunBase::fFitEndTime, PRunBase::fFitStartTime, fNoOfFitBins, and fStartTimeBin.
Referenced by GetNoOfFitBins(), PrepareFitData(), PrepareRawViewData(), and PrepareViewData().
|
virtual |
Evaluates theory function at all data points or high-resolution grid.
Calculates theory curve N(t) for the current parameter values.
Calculates N_theory(t) = N₀·exp(-t/τ_μ)·P_theory(t) + B using THEORY block functions. Stores results in fData for χ² calculation.
Evaluates the single histogram theory function:
![\[N(t) = N_0 e^{-t/\tau_\mu} [1 + P(t)] + B
\]](form_91.png)
for all time bins in the data set, storing results in fData.fTheory. This is used for:
Algorithm:
Time Grid:
Implements PRunBase.
Definition at line 714 of file PRunSingleHisto.cpp.
References fBackground, PRunBase::fData, PRunBase::fFuncValues, PRunBase::fMetaData, PRunBase::fMsrInfo, PRunBase::fRunInfo, PRunBase::fTheory, MSR_PARAM_FUN_OFFSET, PMUON_LIFETIME, and PMUSR_UNDEFINED.
|
privatevirtual |
Estimates background from pre-t0 bins.
Estimates background count rate from pre-t0 bins.
Calculates background average and error from specified bin range (typically before t0). Sets fBackground member.
| histoNo | Histogram index |
Calculates the average background rate from bins before the muon pulse arrives. For pulsed beam facilities (PSI, RAL, TRIUMF), adjusts the background interval to be a multiple of the beam period to avoid systematic biases from beam structure.
Algorithm:
Beam periods:
Why adjust to beam period? Pulsed beams have time-dependent backgrounds from:
Averaging over complete beam cycles ensures unbiased background estimates by including all phases of the pulsed structure.
Edge cases:
| histoNo | Forward histogram number (for error messages, currently not directly used) |
Definition at line 2310 of file PRunSingleHisto.cpp.
References ACCEL_PERIOD_PSI, ACCEL_PERIOD_RAL, ACCEL_PERIOD_TRIUMF, fBackground, fForward, fPacking, PRunBase::fRunInfo, fScaleN0AndBkg, and PRunBase::fTimeResolution.
Referenced by PrepareFitData(), PrepareRawViewData(), and PrepareViewData().
|
privatevirtual |
Estimates initial normalization N₀ from histogram data.
Automatically estimates the normalization parameter N₀ from data.
Calculates N₀ estimate from histogram amplitude, used as starting value if N₀ is a fit parameter.
Provides an intelligent initial guess for N₀ to help MINUIT convergence. The estimate is based on the maximum count rate in the fit range, accounting for muon decay and background.
When estimation is performed:
When estimation is skipped:
Estimation algorithm:
Background handling:
Scaling adjustment: If fScaleN0AndBkg is true (normalizing to 1/ns), the estimate is divided by:
![\[\text{scale factor} = \text{packing} \times (t_{\rm res} \times 1000)
\]](form_106.png)
Definition at line 2174 of file PRunSingleHisto.cpp.
References fForward, PRunBase::fMsrInfo, fPacking, PRunBase::fRunInfo, fScaleN0AndBkg, PRunBase::fT0s, PRunBase::fTimeResolution, and PMUON_LIFETIME.
Referenced by PrepareFitData().
|
inlinevirtual |
Returns the estimated background level.
Definition at line 286 of file PRunSingleHisto.h.
References fBackground.
|
inlinevirtual |
Returns the last bin index in the fit range (exclusive).
Definition at line 298 of file PRunSingleHisto.h.
References fEndTimeBin.
|
virtual |
Returns the number of bins included in the fit range.
Returns the number of bins in the current fit range.
Used for degrees of freedom: ν = N_bins - N_params
Calculates (if not already done) and returns the number of data bins that will be included in the χ² or likelihood calculation. This is determined by the fit range [fFitStartTime, fFitEndTime] and the data time grid.
The calculation is performed by CalcNoOfFitBins(), which sets:
Definition at line 792 of file PRunSingleHisto.cpp.
References CalcNoOfFitBins(), and fNoOfFitBins.
|
inlinevirtual |
Returns the bin packing factor.
Definition at line 304 of file PRunSingleHisto.h.
References fPacking.
|
privatevirtual |
Determines data range (region of valid histogram data).
Determines the data range (first good bin / last good bin).
Establishes start/end bins for analysis from RUN block "data" entry. Data range is typically wider than fit range.
Establishes which histogram bins contain valid muon decay data by finding the "first good bin" (fgb) and "last good bin" (lgb). This range excludes:
Priority hierarchy (highest to lowest):
Auto-estimation (if not specified):
Validation:
Storage: Results are stored in:
These values are used by:
Definition at line 1962 of file PRunSingleHisto.cpp.
References fForward, fGoodBins, PRunBase::fMsrInfo, PRunBase::fRunInfo, PRunBase::fT0s, and PRunBase::fTimeResolution.
Referenced by PrepareData().
|
privatevirtual |
Determines fit range from MSR file settings.
Determines the fit range (start and end times for χ² calculation).
Extracts fit time window from RUN or GLOBAL block "fit" entry. Format: time-based (μs) or bin-based (fgb+n0 lgb-n1).
| globalBlock | GLOBAL block with default fit settings |
Establishes the time window [t_start, t_end] over which the fit will be performed. The fit range can be specified in two ways:
Specification methods:
fit <start> <end> in microsecondsfit 0.1 10.0 (fit from 0.1 to 10.0 μs after t0)fit fgb[+offset0] lgb[-offset1] in binsfit fgb+10 lgb-20 (fit from 10 bins after fgb to 20 bins before lgb)Priority hierarchy (highest to lowest):
fit <start> <end> in RUN blockfit fgb+n0 lgb-n1 in RUN blockfit <start> <end> in GLOBAL blockfit fgb+n0 lgb-n1 in GLOBAL blockBin-based conversion to time: When fit range is given in bins, it's converted to time:
![\[t_{\rm start} = (\text{fgb} + n_0 - t_0) \times \Delta t
\]](form_102.png)
![\[t_{\rm end} = (\text{lgb} - n_1 - t_0) \times \Delta t
\]](form_103.png)
where:
Storage and updates:
Fallback behavior: If no fit range is specified anywhere, uses the entire data range:
![\[t_{\rm start} = (\text{fgb} - t_0) \times \Delta t
\]](form_104.png)
![\[t_{\rm end} = (\text{lgb} - t_0) \times \Delta t
\]](form_105.png)
and prints a warning to std::cerr.
| globalBlock | Pointer to GLOBAL block from MSR file |
Definition at line 2096 of file PRunSingleHisto.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().
|
privatevirtual |
Determines and validates t0 values for histogram.
Determines time-zero (t0) values for all histograms using hierarchical fallback.
Extracts time-zero from RUN block, data file header, GLOBAL block, or automatic determination. Validates t0 is within histogram bounds.
| runData | Raw run data |
| globalBlock | GLOBAL block settings |
| histoNo | Vector of histogram indices |
Time-zero (t0) marks the muon arrival time in each detector histogram, the reference point from which decay time is measured. This method uses a priority system to find t0 values:
Priority hierarchy (highest to lowest):
For ADDRUN support: If multiple runs are added (fRunInfo->GetRunNameSize() > 1), this method also determines t0 values for each added run (fAddT0s) using the same hierarchy. Proper t0 alignment is essential for correct ADDRUN operation.
Algorithm:
Validation: After fallback, checks that each t0 satisfies:
![\[0 \leq t_0 \leq N_{\rm bins}
\]](form_101.png)
If validation fails, returns false with error message.
| runData | Pointer to raw run data handler for main run |
| globalBlock | Pointer to GLOBAL block from MSR file |
| histoNo | Vector of histogram indices (zero-based, after redGreen offset correction) |
Definition at line 1797 of file PRunSingleHisto.cpp.
References PRunBase::fAddT0s, PRunBase::fRawData, PRunBase::fRunInfo, PRunBase::fT0s, PRawRunData::GetDataBin(), PMsrGlobalBlock::GetT0Bin(), PRawRunData::GetT0Bin(), PRawRunData::GetT0BinEstimated(), and PMsrGlobalBlock::GetT0BinSize().
Referenced by PrepareData().
|
inlinevirtual |
Returns the N₀/background scaling mode.
Definition at line 310 of file PRunSingleHisto.h.
References fScaleN0AndBkg.
|
inlinevirtual |
Returns the first bin index in the fit range.
Definition at line 292 of file PRunSingleHisto.h.
References fStartTimeBin.
|
privatevirtual |
Determines if N₀ and background should be scaled to 1/ns.
Determines if N₀ and background should be normalized to 1/ns.
Checks time resolution and fitting preferences to decide scaling mode. Returns true for standard time bins (scale to 1/ns), false otherwise.
Checks whether N₀ and background parameters should be scaled to represent count rates per nanosecond (1/ns) rather than counts per packed bin.
Default behavior: Scaling is ENABLED (true)
This makes fitted parameters physically meaningful and independent of packing:
To disable scaling: Add to MSR file COMMAND block:
When to disable scaling:
Effect on fit parameters:
Implementation details: Scaling is applied in:
These operations cancel out mathematically but keep parameters in 1/ns units.
Definition at line 2426 of file PRunSingleHisto.cpp.
References PRunBase::fMsrInfo.
Referenced by PRunSingleHisto().
|
protectedvirtual |
Main data preparation orchestrator.
Main data preprocessing pipeline for single histogram runs.
Coordinates histogram loading and preprocessing: determines operation mode, calls PrepareFitData() or PrepareViewData(), validates success.
Orchestrates the complete data loading and preprocessing workflow:
ADDRUN t0 Alignment: When adding runs, histograms are aligned by their t0 values:
This ensures muon arrival times coincide across added runs.
Grouping t0 Alignment: When grouping histograms, they are aligned to the first histogram's t0:
Implements PRunBase.
Definition at line 1011 of file PRunSingleHisto.cpp.
References PRunBase::DeadTimeCorrection(), PRunBase::fAddT0s, 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, PrepareFitData(), PrepareRawViewData(), and PrepareViewData().
Referenced by PRunSingleHisto().
|
protectedvirtual |
Prepares histogram data for fitting.
Prepares histogram data for fitting (kFit mode).
Loads forward histogram, extracts metadata, determines t0, subtracts background, packs bins, propagates errors, sets up time grid and fit ranges.
| runData | Raw run data handler |
| histoNo | Histogram index in data file |
Performs final data transformations after PrepareData() has loaded and grouped the raw histogram data:
Packing Algorithm:
Background Handling Priority:
| runData | Pointer to raw run data handler (for metadata access) |
| histoNo | Forward histogram number (for background estimation) |
Definition at line 1213 of file PRunSingleHisto.cpp.
References CalcNoOfFitBins(), EstimateBkg(), EstimateN0(), PRunBase::fData, fForward, fGoodBins, PRunBase::fMsrInfo, fPacking, PRunBase::fRunInfo, fScaleN0AndBkg, PRunBase::fT0s, PRunBase::fTimeResolution, and PMUSR_UNDEFINED.
Referenced by PrepareData().
|
protectedvirtual |
Prepares raw histogram data for viewing (minimal processing).
Lighter-weight preprocessing for raw histogram visualization without background subtraction or full fitting infrastructure.
| runData | Raw run data handler |
| histoNo | Histogram index |
Take the pre-processed data (i.e. grouping and addrun are preformed) and form the histogram for viewing without any life time correction.
The following steps are preformed:
return:
| runData | raw run data handler |
| histoNo | forward histogram number |
Definition at line 1306 of file PRunSingleHisto.cpp.
References CalcNoOfFitBins(), EstimateBkg(), fBackground, PRunBase::fData, fForward, PRunBase::fFuncValues, fGoodBins, PRunBase::fMetaData, PRunBase::fMsrInfo, fPacking, PRunBase::fRunInfo, fScaleN0AndBkg, PRunBase::fT0s, fTheoAsData, PRunBase::fTheory, PRunBase::fTimeResolution, MSR_PARAM_FUN_OFFSET, PMUON_LIFETIME, and PMUSR_UNDEFINED.
Referenced by PrepareData().
|
protectedvirtual |
Prepares processed histogram data for viewing/plotting.
Similar to PrepareFitData() but optimized for visualization with potentially wider time range for context.
| runData | Raw run data handler |
| histoNo | Histogram index |
Take the pre-processed data (i.e. grouping and addrun are preformed) and form the histogram for viewing with life time correction, i.e. the exponential decay is removed.
The following steps are preformed:
Muon life time corrected data: Starting from
![\[ N(t) = N_0 e^{-t/\tau} [ 1 + A(t) ] + \mathrm{Bkg} \]](form_94.png)
it follows that
![\[ A(t) = (-1) + e^{+t/\tau}\, \frac{N(t)-\mathrm{Bkg}}{N_0}. \]](form_95.png)
For the error estimate only the statistical error of 
![\[ \Delta A(t) = \frac{e^{t/\tau}}{N_0}\,\sqrt{\frac{N(t)}{p}} \]](form_97.png)
where 

![\[ N(t_i) = \frac{1}{p}\, \sum_{j=i}^{i+p} n_j \]](form_99.png)
with 
return:
| runData | raw run data handler |
| histoNo | forward histogram number |
Definition at line 1495 of file PRunSingleHisto.cpp.
References CalcNoOfFitBins(), PRunBase::CalculateKaiserFilterCoeff(), EstimateBkg(), fBackground, PRunBase::fData, fForward, PRunBase::fFuncValues, fGoodBins, PRunBase::FilterTheo(), PRunBase::fMetaData, PRunBase::fMsrInfo, fPacking, PRunBase::fRunInfo, fScaleN0AndBkg, PRunBase::fT0s, fTheoAsData, PRunBase::fTheory, PRunBase::fTimeResolution, GAMMA_BAR_MUON, MSR_PARAM_FUN_OFFSET, PMUON_LIFETIME, PMUSR_UNDEFINED, RRF_UNIT_G, RRF_UNIT_kHz, RRF_UNIT_Mcs, RRF_UNIT_MHz, and RRF_UNIT_T.
Referenced by PrepareData().
|
virtual |
Sets fit range using bin-offset specification (COMMANDS block syntax).
Dynamically changes the fit range from COMMAND block instructions.
Format: "fit_range fgb+n0 lgb-n1"
| fitRange | String with bin offsets from good bin markers |
Parses and applies a FIT_RANGE command to modify the fit range on the fly, typically used during interactive fitting sessions or systematic scans.
Syntax (in COMMAND block):
where:
Two modes:
FIT_RANGE fgb lgb applies to all runsFIT_RANGE fgb₀ lgb₀ fgb₁ lgb₁ ... applies pair i to RUN block iAlgorithm:
Example:
| fitRange | String from COMMAND block containing FIT_RANGE specification |
Definition at line 845 of file PRunSingleHisto.cpp.
References PRunBase::fFitEndTime, PRunBase::fFitStartTime, fGoodBins, PRunBase::fRunNo, PRunBase::fT0s, and PRunBase::fTimeResolution.
|
private |
Background level in counts/bin (estimated from pre-t0 bins or fixed value from RUN block)
Definition at line 370 of file PRunSingleHisto.h.
Referenced by CalcChiSquare(), CalcChiSquareExpected(), CalcMaxLikelihood(), CalcMaxLikelihoodExpected(), CalcTheory(), EstimateBkg(), GetBackground(), PrepareRawViewData(), PrepareViewData(), PRunSingleHisto(), and PRunSingleHisto().
|
private |
Last bin index in fit range (exclusive: loop as i < fEndTimeBin)
Definition at line 379 of file PRunSingleHisto.h.
Referenced by CalcChiSquare(), CalcChiSquareExpected(), CalcMaxLikelihood(), CalcMaxLikelihoodExpected(), CalcNoOfFitBins(), GetEndTimeBin(), PRunSingleHisto(), and PRunSingleHisto().
|
private |
Forward detector histogram (background-corrected, packed)
Definition at line 376 of file PRunSingleHisto.h.
Referenced by EstimateBkg(), EstimateN0(), GetProperDataRange(), PrepareData(), PrepareFitData(), PrepareRawViewData(), PrepareViewData(), and ~PRunSingleHisto().
|
private |
Good bin markers for COMMANDS block: [0]=fgb (first good bin/t0), [1]=lgb (last good bin)
Definition at line 374 of file PRunSingleHisto.h.
Referenced by GetProperDataRange(), GetProperFitRange(), PrepareFitData(), PrepareRawViewData(), PrepareViewData(), PRunSingleHisto(), PRunSingleHisto(), and SetFitRangeBin().
|
private |
Number of bins within fit range (fStartTimeBin to fEndTimeBin)
Definition at line 369 of file PRunSingleHisto.h.
Referenced by CalcNoOfFitBins(), GetNoOfFitBins(), PRunSingleHisto(), and PRunSingleHisto().
|
private |
Bin packing factor (REQUIRED: from RUN or GLOBAL block)
Definition at line 371 of file PRunSingleHisto.h.
Referenced by CalcChiSquare(), CalcChiSquareExpected(), CalcMaxLikelihood(), CalcMaxLikelihoodExpected(), EstimateBkg(), EstimateN0(), GetPacking(), PrepareFitData(), PrepareRawViewData(), PrepareViewData(), PRunSingleHisto(), and PRunSingleHisto().
|
private |
Scaling mode: true = scale N₀ and B to 1/ns, false = leave as 1/bin (determined by IsScaleN0AndBkg())
Definition at line 368 of file PRunSingleHisto.h.
Referenced by CalcChiSquare(), CalcChiSquareExpected(), CalcMaxLikelihood(), CalcMaxLikelihoodExpected(), EstimateBkg(), EstimateN0(), GetScaleN0AndBkg(), PrepareFitData(), PrepareRawViewData(), PrepareViewData(), PRunSingleHisto(), and PRunSingleHisto().
|
private |
First bin index in fit range (inclusive, 0-based after packing)
Definition at line 378 of file PRunSingleHisto.h.
Referenced by CalcChiSquare(), CalcChiSquareExpected(), CalcMaxLikelihood(), CalcMaxLikelihoodExpected(), CalcNoOfFitBins(), GetStartTimeBin(), PRunSingleHisto(), and PRunSingleHisto().
|
private |
Theory mode: true = at data points, false = high-resolution grid for smooth Fourier transforms.
Definition at line 372 of file PRunSingleHisto.h.
Referenced by PrepareRawViewData(), PrepareViewData(), PRunSingleHisto(), and PRunSingleHisto().