-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.jl
114 lines (95 loc) · 2.89 KB
/
main.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
### main.jl
### -> gets a config.json file in input for running the Bayesian unbinned fit
###
using Pkg
Pkg.activate(".") # activate the environment
Pkg.instantiate() # instantiate the environment
using ArgParse
using Logging, LoggingExtras
using JSON
using FilePathsBase
# load the script to run the analysis
include("src/ZeroNuFit.jl")
using .ZeroNuFit
function set_logger(config::Dict, output_path::String; toy_idx = nothing)
"""
Function which sets the logging for the program
Parameters
----------
config::Dict the fit config
output_path::String path to save the logs to
"""
if ("debug" in keys(config) && config["debug"] == true)
terminal_log = global_logger(ConsoleLogger(stderr, LogLevel(Debug)))
else
terminal_log = global_logger(ConsoleLogger(stderr, LogLevel(Info)))
end
log_suffix = toy_idx == nothing ? "" : "_$(toy_idx)"
logger = TeeLogger(
terminal_log,
# Accept any messages with level >= Info
MinLevelLogger(
FileLogger("$output_path/logs/logfile$log_suffix.log"),
Logging.Info,
),
# Accept any messages with level >= Debug
MinLevelLogger(FileLogger("$output_path/logs/debug$log_suffix.log"), Logging.Debug),
)
global_logger(logger)
end
# read JSON configuration file
function read_config(file_path::String)
"""
Read the JASON configuration file and parse it into a Dict
"""
json_string = read(file_path, String)
config = JSON.parse(json_string)
return config
end
# process parsed arguments for the main function
function get_argparse()
"""
Parse the script arguments
"""
settings = ArgParseSettings(
prog = "LEGEND ovbb Bayesian unbinned fit",
description = "",
commands_are_required = true,
)
@add_arg_table! settings begin
"--config", "-c"
help = "path to config file"
arg_type = String
required = true
end
parse_args(settings)
return parse_args(settings)
end
function main()
# read parsed arguments
@info "running using ", Base.Threads.nthreads(), " threads"
parsed_args = get_argparse()
# read config path
config_path = parsed_args["config"]
@info "Reading configuration from: $config_path"
config = read_config(config_path)
# load the output path and create the neccesary
output_path = config["output_path"]
for dir in [
"$output_path/",
"$output_path/plots/",
"$output_path/mcmc_files/",
"$output_path/logs/",
]
if !isdir(dir)
mkpath(dir)
end
end
set_logger(config, output_path)
# Call the analysis function from ZeroNuFit
ZeroNuFit.Analysis.run_analysis(config, output_path = output_path, toy_idx = nothing)
end
# Run the main function if this file is executed directly
if abspath(PROGRAM_FILE) == @__FILE__
main()
end