Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
examples/extended/electromagnetic/TestEm11/src/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 //
26 /// \file electromagnetic/TestEm11/src/DetectorConstruction.cc
27 /// \brief Implementation of the DetectorConstruction class
28 //
29 // $Id: DetectorConstruction.cc 77288 2013-11-22 10:52:58Z gcosmo $
30 //
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 
34 #include "DetectorConstruction.hh"
35 #include "DetectorMessenger.hh"
36 
37 #include "G4NistManager.hh"
38 #include "G4Material.hh"
39 #include "G4Box.hh"
40 #include "G4LogicalVolume.hh"
41 #include "G4PVPlacement.hh"
42 #include "G4PVReplica.hh"
43 #include "G4UniformMagField.hh"
44 
45 #include "G4GeometryManager.hh"
46 #include "G4PhysicalVolumeStore.hh"
47 #include "G4LogicalVolumeStore.hh"
48 #include "G4SolidStore.hh"
49 
50 #include "G4UImanager.hh"
51 #include "G4UnitsTable.hh"
52 #include "G4PhysicalConstants.hh"
53 #include "G4SystemOfUnits.hh"
55 #include "G4AutoDelete.hh"
56 #include "G4RunManager.hh"
57 #include <iomanip>
58 
59 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
60 
62 :G4VUserDetectorConstruction(),fDefaultMaterial(0),fPhysiWorld(0),
63  fDetectorMessenger(0)
64 {
65  // default parameter values of the absorbers
66  fNbOfAbsor = 1;
67  fAbsorThickness[0] = 0*mm; //dummy, for initialization
68  fAbsorThickness[1] = 1*mm;
69  fAbsorSizeYZ = 1.*mm;
70  for (G4int iAbs=0; iAbs<MaxAbsor; iAbs++) {
71  fNbOfDivisions[iAbs] = 1;
72  }
73  ComputeParameters();
74 
75  // materials
76  DefineMaterials();
77  SetAbsorMaterial(1,"G4_Si");
78 
79  // create commands for interactive definition of the calorimeter
80  fDetectorMessenger = new DetectorMessenger(this);
81 }
82 
83 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
84 
86 {
87  delete fDetectorMessenger;
88 }
89 
90 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
91 
93 {
94  return ConstructVolumes();
95 }
96 
97 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
98 
99 void DetectorConstruction::DefineMaterials()
100 {
102 
103  man->FindOrBuildMaterial("G4_Al");
104  man->FindOrBuildMaterial("G4_Si");
105  man->FindOrBuildMaterial("G4_Fe");
106  man->FindOrBuildMaterial("G4_Cu");
107  man->FindOrBuildMaterial("G4_Ge");
108  man->FindOrBuildMaterial("G4_Mo");
109  man->FindOrBuildMaterial("G4_Ta");
110  man->FindOrBuildMaterial("G4_W");
111  man->FindOrBuildMaterial("G4_Au");
112  man->FindOrBuildMaterial("G4_Pb");
113  man->FindOrBuildMaterial("G4_PbWO4");
114  man->FindOrBuildMaterial("G4_SODIUM_IODIDE");
115 
116  man->FindOrBuildMaterial("G4_AIR");
117  man->FindOrBuildMaterial("G4_WATER");
118 
119  G4Element* H = man->FindOrBuildElement("H");
120  G4Element* O = man->FindOrBuildElement("O");
121 
122  G4Material* H2O =
123  new G4Material("Water", 1.000*g/cm3, 2);
124  H2O->AddElement(H, 2);
125  H2O->AddElement(O, 1);
127 
128  G4double density = universe_mean_density; //from PhysicalConstants.h
129  G4double pressure = 3.e-18*pascal;
130  G4double temperature = 2.73*kelvin;
131  G4Material* Galactic =
132  new G4Material("Galactic", 1., 1.008*g/mole, density,
133  kStateGas,temperature,pressure);
134 
135  fDefaultMaterial = Galactic;
136 
137  // G4cout << *(G4Material::GetMaterialTable()) << G4endl;
138 }
139 
140 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
141 
142 void DetectorConstruction::ComputeParameters()
143 {
144  // Compute total thickness of absorbers
145  fAbsorSizeX = 0.;
146  for (G4int iAbs=1; iAbs<=fNbOfAbsor; iAbs++) {
147  fAbsorSizeX += fAbsorThickness[iAbs];
148  }
149 }
150 
151 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
152 
153 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
154 {
155  // complete the Calor parameters definition
156  ComputeParameters();
157 
158  // Cleanup old geometry
163 
164  //
165  // World
166  //
167  G4Box* solidWorld =
168  new G4Box("World", //name
169  fAbsorSizeX/2,fAbsorSizeYZ/2,fAbsorSizeYZ/2); //size
170 
171  G4LogicalVolume* logicWorld =
172  new G4LogicalVolume(solidWorld, //solid
173  fDefaultMaterial, //material
174  "World"); //name
175 
176  fPhysiWorld =
177  new G4PVPlacement(0, //no rotation
178  G4ThreeVector(), //at (0,0,0)
179  logicWorld, //logical volume
180  "World", //name
181  0, //mother volume
182  false, //no boolean operation
183  0); //copy number
184 
185  //
186  // Absorbers
187  //
188  fXfront[0] = -0.5*fAbsorSizeX;
189  //
190  for (G4int k=1; k<=fNbOfAbsor; k++) {
191  G4Material* material = fAbsorMaterial[k];
192  G4String matname = material->GetName();
193 
194  G4Box* solidAbsor =
195  new G4Box(matname,fAbsorThickness[k]/2,fAbsorSizeYZ/2,fAbsorSizeYZ/2);
196 
197  G4LogicalVolume* logicAbsor =
198  new G4LogicalVolume(solidAbsor, // solid
199  material, // material
200  matname); // name
201 
202  fXfront[k] = fXfront[k-1] + fAbsorThickness[k-1];
203  G4double xcenter = fXfront[k]+0.5*fAbsorThickness[k];
204  G4ThreeVector position = G4ThreeVector(xcenter,0.,0.);
205 
206  new G4PVPlacement(0, //no rotation
207  position, //position
208  logicAbsor, //logical volume
209  matname, //name
210  logicWorld, //mother
211  false, //no boulean operat
212  k); //copy number
213 
214  // divisions, if any
215  //
216  G4double LayerThickness = fAbsorThickness[k]/fNbOfDivisions[k];
217  G4Box* solidLayer =
218  new G4Box(matname,LayerThickness/2,fAbsorSizeYZ/2,fAbsorSizeYZ/2);
219 
220  G4LogicalVolume* logicLayer =
221  new G4LogicalVolume(solidLayer, //solid
222  material, //material
223  matname); //name
224 
225  new G4PVReplica(matname, //name
226  logicLayer, //logical volume
227  logicAbsor, //mother
228  kXAxis, //axis of replication
229  fNbOfDivisions[k], //number of replica
230  LayerThickness); //witdth of replica
231  }
232 
233 
234  PrintParameters();
235 
236  //always return the physical World
237  //
238  return fPhysiWorld;
239 }
240 
241 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
242 
244 {
245  G4cout << "\n-------------------------------------------------------------"
246  << "\n ---> The Absorber is " << fNbOfAbsor << " layers of:";
247  for (G4int i=1; i<=fNbOfAbsor; i++)
248  {
249  G4cout << "\n \t" << std::setw(12) << fAbsorMaterial[i]->GetName() <<": "
250  << std::setw(6) << G4BestUnit(fAbsorThickness[i],"Length")
251  << " divided in " << fNbOfDivisions[i] << " slices";
252  }
253  G4cout << "\n-------------------------------------------------------------\n"
254  << G4endl;
255 }
256 
257 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
258 
260 {
261  // set the number of Absorbers
262  //
263  if (ival < 1 || ival > (MaxAbsor-1))
264  { G4cout << "\n ---> warning from SetfNbOfAbsor: "
265  << ival << " must be at least 1 and and most " << MaxAbsor-1
266  << ". Command refused" << G4endl;
267  return;
268  }
269  fNbOfAbsor = ival;
271 }
272 
273 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
274 
276 {
277  // search the material by its name
278  //
279  if (iabs > fNbOfAbsor || iabs <= 0)
280  { G4cout << "\n --->warning from SetfAbsorMaterial: absor number "
281  << iabs << " out of range. Command refused" << G4endl;
282  return;
283  }
284 
285  G4Material* pttoMaterial =
287  if (pttoMaterial) {
288  fAbsorMaterial[iabs] = pttoMaterial;
290  }
291 }
292 
293 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
294 
296 {
297  // change Absorber thickness
298  //
299  if (iabs > fNbOfAbsor || iabs <= 0)
300  { G4cout << "\n --->warning from SetfAbsorThickness: absor number "
301  << iabs << " out of range. Command refused" << G4endl;
302  return;
303  }
304  if (val <= DBL_MIN)
305  { G4cout << "\n --->warning from SetfAbsorThickness: thickness "
306  << val << " out of range. Command refused" << G4endl;
307  return;
308  }
309  fAbsorThickness[iabs] = val;
311 }
312 
313 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
314 
316 {
317  // change the transverse size
318  //
319  if (val <= DBL_MIN)
320  { G4cout << "\n --->warning from SetfAbsorSizeYZ: thickness "
321  << val << " out of range. Command refused" << G4endl;
322  return;
323  }
324  fAbsorSizeYZ = val;
326 }
327 
328 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
329 
331 {
332  // set the number of divisions
333  //
334  if (iabs > fNbOfAbsor || iabs < 1)
335  { G4cout << "\n --->warning from SetNbOfDivisions: absor number "
336  << iabs << " out of range. Command refused" << G4endl;
337  return;
338  }
339 
340  if (ival < 1)
341  { G4cout << "\n --->warning from SetNbOfDivisions: "
342  << ival << " must be at least 1. Command refused" << G4endl;
343  return;
344  }
345  fNbOfDivisions[iabs] = ival;
347 }
348 
349 
350 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
351 
353 {
354  if ( fFieldMessenger.Get() == 0 ) {
355  // Create global magnetic field messenger.
356  // Uniform magnetic field is then created automatically if
357  // the field value is not zero.
358  G4ThreeVector fieldValue = G4ThreeVector();
360  new G4GlobalMagFieldMessenger(fieldValue);
361  //msg->SetVerboseLevel(1);
363  fFieldMessenger.Put( msg );
364  }
365 }
366 
367 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
368 
G4IonisParamMat * GetIonisation() const
Definition: G4Material.hh:224
G4Material * FindOrBuildMaterial(const G4String &name, G4bool isotopes=true, G4bool warning=false)
CLHEP::Hep3Vector G4ThreeVector
int universe_mean_density
Definition: hepunit.py:307
Definition: G4Box.hh:63
void SetMeanExcitationEnergy(G4double value)
const G4String & GetName() const
Definition: G4Material.hh:176
value_type & Get() const
Definition: G4Cache.hh:253
static void Clean()
Definition: G4SolidStore.cc:79
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
int G4int
Definition: G4Types.hh:78
static G4NistManager * Instance()
static G4PhysicalVolumeStore * GetInstance()
string material
Definition: eplot.py:19
G4double density
Definition: TRTMaterials.hh:39
function g(Y1, Y2, PT2)
Definition: hijing1.383.f:5205
void Register(T *inst)
Definition: G4AutoDelete.hh:65
G4GLOB_DLL std::ostream G4cout
void PhysicsHasBeenModified()
#define pascal
static G4LogicalVolumeStore * GetInstance()
static G4SolidStore * GetInstance()
static G4GeometryManager * GetInstance()
void ReinitializeGeometry(G4bool destroyFirst=false, G4bool prop=true)
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:74
#define DBL_MIN
Definition: templates.hh:75
#define G4endl
Definition: G4ios.hh:61
void OpenGeometry(G4VPhysicalVolume *vol=0)
void AddElement(G4Element *element, G4int nAtoms)
Definition: G4Material.cc:345
double G4double
Definition: G4Types.hh:76
G4Element * FindOrBuildElement(G4int Z, G4bool isotopes=true)
void Put(const value_type &val) const
Definition: G4Cache.hh:257