19 #include <G4NistManager.hh> 20 #include <G4StableIsotopes.hh> 22 #include <G4Isotope.hh> 23 #include <G4Material.hh> 24 #include <G4UnitsTable.hh> 26 #include <G4LogicalVolume.hh> 27 #include <G4PVPlacement.hh> 28 #include <G4RunManager.hh> 29 #include <G4VPersistencyManager.hh> 30 #include <G4GDMLParser.hh> 31 #include <G4UserLimits.hh> 33 #include <G4SolidStore.hh> 34 #include <G4LogicalVolumeStore.hh> 35 #include <G4PhysicalVolumeStore.hh> 37 #include <G4FieldManager.hh> 39 #include <G4UnitsTable.hh> 40 #include <G4SystemOfUnits.hh> 41 #include <G4PhysicalConstants.hh> 43 #include <G4RegionStore.hh> 58 new G4UnitDefinition(
"volt/cm",
"V/cm",
"Electric field",
volt/
cm);
69 std::istringstream theStream(value);
78 std::size_t
pos = value.find(
"(");
79 if (pos == std::string::npos)
return G4Color(0.5,0.5,0.5,1.0);
81 value = value.substr(pos+1);
82 pos = value.find(
",");
83 if (pos == std::string::npos)
return G4Color(0.5,0.5,0.5,1.0);
85 double r = ParseFloat(elem);
87 value = value.substr(pos+1);
88 pos = value.find(
",");
89 if (pos == std::string::npos)
return G4Color(0.5,0.5,0.5,1.0);
90 elem = value.substr(0,pos);
91 double g = ParseFloat(elem);
93 value = value.substr(pos+1);
94 pos = value.find(
",");
95 if (pos == std::string::npos) {
96 double b = ParseFloat(value);
97 return G4Color(r,g,b,1.0);
99 elem = value.substr(0,pos);
100 double b = ParseFloat(elem);
102 value = value.substr(pos+1);
103 double a = ParseFloat(value);
105 return G4Color(r,g,b,a);
113 std::istringstream theStream(value);
114 theStream >> val >> unit;
115 val *= G4UnitDefinition::GetValueOf(unit);
121 G4ThreeVector field(0,0,0);
122 value = value.substr(value.find(
"(")+1);
123 std::string elem = value.substr(0,value.find(
","));
124 field.setX(ParseUnit(elem,
"V/cm"));
125 value = value.substr(value.find(
",")+1);
126 elem = value.substr(0,value.find(
","));
127 field.setY(ParseUnit(elem,
"V/cm"));
128 value = value.substr(value.find(
",")+1);
129 elem = value.substr(0,value.find(
")"));
130 field.setZ(ParseUnit(elem,
"V/cm"));
135 G4ThreeVector field(0,0,0);
136 value = value.substr(value.find(
"(")+1);
137 std::string elem = value.substr(0,value.find(
","));
138 field.setX(ParseUnit(elem,
"tesla"));
139 value = value.substr(value.find(
",")+1);
140 elem = value.substr(0,value.find(
","));
141 field.setY(ParseUnit(elem,
"tesla"));
142 value = value.substr(value.find(
",")+1);
143 elem = value.substr(0,value.find(
")"));
144 field.setZ(ParseUnit(elem,
"tesla"));
161 G4Color
color(0.5,0.5,0.5,0.5);
163 = aux->second.begin();
164 auxItem != aux->second.end();
166 if (auxItem->type ==
"Color") {
169 <<
" color to " << auxItem->value);
171 if (G4Color::GetColour(auxItem->value,tmp)) {
172 color = G4Color(tmp.GetRed(),
178 color = ParseColor(auxItem->value);
181 if (auxItem->type ==
"Opacity") {
184 <<
" opacity to " << auxItem->value);
185 double opacity = ParseFloat(auxItem->value);
186 color = G4Color(color.GetRed(),
193 aux->first->SetVisAttributes(
new G4VisAttributes(color));
202 = aux->second.begin();
203 auxItem != aux->second.end();
205 if (auxItem->type ==
"StepLimit") {
206 double stepLimit = ParseUnit(auxItem->value,
"mm");
207 EDepSimLog(
"Set volume " << aux->first->GetName()
208 <<
" step limit to " << stepLimit
209 <<
" from " << auxItem->value);
210 aux->first->SetUserLimits(
new G4UserLimits(stepLimit));
218 EDepSimLog(
"Try to construct a custom geometry");
232 G4VPersistencyManager *pMan
233 = G4VPersistencyManager::GetPersistencyManager();
252 auxItem != aux->second.end();
254 if (auxItem->type !=
"SensDet")
continue;
256 bool exclude =
false;
260 if (logName.find((*
e)) != std::string::npos) {
266 EDepSimLog(
"Volume " << logName <<
"marked as sensitive, but" 269 EDepSimLog(
"Collect energy deposition for " << aux->first->GetName()
270 <<
" in " << auxItem->value);
272 aux->first->SetSensitiveDetector(factory.MakeSD(auxItem->value));
279 std::queue<G4LogicalVolume*> remainingVolumes;
281 while (!remainingVolumes.empty()) {
284 G4LogicalVolume* logVolume = remainingVolumes.front();
285 remainingVolumes.pop();
286 for (std::size_t i = 0; i<logVolume->GetNoDaughters(); ++i) {
287 G4VPhysicalVolume* daughter = logVolume->GetDaughter(i);
288 remainingVolumes.push(daughter->GetLogicalVolume());
295 if (aux ==
fGDMLParser->GetAuxMap()->end())
continue;
299 const G4GDMLAuxListType& auxItems = aux->second;
302 bool HasEField =
false;
304 G4ThreeVector eField(0,0,0);
306 auxItem != auxItems.end();
308 if (auxItem->type !=
"EField" && auxItem->type !=
"ArbEField") {
312 if (auxItem->type ==
"EField") {
313 eField = ParseEField(auxItem->value);
317 << logVolume->GetName()
319 <<
" X=" << eField.x()/(
volt/
cm) <<
" V/cm" 320 <<
", Y=" << eField.y()/(
volt/
cm) <<
" V/cm" 321 <<
", Z=" << eField.z()/(
volt/
cm) <<
" V/cm");
324 if (auxItem->type ==
"ArbEField") {
325 eField_fname = auxItem->value;
329 << logVolume->GetName()
330 <<
" to " << eField_fname);
335 bool HasBField =
false;
337 G4ThreeVector bField(0,0,0);
339 auxItem != auxItems.end();
341 if (auxItem->type !=
"BField" && auxItem->type !=
"ArbBField") {
345 if (auxItem->type ==
"BField") {
346 bField = ParseBField(auxItem->value);
350 << logVolume->GetName()
352 <<
" X=" << bField.x()/(
tesla) <<
" T" 353 <<
", Y=" << bField.y()/(
tesla) <<
" T" 354 <<
", Z=" << bField.z()/(
tesla) <<
" T");
357 if (auxItem->type ==
"ArbBField") {
358 bField_fname = auxItem->value;
362 << logVolume->GetName()
363 <<
" to " << bField_fname);
369 if (!HasEField && !HasBField)
continue;
373 if (eField.mag() < 0.01 *
volt/
cm) {
374 eField.setY(0.01 *
volt/
cm);
379 G4FieldManager* manager =
new G4FieldManager();
382 if (!eField_fname.empty()) {
396 if (!bField_fname.empty()) {
414 throw std::runtime_error(
"Field not created");
416 logVolume->SetFieldManager(manager,
true);
423 G4String
name, symbol;
424 G4double temperature, pressure;
426 G4double fractionmass;
428 G4NistManager* nistMan = G4NistManager::Instance();
430 G4Element* elH = nistMan->FindOrBuildElement(1);
432 G4Element* elB = nistMan->FindOrBuildElement(5);
434 G4Element* elC = nistMan->FindOrBuildElement(6);
436 G4Element* elN = nistMan->FindOrBuildElement(7);
438 G4Element* elO = nistMan->FindOrBuildElement(8);
442 G4Element* elNa = nistMan->FindOrBuildElement(11);
446 G4Element* elSi = nistMan->FindOrBuildElement(14);
450 G4Element* elAr = nistMan->FindOrBuildElement(18);
454 G4Element* elFe = nistMan->FindOrBuildElement(26);
456 G4Element* elCo = nistMan->FindOrBuildElement(27);
458 G4Element* elCu = nistMan->FindOrBuildElement(29);
468 =
new G4Material(name=
"Air",
484 =
new G4Material(name=
"Earth",
490 earth->AddElement(elSi, natoms=1);
491 earth->AddElement(elO, natoms=2);
496 =
new G4Material(name=
"Cement",
502 cement->AddElement(elSi, natoms=1);
503 cement->AddElement(elO, natoms=2);
508 G4Material* SS_304 =
new G4Material(name=
"SS_304",
520 G4Material* argon =
new G4Material(name=
"Argon_Gas",
526 argon->AddElement(elAr, natoms=1);
530 G4Material* LAr =
new G4Material(name=
"Argon_Liquid",
536 LAr->AddElement(elAr, natoms=1);
539 G4MaterialPropertiesTable *LArMatProps =
new G4MaterialPropertiesTable();
541 LArMatProps->AddConstProperty(
"TOTALNUM_INT_SITES",-1);
542 LAr->SetMaterialPropertiesTable(LArMatProps);
547 G4Material *wire =
new G4Material(name=
"Captain_Wire",
553 wire->AddElement(elCu, natoms=1);
558 =
new G4Material(name=
"Glass",
569 =
new G4Material(name=
"G10",
583 =
new G4Material(name=
"FR4",
597 G4Material* fr4Copper
598 =
new G4Material(name=
"FR4_Copper",
602 double fr4Frac = 1.0 - cuFrac;
609 fr4Copper->AddElement(elCu,cuFrac);
615 =
new G4Material(name=
"Acrylic",
624 EDepSimLog(*(G4Material::GetMaterialTable()));
632 static G4StableIsotopes theDefaultIsotopes;
635 G4int ncomponents = theDefaultIsotopes.GetNumberOfIsotopes(Z);
636 G4Element* el =
new G4Element(name, symbol, ncomponents);
637 G4int first = theDefaultIsotopes.GetFirstIsotope(Z);
638 for (G4int i=0; i<ncomponents; i++) {
639 G4int
A = theDefaultIsotopes.GetIsotopeNucleonCount(first+i);
640 std::ostringstream os; os << symbol <<
A;
641 G4Isotope* is =
new G4Isotope(name=os.str(),
Z,
A,
643 G4double abundance = theDefaultIsotopes.GetAbundance(first+i);
656 G4RegionStore::GetInstance()->FindOrCreateRegion(
"hallRegion");
665 G4VPhysicalVolume* physWorld
666 =
new G4PVPlacement(0,
679 G4RunManager::GetRunManager()->Initialize();
static constexpr double cm
#define EDepSimLog(outStream)
G4String GetName(void)
Return the base name of the object that this builds.
static constexpr double g
void Update(const G4VPhysicalVolume *aWorld, bool validate)
Update the root geometry to match the g4 geometry.
static constexpr double cm3
virtual ~UserDetectorConstruction()
UserDetectorConstruction()
static constexpr double kg
bool fValidateGeometry
Apply Validation.
#define EDepSimThrow(message)
Print an error message, and then throw an exception.
#define EDepSimInfo(outStream)
virtual G4LogicalVolume * GetPiece(void)=0
static constexpr double mg
virtual void ConstructSDandField()
virtual G4VPhysicalVolume * Construct()
void SetBField(G4Field *bfield_in)
EDepSim::Builder * fWorldBuilder
A constructor to create the world.
void SetEField(G4Field *efield_in)
G4Element * DefineElement(G4String name, G4String symbol, G4double z)
Define the natural isotope abundance.
bool ReadFile(const std::string &fname)
G4VPhysicalVolume * fPhysicalWorld
The constructed world volume.
volt_as<> volt
Type of potential stored in volts, in double precision.
EDepSim::DetectorMessenger * fDetectorMessenger
A messenger to for the DetectorConstruction object.
static constexpr double m3
void SetDrawAtt(G4Material *material, int color, double opacity=1.0)
Set material color.
std::size_t color(std::string const &procname)
G4VPhysicalVolume * ConstructDetector()
void DefineMaterials(void)
Define the materials used in the detector.
#define EDepSimError(outStream)
G4GDMLParser * fGDMLParser
A GDML Parser if one has been defined.
bool ReadFile(const std::string &fname)
std::vector< std::string > fExcludeAsSensitiveDetector
Vector of logical volumes to exclude being sensitive detectors.
static EDepSim::RootGeometryManager * Get(void)
If a persistency manager has not been created, create one.
G4Material * fDefaultMaterial
The default material.