Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:10:09

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