19#include "BDSAcceleratorModel.hh"
20#include "BDSAuxiliaryNavigator.hh"
21#include "BDSBeamline.hh"
24#include "BDSEventAction.hh"
25#include "BDSEventInfo.hh"
26#include "BDSException.hh"
27#include "BDSGlobalConstants.hh"
28#include "BDSOutput.hh"
29#include "BDSParser.hh"
30#include "BDSRunAction.hh"
31#include "BDSSamplerPlacementRecord.hh"
32#include "BDSSamplerRegistry.hh"
34#include "parser/beamBase.h"
35#include "parser/optionsBase.h"
38#include "G4ParticleTable.hh"
39#include "G4ProcessManager.hh"
40#include "G4ProcessVector.hh"
42#include "G4Version.hh"
44#include "CLHEP/Random/Random.h"
52#if G4VERSION_NUMBER > 1049
53#include "BDSPhysicsUtilities.hh"
54#include "G4Positron.hh"
55#include "G4Electron.hh"
58BDSRunAction::BDSRunAction(
BDSOutput* outputIn,
62 G4String trajectorySamplerIDIn):
64 starttime(time(nullptr)),
67 bunchGenerator(bunchGeneratorIn),
68 usingIons(usingIonsIn),
69 cpuStartTime(std::clock_t()),
70 eventAction(eventActionIn),
71 trajectorySamplerID(trajectorySamplerIDIn)
74BDSRunAction::~BDSRunAction()
79void BDSRunAction::BeginOfRunAction(
const G4Run* aRun)
84 BDSAuxiliaryNavigator::ResetNavigatorStates();
96 CLHEP::HepRandom::saveFullState(ss);
101 starttime = time(
nullptr);
105 G4cout << __METHOD_NAME__ <<
"Run " << aRun->GetRunID()
106 <<
" start. Time is " << asctime(localtime(&starttime)) << G4endl;
125#if G4VERSION_NUMBER > 1049
135void BDSRunAction::EndOfRunAction(
const G4Run* aRun)
138 time_t stoptime = time(
nullptr);
141 G4float duration = difftime(stoptime, starttime);
145 auto cpuEndTime = std::clock();
146 G4double durationCPU =
static_cast<G4double
>(cpuEndTime -
cpuStartTime) / CLOCKS_PER_SEC;
150 G4cout << G4endl << __METHOD_NAME__ <<
"Run " << aRun->GetRunID()
151 <<
" end. Time is " << asctime(localtime(&stoptime));
159 G4cout << __METHOD_NAME__ <<
"Run Duration >> " << (int)duration <<
" s" << G4endl;
164 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
165 G4ParticleTable::G4PTblDicIterator* particleIterator = particleTable->GetIterator();
166 particleIterator->reset();
167 while ((*particleIterator)())
169 G4ParticleDefinition* particle = particleIterator->value();
170 G4cout <<
"Particle: \"" << particle->GetParticleName() <<
"\", defined processes are: " << G4endl;
171 G4ProcessManager* pManager = particle->GetProcessManager();
174 G4ProcessVector* processList = pManager->GetProcessList();
177 for (G4int i = 0; i < (G4int)processList->size(); i++)
178 {G4cout <<
"\"" << (*processList)[i]->GetProcessName() <<
"\"" << G4endl;}
188 std::vector<G4int> samplerIDs;
195 G4bool found =
false;
196 for (
const auto& samplerInfo : *samplerRegistry)
198 if (samplerInfo.UniqueName() == tok)
200 samplerIDs.push_back(i);
207 {
throw BDSException(__METHOD_NAME__,
"Error: sampler \"" + tok +
"\" named in the option storeTrajectorySamplerID was not found.");}
216 G4double maxS = 1*CLHEP::m;
221 for (
const auto& range : sRangeToStore)
223 if (range.first > maxS)
224 {
throw BDSException(__METHOD_NAME__,
"S coordinate " + std::to_string(range.first / CLHEP::m) +
"m in option storeTrajectoryElossSRange is beyond the length of the beam line (2m margin).");}
const BDSBeamline * BeamlineMain() const
Accessor.
A vector of BDSBeamlineElement instances - a beamline.
G4double GetTotalArcLength() const
Get the total ARC length for the beamline - ie the maximum s position.
The base class for bunch distribution generators.
virtual const BDSParticleDefinition * ParticleDefinition() const
Access the beam particle definition.
virtual void BeginOfRunAction(G4int numberOfEvents)
Process information at the event level.
void SetSamplerIDsForTrajectories(const std::vector< G4int > &samplerIDsIn)
Update the vector of sampler IDs to match for trajectories.
Interface to store event information use G4 hooks.
void SetStopTime(const time_t &stopTimeIn)
Setters.
void SetStartTime(const time_t &startTimeIn)
Setters.
void SetDurationCPU(G4float durationCPUIn)
Setters.
void SetSeedStateAtStart(const G4String &seedStateAtStartIn)
Setters.
void SetDurationWall(G4float durationWallIn)
Setters.
General exception with possible name of object and message.
static BDSGlobalConstants * Instance()
Access method.
Output base class that defines interface for all output types.
virtual void NewFile()=0
Open a new file. This should call WriteHeader() in it.
virtual void InitialiseGeometryDependent()
void FillParticleData(G4bool writeIons)
Fill the local structure particle data with information. Also calls WriteParticleData().
void FillRun(const BDSEventInfo *info)
Copy run information to output structure.
void FillBeam(const GMAD::BeamBase *beam)
void FillOptions(const GMAD::OptionsBase *options)
virtual void CloseFile()=0
const GMAD::OptionsBase * GetOptionsBase() const
Return bare options base class.
static BDSParser * Instance()
Access method.
const GMAD::BeamBase * GetBeamBase() const
Return bare beam base class.
void SetTrajectorySamplerIDs() const
BDSBunch * bunchGenerator
Cache of bunch generator.
std::clock_t cpuStartTime
Start time of run.
BDSEventAction * eventAction
Event action for updating information at start of run.
G4String trajectorySamplerID
Copy of option.
std::string seedStateAtStart
Seed state at start of the run.
void CheckTrajectoryOptions() const
void PrintAllProcessesForAllParticles() const
const G4bool usingIons
Cache of whether ions are being used (for particle table writing out).
BDSOutput * output
Cache of output instance. Not owned by this class.
Associated information for the placement of a sampler.
static BDSSamplerRegistry * Instance()
Accessor for registry.
Options for a beam distribution.
Basic options class independent of Geant4.
void FixGeant105ThreshholdsForBeamParticle(const BDSParticleDefinition *particleDefinition)
Apply FixGeant105ThreshholdsForParticle to the beam particle definition.
void FixGeant105ThreshholdsForParticle(const G4ParticleDefinition *particleDefinition)