LDMX Software
PtrRetrieval.h
1#ifndef SIMCORE_PTRRETRIEVAL_H
2#define SIMCORE_PTRRETRIEVAL_H
3
4//----------------//
5// C++ StdLib //
6//----------------//
7#include <iostream>
8#include <string>
9
10//------------//
11// Geant4 //
12//------------//
13#include "G4Gamma.hh"
14#include "G4LogicalVolume.hh"
15#include "G4LogicalVolumeStore.hh"
16#include "G4ParticleDefinition.hh"
17#include "G4PhysicalVolumeStore.hh"
18#include "G4ProcessManager.hh"
19#include "G4Region.hh"
20#include "G4RegionStore.hh"
21#include "G4VPhysicalVolume.hh"
22
23namespace simcore {
24namespace g4user {
25namespace ptrretrieval {
26
33inline const G4VProcess* getProcess(const G4ParticleDefinition* particle,
34 const std::string& processName) {
35 if (!particle) return nullptr;
36
37 const auto manager = particle->GetProcessManager();
38 if (!manager) return nullptr;
39
40 const auto processes = manager->GetProcessList();
41 for (int i = 0; i < processes->size(); ++i) {
42 const auto process = (*processes)[i];
43 if (process->GetProcessName().find(processName) != std::string::npos) {
44 return process;
45 }
46 }
47 return nullptr;
48}
49
54inline const G4VProcess* getPhotonuclearProcess() {
55 return getProcess(G4Gamma::Definition(), "photonNuclear");
56}
57
73inline G4Region* getRegion(const std::string& name) {
74 G4Region* region = G4RegionStore::GetInstance()->GetRegion(name);
75 if (!region) {
76 return nullptr;
77 }
78 return region;
79}
80
86inline G4VPhysicalVolume* getPhysicalVolume(const std::string& name) {
87 auto* volume = G4PhysicalVolumeStore::GetInstance()->GetVolume(name);
88 if (!volume) {
89 return nullptr;
90 }
91 return volume;
92}
93
99inline G4LogicalVolume* getLogicalVolume(const std::string& name) {
100 auto* volume = G4LogicalVolumeStore::GetInstance()->GetVolume(name);
101 if (!volume) {
102 return nullptr;
103 }
104 return volume;
105}
106
107} // namespace ptrretrieval
108} // namespace g4user
109} // namespace simcore
110#endif // SIMCORE_PTRRETRIEVAL_H
This namespace is meant to contain all the standard user actions that allow a Geant4 user to interfac...