18#include "BDSColours.hh"
19#include "BDSColourFromMaterial.hh"
20#include "BDSUtilities.hh"
23#include "G4DataVector.hh"
24#include "G4Material.hh"
25#include "G4PhysicsFreeVector.hh"
29#include "CLHEP/Units/SystemOfUnits.h"
43BDSColourFromMaterial::~BDSColourFromMaterial()
46 delete generalDensity;
89 G4DataVector densities(5);
90 for (
auto v : {1e-4, 0.01, 0.1, 1.0, 1e2})
91 {densities.emplace_back(v * CLHEP::g / CLHEP::cm3);}
92 G4DataVector values(5);
93 for (
auto v : {210, 180, 150, 120, 100})
94 {values.emplace_back(v);}
95 generalDensity =
new G4PhysicsFreeVector(densities, values);
99 const G4String& prefixToStripFromName)
101 G4String materialName = material->GetName();
105 std::string toErase =
"g4_";
106 size_t pos = materialName.find(toErase);
107 if (pos != std::string::npos)
108 {materialName.erase(pos, toErase.length());}
111 G4String prefixToStripFromNameLower =
BDS::LowerCase(prefixToStripFromName);
112 if (!prefixToStripFromName.empty() &&
BDS::StrContains(materialName, prefixToStripFromNameLower))
113 {materialName.erase(0, prefixToStripFromName.size());}
115 auto search =
defines.find(materialName);
117 {
return search->second;}
121 G4State state = material->GetState();
124 case G4State::kStateGas:
125 {alpha = 0.05;
break;}
126 case G4State::kStateSolid:
127 {alpha = 1.0;
break;}
128 case G4State::kStateLiquid:
129 {alpha = 0.5;
break;}
131 {alpha = 1.0;
break;}
133 G4double density = material->GetDensity();
134 G4double value = generalDensity->Value(density);
135 G4String vs = G4String(std::to_string(value));
140 std::to_string(alpha));
141 defines[materialName] = result;
147 G4Colour* defaultIn)
const
149 G4String materialName = material->GetName();
153 std::string toErase =
"g4_";
154 size_t pos = materialName.find(toErase);
155 if (pos != std::string::npos)
156 {materialName.erase(pos, toErase.length());}
158 auto search =
defines.find(materialName);
159 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.