Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExN03DetectorConstruction.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 //
27 // $Id: ExN03DetectorConstruction.cc,v 1.5 2006-12-01 02:37:01 kmura Exp $
28 // GEANT4 tag $Name: not supported by cvs2svn $
29 //
30 //
31 
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
34 
37 
38 #include "G4Material.hh"
39 #include "G4Box.hh"
40 #include "G4LogicalVolume.hh"
41 #include "G4PVPlacement.hh"
42 #include "G4PVReplica.hh"
43 #include "G4UniformMagField.hh"
44 
45 #include "G4GeometryManager.hh"
46 #include "G4PhysicalVolumeStore.hh"
47 #include "G4LogicalVolumeStore.hh"
48 #include "G4SolidStore.hh"
49 
50 #include "G4VisAttributes.hh"
51 #include "G4Colour.hh"
52 #include "G4SystemOfUnits.hh"
53 #include "G4PhysicalConstants.hh"
54 
55 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
56 
58 :AbsorberMaterial(0),GapMaterial(0),defaultMaterial(0),
59  solidWorld(0),logicWorld(0),physiWorld(0),
60  solidCalor(0),logicCalor(0),physiCalor(0),
61  solidLayer(0),logicLayer(0),physiLayer(0),
62  solidAbsorber(0),logicAbsorber(0),physiAbsorber(0),
63  solidGap (0),logicGap (0),physiGap (0),
64  magField(0)
65 {
66  // default parameter values of the calorimeter
67  AbsorberThickness = 10.*mm;
68  GapThickness = 5.*mm;
69  NbOfLayers = 10;
70  CalorSizeYZ = 10.*cm;
71  ComputeCalorParameters();
72 
73  // materials
74  DefineMaterials();
75  SetAbsorberMaterial("Lead");
76  SetGapMaterial("liquidArgon");
77 
78  // create commands for interactive definition of the calorimeter
79  detectorMessenger = new ExN03DetectorMessenger(this);
80 }
81 
82 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
83 
85 { delete detectorMessenger;}
86 
87 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
88 
90 {
91  return ConstructCalorimeter();
92 }
93 
94 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
95 
96 void ExN03DetectorConstruction::DefineMaterials()
97 {
98  //This function illustrates the possible ways to define materials
99 
100 G4String symbol; //a=mass of a mole;
101 G4double a, z, density; //z=mean number of protons;
102 G4int iz, n; //iz=number of protons in an isotope;
103  // n=number of nucleons in an isotope;
104 
105 G4int ncomponents, natoms;
106 G4double abundance, fractionmass;
107 
108 //
109 // define Elements
110 //
111 
112 G4Element* H = new G4Element("Hydrogen",symbol="H" , z= 1., a= 1.01*g/mole);
113 G4Element* C = new G4Element("Carbon" ,symbol="C" , z= 6., a= 12.01*g/mole);
114 G4Element* N = new G4Element("Nitrogen",symbol="N" , z= 7., a= 14.01*g/mole);
115 G4Element* O = new G4Element("Oxygen" ,symbol="O" , z= 8., a= 16.00*g/mole);
116 G4Element* Si = new G4Element("Silicon",symbol="Si" , z= 14., a= 28.09*g/mole);
117 
118 //
119 // define an Element from isotopes, by relative abundance
120 //
121 
122 G4Isotope* U5 = new G4Isotope("U235", iz=92, n=235, a=235.01*g/mole);
123 G4Isotope* U8 = new G4Isotope("U238", iz=92, n=238, a=238.03*g/mole);
124 
125 G4Element* U = new G4Element("enriched Uranium",symbol="U",ncomponents=2);
126 U->AddIsotope(U5, abundance= 90.*perCent);
127 U->AddIsotope(U8, abundance= 10.*perCent);
128 
129 //
130 // define simple materials
131 //
132 
133 new G4Material("Aluminium", z=13., a=26.98*g/mole, density=2.700*g/cm3);
134 new G4Material("liquidArgon", z=18., a= 39.95*g/mole, density= 1.390*g/cm3);
135 new G4Material("Lead" , z=82., a= 207.19*g/mole, density= 11.35*g/cm3);
136 
137 //
138 // define a material from elements. case 1: chemical molecule
139 //
140 
141 G4Material* H2O =
142 new G4Material("Water", density= 1.000*g/cm3, ncomponents=2);
143 H2O->AddElement(H, natoms=2);
144 H2O->AddElement(O, natoms=1);
145 // overwrite computed meanExcitationEnergy with ICRU recommended value
147 
148 G4Material* Sci =
149 new G4Material("Scintillator", density= 1.032*g/cm3, ncomponents=2);
150 Sci->AddElement(C, natoms=9);
151 Sci->AddElement(H, natoms=10);
152 
153 G4Material* Myl =
154 new G4Material("Mylar", density= 1.397*g/cm3, ncomponents=3);
155 Myl->AddElement(C, natoms=10);
156 Myl->AddElement(H, natoms= 8);
157 Myl->AddElement(O, natoms= 4);
158 
159 G4Material* SiO2 =
160 new G4Material("quartz",density= 2.200*g/cm3, ncomponents=2);
161 SiO2->AddElement(Si, natoms=1);
162 SiO2->AddElement(O , natoms=2);
163 
164 //
165 // define a material from elements. case 2: mixture by fractional mass
166 //
167 
168 G4Material* Air =
169 new G4Material("Air" , density= 1.290*mg/cm3, ncomponents=2);
170 Air->AddElement(N, fractionmass=0.7);
171 Air->AddElement(O, fractionmass=0.3);
172 
173 //
174 // define a material from elements and/or others materials (mixture of mixtures)
175 //
176 
177 G4Material* Aerog =
178 new G4Material("Aerogel", density= 0.200*g/cm3, ncomponents=3);
179 Aerog->AddMaterial(SiO2, fractionmass=62.5*perCent);
180 Aerog->AddMaterial(H2O , fractionmass=37.4*perCent);
181 Aerog->AddElement (C , fractionmass= 0.1*perCent);
182 
183 //
184 // examples of gas in non STP conditions
185 //
186 
187 G4Material* CO2 =
188 new G4Material("CarbonicGas", density= 27.*mg/cm3, ncomponents=2,
189  kStateGas, 325.*kelvin, 50.*atmosphere);
190 CO2->AddElement(C, natoms=1);
191 CO2->AddElement(O, natoms=2);
192 
193 G4Material* steam =
194 new G4Material("WaterSteam", density= 0.3*mg/cm3, ncomponents=1,
195  kStateGas, 500.*kelvin, 2.*atmosphere);
196 steam->AddMaterial(H2O, fractionmass=1.);
197 
198 //
199 // examples of vacuum
200 //
201 
202 G4Material* Vacuum =
203 new G4Material("Galactic", z=1., a=1.01*g/mole,density= universe_mean_density,
204  kStateGas, 2.73*kelvin, 3.e-18*pascal);
205 
206 G4Material* beam =
207 new G4Material("Beam", density= 1.e-5*g/cm3, ncomponents=1,
209 beam->AddMaterial(Air, fractionmass=1.);
210 
212 
213 //default materials of the World
214 defaultMaterial = Vacuum;
215 }
216 
217 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
218 
219 G4VPhysicalVolume* ExN03DetectorConstruction::ConstructCalorimeter()
220 {
221 
222  // Clean old geometry, if any
223  //
228 
229  // complete the Calor parameters definition
230  ComputeCalorParameters();
231 
232  //
233  // World
234  //
235  solidWorld = new G4Box("World", //its name
236  WorldSizeX/2,WorldSizeYZ/2,WorldSizeYZ/2); //its size
237 
238  logicWorld = new G4LogicalVolume(solidWorld, //its solid
239  defaultMaterial, //its material
240  "World"); //its name
241 
242  physiWorld = new G4PVPlacement(0, //no rotation
243  G4ThreeVector(), //at (0,0,0)
244  logicWorld, //its logical volume
245  "World", //its name
246  0, //its mother volume
247  false, //no boolean operation
248  0); //copy number
249 
250  //
251  // Calorimeter
252  //
253  solidCalor=0; logicCalor=0; physiCalor=0;
254  solidLayer=0; logicLayer=0; physiLayer=0;
255 
256  if (CalorThickness > 0.)
257  { solidCalor = new G4Box("Calorimeter", //its name
258  CalorThickness/2,CalorSizeYZ/2,CalorSizeYZ/2);//size
259 
260  logicCalor = new G4LogicalVolume(solidCalor, //its solid
261  defaultMaterial, //its material
262  "Calorimeter"); //its name
263 
264  physiCalor = new G4PVPlacement(0, //no rotation
265  G4ThreeVector(), //at (0,0,0)
266  logicCalor, //its logical volume
267  "Calorimeter", //its name
268  logicWorld, //its mother volume
269  false, //no boolean operation
270  0); //copy number
271 
272  //
273  // Layer
274  //
275  solidLayer = new G4Box("Layer", //its name
276  LayerThickness/2,CalorSizeYZ/2,CalorSizeYZ/2); //size
277 
278  logicLayer = new G4LogicalVolume(solidLayer, //its solid
279  defaultMaterial, //its material
280  "Layer"); //its name
281  if (NbOfLayers > 1)
282  physiLayer = new G4PVReplica("Layer", //its name
283  logicLayer, //its logical volume
284  logicCalor, //its mother
285  kXAxis, //axis of replication
286  NbOfLayers, //number of replica
287  LayerThickness); //witdth of replica
288  else
289  physiLayer = new G4PVPlacement(0, //no rotation
290  G4ThreeVector(), //at (0,0,0)
291  logicLayer, //its logical volume
292  "Layer", //its name
293  logicCalor, //its mother volume
294  false, //no boolean operation
295  0); //copy number
296  }
297 
298  //
299  // Absorber
300  //
301  solidAbsorber=0; logicAbsorber=0; physiAbsorber=0;
302 
303  if (AbsorberThickness > 0.)
304  { solidAbsorber = new G4Box("Absorber", //its name
305  AbsorberThickness/2,CalorSizeYZ/2,CalorSizeYZ/2);
306 
307  logicAbsorber = new G4LogicalVolume(solidAbsorber, //its solid
308  AbsorberMaterial, //its material
309  AbsorberMaterial->GetName()); //name
310 
311  physiAbsorber = new G4PVPlacement(0, //no rotation
312  G4ThreeVector(-GapThickness/2,0.,0.), //its position
313  logicAbsorber, //its logical volume
314  AbsorberMaterial->GetName(), //its name
315  logicLayer, //its mother
316  false, //no boulean operat
317  0); //copy number
318 
319  }
320 
321  //
322  // Gap
323  //
324  solidGap=0; logicGap=0; physiGap=0;
325 
326  if (GapThickness > 0.)
327  { solidGap = new G4Box("Gap",
328  GapThickness/2,CalorSizeYZ/2,CalorSizeYZ/2);
329 
330  logicGap = new G4LogicalVolume(solidGap,
331  GapMaterial,
332  GapMaterial->GetName());
333 
334  physiGap = new G4PVPlacement(0, //no rotation
335  G4ThreeVector(AbsorberThickness/2,0.,0.), //its position
336  logicGap, //its logical volume
337  GapMaterial->GetName(), //its name
338  logicLayer, //its mother
339  false, //no boulean operat
340  0); //copy number
341  }
342 
344 
345  //
346  // Visualization attributes
347  //
349 
350  G4VisAttributes* simpleBoxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0));
351  simpleBoxVisAtt->SetVisibility(true);
352  logicCalor->SetVisAttributes(simpleBoxVisAtt);
353 
354  /*
355  // Below are vis attributes that permits someone to test / play
356  // with the interactive expansion / contraction geometry system of the
357  // vis/OpenInventor driver :
358  {G4VisAttributes* simpleBoxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,0.0));
359  simpleBoxVisAtt->SetVisibility(true);
360  delete logicCalor->GetVisAttributes();
361  logicCalor->SetVisAttributes(simpleBoxVisAtt);}
362 
363  {G4VisAttributes* atb= new G4VisAttributes(G4Colour(1.0,0.0,0.0));
364  logicLayer->SetVisAttributes(atb);}
365 
366  {G4VisAttributes* atb= new G4VisAttributes(G4Colour(0.0,1.0,0.0));
367  atb->SetForceSolid(true);
368  logicAbsorber->SetVisAttributes(atb);}
369 
370  {//Set opacity = 0.2 then transparency = 1 - 0.2 = 0.8
371  G4VisAttributes* atb= new G4VisAttributes(G4Colour(0.0,0.0,1.0,0.2));
372  atb->SetForceSolid(true);
373  logicGap->SetVisAttributes(atb);}
374  */
375 
376  //
377  //always return the physical World
378  //
379  return physiWorld;
380 }
381 
382 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
383 
385 {
386  G4cout << "\n------------------------------------------------------------"
387  << "\n---> The calorimeter is " << NbOfLayers << " layers of: [ "
388  << AbsorberThickness/mm << "mm of " << AbsorberMaterial->GetName()
389  << " + "
390  << GapThickness/mm << "mm of " << GapMaterial->GetName() << " ] "
391  << "\n------------------------------------------------------------\n";
392 }
393 
394 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
395 
397 {
398  // search the material by its name
399  G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
400  if (pttoMaterial) AbsorberMaterial = pttoMaterial;
401 }
402 
403 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
404 
406 {
407  // search the material by its name
408  G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
409  if (pttoMaterial) GapMaterial = pttoMaterial;
410 }
411 
412 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
413 
415 {
416  // change Absorber thickness and recompute the calorimeter parameters
417  AbsorberThickness = val;
418 }
419 
420 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
421 
423 {
424  // change Gap thickness and recompute the calorimeter parameters
425  GapThickness = val;
426 }
427 
428 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
429 
431 {
432  // change the transverse size and recompute the calorimeter parameters
433  CalorSizeYZ = val;
434 }
435 
436 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
437 
439 {
440  NbOfLayers = val;
441 }
442 
443 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
444 
445 #include "G4FieldManager.hh"
447 
449 {
450  //apply a global uniform magnetic field along Z axis
451  G4FieldManager* fieldMgr
453 
454  if(magField) delete magField; //delete the existing magn field
455 
456  if(fieldValue!=0.) // create a new one if non nul
457  { magField = new G4UniformMagField(G4ThreeVector(0.,0.,fieldValue));
458  fieldMgr->SetDetectorField(magField);
459  fieldMgr->CreateChordFinder(magField);
460  } else {
461  magField = 0;
462  fieldMgr->SetDetectorField(magField);
463  }
464 }
465 
466 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
467 
468 #include "G4RunManager.hh"
469 
471 {
472  G4RunManager::GetRunManager()->DefineWorldVolume(ConstructCalorimeter());
473 }
474 
475 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......