Belle II Software  release-08-01-10
histogram_monitor.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 # Creates two histograms and adds them to the 'Histogram' tab in the display
13 # Doubleclicking them will show them in the current canvas (added on
14 # the right side of the screen) and keep them updated each event.
15 
16 import basf2 as b2
17 
18 from ROOT import Belle2
19 from ROOT import TH1F
20 from ROOT import TH3F
21 
22 
23 class GenerateHist(b2.Module):
24  """Generate some histograms to pass to the display."""
25 
26 
27  edep_hist = TH1F("CDC_edep", "Energy deposition from CDCSimHits", 100, 0.0, 10e-6)
28 
29  pos_hist = TH3F("CDC_pos", "Positions of CDCSimHits",
30  100, -150.0, 150.0,
31  100, -150.0, 150.0,
32  100, -150.0, 150.0)
33 
34  def initialize(self):
35  """reimplementation of Module::initialize()."""
36 
37  Belle2.PyStoreObj("DisplayData").registerInDataStore()
38 
39  def event(self):
40  """reimplementation of Module::event()."""
41 
42  displayData = Belle2.PyStoreObj("DisplayData")
43  displayData.create()
44 
45  cdcsimhits = Belle2.PyStoreArray("CDCSimHits")
46  for hit in cdcsimhits:
47  self.edep_histedep_hist.Fill(hit.getEnergyDep())
48  p = hit.getPosWire()
49  self.pos_histpos_hist.Fill(p.X(), p.Y(), p.Z())
50 
51  displayData.obj().addHistogram("CDC_edep", self.edep_histedep_hist)
52  displayData.obj().addHistogram("CDC_pos", self.pos_histpos_hist)
53 
54 
55 # register necessary modules
56 eventinfosetter = b2.register_module('EventInfoSetter')
57 eventinfosetter.param('evtNumList', [500])
58 
59 
60 # create geometry
61 gearbox = b2.register_module('Gearbox')
62 geometry = b2.register_module('Geometry')
63 geometry.param('components', ['CDC', 'MagneticField'])
64 
65 particlegun = b2.register_module('ParticleGun')
66 
67 # simulation
68 g4sim = b2.register_module('FullSim')
69 # make the simulation less noisy
70 g4sim.logging.log_level = b2.LogLevel.ERROR
71 
72 # create paths
73 main = b2.create_path()
74 
75 # add modules to paths
76 main.add_module(eventinfosetter)
77 
78 main.add_module(gearbox)
79 main.add_module(geometry)
80 main.add_module(particlegun)
81 main.add_module(g4sim)
82 
83 main.add_module(GenerateHist())
84 
85 # default parameters
86 display = b2.register_module('Display')
87 main.add_module(display)
88 
89 b2.process(main)
90 print(b2.statistics)
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67
edep_hist
histogram for SimHit energy deposition
pos_hist
histogram for SimHit positions