TF1 function definition within a class

Dear ROOTers,

I wrote a very simple class to fit a histogram with a superposition of two other histograms. The fit is performed defining a TF1 function whose parameters are simply the integrals of the two histograms used for the sum. The TF1 function is defined using a Double_t method defined within the class itself. I attach the .cxx and .h of the class (I retained the essential parts only) to illustrate the problem: when I try to compile the class within ROOT, the compiler complains because it apparently cannot recognize the method I used to define the TF1:

no matching function for call to ‘TF1::TF1(const char [12], , Double_t&, Double_t&, int)

The problem disappears if I declare the Double_t method as static, but then the compiler complains because I cannot use the TH1F members of the class inside the Double_t method.

What should I do?

Thanks!
Antonio
testClass.cxx (1.48 KB)
testClass.h (753 Bytes)

Hi,
you should create a TF1 as shown in the documentation of the class for last case (TF1 from a member function of a class):
root.cern.ch/root/htmldoc/TF1.html#F5

Lorenzo

Hi Lorenzo,

a function created in this way can be used as a fit function? May I set its parameters in the usual way and use the Fit(…) methods of TH1D and TGraph without exceptional cares?

Thanks,
Antonio

[quote=“moneta”]Hi,
you should create a TF1 as shown in the documentation of the class for last case (TF1 from a member function of a class):
root.cern.ch/root/htmldoc/TF1.html#F5

Lorenzo[/quote]

Yes. it is a TF1 object and can be used in all the methods which takes it as input.

The only limitation is the same one as for free C functions, it cannot be stored in a file, since it requires some code. So, when you write in a file (or when you use TF1::Clone) the function will be sampled in Npx points and only these values will be saved

Lorenzo

Hi Lorenzo,
thank you for clarifying the point. The machinery now works fine :slight_smile:

Antonio

[quote=“moneta”]Yes. it is a TF1 object and can be used in all the methods which takes it as input.

The only limitation is the same one as for free C functions, it cannot be stored in a file, since it requires some code. So, when you write in a file (or when you use TF1::Clone) the function will be sampled in Npx points and only these values will be saved

Lorenzo[/quote]