Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:13:26

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             outputParticles="particles_generated",
0061             outputVertices="vertices_input",
0062             randomNumbers=rnd,
0063         )
0064     )
0065 
0066     s.addWriter(
0067         acts.examples.RootParticleWriter(
0068             level=acts.logging.INFO,
0069             inputParticles="particles_generated",
0070             filePath=tp / "particles.root",
0071         )
0072     )
0073 
0074     addFatras(
0075         s,
0076         setup.trackingGeometry,
0077         setup.field,
0078         rnd,
0079         enableInteractions=True,
0080         inputParticles="particles_generated",
0081         outputParticles="particles_fatras",
0082         outputSimHits="simhits_fatras",
0083         outputDirRoot=tp / "fatras",
0084     )
0085 
0086     addGeant4(
0087         s,
0088         setup.detector,
0089         setup.trackingGeometry,
0090         setup.field,
0091         rnd,
0092         killVolume=setup.trackingGeometry.highestTrackingVolume,
0093         killAfterTime=25 * u.ns,
0094         killSecondaries=True,
0095         inputParticles="particles_generated",
0096         outputParticles="particles_geant4",
0097         outputSimHits="simhits_geant4",
0098         outputDirRoot=tp / "geant4",
0099     )
0100 
0101     s.run()
0102 
0103     for file, name in [
0104         (tp / "particles.root", "particles_gun.root"),
0105         (tp / "fatras" / "particles_simulation.root", "particles_fatras.root"),
0106         (tp / "geant4" / "particles_simulation.root", "particles_geant4.root"),
0107     ]:
0108         assert file.exists(), "file not found"
0109         shutil.copy(file, setup.outdir / name)
0110 
0111 with tempfile.TemporaryDirectory() as temp:
0112     s = acts.examples.Sequencer(
0113         events=3,
0114         numThreads=-1,
0115         logLevel=acts.logging.INFO,
0116     )
0117 
0118     tp = Path(temp)
0119 
0120     for d in setup.decorators:
0121         s.addContextDecorator(d)
0122 
0123     rnd = acts.examples.RandomNumbers(seed=42)
0124 
0125     addPythia8(
0126         s,
0127         hardProcess=["Top:qqbar2ttbar=on"],
0128         npileup=200,
0129         vtxGen=acts.examples.GaussianVertexGenerator(
0130             mean=acts.Vector4(0, 0, 0, 0),
0131             stddev=acts.Vector4(0.0125 * u.mm, 0.0125 * u.mm, 55.5 * u.mm, 5.0 * u.ns),
0132         ),
0133         rnd=rnd,
0134         outputDirRoot=tp,
0135     )
0136 
0137     s.run()
0138 
0139     for file, name in [
0140         (tp / "particles.root", "particles_ttbar.root"),
0141         (tp / "vertices.root", "vertices_ttbar.root"),
0142     ]:
0143         assert file.exists(), "file not found"
0144         shutil.copy(file, setup.outdir / name)