Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
configureMap.py
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file configureMap.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 use the json config file to configure the Json surfaces map for the material 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 if sys.version_info[0] < 3:
20  print("Using Python 2")
21  print("To obtain the proper ordering in the Json files Python 3 is recomanded")
22 
23 if len(sys.argv) < 2:
24  inFileName = "geometry-maps.json"
25  confFileName = "config-map.json"
26 
27 if len(sys.argv) < 3:
28  confFileName = "config-map.json"
29 
30 else:
31  inFileName = sys.argv[1]
32  confFileName = sys.argv[2]
33 
34 
35 with open(inFileName, "r+") as json_file:
36  with open(confFileName, "r") as config_file:
37 
38  config = json.load(config_file)
39  data = json.load(json_file)
40 
41  for entry in data["Surfaces"]["entries"]:
42 
43  if "type" not in entry["value"]["bounds"]:
44  entry["value"]["bounds"]["type"] = ""
45 
46  if "layer" in entry:
47  if "approach" not in entry:
48  if "sensitive" not in entry:
49  for conf in config["Surfaces"][str(entry["volume"])]:
50  if (
51  "layer" in conf
52  and conf["layer"] == "X"
53  and conf["value"]["bounds"]["type"]
54  == entry["value"]["bounds"]["type"]
55  ):
56  entry["value"]["material"]["mapMaterial"] = conf[
57  "value"
58  ]["material"]["mapMaterial"]
59  entry["value"]["material"]["mappingType"] = conf[
60  "value"
61  ]["material"]["mappingType"]
62  ibin = 0
63  for bin in entry["value"]["material"]["binUtility"][
64  "binningdata"
65  ]:
66  bin["bins"] = conf["value"]["material"][
67  "binUtility"
68  ]["binningdata"][ibin]["bins"]
69  ibin = ibin + 1
70  continue
71  continue
72 
73  if "boundary" in entry:
74  if "layer" not in entry:
75  for conf in config["Surfaces"][str(entry["volume"])]:
76  if (
77  "boundary" in conf
78  and conf["boundary"] == entry["boundary"]
79  and conf["value"]["bounds"]["type"]
80  == entry["value"]["bounds"]["type"]
81  ):
82  entry["value"]["material"]["mapMaterial"] = conf["value"][
83  "material"
84  ]["mapMaterial"]
85  entry["value"]["material"]["mappingType"] = conf["value"][
86  "material"
87  ]["mappingType"]
88  ibin = 0
89  for bin in entry["value"]["material"]["binUtility"][
90  "binningdata"
91  ]:
92  bin["bins"] = conf["value"]["material"]["binUtility"][
93  "binningdata"
94  ][ibin]["bins"]
95  ibin = ibin + 1
96  continue
97  continue
98 
99  if "approach" in entry:
100  if "sensitive" not in entry:
101  for conf in config["Surfaces"][str(entry["volume"])]:
102  if (
103  "approach" in conf
104  and conf["approach"] == entry["approach"]
105  and conf["value"]["bounds"]["type"]
106  == entry["value"]["bounds"]["type"]
107  ):
108  entry["value"]["material"]["mapMaterial"] = conf["value"][
109  "material"
110  ]["mapMaterial"]
111  entry["value"]["material"]["mappingType"] = conf["value"][
112  "material"
113  ]["mappingType"]
114  ibin = 0
115  for bin in entry["value"]["material"]["binUtility"][
116  "binningdata"
117  ]:
118  bin["bins"] = conf["value"]["material"]["binUtility"][
119  "binningdata"
120  ][ibin]["bins"]
121  ibin = ibin + 1
122  continue
123  continue
124 
125  if "sensitive" in entry:
126  if "approach" not in entry:
127  for conf in config["Surfaces"][str(entry["volume"])]:
128  if (
129  "sensitive" in conf
130  and conf["sensitive"] == "X"
131  and conf["layer"] == entry["layer"]
132  and conf["value"]["bounds"]["type"]
133  == entry["value"]["bounds"]["type"]
134  ):
135  entry["value"]["material"]["mapMaterial"] = conf["value"][
136  "material"
137  ]["mapMaterial"]
138  entry["value"]["material"]["mappingType"] = conf["value"][
139  "material"
140  ]["mappingType"]
141  ibin = 0
142  for bin in entry["value"]["material"]["binUtility"][
143  "binningdata"
144  ]:
145  bin["bins"] = conf["value"]["material"]["binUtility"][
146  "binningdata"
147  ][ibin]["bins"]
148  ibin = ibin + 1
149  continue
150  continue
151  data["Volumes"] = config["Volumes"]
152  json_file.seek(0)
153  json.dump(data, json_file, indent=4)
154  json_file.truncate()