BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
|
Interface class to use BDSIM. More...
#include <BDSIMClass.hh>
Public Member Functions | |
BDSIM () | |
int | Initialise (int argc, char **argv, bool usualPrintOut=true) |
Initialise everything given these arguments. | |
BDSIM (int argc, char **argv, bool usualPrintOut=true) | |
Construct and initialise BDSIM. | |
~BDSIM () | |
The destructor opens the geometry in Geant4 and deletes everything. | |
bool | Initialised () const |
int | InitialisationResult () const |
void | BeamOn (int nGenerate=-1) |
void | RegisterUserComponent (const G4String &componentTypeName, BDSComponentConstructor *componentConstructor) |
void | GeneratePrimariesOnly (const BDSGlobalConstants *globals) |
void | RegisterUserPhysicsList (G4VModularPhysicsList *userPhysicsListIn) |
Provide a physics list that will be used inplace of the BDSIM generate one. | |
G4VModularPhysicsList * | UserPhysicsList () const |
Access user physics list. | |
Private Member Functions | |
int | Initialise () |
The main function where everything is constructed. | |
Private Attributes | |
bool | ignoreSIGINT |
For cmake testing. | |
bool | usualPrintOut |
Whether to allow the usual cout output. | |
bool | initialised |
Whether initialisation was completed safely. | |
int | initialisationResult |
Possible to not finish initialisation but have completed ok - flag for this. | |
int | argcCache |
Cache of argc. | |
char ** | argvCache |
Cache of argv. | |
BDSParser * | parser |
Cache of main objects in BDSIM. | |
BDSOutput * | bdsOutput |
Cache of main objects in BDSIM. | |
BDSBunch * | bdsBunch |
Cache of main objects in BDSIM. | |
BDSRunManager * | runManager |
Cache of main objects in BDSIM. | |
BDSComponentFactoryUser * | userComponentFactory |
Optional user registered component factory. | |
G4VModularPhysicsList * | userPhysicsList |
Optional user registered physics list. | |
BDSDetectorConstruction * | realWorld |
Cache of main objects in BDSIM. | |
Interface class to use BDSIM.
First way to use: bds = new BDSIM(argc, argv); bds->BeamOn();
Second way to use (delayed initialisation): bds = new BDSIM(); // modify bds in some way bds->Initialise(argc, argv); bds->BeamOn();
Definition at line 50 of file BDSIMClass.hh.
BDSIM::BDSIM | ( | ) |
Construct an instance but don't initialise. Requires initialisation with arguments argc and arv
Definition at line 82 of file BDSIMClass.cc.
BDSIM::BDSIM | ( | int | argc, |
char ** | argv, | ||
bool | usualPrintOut = true |
||
) |
Construct and initialise BDSIM.
Definition at line 98 of file BDSIMClass.cc.
References initialisationResult, and Initialise().
BDSIM::~BDSIM | ( | ) |
The destructor opens the geometry in Geant4 and deletes everything.
Termination & clean up.
Definition at line 412 of file BDSIMClass.cc.
References bdsBunch, bdsOutput, BDSAperturePointsCache::ClearCachedFiles(), initialisationResult, BDSAperturePointsCache::Instance(), BDSBeamPipeFactory::Instance(), BDSCavityFactory::Instance(), BDSColours::Instance(), BDSFieldFactory::Instance(), BDSFieldLoader::Instance(), BDSGeometryFactory::Instance(), BDSGlobalConstants::Instance(), BDSMaterials::Instance(), BDSSamplerRegistry::Instance(), BDSTemporaryFiles::Instance(), parser, runManager, and usualPrintOut.
void BDSIM::BeamOn | ( | int | nGenerate = -1 | ) |
Generate nGenerate events. If the default argument -1 is used, the number is taken from the standard input e.g. the executable option ngenerate and then the one specified in the input gmad files as an option.
Catch aborts to close output stream/file. perhaps not all are needed.
Run in either interactive or batch mode
Definition at line 369 of file BDSIMClass.cc.
References argcCache, argvCache, BDSRunManager::BeamOn(), BDS::HandleAborts(), ignoreSIGINT, initialisationResult, initialised, BDSGlobalConstants::Instance(), realWorld, runManager, and BDSVisManager::StartSession().
void BDSIM::GeneratePrimariesOnly | ( | const BDSGlobalConstants * | globals | ) |
Generate the primaries, fill in the output and close the output. In a function to simplify the main.
Definition at line 467 of file BDSIMClass.cc.
References bdsBunch, bdsOutput, BDSBunch::BeginOfRunAction(), BDSOutput::CloseFile(), BDSOutput::FillBeam(), BDSOutput::FillEventPrimaryOnly(), BDSOutput::FillOptions(), BDSParser::GetBeamBase(), BDSBunch::GetNextParticleValid(), BDSParser::GetOptionsBase(), BDSParser::Instance(), BDSOutput::NewFile(), and BDSBunch::ParticleDefinition().
Referenced by Initialise().
|
inline |
Definition at line 70 of file BDSIMClass.hh.
|
private |
The main function where everything is constructed.
Initialize executable command line options reader object
Parse lattice file
Update options generated by parser with those from executable options.
Check options for consistency
Explicitly initialise materials to construct required materials before global constants.
No longer needed. Everything can safely use BDSGlobalConstants from now on.
Force construction of global constants after parser has been initialised (requires materials first). This uses the options and beam from BDSParser. Non-const as we'll update the particle definition.
Initialize random number generator
Construct output
Check geant4 exists in the current environment
Construct mandatory run manager (the G4 kernel) and register mandatory initialization classes.
Register the geometry and parallel world construction methods with run manager.
Here the geometry isn't actually constructed - this is called by the runManager->Initialize()
For geometry sampling, phys list must be initialized before detector. BUT for samplers we use a parallel world and this HAS to be before the physics
Instantiate the specific type of bunch distribution.
We no longer need beamParticle so delete it to avoid confusion. The definition is held inside bdsBunch (can be updated dynamically).
Construct extra common particles for possible tracking if required without using a physics list.
Optionally generate primaries only and exit Unfortunately, this has to be here as we can't query the geant4 particle table until after the physics list has been constructed and attached a run manager.
Print the geometry tolerance
Set user action classes
Initialize G4 kernel
Create importance store for parallel importance world
Implement bias operations on all volumes only after G4RunManager::Initialize()
Set verbosity levels at run and G4 event level. Per event and stepping are controlled in event, tracking and stepping action. These have to be done here due to the order of construction in Geant4.
Close the geometry in preparation for running - everything is now fixed.
Definition at line 125 of file BDSIMClass.cc.
References BDS::AddIStore(), BDSParser::AmalgamateBeam(), BDSParser::AmalgamateOptions(), argcCache, argvCache, bdsBunch, bdsOutput, BDSExecOptions::Beam(), BDSParticleDefinition::BRho(), BDS::BuildMuonBiasing(), BDS::BuildPhysics(), BDSDetectorConstruction::BuildPhysicsBias(), BDSDetectorConstruction::BuildSamplerWorld(), BDSParser::CheckOptions(), BDS::ConstructAndRegisterParallelWorlds(), BDS::ConstructDesignAndBeamParticle(), BDS::ConstructExtendedParticleSet(), BDS::ConstructParallelWorldPhysics(), BDSBunchFactory::CreateBunch(), BDSOutputFactory::CreateOutput(), BDSBunch::ExpectChangingParticleType(), BDSGeometryWriter::ExportGeometry(), BDS::Geant4EnvironmentIsSet(), GeneratePrimariesOnly(), BDSParser::GetBeam(), BDSParser::GetBiasing(), BDSParser::GetOptions(), BDSExecOptions::IgnoreSIGINT(), ignoreSIGINT, initialised, BDSRunManager::Initialize(), BDSExecOptions::InputFileName(), BDSGlobalConstants::Instance(), BDSMaterials::Instance(), BDSParser::Instance(), BDSParticleDefinition::IsAnIon(), BDS::IsFinite(), BDSParticleDefinition::KineticEnergy(), BDSBunch::Name(), BDSParticleDefinition::Name(), BDSExecOptions::Options(), parser, BDSBunch::ParticleDefinition(), GMAD::OptionsBase::physicsList, BDSMaterials::PrepareRequiredMaterials(), BDSExecOptions::Print(), BDSExecOptions::PrintCopyright(), BDS::PrintDefinedParticles(), BDS::PrintPrimaryParticleProcesses(), realWorld, GMAD::OptionsBase::recreate, BDS::RegisterImportanceBiasing(), BDS::RegisterSamplerPhysics(), runManager, BDSDetectorConstruction::SetDesignParticle(), BDSFieldFactory::SetDesignParticle(), BDSFieldFactory::SetPrimaryGeneratorAction(), BDSGlobalConstants::StoreTrajectoryOptions(), BDSGlobalConstants::UseImportanceSampling(), userComponentFactory, userPhysicsList, usualPrintOut, GMAD::OptionsBase::verbose, and BDS::VerboseEventStop().
Referenced by BDSIM(), and Initialise().
int BDSIM::Initialise | ( | int | argc, |
char ** | argv, | ||
bool | usualPrintOut = true |
||
) |
Initialise everything given these arguments.
Definition at line 116 of file BDSIMClass.cc.
References argcCache, argvCache, initialisationResult, Initialise(), and usualPrintOut.
|
inline |
Accessor as to whether BDSIM kernel is initialised - ie all geometry and physics constructed.
Definition at line 68 of file BDSIMClass.hh.
References initialised.
void BDSIM::RegisterUserComponent | ( | const G4String & | componentTypeName, |
BDSComponentConstructor * | componentConstructor | ||
) |
Register a custom user beam line element by the type name you'd like it to have and the (user-provided) constructor that can construct it.
Definition at line 455 of file BDSIMClass.cc.
References initialised, BDSComponentFactoryUser::RegisterComponent(), and userComponentFactory.
|
inline |
Provide a physics list that will be used inplace of the BDSIM generate one.
Definition at line 87 of file BDSIMClass.hh.
References userPhysicsList.
|
inline |
|
private |
Cache of argc.
Definition at line 98 of file BDSIMClass.hh.
Referenced by BeamOn(), and Initialise().
|
private |
Cache of argv.
Definition at line 99 of file BDSIMClass.hh.
Referenced by BeamOn(), and Initialise().
|
private |
Cache of main objects in BDSIM.
Definition at line 104 of file BDSIMClass.hh.
Referenced by GeneratePrimariesOnly(), Initialise(), and ~BDSIM().
|
private |
Cache of main objects in BDSIM.
Definition at line 103 of file BDSIMClass.hh.
Referenced by GeneratePrimariesOnly(), Initialise(), and ~BDSIM().
|
private |
For cmake testing.
Definition at line 94 of file BDSIMClass.hh.
Referenced by BeamOn(), and Initialise().
|
private |
Possible to not finish initialisation but have completed ok - flag for this.
Definition at line 97 of file BDSIMClass.hh.
Referenced by BDSIM(), BeamOn(), Initialise(), and ~BDSIM().
|
private |
Whether initialisation was completed safely.
Definition at line 96 of file BDSIMClass.hh.
Referenced by BeamOn(), Initialise(), Initialised(), and RegisterUserComponent().
|
private |
Cache of main objects in BDSIM.
Definition at line 102 of file BDSIMClass.hh.
Referenced by Initialise(), and ~BDSIM().
|
private |
Cache of main objects in BDSIM.
Definition at line 108 of file BDSIMClass.hh.
Referenced by BeamOn(), and Initialise().
|
private |
Cache of main objects in BDSIM.
Definition at line 105 of file BDSIMClass.hh.
Referenced by BeamOn(), Initialise(), and ~BDSIM().
|
private |
Optional user registered component factory.
Definition at line 106 of file BDSIMClass.hh.
Referenced by Initialise(), and RegisterUserComponent().
|
private |
Optional user registered physics list.
Definition at line 107 of file BDSIMClass.hh.
Referenced by Initialise(), RegisterUserPhysicsList(), and UserPhysicsList().
|
private |
Whether to allow the usual cout output.
Definition at line 95 of file BDSIMClass.hh.
Referenced by Initialise(), and ~BDSIM().