FairShip
Loading...
Searching...
No Matches
skim_muonback_plane_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 the run_fixedTarget skim for the ci-sim-muonback-plane smoke test.
5
6Keeps only the events with a muon in PlaneHA from one or more
7run_fixedTarget.py outputs (simulated with the hadron absorber field) and
8writes them, with the FileSummary of the first input, to
9tests/data/muonback_plane_smoke.root. Muons behind the absorber are rare, so
10the inputs need a few 10k protons on target in total, e.g.
11
12 python macro/run_fixedTarget.py -n 5000 -e 0.5 -r <run> --AddHadronAbsorberOnly
13
14for a few runs. Re-run only if the output format of run_fixedTarget changes.
15"""
16
17import argparse
18from pathlib import Path
19
20import ROOT
21import shipRoot_conf
22
24
25
26def main() -> int:
27 parser = argparse.ArgumentParser(description=__doc__)
28 parser.add_argument("inputs", nargs="+", help="run_fixedTarget.py output files")
29 parser.add_argument(
30 "--output",
31 type=Path,
32 default=Path(__file__).with_name("muonback_plane_smoke.root"),
33 help="Output skim file",
34 )
35 args = parser.parse_args()
36
37 chain = ROOT.TChain("cbmsim")
38 for f in args.inputs:
39 chain.Add(f)
40 with ROOT.TFile.Open(args.inputs[0]) as first:
41 summary = str(first.Get("FileSummary"))
42
43 out = ROOT.TFile.Open(str(args.output), "RECREATE")
44 skim = chain.CopyTree("Sum$(abs(PlaneHAPoint.fPdgCode) == 13) > 0")
45 skim.Write()
46 out.WriteObject(ROOT.TString(summary), "FileSummary")
47 n = skim.GetEntries()
48 out.Close()
49 print(f"Wrote {n} events to {args.output} ({args.output.stat().st_size} B)")
50 return 0
51
52
53if __name__ == "__main__":
54 raise SystemExit(main())
None configure(darkphoton=None)