Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
HepTool::Evaluator Class Reference

#include <Evaluator.h>

+ Inheritance diagram for HepTool::Evaluator:

Public Types

enum  {
  OK , WARNING_EXISTING_VARIABLE , WARNING_EXISTING_FUNCTION , WARNING_BLANK_STRING ,
  ERROR_NOT_A_NAME , ERROR_SYNTAX_ERROR , ERROR_UNPAIRED_PARENTHESIS , ERROR_UNEXPECTED_SYMBOL ,
  ERROR_UNKNOWN_VARIABLE , ERROR_UNKNOWN_FUNCTION , ERROR_EMPTY_PARAMETER , ERROR_CALCULATION_ERROR
}
 

Public Member Functions

 Evaluator ()
 
 ~Evaluator ()
 
double evaluate (const char *expression)
 
int status () const
 
int error_position () const
 
void print_error () const
 
std::string error_name () const
 
void setVariable (const char *name, double value)
 
void setVariable (const char *name, const char *expression)
 
void setFunction (const char *name, double(*fun)())
 
void setFunction (const char *name, double(*fun)(double))
 
void setFunction (const char *name, double(*fun)(double, double))
 
void setFunction (const char *name, double(*fun)(double, double, double))
 
void setFunction (const char *name, double(*fun)(double, double, double, double))
 
void setFunction (const char *name, double(*fun)(double, double, double, double, double))
 
bool findVariable (const char *name) const
 
bool findFunction (const char *name, int npar) const
 
void removeVariable (const char *name)
 
void removeFunction (const char *name, int npar)
 
void clear ()
 
void setStdMath ()
 
void setSystemOfUnits (double meter=1.0, double kilogram=1.0, double second=1.0, double ampere=1.0, double kelvin=1.0, double mole=1.0, double candela=1.0)
 

Detailed Description

Evaluator of arithmetic expressions with an extendable dictionary. Example:

eval.setStdMath();
double res = eval.evaluate("sin(30*degree)");
void print_error() const
Definition: Evaluator.cc:643
double evaluate(const char *expression)
Definition: Evaluator.cc:613
int status() const
Definition: Evaluator.cc:633
Author
Evgeni Chernyaev Evgue.nosp@m.ni.T.nosp@m.chern.nosp@m.iaev.nosp@m.@cern.nosp@m..ch

Definition at line 25 of file Evaluator.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

List of possible statuses. Status of the last operation can be obtained with status(). In case if status() is an ERROR the corresponding error message can be printed with print_error().

See also
status
error_position
print_error
Enumerator
OK 

Everything OK

WARNING_EXISTING_VARIABLE 

Redefinition of existing variable

WARNING_EXISTING_FUNCTION 

Redefinition of existing function

WARNING_BLANK_STRING 

Empty input string

ERROR_NOT_A_NAME 

Not allowed sysmbol in the name of variable or function

ERROR_SYNTAX_ERROR 

Systax error

ERROR_UNPAIRED_PARENTHESIS 

Unpaired parenthesis

ERROR_UNEXPECTED_SYMBOL 

Unexpected sysbol

ERROR_UNKNOWN_VARIABLE 

Non-existing variable

ERROR_UNKNOWN_FUNCTION 

Non-existing function

ERROR_EMPTY_PARAMETER 

Function call has empty parameter

ERROR_CALCULATION_ERROR 

Error during calculation

Definition at line 38 of file Evaluator.h.

38 {
39 OK, /**< Everything OK */
40 WARNING_EXISTING_VARIABLE, /**< Redefinition of existing variable */
41 WARNING_EXISTING_FUNCTION, /**< Redefinition of existing function */
42 WARNING_BLANK_STRING, /**< Empty input string */
43 ERROR_NOT_A_NAME, /**< Not allowed sysmbol in the name of variable or function */
44 ERROR_SYNTAX_ERROR, /**< Systax error */
45 ERROR_UNPAIRED_PARENTHESIS, /**< Unpaired parenthesis */
46 ERROR_UNEXPECTED_SYMBOL, /**< Unexpected sysbol */
47 ERROR_UNKNOWN_VARIABLE, /**< Non-existing variable */
48 ERROR_UNKNOWN_FUNCTION, /**< Non-existing function */
49 ERROR_EMPTY_PARAMETER, /**< Function call has empty parameter */
50 ERROR_CALCULATION_ERROR /**< Error during calculation */
51 };
@ ERROR_UNPAIRED_PARENTHESIS
Definition: Evaluator.h:45

