Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-09 09:25:45

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 #include "Acts/Definitions/Units.hpp"
0010 
0011 #include "Acts/Definitions/TrackParametrization.hpp"
0012 #include "Acts/EventData/TrackParameters.hpp"
0013 #include "Acts/Geometry/GeometryContext.hpp"
0014 
0015 // This file contains code snippets for the Units documentation
0016 
0017 void basicUnits() {
0018   //! [Using Unit Constants]
0019   // Define input values using unit constants
0020   double length = 1 * Acts::UnitConstants::m;        // length == 1000.0
0021   double momentum = 100 * Acts::UnitConstants::MeV;  // momentum == 0.1
0022 
0023   // Convert output values from native units to specific units
0024   double lengthInMm = length / Acts::UnitConstants::mm;  // == 1000.0
0025   double lengthInM = length / Acts::UnitConstants::m;    // == 1.0
0026   //! [Using Unit Constants]
0027   static_cast<void>(length);
0028   static_cast<void>(momentum);
0029   static_cast<void>(lengthInMm);
0030   static_cast<void>(lengthInM);
0031 }
0032 
0033 void userLiterals() {
0034   //! [Using Unit Literals]
0035   using namespace Acts::UnitLiterals;
0036 
0037   // Define input values using user-defined literals
0038   double length = 1_m;         // == 1000.0 (native units: mm)
0039   double momentum = 1.25_TeV;  // == 1250.0 (native units: GeV)
0040 
0041   // Convert output values to specific units
0042   double lengthInUm = length / 1_um;        // == 1000000.0
0043   double momentumInMeV = momentum / 1_MeV;  // == 1250000.0
0044   //! [Using Unit Literals]
0045   static_cast<void>(length);
0046   static_cast<void>(momentum);
0047   static_cast<void>(lengthInUm);
0048   static_cast<void>(momentumInMeV);
0049 }
0050 
0051 void comprehensiveExample() {
0052   //! [Comprehensive Units Example]
0053   using namespace Acts::UnitLiterals;
0054 
0055   // Define input values with units (via unit constants)
0056   double width = 12 * Acts::UnitConstants::mm;
0057   double mmuon = 105.7 * Acts::UnitConstants::MeV;
0058 
0059   // Define input values with units (via user literals)
0060   double length = 23_cm;
0061   double time = 1214.2_ns;
0062   double angle = 123_degree;
0063   double particleMomentum = 2.5_TeV;
0064   double mass = 511_keV;
0065   double velocity = 345_m / 1_s;
0066   double bfield = 3.9_T;
0067 
0068   // All values are now in native units and can be used in calculations
0069   // Native units: mm, GeV, radian, GeV/(e*mm), etc.
0070   //! [Comprehensive Units Example]
0071   static_cast<void>(width);
0072   static_cast<void>(mmuon);
0073   static_cast<void>(length);
0074   static_cast<void>(time);
0075   static_cast<void>(angle);
0076   static_cast<void>(particleMomentum);
0077   static_cast<void>(mass);
0078   static_cast<void>(velocity);
0079   static_cast<void>(bfield);
0080 }
0081 
0082 void outputConversion() {
0083   Acts::GeometryContext gctx;
0084   Acts::BoundTrackParameters trackPars =
0085       Acts::BoundTrackParameters::createCurvilinear(
0086           Acts::Vector4::Zero(), Acts::Vector3::UnitX(), 1, std::nullopt,
0087           Acts::ParticleHypothesis::pion());
0088   //! [Converting Output Values]
0089   using namespace Acts::UnitLiterals;
0090 
0091   // Assume trackPars is a track parameter object with methods
0092   // that return values in native units
0093 
0094   // Convert output values (via unit constants)
0095   double t_in_ns = trackPars.time() / Acts::UnitConstants::ns;
0096 
0097   // Convert output values (via user literals)
0098   double x_in_mm = trackPars.position(gctx)[Acts::eBoundLoc0] / 1_mm;
0099   double p_in_TeV = trackPars.absoluteMomentum() / 1_TeV;
0100   //! [Converting Output Values]
0101   static_cast<void>(t_in_ns);
0102   static_cast<void>(x_in_mm);
0103   static_cast<void>(p_in_TeV);
0104 }
0105 
0106 void physicalConstants() {
0107   //! [Physical Constants]
0108   // Speed of light in vacuum (dimensionless in native units)
0109   constexpr double c = Acts::PhysicalConstants::c;  // == 1.0
0110 
0111   // Reduced Planck constant h/(2*pi)
0112   // In native units: GeV*mm
0113   constexpr double hbar = Acts::PhysicalConstants::hbar;
0114   //! [Physical Constants]
0115   static_cast<void>(c);
0116   static_cast<void>(hbar);
0117 }
0118 
0119 void goodPractice() {
0120   //! [Unit Best Practices]
0121   using namespace Acts::UnitLiterals;
0122 
0123   // GOOD: All input values explicitly specify units
0124   double momentum = 100 * Acts::UnitConstants::GeV;  // or 100_GeV
0125   double distance = 5 * Acts::UnitConstants::m;      // or 5_m
0126 
0127   // GOOD: Variable names indicate non-native units
0128   double momentumInMeV = 10.0;  // would be 0.01 in native units (GeV)
0129 
0130   // GOOD: Unqualified values are in native units
0131   double energyGeV = 100.0;  // native unit GeV, clear from context
0132 
0133   // Output conversion
0134   double output_in_meters = distance / 1_m;
0135   //! [Unit Best Practices]
0136   static_cast<void>(momentum);
0137   static_cast<void>(momentumInMeV);
0138   static_cast<void>(energyGeV);
0139   static_cast<void>(output_in_meters);
0140 }