Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions MC/bin/o2dpg_sim_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,39 @@ def add(cfg, flatconfig):

return config

def sim_align_detectors(confKey):
"""
Value of align-geom.mDetectors in a configKeyValues string, trimmed as ConfigurableParam does; "all" when absent.
"""
value = "all"
for keyval in confKey.split(";"):
key, sep, val = keyval.partition("=")
if sep and key.strip() == "align-geom.mDetectors":
value = val.strip()
return value

def aligned_in_transport(alignDetectors, det):
"""
Whether o2-sim aligns detector det when align-geom.mDetectors=alignDetectors ("all", "none" or a list).
"""
if "none" in alignDetectors:
return False
if "all" in alignDetectors:
return True
return det in re.split(r"[ ,]+", alignDetectors)

def geom_align_configkey(alignDetectors):
"""
The align-geom part of the configKeyValues for o2-create-aligned-geometry-workflow; empty for the default "all".
"""
return "" if alignDetectors == "all" else f";align-geom.mDetectors={alignDetectors}"

def its_ideal_in_transport(withParallelWorld, alignDetectors):
"""
Whether ITS is ideal in transport: without the parallel world the ideal ITS object is used, else when ITS is not aligned.
"""
return not withParallelWorld or not aligned_in_transport(alignDetectors, "ITS")

