Histogram from MeV to GeV

I want to transform an histogram binned in MeV to GeV. It’s an easy an common task. To do it I need to access to the original binning but:

TH1F h("h", "h", 3, 0, 10)
h.GetXaxis()->GetXbins()->fN

returns 0

what’s wrong?

double xmin = h->GetXaxis()->GetXmin(); double xmax = h->GetXaxis()->GetXmax(); h->SetLimits(xmin/1000,xmax/1000);
Rene

Hi. Rene, your last line is missing a GetXaxis() call.

I always wondered how to do this… I’ve always recreated histograms to change scales like this. Thanks!

[quote=“brun”]double xmin = h->GetXaxis()->GetXmin(); double xmax = h->GetXaxis()->GetXmax(); h->SetLimits(xmin/1000,xmax/1000);
Rene[/quote]

It doesn’t work when the binning is defined with an array

Hi experts,

Sorry for reopening this very old thread, but it is very much related to what I too want. I want to change the axislimits from MeV to GeV. The above prescription works fine for normal binning, but if the binning is defined in an array it didnt work. Is there a work around for this?

Thanks

[url]Can we shift histogram for several channels?