How to control number of bins when use createHistogram

Hi experts,
I use function “createHistogram” creat a histogram from a RooAbsPdf, but the number of bins is not consistent. 7 bins was assigned, but when I got the diagram it only drawn 5 bins. Would you please me tell me how to control the number of bins.
code:
RooRealVar *mass_tt= w->var(“mass_tt”);
RooAbsPdf *atem_ytt_pdf=aterm->createProjection(*mass_tt);
TH1F* aterm_ytt_hist=(TH1F*) atem_ytt_pdf->createHistogram(“rapidity_tt”,7);
aterm_ytt_hist->Scale(85000/aterm_ytt_hist->Integral());
hist_a1d->SetLineColor(2);
aterm_ytt_hist->SetLineColor(4);
aterm_ytt_hist->Draw(“histsame”);

I tried largen the second argument, for example, set it as 50 or 100, then I obtain 7bins as expected.
In Root reference guide it says: TH1 * createHistogram (const char *varNameList, Int_t xbins=0, Int_t ybins=0, Int_t zbins=0).
I found the second argument is not the number of bins, it seems it is the number of events used to create the histogram.

You could try the Binning argument that is documented here:
https://root.cern.ch/doc/master/classRooAbsReal.html#a6659d2c301e5cd65b83ee8c9422c2553

I also had a look at the code, but it looks correct. Could you post an example that we can run?

Hi,
I found the problem. the command “createHistogram(“rapidity_tt”,7);” create a histogram with even bin width, but my PDF(the original histogram) is not even bin width. The edge of my bins is :

Double_t edges[8]={-4,-1.8,-1,-0.2,0.6,1.2,2,4};

How can I create a histogram with not even width using createHistogram?

In the documentation I linked you should find an argument that’s also called Binning, but it should take the number of bins and an array with bin boundaries.

What you can do is either use IntrinsicBinning() or you can create a new RooBinning, and pass it like this:

createHistogram(... Binning(RooBinning(pass your arguments here));

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.