Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PrimaryGeneratorGun2 Class Reference

#include <PrimaryGeneratorGun2.hh>

Inheritance diagram for PrimaryGeneratorGun2:
Collaboration diagram for PrimaryGeneratorGun2:

Public Member Functions

 PrimaryGeneratorGun2 ()
 
 ~PrimaryGeneratorGun2 ()
 
virtual void GeneratePrimaries (G4Event *)
 
G4double GetRadius ()
 
G4double GetCosAlphaMin ()
 
G4double GetCosAlphaMax ()
 
- Public Member Functions inherited from G4VUserPrimaryGeneratorAction
 G4VUserPrimaryGeneratorAction ()
 
virtual ~G4VUserPrimaryGeneratorAction ()
 

Detailed Description

Definition at line 46 of file PrimaryGeneratorGun2.hh.

Constructor & Destructor Documentation

PrimaryGeneratorGun2::PrimaryGeneratorGun2 ( )

Definition at line 47 of file PrimaryGeneratorGun2.cc.

48  : G4VUserPrimaryGeneratorAction(), fParticleGun(0)
49 {
50  // default particle kinematic
51  //
52  G4int n_particle = 1;
53  fParticleGun = new G4ParticleGun(n_particle);
54 
55  G4ParticleDefinition* particle
57  fParticleGun->SetParticleDefinition(particle);
58  fParticleGun->SetParticleEnergy(1*eV);
59 
60  // vertex
61  //
62  fRadius = 8.*mm;
63 
64  //opening angle
65  //
66  G4double alphaMin = 91.*deg;
67  G4double alphaMax = 180.*deg;
68  fCosAlphaMin = std::cos(alphaMin);
69  fCosAlphaMax = std::cos(alphaMax);
70 }
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
static constexpr double mm
Definition: G4SIunits.hh:115
int G4int
Definition: G4Types.hh:78
static constexpr double eV
Definition: G4SIunits.hh:215
void SetParticleEnergy(G4double aKineticEnergy)
static G4ParticleTable * GetParticleTable()
double G4double
Definition: G4Types.hh:76
static constexpr double deg
Definition: G4SIunits.hh:152
void SetParticleDefinition(G4ParticleDefinition *aParticleDefinition)

Here is the call graph for this function:

PrimaryGeneratorGun2::~PrimaryGeneratorGun2 ( )

Definition at line 74 of file PrimaryGeneratorGun2.cc.

75 {
76  delete fParticleGun;
77 }

Member Function Documentation

void PrimaryGeneratorGun2::GeneratePrimaries ( G4Event anEvent)
virtual

Implements G4VUserPrimaryGeneratorAction.

Definition at line 81 of file PrimaryGeneratorGun2.cc.

82 {
83  //vertex position uniform in sphere
84  //
85  G4double cosTheta = 2*G4UniformRand() - 1; //cosTheta uniform in [0, pi]
86  G4double sinTheta = std::sqrt(1. - cosTheta*cosTheta);
87  G4double phi = twopi*G4UniformRand(); //phi uniform in [0, 2*pi]
88  G4ThreeVector ur(sinTheta*std::cos(phi),sinTheta*std::sin(phi),cosTheta);
89 
90  fParticleGun->SetParticlePosition(fRadius*ur);
91 
92  //particle direction uniform around ur
93  //
94  //1- in World frame
95  //cosAlpha uniform in [cos(alphaMin), cos(alphaMax)]
96  G4double cosAlpha = fCosAlphaMin-G4UniformRand()*(fCosAlphaMin-fCosAlphaMax);
97  G4double sinAlpha = std::sqrt(1. - cosAlpha*cosAlpha);
98  //psi uniform in (0,2*pi)
100  G4ThreeVector dir(sinAlpha*std::cos(psi),sinAlpha*std::sin(psi),cosAlpha);
101 
102  //2- rotate dir (rotateUz transforms uz to ur)
103  dir.rotateUz(ur);
104 
105  fParticleGun->SetParticleMomentumDirection(dir);
106 
107  //create vertex
108  //
109  fParticleGun->GeneratePrimaryVertex(anEvent);
110 }
void SetParticleMomentumDirection(G4ParticleMomentum aMomentumDirection)
virtual void GeneratePrimaryVertex(G4Event *evt)
static constexpr double twopi
Definition: G4SIunits.hh:76
void SetParticlePosition(G4ThreeVector aPosition)
#define G4UniformRand()
Definition: Randomize.hh:97
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

G4double PrimaryGeneratorGun2::GetCosAlphaMax ( )
inline

Definition at line 57 of file PrimaryGeneratorGun2.hh.

57 {return fCosAlphaMax;};
G4double PrimaryGeneratorGun2::GetCosAlphaMin ( )
inline

Definition at line 56 of file PrimaryGeneratorGun2.hh.

56 {return fCosAlphaMin;};
G4double PrimaryGeneratorGun2::GetRadius ( )
inline

Definition at line 55 of file PrimaryGeneratorGun2.hh.

55 {return fRadius;};

The documentation for this class was generated from the following files: