Is there a way to change the default type that TTree::Draw uses to make a new histogram? Asking, because I have run into issues with rounding errors when using TH1F, and so I would like to make TTree::Draw default to using either TH1I or TH1D when creating new histograms.
Below is an example script which demonstrates the issue. It makes a tree, fills it 20 million times with the same value, then draws it. The top plot is done without creating a histogram ahead of time. The bottom plot is done by first creating a TH1I, then drawing into that histogram. Note the y-axis scale. Due to using floats as the underlying array type, the TH1F only fills the bin up to 16,777,216, while the TH1I has the correct number of counts.
{
TTree* t = new TTree("t","t");
int x = 5;
t->Branch("x", &x, "x/I");
for(int i=0; i<2e7; i++){
t->Fill();
}
TCanvas* c1 = new TCanvas;
c1->Divide(1,2);
c1->cd(1);
t->Draw("x>>hist_TH1F(10,0,10)");
c1->cd(2);
TH1I* hist_TH1I = new TH1I("hist_TH1I","hist_TH1I",10,0,10);
t->Draw("x>>hist_TH1I");
}
I would like to be able to use TTree::Draw without worrying about whether the bin content will exceed 16.7 million, and so I would like to change the default histogram type used by TTree::Draw. Is this possible?