Constructor & Destructor Documentation

◆ Evaluator()

HepTool::Evaluator::Evaluator ( )

Constructor.

Definition at line 598 of file Evaluator.cc.

598 {
599 Struct * s = new Struct();
600 p = (void *) s;
601 s->theExpression = 0;
602 s->thePosition = 0;
603 s->theStatus = OK;
604 s->theResult = 0.0;
605}
pchar thePosition
Definition: Evaluator.cc:42
pchar theExpression
Definition: Evaluator.cc:41
int theStatus
Definition: Evaluator.cc:43
double theResult
Definition: Evaluator.cc:44

◆ ~Evaluator()

HepTool::Evaluator::~Evaluator ( )

Destructor.

Definition at line 608 of file Evaluator.cc.

608 {
609 delete (Struct *)(p);
610}

Member Function Documentation

◆ clear()

void HepTool::Evaluator::clear ( )

Clear all settings.

Definition at line 764 of file Evaluator.cc.

764 {
765 Struct * s = (Struct *) p;
766 s->theDictionary.clear();
767 s->theExpression = 0;
768 s->thePosition = 0;
769 s->theStatus = OK;
770 s->theResult = 0.0;
771}
dic_type theDictionary
Definition: Evaluator.cc:40

Referenced by G4GDMLEvaluator::Clear(), and G4GDMLEvaluator::G4GDMLEvaluator().

◆ error_name()

std::string HepTool::Evaluator::error_name ( ) const

get a string defining the error name

Definition at line 652 of file Evaluator.cc.

653{
654 char prefix[] = "Evaluator : ";
655 std::ostringstream errn;
656 Struct * s = (Struct *) p;
657 switch (s->theStatus) {
658 case ERROR_NOT_A_NAME:
659 errn << prefix << "invalid name";
660 break;
662 errn << prefix << "syntax error";
663 break;
665 errn << prefix << "unpaired parenthesis";
666 break;
668 errn << prefix << "unexpected symbol";
669 break;
671 errn << prefix << "unknown variable";
672 break;
674 errn << prefix << "unknown function";
675 break;
677 errn << prefix << "empty parameter in function call";
678 break;
680 errn << prefix << "calculation error";
681 break;
682 default:
683 errn << " ";
684 }
685 return errn.str();
686}

Referenced by print_error().

◆ error_position()

int HepTool::Evaluator::error_position ( ) const

Returns position in the input string where the problem occured.

Definition at line 638 of file Evaluator.cc.

638 {
639 return ((Struct *)(p))->thePosition - ((Struct *)(p))->theExpression;
640}

◆ evaluate()

double HepTool::Evaluator::evaluate ( const char *  expression)

Evaluates the arithmetic expression given as character string. The expression may consist of numbers, variables and functions separated by arithmetic (+, - , /, *, ^, **) and logical operators (==, !=, >, >=, <, <=, &&, ||).

Parameters
expressioninput expression.
Returns
result of the evaluation.
See also
status
error_position
print_error

Definition at line 613 of file Evaluator.cc.

613 {
614 Struct * s = (Struct *)(p);
615 if (s->theExpression != 0) { delete[] s->theExpression; }
616 s->theExpression = 0;
617 s->thePosition = 0;
619 s->theResult = 0.0;
620 if (expression != 0) {
621 s->theExpression = new char[strlen(expression)+1];
622 strcpy(s->theExpression, expression);
623 s->theStatus = engine(s->theExpression,
624 s->theExpression+strlen(expression)-1,
625 s->theResult,
626 s->thePosition,
627 s->theDictionary);
628 }
629 return s->theResult;
630}

Referenced by G4GDMLEvaluator::Evaluate(), and G4tgrUtils::GetDouble().

◆ findFunction()

bool HepTool::Evaluator::findFunction ( const char *  name,
int  npar 
) const

Finds the function in the dictionary.

