Message: random generation of particles in x-y plane Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Question random generation of particles in x-y plane 

Keywords: random distribution, incident particles
Forum: Particles
Date: 19 Oct, 2003
From: Sean Turnbull <Sean Turnbull>

I have a cylinder of radius 300mm and total height 400mm. I want to send an incident particle down z axis from top of cylinder and randomise the particles to fall within the 300mm radius, essentially a column of particles.

This is my PrimaryGenerator. Here beamwidth = 300 mm.

 G4int n_particle = 1;
  particleGun = new G4ParticleGun(n_particle);

  // messenger
  gunMessenger = new PrimaryGeneratorMessenger(this);

  // default particle
  G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
  G4ParticleDefinition* particle = particleTable->FindParticle("mu-");

  particleGun->SetParticleDefinition(particle);
  particleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.));
  particleGun->SetParticleEnergy(500*MeV);
}

PrimaryGeneratorAction::~PrimaryGeneratorAction()
{
  delete particleGun;
  delete gunMessenger;
}

void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
{
  // Random generation of mu-
  G4double radius;
  radius = beamwidth;
  G4double x,y,z;
  do{
    x = (G4UniformRand()-1)*radius;
    y = (G4UniformRand()-1)*radius;
    }while (x*x+y*y > radius*radius);
    z = 110*mm;

  G4ThreeVector position(x,y,z);
  particleGun->SetParticlePosition(position);

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

1 Note: Re: random generation of particles in x-y plane   (Wellisch, J.P. - 31 Jan, 2004)
 Add Message Add Message
to: "random generation of particles in x-y plane"

 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 ]