src/tools/geant4/geant4.h
Set of Geant4 utilities for framework integration. More…
Namespaces
Name |
---|
allpix Helper class to hold support layers for a detector model. |
Functions
Name | |
---|---|
template <typename T ,typename… Args> std::shared_ptr< T > |
make_shared_no_delete(Args… args) Version of std::make_shared that does not delete the pointer. |
G4ThreeVector | from_string_impl(std::string str, type_tag< G4ThreeVector > ) Enable support to convert string directly to Geant4 3D vector while fetching configuration parameter. |
std::string | to_string_impl(const G4ThreeVector & vec, empty_tag ) Enable support to convert Geant4 3D vector to string for storage in the configuration. |
G4TwoVector | from_string_impl(std::string str, type_tag< G4TwoVector > ) Enable support to convert string directly to Geant4 2D vector for fetching configuration parameter. |
std::string | to_string_impl(const G4TwoVector & vec, empty_tag ) Enable support to convert Geant4 2D vector to string for storage in the configuration. |
template <typename T > G4ThreeVector |
toG4Vector(const ROOT::Math::DisplacementVector3D< T > & vector) Utility method to convert ROOT 3D vector to Geant4 3D vector. |
template <typename T > G4ThreeVector |
toG4Vector(const ROOT::Math::PositionVector3D< T > & vector) Utility method to convert ROOT 2D vector to Geant4 2D vector. |
Detailed Description
Set of Geant4 utilities for framework integration.
Copyright: Copyright (c) 2017-2024 CERN and the Allpix Squared authors. This software is distributed under the terms of the MIT License, copied verbatim in the file “LICENSE.md”. In applying this license, CERN does not waive the privileges and immunities granted to it by virtue of its status as an Intergovernmental Organization or submit itself to any jurisdiction. SPDX-License-Identifier: MIT
Functions Documentation
function make_shared_no_delete
template <typename T ,
typename... Args>
static std::shared_ptr< T > make_shared_no_delete(
Args... args
)
Version of std::make_shared that does not delete the pointer.
This version is needed because some pointers are deleted by Geant4 internally, but they are stored as std::shared_ptr in the framework.
function from_string_impl
inline G4ThreeVector from_string_impl(
std::string str,
type_tag< G4ThreeVector >
)
Enable support to convert string directly to Geant4 3D vector while fetching configuration parameter.
function to_string_impl
inline std::string to_string_impl(
const G4ThreeVector & vec,
empty_tag
)
Enable support to convert Geant4 3D vector to string for storage in the configuration.
function from_string_impl
inline G4TwoVector from_string_impl(
std::string str,
type_tag< G4TwoVector >
)
Enable support to convert string directly to Geant4 2D vector for fetching configuration parameter.
function to_string_impl
inline std::string to_string_impl(
const G4TwoVector & vec,
empty_tag
)
Enable support to convert Geant4 2D vector to string for storage in the configuration.
function toG4Vector
template <typename T >
G4ThreeVector toG4Vector(
const ROOT::Math::DisplacementVector3D< T > & vector
)
Utility method to convert ROOT 3D vector to Geant4 3D vector.
function toG4Vector
template <typename T >
G4ThreeVector toG4Vector(
const ROOT::Math::PositionVector3D< T > & vector
)
Utility method to convert ROOT 2D vector to Geant4 2D vector.
Source code
#ifndef ALLPIX_GEANT4_H
#define ALLPIX_GEANT4_H
#include <stdexcept>
#include <string>
#include <utility>
#include <G4ThreeVector.hh>
#include <G4TwoVector.hh>
#include <Math/DisplacementVector3D.h>
#include <Math/PositionVector3D.h>
#include "core/utils/text.h"
#include "core/utils/type.h"
template <typename T, typename... Args> static std::shared_ptr<T> make_shared_no_delete(Args... args) {
return std::shared_ptr<T>(new T(args...), [](T*) {});
}
namespace allpix {
inline G4ThreeVector from_string_impl(std::string str, type_tag<G4ThreeVector>) {
std::vector<double> vec_split = allpix::split<double>(std::move(str));
if(vec_split.size() != 3) {
throw std::invalid_argument("array should contain exactly three elements");
}
return {vec_split[0], vec_split[1], vec_split[2]};
}
inline std::string to_string_impl(const G4ThreeVector& vec, empty_tag) {
std::string res;
for(int i = 0; i < 3; ++i) {
res += std::to_string(vec[i]);
if(i != 2) {
res += ",";
}
}
return res;
}
inline G4TwoVector from_string_impl(std::string str, type_tag<G4TwoVector>) {
std::vector<double> vec_split = allpix::split<double>(std::move(str));
if(vec_split.size() != 2) {
throw std::invalid_argument("array should contain exactly two elements");
}
return {vec_split[0], vec_split[1]};
}
inline std::string to_string_impl(const G4TwoVector& vec, empty_tag) {
std::string res;
for(int i = 0; i < 2; ++i) {
res += std::to_string(vec[i]);
if(i != 1) {
res += ",";
}
}
return res;
}
template <typename T> G4ThreeVector toG4Vector(const ROOT::Math::DisplacementVector3D<T>& vector) {
return G4ThreeVector(vector.x(), vector.y(), vector.z());
}
template <typename T> G4ThreeVector toG4Vector(const ROOT::Math::PositionVector3D<T>& vector) {
return G4ThreeVector(vector.x(), vector.y(), vector.z());
}
} // namespace allpix
#endif /* ALLPIX_GEANT4_H */
Updated on 2025-02-27 at 14:14:46 +0000