Loading...
Searching...
No Matches
DetectorConstruction.cc
Go to the documentation of this file.
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//
27/// \file B4/B4d/src/DetectorConstruction.cc
28/// \brief Implementation of the B4d::DetectorConstruction class
29
30#include "DetectorConstruction.hh"
31
32#include "G4Material.hh"
33#include "G4NistManager.hh"
34
35#include "G4Box.hh"
36#include "G4LogicalVolume.hh"
37#include "G4PVPlacement.hh"
38#include "G4PVReplica.hh"
39#include "G4GlobalMagFieldMessenger.hh"
40#include "G4AutoDelete.hh"
41
42#include "G4SDManager.hh"
43#include "G4SDChargedFilter.hh"
44#include "G4MultiFunctionalDetector.hh"
45#include "G4VPrimitiveScorer.hh"
46#include "G4PSEnergyDeposit.hh"
47#include "G4PSTrackLength.hh"
48
49#include "G4VisAttributes.hh"
50#include "G4Colour.hh"
51
52#include "G4PhysicalConstants.hh"
53#include "G4SystemOfUnits.hh"
54
55namespace B4d
56{
57
58//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
59
60G4ThreadLocal
62
63//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
64
66{
67 // Define materials
69
70 // Define volumes
71 return DefineVolumes();
72}
73
74//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
75
77{
78 // Lead material defined using NIST Manager
79 auto nistManager = G4NistManager::Instance();
80 nistManager->FindOrBuildMaterial("G4_Pb");
81
82 // Liquid argon material
83 G4double a; // mass of a mole;
84 G4double z; // z=mean number of protons;
85 G4double density;
86 new G4Material("liquidArgon", z=18., a= 39.95*g/mole, density= 1.390*g/cm3);
87 // The argon by NIST Manager is a gas with a different density
88
89 // Vacuum
90 new G4Material("Galactic", z=1., a=1.01*g/mole,density= universe_mean_density,
91 kStateGas, 2.73*kelvin, 3.e-18*pascal);
92
93 // Print materials
94 G4cout << *(G4Material::GetMaterialTable()) << G4endl;
95}
96
97//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
98
100{
101 // Geometry parameters
102 G4int nofLayers = 10;
103 G4double absoThickness = 10.*mm;
104 G4double gapThickness = 5.*mm;
105 G4double calorSizeXY = 10.*cm;
106
107 auto layerThickness = absoThickness + gapThickness;
108 auto calorThickness = nofLayers * layerThickness;
109 auto worldSizeXY = 1.2 * calorSizeXY;
110 auto worldSizeZ = 1.2 * calorThickness;
111
112 // Get materials
113 auto defaultMaterial = G4Material::GetMaterial("Galactic");
114 auto absorberMaterial = G4Material::GetMaterial("G4_Pb");
115 auto gapMaterial = G4Material::GetMaterial("liquidArgon");
116
117 if ( ! defaultMaterial || ! absorberMaterial || ! gapMaterial ) {
118 G4ExceptionDescription msg;
119 msg << "Cannot retrieve materials already defined.";
120 G4Exception("DetectorConstruction::DefineVolumes()",
121 "MyCode0001", FatalException, msg);
122 }
123
124 //
125 // World
126 //
127 auto worldS
128 = new G4Box("World", // its name
129 worldSizeXY/2, worldSizeXY/2, worldSizeZ/2); // its size
130
131 auto worldLV
132 = new G4LogicalVolume(
133 worldS, // its solid
134 defaultMaterial, // its material
135 "World"); // its name
136
137 auto worldPV = new G4PVPlacement(nullptr, // no rotation
138 G4ThreeVector(), // at (0,0,0)
139 worldLV, // its logical volume
140 "World", // its name
141 nullptr, // its mother volume
142 false, // no boolean operation
143 0, // copy number
144 fCheckOverlaps); // checking overlaps
145
146 //
147 // Calorimeter
148 //
149 auto calorimeterS
150 = new G4Box("Calorimeter", // its name
151 calorSizeXY/2, calorSizeXY/2, calorThickness/2); // its size
152
153 auto calorLV
154 = new G4LogicalVolume(
155 calorimeterS, // its solid
156 defaultMaterial, // its material
157 "Calorimeter"); // its name
158
159 new G4PVPlacement(nullptr, // no rotation
160 G4ThreeVector(), // at (0,0,0)
161 calorLV, // its logical volume
162 "Calorimeter", // its name
163 worldLV, // its mother volume
164 false, // no boolean operation
165 0, // copy number
166 fCheckOverlaps); // checking overlaps
167
168 //
169 // Layer
170 //
171 auto layerS
172 = new G4Box("Layer", // its name
173 calorSizeXY/2, calorSizeXY/2, layerThickness/2); // its size
174
175 auto layerLV
176 = new G4LogicalVolume(
177 layerS, // its solid
178 defaultMaterial, // its material
179 "Layer"); // its name
180
181 new G4PVReplica(
182 "Layer", // its name
183 layerLV, // its logical volume
184 calorLV, // its mother
185 kZAxis, // axis of replication
186 nofLayers, // number of replica
187 layerThickness); // witdth of replica
188
189 //
190 // Absorber
191 //
192 auto absorberS
193 = new G4Box("Abso", // its name
194 calorSizeXY/2, calorSizeXY/2, absoThickness/2); // its size
195
196 auto absorberLV
197 = new G4LogicalVolume(
198 absorberS, // its solid
199 absorberMaterial, // its material
200 "AbsoLV"); // its name
201
202 new G4PVPlacement(nullptr, // no rotation
203 G4ThreeVector(0., 0., -gapThickness / 2), // its position
204 absorberLV, // its logical volume
205 "Abso", // its name
206 layerLV, // its mother volume
207 false, // no boolean operation
208 0, // copy number
209 fCheckOverlaps); // checking overlaps
210
211 //
212 // Gap
213 //
214 auto gapS
215 = new G4Box("Gap", // its name
216 calorSizeXY/2, calorSizeXY/2, gapThickness/2); // its size
217
218 auto gapLV
219 = new G4LogicalVolume(
220 gapS, // its solid
221 gapMaterial, // its material
222 "GapLV"); // its name
223
224 new G4PVPlacement(nullptr, // no rotation
225 G4ThreeVector(0., 0., absoThickness / 2), // its position
226 gapLV, // its logical volume
227 "Gap", // its name
228 layerLV, // its mother volume
229 false, // no boolean operation
230 0, // copy number
231 fCheckOverlaps); // checking overlaps
232
233 //
234 // print parameters
235 //
236 G4cout
237 << G4endl
238 << "------------------------------------------------------------" << G4endl
239 << "---> The calorimeter is " << nofLayers << " layers of: [ "
240 << absoThickness/mm << "mm of " << absorberMaterial->GetName()
241 << " + "
242 << gapThickness/mm << "mm of " << gapMaterial->GetName() << " ] " << G4endl
243 << "------------------------------------------------------------" << G4endl;
244
245 //
246 // Visualization attributes
247 //
248 worldLV->SetVisAttributes(G4VisAttributes::GetInvisible());
249 calorLV->SetVisAttributes(G4VisAttributes(G4Colour::White()));
250
251 //
252 // Always return the physical World
253 //
254 return worldPV;
255}
256
257//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
258
260{
261 G4SDManager::GetSDMpointer()->SetVerboseLevel(1);
262 //
263 // Scorers
264 //
265
266 // declare Absorber as a MultiFunctionalDetector scorer
267 //
268 auto absDetector = new G4MultiFunctionalDetector("Absorber");
269 G4SDManager::GetSDMpointer()->AddNewDetector(absDetector);
270
271 G4VPrimitiveScorer* primitive;
272 primitive = new G4PSEnergyDeposit("Edep");
273 absDetector->RegisterPrimitive(primitive);
274
275 primitive = new G4PSTrackLength("TrackLength");
276 auto charged = new G4SDChargedFilter("chargedFilter");
277 primitive ->SetFilter(charged);
278 absDetector->RegisterPrimitive(primitive);
279
280 SetSensitiveDetector("AbsoLV",absDetector);
281
282 // declare Gap as a MultiFunctionalDetector scorer
283 //
284 auto gapDetector = new G4MultiFunctionalDetector("Gap");
285 G4SDManager::GetSDMpointer()->AddNewDetector(gapDetector);
286
287 primitive = new G4PSEnergyDeposit("Edep");
288 gapDetector->RegisterPrimitive(primitive);
289
290 primitive = new G4PSTrackLength("TrackLength");
291 primitive ->SetFilter(charged);
292 gapDetector->RegisterPrimitive(primitive);
293
294 SetSensitiveDetector("GapLV",gapDetector);
295
296 //
297 // Magnetic field
298 //
299 // Create global magnetic field messenger.
300 // Uniform magnetic field is then created automatically if
301 // the field value is not zero.
302 G4ThreeVector fieldValue;
304 fMagFieldMessenger->SetVerboseLevel(1);
305
306 // Register the field messenger for deleting
307 G4AutoDelete::Register(fMagFieldMessenger);
308}
309
310//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
311
312}
std::vector< ExP01TrackerHit * > a
G4VPhysicalVolume * Construct() override
G4VPhysicalVolume * DefineVolumes()
static G4ThreadLocal G4GlobalMagFieldMessenger * fMagFieldMessenger

Applications | User Support | Publications | Collaboration