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 // << 34 // The Geant4-DNA web site is available at htt 30 // The Geant4-DNA web site is available at http://geant4-dna.org 35 // 31 // >> 32 // $Id$ >> 33 // 36 /// \file DetectorConstruction.cc 34 /// \file DetectorConstruction.cc 37 /// \brief Implementation of the DetectorConst 35 /// \brief Implementation of the DetectorConstruction class 38 36 39 #include "DetectorConstruction.hh" 37 #include "DetectorConstruction.hh" 40 #include "DetectorMessenger.hh" 38 #include "DetectorMessenger.hh" 41 #include "PhysicsList.hh" << 42 << 43 #include "G4LogicalVolumeStore.hh" << 44 #include "G4NistManager.hh" << 45 #include "G4RunManager.hh" << 46 #include "G4SystemOfUnits.hh" 39 #include "G4SystemOfUnits.hh" 47 #include "G4UserLimits.hh" 40 #include "G4UserLimits.hh" >> 41 #include "G4NistManager.hh" >> 42 #include "G4RunManager.hh" >> 43 #include "G4LogicalVolumeStore.hh" 48 44 49 //....oooOO0OOooo........oooOO0OOooo........oo 45 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 50 46 51 DetectorConstruction::DetectorConstruction(Phy << 47 DetectorConstruction::DetectorConstruction() : 52 : G4VUserDetectorConstruction(), << 48 G4VUserDetectorConstruction(), fpWaterMaterial(0) 53 fpWaterMaterial(nullptr), << 54 fLogicWorld(nullptr), << 55 fPhysiWorld(nullptr) << 56 { 49 { 57 // Create commands for interactive definitio << 50 // create commands for interactive definition of the detector 58 fDetectorMessenger = new DetectorMessenger(t << 51 fDetectorMessenger = new DetectorMessenger(this); 59 << 60 // Default values << 61 // << 62 // World size << 63 fWorldSize = 100 *um; << 64 // and material << 65 G4NistManager* man = G4NistManager::Instance << 66 G4Material* H2O = man->FindOrBuildMaterial(" << 67 fpWaterMaterial = H2O; << 68 } 52 } 69 53 70 //....oooOO0OOooo........oooOO0OOooo........oo 54 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 71 55 72 DetectorConstruction::~DetectorConstruction() 56 DetectorConstruction::~DetectorConstruction() 73 { 57 { 74 delete fDetectorMessenger; 58 delete fDetectorMessenger; 75 } 59 } 76 60 77 //....oooOO0OOooo........oooOO0OOooo........oo 61 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 78 62 >> 63 G4VPhysicalVolume* DetectorConstruction::Construct() >> 64 >> 65 { >> 66 DefineMaterials(); >> 67 return ConstructDetector(); >> 68 } >> 69 >> 70 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... >> 71 79 void DetectorConstruction::DefineMaterials() 72 void DetectorConstruction::DefineMaterials() 80 { 73 { >> 74 81 // Water is defined from NIST material datab 75 // Water is defined from NIST material database 82 G4NistManager* man = G4NistManager::Instance << 76 G4NistManager * man = G4NistManager::Instance(); 83 77 84 G4Material* H2O = man->FindOrBuildMaterial(" << 78 G4Material * H2O = man->FindOrBuildMaterial("G4_WATER"); 85 79 86 /* 80 /* 87 If one wishes to test other density value f 81 If one wishes to test other density value for water material, 88 one should use instead: 82 one should use instead: 89 G4Material * H2O = man->BuildMaterialWithNe 83 G4Material * H2O = man->BuildMaterialWithNewDensity("G4_WATER_MODIFIED", 90 "G4_WATER",1.100*g/cm3); 84 "G4_WATER",1.100*g/cm3); 91 85 92 Note: any string for "G4_WATER_MODIFIED" pa 86 Note: any string for "G4_WATER_MODIFIED" parameter is accepted 93 and "G4_WATER" parameter should not be chan 87 and "G4_WATER" parameter should not be changed 94 Both materials are created and can be selec 88 Both materials are created and can be selected from dna.mac 95 */ 89 */ 96 fpWaterMaterial = H2O; 90 fpWaterMaterial = H2O; 97 91 98 // G4cout << "-> Density of water material ( << 92 //G4cout << "-> Density of water material (g/cm3)=" 99 // << fpWaterMaterial->GetDensity()/(g/cm/c << 93 // << fpWaterMaterial->GetDensity()/(g/cm/cm/cm) << G4endl; 100 94 101 G4cout << *(G4Material::GetMaterialTable()) 95 G4cout << *(G4Material::GetMaterialTable()) << G4endl; 102 } 96 } 103 97 104 //....oooOO0OOooo........oooOO0OOooo........oo << 98 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 105 << 99 G4VPhysicalVolume* DetectorConstruction::ConstructDetector() 106 G4Material* << 107 DetectorConstruction::MaterialWithDensity(G4St << 108 { 100 { 109 // Water is defined from NIST material datab << 110 G4NistManager* man = G4NistManager::Instance << 111 101 112 G4Material * material = man->BuildMaterialWi << 102 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 113 "G4_WATER", density); << 114 103 115 G4cout << "-> Density of water_modified mat << 104 // WORLD VOLUME 116 << material->GetDensity()/(g/cm/cm/cm) << << 117 << 118 return material; << 119 } << 120 105 121 //....oooOO0OOooo........oooOO0OOooo........oo << 106 G4double worldSizeX = 100 * micrometer; 122 << 123 G4VPhysicalVolume* DetectorConstruction::Const << 124 { << 125 if (fPhysiWorld) { << 126 return fPhysiWorld; << 127 } << 128 << 129 // World volume << 130 G4double worldSizeX = fWorldSize; << 131 G4double worldSizeY = worldSizeX; 107 G4double worldSizeY = worldSizeX; 132 G4double worldSizeZ = worldSizeX; 108 G4double worldSizeZ = worldSizeX; 133 109 134 G4Box* solidWorld = new G4Box("World", // i << 110 G4Box* solidWorld = new G4Box("World", //its name 135 worldSizeX / 2 << 111 worldSizeX / 2, worldSizeY / 2, worldSizeZ / 2); //its size 136 // its size << 137 << 138 fLogicWorld = new G4LogicalVolume(solidWorld << 139 fpWaterMat << 140 "World"); << 141 << 142 fPhysiWorld = new G4PVPlacement(0, // no ro << 143 G4ThreeVecto << 144 "World", // << 145 fLogicWorld, << 146 0, // its m << 147 false, // n << 148 0); // copy << 149 112 150 // Visualization attributes - white << 113 G4LogicalVolume* logicWorld = new G4LogicalVolume(solidWorld, //its solid 151 G4VisAttributes* worldVisAtt = new G4VisAttr << 114 fpWaterMaterial, //its material >> 115 "World"); //its name >> 116 >> 117 G4PVPlacement* physiWorld = new G4PVPlacement(0, //no rotation >> 118 G4ThreeVector(), //at (0,0,0) >> 119 "World", //its name >> 120 logicWorld, //its logical volume >> 121 0, //its mother volume >> 122 false, //no boolean operation >> 123 0); //copy number >> 124 >> 125 // Visualization attributes >> 126 G4VisAttributes* worldVisAtt = new G4VisAttributes(G4Colour(1.0, 1.0, 1.0)); //White 152 worldVisAtt->SetVisibility(true); 127 worldVisAtt->SetVisibility(true); 153 fLogicWorld->SetVisAttributes(worldVisAtt); << 128 logicWorld->SetVisAttributes(worldVisAtt); 154 129 155 G4VisAttributes* worldVisAtt1 = new G4VisAtt 130 G4VisAttributes* worldVisAtt1 = new G4VisAttributes(G4Colour(1.0, 0.0, 0.0)); 156 worldVisAtt1->SetVisibility(true); 131 worldVisAtt1->SetVisibility(true); 157 132 >> 133 // 158 // Shows how to introduce a 20 eV tracking c 134 // Shows how to introduce a 20 eV tracking cut 159 // logicWorld->SetUserLimits(new G4UserLimit << 135 // >> 136 //logicWorld->SetUserLimits(new G4UserLimits(DBL_MAX,DBL_MAX,DBL_MAX,20*eV)); 160 137 161 return fPhysiWorld; << 138 return physiWorld; 162 } 139 } 163 140 164 //....oooOO0OOooo........oooOO0OOooo........oo 141 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 165 142 166 void DetectorConstruction::SetMaterial(const G << 143 void DetectorConstruction::SetMaterial(G4String materialChoice) 167 { 144 { 168 // Search the material by its name << 145 // Search the material by its name 169 G4Material* pttoMaterial = << 146 G4Material* pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial( 170 G4NistManager::Instance()->FindOrBuildMate << 147 materialChoice); 171 148 172 if (pttoMaterial) { << 149 if (pttoMaterial) >> 150 { 173 fpWaterMaterial = pttoMaterial; 151 fpWaterMaterial = pttoMaterial; 174 if (fLogicWorld) { << 152 G4LogicalVolume* logicWorld = 175 fLogicWorld->SetMaterial(fpWaterMaterial << 153 G4LogicalVolumeStore::GetInstance()->GetVolume("World"); 176 } << 154 logicWorld->SetMaterial(fpWaterMaterial); 177 G4RunManager::GetRunManager()->GeometryHas 155 G4RunManager::GetRunManager()->GeometryHasBeenModified(); 178 } 156 } 179 } 157 } 180 158 181 //....oooOO0OOooo........oooOO0OOooo........oo 159 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 182 160 183 void DetectorConstruction::SetSize(G4double va << 161 void DetectorConstruction::UpdateGeometry() 184 { 162 { 185 fWorldSize = value; << 163 G4RunManager::GetRunManager()->GeometryHasBeenModified(); 186 G4RunManager::GetRunManager()->ReinitializeG << 164 G4RunManager::GetRunManager()->DefineWorldVolume(ConstructDetector()); 187 } 165 } 188 166