Files
musrfit/src/classes/PRunListCollection.cpp
T
2026-02-13 13:59:49 +01:00

1696 lines
58 KiB
C++

/***************************************************************************
PRunListCollection.cpp
Author: Andreas Suter
e-mail: andreas.suter@psi.ch
***************************************************************************/
/***************************************************************************
* Copyright (C) 2007-2026 by Andreas Suter *
* andreas.suter@psi.ch *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <iostream>
#include "PRunListCollection.h"
//--------------------------------------------------------------------------
// Constructor
//--------------------------------------------------------------------------
/**
* \brief Constructor initializing the run collection manager.
*
* Creates an empty collection ready to receive processed run objects via Add() calls.
* The collection maintains separate lists for each fit type (single histogram, asymmetry,
* RRF variants, etc.) and dispatches operations to the appropriate lists.
*
* Initialization:
* - Stores pointers to MSR file handler and raw data handler (not owned)
* - Sets theory calculation mode flag (for plotting vs. fitting)
* - All run lists start empty; populated via subsequent Add() calls
*
* The typical workflow is:
* 1. Create PRunListCollection
* 2. Call Add() for each RUN block in MSR file
* 3. Use Get*Chisq() or Get*MaximumLikelihood() during fitting
* 4. Use Get*() accessors for visualization and analysis
*
* \param msrInfo Pointer to MSR file handler (must remain valid for object lifetime)
* \param data Pointer to raw data handler for loading histogram files
* \param theoAsData Theory calculation mode: true = at data points only, false = high-resolution grid
*
* \see Add() for adding processed runs to the collection
*/
PRunListCollection::PRunListCollection(PMsrHandler *msrInfo, PRunDataHandler *data, Bool_t theoAsData) :
fMsrInfo(msrInfo), fData(data), fTheoAsData(theoAsData)
{
}
//--------------------------------------------------------------------------
// Destructor
//--------------------------------------------------------------------------
/**
* \brief Destructor that cleans up all run objects.
*
* Systematically destroys all PRunBase-derived objects in the collection:
* 1. Calls CleanUp() on each run object to release internal resources
* 2. Explicitly calls destructor to free memory
* 3. Clears the vector to release the pointer storage
*
* This process is repeated for all seven run type lists:
* - Single histogram runs
* - Single histogram RRF runs
* - Asymmetry runs
* - Asymmetry RRF runs
* - β-NMR asymmetry runs
* - μ⁻ (mu-minus) runs
* - Non-μSR runs
*
* The MSR handler (fMsrInfo) and data handler (fData) are NOT deleted
* as they are owned by the calling code.
*/
PRunListCollection::~PRunListCollection()
{
for (UInt_t i=0; i<fRunSingleHistoList.size(); i++) {
fRunSingleHistoList[i]->CleanUp();
fRunSingleHistoList[i]->~PRunSingleHisto();
}
fRunSingleHistoList.clear();
for (UInt_t i=0; i<fRunSingleHistoRRFList.size(); i++) {
fRunSingleHistoRRFList[i]->CleanUp();
fRunSingleHistoRRFList[i]->~PRunSingleHistoRRF();
}
fRunSingleHistoRRFList.clear();
for (UInt_t i=0; i<fRunAsymmetryList.size(); i++) {
fRunAsymmetryList[i]->CleanUp();
fRunAsymmetryList[i]->~PRunAsymmetry();
}
fRunAsymmetryList.clear();
for (UInt_t i=0; i<fRunAsymmetryRRFList.size(); i++) {
fRunAsymmetryRRFList[i]->CleanUp();
fRunAsymmetryRRFList[i]->~PRunAsymmetryRRF();
}
fRunAsymmetryRRFList.clear();
for (UInt_t i=0; i<fRunAsymmetryBNMRList.size(); i++) {
fRunAsymmetryBNMRList[i]->CleanUp();
fRunAsymmetryBNMRList[i]->~PRunAsymmetryBNMR();
}
fRunAsymmetryBNMRList.clear();
for (UInt_t i=0; i<fRunMuMinusList.size(); i++) {
fRunMuMinusList[i]->CleanUp();
fRunMuMinusList[i]->~PRunMuMinus();
}
fRunMuMinusList.clear();
for (UInt_t i=0; i<fRunNonMusrList.size(); i++) {
fRunNonMusrList[i]->CleanUp();
fRunNonMusrList[i]->~PRunNonMusr();
}
fRunNonMusrList.clear();
}
//--------------------------------------------------------------------------
// Add (public)
//--------------------------------------------------------------------------
/**
* \brief Adds a processed run to the appropriate list based on fit type.
*
* Creates a new PRunBase-derived object for the specified MSR file RUN block and
* adds it to the appropriate type-specific list. The method performs fit type
* dispatching by:
* 1. Reading fit type from the RUN block (if specified)
* 2. Falling back to GLOBAL block fit type if not specified in RUN
* 3. Creating the appropriate run object based on fit type
* 4. Calling PrepareData() on the new object to load and process data
* 5. Checking validity and returning success/failure status
*
* Supported fit types and corresponding classes:
* - PRUN_SINGLE_HISTO → PRunSingleHisto
* - PRUN_SINGLE_HISTO_RRF → PRunSingleHistoRRF
* - PRUN_ASYMMETRY → PRunAsymmetry
* - PRUN_ASYMMETRY_RRF → PRunAsymmetryRRF
* - PRUN_ASYMMETRY_BNMR → PRunAsymmetryBNMR
* - PRUN_MU_MINUS → PRunMuMinus
* - PRUN_NON_MUSR → PRunNonMusr
*
* If data preprocessing fails (e.g., file not found, invalid t0, theory errors),
* the run object is still added to the list but marked as invalid, and this
* method returns false.
*
* \param runNo MSR file run number (0-based index into RUN blocks)
* \param tag Operation mode: kFit (for fitting), kView (for display/plotting)
* \return True if run was added and initialized successfully, false if initialization failed
*
* \see PRunBase::PrepareData() for data preprocessing details
*/
Bool_t PRunListCollection::Add(Int_t runNo, EPMusrHandleTag tag)
{
Bool_t success = true;
// try to get the fit type from the RUN block
Int_t fitType = (*fMsrInfo->GetMsrRunList())[runNo].GetFitType();
if (fitType == -1) { // fit type NOT given in the RUN block, check the GLOBAL block
fitType = (*fMsrInfo->GetMsrGlobal()).GetFitType();
}
switch (fitType) {
case PRUN_SINGLE_HISTO:
fRunSingleHistoList.push_back(new PRunSingleHisto(fMsrInfo, fData, runNo, tag, fTheoAsData));
if (!fRunSingleHistoList[fRunSingleHistoList.size()-1]->IsValid())
success = false;
break;
case PRUN_SINGLE_HISTO_RRF:
fRunSingleHistoRRFList.push_back(new PRunSingleHistoRRF(fMsrInfo, fData, runNo, tag, fTheoAsData));
if (!fRunSingleHistoRRFList[fRunSingleHistoRRFList.size()-1]->IsValid())
success = false;
break;
case PRUN_ASYMMETRY:
fRunAsymmetryList.push_back(new PRunAsymmetry(fMsrInfo, fData, runNo, tag, fTheoAsData));
if (!fRunAsymmetryList[fRunAsymmetryList.size()-1]->IsValid())
success = false;
break;
case PRUN_ASYMMETRY_RRF:
fRunAsymmetryRRFList.push_back(new PRunAsymmetryRRF(fMsrInfo, fData, runNo, tag, fTheoAsData));
if (!fRunAsymmetryRRFList[fRunAsymmetryRRFList.size()-1]->IsValid())
success = false;
break;
case PRUN_ASYMMETRY_BNMR:
fRunAsymmetryBNMRList.push_back(new PRunAsymmetryBNMR(fMsrInfo, fData, runNo, tag, fTheoAsData));
if (!fRunAsymmetryBNMRList[fRunAsymmetryBNMRList.size()-1]->IsValid())
success = false;
break;
case PRUN_MU_MINUS:
fRunMuMinusList.push_back(new PRunMuMinus(fMsrInfo, fData, runNo, tag, fTheoAsData));
if (!fRunMuMinusList[fRunMuMinusList.size()-1]->IsValid())
success = false;
break;
case PRUN_NON_MUSR:
fRunNonMusrList.push_back(new PRunNonMusr(fMsrInfo, fData, runNo, tag, fTheoAsData));
if (!fRunNonMusrList[fRunNonMusrList.size()-1]->IsValid())
success = false;
break;
default:
success = false;
break;
}
return success;
}
//--------------------------------------------------------------------------
// SetFitRange (public)
//--------------------------------------------------------------------------
/**
* \brief Sets fit range in bin units using string specification (COMMANDS block syntax).
*
* Parses and applies fit range specified in bin offsets from t0 markers.
* This method supports the COMMANDS block FIT_RANGE syntax used for dynamic
* range adjustments during optimization.
*
* String format:
* - Single range: "fit_range fgb+n0 lgb-n1"
* - Multiple ranges: "fit_range fgb0+n00 lgb0-n01 fgb1+n10 lgb1-n11 ..."
*
* Where:
* - fgb = first good bin (t0 marker from MSR file)
* - lgb = last good bin (end marker, often from data_range or automatic)
* - nXY = offset in bins (can be positive or negative)
*
* Example:
* - "fit_range fgb+10 lgb-20" → Start 10 bins after t0, end 20 bins before last good bin
* - For multiple runs, each gets its own fgb/lgb pair in sequence
*
* This method broadcasts the range specification to all run objects in all lists.
* Each run's SetFitRangeBin() method interprets the string based on its position
* in the MSR file.
*
* \param fitRange String holding fit range specification in bin offsets
*
* \see SetFitRange(PDoublePairVector) for time-based range specification
*/
void PRunListCollection::SetFitRange(const TString fitRange)
{
for (UInt_t i=0; i<fRunSingleHistoList.size(); i++)
fRunSingleHistoList[i]->SetFitRangeBin(fitRange);
for (UInt_t i=0; i<fRunSingleHistoRRFList.size(); i++)
fRunSingleHistoRRFList[i]->SetFitRangeBin(fitRange);
for (UInt_t i=0; i<fRunAsymmetryList.size(); i++)
fRunAsymmetryList[i]->SetFitRangeBin(fitRange);
for (UInt_t i=0; i<fRunAsymmetryRRFList.size(); i++)
fRunAsymmetryRRFList[i]->SetFitRangeBin(fitRange);
for (UInt_t i=0; i<fRunAsymmetryBNMRList.size(); i++)
fRunAsymmetryBNMRList[i]->SetFitRangeBin(fitRange);
for (UInt_t i=0; i<fRunMuMinusList.size(); i++)
fRunMuMinusList[i]->SetFitRangeBin(fitRange);
for (UInt_t i=0; i<fRunNonMusrList.size(); i++)
fRunNonMusrList[i]->SetFitRangeBin(fitRange);
}
//--------------------------------------------------------------------------
// SetFitRange (public)
//--------------------------------------------------------------------------
/**
* \brief Sets fit range in time units (microseconds from t0).
*
* Applies time-based fit ranges to all runs in the collection. This is the
* standard method for specifying fit ranges in the MSR file FIT block or
* during interactive range adjustments.
*
* Range specification modes:
* - <b>Global range:</b> fitRange.size() == 1
* - Same (start, end) time pair applies to all runs
* - Example: {(0.1, 10.0)} → All runs fit from 0.1 μs to 10.0 μs after t0
*
* - <b>Individual ranges:</b> fitRange.size() == number of MSR file runs
* - Each run gets its own (start, end) time pair
* - fitRange[i] corresponds to MSR file RUN block i
* - Example: {(0.1, 10.0), (0.2, 8.0)} → Run 0: 0.1-10.0 μs, Run 1: 0.2-8.0 μs
*
* Processing steps for each run:
* 1. SetFitRange() updates internal start/end time members
* 2. CalcNoOfFitBins() recalculates bin indices (fStartTimeBin, fEndTimeBin)
*
* The bin recalculation is necessary because the fit range is initially specified
* in time but χ² calculation operates on bin indices.
*
* \param fitRange Vector of (start_time, end_time) pairs in microseconds (μs) from t0
*
* \see SetFitRange(TString) for bin-based range specification
* \see PRunBase::CalcNoOfFitBins() for time-to-bin conversion
*/
void PRunListCollection::SetFitRange(const PDoublePairVector fitRange)
{
for (UInt_t i=0; i<fRunSingleHistoList.size(); i++) {
fRunSingleHistoList[i]->SetFitRange(fitRange);
fRunSingleHistoList[i]->CalcNoOfFitBins(); // needed to update fStartTimeBin, fEndTimeBin
}
for (UInt_t i=0; i<fRunSingleHistoRRFList.size(); i++) {
fRunSingleHistoRRFList[i]->SetFitRange(fitRange);
fRunSingleHistoRRFList[i]->CalcNoOfFitBins(); // needed to update fStartTimeBin, fEndTimeBin
}
for (UInt_t i=0; i<fRunAsymmetryList.size(); i++) {
fRunAsymmetryList[i]->SetFitRange(fitRange);
fRunAsymmetryList[i]->CalcNoOfFitBins(); // needed to update fStartTimeBin, fEndTimeBin
}
for (UInt_t i=0; i<fRunAsymmetryRRFList.size(); i++) {
fRunAsymmetryRRFList[i]->SetFitRange(fitRange);
fRunAsymmetryRRFList[i]->CalcNoOfFitBins(); // needed to update fStartTimeBin, fEndTimeBin
}
for (UInt_t i=0; i<fRunAsymmetryBNMRList.size(); i++) {
fRunAsymmetryBNMRList[i]->SetFitRange(fitRange);
fRunAsymmetryBNMRList[i]->CalcNoOfFitBins(); // needed to update fStartTimeBin, fEndTimeBin
}
for (UInt_t i=0; i<fRunMuMinusList.size(); i++) {
fRunMuMinusList[i]->SetFitRange(fitRange);
fRunMuMinusList[i]->CalcNoOfFitBins(); // needed to update fStartTimeBin, fEndTimeBin
}
for (UInt_t i=0; i<fRunNonMusrList.size(); i++)
fRunNonMusrList[i]->SetFitRange(fitRange);
}
//--------------------------------------------------------------------------
// GetSingleHistoChisq (public)
//--------------------------------------------------------------------------
/**
* \brief Calculates total χ² for all single histogram runs (global fit metric).
*
* Sums the chi-squared statistic over all single histogram runs in the collection:
* \f[ \chi^2_{\rm total} = \sum_{i=1}^{N_{\rm runs}} \chi^2_i \f]
*
* where each run's χ² is:
* \f[ \chi^2_i = \sum_{j=1}^{N_{\rm bins,i}} \frac{(y_j^{\rm data} - y_j^{\rm theory})^2}{\sigma_j^2} \f]
*
* This is the objective function minimized by MINUIT during global fitting of
* multiple single histogram runs. Called repeatedly during each fit iteration.
*
* \param par Parameter vector from MINUIT with current parameter values
* \return Total χ² summed over all single histogram runs
*
* \see PRunSingleHisto::CalcChiSquare() for per-run χ² calculation
*/
Double_t PRunListCollection::GetSingleHistoChisq(const std::vector<Double_t>& par) const
{
Double_t chisq = 0.0;
for (UInt_t i=0; i<fRunSingleHistoList.size(); i++)
chisq += fRunSingleHistoList[i]->CalcChiSquare(par);
return chisq;
}
//--------------------------------------------------------------------------
// GetSingleHistoRRFChisq (public)
//--------------------------------------------------------------------------
/**
* <p>Calculates chi-square of <em>all</em> single histogram RRF runs of a msr-file.
*
* <b>return:</b>
* - chi-square of all single histogram RRF runs of the msr-file
*
* \param par fit parameter vector
*/
Double_t PRunListCollection::GetSingleHistoRRFChisq(const std::vector<Double_t>& par) const
{
Double_t chisq = 0.0;
for (UInt_t i=0; i<fRunSingleHistoRRFList.size(); i++)
chisq += fRunSingleHistoRRFList[i]->CalcChiSquare(par);
return chisq;
}
//--------------------------------------------------------------------------
// GetAsymmetryChisq (public)
//--------------------------------------------------------------------------
/**
* \brief Calculates total χ² for all asymmetry runs (global fit metric).
*
* Sums the chi-squared statistic over all asymmetry runs in the collection.
* For asymmetry fits, χ² is calculated from the asymmetry values:
* \f[ A_i = \frac{F_i - \alpha B_i}{F_i + \alpha B_i} \f]
*
* with proper error propagation. This is the objective function for global
* asymmetry fits involving multiple runs (e.g., temperature or field scans).
*
* \param par Parameter vector from MINUIT with current parameter values
* \return Total χ² summed over all asymmetry runs
*
* \see PRunAsymmetry::CalcChiSquare() for per-run asymmetry χ² calculation
*/
Double_t PRunListCollection::GetAsymmetryChisq(const std::vector<Double_t>& par) const
{
Double_t chisq = 0.0;
for (UInt_t i=0; i<fRunAsymmetryList.size(); i++)
chisq += fRunAsymmetryList[i]->CalcChiSquare(par);
return chisq;
}
//--------------------------------------------------------------------------
// GetAsymmetryRRFChisq (public)
//--------------------------------------------------------------------------
/**
* <p>Calculates chi-square of <em>all</em> asymmetry RRF runs of a msr-file.
*
* <b>return:</b>
* - chi-square of all asymmetry RRF runs of the msr-file
*
* \param par fit parameter vector
*/
Double_t PRunListCollection::GetAsymmetryRRFChisq(const std::vector<Double_t>& par) const
{
Double_t chisq = 0.0;
for (UInt_t i=0; i<fRunAsymmetryRRFList.size(); i++)
chisq += fRunAsymmetryRRFList[i]->CalcChiSquare(par);
return chisq;
}
//--------------------------------------------------------------------------
// GetAsymmetryBNMRChisq (public)
//--------------------------------------------------------------------------
/**
* <p>Calculates chi-square of <em>all</em> asymmetry BNMR runs of a msr-file.
*
* <b>return:</b>
* - chi-square of all asymmetry BNMR runs of the msr-file
*
* \param par fit parameter vector
*/
Double_t PRunListCollection::GetAsymmetryBNMRChisq(const std::vector<Double_t>& par) const
{
Double_t chisq = 0.0;
for (UInt_t i=0; i<fRunAsymmetryBNMRList.size(); i++)
chisq += fRunAsymmetryBNMRList[i]->CalcChiSquare(par);
return chisq;
}
//--------------------------------------------------------------------------
// GetMuMinusChisq (public)
//--------------------------------------------------------------------------
/**
* <p>Calculates chi-square of <em>all</em> mu minus runs of a msr-file.
*
* <b>return:</b>
* - chi-square of all mu minus runs of the msr-file
*
* \param par fit parameter vector
*/
Double_t PRunListCollection::GetMuMinusChisq(const std::vector<Double_t>& par) const
{
Double_t chisq = 0.0;
for (UInt_t i=0; i<fRunMuMinusList.size(); i++)
chisq += fRunMuMinusList[i]->CalcChiSquare(par);
return chisq;
}
//--------------------------------------------------------------------------
// GetNonMusrChisq (public)
//--------------------------------------------------------------------------
/**
* <p>Calculates chi-square of <em>all</em> non-muSR runs of a msr-file.
*
* <b>return:</b>
* - chi-square of all non-muSR runs of the msr-file
*
* \param par fit parameter vector
*/
Double_t PRunListCollection::GetNonMusrChisq(const std::vector<Double_t>& par) const
{
Double_t chisq = 0.0;
for (UInt_t i=0; i<fRunNonMusrList.size(); i++)
chisq += fRunNonMusrList[i]->CalcChiSquare(par);
return chisq;
}
//--------------------------------------------------------------------------
// GetSingleRunChisqExpected (public)
//--------------------------------------------------------------------------
/**
* <p>Calculates expected chi-square of the run block index idx of a msr-file.
* Currently this is only possible for Single Histo, and Mu Minus fits.
*
* <b>return:</b>
* - expected chi-square of for a single run block
*
* \param par fit parameter vector
* \param idx run block index
*/
Double_t PRunListCollection::GetSingleRunChisqExpected(const std::vector<Double_t>& par, const UInt_t idx) const
{
Double_t expectedChisq = 0.0;
if (idx > fMsrInfo->GetMsrRunList()->size()) {
std::cerr << ">> PRunListCollection::GetSingleRunChisqExpected() **ERROR** idx=" << idx << " is out of range [0.." << fMsrInfo->GetMsrRunList()->size() << "[" << std::endl << std::endl;
return expectedChisq;
}
UInt_t subIdx = 0;
Int_t type = fMsrInfo->GetMsrRunList()->at(idx).GetFitType();
if (type == -1) { // i.e. not found in the RUN block, try the GLOBAL block
type = fMsrInfo->GetMsrGlobal()->GetFitType();
subIdx = idx;
} else { // found in the RUN block
// count how many entries of this fit-type are present up to idx
for (UInt_t i=0; i<idx; i++) {
if (fMsrInfo->GetMsrRunList()->at(i).GetFitType() == type)
subIdx++;
}
}
// return the chisq of the single run
switch (type) {
case PRUN_SINGLE_HISTO:
expectedChisq = fRunSingleHistoList[subIdx]->CalcChiSquareExpected(par);
break;
case PRUN_SINGLE_HISTO_RRF:
expectedChisq = fRunSingleHistoRRFList[subIdx]->CalcChiSquareExpected(par);
break;
case PRUN_ASYMMETRY:
expectedChisq = fRunAsymmetryList[subIdx]->CalcChiSquareExpected(par);
break;
case PRUN_ASYMMETRY_RRF:
expectedChisq = fRunAsymmetryRRFList[subIdx]->CalcChiSquareExpected(par);
break;
case PRUN_ASYMMETRY_BNMR:
expectedChisq = fRunAsymmetryBNMRList[subIdx]->CalcChiSquareExpected(par);
break;
case PRUN_MU_MINUS:
expectedChisq = fRunMuMinusList[subIdx]->CalcChiSquareExpected(par);
break;
default:
break;
}
return expectedChisq;
}
//--------------------------------------------------------------------------
// GetSingleRunChisq (public)
//--------------------------------------------------------------------------
/**
* <p>Calculates chi-square of a single run-block entry of the msr-file.
*
* <b>return:</b>
* - chi-square of single run-block entry with index idx
*
* \param par fit parameter vector
* \param idx run block index
*/
Double_t PRunListCollection::GetSingleRunChisq(const std::vector<Double_t>& par, const UInt_t idx) const
{
Double_t chisq = 0.0;
if (idx > fMsrInfo->GetMsrRunList()->size()) {
std::cerr << ">> PRunListCollection::GetSingleRunChisq() **ERROR** idx=" << idx << " is out of range [0.." << fMsrInfo->GetMsrRunList()->size() << "[" << std::endl << std::endl;
return chisq;
}
Int_t subIdx = 0;
Int_t type = fMsrInfo->GetMsrRunList()->at(idx).GetFitType();
if (type == -1) { // i.e. not found in the RUN block, try the GLOBAL block
type = fMsrInfo->GetMsrGlobal()->GetFitType();
subIdx = idx;
} else { // found in the RUN block
// count how many entries of this fit-type are present up to idx
for (UInt_t i=0; i<idx; i++) {
if (fMsrInfo->GetMsrRunList()->at(i).GetFitType() == type)
subIdx++;
}
}
// return the chisq of the single run
switch (type) {
case PRUN_SINGLE_HISTO:
chisq = fRunSingleHistoList[subIdx]->CalcChiSquare(par);
break;
case PRUN_SINGLE_HISTO_RRF:
chisq = fRunSingleHistoRRFList[subIdx]->CalcChiSquare(par);
break;
case PRUN_ASYMMETRY:
chisq = fRunAsymmetryList[subIdx]->CalcChiSquare(par);
break;
case PRUN_ASYMMETRY_RRF:
chisq = fRunAsymmetryRRFList[subIdx]->CalcChiSquare(par);
break;
case PRUN_ASYMMETRY_BNMR:
chisq = fRunAsymmetryBNMRList[subIdx]->CalcChiSquare(par);
break;
case PRUN_MU_MINUS:
chisq = fRunMuMinusList[subIdx]->CalcChiSquare(par);
break;
case PRUN_NON_MUSR:
chisq = fRunNonMusrList[subIdx]->CalcChiSquare(par);
break;
default:
break;
}
return chisq;
}
//--------------------------------------------------------------------------
// GetSingleHistoMaximumLikelihood (public)
//--------------------------------------------------------------------------
/**
* <p>Calculates log max-likelihood of <em>all</em> single histogram runs of a msr-file.
*
* <b>return:</b>
* - log max-likelihood of all single histogram runs of the msr-file
*
* \param par fit parameter vector
*/
Double_t PRunListCollection::GetSingleHistoMaximumLikelihood(const std::vector<Double_t>& par) const
{
Double_t mlh = 0.0;
for (UInt_t i=0; i<fRunSingleHistoList.size(); i++)
mlh += fRunSingleHistoList[i]->CalcMaxLikelihood(par);
return mlh;
}
//--------------------------------------------------------------------------
// GetSingleHistoRRFMaximumLikelihood (public)
//--------------------------------------------------------------------------
/**
* <p>Calculates log max-likelihood of <em>all</em> single histogram RRF runs of a msr-file.
*
* <b>return:</b>
* - log max-likelihood of all single histogram runs of the msr-file
*
* \param par fit parameter vector
*/
Double_t PRunListCollection::GetSingleHistoRRFMaximumLikelihood(const std::vector<Double_t>& par) const
{
Double_t mlh = 0.0;
for (UInt_t i=0; i<fRunSingleHistoRRFList.size(); i++)
mlh += fRunSingleHistoRRFList[i]->CalcMaxLikelihood(par);
return mlh;
}
//--------------------------------------------------------------------------
// GetAsymmetryMaximumLikelihood (public)
//--------------------------------------------------------------------------
/**
* <p> Since it is not clear yet how to handle asymmetry fits with max likelihood
* the chi square will be used!
*
* <b>return:</b>
* - chi-square of all asymmetry runs of the msr-file
*
* \param par fit parameter vector
*/
Double_t PRunListCollection::GetAsymmetryMaximumLikelihood(const std::vector<Double_t>& par) const
{
Double_t mlh = 0.0;
for (UInt_t i=0; i<fRunAsymmetryList.size(); i++)
mlh += fRunAsymmetryList[i]->CalcChiSquare(par);
return mlh;
}
//--------------------------------------------------------------------------
// GetAsymmetryRRFMaximumLikelihood (public)
//--------------------------------------------------------------------------
/**
* <p> Since it is not clear yet how to handle asymmetry fits with max likelihood
* the chi square will be used!
*
* <b>return:</b>
* - chi-square of all asymmetry RRF runs of the msr-file
*
* \param par fit parameter vector
*/
Double_t PRunListCollection::GetAsymmetryRRFMaximumLikelihood(const std::vector<Double_t>& par) const
{
Double_t mlh = 0.0;
for (UInt_t i=0; i<fRunAsymmetryRRFList.size(); i++)
mlh += fRunAsymmetryRRFList[i]->CalcChiSquare(par);
return mlh;
}
//--------------------------------------------------------------------------
// GetAsymmetryBNMRMaximumLikelihood (public)
//--------------------------------------------------------------------------
/**
* <p> Since it is not clear yet how to handle asymmetry fits with max likelihood
* the chi square will be used!
*
* <b>return:</b>
* - chi-square of all asymmetry BNMR runs of the msr-file
*
* \param par fit parameter vector
*/
Double_t PRunListCollection::GetAsymmetryBNMRMaximumLikelihood(const std::vector<Double_t>& par) const
{
Double_t mlh = 0.0;
for (UInt_t i=0; i<fRunAsymmetryBNMRList.size(); i++)
mlh += fRunAsymmetryBNMRList[i]->CalcChiSquare(par);
return mlh;
}
//--------------------------------------------------------------------------
// GetMuMinusMaximumLikelihood (public)
//--------------------------------------------------------------------------
/**
* <p>Calculates log max-likelihood of <em>all</em> mu minus runs of a msr-file.
*
* <b>return:</b>
* - log max-likelihood of all mu minus runs of the msr-file
*
* \param par fit parameter vector
*/
Double_t PRunListCollection::GetMuMinusMaximumLikelihood(const std::vector<Double_t>& par) const
{
Double_t mlh = 0.0;
for (UInt_t i=0; i<fRunMuMinusList.size(); i++)
mlh += fRunMuMinusList[i]->CalcMaxLikelihood(par);
return mlh;
}
//--------------------------------------------------------------------------
// GetNonMusrMaximumLikelihood (public)
//--------------------------------------------------------------------------
/**
* <p> Since it is not clear yet how to handle non musr fits with max likelihood
* the chi square will be used!
*
* <b>return:</b>
* - chi-square of all asymmetry runs of the msr-file
*
* \param par fit parameter vector
*/
Double_t PRunListCollection::GetNonMusrMaximumLikelihood(const std::vector<Double_t>& par) const
{
Double_t mlh = 0.0;
for (UInt_t i=0; i<fRunNonMusrList.size(); i++)
mlh += fRunNonMusrList[i]->CalcChiSquare(par);
return mlh;
}
//--------------------------------------------------------------------------
// GetSingleRunMaximumLikelihoodExpected (public)
//--------------------------------------------------------------------------
/**
* <p>Calculates expected mlh of the run block index idx of a msr-file.
*
* <b>return:</b>
* - expected mlh of for a single run block
*
* \param par fit parameter vector
* \param idx run block index
*/
Double_t PRunListCollection::GetSingleRunMaximumLikelihoodExpected(const std::vector<Double_t>& par, const UInt_t idx) const
{
Double_t expected_mlh = 0.0;
if (idx > fMsrInfo->GetMsrRunList()->size()) {
std::cerr << ">> PRunListCollection::GetSingleRunMaximumLikelihoodExpected() **ERROR** idx=" << idx << " is out of range [0.." << fMsrInfo->GetMsrRunList()->size() << "[" << std::endl << std::endl;
return expected_mlh;
}
UInt_t subIdx = 0;
Int_t type = fMsrInfo->GetMsrRunList()->at(idx).GetFitType();
if (type == -1) { // i.e. not found in the RUN block, try the GLOBAL block
type = fMsrInfo->GetMsrGlobal()->GetFitType();
subIdx = idx;
} else { // found in the RUN block
// count how many entries of this fit-type are present up to idx
for (UInt_t i=0; i<idx; i++) {
if (fMsrInfo->GetMsrRunList()->at(i).GetFitType() == type)
subIdx++;
}
}
// return the mlh of the single run
switch (type) {
case PRUN_SINGLE_HISTO:
expected_mlh = fRunSingleHistoList[subIdx]->CalcMaxLikelihoodExpected(par);
break;
default:
break;
}
return expected_mlh;
}
//--------------------------------------------------------------------------
// GetSingleRunMaximumLikelihood (public)
//--------------------------------------------------------------------------
/**
* <p>Calculates mlh of a single run-block entry of the msr-file.
*
* <b>return:</b>
* - mlh of single run-block entry with index idx
*
* \param par fit parameter vector
* \param idx run block index
*/
Double_t PRunListCollection::GetSingleRunMaximumLikelihood(const std::vector<Double_t>& par, const UInt_t idx) const
{
Double_t mlh = 0.0;
if (idx > fMsrInfo->GetMsrRunList()->size()) {
std::cerr << ">> PRunListCollection::GetSingleRunMaximumLikelihood() **ERROR** idx=" << idx << " is out of range [0.." << fMsrInfo->GetMsrRunList()->size() << "[" << std::endl << std::endl;
return mlh;
}
Int_t subIdx = 0;
Int_t type = fMsrInfo->GetMsrRunList()->at(idx).GetFitType();
if (type == -1) { // i.e. not found in the RUN block, try the GLOBAL block
type = fMsrInfo->GetMsrGlobal()->GetFitType();
subIdx = idx;
} else { // found in the RUN block
// count how many entries of this fit-type are present up to idx
for (UInt_t i=0; i<idx; i++) {
if (fMsrInfo->GetMsrRunList()->at(i).GetFitType() == type)
subIdx++;
}
}
// return the mlh of the single run
switch (type) {
case PRUN_SINGLE_HISTO:
mlh = fRunSingleHistoList[subIdx]->CalcMaxLikelihood(par);
break;
default:
break;
}
return mlh;
}
//--------------------------------------------------------------------------
// GetNoOfBinsFitted (public)
//--------------------------------------------------------------------------
/**
* <p>Number of bins in run block idx to be fitted. Only used for single histogram
* fitting together with the expected chisq.
*
* <b>return:</b>
* - number of bins fitted.
*
* \param idx run block index
*/
UInt_t PRunListCollection::GetNoOfBinsFitted(const UInt_t idx) const
{
UInt_t result = 0;
if (idx > fMsrInfo->GetMsrRunList()->size()) {
std::cerr << ">> PRunListCollection::GetNoOfBinsFitted() **ERROR** idx=" << idx << " is out of range [0.." << fMsrInfo->GetMsrRunList()->size() << "[" << std::endl << std::endl;
return result;
}
Int_t type = fMsrInfo->GetMsrRunList()->at(idx).GetFitType();
if (type == -1) { // i.e. not found in the RUN block, try the GLOBAL block
type = fMsrInfo->GetMsrGlobal()->GetFitType();
}
// count how many entries of this fit-type are present up to idx
UInt_t subIdx = 0;
for (UInt_t i=0; i<idx; i++) {
if ((fMsrInfo->GetMsrRunList()->at(i).GetFitType() == type) ||
(fMsrInfo->GetMsrRunList()->at(i).GetFitType() == -1)) // the -1 is needed if there is a global section
subIdx++;
}
// return the chisq of the single run
switch (type) {
case PRUN_SINGLE_HISTO:
result = fRunSingleHistoList[subIdx]->GetNoOfFitBins();
break;
case PRUN_SINGLE_HISTO_RRF:
result = fRunSingleHistoRRFList[subIdx]->GetNoOfFitBins();
break;
case PRUN_ASYMMETRY:
result = fRunAsymmetryList[subIdx]->GetNoOfFitBins();
break;
case PRUN_ASYMMETRY_RRF:
result = fRunAsymmetryRRFList[subIdx]->GetNoOfFitBins();
break;
case PRUN_ASYMMETRY_BNMR:
result = fRunAsymmetryBNMRList[subIdx]->GetNoOfFitBins();
break;
case PRUN_MU_MINUS:
result = fRunMuMinusList[subIdx]->GetNoOfFitBins();
break;
case PRUN_NON_MUSR:
result = fRunNonMusrList[subIdx]->GetNoOfFitBins();
break;
default:
break;
}
return result;
}
//--------------------------------------------------------------------------
// GetTotalNoOfBinsFitted (public)
//--------------------------------------------------------------------------
/**
* <p>Counts the total number of bins to be fitted.
*
* <b>return:</b>
* - total number of bins fitted.
*/
UInt_t PRunListCollection::GetTotalNoOfBinsFitted() const
{
UInt_t counts = 0;
for (UInt_t i=0; i<fRunSingleHistoList.size(); i++)
counts += fRunSingleHistoList[i]->GetNoOfFitBins();
for (UInt_t i=0; i<fRunSingleHistoRRFList.size(); i++)
counts += fRunSingleHistoRRFList[i]->GetNoOfFitBins();
for (UInt_t i=0; i<fRunAsymmetryList.size(); i++)
counts += fRunAsymmetryList[i]->GetNoOfFitBins();
for (UInt_t i=0; i<fRunAsymmetryRRFList.size(); i++)
counts += fRunAsymmetryRRFList[i]->GetNoOfFitBins();
for (UInt_t i=0; i<fRunAsymmetryBNMRList.size(); i++)
counts += fRunAsymmetryBNMRList[i]->GetNoOfFitBins();
for (UInt_t i=0; i<fRunMuMinusList.size(); i++)
counts += fRunMuMinusList[i]->GetNoOfFitBins();
for (UInt_t i=0; i<fRunNonMusrList.size(); i++)
counts += fRunNonMusrList[i]->GetNoOfFitBins();
return counts;
}
//--------------------------------------------------------------------------
// GetSingleHisto (public)
//--------------------------------------------------------------------------
/**
* <p>Get a processed single histogram data set.
*
* <b>return:</b>
* - pointer to the run data set (processed data) if data set is found
* - null pointer otherwise
*
* \param index msr-file run index
* \param tag kIndex -> data at index, kRunNo -> data of given run no
*/
PRunData* PRunListCollection::GetSingleHisto(UInt_t index, EDataSwitch tag)
{
PRunData *data = nullptr;
switch (tag) {
case kIndex:
if (index >= fRunSingleHistoList.size()) {
std::cerr << std::endl << ">> PRunListCollection::GetSingleHisto(): **ERROR** index = " << index << " out of bounds";
std::cerr << std::endl;
return nullptr;
}
fRunSingleHistoList[index]->CalcTheory();
data = fRunSingleHistoList[index]->GetData();
break;
case kRunNo:
for (UInt_t i=0; i<fRunSingleHistoList.size(); i++) {
if (fRunSingleHistoList[i]->GetRunNo() == index) {
data = fRunSingleHistoList[i]->GetData();
break;
}
}
break;
default: // error
break;
}
return data;
}
//--------------------------------------------------------------------------
// GetSingleHistoRRF (public)
//--------------------------------------------------------------------------
/**
* <p>Get a processed single histogram RRF data set.
*
* <b>return:</b>
* - pointer to the run data set (processed data) if data set is found
* - null pointer otherwise
*
* \param index msr-file run index
* \param tag kIndex -> data at index, kRunNo -> data of given run no
*/
PRunData* PRunListCollection::GetSingleHistoRRF(UInt_t index, EDataSwitch tag)
{
PRunData *data = nullptr;
switch (tag) {
case kIndex:
if (index >= fRunSingleHistoRRFList.size()) {
std::cerr << std::endl << ">> PRunListCollection::GetSingleHistoRRF(): **ERROR** index = " << index << " out of bounds";
std::cerr << std::endl;
return nullptr;
}
fRunSingleHistoRRFList[index]->CalcTheory();
data = fRunSingleHistoRRFList[index]->GetData();
break;
case kRunNo:
for (UInt_t i=0; i<fRunSingleHistoRRFList.size(); i++) {
if (fRunSingleHistoRRFList[i]->GetRunNo() == index) {
data = fRunSingleHistoRRFList[i]->GetData();
break;
}
}
break;
default: // error
break;
}
return data;
}
//--------------------------------------------------------------------------
// GetAsymmetry (public)
//--------------------------------------------------------------------------
/**
* <p>Get a processed asymmetry data set.
*
* <b>return:</b>
* - pointer to the run data set (processed data) if data set is found
* - null pointer otherwise
*
* \param index msr-file run index
* \param tag kIndex -> data at index, kRunNo -> data of given run no
*/
PRunData* PRunListCollection::GetAsymmetry(UInt_t index, EDataSwitch tag)
{
PRunData *data = nullptr;
switch (tag) {
case kIndex: // called from musrfit when dumping the data
if (index > fRunAsymmetryList.size()) {
std::cerr << std::endl << ">> PRunListCollection::GetAsymmetry(): **ERROR** index = " << index << " out of bounds";
std::cerr << std::endl;
return nullptr;
}
fRunAsymmetryList[index]->CalcTheory();
data = fRunAsymmetryList[index]->GetData();
break;
case kRunNo: // called from PMusrCanvas
for (UInt_t i=0; i<fRunAsymmetryList.size(); i++) {
if (fRunAsymmetryList[i]->GetRunNo() == index) {
data = fRunAsymmetryList[i]->GetData();
break;
}
}
break;
default: // error
break;
}
return data;
}
//--------------------------------------------------------------------------
// GetAsymmetryBNMR (public)
//--------------------------------------------------------------------------
/**
* <p>Get a processed asymmetry from beta-NMR data set.
*
* <b>return:</b>
* - pointer to the run data set (processed data) if data set is found
* - null pointer otherwise
*
* \param index msr-file run index
* \param tag kIndex -> data at index, kRunNo -> data of given run no
*/
PRunData* PRunListCollection::GetAsymmetryBNMR(UInt_t index, EDataSwitch tag)
{
PRunData *data = 0;
switch (tag) {
case kIndex: // called from musrfit when dumping the data
if (index > fRunAsymmetryBNMRList.size()) {
std::cerr << std::endl << ">> PRunListCollection::GetAsymmetryBNMR(): **ERROR** index = " << index << " out of bounds";
std::cerr << std::endl;
return 0;
}
fRunAsymmetryBNMRList[index]->CalcTheory();
data = fRunAsymmetryBNMRList[index]->GetData();
break;
case kRunNo: // called from PMusrCanvas
for (UInt_t i=0; i<fRunAsymmetryBNMRList.size(); i++) {
if (fRunAsymmetryBNMRList[i]->GetRunNo() == index) {
data = fRunAsymmetryBNMRList[i]->GetData();
break;
}
}
break;
default: // error
break;
}
return data;
}
//--------------------------------------------------------------------------
// GetAsymmetryRRF (public)
//--------------------------------------------------------------------------
/**
* <p>Get a processed asymmetry RRF data set.
*
* <b>return:</b>
* - pointer to the run data set (processed data) if data set is found
* - null pointer otherwise
*
* \param index msr-file run index
* \param tag kIndex -> data at index, kRunNo -> data of given run no
*/
PRunData* PRunListCollection::GetAsymmetryRRF(UInt_t index, EDataSwitch tag)
{
PRunData *data = nullptr;
switch (tag) {
case kIndex: // called from musrfit when dumping the data
if (index > fRunAsymmetryRRFList.size()) {
std::cerr << std::endl << ">> PRunListCollection::GetAsymmetryRRF(): **ERROR** index = " << index << " out of bounds";
std::cerr << std::endl;
return nullptr;
}
fRunAsymmetryRRFList[index]->CalcTheory();
data = fRunAsymmetryRRFList[index]->GetData();
break;
case kRunNo: // called from PMusrCanvas
for (UInt_t i=0; i<fRunAsymmetryRRFList.size(); i++) {
if (fRunAsymmetryRRFList[i]->GetRunNo() == index) {
data = fRunAsymmetryRRFList[i]->GetData();
break;
}
}
break;
default: // error
break;
}
return data;
}
//--------------------------------------------------------------------------
// GetMuMinus (public)
//--------------------------------------------------------------------------
/**
* <p>Get a processed mu minus data set.
*
* <b>return:</b>
* - pointer to the run data set (processed data) if data set is found
* - null pointer otherwise
*
* \param index msr-file run index
* \param tag kIndex -> data at index, kRunNo -> data of given run no
*/
PRunData* PRunListCollection::GetMuMinus(UInt_t index, EDataSwitch tag)
{
PRunData *data = nullptr;
switch (tag) {
case kIndex:
if (index > fRunMuMinusList.size()) {
std::cerr << std::endl << ">> PRunListCollection::GetMuMinus(): **ERROR** index = " << index << " out of bounds";
std::cerr << std::endl;
return nullptr;
}
fRunMuMinusList[index]->CalcTheory();
data = fRunMuMinusList[index]->GetData();
break;
case kRunNo:
for (UInt_t i=0; i<fRunMuMinusList.size(); i++) {
if (fRunMuMinusList[i]->GetRunNo() == index) {
data = fRunMuMinusList[i]->GetData();
break;
}
}
break;
default: // error
break;
}
return data;
}
//--------------------------------------------------------------------------
// GetNonMusr (public)
//--------------------------------------------------------------------------
/**
* <p>Get a processed non-muSR data set.
*
* <b>return:</b>
* - pointer to the run data set (processed data) if data set is found
* - null pointer otherwise
*
* \param index msr-file run index
* \param tag kIndex -> data at index, kRunNo -> data of given run no
*/
PRunData* PRunListCollection::GetNonMusr(UInt_t index, EDataSwitch tag)
{
PRunData *data = nullptr;
switch (tag) {
case kIndex:
if (index > fRunNonMusrList.size()) {
std::cerr << std::endl << ">> PRunListCollection::GetNonMusr(): **ERROR** index = " << index << " out of bounds";
std::cerr << std::endl;
return nullptr;
}
break;
case kRunNo:
for (UInt_t i=0; i<fRunNonMusrList.size(); i++) {
if (fRunNonMusrList[i]->GetRunNo() == index) {
data = fRunNonMusrList[i]->GetData();
break;
}
}
break;
default: // error
break;
}
return data;
}
//--------------------------------------------------------------------------
// GetTemp (public)
//--------------------------------------------------------------------------
/**
* <p>Get the temperature from the data set.
*
* <b>return:</b>
* - temperature pair (T, dT) vector from temperatures stored in the data file.
*
* \param runName name of the run from which to extract the temperature
*/
const PDoublePairVector* PRunListCollection::GetTemp(const TString &runName) const
{
return fData->GetRunData(runName)->GetTemperature();
}
//--------------------------------------------------------------------------
// GetField (public)
//--------------------------------------------------------------------------
/**
* <p>Get the magnetic field from the data set.
*
* <b>return:</b>
* - magnetic field stored in the data file.
*
* \param runName name of the run from which to extract the magnetic field
*/
Double_t PRunListCollection::GetField(const TString &runName) const
{
return fData->GetRunData(runName)->GetField();
}
//--------------------------------------------------------------------------
// GetEnergy (public)
//--------------------------------------------------------------------------
/**
* <p>Get the muon implantation energy from the data set.
*
* <b>return:</b>
* - muon implantation energy stored in the data file.
*
* \param runName name of the run from which to extract the muon implantation energy
*/
Double_t PRunListCollection::GetEnergy(const TString &runName) const
{
return fData->GetRunData(runName)->GetEnergy();
}
//--------------------------------------------------------------------------
// GetSetup (public)
//--------------------------------------------------------------------------
/**
* <p>Get the setup information from the data set.
*
* <b>return:</b>
* - setup information stored in the data file.
*
* \param runName name of the run from which to extract the setup information
*/
const Char_t* PRunListCollection::GetSetup(const TString &runName) const
{
return fData->GetRunData(runName)->GetSetup()->Data();
}
//--------------------------------------------------------------------------
// GetXAxisTitle (public)
//--------------------------------------------------------------------------
/**
* <p>Get the x-axis title (used with non-muSR fit).
*
* <b>return:</b>
* - x-axis title
*
* \param runName name of the run file
* \param idx msr-file run index
*/
const Char_t* PRunListCollection::GetXAxisTitle(const TString &runName, const UInt_t idx) const
{
PRawRunData *runData = fData->GetRunData(runName);
const Char_t *result = nullptr;
if (runData->fDataNonMusr.FromAscii()) {
result = runData->fDataNonMusr.GetLabels()->at(0).Data();
} else {
for (UInt_t i=0; i<fRunNonMusrList.size(); i++) {
if (fRunNonMusrList[i]->GetRunNo() == idx) {
Int_t index = fRunNonMusrList[i]->GetXIndex();
result = runData->fDataNonMusr.GetLabels()->at(index).Data();
break;
}
}
}
return result;
}
//--------------------------------------------------------------------------
// GetYAxisTitle (public)
//--------------------------------------------------------------------------
/**
* <p>Get the y-axis title (used with non-muSR fit).
*
* <b>return:</b>
* - y-axis title
*
* \param runName name of the run file
* \param idx msr-file run index
*/
const Char_t* PRunListCollection::GetYAxisTitle(const TString &runName, const UInt_t idx) const
{
PRawRunData *runData = fData->GetRunData(runName);
const Char_t *result = nullptr;
if (runData->fDataNonMusr.FromAscii()) {
result = runData->fDataNonMusr.GetLabels()->at(1).Data();
} else {
for (UInt_t i=0; i<fRunNonMusrList.size(); i++) {
if (fRunNonMusrList[i]->GetRunNo() == idx) {
Int_t index = fRunNonMusrList[i]->GetYIndex();
result = runData->fDataNonMusr.GetLabels()->at(index).Data();
break;
}
}
}
return result;
}
//--------------------------------------------------------------------------
// GetStartTimeBin (public)
//--------------------------------------------------------------------------
/**
* @brief PRunListCollection::GetStartTimeBin
* @param fitType
* @param idx
* @return
*/
Int_t PRunListCollection::GetStartTimeBin(Int_t fitType, UInt_t idx)
{
Int_t result = -1;
switch (fitType) {
case MSR_FITTYPE_SINGLE_HISTO:
if (idx < fRunSingleHistoList.size())
result = fRunSingleHistoList[idx]->GetStartTimeBin();
break;
case MSR_FITTYPE_ASYM:
if (idx < fRunAsymmetryList.size())
result = fRunAsymmetryList[idx]->GetStartTimeBin();
break;
case MSR_FITTYPE_MU_MINUS:
if (idx < fRunMuMinusList.size())
result = fRunMuMinusList[idx]->GetStartTimeBin();
break;
default:
break;
}
return result;
}
//--------------------------------------------------------------------------
// GetEndTimeBin (public)
//--------------------------------------------------------------------------
/**
* @brief PRunListCollection::GetEndTimeBin
* @param fitType
* @param idx
* @return
*/
Int_t PRunListCollection::GetEndTimeBin(Int_t fitType, UInt_t idx)
{
Int_t result = -1;
switch (fitType) {
case MSR_FITTYPE_SINGLE_HISTO:
if (idx < fRunSingleHistoList.size())
result = fRunSingleHistoList[idx]->GetEndTimeBin();
break;
case MSR_FITTYPE_ASYM:
if (idx < fRunAsymmetryList.size())
result = fRunAsymmetryList[idx]->GetEndTimeBin();
break;
case MSR_FITTYPE_MU_MINUS:
if (idx < fRunMuMinusList.size())
result = fRunMuMinusList[idx]->GetEndTimeBin();
break;
default:
break;
}
return result;
}
//--------------------------------------------------------------------------
// GetSingleHistoParams (public)
//--------------------------------------------------------------------------
/**
* @brief PRunListCollection::GetSingleHistoParams
* @param idx
* @param par
* @param shp
* @return
*/
Int_t PRunListCollection::GetSingleHistoParams(UInt_t idx, const std::vector<Double_t>& par, PDKSParams &dksp)
{
Int_t ierr = 0;
// make sure idx is within proper bounds
if (idx >= fRunSingleHistoList.size())
return 1;
// init param
InitDKSParams(dksp);
// get flag if scaling of N0 and Nbkg is wished
dksp.fScaleN0AndBkg = fRunSingleHistoList[idx]->GetScaleN0AndBkg();
// get the meta data needed to calculate the functions
PMetaData metaData = fRunSingleHistoList[idx]->GetMetaData();
// check if norm is a parameter or a function
PMsrRunBlock runInfo = fMsrInfo->GetMsrRunList()->at(idx);
if (runInfo.GetNormParamNo() < MSR_PARAM_FUN_OFFSET) { // norm is a parameter
dksp.fN0 = par[runInfo.GetNormParamNo()-1];
} else { // norm is a function
// get function number
UInt_t funNo = runInfo.GetNormParamNo()-MSR_PARAM_FUN_OFFSET;
// evaluate function
dksp.fN0 = fMsrInfo->EvalFunc(funNo, *runInfo.GetMap(), par, metaData);
}
// get tau
if (runInfo.GetLifetimeParamNo() != -1)
dksp.fTau = par[runInfo.GetLifetimeParamNo()-1];
else
dksp.fTau = PMUON_LIFETIME;
// get background
if (runInfo.GetBkgFitParamNo() == -1) { // bkg not fitted
if (runInfo.GetBkgFix(0) == PMUSR_UNDEFINED) { // no fixed background given (background interval)
dksp.fNbkg = GetBackground(idx);
} else { // fixed bkg given
dksp.fNbkg = runInfo.GetBkgFix(0);
}
} else { // bkg fitted
dksp.fNbkg = par[runInfo.GetBkgFitParamNo()-1];
}
// get packed time resolution
dksp.fPackedTimeResolution = fRunSingleHistoList[idx]->GetData()->GetDataTimeStep();
// get start time
// fRunSingleHistoList[idx]->GetData()->GetDataTimeStart() : time of fgb, which is 0-bin of the fit-data-set
// fRunSingleHistoList[idx]->GetStartTimeBin() * dksp.fPackedTimeResolution : time-offset from fgb-time to fit start time
dksp.fStartTime = fRunSingleHistoList[idx]->GetData()->GetDataTimeStart() + fRunSingleHistoList[idx]->GetStartTimeBin() * dksp.fPackedTimeResolution;
// get number of bins fitted
dksp.fNoOfFitBins = fRunSingleHistoList[idx]->GetNoOfFitBins();
// calculate functions
Int_t funcNo = 0;
for (Int_t i=0; i<fMsrInfo->GetNoOfFuncs(); i++) {
funcNo = fMsrInfo->GetFuncNo(i);
dksp.fFun.push_back(fMsrInfo->EvalFunc(funcNo, *runInfo.GetMap(), par, metaData));
}
// get map vector
dksp.fMap = *runInfo.GetMap();
dksp.fMap.erase(dksp.fMap.begin()+GetNoOfMaps(), dksp.fMap.end());
// need to reduce map indexes by 1 since in C/C++ arrays start at 0
for (UInt_t i=0; i<dksp.fMap.size(); i++)
dksp.fMap[i] -= 1;
return ierr;
}
//--------------------------------------------------------------------------
// GetAsymmetryParams (public)
//--------------------------------------------------------------------------
/**
* @brief PRunListCollection::GetAsymmetryParams
* @param idx
* @param par
* @param shp
* @return
*/
Int_t PRunListCollection::GetAsymmetryParams(UInt_t idx, const std::vector<Double_t>& par, PDKSParams &dksp)
{
Int_t ierr=0, ival=0;
// make sure idx is within proper bounds
if (idx >= fRunAsymmetryList.size())
return 1;
// init param
InitDKSParams(dksp);
// get the meta data needed to calculate the functions
PMetaData metaData = fRunAsymmetryList[idx]->GetMetaData();
// get alpha
PMsrRunBlock runInfo = fMsrInfo->GetMsrRunList()->at(idx);
ival = runInfo.GetAlphaParamNo();
if (ival > 0)
dksp.fAlpha = par[ival-1];
// get beta
ival = runInfo.GetBetaParamNo();
if (ival > 0)
dksp.fBeta = par[ival-1];
// get packed time resolution
dksp.fPackedTimeResolution = fRunAsymmetryList[idx]->GetData()->GetDataTimeStep();
// get start time
// fRunAsymmetryList[idx]->GetData()->GetDataTimeStart() : time of fgb, which is 0-bin of the fit-data-set
// fRunAsymmetryList[idx]->GetStartTimeBin() * dksp.fPackedTimeResolution : time-offset from fgb-time to fit start time
dksp.fStartTime = fRunAsymmetryList[idx]->GetData()->GetDataTimeStart() + fRunAsymmetryList[idx]->GetStartTimeBin() * dksp.fPackedTimeResolution;
// get number of bins fitted
dksp.fNoOfFitBins = fRunAsymmetryList[idx]->GetNoOfFitBins();
// calculate functions
Int_t funcNo = 0;
for (Int_t i=0; i<fMsrInfo->GetNoOfFuncs(); i++) {
funcNo = fMsrInfo->GetFuncNo(i);
dksp.fFun.push_back(fMsrInfo->EvalFunc(funcNo, *runInfo.GetMap(), par, metaData));
}
// get map vector
dksp.fMap = *runInfo.GetMap();
dksp.fMap.erase(dksp.fMap.begin()+GetNoOfMaps(), dksp.fMap.end());
// need to reduce map indexes by 1 since in C/C++ arrays start at 0
for (UInt_t i=0; i<dksp.fMap.size(); i++)
dksp.fMap[i] -= 1;
return ierr;
}
//--------------------------------------------------------------------------
// GetMuMinusParams (public)
//--------------------------------------------------------------------------
/**
* @brief PRunListCollection::GetMuMinusParams
* @param idx
* @param par
* @param shp
* @return
*/
Int_t PRunListCollection::GetMuMinusParams(UInt_t idx, const std::vector<Double_t>& par, PDKSParams &dksp)
{
Int_t ierr = 0;
// make sure idx is within proper bounds
if (idx >= fRunMuMinusList.size())
return 1;
// get run block
PMsrRunBlock runInfo = fMsrInfo->GetMsrRunList()->at(idx);
// get the meta data needed to calculate the functions
PMetaData metaData = fRunMuMinusList[idx]->GetMetaData();
// init param
InitDKSParams(dksp);
// get packed time resolution
dksp.fPackedTimeResolution = fRunMuMinusList[idx]->GetData()->GetDataTimeStep();
// get start time
// fRunSingleHistoList[idx]->GetData()->GetDataTimeStart() : time of fgb, which is 0-bin of the fit-data-set
// fRunSingleHistoList[idx]->GetStartTimeBin() * dksp.fPackedTimeResolution : time-offset from fgb-time to fit start time
dksp.fStartTime = fRunMuMinusList[idx]->GetData()->GetDataTimeStart() + fRunMuMinusList[idx]->GetStartTimeBin() * dksp.fPackedTimeResolution;
// get number of bins fitted
dksp.fNoOfFitBins = fRunMuMinusList[idx]->GetNoOfFitBins();
// calculate functions
Int_t funcNo = 0;
for (Int_t i=0; i<fMsrInfo->GetNoOfFuncs(); i++) {
funcNo = fMsrInfo->GetFuncNo(i);
dksp.fFun.push_back(fMsrInfo->EvalFunc(funcNo, *runInfo.GetMap(), par, metaData));
}
// get map vector
dksp.fMap = *runInfo.GetMap();
dksp.fMap.erase(dksp.fMap.begin()+GetNoOfMaps(), dksp.fMap.end());
// need to reduce map indexes by 1 since in C/C++ arrays start at 0
for (UInt_t i=0; i<dksp.fMap.size(); i++)
dksp.fMap[i] -= 1;
return ierr;
}
//--------------------------------------------------------------------------
// InitDKSParams (private)
//--------------------------------------------------------------------------
/**
* \brief PRunListCollection::InitDKSParams
* \param param
*/
void PRunListCollection::InitDKSParams(PDKSParams &param)
{
param.fScaleN0AndBkg = false;
param.fN0 = -1.0;
param.fNbkg = -1.0;
param.fTau = -1.0;
param.fAlpha = 1.0;
param.fBeta = 1.0;
param.fPackedTimeResolution = -1.0;
param.fStartTime = -1.0;
param.fNoOfFitBins = -1;
param.fFun.clear();
param.fMap.clear();
}
//--------------------------------------------------------------------------
// GetBackground (private)
//--------------------------------------------------------------------------
/**
* @brief PRunListCollection::GetBackground
* @param idx
* @return
*/
Double_t PRunListCollection::GetBackground(Int_t idx)
{
// make sure idx is within proper bounds
if (idx >= (Int_t)fRunSingleHistoList.size())
return 0.0;
return fRunSingleHistoList[idx]->GetBackground();
}