Belle II Software  release-05-01-25
zero_suppression.py
1 import basf2
2 import ROOT
3 from ROOT import Belle2
4 import b2test_utils
5 
6 # ====================================================================
7 # This test does the following:
8 # 1. Simulate a few hundred ParticleGun events to produce a sample of
9 # SVD simhits.
10 # 2. Use SVDDigitizer with varius zero-suppression cut settings and check
11 # that the settings work.
12 # ====================================================================
13 
14 
15 class CheckZS(basf2.Module):
16  """Check that SVVDShaperDigits are correctly zero-suppressed."""
17 
18  def __init__(self, thresholdSN):
19  '''initialize python module'''
20  super().__init__()
21  self.thresholdSN = thresholdSN
22  '''SNR threshold'''
23 
24  def event(self):
25  '''event'''
26  storedigits = Belle2.PyStoreArray("SVDShaperDigits")
28  for digit in storedigits:
29  info = gc.get(digit.getSensorID())
30  isU = digit.isUStrip()
31  noise_in_e = info.getElectronicNoiseU() if isU else info.getElectronicNoiseV()
32  adu_equivalent = info.getAduEquivalentU() if isU else info.getAduEquivalentV()
33  noise_in_adu = noise_in_e / adu_equivalent
34  threshold_in_adu = self.thresholdSN * noise_in_adu
35  samples = digit.getSamples()
36  for s in samples:
37  if s > threshold_in_adu:
38  break
39  else:
40  basf2.B2FATAL("Found digit under threshold: {0}".format(digit.to_string()))
41 
42 
43 if __name__ == "__main__":
44 
46 
47  basf2.B2INFO('Creating simhits...')
48  # We create data separately, so that we can use them in other tests.
49 
50  create_simhits = basf2.create_path()
51  create_simhits.add_module('EventInfoSetter', evtNumList=[50])
52  create_simhits.add_module('Gearbox')
53  create_simhits.add_module('Geometry', components=['MagneticField', 'SVD'], useDB=False)
54  create_simhits.add_module('ParticleGun')
55  create_simhits.add_module('FullSim')
56  create_simhits.add_module('RootOutput', outputFileName='SimulationForThresholdTest.root',
57  branchNames=['EventMetaData', 'SVDSimHits', 'SVDTrueHits'])
59  b2test_utils.safe_process(create_simhits)
60 
61  basf2.B2INFO('Threshold testing...')
62 
63  threshold = 3
64 
65  test_threshold = basf2.create_path()
66  # Read generated Simhits and Truehits
67  test_threshold.add_module('RootInput', inputFileName='SimulationForThresholdTest.root')
68  test_threshold.add_module('Gearbox')
69  test_threshold.add_module('Geometry', components=['MagneticField', 'SVD'], useDB=False)
70  # Set the threshold.
71  test_threshold.add_module('SVDDigitizer', ZeroSuppressionCut=threshold)
72  threshold_checker = CheckZS(threshold)
73  test_threshold.add_module(threshold_checker)
75  b2test_utils.safe_process(test_threshold)
76 
77  basf2.B2INFO('Test done.')
zero_suppression.CheckZS
Definition: zero_suppression.py:15
zero_suppression.CheckZS.__init__
def __init__(self, thresholdSN)
Definition: zero_suppression.py:18
b2test_utils.show_only_errors
def show_only_errors()
Definition: __init__.py:87
zero_suppression.CheckZS.event
def event(self)
Definition: zero_suppression.py:24
Belle2::VXD::GeoCache::getInstance
static GeoCache & getInstance()
Return a reference to the singleton instance.
Definition: GeoCache.cc:215
zero_suppression.CheckZS.thresholdSN
thresholdSN
Definition: zero_suppression.py:21
b2test_utils.clean_working_directory
def clean_working_directory()
Definition: __init__.py:176
Belle2::PyStoreArray
a (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:58
b2test_utils.safe_process
def safe_process(*args, **kwargs)
Definition: __init__.py:224