20#include "BDSBunchEventGenerator.hh"
21#include "BDSBunchType.hh"
23#include "BDSException.hh"
24#include "BDSGlobalConstants.hh"
25#include "BDSPrimaryGeneratorFile.hh"
26#include "BDSPrimaryGeneratorFileSampler.hh"
27#include "BDSRunAction.hh"
28#include "BDSUtilities.hh"
31#include "BDSPrimaryGeneratorFileHEPMC.hh"
35#include "G4LogicalVolume.hh"
36#include "G4Navigator.hh"
38#include "G4ThreeVector.hh"
39#include "G4TransportationManager.hh"
41#include "G4VPhysicalVolume.hh"
43#include "parser/beam.h"
47BDSPrimaryGeneratorFile::BDSPrimaryGeneratorFile(G4bool loopFileIn,
51 endOfFileReached(false),
52 vertexGeneratedSuccessfully(false),
53 currentFileEventIndex(0),
55 nEventsReadThatPassedFilters(0),
60BDSPrimaryGeneratorFile::~BDSPrimaryGeneratorFile()
66 if (eventOffset > nEventsInFile*nLoops)
68 G4String msg =
"eventOffset (" + std::to_string(eventOffset) +
") is greater than the number of valid data lines in this file.";
75 vertexGeneratedSuccessfully =
false;
76 GeneratePrimaryVertex(event);
77 if (!vertexGeneratedSuccessfully && !endOfFileReached)
78 {bunch->IncrementNEventsInFileSkipped();}
79 return vertexGeneratedSuccessfully;
84 return nEventsInFile - currentFileEventIndex;
89 return nEventsReadThatPassedFilters > 0;
105 if (useEventGeneratorFile || useSamplerLoader)
108 {
throw BDSException(__METHOD_NAME__,
"no distrFile specified for event generator beam distribution.");}
112 {
throw BDSException(__METHOD_NAME__,
"must be used with a BDSBunchEventGenerator instance");}
114 if (useEventGeneratorFile)
124 throw BDSException(__METHOD_NAME__,
"event generator file being used but BDSIM not compiled with HEPMC3");
146 G4cout << __METHOD_NAME__ <<
"distrFileMatchLength is true -> simulating " << nEventsPerLoop <<
" events";
147 if (distrFileLoopNTimes > 1)
148 {G4cout <<
" " << distrFileLoopNTimes <<
" times";}
153 return generatorFromFile;
160 G4Navigator* navigator = G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking();
161 G4VPhysicalVolume* world = navigator->GetWorldVolume();
162 worldSolid = world->GetLogicalVolume()->GetSolid();
164 EInside qinside = worldSolid->Inside(pos);
165 return qinside == EInside::kInside;
A wrapper of BDSBunch to include a filter for the events loaded by an event generator.
G4int DistrFileLoopNTimes() const
Accessor.
The base class for bunch distribution generators.
General exception with possible name of object and message.
void SetNumberToGenerate(G4int number)
Setter.
static BDSGlobalConstants * Instance()
Access method.
Loader to use any HepMC3 compatible file.
Loader to read a specific sampler from a BDSIM ROOT output file.
Common interface for any primary generators that are file based.
G4bool GeneratePrimaryVertexSafe(G4Event *event)
Return false if not able to generate a primary vertex.
void ThrowExceptionIfRecreateOffsetTooHigh(G4long eventOffset) const
G4bool VertexInsideWorld(const G4ThreeVector &pos) const
Utility function for derived classes to check a position is inside the world.
G4bool OKToLoopFile() const
virtual void RecreateAdvanceToEvent(G4int eventOffset)=0
Advance into the file as required.
G4long NEventsLeftInFile() const
static BDSPrimaryGeneratorFile * ConstructGenerator(const GMAD::Beam &beam, BDSBunch *bunchIn, G4bool recreate, G4int eventOffset, G4bool batchMode)
Improve type-safety of native enum data type in C++.
bool eventGeneratorWarnSkippedParticles
Event generator file filter.
std::string distrFile
beam parameters
bool distrFileFromExecOptions
Required to know how to build the absolute path properly.
bool distrFileLoop
beam parameters
bool removeUnstableWithoutDecay
beam parameters
std::string distrType
beam parameters
int distrFileLoopNTimes
beam parameters
bool distrFileMatchLength
beam parameters
G4bool StrContains(const G4String &str, const G4String &test)
Utility function to simplify lots of syntax changes for pedantic g4 changes.
G4String GetFullPath(G4String filename, bool excludeNameFromPath=false, bool useCWDForPrefix=false)