Geant4  10.02.p01
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 //
28 //
29 // $Id: DetectorConstruction.cc 78655 2014-01-14 11:13: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 "G4NistManager.hh"
38 #include "G4Material.hh"
39 #include "G4Box.hh"
40 #include "G4LogicalVolume.hh"
41 #include "G4PVPlacement.hh"
42 #include "G4PVReplica.hh"
43 
44 #include "G4GeometryManager.hh"
45 #include "G4PhysicalVolumeStore.hh"
46 #include "G4LogicalVolumeStore.hh"
47 #include "G4SolidStore.hh"
48 
49 #include "G4RunManager.hh"
50 #include "G4SystemOfUnits.hh"
51 #include "G4UnitsTable.hh"
52 #include "G4PhysicalConstants.hh"
53 
54 #include <iomanip>
55 
56 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
57 
60  fDefaultMaterial(0),fSolidWorld(0),fLogicWorld(0),fPhysiWorld(0),
61  fSolidCalor(0),fLogicCalor(0),fPhysiCalor(0),
62  fSolidLayer(0),fLogicLayer(0),fPhysiLayer(0),
63 fDetectorMessenger(0)
64 {
65  // default parameter values of the calorimeter
66  fNbOfAbsor = 2;
67  fAbsorThickness[1] = 2.3*mm;
68  fAbsorThickness[2] = 5.7*mm;
69  fNbOfLayers = 50;
70  fCalorSizeYZ = 40.*cm;
72 
73  // materials
75  SetWorldMaterial("Galactic");
76  SetAbsorMaterial(1,"Lead");
77  SetAbsorMaterial(2,"liquidArgon");
78 
79  // create commands for interactive definition of the calorimeter
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 
100 {
101  // This function illustrates the possible ways to define materials using
102  // G4 database on G4Elements
104  manager->SetVerbose(0);
105  //
106  // define Elements
107  //
108  G4double z,a;
109 
110  G4Element* H = manager->FindOrBuildElement(1);
111  G4Element* C = manager->FindOrBuildElement(6);
112  G4Element* N = manager->FindOrBuildElement(7);
113  G4Element* O = manager->FindOrBuildElement(8);
114  G4Element* Si = manager->FindOrBuildElement(14);
115  G4Element* Ge = manager->FindOrBuildElement(32);
116  G4Element* Sb = manager->FindOrBuildElement(51);
117  G4Element* I = manager->FindOrBuildElement(53);
118  G4Element* Cs = manager->FindOrBuildElement(55);
119  G4Element* Pb = manager->FindOrBuildElement(82);
120  G4Element* Bi = manager->FindOrBuildElement(83);
121 
122  //
123  // define an Element from isotopes, by relative abundance
124  //
125  G4int iz, n; //iz=number of protons in an isotope;
126  // n=number of nucleons in an isotope;
127  G4int ncomponents;
128  G4double abundance;
129 
130  G4Isotope* U5 = new G4Isotope("U235", iz=92, n=235, a=235.01*g/mole);
131  G4Isotope* U8 = new G4Isotope("U238", iz=92, n=238, a=238.03*g/mole);
132 
133  G4Element* U = new G4Element("enriched Uranium", "U", ncomponents=2);
134  U->AddIsotope(U5, abundance= 90.*perCent);
135  U->AddIsotope(U8, abundance= 10.*perCent);
136 
137  //
138  // define simple materials
139  //
141 
142  new G4Material("liquidH2", z=1., a= 1.008*g/mole, density= 70.8*mg/cm3);
143  new G4Material("Aluminium", z=13., a= 26.98*g/mole, density= 2.700*g/cm3);
144  new G4Material("Titanium", z=22., a= 47.867*g/mole, density= 4.54*g/cm3);
145  new G4Material("Iron", z=26., a= 55.85*g/mole, density= 7.870*g/cm3);
146  new G4Material("Copper", z=29., a= 63.55*g/mole, density= 8.960*g/cm3);
147  new G4Material("Tungsten", z=74., a= 183.85*g/mole, density= 19.30*g/cm3);
148  new G4Material("Gold", z=79., a= 196.97*g/mole, density= 19.32*g/cm3);
149  new G4Material("Uranium", z=92., a= 238.03*g/mole, density= 18.95*g/cm3);
150 
151  //
152  // define a material from elements. case 1: chemical molecule
153  //
154  G4int natoms;
155 
156  G4Material* H2O =
157  new G4Material("Water", density= 1.000*g/cm3, ncomponents=2);
158  H2O->AddElement(H, natoms=2);
159  H2O->AddElement(O, natoms=1);
161  H2O->SetChemicalFormula("H_2O");
162 
163  G4Material* CH =
164  new G4Material("Polystyrene", density= 1.032*g/cm3, ncomponents=2);
165  CH->AddElement(C, natoms=1);
166  CH->AddElement(H, natoms=1);
167 
168  G4Material* Sci =
169  new G4Material("Scintillator", density= 1.032*g/cm3, ncomponents=2);
170  Sci->AddElement(C, natoms=9);
171  Sci->AddElement(H, natoms=10);
172 
173  Sci->GetIonisation()->SetBirksConstant(0.126*mm/MeV);
174 
175  G4Material* Lct =
176  new G4Material("Lucite", density= 1.185*g/cm3, ncomponents=3);
177  Lct->AddElement(C, 59.97*perCent);
178  Lct->AddElement(H, 8.07*perCent);
179  Lct->AddElement(O, 31.96*perCent);
180 
181  G4Material* Sili =
182  new G4Material("Silicon", density= 2.330*g/cm3, ncomponents=1);
183  Sili->AddElement(Si, natoms=1);
184 
185  G4Material* SiO2 =
186  new G4Material("quartz", density= 2.200*g/cm3, ncomponents=2);
187  SiO2->AddElement(Si, natoms=1);
188  SiO2->AddElement(O , natoms=2);
189 
190  G4Material* G10 =
191  new G4Material("NemaG10", density= 1.700*g/cm3, ncomponents=4);
192  G10->AddElement(Si, natoms=1);
193  G10->AddElement(O , natoms=2);
194  G10->AddElement(C , natoms=3);
195  G10->AddElement(H , natoms=3);
196 
197  G4Material* CsI =
198  new G4Material("CsI", density= 4.534*g/cm3, ncomponents=2);
199  CsI->AddElement(Cs, natoms=1);
200  CsI->AddElement(I , natoms=1);
202 
203  G4Material* BGO =
204  new G4Material("BGO", density= 7.10*g/cm3, ncomponents=3);
205  BGO->AddElement(O , natoms=12);
206  BGO->AddElement(Ge, natoms= 3);
207  BGO->AddElement(Bi, natoms= 4);
208 
209  //SiNx
210  density= 3.1 *g/cm3;
211  G4Material* SiNx= new G4Material("SiNx", density, ncomponents=3);
212  SiNx-> AddElement(Si, 300);
213  SiNx-> AddElement(N, 310);
214  SiNx-> AddElement(H, 6);
215 
216  //
217  // define gaseous materials using G4 NIST database
218  //
219  G4double fractionmass;
220 
221  G4Material* Air = manager->FindOrBuildMaterial("G4_AIR");
222  manager->ConstructNewGasMaterial("Air20","G4_AIR",293.*kelvin,1.*atmosphere);
223 
224  G4Material* lAr = manager->FindOrBuildMaterial("G4_lAr");
225  G4Material* lArEm3 = new G4Material("liquidArgon", density= 1.390*g/cm3,
226  ncomponents=1);
227  lArEm3->AddMaterial(lAr, fractionmass=1.0);
228 
229  //
230  // define a material from elements and others materials (mixture of mixtures)
231  //
232 
233  G4Material* Lead = new G4Material("Lead",density=11.35*g/cm3,ncomponents=1);
234  Lead->AddElement(Pb, fractionmass=1.0);
235 
236  G4Material* LeadSb = new G4Material("LeadSb", density=11.35*g/cm3,
237  ncomponents=2);
238  LeadSb->AddElement(Sb, fractionmass=4.*perCent);
239  LeadSb->AddElement(Pb, fractionmass=96.*perCent);
240 
241  G4Material* Aerog = new G4Material("Aerogel", density= 0.200*g/cm3,
242  ncomponents=3);
243  Aerog->AddMaterial(SiO2, fractionmass=62.5*perCent);
244  Aerog->AddMaterial(H2O , fractionmass=37.4*perCent);
245  Aerog->AddElement (C , fractionmass= 0.1*perCent);
246 
247  //
248  // examples of gas in non STP conditions
249  //
250  G4double temperature, pressure;
251 
252  G4Material* CO2 =
253  new G4Material("CarbonicGas", density= 27.*mg/cm3, ncomponents=2,
254  kStateGas, temperature= 325.*kelvin, pressure= 50.*atmosphere);
255  CO2->AddElement(C, natoms=1);
256  CO2->AddElement(O, natoms=2);
257 
258  G4Material* steam =
259  new G4Material("WaterSteam", density= 1.0*mg/cm3, ncomponents=1,
260  kStateGas, temperature= 273*kelvin, pressure= 1*atmosphere);
261  steam->AddMaterial(H2O, fractionmass=1.);
262 
263  new G4Material("ArgonGas", z=18, a=39.948*g/mole, density= 1.782*mg/cm3,
264  kStateGas, 273.15*kelvin, 1*atmosphere);
265  //
266  // examples of vacuum
267  //
268 
269  density = universe_mean_density; //from PhysicalConstants.h
270  pressure = 3.e-18*pascal;
271  temperature = 2.73*kelvin;
272  new G4Material("Galactic", z=1., a=1.008*g/mole, density,
273  kStateGas,temperature,pressure);
274 
275  density = 1.e-5*g/cm3;
276  pressure = 2.e-2*bar;
277  temperature = STP_Temperature; //from PhysicalConstants.h
278  G4Material* beam =
279  new G4Material("Beam", density, ncomponents=1,
280  kStateGas,temperature,pressure);
281  beam->AddMaterial(Air, fractionmass=1.);
282 
283  // G4cout << *(G4Material::GetMaterialTable()) << G4endl;
284 }
285 
286 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
287 
289 {
290  // Compute derived parameters of the calorimeter
291  fLayerThickness = 0.;
292  for (G4int iAbs=1; iAbs<=fNbOfAbsor; iAbs++) {
294  }
298 }
299 
300 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
301 
303 {
304  // complete the Calor parameters definition
306 
307  // Cleanup old geometry
312 
313  //
314  // World
315  //
316 
317  fSolidWorld = new G4Box("World", //its name
318  fWorldSizeX/2,fWorldSizeYZ/2,fWorldSizeYZ/2); //its size
319 
320  fLogicWorld = new G4LogicalVolume(fSolidWorld, //its solid
321  fDefaultMaterial, //its material
322  "World"); //its name
323 
324  fPhysiWorld = new G4PVPlacement(0, //no rotation
325  G4ThreeVector(), //at (0,0,0)
326  fLogicWorld, //its fLogical volume
327  "World", //its name
328  0, //its mother volume
329  false, //no boolean operation
330  0); //copy number
331  //
332  // Calorimeter
333  //
334 
335  fSolidCalor = new G4Box("Calorimeter",
337 
340  "Calorimeter");
341 
342  fPhysiCalor = new G4PVPlacement(0, //no rotation
343  G4ThreeVector(), //at (0,0,0)
344  fLogicCalor, //its fLogical volume
345  "Calorimeter", //its name
346  fLogicWorld, //its mother volume
347  false, //no boolean operation
348  0); //copy number
349 
350  //
351  // Layers
352  //
353 
354  fSolidLayer = new G4Box("Layer",
356 
359  "Layer");
360  if (fNbOfLayers > 1)
361  fPhysiLayer = new G4PVReplica("Layer",
362  fLogicLayer,
363  fLogicCalor,
364  kXAxis,
365  fNbOfLayers,
366  fLayerThickness);
367  else
368  fPhysiLayer = new G4PVPlacement(0,
369  G4ThreeVector(),
370  fLogicLayer,
371  "Layer",
372  fLogicCalor,
373  false,
374  0);
375 
376  //
377  // Absorbers
378  //
379 
380  G4double xfront = -0.5*fLayerThickness;
381  for (G4int k=1; k<=fNbOfAbsor; k++) {
382  fSolidAbsor[k] = new G4Box("Absorber", //its name
384 
385  fLogicAbsor[k] = new G4LogicalVolume(fSolidAbsor[k], //its solid
386  fAbsorMaterial[k], //its material
387  fAbsorMaterial[k]->GetName());
388 
389  G4double xcenter = xfront+0.5*fAbsorThickness[k];
390  xfront += fAbsorThickness[k];
391  fPhysiAbsor[k] = new G4PVPlacement(0,
392  G4ThreeVector(xcenter,0.,0.),
393  fLogicAbsor[k],
394  fAbsorMaterial[k]->GetName(),
395  fLogicLayer,
396  false,
397  k); //copy number
398 
399  }
400 
401 
403 
404  //always return the fPhysical World
405  //
406  return fPhysiWorld;
407 }
408 
409 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
410 
412 {
413  G4cout << "\n-------------------------------------------------------------"
414  << "\n ---> The calorimeter is " << fNbOfLayers << " layers of:";
415  for (G4int i=1; i<=fNbOfAbsor; i++)
416  {
417  G4cout << "\n \t" << std::setw(12) << fAbsorMaterial[i]->GetName() <<": "
418  << std::setw(6) << G4BestUnit(fAbsorThickness[i],"Length");
419  }
420  G4cout << "\n-------------------------------------------------------------\n";
421 
422  G4cout << "\n" << fDefaultMaterial << G4endl;
423  for (G4int j=1; j<=fNbOfAbsor; j++)
424  G4cout << "\n" << fAbsorMaterial[j] << G4endl;
425 
426  G4cout << "\n-------------------------------------------------------------\n";
427 }
428 
429 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
430 
432 {
433  // search the material by its name
434  G4Material* pttoMaterial =
436  if (pttoMaterial) fDefaultMaterial = pttoMaterial;
438 }
439 
440 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
441 
443 {
444  // set the number of Layers
445  //
446  if (ival < 1)
447  { G4cout << "\n --->warning from SetfNbOfLayers: "
448  << ival << " must be at least 1. Command refused" << G4endl;
449  return;
450  }
451  fNbOfLayers = ival;
453 }
454 
455 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
456 
458 {
459  // set the number of Absorbers
460  //
461  if (ival < 1 || ival > (MaxAbsor-1))
462  { G4cout << "\n ---> warning from SetfNbOfAbsor: "
463  << ival << " must be at least 1 and and most " << MaxAbsor-1
464  << ". Command refused" << G4endl;
465  return;
466  }
467  fNbOfAbsor = ival;
469 }
470 
471 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
472 
474  const G4String& material)
475 {
476  // search the material by its name
477  //
478  if (ival > fNbOfAbsor || ival <= 0)
479  { G4cout << "\n --->warning from SetAbsorMaterial: absor number "
480  << ival << " out of range. Command refused" << G4endl;
481  return;
482  }
483 
484  G4Material* pttoMaterial =
486  if (pttoMaterial) fAbsorMaterial[ival] = pttoMaterial;
488 }
489 
490 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
491 
493 {
494  // change Absorber thickness
495  //
496  if (ival > fNbOfAbsor || ival <= 0)
497  { G4cout << "\n --->warning from SetAbsorThickness: absor number "
498  << ival << " out of range. Command refused" << G4endl;
499  return;
500  }
501  if (val <= DBL_MIN)
502  { G4cout << "\n --->warning from SetAbsorThickness: thickness "
503  << val << " out of range. Command refused" << G4endl;
504  return;
505  }
506  fAbsorThickness[ival] = val;
508 }
509 
510 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
511 
513 {
514  // change the transverse size
515  //
516  if (val <= DBL_MIN)
517  { G4cout << "\n --->warning from SetfCalorSizeYZ: thickness "
518  << val << " out of range. Command refused" << G4endl;
519  return;
520  }
521  fCalorSizeYZ = val;
523 }
524 
525 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
526 
528 #include "G4AutoDelete.hh"
529 
531 {
532  if ( fFieldMessenger.Get() == 0 ) {
533  // Create global magnetic field messenger.
534  // Uniform magnetic field is then created automatically if
535  // the field value is not zero.
536  G4ThreeVector fieldValue = G4ThreeVector();
538  new G4GlobalMagFieldMessenger(fieldValue);
539  //msg->SetVerboseLevel(1);
541  fFieldMessenger.Put( msg );
542 
543  }
544 }
545 
546 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4LogicalVolume * fLogicLayer
static const double cm
Definition: G4SIunits.hh:118
G4IonisParamMat * GetIonisation() const
Definition: G4Material.hh:226
G4Material * FindOrBuildMaterial(const G4String &name, G4bool isotopes=true, G4bool warning=false)
static const double MeV
Definition: G4SIunits.hh:211
G4Material * Air
Definition: TRTMaterials.hh:57
void SetChemicalFormula(const G4String &chF)
Definition: G4Material.hh:173
CLHEP::Hep3Vector G4ThreeVector
void AddMaterial(G4Material *material, G4double fraction)
Definition: G4Material.cc:469
G4double z
Definition: TRTMaterials.hh:39
Definition: G4Box.hh:64
void SetMeanExcitationEnergy(G4double value)
const G4String & GetName() const
Definition: G4Material.hh:178
G4VPhysicalVolume * Construct()
void SetBirksConstant(G4double value)
value_type & Get() const
Definition: G4Cache.hh:282
void SetWorldMaterial(const G4String &)
static void Clean()
Definition: G4SolidStore.cc:79
G4VPhysicalVolume * fPhysiAbsor[MaxAbsor]
G4double a
Definition: TRTMaterials.hh:39
const G4int MaxAbsor
double C(double temp)
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
static const double mg
Definition: G4SIunits.hh:181
G4VPhysicalVolume * fPhysiLayer
int G4int
Definition: G4Types.hh:78
G4Material * fAbsorMaterial[MaxAbsor]
static G4NistManager * Instance()
G4Cache< G4GlobalMagFieldMessenger * > fFieldMessenger
G4LogicalVolume * fLogicAbsor[MaxAbsor]
static G4PhysicalVolumeStore * GetInstance()
G4double density
Definition: TRTMaterials.hh:39
virtual void ConstructSDandField()
G4double fAbsorThickness[MaxAbsor]
void Register(T *inst)
Definition: G4AutoDelete.hh:65
G4GLOB_DLL std::ostream G4cout
G4LogicalVolume * fLogicWorld
void PhysicsHasBeenModified()
void SetVerbose(G4int)
G4VPhysicalVolume * fPhysiWorld
void SetAbsorMaterial(G4int, const G4String &)
G4LogicalVolume * fLogicCalor
G4double iz
Definition: TRTMaterials.hh:39
void AddIsotope(G4Isotope *isotope, G4double RelativeAbundance)
Definition: G4Element.cc:151
G4VPhysicalVolume * fPhysiCalor
G4Material * Si
Definition: TRTMaterials.hh:78
static G4LogicalVolumeStore * GetInstance()
static const double cm3
Definition: G4SIunits.hh:120
static G4SolidStore * GetInstance()
static const double perCent
Definition: G4SIunits.hh:329
static const double bar
Definition: G4SIunits.hh:233
const G4int n
static G4GeometryManager * GetInstance()
void ReinitializeGeometry(G4bool destroyFirst=false, G4bool prop=true)
static const double kelvin
Definition: G4SIunits.hh:278
#define pascal
Definition: G4SIunits.hh:231
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
static const double eV
Definition: G4SIunits.hh:212
G4Box * fSolidAbsor[MaxAbsor]
static const double g
Definition: G4SIunits.hh:180
G4VPhysicalVolume * ConstructCalorimeter()
static const double atmosphere
Definition: G4SIunits.hh:234
#define DBL_MIN
Definition: templates.hh:75
static const double mole
Definition: G4SIunits.hh:283
#define G4endl
Definition: G4ios.hh:61
void SetAbsorThickness(G4int, G4double)
void OpenGeometry(G4VPhysicalVolume *vol=0)
void AddElement(G4Element *element, G4int nAtoms)
Definition: G4Material.cc:364
G4Material * ConstructNewGasMaterial(const G4String &name, const G4String &nameNist, G4double temp, G4double pres, G4bool isotopes=true)
double G4double
Definition: G4Types.hh:76
G4Element * FindOrBuildElement(G4int Z, G4bool isotopes=true)
Air AddElement(elN,.7)
G4Material * CO2
Definition: TRTMaterials.hh:81
void Put(const value_type &val) const
Definition: G4Cache.hh:286
static const double mm
Definition: G4SIunits.hh:114
Messenger class that defines commands for DetectorConstruction.
DetectorMessenger * fDetectorMessenger