forked from acts-project/acts
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdigitization.py
More file actions
executable file
·139 lines (119 loc) · 3.34 KB
/
digitization.py
File metadata and controls
executable file
·139 lines (119 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env python3
from pathlib import Path
from typing import Optional
import argparse
import acts
import acts.examples
u = acts.UnitConstants
def runDigitization(
trackingGeometry: acts.TrackingGeometry,
field: acts.MagneticFieldProvider,
outputDir: Path,
digiConfigFile: Path,
particlesInput: Optional[Path] = None,
outputRoot: bool = True,
outputCsv: bool = True,
s: Optional[acts.examples.Sequencer] = None,
doMerge: Optional[bool] = None,
) -> acts.examples.Sequencer:
from acts.examples.simulation import (
addParticleGun,
EtaConfig,
PhiConfig,
ParticleConfig,
addFatras,
addDigitization,
)
from acts.examples.root import RootParticleReader
s = s or acts.examples.Sequencer(
events=100, numThreads=-1, logLevel=acts.logging.INFO
)
rnd = acts.examples.RandomNumbers(seed=42)
if particlesInput is None:
addParticleGun(
s,
EtaConfig(-4.0, 4.0),
ParticleConfig(4, acts.PdgParticle.eMuon, True),
PhiConfig(0.0, 360.0 * u.degree),
multiplicity=2,
rnd=rnd,
)
else:
# Read input from input collection (e.g. Pythia8 output)
evGen = RootParticleReader(
level=s.config.logLevel,
filePath=str(particlesInput),
outputParticles="particles_generated",
)
s.addReader(evGen)
s.addWhiteboardAlias(
"particles_generated_selected", evGen.config.outputParticles
)
outputDir = Path(outputDir)
addFatras(
s,
trackingGeometry,
field,
rnd=rnd,
)
addDigitization(
s,
trackingGeometry,
field,
digiConfigFile=digiConfigFile,
outputDirCsv=outputDir / "csv" if outputCsv else None,
outputDirRoot=outputDir if outputRoot else None,
rnd=rnd,
doMerge=doMerge,
)
return s
if "__main__" == __name__:
# Parse the command line arguments
p = argparse.ArgumentParser(description="Digitization")
p.add_argument(
"--events",
"-n",
type=int,
help="Number of events",
default=1000,
)
p.add_argument(
"--type",
"-t",
type=str,
help="Type of digitization",
default="smearing",
choices=["smearing", "geometric"],
)
p.add_argument(
"--detector",
"-d",
type=str,
help="Output file",
default="generic",
choices=["generic", "odd"],
)
args = p.parse_args()
if args.detector == "generic":
detector = acts.examples.GenericDetector()
else:
from acts.examples.odd import getOpenDataDetector
detector = getOpenDataDetector()
trackingGeometry = detector.trackingGeometry()
digiConfigFile = (
Path(__file__).resolve().parent.parent.parent.parent
/ "Examples/Configs"
/ f"{args.detector}-digi-{args.type}-config.json"
)
assert digiConfigFile.exists()
field = acts.ConstantBField(acts.Vector3(0, 0, 2 * u.T))
s = acts.examples.Sequencer(
events=args.events, numThreads=-1, logLevel=acts.logging.INFO
)
runDigitization(
trackingGeometry,
field,
outputDir=Path.cwd(),
digiConfigFile=digiConfigFile,
s=s,
).run()