5"""Script to collect muons hitting either the UBT extended plane, or the SBT, including soft interaction products, and DIS events, to a ROOT file."""
8Begin of pythia block to avoid aliBuild error
9Uncomment for running with aliBuild
20End of pythia block to avoid aliBuild error
28from pathlib
import Path
31from filterEvents
import load_muon_shield_field
33print(
"Loading ShipMuDIS", flush=
True)
34if r.gSystem.Load(
"libShipMuDIS.so") < 0:
35 raise RuntimeError(
"Could not load libShipMuDIS.so")
36print(
"ShipMuDIS loaded", flush=
True)
37pdg = r.TDatabasePDG.Instance()
39parser = argparse.ArgumentParser()
40parser.add_argument(
"-f",
"--inputfile", help=
"full path to muon background files", required=
True)
44 help=
"custom outputfile name",
45 default=
"muonsProduction_wsoft.root",
47parser.add_argument(
"-n",
"--n_events", type=int, default=-1)
48parser.add_argument(
"-s",
"--start_event", type=int, default=0)
49parser.add_argument(
"--seed", type=int, help=
"Random seed for Pythia6 and ROOT (default: time-based)")
50parser.add_argument(
"--check-all-volumes", action=
"store_true", help=
"Scan all geometry volumes for diagnostics")
51parser.add_argument(
"-z",
"--z_max", type=float, default=20000)
52parser.add_argument(
"--z_min", type=float, default=2500, help=
"Minimum z in cm for diagnostics (default: 2500)")
53parser.add_argument(
"-d",
"--nDIS", help=
"Number of DIS per muon to generate", required=
False, default=1000, type=int)
54parser.add_argument(
"-g",
"--geoFile", dest=
"geoFile", help=
"ROOT geofile", required=
True)
55parser.add_argument(
"--muon-shield-field-map", help=
"Shield field map (default: geometry shieldName)")
56parser.add_argument(
"--muon-shield-field-z", type=float, help=
"Shield map z offset in cm (default: geometry entrance)")
58 "--poca-jump-threshold",
61 help=
"Count transverse jumps between measurement lines larger than this value in cm (default: 1)",
65 help=
"Control FairLogger verbosity: 0=info (default), 1=+debug, 2=+debug1, 3=+debug2",
71args = parser.parse_args()
72if not math.isfinite(args.poca_jump_threshold)
or args.poca_jump_threshold < 0:
73 parser.error(
"--poca-jump-threshold must be finite and nonnegative")
76 r.gErrorIgnoreLevel = r.kWarning
79r.gInterpreter.ProcessLine(
'#include "FairLogger.h"')
81 r.gInterpreter.ProcessLine(
'fair::Logger::SetConsoleSeverity("info");')
82 logging.basicConfig(level=logging.INFO)
84 r.gInterpreter.ProcessLine(
'fair::Logger::SetConsoleSeverity("debug");')
85 logging.basicConfig(level=logging.DEBUG)
87 r.gInterpreter.ProcessLine(
'fair::Logger::SetConsoleSeverity("debug1");')
88 logging.basicConfig(level=logging.DEBUG)
90 r.gInterpreter.ProcessLine(
'fair::Logger::SetConsoleSeverity("debug2");')
91 logging.basicConfig(level=logging.DEBUG)
93print(logging.getLogger().getEffectiveLevel())
94logging.debug(
"Debug messages ON")
96logging.info(f
"Path to MuonBackground : {args.inputfile}")
99theseed = ((args.seed
if args.seed
is not None else time.time_ns()) - 1) % 899999999 + 1
100logging.info(
"Random seed: %d", theseed)
101r.gRandom.SetSeed(theseed)
104r.TGeoManager.Import(args.geoFile)
107 logging.error(
"Failed to load geometry from '%s'", args.geoFile)
110logging.info(
"Geometry successfully loaded.")
115muDis = r.MuDISProcessor()
117field_maker = r.ShipFieldMaker()
118shield_field, shield_path = load_muon_shield_field(
119 field_maker, args.geoFile, args.muon_shield_field_map, args.muon_shield_field_z
121muDis.SetMuonShieldField(shield_field, r.gGeoManager)
122logging.info(
"Muon shield field map: %s", shield_path)
123if args.check_all_volumes:
124 muDis.CheckAllVolumes()
125muDis.SetPocaJumpThreshold(args.poca_jump_threshold)
126ok = muDis.init(args.n_events, args.start_event, 2.0, args.nDIS, theseed, args.z_max, args.z_min)
128 print(
"Invalid initialisation. Doing nothing.")
131p = Path(args.inputfile)
134 muDis.process_file(args.inputfile, args.outputfile)
140 str(path)
for path
in p.rglob(
"*")
if path.is_file()
and pattern
in path.name
and ".root" in path.name
143 print(f
"Found {len(matching_files)} files:")
144 if len(matching_files) < 1:
145 print(
"No input file found in path.")
147 for f
in matching_files:
150 muDis.process_file(matching_files, args.outputfile)
152 print(
"Inputfile string does not exist")