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

#include <B5PrimaryGeneratorAction.hh>

Inheritance diagram for B5PrimaryGeneratorAction:
Collaboration diagram for B5PrimaryGeneratorAction:

Public Member Functions

 B5PrimaryGeneratorAction ()
 
virtual ~B5PrimaryGeneratorAction ()
 
virtual void GeneratePrimaries (G4Event *)
 
void SetMomentum (G4double val)
 
G4double GetMomentum () const
 
void SetSigmaMomentum (G4double val)
 
G4double GetSigmaMomentum () const
 
void SetSigmaAngle (G4double val)
 
G4double GetSigmaAngle () const
 
void SetRandomize (G4bool val)
 
G4bool GetRandomize () const
 
- Public Member Functions inherited from G4VUserPrimaryGeneratorAction
 G4VUserPrimaryGeneratorAction ()
 
virtual ~G4VUserPrimaryGeneratorAction ()
 

Detailed Description

Primary generator

A single particle is generated. User can select

  • the initial momentum and angle
  • the momentum and angle spreads
  • random selection of a particle type from proton, kaon+, pi+, muon+, e+

Definition at line 51 of file B5PrimaryGeneratorAction.hh.

Constructor & Destructor Documentation

B5PrimaryGeneratorAction::B5PrimaryGeneratorAction ( )

Definition at line 43 of file B5PrimaryGeneratorAction.cc.

45  fParticleGun(nullptr), fMessenger(nullptr),
46  fPositron(nullptr), fMuon(nullptr), fPion(nullptr),
47  fKaon(nullptr), fProton(nullptr),
48  fMomentum(1000.*MeV),
49  fSigmaMomentum(50.*MeV),
50  fSigmaAngle(2.*deg),
51  fRandomizePrimary(true)
52 {
53  G4int nofParticles = 1;
54  fParticleGun = new G4ParticleGun(nofParticles);
55 
56  auto particleTable = G4ParticleTable::GetParticleTable();
57  fPositron = particleTable->FindParticle("e+");
58  fMuon = particleTable->FindParticle("mu+");
59  fPion = particleTable->FindParticle("pi+");
60  fKaon = particleTable->FindParticle("kaon+");
61  fProton = particleTable->FindParticle("proton");
62 
63  // default particle kinematics
64  fParticleGun->SetParticlePosition(G4ThreeVector(0.,0.,-8.*m));
65  fParticleGun->SetParticleDefinition(fPositron);
66 
67  // define commands for this class
68  DefineCommands();
69 }
CLHEP::Hep3Vector G4ThreeVector
int G4int
Definition: G4Types.hh:78
void SetParticlePosition(G4ThreeVector aPosition)
static constexpr double m
Definition: G4SIunits.hh:129
static G4ParticleTable * GetParticleTable()
static constexpr double MeV
Definition: G4SIunits.hh:214
static constexpr double deg
Definition: G4SIunits.hh:152
void SetParticleDefinition(G4ParticleDefinition *aParticleDefinition)

Here is the call graph for this function:

B5PrimaryGeneratorAction::~B5PrimaryGeneratorAction ( )
virtual

Definition at line 73 of file B5PrimaryGeneratorAction.cc.

74 {
75  delete fParticleGun;
76  delete fMessenger;
77 }

Member Function Documentation

void B5PrimaryGeneratorAction::GeneratePrimaries ( G4Event event)
virtual

Implements G4VUserPrimaryGeneratorAction.

Definition at line 81 of file B5PrimaryGeneratorAction.cc.

82 {
83  G4ParticleDefinition* particle;
84  if (fRandomizePrimary) {
85  G4int i = (int)(5.*G4UniformRand());
86  switch(i) {
87  case 0:
88  particle = fPositron;
89  break;
90  case 1:
91  particle = fMuon;
92  break;
93  case 2:
94  particle = fPion;
95  break;
96  case 3:
97  particle = fKaon;
98  break;
99  default:
100  particle = fProton;
101  break;
102  }
103  fParticleGun->SetParticleDefinition(particle);
104  }
105  else {
106  particle = fParticleGun->GetParticleDefinition();
107  }
108 
109  auto pp = fMomentum + (G4UniformRand()-0.5)*fSigmaMomentum;
110  auto mass = particle->GetPDGMass();
111  auto ekin = std::sqrt(pp*pp+mass*mass)-mass;
112  fParticleGun->SetParticleEnergy(ekin);
113 
114  auto angle = (G4UniformRand()-0.5)*fSigmaAngle;
115  fParticleGun->SetParticleMomentumDirection(
116  G4ThreeVector(std::sin(angle),0.,std::cos(angle)));
117 
118  fParticleGun->GeneratePrimaryVertex(event);
119 }
CLHEP::Hep3Vector G4ThreeVector
static G4double angle[DIM]
void SetParticleMomentumDirection(G4ParticleMomentum aMomentumDirection)
int G4int
Definition: G4Types.hh:78
virtual void GeneratePrimaryVertex(G4Event *evt)
#define G4UniformRand()
Definition: Randomize.hh:97
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
void SetParticleEnergy(G4double aKineticEnergy)
G4double GetPDGMass() const
G4ParticleDefinition * GetParticleDefinition() const
void SetParticleDefinition(G4ParticleDefinition *aParticleDefinition)

Here is the call graph for this function:

G4double B5PrimaryGeneratorAction::GetMomentum ( ) const
inline

Definition at line 60 of file B5PrimaryGeneratorAction.hh.

60 { return fMomentum; }
G4bool B5PrimaryGeneratorAction::GetRandomize ( ) const
inline

Definition at line 69 of file B5PrimaryGeneratorAction.hh.

69 { return fRandomizePrimary; }
G4double B5PrimaryGeneratorAction::GetSigmaAngle ( ) const
inline

Definition at line 66 of file B5PrimaryGeneratorAction.hh.

66 { return fSigmaAngle; }
G4double B5PrimaryGeneratorAction::GetSigmaMomentum ( ) const
inline

Definition at line 63 of file B5PrimaryGeneratorAction.hh.

63 { return fSigmaMomentum; }
void B5PrimaryGeneratorAction::SetMomentum ( G4double  val)
inline

Definition at line 59 of file B5PrimaryGeneratorAction.hh.

59 { fMomentum = val; }
void B5PrimaryGeneratorAction::SetRandomize ( G4bool  val)
inline

Definition at line 68 of file B5PrimaryGeneratorAction.hh.

68 { fRandomizePrimary = val; }
void B5PrimaryGeneratorAction::SetSigmaAngle ( G4double  val)
inline

Definition at line 65 of file B5PrimaryGeneratorAction.hh.

65 { fSigmaAngle = val; }
void B5PrimaryGeneratorAction::SetSigmaMomentum ( G4double  val)
inline

Definition at line 62 of file B5PrimaryGeneratorAction.hh.

62 { fSigmaMomentum = val; }

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