Belle II Software  release-08-01-10
laserPixelIlumination.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 # ------------------------------------------------------------------------
13 # example of making histograms of pixel hits coming from individual fibers
14 # needs as input the file produced by top/examples/simLaserCalibSystem.py
15 # ------------------------------------------------------------------------
16 
17 import basf2 as b2
18 import os
19 import sys
20 from ROOT import Belle2
21 from ROOT import TH2F, TFile
22 
23 inputFile = 'opticalGun.root'
24 if not os.path.exists(inputFile):
25  b2.B2ERROR(inputFile + ': file not found')
26  b2.B2INFO('File can be generated with top/examples/simLaserCalibSystem.py')
27  sys.exit()
28 
29 
30 class Histogrammer(b2.Module):
31 
32  ''' A module to histogram pixel hits from individual fibers'''
33 
34 
35  hist = [TH2F('fiber' + str(k + 1), 'Pixel hit distribution from fiber No.' + str(k + 1),
36  64, 0.5, 64.5, 8, 0.5, 8.5) for k in range(9)]
37 
38  pixelID = 482
39 
40  propTime = TH2F('propTime', 'Photon propagation times for pixel ' + str(pixelID) +
41  ' vs. fiber number', 9, 0.5, 9.5, 200, 0.0, 1.0)
42  propTime.GetXaxis().SetTitle('fiber number')
43  propTime.GetYaxis().SetTitle('propagation time [ns]')
44 
45  def event(self):
46  ''' Event processor: fill histograms '''
47 
48  digits = Belle2.PyStoreArray('TOPDigits')
49  for digit in digits:
50  simhits = digit.getRelationsWith('TOPSimHits') # several simhits can contribute
51  for simhit in simhits:
52  photon = simhit.getRelated('TOPSimPhotons') # one or none possible
53  if photon:
54  k = int((photon.getEmissionPoint().X() + 22.5) / 5.5)
55  if k >= 0 and k < 9:
56  self.histhist[k].Fill(digit.getPixelCol(), digit.getPixelRow())
57  else:
58  b2.B2ERROR('wrong decoding of fiber number: ' + str(k + 1))
59  if digit.getPixelID() == self.pixelIDpixelID:
60  t = photon.getDetectionTime() - photon.getEmissionTime()
61  self.propTimepropTime.Fill(k + 1, t)
62 
63  def terminate(self):
64  ''' Write histograms to file '''
65 
66  tfile = TFile('laserPixelIlumination.root', 'recreate')
67  for k in range(9):
68  self.histhist[k].Write()
69  self.propTimepropTime.Write()
70  tfile.Close()
71 
72 
73 # Create path
74 main = b2.create_path()
75 
76 # Input
77 roinput = b2.register_module('RootInput')
78 roinput.param('inputFileName', inputFile)
79 main.add_module(roinput)
80 
81 # Histogrammer
82 main.add_module(Histogrammer())
83 
84 # Show progress of processing
85 progress = b2.register_module('Progress')
86 main.add_module(progress)
87 
88 # Process events
89 b2.process(main)
90 
91 # Print call statistics
92 print(b2.statistics)
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72