27#include <G4IonTable.hh>
28#include <G4ParticleDefinition.hh>
29#include <G4ParticleTable.hh>
30#include <G4RunManager.hh>
32#include <TMCManagerStack.h>
33#include <TMCParticleStatus.h>
35#include <TVirtualMC.h>
36#include <TVirtualMCApplication.h>
37#include <TVirtualMCStack.h>
41#include <G4SystemOfUnits.hh>
49 G4RunManager::GetRunManager()->GetUserEventAction()));
63 fSkipUnknownParticles(false)
88 "TG4PrimaryGeneratorAction",
"CheckVMCStack",
"Found nullptr for stack.");
92 if (mcStack->GetNtrack() <= 0) {
94 "No primary particles found on the stack.");
103 const TParticle* particle)
const
105 if (!particleDefinition) {
107 "TG4PrimaryGeneratorAction::CheckParticleDefinition() failed for ";
108 text += TString(particle->GetName());
109 text +=
" pdgEncoding=";
110 text += particle->GetPdgCode();
114 "TG4PrimaryGeneratorAction",
"CheckParticleDefinition", text);
118 "TG4PrimaryGeneratorAction",
"CheckParticleDefinition", text);
128 const TParticle* particle)
const
130 G4double charge = particleDefinition->GetPDGCharge();
131 if (G4IonTable::IsIon(particleDefinition) &&
132 particleDefinition->GetParticleName() !=
"proton") {
136 if (userIon) charge = userIon->
GetQ() * eplus;
144 const G4ThreeVector& position, G4double time,
const G4ThreeVector& momentum,
145 G4double energy,
const G4ThreeVector& polarization, G4double charge,
146 G4double weight)
const
148 auto thisVertex = vertex;
149 auto primaryParticle =
new G4PrimaryParticle(
150 particleDefinition, momentum.x(), momentum.y(), momentum.z(), energy);
151 primaryParticle->SetCharge(charge);
152 primaryParticle->SetWeight(weight);
153 primaryParticle->SetPolarization(polarization);
154 if (vertex == 0 || vertex->GetPosition() != position ||
155 time != vertex->GetT0()) {
158 thisVertex =
new G4PrimaryVertex(position, time);
159 event->AddPrimaryVertex(thisVertex);
161 thisVertex->SetPrimary(primaryParticle);
164 G4cout <<
"Add primary particle to vertex: " << G4endl;
165 primaryParticle->Print();
178 G4int nofParticles =
fMCStack->GetNtrack();
181 G4cout <<
"TG4PrimaryGeneratorAction::TransformPrimaries: " << nofParticles
182 <<
" particles" << G4endl;
184 G4PrimaryVertex* previousVertex = 0;
186 for (G4int i = 0; i < nofParticles; i++) {
189 TParticle* particle =
fMCStack->PopPrimaryForTracking(i);
214 G4double weight = particle->GetWeight();
215 TVector3 polarization;
216 particle->GetPolarisation(polarization);
217 G4ThreeVector g4Polarization(
218 polarization.X(), polarization.Y(), polarization.Z());
223 time, momentum, energy, g4Polarization, charge, weight);
242 G4cout <<
"TG4PrimaryGeneratorAction::TransformTracks: "
245 G4PrimaryVertex* previousVertex = 0;
247 const TParticle* particle = 0;
254 const TMCParticleStatus* particleStatus =
271 const TLorentzVector& particlePosition = particleStatus->fPosition;
278 const TLorentzVector& particleMomentum = particleStatus->fMomentum;
286 G4double weight = particleStatus->fWeight;
287 const TVector3& polarization = particleStatus->fPolarization;
288 G4ThreeVector g4Polarization(
289 polarization.X(), polarization.Y(), polarization.Z());
294 time, momentum, energy, g4Polarization, charge, weight);
311 TVirtualMCApplication* mcApplication = TVirtualMCApplication::Instance();
327 mcApplication->BeginEvent();
342 mcApplication->GeneratePrimaries();
Definition of the TG4EventAction class.
Definition of the TG4G3Units class.
Definition of the TG4Globals class and basic container types.
Definition of the TG4ParticlesManager class.
Definition of the TG4PrimaryGeneratorAction class.
Definition of the TG4PrimaryGeneratorMessenger class.
Definition of the TG4RunManager.h class.
Definition of the TG4StateManager class.
Definition of the TG4TrackManager class.
Definition of the TG4UserIon class.
Actions at the beginning and the end of event.
G4bool IsInterruptibleEvent() const
static void Warning(const TString &className, const TString &methodName, const TString &text)
static void Exception(const TString &className, const TString &methodName, const TString &text)
G4ParticleDefinition * GetParticleDefinition(const TParticle *particle, G4bool warn=true) const
G4ThreeVector GetParticlePosition(const TParticle *particle) const
TG4UserIon * GetUserIon(const G4String &ionName, G4bool warn=true) const
G4ThreeVector GetParticleMomentum(const TParticle *particle) const
static TG4ParticlesManager * Instance()
G4bool fSkipUnknownParticles
Option to skip particles which do not exist in Geant4.
G4bool CheckParticleDefinition(const G4ParticleDefinition *particleDefinition, const TParticle *particle) const
TG4ParticlesManager * fParticlesManager
Thread-local particles manager.
TG4PrimaryGeneratorMessenger * fMessenger
Messenger.
TVirtualMCStack * fMCStack
Thread-local stacks.
G4bool fCached
Flag whether thread-local variables have been cached.
G4PrimaryVertex * AddParticleToVertex(G4Event *event, G4PrimaryVertex *vertex, const G4ParticleDefinition *particleDefinition, const G4ThreeVector &position, G4double time, const G4ThreeVector &momentum, G4double energy, const G4ThreeVector &polarization, G4double charge, G4double weight) const
virtual void GeneratePrimaries(G4Event *event)
G4bool CheckVMCStack(TVirtualMCStack *stack) const
void TransformPrimaries(G4Event *event)
TG4TrackManager * fTrackManager
Thread-local track manager.
virtual ~TG4PrimaryGeneratorAction()
void TransformTracks(G4Event *event)
G4double GetProperCharge(const G4ParticleDefinition *particleDefinition, const TParticle *particle) const
TG4PrimaryGeneratorAction()
TMCManagerStack * fMCManagerStack
Messenger class that defines commands for TG4PrimaryGeneratorAction.
Geant4 implementation of the TVirtualMC interface methods for access to Geant4 at run level.
static TG4RunManager * Instance()
void SetNewState(TG4ApplicationState state)
static TG4StateManager * Instance()
void ResetParticlesStatus()
void AddParticleStatus(const TMCParticleStatus *particleStatus)
static TG4TrackManager * Instance()
void ResetPrimaryParticleIds()
void AddPrimaryParticleId(G4int id)
The class for user ion definition.
G4int GetQ() const
Return the ion charge.
Base class for defining the verbose level and a common messenger.
virtual G4int VerboseLevel() const
@ kInEvent
in event processing