Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExG4DetectorConstruction02.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 // $Id$
27 //
30 
33 
34 #include "G4Material.hh"
35 #include "G4NistManager.hh"
36 #include "G4Box.hh"
37 #include "G4LogicalVolume.hh"
38 #include "G4PVPlacement.hh"
39 
40 
41 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
42 
44  const G4String& boxMaterialName,
45  G4double boxHx, G4double boxHy, G4double boxHz,
46  const G4String& worldMaterialName,
47  G4double worldSizeFactor)
49  fMessenger(this),
50  fBoxMaterialName(boxMaterialName),
51  fWorldMaterialName(worldMaterialName),
52  fBoxDimensions(boxHx*2, boxHy*2, boxHz*2),
53  fWorldSizeFactor(worldSizeFactor),
54  fBoxVolume(0),
55  fWorldVolume(0)
56 {
57 }
58 
59 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
60 
62 {
63 }
64 
65 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
66 
68 {
69  // Define materials via NIST manager
70  //
71  G4NistManager* nistManager = G4NistManager::Instance();
72 
73  G4bool fromIsotopes = false;
74 
75  G4Material* worldMaterial
76  = nistManager->FindOrBuildMaterial(fWorldMaterialName, fromIsotopes);
77 
78  G4Material* boxMaterial
79  = nistManager->FindOrBuildMaterial(fBoxMaterialName, fromIsotopes);
80 
81  // Geometry parameters
82  //
83  G4ThreeVector worldDimensions = fBoxDimensions * fWorldSizeFactor;
84 
85 
86  // World
87  //
88  G4Box* sWorld
89  = new G4Box("World", //name
90  worldDimensions.x(), //dimensions (half-lentghs)
91  worldDimensions.y(),
92  worldDimensions.z());
93 
94  fWorldVolume
95  = new G4LogicalVolume(sWorld, //shape
96  worldMaterial, //material
97  "World"); //name
98 
99  G4VPhysicalVolume* pWorld
100  = new G4PVPlacement(0, //no rotation
101  G4ThreeVector(), //at (0,0,0)
102  fWorldVolume, //logical volume
103  "World", //name
104  0, //mother volume
105  false, //no boolean operation
106  0); //copy number
107 
108  // Box
109  //
110  G4Box* sBox
111  = new G4Box("Box", //its name
112  fBoxDimensions.x(), //dimensions (half-lengths)
113  fBoxDimensions.y(),
114  fBoxDimensions.z());
115 
116  fBoxVolume
117  = new G4LogicalVolume(sBox, //its shape
118  boxMaterial, //its material
119  "Box"); //its name
120 
121  new G4PVPlacement(0, //no rotation
122  G4ThreeVector(), //at (0,0,0)
123  fBoxVolume, //its logical volume
124  "Box", //its name
125  fWorldVolume, //its mother volume
126  false, //no boolean operation
127  0); //copy number
128 
129  //always return the root volume
130  //
131  return pWorld;
132 }
133 
134 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
135 
137 {
138  G4NistManager* nistManager = G4NistManager::Instance();
139  G4bool fromIsotopes = false;
140 
141  G4Material* newMaterial
142  = nistManager->FindOrBuildMaterial(materialName, fromIsotopes);
143 
144  if ( ! newMaterial ) {
145  G4cerr << "Material " << materialName << " not found." << G4endl;
146  G4cerr << "The box material was not changed." << G4endl;
147  return;
148  }
149 
150  if ( fBoxVolume ) fBoxVolume->SetMaterial(newMaterial);
151  G4cout << "Material of box changed to " << materialName << G4endl;
152 }
153 
154 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
155 
157 {
158  G4NistManager* nistManager = G4NistManager::Instance();
159  G4bool fromIsotopes = false;
160 
161  G4Material* newMaterial
162  = nistManager->FindOrBuildMaterial(materialName, fromIsotopes);
163 
164  if ( ! newMaterial ) {
165  G4cerr << "Material " << materialName << " not found." << G4endl;
166  G4cerr << "The box material was not changed." << G4endl;
167  return;
168  }
169 
170  if ( fWorldVolume ) fWorldVolume->SetMaterial(newMaterial);
171  G4cout << "Material of box changed to " << materialName << G4endl;
172 }
173 
174 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
175 
177  G4double hx, G4double hy, G4double hz)
178 {
181 
182  fBoxDimensions = G4ThreeVector(hx, hy, hz);
183 }
184 
185 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
186 
188 {
191 
192  fWorldSizeFactor = factor;
193 }
194 
195 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......