Belle II Software  release-08-01-10
MultiplicityPlotsMixed.py
1 #!/usr/bin/env python
2 
3 
10 
11 """
12 <header>
13  <input>MCvalidationMixed.root</input>
14  <output>MultiplicityPlotsMixed.root</output>
15  <contact>Frank Meier; frank.meier@belle2.org</contact>
16  <description>Comparing generated particle multiplicities</description>
17 </header>
18 """
19 
20 import ROOT
21 import argparse
22 
23 
24 def get_argument_parser():
25  """
26  Parses the command line options and returns the corresponding arguments.
27  """
28 
29  parser = argparse.ArgumentParser(
30  description=__doc__.split("--examples--")[0],
31  # epilog=__doc__.split("--examples--")[1],
32  formatter_class=argparse.RawDescriptionHelpFormatter,
33  # usage="%(prog)s [optional arguments] [--] program [program arguments]"
34  )
35 
36  parser.add_argument('--input', type=str, default='MCvalidationMixed.root', help='The name of the input root file')
37  parser.add_argument('--output', type=str, default='MultiplicityPlotsMixed.root', help='The name of the output root file')
38 
39  return parser
40 
41 
42 def PlottingHistos(particle):
43  ''' Plotting function'''
44 
45  nbins = int(range_dic[particle][1] - (range_dic[particle][0]))
46 
47  hist = rdf.Histo1D((var, var, nbins, range_dic[particle][0], range_dic[particle][1]), var)
48  hist.SetTitle(f";{axis_dic[particle]}; Events")
49  hist.GetListOfFunctions().Add(ROOT.TNamed('Description', f'{axis_dic[particle]} multiplicity'))
50  hist.GetListOfFunctions().Add(ROOT.TNamed('Check', 'Shape should not change drastically.'))
51  hist.GetListOfFunctions().Add(ROOT.TNamed('Contact', 'frank.meier@belle2.org'))
52  hist.GetListOfFunctions().Add(ROOT.TNamed('MetaOptions', 'nostats'))
53  hist.Write()
54 
55 
56 if __name__ == '__main__':
57 
58  parser = get_argument_parser()
59  args = parser.parse_args()
60 
61  # load the root file into RDataFrame
62  rdf = ROOT.RDataFrame("Multiplicities", args.input)
63 
64  # define the variables to plot
65  colnames = rdf.GetColumnNames()
66  all_list = [str(x) for x in colnames if x[0] == "n"]
67  all_list.remove("nB0")
68  all_list.remove("nBp")
69 
70  # define dictionaries for the axis-labels and the ranges
71  range_dic = {'nPIp': [-0.5, 25.5],
72  'nPI0': [-0.5, 20.5],
73  'nETA': [-0.5, 4.5],
74  'nETAprim': [-0.5, 2.5],
75  'nPHI': [-0.5, 3.5],
76  'nRHOp': [-0.5, 6.5],
77  'nRHO0': [-0.5, 4.5],
78  'nKp': [-0.5, 6.5],
79  'nKL0': [-0.5, 5.5],
80  'nKS0': [-0.5, 5.5],
81  'nKstar0': [-0.5, 4.5],
82  'nKstarp': [-0.5, 4.5],
83  'nDp': [-0.5, 3.5],
84  'nD0': [-0.5, 4.5],
85  'nJPSI': [-0.5, 1.5],
86  'nELECTRON': [-0.5, 6.5],
87  'nENEUTRINO': [-0.5, 4.5],
88  'nMUON': [-0.5, 4.5],
89  'nMNEUTRINO': [-0.5, 4.5],
90  'nTAUON': [-0.5, 2.5],
91  'nTNEUTRINO': [-0.5, 4.5],
92  'nPHOTON': [-0.5, 35.5]
93  }
94 
95  axis_dic = {'nPIp': '#pi^{+}',
96  'nPI0': '#pi^{0}',
97  'nETA': '#eta',
98  'nETAprim': "#eta'",
99  'nPHI': '#phi',
100  'nRHOp': '#rho^{+}',
101  'nRHO0': '#rho^{0}',
102  'nKp': 'K^{+}',
103  'nKL0': 'K_{L}^{0}',
104  'nKS0': 'K_{S}^{0}',
105  'nKstar0': 'K^{*,0}',
106  'nKstarp': 'K^{*,+}',
107  'nDp': 'D^{+}',
108  'nD0': 'D^{0}',
109  'nJPSI': 'J/#psi',
110  'nELECTRON': 'e^{#minus}',
111  'nENEUTRINO': '#nu_{e}^{#minus}',
112  'nMUON': '#mu^{#minus}',
113  'nMNEUTRINO': '#nu_{#mu}^{#minus}',
114  'nTAUON': '#tau^{#minus}',
115  'nTNEUTRINO': '#nu_{#tau}^{#minus}',
116  'nPHOTON': '#gamma'}
117 
118  outputFile = ROOT.TFile(args.output, "RECREATE")
119  ROOT.gROOT.SetBatch(True)
120 
121  # plot the histograms
122  for var in all_list:
123  PlottingHistos(var)
124 
125  outputFile.Close()