Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-27 07:24:18

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 os
0011 import sys
0012 
0013 """ Read the detector name from geometry json file """
0014 
0015 
0016 def read_detector_name(geometry_file_name, logging):
0017     if not os.path.isfile(geometry_file_name):
0018         logging.error(f"Geometry json file not found! ({geometry_file_name})")
0019         return "unknown_detector"
0020 
0021     with open(geometry_file_name) as geo_file:
0022         json_geo = json.loads(geo_file.read())
0023         det_name = json_geo["header"]["common"]["detector"]
0024 
0025         return det_name
0026 
0027 
0028 """ Uniform access to the momentum range from the CLI arguments """
0029 
0030 
0031 def get_p_range(parsed_args, logging):
0032 
0033     if parsed_args.p_range is not None:
0034         return parsed_args.p_range[0], parsed_args.p_range[1]
0035     elif parsed_args.pT_range is not None:
0036         return parsed_args.pT_range[0], parsed_args.pT_range[1]
0037     else:
0038         logging.error("No momentum configured")
0039         sys.exit(1)
0040 
0041 
0042 """ Add CLI arguments from the detector IO options in args """
0043 
0044 
0045 def add_detector_io_args(arg_list, parsed_args):
0046 
0047     # Always required
0048     arg_list.extend(
0049         [
0050             "--geometry_file",
0051             parsed_args.geometry_file,
0052         ]
0053     )
0054 
0055     # Optional
0056     if parsed_args.grid_file:
0057         arg_list.extend(["--grid_file", parsed_args.grid_file])
0058 
0059     if parsed_args.material_file:
0060         arg_list.extend(["--material_file", parsed_args.material_file])
0061 
0062 
0063 """ Add CLI arguments from the track generator options in args """
0064 
0065 
0066 def add_track_generator_args(arg_list, parsed_args):
0067 
0068     arg_list.extend(
0069         [
0070             "--random_seed",
0071             str(parsed_args.random_seed),
0072             "--eta_range",
0073             str(parsed_args.eta_range[0]),
0074             str(parsed_args.eta_range[1]),
0075         ]
0076     )
0077 
0078     has_p_range = parsed_args.p_range is not None
0079     has_pT_range = parsed_args.pT_range is not None
0080     if has_p_range and has_pT_range:
0081         print(
0082             "ERROR: Cannot set total momentum and transverse momentum at the same time"
0083         )
0084         sys.exit(1)
0085     elif has_p_range:
0086         arg_list.extend(
0087             ["--p_range", str(parsed_args.p_range[0]), str(parsed_args.p_range[1])]
0088         )
0089     elif has_pT_range:
0090         arg_list.extend(
0091             ["--pT_range", str(parsed_args.pT_range[0]), str(parsed_args.pT_range[1])]
0092         )
0093     else:
0094         # Random track generator
0095         arg_list.extend(["--p_range", "1", "1"])
0096 
0097     if parsed_args.randomize_charge:
0098         arg_list.extend(["--randomize_charge"])
0099 
0100     if hasattr(parsed_args, "n_tracks"):
0101         # Random track generator
0102         arg_list.extend(["--n_tracks", str(parsed_args.n_tracks)])
0103     else:
0104         # Uniform track generator
0105         arg_list.extend(
0106             [
0107                 "--phi_steps",
0108                 str(parsed_args.phi_steps),
0109                 "--eta_steps",
0110                 str(parsed_args.eta_steps),
0111             ]
0112         )
0113 
0114 
0115 """ Add CLI arguments from the propagation options in args """
0116 
0117 
0118 def add_propagation_args(arg_list, parsed_args):
0119 
0120     arg_list.extend(
0121         [
0122             "--min_mask_tolerance",
0123             str(parsed_args.min_mask_tol),
0124             "--max_mask_tolerance",
0125             str(parsed_args.max_mask_tol),
0126             "--mask_tolerance_scalor",
0127             str(parsed_args.mask_tol_scalor),
0128             "--overstep_tolerance",
0129             str(parsed_args.overstep_tol),
0130             "--path_tolerance",
0131             str(parsed_args.path_tol),
0132             "--search_window",
0133             str(parsed_args.search_window[0]),
0134             str(parsed_args.search_window[1]),
0135             "--rk-tolerance",
0136             str(parsed_args.rk_error_tol),
0137             "--path_limit",
0138             str(parsed_args.path_limit),
0139             "--minimum_stepsize",
0140             str(parsed_args.min_step_size),
0141             "--step_contraint",
0142             str(parsed_args.max_step_size),
0143         ]
0144     )
0145 
0146     if parsed_args.covariance_transport:
0147         arg_list.extend(["--covariance_transport"])
0148 
0149     if parsed_args.bethe_energy_loss:
0150         arg_list.extend(["--mean_energy_loss"])
0151 
0152     if parsed_args.energy_loss_grad:
0153         arg_list.extend(["--eloss_gradient"])
0154 
0155     if parsed_args.bfield_grad:
0156         arg_list.extend(["--bfield_gradient"])
0157 
0158     if parsed_args.estimate_scattering_noise:
0159         arg_list.extend(["--estimate_scattering_noise"])
0160         arg_list.extend(
0161             [
0162                 "--n_scattering_stddev",
0163                 str(parsed_args.n_scattering_stddev),
0164                 "--accumulated_error",
0165                 str(parsed_args.accumulated_error),
0166             ]
0167         )