def qed_included(pdga, pdgb, with_qed, no_qed, data_anchoring):
"""
Whether to add the QED background. On by default for same-species heavy-ion collisions,
Expand Down
11 changes: 8 additions & 3 deletions MC/bin/o2dpg_sim_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

from o2dpg_workflow_utils import createTask, createGlobalInitTask, dump_workflow, adjust_RECO_environment, isActive, activate_detector, deactivate_detector, compute_n_workers, merge_dicts, restrict_to_detector_list
from o2dpg_qc_finalization_workflow import include_all_QC_finalization
from o2dpg_sim_config import create_sim_config, create_geant_config, constructConfigKeyArg, option_if_available, overwrite_config, qed_included
from o2dpg_sim_config import create_sim_config, create_geant_config, constructConfigKeyArg, option_if_available, overwrite_config, qed_included, sim_align_detectors, geom_align_configkey, its_ideal_in_transport
from o2dpg_dpl_config_tools import dpl_option_from_config, TaskFinalizer, quote_if_needed

# for some JAliEn interaction
Expand Down Expand Up @@ -601,9 +601,14 @@ def getDPL_global_options(bigshm=False, ccdbbackend=True, runcommand=True):
# We need to query the config if this is done with or without parallel world. This needs to be improved
# as it could be defaulted in the ConfigKey system
with_parallel_world = 1 if args.confKey.find("useParallelWorld=1") != -1 else 0
# The reconstruction geometry is aligned for the same detectors as the transport (align-geom.mDetectors)
sim_align_dets = sim_align_detectors(args.confKey)
geom_align_confkey = geom_align_configkey(sim_align_dets)
its_ideal = 1 if its_ideal_in_transport(with_parallel_world, sim_align_dets) else 0
geom_cmd = f'''
# -- Create aligned geometry using ITS ideal alignment to avoid overlaps in geant
ENABLEPW={with_parallel_world}
ITS_IDEAL={its_ideal}

# when parallel world processing is disabled we need to switch off ITS alignment
if [ "${{ENABLEPW}}" == "0" ]; then
Expand All @@ -626,12 +631,12 @@ def getDPL_global_options(bigshm=False, ccdbbackend=True, runcommand=True):

# fetch the global alignment geometry
${{O2_ROOT}}/bin/o2-create-aligned-geometry-workflow ${{ALIEN_JDL_CCDB_CONDITION_NOT_AFTER:+--condition-not-after $ALIEN_JDL_CCDB_CONDITION_NOT_AFTER}} \
--configKeyValues "HBFUtils.startTime={args.timestamp}" -b --run ${{REMAP_OPT}}
--configKeyValues "HBFUtils.startTime={args.timestamp}{geom_align_confkey}" -b --run ${{REMAP_OPT}}

# copy the object into the CCDB cache
mkdir -p $ALICEO2_CCDB_LOCALCACHE/GLO/Config/GeometryAligned
ln -s -f $PWD/o2sim_geometry-aligned.root $ALICEO2_CCDB_LOCALCACHE/GLO/Config/GeometryAligned/snapshot.root
if [ "$ENABLEPW" == "0" ]; then
if [ "$ITS_IDEAL" == "1" ]; then
[[ -f $PWD/its_GeometryTGeo.root ]] && mkdir -p $ALICEO2_CCDB_LOCALCACHE/ITS/Config/Geometry && ln -s -f $PWD/its_GeometryTGeo.root $ALICEO2_CCDB_LOCALCACHE/ITS/Config/Geometry/snapshot.root
fi

Expand Down
71 changes: 71 additions & 0 deletions MC/bin/tests/test_sim_config_alignment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env python3
"""Offline tests: align-geom.mDetectors of the transport and what geomprefetch derives from it."""
import os
import sys
import unittest

HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.dirname(HERE))

import o2dpg_sim_config as simconfig


class TestSimAlignDetectors(unittest.TestCase):

def test_absent(self):
self.assertEqual(simconfig.sim_align_detectors(""), "all")
self.assertEqual(simconfig.sim_align_detectors("G4.navmode=kTGeo"), "all")

def test_none(self):
self.assertEqual(simconfig.sim_align_detectors("align-geom.mDetectors=none"), "none")

def test_not_first_and_spaces(self):
self.assertEqual(simconfig.sim_align_detectors("G4.navmode=kTGeo; align-geom.mDetectors = none ;"), "none")

def test_partial_list(self):
self.assertEqual(simconfig.sim_align_detectors("align-geom.mDetectors=MCH,MID;G4.navmode=kTGeo"), "MCH,MID")

def test_last_wins(self):
self.assertEqual(simconfig.sim_align_detectors("align-geom.mDetectors=none;align-geom.mDetectors=ITS"), "ITS")

def test_other_align_geom_key(self):
self.assertEqual(simconfig.sim_align_detectors("align-geom.mTimeStamp=1"), "all")


class TestForwardedKey(unittest.TestCase):

def test_default_adds_nothing(self):
self.assertEqual(simconfig.geom_align_configkey("all"), "")

def test_values(self):
self.assertEqual(simconfig.geom_align_configkey("none"), ";align-geom.mDetectors=none")
self.assertEqual(simconfig.geom_align_configkey("MCH,MID"), ";align-geom.mDetectors=MCH,MID")


class TestAlignedInTransport(unittest.TestCase):

def test_all_and_none(self):
self.assertTrue(simconfig.aligned_in_transport("all", "ITS"))
self.assertFalse(simconfig.aligned_in_transport("none", "ITS"))
self.assertFalse(simconfig.aligned_in_transport("all,none", "ITS")) # none wins, as in DetID::getMask

def test_list(self):
self.assertTrue(simconfig.aligned_in_transport("MCH,ITS", "ITS"))
self.assertTrue(simconfig.aligned_in_transport("MCH ITS", "ITS"))
self.assertFalse(simconfig.aligned_in_transport("MCH,MID", "ITS"))
self.assertFalse(simconfig.aligned_in_transport("ITS3", "ITS"))


class TestITSIdeal(unittest.TestCase):

def test_truth_table(self):
self.assertTrue(simconfig.its_ideal_in_transport(0, "all"))
self.assertTrue(simconfig.its_ideal_in_transport(0, "none"))
self.assertFalse(simconfig.its_ideal_in_transport(1, "all"))
self.assertTrue(simconfig.its_ideal_in_transport(1, "none"))
self.assertTrue(simconfig.its_ideal_in_transport(1, "MCH,MID"))
self.assertFalse(simconfig.its_ideal_in_transport(1, "MCH,ITS"))


if __name__ == "__main__":
unittest.main()
Loading