Fitting a histogramm with additional data

Hi rooters,

I’m new to root and have the fallowing problem.

I’ve a .txt with 5 columns. I’ve written a program which reads this file and writes the values into different histograms. There are two kinds, the first ones with many points and the 2nd ones with less points.
The histograms consist of a temperature on the y-axis and the voltage on the x-axis.That’s part one of the program, called histkalibpro.c. Works fine so far.

The other part of the program should use one of the histograms
(called hist2_Tr) to make a fit. My problem is, that I can’t write a function for the fit which can use the values of another histogram ( called hist2_Tf ). I tryed to save them as TH2D, TH1D and TProfile. I got the best results saving hist2_Tr as a TProfile

But saving hist2_Ta as TProfile and reading the values with

Double_t xx = x[0];
Int_t binx = hist2_Tf->GetXaxis()->FindBin(xx);
Ta = hist2_Tf->GetBinContent(binx);

gave me several zeros in the fit,
saving them as TH2D and reading the values with

Double_t xx = x[0];
Double_t xx = x[0];
Int_t binx = hist2_Tf->GetXaxis()->FindBin(xx);
Int_t biny = hist2_Tf->GetYaxis()->FindBin(yy);
Ta = hist2_Tf->GetBinContent(binx,biny);

gave me exactly nothing.
I now managed it to get it working with saving the hist2_Ta as a TH1D and reading the data with

Double_t xx = x[0];
Int_t binx = hist2_Tf->GetXaxis()->FindBin(xx);
Ta = hist2_Tf->GetBinContent(binx);

It works but I’m not sure if the program is doing what I want. And there is still the problem, that the function which is called by the fit reads the data values several times.

I’ve attached my program code and a file with values. Please help, I m already trying to get this to work for about a week.
fitkalibpro.c (3.26 KB)
histkalibpro.c (3.48 KB)
100118.txt (42.5 KB)

I already managed to get rid of some smaller mistakes I made, but I’ve still no solution for my problem. I would be very grateful for any kind of tips.

I’ve attached the new files.
fitkalibpro.c (3.4 KB)
histkalibpro.c (3.42 KB)

The function (in fact histogram) with which you fit your profile is not a good model. If you replace your function eg by a polynomial of degreee2 it will fit nicely.
Try replacing

hist2_Tr->Fit(fTMP,"MR"); by

hist2_Tr->Fit("pol2","m");

Rene

Hi Rene,

thx for the response. The problem is that I need to use the other variables to get a good view on the influence of the outer temperature and the inner temperature on the current ( in this example with the stefan-boltzmann law ).

Therefore I can’t just use a polynom, even though a pol3 fits nearly perfect, but have to involve other variables.

Do you know what I mean?

I just don t know how I can modify this function to read the values without problem.

Double_t formel(Double_t *x, Double_t *par)
{

     Double_t xx = x[0];       
     Int_t binx = hist2_Tf->GetXaxis()->FindBin(xx);
     Tf = hist2_Tf->GetBinContent(binx)+273.15;
     
     Tr=Tf;
     //Tr = wurzel(((x[0]*x[0]*x[0]*x[0])-(5.67e-8*par[0]*Tf*Tf*Tf*Tf))/(5.67e-8*par[1]),4);                                               

}

Lorenzo will help you once he will be back.

Rene

Thx a lot. This really drives me nuts cause I’ve already spend several days trying to get this work.

Hi,

I have not understood how you want to build your parameterize model for fitting. You can use another histogram in the model, but you need to define what are the parameters and have a dependency on those.

In your program nothing works, because your model (the TF1) has no dependency on the parameters

Best Regards

Lorenzo

Hi Lorenzo,

thx for the response, but I don t understand what you mean. Can you give me an example?

Hi,
your fitting function “formel”, has no dependency on the parameters par.
Whatever value of par you input the result is the same.

If you use the commented code, probably is fine, if the function is implemented correctly.

Lorenzo

Ah now I know what you mean. Tr = Tf was just a test to look if the program reads the data of the histogram.

Normally I use the other formulas that are under this one. So the program should work?

Yes, the program should work if the function is correct and if it can reproduce the data, otherwise you might have problems with the fitting converging to a sensible solution

Lorenzo

Perfect, thx alot for your help. Just one small question:

Can I modify my function in some way, that it reads the data just once? And why can’t I get the values of my histogram, if I try to change it to a TH2D and read the data with GetBinContent(binx,biny) ?

Hi,
I am not sure I have understood your questions.

You can copy your histogram data in a vector and use that in implementing the function. You could pre-calculate also some constants (not depending on the x variable or the parameters) if you need to speed up the function evaluation

You should not use a TH2D if your data consists of y(x) values (i.e. y values as function of x). A TH2 represents z values as function of (x,y).

Lorenzo