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
11 changes: 9 additions & 2 deletions .github/scripts/run_fragments.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
All fragments with the same tag run, in page order, in ONE fresh bash shell inside
an empty directory, so `cd` and variables carry over as they would for a reader.
Afterwards, check EDM4hep outputs with `--validate FILE:EVENTS` and LHE outputs
with `--validate-lhe FILE:EVENTS`. LHE counts can also be a MIN-MAX range.
with `--validate-lhe FILE:EVENTS`, or HepMC3 ASCII outputs with
`--validate-hepmc FILE:EVENTS`. LHE counts can also be a MIN-MAX range.
"""

import argparse
Expand All @@ -24,6 +25,7 @@
from pathlib import Path

from validate_edm4hep import validate as validate_edm4hep
from validate_hepmc import validate as validate_hepmc
from validate_lhe import validate as validate_lhe

MARKER = re.compile(r"^\s*<!--\s*ci-fragment:\s*([\w.-]+)\s*-->\s*$")
Expand Down Expand Up @@ -60,6 +62,7 @@ def main():
parser.add_argument("tag")
parser.add_argument("--validate", action="append", default=[], metavar="FILE:EVENTS")
parser.add_argument("--validate-lhe", action="append", default=[], metavar="FILE:COUNT_OR_RANGE")
parser.add_argument("--validate-hepmc", action="append", default=[], metavar="FILE:EVENTS")
parser.add_argument("--print", action="store_true", help="Print the script and exit")
args = parser.parse_args()
page = args.page.resolve()
Expand All @@ -82,7 +85,11 @@ def main():
)
return 1
failed = False
checks = [(args.validate, validate_edm4hep), (args.validate_lhe, validate_lhe)]
checks = [
(args.validate, validate_edm4hep),
(args.validate_lhe, validate_lhe),
(args.validate_hepmc, validate_hepmc),
]
for items, validate in checks:
for item in items:
name, events = item.rsplit(":", 1)
Expand Down
36 changes: 36 additions & 0 deletions .github/scripts/setup_herwig_ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Source after the Key4hep setup, from the CTest build directory.
# Some Key4hep builds omit ThePEG's nested lib directory from Herwig's search path.
herwig_binary=$(command -v Herwig)
herwig_links=$(ldd "$herwig_binary")
thepeg_soname=$(awk '$1 ~ /^libThePEG\.so\./ && $3 == "not" {print $1; exit}' <<< "$herwig_links")
if [[ -n "$thepeg_soname" ]]; then
# Look alongside the selected Herwig package in the active CVMFS stack.
herwig_package=$(dirname "$(dirname "$(realpath "$herwig_binary")")")
packages_dir=$(dirname "$herwig_package")
stack_dir=$(dirname "$packages_dir")
thepeg_libraries=()
for candidate in "$stack_dir"/thepeg/*/lib/ThePEG/"$thepeg_soname" \
"$packages_dir"/thepeg-*/lib/ThePEG/"$thepeg_soname"; do
if [[ -f "$candidate" ]]; then
thepeg_libraries+=("$candidate")
fi
done
if [[ ${#thepeg_libraries[@]} -ne 1 ]]; then
printf 'Expected one %s alongside Herwig in %s, found %s\n' \
"$thepeg_soname" "$herwig_package" "${#thepeg_libraries[@]}" >&2
return 1
fi
thepeg_libdir=$(dirname "${thepeg_libraries[0]}")
export LD_LIBRARY_PATH="$thepeg_libdir${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
fi

# Herwig loads these defaults even for the electron–positron steering.
pdf_dir="$PWD/herwig-pdf"
for pdf_set in CT14lo CT14nlo; do
mkdir -p "$pdf_dir/$pdf_set"
for pdf_file in "$pdf_set.info" "${pdf_set}_0000.dat"; do
curl -fsSL --retry 3 "https://lhapdfsets.web.cern.ch/current/$pdf_set/$pdf_file" \
-o "$pdf_dir/$pdf_set/$pdf_file"
done
done
export LHAPDF_DATA_PATH="$pdf_dir${LHAPDF_DATA_PATH:+:$LHAPDF_DATA_PATH}"
40 changes: 40 additions & 0 deletions .github/scripts/validate_hepmc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""Check the framing and event count of a HepMC3 ASCII file."""

