I have a specific problem for a paper that is going to publication. I have a data distribution that is fit to a Gaussian. The statistics box shows just the RMS of the data, and the mean and sigma of the fit. However, when we rounded to the correct number of sigdigs, the mean comes out “-0.0”, since the mean is just a smidgin on the negative side of zero. One of the reviewers of the draft paper didn’t like this, and so we thought to “FixParameter” the mean to 0.0 since it’s so close to zero. However, we’ve already set “v=1” in SetOptFit in order to suppress displaying the constant term, which is also fixed to the best value specifically for this reason.
So when you fix the mean at 0.0, the mean disappears from the stats box! But if you set v=0, then the constant term shows up too, which we don’t want.
I just haven’t got the time to gin up an example. I thought the problem was obvious from the ROOT documentation. So I hacked my own local ROOT installation, particularly THistPainter.cxx, so that it would skip putting the constant parameter into the stats box. Then I can force it to display “all” fit parameters and get what I want.
I am facing a similar problem. Here is an attached example that reproduces this problem:
#include <TH1F.h>
#include <TRandom.h>
#include <TCanvas.h>
#include <TMath.h>
#include <iostream>
void test() {
// Create a canvas to draw the histogram
TCanvas *c1 = new TCanvas("c1", "Gaussian Histogram", 800, 600);
// Define histogram parameters
int nBins = 100; // Number of bins
float xMin = 0; // Minimum x value (for the half Gaussian, start from 0)
float xMax = 10; // Maximum x value
TH1F *hist = new TH1F("hist", "Gaussian Histogram;X;Entries", nBins, xMin, xMax);
// Define Gaussian parameters
double mean = 5.0; // Mean of the Gaussian
double sigma = 1.0; // Standard deviation of the Gaussian
// Generate random Gaussian numbers and fill the histogram
TRandom random;
for (int i = 0; i < 10000; ++i) {
double value = random.Gaus(mean, sigma);
hist->Fill(value);
}
cout << Form("xMin: %f....xMax: %f",xMin,xMax) << endl;
TF1 *fit = new TF1("fitter","gaus",xMin,xMax);
fit->FixParameter(1,mean);
hist->Fit("fitter","RB");
// Draw the histogram
hist->Draw();
gStyle->SetOptFit(1);
}
When the FixParameter is commented, I see the fit mean as well, in the stats.
I am using ROOT 6.26.14
Ahh, yes, it does not fit properly, but my primary concern was that once FixParameter() is used, that particular parameter (mean in this case) is not displayed in the fit stats. However, I found that it can be enabled by using SetOptFit(1112).