Garfield++ 5.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
GarfieldDetectorConstruction.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26/// \file GarfieldDetectorConstruction.cc
27/// \brief Implementation of the GarfieldDetectorConstruction class
28
30
31#include "G4AutoDelete.hh"
32#include "G4Box.hh"
33#include "G4Colour.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"
47#include "G4Tubs.hh"
48#include "G4VisAttributes.hh"
50#include "GarfieldMessenger.hh"
51
52//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
53
55 : G4VUserDetectorConstruction() {
56 fGarfieldMessenger = new GarfieldMessenger(this);
57}
58
59//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
60
64
65//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
66
68 // Define materials
69 DefineMaterials();
70
71 // Define volumes
72 return DefineVolumes();
73}
74
75//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
76
77void GarfieldDetectorConstruction::DefineMaterials() {
78 G4bool isotopes = false;
79 G4String name, symbol;
80 G4int ncomponents, natoms;
81 G4double density, fractionmass;
82
83 // Lead material defined using NIST Manager
84 G4NistManager* nistManager = G4NistManager::Instance();
85
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");
91
92 nistManager->FindOrBuildMaterial("G4_AIR");
93
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);
99
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);
104
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);
110
111 density = 1.413 * CLHEP::g / CLHEP::cm3;
112 G4Material* Kapton =
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);
118
119 // Print materials
120 G4cout << *(G4Material::GetMaterialTable()) << G4endl;
121}
122
123//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
124
125G4VPhysicalVolume* GarfieldDetectorConstruction::DefineVolumes() {
126 // Geometry parameters
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;
134
135 // Get materials
136 G4Material* defaultMaterial = G4Material::GetMaterial("G4_AIR");
137 fAbsorberMaterial = G4Material::GetMaterial("G4_Pb");
138
139 G4Material* gasMaterial = G4Material::GetMaterial("ArCO2_70_30");
140 G4Material* cathodeMaterial = G4Material::GetMaterial("G4_Al");
141 G4Material* wireMaterial = G4Material::GetMaterial("G4_W");
142
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);
149 }
150
151 //
152 // World
153 //
154 G4VSolid* worldS = new G4Box("World", // its name
155 0.5 * worldSizeXYZ, 0.5 * worldSizeXYZ,
156 0.5 * worldSizeXYZ); // its size
157
158 G4LogicalVolume* worldLV =
159 new G4LogicalVolume(worldS, // its solid
160 defaultMaterial, // its material
161 "World"); // its name
162
163 G4VPhysicalVolume* worldPV =
164 new G4PVPlacement(0, // no rotation
165 G4ThreeVector(), // at (0,0,0)
166 worldLV, // its logical volume
167 "World", // its name
168 0, // its mother volume
169 false, // no boolean operation
170 0, // copy number
171 fCheckOverlaps); // checking overlaps
172 //
173 // Absorber
174 //
175 G4VSolid* absorberS =
176 new G4Box("Absorber", // its name
177 0.5 * absorberThicknessXY, 0.5 * absorberThicknessXY,
178 0.5 * absorberThicknessZ); // its size
179
180 fAbsorberLV = new G4LogicalVolume(absorberS, // its solid
181 fAbsorberMaterial, // its material
182 "Absorber"); // its name
183
184 fAbsorberPV = new G4PVPlacement(
185 0, // no rotation
186 G4ThreeVector(0., 0., absorberThicknessZ / 2), // its position
187 fAbsorberLV, // its logical volume
188 "Absorber", // its name
189 worldLV, // its mother volume
190 false, // no boolean operation
191 0, // copy number
192 fCheckOverlaps); // checking overlaps
193
194 //
195 // Drift tube
196 //
197 G4VSolid* tubeS = new G4Tubs("Tube", // its name
198 0, tubeRadius, tubeHalfLength + tubeThickness, 0,
199 2 * pi); // its size
200
201 G4LogicalVolume* tubeLV =
202 new G4LogicalVolume(tubeS, // its solid
203 cathodeMaterial, // its material
204 "Tube"); // its name
205
206 G4RotationMatrix* rotY = new G4RotationMatrix();
207 rotY->rotateY(90. * CLHEP::degree);
208
209 fTubePV = new G4PVPlacement(
210 rotY,
211 G4ThreeVector(0., -0.2 * tubeRadius,
212 absorberThicknessZ + tubeRadius), // its position
213 tubeLV, // its logical volume
214 "Tube", // its name
215 worldLV, // its mother volume
216 false, // no boolean operation
217 0, // copy number
218 fCheckOverlaps); // checking overlaps
219
220 //
221 // Drift Tube Gas
222 //
223 G4VSolid* gasS = new G4Tubs("Gas", // its name
224 wireRadius, tubeRadius - tubeThickness,
225 tubeHalfLength, 0, 2 * pi); // its size
226
227 G4LogicalVolume* gasLV = new G4LogicalVolume(gasS, // its solid
228 gasMaterial, // its material
229 "Gas"); // its name
230
231 fGasPV = new G4PVPlacement(0, // no rotation
232 G4ThreeVector(0., 0., 0.), // its position
233 gasLV, // its logical volume
234 "Gas", // its name
235 tubeLV, // its mother volume
236 false, // no boolean operation
237 0, // copy number
238 fCheckOverlaps); // checking overlaps
239
240 //
241 // Wire
242 //
243 G4VSolid* wireS =
244 new G4Tubs("Wire", // its name
245 0, wireRadius, tubeHalfLength, 0, 2 * pi); // its size
246
247 G4LogicalVolume* wireLV = new G4LogicalVolume(wireS, // its solid
248 wireMaterial, // its material
249 "Wire"); // its name
250
251 fWirePV = new G4PVPlacement(0, // no rotation
252 G4ThreeVector(0., 0., 0.), // its position
253 wireLV, // its logical volume
254 "Wire", // its name
255 tubeLV, // its mother volume
256 false, // no boolean operation
257 0, // copy number
258 fCheckOverlaps); // checking overlaps
259
260 //
261 // Visualization attributes
262 //
263 worldLV->SetVisAttributes(G4VisAttributes::GetInvisible());
264
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));
269
270 wireLV->SetVisAttributes(VisAttRed);
271 tubeLV->SetVisAttributes(VisAttGreen);
272 gasLV->SetVisAttributes(VisAttWhite);
273 fAbsorberLV->SetVisAttributes(VisAttBlue);
274
275 G4Region* regionGarfield = new G4Region("RegionGarfield");
276 regionGarfield->AddRootLogicalVolume(gasLV);
277
278 G4Region* regionWire = new G4Region("RegionWire");
279 regionWire->AddRootLogicalVolume(wireLV);
280
281 fGarfieldG4FastSimulationModel = new GarfieldG4FastSimulationModel(
282 "GarfieldG4FastSimulationModel", regionGarfield);
283
284 fGarfieldG4FastSimulationModel->WriteGeometryToGDML(fGasPV);
285
286 //
287 // Always return the physical World
288 //
289 return worldPV;
290}
291
292//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
293
295 G4String name, G4String symbol, G4double density, G4int Z, G4int A) {
296 // define a material from an isotope
297 //
298 G4int ncomponents;
299 G4double abundance, massfraction;
300
301 G4Isotope* isotope = new G4Isotope(symbol, Z, A);
302
303 G4Element* element = new G4Element(name, symbol, ncomponents = 1);
304 element->AddIsotope(isotope, abundance = 100. * perCent);
305
306 G4Material* material = new G4Material(name, density, ncomponents = 1);
307 material->AddElement(element, massfraction = 100. * perCent);
308
309 return material;
310}
311
312//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
313
315 G4String materialChoice) {
316 // search the material by its name
317 G4Material* newMaterial =
318 G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
319
320 if (newMaterial) {
321 if (fAbsorberMaterial != newMaterial) {
322 fAbsorberMaterial = newMaterial;
323 if (fAbsorberLV) {
324 fAbsorberLV->SetMaterial(fAbsorberMaterial);
325 }
326 G4RunManager::GetRunManager()->PhysicsHasBeenModified();
327 }
328 } else {
329 G4cout << "\n--> warning from GarfieldDetectorConstruction::SetMaterial : "
330 << materialChoice << " not found" << G4endl;
331 }
332}
333
334//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Definition of the GarfieldDetectorConstruction class.
Definition of the GarfieldMessenger class.
void SetAbsorberMaterial(G4String materialChoice)
G4Material * AbsorberMaterialWithSingleIsotope(G4String name, G4String symbol, G4double density, G4int Z, G4int A)
virtual G4VPhysicalVolume * Construct() override