Set some default behaviour when starting ROOT

For some reason, in ROOT the “OptFit” by default is 0, even when I have fitted a histogram.
I would like to set this option to 1 by default, how can I do this.
I know that I could set things in the “.rootrc” file, but I haven’t found how to set “gStyle->SetOptFit(1)” in .rootrc so that ROOT understands it.



1 Like

According to the documentation for TStyle::SetOptFit the default is 0111 (not the octal number) or ‘cev’ meaning chisquare / ndf, errors and name / values.

Put gStyle->SetOptFit(1) in the file rootlogon.C in the directory where you are starting ROOT.

After testing with 6.08.06, I agree that the default for SetOptFit is 0. This does not agree with the documentation nor the declaration of SetOptFit in TStyle.h:

void SetOptFit(Int_t fit=1);

An example:

#include <TH1D.h>
#include <TStyle.h>

   TH1F *h = new TH1F("h","H", 100, -2, 2);

   h->FillRandom("gaus", 500);


   printf("SetOptFit: %d\n", gStyle->GetOptFit());

@ksmith Seems to me the behavior is correct . By default gStyle->SetOptFit(); is not called. So the flag to turn on or off the fit option is 0. As soon as you call gStyle->SetOptFit(); the default value for the parameter value is set (i.e. 1). That’s what I can see with all the root version I have:

root [0] printf("SetOptFit: %d\n", gStyle->GetOptFit());
SetOptFit: 0
root [1] gStyle->SetOptFit();
root [2] printf("SetOptFit: %d\n", gStyle->GetOptFit());
SetOptFit: 1
root [3] 

From the documentation:

The parameter mode can be = pcev (default = 0111)

which would imply the default value be 111. Instead we have one, although at the end of the documentation we have:

Note: gStyle->SetOptFit(1) means "default value", so it is equivalent to gStyle->SetOptFit(111)

This is at the very least confusing. Is 1==111? What if I only want the values and no probability or errors?

The meaning of default here is confused with the two choices, default when ROOT starts or default when the method is called. SetOptStat behaves such that the default is set when ROOT starts.

I do no think we can change this behavior for backward compatibility version as said in SetOptStat

What about clarification of the meaning of the work default? It seems that SetOptStat and SetOptFit are slightly different. And this brings up the question why is SetOptFit not set to 111 on startup?

Thanks for the remark. Done in the master.

1 Like

Great addition for the documentation. By the way, you misspelled null.

Fixed. Thanks to have seen it.

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