Geant4_10
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 // This example is provided by the Geant4-DNA collaboration
27 // Any report or published results obtained using the Geant4-DNA software
28 // shall cite the following Geant4-DNA collaboration publication:
29 // Med. Phys. 37 (2010) 4692-4708
30 // The Geant4-DNA web site is available at http://geant4-dna.org
31 //
32 
33 #include "DetectorConstruction.hh"
34 #include "DetectorMessenger.hh"
35 #include "G4SystemOfUnits.hh"
36 #include "G4UserLimits.hh"
37 #include "G4NistManager.hh"
38 #include "G4RunManager.hh"
39 
40 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
41 
43 :fPhysiWorld(NULL), fLogicWorld(NULL), fSolidWorld(NULL)
44 {
45  // create commands for interactive definition of the detector
46  fDetectorMessenger = new DetectorMessenger(this);
47 }
48 
49 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
50 
52 {
53  delete fDetectorMessenger;
54 }
55 
56 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
57 
59 
60 {
61  DefineMaterials();
62  return ConstructDetector();
63 }
64 
65 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
66 
67 void DetectorConstruction::DefineMaterials()
68 {
69 
70  // Water is defined from NIST material database
72 
73  G4Material * H2O = man->FindOrBuildMaterial("G4_WATER");
74 
75  // If one wishes to test other density value for water material, one should use instead:
76  // G4Material * H2O = man->BuildMaterialWithNewDensity("G4_WATER_MODIFIED","G4_WATER",1.100*g/cm3);
77 
78  // Note: any string for "G4_WATER_MODIFIED" parameter is accepted
79  // and "G4_WATER" parameter should not be changed
80  // Both materials are created and can be selected from dna.mac
81 
82  fWaterMaterial = H2O;
83 
84  //G4cout << "-> Density of water material (g/cm3)=" << fWaterMaterial->GetDensity()/(g/cm/cm/cm) << G4endl;
85 
87 }
88 
89 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
90 G4VPhysicalVolume* DetectorConstruction::ConstructDetector()
91 {
92 
93 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
94 
95  // WORLD VOLUME
96 
97  fWorldSizeX = 100*micrometer;
98  fWorldSizeY = fWorldSizeX;
99  fWorldSizeZ = fWorldSizeX;
100 
101  fSolidWorld = new G4Box("World", //its name
102  fWorldSizeX/2,fWorldSizeY/2,fWorldSizeZ/2); //its size
103 
104 
105  fLogicWorld = new G4LogicalVolume(fSolidWorld, //its solid
106  fWaterMaterial, //its material
107  "World"); //its name
108 
109  fPhysiWorld = new G4PVPlacement(0, //no rotation
110  G4ThreeVector(), //at (0,0,0)
111  "World", //its name
112  fLogicWorld, //its logical volume
113  0, //its mother volume
114  false, //no boolean operation
115  0); //copy number
116 
117 
118  // Visualization attributes
119  G4VisAttributes* worldVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0)); //White
120  worldVisAtt->SetVisibility(true);
121  fLogicWorld->SetVisAttributes(worldVisAtt);
122 
123  G4VisAttributes* worldVisAtt1 = new G4VisAttributes(G4Colour(1.0,0.0,0.0));
124  worldVisAtt1->SetVisibility(true);
125 
126  //
127 
128  // Shows how to introduce a 20 eV tracking cut
129  //fLogicWorld->SetUserLimits(new G4UserLimits(DBL_MAX,DBL_MAX,DBL_MAX,20*eV));
130 
131  return fPhysiWorld;
132 }
133 
134 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
135 
136 void DetectorConstruction::SetMaterial(G4String materialChoice)
137 {
138  // Search the material by its name
139  G4Material* pttoMaterial =
140  G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
141 
142  if (pttoMaterial)
143  {
144  fWaterMaterial = pttoMaterial;
145  fLogicWorld->SetMaterial(fWaterMaterial);
147  }
148 }
149 
150 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
151 
153 {
155  G4RunManager::GetRunManager()->DefineWorldVolume(ConstructDetector());
156 }
G4Material * FindOrBuildMaterial(const G4String &name, G4bool isotopes=true, G4bool warning=false)
CLHEP::Hep3Vector G4ThreeVector
Definition: G4Box.hh:63
G4VPhysicalVolume * Construct()
void SetVisibility(G4bool)
static G4MaterialTable * GetMaterialTable()
Definition: G4Material.cc:564
static G4NistManager * Instance()
virtual void DefineWorldVolume(G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
G4GLOB_DLL std::ostream G4cout
void PhysicsHasBeenModified()
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:74
#define G4endl
Definition: G4ios.hh:61
void SetMaterial(G4Material *pMaterial)
int micrometer
Definition: hepunit.py:34
void SetVisAttributes(const G4VisAttributes *pVA)