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