DLG4::VolumeBuilders
A fluent interface for Geant4 geometry definition.
Loading...
Searching...
No Matches
Classes | Functions
DLG4::VolumeBuilders::Helpers Namespace Reference

Classes

class  G4MaterialPtrOrString
 

Functions

G4Material * GetMaterial (const G4String &materialName)
 
G4Element * GetElement (const G4String &elementName)
 
G4Material * CopyMaterial (G4MaterialPtrOrString source, const G4String &name, G4double dens, Density unit)
 
G4Material * CopyMaterial (G4MaterialPtrOrString source, const G4String &name)
 

Function Documentation

◆ CopyMaterial() [1/2]

G4Material * CopyMaterial ( G4MaterialPtrOrString  source,
const G4String &  name 
)

Copy a G4Material to one with a new name.

Definition at line 61 of file MaterialsHelpers.cc.

61 {
62 const G4double dens = source->GetDensity();
63 const auto dest = CopyMaterial(source, name, dens, Density::native);
64 return dest;
65 }
G4Material * CopyMaterial(G4MaterialPtrOrString source, const G4String &name, const G4double dens, const Density unit)
Copy a G4Material to one with a new name, and change its density.

◆ CopyMaterial() [2/2]

G4Material * CopyMaterial ( G4MaterialPtrOrString  source,
const G4String &  name,
const G4double  dens,
const Density  unit 
)

Copy a G4Material to one with a new name, and change its density.

Definition at line 51 of file MaterialsHelpers.cc.

52 {
53 const double dens_with_unit = dens * unit.Native();
54 constexpr int n_components = 1;
55 constexpr G4double fraction_mass = 100 * CLHEP::perCent;
56 const auto dest = new G4Material(name, dens_with_unit, n_components);
57 dest->AddMaterial(source, fraction_mass);
58 return dest;
59 }
PropertySetter Native
Definition DLG4Units.hh:182

◆ GetElement()

G4Element * GetElement ( const G4String &  elementName)

Definition at line 31 of file MaterialsHelpers.cc.

31 {
32 // Check the GIlobal Element Table first
33 G4Element *el = G4Element::GetElement(elementName, false);
34
35 if (el) {
36 return el;
37 }
38
39 // Fallback to NIST manager for standard elements
40 G4NistManager *nist = G4NistManager::Instance();
41 el = nist->FindOrBuildElement(elementName);
42
43 if (!el) {
44 G4Exception("GeoModulesContext::GetElement", "ElementNotFound",
45 FatalException, ("Could not find element: " + elementName).c_str());
46 }
47
48 return el;
49 }

◆ GetMaterial()

G4Material * GetMaterial ( const G4String &  materialName)

Get material by local or NIST name.

Parameters
materialName
Returns

Definition at line 10 of file MaterialsHelpers.cc.

10 {
11 // Check local material store (materials already created/defined)
12 // 2nd parameter is warn if missing.
13 G4Material *mat = G4Material::GetMaterial(materialName, false);
14
15 if (mat) {
16 return mat;
17 }
18
19 // Fallback to NIST manager
20 G4NistManager *nist = G4NistManager::Instance();
21 mat = nist->FindOrBuildMaterial(materialName);
22
23 if (!mat) {
24 G4Exception("GeoModulesContext::GetMaterial", "MatNotFound",
25 FatalException, ("Could not find material: " + materialName).c_str());
26 }
27
28 return mat;
29 }