13 <output>timeDistributions.root</output>
14 <contact>marko.staric@ijs.si</contact>
15 <description>Runs BG mixer
and makes validation histograms</description>
23from ROOT import Belle2
24from ROOT import TH1F, TFile, TNamed
26b2.set_random_seed(123452)
29class BGHistogrammer(b2.Module):
32 Make validation histograms for BG mixer.
49 ''' Initialize the Module: set histogram axis titles, description and check'''
52 self.
hist = [TH1F(
'h' + str(i), self.
simHits[i], 400, -20, 20)
for i
in range(self.
n)]
54 for i
in range(self.
n):
55 self.
hist[i].GetXaxis().SetTitle(
'time [#mus]')
56 self.
hist[i].GetYaxis().SetTitle(
'entries/bin')
57 descr = TNamed(
'Description',
'Time distribution of ' + self.
simHits[i] +
58 ' for mixed background')
59 self.
hist[i].GetListOfFunctions().Add(descr)
60 check = TNamed(
'Check',
'Distribution must be flat in the time window. ' +
61 'Bin statistics is not Poissonian.')
62 self.
hist[i].GetListOfFunctions().Add(check)
63 contact = TNamed(
'Contact',
'marko.staric@ijs.si')
64 self.
hist[i].GetListOfFunctions().Add(contact)
65 options = TNamed(
'MetaOptions',
'shifter')
66 self.
hist[i].GetListOfFunctions().Add(options)
69 ''' Event processor: fill histograms '''
71 for i
in range(self.
n):
74 time = hit.getGlobalTime() / 1000
75 self.
hist[i].Fill(time)
78 ''' Set bin errors - they are not Poissonian'''
79 hmax = hist.GetMaximum()
80 temp = TH1F(
'temp',
'temporary', 100, 0, hmax * 1.1)
81 for i
in range(hist.GetNbinsX()):
82 h = hist.GetBinContent(i + 1)
86 rms = temp.GetStdDev()
88 for i
in range(hist.GetNbinsX()):
89 h = hist.GetBinContent(i + 1)
92 e = rms * math.sqrt(h / mean)
93 hist.SetBinError(i + 1, e)
96 """ Write histograms to the file."""
98 tfile = TFile(
'timeDistributions.root',
'recreate')
99 for i
in range(self.
n):
106main = b2.create_path()
109eventinfosetter = b2.register_module(
'EventInfoSetter')
110eventinfosetter.param({
'evtNumList': [100],
'runList': [1]})
111main.add_module(eventinfosetter)
114gearbox = b2.register_module(
'Gearbox')
115main.add_module(gearbox)
118geometry = b2.register_module(
'Geometry')
119main.add_module(geometry)
123if 'BELLE2_BACKGROUND_MIXING_DIR' in os.environ:
124 bg = glob.glob(os.environ[
'BELLE2_BACKGROUND_MIXING_DIR'] +
'/*.root')
126 b2.B2FATAL(
'No beam background samples found in folder ' +
127 os.environ[
'BELLE2_BACKGROUND_MIXING_DIR'])
128 b2.B2INFO(
'Using background samples from ' + os.environ[
'BELLE2_BACKGROUND_MIXING_DIR'])
129 bkgmixer = b2.register_module(
'BeamBkgMixer')
130 bkgmixer.param(
'backgroundFiles', bg)
131 main.add_module(bkgmixer)
133 b2.B2FATAL(
'variable BELLE2_BACKGROUND_MIXING_DIR is not set')
139main.add_module(
'Progress')
A (simplified) python wrapper for StoreArray.
def setErrors(self, hist)
list simHits
list of SimHits to be histogramed
len n
length of simHits list