gphysics
Loading...
Searching...
No Matches
gphysicsRuntime.h
Go to the documentation of this file.
1#pragma once
2
3#include "G4VModularPhysicsList.hh"
4#include "G4Cache.hh"
5
6#include <map>
7#include <memory>
8#include <optional>
9#include <set>
10#include <string>
11#include <vector>
12
14class G4VProcess;
15
16namespace gphysics {
17
19 std::string name;
20 std::string category;
21 bool active = true;
22 bool mixed = false;
23 bool editable = true;
24 std::vector<std::string> particles;
25};
26
30class RuntimePhysicsList : public G4VModularPhysicsList {
31public:
32 explicit RuntimePhysicsList(const std::string& selection);
33 ~RuntimePhysicsList() override;
34 void ConstructParticle() override;
35 void ConstructProcess() override;
36 void SetCuts() override;
37 void InitializeWorker() override;
38 void TerminateWorker() override;
39
40 bool select(const std::string& selection, std::string& error);
41 bool setProductionCut(double millimeters, std::string& error);
42 bool setProcessEnabled(const std::string& name, bool enabled, std::string& error);
43 [[nodiscard]] const std::string& selection() const { return selected; }
44 [[nodiscard]] std::vector<ProcessState> processes() const;
45 [[nodiscard]] static std::vector<std::string> referenceLists();
46 [[nodiscard]] static std::vector<std::string> constructors();
47 [[nodiscard]] static RuntimePhysicsList* current();
48
49private:
50 friend class ::GPhysicsMessenger;
51 void clearProcesses();
52 void rebuildWorker();
53 void applyActivation();
54 void broadcast(const std::string& command);
55 struct ThreadState {
56 bool initialized = false;
57 std::set<G4VProcess*> retained;
58 std::vector<G4VPhysicsConstructor*> retainedConstructors;
59 };
60
61 // Geant4 list destructors delete the global particle table. Keep factory lists until shutdown;
62 // non-EM processes are removed at each switch, and factory lists retain constructor ownership.
63 std::vector<std::unique_ptr<G4VModularPhysicsList>> lists;
64 G4VModularPhysicsList* activeList = nullptr;
65 std::vector<G4VPhysicsConstructor*> activeConstructors;
66 G4Cache<ThreadState> threadState;
67 std::unique_ptr<GPhysicsMessenger> messenger;
68 std::map<std::string, bool> activation;
69 std::optional<double> productionCut;
70 std::string selected;
71 std::string electromagneticIdentity;
72};
73
74} // namespace gphysics
RuntimePhysicsList(const std::string &selection)
static std::vector< std::string > referenceLists()
static std::vector< std::string > constructors()
bool setProductionCut(double millimeters, std::string &error)
static RuntimePhysicsList * current()
const std::string & selection() const
bool select(const std::string &selection, std::string &error)
std::vector< ProcessState > processes() const
bool setProcessEnabled(const std::string &name, bool enabled, std::string &error)
std::vector< std::string > particles