ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DetectorConstruction.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file 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 //
29 //
30 //
31 // -------------------------------------------------------------
32 // GEANT4 ibrem test
33 //
34 // Authors: V.Grichine, V.Ivanchenko
35 //
36 // Modified:
37 //
38 // 18-02-03 V.Ivanchenko create
39 //
40 // -------------------------------------------------------------
41 
42 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
43 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
44 
45 #include "DetectorConstruction.hh"
46 #include "DetectorMessenger.hh"
47 #include "PhantomSD.hh"
48 #include "TargetSD.hh"
49 #include "CheckVolumeSD.hh"
50 
51 #include "G4Box.hh"
52 #include "G4Tubs.hh"
53 #include "G4LogicalVolume.hh"
54 #include "G4VPhysicalVolume.hh"
55 #include "G4PVPlacement.hh"
56 #include "G4Material.hh"
57 #include "G4SDManager.hh"
58 #include "PhantomSD.hh"
59 #include "G4NistManager.hh"
60 
61 #include "G4PhysicalVolumeStore.hh"
62 #include "G4LogicalVolumeStore.hh"
63 #include "G4SolidStore.hh"
64 #include "G4RunManager.hh"
65 #include "G4GeometryManager.hh"
66 
67 #include "G4VisAttributes.hh"
68 #include "G4Colour.hh"
69 
70 #include "globals.hh"
71 #include "G4PhysicalConstants.hh"
72 #include "G4SystemOfUnits.hh"
73 #include "G4ios.hh"
74 
75 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
76 
78 {
79  fLogicTarget1 = 0;
80  fLogicTarget2 = 0;
81 
82  fMessenger = new DetectorMessenger(this);
83  fVerbose = false;
84 
85  fNumZ = 60;
86  fNumR = 80;
87 
88  fNumE = 200;
89  fMaxEnergy = 50.0*MeV;
90 
92 
93  fDelta = 0.001*mm;
94 
95  fTargetRadius = 100.*mm;
96  fTarget1Z = 9.*mm;
97  fTarget2Z = 6.*mm;
98 
99  fGasVolumeRadius = 210.*mm;
100  fGasVolumeZ = 690.*mm;
101  fMylarVolumeZ = 0.02*mm;
102 
103  fCheckVolumeZ = 0.1*mm;
104  fCheckShiftZ = 200.*mm;
105 
106  fAbsorberRadius = 200.*mm;
107  fPhantomRadius = 300.*mm;
108  fPhantomZ = 300.*mm;
109 
110  fAirZ = 210.*mm;
111  fAbsorberShiftZ = 70.*mm;
112  fWindowZ = 0.05*mm;
113 
115  //man->SetVerbose(1);
116 
117  fTarget1Material = man->FindOrBuildMaterial("G4_Be");
119  fTarget2Material = man->FindOrBuildMaterial("G4_W");
120  fLightMaterial = man->FindOrBuildMaterial("G4_He");
121  fAbsorberMaterial= man->FindOrBuildMaterial("G4_WATER");
122  fWorldMaterial = man->FindOrBuildMaterial("G4_AIR");
123  fMylar = man->FindOrBuildMaterial("G4_MYLAR");
124 
126 }
127 
128 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
129 
131 {
132  delete fMessenger;
133 }
134 
135 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
136 
138 {
139  // Volumee sizes
140 
141  G4double factor = 1.2;
142 
146 
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) {
154  }
155 
156  // Z position of volumes from upstream to downstream
157 
158  fWindowPosZ = -(ztot + fWindowZ)*0.5;
160 
161  fTargetVolumePosZ= -0.5*(ztot - fTargetVolumeZ);
162  fTarget1PosZ = -0.5*(fTargetVolumeZ - fTarget1Z) + fDistanceVacuumTarget;
163  fTarget2PosZ = fTarget1PosZ + 0.5*(fTarget2Z + fTarget1Z);
164 
167  + fCheckShiftZ;
168  fMylarPosZ = fGasVolumePosZ + 0.5*(fGasVolumeZ + fMylarVolumeZ) + fDelta;
169 
172 
174 
176 }
177 
178 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
179 
181 {
183 
188  //
189  // World
190  //
191 
192  G4Box* solidWorld = new G4Box("World",fWorldXY,fWorldXY,fWorldZ);
193  G4LogicalVolume* logicWorld = new G4LogicalVolume(solidWorld,
194  fWorldMaterial,"World");
196  logicWorld,0,false,0);
197 
198  // Be Vacuum window
199  G4Tubs* solidWin = new G4Tubs("Window",0.,fTargetRadius*0.25,0.5*fWindowZ,
200  0.,twopi);
201  G4LogicalVolume* logicWin = new G4LogicalVolume(solidWin,
202  fWindowMaterial,"Window");
203  new G4PVPlacement(0,G4ThreeVector(0.,0.,fWindowPosZ),"Window",logicWin,
204  physWorld,false,0);
205 
206  // Target Volume
207  G4Tubs* solidTGVolume = new G4Tubs("TargetVolume",0.,fTargetRadius,
208  0.5*fTargetVolumeZ,0.,twopi);
209  G4LogicalVolume* logicTGVolume = new G4LogicalVolume(solidTGVolume,
211  "TargetVolume");
213  logicTGVolume,"TargetVolume",
214  logicWorld,false,0);
215 
216  // Target 1
217  G4Tubs* solidTarget1 = new G4Tubs("Target1",0.,fTargetRadius*0.5,
218  0.5*fTarget1Z,0.,twopi);
219  fLogicTarget1 = new G4LogicalVolume(solidTarget1,fTarget1Material,"Target1");
221  fLogicTarget1,"Target1",
222  logicTGVolume,false,0);
223  // fLogicTarget1->SetSensitiveDetector(fTargetSD);
224 
225  // Target 2 (for combined targets)
226  G4Tubs* solidTarget2 = new G4Tubs("Target2",0.,fTargetRadius*0.5,
227  0.5*fTarget2Z,0.,twopi);
228  fLogicTarget2 = new G4LogicalVolume(solidTarget2,fTarget2Material,"Target2");
230  fLogicTarget2,"Target2",
231  logicTGVolume,false,0);
232 
233  // fLogicTarget2->SetSensitiveDetector(fTargetSD);
234 
235  // Gas Volume
236  G4Tubs* solidGasVolume = new G4Tubs("GasVolume",0.,fGasVolumeRadius,
237  0.5*fGasVolumeZ,0.,twopi);
238  G4LogicalVolume* logicGasVolume = new G4LogicalVolume(solidGasVolume,
240  "GasVolume");
242  "GasVolume",logicGasVolume,
243  physWorld,false,0);
244 
245  // Mylar window
246  G4Tubs* sMylarVolume = new G4Tubs("Mylar",0.,fGasVolumeRadius,
247  0.5*fMylarVolumeZ,0.,twopi);
248  G4LogicalVolume* lMylarVolume = new G4LogicalVolume(sMylarVolume,
249  fMylar,"Mylar");
250  new G4PVPlacement(0,G4ThreeVector(0.,0.,fMylarPosZ),"Mylar",lMylarVolume,
251  physWorld,false,0);
252 
253  // Check Volume
254  G4Tubs* solidCheckVolume = new G4Tubs("CheckVolume",0.,fGasVolumeRadius,
255  0.5*fCheckVolumeZ,0.,twopi);
256  fLogicCheckVolume = new G4LogicalVolume(solidCheckVolume,
258  "CheckVolume");
260  "CheckVolume",fLogicCheckVolume,
261  physWorld,false,0);
262  // logicCheckVolume->SetSensitiveDetector(fCheckSD);
263 
264  // Phantom
265  G4Box* solidPhantom = new G4Box("Phantom",fPhantomRadius,fPhantomRadius,
266  0.5*fPhantomZ);
267  G4LogicalVolume* logicPhantom = new G4LogicalVolume(solidPhantom,
269  "Phantom");
270  G4VPhysicalVolume* physPhantom =
272  "Phantom",logicPhantom,
273  physWorld,false,0);
274 
275  G4Tubs* solidPh = new G4Tubs("PhantomSD",0.,fAbsorberRadius,
276  0.5*fPhantomZ,0.,twopi);
277  fLogicPh = new G4LogicalVolume(solidPh,
278  fAbsorberMaterial,"PhantomSD");
279  fPhantom = new G4PVPlacement(0,G4ThreeVector(0.,0.,0.),
280  "Phantom",fLogicPh,
281  physPhantom,false,0);
282  G4cout << "Phantom R= " << fAbsorberRadius << " dz= " << 0.5*fPhantomZ
283  << G4endl;
284 
285  // Sensitive Absorber
286  G4double absWidth = 0.5*fAbsorberZ;
287  G4Tubs* solidAbsorber = new G4Tubs("Absorber",0.,fAbsorberRadius,absWidth,
288  0.,twopi);
289  fLogicAbsorber = new G4LogicalVolume(solidAbsorber,
291  "Absorber");
292  G4cout << "Absorber R= " << fAbsorberRadius << " dz= " << absWidth
293  << " posZ= " << fAbsorberPosZ<< G4endl;
294 
295  new G4PVPlacement(0,G4ThreeVector(0.,0.,fAbsorberPosZ),"Absorber",
296  fLogicAbsorber,fPhantom,false,0);
297 
299 
300  G4double r1 = 0.0;
301  G4double r2 = 0.0;
302  G4Tubs* solidRing;
303 
304  G4VisAttributes* VisAtt_ring =
306  for(G4int k=0; k<fNumR; k++) {
307  r2 = r1 + stepR;
308  if(k == fNumR-1) r2 = fAbsorberRadius;
309  // G4cout << "New ring r1= " << r1 << " r2= " << r2
310  // << " dz= " << absWidth << G4endl;
311  solidRing = new G4Tubs("Ring",r1,r2,absWidth,0.,twopi);
312  G4LogicalVolume* logicRing = new G4LogicalVolume(solidRing,
313  fAbsorberMaterial,"Ring");
314  // logicRing->SetSensitiveDetector(fPhantomSD);
315  logicRing->SetVisAttributes(VisAtt_ring);
316  fLogicRing.push_back(logicRing);
317  new G4PVPlacement(0,G4ThreeVector(0.,0.,0.),logicRing,"Ring",
318  fLogicAbsorber,false,k);
319  r1 = r2;
320  }
321 
322  //
323  // Visualization attributes
324  //
325  G4VisAttributes* VisAtt = 0;
326  VisAtt = new G4VisAttributes(G4Colour(1.0,1.0,1.0));
327  VisAtt->SetVisibility(true);
329 
330  VisAtt= new G4VisAttributes(G4Colour(1.0,1.0,2.0));
331  VisAtt->SetVisibility(true);
332  logicPhantom->SetVisAttributes(VisAtt);
333 
334  VisAtt= new G4VisAttributes(G4Colour(1.0,0.0,2.0));
335  VisAtt->SetVisibility(true);
336  fLogicPh->SetVisAttributes(VisAtt);
337 
338  VisAtt= new G4VisAttributes(G4Colour(1.0,1.0,0.0));
339  VisAtt->SetVisibility(true);
341 
342  VisAtt= new G4VisAttributes(G4Colour(0.1,1.0,2.0));
343  VisAtt->SetVisibility(true);
344  logicWorld->SetVisAttributes(VisAtt);
345 
346  VisAtt= new G4VisAttributes(G4Colour(1.0,1.0,0.0));
347  VisAtt->SetVisibility(true);
348  logicGasVolume->SetVisAttributes(VisAtt);
349 
350  VisAtt= new G4VisAttributes(G4Colour(0.0,0.5,1.0));
351  VisAtt->SetVisibility(true);
354  logicTGVolume->SetVisAttributes(VisAtt);
355 
356  return physWorld;
357 }
358 
359 
361 {
362  static G4ThreadLocal G4bool initialized = false;
363  if ( ! initialized ) {
364  // Prepare sensitive detectors
365  CheckVolumeSD* fCheckSD = new CheckVolumeSD("checkSD");
366  (G4SDManager::GetSDMpointer())->AddNewDetector( fCheckSD );
368 
369  TargetSD* fTargetSD = new TargetSD("targetSD");
370  (G4SDManager::GetSDMpointer())->AddNewDetector( fTargetSD );
373 
374  PhantomSD* fPhantomSD = new PhantomSD("phantomSD");
375  (G4SDManager::GetSDMpointer())->AddNewDetector( fPhantomSD );
376  fPhantomSD->SetShiftZ(fShiftZPh);
377  for(auto& v : fLogicRing)
378  v->SetSensitiveDetector(fPhantomSD);
379  fLogicPh->SetSensitiveDetector(fPhantomSD);
381  initialized=true;
382  }
383 }
384 
385 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
386 
388 {
389  // search the material by its name
390  G4Material* pttoMaterial =
392  if(!pttoMaterial) {
393  G4cout << "Material " << mat << " is not found out!" << G4endl;
394  } else if (pttoMaterial != fTarget1Material) {
395  G4cout << "New target1 material " << mat << G4endl;
398  }
399 }
400 
401 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
402 
404 {
405  // search the material by its name
406  G4Material* pttoMaterial =
408 
409  if(!pttoMaterial) {
410  G4cout << "Material " << mat << " is not found out!" << G4endl;
411  } else if (pttoMaterial != fTarget2Material) {
412  fTarget2Material = pttoMaterial;
413  G4cout << "New target2 material " << mat << G4endl;
416  }
417 }
418 
419 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
420 
422 {
423 
424  G4cout << "===================================================" << G4endl;
425  G4cout << "# GammaTherapy Geometry #" << G4endl;
426  G4cout << "===================================================" << G4endl;
427  G4cout << " World width= " << fWorldZ/mm << " mm " << G4endl;
428  G4cout << " Window width= " << fWindowZ/mm << " mm position = "
429  << fWindowPosZ/mm << " mm:" << G4endl;
430  G4cout << " TargetV width= " << fTargetVolumeZ/mm << " mm position = "
431  << fTargetVolumePosZ/mm << " mm:" << G4endl;
432  G4cout << " Target1 width= " << fTarget1Z/mm << " mm position = "
433  << fTarget1PosZ/mm << " mm:" << G4endl;
434  G4cout << " Target2 width= " << fTarget2Z/mm << " mm position = "
435  << fTarget2PosZ/mm << " mm:" << G4endl;
436  G4cout << " Gas width= " << fGasVolumeZ/mm << " mm position = "
437  << fGasVolumePosZ/mm << " mm:" << G4endl;
438  G4cout << " Mylar width= " << fMylarVolumeZ/mm << " mm position = "
439  << fMylarPosZ/mm << " mm:" << G4endl;
440  G4cout << " Check width= " << fCheckVolumeZ/mm << " mm position = "
441  << fCheckVolumePosZ/mm << " mm:" << G4endl;
442  G4cout << " Air width= " << fAirZ/mm << " mm " << G4endl;
443  G4cout << " Phantom width= " << fPhantomZ/mm << " mm position = "
444  << fPhantomPosZ/mm << " mm:" << G4endl;
445  G4cout << " Absorb width= " << fAbsorberZ/mm << " mm position = "
446  << fAbsorberPosZ/mm << " mm:" << G4endl;
447  G4cout << " Absorb shift= " << fShiftZPh/mm << " mm " << G4endl;
448  G4cout << " Target1 " << fTarget1Material->GetName() << G4endl;
449  G4cout << " Target2 " << fTarget2Material->GetName() << G4endl;
450  G4cout << " Phantom " << fAbsorberMaterial->GetName() << G4endl;
451  G4cout << "===================================================" << G4endl;
452 
453 }