p73
May 1, 2017, 11:10am
1
I have a class GKF
in which member function I want to use Functor
in the following way:
class GKF {
protected:
vector<GKP*> Photons;
public:
...
double Chi2_plus_Constraints( const double* );
int Perform_Minimization( const char*, const char* );
...
and definitions:
...
double GKF::Chi2_plus_Constraints( const double* x ){
//some operations with x[];
return Chi2 + Constraints;
}
int GKF::Perform_Minimization( const char* name, const char* algo ){
ROOT::Math::MInimizer *minimizer =
ROOT::Math::Factory::CreateMinimizer( name, algo );
...
// I want to have something like this
ROOT::Math::Functor functor( &GKF::Chi2_plus_Constraints, NDF );
...
minimizer->SetFunction( functor );
}
Is it possible? NOTE: I want objective function to be a member function of class in which I use Math::Functor
.
Thanks in advance.
Pointers to member functions need to be associated with a specific object. Basically the compiler needs to know what this
variable to pass to the member function. So looking at the documentation at https://root.cern.ch/root/html/src/ROOT__Math__Functor.h.html#374 it looks like the Functor has a constructor taking object, pointer to member function and dimension. So that should probably work. (Disclaimer: I don’t know anything about the ROOT::Math::Minimizer.)
p73
May 2, 2017, 3:45am
3
Should I write that in the following way:
ROOT::Math::Functor functor( this, Chi2_plus_Constraints, nDim );
or in this way?
ROOT::Math::Functor functor( this, GKF::Chi2_plus_Constraints, nDim );
or something different?
p73
May 2, 2017, 12:33pm
4
So far it is working ( I say working but in real life it has been just compiled without errors of compilation ) in this way:
ROOT::Math::Functor( this, &GKF::Chi2_plus_Constraints, nDim );
1 Like
system
Closed
May 16, 2017, 12:33pm
5
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.