Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
examples/extended/electromagnetic/TestEm3/src/DetectorConstruction.cc
이 파일의 문서화 페이지로 가기
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 109115 2018-03-28 07:14:10Z 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  fWorldMaterial(nullptr),fSolidWorld(nullptr),fLogicWorld(nullptr),
61  fPhysiWorld(nullptr),fSolidCalor(nullptr),fLogicCalor(nullptr),
62  fPhysiCalor(nullptr),fSolidLayer(nullptr),fLogicLayer(nullptr),
63  fPhysiLayer(nullptr)
64 {
65  for(G4int i=0; i<kMaxAbsor; ++i) {
66  fAbsorMaterial[i] = nullptr;
67  fAbsorThickness[i] = 0.0;
68  fSolidAbsor[i] = nullptr;
69  fLogicAbsor[i] = nullptr;
70  fPhysiAbsor[i] = nullptr;
71  }
72 
73  // default parameter values of the calorimeter
74  fNbOfAbsor = 2;
75  fAbsorThickness[1] = 2.3*mm;
76  fAbsorThickness[2] = 5.7*mm;
77  fNbOfLayers = 50;
78  fCalorSizeYZ = 40.*cm;
80 
81  // materials
83  SetWorldMaterial("Galactic");
84  SetAbsorMaterial(1,"G4_Pb");
85  SetAbsorMaterial(2,"G4_lAr");
86 
87  // create commands for interactive definition of the calorimeter
89 }
90 
91 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
92 
94 {
95  delete fDetectorMessenger;
96 }
97 
98 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
99 
101 {
102  // This function illustrates the possible ways to define materials using
103  // G4 database on G4Elements
105  manager->SetVerbose(0);
106  //
107  // define Elements
108  //
109  G4double z,a;
110 
111  G4Element* H = manager->FindOrBuildElement(1);
112  G4Element* C = manager->FindOrBuildElement(6);
113  G4Element* N = manager->FindOrBuildElement(7);
114  G4Element* O = manager->FindOrBuildElement(8);
115  G4Element* Si = manager->FindOrBuildElement(14);
116  G4Element* Ge = manager->FindOrBuildElement(32);
117  G4Element* Sb = manager->FindOrBuildElement(51);
118  G4Element* I = manager->FindOrBuildElement(53);
119  G4Element* Cs = manager->FindOrBuildElement(55);
120  G4Element* Pb = manager->FindOrBuildElement(82);
121  G4Element* Bi = manager->FindOrBuildElement(83);
122 
123  //
124  // define an Element from isotopes, by relative abundance
125  //
126  G4int iz, n; //iz=number of protons in an isotope;
127  // n=number of nucleons in an isotope;
128  G4int ncomponents;
129  G4double abundance;
130 
131  G4Isotope* U5 = new G4Isotope("U235", iz=92, n=235, a=235.01*g/mole);
132  G4Isotope* U8 = new G4Isotope("U238", iz=92, n=238, a=238.03*g/mole);
133 
134  G4Element* U = new G4Element("enriched Uranium", "U", ncomponents=2);
135  U->AddIsotope(U5, abundance= 90.*perCent);
136  U->AddIsotope(U8, abundance= 10.*perCent);
137 
138  //
139  // define simple materials
140  //
141  G4double density;
142 
143  new G4Material("liquidH2", z=1., a= 1.008*g/mole, density= 70.8*mg/cm3);
144  new G4Material("Aluminium", z=13., a= 26.98*g/mole, density= 2.700*g/cm3);
145  new G4Material("Titanium", z=22., a= 47.867*g/mole, density= 4.54*g/cm3);
146  new G4Material("Iron", z=26., a= 55.85*g/mole, density= 7.870*g/cm3);
147  new G4Material("Copper", z=29., a= 63.55*g/mole, density= 8.960*g/cm3);
148  new G4Material("Tungsten", z=74., a= 183.85*g/mole, density= 19.30*g/cm3);
149  new G4Material("Gold", z=79., a= 196.97*g/mole, density= 19.32*g/cm3);
150  new G4Material("Uranium", z=92., a= 238.03*g/mole, density= 18.95*g/cm3);
151 
152  //
153  // define a material from elements. case 1: chemical molecule
154  //
155  G4int natoms;
156 
157  G4Material* H2O =
158  new G4Material("Water", density= 1.000*g/cm3, ncomponents=2);
159  H2O->AddElement(H, natoms=2);
160  H2O->AddElement(O, natoms=1);
162  H2O->SetChemicalFormula("H_2O");
163 
164  G4Material* CH =
165  new G4Material("Polystyrene", density= 1.032*g/cm3, ncomponents=2);
166  CH->AddElement(C, natoms=1);
167  CH->AddElement(H, natoms=1);
168 
169  G4Material* Sci =
170  new G4Material("Scintillator", density= 1.032*g/cm3, ncomponents=2);
171  Sci->AddElement(C, natoms=9);
172  Sci->AddElement(H, natoms=10);
173 
174  Sci->GetIonisation()->SetBirksConstant(0.126*mm/MeV);
175 
176  G4Material* Lct =
177  new G4Material("Lucite", density= 1.185*g/cm3, ncomponents=3);
178  Lct->AddElement(C, 59.97*perCent);
179  Lct->AddElement(H, 8.07*perCent);
180  Lct->AddElement(O, 31.96*perCent);
181 
182  G4Material* Sili =
183  new G4Material("Silicon", density= 2.330*g/cm3, ncomponents=1);
184  Sili->AddElement(Si, natoms=1);
185 
186  G4Material* SiO2 =
187  new G4Material("quartz", density= 2.200*g/cm3, ncomponents=2);
188  SiO2->AddElement(Si, natoms=1);
189  SiO2->AddElement(O , natoms=2);
190 
191  G4Material* G10 =
192  new G4Material("NemaG10", density= 1.700*g/cm3, ncomponents=4);
193  G10->AddElement(Si, natoms=1);
194  G10->AddElement(O , natoms=2);
195  G10->AddElement(C , natoms=3);
196  G10->AddElement(H , natoms=3);
197 
198  G4Material* CsI =
199  new G4Material("CsI", density= 4.534*g/cm3, ncomponents=2);
200  CsI->AddElement(Cs, natoms=1);
201  CsI->AddElement(I , natoms=1);
203 
204  G4Material* BGO =
205  new G4Material("BGO", density= 7.10*g/cm3, ncomponents=3);
206  BGO->AddElement(O , natoms=12);
207  BGO->AddElement(Ge, natoms= 3);
208  BGO->AddElement(Bi, natoms= 4);
209 
210  //SiNx
211  density= 3.1 *g/cm3;
212  G4Material* SiNx= new G4Material("SiNx", density, ncomponents=3);
213  SiNx-> AddElement(Si, 300);
214  SiNx-> AddElement(N, 310);
215  SiNx-> AddElement(H, 6);
216 
217  //
218  // define gaseous materials using G4 NIST database
219  //
220  G4double fractionmass;
221 
222  G4Material* Air = manager->FindOrBuildMaterial("G4_AIR");
223  manager->ConstructNewGasMaterial("Air20","G4_AIR",293.*kelvin,1.*atmosphere);
224 
225  G4Material* lAr = manager->FindOrBuildMaterial("G4_lAr");
226  G4Material* lArEm3 = new G4Material("liquidArgon", density= 1.390*g/cm3,
227  ncomponents=1);
228  lArEm3->AddMaterial(lAr, fractionmass=1.0);
229 
230  //
231  // define a material from elements and others materials (mixture of mixtures)
232  //
233 
234  G4Material* Lead = new G4Material("Lead",density=11.35*g/cm3,ncomponents=1);
235  Lead->AddElement(Pb, fractionmass=1.0);
236 
237  G4Material* LeadSb = new G4Material("LeadSb", density=11.35*g/cm3,
238  ncomponents=2);
239  LeadSb->AddElement(Sb, fractionmass=4.*perCent);
240  LeadSb->AddElement(Pb, fractionmass=96.*perCent);
241 
242  G4Material* Aerog = new G4Material("Aerogel", density= 0.200*g/cm3,
243  ncomponents=3);
244  Aerog->AddMaterial(SiO2, fractionmass=62.5*perCent);
245  Aerog->AddMaterial(H2O , fractionmass=37.4*perCent);
246  Aerog->AddElement (C , fractionmass= 0.1*perCent);
247 
248  //
249  // examples of gas in non STP conditions
250  //
251  G4double temperature, pressure;
252 
253  G4Material* CO2 =
254  new G4Material("CarbonicGas", density= 27.*mg/cm3, ncomponents=2,
255  kStateGas, temperature= 325.*kelvin, pressure= 50.*atmosphere);
256  CO2->AddElement(C, natoms=1);
257  CO2->AddElement(O, natoms=2);
258 
259  G4Material* steam =
260  new G4Material("WaterSteam", density= 1.0*mg/cm3, ncomponents=1,
261  kStateGas, temperature= 273*kelvin, pressure= 1*atmosphere);
262  steam->AddMaterial(H2O, fractionmass=1.);
263 
264  new G4Material("ArgonGas", z=18, a=39.948*g/mole, density= 1.782*mg/cm3,
265  kStateGas, 273.15*kelvin, 1*atmosphere);
266  //
267  // examples of vacuum
268  //
269 
270  density = universe_mean_density; //from PhysicalConstants.h
271  pressure = 3.e-18*pascal;
272  temperature = 2.73*kelvin;
273  new G4Material("Galactic", z=1., a=1.008*g/mole, density,
274  kStateGas,temperature,pressure);
275 
276  density = 1.e-5*g/cm3;
277  pressure = 2.e-2*bar;
278  temperature = STP_Temperature; //from PhysicalConstants.h
279  G4Material* beam =
280  new G4Material("Beam", density, ncomponents=1,
281  kStateGas,temperature,pressure);
282  beam->AddMaterial(Air, fractionmass=1.);
283 
284  // G4cout << *(G4Material::GetMaterialTable()) << G4endl;
285 }
286 
287 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
288 
290 {
291  // Compute derived parameters of the calorimeter
292  fLayerThickness = 0.;
293  for (G4int iAbs=1; iAbs<=fNbOfAbsor; iAbs++) {
295  }
299 }
300 
301 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
302 
304 {
305  if(fPhysiWorld) { return fPhysiWorld; }
306  // complete the Calor parameters definition
308 
309  //
310  // World
311  //
312  fSolidWorld = new G4Box("World", //its name
313  fWorldSizeX/2,fWorldSizeYZ/2,fWorldSizeYZ/2); //its size
314 
315  fLogicWorld = new G4LogicalVolume(fSolidWorld, //its solid
316  fWorldMaterial, //its material
317  "World"); //its name
318 
319  fPhysiWorld = new G4PVPlacement(0, //no rotation
320  G4ThreeVector(), //at (0,0,0)
321  fLogicWorld, //its fLogical volume
322  "World", //its name
323  0, //its mother volume
324  false, //no boolean operation
325  0); //copy number
326  //
327  // Calorimeter
328  //
329 
330  fSolidCalor = new G4Box("Calorimeter",
332 
335  "Calorimeter");
336 
337  fPhysiCalor = new G4PVPlacement(0, //no rotation
338  G4ThreeVector(), //at (0,0,0)
339  fLogicCalor, //its fLogical volume
340  "Calorimeter", //its name
341  fLogicWorld, //its mother volume
342  false, //no boolean operation
343  0); //copy number
344 
345  //
346  // Layers
347  //
348 
349  fSolidLayer = new G4Box("Layer",
351 
354  "Layer");
355  if (fNbOfLayers > 1) {
356  fPhysiLayer = new G4PVReplica("Layer",
357  fLogicLayer,
358  fLogicCalor,
359  kXAxis,
360  fNbOfLayers,
361  fLayerThickness);
362  } else {
363  fPhysiLayer = new G4PVPlacement(0,
364  G4ThreeVector(),
365  fLogicLayer,
366  "Layer",
367  fLogicCalor,
368  false,
369  0);
370  }
371  //
372  // Absorbers
373  //
374 
375  G4double xfront = -0.5*fLayerThickness;
376  for (G4int k=1; k<=fNbOfAbsor; ++k) {
377  fSolidAbsor[k] = new G4Box("Absorber", //its name
379 
380  fLogicAbsor[k] = new G4LogicalVolume(fSolidAbsor[k], //its solid
381  fAbsorMaterial[k], //its material
382  fAbsorMaterial[k]->GetName());
383 
384  G4double xcenter = xfront+0.5*fAbsorThickness[k];
385  xfront += fAbsorThickness[k];
386  fPhysiAbsor[k] = new G4PVPlacement(0,
387  G4ThreeVector(xcenter,0.,0.),
388  fLogicAbsor[k],
389  fAbsorMaterial[k]->GetName(),
390  fLogicLayer,
391  false,
392  k); //copy number
393 
394  }
395 
397 
398  //always return the fPhysical World
399  //
400  return fPhysiWorld;
401 }
402 
403 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
404 
406 {
407  G4cout << "\n-------------------------------------------------------------"
408  << "\n ---> The calorimeter is " << fNbOfLayers << " layers of:";
409  for (G4int i=1; i<=fNbOfAbsor; ++i) {
410  G4cout << "\n \t" << std::setw(12) << fAbsorMaterial[i]->GetName() <<": "
411  << std::setw(6) << G4BestUnit(fAbsorThickness[i],"Length");
412  }
413  G4cout << "\n-------------------------------------------------------------\n";
414 
415  G4cout << "\n" << fWorldMaterial << G4endl;
416  for (G4int j=1; j<=fNbOfAbsor; ++j) {
417  G4cout << "\n" << fAbsorMaterial[j] << G4endl;
418  }
419  G4cout << "\n-------------------------------------------------------------\n";
420 }
421 
422 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
423 
425 {
426  // search the material by its name
427  G4Material* pttoMaterial =
429  if(pttoMaterial) {
430  fWorldMaterial = pttoMaterial;
431  if(fLogicWorld) {
435  }
436  }
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;
451 }
452 
453 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
454 
456 {
457  // set the number of Absorbers
458  //
459  if (ival < 1 || ival > (kMaxAbsor-1))
460  { G4cout << "\n ---> warning from SetfNbOfAbsor: "
461  << ival << " must be at least 1 and and most " << kMaxAbsor-1
462  << ". Command refused" << G4endl;
463  return;
464  }
465  fNbOfAbsor = ival;
466 }
467 
468 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
469 
471  const G4String& material)
472 {
473  // search the material by its name
474  //
475  if (ival > fNbOfAbsor || ival <= 0)
476  { G4cout << "\n --->warning from SetAbsorMaterial: absor number "
477  << ival << " out of range. Command refused" << G4endl;
478  return;
479  }
480 
481  G4Material* pttoMaterial =
483  if (pttoMaterial) {
484  fAbsorMaterial[ival] = pttoMaterial;
485  if(fLogicAbsor[ival]) {
486  fLogicAbsor[ival]->SetMaterial(pttoMaterial);
488  }
489  }
490 }
491 
492 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
493 
495 {
496  // change Absorber thickness
497  //
498  if (ival > fNbOfAbsor || ival <= 0)
499  { G4cout << "\n --->warning from SetAbsorThickness: absor number "
500  << ival << " out of range. Command refused" << G4endl;
501  return;
502  }
503  if (val <= DBL_MIN)
504  { G4cout << "\n --->warning from SetAbsorThickness: thickness "
505  << val << " out of range. Command refused" << G4endl;
506  return;
507  }
508  fAbsorThickness[ival] = val;
509 }
510 
511 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
512 
514 {
515  // change the transverse size
516  //
517  if (val <= DBL_MIN)
518  { G4cout << "\n --->warning from SetfCalorSizeYZ: thickness "
519  << val << " out of range. Command refused" << G4endl;
520  return;
521  }
522  fCalorSizeYZ = val;
523 }
524 
525 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
526 
528 #include "G4AutoDelete.hh"
529 
531 {
532  if ( fFieldMessenger.Get() == nullptr ) {
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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
static constexpr double kelvin
Definition: G4SIunits.hh:281
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:80
static constexpr double atmosphere
Definition: G4SIunits.hh:237
CLHEP::Hep3Vector G4ThreeVector
std::vector< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33
static constexpr double MeV
Definition: G4SIunits.hh:214
static constexpr double STP_Temperature
static constexpr double mm
Definition: G4SIunits.hh:115
#define G4endl
Definition: G4ios.hh:61
Double_t z
static constexpr double perCent
Definition: G4SIunits.hh:332
void SetMeanExcitationEnergy(G4double value)
void SetBirksConstant(G4double value)
static constexpr double universe_mean_density
void Register(T *inst)
Definition: G4AutoDelete.hh:65
const G4String & GetName() const
Definition: G4Material.hh:179
void AddIsotope(G4Isotope *isotope, G4double RelativeAbundance)
Definition: G4Element.cc:152
void SetVerbose(G4int)
G4Element * FindOrBuildElement(G4int Z, G4bool isotopes=true)
void SetWorldMaterial(const G4String &materialName)
static constexpr double g
Definition: G4SIunits.hh:183
G4Material * ConstructNewGasMaterial(const G4String &name, const G4String &nameNist, G4double temp, G4double pres, G4bool isotopes=true)
double G4double
Definition: G4Types.hh:76
**D E S C R I P T I O N
static constexpr double mg
Definition: G4SIunits.hh:184
Definition: G4Box.hh:64
G4Material * FindOrBuildMaterial(const G4String &name, G4bool isotopes=true, G4bool warning=false)
static constexpr double eV
Definition: G4SIunits.hh:215
value_type & Get() const
Definition: G4Cache.hh:314
void Put(const value_type &val) const
Definition: G4Cache.hh:318
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
void SetChemicalFormula(const G4String &chF)
Definition: G4Material.hh:174
int G4int
Definition: G4Types.hh:78
double C(double temp)
void AddElement(G4Element *element, G4int nAtoms)
Definition: G4Material.cc:368
G4IonisParamMat * GetIonisation() const
Definition: G4Material.hh:227
#define DBL_MIN
Definition: templates.hh:75
void PhysicsHasBeenModified()
G4Cache< G4GlobalMagFieldMessenger * > fFieldMessenger
G4GLOB_DLL std::ostream G4cout
static constexpr double cm
Definition: G4SIunits.hh:119
void SetMaterial(G4Material *pMaterial)
Char_t n[5]
static constexpr double mole
Definition: G4SIunits.hh:286
#define pascal
void AddMaterial(G4Material *material, G4double fraction)
Definition: G4Material.cc:473
static constexpr double bar
Definition: G4SIunits.hh:236
static constexpr double cm3
Definition: G4SIunits.hh:121
static G4NistManager * Instance()