MARLEY (Model of Argon Reaction Low Energy Yields) v2.0.0
A Monte Carlo event generator for tens-of-MeV neutrino interactions
Loading...
Searching...
No Matches
Units.h
1// -*- C++ -*-
2//
3// This file is part of HepMC
4// Copyright (C) 2014-2023 The HepMC collaboration (see AUTHORS for details)
5//
6#ifndef HEPMC3_UNITS_H
7#define HEPMC3_UNITS_H
18#include <string>
19#include "HepMC3/Errors.h"
20#include "HepMC3/Setup.h"
21#include "HepMC3/FourVector.h"
22
23namespace HepMC3 {
24
25
26class Units {
27public:
29 enum MomentumUnit { MEV, GEV };
30
32 enum LengthUnit { MM, CM };
33
34public:
36 static MomentumUnit momentum_unit( const std::string& name ) {
37 if ( name.compare(0,3,"GEV") == 0 ) return GEV;
38 if ( name.compare(0,3,"MEV") == 0 ) return MEV;
39
40 HEPMC3_ERROR_LEVEL(300,"Units::momentum_unit: unrecognised unit name: '" << name <<"', setting to GEV" )
41
42 return GEV;
43 }
44
46 static LengthUnit length_unit( const std::string& name ) {
47 if ( name.compare(0,2,"CM") == 0 ) return CM;
48 if ( name.compare(0,2,"MM") == 0 ) return MM;
49
50 HEPMC3_ERROR_LEVEL(300,"Units::length_unit: unrecognised unit name: '" << name <<"', setting to CM" )
51
52 return CM;
53 }
54
56 static std::string name( MomentumUnit u ) {
57 switch(u) {
58 case MEV:
59 return "MEV";
60 case GEV:
61 return "GEV";
62 }
63
64 return "<UNDEFINED>";
65 }
66
68 static std::string name( LengthUnit u ) {
69 switch(u) {
70 case MM:
71 return "MM";
72 case CM:
73 return "CM";
74 }
75
76 return "<UNDEFINED>";
77 }
78
80 template <typename T>
81 static void convert( T &m, MomentumUnit from, MomentumUnit to ) {
82 if ( from == to ) return;
83
84 if ( from == GEV ) {
85 // GEV -> MEV
86 m *= 1000.;
87 }
88 else if ( from == MEV ) {
89 // MEV -> GEV
90 m *= 0.001;
91 }
92 }
93
95 template <typename T>
96 static void convert( T &m, LengthUnit from, LengthUnit to ) {
97 if ( from == to ) return;
98
99 if ( from == CM ) {
100 // CM -> MM
101 m *= 10.0;
102 }
103 else if ( from == MM ) {
104 // MM -> CM
105 m *= 0.1;
106 }
107 }
108
109};
110
111} // namespace HepMC3
112
113#endif
Stores units-related enums and conversion functions.
Definition Units.h:26
LengthUnit
Position units.
Definition Units.h:32
static MomentumUnit momentum_unit(const std::string &name)
Get momentum unit based on its name.
Definition Units.h:36
static std::string name(MomentumUnit u)
Get name of momentum unit.
Definition Units.h:56
static void convert(T &m, LengthUnit from, LengthUnit to)
Convert FourVector to different length unit.
Definition Units.h:96
static LengthUnit length_unit(const std::string &name)
Get length unit based on its name.
Definition Units.h:46
MomentumUnit
Momentum units.
Definition Units.h:29
static std::string name(LengthUnit u)
Get name of length unit.
Definition Units.h:68
static void convert(T &m, MomentumUnit from, MomentumUnit to)
Convert FourVector to different momentum unit.
Definition Units.h:81