Belle II Software  release-05-01-25
SVDClustersDebug.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 import os
5 import basf2
6 from basf2 import *
7 from generators import add_evtgen_generator
8 from modularAnalysis import setupEventInfo
9 from simulation import add_simulation
10 from svd import *
11 import ROOT
12 from ROOT import Belle2, TH1F, TH2F, TFile
13 from ROOT.Belle2 import SVDNoiseCalibrations
14 import os.path
15 import sys
16 
17 
24 
25 # GLOBAL_TAG = "svd_commissioning_20180711" #for commissioning data
26 
27 fileIN = "given by the user" # is the -i option is used
28 fileOUT = "given by the user" # if the -o option is used
29 cluster3 = "SVDClustersZS3"
30 reco3 = "SVDRecoDigitsZS3"
31 shaper3 = "SVDShaperDigitsZS3"
32 cluster5 = "SVDClustersZS5"
33 reco5 = "SVDRecoDigitsZS5"
34 shaper5 = "SVDShaperDigitsZS5"
35 
36 if(len(sys.argv) == 1 + 1):
37  fileOUT = sys.argv[1]
38 
39 
40 class SVDClustersDebug(basf2.Module):
41  '''class to debug clusterizer'''
42 
43  def initialize(self):
44  ''' initialize'''
45 
47 
48  self.fb2u = TH2F("nCl_L4L5S2U", "4.5.2 U ZS3 vs ZS5 clusters", 100, 0, 100, 100, 0, 100)
49  '''debug histogram'''
50 
51  def event(self):
52  '''event'''
53 
54  evt = Belle2.PyStoreObj("EventMetaData")
55 
56  clustersZS3 = Belle2.PyStoreArray(cluster3)
57  clustersZS5 = Belle2.PyStoreArray(cluster5)
58 
59  nCl3 = 0
60  nCl5 = 0
61 
62  for d in clustersZS5:
63  if(str(d.getSensorID()) == "4.5.2"):
64  if(d.isUCluster()):
65  nCl5 = nCl5 + 1
66 
67  for d in clustersZS3:
68  if(str(d.getSensorID()) == "4.5.2"):
69  if(d.isUCluster()):
70  nCl3 = nCl3 + 1
71 
72  self.fb2u.Fill(nCl3, nCl5)
73 
74  noisePayload = Belle2.SVDNoiseCalibrations()
75 # print(type(noisePayload))
76 
77  if nCl3 != nCl5:
78  print("different number of clusters in event " + str(evt.getEvent()) +
79  "! ZS3 = " + str(nCl3) + ", ZS5 = " + str(nCl5) + " ")
80 
81  # for d in clustersZS5:
82  # if(str(d.getSensorID()) == "4.5.2") :
83  # if(d.isUCluster()):
84  # print(" ZS5: seed charge = "+str(d.getSeedCharge())+",\
85  # size = "+str(d.getSize())+", position = "+str(d.getPosition())+", charge = "+str(d.getCharge())+" ")
86 
87  # for d in clustersZS3:
88  # if(str(d.getSensorID()) == "4.5.2") :
89  # if(d.isUCluster()):
90  # print(" ZS3: seed charge = "+str(d.getSeedCharge())+",\
91  # size = "+str(d.getSize())+", position = "+str(d.getPosition())+", charge = "+str(d.getCharge())+" ")
92 
93  for d3 in clustersZS3:
94  if(str(d3.getSensorID()) == "4.5.2"):
95  if(d3.isUCluster()):
96  found = False
97  for d5 in clustersZS5:
98  if(str(d5.getSensorID()) == "4.5.2"):
99  if(d5.isUCluster()):
100  if(d5.getSeedCharge() == d3.getSeedCharge()):
101  found = True
102  if not found:
103  print(" ONLY ZS3: seed charge = " + str(d3.getSeedCharge()) + ", size = " + str(d3.getSize()) +
104  ", position = " + str(d3.getPosition()) + ", charge = " + str(d3.getCharge()) + " ")
105  reco = d3.getRelationsTo(reco3)
106 # print("test size cluster: "+str(reco.size()))
107  for r in reco:
108  charge = r.getCharge()
109  noise = noisePayload.getNoiseInElectrons(r.getSensorID(), True, r.getCellID())
110  print(" SNR = " + str(charge / noise) + ", charge = " + str(charge) + ", noise = " + str(noise))
111 
112  def terminate(self):
113  '''terminate'''
114 
115  f = TFile(fileOUT, "RECREATE")
116  self.fb2u.GetXaxis().SetTitle("# cl ZS3")
117  self.fb2u.GetYaxis().SetTitle("# cl ZS5")
118  self.fb2u.Write()
119 
120  f.Close()
121 
122 
123 # setup database for commissioning data
124 # reset_database()
125 # use_central_database(GLOBAL_TAG, LogLevel.WARNING)
126 
127 # Create paths
128 main = create_path()
129 
130 # if run on real data
131 # main.add_module('RootInput')
132 
133 # generation and simulation
134 setupEventInfo(100, main)
135 add_evtgen_generator(main, 'charged')
136 add_simulation(main, components=['SVD'])
137 set_module_parameters(main, type="Geometry", useDB=False, components=["SVD"])
138 
139 
140 # if run on real data
141 # main.add_module("Gearbox")
142 # main.add_module('Geometry', useDB=True)
143 # main.add_module('SVDUnpacker', svdShaperDigitListName='SVDShaperDigitsToFilter')
144 
145 # ZS 3
146 zs3 = register_module('SVDZeroSuppressionEmulator')
147 zs3.set_name("SVDZeroSuppressionEmulator_ZS3")
148 zs3.param('SNthreshold', 3)
149 zs3.param('ShaperDigits', 'SVDShaperDigits') # ToFilter
150 zs3.param('ShaperDigitsIN', shaper3)
151 zs3.param('FADCmode', True)
152 # zs3.param('FADCmode',False)
153 main.add_module(zs3)
154 
155 fitterZS3 = register_module('SVDCoGTimeEstimator')
156 fitterZS3.set_name('SVDCoGTimeEstimatorZS3')
157 fitterZS3.param('RecoDigits', reco3)
158 fitterZS3.param('ShaperDigits', shaper3)
159 main.add_module(fitterZS3)
160 
161 clusterizerZS3 = register_module('SVDSimpleClusterizer')
162 clusterizerZS3.set_name('SVDSimpleClusterizerZS3')
163 clusterizerZS3.param('RecoDigits', reco3)
164 clusterizerZS3.param('Clusters', cluster3)
165 main.add_module(clusterizerZS3)
166 
167 # ZS 5
168 zs5 = register_module('SVDZeroSuppressionEmulator')
169 zs5.set_name("SVDZeroSuppressionEmulator_ZS5")
170 zs5.param('SNthreshold', 5)
171 zs5.param('ShaperDigits', 'SVDShaperDigits') # ToFilter
172 zs5.param('ShaperDigitsIN', shaper5)
173 zs5.param('FADCmode', True)
174 # zs5.param('FADCmode',False)
175 main.add_module(zs5)
176 
177 fitterZS5 = register_module('SVDCoGTimeEstimator')
178 fitterZS5.set_name('SVDCoGTimeEstimatorZS5')
179 fitterZS5.param('RecoDigits', reco5)
180 fitterZS5.param('ShaperDigits', shaper5)
181 main.add_module(fitterZS5)
182 
183 clusterizerZS5 = register_module('SVDSimpleClusterizer')
184 clusterizerZS5.set_name('SVDSimpleClusterizerZS5')
185 clusterizerZS5.param('RecoDigits', reco5)
186 clusterizerZS5.param('Clusters', cluster5)
187 main.add_module(clusterizerZS5)
188 
189 
190 main.add_module(SVDClustersDebug())
191 
192 # main.add_module('Progress')
193 # main.add_module('ProgressBar')
194 
195 # main.add_module('RootOutput')
196 print_path(main)
197 
198 # Process events
199 process(main)
200 
201 print(statistics)
SVDClustersDebug.SVDClustersDebug.fb2u
fb2u
Definition: SVDClustersDebug.py:48
SVDClustersDebug.SVDClustersDebug.initialize
def initialize(self)
Definition: SVDClustersDebug.py:43
Belle2::PyStoreObj
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:69
SVDClustersDebug.SVDClustersDebug
Definition: SVDClustersDebug.py:40
Belle2::SVDNoiseCalibrations
This class defines the dbobject and the method to access SVD calibrations from the noise local runs.
Definition: SVDNoiseCalibrations.h:46
Belle2::VXD::GeoCache::getInstance
static GeoCache & getInstance()
Return a reference to the singleton instance.
Definition: GeoCache.cc:215
SVDClustersDebug.SVDClustersDebug.terminate
def terminate(self)
Definition: SVDClustersDebug.py:112
SVDClustersDebug.SVDClustersDebug.event
def event(self)
Definition: SVDClustersDebug.py:51
Belle2::PyStoreArray
a (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:58