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 // G4ParticleChangeForLoss class implementatio 26 // G4ParticleChangeForLoss class implementation 27 // 27 // 28 // Author: Hisaya Kurashige, 23 March 1998 28 // Author: Hisaya Kurashige, 23 March 1998 29 // Revision: Vladimir Ivantchenko, 16 January 29 // Revision: Vladimir Ivantchenko, 16 January 2004 30 // ------------------------------------------- 30 // -------------------------------------------------------------------- 31 31 32 #include "G4ParticleChangeForLoss.hh" 32 #include "G4ParticleChangeForLoss.hh" 33 #include "G4SystemOfUnits.hh" 33 #include "G4SystemOfUnits.hh" >> 34 #include "G4Track.hh" >> 35 #include "G4Step.hh" >> 36 #include "G4DynamicParticle.hh" 34 #include "G4ExceptionSeverity.hh" 37 #include "G4ExceptionSeverity.hh" 35 38 36 // ------------------------------------------- 39 // -------------------------------------------------------------------- 37 G4ParticleChangeForLoss::G4ParticleChangeForLo 40 G4ParticleChangeForLoss::G4ParticleChangeForLoss() >> 41 : G4VParticleChange() >> 42 , lowEnergyLimit(1.0 * eV) 38 { 43 { 39 // Disable flag that is enabled in G4VPartic << 44 theSteppingControlFlag = NormalCondition; 40 debugFlag = false; << 45 debugFlag = false; 41 SetNumberOfSecondaries(1); << 46 } >> 47 >> 48 // -------------------------------------------------------------------- >> 49 G4ParticleChangeForLoss::~G4ParticleChangeForLoss() >> 50 { >> 51 } >> 52 >> 53 // -------------------------------------------------------------------- >> 54 G4ParticleChangeForLoss::G4ParticleChangeForLoss( >> 55 const G4ParticleChangeForLoss& right) >> 56 : G4VParticleChange(right) >> 57 { >> 58 currentTrack = right.currentTrack; >> 59 proposedKinEnergy = right.proposedKinEnergy; >> 60 lowEnergyLimit = right.lowEnergyLimit; >> 61 currentCharge = right.currentCharge; >> 62 proposedMomentumDirection = right.proposedMomentumDirection; >> 63 } >> 64 >> 65 // -------------------------------------------------------------------- >> 66 G4ParticleChangeForLoss& G4ParticleChangeForLoss::operator=( >> 67 const G4ParticleChangeForLoss& right) >> 68 { >> 69 if(this != &right) >> 70 { >> 71 if(theNumberOfSecondaries > 0) >> 72 { >> 73 for(G4int index = 0; index < theNumberOfSecondaries; ++index) >> 74 { >> 75 if((*theListOfSecondaries)[index]) >> 76 delete(*theListOfSecondaries)[index]; >> 77 } >> 78 } >> 79 delete theListOfSecondaries; >> 80 theListOfSecondaries = new G4TrackFastVector(); >> 81 theNumberOfSecondaries = right.theNumberOfSecondaries; >> 82 for(G4int index = 0; index < theNumberOfSecondaries; ++index) >> 83 { >> 84 G4Track* newTrack = new G4Track(*((*right.theListOfSecondaries)[index])); >> 85 theListOfSecondaries->SetElement(index, newTrack); >> 86 } >> 87 >> 88 theStatusChange = right.theStatusChange; >> 89 theLocalEnergyDeposit = right.theLocalEnergyDeposit; >> 90 theSteppingControlFlag = right.theSteppingControlFlag; >> 91 theParentWeight = right.theParentWeight; >> 92 isParentWeightProposed = right.isParentWeightProposed; >> 93 fSetSecondaryWeightByProcess = right.fSetSecondaryWeightByProcess; >> 94 >> 95 currentTrack = right.currentTrack; >> 96 proposedKinEnergy = right.proposedKinEnergy; >> 97 currentCharge = right.currentCharge; >> 98 proposedMomentumDirection = right.proposedMomentumDirection; >> 99 } >> 100 return *this; 42 } 101 } 43 102 44 // ------------------------------------------- 103 // -------------------------------------------------------------------- 45 void G4ParticleChangeForLoss::DumpInfo() const 104 void G4ParticleChangeForLoss::DumpInfo() const 46 { 105 { 47 // use base-class DumpInfo 106 // use base-class DumpInfo 48 G4VParticleChange::DumpInfo(); 107 G4VParticleChange::DumpInfo(); 49 108 50 G4long oldprc = G4cout.precision(8); << 109 G4int oldprc = G4cout.precision(3); 51 G4cout << " --------------------------- << 52 G4cout << " G4ParticleChangeForLoss p << 53 G4cout << " Charge (eplus) : " << s 110 G4cout << " Charge (eplus) : " << std::setw(20) 54 << currentCharge / eplus << G4endl; 111 << currentCharge / eplus << G4endl; 55 G4cout << " Kinetic Energy (MeV): " < 112 G4cout << " Kinetic Energy (MeV): " << std::setw(20) 56 << proposedKinEnergy / MeV << G4endl; 113 << proposedKinEnergy / MeV << G4endl; 57 G4cout << " Momentum Direct - x : " < 114 G4cout << " Momentum Direct - x : " << std::setw(20) 58 << proposedMomentumDirection.x() << G 115 << proposedMomentumDirection.x() << G4endl; 59 G4cout << " Momentum Direct - y : " < 116 G4cout << " Momentum Direct - y : " << std::setw(20) 60 << proposedMomentumDirection.y() << G 117 << proposedMomentumDirection.y() << G4endl; 61 G4cout << " Momentum Direct - z : " < 118 G4cout << " Momentum Direct - z : " << std::setw(20) 62 << proposedMomentumDirection.z() << G 119 << proposedMomentumDirection.z() << G4endl; 63 G4cout.precision(oldprc); 120 G4cout.precision(oldprc); 64 } 121 } 65 122 66 // ------------------------------------------- 123 // -------------------------------------------------------------------- >> 124 G4bool G4ParticleChangeForLoss::CheckIt(const G4Track& aTrack) >> 125 { >> 126 G4bool itsOK = true; >> 127 G4bool exitWithError = false; >> 128 >> 129 G4double accuracy; >> 130 >> 131 // Energy should not be lager than initial value >> 132 accuracy = (proposedKinEnergy - aTrack.GetKineticEnergy()) / MeV; >> 133 if(accuracy > accuracyForWarning) >> 134 { >> 135 itsOK = false; >> 136 exitWithError = (accuracy > accuracyForException); >> 137 #ifdef G4VERBOSE >> 138 G4cout << "G4ParticleChangeForLoss::CheckIt: "; >> 139 G4cout << "KinEnergy become larger than the initial value!" >> 140 << " Difference: " << accuracy << "[MeV] " << G4endl; >> 141 G4cout << aTrack.GetDefinition()->GetParticleName() >> 142 << " E=" << aTrack.GetKineticEnergy() / MeV >> 143 << " pos=" << aTrack.GetPosition().x() / m << ", " >> 144 << aTrack.GetPosition().y() / m << ", " >> 145 << aTrack.GetPosition().z() / m << G4endl; >> 146 #endif >> 147 } >> 148 >> 149 // dump out information of this particle change >> 150 #ifdef G4VERBOSE >> 151 if(!itsOK) { DumpInfo(); } >> 152 #endif >> 153 >> 154 // exit with error >> 155 if(exitWithError) >> 156 { >> 157 G4Exception("G4ParticleChangeForLoss::CheckIt()", "TRACK004", >> 158 EventMustBeAborted, "energy was illegal"); >> 159 } >> 160 >> 161 // correction >> 162 if(!itsOK) >> 163 { >> 164 proposedKinEnergy = aTrack.GetKineticEnergy(); >> 165 } >> 166 >> 167 itsOK = (itsOK) && G4VParticleChange::CheckIt(aTrack); >> 168 return itsOK; >> 169 } >> 170 >> 171 // -------------------------------------------------------------------- 67 G4Step* G4ParticleChangeForLoss::UpdateStepFor 172 G4Step* G4ParticleChangeForLoss::UpdateStepForAlongStep(G4Step* pStep) 68 { 173 { 69 const G4StepPoint* pPreStepPoint = pStep->Ge << 70 G4StepPoint* pPostStepPoint = pStep->GetPost 174 G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint(); >> 175 G4StepPoint* pPreStepPoint = pStep->GetPreStepPoint(); >> 176 G4Track* pTrack = pStep->GetTrack(); 71 177 72 // accumulate change of the kinetic energy 178 // accumulate change of the kinetic energy 73 G4double preKinEnergy = pPreStepPoint->GetKi 179 G4double preKinEnergy = pPreStepPoint->GetKineticEnergy(); 74 G4double kinEnergy = 180 G4double kinEnergy = 75 pPostStepPoint->GetKineticEnergy() + (prop 181 pPostStepPoint->GetKineticEnergy() + (proposedKinEnergy - preKinEnergy); 76 182 77 pPostStepPoint->SetCharge(currentCharge); << 183 // update kinetic energy and charge 78 << 184 if(kinEnergy < lowEnergyLimit) 79 // calculate velocity << 80 if(kinEnergy > 0.0) << 81 { << 82 pPostStepPoint->SetKineticEnergy(kinEnergy << 83 << 84 // assuming that mass>0, zero mass particl << 85 pPostStepPoint->SetVelocity(CLHEP::c_light << 86 } << 87 else << 88 { 185 { 89 pPostStepPoint->SetKineticEnergy(0.0); << 186 theLocalEnergyDeposit += kinEnergy; >> 187 kinEnergy = 0.0; 90 pPostStepPoint->SetVelocity(0.0); 188 pPostStepPoint->SetVelocity(0.0); 91 } 189 } >> 190 else >> 191 { >> 192 pPostStepPoint->SetCharge(currentCharge); >> 193 // calculate velocity >> 194 pTrack->SetKineticEnergy(kinEnergy); >> 195 pPostStepPoint->SetVelocity(pTrack->CalculateVelocity()); >> 196 pTrack->SetKineticEnergy(preKinEnergy); >> 197 } >> 198 pPostStepPoint->SetKineticEnergy(kinEnergy); 92 199 93 if(isParentWeightProposed) 200 if(isParentWeightProposed) 94 { 201 { 95 pPostStepPoint->SetWeight(theParentWeight) 202 pPostStepPoint->SetWeight(theParentWeight); 96 } 203 } 97 204 98 pStep->AddTotalEnergyDeposit(theLocalEnergyD 205 pStep->AddTotalEnergyDeposit(theLocalEnergyDeposit); 99 pStep->AddNonIonizingEnergyDeposit(theNonIon 206 pStep->AddNonIonizingEnergyDeposit(theNonIonizingEnergyDeposit); 100 return pStep; 207 return pStep; 101 } 208 } 102 209 103 // ------------------------------------------- 210 // -------------------------------------------------------------------- 104 G4Step* G4ParticleChangeForLoss::UpdateStepFor 211 G4Step* G4ParticleChangeForLoss::UpdateStepForPostStep(G4Step* pStep) 105 { 212 { 106 G4StepPoint* pPostStepPoint = pStep->GetPost 213 G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint(); >> 214 G4Track* pTrack = pStep->GetTrack(); 107 215 108 pPostStepPoint->SetCharge(currentCharge); 216 pPostStepPoint->SetCharge(currentCharge); 109 pPostStepPoint->SetMomentumDirection(propose 217 pPostStepPoint->SetMomentumDirection(proposedMomentumDirection); >> 218 pPostStepPoint->SetKineticEnergy(proposedKinEnergy); >> 219 pTrack->SetKineticEnergy(proposedKinEnergy); 110 if(proposedKinEnergy > 0.0) 220 if(proposedKinEnergy > 0.0) 111 { 221 { 112 pPostStepPoint->SetKineticEnergy(proposedK << 222 pPostStepPoint->SetVelocity(pTrack->CalculateVelocity()); 113 << 114 // assuming that mass>0, zero mass particl << 115 pPostStepPoint->SetVelocity(CLHEP::c_light << 116 } 223 } 117 else 224 else 118 { 225 { 119 pPostStepPoint->SetKineticEnergy(0.0); << 120 pPostStepPoint->SetVelocity(0.0); 226 pPostStepPoint->SetVelocity(0.0); 121 } 227 } 122 pPostStepPoint->SetPolarization(proposedPola 228 pPostStepPoint->SetPolarization(proposedPolarization); 123 229 124 if(isParentWeightProposed) 230 if(isParentWeightProposed) 125 { 231 { 126 pPostStepPoint->SetWeight(theParentWeight) 232 pPostStepPoint->SetWeight(theParentWeight); 127 } 233 } 128 234 129 pStep->AddTotalEnergyDeposit(theLocalEnergyD 235 pStep->AddTotalEnergyDeposit(theLocalEnergyDeposit); 130 pStep->AddNonIonizingEnergyDeposit(theNonIon 236 pStep->AddNonIonizingEnergyDeposit(theNonIonizingEnergyDeposit); 131 return pStep; 237 return pStep; 132 } 238 } 133 239