Parameters
namename of the function to be unset.
nparnumber of parameters of the function.
Returns
true if such a function exists, false otherwise.

Definition at line 734 of file Evaluator.cc.

734 {
735 if (name == 0 || *name == '\0') return false;
736 if (npar < 0 || npar > MAX_N_PAR) return false;
737 const char * pointer; int n; REMOVE_BLANKS;
738 if (n == 0) return false;
739 Struct * s = (Struct *)(p);
740 return ((s->theDictionary).find(sss[npar]+string(pointer,n)) ==
741 (s->theDictionary).end()) ? false : true;
742}
#define MAX_N_PAR
Definition: Evaluator.cc:61
#define REMOVE_BLANKS
Definition: Evaluator.cc:50

◆ findVariable()

bool HepTool::Evaluator::findVariable ( const char *  name) const

Finds the variable in the dictionary.

Parameters
namename of the variable.
Returns
true if such a variable exists, false otherwise.

Definition at line 723 of file Evaluator.cc.

723 {
724 if (name == 0 || *name == '\0') return false;
725 const char * pointer; int n; REMOVE_BLANKS;
726 if (n == 0) return false;
727 Struct * s = (Struct *)(p);
728 return
729 ((s->theDictionary).find(string(pointer,n)) == (s->theDictionary).end()) ?
730 false : true;
731}

Referenced by G4GDMLEvaluator::DefineConstant(), G4GDMLEvaluator::DefineVariable(), and G4GDMLEvaluator::GetConstant().

◆ print_error()

void HepTool::Evaluator::print_error ( ) const

Prints error message if status() is an ERROR.

Definition at line 643 of file Evaluator.cc.

643 {
644 Struct * s = (Struct *) p;
645 if(s->theStatus != OK) {
646 std::cerr << error_name() << std::endl;
647 }
648 return;
649}
std::string error_name() const
Definition: Evaluator.cc:652

Referenced by G4GDMLEvaluator::Evaluate(), and G4tgrEvaluator::print_error().

◆ removeFunction()

void HepTool::Evaluator::removeFunction ( const char *  name,
int  npar 
)

Removes the function from the dictionary.

Parameters
namename of the function to be unset.
nparnumber of parameters of the function.

Definition at line 754 of file Evaluator.cc.

754 {
755 if (name == 0 || *name == '\0') return;
756 if (npar < 0 || npar > MAX_N_PAR) return;
757 const char * pointer; int n; REMOVE_BLANKS;
758 if (n == 0) return;
759 Struct * s = (Struct *)(p);
760 (s->theDictionary).erase(sss[npar]+string(pointer,n));
761}

◆ removeVariable()

void HepTool::Evaluator::removeVariable ( const char *  name)

Removes the variable from the dictionary.

Parameters
namename of the variable.

Definition at line 745 of file Evaluator.cc.

745 {
746 if (name == 0 || *name == '\0') return;
747 const char * pointer; int n; REMOVE_BLANKS;
748 if (n == 0) return;
749 Struct * s = (Struct *)(p);
750 (s->theDictionary).erase(string(pointer,n));
751}

◆ setFunction() [1/6]

void HepTool::Evaluator::setFunction ( const char *  name,
double(*)()  fun 
)

Adds to the dictionary a function without parameters. If such a function already exist in the dictionary, then status will be set to WARNING_EXISTING_FUNCTION.

Parameters
namefunction name.
funpointer to the real function in the user code.

Definition at line 698 of file Evaluator.cc.

700{ setItem("0", name, Item(reinterpret_cast<voidfuncptr>(fun)), (Struct *)p); }
void(* voidfuncptr)()
Definition: Evaluator.cc:20

Referenced by setStdMath().

◆ setFunction() [2/6]

void HepTool::Evaluator::setFunction ( const char *  name,
double(*)(double)  fun 
)

Adds to the dictionary a function with one parameter. If such a function already exist in the dictionary, then status will be set to WARNING_EXISTING_FUNCTION.

Parameters
namefunction name.
funpointer to the real function in the user code.

Definition at line 702 of file Evaluator.cc.

704{ setItem("1", name, Item(reinterpret_cast<voidfuncptr>(fun)), (Struct *)p); }

◆ setFunction() [3/6]

