Belle II Software  release-08-01-10
Materials.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #pragma once
10 #include <framework/core/MRUCache.h>
11 
12 #include <optional>
13 #include <set>
14 #include <string>
15 #include <vector>
16 
17 class G4Material;
18 class G4Element;
19 class G4MaterialPropertiesTable;
20 class G4OpticalSurface;
21 class G4NistElementBuilder;
22 class G4NistMaterialBuilder;
23 
24 namespace Belle2 {
29  namespace gearbox { class Interface; }
30 
31  class GeoMaterial;
32  class GeoOpticalSurface;
33  class GeoMaterialProperty;
34 
35  namespace geometry {
48  class Materials {
49  public:
50  enum { CacheSize = 100 };
51 
53  static Materials& getInstance();
54 
56  ~Materials();
57 
63  static G4Material* get(const std::string& name) { return Materials::getInstance().getMaterial(name); }
64 
80  G4Material* getMaterial(const std::string& name, bool showErrors = true);
81 
86  G4Element* getElement(const std::string& name);
87 
94  G4Material* createMaterial(const gearbox::Interface& parameters);
95 
101  G4Material* createMaterial(const GeoMaterial& parameters);
102 
108  G4OpticalSurface* createOpticalSurface(const gearbox::Interface& parameters);
109 
115  G4OpticalSurface* createOpticalSurface(const GeoOpticalSurface& surface);
116 
124 
131 
133  void clear();
134 
136  void setDensityScale(double scale)
137  {
138  if (scale == 1.0) return resetDensityScale();
139  m_densityScale = scale;
140  }
143  {
144  m_densityScale.reset();
145  }
147  std::set<std::string> getDensityScaleIgnoredMaterials() const { return m_ignoreScaling; }
149  void setDensityScaleIgnoredMaterials(const std::set<std::string>& ignored) { m_ignoreScaling = ignored; }
150  protected:
152  Materials(): m_materialCache(CacheSize) {};
154  Materials(const Materials&) = delete;
156  void operator=(const Materials&) = delete;
158  G4Material* findMaterial(const std::string& name);
159 
162 
164  std::vector<G4MaterialPropertiesTable*> m_PropTables;
165 
168  G4NistElementBuilder* m_nistElementBuilder{nullptr};
170  G4NistMaterialBuilder* m_nistMaterialBuilder{nullptr};
171 
173  G4MaterialPropertiesTable* createProperties(const std::vector<GeoMaterialProperty>& props);
174 
176  void initBuilders();
177 
179  std::optional<double> m_densityScale;
181  std::set<std::string> m_ignoreScaling{"G4_AIR", "Air", "Vacuum"};
182  };
183  } //geometry namespace
185 } //Belle2 namespace
Class to represent a material informaion in the Database.
Definition: GeoMaterial.h:22
Represent an optical finish of a surface.
Exception to be thrown in case of an empty result.
Definition: Interface.h:35
Thin wrapper around the Geant4 Material system.
Definition: Materials.h:48
void setDensityScaleIgnoredMaterials(const std::set< std::string > &ignored)
set the set of material names which will not be scaled in any way
Definition: Materials.h:149
GeoOpticalSurface createOpticalSurfaceConfig(const gearbox::Interface &parameters)
Create Optical Surface Configuration from XML description.
Definition: Materials.cc:309
G4Material * getMaterial(const std::string &name, bool showErrors=true)
Get a pointer to the G4Material with the given name.
Definition: Materials.cc:127
GeoMaterial createMaterialConfig(const gearbox::Interface &parameters)
Create Material from XML description.
Definition: Materials.cc:229
Materials(const Materials &)=delete
Singleton: hide copy constructor.
void resetDensityScale()
Disable density scaling.
Definition: Materials.h:142
void setDensityScale(double scale)
Set the density scale to the given value.
Definition: Materials.h:136
~Materials()
Destructor for objects that I have created.
Definition: Materials.cc:91
static G4Material * get(const std::string &name)
Find given material.
Definition: Materials.h:63
G4NistElementBuilder * m_nistElementBuilder
G4NistElementBuilder instance to create chemical elements with correct natural abundances from NIST d...
Definition: Materials.h:168
G4NistMaterialBuilder * m_nistMaterialBuilder
G4NistMaterialBuilder to create predefined materials from NIST database.
Definition: Materials.h:170
static Materials & getInstance()
Get a reference to the singleton instance.
Definition: Materials.cc:85
Materials()
Singleton: hide constructor.
Definition: Materials.h:152
G4MaterialPropertiesTable * createProperties(const std::vector< GeoMaterialProperty > &props)
Create a properties table from a vector of properties.
Definition: Materials.cc:69
std::set< std::string > getDensityScaleIgnoredMaterials() const
get the set of material names which will not be scaled in any way
Definition: Materials.h:147
void initBuilders()
Initialize Nist Builder instances.
Definition: Materials.cc:96
G4Material * createMaterial(const gearbox::Interface &parameters)
Create a material from the parameters specified by parameters.
Definition: Materials.cc:158
MRUCache< std::string, G4Material * > m_materialCache
Cache for already searched Materials.
Definition: Materials.h:161
std::optional< double > m_densityScale
If set we scale all densities by a given factor.
Definition: Materials.h:179
G4Material * findMaterial(const std::string &name)
find an existing material by name
Definition: Materials.cc:105
std::set< std::string > m_ignoreScaling
Names of materials we don't want to scale.
Definition: Materials.h:181
void clear()
Clear all existing materials.
Definition: Materials.cc:380
std::vector< G4MaterialPropertiesTable * > m_PropTables
Vector of created G4MaterialProperties objects.
Definition: Materials.h:164
G4OpticalSurface * createOpticalSurface(const gearbox::Interface &parameters)
Create an optical surface from parameters, will abort on error.
Definition: Materials.cc:291
void operator=(const Materials &)=delete
Singleton: hide assignment operator.
G4Element * getElement(const std::string &name)
Find given chemical element.
Definition: Materials.cc:150
Abstract base class for different kinds of events.