23 #ifndef RestCore_TRestSystemOfUnits
24 #define RestCore_TRestSystemOfUnits
35 #ifdef REST_UnitsAdd_Caller
36 #define AddUnit(name, type, scale) double name = _AddUnit(#name, type, scale)
38 #define AddUnit(name, type, scale) constexpr double name = scale
45 enum Physical_Unit { Energy, Time, Length, Mass, Voltage, MagneticField, Pressure, Angle, NOT_A_UNIT = -1 };
50 std::vector<int> fComponents;
52 std::vector<double> fComponentOrder;
56 double fScaleCombined;
68 std::string ToStandardDefinition();
71 if (
units.fZombie)
return val;
72 return val *
units.fScaleCombined;
76 if (
units.fZombie)
return val;
77 return val /
units.fScaleCombined;
82 bool IsUnit(std::string in);
100 double _AddUnit(std::string name,
int type,
double scale);
103 AddUnit(meV, REST_Units::Energy, 1e6);
104 AddUnit(eV, REST_Units::Energy, 1e3);
105 AddUnit(keV, REST_Units::Energy, 1);
106 AddUnit(MeV, REST_Units::Energy, 1e-3);
107 AddUnit(GeV, REST_Units::Energy, 1e-6);
108 AddUnit(J, REST_Units::Energy, 1.60e-19);
109 AddUnit(kJ, REST_Units::Energy, 1.60e-22);
112 AddUnit(ns, REST_Units::Time, 1.e3);
113 AddUnit(us, REST_Units::Time, 1.);
114 AddUnit(ms, REST_Units::Time, 1.e-3);
115 AddUnit(s, REST_Units::Time, 1.e-6);
116 AddUnit(Hz, REST_Units::Time, 1.e6);
117 AddUnit(minu, REST_Units::Time, 1.e-6 / 60.);
118 AddUnit(minutes, REST_Units::Time, 1.e-6 / 60.);
119 AddUnit(hr, REST_Units::Time, 1e-6 / 3600.);
120 AddUnit(hours, REST_Units::Time, 1e-6 / 3600.);
121 AddUnit(day, REST_Units::Time, 1e-6 / 3600. / 24.);
122 AddUnit(days, REST_Units::Time, 1e-6 / 3600. / 24.);
123 AddUnit(mon, REST_Units::Time, 1e-6 / 3600. / 24. / 30);
124 AddUnit(months, REST_Units::Time, 1e-6 / 3600. / 24. / 30);
125 AddUnit(yr, REST_Units::Time, 1e-6 / 3600. / 24. / 365.25);
126 AddUnit(years, REST_Units::Time, 1e-6 / 3600. / 24. / 365.25);
129 AddUnit(nm, REST_Units::Length, 1e6);
130 AddUnit(um, REST_Units::Length, 1e3);
131 AddUnit(mm, REST_Units::Length, 1.);
132 AddUnit(cm, REST_Units::Length, 1e-1);
133 AddUnit(m, REST_Units::Length, 1e-3);
136 AddUnit(mg, REST_Units::Mass, 1e6);
137 AddUnit(gram, REST_Units::Mass, 1e3);
138 AddUnit(g, REST_Units::Mass, 1e3);
139 AddUnit(kg, REST_Units::Mass, 1.);
140 AddUnit(ton, REST_Units::Mass, 1e-3);
143 AddUnit(mV, REST_Units::Voltage, 1.e3);
144 AddUnit(V, REST_Units::Voltage, 1.);
145 AddUnit(kV, REST_Units::Voltage, 1.e-3);
148 AddUnit(mT, REST_Units::MagneticField, 1.e3);
149 AddUnit(T, REST_Units::MagneticField, 1.);
150 AddUnit(G, REST_Units::MagneticField, 1.e4);
153 AddUnit(bar, REST_Units::Pressure, 1.);
154 AddUnit(mbar, REST_Units::Pressure, 1.e3);
155 AddUnit(atm, REST_Units::Pressure, 1.013);
156 AddUnit(torr, REST_Units::Pressure, 760);
157 AddUnit(MPa, REST_Units::Pressure, 0.101325);
158 AddUnit(kPa, REST_Units::Pressure, 101.325);
159 AddUnit(Pa, REST_Units::Pressure, 101325);
160 AddUnit(mPa, REST_Units::Pressure, 10132500);
163 AddUnit(rad, REST_Units::Angle, 1.);
164 AddUnit(radian, REST_Units::Angle, 1.);
165 AddUnit(radians, REST_Units::Angle, 1.);
166 AddUnit(deg, REST_Units::Angle, TMath::RadToDeg());
167 AddUnit(degree, REST_Units::Angle, TMath::RadToDeg());
168 AddUnit(degrees, REST_Units::Angle, TMath::RadToDeg());
169 AddUnit(arcmin, REST_Units::Angle, TMath::RadToDeg() * 60.);
170 AddUnit(arcsec, REST_Units::Angle, TMath::RadToDeg() * 3600.);
double GetUnitScale(std::string singleUnit)
Get the scale of the unit to convert to the REST standard units.
TRestSystemOfUnits(std::string unitsStr)
Constructor from a unit std::string.
bool IsZombie() const
Whether this unit is zombie(invalid)
int GetUnitType(std::string singleUnit)
Get the type of the units.
This namespace defines the unit conversion for different units which are understood by REST.
bool IsBasicUnit(std::string in)
Checks if the string is a REST basic unit.
Double_t GetValueInRESTUnits(std::string in)
It scales a physics measurement with its units into a REST default units value.
TVector3 Get3DVectorInRESTUnits(std::string in)
It scales a physics measurement with its units into a REST default units value.
Double_t GetDblValueInString(std::string in)
It scales a physics measurement with its units into a REST default units value.
double GetScaleToStandardUnit(std::string unitsdef)
Get the scale to REST standard unit. scale (unitsdef) = 1 (standard unit)
Double_t ConvertRESTUnitsValueToCustomUnits(Double_t value, std::string unitsStr)
Convert value with REST units into the given custom units.
std::string FindRESTUnitsInString(std::string InString)
Find and return the units definition in a string.
Double_t GetDblValueInRESTUnits(std::string in)
It scales a physics measurement with its units into a REST default units value.
std::string GetStandardUnitDefinition(std::string unitsdef)
Get standard form of this unit definition.
bool IsUnit(std::string in)
Checks if the string is a REST supported unit.
TVector2 Get2DVectorInRESTUnits(std::string in)
It scales a physics measurement with its units into a REST default units value.
Double_t ConvertValueToRESTUnits(Double_t value, std::string unitsStr)
Convert value into REST units.
TVector3 Get3DVectorValueInString(std::string in)
It scales a physics measurement with its units into a REST default units value.
TVector2 Get2DVectorValueInString(std::string in)
It scales a physics measurement with its units into a REST default units value.
std::string RemoveUnitsFromString(std::string s)
It should remove all units found inside the input string.
double _AddUnit(std::string name, int type, double scale)
Add a unit with given name, type and scale.