void HepTool::Evaluator::setFunction ( const char *  name,
double(*)(double, double)  fun 
)

Adds to the dictionary a function with two parameters. If such a function already exist in the dictionary, then status will be set to WARNING_EXISTING_FUNCTION.

Parameters
namefunction name.
funpointer to the real function in the user code.

Definition at line 706 of file Evaluator.cc.

708{ setItem("2", name, Item(reinterpret_cast<voidfuncptr>(fun)), (Struct *)p); }

◆ setFunction() [4/6]

void HepTool::Evaluator::setFunction ( const char *  name,
double(*)(double, double, double)  fun 
)

Adds to the dictionary a function with three parameters. If such a function already exist in the dictionary, then status will be set to WARNING_EXISTING_FUNCTION.

Parameters
namefunction name.
funpointer to the real function in the user code.

Definition at line 710 of file Evaluator.cc.

712{ setItem("3", name, Item(reinterpret_cast<voidfuncptr>(fun)), (Struct *)p); }

◆ setFunction() [5/6]

void HepTool::Evaluator::setFunction ( const char *  name,
double(*)(double, double, double, double)  fun 
)

Adds to the dictionary a function with four parameters. If such a function already exist in the dictionary, then status will be set to WARNING_EXISTING_FUNCTION.

Parameters
namefunction name.
funpointer to the real function in the user code.

Definition at line 714 of file Evaluator.cc.

716{ setItem("4", name, Item(reinterpret_cast<voidfuncptr>(fun)), (Struct *)p); }

◆ setFunction() [6/6]

void HepTool::Evaluator::setFunction ( const char *  name,
double(*)(double, double, double, double, double)  fun 
)

Adds to the dictionary a function with five parameters. If such a function already exist in the dictionary, then status will be set to WARNING_EXISTING_FUNCTION.

Parameters
namefunction name.
funpointer to the real function in the user code.

Definition at line 718 of file Evaluator.cc.

720{ setItem("5", name, Item(reinterpret_cast<voidfuncptr>(fun)), (Struct *)p); }

◆ setStdMath()

void HepTool::Evaluator::setStdMath ( )

Sets standard mathematical functions and constants.

Definition at line 29 of file setStdMath.cc.

29 {
30
31 // S E T S T A N D A R D C O N S T A N T S
32
33 setVariable("pi", 3.14159265358979323846);
34 setVariable("e", 2.7182818284590452354);
35 setVariable("gamma", 0.577215664901532861);
36 setVariable("radian", 1.0);
37 setVariable("rad", 1.0);
38 setVariable("degree", 3.14159265358979323846/180.);
39 setVariable("deg", 3.14159265358979323846/180.);
40
41 // S E T S T A N D A R D F U N C T I O N S
42
43 setFunction("abs", eval_abs);
44 setFunction("min", eval_min);
45 setFunction("max", eval_max);
46 setFunction("sqrt", eval_sqrt);
47 setFunction("pow", eval_pow);
48 setFunction("sin", eval_sin);
49 setFunction("cos", eval_cos);
50 setFunction("tan", eval_tan);
51 setFunction("asin", eval_asin);
52 setFunction("acos", eval_acos);
53 setFunction("atan", eval_atan);
54 setFunction("atan2", eval_atan2);
55 setFunction("sinh", eval_sinh);
56 setFunction("cosh", eval_cosh);
57 setFunction("tanh", eval_tanh);
58 setFunction("exp", eval_exp);
59 setFunction("log", eval_log);
60 setFunction("log10", eval_log10);
61}
void setFunction(const char *name, double(*fun)())
Definition: Evaluator.cc:698
void setVariable(const char *name, double value)
Definition: Evaluator.cc:689

Referenced by G4GDMLEvaluator::Clear(), and G4GDMLEvaluator::G4GDMLEvaluator().

◆ setSystemOfUnits()

void HepTool::Evaluator::setSystemOfUnits ( double  meter = 1.0,
double  kilogram = 1.0,
double  second = 1.0,
double  ampere = 1.0,
double  kelvin = 1.0,
double  mole = 1.0,
double  candela = 1.0 
)

