Message: RE: Generating 2 particles with different energies Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

None RE: Generating 2 particles with different energies 

Forum: Particles
Re: None Generating 2 particles with different energies (Adam)
Re: None RE: Generating 2 particles with different energies (Makoto Asai)
Date: 11 Jun, 2007
From: Adam <ax_blais@laurentian.ca>

Here it is:

#include "ExN02PrimaryGeneratorAction.hh"
#include "ExN02DetectorConstruction.hh"

#include "G4Event.hh"
#include "G4ParticleGun.hh"
#include "G4ParticleTable.hh"
#include "G4ParticleDefinition.hh"
#include "G4PhysicalVolumeStore.hh"
#include "globals.hh"

#include <cmath>

#include "G4Electron.hh"
#include "Randomize.hh"

void ExN02PrimaryGeneratorAction::GeneratePointsInVolume() {

  G4ThreeVector RandPos;
  G4double x=0.*cm, y=0.*cm, z=0.*cm;
  G4double radius=304.2*cm, height=304.2*cm;

  x = radius*2.*cm;
  y = radius*2.*cm;
  while(((x*x)+(y*y)) > (radius*radius)) {
    x = G4UniformRand();
    y = G4UniformRand();
    z = G4UniformRand();
    x = (x*2.*radius) - radius;
    y = (y*2.*radius) - radius;
    z = (z*2.*height) - height;
  }

  RandPos.setX(x);
  RandPos.setY(y);
  RandPos.setZ(z);

  //G4cout << "Starting position is : " << RandPos << G4endl;

particleGun->SetParticlePosition(RandPos); }

void ExN02PrimaryGeneratorAction::GenerateIsotropicFlux()
{
  G4double rndm, rndm2;
  G4double px, py, pz;
  G4double MinTheta = 0.;
  G4double MaxTheta = pi;
  G4double MinPhi = 0.;
  G4double MaxPhi = twopi;
  G4double sinphi, Phi;

  G4double sintheta, costheta, cosphi;
  rndm = G4UniformRand();
  costheta = std::cos(MinTheta) - rndm * (std::cos(MinTheta) - std::cos(MaxTheta));
  sintheta = std::sqrt(1. - costheta*costheta);

  rndm2 = G4UniformRand();
  Phi = MinPhi + (MaxPhi - MinPhi) * rndm2;
  sinphi = std::sin(Phi);
  cosphi = std::cos(Phi);

  px = -sintheta * cosphi;
  py = -sintheta * sinphi;
  pz = -costheta;

 G4double ResMag = std::sqrt((px*px) + (py*py) + (pz*pz));
  px = px/ResMag;
  py = py/ResMag;
  pz = pz/ResMag;

  G4ParticleMomentum particle_momentum_direction;

  particle_momentum_direction.setX(px);
  particle_momentum_direction.setY(py);
  particle_momentum_direction.setZ(pz);

  // particle_momentum_direction now holds unit momentum vector.

  //G4cout << "Generating isotropic vector: " << particle_momentum_direction << G4endl;

particleGun->SetParticleMomentum(particle_momentum_direction); }

void ExN02PrimaryGeneratorAction::GenerateRandomEnergy()
{
  G4double Q = 2.4578;
  G4double me = 0.511;

  G4double y;

  e1 = G4UniformRand() * Q;
  y = G4UniformRand();

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

  e2 = Q - e1;

G4cout << e1 << " " << y << "******************" << G4endl; }

ExN02PrimaryGeneratorAction::ExN02PrimaryGeneratorAction(
                                               ExN02DetectorConstruction* myDC)
:myDetector(myDC)
{
  G4int n_particle = 2;

  particleGun = new G4ParticleGun(n_particle);
  particleGun->SetParticleDefinition(G4Electron::ElectronDefinition());

}

ExN02PrimaryGeneratorAction::~ExN02PrimaryGeneratorAction()
{
  delete particleGun;
}

void ExN02PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
{
  ExN02PrimaryGeneratorAction::GenerateIsotropicFlux();
  ExN02PrimaryGeneratorAction::GeneratePointsInVolume();
  particleGun->SetParticleEnergy(e1);
  particleGun->GeneratePrimaryVertex(anEvent);
  particleGun->SetParticleEnergy(e2);
  particleGun->GeneratePrimaryVertex(anEvent);
}

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

1 None: RE: Generating 2 particles with different energies   (Makoto Asai - 11 Jun, 2007)
(_ None: RE: Generating 2 particles with different energies   (Adam - 11 Jun, 2007)
(_ None: RE: Generating 2 particles with different energies   (Makoto Asai - 11 Jun, 2007)
(_ None: RE: Generating 2 particles with different energies   (Adam - 11 Jun, 2007)
 Add Message Add Message
to: "RE: Generating 2 particles with different energies"

 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 ]