Geant4  10.00.p03
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 77251 2013-11-22 10:06:41Z gcosmo $
30 //
31 
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
34 
35 #include "DetectorConstruction.hh"
36 #include "DetectorMessenger.hh"
37 
38 #include "G4Material.hh"
39 #include "G4NistManager.hh"
40 #include "G4Box.hh"
41 #include "G4LogicalVolume.hh"
42 #include "G4PVPlacement.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 "G4UnitsTable.hh"
51 #include "G4SystemOfUnits.hh"
52 
53 #include "G4FieldManager.hh"
55 #include "G4RunManager.hh"
56 
57 
58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
59 
62  fPBox(0), fLBox(0), fMaterial(0), fMagField(0), fDetectorMessenger(0)
63 {
64  fBoxSize = 10*m;
66  SetMaterial("Molybdenum98");
68 }
69 
70 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
71 
73 { delete fDetectorMessenger;}
74 
75 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
76 
78 {
79  return ConstructVolumes();
80 }
81 
82 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
83 
85 {
86  // define a Material from isotopes
87  //
88  MaterialWithSingleIsotope("Molybdenum98", "Mo98", 10.28*g/cm3, 42, 98);
89 
90  // or use G4-NIST materials data base
91  //
93  man->FindOrBuildMaterial("G4_B");
94 
96 }
97 
98 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
99 
102 {
103  // define a material from an isotope
104  //
105  G4int ncomponents;
106  G4double abundance, massfraction;
107 
108  G4Isotope* isotope = new G4Isotope(symbol, Z, A);
109 
110  G4Element* element = new G4Element(name, symbol, ncomponents=1);
111  element->AddIsotope(isotope, abundance= 100.*perCent);
112 
113  G4Material* material = new G4Material(name, density, ncomponents=1);
114  material->AddElement(element, massfraction=100.*perCent);
115 
116  return material;
117 }
118 
119 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
120 
122 {
123  // Cleanup old geometry
128 
129  G4Box*
130  sBox = new G4Box("Container", //its name
131  fBoxSize/2,fBoxSize/2,fBoxSize/2); //its dimensions
132 
133  fLBox = new G4LogicalVolume(sBox, //its shape
134  fMaterial, //its material
135  fMaterial->GetName()); //its name
136 
137  fPBox = new G4PVPlacement(0, //no rotation
138  G4ThreeVector(), //at (0,0,0)
139  fLBox, //its logical volume
140  fMaterial->GetName(), //its name
141  0, //its mother volume
142  false, //no boolean operation
143  0); //copy number
144 
145  PrintParameters();
146 
147  //always return the root volume
148  //
149  return fPBox;
150 }
151 
152 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
153 
155 {
156  G4cout << "\n The Box is " << G4BestUnit(fBoxSize,"Length")
157  << " of " << fMaterial->GetName()
158  << "\n \n" << fMaterial << G4endl;
159 }
160 
161 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
162 
163 void DetectorConstruction::SetMaterial(G4String materialChoice)
164 {
165  // search the material by its name
166  G4Material* pttoMaterial =
167  G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
168 
169  if (pttoMaterial) {
170  if(fMaterial != pttoMaterial) {
171  fMaterial = pttoMaterial;
172  if(fLBox) { fLBox->SetMaterial(pttoMaterial); }
174  }
175  } else {
176  G4cout << "\n--> warning from DetectorConstruction::SetMaterial : "
177  << materialChoice << " not found" << G4endl;
178  }
179 }
180 
181 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
182 
184 {
185  fBoxSize = value;
187 }
188 
189 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
190 
192 {
193  //apply a global uniform magnetic field along Z axis
194  G4FieldManager* fieldMgr
196 
197  if (fMagField) delete fMagField; //delete the existing magn field
198 
199  if (fieldValue!=0.) // create a new one if non nul
200  {
201  fMagField = new G4UniformMagField(G4ThreeVector(0.,0.,fieldValue));
202  fieldMgr->SetDetectorField(fMagField);
203  fieldMgr->CreateChordFinder(fMagField);
204  }
205  else
206  {
207  fMagField = 0;
208  fieldMgr->SetDetectorField(fMagField);
209  }
210 }
211 
212 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
213 
G4Material * FindOrBuildMaterial(const G4String &name, G4bool isotopes=true, G4bool warning=false)
G4String symbol
Definition: TRTMaterials.hh:40
CLHEP::Hep3Vector G4ThreeVector
G4bool SetDetectorField(G4Field *detectorField)
Definition: G4Box.hh:64
G4String name
Definition: TRTMaterials.hh:40
const G4String & GetName() const
Definition: G4Material.hh:176
G4VPhysicalVolume * Construct()
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()
G4double density
Definition: TRTMaterials.hh:39
G4GLOB_DLL std::ostream G4cout
void PhysicsHasBeenModified()
void AddIsotope(G4Isotope *isotope, G4double RelativeAbundance)
Definition: G4Element.cc:151
G4UniformMagField * fMagField
static G4LogicalVolumeStore * GetInstance()
static const double cm3
Definition: G4SIunits.hh:108
static G4SolidStore * GetInstance()
static const double perCent
Definition: G4SIunits.hh:296
static G4GeometryManager * GetInstance()
static const G4double A[nN]
void ReinitializeGeometry(G4bool destroyFirst=false, G4bool prop=true)
static G4TransportationManager * GetTransportationManager()
G4FieldManager * GetFieldManager() const
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:74
G4Material * MaterialWithSingleIsotope(G4String, G4String, G4double, G4int, G4int)
static const double g
Definition: G4SIunits.hh:162
#define G4endl
Definition: G4ios.hh:61
static const double m
Definition: G4SIunits.hh:110
void OpenGeometry(G4VPhysicalVolume *vol=0)
void AddElement(G4Element *element, G4int nAtoms)
Definition: G4Material.cc:363
G4VPhysicalVolume * fPBox
double G4double
Definition: G4Types.hh:76
void CreateChordFinder(G4MagneticField *detectorMagField)
G4VPhysicalVolume * ConstructVolumes()
void SetMaterial(G4Material *pMaterial)
Messenger class that defines commands for DetectorConstruction.
DetectorMessenger * fDetectorMessenger