LCOV - code coverage report
Current view: top level - src - ParticleState.cpp (source / functions) Coverage Total Hit
Test: coverage.info.cleaned Lines: 85.2 % 54 46
Test Date: 2026-06-18 09:49:19 Functions: 94.1 % 17 16

            Line data    Source code
       1              : #include "crpropa/ParticleState.h"
       2              : #include "crpropa/Units.h"
       3              : #include "crpropa/Common.h"
       4              : #include "crpropa/ParticleID.h"
       5              : #include "crpropa/ParticleMass.h"
       6              : 
       7              : #include "HepPID/ParticleIDMethods.hh"
       8              : 
       9              : #include <cstdlib>
      10              : #include <sstream>
      11              : 
      12              : namespace crpropa {
      13              : 
      14     16864046 : ParticleState::ParticleState(int id, double E, Vector3d pos, Vector3d dir): id(0), energy(0.), position(0.), direction(0.), pmass(0.), charge(0.)
      15              : {
      16     16864046 :         setId(id);
      17     16864046 :         setEnergy(E);
      18     16864046 :         setPosition(pos);
      19     16864046 :         setDirection(dir);
      20     16864046 : }
      21              : 
      22     24135284 : void ParticleState::setPosition(const Vector3d &pos) {
      23              :         position = pos;
      24     24135284 : }
      25              : 
      26     15818018 : const Vector3d &ParticleState::getPosition() const {
      27     15818018 :         return position;
      28              : }
      29              : 
      30     17349287 : void ParticleState::setDirection(const Vector3d &dir) {
      31              :         direction = dir / dir.getR();
      32     17349287 : }
      33              : 
      34       493244 : const Vector3d &ParticleState::getDirection() const {
      35       493244 :         return direction;
      36              : }
      37              : 
      38     20339163 : void ParticleState::setEnergy(double newEnergy) {
      39     20339163 :         energy = std::max(0., newEnergy); // prevent negative energies
      40     20339163 : }
      41              : 
      42       590069 : double ParticleState::getEnergy() const {
      43       590069 :         return energy;
      44              : }
      45              : 
      46            1 : double ParticleState::getRigidity() const {
      47            1 :         return fabs(energy / charge);
      48              : }
      49              : 
      50     20338037 : void ParticleState::setId(int newId) {
      51     20338037 :         id = newId;
      52     20338037 :         pmass = particleMass(id);
      53     20338037 :         if (isNucleus(id)) {
      54       146179 :                 charge = chargeNumber(id) * eplus;
      55       146179 :                 if (id < 0)
      56            4 :                         charge *= -1; // anti-nucleus
      57              :         } else {
      58     20191858 :                 charge = HepPID::charge(id) * eplus;
      59              :         }
      60     20338037 : }
      61              : 
      62       211207 : int ParticleState::getId() const {
      63       211207 :         return id;
      64              : }
      65              : 
      66            7 : double ParticleState::getMass() const {
      67            7 :         return pmass;
      68              : }
      69              : 
      70       960340 : double ParticleState::getCharge() const {
      71       960340 :         return charge;
      72              : }
      73              : 
      74         3145 : double ParticleState::getLorentzFactor() const {
      75         3145 :         return energy / (pmass * c_squared);
      76              : }
      77              : 
      78         1474 : void ParticleState::setLorentzFactor(double lf) {
      79         1474 :         lf = std::max(0., lf); // prevent negative Lorentz factors
      80         1474 :         energy = lf * pmass * c_squared;
      81         1474 : }
      82              : 
      83            1 : Vector3d ParticleState::getVelocity() const {
      84            1 :         return direction * c_light;
      85              : }
      86              : 
      87            7 : Vector3d ParticleState::getMomentum() const {
      88            7 :         return direction * (energy / c_light);
      89              : }
      90              : 
      91            0 : std::string ParticleState::getDescription() const {
      92            0 :         std::stringstream ss;
      93            0 :         ss << "Particle " << id << ", ";
      94            0 :         ss << "E = " << energy / EeV << " EeV, ";
      95            0 :         ss << "x = " << position / Mpc << " Mpc, ";
      96            0 :         ss << "p = " << direction;
      97            0 :         return ss.str();
      98            0 : }
      99              : 
     100              : } // namespace crpropa
        

Generated by: LCOV version 2.0-1