Message: generate particle source Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Question generate particle source 

Forum: Particles
Date: 24 Jul, 2013
From: shayma nader <shayma nader>

salam please i need your help iam beginner in geant 4 i have to generate positron source in space i used particle gun in primary generation action but it wasn't describe in space so when i read about generation source in space there saying that i must used general particle source instead of particle gun to obtain source spread in space i don't know how i can change particle gun to general particle source please help me

................................. #include "PSPrimaryGeneratorAction.hh"

#include "PSDetectorConstruction.hh"
#include "G4Event.hh"
#include "G4ParticleGun.hh"
#include "G4ParticleTable.hh"
#include "G4ParticleDefinition.hh"
#include "G4ChargedGeantino.hh"
#include "Randomize.hh"
#include <iostream>
#include <fstream>
using namespace std; //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

PSPrimaryGeneratorAction::PSPrimaryGeneratorAction(PSDetectorConstruction* DC)
:Detector(DC)
{
 G4int n_particle = 1;
  particleGun  =  new G4ParticleGun(n_particle);

 //G4cout<<"-----------------------------------------------------------"<<G4endl;

  G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
  G4String particleName;
  G4ParticleDefinition* particle
                    = particleTable->FindParticle(particleName="e+");
  particleGun->SetParticleDefinition(particle);
  particleGun->SetParticleEnergy(1.*MeV);
  particleGun->SetParticlePosition(G4ThreeVector(0.0*cm,0.0*cm,0.0*cm));

}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

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

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

void PSPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
{
  //this function is called at the begining of event

  G4double Pi = 3.14159;
  G4double cosTheta = 2*G4UniformRand() - 1., phi = twopi*G4UniformRand();
  G4double sinTheta = std::sqrt(1. - cosTheta*cosTheta);
  G4double Px = sinTheta*std::cos(phi),
           Py = sinTheta*std::sin(phi),
           Pz = cosTheta;

particleGun->SetParticleMomentumDirection(G4ThreeVector(Px,Py,Pz)); particleGun->GeneratePrimaryVertex(anEvent); }

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

thank in advanced

 Add Message Add Message
to: "generate particle source"

 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 ]