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: DetectorConstruction.cc 66995 2013-01-29 14:46:45Z 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 "G4NistManager.hh"
49 #include "G4UnitsTable.hh"
50 
51 #include "G4FieldManager.hh"
53 #include "G4RunManager.hh"
54 
55 #include "G4PhysicalConstants.hh"
56 #include "G4SystemOfUnits.hh"
57 
58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
59 
61 {
62  // default parameter values
63  fAbsorSizeX = fAbsorSizeYZ = 20*cm;
64  fWorldSizeX = fWorldSizeYZ = 1.2*fAbsorSizeX;
65 
66  fWorldMaterial = fAbsorMaterial = 0;
67  fMagField = 0;
68  fLAbsor = 0;
69 
70  fTallyNumber = 0;
71  for (G4int j=0; j<MaxTally; j++) {
72  fTallySize[j] = fTallyPosition[j] = G4ThreeVector();
73  fTallyMaterial[j] = 0;
74  fTallyMass[j] = 0.;
75  fLTally[j] = 0;
76  }
77 
78  DefineMaterials();
79  SetMaterial("Water");
80  for (G4int j=0; j<MaxTally; j++) { SetTallyMaterial(j,"Water");};
81 
82  // create commands for interactive definition of the detector
83  fDetectorMessenger = new DetectorMessenger(this);
84 }
85 
86 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
87 
89 { delete fDetectorMessenger;}
90 
91 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
92 
94 {
95  return ConstructVolumes();
96 }
97 
98 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
99 
100 void DetectorConstruction::DefineMaterials()
101 {
102  //
103  // define Elements
104  //
105  G4double z, a;
106 
107  G4Element* H = new G4Element("Hydrogen", "H", z= 1, a= 1.008*g/mole);
108  G4Element* N = new G4Element("Nitrogen", "N", z= 7, a= 14.01*g/mole);
109  G4Element* O = new G4Element("Oxygen" , "O", z= 8, a= 16.00*g/mole);
110 
111  //
112  // define Materials.
113  //
114  G4double density, temperature, pressure;
115  G4int ncomponents, natoms;
116  G4double fractionmass;
117 
118  G4Material* H2O =
119  new G4Material("Water", density= 1.0*g/cm3, ncomponents=2);
120  H2O->AddElement(H, natoms=2);
121  H2O->AddElement(O, natoms=1);
123 
124  // In this line both G4_WATER and Water_1.05 will be constructed
126  BuildMaterialWithNewDensity("Water_1.05","G4_WATER",1.05*g/cm3);
127 
128  G4Material* Air =
129  new G4Material("Air" , density= 1.290*mg/cm3, ncomponents=2);
130  Air->AddElement(N, fractionmass=0.7);
131  Air->AddElement(O, fractionmass=0.3);
132 
133  density = 1.e-5*g/cm3;
134  pressure = 2.e-2*bar;
135  temperature = STP_Temperature; // From PhysicalConstants.h .
136  G4Material* vac = new G4Material( "TechVacuum", density, 1,
137  kStateGas, temperature, pressure );
138  vac->AddMaterial( Air, 1. );
139 
140  density = universe_mean_density; //from PhysicalConstants.h
141  pressure = 3.e-18*pascal;
142  temperature = 2.73*kelvin;
143  G4Material* vacuum =
144  new G4Material("Galactic",z= 1,a= 1.008*g/mole,density,
145  kStateGas,temperature,pressure);
146 
147  //default materials
148  fWorldMaterial = vacuum;
149 }
150 
151 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
152 
153 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
154 {
159 
160  // World
161  //
162  G4Box*
163  sWorld = new G4Box("World", //name
164  fWorldSizeX/2,fWorldSizeYZ/2,fWorldSizeYZ/2); //dimensions
165 
167  lWorld = new G4LogicalVolume(sWorld, //shape
168  fWorldMaterial, //material
169  "World"); //name
170 
172  pWorld = new G4PVPlacement(0, //no rotation
173  G4ThreeVector(), //at (0,0,0)
174  lWorld, //logical volume
175  "World", //name
176  0, //mother volume
177  false, //no boolean operation
178  0); //copy number
179  //
180  // Absorber
181  //
182  G4Box*
183  sAbsor = new G4Box("Absorber", //name
184  fAbsorSizeX/2,fAbsorSizeYZ/2,fAbsorSizeYZ/2); //dimensions
185 
186  fLAbsor = new G4LogicalVolume(sAbsor, //shape
187  fAbsorMaterial, //material
188  "Absorber"); //name
189 
190 
191  new G4PVPlacement(0, //no rotation
192  G4ThreeVector(), //at (0,0,0)
193  fLAbsor, //logical volume
194  "Absorber", //name
195  lWorld, //mother volume
196  false, //no boolean operation
197  0); //copy number
198  //
199  // Tallies (optional)
200  //
201  if (fTallyNumber > 0) {
202  for (G4int j=1; j<=fTallyNumber; j++) {
203 
204  G4Box* sTally = new G4Box("Tally",
205  fTallySize[j].x()/2,fTallySize[j].y()/2,fTallySize[j].z()/2);
206 
207  fLTally[j] = new G4LogicalVolume(sTally,fTallyMaterial[j],"Tally");
208 
209  new G4PVPlacement(0, //no rotation
210  fTallyPosition[j], //position
211  fLTally[j], //logical volume
212  "Tally", //name
213  fLAbsor, //mother volume
214  false, //no boolean operation
215  j); //copy number
216 
217  fTallyMass[j] = fTallySize[j].x()*fTallySize[j].y()*fTallySize[j].z()
218  *(fTallyMaterial[j]->GetDensity());
219  }
220  }
221 
222  PrintParameters();
223 
224  //
225  //always return the World volume
226  //
227  return pWorld;
228 }
229 
230 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
231 
233 {
235  G4cout << "\n---------------------------------------------------------\n";
236  G4cout << "---> The Absorber is " << G4BestUnit(fAbsorSizeX,"Length")
237  << " of " << fAbsorMaterial->GetName() << G4endl;
238  G4cout << "\n---------------------------------------------------------\n";
239 
240  if (fTallyNumber > 0) {
241  G4cout << "---> There are " << fTallyNumber << " tallies : " << G4endl;
242  for (G4int j=1; j<=fTallyNumber; j++) {
243  G4cout << "fTally " << j << ": "
244  << fTallyMaterial[j]->GetName()
245  << ", mass = " << G4BestUnit(fTallyMass[j],"Mass")
246  << " size = " << G4BestUnit(fTallySize[j],"Length")
247  << " position = " << G4BestUnit(fTallyPosition[j],"Length")
248  << G4endl;
249  }
250  G4cout << "\n---------------------------------------------------------\n";
251  }
252 }
253 
254 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
255 
257 {
258  fAbsorSizeX = value; fWorldSizeX = 1.2*fAbsorSizeX;
260 }
261 
262 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
263 
265 {
266  fAbsorSizeYZ = value;
267  fWorldSizeYZ = 1.2*fAbsorSizeYZ;
269 }
270 
271 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
272 
273 void DetectorConstruction::SetMaterial(G4String materialChoice)
274 {
275  // search the material by its name
276  G4Material* pttoMaterial =
277  G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
278  if (pttoMaterial) {
279  fAbsorMaterial = pttoMaterial;
280  if(fLAbsor) {
281  fLAbsor->SetMaterial(fAbsorMaterial);
283  }
284  }
285 }
286 
287 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
288 
290 {
291  //apply a global uniform magnetic field along Z axis
292  G4FieldManager* fieldMgr
294 
295  if (fMagField) delete fMagField; //delete the existing magn field
296 
297  if (fieldValue!=0.) // create a new one if non nul
298  {
299  fMagField = new G4UniformMagField(G4ThreeVector(0.,0.,fieldValue));
300  fieldMgr->SetDetectorField(fMagField);
301  fieldMgr->CreateChordFinder(fMagField);
302  }
303  else
304  {
305  fMagField = 0;
306  fieldMgr->SetDetectorField(fMagField);
307  }
308 }
309 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
310 
312 {
313  fTallyNumber = value;
314 }
315 
316 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
317 
319 {
320  fTallySize[j] = value;
322 }
323 
324 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
325 
327 {
328  // search the material by its name
329  G4Material* pttoMaterial =
330  G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
331  if (pttoMaterial) {
332  fTallyMaterial[j] = pttoMaterial;
333  if(fLTally[j]) {
334  fLTally[j]->SetMaterial(fTallyMaterial[j]);
336  }
337  }
338 }
339 
340 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
341 
343 {
344 
345  fTallyPosition[j] = value;
347 }
348 
349 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
350 
352 {
354  G4RunManager::GetRunManager()->DefineWorldVolume(ConstructVolumes());
355 }
356 
357 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......