Geant4  10.03.p03
 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 //
26 // $Id: DetectorConstruction.cc 101905 2016-12-07 11:34:39Z gunter $
27 //
30 //
31 //
32 // -------------------------------------------------------------
33 // GEANT4 ibrem test
34 //
35 // Authors: V.Grichine, V.Ivanchenko
36 //
37 // Modified:
38 //
39 // 18-02-03 V.Ivanchenko create
40 //
41 // -------------------------------------------------------------
42 
43 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
44 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
45 
46 #include "DetectorConstruction.hh"
47 #include "DetectorMessenger.hh"
48 #include "PhantomSD.hh"
49 #include "TargetSD.hh"
50 #include "CheckVolumeSD.hh"
51 #include "Histo.hh"
52 
53 #include "G4Box.hh"
54 #include "G4Tubs.hh"
55 #include "G4LogicalVolume.hh"
56 #include "G4VPhysicalVolume.hh"
57 #include "G4PVPlacement.hh"
58 #include "G4Material.hh"
59 #include "G4SDManager.hh"
60 #include "PhantomSD.hh"
61 #include "G4NistManager.hh"
62 
63 #include "G4PhysicalVolumeStore.hh"
64 #include "G4LogicalVolumeStore.hh"
65 #include "G4SolidStore.hh"
66 #include "G4RunManager.hh"
67 
68 #include "G4VisAttributes.hh"
69 #include "G4Colour.hh"
70 
71 #include "globals.hh"
72 #include "G4PhysicalConstants.hh"
73 #include "G4SystemOfUnits.hh"
74 #include "G4ios.hh"
75 
76 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
77 
79 {
80  fLogicTarget1 = 0;
81  fLogicTarget2 = 0;
82 
83  fMessenger = new DetectorMessenger(this);
84 
85  fCheckSD = new CheckVolumeSD("checkSD");
86  (G4SDManager::GetSDMpointer())->AddNewDetector( fCheckSD );
87  fPhantomSD = new PhantomSD("phantomSD");
88  (G4SDManager::GetSDMpointer())->AddNewDetector( fPhantomSD );
89  fTargetSD = new TargetSD("targetSD");
90  (G4SDManager::GetSDMpointer())->AddNewDetector( fTargetSD );
91 
92  fDistanceVacuumTarget = 30.*mm,
93 
94  fDelta = 0.001*mm;
95 
96  fTargetRadius = 100.*mm;
97  fTarget1Z = 9.*mm;
98  fTarget2Z = 6.*mm;
99 
100  fGasVolumeRadius = 210.*mm;
101  fGasVolumeZ = 690.*mm;
102  fMylarVolumeZ = 0.02*mm;
103 
104  fCheckVolumeZ = 0.1*mm;
105  fCheckShiftZ = 200.*mm;
106 
107  fAbsorberRadius = 200.*mm;
108  fPhantomRadius = 300.*mm;
109  fPhantomZ = 300.*mm;
110 
111  fAirZ = 210.*mm;
112  fAbsorberShiftZ = 70.*mm;
113  fWindowZ = 0.05*mm;
114 
116  //man->SetVerbose(1);
117 
118  fTarget1Material = man->FindOrBuildMaterial("G4_Be");
119  fWindowMaterial = fTarget1Material;
120  fTarget2Material = man->FindOrBuildMaterial("G4_W");
121  fLightMaterial = man->FindOrBuildMaterial("G4_He");
122  fAbsorberMaterial= man->FindOrBuildMaterial("G4_WATER");
123  fWorldMaterial = man->FindOrBuildMaterial("G4_AIR");
124  fMylar = man->FindOrBuildMaterial("G4_MYLAR");
125 
127 }
128 
129 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
130 
132 {}
133 
134 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
135 
136 void DetectorConstruction::InitialiseGeometryParameters()
137 {
138  // Volumee sizes
139 
140  G4double factor = 1.2;
141 
142  fWorldXY = factor*std::max(fPhantomRadius,fGasVolumeRadius);
143  G4double nz = (G4int)((Histo::GetPointer())->GetNumberDivZ());
144  fAbsorberZ = fPhantomZ/nz;
145  fGasVolumeZ = 1000.*mm - fAbsorberShiftZ - fAirZ - fTarget1Z - fTarget2Z;
146 
147  G4double ztot = fGasVolumeZ + fAirZ + fPhantomZ + fDistanceVacuumTarget;
148  fTargetVolumeZ = fDistanceVacuumTarget + fTarget2Z + fTarget1Z + fDelta;
149  fWorldZ = factor*ztot*0.5;
150 
151  if(fCheckShiftZ < fDelta) { fCheckShiftZ = fDelta; }
152  if(fCheckShiftZ > fAirZ - fCheckVolumeZ -fDelta) {
153  fCheckShiftZ = fAirZ - fCheckVolumeZ -fDelta;
154  }
155 
156  // Z position of volumes from upstream to downstream
157 
158  fWindowPosZ = -(ztot + fWindowZ)*0.5;
159  fGeneratorPosZ = fWindowPosZ - 0.5*fWindowZ - fDelta;
160 
161  fTargetVolumePosZ= -0.5*(ztot - fTargetVolumeZ);
162  fTarget1PosZ = -0.5*(fTargetVolumeZ - fTarget1Z) + fDistanceVacuumTarget;
163  fTarget2PosZ = fTarget1PosZ + 0.5*(fTarget2Z + fTarget1Z);
164 
165  fGasVolumePosZ = fTargetVolumePosZ + 0.5*(fTargetVolumeZ + fGasVolumeZ);
166  fCheckVolumePosZ = fGasVolumePosZ + 0.5*(fGasVolumeZ + fCheckVolumeZ)
167  + fCheckShiftZ;
168  fMylarPosZ = fGasVolumePosZ + 0.5*(fGasVolumeZ + fMylarVolumeZ) + fDelta;
169 
170  fPhantomPosZ = fGasVolumePosZ + 0.5*(fGasVolumeZ + fPhantomZ) + fAirZ;
171  fAbsorberPosZ = fAbsorberShiftZ - 0.5*(fPhantomZ - fAbsorberZ);
172  (Histo::GetPointer())->SetAbsorberZ(fPhantomZ);
173  (Histo::GetPointer())->SetAbsorberR(fAbsorberRadius);
174  (Histo::GetPointer())->SetScoreZ(fAbsorberShiftZ);
175  G4double shiftZPh = fPhantomPosZ-0.5*fPhantomZ;
176  fPhantomSD->SetShiftZ(shiftZPh);
177 
178  G4cout << "===================================================" << G4endl;
179  G4cout << "# GammaTherapy Geometry #" << G4endl;
180  G4cout << "===================================================" << G4endl;
181  G4cout << " World width= " << fWorldZ/mm << " mm " << G4endl;
182  G4cout << " Window width= " << fWindowZ/mm << " mm position = "
183  << fWindowPosZ/mm << " mm:" << G4endl;
184  G4cout << " TargetV width= " << fTargetVolumeZ/mm << " mm position = "
185  << fTargetVolumePosZ/mm << " mm:" << G4endl;
186  G4cout << " Target1 width= " << fTarget1Z/mm << " mm position = "
187  << fTarget1PosZ/mm << " mm:" << G4endl;
188  G4cout << " Target2 width= " << fTarget2Z/mm << " mm position = "
189  << fTarget2PosZ/mm << " mm:" << G4endl;
190  G4cout << " Gas width= " << fGasVolumeZ/mm << " mm position = "
191  << fGasVolumePosZ/mm << " mm:" << G4endl;
192  G4cout << " Mylar width= " << fMylarVolumeZ/mm << " mm position = "
193  << fMylarPosZ/mm << " mm:" << G4endl;
194  G4cout << " Check width= " << fCheckVolumeZ/mm << " mm position = "
195  << fCheckVolumePosZ/mm << " mm:" << G4endl;
196  G4cout << " Air width= " << fAirZ/mm << " mm " << G4endl;
197  G4cout << " Phantom width= " << fPhantomZ/mm << " mm position = "
198  << fPhantomPosZ/mm << " mm:" << G4endl;
199  G4cout << " Absorb width= " << fAbsorberZ/mm << " mm position = "
200  << fAbsorberPosZ/mm << " mm:" << G4endl;
201  G4cout << " Absorb shift= " << shiftZPh/mm << " mm " << G4endl;
202  G4cout << " Target1 " << fTarget1Material->GetName() << G4endl;
203  G4cout << " Target2 " << fTarget2Material->GetName() << G4endl;
204  G4cout << " Phantom " << fAbsorberMaterial->GetName() << G4endl;
205  G4cout << "===================================================" << G4endl;
206 }
207 
208 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
209 
211 {
212  InitialiseGeometryParameters();
213 
214  //
215  // World
216  //
217  G4VPhysicalVolume* pv;
218 
219  G4Box* solidWorld = new G4Box("World",fWorldXY,fWorldXY,fWorldZ);
220  G4LogicalVolume* logicWorld = new G4LogicalVolume(solidWorld,
221  fWorldMaterial,"World");
222  G4VPhysicalVolume* physWorld = new G4PVPlacement(0,G4ThreeVector(),"World",
223  logicWorld,0,false,0);
224 
225  // Be Vacuum window
226  G4Tubs* solidWin = new G4Tubs("Window",0.,fTargetRadius*0.25,0.5*fWindowZ,
227  0.,twopi);
228  G4LogicalVolume* logicWin = new G4LogicalVolume(solidWin,
229  fWindowMaterial,"Window");
230  pv = new G4PVPlacement(0,G4ThreeVector(0.,0.,fWindowPosZ),"Window",logicWin,
231  physWorld,false,0);
232 
233  // Target Volume
234  G4Tubs* solidTGVolume = new G4Tubs("TargetVolume",0.,fTargetRadius,
235  0.5*fTargetVolumeZ,0.,twopi);
236  G4LogicalVolume* logicTGVolume = new G4LogicalVolume(solidTGVolume,
237  fLightMaterial,
238  "TargetVolume");
239  pv = new G4PVPlacement(0,G4ThreeVector(0.,0.,fTargetVolumePosZ),
240  logicTGVolume,"TargetVolume",
241  logicWorld,false,0);
242 
243  // Target 1
244  G4Tubs* solidTarget1 = new G4Tubs("Target1",0.,fTargetRadius*0.5,
245  0.5*fTarget1Z,0.,twopi);
246  fLogicTarget1 = new G4LogicalVolume(solidTarget1,fTarget1Material,"Target1");
247  pv = new G4PVPlacement(0,G4ThreeVector(0.,0.,fTarget1PosZ),
248  fLogicTarget1,"Target1",
249  logicTGVolume,false,0);
250  (Histo::GetPointer())->SetTarget1(pv);
251  fLogicTarget1->SetSensitiveDetector(fTargetSD);
252 
253  // Target 2 (for combined targets)
254  G4Tubs* solidTarget2 = new G4Tubs("Target2",0.,fTargetRadius*0.5,
255  0.5*fTarget2Z,0.,twopi);
256  fLogicTarget2 = new G4LogicalVolume(solidTarget2,fTarget2Material,"Target2");
257  pv = new G4PVPlacement(0,G4ThreeVector(0.,0.,fTarget2PosZ),
258  fLogicTarget2,"Target2",
259  logicTGVolume,false,0);
260 
261  (Histo::GetPointer())->SetTarget2(pv);
262  fLogicTarget2->SetSensitiveDetector(fTargetSD);
263 
264  // Gas Volume
265  G4Tubs* solidGasVolume = new G4Tubs("GasVolume",0.,fGasVolumeRadius,
266  0.5*fGasVolumeZ,0.,twopi);
267  G4LogicalVolume* logicGasVolume = new G4LogicalVolume(solidGasVolume,
268  fLightMaterial,
269  "GasVolume");
270  pv = new G4PVPlacement(0,G4ThreeVector(0.,0.,fGasVolumePosZ),
271  "GasVolume",logicGasVolume,
272  physWorld,false,0);
273  (Histo::GetPointer())->SetGasVolume(pv);
274 
275  // Mylar window
276  G4Tubs* sMylarVolume = new G4Tubs("Mylar",0.,fGasVolumeRadius,
277  0.5*fMylarVolumeZ,0.,twopi);
278  G4LogicalVolume* lMylarVolume = new G4LogicalVolume(sMylarVolume,
279  fMylar,"Mylar");
280  pv = new G4PVPlacement(0,G4ThreeVector(0.,0.,fMylarPosZ),"Mylar",lMylarVolume,
281  physWorld,false,0);
282 
283  // Check Volume
284  G4Tubs* solidCheckVolume = new G4Tubs("CheckVolume",0.,fGasVolumeRadius,
285  0.5*fCheckVolumeZ,0.,twopi);
286  G4LogicalVolume* logicCheckVolume = new G4LogicalVolume(solidCheckVolume,
287  fWorldMaterial,
288  "CheckVolume");
289  pv = new G4PVPlacement(0,G4ThreeVector(0.,0.,fCheckVolumePosZ),
290  "CheckVolume",logicCheckVolume,
291  physWorld,false,0);
292  (Histo::GetPointer())->SetCheckVolume(pv);
293  logicCheckVolume->SetSensitiveDetector(fCheckSD);
294 
295  // Phantom
296  G4Box* solidPhantom = new G4Box("Phantom",fPhantomRadius,fPhantomRadius,
297  0.5*fPhantomZ);
298  G4LogicalVolume* logicPhantom = new G4LogicalVolume(solidPhantom,
299  fAbsorberMaterial,
300  "Phantom");
301  G4VPhysicalVolume* physPhantom =
302  new G4PVPlacement(0, G4ThreeVector(0.,0.,fPhantomPosZ),
303  "Phantom",logicPhantom,
304  physWorld,false,0);
305 
306  G4Tubs* solidPh = new G4Tubs("PhantomSD",0.,fAbsorberRadius,
307  0.5*fPhantomZ,0.,twopi);
308  G4LogicalVolume* logicPh = new G4LogicalVolume(solidPh,
309  fAbsorberMaterial,"PhantomSD");
310  G4VPhysicalVolume* physPh = new G4PVPlacement(0,G4ThreeVector(0.,0.,0.),
311  "Phantom",logicPh,
312  physPhantom,false,0);
313  G4cout << "Phantom R= " << fAbsorberRadius << " dz= " << 0.5*fPhantomZ
314  << G4endl;
315 
316  // Sensitive Absorber
317  G4double absWidth = 0.5*fAbsorberZ;
318  G4Tubs* solidAbsorber = new G4Tubs("Absorber",0.,fAbsorberRadius,absWidth,
319  0.,twopi);
320  G4LogicalVolume* logicAbsorber = new G4LogicalVolume(solidAbsorber,
321  fAbsorberMaterial,
322  "Absorber");
323  G4cout << "Absorber R= " << fAbsorberRadius << " dz= " << absWidth
324  << " posZ= " << fAbsorberPosZ<< G4endl;
325 
326  pv = new G4PVPlacement(0,G4ThreeVector(0.,0.,fAbsorberPosZ),"Absorber",
327  logicAbsorber,physPh,false,0);
328  (Histo::GetPointer())->SetPhantom(physPh);
329  G4int numR = (Histo::GetPointer())->GetNumberDivR();
330  G4double stepR = fAbsorberRadius/(G4double)numR;
331 
332  G4double r1 = 0.0;
333  G4double r2 = 0.0;
334  G4Tubs* solidRing;
335  G4LogicalVolume* logicRing;
336 
337  for(G4int k=0; k<numR; k++) {
338  r2 = r1 + stepR;
339  if(k == numR-1) r2 = fAbsorberRadius;
340  // G4cout << "New ring r1= " << r1 << " r2= " << r2
341  // << " dz= " << absWidth << G4endl;
342  solidRing = new G4Tubs("Ring",r1,r2,absWidth,0.,twopi);
343  logicRing = new G4LogicalVolume(solidRing,fAbsorberMaterial,"Ring");
344  logicRing->SetSensitiveDetector(fPhantomSD);
346  pv = new G4PVPlacement(0,G4ThreeVector(0.,0.,0.),logicRing,"Ring",
347  logicAbsorber,false,k);
348  r1 = r2;
349  }
350  //
351  // Sensitive Detectors: Absorber
352  //
353  logicPh->SetSensitiveDetector(fPhantomSD);
354  logicAbsorber->SetSensitiveDetector(fPhantomSD);
355  //
356  // Visualization attributes
357  //
358  G4VisAttributes* VisAtt = 0;
359  VisAtt = new G4VisAttributes(G4Colour(1.0,1.0,1.0));
360  VisAtt->SetVisibility(true);
361  logicAbsorber->SetVisAttributes(VisAtt);
362 
363  VisAtt= new G4VisAttributes(G4Colour(1.0,1.0,2.0));
364  VisAtt->SetVisibility(true);
365  logicPhantom->SetVisAttributes(VisAtt);
366 
367  VisAtt= new G4VisAttributes(G4Colour(1.0,0.0,2.0));
368  VisAtt->SetVisibility(true);
369  logicPh->SetVisAttributes(VisAtt);
370 
371  VisAtt= new G4VisAttributes(G4Colour(1.0,1.0,0.0));
372  VisAtt->SetVisibility(true);
373  logicAbsorber->SetVisAttributes(VisAtt);
374 
375  VisAtt= new G4VisAttributes(G4Colour(0.1,1.0,2.0));
376  VisAtt->SetVisibility(true);
377  logicWorld->SetVisAttributes(VisAtt);
378 
379  VisAtt= new G4VisAttributes(G4Colour(1.0,1.0,0.0));
380  VisAtt->SetVisibility(true);
381  logicGasVolume->SetVisAttributes(VisAtt);
382 
383  VisAtt= new G4VisAttributes(G4Colour(0.0,0.5,1.0));
384  VisAtt->SetVisibility(true);
385  fLogicTarget1->SetVisAttributes(VisAtt);
386  fLogicTarget2->SetVisAttributes(VisAtt);
387  logicTGVolume->SetVisAttributes(VisAtt);
388 
389  return physWorld;
390 }
391 
392 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
393 
395 {
396  // search the material by its name
397  G4Material* pttoMaterial =
399  if(!pttoMaterial) {
400  G4cout << "Material " << mat << " is not found out!" << G4endl;
401  } else if (pttoMaterial != fTarget1Material) {
402  G4cout << "New target1 material " << mat << G4endl;
403  if(fLogicTarget1) { fLogicTarget1->SetMaterial(fTarget1Material); }
405  }
406 }
407 
408 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
409 
411 {
412  // search the material by its name
413  G4Material* pttoMaterial =
415 
416  if(!pttoMaterial) {
417  G4cout << "Material " << mat << " is not found out!" << G4endl;
418  } else if (pttoMaterial != fTarget2Material) {
419  fTarget2Material = pttoMaterial;
420  G4cout << "New target2 material " << mat << G4endl;
421  if(fLogicTarget2) { fLogicTarget2->SetMaterial(fTarget2Material); }
423  }
424 }
425 
426 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4Material * FindOrBuildMaterial(const G4String &name, G4bool isotopes=true, G4bool warning=false)
void SetShiftZ(G4double val)
Definition: PhantomSD.hh:69
static Histo * GetPointer()
Definition: Histo.cc:59
static constexpr double mm
Definition: G4SIunits.hh:115
CLHEP::Hep3Vector G4ThreeVector
Definition: G4Box.hh:64
const G4String & GetName() const
Definition: G4Material.hh:178
G4VPhysicalVolume * Construct()
Definition: G4Tubs.hh:85
static G4MaterialTable * GetMaterialTable()
Definition: G4Material.cc:587
int G4int
Definition: G4Types.hh:78
static G4NistManager * Instance()
void SetTarget2Material(const G4String &m)
static constexpr double twopi
Definition: G4SIunits.hh:76
G4GLOB_DLL std::ostream G4cout
void SetAbsorberZ(G4double val)
void PhysicsHasBeenModified()
void SetVisibility(G4bool=true)
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
Definition of the PhantomSD class.
T max(const T t1, const T t2)
brief Return the largest of the two arguments
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:40
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
void SetTarget1Material(const G4String &m)
void SetMaterial(G4Material *pMaterial)
static const G4VisAttributes & GetInvisible()
void SetVisAttributes(const G4VisAttributes *pVA)
void SetSensitiveDetector(G4VSensitiveDetector *pSDetector)