Belle II Software  release-08-01-10
B2A906-EnergyBiasCorrection.py
1 #!/usr/bin/env python3
2 
3 
10 
11 import basf2 as b2
12 import modularAnalysis as ma
13 import variables as va
14 
15 # define scale tests
16 sys_tests = ['def', 'scale']
17 
18 # Select the variation from the list
19 test = 'scale'
20 
21 if test not in sys_tests:
22  print(f"Unknown systematic test {test}")
23  exit(1)
24 
25 # create path
26 my_path = b2.create_path()
27 
28 # load input ROOT file
29 ma.inputMdst(filename=b2.find_file('B02D0pi0_D02pi0pi0.root', 'examples', False),
30  path=my_path)
31 
32 # ID of weight table
33 weight_table_id = "PhotonEnergyBiasCorrection_Feb2021"
34 
35 b2.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
39 va.variables.addAlias('Weight', 'extraInfo(' + weight_table_id + '_Weight)')
40 va.variables.addAlias('StatErr', 'extraInfo(' + weight_table_id + '_StatErr)')
41 va.variables.addAlias('binID', 'extraInfo(' + weight_table_id + '_binID)')
42 
43 # fill particleLists
44 GammaSelection = 'theta > 0.296706 and theta < 2.6179'
45 ma.fillParticleList(decayString='gamma:sel',
46  cut=GammaSelection,
47  path=my_path)
48 
49 if test == 'def':
50  pass
51 elif 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 
58 var1 = ['M',
59  'p',
60  'E', 'Weight', 'StatErr', 'binID'
61  ]
62 
63 
64 ma.variablesToNtuple(decayString='gamma:sel',
65  variables=var1,
66  filename=f'gamma_{test}.root',
67  path=my_path)
68 
69 # process the events
70 b2.process(my_path)
71 
72 # print out the summary
73 print(b2.statistics)