Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
examples/extended/common/src/DetectorConstruction.cc
이 파일의 문서화 페이지로 가기
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 "DetectorConstruction.hh"
32 
33 #include "G4Material.hh"
34 #include "G4NistManager.hh"
35 #include "G4Box.hh"
36 #include "G4LogicalVolume.hh"
37 #include "G4PVPlacement.hh"
38 #include "G4GenericMessenger.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(nullptr),
49  fBoxMaterialName(boxMaterialName),
50  fWorldMaterialName(worldMaterialName),
51  fBoxDimensions(boxHx*2, boxHy*2, boxHz*2),
52  fWorldSizeFactor(worldSizeFactor),
53  fBoxVolume(nullptr),
54  fWorldVolume(nullptr)
55 {
57 }
58 
59 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
60 
62 {
63  delete fMessenger;
64 }
65 
66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
67 
69 {
70  // Define materials via NIST manager
71  //
72  auto nistManager = G4NistManager::Instance();
73 
74  auto worldMaterial = nistManager->FindOrBuildMaterial(fWorldMaterialName);
75  auto boxMaterial = nistManager->FindOrBuildMaterial(fBoxMaterialName);
76 
77  // Geometry parameters
78  //
79  G4ThreeVector worldDimensions = fBoxDimensions * fWorldSizeFactor;
80 
81  // World
82  //
83  auto sWorld
84  = new G4Box("World", //name
85  worldDimensions.x(), //dimensions (half-lentghs)
86  worldDimensions.y(),
87  worldDimensions.z());
88 
90  = new G4LogicalVolume(sWorld, //shape
91  worldMaterial, //material
92  "World"); //name
93 
94  auto pWorld
95  = new G4PVPlacement(0, //no rotation
96  G4ThreeVector(), //at (0,0,0)
97  fWorldVolume, //logical volume
98  "World", //name
99  0, //mother volume
100  false, //no boolean operation
101  0); //copy number
102 
103  // Box
104  //
105  auto sBox
106  = new G4Box("Box", //its name
107  fBoxDimensions.x(), //dimensions (half-lengths)
108  fBoxDimensions.y(),
109  fBoxDimensions.z());
110 
111  fBoxVolume
112  = new G4LogicalVolume(sBox, //its shape
113  boxMaterial, //its material
114  "Box"); //its name
115 
116  new G4PVPlacement(0, //no rotation
117  G4ThreeVector(), //at (0,0,0)
118  fBoxVolume, //its logical volume
119  "Box", //its name
120  fWorldVolume, //its mother volume
121  false, //no boolean operation
122  0); //copy number
123 
124  //always return the root volume
125  //
126  return pWorld;
127 }
128 
129 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
130 
132 {
133  auto nistManager = G4NistManager::Instance();
134 
135  auto newMaterial = nistManager->FindOrBuildMaterial(materialName);
136  if ( ! newMaterial ) {
137  G4cerr << "Material " << materialName << " not found." << G4endl;
138  G4cerr << "The box material was not changed." << G4endl;
139  return;
140  }
141 
142  if ( fBoxVolume ) fBoxVolume->SetMaterial(newMaterial);
143  G4cout << "Material of box changed to " << materialName << G4endl;
144 }
145 
146 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
147 
149 {
150  auto nistManager = G4NistManager::Instance();
151 
152  auto newMaterial = nistManager->FindOrBuildMaterial(materialName);
153  if ( ! newMaterial ) {
154  G4cerr << "Material " << materialName << " not found." << G4endl;
155  G4cerr << "The box material was not changed." << G4endl;
156  return;
157  }
158 
159  if ( fWorldVolume ) fWorldVolume->SetMaterial(newMaterial);
160  G4cout << "Material of box changed to " << materialName << G4endl;
161 }
162 
163 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
164 
166 {
169 
170  fBoxDimensions = dimensions;
171 }
172 
173 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
174 
176 {
179 
180  fWorldSizeFactor = factor;
181 }
182 
183 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
184 
186 {
187  // Define /B5/detector command directory using generic messenger class
188  fMessenger = new G4GenericMessenger(this,
189  "/detector/",
190  "Detector control");
191 
192  // setBoxMaterial command
193  auto& setBoxMaterialCmd
194  = fMessenger->DeclareMethod("setBoxMaterial",
196  "Set box material name.");
197  setBoxMaterialCmd.SetParameterName("boxMaterialName", false);
198  setBoxMaterialCmd.SetDefaultValue("G4_AIR");
199 
200  // setWorldMaterial command
201  auto& setWorldMaterialCmd
202  = fMessenger->DeclareMethod("setWorldMaterial",
204  "Set world material name.");
205  setWorldMaterialCmd.SetParameterName("worldMaterialName", false);
206  setWorldMaterialCmd.SetDefaultValue("G4_AIR");
207 
208  // setBoxDimensions command
209  auto& setBoxDimensionsCmd
210  = fMessenger->DeclareMethodWithUnit("setBoxDimensions", "mm",
212  "Set box dimensions (in half lentgh).");
213  setBoxDimensionsCmd.SetParameterName("boxDimensions", false);
214  setBoxDimensionsCmd.SetStates(G4State_PreInit);
215 
216  // setWorldSizeFactor command
217  auto& setWorldSizeFactorCmd
218  = fMessenger->DeclareMethod("setWorldSizeFactor",
220  "Set the multiplication factor from box dimensions to world dimensions.");
221  setWorldSizeFactorCmd.SetParameterName("worldSizeFactor", false);
222  setWorldSizeFactorCmd.SetRange("WorldSizeFactor >= 1");
223  setWorldSizeFactorCmd.SetStates(G4State_PreInit);
224 }
225 
226 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
This class is generic messenger.
CLHEP::Hep3Vector G4ThreeVector
Command & DeclareMethodWithUnit(const G4String &name, const G4String &defaultUnit, const G4AnyMethod &fun, const G4String &doc="")
#define G4endl
Definition: G4ios.hh:61
double z() const
Command & SetDefaultValue(const G4String &)
Command & DeclareMethod(const G4String &name, const G4AnyMethod &fun, const G4String &doc="")
void SetWorldMaterial(const G4String &materialName)
double G4double
Definition: G4Types.hh:76
Command & SetStates(G4ApplicationState s0)
Definition: G4Box.hh:64
Command & SetRange(const G4String &range)
G4GLOB_DLL std::ostream G4cerr
Command & SetParameterName(const G4String &, G4bool, G4bool=false)
G4GLOB_DLL std::ostream G4cout
double x() const
double y() const
static G4NistManager * Instance()