Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // This example is provided by the Geant4-DNA 26 // This example is provided by the Geant4-DNA collaboration 27 // Any report or published results obtained us << 27 // Any report or published results obtained using the Geant4-DNA software 28 // shall cite the following Geant4-DNA collabo << 28 // shall cite the following Geant4-DNA collaboration publication: 29 // Med. Phys. 45, (2018) e722-e739 << 30 // Phys. Med. 31 (2015) 861-874 << 31 // Med. Phys. 37 (2010) 4692-4708 29 // Med. Phys. 37 (2010) 4692-4708 32 // Int. J. Model. Simul. Sci. Comput. 1 (2010) << 33 // The Geant4-DNA web site is available at htt 30 // The Geant4-DNA web site is available at http://geant4-dna.org 34 // 31 // 35 // << 36 /// \file DetectorConstruction.cc 32 /// \file DetectorConstruction.cc 37 /// \brief Implementation of the DetectorConst 33 /// \brief Implementation of the DetectorConstruction class 38 34 39 #include "DetectorConstruction.hh" 35 #include "DetectorConstruction.hh" 40 36 41 #include "DetectorMessenger.hh" << 42 #include "PhysicsList.hh" << 43 << 44 #include "G4LogicalVolume.hh" << 45 #include "G4RunManager.hh" << 46 #include "G4SystemOfUnits.hh" 37 #include "G4SystemOfUnits.hh" >> 38 #include "G4Region.hh" >> 39 #include "G4ProductionCuts.hh" 47 40 48 //....oooOO0OOooo........oooOO0OOooo........oo << 41 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 49 42 50 DetectorConstruction::DetectorConstruction(Phy << 43 DetectorConstruction::DetectorConstruction() 51 : G4VUserDetectorConstruction(), << 44 :G4VUserDetectorConstruction(), 52 fpWaterMaterial(nullptr), << 45 fpWaterMaterial(0),fpRegion(0) 53 fLogicWorld(nullptr), << 46 {} 54 fPhysiWorld(nullptr) << 55 { << 56 fDetectorMessenger = new DetectorMessenger(t << 57 } << 58 47 59 //....oooOO0OOooo........oooOO0OOooo........oo << 48 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 60 49 61 DetectorConstruction::~DetectorConstruction() 50 DetectorConstruction::~DetectorConstruction() >> 51 {} >> 52 >> 53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 54 >> 55 G4VPhysicalVolume* DetectorConstruction::Construct() >> 56 62 { 57 { 63 delete fDetectorMessenger; << 58 DefineMaterials(); >> 59 return ConstructDetector(); 64 } 60 } 65 61 66 //....oooOO0OOooo........oooOO0OOooo........oo << 62 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 67 63 68 void DetectorConstruction::DefineMaterials() 64 void DetectorConstruction::DefineMaterials() 69 { << 65 { 70 // Water is defined from NIST material datab << 71 G4NistManager* man = G4NistManager::Instance << 72 66 73 G4Material* H2O = man->FindOrBuildMaterial(" << 67 // Water is defined from NIST material database >> 68 G4NistManager * man = G4NistManager::Instance(); >> 69 G4Material * H2O = man->FindOrBuildMaterial("G4_WATER"); 74 70 75 /* << 71 // Default materials in setup. 76 If one wishes to test other density value f << 77 one should use instead: << 78 G4Material * H2O = man->BuildMaterialWithNe << 79 "G4_WATER",1.100*g/cm3); << 80 << 81 Note: any string for "G4_WATER_MODIFIED" pa << 82 and "G4_WATER" parameter should not be chan << 83 Both materials are created and can be selec << 84 */ << 85 fpWaterMaterial = H2O; 72 fpWaterMaterial = H2O; 86 73 87 // G4cout << "-> Density of water material ( << 88 // << fpWaterMaterial->GetDensity()/(g/cm/c << 89 << 90 G4cout << *(G4Material::GetMaterialTable()) << 91 } 74 } 92 75 93 //....oooOO0OOooo........oooOO0OOooo........oo << 76 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 94 77 95 G4VPhysicalVolume* DetectorConstruction::Const << 78 G4VPhysicalVolume* DetectorConstruction::ConstructDetector() 96 { 79 { 97 if (fPhysiWorld) { << 80 // WORLD VOLUME 98 return fPhysiWorld; << 81 99 } << 82 G4double worldSizeX = 1*mm; 100 DefineMaterials(); << 83 G4double worldSizeY = 1*mm; 101 << 84 G4double worldSizeZ = 1*mm; 102 // World volume << 85 103 << 86 G4VSolid* solidWorld = new G4Box("World", //its name 104 G4double worldSizeX = 10 * micrometer; << 87 worldSizeX/2, 105 G4double worldSizeY = worldSizeX; << 88 worldSizeY/2, 106 G4double worldSizeZ = worldSizeX; << 89 worldSizeZ/2); //its size 107 << 90 108 G4Box* solidWorld = new G4Box("World", // i << 91 G4LogicalVolume* logicWorld = new G4LogicalVolume(solidWorld, //its solid 109 worldSizeX / 2 << 92 fpWaterMaterial, //its material 110 << 93 "World"); //its name 111 fLogicWorld = new G4LogicalVolume(solidWorld << 94 112 fpWaterMat << 95 G4VPhysicalVolume* physiWorld = new G4PVPlacement(0, //no rotation 113 "World"); << 96 G4ThreeVector(), //at (0,0,0) 114 << 97 "World", //its name 115 fPhysiWorld = new G4PVPlacement(0, // no ro << 98 logicWorld, //its logical volume 116 G4ThreeVecto << 99 0, //its mother volume 117 "World", // << 100 false, //no boolean operation 118 fLogicWorld, << 101 0); //copy number 119 0, // its m << 102 120 false, // n << 103 G4double TargetSizeZ = worldSizeZ*0.05; 121 0); // copy << 104 122 << 105 G4Box* targetSolid = new G4Box("Target", //its name 123 // Target volume << 106 worldSizeX/2, 124 << 107 worldSizeY/2, 125 G4Box* solidTarget = new G4Box("volumeTarget << 108 TargetSizeZ/2); //its size 126 worldSizeX / << 109 127 << 110 G4LogicalVolume* logicTarget = 128 fLogicTarget = new G4LogicalVolume(solidTarg << 111 new G4LogicalVolume(targetSolid, //its solid 129 fpWaterMa << 112 fpWaterMaterial, //its material 130 "volumeTa << 113 "Target"); //its name 131 << 114 132 fPhysiTarget = new G4PVPlacement(0, // no r << 115 new G4PVPlacement(0, //no rotation 133 G4ThreeVect << 116 G4ThreeVector(), //at (0,0,0) 134 "volumeTarg << 117 "Target", //its name 135 fLogicTarge << 118 logicTarget, //its logical volume 136 fPhysiWorld << 119 physiWorld, //its mother volume 137 false, // << 120 false, //no boolean operation 138 0); // cop << 121 0); //copy number 139 << 122 140 // Target region << 123 // Visualization attributes 141 << 124 142 G4Region* targetRegion = new G4Region("regio << 125 G4VisAttributes* worldVisAtt = 143 << 126 new G4VisAttributes(G4Colour(1.0,1.0,1.0)); //White 144 // Cuts needed to allow combination of Physi << 127 worldVisAtt->SetVisibility(true); 145 // Default EM settings for fast simulation f << 128 logicWorld->SetVisAttributes(worldVisAtt); 146 // 1 um proton cut avoids creation of very s << 147 G4ProductionCuts* cuts = new G4ProductionCut << 148 cuts->SetProductionCut(0.7 * mm, "gamma"); << 149 cuts->SetProductionCut(0.7 * mm, "e-"); << 150 cuts->SetProductionCut(0.7 * mm, "e+"); << 151 cuts->SetProductionCut(1 * micrometer, "prot << 152 targetRegion->SetProductionCuts(cuts); << 153 129 154 targetRegion->AddRootLogicalVolume(fLogicTar << 130 G4VisAttributes* worldVisAtt1 = new G4VisAttributes(G4Colour(1.0,0.0,0.0)); >> 131 worldVisAtt1->SetVisibility(true); >> 132 logicTarget->SetVisAttributes(worldVisAtt1); 155 133 156 // Visualization attributes - white << 134 // Create Target G4Region and add logical volume 157 G4VisAttributes* worldVisAtt = new G4VisAttr << 158 worldVisAtt->SetVisibility(true); << 159 fLogicWorld->SetVisAttributes(worldVisAtt); << 160 135 161 G4VisAttributes* targetVisAtt = new G4VisAtt << 136 fpRegion = new G4Region("Target"); 162 targetVisAtt->SetVisibility(true); << 163 fLogicTarget->SetVisAttributes(targetVisAtt) << 164 137 165 return fPhysiWorld; << 138 G4ProductionCuts* cuts = new G4ProductionCuts(); 166 } << 167 139 168 //....oooOO0OOooo........oooOO0OOooo........oo << 140 G4double defCut = 1*nanometer; >> 141 cuts->SetProductionCut(defCut,"gamma"); >> 142 cuts->SetProductionCut(defCut,"e-"); >> 143 cuts->SetProductionCut(defCut,"e+"); >> 144 cuts->SetProductionCut(defCut,"proton"); 169 145 170 void DetectorConstruction::SetMaterial(const G << 146 fpRegion->SetProductionCuts(cuts); 171 { << 147 fpRegion->AddRootLogicalVolume(logicTarget); 172 // Search the material by its name << 173 G4Material* pttoMaterial = G4NistManager::In << 174 148 175 if (pttoMaterial) { << 149 return physiWorld; 176 fpWaterMaterial = pttoMaterial; << 177 if (fLogicWorld) { << 178 fLogicWorld->SetMaterial(fpWaterMaterial << 179 } << 180 G4RunManager::GetRunManager()->GeometryHas << 181 } << 182 } 150 } 183 151