acts icon indicating copy to clipboard operation
acts copied to clipboard

Bug: fatras different particle final states between python and executable

Open CouthuresJeremy opened this issue 4 years ago • 6 comments

Hi, I saw a small difference in the particle final states between python and executable when running fatras.

Here are the args that I used for the executable:

ActsExampleFatrasGeneric \
  --events=1 \
  --rnd-seed=42 \
  --gen-eta=-4:4 \
  --gen-mom-gev=1:5 \
  --gen-mom-transverse \
  --gen-pdg=13 \
  --gen-randomize-charge \
  --bf-constant-tesla=0:0:2 \
  --output-dir=fatras \
  --output-csv \
  --loglevel=0

Here is the python file that I used:

#!/usr/bin/env python3
import pathlib, acts, acts.examples

u = acts.UnitConstants
outputDir = pathlib.Path.cwd()

gdc = acts.examples.GenericDetector.Config()
detector = acts.examples.GenericDetector()
trackingGeometry, contextDecorators = detector.finalize(gdc, None)

field = acts.ConstantBField(acts.Vector3(0.0, 0.0, 2.0 * u.T))
rnd = acts.examples.RandomNumbers(seed=42)

from particle_gun import addParticleGun, MomentumConfig, EtaConfig, ParticleConfig
from fatras import addFatras

s = acts.examples.Sequencer(events=1, numThreads=-1)
s.config.logLevel = acts.logging.VERBOSE
s = addParticleGun(
    s,
    momentumConfig=MomentumConfig(1.0 * u.GeV, 5.0 * u.GeV, True),
    etaConfig=EtaConfig(-4.0, 4.0),
    particleConfig=ParticleConfig(1, acts.PdgParticle.eMuon, True),
    rnd=rnd,
)

s = addFatras(
    s,
    trackingGeometry,
    field,
    outputDirCsv = outputDir / "csv",
    rnd=rnd,
)
s.run()

event000000000-particles_final.csv: Executable:

particle_id,particle_type,process,vx,vy,vz,vt,px,py,pz,m,q
4503599644147712,13,0,-715.953308,738.44519,84.6097717,3.44791126,-2.75245881,2.39595652,0.301638216,0.105658367,-1

Python:

particle_id,particle_type,process,vx,vy,vz,vt,px,py,pz,m,q
4503599644147712,13,0,-715.985718,738.413757,85.0053482,3.44800162,-2.76315808,2.40676093,0.30248946,0.105658367,-1

First difference that I saw in the logs: Executable:

16:56:57    Simulation     VERBOSE   BeamPipe::Barrel | Try to find boundaries, 
we are at: -12.0544  14.6864  1.56843, dir: -0.633436  0.769426 0.0821147

Python:

16:56:58    Simulation     VERBOSE   BeamPipe::Barrel | Try to find boundaries, 
we are at: -12.0544  14.6864  1.56843, dir: -0.633487  0.769367 0.0822692

Does anyone have an idea of where it might come from?

CouthuresJeremy avatar Mar 31 '22 15:03 CouthuresJeremy

Hey @CouthuresJeremy, thanks for reporting this!

@timadye, does this look like the discrepancy between the two implementations that you observed?

paulgessinger avatar Mar 31 '22 16:03 paulgessinger

Hi @CouthuresJeremy, Thanks for checking this. That is very useful. I didn't do an exact comparison between the C++ and Python implementations, just checking the distributions. I did do some exact comparisons with some changes in the Python implementation. One oddity that @paulgessinger might have been referring to was including a preselector before the Fatras step. Even with a preselector that should select all particles, I saw small differences later on. #1174 has an option to disable the preselection. I hope that will be merged soon, but in the meantime, could you try commenting out the ParticleSelector in fatras.py lines 39-43 and replacing selector.config.outputParticles with "particles_input". I can also try this...

timadye avatar Apr 01 '22 11:04 timadye

Hi @timadye, Here are the results that I've got: With ParticleSelector in fatras.py:

particle_id,particle_type,process,vx,vy,vz,vt,px,py,pz,m,q
4503599644147712,13,0,-715.985718,738.413757,85.0053482,3.44800162,-2.76315808,2.40676093,0.30248946,0.105658367,-1

Without ParticleSelector in fatras.py:

particle_id,particle_type,process,vx,vy,vz,vt,px,py,pz,m,q
4503599644147712,13,0,-715.985718,738.413757,85.0053482,3.44800162,-2.76315808,2.40676093,0.30248946,0.105658367,-1

I don't see any difference between those two.

I saw #1174 and I can say that it is very useful for someone who started to use the Python Bindings this week.

CouthuresJeremy avatar Apr 01 '22 12:04 CouthuresJeremy

Just to confirm, I see the same effect that @CouthuresJeremy described (using #1174). And using preselectParticles=False makes no difference.

Sorry, that doesn't add anything to @CouthuresJeremy's observation.

timadye avatar Apr 01 '22 18:04 timadye

One idea...

We have the same input particle, and Fatras makes small changes to the output particile. So I guess it's different multiple scattering or energy loss.

A real difference might be that there is some configuration that isn't being picked up in one or the other.

A spurious difference might be that those effects are calculated in a different order, so the random number generator gives different results.

Just random (pun intended) speculation.

timadye avatar Apr 01 '22 18:04 timadye

This issue/PR has been automatically marked as stale because it has not had recent activity. The stale label will be removed if any interaction occurs.

stale[bot] avatar May 01 '22 18:05 stale[bot]

Since we removed the examples binaries in

  • https://github.com/acts-project/acts/pull/2685

I think, we can close this issue.

AJPfleger avatar May 22 '24 08:05 AJPfleger