2023-12-19 13:00:59 +01:00
|
|
|
# flake8: noqaq
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import argparse
|
2024-02-26 16:18:03 +01:00
|
|
|
from parameterisations.parameterise_magnet_kink_electron import parameterise_magnet_kink
|
|
|
|
from parameterisations.parameterise_track_model_electron import parameterise_track_model
|
2023-12-19 13:00:59 +01:00
|
|
|
from parameterisations.parameterise_search_window import parameterise_search_window
|
|
|
|
from parameterisations.parameterise_field_integral import parameterise_field_integral
|
|
|
|
from parameterisations.parameterise_hough_histogram import parameterise_hough_histogram
|
2024-02-26 16:18:03 +01:00
|
|
|
from parameterisations.utils.preselection_trackinglosses import preselection
|
2023-12-19 13:00:59 +01:00
|
|
|
from parameterisations.train_forward_ghost_mlps import (
|
|
|
|
train_default_forward_ghost_mlp,
|
|
|
|
train_veloUT_forward_ghost_mlp,
|
|
|
|
)
|
|
|
|
from parameterisations.train_matching_ghost_mlps import train_matching_ghost_mlp
|
|
|
|
from parameterisations.utils.parse_tmva_matrix_to_array import (
|
|
|
|
parse_tmva_matrix_to_array,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument(
|
|
|
|
"--field-params",
|
|
|
|
action="store_true",
|
|
|
|
help="Enables determination of magnetic field parameterisations.",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--forward-weights",
|
|
|
|
action="store_true",
|
|
|
|
help="Enables determination of weights used by neural networks.",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--matching-weights",
|
|
|
|
action="store_true",
|
2024-02-25 12:06:14 +01:00
|
|
|
# default=True,
|
2023-12-19 13:00:59 +01:00
|
|
|
help="Enables determination of weights used by neural networks.",
|
|
|
|
)
|
2024-01-09 16:32:06 +01:00
|
|
|
parser.add_argument(
|
|
|
|
"-p",
|
|
|
|
"--prepare",
|
|
|
|
action="store_true",
|
|
|
|
help="Enables preparation of data for matching.",
|
|
|
|
)
|
2023-12-19 13:00:59 +01:00
|
|
|
parser.add_argument(
|
|
|
|
"--prepare-params-data",
|
|
|
|
action="store_true",
|
|
|
|
help="Enables preparation of data for magnetic field parameterisations.",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--prepare-weights-data",
|
|
|
|
action="store_true",
|
|
|
|
help="Enables preparation of data for NN weight determination.",
|
|
|
|
)
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2024-02-26 16:18:03 +01:00
|
|
|
selected = "data/tracking_losses_ntuple_B_def_selected.root"
|
2023-12-19 13:00:59 +01:00
|
|
|
if args.prepare_params_data:
|
2024-02-26 16:18:03 +01:00
|
|
|
selection = "fromSignal == 1 && isElectron == 1 && pt > 10 && p > 1500 && p < 100000 && !std::isnan(ideal_state_770_x) && !std::isnan(ideal_state_9410_x) && !std::isnan(ideal_state_10000_x)"
|
2023-12-19 13:00:59 +01:00
|
|
|
print("Run selection cuts =", selection)
|
|
|
|
selected_md = preselection(
|
|
|
|
cuts=selection,
|
2024-02-26 16:18:03 +01:00
|
|
|
input_file="data/tracking_losses_ntuple_B_def.root",
|
2023-12-19 13:00:59 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
cpp_files = []
|
|
|
|
if args.field_params:
|
|
|
|
print("Parameterise magnet kink position ...")
|
2024-02-26 16:18:03 +01:00
|
|
|
cpp_files.append(parameterise_magnet_kink(input_file=selected))
|
2023-12-19 13:00:59 +01:00
|
|
|
print("Parameterise track model ...")
|
|
|
|
cpp_files.append(parameterise_track_model(input_file=selected))
|
|
|
|
|
2024-02-25 12:06:14 +01:00
|
|
|
# selected_all_p = (
|
|
|
|
# "nn_neural_net_training/data/param_data_B_default_thesis_selected_all_p.root"
|
|
|
|
# )
|
|
|
|
# if args.prepare_params_data:
|
|
|
|
# selection_all_momenta = "chi2_comb < 5 && pid != 11"
|
|
|
|
# print()
|
|
|
|
# print("Run selection cuts =", selection_all_momenta)
|
|
|
|
# selected_md_all_p = preselection(
|
|
|
|
# cuts=selection_all_momenta,
|
|
|
|
# outfile_postfix="selected_all_p",
|
|
|
|
# input_file="nn_neural_net_training/data/param_data_B_default_thesis.root",
|
|
|
|
# )
|
2023-12-19 13:00:59 +01:00
|
|
|
|
2024-02-25 12:06:14 +01:00
|
|
|
# if args.field_params:
|
|
|
|
# print("Parameterise magnet kink position ...")
|
|
|
|
# cpp_files.append(parameterise_magnet_kink(input_file=selected_all_p))
|
|
|
|
# print("Parameterise track model ...")
|
|
|
|
# cpp_files.append(parameterise_track_model(input_file=selected_all_p))
|
|
|
|
# print("Parameterise search window ...")
|
|
|
|
# cpp_files.append(parameterise_search_window(input_file=selected_all_p))
|
|
|
|
# print("Parameterise magnetic field integral ...")
|
|
|
|
# cpp_files.append(parameterise_field_integral(input_file=selected_all_p))
|
|
|
|
# print("Parameterise Hough histogram binning ...")
|
|
|
|
# cpp_files.append(parameterise_hough_histogram(input_file=selected_all_p))
|
2023-12-19 13:00:59 +01:00
|
|
|
|
|
|
|
###>>>
|
|
|
|
ghost_data = "neural_net_training/data/ghost_data.root"
|
|
|
|
if args.prepare_weights_data:
|
|
|
|
merge_cmd = [
|
|
|
|
"hadd",
|
|
|
|
"-fk",
|
|
|
|
ghost_data,
|
|
|
|
"data/ghost_data_MD.root",
|
|
|
|
"data/ghost_data_MU.root",
|
|
|
|
]
|
|
|
|
print("Concatenate polarities for neural network training ...")
|
|
|
|
subprocess.run(merge_cmd, check=True)
|
|
|
|
###<<<
|
|
|
|
if args.forward_weights:
|
|
|
|
train_default_forward_ghost_mlp(prepare_data=args.prepare_weights_data)
|
|
|
|
# FIXME: use env variable instead
|
|
|
|
os.chdir(os.path.dirname(os.path.realpath(__file__)))
|
|
|
|
train_veloUT_forward_ghost_mlp(prepare_data=args.prepare_weights_data)
|
|
|
|
# this ensures that the directory is correct
|
|
|
|
os.chdir(os.path.dirname(os.path.realpath(__file__)))
|
|
|
|
cpp_files += parse_tmva_matrix_to_array(
|
|
|
|
[
|
|
|
|
"neural_net_training/result/GhostNNDataSet/weights/TMVAClassification_default_forward_ghost_mlp.class.C",
|
|
|
|
"neural_net_training/result/GhostNNDataSet/weights/TMVAClassification_veloUT_forward_ghost_mlp.class.C",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
###>>>
|
|
|
|
if args.matching_weights:
|
|
|
|
os.chdir(os.path.dirname(os.path.realpath(__file__)))
|
|
|
|
train_matching_ghost_mlp(
|
2024-01-15 09:39:38 +01:00
|
|
|
prepare_data=args.prepare,
|
2024-01-15 16:16:12 +01:00
|
|
|
input_file="data/ghost_data_B_default_phi_eta.root",
|
2024-01-09 16:32:06 +01:00
|
|
|
tree_name="PrMatchNN_3e224c41.PrMCDebugMatchToolNN/MVAInputAndOutput",
|
2023-12-19 13:00:59 +01:00
|
|
|
outdir="neural_net_training",
|
2024-01-09 16:32:06 +01:00
|
|
|
exclude_electrons=False,
|
|
|
|
only_electrons=True,
|
2023-12-19 13:00:59 +01:00
|
|
|
)
|
|
|
|
# this ensures that the directory is correct
|
|
|
|
os.chdir(os.path.dirname(os.path.realpath(__file__)))
|
|
|
|
cpp_files += parse_tmva_matrix_to_array(
|
|
|
|
[
|
|
|
|
"neural_net_training/result/MatchNNDataSet/weights/TMVAClassification_matching_mlp.class.C",
|
|
|
|
],
|
|
|
|
simd_type=True,
|
|
|
|
)
|
|
|
|
###<<<
|
|
|
|
for file in cpp_files:
|
|
|
|
subprocess.run(
|
|
|
|
[
|
|
|
|
"clang-format",
|
|
|
|
"-i",
|
|
|
|
f"{file}",
|
|
|
|
],
|
|
|
|
)
|