Belle II Software  release-08-01-10
EventShapePlotsMixed.py
1 #!/usr/bin/env python
2 
3 
10 
11 """
12 <header>
13  <input>MCvalidationMixed.root</input>
14  <output>EventShapePlotsMixed.root</output>
15  <contact>Frank Meier; frank.meier@belle2.org</contact>
16  <description>Comparing event shape variables</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='EventShapePlotsMixed.root', help='The name of the output root file')
38 
39  return parser
40 
41 
42 def PlottingHistos(var):
43  ''' Plotting function'''
44 
45  hist = rdf.Histo1D((var, var, 25, range_dic[var][0], range_dic[var][1]), var)
46  hist.SetTitle(f";{axis_dic[var]}; Events")
47  hist.GetListOfFunctions().Add(ROOT.TNamed('Description', axis_dic[var]))
48  hist.GetListOfFunctions().Add(ROOT.TNamed('Check', 'Shape should not change drastically.'))
49  hist.GetListOfFunctions().Add(ROOT.TNamed('Contact', 'frank.meier@belle2.org'))
50  hist.GetListOfFunctions().Add(ROOT.TNamed('MetaOptions', 'nostats'))
51  hist.Write()
52 
53 
54 if __name__ == '__main__':
55 
56  parser = get_argument_parser()
57  args = parser.parse_args()
58  # load the root file into RDataFrame
59  rdf = ROOT.RDataFrame("EventShape", args.input)
60 
61  # define the variables to plot
62  colnames = rdf.GetColumnNames()
63  all_list = [str(x) for x in colnames if x[0] != "_"]
64 
65  # define dictionaries for the ranges and axis-labels
66  range_dic = {'foxWolframR1': [0, 0.15],
67  'foxWolframR2': [0, 0.4],
68  'foxWolframR3': [0, 0.25],
69  'foxWolframR4': [0, 0.3],
70  'cleoConeThrust0': [0, 2.5],
71  'cleoConeThrust1': [0, 5],
72  'cleoConeThrust2': [0, 6],
73  'cleoConeThrust3': [0, 6],
74  'cleoConeThrust4': [0, 6],
75  'cleoConeThrust5': [0, 6],
76  'cleoConeThrust6': [0, 5],
77  'cleoConeThrust7': [0, 4],
78  'cleoConeThrust8': [0, 2],
79  'sphericity': [0, 1],
80  'aplanarity': [0, 0.5],
81  'thrust': [0.5, 0.9],
82  'thrustAxisCosTheta': [0, 1],
83  'harmonicMomentThrust0': [0.5, 1.5],
84  'harmonicMomentThrust1': [-0.4, 0.4],
85  'harmonicMomentThrust2': [0, 0.8],
86  'harmonicMomentThrust3': [-0.4, 0.4],
87  'harmonicMomentThrust4': [-0.3, 0.5],
88  }
89 
90  axis_dic = {'foxWolframR1': 'R_{1}',
91  'foxWolframR2': 'R_{2}',
92  'foxWolframR3': 'R_{3}',
93  'foxWolframR4': 'R_{4}',
94  'cleoConeThrust0': "Cleo Cone 0",
95  'cleoConeThrust1': "Cleo Cone 1",
96  'cleoConeThrust2': "Cleo Cone 2",
97  'cleoConeThrust3': "Cleo Cone 3",
98  'cleoConeThrust4': "Cleo Cone 4",
99  'cleoConeThrust5': "Cleo Cone 5",
100  'cleoConeThrust6': "Cleo Cone 6",
101  'cleoConeThrust7': "Cleo Cone 7",
102  'cleoConeThrust8': "Cleo Cone 8",
103  'sphericity': "Sphericity",
104  'aplanarity': "Aplanarity",
105  'thrust': "Thrust",
106  'thrustAxisCosTheta': "ThrustAxisCosTheta",
107  'harmonicMomentThrust0': "harmonicMomentThrust0",
108  'harmonicMomentThrust1': "harmonicMomentThrust1",
109  'harmonicMomentThrust2': "harmonicMomentThrust2",
110  'harmonicMomentThrust3': "harmonicMomentThrust3",
111  'harmonicMomentThrust4': "harmonicMomentThrust4"
112  }
113 
114  outputFile = ROOT.TFile(args.output, "RECREATE")
115  ROOT.gROOT.SetBatch(True)
116 
117  # plot the histograms
118  for var in all_list:
119  PlottingHistos(var)
120 
121  outputFile.Close()