forked from acts-project/acts
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmaterial_validation_itk.py
More file actions
executable file
·119 lines (96 loc) · 3.39 KB
/
material_validation_itk.py
File metadata and controls
executable file
·119 lines (96 loc) · 3.39 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
#!/usr/bin/env python3
import os
import argparse
from pathlib import Path
from acts.examples import Sequencer
from acts.examples.simulation import addParticleGun, EtaConfig, ParticleConfig
from acts.examples.root import RootMaterialTrackWriter, RootPropagationStepsWriter
import acts
def runMaterialValidation(
nevents,
ntracks,
trackingGeometry,
decorators,
field,
outputDir,
outputName="propagation_material",
dumpPropagationSteps=False,
s=None,
):
# Create a sequencer
s = s or Sequencer(events=nevents, numThreads=-1)
rnd = acts.examples.RandomNumbers(seed=42)
for decorator in decorators:
s.addContextDecorator(decorator)
nav = acts.Navigator(
trackingGeometry=trackingGeometry,
resolveSensitive=True,
resolveMaterial=True,
resolvePassive=True,
)
# stepper = acts.StraightLineStepper()
stepper = acts.EigenStepper(field)
prop = acts.examples.ConcretePropagator(acts.Propagator(stepper, nav))
addParticleGun(
s,
ParticleConfig(num=ntracks, pdg=acts.PdgParticle.eMuon, randomizeCharge=True),
EtaConfig(-4.0, 4.0),
rnd=rnd,
)
trkParamExtractor = acts.examples.ParticleTrackParamExtractor(
level=acts.logging.INFO,
inputParticles="particles_generated",
outputTrackParameters="params_particles_generated",
)
s.addAlgorithm(trkParamExtractor)
alg = acts.examples.PropagationAlgorithm(
propagatorImpl=prop,
level=acts.logging.INFO,
sterileLogger=False,
recordMaterialInteractions=True,
inputTrackParameters="params_particles_generated",
outputPropagationSteps="propagation_steps",
outputMaterialTracks="material_tracks",
)
s.addAlgorithm(alg)
s.addWriter(
RootMaterialTrackWriter(
level=acts.logging.INFO,
inputMaterialTracks=alg.config.outputMaterialCollection,
filePath=os.path.join(outputDir, (outputName + ".root")),
storeSurface=True,
storeVolume=True,
)
)
if dumpPropagationSteps:
s.addWriter(
RootPropagationStepsWriter(
level=acts.logging.INFO,
collection=alg.config.outputSummaryCollection,
filePath=outputDir + "/propagation_steps.root",
)
)
return s
if "__main__" == __name__:
p = argparse.ArgumentParser(
description="Script to run material validation on ITk geometry"
)
p.add_argument(
"geo_dir",
help="Input directory containing the ITk standalone geometry. Get in touch if you don't have this.",
)
p.add_argument("--material", type=str, default="", help="Material file")
args = p.parse_args()
geo_example_dir = Path(args.geo_dir)
assert geo_example_dir.exists(), "Detector example input directory missing"
assert os.path.exists(
args.material
), "Invalid file path/name in --material. Please check your input!"
from acts.examples.itk import buildITkGeometry
detector = buildITkGeometry(geo_example_dir, customMaterialFile=args.material)
trackingGeometry = detector.trackingGeometry()
decorators = detector.contextDecorators()
field = acts.ConstantBField(acts.Vector3(0, 0, 2 * acts.UnitConstants.T))
runMaterialValidation(
trackingGeometry, decorators, field, outputDir=os.getcwd()
).run()