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