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