source: trunk/examples/extended/electromagnetic/TestEm16/src/DetectorConstruction.cc@ 1036

Last change on this file since 1036 was 807, checked in by garnier, 17 years ago

update

File size: 7.5 KB
Line 
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// $Id: DetectorConstruction.cc,v 1.4 2007/01/18 09:07:20 hbu Exp $
27// GEANT4 tag $Name: $
28//
29//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
30//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
31
32#include "DetectorConstruction.hh"
33#include "DetectorMessenger.hh"
34
35#include "G4Material.hh"
36#include "G4Box.hh"
37#include "G4LogicalVolume.hh"
38#include "G4PVPlacement.hh"
39#include "G4UniformMagField.hh"
40#include "G4PropagatorInField.hh"
41#include "G4UserLimits.hh"
42
43#include "G4GeometryManager.hh"
44#include "G4PhysicalVolumeStore.hh"
45#include "G4LogicalVolumeStore.hh"
46#include "G4SolidStore.hh"
47
48#include "G4UnitsTable.hh"
49
50//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
51
52DetectorConstruction::DetectorConstruction()
53:pBox(0), BoxSize(500*m), aMaterial(0), magField(0)
54{
55 DefineMaterials();
56 SetMaterial("Iron");
57
58 // create UserLimits
59 userLimits = new G4UserLimits();
60
61 // create commands for interactive definition of the detector
62 detectorMessenger = new DetectorMessenger(this);
63}
64
65//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
66
67DetectorConstruction::~DetectorConstruction()
68{ delete detectorMessenger;}
69
70//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
71
72G4VPhysicalVolume* DetectorConstruction::Construct()
73{
74 return ConstructVolumes();
75}
76
77//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
78
79void DetectorConstruction::DefineMaterials()
80{
81 G4double a, z, density;
82
83 new G4Material("Beryllium", z= 4., a= 9.012182*g/mole, density= 1.848*g/cm3);
84 new G4Material("Carbon", z= 6., a= 12.011*g/mole, density= 2.265*g/cm3);
85 new G4Material("Iron", z=26., a= 55.85*g/mole, density= 7.870*g/cm3);
86
87 // define a vacuum with a restgas pressure typical for accelerators
88 G4double const Torr = atmosphere/760.; // 1 Torr
89 G4double pressure = 10e-9*Torr, temperature = 296.150*kelvin; // 23 Celsius
90 new G4Material("Vacuum", z=7., a=14.01*g/mole, density= 1.516784e-11*kg/m3,
91 kStateGas, temperature, pressure);
92
93 G4cout << *(G4Material::GetMaterialTable()) << G4endl;
94}
95
96//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
97
98G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
99{
100 G4GeometryManager::GetInstance()->OpenGeometry();
101 G4PhysicalVolumeStore::GetInstance()->Clean();
102 G4LogicalVolumeStore::GetInstance()->Clean();
103 G4SolidStore::GetInstance()->Clean();
104
105 G4Box*
106 sBox = new G4Box("Container", //its name
107 BoxSize/2,BoxSize/2,BoxSize/2); //its dimensions
108
109 G4LogicalVolume*
110 lBox = new G4LogicalVolume(sBox, //its shape
111 aMaterial, //its material
112 aMaterial->GetName()); //its name
113
114 lBox->SetUserLimits(userLimits);
115
116 pBox = new G4PVPlacement(0, //no rotation
117 G4ThreeVector(), //at (0,0,0)
118 lBox, //its logical volume
119 aMaterial->GetName(), //its name
120 0, //its mother volume
121 false, //no boolean operation
122 0); //copy number
123
124 PrintParameters();
125
126 //
127 //always return the root volume
128 //
129 return pBox;
130}
131
132//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
133
134void DetectorConstruction::PrintParameters()
135{
136 G4cout << "\n The Box is " << G4BestUnit(BoxSize,"Length")
137 << " of " << aMaterial->GetName() << G4endl;
138}
139
140//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
141
142void DetectorConstruction::SetMaterial(G4String materialChoice)
143{
144 // search the material by its name
145 G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
146 if (pttoMaterial) aMaterial = pttoMaterial;
147}
148
149//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
150
151void DetectorConstruction::SetSize(G4double value)
152{
153 BoxSize = value;
154}
155
156//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
157
158#include "G4FieldManager.hh"
159#include "G4TransportationManager.hh"
160
161void DetectorConstruction::SetMagField(G4double fieldValue)
162{
163 //apply a global uniform magnetic field along Z axis
164 G4FieldManager* fieldMgr
165 = G4TransportationManager::GetTransportationManager()->GetFieldManager();
166
167 if (magField) delete magField; //delete the existing magn field
168
169 if (fieldValue!=0.) // create a new one if non null
170 {
171 magField = new G4UniformMagField(G4ThreeVector(0.,0.,fieldValue));
172 fieldMgr->SetDetectorField(magField);
173 fieldMgr->CreateChordFinder(magField);
174 }
175 else
176 {
177 magField = 0;
178 fieldMgr->SetDetectorField(magField);
179 }
180}
181
182//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
183
184void DetectorConstruction::SetMaxStepSize(G4double val)
185{
186 // set the maximum allowed step size
187 //
188 if (val <= DBL_MIN)
189 { G4cout << "\n --->warning from SetMaxStepSize: maxStep "
190 << val << " out of range. Command refused" << G4endl;
191 return;
192 }
193 userLimits->SetMaxAllowedStep(val);
194}
195
196//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
197
198void DetectorConstruction::SetMaxStepLength(G4double val)
199{
200 // set the maximum length of tracking step
201 //
202 if (val <= DBL_MIN)
203 { G4cout << "\n --->warning from SetMaxStepLength: maxStep "
204 << val << " out of range. Command refused" << G4endl;
205 return;
206 }
207 G4TransportationManager* tmanager =
208 G4TransportationManager::GetTransportationManager();
209 tmanager->GetPropagatorInField()
210 ->SetLargestAcceptableStep(val);
211}
212
213//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
214
215#include "G4RunManager.hh"
216
217void DetectorConstruction::UpdateGeometry()
218{
219 G4RunManager::GetRunManager()->DefineWorldVolume(ConstructVolumes());
220}
221
222//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Note: See TracBrowser for help on using the repository browser.