ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ParticleData.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ParticleData.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2018 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
10 
11 #include <algorithm>
12 #include <cassert>
13 #include <cstdint>
14 #include <iterator>
15 #include <limits>
16 #include <optional>
17 #include <ostream>
18 
19 #include "Acts/Utilities/Units.hpp"
20 
21 #include "ParticleDataTable.hpp"
22 
23 // Find an element within a data column using sorted pdg numbers as the index.
24 template <typename ColumnContainer>
25 static inline auto findByPdg(int32_t pdg, const ColumnContainer& column)
26  -> std::optional<std::decay_t<decltype(column[0])>> {
27  // should be a static_assert, but that seems to fail on LLVM
28  assert((std::size(column) == kParticlesCount) and "Inconsistent column size");
29 
30  auto beg = std::cbegin(kParticlesPdgNumber);
31  auto end = std::cend(kParticlesPdgNumber);
32  // assumes sorted container of pdg numbers
33  auto pos = std::lower_bound(beg, end, pdg);
34  if (pos == end) {
35  return std::nullopt;
36  }
37  if (*pos != pdg) {
38  return std::nullopt;
39  }
40  return std::make_optional(column[std::distance(beg, pos)]);
41 }
42 
44  const auto q3 = findByPdg(static_cast<int32_t>(pdg), kParticlesThreeCharge);
45  if (q3.has_value()) {
46  // convert three charge to regular charge in native units
47  return (q3.value() / 3.0f) * Acts::UnitConstants::e;
48  } else {
49  // there is no good default charge. clearly mark the missing value.
50  return std::numeric_limits<float>::quiet_NaN();
51  }
52 }
53 
55  const auto mass = findByPdg(static_cast<int32_t>(pdg), kParticlesMassMeV);
56  // for medium- to high-pt, zero mass is a reasonable fall-back.
57  return mass.value_or(0.0f) * Acts::UnitConstants::MeV;
58 }
59 
61  return findByPdg(static_cast<int32_t>(pdg), kParticlesName).value_or("");
62 }
63 
64 std::ostream& Acts::operator<<(std::ostream& os, Acts::PdgParticle pdg) {
65  const auto name = ActsFatras::findName(pdg);
66  os << static_cast<int32_t>(pdg);
67  if (not name.empty()) {
68  os << '|' << name;
69  }
70  return os;
71 }