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);
myfit->SetParameters(50.,1.);
histo->Fit(myfit,"R");
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.
Still the same issue as shown in the opening post. Thank you for your help though!
Edit:
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)
j=0
for elem in time: # fill histogram with elements from data
j += 1
for i in range (0,int(count[j-1])):
histoa.Fill(elem)
canvasa = ROOT.TCanvas("name", "title", 1024, 768)
histoa.Fit("expo")
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);
myfit->SetParameters(50.,1.);
histo->Fit(myfit,"R");
}
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.
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.