-
Notifications
You must be signed in to change notification settings - Fork 1
/
pyg4_mod_and_add.py
executable file
·59 lines (44 loc) · 1.82 KB
/
pyg4_mod_and_add.py
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
#!/usr/bin/env python3
#
import pyg4ometry
def add_sens_to_file(inFile, outFile):
r1 = pyg4ometry.gdml.Reader(inFile)
reg1 = r1.getRegistry()
print("Looping over volumes")
for volname, volume in reg1.logicalVolumeDict.items():
aux_tag = pyg4ometry.gdml.Auxiliary("SensDet", volname)
volume .addAuxiliaryInfo(aux_tag)
# gdml output
w = pyg4ometry.gdml.Writer()
w.addDetector(reg1)
w.write(outFile)
def merge_files(inFileArC, inFileMin, outFile):
r1 = pyg4ometry.gdml.Reader(inFileArC)
reg1 = r1.getRegistry()
r2 = pyg4ometry.gdml.Reader(inFileMin)
reg2 = r2.getRegistry()
## Want to loop over the logical volumes, and add an auxiliary field to them
print("Looping over ArC volumes")
for volname, volume in reg1.logicalVolumeDict.items():
aux_tag = pyg4ometry.gdml.Auxiliary("SensDet", volname)
volume .addAuxiliaryInfo(aux_tag)
print("Looping over MINERvA volumes")
for volname, volume in reg2.logicalVolumeDict.items():
if "AssemblyVolume" in str(type(volume)): continue
if "Fiber" in volname: continue
aux_tag = pyg4ometry.gdml.Auxiliary("SensDet", volname)
volume .addAuxiliaryInfo(aux_tag)
print("Merging volumes")
lv = reg2.logicalVolumeDict["MINERvA_components"]
# create physical volume with placement
pv = pyg4ometry.geant4.PhysicalVolume([0,0,0],[0,0,0], lv, "MINERvA", reg1.logicalVolumeDict["volMinosNDHall"], reg1)
reg1.addVolumeRecursive(pv)
# gdml output
w = pyg4ometry.gdml.Writer()
w.addDetector(reg1)
w.write(outFile)
if __name__ == "__main__":
inFileArC = "input/arc2x2.gdml"
inFileMin = "input/MINERvA_only_15trackerplanes.gdml"
outFile = "output/Merged2x2MINERvA.gdml"
merge_files(inFileArC, inFileMin, outFile)