G4OCCT 0.1.0
Geant4 interface to Open CASCADE Technology (OCCT) geometry definitions
Loading...
Searching...
No Matches
DetectorConstruction.cc
Go to the documentation of this file.
1// ********************************************************************
2// * License and Disclaimer *
3// * *
4// * The Geant4 software is copyright of the Copyright Holders of *
5// * the Geant4 Collaboration. It is provided under the terms and *
6// * conditions of the Geant4 Software License, included in the file *
7// * LICENSE and available at http://cern.ch/geant4/license . These *
8// * include a list of copyright holders. *
9// * *
10// * Neither the authors of this software system, nor their employing *
11// * institutes,nor the agencies providing financial support for this *
12// * work make any representation or warranty, express or implied, *
13// * regarding this software system or assume any liability for its *
14// * use. Please see the license in the file LICENSE and URL above *
15// * for the full disclaimer and the limitation of liability. *
16// * *
17// * This code implementation is the result of the scientific and *
18// * technical work of the GEANT4 collaboration. *
19// * By using, copying, modifying or distributing the software (or *
20// * any work based on the software) you agree to acknowledge its *
21// * use in resulting scientific publications, and indicate your *
22// * acceptance of all terms of the Geant4 Software license. *
23// ********************************************************************
24//
27
28#include "DetectorConstruction.hh"
29
30#include "CalorimeterSD.hh"
31
32#include "G4OCCT/G4OCCTSolid.hh"
33
34#include "G4AutoDelete.hh"
35#include "G4Box.hh"
36#include "G4Colour.hh"
37#include "G4GlobalMagFieldMessenger.hh"
38#include "G4LogicalVolume.hh"
39#include "G4Material.hh"
40#include "G4NistManager.hh"
41#include "G4PVPlacement.hh"
42#include "G4PVReplica.hh"
43#include "G4PhysicalConstants.hh"
44#include "G4SDManager.hh"
45#include "G4SystemOfUnits.hh"
46#include "G4VisAttributes.hh"
47
48#include <string>
49
50namespace B4c {
51
52//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
53
54G4ThreadLocal G4GlobalMagFieldMessenger* DetectorConstruction::fMagFieldMessenger = nullptr;
55
56//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
57
58G4VPhysicalVolume* DetectorConstruction::Construct() {
59 // Define materials
60 DefineMaterials();
61
62 // Define volumes
63 return DefineVolumes();
64}
65
66//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
67
68void DetectorConstruction::DefineMaterials() {
69 // Lead material defined using NIST Manager
70 auto nistManager = G4NistManager::Instance();
71 nistManager->FindOrBuildMaterial("G4_Pb");
72
73 // Liquid argon material
74 G4double a; // mass of a mole;
75 G4double z; // z=mean number of protons;
76 G4double density;
77 new G4Material("liquidArgon", z = 18., a = 39.95 * g / mole, density = 1.390 * g / cm3);
78 // The argon by NIST Manager is a gas with a different density
79
80 // Vacuum
81 new G4Material("Galactic", z = 1., a = 1.01 * g / mole, density = universe_mean_density,
82 kStateGas, 2.73 * kelvin, 3.e-18 * pascal);
83
84 // Print materials
85 G4cout << *(G4Material::GetMaterialTable()) << G4endl;
86}
87
88//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
89
90G4VPhysicalVolume* DetectorConstruction::DefineVolumes() {
91 // Geometry parameters
92 fNofLayers = 10;
93 G4double absoThickness = 10. * mm;
94 G4double gapThickness = 5. * mm;
95 G4double calorSizeXY = 10. * cm;
96
97 auto layerThickness = absoThickness + gapThickness;
98 auto calorThickness = fNofLayers * layerThickness;
99 auto worldSizeXY = 1.2 * calorSizeXY;
100 auto worldSizeZ = 1.2 * calorThickness;
101
102 // Get materials
103 auto defaultMaterial = G4Material::GetMaterial("Galactic");
104 auto absorberMaterial = G4Material::GetMaterial("G4_Pb");
105 auto gapMaterial = G4Material::GetMaterial("liquidArgon");
106
107 if (!defaultMaterial || !absorberMaterial || !gapMaterial) {
108 G4ExceptionDescription msg;
109 msg << "Cannot retrieve materials already defined.";
110 G4Exception("DetectorConstruction::DefineVolumes()", "MyCode0001", FatalException, msg);
111 }
112
113 //
114 // World
115 //
116 auto worldS = new G4Box("World", // its name
117 worldSizeXY / 2, worldSizeXY / 2, worldSizeZ / 2); // its size
118
119 auto worldLV = new G4LogicalVolume(worldS, // its solid
120 defaultMaterial, // its material
121 "World"); // its name
122
123 auto worldPV = new G4PVPlacement(nullptr, // no rotation
124 G4ThreeVector(), // at (0,0,0)
125 worldLV, // its logical volume
126 "World", // its name
127 nullptr, // its mother volume
128 false, // no boolean operation
129 0, // copy number
130 fCheckOverlaps); // checking overlaps
131
132 //
133 // Calorimeter
134 //
135 auto calorimeterS = new G4Box("Calorimeter", // its name
136 calorSizeXY / 2, calorSizeXY / 2, calorThickness / 2); // its size
137
138 auto calorLV = new G4LogicalVolume(calorimeterS, // its solid
139 defaultMaterial, // its material
140 "Calorimeter"); // its name
141
142 new G4PVPlacement(nullptr, // no rotation
143 G4ThreeVector(), // at (0,0,0)
144 calorLV, // its logical volume
145 "Calorimeter", // its name
146 worldLV, // its mother volume
147 false, // no boolean operation
148 0, // copy number
149 fCheckOverlaps); // checking overlaps
150
151 //
152 // Layer
153 //
154 auto layerS = new G4Box("Layer", // its name
155 calorSizeXY / 2, calorSizeXY / 2, layerThickness / 2); // its size
156
157 auto layerLV = new G4LogicalVolume(layerS, // its solid
158 defaultMaterial, // its material
159 "Layer"); // its name
160
161 new G4PVReplica("Layer", // its name
162 layerLV, // its logical volume
163 calorLV, // its mother
164 kZAxis, // axis of replication
165 fNofLayers, // number of replica
166 layerThickness); // width of replica
167
168 //
169 // Absorber — loaded from STEP file via G4OCCTSolid::FromSTEP
170 //
171 // The STEP box is centered at the origin and spans
172 // ±calorSizeXY/2 in x and y, ±absoThickness/2 in z.
173 //
174 const std::string stepDir = G4OCCT_B4C_STEP_DIR;
175 auto* absorberS = G4OCCTSolid::FromSTEP("Abso", stepDir + "/absorber.step");
176
177 auto absorberLV = new G4LogicalVolume(absorberS, // its solid
178 absorberMaterial, // its material
179 "AbsoLV"); // its name
180
181 new G4PVPlacement(nullptr, // no rotation
182 G4ThreeVector(0., 0., -gapThickness / 2), // its position
183 absorberLV, // its logical volume
184 "Abso", // its name
185 layerLV, // its mother volume
186 false, // no boolean operation
187 0, // copy number
188 fCheckOverlaps); // checking overlaps
189
190 //
191 // Gap — loaded from STEP file via G4OCCTSolid::FromSTEP
192 //
193 // The STEP box is centered at the origin and spans
194 // ±calorSizeXY/2 in x and y, ±gapThickness/2 in z.
195 //
196 auto* gapS = G4OCCTSolid::FromSTEP("Gap", stepDir + "/gap.step");
197
198 auto gapLV = new G4LogicalVolume(gapS, // its solid
199 gapMaterial, // its material
200 "GapLV"); // its name
201
202 new G4PVPlacement(nullptr, // no rotation
203 G4ThreeVector(0., 0., absoThickness / 2), // its position
204 gapLV, // its logical volume
205 "Gap", // its name
206 layerLV, // its mother volume
207 false, // no boolean operation
208 0, // copy number
209 fCheckOverlaps); // checking overlaps
210
211 //
212 // print parameters
213 //
214 G4cout << G4endl << "------------------------------------------------------------" << G4endl
215 << "---> The calorimeter is " << fNofLayers << " layers of: [ " << absoThickness / mm
216 << "mm of " << absorberMaterial->GetName() << " + " << gapThickness / mm << "mm of "
217 << gapMaterial->GetName() << " ] " << G4endl
218 << "------------------------------------------------------------" << G4endl;
219
220 //
221 // Visualization attributes
222 //
223 worldLV->SetVisAttributes(G4VisAttributes::GetInvisible());
224 calorLV->SetVisAttributes(G4VisAttributes(G4Colour::White()));
225
226 //
227 // Always return the physical World
228 //
229 return worldPV;
230}
231
232//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
233
235 // G4SDManager::GetSDMpointer()->SetVerboseLevel(1);
236
237 //
238 // Sensitive detectors
239 //
240 auto absoSD = new CalorimeterSD("AbsorberSD", "AbsorberHitsCollection", fNofLayers);
241 G4SDManager::GetSDMpointer()->AddNewDetector(absoSD);
242 SetSensitiveDetector("AbsoLV", absoSD);
243
244 auto gapSD = new CalorimeterSD("GapSD", "GapHitsCollection", fNofLayers);
245 G4SDManager::GetSDMpointer()->AddNewDetector(gapSD);
246 SetSensitiveDetector("GapLV", gapSD);
247
248 //
249 // Magnetic field
250 //
251 // Create global magnetic field messenger.
252 // Uniform magnetic field is then created automatically if
253 // the field value is not zero.
254 G4ThreeVector fieldValue;
255 fMagFieldMessenger = new G4GlobalMagFieldMessenger(fieldValue);
256 fMagFieldMessenger->SetVerboseLevel(1);
257
258 // Register the field messenger for deleting
259 G4AutoDelete::Register(fMagFieldMessenger);
260}
261
262//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
263
264} // namespace B4c
Definition of the B4c::CalorimeterSD class.
Declaration of G4OCCTSolid.
G4VPhysicalVolume * Construct() override
static G4OCCTSolid * FromSTEP(const G4String &name, const std::string &path)