Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DetectorConstruction.cc
Go to the documentation of this file.
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 //
28 //
29 
30 //
31 // $Id$
32 //
33 //
34 
35 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
36 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
37 
38 #include "DetectorConstruction.hh"
39 #include "DetectorMessenger.hh"
40 
41 #include "G4Material.hh"
42 #include "G4NistManager.hh"
43 #include "G4Box.hh"
44 #include "G4LogicalVolume.hh"
45 #include "G4PVPlacement.hh"
46 #include "G4UniformMagField.hh"
47 
48 #include "G4GeometryManager.hh"
49 #include "G4PhysicalVolumeStore.hh"
50 #include "G4LogicalVolumeStore.hh"
51 #include "G4SolidStore.hh"
52 
53 #include "G4UnitsTable.hh"
54 #include "G4SystemOfUnits.hh"
55 
56 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
57 
59 :fPBox(0), fLBox(0), fMaterial(0), fMagField(0)
60 {
61  fBoxSize = 10*m;
62  DefineMaterials();
63  SetMaterial("Molybdenum98");
64  fDetectorMessenger = new DetectorMessenger(this);
65 }
66 
67 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
68 
70 { delete fDetectorMessenger;}
71 
72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
73 
75 {
76  return ConstructVolumes();
77 }
78 
79 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
80 
81 void DetectorConstruction::DefineMaterials()
82 {
83  // define a Material from isotopes
84  //
85  MaterialWithSingleIsotope("Boron10", "B10", 2.46*g/cm3, 5, 10);
86  MaterialWithSingleIsotope("Boron11", "B11", 2.46*g/cm3, 5, 11);
87  MaterialWithSingleIsotope("Oxygen16", "O16", 1.43*g/cm3, 8, 16);
88  MaterialWithSingleIsotope("Cacium40", "Ca40", 1.55*g/cm3, 20, 40);
89  MaterialWithSingleIsotope("Zirconium90", "Zr90", 6.51*g/cm3, 40, 90);
90  MaterialWithSingleIsotope("Molybdenum98", "Mo98", 10.28*g/cm3, 42, 98);
91  MaterialWithSingleIsotope("Molybdenum100","Mo100", 10.28*g/cm3, 42, 100);
92  MaterialWithSingleIsotope("Lead208", "Pb208", 11.34*g/cm3, 82, 208);
93  MaterialWithSingleIsotope("Uranium235", "U235", 19.05*g/cm3, 92, 235);
94  MaterialWithSingleIsotope("Uranium238", "U238", 19.05*g/cm3, 92, 238);
95 
96  // or use G4-NIST materials data base
97  //
99  man->FindOrBuildMaterial("G4_B");
100 
102 }
103 
104 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
105 
108 {
109  // define a material from an isotope
110  //
111  G4int ncomponents;
112  G4double abundance, massfraction;
113 
114  G4Isotope* isotope = new G4Isotope(symbol, Z, A);
115 
116  G4Element* element = new G4Element(name, symbol, ncomponents=1);
117  element->AddIsotope(isotope, abundance= 100.*perCent);
118 
119  G4Material* material = new G4Material(name, density, ncomponents=1);
120  material->AddElement(element, massfraction=100.*perCent);
121 
122  return material;
123 }
124 
125 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
126 
127 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
128 {
129  // Cleanup old geometry
134 
135  G4Box*
136  sBox = new G4Box("Container", //its name
137  fBoxSize/2,fBoxSize/2,fBoxSize/2); //its dimensions
138 
139  fLBox = new G4LogicalVolume(sBox, //its shape
140  fMaterial, //its material
141  fMaterial->GetName()); //its name
142 
143  fPBox = new G4PVPlacement(0, //no rotation
144  G4ThreeVector(), //at (0,0,0)
145  fLBox, //its logical volume
146  fMaterial->GetName(), //its name
147  0, //its mother volume
148  false, //no boolean operation
149  0); //copy number
150 
151  PrintParameters();
152 
153  //always return the root volume
154  //
155  return fPBox;
156 }
157 
158 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
159 
161 {
162  G4cout << "\n The Box is " << G4BestUnit(fBoxSize,"Length")
163  << " of " << fMaterial->GetName()
164  << "\n \n" << fMaterial << G4endl;
165 }
166 
167 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
168 
169 void DetectorConstruction::SetMaterial(G4String materialChoice)
170 {
171  // search the material by its name
173  G4Material* pttoMaterial =
174  G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
175 
176  if (pttoMaterial) { fMaterial = pttoMaterial;
177  } else {
178  G4cout << "\n--> warning from DetectorConstruction::SetMaterial : "
179  << materialChoice << " not found" << G4endl;
180  }
181 }
182 
183 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
184 
186 {
187  fBoxSize = value;
188 }
189 
190 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
191 
192 #include "G4FieldManager.hh"
194 
196 {
197  //apply a global uniform magnetic field along Z axis
198  G4FieldManager* fieldMgr
200 
201  if (fMagField) delete fMagField; //delete the existing magn field
202 
203  if (fieldValue!=0.) // create a new one if non nul
204  {
205  fMagField = new G4UniformMagField(G4ThreeVector(0.,0.,fieldValue));
206  fieldMgr->SetDetectorField(fMagField);
207  fieldMgr->CreateChordFinder(fMagField);
208  }
209  else
210  {
211  fMagField = 0;
212  fieldMgr->SetDetectorField(fMagField);
213  }
214 }
215 
216 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
217 
218 #include "G4RunManager.hh"
219 
221 {
222  G4RunManager::GetRunManager()->DefineWorldVolume(ConstructVolumes());
223 }
224 
225 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......