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->getRequiredScalarString("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 if (!physList) {
60 log->error(gphysics::ERR_PHYSLISTERROR, "physics list <" + gphysList + "> could not be loaded.");
61 }
62
63 // Register step limiters (module default add-on).
64 // This is intentionally registered even when users select a standard reference list.
65 physList->RegisterPhysics(new G4StepLimiterPhysics());
66
67 log->info(2, "G4PhysListFactory: <" + g4physList + "> loaded.");
68}
69
70
71// Implementation note (non-Doxygen):
72// Prints Geant4 version metadata and queries Geant4 registries for the available lists/constructors.
73void GPhysics::printAvailable() const {
74 std::string g4ver = gutilities::replaceCharInStringWithChars(G4Version, "$", "");
75
76 log->info(0, "Geant4 Version ", g4ver, " ", G4Date);;
77
78 g4alt::G4PhysListFactory factory;
79 factory.PrintAvailablePhysLists();
80
81 log->info(0, "Available Geant4 Physics Lists:");
82
83 G4PhysicsConstructorRegistry* g4pctorFactory = G4PhysicsConstructorRegistry::Instance();
84 g4pctorFactory->PrintAvailablePhysicsConstructors();
85}
GBase(const std::shared_ptr< GOptions > &gopt, std::string logger_name="")
std::shared_ptr< GLogger > log
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
constexpr int 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)