ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Particle.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Particle.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2018-2020 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 
9 #pragma once
10 
11 #include <cmath>
12 #include <iosfwd>
13 #include <limits>
14 
19 
20 namespace ActsFatras {
21 
23 class Particle {
24  public:
25  using Scalar = double;
28 
30  Particle() = default;
41  Scalar mass)
42  : m_particleId(particleId), m_pdg(pdg), m_charge(charge), m_mass(mass) {}
50  Particle(const Particle &) = default;
51  Particle(Particle &&) = default;
52  Particle &operator=(const Particle &) = default;
53  Particle &operator=(Particle &&) = default;
54 
61  Particle p = *this;
63  return p;
64  }
65 
67  Particle &setProcess(ProcessType proc) { return m_process = proc, *this; }
71  Particle &setPosition4(const Vector4 &pos4) {
72  m_position4 = pos4;
73  return *this;
74  }
77  m_position4.head<3>() = position;
78  m_position4[3] = time;
79  return *this;
80  }
83  m_position4[0] = x;
84  m_position4[1] = y;
85  m_position4[2] = z;
86  m_position4[3] = time;
87  return *this;
88  }
90  Particle &setDirection(const Vector3 &direction) {
91  m_unitDirection = direction;
92  m_unitDirection.normalize();
93  return *this;
94  }
97  m_unitDirection[0] = dx;
98  m_unitDirection[1] = dy;
99  m_unitDirection[2] = dz;
100  m_unitDirection.normalize();
101  return *this;
102  }
106  return *this;
107  }
114  const auto newEnergy = std::hypot(m_mass, m_absMomentum) + delta;
115  if (newEnergy <= m_mass) {
116  m_absMomentum = Scalar(0);
117  } else {
118  m_absMomentum = std::sqrt(newEnergy * newEnergy - m_mass * m_mass);
119  }
120  return *this;
121  }
122 
124  constexpr Barcode particleId() const { return m_particleId; }
126  constexpr ProcessType process() const { return m_process; }
128  constexpr Acts::PdgParticle pdg() const { return m_pdg; }
130  constexpr Scalar charge() const { return m_charge; }
132  constexpr Scalar mass() const { return m_mass; }
133 
137  constexpr const Vector4 &position4() const { return m_position4; }
139  auto position() const { return m_position4.head<3>(); }
141  Scalar time() const { return m_position4[3]; }
145  Vector4 momentum4() const {
146  Vector4 mom4;
147  // stored direction is always normalized
148  mom4[0] = m_absMomentum * m_unitDirection[0];
149  mom4[1] = m_absMomentum * m_unitDirection[1];
150  mom4[2] = m_absMomentum * m_unitDirection[2];
151  mom4[3] = energy();
152  return mom4;
153  }
155  const Vector3 &unitDirection() const { return m_unitDirection; }
158  return m_absMomentum * m_unitDirection.head<2>().norm();
159  }
161  constexpr Scalar absMomentum() const { return m_absMomentum; }
163  Scalar energy() const { return std::hypot(m_mass, m_absMomentum); }
164 
166  constexpr operator bool() const { return Scalar(0) < m_absMomentum; }
168  constexpr bool operator!() const { return m_absMomentum <= Scalar(0); }
169 
174  constexpr Particle &setMaterialPassed(Scalar pathX0, Scalar pathL0) {
175  m_pathX0 = pathX0;
176  m_pathL0 = pathL0;
177  return *this;
178  }
183  constexpr Particle &setMaterialLimits(Scalar limitX0, Scalar limitL0) {
184  m_limitX0 = limitX0;
185  m_limitL0 = limitL0;
186  return *this;
187  }
189  constexpr Scalar pathInX0() const { return m_pathX0; }
191  constexpr Scalar pathInL0() const { return m_pathL0; }
193  constexpr Scalar pathLimitX0() const { return m_limitX0; }
195  constexpr Scalar pathLimitL0() const { return m_limitL0; }
196 
197  private:
198  // identity, i.e. things that do not change over the particle lifetime.
205  // Particle charge and mass.
208  // kinematics, i.e. things that change over the particle lifetime.
209  Vector3 m_unitDirection = Vector3::UnitZ();
211  Vector4 m_position4 = Vector4::Zero();
212  // simulation-specific X0/L0 information and limits
213  // these values are here to simplify the simulation of (nuclear) interactions.
214  // instead of checking at every surface whether an interaction should occur we
215  // can draw an overall limit once. the relevant interaction only needs to
216  // be executed once the limit is reached.
217  // this information is not really particle-specific and should probably be
218  // handled separately. for now, storing it directly here is the simplest
219  // solution.
224 };
225 
226 std::ostream &operator<<(std::ostream &os, const Particle &particle);
227 
228 } // namespace ActsFatras