IAP GITLAB

Skip to content
Snippets Groups Projects
Forked from Air Shower Physics / corsika
4132 commits behind the upstream repository.
ParticleProperties.h 1.99 KiB
/**
   @file Particles.h

   Interface to particle properties
 */

#ifndef _include_ParticleProperties_h_
#define _include_ParticleProperties_h_

#include <array>
#include <cstdint>
#include <iostream>
#include <type_traits>

#include <corsika/units/PhysicalConstants.h>
#include <corsika/units/PhysicalUnits.h>

/**
 * @namespace particle
 *
 * The properties of all elementary particles is stored here. The data
 * is taken from the Pythia ParticleData.xml file.
 *
 */

namespace corsika::particles {
  enum class Code : int16_t;

  using PDGCodeType = int16_t;
  using CodeIntType = std::underlying_type<Code>::type;

  // forward declarations to be used in GeneratedParticleProperties
  int16_t constexpr GetElectricChargeNumber(Code const);
  corsika::units::ElectricChargeType constexpr GetElectricCharge(Code const);
  corsika::units::MassType constexpr GetMass(Code const);
  PDGCodeType constexpr GetPDG(Code const);
  std::string const GetName(Code const);

#include <corsika/particles/GeneratedParticleProperties.inc>

  /*!
   * returns mass of particle
   */
  corsika::units::MassType constexpr GetMass(Code const p) {
    return masses[static_cast<CodeIntType const>(p)];
  }

  PDGCodeType constexpr GetPDG(Code const p) {
    return pdg_codes[static_cast<CodeIntType const>(p)];
  }

  /*!
   * returns electric charge of particle / (e/3).
   */
  int16_t constexpr GetElectricChargeNumber(Code const p) {
    return electric_charges[static_cast<CodeIntType const>(p)];
  }

  corsika::units::ElectricChargeType constexpr GetElectricCharge(Code const p) {
    return GetElectricChargeNumber(p) * (corsika::units::constants::e / 3.);
  }

  std::string const GetName(Code const p) {
    return names[static_cast<CodeIntType const>(p)];
  }

  namespace io {

    std::ostream& operator<<(std::ostream& stream, Code const p) {
      return stream << GetName(p);
    }

  } // namespace io

} // namespace corsika::particles

// to inject the operator<< into the root namespace
using namespace corsika::particles::io;

#endif