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
45enum 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;
82bool IsUnit(std::string in);
100double _AddUnit(std::string name,
int type,
double scale);
103AddUnit(meV, REST_Units::Energy, 1e6);
104AddUnit(eV, REST_Units::Energy, 1e3);
105AddUnit(keV, REST_Units::Energy, 1);
106AddUnit(MeV, REST_Units::Energy, 1e-3);
107AddUnit(GeV, REST_Units::Energy, 1e-6);
108AddUnit(J, REST_Units::Energy, 1.60e-19);
109AddUnit(kJ, REST_Units::Energy, 1.60e-22);
112AddUnit(ns, REST_Units::Time, 1.e3);
113AddUnit(us, REST_Units::Time, 1.);
114AddUnit(ms, REST_Units::Time, 1.e-3);
115AddUnit(s, REST_Units::Time, 1.e-6);
116AddUnit(Hz, REST_Units::Time, 1.e6);
117AddUnit(minu, REST_Units::Time, 1.e-6 / 60.);
118AddUnit(minutes, REST_Units::Time, 1.e-6 / 60.);
119AddUnit(hr, REST_Units::Time, 1e-6 / 3600.);
120AddUnit(hours, REST_Units::Time, 1e-6 / 3600.);
121AddUnit(day, REST_Units::Time, 1e-6 / 3600. / 24.);
122AddUnit(days, REST_Units::Time, 1e-6 / 3600. / 24.);
123AddUnit(mon, REST_Units::Time, 1e-6 / 3600. / 24. / 30);
124AddUnit(months, REST_Units::Time, 1e-6 / 3600. / 24. / 30);
125AddUnit(yr, REST_Units::Time, 1e-6 / 3600. / 24. / 365.25);
126AddUnit(years, REST_Units::Time, 1e-6 / 3600. / 24. / 365.25);
129AddUnit(nm, REST_Units::Length, 1e6);
130AddUnit(um, REST_Units::Length, 1e3);
131AddUnit(mm, REST_Units::Length, 1.);
132AddUnit(cm, REST_Units::Length, 1e-1);
133AddUnit(m, REST_Units::Length, 1e-3);
136AddUnit(mg, REST_Units::Mass, 1e6);
137AddUnit(gram, REST_Units::Mass, 1e3);
138AddUnit(g, REST_Units::Mass, 1e3);
139AddUnit(kg, REST_Units::Mass, 1.);
140AddUnit(ton, REST_Units::Mass, 1e-3);
143AddUnit(mV, REST_Units::Voltage, 1.e3);
144AddUnit(V, REST_Units::Voltage, 1.);
145AddUnit(kV, REST_Units::Voltage, 1.e-3);
148AddUnit(mT, REST_Units::MagneticField, 1.e3);
149AddUnit(T, REST_Units::MagneticField, 1.);
150AddUnit(G, REST_Units::MagneticField, 1.e4);
153AddUnit(bar, REST_Units::Pressure, 1.);
154AddUnit(mbar, REST_Units::Pressure, 1.e3);
155AddUnit(atm, REST_Units::Pressure, 1.013);
156AddUnit(torr, REST_Units::Pressure, 760);
157AddUnit(MPa, REST_Units::Pressure, 0.101325);
158AddUnit(kPa, REST_Units::Pressure, 101.325);
159AddUnit(Pa, REST_Units::Pressure, 101325);
160AddUnit(mPa, REST_Units::Pressure, 10132500);
163AddUnit(rad, REST_Units::Angle, 1.);
164AddUnit(radian, REST_Units::Angle, 1.);
165AddUnit(radians, REST_Units::Angle, 1.);
166AddUnit(deg, REST_Units::Angle, TMath::RadToDeg());
167AddUnit(degree, REST_Units::Angle, TMath::RadToDeg());
168AddUnit(degrees, REST_Units::Angle, TMath::RadToDeg());
169AddUnit(arcmin, REST_Units::Angle, TMath::RadToDeg() * 60.);
170AddUnit(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.