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