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