LCOV - code coverage report
Current view: top level - src - ParticleID.cpp (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 16 30 53.3 %
Date: 2024-04-29 14:43:01 Functions: 4 5 80.0 %

          Line data    Source code
       1             : #include "crpropa/ParticleID.h"
       2             : 
       3             : #include "HepPID/ParticleIDMethods.hh"
       4             : #include "HepPID/ParticleName.hh"
       5             : #include "kiss/convert.h"
       6             : 
       7             : #include <string>
       8             : 
       9             : namespace crpropa {
      10             : 
      11       45289 : int nucleusId(int a, int z) {
      12       45289 :         if (z < 0)
      13           0 :                 throw std::runtime_error(
      14           0 :                                 "crpropa::Nucleus: no nucleus with Z < 0, A=" + kiss::str(a) + " Z="
      15           0 :                                                 + kiss::str(z));
      16       45289 :         if (a < 1)
      17           0 :                 throw std::runtime_error(
      18           0 :                                 "crpropa::Nucleus: no nucleus with A < 1, A=" + kiss::str(a) + " Z="
      19           0 :                                                 + kiss::str(z));
      20       45289 :         if (a < z)
      21           1 :                 throw std::runtime_error(
      22           2 :                                 "crpropa::Nucleus: no nucleus with A < Z, A=" + kiss::str(a) + " Z="
      23           4 :                                                 + kiss::str(z));
      24       45288 :         return 1000000000 + z * 10000 + a * 10;
      25             : }
      26             : 
      27      589687 : int chargeNumber(int id) {
      28      589687 :         return HepPID::Z(id);
      29             : }
      30             : 
      31      377921 : int massNumber(int id) {
      32      377921 :         if (id == 2112)
      33             :                 return 1;
      34      377920 :         return HepPID::A(id);
      35             : }
      36             : 
      37    20563132 : bool isNucleus(int id) {
      38    20563132 :         if (id == 2112)
      39             :                 return true; // consider neutron as nucleus
      40    20563132 :         return HepPID::isNucleus(id);
      41             : }
      42             : 
      43           0 : std::string convertIdToName(int id) {
      44             :         // handle a few extra cases that HepPID doesn't like
      45           0 :         if (id == 1000000010) // neutron
      46           0 :                 id = 2112;
      47           0 :         if (id == -1000000010) // anti-neutron
      48           0 :                 id = -2112;
      49           0 :         if (id == -1000010010) // anti-proton
      50           0 :                 id = -2212;
      51           0 :         return HepPID::particleName(id);
      52             : }
      53             : 
      54             : }

Generated by: LCOV version 1.14