implemented single side parameter boundary handling for MINUIT2

This commit is contained in:
nemu 2008-09-23 06:51:43 +00:00
parent 8ba07a692a
commit 4f1ade3ca7
4 changed files with 83 additions and 58 deletions

View File

@ -94,6 +94,14 @@ short term:
* PFitter.cpp: implement HESSE * PFitter.cpp: implement HESSE
**DONE** 08-09-01 **DONE** 08-09-01
* implement the handling for single side limited boundaries for parameters which is
possible in MINUIT2
syntax would be:
0.0 100.0 // lower and upper limit
0.0 none // lower limit only
none 100.0 // upper limit only
**FIRST IMPLEMENTATION DONE, NEEDS EXTENSIVE TESTING** 08-09-23
* implement FFT with msr-interface * implement FFT with msr-interface
--------------------- ---------------------

View File

@ -280,13 +280,28 @@ bool PFitter::SetParameters()
} else { // add free parameter } else { // add free parameter
// check if boundaries are given // check if boundaries are given
if (fParams[i].fNoOfParams > 5) { // boundaries given if (fParams[i].fNoOfParams > 5) { // boundaries given
fMnUserParams.Add(fParams[i].fName.Data(), fParams[i].fValue, fParams[i].fStep, cout << endl << ">> name=" << fParams[i].fName.Data() << ", lower=" << fParams[i].fLowerBoundaryPresent << ", upper=" << fParams[i].fUpperBoundaryPresent;
fParams[i].fLowerBoundary, fParams[i].fUpperBoundary); if (fParams[i].fLowerBoundaryPresent &&
fParams[i].fUpperBoundaryPresent) { // upper and lower boundaries given
cout << endl << ">> lower and upper";
fMnUserParams.Add(fParams[i].fName.Data(), fParams[i].fValue, fParams[i].fStep,
fParams[i].fLowerBoundary, fParams[i].fUpperBoundary);
} else if (fParams[i].fLowerBoundaryPresent &&
!fParams[i].fUpperBoundaryPresent) { // lower boundary limited
cout << endl << ">> lower only";
fMnUserParams.Add(fParams[i].fName.Data(), fParams[i].fValue, fParams[i].fStep);
fMnUserParams.SetLowerLimit(fParams[i].fName.Data(), fParams[i].fLowerBoundary);
} else { // upper boundary limited
cout << endl << ">> upper only";
fMnUserParams.Add(fParams[i].fName.Data(), fParams[i].fValue, fParams[i].fStep);
fMnUserParams.SetUpperLimit(fParams[i].fName.Data(), fParams[i].fUpperBoundary);
}
} else { // no boundaries given } else { // no boundaries given
fMnUserParams.Add(fParams[i].fName.Data(), fParams[i].fValue, fParams[i].fStep); fMnUserParams.Add(fParams[i].fName.Data(), fParams[i].fValue, fParams[i].fStep);
} }
} }
} }
cout << endl;
// check if there is an unused parameter, if so, fix it // check if there is an unused parameter, if so, fix it
for (unsigned int i=0; i<fParams.size(); i++) { for (unsigned int i=0; i<fParams.size(); i++) {

View File

@ -322,11 +322,17 @@ int PMsrHandler::WriteMsrLogFile()
if (fParam[i].fNoOfParams > 5) { if (fParam[i].fNoOfParams > 5) {
f.width(7); f.width(7);
f.precision(prec); f.precision(prec);
f << left << fParam[i].fLowerBoundary; if (fParam[i].fLowerBoundaryPresent)
f << left << fParam[i].fLowerBoundary;
else
f << left << "none";
f << " "; f << " ";
f.width(7); f.width(7);
f.precision(prec); f.precision(prec);
f << left << fParam[i].fUpperBoundary; if (fParam[i].fUpperBoundaryPresent)
f << left << fParam[i].fUpperBoundary;
else
f << left << "none";
f << " "; f << " ";
} }
CheckAndWriteComment(f, ++lineNo); CheckAndWriteComment(f, ++lineNo);
@ -812,7 +818,6 @@ int PMsrHandler::ParameterInUse(unsigned int paramNo)
* \code * \code
* No Name Value Step/Neg_Error Pos_Error Boundary_Low Boundary_High * No Name Value Step/Neg_Error Pos_Error Boundary_Low Boundary_High
* x x x x x x x -> 7 Parameters, e.g. after a MINOS fit * x x x x x x x -> 7 Parameters, e.g. after a MINOS fit
* x x x x x x -> 6 Parameters, e.g. after a MIGRAD fit
* x x x x x -> 5 Parameters, e.g. after a MINOS fit * x x x x x -> 5 Parameters, e.g. after a MINOS fit
* without boundaries * without boundaries
* x x x x -> 4 Parameters, e.g. after MIGRAD fit * x x x x -> 4 Parameters, e.g. after MIGRAD fit
@ -838,15 +843,17 @@ bool PMsrHandler::HandleFitParameterEntry(PMsrLines &lines)
while ((iter != lines.end()) && !error) { while ((iter != lines.end()) && !error) {
// init param structure // init param structure
param.fNoOfParams = -1; param.fNoOfParams = -1;
param.fNo = -1; param.fNo = -1;
param.fName = TString(""); param.fName = TString("");
param.fValue = 0.0; param.fValue = 0.0;
param.fStep = 0.0; param.fStep = 0.0;
param.fPosErrorPresent = false; param.fPosErrorPresent = false;
param.fPosError = 0.0; param.fPosError = 0.0;
param.fLowerBoundary = 0.0; param.fLowerBoundaryPresent = false;
param.fUpperBoundary = 0.0; param.fLowerBoundary = 0.0;
param.fUpperBoundaryPresent = false;
param.fUpperBoundary = 0.0;
tokens = iter->fLine.Tokenize(" \t"); tokens = iter->fLine.Tokenize(" \t");
if (!tokens) { if (!tokens) {
@ -856,7 +863,7 @@ bool PMsrHandler::HandleFitParameterEntry(PMsrLines &lines)
} }
// handle various input possiblities // handle various input possiblities
if ((tokens->GetEntries() < 4) || (tokens->GetEntries() > 7)) { if ((tokens->GetEntries() < 4) || (tokens->GetEntries() > 7) || (tokens->GetEntries() == 6)) {
error = true; error = true;
} else { // handle the first 4 parameter since they are always the same } else { // handle the first 4 parameter since they are always the same
// parameter number // parameter number
@ -905,34 +912,13 @@ bool PMsrHandler::HandleFitParameterEntry(PMsrLines &lines)
param.fPosError = (double)str.Atof(); param.fPosError = (double)str.Atof();
} else { } else {
str.ToLower(); str.ToLower();
if (!str.CompareTo("none")) if (!str.CompareTo("none", TString::kIgnoreCase))
param.fPosErrorPresent = false; param.fPosErrorPresent = false;
else else
error = true; error = true;
} }
} }
// 6 values, i.e. No Name Value Error Lower_Bounderay Upper_Boundary
if (tokens->GetEntries() == 6) {
param.fNoOfParams = 6;
// lower boundary
ostr = dynamic_cast<TObjString*>(tokens->At(4));
str = ostr->GetString();
if (str.IsFloat())
param.fLowerBoundary = (double)str.Atof();
else
error = true;
// upper boundary
ostr = dynamic_cast<TObjString*>(tokens->At(5));
str = ostr->GetString();
if (str.IsFloat())
param.fUpperBoundary = (double)str.Atof();
else
error = true;
}
// 7 values, i.e. No Name Value Neg_Error Pos_Error Lower_Bounderay Upper_Boundary // 7 values, i.e. No Name Value Neg_Error Pos_Error Lower_Bounderay Upper_Boundary
if (tokens->GetEntries() == 7) { if (tokens->GetEntries() == 7) {
param.fNoOfParams = 7; param.fNoOfParams = 7;
@ -945,7 +931,7 @@ bool PMsrHandler::HandleFitParameterEntry(PMsrLines &lines)
param.fPosError = (double)str.Atof(); param.fPosError = (double)str.Atof();
} else { } else {
str.ToLower(); str.ToLower();
if (!str.CompareTo("none")) if (!str.CompareTo("none", TString::kIgnoreCase))
param.fPosErrorPresent = false; param.fPosErrorPresent = false;
else else
error = true; error = true;
@ -954,18 +940,32 @@ bool PMsrHandler::HandleFitParameterEntry(PMsrLines &lines)
// lower boundary // lower boundary
ostr = dynamic_cast<TObjString*>(tokens->At(5)); ostr = dynamic_cast<TObjString*>(tokens->At(5));
str = ostr->GetString(); str = ostr->GetString();
if (str.IsFloat()) // check if lower boundary is "none", i.e. upper boundary limited only
param.fLowerBoundary = (double)str.Atof(); if (!str.CompareTo("none", TString::kIgnoreCase)) { // none
else param.fLowerBoundaryPresent = false;
error = true; } else { // assuming that the lower boundary is a number
if (str.IsFloat()) {
param.fLowerBoundary = (double)str.Atof();
param.fLowerBoundaryPresent = true;
} else {
error = true;
}
}
// upper boundary // upper boundary
ostr = dynamic_cast<TObjString*>(tokens->At(6)); ostr = dynamic_cast<TObjString*>(tokens->At(6));
str = ostr->GetString(); str = ostr->GetString();
if (str.IsFloat()) // check if upper boundary is "none", i.e. lower boundary limited only
param.fUpperBoundary = (double)str.Atof(); if (!str.CompareTo("none", TString::kIgnoreCase)) { // none
else param.fUpperBoundaryPresent = false;
error = true; } else { // assuming a number
if (str.IsFloat()) {
param.fUpperBoundary = (double)str.Atof();
param.fUpperBoundaryPresent = true;
} else {
error = true;
}
}
} }
} }
@ -988,9 +988,9 @@ bool PMsrHandler::HandleFitParameterEntry(PMsrLines &lines)
cout << endl << "Step/Neg_Error: the starting step value in a fit (a double), or"; cout << endl << "Step/Neg_Error: the starting step value in a fit (a double), or";
cout << endl << " the symmetric error (MIGRAD, SIMPLEX), or"; cout << endl << " the symmetric error (MIGRAD, SIMPLEX), or";
cout << endl << " the negative error (MINOS)"; cout << endl << " the negative error (MINOS)";
cout << endl << "Pos_Error: the positive error (MINOS), (a double)"; cout << endl << "Pos_Error: the positive error (MINOS), (a double or \"none\")";
cout << endl << "Lower_Boundary: the lower boundary allowed for the fit parameter (a double)"; cout << endl << "Lower_Boundary: the lower boundary allowed for the fit parameter (a double or \"none\")";
cout << endl << "Upper_Boundary: the upper boundary allowed for the fit parameter (a double)"; cout << endl << "Upper_Boundary: the upper boundary allowed for the fit parameter (a double or \"none\")";
cout << endl; cout << endl;
} else { // everything is OK, therefore add the parameter to the parameter list } else { // everything is OK, therefore add the parameter to the parameter list
fParam.push_back(param); fParam.push_back(param);

View File

@ -196,15 +196,17 @@ typedef vector<PMsrLineStructure> PMsrLines;
* <p> Holds the information of a parameter. * <p> Holds the information of a parameter.
*/ */
typedef struct { typedef struct {
int fNoOfParams; ///< how many parameters are given int fNoOfParams; ///< how many parameters are given
int fNo; ///< parameter number int fNo; ///< parameter number
TString fName; ///< name TString fName; ///< name
double fValue; ///< value double fValue; ///< value
double fStep; ///< step / error / neg_error, depending on the situation double fStep; ///< step / error / neg_error, depending on the situation
bool fPosErrorPresent; ///< positive error is defined (as a number) bool fPosErrorPresent; ///< positive error is defined (as a number)
double fPosError; ///< positive error if present double fPosError; ///< positive error if present
double fLowerBoundary; ///< lower boundary for the fit parameter bool fLowerBoundaryPresent; ///< flag showing if a lower boundary is present
double fUpperBoundary; ///< upper boundary for the fit parameter double fLowerBoundary; ///< lower boundary for the fit parameter
bool fUpperBoundaryPresent; ///< flag showing if an upper boundary is present
double fUpperBoundary; ///< upper boundary for the fit parameter
} PMsrParamStructure; } PMsrParamStructure;
//------------------------------------------------------------- //-------------------------------------------------------------