Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-07-16 08:08:21

0001 import acts
0002 import argparse
0003 from acts import (
0004     logging,
0005     GeometryContext,
0006 )
0007 from acts import geomodel as gm
0008 from acts import examples
0009 
0010 
0011 def main():
0012     p = argparse.ArgumentParser()
0013 
0014     p.add_argument("-i", "--input", type=str, default="", help="Input SQL file")
0015 
0016     p.add_argument(
0017         "-o", "--output", type=str, default="GeoModel", help="Output file(s) base name"
0018     )
0019 
0020     p.add_argument(
0021         "-q",
0022         "--queries",
0023         type=str,
0024         nargs="+",
0025         default=[],
0026         help="List of Queries for Published full phys volumes",
0027     )
0028 
0029     p.add_argument(
0030         "-n",
0031         "--name-list",
0032         type=str,
0033         nargs="+",
0034         default=[],
0035         help="List of Name List for the Surface Factory",
0036     )
0037 
0038     p.add_argument(
0039         "-ml",
0040         "--material-list",
0041         type=str,
0042         nargs="+",
0043         default=[],
0044         help="List of Material List for the Surface Factory",
0045     )
0046 
0047     p.add_argument(
0048         "--table-name",
0049         type=str,
0050         default="ActsBlueprint",
0051         help="Name of the blueprint table",
0052     )
0053 
0054     p.add_argument(
0055         "-t",
0056         "--top-node",
0057         type=str,
0058         default="",
0059         help="Name of the top node in the blueprint tree",
0060     )
0061 
0062     p.add_argument(
0063         "-b",
0064         "--top-node-bounds",
0065         type=str,
0066         default="",
0067         help="Table entry string overriding the top node bounds",
0068     )
0069 
0070     p.add_argument(
0071         "-m", "--map", type=str, default="", help="Input file for the material map"
0072     )
0073 
0074     p.add_argument(
0075         "--convert-subvols",
0076         help="Convert the children of the top level full phys vol",
0077         action="store_true",
0078         default=False,
0079     )
0080 
0081     p.add_argument(
0082         "--convert-boundingboxes",
0083         help="Convert the fpvs to bounding boxes",
0084         type=str,
0085         nargs="+",
0086         default=[],
0087     )
0088 
0089     p.add_argument(
0090         "--output-svg",
0091         help="Write the surfaces to SVG files",
0092         action="store_true",
0093         default=False,
0094     )
0095 
0096     p.add_argument(
0097         "--output-internals-svg",
0098         help="Write the internal navigation to SVG files",
0099         action="store_true",
0100         default=False,
0101     )
0102 
0103     p.add_argument(
0104         "--output-obj",
0105         help="Write the surfaces to OBJ files",
0106         action="store_true",
0107         default=False,
0108     )
0109 
0110     p.add_argument(
0111         "--output-json",
0112         help="Write the surfaces to OBJ files",
0113         action="store_true",
0114         default=False,
0115     )
0116 
0117     p.add_argument(
0118         "--enable-blueprint",
0119         help="Enable the usage of the blueprint",
0120         action="store_true",
0121         default=False,
0122     )
0123 
0124     args = p.parse_args()
0125 
0126     gContext = acts.GeometryContext.dangerouslyDefaultConstruct()
0127     logLevel = logging.INFO
0128 
0129     materialDecorator = None
0130     if args.map != "":
0131         print("Loading a material decorator from file:", args.map)
0132         materialDecorator = acts.IMaterialDecorator.fromFile(args.map)
0133 
0134     # Read the geometry model from the database
0135     gmTree = acts.geomodel.readFromDb(args.input)
0136     gmFactoryConfig = gm.GeoModelDetectorObjectFactory.Config()
0137     gmFactoryConfig.materialList = args.material_list
0138     gmFactoryConfig.nameList = args.name_list
0139     gmFactoryConfig.convertBox = args.convert_boundingboxes
0140     gmFactoryConfig.convertSubVolumes = args.convert_subvols
0141     gmFactory = gm.GeoModelDetectorObjectFactory(gmFactoryConfig, logLevel)
0142     # The options
0143     gmFactoryOptions = gm.GeoModelDetectorObjectFactory.Options()
0144     gmFactoryOptions.queries = args.queries
0145     # The Cache & construct call
0146     gmFactoryCache = gm.GeoModelDetectorObjectFactory.Cache()
0147     gmFactory.construct(gmFactoryCache, gContext, gmTree, gmFactoryOptions)
0148 
0149     # All surfaces from GeoModel
0150     # Output the surface to an OBJ file
0151     if args.output_obj:
0152         gmBoxes = gmFactoryCache.boundingBoxes
0153         gmBoxSurfaces = []
0154         for gmBox in gmBoxes:
0155             gmBoxSurfaces.extend(gmBox.surfaces())
0156         gmSurfaces = [ss[1] for ss in gmFactoryCache.sensitiveSurfaces]
0157         unboundSurfaces = [item for item in gmSurfaces if item not in gmBoxSurfaces]
0158         viewCfg = acts.ViewConfig()
0159         viewCfg.quarterSegments = 720
0160         viewCfg.color = acts.Color(75, 220, 100)
0161         acts.examples.writeVolumesSurfacesObj(
0162             unboundSurfaces,
0163             gmBoxes,
0164             gContext,
0165             viewCfg,
0166             args.output + "_vols.obj",
0167         )
0168 
0169 
0170 if "__main__" == __name__:
0171     main()