Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
writeMapConfig.py
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file writeMapConfig.py
1 # This file is part of the Acts project.
2 #
3 # Copyright (C) 2020-2021 CERN for the benefit of the Acts project
4 #
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 import json
10 import sys
11 
12 # Should be run with Python 3 if possible
13 # Script that parse a Json surfaces map to create an easy to use json config file for the mapping
14 # Take two arguments in input : The path to the surfaces map and the path of the json config file
15 # By default the input is : 'surfaces-map.json' and the output is : 'config-map.json'
16 # The config file can be used to define a binning for all the surfaces in a given volume
17 # It can also be used to define the binning for volume mapping
18 
19 
21  outputmat = {}
22  value = {}
23  material = {}
24  bound = {}
25  outputmat["volume"] = mat["volume"]
26  if "boundary" in mat:
27  outputmat["boundary"] = mat["boundary"]
28  if "layer" in mat:
29  if "approach" not in entry:
30  if "sensitive" not in entry:
31  outputmat["layer"] = "X"
32  if "approach" in mat:
33  outputmat["approach"] = mat["approach"]
34  if "sensitive" in mat:
35  outputmat["layer"] = mat["layer"]
36  outputmat["sensitive"] = "X"
37  material["binUtility"] = mat["value"]["material"]["binUtility"]
38  material["mapMaterial"] = False
39  material["mappingType"] = mat["value"]["material"]["mappingType"]
40  bound["type"] = mat["value"]["bounds"]["type"]
41  value["material"] = material
42  value["bounds"] = bound
43  outputmat["value"] = value
44  return outputmat
45 
46 
47 if sys.version_info[0] < 3:
48  print("Using Python 2")
49  print("To obtain the proper ordering in the Json files Python 3 is recomanded")
50 
51 if len(sys.argv) < 2:
52  inFileName = "geometry-maps.json"
53 else:
54  inFileName = sys.argv[1]
55 
56 
57 with open(inFileName, "r") as json_file:
58  config = {}
59  config["Surfaces"] = {}
60  data = json.load(json_file)
61  lastVol = -1
62  for entry in data["Surfaces"]["entries"]:
63  if lastVol != entry["volume"]:
64  if lastVol != -1:
65  config["Surfaces"][lastVol] = vconfig
66  vconfig = []
67  lastVol = entry["volume"]
68  typeLayer = []
69  createdApproach1 = False
70  createdApproach2 = False
71  typeSensitive = {}
72 
73  if "type" not in entry["value"]["bounds"]:
74  entry["value"]["bounds"]["type"] = ""
75 
76  if "layer" in entry:
77  if "approach" not in entry:
78  if "sensitive" not in entry:
79  if entry["value"]["bounds"]["type"] not in typeLayer:
80  typeLayer.append(entry["value"]["bounds"]["type"])
81  surface = getSurfaceMaterial(entry)
82  vconfig.append(surface)
83  continue
84 
85  if "boundary" in entry:
86  if "layer" not in entry:
87  surface = getSurfaceMaterial(entry)
88  vconfig.append(surface)
89  continue
90 
91  if "approach" in entry:
92  if "sensitive" not in entry:
93  if entry["approach"] == 1 and createdApproach1 == False:
94  createdApproach1 = True
95  surface = getSurfaceMaterial(entry)
96  vconfig.append(surface)
97  continue
98  if entry["approach"] == 2 and createdApproach2 == False:
99  createdApproach2 = True
100  surface = getSurfaceMaterial(entry)
101  vconfig.append(surface)
102  continue
103 
104  if "sensitive" in entry:
105  if "approach" not in entry:
106  if entry["value"]["material"]["binUtility"]["binningdata"] != None:
107  if not entry["layer"] in typeSensitive:
108  typeSensitive[entry["layer"]] = []
109  if (
110  entry["value"]["bounds"]["type"]
111  not in typeSensitive[entry["layer"]]
112  ):
113  typeSensitive[entry["layer"]].append(
114  entry["value"]["bounds"]["type"]
115  )
116  surface = getSurfaceMaterial(entry)
117  vconfig.append(surface)
118  continue
119 
120  if lastVol != -1:
121  config["Surfaces"][lastVol] = vconfig
122  config["Volumes"] = data["Volumes"]
123 
124 if len(sys.argv) < 3:
125  outFileName = "config-map.json"
126 else:
127  outFileName = sys.argv[2]
128 
129 with open(outFileName, "w") as outfile:
130  json.dump(config, outfile, indent=4)