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,
52 endOfFileReached(false),
53 vertexGeneratedSuccessfully(false),
54 currentFileEventIndex(0),
56 nEventsReadThatPassedFilters(0),
61BDSPrimaryGeneratorFile::~BDSPrimaryGeneratorFile()
67 if (eventOffset > nEventsInFile*nLoops)
69 G4String msg =
"eventOffset (" + std::to_string(eventOffset) +
") is greater than the number of valid data lines in this file.";
76 vertexGeneratedSuccessfully =
false;
77 GeneratePrimaryVertex(event);
78 if (!vertexGeneratedSuccessfully && !endOfFileReached)
79 {bunch->IncrementNEventsInFileSkipped();}
80 return vertexGeneratedSuccessfully;
85 return nEventsInFile - currentFileEventIndex;
90 return nEventsReadThatPassedFilters > 0 || recreate;
106 if (useEventGeneratorFile || useSamplerLoader)
109 {
throw BDSException(__METHOD_NAME__,
"no distrFile specified for event generator beam distribution.");}
113 {
throw BDSException(__METHOD_NAME__,
"must be used with a BDSBunchEventGenerator instance");}
115 if (useEventGeneratorFile)
125 throw BDSException(__METHOD_NAME__,
"event generator file being used but BDSIM not compiled with HEPMC3");
150 G4cout << __METHOD_NAME__ <<
"distrFileMatchLength is true -> simulating " << nEventsPerLoop <<
" events";
151 if (distrFileLoopNTimes > 1)
152 {G4cout <<
" " << distrFileLoopNTimes <<
" times";}
157 return generatorFromFile;
164 G4Navigator* navigator = G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking();
165 G4VPhysicalVolume* world = navigator->GetWorldVolume();
166 worldSolid = world->GetLogicalVolume()->GetSolid();
168 EInside qinside = worldSolid->Inside(pos);
169 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
fo 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)