Belle II Software development
createSimFile.py
1#!/usr/bin/env python3
2
3
10
11import basf2 as b2
12from beamparameters import add_beamparameters
13
14# This is tracking/vxdCaTracking/extendedExamples/scripts/setup_modules.py
15# If later the use of bg is wanted, you can as well import setup_bg
16from VXDTF.setup_modules import (setup_sim,
17 setup_realClusters,
18 setup_mcTF)
19
20# 0 means really random. Set to different seed to have reproducible simulation.
21b2.set_random_seed(0)
22
23# Extremely "non-verbose". Should be OK, as this are well tested modules...
24# Can be overridden with the "-l LEVEL" flag for basf2.
25b2.set_log_level(b2.LogLevel.ERROR)
26
27# ---------------------------------------------------------------------------------------
28# Creating the main path, that will be executed in the end:
29main = b2.create_path()
30
31# EventInfoSetter, EventInfoPrinter, Progress:
32
33# Default is 1 event. To make more use the "-n NUMBER" flag for basf2.
34eventinfosetter = b2.register_module('EventInfoSetter')
35
36# Just some info about what is going on...
37eventinfoprinter = b2.register_module('EventInfoPrinter')
38progress = b2.register_module('Progress')
39
40main.add_module(eventinfosetter)
41main.add_module(eventinfoprinter)
42main.add_module(progress)
43
44# beam parameters
45# To find out about the add_... functions: start basf2, import the function and use help(add_...)
46beamparameters = add_beamparameters(main, "Y4S")
47b2.print_params(beamparameters)
48
49# We might want to have particle gun(s) and EVTGen.
50# Still in that case the ParticleGun modules better come first:
51param_pGun = {
52 'pdgCodes': [13, -13], # 13 = muon --> negatively charged!
53 'nTracks': 5, # 20 tracks is a lot, but we don't use beam background in this script.
54 'momentumGeneration': 'uniformPt',
55 'momentumParams': [0.1, 0.15], # 2 values: [min, max] in GeV
56 'thetaGeneration': 'uniform',
57 'thetaParams': [60., 85.], # 2 values: [min, max] in degree
58 'phiGeneration': 'uniform',
59 'phiParams': [0., 90.], # [min, max] in degree
60 'vertexGeneration': 'uniform',
61 'xVertexParams': [-0.1, 0.1], # in cm...
62 'yVertexParams': [-0.1, 0.1],
63 'zVertexParams': [-0.5, 0.5],
64}
65
66particlegun = b2.register_module('ParticleGun')
67particlegun.logging.log_level = b2.LogLevel.WARNING
68particlegun.param(param_pGun)
69main.add_module(particlegun)
70
71# Now we might want to add EvtGen:
72if False:
73 evtgenInput = b2.register_module('EvtGenInput')
74 evtgenInput.logging.log_level = b2.LogLevel.WARNING
75 main.add_module(evtgenInput)
76
77# Gearbox to access stuff from the data folders, and Geometry:
78gearbox = b2.register_module('Gearbox')
79main.add_module(gearbox)
80
81geometry = b2.register_module('Geometry')
82geometry.param('components', ['BeamPipe', 'MagneticFieldConstant4LimitedRSVD', # Important: look at B field!
83 'PXD', 'SVD'])
84main.add_module(geometry)
85
86# Geant 4 Simulation: this setup could be fed with ignoring the energy deposit as parameter...
87# read careful the description as you otherwise might not get any hits.
88g4sim = setup_sim()
89main.add_module(g4sim)
90
91
92# Digitization and Clusterization -------------------------------------------------------
93if True:
94 setup_realClusters(main, usePXD=True) # usePXD=True: needed since 2gftc-converter does not work without it
95
96else: # Use simple clusterizer, that takes TrueHits.
97 simpleClusterizer = b2.register_module('VXDSimpleClusterizer')
98 simpleClusterizer.param('setMeasSigma', 0)
99 simpleClusterizer.param('onlyPrimaries', True)
100 useEDeposit = True
101 if useEDeposit is False:
102 simpleClusterizer.param('energyThresholdU', -0.0001)
103 simpleClusterizer.param('energyThresholdV', -0.0001)
104 simpleClusterizer.param('energyThreshold', -0.0001)
105 main.add_module(simpleClusterizer)
106
107# Setting up the MC based track finder is necessary to collect information etc.
108setup_mcTF(path=main, nameOutput='mcTracks', usePXD=False, logLevel=b2.LogLevel.INFO)
109
110# Module to write the DataStore into a Root file. Name of output file can be overridden with "-o NAME" flag.
111rootOutput = b2.register_module('RootOutput')
112rootOutput.param('outputFileName', "MyRootFile.root")
113main.add_module(rootOutput)
114
115# Final words:
116b2.log_to_file('createSim.log', append=False)
117b2.process(main)
118print(b2.statistics)