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.10 2008/04/21 13:13:30 vnivanch Exp $ |
---|
27 | // GEANT4 tag $Name: geant4-09-03-cand-01 $ |
---|
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 | |
---|
41 | #include "G4GeometryManager.hh" |
---|
42 | #include "G4PhysicalVolumeStore.hh" |
---|
43 | #include "G4LogicalVolumeStore.hh" |
---|
44 | #include "G4SolidStore.hh" |
---|
45 | |
---|
46 | #include "G4NistManager.hh" |
---|
47 | #include "G4UnitsTable.hh" |
---|
48 | |
---|
49 | #include "G4FieldManager.hh" |
---|
50 | #include "G4TransportationManager.hh" |
---|
51 | #include "G4RunManager.hh" |
---|
52 | |
---|
53 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
54 | |
---|
55 | DetectorConstruction::DetectorConstruction() |
---|
56 | { |
---|
57 | // default parameter values |
---|
58 | absorSizeX = absorSizeYZ = 20*cm; |
---|
59 | worldSizeX = worldSizeYZ = 1.2*absorSizeX; |
---|
60 | |
---|
61 | worldMaterial = absorMaterial = 0; |
---|
62 | magField = 0; |
---|
63 | lAbsor = 0; |
---|
64 | |
---|
65 | tallySize = G4ThreeVector(); |
---|
66 | tallyMaterial = 0; |
---|
67 | tallyMass = 0.; |
---|
68 | tallyNumber = 0; |
---|
69 | tallyPosition = new G4ThreeVector[MaxTally]; |
---|
70 | lTally = 0; |
---|
71 | |
---|
72 | DefineMaterials(); |
---|
73 | SetMaterial("Water"); |
---|
74 | SetTallyMaterial("Water"); |
---|
75 | |
---|
76 | // create commands for interactive definition of the detector |
---|
77 | detectorMessenger = new DetectorMessenger(this); |
---|
78 | } |
---|
79 | |
---|
80 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
81 | |
---|
82 | DetectorConstruction::~DetectorConstruction() |
---|
83 | { delete [] tallyPosition; delete detectorMessenger;} |
---|
84 | |
---|
85 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
86 | |
---|
87 | G4VPhysicalVolume* DetectorConstruction::Construct() |
---|
88 | { |
---|
89 | return ConstructVolumes(); |
---|
90 | } |
---|
91 | |
---|
92 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
93 | |
---|
94 | void DetectorConstruction::DefineMaterials() |
---|
95 | { |
---|
96 | // |
---|
97 | // define Elements |
---|
98 | // |
---|
99 | G4double z, a; |
---|
100 | |
---|
101 | G4Element* H = new G4Element("Hydrogen", "H", z= 1, a= 1.008*g/mole); |
---|
102 | G4Element* N = new G4Element("Nitrogen", "N", z= 7, a= 14.01*g/mole); |
---|
103 | G4Element* O = new G4Element("Oxygen" , "O", z= 8, a= 16.00*g/mole); |
---|
104 | |
---|
105 | // |
---|
106 | // define Materials. |
---|
107 | // |
---|
108 | G4double density, temperature, pressure; |
---|
109 | G4int ncomponents, natoms; |
---|
110 | G4double fractionmass; |
---|
111 | |
---|
112 | G4Material* H2O = |
---|
113 | new G4Material("Water", density= 1.0*g/cm3, ncomponents=2); |
---|
114 | H2O->AddElement(H, natoms=2); |
---|
115 | H2O->AddElement(O, natoms=1); |
---|
116 | H2O->GetIonisation()->SetMeanExcitationEnergy(75.0*eV); |
---|
117 | |
---|
118 | G4Material* Air = |
---|
119 | new G4Material("Air" , density= 1.290*mg/cm3, ncomponents=2); |
---|
120 | Air->AddElement(N, fractionmass=0.7); |
---|
121 | Air->AddElement(O, fractionmass=0.3); |
---|
122 | |
---|
123 | density = 1.e-5*g/cm3; |
---|
124 | pressure = 2.e-2*bar; |
---|
125 | temperature = STP_Temperature; // From PhysicalConstants.h . |
---|
126 | G4Material* vac = new G4Material( "TechVacuum", density, 1, |
---|
127 | kStateGas, temperature, pressure ); |
---|
128 | vac->AddMaterial( Air, 1. ); |
---|
129 | |
---|
130 | density = universe_mean_density; //from PhysicalConstants.h |
---|
131 | pressure = 3.e-18*pascal; |
---|
132 | temperature = 2.73*kelvin; |
---|
133 | G4Material* vacuum = |
---|
134 | new G4Material("Galactic",z= 1,a= 1.008*g/mole,density, |
---|
135 | kStateGas,temperature,pressure); |
---|
136 | |
---|
137 | //default materials |
---|
138 | worldMaterial = vacuum; |
---|
139 | } |
---|
140 | |
---|
141 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
142 | |
---|
143 | G4VPhysicalVolume* DetectorConstruction::ConstructVolumes() |
---|
144 | { |
---|
145 | G4GeometryManager::GetInstance()->OpenGeometry(); |
---|
146 | G4PhysicalVolumeStore::GetInstance()->Clean(); |
---|
147 | G4LogicalVolumeStore::GetInstance()->Clean(); |
---|
148 | G4SolidStore::GetInstance()->Clean(); |
---|
149 | |
---|
150 | // World |
---|
151 | // |
---|
152 | G4Box* |
---|
153 | sWorld = new G4Box("World", //name |
---|
154 | worldSizeX/2,worldSizeYZ/2,worldSizeYZ/2); //dimensions |
---|
155 | |
---|
156 | G4LogicalVolume* |
---|
157 | lWorld = new G4LogicalVolume(sWorld, //shape |
---|
158 | worldMaterial, //material |
---|
159 | "World"); //name |
---|
160 | |
---|
161 | G4VPhysicalVolume* |
---|
162 | pWorld = new G4PVPlacement(0, //no rotation |
---|
163 | G4ThreeVector(), //at (0,0,0) |
---|
164 | lWorld, //logical volume |
---|
165 | "World", //name |
---|
166 | 0, //mother volume |
---|
167 | false, //no boolean operation |
---|
168 | 0); //copy number |
---|
169 | // |
---|
170 | // Absorber |
---|
171 | // |
---|
172 | G4Box* |
---|
173 | sAbsor = new G4Box("Absorber", //name |
---|
174 | absorSizeX/2,absorSizeYZ/2,absorSizeYZ/2); //dimensions |
---|
175 | |
---|
176 | lAbsor = new G4LogicalVolume(sAbsor, //shape |
---|
177 | absorMaterial, //material |
---|
178 | "Absorber"); //name |
---|
179 | |
---|
180 | |
---|
181 | new G4PVPlacement(0, //no rotation |
---|
182 | G4ThreeVector(), //at (0,0,0) |
---|
183 | lAbsor, //logical volume |
---|
184 | "Absorber", //name |
---|
185 | lWorld, //mother volume |
---|
186 | false, //no boolean operation |
---|
187 | 0); //copy number |
---|
188 | // |
---|
189 | // Tallies (optional) |
---|
190 | // |
---|
191 | if (tallyNumber > 0) { |
---|
192 | G4Box* |
---|
193 | sTally = new G4Box("Tally",tallySize.x()/2,tallySize.y()/2,tallySize.z()/2); |
---|
194 | lTally = new G4LogicalVolume(sTally,tallyMaterial,"Tally"); |
---|
195 | |
---|
196 | for (G4int j=0; j<tallyNumber; j++) |
---|
197 | { |
---|
198 | new G4PVPlacement(0, //no rotation |
---|
199 | tallyPosition[j], //position |
---|
200 | lTally, //logical volume |
---|
201 | "Tally", //name |
---|
202 | lAbsor, //mother volume |
---|
203 | false, //no boolean operation |
---|
204 | j); //copy number |
---|
205 | } |
---|
206 | |
---|
207 | tallyMass = tallySize.x()*tallySize.y()*tallySize.z() |
---|
208 | *(tallyMaterial->GetDensity()); |
---|
209 | } |
---|
210 | |
---|
211 | PrintParameters(); |
---|
212 | |
---|
213 | // |
---|
214 | //always return the World volume |
---|
215 | // |
---|
216 | return pWorld; |
---|
217 | } |
---|
218 | |
---|
219 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
220 | |
---|
221 | void DetectorConstruction::PrintParameters() |
---|
222 | { |
---|
223 | G4cout << *(G4Material::GetMaterialTable()) << G4endl; |
---|
224 | G4cout << "\n---------------------------------------------------------\n"; |
---|
225 | G4cout << "---> The Absorber is " << G4BestUnit(absorSizeX,"Length") |
---|
226 | << " of " << absorMaterial->GetName() << G4endl; |
---|
227 | G4cout << "\n---------------------------------------------------------\n"; |
---|
228 | |
---|
229 | if (tallyNumber > 0) { |
---|
230 | G4cout << "---> There are " << tallyNumber << " tallies : " |
---|
231 | << G4BestUnit(tallySize,"Length") |
---|
232 | << " of " << tallyMaterial->GetName() |
---|
233 | << " (mass : " << G4BestUnit(tallyMass,"Mass") << ")" << G4endl; |
---|
234 | |
---|
235 | for (G4int j=0; j<tallyNumber; j++) |
---|
236 | G4cout << "tally " << j << ": " |
---|
237 | << "position = " << G4BestUnit(tallyPosition[j],"Length") << G4endl; |
---|
238 | G4cout << "\n---------------------------------------------------------\n"; |
---|
239 | } |
---|
240 | } |
---|
241 | |
---|
242 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
243 | |
---|
244 | void DetectorConstruction::SetSizeX(G4double value) |
---|
245 | { |
---|
246 | absorSizeX = value; worldSizeX = 1.2*absorSizeX; |
---|
247 | G4RunManager::GetRunManager()->GeometryHasBeenModified(); |
---|
248 | } |
---|
249 | |
---|
250 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
251 | |
---|
252 | void DetectorConstruction::SetSizeYZ(G4double value) |
---|
253 | { |
---|
254 | absorSizeYZ = value; |
---|
255 | worldSizeYZ = 1.2*absorSizeYZ; |
---|
256 | G4RunManager::GetRunManager()->GeometryHasBeenModified(); |
---|
257 | } |
---|
258 | |
---|
259 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
260 | |
---|
261 | void DetectorConstruction::SetMaterial(G4String materialChoice) |
---|
262 | { |
---|
263 | // search the material by its name |
---|
264 | G4Material* pttoMaterial = |
---|
265 | G4NistManager::Instance()->FindOrBuildMaterial(materialChoice); |
---|
266 | if (pttoMaterial) { |
---|
267 | absorMaterial = pttoMaterial; |
---|
268 | if(lAbsor) { |
---|
269 | lAbsor->SetMaterial(absorMaterial); |
---|
270 | G4RunManager::GetRunManager()->PhysicsHasBeenModified(); |
---|
271 | } |
---|
272 | } |
---|
273 | } |
---|
274 | |
---|
275 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
276 | |
---|
277 | void DetectorConstruction::SetMagField(G4double fieldValue) |
---|
278 | { |
---|
279 | //apply a global uniform magnetic field along Z axis |
---|
280 | G4FieldManager* fieldMgr |
---|
281 | = G4TransportationManager::GetTransportationManager()->GetFieldManager(); |
---|
282 | |
---|
283 | if (magField) delete magField; //delete the existing magn field |
---|
284 | |
---|
285 | if (fieldValue!=0.) // create a new one if non nul |
---|
286 | { |
---|
287 | magField = new G4UniformMagField(G4ThreeVector(0.,0.,fieldValue)); |
---|
288 | fieldMgr->SetDetectorField(magField); |
---|
289 | fieldMgr->CreateChordFinder(magField); |
---|
290 | } |
---|
291 | else |
---|
292 | { |
---|
293 | magField = 0; |
---|
294 | fieldMgr->SetDetectorField(magField); |
---|
295 | } |
---|
296 | } |
---|
297 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
298 | |
---|
299 | void DetectorConstruction::SetTallySize(G4ThreeVector value) |
---|
300 | { |
---|
301 | tallySize = value; |
---|
302 | G4RunManager::GetRunManager()->GeometryHasBeenModified(); |
---|
303 | } |
---|
304 | |
---|
305 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
306 | |
---|
307 | void DetectorConstruction::SetTallyMaterial(G4String materialChoice) |
---|
308 | { |
---|
309 | // search the material by its name |
---|
310 | G4Material* pttoMaterial = |
---|
311 | G4NistManager::Instance()->FindOrBuildMaterial(materialChoice); |
---|
312 | if (pttoMaterial) { |
---|
313 | tallyMaterial = pttoMaterial; |
---|
314 | if(lTally) { |
---|
315 | lTally->SetMaterial(tallyMaterial); |
---|
316 | G4RunManager::GetRunManager()->PhysicsHasBeenModified(); |
---|
317 | } |
---|
318 | } |
---|
319 | } |
---|
320 | |
---|
321 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
322 | |
---|
323 | void DetectorConstruction::SetTallyPosition(G4ThreeVector value) |
---|
324 | { |
---|
325 | if (tallyNumber < MaxTally) { |
---|
326 | tallyPosition[tallyNumber] = value; |
---|
327 | tallyNumber++; |
---|
328 | } |
---|
329 | G4RunManager::GetRunManager()->GeometryHasBeenModified(); |
---|
330 | } |
---|
331 | |
---|
332 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
333 | |
---|
334 | void DetectorConstruction::UpdateGeometry() |
---|
335 | { |
---|
336 | G4RunManager::GetRunManager()->PhysicsHasBeenModified(); |
---|
337 | G4RunManager::GetRunManager()->DefineWorldVolume(ConstructVolumes()); |
---|
338 | } |
---|
339 | |
---|
340 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|