Geant4  10.03.p03
 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 
31 #include "ExG4DetectorConstruction02.hh"
32 #include "ExG4DetectorConstruction02Messenger.hh"
33 
34 #include "G4Material.hh"
35 #include "G4NistManager.hh"
36 #include "G4Box.hh"
37 #include "G4LogicalVolume.hh"
38 #include "G4PVPlacement.hh"
39 
40 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
41 
43  const G4String& boxMaterialName,
44  G4double boxHx, G4double boxHy, G4double boxHz,
45  const G4String& worldMaterialName,
46  G4double worldSizeFactor)
48  fMessenger(this),
49  fBoxMaterialName(boxMaterialName),
50  fWorldMaterialName(worldMaterialName),
51  fBoxDimensions(boxHx*2, boxHy*2, boxHz*2),
52  fWorldSizeFactor(worldSizeFactor),
53  fBoxVolume(0),
54  fWorldVolume(0)
55 {
56 }
57 
58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
59 
61 {
62 }
63 
64 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
65 
67 {
68  // Define materials via NIST manager
69  //
70  G4NistManager* nistManager = G4NistManager::Instance();
71 
72  G4Material* worldMaterial
73  = nistManager->FindOrBuildMaterial(fWorldMaterialName);
74 
75  G4Material* boxMaterial
76  = nistManager->FindOrBuildMaterial(fBoxMaterialName);
77 
78  // Geometry parameters
79  //
80  G4ThreeVector worldDimensions = fBoxDimensions * fWorldSizeFactor;
81 
82 
83  // World
84  //
85  G4Box* sWorld
86  = new G4Box("World", //name
87  worldDimensions.x(), //dimensions (half-lentghs)
88  worldDimensions.y(),
89  worldDimensions.z());
90 
91  fWorldVolume
92  = new G4LogicalVolume(sWorld, //shape
93  worldMaterial, //material
94  "World"); //name
95 
96  G4VPhysicalVolume* pWorld
97  = new G4PVPlacement(0, //no rotation
98  G4ThreeVector(), //at (0,0,0)
99  fWorldVolume, //logical volume
100  "World", //name
101  0, //mother volume
102  false, //no boolean operation
103  0); //copy number
104 
105  // Box
106  //
107  G4Box* sBox
108  = new G4Box("Box", //its name
109  fBoxDimensions.x(), //dimensions (half-lengths)
110  fBoxDimensions.y(),
111  fBoxDimensions.z());
112 
113  fBoxVolume
114  = new G4LogicalVolume(sBox, //its shape
115  boxMaterial, //its material
116  "Box"); //its name
117 
118  new G4PVPlacement(0, //no rotation
119  G4ThreeVector(), //at (0,0,0)
120  fBoxVolume, //its logical volume
121  "Box", //its name
122  fWorldVolume, //its mother volume
123  false, //no boolean operation
124  0); //copy number
125 
126  //always return the root volume
127  //
128  return pWorld;
129 }
130 
131 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
132 
134 {
135  G4NistManager* nistManager = G4NistManager::Instance();
136 
137  G4Material* newMaterial
138  = nistManager->FindOrBuildMaterial(materialName);
139 
140  if ( ! newMaterial ) {
141  G4cerr << "Material " << materialName << " not found." << G4endl;
142  G4cerr << "The box material was not changed." << G4endl;
143  return;
144  }
145 
146  if ( fBoxVolume ) fBoxVolume->SetMaterial(newMaterial);
147  G4cout << "Material of box changed to " << materialName << G4endl;
148 }
149 
150 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
151 
153 {
154  G4NistManager* nistManager = G4NistManager::Instance();
155 
156  G4Material* newMaterial
157  = nistManager->FindOrBuildMaterial(materialName);
158 
159  if ( ! newMaterial ) {
160  G4cerr << "Material " << materialName << " not found." << G4endl;
161  G4cerr << "The box material was not changed." << G4endl;
162  return;
163  }
164 
165  if ( fWorldVolume ) fWorldVolume->SetMaterial(newMaterial);
166  G4cout << "Material of box changed to " << materialName << G4endl;
167 }
168 
169 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
170 
172  G4double hx, G4double hy, G4double hz)
173 {
176 
177  fBoxDimensions = G4ThreeVector(hx, hy, hz);
178 }
179 
180 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
181 
183 {
186 
187  fWorldSizeFactor = factor;
188 }
189 
190 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
virtual G4VPhysicalVolume * Construct()
G4Material * FindOrBuildMaterial(const G4String &name, G4bool isotopes=true, G4bool warning=false)
CLHEP::Hep3Vector G4ThreeVector
double x() const
void SetWorldMaterial(const G4String &materialName)
Definition: G4Box.hh:64
void SetBoxDimensions(G4double hx, G4double hy, G4double hz)
static G4NistManager * Instance()
double z() const
G4GLOB_DLL std::ostream G4cout
void SetBoxMaterial(const G4String &materialName)
double y() const
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
void SetMaterial(G4Material *pMaterial)
ExG4DetectorConstruction02(const G4String &boxMaterialName="G4_AIR", G4double boxHx=40 *CLHEP::cm, G4double boxHy=40 *CLHEP::cm, G4double boxHz=40 *CLHEP::cm, const G4String &worldMaterialName="G4_AIR", G4double worldSizeFactor=1.25)
G4GLOB_DLL std::ostream G4cerr