Belle II Software  release-05-01-25
KoralWPlots.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 # ####################################################### This steering file
5 # shows all options for the generation of four fermion final state events.
6 #
7 # 100 four fermion final state QED events are generated using the KoralW
8 # Fortran generator and some plots are shown at the end.
9 #
10 # Example steering file - 2011 Belle II Collaboration
11 # #######################################################
12 
13 import sys
14 import math
15 import basf2
16 
17 # reenable GUI thread for our canvas
18 from ROOT import PyConfig
19 PyConfig.StartGuiThread = True
20 
21 # Set the global log level
22 basf2.logging.log_level = basf2.LogLevel.WARNING
23 
24 # Load the required libraries
25 import ROOT
26 from ROOT import Belle2
27 
28 # Create some histograms to be filled
29 h_nTracks = ROOT.TH1D('nTracks', 'Number of Tracks per Event;#', 20, 0, 20)
30 h_pdg = ROOT.TH1D('pid', 'Particle code of particles', 100, -50, 50)
31 h_momentum = ROOT.TH1D('momentum', 'Momentum of particles', 200, 0, 8)
32 h_pt = ROOT.TH1D('pt', 'Transverse Momentum of particles', 200, 0, 2)
33 h_phi = ROOT.TH1D('phi', 'Azimuth angle of particles', 200, -180, 180)
34 h_theta = ROOT.TH1D('theta', 'Polar angle of particles', 200, 0, 180)
35 h_costheta = ROOT.TH1D('costheta', 'Cosinus of the polar angle of particles',
36  200, -1, 1)
37 h_vertex = ROOT.TH2D(
38  'xyvertex',
39  'XY Vertex of particles',
40  200,
41  -10,
42  10,
43  200,
44  -10,
45  10,
46 )
47 
48 
49 class ShowMCParticles(basf2.Module):
50 
51  """Simple module to collect some information about MCParticles"""
52 
53  def event(self):
54  """Fill the histograms with the values of the MCParticle collection"""
55 
56  mcParticles = Belle2.PyStoreArray('MCParticles')
57  nTracks = mcParticles.getEntries()
58  h_nTracks.Fill(nTracks)
59  for i in range(nTracks):
60  mc = mcParticles[i]
61  if mc.hasStatus(Belle2.MCParticle.c_PrimaryParticle):
62  p = mc.getMomentum()
63  h_momentum.Fill(p.Mag())
64  h_pt.Fill(p.Perp())
65  h_phi.Fill(p.Phi() / math.pi * 180)
66  h_theta.Fill(p.Theta() / math.pi * 180)
67  h_costheta.Fill(math.cos(p.Theta()))
68  h_pdg.Fill(mc.getPDG())
69  h_vertex.Fill(mc.getProductionVertex().X(),
70  mc.getProductionVertex().Y())
71 
72 
73 main = basf2.create_path()
74 
75 # event info setter
76 main.add_module("EventInfoSetter", expList=0, runList=1, evtNumList=100)
77 
78 # Register the BHWideInput module
79 koralw = basf2.register_module('KoralWInput')
80 
81 # Set the logging level for the KoralW module to INFO in order to see the total
82 # cross section
83 koralw.set_log_level(basf2.LogLevel.INFO)
84 
85 # Register the Progress module and the Python histogram module
86 progress = basf2.register_module('Progress')
87 showMCPart = ShowMCParticles()
88 
89 # Create the main path and add the modules
90 main.add_module(progress)
91 main.add_module(koralw)
92 main.add_module(showMCPart)
93 
94 # generate events
95 basf2.process(main)
96 
97 # show call statistics
98 print(basf2.statistics)
99 
100 # Create a Canvas to show histograms
101 c = ROOT.TCanvas('Canvas', 'Canvas', 1536, 768)
102 c.Divide(4, 2, 1e-5, 1e-5)
103 
104 # Draw all histograms
105 histograms = [
106  h_nTracks,
107  h_pdg,
108  h_momentum,
109  h_pt,
110  h_theta,
111  h_costheta,
112  h_phi,
113 ]
114 for (i, h) in enumerate(histograms):
115  c.cd(i + 1)
116  h.SetMinimum(0)
117  h.Draw()
118 c.cd(i + 2)
119 h_vertex.Draw('colz')
120 c.Update()
121 
122 # Wait for enter to be pressed
123 sys.stdin.readline()
basf2.process
def process(path, max_event=0)
Definition: __init__.py:25
KoralWPlots.ShowMCParticles
Definition: KoralWPlots.py:49
Belle2::PyStoreArray
a (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:58
KoralWPlots.ShowMCParticles.event
def event(self)
Definition: KoralWPlots.py:53