19#include "BDSColours.hh"
20#include "BDSColourFromMaterial.hh"
21#include "BDSUtilities.hh"
24#include "G4DataVector.hh"
25#include "G4Material.hh"
26#include "G4PhysicsFreeVector.hh"
30#include "CLHEP/Units/SystemOfUnits.h"
44BDSColourFromMaterial::~BDSColourFromMaterial()
47 delete generalDensity;
84 G4DataVector densities(5);
85 for (
auto v : {1e-4, 0.01, 0.1, 1.0, 1e2})
86 {densities.emplace_back(v * CLHEP::g / CLHEP::cm3);}
87 G4DataVector values(5);
88 for (
auto v : {210, 180, 150, 120, 100})
89 {values.emplace_back(v);}
90 generalDensity =
new G4PhysicsFreeVector(densities, values);
94 const G4String& prefixToStripFromName)
96 G4String materialName = material->GetName();
100 std::string toErase =
"g4_";
101 size_t pos = materialName.find(toErase);
102 if (pos != std::string::npos)
103 {materialName.erase(pos, toErase.length());}
105 if (!prefixToStripFromName.empty())
106 {materialName.erase(0, prefixToStripFromName.size());}
108 auto search =
defines.find(materialName);
110 {
return search->second;}
114 G4State state = material->GetState();
117 case G4State::kStateGas:
118 {alpha = 0.05;
break;}
119 case G4State::kStateSolid:
120 {alpha = 1.0;
break;}
121 case G4State::kStateLiquid:
122 {alpha = 0.5;
break;}
124 {alpha = 1.0;
break;}
126 G4double density = material->GetDensity();
127 G4double value = generalDensity->Value(density);
128 G4String vs = G4String(std::to_string(value));
133 std::to_string(alpha));
134 defines[materialName] = result;
140 G4Colour* defaultIn)
const
142 G4String materialName = material->GetName();
146 std::string toErase =
"g4_";
147 size_t pos = materialName.find(toErase);
148 if (pos != std::string::npos)
149 {materialName.erase(pos, toErase.length());}
151 auto search =
defines.find(materialName);
152 return search !=
defines.end() ? search->second : defaultIn;
Automatic colours from materials.
std::map< G4String, G4Colour * > defines
Specially defined material colours.
static BDSColourFromMaterial * Instance()
Singleton pattern.
G4Colour * GetColour(const G4Material *material, const G4String &prefixToStripFromName="")
Get colour from name.
BDSColourFromMaterial()
Private constructor as singleton.
G4Colour * GetColourWithDefault(const G4Material *material, G4Colour *defaultIn) const
Get colour from name - if not found return the supplied default.
Colour class that holds all colours used in BDSIM.
static BDSColours * Instance()
singleton pattern
G4Colour * GetColour(const G4String &type, G4bool normaliseTo255=true)
Get colour from name.
G4String LowerCase(const G4String &str)
Utility function to simplify lots of syntax changes for pedantic g4 changes.