Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
examples/extended/electromagnetic/TestEm12/src/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 //
26 /// \file electromagnetic/TestEm12/src/DetectorConstruction.cc
27 /// \brief Implementation of the DetectorConstruction class
28 //
29 // $Id: DetectorConstruction.cc 68385 2013-03-23 14:07:15Z maire $
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 
58  fAbsorMaterial(0),
59  fMagField(0),
60  fAbsor(0),
61  fDetectorMessenger(0)
62 {
63  // default parameter values
64  fAbsorRadius = 3*cm;
65  fNbOfLayers = 1;
66 
67  DefineMaterials();
68  SetMaterial("G4_WATER");
69 
70  // create commands for interactive definition of the detector
71  fDetectorMessenger = new DetectorMessenger(this);
72 }
73 
74 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
75 
77 { delete fDetectorMessenger;}
78 
79 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
80 
82 {
83  return ConstructVolumes();
84 }
85 
86 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
87 
88 void DetectorConstruction::DefineMaterials()
89 {
91 
92  man->FindOrBuildMaterial("G4_Al");
93  man->FindOrBuildMaterial("G4_Si");
94  man->FindOrBuildMaterial("G4_Fe");
95  man->FindOrBuildMaterial("G4_Ge");
96  man->FindOrBuildMaterial("G4_W");
97  man->FindOrBuildMaterial("G4_Pb");
98 
99  man->FindOrBuildMaterial("G4_AIR");
100  man->FindOrBuildMaterial("G4_WATER");
101 
102  ///G4cout << *(G4Material::GetMaterialTable()) << G4endl;
103 }
104 
105 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
106 
107 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
108 {
113 
114  // Absorber
115  //
116  G4Sphere*
117  sAbsor = new G4Sphere("Absorber", //name
118  0., fAbsorRadius, 0., twopi, 0., pi); //size
119 
121  lAbsor = new G4LogicalVolume(sAbsor, //solid
122  fAbsorMaterial, //material
123  "Absorber"); //name
124 
125  fAbsor = new G4PVPlacement(0, //no rotation
126  G4ThreeVector(), //at (0,0,0)
127  lAbsor, //logical volume
128  "Absorber", //name
129  0, //mother volume
130  false, //no boolean operation
131  0); //copy number
132 
133  // Layers
134  //
135  fLayerThickness = fAbsorRadius/fNbOfLayers;
136 
137  for (G4int i=1; i<=fNbOfLayers; i++) {
138  G4Sphere*
139  sLayer = new G4Sphere("Layer", (i-1)*fLayerThickness, i*fLayerThickness,
140  0., twopi, 0., pi);
141 
143  lLayer = new G4LogicalVolume(sLayer, //shape
144  fAbsorMaterial, //material
145  "Layer"); //name
146 
147  new G4PVPlacement(0, //no rotation
148  G4ThreeVector(), //at (0,0,0)
149  lLayer, //logical volume
150  "Layer", //name
151  lAbsor, //mother volume
152  false, //no boolean operation
153  i); //copy number
154 
155  }
156 
157  PrintParameters();
158 
159  //
160  //always return the root volume
161  //
162  return fAbsor;
163 }
164 
165 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
166 
168 {
169  G4cout << "\n---------------------------------------------------------\n";
170  G4cout << "---> The Absorber is a sphere of "
171  << G4BestUnit(fAbsorRadius,"Length") << " radius of "
172  << fAbsorMaterial->GetName() << " divided in " << fNbOfLayers
173  << " slices of " << G4BestUnit(fLayerThickness,"Length")
174  << "\n \n" << fAbsorMaterial << 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......
G4Material * FindOrBuildMaterial(const G4String &name, G4bool isotopes=true, G4bool warning=false)
CLHEP::Hep3Vector G4ThreeVector
G4bool SetDetectorField(G4Field *detectorField)
static G4Material * GetMaterial(const G4String &name, G4bool warning=true)
Definition: G4Material.cc:578
const G4String & GetName() const
Definition: G4Material.hh:176
static void Clean()
Definition: G4SolidStore.cc:79
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
int G4int
Definition: G4Types.hh:78
static G4NistManager * Instance()
virtual void DefineWorldVolume(G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
static G4PhysicalVolumeStore * GetInstance()
G4GLOB_DLL std::ostream G4cout
static G4LogicalVolumeStore * GetInstance()
static G4SolidStore * GetInstance()
static G4GeometryManager * GetInstance()
static G4TransportationManager * GetTransportationManager()
G4FieldManager * GetFieldManager() const
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:74
const XML_Char int const XML_Char * value
#define G4endl
Definition: G4ios.hh:61
void OpenGeometry(G4VPhysicalVolume *vol=0)
double G4double
Definition: G4Types.hh:76
void CreateChordFinder(G4MagneticField *detectorMagField)