Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
B4dDetectorConstruction.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 // $Id: B4dDetectorConstruction.cc 101905 2016-12-07 11:34:39Z gunter $
27 //
30 
32 
33 #include "G4Material.hh"
34 #include "G4NistManager.hh"
35 
36 #include "G4Box.hh"
37 #include "G4LogicalVolume.hh"
38 #include "G4PVPlacement.hh"
39 #include "G4PVReplica.hh"
41 #include "G4AutoDelete.hh"
42 
43 #include "G4SDManager.hh"
44 #include "G4SDChargedFilter.hh"
46 #include "G4VPrimitiveScorer.hh"
47 #include "G4PSEnergyDeposit.hh"
48 #include "G4PSTrackLength.hh"
49 
50 #include "G4VisAttributes.hh"
51 #include "G4Colour.hh"
52 
53 #include "G4PhysicalConstants.hh"
54 #include "G4SystemOfUnits.hh"
55 
56 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
57 
59 G4GlobalMagFieldMessenger* B4dDetectorConstruction::fMagFieldMessenger = 0;
60 
61 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
62 
65  fCheckOverlaps(true)
66 {
67 }
68 
69 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
70 
72 {
73 }
74 
75 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
76 
78 {
79  // Define materials
80  DefineMaterials();
81 
82  // Define volumes
83  return DefineVolumes();
84 }
85 
86 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
87 
88 void B4dDetectorConstruction::DefineMaterials()
89 {
90  // Lead material defined using NIST Manager
91  auto nistManager = G4NistManager::Instance();
92  nistManager->FindOrBuildMaterial("G4_Pb");
93 
94  // Liquid argon material
95  G4double a; // mass of a mole;
96  G4double z; // z=mean number of protons;
97  G4double density;
98  new G4Material("liquidArgon", z=18., a= 39.95*g/mole, density= 1.390*g/cm3);
99  // The argon by NIST Manager is a gas with a different density
100 
101  // Vacuum
102  new G4Material("Galactic", z=1., a=1.01*g/mole,density= universe_mean_density,
103  kStateGas, 2.73*kelvin, 3.e-18*pascal);
104 
105  // Print materials
107 }
108 
109 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
110 
111 G4VPhysicalVolume* B4dDetectorConstruction::DefineVolumes()
112 {
113  // Geometry parameters
114  G4int nofLayers = 10;
115  G4double absoThickness = 10.*mm;
116  G4double gapThickness = 5.*mm;
117  G4double calorSizeXY = 10.*cm;
118 
119  auto layerThickness = absoThickness + gapThickness;
120  auto calorThickness = nofLayers * layerThickness;
121  auto worldSizeXY = 1.2 * calorSizeXY;
122  auto worldSizeZ = 1.2 * calorThickness;
123 
124  // Get materials
125  auto defaultMaterial = G4Material::GetMaterial("Galactic");
126  auto absorberMaterial = G4Material::GetMaterial("G4_Pb");
127  auto gapMaterial = G4Material::GetMaterial("liquidArgon");
128 
129  if ( ! defaultMaterial || ! absorberMaterial || ! gapMaterial ) {
131  msg << "Cannot retrieve materials already defined.";
132  G4Exception("B4DetectorConstruction::DefineVolumes()",
133  "MyCode0001", FatalException, msg);
134  }
135 
136  //
137  // World
138  //
139  auto worldS
140  = new G4Box("World", // its name
141  worldSizeXY/2, worldSizeXY/2, worldSizeZ/2); // its size
142 
143  auto worldLV
144  = new G4LogicalVolume(
145  worldS, // its solid
146  defaultMaterial, // its material
147  "World"); // its name
148 
149  auto worldPV
150  = new G4PVPlacement(
151  0, // no rotation
152  G4ThreeVector(), // at (0,0,0)
153  worldLV, // its logical volume
154  "World", // its name
155  0, // its mother volume
156  false, // no boolean operation
157  0, // copy number
158  fCheckOverlaps); // checking overlaps
159 
160  //
161  // Calorimeter
162  //
163  auto calorimeterS
164  = new G4Box("Calorimeter", // its name
165  calorSizeXY/2, calorSizeXY/2, calorThickness/2); // its size
166 
167  auto calorLV
168  = new G4LogicalVolume(
169  calorimeterS, // its solid
170  defaultMaterial, // its material
171  "Calorimeter"); // its name
172 
173  new G4PVPlacement(
174  0, // no rotation
175  G4ThreeVector(), // at (0,0,0)
176  calorLV, // its logical volume
177  "Calorimeter", // its name
178  worldLV, // its mother volume
179  false, // no boolean operation
180  0, // copy number
181  fCheckOverlaps); // checking overlaps
182 
183  //
184  // Layer
185  //
186  auto layerS
187  = new G4Box("Layer", // its name
188  calorSizeXY/2, calorSizeXY/2, layerThickness/2); // its size
189 
190  auto layerLV
191  = new G4LogicalVolume(
192  layerS, // its solid
193  defaultMaterial, // its material
194  "Layer"); // its name
195 
196  new G4PVReplica(
197  "Layer", // its name
198  layerLV, // its logical volume
199  calorLV, // its mother
200  kZAxis, // axis of replication
201  nofLayers, // number of replica
202  layerThickness); // witdth of replica
203 
204  //
205  // Absorber
206  //
207  auto absorberS
208  = new G4Box("Abso", // its name
209  calorSizeXY/2, calorSizeXY/2, absoThickness/2); // its size
210 
211  auto absorberLV
212  = new G4LogicalVolume(
213  absorberS, // its solid
214  absorberMaterial, // its material
215  "AbsoLV"); // its name
216 
217  new G4PVPlacement(
218  0, // no rotation
219  G4ThreeVector(0., 0., -gapThickness/2), // its position
220  absorberLV, // its logical volume
221  "Abso", // its name
222  layerLV, // its mother volume
223  false, // no boolean operation
224  0, // copy number
225  fCheckOverlaps); // checking overlaps
226 
227  //
228  // Gap
229  //
230  auto gapS
231  = new G4Box("Gap", // its name
232  calorSizeXY/2, calorSizeXY/2, gapThickness/2); // its size
233 
234  auto gapLV
235  = new G4LogicalVolume(
236  gapS, // its solid
237  gapMaterial, // its material
238  "GapLV"); // its name
239 
240  new G4PVPlacement(
241  0, // no rotation
242  G4ThreeVector(0., 0., absoThickness/2), // its position
243  gapLV, // its logical volume
244  "Gap", // its name
245  layerLV, // its mother volume
246  false, // no boolean operation
247  0, // copy number
248  fCheckOverlaps); // checking overlaps
249 
250  //
251  // print parameters
252  //
253  G4cout
254  << G4endl
255  << "------------------------------------------------------------" << G4endl
256  << "---> The calorimeter is " << nofLayers << " layers of: [ "
257  << absoThickness/mm << "mm of " << absorberMaterial->GetName()
258  << " + "
259  << gapThickness/mm << "mm of " << gapMaterial->GetName() << " ] " << G4endl
260  << "------------------------------------------------------------" << G4endl;
261 
262  //
263  // Visualization attributes
264  //
265  worldLV->SetVisAttributes (G4VisAttributes::GetInvisible());
266 
267  auto simpleBoxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0));
268  simpleBoxVisAtt->SetVisibility(true);
269  calorLV->SetVisAttributes(simpleBoxVisAtt);
270 
271  //
272  // Always return the physical World
273  //
274  return worldPV;
275 }
276 
277 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
278 
280 {
282  //
283  // Scorers
284  //
285 
286  // declare Absorber as a MultiFunctionalDetector scorer
287  //
288  auto absDetector = new G4MultiFunctionalDetector("Absorber");
290 
291  G4VPrimitiveScorer* primitive;
292  primitive = new G4PSEnergyDeposit("Edep");
293  absDetector->RegisterPrimitive(primitive);
294 
295  primitive = new G4PSTrackLength("TrackLength");
296  auto charged = new G4SDChargedFilter("chargedFilter");
297  primitive ->SetFilter(charged);
298  absDetector->RegisterPrimitive(primitive);
299 
300  SetSensitiveDetector("AbsoLV",absDetector);
301 
302  // declare Gap as a MultiFunctionalDetector scorer
303  //
304  auto gapDetector = new G4MultiFunctionalDetector("Gap");
306 
307  primitive = new G4PSEnergyDeposit("Edep");
308  gapDetector->RegisterPrimitive(primitive);
309 
310  primitive = new G4PSTrackLength("TrackLength");
311  primitive ->SetFilter(charged);
312  gapDetector->RegisterPrimitive(primitive);
313 
314  SetSensitiveDetector("GapLV",gapDetector);
315 
316  //
317  // Magnetic field
318  //
319  // Create global magnetic field messenger.
320  // Uniform magnetic field is then created automatically if
321  // the field value is not zero.
322  G4ThreeVector fieldValue;
323  fMagFieldMessenger = new G4GlobalMagFieldMessenger(fieldValue);
324  fMagFieldMessenger->SetVerboseLevel(1);
325 
326  // Register the field messenger for deleting
327  G4AutoDelete::Register(fMagFieldMessenger);
328 }
329 
330 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void SetVerboseLevel(G4int verboseLevel)
virtual G4VPhysicalVolume * Construct()
static constexpr double mm
Definition: G4SIunits.hh:115
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
CLHEP::Hep3Vector G4ThreeVector
std::vector< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33
static G4Material * GetMaterial(const G4String &name, G4bool warning=true)
Definition: G4Material.cc:602
int universe_mean_density
Definition: hepunit.py:307
Definition: G4Box.hh:64
void SetVerboseLevel(G4int vl)
Definition: G4SDManager.hh:90
static G4MaterialTable * GetMaterialTable()
Definition: G4Material.cc:587
void SetFilter(G4VSDFilter *f)
#define G4ThreadLocal
Definition: tls.hh:89
int G4int
Definition: G4Types.hh:78
static G4NistManager * Instance()
function g(Y1, Y2, PT2)
Definition: hijing1.383.f:5205
void Register(T *inst)
Definition: G4AutoDelete.hh:65
G4GLOB_DLL std::ostream G4cout
static constexpr double cm
Definition: G4SIunits.hh:119
#define pascal
Definition of the B4dDetectorConstruction class.
static constexpr double kelvin
Definition: G4SIunits.hh:281
static constexpr double cm3
Definition: G4SIunits.hh:121
void SetSensitiveDetector(const G4String &logVolName, G4VSensitiveDetector *aSD, G4bool multi=false)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void AddNewDetector(G4VSensitiveDetector *aSD)
Definition: G4SDManager.cc:71
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:40
tuple z
Definition: test.py:28
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
static constexpr double mole
Definition: G4SIunits.hh:286
static const G4VisAttributes & GetInvisible()