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 | // |
---|
27 | // ------------------------------------------------------------- |
---|
28 | // GEANT4 hTest |
---|
29 | // |
---|
30 | // History: based on object model of |
---|
31 | // 2nd December 1995, G.Cosmo |
---|
32 | // ---------- hTestDetectorConstruction ------- |
---|
33 | // |
---|
34 | // Modified: 05.04.01 Vladimir Ivanchenko new design of hTest |
---|
35 | // |
---|
36 | // ------------------------------------------------------------- |
---|
37 | |
---|
38 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
39 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
40 | |
---|
41 | #include "hTestDetectorConstruction.hh" |
---|
42 | #include "hTestDetectorMessenger.hh" |
---|
43 | #include "hTestEventAction.hh" |
---|
44 | #include "hTestCalorimeterSD.hh" |
---|
45 | #include "hTestHisto.hh" |
---|
46 | |
---|
47 | #include "G4Material.hh" |
---|
48 | #include "G4Box.hh" |
---|
49 | #include "G4LogicalVolume.hh" |
---|
50 | #include "G4PVPlacement.hh" |
---|
51 | #include "G4UniformMagField.hh" |
---|
52 | #include "G4FieldManager.hh" |
---|
53 | #include "G4TransportationManager.hh" |
---|
54 | #include "G4SDManager.hh" |
---|
55 | #include "G4RunManager.hh" |
---|
56 | |
---|
57 | #include "G4VisAttributes.hh" |
---|
58 | #include "G4Colour.hh" |
---|
59 | |
---|
60 | #include "globals.hh" |
---|
61 | #include "G4ios.hh" |
---|
62 | |
---|
63 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
64 | |
---|
65 | hTestDetectorConstruction::hTestDetectorConstruction(): |
---|
66 | AbsorberMaterial(0), |
---|
67 | WorldMaterial(0), |
---|
68 | solidWorld(0), |
---|
69 | logicWorld(0), |
---|
70 | physWorld(0), |
---|
71 | solidAbs(0), |
---|
72 | logicAbs(0), |
---|
73 | physAbs(0), |
---|
74 | magField(0), |
---|
75 | calorimeterSD(0), |
---|
76 | theEvent(0), |
---|
77 | myVerbose(0), |
---|
78 | nEvents(0), |
---|
79 | detIsConstructed(false), |
---|
80 | nAbsSaved(0), |
---|
81 | nFirstEvtToDebug(-1), |
---|
82 | nLastEvtToDebug(-1) |
---|
83 | { |
---|
84 | // Default parameter values of the calorimeter |
---|
85 | // corresponds to water test |
---|
86 | nameMatAbsorber = G4String("Water"); |
---|
87 | AbsorberThickness = 1.0*mm; |
---|
88 | SizeXY = 1000.0*mm; |
---|
89 | gap = 0.0; |
---|
90 | NumberOfAbsorbers = 300; |
---|
91 | nameMatWorld = G4String("Air"); |
---|
92 | WorldSizeZ = 400.0*mm; |
---|
93 | maxDelta = 10.0*MeV; |
---|
94 | |
---|
95 | ComputeGeomParameters(); |
---|
96 | |
---|
97 | // create commands for interactive definition of the calorimeter |
---|
98 | detectorMessenger = new hTestDetectorMessenger(this); |
---|
99 | } |
---|
100 | |
---|
101 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
102 | |
---|
103 | hTestDetectorConstruction::~hTestDetectorConstruction() |
---|
104 | { |
---|
105 | delete detectorMessenger; |
---|
106 | } |
---|
107 | |
---|
108 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
109 | |
---|
110 | G4VPhysicalVolume* hTestDetectorConstruction::Construct() |
---|
111 | { |
---|
112 | if(!detIsConstructed) DefineMaterials(); |
---|
113 | WorldMaterial = GetMaterial(nameMatWorld); |
---|
114 | AbsorberMaterial = GetMaterial(nameMatAbsorber); |
---|
115 | return ConstructGeometry(); |
---|
116 | } |
---|
117 | |
---|
118 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
119 | |
---|
120 | void hTestDetectorConstruction::DefineMaterials() |
---|
121 | { |
---|
122 | if(myVerbose > 0) { |
---|
123 | G4cout << "hTestDetectorConstruction: DefineMaterials starts" << G4endl; |
---|
124 | } |
---|
125 | |
---|
126 | G4String name, symbol; //a=mass of a mole; |
---|
127 | G4double a, z, density; //z=mean number of protons; |
---|
128 | |
---|
129 | G4int ncomponents, natoms; |
---|
130 | G4double fractionmass; |
---|
131 | G4double temperature, pressure; |
---|
132 | |
---|
133 | // |
---|
134 | // define Elements |
---|
135 | // |
---|
136 | |
---|
137 | a = 1.01*g/mole; |
---|
138 | G4Element* elH = new G4Element(name="Hydrogen",symbol="H", z= 1., a); |
---|
139 | |
---|
140 | a = 14.01*g/mole; |
---|
141 | G4Element* elN = new G4Element(name="Nitrogen",symbol="N" , z= 7., a); |
---|
142 | |
---|
143 | a = 16.00*g/mole; |
---|
144 | G4Element* elO = new G4Element(name="Oxygen" ,symbol="O" , z= 8., a); |
---|
145 | |
---|
146 | a = 12.00*g/mole; |
---|
147 | G4Element* elC = new G4Element(name="Carbon" ,symbol="C" , z= 6., a); |
---|
148 | |
---|
149 | a = 69.723*g/mole; |
---|
150 | G4Element* elGa = new G4Element(name="Gallium" ,symbol="Ga" , z= 31., a); |
---|
151 | |
---|
152 | a = 74.9216*g/mole; |
---|
153 | G4Element* elAs = new G4Element(name="Arsenicum" ,symbol="As" , z= 33., a); |
---|
154 | |
---|
155 | G4Element* Cs = new G4Element ("Cesium" , "Cs", 55. , 132.905*g/mole); |
---|
156 | |
---|
157 | G4Element* I = new G4Element ("Iodide" , "I", 53. , 126.9044*g/mole); |
---|
158 | |
---|
159 | // |
---|
160 | // define simple materials |
---|
161 | // |
---|
162 | G4Material* ma; |
---|
163 | |
---|
164 | density = 1.848*g/cm3; |
---|
165 | a = 9.01*g/mole; |
---|
166 | |
---|
167 | ma = new G4Material(name="Beryllium", z=4., a, density); |
---|
168 | |
---|
169 | density = 2.700*g/cm3; |
---|
170 | a = 26.98*g/mole; |
---|
171 | ma = new G4Material(name="Aluminum", z=13., a, density); |
---|
172 | |
---|
173 | density = 2.0*g/cm3; |
---|
174 | a = 12.0107*g/mole; |
---|
175 | ma = new G4Material(name="Carbon", z=6., a, density); |
---|
176 | |
---|
177 | density = 2.330*g/cm3; |
---|
178 | a = 28.09*g/mole; |
---|
179 | ma = new G4Material(name="Silicon", z=14., a, density); |
---|
180 | |
---|
181 | density = 1.390*g/cm3; |
---|
182 | a = 39.95*g/mole; |
---|
183 | ma = new G4Material(name="LiquidArgon", z=18., a, density); |
---|
184 | |
---|
185 | density = 3.02*g/cm3; |
---|
186 | a = 131.29*g/mole; |
---|
187 | ma = new G4Material(name="LiquidXenon", z=54., a, density); |
---|
188 | |
---|
189 | density = 7.870*g/cm3; |
---|
190 | a = 55.85*g/mole; |
---|
191 | ma = new G4Material(name="Iron" , z=26., a, density); |
---|
192 | |
---|
193 | density = 8.960*g/cm3; |
---|
194 | a = 63.55*g/mole; |
---|
195 | ma = new G4Material(name="Copper" , z=29., a, density); |
---|
196 | |
---|
197 | density = 5.323*g/cm3; |
---|
198 | a = 72.61*g/mole; |
---|
199 | ma = new G4Material(name="Germanium", z=32., a, density); |
---|
200 | |
---|
201 | density = 19.32*g/cm3; |
---|
202 | a =196.97*g/mole; |
---|
203 | ma = new G4Material(name="Gold" , z=79., a, density); |
---|
204 | |
---|
205 | density = 11.35*g/cm3; |
---|
206 | a = 207.19*g/mole; |
---|
207 | ma = new G4Material(name="Lead" , z=82., a, density); |
---|
208 | |
---|
209 | ma = new G4Material("Tantalum", z=73., 180.9479*g/mole, 16.67*g/cm3); |
---|
210 | |
---|
211 | ma = new G4Material("Uranium", z=92., 238.03*g/mole, 18.95*g/cm3); |
---|
212 | |
---|
213 | // |
---|
214 | // define a material from elements. case 1: chemical molecule |
---|
215 | // |
---|
216 | |
---|
217 | density = 1.000*g/cm3; |
---|
218 | ma = new G4Material("Water", density, 2); |
---|
219 | ma->SetChemicalFormula("H_2O"); |
---|
220 | ma->AddElement(elH, natoms=2); |
---|
221 | ma->AddElement(elO, natoms=1); |
---|
222 | |
---|
223 | density = 0.00066715*g/cm3; |
---|
224 | ma = new G4Material("Methane", density, 2); |
---|
225 | ma->SetChemicalFormula("CH_4"); |
---|
226 | ma->AddElement(elH, natoms=4); |
---|
227 | ma->AddElement(elC, natoms=1); |
---|
228 | |
---|
229 | ma = new G4Material("Graphite", 2.265*g/cm3, 1); |
---|
230 | ma->SetChemicalFormula("Graphite"); |
---|
231 | ma->AddElement( elC, 1 ); |
---|
232 | |
---|
233 | density = 5.3176*g/cm3; |
---|
234 | ma = new G4Material("GaAs", density, ncomponents=2); |
---|
235 | ma->SetChemicalFormula("GaAS"); |
---|
236 | ma->AddElement(elGa, natoms=1); |
---|
237 | ma->AddElement(elAs, natoms=1); |
---|
238 | |
---|
239 | ma = new G4Material ("Ethane" , 0.4241*g/cm3, 2); |
---|
240 | ma->SetChemicalFormula("C_2H_6"); |
---|
241 | ma->AddElement(elH,6); |
---|
242 | ma->AddElement(elC,2); |
---|
243 | |
---|
244 | ma = new G4Material ("CsI" , 4.53*g/cm3, 2); |
---|
245 | ma->SetChemicalFormula("CsI"); |
---|
246 | ma->AddElement(Cs,1); |
---|
247 | ma->AddElement(I,1); |
---|
248 | |
---|
249 | // |
---|
250 | // define a material from elements. case 2: mixture by fractional mass |
---|
251 | // |
---|
252 | |
---|
253 | density = 1.290*mg/cm3; |
---|
254 | //density = 1.*mg/cm3; |
---|
255 | ma = new G4Material("Air" , density, ncomponents=2); |
---|
256 | ma->AddElement(elN, fractionmass=0.7); |
---|
257 | ma->AddElement(elO, fractionmass=0.3); |
---|
258 | |
---|
259 | density = 1.39*g/cm3; |
---|
260 | ma = new G4Material("Mylar" , density, ncomponents=3); |
---|
261 | ma->AddElement(elC, natoms=10); |
---|
262 | ma->AddElement(elH, natoms=18); |
---|
263 | ma->AddElement(elO, natoms=5); |
---|
264 | |
---|
265 | density = universe_mean_density; //from PhysicalConstants.h |
---|
266 | pressure = 3.e-18*pascal; |
---|
267 | temperature = 2.73*kelvin; |
---|
268 | a = 1.01*g/mole; |
---|
269 | z = 1.0; |
---|
270 | ma = new G4Material("Vacuum", z, a, density, |
---|
271 | kStateGas,temperature,pressure); |
---|
272 | |
---|
273 | G4cout << *(G4Material::GetMaterialTable()) << G4endl; |
---|
274 | |
---|
275 | } |
---|
276 | |
---|
277 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
278 | |
---|
279 | G4VPhysicalVolume* hTestDetectorConstruction::ConstructGeometry() |
---|
280 | { |
---|
281 | if(myVerbose > 0) { |
---|
282 | G4cout << "hTestDetectorConstruction: ConstructGeometry starts" << G4endl; |
---|
283 | } |
---|
284 | |
---|
285 | ComputeGeomParameters(); |
---|
286 | |
---|
287 | // |
---|
288 | // World |
---|
289 | // |
---|
290 | solidWorld = new G4Box("World",SizeXY+1.0*mm,SizeXY+1.0*mm,WorldSizeZ); |
---|
291 | |
---|
292 | logicWorld = new G4LogicalVolume(solidWorld,WorldMaterial,"World"); |
---|
293 | |
---|
294 | physWorld = new G4PVPlacement(0,G4ThreeVector(),"World",logicWorld, |
---|
295 | 0,false,0); |
---|
296 | |
---|
297 | // |
---|
298 | // Absorber |
---|
299 | // |
---|
300 | solidAbs = new G4Box("Absorber",SizeXY,SizeXY,AbsorberThickness*0.5); |
---|
301 | |
---|
302 | logicAbs = new G4LogicalVolume(solidAbs,AbsorberMaterial,"Absorber"); |
---|
303 | |
---|
304 | G4double z = AbsorberThickness * 0.5; |
---|
305 | |
---|
306 | for (G4int j=0; j<NumberOfAbsorbers; j++) { |
---|
307 | |
---|
308 | physAbs = new G4PVPlacement(0,G4ThreeVector(0.0,0.0,z), |
---|
309 | "Absorber",logicAbs,physWorld,false,j); |
---|
310 | z += AbsorberThickness + gap; |
---|
311 | } |
---|
312 | |
---|
313 | // |
---|
314 | // Sensitive Detectors: Absorber |
---|
315 | // |
---|
316 | |
---|
317 | calorimeterSD = new hTestCalorimeterSD("hTest"); |
---|
318 | (G4SDManager::GetSDMpointer())->AddNewDetector( calorimeterSD ); |
---|
319 | logicAbs->SetSensitiveDetector(calorimeterSD); |
---|
320 | |
---|
321 | // |
---|
322 | // Visualization attributes |
---|
323 | // |
---|
324 | G4VisAttributes* VisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0)); |
---|
325 | VisAtt->SetVisibility(true); |
---|
326 | logicAbs->SetVisAttributes(VisAtt); |
---|
327 | |
---|
328 | PrintGeomParameters(); |
---|
329 | |
---|
330 | detIsConstructed = true; |
---|
331 | |
---|
332 | // |
---|
333 | //always return the physical World |
---|
334 | // |
---|
335 | |
---|
336 | return physWorld; |
---|
337 | } |
---|
338 | |
---|
339 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
340 | |
---|
341 | void hTestDetectorConstruction::PrintGeomParameters() |
---|
342 | { |
---|
343 | G4cout << "The WORLD is made of " |
---|
344 | << " of " << WorldMaterial->GetName(); |
---|
345 | G4cout << ". The transverse size (XY) of the world is " |
---|
346 | << SizeXY/mm << " mm" << G4endl; |
---|
347 | G4cout << "The ABSORBER is made of " << NumberOfAbsorbers << " items of " |
---|
348 | << AbsorberThickness/mm |
---|
349 | << " mm of " << AbsorberMaterial->GetName(); |
---|
350 | G4cout << ". The transverse size (XY) is " |
---|
351 | << SizeXY/mm << " mm" << G4endl; |
---|
352 | } |
---|
353 | |
---|
354 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
355 | |
---|
356 | G4Material* hTestDetectorConstruction::GetMaterial(const G4String& mat) |
---|
357 | { |
---|
358 | // search the material by its name |
---|
359 | G4Material* pttoMaterial = G4Material::GetMaterial(mat); |
---|
360 | if(detIsConstructed) MaterialIsChanged(); |
---|
361 | return pttoMaterial; |
---|
362 | } |
---|
363 | |
---|
364 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
365 | |
---|
366 | void hTestDetectorConstruction::SetNumberOfAbsorbers(G4int val) |
---|
367 | { |
---|
368 | // change Absorber thickness and recompute the calorimeter parameters |
---|
369 | NumberOfAbsorbers = val; |
---|
370 | if(detIsConstructed) GeometryIsChanged(); |
---|
371 | } |
---|
372 | |
---|
373 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
374 | |
---|
375 | void hTestDetectorConstruction::SetAbsorberThickness(G4double val) |
---|
376 | { |
---|
377 | // change Absorber thickness and recompute the calorimeter parameters |
---|
378 | AbsorberThickness = val; |
---|
379 | if(detIsConstructed) GeometryIsChanged(); |
---|
380 | } |
---|
381 | |
---|
382 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
383 | |
---|
384 | void hTestDetectorConstruction::SetAbsorberSizeXY(G4double val) |
---|
385 | { |
---|
386 | // change the transverse size and recompute the calorimeter parameters |
---|
387 | SizeXY = val; |
---|
388 | if(detIsConstructed) GeometryIsChanged(); |
---|
389 | } |
---|
390 | |
---|
391 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
392 | |
---|
393 | void hTestDetectorConstruction::SetWorldSizeZ(G4double val) |
---|
394 | { |
---|
395 | WorldSizeZ = val; |
---|
396 | if(detIsConstructed) GeometryIsChanged(); |
---|
397 | } |
---|
398 | |
---|
399 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
400 | |
---|
401 | void hTestDetectorConstruction::SetGap(G4double val) |
---|
402 | { |
---|
403 | gap = val; |
---|
404 | if(detIsConstructed) GeometryIsChanged(); |
---|
405 | } |
---|
406 | |
---|
407 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
408 | |
---|
409 | void hTestDetectorConstruction::SetMagField(G4double fieldValue, G4int axis) |
---|
410 | { |
---|
411 | // access to the field manager |
---|
412 | G4FieldManager* fieldMgr |
---|
413 | = G4TransportationManager::GetTransportationManager()->GetFieldManager(); |
---|
414 | |
---|
415 | if(magField) delete magField; //delete the existing magn field |
---|
416 | |
---|
417 | // Create new field if >0 |
---|
418 | if(fieldValue!=0.0) { |
---|
419 | |
---|
420 | G4ThreeVector B; |
---|
421 | // Choose direction of the field |
---|
422 | if(1 == axis) { |
---|
423 | B = G4ThreeVector(fieldValue,0.,0.); |
---|
424 | } else if(2 == axis) { |
---|
425 | B = G4ThreeVector(0.,fieldValue,0.); |
---|
426 | } else { |
---|
427 | B = G4ThreeVector(0.,0.,fieldValue); |
---|
428 | } |
---|
429 | |
---|
430 | magField = new G4UniformMagField(B); |
---|
431 | fieldMgr->SetDetectorField(magField); |
---|
432 | fieldMgr->CreateChordFinder(magField); |
---|
433 | |
---|
434 | // Set zero field |
---|
435 | } else { |
---|
436 | magField = 0; |
---|
437 | fieldMgr->SetDetectorField(magField); |
---|
438 | } |
---|
439 | } |
---|
440 | |
---|
441 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
442 | |
---|
443 | void hTestDetectorConstruction::ComputeGeomParameters() |
---|
444 | { |
---|
445 | // Compute derived parameters of the 1st absorber |
---|
446 | |
---|
447 | if(WorldSizeZ < (AbsorberThickness + gap)*NumberOfAbsorbers) |
---|
448 | WorldSizeZ = (AbsorberThickness + gap)*NumberOfAbsorbers + 1.0*mm; |
---|
449 | |
---|
450 | (hTestHisto::GetPointer())->SetNumberOfAbsorbers(NumberOfAbsorbers); |
---|
451 | (hTestHisto::GetPointer())->SetAbsorberThickness(AbsorberThickness); |
---|
452 | (hTestHisto::GetPointer())->SetNumAbsorbersSaved(nAbsSaved); |
---|
453 | } |
---|
454 | |
---|
455 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
456 | |
---|
457 | void hTestDetectorConstruction::UpdateGeometry() |
---|
458 | { |
---|
459 | (G4RunManager::GetRunManager())->DefineWorldVolume(ConstructGeometry()); |
---|
460 | } |
---|
461 | |
---|
462 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
463 | |
---|
464 | void hTestDetectorConstruction::GeometryIsChanged() |
---|
465 | { |
---|
466 | (G4RunManager::GetRunManager())->GeometryHasBeenModified(); |
---|
467 | } |
---|
468 | |
---|
469 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
470 | |
---|
471 | void hTestDetectorConstruction::MaterialIsChanged() |
---|
472 | { |
---|
473 | (G4RunManager::GetRunManager())->CutOffHasBeenModified(); |
---|
474 | (G4RunManager::GetRunManager())->GeometryHasBeenModified(); |
---|
475 | } |
---|
476 | |
---|
477 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
478 | |
---|
479 | |
---|
480 | |
---|
481 | |
---|
482 | |
---|
483 | |
---|
484 | |
---|