|
|
|||
File indexing completed on 2026-04-17 07:46:17
0001 // This file is part of the ACTS project. 0002 // 0003 // Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/. 0008 0009 #pragma once 0010 0011 #include <cassert> 0012 #include <cmath> 0013 0014 namespace Acts { 0015 0016 /// @ingroup eventdata 0017 /// @defgroup eventdata-charge Charge hypothesis for track reconstruction 0018 /// 0019 /// Track parameters store a single coefficient that describes charge and 0020 /// momentum. This is either charge/momentum or 1/momentum, but the 0021 /// interpretation depends on what type of particle is described. In this code 0022 /// base this coefficient is always referred to as `qOverP` (or 0023 /// charge-over-momentum) even for uncharged particles. The following types are 0024 /// used to restrict the particle charge magnitude (at compile time) and support 0025 /// the umambigous extraction of charge and absolute momentum from said track 0026 /// parameter coefficient. 0027 /// 0028 /// All types are designed to be interchangeable. Each one can be 0029 /// constructed with the input charge magnitude 0030 /// 0031 /// ```cpp 0032 /// ChargeHypothesis c(1_e); 0033 /// ``` 0034 /// 0035 /// and can then be used to extract the charge value 0036 /// 0037 /// ```cpp 0038 /// auto q = c.extractCharge(qOverP); 0039 /// ``` 0040 /// 0041 /// or the absolute momentum 0042 /// 0043 /// ```cpp 0044 /// auto p = c.extractMomentum(qOverP); 0045 /// ``` 0046 /// 0047 /// from the charge-over-momentum track parameter. 0048 /// 0049 /// @{ 0050 0051 /// Charge and momentum interpretation for arbitrarily charged particles. 0052 /// 0053 /// Only a charge magnitude identical to zero is interpreted as representing a 0054 /// neutral particle. This avoids ambiguities that might arise from using an 0055 /// approximate comparison with an arbitrary epsilon. 0056 class ChargeHypothesis final { 0057 public: 0058 /// Construct with the magnitude of the input charge. 0059 /// @param absoluteCharge The absolute value of the charge magnitude 0060 constexpr explicit ChargeHypothesis(float absoluteCharge) noexcept 0061 : m_absoluteCharge{absoluteCharge} { 0062 assert(absoluteCharge >= 0 && 0063 "Input charge magnitude must be zero or positive"); 0064 } 0065 0066 /// Get the absolute charge magnitude 0067 /// @return Absolute charge magnitude (0 for neutral particles) 0068 constexpr float absoluteCharge() const noexcept { return m_absoluteCharge; } 0069 0070 /// Extract the signed charge from q/p 0071 /// @param qOverP Charge over momentum 0072 /// @return Signed charge with correct magnitude (0 for neutral) 0073 constexpr float extractCharge(double qOverP) const noexcept { 0074 return static_cast<float>(std::copysign(m_absoluteCharge, qOverP)); 0075 } 0076 /// Extract momentum magnitude from q/p 0077 /// @param qOverP Charge over momentum 0078 /// @return Momentum magnitude (handles both charged and neutral particles) 0079 constexpr double extractMomentum(double qOverP) const noexcept { 0080 return (m_absoluteCharge != 0.0f) ? extractCharge(qOverP) / qOverP 0081 : 1.0 / qOverP; 0082 } 0083 0084 /// Compute q/p from momentum and signed charge 0085 /// @param momentum Particle momentum magnitude 0086 /// @param signedQ Signed charge (must match stored charge magnitude) 0087 /// @return Charge over momentum (handles both charged and neutral particles) 0088 constexpr double qOverP(double momentum, float signedQ) const noexcept { 0089 assert(std::abs(signedQ) == m_absoluteCharge && "inconsistent charge"); 0090 return (m_absoluteCharge != 0.0f) ? signedQ / momentum : 1.0 / momentum; 0091 } 0092 0093 /// Compare for equality. 0094 /// @param rhs The ChargeHypothesis to compare to 0095 /// @return True if the two ChargeHypothesis objects are equal, false otherwise 0096 constexpr bool operator==(const ChargeHypothesis& rhs) const noexcept = 0097 default; 0098 0099 private: 0100 float m_absoluteCharge{}; 0101 }; 0102 0103 /// @} 0104 0105 } // namespace Acts
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|