ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DetectorConstruction.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file 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 //
29 
30 #include "DetectorConstruction.hh"
31 
32 #include "G4Material.hh"
33 #include "G4NistManager.hh"
34 #include "G4Box.hh"
35 #include "G4LogicalVolume.hh"
36 #include "G4PVPlacement.hh"
37 #include "G4GenericMessenger.hh"
38 
39 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
40 
42  const G4String& boxMaterialName,
43  G4double boxHx, G4double boxHy, G4double boxHz,
44  const G4String& worldMaterialName,
45  G4double worldSizeFactor)
47  fMessenger(nullptr),
48  fBoxMaterialName(boxMaterialName),
49  fWorldMaterialName(worldMaterialName),
50  fBoxDimensions(boxHx*2, boxHy*2, boxHz*2),
51  fWorldSizeFactor(worldSizeFactor),
52  fBoxVolume(nullptr),
53  fWorldVolume(nullptr)
54 {
56 }
57 
58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
59 
61 {
62  delete fMessenger;
63 }
64 
65 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
66 
68 {
69  // Define materials via NIST manager
70  //
71  auto nistManager = G4NistManager::Instance();
72 
73  auto worldMaterial = nistManager->FindOrBuildMaterial(fWorldMaterialName);
74  auto boxMaterial = nistManager->FindOrBuildMaterial(fBoxMaterialName);
75 
76  // Geometry parameters
77  //
78  G4ThreeVector worldDimensions = fBoxDimensions * fWorldSizeFactor;
79 
80  // World
81  //
82  auto sWorld
83  = new G4Box("World", //name
84  worldDimensions.x(), //dimensions (half-lentghs)
85  worldDimensions.y(),
86  worldDimensions.z());
87 
89  = new G4LogicalVolume(sWorld, //shape
90  worldMaterial, //material
91  "World"); //name
92 
93  auto pWorld
94  = new G4PVPlacement(0, //no rotation
95  G4ThreeVector(), //at (0,0,0)
96  fWorldVolume, //logical volume
97  "World", //name
98  0, //mother volume
99  false, //no boolean operation
100  0); //copy number
101 
102  // Box
103  //
104  auto sBox
105  = new G4Box("Box", //its name
106  fBoxDimensions.x(), //dimensions (half-lengths)
107  fBoxDimensions.y(),
108  fBoxDimensions.z());
109 
110  fBoxVolume
111  = new G4LogicalVolume(sBox, //its shape
112  boxMaterial, //its material
113  "Box"); //its name
114 
115  new G4PVPlacement(0, //no rotation
116  G4ThreeVector(), //at (0,0,0)
117  fBoxVolume, //its logical volume
118  "Box", //its name
119  fWorldVolume, //its mother volume
120  false, //no boolean operation
121  0); //copy number
122 
123  //always return the root volume
124  //
125  return pWorld;
126 }
127 
128 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
129 
131 {
132  auto nistManager = G4NistManager::Instance();
133 
134  auto newMaterial = nistManager->FindOrBuildMaterial(materialName);
135  if ( ! newMaterial ) {
136  G4cerr << "Material " << materialName << " not found." << G4endl;
137  G4cerr << "The box material was not changed." << G4endl;
138  return;
139  }
140 
141  if ( fBoxVolume ) fBoxVolume->SetMaterial(newMaterial);
142  G4cout << "Material of box changed to " << materialName << G4endl;
143 }
144 
145 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
146 
148 {
149  auto nistManager = G4NistManager::Instance();
150 
151  auto newMaterial = nistManager->FindOrBuildMaterial(materialName);
152  if ( ! newMaterial ) {
153  G4cerr << "Material " << materialName << " not found." << G4endl;
154  G4cerr << "The box material was not changed." << G4endl;
155  return;
156  }
157 
158  if ( fWorldVolume ) fWorldVolume->SetMaterial(newMaterial);
159  G4cout << "Material of box changed to " << materialName << G4endl;
160 }
161 
162 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
163 
165 {
168 
169  fBoxDimensions = dimensions;
170 }
171 
172 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
173 
175 {
178 
179  fWorldSizeFactor = factor;
180 }
181 
182 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
183 
185 {
186  // Define /B5/detector command directory using generic messenger class
187  fMessenger = new G4GenericMessenger(this,
188  "/detector/",
189  "Detector control");
190 
191  // setBoxMaterial command
192  auto& setBoxMaterialCmd
193  = fMessenger->DeclareMethod("setBoxMaterial",
195  "Set box material name.");
196  setBoxMaterialCmd.SetParameterName("boxMaterialName", false);
197  setBoxMaterialCmd.SetDefaultValue("G4_AIR");
198 
199  // setWorldMaterial command
200  auto& setWorldMaterialCmd
201  = fMessenger->DeclareMethod("setWorldMaterial",
203  "Set world material name.");
204  setWorldMaterialCmd.SetParameterName("worldMaterialName", false);
205  setWorldMaterialCmd.SetDefaultValue("G4_AIR");
206 
207  // setBoxDimensions command
208  auto& setBoxDimensionsCmd
209  = fMessenger->DeclareMethodWithUnit("setBoxDimensions", "mm",
211  "Set box dimensions (in half lentgh).");
212  setBoxDimensionsCmd.SetParameterName("boxDimensions", false);
213  setBoxDimensionsCmd.SetStates(G4State_PreInit);
214 
215  // setWorldSizeFactor command
216  auto& setWorldSizeFactorCmd
217  = fMessenger->DeclareMethod("setWorldSizeFactor",
219  "Set the multiplication factor from box dimensions to world dimensions.");
220  setWorldSizeFactorCmd.SetParameterName("worldSizeFactor", false);
221  setWorldSizeFactorCmd.SetRange("WorldSizeFactor >= 1");
222  setWorldSizeFactorCmd.SetStates(G4State_PreInit);
223 }
224 
225 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......