Geant4 Cross Reference |
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 // This example is provided by the Geant4-DNA collaboration 27 // Any report or published results obtained using the Geant4-DNA software 28 // shall cite the following Geant4-DNA collaboration publications: 29 // Med. Phys. 45 (2018) e722-e739 30 // Phys. Med. 31 (2015) 861-874 31 // Med. Phys. 37 (2010) 4692-4708 32 // Int. J. Model. Simul. Sci. Comput. 1 (2010) 157–178 33 // 34 // The Geant4-DNA web site is available at http://geant4-dna.org 35 // 36 /// \file DetectorConstruction.cc 37 /// \brief Implementation of the DetectorConstruction class 38 39 #include "DetectorConstruction.hh" 40 #include "DetectorMessenger.hh" 41 #include "PhysicsList.hh" 42 43 #include "G4LogicalVolumeStore.hh" 44 #include "G4NistManager.hh" 45 #include "G4RunManager.hh" 46 #include "G4SystemOfUnits.hh" 47 #include "G4UserLimits.hh" 48 49 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 50 51 DetectorConstruction::DetectorConstruction(PhysicsList* ptr) 52 : G4VUserDetectorConstruction(), 53 fpWaterMaterial(nullptr), 54 fLogicWorld(nullptr), 55 fPhysiWorld(nullptr) 56 { 57 // Create commands for interactive definition of the detector 58 fDetectorMessenger = new DetectorMessenger(this, ptr); 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("G4_WATER"); 67 fpWaterMaterial = H2O; 68 } 69 70 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 71 72 DetectorConstruction::~DetectorConstruction() 73 { 74 delete fDetectorMessenger; 75 } 76 77 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 78 79 void DetectorConstruction::DefineMaterials() 80 { 81 // Water is defined from NIST material database 82 G4NistManager* man = G4NistManager::Instance(); 83 84 G4Material* H2O = man->FindOrBuildMaterial("G4_WATER"); 85 86 /* 87 If one wishes to test other density value for water material, 88 one should use instead: 89 G4Material * H2O = man->BuildMaterialWithNewDensity("G4_WATER_MODIFIED", 90 "G4_WATER",1.100*g/cm3); 91 92 Note: any string for "G4_WATER_MODIFIED" parameter is accepted 93 and "G4_WATER" parameter should not be changed 94 Both materials are created and can be selected from dna.mac 95 */ 96 fpWaterMaterial = H2O; 97 98 // G4cout << "-> Density of water material (g/cm3)=" 99 // << fpWaterMaterial->GetDensity()/(g/cm/cm/cm) << G4endl; 100 101 G4cout << *(G4Material::GetMaterialTable()) << G4endl; 102 } 103 104 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 105 106 G4Material* 107 DetectorConstruction::MaterialWithDensity(G4String name, G4double density) 108 { 109 // Water is defined from NIST material database 110 G4NistManager* man = G4NistManager::Instance(); 111 112 G4Material * material = man->BuildMaterialWithNewDensity(name, 113 "G4_WATER", density); 114 115 G4cout << "-> Density of water_modified material (g/cm3)=" 116 << material->GetDensity()/(g/cm/cm/cm) << G4endl; 117 118 return material; 119 } 120 121 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 122 123 G4VPhysicalVolume* DetectorConstruction::Construct() 124 { 125 if (fPhysiWorld) { 126 return fPhysiWorld; 127 } 128 129 // World volume 130 G4double worldSizeX = fWorldSize; 131 G4double worldSizeY = worldSizeX; 132 G4double worldSizeZ = worldSizeX; 133 134 G4Box* solidWorld = new G4Box("World", // its name 135 worldSizeX / 2, worldSizeY / 2, worldSizeZ / 2); 136 // its size 137 138 fLogicWorld = new G4LogicalVolume(solidWorld, // its solid 139 fpWaterMaterial, // its material 140 "World"); // its name 141 142 fPhysiWorld = new G4PVPlacement(0, // no rotation 143 G4ThreeVector(), // at (0,0,0) 144 "World", // its name 145 fLogicWorld, // its logical volume 146 0, // its mother volume 147 false, // no boolean operation 148 0); // copy number 149 150 // Visualization attributes - white 151 G4VisAttributes* worldVisAtt = new G4VisAttributes(G4Colour(1.0, 1.0, 1.0)); 152 worldVisAtt->SetVisibility(true); 153 fLogicWorld->SetVisAttributes(worldVisAtt); 154 155 G4VisAttributes* worldVisAtt1 = new G4VisAttributes(G4Colour(1.0, 0.0, 0.0)); 156 worldVisAtt1->SetVisibility(true); 157 158 // Shows how to introduce a 20 eV tracking cut 159 // logicWorld->SetUserLimits(new G4UserLimits(DBL_MAX,DBL_MAX,DBL_MAX,20*eV)); 160 161 return fPhysiWorld; 162 } 163 164 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 165 166 void DetectorConstruction::SetMaterial(const G4String& materialChoice) 167 { 168 // Search the material by its name 169 G4Material* pttoMaterial = 170 G4NistManager::Instance()->FindOrBuildMaterial(materialChoice); 171 172 if (pttoMaterial) { 173 fpWaterMaterial = pttoMaterial; 174 if (fLogicWorld) { 175 fLogicWorld->SetMaterial(fpWaterMaterial); 176 } 177 G4RunManager::GetRunManager()->GeometryHasBeenModified(); 178 } 179 } 180 181 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 182 183 void DetectorConstruction::SetSize(G4double value) 184 { 185 fWorldSize = value; 186 G4RunManager::GetRunManager()->ReinitializeGeometry(); 187 } 188