DLG4::VolumeBuilders
A fluent interface for Geant4 geometry definition.
Loading...
Searching...
No Matches
VolumeBuildersUnitTypes.hh
Go to the documentation of this file.
1// VolumeBuilderUnitTypes.hh
2// A bridge to bring DLG4Units.hh into VolumeBuilders without a header loop
3// Created by D.S. Leonard on 5/11/26.
4//
5
6#ifndef HPGESIM_VOLUMEBUIDLERSUNITTYPES_HH
7#define HPGESIM_VOLUMEBUIDLERSUNITTYPES_HH
8#include "DLG4Units.hh"
9
10namespace DLG4::VolumeBuilders {
16 template <class T,class NativeType>
24
25
35 public:
36 double x, y, z;
38
40
42
45
46 ThreeVecDimensioner(G4ThreeVector v, const Length &u)
47 : Length3Vec(v, u) { Sync(); }
48
49 ThreeVecDimensioner(double x, double y, double z, const Length &u)
50 : Length3Vec(x, y, z, u) { Sync(); }
51
52 ThreeVecDimensioner(double x, double y, double z): Length3Vec(x,y,z,DLG4::Units::Length::native) {
53 is_dimensioned_ = false;
54 Sync();
55 }
56
57 ThreeVecDimensioner(G4ThreeVector v)
58 : ThreeVecDimensioner(v.x(), v.y(), v.z()) {
59 }
60
61 [[nodiscard]] G4ThreeVector apply_units(const Length dflt_unit) const {
62 auto vec = G4ThreeVector(x, y, z);
63 if (!is_dimensioned_) {
64 vec *= dflt_unit.Native;
65 }
66 return vec;
67 }
68
69 private:
70 void Sync() {
71 x = NativeValue_->x();
72 y = NativeValue_->y();
73 z = NativeValue_->z();
74 }
75
76 bool is_dimensioned_ = true;
77 };
78
79
80}
81
82
83
84#endif //HPGESIM_VOLUMEBUIDLERSUNITTYPES_HH
Typesafe units, for VolumeBuilders, Geant, ETC !! No accidental mixing values and units.
A 3 vector that is scalable with/to Units.
Definition DLG4Units.hh:430
CRTP base methods for Unit classes.
Definition DLG4Units.hh:92
std::optional< G4ThreeVector > NativeValue_
Definition DLG4Units.hh:98
A 3D vector that manages unit policy for parameter passing If constructed with a unit,...
ThreeVecDimensioner(double x, double y, double z, const Length &u)
ThreeVecDimensioner(G4ThreeVector v, const Length &u)
ThreeVecDimensioner(const ThreeVecDimensioner &)=delete
G4ThreeVector apply_units(const Length dflt_unit) const
ThreeVecDimensioner & operator=(const ThreeVecDimensioner &)=delete
void SetGlobalDefaultUnit(T unit)
Set the global default unit.
Definition DLG4Units.hh:56