source: trunk/examples/novice/N03/src/ExN03DetectorConstruction.cc@ 1234

Last change on this file since 1234 was 1209, checked in by garnier, 16 years ago

CVS update

File size: 17.0 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//
27// $Id: ExN03DetectorConstruction.cc,v 1.24 2008/08/12 20:00:03 gum Exp $
28// GEANT4 tag $Name: geant4-09-03-cand-01 $
29//
30//
31
32//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
34
35#include "ExN03DetectorConstruction.hh"
36#include "ExN03DetectorMessenger.hh"
37
38#include "G4Material.hh"
39#include "G4Box.hh"
40#include "G4LogicalVolume.hh"
41#include "G4PVPlacement.hh"
42#include "G4PVReplica.hh"
43#include "G4UniformMagField.hh"
44
45#include "G4GeometryManager.hh"
46#include "G4PhysicalVolumeStore.hh"
47#include "G4LogicalVolumeStore.hh"
48#include "G4SolidStore.hh"
49
50#include "G4VisAttributes.hh"
51#include "G4Colour.hh"
52
53//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
54
55ExN03DetectorConstruction::ExN03DetectorConstruction()
56:AbsorberMaterial(0),GapMaterial(0),defaultMaterial(0),
57 solidWorld(0),logicWorld(0),physiWorld(0),
58 solidCalor(0),logicCalor(0),physiCalor(0),
59 solidLayer(0),logicLayer(0),physiLayer(0),
60 solidAbsorber(0),logicAbsorber(0),physiAbsorber(0),
61 solidGap (0),logicGap (0),physiGap (0),
62 magField(0)
63{
64 // default parameter values of the calorimeter
65 AbsorberThickness = 10.*mm;
66 GapThickness = 5.*mm;
67 NbOfLayers = 10;
68 CalorSizeYZ = 10.*cm;
69 ComputeCalorParameters();
70
71 // materials
72 DefineMaterials();
73 SetAbsorberMaterial("Lead");
74 SetGapMaterial("liquidArgon");
75
76 // create commands for interactive definition of the calorimeter
77 detectorMessenger = new ExN03DetectorMessenger(this);
78}
79
80//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
81
82ExN03DetectorConstruction::~ExN03DetectorConstruction()
83{ delete detectorMessenger;}
84
85//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
86
87G4VPhysicalVolume* ExN03DetectorConstruction::Construct()
88{
89 return ConstructCalorimeter();
90}
91
92//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
93
94void ExN03DetectorConstruction::DefineMaterials()
95{
96 //This function illustrates the possible ways to define materials
97
98G4String symbol; //a=mass of a mole;
99G4double a, z, density; //z=mean number of protons;
100G4int iz, n; //iz=number of protons in an isotope;
101 // n=number of nucleons in an isotope;
102
103G4int ncomponents, natoms;
104G4double abundance, fractionmass;
105
106//
107// define Elements
108//
109
110G4Element* H = new G4Element("Hydrogen",symbol="H" , z= 1., a= 1.01*g/mole);
111G4Element* C = new G4Element("Carbon" ,symbol="C" , z= 6., a= 12.01*g/mole);
112G4Element* N = new G4Element("Nitrogen",symbol="N" , z= 7., a= 14.01*g/mole);
113G4Element* O = new G4Element("Oxygen" ,symbol="O" , z= 8., a= 16.00*g/mole);
114G4Element* Si = new G4Element("Silicon",symbol="Si" , z= 14., a= 28.09*g/mole);
115
116//
117// define an Element from isotopes, by relative abundance
118//
119
120G4Isotope* U5 = new G4Isotope("U235", iz=92, n=235, a=235.01*g/mole);
121G4Isotope* U8 = new G4Isotope("U238", iz=92, n=238, a=238.03*g/mole);
122
123G4Element* U = new G4Element("enriched Uranium",symbol="U",ncomponents=2);
124U->AddIsotope(U5, abundance= 90.*perCent);
125U->AddIsotope(U8, abundance= 10.*perCent);
126
127//
128// define simple materials
129//
130
131new G4Material("Aluminium", z=13., a=26.98*g/mole, density=2.700*g/cm3);
132new G4Material("liquidArgon", z=18., a= 39.95*g/mole, density= 1.390*g/cm3);
133new G4Material("Lead" , z=82., a= 207.19*g/mole, density= 11.35*g/cm3);
134
135//
136// define a material from elements. case 1: chemical molecule
137//
138
139G4Material* H2O =
140new G4Material("Water", density= 1.000*g/cm3, ncomponents=2);
141H2O->AddElement(H, natoms=2);
142H2O->AddElement(O, natoms=1);
143// overwrite computed meanExcitationEnergy with ICRU recommended value
144H2O->GetIonisation()->SetMeanExcitationEnergy(75.0*eV);
145
146G4Material* Sci =
147new G4Material("Scintillator", density= 1.032*g/cm3, ncomponents=2);
148Sci->AddElement(C, natoms=9);
149Sci->AddElement(H, natoms=10);
150
151G4Material* Myl =
152new G4Material("Mylar", density= 1.397*g/cm3, ncomponents=3);
153Myl->AddElement(C, natoms=10);
154Myl->AddElement(H, natoms= 8);
155Myl->AddElement(O, natoms= 4);
156
157G4Material* SiO2 =
158new G4Material("quartz",density= 2.200*g/cm3, ncomponents=2);
159SiO2->AddElement(Si, natoms=1);
160SiO2->AddElement(O , natoms=2);
161
162//
163// define a material from elements. case 2: mixture by fractional mass
164//
165
166G4Material* Air =
167new G4Material("Air" , density= 1.290*mg/cm3, ncomponents=2);
168Air->AddElement(N, fractionmass=0.7);
169Air->AddElement(O, fractionmass=0.3);
170
171//
172// define a material from elements and/or others materials (mixture of mixtures)
173//
174
175G4Material* Aerog =
176new G4Material("Aerogel", density= 0.200*g/cm3, ncomponents=3);
177Aerog->AddMaterial(SiO2, fractionmass=62.5*perCent);
178Aerog->AddMaterial(H2O , fractionmass=37.4*perCent);
179Aerog->AddElement (C , fractionmass= 0.1*perCent);
180
181//
182// examples of gas in non STP conditions
183//
184
185G4Material* CO2 =
186new G4Material("CarbonicGas", density= 1.842*mg/cm3, ncomponents=2,
187 kStateGas, 325.*kelvin, 50.*atmosphere);
188CO2->AddElement(C, natoms=1);
189CO2->AddElement(O, natoms=2);
190
191G4Material* steam =
192new G4Material("WaterSteam", density= 0.3*mg/cm3, ncomponents=1,
193 kStateGas, 500.*kelvin, 2.*atmosphere);
194steam->AddMaterial(H2O, fractionmass=1.);
195
196//
197// examples of vacuum
198//
199
200G4Material* Vacuum =
201new G4Material("Galactic", z=1., a=1.01*g/mole,density= universe_mean_density,
202 kStateGas, 2.73*kelvin, 3.e-18*pascal);
203
204G4Material* beam =
205new G4Material("Beam", density= 1.e-5*g/cm3, ncomponents=1,
206 kStateGas, STP_Temperature, 2.e-2*bar);
207beam->AddMaterial(Air, fractionmass=1.);
208
209G4cout << *(G4Material::GetMaterialTable()) << G4endl;
210
211//default materials of the World
212defaultMaterial = Vacuum;
213}
214
215//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
216
217G4VPhysicalVolume* ExN03DetectorConstruction::ConstructCalorimeter()
218{
219
220 // Clean old geometry, if any
221 //
222 G4GeometryManager::GetInstance()->OpenGeometry();
223 G4PhysicalVolumeStore::GetInstance()->Clean();
224 G4LogicalVolumeStore::GetInstance()->Clean();
225 G4SolidStore::GetInstance()->Clean();
226
227 // complete the Calor parameters definition
228 ComputeCalorParameters();
229
230 //
231 // World
232 //
233 solidWorld = new G4Box("World", //its name
234 WorldSizeX/2,WorldSizeYZ/2,WorldSizeYZ/2); //its size
235
236 logicWorld = new G4LogicalVolume(solidWorld, //its solid
237 defaultMaterial, //its material
238 "World"); //its name
239
240 physiWorld = new G4PVPlacement(0, //no rotation
241 G4ThreeVector(), //at (0,0,0)
242 logicWorld, //its logical volume
243 "World", //its name
244 0, //its mother volume
245 false, //no boolean operation
246 0); //copy number
247
248 //
249 // Calorimeter
250 //
251 solidCalor=0; logicCalor=0; physiCalor=0;
252 solidLayer=0; logicLayer=0; physiLayer=0;
253
254 if (CalorThickness > 0.)
255 { solidCalor = new G4Box("Calorimeter", //its name
256 CalorThickness/2,CalorSizeYZ/2,CalorSizeYZ/2);//size
257
258 logicCalor = new G4LogicalVolume(solidCalor, //its solid
259 defaultMaterial, //its material
260 "Calorimeter"); //its name
261
262 physiCalor = new G4PVPlacement(0, //no rotation
263 G4ThreeVector(), //at (0,0,0)
264 logicCalor, //its logical volume
265 "Calorimeter", //its name
266 logicWorld, //its mother volume
267 false, //no boolean operation
268 0); //copy number
269
270 //
271 // Layer
272 //
273 solidLayer = new G4Box("Layer", //its name
274 LayerThickness/2,CalorSizeYZ/2,CalorSizeYZ/2); //size
275
276 logicLayer = new G4LogicalVolume(solidLayer, //its solid
277 defaultMaterial, //its material
278 "Layer"); //its name
279 if (NbOfLayers > 1)
280 physiLayer = new G4PVReplica("Layer", //its name
281 logicLayer, //its logical volume
282 logicCalor, //its mother
283 kXAxis, //axis of replication
284 NbOfLayers, //number of replica
285 LayerThickness); //witdth of replica
286 else
287 physiLayer = new G4PVPlacement(0, //no rotation
288 G4ThreeVector(), //at (0,0,0)
289 logicLayer, //its logical volume
290 "Layer", //its name
291 logicCalor, //its mother volume
292 false, //no boolean operation
293 0); //copy number
294 }
295
296 //
297 // Absorber
298 //
299 solidAbsorber=0; logicAbsorber=0; physiAbsorber=0;
300
301 if (AbsorberThickness > 0.)
302 { solidAbsorber = new G4Box("Absorber", //its name
303 AbsorberThickness/2,CalorSizeYZ/2,CalorSizeYZ/2);
304
305 logicAbsorber = new G4LogicalVolume(solidAbsorber, //its solid
306 AbsorberMaterial, //its material
307 AbsorberMaterial->GetName()); //name
308
309 physiAbsorber = new G4PVPlacement(0, //no rotation
310 G4ThreeVector(-GapThickness/2,0.,0.), //its position
311 logicAbsorber, //its logical volume
312 AbsorberMaterial->GetName(), //its name
313 logicLayer, //its mother
314 false, //no boulean operat
315 0); //copy number
316
317 }
318
319 //
320 // Gap
321 //
322 solidGap=0; logicGap=0; physiGap=0;
323
324 if (GapThickness > 0.)
325 { solidGap = new G4Box("Gap",
326 GapThickness/2,CalorSizeYZ/2,CalorSizeYZ/2);
327
328 logicGap = new G4LogicalVolume(solidGap,
329 GapMaterial,
330 GapMaterial->GetName());
331
332 physiGap = new G4PVPlacement(0, //no rotation
333 G4ThreeVector(AbsorberThickness/2,0.,0.), //its position
334 logicGap, //its logical volume
335 GapMaterial->GetName(), //its name
336 logicLayer, //its mother
337 false, //no boulean operat
338 0); //copy number
339 }
340
341 PrintCalorParameters();
342
343 //
344 // Visualization attributes
345 //
346 logicWorld->SetVisAttributes (G4VisAttributes::Invisible);
347
348 G4VisAttributes* simpleBoxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0));
349 simpleBoxVisAtt->SetVisibility(true);
350 logicCalor->SetVisAttributes(simpleBoxVisAtt);
351
352 /*
353 // Below are vis attributes that permits someone to test / play
354 // with the interactive expansion / contraction geometry system of the
355 // vis/OpenInventor driver :
356 {G4VisAttributes* simpleBoxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,0.0));
357 simpleBoxVisAtt->SetVisibility(true);
358 delete logicCalor->GetVisAttributes();
359 logicCalor->SetVisAttributes(simpleBoxVisAtt);}
360
361 {G4VisAttributes* atb= new G4VisAttributes(G4Colour(1.0,0.0,0.0));
362 logicLayer->SetVisAttributes(atb);}
363
364 {G4VisAttributes* atb= new G4VisAttributes(G4Colour(0.0,1.0,0.0));
365 atb->SetForceSolid(true);
366 logicAbsorber->SetVisAttributes(atb);}
367
368 {//Set opacity = 0.2 then transparency = 1 - 0.2 = 0.8
369 G4VisAttributes* atb= new G4VisAttributes(G4Colour(0.0,0.0,1.0,0.2));
370 atb->SetForceSolid(true);
371 logicGap->SetVisAttributes(atb);}
372 */
373
374 //
375 //always return the physical World
376 //
377 return physiWorld;
378}
379
380//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
381
382void ExN03DetectorConstruction::PrintCalorParameters()
383{
384 G4cout << "\n------------------------------------------------------------"
385 << "\n---> The calorimeter is " << NbOfLayers << " layers of: [ "
386 << AbsorberThickness/mm << "mm of " << AbsorberMaterial->GetName()
387 << " + "
388 << GapThickness/mm << "mm of " << GapMaterial->GetName() << " ] "
389 << "\n------------------------------------------------------------\n";
390}
391
392//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
393
394void ExN03DetectorConstruction::SetAbsorberMaterial(G4String materialChoice)
395{
396 // search the material by its name
397 G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
398 if (pttoMaterial) AbsorberMaterial = pttoMaterial;
399}
400
401//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
402
403void ExN03DetectorConstruction::SetGapMaterial(G4String materialChoice)
404{
405 // search the material by its name
406 G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
407 if (pttoMaterial) GapMaterial = pttoMaterial;
408}
409
410//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
411
412void ExN03DetectorConstruction::SetAbsorberThickness(G4double val)
413{
414 // change Absorber thickness and recompute the calorimeter parameters
415 AbsorberThickness = val;
416}
417
418//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
419
420void ExN03DetectorConstruction::SetGapThickness(G4double val)
421{
422 // change Gap thickness and recompute the calorimeter parameters
423 GapThickness = val;
424}
425
426//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
427
428void ExN03DetectorConstruction::SetCalorSizeYZ(G4double val)
429{
430 // change the transverse size and recompute the calorimeter parameters
431 CalorSizeYZ = val;
432}
433
434//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
435
436void ExN03DetectorConstruction::SetNbOfLayers(G4int val)
437{
438 NbOfLayers = val;
439}
440
441//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
442
443#include "G4FieldManager.hh"
444#include "G4TransportationManager.hh"
445
446void ExN03DetectorConstruction::SetMagField(G4double fieldValue)
447{
448 //apply a global uniform magnetic field along Z axis
449 G4FieldManager* fieldMgr
450 = G4TransportationManager::GetTransportationManager()->GetFieldManager();
451
452 if(magField) delete magField; //delete the existing magn field
453
454 if(fieldValue!=0.) // create a new one if non nul
455 { magField = new G4UniformMagField(G4ThreeVector(0.,0.,fieldValue));
456 fieldMgr->SetDetectorField(magField);
457 fieldMgr->CreateChordFinder(magField);
458 } else {
459 magField = 0;
460 fieldMgr->SetDetectorField(magField);
461 }
462}
463
464//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
465
466#include "G4RunManager.hh"
467
468void ExN03DetectorConstruction::UpdateGeometry()
469{
470 G4RunManager::GetRunManager()->DefineWorldVolume(ConstructCalorimeter());
471}
472
473//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Note: See TracBrowser for help on using the repository browser.