Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
B4DetectorConstruction.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$
27 //
30 
31 #include "B4DetectorConstruction.hh"
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"
40 #include "G4UniformMagField.hh"
41 
42 #include "G4GeometryManager.hh"
43 #include "G4PhysicalVolumeStore.hh"
44 #include "G4LogicalVolumeStore.hh"
45 #include "G4SolidStore.hh"
46 
47 #include "G4VisAttributes.hh"
48 #include "G4Colour.hh"
49 
50 #include "G4FieldManager.hh"
52 #include "G4GenericMessenger.hh"
53 
54 #include "G4PhysicalConstants.hh"
55 #include "G4SystemOfUnits.hh"
56 
57 #include <stdio.h>
58 
59 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
60 
63  fMessenger(0),
64  fMagField(0),
65  fAbsorberPV(0),
66  fGapPV(0),
67  fCheckOverlaps(true)
68 {
69  // Define /B4/det commands using generic messenger class
70  fMessenger
71  = new G4GenericMessenger(this, "/B4/det/", "Detector construction control");
72 
73  // Define /B4/det/setMagField command
74  G4GenericMessenger::Command& setMagFieldCmd
75  = fMessenger->DeclareMethod("setMagField",
77  "Define magnetic field value (in X direction");
78  setMagFieldCmd.SetUnitCategory("Magnetic flux density");
79 }
80 
81 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
82 
84 {
85  delete fMagField;
86  delete fMessenger;
87 }
88 
89 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
90 
92 {
93  // Define materials
94  DefineMaterials();
95 
96  // Define volumes
97  return DefineVolumes();
98 }
99 
100 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
101 
102 void B4DetectorConstruction::DefineMaterials()
103 {
104  // Lead material defined using NIST Manager
105  G4NistManager* nistManager = G4NistManager::Instance();
106  G4bool fromIsotopes = false;
107  nistManager->FindOrBuildMaterial("G4_Pb", fromIsotopes);
108 
109  // Liquid argon material
110  G4double a; // mass of a mole;
111  G4double z; // z=mean number of protons;
112  G4double density;
113  new G4Material("liquidArgon", z=18., a= 39.95*g/mole, density= 1.390*g/cm3);
114  // The argon by NIST Manager is a gas with a different density
115 
116  // Vacuum
117  new G4Material("Galactic", z=1., a=1.01*g/mole,density= universe_mean_density,
118  kStateGas, 2.73*kelvin, 3.e-18*pascal);
119 
120  // Print materials
122 }
123 
124 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
125 
126 G4VPhysicalVolume* B4DetectorConstruction::DefineVolumes()
127 {
128  // Geometry parameters
129  G4int nofLayers = 10;
130  G4double absoThickness = 10.*mm;
131  G4double gapThickness = 5.*mm;
132  G4double calorSizeXY = 10.*cm;
133 
134  G4double layerThickness = absoThickness + gapThickness;
135  G4double calorThickness = nofLayers * layerThickness;
136  G4double worldSizeXY = 1.2 * calorSizeXY;
137  G4double worldSizeZ = 1.2 * calorThickness;
138 
139  // Get materials
140  G4Material* defaultMaterial = G4Material::GetMaterial("Galactic");
141  G4Material* absorberMaterial = G4Material::GetMaterial("G4_Pb");
142  G4Material* gapMaterial = G4Material::GetMaterial("liquidArgon");
143 
144  if ( ! defaultMaterial || ! absorberMaterial || ! gapMaterial ) {
145  G4cerr << "Cannot retrieve materials already defined. " << G4endl;
146  G4cerr << "Exiting application " << G4endl;
147  exit(1);
148  }
149 
150  //
151  // World
152  //
153  G4VSolid* worldS
154  = new G4Box("World", // its name
155  worldSizeXY/2, worldSizeXY/2, worldSizeZ/2); // its size
156 
157  G4LogicalVolume* worldLV
158  = new G4LogicalVolume(
159  worldS, // its solid
160  defaultMaterial, // its material
161  "World"); // its name
162 
163  G4VPhysicalVolume* worldPV
164  = new G4PVPlacement(
165  0, // no rotation
166  G4ThreeVector(), // at (0,0,0)
167  worldLV, // its logical volume
168  "World", // its name
169  0, // its mother volume
170  false, // no boolean operation
171  0, // copy number
172  fCheckOverlaps); // checking overlaps
173 
174  //
175  // Calorimeter
176  //
177  G4VSolid* calorimeterS
178  = new G4Box("Calorimeter", // its name
179  calorSizeXY/2, calorSizeXY/2, calorThickness/2); // its size
180 
181  G4LogicalVolume* calorLV
182  = new G4LogicalVolume(
183  calorimeterS, // its solid
184  defaultMaterial, // its material
185  "Calorimeter"); // its name
186 
187  new G4PVPlacement(
188  0, // no rotation
189  G4ThreeVector(), // at (0,0,0)
190  calorLV, // its logical volume
191  "Calorimeter", // its name
192  worldLV, // its mother volume
193  false, // no boolean operation
194  0, // copy number
195  fCheckOverlaps); // checking overlaps
196 
197  //
198  // Layer
199  //
200  G4VSolid* layerS
201  = new G4Box("Layer", // its name
202  calorSizeXY/2, calorSizeXY/2, layerThickness/2); // its size
203 
204  G4LogicalVolume* layerLV
205  = new G4LogicalVolume(
206  layerS, // its solid
207  defaultMaterial, // its material
208  "Layer"); // its name
209 
210  new G4PVReplica(
211  "Layer", // its name
212  layerLV, // its logical volume
213  calorLV, // its mother
214  kZAxis, // axis of replication
215  nofLayers, // number of replica
216  layerThickness); // witdth of replica
217 
218  //
219  // Absorber
220  //
221  G4VSolid* absorberS
222  = new G4Box("Abso", // its name
223  calorSizeXY/2, calorSizeXY/2, absoThickness/2); // its size
224 
225  G4LogicalVolume* absorberLV
226  = new G4LogicalVolume(
227  absorberS, // its solid
228  absorberMaterial, // its material
229  "Abso"); // its name
230 
231  fAbsorberPV
232  = new G4PVPlacement(
233  0, // no rotation
234  G4ThreeVector(0., 0., -gapThickness/2), // its position
235  absorberLV, // its logical volume
236  "Abso", // its name
237  layerLV, // its mother volume
238  false, // no boolean operation
239  0, // copy number
240  fCheckOverlaps); // checking overlaps
241 
242  //
243  // Gap
244  //
245  G4VSolid* gapS
246  = new G4Box("Gap", // its name
247  calorSizeXY/2, calorSizeXY/2, gapThickness/2); // its size
248 
249  G4LogicalVolume* gapLV
250  = new G4LogicalVolume(
251  gapS, // its solid
252  gapMaterial, // its material
253  "Gap"); // its name
254 
255  fGapPV
256  = new G4PVPlacement(
257  0, // no rotation
258  G4ThreeVector(0., 0., absoThickness/2), // its position
259  gapLV, // its logical volume
260  "Gap", // its name
261  layerLV, // its mother volume
262  false, // no boolean operation
263  0, // copy number
264  fCheckOverlaps); // checking overlaps
265 
266  //
267  // print parameters
268  //
269  G4cout << "\n------------------------------------------------------------"
270  << "\n---> The calorimeter is " << nofLayers << " layers of: [ "
271  << absoThickness/mm << "mm of " << absorberMaterial->GetName()
272  << " + "
273  << gapThickness/mm << "mm of " << gapMaterial->GetName() << " ] "
274  << "\n------------------------------------------------------------\n";
275 
276  //
277  // Visualization attributes
278  //
280 
281  G4VisAttributes* simpleBoxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0));
282  simpleBoxVisAtt->SetVisibility(true);
283  calorLV->SetVisAttributes(simpleBoxVisAtt);
284 
285  //
286  // Always return the physical World
287  //
288  return worldPV;
289 }
290 
291 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
292 
294 {
295  // Apply a global uniform magnetic field along X axis
296  G4FieldManager* fieldManager
298 
299  // Delete the existing magnetic field
300  if ( fMagField ) delete fMagField;
301 
302  if ( fieldValue != 0. ) {
303  // create a new one if not null
304  fMagField
305  = new G4UniformMagField(G4ThreeVector(fieldValue, 0., 0.));
306 
307  fieldManager->SetDetectorField(fMagField);
308  fieldManager->CreateChordFinder(fMagField);
309  }
310  else {
311  fMagField = 0;
312  fieldManager->SetDetectorField(fMagField);
313  }
314 }