Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
propagation.py
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file propagation.py
1 #!/usr/bin/env python3
2 import os
3 
4 import acts
5 import acts.examples
6 
7 from acts.examples import GenericDetector, AlignedDetector
8 from common import getOpenDataDetectorDirectory
9 
10 u = acts.UnitConstants
11 
12 
13 def runPropagation(trackingGeometry, field, outputDir, s=None, decorators=[]):
14  s = s or acts.examples.Sequencer(events=100, numThreads=1)
15 
16  for d in decorators:
17  s.addContextDecorator(d)
18 
19  rnd = acts.examples.RandomNumbers(seed=42)
20 
21  nav = acts.Navigator(trackingGeometry=trackingGeometry)
22 
23  stepper = acts.EigenStepper(field)
24  # stepper = acts.AtlasStepper(field)
25  # stepper = acts.StraightLineStepper()
26 
27  print("We're running with:", type(stepper).__name__)
29 
30  alg = acts.examples.PropagationAlgorithm(
31  propagatorImpl=prop,
32  level=acts.logging.INFO,
33  randomNumberSvc=rnd,
34  ntests=1000,
35  sterileLogger=True,
36  propagationStepCollection="propagation-steps",
37  )
38 
39  s.addAlgorithm(alg)
40 
41  # Output
42  s.addWriter(
43  acts.examples.ObjPropagationStepsWriter(
44  level=acts.logging.INFO,
45  collection="propagation-steps",
46  outputDir=outputDir + "/obj",
47  )
48  )
49 
50  s.addWriter(
51  acts.examples.RootPropagationStepsWriter(
52  level=acts.logging.INFO,
53  collection="propagation-steps",
54  filePath=outputDir + "/propagation_steps.root",
55  )
56  )
57 
58  return s
59 
60 
61 if "__main__" == __name__:
62  matDeco = None
63  # matDeco = acts.IMaterialDecorator.fromFile("material.json")
64  # matDeco = acts.IMaterialDecorator.fromFile("material.root")
65 
66  ## Generic detector: Default
67  (
68  detector,
69  trackingGeometry,
70  contextDecorators,
71  ) = GenericDetector.create(mdecorator=matDeco)
72 
73  ## Alternative: Aligned detector in a couple of modes
74  # detector, trackingGeometry, contextDecorators = AlignedDetector.create(
75  # decoratorLogLevel=acts.logging.INFO,
76  # # These parameters need to be tuned so that GC doesn't break
77  # # with multiple threads
78  # iovSize=10,
79  # flushSize=10,
80  # # External alignment store
81  # mode=AlignedDetector.Config.Mode.External,
82  # # OR: Internal alignment storage
83  # # mode=AlignedDetector.Config.Mode.Internal,
84  # )
85 
86  ## Alternative: DD4hep detector
87  # dd4hepCfg = acts.examples.DD4hepDetector.Config()
88  # dd4hepCfg.xmlFileNames = [str(getOpenDataDetectorDirectory()/"xml/OpenDataDetector.xml")]
89  # detector = acts.examples.DD4hepDetector()
90  # trackingGeometry, contextDecorators = detector.finalize(dd4hepCfg, None)
91 
92  ## Magnetic field setup: Default: constant 2T longitudinal field
93  field = acts.ConstantBField(acts.Vector3(0, 0, 2 * acts.UnitConstants.T))
94 
95  ## Alternative: no B field
96  # field = acts.NullBField()
97 
98  ## Alternative: Analytical solenoid B field, discretized in an interpolated field map
99  # solenoid = acts.SolenoidBField(
100  # radius = 1200*u.mm,
101  # length = 6000*u.mm,
102  # bMagCenter = 2*u.T,
103  # nCoils = 1194
104  # )
105  # field = acts.solenoidFieldMap(
106  # rlim=(0, 1200*u.mm),
107  # zlim=(-5000*u.mm, 5000*u.mm),
108  # nbins=(50, 50),
109  # field=solenoid
110  # )
111 
113  trackingGeometry, field, os.getcwd(), decorators=contextDecorators
114  ).run()