Geant4  10.03.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 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 
71  ComputeParameters();
72 
73  // materials
74  DefineMaterials();
75  SetAbsorMaterial(1,"G4_Si");
76 
77  // create commands for interactive definition of the calorimeter
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 {
92  return ConstructVolumes();
93 }
94 
95 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
96 
97 void DetectorConstruction::DefineMaterials()
98 {
100 
101  man->FindOrBuildMaterial("G4_AIR");
102 
103  G4Element* H = man->FindOrBuildElement("H");
104  G4Element* O = man->FindOrBuildElement("O");
105 
106  G4Material* H2O =
107  new G4Material("Water", 1.000*g/cm3, 2);
108  H2O->AddElement(H, 2);
109  H2O->AddElement(O, 1);
111 
112  // example of vacuum
113  G4double density = universe_mean_density; //from PhysicalConstants.h
114  G4double pressure = 3.e-18*pascal;
115  G4double temperature = 2.73*kelvin;
116  G4Material* Galactic =
117  new G4Material("Galactic", 1., 1.008*g/mole, density,
118  kStateGas,temperature,pressure);
119 
120  fDefaultMaterial = Galactic;
121 
122  // G4cout << *(G4Material::GetMaterialTable()) << G4endl;
123 }
124 
125 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
126 
128  G4String symbol, G4double density, G4int Z, G4int A)
129 {
130  // define a material from an isotope
131  //
132  G4int ncomponents;
133  G4double abundance, massfraction;
134 
135  G4Isotope* isotope = new G4Isotope(symbol, Z, A);
136 
137  G4Element* element = new G4Element(name, symbol, ncomponents=1);
138  element->AddIsotope(isotope, abundance= 100.*perCent);
139 
140  G4Material* material = new G4Material(name, density, ncomponents=1);
141  material->AddElement(element, massfraction=100.*perCent);
142 
143  return material;
144 }
145 
146 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
147 
148 void DetectorConstruction::ComputeParameters()
149 {
150  // Compute total thickness of absorbers
151  fAbsorSizeX = 0.;
152  for (G4int iAbs=1; iAbs<=fNbOfAbsor; iAbs++) {
153  fAbsorSizeX += fAbsorThickness[iAbs];
154  }
155  fWorldSizeX = 1.2*fAbsorSizeX;
156  fWorldSizeYZ = 1.2*fAbsorSizeYZ;
157 }
158 
159 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
160 
161 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
162 {
163  // complete the Calor parameters definition
164  ComputeParameters();
165 
166  // Cleanup old geometry
171 
172  //
173  // World
174  //
175  G4Box* solidWorld =
176  new G4Box("World", //name
177  fWorldSizeX/2,fWorldSizeYZ/2,fWorldSizeYZ/2); //size
178 
179  G4LogicalVolume* logicWorld =
180  new G4LogicalVolume(solidWorld, //solid
181  fDefaultMaterial, //material
182  "World"); //name
183 
184  fPhysiWorld =
185  new G4PVPlacement(0, //no rotation
186  G4ThreeVector(), //at (0,0,0)
187  logicWorld, //logical volume
188  "World", //name
189  0, //mother volume
190  false, //no boolean operation
191  0); //copy number
192 
193  //
194  // Absorbers
195  //
196  fXfront[0] = -0.5*fAbsorSizeX;
197  //
198  for (G4int k=1; k<=fNbOfAbsor; k++) {
199  G4Material* material = fAbsorMaterial[k];
200  G4String matname = material->GetName();
201 
202  G4Box* solidAbsor =
203  new G4Box(matname,fAbsorThickness[k]/2,fAbsorSizeYZ/2,fAbsorSizeYZ/2);
204 
205  G4LogicalVolume* logicAbsor =
206  new G4LogicalVolume(solidAbsor, // solid
207  material, // material
208  matname); // name
209 
210  fXfront[k] = fXfront[k-1] + fAbsorThickness[k-1];
211  G4double xcenter = fXfront[k]+0.5*fAbsorThickness[k];
212  G4ThreeVector position = G4ThreeVector(xcenter,0.,0.);
213 
214  new G4PVPlacement(0, //no rotation
215  position, //position
216  logicAbsor, //logical volume
217  matname, //name
218  logicWorld, //mother
219  false, //no boulean operat
220  k); //copy number
221  }
222 
223  PrintParameters();
224 
225  //always return the physical World
226  //
227  return fPhysiWorld;
228 }
229 
230 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
231 
233 {
234  G4cout << "\n-------------------------------------------------------------"
235  << "\n ---> The Absorber is " << fNbOfAbsor << " layers of:";
236  for (G4int i=1; i<=fNbOfAbsor; i++)
237  {
238  G4cout << "\n \t" << std::setw(12) << fAbsorMaterial[i]->GetName() <<": "
239  << std::setw(6) << G4BestUnit(fAbsorThickness[i],"Length");
240  }
241  G4cout << "\n-------------------------------------------------------------\n"
242  << G4endl;
243 }
244 
245 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
246 
248 {
249  // set the number of Absorbers
250  //
251  if (ival < 1 || ival > (kMaxAbsor-1))
252  { G4cout << "\n ---> warning from SetfNbOfAbsor: "
253  << ival << " must be at least 1 and and most " << kMaxAbsor-1
254  << ". Command refused" << G4endl;
255  return;
256  }
257  fNbOfAbsor = ival;
259 }
260 
261 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
262 
263 void DetectorConstruction::SetAbsorMaterial(G4int iabs,const G4String& material)
264 {
265  // search the material by its name
266  //
267  if (iabs > fNbOfAbsor || iabs <= 0)
268  { G4cout << "\n --->warning from SetfAbsorMaterial: absor number "
269  << iabs << " out of range. Command refused" << G4endl;
270  return;
271  }
272 
273  G4Material* pttoMaterial =
275  if (pttoMaterial) {
276  fAbsorMaterial[iabs] = pttoMaterial;
278  }
279 }
280 
281 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
282 
284 {
285  // change Absorber thickness
286  //
287  if (iabs > fNbOfAbsor || iabs <= 0)
288  { G4cout << "\n --->warning from SetfAbsorThickness: absor number "
289  << iabs << " out of range. Command refused" << G4endl;
290  return;
291  }
292  if (val <= DBL_MIN)
293  { G4cout << "\n --->warning from SetfAbsorThickness: thickness "
294  << val << " out of range. Command refused" << G4endl;
295  return;
296  }
297  fAbsorThickness[iabs] = val;
299 }
300 
301 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
302 
304 {
305  // change the transverse size
306  //
307  if (val <= DBL_MIN)
308  { G4cout << "\n --->warning from SetfAbsorSizeYZ: thickness "
309  << val << " out of range. Command refused" << G4endl;
310  return;
311  }
312  fAbsorSizeYZ = val;
314 }
315 
316 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
317 
319 {
320  if ( fFieldMessenger.Get() == 0 ) {
321  // Create global magnetic field messenger.
322  // Uniform magnetic field is then created automatically if
323  // the field value is not zero.
324  G4ThreeVector fieldValue = G4ThreeVector();
326  new G4GlobalMagFieldMessenger(fieldValue);
327  //msg->SetVerboseLevel(1);
329  fFieldMessenger.Put( msg );
330  }
331 }
332 
333 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
334 
const XML_Char * name
Definition: expat.h:151
G4IonisParamMat * GetIonisation() const
Definition: G4Material.hh:226
G4Material * FindOrBuildMaterial(const G4String &name, G4bool isotopes=true, G4bool warning=false)
static constexpr double mm
Definition: G4SIunits.hh:115
CLHEP::Hep3Vector G4ThreeVector
int universe_mean_density
Definition: hepunit.py:307
Definition: G4Box.hh:64
void SetMeanExcitationEnergy(G4double value)
static constexpr double perCent
Definition: G4SIunits.hh:332
const G4String & GetName() const
Definition: G4Material.hh:178
G4VPhysicalVolume * Construct()
value_type & Get() const
Definition: G4Cache.hh:282
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
virtual void ConstructSDandField()
function g(Y1, Y2, PT2)
Definition: hijing1.383.f:5205
void Register(T *inst)
Definition: G4AutoDelete.hh:65
G4GLOB_DLL std::ostream G4cout
double A(double temperature)
void PhysicsHasBeenModified()
void SetAbsorMaterial(G4int, const G4String &)
const G4int kMaxAbsor
void AddIsotope(G4Isotope *isotope, G4double RelativeAbundance)
Definition: G4Element.cc:152
#define pascal
static G4LogicalVolumeStore * GetInstance()
static G4SolidStore * GetInstance()
static constexpr double eV
Definition: G4SIunits.hh:215
static G4GeometryManager * GetInstance()
static constexpr double kelvin
Definition: G4SIunits.hh:281
static constexpr double cm3
Definition: G4SIunits.hh:121
void ReinitializeGeometry(G4bool destroyFirst=false, G4bool prop=true)
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
G4Material * MaterialWithSingleIsotope(G4String, G4String, G4double, G4int, G4int)
#define DBL_MIN
Definition: templates.hh:75
#define G4endl
Definition: G4ios.hh:61
void SetAbsorThickness(G4int, G4double)
void OpenGeometry(G4VPhysicalVolume *vol=0)
void AddElement(G4Element *element, G4int nAtoms)
Definition: G4Material.cc:362
double G4double
Definition: G4Types.hh:76
G4Element * FindOrBuildElement(G4int Z, G4bool isotopes=true)
void Put(const value_type &val) const
Definition: G4Cache.hh:286
static constexpr double mole
Definition: G4SIunits.hh:286