Can SetBinContent change the number of binn?!

Hi rooters,
I am observing an extremely strange thing. Can SetBinContent change the number of bins?

This is the code I have

    cout<<h->GetNbinsX()<<endl;
    h->SetBinContent(h->GetNbinsX()+ 1, scale);
    cout << "Finish Lumi normalizing histogram.\n";
    cout<<h->GetNbinsX()<<endl;

and this is the output

18
Finish Lumi normalizing histogram.
36

Try:
h->ResetBit(TH1::kCanRebin);

Hi ,
Where should I add this piece of code?
TH1::kCanRebin is not defined in root!

Cheers

It exists in ROOT 5 (In compiled code #include “TH1.h”).
It seems that some genius removed it in ROOT 6 :mrgreen:
So, in ROOT 6, try (in compiled code #include “TAxis.h”):
h->GetXaxis()->SetCanExtend(kFALSE);

Yes, it is written here.

thanks a lot,
I tried it and it works. However, I still do not fundamentally understand why the number of bins would change when I call SetBinContent() function.
I only want to set the content of the overflow bin!

Cheers

Hi
if you dont like the way it is implemented you may exploit
the inheritance of say TH1F from TArrayF:

TH1F h("zz", "yy", 10,0,10);
h[2] = 2;   // bin 2
h[0] = 34;  // underflow
h[11] = 26; // overflow
h[12] = 34;
Error in <TArrayF::operator[]>: index 12 out of bounds...

Otto

Just be aware that TH1F::SetBinContent automatically performs some [url=https://root-forum.cern.ch/t/bin-errors-with-addbincontent-and-sumw2/19465/5 side actions[/url] (which are not done if you go via the TArrayF shortcut).
In any case, after you manually modify bin contents, I think you should call TH1::ResetStats.