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