I have written some analysis code to output my results as histograms, so that I can then scale, stack, and rebin however I want without having to run through the data files again.

I now need to change the x-axis range from the initial (0,1000) to (0,500), I have tried using

but it does nothing more than changing the axis to (0.,500.) the bins in the histogram does not change with it (ie a peak at 200 will now be at 100).

Does any one know how to do this without using something like SetRangeUser, which requires the use of the index of the bins?

I have tried that already, however it also only does exactly what I described above, the bins do not change accordingly with the range of the axis, ie the peak at 200 now shows at 100, after going from (0,1000) to (0,500).

I have looked at that thread and doesn’t seem to have the answer that I am looking for.

I have produced a histogram that initially has the range (0,1000) on the x-axis, and I observe a peak at 200, 1/5 of the whole x-axis counting from the left.

I now only want to keep the left half of the histogram, the (0,500) range. If I use SetLimits() like I said above, the only change that I see is the numbers on the axis, in this case divided by 2.

The entire histogram however do not change with it, the peak that was initially lined up at the 200 mark on the initial x-axis, now lines up with the 100 mark. Remaining at the 1/5 mark of the entire x-axis range counting from the left, instead of moving accordingly to the new location of the 200 mark, which would now be 2/5 of the whole axis counting from the left.

Again I have looked at SetRangeUser(), it doesn’t change anything.

I hope this longer explanation of my problem has made things more clear, rather than complicating it even more.

One way to help you further would be to have a small macro reproducing the problem.

You can try one more thing:
In the graphics window set the range you need using the mouse along the X axis.
If you manage to get what you want, then do “Save As …” in a .C file from the the “File” canvas menu.
Then look at that .C file to see what it does.

Now it is more clear.
Still, when you say “I now only want to keep the left half of the histogram”, do you mean that you want to “completely remove” the remaining bins (i.e. the “right half”) from your histogram, or do you mean that they can stay in your histogram and you simply want to display the “left half” only?
In the latter case, for a TH1 I am usually using something like this:
histo->Draw();
histo->SetAxisRange(xmin, xmax, “X”);
histo->SetAxisRange(ymin, ymax, “Y”);
histo->Draw(); // make sure it’s redrawn
If I am dealing with a THStack of several TH1 histograms, I am usually using something like this:
stack->Draw(“H”);
stack->GetXaxis()->SetLimits(xmin, xmax);
stack->SetMinimum(ymin);
stack->SetMaximum(ymax);
stack->Draw(“H”); // make sure it’s redrawn
If you want to “delete” unwanted bins from your histogram (i.e. the “right half”) then I don’t know of any easy way (except creating a new histogram with “cut axes” and copying the “wanted” contents only).