Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-08 08:38:12

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 always charge/momentum, even if the particle is neutral.
0021 /// The following types are used to restrict the particle charge magnitude (at
0022 /// compile time) and support the umambigous extraction of charge and absolute
0023 /// momentum from said track parameter coefficient.
0024 ///
0025 /// All types are designed to be interchangeable. Each one can be
0026 /// constructed with the input charge magnitude
0027 ///
0028 /// ```cpp
0029 /// ChargeHypothesis c(1_e);
0030 /// ```
0031 ///
0032 /// and can then be used to extract the charge value
0033 ///
0034 /// ```cpp
0035 /// auto q = c.extractCharge(qOverP);
0036 /// ```
0037 ///
0038 /// or the absolute momentum
0039 ///
0040 /// ```cpp
0041 /// auto p = c.extractMomentum(qOverP);
0042 /// ```
0043 ///
0044 /// from the charge-over-momentum track parameter.
0045 ///
0046 /// @{
0047 
0048 /// Charge and momentum interpretation for arbitrarily charged particles.
0049 ///
0050 /// Only a charge magnitude identical to zero is interpreted as representing a
0051 /// neutral particle. This avoids ambiguities that might arise from using an
0052 /// approximate comparison with an arbitrary epsilon.
0053 class ChargeHypothesis final {
0054  public:
0055   /// Construct with the magnitude of the input charge.
0056   /// @param absoluteCharge The absolute value of the charge magnitude
0057   constexpr explicit ChargeHypothesis(float absoluteCharge) noexcept
0058       : m_absoluteCharge{absoluteCharge} {
0059     assert(absoluteCharge >= 0 &&
0060            "Input charge magnitude must be zero or positive");
0061   }
0062 
0063   /// Get the absolute charge magnitude
0064   /// @return Absolute charge magnitude (0 for neutral particles)
0065   constexpr float absoluteCharge() const noexcept { return m_absoluteCharge; }
0066 
0067   /// Extract the signed charge from q/p
0068   /// @param qOverP Charge over momentum
0069   /// @return Signed charge with correct magnitude (0 for neutral)
0070   constexpr float extractCharge(double qOverP) const noexcept {
0071     return static_cast<float>(std::copysign(m_absoluteCharge, qOverP));
0072   }
0073   /// Extract momentum magnitude from q/p
0074   /// @param qOverP Charge over momentum
0075   /// @return Momentum magnitude (handles both charged and neutral particles)
0076   constexpr double extractMomentum(double qOverP) const noexcept {
0077     return extractCharge(qOverP) / qOverP;
0078   }
0079 
0080   /// Compute q/p from momentum and signed charge
0081   /// @param momentum Particle momentum magnitude
0082   /// @param signedQ Signed charge (must match stored charge magnitude)
0083   /// @return Charge over momentum (handles both charged and neutral particles)
0084   constexpr double qOverP(double momentum, float signedQ) const noexcept {
0085     assert(std::abs(signedQ) == m_absoluteCharge && "inconsistent charge");
0086     return signedQ / momentum;
0087   }
0088 
0089   /// Compare for equality.
0090   /// @param rhs The ChargeHypothesis to compare to
0091   /// @return True if the two ChargeHypothesis objects are equal, false otherwise
0092   constexpr bool operator==(const ChargeHypothesis& rhs) const noexcept =
0093       default;
0094 
0095  private:
0096   float m_absoluteCharge{};
0097 };
0098 
0099 /// @}
0100 
0101 }  // namespace Acts