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.2 2006/06/29 16:43:00 gunter Exp $ |
---|
27 | // GEANT4 tag $Name: geant4-09-04-beta-01 $ |
---|
28 | // |
---|
29 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
30 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
31 | |
---|
32 | #include "DetectorConstruction.hh" |
---|
33 | #include "DetectorMessenger.hh" |
---|
34 | |
---|
35 | #include "G4NistManager.hh" |
---|
36 | #include "G4Sphere.hh" |
---|
37 | #include "G4LogicalVolume.hh" |
---|
38 | #include "G4VPhysicalVolume.hh" |
---|
39 | #include "G4PVPlacement.hh" |
---|
40 | #include "G4PVReplica.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 "G4UnitsTable.hh" |
---|
49 | |
---|
50 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
51 | |
---|
52 | DetectorConstruction::DetectorConstruction() |
---|
53 | { |
---|
54 | // default parameter values |
---|
55 | absorRadius = 3*cm; |
---|
56 | nbOfLayers = 1; |
---|
57 | |
---|
58 | absorMaterial = 0; |
---|
59 | magField = 0; |
---|
60 | pAbsor = 0; |
---|
61 | |
---|
62 | DefineMaterials(); |
---|
63 | SetMaterial("G4_WATER"); |
---|
64 | |
---|
65 | // create commands for interactive definition of the detector |
---|
66 | detectorMessenger = new DetectorMessenger(this); |
---|
67 | } |
---|
68 | |
---|
69 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
70 | |
---|
71 | DetectorConstruction::~DetectorConstruction() |
---|
72 | { delete detectorMessenger;} |
---|
73 | |
---|
74 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
75 | |
---|
76 | G4VPhysicalVolume* DetectorConstruction::Construct() |
---|
77 | { |
---|
78 | return ConstructVolumes(); |
---|
79 | } |
---|
80 | |
---|
81 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
82 | |
---|
83 | void DetectorConstruction::DefineMaterials() |
---|
84 | { |
---|
85 | G4NistManager* man = G4NistManager::Instance(); |
---|
86 | |
---|
87 | G4bool isotopes = false; |
---|
88 | |
---|
89 | man->FindOrBuildMaterial("G4_Al", isotopes); |
---|
90 | man->FindOrBuildMaterial("G4_Si", isotopes); |
---|
91 | man->FindOrBuildMaterial("G4_Fe", isotopes); |
---|
92 | man->FindOrBuildMaterial("G4_Ge", isotopes); |
---|
93 | man->FindOrBuildMaterial("G4_W" , isotopes); |
---|
94 | man->FindOrBuildMaterial("G4_Pb", isotopes); |
---|
95 | |
---|
96 | man->FindOrBuildMaterial("G4_AIR" , isotopes); |
---|
97 | man->FindOrBuildMaterial("G4_WATER", isotopes); |
---|
98 | |
---|
99 | G4cout << *(G4Material::GetMaterialTable()) << G4endl; |
---|
100 | } |
---|
101 | |
---|
102 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
103 | |
---|
104 | G4VPhysicalVolume* DetectorConstruction::ConstructVolumes() |
---|
105 | { |
---|
106 | G4GeometryManager::GetInstance()->OpenGeometry(); |
---|
107 | G4PhysicalVolumeStore::GetInstance()->Clean(); |
---|
108 | G4LogicalVolumeStore::GetInstance()->Clean(); |
---|
109 | G4SolidStore::GetInstance()->Clean(); |
---|
110 | |
---|
111 | // Absorber |
---|
112 | // |
---|
113 | G4Sphere* |
---|
114 | sAbsor = new G4Sphere("Absorber", //name |
---|
115 | 0., absorRadius, 0., twopi, 0., pi); //size |
---|
116 | |
---|
117 | G4LogicalVolume* |
---|
118 | lAbsor = new G4LogicalVolume(sAbsor, //solid |
---|
119 | absorMaterial, //material |
---|
120 | "Absorber"); //name |
---|
121 | |
---|
122 | pAbsor = new G4PVPlacement(0, //no rotation |
---|
123 | G4ThreeVector(), //at (0,0,0) |
---|
124 | lAbsor, //logical volume |
---|
125 | "Absorber", //name |
---|
126 | 0, //mother volume |
---|
127 | false, //no boolean operation |
---|
128 | 0); //copy number |
---|
129 | |
---|
130 | // Layers |
---|
131 | // |
---|
132 | layerThickness = absorRadius/nbOfLayers; |
---|
133 | |
---|
134 | for (G4int i=1; i<=nbOfLayers; i++) { |
---|
135 | G4Sphere* |
---|
136 | sLayer = new G4Sphere("Layer", (i-1)*layerThickness, i*layerThickness, |
---|
137 | 0., twopi, 0., pi); |
---|
138 | |
---|
139 | G4LogicalVolume* |
---|
140 | lLayer = new G4LogicalVolume(sLayer, //shape |
---|
141 | absorMaterial, //material |
---|
142 | "Layer"); //name |
---|
143 | |
---|
144 | new G4PVPlacement(0, //no rotation |
---|
145 | G4ThreeVector(), //at (0,0,0) |
---|
146 | lLayer, //logical volume |
---|
147 | "Layer", //name |
---|
148 | lAbsor, //mother volume |
---|
149 | false, //no boolean operation |
---|
150 | i); //copy number |
---|
151 | |
---|
152 | } |
---|
153 | |
---|
154 | PrintParameters(); |
---|
155 | |
---|
156 | // |
---|
157 | //always return the root volume |
---|
158 | // |
---|
159 | return pAbsor; |
---|
160 | } |
---|
161 | |
---|
162 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
163 | |
---|
164 | void DetectorConstruction::PrintParameters() |
---|
165 | { |
---|
166 | G4cout << "\n---------------------------------------------------------\n"; |
---|
167 | G4cout << "---> The Absorber is a sphere of " |
---|
168 | << G4BestUnit(absorRadius,"Length") << " radius of " |
---|
169 | << absorMaterial->GetName() << " divided in " << nbOfLayers |
---|
170 | << " slices of " << G4BestUnit(layerThickness,"Length") << G4endl; |
---|
171 | G4cout << "\n---------------------------------------------------------\n"; |
---|
172 | } |
---|
173 | |
---|
174 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
175 | |
---|
176 | void DetectorConstruction::SetRadius(G4double value) |
---|
177 | { |
---|
178 | absorRadius = value; |
---|
179 | } |
---|
180 | |
---|
181 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
182 | |
---|
183 | void DetectorConstruction::SetMaterial(G4String materialChoice) |
---|
184 | { |
---|
185 | // search the material by its name |
---|
186 | G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice); |
---|
187 | if (pttoMaterial) absorMaterial = pttoMaterial; |
---|
188 | } |
---|
189 | |
---|
190 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
191 | |
---|
192 | void DetectorConstruction::SetNbOfLayers(G4int value) |
---|
193 | { |
---|
194 | nbOfLayers = value; |
---|
195 | } |
---|
196 | |
---|
197 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
198 | |
---|
199 | #include "G4FieldManager.hh" |
---|
200 | #include "G4TransportationManager.hh" |
---|
201 | |
---|
202 | void DetectorConstruction::SetMagField(G4double fieldValue) |
---|
203 | { |
---|
204 | //apply a global uniform magnetic field along Z axis |
---|
205 | G4FieldManager* fieldMgr |
---|
206 | = G4TransportationManager::GetTransportationManager()->GetFieldManager(); |
---|
207 | |
---|
208 | if (magField) delete magField; //delete the existing magn field |
---|
209 | |
---|
210 | if (fieldValue!=0.) // create a new one if non nul |
---|
211 | { |
---|
212 | magField = new G4UniformMagField(G4ThreeVector(0.,0.,fieldValue)); |
---|
213 | fieldMgr->SetDetectorField(magField); |
---|
214 | fieldMgr->CreateChordFinder(magField); |
---|
215 | } |
---|
216 | else |
---|
217 | { |
---|
218 | magField = 0; |
---|
219 | fieldMgr->SetDetectorField(magField); |
---|
220 | } |
---|
221 | } |
---|
222 | |
---|
223 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
224 | |
---|
225 | #include "G4RunManager.hh" |
---|
226 | |
---|
227 | void DetectorConstruction::UpdateGeometry() |
---|
228 | { |
---|
229 | G4RunManager::GetRunManager()->DefineWorldVolume(ConstructVolumes()); |
---|
230 | } |
---|
231 | |
---|
232 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|