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