Belle II Software development
GeoCacheDemo.py
1#!/usr/bin/env python3
2
3
10
11import basf2 as b2
12import ROOT
13from ROOT import Belle2
14
15b2.logging.log_level = b2.LogLevel.WARNING
16
17
18class PrintPXDHits(b2.Module):
19
20 """Prints global coordinates of PXD hits to demonstrate the Pythonized
21 VXD::GeoCache.
22 Only SensorInfoBase is Pythonized (not PXD:SensorInfo and SVD::SensorInfo),
23 so that there is currently no access to specific PXD/SVD sensor features
24 (like PXD bulk doping or SVD APV25 time constants - such support can be
25 easily added, if desired, by placing the classes in the corresponding
26 linkdef.h file.
27 Complete geometry and sensor matrix information is, however, available
28 for all sensor types.
29 """
30
31 def __init__(self):
32 """Initialize the module"""
33
34 super().__init__()
35
36 def initialize(self):
37 """ Does nothing """
38
39 def beginRun(self):
40 """ Does nothing """
41
42 def event(self):
43 """Prints out PXD hits in global coordinates."""
44
46 # PXD clusters
47 pxd_clusters = Belle2.PyStoreArray("PXDClusters")
48 if pxd_clusters.getEntries() > 0:
49 id = pxd_clusters[0].getSensorID()
50 info = geoCache.get(id)
51 else:
52 b2.B2INFO("No PXD hits in this event.")
53
54 for cluster in pxd_clusters:
55 if id != cluster.getSensorID(): # next sensor
56 id = cluster.getSensorID()
57 info = geoCache.get(id)
58 b2.B2INFO(f"Layer: {id.getLayerNumber()}, Ladder: {id.getLadderNumber()}, Sensor: {id.getSensorNumber()}")
59
60 r_local = ROOT.TVector3(cluster.getU(), cluster.getV(), 0)
61 r_global = info.pointToGlobal(r_local)
62 b2.B2INFO(f'PXD hit: {r_global.X():10.5f} {r_global.Y():10.5f} {r_global.Z():10.5f}')
63
64 def terminate(self):
65 """ Do nothing """
66
67
68# Particle gun module
69particlegun = b2.register_module('ParticleGun')
70# Create Event information
71eventinfosetter = b2.register_module('EventInfoSetter')
72# Show progress of processing
73progress = b2.register_module('Progress')
74# Load parameters
75gearbox = b2.register_module('Gearbox')
76# Create geometry
77geometry = b2.register_module('Geometry')
78# Run simulation
79simulation = b2.register_module('FullSim')
80# PXD digitization module
81pxddigi = b2.register_module('PXDDigitizer')
82# PXD clustering module
83pxdclust = b2.register_module('PXDClusterizer')
84# Print hits
85printHits = PrintPXDHits()
86printHits.set_log_level(b2.LogLevel.INFO)
87
88# Specify number of events to generate
89eventinfosetter.param({'evtNumList': [5], 'runList': [1]})
90
91# Set parameters for particlegun
92particlegun.param({ # Generate 5 tracks on average
93 # the number of tracks is a Poisson variate
94 # Generate pi+, pi-, e+ and e-
95 # with a normal distributed transversal momentum
96 # with a center of 5 GeV and a width of 1 GeV
97 # a normal distributed phi angle,
98 # center of 180 degree and a width of 30 degree
99 # Generate theta angles uniform in cos theta
100 # between 17 and 150 degree
101 # normal distributed vertex generation
102 # around the origin with a sigma of 2cm in the xy plane
103 # and no deviation in z
104 # all tracks sharing the same vertex per event
105 'nTracks': 1,
106 'varyNTracks': True,
107 'pdgCodes': [211, -211, 11, -11],
108 'momentumGeneration': 'normalPt',
109 'momentumParams': [5, 1],
110 'phiGeneration': 'normal',
111 'phiParams': [0, 360],
112 'thetaGeneration': 'uniformCos',
113 'thetaParams': [17, 150],
114 'vertexGeneration': 'normal',
115 'xVertexParams': [0, 1],
116 'yVertexParams': [0, 1],
117 'zVertexParams': [0, 1],
118 'independentVertices': False,
119 })
120
121# Select subdetectors to be built
122geometry.param('components', ['MagneticField', 'PXD'])
123
124# create processing path
125main = b2.create_path()
126main.add_module(eventinfosetter)
127main.add_module(progress)
128main.add_module(particlegun)
129main.add_module(gearbox)
130main.add_module(geometry)
131main.add_module(simulation)
132main.add_module(pxddigi)
133main.add_module(pxdclust)
134main.add_module(printHits)
135
136# generate events
137b2.process(main)
138
139# show call statistics
140print(b2.statistics)
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
static GeoCache & getInstance()
Return a reference to the singleton instance.
Definition: GeoCache.cc:214