Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
event_recording.py
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file event_recording.py
1 #!/usr/bin/env python3
2 import os
3 from pathlib import Path
4 
5 import acts
6 import acts.examples
7 
13 
14 u = acts.UnitConstants
15 
16 from common import getOpenDataDetectorDirectory
17 from acts.examples.odd import getOpenDataDetector
18 
19 
20 def runEventRecording(detectorConstructionFactory, outputDir, s=None):
21  hepmc_dir = os.path.join(outputDir, "hepmc3")
22  if not os.path.exists(hepmc_dir):
23  os.mkdir(hepmc_dir)
24 
25  s = s or acts.examples.Sequencer(
26  events=int(os.environ.get("NEVENTS", 100)), numThreads=1
27  )
28 
29  rnd = acts.examples.RandomNumbers(seed=42)
30  evGen = acts.examples.EventGenerator(
31  level=acts.logging.INFO,
32  generators=[
33  acts.examples.EventGenerator.Generator(
34  multiplicity=acts.examples.FixedMultiplicityGenerator(n=2),
35  vertex=acts.examples.GaussianVertexGenerator(
36  stddev=acts.Vector4(0, 0, 0, 0), mean=acts.Vector4(0, 0, 0, 0)
37  ),
38  particles=acts.examples.ParametricParticleGenerator(
39  p=(1 * u.GeV, 10 * u.GeV),
40  eta=(-2, 2),
41  phi=(0, 90 * u.degree),
42  randomizeCharge=True,
43  numParticles=4,
44  ),
45  )
46  ],
47  outputParticles="particles_input",
48  randomNumbers=rnd,
49  )
50 
51  s.addReader(evGen)
52 
53  erAlgCfg = acts.examples.geant4.hepmc3.EventRecording.Config(
54  inputParticles=evGen.config.outputParticles,
55  outputHepMcTracks="geant-event",
56  seed1=43,
57  seed2=44,
58  detectorConstructionFactory=detectorConstructionFactory,
59  )
60 
61  erAlg = acts.examples.geant4.hepmc3.EventRecording(
62  config=erAlgCfg, level=acts.logging.INFO
63  )
64 
65  s.addAlgorithm(erAlg)
66 
67  s.addWriter(
68  acts.examples.hepmc3.HepMC3AsciiWriter(
69  level=acts.logging.INFO,
70  outputDir=hepmc_dir,
71  outputStem="events",
72  inputEvents=erAlg.config.outputHepMcTracks,
73  )
74  )
75 
76  return s
77 
78 
79 if "__main__" == __name__:
80  detector, trackingGeometry, decorators = getOpenDataDetector(
82  )
83 
84  detectorConstructionFactory = (
85  acts.examples.geant4.dd4hep.DDG4DetectorConstructionFactory(detector)
86  )
87 
89  detectorConstructionFactory=detectorConstructionFactory,
90  outputDir=os.getcwd(),
91  ).run()