musrfit  1.9.2
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-2023 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 //--------------------------------------------------------------------------
41 PFitterFcn::PFitterFcn(PRunListCollection *runList, Bool_t useChi2)
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 //--------------------------------------------------------------------------
60 {
61 }
62 
63 //--------------------------------------------------------------------------
64 // operator()
65 //--------------------------------------------------------------------------
71 Double_t PFitterFcn::operator()(const std::vector<Double_t>& par) const
72 {
73  Double_t value = 0.0;
74 
75  if (fUseChi2) { // chi square
81  value += fRunListCollection->GetMuMinusChisq(par);
82  value += fRunListCollection->GetNonMusrChisq(par);
83  } else { // max likelihood
91  }
92 
93  return value;
94 }
95 
96 //--------------------------------------------------------------------------
97 // CalcExpectedChiSquare()
98 //--------------------------------------------------------------------------
106 void 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 }
virtual Double_t GetAsymmetryMaximumLikelihood(const std::vector< Double_t > &par) const
virtual Double_t GetMuMinusMaximumLikelihood(const std::vector< Double_t > &par) const
virtual Double_t GetSingleHistoChisq(const std::vector< Double_t > &par) const
PFitterFcn(PRunListCollection *runList, Bool_t useChi2)
Definition: PFitterFcn.cpp:41
virtual Double_t GetNonMusrMaximumLikelihood(const std::vector< Double_t > &par) const
virtual Double_t GetNonMusrChisq(const std::vector< Double_t > &par) const
virtual Double_t GetAsymmetryRRFMaximumLikelihood(const std::vector< Double_t > &par) const
Double_t operator()(const std::vector< Double_t > &par) const
Definition: PFitterFcn.cpp:71
virtual Double_t GetAsymmetryBNMRChisq(const std::vector< Double_t > &par) const
void CalcExpectedChiSquare(const std::vector< Double_t > &par, Double_t &totalExpectedChisq, std::vector< Double_t > &expectedChisqPerRun)
Definition: PFitterFcn.cpp:106
virtual Double_t GetSingleRunMaximumLikelihoodExpected(const std::vector< Double_t > &par, const UInt_t idx) const
virtual Double_t GetAsymmetryBNMRMaximumLikelihood(const std::vector< Double_t > &par) const
virtual Double_t GetMuMinusChisq(const std::vector< Double_t > &par) const
virtual Double_t GetAsymmetryChisq(const std::vector< Double_t > &par) const
Bool_t fUseChi2
true = chisq fit, false = log max-likelihood fit
Definition: PFitterFcn.h:57
virtual Double_t GetSingleHistoMaximumLikelihood(const std::vector< Double_t > &par) const
virtual Double_t GetSingleHistoRRFChisq(const std::vector< Double_t > &par) const
virtual Double_t GetSingleHistoRRFMaximumLikelihood(const std::vector< Double_t > &par) const
virtual Double_t GetSingleRunChisqExpected(const std::vector< Double_t > &par, const UInt_t idx) const
virtual Double_t GetAsymmetryRRFChisq(const std::vector< Double_t > &par) const
PRunListCollection * fRunListCollection
pre-processed data to be fitted
Definition: PFitterFcn.h:58
virtual UInt_t GetNoOfSingleHisto() const
returns the number of single histogram data sets present in the msr-file
Double_t fUp
for chisq == 1.0, i.e. errors are 1 std. deviation errors. for log max-likelihood == 0...
Definition: PFitterFcn.h:56