FairShip
Loading...
Searching...
No Matches
skim_muonback_smoke.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# SPDX-License-Identifier: LGPL-3.0-or-later
3# SPDX-FileCopyrightText: Copyright CERN for the benefit of the SHiP Collaboration
4"""Create a tiny pythia8-Geant4 muon-back skim for the ci-sim-muonback smoke test.
5
6Reads the full muon-back background sample (via xrootd with a Kerberos token,
7or the public HTTPS link), copies the first N entries of the pythia8-Geant4
8TTree into tests/data/muonback_smoke.root, and exits. Re-run only if the
9sample format changes.
10"""
11
12import argparse
13from pathlib import Path
14
15import ROOT
16import shipRoot_conf
17
19
20
21def main() -> int:
22 parser = argparse.ArgumentParser(description=__doc__)
23 parser.add_argument(
24 "--source",
25 help="Input file (HTTPS public link or root:// URL)",
26 required=True,
27 )
28 parser.add_argument(
29 "--output",
30 type=Path,
31 default=Path(__file__).with_name("muonback_smoke.root"),
32 help="Output skim file",
33 )
34 parser.add_argument(
35 "--entries",
36 type=int,
37 default=200,
38 help="Number of entries to copy from the pythia8-Geant4 tree",
39 )
40 args = parser.parse_args()
41
42 src = ROOT.TFile.Open(args.source, "READ")
43 tree = src.Get("pythia8-Geant4") or src.Get("cbmsim")
44 if not tree:
45 raise SystemExit("Neither pythia8-Geant4 nor cbmsim tree found in source")
46
47 out = ROOT.TFile.Open(str(args.output), "RECREATE")
48 skim = tree.CopyTree("", "", args.entries, 0)
49 skim.Write()
50 out.Close()
51 src.Close()
52 print(f"Wrote {args.entries} entries to {args.output} ({args.output.stat().st_size} B)")
53 return 0
54
55
56if __name__ == "__main__":
57 raise SystemExit(main())
None configure(darkphoton=None)