Sets system of units. Default is the SI system of units. To set the CGS (Centimeter-Gram-Second) system of units one should call: setSystemOfUnits(100., 1000., 1.0, 1.0, 1.0, 1.0, 1.0);

To set system of units accepted in the GEANT4 simulation toolkit one should call:

setSystemOfUnits(1.e+3, 1./1.60217733e-25, 1.e+9, 1./1.60217733e-10,
1.0, 1.0, 1.0);
void setSystemOfUnits(double meter=1.0, double kilogram=1.0, double second=1.0, double ampere=1.0, double kelvin=1.0, double mole=1.0, double candela=1.0)

The basic units in GEANT4 are:

millimeter (millimeter = 1.)
nanosecond (nanosecond = 1.)
Mega electron Volt (MeV = 1.)
positron charge (eplus = 1.)
degree Kelvin (kelvin = 1.)
the amount of substance (mole = 1.)
luminous intensity (candela = 1.)
radian (radian = 1.)
steradian (steradian = 1.)

Definition at line 8 of file setSystemOfUnits.cc.

15{
16 const double kilo_ = 1.e+03; // chilioi (Greek) "thousand"
17 const double mega_ = 1.e+06; // megas (Greek) "large"
18 const double giga_ = 1.e+09; // gigas (Greek) "giant"
19 const double tera_ = 1.e+12; // teras (Greek) "monster"
20 const double peta_ = 1.e+15; // pente (Greek) "five"
21
22 const double deci_ = 1.e-01; // decimus (Latin) "tenth"
23 const double centi_ = 1.e-02; // centum (Latin) "hundred"
24 const double milli_ = 1.e-03; // mille (Latin) "thousand"
25 const double micro_ = 1.e-06; // micro (Latin) or mikros (Greek) "small"
26 const double nano_ = 1.e-09; // nanus (Latin) or nanos (Greek) "dwarf"
27 const double pico_ = 1.e-12; // pico (Spanish) "bit"
28
29 // ======================================================================
30 //
31 // Base (default) SI units
32 // for the basic measurable quantities (dimensions):
33 //
34 // ======================================================================
35
36 // Length
37 // metrum (Latin) and metron (Greek) "measure"
38 const double m = meter;
39 setVariable("meter", m);
40 setVariable("metre", m);
41 setVariable("m", m);
42
43 // Mass
44 const double kg = kilogram;
45 setVariable("kilogram", kg);
46 setVariable("kg", kg);
47
48 // Time
49 // minuta secundam (Latin) "second small one"
50 const double s = second;
51 setVariable("second", s);
52 setVariable("s", s);
53
54 // Current
55 // --- honors Andre-Marie Ampere (1775-1836) of France
56 const double A = ampere;
57 setVariable("ampere", A);
58 setVariable("amp", A);
59 setVariable("A", A);
60
61 // Temperature
62 // --- honors William Thomson, 1st Baron Lord Kelvin (1824-1907) of England
63 const double K = kelvin;
64 setVariable("kelvin", K);
65 setVariable("K", K);
66
67 // Amount of substance
68 const double mol = mole;
69 setVariable("mole", mol);
70 setVariable("mol", mol);
71
72 // Luminous intensity
73 const double cd = candela;
74 setVariable("candela", cd);
75 setVariable("cd", cd);
76
77 // ======================================================================
78 //
79 // Supplementary SI units having special symbols:
80 //
81 // ======================================================================
82
83 // Plane angle
84 const double rad = 1.;
85 setVariable("radian", rad);
86 setVariable("rad", rad);
87 setVariable("milliradian", milli_ * rad);
88 setVariable("mrad", milli_ * rad);
89
90 const double pi = 3.14159265358979323846;
91 const double deg = rad*pi/180.;
92 setVariable("degree", deg);
93 setVariable("deg", deg);
94
95 // Solid angle
96 const double sr = 1.;
97 setVariable("steradian", sr);
98 setVariable("sr", sr);
99
100 // ======================================================================
101 //
102 // Derived SI units having special symbols:
103 //
104 // ======================================================================
105
106 // Frequency
107 // --- honors Heinrich Rudolf Hertz (1857-1894) of Germany
108 const double Hz = 1./s;
109 setVariable("hertz", Hz);
110 setVariable("Hz", Hz);
111
112 // Force
113 // --- honors Sir Isaac Newton (1642-1727) of England
114 const double N = m * kg / (s*s);
115 setVariable("newton", N);
116 setVariable("N", N);
117
118 // Pressure
119 // --- honors Blaise Pascal (1623-1662) of France
120 const double Pa = N / (m*m);
121 setVariable("pascal", Pa);
122 setVariable("Pa", Pa);
123
124 const double atm = 101325. * Pa;
125 setVariable("atmosphere", atm);
126 setVariable("atm", atm);
127
128 const double bar = 100000*Pa;
129 setVariable("bar", bar);
130
131 // Energy
132 // --- honors James Prescott Joule (1818-1889) of England
133 const double J = N * m;
134 setVariable("joule", J);
135 setVariable("J", J);
136
137 // Power
138 // --- honors James Watt (1736-1819) of Scotland
139 const double W = J / s;
140 setVariable("watt", W);
141 setVariable("W", W);
142
143 // Electric charge
144 // --- honors Charles-Augustin de Coulomb (1736-1806) of France
145 const double C = A * s;
146 setVariable("coulomb", C);
147 setVariable("C", C);
148
149 // Electric potential
150 // --- honors Count Alessandro Volta (1745-1827) of Italy
151 const double V = J / C;
152 setVariable("volt", V);
153 setVariable("V", V);
154
155 // Electric resistance
156 // --- honors Georg Simon Ohm (1787-1854) of Germany
157 const double ohm = V / A;
158 setVariable("ohm", ohm);
159
160 // Electric conductance
161 // --- honors Ernst Werner von Siemens (1816-1892) or
162 // his brother Sir William (Karl Wilhelm von) Siemens (1823-1883)
163 // of Germany (England)
164 const double S = 1./ ohm;
165 setVariable("siemens", S);
166 setVariable("S", S);
167
168 // Electric capacitance
169 // --- honors Michael Faraday (1791-1867) of England
170 const double F = C / V;
171 setVariable("farad", F);
172 setVariable("F", F);
173
174 // Magnetic flux density
175 // --- honors Nikola Tesla (1856-1943) of Croatia (United States)
176 const double T = V * s / (m*m);
177 setVariable("tesla", T);
178 setVariable("T", T);
179
180 // --- honors Karl Friedrich Gauss (1777-1855) of Germany
181 const double Gs = 1.e-4*T;
182 setVariable("gauss", Gs);
183 setVariable("Gs", Gs);
184
185 // Magnetic flux
186 // --- honors Wilhelm Eduard Weber (1804-1891) of Germany
187 const double Wb = V * s;
188 setVariable("weber", Wb);
189 setVariable("Wb", Wb);
190
191 // Inductance
192 // --- honors Joseph Henry (1797-1878) of the United States
193 const double H = Wb / A;
194 setVariable("henry", H);
195 setVariable("H", H);
196
197 // Luminous flux
198 const double lm = cd * sr;
199 setVariable("lumen", lm);
200 setVariable("lm", lm);
201
202 // Illuminace
203 const double lx = lm / (m*m);
204 setVariable("lux", lx);
205 setVariable("lx", lx);
206
207 // Radioactivity
208 // --- honors Antoine-Henri Becquerel (1852-1908) of France
209 const double Bq = 1./s;
210 setVariable("becquerel", Bq);
211 setVariable("Bq", Bq);
212 setVariable("kilobecquerel", kilo_ * Bq);
213 setVariable("kBq", kilo_ * Bq);
214 setVariable("megabecquerel", mega_ * Bq);
215 setVariable("MBq", mega_ * Bq);
216 setVariable("gigabecquerel", giga_ * Bq);
217 setVariable("GBq", giga_ * Bq);
218
219 // --- honors Pierre Curie (1859-1906) of France
220 // and Marie Sklodowska Curie (1867-1934) of Poland
221 setVariable("curie", 3.7e+10 * Bq);
222 setVariable("Ci", 3.7e+10 * Bq);
223 setVariable("millicurie", milli_ * 3.7e+10 * Bq);
224 setVariable("mCi", milli_ * 3.7e+10 * Bq);
225 setVariable("microcurie", micro_ * 3.7e+10 * Bq);
226 setVariable("uCi", micro_ * 3.7e+10 * Bq);
227
228 // Specific energy
229 // --- honors Louis Harold Gray, F.R.S. (1905-1965) of England
230 const double Gy = J / kg;
231 setVariable("gray", Gy);
232 setVariable("Gy", Gy);
233 setVariable("kilogray", kilo_ * Gy);
234 setVariable("milligray", milli_ * Gy);
235 setVariable("microgray", micro_ * Gy);
236
237 // Dose equivalent
238 const double Sv = J / kg;
239 setVariable("sievert", Sv);
240 setVariable("Sv", Sv);
241
242 // ======================================================================
243 //
244 // Selected units:
245 //
246 // ======================================================================
247
248 // Length
249
250 const double mm = milli_ * m;
251 setVariable("millimeter", mm);
252 setVariable("mm", mm);
253
254 const double cm = centi_ * m;
255 setVariable("centimeter", cm);
256 setVariable("cm", cm);
257
258 setVariable("decimeter", deci_ * m);
259
260 const double km = kilo_ * m;
261 setVariable("kilometer", km);
262 setVariable("km", km);
263
264 setVariable("micrometer", micro_ * m);
265 setVariable("micron", micro_ * m);
266 setVariable("nanometer", nano_ * m);
267
268 // --- honors Anders Jonas Angstrom (1814-1874) of Sweden
269 setVariable("angstrom", 1.e-10 * m);
270
271 // --- honors Enrico Fermi (1901-1954) of Italy
272 setVariable("fermi", 1.e-15 * m);
273
274 // Length^2
275
276 setVariable("m2", m*m);
277 setVariable("mm2", mm*mm);
278 setVariable("cm2", cm*cm);
279 setVariable("km2", km*km);
280
281 const double barn = 1.e-28 * m*m;
282 setVariable("barn", barn);
283 setVariable("millibarn", milli_ * barn);
284 setVariable("mbarn", milli_ * barn);
285 setVariable("microbarn", micro_ * barn);
286 setVariable("nanobarn", nano_ * barn);
287 setVariable("picobarn", pico_ * barn);
288
289 // LengthL^3
290
291 setVariable("m3", m*m*m);
292 setVariable("mm3", mm*mm*mm);
293 setVariable("cm3", cm*cm*cm);
294 setVariable("cc", cm*cm*cm);
295 setVariable("km3", km*km*km);
296
297 const double L = 1.e-3*m*m*m;
298 setVariable("liter", L);
299 setVariable("litre", L);
300 setVariable("L", L);
301 setVariable("centiliter", centi_ * L);
302 setVariable("cL", centi_ * L);
303 setVariable("milliliter", milli_ * L);
304 setVariable("mL", milli_ * L);
305
306 // Length^-1
307
308 const double dpt = 1./m;
309 setVariable("diopter", dpt);
310 setVariable("dioptre", dpt);
311 setVariable("dpt", dpt);
312
313 // Mass
314
315 const double g = 0.001*kg;
316 setVariable("gram", g);
317 setVariable("g", g);
318 setVariable("milligram", milli_ * g);
319 setVariable("mg", milli_ * g);
320
321 // Time
322
323 setVariable("millisecond", milli_ * s);
324 setVariable("ms", milli_ * s);
325 setVariable("microsecond", micro_ * s);
326 setVariable("us", micro_ * s);
327 setVariable("nanosecond", nano_ * s);
328 setVariable("ns", nano_ * s);
329 setVariable("picosecond", pico_ * s);
330 setVariable("ps", pico_ * s);
331
332 // Current
333
334 setVariable("milliampere", milli_ * A);
335 setVariable("mA", milli_ * A);
336 setVariable("microampere", micro_ * A);
337 setVariable("nanoampere", nano_ * A);
338
339 // Frequency
340
341 setVariable("kilohertz", kilo_ * Hz);
342 setVariable("kHz", kilo_ * Hz);
343 setVariable("megahertz", mega_ * Hz);
344 setVariable("MHz", mega_ * Hz);
345
346 // Force
347 setVariable("kilonewton", kilo_ * N);
348 setVariable("kN", kilo_ * N);
349
350 // Pressure
351 setVariable("kilobar", kilo_ * bar);
352 setVariable("kbar", kilo_ * bar);
353 setVariable("millibar", milli_ * bar);
354 setVariable("mbar", milli_ * bar);
355
356 // Energy
357 setVariable("kilojoule", kilo_ * J);
358 setVariable("kJ", kilo_ * J);
359 setVariable("megajoule", mega_ * J);
360 setVariable("MJ", mega_ * J);
361 setVariable("gigajoule", giga_ * J);
362 setVariable("GJ", giga_ * J);
363
364 const double e_SI = 1.60217733e-19; // positron charge in coulomb
365 const double ePlus = e_SI * C; // positron charge
366 const double eV = ePlus * V;
367 setVariable("electronvolt", eV);
368 setVariable("eV", eV);
369 setVariable("kiloelectronvolt", kilo_ * eV);
370 setVariable("keV", kilo_ * eV);
371 setVariable("megaelectronvolt", mega_ * eV);
372 setVariable("MeV", mega_ * eV);
373 setVariable("gigaelectronvolt", giga_ * eV);
374 setVariable("GeV", giga_ * eV);
375 setVariable("teraelectronvolt", tera_ * eV);
376 setVariable("TeV", tera_ * eV);
377 setVariable("petaelectronvolt", peta_ * eV);
378 setVariable("PeV", peta_ * eV);
379
380 // Power
381 setVariable("kilowatt", kilo_ * W);
382 setVariable("kW", kilo_ * W);
383 setVariable("megawatt", mega_ * W);
384 setVariable("MW", mega_ * W);
385 setVariable("gigawatt", giga_ * W);
386 setVariable("GW", giga_ * W);
387
388 // Electric potential
389 setVariable("kilovolt", kilo_ * V);
390 setVariable("kV", kilo_ * V);
391 setVariable("megavolt", mega_ * V);
392 setVariable("MV", mega_ * V);
393
394 // Electric capacitance
395 setVariable("millifarad", milli_ * F);
396 setVariable("mF", milli_ * F);
397 setVariable("microfarad", micro_ * F);
398 setVariable("uF", micro_ * F);
399 setVariable("nanofarad", nano_ * F);
400 setVariable("nF", nano_ * F);
401 setVariable("picofarad", pico_ * F);
402 setVariable("pF", pico_ * F);
403
404 // Magnetic flux density
405 setVariable("kilogauss", kilo_ * Gs);
406 setVariable("kGs", kilo_ * Gs);
407}
double S(double temp)
double C(double temp)
double A(double temperature)
const G4double pi

