Belle II Software  release-08-01-10
digitize.py
1 #!/usr/bin/env python3
2 
3 
10 
11 import basf2 as b2
12 from optparse import OptionParser
13 
14 # --------------------------------------------------------------------
15 # Example steering script for digitization and analysis of existing
16 # background files containing only SimHits
17 # Analysis output histograms are stored into a root file
18 # In addition you can store the collection of hits in your detector
19 # by uncommenting root output module lines
20 #
21 # run as: basf2 beast/examples/digitize.py -- -f inputfile -o outputfile
22 # --------------------------------------------------------------------
23 
24 parser = OptionParser()
25 parser.add_option('-f', '--file', dest='filename',
26  default='input.root')
27 parser.add_option('-o', '--output', dest='output_filename',
28  default='output.root')
29 
30 (options, args) = parser.parse_args()
31 
32 # Suppress messages and warnings during processing:
33 b2.set_log_level(b2.LogLevel.ERROR)
34 
35 # Create path
36 main = b2.create_path()
37 
38 # input root file
39 input_module = b2.register_module('RootInput')
40 input_module.param('inputFileName', options.filename)
41 main.add_module(input_module)
42 
43 histo = b2.register_module('HistoManager')
44 histo.param('histoFileName', options.output_filename) # File to save histograms
45 main.add_module(histo)
46 
47 # Gearbox: access to database (xml files)
48 gearbox = b2.register_module('Gearbox')
49 main.add_module(gearbox)
50 
51 # digitizers (for example He3Digitizer)
52 he3digi = b2.register_module('He3Digitizer')
53 main.add_module(he3digi)
54 
55 # make histograms (for example for He3)
56 he3study = b2.register_module('He3tubeStudy')
57 main.add_module(he3study)
58 
59 # root output module
60 # now the root output file contains digitized He3 hits (He3tubeHits)!
61 # output = register_module('RootOutput')
62 # output.param('outputFileName', options.output_filename)
63 # if you want to store only branches of interest (hits in your detector, etc.) use
64 # output.param('branchNames', ['He3tubeHits'])
65 # main.add_module(output)
66 
67 # Show progress of processing
68 progress = b2.register_module('Progress')
69 main.add_module(progress)
70 
71 # Process events
72 b2.process(main)
73 
74 # Print call statistics
75 print(b2.statistics)