Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-07-16 08:08:01

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 "ActsExamples/Geant4/AlgebraConverters.hpp"
0010 
0011 #include "Acts/Definitions/Units.hpp"
0012 
0013 #include "CLHEP/Units/SystemOfUnits.h"
0014 
0015 namespace {
0016 constexpr double convertLength = CLHEP::mm / Acts::UnitConstants::mm;
0017 constexpr double convertTime = Acts::UnitConstants::ns / CLHEP::ns;
0018 constexpr double convertEnergy = Acts::UnitConstants::GeV / CLHEP::GeV;
0019 }  // namespace
0020 
0021 namespace ActsExamples::Geant4 {
0022 Acts::Vector3 convertPosition(const G4ThreeVector& g4vec) {
0023   return Acts::Vector3(g4vec[0] * convertLength, g4vec[1] * convertLength,
0024                        g4vec[2] * convertLength);
0025 };
0026 
0027 Acts::Vector4 convertPosition(const G4ThreeVector& g4vec, const double time) {
0028   return Acts::Vector4(g4vec[0] * convertLength, g4vec[1] * convertLength,
0029                        g4vec[2] * convertLength, time * convertTime);
0030 }
0031 
0032 Acts::Vector4 convertMomentum(const G4ThreeVector& g4vec, const double energy) {
0033   return Acts::Vector4{convertEnergy * g4vec[0], convertEnergy * g4vec[1],
0034                        convertEnergy * g4vec[2], convertEnergy * energy};
0035 }
0036 
0037 G4ThreeVector convertPosition(const Acts::Vector3& actsVec) {
0038   return G4ThreeVector(actsVec[0] / convertLength, actsVec[1] / convertLength,
0039                        actsVec[2] / convertLength);
0040 }
0041 Acts::Vector3 convertDirection(const G4ThreeVector& g4vec) {
0042   return Acts::Vector3{g4vec[0], g4vec[1], g4vec[2]};
0043 }
0044 G4ThreeVector convertDirection(const Acts::Vector3& actsVec) {
0045   return G4ThreeVector{actsVec[0], actsVec[1], actsVec[2]};
0046 }
0047 
0048 }  // namespace ActsExamples::Geant4