{ TTree* tree = new TTree("tree", "my tree"); Double_t rand; tree->Branch("gaus", &rand, "gaus/D"); for (Int_t i = 0; i < 100; i++) { rand = gRandom->Gaus(5, 2); tree->Fill(); } tree->Draw("gaus>>htemp"); TH1F* h = (TH1F*)gROOT->FindObject("htemp"); Int_t before_nBins = h->GetNbinsX(); // THE CULPRIT (given htemp is not fully initialized) h->SetBinContent(before_nBins+1, 100); Int_t after_nBins = h->GetNbinsX(); std::cout << "Before nBins: " << before_nBins << std::endl; std::cout << "After nBins: " << after_nBins << std::endl; }