Belle II Software  release-06-01-15
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 import TVector3
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", TVector3(0, 0, 0))
46  displayData.obj().addLabel("0,0,10", TVector3(0, 0, 10))
47 
48  # visualize extent of vertex
49  global vertexparams
50  displayData.obj().addPoint("Vertex", TVector3(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", TVector3(vertexparams[0][0],
58  vertexparams[1][0],
59  vertexparams[2][0]))
60  vertexparams[d][0] += 2 * sigma
61  displayData.obj().addPoint("Width", TVector3(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 geometry.param('components', ['CDC', 'MagneticField'])
76 
77 particlegun = b2.register_module('ParticleGun')
78 
79 particlegun.param('vertexGeneration', 'normal')
80 
81 particlegun.param('xVertexParams', vertexparams[0])
82 particlegun.param('yVertexParams', vertexparams[1])
83 particlegun.param('zVertexParams', vertexparams[2])
84 
85 # simulation
86 g4sim = b2.register_module('FullSim')
87 # make the simulation less noisy
88 g4sim.logging.log_level = b2.LogLevel.ERROR
89 
90 # create paths
91 main = b2.create_path()
92 
93 # add modules to paths
94 main.add_module(eventinfosetter)
95 
96 main.add_module(gearbox)
97 main.add_module(geometry)
98 main.add_module(particlegun)
99 # main.add_module(g4sim)
100 
101 main.add_module(VisualizeVertex())
102 
103 # default parameters
104 display = b2.register_module('Display')
105 display.param('showAllPrimaries', True)
106 main.add_module(display)
107 
108 b2.process(main)
109 print(b2.statistics)
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67