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 26 27 #include "G4ErrorEnergyLoss.hh" 27 #include "G4ErrorEnergyLoss.hh" 28 #include "G4EnergyLossForExtrapolator.hh" << 29 #include "G4ErrorPropagatorData.hh" 28 #include "G4ErrorPropagatorData.hh" >> 29 #include "G4EnergyLossForExtrapolator.hh" 30 30 31 //-------------------------------------------- 31 //------------------------------------------------------------------- 32 G4ErrorEnergyLoss::G4ErrorEnergyLoss(const G4S 32 G4ErrorEnergyLoss::G4ErrorEnergyLoss(const G4String& processName, 33 G4ProcessType type) 33 G4ProcessType type) 34 : G4VContinuousProcess(processName, type) << 34 : G4VContinuousProcess(processName, type) 35 { 35 { 36 if (verboseLevel>2) { 36 if (verboseLevel>2) { 37 G4cout << GetProcessName() << " is created 37 G4cout << GetProcessName() << " is created " << G4endl; 38 } 38 } 39 39 40 theELossForExtrapolator = new G4EnergyLossFo << 40 InstantiateEforExtrapolator(); 41 theStepLimit = 1.*CLHEP::mm; << 41 >> 42 theStepLimit = 1.; 42 } 43 } 43 44 44 //-------------------------------------------- 45 //------------------------------------------------------------------- 45 void G4ErrorEnergyLoss::InstantiateEforExtrapo 46 void G4ErrorEnergyLoss::InstantiateEforExtrapolator() 46 {} << 47 << 48 //-------------------------------------------- << 49 G4ErrorEnergyLoss::~G4ErrorEnergyLoss() << 50 { 47 { 51 delete theELossForExtrapolator; << 48 if( theELossForExtrapolator == 0 ) { >> 49 theELossForExtrapolator = new G4EnergyLossForExtrapolator; >> 50 } 52 } 51 } 53 52 54 //-------------------------------------------- << 55 53 56 G4bool G4ErrorEnergyLoss::IsApplicable(const G << 54 //------------------------------------------------------------------- >> 55 G4ErrorEnergyLoss::~G4ErrorEnergyLoss() 57 { 56 { 58 return (aParticleType.GetPDGCharge() != 0); << 57 if( theELossForExtrapolator != 0 ) { >> 58 delete theELossForExtrapolator; >> 59 } 59 } 60 } 60 61 61 //-------------------------------------------- 62 //------------------------------------------------------------------- 62 G4VParticleChange* 63 G4VParticleChange* 63 G4ErrorEnergyLoss::AlongStepDoIt(const G4Track 64 G4ErrorEnergyLoss::AlongStepDoIt(const G4Track& aTrack, const G4Step& aStep) 64 { 65 { 65 aParticleChange.Initialize(aTrack); 66 aParticleChange.Initialize(aTrack); 66 67 67 G4ErrorPropagatorData* g4edata = G4ErrorProp << 68 G4ErrorPropagatorData* g4edata = G4ErrorPropagatorData::GetErrorPropagatorData(); 68 69 69 G4double kinEnergyStart = aTrack.GetKineticE 70 G4double kinEnergyStart = aTrack.GetKineticEnergy(); 70 G4double step_length = aStep.GetStepLength( 71 G4double step_length = aStep.GetStepLength(); 71 72 72 const G4Material* aMaterial = aTrack.GetMate 73 const G4Material* aMaterial = aTrack.GetMaterial(); 73 const G4ParticleDefinition* aParticleDef = a 74 const G4ParticleDefinition* aParticleDef = aTrack.GetDynamicParticle()->GetDefinition(); 74 G4double kinEnergyEnd = kinEnergyStart; 75 G4double kinEnergyEnd = kinEnergyStart; 75 76 76 // backward - energy increased << 77 if( g4edata->GetMode() == G4ErrorMode(G4Erro 77 if( g4edata->GetMode() == G4ErrorMode(G4ErrorMode_PropBackwards) ) { 78 kinEnergyEnd = theELossForExtrapolator->En 78 kinEnergyEnd = theELossForExtrapolator->EnergyBeforeStep( kinEnergyStart, 79 step_length, 79 step_length, 80 aMaterial, 80 aMaterial, 81 aParticleDef ); 81 aParticleDef ); 82 G4double kinEnergyHalfStep = (kinEnergySta << 82 G4double kinEnergyHalfStep = kinEnergyStart - (kinEnergyStart-kinEnergyEnd)/2.; 83 83 84 #ifdef G4VERBOSE 84 #ifdef G4VERBOSE 85 if(G4ErrorPropagatorData::verbose() >= 3 ) 85 if(G4ErrorPropagatorData::verbose() >= 3 ) 86 G4cout << " G4ErrorEnergyLoss FWD end " < 86 G4cout << " G4ErrorEnergyLoss FWD end " << kinEnergyEnd 87 << " halfstep " << kinEnergyHalfStep << G 87 << " halfstep " << kinEnergyHalfStep << G4endl; 88 #endif 88 #endif 89 89 90 //--- rescale to energy lost at 1/2 step 90 //--- rescale to energy lost at 1/2 step 91 kinEnergyEnd = theELossForExtrapolator->En 91 kinEnergyEnd = theELossForExtrapolator->EnergyBeforeStep( kinEnergyHalfStep, 92 step_length, 92 step_length, 93 aMaterial, 93 aMaterial, 94 aParticleDef ); 94 aParticleDef ); 95 kinEnergyEnd = kinEnergyStart - (kinEnergy 95 kinEnergyEnd = kinEnergyStart - (kinEnergyHalfStep - kinEnergyEnd ); 96 << 96 }else if( g4edata->GetMode() == G4ErrorMode(G4ErrorMode_PropForwards) ) { 97 // forward - energy decreased << 98 } else { << 99 kinEnergyEnd = theELossForExtrapolator->En 97 kinEnergyEnd = theELossForExtrapolator->EnergyAfterStep( kinEnergyStart, 100 step_length, 98 step_length, 101 aMaterial, 99 aMaterial, 102 aParticleDef ); 100 aParticleDef ); 103 G4double kinEnergyHalfStep = (kinEnergySta << 101 G4double kinEnergyHalfStep = kinEnergyStart - (kinEnergyStart-kinEnergyEnd)/2.; 104 #ifdef G4VERBOSE 102 #ifdef G4VERBOSE 105 if(G4ErrorPropagatorData::verbose() >= 3 ) 103 if(G4ErrorPropagatorData::verbose() >= 3 ) 106 G4cout << " G4ErrorEnergyLoss BCKD end " 104 G4cout << " G4ErrorEnergyLoss BCKD end " << kinEnergyEnd 107 << " halfstep " << kinEnergyHalfStep << G 105 << " halfstep " << kinEnergyHalfStep << G4endl; 108 #endif 106 #endif 109 107 110 //--- rescale to energy lost at 1/2 step 108 //--- rescale to energy lost at 1/2 step 111 kinEnergyEnd = theELossForExtrapolator->En 109 kinEnergyEnd = theELossForExtrapolator->EnergyAfterStep( kinEnergyHalfStep, 112 step_length, 110 step_length, 113 aMaterial, 111 aMaterial, 114 aParticleDef ); 112 aParticleDef ); 115 kinEnergyEnd = kinEnergyStart - (kinEnergy 113 kinEnergyEnd = kinEnergyStart - (kinEnergyHalfStep - kinEnergyEnd ); 116 } 114 } 117 115 118 G4double edepo = kinEnergyEnd - kinEnergySta 116 G4double edepo = kinEnergyEnd - kinEnergyStart; 119 117 120 #ifdef G4VERBOSE 118 #ifdef G4VERBOSE 121 if( G4ErrorPropagatorData::verbose() >= 2 ) 119 if( G4ErrorPropagatorData::verbose() >= 2 ) 122 G4cout << "AlongStepDoIt Estart= " << kinE 120 G4cout << "AlongStepDoIt Estart= " << kinEnergyStart << " Eend " << kinEnergyEnd 123 << " Ediff " << kinEnergyStart-kinEnergyE 121 << " Ediff " << kinEnergyStart-kinEnergyEnd << " step= " << step_length 124 << " mate= " << aMaterial->GetName() 122 << " mate= " << aMaterial->GetName() 125 << " particle= " << aParticleDef->GetPart 123 << " particle= " << aParticleDef->GetParticleName() << G4endl; 126 #endif 124 #endif 127 125 128 aParticleChange.ClearDebugFlag(); 126 aParticleChange.ClearDebugFlag(); 129 aParticleChange.ProposeLocalEnergyDeposit( e 127 aParticleChange.ProposeLocalEnergyDeposit( edepo ); 130 aParticleChange.SetNumberOfSecondaries(0); 128 aParticleChange.SetNumberOfSecondaries(0); 131 129 132 aParticleChange.ProposeEnergy( kinEnergyEnd 130 aParticleChange.ProposeEnergy( kinEnergyEnd ); 133 131 134 return &aParticleChange; 132 return &aParticleChange; 135 } 133 } 136 134 137 135 138 //-------------------------------------------- 136 //------------------------------------------------------------------- 139 G4double G4ErrorEnergyLoss::GetContinuousStepL 137 G4double G4ErrorEnergyLoss::GetContinuousStepLimit(const G4Track& aTrack, 140 G4double, G4double, G4double& ) << 138 G4double , 141 { << 139 G4double currentMinimumStep, 142 G4double ekin = aTrack.GetKineticEnergy(); << 140 G4double& ) 143 const G4Material* mat = aTrack.GetMaterial() << 141 { 144 const G4ParticleDefinition* part = << 142 G4double Step = DBL_MAX; 145 aTrack.GetDynamicParticle()->GetDefinition << 143 if( theStepLimit != 1. ) { 146 G4double range = theELossForExtrapolator->Co << 144 G4double kinEnergyStart = aTrack.GetKineticEnergy(); 147 G4double delta = std::max(range*theFractionL << 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 } 148 #ifdef G4VERBOSE 158 #ifdef G4VERBOSE 149 if(G4ErrorPropagatorData::verbose() >= 2 ) { << 159 if(G4ErrorPropagatorData::verbose() >= 3 ) 150 G4cout << " G4ErrorEnergyLoss: limiting St << 160 G4cout << " G4ErrorEnergyLoss: currentMinimumStep " <<currentMinimumStep 151 << " energy(GeV) " << ekin / CLHEP::GeV << 161 << " kinEnergyLoss " << kinEnergyLoss 152 << " for " << part->GetParticleName() << << 162 << " kinEnergyStart " << kinEnergyStart << G4endl; 153 } << 154 #endif 163 #endif 155 return delta; << 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 156 } 177 } 157 178