I have some data and bkg histograms, which I initially can plot alright…
However, when I do fit the data-bkg histogram ie like
# Plot bkg+bkg2 (green dashed)
hist_bkg_plus_bkg2 = hist_bkg1.Clone()
hist_bkg_plus_bkg2.Draw(" L same") # Draw bkg+bkg2 (green dashed)
# Fit data-bkg distribution with a Gaussian (blue)
hist_data_minus_bkg = hist_data_minus_bkg.Clone()
fit_data_minus_bkg = hist_data_minus_bkg.Fit("gaus", "S", "", -50, 50)
then even if I do not plot the fitted function, it appears on canvas, whereas the data (red points in first plot) bit also bkg (green points in previous plot) disappear, ie only the data-bkg and the fit are drawn. Even if I try to redraw the other histograms, they still do not appear on the canvas
What am I missing?
Thanks for posting. I think I miss some context to help out here: could you please post a minimal reproducer of the behaviour which I could also run? I am confident that once we have those few lines we can fix this.
Thanks for your reply. I am attaching some small example code/files to reproduce the problem
data.root (304.6 KB)
wjets.root (346.6 KB)
qcd.root (473.5 KB)
fitSimple.py (3.7 KB)
Once you have done a fit on a histogram, the fitting function becomes an item in the list of functions of this histogram. When the histogram is drawn the list of functions is also drawn. If you want to draw only the histogram you need the option “HIST”:
I hope it helps.
Sorry, maybe it is trivial, but can you point me what commands I should use to get on the canvas
.- the data histo
.- the data-bkg histo
.- the fit curve as well
I ve been trying to use
"hist" as you say, but I cannot make it to work and get all three curves on the canvas.
auto C = new TCanvas();
auto h1 = new TH1D("h1","Background", 100,-1,1);
auto h2 = new TH1D("h2","Data", 100,-1,1);
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.