source: trunk/examples/extended/electromagnetic/TestEm5/src/DetectorConstruction.cc@ 1036

Last change on this file since 1036 was 807, checked in by garnier, 17 years ago

update

File size: 14.8 KB
RevLine 
[807]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// $Id: DetectorConstruction.cc,v 1.13 2006/09/25 17:06:29 maire Exp $
27// GEANT4 tag $Name: geant4-09-01-patch-02 $
28//
29//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
30//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
31
32#include "DetectorConstruction.hh"
33#include "DetectorMessenger.hh"
34
35#include "G4Material.hh"
36#include "G4Box.hh"
37#include "G4LogicalVolume.hh"
38#include "G4PVPlacement.hh"
39#include "G4UniformMagField.hh"
40
41#include "G4GeometryManager.hh"
42#include "G4PhysicalVolumeStore.hh"
43#include "G4LogicalVolumeStore.hh"
44#include "G4SolidStore.hh"
45
46#include "G4UnitsTable.hh"
47#include "G4NistManager.hh"
48
49//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
50
51DetectorConstruction::DetectorConstruction()
52:AbsorberMaterial(0),WorldMaterial(0),defaultWorld(true),
53 solidWorld(0),logicWorld(0),physiWorld(0),
54 solidAbsorber(0),logicAbsorber(0),physiAbsorber(0),
55 magField(0)
56{
57 // default parameter values of the calorimeter
58 AbsorberThickness = 1.*cm;
59 AbsorberSizeYZ = 2.*cm;
60 XposAbs = 0.*cm;
61 ComputeCalorParameters();
62
63 // materials
64 DefineMaterials();
65 SetWorldMaterial ("Galactic");
66 SetAbsorberMaterial("Silicon");
67
68 // create commands for interactive definition of the calorimeter
69 detectorMessenger = new DetectorMessenger(this);
70}
71
72//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
73
74DetectorConstruction::~DetectorConstruction()
75{
76 delete detectorMessenger;
77}
78
79//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
80
81G4VPhysicalVolume* DetectorConstruction::Construct()
82{
83 return ConstructCalorimeter();
84}
85
86//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
87
88void DetectorConstruction::DefineMaterials()
89{
90 //This function illustrates the possible ways to define materials
91
92G4String symbol; //a=mass of a mole;
93G4double a, z, density; //z=mean number of protons;
94
95G4int ncomponents, natoms;
96G4double fractionmass;
97G4double temperature, pressure;
98
99//
100// define Elements
101//
102
103G4Element* H = new G4Element("Hydrogen",symbol="H", z= 1, a= 1.01*g/mole);
104G4Element* C = new G4Element("Carbon", symbol="C", z= 6, a= 12.01*g/mole);
105G4Element* N = new G4Element("Nitrogen",symbol="N", z= 7, a= 14.01*g/mole);
106G4Element* O = new G4Element("Oxygen", symbol="O", z= 8, a= 16.00*g/mole);
107G4Element* Na = new G4Element("Sodium", symbol="Na", z=11, a= 22.99*g/mole);
108G4Element* Ar = new G4Element("Argon", symbol="Ar", z=18, a= 39.95*g/mole);
109G4Element* I = new G4Element("Iodine", symbol="I" , z=53, a= 126.90*g/mole);
110G4Element* Xe = new G4Element("Xenon", symbol="Xe", z=54, a= 131.29*g/mole);
111
112//
113// define simple materials
114//
115
116new G4Material("H2Liq" , z= 1, a= 1.01*g/mole, density= 70.8*mg/cm3);
117new G4Material("Beryllium", z= 4, a= 9.01*g/mole, density= 1.848*g/cm3);
118new G4Material("Aluminium", z=13, a=26.98*g/mole, density= 2.700*g/cm3);
119new G4Material("Silicon" , z=14, a=28.09*g/mole, density= 2.330*g/cm3);
120
121G4Material* lAr =
122new G4Material("liquidArgon", density= 1.390*g/cm3, ncomponents=1);
123lAr->AddElement(Ar, natoms=1);
124
125new G4Material("Iron", z=26, a= 55.85*g/mole, density= 7.870*g/cm3);
126new G4Material("Copper", z=29, a= 63.55*g/mole, density= 8.960*g/cm3);
127new G4Material("Silver", z=47, a=107.87*g/mole, density= 10.50*g/cm3);
128new G4Material("Tungsten", z=74, a=183.85*g/mole, density= 19.30*g/cm3);
129new G4Material("Gold", z=79, a=196.97*g/mole, density= 19.32*g/cm3);
130new G4Material("Lead", z=82, a=207.19*g/mole, density= 11.35*g/cm3);
131
132//
133// define a material from elements. case 1: chemical molecule
134//
135
136G4Material* H2O = new G4Material("Water", density= 1.000*g/cm3, ncomponents=2);
137H2O->AddElement(H, natoms=2);
138H2O->AddElement(O, natoms=1);
139H2O->GetIonisation()->SetMeanExcitationEnergy(75*eV);
140
141G4Material* CH = new G4Material("Plastic", density= 1.04*g/cm3, ncomponents=2);
142CH->AddElement(C, natoms=1);
143CH->AddElement(H, natoms=1);
144
145G4Material* NaI = new G4Material("NaI", density= 3.67*g/cm3, ncomponents=2);
146NaI->AddElement(Na, natoms=1);
147NaI->AddElement(I , natoms=1);
148NaI->GetIonisation()->SetMeanExcitationEnergy(452*eV);
149
150//
151// define a material from elements. case 2: mixture by fractional mass
152//
153
154G4Material* Air = new G4Material("Air", density= 1.290*mg/cm3, ncomponents=2);
155Air->AddElement(N, fractionmass=0.7);
156Air->AddElement(O, fractionmass=0.3);
157
158G4Material* Air20 =
159new G4Material("Air20", density= 1.205*mg/cm3, ncomponents=2,
160 kStateGas, 293.*kelvin, 1.*atmosphere);
161Air20->AddElement(N, fractionmass=0.7);
162Air20->AddElement(O, fractionmass=0.3);
163
164//Graphite
165//
166G4Material* Graphite =
167new G4Material("Graphite", density= 1.7*g/cm3, ncomponents=1);
168Graphite->AddElement(C, fractionmass=1.);
169
170//Havar
171//
172G4Element* Cr = new G4Element("Chrome", "Cr", z=25, a= 51.996*g/mole);
173G4Element* Fe = new G4Element("Iron" , "Fe", z=26, a= 55.845*g/mole);
174G4Element* Co = new G4Element("Cobalt", "Co", z=27, a= 58.933*g/mole);
175G4Element* Ni = new G4Element("Nickel", "Ni", z=28, a= 58.693*g/mole);
176G4Element* W = new G4Element("Tungsten","W", z=74, a= 183.850*g/mole);
177
178G4Material* Havar =
179new G4Material("Havar", density= 8.3*g/cm3, ncomponents=5);
180Havar->AddElement(Cr, fractionmass=0.1785);
181Havar->AddElement(Fe, fractionmass=0.1822);
182Havar->AddElement(Co, fractionmass=0.4452);
183Havar->AddElement(Ni, fractionmass=0.1310);
184Havar->AddElement(W , fractionmass=0.0631);
185
186//
187// examples of gas
188//
189new G4Material("ArgonGas", z=18, a=39.948*g/mole, density= 1.782*mg/cm3,
190 kStateGas, 273.15*kelvin, 1*atmosphere);
191
192new G4Material("XenonGas", z=54, a=131.29*g/mole, density= 5.458*mg/cm3,
193 kStateGas, 293.15*kelvin, 1*atmosphere);
194
195G4Material* CO2 =
196new G4Material("CarbonicGas", density= 1.977*mg/cm3, ncomponents=2);
197CO2->AddElement(C, natoms=1);
198CO2->AddElement(O, natoms=2);
199
200G4Material* ArCO2 =
201new G4Material("ArgonCO2", density= 1.8223*mg/cm3, ncomponents=2);
202ArCO2->AddElement (Ar, fractionmass=0.7844);
203ArCO2->AddMaterial(CO2, fractionmass=0.2156);
204
205//another way to define mixture of gas per volume
206G4Material* NewArCO2 =
207new G4Material("NewArgonCO2", density= 1.8223*mg/cm3, ncomponents=3);
208NewArCO2->AddElement (Ar, natoms=8);
209NewArCO2->AddElement (C, natoms=2);
210NewArCO2->AddElement (O, natoms=4);
211
212G4Material* ArCH4 =
213new G4Material("ArgonCH4", density= 1.709*mg/cm3, ncomponents=3);
214ArCH4->AddElement (Ar, natoms=93);
215ArCH4->AddElement (C, natoms=7);
216ArCH4->AddElement (H, natoms=28);
217
218G4Material* XeCH =
219new G4Material("XenonMethanePropane", density= 4.9196*mg/cm3, ncomponents=3,
220 kStateGas, 293.15*kelvin, 1*atmosphere);
221XeCH->AddElement (Xe, natoms=875);
222XeCH->AddElement (C, natoms=225);
223XeCH->AddElement (H, natoms=700);
224
225G4Material* steam =
226new G4Material("WaterSteam", density= 1.0*mg/cm3, ncomponents=1);
227steam->AddMaterial(H2O, fractionmass=1.);
228steam->GetIonisation()->SetMeanExcitationEnergy(71.6*eV);
229
230//
231// example of vacuum
232//
233
234density = universe_mean_density; //from PhysicalConstants.h
235pressure = 3.e-18*pascal;
236temperature = 2.73*kelvin;
237new G4Material("Galactic", z=1, a=1.01*g/mole,density,
238 kStateGas,temperature,pressure);
239}
240
241//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
242
243void DetectorConstruction::ComputeCalorParameters()
244{
245 // Compute derived parameters of the calorimeter
246 xstartAbs = XposAbs-0.5*AbsorberThickness;
247 xendAbs = XposAbs+0.5*AbsorberThickness;
248
249 if (defaultWorld) {
250 WorldSizeX = 1.5*AbsorberThickness; WorldSizeYZ= 1.2*AbsorberSizeYZ;
251 }
252}
253
254//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
255
256G4VPhysicalVolume* DetectorConstruction::ConstructCalorimeter()
257{
258 // Cleanup old geometry
259 //
260 G4GeometryManager::GetInstance()->OpenGeometry();
261 G4PhysicalVolumeStore::GetInstance()->Clean();
262 G4LogicalVolumeStore::GetInstance()->Clean();
263 G4SolidStore::GetInstance()->Clean();
264
265 // complete the Calor parameters definition
266 ComputeCalorParameters();
267
268 // World
269 //
270 solidWorld = new G4Box("World", //its name
271 WorldSizeX/2,WorldSizeYZ/2,WorldSizeYZ/2); //its size
272
273 logicWorld = new G4LogicalVolume(solidWorld, //its solid
274 WorldMaterial, //its material
275 "World"); //its name
276
277 physiWorld = new G4PVPlacement(0, //no rotation
278 G4ThreeVector(), //at (0,0,0)
279 logicWorld, //its logical volume
280 "World", //its name
281 0, //its mother volume
282 false, //no boolean operation
283 0); //copy number
284
285 // Absorber
286 //
287 solidAbsorber = new G4Box("Absorber",
288 AbsorberThickness/2,AbsorberSizeYZ/2,AbsorberSizeYZ/2);
289
290 logicAbsorber = new G4LogicalVolume(solidAbsorber, //its solid
291 AbsorberMaterial, //its material
292 "Absorber"); //its name
293
294 physiAbsorber = new G4PVPlacement(0, //no rotation
295 G4ThreeVector(XposAbs,0.,0.), //its position
296 logicAbsorber, //its logical volume
297 "Absorber", //its name
298 logicWorld, //its mother
299 false, //no boulean operat
300 0); //copy number
301
302 PrintCalorParameters();
303
304 //always return the physical World
305 //
306 return physiWorld;
307}
308
309//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
310
311void DetectorConstruction::PrintCalorParameters()
312{
313 G4cout << "\n" << WorldMaterial << G4endl;
314 G4cout << "\n" << AbsorberMaterial << G4endl;
315
316 G4cout << "\n The WORLD is made of " << G4BestUnit(WorldSizeX,"Length")
317 << " of " << WorldMaterial->GetName();
318 G4cout << ". The transverse size (YZ) of the world is "
319 << G4BestUnit(WorldSizeYZ,"Length") << G4endl;
320 G4cout << " The ABSORBER is made of "
321 <<G4BestUnit(AbsorberThickness,"Length")
322 << " of " << AbsorberMaterial->GetName();
323 G4cout << ". The transverse size (YZ) is "
324 << G4BestUnit(AbsorberSizeYZ,"Length") << G4endl;
325 G4cout << " X position of the middle of the absorber "
326 << G4BestUnit(XposAbs,"Length");
327 G4cout << G4endl;
328}
329
330//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
331
332void DetectorConstruction::SetAbsorberMaterial(G4String materialChoice)
333{
334 // search the material by its name
335 G4Material* pttoMaterial =
336 G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
337
338 if (pttoMaterial) AbsorberMaterial = pttoMaterial;
339}
340
341//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
342
343void DetectorConstruction::SetWorldMaterial(G4String materialChoice)
344{
345 // search the material by its name
346 G4Material* pttoMaterial =
347 G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
348
349 if (pttoMaterial) WorldMaterial = pttoMaterial;
350}
351
352//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
353
354void DetectorConstruction::SetAbsorberThickness(G4double val)
355{
356 AbsorberThickness = val;
357}
358
359//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
360
361void DetectorConstruction::SetAbsorberSizeYZ(G4double val)
362{
363 AbsorberSizeYZ = val;
364}
365
366//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
367
368void DetectorConstruction::SetWorldSizeX(G4double val)
369{
370 WorldSizeX = val;
371 defaultWorld = false;
372}
373
374//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
375
376void DetectorConstruction::SetWorldSizeYZ(G4double val)
377{
378 WorldSizeYZ = val;
379 defaultWorld = false;
380}
381
382//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
383
384void DetectorConstruction::SetAbsorberXpos(G4double val)
385{
386 XposAbs = val;
387}
388
389//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
390
391#include "G4FieldManager.hh"
392#include "G4TransportationManager.hh"
393
394void DetectorConstruction::SetMagField(G4double fieldValue)
395{
396 //apply a global uniform magnetic field along Z axis
397 G4FieldManager* fieldMgr
398 = G4TransportationManager::GetTransportationManager()->GetFieldManager();
399
400 if(magField) delete magField; //delete the existing magn field
401
402 if(fieldValue!=0.) // create a new one if non nul
403 { magField = new G4UniformMagField(G4ThreeVector(0.,0.,fieldValue));
404 fieldMgr->SetDetectorField(magField);
405 fieldMgr->CreateChordFinder(magField);
406 } else {
407 magField = NULL;
408 fieldMgr->SetDetectorField(magField);
409 }
410}
411
412//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
413
414#include "G4RunManager.hh"
415
416void DetectorConstruction::UpdateGeometry()
417{
418 G4RunManager::GetRunManager()->DefineWorldVolume(ConstructCalorimeter());
419}
420
421//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
422
Note: See TracBrowser for help on using the repository browser.