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