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;
90 G4DataVector densities(5);
91 for (
auto v : {1e-4, 0.01, 0.1, 1.0, 1e2})
92 {densities.emplace_back(v * CLHEP::g / CLHEP::cm3);}
93 G4DataVector values(5);
94 for (
auto v : {210, 180, 150, 120, 100})
95 {values.emplace_back(v);}
96 generalDensity =
new G4PhysicsFreeVector(densities, values);
100 const G4String& prefixToStripFromName)
102 G4String materialName = material->GetName();
106 std::string toErase =
"g4_";
107 size_t pos = materialName.find(toErase);
108 if (pos != std::string::npos)
109 {materialName.erase(pos, toErase.length());}
112 G4String prefixToStripFromNameLower =
BDS::LowerCase(prefixToStripFromName);
113 if (!prefixToStripFromName.empty() &&
BDS::StrContains(materialName, prefixToStripFromNameLower))
114 {materialName.erase(0, prefixToStripFromName.size());}
116 auto search =
defines.find(materialName);
118 {
return search->second;}
122 G4State state = material->GetState();
125 case G4State::kStateGas:
126 {alpha = 0.05;
break;}
127 case G4State::kStateSolid:
128 {alpha = 1.0;
break;}
129 case G4State::kStateLiquid:
130 {alpha = 0.5;
break;}
132 {alpha = 1.0;
break;}
134 G4double density = material->GetDensity();
135 G4double value = generalDensity->Value(density);
136 G4String vs = G4String(std::to_string(value));
141 std::to_string(alpha));
142 defines[materialName] = result;
148 G4Colour* defaultIn)
const
150 G4String materialName = material->GetName();
154 std::string toErase =
"g4_";
155 size_t pos = materialName.find(toErase);
156 if (pos != std::string::npos)
157 {materialName.erase(pos, toErase.length());}
159 auto search =
defines.find(materialName);
160 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.
G4Colour * GetColour(G4double red, G4double green, G4double blue, G4double alpha=1)
Get a cached anonymous colour by values.
static BDSColours * Instance()
singleton pattern
G4bool StrContains(const G4String &str, const G4String &test)
Utility function to simplify lots of syntax changes for pedantic g4 changes.
G4String LowerCase(const G4String &str)
Utility function to simplify lots of syntax changes for pedantic g4 changes.