Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
examples/extended/medical/GammaTherapy/src/DetectorConstruction.cc
이 파일의 문서화 페이지로 가기
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 103469 2017-04-11 07:29:36Z gcosmo $
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 
52 #include "G4Box.hh"
53 #include "G4Tubs.hh"
54 #include "G4LogicalVolume.hh"
55 #include "G4VPhysicalVolume.hh"
56 #include "G4PVPlacement.hh"
57 #include "G4Material.hh"
58 #include "G4SDManager.hh"
59 #include "PhantomSD.hh"
60 #include "G4NistManager.hh"
61 
62 #include "G4PhysicalVolumeStore.hh"
63 #include "G4LogicalVolumeStore.hh"
64 #include "G4SolidStore.hh"
65 #include "G4RunManager.hh"
66 #include "G4GeometryManager.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  fVerbose = false;
85 
86  fNumZ = 60;
87  fNumR = 80;
88 
89  fNumE = 200;
90  fMaxEnergy = 50.0*MeV;
91 
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");
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  delete fMessenger;
134 }
135 
136 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
137 
139 {
140  // Volumee sizes
141 
142  G4double factor = 1.2;
143 
147 
149  fTargetVolumeZ = fDistanceVacuumTarget + fTarget2Z + fTarget1Z + fDelta;
150  fWorldZ = factor*ztot*0.5;
151 
152  if(fCheckShiftZ < fDelta) { fCheckShiftZ = fDelta; }
153  if(fCheckShiftZ > fAirZ - fCheckVolumeZ -fDelta) {
155  }
156 
157  // Z position of volumes from upstream to downstream
158 
159  fWindowPosZ = -(ztot + fWindowZ)*0.5;
161 
162  fTargetVolumePosZ= -0.5*(ztot - fTargetVolumeZ);
163  fTarget1PosZ = -0.5*(fTargetVolumeZ - fTarget1Z) + fDistanceVacuumTarget;
164  fTarget2PosZ = fTarget1PosZ + 0.5*(fTarget2Z + fTarget1Z);
165 
168  + fCheckShiftZ;
169  fMylarPosZ = fGasVolumePosZ + 0.5*(fGasVolumeZ + fMylarVolumeZ) + fDelta;
170 
173 
175 
177 }
178 
179 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
180 
182 {
184 
189  //
190  // World
191  //
192 
193  G4Box* solidWorld = new G4Box("World",fWorldXY,fWorldXY,fWorldZ);
194  G4LogicalVolume* logicWorld = new G4LogicalVolume(solidWorld,
195  fWorldMaterial,"World");
196  G4VPhysicalVolume* physWorld = new G4PVPlacement(0,G4ThreeVector(),"World",
197  logicWorld,0,false,0);
198 
199  // Be Vacuum window
200  G4Tubs* solidWin = new G4Tubs("Window",0.,fTargetRadius*0.25,0.5*fWindowZ,
201  0.,twopi);
202  G4LogicalVolume* logicWin = new G4LogicalVolume(solidWin,
203  fWindowMaterial,"Window");
204  new G4PVPlacement(0,G4ThreeVector(0.,0.,fWindowPosZ),"Window",logicWin,
205  physWorld,false,0);
206 
207  // Target Volume
208  G4Tubs* solidTGVolume = new G4Tubs("TargetVolume",0.,fTargetRadius,
209  0.5*fTargetVolumeZ,0.,twopi);
210  G4LogicalVolume* logicTGVolume = new G4LogicalVolume(solidTGVolume,
212  "TargetVolume");
214  logicTGVolume,"TargetVolume",
215  logicWorld,false,0);
216 
217  // Target 1
218  G4Tubs* solidTarget1 = new G4Tubs("Target1",0.,fTargetRadius*0.5,
219  0.5*fTarget1Z,0.,twopi);
220  fLogicTarget1 = new G4LogicalVolume(solidTarget1,fTarget1Material,"Target1");
222  fLogicTarget1,"Target1",
223  logicTGVolume,false,0);
224  // fLogicTarget1->SetSensitiveDetector(fTargetSD);
225 
226  // Target 2 (for combined targets)
227  G4Tubs* solidTarget2 = new G4Tubs("Target2",0.,fTargetRadius*0.5,
228  0.5*fTarget2Z,0.,twopi);
229  fLogicTarget2 = new G4LogicalVolume(solidTarget2,fTarget2Material,"Target2");
231  fLogicTarget2,"Target2",
232  logicTGVolume,false,0);
233 
234  // fLogicTarget2->SetSensitiveDetector(fTargetSD);
235 
236  // Gas Volume
237  G4Tubs* solidGasVolume = new G4Tubs("GasVolume",0.,fGasVolumeRadius,
238  0.5*fGasVolumeZ,0.,twopi);
239  G4LogicalVolume* logicGasVolume = new G4LogicalVolume(solidGasVolume,
241  "GasVolume");
243  "GasVolume",logicGasVolume,
244  physWorld,false,0);
245 
246  // Mylar window
247  G4Tubs* sMylarVolume = new G4Tubs("Mylar",0.,fGasVolumeRadius,
248  0.5*fMylarVolumeZ,0.,twopi);
249  G4LogicalVolume* lMylarVolume = new G4LogicalVolume(sMylarVolume,
250  fMylar,"Mylar");
251  new G4PVPlacement(0,G4ThreeVector(0.,0.,fMylarPosZ),"Mylar",lMylarVolume,
252  physWorld,false,0);
253 
254  // Check Volume
255  G4Tubs* solidCheckVolume = new G4Tubs("CheckVolume",0.,fGasVolumeRadius,
256  0.5*fCheckVolumeZ,0.,twopi);
257  fLogicCheckVolume = new G4LogicalVolume(solidCheckVolume,
259  "CheckVolume");
261  "CheckVolume",fLogicCheckVolume,
262  physWorld,false,0);
263  // logicCheckVolume->SetSensitiveDetector(fCheckSD);
264 
265  // Phantom
266  G4Box* solidPhantom = new G4Box("Phantom",fPhantomRadius,fPhantomRadius,
267  0.5*fPhantomZ);
268  G4LogicalVolume* logicPhantom = new G4LogicalVolume(solidPhantom,
270  "Phantom");
271  G4VPhysicalVolume* physPhantom =
273  "Phantom",logicPhantom,
274  physWorld,false,0);
275 
276  G4Tubs* solidPh = new G4Tubs("PhantomSD",0.,fAbsorberRadius,
277  0.5*fPhantomZ,0.,twopi);
278  fLogicPh = new G4LogicalVolume(solidPh,
279  fAbsorberMaterial,"PhantomSD");
280  fPhantom = new G4PVPlacement(0,G4ThreeVector(0.,0.,0.),
281  "Phantom",fLogicPh,
282  physPhantom,false,0);
283  G4cout << "Phantom R= " << fAbsorberRadius << " dz= " << 0.5*fPhantomZ
284  << G4endl;
285 
286  // Sensitive Absorber
287  G4double absWidth = 0.5*fAbsorberZ;
288  G4Tubs* solidAbsorber = new G4Tubs("Absorber",0.,fAbsorberRadius,absWidth,
289  0.,twopi);
290  fLogicAbsorber = new G4LogicalVolume(solidAbsorber,
292  "Absorber");
293  G4cout << "Absorber R= " << fAbsorberRadius << " dz= " << absWidth
294  << " posZ= " << fAbsorberPosZ<< G4endl;
295 
296  new G4PVPlacement(0,G4ThreeVector(0.,0.,fAbsorberPosZ),"Absorber",
297  fLogicAbsorber,fPhantom,false,0);
298 
300 
301  G4double r1 = 0.0;
302  G4double r2 = 0.0;
303  G4Tubs* solidRing;
304 
305  G4VisAttributes* VisAtt_ring =
307  for(G4int k=0; k<fNumR; k++) {
308  r2 = r1 + stepR;
309  if(k == fNumR-1) r2 = fAbsorberRadius;
310  // G4cout << "New ring r1= " << r1 << " r2= " << r2
311  // << " dz= " << absWidth << G4endl;
312  solidRing = new G4Tubs("Ring",r1,r2,absWidth,0.,twopi);
313  G4LogicalVolume* logicRing = new G4LogicalVolume(solidRing,
314  fAbsorberMaterial,"Ring");
315  // logicRing->SetSensitiveDetector(fPhantomSD);
316  logicRing->SetVisAttributes(VisAtt_ring);
317  fLogicRing.push_back(logicRing);
318  new G4PVPlacement(0,G4ThreeVector(0.,0.,0.),logicRing,"Ring",
319  fLogicAbsorber,false,k);
320  r1 = r2;
321  }
322 
323  //
324  // Visualization attributes
325  //
326  G4VisAttributes* VisAtt = 0;
327  VisAtt = new G4VisAttributes(G4Colour(1.0,1.0,1.0));
328  VisAtt->SetVisibility(true);
330 
331  VisAtt= new G4VisAttributes(G4Colour(1.0,1.0,2.0));
332  VisAtt->SetVisibility(true);
333  logicPhantom->SetVisAttributes(VisAtt);
334 
335  VisAtt= new G4VisAttributes(G4Colour(1.0,0.0,2.0));
336  VisAtt->SetVisibility(true);
337  fLogicPh->SetVisAttributes(VisAtt);
338 
339  VisAtt= new G4VisAttributes(G4Colour(1.0,1.0,0.0));
340  VisAtt->SetVisibility(true);
342 
343  VisAtt= new G4VisAttributes(G4Colour(0.1,1.0,2.0));
344  VisAtt->SetVisibility(true);
345  logicWorld->SetVisAttributes(VisAtt);
346 
347  VisAtt= new G4VisAttributes(G4Colour(1.0,1.0,0.0));
348  VisAtt->SetVisibility(true);
349  logicGasVolume->SetVisAttributes(VisAtt);
350 
351  VisAtt= new G4VisAttributes(G4Colour(0.0,0.5,1.0));
352  VisAtt->SetVisibility(true);
355  logicTGVolume->SetVisAttributes(VisAtt);
356 
357  return physWorld;
358 }
359 
360 
362 {
363  static G4ThreadLocal G4bool initialized = false;
364  if ( ! initialized ) {
365  // Prepare sensitive detectors
366  CheckVolumeSD* fCheckSD = new CheckVolumeSD("checkSD");
367  (G4SDManager::GetSDMpointer())->AddNewDetector( fCheckSD );
369 
370  TargetSD* fTargetSD = new TargetSD("targetSD");
371  (G4SDManager::GetSDMpointer())->AddNewDetector( fTargetSD );
374 
375  PhantomSD* fPhantomSD = new PhantomSD("phantomSD");
376  (G4SDManager::GetSDMpointer())->AddNewDetector( fPhantomSD );
377  fPhantomSD->SetShiftZ(fShiftZPh);
378  for(auto& v : fLogicRing)
379  v->SetSensitiveDetector(fPhantomSD);
380  fLogicPh->SetSensitiveDetector(fPhantomSD);
382  initialized=true;
383  }
384 }
385 
386 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
387 
389 {
390  // search the material by its name
391  G4Material* pttoMaterial =
393  if(!pttoMaterial) {
394  G4cout << "Material " << mat << " is not found out!" << G4endl;
395  } else if (pttoMaterial != fTarget1Material) {
396  G4cout << "New target1 material " << mat << G4endl;
399  }
400 }
401 
402 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
403 
405 {
406  // search the material by its name
407  G4Material* pttoMaterial =
409 
410  if(!pttoMaterial) {
411  G4cout << "Material " << mat << " is not found out!" << G4endl;
412  } else if (pttoMaterial != fTarget2Material) {
413  fTarget2Material = pttoMaterial;
414  G4cout << "New target2 material " << mat << G4endl;
417  }
418 }
419 
420 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
421 
423 {
424 
425  G4cout << "===================================================" << G4endl;
426  G4cout << "# GammaTherapy Geometry #" << G4endl;
427  G4cout << "===================================================" << G4endl;
428  G4cout << " World width= " << fWorldZ/mm << " mm " << G4endl;
429  G4cout << " Window width= " << fWindowZ/mm << " mm position = "
430  << fWindowPosZ/mm << " mm:" << G4endl;
431  G4cout << " TargetV width= " << fTargetVolumeZ/mm << " mm position = "
432  << fTargetVolumePosZ/mm << " mm:" << G4endl;
433  G4cout << " Target1 width= " << fTarget1Z/mm << " mm position = "
434  << fTarget1PosZ/mm << " mm:" << G4endl;
435  G4cout << " Target2 width= " << fTarget2Z/mm << " mm position = "
436  << fTarget2PosZ/mm << " mm:" << G4endl;
437  G4cout << " Gas width= " << fGasVolumeZ/mm << " mm position = "
438  << fGasVolumePosZ/mm << " mm:" << G4endl;
439  G4cout << " Mylar width= " << fMylarVolumeZ/mm << " mm position = "
440  << fMylarPosZ/mm << " mm:" << G4endl;
441  G4cout << " Check width= " << fCheckVolumeZ/mm << " mm position = "
442  << fCheckVolumePosZ/mm << " mm:" << G4endl;
443  G4cout << " Air width= " << fAirZ/mm << " mm " << G4endl;
444  G4cout << " Phantom width= " << fPhantomZ/mm << " mm position = "
445  << fPhantomPosZ/mm << " mm:" << G4endl;
446  G4cout << " Absorb width= " << fAbsorberZ/mm << " mm position = "
447  << fAbsorberPosZ/mm << " mm:" << G4endl;
448  G4cout << " Absorb shift= " << fShiftZPh/mm << " mm " << G4endl;
449  G4cout << " Target1 " << fTarget1Material->GetName() << G4endl;
450  G4cout << " Target2 " << fTarget2Material->GetName() << G4endl;
451  G4cout << " Phantom " << fAbsorberMaterial->GetName() << G4endl;
452  G4cout << "===================================================" << G4endl;
453 
454 }
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:80
T max(const T t1, const T t2)
brief Return the largest of the two arguments
static void Clean()
Definition: G4SolidStore.cc:73
CLHEP::Hep3Vector G4ThreeVector
static constexpr double MeV
Definition: G4SIunits.hh:214
static G4MaterialTable * GetMaterialTable()
Definition: G4Material.cc:593
static constexpr double mm
Definition: G4SIunits.hh:115
Definition: G4Tubs.hh:85
#define G4endl
Definition: G4ios.hh:61
#define G4ThreadLocal
Definition: tls.hh:69
Definition of the PhantomSD class.
static const G4VisAttributes & GetInvisible()
const G4String & GetName() const
Definition: G4Material.hh:179
double G4double
Definition: G4Types.hh:76
bool G4bool
Definition: G4Types.hh:79
void SetShiftZ(G4double val)
Definition: PhantomSD.hh:68
static G4GeometryManager * GetInstance()
Definition: G4Box.hh:64
G4Material * FindOrBuildMaterial(const G4String &name, G4bool isotopes=true, G4bool warning=false)
static constexpr double twopi
Definition: G4SIunits.hh:76
Float_t mat
void OpenGeometry(G4VPhysicalVolume *vol=0)
void SetVisAttributes(const G4VisAttributes *pVA)
static G4SolidStore * GetInstance()
void SetVisibility(G4bool=true)
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:40
static G4PhysicalVolumeStore * GetInstance()
int G4int
Definition: G4Types.hh:78
void PhysicsHasBeenModified()
G4GLOB_DLL std::ostream G4cout
void SetMaterial(G4Material *pMaterial)
static G4LogicalVolumeStore * GetInstance()
static G4NistManager * Instance()
void SetSensitiveDetector(G4VSensitiveDetector *pSDetector)