forked from acts-project/acts
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmaterial_mapping.py
More file actions
executable file
·199 lines (167 loc) · 5.79 KB
/
material_mapping.py
File metadata and controls
executable file
·199 lines (167 loc) · 5.79 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/usr/bin/env python3
import argparse
from pathlib import Path
import acts
from acts import (
Surface,
MaterialMapper,
IntersectionMaterialAssigner,
BinnedSurfaceMaterialAccumulator,
logging,
GeometryContext,
)
from acts.json import MaterialMapJsonConverter
from acts.examples import (
Sequencer,
WhiteBoard,
MaterialMapping,
)
from acts.examples.root import (
RootMaterialTrackReader,
RootMaterialTrackWriter,
RootMaterialWriter,
)
from acts.examples.json import (
JsonMaterialWriter,
JsonFormat,
)
from acts.examples.odd import getOpenDataDetector, getOpenDataDetectorDirectory
def runMaterialMapping(
surfaces: list[Surface],
inputFile: Path,
outputFileBase: str,
outputMapFormats: list[str] = ["json", "root"],
loglevel: acts.logging.Level = acts.logging.INFO,
outputMaterialTracks: str = "material_tracks",
treeName: str = "material_tracks",
):
# Create a sequencer
print("Creating the sequencer with 1 thread (inter event information needed)")
s = Sequencer(numThreads=1)
# IO for material tracks reading
wb = WhiteBoard(acts.logging.INFO)
# Read material step information from a ROOT TTRee
s.addReader(
RootMaterialTrackReader(
level=acts.logging.INFO,
outputMaterialTracks=outputMaterialTracks,
treeName=treeName,
fileList=[str(inputFile)],
readCachedSurfaceInformation=False,
)
)
# Assignment setup : Intersection assigner
materialAssingerConfig = IntersectionMaterialAssigner.Config()
materialAssingerConfig.surfaces = surfaces
materialAssinger = IntersectionMaterialAssigner(materialAssingerConfig, loglevel)
# Accumulation setup : Binned surface material accumulator
materialAccumulatorConfig = BinnedSurfaceMaterialAccumulator.Config()
materialAccumulatorConfig.materialSurfaces = surfaces
materialAccumulator = BinnedSurfaceMaterialAccumulator(
materialAccumulatorConfig, loglevel
)
# Mapper setup
materialMapperConfig = MaterialMapper.Config()
materialMapperConfig.assignmentFinder = materialAssinger
materialMapperConfig.surfaceMaterialAccumulator = materialAccumulator
materialMapper = MaterialMapper(materialMapperConfig, loglevel)
# Add the map writer(s)
materialMapWriters = []
# json map writer
if "json" in outputMapFormats:
jmConverterCfg = MaterialMapJsonConverter.Config(
processSensitives=True,
processApproaches=True,
processRepresenting=True,
processBoundaries=True,
processVolumes=False,
)
# Suffix for the map file is added in the writer depending on the format
materialMapWriters.append(
JsonMaterialWriter(
level=loglevel,
converterCfg=jmConverterCfg,
fileName=outputFileBase + "_map",
writeFormat=JsonFormat.Json,
)
)
if "root" in outputMapFormats:
materialMapWriters.append(
RootMaterialWriter(
level=loglevel,
filePath=outputFileBase + "_map.root",
)
)
# Mapping Algorithm
materialMappingConfig = MaterialMapping.Config()
materialMappingConfig.materialMapper = materialMapper
materialMappingConfig.inputMaterialTracks = outputMaterialTracks
materialMappingConfig.mappedMaterialTracks = outputMaterialTracks + "_mapped"
materialMappingConfig.unmappedMaterialTracks = outputMaterialTracks + "_unmapped"
materialMappingConfig.materialWriters = materialMapWriters
materialMapping = MaterialMapping(materialMappingConfig, loglevel)
s.addAlgorithm(materialMapping)
# Add the mapped material tracks writer
s.addWriter(
RootMaterialTrackWriter(
level=acts.logging.INFO,
inputMaterialTracks=materialMappingConfig.mappedMaterialTracks,
filePath=outputFileBase + "_mapped.root",
storeSurface=True,
storeVolume=False,
)
)
# Add the unmapped material tracks writer
s.addWriter(
RootMaterialTrackWriter(
level=acts.logging.INFO,
inputMaterialTracks=materialMappingConfig.unmappedMaterialTracks,
filePath=outputFileBase + "_unmapped.root",
storeSurface=True,
storeVolume=False,
)
)
return s
if "__main__" == __name__:
p = argparse.ArgumentParser()
p.add_argument(
"-n", "--events", type=int, default=1000, help="Number of events to process"
)
p.add_argument(
"-i", "--input", type=str, default="", help="Input file with material tracks"
)
p.add_argument(
"-o", "--output", type=str, default="", help="Output file (core) name"
)
p.add_argument(
"--matconfig", type=str, default="", help="Material configuration file"
)
p.add_argument(
"--tree-name",
type=str,
default="material_tracks",
help="Input material track tree name",
)
p.add_argument(
"--material_tracks-name",
type=str,
default="material_tracks",
help="Input material track collection name",
)
args = p.parse_args()
logLevel = logging.INFO
matDeco = None
if args.matconfig != "":
matDeco = acts.IMaterialDecorator.fromFile(args.matconfig)
detector = getOpenDataDetector(matDeco)
trackingGeometry = detector.trackingGeometry()
materialSurfaces = trackingGeometry.extractMaterialSurfaces()
runMaterialMapping(
materialSurfaces,
inputFile=Path(args.input),
outputFileBase=args.output,
outputMapFormats=["json", "root"],
loglevel=logLevel,
outputMaterialTracks=args.material_tracks_name,
treeName=args.tree_name,
).run()