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