Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 //
28 //
29 // $Id: DetectorConstruction.cc 66994 2013-01-29 14:34:08Z gcosmo $
30 //
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 
34 #include "DetectorConstruction.hh"
35 #include "DetectorMessenger.hh"
36 
37 #include "G4Material.hh"
38 #include "G4Box.hh"
39 #include "G4LogicalVolume.hh"
40 #include "G4PVPlacement.hh"
41 #include "G4UniformMagField.hh"
42 
43 #include "G4GeometryManager.hh"
44 #include "G4UserLimits.hh"
45 #include "G4PhysicalVolumeStore.hh"
46 #include "G4LogicalVolumeStore.hh"
47 #include "G4SolidStore.hh"
48 
49 #include "G4UnitsTable.hh"
50 #include "G4NistManager.hh"
51 
52 #include "G4MonopoleFieldSetup.hh"
53 #include "G4FieldManager.hh"
55 #include "G4ThreeVector.hh"
56 #include "G4RunManager.hh"
57 #include "G4SystemOfUnits.hh"
58 
59 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
60 
62 {
63  // default parameter values
64  fAbsorSizeX = fAbsorSizeYZ = 10 * cm;
65  fWorldSizeX = fWorldSizeYZ = 1.2 * fAbsorSizeX;
66  fMaxStepSize = 5 * mm;
67 
68  fAbsorMaterial = 0;
69  fMagField = 0;
70  fLogAbsor = 0;
72 
73  SetMaterial("G4_Al");
74  fWorldMaterial =
76 
77  // create commands for interactive definition of the detector
78  fDetectorMessenger = new DetectorMessenger(this);
79 }
80 
81 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
82 
84 {
85  delete fDetectorMessenger;
86 }
87 
88 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
89 
91 {
96 
97  /**************************** World *****************************/
98  G4Box * sWorld = new G4Box("world",
99  fWorldSizeX / 2, fWorldSizeYZ / 2, fWorldSizeYZ / 2);
100 
101  G4LogicalVolume * lWorld = new G4LogicalVolume(sWorld,
102  fWorldMaterial,
103  "world");
104 
105  G4VPhysicalVolume * pWorld = new G4PVPlacement(0, //no rotation
106  G4ThreeVector(), //at (0,0,0)
107  lWorld, //logical volume
108  "world", //name
109  0, //mother volume
110  false, //no boolean operation
111  0); //copy number
112 
113 
114  /************************** Absorber ***************************/
115  G4Box * sAbsor = new G4Box("Absorber",
116  fAbsorSizeX / 2, fAbsorSizeYZ / 2, fAbsorSizeYZ / 2);
117 
118  fLogAbsor = new G4LogicalVolume(sAbsor,
119  fAbsorMaterial,
120  "Absorber");
121 
122  new G4PVPlacement(0, //no rotation
123  G4ThreeVector(), //at (0,0,0)
124  fLogAbsor, //logical volume
125  "Absorber", //name
126  lWorld, //mother volume
127  false, //no boolean operation
128  0); //copy number
129  fLogAbsor->SetUserLimits(new G4UserLimits(fMaxStepSize));
130 
131  PrintParameters();
132 
133  /************ always return the World volume *****************/
134  return pWorld;
135 }
136 
137 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
138 
140 {
141  G4cout << "\n---------------------------------------------------------\n";
142  G4cout << "---> The Absorber is " << G4BestUnit(fAbsorSizeX, "Length")
143  << " of " << fAbsorMaterial->GetName() << G4endl;
144  G4cout << "\n---------------------------------------------------------\n";
145 
146 }
147 
148 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
149 
151 {
152  if(value > 0.0) {
153  fAbsorSizeX = value;
154  fWorldSizeX = 1.2 * fAbsorSizeX;
156  }
157 }
158 
159 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
160 
162 {
163  if(value > 0.0) {
164  fAbsorSizeYZ = value;
165  fWorldSizeYZ = 1.2 * fAbsorSizeYZ;
167  }
168 }
169 
170 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
171 
172 void DetectorConstruction::SetMaterial(const G4String& namemat)
173 {
174  // search the material by its name
176  if(!mat) {
177  G4cout << "!!! DetectorConstruction::SetMaterial: WARNING Material <"
178  << namemat << "> does not exist in DB" << G4endl;
179  return;
180  }
181  // new material is found out
182  if (mat != fAbsorMaterial) {
183  fAbsorMaterial = mat;
184  if(fLogAbsor) { fLogAbsor->SetMaterial(mat); }
186  }
187 }
188 
189 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
190 
192 {
193  fMonFieldSetup->SetMagField(fieldValue);
194 
195  //apply a global uniform magnetic field along Z axis
196  G4FieldManager * fieldMgr =
198 
199  if (fMagField) { delete fMagField; } //delete the existing magn field
200 
201  if (fieldValue != 0.) // create a new one if non nul
202  {
203  fMagField = new G4UniformMagField(G4ThreeVector(0., 0., fieldValue));
204  fieldMgr->SetDetectorField(fMagField);
205  fieldMgr->CreateChordFinder(fMagField);
206  }
207  else
208  {
209  fMagField = 0;
210  fieldMgr->SetDetectorField(fMagField);
211  }
212 }
213 
214 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
215 
217 {
218  fMaxStepSize = step;
219  if(fLogAbsor) { fLogAbsor->SetUserLimits(new G4UserLimits(fMaxStepSize)); }
220 }
221 
222 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
223 
225 {
227 }
228 
229 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......