20#include "BDSLinkBunch.hh"
21#include "BDSBunchSixTrackLink.hh"
23#include "BDSEventInfo.hh"
24#include "BDSException.hh"
25#include "BDSExtent.hh"
26#include "BDSIonDefinition.hh"
27#include "BDSLinkDetectorConstruction.hh"
28#include "BDSLinkEventInfo.hh"
29#include "BDSLinkPrimaryGeneratorAction.hh"
30#include "BDSLinkRegistry.hh"
31#include "BDSPrimaryVertexInformation.hh"
32#include "BDSRandom.hh"
35#include "G4IonTable.hh"
36#include "G4ParticleGun.hh"
40 int* currentElementIndexIn,
44 currentElementIndex(currentElementIndexIn),
45 construction(constructionIn),
51 particleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.));
56BDSLinkPrimaryGeneratorAction::~BDSLinkPrimaryGeneratorAction()
65 anEvent->SetUserInformation(eventInfo);
75 eventInfo->externalParticleIDofPrimary = bunchSTL->CurrentExternalParticleID();
76 eventInfo->externalParentIDofPrimary = bunchSTL->CurrentExternalParentID();
82 anEvent->SetEventAborted();
83 G4cout << exception.
what() << G4endl;
84 G4cout <<
"Aborting this event (#" << anEvent->GetEventID() <<
")" << G4endl;
95 G4cout <<
"PGA: Coords before " << coords;
96 G4cout <<
"Offset " << tr.getTranslation() << G4endl;
101 {G4cout <<
"Coords after " << cg.global;}
118 G4cout << __METHOD_NAME__ <<
"Event #" << anEvent->GetEventID()
119 <<
" - Particle kinetic energy smaller than 0! "
120 <<
"This will not be tracked." << G4endl;
121 anEvent->SetEventAborted();
128 G4cerr << __METHOD_NAME__ <<
"point: " << cg.global
129 <<
"mm lies outside the world volume with extent ("
130 <<
worldExtent <<
" - event aborted!" << G4endl << G4endl;
131 anEvent->SetEventAborted();
135 G4cout << __METHOD_NAME__ << coords << G4endl;
138 G4ThreeVector PartMomDir(cg.global.xp,cg.global.yp,cg.global.zp);
139 G4ThreeVector PartPosition(cg.global.x,cg.global.y,cg.global.z);
143 particleGun->SetParticleMomentumDirection(PartMomDir);
149 auto vertex = anEvent->GetPrimaryVertex();
150 vertex->SetWeight(cg.local.weight);
The base class for bunch distribution generators.
virtual const BDSParticleDefinition * ParticleDefinition() const
Access the beam particle definition.
virtual BDSParticleCoordsFull GetNextParticleLocal()
void SetSeedStateAtStart(const G4String &seedStateAtStartIn)
Setters.
General exception with possible name of object and message.
const char * what() const noexcept override
Override message in std::exception.
G4bool Encompasses(const G4ThreeVector &point) const
Return whether the extent encompasses the point. True if point lies inside the extent.
A bunch distribution that holds a bunch from a Link.
Construction of the geometry in the case of a link model.
BDSLinkRegistry * LinkRegistry() const
Accessor.
Simple extension to cache extra variables through an event.
BDSBunch * bunch
BDSIM particle generator.
virtual void GeneratePrimaries(G4Event *)
Main interface for Geant4. Prepare primary(ies) for the event.
int * currentElementIndex
External integer for which element to track in.
G4ParticleGun * particleGun
Geant4 particle gun that creates single particles.
BDSExtent worldExtent
World extent that particle coordinates are checked against to ensure they're inside it.
BDSLinkPrimaryGeneratorAction(BDSBunch *bunchIn, int *currentElementIndexIn, BDSLinkDetectorConstruction *constructionIn, G4bool debugIn=false)
Bunch must have a valid particle definition (ie not nullptr).
BDSLinkDetectorConstruction * construction
Cache of detector construction for link registry of transforms.
A set of particle coordinates in both local and global.
A set of particle coordinates including energy and weight.
A set of particle coordinates.
BDSParticleCoords ApplyTransform(const G4Transform3D &transform) const
Apply a transform to the coordinates and return a copy of them transformed.
BDSParticleCoords ApplyOffset(const G4ThreeVector &offset) const
Apply an offset to the spatial coordinates only and return a copy.
G4double Mass() const
Accessor.
G4double Charge() const
Accessor.
G4ParticleDefinition * ParticleDefinition() const
Accessor.