Belle II Software development
CDCPlotModule Class Reference
Inheritance diagram for CDCPlotModule:

Public Member Functions

def event (self)
 
def terminate (self)
 

Static Public Attributes

int num_events = 0
 event counter
 

Detailed Description

An example python module.

It gathers the x/y position off all CDCSimHits and draws them using
matplotlib. The result is saved as a PNG.

Definition at line 61 of file cdcplotmodule.py.

Member Function Documentation

◆ event()

def event (   self)
reimplementation of Module::event().

loops over the CDCSimHits in the current event.

Definition at line 71 of file cdcplotmodule.py.

71 def event(self):
72 """reimplementation of Module::event().
73
74 loops over the CDCSimHits in the current event.
75 """
76 simhits = Belle2.PyStoreArray('CDCSimHits')
77
78 # list of lists of simhit positions, one list per mcpart
79 trackhits_x = []
80 trackhits_y = []
81
82 mcparts = []
83 for hit in simhits:
84 mcpart = hit.getRelatedFrom("MCParticles")
85 if mcpart not in mcparts:
86 mcparts.append(mcpart)
87 trackhits_x.append([])
88 trackhits_y.append([])
89 # add simhit to the list corresponding to this particle
90 idx = mcparts.index(mcpart)
91 hitpos = hit.getPosWire() # TVector3
92 trackhits_x[idx].append(hitpos.X())
93 trackhits_y[idx].append(hitpos.Y())
94
95 npart = len(mcparts)
96 if npart > 0:
97 # plot the (x,y) list on a matplotlib figure
98 col = [colormap.jet(1.0 * c / (npart - 1)) for c in range(npart)]
99 fig = plot(trackhits_x, trackhits_y, col)
100
101 filename = f'cdchits_{self.num_events}.png'
102 if os.path.lexists(filename):
103 B2WARNING(filename + ' exists, overwriting ...')
104 else:
105 B2INFO('creating ' + filename + ' ...')
106 fig.savefig(filename)
107
108 self.num_events += 1
109
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
Definition: plot.py:1

◆ terminate()

def terminate (   self)
reimplementation of Module::terminate().

Definition at line 110 of file cdcplotmodule.py.

110 def terminate(self):
111 """reimplementation of Module::terminate()."""
112 B2INFO('terminating CDCPlotModule')
113
114
115# Normal steering file part begins here
116
117# choose the particles you want to simulate

Member Data Documentation

◆ num_events

int num_events = 0
static

event counter

Definition at line 69 of file cdcplotmodule.py.


The documentation for this class was generated from the following file: