|
|
|||
File indexing completed on 2026-03-30 07:50:44
0001 // 0002 // ******************************************************************** 0003 // * License and Disclaimer * 0004 // * * 0005 // * The Geant4 software is copyright of the Copyright Holders of * 0006 // * the Geant4 Collaboration. It is provided under the terms and * 0007 // * conditions of the Geant4 Software License, included in the file * 0008 // * LICENSE and available at http://cern.ch/geant4/license . These * 0009 // * include a list of copyright holders. * 0010 // * * 0011 // * Neither the authors of this software system, nor their employing * 0012 // * institutes,nor the agencies providing financial support for this * 0013 // * work make any representation or warranty, express or implied, * 0014 // * regarding this software system or assume any liability for its * 0015 // * use. Please see the license in the file LICENSE and URL above * 0016 // * for the full disclaimer and the limitation of liability. * 0017 // * * 0018 // * This code implementation is the result of the scientific and * 0019 // * technical work of the GEANT4 collaboration. * 0020 // * By using, copying, modifying or distributing the software (or * 0021 // * any work based on the software) you agree to acknowledge its * 0022 // * use in resulting scientific publications, and indicate your * 0023 // * acceptance of all terms of the Geant4 Software license. * 0024 // ******************************************************************** 0025 // 0026 /// \file DetectorConstruction.cc 0027 /// \brief Implementation of the DetectorConstruction class 0028 0029 // This example is provided by the Geant4-DNA collaboration 0030 // Any report or published results obtained using the Geant4-DNA software 0031 // shall cite the following Geant4-DNA collaboration publications: 0032 // Med. Phys. 45 (2018) e722-e739 0033 // Phys. Med. 31 (2015) 861-874 0034 // Med. Phys. 37 (2010) 4692-4708 0035 // Int. J. Model. Simul. Sci. Comput. 1 (2010) 157–178 0036 // 0037 // The Geant4-DNA web site is available at http://geant4-dna.org 0038 // 0039 0040 #include "DetectorConstruction.hh" 0041 #include "DetectorMessenger.hh" 0042 #include "PhysicsList.hh" 0043 0044 #include "G4LogicalVolumeStore.hh" 0045 #include "G4NistManager.hh" 0046 #include "G4RunManager.hh" 0047 #include "G4SystemOfUnits.hh" 0048 #include "G4UserLimits.hh" 0049 0050 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 0051 0052 DetectorConstruction::DetectorConstruction(PhysicsList* ptr) 0053 : G4VUserDetectorConstruction(), 0054 fpWaterMaterial(nullptr), 0055 fLogicWorld(nullptr), 0056 fPhysiWorld(nullptr) 0057 { 0058 // Create commands for interactive definition of the detector 0059 fDetectorMessenger = new DetectorMessenger(this, ptr); 0060 0061 // Default values 0062 // 0063 // World size 0064 fWorldSize = 100 *um; 0065 // and material 0066 G4NistManager* man = G4NistManager::Instance(); 0067 G4Material* H2O = man->FindOrBuildMaterial("G4_WATER"); 0068 fpWaterMaterial = H2O; 0069 } 0070 0071 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 0072 0073 DetectorConstruction::~DetectorConstruction() 0074 { 0075 delete fDetectorMessenger; 0076 } 0077 0078 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 0079 0080 void DetectorConstruction::DefineMaterials() 0081 { 0082 // Water is defined from NIST material database 0083 G4NistManager* man = G4NistManager::Instance(); 0084 0085 G4Material* H2O = man->FindOrBuildMaterial("G4_WATER"); 0086 0087 /* 0088 If one wishes to test other density value for water material, 0089 one should use instead: 0090 G4Material * H2O = man->BuildMaterialWithNewDensity("G4_WATER_MODIFIED", 0091 "G4_WATER",1.100*g/cm3); 0092 0093 Note: any string for "G4_WATER_MODIFIED" parameter is accepted 0094 and "G4_WATER" parameter should not be changed 0095 Both materials are created and can be selected from dna.mac 0096 */ 0097 fpWaterMaterial = H2O; 0098 0099 // G4cout << "-> Density of water material (g/cm3)=" 0100 // << fpWaterMaterial->GetDensity()/(g/cm/cm/cm) << G4endl; 0101 0102 G4cout << *(G4Material::GetMaterialTable()) << G4endl; 0103 } 0104 0105 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 0106 0107 G4Material* 0108 DetectorConstruction::MaterialWithDensity(G4String name, G4double density) 0109 { 0110 // Water is defined from NIST material database 0111 G4NistManager* man = G4NistManager::Instance(); 0112 0113 G4Material * material = man->BuildMaterialWithNewDensity(name, 0114 "G4_WATER", density); 0115 0116 G4cout << "-> Density of water_modified material (g/cm3)=" 0117 << material->GetDensity()/(g/cm/cm/cm) << G4endl; 0118 0119 return material; 0120 } 0121 0122 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 0123 0124 G4VPhysicalVolume* DetectorConstruction::Construct() 0125 { 0126 if (fPhysiWorld) { 0127 return fPhysiWorld; 0128 } 0129 0130 // World volume 0131 G4double worldSizeX = fWorldSize; 0132 G4double worldSizeY = worldSizeX; 0133 G4double worldSizeZ = worldSizeX; 0134 0135 G4Box* solidWorld = new G4Box("World", // its name 0136 worldSizeX / 2, worldSizeY / 2, worldSizeZ / 2); 0137 // its size 0138 0139 fLogicWorld = new G4LogicalVolume(solidWorld, // its solid 0140 fpWaterMaterial, // its material 0141 "World"); // its name 0142 0143 fPhysiWorld = new G4PVPlacement(0, // no rotation 0144 G4ThreeVector(), // at (0,0,0) 0145 "World", // its name 0146 fLogicWorld, // its logical volume 0147 0, // its mother volume 0148 false, // no boolean operation 0149 0); // copy number 0150 0151 // Visualization attributes - white 0152 G4VisAttributes* worldVisAtt = new G4VisAttributes(G4Colour(1.0, 1.0, 1.0)); 0153 worldVisAtt->SetVisibility(true); 0154 fLogicWorld->SetVisAttributes(worldVisAtt); 0155 0156 G4VisAttributes* worldVisAtt1 = new G4VisAttributes(G4Colour(1.0, 0.0, 0.0)); 0157 worldVisAtt1->SetVisibility(true); 0158 0159 // Shows how to introduce a 20 eV tracking cut 0160 // logicWorld->SetUserLimits(new G4UserLimits(DBL_MAX,DBL_MAX,DBL_MAX,20*eV)); 0161 0162 return fPhysiWorld; 0163 } 0164 0165 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 0166 0167 void DetectorConstruction::SetMaterial(const G4String& materialChoice) 0168 { 0169 // Search the material by its name 0170 G4Material* pttoMaterial = 0171 G4NistManager::Instance()->FindOrBuildMaterial(materialChoice); 0172 0173 if (pttoMaterial) { 0174 fpWaterMaterial = pttoMaterial; 0175 if (fLogicWorld) { 0176 fLogicWorld->SetMaterial(fpWaterMaterial); 0177 } 0178 G4RunManager::GetRunManager()->GeometryHasBeenModified(); 0179 } 0180 } 0181 0182 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 0183 0184 void DetectorConstruction::SetSize(G4double value) 0185 { 0186 fWorldSize = value; 0187 G4RunManager::GetRunManager()->ReinitializeGeometry(); 0188 }
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|