Belle II Software development
PhokharaEvtgenAnalyze.py
1#!/usr/bin/env python3
2
3"""
4<header>
5 <input>PhokharaEvtgenData.root</input>
6 <output>PhokharaEvtgenAnalysis.root</output>
7 <contact>Kirill Chilikin (K.A.Chilikin@inp.nsk.su)</contact>
8 <description>Analysis of e+ e- -> J/psi eta_c events.</description>
9</header>
10"""
11
12import basf2 as b2
13import ROOT
14import numpy
15from ROOT import Belle2
16
17
18class PhokharaEvtgenAnalysisModule(b2.Module):
19 """ Analysis module for PhokharaEvtgen. """
20
21 def __init__(self):
22 """Initialization."""
23 super().__init__()
24
25 self.output_file = ROOT.TFile('PhokharaEvtgenAnalysis.root', 'recreate')
26
27 self.tree = ROOT.TTree('tree', '')
28
29 self.ecms = numpy.zeros(1, dtype=numpy.float32)
30
31 self.gamma_e = numpy.zeros(1, dtype=numpy.float32)
32
33 self.gamma_px = numpy.zeros(1, dtype=numpy.float32)
34
35 self.gamma_py = numpy.zeros(1, dtype=numpy.float32)
36
37 self.gamma_pz = numpy.zeros(1, dtype=numpy.float32)
38
39 self.jpsi_e = numpy.zeros(1, dtype=numpy.float32)
40
41 self.jpsi_px = numpy.zeros(1, dtype=numpy.float32)
42
43 self.jpsi_py = numpy.zeros(1, dtype=numpy.float32)
44
45 self.jpsi_pz = numpy.zeros(1, dtype=numpy.float32)
46
47 self.lepton_e = numpy.zeros(1, dtype=numpy.float32)
48
49 self.lepton_px = numpy.zeros(1, dtype=numpy.float32)
50
51 self.lepton_py = numpy.zeros(1, dtype=numpy.float32)
52
53 self.lepton_pz = numpy.zeros(1, dtype=numpy.float32)
54 self.tree.Branch('ecms', self.ecms, 'ecms/F')
55 self.tree.Branch('gamma_e', self.gamma_e, 'gamma_e/F')
56 self.tree.Branch('gamma_px', self.gamma_px, 'gamma_px/F')
57 self.tree.Branch('gamma_py', self.gamma_py, 'gamma_py/F')
58 self.tree.Branch('gamma_pz', self.gamma_pz, 'gamma_pz/F')
59 self.tree.Branch('jpsi_e', self.jpsi_e, 'jpsi_e/F')
60 self.tree.Branch('jpsi_px', self.jpsi_px, 'jpsi_px/F')
61 self.tree.Branch('jpsi_py', self.jpsi_py, 'jpsi_py/F')
62 self.tree.Branch('jpsi_pz', self.jpsi_pz, 'jpsi_pz/F')
63 self.tree.Branch('lepton_e', self.lepton_e, 'lepton_e/F')
64 self.tree.Branch('lepton_px', self.lepton_px, 'lepton_px/F')
65 self.tree.Branch('lepton_py', self.lepton_py, 'lepton_py/F')
66 self.tree.Branch('lepton_pz', self.lepton_pz, 'lepton_pz/F')
67
68 def event(self):
69 """ Event function. """
70 mc_initial_particles = Belle2.PyStoreObj('MCInitialParticles')
71 self.ecms[0] = mc_initial_particles.getMass()
72 mc_particles = Belle2.PyStoreArray('MCParticles')
73 for mc_particle in mc_particles:
74 # Select virtual photons.
75 if (mc_particle.getPDG() != 10022):
76 continue
77 p = mc_particle.getMomentum()
78 self.gamma_e[0] = mc_particle.getEnergy()
79 self.gamma_px[0] = p.X()
80 self.gamma_py[0] = p.Y()
81 self.gamma_pz[0] = p.Z()
82 jpsi = mc_particle.getDaughters()[0]
83 p = jpsi.getMomentum()
84 self.jpsi_e[0] = jpsi.getEnergy()
85 self.jpsi_px[0] = p.X()
86 self.jpsi_py[0] = p.Y()
87 self.jpsi_pz[0] = p.Z()
88 lepton = jpsi.getDaughters()[0]
89 p = lepton.getMomentum()
90 self.lepton_e[0] = lepton.getEnergy()
91 self.lepton_px[0] = p.X()
92 self.lepton_py[0] = p.Y()
93 self.lepton_pz[0] = p.Z()
94 self.tree.Fill()
95
96 def terminate(self):
97 """ Termination function. """
98 self.output_file.cd()
99 self.tree.Write()
100 self.output_file.Close()
101
102
103
104
105# Input.
106root_input = b2.register_module('RootInput')
107root_input.param('inputFileName', 'PhokharaEvtgenData.root')
108
109# Analysis.
110phokhara_evtgen = PhokharaEvtgenAnalysisModule()
111
112# Create main path.
113main = b2.create_path()
114
115
116
117# Add modules to main path
118main.add_module(root_input)
119main.add_module(phokhara_evtgen)
120
121main.add_module('Progress')
122# Run.
123b2.process(main)
124
125print(b2.statistics)
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67
gamma_py
Virtual photon momentum (y component).
gamma_px
Virtual photon momentum (x component).
gamma_pz
Virtual photon momentum (z component).