G4ParticleChangeForGamma.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id: G4ParticleChangeForGamma.cc 68795 2013-04-05 13:24:46Z gcosmo $
00028 //
00029 //
00030 // --------------------------------------------------------------
00031 //      GEANT 4 class implementation file
00032 //
00033 // ------------------------------------------------------------
00034 //   15 April 2005 V.Ivanchenko for gamma EM processes
00035 // --------------------------------------------------------------
00036 //
00037 //   Modified::
00038 //   28.08.06 V.Ivanchenko Add access to current track and polarizaion
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 // assignment operator
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   //  create track
00126   G4Track* aTrack = new G4Track(aParticle, currentTrack->GetGlobalTime(),
00127                                            currentTrack->GetPosition());
00128 
00129   //   Touchable handle is copied to keep the pointer
00130   aTrack->SetTouchableHandle(currentTrack->GetTouchableHandle());
00131 
00132   //  add a secondary
00133   G4VParticleChange::AddSecondary(aTrack);
00134 }
00135 
00136 //----------------------------------------------------------------
00137 // method for updating G4Step
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   // update velocity for scattering process and particles with mass
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 // methods for printing messages
00179 //
00180 
00181 void G4ParticleChangeForGamma::DumpInfo() const
00182 {
00183 // use base-class DumpInfo
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   // Energy should not be lager than initial value
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   // dump out information of this particle change
00225 #ifdef G4VERBOSE
00226   if (!itsOK) DumpInfo();
00227 #endif
00228 
00229   // Exit with error
00230   if (exitWithError) {
00231     G4Exception("G4ParticleChangeForGamma::CheckIt",
00232                 "TRACK004",EventMustBeAborted,
00233                 "energy was  illegal");
00234   }
00235 
00236   //correction
00237   if (!itsOK) {
00238     proposedKinEnergy = aTrack.GetKineticEnergy();
00239   }
00240 
00241   itsOK = (itsOK) && G4VParticleChange::CheckIt(aTrack);
00242   return itsOK;
00243 }

Generated on Mon May 27 17:49:15 2013 for Geant4 by  doxygen 1.4.7