Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/Geant4/G4DynamicParticle.icc was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // G4DynamicParticle inline implementation
0027 //
0028 // 17.08.1999 - H.Kurashige
0029 // --------------------------------------------------------------------
0030 
0031 extern G4PART_DLL G4Allocator<G4DynamicParticle>*& pDynamicParticleAllocator();
0032 
0033 // ------------------------
0034 // Inlined operators
0035 // ------------------------
0036 
0037 inline void* G4DynamicParticle::operator new(size_t)
0038 {
0039   if (pDynamicParticleAllocator() == nullptr) {
0040     pDynamicParticleAllocator() = new G4Allocator<G4DynamicParticle>;
0041   }
0042   return pDynamicParticleAllocator()->MallocSingle();
0043 }
0044 
0045 inline void G4DynamicParticle::operator delete(void* aDynamicParticle)
0046 {
0047   pDynamicParticleAllocator()->FreeSingle((G4DynamicParticle*)aDynamicParticle);
0048 }
0049 
0050 // ------------------------
0051 // Inlined functions
0052 // ------------------------
0053 
0054 inline const G4ElectronOccupancy* G4DynamicParticle::GetElectronOccupancy() const
0055 {
0056   return theElectronOccupancy;
0057 }
0058 
0059 inline G4int G4DynamicParticle::GetTotalOccupancy() const
0060 {
0061   return (theElectronOccupancy) != nullptr ? theElectronOccupancy->GetTotalOccupancy() : 0;
0062 }
0063 
0064 inline G4int G4DynamicParticle::GetOccupancy(G4int orbit) const
0065 {
0066   return (theElectronOccupancy) != nullptr ? theElectronOccupancy->GetOccupancy(orbit) : 0;
0067 }
0068 
0069 inline void G4DynamicParticle::AddElectron(G4int orbit, G4int number)
0070 {
0071   if (theElectronOccupancy == nullptr) {
0072     AllocateElectronOccupancy();
0073   }
0074   if (theElectronOccupancy != nullptr) {
0075     G4int n = theElectronOccupancy->AddElectron(orbit, number);
0076     theDynamicalCharge -= CLHEP::eplus * n;
0077     theDynamicalMass += CLHEP::electron_mass_c2 * n;
0078   }
0079 }
0080 
0081 inline void G4DynamicParticle::RemoveElectron(G4int orbit, G4int number)
0082 {
0083   if (theElectronOccupancy == nullptr) {
0084     AllocateElectronOccupancy();
0085   }
0086   if (theElectronOccupancy != nullptr) {
0087     G4int n = theElectronOccupancy->RemoveElectron(orbit, number);
0088     theDynamicalCharge += CLHEP::eplus * n;
0089     theDynamicalMass -= CLHEP::electron_mass_c2 * n;
0090   }
0091 }
0092 
0093 inline G4double G4DynamicParticle::GetCharge() const
0094 {
0095   return theDynamicalCharge;
0096 }
0097 
0098 inline void G4DynamicParticle::SetCharge(G4double newCharge)
0099 {
0100   theDynamicalCharge = newCharge;
0101 }
0102 
0103 inline void G4DynamicParticle::SetCharge(G4int newCharge)
0104 {
0105   theDynamicalCharge = newCharge * CLHEP::eplus;
0106 }
0107 
0108 inline G4double G4DynamicParticle::GetMass() const
0109 {
0110   return theDynamicalMass;
0111 }
0112 
0113 inline void G4DynamicParticle::SetMass(G4double newMass)
0114 {
0115   if (theDynamicalMass != newMass) {
0116     theDynamicalMass = std::max(newMass, 0.0);
0117     theBeta = -1.0;
0118   }
0119 }
0120 
0121 inline G4double G4DynamicParticle::GetSpin() const
0122 {
0123   return theDynamicalSpin;
0124 }
0125 
0126 inline void G4DynamicParticle::SetSpin(G4double spin)
0127 {
0128   theDynamicalSpin = spin;
0129 }
0130 
0131 inline void G4DynamicParticle::SetSpin(G4int spinInUnitOfHalfInteger)
0132 {
0133   theDynamicalSpin = spinInUnitOfHalfInteger * 0.5;
0134 }
0135 
0136 inline G4double G4DynamicParticle::GetMagneticMoment() const
0137 {
0138   return theDynamicalMagneticMoment;
0139 }
0140 
0141 inline void G4DynamicParticle::SetMagneticMoment(G4double magneticMoment)
0142 {
0143   theDynamicalMagneticMoment = magneticMoment;
0144 }
0145 
0146 inline const G4ThreeVector& G4DynamicParticle::GetMomentumDirection() const
0147 {
0148   return theMomentumDirection;
0149 }
0150 
0151 inline G4ThreeVector G4DynamicParticle::GetMomentum() const
0152 {
0153   G4double pModule =
0154     std::sqrt(theKineticEnergy * theKineticEnergy + 2 * theKineticEnergy * theDynamicalMass);
0155   G4ThreeVector pMomentum(theMomentumDirection.x() * pModule, theMomentumDirection.y() * pModule,
0156                           theMomentumDirection.z() * pModule);
0157   return pMomentum;
0158 }
0159 
0160 inline G4LorentzVector G4DynamicParticle::Get4Momentum() const
0161 {
0162   const G4double mass = theDynamicalMass;
0163   const G4double energy = theKineticEnergy;
0164   const G4double momentum = std::sqrt(energy * energy + 2.0 * mass * energy);
0165   G4LorentzVector p4(theMomentumDirection.x() * momentum, theMomentumDirection.y() * momentum,
0166                      theMomentumDirection.z() * momentum, energy + mass);
0167   return p4;
0168 }
0169 
0170 inline G4double G4DynamicParticle::GetTotalMomentum() const
0171 {
0172   // The momentum is returned in energy equivalent
0173   //
0174   return std::sqrt((theKineticEnergy + 2. * theDynamicalMass) * theKineticEnergy);
0175 }
0176 
0177 inline G4ParticleDefinition* G4DynamicParticle::GetDefinition() const
0178 {
0179   return const_cast<G4ParticleDefinition*>(theParticleDefinition);
0180 }
0181 
0182 inline const G4ParticleDefinition* G4DynamicParticle::GetParticleDefinition() const
0183 {
0184   return theParticleDefinition;
0185 }
0186 
0187 inline const G4ThreeVector& G4DynamicParticle::GetPolarization() const
0188 {
0189   return thePolarization;
0190 }
0191 
0192 inline G4double G4DynamicParticle::GetProperTime() const
0193 {
0194   return theProperTime;
0195 }
0196 
0197 inline G4double G4DynamicParticle::GetTotalEnergy() const
0198 {
0199   return (theKineticEnergy + theDynamicalMass);
0200 }
0201 
0202 inline G4double G4DynamicParticle::GetKineticEnergy() const
0203 {
0204   return theKineticEnergy;
0205 }
0206 
0207 inline G4double G4DynamicParticle::GetLogKineticEnergy() const
0208 {
0209   if (theLogKineticEnergy == DBL_MAX) {
0210     theLogKineticEnergy = (theKineticEnergy > 0.) ? G4Log(theKineticEnergy) : LOG_EKIN_MIN;
0211   }
0212   return theLogKineticEnergy;
0213 }
0214 
0215 inline void G4DynamicParticle::SetMomentumDirection(const G4ThreeVector& aDirection)
0216 {
0217   theMomentumDirection = aDirection;
0218 }
0219 
0220 inline void G4DynamicParticle::SetMomentumDirection(G4double px, G4double py, G4double pz)
0221 {
0222   theMomentumDirection.setX(px);
0223   theMomentumDirection.setY(py);
0224   theMomentumDirection.setZ(pz);
0225 }
0226 
0227 inline void G4DynamicParticle::SetPolarization(const G4ThreeVector& vp)
0228 {
0229   thePolarization = vp;
0230 }
0231 
0232 inline void G4DynamicParticle::SetPolarization(G4double polX, G4double polY, G4double polZ)
0233 {
0234   thePolarization.setX(polX);
0235   thePolarization.setY(polY);
0236   thePolarization.setZ(polZ);
0237 }
0238 
0239 inline void G4DynamicParticle::SetKineticEnergy(G4double aEnergy)
0240 {
0241   if (aEnergy != theKineticEnergy) {
0242     theLogKineticEnergy = DBL_MAX;
0243     theKineticEnergy = aEnergy;
0244     theBeta = -1.0;
0245   }
0246 }
0247 
0248 inline void G4DynamicParticle::SetProperTime(G4double atime)
0249 {
0250   theProperTime = atime;
0251 }
0252 
0253 inline const G4DecayProducts* G4DynamicParticle::GetPreAssignedDecayProducts() const
0254 {
0255   return thePreAssignedDecayProducts;
0256 }
0257 
0258 inline void G4DynamicParticle::SetPreAssignedDecayProducts(G4DecayProducts* aDecayProducts)
0259 {
0260   thePreAssignedDecayProducts = aDecayProducts;
0261 }
0262 
0263 inline G4double G4DynamicParticle::GetPreAssignedDecayProperTime() const
0264 {
0265   return thePreAssignedDecayTime;
0266 }
0267 
0268 inline void G4DynamicParticle::SetPreAssignedDecayProperTime(G4double aTime)
0269 {
0270   thePreAssignedDecayTime = aTime;
0271 }
0272 
0273 inline void G4DynamicParticle::SetVerboseLevel(G4int value)
0274 {
0275   verboseLevel = value;
0276 }
0277 
0278 inline G4int G4DynamicParticle::GetVerboseLevel() const
0279 {
0280   return verboseLevel;
0281 }
0282 
0283 inline void G4DynamicParticle::SetPrimaryParticle(G4PrimaryParticle* p)
0284 {
0285   primaryParticle = p;
0286 }
0287 
0288 inline G4PrimaryParticle* G4DynamicParticle::GetPrimaryParticle() const
0289 {
0290   return primaryParticle;
0291 }
0292 
0293 inline G4int G4DynamicParticle::GetPDGcode() const
0294 {
0295   G4int code = theParticleDefinition->GetPDGEncoding();
0296   return (code == 0) ? thePDGcode : code;
0297 }
0298 
0299 inline void G4DynamicParticle::SetPDGcode(G4int c)
0300 {
0301   thePDGcode = c;
0302 }
0303 
0304 inline void G4DynamicParticle::ComputeBeta() const
0305 {
0306   // ultra relativistic particles and particles with mass zero
0307   theBeta = 1.0;
0308 
0309   // other particles
0310   if (theDynamicalMass > 0.0 && theKineticEnergy < 1000 * theDynamicalMass) {
0311     const G4double T = theKineticEnergy / theDynamicalMass;
0312     theBeta = std::sqrt(T * (T + 2.)) / (T + 1.0);
0313   }
0314 }
0315 
0316 inline G4double G4DynamicParticle::GetBeta() const
0317 {
0318   if (theBeta < 0.0) {
0319     ComputeBeta();
0320   }
0321   return theBeta;
0322 }