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