Analysis Software
Documentation for sPHENIX simulation 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 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 "Acts/Geometry/GeometryID.hpp"
13 #include "Acts/Utilities/Definitions.hpp"
15 #include "Acts/Utilities/Units.hpp"
16 #include <cmath>
17 
18 namespace Fatras {
19 
21 typedef int pdg_type;
22 
24 typedef unsigned int process_code;
25 
27 typedef unsigned int barcode_type;
28 
29 namespace Test {
30 
32 class Particle {
33 
34 public:
36  Particle() = default;
37 
45  Particle(const Acts::Vector3D &position, const Acts::Vector3D &momentum,
46  double m, double q, pdg_type pdg = 0, barcode_type barcode = 0,
47  double startTime = 0.)
48  : m_position(position), m_momentum(momentum), m_m(m), m_q(q),
49  m_p(momentum.norm()), m_pT(Acts::VectorHelpers::perp(momentum)),
50  m_pdg(pdg), m_barcode(barcode), m_timeStamp(startTime) {
51  m_E = std::sqrt(m_p * m_p + m_m * m_m);
52  m_beta = (m_p / m_E);
53  m_gamma = (m_E / m_m);
54  }
55 
61  void setLimits(double x0Limit, double l0Limit,
62  double timeLimit = std::numeric_limits<double>::max()) {
63  m_limitInX0 = x0Limit;
64  m_limitInL0 = l0Limit;
65  m_timeLimit = timeLimit;
66  }
67 
71  void scatter(Acts::Vector3D nmomentum) {
72  m_momentum = std::move(nmomentum);
74  }
75 
79  void energyLoss(double deltaE) {
80  // particle falls to rest
81  if (m_E - deltaE < m_m) {
82  m_E = m_m;
83  m_p = 0.;
84  m_pT = 0.;
85  m_beta = 0.;
86  m_gamma = 1.;
87  m_momentum = Acts::Vector3D(0., 0., 0.);
88  m_alive = false;
89  }
90  // updatet the parameters
91  m_E -= deltaE;
92  m_p = std::sqrt(m_E * m_E - m_m * m_m);
93  m_momentum = m_p * m_momentum.normalized();
95  m_beta = (m_p / m_E);
96  m_gamma = (m_E / m_m);
97  }
98 
109  bool update(const Acts::Vector3D &position, const Acts::Vector3D &momentum,
110  double deltaPahtX0 = 0., double deltaPahtL0 = 0.,
111  double deltaTime = 0.) {
114  m_p = momentum.norm();
115  if (m_p) {
116  m_pT = Acts::VectorHelpers::perp(momentum);
117  m_E = std::sqrt(m_p * m_p + m_m * m_m);
118  m_timeStamp += deltaTime;
119  m_beta = (m_p / m_E);
120  m_gamma = (m_E / m_m);
121 
122  // set parameters and check limits
123  m_pathInX0 += deltaPahtX0;
124  m_pathInL0 += deltaPahtL0;
125  m_timeStamp += deltaTime;
128  m_alive = false;
129  }
130  }
131  return !m_alive;
132  }
133 
135  const Acts::Vector3D &position() const { return m_position; }
136 
138  const Acts::Vector3D &momentum() const { return m_momentum; }
139 
141  const double p() const { return m_p; }
142 
144  const double pT() const { return m_pT; }
145 
147  const double E() const { return m_E; }
148 
150  const double m() const { return m_m; }
151 
153  const double beta() const { return m_beta; }
154 
156  const double gamma() const { return m_gamma; }
157 
159  const double q() const { return m_q; }
160 
162  const pdg_type pdg() const { return m_pdg; }
163 
165  const barcode_type barcode() const { return m_barcode; }
166 
168  const double pathInX0() const { return m_pathInX0; }
169 
171  const double limitInX0() const { return m_limitInX0; }
172 
174  const double pathInL0() const { return m_limitInX0; }
175 
177  const double limitInL0() const { return m_limitInL0; }
178 
180  operator bool() { return m_alive; }
181 
182 private:
183  Acts::Vector3D m_position = Acts::Vector3D(0., 0., 0.);
184  Acts::Vector3D m_momentum = Acts::Vector3D(0., 0., 0.);
185 
186  double m_m = 0.;
187  double m_E = 0.;
188  double m_q = 0.;
189  double m_beta = 0.;
190  double m_gamma = 1.;
191  double m_p = 0.;
192  double m_pT = 0.;
195 
196  double m_pathInX0 = 0.;
197  double m_limitInX0 = std::numeric_limits<double>::max();
198 
199  double m_pathInL0 = 0.;
200  double m_limitInL0 = std::numeric_limits<double>::max();
201 
202  double m_timeStamp = 0.;
203  double m_timeLimit = std::numeric_limits<double>::max(); // time limit
204 
205  bool m_alive = true;
206 };
207 
208 } // end of namespace Test
209 } // end of namespace Fatras