Belle II Software development
PackerTest.py
1#!/usr/bin/env python3
2
3
10
11# Particle gun muon events for KLM, only KLM digitization and reconstruction.
12
13import basf2
14import ROOT
15
16basf2.set_log_level(basf2.LogLevel.INFO)
17
18# EventInfoSetter - generate event meta data
19eventinfosetter = basf2.register_module('EventInfoSetter')
20eventinfosetter.param('evtNumList', [200])
21
22# Particle gun
23particlegun = basf2.register_module('ParticleGun')
24particlegun.param('nTracks', 1)
25particlegun.param('pdgCodes', [13, -13])
26particlegun.param('momentumGeneration', 'uniform')
27particlegun.param('momentumParams', [1, 3])
28particlegun.param('thetaGeneration', 'uniform')
29particlegun.param('thetaParams', [17, 150])
30particlegun.param('phiGeneration', 'uniform')
31particlegun.param('phiParams', [0, 360])
32
33# Geometry parameter loader
34paramloader = basf2.register_module('Gearbox')
35
36# Geometry builder
37geobuilder = basf2.register_module('Geometry')
38geobuilder.param('components', ['KLM'])
39geobuilder.param('useDB', False)
40
41# Full Geant4 simulation
42g4sim = basf2.register_module('FullSim')
43
44# Digitizers
45klm_digitizer = basf2.register_module('KLMDigitizer')
46
47# Packer
48klm_packer = basf2.register_module('KLMPacker')
49
50# Unpacker
51klm_unpacker = basf2.register_module('KLMUnpacker')
52klm_unpacker.param('outputKLMDigitsName', 'KLMDigitsUnpacked')
53
54# Reconstructor
55klm_reconstructor = basf2.register_module('KLMReconstructor')
56
57# Root file output
58output = basf2.register_module('RootOutput')
59output.param('outputFileName', 'ParticleGunMuonsKLM.root')
60
61# Create main path
62main = basf2.create_path()
63
64# Add modules to main path
65main.add_module(eventinfosetter)
66main.add_module(particlegun)
67main.add_module(paramloader)
68main.add_module(geobuilder)
69main.add_module(g4sim)
70
71main.add_module(klm_digitizer)
72main.add_module(klm_packer)
73main.add_module(klm_unpacker)
74main.add_module(klm_reconstructor)
75
76main.add_module(output)
77
78# Process the events
79basf2.process(main)
80print(basf2.statistics)
81
82# Print size of raw data
83root_file = ROOT.TFile('ParticleGunMuonsKLM.root')
84tree = root_file.Get('tree')
85events = tree.GetEntriesFast()
86print(f'Events: {int(events)}')
87for branch in tree.GetListOfBranches():
88 name = branch.GetName()
89 if name.startswith('Raw'):
90 size = branch.GetTotBytes('*') * 1.0
91 zipsize = branch.GetZipBytes('*') * 1.0
92 print(f"{name} {size / 1024.0 / events:.2f} ({zipsize / 1024.0 / events:.2f})")