Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
examples/extended/electromagnetic/TestEm7/src/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 //
26 /// \file electromagnetic/TestEm7/src/DetectorConstruction.cc
27 /// \brief Implementation of the DetectorConstruction class
28 //
29 // $Id: DetectorConstruction.cc 68263 2013-03-20 10:16:46Z maire $
30 //
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 
34 #include "DetectorConstruction.hh"
35 #include "DetectorMessenger.hh"
36 
37 #include "G4Material.hh"
38 #include "G4Box.hh"
39 #include "G4LogicalVolume.hh"
40 #include "G4PVPlacement.hh"
41 #include "G4UniformMagField.hh"
42 
43 #include "G4GeometryManager.hh"
44 #include "G4PhysicalVolumeStore.hh"
45 #include "G4LogicalVolumeStore.hh"
46 #include "G4SolidStore.hh"
47 
48 #include "G4NistManager.hh"
49 #include "G4UnitsTable.hh"
50 
51 #include "G4FieldManager.hh"
53 #include "G4RunManager.hh"
54 
55 #include "G4PhysicalConstants.hh"
56 #include "G4SystemOfUnits.hh"
57 
58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
59 
62  fWorldMaterial(0),fAbsorMaterial(0),fMagField(0),fLAbsor(0),
63  fDetectorMessenger(0)
64 {
65  // default parameter values
66  fAbsorSizeX = fAbsorSizeYZ = 20*cm;
67  fWorldSizeX = fWorldSizeYZ = 1.2*fAbsorSizeX;
68 
69  fWorldMaterial = fAbsorMaterial = 0;
70  fMagField = 0;
71  fLAbsor = 0;
72 
73  fTallyNumber = 0;
74  for (G4int j=0; j<MaxTally; j++) {
75  fTallySize[j] = fTallyPosition[j] = G4ThreeVector();
76  fTallyMaterial[j] = 0;
77  fTallyMass[j] = 0.;
78  fLTally[j] = 0;
79  }
80 
81  DefineMaterials();
82  SetMaterial("Water");
83  for (G4int j=0; j<MaxTally; j++) { SetTallyMaterial(j,"Water");};
84 
85  // create commands for interactive definition of the detector
86  fDetectorMessenger = new DetectorMessenger(this);
87 }
88 
89 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
90 
92 { delete fDetectorMessenger;}
93 
94 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
95 
97 {
98  return ConstructVolumes();
99 }
100 
101 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
102 
103 void DetectorConstruction::DefineMaterials()
104 {
105  //
106  // define Elements
107  //
108  G4double z, a;
109 
110  G4Element* H = new G4Element("Hydrogen", "H", z= 1, a= 1.008*g/mole);
111  G4Element* N = new G4Element("Nitrogen", "N", z= 7, a= 14.01*g/mole);
112  G4Element* O = new G4Element("Oxygen" , "O", z= 8, a= 16.00*g/mole);
113 
114  //
115  // define Materials.
116  //
117  G4double density, temperature, pressure;
118  G4int ncomponents, natoms;
119  G4double fractionmass;
120 
121  G4Material* H2O =
122  new G4Material("Water", density= 1.0*g/cm3, ncomponents=2);
123  H2O->AddElement(H, natoms=2);
124  H2O->AddElement(O, natoms=1);
126 
127  // In this line both G4_WATER and Water_1.05 will be constructed
129  BuildMaterialWithNewDensity("Water_1.05","G4_WATER",1.05*g/cm3);
130 
131  G4Material* Air =
132  new G4Material("Air" , density= 1.290*mg/cm3, ncomponents=2);
133  Air->AddElement(N, fractionmass=0.7);
134  Air->AddElement(O, fractionmass=0.3);
135 
136  density = 1.e-5*g/cm3;
137  pressure = 2.e-2*bar;
138  temperature = STP_Temperature; // From PhysicalConstants.h .
139  G4Material* vac = new G4Material( "TechVacuum", density, 1,
140  kStateGas, temperature, pressure );
141  vac->AddMaterial( Air, 1. );
142 
143  density = universe_mean_density; //from PhysicalConstants.h
144  pressure = 3.e-18*pascal;
145  temperature = 2.73*kelvin;
146  G4Material* vacuum =
147  new G4Material("Galactic",z= 1,a= 1.008*g/mole,density,
148  kStateGas,temperature,pressure);
149 
150  //default materials
151  fWorldMaterial = vacuum;
152 }
153 
154 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
155 
156 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
157 {
162 
163  // World
164  //
165  G4Box*
166  sWorld = new G4Box("World", //name
167  fWorldSizeX/2,fWorldSizeYZ/2,fWorldSizeYZ/2); //dimensions
168 
170  lWorld = new G4LogicalVolume(sWorld, //shape
171  fWorldMaterial, //material
172  "World"); //name
173 
175  pWorld = new G4PVPlacement(0, //no rotation
176  G4ThreeVector(), //at (0,0,0)
177  lWorld, //logical volume
178  "World", //name
179  0, //mother volume
180  false, //no boolean operation
181  0); //copy number
182  //
183  // Absorber
184  //
185  G4Box*
186  sAbsor = new G4Box("Absorber", //name
187  fAbsorSizeX/2,fAbsorSizeYZ/2,fAbsorSizeYZ/2); //dimensions
188 
189  fLAbsor = new G4LogicalVolume(sAbsor, //shape
190  fAbsorMaterial, //material
191  "Absorber"); //name
192 
193 
194  new G4PVPlacement(0, //no rotation
195  G4ThreeVector(), //at (0,0,0)
196  fLAbsor, //logical volume
197  "Absorber", //name
198  lWorld, //mother volume
199  false, //no boolean operation
200  0); //copy number
201  //
202  // Tallies (optional)
203  //
204  if (fTallyNumber > 0) {
205  for (G4int j=1; j<=fTallyNumber; j++) {
206 
207  G4Box* sTally = new G4Box("Tally",
208  fTallySize[j].x()/2,fTallySize[j].y()/2,fTallySize[j].z()/2);
209 
210  fLTally[j] = new G4LogicalVolume(sTally,fTallyMaterial[j],"Tally");
211 
212  new G4PVPlacement(0, //no rotation
213  fTallyPosition[j], //position
214  fLTally[j], //logical volume
215  "Tally", //name
216  fLAbsor, //mother volume
217  false, //no boolean operation
218  j); //copy number
219 
220  fTallyMass[j] = fTallySize[j].x()*fTallySize[j].y()*fTallySize[j].z()
221  *(fTallyMaterial[j]->GetDensity());
222  }
223  }
224 
225  PrintParameters();
226 
227  //
228  //always return the World volume
229  //
230  return pWorld;
231 }
232 
233 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
234 
236 {
238  G4cout << "\n---------------------------------------------------------\n";
239  G4cout << "---> The Absorber is " << G4BestUnit(fAbsorSizeX,"Length")
240  << " of " << fAbsorMaterial->GetName() << G4endl;
241  G4cout << "\n---------------------------------------------------------\n";
242 
243  if (fTallyNumber > 0) {
244  G4cout << "---> There are " << fTallyNumber << " tallies : " << G4endl;
245  for (G4int j=1; j<=fTallyNumber; j++) {
246  G4cout << "fTally " << j << ": "
247  << fTallyMaterial[j]->GetName()
248  << ", mass = " << G4BestUnit(fTallyMass[j],"Mass")
249  << " size = " << G4BestUnit(fTallySize[j],"Length")
250  << " position = " << G4BestUnit(fTallyPosition[j],"Length")
251  << G4endl;
252  }
253  G4cout << "\n---------------------------------------------------------\n";
254  }
255 }
256 
257 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
258 
260 {
261  fAbsorSizeX = value; fWorldSizeX = 1.2*fAbsorSizeX;
263 }
264 
265 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
266 
268 {
269  fAbsorSizeYZ = value;
270  fWorldSizeYZ = 1.2*fAbsorSizeYZ;
272 }
273 
274 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
275 
276 void DetectorConstruction::SetMaterial(G4String materialChoice)
277 {
278  // search the material by its name
279  G4Material* pttoMaterial =
280  G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
281  if (pttoMaterial) {
282  fAbsorMaterial = pttoMaterial;
283  if(fLAbsor) {
284  fLAbsor->SetMaterial(fAbsorMaterial);
286  }
287  }
288 }
289 
290 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
291 
293 {
294  //apply a global uniform magnetic field along Z axis
295  G4FieldManager* fieldMgr
297 
298  if (fMagField) delete fMagField; //delete the existing magn field
299 
300  if (fieldValue!=0.) // create a new one if non nul
301  {
302  fMagField = new G4UniformMagField(G4ThreeVector(0.,0.,fieldValue));
303  fieldMgr->SetDetectorField(fMagField);
304  fieldMgr->CreateChordFinder(fMagField);
305  }
306  else
307  {
308  fMagField = 0;
309  fieldMgr->SetDetectorField(fMagField);
310  }
311 }
312 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
313 
315 {
316  fTallyNumber = value;
317 }
318 
319 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
320 
322 {
323  fTallySize[j] = value;
325 }
326 
327 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
328 
330 {
331  // search the material by its name
332  G4Material* pttoMaterial =
333  G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
334  if (pttoMaterial) {
335  fTallyMaterial[j] = pttoMaterial;
336  if(fLTally[j]) {
337  fLTally[j]->SetMaterial(fTallyMaterial[j]);
339  }
340  }
341 }
342 
343 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
344 
346 {
347 
348  fTallyPosition[j] = value;
350 }
351 
352 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
353 
355 {
357  G4RunManager::GetRunManager()->DefineWorldVolume(ConstructVolumes());
358 }
359 
360 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void GeometryHasBeenModified(G4bool prop=true)
G4IonisParamMat * GetIonisation() const
Definition: G4Material.hh:224
G4Material * FindOrBuildMaterial(const G4String &name, G4bool isotopes=true, G4bool warning=false)
G4Material * Air
Definition: TRTMaterials.hh:57
CLHEP::Hep3Vector G4ThreeVector
double x() const
G4bool SetDetectorField(G4Field *detectorField)
void AddMaterial(G4Material *material, G4double fraction)
Definition: G4Material.cc:450
G4double z
Definition: TRTMaterials.hh:39
int universe_mean_density
Definition: hepunit.py:307
Definition: G4Box.hh:63
void SetMeanExcitationEnergy(G4double value)
const G4String & GetName() const
Definition: G4Material.hh:176
static G4MaterialTable * GetMaterialTable()
Definition: G4Material.cc:564
G4double GetDensity() const
Definition: G4Material.hh:178
static void Clean()
Definition: G4SolidStore.cc:79
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
float STP_Temperature
Definition: hepunit.py:302
int G4int
Definition: G4Types.hh:78
static G4NistManager * Instance()
double z() const
virtual void DefineWorldVolume(G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
static G4PhysicalVolumeStore * GetInstance()
G4double density
Definition: TRTMaterials.hh:39
function g(Y1, Y2, PT2)
Definition: hijing1.383.f:5205
G4GLOB_DLL std::ostream G4cout
void PhysicsHasBeenModified()
#define pascal
static G4LogicalVolumeStore * GetInstance()
static G4SolidStore * GetInstance()
static G4GeometryManager * GetInstance()
static G4TransportationManager * GetTransportationManager()
G4FieldManager * GetFieldManager() const
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:74
double y() const
const XML_Char int const XML_Char * value
#define G4endl
Definition: G4ios.hh:61
**D E S C R I P T I O N
void OpenGeometry(G4VPhysicalVolume *vol=0)
void AddElement(G4Element *element, G4int nAtoms)
Definition: G4Material.cc:345
double G4double
Definition: G4Types.hh:76
void CreateChordFinder(G4MagneticField *detectorMagField)
void SetMaterial(G4Material *pMaterial)