G4InuclParticle.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 // 20100409  M. Kelsey -- Drop unused string argument from ctors.
00029 // 20110721  M. Kelsey -- Add model ID as optional ctor argument (so subclasses
00030 //              don't have to call SetModel()).
00031 // 20110922  M. Kelsey -- Add stream argument to printParticle() => print()
00032 
00033 #include <cmath>
00034 
00035 #include "G4InuclParticle.hh"
00036 #include "G4ios.hh"
00037 #include "G4SystemOfUnits.hh"
00038 
00039 // Internal constructor only usable by subclasses
00040 G4InuclParticle::G4InuclParticle(G4ParticleDefinition* pd,
00041                                  const G4LorentzVector& mom,
00042                                  G4InuclParticle::Model model)
00043   : modelId(model) {
00044   setDefinition(pd);
00045   setMomentum(mom);
00046 }
00047 
00048 
00049 // Assignment operator for use with std::sort()
00050 G4InuclParticle& G4InuclParticle::operator=(const G4InuclParticle& right) {
00051   pDP = right.pDP;
00052   modelId = right.modelId;
00053 
00054   return *this;
00055 }
00056 
00057 
00058 // Set particle definition allowing for null pointer to erase DynPart content
00059 void G4InuclParticle::setDefinition(G4ParticleDefinition* pd) {
00060   if (pd) pDP.SetDefinition(pd);
00061   else {
00062     static const G4DynamicParticle empty;       // To zero out everything
00063     pDP = empty;
00064   }
00065 }
00066 
00067 
00068 // WARNING!  Bertini code doesn't do four-vectors; repair mass before use!
00069 void G4InuclParticle::setMomentum(const G4LorentzVector& mom) {
00070   G4double mass = getMass();
00071   if (std::fabs(mass-mom.m()) <= 1e-5) 
00072     pDP.Set4Momentum(mom*GeV/MeV);              // From Bertini to G4 units
00073   else
00074     pDP.SetMomentum(mom.vect()*GeV/MeV);        // Don't change current mass!
00075 }
00076 
00077 
00078 // Proper stream output (just calls print())
00079 
00080 std::ostream& operator<<(std::ostream& os, const G4InuclParticle& part) {
00081   part.print(os);
00082   return os;
00083 }
00084 
00085 void G4InuclParticle::print(std::ostream& os) const {
00086   G4LorentzVector mom = getMomentum();
00087   os << " px " << mom.px() << " py " << mom.py() << " pz " << mom.pz()
00088      << " pmod " << mom.rho() << " E " << mom.e()
00089      << " creator model " << modelId;
00090 }
00091 

Generated on Mon May 27 17:48:38 2013 for Geant4 by  doxygen 1.4.7