Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
examples/extended/electromagnetic/TestEm5/src/DetectorConstruction.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 electromagnetic/TestEm5/src/DetectorConstruction.cc
27 /// \brief Implementation of the DetectorConstruction class
28 //
29 // $Id: DetectorConstruction.cc 77600 2013-11-26 17:07:41Z gcosmo $
30 //
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 
34 #include "DetectorConstruction.hh"
35 #include "DetectorMessenger.hh"
36 
37 #include "G4Material.hh"
38 #include "G4Box.hh"
39 #include "G4LogicalVolume.hh"
40 #include "G4PVPlacement.hh"
41 #include "G4UniformMagField.hh"
42 
43 #include "G4GeometryManager.hh"
44 #include "G4PhysicalVolumeStore.hh"
45 #include "G4LogicalVolumeStore.hh"
46 #include "G4SolidStore.hh"
47 
48 #include "G4UnitsTable.hh"
49 #include "G4NistManager.hh"
50 #include "G4RunManager.hh"
51 
52 #include "G4PhysicalConstants.hh"
53 #include "G4SystemOfUnits.hh"
54 
56 #include "G4AutoDelete.hh"
57 
58 
59 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
60 
63  fAbsorberMaterial(0),fWorldMaterial(0),fDefaultWorld(true),
64  fSolidWorld(0),fLogicWorld(0),fPhysiWorld(0),
65  fSolidAbsorber(0),fLogicAbsorber(0),fPhysiAbsorber(0),
66  fDetectorMessenger(0)
67 {
68  // default parameter values of the calorimeter
69  fAbsorberThickness = 1.*cm;
70  fAbsorberSizeYZ = 2.*cm;
71  fXposAbs = 0.*cm;
72  ComputeCalorParameters();
73 
74  // materials
75  DefineMaterials();
76  SetWorldMaterial ("Galactic");
77  SetAbsorberMaterial("Silicon");
78 
79  // create commands for interactive definition of the calorimeter
80  fDetectorMessenger = new DetectorMessenger(this);
81 }
82 
83 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
84 
86 {
87  delete fDetectorMessenger;
88 }
89 
90 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
91 
93 {
94  return ConstructCalorimeter();
95 }
96 
97 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
98 
99 void DetectorConstruction::DefineMaterials()
100 {
101  //This function illustrates the possible ways to define materials
102 
103  G4String symbol; //a=mass of a mole;
104  G4double a, z, density; //z=mean number of protons;
105 
106  G4int ncomponents, natoms;
107  G4double fractionmass;
108  G4double temperature, pressure;
109 
110  //
111  // define Elements
112  //
113 
114  G4Element* H = new G4Element("Hydrogen",symbol="H", z= 1, a= 1.01*g/mole);
115  G4Element* C = new G4Element("Carbon", symbol="C", z= 6, a= 12.01*g/mole);
116  G4Element* N = new G4Element("Nitrogen",symbol="N", z= 7, a= 14.01*g/mole);
117  G4Element* O = new G4Element("Oxygen", symbol="O", z= 8, a= 16.00*g/mole);
118  G4Element* Na = new G4Element("Sodium", symbol="Na", z=11, a= 22.99*g/mole);
119  G4Element* Ar = new G4Element("Argon", symbol="Ar", z=18, a= 39.95*g/mole);
120  G4Element* I = new G4Element("Iodine", symbol="I" , z=53, a= 126.90*g/mole);
121  G4Element* Xe = new G4Element("Xenon", symbol="Xe", z=54, a= 131.29*g/mole);
122 
123  //
124  // define simple materials
125  //
126 
127  new G4Material("H2Liq" , z= 1, a= 1.01*g/mole, density= 70.8*mg/cm3);
128  new G4Material("Beryllium", z= 4, a= 9.01*g/mole, density= 1.848*g/cm3);
129  new G4Material("Aluminium", z=13, a=26.98*g/mole, density= 2.700*g/cm3);
130  new G4Material("Silicon" , z=14, a=28.09*g/mole, density= 2.330*g/cm3);
131 
132  G4Material* lAr =
133  new G4Material("liquidArgon", density= 1.390*g/cm3, ncomponents=1);
134  lAr->AddElement(Ar, natoms=1);
135 
136  new G4Material("Iron", z=26, a= 55.85*g/mole, density= 7.870*g/cm3);
137  new G4Material("Copper", z=29, a= 63.55*g/mole, density= 8.960*g/cm3);
138  new G4Material("Germanium",z=32, a= 72.61*g/mole, density= 5.323*g/cm3);
139  new G4Material("Silver", z=47, a=107.87*g/mole, density= 10.50*g/cm3);
140  new G4Material("Tungsten", z=74, a=183.85*g/mole, density= 19.30*g/cm3);
141  new G4Material("Gold", z=79, a=196.97*g/mole, density= 19.32*g/cm3);
142  new G4Material("Lead", z=82, a=207.19*g/mole, density= 11.35*g/cm3);
143 
144  //
145  // define a material from elements. case 1: chemical molecule
146  //
147 
148  G4Material* H2O = new G4Material("Water",density= 1.000*g/cm3,ncomponents=2);
149  H2O->AddElement(H, natoms=2);
150  H2O->AddElement(O, natoms=1);
152 
153  G4Material* CH = new G4Material("Plastic",density= 1.04*g/cm3,ncomponents=2);
154  CH->AddElement(C, natoms=1);
155  CH->AddElement(H, natoms=1);
156 
157  G4Material* NaI = new G4Material("NaI", density= 3.67*g/cm3, ncomponents=2);
158  NaI->AddElement(Na, natoms=1);
159  NaI->AddElement(I , natoms=1);
161 
162  //
163  // define a material from elements. case 2: mixture by fractional mass
164  //
165 
166  G4Material* Air = new G4Material("Air", density= 1.290*mg/cm3, ncomponents=2);
167  Air->AddElement(N, fractionmass=0.7);
168  Air->AddElement(O, fractionmass=0.3);
169 
170  G4Material* Air20 =
171  new G4Material("Air20", density= 1.205*mg/cm3, ncomponents=2,
172  kStateGas, 293.*kelvin, 1.*atmosphere);
173  Air20->AddElement(N, fractionmass=0.7);
174  Air20->AddElement(O, fractionmass=0.3);
175 
176  //Graphite
177  //
178  G4Material* Graphite =
179  new G4Material("Graphite", density= 1.7*g/cm3, ncomponents=1);
180  Graphite->AddElement(C, fractionmass=1.);
181 
182  //Havar
183  //
184  G4Element* Cr = new G4Element("Chrome", "Cr", z=25, a= 51.996*g/mole);
185  G4Element* Fe = new G4Element("Iron" , "Fe", z=26, a= 55.845*g/mole);
186  G4Element* Co = new G4Element("Cobalt", "Co", z=27, a= 58.933*g/mole);
187  G4Element* Ni = new G4Element("Nickel", "Ni", z=28, a= 58.693*g/mole);
188  G4Element* W = new G4Element("Tungsten","W", z=74, a= 183.850*g/mole);
189 
190  G4Material* Havar =
191  new G4Material("Havar", density= 8.3*g/cm3, ncomponents=5);
192  Havar->AddElement(Cr, fractionmass=0.1785);
193  Havar->AddElement(Fe, fractionmass=0.1822);
194  Havar->AddElement(Co, fractionmass=0.4452);
195  Havar->AddElement(Ni, fractionmass=0.1310);
196  Havar->AddElement(W , fractionmass=0.0631);
197 
198  //
199  // examples of gas
200  //
201  new G4Material("ArgonGas", z=18, a=39.948*g/mole, density= 1.782*mg/cm3,
202  kStateGas, 273.15*kelvin, 1*atmosphere);
203 
204  new G4Material("XenonGas", z=54, a=131.29*g/mole, density= 5.458*mg/cm3,
205  kStateGas, 293.15*kelvin, 1*atmosphere);
206 
207  G4Material* CO2 =
208  new G4Material("CarbonicGas", density= 1.977*mg/cm3, ncomponents=2);
209  CO2->AddElement(C, natoms=1);
210  CO2->AddElement(O, natoms=2);
211 
212  G4Material* ArCO2 =
213  new G4Material("ArgonCO2", density= 1.8223*mg/cm3, ncomponents=2);
214  ArCO2->AddElement (Ar, fractionmass=0.7844);
215  ArCO2->AddMaterial(CO2, fractionmass=0.2156);
216 
217  //another way to define mixture of gas per volume
218  G4Material* NewArCO2 =
219  new G4Material("NewArgonCO2", density= 1.8223*mg/cm3, ncomponents=3);
220  NewArCO2->AddElement (Ar, natoms=8);
221  NewArCO2->AddElement (C, natoms=2);
222  NewArCO2->AddElement (O, natoms=4);
223 
224  G4Material* ArCH4 =
225  new G4Material("ArgonCH4", density= 1.709*mg/cm3, ncomponents=3);
226  ArCH4->AddElement (Ar, natoms=93);
227  ArCH4->AddElement (C, natoms=7);
228  ArCH4->AddElement (H, natoms=28);
229 
230  G4Material* XeCH =
231  new G4Material("XenonMethanePropane", density= 4.9196*mg/cm3, ncomponents=3,
232  kStateGas, 293.15*kelvin, 1*atmosphere);
233  XeCH->AddElement (Xe, natoms=875);
234  XeCH->AddElement (C, natoms=225);
235  XeCH->AddElement (H, natoms=700);
236 
237  G4Material* steam =
238  new G4Material("WaterSteam", density= 1.0*mg/cm3, ncomponents=1);
239  steam->AddMaterial(H2O, fractionmass=1.);
240  steam->GetIonisation()->SetMeanExcitationEnergy(71.6*eV);
241 
242  //
243  // example of vacuum
244  //
245 
246  density = universe_mean_density; //from PhysicalConstants.h
247  pressure = 3.e-18*pascal;
248  temperature = 2.73*kelvin;
249  new G4Material("Galactic", z=1, a=1.01*g/mole,density,
250  kStateGas,temperature,pressure);
251 }
252 
253 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
254 
255 void DetectorConstruction::ComputeCalorParameters()
256 {
257  // Compute derived parameters of the calorimeter
258  fXstartAbs = fXposAbs-0.5*fAbsorberThickness;
259  fXendAbs = fXposAbs+0.5*fAbsorberThickness;
260 
261  if (fDefaultWorld) {
262  fWorldSizeX = 1.5*fAbsorberThickness; fWorldSizeYZ= 1.2*fAbsorberSizeYZ;
263  }
264 }
265 
266 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
267 
268 G4VPhysicalVolume* DetectorConstruction::ConstructCalorimeter()
269 {
270  // Cleanup old geometry
271  //
276 
277  // World
278  //
279  fSolidWorld = new G4Box("World", //its name
280  fWorldSizeX/2,fWorldSizeYZ/2,fWorldSizeYZ/2); //its size
281 
282  fLogicWorld = new G4LogicalVolume(fSolidWorld, //its solid
283  fWorldMaterial, //its material
284  "World"); //its name
285 
286  fPhysiWorld = new G4PVPlacement(0, //no rotation
287  G4ThreeVector(), //at (0,0,0)
288  fLogicWorld, //its logical volume
289  "World", //its name
290  0, //its mother volume
291  false, //no boolean operation
292  0); //copy number
293 
294  // Absorber
295  //
296  fSolidAbsorber = new G4Box("Absorber",
297  fAbsorberThickness/2,fAbsorberSizeYZ/2,fAbsorberSizeYZ/2);
298 
299  fLogicAbsorber = new G4LogicalVolume(fSolidAbsorber, //its solid
300  fAbsorberMaterial, //its material
301  "Absorber"); //its name
302 
303  fPhysiAbsorber = new G4PVPlacement(0, //no rotation
304  G4ThreeVector(fXposAbs,0.,0.), //its position
305  fLogicAbsorber, //its logical volume
306  "Absorber", //its name
307  fLogicWorld, //its mother
308  false, //no boulean operat
309  0); //copy number
310 
312 
313  //always return the physical World
314  //
315  return fPhysiWorld;
316 }
317 
318 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
319 
321 {
322  G4cout << "\n" << fWorldMaterial << G4endl;
323  G4cout << "\n" << fAbsorberMaterial << G4endl;
324 
325  G4cout << "\n The WORLD is made of " << G4BestUnit(fWorldSizeX,"Length")
326  << " of " << fWorldMaterial->GetName();
327  G4cout << ". The transverse size (YZ) of the world is "
328  << G4BestUnit(fWorldSizeYZ,"Length") << G4endl;
329  G4cout << " The ABSORBER is made of "
330  <<G4BestUnit(fAbsorberThickness,"Length")
331  << " of " << fAbsorberMaterial->GetName();
332  G4cout << ". The transverse size (YZ) is "
333  << G4BestUnit(fAbsorberSizeYZ,"Length") << G4endl;
334  G4cout << " X position of the middle of the absorber "
335  << G4BestUnit(fXposAbs,"Length");
336  G4cout << G4endl;
337 }
338 
339 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
340 
342 {
343  // search the material by its name
344  G4Material* pttoMaterial =
345  G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
346 
347  if (pttoMaterial && fAbsorberMaterial != pttoMaterial) {
348  fAbsorberMaterial = pttoMaterial;
349  if(fLogicAbsorber) fLogicAbsorber->SetMaterial(fAbsorberMaterial);
351  }
352 }
353 
354 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
355 
357 {
358  // search the material by its name
359  G4Material* pttoMaterial =
360  G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
361 
362  if (pttoMaterial && fWorldMaterial != pttoMaterial) {
363  fWorldMaterial = pttoMaterial;
364  if(fLogicWorld) fLogicWorld->SetMaterial(fWorldMaterial);
366  }
367 }
368 
369 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
370 
372 {
373  fAbsorberThickness = val;
374  ComputeCalorParameters();
376 }
377 
378 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
379 
381 {
382  fAbsorberSizeYZ = val;
383  ComputeCalorParameters();
385 }
386 
387 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
388 
390 {
391  fWorldSizeX = val;
392  fDefaultWorld = false;
393  ComputeCalorParameters();
395 }
396 
397 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
398 
400 {
401  fWorldSizeYZ = val;
402  fDefaultWorld = false;
403  ComputeCalorParameters();
405 }
406 
407 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
408 
410 {
411  fXposAbs = val;
412  ComputeCalorParameters();
414 }
415 
416 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
417 
418 
420 {
421  if ( fFieldMessenger.Get() == 0 ) {
422  // Create global magnetic field messenger.
423  // Uniform magnetic field is then created automatically if
424  // the field value is not zero.
425  G4ThreeVector fieldValue = G4ThreeVector();
427  new G4GlobalMagFieldMessenger(fieldValue);
428  //msg->SetVerboseLevel(1);
430  fFieldMessenger.Put( msg );
431 
432  }
433 }
434 
435 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
436 
G4IonisParamMat * GetIonisation() const
Definition: G4Material.hh:224
G4Material * FindOrBuildMaterial(const G4String &name, G4bool isotopes=true, G4bool warning=false)
G4String symbol
Definition: TRTMaterials.hh:40
G4Material * Air
Definition: TRTMaterials.hh:57
CLHEP::Hep3Vector G4ThreeVector
void AddMaterial(G4Material *material, G4double fraction)
Definition: G4Material.cc:450
G4double z
Definition: TRTMaterials.hh:39
int universe_mean_density
Definition: hepunit.py:307
Definition: G4Box.hh:63
void SetMeanExcitationEnergy(G4double value)
const G4String & GetName() const
Definition: G4Material.hh:176
value_type & Get() const
Definition: G4Cache.hh:253
int atmosphere
Definition: hepunit.py:151
static void Clean()
Definition: G4SolidStore.cc:79
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
int G4int
Definition: G4Types.hh:78
static G4NistManager * Instance()
static G4PhysicalVolumeStore * GetInstance()
G4double density
Definition: TRTMaterials.hh:39
function g(Y1, Y2, PT2)
Definition: hijing1.383.f:5205
void Register(T *inst)
Definition: G4AutoDelete.hh:65
G4GLOB_DLL std::ostream G4cout
void PhysicsHasBeenModified()
#define pascal
static G4LogicalVolumeStore * GetInstance()
static G4SolidStore * GetInstance()
static G4GeometryManager * GetInstance()
void ReinitializeGeometry(G4bool destroyFirst=false, G4bool prop=true)
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:74
#define G4endl
Definition: G4ios.hh:61
**D E S C R I P T I O N
void OpenGeometry(G4VPhysicalVolume *vol=0)
void AddElement(G4Element *element, G4int nAtoms)
Definition: G4Material.cc:345
double G4double
Definition: G4Types.hh:76
G4Material * CO2
Definition: TRTMaterials.hh:81
void SetMaterial(G4Material *pMaterial)
void Put(const value_type &val) const
Definition: G4Cache.hh:257