2 // ********************************************************************
 
    3 // * License and Disclaimer                                           *
 
    5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
 
    6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
 
    7 // * conditions of the Geant4 Software License,  included in the file *
 
    8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
 
    9 // * include a list of copyright holders.                             *
 
   11 // * Neither the authors of this software system, nor their employing *
 
   12 // * institutes,nor the agencies providing financial support for this *
 
   13 // * work  make  any representation or  warranty, express or implied, *
 
   14 // * regarding  this  software system or assume any liability for its *
 
   15 // * use.  Please see the license in the file  LICENSE  and URL above *
 
   16 // * for the full disclaimer and the limitation of liability.         *
 
   18 // * This  code  implementation is the result of  the  scientific and *
 
   19 // * technical work of the GEANT4 collaboration.                      *
 
   20 // * By using,  copying,  modifying or  distributing the software (or *
 
   21 // * any work based  on the software)  you  agree  to acknowledge its *
 
   22 // * use  in  resulting  scientific  publications,  and indicate your *
 
   23 // * acceptance of all terms of the Geant4 Software license.          *
 
   24 // ********************************************************************
 
   27 // $Id: G4DynamicParticle.icc 72152 2013-07-11 12:49:58Z gcosmo $
 
   30 // ------------------------------------------------------------
 
   31 // GEANT 4 class header file 
 
   33 // History: first implementation, based on object model of
 
   34 //                             17 AUg. 1999   H.Kurashige  
 
   35 // ------------------------------------------------------------
 
   37 extern G4PART_DLL G4ThreadLocal G4Allocator<G4DynamicParticle> *pDynamicParticleAllocator;
 
   39 // ------------------------
 
   41 // ------------------------
 
   43 inline void * G4DynamicParticle::operator new(size_t)
 
   45   if (!pDynamicParticleAllocator) pDynamicParticleAllocator =
 
   46     new G4Allocator<G4DynamicParticle>;
 
   47   return pDynamicParticleAllocator->MallocSingle();
 
   50 inline void G4DynamicParticle::operator delete(void * aDynamicParticle)
 
   52   pDynamicParticleAllocator->FreeSingle((G4DynamicParticle *) aDynamicParticle);
 
   55 // ------------------------
 
   57 // ------------------------
 
   59 inline const G4ElectronOccupancy* G4DynamicParticle::GetElectronOccupancy() const
 
   61   return theElectronOccupancy;
 
   64 inline G4int  G4DynamicParticle::GetTotalOccupancy() const
 
   67   if ( theElectronOccupancy != 0) { 
 
   68     value = theElectronOccupancy->GetTotalOccupancy();
 
   73 inline G4int   G4DynamicParticle::GetOccupancy(G4int orbit) const
 
   76   if ( theElectronOccupancy != 0) { 
 
   77     value = theElectronOccupancy->GetOccupancy(orbit);
 
   82 inline void  G4DynamicParticle::AddElectron(G4int orbit, G4int number )
 
   84   if ( theElectronOccupancy == 0) AllocateElectronOccupancy();
 
   85   if ( theElectronOccupancy != 0) { 
 
   86     G4int n = theElectronOccupancy->AddElectron(orbit, number );
 
   87     theDynamicalCharge -= CLHEP::eplus * n;
 
   88     theDynamicalMass += GetElectronMass() * n;
 
   92 inline void    G4DynamicParticle::RemoveElectron(G4int orbit, G4int number)
 
   94  if ( theElectronOccupancy == 0) AllocateElectronOccupancy();
 
   95  if ( theElectronOccupancy != 0) { 
 
   96     G4int n = theElectronOccupancy->RemoveElectron(orbit, number );
 
   97     theDynamicalCharge += CLHEP::eplus * n;
 
   98     theDynamicalMass -= GetElectronMass() * n;
 
  102 inline G4double G4DynamicParticle::GetCharge() const
 
  104   return theDynamicalCharge;
 
  107 inline void G4DynamicParticle::SetCharge(G4double newCharge)
 
  109   theDynamicalCharge = newCharge;
 
  112 inline void G4DynamicParticle::SetCharge(G4int newCharge)
 
  114   theDynamicalCharge = newCharge*CLHEP::eplus;
 
  117 inline G4double G4DynamicParticle::GetMass() const
 
  119   return theDynamicalMass;
 
  123 inline G4double G4DynamicParticle::GetSpin() const
 
  125   return theDynamicalSpin;
 
  128 inline void  G4DynamicParticle::SetSpin(G4double spin)
 
  130   theDynamicalSpin = spin;
 
  133 inline void  G4DynamicParticle::SetSpin(G4int    spinInUnitOfHalfInteger)
 
  135   theDynamicalSpin =  spinInUnitOfHalfInteger * 0.5;
 
  138 inline G4double G4DynamicParticle::GetMagneticMoment() const
 
  140   return theDynamicalMagneticMoment;
 
  143 inline void  G4DynamicParticle::SetMagneticMoment(G4double magneticMoment)
 
  145    theDynamicalMagneticMoment = magneticMoment;  
 
  148 inline void G4DynamicParticle::SetMass(G4double newMass)
 
  150   theDynamicalMass = newMass;
 
  153 inline const G4ThreeVector& G4DynamicParticle::GetMomentumDirection() const
 
  155  return theMomentumDirection;
 
  158 inline G4ThreeVector G4DynamicParticle::GetMomentum() const
 
  160   G4double pModule = std::sqrt(theKineticEnergy*theKineticEnergy +
 
  161                         2*theKineticEnergy*theDynamicalMass);
 
  162   G4ThreeVector pMomentum(theMomentumDirection.x()*pModule,
 
  163                           theMomentumDirection.y()*pModule,
 
  164                           theMomentumDirection.z()*pModule);
 
  168 inline  G4LorentzVector  G4DynamicParticle::Get4Momentum() const
 
  170   G4double mass      = theDynamicalMass;
 
  171   G4double energy    = theKineticEnergy;
 
  172   G4double momentum  = std::sqrt(energy*energy+2.0*mass*energy);
 
  173   G4LorentzVector    p4( theMomentumDirection.x()*momentum,
 
  174                             theMomentumDirection.y()*momentum,
 
  175                             theMomentumDirection.z()*momentum,
 
  180 inline G4double G4DynamicParticle::GetTotalMomentum() const
 
  182   // The momentum is returned in energy equivalent.
 
  183   return std::sqrt((theKineticEnergy + 2.*theDynamicalMass)* theKineticEnergy);
 
  186 inline G4ParticleDefinition* G4DynamicParticle::GetDefinition() const
 
  188   return const_cast<G4ParticleDefinition*>(theParticleDefinition);
 
  191 inline const G4ParticleDefinition* G4DynamicParticle::GetParticleDefinition() const
 
  193   return const_cast<G4ParticleDefinition*>(theParticleDefinition);
 
  196 inline const G4ThreeVector& G4DynamicParticle::GetPolarization() const
 
  198   return thePolarization;
 
  201 inline G4double G4DynamicParticle::GetProperTime() const
 
  203   return theProperTime;
 
  206 inline G4double G4DynamicParticle::GetTotalEnergy() const
 
  208   return (theKineticEnergy+theDynamicalMass);
 
  211 inline G4double G4DynamicParticle::GetKineticEnergy() const
 
  213   return theKineticEnergy;
 
  216 inline void G4DynamicParticle::SetMomentumDirection(const G4ThreeVector &aDirection)
 
  218   theMomentumDirection = aDirection;
 
  221 inline void G4DynamicParticle::SetMomentumDirection(G4double px, G4double py, G4double pz)
 
  223   theMomentumDirection.setX(px);
 
  224   theMomentumDirection.setY(py);
 
  225   theMomentumDirection.setZ(pz);
 
  229 inline void G4DynamicParticle::SetPolarization(G4double polX, G4double polY, G4double polZ)
 
  231   thePolarization.setX(polX);
 
  232   thePolarization.setY(polY);
 
  233   thePolarization.setZ(polZ);
 
  236 inline void G4DynamicParticle::SetKineticEnergy(G4double aEnergy)
 
  238   theKineticEnergy = aEnergy;
 
  241 inline void G4DynamicParticle::SetProperTime(G4double atime)
 
  243   theProperTime = atime;
 
  246 inline const G4DecayProducts* G4DynamicParticle::GetPreAssignedDecayProducts() const
 
  248   return thePreAssignedDecayProducts;
 
  251 inline void G4DynamicParticle::SetPreAssignedDecayProducts(G4DecayProducts* aDecayProducts)
 
  253  thePreAssignedDecayProducts = aDecayProducts;
 
  256 inline G4double G4DynamicParticle::GetPreAssignedDecayProperTime() const
 
  258   return thePreAssignedDecayTime;
 
  261 inline void G4DynamicParticle::SetPreAssignedDecayProperTime(G4double aTime)
 
  263   thePreAssignedDecayTime = aTime;
 
  267 void G4DynamicParticle::SetVerboseLevel(G4int value)
 
  269    verboseLevel = value;
 
  273 G4int G4DynamicParticle::GetVerboseLevel() const
 
  279 void G4DynamicParticle::SetPrimaryParticle(G4PrimaryParticle* p) 
 
  285 G4PrimaryParticle* G4DynamicParticle::GetPrimaryParticle() const 
 
  287    return primaryParticle;
 
  291 G4int G4DynamicParticle::GetPDGcode() const
 
  293   G4int code = theParticleDefinition->GetPDGEncoding();
 
  294   if(code==0) code = thePDGcode;
 
  299 void G4DynamicParticle::SetPDGcode(G4int c)