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 publications: 29 // Med. Phys. 45 (2018) e722-e739 << 30 // Phys. Med. 31 (2015) 861-874 29 // Phys. Med. 31 (2015) 861-874 31 // Med. Phys. 37 (2010) 4692-4708 30 // 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 31 // The Geant4-DNA web site is available at http://geant4-dna.org 34 // 32 // 35 /// \file DetectorConstruction.cc 33 /// \file DetectorConstruction.cc 36 /// \brief Implementation of the DetectorConst 34 /// \brief Implementation of the DetectorConstruction class 37 << 35 38 #include "DetectorConstruction.hh" 36 #include "DetectorConstruction.hh" 39 << 40 #include "DetectorMessenger.hh" 37 #include "DetectorMessenger.hh" 41 #include "TrackerSD.hh" 38 #include "TrackerSD.hh" 42 39 43 #include "G4Box.hh" << 40 #include "G4Material.hh" 44 #include "G4GeometryManager.hh" << 45 #include "G4GeometryTolerance.hh" << 46 #include "G4NistManager.hh" 41 #include "G4NistManager.hh" >> 42 >> 43 #include "G4Box.hh" 47 #include "G4PVPlacement.hh" 44 #include "G4PVPlacement.hh" 48 #include "G4SDManager.hh" << 45 >> 46 #include "G4GeometryTolerance.hh" >> 47 #include "G4GeometryManager.hh" >> 48 49 #include "G4SystemOfUnits.hh" 49 #include "G4SystemOfUnits.hh" 50 #include "G4UnitsTable.hh" << 51 #include "G4UserLimits.hh" 50 #include "G4UserLimits.hh" >> 51 #include "G4UnitsTable.hh" 52 52 53 //....oooOO0OOooo........oooOO0OOooo........oo << 53 #include "G4SDManager.hh" 54 54 55 DetectorConstruction::DetectorConstruction() : << 55 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 56 >> 57 DetectorConstruction::DetectorConstruction() >> 58 :G4VUserDetectorConstruction() 56 { 59 { 57 // Create commands for interactive definitio << 60 // Create commands for interactive definition of the detector 58 fDetectorMessenger = std::make_unique<Detect 61 fDetectorMessenger = std::make_unique<DetectorMessenger>(this); 59 } 62 } 60 63 61 //....oooOO0OOooo........oooOO0OOooo........oo 64 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 62 << 65 63 DetectorConstruction::~DetectorConstruction() 66 DetectorConstruction::~DetectorConstruction() = default; 64 67 65 //....oooOO0OOooo........oooOO0OOooo........oo 68 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 66 << 69 67 G4VPhysicalVolume* DetectorConstruction::Const 70 G4VPhysicalVolume* DetectorConstruction::Construct() 68 { 71 { 69 // Define materials 72 // Define materials 70 DefineMaterials(); 73 DefineMaterials(); 71 74 72 // Define volumes 75 // Define volumes 73 return DefineVolumes(); 76 return DefineVolumes(); 74 } 77 } 75 78 76 //....oooOO0OOooo........oooOO0OOooo........oo 79 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 77 80 78 void DetectorConstruction::DefineMaterials() 81 void DetectorConstruction::DefineMaterials() 79 { 82 { 80 // Water is defined from NIST material datab 83 // Water is defined from NIST material database 81 G4NistManager* man = G4NistManager::Instance << 84 G4NistManager * man = G4NistManager::Instance(); 82 G4Material* H2O = man->FindOrBuildMaterial(" << 85 >> 86 G4Material * H2O = man->FindOrBuildMaterial("G4_WATER"); >> 87 83 fpWaterMaterial = H2O; 88 fpWaterMaterial = H2O; 84 89 85 // Print materials 90 // Print materials 86 G4cout << *(G4Material::GetMaterialTable()) 91 G4cout << *(G4Material::GetMaterialTable()) << G4endl; 87 } 92 } 88 93 89 //....oooOO0OOooo........oooOO0OOooo........oo 94 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 90 95 91 G4VPhysicalVolume* DetectorConstruction::Defin 96 G4VPhysicalVolume* DetectorConstruction::DefineVolumes() 92 { 97 { 93 G4double worldLength = 10 * m; << 98 G4double worldLength = 10*m; 94 99 95 // World 100 // World 96 101 97 G4GeometryManager::GetInstance()->SetWorldMa 102 G4GeometryManager::GetInstance()->SetWorldMaximumExtent(worldLength); 98 103 99 G4cout << "Computed tolerance = " 104 G4cout << "Computed tolerance = " 100 << G4GeometryTolerance::GetInstance() << 105 << G4GeometryTolerance::GetInstance()->GetSurfaceTolerance()/nm 101 << 106 << " nm" << G4endl; 102 auto* worldS = new G4Box("world", // its na << 103 worldLength / 2, wo << 104 107 105 auto* worldLV = new G4LogicalVolume(worldS, << 108 auto* worldS 106 fpWaterM << 109 = new G4Box("world", //its name 107 "World_L << 110 worldLength/2,worldLength/2,worldLength/2); //its size 108 << 111 109 G4VPhysicalVolume* worldPV = new G4PVPlaceme << 112 auto* worldLV 110 << 113 = new G4LogicalVolume( 111 << 114 worldS, //its solid 112 << 115 fpWaterMaterial, //its material 113 << 116 "World_LV"); //its name 114 << 117 115 << 118 G4VPhysicalVolume* worldPV 116 << 119 = new G4PVPlacement( 117 << 120 nullptr, // no rotation 118 worldLV->SetUserLimits(new G4UserLimits(fpMa << 121 G4ThreeVector(), // at (0,0,0) >> 122 worldLV, // its logical volume >> 123 "World", // its name >> 124 nullptr, // its mother volume >> 125 false, // no boolean operations >> 126 0, // copy number >> 127 false); // checking overlaps >> 128 >> 129 worldLV->SetUserLimits(new G4UserLimits(fpMaxStepSize,DBL_MAX,DBL_MAX, >> 130 fpTrackingCut)); 119 131 120 PrintParameters(); 132 PrintParameters(); 121 << 133 122 return worldPV; 134 return worldPV; 123 } 135 } 124 136 125 //....oooOO0OOooo........oooOO0OOooo........oo 137 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 126 << 138 127 void DetectorConstruction::ConstructSDandField 139 void DetectorConstruction::ConstructSDandField() 128 { 140 { 129 // Sensitive detector << 141 // Sensitive detectors 130 142 131 G4String trackerChamberSDname = "TrackerCham 143 G4String trackerChamberSDname = "TrackerChamberSD"; 132 << 144 133 auto* aTrackerSD = new TrackerSD(trackerCham << 145 auto* aTrackerSD = new TrackerSD(trackerChamberSDname, >> 146 "TrackerHitsCollection"); 134 aTrackerSD->SetRadius(fRadius); 147 aTrackerSD->SetRadius(fRadius); 135 148 136 G4SDManager::GetSDMpointer()->AddNewDetector 149 G4SDManager::GetSDMpointer()->AddNewDetector(aTrackerSD); 137 150 >> 151 // Setting aTrackerSD to all logical volumes with the same name >> 152 // of "Chamber_LV". 138 SetSensitiveDetector("World_LV", aTrackerSD, 153 SetSensitiveDetector("World_LV", aTrackerSD, true); 139 } << 154 >> 155 } 140 156 141 //....oooOO0OOooo........oooOO0OOooo........oo 157 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 142 158 143 void DetectorConstruction::SetTrackingCut(cons 159 void DetectorConstruction::SetTrackingCut(const G4double& value) 144 { 160 { 145 fpTrackingCut = value; 161 fpTrackingCut = value; 146 } 162 } 147 163 148 //....oooOO0OOooo........oooOO0OOooo........oo 164 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 149 165 150 void DetectorConstruction::SetMaxStepSize(cons 166 void DetectorConstruction::SetMaxStepSize(const G4double& value) 151 { 167 { 152 fpMaxStepSize = value; 168 fpMaxStepSize = value; 153 } 169 } 154 170 155 void DetectorConstruction::SetTrackerSDRadius( 171 void DetectorConstruction::SetTrackerSDRadius(const G4double& value) 156 { 172 { 157 fRadius = value; 173 fRadius = value; 158 } 174 } 159 175 160 //....oooOO0OOooo........oooOO0OOooo........oo 176 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 161 177 162 void DetectorConstruction::PrintParameters() c 178 void DetectorConstruction::PrintParameters() const 163 { 179 { 164 G4cout << "\n------------------------------- 180 G4cout << "\n---------------------------------------------------------\n"; 165 G4cout << "---> The tracking cut is set to " << 181 G4cout << "---> The tracking cut is set to " 166 G4cout << "---> The maximum step size is set << 182 << G4BestUnit(fpTrackingCut,"Energy") << G4endl; 167 << G4endl; << 183 G4cout << "---> The maximum step size is set to " 168 G4cout << "---> The TrackerSD radius is set << 184 << G4BestUnit(fpMaxStepSize,"Length") << G4endl; >> 185 G4cout << "---> The TrackerSD radius is set to " >> 186 << G4BestUnit(fRadius,"Length") << G4endl; 169 G4cout << "\n------------------------------- 187 G4cout << "\n---------------------------------------------------------\n"; 170 } 188 } 171 189 172 //....oooOO0OOooo........oooOO0OOooo........oo 190 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 191 173 192