source: trunk/examples/extended/analysis/AnaEx01/src/AnaEx01DetectorConstruction.cc@ 1330

Last change on this file since 1330 was 1230, checked in by garnier, 16 years ago

update to geant4.9.3

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