File indexing completed on 2025-01-18 10:01:14
0001
0002
0003
0004
0005
0006 #ifndef HEPMC3_UNITS_H
0007 #define HEPMC3_UNITS_H
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #include <string>
0019 #include "HepMC3/Errors.h"
0020 #include "HepMC3/Setup.h"
0021 #include "HepMC3/FourVector.h"
0022
0023 namespace HepMC3 {
0024
0025
0026 class Units {
0027 public:
0028
0029 enum MomentumUnit { MEV, GEV };
0030
0031
0032 enum LengthUnit { MM, CM };
0033
0034 public:
0035
0036 static MomentumUnit momentum_unit( const std::string& name ) {
0037 if ( name.compare(0,3,"GEV") == 0 ) return GEV;
0038 if ( name.compare(0,3,"MEV") == 0 ) return MEV;
0039
0040 HEPMC3_ERROR_LEVEL(300,"Units::momentum_unit: unrecognised unit name: '" << name <<"', setting to GEV" )
0041
0042 return GEV;
0043 }
0044
0045
0046 static LengthUnit length_unit( const std::string& name ) {
0047 if ( name.compare(0,2,"CM") == 0 ) return CM;
0048 if ( name.compare(0,2,"MM") == 0 ) return MM;
0049
0050 HEPMC3_ERROR_LEVEL(300,"Units::length_unit: unrecognised unit name: '" << name <<"', setting to CM" )
0051
0052 return CM;
0053 }
0054
0055
0056 static std::string name( MomentumUnit u ) {
0057 switch(u) {
0058 case MEV:
0059 return "MEV";
0060 case GEV:
0061 return "GEV";
0062 }
0063
0064 return "<UNDEFINED>";
0065 }
0066
0067
0068 static std::string name( LengthUnit u ) {
0069 switch(u) {
0070 case MM:
0071 return "MM";
0072 case CM:
0073 return "CM";
0074 }
0075
0076 return "<UNDEFINED>";
0077 }
0078
0079
0080 template <typename T>
0081 static void convert( T &m, MomentumUnit from, MomentumUnit to ) {
0082 if ( from == to ) return;
0083
0084 if ( from == GEV ) {
0085
0086 m *= 1000.;
0087 }
0088 else if ( from == MEV ) {
0089
0090 m *= 0.001;
0091 }
0092 }
0093
0094
0095 template <typename T>
0096 static void convert( T &m, LengthUnit from, LengthUnit to ) {
0097 if ( from == to ) return;
0098
0099 if ( from == CM ) {
0100
0101 m *= 10.0;
0102 }
0103 else if ( from == MM ) {
0104
0105 m *= 0.1;
0106 }
0107 }
0108
0109 };
0110
0111 }
0112
0113 #endif