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 << 27 // 26 // 28 // Author: Hisaya Kurashige, 23 March 1998 << 27 // $Id: G4ParticleChangeForLoss.cc,v 1.16 2006/08/28 16:10:29 vnivanch Exp $ 29 // Revision: Vladimir Ivantchenko, 16 January << 28 // GEANT4 tag $Name: geant4-08-02 $ 30 // ------------------------------------------- << 29 // 31 << 30 // >> 31 // -------------------------------------------------------------- >> 32 // GEANT 4 class implementation file >> 33 // >> 34 // ------------------------------------------------------------ >> 35 // Implemented for the new scheme 23 Mar. 1998 H.Kurahige >> 36 // -------------------------------------------------------------- >> 37 // >> 38 // Modified: >> 39 // 16.01.04 V.Ivanchenko update for model variant of energy loss >> 40 // 15.04.05 V.Ivanchenko inline update methods >> 41 // 28.08.06 V.Ivanchenko Add access to current track and polarizaion >> 42 // >> 43 // ------------------------------------------------------------ >> 44 // 32 #include "G4ParticleChangeForLoss.hh" 45 #include "G4ParticleChangeForLoss.hh" 33 #include "G4SystemOfUnits.hh" << 46 #include "G4Track.hh" >> 47 #include "G4Step.hh" >> 48 #include "G4DynamicParticle.hh" 34 #include "G4ExceptionSeverity.hh" 49 #include "G4ExceptionSeverity.hh" 35 50 36 // ------------------------------------------- << 51 G4ParticleChangeForLoss::G4ParticleChangeForLoss():G4VParticleChange() 37 G4ParticleChangeForLoss::G4ParticleChangeForLo << 38 { 52 { 39 // Disable flag that is enabled in G4VPartic << 53 theSteppingControlFlag = NormalCondition; 40 debugFlag = false; 54 debugFlag = false; 41 SetNumberOfSecondaries(1); << 55 #ifdef G4VERBOSE >> 56 if (verboseLevel>2) { >> 57 G4cout << "G4ParticleChangeForLoss::G4ParticleChangeForLoss() " << G4endl; >> 58 } >> 59 #endif 42 } 60 } 43 61 44 // ------------------------------------------- << 62 G4ParticleChangeForLoss::~G4ParticleChangeForLoss() 45 void G4ParticleChangeForLoss::DumpInfo() const << 46 { 63 { 47 // use base-class DumpInfo << 64 #ifdef G4VERBOSE 48 G4VParticleChange::DumpInfo(); << 65 if (verboseLevel>2) { 49 << 66 G4cout << "G4ParticleChangeForLoss::~G4ParticleChangeForLoss() " << G4endl; 50 G4long oldprc = G4cout.precision(8); << 67 } 51 G4cout << " --------------------------- << 68 #endif 52 G4cout << " G4ParticleChangeForLoss p << 53 G4cout << " Charge (eplus) : " << s << 54 << currentCharge / eplus << G4endl; << 55 G4cout << " Kinetic Energy (MeV): " < << 56 << proposedKinEnergy / MeV << G4endl; << 57 G4cout << " Momentum Direct - x : " < << 58 << proposedMomentumDirection.x() << G << 59 G4cout << " Momentum Direct - y : " < << 60 << proposedMomentumDirection.y() << G << 61 G4cout << " Momentum Direct - z : " < << 62 << proposedMomentumDirection.z() << G << 63 G4cout.precision(oldprc); << 64 } 69 } 65 70 66 // ------------------------------------------- << 71 G4ParticleChangeForLoss::G4ParticleChangeForLoss( 67 G4Step* G4ParticleChangeForLoss::UpdateStepFor << 72 const G4ParticleChangeForLoss &right): G4VParticleChange(right) 68 { 73 { 69 const G4StepPoint* pPreStepPoint = pStep->Ge << 74 if (verboseLevel>1) { 70 G4StepPoint* pPostStepPoint = pStep->GetPost << 75 G4cout << "G4ParticleChangeForLoss:: copy constructor is called " << G4endl; 71 << 72 // accumulate change of the kinetic energy << 73 G4double preKinEnergy = pPreStepPoint->GetKi << 74 G4double kinEnergy = << 75 pPostStepPoint->GetKineticEnergy() + (prop << 76 << 77 pPostStepPoint->SetCharge(currentCharge); << 78 << 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 { << 89 pPostStepPoint->SetKineticEnergy(0.0); << 90 pPostStepPoint->SetVelocity(0.0); << 91 } 76 } >> 77 currentTrack = right.currentTrack; >> 78 proposedKinEnergy = right.proposedKinEnergy; >> 79 currentCharge = right.currentCharge; >> 80 proposedMomentumDirection = right.proposedMomentumDirection; >> 81 } 92 82 93 if(isParentWeightProposed) << 83 // assignment operator 94 { << 84 G4ParticleChangeForLoss & G4ParticleChangeForLoss::operator=( 95 pPostStepPoint->SetWeight(theParentWeight) << 85 const G4ParticleChangeForLoss &right) >> 86 { >> 87 if (verboseLevel>1) { >> 88 G4cout << "G4ParticleChangeForLoss:: assignment operator is called " << G4endl; >> 89 } >> 90 if (this != &right) { >> 91 theListOfSecondaries = right.theListOfSecondaries; >> 92 theSizeOftheListOfSecondaries = right.theSizeOftheListOfSecondaries; >> 93 theNumberOfSecondaries = right.theNumberOfSecondaries; >> 94 theStatusChange = right.theStatusChange; >> 95 theLocalEnergyDeposit = right.theLocalEnergyDeposit; >> 96 theSteppingControlFlag = right.theSteppingControlFlag; >> 97 theParentWeight = right.theParentWeight; >> 98 >> 99 currentTrack = right.currentTrack; >> 100 proposedKinEnergy = right.proposedKinEnergy; >> 101 currentCharge = right.currentCharge; >> 102 proposedMomentumDirection = right.proposedMomentumDirection; 96 } 103 } >> 104 return *this; >> 105 } >> 106 >> 107 //---------------------------------------------------------------- >> 108 // methods for printing messages >> 109 // 97 110 98 pStep->AddTotalEnergyDeposit(theLocalEnergyD << 111 void G4ParticleChangeForLoss::DumpInfo() const 99 pStep->AddNonIonizingEnergyDeposit(theNonIon << 112 { 100 return pStep; << 113 // use base-class DumpInfo >> 114 G4VParticleChange::DumpInfo(); >> 115 >> 116 G4cout.precision(3); >> 117 G4cout << " Charge (eplus) : " >> 118 << std::setw(20) << currentCharge/eplus >> 119 << G4endl; >> 120 G4cout << " Kinetic Energy (MeV): " >> 121 << std::setw(20) << proposedKinEnergy/MeV >> 122 << G4endl; >> 123 G4cout << " Momentum Direct - x : " >> 124 << std::setw(20) << proposedMomentumDirection.x() >> 125 << G4endl; >> 126 G4cout << " Momentum Direct - y : " >> 127 << std::setw(20) << proposedMomentumDirection.y() >> 128 << G4endl; >> 129 G4cout << " Momentum Direct - z : " >> 130 << std::setw(20) << proposedMomentumDirection.z() >> 131 << G4endl; 101 } 132 } 102 133 103 // ------------------------------------------- << 134 G4bool G4ParticleChangeForLoss::CheckIt(const G4Track& aTrack) 104 G4Step* G4ParticleChangeForLoss::UpdateStepFor << 105 { 135 { 106 G4StepPoint* pPostStepPoint = pStep->GetPost << 136 G4bool itsOK = true; >> 137 G4bool exitWithError = false; 107 138 108 pPostStepPoint->SetCharge(currentCharge); << 139 G4double accuracy; 109 pPostStepPoint->SetMomentumDirection(propose << 110 if(proposedKinEnergy > 0.0) << 111 { << 112 pPostStepPoint->SetKineticEnergy(proposedK << 113 140 114 // assuming that mass>0, zero mass particl << 141 // Energy should not be lager than initial value 115 pPostStepPoint->SetVelocity(CLHEP::c_light << 142 accuracy = ( proposedKinEnergy - aTrack.GetKineticEnergy())/MeV; >> 143 if (accuracy > accuracyForWarning) { >> 144 #ifdef G4VERBOSE >> 145 G4cout << "G4ParticleChangeForLoss::CheckIt: "; >> 146 G4cout << "KinEnergy become larger than the initial value!" << G4endl; >> 147 G4cout << " Difference: " << accuracy << "[MeV] " <<G4endl; >> 148 #endif >> 149 itsOK = false; >> 150 if (accuracy > accuracyForException) exitWithError = true; 116 } 151 } 117 else << 152 118 { << 153 // dump out information of this particle change 119 pPostStepPoint->SetKineticEnergy(0.0); << 154 #ifdef G4VERBOSE 120 pPostStepPoint->SetVelocity(0.0); << 155 if (!itsOK) { >> 156 G4cout << "G4ParticleChangeForLoss::CheckIt " << G4endl; >> 157 DumpInfo(); >> 158 } >> 159 #endif >> 160 >> 161 // Exit with error >> 162 if (exitWithError) { >> 163 G4Exception("G4ParticleChangeForLoss::CheckIt", >> 164 "400", >> 165 EventMustBeAborted, >> 166 "energy was illegal"); 121 } 167 } 122 pPostStepPoint->SetPolarization(proposedPola << 123 168 124 if(isParentWeightProposed) << 169 //correction 125 { << 170 if (!itsOK) { 126 pPostStepPoint->SetWeight(theParentWeight) << 171 proposedKinEnergy = aTrack.GetKineticEnergy(); 127 } 172 } 128 173 129 pStep->AddTotalEnergyDeposit(theLocalEnergyD << 174 itsOK = (itsOK) && G4VParticleChange::CheckIt(aTrack); 130 pStep->AddNonIonizingEnergyDeposit(theNonIon << 175 return itsOK; 131 return pStep; << 132 } 176 } 133 177