implemented max log likelihood, and other things
This commit is contained in:
@@ -178,7 +178,7 @@ bool PFitter::CheckCommands()
|
||||
continue;
|
||||
} else if (it->fLine.Contains("CHI_SQUARE")) {
|
||||
fUseChi2 = true;
|
||||
} else if (it->fLine.Contains("MAX_LIKELYHOOD")) {
|
||||
} else if (it->fLine.Contains("MAX_LIKELIHOOD")) {
|
||||
fUseChi2 = false;
|
||||
} else if (it->fLine.Contains("INTERACTIVE")) {
|
||||
fCmdList.push_back(PMN_INTERACTIVE);
|
||||
@@ -325,7 +325,7 @@ bool PFitter::ExecuteMinimize()
|
||||
ROOT::Minuit2::MnMinimize minimize((*fFitterFcn), fMnUserParams);
|
||||
|
||||
// minimize
|
||||
ROOT::Minuit2::FunctionMinimum min = minimize();
|
||||
ROOT::Minuit2::FunctionMinimum min = minimize();
|
||||
if (!min.IsValid()) {
|
||||
cout << endl << "**WARNING**: PFitter::ExecuteMinimize(): Fit did not converge, sorry ...";
|
||||
return false;
|
||||
|
||||
@@ -53,6 +53,19 @@ PFitterFcn::PFitterFcn(PRunListCollection *runList, bool useChi2)
|
||||
fUp = 0.5;
|
||||
|
||||
fRunListCollection = runList;
|
||||
|
||||
// check if max likelihood is used together with asymmetry/RRF/nonMusr data.
|
||||
// if yes place a warning since this option is not implemented and a fall back
|
||||
// to chi2 will be used.
|
||||
if (!fUseChi2) {
|
||||
if ((fRunListCollection->GetNoOfAsymmetry() > 0) ||
|
||||
(fRunListCollection->GetNoOfRRF() > 0) ||
|
||||
(fRunListCollection->GetNoOfNonMusr() > 0)) {
|
||||
cout << endl << "**WARNING**: Maximum Log Likelihood Fit is only implemented for Single Histogram Fit";
|
||||
cout << endl << " Will fall back to Chi Square Fit.";
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -80,7 +93,7 @@ double PFitterFcn::operator()(const std::vector<double>& par) const
|
||||
value += fRunListCollection->GetAsymmetryChisq(par);
|
||||
value += fRunListCollection->GetRRFChisq(par);
|
||||
value += fRunListCollection->GetNonMusrChisq(par);
|
||||
} else { // max likelyhood
|
||||
} else { // max likelihood
|
||||
value += fRunListCollection->GetSingleHistoMaximumLikelihood(par);
|
||||
value += fRunListCollection->GetAsymmetryMaximumLikelihood(par);
|
||||
value += fRunListCollection->GetRRFMaximumLikelihood(par);
|
||||
|
||||
@@ -1467,7 +1467,7 @@ bool PMsrHandler::FilterFunMapNumber(TString str, const char *filter, int &no)
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p> In the command block there shall be a new command which can be used
|
||||
* to switch between chi2 and maximum_likelyhood!!
|
||||
* to switch between chi2 and maximum_likelihood!!
|
||||
*
|
||||
* \param lines is a list of lines containing the fitparameter block
|
||||
*/
|
||||
|
||||
@@ -99,9 +99,6 @@ bool PRunListCollection::Add(int runNo)
|
||||
|
||||
int fitType = (*fMsrInfo->GetMsrRunList())[runNo].fFitType;
|
||||
|
||||
PRunAsymmetry* asym;
|
||||
bool status;
|
||||
|
||||
switch (fitType) {
|
||||
case PRUN_SINGLE_HISTO:
|
||||
fRunSingleHistoList.push_back(new PRunSingleHisto(fMsrInfo, fData, runNo));
|
||||
@@ -110,8 +107,6 @@ bool status;
|
||||
break;
|
||||
case PRUN_ASYMMETRY:
|
||||
fRunAsymmetryList.push_back(new PRunAsymmetry(fMsrInfo, fData, runNo));
|
||||
asym = fRunAsymmetryList[fRunAsymmetryList.size()-1];
|
||||
status = asym->IsValid();
|
||||
if (!fRunAsymmetryList[fRunAsymmetryList.size()-1]->IsValid())
|
||||
success = false;
|
||||
break;
|
||||
@@ -217,14 +212,15 @@ double PRunListCollection::GetSingleHistoMaximumLikelihood(const std::vector<dou
|
||||
// GetAsymmetryMaximumLikelihood
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>
|
||||
* <p> Since it is not clear yet how to handle asymmetry fits with max likelihood
|
||||
* the chi square will be used!
|
||||
*/
|
||||
double PRunListCollection::GetAsymmetryMaximumLikelihood(const std::vector<double>& par)
|
||||
{
|
||||
double mlh = 0.0;
|
||||
|
||||
for (unsigned int i=0; i<fRunAsymmetryList.size(); i++)
|
||||
mlh += fRunAsymmetryList[i]->CalcMaxLikelihood(par);
|
||||
mlh += fRunAsymmetryList[i]->CalcChiSquare(par);
|
||||
|
||||
return mlh;
|
||||
}
|
||||
@@ -233,14 +229,15 @@ double PRunListCollection::GetAsymmetryMaximumLikelihood(const std::vector<doubl
|
||||
// GetRRFMaximumLikelihood
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>
|
||||
* <p> Since it is not clear yet how to handle RRF fits with max likelihood
|
||||
* the chi square will be used!
|
||||
*/
|
||||
double PRunListCollection::GetRRFMaximumLikelihood(const std::vector<double>& par)
|
||||
{
|
||||
double mlh = 0.0;
|
||||
|
||||
for (unsigned int i=0; i<fRunRRFList.size(); i++)
|
||||
mlh += fRunRRFList[i]->CalcMaxLikelihood(par);
|
||||
mlh += fRunRRFList[i]->CalcChiSquare(par);
|
||||
|
||||
return mlh;
|
||||
}
|
||||
@@ -249,14 +246,15 @@ double PRunListCollection::GetRRFMaximumLikelihood(const std::vector<double>& pa
|
||||
// GetNonMusrMaximumLikelihood
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>
|
||||
* <p> Since it is not clear yet how to handle non musr fits with max likelihood
|
||||
* the chi square will be used!
|
||||
*/
|
||||
double PRunListCollection::GetNonMusrMaximumLikelihood(const std::vector<double>& par)
|
||||
{
|
||||
double mlh = 0.0;
|
||||
|
||||
for (unsigned int i=0; i<fRunNonMusrList.size(); i++)
|
||||
mlh += fRunNonMusrList[i]->CalcMaxLikelihood(par);
|
||||
mlh += fRunNonMusrList[i]->CalcChiSquare(par);
|
||||
|
||||
return mlh;
|
||||
}
|
||||
|
||||
@@ -166,9 +166,54 @@ double PRunSingleHisto::CalcChiSquare(const std::vector<double>& par)
|
||||
*/
|
||||
double PRunSingleHisto::CalcMaxLikelihood(const std::vector<double>& par)
|
||||
{
|
||||
cout << endl << "PRunSingleHisto::CalcMaxLikelihood(): not implemented yet ..." << endl;
|
||||
double mllh = 0.0; // maximum log likelihood assuming poisson distribution for the single bin
|
||||
|
||||
return 1.0;
|
||||
double N0;
|
||||
|
||||
// check if norm is a parameter or a function
|
||||
if (fRunInfo->fNormParamNo < MSR_PARAM_FUN_OFFSET) { // norm is a parameter
|
||||
N0 = par[fRunInfo->fNormParamNo-1];
|
||||
} else { // norm is a function
|
||||
// get function number
|
||||
unsigned int funNo = fRunInfo->fNormParamNo-MSR_PARAM_FUN_OFFSET;
|
||||
// evaluate function
|
||||
N0 = fMsrInfo->EvalFunc(funNo,fRunInfo->fMap,par);
|
||||
}
|
||||
|
||||
// get tau
|
||||
double tau;
|
||||
if (fRunInfo->fLifetimeParamNo != -1)
|
||||
tau = par[fRunInfo->fLifetimeParamNo-1];
|
||||
else
|
||||
tau = PMUON_LIFETIME;
|
||||
|
||||
// get background
|
||||
double bkg = par[fRunInfo->fBkgFitParamNo-1];
|
||||
|
||||
// calculate functions
|
||||
for (int i=0; i<fMsrInfo->GetNoOfFuncs(); i++) {
|
||||
int funcNo = fMsrInfo->GetFuncNo(i);
|
||||
fFuncValues[i] = fMsrInfo->EvalFunc(funcNo, fRunInfo->fMap, par);
|
||||
}
|
||||
|
||||
// calculate maximum log likelihood
|
||||
double theo;
|
||||
double data;
|
||||
for (unsigned int i=0; i<fData.fValue.size(); i++) {
|
||||
if ((fData.fTime[i]>=fFitStartTime) && (fData.fTime[i]<=fFitStopTime)) {
|
||||
// calculate theory for the given parameter set
|
||||
theo = N0*TMath::Exp(-fData.fTime[i]/tau)*(1+fTheory->Func(fData.fTime[i], par, fFuncValues))+bkg;
|
||||
// check if data value is not too small
|
||||
if (fData.fValue[i] > 1.0e-9)
|
||||
data = fData.fValue[i];
|
||||
else
|
||||
data = 1.0e-9;
|
||||
// add maximum log likelihood contribution of bin i
|
||||
mllh -= data*TMath::Log(theo) - theo - TMath::LnGamma(data+1);
|
||||
}
|
||||
}
|
||||
|
||||
return mllh;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user