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