**Table of contents**- Detection of intersection points in QSS3 and Geant4

# Detection of intersection points in QSS3 and Geant4¶

This page documents a new experiment recently performed to gain a better insight on how accurate are QSS3 and Geant4 when detecting crossing planes.

## Outline of the experiment¶

- We ran several simulations combining different number of planes, different values of
`epsilon`

/`dQRel`

and three track lengths (detailed below). - The
`(x, y)`

coordinates of the intersection points found throughout the simulations are parsed to generate a scatter plot with histograms for`x`

and`y`

. - Since the
`x`

coordinates of the planes are well known, the plot also includes vertical lines representing each crossing plane. This allows to quickly visualize how "meaningful" are the crossing points detected by each method (in fact, this helped us to identify and fix a bug in the QSS3 model triggered by an even number of planes). - In addition to this, we plotted histograms of the errors in
`x`

and`y`

when crossing a single plane.

### Parameter settings¶

- The planes used are a subset of those previously used on Nico's experiments (i.e., [1, 5, 10, 20, 40, 80]).
`epsilon`

/`dQRel`

: [1e-5, 1e-4, 1e-3]`trackMaxLen`

: [10 m, 100 m, 1000 m]- Remaining Geant4 parameters:
`stepMax`

: 20 mm`deltaOneStep`

: 0.01 mm`deltaInt`

: 1e-5 mm`deltaChord`

: 0.25 mm

- The 1 plane scenario was used to generate error plots with the following settings:
`trackMaxLen`

: 100 m (which yields roughly 418 crosses of the intersection point mentioned below)`epsilon`

/`dQRel`

: 1e-5- The intersection point we study is
`(x0, y0)`

=`(0, -2R)`

, being`R`

~ 38.08538603615 mm. Thus, the errors plotted are:`G4_x_err`

=`G4_x`

-`x0`

=`G4_x`

(analogous for`QSS3`

)`G4_y_err`

=`G4_y`

-`y0`

=`G4_y`

+`2R`

(analogous for`QSS3`

)

## Results¶

### Crossing planes placed on `x`

axis¶

#### Intersection points¶

- We attach the three plots for
`epsilon`

/`dRel`

= 1e-5 and 20 planes (other plots might be added later if requested). **Update:**the non-uniform shape on QSS' x-bins was being caused by an improper parsing of the output of the QSS solver.

`trackMaxLen = 10 m`

`trackMaxLen = 100 m`

`trackMaxLen = 1000 m`

#### Crossing plane detection error¶

- Histograms for
(blue) and`G4_x_err`

(red)`QSS3_x_err`

- Statistics

Error | Total samples | Unique samples | Mean | Standard deviation |
---|---|---|---|---|

`G4_x_err` |
418 | 47 | -5.24082e-17 | 1.03257e-15 |

`QSS3_x_err` |
418 | 418 | -1.00001e-09 | 2.9405e-12 |

- Histograms for
(blue) and`G4_y_err`

(red)`QSS3_y_err`

- Statistics

Error | Total samples | Unique samples | Mean | Standard deviation |
---|---|---|---|---|

`G4_y_err` |
418 | 418 | 0.00027773 | 5.16973e-09 |

`QSS3_y_err` |
418 | 418 | 0.0549559 | 0.0317135 |

#### Additional plots to understand G4's behavior¶

### Crossing planes placed on `y`

axis (QSS only)¶

#### Intersection points¶

`trackMaxLen = 100 m`

`trackMaxLen = 1000 m`

#### Crossing plane detection error¶

- Histogram for
`QSS3_x_err`

- Histograms for
`QSS3_y_err`

## Discussion¶

- At a first glance, both methods seem to detect intersection points reasonably.
- However, it is interesting to note that the
`y`

coordinates found by QSS3 tend to move towards the interior of the circumference --which becomes more noticeable with larger distances--, whereas Geant4 seems to remain stable regarding this issue.- This might be explained by recalling that, as we observed in past experiments,
`QSS3_r_error`

(i.e., the difference between the radius and the theoretical one) is generally below 0 and its absolute value keeps growing as the distance travelled increases (this was an expected behavior for a marginally stable system like the one we are studying). - On the other hand, we had also observed that
`G4_r_error`

does not vary significatively when the distance increases.

- This might be explained by recalling that, as we observed in past experiments,
- When
`dQRel`

is decreased, it can be seen that the accuracy of the`y`

coordinates found by QSS3 is even worse, which is reasonable. This does not apply to Geant4, but this is also an expected behavior as`epsilon`

is not involved in the accuracy of the intersection points.

### Error distribution¶

- The histograms for the error in
`x`

show that both methods are good at detecting intersections.- The average QSS3 error is four orders of magnitude below
`dQRel`

= 1e-5. - Even though Geant4 yielded better results, with errors several orders of magnitude below those of QSS3 and closer to zero, we still need to run QSS3 simulations with smaller
`dQRel`

values, which might increase the accuracy of the detection. Currently, however, our lower bound is 1e-5 as the solver fails to run the simulation if this precision is increased. QSS expert Dr. Federico Bergero suggested that the cause of this is chattering (a phenomenon triggered by the discontinuities in the model).

- The average QSS3 error is four orders of magnitude below
- On the other hand,
`y`

errors are rather high for QSS3. Nevertheless, this accuracy loss comes, as mentioned above, from the energy losses due to the unsuitability of this method to handle marginally stable systems as the current one.

## Implementation details¶

### Geant4¶

- In order to retrieve the intersection points, we added a temporary print statement in
`G4PropagatorInField::ComputeStep`

just after calling`EstimateIntersectionPoint`

and confirming that an intersection was found. - In changeset 0ab505d2, the N02 code was extended with new functionality to allow modifying the number of crossing planes from macro files. This was later used by our parameter sweeper script to gather the data used in this experiment.

### QSS3¶

- The micoModelica model used by Nico was slightly modified. New variables to capture the coordinates of the intersection points were added.
- In the process, we discovered a bug in the QSS solver when dealing with these new variables.
- In addition, we found that the original model was not computing properly the
`x`

coordinates of the intersection planes when an even number of such planes was used (the planes were equidistantly placed but slightly out of phase).