00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include "G4ParticleChangeForGamma.hh"
00043 #include "G4SystemOfUnits.hh"
00044 #include "G4Track.hh"
00045 #include "G4Step.hh"
00046 #include "G4DynamicParticle.hh"
00047 #include "G4ExceptionSeverity.hh"
00048
00049 G4ParticleChangeForGamma::G4ParticleChangeForGamma()
00050 : G4VParticleChange(), currentTrack(0), proposedKinEnergy(0.)
00051 {
00052 theSteppingControlFlag = NormalCondition;
00053 debugFlag = false;
00054 #ifdef G4VERBOSE
00055 if (verboseLevel>2) {
00056 G4cout << "G4ParticleChangeForGamma::G4ParticleChangeForGamma() " << G4endl;
00057 }
00058 #endif
00059 }
00060
00061 G4ParticleChangeForGamma::~G4ParticleChangeForGamma()
00062 {
00063 #ifdef G4VERBOSE
00064 if (verboseLevel>2) {
00065 G4cout << "G4ParticleChangeForGamma::~G4ParticleChangeForGamma() " << G4endl;
00066 }
00067 #endif
00068 }
00069
00070 G4ParticleChangeForGamma::G4ParticleChangeForGamma(
00071 const G4ParticleChangeForGamma &right): G4VParticleChange(right)
00072 {
00073 if (verboseLevel>1)
00074 G4cout << "G4ParticleChangeForGamma:: copy constructor is called " << G4endl;
00075
00076 currentTrack = right.currentTrack;
00077 proposedKinEnergy = right.proposedKinEnergy;
00078 proposedMomentumDirection = right.proposedMomentumDirection;
00079 proposedPolarization = right.proposedPolarization;
00080 }
00081
00082
00083 G4ParticleChangeForGamma & G4ParticleChangeForGamma::operator=(
00084 const G4ParticleChangeForGamma &right)
00085 {
00086 #ifdef G4VERBOSE
00087 if (verboseLevel>1)
00088 G4cout << "G4ParticleChangeForGamma:: assignment operator is called " << G4endl;
00089 #endif
00090
00091 if (this != &right) {
00092 if (theNumberOfSecondaries>0) {
00093 #ifdef G4VERBOSE
00094 if (verboseLevel>0) {
00095 G4cout << "G4ParticleChangeForGamma: assignment operator Warning ";
00096 G4cout << "theListOfSecondaries is not empty ";
00097 }
00098 #endif
00099 for (G4int index= 0; index<theNumberOfSecondaries; index++){
00100 if ( (*theListOfSecondaries)[index] ) delete (*theListOfSecondaries)[index] ;
00101 }
00102 }
00103 delete theListOfSecondaries;
00104 theListOfSecondaries = new G4TrackFastVector();
00105 theNumberOfSecondaries = right.theNumberOfSecondaries;
00106 for (G4int index = 0; index<theNumberOfSecondaries; index++){
00107 G4Track* newTrack = new G4Track(*((*right.theListOfSecondaries)[index] ));
00108 theListOfSecondaries->SetElement(index, newTrack); }
00109
00110 theStatusChange = right.theStatusChange;
00111 theLocalEnergyDeposit = right.theLocalEnergyDeposit;
00112 theSteppingControlFlag = right.theSteppingControlFlag;
00113 theParentWeight = right.theParentWeight;
00114
00115 currentTrack = right.currentTrack;
00116 proposedKinEnergy = right.proposedKinEnergy;
00117 proposedMomentumDirection = right.proposedMomentumDirection;
00118 proposedPolarization = right.proposedPolarization;
00119 }
00120 return *this;
00121 }
00122
00123 void G4ParticleChangeForGamma::AddSecondary(G4DynamicParticle* aParticle)
00124 {
00125
00126 G4Track* aTrack = new G4Track(aParticle, currentTrack->GetGlobalTime(),
00127 currentTrack->GetPosition());
00128
00129
00130 aTrack->SetTouchableHandle(currentTrack->GetTouchableHandle());
00131
00132
00133 G4VParticleChange::AddSecondary(aTrack);
00134 }
00135
00136
00137
00138
00139
00140 G4Step* G4ParticleChangeForGamma::UpdateStepForAtRest(G4Step* pStep)
00141 {
00142 pStep->AddTotalEnergyDeposit( theLocalEnergyDeposit );
00143 pStep->SetStepLength( 0.0 );
00144
00145 if (isParentWeightProposed ){
00146 pStep->GetPostStepPoint()->SetWeight( theParentWeight );
00147 }
00148
00149 return pStep;
00150 }
00151
00152 G4Step* G4ParticleChangeForGamma::UpdateStepForPostStep(G4Step* pStep)
00153 {
00154 G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint();
00155 G4Track* pTrack = pStep->GetTrack();
00156
00157 pPostStepPoint->SetKineticEnergy( proposedKinEnergy );
00158 pPostStepPoint->SetMomentumDirection( proposedMomentumDirection );
00159 pPostStepPoint->SetPolarization( proposedPolarization );
00160
00161
00162 if(proposedKinEnergy > 0.0) {
00163 if(pTrack->GetParticleDefinition()->GetPDGMass() > 0.0) {
00164 pPostStepPoint->SetVelocity(pTrack->CalculateVelocity());
00165 }
00166 }
00167
00168 if (isParentWeightProposed ){
00169 pPostStepPoint->SetWeight( theParentWeight );
00170 }
00171
00172 pStep->AddTotalEnergyDeposit( theLocalEnergyDeposit );
00173 pStep->AddNonIonizingEnergyDeposit( theNonIonizingEnergyDeposit );
00174 return pStep;
00175 }
00176
00177
00178
00179
00180
00181 void G4ParticleChangeForGamma::DumpInfo() const
00182 {
00183
00184 G4VParticleChange::DumpInfo();
00185
00186 G4int oldprc = G4cout.precision(3);
00187 G4cout << " Kinetic Energy (MeV): "
00188 << std::setw(20) << proposedKinEnergy/MeV
00189 << G4endl;
00190 G4cout << " Momentum Direction: "
00191 << std::setw(20) << proposedMomentumDirection
00192 << G4endl;
00193 G4cout << " Polarization: "
00194 << std::setw(20) << proposedPolarization
00195 << G4endl;
00196 G4cout.precision(oldprc);
00197 }
00198
00199 G4bool G4ParticleChangeForGamma::CheckIt(const G4Track& aTrack)
00200 {
00201 G4bool itsOK = true;
00202 G4bool exitWithError = false;
00203
00204 G4double accuracy;
00205
00206
00207 accuracy = ( proposedKinEnergy - aTrack.GetKineticEnergy())/MeV;
00208 if (accuracy > accuracyForWarning) {
00209 itsOK = false;
00210 exitWithError = (accuracy > accuracyForException);
00211 #ifdef G4VERBOSE
00212 G4cout << "G4ParticleChangeForGamma::CheckIt: ";
00213 G4cout << "KinEnergy become larger than the initial value!"
00214 << " Difference: " << accuracy << "[MeV] " <<G4endl;
00215 G4cout << aTrack.GetDefinition()->GetParticleName()
00216 << " E=" << aTrack.GetKineticEnergy()/MeV
00217 << " pos=" << aTrack.GetPosition().x()/m
00218 << ", " << aTrack.GetPosition().y()/m
00219 << ", " << aTrack.GetPosition().z()/m
00220 << G4endl;
00221 #endif
00222 }
00223
00224
00225 #ifdef G4VERBOSE
00226 if (!itsOK) DumpInfo();
00227 #endif
00228
00229
00230 if (exitWithError) {
00231 G4Exception("G4ParticleChangeForGamma::CheckIt",
00232 "TRACK004",EventMustBeAborted,
00233 "energy was illegal");
00234 }
00235
00236
00237 if (!itsOK) {
00238 proposedKinEnergy = aTrack.GetKineticEnergy();
00239 }
00240
00241 itsOK = (itsOK) && G4VParticleChange::CheckIt(aTrack);
00242 return itsOK;
00243 }