31#include "G4AutoDelete.hh"
34#include "G4GeometryManager.hh"
35#include "G4GlobalMagFieldMessenger.hh"
36#include "G4LogicalVolume.hh"
37#include "G4LogicalVolumeStore.hh"
38#include "G4Material.hh"
39#include "G4NistManager.hh"
40#include "G4PVPlacement.hh"
41#include "G4PVReplica.hh"
42#include "G4PhysicalConstants.hh"
43#include "G4PhysicalVolumeStore.hh"
44#include "G4RunManager.hh"
45#include "G4SolidStore.hh"
46#include "G4SystemOfUnits.hh"
48#include "G4VisAttributes.hh"
55 : G4VUserDetectorConstruction() {
62 delete fGarfieldMessenger;
72 return DefineVolumes();
77void GarfieldDetectorConstruction::DefineMaterials() {
78 G4bool isotopes =
false;
79 G4String name, symbol;
80 G4int ncomponents, natoms;
81 G4double density, fractionmass;
84 G4NistManager* nistManager = G4NistManager::Instance();
86 nistManager->FindOrBuildMaterial(
"G4_Pb");
87 nistManager->FindOrBuildMaterial(
"G4_Cu");
88 nistManager->FindOrBuildMaterial(
"G4_Al");
89 nistManager->FindOrBuildMaterial(
"G4_Au");
90 nistManager->FindOrBuildMaterial(
"G4_W");
92 nistManager->FindOrBuildMaterial(
"G4_AIR");
94 G4Element* H = nistManager->FindOrBuildElement(
"H", isotopes);
95 G4Element* N = nistManager->FindOrBuildElement(
"N", isotopes);
96 G4Element* C = nistManager->FindOrBuildElement(
"C", isotopes);
97 G4Element* O = nistManager->FindOrBuildElement(
"O", isotopes);
98 G4Element* Ar = nistManager->FindOrBuildElement(
"Ar", isotopes);
100 G4Material* CO2 =
new G4Material(
101 "CO2", density = 1.977 * CLHEP::mg / CLHEP::cm3, ncomponents = 2);
102 CO2->AddElement(C, natoms = 1);
103 CO2->AddElement(O, natoms = 2);
105 G4Material* ArCO2_70_30 =
106 new G4Material(
"ArCO2_70_30", density = 1.8223 * CLHEP::mg / CLHEP::cm3,
107 ncomponents = 2, kStateGas);
108 ArCO2_70_30->AddElement(Ar, fractionmass = 0.70);
109 ArCO2_70_30->AddMaterial(CO2, fractionmass = 0.30);
111 density = 1.413 * CLHEP::g / CLHEP::cm3;
113 new G4Material(name =
"Kapton", density, ncomponents = 4);
114 Kapton->AddElement(O, 5);
115 Kapton->AddElement(C, 22);
116 Kapton->AddElement(N, 2);
117 Kapton->AddElement(H, 10);
120 G4cout << *(G4Material::GetMaterialTable()) << G4endl;
125G4VPhysicalVolume* GarfieldDetectorConstruction::DefineVolumes() {
127 G4double worldSizeXYZ = 1000 * mm;
128 G4double absorberThicknessZ = 10. * mm;
129 G4double absorberThicknessXY = 100. * mm;
130 G4double wireRadius = 0.025 * mm;
131 G4double tubeRadius = 15 * mm;
132 G4double tubeHalfLength = 100 * mm;
133 G4double tubeThickness = 500 * um;
136 G4Material* defaultMaterial = G4Material::GetMaterial(
"G4_AIR");
137 fAbsorberMaterial = G4Material::GetMaterial(
"G4_Pb");
139 G4Material* gasMaterial = G4Material::GetMaterial(
"ArCO2_70_30");
140 G4Material* cathodeMaterial = G4Material::GetMaterial(
"G4_Al");
141 G4Material* wireMaterial = G4Material::GetMaterial(
"G4_W");
143 if (!defaultMaterial || !fAbsorberMaterial || !gasMaterial ||
144 !cathodeMaterial || !wireMaterial) {
145 G4ExceptionDescription msg;
146 msg <<
"Cannot retrieve materials already defined.";
147 G4Exception(
"GarfieldDetectorConstruction::DefineVolumes()",
148 "exampleGarfield", FatalException, msg);
154 G4VSolid* worldS =
new G4Box(
"World",
155 0.5 * worldSizeXYZ, 0.5 * worldSizeXYZ,
158 G4LogicalVolume* worldLV =
159 new G4LogicalVolume(worldS,
163 G4VPhysicalVolume* worldPV =
175 G4VSolid* absorberS =
176 new G4Box(
"Absorber",
177 0.5 * absorberThicknessXY, 0.5 * absorberThicknessXY,
178 0.5 * absorberThicknessZ);
180 fAbsorberLV =
new G4LogicalVolume(absorberS,
184 fAbsorberPV =
new G4PVPlacement(
186 G4ThreeVector(0., 0., absorberThicknessZ / 2),
197 G4VSolid* tubeS =
new G4Tubs(
"Tube",
198 0, tubeRadius, tubeHalfLength + tubeThickness, 0,
201 G4LogicalVolume* tubeLV =
202 new G4LogicalVolume(tubeS,
206 G4RotationMatrix* rotY =
new G4RotationMatrix();
207 rotY->rotateY(90. * CLHEP::degree);
209 fTubePV =
new G4PVPlacement(
211 G4ThreeVector(0., -0.2 * tubeRadius,
212 absorberThicknessZ + tubeRadius),
223 G4VSolid* gasS =
new G4Tubs(
"Gas",
224 wireRadius, tubeRadius - tubeThickness,
225 tubeHalfLength, 0, 2 * pi);
227 G4LogicalVolume* gasLV =
new G4LogicalVolume(gasS,
231 fGasPV =
new G4PVPlacement(0,
232 G4ThreeVector(0., 0., 0.),
245 0, wireRadius, tubeHalfLength, 0, 2 * pi);
247 G4LogicalVolume* wireLV =
new G4LogicalVolume(wireS,
251 fWirePV =
new G4PVPlacement(0,
252 G4ThreeVector(0., 0., 0.),
263 worldLV->SetVisAttributes(G4VisAttributes::GetInvisible());
265 G4VisAttributes* VisAttBlue =
new G4VisAttributes(G4Colour(0.0, 0.0, 1.0));
266 G4VisAttributes* VisAttGreen =
new G4VisAttributes(G4Colour(0.0, 1.0, 0.0));
267 G4VisAttributes* VisAttRed =
new G4VisAttributes(G4Colour(1.0, 0.0, 0.0));
268 G4VisAttributes* VisAttWhite =
new G4VisAttributes(G4Colour(1.0, 1.0, 1.0));
270 wireLV->SetVisAttributes(VisAttRed);
271 tubeLV->SetVisAttributes(VisAttGreen);
272 gasLV->SetVisAttributes(VisAttWhite);
273 fAbsorberLV->SetVisAttributes(VisAttBlue);
275 G4Region* regionGarfield =
new G4Region(
"RegionGarfield");
276 regionGarfield->AddRootLogicalVolume(gasLV);
278 G4Region* regionWire =
new G4Region(
"RegionWire");
279 regionWire->AddRootLogicalVolume(wireLV);
281 fGarfieldG4FastSimulationModel =
new GarfieldG4FastSimulationModel(
282 "GarfieldG4FastSimulationModel", regionGarfield);
284 fGarfieldG4FastSimulationModel->WriteGeometryToGDML(fGasPV);
295 G4String name, G4String symbol, G4double density, G4int Z, G4int A) {
299 G4double abundance, massfraction;
301 G4Isotope* isotope =
new G4Isotope(symbol, Z, A);
303 G4Element* element =
new G4Element(name, symbol, ncomponents = 1);
304 element->AddIsotope(isotope, abundance = 100. * perCent);
306 G4Material* material =
new G4Material(name, density, ncomponents = 1);
307 material->AddElement(element, massfraction = 100. * perCent);
315 G4String materialChoice) {
317 G4Material* newMaterial =
318 G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
321 if (fAbsorberMaterial != newMaterial) {
322 fAbsorberMaterial = newMaterial;
324 fAbsorberLV->SetMaterial(fAbsorberMaterial);
326 G4RunManager::GetRunManager()->PhysicsHasBeenModified();
329 G4cout <<
"\n--> warning from GarfieldDetectorConstruction::SetMaterial : "
330 << materialChoice <<
" not found" << G4endl;
Definition of the GarfieldDetectorConstruction class.
Definition of the GarfieldMessenger class.
GarfieldDetectorConstruction()
void SetAbsorberMaterial(G4String materialChoice)
G4Material * AbsorberMaterialWithSingleIsotope(G4String name, G4String symbol, G4double density, G4int Z, G4int A)
virtual ~GarfieldDetectorConstruction()
virtual G4VPhysicalVolume * Construct() override