Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Common::DetectorConstruction Class Reference

Simple detector construction with a box volume placed in a world. More...

#include <Doxymodules_common.h>

Inheritance diagram for Common::DetectorConstruction:
G4VUserDetectorConstruction

Public Member Functions

 DetectorConstruction (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)
 
 ~DetectorConstruction () override
 
G4VPhysicalVolumeConstruct () override
 
void SetBoxMaterial (const G4String &materialName)
 
void SetWorldMaterial (const G4String &materialName)
 
void SetBoxDimensions (G4ThreeVector dimensions)
 
void SetWorldSizeFactor (G4double factor)
 

Private Member Functions

void DefineCommands ()
 

Private Attributes

G4GenericMessengerfMessenger = nullptr
 
G4String fBoxMaterialName
 
G4String fWorldMaterialName
 
G4ThreeVector fBoxDimensions
 
G4double fWorldSizeFactor = 0.
 
G4LogicalVolumefBoxVolume = nullptr
 
G4LogicalVolumefWorldVolume = nullptr
 

Detailed Description

Simple detector construction with a box volume placed in a world.

Definition at line 12 of file Doxymodules_common.h.

Constructor & Destructor Documentation

◆ DetectorConstruction()

Common::DetectorConstruction::DetectorConstruction ( 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 
)

Definition at line 44 of file DetectorConstruction.cc.

49 : fBoxMaterialName(boxMaterialName),
50 fWorldMaterialName(worldMaterialName),
51 fBoxDimensions(boxHx*2, boxHy*2, boxHz*2),
52 fWorldSizeFactor(worldSizeFactor)
53{
55}

◆ ~DetectorConstruction()

Common::DetectorConstruction::~DetectorConstruction ( )
override

Definition at line 59 of file DetectorConstruction.cc.

60{
61 delete fMessenger;
62}

Member Function Documentation

◆ Construct()

G4VPhysicalVolume * Common::DetectorConstruction::Construct ( )
override

Definition at line 66 of file DetectorConstruction.cc.

67{
68 // Define materials via NIST manager
69 //
70 auto nistManager = G4NistManager::Instance();
71
72 auto worldMaterial = nistManager->FindOrBuildMaterial(fWorldMaterialName);
73 auto boxMaterial = nistManager->FindOrBuildMaterial(fBoxMaterialName);
74
75 // Geometry parameters
76 //
77 G4ThreeVector worldDimensions = fBoxDimensions * fWorldSizeFactor;
78
79 // World
80 //
81 auto sWorld
82 = new G4Box("World", //name
83 worldDimensions.x(), //dimensions (half-lentghs)
84 worldDimensions.y(),
85 worldDimensions.z());
86
88 = new G4LogicalVolume(sWorld, //shape
89 worldMaterial, //material
90 "World"); //name
91
92 auto pWorld
93 = new G4PVPlacement(0, //no rotation
94 G4ThreeVector(), //at (0,0,0)
95 fWorldVolume, //logical volume
96 "World", //name
97 0, //mother volume
98 false, //no boolean operation
99 0); //copy number
100
101 // Box
102 //
103 auto sBox
104 = new G4Box("Box", //its name
105 fBoxDimensions.x(), //dimensions (half-lengths)
106 fBoxDimensions.y(),
107 fBoxDimensions.z());
108
110 = new G4LogicalVolume(sBox, //its shape
111 boxMaterial, //its material
112 "Box"); //its name
113
114 new G4PVPlacement(0, //no rotation
115 G4ThreeVector(), //at (0,0,0)
116 fBoxVolume, //its logical volume
117 "Box", //its name
118 fWorldVolume, //its mother volume
119 false, //no boolean operation
120 0); //copy number
121
122 //always return the root volume
123 //
124 return pWorld;
125}

◆ SetBoxMaterial()

void Common::DetectorConstruction::SetBoxMaterial ( const G4String materialName)

Definition at line 129 of file DetectorConstruction.cc.

130{
131 auto nistManager = G4NistManager::Instance();
132
133 auto newMaterial = nistManager->FindOrBuildMaterial(materialName);
134 if ( ! newMaterial ) {
135 G4cerr << "Material " << materialName << " not found." << G4endl;
136 G4cerr << "The box material was not changed." << G4endl;
137 return;
138 }
139
140 if ( fBoxVolume ) fBoxVolume->SetMaterial(newMaterial);
141 G4cout << "Material of box changed to " << materialName << G4endl;
142}

◆ SetWorldMaterial()

void Common::DetectorConstruction::SetWorldMaterial ( const G4String materialName)

Definition at line 146 of file DetectorConstruction.cc.

