I have a simple question:
I have a histogram defined with variable bin width, now I want to define TFrame with the same variable bin width. But the frame drawn with wrong x-axis binning.
Here are a part of the definition of the histogram and the frame
const int NMbins = 5;
double Mbins[6]={0.,25.,50.,200., 500.,1000.};
TH1F *hPFMET = new TH1F("hPFMET","",NMbins, Mbins);
Now in a new macro I want to create a Frame with the same variable binning to draw this histogram on top, what I did
const int NMbins = 5;
double Mbins[6]={0.,25.,50.,200., 500.,1000.};
hframe= new TH2F("hframe","hframe",NMbins,Mbins,1000, 0.000001, 100000.);//
I get my histogram but the x axis has a different binning.
Thanks for your reply, I tried the first proposed solution but I see that the x-axis range didn’t change. I run your macro and attached the plot. rebinning_frame.pdf (14.4 KB)
Your plot looks perfectly fine.
I have no idea what you’re trying to achieve.
If you want the y-axis from 0.000001 to 100000., simply instead of hPFMET->GetMinimum() use 1.e-6 and instead of hPFMET->GetMaximum() use 1.e5 (note also that frame->SetBins(NMbins, Mbins); call is “optional” so not really required).
Maybe I didn’t explain my question well. I want that the binning in X-axis to be written just the 5 bins we defined not the 20 GeV bin as in the plot attached before.
Yes I have a histogram of variable bin width in different root files, I stacked all the files together as in the attached plot.I want to change the X-axis to be exactly as the bins I set in the histogram.the bins are {0.,25.,50.,200., 500.,1000.}.
“I get my histogram but the x axis has a different binning.”
Wiles answer shows binning as expected.
" want that the binning in X-axis to be written just the 5 bins"
I guess you want labels at 0, 25, 50, 200, 500, 1000
Think thats not implemented currently in TGaxis but could
easily done “by hand” (TLatex)
“I have a histogram of variable bin width in different root files”
If you want to change their binning each new bin edge m u s t coincide
with one in the original (bins can not be divided)
I assume you want to put the hist in your plot pTmiss into one
with (0, 50, 200, 500, 1000) binning:, thats not possible without
violating your data, you must go back to the original data (TTree)