Belle II Software  release-05-01-25
checkHitHeightAndWidth.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 from basf2 import *
5 import sys
6 import glob
7 from ROOT import Belle2
8 from ROOT import TH2F, TFile
9 
10 #
11 # ------------------------------------------------------------------------
12 # Simple module to study the width and amplitude of all the topdigits
13 # Umberto Tamponi (tamponi@to.infn.it)
14 #
15 # usage: basf2 checkHitHeightAndWidth.py run_number output_name.root
16 # the run number accepts wildcards
17 # ------------------------------------------------------------------------
18 
19 
20 class Histogrammer(Module):
21 
22  ''' A module to histogram width and amplitude of calibration pulses'''
23 
24 
25  hist = [TH2F('WidthVSAmplitude_Slot_' + str(k + 1), 'With VS amplidute of the Digits in slot ' + str(k + 1),
26  2000, 0., 2000, 80, 0., 20) for k in range(16)]
27 
28 
29  histSampling = [[TH2F('WidthVSample_Slot_' + str(k + 1) + '_Channel_' + str(j),
30  'With VS amplidute of the Digits in slot ' + str(k + 1) + ' channel ' + str(j),
31  256,
32  0.,
33  256,
34  100,
35  0.,
36  20) for k in range(16)] for j in range(512)]
37 
38  outname = 'calpulseCheck.root'
39 
40  def setOutputName(self, outputname):
41  ''' Sets the output file name '''
42 
43 
44  self.outname = outputname
45 
46  def event(self):
47  ''' Event processor: fill histograms '''
48 
49  digits = Belle2.PyStoreArray('TOPDigits')
50  for digit in digits:
51  quality = digit.getHitQuality()
52  slotID = digit.getModuleID()
53  hwchan = digit.getChannel()
54  self.hist[slotID - 1].Fill(digit.getPulseHeight(), digit.getPulseWidth())
55  self.histSampling[hwchan][slotID - 1].Fill(digit.getModulo256Sample(), digit.getPulseWidth())
56 
57  def terminate(self):
58  ''' Write histograms to file '''
59 
60  tfile = TFile(self.outname, 'recreate')
61  for k in range(16):
62  self.hist[k].GetXaxis().SetTitle("TOPDigit amplitude [ADC counts]")
63  self.hist[k].GetYaxis().SetTitle("TOPDigit width [ns]")
64  self.hist[k].Write()
65  for k in range(16):
66  for j in range(512):
67  self.histSampling[j][k].GetXaxis().SetTitle("TOPDigit sample%256")
68  self.histSampling[j][k].GetYaxis().SetTitle("TOPDigit width [ns]")
69  self.histSampling[j][k].Write()
70 
71  tfile.Close()
72 
73 
74 argvs = sys.argv
75 
76 print('usage: basf2', argvs[0], 'runNumber outfileName')
77 
78 runnumber = argvs[1] # run number. Wildcards should work
79 outfile = argvs[2] # output name
80 
81 
82 files = glob.glob('/ghi/fs01/belle2/bdata/Data/sRaw/e0001/r0' + str(runnumber) + '/sub00/*.sroot')
83 
84 # Suppress messages and warnings during processing
85 set_log_level(LogLevel.ERROR)
86 
87 # Define a global tag (note: the one given bellow will become out-dated!)
88 use_central_database('data_reprocessing_proc8')
89 
90 # Create path
91 main = create_path()
92 
93 # input
94 roinput = register_module('SeqRootInput')
95 roinput.param('inputFileNames', files)
96 main.add_module(roinput)
97 
98 #
99 # conversion from RawCOPPER or RawDataBlock to RawDetector objects
100 # Pocket DAQ data not supported yet
101 #
102 # if datatype == 'pocket':
103 # print('pocket DAQ data assumed')
104 # converter = register_module('Convert2RawDet')
105 # main.add_module(converter)
106 
107 # Initialize TOP geometry parameters (creation of Geant geometry is not needed)
108 main.add_module('TOPGeometryParInitializer')
109 
110 # Unpacking (format auto detection works now)
111 unpack = register_module('TOPUnpacker')
112 main.add_module(unpack)
113 
114 # Add multiple hits by running feature extraction offline
115 featureExtractor = register_module('TOPWaveformFeatureExtractor')
116 main.add_module(featureExtractor)
117 
118 # Convert to TOPDigits
119 converter = register_module('TOPRawDigitConverter')
120 converter.param('useSampleTimeCalibration', False)
121 converter.param('useChannelT0Calibration', False)
122 converter.param('useModuleT0Calibration', False)
123 converter.param('useCommonT0Calibration', False)
124 # converter.param('calibrationChannel', channel) # if set, cal pulses will be flagged
125 converter.param('calpulseHeightMin', 450) # in [ADC counts]
126 converter.param('calpulseHeightMax', 900) # in [ADC counts]
127 converter.param('calpulseWidthMin', 2.0) # in [ns]
128 converter.param('calpulseWidthMax', 8.0) # in [ns]
129 converter.param('lookBackWindows', 29) # in number of windows
130 main.add_module(converter)
131 
132 # Histogrammer
133 histogramModule = Histogrammer()
134 histogramModule.setOutputName(outfile)
135 main.add_module(histogramModule)
136 
137 # Show progress of processing
138 progress = register_module('Progress')
139 main.add_module(progress)
140 
141 # Process events
142 process(main)
143 
144 # Print call statistics
145 print(statistics)
146 print(statistics(statistics.TERM))
checkHitHeightAndWidth.Histogrammer.histSampling
list histSampling
Width as function of the sample number in each channel.
Definition: checkHitHeightAndWidth.py:29
checkHitHeightAndWidth.Histogrammer
Definition: checkHitHeightAndWidth.py:20
checkHitHeightAndWidth.Histogrammer.terminate
def terminate(self)
Definition: checkHitHeightAndWidth.py:57
checkHitHeightAndWidth.Histogrammer.setOutputName
def setOutputName(self, outputname)
Definition: checkHitHeightAndWidth.py:40
checkHitHeightAndWidth.Histogrammer.event
def event(self)
Definition: checkHitHeightAndWidth.py:46
checkHitHeightAndWidth.Histogrammer.hist
list hist
Width VS amplitude plot in each slot.
Definition: checkHitHeightAndWidth.py:25
Belle2::PyStoreArray
a (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:58
checkHitHeightAndWidth.Histogrammer.outname
string outname
Default output name.
Definition: checkHitHeightAndWidth.py:38