Belle II Software  release-06-00-14
B2A103-SimulateAndReconstruct-withoutBeamBkg.py
1 #!/usr/bin/env python3
2 
3 
10 
11 # ########################################################################
12 # #
13 # Stuck? Ask for help at questions.belle2.org #
14 # #
15 # This tutorial demonstrates how to perform detector simulation and #
16 # reconstruction (track finding+track fitting+ecl reconstruction+...) #
17 # on a previously generated events with beam background mixing. #
18 # #
19 # #
20 # The processed events are saved to the output ROOT file that #
21 # now contain in addition to the generated particles #
22 # (MCParticle objects stored in the StoreArray<MCParticle>) also #
23 # reconstructed MDST objects (Track/ECLCluster/KLMCluster/...). #
24 # #
25 # ########################################################################
26 
27 import basf2 as b2
28 import modularAnalysis as ma
29 import simulation as si
30 import reconstruction as re
31 import os.path
32 
33 
34 # check if the required input file exists (from B2A101 example)
35 if not os.path.isfile('B2A101-Y4SEventGeneration-evtgen.root'):
36  b2.B2FATAL(
37  'Required input file (B2A101-Y4SEventGeneration-evtgen.root) does not exist. \n'
38  'Please run B2A101-Y4SEventGeneration.py tutorial script first.')
39 
40 # create a path
41 my_path = b2.create_path()
42 
43 # load input ROOT file
44 ma.inputMdst('default', 'B2A101-Y4SEventGeneration-evtgen.root', path=my_path)
45 
46 # simulation
47 si.add_simulation(path=my_path)
48 
49 # reconstruction
50 re.add_reconstruction(path=my_path)
51 
52 # dump in MDST format
53 re.add_mdst_output(path=my_path,
54  mc=True,
55  filename='B2A101-Y4SEventGeneration-gsim-BKGx0.root')
56 
57 # Show progress of processing
58 my_path.add_module('ProgressBar')
59 
60 # Process the events
61 b2.process(my_path)
62 
63 # print out the summary
64 print(b2.statistics)