Geant4  10.00.p01
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 77601 2013-11-26 17:08:44Z gcosmo $
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 
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
81 
82  // Define volumes
83  return DefineVolumes();
84 }
85 
86 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
87 
89 {
90  // Lead material defined using NIST Manager
91  G4NistManager* 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;
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 
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  G4double layerThickness = absoThickness + gapThickness;
120  G4double calorThickness = nofLayers * layerThickness;
121  G4double worldSizeXY = 1.2 * calorSizeXY;
122  G4double worldSizeZ = 1.2 * calorThickness;
123 
124  // Get materials
125  G4Material* defaultMaterial = G4Material::GetMaterial("Galactic");
126  G4Material* absorberMaterial = G4Material::GetMaterial("G4_Pb");
127  G4Material* 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  G4VSolid* worldS
140  = new G4Box("World", // its name
141  worldSizeXY/2, worldSizeXY/2, worldSizeZ/2); // its size
142 
143  G4LogicalVolume* worldLV
144  = new G4LogicalVolume(
145  worldS, // its solid
146  defaultMaterial, // its material
147  "World"); // its name
148 
149  G4VPhysicalVolume* 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  G4VSolid* calorimeterS
164  = new G4Box("Calorimeter", // its name
165  calorSizeXY/2, calorSizeXY/2, calorThickness/2); // its size
166 
167  G4LogicalVolume* 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  G4VSolid* layerS
187  = new G4Box("Layer", // its name
188  calorSizeXY/2, calorSizeXY/2, layerThickness/2); // its size
189 
190  G4LogicalVolume* 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  G4VSolid* absorberS
208  = new G4Box("Abso", // its name
209  calorSizeXY/2, calorSizeXY/2, absoThickness/2); // its size
210 
211  G4LogicalVolume* 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  G4VSolid* gapS
231  = new G4Box("Gap", // its name
232  calorSizeXY/2, calorSizeXY/2, gapThickness/2); // its size
233 
234  G4LogicalVolume* 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 << "\n------------------------------------------------------------"
254  << "\n---> The calorimeter is " << nofLayers << " layers of: [ "
255  << absoThickness/mm << "mm of " << absorberMaterial->GetName()
256  << " + "
257  << gapThickness/mm << "mm of " << gapMaterial->GetName() << " ] "
258  << "\n------------------------------------------------------------\n";
259 
260  //
261  // Visualization attributes
262  //
264 
265  G4VisAttributes* simpleBoxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0));
266  simpleBoxVisAtt->SetVisibility(true);
267  calorLV->SetVisAttributes(simpleBoxVisAtt);
268 
269  //
270  // Always return the physical World
271  //
272  return worldPV;
273 }
274 
275 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
276 
278 {
280  //
281  // Scorers
282  //
283 
284  // declare Absorber as a MultiFunctionalDetector scorer
285  //
286  G4MultiFunctionalDetector* absDetector
287  = new G4MultiFunctionalDetector("Absorber");
288 
289  G4VPrimitiveScorer* primitive;
290  primitive = new G4PSEnergyDeposit("Edep");
291  absDetector->RegisterPrimitive(primitive);
292 
293  primitive = new G4PSTrackLength("TrackLength");
294  G4SDChargedFilter* charged = new G4SDChargedFilter("chargedFilter");
295  primitive ->SetFilter(charged);
296  absDetector->RegisterPrimitive(primitive);
297 
298  SetSensitiveDetector("AbsoLV",absDetector);
299 
300  // declare Gap as a MultiFunctionalDetector scorer
301  //
302  G4MultiFunctionalDetector* gapDetector
303  = new G4MultiFunctionalDetector("Gap");
304 
305  primitive = new G4PSEnergyDeposit("Edep");
306  gapDetector->RegisterPrimitive(primitive);
307 
308  primitive = new G4PSTrackLength("TrackLength");
309  primitive ->SetFilter(charged);
310  gapDetector->RegisterPrimitive(primitive);
311 
312  SetSensitiveDetector("GapLV",gapDetector);
313 
314  //
315  // Magnetic field
316  //
317  // Create global magnetic field messenger.
318  // Uniform magnetic field is then created automatically if
319  // the field value is not zero.
320  G4ThreeVector fieldValue = G4ThreeVector();
323 
324  // Register the field messenger for deleting
326 }
327 
328 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
static const double cm
Definition: G4SIunits.hh:106
void SetVerboseLevel(G4int verboseLevel)
virtual G4VPhysicalVolume * Construct()
G4bool RegisterPrimitive(G4VPrimitiveScorer *)
G4Material * FindOrBuildMaterial(const G4String &name, G4bool isotopes=true, G4bool warning=false)
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
CLHEP::Hep3Vector G4ThreeVector
static G4Material * GetMaterial(const G4String &name, G4bool warning=true)
Definition: G4Material.cc:578
G4double z
Definition: TRTMaterials.hh:39
Definition: G4Box.hh:63
void SetVerboseLevel(G4int vl)
Definition: G4SDManager.hh:90
const G4String & GetName() const
Definition: G4Material.hh:176
void SetVisibility(G4bool)
static G4MaterialTable * GetMaterialTable()
Definition: G4Material.cc:564
void SetFilter(G4VSDFilter *f)
G4double a
Definition: TRTMaterials.hh:39
#define G4ThreadLocal
Definition: tls.hh:52
int G4int
Definition: G4Types.hh:78
static G4NistManager * Instance()
G4VPhysicalVolume * DefineVolumes()
G4double density
Definition: TRTMaterials.hh:39
void Register(T *inst)
Definition: G4AutoDelete.hh:65
G4GLOB_DLL std::ostream G4cout
static const double cm3
Definition: G4SIunits.hh:108
Definition of the B4dDetectorConstruction class.
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
static const double kelvin
Definition: G4SIunits.hh:260
#define pascal
Definition: G4SIunits.hh:213
static G4ThreadLocal G4GlobalMagFieldMessenger * fMagFieldMessenger
static const double g
Definition: G4SIunits.hh:162
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:40
static const G4VisAttributes Invisible
static const double mole
Definition: G4SIunits.hh:265
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
static const double mm
Definition: G4SIunits.hh:102
void SetVisAttributes(const G4VisAttributes *pVA)