Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 // G4ParticleChangeForLoss class implementatio << 27 // 23 // 28 // Author: Hisaya Kurashige, 23 March 1998 << 24 // $Id: G4ParticleChangeForLoss.cc,v 1.6 2001/07/11 10:08:39 gunter Exp $ 29 // Revision: Vladimir Ivantchenko, 16 January << 25 // GEANT4 tag $Name: geant4-05-00 $ 30 // ------------------------------------------- << 26 // >> 27 // >> 28 // -------------------------------------------------------------- >> 29 // GEANT 4 class implementation file >> 30 // >> 31 // >> 32 // >> 33 // ------------------------------------------------------------ >> 34 // Implemented for the new scheme 23 Mar. 1998 H.Kurahige >> 35 // -------------------------------------------------------------- 31 36 32 #include "G4ParticleChangeForLoss.hh" 37 #include "G4ParticleChangeForLoss.hh" 33 #include "G4SystemOfUnits.hh" << 38 #include "G4Track.hh" 34 #include "G4ExceptionSeverity.hh" << 39 #include "G4Step.hh" >> 40 #include "G4TrackFastVector.hh" >> 41 #include "G4DynamicParticle.hh" 35 42 36 // ------------------------------------------- << 43 G4ParticleChangeForLoss::G4ParticleChangeForLoss():G4VParticleChange() 37 G4ParticleChangeForLoss::G4ParticleChangeForLo << 38 { 44 { 39 // Disable flag that is enabled in G4VPartic << 40 debugFlag = false; 45 debugFlag = false; 41 SetNumberOfSecondaries(1); << 46 #ifdef G4VERBOSE >> 47 if (verboseLevel>2) { >> 48 G4cout << "G4ParticleChangeForLoss::G4ParticleChangeForLoss() " << G4endl; >> 49 } >> 50 #endif 42 } 51 } 43 52 44 // ------------------------------------------- << 53 G4ParticleChangeForLoss::~G4ParticleChangeForLoss() 45 void G4ParticleChangeForLoss::DumpInfo() const << 46 { 54 { 47 // use base-class DumpInfo << 55 #ifdef G4VERBOSE 48 G4VParticleChange::DumpInfo(); << 56 if (verboseLevel>2) { >> 57 G4cout << "G4ParticleChangeForLoss::~G4ParticleChangeForLoss() " << G4endl; >> 58 } >> 59 #endif >> 60 } 49 61 50 G4long oldprc = G4cout.precision(8); << 62 // copy constructor 51 G4cout << " --------------------------- << 63 G4ParticleChangeForLoss::G4ParticleChangeForLoss(const G4ParticleChangeForLoss &right): G4VParticleChange(right) 52 G4cout << " G4ParticleChangeForLoss p << 64 { 53 G4cout << " Charge (eplus) : " << s << 65 if (verboseLevel>1) { 54 << currentCharge / eplus << G4endl; << 66 G4cout << "G4ParticleChangeForLoss:: copy constructor is called " << G4endl; 55 G4cout << " Kinetic Energy (MeV): " < << 67 } 56 << proposedKinEnergy / MeV << G4endl; << 68 theEnergyChange = right.theEnergyChange; 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 // assignemnt operator 67 G4Step* G4ParticleChangeForLoss::UpdateStepFor << 72 G4ParticleChangeForLoss & G4ParticleChangeForLoss::operator=(const G4ParticleChangeForLoss &right) 68 { 73 { 69 const G4StepPoint* pPreStepPoint = pStep->Ge << 74 if (verboseLevel>1) { 70 G4StepPoint* pPostStepPoint = pStep->GetPost << 75 G4cout << "G4ParticleChangeForLoss:: assignment operator is called " << G4endl; >> 76 } >> 77 if (this != &right) >> 78 { >> 79 theListOfSecondaries = right.theListOfSecondaries; >> 80 theSizeOftheListOfSecondaries = right.theSizeOftheListOfSecondaries; >> 81 theNumberOfSecondaries = right.theNumberOfSecondaries; >> 82 theStatusChange = right.theStatusChange; >> 83 theTrueStepLength = right.theTrueStepLength; >> 84 theLocalEnergyDeposit = right.theLocalEnergyDeposit; >> 85 theSteppingControlFlag = right.theSteppingControlFlag; >> 86 >> 87 theEnergyChange = right.theEnergyChange; >> 88 theLocalEnergyDeposit = right.theLocalEnergyDeposit ; >> 89 } >> 90 return *this; >> 91 } >> 92 71 93 72 // accumulate change of the kinetic energy << 94 //---------------------------------------------------------------- 73 G4double preKinEnergy = pPreStepPoint->GetKi << 95 // functions for Initialization 74 G4double kinEnergy = << 96 // 75 pPostStepPoint->GetKineticEnergy() + (prop << 97 76 << 98 void G4ParticleChangeForLoss::Initialize(const G4Track& track) 77 pPostStepPoint->SetCharge(currentCharge); << 99 { 78 << 100 // use base class's method at first 79 // calculate velocity << 101 G4VParticleChange::Initialize(track); 80 if(kinEnergy > 0.0) << 102 81 { << 103 // set Energy equal to those of the parent particle 82 pPostStepPoint->SetKineticEnergy(kinEnergy << 104 const G4DynamicParticle* pParticle = track.GetDynamicParticle(); 83 << 105 theEnergyChange = pParticle->GetKineticEnergy(); 84 // assuming that mass>0, zero mass particl << 106 } 85 pPostStepPoint->SetVelocity(CLHEP::c_light << 107 86 } << 108 //---------------------------------------------------------------- 87 else << 109 // methods for updating G4Step 88 { << 110 // >> 111 >> 112 G4Step* G4ParticleChangeForLoss::UpdateStepForAlongStep(G4Step* pStep) >> 113 { >> 114 // A physics process always calculates the final state of the >> 115 // particle relative to the initial state at the beginning >> 116 // of the Step, i.e., based on information of G4Track (or >> 117 // equivalently the PreStepPoint). >> 118 // So, the differences (delta) between these two states have to be >> 119 // calculated and be accumulated in PostStepPoint. >> 120 >> 121 >> 122 G4StepPoint* pPreStepPoint = pStep->GetPreStepPoint(); >> 123 G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint(); >> 124 G4Track* aTrack = pStep->GetTrack(); >> 125 >> 126 // calculate new kinetic energy >> 127 G4double energy = pPostStepPoint->GetKineticEnergy() >> 128 + (theEnergyChange - pPreStepPoint->GetKineticEnergy()); >> 129 >> 130 // update kinetic energy and momentum direction >> 131 if (energy > 0.0) { >> 132 pPostStepPoint->SetKineticEnergy( energy ); >> 133 } else { >> 134 // stop case 89 pPostStepPoint->SetKineticEnergy(0.0); 135 pPostStepPoint->SetKineticEnergy(0.0); 90 pPostStepPoint->SetVelocity(0.0); << 91 } 136 } 92 137 93 if(isParentWeightProposed) << 138 #ifdef G4VERBOSE 94 { << 139 if (debugFlag) CheckIt(*aTrack); 95 pPostStepPoint->SetWeight(theParentWeight) << 140 #endif 96 } << 97 141 98 pStep->AddTotalEnergyDeposit(theLocalEnergyD << 142 // Update the G4Step specific attributes 99 pStep->AddNonIonizingEnergyDeposit(theNonIon << 143 return UpdateStepInfo(pStep); 100 return pStep; << 101 } 144 } 102 145 103 // ------------------------------------------- << 146 //---------------------------------------------------------------- 104 G4Step* G4ParticleChangeForLoss::UpdateStepFor << 147 // methods for printing messages >> 148 // >> 149 >> 150 void G4ParticleChangeForLoss::DumpInfo() const 105 { 151 { 106 G4StepPoint* pPostStepPoint = pStep->GetPost << 152 // use base-class DumpInfo >> 153 G4VParticleChange::DumpInfo(); 107 154 108 pPostStepPoint->SetCharge(currentCharge); << 155 G4cout.precision(3); 109 pPostStepPoint->SetMomentumDirection(propose << 156 G4cout << " Kinetic Energy (MeV): " 110 if(proposedKinEnergy > 0.0) << 157 << G4std::setw(20) << theEnergyChange/MeV 111 { << 158 << G4endl; 112 pPostStepPoint->SetKineticEnergy(proposedK << 159 } >> 160 >> 161 G4bool G4ParticleChangeForLoss::CheckIt(const G4Track& aTrack) >> 162 { >> 163 G4bool itsOK = true; >> 164 G4bool exitWithError = false; 113 165 114 // assuming that mass>0, zero mass particl << 166 G4double accuracy; 115 pPostStepPoint->SetVelocity(CLHEP::c_light << 167 >> 168 // Energy should not be lager than initial value >> 169 accuracy = ( theEnergyChange - aTrack.GetKineticEnergy())/MeV; >> 170 if (accuracy > accuracyForWarning) { >> 171 G4cout << " G4ParticleChangeForLoss::CheckIt : "; >> 172 G4cout << "the energy becoes larger than the initial value !!" << G4endl; >> 173 G4cout << " Difference: " << accuracy << "[MeV] " <<G4endl; >> 174 itsOK = false; >> 175 if (accuracy > accuracyForException) exitWithError = true; 116 } 176 } 117 else << 177 118 { << 178 // dump out information of this particle change 119 pPostStepPoint->SetKineticEnergy(0.0); << 179 if (!itsOK) { 120 pPostStepPoint->SetVelocity(0.0); << 180 G4cout << " G4ParticleChangeForLoss::CheckIt " <<G4endl; >> 181 DumpInfo(); 121 } 182 } 122 pPostStepPoint->SetPolarization(proposedPola << 123 183 124 if(isParentWeightProposed) << 184 // Exit with error 125 { << 185 if (exitWithError) G4Exception("G4ParticleChangeForLoss::CheckIt"); 126 pPostStepPoint->SetWeight(theParentWeight) << 186 >> 187 //correction >> 188 if (!itsOK) { >> 189 theEnergyChange = aTrack.GetKineticEnergy(); 127 } 190 } 128 191 129 pStep->AddTotalEnergyDeposit(theLocalEnergyD << 192 itsOK = (itsOK) && G4VParticleChange::CheckIt(aTrack); 130 pStep->AddNonIonizingEnergyDeposit(theNonIon << 193 return itsOK; 131 return pStep; << 132 } 194 } >> 195 >> 196 >> 197 >> 198 >> 199 >> 200 >> 201 >> 202 >> 203 >> 204 >> 205 >> 206 133 207