Fit function not drawn completely


I am experiencing a weired issue: The fit function is not drawn over the whole range:

using ROOT 6.08/06 and

TH1F *histo = new TH1F("histo","#Delta t (100ms)",50,0.,0.1);
TF1 *myfit = new TF1("myfit","[0]*exp(-[1]*x)",0.03, 0.1);

and the followoing data: histdata.txt

However, only if I change the fitting range to [0., 0.1] the fit function is drawn over the whole range as expected.

Do you have an idea why this happens? And why is the fitting graph not solid?

PS: It’s really really weird. With ROOT 5.34 it works as expected. Since I moved to a self compiled ROOT 6.08/06 and ROOT master on Kubuntu 16.10 64 bit I encounter many strange issues like the one described.
I start my files with root -l file.C+ to check for any errors, but there are none actually.

Try: TH1F *histo = new TH1F("histo", "#Delta t (100ms)", 50, 0., 0.1); // ... fill the histogram ... and then ... TF1 *myfit = new TF1("myfit", "[0]*exp(-[1]*x)", 0., 0.1); myfit->SetParameters(50., 1.); histo->Fit(myfit, "0", "", 0.03, 0.1); histo->Draw(); myfit->SetLineStyle(1); myfit->Draw("same");

Thank you for your reply. I tried your solution:

The following gives me the same result as before:

 TH1F *histo = new TH1F("histo", "#Delta t (100ms)", 50, 0., 0.1);
 TF1 *myfit = new TF1("myfit", "[0]*exp(-[1]*x)", 0., 0.1);
 myfit->SetParameters(50., 1.);
 histo->Fit(myfit, "0", "", 0.03, 0.1);


If the histo is not drawn at all at least the beginning of the fit can be seen …

  // histo->Draw();

I run out of ideas :frowning:

Try: TH1F *histo = new TH1F("histo", "#Delta t (100ms)", 50, 0., 0.1); // ... fill the histogram ... and then ... TF1 *myfit = new TF1("myfit", "[0]*exp(-[1]*x)", 0., 0.1); myfit->SetParameters(50., 1.); histo->Fit(myfit, "", "", 0.03, 0.1); TF1 *f = histo->GetFunction("myfit"); if (f) { f->SetRange(histo->GetXaxis()->GetXmin(), histo->GetXaxis()->GetXmax()); f->SetLineStyle(1); if (gPad) { gPad->Modified(); gPad->Update(); } }

Still the same issue as shown in the opening post. Thank you for your help though!


I managed to install PyROOT and Jupyter Notebook on my machine together with the troublesome ROOT installation and wrote a simple python script to do the fitting and it just works!

Why the heck does the C-file not work as expected?

file_name = "histo.txt"
time, count = np.genfromtxt(file_name, unpack=1, usecols=(0,1))
n = len(count)

histoa = ROOT.TH1F("histo", "Exponential", n, 0, 0.1)

for elem in time: # fill histogram with elements from data
    j += 1
    for i in range (0,int(count[j-1])):
canvasa = ROOT.TCanvas("name", "title", 1024, 768)
histoa.Draw("")  # draw histogram
canvasa.SaveAs("histo.png") # save histogram


I cannot reproduce that, it works just fine for me with this script:

void T() {
   TH1F *histo = new TH1F("histo","#Delta t (100ms)",50,0.,0.1);
   string line;
   ifstream in("histdata.txt");
   while (getline(in, line)) {
      std::stringstream isstr(line);
      double x = -1.;
      char comma;
      int weight = 0;
      isstr >> x >> comma >> weight;
      histo->Fill(x, weight);
      cout << "Filled " << weight << " at " << x << '\n';
   TF1 *myfit = new TF1("myfit","[0]*exp(-[1]*x)",0.03, 0.1);

I’d assume that your build or install is broken - maybe because it mixes libraries / headers. For a running build you can check with gInterpreter->GetSharedLibs() whether all libraries come from the proper location; .files shows whether all headers come from the proper location.

If all of that is correct then you might have a build problem; we have just fixed an issue (ROOT-8698) in our CMake configuration where the build would pick up existing ROOT headers (from an unrelated build) while building ROOT. That’s fixed in the master and the v6-08-00-patches pranch - it just missed v6.08/06.

Cheers, Axel.

1 Like

Thanks Alex for your time. I run your macro with v6-09/01 and the result looks like this:

I also ran gInterpreter->GetSharedLibs() and files:
GetharedLibs.txt (19.4 KB) Files.txt (478 Bytes)

They look fine in my opinion. I will test the lastest ROOT head soon and otherwise I will stick probably with python for the time being.

Edit: Root 6.09/03 did not bring me any further.



Super weird. And that’s kubuntu 16.10, default compiler? Which window system do you use - wayland?


It is indeed super weird! I use essentially the default setup on Kubuntu.
Though I updated some plasma packages ( kubuntu-ppa/backports), the issue existed already before.
For compilation I tested both the GCC and Clang compiler with the same results.

If you have look at the last posted plot, it’s not only that the graphics are wrong, also the fit does not really fit (pun intended).

A few details about my system:

x11 window system
Kubuntu 16.10 4.8.0-41-generic x86_64 GNU/Linux
cmake 3.5.2-2ubuntu1 
llvm-defaults (0.34)
clang version 3.8.1-12ubuntu1
gcc 6.2.0-5ubuntu12

I wanted to test the precompiled version of ROOT but I could not get it running due to missing Cling libraries, but this may be reason to open another thread. :frowning:

I could solve this problem by using UXA instead of SNA for my Intel HD graphics card:

Section "Device"
    Identifier  "Intel Graphics"
    Driver      "intel"
    Option      "AccelMethod"  "uxa"
    #Option      "AccelMethod"  "sna"


1 Like

Wow. That’s terrible. Thanks for reporting, I would never have found out!


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.