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 "G4Material.hh"
38 #include "G4Box.hh"
39 #include "G4LogicalVolume.hh"
40 #include "G4PVPlacement.hh"
41 #include "G4UniformMagField.hh"
42 #include "G4UserLimits.hh"
43 
44 #include "G4GeometryManager.hh"
45 #include "G4PhysicalVolumeStore.hh"
46 #include "G4LogicalVolumeStore.hh"
47 #include "G4SolidStore.hh"
48 
49 #include "G4UnitsTable.hh"
50 #include "G4SystemOfUnits.hh"
51 
52 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
53 
55 :fP_Box(0), fL_Box(0), fBoxSize(500*m), fMaterial(0), fMagField(0)
56 {
57  DefineMaterials();
58  SetMaterial("Iron");
59 
60  // create UserLimits
61  fUserLimits = new G4UserLimits();
62 
63  // create commands for interactive definition of the detector
64  fDetectorMessenger = new DetectorMessenger(this);
65 }
66 
67 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
68 
70 { delete fDetectorMessenger;}
71 
72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
73 
75 {
76  return ConstructVolumes();
77 }
78 
79 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
80 
81 void DetectorConstruction::DefineMaterials()
82 {
83  G4double a, z, density;
84 
85  new G4Material("Beryllium", z= 4., a= 9.012182*g/mole, density= 1.848*g/cm3);
86  new G4Material("Carbon", z= 6., a= 12.011*g/mole, density= 2.265*g/cm3);
87  new G4Material("Iron", z=26., a= 55.85*g/mole, density= 7.870*g/cm3);
88 
90 }
91 
92 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
93 
94 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
95 {
100 
101  G4Box*
102  sBox = new G4Box("Container", //its name
103  fBoxSize/2,fBoxSize/2,fBoxSize/2); //its dimensions
104 
105  fL_Box = new G4LogicalVolume(sBox, //its shape
106  fMaterial, //its material
107  fMaterial->GetName()); //its name
108 
109  fL_Box->SetUserLimits(fUserLimits);
110 
111  fP_Box = new G4PVPlacement(0, //no rotation
112  G4ThreeVector(), //at (0,0,0)
113  fL_Box, //its logical volume
114  fMaterial->GetName(), //its name
115  0, //its mother volume
116  false, //no boolean operation
117  0); //copy number
118 
119  PrintParameters();
120 
121  //
122  //always return the root volume
123  //
124  return fP_Box;
125 }
126 
127 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
128 
130 {
131  G4cout << "\n The Box is " << G4BestUnit(fBoxSize,"Length")
132  << " of " << fMaterial->GetName() << G4endl;
133 }
134 
135 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
136 
137 void DetectorConstruction::SetMaterial(G4String materialChoice)
138 {
139  // search the material by its name
140  G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
141  if (pttoMaterial) fMaterial = pttoMaterial;
142 }
143 
144 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
145 
147 {
148  fBoxSize = value;
149 }
150 
151 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
152 
153 #include "G4FieldManager.hh"
155 
157 {
158  //apply a global uniform magnetic field along Z axis
159  G4FieldManager* fieldMgr
161 
162  if (fMagField) delete fMagField; //delete the existing magn field
163 
164  if (fieldValue!=0.) // create a new one if non nul
165  {
166  fMagField = new G4UniformMagField(G4ThreeVector(0.,0.,fieldValue));
167  fieldMgr->SetDetectorField(fMagField);
168  fieldMgr->CreateChordFinder(fMagField);
169  }
170  else
171  {
172  fMagField = 0;
173  fieldMgr->SetDetectorField(fMagField);
174  }
175 }
176 
177 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
178 
180 {
181  // set the maximum allowed step size
182  //
183  if (val <= DBL_MIN)
184  { G4cout << "\n --->warning from SetMaxStepSize: maxStep "
185  << val << " out of range. Command refused" << G4endl;
186  return;
187  }
188  fUserLimits->SetMaxAllowedStep(val);
189 }
190 
191 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
192 
193 #include "G4RunManager.hh"
194 
196 {
197  G4RunManager::GetRunManager()->DefineWorldVolume(ConstructVolumes());
198 }
199 
200 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......