START = "HepMC::Asciiv3-START_EVENT_LISTING"
END = "HepMC::Asciiv3-END_EVENT_LISTING"


def validate(path, expected):
if expected <= 0:
raise ValueError("Expected a positive event count")

count = 0
with path.open() as stream:
if not next(stream, "").startswith("HepMC::Version ") or next(stream, "").strip() != START:
raise ValueError("Expected a HepMC3 ASCII header")

declared_particles = particles = 0
for line in stream:
record = line.split()
if not record:
continue
if record[0] in ("E", END):
if particles != declared_particles:
raise ValueError(f"Particle count mismatch in HepMC event {count}")
if record[0] == END:
break
count += 1
declared_particles = int(record[3])
if declared_particles <= 0:
raise ValueError(f"Empty HepMC event {count}")
particles = 0
elif record[0] == "P":
particles += 1
else:
raise ValueError("Missing HepMC3 end marker")
if any(line.strip() for line in stream):
raise ValueError("Unexpected data after the HepMC3 end marker")

if count != expected:
raise ValueError(f"Event count mismatch: {count} != {expected}")
return {"valid": True, "entries": count, "scope": "HepMC3 ASCII framing and event count"}
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
source ${{ matrix.STACK }} ${{ contains(matrix.STACK, 'sw-nightlies') && '--spack' || '' }};\
mkdir build;\
cd build;\
source ../.github/scripts/setup_herwig_ci.sh;\
cmake ..;\
make;\
ctest --output-on-failure --no-tests=error;
Expand Down
46 changes: 46 additions & 0 deletions 2-gen-and-fastsim/2-1-event-generation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,27 @@ which Herwig
/cvmfs/sw.hsf.org/spackages7/herwig3/7.2.3/x86_64-centos7-gcc11.2.0-opt/q3pxd/bin/Herwig
```

This example runs Herwig's built-in electron–positron setup at 91.2 GeV.
It generates 100 quark–antiquark events and writes the showered and hadronized
events in HepMC3 ASCII format.

<!-- ci-fragment: herwig -->
```bash
cat > fcc-lep.in <<'HERWIG'
read snippets/EECollider.in
cd /Herwig/MatrixElements
insert SubProcess:MatrixElements 0 MEee2gZ2qq
cd /Herwig/Generators
set EventGenerator:EventHandler:LuminosityFunction:Energy 91.2
read snippets/HepMC.in
set /Herwig/Analysis/HepMC:Format GenEventHepMC3
set /Herwig/Analysis/HepMC:Filename herwig_100.hepmc
saverun fcc-lep EventGenerator
HERWIG
Herwig read fcc-lep.in
Herwig run fcc-lep.run -N 100
```


### MadGraph5

Expand All @@ -777,6 +798,31 @@ which mg5_aMC
/cvmfs/sw.hsf.org/spackages7/madgraph5amc/2.8.1/x86_64-centos7-gcc11.2.0-opt/nlauf/bin/mg5_aMC
```

This example generates 100 electron–positron dimuon events at 91.2 GeV.
MadGraph writes the unweighted hard-process events in LHE format.

<!-- ci-fragment: madgraph5 -->
```bash
cat > fcc-mumu.mg5 <<'MADGRAPH'
set run_mode 0
set automatic_html_opening False
generate e+ e- > mu+ mu-
output fcc_mumu -f
launch fcc_mumu
shower=OFF
done
set lpp1 0
set lpp2 0
set ebeam1 45.6
set ebeam2 45.6
set nevents 100
set use_syst False
done
MADGRAPH
mg5_aMC fcc-mumu.mg5
gzip -dc fcc_mumu/Events/run_01/unweighted_events.lhe.gz > madgraph5_100.lhe
```


## Hands-on case study: ditau events with Pythia8, Whizard and KKMCee

Expand Down
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,9 @@ add_fragment_test("2-gen-and-fastsim/2-1-event-generation/README" bhlumi

add_fragment_test("2-gen-and-fastsim/2-1-event-generation/README" babayaga
--validate-lhe bbyg_100.LHE:1-100)

add_fragment_test("2-gen-and-fastsim/2-1-event-generation/README" herwig
--validate-hepmc herwig_100.hepmc:100)

add_fragment_test("2-gen-and-fastsim/2-1-event-generation/README" madgraph5
--validate-lhe madgraph5_100.lhe:100)
Loading