[819] | 1 | // |
---|
| 2 | // ******************************************************************** |
---|
| 3 | // * License and Disclaimer * |
---|
| 4 | // * * |
---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
| 7 | // * conditions of the Geant4 Software License, included in the file * |
---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
| 9 | // * include a list of copyright holders. * |
---|
| 10 | // * * |
---|
| 11 | // * Neither the authors of this software system, nor their employing * |
---|
| 12 | // * institutes,nor the agencies providing financial support for this * |
---|
| 13 | // * work make any representation or warranty, express or implied, * |
---|
| 14 | // * regarding this software system or assume any liability for its * |
---|
| 15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
| 16 | // * for the full disclaimer and the limitation of liability. * |
---|
| 17 | // * * |
---|
| 18 | // * This code implementation is the result of the scientific and * |
---|
| 19 | // * technical work of the GEANT4 collaboration. * |
---|
| 20 | // * By using, copying, modifying or distributing the software (or * |
---|
| 21 | // * any work based on the software) you agree to acknowledge its * |
---|
| 22 | // * use in resulting scientific publications, and indicate your * |
---|
| 23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
| 24 | // ******************************************************************** |
---|
| 25 | // |
---|
| 26 | |
---|
| 27 | #include "G4ErrorEnergyLoss.hh" |
---|
| 28 | #include "G4ErrorPropagatorData.hh" |
---|
| 29 | #include "G4EnergyLossForExtrapolator.hh" |
---|
| 30 | |
---|
| 31 | //------------------------------------------------------------------- |
---|
| 32 | G4ErrorEnergyLoss::G4ErrorEnergyLoss(const G4String& processName, |
---|
| 33 | G4ProcessType type) |
---|
| 34 | : G4VContinuousProcess(processName, type) |
---|
| 35 | { |
---|
| 36 | if (verboseLevel>2) { |
---|
| 37 | G4cout << GetProcessName() << " is created " << G4endl; |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | InstantiateEforExtrapolator(); |
---|
| 41 | |
---|
| 42 | theStepLimit = 1.; |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | //------------------------------------------------------------------- |
---|
| 46 | void G4ErrorEnergyLoss::InstantiateEforExtrapolator() |
---|
| 47 | { |
---|
| 48 | if( theELossForExtrapolator == 0 ) { |
---|
| 49 | theELossForExtrapolator = new G4EnergyLossForExtrapolator; |
---|
| 50 | } |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | |
---|
| 54 | //------------------------------------------------------------------- |
---|
| 55 | G4ErrorEnergyLoss::~G4ErrorEnergyLoss() |
---|
| 56 | { |
---|
| 57 | if( theELossForExtrapolator != 0 ) { |
---|
| 58 | delete theELossForExtrapolator; |
---|
| 59 | } |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | //------------------------------------------------------------------- |
---|
| 63 | G4VParticleChange* |
---|
| 64 | G4ErrorEnergyLoss::AlongStepDoIt(const G4Track& aTrack, const G4Step& aStep) |
---|
| 65 | { |
---|
| 66 | aParticleChange.Initialize(aTrack); |
---|
| 67 | |
---|
| 68 | G4ErrorPropagatorData* g4edata = G4ErrorPropagatorData::GetErrorPropagatorData(); |
---|
| 69 | |
---|
| 70 | G4double kinEnergyStart = aTrack.GetKineticEnergy(); |
---|
| 71 | G4double step_length = aStep.GetStepLength(); |
---|
| 72 | |
---|
| 73 | const G4Material* aMaterial = aTrack.GetMaterial(); |
---|
| 74 | const G4ParticleDefinition* aParticleDef = aTrack.GetDynamicParticle()->GetDefinition(); |
---|
| 75 | G4double kinEnergyEnd = kinEnergyStart; |
---|
| 76 | |
---|
| 77 | if( g4edata->GetMode() == G4ErrorMode(G4ErrorMode_PropBackwards) ) { |
---|
| 78 | kinEnergyEnd = theELossForExtrapolator->EnergyBeforeStep( kinEnergyStart, |
---|
| 79 | step_length, |
---|
| 80 | aMaterial, |
---|
| 81 | aParticleDef ); |
---|
| 82 | G4double kinEnergyHalfStep = kinEnergyStart - (kinEnergyStart-kinEnergyEnd)/2.; |
---|
| 83 | |
---|
| 84 | #ifdef G4VERBOSE |
---|
| 85 | if(G4ErrorPropagatorData::verbose() >= 3 ) |
---|
| 86 | G4cout << " G4ErrorEnergyLoss FWD end " << kinEnergyEnd |
---|
| 87 | << " halfstep " << kinEnergyHalfStep << G4endl; |
---|
| 88 | #endif |
---|
| 89 | |
---|
| 90 | //--- rescale to energy lost at 1/2 step |
---|
| 91 | kinEnergyEnd = theELossForExtrapolator->EnergyBeforeStep( kinEnergyHalfStep, |
---|
| 92 | step_length, |
---|
| 93 | aMaterial, |
---|
| 94 | aParticleDef ); |
---|
| 95 | kinEnergyEnd = kinEnergyStart - (kinEnergyHalfStep - kinEnergyEnd ); |
---|
| 96 | }else if( g4edata->GetMode() == G4ErrorMode(G4ErrorMode_PropForwards) ) { |
---|
| 97 | kinEnergyEnd = theELossForExtrapolator->EnergyAfterStep( kinEnergyStart, |
---|
| 98 | step_length, |
---|
| 99 | aMaterial, |
---|
| 100 | aParticleDef ); |
---|
| 101 | G4double kinEnergyHalfStep = kinEnergyStart - (kinEnergyStart-kinEnergyEnd)/2.; |
---|
| 102 | #ifdef G4VERBOSE |
---|
| 103 | if(G4ErrorPropagatorData::verbose() >= 3 ) |
---|
| 104 | G4cout << " G4ErrorEnergyLoss BCKD end " << kinEnergyEnd |
---|
| 105 | << " halfstep " << kinEnergyHalfStep << G4endl; |
---|
| 106 | #endif |
---|
| 107 | |
---|
| 108 | //--- rescale to energy lost at 1/2 step |
---|
| 109 | kinEnergyEnd = theELossForExtrapolator->EnergyAfterStep( kinEnergyHalfStep, |
---|
| 110 | step_length, |
---|
| 111 | aMaterial, |
---|
| 112 | aParticleDef ); |
---|
| 113 | kinEnergyEnd = kinEnergyStart - (kinEnergyHalfStep - kinEnergyEnd ); |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | G4double edepo = kinEnergyEnd - kinEnergyStart; |
---|
| 117 | |
---|
| 118 | #ifdef G4VERBOSE |
---|
| 119 | if( G4ErrorPropagatorData::verbose() >= 2 ) |
---|
| 120 | G4cout << "AlongStepDoIt Estart= " << kinEnergyStart << " Eend " << kinEnergyEnd |
---|
| 121 | << " Ediff " << kinEnergyStart-kinEnergyEnd << " step= " << step_length |
---|
| 122 | << " mate= " << aMaterial->GetName() |
---|
| 123 | << " particle= " << aParticleDef->GetParticleName() << G4endl; |
---|
| 124 | #endif |
---|
| 125 | |
---|
| 126 | aParticleChange.ClearDebugFlag(); |
---|
| 127 | aParticleChange.ProposeLocalEnergyDeposit( edepo ); |
---|
| 128 | aParticleChange.SetNumberOfSecondaries(0); |
---|
| 129 | |
---|
| 130 | aParticleChange.ProposeEnergy( kinEnergyEnd ); |
---|
| 131 | |
---|
| 132 | return &aParticleChange; |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | |
---|
| 136 | //------------------------------------------------------------------- |
---|
| 137 | G4double G4ErrorEnergyLoss::GetContinuousStepLimit(const G4Track& aTrack, |
---|
| 138 | G4double , |
---|
| 139 | G4double currentMinimumStep, |
---|
| 140 | G4double& ) |
---|
| 141 | { |
---|
| 142 | G4double Step = DBL_MAX; |
---|
| 143 | if( theStepLimit != 1. ) { |
---|
| 144 | G4double kinEnergyStart = aTrack.GetKineticEnergy(); |
---|
| 145 | G4double kinEnergyLoss = kinEnergyStart; |
---|
| 146 | const G4Material* aMaterial = aTrack.GetMaterial(); |
---|
| 147 | const G4ParticleDefinition* aParticleDef = aTrack.GetDynamicParticle()->GetDefinition(); |
---|
| 148 | G4ErrorPropagatorData* g4edata = G4ErrorPropagatorData::GetErrorPropagatorData(); |
---|
| 149 | if( g4edata->GetMode() == G4ErrorMode(G4ErrorMode_PropBackwards) ) { |
---|
| 150 | kinEnergyLoss = - kinEnergyStart + |
---|
| 151 | theELossForExtrapolator->EnergyBeforeStep( kinEnergyStart, currentMinimumStep, |
---|
| 152 | aMaterial, aParticleDef ); |
---|
| 153 | }else if( g4edata->GetMode() == G4ErrorMode(G4ErrorMode_PropForwards) ) { |
---|
| 154 | kinEnergyLoss = kinEnergyStart - |
---|
| 155 | theELossForExtrapolator->EnergyAfterStep( kinEnergyStart, currentMinimumStep, |
---|
| 156 | aMaterial, aParticleDef ); |
---|
| 157 | } |
---|
| 158 | #ifdef G4VERBOSE |
---|
| 159 | if(G4ErrorPropagatorData::verbose() >= 3 ) |
---|
| 160 | G4cout << " G4ErrorEnergyLoss: currentMinimumStep " <<currentMinimumStep |
---|
| 161 | << " kinEnergyLoss " << kinEnergyLoss |
---|
| 162 | << " kinEnergyStart " << kinEnergyStart << G4endl; |
---|
| 163 | #endif |
---|
| 164 | if( kinEnergyLoss / kinEnergyStart > theStepLimit ) { |
---|
| 165 | Step = theStepLimit / (kinEnergyLoss / kinEnergyStart) * currentMinimumStep; |
---|
| 166 | #ifdef G4VERBOSE |
---|
| 167 | if(G4ErrorPropagatorData::verbose() >= 2 ) |
---|
| 168 | G4cout << " G4ErrorEnergyLoss: limiting Step " << Step |
---|
| 169 | << " energy loss fraction " << kinEnergyLoss / kinEnergyStart |
---|
| 170 | << " > " << theStepLimit << G4endl; |
---|
| 171 | #endif |
---|
| 172 | } |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | return Step; |
---|
| 176 | |
---|
| 177 | } |
---|