Fill sim_telarray meta_parameter field.
Fill the metaparameter field using the CTA-PROD6-metaparam.cfg
and the code below to fill the metaparameter field.
Observe:
- parameters like primary_hole_diameter or secondary_hole_diameter are called in the model parameter DB primary_mirror... and secondary_mirror...
- the script below fails to pick up discriminator_pulse_shape (is it is the only parameter defined for both trigger classes)
I have painfully checked for each telescope type the changes, but we need to find a better way on how to validate this.
We have some missing parameters:
- nightsky_background, random_mono_probability, muon_mono_thresholds
Here my script:
import json
import os
from pathlib import Path
import re
def extract_metaparam_lines(file_path):
metaparam_info = {}
current_optics_class = None
current_trigger_class = None
with open(file_path, "r", encoding="utf-8") as f:
for line in f:
line = line.strip()
# Check for OPTICS_CLASS
if "OPTICS_CLASS ==" in line:
match = re.search(r"OPTICS_CLASS == (\d+)", line)
if match:
current_optics_class = int(match.group(1))
continue
# Check for TRIGGER_CLASS
if "TRIGGER_CLASS ==" in line:
match = re.search(r"TRIGGER_CLASS == (\d+)", line)
if match:
current_trigger_class = int(match.group(1))
continue
# Extract metaparam telescope parameters
match = re.match(r"^metaparam telescope add (\w+)", line)
if match:
param_name = match.group(1)
metaparam_info[param_name] = {
"optics_class": current_optics_class,
"trigger_class": current_trigger_class
}
# Reset classes when their sections end
if current_optics_class and line.strip() == "% #endif":
current_optics_class = None
if current_trigger_class and line.strip() == "% #endif":
current_trigger_class = None
return metaparam_info
def update_json_files(directory, metaparam_info):
for json_file in Path(directory).rglob("*.json"):
with open(json_file, "r", encoding="utf-8") as f:
data = json.load(f)
# Ensure meta_parameter exists and defaults to false
if "meta_parameter" not in data:
data["meta_parameter"] = False
modified = True
else:
modified = False
# Set TRIGGER_CLASS based on filename
filename = str(json_file)
if "LST" in filename:
trigger_class = 2
elif "MSTx-FlashCam" in filename:
trigger_class = 3
else:
trigger_class = 1
if "SST" in filename or "SCT" in filename:
optics_class = 2
else:
optics_class = 1
print(f"File: {json_file} Trigger {trigger_class} Optics {optics_class}")
# Check if any metaparam key exists in the filename
for param_name, param_info in metaparam_info.items():
if param_name == Path(filename).parts[-2]:
if param_info["optics_class"] is None and param_info["trigger_class"] is None:
data["meta_parameter"] = True
modified = True
break
if param_info["optics_class"] == optics_class:
data["meta_parameter"] = True
modified = True
break
if param_info["trigger_class"] == trigger_class:
data["meta_parameter"] = True
modified = True
break
if modified:
with open(json_file, "w", encoding="utf-8") as f:
json.dump(data, f, indent=4)
print(f"Updated: {json_file}")
if __name__ == "__main__":
metaparam_file = "CTA-PROD6-metaparam.cfg"
base_directory = Path(".")
metaparam_info = extract_metaparam_lines(metaparam_file)
print(f"Extracted metaparam info: {metaparam_info}")
update_json_files(base_directory, metaparam_info)