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