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[ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /track/src/G4ParticleChangeForLoss.cc (Version 11.3.0) and /track/src/G4ParticleChangeForLoss.cc (Version 11.0)


  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     26 // G4ParticleChangeForLoss class implementation
 27 //                                                 27 //
 28 // Author: Hisaya Kurashige, 23 March 1998         28 // Author: Hisaya Kurashige, 23 March 1998  
 29 // Revision: Vladimir Ivantchenko, 16 January      29 // Revision: Vladimir Ivantchenko, 16 January 2004
 30 // -------------------------------------------     30 // --------------------------------------------------------------------
 31                                                    31 
 32 #include "G4ParticleChangeForLoss.hh"              32 #include "G4ParticleChangeForLoss.hh"
 33 #include "G4SystemOfUnits.hh"                      33 #include "G4SystemOfUnits.hh"
                                                   >>  34 #include "G4Track.hh"
                                                   >>  35 #include "G4Step.hh"
                                                   >>  36 #include "G4DynamicParticle.hh"
 34 #include "G4ExceptionSeverity.hh"                  37 #include "G4ExceptionSeverity.hh"
 35                                                    38 
 36 // -------------------------------------------     39 // --------------------------------------------------------------------
 37 G4ParticleChangeForLoss::G4ParticleChangeForLo     40 G4ParticleChangeForLoss::G4ParticleChangeForLoss()
                                                   >>  41   : G4VParticleChange()
                                                   >>  42   , lowEnergyLimit(1.0 * eV)
 38 {                                                  43 {
                                                   >>  44   theSteppingControlFlag = NormalCondition;
 39   // Disable flag that is enabled in G4VPartic     45   // Disable flag that is enabled in G4VParticleChange if G4VERBOSE.
 40   debugFlag = false;                           <<  46   debugFlag              = false;
 41   SetNumberOfSecondaries(1);                   <<  47 }
                                                   >>  48 
                                                   >>  49 // --------------------------------------------------------------------
                                                   >>  50 G4ParticleChangeForLoss::~G4ParticleChangeForLoss()
                                                   >>  51 {
                                                   >>  52 }
                                                   >>  53 
                                                   >>  54 // --------------------------------------------------------------------
                                                   >>  55 G4ParticleChangeForLoss::G4ParticleChangeForLoss(
                                                   >>  56   const G4ParticleChangeForLoss& right)
                                                   >>  57   : G4VParticleChange(right)
                                                   >>  58 {
                                                   >>  59   currentTrack              = right.currentTrack;
                                                   >>  60   proposedKinEnergy         = right.proposedKinEnergy;
                                                   >>  61   lowEnergyLimit            = right.lowEnergyLimit;
                                                   >>  62   currentCharge             = right.currentCharge;
                                                   >>  63   proposedMomentumDirection = right.proposedMomentumDirection;
                                                   >>  64 }
                                                   >>  65 
                                                   >>  66 // --------------------------------------------------------------------
                                                   >>  67 G4ParticleChangeForLoss& G4ParticleChangeForLoss::operator=(
                                                   >>  68   const G4ParticleChangeForLoss& right)
                                                   >>  69 {
                                                   >>  70   if(this != &right)
                                                   >>  71   {
                                                   >>  72     if(theNumberOfSecondaries > 0)
                                                   >>  73     {
                                                   >>  74       for(G4int index = 0; index < theNumberOfSecondaries; ++index)
                                                   >>  75       {
                                                   >>  76         if((*theListOfSecondaries)[index])
                                                   >>  77           delete(*theListOfSecondaries)[index];
                                                   >>  78       }
                                                   >>  79     }
                                                   >>  80     delete theListOfSecondaries;
                                                   >>  81     theListOfSecondaries   = new G4TrackFastVector();
                                                   >>  82     theNumberOfSecondaries = right.theNumberOfSecondaries;
                                                   >>  83     for(G4int index = 0; index < theNumberOfSecondaries; ++index)
                                                   >>  84     {
                                                   >>  85       G4Track* newTrack = new G4Track(*((*right.theListOfSecondaries)[index]));
                                                   >>  86       theListOfSecondaries->SetElement(index, newTrack);
                                                   >>  87     }
                                                   >>  88 
                                                   >>  89     theStatusChange              = right.theStatusChange;
                                                   >>  90     theLocalEnergyDeposit        = right.theLocalEnergyDeposit;
                                                   >>  91     theSteppingControlFlag       = right.theSteppingControlFlag;
                                                   >>  92     theParentWeight              = right.theParentWeight;
                                                   >>  93     isParentWeightProposed       = right.isParentWeightProposed;
                                                   >>  94     fSetSecondaryWeightByProcess = right.fSetSecondaryWeightByProcess;
                                                   >>  95 
                                                   >>  96     currentTrack              = right.currentTrack;
                                                   >>  97     proposedKinEnergy         = right.proposedKinEnergy;
                                                   >>  98     currentCharge             = right.currentCharge;
                                                   >>  99     proposedMomentumDirection = right.proposedMomentumDirection;
                                                   >> 100   }
                                                   >> 101   return *this;
 42 }                                                 102 }
 43                                                   103 
 44 // -------------------------------------------    104 // --------------------------------------------------------------------
 45 void G4ParticleChangeForLoss::DumpInfo() const    105 void G4ParticleChangeForLoss::DumpInfo() const
 46 {                                                 106 {
 47   // use base-class DumpInfo                      107   // use base-class DumpInfo
 48   G4VParticleChange::DumpInfo();                  108   G4VParticleChange::DumpInfo();
 49                                                   109 
 50   G4long oldprc = G4cout.precision(8);         << 110   G4int oldprc = G4cout.precision(3);
 51   G4cout << "      --------------------------- << 
 52   G4cout << "        G4ParticleChangeForLoss p << 
 53   G4cout << "        Charge (eplus)   : " << s    111   G4cout << "        Charge (eplus)   : " << std::setw(20)
 54          << currentCharge / eplus << G4endl;      112          << currentCharge / eplus << G4endl;
 55   G4cout << "        Kinetic Energy (MeV): " <    113   G4cout << "        Kinetic Energy (MeV): " << std::setw(20)
 56          << proposedKinEnergy / MeV << G4endl;    114          << proposedKinEnergy / MeV << G4endl;
 57   G4cout << "        Momentum Direct - x : " <    115   G4cout << "        Momentum Direct - x : " << std::setw(20)
 58          << proposedMomentumDirection.x() << G    116          << proposedMomentumDirection.x() << G4endl;
 59   G4cout << "        Momentum Direct - y : " <    117   G4cout << "        Momentum Direct - y : " << std::setw(20)
 60          << proposedMomentumDirection.y() << G    118          << proposedMomentumDirection.y() << G4endl;
 61   G4cout << "        Momentum Direct - z : " <    119   G4cout << "        Momentum Direct - z : " << std::setw(20)
 62          << proposedMomentumDirection.z() << G    120          << proposedMomentumDirection.z() << G4endl;
 63   G4cout.precision(oldprc);                       121   G4cout.precision(oldprc);
 64 }                                                 122 }
 65                                                   123 
 66 // -------------------------------------------    124 // --------------------------------------------------------------------
                                                   >> 125 G4bool G4ParticleChangeForLoss::CheckIt(const G4Track& aTrack)
                                                   >> 126 {
                                                   >> 127   G4bool itsOK         = true;
                                                   >> 128   G4bool exitWithError = false;
                                                   >> 129 
                                                   >> 130   G4double accuracy;
                                                   >> 131 
                                                   >> 132   // Energy should not be lager than initial value
                                                   >> 133   accuracy = (proposedKinEnergy - aTrack.GetKineticEnergy()) / MeV;
                                                   >> 134   if(accuracy > accuracyForWarning)
                                                   >> 135   {
                                                   >> 136     itsOK         = false;
                                                   >> 137     exitWithError = (accuracy > accuracyForException);
                                                   >> 138 #ifdef G4VERBOSE
                                                   >> 139     G4cout << "G4ParticleChangeForLoss::CheckIt: ";
                                                   >> 140     G4cout << "KinEnergy become larger than the initial value!"
                                                   >> 141            << "  Difference:  " << accuracy << "[MeV] " << G4endl;
                                                   >> 142     G4cout << aTrack.GetDefinition()->GetParticleName()
                                                   >> 143            << " E=" << aTrack.GetKineticEnergy() / MeV
                                                   >> 144            << " pos=" << aTrack.GetPosition().x() / m << ", "
                                                   >> 145            << aTrack.GetPosition().y() / m << ", "
                                                   >> 146            << aTrack.GetPosition().z() / m << G4endl;
                                                   >> 147 #endif
                                                   >> 148   }
                                                   >> 149 
                                                   >> 150   // dump out information of this particle change
                                                   >> 151 #ifdef G4VERBOSE
                                                   >> 152   if(!itsOK) { DumpInfo(); }
                                                   >> 153 #endif
                                                   >> 154 
                                                   >> 155   // exit with error
                                                   >> 156   if(exitWithError)
                                                   >> 157   {
                                                   >> 158     G4Exception("G4ParticleChangeForLoss::CheckIt()", "TRACK004",
                                                   >> 159                 EventMustBeAborted, "energy was  illegal");
                                                   >> 160   }
                                                   >> 161 
                                                   >> 162   // correction
                                                   >> 163   if(!itsOK)
                                                   >> 164   {
                                                   >> 165     proposedKinEnergy = aTrack.GetKineticEnergy();
                                                   >> 166   }
                                                   >> 167 
                                                   >> 168   itsOK = (itsOK) && G4VParticleChange::CheckIt(aTrack);
                                                   >> 169   return itsOK;
                                                   >> 170 }
                                                   >> 171 
                                                   >> 172 // --------------------------------------------------------------------
 67 G4Step* G4ParticleChangeForLoss::UpdateStepFor    173 G4Step* G4ParticleChangeForLoss::UpdateStepForAlongStep(G4Step* pStep)
 68 {                                                 174 {
 69   const G4StepPoint* pPreStepPoint = pStep->Ge << 
 70   G4StepPoint* pPostStepPoint = pStep->GetPost    175   G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint();
                                                   >> 176   G4StepPoint* pPreStepPoint  = pStep->GetPreStepPoint();
                                                   >> 177   G4Track* pTrack             = pStep->GetTrack();
 71                                                   178 
 72   // accumulate change of the kinetic energy      179   // accumulate change of the kinetic energy
 73   G4double preKinEnergy = pPreStepPoint->GetKi    180   G4double preKinEnergy = pPreStepPoint->GetKineticEnergy();
 74   G4double kinEnergy =                            181   G4double kinEnergy =
 75     pPostStepPoint->GetKineticEnergy() + (prop    182     pPostStepPoint->GetKineticEnergy() + (proposedKinEnergy - preKinEnergy);
 76                                                   183 
 77   pPostStepPoint->SetCharge(currentCharge);    << 184   // update kinetic energy and charge
 78                                                << 185   if(kinEnergy < lowEnergyLimit)
 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   {                                               186   {
 89     pPostStepPoint->SetKineticEnergy(0.0);     << 187     theLocalEnergyDeposit += kinEnergy;
                                                   >> 188     kinEnergy = 0.0;
 90     pPostStepPoint->SetVelocity(0.0);             189     pPostStepPoint->SetVelocity(0.0);
 91   }                                               190   }
                                                   >> 191   else
                                                   >> 192   {
                                                   >> 193     pPostStepPoint->SetCharge(currentCharge);
                                                   >> 194     // calculate velocity
                                                   >> 195     pTrack->SetKineticEnergy(kinEnergy);
                                                   >> 196     pPostStepPoint->SetVelocity(pTrack->CalculateVelocity());
                                                   >> 197     pTrack->SetKineticEnergy(preKinEnergy);
                                                   >> 198   }
                                                   >> 199   pPostStepPoint->SetKineticEnergy(kinEnergy);
 92                                                   200 
 93   if(isParentWeightProposed)                      201   if(isParentWeightProposed)
 94   {                                               202   {
 95     pPostStepPoint->SetWeight(theParentWeight)    203     pPostStepPoint->SetWeight(theParentWeight);
 96   }                                               204   }
 97                                                   205 
 98   pStep->AddTotalEnergyDeposit(theLocalEnergyD    206   pStep->AddTotalEnergyDeposit(theLocalEnergyDeposit);
 99   pStep->AddNonIonizingEnergyDeposit(theNonIon    207   pStep->AddNonIonizingEnergyDeposit(theNonIonizingEnergyDeposit);
100   return pStep;                                   208   return pStep;
101 }                                                 209 }
102                                                   210 
103 // -------------------------------------------    211 // --------------------------------------------------------------------
104 G4Step* G4ParticleChangeForLoss::UpdateStepFor    212 G4Step* G4ParticleChangeForLoss::UpdateStepForPostStep(G4Step* pStep)
105 {                                                 213 {
106   G4StepPoint* pPostStepPoint = pStep->GetPost    214   G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint();
                                                   >> 215   G4Track* pTrack             = pStep->GetTrack();
107                                                   216 
108   pPostStepPoint->SetCharge(currentCharge);       217   pPostStepPoint->SetCharge(currentCharge);
109   pPostStepPoint->SetMomentumDirection(propose    218   pPostStepPoint->SetMomentumDirection(proposedMomentumDirection);
                                                   >> 219   pPostStepPoint->SetKineticEnergy(proposedKinEnergy);
                                                   >> 220   pTrack->SetKineticEnergy(proposedKinEnergy);
110   if(proposedKinEnergy > 0.0)                     221   if(proposedKinEnergy > 0.0)
111   {                                               222   {
112     pPostStepPoint->SetKineticEnergy(proposedK << 223     pPostStepPoint->SetVelocity(pTrack->CalculateVelocity());
113                                                << 
114     // assuming that mass>0, zero mass particl << 
115     pPostStepPoint->SetVelocity(CLHEP::c_light << 
116   }                                               224   }
117   else                                            225   else
118   {                                               226   {
119     pPostStepPoint->SetKineticEnergy(0.0);     << 
120     pPostStepPoint->SetVelocity(0.0);             227     pPostStepPoint->SetVelocity(0.0);
121   }                                               228   }
122   pPostStepPoint->SetPolarization(proposedPola    229   pPostStepPoint->SetPolarization(proposedPolarization);
123                                                   230 
124   if(isParentWeightProposed)                      231   if(isParentWeightProposed)
125   {                                               232   {
126     pPostStepPoint->SetWeight(theParentWeight)    233     pPostStepPoint->SetWeight(theParentWeight);
127   }                                               234   }
128                                                   235 
129   pStep->AddTotalEnergyDeposit(theLocalEnergyD    236   pStep->AddTotalEnergyDeposit(theLocalEnergyDeposit);
130   pStep->AddNonIonizingEnergyDeposit(theNonIon    237   pStep->AddNonIonizingEnergyDeposit(theNonIonizingEnergyDeposit);
131   return pStep;                                   238   return pStep;
132 }                                                 239 }
133                                                   240