Skip to content

Commit 3e443ae

Browse files
sawenzelclaude
andcommitted
Switch off TPC loopers and QED for MC-DATA embedding
This switches off the TPC looper generator and the QED background for --data-anchoring and stamps the production's interaction rate into imported contexts. - The data already carries both backgrounds. - The looper generator aborted on contexts taken from data, which carried no interaction rate. - --with-qed and an explicit GenTPCLoopers.loopersVeto still win. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 54ec2ac commit 3e443ae

3 files changed

Lines changed: 74 additions & 6 deletions

File tree

‎MC/bin/o2dpg_sim_config.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ def add(cfg, flatconfig):
190190
if not getattr(args, "with_ZDC", False) and "ZDC" not in getattr(args, "skipModules", []):
191191
add(config, {"ZDCSimParam.buildBeamLine" : "false"})
192192
add(config, {"GenTPCLoopers.colsys" : args.col})
193+
# MC-DATA embedding simulates small signals at the data collisions; no TPC loopers
194+
if len(getattr(args, "data_anchoring", "")) > 0:
195+
add(config, {"GenTPCLoopers.loopersVeto" : "true"})
193196

194197
# ----- apply external overwrites from command line -------
195198
for keyval in externalConfigString.split(";"):
@@ -199,6 +202,15 @@ def add(cfg, flatconfig):
199202

200203
return config
201204

205+
def qed_included(pdga, pdgb, with_qed, no_qed, data_anchoring):
206+
"""
207+
Whether to add the QED background. On by default for same-species heavy-ion collisions,
208+
off for MC-DATA embedding (the data already carries it). --with-qed forces it on,
209+
--no-qed forces it off and wins over everything.
210+
"""
211+
default = pdga == pdgb and pdga != 2212 and len(data_anchoring) == 0
212+
return (default or with_qed) and not no_qed
213+
202214
def constructConfigKeyArg(config):
203215
# flattens dictionary constructed in create_geant_config
204216
# and constructs the --configKeyValues options for simulation

‎MC/bin/o2dpg_sim_workflow.py‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
from o2dpg_workflow_utils import createTask, createGlobalInitTask, dump_workflow, adjust_RECO_environment, isActive, activate_detector, deactivate_detector, compute_n_workers, merge_dicts
4545
from o2dpg_qc_finalization_workflow import include_all_QC_finalization
46-
from o2dpg_sim_config import create_sim_config, create_geant_config, constructConfigKeyArg, option_if_available, overwrite_config
46+
from o2dpg_sim_config import create_sim_config, create_geant_config, constructConfigKeyArg, option_if_available, overwrite_config, qed_included
4747
from o2dpg_dpl_config_tools import dpl_option_from_config, TaskFinalizer, quote_if_needed
4848

4949
# for some JAliEn interaction
@@ -643,11 +643,9 @@ def getDPL_global_options(bigshm=False, ccdbbackend=True, runcommand=True):
643643

644644
workflow['stages'].append(GRP_TASK)
645645

646-
# QED background is enabled by default only for same-species (heavy-ion) collisions.
647-
# --with-qed forces it on; --no-qed forces it off and wins over both the default and --with-qed
648-
# (the two flags are mutually exclusive at the argparse level, so they can never both be set).
649-
QED_enabled = True if (PDGA==PDGB and PDGA!=2212) else False
650-
includeQED = (QED_enabled or args.with_qed) and not args.no_qed
646+
# QED background: on by default for same-species heavy-ion collisions, off for MC-DATA embedding;
647+
# --with-qed forces it on, --no-qed forces it off (see qed_included)
648+
includeQED = qed_included(PDGA, PDGB, args.with_qed, args.no_qed, args.data_anchoring)
651649
signalprefix='sgn'
652650

653651
# No vertexing for event pool generation; otherwise the vertex comes from CCDB and later from CollContext
@@ -714,6 +712,10 @@ def getDPL_global_options(bigshm=False, ccdbbackend=True, runcommand=True):
714712
' --nontrivial-mu-distribution ccdb://https://alice-ccdb.cern.ch/FT0/Calib/EventsPerBc',
715713
f'--QEDinteraction {qedspec}' if includeQED else None
716714
], configname = 'precollcontext')
715+
if len(args.data_anchoring) > 0:
716+
# contexts taken from data carry no interaction rate; store the one used for this production
717+
PreCollContextTask['cmd'] += ' && python3 ${O2DPG_ROOT}/MC/utils/o2dpg_data_embedding_utils.py --set-interaction-rate ' + str(INTRATE) \
718+
+ ' --context ' + ' '.join(f'tf{tf}/collisioncontext.root' for tf in range(1, NTIMEFRAMES + 1))
717719
workflow['stages'].append(PreCollContextTask)
718720

719721
if doembedding:
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env python3
2+
"""Offline tests: MC-DATA embedding switches the TPC looper generator and the QED background off."""
3+
import argparse
4+
import os
5+
import sys
6+
import unittest
7+
8+
HERE = os.path.dirname(os.path.abspath(__file__))
9+
sys.path.insert(0, os.path.dirname(HERE))
10+
11+
import o2dpg_sim_config as simconfig
12+
13+
14+
def args(**kw):
15+
base = dict(gen="pythia8pp", col="PbPb", with_ZDC=False, skipModules=[], data_anchoring="")
16+
base.update(kw)
17+
return argparse.Namespace(**base)
18+
19+
20+
class TestLoopersVeto(unittest.TestCase):
21+
22+
def test_data_anchoring_vetoes_loopers(self):
23+
cfg = simconfig.create_geant_config(args(data_anchoring="ctx.root"), "")
24+
self.assertEqual(cfg["GenTPCLoopers"].get("loopersVeto"), "true")
25+
26+
def test_ordinary_production_keeps_loopers(self):
27+
cfg = simconfig.create_geant_config(args(), "")
28+
self.assertNotIn("loopersVeto", cfg["GenTPCLoopers"])
29+
30+
def test_explicit_key_wins(self):
31+
cfg = simconfig.create_geant_config(args(data_anchoring="ctx.root"), "GenTPCLoopers.loopersVeto=false")
32+
self.assertEqual(cfg["GenTPCLoopers"].get("loopersVeto"), "false")
33+
34+
35+
class TestQED(unittest.TestCase):
36+
PB = 1000822080
37+
38+
def test_default_on_for_heavy_ions_only(self):
39+
self.assertTrue(simconfig.qed_included(self.PB, self.PB, False, False, ""))
40+
self.assertFalse(simconfig.qed_included(2212, 2212, False, False, ""))
41+
42+
def test_flags(self):
43+
self.assertTrue(simconfig.qed_included(2212, 2212, True, False, ""))
44+
self.assertFalse(simconfig.qed_included(self.PB, self.PB, False, True, ""))
45+
46+
def test_data_anchoring_switches_qed_off(self):
47+
self.assertFalse(simconfig.qed_included(self.PB, self.PB, False, False, "ctx.root"))
48+
49+
def test_with_qed_wins_over_data_anchoring(self):
50+
self.assertTrue(simconfig.qed_included(self.PB, self.PB, True, False, "ctx.root"))
51+
52+
53+
if __name__ == "__main__":
54+
unittest.main()

0 commit comments

Comments
 (0)