Previous: Pre-installed Classes
Up: Pre-installed Classes
Next: Environment Class
Previous Page: Pre-installed Classes
Next Page: Environment Class
Calculator objects contain an expression which tells the program how their values can be obtained from other DSPACK objects.
The user can program the calculator object by typing the expression interactively, placing it in the Object Description File or by calling
CALL dscprg (expression,ivdsn,ierr)
In all cases the class of the object is set to 'calc' and the type is set to 0.
Calculator object types:
Examples:
The first example shows how all items of an object can be calculated from another object. The calculation has to be performed only once. Simple calculator expressions
CALC VTP2_DIMS.FIRST_ROW = VTP2_SECTORS.ZC1-VTP2_SECTORS.DZ/2+VTP2_SECTORS.ZBORDER CALC VTP2_DIMS.ROW_STEP = (VTP2_SECTORS.DZ-2*VTP2_SECTORS.ZBORDER)/VTP2_SECTORS.NROWS CALC VTP2_DIMS.YMAX = VTP2_SECTORS.YC+VTP2_SECTORS.DY/2 CALC VTP2_DIMS.XMAX = VTP2_SECTORS.XC2+VTP2_SECTORS.DX/2 CALC VTP2_DIMS.XMIN = VTP2_SECTORS.XC2-VTP2_SECTORS.DX/2
The following example shows a series of calculations needed to find a mean value of pr_v1_guess.z and it's error. The calculation should be repeated once per event in order for the sums to be calculated. The object should be stored in section 2 (constants) and accessed exactly once per event. Calculator objects of type=2 - an example
DEFINE v1 S 2 .REAL4 sum .REAL4 ss .INT4 n .REAL4 z .REAL4 dz END DEFINECALC v1.sum = v1.sum + pr_v1_guess.z CALC v1.ss = v1.ss + pr_v1_guess.dz^2 CALC v1.n = v1.n + 1 CALC v1.z = v1.sum/v1.n CALC v1.dz = SQRT(v1.ss)/v1.n
RECLASS v1 -CLASS calc -TYPE 2 ! need to RECLASS - the default is TYPE=0
INIT v1 sum = 0.0 ss = 0.0 n = 0 END INIT
All calculations are performed on ALL entries of the source objects and the result will have the same number of entries as the source. In each expression all objects must either have the same number of entries or ONE entry - the element with one entry is treated as a constant and it's value is extended - repeated for all entries of other objects.
Calculator functions.
The full list of calculator functions is as follows:
Calculator functions
+ - * / SQRT LOG (ln) SQRE (x**2) EXP XtoY (X**Y)(X^Y) ABS NEG (-x) SIN COS TAN ASIN ACOS ATAN 1/X INT MAX (2 arguments) MIN (2 arguments) RAN (argument * random number (0:1)) PROB(X,N) (2 arguments) (CERNLIB PROB - G100 ) SUM - the sum of all entries NENT - number of entries AND OR XOR - (exclusive or) NOT > (gt) < (lt) = (eq) != (ne) >= (ge) <= (le) IND(N,X) - Nth entry of X TENT - number of true entries
If the calculator expression is programmed for an existing object, the result is converted to the type of the target object.
The logical functions produce logical results - if converted to integers or reals they are 0 for FALSE and -1 for TRUE.
Functions SUM, NENT and TENT result in a single entry when applied to multi-entry operands. If these functions are used as a part of larger expression - they behave like constants - they are repeated for each entry of the result. For IND(N,X) the number of entries in N determines the number of entries of the result.