147{
148 auto nistManager = G4NistManager::Instance();
149
150 auto newMaterial = nistManager->FindOrBuildMaterial(materialName);
151 if ( ! newMaterial ) {
152 G4cerr << "Material " << materialName << " not found." << G4endl;
153 G4cerr << "The box material was not changed." << G4endl;
154 return;
155 }
156
157 if ( fWorldVolume ) fWorldVolume->SetMaterial(newMaterial);
158 G4cout << "Material of box changed to " << materialName << G4endl;
159}

◆ SetBoxDimensions()

void Common::DetectorConstruction::SetBoxDimensions ( G4ThreeVector  dimensions)

Set box dimension (in half lengths). This setting has effect only if called in PreInit> phase

Definition at line 163 of file DetectorConstruction.cc.

164{
165/// Set box dimension (in half lengths).
166/// This setting has effect only if called in PreInit> phase
167
168 fBoxDimensions = dimensions;
169}

◆ SetWorldSizeFactor()

void Common::DetectorConstruction::SetWorldSizeFactor ( G4double  factor)

Set the multiplication factor from box dimensions to world dimensions. This setting has effect only if called in PreInit> phase

Definition at line 173 of file DetectorConstruction.cc.

174{
175/// Set the multiplication factor from box dimensions to world dimensions.
176/// This setting has effect only if called in PreInit> phase
177
178 fWorldSizeFactor = factor;
179}

◆ DefineCommands()

void Common::DetectorConstruction::DefineCommands ( )
private

Definition at line 183 of file DetectorConstruction.cc.

184{
185 // Define /B5/detector command directory using generic messenger class
187 "/detector/",
188 "Detector control");
189
190 // setBoxMaterial command
191 auto& setBoxMaterialCmd
192 = fMessenger->DeclareMethod("setBoxMaterial",
194 "Set box material name.");
195 setBoxMaterialCmd.SetParameterName("boxMaterialName", false);
196 setBoxMaterialCmd.SetDefaultValue("G4_AIR");
197
198 // setWorldMaterial command
199 auto& setWorldMaterialCmd
200 = fMessenger->DeclareMethod("setWorldMaterial",
202 "Set world material name.");
203 setWorldMaterialCmd.SetParameterName("worldMaterialName", false);
204 setWorldMaterialCmd.SetDefaultValue("G4_AIR");
205
206 // setBoxDimensions command
207 auto& setBoxDimensionsCmd
208 = fMessenger->DeclareMethodWithUnit("setBoxDimensions", "mm",
210 "Set box dimensions (in half lentgh).");
211 setBoxDimensionsCmd.SetParameterName("boxDimensions", false);
212 setBoxDimensionsCmd.SetStates(G4State_PreInit);
213
214 // setWorldSizeFactor command
215 auto& setWorldSizeFactorCmd
216 = fMessenger->DeclareMethod("setWorldSizeFactor",
218 "Set the multiplication factor from box dimensions to world dimensions.");
219 setWorldSizeFactorCmd.SetParameterName("worldSizeFactor", false);
220 setWorldSizeFactorCmd.SetRange("WorldSizeFactor >= 1");
221 setWorldSizeFactorCmd.SetStates(G4State_PreInit);
222}
void SetWorldMaterial(const G4String &materialName)
void SetBoxDimensions(G4ThreeVector dimensions)
void SetBoxMaterial(const G4String &materialName)
void SetWorldSizeFactor(G4double factor)

Member Data Documentation

◆ fMessenger

G4GenericMessenger* Common::DetectorConstruction::fMessenger = nullptr
private

Definition at line 71 of file DetectorConstruction.hh.

◆ fBoxMaterialName

G4String Common::DetectorConstruction::fBoxMaterialName
private

Definition at line 72 of file DetectorConstruction.hh.

◆ fWorldMaterialName

G4String Common::DetectorConstruction::fWorldMaterialName
private

Definition at line 73 of file DetectorConstruction.hh.

◆ fBoxDimensions

G4ThreeVector Common::DetectorConstruction::fBoxDimensions
private

Definition at line 74 of file DetectorConstruction.hh.

◆ fWorldSizeFactor

G4double Common::DetectorConstruction::fWorldSizeFactor = 0.
private

Definition at line 75 of file DetectorConstruction.hh.

◆ fBoxVolume

G4LogicalVolume* Common::DetectorConstruction::fBoxVolume = nullptr
private

Definition at line 76 of file DetectorConstruction.hh.

◆ fWorldVolume

G4LogicalVolume* Common::DetectorConstruction::fWorldVolume = nullptr
private

Definition at line 77 of file DetectorConstruction.hh.


The documentation for this class was generated from the following files:

Applications | User Support | Publications | Collaboration