ECCE @ 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 surface of a specific type and boundary type in a given volume
17 # If the binning is kept to (1,1) the surface will not be mapped on.
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 with open(inFileName,'r+') as json_file:
35  with open(confFileName,'r') as config_file:
36 
37  config = json.load(config_file)
38  data = json.load(json_file)
39 
40  for kvol in data['volumes']:
41  Name = data['volumes'][kvol]['Name']
42 
43  if 'boundaries' in data['volumes'][kvol] :
44  for kbound in data['volumes'][kvol]['boundaries'] :
45  dbound = data['volumes'][kvol]['boundaries'][kbound]
46  data['volumes'][kvol]['boundaries'][kbound]['bin0'] = config[Name]['boundaries'][dbound['stype']][0]
47  data['volumes'][kvol]['boundaries'][kbound]['bin1'] = config[Name]['boundaries'][dbound['stype']][1]
48  if (config[Name]['boundaries'][dbound['stype']][0][2] != 1) or (config[Name]['boundaries'][dbound['stype']][1][2] != 1) :
49  data['volumes'][kvol]['boundaries'][kbound]['matSurface'] = True
50 
51  if 'layers' in data['volumes'][kvol] :
52  for klay in data['volumes'][kvol]['layers'] :
53 
54  if 'representing' in data['volumes'][kvol]['layers'][klay] :
55  drep = data['volumes'][kvol]['layers'][klay]['representing']
56  data['volumes'][kvol]['layers'][klay]['representing']['bin0'] = config[Name]['representing'][drep['stype']][0]
57  data['volumes'][kvol]['layers'][klay]['representing']['bin1'] = config[Name]['representing'][drep['stype']][1]
58  if (config[Name]['representing'][drep['stype']][0][2] != 1) or (config[Name]['representing'][drep['stype']][1][2] != 1) :
59  data['volumes'][kvol]['layers'][klay]['representing']['matSurface'] = True
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][0]
65  data['volumes'][kvol]['layers'][klay]['approach'][kapp]['bin1'] = config[Name]['approach'][dapp['stype']][kapp][1]
66  if (config[Name]['approach'][dapp['stype']][kapp][0][2] != 1) or (config[Name]['approach'][dapp['stype']][kapp][1][2] != 1) :
67  data['volumes'][kvol]['layers'][klay]['approach'][kapp]['matSurface'] = True
68 
69 
70  if 'sensitive' in data['volumes'][kvol]['layers'][klay] :
71  for ksen in data['volumes'][kvol]['layers'][klay]['sensitive'] :
72  dsen = data['volumes'][kvol]['layers'][klay]['sensitive'][ksen]
73  data['volumes'][kvol]['layers'][klay]['sensitive'][ksen]['bin0'] = config[Name]['sensitive'][dsen['stype']][0]
74  data['volumes'][kvol]['layers'][klay]['sensitive'][ksen]['bin1'] = config[Name]['sensitive'][dsen['stype']][1]
75  if (config[Name]['sensitive'][dsen['stype']][0][2] != 1) or (config[Name]['sensitive'][dsen['stype']][1][2] != 1) :
76  data['volumes'][kvol]['layers'][klay]['sensitive'][ksen] = True
77 
78  json_file.seek(0)
79  json.dump(data, json_file, indent=4)
80  json_file.truncate()