Belle II Software  release-05-01-25
subtractCalPulse.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 # ---------------------------------------------------------------------------------------
5 # Subtract cal pulse time in TOPDigits::m_time
6 #
7 # Usage: basf2 subtractCalPulse.py [channel] -i <input_file.root> -o <output_file.root>
8 # channel calibration channel (0-7, default=0)
9 # input_file root file prepared with unpackToTOPDigits.py (calibrationChannel must be set)
10 # outpu_file root output file (default = RootOutput.root)
11 #
12 # cal pulse time is subtracted only if exactly two cal pulses are found for given asic
13 # if this requirement is not satisfied the hits for given asic are marked as c_Junk
14 # (see python module)
15 # ---------------------------------------------------------------------------------------
16 
17 from basf2 import *
18 from ROOT import Belle2
19 import sys
20 
21 calChannel = 0
22 argvs = sys.argv
23 if len(argvs) > 1:
24  calChannel = int(argvs[1])
25 
26 B2RESULT('using calibration channel ' + str(calChannel))
27 
28 
29 class SubtractCalSignal(Module):
30  ''' subtract time of the first calibration signal '''
31 
32  def event(self):
33  ''' event function '''
34 
35  digits = Belle2.PyStoreArray('TOPDigits')
36  t0 = [0 for i in range(64)]
37  num = [0 for i in range(64)]
38  for digit in digits:
39  channel = digit.getChannel()
40  i = int(channel / 8)
41  ch = int(channel) % 8
42  if ch == calChannel and digit.getHitQuality() == 4:
43  if num[i] == 0:
44  t0[i] = digit.getTime()
45  num[i] += 1
46  else:
47  t0[i] = min(t0[i], digit.getTime())
48  num[i] += 1
49  sum = 0
50  for digit in digits:
51  i = int(digit.getChannel()/8)
52  if num[i] == 2:
53  digit.subtractT0(t0[i])
54  sum += 1
55  else:
56  digit.setHitQuality(0)
57  if sum == 0:
58  B2ERROR("No calibration double pulses found in the event")
59 
60 
61 # Create path
62 main = create_path()
63 
64 # input
65 roinput = register_module('RootInput')
66 main.add_module(roinput)
67 
68 # Subtract time of the first calibration signal pulse
69 main.add_module(SubtractCalSignal())
70 
71 # output
72 output = register_module('RootOutput')
73 main.add_module(output)
74 
75 # Print progress
76 progress = register_module('Progress')
77 main.add_module(progress)
78 
79 # Process events
80 process(main)
81 
82 # Print statistics
83 print(statistics)
subtractCalPulse.SubtractCalSignal
Definition: subtractCalPulse.py:29
subtractCalPulse.SubtractCalSignal.event
def event(self)
Definition: subtractCalPulse.py:32
Belle2::PyStoreArray
a (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:58