# GDML expression square a value

When using an expression in GDML what standard do I follow for performing math? Expressions are not mentioned in the GDML manual.

For example, I need to compute the square of a value, which choice works and which is best?

``````<expression name="value_squared">
value**2
</expression>
``````

OR

``````<expression name="value_squared">
pow(value, 2)
</expression>
``````

OR

``````<expression name="value_squared">
value*value
</expression>
``````

OR

``````<expression name="value_squared">
value^2
</expression>
``````

Hi,

in Geant4, the expressions are evaluated using CLHEP evaluator, which says:

/**

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

so, all the choices you have mentioned except ‘pow’ should work.

In ROOT, it is the TFormula that is used to evaluate expressions:

double TGDMLParse::Evaluate(const char* evalline)
{
return TFormula(“TFormula”, evalline).Eval(0);
}

however, looking at TGDMLParse::ParseGDML method, it seems to me that the support for the GDML tag “expression” is missing (however, you can use arithmetic expressions inside other tags involving numerical values, like position, etc).

Cheers,
Witek

A quick summary, every choice from above seems to be supported in Geant4 (even pow seemed to work), but ROOT lacks support for the expression tag altogether?

Your description from CLHEP doesn’t seem to clarify the difference between `^` and `**`, are they the same?

^ and ** are the same.

Yes, ROOT seems to lack the support for the expression tag.

Indeed, ROOT GDML parser lacks support for the “expression” tag, all expressions are evaluated “inline” using TFormula

So the expressions are not being ignored?

Yes, in the sense that constructs like 10.*sqrt(2.) are evaluated.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.