Belle II Software  release-08-01-10
PXDDataBaseImporter.py
1 #!/usr/bin/env python3
2 
3 
10 
11 
12 
17 
18 
19 import basf2 as b2
20 from ROOT import Belle2
21 import ROOT
22 
23 # set some random seed
24 b2.set_random_seed(10346)
25 
26 
27 def importEmptyHotPixelMask(expLow=0, runLow=0, expHigh=-1, runHigh=-1):
28  """
29  This function imports an empty payloads for the PXD
30  hot pixel masking.
31 
32  This function works for every Belle 2 geometry
33  """
34 
35  # Create an empty hot pixel mask
36  HotPixelMask = Belle2.PXDMaskedPixelPar()
37 
38  # Set the iov for the mask
39  iov = Belle2.IntervalOfValidity(expLow, runLow, expHigh, runHigh)
40  Belle2.Database.Instance().storeData('PXDMaskedPixelPar', HotPixelMask, iov)
41 
42 
43 def importEmptyDeadPixelMask(expLow=0, runLow=0, expHigh=-1, runHigh=-1):
44  """
45  This function imports an empty payloads for the PXD
46  dead pixel masking.
47 
48  This function works for every Belle 2 geometry
49  """
50 
51  # Create an empty mask
52  DeadPixelMask = Belle2.PXDDeadPixelPar()
53 
54  # Set the iov for the mask
55  iov = Belle2.IntervalOfValidity(expLow, runLow, expHigh, runHigh)
56  Belle2.Database.Instance().storeData('PXDDeadPixelPar', DeadPixelMask, iov)
57 
58 
59 def importEmptyOccupancyInfo(expLow=0, runLow=0, expHigh=-1, runHigh=-1):
60  """
61  This function imports an empty payloads for the PXD
62  pixel masking.
63 
64  This function works for every Belle 2 geometry
65  """
66 
67  # Create a dummy occupancy info
68  OccupancyInfo = Belle2.PXDOccupancyInfoPar()
69 
70  # Set the iov for the mask
71  iov = Belle2.IntervalOfValidity(expLow, runLow, expHigh, runHigh)
72  Belle2.Database.Instance().storeData('PXDOccupancyInfoPar', OccupancyInfo, iov)
73 
74 
75 def importEmptyClusterChargeMap(expLow=0, runLow=0, expHigh=-1, runHigh=-1):
76  """
77  This function imports an empty payloads for the PXD
78  gain calibration.
79 
80  This function works for every Belle 2 geometry
81  """
82 
83  # Create a dummy payload
84  ChargeMap = Belle2.PXDClusterChargeMapPar()
85 
86  # Set the iov for the mask
87  iov = Belle2.IntervalOfValidity(expLow, runLow, expHigh, runHigh)
88  Belle2.Database.Instance().storeData('PXDClusterChargeMapPar', ChargeMap, iov)
89 
90 
91 def importEmptyGainMap(expLow=0, runLow=0, expHigh=-1, runHigh=-1):
92  """
93  This function imports an empty payloads for the PXD
94  gain calibration.
95 
96  This function works for every Belle 2 geometry
97  """
98 
99  # Create a dummy payload
100  GainMap = Belle2.PXDGainMapPar()
101 
102  # Set the iov for the mask
103  iov = Belle2.IntervalOfValidity(expLow, runLow, expHigh, runHigh)
104  Belle2.Database.Instance().storeData('PXDGainMapPar', GainMap, iov)
105 
106 
107 def importRandomPixelMaskPhase2(HotPixelFraction=0.001, expLow=0, runLow=0, expHigh=-1, runHigh=-1):
108  """
109  This function imports payloads for the PXD
110  pixel masking with random hot pixels
111 
112  This function works for Phase 2
113  """
114 
115  # Create an empty mask
116  pixelMask = Belle2.PXDMaskedPixelPar()
117 
118  # Create a list of sensors
119  sensorIDList = [
120  Belle2.VxdID("1.1.1"), Belle2.VxdID("1.1.2"),
121  Belle2.VxdID("1.2.1"), Belle2.VxdID("1.2.2"),
122  Belle2.VxdID("1.3.1"), Belle2.VxdID("1.3.2"),
123  Belle2.VxdID("1.4.1"), Belle2.VxdID("1.4.2"),
124  Belle2.VxdID("1.5.1"), Belle2.VxdID("1.5.2"),
125  Belle2.VxdID("1.6.1"), Belle2.VxdID("1.6.2"),
126  Belle2.VxdID("1.7.1"), Belle2.VxdID("1.7.2"),
127  Belle2.VxdID("1.8.1"), Belle2.VxdID("1.8.2"),
128  Belle2.VxdID("2.4.1"), Belle2.VxdID("2.4.2"),
129  Belle2.VxdID("2.5.1"), Belle2.VxdID("2.5.2")]
130 
131  # Mean number of hot pixels per sensor
132  AverageHotPixels = HotPixelFraction * 250 * 768
133 
134  # ... and mask some random pixels
135  for sensorID in sensorIDList:
136  # Randomized number of hot pixels
137  nHotPixels = ROOT.gRandom.Poisson(AverageHotPixels)
138 
139  for i in range(nHotPixels):
140  uid = ROOT.gRandom.Integer(250)
141  vid = ROOT.gRandom.Integer(768)
142  print(f"mask pixel uid={uid}, vid={vid}, id={uid * 768 + vid}")
143  pixelMask.maskSinglePixel(sensorID.getID(), uid * 768 + vid)
144 
145  # Print the final mask before committing to db
146  for sensorMask in pixelMask.getMaskedPixelMap():
147  sensorID = Belle2.VxdID(sensorMask.first)
148  print(f"Mask for sensor {sensorID} contains {sensorMask.second.size()} pixels")
149 
150  iov = Belle2.IntervalOfValidity(expLow, runLow, expHigh, runHigh)
151  Belle2.Database.Instance().storeData('PXDMaskedPixelPar', pixelMask, iov)
152 
153 
154 if __name__ == "__main__":
155 
156  importEmptyHotPixelMask()
157  importEmptyDeadPixelMask()
158  importEmptyOccupancyInfo()
159  importEmptyGainMap()
160  importEmptyClusterChargeMap()
A class that describes the interval of experiments/runs for which an object in the database is valid.
The payload class for PXD cluster charge calibrations.
The payload telling which PXD pixel is dead (=Readout system does not receive signals)
The payload class for PXD gain corrections.
Definition: PXDGainMapPar.h:43
The payload telling which PXD pixel to mask (ignore)
The payload collecting some meta information from running the masking algorithm.
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
static Database & Instance()
Instance of a singleton Database.
Definition: Database.cc:42