G4ParticleChangeForMSC.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$
00028 //
00029 // 
00030 // --------------------------------------------------------------
00031 //      GEANT 4 class implementation file 
00032 //
00033 //      
00034 //      
00035 // ------------------------------------------------------------
00036 //   Implemented for the new scheme                 23 Mar. 1998  H.Kurahige
00037 //   Update for model variant of msc                16 Jan  2004  V.Ivanchenko
00038 // --------------------------------------------------------------
00039 
00040 #include "G4ParticleChangeForMSC.hh"
00041 #include "G4SystemOfUnits.hh"
00042 #include "G4Track.hh"
00043 #include "G4Step.hh"
00044 #include "G4DynamicParticle.hh"
00045 #include "G4ExceptionSeverity.hh"
00046 
00047 G4ParticleChangeForMSC::G4ParticleChangeForMSC()
00048   : G4VParticleChange()
00049 {
00050 #ifdef G4VERBOSE
00051   if (verboseLevel>2) {
00052     G4cout << "G4ParticleChangeForMSC::G4ParticleChangeForMSC() " << G4endl;
00053   }
00054 #endif
00055 }
00056 
00057 G4ParticleChangeForMSC::~G4ParticleChangeForMSC()
00058 {
00059 #ifdef G4VERBOSE
00060   if (verboseLevel>2) {
00061     G4cout << "G4ParticleChangeForMSC::~G4ParticleChangeForMSC() " << G4endl;
00062   }
00063 #endif
00064 }
00065 
00066 G4ParticleChangeForMSC::
00067 G4ParticleChangeForMSC(const G4ParticleChangeForMSC &right)
00068   : G4VParticleChange(right)
00069 {
00070    if (verboseLevel>1) {
00071     G4cout << "G4ParticleChangeForMSC::  copy constructor is called " << G4endl;
00072    }
00073       theMomentumDirection = right.theMomentumDirection;
00074       thePosition = right.thePosition;
00075 }
00076 
00077 // assignment operator
00078 G4ParticleChangeForMSC & G4ParticleChangeForMSC::operator=(
00079                                    const G4ParticleChangeForMSC &right)
00080 {
00081    if (verboseLevel>1) {
00082     G4cout << "G4ParticleChangeForMSC:: assignment operator is called " << G4endl;
00083    }
00084    if (this != &right)
00085    {
00086       theListOfSecondaries = right.theListOfSecondaries;
00087       theSizeOftheListOfSecondaries = right.theSizeOftheListOfSecondaries;
00088       theNumberOfSecondaries = right.theNumberOfSecondaries;
00089       theStatusChange = right.theStatusChange;
00090       theLocalEnergyDeposit = right.theLocalEnergyDeposit;
00091       theSteppingControlFlag = right.theSteppingControlFlag;
00092       theTrueStepLength = right.theTrueStepLength;
00093 
00094       theMomentumDirection = right.theMomentumDirection;
00095       thePosition = right.thePosition;
00096    }
00097    return *this;
00098 }
00099 
00100 //----------------------------------------------------------------
00101 // methods for updating G4Step
00102 //
00103 
00104 G4Step* G4ParticleChangeForMSC::UpdateStepForAlongStep(G4Step* pStep)
00105 {
00106   //  Update the G4Step specific attributes
00107   pStep->SetStepLength(theTrueStepLength);
00108   theStatusChange = pStep->GetTrack()->GetTrackStatus();
00109 
00110   // Multiple scattering calculates the final state of the particle
00111   G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint();
00112 
00113   // update  momentum direction
00114   pPostStepPoint->SetMomentumDirection(theMomentumDirection);
00115 
00116   // update position
00117   pPostStepPoint->SetPosition( thePosition );
00118   return pStep;
00119 }
00120 
00121 G4Step* G4ParticleChangeForMSC::UpdateStepForPostStep(G4Step* pStep)
00122 {
00123   // Multiple scattering calculates the final state of the particle
00124   G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint();
00125 
00126   // update  momentum direction
00127   pPostStepPoint->SetMomentumDirection(theMomentumDirection);
00128 
00129   // update position
00130   pPostStepPoint->SetPosition( thePosition );
00131 
00132   //  Update the G4Step specific attributes
00133   return pStep;
00134 }
00135 
00136 
00137 //----------------------------------------------------------------
00138 // methods for printing messages
00139 //
00140 
00141 void G4ParticleChangeForMSC::DumpInfo() const
00142 {
00143 // use base-class DumpInfo
00144   G4VParticleChange::DumpInfo();
00145 
00146   G4int oldprc = G4cout.precision(3);
00147   G4cout << "        Position - x (mm)   : "
00148        << std::setw(20) << thePosition.x()/mm
00149        << G4endl;
00150   G4cout << "        Position - y (mm)   : "
00151        << std::setw(20) << thePosition.y()/mm
00152        << G4endl;
00153   G4cout << "        Position - z (mm)   : "
00154        << std::setw(20) << thePosition.z()/mm
00155        << G4endl;
00156   G4cout << "        Momentum Direct - x : "
00157        << std::setw(20) << theMomentumDirection.x()
00158        << G4endl;
00159   G4cout << "        Momentum Direct - y : "
00160        << std::setw(20) << theMomentumDirection.y()
00161        << G4endl;
00162   G4cout << "        Momentum Direct - z : "
00163        << std::setw(20) << theMomentumDirection.z()
00164        << G4endl;
00165   G4cout.precision(oldprc);
00166 }
00167 
00168 
00169 G4bool G4ParticleChangeForMSC::CheckIt(const G4Track& aTrack)
00170 {
00171   G4bool    itsOK = true;
00172   G4bool    exitWithError = false;
00173 
00174   G4double  accuracy;
00175 
00176   // check
00177 
00178   // MomentumDirection should be unit vector
00179   accuracy = std::fabs(theMomentumDirection.mag2()-1.0);
00180   if (accuracy > accuracyForWarning) {
00181     itsOK = false;
00182     exitWithError = (accuracy > accuracyForException);
00183 #ifdef G4VERBOSE
00184     G4cout << "  G4ParticleChangeForMSC::CheckIt  : ";
00185     G4cout << "the Momentum Change is not unit vector !!"
00186            << "  Difference:  " << accuracy << G4endl;
00187     G4cout << aTrack.GetDefinition()->GetParticleName()
00188            << " E=" << aTrack.GetKineticEnergy()/MeV
00189            << " pos=" << aTrack.GetPosition().x()/m
00190            << ", " << aTrack.GetPosition().y()/m
00191            << ", " << aTrack.GetPosition().z()/m
00192            <<G4endl;
00193 #endif
00194   }
00195 
00196   // dump out information of this particle change
00197 #ifdef G4VERBOSE
00198   if (!itsOK) DumpInfo();
00199 #endif
00200 
00201   // Exit with error
00202   if (exitWithError) {
00203     G4Exception("G4ParticleChangeForMSC::CheckIt",
00204                 "300",
00205                 EventMustBeAborted,
00206                 "momentum direction was illegal");
00207   }
00208   //correction
00209   if (!itsOK) {
00210     G4double vmag = theMomentumDirection.mag();
00211     theMomentumDirection = (1./vmag)*theMomentumDirection;
00212   }
00213 
00214   itsOK = (itsOK) && G4VParticleChange::CheckIt(aTrack);
00215   return itsOK;
00216 }
00217 
00218 
00219 
00220 

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