Belle II Software development
PartGunChargedStableGenSim.py
1#!/usr/bin/env python3
2
3
10
11"""
12<header>
13 <output>PartGunChargedStableGenSim.root</output>
14 <cacheable/>
15 <contact>arul.prakash@physik.uni-muenchen.de</contact>
16 <description> This steering script generates 1000 particle gun events for a set of charged stable particles,
17runs the fullsim w/ mixed in background, and dumps full output (*Digits containers) in a file.</description>
18</header>
19"""
20
21# NB. Argument parsing is done *before* any import from the ROOT module, otherwise PyROOT will hijack the command-line options
22# in case of clashing option names. Most notably, this would happen with the '-h', '--help' option.
23import argparse
24
25parser = argparse.ArgumentParser(
26 description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
27)
28parser.add_argument(
29 "--bkg_dir",
30 type=str,
31 default=None,
32 help="The directory containing beam bkg files.\n"
33 "If not set, basf2 will search for the 'BELLE2_BACKGROUND_DIR' env variable by default,\n"
34 "which is defined on the validation server.",
35)
36args = parser.parse_args()
37
38from ROOT import Belle2 # noqa
39from background import get_background_files # noqa
40from simulation import add_simulation # noqa
41import basf2 # noqa
42
43# Pdg code of the charged stable particles & antiparticles.
44chargedStableList = []
45for idx in range(len(Belle2.Const.chargedStableSet)):
46 particle = Belle2.Const.chargedStableSet.at(idx)
47 pdgId = particle.getPDGCode()
48 chargedStableList.extend([pdgId, -pdgId])
49
50# Create path.
51main = basf2.create_path()
52
53# Event setting and info.
54main.add_module("EventInfoSetter", evtNumList=[3000], runList=[1])
55
56# Fixed random seed.
57basf2.set_random_seed("Pe@ce&Love")
58
59# Single particle generator settings.
60pGun = basf2.register_module("ParticleGun")
61param_pGun = {
62 "pdgCodes": chargedStableList,
63 "nTracks": 0, # 0 : generate 1 track per pdgId per event.
64 "momentumGeneration": "uniform",
65 "momentumParams": [0.05, 5.0],
66 "thetaGeneration": "uniform",
67 "thetaParams": [17, 150], # Generate tracks within CDC acceptance.
68 "phiGeneration": "uniform",
69 "phiParams": [0, 360],
70 "vertexGeneration": "uniform",
71 "xVertexParams": [0.0, 0.0],
72 "yVertexParams": [0.0, 0.0],
73 "zVertexParams": [0.0, 0.0],
74}
75pGun.param(param_pGun)
76main.add_module(pGun)
77
78# Detector simulation + bkg.
79add_simulation(main, bkgfiles=get_background_files(folder=args.bkg_dir))
80
81# Memory profile.
82main.add_module("Profile")
83
84# Create output of event generation + detector simulation.
85main.add_module(
86 "RootOutput", outputFileName="../PartGunChargedStableGenSim.root"
87)
88
89# Show progress of processing.
90main.add_module("Progress")
91
92basf2.print_path(main)
93
94basf2.process(main)