# New experiment: error measures in one cycle, varying epsilon¶

## Motivation¶

As we already discussed, past experiments have shown some counterintuitive facts that are yet to be explained. On the one hand, the errors computed did not seem to change as epsilon was decreased . Also, we recently observed that Geant4 calls `AccurateAdvance` depending at least on the values of `stepMax` and `epsilon` . After further inspection, we have seen that this function is used even though `QuickAdvance` seems to provide acceptable results (fourth item on Nico's last email as of 2015-11-30).

In order to explore this, we designed a new experiment. The goal was not only to have a controlled trajectory with a fixed and well-known number of steps, but also to change the accuracy parameters together and keep them synchronized, since we were usually focusing on `epsilonMin` and `epsilonMax` alone. As we show below, these changes follow from the relationship between `deltaOneStep`, `stepMax`, `epsilonMin` and `epsilonMax` .

## Outline of the experiment¶

• The simulation consists of one full cycle of the particle. This was achieved by setting `trackMaxLen = p`, where `p` is the circle perimeter (see below).
• The idea was to keep the number of steps small, and so we defined `stepMax = p / SLICES`, being `SLICES` a constant with the value 10.
• As we are focusing on how `epsilon` and `deltaOneStep` interact with the step taken so as to decide whether or not `AccurateAdvance` is called, we set `deltaChord = p` just to keep it high enough and make sure that it does not interfere with the experiment.
• `deltaOneStep`, `epsilonMin` and `epsilonMax` are defined in terms of `stepMax` and an additional value `f`, which is the factor by which `stepMax` is divided:
• `deltaOneStep = stepMax / f`
• `epsilonMin = epsilonMax = 1 / f`
• This way, `epsilon = deltaOneStep / stepMax = stepMax / (f * stepMax) = 1 / f`, which explains why `epsilonMin` and `epsilonMax` take this value.
• Having this framework, the expriment iterates increasing values of `f` and takes measures of the maximum r_error obtained and the substep ratio for each run.
• Finally, for this experiment we added a new output line inside `G4ChordFinder::AdvanceChordLimited` so as to expose the values of `dyErr`, `epsStep` and `stepPossible` after calling `FindNextChord`, for each step of each run.

### Settings and definitions¶

• `p`: circle perimeter. Since its radius is ~38.0854 mm, `p ~= 239.2976256980574 mm`.
• `SLICES`: a constant value used to control the number of steps in each run. Set to 10 by default and generic settings.
• `f`: variable that defines how the accuracy parameters are obtained from `stepMax`. Each run uses a different value for `f`. The range we swept for the results below is `[100, 10^5)` with leaps of `10^4`.
• `r_error(t) = sqrt((G4x(t) - ANx(t))^2 + (G4y(t) - ANy(t))^2)`
• `StepRatio = RHS steps / (output steps * 11)`

## Results¶

• The following table summarizes the results we found:
f stepMax [mm] epsilonMin epsilonMax deltaOneStep [mm] max(r_error) [mm] StepRatio
100 23.9297625698 0.01 0.01 0.2392976257 0.000680661443008 1
10100 23.9297625698 0.0000990099 0.0000990099 0.0023692834 0.000689586107749 3
20100 23.9297625698 0.0000497512 0.0000497512 0.0011905355 0.000706697247766 4
30100 23.9297625698 0.0000332226 0.0000332226 0.0007950087 0.000719450484745 4
40100 23.9297625698 0.0000249377 0.0000249377 0.0005967522 0.000721110255093 4
50100 23.9297625698 0.0000199601 0.0000199601 0.0004776400 0.000722221572649 4
60100 23.9297625698 0.0000166389 0.0000166389 0.0003981658 0.000723336712742 4
70100 23.9297625698 0.0000142653 0.0000142653 0.0003413661 0.000723336712742 4
80100 23.9297625698 0.0000124844 0.0000124844 0.0002987486 0.000723895710721 4
90100 23.9297625698 0.0000110988 0.0000110988 0.0002655911 0.000723895710721 4

### Discussion¶

• We could not see significant changes in the errors. In fact, the variance of the errors is very small (~2.27e-10).
• Apparently `dyErr` is not changing, which is also rather surprising. The debug line we added always shows that `dyErr = 1.338101e-02`. In consequence, Geant4 should call `AccurateAdvance` if `epsStep <= 5.59178e-4 = dyErr / stepMax` (as `stepMax` is fixed). This last inequality holds for every `f` but 100.
• The `StepRatio` grows with `f`, which is reasonable. Lower values of `f` make `epsilon` larger, and thus less work is needed to fulfill this precision requirement.