TTree::Draw, underlying type

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?

Whoops, I forgot to include an image of the generated plot.

create your histogram h before doing TTree::Draw and do “x>>h”

Thank you for the suggestion. I was hoping to be able to change the default type, so that I would not need to define the histogram in advance. That way, I could put the change into my rootlogon() script, then use TTree::Draw without needing to stop and think each time whether any bin will have more than 16.7 million counts. With the current solution, it needs to be applied to each histogram individually, ahead of time.