Belle II Software development
checkHitHeightAndWidth.py
1#!/usr/bin/env python3
2
3
10
11import basf2 as b2
12from ROOT import Belle2
13from ROOT import TH2F, TFile, gDirectory
14
15#
16# ------------------------------------------------------------------------
17# Simple module to study the width and amplitude of TOPDigits
18#
19# usage: basf2 checkHitHeightAndWidth.py -i <raw_data.root>
20# ------------------------------------------------------------------------
21
22
23class Histogrammer(b2.Module):
24
25 ''' A module to histogram width and amplitude of TOPDigits '''
26
27 def initialize(self):
28 ''' Open output file and book histograms '''
29
30
31 self.tfile = TFile.Open('hitHeightAndWidth.root', 'recreate')
32 dirs = [gDirectory.mkdir('slot_' + f'{slot:02d}') for slot in range(1, 17)]
33
34
35 self.hist = []
36
37 self.histSampling = []
38
39 for slot in range(1, 17):
40 dirs[slot - 1].cd()
41 h = TH2F('WidthVSAmplitude', 'Slot ' + str(slot) +
42 ';amplitude [ADC counts]; width [ns]', 2000, 0, 2000, 200, 0, 10)
43 self.hist.append(h)
44 hh = [TH2F('WidthVSample_ch' + f'{ch:03d}', 'Slot ' + str(slot) + ', channel ' + str(ch) +
45 ';sample; width [ns]', 256, 0, 256, 200, 0, 10) for ch in range(512)]
46 self.histSampling.append(hh)
47
48 def event(self):
49 ''' Event processor: fill histograms '''
50
51 digits = Belle2.PyStoreArray('TOPDigits')
52 for digit in digits:
53 if digit.getHitQuality() == 0:
54 continue
55 slotID = digit.getModuleID()
56 hwchan = digit.getChannel()
57 self.hist[slotID - 1].Fill(digit.getPulseHeight(), digit.getPulseWidth())
58 self.histSampling[slotID - 1][hwchan].Fill(digit.getModulo256Sample(), digit.getPulseWidth())
59
60 def terminate(self):
61 ''' Write histograms to file '''
62
63 self.tfile.Write()
64 self.tfile.Close()
65
66
67# Suppress messages and warnings during processing
68b2.set_log_level(b2.LogLevel.ERROR)
69
70# Define a global tag
71b2.conditions.override_globaltags()
72b2.conditions.append_globaltag('online')
73
74# Create path
75main = b2.create_path()
76
77# input
78# roinput = b2.register_module('SeqRootInput') # sroot files
79roinput = b2.register_module('RootInput') # root files
80main.add_module(roinput)
81
82# Initialize TOP geometry parameters (creation of Geant geometry is not needed)
83main.add_module('TOPGeometryParInitializer')
84
85# Unpacking (format auto detection works now)
86unpack = b2.register_module('TOPUnpacker')
87main.add_module(unpack)
88
89# Convert to TOPDigits
90converter = b2.register_module('TOPRawDigitConverter')
91main.add_module(converter)
92
93# Histogrammer
94histogramModule = Histogrammer()
95main.add_module(histogramModule)
96
97# Show progress of processing
98progress = b2.register_module('Progress')
99main.add_module(progress)
100
101# Process events
102b2.process(main)
103
104# Print call statistics
105print(b2.statistics)
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
hist
Width VS amplitude plot in each slot.
histSampling
Width as function of the sample number in each channel.