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