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 B2/B2b/src/DetectorConstruction.cc
28/// \brief Implementation of the B2b::DetectorConstruction class
29
30#include "DetectorConstruction.hh"
31#include "DetectorMessenger.hh"
33#include "TrackerSD.hh"
34
35#include "G4Material.hh"
36#include "G4NistManager.hh"
37#include "G4SDManager.hh"
38
39#include "G4Box.hh"
40#include "G4Tubs.hh"
41#include "G4LogicalVolume.hh"
42#include "G4PVPlacement.hh"
43#include "G4PVParameterised.hh"
44#include "G4GlobalMagFieldMessenger.hh"
45#include "G4AutoDelete.hh"
46
47#include "G4GeometryTolerance.hh"
48#include "G4GeometryManager.hh"
49
50#include "G4UserLimits.hh"
51
52#include "G4VisAttributes.hh"
53#include "G4Colour.hh"
54
55#include "G4SystemOfUnits.hh"
56
57using namespace B2;
58
59namespace B2b
60{
61
62//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
63
64G4ThreadLocal
66
71
72//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
73
79
80//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
81
83{
84 // Define materials
86
87 // Define volumes
88 return DefineVolumes();
89}
90
91//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
92
94{
95 // Material definition
96
97 G4NistManager* nistManager = G4NistManager::Instance();
98
99 // Air defined using NIST Manager
100 nistManager->FindOrBuildMaterial("G4_AIR");
101
102 // Lead defined using NIST Manager
103 fTargetMaterial = nistManager->FindOrBuildMaterial("G4_Pb");
104
105 // Xenon gas defined using NIST Manager
106 fChamberMaterial = nistManager->FindOrBuildMaterial("G4_Xe");
107
108 // Print materials
109 G4cout << *(G4Material::GetMaterialTable()) << G4endl;
110}
111
112//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
113
115{
116 G4Material* air = G4Material::GetMaterial("G4_AIR");
117
118 // Sizes of the principal geometrical components (solids)
119
120 G4int NbOfChambers = 5;
121 G4double chamberSpacing = 80*cm; // from chamber center to center!
122
123 G4double chamberWidth = 20.0*cm; // width of the chambers
124 G4double targetLength = 5.0*cm; // full length of Target
125
126 G4double trackerLength = (NbOfChambers+1)*chamberSpacing;
127
128 G4double worldLength = 1.2 * (2*targetLength + trackerLength);
129
130 G4double targetRadius = 0.5*targetLength; // Radius of Target
131 targetLength = 0.5*targetLength; // Half length of the Target
132 G4double trackerSize = 0.5*trackerLength; // Half length of the Tracker
133
134 // Definitions of Solids, Logical Volumes, Physical Volumes
135
136 // World
137
138 G4GeometryManager::GetInstance()->SetWorldMaximumExtent(worldLength);
139
140 G4cout << "Computed tolerance = "
141 << G4GeometryTolerance::GetInstance()->GetSurfaceTolerance()/mm
142 << " mm" << G4endl;
143
144 auto worldS = new G4Box("world", // its name
145 worldLength / 2, worldLength / 2, worldLength / 2); // its size
146 auto worldLV = new G4LogicalVolume(worldS, // its solid
147 air, // its material
148 "World"); // its name
149
150 // Must place the World Physical volume unrotated at (0,0,0).
151 //
152 auto worldPV = new G4PVPlacement(nullptr, // no rotation
153 G4ThreeVector(), // at (0,0,0)
154 worldLV, // its logical volume
155 "World", // its name
156 nullptr, // its mother volume
157 false, // no boolean operations
158 0, // copy number
159 fCheckOverlaps); // checking overlaps
160
161 // Target
162
163 G4ThreeVector positionTarget = G4ThreeVector(0,0,-(targetLength+trackerSize));
164
165 auto targetS = new G4Tubs("target", 0., targetRadius, targetLength, 0. * deg, 360. * deg);
166 fLogicTarget = new G4LogicalVolume(targetS, fTargetMaterial, "Target", nullptr, nullptr, nullptr);
167 new G4PVPlacement(nullptr, // no rotation
168 positionTarget, // at (x,y,z)
169 fLogicTarget, // its logical volume
170 "Target", // its name
171 worldLV, // its mother volume
172 false, // no boolean operations
173 0, // copy number
174 fCheckOverlaps); // checking overlaps
175
176 G4cout << "Target is " << 2*targetLength/cm << " cm of "
177 << fTargetMaterial->GetName() << G4endl;
178
179 // Tracker
180
181 G4ThreeVector positionTracker = G4ThreeVector(0,0,0);
182
183 auto trackerS = new G4Tubs("tracker", 0, trackerSize, trackerSize, 0. * deg, 360. * deg);
184 auto trackerLV = new G4LogicalVolume(trackerS, air, "Tracker", nullptr, nullptr, nullptr);
185 new G4PVPlacement(nullptr, // no rotation
186 positionTracker, // at (x,y,z)
187 trackerLV, // its logical volume
188 "Tracker", // its name
189 worldLV, // its mother volume
190 false, // no boolean operations
191 0, // copy number
192 fCheckOverlaps); // checking overlaps
193
194 // Tracker segments
195
196 // An example of Parameterised volumes
197 // Dummy values for G4Tubs -- modified by parameterised volume
198
199 auto chamberS = new G4Tubs("tracker", 0, 100 * cm, 100 * cm, 0. * deg, 360. * deg);
201 new G4LogicalVolume(chamberS, fChamberMaterial, "Chamber", nullptr, nullptr, nullptr);
202
203 G4double firstPosition = -trackerSize + chamberSpacing;
204 G4double firstLength = trackerLength/10;
205 G4double lastLength = trackerLength;
206
207 G4VPVParameterisation* chamberParam =
209 NbOfChambers, // NoChambers
210 firstPosition, // Z of center of first
211 chamberSpacing, // Z spacing of centers
212 chamberWidth, // chamber width
213 firstLength, // initial length
214 lastLength); // final length
215
216 // dummy value : kZAxis -- modified by parameterised volume
217
218 new G4PVParameterised("Chamber", // their name
219 fLogicChamber, // their logical volume
220 trackerLV, // Mother logical volume
221 kZAxis, // Are placed along this axis
222 NbOfChambers, // Number of chambers
223 chamberParam, // The parametrisation
224 fCheckOverlaps); // checking overlaps
225
226 G4cout << "There are " << NbOfChambers << " chambers in the tracker region. "
227 << G4endl
228 << "The chambers are " << chamberWidth/cm << " cm of "
229 << fChamberMaterial->GetName() << G4endl
230 << "The distance between chamber is " << chamberSpacing/cm << " cm"
231 << G4endl;
232
233 // Visualization attributes
234
235 G4VisAttributes boxVisAtt(G4Colour::White());
236
237 worldLV ->SetVisAttributes(boxVisAtt);
238 fLogicTarget ->SetVisAttributes(boxVisAtt);
239 trackerLV ->SetVisAttributes(boxVisAtt);
240
241 G4VisAttributes chamberVisAtt(G4Colour::Yellow());
242 fLogicChamber->SetVisAttributes(chamberVisAtt);
243
244 // Example of User Limits
245 //
246 // Below is an example of how to set tracking constraints in a given
247 // logical volume
248 //
249 // Sets a max step length in the tracker region, with G4StepLimiter
250
251 G4double maxStep = 0.5*chamberWidth;
252 fStepLimit = new G4UserLimits(maxStep);
253 trackerLV->SetUserLimits(fStepLimit);
254
255 /// Set additional contraints on the track, with G4UserSpecialCuts
256 ///
257 /// G4double maxLength = 2*trackerLength, maxTime = 0.1*ns, minEkin = 10*MeV;
258 /// trackerLV->SetUserLimits(new G4UserLimits(maxStep,
259 /// maxLength,
260 /// maxTime,
261 /// minEkin));
262
263 // Always return the physical world
264
265 return worldPV;
266}
267
268//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
269
271{
272 // Sensitive detectors
273
274 G4String trackerChamberSDname = "B2/TrackerChamberSD";
275 auto aTrackerSD = new TrackerSD(trackerChamberSDname, "TrackerHitsCollection");
276 G4SDManager::GetSDMpointer()->AddNewDetector(aTrackerSD);
277 SetSensitiveDetector( fLogicChamber, aTrackerSD );
278
279 // Create global magnetic field messenger.
280 // Uniform magnetic field is then created automatically if
281 // the field value is not zero.
282 G4ThreeVector fieldValue = G4ThreeVector();
284 fMagFieldMessenger->SetVerboseLevel(1);
285
286 // Register the field messenger for deleting
287 G4AutoDelete::Register(fMagFieldMessenger);
288}
289
290//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
291
293{
294 G4NistManager* nistManager = G4NistManager::Instance();
295
296 G4Material* pttoMaterial =
297 nistManager->FindOrBuildMaterial(materialName);
298
299 if (fTargetMaterial != pttoMaterial) {
300 if ( pttoMaterial ) {
301 fTargetMaterial = pttoMaterial;
302 if (fLogicTarget) fLogicTarget->SetMaterial(fTargetMaterial);
303 G4cout
304 << G4endl
305 << "----> The target is made of " << materialName << G4endl;
306 } else {
307 G4cout
308 << G4endl
309 << "--> WARNING from SetTargetMaterial : "
310 << materialName << " not found" << G4endl;
311 }
312 }
313}
314
315//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
316
318{
319 G4NistManager* nistManager = G4NistManager::Instance();
320
321 G4Material* pttoMaterial =
322 nistManager->FindOrBuildMaterial(materialName);
323
324 if (fChamberMaterial != pttoMaterial) {
325 if ( pttoMaterial ) {
326 fChamberMaterial = pttoMaterial;
328 G4cout
329 << G4endl
330 << "----> The chambers are made of " << materialName << G4endl;
331 } else {
332 G4cout
333 << G4endl
334 << "--> WARNING from SetChamberMaterial : "
335 << materialName << " not found" << G4endl;
336 }
337 }
338}
339
340//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
341
343{
344 if ((fStepLimit)&&(maxStep>0.)) fStepLimit->SetMaxAllowedStep(maxStep);
345}
346
347//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
348
349}
Definition of the B2b::ChamberParameterisation class.
Definition of the B2::TrackerSD class.
Tracker sensitive detector class.
A parameterisation that describes a series of boxes along Z.
G4VPhysicalVolume * DefineVolumes()
static G4ThreadLocal G4GlobalMagFieldMessenger * fMagFieldMessenger
G4VPhysicalVolume * Construct() override
Messenger class that defines commands for B2b::DetectorConstruction.

Applications | User Support | Publications | Collaboration