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 // chem6 example is derived from chem4 and che 27 // chem6 example is derived from chem4 and chem5 examples 28 // 28 // 29 // Any report or published results obtained us 29 // Any report or published results obtained using the Geant4-DNA software 30 // shall cite the following Geant4-DNA collabo 30 // shall cite the following Geant4-DNA collaboration publication: 31 // J. Appl. Phys. 125 (2019) 104301 31 // J. Appl. Phys. 125 (2019) 104301 32 // Med. Phys. 45 (2018) e722-e739 32 // Med. Phys. 45 (2018) e722-e739 33 // J. Comput. Phys. 274 (2014) 841-882 33 // J. Comput. Phys. 274 (2014) 841-882 34 // Med. Phys. 37 (2010) 4692-4708 34 // Med. Phys. 37 (2010) 4692-4708 35 // Int. J. Model. Simul. Sci. Comput. 1 (2010) 35 // Int. J. Model. Simul. Sci. Comput. 1 (2010) 157-178 36 // The Geant4-DNA web site is available at htt 36 // The Geant4-DNA web site is available at http://geant4-dna.org 37 // 37 // 38 // Authors: W. G. Shin and S. Incerti (CENBG, 38 // Authors: W. G. Shin and S. Incerti (CENBG, France) 39 // 39 // 40 // $Id$ 40 // $Id$ 41 // 41 // 42 /// \file PrimaryKiller.cc 42 /// \file PrimaryKiller.cc 43 /// \brief Implementation of the PrimaryKiller 43 /// \brief Implementation of the PrimaryKiller class 44 44 45 #include "PrimaryKiller.hh" 45 #include "PrimaryKiller.hh" 46 46 >> 47 #include <G4UnitsTable.hh> 47 #include <G4Event.hh> 48 #include <G4Event.hh> 48 #include <G4RunManager.hh> << 49 #include <G4SystemOfUnits.hh> 49 #include <G4SystemOfUnits.hh> 50 #include <G4UIcmdWith3VectorAndUnit.hh> << 51 #include <G4UIcmdWithADoubleAndUnit.hh> 50 #include <G4UIcmdWithADoubleAndUnit.hh> 52 #include <G4UnitsTable.hh> << 51 #include <G4UIcmdWith3VectorAndUnit.hh> >> 52 #include <G4RunManager.hh> 53 53 54 /** \file PrimaryKiller.cc 54 /** \file PrimaryKiller.cc 55 \class PrimaryKiller 55 \class PrimaryKiller 56 56 57 Kill the primary particle: 57 Kill the primary particle: 58 - either after a given energy loss 58 - either after a given energy loss 59 - or after the primary particle has reache 59 - or after the primary particle has reached a given energy 60 */ 60 */ 61 61 62 //....oooOO0OOooo........oooOO0OOooo........oo 62 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo..... 63 63 64 PrimaryKiller::PrimaryKiller(G4String name, G4 64 PrimaryKiller::PrimaryKiller(G4String name, G4int depth) 65 : G4VPrimitiveScorer(name, depth), G4UImesse << 65 : G4VPrimitiveScorer(name,depth), >> 66 G4UImessenger() 66 { 67 { 67 fELoss = 0.; // cumulated energy for curren << 68 fELoss = 0.; // cumulated energy for current event 68 69 69 fELossRange_Min = DBL_MAX; // fELoss from w << 70 fELossRange_Min = DBL_MAX; // fELoss from which the primary is killed 70 fELossRange_Max = DBL_MAX; // fELoss from w << 71 fELossRange_Max = DBL_MAX; // fELoss from which the event is aborted 71 fKineticE_Min = 0; // kinetic energy below << 72 fKineticE_Min = 0; // kinetic energy below which the primary is killed 72 fPhantomSize = G4ThreeVector(1 * km, 1 * km, << 73 fPhantomSize = G4ThreeVector(1*km,1*km,1*km); 73 << 74 74 fpELossUI = new G4UIcmdWithADoubleAndUnit("/ << 75 fpELossUI = new G4UIcmdWithADoubleAndUnit("/primaryKiller/eLossMin",this); 75 fpAbortEventIfELossUpperThan = new G4UIcmdWi << 76 fpAbortEventIfELossUpperThan = 76 fpMinKineticE = new G4UIcmdWithADoubleAndUni << 77 new G4UIcmdWithADoubleAndUnit("/primaryKiller/eLossMax", this); 77 fpSizeUI = new G4UIcmdWith3VectorAndUnit("/p << 78 fpMinKineticE = >> 79 new G4UIcmdWithADoubleAndUnit("/primaryKiller/minKineticE", this); >> 80 fpSizeUI = new G4UIcmdWith3VectorAndUnit("/primaryKiller/setSize",this); 78 fpSizeUI->SetDefaultUnit("um"); 81 fpSizeUI->SetDefaultUnit("um"); 79 } 82 } 80 83 81 //....oooOO0OOooo........oooOO0OOooo........oo 84 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo..... 82 85 83 PrimaryKiller::~PrimaryKiller() 86 PrimaryKiller::~PrimaryKiller() 84 { 87 { 85 delete fpELossUI; 88 delete fpELossUI; 86 delete fpAbortEventIfELossUpperThan; 89 delete fpAbortEventIfELossUpperThan; 87 delete fpSizeUI; 90 delete fpSizeUI; 88 } 91 } 89 92 90 //....oooOO0OOooo........oooOO0OOooo........oo 93 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo..... 91 94 92 void PrimaryKiller::SetNewValue(G4UIcommand* c << 95 void PrimaryKiller::SetNewValue(G4UIcommand * command, >> 96 G4String newValue) 93 { 97 { 94 if (command == fpELossUI) { << 98 if(command == fpELossUI){ 95 fELossRange_Min = fpELossUI->GetNewDoubleV 99 fELossRange_Min = fpELossUI->GetNewDoubleValue(newValue); 96 } 100 } 97 else if (command == fpAbortEventIfELossUpper << 101 else if(command == fpAbortEventIfELossUpperThan){ 98 fELossRange_Max = fpAbortEventIfELossUpper << 102 fELossRange_Max = >> 103 fpAbortEventIfELossUpperThan->GetNewDoubleValue(newValue); 99 } 104 } 100 else if (command == fpSizeUI) { << 105 else if(command == fpSizeUI){ 101 fPhantomSize = fpSizeUI->GetNew3VectorValu 106 fPhantomSize = fpSizeUI->GetNew3VectorValue(newValue); 102 } 107 } 103 } 108 } 104 109 105 //....oooOO0OOooo........oooOO0OOooo........oo 110 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo..... 106 111 107 G4bool PrimaryKiller::ProcessHits(G4Step* aSte << 112 G4bool PrimaryKiller::ProcessHits(G4Step* aStep,G4TouchableHistory*) 108 { 113 { >> 114 109 const G4Track* track = aStep->GetTrack(); 115 const G4Track* track = aStep->GetTrack(); 110 G4ThreeVector pos = aStep->GetPostStepPoint( 116 G4ThreeVector pos = aStep->GetPostStepPoint()->GetPosition(); 111 117 112 if (std::abs(pos.x()) > fPhantomSize.getX() << 118 if(std::abs(pos.x())>fPhantomSize.getX()/2 || 113 || std::abs(pos.z()) > fPhantomSize.getZ << 119 std::abs(pos.y())>fPhantomSize.getY()/2 || 114 { << 120 std::abs(pos.z())>fPhantomSize.getZ()/2){ 115 ((G4Track*)track)->SetTrackStatus(fStopAnd 121 ((G4Track*)track)->SetTrackStatus(fStopAndKill); 116 return false; 122 return false; 117 } 123 } 118 124 119 if (track->GetTrackID() != 1 || track->GetPa << 125 if(track->GetTrackID() != 1 || 120 return FALSE; << 126 track->GetParticleDefinition()->GetPDGEncoding() != 11) return FALSE; 121 127 122 //------------------- 128 //------------------- 123 129 124 double kineticE = aStep->GetPostStepPoint()- 130 double kineticE = aStep->GetPostStepPoint()->GetKineticEnergy(); 125 131 126 G4double eLoss = aStep->GetPreStepPoint()->G << 132 G4double eLoss = aStep->GetPreStepPoint()->GetKineticEnergy() >> 133 - kineticE; 127 134 128 if (eLoss == 0.) return FALSE; << 135 if ( eLoss == 0. ) return FALSE; 129 136 130 //------------------- 137 //------------------- 131 138 132 fELoss += eLoss; << 139 fELoss+=eLoss; 133 << 140 134 if (fELoss > fELossRange_Max) { << 141 if(fELoss > fELossRange_Max){ 135 G4RunManager::GetRunManager()->AbortEvent( 142 G4RunManager::GetRunManager()->AbortEvent(); 136 /* int eventID = << 143 /* int eventID = 137 G4EventManager::GetEventManager()->Ge << 144 G4EventManager::GetEventManager()->GetConstCurrentEvent()->GetEventID(); 138 145 139 G4cout << " * PrimaryKiller: aborts ev << 146 G4cout << " * PrimaryKiller: aborts event " << eventID <<" energy loss " 140 "is too large. \n" << 147 "is too large. \n" 141 << " * Energy loss by primary i << 148 << " * Energy loss by primary is: " 142 << G4BestUnit(fELoss, "Energy") << 149 << G4BestUnit(fELoss, "Energy") 143 << ". Event is aborted if the E << 150 << ". Event is aborted if the Eloss is > " 144 << G4BestUnit(fELossRange_Max, << 151 << G4BestUnit(fELossRange_Max, "Energy") 145 << G4endl; << 152 << G4endl; 146 */ << 153 */ 147 } 154 } 148 155 149 if (fELoss >= fELossRange_Min || kineticE <= << 156 if(fELoss >= fELossRange_Min || kineticE <= fKineticE_Min){ 150 ((G4Track*)track)->SetTrackStatus(fStopAnd 157 ((G4Track*)track)->SetTrackStatus(fStopAndKill); 151 // G4cout << "kill track at : "<<'\n'; << 158 // G4cout << "kill track at : "<<'\n'; 152 // << G4BestUnit(kineticE, "Ener << 159 // << G4BestUnit(kineticE, "Energy") 153 // << ", E loss is: " << 160 // << ", E loss is: " 154 // << G4BestUnit(fELoss, "Energy << 161 // << G4BestUnit(fELoss, "Energy") 155 // << " /fELossMax: " << 162 // << " /fELossMax: " 156 // << G4BestUnit(fELossMax, "Ene << 163 // << G4BestUnit(fELossMax, "Energy") 157 // << ", EThreshold is: " << 164 // << ", EThreshold is: " 158 // << G4BestUnit(fEThreshold, "E << 165 // << G4BestUnit(fEThreshold, "Energy") 159 // << G4endl; << 166 // << G4endl; 160 } 167 } 161 168 162 return TRUE; 169 return TRUE; 163 } 170 } 164 171 165 //....oooOO0OOooo........oooOO0OOooo........oo 172 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo..... 166 173 167 void PrimaryKiller::Initialize(G4HCofThisEvent 174 void PrimaryKiller::Initialize(G4HCofThisEvent* /*HCE*/) 168 { 175 { 169 fELoss = 0.; 176 fELoss = 0.; 170 } 177 } 171 178 172 //....oooOO0OOooo........oooOO0OOooo........oo 179 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo..... 173 180 174 void PrimaryKiller::EndOfEvent(G4HCofThisEvent << 181 void PrimaryKiller::EndOfEvent(G4HCofThisEvent*) >> 182 { >> 183 } 175 184 176 //....oooOO0OOooo........oooOO0OOooo........oo 185 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo..... 177 186 178 void PrimaryKiller::DrawAll() 187 void PrimaryKiller::DrawAll() 179 { << 188 {;} 180 ; << 181 } << 182 189 183 //....oooOO0OOooo........oooOO0OOooo........oo 190 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo..... 184 191 185 void PrimaryKiller::PrintAll() {} << 192 void PrimaryKiller::PrintAll() >> 193 {} 186 194 187 //....oooOO0OOooo........oooOO0OOooo........oo 195 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo..... 188 196