Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
digitization.py
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file digitization.py
1 #!/usr/bin/env python3
2 from pathlib import Path
3 from typing import Optional, Union
4 
5 import acts
6 import acts.examples
7 
8 
9 u = acts.UnitConstants
10 
11 
12 def runDigitization(
13  trackingGeometry: acts.TrackingGeometry,
14  field: acts.MagneticFieldProvider,
15  outputDir: Path,
16  digiConfigFile: Path,
17  particlesInput: Optional[Path] = None,
18  outputRoot: bool = True,
19  outputCsv: bool = True,
20  s: Optional[acts.examples.Sequencer] = None,
21  doMerge: Optional[bool] = None,
23 
24  from acts.examples.simulation import (
25  addParticleGun,
26  EtaConfig,
27  PhiConfig,
28  ParticleConfig,
29  addFatras,
30  addDigitization,
31  )
32 
33  s = s or acts.examples.Sequencer(
34  events=100, numThreads=-1, logLevel=acts.logging.INFO
35  )
36  rnd = acts.examples.RandomNumbers(seed=42)
37 
38  if particlesInput is None:
40  s,
41  EtaConfig(-2.0, 2.0),
42  ParticleConfig(4, acts.PdgParticle.eMuon, True),
43  PhiConfig(0.0, 360.0 * u.degree),
44  multiplicity=2,
45  rnd=rnd,
46  )
47  else:
48  # Read input from input collection (e.g. Pythia8 output)
49  evGen = acts.examples.RootParticleReader(
50  level=s.config.logLevel,
51  particleCollection="particles_input",
52  filePath=str(particlesInput),
53  orderedEvents=False,
54  )
55  s.addReader(evGen)
56 
57  outputDir = Path(outputDir)
58  addFatras(
59  s,
60  trackingGeometry,
61  field,
62  rnd=rnd,
63  )
64 
66  s,
67  trackingGeometry,
68  field,
69  digiConfigFile=digiConfigFile,
70  outputDirCsv=outputDir / "csv" if outputCsv else None,
71  outputDirRoot=outputDir if outputRoot else None,
72  rnd=rnd,
73  doMerge=doMerge,
74  )
75 
76  return s
77 
78 
79 if "__main__" == __name__:
80  detector, trackingGeometry, _ = acts.examples.GenericDetector.create()
81 
82  digiConfigFile = (
83  Path(__file__).resolve().parent.parent.parent.parent
84  / "Examples/Algorithms/Digitization/share/default-smearing-config-generic.json"
85  )
86  assert digiConfigFile.exists()
87 
88  field = acts.ConstantBField(acts.Vector3(0, 0, 2 * u.T))
89 
90  runDigitization(trackingGeometry, field, outputDir=Path.cwd()).run()