G4DynamicParticle.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 //      History: first implementation, based on object model of
00034 //      2nd December 1995, G.Cosmo
00035 //      ---------------- G4DynamicParticle  ----------------
00036 //      first implementation by Makoto Asai, 29 January 1996
00037 //      revised by G.Cosmo, 29 February 1996
00038 //      revised by H.Kurashige 06 May 1996
00039 //      revised by Hisaya Kurashige, 27 July 1996
00040 //         modify thePreAssignedDecayProducts
00041 //         add   void SetMomentum(G4ThreeVector &momentum)
00042 //         add   void Set4Momentum(G4LorentzVector &momentum)
00043 //         add   G4DynamicParticle(G4ParticleDefinition * aParticleDefinition,
00044 //                                 G4LorentzVector &p4vector)
00045 //      revised by Hisaya Kurashige, 19 Oct 1996
00046 //         add    theKillProcess
00047 //         add    ProperTime
00048 //      revised by Hisaya Kurashige, 26 Mar 1997
00049 //         modify destructor
00050 //      revised by Hisaya Kurashige, 05 June 1997
00051 //         modify DumpInfo()
00052 //      revised by Hisaya Kurashige, 5  June 1998
00053 //         remove    theKillProcess
00054 //      revised by Hisaya Kurashige, 5  Mar 2001
00055 //         fixed  SetDefinition()
00056 //      revised by V.Ivanchenko,    12 June 2003
00057 //         fixed problem of massless particles
00058 //      revised by V.Ivanchenko,    18 June 2003
00059 //         take into account the case of virtual photons
00060 //      revised by M.Kelsey         12 May 2010
00061 //         ensure that all constructors initialize all data members
00062 //--------------------------------------------------------------
00063 
00064 #include "G4DynamicParticle.hh"
00065 #include "G4PhysicalConstants.hh"
00066 #include "G4SystemOfUnits.hh"
00067 #include "G4DecayProducts.hh"
00068 #include "G4LorentzVector.hh"
00069 #include "G4ParticleDefinition.hh"
00070 #include "G4ParticleTable.hh"
00071 #include "G4IonTable.hh"
00072 #include "G4PrimaryParticle.hh"
00073 
00074 G4Allocator<G4DynamicParticle> aDynamicParticleAllocator;
00075 
00076 static const G4double EnergyMomentumRelationAllowance = keV;
00077 
00079 G4DynamicParticle::G4DynamicParticle():
00080                    theMomentumDirection(0.0,0.0,1.0),
00081                    theParticleDefinition(0),
00082                    theKineticEnergy(0.0),
00083                    theProperTime(0.0),
00084                    theDynamicalMass(0.0),
00085                    theDynamicalCharge(0.0),
00086                    theDynamicalSpin(0.0),
00087                    theDynamicalMagneticMoment(0.0),
00088                    theElectronOccupancy(0),
00089                    thePreAssignedDecayProducts(0),
00090                    thePreAssignedDecayTime(-1.0),
00091                    verboseLevel(1),
00092                    primaryParticle(0),
00093                    thePDGcode(0) {}
00094 
00096 // -- constructors ----
00098 G4DynamicParticle::G4DynamicParticle(const G4ParticleDefinition * aParticleDefinition,
00099                                      const G4ThreeVector& aMomentumDirection,
00100                                      G4double aKineticEnergy):
00101                    theMomentumDirection(aMomentumDirection),
00102                    theParticleDefinition(aParticleDefinition),
00103                    theKineticEnergy(aKineticEnergy),
00104                    theProperTime(0.0),
00105                    theDynamicalMass(aParticleDefinition->GetPDGMass()),
00106                    theDynamicalCharge(aParticleDefinition->GetPDGCharge()),
00107                    theDynamicalSpin(aParticleDefinition->GetPDGSpin()),
00108                    theDynamicalMagneticMoment(aParticleDefinition->GetPDGMagneticMoment()),
00109                    theElectronOccupancy(0),
00110                    thePreAssignedDecayProducts(0),
00111                    thePreAssignedDecayTime(-1.0),
00112                    verboseLevel(1),
00113                    primaryParticle(0),
00114                    thePDGcode(0) {}
00115 
00117 G4DynamicParticle::G4DynamicParticle(const G4ParticleDefinition * aParticleDefinition,
00118                                      const G4ThreeVector& aParticleMomentum):
00119                    theParticleDefinition(aParticleDefinition),
00120                    theKineticEnergy(0.0),
00121                    theProperTime(0.0),
00122                    theDynamicalMass(aParticleDefinition->GetPDGMass()),
00123                    theDynamicalCharge(aParticleDefinition->GetPDGCharge()),
00124                    theDynamicalSpin(aParticleDefinition->GetPDGSpin()),
00125                    theDynamicalMagneticMoment(aParticleDefinition->GetPDGMagneticMoment()),
00126                    theElectronOccupancy(0),
00127                    thePreAssignedDecayProducts(0),
00128                    thePreAssignedDecayTime(-1.0),
00129                    verboseLevel(1),
00130                    primaryParticle(0),
00131                    thePDGcode(0)
00132 {
00133   // 3-dim momentum is given
00134   SetMomentum(aParticleMomentum);
00135 }
00136 
00138 G4DynamicParticle::G4DynamicParticle(const G4ParticleDefinition * aParticleDefinition,
00139                                      const G4LorentzVector   &aParticleMomentum):
00140                    theParticleDefinition(aParticleDefinition),
00141                    theKineticEnergy(0.0),
00142                    theProperTime(0.0),
00143                    theDynamicalMass(aParticleDefinition->GetPDGMass()),
00144                    theDynamicalCharge(aParticleDefinition->GetPDGCharge()),
00145                    theDynamicalSpin(aParticleDefinition->GetPDGSpin()),
00146                    theDynamicalMagneticMoment(aParticleDefinition->GetPDGMagneticMoment()),
00147                    theElectronOccupancy(0),
00148                    thePreAssignedDecayProducts(0),
00149                    thePreAssignedDecayTime(-1.0),
00150                    verboseLevel(1),
00151                    primaryParticle(0),
00152                    thePDGcode(0)
00153 {
00154   // 4-momentum vector (Lorentz vecotr) is given
00155   Set4Momentum(aParticleMomentum);
00156 }
00157 
00158 G4DynamicParticle::G4DynamicParticle(const G4ParticleDefinition * aParticleDefinition,
00159                                      G4double totalEnergy,
00160                                      const G4ThreeVector &aParticleMomentum):
00161                    theParticleDefinition(aParticleDefinition),
00162                    theKineticEnergy(0.0),
00163                    theProperTime(0.0),
00164                    theDynamicalMass(aParticleDefinition->GetPDGMass()),
00165                    theDynamicalCharge(aParticleDefinition->GetPDGCharge()),
00166                    theDynamicalSpin(aParticleDefinition->GetPDGSpin()),
00167                    theDynamicalMagneticMoment(aParticleDefinition->GetPDGMagneticMoment()),
00168                    theElectronOccupancy(0),
00169                    thePreAssignedDecayProducts(0),
00170                    thePreAssignedDecayTime(-1.0),
00171                    verboseLevel(1),
00172                    primaryParticle(0),
00173                    thePDGcode(0)
00174 {
00175   // total energy and 3-dim momentum are given
00176   G4double pModule2 = aParticleMomentum.mag2();
00177   if (pModule2>0.0) {
00178     G4double mass2 = totalEnergy*totalEnergy - pModule2;
00179     if(mass2 < EnergyMomentumRelationAllowance*EnergyMomentumRelationAllowance) {
00180       theDynamicalMass = 0.;
00181       SetMomentumDirection(aParticleMomentum.unit());
00182       SetKineticEnergy(totalEnergy);
00183     } else {
00184       theDynamicalMass = std::sqrt(mass2);
00185       SetMomentum(aParticleMomentum);
00186     }
00187   } else {
00188     SetMomentumDirection(1.0,0.0,0.0);
00189     SetKineticEnergy(0.0);
00190   }
00191 }
00192 
00194 G4DynamicParticle::G4DynamicParticle(const G4DynamicParticle &right):
00195   theMomentumDirection(right.theMomentumDirection),
00196   theParticleDefinition(right.theParticleDefinition),
00197   thePolarization(right.thePolarization),
00198   theKineticEnergy(right.theKineticEnergy),
00199   theProperTime(0.0),
00200   theDynamicalMass(right.theDynamicalMass),
00201   theDynamicalCharge(right.theDynamicalCharge),
00202   theDynamicalSpin(right.theDynamicalSpin),
00203   theDynamicalMagneticMoment(right.theDynamicalMagneticMoment),
00204   theElectronOccupancy(0),
00205   thePreAssignedDecayProducts(0),       // Do not copy preassignedDecayProducts
00206   thePreAssignedDecayTime(-1.0),
00207   verboseLevel(right.verboseLevel),
00208   primaryParticle(right.primaryParticle),
00209   thePDGcode(right.thePDGcode)
00210 {
00211   if (right.theElectronOccupancy != 0) {
00212       theElectronOccupancy =
00213         new G4ElectronOccupancy(*right.theElectronOccupancy);
00214   }
00215 }
00216 
00218 // -- destructor ----
00220 G4DynamicParticle::~G4DynamicParticle() {
00221 
00222   //  delete thePreAssignedDecayProducts
00223   if (thePreAssignedDecayProducts != 0) delete thePreAssignedDecayProducts;
00224   thePreAssignedDecayProducts = 0;
00225 
00226   if (theElectronOccupancy != 0) delete theElectronOccupancy;
00227   theElectronOccupancy =0;
00228 }
00229 
00230 
00232 // -- operators ----
00234 G4DynamicParticle & G4DynamicParticle::operator=(const G4DynamicParticle &right)
00235 {
00236   if (this != &right) {
00237     theMomentumDirection = right.theMomentumDirection;
00238     theParticleDefinition = right.theParticleDefinition;
00239     thePolarization = right.thePolarization;
00240     theKineticEnergy = right.theKineticEnergy;
00241     theProperTime = right.theProperTime;
00242 
00243     theDynamicalMass = right.theDynamicalMass;
00244     theDynamicalCharge = right.theDynamicalCharge;
00245     theDynamicalSpin = right.theDynamicalSpin;
00246     theDynamicalMagneticMoment = right.theDynamicalMagneticMoment;
00247 
00248     if (theElectronOccupancy != 0) delete theElectronOccupancy;
00249     if (right.theElectronOccupancy != 0){
00250       theElectronOccupancy =
00251              new G4ElectronOccupancy(*right.theElectronOccupancy);
00252     } else {
00253       theElectronOccupancy = 0;
00254     }
00255 
00256     // thePreAssignedDecayProducts must not be copied.
00257     thePreAssignedDecayProducts = 0;
00258     thePreAssignedDecayTime = -1.0;
00259 
00260     verboseLevel = right.verboseLevel;
00261 
00262     // Primary particle information must be preserved
00263     //*** primaryParticle = right.primaryParticle;
00264 
00265     thePDGcode = right.thePDGcode;
00266   }
00267   return *this;
00268 }
00269 
00271 void G4DynamicParticle::SetDefinition(const G4ParticleDefinition * aParticleDefinition)
00272 {
00273   // remove preassigned decay
00274   if (thePreAssignedDecayProducts != 0) {
00275 #ifdef G4VERBOSE
00276     if (verboseLevel>0) {
00277       G4cerr << " G4DynamicParticle::SetDefinition()::"
00278              << "!!! Pre-assigned decay products is attached !!!! " << G4endl;
00279       G4cerr << "!!! New Definition is " << aParticleDefinition->GetParticleName() 
00280              << " !!! " << G4endl;
00281       G4cerr << "!!! Pre-assigned decay products will be deleted !!!! " << G4endl;
00282     }
00283 #endif
00284     delete thePreAssignedDecayProducts;
00285   }
00286   thePreAssignedDecayProducts = 0;
00287 
00288   theParticleDefinition = aParticleDefinition;
00289 
00290   // set Dynamic mass/chrge
00291   theDynamicalMass = theParticleDefinition->GetPDGMass();
00292   theDynamicalCharge = theParticleDefinition->GetPDGCharge();
00293   theDynamicalSpin = theParticleDefinition->GetPDGSpin();
00294   theDynamicalMagneticMoment = theParticleDefinition->GetPDGMagneticMoment();
00295 
00296   // Set electron orbits
00297   if (theElectronOccupancy != 0) delete theElectronOccupancy;
00298   theElectronOccupancy =0;
00299   //AllocateElectronOccupancy();
00300 
00301 }
00302 
00304 G4int G4DynamicParticle::operator==(const G4DynamicParticle &right) const
00305 {
00306   return (this == (G4DynamicParticle *) &right);
00307 }
00308 
00310 G4int G4DynamicParticle::operator!=(const G4DynamicParticle &right) const
00311 {
00312   return (this != (G4DynamicParticle *) &right);
00313 }
00314 
00315 
00316 
00318 // -- AllocateElectronOccupancy --
00320 void  G4DynamicParticle::AllocateElectronOccupancy()
00321 {
00322   const G4ParticleDefinition* particle = GetDefinition();
00323 
00324   if (G4IonTable::IsIon(particle)) {
00325     // Only ions can have ElectronOccupancy
00326     theElectronOccupancy = new G4ElectronOccupancy();
00327 
00328   } else {
00329     theElectronOccupancy = 0;
00330 
00331   }
00332 }
00333 
00335 // -- methods for setting Energy/Momentum  --
00337 void G4DynamicParticle::SetMomentum(const G4ThreeVector &momentum)
00338 {
00339   G4double pModule2 = momentum.mag2();
00340   if (pModule2>0.0) {
00341     G4double mass = theDynamicalMass;
00342     SetMomentumDirection(momentum.unit());
00343     SetKineticEnergy(std::sqrt(pModule2 + mass*mass)-mass);
00344   } else {
00345     SetMomentumDirection(1.0,0.0,0.0);
00346     SetKineticEnergy(0.0);
00347   }
00348 }
00349 
00351 void G4DynamicParticle::Set4Momentum(const G4LorentzVector &momentum )
00352 {
00353   G4double pModule2 = momentum.vect().mag2();
00354   if (pModule2>0.0) {
00355     SetMomentumDirection(momentum.vect().unit());
00356     G4double totalenergy = momentum.t();
00357     G4double mass2 = totalenergy*totalenergy - pModule2;
00358     if(mass2 < EnergyMomentumRelationAllowance*EnergyMomentumRelationAllowance) {
00359       theDynamicalMass = 0.;
00360       SetKineticEnergy(totalenergy);
00361     } else {
00362       theDynamicalMass = std::sqrt(mass2);
00363       SetKineticEnergy(totalenergy-theDynamicalMass);
00364     }
00365   } else {
00366     SetMomentumDirection(1.0,0.0,0.0);
00367     SetKineticEnergy(0.0);
00368   }
00369 }
00370 
00371 
00373 //  --- Dump Information --
00375 #ifdef G4VERBOSE
00376 void G4DynamicParticle::DumpInfo(G4int mode) const
00377 {
00378   if (theParticleDefinition == 0) {
00379     G4cout << " G4DynamicParticle::DumpInfo():: !!!Particle type not defined !!!! " << G4endl;
00380   } else {
00381     G4cout << " Particle type - " << theParticleDefinition->GetParticleName() << G4endl
00382          << "   mass:        " << GetMass()/GeV <<  "[GeV]" <<G4endl
00383          << "   charge:      " << GetCharge()/eplus <<  "[e]" <<G4endl
00384          << "   Direction x: " << GetMomentumDirection().x() << ", y: "
00385          << GetMomentumDirection().y() << ", z: "
00386                              << GetMomentumDirection().z() << G4endl
00387          << "   Total Momentum = " << GetTotalMomentum() /GeV << "[GeV]" << G4endl
00388          << "   Momentum: "    << GetMomentum().x() /GeV << "[GeV]" << ", y: "
00389                                << GetMomentum().y() /GeV << "[GeV]" << ", z: "
00390                                << GetMomentum().z() /GeV << "[GeV]" << G4endl
00391          << "   Total Energy   = " << GetTotalEnergy()/GeV << "[GeV]"  << G4endl
00392          << "   Kinetic Energy = " << GetKineticEnergy() /GeV << "[GeV]" << G4endl
00393          << " MagneticMoment  [MeV/T]: " << GetMagneticMoment()/MeV*tesla << G4endl
00394          << "   ProperTime     = " << GetProperTime() /ns <<  "[ns]" << G4endl;
00395 
00396     if (mode>0) {
00397       if( theElectronOccupancy != 0) {
00398         theElectronOccupancy->DumpInfo();
00399       }
00400     }
00401   }
00402 }
00403 #else
00404 void G4DynamicParticle::DumpInfo(G4int) const
00405 {
00406   return;
00407 }
00408 #endif
00409 
00411 G4double  G4DynamicParticle::GetElectronMass() const
00412 {
00413   static G4double electronMass = 0.0;
00414 
00415   // check if electron exits and get the mass
00416   if (electronMass<=0.0) {
00417     G4ParticleDefinition* electron = G4ParticleTable::GetParticleTable()->FindParticle("e-");
00418     if (electron == 0) {
00419       G4Exception("G4DynamicParticle::GetElectronMass()","PART021",
00420                   FatalException,"G4DynamicParticle: G4Electron is not defined !!");
00421     }
00422     electronMass = electron->GetPDGMass();
00423   }
00424 
00425   return electronMass;
00426 }

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