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 101390 2016-11-16 14:13:20Z 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 "G4PhysicalVolumeStore.hh"
45 #include "G4LogicalVolumeStore.hh"
46 #include "G4SolidStore.hh"
47 
48 #include "G4NistManager.hh"
49 #include "G4UnitsTable.hh"
50 
51 #include "G4FieldManager.hh"
53 #include "G4RunManager.hh"
54 
55 #include "G4PhysicalConstants.hh"
56 #include "G4SystemOfUnits.hh"
57 
58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
59 
62  fMagField(nullptr),
63  fLAbsor(nullptr),
64  fLWorld(nullptr)
65 {
66  // default parameter values
67  fAbsorSizeX = fAbsorSizeYZ = 20*cm;
68  fWorldSizeX = fWorldSizeYZ = 1.2*fAbsorSizeX;
69 
70  fTallyNumber = 0;
71  for (G4int j=0; j<kMaxTally; j++) {
72  fTallySize[j] = fTallyPosition[j] = G4ThreeVector(0.,0.,0.);
73  fTallyMass[j] = 0.;
74  fLTally[j] = nullptr;
75  }
76 
77  DefineMaterials();
78 
79  // create commands for interactive definition of the detector
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 
92 void DetectorConstruction::DefineMaterials()
93 {
94  //
95  // define Elements
96  //
97  G4double z, a;
98 
99  G4Element* H = new G4Element("Hydrogen", "H", z= 1, a= 1.008*g/mole);
100  G4Element* N = new G4Element("Nitrogen", "N", z= 7, a= 14.01*g/mole);
101  G4Element* O = new G4Element("Oxygen" , "O", z= 8, a= 16.00*g/mole);
102 
103  //
104  // define Materials.
105  //
106  G4double density, temperature, pressure;
107  G4int ncomponents, natoms;
108  G4double fractionmass;
109 
110  G4Material* H2O =
111  new G4Material("Water", density= 1.0*g/cm3, ncomponents=2);
112  H2O->AddElement(H, natoms=2);
113  H2O->AddElement(O, natoms=1);
115 
116  // In this line both G4_WATER and Water_1.05 will be constructed
118  BuildMaterialWithNewDensity("Water_1.05","G4_WATER",1.05*g/cm3);
119 
120  G4Material* Air =
121  new G4Material("Air" , density= 1.290*mg/cm3, ncomponents=2);
122  Air->AddElement(N, fractionmass=0.7);
123  Air->AddElement(O, fractionmass=0.3);
124 
125  density = 1.e-5*g/cm3;
126  pressure = 2.e-2*bar;
127  temperature = STP_Temperature; // From PhysicalConstants.h .
128  G4Material* vac = new G4Material( "TechVacuum", density, 1,
129  kStateGas, temperature, pressure );
130  vac->AddMaterial( Air, 1. );
131 
132  density = universe_mean_density; //from PhysicalConstants.h
133  pressure = 3.e-18*pascal;
134  temperature = 2.73*kelvin;
135  G4Material* vacuum =
136  new G4Material("Galactic",z= 1,a= 1.008*g/mole,density,
137  kStateGas,temperature,pressure);
138 
139  //default materials
140  fAbsorMaterial = H2O;
141  fWorldMaterial = vacuum;
142 }
143 
144 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
145 
147 {
148  // World
149  //
150  G4Box*
151  sWorld = new G4Box("World", //name
152  fWorldSizeX/2,fWorldSizeYZ/2,fWorldSizeYZ/2); //dimensions
153 
154  fLWorld = new G4LogicalVolume(sWorld, //shape
155  fWorldMaterial, //material
156  "World"); //name
157 
159  pWorld = new G4PVPlacement(0, //no rotation
160  G4ThreeVector(0.,0.,0.), //at (0,0,0)
161  fLWorld, //logical volume
162  "World", //name
163  0, //mother volume
164  false, //no boolean operation
165  0); //copy number
166  //
167  // Absorber
168  //
169  G4Box*
170  sAbsor = new G4Box("Absorber", //name
171  fAbsorSizeX/2,fAbsorSizeYZ/2,fAbsorSizeYZ/2); //dimensions
172 
173  fLAbsor = new G4LogicalVolume(sAbsor, //shape
174  fAbsorMaterial, //material
175  "Absorber"); //name
176 
177 
178  new G4PVPlacement(0, //no rotation
179  G4ThreeVector(0.,0.,0.), //at (0,0,0)
180  fLAbsor, //logical volume
181  "Absorber", //name
182  fLWorld, //mother volume
183  false, //no boolean operation
184  0); //copy number
185  //
186  // Tallies (optional)
187  //
188  if (fTallyNumber > 0) {
189  for (G4int j=0; j<fTallyNumber; ++j) {
190 
191  G4Box* sTally = new G4Box("Tally",
192  fTallySize[j].x()/2,fTallySize[j].y()/2,fTallySize[j].z()/2);
193 
194  fLTally[j] = new G4LogicalVolume(sTally,fAbsorMaterial,"Tally");
195 
196  new G4PVPlacement(0, //no rotation
197  fTallyPosition[j], //position
198  fLTally[j], //logical volume
199  "Tally", //name
200  fLAbsor, //mother volume
201  false, //no boolean operation
202  j+1); //copy number
203 
204  fTallyMass[j] = fTallySize[j].x()*fTallySize[j].y()*fTallySize[j].z()
205  *(fAbsorMaterial->GetDensity());
206  }
207  }
208 
209  PrintParameters();
210 
211  //
212  //always return the World volume
213  //
214  return pWorld;
215 }
216 
217 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
218 
220 {
222  G4cout << "\n---------------------------------------------------------\n";
223  G4cout << "---> The Absorber is " << G4BestUnit(fAbsorSizeX,"Length")
224  << " of " << fAbsorMaterial->GetName() << G4endl;
225  G4cout << "\n---------------------------------------------------------\n";
226 
227  if (fTallyNumber > 0) {
228  G4cout << "---> There are " << fTallyNumber << " tallies : " << G4endl;
229  for (G4int j=0; j<fTallyNumber; ++j) {
230  G4cout << "fTally " << j << ": "
231  << fAbsorMaterial->GetName()
232  << ", mass = " << G4BestUnit(fTallyMass[j],"Mass")
233  << " size = " << G4BestUnit(fTallySize[j],"Length")
234  << " position = " << G4BestUnit(fTallyPosition[j],"Length")
235  << G4endl;
236  }
237  G4cout << "\n---------------------------------------------------------\n";
238  }
239 }
240 
241 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
242 
244 {
245  fAbsorSizeX = value;
246  fWorldSizeX = 1.2*fAbsorSizeX;
247 }
248 
249 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
250 
252 {
253  fAbsorSizeYZ = value;
254  fWorldSizeYZ = 1.2*fAbsorSizeYZ;
255 }
256 
257 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
258 
259 void DetectorConstruction::SetMaterial(const G4String& materialChoice)
260 {
261  // search the material by its name
262  G4Material* pttoMaterial =
263  G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
264  if (pttoMaterial && pttoMaterial != fAbsorMaterial) {
265  // change target material everywhere
266  fAbsorMaterial = pttoMaterial;
267  for (G4int j=0; j<fTallyNumber; ++j) {
268  if(fLTally[j]) {
269  fLTally[j]->SetMaterial(pttoMaterial);
270  fTallyMass[j] = fTallySize[j].x()*fTallySize[j].y()*fTallySize[j].z()
271  *(pttoMaterial->GetDensity());
272  }
273  }
274  if(fLAbsor) {
275  fLAbsor->SetMaterial(fAbsorMaterial);
277  }
278  }
279 }
280 
281 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
282 
283 void DetectorConstruction::SetWorldMaterial(const G4String& materialChoice)
284 {
285  // search the material by its name
286  G4Material* pttoMaterial =
287  G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
288  if (pttoMaterial && pttoMaterial != fWorldMaterial) {
289  fWorldMaterial = pttoMaterial;
290  if(fLWorld) {
291  fLWorld->SetMaterial(fAbsorMaterial);
293  }
294  }
295 }
296 
297 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
298 
300 {
301  //apply a global uniform magnetic field along Z axis
302  G4FieldManager* fieldMgr
304 
305  if (fMagField) delete fMagField; //delete the existing magn field
306 
307  if (fieldValue!=0.) // create a new one if non nul
308  {
309  fMagField = new G4UniformMagField(G4ThreeVector(0.,0.,fieldValue));
310  fieldMgr->SetDetectorField(fMagField);
311  fieldMgr->CreateChordFinder(fMagField);
312  }
313  else
314  {
315  fMagField = nullptr;
316  fieldMgr->SetDetectorField(fMagField);
317  }
318 }
319 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
320 
322 {
323  if(value >= 0 && value <kMaxTally) {
324  fTallyNumber = value;
325  } else {
326  G4cout << "### DetectorConstruction::SetTallyNumber WARNING: wrong tally "
327  << "number " << value << " is ignored" << G4endl;
328  }
329 }
330 
331 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
332 
334 {
335  if(j >= 0 && j < kMaxTally) {
336  fTallySize[j] = value;
337  } else {
338  G4cout << "### DetectorConstruction::SetTallyNumber WARNING: wrong tally "
339  << "number " << j << " is ignored" << G4endl;
340  }
341 }
342 
343 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
344 
346 {
347  if(j >= 0 && j < kMaxTally) {
348  fTallyPosition[j] = value;
349  } else {
350  G4cout << "### DetectorConstruction::SetTallyPosition WARNING: wrong tally "
351  << "number " << j << " is ignored" << G4endl;
352  }
353 }
354 
356 {
357  if(j >= 0 && j < kMaxTally) {
358  return fTallyMass[j];
359  } else {
360  G4cout << "### DetectorConstruction::GetTallyMass WARNING: wrong tally "
361  << "number " << j << " is ignored" << G4endl;
362  return 0.0;
363  }
364 }
365 
367 {
368  if(j >= 0 && j < kMaxTally) {
369  return fLTally[j];
370  } else {
371  G4cout << "### DetectorConstruction::GetLOgicalTally WARNING: wrong tally "
372  << "number " << j << " is ignored" << G4endl;
373  return nullptr;
374  }
375 }
376 
377 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4IonisParamMat * GetIonisation() const
Definition: G4Material.hh:226
G4Material * FindOrBuildMaterial(const G4String &name, G4bool isotopes=true, G4bool warning=false)
static constexpr double mg
Definition: G4SIunits.hh:184
CLHEP::Hep3Vector G4ThreeVector
double x() const
G4bool SetDetectorField(G4Field *detectorField)
void AddMaterial(G4Material *material, G4double fraction)
Definition: G4Material.cc:467
std::vector< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33
int universe_mean_density
Definition: hepunit.py:307
Definition: G4Box.hh:64
void SetMeanExcitationEnergy(G4double value)
const G4String & GetName() const
Definition: G4Material.hh:178
G4VPhysicalVolume * Construct()
static G4MaterialTable * GetMaterialTable()
Definition: G4Material.cc:587
G4double GetDensity() const
Definition: G4Material.hh:180
void SetWorldMaterial(const G4String &)
tuple x
Definition: test.py:50
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
float STP_Temperature
Definition: hepunit.py:302
int G4int
Definition: G4Types.hh:78
static G4NistManager * Instance()
double z() const
function g(Y1, Y2, PT2)
Definition: hijing1.383.f:5205
G4GLOB_DLL std::ostream G4cout
const XML_Char int const XML_Char * value
Definition: expat.h:331
void PhysicsHasBeenModified()
const G4int kMaxTally
static constexpr double cm
Definition: G4SIunits.hh:119
#define pascal
static constexpr double eV
Definition: G4SIunits.hh:215
static constexpr double kelvin
Definition: G4SIunits.hh:281
static constexpr double cm3
Definition: G4SIunits.hh:121
static G4TransportationManager * GetTransportationManager()
G4FieldManager * GetFieldManager() const
void SetTallyPosition(G4int, const G4ThreeVector &)
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
double y() const
void SetTallySize(G4int, const G4ThreeVector &)
tuple z
Definition: test.py:28
#define G4endl
Definition: G4ios.hh:61
**D E S C R I P T I O N
Definition: HEPEvtcom.cc:77
const G4LogicalVolume * GetLogicalTally(G4int n) const
void AddElement(G4Element *element, G4int nAtoms)
Definition: G4Material.cc:362
static constexpr double bar
Definition: G4SIunits.hh:236
double G4double
Definition: G4Types.hh:76
void CreateChordFinder(G4MagneticField *detectorMagField)
void SetMaterial(G4Material *pMaterial)
static constexpr double mole
Definition: G4SIunits.hh:286
G4double GetTallyMass(G4int n) const