Geant4  9.6.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$
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 #include "G4UniformMagField.hh"
44 
45 #include "G4GeometryManager.hh"
46 #include "G4PhysicalVolumeStore.hh"
47 #include "G4LogicalVolumeStore.hh"
48 #include "G4SolidStore.hh"
49 
50 #include "G4UImanager.hh"
51 #include "G4UnitsTable.hh"
52 #include "G4PhysicalConstants.hh"
53 #include "G4SystemOfUnits.hh"
54 #include <iomanip>
55 
56 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
57 
59 :fDefaultMaterial(0),fPhysiWorld(0),fMagField(0)
60 {
61  // default parameter values of the absorbers
62  fNbOfAbsor = 1;
63  fAbsorThickness[0] = 0*mm; //dummy, for initialization
64  fAbsorThickness[1] = 1*mm;
65  fAbsorSizeYZ = 1.*mm;
66  for (G4int iAbs=0; iAbs<MaxAbsor; iAbs++) {
67  fNbOfDivisions[iAbs] = 1;
68  }
69  ComputeParameters();
70 
71  // materials
72  DefineMaterials();
73  SetAbsorMaterial(1,"G4_Si");
74 
75  // create commands for interactive definition of the calorimeter
76  fDetectorMessenger = new DetectorMessenger(this);
77 }
78 
79 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
80 
82 {
83  delete fDetectorMessenger;
84 }
85 
86 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
87 
89 {
90  return ConstructVolumes();
91 }
92 
93 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
94 
95 void DetectorConstruction::DefineMaterials()
96 {
98 
99  G4bool isotopes = false;
100 
101  man->FindOrBuildMaterial("G4_Al", isotopes);
102  man->FindOrBuildMaterial("G4_Si", isotopes);
103  man->FindOrBuildMaterial("G4_Fe", isotopes);
104  man->FindOrBuildMaterial("G4_Cu", isotopes);
105  man->FindOrBuildMaterial("G4_Ge", isotopes);
106  man->FindOrBuildMaterial("G4_Mo", isotopes);
107  man->FindOrBuildMaterial("G4_Ta", isotopes);
108  man->FindOrBuildMaterial("G4_W" , isotopes);
109  man->FindOrBuildMaterial("G4_Au", isotopes);
110  man->FindOrBuildMaterial("G4_Pb", isotopes);
111  man->FindOrBuildMaterial("G4_PbWO4", isotopes);
112  man->FindOrBuildMaterial("G4_SODIUM_IODIDE", isotopes);
113 
114  man->FindOrBuildMaterial("G4_AIR" , isotopes);
115  man->FindOrBuildMaterial("G4_WATER", isotopes);
116 
117  G4Element* H = man->FindOrBuildElement("H", isotopes);
118  G4Element* O = man->FindOrBuildElement("O", isotopes);
119 
120  G4Material* H2O =
121  new G4Material("Water", 1.000*g/cm3, 2);
122  H2O->AddElement(H, 2);
123  H2O->AddElement(O, 1);
125 
126  G4double density = universe_mean_density; //from PhysicalConstants.h
127  G4double pressure = 3.e-18*pascal;
128  G4double temperature = 2.73*kelvin;
129  G4Material* Galactic =
130  new G4Material("Galactic", 1., 1.008*g/mole, density,
131  kStateGas,temperature,pressure);
132 
133  fDefaultMaterial = Galactic;
134 
135  // G4cout << *(G4Material::GetMaterialTable()) << G4endl;
136 }
137 
138 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
139 
140 void DetectorConstruction::ComputeParameters()
141 {
142  // Compute total thickness of absorbers
143  fAbsorSizeX = 0.;
144  for (G4int iAbs=1; iAbs<=fNbOfAbsor; iAbs++) {
145  fAbsorSizeX += fAbsorThickness[iAbs];
146  }
147 }
148 
149 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
150 
151 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
152 {
153  // complete the Calor parameters definition
154  ComputeParameters();
155 
156  // Cleanup old geometry
161 
162  //
163  // World
164  //
165  G4Box* solidWorld =
166  new G4Box("World", //name
167  fAbsorSizeX/2,fAbsorSizeYZ/2,fAbsorSizeYZ/2); //size
168 
169  G4LogicalVolume* logicWorld =
170  new G4LogicalVolume(solidWorld, //solid
171  fDefaultMaterial, //material
172  "World"); //name
173 
174  fPhysiWorld =
175  new G4PVPlacement(0, //no rotation
176  G4ThreeVector(), //at (0,0,0)
177  logicWorld, //logical volume
178  "World", //name
179  0, //mother volume
180  false, //no boolean operation
181  0); //copy number
182 
183  //
184  // Absorbers
185  //
186  fXfront[0] = -0.5*fAbsorSizeX;
187  //
188  for (G4int k=1; k<=fNbOfAbsor; k++) {
189  G4Material* material = fAbsorMaterial[k];
190  G4String matname = material->GetName();
191 
192  G4Box* solidAbsor =
193  new G4Box(matname,fAbsorThickness[k]/2,fAbsorSizeYZ/2,fAbsorSizeYZ/2);
194 
195  G4LogicalVolume* logicAbsor =
196  new G4LogicalVolume(solidAbsor, // solid
197  material, // material
198  matname); // name
199 
200  fXfront[k] = fXfront[k-1] + fAbsorThickness[k-1];
201  G4double xcenter = fXfront[k]+0.5*fAbsorThickness[k];
202  G4ThreeVector position = G4ThreeVector(xcenter,0.,0.);
203 
204  new G4PVPlacement(0, //no rotation
205  position, //position
206  logicAbsor, //logical volume
207  matname, //name
208  logicWorld, //mother
209  false, //no boulean operat
210  k); //copy number
211 
212  // divisions, if any
213  //
214  G4double LayerThickness = fAbsorThickness[k]/fNbOfDivisions[k];
215  G4Box* solidLayer =
216  new G4Box(matname,LayerThickness/2,fAbsorSizeYZ/2,fAbsorSizeYZ/2);
217 
218  G4LogicalVolume* logicLayer =
219  new G4LogicalVolume(solidLayer, //solid
220  material, //material
221  matname); //name
222 
223  new G4PVReplica(matname, //name
224  logicLayer, //logical volume
225  logicAbsor, //mother
226  kXAxis, //axis of replication
227  fNbOfDivisions[k], //number of replica
228  LayerThickness); //witdth of replica
229  }
230 
231 
232  PrintParameters();
233 
234  //always return the physical World
235  //
236  return fPhysiWorld;
237 }
238 
239 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
240 
242 {
243  G4cout << "\n-------------------------------------------------------------"
244  << "\n ---> The Absorber is " << fNbOfAbsor << " layers of:";
245  for (G4int i=1; i<=fNbOfAbsor; i++)
246  {
247  G4cout << "\n \t" << std::setw(12) << fAbsorMaterial[i]->GetName() <<": "
248  << std::setw(6) << G4BestUnit(fAbsorThickness[i],"Length")
249  << " divided in " << fNbOfDivisions[i] << " slices";
250  }
251  G4cout << "\n-------------------------------------------------------------\n"
252  << G4endl;
253 }
254 
255 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
256 
258 {
259  // set the number of Absorbers
260  //
261  if (ival < 1 || ival > (MaxAbsor-1))
262  { G4cout << "\n ---> warning from SetfNbOfAbsor: "
263  << ival << " must be at least 1 and and most " << MaxAbsor-1
264  << ". Command refused" << G4endl;
265  return;
266  }
267  fNbOfAbsor = ival;
268 }
269 
270 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
271 
273 {
274  // search the material by its name
275  //
276  if (iabs > fNbOfAbsor || iabs <= 0)
277  { G4cout << "\n --->warning from SetfAbsorMaterial: absor number "
278  << iabs << " out of range. Command refused" << G4endl;
279  return;
280  }
281 
282  G4Material* pttoMaterial =
284  if (pttoMaterial) fAbsorMaterial[iabs] = pttoMaterial;
285 }
286 
287 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
288 
290 {
291  // change Absorber thickness
292  //
293  if (iabs > fNbOfAbsor || iabs <= 0)
294  { G4cout << "\n --->warning from SetfAbsorThickness: absor number "
295  << iabs << " out of range. Command refused" << G4endl;
296  return;
297  }
298  if (val <= DBL_MIN)
299  { G4cout << "\n --->warning from SetfAbsorThickness: thickness "
300  << val << " out of range. Command refused" << G4endl;
301  return;
302  }
303  fAbsorThickness[iabs] = val;
304 }
305 
306 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
307 
309 {
310  // change the transverse size
311  //
312  if (val <= DBL_MIN)
313  { G4cout << "\n --->warning from SetfAbsorSizeYZ: thickness "
314  << val << " out of range. Command refused" << G4endl;
315  return;
316  }
317  fAbsorSizeYZ = val;
318 }
319 
320 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
321 
323 {
324  // set the number of divisions
325  //
326  if (iabs > fNbOfAbsor || iabs < 1)
327  { G4cout << "\n --->warning from SetNbOfDivisions: absor number "
328  << iabs << " out of range. Command refused" << G4endl;
329  return;
330  }
331 
332  if (ival < 1)
333  { G4cout << "\n --->warning from SetNbOfDivisions: "
334  << ival << " must be at least 1. Command refused" << G4endl;
335  return;
336  }
337  fNbOfDivisions[iabs] = ival;
338 }
339 
340 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
341 
342 #include "G4FieldManager.hh"
344 
346 {
347  //apply a global uniform magnetic field along Z axis
348  //
349  G4FieldManager* fieldMgr
351 
352  if(fMagField) delete fMagField; //delete the existing magn field
353 
354  if(fieldValue!=0.) // create a new one if non nul
355  { fMagField = new G4UniformMagField(G4ThreeVector(0.,0.,fieldValue));
356  fieldMgr->SetDetectorField(fMagField);
357  fieldMgr->CreateChordFinder(fMagField);
358  } else {
359  fMagField = 0;
360  fieldMgr->SetDetectorField(fMagField);
361  }
362 }
363 
364 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
365 
366 #include "G4RunManager.hh"
367 
369 {
370  G4RunManager::GetRunManager()->DefineWorldVolume(ConstructVolumes());
371 }
372 
373 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......