Belle II Software  release-05-02-19
Materials.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010-2019 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Martin Ritter *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 #include <framework/core/MRUCache.h>
13 
14 #include <optional>
15 #include <set>
16 #include <string>
17 #include <vector>
18 
19 class G4Material;
20 class G4Element;
21 class G4MaterialPropertiesTable;
22 class G4OpticalSurface;
23 class G4NistElementBuilder;
24 class G4NistMaterialBuilder;
25 
26 namespace Belle2 {
31  namespace gearbox { class Interface; }
32 
33  class GeoMaterial;
34  class GeoOpticalSurface;
35  class GeoMaterialProperty;
36 
37  namespace geometry {
50  class Materials {
51  public:
52  enum { CacheSize = 100 };
53 
55  static Materials& getInstance();
56 
58  ~Materials();
59 
65  static G4Material* get(const std::string& name) { return Materials::getInstance().getMaterial(name); }
66 
81  G4Material* getMaterial(const std::string& name, bool showErrors = true);
82 
87  G4Element* getElement(const std::string& name);
88 
95  G4Material* createMaterial(const gearbox::Interface& parameters);
96 
102  G4Material* createMaterial(const GeoMaterial& parameters);
103 
109  G4OpticalSurface* createOpticalSurface(const gearbox::Interface& parameters);
110 
116  G4OpticalSurface* createOpticalSurface(const GeoOpticalSurface& surface);
117 
125 
132 
134  void clear();
135 
137  void setDensityScale(double scale)
138  {
139  if (scale == 1.0) return resetDensityScale();
140  m_densityScale = scale;
141  }
144  {
145  m_densityScale.reset();
146  }
148  std::set<std::string> getDensityScaleIgnoredMaterials() const { return m_ignoreScaling; }
150  void setDensityScaleIgnoredMaterials(const std::set<std::string>& ignored) { m_ignoreScaling = ignored; }
151  protected:
153  Materials(): m_materialCache(CacheSize) {};
155  Materials(const Materials&) = delete;
157  void operator=(const Materials&) = delete;
159  G4Material* findMaterial(const std::string& name);
160 
163 
165  std::vector<G4MaterialPropertiesTable*> m_PropTables;
166 
169  G4NistElementBuilder* m_nistElementBuilder{nullptr};
171  G4NistMaterialBuilder* m_nistMaterialBuilder{nullptr};
172 
174  G4MaterialPropertiesTable* createProperties(const std::vector<GeoMaterialProperty>& props);
175 
177  void initBuilders();
178 
180  std::optional<double> m_densityScale;
182  std::set<std::string> m_ignoreScaling{"G4_AIR", "Air", "Vacuum"};
183  };
184  } //geometry namespace
186 } //Belle2 namespace
Belle2::geometry::Materials::getDensityScaleIgnoredMaterials
std::set< std::string > getDensityScaleIgnoredMaterials() const
get the set of material names which will not be scaled in any way
Definition: Materials.h:148
Belle2::geometry::Materials::m_materialCache
MRUCache< std::string, G4Material * > m_materialCache
Cache for already searched Materials.
Definition: Materials.h:162
Belle2::GeoMaterial
Class to represent a material informaion in the Database.
Definition: GeoMaterial.h:32
Belle2::geometry::Materials::initBuilders
void initBuilders()
Initialize Nist Builder instances.
Definition: Materials.cc:98
Belle2::geometry::Materials::createOpticalSurfaceConfig
GeoOpticalSurface createOpticalSurfaceConfig(const gearbox::Interface &parameters)
Create Optical Surface Configuration from XML description.
Definition: Materials.cc:306
Belle2::geometry::Materials::m_nistElementBuilder
G4NistElementBuilder * m_nistElementBuilder
G4NistElementBuilder instance to create chemical elements with correct natural abundances from NIST d...
Definition: Materials.h:169
Belle2::geometry::Materials::createMaterial
G4Material * createMaterial(const gearbox::Interface &parameters)
Create a material from the parameters specified by parameters.
Definition: Materials.cc:159
Belle2::geometry::Materials::createMaterialConfig
GeoMaterial createMaterialConfig(const gearbox::Interface &parameters)
Create Material from XML description.
Definition: Materials.cc:226
Belle2::MRUCache< std::string, G4Material * >
Belle2::geometry::Materials::operator=
void operator=(const Materials &)=delete
Singleton: hide assignment operator.
Belle2::geometry::Materials::get
static G4Material * get(const std::string &name)
Find given material.
Definition: Materials.h:65
Belle2::geometry::Materials::~Materials
~Materials()
Destructor for objects that I have created.
Definition: Materials.cc:93
Belle2::geometry::Materials::m_densityScale
std::optional< double > m_densityScale
If set we scale all densities by a given factor.
Definition: Materials.h:180
Belle2::geometry::Materials::setDensityScale
void setDensityScale(double scale)
Set the density scale to the given value.
Definition: Materials.h:137
Belle2::geometry::Materials::findMaterial
G4Material * findMaterial(const std::string &name)
find an existing material by name
Definition: Materials.cc:107
Belle2::GeoOpticalSurface
Represent an optical finish of a surface.
Definition: GeoOpticalSurface.h:31
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::geometry::Materials::getInstance
static Materials & getInstance()
Get a reference to the singleton instance.
Definition: Materials.cc:87
Belle2::geometry::Materials::Materials
Materials()
Singleton: hide constructor.
Definition: Materials.h:153
Belle2::geometry::Materials::createOpticalSurface
G4OpticalSurface * createOpticalSurface(const gearbox::Interface &parameters)
Create an optical surface from parameters, will abort on error.
Definition: Materials.cc:288
Belle2::geometry::Materials::createProperties
G4MaterialPropertiesTable * createProperties(const std::vector< GeoMaterialProperty > &props)
Create a properties table from a vector of properties.
Definition: Materials.cc:71
Belle2::geometry::Materials
Thin wrapper around the Geant4 Material system.
Definition: Materials.h:50
Belle2::geometry::Materials::setDensityScaleIgnoredMaterials
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:150
Belle2::geometry::Materials::m_nistMaterialBuilder
G4NistMaterialBuilder * m_nistMaterialBuilder
G4NistMaterialBuilder to create predefined materials from NIST database.
Definition: Materials.h:171
Belle2::gearbox::Interface
Exception to be thrown in case of an empty result.
Definition: Interface.h:37
Belle2::geometry::Materials::getElement
G4Element * getElement(const std::string &name)
Find given chemical element.
Definition: Materials.cc:151
Belle2::geometry::Materials::m_PropTables
std::vector< G4MaterialPropertiesTable * > m_PropTables
Vector of created G4MaterialProperties objects.
Definition: Materials.h:165
Belle2::geometry::Materials::getMaterial
G4Material * getMaterial(const std::string &name, bool showErrors=true)
Get a pointer to the G4Material with the given name.
Definition: Materials.cc:129
Belle2::geometry::Materials::resetDensityScale
void resetDensityScale()
Disable density scaling.
Definition: Materials.h:143
Belle2::geometry::Materials::clear
void clear()
Clear all existing materials.
Definition: Materials.cc:377
Belle2::geometry::Materials::m_ignoreScaling
std::set< std::string > m_ignoreScaling
Names of materials we don't want to scale.
Definition: Materials.h:182