Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:09

0001 #!/usr/bin/env python3
0002 
0003 import os
0004 import acts
0005 import acts.examples
0006 from acts.examples import GenericDetector, AlignedDetector
0007 from acts.examples.odd import getOpenDataDetectorDirectory
0008 from acts.examples.simulation import (
0009     addParticleGun,
0010     EtaConfig,
0011     ParticleConfig,
0012     MomentumConfig,
0013 )
0014 
0015 u = acts.UnitConstants
0016 
0017 
0018 def runPropagation(trackingGeometry, field, outputDir, s=None, decorators=[]):
0019     s = s or acts.examples.Sequencer(events=100, numThreads=1)
0020 
0021     for d in decorators:
0022         s.addContextDecorator(d)
0023 
0024     rnd = acts.examples.RandomNumbers(seed=42)
0025 
0026     addParticleGun(
0027         s,
0028         ParticleConfig(num=1000, pdg=acts.PdgParticle.eMuon, randomizeCharge=True),
0029         EtaConfig(-4.0, 4.0),
0030         MomentumConfig(1 * u.GeV, 100 * u.GeV, transverse=True),
0031         rnd=rnd,
0032     )
0033 
0034     trkParamExtractor = acts.examples.ParticleTrackParamExtractor(
0035         level=acts.logging.WARNING,
0036         inputParticles="particles_input",
0037         outputTrackParameters="params_particles_input",
0038     )
0039     s.addAlgorithm(trkParamExtractor)
0040 
0041     nav = acts.Navigator(trackingGeometry=trackingGeometry)
0042 
0043     stepper = acts.EigenStepper(field)
0044     # stepper = acts.AtlasStepper(field)
0045     # stepper = acts.StraightLineStepper()
0046 
0047     propagator = acts.examples.ConcretePropagator(acts.Propagator(stepper, nav))
0048 
0049     propagationAlgorithm = acts.examples.PropagationAlgorithm(
0050         propagatorImpl=propagator,
0051         level=acts.logging.INFO,
0052         sterileLogger=True,
0053         inputTrackParameters="params_particles_input",
0054         outputSummaryCollection="propagation_summary",
0055     )
0056     s.addAlgorithm(propagationAlgorithm)
0057 
0058     s.addWriter(
0059         acts.examples.RootPropagationSummaryWriter(
0060             level=acts.logging.INFO,
0061             inputSummaryCollection="propagation_summary",
0062             filePath=outputDir + "/propagation_summary.root",
0063         )
0064     )
0065 
0066     return s
0067 
0068 
0069 if "__main__" == __name__:
0070     matDeco = None
0071     # matDeco = acts.IMaterialDecorator.fromFile("material.json")
0072     # matDeco = acts.IMaterialDecorator.fromFile("material.root")
0073 
0074     ## Generic detector: Default
0075     detector = GenericDetector(mdecorator=matDeco)
0076 
0077     ## Alternative: Aligned detector in a couple of modes
0078     # detector = AlignedDetector(
0079     #     decoratorLogLevel=acts.logging.INFO,
0080     #     # These parameters need to be tuned so that GC doesn't break
0081     #     # with multiple threads
0082     #     iovSize=10,
0083     #     flushSize=10,
0084     #     # External alignment store
0085     #     mode=AlignedDetector.Config.Mode.External,
0086     #     # OR: Internal alignment storage
0087     #     # mode=AlignedDetector.Config.Mode.Internal,
0088     # )
0089 
0090     ## Alternative: DD4hep detector
0091     # dd4hepCfg = acts.examples.DD4hepDetector.Config()
0092     # dd4hepCfg.xmlFileNames = [str(getOpenDataDetectorDirectory()/"xml/OpenDataDetector.xml")]
0093     # detector = acts.examples.DD4hepDetector(dd4hepCfg)
0094 
0095     trackingGeometry = detector.trackingGeometry()
0096     contextDecorators = detector.contextDecorators()
0097 
0098     ## Magnetic field setup: Default: constant 2T longitudinal field
0099     field = acts.ConstantBField(acts.Vector3(0, 0, 2 * acts.UnitConstants.T))
0100 
0101     ## Alternative: no B field
0102     # field = acts.NullBField()
0103 
0104     ## Alternative: Analytical solenoid B field, discretized in an interpolated field map
0105     # solenoid = acts.SolenoidBField(
0106     #     radius = 1200*u.mm,
0107     #     length = 6000*u.mm,
0108     #     bMagCenter = 2*u.T,
0109     #     nCoils = 1194
0110     # )
0111     # field = acts.solenoidFieldMap(
0112     #     rlim=(0, 1200*u.mm),
0113     #     zlim=(-5000*u.mm, 5000*u.mm),
0114     #     nbins=(50, 50),
0115     #     field=solenoid
0116     # )
0117 
0118     os.makedirs(os.getcwd() + "/propagation", exist_ok=True)
0119 
0120     runPropagation(
0121         trackingGeometry,
0122         field,
0123         os.getcwd() + "/propagation",
0124         decorators=contextDecorators,
0125     ).run()