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