Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
g3tog4/clGeometry/common/src/DetectorConstruction0.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 "DetectorConstruction0.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& materialName,
44  G4double hx, G4double hy, G4double hz)
46  fMessenger(nullptr),
47  fMaterialName(materialName),
48  fDimensions(hx, hy, hz),
49  fWorldVolume(nullptr)
50 {
52 }
53 
54 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
55 
57 {
58  delete fMessenger;
59 }
60 
61 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
62 
64 {
65  // Define materials via NIST manager
66  //
67  auto nistManager = G4NistManager::Instance();
68 
69  auto material = nistManager->FindOrBuildMaterial(fMaterialName);
70 
71  // World
72  //
73  auto sWorld
74  = new G4Box("World", //name
75  fDimensions.x(), //dimensions (half-lentghs)
76  fDimensions.y(),
77  fDimensions.z());
78 
80  = new G4LogicalVolume(sWorld, //shape
81  material, //material
82  "World"); //name
83 
84  auto pWorld
85  = new G4PVPlacement(0, //no rotation
86  G4ThreeVector(), //at (0,0,0)
87  fWorldVolume, //logical volume
88  "World", //name
89  0, //mother volume
90  false, //no boolean operation
91  0); //copy number
92 
93  //always return the root volume
94  //
95  return pWorld;
96 }
97 
98 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
99 
100 void DetectorConstruction0::SetMaterial(const G4String& materialName)
101 {
102  auto nistManager = G4NistManager::Instance();
103 
104  auto newMaterial = nistManager->FindOrBuildMaterial(materialName);
105  if ( ! newMaterial ) {
106  G4cerr << "Material " << materialName << " not found." << G4endl;
107  G4cerr << "The box material was not changed." << G4endl;
108  return;
109  }
110 
111  if ( fWorldVolume ) fWorldVolume->SetMaterial(newMaterial);
112  G4cout << "Material of box changed to " << materialName << G4endl;
113 }
114 
115 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
116 
118 {
121 
122  fDimensions = dimensions;
123 }
124 
125 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
126 
128 {
129  // Define /B5/detector command directory using generic messenger class
130  fMessenger = new G4GenericMessenger(this,
131  "/detector/",
132  "Detector control");
133 
134  // setMaterial command
135  auto& setMaterialCmd
136  = fMessenger->DeclareMethod("setMaterial",
138  "Set world material name.");
139  setMaterialCmd.SetParameterName("materialName", false);
140  setMaterialCmd.SetDefaultValue("G4_AIR");
141  setMaterialCmd.SetStates(G4State_PreInit);
142 
143  // setDimensions command
144  auto& setDimensionsCmd
145  = fMessenger->DeclareMethodWithUnit("setDimensions", "mm",
147  "Set world dimensions (in half lentgh).");
148  setDimensionsCmd.SetParameterName("dimensions", false);
149  setDimensionsCmd.SetStates(G4State_PreInit);
150 }
151 
152 //....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="")
virtual G4VPhysicalVolume * Construct()
double G4double
Definition: G4Types.hh:76
Command & SetStates(G4ApplicationState s0)
Definition: G4Box.hh:64
G4GLOB_DLL std::ostream G4cerr
void SetMaterial(const G4String &materialName)
Command & SetParameterName(const G4String &, G4bool, G4bool=false)
DetectorConstruction0(const G4String &materialName="G4_AIR", G4double hx=50 *CLHEP::cm, G4double hy=50 *CLHEP::cm, G4double hz=50 *CLHEP::cm)
G4GLOB_DLL std::ostream G4cout
double x() const
void SetDimensions(G4ThreeVector dimensions)
double y() const
static G4NistManager * Instance()