Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:14:59

0001 # This file is part of the ACTS project.
0002 #
0003 # Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 #
0005 # This Source Code Form is subject to the terms of the Mozilla Public
0006 # License, v. 2.0. If a copy of the MPL was not distributed with this
0007 # file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 import json
0010 import sys
0011 
0012 # Should be run with Python 3 if possible
0013 # Script that parse a Json surfaces map to create an easy to use json config file for the mapping
0014 # Take two arguments in input : The path to the surfaces map and the path of the json config file
0015 # By default the input is : 'geometry-map.json' and the output is : 'config-map.json'
0016 # The config file can be used to define a binning for all the surfaces in a given volume
0017 # It can also be used to define the binning for volume mapping
0018 
0019 
0020 def getSurfaceMaterial(mat):
0021     outputmat = {}
0022     value = {}
0023     material = {}
0024     bound = {}
0025     outputmat["volume"] = mat["volume"]
0026     if "boundary" in mat:
0027         outputmat["boundary"] = mat["boundary"]
0028     if "layer" in mat:
0029         if "approach" not in entry:
0030             if "sensitive" not in entry:
0031                 outputmat["layer"] = "X"
0032     if "approach" in mat:
0033         outputmat["approach"] = mat["approach"]
0034     if "sensitive" in mat:
0035         outputmat["layer"] = mat["layer"]
0036         outputmat["sensitive"] = "X"
0037     material["binUtility"] = mat["value"]["material"]["binUtility"]
0038     material["mapMaterial"] = False
0039     material["mappingType"] = mat["value"]["material"]["mappingType"]
0040     bound["type"] = mat["value"]["bounds"]["type"]
0041     value["material"] = material
0042     value["bounds"] = bound
0043     outputmat["value"] = value
0044     return outputmat
0045 
0046 
0047 if sys.version_info[0] < 3:
0048     print("Using Python 2")
0049     print("To obtain the proper ordering in the Json files Python 3 is recommended")
0050 
0051 if len(sys.argv) < 2:
0052     inFileName = "geometry-map.json"
0053 else:
0054     inFileName = sys.argv[1]
0055 
0056 
0057 with open(inFileName, "r") as json_file:
0058     config = {}
0059     config["Surfaces"] = {}
0060     data = json.load(json_file)
0061     lastVol = -1
0062     for entry in data["Surfaces"]["entries"]:
0063         if lastVol != entry["volume"]:
0064             if lastVol != -1:
0065                 config["Surfaces"][lastVol] = vconfig
0066             vconfig = []
0067             lastVol = entry["volume"]
0068             typeLayer = []
0069             createdApproach1 = False
0070             createdApproach2 = False
0071             typeSensitive = {}
0072 
0073         if "type" not in entry["value"]["bounds"]:
0074             entry["value"]["bounds"]["type"] = ""
0075 
0076         if "layer" in entry:
0077             if "approach" not in entry:
0078                 if "sensitive" not in entry:
0079                     if entry["value"]["bounds"]["type"] not in typeLayer:
0080                         typeLayer.append(entry["value"]["bounds"]["type"])
0081                         surface = getSurfaceMaterial(entry)
0082                         vconfig.append(surface)
0083                         continue
0084 
0085         if "boundary" in entry:
0086             if "layer" not in entry:
0087                 surface = getSurfaceMaterial(entry)
0088                 vconfig.append(surface)
0089                 continue
0090 
0091         if "approach" in entry:
0092             if "sensitive" not in entry:
0093                 if entry["approach"] == 1 and createdApproach1 == False:
0094                     createdApproach1 = True
0095                     surface = getSurfaceMaterial(entry)
0096                     vconfig.append(surface)
0097                     continue
0098                 if entry["approach"] == 2 and createdApproach2 == False:
0099                     createdApproach2 = True
0100                     surface = getSurfaceMaterial(entry)
0101                     vconfig.append(surface)
0102                     continue
0103 
0104         if "sensitive" in entry:
0105             if "approach" not in entry:
0106                 if entry["value"]["material"]["binUtility"]["binningdata"] != None:
0107                     if not entry["layer"] in typeSensitive:
0108                         typeSensitive[entry["layer"]] = []
0109                     if (
0110                         entry["value"]["bounds"]["type"]
0111                         not in typeSensitive[entry["layer"]]
0112                     ):
0113                         typeSensitive[entry["layer"]].append(
0114                             entry["value"]["bounds"]["type"]
0115                         )
0116                         surface = getSurfaceMaterial(entry)
0117                         vconfig.append(surface)
0118                         continue
0119 
0120     if lastVol != -1:
0121         config["Surfaces"][lastVol] = vconfig
0122     config["Volumes"] = data["Volumes"]
0123 
0124 if len(sys.argv) < 3:
0125     outFileName = "config-map.json"
0126 else:
0127     outFileName = sys.argv[2]
0128 
0129 with open(outFileName, "w") as outfile:
0130     json.dump(config, outfile, indent=4)