Plotting rapidity using root

I am trying to plot rapidity using root. try3.c (280 Bytes).This is my code. But while executing this I get an error Error: log param[0]=-16.0655 up:1.#INF low:0 out of range C:\root\trial\try3.c(1
1)
*** Interpreter error recovered ***
how do i resolve this?

Fix the reported warnings and then the error will disappear automatically:

root [0] .x try3.c 
Warning: Automatic variable E is allocated try3.c:10:
Warning: Automatic variable y is allocated try3.c:11:
Error: log param[0]=-16.0655 up:inf low:0 out of range try3.c:11:
*** Interpreter error recovered ***

try3.c (356 Bytes)

Sir what does this #Inf error mean?

The macro I posted does not produce any error on my machine.
Have you tried it ?

Yes sir, I tried it and it doesn’t produce any error. You added the auto keyword to h. But even after removing that auto keyword there isn’t any error but if I put a mass like .938 it’s giving the same error. Is log becoming infinity in this case?

Yours sincerely,

Anjali

Try this:

void try3() {
   TH1D *h = new TH1D("h","rapidity",500,-500,500);
   Double_t y,m,px,py,pz,pt,p,E;
   m =.938;
   for (Int_t i=0;i<10000;i++) {
      gRandom->Rannor(px,py);
      gRandom->Rannor(pz,pt);
      p = -(px*px+py*py+pz*pz)+(pt*pt);
      E = sqrt((p*p)+(m*m));
      y =.5*log((E+pz)/(E-pz));
      h->Fill(y);
   }
   h->Draw();
}

It does not give me any error either.