musrfit 1.10.0
PFitterFcn.cpp
Go to the documentation of this file.
1/***************************************************************************
2
3 PFitterFcn.cpp
4
5 Author: Andreas Suter
6 e-mail: andreas.suter@psi.ch
7
8***************************************************************************/
9
10/***************************************************************************
11 * Copyright (C) 2007-2026 by Andreas Suter *
12 * andreas.suter@psi.ch *
13 * *
14 * This program is free software; you can redistribute it and/or modify *
15 * it under the terms of the GNU General Public License as published by *
16 * the Free Software Foundation; either version 2 of the License, or *
17 * (at your option) any later version. *
18 * *
19 * This program is distributed in the hope that it will be useful, *
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22 * GNU General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU General Public License *
25 * along with this program; if not, write to the *
26 * Free Software Foundation, Inc., *
27 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
28 ***************************************************************************/
29
30#include "PFitterFcn.h"
31
32//--------------------------------------------------------------------------
33// Constructor
34//--------------------------------------------------------------------------
42{
43 fUseChi2 = useChi2;
44
45 if (fUseChi2)
46 fUp = 1.0;
47 else
48 fUp = 0.5;
49
50 fRunListCollection = runList;
51}
52
53//--------------------------------------------------------------------------
54// Destructor
55//--------------------------------------------------------------------------
62
63//--------------------------------------------------------------------------
64// operator()
65//--------------------------------------------------------------------------
71Double_t PFitterFcn::operator()(const std::vector<Double_t>& par) const
72{
73 Double_t value = 0.0;
74
75 if (fUseChi2) { // chi square
76 value += fRunListCollection->GetSingleHistoChisq(par);
77 value += fRunListCollection->GetSingleHistoRRFChisq(par);
78 value += fRunListCollection->GetAsymmetryChisq(par);
79 value += fRunListCollection->GetAsymmetryRRFChisq(par);
80 value += fRunListCollection->GetAsymmetryBNMRChisq(par);
81 value += fRunListCollection->GetMuMinusChisq(par);
82 value += fRunListCollection->GetNonMusrChisq(par);
83 } else { // max likelihood
84 value += fRunListCollection->GetSingleHistoMaximumLikelihood(par);
85 value += fRunListCollection->GetSingleHistoRRFMaximumLikelihood(par);
86 value += fRunListCollection->GetAsymmetryMaximumLikelihood(par);
87 value += fRunListCollection->GetAsymmetryRRFMaximumLikelihood(par);
88 value += fRunListCollection->GetAsymmetryBNMRMaximumLikelihood(par);
89 value += fRunListCollection->GetMuMinusMaximumLikelihood(par);
90 value += fRunListCollection->GetNonMusrMaximumLikelihood(par);
91 }
92
93 return value;
94}
95
96//--------------------------------------------------------------------------
97// CalcExpectedChiSquare()
98//--------------------------------------------------------------------------
106void PFitterFcn::CalcExpectedChiSquare(const std::vector<Double_t> &par, Double_t &totalExpectedChisq, std::vector<Double_t> &expectedChisqPerRun)
107{
108 // init expected chisq related variables
109 totalExpectedChisq = 0.0;
110 expectedChisqPerRun.clear();
111
112 Double_t value = 0.0;
113 if (fUseChi2) {
114 // single histo
115 for (UInt_t i=0; i<fRunListCollection->GetNoOfSingleHisto(); i++) {
116 value = fRunListCollection->GetSingleRunChisqExpected(par, i); // calculate the expected chisq for single histo run block 'i'
117 expectedChisqPerRun.push_back(value);
118 totalExpectedChisq += value;
119 }
120 } else { // log max. likelihood
121 // single histo
122 for (UInt_t i=0; i<fRunListCollection->GetNoOfSingleHisto(); i++) {
123 value = fRunListCollection->GetSingleRunMaximumLikelihoodExpected(par, i); // calculate the expected mlh for single histo run block 'i'
124 expectedChisqPerRun.push_back(value);
125 totalExpectedChisq += value;
126 }
127 }
128}
PRunListCollection * fRunListCollection
Pointer to preprocessed muSR data collection.
Definition PFitterFcn.h:168
void CalcExpectedChiSquare(const std::vector< Double_t > &par, Double_t &totalExpectedChisq, std::vector< Double_t > &expectedChisqPerRun)
Calculates expected χ² (or maxLH) for quality assessment.
~PFitterFcn()
Destructor.
Double_t fUp
Error definition: 1.0 for χ² (1σ = Δχ²=1), 0.5 for maxLH (1σ = ΔmaxLH=0.5)
Definition PFitterFcn.h:166
Double_t operator()(const std::vector< Double_t > &par) const
Evaluates objective function for given parameters.
Bool_t fUseChi2
Fit mode flag: true = χ² minimization, false = max log-likelihood.
Definition PFitterFcn.h:167
PFitterFcn(PRunListCollection *runList, Bool_t useChi2)
Constructor for objective function.
Manager class for all processed μSR run data during fitting.