Files
geant4/examples/extended/electromagnetic/TestEm8/src/Em8PrimaryGeneratorAction.cc
T
2016-06-09 10:56:29 +02:00

154 lines
5.1 KiB
C++

//
// ********************************************************************
// * DISCLAIMER *
// * *
// * The following disclaimer summarizes all the specific disclaimers *
// * of contributors to this software. The specific disclaimers,which *
// * govern, are listed with their locations in: *
// * http://cern.ch/geant4/license *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. *
// * *
// * This code implementation is the intellectual property of the *
// * GEANT4 collaboration. *
// * By copying, distributing or modifying the Program (or any work *
// * based on the Program) you indicate your acceptance of this *
// * statement, and all its terms. *
// ********************************************************************
//
//
// $Id: Em8PrimaryGeneratorAction.cc,v 1.5 2004/05/24 16:56:31 grichine Exp $
// GEANT4 tag $Name: geant4-06-02 $
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
#include "Em8PrimaryGeneratorAction.hh"
#include "Em8DetectorConstruction.hh"
#include "Em8PrimaryGeneratorMessenger.hh"
#include "G4Event.hh"
#include "G4ParticleGun.hh"
#include "G4ParticleTable.hh"
#include "G4ParticleDefinition.hh"
#include "Randomize.hh"
#include "G4ios.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
G4String Em8PrimaryGeneratorAction::thePrimaryParticleName="proton" ;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
Em8PrimaryGeneratorAction::Em8PrimaryGeneratorAction(
Em8DetectorConstruction* Em8DC)
:Em8Detector(Em8DC),rndmFlag("off"),xvertex(0.),yvertex(0.),zvertex(0.),
vertexdefined(false)
{
G4int n_particle = 1;
particleGun = new G4ParticleGun(n_particle);
//create a messenger for this class
gunMessenger = new Em8PrimaryGeneratorMessenger(this);
// default particle kinematic
G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
G4String particleName;
G4ParticleDefinition* particle
= particleTable->FindParticle(particleName="proton");
particleGun->SetParticleDefinition(particle);
thePrimaryParticleName = particle->GetParticleName() ;
particleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.));
particleGun->SetParticleEnergy(100.*GeV);
zvertex = 0.0 ; // -0.5*(Em8Detector->GetAbsorberThickness());
particleGun->SetParticlePosition(G4ThreeVector(xvertex,yvertex,zvertex));
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
Em8PrimaryGeneratorAction::~Em8PrimaryGeneratorAction()
{
delete particleGun;
delete gunMessenger;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void Em8PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
{
//this function is called at the begining of event
//
thePrimaryParticleName = particleGun->GetParticleDefinition()->
GetParticleName() ;
G4double x0,y0,z0 ;
G4double delta = 0.0001*mm;
if(vertexdefined)
{
x0 = xvertex ;
y0 = yvertex ;
z0 = zvertex ;
}
else
{
x0 = 0. ;
y0 = 0. ;
z0 = -0.5*( Em8Detector->GetWorldSizeZ() ) + delta ;
}
G4double r0,phi0 ;
/* ****************************************************
if (rndmFlag == "on")
{
r0 = (Em8Detector->GetAbsorberRadius())*sqrt(G4UniformRand());
phi0 = twopi*G4UniformRand();
x0 = r0*cos(phi0);
y0 = r0*sin(phi0);
}
********************************************* */
particleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0));
particleGun->GeneratePrimaryVertex(anEvent);
}
///////////////////////////////////////////////////////////////////////
//
//
G4String Em8PrimaryGeneratorAction::GetPrimaryName()
{
return thePrimaryParticleName ;
}
void Em8PrimaryGeneratorAction::Setzvertex(G4double z)
{
vertexdefined = true ;
zvertex = z ;
G4cout << " Z coordinate of the primary vertex = " << zvertex/mm <<
" mm." << G4endl;
}
void Em8PrimaryGeneratorAction::Setxvertex(G4double x)
{
vertexdefined = true ;
xvertex = x ;
G4cout << " X coordinate of the primary vertex = " << xvertex/mm <<
" mm." << G4endl;
}
void Em8PrimaryGeneratorAction::Setyvertex(G4double y)
{
vertexdefined = true ;
yvertex = y ;
G4cout << " Y coordinate of the primary vertex = " << yvertex/mm <<
" mm." << G4endl;
}