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