118 def get_mc_counts(self):
119 """
120 Read out the number of MC particles from the file created by reconstruct
121 """
122
123
124 import ROOT
125 root_file = ROOT.TFile.Open(self.filename, 'read')
126 mc_counts = {}
127
128 for key in root_file.GetListOfKeys():
129 variable = ROOT.Belle2.MakeROOTCompatible.invertMakeROOTCompatible(key.GetName())
130 pdg = abs(int(variable[len('NumberOfMCParticlesInEvent('):-len(")")]))
131 hist = key.ReadObj()
132 mc_counts[pdg] = {}
133 mc_counts[pdg]['sum'] = sum(hist.GetXaxis().GetBinCenter(bin + 1) * hist.GetBinContent(bin + 1)
134 for bin in range(hist.GetNbinsX()))
135 mc_counts[pdg]['std'] = hist.GetStdDev()
136 mc_counts[pdg]['avg'] = hist.GetMean()
137 mc_counts[pdg]['max'] = hist.GetXaxis().GetBinCenter(hist.FindLastBinAbove(0.0))
138 mc_counts[pdg]['min'] = hist.GetXaxis().GetBinCenter(hist.FindFirstBinAbove(0.0))
139
140 mc_counts[0] = {}
141 mc_counts[0]['sum'] = hist.GetEntries()
142 root_file.Close()
143 return mc_counts
144
145