Belle II Software  release-06-00-14
evtgen_sim.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 import basf2 as b2
13 from optparse import OptionParser
14 from tracking import add_tracking_reconstruction
15 from modularAnalysis import inputMdst
16 import os
17 # --------------------------------------------------------------------
18 # Performs Geant4 simulation of events generated with evtgen_gen.py
19 # PXD, SVD, CDC and ARICH detectors are used. Reconstruction of tracks
20 # is also included and objects needed for ARICH reconstruction are stored
21 # in output root file.
22 # --------------------------------------------------------------------
23 
24 parser = OptionParser()
25 parser.add_option('-f', '--file', dest='filename',
26  default='ARICHEvents.root')
27 (options, args) = parser.parse_args()
28 
29 home = os.environ['BELLE2_LOCAL_DIR']
30 
31 mypath = b2.create_path()
32 
33 # Suppress messages and warnings during processing:
34 b2.set_log_level(b2.LogLevel.ERROR)
35 
36 # load input ROOT file
37 inputMdst('None', home + '/B2Kpi_events.root', path=mypath)
38 
39 # Gearbox: access to database (xml files)
40 gearbox = b2.register_module('Gearbox')
41 mypath.add_module(gearbox)
42 
43 # Geometry
44 geometry = b2.register_module('Geometry')
45 geometry.param('components', [
46  'MagneticField',
47  'BeamPipe',
48  'PXD',
49  'SVD',
50  'CDC',
51  'ARICH'])
52 mypath.add_module(geometry)
53 
54 # Simulation
55 simulation = b2.register_module('FullSim')
56 mypath.add_module(simulation)
57 
58 # PXD digitization & clustering
59 pxd_digitizer = b2.register_module('PXDDigitizer')
60 mypath.add_module(pxd_digitizer)
61 pxd_clusterizer = b2.register_module('PXDClusterizer')
62 mypath.add_module(pxd_clusterizer)
63 
64 # SVD digitization & clustering
65 svd_digitizer = b2.register_module('SVDDigitizer')
66 mypath.add_module(svd_digitizer)
67 svd_clusterizer = b2.register_module('SVDClusterizer')
68 mypath.add_module(svd_clusterizer)
69 
70 # CDC digitization
71 cdcDigitizer = b2.register_module('CDCDigitizer')
72 mypath.add_module(cdcDigitizer)
73 
74 # tracking reconstruction
75 add_tracking_reconstruction(mypath)
76 
77 # Track extrapolation
78 ext = b2.register_module('Ext')
79 mypath.add_module(ext)
80 
81 # This creates relations between ExtHits (track points on aerogel plane, from
82 # extrapolated CDC tracks) and ARICHAeroHits (MC hits on aerogel plane).
83 # It allows to have relevant MC information
84 # without storing full MCParticles (which are LARGE) into output root file.
85 arichRELATE = b2.register_module('ARICHRelate')
86 mypath.add_module(arichRELATE)
87 
88 # store branches needed for ARICH reconstruction in root file
89 output = b2.register_module('RootOutput')
90 output.param('outputFileName', options.filename)
91 output.param('branchNames', ['ARICHAeroHits', 'ARICHSimHits', 'ExtHits',
92  'ARICHAeroHitsToExtHits', 'Tracks', 'TrackFitResults'])
93 mypath.add_module(output)
94 
95 # Show progress of processing
96 progress = b2.register_module('Progress')
97 mypath.add_module(progress)
98 
99 # Process events
100 b2.process(mypath)
101 
102 # Print call statistics
103 print(b2.statistics)