Belle II Software development
pgun_vertex.py
1#!/usr/bin/env python3
2
3
10
11# This example uses a python module to show the ParticleGun vertex
12# mean and sigma in the display.
13
14import basf2 as b2
15
16from ROOT import Belle2
17from ROOT.Math import XYZVector
18
19# Setting the parameters for random generation of the event vertex Three
20# different distributions can be used: - fixed: always use the exact same
21# value - uniform: uniform distribution between min and max - normal: normal
22# distribution around mean with width of sigma
23#
24# The default is a normal distribution of the vertex
25
26# X/Y/Z parameters:
27vertexparams = [[0, 1], [0, 1], [10, 2]]
28
29
30class VisualizeVertex(b2.Module):
31 """Visualize the vertex configured for the ParticleGun"""
32
33 def initialize(self):
34 """reimplementation of Module::initialize()."""
35
36 Belle2.PyStoreObj("DisplayData").registerInDataStore()
37
38 def event(self):
39 """reimplementation of Module::event()."""
40
41 displayData = Belle2.PyStoreObj("DisplayData")
42 displayData.create()
43
44 displayData.obj().addLabel("Origin", XYZVector(0, 0, 0))
45 displayData.obj().addLabel("0,0,10", XYZVector(0, 0, 10))
46
47 # visualize extent of vertex
48 global vertexparams
49 displayData.obj().addPoint("Vertex", XYZVector(vertexparams[0][0],
50 vertexparams[1][0],
51 vertexparams[2][0]))
52 for d in range(3):
53 sigma = vertexparams[d][1]
54 # add points at +-sigma on both sides of Vertex
55 vertexparams[d][0] -= sigma
56 displayData.obj().addPoint("Width", XYZVector(vertexparams[0][0],
57 vertexparams[1][0],
58 vertexparams[2][0]))
59 vertexparams[d][0] += 2 * sigma
60 displayData.obj().addPoint("Width", XYZVector(vertexparams[0][0],
61 vertexparams[1][0],
62 vertexparams[2][0]))
63 vertexparams[d][0] -= sigma
64
65
66# register necessary modules
67eventinfosetter = b2.register_module('EventInfoSetter')
68eventinfosetter.param('evtNumList', [500])
69
70
71# create geometry
72gearbox = b2.register_module('Gearbox')
73geometry = b2.register_module('Geometry')
74
75particlegun = b2.register_module('ParticleGun')
76
77particlegun.param('vertexGeneration', 'normal')
78
79particlegun.param('xVertexParams', vertexparams[0])
80particlegun.param('yVertexParams', vertexparams[1])
81particlegun.param('zVertexParams', vertexparams[2])
82
83# simulation
84g4sim = b2.register_module('FullSim')
85# make the simulation less noisy
86g4sim.logging.log_level = b2.LogLevel.ERROR
87
88# create paths
89main = b2.create_path()
90
91# add modules to paths
92main.add_module(eventinfosetter)
93
94main.add_module(gearbox)
95main.add_module(geometry)
96main.add_module(particlegun)
97# main.add_module(g4sim)
98
99main.add_module(VisualizeVertex())
100
101# default parameters
102display = b2.register_module('Display')
103display.param('showAllPrimaries', True)
104main.add_module(display)
105
106b2.process(main)
107print(b2.statistics)
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67