From 3b595f0730144134db56853dbf6c3278d442c88c Mon Sep 17 00:00:00 2001 From: nemu Date: Mon, 9 Jun 2008 12:11:37 +0000 Subject: [PATCH] some more work in userFcn --- src/classes/PFitter.cpp | 28 ++++++++++++++++++----- src/classes/PTheory.cpp | 50 ++++++++++++++++++++++++++--------------- src/include/PTheory.h | 1 + 3 files changed, 55 insertions(+), 24 deletions(-) diff --git a/src/classes/PFitter.cpp b/src/classes/PFitter.cpp index 1dd5d747..7a2f7a15 100644 --- a/src/classes/PFitter.cpp +++ b/src/classes/PFitter.cpp @@ -314,10 +314,15 @@ bool PFitter::ExecuteMigrad() fMnUserParams = fFcnMin->UserParameters(); // 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 - 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()) { cout << endl << "**WARNING**: PFitter::ExecuteMigrad(): Fit did not converge, sorry ..."; return false; @@ -367,10 +372,16 @@ bool PFitter::ExecuteMinimize() fMnUserParams = fFcnMin->UserParameters(); // 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 - 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()) { cout << endl << "**WARNING**: PFitter::ExecuteMinimize(): Fit did not converge, sorry ..."; return false; @@ -692,10 +703,15 @@ bool PFitter::ExecuteSimplex() fMnUserParams = fFcnMin->UserParameters(); // 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 - 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()) { cout << endl << "**WARNING**: PFitter::ExecuteSimplex(): Fit did not converge, sorry ..."; return false; diff --git a/src/classes/PTheory.cpp b/src/classes/PTheory.cpp index 0a00ca9b..d628cb67 100644 --- a/src/classes/PTheory.cpp +++ b/src/classes/PTheory.cpp @@ -183,8 +183,14 @@ PTheory::PTheory(PMsrHandler *msrInfo, unsigned int runNo, const bool hasParent) str = ostr->GetString(); // if userFcn, the first entry is the function name and needs to be handled specially - if ((fType == THEORY_USER_FCN) && (i == 1)) { - fUserFcnClassName = str; + if ((fType == THEORY_USER_FCN) && ((i == 1) || (i == 2))) { +cout << endl << ">> userFcn: i=" << i << ", str=" << str.Data() << endl; + if (i == 1) { + fUserFcnSharedLibName = str; + } + if (i == 2) { + fUserFcnClassName = str; + } continue; } @@ -259,22 +265,28 @@ PTheory::PTheory(PMsrHandler *msrInfo, unsigned int runNo, const bool hasParent) if (!fUserFcnClassName.IsWhitespace()) { cout << endl << ">> user function class name: " << fUserFcnClassName.Data() << endl; if (!TClass::GetDict(fUserFcnClassName.Data())) { - char libname[256]; - sprintf(libname, "lib%s.so", fUserFcnClassName.Data()); // add path needed?? - if (gSystem->Load(libname) < 0) { - cout << endl << "**ERROR**: PTheory: user function class '" << fUserFcnClassName.Data() << "' not found. See line no " << line->fLineNo; + if (gSystem->Load(fUserFcnSharedLibName.Data()) < 0) { + cout << endl << "**ERROR**: PTheory: user function class '" << fUserFcnClassName.Data() << "' not found."; + cout << endl << " Tried to load " << fUserFcnSharedLibName.Data() << " but failed."; + cout << endl << " See line no " << line->fLineNo; fValid = false; + // clean up + if (tokens) { + delete tokens; + tokens = 0; + } + return; } - } else { // invoke user function object - fUserFcn = 0; - fUserFcn = (PUserFcnBase*)TClass::GetClass(fUserFcnClassName.Data())->New(); -cout << endl << ">> fUserFcn = " << fUserFcn; - if (fUserFcn == 0) { - cout << endl << "**ERROR**: PTheory: user function object could not be invoked. See line no " << line->fLineNo; - fValid = false; - } else { // user function valid, hence expand the fUserParam vector to the proper size - fUserParam.resize(fParamNo.size()); - } + } + // invoke user function object + fUserFcn = 0; + fUserFcn = (PUserFcnBase*)TClass::GetClass(fUserFcnClassName.Data())->New(); +cout << endl << ">> fUserFcn = " << fUserFcn << endl; + if (fUserFcn == 0) { + cout << endl << "**ERROR**: PTheory: user function object could not be invoked. See line no " << line->fLineNo; + fValid = false; + } 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 ostr = dynamic_cast(tokens->At(0)); str = ostr->GetString(); - // check if the line is just a '+'; if so nothing to be done - if (str.Contains("+")) + // check if the line is just a '+'or a userFcn; if so nothing to be done + if (str.Contains("+") || str.Contains("userFcn")) continue; // search the theory function for (unsigned int j=0; j " << i << ": " << fUserParam[i]; } cout << endl; + cout << endl << ">> t=" << t << ", function value=" << (*fUserFcn)(t, fUserParam); + cout << endl; } return (*fUserFcn)(t, fUserParam); diff --git a/src/include/PTheory.h b/src/include/PTheory.h index 1bd36828..b0d910cb 100644 --- a/src/include/PTheory.h +++ b/src/include/PTheory.h @@ -216,6 +216,7 @@ class PTheory TF1 *fStaticKTLFFunc; 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 mutable PDoubleVector fUserParam; ///< vector holding the resolved user function parameters, i.e. map and function resolved.