Problem plotting Binomial distribution

I am defining a (standardized) binomial probability mass function for n=2000, p=0.01 like

  TF1 *binomial = new TF1("binomial", "[0]*TMath::Binomial([1], x) * ([2])^x * (1-[2])^([1]-x)", 0, 100);
  binomial->SetParameter(0, 10000);
  binomial->SetParameter(1, 2000);
  binomial->SetParameter(2, 0.01);

When I evaluate it at x=20 (expectation value)

binomialf->Eval(20)

I get 892.83 as expected.

However, when drawing the function in a histogram it has its maximum at around (x,y) = (20, 140), which is clearly wrong, as it should precisely be at (20, 892.83). I suspect that it has something to do with the fact that binomial is only defined for discrete values (which I did not know how to express in the function definition) and root does some sort of interpolation?!

How do I fix the plot?

EDIT: When I plot binomial individually (not together with a histogram using binomial->Draw(“same”) I get yet another peek value which is approximately off by a factor of 10. (see Image) binomial.pdf (14 KB)

binomial->SetNpx(100000)
binomial->Draw()

Ok, that seems to fix some issues and makes sense! However it still does not look pretty and rather hackish (there is still some interpolation going and the graph goes through some intermediate point in the middle of nowhere for which it is not defined).

It would probably make sense to only plot the function at discrete values and then connect them with straight lines or display them as bars.

Is there root support to
a.) declare a function to be defined only at discrete values
b.) have special plotting commands for discrete functions?

May be try:

binomial->Draw(“P”);

Thanks for your help! But being fairly new with root I would appreciate it if you could take the time to respond to my questions and not only drop a line of code without any further explanation. This would certainly also make things easier for other persons having the same problem.

it is not dropping a line, it is just the continuation of the previous post. I told you before to do:

binomial->SetNpx(100000)
binomial->Draw()

Now I suggest you try the same with option P

binomial->SetNpx(100000)
binomial->Draw("P")

Sorry, I thought it was clear enough.

Hi,
Since the binomial is a discrete function, you want actually to be evaluate at the integer values.
It is important then that each bin has a bin width of 1, so in your case with a range [0,100], you need to have 100 points. But you need to fix the function definition for the other terms which are not in the binomial, as following

 TF1 *binomial = new TF1("binomial", "[0]*TMath::Binomial([1], x) * ([2])^(int(x)) * (1-[2])^([1]-int(x))", 0., 100.);  
  binomial->SetParameter(0, 10000);
  binomial->SetParameter(1, 2000);
  binomial->SetParameter(2, 0.01);
  binomial->SetNpx(100);
  binomial->Draw("HIST");  // to draw it as an histogram

Or otherwise you make the function having been center corresponding to exact integers. This can be achieved for example by setting the range to [0.5,100.5]

Lorenzo