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