Skip to content

Commit

Permalink
fix: Make charge smearing optional in digi config (acts-project#3710)
Browse files Browse the repository at this point in the history
Currently, the JSON reading for digitization configurations unconditionally reads the charge smearing data, but this need not necessarily be present; the geometric config for the ODD, for example, does not have this data. As a result, parser was failing to parse the geometric ODD digitization config. This commit makes the reading conditional and adds tests to ensure the ODD config reading remains functional.
  • Loading branch information
stephenswat authored and Rosie-Hasan committed Nov 13, 2024
1 parent 0479a59 commit 396fbfd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Examples/Io/Json/src/JsonDigitizationConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ void ActsExamples::to_json(nlohmann::json& j,
j["thickness"] = gdc.thickness;
j["threshold"] = gdc.threshold;
j["digital"] = gdc.digital;
to_json(j["charge-smearing"], gdc.chargeSmearer);
if (j.find("charge-smearing") != j.end()) {
to_json(j["charge-smearing"], gdc.chargeSmearer);
}
}

void ActsExamples::from_json(const nlohmann::json& j,
Expand All @@ -161,7 +163,9 @@ void ActsExamples::from_json(const nlohmann::json& j,
gdc.varianceMap[idx] = vars;
}
}
from_json(j["charge-smearing"], gdc.chargeSmearer);
if (j.find("charge-smearing") != j.end()) {
from_json(j["charge-smearing"], gdc.chargeSmearer);
}
}

void ActsExamples::to_json(nlohmann::json& j,
Expand Down
34 changes: 34 additions & 0 deletions Examples/Python/tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,40 @@ def test_digitization_example(trk_geo, tmp_path, assert_root_hash, digi_config_f
assert_root_hash(root_file.name, root_file)


@pytest.mark.parametrize(
"digi_config_file",
[
DIGI_SHARE_DIR / "default-smearing-config-generic.json",
DIGI_SHARE_DIR / "default-geometric-config-generic.json",
pytest.param(
(
getOpenDataDetectorDirectory()
/ "config"
/ "odd-digi-smearing-config.json"
),
marks=[
pytest.mark.odd,
],
),
pytest.param(
(
getOpenDataDetectorDirectory()
/ "config"
/ "odd-digi-geometric-config.json"
),
marks=[
pytest.mark.odd,
],
),
],
ids=["smeared", "geometric", "odd-smeared", "odd-geometric"],
)
def test_digitization_example_input_parsing(digi_config_file):
from acts.examples import readDigiConfigFromJson

acts.examples.readDigiConfigFromJson(str(digi_config_file))


@pytest.mark.parametrize(
"digi_config_file",
[
Expand Down

0 comments on commit 396fbfd

Please sign in to comment.