Belle II Software  release-08-01-10
Materials Class Reference

Thin wrapper around the Geant4 Material system. More...

#include <Materials.h>

Collaboration diagram for Materials:

Public Types

enum  { CacheSize = 100 }
 

Public Member Functions

 ~Materials ()
 Destructor for objects that I have created.
 
G4Material * getMaterial (const std::string &name, bool showErrors=true)
 Get a pointer to the G4Material with the given name. More...
 
G4Element * getElement (const std::string &name)
 Find given chemical element. More...
 
G4Material * createMaterial (const gearbox::Interface &parameters)
 Create a material from the parameters specified by parameters. More...
 
G4Material * createMaterial (const GeoMaterial &parameters)
 Create Geant4 Material from Material definition in DB. More...
 
G4OpticalSurface * createOpticalSurface (const gearbox::Interface &parameters)
 Create an optical surface from parameters, will abort on error. More...
 
G4OpticalSurface * createOpticalSurface (const GeoOpticalSurface &surface)
 Create an optical surface from Surface definition in DB. More...
 
GeoMaterial createMaterialConfig (const gearbox::Interface &parameters)
 Create Material from XML description. More...
 
GeoOpticalSurface createOpticalSurfaceConfig (const gearbox::Interface &parameters)
 Create Optical Surface Configuration from XML description. More...
 
void clear ()
 Clear all existing materials.
 
void setDensityScale (double scale)
 Set the density scale to the given value.
 
void resetDensityScale ()
 Disable density scaling.
 
std::set< std::string > getDensityScaleIgnoredMaterials () const
 get the set of material names which will not be scaled in any way
 
void setDensityScaleIgnoredMaterials (const std::set< std::string > &ignored)
 set the set of material names which will not be scaled in any way
 

Static Public Member Functions

static MaterialsgetInstance ()
 Get a reference to the singleton instance.
 
static G4Material * get (const std::string &name)
 Find given material. More...
 

Protected Member Functions

 Materials ()
 Singleton: hide constructor.
 
 Materials (const Materials &)=delete
 Singleton: hide copy constructor.
 
void operator= (const Materials &)=delete
 Singleton: hide assignment operator.
 
G4Material * findMaterial (const std::string &name)
 find an existing material by name
 
G4MaterialPropertiesTable * createProperties (const std::vector< GeoMaterialProperty > &props)
 Create a properties table from a vector of properties. More...
 
void initBuilders ()
 Initialize Nist Builder instances.
 

Protected Attributes

MRUCache< std::string, G4Material * > m_materialCache
 Cache for already searched Materials.
 
std::vector< G4MaterialPropertiesTable * > m_PropTables
 Vector of created G4MaterialProperties objects.
 
G4NistElementBuilder * m_nistElementBuilder {nullptr}
 G4NistElementBuilder instance to create chemical elements with correct natural abundances from NIST database.
 
G4NistMaterialBuilder * m_nistMaterialBuilder {nullptr}
 G4NistMaterialBuilder to create predefined materials from NIST database.
 
std::optional< double > m_densityScale
 If set we scale all densities by a given factor.
 
std::set< std::string > m_ignoreScaling {"G4_AIR", "Air", "Vacuum"}
 Names of materials we don't want to scale.
 

Detailed Description

Thin wrapper around the Geant4 Material system.

This class serves the purpose to simplify the access to the Geant4 materials using the G4NistManager and to directly create materials from a Gearbox parameter set. Since Geant4 keeps track of all defined materials, this class is also able to find Materials created directly by the user.

Care should be taken when a Material is created with a name that already exists. In that case it may be possible that we return the wrong material since the first material with the given name will be returned.

Definition at line 48 of file Materials.h.

Member Function Documentation

◆ createMaterial() [1/2]

G4Material * createMaterial ( const gearbox::Interface parameters)

Create a material from the parameters specified by parameters.

Parameters
parametersMaterial properties
Returns
pointer to the newly created material, 0 if there was an error creating it

Definition at line 158 of file Materials.cc.

159  {
160  GeoMaterial material = createMaterialConfig(parameters);
161  return createMaterial(material);
162  }
GeoMaterial createMaterialConfig(const gearbox::Interface &parameters)
Create Material from XML description.
Definition: Materials.cc:229
G4Material * createMaterial(const gearbox::Interface &parameters)
Create a material from the parameters specified by parameters.
Definition: Materials.cc:158

◆ createMaterial() [2/2]

G4Material * createMaterial ( const GeoMaterial parameters)

Create Geant4 Material from Material definition in DB.

Parameters
parametersMaterial properties
Returns
pointer to the newly created material, 0 if there was an error creating it

Definition at line 164 of file Materials.cc.

◆ createMaterialConfig()

GeoMaterial createMaterialConfig ( const gearbox::Interface parameters)

Create Material from XML description.

Parameters
parametersGearDir pointing to the Material description
Returns
GeoMaterial instance describing the material and suitable for serialization

Definition at line 229 of file Materials.cc.

◆ createOpticalSurface() [1/2]

G4OpticalSurface * createOpticalSurface ( const gearbox::Interface parameters)

Create an optical surface from parameters, will abort on error.

Parameters
parametersOptical surface definition
Returns
new optical surface

Definition at line 291 of file Materials.cc.

◆ createOpticalSurface() [2/2]

G4OpticalSurface * createOpticalSurface ( const GeoOpticalSurface surface)

Create an optical surface from Surface definition in DB.

Parameters
surfaceOptical surface definition
Returns
new optical surface

Definition at line 297 of file Materials.cc.

◆ createOpticalSurfaceConfig()

GeoOpticalSurface createOpticalSurfaceConfig ( const gearbox::Interface parameters)

Create Optical Surface Configuration from XML description.

Parameters
parametersGearDir pointing to the Optical Surface description
Returns
GeoOpticalSurface instance describing the material and suitable for serialization

Definition at line 309 of file Materials.cc.

◆ createProperties()

G4MaterialPropertiesTable * createProperties ( const std::vector< GeoMaterialProperty > &  props)
protected

Create a properties table from a vector of properties.

Return 0 if the vector is empty

Definition at line 69 of file Materials.cc.

◆ get()

static G4Material* get ( const std::string &  name)
inlinestatic

Find given material.

Shorthand for Materials::getInstance().getMaterial()

See also
Materials::getMaterial
Parameters
nameof the material to find

Definition at line 63 of file Materials.h.

63 { return Materials::getInstance().getMaterial(name); }
G4Material * getMaterial(const std::string &name, bool showErrors=true)
Get a pointer to the G4Material with the given name.
Definition: Materials.cc:127
static Materials & getInstance()
Get a reference to the singleton instance.
Definition: Materials.cc:85

◆ getElement()

G4Element * getElement ( const std::string &  name)

Find given chemical element.

Parameters
nameName of the Element, e.g. Si, Al, He

Definition at line 150 of file Materials.cc.

◆ getMaterial()

G4Material * getMaterial ( const std::string &  name,
bool  showErrors = true 
)

Get a pointer to the G4Material with the given name.

If the given name cannot be found we also try to find it in the Nist database by prepending the name with G4_ and trying in with given case and all uppercase since single element materials are defined as e.g. G4_Si, G4_Al and other materials are defined all uppercase, e.g. G4_AIR, G4_TEFLON.

Found materials are cached internaly using an MRU cache so repitive access to materials should be O(1) in most cases

Parameters
nameName of the material to be found
showErrorsIf false don't show any errors, just return nullptr if the material cannot be found

Definition at line 127 of file Materials.cc.


The documentation for this class was generated from the following files: