Belle II Software  release-05-01-25
simpleEventDisplay.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 # avoid race conditions beetween pyroot and GUI thread
5 from ROOT import PyConfig
6 PyConfig.StartGuiThread = False
7 
8 from basf2 import *
9 import os
10 import glob
11 import sys
12 
13 from ROOT import Belle2
14 from ROOT import TH1F, TH2F, TCanvas
15 from simulation import add_simulation
16 from reconstruction import add_reconstruction
17 
18 
19 # ------------------------------------------------------------------------------
20 # An example of a simple event display, made by using a python module.
21 # It displays timing distributions of modules produced by a generic BBbar event.
22 # Red histograms are marking the modules with at least one track impact.
23 # ------------------------------------------------------------------------------
24 
25 class TOPDisplay(Module):
26 
27  '''
28  Simple event display for TOP.
29  It displays single event timing distributions of modules using TOPDigits.
30  Distributions of modules with the track impact are shown in red color.
31  '''
32 
33 
34  hist = [TH1F('h' + str(i), 'module#' + str(i), 128, 0.0, 256.0) for i in
35  range(16)]
36 
37  c1 = TCanvas('c1', 'TOP event display', 1000, 800)
38 
39  def initialize(self):
40  ''' Initialize the Module: open the canvas. '''
41 
42  self.c1.Divide(4, 4)
43  self.c1.Show()
44 
45  def event(self):
46  '''
47  Event processor: reset and fill the histograms, display them,
48  wait for user respond.
49  '''
50 
51  for i in range(16):
52  self.hist[i].Reset()
53  self.hist[i].SetFillColor(0)
54  self.hist[i].SetLineColor(1)
55 
56  likelihoods = Belle2.PyStoreArray('TOPLikelihoods')
57  for likelihood in likelihoods:
58  if likelihood.getFlag() == 1:
59  exthit = likelihood.getRelated('ExtHits')
60  try:
61  moduleID = exthit.getCopyID()
62  self.hist[moduleID - 1].SetFillColor(2)
63  self.hist[moduleID - 1].SetLineColor(2)
64  except:
65  B2ERROR('No relation to ExtHit')
66 
67  digits = Belle2.PyStoreArray('TOPDigits')
68  for digit in digits:
69  moduleID = digit.getModuleID()
70  tdc = digit.getRawTime()
71  self.hist[moduleID - 1].Fill(tdc)
72 
73  for i in range(16):
74  self.c1.cd(i + 1)
75  self.hist[i].Draw()
76 
77  self.c1.Update()
78 
79  # wait for user respond
80  try:
81  q = 0
82  Q = 0
83  abc = eval(input('Type <CR> to continue or Q to quit '))
84  evtMetaData = Belle2.PyStoreObj('EventMetaData')
85  evtMetaData.obj().setEndOfData()
86  except:
87  abc = '' # dummy line to terminate try-except
88 
89 
90 # Check if the display is set (needed for canvas)
91 if 'DISPLAY' not in os.environ:
92  print('DISPLAY variable is not set')
93  print('- to set it in bash: export DISPLAY=:0')
94  print('- to set it in csh: setenv DISPLAY :0')
95  sys.exit()
96 
97 # Suppress messages other than errors
98 set_log_level(LogLevel.ERROR)
99 
100 # Create path
101 main = create_path()
102 
103 # Set number of events to generate
104 eventinfosetter = register_module('EventInfoSetter')
105 eventinfosetter.param('evtNumList', [1000])
106 main.add_module(eventinfosetter)
107 
108 # generate BBbar events
109 evtgeninput = register_module('EvtGenInput')
110 main.add_module(evtgeninput)
111 
112 # Detector simulation
113 bg = None
114 if 'BELLE2_BACKGROUND_DIR' in os.environ:
115  bg = glob.glob(os.environ['BELLE2_BACKGROUND_DIR'] + '/*.root')
116 add_simulation(main, bkgfiles=bg)
117 
118 # Reconstruction
119 add_reconstruction(main)
120 
121 # dispay
122 main.add_module(TOPDisplay())
123 
124 # Show progress of processing
125 progress = register_module('Progress')
126 main.add_module(progress)
127 
128 # Process events
129 process(main)
130 
131 # Print call statistics
132 print(statistics)
simpleEventDisplay.TOPDisplay.initialize
def initialize(self)
Definition: simpleEventDisplay.py:39
simpleEventDisplay.TOPDisplay.hist
list hist
1D histograms
Definition: simpleEventDisplay.py:34
Belle2::PyStoreObj
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:69
simpleEventDisplay.TOPDisplay.event
def event(self)
Definition: simpleEventDisplay.py:45
Belle2::eval
double eval(const std::vector< double > &spl, const std::vector< double > &vals, double x)
Evaluate spline (zero order or first order) in point x.
Definition: tools.h:118
simpleEventDisplay.TOPDisplay.c1
c1
canvas
Definition: simpleEventDisplay.py:37
Belle2::PyStoreArray
a (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:58
simpleEventDisplay.TOPDisplay
Definition: simpleEventDisplay.py:25