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