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 "G4Sphere.hh"
39 #include "G4LogicalVolume.hh"
40 #include "G4VPhysicalVolume.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 "G4UnitsTable.hh"
51 #include "G4PhysicalConstants.hh"
52 #include "G4SystemOfUnits.hh"
53 
54 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
55 
57 {
58  // default parameter values
59  fAbsorRadius = 3*cm;
60  fNbOfLayers = 1;
61 
62  fAbsorMaterial = 0;
63  fMagField = 0;
64  fAbsor = 0;
65 
66  DefineMaterials();
67  SetMaterial("G4_WATER");
68 
69  // create commands for interactive definition of the detector
70  fDetectorMessenger = new DetectorMessenger(this);
71 }
72 
73 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
74 
76 { delete fDetectorMessenger;}
77 
78 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
79 
81 {
82  return ConstructVolumes();
83 }
84 
85 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
86 
87 void DetectorConstruction::DefineMaterials()
88 {
90 
91  G4bool isotopes = false;
92 
93  man->FindOrBuildMaterial("G4_Al", isotopes);
94  man->FindOrBuildMaterial("G4_Si", isotopes);
95  man->FindOrBuildMaterial("G4_Fe", isotopes);
96  man->FindOrBuildMaterial("G4_Ge", isotopes);
97  man->FindOrBuildMaterial("G4_W" , isotopes);
98  man->FindOrBuildMaterial("G4_Pb", isotopes);
99 
100  man->FindOrBuildMaterial("G4_AIR" , isotopes);
101  man->FindOrBuildMaterial("G4_WATER", isotopes);
102 
104 }
105 
106 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
107 
108 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
109 {
114 
115  // Absorber
116  //
117  G4Sphere*
118  sAbsor = new G4Sphere("Absorber", //name
119  0., fAbsorRadius, 0., twopi, 0., pi); //size
120 
122  lAbsor = new G4LogicalVolume(sAbsor, //solid
123  fAbsorMaterial, //material
124  "Absorber"); //name
125 
126  fAbsor = new G4PVPlacement(0, //no rotation
127  G4ThreeVector(), //at (0,0,0)
128  lAbsor, //logical volume
129  "Absorber", //name
130  0, //mother volume
131  false, //no boolean operation
132  0); //copy number
133 
134  // Layers
135  //
136  fLayerThickness = fAbsorRadius/fNbOfLayers;
137 
138  for (G4int i=1; i<=fNbOfLayers; i++) {
139  G4Sphere*
140  sLayer = new G4Sphere("Layer", (i-1)*fLayerThickness, i*fLayerThickness,
141  0., twopi, 0., pi);
142 
144  lLayer = new G4LogicalVolume(sLayer, //shape
145  fAbsorMaterial, //material
146  "Layer"); //name
147 
148  new G4PVPlacement(0, //no rotation
149  G4ThreeVector(), //at (0,0,0)
150  lLayer, //logical volume
151  "Layer", //name
152  lAbsor, //mother volume
153  false, //no boolean operation
154  i); //copy number
155 
156  }
157 
158  PrintParameters();
159 
160  //
161  //always return the root volume
162  //
163  return fAbsor;
164 }
165 
166 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
167 
169 {
170  G4cout << "\n---------------------------------------------------------\n";
171  G4cout << "---> The Absorber is a sphere of "
172  << G4BestUnit(fAbsorRadius,"Length") << " radius of "
173  << fAbsorMaterial->GetName() << " divided in " << fNbOfLayers
174  << " slices of " << G4BestUnit(fLayerThickness,"Length") << G4endl;
175  G4cout << "\n---------------------------------------------------------\n";
176 }
177 
178 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
179 
181 {
182  fAbsorRadius = value;
183 }
184 
185 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
186 
187 void DetectorConstruction::SetMaterial(G4String materialChoice)
188 {
189  // search the material by its name
190  G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
191  if (pttoMaterial) fAbsorMaterial = pttoMaterial;
192 }
193 
194 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
195 
197 {
198  fNbOfLayers = value;
199 }
200 
201 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
202 
203 #include "G4FieldManager.hh"
205 
207 {
208  //apply a global uniform magnetic field along Z axis
209  G4FieldManager* fieldMgr
211 
212  if (fMagField) delete fMagField; //delete the existing magn field
213 
214  if (fieldValue!=0.) // create a new one if non nul
215  {
216  fMagField = new G4UniformMagField(G4ThreeVector(0.,0.,fieldValue));
217  fieldMgr->SetDetectorField(fMagField);
218  fieldMgr->CreateChordFinder(fMagField);
219  }
220  else
221  {
222  fMagField = 0;
223  fieldMgr->SetDetectorField(fMagField);
224  }
225 }
226 
227 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
228 
229 #include "G4RunManager.hh"
230 
232 {
233 G4RunManager::GetRunManager()->DefineWorldVolume(ConstructVolumes());
234 }
235 
236 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......