Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:09:09

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2018 CERN for the benefit of the Acts project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/Geometry/GeometryID.hpp"
0012 #include "Acts/Surfaces/Surface.hpp"
0013 #include "Acts/Utilities/Definitions.hpp"
0014 #include "Acts/Utilities/Helpers.hpp"
0015 #include "Acts/Utilities/Units.hpp"
0016 #include <cmath>
0017 
0018 namespace Fatras {
0019 
0020 /// Typedef the pdg code
0021 typedef int pdg_type;
0022 
0023 /// Typedef the process code
0024 typedef unsigned int process_code;
0025 
0026 /// Typedef barcode
0027 typedef unsigned int barcode_type;
0028 
0029 namespace Test {
0030 
0031 /// @brief Particle for testing acts-fatras core functionality
0032 class Particle {
0033 
0034 public:
0035   /// Default
0036   Particle() = default;
0037 
0038   /// @brief Construct a particle consistently
0039   ///
0040   /// @param pposition The particle position at construction
0041   /// @param pmomentum The particle momentum at construction
0042   /// @param pm The particle mass
0043   /// @param pq The partilce charge
0044   /// @param pbarcode The particle barcode
0045   Particle(const Acts::Vector3D &position, const Acts::Vector3D &momentum,
0046            double m, double q, pdg_type pdg = 0, barcode_type barcode = 0,
0047            double startTime = 0.)
0048       : m_position(position), m_momentum(momentum), m_m(m), m_q(q),
0049         m_p(momentum.norm()), m_pT(Acts::VectorHelpers::perp(momentum)),
0050         m_pdg(pdg), m_barcode(barcode), m_timeStamp(startTime) {
0051     m_E = std::sqrt(m_p * m_p + m_m * m_m);
0052     m_beta = (m_p / m_E);
0053     m_gamma = (m_E / m_m);
0054   }
0055 
0056   /// @brief Set the limits
0057   ///
0058   /// @param x0Limit the limit in X0 to be passed
0059   /// @param l0Limit the limit in L0 to be passed
0060   /// @param timeLimit the readout time limit to be passed
0061   void setLimits(double x0Limit, double l0Limit,
0062                  double timeLimit = std::numeric_limits<double>::max()) {
0063     m_limitInX0 = x0Limit;
0064     m_limitInL0 = l0Limit;
0065     m_timeLimit = timeLimit;
0066   }
0067 
0068   /// @brief Update the particle with applying energy loss
0069   ///
0070   /// @param deltaE is the energy loss to be applied
0071   void scatter(Acts::Vector3D nmomentum) {
0072     m_momentum = std::move(nmomentum);
0073     m_pT = Acts::VectorHelpers::perp(m_momentum);
0074   }
0075 
0076   /// @brief Update the particle with applying energy loss
0077   ///
0078   /// @param deltaE is the energy loss to be applied
0079   void energyLoss(double deltaE) {
0080     // particle falls to rest
0081     if (m_E - deltaE < m_m) {
0082       m_E = m_m;
0083       m_p = 0.;
0084       m_pT = 0.;
0085       m_beta = 0.;
0086       m_gamma = 1.;
0087       m_momentum = Acts::Vector3D(0., 0., 0.);
0088       m_alive = false;
0089     }
0090     // updatet the parameters
0091     m_E -= deltaE;
0092     m_p = std::sqrt(m_E * m_E - m_m * m_m);
0093     m_momentum = m_p * m_momentum.normalized();
0094     m_pT = Acts::VectorHelpers::perp(m_momentum);
0095     m_beta = (m_p / m_E);
0096     m_gamma = (m_E / m_m);
0097   }
0098 
0099   /// @brief Update the particle with a new position and momentum,
0100   /// this corresponds to a step update
0101   ///
0102   /// @param position New position after update
0103   /// @param momentum New momentum after update
0104   /// @param deltaPathX0 passed since last step
0105   /// @param deltaPathL0 passed since last step
0106   /// @param deltaTime The time elapsed
0107   ///
0108   /// @return break condition
0109   bool update(const Acts::Vector3D &position, const Acts::Vector3D &momentum,
0110               double deltaPahtX0 = 0., double deltaPahtL0 = 0.,
0111               double deltaTime = 0.) {
0112     m_position = position;
0113     m_momentum = momentum;
0114     m_p = momentum.norm();
0115     if (m_p) {
0116       m_pT = Acts::VectorHelpers::perp(momentum);
0117       m_E = std::sqrt(m_p * m_p + m_m * m_m);
0118       m_timeStamp += deltaTime;
0119       m_beta = (m_p / m_E);
0120       m_gamma = (m_E / m_m);
0121 
0122       // set parameters and check limits
0123       m_pathInX0 += deltaPahtX0;
0124       m_pathInL0 += deltaPahtL0;
0125       m_timeStamp += deltaTime;
0126       if (m_pathInX0 >= m_limitInX0 || m_pathInL0 >= m_limitInL0 ||
0127           m_timeStamp > m_timeLimit) {
0128         m_alive = false;
0129       }
0130     }
0131     return !m_alive;
0132   }
0133 
0134   /// @brief Access methods: position
0135   const Acts::Vector3D &position() const { return m_position; }
0136 
0137   /// @brief Access methods: momentum
0138   const Acts::Vector3D &momentum() const { return m_momentum; }
0139 
0140   /// @brief Access methods: p
0141   const double p() const { return m_p; }
0142 
0143   /// @brief Access methods: pT
0144   const double pT() const { return m_pT; }
0145 
0146   /// @brief Access methods: E
0147   const double E() const { return m_E; }
0148 
0149   /// @brief Access methods: m
0150   const double m() const { return m_m; }
0151 
0152   /// @brief Access methods: beta
0153   const double beta() const { return m_beta; }
0154 
0155   /// @brief Access methods: gamma
0156   const double gamma() const { return m_gamma; }
0157 
0158   /// @brief Access methods: charge
0159   const double q() const { return m_q; }
0160 
0161   /// @brief Access methods: pdg code
0162   const pdg_type pdg() const { return m_pdg; }
0163 
0164   /// @brief Access methods: barcode
0165   const barcode_type barcode() const { return m_barcode; }
0166 
0167   /// @brief Access methods: path/X0
0168   const double pathInX0() const { return m_pathInX0; }
0169 
0170   /// @brief Access methods: limit/X0
0171   const double limitInX0() const { return m_limitInX0; }
0172 
0173   /// @brief Access methods: pdg code
0174   const double pathInL0() const { return m_limitInX0; }
0175 
0176   /// @brief Access methods: barcode
0177   const double limitInL0() const { return m_limitInL0; }
0178 
0179   /// @brief boolean operator indicating the particle to be alive
0180   operator bool() { return m_alive; }
0181 
0182 private:
0183   Acts::Vector3D m_position = Acts::Vector3D(0., 0., 0.); //!< kinematic info
0184   Acts::Vector3D m_momentum = Acts::Vector3D(0., 0., 0.); //!< kinematic info
0185 
0186   double m_m = 0.;            //!< particle mass
0187   double m_E = 0.;            //!< total energy
0188   double m_q = 0.;            //!< the charge
0189   double m_beta = 0.;         //!< relativistic beta factor
0190   double m_gamma = 1.;        //!< relativistic gamma factor
0191   double m_p = 0.;            //!< momentum magnitude
0192   double m_pT = 0.;           //!< transverse momentum magnitude
0193   pdg_type m_pdg = 0;         //!< pdg code of the particle
0194   barcode_type m_barcode = 0; //!< barcode of the particle
0195 
0196   double m_pathInX0 = 0.; //!< passed path in X0
0197   double m_limitInX0 = std::numeric_limits<double>::max(); //!< path limit in X0
0198 
0199   double m_pathInL0 = 0.; //!< passed path in L0
0200   double m_limitInL0 = std::numeric_limits<double>::max(); //!< path limit in X0
0201 
0202   double m_timeStamp = 0.; //!< passed time elapsed
0203   double m_timeLimit = std::numeric_limits<double>::max(); // time limit
0204 
0205   bool m_alive = true; //!< the particle is alive
0206 };
0207 
0208 } // end of namespace Test
0209 } // end of namespace Fatras