some more work in userFcn

This commit is contained in:
nemu
2008-06-09 12:11:37 +00:00
parent 660cf9e014
commit 3b595f0730
3 changed files with 55 additions and 24 deletions

View File

@ -314,10 +314,15 @@ bool PFitter::ExecuteMigrad()
fMnUserParams = fFcnMin->UserParameters(); fMnUserParams = fFcnMin->UserParameters();
// create migrad object // create migrad object
ROOT::Minuit2::MnMigrad migrad((*fFitterFcn), fMnUserParams); // set MnStrategy to high == 2, see MINUIT2 manual MnStrategy
ROOT::Minuit2::MnMigrad migrad((*fFitterFcn), fMnUserParams, 2);
// minimize // minimize
ROOT::Minuit2::FunctionMinimum min = migrad(); // maxfcn is 10*MINUIT2 Default maxfcn
unsigned int maxfcn = 10*(200 + 100*fParams.size() + 5*fParams.size()*fParams.size());
// tolerance = MINUIT2 Default tolerance
double tolerance = 0.1;
ROOT::Minuit2::FunctionMinimum min = migrad(maxfcn, tolerance);
if (!min.IsValid()) { if (!min.IsValid()) {
cout << endl << "**WARNING**: PFitter::ExecuteMigrad(): Fit did not converge, sorry ..."; cout << endl << "**WARNING**: PFitter::ExecuteMigrad(): Fit did not converge, sorry ...";
return false; return false;
@ -367,10 +372,16 @@ bool PFitter::ExecuteMinimize()
fMnUserParams = fFcnMin->UserParameters(); fMnUserParams = fFcnMin->UserParameters();
// create minimizer object // create minimizer object
ROOT::Minuit2::MnMinimize minimize((*fFitterFcn), fMnUserParams); // set MnStrategy to high == 2, see MINUIT2 manual MnStrategy
ROOT::Minuit2::MnMinimize minimize((*fFitterFcn), fMnUserParams, 2);
// minimize // minimize
ROOT::Minuit2::FunctionMinimum min = minimize(); // maxfcn is 10*MINUIT2 Default maxfcn
unsigned int maxfcn = 10*(200 + 100*fParams.size() + 5*fParams.size()*fParams.size());
cout << endl << "maxfcn=" << maxfcn << endl;
// tolerance = MINUIT2 Default tolerance
double tolerance = 0.1;
ROOT::Minuit2::FunctionMinimum min = minimize(maxfcn, tolerance);
if (!min.IsValid()) { if (!min.IsValid()) {
cout << endl << "**WARNING**: PFitter::ExecuteMinimize(): Fit did not converge, sorry ..."; cout << endl << "**WARNING**: PFitter::ExecuteMinimize(): Fit did not converge, sorry ...";
return false; return false;
@ -692,10 +703,15 @@ bool PFitter::ExecuteSimplex()
fMnUserParams = fFcnMin->UserParameters(); fMnUserParams = fFcnMin->UserParameters();
// create minimizer object // create minimizer object
ROOT::Minuit2::MnSimplex simplex((*fFitterFcn), fMnUserParams); // set MnStrategy to high == 2, see MINUIT2 manual MnStrategy
ROOT::Minuit2::MnSimplex simplex((*fFitterFcn), fMnUserParams, 2);
// minimize // minimize
ROOT::Minuit2::FunctionMinimum min = simplex(); // maxfcn is 10*MINUIT2 Default maxfcn
unsigned int maxfcn = 10*(200 + 100*fParams.size() + 5*fParams.size()*fParams.size());
// tolerance = MINUIT2 Default tolerance
double tolerance = 0.1;
ROOT::Minuit2::FunctionMinimum min = simplex(maxfcn, tolerance);
if (!min.IsValid()) { if (!min.IsValid()) {
cout << endl << "**WARNING**: PFitter::ExecuteSimplex(): Fit did not converge, sorry ..."; cout << endl << "**WARNING**: PFitter::ExecuteSimplex(): Fit did not converge, sorry ...";
return false; return false;

View File

@ -183,8 +183,14 @@ PTheory::PTheory(PMsrHandler *msrInfo, unsigned int runNo, const bool hasParent)
str = ostr->GetString(); str = ostr->GetString();
// if userFcn, the first entry is the function name and needs to be handled specially // if userFcn, the first entry is the function name and needs to be handled specially
if ((fType == THEORY_USER_FCN) && (i == 1)) { if ((fType == THEORY_USER_FCN) && ((i == 1) || (i == 2))) {
fUserFcnClassName = str; cout << endl << ">> userFcn: i=" << i << ", str=" << str.Data() << endl;
if (i == 1) {
fUserFcnSharedLibName = str;
}
if (i == 2) {
fUserFcnClassName = str;
}
continue; continue;
} }
@ -259,22 +265,28 @@ PTheory::PTheory(PMsrHandler *msrInfo, unsigned int runNo, const bool hasParent)
if (!fUserFcnClassName.IsWhitespace()) { if (!fUserFcnClassName.IsWhitespace()) {
cout << endl << ">> user function class name: " << fUserFcnClassName.Data() << endl; cout << endl << ">> user function class name: " << fUserFcnClassName.Data() << endl;
if (!TClass::GetDict(fUserFcnClassName.Data())) { if (!TClass::GetDict(fUserFcnClassName.Data())) {
char libname[256]; if (gSystem->Load(fUserFcnSharedLibName.Data()) < 0) {
sprintf(libname, "lib%s.so", fUserFcnClassName.Data()); // add path needed?? cout << endl << "**ERROR**: PTheory: user function class '" << fUserFcnClassName.Data() << "' not found.";
if (gSystem->Load(libname) < 0) { cout << endl << " Tried to load " << fUserFcnSharedLibName.Data() << " but failed.";
cout << endl << "**ERROR**: PTheory: user function class '" << fUserFcnClassName.Data() << "' not found. See line no " << line->fLineNo; cout << endl << " See line no " << line->fLineNo;
fValid = false; fValid = false;
// clean up
if (tokens) {
delete tokens;
tokens = 0;
}
return;
} }
} else { // invoke user function object }
fUserFcn = 0; // invoke user function object
fUserFcn = (PUserFcnBase*)TClass::GetClass(fUserFcnClassName.Data())->New(); fUserFcn = 0;
cout << endl << ">> fUserFcn = " << fUserFcn; fUserFcn = (PUserFcnBase*)TClass::GetClass(fUserFcnClassName.Data())->New();
if (fUserFcn == 0) { cout << endl << ">> fUserFcn = " << fUserFcn << endl;
cout << endl << "**ERROR**: PTheory: user function object could not be invoked. See line no " << line->fLineNo; if (fUserFcn == 0) {
fValid = false; cout << endl << "**ERROR**: PTheory: user function object could not be invoked. See line no " << line->fLineNo;
} else { // user function valid, hence expand the fUserParam vector to the proper size fValid = false;
fUserParam.resize(fParamNo.size()); } else { // user function valid, hence expand the fUserParam vector to the proper size
} fUserParam.resize(fParamNo.size());
} }
} }
@ -663,8 +675,8 @@ void PTheory::MakeCleanAndTidyTheoryBlock(PMsrLines *fullTheoryBlock)
// make a handable string out of the asymmetry token // make a handable string out of the asymmetry token
ostr = dynamic_cast<TObjString*>(tokens->At(0)); ostr = dynamic_cast<TObjString*>(tokens->At(0));
str = ostr->GetString(); str = ostr->GetString();
// check if the line is just a '+'; if so nothing to be done // check if the line is just a '+'or a userFcn; if so nothing to be done
if (str.Contains("+")) if (str.Contains("+") || str.Contains("userFcn"))
continue; continue;
// search the theory function // search the theory function
for (unsigned int j=0; j<THEORY_MAX; j++) { for (unsigned int j=0; j<THEORY_MAX; j++) {
@ -1170,6 +1182,8 @@ if (first) {
cout << endl << "-> " << i << ": " << fUserParam[i]; cout << endl << "-> " << i << ": " << fUserParam[i];
} }
cout << endl; cout << endl;
cout << endl << ">> t=" << t << ", function value=" << (*fUserFcn)(t, fUserParam);
cout << endl;
} }
return (*fUserFcn)(t, fUserParam); return (*fUserFcn)(t, fUserParam);

View File

@ -216,6 +216,7 @@ class PTheory
TF1 *fStaticKTLFFunc; TF1 *fStaticKTLFFunc;
TString fUserFcnClassName; ///< name of the user function class for within root TString fUserFcnClassName; ///< name of the user function class for within root
TString fUserFcnSharedLibName; ///< name of the shared lib to which the user function belongs
PUserFcnBase *fUserFcn; ///< pointer to the user function object PUserFcnBase *fUserFcn; ///< pointer to the user function object
mutable PDoubleVector fUserParam; ///< vector holding the resolved user function parameters, i.e. map and function resolved. mutable PDoubleVector fUserParam; ///< vector holding the resolved user function parameters, i.e. map and function resolved.