LDMX-Software / SimCore

Integration of Geant4 simulation framework into a more generalized event processing framework.
2 stars 0 forks source link

8GeV generator not centering the beam #97

Closed tomeichlersmith closed 1 year ago

tomeichlersmith commented 1 year ago

The 8GeV electron generator is not centering the beam on the target and now that I mention it, the 4GeV beam isn't doing that either although they are both within ~5mm of the center in the horizontal direction and seemingly perfectly centered vertically.

target_sim_hits

These distributions were made using the 4gev and 8gev particle gun generators currently in SimCore and then a filter on the total energy of the primary electron as it reaches the ECal was applied. This was the sample I had readily available for my work with EaT, it'll probably be a good idea to do an unfiltered sample to make sure my selection isn't biasing how the electron reaches the target.

tomeichlersmith commented 1 year ago

Looking at the scoring planes so I can more easily inspect the momentum of the primary at the target, I also can select out only the primary particle which is helpful for removing all the noise from soft particles polluting the position diagram. This makes the picture look a bit nicer for the 4GeV beam.

primary-tgt-xy

The main issue is that the current 8GeV beam is not normal to the target surface when it is incident. It is pretty close but not as tuned as we'd like for the large studies we are interested in doing. We could maybe improve the 4GeV beam as well, but I'm unsure if that is possible given how much material is in the way. As the position plot implies, we are alright in $p_y$, its just the $p_x$ affected by the magnet which is complicated.

primary-tgt-px primary-tgt-py

tomeichlersmith commented 1 year ago

The central peak of the distribution is the full-energy primaries as expected. This is what we want to be centered on (or near) zero. If it can be on zero, then we want to preference slightly high $p_x$ since any loss of momentum will bend the electron in the negative $x$ direction.

primary-tgt-px-high-energy

tomeichlersmith commented 1 year ago

We already calculate the direction vector from the angle so I'm thinking maybe we just calculate the direction and transverse position from the gyro-radius. This is relatively simple:

# input energy of particle in GeV
E = 4 # or 8 GeV
# approximate our field as 1.5T uniform field along y
B = 1.5 # T
# the gyroradius calculated from our magnetic field assuming uniformity
#   we just use E instead of p here because the electron mass is negligible at these energies
R = 3.3*E/B*1000 # mm
# the desired distance from the target in z
z = 880 # mm
# then we can get the transverse displacement and direction vector
x = R - sqrt(R**2 - z**2)
position = [ -x, 0, -z ]
direction = [ z/R, 0, (R-x)/R ]
tomeichlersmith commented 1 year ago

Using the naive gyro radius definitely gets us closer for the 8GeV beam but it moves the 4GeV beam away from the center. I'm guessing this is because there is a portion of the electron's flight where it is only in the fringe field of the magnet and so its not "feeling" the full 1.5T during that early part. It seems like it is overshooting the entry angle slightly so I'm going to start playing with rotating the direction around y ever so slightly to try to account for this fringe field.

output_5_0 output_5_1

This uploaded tar-ball has the config I used as well as the jupyter notebook I used to make the plot.

bryngemark commented 1 year ago

Hi @tomeichlersmith, one way I've suggested doing this in the past (and I think andrew tried) is to take out all the upstream material and shoot positrons from (0,0,0) and see where they end up at your desired starting z. This should tell you how to account for the non-homogeneities of the actual field.

tomeichlersmith commented 1 year ago

Removing the detector components and shooting positrons backwards (and then multiplying their endpoint momentum by -1) provides interesting results. Interestingly, within calculational error, it appears like both beams should have the same transverse momentum. Maybe this makes sense but I found it interesting.

beam x y z px py pz
4 -600.8976671223825 0.0 -6000.0 434.54358639748824 8.334844963520257e-05 3976.8404168653105
8 -299.2386690361795 0.0 -6000.0 434.59720869099084 8.34525312746188e-05 7988.698324864931
tomeichlersmith commented 1 year ago

Interestingly, using the "From Positron" initial values (above) causes the vertex to end up slightly bent away from perfectly centered. It ends up being a little "over bended" compared to the "Gyro" initial state being "under bended". This is after putting the upstream detectors back in and so perhaps we want this "over bending" from detector material to be there for realism sake? I guess it depends on how we expect the detector be be built - will we be able to move our components as we use the beam to observe their placement or not? Without putting the upstream detectors back in, we simply get delta-function-like spikes near the peaks of these distributions.

primary-tgt

tomeichlersmith commented 1 year ago

I'm going to use these values for actually implementing this

beam x y z px py pz
4 -600.8976671223585 0.0 -6000.0 434.54301089006407 -0.0 3976.8404804302777
8 -299.2386690686212 0.0 -6000.0 434.59663056485 -0.0 7988.698356992288
1.2 -2083.3707473241993 0.0 -6000.0 425.132266424426 -0.0 1122.7149711218378

Looking into it, the mean of these just picked out a few floating-point errors along the y direction. These are the modes (down to floating point precision) and so they should be good.

tomeichlersmith commented 1 year ago

Resolved by #98