Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-02 07:50:36

0001 #!/usr/bin/env python3
0002 
0003 import tempfile
0004 from pathlib import Path
0005 import shutil
0006 
0007 import acts
0008 from acts.examples.simulation import (
0009     addFatras,
0010     addGeant4,
0011     addPythia8,
0012 )
0013 
0014 from physmon_common import makeSetup
0015 
0016 u = acts.UnitConstants
0017 
0018 setup = makeSetup()
0019 
0020 
0021 with tempfile.TemporaryDirectory() as temp:
0022     tp = Path(temp)
0023 
0024     rnd = acts.examples.RandomNumbers(seed=42)
0025 
0026     s = acts.examples.Sequencer(
0027         events=1000,
0028         numThreads=1,
0029         logLevel=acts.logging.INFO,
0030     )
0031 
0032     for d in setup.decorators:
0033         s.addContextDecorator(d)
0034 
0035     s.addReader(
0036         acts.examples.EventGenerator(
0037             level=acts.logging.INFO,
0038             generators=[
0039                 acts.examples.EventGenerator.Generator(
0040                     multiplicity=acts.examples.FixedMultiplicityGenerator(n=1),
0041                     vertex=acts.examples.GaussianVertexGenerator(
0042                         mean=acts.Vector4(0, 0, 0, 0),
0043                         stddev=acts.Vector4(10 * u.um, 10 * u.um, 50 * u.mm, 1 * u.ns),
0044                     ),
0045                     particles=acts.examples.ParametricParticleGenerator(
0046                         p=(1 * u.GeV, 100 * u.GeV),
0047                         pTransverse=True,
0048                         eta=(-3.0, 3.0),
0049                         phi=(0.0 * u.degree, 360.0 * u.degree),
0050                         pdg=pdg,
0051                         randomizeCharge=True,
0052                     ),
0053                 )
0054                 for pdg in [
0055                     acts.PdgParticle.eMuon,
0056                     acts.PdgParticle.ePionPlus,
0057                     acts.PdgParticle.eElectron,
0058                 ]
0059             ],
0060             randomNumbers=rnd,
0061             outputEvent="particle_gun_event",
0062         )
0063     )
0064 
0065     s.addAlgorithm(
0066         acts.examples.hepmc3.HepMC3InputConverter(
0067             level=acts.logging.INFO,
0068             inputEvent="particle_gun_event",
0069             outputParticles="particles_generated",
0070             outputVertices="vertices_input",
0071             mergePrimaries=False,
0072         )
0073     )
0074 
0075     s.addWriter(
0076         acts.examples.RootParticleWriter(
0077             level=acts.logging.INFO,
0078             inputParticles="particles_generated",
0079             filePath=tp / "particles.root",
0080         )
0081     )
0082 
0083     addFatras(
0084         s,
0085         setup.trackingGeometry,
0086         setup.field,
0087         rnd,
0088         enableInteractions=True,
0089         inputParticles="particles_generated",
0090         outputParticles="particles_fatras",
0091         outputSimHits="simhits_fatras",
0092         outputDirRoot=tp / "fatras",
0093     )
0094 
0095     addGeant4(
0096         s,
0097         setup.detector,
0098         setup.trackingGeometry,
0099         setup.field,
0100         rnd,
0101         killVolume=setup.trackingGeometry.highestTrackingVolume,
0102         killAfterTime=25 * u.ns,
0103         killSecondaries=True,
0104         inputParticles="particles_generated",
0105         outputParticles="particles_geant4",
0106         outputSimHits="simhits_geant4",
0107         outputDirRoot=tp / "geant4",
0108     )
0109 
0110     s.run()
0111 
0112     for file, name in [
0113         (tp / "particles.root", "particles_gun.root"),
0114         (tp / "fatras" / "particles_simulation.root", "particles_fatras.root"),
0115         (tp / "geant4" / "particles_simulation.root", "particles_geant4.root"),
0116     ]:
0117         assert file.exists(), "file not found"
0118         shutil.copy(file, setup.outdir / name)
0119 
0120 with tempfile.TemporaryDirectory() as temp:
0121     s = acts.examples.Sequencer(
0122         events=3,
0123         numThreads=1,  # Pythia8 does not give identical results otherwise
0124         logLevel=acts.logging.INFO,
0125     )
0126 
0127     tp = Path(temp)
0128 
0129     for d in setup.decorators:
0130         s.addContextDecorator(d)
0131 
0132     rnd = acts.examples.RandomNumbers(seed=42)
0133 
0134     addPythia8(
0135         s,
0136         hardProcess=["Top:qqbar2ttbar=on"],
0137         npileup=200,
0138         vtxGen=acts.examples.GaussianVertexGenerator(
0139             mean=acts.Vector4(0, 0, 0, 0),
0140             stddev=acts.Vector4(0.0125 * u.mm, 0.0125 * u.mm, 55.5 * u.mm, 5.0 * u.ns),
0141         ),
0142         rnd=rnd,
0143         outputDirRoot=tp,
0144     )
0145 
0146     s.run()
0147 
0148     for file, name in [
0149         (tp / "particles.root", "particles_ttbar.root"),
0150         (tp / "vertices.root", "vertices_ttbar.root"),
0151     ]:
0152         assert file.exists(), "file not found"
0153         shutil.copy(file, setup.outdir / name)