gphysics
Loading...
Searching...
No Matches
gphysics.cc
Go to the documentation of this file.
1// gphysics
2#include "gphysics.h"
3#include "gphysics_options.h"
5
6// gemc
7#include "gutilities.h"
8
9// geant4 version
10#include "G4Version.hh"
11
12// geant4
13
14// From examples/extended/physicslists/extensibleFactory:
15// The extensible factory also allows for the extension of lists by adding
16// (using "+" as a separator) or replacing (using "_" as a separator)
17// specific physics constructors. These can be specified by
18// pre-defining a short name (e.g. RADIO for G4RadioactiveDecayPhysics) or
19// providing the full class name.
20#include "G4PhysListFactoryAlt.hh"
21
22#include "G4StepLimiterPhysics.hh"
23
24// allow ourselves to give the user extra info about available physics constructors (ctors)
25#include "G4PhysicsConstructorFactory.hh"
26
27
28// Implementation note (non-Doxygen):
29// The public API and semantics are documented in gphysics.h. This translation unit focuses on:
30// - Reading options
31// - Instantiating the requested reference physics list using the Geant4 extensible factory
32// - Registering default add-on constructors
33GPhysics::GPhysics(const std::shared_ptr<GOptions>& gopts) :
34 GBase(gopts, GPHYSICS_LOGGER),
35 physList(nullptr) {
36 log->debug(CONSTRUCTOR, "GPhysics");
37
38 bool showPhys = gopts->getSwitch("showPhysics");
39 std::string gphysList = gopts->getScalarString("phys_list");
40
41 if (showPhys) {
42 // Diagnostic mode: print what Geant4 advertises and return without building a list.
43 printAvailable();
44 return;
45 }
46
47 // g4alt::G4PhysListFactoryAlt is the extensible factory
48 // including the G4PhysListFactoryAlt.hh header and the line:
49 // using namespace g4alt;
50 // would make this a drop-in replacement, but we'll list the explicit
51 // namespace here just for clarity
52 g4alt::G4PhysListFactory factory;
53
54 // The Geant4 factory syntax is whitespace-sensitive; normalize user input.
55 std::string g4physList = gutilities::removeAllSpacesFromString(gphysList);
56
57 physList = factory.GetReferencePhysList(g4physList);
58
59 // Register step limiters (module default add-on).
60 // This is intentionally registered even when users select a standard reference list.
61 physList->RegisterPhysics(new G4StepLimiterPhysics());
62
63 if (!physList) { log->error(ERR_PHYSLISTERROR, "physics list <" + gphysList + "> could not be loaded."); }
64
65 log->info(2, "G4PhysListFactory: <" + g4physList + "> loaded.");
66}
67
68
69// Implementation note (non-Doxygen):
70// Prints Geant4 version metadata and queries Geant4 registries for the available lists/constructors.
71void GPhysics::printAvailable() const {
72 std::string g4ver = gutilities::replaceCharInStringWithChars(G4Version, "$", "");
73
74 log->info(0, "Geant4 Version ", g4ver, " ", G4Date);;
75
76 g4alt::G4PhysListFactory factory;
77 factory.PrintAvailablePhysLists();
78
79 log->info(0, "Available Geant4 Physics Lists:");
80
81 G4PhysicsConstructorRegistry* g4pctorFactory = G4PhysicsConstructorRegistry::Instance();
82 g4pctorFactory->PrintAvailablePhysicsConstructors();
83}
std::shared_ptr< GLogger > log
void debug(debug_type type, Args &&... args) const
void info(int level, Args &&... args) const
void error(int exit_code, Args &&... args) const
GPhysics(const std::shared_ptr< GOptions > &gopts)
Constructs the physics list builder and (unless requested otherwise) instantiates the physics list.
Definition gphysics.cc:33
CONSTRUCTOR
constexpr const char * GPHYSICS_LOGGER
#define ERR_PHYSLISTERROR
Error code used when the requested physics list cannot be loaded.
string removeAllSpacesFromString(const std::string &str)
string replaceCharInStringWithChars(const std::string &input, const std::string &toReplace, const std::string &replacement)