Belle II Software light-2406-ragdoll
B2A906-EnergyBiasCorrection.py
1#!/usr/bin/env python3
2
3
10
11import basf2 as b2
12import modularAnalysis as ma
13import variables as va
14
15# define scale tests
16sys_tests = ['def', 'scale']
17
18# Select the variation from the list
19test = 'scale'
20
21if test not in sys_tests:
22 print(f"Unknown systematic test {test}")
23 exit(1)
24
25# create path
26my_path = b2.create_path()
27
28# load input ROOT file
29ma.inputMdst(filename=b2.find_file('B02D0pi0_D02pi0pi0.root', 'examples', False),
30 path=my_path)
31
32# ID of weight table
33weight_table_id = "PhotonEnergyBiasCorrection_Feb2021"
34
35b2.conditions.prepend_globaltag(ma.getAnalysisGlobaltag())
36
37# We know what weight info will be added,
38# so we add aliases and add it to the tools
39va.variables.addAlias('Weight', 'extraInfo(' + weight_table_id + '_Weight)')
40va.variables.addAlias('StatErr', 'extraInfo(' + weight_table_id + '_StatErr)')
41va.variables.addAlias('binID', 'extraInfo(' + weight_table_id + '_binID)')
42
43# fill particleLists
44GammaSelection = 'theta > 0.296706 and theta < 2.6179'
45ma.fillParticleList(decayString='gamma:sel',
46 cut=GammaSelection,
47 path=my_path)
48
49if test == 'def':
50 pass
51elif test == 'scale':
52 # The scaling must only be applied to collision data, but not to MC.
53 # In principle, it can be run for MC as well because internally MC events are skipped anyway.
54 # However, it's better (faster, no error message) to skip the energy scaling in the steering file when running over MC.
55 # weight_table_id+"_Weight" is used to scale photon energy
56 ma.correctEnergyBias(inputListNames=['gamma:sel'], tableName=weight_table_id, path=my_path)
57
58var1 = ['M',
59 'p',
60 'E', 'Weight', 'StatErr', 'binID'
61 ]
62
63
64ma.variablesToNtuple(decayString='gamma:sel',
65 variables=var1,
66 filename=f'gamma_{test}.root',
67 path=my_path)
68
69# process the events
70b2.process(my_path)
71
72# print out the summary
73print(b2.statistics)