G4CascadParticle.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 // $Id$
00027 //
00028 // 20100112  M. Kelsey -- Remove G4CascadeMomentum, use G4LorentzVector directly
00029 // 20100114  M. Kelsey -- Replace vector<G4Double> position with G4ThreeVector 
00030 // 20101012  M. Kelsey -- Check for negative d2 in getPathToTheNextZone()
00031 // 20110806  M. Kelsey -- Add fill() function to replicate ctor/op=() action
00032 // 20110922  M. Kelsey -- Follow G4InuclParticle::print(ostream&) migration,
00033 //              Add stream argument to print(), add operator<<().
00034 // 20111017  M. Kelsey -- Add check for zero momentum in path calculation.
00035 
00036 #include "G4CascadParticle.hh"
00037 #include "G4ios.hh"
00038 #include <cmath>
00039 
00040 
00041 // Default constructor produces non-functional object
00042 
00043 G4CascadParticle::G4CascadParticle()
00044   : verboseLevel(0), current_zone(-1), current_path(-1.), movingIn(false),
00045     reflectionCounter(0), reflected(false), generation(-1) {
00046   if (verboseLevel > 3) {
00047     G4cout << " >>> G4CascadParticle::G4CascadParticle" << G4endl;
00048   }
00049 }
00050 
00051 // Analogue to operator=() to support filling vectors w/o temporaries
00052 
00053 void G4CascadParticle::fill(const G4InuclElementaryParticle& particle, 
00054                             const G4ThreeVector& pos, G4int izone,
00055                             G4double cpath, G4int gen) {
00056   if (verboseLevel > 3) G4cout << " >>> G4CascadParticle::fill" << G4endl;
00057 
00058   theParticle = particle;
00059   position = pos;
00060   current_zone = izone;
00061   current_path = cpath;
00062   movingIn = true;
00063   reflectionCounter = 0;
00064   reflected = false;
00065   generation = gen;
00066 }
00067 
00068 
00069 G4double G4CascadParticle::getPathToTheNextZone(G4double rz_in, 
00070                                                 G4double rz_out) {
00071   if (verboseLevel > 3) {
00072     G4cout << " >>> G4CascadParticle::getPathToTheNextZone rz_in " << rz_in
00073            << " rz_out " << rz_out << G4endl;
00074   }
00075 
00076   const G4LorentzVector& mom = getMomentum();
00077 
00078   G4double path = -1.0;
00079   G4double rp = mom.vect().dot(position);
00080   G4double rr = position.mag2();
00081   G4double pp = mom.vect().mag2();
00082 
00083   if (std::abs(pp) < 1e-9) {    // Cut-off for "at rest" is 1 eV momentum
00084     if (verboseLevel > 3) G4cout << " at rest; path length is zero" << G4endl;
00085     return 0.;
00086   }
00087 
00088   G4double ra = rr - rp * rp / pp;
00089   pp = std::sqrt(pp);
00090   G4double ds;
00091   G4double d2;
00092 
00093   if (verboseLevel > 3) {
00094     G4cout << " current_zone " << current_zone << " rr " << rr
00095            << " rp " << rp << " pp " << pp << " ra " << ra << G4endl;
00096   }
00097 
00098   if (current_zone == 0 || rp > 0.0) {
00099     d2 = rz_out * rz_out - ra;
00100     if (d2 > 0.0) {
00101       ds = 1.0;
00102       movingIn = false;
00103     } else {
00104       d2 = rz_in * rz_in - ra;
00105       ds = -1.0;
00106       movingIn = true;
00107     }
00108   } else { 
00109     d2 = rz_in * rz_in - ra;
00110     if (d2 > 0.0) {
00111       ds = -1.0;
00112       movingIn = true;
00113     } else {
00114       d2 = rz_out * rz_out - ra;
00115       ds = 1.0;
00116       movingIn = false;
00117     }
00118   }
00119 
00120   if (verboseLevel > 3) G4cout << " ds " << ds << " d2 " << d2 << G4endl;
00121 
00122   if (d2 < 0.0 && d2 > -1e-6) d2 = 0.;          // Account for round-off
00123 
00124   if (d2 > 0.0) path = ds * std::sqrt(d2) - rp / pp;    // Avoid FPE failure
00125 
00126   return path;    
00127 }
00128 
00129 void G4CascadParticle::propagateAlongThePath(G4double path) {
00130   if (verboseLevel > 3) {
00131     G4cout << " >>> G4CascadParticle::propagateAlongThePath" << G4endl;
00132   }
00133 
00134   position += getMomentum().vect().unit()*path;
00135 }
00136 
00137 
00138 // Proper stream output (just calls print())
00139 
00140 std::ostream& operator<<(std::ostream& os, const G4CascadParticle& part) {
00141   part.print(os);
00142   return os;
00143 }
00144 
00145 void G4CascadParticle::print(std::ostream& os) const {
00146   os << theParticle << G4endl
00147      << " zone " << current_zone << " current_path " << current_path
00148      << " reflectionCounter " << reflectionCounter << G4endl
00149      << " x " << position.x() << " y " << position.y()
00150      << " z " << position.z() << G4endl;
00151 }
00152 

Generated on Mon May 27 17:47:51 2013 for Geant4 by  doxygen 1.4.7