ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DetectorConstruction0.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file 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 //
29 
30 #include "DetectorConstruction0.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& materialName,
45  fMessenger(nullptr),
46  fMaterialName(materialName),
47  fDimensions(hx, hy, hz),
48  fWorldVolume(nullptr)
49 {
51 }
52 
53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
54 
56 {
57  delete fMessenger;
58 }
59 
60 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
61 
63 {
64  // Define materials via NIST manager
65  //
66  auto nistManager = G4NistManager::Instance();
67 
68  auto material = nistManager->FindOrBuildMaterial(fMaterialName);
69 
70  // World
71  //
72  auto sWorld
73  = new G4Box("World", //name
74  fDimensions.x(), //dimensions (half-lentghs)
75  fDimensions.y(),
76  fDimensions.z());
77 
79  = new G4LogicalVolume(sWorld, //shape
80  material, //material
81  "World"); //name
82 
83  auto pWorld
84  = new G4PVPlacement(0, //no rotation
85  G4ThreeVector(), //at (0,0,0)
86  fWorldVolume, //logical volume
87  "World", //name
88  0, //mother volume
89  false, //no boolean operation
90  0); //copy number
91 
92  //always return the root volume
93  //
94  return pWorld;
95 }
96 
97 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
98 
100 {
101  auto nistManager = G4NistManager::Instance();
102 
103  auto newMaterial = nistManager->FindOrBuildMaterial(materialName);
104  if ( ! newMaterial ) {
105  G4cerr << "Material " << materialName << " not found." << G4endl;
106  G4cerr << "The box material was not changed." << G4endl;
107  return;
108  }
109 
110  if ( fWorldVolume ) fWorldVolume->SetMaterial(newMaterial);
111  G4cout << "Material of box changed to " << materialName << G4endl;
112 }
113 
114 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
115 
117 {
120 
121  fDimensions = dimensions;
122 }
123 
124 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
125 
127 {
128  // Define /B5/detector command directory using generic messenger class
129  fMessenger = new G4GenericMessenger(this,
130  "/detector/",
131  "Detector control");
132 
133  // setMaterial command
134  auto& setMaterialCmd
135  = fMessenger->DeclareMethod("setMaterial",
137  "Set world material name.");
138  setMaterialCmd.SetParameterName("materialName", false);
139  setMaterialCmd.SetDefaultValue("G4_AIR");
140  setMaterialCmd.SetStates(G4State_PreInit);
141 
142  // setDimensions command
143  auto& setDimensionsCmd
144  = fMessenger->DeclareMethodWithUnit("setDimensions", "mm",
146  "Set world dimensions (in half lentgh).");
147  setDimensionsCmd.SetParameterName("dimensions", false);
148  setDimensionsCmd.SetStates(G4State_PreInit);
149 }
150 
151 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......