TF3 access to class members

Hi rooters,

I want to integrate a function F(x,y,z) using the TF3::Integral method. I read (x,y,z,F) from an ascii and I don’t want to use global variables, so I’d like to do the following:

[ul]
[li] read (x,y,z,F) and store them in a class CData.[/li]
[li] define a function iFunc with access to CData private members.[/li]
[li] use iFunc to construct a TF3:

is there a way to do this?

Thanks in advance
Pablo

edit: I’ve tried to define iFunc as a CData friend function and as a CData member functions without success

this have worked:
header:

class CData{
...

  Double_t GetIntegral();
  static Double_t iFuncInterface(Double_t *point,Double_t *par);

...

  private:
...

  TF3* iFunc;
  static std::map<int,std::map<int,std::map<int,double > > > F;

...
}

and the implementation:

std::map<int,std::map<int,std::map<int,double > > > CData::F;

Double_t CData::iFuncInterface(Double_t *point,Double_t *par){
  Double_t x = point[0];
  Double_t y = point[1];
  Double_t z = point[2];
...
F Interpolation
...  

  return Fvalue(x,y,z);
};

...

Double_t CData::GetIntegral(){
  iFunc = new TF3("iFunc",iFuncInterface,0,1,0,1,0,1,0);
  return iFunc->Integral(0,1,0,1,0,1);
};

Hi,

I am surprised this works for you, because it shouldn’t. The correct way to make a TFx object using a member function of a class and without using a global object, is to do as explained in

root.cern.ch/root/htmldoc/TF1.html#F5

The example is for a TF1, but it works also for a TF3. One needs to add in the constructor the range values for the y and z axis, i.e. using the constructor defined at line 53 of TF1.h: root.cern.ch/root/htmldoc/src/TF3.h.html#53

Best Regards

Lorenzo

Thanks Lorenzo I will implement your proposal, it is more elegant.

The key in “my” method is the static definition of iFuncInterface, but I’m not completely sure why. But for sure it works!

Cheers,
Pablo

Hi,

I understood you wanted to access data member of your CData class. In that case the member function cannot be static

Lorenzo

!!!

If I understand it correctly, static members of classes are instanced on the first instance of the class, and they are the same for all the instances off the class.
For sure I’m using classes with members defined as static!