Referenced by G4GDMLEvaluator::Clear(), and G4GDMLEvaluator::G4GDMLEvaluator().

◆ setVariable() [1/2]

void HepTool::Evaluator::setVariable ( const char *  name,
const char *  expression 
)

Adds to the dictionary a variable with an arithmetic expression assigned to it. If a variable with such a name already exist in the dictionary, then status will be set to WARNING_EXISTING_VARIABLE.

Parameters
namename of the variable.
expressionarithmetic expression.

Definition at line 692 of file Evaluator.cc.

693{ setItem("", name, Item(expression), (Struct *)p); }

◆ setVariable() [2/2]

void HepTool::Evaluator::setVariable ( const char *  name,
double  value 
)

Adds to the dictionary a variable with given value. If a variable with such a name already exist in the dictionary, then status will be set to WARNING_EXISTING_VARIABLE.

Parameters
namename of the variable.
valuevalue assigned to the variable.

Definition at line 689 of file Evaluator.cc.

690{ setItem("", name, Item(value), (Struct *)p); }

Referenced by G4GDMLEvaluator::DefineConstant(), G4GDMLEvaluator::DefineVariable(), setStdMath(), setSystemOfUnits(), and G4GDMLEvaluator::SetVariable().

◆ status()

int HepTool::Evaluator::status ( ) const

Returns status of the last operation with the evaluator.

Definition at line 633 of file Evaluator.cc.

633 {
634 return ((Struct *)(p))->theStatus;
635}

Referenced by G4GDMLEvaluator::Evaluate(), and G4tgrUtils::GetDouble().


The documentation for this class was generated from the following files: