Belle II Software development
checkCalpulse.py
1#!/usr/bin/env python3
2
3
10
11# ---------------------------------------------------------------------------------------------------------------------------
12# Makes histograms from TOPDigits to decide visually about calpulse selection settings.
13# Input: pulser or laser raw data in root format (local run)
14# Output: checkCalpulse.root
15#
16# usage: basf2 checkCalpulse.py -i <local_run.root> [cal_channel] [time_cut_lo] [time_cut_hi] [localDB]
17# cal_channel (optional) calibration channel number (0 - 7), if given TOPDigits in other ASIC channels will be ignored
18# time_cut_lo (optional) cut on hit time, if given TOPDigits with time < time_cut_lo will be ignored
19# time_cut_hi (optional) cut on hit time, if given TOPDigits with time > time_cut_hi will be ignored
20# localDB (optional) local database or global tag, if given the time base calibration will be used
21# ---------------------------------------------------------------------------------------------------------------------------
22
23import basf2 as b2
24from ROOT import Belle2
25from ROOT import TFile, TH1F, TH2F
26import sys
27
28look_back_windows = 30 # make sure this is the correct setting for your local run!
29
30cal_channel = None
31if len(sys.argv) > 1:
32 cal_channel = int(sys.argv[1])
33time_cut_lo = None
34if len(sys.argv) > 2:
35 time_cut_lo = float(sys.argv[2])
36time_cut_hi = None
37if len(sys.argv) > 3:
38 time_cut_hi = float(sys.argv[3])
39use_sample_times = False
40use_asic_shifts = False
41if len(sys.argv) > 4:
42 use_sample_times = True
43 use_asic_shifts = True
44 tag = sys.argv[4]
45 if '.txt' in tag:
46 b2.conditions.append_testing_payloads(tag)
47 else:
48 b2.conditions.expert_settings(usable_globaltag_states={'PUBLISHED', 'RUNNING', 'TESTING', 'VALIDATED', 'OPEN'})
49 b2.conditions.prepend_globaltag(tag)
50
51
52class Histogrammer(b2.Module):
53 ''' Makes histograms from TOPDigits '''
54
55 def initialize(self):
56 ''' initialize: open root file, book histograms '''
57
58
59 self.tfile = TFile.Open('checkCalpulse.root', 'recreate')
60
61 self.height_vs_width = TH2F("height_vs_width", "Pulse height vs. width; pulse width [ns]; pulse height [ADC counts]",
62 100, 0, 10, 200, 0, 2000)
63
64 self.height_vs_sample = TH2F("height_vs_sample", "Pulse height vs. sample; sample number; pulse height [ADC counts]",
65 256, 0, 256, 200, 0, 2000)
66
67 self.width_vs_sample = TH2F("width_vs_sample", "Pulse width vs. sample; sample number; pulse width [ns]",
68 256, 0, 256, 100, 0, 10)
69
70 self.time = TH1F('time', 'Time distibution; time [ns]', 400, -100, 300)
71
72 self.asic_channels = TH1F('asic_channels', 'ASIC channel occupancy; ASIC channel number', 8, 0, 8)
73
74 def event(self):
75 ''' event processing: fill histograms '''
76
77 for digit in Belle2.PyStoreArray('TOPDigits'):
78 if digit.getHitQuality() == 0:
79 continue
80 if cal_channel is not None and digit.getASICChannel() != cal_channel:
81 continue
82 if time_cut_lo is not None and digit.getTime() < time_cut_lo:
83 continue
84 if time_cut_hi is not None and digit.getTime() > time_cut_hi:
85 continue
86 self.height_vs_width.Fill(digit.getPulseWidth(), digit.getPulseHeight())
87 self.height_vs_sample.Fill(digit.getModulo256Sample(), digit.getPulseHeight())
88 if digit.getPulseHeight() > 100:
89 self.width_vs_sample.Fill(digit.getModulo256Sample(), digit.getPulseWidth())
90 self.time.Fill(digit.getTime())
91 self.asic_channels.Fill(digit.getASICChannel())
92
93 def terminate(self):
94 ''' terminate: write histograms and close the file '''
95
96 h = self.height_vs_width.ProjectionX('width')
97 h.SetTitle('Pulse width')
98 h = self.height_vs_width.ProjectionY('height')
99 h.SetTitle('Pulse height')
100 self.tfile.Write()
101 self.tfile.Close()
102
103
104main = b2.create_path()
105main.add_module('RootInput')
106main.add_module('TOPGeometryParInitializer')
107main.add_module('TOPUnpacker')
108main.add_module('TOPRawDigitConverter',
109 useSampleTimeCalibration=use_sample_times,
110 useAsicShiftCalibration=use_asic_shifts,
111 useChannelT0Calibration=False,
112 useModuleT0Calibration=False,
113 useCommonT0Calibration=False,
114 minPulseWidth=0.5,
115 lookBackWindows=look_back_windows)
116
117main.add_module(Histogrammer())
118main.add_module('Progress')
119
120# Process events
121b2.process(main)
122
123# Print call statistics
124print(b2.statistics)
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
height_vs_sample
histogram of pulse height vs.
asic_channels
histogram of asic channel occupancy
width_vs_sample
histogram of pulse width vs.
height_vs_width
histogram of pulse height vs.
time
histogram of time distribution