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