EIC 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 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 = 'surfaces-map.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 kvol in data['volumes']:
42  Name = data['volumes'][kvol]['Name']
43 
44  if 'boundaries' in data['volumes'][kvol] :
45  for kbound in data['volumes'][kvol]['boundaries'] :
46  dbound = data['volumes'][kvol]['boundaries'][kbound]
47  data['volumes'][kvol]['boundaries'][kbound]['bin0'] = config[Name]['boundaries'][dbound['stype']]['bin0']
48  data['volumes'][kvol]['boundaries'][kbound]['bin1'] = config[Name]['boundaries'][dbound['stype']]['bin1']
49  data['volumes'][kvol]['boundaries'][kbound]['mapMaterial'] = config[Name]['boundaries'][dbound['stype']]['mapMaterial']
50 
51 
52  if 'layers' in data['volumes'][kvol] :
53  for klay in data['volumes'][kvol]['layers'] :
54 
55  if 'representing' in data['volumes'][kvol]['layers'][klay] :
56  drep = data['volumes'][kvol]['layers'][klay]['representing']
57  data['volumes'][kvol]['layers'][klay]['representing']['bin0'] = config[Name]['representing'][drep['stype']]['bin0']
58  data['volumes'][kvol]['layers'][klay]['representing']['bin1'] = config[Name]['representing'][drep['stype']]['bin1']
59  data['volumes'][kvol]['layers'][klay]['representing']['mapMaterial'] = config[Name]['representing'][drep['stype']]['mapMaterial']
60 
61  if 'approach' in data['volumes'][kvol]['layers'][klay] :
62  for kapp in data['volumes'][kvol]['layers'][klay]['approach'] :
63  dapp = data['volumes'][kvol]['layers'][klay]['approach'][kapp]
64  data['volumes'][kvol]['layers'][klay]['approach'][kapp]['bin0'] = config[Name]['approach'][dapp['stype']][kapp]['bin0']
65  data['volumes'][kvol]['layers'][klay]['approach'][kapp]['bin1'] = config[Name]['approach'][dapp['stype']][kapp]['bin1']
66  data['volumes'][kvol]['layers'][klay]['approach'][kapp]['mapMaterial'] = config[Name]['approach'][dapp['stype']][kapp]['mapMaterial']
67 
68  if 'sensitive' in data['volumes'][kvol]['layers'][klay] :
69  for ksen in data['volumes'][kvol]['layers'][klay]['sensitive'] :
70  dsen = data['volumes'][kvol]['layers'][klay]['sensitive'][ksen]
71  data['volumes'][kvol]['layers'][klay]['sensitive'][ksen]['bin0'] = config[Name]['sensitive'][dsen['stype']]['bin0']
72  data['volumes'][kvol]['layers'][klay]['sensitive'][ksen]['bin1'] = config[Name]['sensitive'][dsen['stype']]['bin1']
73  data['volumes'][kvol]['layers'][klay]['sensitive'][ksen]['mapMaterial'] = config[Name]['sensitive'][dsen['stype']]['mapMaterial']
74 
75 
76  if 'material' in data['volumes'][kvol] :
77  data['volumes'][kvol]['material']['mapMaterial'] = config[Name]['material']['mapMaterial']
78  for bin in data['volumes'][kvol]['material'] :
79  if bin == 'bin0' :
80  data['volumes'][kvol]['material']['bin0'] = config[Name]['material']['bin0']
81  if bin == 'bin1' :
82  data['volumes'][kvol]['material']['bin1'] = config[Name]['material']['bin1']
83  if bin == 'bin2' :
84  data['volumes'][kvol]['material']['bin2'] = config[Name]['material']['bin2']
85 
86 
87  json_file.seek(0)
88  json.dump(data, json_file, indent=4)
89  json_file.truncate()
90