Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ it in future.

* New warm MS option TRY_2025 (Stellatryon v.2) added to the config and its field map

* Created genie_config folder for our XML configuration files. For now, only replacing Pythia6Decayer with Pythia8Decayer
### Changed

* Only get evtNo in ShipStack if there are tracks. Prevents seg faults from accessing empty events at the end of the run. #1051
* makeGenieEvents: automatically set GXMLPATH to the genie_config folder. Remove option --nudet since now GXMLPATH always needs to be set.
* Make Ship::Generator base class for all the generators. Each generator can in principal take a list of files, although each will need to implement the method to do so. #1047
* Add file glob to run_simScript.py input files to allow for wildcards etc. Also, if nEvents is set to -1, run over everything. #1041
* Turn warning to debug in MuonBackGenerator to prevent overly verbose output. #1036
Expand Down
44 changes: 19 additions & 25 deletions macro/makeGenieEvents.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
# SPDX-FileCopyrightText: Copyright CERN for the benefit of the SHiP Collaboration
"""Generate GENIE neutrino interaction events from flux histograms.

This launcher wraps `genie_utils` (gmkspl/gevgen/gntpc helpers) and adds:
This "launcher" wraps `genie_utils` (gmkspl/gevgen/gntpc helpers) and adds:
- Argument parsing with sensible defaults and validation
- Optional *nudet* mode (disables charm/tau decays via GXMLPATH)
- Automatic neutrino/antineutrino scaling based on flux hist sums
- Structured logging and robust error reporting

Typical use
-----------
$ python $FAIRSHIP/macro/makeGenieEvents sim \
$ python $FAIRSHIP/macro/makeGenieEvents.py sim \
--seed 65539 \
--output ./work \
--filedir /eos/experiment/ship/data/Mbias/background-prod-2018 \
Expand All @@ -21,21 +20,21 @@
--emin 0.5 --emax 350 \
--xsec-file gxspl-FNALsmall.xml \
--flux-file pythia8_Geant4_1.0_withCharm_nu.root \
--event-generator-list CC \
--nudet
--event-generator-list CC

Notes
-----
- This tool *does not* modify your parent shell environment.
- `--nudet` sets `GXMLPATH` for the child process only (you can override path
with `--gxmlpath`).
- GXMLPATH is automatically set to $FAIRSHIP_ROOT/shipgen/genie_config by default.
- Use `--gxmlpath` to override the default GXMLPATH if needed.

"""

from __future__ import annotations

import argparse
import logging
import os
from collections.abc import Mapping, Sequence
from pathlib import Path

Expand Down Expand Up @@ -101,11 +100,15 @@ def _ensure_dir(path: Path) -> None:
path.mkdir(parents=True, exist_ok=True)


def _build_env(nudet: bool, gxmlpath: Path | None) -> Mapping[str, str | None] | None:
"""Build per-call env overrides (sets GXMLPATH only in nudet mode)."""
if not nudet:
return None
val = str(gxmlpath) if gxmlpath else "/eos/experiment/ship/user/aiuliano/GENIE_FNAL_nu_splines"
def _build_env(gxmlpath: Path | None) -> Mapping[str, str | None] | None:
"""Build per-call env overrides (sets GXMLPATH)."""
fairship_root_path = os.getenv("FAIRSHIP_ROOT") or os.getenv("FAIRSHIP")
if not fairship_root_path:
raise OSError(
"FAIRSHIP_ROOT (or FAIRSHIP) environment variable is not set. "
"Please run inside the FairShip alienv environment."
)
val = str(gxmlpath) if gxmlpath else fairship_root_path + "/shipgen/genie_config"
return {"GXMLPATH": val}


Expand Down Expand Up @@ -165,10 +168,7 @@ def make_events(
out_dir = work_dir / f"genie-{pdg_name}_{N}_events"
_ensure_dir(out_dir)

nudet_suffix = "_nudet" if env_vars and env_vars.get("GXMLPATH") else ""
filename = (
f"run_{run}_{pdg_name}_{N}_events_{targetcode}_{emin}_{emax}_GeV_{process or 'ALL'}{nudet_suffix}.ghep.root"
)
filename = f"run_{run}_{pdg_name}_{N}_events_{targetcode}_{emin}_{emax}_GeV_{process or 'ALL'}.ghep.root"
ghep_path = out_dir / filename
gst_path = out_dir / f"genie-{filename}"

Expand Down Expand Up @@ -259,8 +259,7 @@ def _build_parser() -> argparse.ArgumentParser:
default=None,
help="GENIE generator list (e.g. CC, CCDIS, CCQE, CharmCCDIS, RES, CCRES, ...)",
)
ap.add_argument("--nudet", action="store_true", help="Disable charm & tau decays via GXMLPATH")
ap.add_argument("--gxmlpath", type=Path, default=None, help="Override GXMLPATH in --nudet mode")
ap.add_argument("--gxmlpath", type=Path, default=None, help="Override GXMLPATH")
ap.add_argument(
"-p",
"--particles",
Expand Down Expand Up @@ -315,7 +314,7 @@ def main(argv: Sequence[str] | None = None) -> int:
return 0

# sim
env_vars = _build_env(nudet=bool(args.nudet), gxmlpath=args.gxmlpath)
env_vars = _build_env(gxmlpath=args.gxmlpath)
targetcode = _target_code(args.target)

splines = (args.splinedir / args.xsec_file).resolve()
Expand All @@ -328,12 +327,7 @@ def main(argv: Sequence[str] | None = None) -> int:
particles = _pdg_list(args.particles)
nu_over_nubar = extract_nu_over_nubar(flux, particles)

logging.info(
f"Seed: {args.seed} | "
f"Target: {args.target} ({targetcode}) | "
f"Process: {args.evtype or 'ALL'} | "
f"nudet={bool(args.nudet)}"
)
logging.info(f"Seed: {args.seed} | Target: {args.target} ({targetcode}) | Process: {args.evtype or 'ALL'}")
make_events(
run=int(args.run),
nevents=int(args.nevents),
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ ignore = [


[tool.codespell]
ignore-words-list = 'Millepede,Gaus,gaus,dYIn,te'
ignore-words-list = 'Millepede,Gaus,gaus,dYIn,te,KNO'
31 changes: 31 additions & 0 deletions shipgen/genie_config/AGKY2019.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="ISO-8859-1"?>

<!--
Configuration for the AGKY2019 HadronizationModelI

Algorithm Configurable Parameters:
......................................................................................................
Name Type Opt Comment Default
......................................................................................................
KNO-Hadronizer alg No
PYTHIA-Hadronizer alg No
TransMethod int Yes 0: KNO only 2
1: PYTHIA only
2: linear transition from KNO->PYTHIA in
[Wmin,Wmax] invariant mass window
KNO2PYTHIA-Wmin double No relevant only for method=2 CommonParam[KNO2Pythia]
KNO2PYTHIA-Wmax double No relevant only for method=2 CommonParam[KNO2Pythia]
-->

<alg_conf>

<param_set name="Default">

<param type="string" name="CommonParam"> KNO2Pythia </param>

<param type="alg" name="KNO-Hadronizer"> genie::AGKYLowW2019/Default </param>
<param type="alg" name="PYTHIA-Hadronizer"> genie::Pythia8Hadro2019/Default </param>

</param_set>

</alg_conf>
Loading