some more work in userFcn
This commit is contained in:
parent
660cf9e014
commit
3b595f0730
@ -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;
|
||||
|
@ -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<TObjString*>(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<THEORY_MAX; j++) {
|
||||
@ -1170,6 +1182,8 @@ if (first) {
|
||||
cout << endl << "-> " << i << ": " << fUserParam[i];
|
||||
}
|
||||
cout << endl;
|
||||
cout << endl << ">> t=" << t << ", function value=" << (*fUserFcn)(t, fUserParam);
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
return (*fUserFcn)(t, fUserParam);
|
||||
|
@ -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.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user