Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 98762 2016-08-09 14:08:07Z 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;
71  ComputeCalorParameters();
72 
73  // materials
74  DefineMaterials();
75  SetWorldMaterial("Galactic");
76  SetAbsorMaterial(1,"Lead");
77  SetAbsorMaterial(2,"liquidArgon");
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 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  //
140  G4double density;
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 
288 void DetectorConstruction::ComputeCalorParameters()
289 {
290  // Compute derived parameters of the calorimeter
291  fLayerThickness = 0.;
292  for (G4int iAbs=1; iAbs<=fNbOfAbsor; iAbs++) {
293  fLayerThickness += fAbsorThickness[iAbs];
294  }
295  fCalorThickness = fNbOfLayers*fLayerThickness;
296  fWorldSizeX = 1.2*fCalorThickness;
297  fWorldSizeYZ = 1.2*fCalorSizeYZ;
298 }
299 
300 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
301 
302 G4VPhysicalVolume* DetectorConstruction::ConstructCalorimeter()
303 {
304  // complete the Calor parameters definition
305  ComputeCalorParameters();
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",
336  fCalorThickness/2,fCalorSizeYZ/2,fCalorSizeYZ/2);
337 
338  fLogicCalor = new G4LogicalVolume(fSolidCalor,
339  fDefaultMaterial,
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",
355  fLayerThickness/2,fCalorSizeYZ/2,fCalorSizeYZ/2);
356 
357  fLogicLayer = new G4LogicalVolume(fSolidLayer,
358  fDefaultMaterial,
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
383  fAbsorThickness[k]/2,fCalorSizeYZ/2,fCalorSizeYZ/2);
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 
402 
403  //always return the fPhysical World
404  //
405  return fPhysiWorld;
406 }
407 
408 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
409 
411 {
412  G4cout << "\n-------------------------------------------------------------"
413  << "\n ---> The calorimeter is " << fNbOfLayers << " layers of:";
414  for (G4int i=1; i<=fNbOfAbsor; i++)
415  {
416  G4cout << "\n \t" << std::setw(12) << fAbsorMaterial[i]->GetName() <<": "
417  << std::setw(6) << G4BestUnit(fAbsorThickness[i],"Length");
418  }
419  G4cout << "\n-------------------------------------------------------------\n";
420 
421  G4cout << "\n" << fDefaultMaterial << G4endl;
422  for (G4int j=1; j<=fNbOfAbsor; j++)
423  G4cout << "\n" << fAbsorMaterial[j] << G4endl;
424 
425  G4cout << "\n-------------------------------------------------------------\n";
426 }
427 
428 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
429 
431 {
432  // search the material by its name
433  G4Material* pttoMaterial =
435  if (pttoMaterial) fDefaultMaterial = pttoMaterial;
437 }
438 
439 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
440 
442 {
443  // set the number of Layers
444  //
445  if (ival < 1)
446  { G4cout << "\n --->warning from SetfNbOfLayers: "
447  << ival << " must be at least 1. Command refused" << G4endl;
448  return;
449  }
450  fNbOfLayers = ival;
452 }
453 
454 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
455 
457 {
458  // set the number of Absorbers
459  //
460  if (ival < 1 || ival > (kMaxAbsor-1))
461  { G4cout << "\n ---> warning from SetfNbOfAbsor: "
462  << ival << " must be at least 1 and and most " << kMaxAbsor-1
463  << ". Command refused" << G4endl;
464  return;
465  }
466  fNbOfAbsor = ival;
468 }
469 
470 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
471 
473  const G4String& material)
474 {
475  // search the material by its name
476  //
477  if (ival > fNbOfAbsor || ival <= 0)
478  { G4cout << "\n --->warning from SetAbsorMaterial: absor number "
479  << ival << " out of range. Command refused" << G4endl;
480  return;
481  }
482 
483  G4Material* pttoMaterial =
485  if (pttoMaterial) fAbsorMaterial[ival] = pttoMaterial;
487 }
488 
489 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
490 
492 {
493  // change Absorber thickness
494  //
495  if (ival > fNbOfAbsor || ival <= 0)
496  { G4cout << "\n --->warning from SetAbsorThickness: absor number "
497  << ival << " out of range. Command refused" << G4endl;
498  return;
499  }
500  if (val <= DBL_MIN)
501  { G4cout << "\n --->warning from SetAbsorThickness: thickness "
502  << val << " out of range. Command refused" << G4endl;
503  return;
504  }
505  fAbsorThickness[ival] = val;
507 }
508 
509 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
510 
512 {
513  // change the transverse size
514  //
515  if (val <= DBL_MIN)
516  { G4cout << "\n --->warning from SetfCalorSizeYZ: thickness "
517  << val << " out of range. Command refused" << G4endl;
518  return;
519  }
520  fCalorSizeYZ = val;
522 }
523 
524 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
525 
527 #include "G4AutoDelete.hh"
528 
530 {
531  if ( fFieldMessenger.Get() == 0 ) {
532  // Create global magnetic field messenger.
533  // Uniform magnetic field is then created automatically if
534  // the field value is not zero.
535  G4ThreeVector fieldValue = G4ThreeVector();
537  new G4GlobalMagFieldMessenger(fieldValue);
538  //msg->SetVerboseLevel(1);
540  fFieldMessenger.Put( msg );
541 
542  }
543 }
544 
545 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4IonisParamMat * GetIonisation() const
Definition: G4Material.hh:226
G4Material * FindOrBuildMaterial(const G4String &name, G4bool isotopes=true, G4bool warning=false)
void SetChemicalFormula(const G4String &chF)
Definition: G4Material.hh:173
static constexpr double mm
Definition: G4SIunits.hh:115
static constexpr double mg
Definition: G4SIunits.hh:184
CLHEP::Hep3Vector G4ThreeVector
void AddMaterial(G4Material *material, G4double fraction)
Definition: G4Material.cc:467
std::vector< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33
int universe_mean_density
Definition: hepunit.py:307
Definition: G4Box.hh:64
void SetMeanExcitationEnergy(G4double value)
static constexpr double perCent
Definition: G4SIunits.hh:332
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
double C(double temp)
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
float STP_Temperature
Definition: hepunit.py:302
int G4int
Definition: G4Types.hh:78
static G4NistManager * Instance()
static G4PhysicalVolumeStore * GetInstance()
string material
Definition: eplot.py:19
virtual void ConstructSDandField()
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()
void SetVerbose(G4int)
void SetAbsorMaterial(G4int, const G4String &)
const G4int kMaxAbsor
static constexpr double cm
Definition: G4SIunits.hh:119
void AddIsotope(G4Isotope *isotope, G4double RelativeAbundance)
Definition: G4Element.cc:152
#define pascal
static G4LogicalVolumeStore * GetInstance()
static G4SolidStore * GetInstance()
static constexpr double eV
Definition: G4SIunits.hh:215
const G4int n
static G4GeometryManager * GetInstance()
static constexpr double kelvin
Definition: G4SIunits.hh:281
static constexpr double cm3
Definition: G4SIunits.hh:121
void ReinitializeGeometry(G4bool destroyFirst=false, G4bool prop=true)
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
#define DBL_MIN
Definition: templates.hh:75
tuple z
Definition: test.py:28
#define G4endl
Definition: G4ios.hh:61
void SetAbsorThickness(G4int, G4double)
**D E S C R I P T I O N
Definition: HEPEvtcom.cc:77
static constexpr double MeV
Definition: G4SIunits.hh:214
void OpenGeometry(G4VPhysicalVolume *vol=0)
void AddElement(G4Element *element, G4int nAtoms)
Definition: G4Material.cc:362
G4Material * ConstructNewGasMaterial(const G4String &name, const G4String &nameNist, G4double temp, G4double pres, G4bool isotopes=true)
static constexpr double bar
Definition: G4SIunits.hh:236
double G4double
Definition: G4Types.hh:76
G4Element * FindOrBuildElement(G4int Z, G4bool isotopes=true)
void Put(const value_type &val) const
Definition: G4Cache.hh:286
static constexpr double atmosphere
Definition: G4SIunits.hh:237
static constexpr double mole
Definition: G4SIunits.hh:286