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3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  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 DetectorConstruction.cc
 27 /// \brief Implementation of the DetectorConstruction class
 28 //
 29 //
 30 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 32 
 33 #include "DetectorConstruction.hh"
 34 
 35 #include "DetectorMessenger.hh"
 36 
 37 #include "G4GeometryManager.hh"
 38 #include "G4LogicalVolume.hh"
 39 #include "G4LogicalVolumeStore.hh"
 40 #include "G4Material.hh"
 41 #include "G4NistManager.hh"
 42 #include "G4PVPlacement.hh"
 43 #include "G4PhysicalConstants.hh"
 44 #include "G4PhysicalVolumeStore.hh"
 45 #include "G4RunManager.hh"
 46 #include "G4SolidStore.hh"
 47 #include "G4SystemOfUnits.hh"
 48 #include "G4Tubs.hh"
 49 #include "G4UnitsTable.hh"
 50 
 51 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 52 
 53 DetectorConstruction::DetectorConstruction()
 54 {
 55   fTargetLength = 1 * cm;
 56   fTargetRadius = 0.5 * cm;
 57   fDetectorLength = 5 * cm;
 58   fDetectorThickness = 2 * cm;
 59 
 60   fWorldLength = std::max(fTargetLength, fDetectorLength);
 61   fWorldRadius = fTargetRadius + fDetectorThickness;
 62 
 63   DefineMaterials();
 64 
 65   fDetectorMessenger = new DetectorMessenger(this);
 66 }
 67 
 68 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 69 
 70 DetectorConstruction::~DetectorConstruction()
 71 {
 72   delete fDetectorMessenger;
 73 }
 74 
 75 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 76 
 77 G4VPhysicalVolume* DetectorConstruction::Construct()
 78 {
 79   return ConstructVolumes();
 80 }
 81 
 82 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 83 
 84 void DetectorConstruction::DefineMaterials()
 85 {
 86   // build materials
 87   //
 88   fDetectorMater = new G4Material("Germanium", 32, 72.61 * g / mole, 5.323 * g / cm3);
 89 
 90   G4Element* N = new G4Element("Nitrogen", "N", 7, 14.01 * g / mole);
 91   G4Element* O = new G4Element("Oxygen", "O", 8, 16.00 * g / mole);
 92   //
 93   G4int ncomponents;
 94   G4double fractionmass;
 95   G4Material* Air20 = new G4Material("Air", 1.205 * mg / cm3, ncomponents = 2, kStateGas,
 96                                      293. * kelvin, 1. * atmosphere);
 97   Air20->AddElement(N, fractionmass = 0.7);
 98   Air20->AddElement(O, fractionmass = 0.3);
 99   //
100   fWorldMater = Air20;
101 
102   // or use G4 materials data base
103   //
104   G4NistManager* man = G4NistManager::Instance();
105   fTargetMater = man->FindOrBuildMaterial("G4_CESIUM_IODIDE");
106 
107   /// G4cout << *(G4Material::GetMaterialTable()) << G4endl;
108 }
109 
110 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
111 
112 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
113 {
114   // Cleanup old geometry
115   G4GeometryManager::GetInstance()->OpenGeometry();
116   G4PhysicalVolumeStore::GetInstance()->Clean();
117   G4LogicalVolumeStore::GetInstance()->Clean();
118   G4SolidStore::GetInstance()->Clean();
119 
120   // World
121   //
122   // (re) compute World dimensions if necessary
123   fWorldLength = std::max(fTargetLength, fDetectorLength);
124   fWorldRadius = fTargetRadius + fDetectorThickness;
125 
126   G4Tubs* sWorld = new G4Tubs("World",  // name
127                               0., fWorldRadius, 0.5 * fWorldLength, 0., twopi);  // dimensions
128 
129   G4LogicalVolume* lWorld = new G4LogicalVolume(sWorld,  // shape
130                                                 fWorldMater,  // material
131                                                 "World");  // name
132 
133   fPhysiWorld = new G4PVPlacement(0,  // no rotation
134                                   G4ThreeVector(),  // at (0,0,0)
135                                   lWorld,  // logical volume
136                                   "World",  // name
137                                   0,  // mother volume
138                                   false,  // no boolean operation
139                                   0);  // copy number
140 
141   // Target
142   //
143   G4Tubs* sTarget = new G4Tubs("Target",  // name
144                                0., fTargetRadius, 0.5 * fTargetLength, 0., twopi);  // dimensions
145 
146   fLogicTarget = new G4LogicalVolume(sTarget,  // shape
147                                      fTargetMater,  // material
148                                      "Target");  // name
149 
150   new G4PVPlacement(0,  // no rotation
151                     G4ThreeVector(),  // at (0,0,0)
152                     fLogicTarget,  // logical volume
153                     "Target",  // name
154                     lWorld,  // mother  volume
155                     false,  // no boolean operation
156                     0);  // copy number
157 
158   // Detector
159   //
160   G4Tubs* sDetector =
161     new G4Tubs("Detector", fTargetRadius, fWorldRadius, 0.5 * fDetectorLength, 0., twopi);
162 
163   fLogicDetector = new G4LogicalVolume(sDetector,  // shape
164                                        fDetectorMater,  // material
165                                        "Detector");  // name
166 
167   new G4PVPlacement(0,  // no rotation
168                     G4ThreeVector(),  // at (0,0,0)
169                     fLogicDetector,  // logical volume
170                     "Detector",  // name
171                     lWorld,  // mother  volume
172                     false,  // no boolean operation
173                     0);  // copy number
174 
175   PrintParameters();
176 
177   // always return the root volume
178   //
179   return fPhysiWorld;
180 }
181 
182 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
183 
184 void DetectorConstruction::PrintParameters()
185 {
186   G4cout << "\n Target : Length = " << G4BestUnit(fTargetLength, "Length")
187          << " Radius = " << G4BestUnit(fTargetRadius, "Length")
188          << " Material = " << fTargetMater->GetName();
189   G4cout << "\n Detector : Length = " << G4BestUnit(fDetectorLength, "Length")
190          << " Tickness = " << G4BestUnit(fDetectorThickness, "Length")
191          << " Material = " << fDetectorMater->GetName() << G4endl;
192   G4cout << "\n" << fTargetMater << "\n" << fDetectorMater << G4endl;
193 }
194 
195 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
196 
197 void DetectorConstruction::SetTargetMaterial(G4String materialChoice)
198 {
199   // search the material by its name
200   G4Material* pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
201 
202   if (pttoMaterial) {
203     fTargetMater = pttoMaterial;
204     if (fLogicTarget) {
205       fLogicTarget->SetMaterial(fTargetMater);
206     }
207     G4RunManager::GetRunManager()->PhysicsHasBeenModified();
208   }
209   else {
210     G4cout << "\n--> warning from DetectorConstruction::SetTargetMaterial : " << materialChoice
211            << " not found" << G4endl;
212   }
213 }
214 
215 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
216 
217 void DetectorConstruction::SetDetectorMaterial(G4String materialChoice)
218 {
219   // search the material by its name
220   G4Material* pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
221 
222   if (pttoMaterial) {
223     fDetectorMater = pttoMaterial;
224     if (fLogicDetector) {
225       fLogicDetector->SetMaterial(fDetectorMater);
226     }
227     G4RunManager::GetRunManager()->PhysicsHasBeenModified();
228   }
229   else {
230     G4cout << "\n--> warning from DetectorConstruction::SetDetectorMaterial : " << materialChoice
231            << " not found" << G4endl;
232   }
233 }
234 
235 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
236 
237 void DetectorConstruction::SetTargetRadius(G4double value)
238 {
239   fTargetRadius = value;
240   G4RunManager::GetRunManager()->ReinitializeGeometry();
241 }
242 
243 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
244 
245 void DetectorConstruction::SetTargetLength(G4double value)
246 {
247   fTargetLength = value;
248   G4RunManager::GetRunManager()->ReinitializeGeometry();
249 }
250 
251 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
252 
253 void DetectorConstruction::SetDetectorThickness(G4double value)
254 {
255   fDetectorThickness = value;
256   G4RunManager::GetRunManager()->ReinitializeGeometry();
257 }
258 
259 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
260 
261 void DetectorConstruction::SetDetectorLength(G4double value)
262 {
263   fDetectorLength = value;
264   G4RunManager::GetRunManager()->ReinitializeGeometry();
265 }
266 
267 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
268 
269 G4double DetectorConstruction::GetTargetLength()
270 {
271   return fTargetLength;
272 }
273 
274 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
275 
276 G4double DetectorConstruction::GetTargetRadius()
277 {
278   return fTargetRadius;
279 }
280 
281 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
282 
283 G4Material* DetectorConstruction::GetTargetMaterial()
284 {
285   return fTargetMater;
286 }
287 
288 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
289 
290 G4LogicalVolume* DetectorConstruction::GetLogicTarget()
291 {
292   return fLogicTarget;
293 }
294 
295 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
296 
297 G4double DetectorConstruction::GetDetectorLength()
298 {
299   return fDetectorLength;
300 }
301 
302 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
303 
304 G4double DetectorConstruction::GetDetectorThickness()
305 {
306   return fDetectorThickness;
307 }
308 
309 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
310 
311 G4Material* DetectorConstruction::GetDetectorMaterial()
312 {
313   return fDetectorMater;
314 }
315 
316 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
317 
318 G4LogicalVolume* DetectorConstruction::GetLogicDetector()
319 {
320   return fLogicDetector;
321 }
322 
323 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
324