Geant4_10
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 68036 2013-03-13 14:13:45Z 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 
63  fWorldMaterial(0),
64  fAbsorMaterial(0),
65  fMagField(0),
66  fMonFieldSetup(0),
67  fLogAbsor(0),
68  fDetectorMessenger(0)
69 {
70  // default parameter values
71  fAbsorSizeX = fAbsorSizeYZ = 10 * cm;
72  fWorldSizeX = fWorldSizeYZ = 1.2 * fAbsorSizeX;
73  fMaxStepSize = 5 * mm;
74 
76 
77  SetMaterial("G4_Al");
78  fWorldMaterial =
80 
81  // create commands for interactive definition of the detector
82  fDetectorMessenger = new DetectorMessenger(this);
83 }
84 
85 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
86 
88 {
89  delete fDetectorMessenger;
90 }
91 
92 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
93 
95 {
100 
101  /**************************** World *****************************/
102  G4Box * sWorld = new G4Box("world",
103  fWorldSizeX / 2, fWorldSizeYZ / 2, fWorldSizeYZ / 2);
104 
105  G4LogicalVolume * lWorld = new G4LogicalVolume(sWorld,
106  fWorldMaterial,
107  "world");
108 
109  G4VPhysicalVolume * pWorld = new G4PVPlacement(0, //no rotation
110  G4ThreeVector(), //at (0,0,0)
111  lWorld, //logical volume
112  "world", //name
113  0, //mother volume
114  false, //no boolean operation
115  0); //copy number
116 
117 
118  /************************** Absorber ***************************/
119  G4Box * sAbsor = new G4Box("Absorber",
120  fAbsorSizeX / 2, fAbsorSizeYZ / 2, fAbsorSizeYZ / 2);
121 
122  fLogAbsor = new G4LogicalVolume(sAbsor,
123  fAbsorMaterial,
124  "Absorber");
125 
126  new G4PVPlacement(0, //no rotation
127  G4ThreeVector(), //at (0,0,0)
128  fLogAbsor, //logical volume
129  "Absorber", //name
130  lWorld, //mother volume
131  false, //no boolean operation
132  0); //copy number
133  fLogAbsor->SetUserLimits(new G4UserLimits(fMaxStepSize));
134 
135  PrintParameters();
136 
137  /************ always return the World volume *****************/
138  return pWorld;
139 }
140 
141 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
142 
144 {
145  G4cout << "\n---------------------------------------------------------\n";
146  G4cout << "---> The Absorber is " << G4BestUnit(fAbsorSizeX, "Length")
147  << " of " << fAbsorMaterial->GetName() << G4endl;
148  G4cout << "\n---------------------------------------------------------\n";
149 
150 }
151 
152 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
153 
155 {
156  if(value > 0.0) {
157  fAbsorSizeX = value;
158  fWorldSizeX = 1.2 * fAbsorSizeX;
160  }
161 }
162 
163 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
164 
166 {
167  if(value > 0.0) {
168  fAbsorSizeYZ = value;
169  fWorldSizeYZ = 1.2 * fAbsorSizeYZ;
171  }
172 }
173 
174 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
175 
176 void DetectorConstruction::SetMaterial(const G4String& namemat)
177 {
178  // search the material by its name
180  if(!mat) {
181  G4cout << "!!! DetectorConstruction::SetMaterial: WARNING Material <"
182  << namemat << "> does not exist in DB" << G4endl;
183  return;
184  }
185  // new material is found out
186  if (mat != fAbsorMaterial) {
187  fAbsorMaterial = mat;
188  if(fLogAbsor) { fLogAbsor->SetMaterial(mat); }
190  }
191 }
192 
193 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
194 
196 {
197  fMonFieldSetup->SetMagField(fieldValue);
198 
199  //apply a global uniform magnetic field along Z axis
200  G4FieldManager * fieldMgr =
202 
203  if (fMagField) { delete fMagField; } //delete the existing magn field
204 
205  if (fieldValue != 0.) // create a new one if non nul
206  {
207  fMagField = new G4UniformMagField(G4ThreeVector(0., 0., fieldValue));
208  fieldMgr->SetDetectorField(fMagField);
209  fieldMgr->CreateChordFinder(fMagField);
210  }
211  else
212  {
213  fMagField = 0;
214  fieldMgr->SetDetectorField(fMagField);
215  }
216 }
217 
218 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
219 
221 {
222  fMaxStepSize = step;
223  if(fLogAbsor) { fLogAbsor->SetUserLimits(new G4UserLimits(fMaxStepSize)); }
224 }
225 
226 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
227 
229 {
231 }
232 
233 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void GeometryHasBeenModified(G4bool prop=true)
G4Material * FindOrBuildMaterial(const G4String &name, G4bool isotopes=true, G4bool warning=false)
void SetMagField(G4double fieldValue)
CLHEP::Hep3Vector G4ThreeVector
G4bool SetDetectorField(G4Field *detectorField)
Definition: G4Box.hh:63
const G4String & GetName() const
Definition: G4Material.hh:176
G4VPhysicalVolume * Construct()
void SetUserLimits(G4UserLimits *pULimits)
static void Clean()
Definition: G4SolidStore.cc:79
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
static G4NistManager * Instance()
Definition of the G4MonopoleFieldSetup class.
Float_t mat
Definition: plot.C:40
static G4PhysicalVolumeStore * GetInstance()
G4GLOB_DLL std::ostream G4cout
void PhysicsHasBeenModified()
static G4LogicalVolumeStore * GetInstance()
static G4SolidStore * GetInstance()
static G4MonopoleFieldSetup * GetMonopoleFieldSetup()
static G4GeometryManager * GetInstance()
static G4TransportationManager * GetTransportationManager()
G4FieldManager * GetFieldManager() const
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:74
const XML_Char int const XML_Char * value
Definition: expat.h:331
#define G4endl
Definition: G4ios.hh:61
void OpenGeometry(G4VPhysicalVolume *vol=0)
double G4double
Definition: G4Types.hh:76
void CreateChordFinder(G4MagneticField *detectorMagField)
void SetMaterial(G4Material *pMaterial)