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