Message: Help with random generator Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

None Help with random generator 

Forum: Event and Track Management
Date: 15 Jun, 2007
From: Adam <ax_blais@laurentian.ca>

I'm generating a random energy e1. The energy has to be produced according to a probability distribution function. My code for generating the random energy is here:

 G4double Q = 2.4578*MeV;
  G4double me = 0.511*MeV;

  G4double y = 0;

  do {
    e1 = G4UniformRand() * Q;
    y = G4UniformRand();
  } while(y > (0.1091196*((e1 + me)*(e1 + me)) * ((Q + me - e1)*(Q + me - e1))));

y is the probability between 0 and 1. Essentially I reject any energies that lie above the distribution function.

When I do a simulation of 10000 events, the energies don't seem to be distributed correctly. My histogram is here:

http://img371.imageshack.us/img371/1189/energyhistogramhy2.jpg

The bars should be along the function with slight variation, but the bars don't seem to go with the function at all. I don't understand why this is because I'm plotting the same function that is in my code, so theoretically it should be about the same. I get this same shape with 100000 events. I also have changed the seed several times and still get a similar result.

Any ideas?

Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

1 None: Re: Help with random generator   (Adam - 15 Jun, 2007)
 Add Message Add Message
to: "Help with random generator"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews


[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]