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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ it in future.
## Unreleased

### Added
* Add option to split kaons and pions right before they decay, to increase the number of muons

### Changed

Expand Down
16 changes: 12 additions & 4 deletions gconfig/g4Config.C
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,18 @@ void Config() {
/// - stackPopper - stackPopper process
/// When more than one options are selected, they should be separated with '+'
/// character: eg. stepLimit+specialCuts.
TG4RunConfiguration* runConfiguration = new TG4RunConfiguration(
"geomRoot", "FTFP_BERT_HP_EMZ", "stepLimiter+specialCuts+specialControls",
false, // specialStacking (default)
false); // disable MT

const char* env = std::getenv("KAON_PION_SPLITS");
int32_t fNsplits = env ? std::atoi(env) : 0;

std::string controls = "stepLimiter+specialCuts+specialControls";
/// stackPopper is required when adding secondaries, e.g. when splitting the
/// pions and kaons
if (fNsplits != 0) controls += "+stackPopper";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Align stackPopper activation with positive split semantics.

At Line 40, fNsplits != 0 enables +stackPopper even for negative values, but downstream splitting paths are gated on fNsplits > 0. Use a strictly positive check to keep configuration behavior consistent.

🔧 Proposed fix
-  if (fNsplits != 0) controls += "+stackPopper";
+  if (fNsplits > 0) controls += "+stackPopper";
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (fNsplits != 0) controls += "+stackPopper";
if (fNsplits > 0) controls += "+stackPopper";
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@gconfig/g4Config.C` at line 40, The condition at line 40 that controls
stackPopper activation uses `fNsplits != 0`, which enables the feature for both
positive and negative split values, but the downstream splitting logic only
activates when `fNsplits > 0`. Change the condition from `fNsplits != 0` to
`fNsplits > 0` in the stackPopper control statement to ensure consistent
behavior and prevent stackPopper from being activated when actual splitting does
not occur.

TG4RunConfiguration* runConfiguration =
new TG4RunConfiguration("geomRoot", "FTFP_BERT_HP_EMZ", controls.c_str(),
false, // specialStacking (default)
false); // disable MT

/// Create the G4 VMC
TGeant4* geant4 =
Expand Down
17 changes: 17 additions & 0 deletions macro/run_fixedTarget.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ def get_work_dir(run_number, tag: str | None = None) -> str:
ap.add_argument("-J", "--Jpsi-mainly", action=argparse.BooleanOptionalAction, dest="JpsiMainly", default=False)
ap.add_argument("-b", "--boostDiMuon", type=float, default=1.0, help="boost Di-muon branching ratios")
ap.add_argument("-X", "--boostFactor", type=float, default=1.0, help="boost Di-muon prod cross sections")
ap.add_argument(
"--kaon-pion-splits",
type=int,
default=0,
help="splitting factor for kaons and pions, in order to boost the number of muons stemming from their decays",
)
ap.add_argument(
"--multiple-kpi-splits", action="store_true", help="split kaons and pions multiple times along the track path"
)

Comment on lines +81 to +90

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Validate split-flag combinations at parse time.

Lines 81-90 allow invalid combinations (e.g., negative --kaon-pion-splits, or --multiple-kpi-splits with zero splits), which currently fail silently at runtime. Add explicit argument validation right after parsing.

🔧 Proposed fix
 args = ap.parse_args()
+if args.kaon_pion_splits < 0:
+    ap.error("--kaon-pion-splits must be >= 0")
+if args.multiple_kpi_splits and args.kaon_pion_splits == 0:
+    ap.error("--multiple-kpi-splits requires --kaon-pion-splits > 0")
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@macro/run_fixedTarget.py` around lines 81 - 90, The argument parser currently
accepts invalid flag combinations without validation, such as negative values
for the kaon-pion-splits argument or using the multiple-kpi-splits flag with
zero splits, causing silent failures at runtime. After calling ap.parse_args()
to parse the command line arguments, add explicit validation to check that
kaon-pion-splits is non-negative and that if multiple-kpi-splits is True, then
kaon-pion-splits must be greater than zero. If either condition fails, raise an
appropriate error or print an error message and exit with a non-zero status
code.

ap.add_argument("-C", "--charm", action=argparse.BooleanOptionalAction, default=False, help="generate charm decays")
ap.add_argument("-B", "--beauty", action=argparse.BooleanOptionalAction, default=False, help="generate beauty decays")
ap.add_argument(
Expand Down Expand Up @@ -272,6 +282,8 @@ def get_work_dir(run_number, tag: str | None = None) -> str:
if args.boostFactor > 1:
# Turn off UseGeneralProcess to access GammaToMuons directly when cross-sections need to be changed
os.environ["SET_GENERAL_PROCESS_TO_FALSE"] = "1"
if args.kaon_pion_splits > 0:
os.environ["KAON_PION_SPLITS"] = str(args.kaon_pion_splits)
run.SetUserConfig("g4Config.C") # user configuration file default g4Config.C
rtdb = run.GetRuntimeDb()

Expand Down Expand Up @@ -342,6 +354,9 @@ def get_work_dir(run_number, tag: str | None = None) -> str:


sensPlaneHA = ROOT.exitHadronAbsorber()
sensPlaneHA.SetNSplits(args.kaon_pion_splits) # type: ignore[missing-attribute]
if args.multiple_kpi_splits:
sensPlaneHA.SetSplitMultipleTimes() # type: ignore[missing-attribute]
sensPlaneHA.SetEnergyCut(args.ecut * u.GeV)
sensPlaneHA.SetVetoPointName("PlaneHA")

Expand Down Expand Up @@ -422,6 +437,8 @@ def get_work_dir(run_number, tag: str | None = None) -> str:
fStack = gMC.GetStack()
fStack.SetMinPoints(1)
fStack.SetEnergyCut(-1.0)
if args.kaon_pion_splits > 0:
fStack.SetSplitting()
#
import AddDiMuonDecayChannelsToG4

Expand Down
Loading
Loading