Belle II Software  release-08-01-10
offlineanalysis.py
1 # @cond
2 import b2luigi as luigi
3 from b2luigi.basf2_helper import Basf2nTupleMergeTask
4 from reconstruction import ReconstructionWrapper
5 import uproot
6 import matplotlib.pyplot as plt
7 
8 
9 class MergeFiles(Basf2nTupleMergeTask):
10  batch_system = 'local'
11  projectName = luigi.Parameter()
12 
13  def requires(self):
14  skims = open(f"../{self.projectName}skims.dat", 'r')
15  for skim in skims.read().splitlines():
16  yield ReconstructionWrapper(skim=skim, projectName=self.projectName)
17 
18 
19 class Plot(luigi.Task):
20  batch_system = 'local'
21 
22  def requires(self):
23  data = {}
24  data.update({"bmesons": MergeFiles(projectName="bmesons")})
25  data.update({"qqcontinuum": MergeFiles(projectName="qqcontinuum")})
26  return data
27 
28  def output(self):
29  yield self.add_to_output("Mbc.jpg")
30  yield self.add_to_output("deltaE.jpg")
31 
32  def run(self):
33  treeName = 'BtoPiDtoKPiPi'
34  some_variables = ["Mbc", "deltaE"]
35  BBdata = self.requires()["bmesons"].get_output_file_name("reco.root")
36  QQdata = self.requires()["qqcontinuum"].get_output_file_name("reco.root")
37  BBtuple = uproot.open(f"{BBdata}:{treeName}")
38  QQtuple = uproot.open(f"{QQdata}:{treeName}")
39 
40  for var in some_variables:
41  plt.hist([QQtuple[var].array(), BBtuple[var].array()], label=["uudd Continuum", "mixed B mesons"], stacked=True)
42  plt.legend(loc='best')
43  plt.xlabel(f"{var} [GeV]")
44  plt.savefig(self.get_output_file_name(f"{var}.jpg"), dpi=100)
45  plt.close()
46 # @endcond