# Iterative DoDistortions in StMagUtilities

StMagUtilities corrections for distortions were implemented with the expectation that the displacements due to distortions do not vary significantly over distances comparable to those displacements. More specifically, using D(x) to denote the distortion displacement at x:
• if x' = x + D(x)... then D(x') = D(x)
Which then implies:
• if x' = x + D(x)... then x = x' - D(x')
In English, this perturbative approach means the distortion can be calculated at the location of either the reconstruced distorted hit, or the generated hit. I believe I checked that this held true to within a few microns just a few years ago. However, Yuri has noted it not to be true with the large distortions that existed in Run 12 pp510 data. I confirmed this is now worth worrying about and looking into a possible solution:
• if x' = x + D(x)... then, since we know x' a priori but not x...
• while (|D(x'i)-D(x'i-1)| > C) x'i+1 = x'0 - D(x'i)
• ...for which we expect limi→∞x'i = x {to within ~±C}
• ...allowing us to recover x = x' - D(x)
Where C is some satisfactory maximim limit on the precision for which we look for convergence. Note that the iteration needs only to be done on either the DoDistortion() or UndoDistortion(), but not both. It should depend on whether D(x) is calculated as a distortion or correction. In reality, I believe D(x) is currently calculated in StMagUtilities as a distortion, so it is UndoDistortion() which should use the iterative solution. However, to learn something more, it was simpler to implement DoDistortion() as the iterative function. This is just a test and I do not believe this is how it should be permanently implemented.

I present here some things I found using C = 1.0 micron and examining the highest luminosity good run which include the TPC (13099025), using zerobias (i.e. pile-up) data.

Here are the number of iterations it takes to satisfy convergence (given that it did converge); the mean number of iterations is 4.146: Here is the final transverse displacement after convergence vs. the displacement from the first iteration (which represents what we do now with no iteration), and then the difference in these two displacements vs. the number of iterations it took to satisfy convergence. We can see that not iterating can result in as much as a 1.5 cm error in the assigned distortion displacement, though I will note that the mean absolute error is 0.086 cm (860 microns) and the maximum error near the padrows is just below 1.0 cm (the 1.5 cm maximum is observed at radii closer to the inner field cage). There is a class of hits at 25 iterations which indicates they did not converge (I set a limit at 25).  Next is what I call the "route to convergence", which shows the incremental improvement in any iteration vs. the incremental improvement of the previous iteration (essentially |x'i+1-x'i| vs. |x'i-x'i-1| ), where the color is the iteration (purple is the first iteration i=1, dark blue is i=2, etc...) Next I try to show where in the TPC it took longest to converge, by showing y vs. x and r vs. z, using color to represent the number of iterations it took to converge (the red points are where convergence did not occur, otherwise convergence is generally quickest at the outer radii and shortest drift and slowest at the inner radii and longest drift):  Regarding the points near the GridLeak sheet of ionic charge, what appears to be happening is a back-and-forth between two positions. Here is an example:

iteration x y z
0 -3.533849 -121.6399 158.79699
1 -3.787230 -121.833 158.79699
2 -3.005870 -121.4359 158.79699
3 -3.787230 -121.833 158.79699
4 -3.005870 -121.4359 158.79699
... ... ... ...

The above example is for a hit that's moving ~1 cm between iterations for the corrected position. Among these un-converged hits, this is not extraordinary as the distance some of these hits "wobble" can be up to 3.2 cm in the data I examined.

-Gene