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