Belle II Software  release-05-01-25
BHWidePlots.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 # This steering file
5 # shows all options for the generation of radiative Bhabha scattering.
6 #
7 # 10000 radiative Bhabha events are generated using the BHWide Fortran
8 # 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, 6)
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 # Create the main path and add the modules
74 main = basf2.create_path()
75 
76 # event info setter
77 main.add_module("EventInfoSetter", expList=0, runList=1, evtNumList=100)
78 
79 # Register the BHWideInput module
80 bhwide = basf2.register_module('BHWideInput')
81 
82 # Set the min and max values for the theta scattering angle of the Positrons
83 bhwide.param('ScatteringAngleRangePositron', [5.7, 174.3])
84 
85 # Set the min and max values for the theta scattering angle of the Electrons
86 bhwide.param('ScatteringAngleRangeElectron', [5.7, 174.3])
87 
88 # Set the logging level for the BHWide module to INFO in order to see the total
89 # cross section
90 bhwide.set_log_level(basf2.LogLevel.INFO)
91 
92 # Register the Progress module and the Python histogram module
93 showMCPart = ShowMCParticles()
94 
95 main.add_module("Progress")
96 main.add_module(bhwide)
97 main.add_module(showMCPart)
98 
99 # generate events
100 basf2.process(main)
101 
102 # show call statistics
103 print(basf2.statistics)
104 
105 # Create a Canvas to show histograms
106 c = ROOT.TCanvas('Canvas', 'Canvas', 1536, 768)
107 c.Divide(4, 2, 1e-5, 1e-5)
108 
109 # Draw all histograms
110 histograms = [
111  h_nTracks,
112  h_pdg,
113  h_momentum,
114  h_pt,
115  h_theta,
116  h_costheta,
117  h_phi,
118 ]
119 for (i, h) in enumerate(histograms):
120  c.cd(i + 1)
121  h.SetMinimum(0)
122  h.Draw()
123 c.cd(i + 2)
124 h_vertex.Draw('colz')
125 c.Update()
126 
127 # Wait for enter to be pressed
128 sys.stdin.readline()
BHWidePlots.ShowMCParticles.event
def event(self)
Definition: BHWidePlots.py:53
BHWidePlots.ShowMCParticles
Definition: BHWidePlots.py:49
basf2.process
def process(path, max_event=0)
Definition: __init__.py:25
Belle2::PyStoreArray
a (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:58